diff --git a/HomeForm.qml b/HomeForm.qml
index 6d95862..1b5e215 100644
--- a/HomeForm.qml
+++ b/HomeForm.qml
@@ -4,18 +4,6 @@ import QtQuick.Controls 2.0
Page {
title: qsTr("nooLight")
- function showError(text) {
- ToolTip.show(text, 1000)
- }
-
- LightsModel {
- id: lightsModel
-
- serviceUrl: settings.serviceUrl
-
- onError: showError(text)
- }
-
ListView {
anchors.fill: parent
anchors.margins: 5
diff --git a/LightsModel.qml b/LightsModel.qml
index a5d3c2e..0d6719b 100644
--- a/LightsModel.qml
+++ b/LightsModel.qml
@@ -20,6 +20,8 @@ ListModel {
property alias serviceUrl: nooLiteClient.serviceUrl
property bool isLoading: false
+ property int channelsCount: 0
+
signal error(string text)
onServiceUrlChanged: reload()
@@ -30,12 +32,25 @@ ListModel {
}
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.switchChannel(channelId)
+ root.client.sendCommand("switch", channelId)
+ }
+
+ function bindChannel(channelId) {
+ root.client.sendCommand("bind", channelId)
+ }
+
+ function unbindChannel(channelId) {
+ root.client.sendCommand("unbind", channelId)
}
}
diff --git a/NooLiteClient.qml b/NooLiteClient.qml
index caba1f2..7a6ff64 100644
--- a/NooLiteClient.qml
+++ b/NooLiteClient.qml
@@ -37,8 +37,8 @@ QtObject {
_get(root.serviceUrl + '/static/channels.js', root.modelLoad)
}
- function switchChannel(channelId) {
- _get(root.serviceUrl + '/noolite/switch/%1'.arg(channelId), function (data) {
+ function sendCommand(command, channelId) {
+ _get(root.serviceUrl + '/noolite/%1/%2'.arg(command).arg(channelId), function (data) {
if (data.error) {
root.error(qsTr("Server error: %1").arg(data.error))
return
diff --git a/ServiceForm.qml b/ServiceForm.qml
new file mode 100644
index 0000000..0e6dcbc
--- /dev/null
+++ b/ServiceForm.qml
@@ -0,0 +1,40 @@
+import QtQuick 2.0
+import QtQuick.Controls 2.2
+
+Page {
+ id: root
+
+ title: qsTr("Service")
+
+ ListView {
+ model: lightsModel.channelsCount
+
+ anchors.fill: parent
+
+ delegate: Row {
+ spacing: 4
+
+ anchors.horizontalCenter: parent.horizontalCenter
+
+ Button {
+ width: 160
+
+ text: qsTr("Bind channel %1").arg(index)
+
+ onClicked: {
+ lightsModel.bindChannel(index)
+ }
+ }
+
+ Button {
+ width: 160
+
+ text: qsTr("Unbind channel %1").arg(index)
+
+ onClicked: {
+ lightsModel.unbindChannel(index)
+ }
+ }
+ }
+ }
+}
diff --git a/main.qml b/main.qml
index 8451453..84ef5fa 100644
--- a/main.qml
+++ b/main.qml
@@ -16,6 +16,14 @@ ApplicationWindow {
property string serviceUrl: ""
}
+ LightsModel {
+ id: lightsModel
+
+ serviceUrl: settings.serviceUrl
+
+ onError: stackView.showError(text)
+ }
+
header: ToolBar {
contentHeight: 36
@@ -72,16 +80,19 @@ ApplicationWindow {
}
}
+ ItemDelegate {
+ text: qsTr("Service")
+ width: parent.width
+ onClicked: {
+ stackView.openPage("ServiceForm.qml")
+ }
+ }
+
ItemDelegate {
text: qsTr("Settings")
width: parent.width
onClicked: {
- if (stackView.depth > 1) {
- stackView.pop()
- }
-
- stackView.push("SettingsForm.qml")
- drawer.close()
+ stackView.openPage("SettingsForm.qml")
}
}
}
@@ -91,6 +102,19 @@ ApplicationWindow {
id: stackView
initialItem: "HomeForm.qml"
anchors.fill: parent
+
+ function openPage(page) {
+ if (depth > 1) {
+ pop()
+ }
+
+ push(page)
+ drawer.close()
+ }
+
+ function showError(text) {
+ ToolTip.show(text, 1000)
+ }
}
onClosing: {
diff --git a/qml.qrc b/qml.qrc
index 9f8acd6..4f7dd5b 100644
--- a/qml.qrc
+++ b/qml.qrc
@@ -12,5 +12,6 @@
lamp.png
Off.png
NooLiteClient.qml
+ ServiceForm.qml