Warning, /plasma/bluedevil/src/applet/package/contents/ui/main.qml is written in an unsupported language. File is not indexed.
0001 /* 0002 SPDX-FileCopyrightText: 2013-2014 Jan Grulich <jgrulich@redhat.com> 0003 SPDX-FileCopyrightText: 2014-2015 David Rosca <nowrep@gmail.com> 0004 0005 SPDX-License-Identifier: LGPL-2.1-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL 0006 */ 0007 0008 import QtQuick 2.15 0009 0010 import org.kde.plasma.core as PlasmaCore 0011 import org.kde.kirigami 2.20 as Kirigami 0012 import org.kde.plasma.plasmoid 2.0 0013 import org.kde.plasma.private.bluetooth as PlasmaBt 0014 0015 import org.kde.bluezqt 1.0 as BluezQt 0016 import org.kde.kcmutils 0017 0018 PlasmoidItem { 0019 id: bluetoothApplet 0020 0021 property var connectedDevices: [] 0022 property int runningActions: 0 0023 property QtObject btManager: BluezQt.Manager 0024 property alias addDeviceAction: addAction 0025 property alias enableBluetoothAction: enableAction 0026 0027 switchWidth: Kirigami.Units.gridUnit * 15 0028 switchHeight: Kirigami.Units.gridUnit * 10 0029 0030 // Only exists because the default CompactRepresentation doesn't expose 0031 // a middle-click action. 0032 // TODO remove once it gains that feature. 0033 compactRepresentation: CompactRepresentation { } 0034 fullRepresentation: FullRepresentation { } 0035 0036 Plasmoid.status: (btManager.bluetoothOperational) ? PlasmaCore.Types.ActiveStatus : PlasmaCore.Types.PassiveStatus 0037 Plasmoid.busy: runningActions > 0 0038 0039 Plasmoid.icon: { 0040 if (connectedDevices.length > 0) { 0041 return "network-bluetooth-activated-symbolic"; 0042 } 0043 if (!btManager.bluetoothOperational) { 0044 return "network-bluetooth-inactive-symbolic"; 0045 } 0046 return "network-bluetooth-symbolic"; 0047 } 0048 toolTipMainText: i18n("Bluetooth") 0049 toolTipSubText: { 0050 if (btManager.bluetoothBlocked) { 0051 return i18n("Bluetooth is disabled; middle-click to enable"); 0052 } 0053 if (!btManager.bluetoothOperational) { 0054 if (btManager.adapters.length === 0) { 0055 return i18n("No adapters available"); 0056 } 0057 return i18n("Bluetooth is offline"); 0058 } 0059 0060 const hint = i18n("Middle-click to disable Bluetooth"); 0061 0062 if (connectedDevices.length === 0) { 0063 return "%1\n%2".arg(i18n("No connected devices")).arg(hint); 0064 0065 } else if (connectedDevices.length === 1) { 0066 const device = connectedDevices[0]; 0067 const battery = device.battery; 0068 const name = i18n("%1 connected", device.name); 0069 let text = battery 0070 ? "%1 · %2".arg(name).arg(i18n("%1% Battery", battery.percentage)) 0071 : name 0072 return "%1\n%2".arg(text).arg(hint); 0073 0074 } else { 0075 let text = i18ncp("Number of connected devices", "%1 connected device", "%1 connected devices", connectedDevices.length); 0076 for (let i = 0; i < connectedDevices.length; ++i) { 0077 const device = connectedDevices[i]; 0078 const battery = device.battery; 0079 text += battery 0080 ? "\n \u2022 %1 · %2".arg(device.name).arg(i18n("%1% Battery", battery.percentage)) 0081 : "\n \u2022 %1".arg(device.name); 0082 } 0083 text += "\n%1".arg(hint); 0084 return text; 0085 } 0086 } 0087 0088 Connections { 0089 target: btManager 0090 0091 function onDeviceAdded() { 0092 updateConnectedDevices(); 0093 } 0094 function onDeviceRemoved() { 0095 updateConnectedDevices(); 0096 } 0097 function onDeviceChanged() { 0098 updateConnectedDevices(); 0099 } 0100 function onBluetoothBlockedChanged() { 0101 updateConnectedDevices(); 0102 } 0103 function onBluetoothOperationalChanged() { 0104 updateConnectedDevices(); 0105 } 0106 } 0107 0108 function updateConnectedDevices() { 0109 let _connectedDevices = []; 0110 for (let i = 0; i < btManager.devices.length; ++i) { 0111 const device = btManager.devices[i]; 0112 if (device.connected) { 0113 _connectedDevices.push(device); 0114 } 0115 } 0116 0117 if (connectedDevices != _connectedDevices) { 0118 connectedDevices = _connectedDevices; 0119 connectedDevicesChanged(); 0120 } 0121 } 0122 0123 function toggleBluetooth() { 0124 const enable = !btManager.bluetoothOperational; 0125 btManager.bluetoothBlocked = !enable; 0126 0127 for (let i = 0; i < btManager.adapters.length; ++i) { 0128 const adapter = btManager.adapters[i]; 0129 adapter.powered = enable; 0130 } 0131 } 0132 0133 0134 Plasmoid.contextualActions: [ 0135 PlasmaCore.Action { 0136 id: addAction 0137 text: i18n("Add New Device…") 0138 icon.name: "list-add-symbolic" 0139 visible: !btManager.bluetoothBlocked 0140 onTriggered: PlasmaBt.LaunchApp.launchWizard() 0141 }, 0142 PlasmaCore.Action { 0143 id: enableAction 0144 text: i18n("Enable Bluetooth") 0145 icon.name: "preferences-system-bluetooth-symbolic" 0146 priority: PlasmaCore.Action.LowPriority 0147 checkable: true 0148 checked: btManager.bluetoothOperational 0149 visible: btManager.bluetoothBlocked || btManager.adapters.length > 0 0150 onTriggered: toggleBluetooth() 0151 } 0152 ] 0153 0154 PlasmaCore.Action { 0155 id: configureAction 0156 text: i18n("Configure &Bluetooth…") 0157 icon.name: "configure-symbolic" 0158 onTriggered: KCMLauncher.openSystemSettings("kcm_bluetooth") 0159 } 0160 0161 Component.onCompleted: { 0162 Plasmoid.setInternalAction("configure", configureAction); 0163 0164 updateConnectedDevices(); 0165 } 0166 }