|
|
@@ -0,0 +1,50 @@
|
|
|
+import QtQuick 2.0
|
|
|
+
|
|
|
+QtObject {
|
|
|
+ id: root
|
|
|
+
|
|
|
+ property string serviceUrl: undefined
|
|
|
+
|
|
|
+ signal modelLoad(var data)
|
|
|
+ signal error(string text)
|
|
|
+
|
|
|
+ function _get(url, callback) {
|
|
|
+ var request = new XMLHttpRequest()
|
|
|
+
|
|
|
+ request.open('GET', url)
|
|
|
+ request.onreadystatechange = function () {
|
|
|
+ if (request.readyState !== XMLHttpRequest.DONE) {
|
|
|
+ return
|
|
|
+ }
|
|
|
+
|
|
|
+ if (request.status === 200) {
|
|
|
+ if (callback !== undefined) {
|
|
|
+ callback(JSON.parse(request.responseText))
|
|
|
+ }
|
|
|
+
|
|
|
+ return
|
|
|
+ }
|
|
|
+
|
|
|
+ root.error(qsTr("[%1] Request error: %2").
|
|
|
+ arg(request.status).
|
|
|
+ arg(request.statusText))
|
|
|
+ }
|
|
|
+
|
|
|
+ request.send()
|
|
|
+ }
|
|
|
+
|
|
|
+ function loadModel() {
|
|
|
+ _get(root.serviceUrl + '/static/channels.js', root.modelLoad)
|
|
|
+ }
|
|
|
+
|
|
|
+ function switchChannel(channelId) {
|
|
|
+ _get(root.serviceUrl + '/noolite/switch/%1'.arg(channelId), function (data) {
|
|
|
+ if (data.error) {
|
|
|
+ root.error(qsTr("Server error: %1").arg(data.error))
|
|
|
+ return
|
|
|
+ }
|
|
|
+
|
|
|
+ console.log(data.command, data.channel)
|
|
|
+ })
|
|
|
+ }
|
|
|
+}
|