Compare commits

..

7 Commits

Author SHA1 Message Date
83aa943fd9
added contextmenu and hide tray icon 2024-06-08 18:41:43 +02:00
3a1a5588d4
remove fullrepresentation 2024-06-08 18:41:11 +02:00
8b68977425
wrong color 2024-06-07 16:33:19 +02:00
c1dae41baa
update readme 2024-06-07 02:08:19 +02:00
6e47175625
bring back config 2024-06-07 02:05:50 +02:00
b2e7b948fe
irgendwas mit json 2024-06-07 01:56:43 +02:00
6290a78666
plasma6 alpha 2024-03-07 12:44:01 +01:00
10 changed files with 188 additions and 147 deletions

View File

@ -2,25 +2,25 @@
## Requirements ## Requirements
- [HeadsetControl](https://github.com/Sapd/HeadsetControl) - [HeadsetControl](https://github.com/Sapd/HeadsetControl) v3.0.0 or newer
## Install ## Install
``` ```
git clone https://git.lat/Flummi/headsetcontrol-battery-widget.git git clone https://git.lat/Flummi/headsetcontrol-battery-widget.git
cd headsetcontrol-battery-widget cd headsetcontrol-battery-widget
kpackagetool5 -t Plasma/Applet --install ./package kpackagetool6 -t Plasma/Applet --install ./package
``` ```
## Uninstall ## Uninstall
``` ```
kpackagetool5 -t Plasma/Applet --remove org.kde.plasma.headsetcontrol-battery-widget kpackagetool6 -t Plasma/Applet --remove org.kde.plasma.headsetcontrol-battery-widget
``` ```
## Development ## Development
``` ```
cd headsetcontrol-battery-widget cd headsetcontrol-battery-widget
kpackagetool5 -t Plasma/Applet --upgrade ./package ; systemctl --user restart plasma-plasmashell kpackagetool6 -t Plasma/Applet --upgrade ./package ; systemctl --user restart plasma-plasmashell
``` ```

View File

@ -1,5 +1,5 @@
import QtQuick 2.0 import QtQuick
import org.kde.plasma.configuration 2.0 import org.kde.plasma.configuration
ConfigModel { ConfigModel {
ConfigCategory { ConfigCategory {

View File

@ -29,7 +29,7 @@
<default>true</default> <default>true</default>
</entry> </entry>
<!-- debug -->
<entry name="debug_active" type="Bool"> <entry name="debug_active" type="Bool">
<default>false</default> <default>false</default>
</entry> </entry>

View File

@ -1,8 +1,7 @@
import QtQuick 2.15 import QtQuick
import QtQuick.Layouts 1.3 import QtQuick.Layouts
import org.kde.plasma.plasmoid 2.0 import org.kde.plasma.plasmoid
import org.kde.plasma.core 2.0 as PlasmaCore import org.kde.kirigami as Kirigami
import org.kde.kirigami 2.14 as Kirigami
import "./lib/helper.js" as Helper import "./lib/helper.js" as Helper
@ -14,10 +13,8 @@ Item {
anchors.topMargin: 10 - batteryheight anchors.topMargin: 10 - batteryheight
anchors.bottomMargin: 10 - batteryheight anchors.bottomMargin: 10 - batteryheight
color: "transparent" color: "transparent"
border.color: PlasmaCore.Theme.textColor border.color: Kirigami.Theme.textColor
radius: 4 radius: 4
Plasmoid.toolTipMainText: "battery level: " + Helper.batteryLevel(batteryPercent)
Plasmoid.toolTipSubText: "polling rate: " + pollingrate + " seconds"
Item { Item {
anchors.fill: parent anchors.fill: parent
@ -35,8 +32,8 @@ Item {
anchors.horizontalCenter: parent.horizontalCenter anchors.horizontalCenter: parent.horizontalCenter
anchors.topMargin: 1 anchors.topMargin: 1
anchors.bottomMargin: 1 anchors.bottomMargin: 1
source: Helper.batteryIcon(batteryPercent) source: Helper.batteryIcon(batteryStatus)
color: batteryPercent == -1 ? colorFull : PlasmaCore.Theme.textColor color: batteryPercent == -1 ? colorEmpty : Kirigami.Theme.textColor
} }
} }
} }
@ -48,13 +45,6 @@ Item {
radius: 4 radius: 4
height: parent.height / 3 height: parent.height / 3
width: 2 width: 2
color: PlasmaCore.Theme.textColor color: Kirigami.Theme.textColor
}
MouseArea {
anchors.fill: parent
onClicked: {
plasmoid.expanded = !plasmoid.expanded
}
} }
} }

View File

@ -1,44 +0,0 @@
import QtQuick 2.15
import QtQuick.Layouts 1.3
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 "./lib/helper.js" as Helper
Item {
id: fullRep
Layout.preferredWidth: 250 * PlasmaCore.Units.devicePixelRatio
Layout.preferredHeight: 250 * PlasmaCore.Units.devicePixelRatio
Layout.minimumWidth: Layout.preferredWidth
Layout.maximumWidth: Layout.preferredWidth
Layout.minimumHeight: Layout.preferredHeight
Layout.maximumHeight: Layout.preferredHeight
clip: true
ColumnLayout {
id: wrapper
anchors.fill: parent
spacing: 0
RowLayout {
spacing: 0
Layout.fillWidth: true
ColumnLayout {
spacing: 0
// Items
Text {
text: "henlo"
color: PlasmaCore.Theme.textColor
}
}
}
Item {
Layout.fillHeight: true
}
}
}

View File

@ -1,19 +1,39 @@
import QtQuick 2.0 import QtQuick
import QtQuick.Layouts 1.3 import QtQuick.Controls
import org.kde.plasma.core 2.0 as PlasmaCore import QtQuick.Layouts
import org.kde.plasma.components 2.0 as PlasmaComponents import org.kde.plasma.core as PlasmaCore
import QtQuick.Controls 2.5 as QQC2 import org.kde.plasma.components as PlasmaComponents
import org.kde.kirigami 2.4 as Kirigami import org.kde.kirigami as Kirigami
import org.kde.kquickcontrols 2.0 as KQControls import org.kde.kquickcontrols as KQControls
import org.kde.kcmutils as KCM
import "../lib/helper.js" as Helper import "../lib/helper.js" as Helper
QQC2.Pane { KCM.SimpleKCM {
id: root id: root
property alias cfg_debug_active: debug_active.checked property alias cfg_debug_active: debug_active.checked
property alias cfg_debug_charge: debug_charge.value property alias cfg_debug_charge: debug_charge.value
property bool debug_activeDefault
property int debug_chargeDefault
property int cfg_pollingrate
property int cfg_batteryheight
property string cfg_colorEmpty
property string cfg_colorHalf
property string cfg_colorFull
property bool cfg_notifications
property int cfg_batteryThreshold
property int cfg_pollingrateDefault
property int cfg_batteryheightDefault
property string cfg_colorEmptyDefault
property string cfg_colorHalfDefault
property string cfg_colorFullDefault
property bool cfg_notificationsDefault
property int cfg_batteryThresholdDefault
Kirigami.FormLayout { Kirigami.FormLayout {
anchors.fill: parent anchors.fill: parent
wideMode: false wideMode: false
@ -40,11 +60,11 @@ QQC2.Pane {
text: "battery charge:" text: "battery charge:"
color: PlasmaCore.Theme.textColor color: PlasmaCore.Theme.textColor
} }
PlasmaComponents.Slider { Slider {
id: debug_charge id: debug_charge
value: 0 value: 0
minimumValue: -2 from: 0
maximumValue: 100 to: 100
stepSize: 1 stepSize: 1
} }
Text { Text {

View File

@ -1,14 +1,15 @@
import QtQuick 2.0 import QtQuick
import QtQuick.Layouts 1.3 import QtQuick.Controls
import org.kde.plasma.core 2.0 as PlasmaCore import QtQuick.Layouts
import org.kde.plasma.components 2.0 as PlasmaComponents import org.kde.plasma.core as PlasmaCore
import QtQuick.Controls 2.5 as QQC2 import org.kde.plasma.components as PlasmaComponents
import org.kde.kirigami 2.4 as Kirigami import org.kde.kirigami as Kirigami
import org.kde.kquickcontrols 2.0 as KQControls import org.kde.kquickcontrols as KQControls
import org.kde.kcmutils as KCM
import "../lib/helper.js" as Helper import "../lib/helper.js" as Helper
QQC2.Pane { KCM.SimpleKCM {
id: root id: root
property alias cfg_pollingrate: pollingrate.value property alias cfg_pollingrate: pollingrate.value
@ -16,10 +17,22 @@ QQC2.Pane {
property alias cfg_colorEmpty: colorEmpty.color property alias cfg_colorEmpty: colorEmpty.color
property alias cfg_colorHalf: colorHalf.color property alias cfg_colorHalf: colorHalf.color
property alias cfg_colorFull: colorFull.color property alias cfg_colorFull: colorFull.color
property alias cfg_notifications: notifications.checked property alias cfg_notifications: notifications.checked
property alias cfg_batteryThreshold: batteryThreshold.value property alias cfg_batteryThreshold: batteryThreshold.value
property int cfg_pollingrateDefault
property int cfg_batteryheightDefault
property string cfg_colorEmptyDefault
property string cfg_colorHalfDefault
property string cfg_colorFullDefault
property bool cfg_notificationsDefault
property int cfg_batteryThresholdDefault
property bool cfg_debug_active
property int cfg_debug_charge
property bool cfg_debug_activeDefault
property int cfg_debug_chargeDefault
Kirigami.FormLayout { Kirigami.FormLayout {
anchors.fill: parent anchors.fill: parent
wideMode: false wideMode: false
@ -34,11 +47,11 @@ QQC2.Pane {
text: "polling rate:" text: "polling rate:"
color: PlasmaCore.Theme.textColor color: PlasmaCore.Theme.textColor
} }
PlasmaComponents.Slider { Slider {
id: pollingrate id: pollingrate
value: 10 value: 10
minimumValue: 2 from: 2
maximumValue: 60 to: 60
stepSize: 2 stepSize: 2
} }
Text { Text {
@ -51,11 +64,11 @@ QQC2.Pane {
text: "battery height:" text: "battery height:"
color: PlasmaCore.Theme.textColor color: PlasmaCore.Theme.textColor
} }
PlasmaComponents.Slider { Slider {
id: batteryheight id: batteryheight
value: 8.0 value: 8.0
minimumValue: 1 from: 1
maximumValue: 10 to: 10
stepSize: 1 stepSize: 1
} }
Text { Text {
@ -183,11 +196,11 @@ QQC2.Pane {
text: "battery threshold:" text: "battery threshold:"
color: PlasmaCore.Theme.textColor color: PlasmaCore.Theme.textColor
} }
PlasmaComponents.Slider { Slider {
id: batteryThreshold id: batteryThreshold
value: 10 value: 10
minimumValue: 1 from: 1
maximumValue: 50 to: 50
stepSize: 1 stepSize: 1
} }
Text { Text {

View File

@ -1,12 +1,15 @@
const batteryLevel = batteryPercent => ({ const batteryLevel = (batteryStatus, batteryPercent) => ({
"-2": "not connected", "BATTERY_UNAVAILABLE": "not connected",
"-1": "charging" "BATTERY_CHARGING": "charging (" + batteryPercent + "%)",
})[batteryPercent] ?? batteryPercent + "%"; "HEADSET_UNAVAILABLE": "no headset connected"
})[batteryStatus] ?? batteryPercent + "%";
const batteryIcon = batteryPercent => ({ const batteryIcon = batteryStatus => ({
"-2": "action-unavailable", "BATTERY_UNAVAILABLE": "action-unavailable",
"-1": "reload" "BATTERY_AVAILABLE": "audio-headphones-symbolic",
})[batteryPercent] ?? "audio-headphones-symbolic"; "BATTERY_CHARGING": "freon-voltage-symbolic",
"HEADSET_UNAVAILABLE": "dialog-error"
})[batteryStatus] ?? "audio-headphones-symbolic";
const hex2rgb = (hex, h = hex.replace('#', '0x')) => ({ r: h >> 16 & 255, g: h >> 8 & 255, b: h & 255 }); const hex2rgb = (hex, h = hex.replace('#', '0x')) => ({ r: h >> 16 & 255, g: h >> 8 & 255, b: h & 255 });
const rgb2Hex = rgb => "#" + ((1 << 24) + (rgb.r << 16) + (rgb.g << 8) + rgb.b).toString(16).slice(1); const rgb2Hex = rgb => "#" + ((1 << 24) + (rgb.r << 16) + (rgb.g << 8) + rgb.b).toString(16).slice(1);

View File

@ -1,43 +1,70 @@
import QtQuick 2.15 import QtQuick
import QtQuick.Layouts 1.3 import QtQuick.Layouts
import org.kde.plasma.plasmoid 2.0 import org.kde.plasma.plasmoid
import org.kde.plasma.core 2.0 as PlasmaCore import org.kde.kirigami as Kirigami
import org.kde.kirigami 2.14 as Kirigami import org.kde.plasma.plasma5support as Plasma5Support
import org.kde.plasma.core as PlasmaCore
import org.kde.notification 1.0 import org.kde.notification
import "./lib/helper.js" as Helper import "./lib/helper.js" as Helper
Item { PlasmoidItem {
id: main id: root
Plasmoid.status: PlasmaCore.Types.ActiveStatus
property int pollingrate: Plasmoid.configuration.pollingrate readonly property int pollingrate: Plasmoid.configuration.pollingrate
property int batteryheight: Plasmoid.configuration.batteryheight readonly property int batteryheight: Plasmoid.configuration.batteryheight
property string colorEmpty: Plasmoid.configuration.colorEmpty readonly property string colorEmpty: Plasmoid.configuration.colorEmpty
property string colorHalf: Plasmoid.configuration.colorHalf readonly property string colorHalf: Plasmoid.configuration.colorHalf
property string colorFull: Plasmoid.configuration.colorFull readonly property string colorFull: Plasmoid.configuration.colorFull
property bool notifications: Plasmoid.configuration.notifications readonly property bool notifications: Plasmoid.configuration.notifications
property int batteryThreshold: Plasmoid.configuration.batteryThreshold readonly property int batteryThreshold: Plasmoid.configuration.batteryThreshold
property bool debug_active: Plasmoid.configuration.debug_active readonly property bool debug_active: Plasmoid.configuration.debug_active
property int debug_charge: Plasmoid.configuration.debug_charge readonly property int debug_charge: Plasmoid.configuration.debug_charge
property int batteryPercent: -2 property string batteryStatus: "BATTERY_UNAVAILABLE"
property bool notification_sent: false; property int batteryPercent: 0
property bool notification_sent: false
property variant deviceList: []
property int activeDevice: 0
PlasmaCore.DataSource { //property variant capabilities: []
Plasma5Support.DataSource {
id: hsSource id: hsSource
engine: "executable" engine: "executable"
connectedSources: ["headsetcontrol -bc"] connectedSources: ["headsetcontrol -o json"]
interval: pollingrate * 1e3 interval: pollingrate * 1e3
onNewData: { onNewData: (_, data) => {
if(debug_active) const res = JSON.parse(data.stdout);
if(res.device_count === 0) {
batteryStatus = "HEADSET_UNAVAILABLE";
batteryPercent = 0;
root.Plasmoid.status = PlasmaCore.Types.PassiveStatus;
return;
}
//if(capabilities.length != res.devices[activeDevice].capabilities_str.length)
// capabilities = res.devices[activeDevice].capabilities_str;
deviceList = res.devices.map(e => e.product);
batteryPercent = res.devices[activeDevice].battery.level;
batteryStatus = batteryPercent > 0 ? res.devices[activeDevice].battery.status : "BATTERY_UNAVAILABLE";
// debug deshmug
if(debug_active) {
batteryStatus = "BATTERY_AVAILABLE";
batteryPercent = debug_charge; batteryPercent = debug_charge;
else }
batteryPercent = data['exit code'] > 0
? -2 // not connected // hide trayicon if headset isn't connected
: +data.stdout; root.Plasmoid.status = batteryStatus == "BATTERY_UNAVAILABLE"
? PlasmaCore.Types.PassiveStatus
: PlasmaCore.Types.ActiveStatus;
// send notification if necessary // send notification if necessary
if(batteryPercent <= batteryThreshold && batteryPercent >= 0 && !notification_sent && notifications) { if(batteryPercent <= batteryThreshold && batteryPercent >= 0 && !notification_sent && notifications) {
@ -56,9 +83,12 @@ Item {
} }
} }
Plasmoid.preferredRepresentation: Plasmoid.compactRepresentation toolTipMainText: "battery level: " + Helper.batteryLevel(batteryStatus, batteryPercent)
Plasmoid.fullRepresentation: FullRepresentation{} toolTipSubText: "polling rate: " + pollingrate + " seconds"
Plasmoid.compactRepresentation: CompactRepresentation{}
preferredRepresentation: compactRepresentation
compactRepresentation: CompactRepresentation{}
fullRepresentation: Item{}
Notification { Notification {
id: notification id: notification
@ -67,4 +97,32 @@ Item {
flags: Notification.DefaultEvent flags: Notification.DefaultEvent
urgency: Notification.CriticalUrgency urgency: Notification.CriticalUrgency
} }
Instantiator {
model: deviceList
delegate: PlasmaCore.Action {
text: modelData
icon.name: "audio-headphones-symbolic"
/*onTriggered: {
console.log("headset lel");
}*/
}
onObjectAdded: (index, object) => {
Plasmoid.contextualActions.splice(Plasmoid.contextualActions.indexOf(separator2), 0, object)
}
onObjectRemoved: (index, object) => {
Plasmoid.contextualActions.splice(Plasmoid.contextualActions.indexOf(object), 1)
}
}
Plasmoid.contextualActions: [
PlasmaCore.Action {
id: separator1
isSeparator: true
},
PlasmaCore.Action {
id: separator2
isSeparator: true
}
]
} }

View File

@ -1,24 +1,25 @@
{ {
"KPackageStructure": "Plasma/Applet",
"KPlugin": { "KPlugin": {
"Name": "Headset Battery Widget",
"Description": "Headset Battery Widget",
"Icon": "battery",
"Category": "System Information",
"Authors": [{ "Authors": [{
"Email": "flummi@srv.fail", "Email": "flummi@srv.fail",
"Name": "Flummi" "Name": "Flummi"
}], }],
"Category": "System Information",
"Dependencies": [
],
"EnabledByDefault": true,
"Icon": "battery",
"Id": "org.kde.plasma.headsetcontrol-battery-widget", "Id": "org.kde.plasma.headsetcontrol-battery-widget",
"Name": "Headset Battery Widget", "License": "",
"Version": "1.7",
"EnabledByDefault": true,
"Website": "https://git.lat/Flummi/headsetcontrol-battery-widget",
"BugReportUrl": "https://git.lat/Flummi/headsetcontrol-battery-widget/issues",
"ServiceTypes": [ "ServiceTypes": [
"Plasma/Applet" "Plasma/Applet"
], ]
"Version": "1.5",
"Website": "https://git.lat/Flummi/headsetcontrol-battery-widget"
}, },
"X-Plasma-NotificationArea": true, "X-Plasma-NotificationArea": true,
"X-Plasma-NotificationAreaCategory": "Hardware", "X-Plasma-NotificationAreaCategory": "Hardware",
"X-Plasma-API": "declarativeappletscript", "X-Plasma-API-Minimum-Version": "6.0"
"X-Plasma-MainScript": "ui/main.qml"
} }