Warning, /plasma/plasma-mobile/kcms/wifi/ui/main.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.plasma.networkmanagement as PlasmaNM
0010 import org.kde.kirigami as Kirigami
0011 import org.kde.kcmutils
0012 import org.kde.kirigamiaddons.formcard 1 as FormCard
0013 
0014 SimpleKCM {
0015     id: root
0016 
0017     property bool editMode: false
0018 
0019     topPadding: Kirigami.Units.gridUnit
0020     bottomPadding: Kirigami.Units.gridUnit
0021     leftPadding: 0
0022     rightPadding: 0
0023 
0024     actions: [
0025         Kirigami.Action {
0026             text: i18n("Edit")
0027             icon.name: 'entry-edit'
0028             checkable: true
0029             onCheckedChanged: root.editMode = checked
0030         }
0031     ]
0032 
0033     PlasmaNM.Handler {
0034         id: handler
0035     }
0036 
0037     PlasmaNM.EnabledConnections {
0038         id: enabledConnections
0039     }
0040 
0041     PlasmaNM.NetworkModel {
0042         id: connectionModel
0043     }
0044 
0045     PlasmaNM.MobileProxyModel {
0046         id: mobileProxyModel
0047         sourceModel: connectionModel
0048         showSavedMode: false
0049     }
0050 
0051     Component.onCompleted: handler.requestScan()
0052 
0053     Timer {
0054         id: scanTimer
0055         interval: 10200
0056         repeat: true
0057         running: parent.visible
0058 
0059         onTriggered: handler.requestScan()
0060     }
0061 
0062     ConnectDialog {
0063         id: connectionDialog
0064     }
0065 
0066     ColumnLayout {
0067 
0068         Kirigami.InlineMessage {
0069             id: inlineError
0070             showCloseButton: true
0071             Layout.fillWidth: true
0072 
0073             type: Kirigami.MessageType.Warning
0074             Connections {
0075                 target: handler
0076                 function onConnectionActivationFailed(connectionPath, message) {
0077                     inlineError.text = message;
0078                     inlineError.visible = true;
0079                 }
0080             }
0081         }
0082 
0083         FormCard.FormCard {
0084             FormCard.FormSwitchDelegate {
0085                 id: wifiSwitch
0086                 text: i18n("Wi-Fi")
0087                 checked: enabledConnections.wirelessEnabled
0088                 onClicked: {
0089                     handler.enableWireless(checked);
0090                     checked = Qt.binding(() => enabledConnections.wirelessEnabled);
0091                 }
0092             }
0093         }
0094 
0095         FormCard.FormHeader {
0096             visible: savedCard.visible
0097             title: i18n('Saved Networks')
0098         }
0099 
0100         FormCard.FormCard {
0101             id: savedCard
0102             visible: enabledConnections.wirelessEnabled && count > 0
0103 
0104             // number of visible entries
0105             property int count: 0
0106             function updateCount() {
0107                 count = 0;
0108                 for (let i = 0; i < connectedRepeater.count; i++) {
0109                     let item = connectedRepeater.itemAt(i);
0110                     if (item && item.shouldDisplay) {
0111                         count++;
0112                     }
0113                 }
0114             }
0115 
0116             Repeater {
0117                 id: connectedRepeater
0118                 model: mobileProxyModel
0119                 delegate: ConnectionItemDelegate {
0120                     editMode: root.editMode
0121                     
0122                     // connected or saved
0123                     property bool shouldDisplay: (Uuid != "") || ConnectionState === PlasmaNM.Enums.Activated
0124                     onShouldDisplayChanged: savedCard.updateCount()
0125                     
0126                     // separate property for visible since visible is false when the whole card is not visible
0127                     visible: shouldDisplay
0128                 }
0129             }
0130         }
0131 
0132         FormCard.FormHeader {
0133             visible: enabledConnections.wirelessEnabled
0134             title: i18n("Available Networks")
0135         }
0136 
0137         FormCard.FormCard {
0138             id: availableCard
0139             visible: enabledConnections.wirelessEnabled && count > 0
0140 
0141             // number of visible entries
0142             property int count: 0
0143             function updateCount() {
0144                 count = 0;
0145                 for (let i = 0; i < availableRepeater.count; i++) {
0146                     let item = availableRepeater.itemAt(i);
0147                     if (item && item.shouldDisplay) {
0148                         count++;
0149                     }
0150                 }
0151             }
0152 
0153             Repeater {
0154                 id: availableRepeater
0155                 model: mobileProxyModel
0156                 delegate: ConnectionItemDelegate {
0157                     editMode: root.editMode
0158 
0159                     property bool shouldDisplay: !((Uuid != "") || ConnectionState === PlasmaNM.Enums.Activated)
0160                     onShouldDisplayChanged: availableCard.updateCount()
0161                     
0162                     visible: shouldDisplay
0163                 }
0164             }
0165 
0166             FormCard.FormButtonDelegate {
0167                 icon.name: 'list-add'
0168                 text: i18n('Add Custom Connection')
0169                 visible: enabledConnections.wirelessEnabled
0170                 onClicked: kcm.push("NetworkSettings.qml")
0171             }
0172         }
0173     }
0174 }