diff options
Diffstat (limited to 'desktop/modules/appearance/WallEngine.qml')
| -rw-r--r-- | desktop/modules/appearance/WallEngine.qml | 57 |
1 files changed, 52 insertions, 5 deletions
diff --git a/desktop/modules/appearance/WallEngine.qml b/desktop/modules/appearance/WallEngine.qml index fe45f7b..54705f6 100644 --- a/desktop/modules/appearance/WallEngine.qml +++ b/desktop/modules/appearance/WallEngine.qml @@ -33,7 +33,6 @@ Singleton { function listed(path, which) { return list(which).indexOf(path) >= 0; } // A gallery folder by its Wallpapers.groups key, "" for the hearted list. function folder(which) { return which === "V" ? cfg.folderV : cfg.folderH; } - function setFolder(which, key) { Prefs.setWallEngine(which === "V" ? { folderV: key } : { folderH: key }); } // What a tick draws from. A folder that is no longer in the gallery // gives nothing, so that screen is left alone rather than falling back // to the list behind the user's back. @@ -65,9 +64,46 @@ Singleton { } } - function setMinutes(m) { - if (Number.isInteger(m) && m >= 1 && m !== cfg.minutes) Prefs.setWallEngine({ minutes: m }); + // The page's draft, like every settings page: the interval and the two + // sources change here and reach Prefs on Start or Apply. Reset binds + // them back to what is saved. Hearts are not drafted: the picker writes + // them as they are clicked. + property int draftMinutes: cfg.minutes + property string draftFolderH: cfg.folderH + property string draftFolderV: cfg.folderV + readonly property bool dirty: draftMinutes !== cfg.minutes + || draftFolderH !== cfg.folderH || draftFolderV !== cfg.folderV + function draftFolder(which) { return which === "V" ? draftFolderV : draftFolderH; } + function setDraftFolder(which, key) { + if (which === "V") draftFolderV = key; + else draftFolderH = key; } + function setDraftMinutes(m) { + if (Number.isInteger(m) && m >= 1) draftMinutes = m; + } + function reset() { + draftMinutes = Qt.binding(() => cfg.minutes); + draftFolderH = Qt.binding(() => cfg.folderH); + draftFolderV = Qt.binding(() => cfg.folderV); + } + function commit() { + Prefs.setWallEngine({ minutes: draftMinutes, folderH: draftFolderH, folderV: draftFolderV }); + reset(); + } + + // Start changes the wallpapers at once: the first timer change would + // otherwise be a whole interval away, which read as the engine not + // working. + function start() { + commit(); + setOn(true); + next(); + } + function apply() { + commit(); + restartTimer(); + } + function stop() { setOn(false); } // ponytail: in memory, so a restart starts a new round. property var bagH: [] @@ -88,7 +124,15 @@ Singleton { function next() { tick(); + restartTimer(); + } + + // When the timer next fires, for the page's header; 0 while off. Timer + // has no such property, so it is kept beside it. + property double nextAt: 0 + function restartTimer() { timer.restart(); + nextAt = Date.now() + timer.interval; } // A switch-off during a run cannot start its own; it goes when that run @@ -106,7 +150,10 @@ Singleton { interval: root.cfg.minutes * 60000 repeat: true running: root.on - onTriggered: root.tick() + onTriggered: { root.nextAt = Date.now() + interval; root.tick(); } + // A running Timer restarts on a new interval. + onIntervalChanged: if (running) root.nextAt = Date.now() + interval + onRunningChanged: root.nextAt = running ? Date.now() + interval : 0 } Connections { @@ -116,7 +163,7 @@ Singleton { if (!root.on) return; Prefs.setWallEngine({ homeH: h !== "" ? h : root.cfg.homeH, homeV: v !== "" ? v : root.cfg.homeV }); - timer.restart(); + root.restartTimer(); } function onFinished() { if (!root.homeWaiting || root.on) return; |
