commit efbda53ab46810930b67372cad2f7815e51d5d22 Author: Flummi Date: Wed Jan 17 20:06:16 2024 +0100 first commit diff --git a/README.md b/README.md new file mode 100644 index 0000000..5688a74 --- /dev/null +++ b/README.md @@ -0,0 +1 @@ +# Headset Battery Widget diff --git a/package/contents/icons/battery_100.png b/package/contents/icons/battery_100.png new file mode 100644 index 0000000..47584f6 Binary files /dev/null and b/package/contents/icons/battery_100.png differ diff --git a/package/contents/icons/battery_20.png b/package/contents/icons/battery_20.png new file mode 100644 index 0000000..f87f86c Binary files /dev/null and b/package/contents/icons/battery_20.png differ diff --git a/package/contents/icons/battery_40.png b/package/contents/icons/battery_40.png new file mode 100644 index 0000000..cca846e Binary files /dev/null and b/package/contents/icons/battery_40.png differ diff --git a/package/contents/icons/battery_60.png b/package/contents/icons/battery_60.png new file mode 100644 index 0000000..225254f Binary files /dev/null and b/package/contents/icons/battery_60.png differ diff --git a/package/contents/icons/battery_80.png b/package/contents/icons/battery_80.png new file mode 100644 index 0000000..a4d9e77 Binary files /dev/null and b/package/contents/icons/battery_80.png differ diff --git a/package/contents/icons/battery_charging.png b/package/contents/icons/battery_charging.png new file mode 100644 index 0000000..3e3b6a8 Binary files /dev/null and b/package/contents/icons/battery_charging.png differ diff --git a/package/contents/icons/battery_nc.png b/package/contents/icons/battery_nc.png new file mode 100644 index 0000000..c239492 Binary files /dev/null and b/package/contents/icons/battery_nc.png differ diff --git a/package/contents/ui/main.qml b/package/contents/ui/main.qml new file mode 100644 index 0000000..cc7b8cd --- /dev/null +++ b/package/contents/ui/main.qml @@ -0,0 +1,65 @@ +import QtQuick 2.0 +import QtQuick.Layouts 1.3 +import org.kde.plasma.plasmoid 2.0 +import org.kde.plasma.core 2.0 as PlasmaCore + +Item { + id: main + + property int batteryPercent: -2 + + PlasmaCore.DataSource { + id: hsSource + engine: "executable" + connectedSources: ["headsetcontrol -bc"] + interval: 2000 + onNewData: { + if(data['exit_code'] > 0) + return console.log('error lol'); + batteryPercent = data['stdout']; + } + } + + Plasmoid.preferredRepresentation: Plasmoid.compactRepresentation + + Plasmoid.compactRepresentation: Item { + Layout.minimumWidth: units.iconSizes.medium + + Image { + anchors.fill: parent + smooth: true + fillMode: Image.PreserveAspectFit + source: batteryIcon() + Plasmoid.toolTipMainText: "battery status:" + Plasmoid.toolTipSubText: batteryStatus() + } + + function batteryIcon() { + let iconName = "battery_100" + if(batteryPercent == -1) // charing + iconName = "battery_charging" + else if(batteryPercent == -2) // not connected + iconName = "battery_nc"; + else if(batteryPercent > 80) + iconName = "battery_100"; + else if(batteryPercent > 60) + iconName = "battery_80"; + else if(batteryPercent > 40) + iconName = "battery_60"; + else if(batteryPercent > 20) + iconName = "battery_40"; + else + iconName = "battery_20"; + return "../icons/" + iconName + ".png"; + } + + function batteryStatus() { + if(batteryPercent == -1) + return "charging"; + else if(batteryPercent == -2) + return "not connected"; + else + return batteryPercent + " %"; + } + } +} diff --git a/package/metadata.json b/package/metadata.json new file mode 100644 index 0000000..d0eb920 --- /dev/null +++ b/package/metadata.json @@ -0,0 +1,21 @@ +{ + "KPlugin": { + "Authors": [{ + "Email": "flummi@srv.fail", + "Name": "Flummi" + }], + "Category": "System Information", + "Dependencies": [ + ], + "Icon": "battery", + "Id": "org.kde.plasma.headsetcontrol-battery-widget", + "Name": "Headset Battery Widget", + "ServiceTypes": [ + "Plasma/Applet" + ], + "Version": "1", + "Website": "https://git.lat/Flummi/headsetcontrol-battery-widget" + }, + "X-Plasma-API": "declarativeappletscript", + "X-Plasma-MainScript": "ui/main.qml" +}