1
1
import QtQuick 1.1
2
+ import "../code/js/NotificationHelper.js" as NotificationHelper
3
+ import "../code/js/CommandRunner.js" as CommandRunner
4
+ import "../code/js/SettingsManager.js" as SettingsManager
2
5
3
6
Item {
4
7
5
8
Image {
9
+ id: widgetImage
6
10
7
11
property string okImage: " plasmapackage:/images/ok.png"
8
12
property string errorImage: " plasmapackage:/images/error.png"
9
13
property string workingImage: " plasmapackage:/images/gear.png"
10
- property string nextImage: widgetImage .errorImage
11
- property int commandInterval: 1000
14
+ property bool isRunning: false
12
15
13
- id: widgetImage
14
- source: widgetImage .okImage
16
+ source: widgetImage .workingImage
15
17
anchors .centerIn : parent
16
18
width: parent .width
17
19
height: parent .height
18
20
fillMode: Image .PreserveAspectFit
19
21
20
22
MouseArea {
21
23
anchors .fill : parent
22
- onClicked: widgetImage .runCommand ()
24
+ onClicked: widgetImage .go ()
23
25
}
24
26
25
- function switchImages (){
26
- var nextImage = widgetImage .nextImage ;
27
- widgetImage .nextImage = widgetImage .source ;
28
- widgetImage .source = nextImage;
29
- }
30
-
31
- function sendNotification (){
32
- console .log (" Clicked!" );
33
- var service = dataEngine (" notifications" ).serviceForSource (" notification" );
34
- var operation = service .operationDescription (" createNotification" );
35
- operation[" appName" ] = " Min-Status-Widget" ;
36
- operation[" appIcon" ] = plasmoid .file (" images" , " ok.png" );
37
- operation[" summary" ] = " Something Happened!" ;
38
- operation[" body" ] = " I'm assuming that this should be longer..." ;
39
- operation[" timeout" ] = 3000 ;
40
-
41
- service .startOperationCall (operation);
42
- console .log (service .serviceReady (service));
43
- }
44
-
45
- function runCommand (){
46
- widgetImage .source = widgetImage .workingImage ;
47
- console .log (" Running Command..." );
48
- var result = plasmoid .runCommand (" /home/jschindler/src/min-status-widget/resources/randomSuccess.sh" );
49
- sendNotification ();
50
- console .log (result);
27
+ Timer {
28
+ id: myTimer
29
+ interval: 3000 ; running: false ; repeat: true
30
+ onTriggered: widgetImage .go ()
51
31
}
52
32
53
- Timer {
54
- id: " myTimer"
55
- interval: 500 ; running: true ; repeat: true
56
- onTriggered: widgetImage .switchImages ()
33
+ Component .onCompleted : myTimer .running = true
34
+
35
+ function go (){
36
+ if (! isRunning){
37
+ isRunning = true ;
38
+ source = workingImage;
39
+ var result = CommandRunner .runCommand (SettingsManager .getCommandToRun ());
40
+ if (result){
41
+ NotificationHelper .sendSuccessNotifiaction (" MyCommand" );
42
+ source = okImage;
43
+ } else {
44
+ NotificationHelper .sendFailureNotifiaction (" MyCommand" );
45
+ source = errorImage;
46
+ }
47
+ isRunning = false
48
+ }
57
49
}
58
50
}
59
51
}
0 commit comments