40 lines
910 B
QML
40 lines
910 B
QML
import QtQml.Models 2.1
|
|
|
|
ListModel {
|
|
id: root
|
|
|
|
property string serviceUrl: undefined
|
|
|
|
signal error(string text)
|
|
|
|
onServiceUrlChanged: reload()
|
|
|
|
function reload() {
|
|
var request = new XMLHttpRequest()
|
|
|
|
request.open('GET', root.serviceUrl + '/static/channels.js')
|
|
request.onreadystatechange = function () {
|
|
if (request.readyState !== XMLHttpRequest.DONE) {
|
|
return
|
|
}
|
|
|
|
if (request.status === 200) {
|
|
populateModel(JSON.parse(request.responseText))
|
|
return
|
|
}
|
|
|
|
root.error(qsTr("[%1] Request error: %2").
|
|
arg(request.status).
|
|
arg(request.statusText))
|
|
}
|
|
|
|
request.send()
|
|
}
|
|
|
|
function populateModel(data) {
|
|
data.groups.forEach(function (group) {
|
|
root.append(group)
|
|
})
|
|
}
|
|
}
|