-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathMessageScreen.qml
More file actions
286 lines (244 loc) · 6.48 KB
/
MessageScreen.qml
File metadata and controls
286 lines (244 loc) · 6.48 KB
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
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
import QtQuick 2.1
import qb.components 1.0
import BasicUIControls 1.0;
Screen {
id: mediaSelectZoneScreen
screenTitle: "Audioberichten"
property bool waitForMessageCompletion : false
Component.onCompleted: { //get automatic updates from your favourite football teams (via the voetbal app)
try{
tscsignals.tscSignal.connect(playMessage);
} catch(e) {
}
}
function playMessage(appName, appArguments) {
if ((appName == "sonos") && app.playFootballScores) {
var xmlhttp = new XMLHttpRequest();
xmlhttp.open("GET", "http://"+app.connectionPath+"/"+app.sonosNameVoetbalApp+"/say/" + appArguments + "/nl-nl/" + app.messageVolume);
xmlhttp.send();
}
}
onShown: {
saveVolumeLabel.inputText = app.messageVolume;
updateZones();
fillEffectsList();
}
function fillEffectsList() {
// fill favourites list
favouritesScrollableSimpleList.removeAll();
for (var i = 0; i < app.messageTextArray.length; i++) {
favouritesScrollableSimpleList.addDevice(app.messageTextArray[i]);
}
favouritesScrollableSimpleList.refreshView();
}
function updateZones() {
var xmlhttp = new XMLHttpRequest();
xmlhttp.onreadystatechange=function() {
if (xmlhttp.readyState == 4) {
if (xmlhttp.status == 200) {
var response = JSON.parse(xmlhttp.responseText);
if (response.length > 0) {
zoneNameModel.clear();
zoneNameModel.append({zoneName: "Alle"});
for (var i = 0; i < response.length; i++) {
zoneNameModel.append({zoneName: response[i]["coordinator"]["roomName"]});
}
}
}
}
}
xmlhttp.open("GET", "http://"+app.connectionPath+"/zones");
xmlhttp.send();
}
function removeText(item) {
var i = app.messageTextArray.indexOf(item);
if (i > -1) {
app.messageTextArray.splice(i, 1);
}
app.saveSettings();
fillEffectsList();
}
function saveText(text) {
if (text) {
saveTextNameLabel.inputText = text;
app.messageTextArray.push(text);
app.saveSettings();
}
}
function saveVolume(text) {
if (text) {
app.messageVolume = text;
saveVolumeLabel.inputText = app.messageVolume;
app.saveSettings();
}
}
function validateVolume(text, isFinalString) {
if (isFinalString) {
if ((parseInt(text) > 19) && (parseInt(text) < 101))
return null;
else
return {title: "Ongeldig volume", content: "Voer een getal in tussen 20 en 100"};
}
return null;
}
Text {
id: txtBox
text: "1. Selekteer een zone:"
height: isNxt ? 35 : 28
font.pixelSize: isNxt ? 25 : 20
font.family: qfont.regular.name
font.bold: true
color: colors.tileTextColor
width: isNxt ? 250 : 200
anchors.top: parent.top
anchors.topMargin : 10
anchors.left: parent.left
anchors.leftMargin : isNxt ? 25 : 20
}
ControlGroup {
id: zoneGroup
exclusive: false
}
GridView {
id: zoneGridView
model: zoneNameModel
delegate: MessageScreenDelegate {}
interactive: false
flow: GridView.TopToBottom
cellWidth: isNxt ? 320 : 250
cellHeight: isNxt ? 50 : 40
anchors {
fill: parent
top: txtBox.bottom
left: txtBox.left
topMargin: isNxt ? 50 : 40
}
}
EditTextLabel4421 {
id: saveTextNameLabel
width: favouritesScrollableSimpleList.width
height: isNxt ? 44 : 35
leftTextAvailableWidth: isNxt ? 200 : 160
leftText: "Nieuwe Tekst:"
anchors {
left: txtBox.left
leftMargin: isNxt ? 375 : 300
top: txtBox.top
topMargin: isNxt ? 40 : 32
}
onClicked: {
qkeyboard.open("Naam favouriet:", saveTextNameLabel.inputText, saveText);
}
}
Text {
id: txtBox2
text: "2. Kies volume audiobericht:"
height: isNxt ? 35 : 28
font.pixelSize: isNxt ? 25 : 20
font.family: qfont.regular.name
font.bold: true
color: colors.tileTextColor
width: isNxt ? 250 : 200
anchors.bottom: saveVolumeLabel.top
anchors.left: saveVolumeLabel.left
}
Text {
id: txtBox3
text: "3. Kies bericht om af te spelen:"
height: isNxt ? 35 : 28
font.pixelSize: isNxt ? 25 : 20
font.family: qfont.regular.name
font.bold: true
color: colors.tileTextColor
width: isNxt ? 250 : 200
anchors.bottom: txtBox.bottom
anchors.left: favouritesScrollableSimpleList.left
}
EditTextLabel4421 {
id: saveVolumeLabel
width: isNxt ? 200 : 160
height: isNxt ? 44 : 35
leftTextAvailableWidth: isNxt ? 125 : 100
leftText: "Volume:"
anchors {
left: txtBox.left
bottom: favouritesScrollableSimpleList.bottom
}
onClicked: {
qkeyboard.open("Volume (20 - 100)", saveVolumeLabel.inputText, saveVolume, validateVolume);
}
}
ListModel {
id: zoneNameModel
}
// favourites Message list
//this is the delegate of the saved messages
Component {
id: favouritesDelegate
//make it clickable
Item {
width: isNxt ? 500 : 400
height: isNxt ? 50 : 40
visible: (waitForMessageCompletion == false)
//name and number showed in the playlist
StandardButton {
id: listItemText
text: item
width: isNxt ? parent.width - 50 : parent.width - 40
anchors {
top: parent.top
left: parent.left
topMargin: 10
}
onClicked: {
waitForMessageCompletion = true;
var xmlhttp = new XMLHttpRequest();
if (app.messageSonosName == "Alle") {
xmlhttp.open("GET", "http://"+app.connectionPath+"/sayall/" + item + "/nl-nl/" + app.messageVolume);
} else {
xmlhttp.open("GET", "http://"+app.connectionPath+"/"+app.messageSonosName+"/say/" + item + "/nl-nl/" + app.messageVolume);
}
xmlhttp.onreadystatechange=function() {
if (xmlhttp.readyState == 4) {
if (xmlhttp.status == 200) {
var messageResponse = "Fout in versturen bericht";
var response = JSON.parse(xmlhttp.responseText);
if (response['status']) {
if (response['status'] == "success") {
messageResponse = "Bericht succesvol afgespeeld";
}
}
qdialog.showDialog(qdialog.SizeSmall, "Sonos mededeling", messageResponse, "Sluiten");
waitForMessageCompletion = false;
}
}
}
xmlhttp.send();
}
}
IconButton {
id: deleteIcon
width: 40
iconSource: "qrc:/tsc/icon_delete.png"
anchors {
left: listItemText.right
leftMargin: 10
top: listItemText.top
}
bottomClickMargin: 3
onClicked: removeText(item)
}
}
}
//property's of the scrollable list
ScrollableSimpleList {
id: favouritesScrollableSimpleList
width: isNxt ? 600 : 480
height: isNxt ? 375 : 300
itemsPerPage: 6
delegate: favouritesDelegate
anchors.top: saveTextNameLabel.bottom
anchors.right: saveTextNameLabel.right
anchors.topMargin: isNxt ? 25 : 20
}
}