Warning, /plasma/plasma-nm/kcm/qml/ConfigurationDialog.qml is written in an unsupported language. File is not indexed.

0001 /*
0002     SPDX-FileCopyrightText: 2019 Jan Grulich <jgrulich@redhat.com>
0003     SPDX-FileCopyrightText: 2023 ivan tkachenko <me@ratijas.tk>
0004 
0005     SPDX-License-Identifier: LGPL-2.1-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL
0006 */
0007 
0008 import QtQuick
0009 import QtQuick.Controls as QQC2
0010 import QtQuick.Layouts
0011 import org.kde.kcmutils as KCMUtils
0012 import org.kde.kirigami as Kirigami
0013 import org.kde.plasma.networkmanagement as PlasmaNM
0014 
0015 QQC2.ApplicationWindow {
0016     id: root
0017 
0018     required property PlasmaNM.Handler handler
0019 
0020     title: i18nc("@title:window", "Configuration")
0021 
0022     minimumHeight: Kirigami.Units.gridUnit * 6
0023     maximumHeight: page.implicitHeight + dialogButtonBox.implicitHeight
0024     height: maximumHeight
0025     minimumWidth: Kirigami.Units.gridUnit * 15
0026     width: Kirigami.Units.gridUnit * 25
0027 
0028     KCMUtils.SimpleKCM {
0029         id: page
0030 
0031         anchors.fill: parent
0032 
0033         Kirigami.FormLayout {
0034             Kirigami.Separator {
0035                 Kirigami.FormData.label: i18n("General")
0036                 Kirigami.FormData.isSection: true
0037             }
0038 
0039             QQC2.CheckBox {
0040                 id: unlockModem
0041                 Layout.fillWidth: true
0042                 KeyNavigation.down: manageVirtualConnections
0043                 text: i18n("Ask for PIN on modem detection")
0044             }
0045 
0046             QQC2.CheckBox {
0047                 id: manageVirtualConnections
0048                 Layout.fillWidth: true
0049                 KeyNavigation.down: hotspotName
0050                 text: i18n("Show virtual connections")
0051             }
0052 
0053             Kirigami.Separator {
0054                 id: hotspotLabel
0055                 Kirigami.FormData.label: i18n("Hotspot")
0056                 Kirigami.FormData.isSection: true
0057             }
0058 
0059             QQC2.TextField {
0060                 id: hotspotName
0061                 Layout.fillWidth: true
0062                 KeyNavigation.down: hotspotPassword
0063                 Kirigami.FormData.label: i18nc("@label Hotspot name", "Name:")
0064             }
0065 
0066             Kirigami.PasswordField {
0067                 id: hotspotPassword
0068                 Layout.fillWidth: true
0069                 Kirigami.FormData.label: i18nc("@label Hotspot password", "Password:")
0070                 showPassword: true
0071                 validator: RegularExpressionValidator {
0072                     // useApMode is a context property
0073                     regularExpression: useApMode
0074                         ? /^$|^(?:.{8,64}){1}$/
0075                         : /^$|^(?:.{5}|[0-9a-fA-F]{10}|.{13}|[0-9a-fA-F]{26}){1}$/
0076                 }
0077             }
0078         }
0079 
0080         footer: ColumnLayout {
0081             spacing: 0
0082 
0083             Kirigami.InlineMessage {
0084                 Layout.fillWidth: true
0085                 Layout.margins: Kirigami.Units.largeSpacing
0086                 Layout.bottomMargin: 0
0087                 type: Kirigami.MessageType.Error
0088                 text: i18n("Hotspot name must not be empty")
0089                 visible: handler.hotspotSupported && hotspotName.text === ""
0090             }
0091 
0092             Kirigami.InlineMessage {
0093                 Layout.fillWidth: true
0094                 Layout.margins: Kirigami.Units.largeSpacing
0095                 Layout.bottomMargin: 0
0096                 type: Kirigami.MessageType.Error
0097                 text: useApMode
0098                     ? i18n("Hotspot password must either be empty or consist of anywhere from 8 up to 64 characters")
0099                     : i18n("Hotspot password must either be empty or consist of one of the following:<ul><li>Exactly 5 or 13 any characters</li><li>Exactly 10 or 26 hexadecimal characters:<br/>abcdef, ABCDEF or 0-9</li></ul>")
0100                 visible: handler.hotspotSupported && !hotspotPassword.acceptableInput
0101             }
0102         }
0103     }
0104 
0105     footer: QQC2.DialogButtonBox {
0106         id: dialogButtonBox
0107 
0108         standardButtons: QQC2.DialogButtonBox.Ok | QQC2.DialogButtonBox.Cancel | QQC2.DialogButtonBox.Reset
0109 
0110         onAccepted: root.accept()
0111         onRejected: root.reject()
0112         onReset: root.loadConfiguration()
0113 
0114         KeyNavigation.up: hotspotPassword
0115 
0116         Component.onCompleted: {
0117             const okButton = standardButton(QQC2.DialogButtonBox.Ok);
0118             if (okButton) {
0119                 okButton.enabled = Qt.binding(() => root.acceptableConfiguration());
0120                 hotspotPassword.KeyNavigation.down = okButton;
0121             }
0122         }
0123     }
0124 
0125     Shortcut {
0126         sequences: ["Return", "Enter"]
0127         onActivated: root.accept()
0128     }
0129 
0130     Shortcut {
0131         sequences: [StandardKey.Back, StandardKey.Cancel, StandardKey.Close]
0132         onActivated: root.reject()
0133     }
0134 
0135     // Unfortunately, unlike Dialog, DialogButtonBox lacks accept and reject
0136     // methods. Though unlike DialogButtonBox we also want to make sure that
0137     // OK button is enabled.
0138     function accept() {
0139         if (acceptableConfiguration()) {
0140             saveConfiguration();
0141             close();
0142         }
0143     }
0144 
0145     function reject() {
0146         close();
0147     }
0148 
0149     function acceptableConfiguration(): bool {
0150         if (handler.hotspotSupported) {
0151             return hotspotName.text !== "" && hotspotPassword.acceptableInput;
0152         } else {
0153             return true;
0154         }
0155     }
0156 
0157     function loadConfiguration() {
0158         unlockModem.checked = PlasmaNM.Configuration.unlockModemOnDetection;
0159         manageVirtualConnections.checked = PlasmaNM.Configuration.manageVirtualConnections;
0160         // hotspot
0161         hotspotLabel.visible = handler.hotspotSupported;
0162         hotspotName.visible = handler.hotspotSupported;
0163         hotspotPassword.visible = handler.hotspotSupported;
0164         if (handler.hotspotSupported) {
0165             hotspotName.text = PlasmaNM.Configuration.hotspotName;
0166             hotspotPassword.text = PlasmaNM.Configuration.hotspotPassword;
0167         }
0168     }
0169 
0170     function saveConfiguration() {
0171         PlasmaNM.Configuration.unlockModemOnDetection = unlockModem.checked;
0172         PlasmaNM.Configuration.manageVirtualConnections = manageVirtualConnections.checked;
0173         if (handler.hotspotSupported) {
0174             PlasmaNM.Configuration.hotspotName = hotspotName.text;
0175             PlasmaNM.Configuration.hotspotPassword = hotspotPassword.text;
0176         }
0177     }
0178 
0179     onVisibleChanged: {
0180         if (visible) {
0181             loadConfiguration();
0182             unlockModem.forceActiveFocus(Qt.ActiveWindowFocusReason);
0183         }
0184     }
0185 }