Compare commits
	
		
			28 Commits
		
	
	
		
			efbda53ab4
			...
			plasma5
		
	
	| Author | SHA1 | Date | |
|---|---|---|---|
| 
						
						
							
						
						4adea966fa
	
				 | 
					
					
						|||
| 
						
						
							
						
						d821e5b5c0
	
				 | 
					
					
						|||
| 
						
						
							
						
						f3529afeb1
	
				 | 
					
					
						|||
| 
						
						
							
						
						b15a5946a7
	
				 | 
					
					
						|||
| 
						
						
							
						
						ef3ed2726b
	
				 | 
					
					
						|||
| 
						
						
							
						
						5b423c2ab7
	
				 | 
					
					
						|||
| 
						
						
							
						
						f5ed9d0c64
	
				 | 
					
					
						|||
| 
						
						
							
						
						04ad311289
	
				 | 
					
					
						|||
| 
						
						
							
						
						65959a5c4b
	
				 | 
					
					
						|||
| 
						
						
							
						
						1af112eb52
	
				 | 
					
					
						|||
| 
						
						
							
						
						58c37a9dce
	
				 | 
					
					
						|||
| 
						
						
							
						
						6e4b12a298
	
				 | 
					
					
						|||
| 
						
						
							
						
						ed47f2a542
	
				 | 
					
					
						|||
| 
						
						
							
						
						2b1c3489e6
	
				 | 
					
					
						|||
| 
						
						
							
						
						bd243ec115
	
				 | 
					
					
						|||
| 
						
						
							
						
						de0ae352cb
	
				 | 
					
					
						|||
| 
						
						
							
						
						c36eb8daae
	
				 | 
					
					
						|||
| 
						
						
							
						
						ecf5c67ffb
	
				 | 
					
					
						|||
| 
						
						
							
						
						d51555ee47
	
				 | 
					
					
						|||
| 
						
						
							
						
						92c931d6aa
	
				 | 
					
					
						|||
| 
						
						
							
						
						c6e29f9c15
	
				 | 
					
					
						|||
| 
						
						
							
						
						445a60a862
	
				 | 
					
					
						|||
| 
						
						
							
						
						026f9b740a
	
				 | 
					
					
						|||
| 
						
						
							
						
						4cea131ed0
	
				 | 
					
					
						|||
| 
						
						
							
						
						2d04bddde9
	
				 | 
					
					
						|||
| 
						
						
							
						
						8c221144d3
	
				 | 
					
					
						|||
| 
						
						
							
						
						cf01291e4b
	
				 | 
					
					
						|||
| 
						
						
							
						
						1ff2e30132
	
				 | 
					
					
						
							
								
								
									
										25
									
								
								README.md
									
									
									
									
									
								
							
							
						
						@@ -1 +1,26 @@
 | 
				
			|||||||
# Headset Battery Widget
 | 
					# Headset Battery Widget
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					## Requirements
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					- [HeadsetControl](https://github.com/Sapd/HeadsetControl)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					## Install
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					```
 | 
				
			||||||
 | 
					git clone https://git.lat/Flummi/headsetcontrol-battery-widget.git
 | 
				
			||||||
 | 
					cd headsetcontrol-battery-widget
 | 
				
			||||||
 | 
					kpackagetool5 -t Plasma/Applet --install ./package
 | 
				
			||||||
 | 
					```
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					## Uninstall
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					```
 | 
				
			||||||
 | 
					kpackagetool5 -t Plasma/Applet --remove org.kde.plasma.headsetcontrol-battery-widget
 | 
				
			||||||
 | 
					```
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					## Development
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					```
 | 
				
			||||||
 | 
					cd headsetcontrol-battery-widget
 | 
				
			||||||
 | 
					kpackagetool5 -t Plasma/Applet --upgrade ./package ; systemctl --user restart plasma-plasmashell
 | 
				
			||||||
 | 
					```
 | 
				
			||||||
 
 | 
				
			|||||||
							
								
								
									
										15
									
								
								package/contents/config/config.qml
									
									
									
									
									
										Normal file
									
								
							
							
						
						@@ -0,0 +1,15 @@
 | 
				
			|||||||
 | 
					import QtQuick 2.0
 | 
				
			||||||
 | 
					import org.kde.plasma.configuration 2.0
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					ConfigModel {
 | 
				
			||||||
 | 
					  ConfigCategory {
 | 
				
			||||||
 | 
					    name: i18n("General")
 | 
				
			||||||
 | 
					    icon: "configure"
 | 
				
			||||||
 | 
					    source: "config/general.qml"
 | 
				
			||||||
 | 
					  }
 | 
				
			||||||
 | 
					  ConfigCategory {
 | 
				
			||||||
 | 
					    name: i18n("Debug")
 | 
				
			||||||
 | 
					    icon: "cab_view"
 | 
				
			||||||
 | 
					    source: "config/debug.qml"
 | 
				
			||||||
 | 
					  }
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
							
								
								
									
										40
									
								
								package/contents/config/main.xml
									
									
									
									
									
										Normal file
									
								
							
							
						
						@@ -0,0 +1,40 @@
 | 
				
			|||||||
 | 
					<?xml version="1.0" encoding="UTF-8"?>
 | 
				
			||||||
 | 
					<kcfg xmlns="http://www.kde.org/standards/kcfg/1.0"
 | 
				
			||||||
 | 
					      xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
 | 
				
			||||||
 | 
					      xsi:schemaLocation="http://www.kde.org/standards/kcfg/1.0
 | 
				
			||||||
 | 
					      http://www.kde.org/standards/kcfg/1.0/kcfg.xsd">
 | 
				
			||||||
 | 
					  <kcfgfile name=""/>
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  <group name="General">
 | 
				
			||||||
 | 
					    <entry name="pollingrate" type="Int">
 | 
				
			||||||
 | 
					      <default>10</default>
 | 
				
			||||||
 | 
					    </entry>
 | 
				
			||||||
 | 
					    <entry name="batteryheight" type="Int">
 | 
				
			||||||
 | 
					      <default>8</default>
 | 
				
			||||||
 | 
					    </entry>
 | 
				
			||||||
 | 
					    <entry name="colorEmpty" type="String">
 | 
				
			||||||
 | 
					      <default>#ff0000</default>
 | 
				
			||||||
 | 
					    </entry>
 | 
				
			||||||
 | 
					    <entry name="colorHalf" type="String">
 | 
				
			||||||
 | 
					      <default>#ffff00</default>
 | 
				
			||||||
 | 
					    </entry>
 | 
				
			||||||
 | 
					    <entry name="colorFull" type="String">
 | 
				
			||||||
 | 
					      <default>#008800</default>
 | 
				
			||||||
 | 
					    </entry>
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    <entry name="batteryThreshold" type="Int">
 | 
				
			||||||
 | 
					      <default>10</default>
 | 
				
			||||||
 | 
					    </entry>
 | 
				
			||||||
 | 
					    <entry name="notifications" type="Bool">
 | 
				
			||||||
 | 
					      <default>true</default>
 | 
				
			||||||
 | 
					    </entry>
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    <!-- debug -->
 | 
				
			||||||
 | 
					    <entry name="debug_active" type="Bool">
 | 
				
			||||||
 | 
					      <default>false</default>
 | 
				
			||||||
 | 
					    </entry>
 | 
				
			||||||
 | 
					    <entry name="debug_charge" type="Int">
 | 
				
			||||||
 | 
					      <default>0</default>
 | 
				
			||||||
 | 
					    </entry>
 | 
				
			||||||
 | 
					  </group>
 | 
				
			||||||
 | 
					</kcfg>
 | 
				
			||||||
| 
		 Before Width: | Height: | Size: 11 KiB  | 
| 
		 Before Width: | Height: | Size: 5.1 KiB  | 
| 
		 Before Width: | Height: | Size: 9.8 KiB  | 
| 
		 Before Width: | Height: | Size: 10 KiB  | 
| 
		 Before Width: | Height: | Size: 11 KiB  | 
| 
		 Before Width: | Height: | Size: 9.7 KiB  | 
| 
		 Before Width: | Height: | Size: 17 KiB  | 
							
								
								
									
										60
									
								
								package/contents/ui/CompactRepresentation.qml
									
									
									
									
									
										Normal file
									
								
							
							
						
						@@ -0,0 +1,60 @@
 | 
				
			|||||||
 | 
					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 {
 | 
				
			||||||
 | 
					  Rectangle { // battery
 | 
				
			||||||
 | 
					    id: container
 | 
				
			||||||
 | 
					    anchors.fill: parent
 | 
				
			||||||
 | 
					    anchors.rightMargin: 1
 | 
				
			||||||
 | 
					    anchors.topMargin: 10 - batteryheight
 | 
				
			||||||
 | 
					    anchors.bottomMargin: 10 - batteryheight
 | 
				
			||||||
 | 
					    color: "transparent"
 | 
				
			||||||
 | 
					    border.color: PlasmaCore.Theme.textColor
 | 
				
			||||||
 | 
					    radius: 4
 | 
				
			||||||
 | 
					    Plasmoid.toolTipMainText: "battery level: " + Helper.batteryLevel(batteryPercent)
 | 
				
			||||||
 | 
					    Plasmoid.toolTipSubText: "polling rate: " + pollingrate + " seconds"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    Item {
 | 
				
			||||||
 | 
					      anchors.fill: parent
 | 
				
			||||||
 | 
					      anchors.margins: 2
 | 
				
			||||||
 | 
					      Rectangle { // battery fill
 | 
				
			||||||
 | 
					        anchors.left: parent.left
 | 
				
			||||||
 | 
					        anchors.top: parent.top
 | 
				
			||||||
 | 
					        anchors.bottom: parent.bottom
 | 
				
			||||||
 | 
					        color: Helper.interpolateColor(batteryPercent / 100, [ colorEmpty, colorHalf, colorFull ])
 | 
				
			||||||
 | 
					        width: parent.width * Math.max(0, Math.min(batteryPercent, 100)) / 100
 | 
				
			||||||
 | 
					      }
 | 
				
			||||||
 | 
					      Kirigami.Icon { // headphones icon
 | 
				
			||||||
 | 
					        anchors.bottom: parent.bottom
 | 
				
			||||||
 | 
					        anchors.verticalCenter: parent.verticalCenter
 | 
				
			||||||
 | 
					        anchors.horizontalCenter: parent.horizontalCenter
 | 
				
			||||||
 | 
					        anchors.topMargin: 1
 | 
				
			||||||
 | 
					        anchors.bottomMargin: 1
 | 
				
			||||||
 | 
					        source: Helper.batteryIcon(batteryPercent)
 | 
				
			||||||
 | 
					        color: batteryPercent == -1 ? colorFull : PlasmaCore.Theme.textColor
 | 
				
			||||||
 | 
					      }
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					  }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  Rectangle { // battery cap
 | 
				
			||||||
 | 
					    anchors.left: container.right
 | 
				
			||||||
 | 
					    anchors.leftMargin: 1
 | 
				
			||||||
 | 
					    anchors.verticalCenter: parent.verticalCenter
 | 
				
			||||||
 | 
					    radius: 4
 | 
				
			||||||
 | 
					    height: parent.height / 3
 | 
				
			||||||
 | 
					    width: 2
 | 
				
			||||||
 | 
					    color: PlasmaCore.Theme.textColor
 | 
				
			||||||
 | 
					  }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  MouseArea {
 | 
				
			||||||
 | 
					    anchors.fill: parent
 | 
				
			||||||
 | 
					    onClicked: {
 | 
				
			||||||
 | 
					      plasmoid.expanded = !plasmoid.expanded
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					  }
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
							
								
								
									
										44
									
								
								package/contents/ui/FullRepresentation.qml
									
									
									
									
									
										Normal 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
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					  }
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
							
								
								
									
										57
									
								
								package/contents/ui/config/debug.qml
									
									
									
									
									
										Normal file
									
								
							
							
						
						@@ -0,0 +1,57 @@
 | 
				
			|||||||
 | 
					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
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					QQC2.Pane {
 | 
				
			||||||
 | 
					  id: root
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  property alias cfg_debug_active: debug_active.checked
 | 
				
			||||||
 | 
					  property alias cfg_debug_charge: debug_charge.value
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  Kirigami.FormLayout {
 | 
				
			||||||
 | 
					    anchors.fill: parent
 | 
				
			||||||
 | 
					    wideMode: false
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    GridLayout {
 | 
				
			||||||
 | 
					      columns: 3
 | 
				
			||||||
 | 
					      rows: 2
 | 
				
			||||||
 | 
					      rowSpacing: 10
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					      // first row
 | 
				
			||||||
 | 
					      Text {
 | 
				
			||||||
 | 
					        text: "debug:"
 | 
				
			||||||
 | 
					        color: PlasmaCore.Theme.textColor
 | 
				
			||||||
 | 
					      }
 | 
				
			||||||
 | 
					      PlasmaComponents.CheckBox {
 | 
				
			||||||
 | 
					        id: debug_active
 | 
				
			||||||
 | 
					      }
 | 
				
			||||||
 | 
					      Text {
 | 
				
			||||||
 | 
					        text: ""
 | 
				
			||||||
 | 
					      }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					      // second row
 | 
				
			||||||
 | 
					      Text {
 | 
				
			||||||
 | 
					        text: "battery charge:"
 | 
				
			||||||
 | 
					        color: PlasmaCore.Theme.textColor
 | 
				
			||||||
 | 
					      }
 | 
				
			||||||
 | 
					      PlasmaComponents.Slider {
 | 
				
			||||||
 | 
					        id: debug_charge
 | 
				
			||||||
 | 
					        value: 0
 | 
				
			||||||
 | 
					        minimumValue: -2
 | 
				
			||||||
 | 
					        maximumValue: 100
 | 
				
			||||||
 | 
					        stepSize: 1
 | 
				
			||||||
 | 
					      }
 | 
				
			||||||
 | 
					      Text {
 | 
				
			||||||
 | 
					        text: cfg_debug_charge + "%"
 | 
				
			||||||
 | 
					        color: PlasmaCore.Theme.textColor
 | 
				
			||||||
 | 
					      }
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  }
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
							
								
								
									
										199
									
								
								package/contents/ui/config/general.qml
									
									
									
									
									
										Normal file
									
								
							
							
						
						@@ -0,0 +1,199 @@
 | 
				
			|||||||
 | 
					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
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					QQC2.Pane {
 | 
				
			||||||
 | 
					  id: root
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  property alias cfg_pollingrate: pollingrate.value
 | 
				
			||||||
 | 
					  property alias cfg_batteryheight: batteryheight.value
 | 
				
			||||||
 | 
					  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
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  Kirigami.FormLayout {
 | 
				
			||||||
 | 
					    anchors.fill: parent
 | 
				
			||||||
 | 
					    wideMode: false
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    GridLayout {
 | 
				
			||||||
 | 
					      columns: 3
 | 
				
			||||||
 | 
					      rows: 2
 | 
				
			||||||
 | 
					      rowSpacing: 10
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					      // first row
 | 
				
			||||||
 | 
					      Text {
 | 
				
			||||||
 | 
					        text: "polling rate:"
 | 
				
			||||||
 | 
					        color: PlasmaCore.Theme.textColor
 | 
				
			||||||
 | 
					      }
 | 
				
			||||||
 | 
					      PlasmaComponents.Slider {
 | 
				
			||||||
 | 
					        id: pollingrate
 | 
				
			||||||
 | 
					        value: 10
 | 
				
			||||||
 | 
					        minimumValue: 2
 | 
				
			||||||
 | 
					        maximumValue: 60
 | 
				
			||||||
 | 
					        stepSize: 2
 | 
				
			||||||
 | 
					      }
 | 
				
			||||||
 | 
					      Text {
 | 
				
			||||||
 | 
					        text: cfg_pollingrate + " seconds"
 | 
				
			||||||
 | 
					        color: PlasmaCore.Theme.textColor
 | 
				
			||||||
 | 
					      }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					      // second row
 | 
				
			||||||
 | 
					      Text {
 | 
				
			||||||
 | 
					        text: "battery height:"
 | 
				
			||||||
 | 
					        color: PlasmaCore.Theme.textColor
 | 
				
			||||||
 | 
					      }
 | 
				
			||||||
 | 
					      PlasmaComponents.Slider {
 | 
				
			||||||
 | 
					        id: batteryheight
 | 
				
			||||||
 | 
					        value: 8.0
 | 
				
			||||||
 | 
					        minimumValue: 1
 | 
				
			||||||
 | 
					        maximumValue: 10
 | 
				
			||||||
 | 
					        stepSize: 1
 | 
				
			||||||
 | 
					      }
 | 
				
			||||||
 | 
					      Text {
 | 
				
			||||||
 | 
					        text: cfg_batteryheight
 | 
				
			||||||
 | 
					        color: PlasmaCore.Theme.textColor
 | 
				
			||||||
 | 
					      }
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    // color config
 | 
				
			||||||
 | 
					    GridLayout {
 | 
				
			||||||
 | 
					      columns: 3
 | 
				
			||||||
 | 
					      rows: 3
 | 
				
			||||||
 | 
					      rowSpacing: 1
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					      // first row
 | 
				
			||||||
 | 
					      Text {
 | 
				
			||||||
 | 
					        text: "empty:"
 | 
				
			||||||
 | 
					        color: PlasmaCore.Theme.textColor
 | 
				
			||||||
 | 
					      }
 | 
				
			||||||
 | 
					      KQControls.ColorButton {
 | 
				
			||||||
 | 
					        id: colorEmpty
 | 
				
			||||||
 | 
					        color: cfg_colorEmpty
 | 
				
			||||||
 | 
					      }
 | 
				
			||||||
 | 
					      Text {
 | 
				
			||||||
 | 
					        text: cfg_colorEmpty
 | 
				
			||||||
 | 
					        color: PlasmaCore.Theme.textColor
 | 
				
			||||||
 | 
					      }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					      // secod row
 | 
				
			||||||
 | 
					      Text {
 | 
				
			||||||
 | 
					        text: "half:"
 | 
				
			||||||
 | 
					        color: PlasmaCore.Theme.textColor
 | 
				
			||||||
 | 
					      }
 | 
				
			||||||
 | 
					      KQControls.ColorButton {
 | 
				
			||||||
 | 
					        id: colorHalf
 | 
				
			||||||
 | 
					        color: cfg_colorHalf
 | 
				
			||||||
 | 
					      }
 | 
				
			||||||
 | 
					      Text {
 | 
				
			||||||
 | 
					        text: cfg_colorHalf
 | 
				
			||||||
 | 
					        color: PlasmaCore.Theme.textColor
 | 
				
			||||||
 | 
					      }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					      // third row
 | 
				
			||||||
 | 
					      Text {
 | 
				
			||||||
 | 
					        text: "full:"
 | 
				
			||||||
 | 
					        color: PlasmaCore.Theme.textColor
 | 
				
			||||||
 | 
					      }
 | 
				
			||||||
 | 
					      KQControls.ColorButton {
 | 
				
			||||||
 | 
					        id: colorFull
 | 
				
			||||||
 | 
					        color: cfg_colorFull
 | 
				
			||||||
 | 
					      }
 | 
				
			||||||
 | 
					      Text {
 | 
				
			||||||
 | 
					        text: cfg_colorFull
 | 
				
			||||||
 | 
					        color: PlasmaCore.Theme.textColor
 | 
				
			||||||
 | 
					      }
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    // color gradient example
 | 
				
			||||||
 | 
					    GridLayout {
 | 
				
			||||||
 | 
					      columns: 10
 | 
				
			||||||
 | 
					      rows: 1
 | 
				
			||||||
 | 
					      rowSpacing: 0
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					      Text {
 | 
				
			||||||
 | 
					        text: "█"
 | 
				
			||||||
 | 
					        color: Helper.interpolateColor(.1, [ cfg_colorEmpty.toString(), cfg_colorHalf.toString(), cfg_colorFull.toString() ])
 | 
				
			||||||
 | 
					      }
 | 
				
			||||||
 | 
					      Text {
 | 
				
			||||||
 | 
					        text: "█"
 | 
				
			||||||
 | 
					        color: Helper.interpolateColor(.2, [ cfg_colorEmpty.toString(), cfg_colorHalf.toString(), cfg_colorFull.toString() ])
 | 
				
			||||||
 | 
					      }
 | 
				
			||||||
 | 
					      Text {
 | 
				
			||||||
 | 
					        text: "█"
 | 
				
			||||||
 | 
					        color: Helper.interpolateColor(.3, [ cfg_colorEmpty.toString(), cfg_colorHalf.toString(), cfg_colorFull.toString() ])
 | 
				
			||||||
 | 
					      }
 | 
				
			||||||
 | 
					      Text {
 | 
				
			||||||
 | 
					        text: "█"
 | 
				
			||||||
 | 
					        color: Helper.interpolateColor(.4, [ cfg_colorEmpty.toString(), cfg_colorHalf.toString(), cfg_colorFull.toString() ])
 | 
				
			||||||
 | 
					      }
 | 
				
			||||||
 | 
					      Text {
 | 
				
			||||||
 | 
					        text: "█"
 | 
				
			||||||
 | 
					        color: Helper.interpolateColor(.5, [ cfg_colorEmpty.toString(), cfg_colorHalf.toString(), cfg_colorFull.toString() ])
 | 
				
			||||||
 | 
					      }
 | 
				
			||||||
 | 
					      Text {
 | 
				
			||||||
 | 
					        text: "█"
 | 
				
			||||||
 | 
					        color: Helper.interpolateColor(.6, [ cfg_colorEmpty.toString(), cfg_colorHalf.toString(), cfg_colorFull.toString() ])
 | 
				
			||||||
 | 
					      }
 | 
				
			||||||
 | 
					      Text {
 | 
				
			||||||
 | 
					        text: "█"
 | 
				
			||||||
 | 
					        color: Helper.interpolateColor(.7, [ cfg_colorEmpty.toString(), cfg_colorHalf.toString(), cfg_colorFull.toString() ])
 | 
				
			||||||
 | 
					      }
 | 
				
			||||||
 | 
					      Text {
 | 
				
			||||||
 | 
					        text: "█"
 | 
				
			||||||
 | 
					        color: Helper.interpolateColor(.8, [ cfg_colorEmpty.toString(), cfg_colorHalf.toString(), cfg_colorFull.toString() ])
 | 
				
			||||||
 | 
					      }
 | 
				
			||||||
 | 
					      Text {
 | 
				
			||||||
 | 
					        text: "█"
 | 
				
			||||||
 | 
					        color: Helper.interpolateColor(.9, [ cfg_colorEmpty.toString(), cfg_colorHalf.toString(), cfg_colorFull.toString() ])
 | 
				
			||||||
 | 
					      }
 | 
				
			||||||
 | 
					      Text {
 | 
				
			||||||
 | 
					        text: "█"
 | 
				
			||||||
 | 
					        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
 | 
				
			||||||
 | 
					      }
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					  }
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
							
								
								
									
										29
									
								
								package/contents/ui/lib/helper.js
									
									
									
									
									
										Normal file
									
								
							
							
						
						@@ -0,0 +1,29 @@
 | 
				
			|||||||
 | 
					const batteryLevel = batteryPercent => ({
 | 
				
			||||||
 | 
					  "-2": "not connected",
 | 
				
			||||||
 | 
					  "-1": "charging"
 | 
				
			||||||
 | 
					})[batteryPercent] ?? batteryPercent + "%";
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					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);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					const interpolateColor = (f, c) => {
 | 
				
			||||||
 | 
					  if(!f)     return "transparent";
 | 
				
			||||||
 | 
					  if(f >= 1) return c.pop();
 | 
				
			||||||
 | 
					  if(f <= 0) return c.shift();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  f *= c.length - 1;
 | 
				
			||||||
 | 
					  const i = ~~f;
 | 
				
			||||||
 | 
					  f -= i;
 | 
				
			||||||
 | 
					  const [ c1, c2 ] = [ hex2rgb(c[i]), hex2rgb(c[i + 1]) ];
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  return rgb2Hex({
 | 
				
			||||||
 | 
					    r: c1.r + ((c2.r - c1.r) * f) | 10,
 | 
				
			||||||
 | 
					    g: c1.g + ((c2.g - c1.g) * f) | 10,
 | 
				
			||||||
 | 
					    b: c1.b + ((c2.b - c1.b) * f) | 10
 | 
				
			||||||
 | 
					  });
 | 
				
			||||||
 | 
					};
 | 
				
			||||||
@@ -1,65 +1,70 @@
 | 
				
			|||||||
import QtQuick 2.0
 | 
					import QtQuick 2.15
 | 
				
			||||||
import QtQuick.Layouts 1.3
 | 
					import QtQuick.Layouts 1.3
 | 
				
			||||||
import org.kde.plasma.plasmoid 2.0
 | 
					import org.kde.plasma.plasmoid 2.0
 | 
				
			||||||
import org.kde.plasma.core 2.0 as PlasmaCore
 | 
					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 {
 | 
					Item {
 | 
				
			||||||
  id: main
 | 
					  id: main
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  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
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  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 int batteryPercent: -2
 | 
				
			||||||
 | 
					  property bool notification_sent: false;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  PlasmaCore.DataSource {
 | 
					  PlasmaCore.DataSource {
 | 
				
			||||||
    id: hsSource
 | 
					    id: hsSource
 | 
				
			||||||
    engine: "executable"
 | 
					    engine: "executable"
 | 
				
			||||||
    connectedSources: ["headsetcontrol -bc"]
 | 
					    connectedSources: ["headsetcontrol -bc"]
 | 
				
			||||||
    interval: 2000
 | 
					    interval: pollingrate * 1e3
 | 
				
			||||||
    onNewData: {
 | 
					    onNewData: {
 | 
				
			||||||
      if(data['exit_code'] > 0)
 | 
					      if(debug_active)
 | 
				
			||||||
        return console.log('error lol');
 | 
					        batteryPercent = debug_charge;
 | 
				
			||||||
      batteryPercent = data['stdout'];
 | 
					      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();
 | 
				
			||||||
 | 
					      }
 | 
				
			||||||
 | 
					      // reset notifications if battery level is over batteryThreshold
 | 
				
			||||||
 | 
					      if((batteryPercent > batteryThreshold || batteryPercent < 0) && notification_sent && notifications) {
 | 
				
			||||||
 | 
					        notification_sent = false;
 | 
				
			||||||
 | 
					      }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					      return;
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
  }
 | 
					  }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  Plasmoid.preferredRepresentation: Plasmoid.compactRepresentation
 | 
					  Plasmoid.preferredRepresentation: Plasmoid.compactRepresentation
 | 
				
			||||||
 | 
					  Plasmoid.fullRepresentation: FullRepresentation{} 
 | 
				
			||||||
 | 
					  Plasmoid.compactRepresentation: CompactRepresentation{}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  Plasmoid.compactRepresentation: Item {
 | 
					  Notification {
 | 
				
			||||||
    Layout.minimumWidth: units.iconSizes.medium
 | 
					    id: notification
 | 
				
			||||||
 | 
					    componentName: "plasma_workspace"
 | 
				
			||||||
    Image {
 | 
					    eventId: "notification"
 | 
				
			||||||
      anchors.fill: parent
 | 
					    flags: Notification.DefaultEvent
 | 
				
			||||||
      smooth: true
 | 
					    urgency: Notification.CriticalUrgency
 | 
				
			||||||
      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 + " %";
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
  }
 | 
					  }
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -7,15 +7,18 @@
 | 
				
			|||||||
    "Category": "System Information",
 | 
					    "Category": "System Information",
 | 
				
			||||||
    "Dependencies": [
 | 
					    "Dependencies": [
 | 
				
			||||||
    ],
 | 
					    ],
 | 
				
			||||||
 | 
					    "EnabledByDefault": true,
 | 
				
			||||||
    "Icon": "battery",
 | 
					    "Icon": "battery",
 | 
				
			||||||
    "Id": "org.kde.plasma.headsetcontrol-battery-widget",
 | 
					    "Id": "org.kde.plasma.headsetcontrol-battery-widget",
 | 
				
			||||||
    "Name": "Headset Battery Widget",
 | 
					    "Name": "Headset Battery Widget",
 | 
				
			||||||
    "ServiceTypes": [
 | 
					    "ServiceTypes": [
 | 
				
			||||||
      "Plasma/Applet"
 | 
					      "Plasma/Applet"
 | 
				
			||||||
    ],
 | 
					    ],
 | 
				
			||||||
    "Version": "1",
 | 
					    "Version": "1.5",
 | 
				
			||||||
    "Website": "https://git.lat/Flummi/headsetcontrol-battery-widget"
 | 
					    "Website": "https://git.lat/Flummi/headsetcontrol-battery-widget"
 | 
				
			||||||
  },
 | 
					  },
 | 
				
			||||||
 | 
					  "X-Plasma-NotificationArea": true,
 | 
				
			||||||
 | 
					  "X-Plasma-NotificationAreaCategory": "Hardware",
 | 
				
			||||||
  "X-Plasma-API": "declarativeappletscript",
 | 
					  "X-Plasma-API": "declarativeappletscript",
 | 
				
			||||||
  "X-Plasma-MainScript": "ui/main.qml"
 | 
					  "X-Plasma-MainScript": "ui/main.qml"
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 
 | 
				
			|||||||