Skip to content

Commit

Permalink
Add option to pause when running on battery below specified level
Browse files Browse the repository at this point in the history
  • Loading branch information
luisbocanegra committed Mar 19, 2024
1 parent ccceaee commit 6ae38f9
Show file tree
Hide file tree
Showing 3 changed files with 77 additions and 25 deletions.
3 changes: 3 additions & 0 deletions package/contents/config/main.xml
Original file line number Diff line number Diff line change
Expand Up @@ -30,5 +30,8 @@
<label>Mute audio</label>
<default>true</default>
</entry>
<entry name="PauseBatteryLevel" type="Int">
<default>10</default>
</entry>
</group>
</kcfg>
63 changes: 43 additions & 20 deletions package/contents/ui/config.qml
Original file line number Diff line number Diff line change
Expand Up @@ -36,12 +36,11 @@ Kirigami.FormLayout {
property alias formLayout: root

property alias cfg_VideoWallpaperBackgroundVideo: videoPathLine.text
property int cfg_FillMode: 2
property bool cfg_MuteAudio: true
property bool cfg_DoublePlayer: true

property int cfg_FillMode: videoFillMode.currentIndex
property bool cfg_MuteAudio: muteRadio.checked
property int cfg_PauseMode: wallpaper.configuration.PauseMode
property alias cfg_BackgroundColor: colorButton.color
property int cfg_PauseBatteryLevel: pauseBatteryLevel.value

RowLayout {
Layout.fillWidth:true
Expand Down Expand Up @@ -107,18 +106,35 @@ Kirigami.FormLayout {
dialogTitle: i18nd("@dialog:background_color_title", "Select Background Color")
}

CheckBox {
id: muteRadio
Kirigami.FormData.label: i18nd("@checkbox:mute_audio", "Mute audio:")
checked: cfg_MuteAudio
onCheckedChanged: {
if (checked) {
cfg_MuteAudio = true
} else {
cfg_MuteAudio = false
}
}
}

Label {
Kirigami.FormData.label: i18nd("@buttonGroup:pause_mode", "Pause video:")
text: "Window State"
font.weight: Font.DemiBold
}

RadioButton {
id: maximizedPauseRadioButtton
Kirigami.FormData.label: i18nd("@buttonGroup:pause_mode", "Pause video:")
text: i18n("When there are maximized or full-screen windows.")
text: i18n("When there are maximized or full-screen windows")
ButtonGroup.group: pauseModeGroup
property int index: 0
checked: wallpaper.configuration.PauseMode === index
}
RadioButton {
id: busyPauseRadioButton
text: i18n("When the desktop is busy.")
text: i18n("When at least one window is shown")
ButtonGroup.group: pauseModeGroup
property int index: 1
checked: wallpaper.configuration.PauseMode === index
Expand All @@ -130,6 +146,26 @@ Kirigami.FormLayout {
property int index: 2
checked: wallpaper.configuration.PauseMode === index
}
Label {
text: "On Battery"
font.weight: Font.DemiBold
}
RowLayout {
Label {
id: batteryPauseCheckBox
text: i18n("When is below:")
}
SpinBox {
id: pauseBatteryLevel
from: 0
to: 100
value: cfg_PauseBatteryLevel
onValueChanged: {
cfg_PauseBatteryLevel = value
}
}
}

ButtonGroup {
id: pauseModeGroup
onCheckedButtonChanged: {
Expand All @@ -139,19 +175,6 @@ Kirigami.FormLayout {
}
}

CheckBox {
id: muteRadio
Kirigami.FormData.label: i18nd("@checkbox:mute_audio", "Mute audio:")
checked: cfg_MuteAudio
onCheckedChanged: {
if (checked) {
cfg_MuteAudio = true
} else {
cfg_MuteAudio = false
}
}
}

FileDialog {
id: fileDialog
fileMode : FileDialog.OpenFile
Expand Down
36 changes: 31 additions & 5 deletions package/contents/ui/main.qml
Original file line number Diff line number Diff line change
Expand Up @@ -19,24 +19,50 @@
*/

import QtQuick

import org.kde.plasma.core as Plasmacore
import org.kde.plasma.wallpapers.image as Wallpaper
import org.kde.plasma.plasmoid
import QtMultimedia
import org.kde.plasma.plasma5support as P5Support
import org.kde.plasma.plasmoid

WallpaperItem {
anchors.fill: parent
id: main
property string videoWallpaperBackgroundVideo: wallpaper.configuration.VideoWallpaperBackgroundVideo
property bool playing: windowModel.playVideoWallpaper
property bool playing: windowModel.playVideoWallpaper && !pauseBattery
property bool isLoading: true
onPlayingChanged: playing && !isLoading ? main.play() : main.pause()
property int pauseBatteryLevel: wallpaper.configuration.PauseBatteryLevel

onPlayingChanged: {
playing && !isLoading ? main.play() : main.pause()
}
onVideoWallpaperBackgroundVideoChanged: {
if (isLoading) return
updateState()
}

property QtObject pmSource: P5Support.DataSource {
id: pmSource
engine: "powermanagement"
connectedSources: sources
onSourceAdded: source => {
disconnectSource(source);
connectSource(source);
dumpProps(pmSource.connectedSources)
}
onSourceRemoved: source => {
disconnectSource(source);
dumpProps(pmSource.connectedSources)
}
}

property bool pauseBattery: {
let result = false
if (pmSource.data.Battery["Has Cumulative"] && pmSource.data["Battery"]["State"] === "Discharging") {
result = pauseBatteryLevel > pmSource.data.Battery.Percent
}
return result
}

WindowModel {
id: windowModel
screenGeometry: main.parent.screenGeometry
Expand Down

0 comments on commit 6ae38f9

Please sign in to comment.