57 lines
1.1 KiB
QML
57 lines
1.1 KiB
QML
import QtQml.Models 2.1
|
|
|
|
ListModel {
|
|
id: root
|
|
|
|
readonly property var client: NooLiteClient {
|
|
id: nooLiteClient
|
|
|
|
onError: {
|
|
root.error(text)
|
|
root.isLoading = false
|
|
}
|
|
|
|
onModelLoad: {
|
|
root.populateModel(data)
|
|
root.isLoading = false
|
|
}
|
|
}
|
|
|
|
property alias serviceUrl: nooLiteClient.serviceUrl
|
|
property bool isLoading: false
|
|
|
|
property int channelsCount: 0
|
|
|
|
signal error(string text)
|
|
|
|
onServiceUrlChanged: reload()
|
|
|
|
function reload() {
|
|
root.client.loadModel()
|
|
root.isLoading = true
|
|
}
|
|
|
|
function populateModel(data) {
|
|
root.clear()
|
|
root.channelsCount = 0
|
|
|
|
data.groups.forEach(function (group) {
|
|
root.append(group)
|
|
|
|
root.channelsCount += group.channels.length
|
|
})
|
|
}
|
|
|
|
function switchChannel(channelId) {
|
|
root.client.sendCommand("switch", channelId)
|
|
}
|
|
|
|
function bindChannel(channelId) {
|
|
root.client.sendCommand("bind", channelId)
|
|
}
|
|
|
|
function unbindChannel(channelId) {
|
|
root.client.sendCommand("unbind", channelId)
|
|
}
|
|
}
|