Changeset View
Changeset View
Standalone View
Standalone View
applets/timer/package/contents/ui/main.qml
Show All 16 Lines | |||||
17 | * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA . * | 17 | * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA . * | ||
18 | ***************************************************************************/ | 18 | ***************************************************************************/ | ||
19 | 19 | | |||
20 | import QtQuick 2.2 | 20 | import QtQuick 2.2 | ||
21 | import org.kde.plasma.plasmoid 2.0 | 21 | import org.kde.plasma.plasmoid 2.0 | ||
22 | import org.kde.plasma.core 2.0 as PlasmaCore | 22 | import org.kde.plasma.core 2.0 as PlasmaCore | ||
23 | import org.kde.plasma.components 2.0 as PlasmaComponents | 23 | import org.kde.plasma.components 2.0 as PlasmaComponents | ||
24 | import org.kde.kquickcontrolsaddons 2.0 as QtExtra | 24 | import org.kde.kquickcontrolsaddons 2.0 as QtExtra | ||
25 | import org.kde.plasma.private.timer 0.1 as TimerPlasmoid | ||||
25 | 26 | | |||
26 | Item { | 27 | Item { | ||
27 | id: root; | 28 | id: root; | ||
28 | property variant predefinedTimers: plasmoid.configuration.predefinedTimers; | 29 | property variant predefinedTimers: plasmoid.configuration.predefinedTimers; | ||
29 | 30 | | |||
30 | property int seconds : restoreToSeconds(plasmoid.configuration.running, plasmoid.configuration.savedAt, plasmoid.configuration.seconds); | 31 | property int seconds : restoreToSeconds(plasmoid.configuration.running, plasmoid.configuration.savedAt, plasmoid.configuration.seconds); | ||
31 | 32 | | |||
33 | // show notification on timer completion (default: enabled) | ||||
34 | property bool showNotification: plasmoid.configuration.showNotification; | ||||
35 | // run custom command on timer completion (default: disabled) | ||||
36 | property bool runCommand: plasmoid.configuration.runCommand; | ||||
37 | property string command: plasmoid.configuration.command; | ||||
38 | | ||||
32 | // show title (can be customized in the settings dialog, default: disabled) | 39 | // show title (can be customized in the settings dialog, default: disabled) | ||
33 | property bool showTitle: plasmoid.configuration.showTitle; | 40 | property bool showTitle: plasmoid.configuration.showTitle; | ||
34 | property string title: plasmoid.configuration.title; | 41 | property string title: plasmoid.configuration.title; | ||
35 | property bool running: (plasmoid.configuration.running > 0) ? true : false; | 42 | property bool running: (plasmoid.configuration.running > 0) ? true : false; | ||
36 | property bool suspended: false; | 43 | property bool suspended: false; | ||
37 | 44 | | |||
38 | property string notificationText: plasmoid.configuration.notificationText; | 45 | property string notificationText: plasmoid.configuration.notificationText; | ||
39 | 46 | | |||
Show All 20 Lines | |||||
60 | Plasmoid.fullRepresentation: TimerView { } | 67 | Plasmoid.fullRepresentation: TimerView { } | ||
61 | 68 | | |||
62 | PlasmaCore.DataSource { | 69 | PlasmaCore.DataSource { | ||
63 | id: notificationSource | 70 | id: notificationSource | ||
64 | engine: "notifications" | 71 | engine: "notifications" | ||
65 | connectedSources: "org.freedesktop.Notifications" | 72 | connectedSources: "org.freedesktop.Notifications" | ||
66 | } | 73 | } | ||
67 | 74 | | |||
75 | Timer { | ||||
76 | id: t; | ||||
77 | interval: 1000; | ||||
78 | onTriggered: { | ||||
79 | if (root.seconds != 0) { | ||||
80 | root.seconds--; | ||||
81 | } | ||||
82 | if (root.seconds == 0) { | ||||
83 | root.running = false; | ||||
84 | | ||||
85 | if (showNotification) { | ||||
86 | root.createNotification(); | ||||
87 | } | ||||
88 | if (runCommand) { | ||||
89 | TimerPlasmoid.Timer.runCommand(command); | ||||
90 | } | ||||
91 | saveTimer(); | ||||
92 | } | ||||
93 | } | ||||
94 | repeat: true; | ||||
95 | running: root.running; | ||||
96 | } | ||||
97 | | ||||
98 | Timer { | ||||
99 | id: delayedSaveTimer; | ||||
100 | interval: 3000; | ||||
101 | onTriggered: saveTimer(); | ||||
102 | } | ||||
103 | | ||||
104 | function onDigitHasChanged() { | ||||
105 | delayedSaveTimer.stop(); | ||||
106 | delayedSaveTimer.start(); | ||||
107 | } | ||||
108 | | ||||
68 | function createNotification() { | 109 | function createNotification() { | ||
69 | var service = notificationSource.serviceForSource("notification"); | 110 | var service = notificationSource.serviceForSource("notification"); | ||
70 | var operation = service.operationDescription("createNotification"); | 111 | var operation = service.operationDescription("createNotification"); | ||
71 | 112 | | |||
72 | operation.appName = root.title || i18n("Timer"); | 113 | operation.appName = root.title || i18n("Timer"); | ||
73 | operation["appIcon"] = "chronometer"; | 114 | operation["appIcon"] = "chronometer"; | ||
74 | operation.summary = notificationText || i18n("Timer finished") | 115 | operation.summary = notificationText || i18n("Timer finished") | ||
75 | operation["body"] = ""; | 116 | operation["body"] = ""; | ||
▲ Show 20 Lines • Show All 90 Lines • Show Last 20 Lines |