Warning, /education/kstars/kstars/kstarslite/qml/indi/INDIControlPanel.qml is written in an unsupported language. File is not indexed.

0001 // SPDX-FileCopyrightText: 2016 Artem Fedoskin <afedoskin3@gmail.com>
0002 // SPDX-License-Identifier: GPL-2.0-or-later
0003 
0004 import QtQuick 2.6
0005 import QtQuick.Window 2.2
0006 import QtQuick.Controls 2.0
0007 import QtQuick.Layouts 1.2
0008 import Qt.labs.settings 1.0
0009 import "../modules"
0010 import "../constants" 1.0
0011 
0012 KSPage {
0013     id: indiPage
0014     objectName: "indiControlPanel"
0015     title: xi18n("INDI Control Panel")
0016 
0017     property bool connected: ClientManagerLite.connected
0018     property alias webMStatusText: webMStatusLabel.text
0019     property alias webMStatusTextVisible: webMStatusLabel.visible
0020     property alias webMActiveProfileText: webMActiveProfileLabel.text
0021     property alias webMActiveProfileLayoutVisible: webMActiveProfileLayout.visible
0022     property alias webMBrowserButtonVisible: webMBrowserButton.visible
0023     property alias webMProfileListVisible: webMProfileList.visible
0024 
0025     function connectIndiServer() {
0026         indiServerConnectButton.clicked()
0027     }
0028 
0029     Component.onCompleted: {
0030         // Debug purposes
0031         ClientManagerLite.setHost("localhost", 7624)
0032     }
0033 
0034     onConnectedChanged: {
0035         if (!indiPage.connected) {
0036             for (var i = 0; i < devicesModel.count; ++i) {
0037                 devicesModel.get(i).panel.destroy()
0038                 stackView.pop(indiPage)
0039             }
0040             devicesModel.clear()
0041             skyMapLite.notification.showNotification("Disconnected from the server")
0042         }
0043     }
0044 
0045     ColumnLayout {
0046         anchors.fill: parent
0047         id: cPanelColumn
0048         spacing: 5 * Num.dp
0049 
0050         ColumnLayout {
0051             visible: !indiPage.connected
0052             anchors {
0053                 left: parent.left
0054                 right: parent.right
0055             }
0056 
0057             KSLabel {
0058                 text: xi18n("IP Address or Hostname")
0059             }
0060 
0061             RowLayout {
0062                 anchors {
0063                     left: parent.left
0064                     right: parent.right
0065                 }
0066 
0067                 KSTextField {
0068                     id: ipHost
0069                     placeholderText: xi18n("xxx.xxx.xxx.xxx")
0070                     Layout.alignment: Qt.AlignHCenter
0071                     Layout.maximumWidth: parent.width*0.8
0072                     Layout.fillWidth: true
0073                     font.capitalization: Font.AllLowercase
0074                     //text: ClientManagerLite.lastUsedServer
0075                     text: "localhost"
0076 
0077                     Settings
0078                     {
0079                         property alias ipHostText : ipHost.text
0080                     }
0081                 }
0082             }
0083 
0084             KSLabel {
0085                 text: xi18n("Web Manager Port")
0086             }
0087 
0088             RowLayout {
0089                 anchors {
0090                     left: parent.left
0091                     right: parent.right
0092                 }
0093 
0094                 KSTextField {
0095                     id: portWebManager
0096                     placeholderText: xi18n("xxxx")
0097                     Layout.alignment: Qt.AlignHCenter
0098                     Layout.maximumWidth: parent.width*0.2
0099                     Layout.fillWidth: true
0100                     //text: ClientManagerLite.lastUsedWebManagerPort
0101                     text: "8624"
0102 
0103                     Settings
0104                     {
0105                         property alias portWebManagerText : portWebManager.text
0106                     }
0107                 }
0108 
0109                 Button {
0110                     id: webMConnectButton
0111                     text: xi18n("Get Status")
0112 
0113                     onClicked: {
0114                         ClientManagerLite.getWebManagerProfiles(ipHost.text, parseInt(portWebManager.text));
0115                         Qt.inputMethod.hide()
0116                     }
0117                 }
0118             }
0119 
0120             KSLabel {
0121                 id: webMStatusLabel
0122                 text: xi18n("Web Manager Status:")
0123                 visible: false
0124             }
0125 
0126             RowLayout {
0127                 id: webMActiveProfileLayout
0128                 visible: false
0129 
0130                 KSLabel {
0131                     id: webMActiveProfileLabel
0132                     text: xi18n("Active Profile:")
0133                 }
0134 
0135                 Button {
0136                     id: webMStopButton
0137                     text: xi18n("Stop")
0138 
0139                     onClicked: {
0140                         ClientManagerLite.stopWebManagerProfile();
0141                     }
0142                 }
0143             }
0144 
0145             ListView {
0146                 id: webMProfileList
0147                 model: webMProfileModel
0148                 highlightFollowsCurrentItem: false
0149                 width: parent.width
0150                 height: childrenRect.height
0151                 visible: false
0152 
0153                 delegate: RowLayout {
0154                     height: webMConnectButton.height
0155 
0156                     Rectangle {
0157                         width: webMStatusLabel.width
0158                         height: webMConnectButton.height
0159                         KSLabel {
0160                             text: xi18n("Profile: %1", modelData)
0161                         }
0162                     }
0163 
0164                     Button {
0165                         height: webMConnectButton.height
0166                         text: xi18n("Start")
0167 
0168                         onClicked: {
0169                             ClientManagerLite.startWebManagerProfile(modelData);
0170                         }
0171                     }
0172                 }
0173             } // ListView
0174 
0175             Button {
0176                 id: webMBrowserButton
0177                 text: xi18n("Manage Profiles")
0178                 visible: false
0179 
0180                 onClicked: {
0181                     Qt.openUrlExternally("http://"+ipHost.text+":"+portWebManager.text)
0182                 }
0183             }
0184 
0185             KSLabel {
0186                 text: xi18n("Server Port")
0187             }
0188 
0189             RowLayout {
0190                 anchors {
0191                     left: parent.left
0192                     right: parent.right
0193                 }
0194 
0195                 KSTextField {
0196                     id: portHost
0197                     placeholderText: xi18n("INDI Server Port")
0198                     Layout.alignment: Qt.AlignHCenter
0199                     Layout.maximumWidth: parent.width*0.2
0200                     Layout.fillWidth: true
0201                     //text: ClientManagerLite.lastUsedPort
0202                     text: "7624"
0203 
0204                     Settings
0205                     {
0206                         property alias portHostText : portHost.text
0207                     }
0208                 }
0209 
0210                 Button {
0211                     id: indiServerConnectButton
0212                     text: indiPage.connected ? xi18n("Disconnect") : xi18n("Connect")
0213 
0214                     onClicked: {
0215                         if (!indiPage.connected) {
0216                             if(ClientManagerLite.setHost(ipHost.text, parseInt(portHost.text))) {
0217                                 skyMapLite.notification.showNotification(xi18n("Successfully connected to the server"))
0218                             } else {
0219                                 skyMapLite.notification.showNotification(xi18n("Could not connect to the server"))
0220                             }
0221                         } else {
0222 
0223                             ClientManagerLite.disconnectHost()
0224                         }
0225                         Qt.inputMethod.hide()
0226                     }
0227                 }
0228 
0229             }
0230         }
0231 
0232         KSLabel {
0233             id: connectedTo
0234             visible: indiPage.connected
0235             text: xi18n("Connected to %1", ClientManagerLite.connectedHost)
0236         }
0237 
0238 
0239         ColumnLayout {
0240             Layout.fillHeight: true
0241             Layout.fillWidth: true
0242             visible: indiPage.connected
0243 
0244             Rectangle {
0245                 Layout.fillWidth: true
0246                 height: 1 * Num.dp
0247                 color: "gray"
0248             }
0249 
0250             KSLabel {
0251                 id: devicesLabel
0252                 text: xi18n("Available Devices")
0253             }
0254 
0255             ListModel {
0256                 id: devicesModel
0257             }
0258 
0259             Connections {
0260                 target: ClientManagerLite
0261                 onNewINDIDevice: {
0262                     var component = Qt.createComponent(Qt.resolvedUrl("./DevicePanel.qml"));
0263                     var devicePanel = component.createObject(window);
0264                     devicePanel.deviceName = deviceName
0265                     devicesModel.append({ name: deviceName, panel: devicePanel })
0266                 }
0267                 onRemoveINDIDevice: {
0268                     for (i = 0; i < devicesModel.count; ++i) {
0269                         if(devicesModel.get(i).name == deviceName) {
0270                             devicesModel.panel.destroy()
0271                             devicesModel.remove(i)
0272                         }
0273                     }
0274                 }
0275                 onNewINDIMessage: {
0276                     skyMapLite.notification.showNotification(message)
0277                 }
0278             }
0279         }
0280 
0281         KSListView {
0282             id: devicesPage
0283             Layout.fillHeight: true
0284             Layout.fillWidth: true
0285 
0286             model: devicesModel
0287             textRole: "name"
0288 
0289             onClicked: {
0290                 stackView.push(devicesModel.get(currentIndex).panel)
0291             }
0292         }
0293 
0294         KSButton
0295         {
0296             id: disconnectINDI
0297             visible: indiPage.connected
0298             text: xi18n("Disconnect INDI");
0299 
0300             onClicked:
0301             {
0302                 ClientManagerLite.disconnectHost();
0303             }
0304         }
0305     }
0306 }