Compare commits

..

No commits in common. "master" and "plasma5" have entirely different histories.

10 changed files with 147 additions and 188 deletions

View File

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

View File

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

View File

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

View File

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

View File

@ -0,0 +1,44 @@
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,39 +1,19 @@
import QtQuick
import QtQuick.Controls
import QtQuick.Layouts
import org.kde.plasma.core as PlasmaCore
import org.kde.plasma.components as PlasmaComponents
import org.kde.kirigami as Kirigami
import org.kde.kquickcontrols as KQControls
import org.kde.kcmutils as KCM
import QtQuick 2.0
import QtQuick.Layouts 1.3
import org.kde.plasma.core 2.0 as PlasmaCore
import org.kde.plasma.components 2.0 as PlasmaComponents
import QtQuick.Controls 2.5 as QQC2
import org.kde.kirigami 2.4 as Kirigami
import org.kde.kquickcontrols 2.0 as KQControls
import "../lib/helper.js" as Helper
KCM.SimpleKCM {
QQC2.Pane {
id: root
property alias cfg_debug_active: debug_active.checked
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 {
anchors.fill: parent
wideMode: false
@ -60,11 +40,11 @@ KCM.SimpleKCM {
text: "battery charge:"
color: PlasmaCore.Theme.textColor
}
Slider {
PlasmaComponents.Slider {
id: debug_charge
value: 0
from: 0
to: 100
minimumValue: -2
maximumValue: 100
stepSize: 1
}
Text {

View File

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

View File

@ -1,15 +1,12 @@
const batteryLevel = (batteryStatus, batteryPercent) => ({
"BATTERY_UNAVAILABLE": "not connected",
"BATTERY_CHARGING": "charging (" + batteryPercent + "%)",
"HEADSET_UNAVAILABLE": "no headset connected"
})[batteryStatus] ?? batteryPercent + "%";
const batteryLevel = batteryPercent => ({
"-2": "not connected",
"-1": "charging"
})[batteryPercent] ?? batteryPercent + "%";
const batteryIcon = batteryStatus => ({
"BATTERY_UNAVAILABLE": "action-unavailable",
"BATTERY_AVAILABLE": "audio-headphones-symbolic",
"BATTERY_CHARGING": "freon-voltage-symbolic",
"HEADSET_UNAVAILABLE": "dialog-error"
})[batteryStatus] ?? "audio-headphones-symbolic";
const batteryIcon = batteryPercent => ({
"-2": "action-unavailable",
"-1": "reload"
})[batteryPercent] ?? "audio-headphones-symbolic";
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);

View File

@ -1,70 +1,43 @@
import QtQuick
import QtQuick.Layouts
import org.kde.plasma.plasmoid
import org.kde.kirigami as Kirigami
import org.kde.plasma.plasma5support as Plasma5Support
import org.kde.plasma.core as PlasmaCore
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 org.kde.notification
import org.kde.notification 1.0
import "./lib/helper.js" as Helper
PlasmoidItem {
id: root
Plasmoid.status: PlasmaCore.Types.ActiveStatus
Item {
id: main
readonly property int pollingrate: Plasmoid.configuration.pollingrate
readonly property int batteryheight: Plasmoid.configuration.batteryheight
readonly property string colorEmpty: Plasmoid.configuration.colorEmpty
readonly property string colorHalf: Plasmoid.configuration.colorHalf
readonly property string colorFull: Plasmoid.configuration.colorFull
property int pollingrate: Plasmoid.configuration.pollingrate
property int batteryheight: Plasmoid.configuration.batteryheight
property string colorEmpty: Plasmoid.configuration.colorEmpty
property string colorHalf: Plasmoid.configuration.colorHalf
property string colorFull: Plasmoid.configuration.colorFull
readonly property bool notifications: Plasmoid.configuration.notifications
readonly property int batteryThreshold: Plasmoid.configuration.batteryThreshold
property bool notifications: Plasmoid.configuration.notifications
property int batteryThreshold: Plasmoid.configuration.batteryThreshold
readonly property bool debug_active: Plasmoid.configuration.debug_active
readonly property int debug_charge: Plasmoid.configuration.debug_charge
property bool debug_active: Plasmoid.configuration.debug_active
property int debug_charge: Plasmoid.configuration.debug_charge
property string batteryStatus: "BATTERY_UNAVAILABLE"
property int batteryPercent: 0
property bool notification_sent: false
property variant deviceList: []
property int activeDevice: 0
property int batteryPercent: -2
property bool notification_sent: false;
//property variant capabilities: []
Plasma5Support.DataSource {
PlasmaCore.DataSource {
id: hsSource
engine: "executable"
connectedSources: ["headsetcontrol -o json"]
connectedSources: ["headsetcontrol -bc"]
interval: pollingrate * 1e3
onNewData: (_, data) => {
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";
onNewData: {
if(debug_active)
batteryPercent = debug_charge;
}
// hide trayicon if headset isn't connected
root.Plasmoid.status = batteryStatus == "BATTERY_UNAVAILABLE"
? PlasmaCore.Types.PassiveStatus
: PlasmaCore.Types.ActiveStatus;
else
batteryPercent = data['exit code'] > 0
? -2 // not connected
: +data.stdout;
// send notification if necessary
if(batteryPercent <= batteryThreshold && batteryPercent >= 0 && !notification_sent && notifications) {
@ -83,12 +56,9 @@ PlasmoidItem {
}
}
toolTipMainText: "battery level: " + Helper.batteryLevel(batteryStatus, batteryPercent)
toolTipSubText: "polling rate: " + pollingrate + " seconds"
preferredRepresentation: compactRepresentation
compactRepresentation: CompactRepresentation{}
fullRepresentation: Item{}
Plasmoid.preferredRepresentation: Plasmoid.compactRepresentation
Plasmoid.fullRepresentation: FullRepresentation{}
Plasmoid.compactRepresentation: CompactRepresentation{}
Notification {
id: notification
@ -97,32 +67,4 @@ PlasmoidItem {
flags: Notification.DefaultEvent
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,25 +1,24 @@
{
"KPackageStructure": "Plasma/Applet",
"KPlugin": {
"Name": "Headset Battery Widget",
"Description": "Headset Battery Widget",
"Icon": "battery",
"Category": "System Information",
"Authors": [{
"Email": "flummi@srv.fail",
"Name": "Flummi"
}],
"Id": "org.kde.plasma.headsetcontrol-battery-widget",
"License": "",
"Version": "1.7",
"Category": "System Information",
"Dependencies": [
],
"EnabledByDefault": true,
"Website": "https://git.lat/Flummi/headsetcontrol-battery-widget",
"BugReportUrl": "https://git.lat/Flummi/headsetcontrol-battery-widget/issues",
"Icon": "battery",
"Id": "org.kde.plasma.headsetcontrol-battery-widget",
"Name": "Headset Battery Widget",
"ServiceTypes": [
"Plasma/Applet"
]
],
"Version": "1.5",
"Website": "https://git.lat/Flummi/headsetcontrol-battery-widget"
},
"X-Plasma-NotificationArea": true,
"X-Plasma-NotificationAreaCategory": "Hardware",
"X-Plasma-API-Minimum-Version": "6.0"
"X-Plasma-API": "declarativeappletscript",
"X-Plasma-MainScript": "ui/main.qml"
}