-
Notifications
You must be signed in to change notification settings - Fork 4
/
Toholed.qml
127 lines (112 loc) · 4.45 KB
/
Toholed.qml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
/*
* 2miich - Liiga scores app
* Copyright (C) 2014 Santtu Lakkala <inz@inz.fi>
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
import QtQuick 2.0
import harbour.toomiich.Oledify 1.0
import harbour.toomiich.PersistentTimer 1.0
import harbour.toomiich.DBusInterface 2.0
Oledify {
id: oledify
property bool present: tohOled.status === DBusInterface.Available;
property bool enable: false;
property bool _active: present && enable;
property bool haveLock: false
property alias clockX: clock.x
property alias clockY: clock.y
property alias clockW: clock.width
property alias clockH: clock.height
property bool clockEnabled: false
property list<QtObject> resources: [
DBusInterface {
id: tohOled
watchServiceStatus: true
service: 'com.kimmoli.toholed'
iface: 'com.kimmoli.toholed'
path: '/'
bus: DBusInterface.SystemBus
},
PersistentTimer {
interval: 25000
running: _active
repeat: true
wakeUp: true
onTriggered: {
tohOled.typedCallWithReturn("draw", [
{type: 's', value: 'lock'},
{type: 'b', value: enable},
{type: 's', value: 'fi.inz.2miich'}
],
function (reply) {
var hadLock = haveLock;
haveLock = reply === 'ok';
if (haveLock) {
if (!hadLock)
oledify.update();
else
clock.update();
}
});
}
},
Oledify {
id: clock
width: 128
height: 16
property int x: 0
property int y: 48
function update() {
if (!clockEnabled)
return false;
clock.clear();
clock.drawText(width / 2, 0, true, 0, 14, false, new Date().toLocaleTimeString(Qt.locale(), "hh:mm"));
tohOled.call("drawPicture", [x, y, clock.data]);
}
}
]
on_ActiveChanged: {
if (present) {
tohOled.typedCallWithReturn("draw", [
{type: 's', value: 'lock'},
{type: 'b', value: enable},
{type: 's', value: 'fi.inz.2miich'}
],
function (reply) {
var hadLock = haveLock;
haveLock = enable && reply === 'ok';
if (haveLock && !hadLock)
oledify.update();
});
}
}
onPresentChanged: {
if (!present)
haveLock = false;
}
function update() {
if (haveLock) {
if (clockEnabled) {
oledify.clearRect(clockX, clockY, clockW, clockH);
oledify.drawText(clockX + clockW / 2, clockY, true, 0, 14, false, new Date().toLocaleTimeString(Qt.locale(), "hh:mm"))
}
tohOled.call("drawPicture", [0, 0, oledify.data]);
}
}
function blink() {
if (haveLock)
tohOled.call("draw", ["blink", 3]);
}
}