Skip to content

Commit 94699d5

Browse files
committed
WIP: Implementing day-night modes and investigating a bug that freezes the video player when applying them and when changing sunrise/sunset times
1 parent 9451925 commit 94699d5

5 files changed

Lines changed: 137 additions & 32 deletions

File tree

package/contents/config/main.xml

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -137,10 +137,22 @@
137137
<entry name="ChangeWallpaperTimerHours" type="Int">
138138
<default>0</default>
139139
</entry>
140-
<entry name="DayNightCycle" type="Bool">
140+
<entry name="DayNightCycleEnabled" type="Bool">
141141
<label>Whether or not to cycle between day and night wallpapers</label>
142142
<default>False</default>
143143
</entry>
144+
<entry name="DayNightCycleMode" type="Int">
145+
<label>Mode</label>
146+
<default>0</default>
147+
</entry>
148+
<entry name="DayNightCycleSunriseTime" type="Int">
149+
<label>Time of sunrise</label>
150+
<default>360</default>
151+
</entry>
152+
<entry name="DayNightCycleSunsetTime" type="Int">
153+
<label>Time of sunset</label>
154+
<default>1080</default>
155+
</entry>
144156
<entry name="ResumeLastVideo" type="Bool">
145157
<label>Whether or not to resume last playing video on startup</label>
146158
<default>True</default>

package/contents/ui/code/enum.js

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,13 @@ const DayNightCycleAssignment = {
2222
Night: 2,
2323
};
2424

25+
const DayNightCycleMode = {
26+
Time: 0,
27+
PlasmaStyle: 1,
28+
AlwaysDay: 2,
29+
AlwaysNight: 3,
30+
};
31+
2532
const PauseMode = {
2633
MaximizedOrFullScreen: 0,
2734
ActiveWindowPresent: 1,
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
import QtQuick.Controls
2+
import QtQuick.Layouts
3+
4+
RowLayout {
5+
id: root
6+
required property string label
7+
property int value
8+
9+
Label {
10+
text: root.label
11+
}
12+
SpinBox {
13+
id: hours
14+
from: 0
15+
to: 23
16+
value: Math.floor(root.value / 60)
17+
editable: true
18+
textFromValue: (value) => value.toString().padStart(2, '0')
19+
valueFromText: (text) => parseInt(text, 10)
20+
onValueModified: {
21+
root.value = hours.value * 60 + minutes.value
22+
}
23+
}
24+
SpinBox {
25+
id: minutes
26+
from: 0
27+
to: 59
28+
value: root.value % 60
29+
editable: true
30+
textFromValue: (value) => value.toString().padStart(2, '0')
31+
valueFromText: (text) => parseInt(text, 10)
32+
onValueModified: {
33+
root.value = hours.value * 60 + minutes.value
34+
}
35+
}
36+
}

package/contents/ui/config.qml

Lines changed: 52 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,10 @@ ColumnLayout {
6464
property real cfg_PlaybackRate
6565
property real cfg_AlternativePlaybackRate
6666
property alias cfg_Volume: volumeSlider.value
67-
property alias cfg_DayNightCycle: dayNightCycleCheckBox.checked
67+
property alias cfg_DayNightCycleEnabled: dayNightCycleEnableCheckBox.checked
68+
property alias cfg_DayNightCycleMode: dayNightCycleMode.currentValue
69+
property alias cfg_DayNightCycleSunriseTime: dayNightCycleSunriseTime.value
70+
property alias cfg_DayNightCycleSunsetTime: dayNightCycleSunsetTime.value
6871
property alias cfg_RandomMode: randomModeCheckbox.checked
6972
property alias cfg_ResumeLastVideo: resumeLastVideoCheckbox.checked
7073
property alias cfg_ChangeWallpaperMode: changeWallpaperModeComboBox.currentValue
@@ -326,6 +329,54 @@ ColumnLayout {
326329
valueRole: "value"
327330
}
328331
}
332+
333+
ColumnLayout {
334+
Kirigami.FormData.label: i18nd("plasma_wallpaper_luisbocanegra.smart.video.wallpaper.reborn", "Day-Night Cycle:")
335+
visible: root.currentTab === 0
336+
RowLayout {
337+
CheckBox {
338+
id: dayNightCycleEnableCheckBox
339+
Kirigami.FormData.label: i18nd("plasma_wallpaper_luisbocanegra.smart.video.wallpaper.reborn", "Enable")
340+
}
341+
ComboBox {
342+
id: dayNightCycleMode
343+
model: [
344+
{
345+
text: i18nd("plasma_wallpaper_luisbocanegra.smart.video.wallpaper.reborn", "Based on time"),
346+
value: Enum.DayNightCycleMode.Time
347+
},
348+
{
349+
text: i18nd("plasma_wallpaper_luisbocanegra.smart.video.wallpaper.reborn", "Based on Plasma Style"),
350+
value: Enum.DayNightCycleMode.PlasmaStyle
351+
},
352+
{
353+
text: i18nd("plasma_wallpaper_luisbocanegra.smart.video.wallpaper.reborn", "Always Day"),
354+
value: Enum.DayNightCycleMode.AlwaysDay
355+
},
356+
{
357+
text: i18nd("plasma_wallpaper_luisbocanegra.smart.video.wallpaper.reborn", "Always Night"),
358+
value: Enum.DayNightCycleMode.AlwaysNight
359+
}
360+
]
361+
textRole: "text"
362+
valueRole: "value"
363+
enabled: dayNightCycleEnableCheckBox.checked
364+
}
365+
}
366+
}
367+
RowLayout {
368+
// Kirigami.FormData.label: i18nd("plasma_wallpaper_luisbocanegra.smart.video.wallpaper.reborn", "Times:")
369+
visible: root.currentTab === 0 && dayNightCycleEnableCheckBox.checked
370+
Components.TimePicker {
371+
id: dayNightCycleSunriseTime
372+
label: i18nd("plasma_wallpaper_luisbocanegra.smart.video.wallpaper.reborn", "Sunrise:")
373+
}
374+
Components.TimePicker {
375+
id: dayNightCycleSunsetTime
376+
label: i18nd("plasma_wallpaper_luisbocanegra.smart.video.wallpaper.reborn", "Sunset:")
377+
}
378+
}
379+
329380
// RowLayout {
330381
ButtonGroup {
331382
id: backgroundGroup
@@ -483,12 +534,6 @@ ColumnLayout {
483534
}
484535
}
485536

486-
CheckBox {
487-
id: dayNightCycleCheckBox
488-
Kirigami.FormData.label: i18n("Day/Night Cycle:")
489-
visible: root.currentTab === 1
490-
}
491-
492537
CheckBox {
493538
id: randomModeCheckbox
494539
Kirigami.FormData.label: i18nd("plasma_wallpaper_luisbocanegra.smart.video.wallpaper.reborn", "Random order:")

package/contents/ui/main.qml

Lines changed: 29 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -42,14 +42,30 @@ WallpaperItem {
4242
}
4343
property int currentVideoIndex: 0
4444
property bool resumeLastVideo: main.configuration.ResumeLastVideo
45-
property bool dayNightCycle: main.configuration.DayNightCycle
46-
property bool isDay: {
47-
const currentTime = new Date().getHours();
48-
return currentTime >= 6 && currentTime < 19;
45+
property bool dayNightCycleEnabled: main.configuration.DayNightCycleEnabled
46+
47+
function detectDayTime() {
48+
let mode = main.configuration.DayNightCycleMode;
49+
switch(mode) {
50+
case Enum.DayNightCycleMode.Time:
51+
// if (KNightTimePlugin) {
52+
// return ...;
53+
// }
54+
const { DayNightCycleSunriseTime, DayNightCycleSunsetTime } = main.configuration;
55+
const now = new Date();
56+
const currentTime = now.getHours() * 60 + now.getMinutes();
57+
58+
return currentTime >= DayNightCycleSunriseTime && currentTime < DayNightCycleSunsetTime;
59+
case Enum.DayNightCycleMode.PlasmaStyle: return Qt.styleHints.colorScheme === Qt.ColorScheme.Light;
60+
case Enum.DayNightCycleMode.AlwaysNight: return false;
61+
case Enum.DayNightCycleMode.AlwaysDay:
62+
default: return true;
63+
}
4964
}
65+
property bool isDay: detectDayTime()
5066

5167
function getLastVideo() {
52-
if (dayNightCycle) {
68+
if (dayNightCycleEnabled) {
5369
return main.configuration[isDay ? "LastVideoDay" : "LastVideoNight"];
5470
}
5571
return main.configuration.LastVideo;
@@ -220,7 +236,7 @@ WallpaperItem {
220236
}
221237

222238
function getVideos() {
223-
if (dayNightCycle) {
239+
if (dayNightCycleEnabled) {
224240
return Utils.parseCompat(videoUrls).filter(video => {
225241
const isDayCycle = video.dayNightCycleAssignment !== Enum.DayNightCycleAssignment.Night;
226242
const isNightCycle = video.dayNightCycleAssignment !== Enum.DayNightCycleAssignment.Day;
@@ -300,31 +316,20 @@ WallpaperItem {
300316
repeat: true
301317
triggeredOnStart: true
302318
onTriggered: {
303-
const dayNightCycleConfigChanged = dayNightCycle !== main.configuration.DayNightCycle;
304-
if (!dayNightCycleConfigChanged && !main.configuration.DayNightCycle) {
319+
const dayNightCycleEnabledChanged = dayNightCycleEnabled !== main.configuration.DayNightCycleEnabled;
320+
if ((!dayNightCycleEnabledChanged && !main.configuration.DayNightCycleEnabled) || main.isLoading) {
305321
return;
306322
}
307-
dayNightCycle = main.configuration.DayNightCycle;
323+
dayNightCycleEnabled = main.configuration.DayNightCycleEnabled;
308324

309-
const hours = new Date().getHours();
310-
const isDay = hours >= 6 && hours < 19;
325+
const isDay = detectDayTime();
311326

312-
if ((main.isDay != isDay) || dayNightCycleConfigChanged) {
327+
if ((main.isDay != isDay) || dayNightCycleEnabledChanged) {
313328
main.save();
314329
main.isDay = isDay;
315330
videosConfig = getVideos();
316331

317-
if (getLastVideo() === "") {
318-
setCurrentSource(0);
319-
return player.next();
320-
}
321-
322-
currentVideoIndex = getLastVideoIndex();
323-
324-
if (main.configuration.ResumeLastVideo) {
325-
// TODO: Resume last (day/night) video when changing from day to night or vice versa
326-
}
327-
332+
currentVideoIndex = main.configuration.ResumeLastVideo ? getLastVideoIndex() : 0;
328333
setCurrentSource(currentVideoIndex);
329334

330335
player.next();
@@ -538,7 +543,7 @@ WallpaperItem {
538543
// Save last video and position to resume from it on next login/lock
539544
main.configuration.LastVideo = main.currentSource.filename;
540545
main.configuration.LastVideoPosition = player.lastVideoPosition;
541-
if(dayNightCycle) {
546+
if(dayNightCycleEnabled) {
542547
main.configuration[main.isDay ? "LastVideoDay" : "LastVideoNight"] = main.currentSource.filename;
543548
}
544549
main.configuration.writeConfig();

0 commit comments

Comments
 (0)