mirror of
https://invent.kde.org/marcoa/shift-shell.git
synced 2026-08-02 17:54:45 +00:00
quicksettings/bluetooth: set connected devices as status
This commit is contained in:
parent
c07aa84f63
commit
6d1aeae654
1 changed files with 72 additions and 6 deletions
|
|
@ -7,17 +7,83 @@ import org.kde.bluezqt 1.0 as BluezQt
|
||||||
import org.kde.plasma.private.mobileshell 1.0 as MobileShell
|
import org.kde.plasma.private.mobileshell 1.0 as MobileShell
|
||||||
|
|
||||||
MobileShell.QuickSetting {
|
MobileShell.QuickSetting {
|
||||||
|
property QtObject btManager: BluezQt.Manager
|
||||||
|
property var connectedDevices: []
|
||||||
|
|
||||||
|
id: root
|
||||||
|
|
||||||
text: i18n("Bluetooth")
|
text: i18n("Bluetooth")
|
||||||
icon: "network-bluetooth"
|
icon: "network-bluetooth"
|
||||||
settingsCommand: "plasma-open-settings kcm_bluetooth"
|
settingsCommand: "plasma-open-settings kcm_bluetooth"
|
||||||
function toggle() {
|
function toggle() {
|
||||||
var enable = !BluezQt.Manager.bluetoothOperational;
|
const enable = !btManager.bluetoothOperational;
|
||||||
BluezQt.Manager.bluetoothBlocked = !enable;
|
btManager.bluetoothBlocked = !enable;
|
||||||
|
|
||||||
for (var i = 0; i < BluezQt.Manager.adapters.length; ++i) {
|
for (var i = 0; i < btManager.adapters.length; ++i) {
|
||||||
var adapter = BluezQt.Manager.adapters[i];
|
btManager.adapters[i].powered = enable;
|
||||||
adapter.powered = enable;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
enabled: BluezQt.Manager.bluetoothOperational
|
enabled: btManager.bluetoothOperational
|
||||||
|
|
||||||
|
Connections {
|
||||||
|
target: btManager
|
||||||
|
|
||||||
|
function onDeviceAdded() {
|
||||||
|
updateConnectedDevices();
|
||||||
|
}
|
||||||
|
function onDeviceRemoved() {
|
||||||
|
updateConnectedDevices();
|
||||||
|
}
|
||||||
|
function onDeviceChanged() {
|
||||||
|
updateConnectedDevices();
|
||||||
|
}
|
||||||
|
function onBluetoothBlockedChanged() {
|
||||||
|
updateConnectedDevices();
|
||||||
|
}
|
||||||
|
function onBluetoothOperationalChanged() {
|
||||||
|
updateConnectedDevices();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function updateConnectedDevices() {
|
||||||
|
let _connectedDevices = [];
|
||||||
|
for (let i = 0; i < btManager.devices.length; ++i) {
|
||||||
|
const device = btManager.devices[i];
|
||||||
|
if (device.connected) {
|
||||||
|
_connectedDevices.push(device);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (connectedDevices != _connectedDevices) {
|
||||||
|
connectedDevices = _connectedDevices;
|
||||||
|
|
||||||
|
if (connectedDevices.length === 0) {
|
||||||
|
root.status = ""
|
||||||
|
} else if (connectedDevices.length === 1) {
|
||||||
|
root.status = formatDevice(0);
|
||||||
|
} else {
|
||||||
|
let text = "";
|
||||||
|
for (let i = 0; i < connectedDevices.length; i++) {
|
||||||
|
const device = connectedDevices[i];
|
||||||
|
const battery = device.battery;
|
||||||
|
text += formatDevice(i) + " \u2022 ";
|
||||||
|
}
|
||||||
|
|
||||||
|
// trims until the last dot
|
||||||
|
text = text.substring(0, text.length - 2);
|
||||||
|
|
||||||
|
root.status = text;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function formatDevice(deviceIndex) {
|
||||||
|
const device = connectedDevices[deviceIndex];
|
||||||
|
const battery = device.battery;
|
||||||
|
const name = device.name;
|
||||||
|
|
||||||
|
return battery
|
||||||
|
? "%1 · %2".arg(name).arg(battery.percentage)
|
||||||
|
: name;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue