/
WaterTariffScreen.qml
200 lines (161 loc) · 4.92 KB
/
WaterTariffScreen.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
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
import QtQuick 2.1
import BasicUIControls 1.0
import qb.components 1.0
import FileIO 1.0
Screen {
id: waterConfigScreen
screenTitle: "Water"
property int configChangeStep : 0
property bool stepRunning : false
property bool needReboot : false
property string oldprice : ""
property string newprice : oldprice
property string pwrusageFileString : "file:///mnt/data/qmf/config/config_happ_pwrusage.xml"
FileIO {id: pwrusageFile; source: "file:///mnt/data/qmf/config/config_happ_pwrusage.xml"}
FileIO {id: pwrusageFileBak; source: "file:///mnt/data/qmf/config/config_happ_pwrusage.bak"}
onShown: {
addCustomTopRightButton("Opslaan")
getTariff()
priceInput.inputText = newprice
}
onCustomButtonClicked: {
configChangeStep = 0
stepRunning = true
}
function saveprice(text) {
if (text) {
if(text.indexOf(',')>-1){text = text.replace(',','.')}
newprice = text;
}
}
Text {
id: mytext1
text: "Prijs"
font.family: qfont.semiBold.name
font.pixelSize: isNxt ? 18:14
anchors {
top: parent.top
left: parent.left
leftMargin: 20
topMargin:20
}
}
EditTextLabel4421 {
id: priceInput
width: (parent.width*0.6)
height: 30
leftTextAvailableWidth: (parent.width*0.6)-100
leftText: "Prijs inclusief belasting (bijv. 1.0000)"
labelFontSize: isNxt ? 18:14
labelFontFamily: qfont.semiBold.name
anchors {
left: mytext1.left
top: mytext1.bottom
topMargin: 6
}
onClicked: {
qkeyboard.open(priceInput.leftText, priceInput.inputText,saveprice)
}
}
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
function getTariff(){
console.log("*********Water check billingInfo in config_happ_pwrusage.xml")
var waterfound = false
var pwrusageString = pwrusageFile.read()
var pwrusageArray = pwrusageString.split("<billingInfo>")
for (var t in pwrusageArray){
var n201 = pwrusageArray[t].indexOf('</billingInfo>')
var partOfString = pwrusageArray[t].substring(0, n201)
if (partOfString.indexOf("water")>-1){
waterfound = true
console.log("*********Water : " + pwrusageArray[t])
var n300 = pwrusageArray[t].indexOf('<price>') + "<price>".length
var n301 = pwrusageArray[t].indexOf('</price>',n300)
oldprice = pwrusageArray[t].substring(n300, n301)
console.log("*********Water price : " + oldprice)
}
}
}
function modTariff(configChangeStep){
console.log("*********Water configChangeStep = " + configChangeStep)
var oldpwrusageString = pwrusageFile.read()
switch (configChangeStep) {
case 0: {
console.log("*********Water show popup")
app.popupString = "Water instellen en herstarten als nodig" + "..."
app.waterRebootPopup.show()
break;
}
case 1: {
if (oldprice != newprice) {
console.log("*********Water check pwrusageFileString for tariff")
pwrusageFileBak.write(oldpwrusageString)
try {
var tariffOld = new XMLHttpRequest();
tariffOld.onreadystatechange = function() {
if (tariffOld.readyState == XMLHttpRequest.DONE) {
var newContent = tariffOld.responseText
newContent = newContent.replace('<price>' + oldprice + '</price>','<price>' + newprice + '</price>')
var tariffNew = new XMLHttpRequest();
tariffNew.open("PUT", pwrusageFileString);
tariffNew.send(newContent);
tariffNew.close;
app.popupString = "Prijs inclusief belastingen opgeslagen" + "..."
needReboot = true
}
}
tariffOld.open("GET", pwrusageFileString, true);
tariffOld.send();
} catch(e) { }
}else{
app.popupString = "Prijs inclusief belastingen niet gewijzigd" + "..."
}
break;
}
case 2: {
if (!needReboot) {
console.log("*********Water no changes in tariff so no need to restart")
app.popupString = "Restart niet nodig" + "..."
app.waterRebootPopup.hide()
configChangeStep = 20
stepRunning = false
hide()
break
}
break;
}
case 3: {
if (needReboot) {
console.log("*********Water reboot")
console.log("*********Water restartingToon")
app.popupString = "Herstarten van Toon" + "..."
app.waterRebootPopup.hide()
//app.restartToon()
//Qt.quit();
}
break;
}
default: {
console.log("*********Water to default case ")
app.waterRebootPopup.hide()
configChangeStep = 20
stepRunning = false
needReboot = false
hide()
break;
}
}
}
Timer {
id: stepTimer //interval to nicely save all and reboot
interval: 3000
repeat:true
running: stepRunning
triggeredOnStart: true
onTriggered: {
modTariff(configChangeStep)
configChangeStep++
}
}
}