Warning, /plasma/plasma-nm/applet/contents/ui/Toolbar.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 QtQuick.Layouts 1.2 0009 import org.kde.plasma.components 3.0 as PlasmaComponents3 0010 import org.kde.plasma.core 2.0 as PlasmaCore 0011 import org.kde.kirigami 2.20 as Kirigami 0012 import org.kde.plasma.extras 2.0 as PlasmaExtras 0013 import org.kde.plasma.networkmanagement as PlasmaNM 0014 import org.kde.kcmutils as KCMUtils 0015 0016 RowLayout { 0017 id: toolbar 0018 0019 readonly property var displayWifiMessage: !wifiSwitchButton.checked && wifiSwitchButton.visible 0020 readonly property var displayWwanMessage: !wwanSwitchButton.checked && wwanSwitchButton.visible 0021 readonly property var displayplaneModeMessage: planeModeSwitchButton.checked && planeModeSwitchButton.visible 0022 0023 property bool hasConnections 0024 property alias searchTextField: searchTextField 0025 0026 PlasmaNM.EnabledConnections { 0027 id: enabledConnections 0028 0029 // When user interactively toggles a checkbox, a binding may be 0030 // preserved, but the state gets out of sync until next relevant 0031 // notify signal is dispatched. So, we refresh the bindings here. 0032 0033 onWirelessEnabledChanged: wifiSwitchButton.checked = Qt.binding(() => 0034 wifiSwitchButton.administrativelyEnabled && enabledConnections.wirelessEnabled 0035 ); 0036 0037 onWwanEnabledChanged: wwanSwitchButton.checked = Qt.binding(() => 0038 wwanSwitchButton.administrativelyEnabled && enabledConnections.wwanEnabled 0039 ); 0040 } 0041 0042 spacing: Kirigami.Units.smallSpacing * 3 0043 0044 RowLayout { 0045 // Add margin before switches for consistency with other applets 0046 Layout.leftMargin: Kirigami.Units.smallSpacing 0047 0048 spacing: parent.spacing 0049 0050 // Only show when switches are visible (and avoid parent spacing otherwise) 0051 visible: availableDevices.wirelessDeviceAvailable || availableDevices.modemDeviceAvailable 0052 0053 PlasmaComponents3.Switch { 0054 id: wifiSwitchButton 0055 0056 // can't overload Item::enabled, because it's being used for other things, like Edit Mode on a desktop 0057 readonly property bool administrativelyEnabled: 0058 !PlasmaNM.Configuration.airplaneModeEnabled 0059 && availableDevices.wirelessDeviceAvailable 0060 && enabledConnections.wirelessHwEnabled 0061 0062 checked: administrativelyEnabled && enabledConnections.wirelessEnabled 0063 enabled: administrativelyEnabled 0064 0065 icon.name: administrativelyEnabled ? "network-wireless-on" : "network-wireless-off" 0066 visible: availableDevices.wirelessDeviceAvailable 0067 0068 KeyNavigation.right: wwanSwitchButton.visible ? wwanSwitchButton : wwanSwitchButton.KeyNavigation.right 0069 0070 onToggled: handler.enableWireless(checked); 0071 0072 PlasmaComponents3.ToolTip { 0073 text: i18n("Enable Wi-Fi") 0074 } 0075 0076 PlasmaComponents3.BusyIndicator { 0077 parent: wifiSwitchButton 0078 anchors { 0079 fill: wifiSwitchButton.contentItem 0080 leftMargin: wifiSwitchButton.indicator.width + wifiSwitchButton.spacing 0081 } 0082 z: 1 0083 0084 // Scanning may be too fast to notice. Prolong the animation up to at least `humanMoment`. 0085 running: handler.scanning || timer.running 0086 Timer { 0087 id: timer 0088 interval: Kirigami.Units.humanMoment 0089 } 0090 Connections { 0091 target: handler 0092 function onScanningChanged() { 0093 if (handler.scanning) { 0094 timer.restart(); 0095 } 0096 } 0097 } 0098 } 0099 } 0100 0101 PlasmaComponents3.Switch { 0102 id: wwanSwitchButton 0103 0104 // can't overload Item::enabled, because it's being used for other things, like Edit Mode on a desktop 0105 readonly property bool administrativelyEnabled: 0106 !PlasmaNM.Configuration.airplaneModeEnabled 0107 && availableDevices.modemDeviceAvailable 0108 && enabledConnections.wwanHwEnabled 0109 0110 checked: administrativelyEnabled && enabledConnections.wwanEnabled 0111 enabled: administrativelyEnabled 0112 0113 icon.name: administrativelyEnabled ? "network-mobile-on" : "network-mobile-off" 0114 visible: availableDevices.modemDeviceAvailable 0115 0116 KeyNavigation.left: wifiSwitchButton 0117 KeyNavigation.right: planeModeSwitchButton.visible ? planeModeSwitchButton : planeModeSwitchButton.KeyNavigation.right 0118 0119 onToggled: handler.enableWwan(checked); 0120 0121 PlasmaComponents3.ToolTip { 0122 text: i18n("Enable mobile network") 0123 } 0124 } 0125 0126 PlasmaComponents3.Switch { 0127 id: planeModeSwitchButton 0128 0129 property bool initialized: false 0130 0131 checked: PlasmaNM.Configuration.airplaneModeEnabled 0132 0133 icon.name: PlasmaNM.Configuration.airplaneModeEnabled ? "network-flightmode-on" : "network-flightmode-off" 0134 0135 visible: availableDevices.modemDeviceAvailable || availableDevices.wirelessDeviceAvailable 0136 0137 KeyNavigation.left: wwanSwitchButton.visible ? wwanSwitchButton : wwanSwitchButton.KeyNavigation.left 0138 KeyNavigation.right: hotspotButton.visible ? hotspotButton : hotspotButton.KeyNavigation.right 0139 0140 onToggled: { 0141 handler.enableAirplaneMode(checked); 0142 PlasmaNM.Configuration.airplaneModeEnabled = checked; 0143 } 0144 0145 PlasmaComponents3.ToolTip { 0146 text: planeModeSwitchButton.checked ? 0147 xi18nc("@info", "Disable airplane mode<nl/><nl/>This will enable Wi-Fi and Bluetooth") : 0148 xi18nc("@info", "Enable airplane mode<nl/><nl/>This will disable Wi-Fi and Bluetooth") 0149 } 0150 } 0151 } 0152 0153 PlasmaComponents3.ToolButton { 0154 id: hotspotButton 0155 0156 visible: handler.hotspotSupported 0157 checkable: true 0158 0159 text: i18n("Hotspot") 0160 icon.name: "network-wireless-on" 0161 0162 KeyNavigation.left: planeModeSwitchButton.visible ? planeModeSwitchButton : planeModeSwitchButton.KeyNavigation.left 0163 KeyNavigation.right: searchTextField 0164 0165 onClicked: { 0166 if (PlasmaNM.Configuration.hotspotConnectionPath) { 0167 checked = false 0168 handler.stopHotspot() 0169 } else { 0170 checked = true 0171 handler.createHotspot() 0172 } 0173 } 0174 0175 PlasmaComponents3.ToolTip { 0176 id: tooltip 0177 } 0178 0179 Connections { 0180 target: handler 0181 function onHotspotCreated() { 0182 hotspotButton.checked = true 0183 tooltip.text = i18n("Disable Hotspot") 0184 } 0185 0186 function onHotspotDisabled() { 0187 hotspotButton.checked = false 0188 tooltip.text = i18n("Create Hotspot") 0189 } 0190 } 0191 0192 Component.onCompleted: { 0193 checked = PlasmaNM.Configuration.hotspotConnectionPath 0194 tooltip.text = PlasmaNM.Configuration.hotspotConnectionPath ? i18n("Disable Hotspot") : i18n("Create Hotspot") 0195 } 0196 } 0197 0198 PlasmaExtras.SearchField { 0199 id: searchTextField 0200 0201 Layout.fillWidth: true 0202 0203 enabled: toolbar.hasConnections || text.length > 0 0204 0205 // This uses expanded to ensure the binding gets reevaluated 0206 // when the plasmoid is shown again and that way ensure we are 0207 // always in the correct state on show. 0208 focus: mainWindow.expanded && !Kirigami.InputMethod.willShowOnActive 0209 0210 KeyNavigation.left: hotspotButton.visible ? hotspotButton : hotspotButton.KeyNavigation.left 0211 KeyNavigation.right: openEditorButton 0212 0213 onTextChanged: { 0214 appletProxyModel.setFilterFixedString(text) 0215 } 0216 } 0217 0218 PlasmaComponents3.ToolButton { 0219 id: openEditorButton 0220 0221 visible: mainWindow.kcmAuthorized && !(plasmoid.containmentDisplayHints & PlasmaCore.Types.ContainmentDrawsPlasmoidHeading) 0222 0223 icon.name: "configure" 0224 0225 PlasmaComponents3.ToolTip { 0226 text: i18n("Configure network connections…") 0227 } 0228 0229 onClicked: { 0230 KCMUtils.KCMLauncher.openSystemSettings(mainWindow.kcm) 0231 } 0232 } 0233 }