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 2.0 as PlasmaCore
0011 import org.kde.plasma.plasmoid 2.0
0012 import org.kde.plasma.private.bluetooth 1.0 as PlasmaBt
0013
0014 import org.kde.bluezqt 1.0 as BluezQt
0015 import org.kde.kquickcontrolsaddons 2.0
0016
0017 Item {
0018 id: bluetoothApplet
0019
0020 property var connectedDevices: []
0021 property int runningActions: 0
0022 property QtObject btManager: BluezQt.Manager
0023
0024 Plasmoid.switchWidth: PlasmaCore.Units.gridUnit * 15
0025 Plasmoid.switchHeight: PlasmaCore.Units.gridUnit * 10
0026
0027 Plasmoid.compactRepresentation: CompactRepresentation { }
0028 Plasmoid.fullRepresentation: FullRepresentation { }
0029
0030 Plasmoid.status: (btManager.bluetoothOperational) ? PlasmaCore.Types.ActiveStatus : PlasmaCore.Types.PassiveStatus
0031 Plasmoid.busy: runningActions > 0
0032
0033 Plasmoid.icon: {
0034 if (connectedDevices.length > 0) {
0035 return "preferences-system-bluetooth-activated";
0036 }
0037 if (!btManager.bluetoothOperational) {
0038 return "preferences-system-bluetooth-inactive";
0039 }
0040 return "preferences-system-bluetooth";
0041 }
0042 Plasmoid.toolTipMainText: i18n("Bluetooth")
0043 Plasmoid.toolTipSubText: {
0044 if (btManager.bluetoothBlocked) {
0045 return i18n("Bluetooth is disabled; middle-click to enable");
0046 }
0047 if (!btManager.bluetoothOperational) {
0048 if (btManager.adapters.length === 0) {
0049 return i18n("No adapters available");
0050 }
0051 return i18n("Bluetooth is offline");
0052 }
0053
0054 const hint = i18n("Middle-click to disable Bluetooth");
0055
0056 if (connectedDevices.length === 0) {
0057 return "%1\n%2".arg(i18n("No connected devices")).arg(hint);
0058
0059 } else if (connectedDevices.length === 1) {
0060 const device = connectedDevices[0];
0061 const battery = device.battery;
0062 const name = i18n("%1 connected", device.name);
0063 let text = battery
0064 ? "%1 · %2".arg(name).arg(i18n("%1% Battery", battery.percentage))
0065 : name
0066 return "%1\n%2".arg(text).arg(hint);
0067
0068 } else {
0069 let text = i18ncp("Number of connected devices", "%1 connected device", "%1 connected devices", connectedDevices.length);
0070 for (let i = 0; i < connectedDevices.length; ++i) {
0071 const device = connectedDevices[i];
0072 const battery = device.battery;
0073 text += battery
0074 ? "\n \u2022 %1 · %2".arg(device.name).arg(i18n("%1% Battery", battery.percentage))
0075 : "\n \u2022 %1".arg(device.name);
0076 }
0077 text += "\n%1".arg(hint);
0078 return text;
0079 }
0080 }
0081
0082 Connections {
0083 target: btManager
0084
0085 function onDeviceAdded() {
0086 updateConnectedDevices();
0087 }
0088 function onDeviceRemoved() {
0089 updateConnectedDevices();
0090 }
0091 function onDeviceChanged() {
0092 updateConnectedDevices();
0093 }
0094 function onBluetoothBlockedChanged() {
0095 updateConnectedDevices();
0096 }
0097 function onBluetoothOperationalChanged() {
0098 updateConnectedDevices();
0099 }
0100 }
0101
0102 function updateConnectedDevices() {
0103 let _connectedDevices = [];
0104 for (let i = 0; i < btManager.devices.length; ++i) {
0105 const device = btManager.devices[i];
0106 if (device.connected) {
0107 _connectedDevices.push(device);
0108 }
0109 }
0110
0111 if (connectedDevices != _connectedDevices) {
0112 connectedDevices = _connectedDevices;
0113 connectedDevicesChanged();
0114 }
0115 }
0116
0117 function toggleBluetooth() {
0118 const enable = !btManager.bluetoothOperational;
0119 btManager.bluetoothBlocked = !enable;
0120
0121 for (let i = 0; i < btManager.adapters.length; ++i) {
0122 const adapter = btManager.adapters[i];
0123 adapter.powered = enable;
0124 }
0125 }
0126
0127 function action_configure() {
0128 KCMShell.openSystemSettings("kcm_bluetooth");
0129 }
0130
0131 function action_addNewDevice() {
0132 PlasmaBt.LaunchApp.launchWizard();
0133 }
0134
0135 function action_btSwitch() {
0136 toggleBluetooth()
0137 }
0138
0139 Component.onCompleted: {
0140 Plasmoid.removeAction("configure");
0141 Plasmoid.setAction("configure", i18n("Configure &Bluetooth…"), "configure");
0142
0143 Plasmoid.setAction("addNewDevice", i18n("Add New Device…"), "list-add");
0144 Plasmoid.action("addNewDevice").visible = Qt.binding(() => !btManager.bluetoothBlocked);
0145
0146 Plasmoid.setAction("btSwitch", i18n("Enable Bluetooth"), "preferences-system-bluetooth");
0147 Plasmoid.action("btSwitch").priority = 0;
0148 Plasmoid.action("btSwitch").checkable = true;
0149 Plasmoid.action("btSwitch").checked = Qt.binding(() => btManager.bluetoothOperational);
0150 Plasmoid.action("btSwitch").visible = Qt.binding(() => btManager.bluetoothBlocked || btManager.adapters.length > 0);
0151
0152 updateConnectedDevices();
0153 }
0154 }