Warning, /plasma/plasma-nm/applet/contents/ui/main.qml is written in an unsupported language. File is not indexed.
0001 /* 0002 SPDX-FileCopyrightText: 2013-2017 Jan Grulich <jgrulich@redhat.com> 0003 0004 SPDX-License-Identifier: LGPL-2.1-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL 0005 */ 0006 0007 import QtQuick 2.2 0008 import org.kde.plasma.plasmoid 2.0 0009 import org.kde.plasma.core 2.0 as PlasmaCore 0010 import org.kde.plasma.networkmanagement 0.2 as PlasmaNM 0011 import org.kde.kquickcontrolsaddons 2.0 0012 import QtQuick.Layouts 1.1 0013 0014 Item { 0015 id: mainWindow 0016 0017 readonly property string kcm: "kcm_networkmanagement" 0018 readonly property bool kcmAuthorized: KCMShell.authorize("kcm_networkmanagement.desktop").length == 1 0019 readonly property bool delayModelUpdates: Plasmoid.fullRepresentationItem !== null 0020 && Plasmoid.fullRepresentationItem.connectionModel !== null 0021 && Plasmoid.fullRepresentationItem.connectionModel.delayModelUpdates 0022 0023 Plasmoid.toolTipMainText: i18n("Networks") 0024 Plasmoid.toolTipSubText: { 0025 const activeConnections = networkStatus.activeConnections; 0026 0027 if (!availableDevices.modemDeviceAvailable && !availableDevices.wirelessDeviceAvailable) { 0028 return activeConnections; 0029 } 0030 0031 if (PlasmaNM.Configuration.airplaneModeEnabled) { 0032 return i18nc("@info:tooltip", "Middle-click to turn off Airplane Mode"); 0033 } else { 0034 const hint = i18nc("@info:tooltip", "Middle-click to turn on Airplane Mode"); 0035 return activeConnections ? `${activeConnections}\n${hint}` : hint; 0036 } 0037 } 0038 0039 Plasmoid.busy: connectionIconProvider.connecting 0040 Plasmoid.icon: connectionIconProvider.connectionTooltipIcon 0041 Plasmoid.switchWidth: PlasmaCore.Units.gridUnit * 10 0042 Plasmoid.switchHeight: PlasmaCore.Units.gridUnit * 10 0043 Plasmoid.compactRepresentation: CompactRepresentation { } 0044 Plasmoid.fullRepresentation: PopupDialog { 0045 id: dialogItem 0046 Layout.minimumWidth: PlasmaCore.Units.iconSizes.medium * 10 0047 Layout.minimumHeight: PlasmaCore.Units.gridUnit * 20 0048 anchors.fill: parent 0049 focus: true 0050 } 0051 0052 function action_wifiSwitch() { 0053 handler.enableWireless(plasmoid.action("wifiSwitch").checked) 0054 } 0055 0056 function action_wwanSwitch() { 0057 handler.enableWwan(plasmoid.action("wifiSwitch").checked) 0058 } 0059 0060 function action_planeModeSwitch() { 0061 let checked = plasmoid.action("wifiSwitch").checked 0062 handler.enableAirplaneMode(checked) 0063 PlasmaNM.Configuration.airplaneModeEnabled = checked 0064 } 0065 0066 function action_configure() { 0067 KCMShell.openSystemSettings(kcm) 0068 } 0069 0070 function action_showPortal() { 0071 Qt.openUrlExternally("http://networkcheck.kde.org") 0072 } 0073 0074 Component.onCompleted: { 0075 Plasmoid.setAction("wifiSwitch", i18n("Enable Wi-Fi"), "network-wireless-on") 0076 plasmoid.action("wifiSwitch").priority = 0 0077 plasmoid.action("wifiSwitch").checkable = true 0078 plasmoid.action("wifiSwitch").checked = Qt.binding(() => enabledConnections.wirelessEnabled) 0079 plasmoid.action("wifiSwitch").visible = Qt.binding(() => enabledConnections.wirelessHwEnabled 0080 && availableDevices.wirelessDeviceAvailable 0081 && !PlasmaNM.Configuration.airplaneModeEnabled) 0082 0083 Plasmoid.setAction("wwanSwitch", i18n("Enable Mobile Network"), "network-mobile-on") 0084 plasmoid.action("wwanSwitch").priority = 0 0085 plasmoid.action("wwanSwitch").checkable = true 0086 plasmoid.action("wwanSwitch").checked = Qt.binding(() => enabledConnections.wwanEnabled) 0087 plasmoid.action("wwanSwitch").visible = Qt.binding(() => enabledConnections.wwanHwEnabled 0088 && availableDevices.modemDeviceAvailable 0089 && !PlasmaNM.Configuration.airplaneModeEnabled) 0090 0091 Plasmoid.setAction("planeModeSwitch", i18n("Enable Airplane Mode"), "network-flightmode-on") 0092 plasmoid.action("planeModeSwitch").priority = 0 0093 plasmoid.action("planeModeSwitch").checkable = true 0094 plasmoid.action("planeModeSwitch").checked = Qt.binding(() => PlasmaNM.Configuration.airplaneModeEnabled) 0095 plasmoid.action("planeModeSwitch").visible = Qt.binding(() => Plasmoid.compactRepresentationItem.airplaneModeAvailable) 0096 0097 plasmoid.setAction("showPortal", i18n("Open Network Login Page…"), "internet-services") 0098 plasmoid.action("showPortal").visible = Qt.binding(() => connectionIconProvider.needsPortal) 0099 0100 plasmoid.removeAction("configure") 0101 if (kcmAuthorized) { 0102 plasmoid.setAction("configure", i18n("&Configure Network Connections…"), "configure", "alt+d, s") 0103 } 0104 } 0105 0106 PlasmaNM.EnabledConnections { 0107 id: enabledConnections 0108 } 0109 0110 PlasmaNM.AvailableDevices { 0111 id: availableDevices 0112 } 0113 0114 PlasmaNM.NetworkStatus { 0115 id: networkStatus 0116 } 0117 0118 PlasmaNM.ConnectionIcon { 0119 id: connectionIconProvider 0120 } 0121 0122 PlasmaNM.Handler { 0123 id: handler 0124 0125 onWifiCodeReceived: (data, connectionName) => { 0126 if (data.length === 0) { 0127 console.error("Cannot create QR code component: Unsupported connection"); 0128 return; 0129 } 0130 0131 const showQRComponent = Qt.createComponent("ShowQR.qml", mainWindow); 0132 if (showQRComponent.status === Component.Error) { 0133 console.warn("Cannot create QR code component:", showQRComponent.errorString()); 0134 return; 0135 } 0136 0137 const obj = showQRComponent.createObject(mainWindow, { 0138 content: data, 0139 title: i18nc("@title:window", "QR Code for %1", connectionName), 0140 }); 0141 obj.showMaximized() 0142 0143 showQRComponent.destroy(); 0144 } 0145 } 0146 0147 Timer { 0148 id: scanTimer 0149 interval: 10200 0150 repeat: true 0151 running: plasmoid.expanded && !PlasmaNM.Configuration.airplaneModeEnabled && !mainWindow.delayModelUpdates 0152 0153 onTriggered: handler.requestScan() 0154 } 0155 }