LightsModel.qml 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. import QtQml.Models 2.1
  2. ListModel {
  3. id: root
  4. readonly property var client: NooLiteClient {
  5. id: nooLiteClient
  6. onError: (text) => {
  7. root.error(text)
  8. root.isLoading = false
  9. }
  10. onModelLoad: (data) => {
  11. root.populateModel(data)
  12. root.isLoading = false
  13. }
  14. }
  15. property alias serviceUrl: nooLiteClient.serviceUrl
  16. property bool isLoading: false
  17. property int channelsCount: 0
  18. signal error(string text)
  19. onServiceUrlChanged: reload()
  20. function reload() {
  21. root.client.loadModel()
  22. root.isLoading = true
  23. }
  24. function populateModel(data) {
  25. root.clear()
  26. root.channelsCount = 0
  27. data.groups.forEach(function (group) {
  28. root.append(group)
  29. root.channelsCount += group.channels.length
  30. })
  31. }
  32. function switchChannel(channelId) {
  33. root.client.sendCommand("switch", channelId)
  34. }
  35. function bindChannel(channelId) {
  36. root.client.sendCommand("bind", channelId)
  37. }
  38. function unbindChannel(channelId) {
  39. root.client.sendCommand("unbind", channelId)
  40. }
  41. }