Kstars

INDIControlPanel.qml
1// SPDX-FileCopyrightText: 2016 Artem Fedoskin <afedoskin3@gmail.com>
2// SPDX-License-Identifier: GPL-2.0-or-later
3
4import QtQuick 2.6
5import QtQuick.Window 2.2
6import QtQuick.Controls 2.0
7import QtQuick.Layouts 1.2
8import Qt.labs.settings 1.0
9import "../modules"
10import "../constants" 1.0
11
12KSPage {
13 id: indiPage
14 objectName: "indiControlPanel"
15 title: xi18n("INDI Control Panel")
16
17 property bool connected: ClientManagerLite.connected
18 property alias webMStatusText: webMStatusLabel.text
19 property alias webMStatusTextVisible: webMStatusLabel.visible
20 property alias webMActiveProfileText: webMActiveProfileLabel.text
21 property alias webMActiveProfileLayoutVisible: webMActiveProfileLayout.visible
22 property alias webMBrowserButtonVisible: webMBrowserButton.visible
23 property alias webMProfileListVisible: webMProfileList.visible
24
25 function connectIndiServer() {
26 indiServerConnectButton.clicked()
27 }
28
29 Component.onCompleted: {
30 // Debug purposes
31 ClientManagerLite.setHost("localhost", 7624)
32 }
33
34 onConnectedChanged: {
35 if (!indiPage.connected) {
36 for (var i = 0; i < devicesModel.count; ++i) {
37 devicesModel.get(i).panel.destroy()
38 stackView.pop(indiPage)
39 }
40 devicesModel.clear()
41 skyMapLite.notification.showNotification("Disconnected from the server")
42 }
43 }
44
45 ColumnLayout {
46 anchors.fill: parent
47 id: cPanelColumn
48 spacing: 5 * Num.dp
49
50 ColumnLayout {
51 visible: !indiPage.connected
52 anchors {
53 left: parent.left
54 right: parent.right
55 }
56
57 KSLabel {
58 text: xi18n("IP Address or Hostname")
59 }
60
61 RowLayout {
62 anchors {
63 left: parent.left
64 right: parent.right
65 }
66
67 KSTextField {
68 id: ipHost
69 placeholderText: xi18n("xxx.xxx.xxx.xxx")
70 Layout.alignment: Qt.AlignHCenter
71 Layout.maximumWidth: parent.width*0.8
72 Layout.fillWidth: true
73 font.capitalization: Font.AllLowercase
74 //text: ClientManagerLite.lastUsedServer
75 text: "localhost"
76
77 Settings
78 {
79 property alias ipHostText : ipHost.text
80 }
81 }
82 }
83
84 KSLabel {
85 text: xi18n("Web Manager Port")
86 }
87
88 RowLayout {
89 anchors {
90 left: parent.left
91 right: parent.right
92 }
93
94 KSTextField {
95 id: portWebManager
96 placeholderText: xi18n("xxxx")
97 Layout.alignment: Qt.AlignHCenter
98 Layout.maximumWidth: parent.width*0.2
99 Layout.fillWidth: true
100 //text: ClientManagerLite.lastUsedWebManagerPort
101 text: "8624"
102
103 Settings
104 {
105 property alias portWebManagerText : portWebManager.text
106 }
107 }
108
109 Button {
110 id: webMConnectButton
111 text: xi18n("Get Status")
112
113 onClicked: {
114 ClientManagerLite.getWebManagerProfiles(ipHost.text, parseInt(portWebManager.text));
115 Qt.inputMethod.hide()
116 }
117 }
118 }
119
120 KSLabel {
121 id: webMStatusLabel
122 text: xi18n("Web Manager Status:")
123 visible: false
124 }
125
126 RowLayout {
127 id: webMActiveProfileLayout
128 visible: false
129
130 KSLabel {
131 id: webMActiveProfileLabel
132 text: xi18n("Active Profile:")
133 }
134
135 Button {
136 id: webMStopButton
137 text: xi18n("Stop")
138
139 onClicked: {
141 }
142 }
143 }
144
145 ListView {
146 id: webMProfileList
147 model: webMProfileModel
148 highlightFollowsCurrentItem: false
149 width: parent.width
150 height: childrenRect.height
151 visible: false
152
153 delegate: RowLayout {
154 height: webMConnectButton.height
155
156 Rectangle {
157 width: webMStatusLabel.width
158 height: webMConnectButton.height
159 KSLabel {
160 text: xi18n("Profile: %1", modelData)
161 }
162 }
163
164 Button {
165 height: webMConnectButton.height
166 text: xi18n("Start")
167
168 onClicked: {
170 }
171 }
172 }
173 } // ListView
174
175 Button {
176 id: webMBrowserButton
177 text: xi18n("Manage Profiles")
178 visible: false
179
180 onClicked: {
181 Qt.openUrlExternally("http://"+ipHost.text+":"+portWebManager.text)
182 }
183 }
184
185 KSLabel {
186 text: xi18n("Server Port")
187 }
188
189 RowLayout {
190 anchors {
191 left: parent.left
192 right: parent.right
193 }
194
195 KSTextField {
196 id: portHost
197 placeholderText: xi18n("INDI Server Port")
198 Layout.alignment: Qt.AlignHCenter
199 Layout.maximumWidth: parent.width*0.2
200 Layout.fillWidth: true
201 //text: ClientManagerLite.lastUsedPort
202 text: "7624"
203
204 Settings
205 {
206 property alias portHostText : portHost.text
207 }
208 }
209
210 Button {
211 id: indiServerConnectButton
212 text: indiPage.connected ? xi18n("Disconnect") : xi18n("Connect")
213
214 onClicked: {
215 if (!indiPage.connected) {
216 if(ClientManagerLite.setHost(ipHost.text, parseInt(portHost.text))) {
217 skyMapLite.notification.showNotification(xi18n("Successfully connected to the server"))
218 } else {
219 skyMapLite.notification.showNotification(xi18n("Could not connect to the server"))
220 }
221 } else {
222
223 ClientManagerLite.disconnectHost()
224 }
225 Qt.inputMethod.hide()
226 }
227 }
228
229 }
230 }
231
232 KSLabel {
233 id: connectedTo
234 visible: indiPage.connected
235 text: xi18n("Connected to %1", ClientManagerLite.connectedHost)
236 }
237
238
239 ColumnLayout {
240 Layout.fillHeight: true
241 Layout.fillWidth: true
242 visible: indiPage.connected
243
244 Rectangle {
245 Layout.fillWidth: true
246 height: 1 * Num.dp
247 color: "gray"
248 }
249
250 KSLabel {
251 id: devicesLabel
252 text: xi18n("Available Devices")
253 }
254
255 ListModel {
256 id: devicesModel
257 }
258
259 Connections {
260 target: ClientManagerLite
261 onNewINDIDevice: {
262 var component = Qt.createComponent(Qt.resolvedUrl("./DevicePanel.qml"));
263 var devicePanel = component.createObject(window);
264 devicePanel.deviceName = deviceName
265 devicesModel.append({ name: deviceName, panel: devicePanel })
266 }
267 onRemoveINDIDevice: {
268 for (i = 0; i < devicesModel.count; ++i) {
269 if(devicesModel.get(i).name == deviceName) {
270 devicesModel.panel.destroy()
271 devicesModel.remove(i)
272 }
273 }
274 }
275 onNewINDIMessage: {
276 skyMapLite.notification.showNotification(message)
277 }
278 }
279 }
280
281 KSListView {
282 id: devicesPage
283 Layout.fillHeight: true
284 Layout.fillWidth: true
285
286 model: devicesModel
287 textRole: "name"
288
289 onClicked: {
290 stackView.push(devicesModel.get(currentIndex).panel)
291 }
292 }
293
294 KSButton
295 {
296 id: disconnectINDI
297 visible: indiPage.connected
298 text: xi18n("Disconnect INDI");
299
300 onClicked:
301 {
302 ClientManagerLite.disconnectHost();
303 }
304 }
305 }
306}
Q_INVOKABLE void getWebManagerProfiles(const QString &ip, unsigned int port)
Get the profiles from Web Manager.
Q_INVOKABLE void startWebManagerProfile(const QString &profile)
Start an INDI server with a Web Manager profile.
Q_INVOKABLE void stopWebManagerProfile()
Stop the INDI server with an active Web Manager profile.
QString xi18n(const char *text, const TYPE &arg...)
QString name(GameStandardAction id)
QTextStream & left(QTextStream &stream)
QTextStream & right(QTextStream &stream)
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Mon Nov 4 2024 16:38:43 by doxygen 1.12.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.