diff --git a/mobile/package/contents/ui/IPDetailsSection.qml b/mobile/package/contents/ui/IPDetailsSection.qml index eb58eb9e..8c04bb8d 100644 --- a/mobile/package/contents/ui/IPDetailsSection.qml +++ b/mobile/package/contents/ui/IPDetailsSection.qml @@ -1,140 +1,157 @@ /* * 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.plasma.components 2.0 as PlasmaComponents ColumnLayout { id: ipmain property var ipmap: ({}) property alias address: manualIPaddress.text property alias gateway: manualIPgateway.text property alias prefix: manualIPprefix.text property alias dns: manualIPdns.text property bool enabledSave: (ipMethodComb.currentIndex == 0 || ( ipMethodComb.currentIndex == 1 && manualIPaddress.acceptableInput && manualIPgateway.acceptableInput && manualIPprefix.acceptableInput && manualIPdns.acceptableInput )) property var ipRegex: /^(([01]?[0-9]?[0-9]|2([0-4][0-9]|5[0-5]))\.){3}([01]?[0-9]?[0-9]|2([0-4][0-9]|5[0-5]))$/ spacing: units.gridUnit + implicitWidth: Kirigami.Units.gridUnit * 20 + width: implicitWidth ColumnLayout { Controls.Label { anchors.left: parent.left text: i18n("IP settings") font.weight: Font.Bold } Controls.ComboBox { id: ipMethodComb + width: parent.width model: [i18n("Automatic"), i18n("Manual")] onCurrentIndexChanged: { if (ipMethodComb.currentIndex == 0) { ipmain.state = "Automatic" + manualIPSettings.visible = false } if (ipMethodComb.currentIndex == 1) { ipmain.state = "Manual" + manualIPSettings.visible = true } } } } ColumnLayout{ id: manualIPSettings Layout.fillWidth: true Controls.Label { text: i18n("IP Address") } Controls.TextField { id: manualIPaddress placeholderText: "193.168.1.128" text: address validator: RegExpValidator { regExp: ipRegex } } Controls.Label { text: i18n("Gateway") } Controls.TextField { id: manualIPgateway placeholderText: "192.168.1.1" text: gateway validator: RegExpValidator { regExp: ipRegex } } Controls.Label { text: i18n("Network prefix length") } Controls.TextField { id: manualIPprefix placeholderText: "32" text: prefix validator: IntValidator { bottom: 1; top: 32; } } Controls.Label { text: i18n("DNS") } Controls.TextField { id: manualIPdns placeholderText: "8.8.8.8" text: dns validator: RegExpValidator { regExp: ipRegex } } } states: [ State { name: "Automatic" - PropertyChanges{ target: manualIPSettings; visible: false } PropertyChanges{ target: ipmain; ipmap: {"method": "auto"} } }, State { - name:"Manual" - PropertyChanges { target: manualIPSettings; visible: true } + name: "Manual" PropertyChanges { target: ipmain; ipmap : { "method": "manual", "address": address, "prefix": prefix, "gateway": gateway, "dns": dns } } } ] + + function setStateFromMap() { + if (!ipmap) + return; + if (ipmap["method"] === "auto") + ipMethodComb.currentIndex = 0 + if (ipmap["method"] === "manual"){ + address = ipmap["address"]; + gateway = ipmap["gateway"]; + prefix = ipmap["prefix"]; + dns = ipmap["dns"]; + ipMethodComb.currentIndex = 1 + } + } } diff --git a/mobile/package/contents/ui/NetworkDetailsView.qml b/mobile/package/contents/ui/NetworkDetailsView.qml index 4b315276..719d92e4 100644 --- a/mobile/package/contents/ui/NetworkDetailsView.qml +++ b/mobile/package/contents/ui/NetworkDetailsView.qml @@ -1,154 +1,164 @@ /* * 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 path property alias signal_strength: signalStrengthLabel.text property alias signal_speed: linkSpeedLabel.text property alias ip_address: ipAddressLabel.text property alias security: securityLabel.text property var settings: ({}) property var activeMap: ({}) + property bool enabledSave: true && detailsIP.enabledSave Column { + id: detailsView + spacing: Kirigami.Units.gridUnit Column { id: staticInfo anchors.bottomMargin: units.gridUnit Row { spacing: units.gridUnit / 2 Controls.Label { font.weight: Font.Bold text: i18n("Strength:") } Controls.Label { id: signalStrengthLabel } } Row { spacing: units.gridUnit / 2 Controls.Label { font.weight: Font.Bold text: i18n("Link Speed:") } Controls.Label { id: linkSpeedLabel } } Row { spacing: units.gridUnit / 2 Controls.Label { font.weight: Font.Bold text: i18n("Security:") } Controls.Label { id: securityLabel } } Row { spacing: units.gridUnit / 2 Controls.Label { font.weight: Font.Bold text: i18n("IP Address:") } Controls.Label { id: ipAddressLabel } } } SecuritySection { id: detailsSecuritySection - } - - RowLayout { - - Controls.Label { - anchors.left: parent.left - text: i18n("Advanced options") - } - Controls.Switch { - id: advancedOptionsSwitch - checked: false - } + anchors.bottomMargin: 10 } IPDetailsSection { id: detailsIP - visible: advancedOptionsSwitch.checked } } actions { + left: Kirigami.Action { + iconName: "document-save" + text: i18n("Save") + enabled: enabledSave + onTriggered: { + save() + applicationWindow().pageStack.pop() + } + } + right: Kirigami.Action { iconName: "dialog-cancel" + text: i18n("Cancel") onTriggered: { applicationWindow().pageStack.pop() } } } function fillDetails() { /* var d = {} for (var i = 0; i < (details.length / 2); i++){ d[details[(i * 2)]] = details[(i * 2) + 1] } if (d['Access point (SSID)']) detailsDialog.titleText = d['Access point (SSID)'] signal_strength = d['Signal strength'] if (d['IPv4 Address']) ip_address = detailsIP.address = d['IPv4 Address'] if (d['Security type']) security = d['Security type'] if (d['Connection speed']) signal_speed = d['Connection speed'] if (activeMap && ipMethodComb.currentIndex == 1) { IPDetailsSection.address = activeMap["address"] IPDetailsSection.dns = activeMap["dns"] IPDetailsSection.prefix = activeMap["prefix"] IPDetailsSection.gateway = activeMap["gateway"] }*/ } function loadNetworkSettings() { console.info(path); settings = utils.getConnectionSettings(path,"connection"); detailsSecuritySection.securityMap = utils.getConnectionSettings(path,"802-11-wireless-security"); detailsIP.ipmap = utils.getConnectionSettings(path,"ipv4"); - console.info(detailsIP.ipmap["method"]); + detailsSecuritySection.setStateFromMap(); + detailsIP.setStateFromMap(); + } + + function save() { + settings = detailsIP.ipmap; + if (detailsSecuritySection.password !== "") { //otherwise password is unchanged + settings["802-11-wireless-security"] = detailsSecuritySection.securityMap; + } + utils.updateConnectionFromQML(path,settings); } } diff --git a/mobile/package/contents/ui/SecuritySection.qml b/mobile/package/contents/ui/SecuritySection.qml index 631715a6..6283040e 100644 --- a/mobile/package/contents/ui/SecuritySection.qml +++ b/mobile/package/contents/ui/SecuritySection.qml @@ -1,137 +1,154 @@ /* * 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.Controls 2.2 as Controls import QtQuick.Layouts 1.2 as Layouts import org.kde.plasma.networkmanagement 0.2 as PlasmaNM +import org.kde.kirigami 2.2 as Kirigami Layouts.ColumnLayout { id:securitySectionView property var securityMap: ({}) property var enabledSave: !wepWpaPasswordField.visible || (wepWpaPasswordField.visible && wepWpaPasswordField.acceptableInput) property alias password: wepWpaPasswordField.text - width: parent.width + + implicitWidth: Kirigami.Units.gridUnit * 20 + width: implicitWidth Column { id: securitySectionHeader width: parent.width anchors { top:parent.top topMargin: units.Gridunit bottomMargin: units.Gridunit left: parent.left } Controls.Label { text: i18n("Security") font.weight: Font.Bold } Controls.ComboBox { id: securityCombobox //anchors.bottomMargin: units.Gridunit + implicitWidth: Kirigami.Units.gridUnit * 15 + //width: parent.width anchors.bottomMargin: 50 model: ListModel { id: securityTypesModel // FIXME just placeholder element to set "text" property as default ListElement { text: "placeholder" } Component.onCompleted: { clear() append({ "text": i18n("None"), "type": PlasmaNM.Enums.NoneSecurity }) append({ "text": i18n("WEP Key"), "type": PlasmaNM.Enums.StaticWep }) append({ "text": i18n("Dynamic WEP"), "type": PlasmaNM.Enums.DynamicWep }) append({ "text": i18n("WPA/WPA2 Personal"), "type": PlasmaNM.Enums.Wpa2Psk }) append({ "text": i18n("WPA/WPA2 Enterprise"), "type": PlasmaNM.Enums.Wpa2Eap }) securityCombobox.currentIndex = 0 } } onCurrentIndexChanged: { securitySectionView.state = securityTypesModel.get(currentIndex).type; } } - - Controls.Label { - anchors.bottomMargin: units.Gridunit - text: securityCombobox.currentText - } } - Layouts.ColumnLayout { + Item { id: wepWpaSecurity anchors.top: securitySectionHeader.bottom width: parent.width - Column { + visible: securityCombobox.currentIndex == 1 || securityCombobox.currentIndex == 3 + PasswordField { + id: wepWpaPasswordField width: parent.width - visible: securityCombobox.currentIndex == 1 || securityCombobox.currentIndex == 3 - PasswordField { - id: wepWpaPasswordField - width: parent.width - securityType: securityTypesModel.get(securityCombobox.currentIndex).type - - } + securityType: securityTypesModel.get(securityCombobox.currentIndex).type } } Layouts.ColumnLayout { id: eap anchors.top: securitySectionHeader.bottom Column { visible: securityCombobox.currentIndex == 2 || securityCombobox.currentIndex == 4 Controls.Label { text: i18n("Authentication") } Controls.ComboBox { id: authComboBox model: [i18n("TLS"), i18n("LEAP"), i18n("FAST"), i18n("Tunneled TLS"), i18n("Protected EAP")] // more - SIM, AKA, PWD ? } Controls.Label{ text: "----Not yet implemented----" color: "red" } } } states: [ State { name: PlasmaNM.Enums.NoneSecurity PropertyChanges { target: securitySectionView; securityMap: {"type" : PlasmaNM.Enums.NoneSecurity } } }, State { name: PlasmaNM.Enums.StaticWep PropertyChanges { target: securitySectionView; securityMap: { "type" : PlasmaNM.Enums.StaticWep, "password" : password } } }, State { name: PlasmaNM.Enums.Wpa2Psk PropertyChanges { target: securitySectionView; securityMap: { "type" : PlasmaNM.Enums.Wpa2Psk, "password" : password } } } - ] + function setStateFromMap(){ + var x = securityMap["key-mgmt"] + switch (x) { + case "none": + securityCombobox.currentIndex = 1 + break; + case "ieee8021x": + securityCombobox.currentIndex = 2 + break; + case "wpa-psk": + securityCombobox.currentIndex = 3 + break; + case "wpa-eap": + securityCombobox.currentIndex = 4 + break; + default: + securityCombobox.currentIndex = 0 + break; + } + wepWpaPasswordField.placeholderText = i18n("(Unchanged)") + securityCombobox.enabled = false + } }