diff --git a/mobile/wifi/package/contents/ui/ConnectionEditor.qml b/mobile/wifi/package/contents/ui/ConnectionEditor.qml index ec106a8e..3ac1a6da 100644 --- a/mobile/wifi/package/contents/ui/ConnectionEditor.qml +++ b/mobile/wifi/package/contents/ui/ConnectionEditor.qml @@ -1,115 +1,94 @@ /* * Copyright 2017 Martin Kacej * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU Library General Public License as * published by the Free Software Foundation; either version 2 or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU Library General Public License for more details * * You should have received a copy of the GNU Library General Public * License along with this program; if not, write to the * Free Software Foundation, Inc., * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ import QtQuick 2.6 import QtQuick.Controls 2.2 as Controls import QtQuick.Layouts 1.2 import org.kde.kirigami 2.2 as Kirigami Kirigami.ScrollablePage { property var details property var str: 0 property var connection : ({}) property var enabledSaving: (editorIpSection.enabledSave && editorSecuritySection.enabledSave && ssidField.text) title: i18n("Connection Editor") width: parent.width - ColumnLayout{ - id: columnlayout - // anchors.horizontalCenter: parent.horizontalCenter - + ColumnLayout { Controls.Label { text: i18n("SSID") font.weight: Font.Bold //anchors.horizontalCenter: parent.horizontalCenter } Controls.TextField { id: ssidField //anchors.horizontalCenter: parent.horizontalCenter placeholderText: i18n("None") } IPAddressSetting { id: editorIpSection width: parent.width //anchors.horizontalCenter: parent.horizontalCenter } WirelessSecuritySetting { id: editorSecuritySection anchors.topMargin: units.gridUnit //anchors.horizontalCenter: parent.horizontalCenter width: parent.width } } footer: Item { height: Kirigami.Units.gridUnit * 4 RowLayout { anchors.horizontalCenter: parent.horizontalCenter spacing: Kirigami.Units.gridUnit Controls.Button { enabled: enabledSaving - RowLayout { - anchors.centerIn: parent - Kirigami.Icon { - width: Kirigami.Units.iconSizes.smallMedium - height: width - source: "document-save" - } - Text { - text: i18n("Save") - } - } + text: i18n("Save") + icon.name: "document-save" onPressed: { save() - applicationWindow().pageStack.pop() + kcm.pop() } } Controls.Button { - RowLayout { - anchors.centerIn: parent - Kirigami.Icon { - width: Kirigami.Units.iconSizes.smallMedium - height: width - source: "dialog-cancel" - } - Text { - text: i18n("Cancel") - } - } + icon.name: "dialog-cancel" + text: i18n("Cancel") onPressed: { - applicationWindow().pageStack.pop() + kcm.pop() } } } } function save() { connection = editorIpSection.ipmap connection["id"] = ssidField.text connection["mode"] = "infrastructure" connection["802-11-wireless-security"] = editorSecuritySection.securityMap console.info(connection) kcm.addConnectionFromQML(connection) console.info('Connection saved '+ connection["id"]) } } diff --git a/mobile/wifi/package/contents/ui/TetheringSetting.qml b/mobile/wifi/package/contents/ui/TetheringSetting.qml index d9d5b6e5..9163c887 100644 --- a/mobile/wifi/package/contents/ui/TetheringSetting.qml +++ b/mobile/wifi/package/contents/ui/TetheringSetting.qml @@ -1,253 +1,208 @@ /* * Copyright 2017-2018 Martin Kacej * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU Library General Public License as * published by the Free Software Foundation; either version 2 or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU Library General Public License for more details * * You should have received a copy of the GNU Library General Public * License along with this program; if not, write to the * Free Software Foundation, Inc., * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ import QtQuick 2.6 import QtQuick.Layouts 1.3 import QtQuick.Controls 2.2 as Controls import org.kde.plasma.networkmanagement 0.2 as PlasmaNM -import org.kde.kirigami 2.2 as Kirigami +import org.kde.kirigami 2.10 as Kirigami Kirigami.ScrollablePage { property var connectPath property var devicePath property alias name: hotSpotName.text - header: ColumnLayout { - width: parent.width - anchors.leftMargin: Kirigami.Units.largeSpacing * 2 - - Kirigami.Separator {} - - RowLayout{ - Kirigami.Separator {} - Controls.Label { - anchors.leftMargin: Kirigami.Units.largeSpacing * 2 - text: i18n("Wi-fi hotspot") - Layout.fillWidth: true - font.weight: Font.Bold - } - Controls.Switch { - id: hotSpotSwitch - onCheckedChanged: { - if (checked) { - initTethering() - } else { - disableTethering() - } - } - } - Kirigami.Separator {} - Rectangle{ - height: 1 - Layout.fillWidth: true - color: "black" - } - } - } -// RowLayout { -// width: parent.width -// Controls.Label { -// text: "Wi-fi hotspot" -// Layout.fillWidth: true -// } -// Controls.Switch { -// id: hotSpotSwitch -// onCheckedChanged: { -// if (checked) { -// initTethering() -// } else { -// disableTethering() -// } -// } -// } -// } + title: i18n("Wi-Fi Hotspot") ColumnLayout { spacing: Kirigami.Units.gridUnit Kirigami.Separator{} RowLayout { id: hotSpotStatus spacing: Kirigami.Units.gridUnit property alias text: hotSpotStatusLabel.text Controls.Label { id: hotSpotStatusLabel } Kirigami.Icon { id: hotSpotStatusIcon width: Kirigami.Units.iconSizes.smallMedium height: width source: "network-wireless-disconnected" } } Controls.Button { id: hotSpotConfigButton checkable: true checked: false text: i18n("Configure") onPressed: { loadSettings() } } Column { id: hotSpotSettings width: parent.width / 2 visible: hotSpotConfigButton.checked Column { width: parent.width Controls.Label { text: i18n("SSID") font.weight: Font.Bold } Controls.TextField { id: hotSpotName width: parent.width / 2 placeholderText: i18n("My Hotspot") } } RowLayout { Controls.CheckBox { id: hotSpotConfigHidden checked: false } Controls.Label { text: i18n("Hide this network") } } RowLayout { Controls.CheckBox { id: hotSpotConfigSecurity checked: false } Controls.Label { text: i18n("Protect hotspot with WPA2/PSK password") } } PasswordField { id: hotSpotConfigPassword width: parent.width / 2 visible: hotSpotConfigSecurity.checked securityType: PlasmaNM.Enums.Wpa2Psk } Controls.Button { text: i18n("Save Hotspot configuration") enabled: name && (!hotSpotConfigSecurity.checked || (hotSpotConfigSecurity.checked && hotSpotConfigPassword.acceptableInput)) onPressed: { saveSettings() hotSpotConfigButton.checked = false } } } } - footer: Item { - height: Kirigami.Units.gridUnit * 4 - Controls.Button { - anchors.centerIn: parent - Kirigami.Icon { - anchors.centerIn: parent - width: Kirigami.Units.iconSizes.medium - height: width - source: "dialog-close" - } - onPressed: { - applicationWindow().pageStack.pop() + actions { + main: Kirigami.Action { + icon.name: checked ? "network-wireless-disconnected" : "network-wireless-connected" + text: checked ? i18n("Disable Wi-Fi Hotspot") : i18n("Enable Wi-Fi Hotspot") + checkable: true + onCheckedChanged: { + if (checked) { + initTethering() + } else { + disableTethering() + } } - + } + right: Kirigami.Action { + icon.name: "dialog-close" + text: i18n("Cancel") + onTriggered: kcm.pop() } } Component.onCompleted: { hotSpotStatus.text = i18n("Hotspot is inactive") checkTethering() } function checkTethering() { devicePath = kcm.getAccessPointDevice(); if (devicePath === "") { hotSpotStatus.text = i18n("Not possible to start Access point.") hotSpotStatusIcon.source = "dialog-close" hotSpotSwitch.enabled = false return } connectPath = kcm.getAccessPointConnection() var map = kcm.getActiveConnectionInfo(connectPath); if (map["address"]) { // means AP connection is active hotSpotSwitch.checked = true hotSpotStatus.text = i18n("Access point running: %1", name) } } function initTethering() { connectPath = kcm.getAccessPointConnection() if (connectPath === "") { hotSpotStatus.text = i18n("No suitable configuration found.") hotSpotStatusIcon.source = "error" hotSpotSwitch.checked = false return } loadSettings() handler.activateConnection(connectPath,devicePath,"") hotSpotStatus.text = i18n("Access point running: %1", name) hotSpotStatusIcon.source = "network-wireless-symbolic" } function disableTethering(){ if (connectPath !== "") { handler.deactivateConnection(connectPath,devicePath) hotSpotStatus.text = i18n("Hotspot is inactive") hotSpotStatusIcon.source = "network-wireless-disconnected" } } function saveSettings() { var map = {} map["id"] = name map["mode"] = "ap" map["method"] = "shared" map["hidden"] = hotSpotConfigHidden.checked if (hotSpotConfigSecurity.checked) { var securityMap = {} securityMap["type"] = PlasmaNM.Enums.Wpa2Psk securityMap["password"] = hotSpotConfigPassword.text map["802-11-wireless-security"] = securityMap } if (connectPath === "") { kcm.addConnectionFromQML(map) } else { kcm.updateConnectionFromQML(connectPath,map) } } function loadSettings() { var map = kcm.getConnectionSettings(connectPath,"connection"); name = map["id"] map = kcm.getConnectionSettings(connectPath,"802-11-wireless"); if (map["hidden"]) hotSpotConfigHidden.checked = map["hidden"] map = kcm.getConnectionSettings(connectPath,"802-11-wireless-security") if (map["key-mgmt"]) { hotSpotConfigSecurity.checked = true } hotSpotStatus.text = i18n("Access point available: %1", name) } } diff --git a/mobile/wifi/package/contents/ui/main.qml b/mobile/wifi/package/contents/ui/main.qml index 6e7cbff7..17720133 100644 --- a/mobile/wifi/package/contents/ui/main.qml +++ b/mobile/wifi/package/contents/ui/main.qml @@ -1,216 +1,205 @@ /* * Copyright 2017 Martin Kacej * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU Library General Public License as * published by the Free Software Foundation; either version 2 or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU Library General Public License for more details * * You should have received a copy of the GNU Library General Public * License along with this program; if not, write to the * Free Software Foundation, Inc., * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ import QtQuick 2.6 import QtQuick.Layouts 1.2 import QtQuick.Controls 2.2 as Controls import org.kde.plasma.networkmanagement 0.2 as PlasmaNM -import org.kde.kirigami 2.5 as Kirigami +import org.kde.kirigami 2.10 as Kirigami import org.kde.kcm 1.1 SimpleKCM { id: main PlasmaNM.Handler { id: handler onWirelessScanTimerEnabled: { if (enabled) { scanTimer.restart() } else { scanTimer.stop() } } } PlasmaNM.EnabledConnections { id: enabledConnections onWirelessEnabledChanged: { wifiSwitchButton.checked = wifiSwitchButton.enabled && enabled } } PlasmaNM.NetworkModel { id: connectionModel } PlasmaNM.MobileProxyModel { id: mobileProxyModel sourceModel: connectionModel showSavedMode: false } Component.onCompleted: handler.requestScan() Timer { id: scanTimer interval: 15000 repeat: true running: parent.visible onTriggered: handler.requestScan() } header: Kirigami.InlineMessage { id: inlineError Layout.fillWidth: true showCloseButton: true visible: false type: Kirigami.MessageType.Warning Connections { target: handler onConnectionActivationFailed: { inlineError.text = message; inlineError.visible = true; } } } ListView { id: view anchors.fill: parent clip: true width: parent.width currentIndex: -1 boundsBehavior: Flickable.StopAtBounds - header: Controls.Label { - leftPadding: Kirigami.Units.smallSpacing + header: Kirigami.ListSectionHeader { text: mobileProxyModel.showSavedMode ? i18n("Saved networks") : i18n("Available networks") } model: mobileProxyModel delegate: ConnectionItemDelegate {} } actions.main: Kirigami.Action { iconName: enabledConnections.wirelessEnabled ? "network-wireless-disconnected" : "network-wireless-connected" text: enabledConnections.wirelessEnabled ? i18n("Disable Wi-Fi") : i18n("Enable Wi-Fi") onTriggered: handler.enableWireless(!enabledConnections.wirelessEnabled); } actions.contextualActions: [ Kirigami.Action { iconName: "edit" text: i18n("Add custom connection") onTriggered: { - applicationWindow().pageStack.push(connectionEditorDialogComponent) + kcm.push("ConnectionEditor.qml") contextDrawer.close() } }, Kirigami.Action { iconName: "edit" text: i18n("Create Hotspot") onTriggered: { - applicationWindow().pageStack.push(tetheringComponent) + kcm.push("TetheringSetting.qml") contextDrawer.close() } }, Kirigami.Action { iconName: "edit" text: i18n("Saved Connections") checkable: true checked: false onTriggered: { mobileProxyModel.showSavedMode = !mobileProxyModel.showSavedMode } } ] /* footer: Controls.Button { width: parent.width text: "ContextualActions" iconName: "edit" onClicked: bottomDrawer.open() } Kirigami.OverlayDrawer { id: bottomDrawer edge: Qt.BottomEdge contentItem: Item { implicitHeight: childrenRect.height + Kirigami.Units.gridUnit ColumnLayout{ anchors.centerIn: parent Controls.Button { text: "Add custom connection" onClicked: applicationWindow().pageStack.push(connectionEditorDialogComponent) } Controls.Button { text: "Create Hotspot" onClicked: showPassiveNotification("Open tethering") } Item { Layout.minimumHeight: Units.gridUnit * 4 } } } } */ Kirigami.OverlayDrawer { id: deleteConnectionDialog property var name property var dbusPath edge: Qt.BottomEdge contentItem: Column { anchors.centerIn: parent spacing: Kirigami.Units.largeSpacing bottomPadding: Kirigami.Units.largeSpacing Controls.Label { anchors.horizontalCenter: parent.horizontalCenter text: i18n("Delete connection %1 from device?", deleteConnectionDialog.name) } Controls.Button { text: i18n("Delete") anchors.horizontalCenter: parent.horizontalCenter onClicked: { handler.removeConnection(deleteConnectionDialog.dbusPath) deleteConnectionDialog.close() } } Controls.Button { text: i18n("Cancel") anchors.horizontalCenter: parent.horizontalCenter onClicked: deleteConnectionDialog.close() } } onVisibleChanged: { if (!visible) { deleteConnectionDialog.name = "" deleteConnectionDialog.dbusPath = "" } } } - - Component { - id: connectionEditorDialogComponent - ConnectionEditor { } - } - - Component { - id: tetheringComponent - TetheringSetting { } - } }