comit the changes for quick-widgets-0.2.1
[quick-widgets] / plugins / qmlprocess / qmlprocess / ProcessLabel.qml
1 import Qt 4.7
2 //import quickwidgets 1.0
3
4 Rectangle {
5      id: proclabel
6      width: 100
7      height: childrenRect.height
8      color: "blue"
9      opacity: 0.8
10      radius: 5
11
12      function parse(stdout) {
13          var rx = /[0-9]+/gi;
14          var val = stdout.match(rx)
15          return String(val)
16      }
17
18      property string command: "sh -c \"cat /proc/meminfo | /bin/grep 'Active:'\""
19      property string label: "Value:"
20      property string textcolor: "white"
21      property real interval_in_sec: 5
22
23      function setText() {
24          txt.text = txt.stagedtxt
25      }
26
27      Text {
28           property string stagedtxt: ""
29           id: txt
30           smooth: true
31           font.pointSize: 16
32           anchors.right: proclabel.right
33           anchors.margins: 5
34           text: ""
35           verticalAlignment: Text.AlignVCenter
36           horizontalAlignment: Text.AlignRight
37           color: proclabel.textcolor
38           Behavior on stagedtxt {
39               SequentialAnimation {
40                   NumberAnimation { target: txt; property: "opacity"; to: 0; duration: 300 }
41                   ScriptAction { script: setText(); }
42                   NumberAnimation { target: txt; property: "opacity"; to: 1; duration: 500 }
43               }
44           }
45       }
46
47      Text {
48           id: label
49           smooth: true
50           font.pointSize: 16
51           font.weight: Font.Bold
52           anchors.left: proclabel.left
53           anchors.margins: 5
54           text: proclabel.label
55           verticalAlignment: Text.AlignVCenter
56           horizontalAlignment: Text.AlignLeft
57           color: proclabel.textcolor
58      }
59
60      Process {
61           id: process
62           command: proclabel.command
63           onCompleted: { txt.stagedtxt = parse(stdout);}
64           onFailed: { proclabel.color = "red"; txt.stagedtxt = stderr }
65      }
66
67      Timer {
68          id: timer
69           triggeredOnStart: true
70           running: runtime.isActiveWindow
71           repeat: true
72           interval: proclabel.interval_in_sec*1000
73           onTriggered: { process.run() }
74      }
75  }