From 3c61f2ae7c13ddef0e8f69b5d37a510ebb4221de Mon Sep 17 00:00:00 2001 From: cutefishd Date: Sun, 18 Apr 2021 03:08:34 +0800 Subject: [PATCH] Improve network --- src/qml/NetworkPage.qml | 135 ------------- .../WifiItem.qml} | 27 +-- src/qml/NetworkPage/WifiView.qml | 72 +++++++ src/qml/{ => NetworkPage}/WiredItem.qml | 0 .../WirelessDetailsDialog.qml | 3 +- src/qml/NetworkPage/main.qml | 106 +++++++++++ src/qml/SideBar.qml | 2 +- src/qml/Wallpaper/BackgroundPage.qml | 178 +++++++++--------- src/resources.qrc | 9 +- 9 files changed, 288 insertions(+), 244 deletions(-) delete mode 100644 src/qml/NetworkPage.qml rename src/qml/{WirelessItem.qml => NetworkPage/WifiItem.qml} (82%) create mode 100644 src/qml/NetworkPage/WifiView.qml rename src/qml/{ => NetworkPage}/WiredItem.qml (100%) rename src/qml/{ => NetworkPage}/WirelessDetailsDialog.qml (97%) create mode 100644 src/qml/NetworkPage/main.qml diff --git a/src/qml/NetworkPage.qml b/src/qml/NetworkPage.qml deleted file mode 100644 index 961efd1..0000000 --- a/src/qml/NetworkPage.qml +++ /dev/null @@ -1,135 +0,0 @@ -import QtQuick 2.4 -import QtQuick.Controls 2.4 -import QtQuick.Layouts 1.3 -import QtGraphicalEffects 1.0 - -import FishUI 1.0 as FishUI -import Cutefish.NetworkManagement 1.0 as NM - -ItemPage { - id: control - headerTitle: qsTr("Network") - - property var itemHeight: 50 - property var settingsMap: ({}) - - NM.Networking { - id: networking - } - - NM.NetworkModel { - id: networkModel - } - - Scrollable { - anchors.fill: parent - contentHeight: mainLayout.implicitHeight - - ColumnLayout { - id: mainLayout - anchors.fill: parent - - // Wired connection - ColumnLayout { - id: wiredLayout - - visible: networking.enabled && wiredView.count > 0 - - RowLayout { - Label { - text: qsTr("Wired") - color: FishUI.Theme.disabledTextColor - Layout.fillWidth: true - } - } - - ListView { - id: wiredView - - Layout.fillWidth: true - implicitHeight: wiredView.count * control.itemHeight - clip: true - - model: NM.TechnologyProxyModel { - type: NM.TechnologyProxyModel.WiredType - sourceModel: networkModel - } - - ScrollBar.vertical: ScrollBar {} - - delegate: WiredItem { - height: control.itemHeight - width: wiredView.width - } - } - } - - HorizontalDivider { - visible: wiredView.visible && networking.wirelessHardwareEnabled - } - - // Wireless - ColumnLayout { - id: wirelessLayout - spacing: FishUI.Units.largeSpacing - - RowLayout { - spacing: FishUI.Units.largeSpacing - - Label { - text: qsTr("Wi-Fi") - color: FishUI.Theme.disabledTextColor - } - - FishUI.BusyIndicator { - id: wlanBusyIndicator - width: wirelessSwitch.height - height: width - visible: networking.wirelessEnabled && wirelessView.count === 0 - running: wlanBusyIndicator.visible - } - - Item { - Layout.fillWidth: true - } - - Switch { - id: wirelessSwitch - Layout.fillHeight: true - leftPadding: 0 - rightPadding: 0 - onCheckedChanged: networking.wirelessEnabled = checked - } - - Component.onCompleted: { - wirelessSwitch.checked = networking.wirelessEnabled - } - } - - ListView { - id: wirelessView - - visible: networking.wirelessEnabled && networking.wirelessHardwareEnabled - Layout.fillWidth: true - - implicitHeight: count * control.itemHeight - interactive: false - clip: true - - model: NM.TechnologyProxyModel { - type: NM.TechnologyProxyModel.WirelessType - sourceModel: networkModel - showInactiveConnections: true - } - - ScrollBar.vertical: ScrollBar {} - - delegate: WirelessItem { - height: control.itemHeight - width: wirelessView.width - } - } - } - } - } -} diff --git a/src/qml/WirelessItem.qml b/src/qml/NetworkPage/WifiItem.qml similarity index 82% rename from src/qml/WirelessItem.qml rename to src/qml/NetworkPage/WifiItem.qml index 6f6608c..261b484 100644 --- a/src/qml/WirelessItem.qml +++ b/src/qml/NetworkPage/WifiItem.qml @@ -6,13 +6,14 @@ import QtQuick.Window 2.3 import FishUI 1.0 as FishUI import Cutefish.NetworkManagement 1.0 as NM +import "../" Item { id: control - property bool passwordIsStatic: (model.securityType === NM.NetworkModel.StaticWep || model.securityType === NM.NetworkModel.WpaPsk || - model.securityType === NM.NetworkModel.Wpa2Psk || model.securityType === NM.NetworkModel.SAE) - property bool predictableWirelessPassword: !model.uuid && model.type === NM.NetworkModel.Wireless && passwordIsStatic + property bool passwordIsStatic: (model.securityType === NM.Enums.StaticWep || model.securityType === NM.Enums.WpaPsk || + model.securityType === NM.Enums.Wpa2Psk || model.securityType === NM.Enums.SAE) + property bool predictableWirelessPassword: !model.uuid && model.type === NM.Enums.Wireless && passwordIsStatic Rectangle { anchors.fill: parent @@ -38,14 +39,14 @@ Item { onClicked: { if (model.uuid || !predictableWirelessPassword) { - if (connectionState === NM.NetworkModel.Deactivated) { + if (connectionState === NM.Enums.Deactivated) { if (!predictableWirelessPassword && !model.uuid) { - networking.addAndActivateConnection(model.devicePath, model.specificPath); + handler.addAndActivateConnection(model.devicePath, model.specificPath); } else { - networking.activateConnection(model.connectionPath, model.devicePath, model.specificPath); + handler.activateConnection(model.connectionPath, model.devicePath, model.specificPath); } } else { - networking.deactivateConnection(model.connectionPath, model.devicePath); + handler.deactivateConnection(model.connectionPath, model.devicePath); } } else if (predictableWirelessPassword) { passwordDialog.show() @@ -77,8 +78,8 @@ Item { id: busyIndicator width: 22 height: width - visible: connectionState === NM.NetworkModel.Activating || - connectionState === NM.NetworkModel.Deactivating + visible: connectionState === NM.Enums.Activating || + connectionState === NM.Enums.Deactivating running: busyIndicator.visible } @@ -88,7 +89,7 @@ Item { height: width sourceSize: Qt.size(width, height) source: "qrc:/images/checked.svg" - visible: model.connectionState === NM.NetworkModel.Activated + visible: model.connectionState === NM.Enums.Activated ColorOverlay { anchors.fill: parent @@ -105,7 +106,7 @@ Item { height: width sourceSize: Qt.size(width, height) source: "qrc:/images/locked.svg" - visible: model.securityType !== -1 && model.securityType !== 0 + visible: (model.securityType === -1 | model.securityType === 0) ? false : true ColorOverlay { anchors.fill: parent @@ -150,7 +151,7 @@ Item { } onAccept: { - networking.addAndActivateConnection(model.devicePath, model.specificPath, passwordField.text) + handler.addAndActivateConnection(model.devicePath, model.specificPath, passwordField.text) passwordDialog.close() } @@ -172,7 +173,7 @@ Item { placeholderText: qsTr("Password") validator: RegExpValidator { regExp: { - if (model.securityType === NM.NetworkModel.StaticWep) + if (model.securityType === NM.Enums.StaticWep) return /^(?:[\x20-\x7F]{5}|[0-9a-fA-F]{10}|[\x20-\x7F]{13}|[0-9a-fA-F]{26}){1}$/; return /^(?:[\x20-\x7F]{8,64}){1}$/; } diff --git a/src/qml/NetworkPage/WifiView.qml b/src/qml/NetworkPage/WifiView.qml new file mode 100644 index 0000000..ad34d7c --- /dev/null +++ b/src/qml/NetworkPage/WifiView.qml @@ -0,0 +1,72 @@ +import QtQuick 2.12 +import QtQuick.Controls 2.12 +import QtQuick.Layouts 1.12 +import FishUI 1.0 as FishUI + +Item { + implicitHeight: _contentLayout.implicitHeight + FishUI.Theme.mediumRadius * 2 + + ColumnLayout { + id: _contentLayout + anchors.fill: parent + spacing: FishUI.Units.smallSpacing + + RowLayout { + Label { + id: wlanLabel + text: qsTr("WLAN") + } + + FishUI.BusyIndicator { + id: wlanBusyIndicator + width: wirelessSwitch.height + height: width + visible: enabledConnections.wirelessEnabled && wirelessView.count === 0 + running: wlanBusyIndicator.visible + } + + Item { + Layout.fillWidth: true + } + + Switch { + id: wirelessSwitch + height: wlanLabel.implicitHeight + leftPadding: 0 + rightPadding: 0 + + checked: enabledConnections.wirelessEnabled + onCheckedChanged: { + if (checked) { + if (!enabledConnections.wirelessEnabled) { + handler.enableWireless(checked) + handler.requestScan() + } + } else { + if (enabledConnections.wirelessEnabled) { + handler.enableWireless(checked) + } + } + } + } + } + + ListView { + id: wirelessView + Layout.fillWidth: true + Layout.preferredHeight: itemHeight * count + clip: true + model: appletProxyModel + interactive: false + + visible: enabledConnections.wirelessEnabled + + property var itemHeight: 45 + + delegate: WifiItem { + width: ListView.view.width + height: ListView.view.itemHeight + } + } + } +} diff --git a/src/qml/WiredItem.qml b/src/qml/NetworkPage/WiredItem.qml similarity index 100% rename from src/qml/WiredItem.qml rename to src/qml/NetworkPage/WiredItem.qml diff --git a/src/qml/WirelessDetailsDialog.qml b/src/qml/NetworkPage/WirelessDetailsDialog.qml similarity index 97% rename from src/qml/WirelessDetailsDialog.qml rename to src/qml/NetworkPage/WirelessDetailsDialog.qml index f794fe3..8a459fa 100644 --- a/src/qml/WirelessDetailsDialog.qml +++ b/src/qml/NetworkPage/WirelessDetailsDialog.qml @@ -164,7 +164,8 @@ Dialog { Layout.fillWidth: true flat: true onClicked: { - networking.removeConnection(model.connectionPath) + handler.removeConnection(model.connectionPath) + control.reject() } } } diff --git a/src/qml/NetworkPage/main.qml b/src/qml/NetworkPage/main.qml new file mode 100644 index 0000000..72d5bef --- /dev/null +++ b/src/qml/NetworkPage/main.qml @@ -0,0 +1,106 @@ +import QtQuick 2.4 +import QtQuick.Controls 2.4 +import QtQuick.Layouts 1.3 +import QtGraphicalEffects 1.0 + +import FishUI 1.0 as FishUI +import Cutefish.NetworkManagement 1.0 as NM + +import "../" + +ItemPage { + id: control + headerTitle: qsTr("Network") + + property var itemHeight: 50 + property var settingsMap: ({}) + + NM.Handler { + id: handler + } + + NM.WifiSettings { + id: wifiSettings + } + + NM.NetworkModel { + id: networkModel + } + + NM.EnabledConnections { + id: enabledConnections + } + + NM.IdentityModel { + id: connectionModel + } + + NM.AppletProxyModel { + id: appletProxyModel + sourceModel: connectionModel + } + + Component.onCompleted: handler.requestScan() + + Timer { + id: scanTimer + interval: 10200 + repeat: true + running: control.visible + onTriggered: handler.requestScan() + } + + Scrollable { + anchors.fill: parent + contentHeight: mainLayout.implicitHeight + + ColumnLayout { + id: mainLayout + anchors.fill: parent + + // Wired connection + ColumnLayout { + id: wiredLayout + + visible: enabledConnections.wwanEnabled && wiredView.count > 0 + + RowLayout { + Label { + text: qsTr("Wired") + color: FishUI.Theme.disabledTextColor + Layout.fillWidth: true + } + } + + ListView { + id: wiredView + + Layout.fillWidth: true + implicitHeight: wiredView.count * control.itemHeight + clip: true + + model: NM.TechnologyProxyModel { + type: NM.TechnologyProxyModel.WiredType + sourceModel: networkModel + } + + ScrollBar.vertical: ScrollBar {} + + delegate: WiredItem { + height: control.itemHeight + width: wiredView.width + } + } + } + + HorizontalDivider { + visible: wiredView.visible && enabledConnections.wirelessHwEnabled + } + + WifiView { + Layout.fillWidth: true + visible: enabledConnections.wirelessHwEnabled + } + } + } +} diff --git a/src/qml/SideBar.qml b/src/qml/SideBar.qml index cccdba1..7b6a613 100644 --- a/src/qml/SideBar.qml +++ b/src/qml/SideBar.qml @@ -45,7 +45,7 @@ Item { ListElement { title: qsTr("Network") name: "network" - page: "qrc:/qml/NetworkPage.qml" + page: "qrc:/qml/NetworkPage/main.qml" iconSource: "network.svg" } diff --git a/src/qml/Wallpaper/BackgroundPage.qml b/src/qml/Wallpaper/BackgroundPage.qml index 4d52e10..3e6692d 100644 --- a/src/qml/Wallpaper/BackgroundPage.qml +++ b/src/qml/Wallpaper/BackgroundPage.qml @@ -57,125 +57,123 @@ ItemPage { } } - Loader { - Layout.fillWidth: true - height: item.height - sourceComponent: background.backgroundType === 0 ? imageView : colorView - } - } - } - - Component { - id: imageView + GridView { + id: _view - GridView { - id: _view - // spacing: FishUI.Units.smallSpacing - // orientation: Qt.Horizontal + property int rowCount: _view.width / itemWidth - property int rowCount: _view.width / itemWidth + Layout.fillWidth: true + implicitHeight: Math.ceil(_view.count / rowCount) * cellHeight + FishUI.Units.largeSpacing - implicitHeight: Math.ceil(_view.count / rowCount) * (itemHeight + FishUI.Units.largeSpacing * 2) + visible: background.backgroundType === 0 - clip: true - model: background.backgrounds - currentIndex: -1 - interactive: false + clip: true + model: background.backgrounds + currentIndex: -1 + interactive: false - cellHeight: calcExtraSpacing(itemHeight, _view.height) + itemHeight - cellWidth: calcExtraSpacing(itemWidth, _view.width) + itemWidth + cellHeight: itemHeight + cellWidth: calcExtraSpacing(itemWidth, _view.width) + itemWidth - property int itemWidth: 250 - property int itemHeight: 170 + property int itemWidth: 250 + property int itemHeight: 170 - delegate: Item { - id: item + delegate: Item { + id: item - property bool isSelected: modelData === background.currentBackgroundPath + property bool isSelected: modelData === background.currentBackgroundPath - width: GridView.view.cellWidth - height: GridView.view.cellHeight - scale: 1.0 + width: GridView.view.cellWidth + height: GridView.view.cellHeight + scale: 1.0 - Behavior on scale { - NumberAnimation { - duration: 100 + Behavior on scale { + NumberAnimation { + duration: 100 + } } - } - - Rectangle { - anchors.fill: parent - anchors.margins: FishUI.Units.smallSpacing - color: "transparent" - radius: FishUI.Theme.bigRadius + FishUI.Units.smallSpacing / 2 - - border.color: FishUI.Theme.highlightColor - border.width: image.status == Image.Ready & isSelected ? 3 : 0 - Image { - id: image + Rectangle { anchors.fill: parent anchors.margins: FishUI.Units.smallSpacing - source: "file://" + modelData - sourceSize: Qt.size(width, height) - fillMode: Image.PreserveAspectCrop - asynchronous: true - mipmap: true - cache: true - opacity: 1.0 - smooth: false - - Behavior on opacity { - NumberAnimation { - duration: 100 - easing.type: Easing.InOutCubic + color: "transparent" + radius: FishUI.Theme.bigRadius + FishUI.Units.smallSpacing / 2 + + border.color: FishUI.Theme.highlightColor + border.width: image.status == Image.Ready & isSelected ? 3 : 0 + + Image { + id: image + anchors.fill: parent + anchors.margins: FishUI.Units.smallSpacing + source: "file://" + modelData + sourceSize: Qt.size(width, height) + fillMode: Image.PreserveAspectCrop + asynchronous: true + mipmap: true + cache: true + smooth: true + opacity: 1.0 + + Behavior on opacity { + NumberAnimation { + duration: 100 + easing.type: Easing.InOutCubic + } } - } - layer.enabled: true - layer.effect: OpacityMask { - maskSource: Item { - width: image.width - height: image.height + layer.enabled: true + layer.effect: OpacityMask { + maskSource: Item { + width: image.width + height: image.height - Rectangle { - anchors.fill: parent - radius: FishUI.Theme.bigRadius + Rectangle { + anchors.fill: parent + radius: FishUI.Theme.bigRadius + } } } } - } - MouseArea { - anchors.fill: parent - acceptedButtons: Qt.LeftButton - hoverEnabled: true + MouseArea { + anchors.fill: parent + acceptedButtons: Qt.LeftButton + hoverEnabled: true - onClicked: { - background.setBackground(modelData) - } + onClicked: { + background.setBackground(modelData) + } - onEntered: function() { - image.opacity = 0.7 - } - onExited: function() { - image.opacity = 1.0 + onEntered: function() { + image.opacity = 0.7 + } + onExited: function() { + image.opacity = 1.0 + } + + onPressedChanged: item.scale = pressed ? 0.97 : 1.0 } + } + } - onPressedChanged: item.scale = pressed ? 0.97 : 1.0 + function calcExtraSpacing(cellSize, containerSize) { + var availableColumns = Math.floor(containerSize / cellSize) + var extraSpacing = 0 + if (availableColumns > 0) { + var allColumnSize = availableColumns * cellSize + var extraSpace = Math.max(containerSize - allColumnSize, FishUI.Units.largeSpacing) + extraSpacing = extraSpace / availableColumns } + return Math.floor(extraSpacing) } } - function calcExtraSpacing(cellSize, containerSize) { - var availableColumns = Math.floor(containerSize / cellSize) - var extraSpacing = 0 - if (availableColumns > 0) { - var allColumnSize = availableColumns * cellSize - var extraSpace = Math.max(containerSize - allColumnSize, FishUI.Units.largeSpacing) - extraSpacing = extraSpace / availableColumns - } - return Math.floor(extraSpacing) + Loader { + Layout.fillWidth: true + height: item.height + visible: background.backgroundType === 1 + sourceComponent: colorView } } } diff --git a/src/resources.qrc b/src/resources.qrc index 9f4e8d3..c7eba51 100644 --- a/src/resources.qrc +++ b/src/resources.qrc @@ -24,7 +24,6 @@ qml/HorizontalDivider.qml qml/DockPage.qml qml/LanguagePage.qml - qml/NetworkPage.qml images/locked.svg images/checked.svg images/light/network-wired.svg @@ -42,10 +41,7 @@ images/view-refresh.svg images/info.svg qml/IconButton.qml - qml/WirelessItem.qml images/go-previous.svg - qml/WirelessDetailsDialog.qml - qml/WiredItem.qml qml/AccountsPage.qml qml/Hideable.qml qml/AddUserDialog.qml @@ -85,5 +81,10 @@ images/sidebar/light/language.svg images/sidebar/light/network.svg images/sidebar/light/wallpaper.svg + qml/NetworkPage/WifiView.qml + qml/NetworkPage/main.qml + qml/NetworkPage/WifiItem.qml + qml/NetworkPage/WirelessDetailsDialog.qml + qml/NetworkPage/WiredItem.qml