diff --git a/package/contents/config/main.xml b/package/contents/config/main.xml index 1d0ccb3..453d1de 100644 --- a/package/contents/config/main.xml +++ b/package/contents/config/main.xml @@ -22,6 +22,13 @@ #008800 + + 10 + + + true + + false diff --git a/package/contents/ui/CompactRepresentation.qml b/package/contents/ui/CompactRepresentation.qml index 2006016..97958dd 100644 --- a/package/contents/ui/CompactRepresentation.qml +++ b/package/contents/ui/CompactRepresentation.qml @@ -7,13 +7,10 @@ import org.kde.kirigami 2.14 as Kirigami import "./lib/helper.js" as Helper Item { - Layout.minimumWidth: units.iconSizes.medium - Layout.alignment: Qt.AlignHCenter - Rectangle { // battery id: container anchors.fill: parent - anchors.rightMargin: 2 + anchors.rightMargin: 1 anchors.topMargin: 10 - batteryheight anchors.bottomMargin: 10 - batteryheight color: "transparent" diff --git a/package/contents/ui/config/general.qml b/package/contents/ui/config/general.qml index c614066..29e7718 100644 --- a/package/contents/ui/config/general.qml +++ b/package/contents/ui/config/general.qml @@ -17,6 +17,9 @@ QQC2.Pane { property alias cfg_colorHalf: colorHalf.color property alias cfg_colorFull: colorFull.color + property alias cfg_notifications: notifications.checked + property alias cfg_batteryThreshold: batteryThreshold.value + Kirigami.FormLayout { anchors.fill: parent wideMode: false @@ -157,5 +160,40 @@ QQC2.Pane { color: Helper.interpolateColor( 1, [ cfg_colorEmpty.toString(), cfg_colorHalf.toString(), cfg_colorFull.toString() ]) } } + + GridLayout { + columns: 3 + rows: 2 + rowSpacing: 10 + + // first row + Text { + text: "notifications:" + color: PlasmaCore.Theme.textColor + } + PlasmaComponents.CheckBox { + id: notifications + } + Text { + text: "" + } + + // second row + Text { + text: "battery threshold:" + color: PlasmaCore.Theme.textColor + } + PlasmaComponents.Slider { + id: batteryThreshold + value: 10 + minimumValue: 1 + maximumValue: 50 + stepSize: 1 + } + Text { + text: cfg_batteryThreshold + color: PlasmaCore.Theme.textColor + } + } } } diff --git a/package/contents/ui/main.qml b/package/contents/ui/main.qml index b42748d..3ddb34f 100644 --- a/package/contents/ui/main.qml +++ b/package/contents/ui/main.qml @@ -4,6 +4,8 @@ import org.kde.plasma.plasmoid 2.0 import org.kde.plasma.core 2.0 as PlasmaCore import org.kde.kirigami 2.14 as Kirigami +import org.kde.notification 1.0 + import "./lib/helper.js" as Helper Item { @@ -15,10 +17,14 @@ Item { property string colorHalf: Plasmoid.configuration.colorHalf property string colorFull: Plasmoid.configuration.colorFull + property bool notifications: Plasmoid.configuration.notifications + property int batteryThreshold: Plasmoid.configuration.batteryThreshold + property bool debug_active: Plasmoid.configuration.debug_active property int debug_charge: Plasmoid.configuration.debug_charge property int batteryPercent: -2 + property bool notification_sent: false; PlasmaCore.DataSource { id: hsSource @@ -27,15 +33,36 @@ Item { interval: pollingrate * 1e3 onNewData: { if(debug_active) - return batteryPercent = debug_charge; - - return batteryPercent = data['exit code'] > 0 - ? -2 // not connected - : data['stdout']; + batteryPercent = debug_charge; + else + batteryPercent = data['exit code'] > 0 + ? -2 // not connected + : +data.stdout; + + // send notification if necessary + if(batteryPercent <= batteryThreshold && batteryPercent >= 0 && !notification_sent && notifications) { + notification_sent = true; + notification.text = "Battery Level is low (" + batteryPercent + "%)"; + notification.title = "Headset Battery Level Alert"; + notification.iconName = "notification-battery-low"; + notification.sendEvent(); + } + else // reset notifications if battery level is over batteryThreshold + notification_sent = false; + + return; } } Plasmoid.preferredRepresentation: Plasmoid.compactRepresentation Plasmoid.fullRepresentation: FullRepresentation{} Plasmoid.compactRepresentation: CompactRepresentation{} + + Notification { + id: notification + componentName: "plasma_workspace" + eventId: "notification" + flags: Notification.Persistent + urgency: Notification.HighUrgency + } }