Debian Codegraph @

qml/generic/Search.qml

raw
1 import QtQuick 2.2
2 import QtQuick.Controls 1.1
3 import QtQuick.Layouts 1.1
4 import QtQuick.Window 2.1
5 import "UI" 1.0
6
7
8 Item {
9 property bool init: p.updateMessage === ""
10 state: "initing"
11
12 Window {
13 id: downloadWin
14 property int maxId: download.maxId
15 onMaxIdChanged: visible = (maxId > 0)
16 //visible: false
17 onVisibleChanged: if (visible) {
18 x = window.x + (window.width - width) / 2
19 y = window.y + (window.height - height) / 2
20 }
21 width: parent.width / 3; height: Math.min(parent.height / 2, width + 20);
22 color: "lightgray"
23 title: qsTr("Download") + translator.lang
24
25 ColumnLayout {
26 anchors.fill: parent
27 CircleProgress {
28 Layout.fillHeight: true
29 Layout.fillWidth: true
30 currentValue: download.curProgress
31 overallValue: download.progress
32 curId: download.id + 1
33 maxId: download.maxId
34 statusText: "Downloading"
35 text: download.curName
36 }
37 Button {
38 id: cancelButton
39 text: qsTr("Cancel Download") + translator.lang
40 onClicked: download.reset();
41 anchors.horizontalCenter: parent.horizontalCenter
42 }
43 }
44 }
45 Column {
46 id: scanButton
47 anchors { bottom: parent.bottom; bottomMargin: 15; leftMargin: 15 }
48 ColumnLayout {
49 anchors.horizontalCenter: parent.horizontalCenter
50 Button {
51 id: searchButton
52 anchors.horizontalCenter: parent.horizontalCenter
53 enabled: !p.scanning
54 text: (p.scanning ? qsTr("Searching...") : qsTr("Search")) + translator.lang
55 onClicked: { p.updateDetailRequest((/*delta.checked ? i.appDeltaMsg() :*/ ""), country.value, carrier.value, device.selectedItem, variant.selectedItem, mode.selectedItem /*, server.selectedItem , version.selectedItem*/) } }
56 RadioButton {
57 id: delta
58 anchors.horizontalCenter: parent.horizontalCenter
59 visible: false && settings.advanced && !p.scanning && typeof i !== 'undefined' && i.appCount > 0
60 checked: true
61 text: qsTr("Delta") + translator.lang
62 }
63 Button {
64 text: qsTr("Version Lookup") + translator.lang
65 onClicked: versionLookup.visible = !versionLookup.visible
66 }
67 }
68 Text {
69 property string message: p.error
70 visible: message.length > 1 && !p.multiscan && p.updateMessage == ""
71 Layout.alignment: Qt.AlignHCenter
72 font.bold: true
73 onMessageChanged: if (message.length && message.length < 5)
74 text = qsTr("Server did not respond as expected [%1].").arg(message)
75 else if (message === "Success")
76 text = qsTr("Success. No updates were available.")
77 else
78 text = message;
79 }
80 }
81 RowLayout {
82 id: urlLinks
83 anchors { left: variables.right; right: parent.right; bottom: parent.bottom; margins: 15 }
84 GroupBox {
85 title: qsTr("Download For") + translator.lang
86 TextCoupleSelect {
87 id: downloadDevice
88 type: qsTr("Device") + translator.lang
89 selectedItem: 0
90
91 //property int familyType: (selectedItem == 0) ? i.device.hwFamily : selectedItem
92 property string hwid: i.device === null ? "" : i.device.hw
93 property int hwfam: i.device === null ? 0 : i.device.hwFamily
94 property string familyName: (hwfam == 0 || hwfam > listModel.count) ? qsTr("Unknown") : listModel.get(hwfam).text
95 subtext: hwid != "" ? hwid + " (" + familyName + ")" : ""
96 onSubtextChanged: generateModel()
97 Component.onCompleted: generateModel()
98
99 function generateModel() {
100 var newText = (hwid != "Unknown" && hwid != "") ? qsTr("Connected") : qsTr("As Searched")
101 if (listModel.count < 2 || listModel.get(0).text !== newText) {
102 listModel.clear()
103 listModel.append({"text" : newText })
104 for (var i = 0; i < babyModel.count; i++)
105 listModel.append({"text" : babyModel.get(i).text })
106 }
107 }
108
109 listModel: ListModel {
110 ListElement { text: "As Searched" }
111 }
112 }
113 }
114 ColumnLayout {
115 Button {
116 enabled: p.updateCheckedCount > 0
117 Layout.alignment: Qt.AlignHCenter
118 text: qsTr("Grab Links") + translator.lang
119 onClicked: p.grabLinks(downloadDevice.selectedItem)
120 }
121 Button {
122 enabled: p.updateCheckedCount > 0 && !download.verifying
123 visible: !download.running
124 Layout.alignment: Qt.AlignHCenter
125 text: (download.verifying ? qsTr("Verifying") : qsTr("Download")) + translator.lang
126 onClicked: { download.start(); p.downloadLinks(downloadDevice.selectedItem) }
127 }
128 Button {
129 visible: download.running
130 text: qsTr("View Download (%1%)").arg(download.progress) + translator.lang
131 onClicked: downloadWin.visible = true
132 }
133 Button {
134 visible: download.running
135 text: qsTr("Cancel Download") + translator.lang
136 onClicked: download.reset();
137 }
138 }
139 }
140 ColumnLayout {
141 id: variables
142 anchors.top: parent.top
143 anchors.topMargin: 30
144 anchors.leftMargin: 10
145 Layout.fillHeight: true
146 height: (parent.height * 4) / 6
147 Button {
148 id: hideWhitelistButton
149 checkable: true
150 text: checked ? qsTr("Hide") : qsTr("Show Settings")
151 }
152
153 ColumnLayout {
154 id: whitelistSettings
155 spacing: 25
156 scale: hideWhitelistButton.checked
157 visible: scale !== 0.0
158 Behavior on scale { NumberAnimation { duration: 300 } }
159 Label {
160 font.pointSize: 14
161 text: qsTr("Whitelist Settings") + translator.lang
162 font.bold: true
163 }
164 Label {
165 visible: !settings.advanced
166 text: qsTr("Finds updates approved by other carriers") + translator.lang
167 }
168 // On a new device becoming connected, update search results
169 property bool devicePresent: i.completed
170 property bool githubUpdateComplete: false
171 onDevicePresentChanged: if (githubUpdateComplete && devicePresent && searchButton.enabled) searchButton.clicked()
172 // Find latest country/carrier pair from github
173 property string latestOS: "10.3.2.840"
174 Component.onCompleted: {
175 var http = new XMLHttpRequest()
176 var url = "https://raw.githubusercontent.com/xsacha/Sachesi/master/carrier";
177 http.open("GET", url, true);
178 http.send(null)
179 http.onreadystatechange = function() {
180 if(http.readyState == 4 && http.status == 200) {
181 var array = http.responseText.split('\n');
182 array = array.filter(function(e){return e});
183 if (array.length > 3) {
184 country.value = array[0]
185 carrier.value = array[1]
186 device.selectedItem = parseInt(array[2])
187 latestOS = array[3]
188 if (array.length > 4) {
189 variant.selectedItem = parseInt(array[4])
190 }
191 if (searchButton.enabled)
192 searchButton.clicked()
193 githubUpdateComplete = true;
194 }
195 }
196 }
197 }
198 TextCouple {
199 id: country
200 type: qsTr("Country") + translator.lang
201 value: "310"
202 subtext: carrierinfo.country
203 restrictions: Qt.ImhDigitsOnly | Qt.ImhNoPredictiveText
204 maxLength: 3
205 onValueChanged: if (value.length == 3) carrierinfo.mccChange(value);
206 onClicked: searchButton.clicked();
207 helpLink: "https://en.wikipedia.org/w/index.php?title=Mobile_country_code"
208 }
209 TextCouple {
210 id: carrier
211 type: qsTr("Carrier") + translator.lang
212 value: "200"
213 subtext: carrierinfo.carrier
214 restrictions: Qt.ImhDigitsOnly | Qt.ImhNoPredictiveText
215 maxLength: 3
216 onValueChanged: if (value.length > 0 && value.length <= 3) carrierinfo.mncChange(("00" + value).slice(-3));
217 onClicked: searchButton.clicked();
218 }
219 Image {
220 source: carrierinfo.image <= 0 ? "" : "http://appworld.blackberry.com/ClientAPI/image/" + carrierinfo.image + "/150X/png"
221 sourceSize {height: carrier.height * 2 }
222 }
223
224 GroupBox {
225 title: qsTr("Search For") + translator.lang
226 ColumnLayout {
227 TextCoupleSelect {
228 id: device
229 selectedItem: 0
230 type: qsTr("Device") + translator.lang
231
232 // List everything we know except abandoned models
233 ListModel {
234 id: advancedModel
235 ListElement { text: "Z30 + Classic + Leap"}
236 ListElement { text: "Z10 (OMAP)" }
237 ListElement { text: "Z10 (QCOM) + P9982" }
238 ListElement { text: "Z3 + Kopi/Cafe" }
239 ListElement { text: "Passport" }
240 ListElement { text: "Q5 + Q10 + P9983" }
241 ListElement { text: "Developer" }
242 ListElement { text: "Ontario"}
243 }
244 // Only list released models
245 ListModel {
246 id: babyModel
247 ListElement { text: "Z30 + Classic" }
248 ListElement { text: "Z10 (STL 100-1)" }
249 ListElement { text: "Z10 (STL 100-2/3/4) + P9982" }
250 ListElement { text: "Z3"}
251 ListElement { text: "Passport"}
252 ListElement { text: "Q5 + Q10 + P9983"}
253 }
254 function changeModel() {
255 var selected = selectedItem
256 listModel = settings.advanced ? advancedModel : babyModel
257 selectedItem = Math.min(selected, listModel.count - 1);
258 }
259 function updateVariant() {
260 if (variantModel != null) {
261 variantModel.clear()
262 if (p.variantCount(selectedItem) > 1)
263 variantModel.append({ 'text': qsTr('Any')});
264 for (var i = 0; i < p.variantCount(selectedItem); i++)
265 variantModel.append({ 'text': p.nameFromVariant(selectedItem, i)})
266
267 variant.selectedItem = 10;
268 }
269 }
270 property bool advanced: settings.advanced
271 onAdvancedChanged: changeModel()
272 onSelectedItemChanged: updateVariant();
273 Component.onCompleted: { changeModel(); updateVariant(); }
274 }
275
276 TextCoupleSelect {
277 id: variant
278 type: qsTr("Variant") + translator.lang
279 selectedItem: 9
280 // This is going to be hell to maintain. Maybe an identifier in dev[] for carrier-specific and its associated code?
281 /*onSelectedItemChanged: if (device.text === "Z10 QCOM" && selectedItem == 3) { country.value = "311"; carrier.value = "480" }
282 else if (device.text === "Q10" && selectedItem == 2) { country.value = "311"; carrier.value = "480" }
283 else if (device.text === "Q10" && selectedItem == 4) { country.value = "310"; carrier.value = "120" }
284 else if (device.text === "Z30" && selectedItem == 3) { country.value = "311"; carrier.value = "480" }
285 else if (device.text === "Z30" && selectedItem == 4) { country.value = "310"; carrier.value = "120" }*/
286
287 listModel: ListModel { id: variantModel; }
288 }
289 }
290 }
291
292 TextCoupleSelect {
293 visible: settings.advanced
294 id: mode
295 type: qsTr("Mode") + translator.lang
296 listModel: [ qsTr("Upgrade") + translator.lang, qsTr("Debrick") + translator.lang ]
297 }
298
299 /*TextCoupleSelect {
300 visible: settings.advanced
301 id: server
302 type: qsTr("Server") + translator.lang
303 listModel: [ qsTr("Production") + translator.lang, qsTr("Beta") + translator.lang, qsTr("Beta 2") + translator.lang, qsTr("Alpha") + translator.lang, qsTr("Alpha 2") + translator.lang ]
304 }*/
305
306 /*TextCoupleSelect {
307 id: version
308 type: "API"
309 listModel: [ "2.1.0", "2.0.0", "1.0.0" ]
310 }*/
311 }
312 }
313 VersionLookup {
314 id: versionLookup
315 }
316
317 TextArea {
318 id: updateMessage
319 anchors {top: parent.top; left: variables.right; right: parent.right; margins: 15; }
320 Layout.fillWidth: true
321 height: parent.height / 10
322 text: p.updateMessage
323 readOnly: true
324 textFormat: TextEdit.RichText
325 selectByKeyboard: true
326 }
327
328 // Changes required to make this workable
329 // - Need to prevent it being horizontally scrollable or at least make it fit by default
330 // - Requires Qt 5.3 for resizeToContents()!!
331 // - Context menu doesn't work? We need (Un)Check All
332 /*TableView {
333 id: updateAppMessage
334 anchors {top: updateMessage.bottom; bottom: urlLinks.top; left: variables.right; right: parent.right; margins: 15; }
335 Layout.fillHeight: true
336 Layout.fillWidth: true
337 alternatingRowColors: false
338 backgroundVisible: false
339 model: p.updateAppList
340 Menu {
341 id: options_menu
342 signal checkAll()
343 signal uncheckAll()
344 title: qsTr("Options") + translator.lang
345 MenuItem {
346 enabled: p.updateCheckedCount != p.updateAppCount
347 text: qsTr("Check All") + translator.lang
348 onTriggered: {
349 options_menu.checkAll();
350 for (var i = 0; i < p.updateAppCount; i++)
351 p.updateAppList[i].isMarked = true;
352 }
353 }
354 MenuItem {
355 enabled: p.updateCheckedCount > 0
356 text: qsTr("Uncheck All") + translator.lang
357 onTriggered: {
358 options_menu.uncheckAll()
359 for (var i = 0; i < p.updateAppCount; i++)
360 p.updateAppList[i].isMarked = false;
361 }
362 }
363 }
364 TableViewColumn { width: parent.width - verCol.width - sizeCol.width; id: nameCol; role: "friendlyName"; title: qsTr("Name") + translator.lang; }
365 TableViewColumn { id: verCol; role: "version"; title: qsTr("Version") + translator.lang; resizable: false; }
366 TableViewColumn { id: sizeCol; role: "size"; title: qsTr("Size") + translator.lang; resizable: false; }
367 //onModelChanged: { verCol.resizeToContents(); sizeCol.resizeToContents(); }
368 rowDelegate: Rectangle {
369 opacity: 0.2
370 color: { switch(typeof modelData != 'undefined' ? modelData.type : "") {
371 case "os": return "red";
372 case "radio": return "purple";
373 case "application": if (modelData.friendlyName.indexOf("sys.data") === 0) return "lightblue"; else return "steelblue";
374 default: return "transparent";
375 }
376 }
377 }
378
379 itemDelegate: Text {
380 property variant value: styleData.value
381 text: styleData.role === "size" ? qsTr("%1 MB").arg((value / 1024 / 1024).toFixed(1)) + translator.lang : value
382 horizontalAlignment: (styleData.role === "size") ? Qt.AlignRight : Qt.AlignLeft
383 clip: true
384 }
385 }*/
386
387 // Cheat to get system widths of text here. Should use a TableView (above) later to replace it.
388 // A Label with 6 characters and ' MB', like the maximum filesize of an app
389 Label { visible: false; id: sizeHint; font.pointSize: 12; text: qsTr("1700.0 MB") + translator.lang; }
390 GroupBox {
391 id: updateAppMessage
392 // Qt 5.2 width bug: Add an extra 8 spaces to message to compensate
393 property string selectedMsg: qsTr("Selected: %1 Apps").arg(p.updateCheckedCount == p.updateAppCount ? qsTr("All (%1)").arg(p.updateAppCount) : (p.updateCheckedCount + "/" + p.updateAppCount))
394 + (p.updateNeededCount !== p.updateAppCount ? (" | " + qsTr("Needed: %1 Apps").arg(p.updateCheckedNeededCount == p.updateAppNeededCount ? qsTr("All (%1)").arg(p.updateAppNeededCount) : p.updateCheckedNeededCount + "/" + p.updateAppNeededCount)) : "")
395 + " " + translator.lang
396 title: selectedMsg
397
398 anchors {top: updateMessage.bottom; bottom: urlLinks.top; left: variables.right; right: parent.right; margins: 15; }
399 Layout.fillHeight: true
400 Layout.fillWidth: true
401 ScrollView {
402 anchors.fill: parent
403 ListView {
404 anchors.fill: parent
405 spacing: 3
406 clip: true
407 model: p.updateAppList
408 Menu {
409 id: options_menu
410 signal checkAll()
411 signal checkAllNeeded()
412 signal uncheckAll()
413 title: qsTr("Options") + translator.lang
414 MenuItem {
415 enabled: p.updateCheckedCount !== p.updateAppCount
416 text: qsTr("Check All") + translator.lang
417 onTriggered: {
418 options_menu.checkAll();
419 for (var i = 0; i < p.updateAppCount; i++)
420 p.updateAppList[i].isMarked = true;
421 }
422 }
423 MenuItem {
424 enabled: p.updateCheckedNeededCount !== p.updateAppNeededCount
425 text: qsTr("Check All Needed") + translator.lang
426 onTriggered: {
427 options_menu.checkAllNeeded();
428 for (var i = 0; i < p.updateAppCount; i++)
429 p.updateAppList[i].isMarked = (p.updateAppList[i].isAvailable && !p.updateAppList[i].isInstalled);
430 }
431 }
432 MenuItem {
433 enabled: p.updateCheckedCount > 0
434 text: qsTr("Uncheck All") + translator.lang
435 onTriggered: {
436 options_menu.uncheckAll()
437 for (var i = 0; i < p.updateAppCount; i++)
438 p.updateAppList[i].isMarked = false;
439 }
440 }
441 }
442
443 MouseArea {
444 acceptedButtons: Qt.RightButton
445 onClicked: options_menu.popup()
446 anchors.fill: parent
447 }
448 delegate: Item {
449 visible: type !== "";
450 width: parent.width - 3
451 height: type === "" ? 0 : 26
452 Rectangle {
453 anchors.fill: parent
454 color: { switch(type) {
455 case "os": return "red";
456 case "radio": return "purple";
457 case "application": if (friendlyName.indexOf("sys.data") === 0) return "lightblue"; else return "steelblue";
458 default: return "transparent";
459 }
460 }
461 opacity: 0.2
462 }
463 CheckBox {
464 id: delegateBox
465 text: friendlyName + (isInstalled ? " " + qsTr("(older)") : (isAvailable ? "" : " " + qsTr("(downloaded)"))) + translator.lang
466 opacity: (!isInstalled && isAvailable) ? 1.0 : 0.6
467 width: Math.min(implicitWidth, parent.width - versionText.width*versionText.visible - sizeText.width)
468 clip: true
469 checked: isMarked
470 onCheckedChanged: isMarked = checked;
471 Connections {
472 target: options_menu
473 onCheckAll: delegateBox.checked = true;
474 onCheckAllNeeded: delegateBox.checked = isAvailable && !isInstalled;
475 onUncheckAll: delegateBox.checked = false;
476 }
477 }
478
479 Label {
480 id: versionText
481 anchors.right: sizeText.left;
482 visible: (parent.width - sizeText.paintedWidth) > delegateBox.implicitWidth
483 text: version
484 }
485 Label {
486 id: sizeText
487 anchors.right: parent.right
488 width: sizeHint.width
489 horizontalAlignment: Text.AlignRight
490 text: qsTr("%1 MB").arg((size / 1024 / 1024).toFixed(1)) + translator.lang
491 font.pointSize: 12;
492 }
493 }
494 }
495 }
496 }
497
498 states: [
499 State {
500 name: "initing"
501 when: init
502 AnchorChanges { target: variables; anchors.horizontalCenter: parent.horizontalCenter; anchors.left: undefined }
503 AnchorChanges { target: scanButton; anchors.horizontalCenter: parent.horizontalCenter; anchors.left: undefined }
504 PropertyChanges { target: updateMessage; visible: false; opacity: 0.0; scale: 0.4 }
505 PropertyChanges { target: updateAppMessage; visible: false; opacity: 0.0; scale: 0.4 }
506 PropertyChanges { target: urlLinks; visible: false; opacity: 0.0; scale: 0.4 }
507 },
508 State {
509 name: "showing"
510 when: !init
511 AnchorChanges { target: variables; anchors.horizontalCenter: undefined; anchors.left: parent.left }
512 AnchorChanges { target: scanButton; anchors.horizontalCenter: undefined; anchors.left: parent.left }
513 PropertyChanges { target: updateMessage; visible: true; opacity: 1.0; scale: 1.0 }
514 PropertyChanges { target: updateAppMessage; visible: true; opacity: 1.0; scale: 1.0 }
515 PropertyChanges { target: urlLinks; visible: true; opacity: 1.0; scale: 1.0 }
516 }
517 ]
518
519 transitions:
520 Transition {
521 from: "initing, showing, error"
522 AnchorAnimation { duration: 200 }
523 PropertyAnimation { property: "opacity"; duration: 200 }
524 PropertyAnimation { property: "scale"; duration: 200 }
525 }
526 }