first commit
BIN
package/contents/icons/battery_100.png
Normal file
After Width: | Height: | Size: 11 KiB |
BIN
package/contents/icons/battery_20.png
Normal file
After Width: | Height: | Size: 5.1 KiB |
BIN
package/contents/icons/battery_40.png
Normal file
After Width: | Height: | Size: 9.8 KiB |
BIN
package/contents/icons/battery_60.png
Normal file
After Width: | Height: | Size: 10 KiB |
BIN
package/contents/icons/battery_80.png
Normal file
After Width: | Height: | Size: 11 KiB |
BIN
package/contents/icons/battery_charging.png
Normal file
After Width: | Height: | Size: 9.7 KiB |
BIN
package/contents/icons/battery_nc.png
Normal file
After Width: | Height: | Size: 17 KiB |
65
package/contents/ui/main.qml
Normal file
|
@ -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 + " %";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
21
package/metadata.json
Normal file
|
@ -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"
|
||||||
|
}
|