Warning, /plasma/plasma-mobile/kcms/wifi/ui/NetworkSettings.qml is written in an unsupported language. File is not indexed.
0001 // SPDX-FileCopyrightText: 2017 Martin Kacej <m.kacej@atlas.sk> 0002 // SPDX-FileCopyrightText: 2023 Devin Lin <devin@kde.org> 0003 // SPDX-License-Identifier: LGPL-2.0-or-later 0004 0005 import QtQuick 0006 import QtQuick.Layouts 0007 import QtQuick.Controls as Controls 0008 0009 import org.kde.kirigami as Kirigami 0010 import org.kde.plasma.networkmanagement as PlasmaNM 0011 import org.kde.kcmutils 0012 import org.kde.kirigamiaddons.formcard 1 as FormCard 0013 0014 Kirigami.ScrollablePage { 0015 title: path ? wirelessSettings["ssid"] : i18n("Add New Connection") 0016 0017 property var path 0018 0019 property var wirelessSettings: ({}) 0020 property var securitySettings: ({}) 0021 property var ipSettings: ({}) 0022 property var secrets: ({}) 0023 0024 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]))$/ 0025 0026 property bool enabledSave: (ipMethodCombobox.currentIndex == 0 0027 || (ipMethodCombobox.currentIndex == 1 0028 && manualIPaddress.acceptableInput 0029 && manualIPgateway.acceptableInput 0030 && manualIPprefix.acceptableInput 0031 && manualIPdns.acceptableInput)) 0032 0033 actions: [ 0034 Kirigami.Action { 0035 icon.name: "dialog-ok" 0036 text: i18n("Save") 0037 enabled: enabledSave 0038 onTriggered: { 0039 save() 0040 kcm.pop() 0041 } 0042 } 0043 ] 0044 0045 topPadding: Kirigami.Units.gridUnit 0046 bottomPadding: Kirigami.Units.gridUnit 0047 leftPadding: 0 0048 rightPadding: 0 0049 0050 ColumnLayout { 0051 FormCard.FormHeader { 0052 title: i18n('General') 0053 } 0054 0055 FormCard.FormCard { 0056 FormCard.FormTextFieldDelegate { 0057 id: ssidField 0058 label: i18n('SSID') 0059 text: wirelessSettings["ssid"] ? wirelessSettings["ssid"] : "" 0060 enabled: true 0061 onTextChanged: { 0062 ipSettings["id"] = text 0063 } 0064 } 0065 0066 FormCard.FormDelegateSeparator { 0067 above: ssidField 0068 below: hidden 0069 } 0070 0071 FormCard.FormSwitchDelegate { 0072 id: hidden 0073 text: i18n("Hidden Network") 0074 checked: wirelessSettings["hidden"] ? wirelessSettings["hidden"] : false 0075 onToggled: ipSettings["hidden"] = checked 0076 } 0077 } 0078 0079 FormCard.FormHeader { 0080 title: i18n('Security') 0081 } 0082 0083 FormCard.FormCard { 0084 FormCard.FormComboBoxDelegate { 0085 id: securityCombobox 0086 currentIndex: 0 0087 text: i18n('Security type') 0088 model: ListModel { 0089 id: securityTypesModel 0090 // FIXME just placeholder element to set "text" property as default 0091 ListElement { 0092 text: "placeholder" 0093 } 0094 function load() { 0095 clear() 0096 append({ "text": i18n("None"), "type": PlasmaNM.Enums.NoneSecurity }) 0097 append({ "text": i18n("WEP Key"), "type": PlasmaNM.Enums.StaticWep }) 0098 append({ "text": i18n("Dynamic WEP"), "type": PlasmaNM.Enums.DynamicWep }) 0099 append({ "text": i18n("WPA/WPA2 Personal"), "type": PlasmaNM.Enums.Wpa2Psk }) 0100 append({ "text": i18n("WPA/WPA2 Enterprise"), "type": PlasmaNM.Enums.Wpa2Eap }) 0101 switch (securitySettings["key-mgmt"]) { 0102 case "none": 0103 securityCombobox.currentIndex = 0 0104 break 0105 case "ieee8021x": 0106 securityCombobox.currentIndex = 1 0107 break 0108 case "wpa-psk": 0109 securityCombobox.currentIndex = 3 0110 break 0111 case "wpa-eap": 0112 securityCombobox.currentIndex = 4 0113 break 0114 default: 0115 securityCombobox.currentIndex = 0 0116 break 0117 } 0118 } 0119 } 0120 } 0121 0122 FormCard.FormDelegateSeparator { 0123 above: securityCombobox 0124 below: passwordDelegate 0125 visible: passwordDelegate.visible 0126 } 0127 0128 FormCard.FormTextFieldDelegate { 0129 id: passwordDelegate 0130 label: i18n('Password') 0131 echoMode: TextInput.Password 0132 inputMethodHints: Qt.ImhHiddenText 0133 text: secrets["psk"] 0134 visible: securityTypesModel.get(securityCombobox.currentIndex).type !== PlasmaNM.Enums.NoneSecurity 0135 onTextChanged: securitySettings["password"] = text 0136 } 0137 0138 FormCard.FormDelegateSeparator { 0139 above: passwordDelegate 0140 below: authComboBox 0141 visible: authComboBox.visible 0142 } 0143 0144 FormCard.FormComboBoxDelegate { 0145 id: authComboBox 0146 text: i18n("Authentication:") 0147 currentIndex: 0 0148 visible: securityCombobox.currentIndex === 2 0149 || securityCombobox.currentIndex === 4 0150 model: [i18n("TLS"), i18n("LEAP"), i18n("FAST"), i18n( 0151 "Tunneled TLS"), i18n( 0152 "Protected EAP")] // more - SIM, AKA, PWD ? 0153 } 0154 0155 Controls.Label { 0156 visible: securityCombobox.currentIndex !== 3 && securityCombobox.currentIndex !== 0 0157 text: "----Not yet implemented----" 0158 color: "red" 0159 } 0160 } 0161 0162 FormCard.FormHeader { 0163 title: i18n('IP Settings') 0164 } 0165 0166 FormCard.FormCard { 0167 FormCard.FormComboBoxDelegate { 0168 id: ipMethodCombobox 0169 text: i18n('Method') 0170 model: [i18n("Automatic"), i18n("Manual")] 0171 currentIndex: ipSettings["method"] === "manual" ? 1 : 0 0172 property var manualIp: currentIndex === 1 0173 onCurrentIndexChanged: { 0174 ipSettings["method"] = currentIndex === 1 ? "manual" : "auto" 0175 } 0176 } 0177 0178 FormCard.FormDelegateSeparator { 0179 above: ipMethodCombobox 0180 below: manualIPaddress 0181 visible: manualIPaddress.visible 0182 } 0183 0184 FormCard.FormTextFieldDelegate { 0185 id: manualIPaddress 0186 label: i18n("IP Address") 0187 visible: ipMethodCombobox.manualIp 0188 placeholderText: "192.168.1.128" 0189 text: ipSettings["address"] ? ipSettings["address"] : "" 0190 onTextChanged: ipSettings["address"] = text 0191 validator: RegularExpressionValidator { 0192 regularExpression: ipRegex 0193 } 0194 } 0195 0196 FormCard.FormDelegateSeparator { 0197 above: manualIPaddress 0198 below: manualIPgateway 0199 visible: manualIPgateway.visible 0200 } 0201 0202 FormCard.FormTextFieldDelegate { 0203 id: manualIPgateway 0204 label: i18n("Gateway") 0205 visible: ipMethodCombobox.manualIp 0206 placeholderText: "192.168.1.1" 0207 text: ipSettings["gateway"] ? ipSettings["gateway"] : "" 0208 onTextChanged: ipSettings["gateway"] = text 0209 validator: RegularExpressionValidator { 0210 regularExpression: ipRegex 0211 } 0212 } 0213 0214 FormCard.FormDelegateSeparator { 0215 above: manualIPgateway 0216 below: manualIPprefix 0217 visible: manualIPprefix.visible 0218 } 0219 0220 FormCard.FormTextFieldDelegate { 0221 id: manualIPprefix 0222 label: i18n("Network prefix length") 0223 visible: ipMethodCombobox.manualIp 0224 placeholderText: "16" 0225 text: ipSettings["prefix"] ? ipSettings["prefix"] : "" 0226 onTextChanged: ipSettings["prefix"] = text 0227 validator: IntValidator { 0228 bottom: 1 0229 top: 32 0230 } 0231 } 0232 0233 FormCard.FormDelegateSeparator { 0234 above: manualIPprefix 0235 below: manualIPdns 0236 visible: manualIPdns.visible 0237 } 0238 0239 FormCard.FormTextFieldDelegate { 0240 id: manualIPdns 0241 label: i18n("DNS") 0242 visible: ipMethodCombobox.manualIp 0243 placeholderText: "8.8.8.8" 0244 text: ipSettings["dns"] ? ipSettings["dns"] : "" 0245 onTextChanged: ipSettings["dns"] = text 0246 validator: RegularExpressionValidator { 0247 regularExpression: ipRegex 0248 } 0249 } 0250 } 0251 } 0252 0253 Component.onCompleted: { 0254 wirelessSettings = kcm.getConnectionSettings(path, "802-11-wireless") 0255 securitySettings = kcm.getConnectionSettings(path, "802-11-wireless-security") 0256 ipSettings = kcm.getConnectionSettings(path, "ipv4") 0257 secrets = kcm.getConnectionSettings(path, "secrets") 0258 0259 securityTypesModel.load() 0260 } 0261 0262 function save() { 0263 var settings = ipSettings 0264 settings["mode"] = "infrastructure" 0265 securitySettings["type"] = securityTypesModel.get(securityCombobox.currentIndex).type 0266 settings["802-11-wireless-security"] = securitySettings 0267 0268 if (path) 0269 kcm.updateConnectionFromQML(path, settings) 0270 else 0271 kcm.addConnectionFromQML(settings) 0272 } 0273 }