Kstars

clientmanagerlite.h
1 /*
2  SPDX-FileCopyrightText: 2016 Artem Fedoskin <[email protected]>
3  SPDX-License-Identifier: GPL-2.0-or-later
4 */
5 
6 #pragma once
7 
8 #include "baseclientqt.h"
9 #include "indicommon.h"
10 #include "indistd.h"
11 
12 #include <QImage>
13 #include <QNetworkAccessManager>
14 #include <QNetworkReply>
15 
16 #include <memory>
17 
18 class QFileDialog;
19 class QQmlContext;
20 
21 using namespace INDI;
22 class TelescopeLite;
23 
24 struct DeviceInfoLite
25 {
26  explicit DeviceInfoLite(INDI::BaseDevice *dev);
27  ~DeviceInfoLite();
28 
29  INDI::BaseDevice *device { nullptr };
30  /// Motion control
31  std::unique_ptr<TelescopeLite> telescope;
32 };
33 
34 /**
35  * @class ClientManagerLite
36  *
37  * @author Artem Fedoskin
38  * @version 1.0
39  */
40 class ClientManagerLite : public INDI::BaseClientQt
41 {
42  Q_OBJECT
43  Q_PROPERTY(QString connectedHost READ connectedHost WRITE setConnectedHost NOTIFY connectedHostChanged)
44  Q_PROPERTY(bool connected READ isConnected WRITE setConnected NOTIFY connectedChanged)
45 
46  /**
47  * A wrapper for Options::lastServer(). Used to store last used server if user successfully
48  * connected to some server at least once.
49  **/
50  Q_PROPERTY(QString lastUsedServer READ getLastUsedServer WRITE setLastUsedServer NOTIFY lastUsedServerChanged)
51 
52  /**
53  * A wrapper for Options::lastServer(). Used to store last used port if user successfully
54  * connected to some server at least once.
55  **/
56  Q_PROPERTY(int lastUsedPort READ getLastUsedPort WRITE setLastUsedPort NOTIFY lastUsedPortChanged)
57 
58  /**
59  * A wrapper for Options::lastServer(). Used to store last Web Manager used port if user successfully
60  * connected at least once.
61  **/
62  Q_PROPERTY(int lastUsedWebManagerPort READ getLastUsedWebManagerPort WRITE setLastUsedWebManagerPort
63  NOTIFY lastUsedWebManagerPortChanged)
64  public:
65  typedef enum { UPLOAD_CLIENT, UPLOAD_LOCAL, UPLOAD_BOTH } UploadMode;
66 
67  explicit ClientManagerLite(QQmlContext &main_context);
68  virtual ~ClientManagerLite();
69 
70  Q_INVOKABLE bool setHost(const QString &ip, unsigned int port);
71  Q_INVOKABLE void disconnectHost();
72 
73  /**
74  * Get the profiles from Web Manager
75  *
76  * @param ip IP address
77  * @param port Port number
78  *
79  * The process is async and the results are stored in @a webMProfiles. Once this
80  * request finishes, the server status is queried from the server.
81  */
82  Q_INVOKABLE void getWebManagerProfiles(const QString &ip, unsigned int port);
83 
84  /**
85  * Start an INDI server with a Web Manager profile
86  *
87  * @param profile Profile name
88  */
89  Q_INVOKABLE void startWebManagerProfile(const QString &profile);
90 
91  /** Stop the INDI server with an active Web Manager profile */
92  Q_INVOKABLE void stopWebManagerProfile();
93 
94  /** Handle the errors of the async Web Manager requests */
95  Q_INVOKABLE void webManagerReplyError(QNetworkReply::NetworkError code);
96 
97  /** Do actions when async Web Manager requests are finished */
98  Q_INVOKABLE void webManagerReplyFinished();
99 
100  Q_INVOKABLE TelescopeLite *getTelescope();
101 
102  QString connectedHost()
103  {
104  return m_connectedHost;
105  }
106  void setConnectedHost(const QString &connectedHost);
107  void setConnected(bool connected);
108 
109  /**
110  * Set the INDI Control Page
111  *
112  * @param page Reference to the QML page
113  */
115  {
116  indiControlPage = &page;
117  };
118 
119  /**
120  * @brief syncLED
121  * @param device device name
122  * @param property property name
123  * @param name of Light which LED needs to be synced
124  * @return color of state
125  */
126  Q_INVOKABLE QString syncLED(const QString &device, const QString &property, const QString &name = "");
127 
128  void buildTextGUI(INDI::Property property);
129  void buildNumberGUI(INDI::Property property);
130  void buildMenuGUI(INDI::Property property);
131  void buildSwitchGUI(INDI::Property property, PGui guiType);
132  void buildSwitch(bool buttonGroup, ISwitch *sw, INDI::Property property, bool exclusive = false,
133  PGui guiType = PG_BUTTONS);
134  void buildLightGUI(INDI::Property property);
135  //void buildBLOBGUI(INDI::Property property);
136 
137  Q_INVOKABLE void sendNewINDISwitch(const QString &deviceName, const QString &propName, const QString &name);
138  Q_INVOKABLE void sendNewINDISwitch(const QString &deviceName, const QString &propName, int index);
139 
140  Q_INVOKABLE void sendNewINDINumber(const QString &deviceName, const QString &propName, const QString &numberName,
141  double value);
142  Q_INVOKABLE void sendNewINDIText(const QString &deviceName, const QString &propName, const QString &fieldName,
143  const QString &text);
144 
145  bool isConnected()
146  {
147  return m_connected;
148  }
149  Q_INVOKABLE bool isDeviceConnected(const QString &deviceName);
150 
151  QList<DeviceInfoLite *> getDevices()
152  {
153  return m_devices;
154  }
155 
156  Q_INVOKABLE QString getLastUsedServer();
157  Q_INVOKABLE void setLastUsedServer(const QString &server);
158 
159  Q_INVOKABLE int getLastUsedPort();
160  Q_INVOKABLE void setLastUsedPort(int port);
161 
162  Q_INVOKABLE int getLastUsedWebManagerPort();
163  Q_INVOKABLE void setLastUsedWebManagerPort(int port);
164 
165  /**
166  * @brief saveDisplayImage
167  * @return true if image was saved false otherwise
168  */
169  Q_INVOKABLE bool saveDisplayImage();
170 
171  void clearDevices();
172 
173  private slots:
174 
175  void connectNewDevice(const QString &device_name);
176 
177  protected:
178  virtual void newDevice(INDI::BaseDevice *dp) override;
179  virtual void removeDevice(INDI::BaseDevice *dp) override;
180  virtual void newProperty(INDI::Property property) override;
181  virtual void removeProperty(INDI::Property property) override;
182  virtual void newBLOB(IBLOB *bp) override;
183  virtual void newSwitch(ISwitchVectorProperty *svp) override;
184  virtual void newNumber(INumberVectorProperty *nvp) override;
185  virtual void newMessage(INDI::BaseDevice *dp, int messageID) override;
186  virtual void newText(ITextVectorProperty *tvp) override;
187  virtual void newLight(ILightVectorProperty *lvp) override;
188  virtual void serverConnected() override {}
189  virtual void serverDisconnected(int exit_code) override;
190  signals:
191  //Device
192  void newINDIDevice(QString deviceName);
193  void removeINDIDevice(QString deviceName);
194  void deviceConnected(QString deviceName, bool isConnected);
195 
196  void newINDIProperty(QString deviceName, QString propName, QString groupName, QString type, QString label);
197 
198  void createINDIText(QString deviceName, QString propName, QString propLabel, QString fieldName, QString propText,
199  bool read, bool write);
200 
201  void createINDINumber(QString deviceName, QString propName, QString propLabel, QString numberName, QString propText,
202  bool read, bool write, bool scale);
203 
204  void createINDIButton(QString deviceName, QString propName, QString propText, QString switchName, bool read,
205  bool write, bool exclusive, bool checked, bool checkable);
206  void createINDIRadio(QString deviceName, QString propName, QString propText, QString switchName, bool read,
207  bool write, bool exclusive, bool checked, bool enabled);
208 
209  void createINDIMenu(QString deviceName, QString propName, QString switchLabel, QString switchName, bool isSelected);
210 
211  void createINDILight(QString deviceName, QString propName, QString label, QString lightName);
212 
213  void removeINDIProperty(QString deviceName, QString groupName, QString propName);
214 
215  //Update signals
216  void newINDISwitch(QString deviceName, QString propName, QString switchName, bool isOn);
217  void newINDINumber(QString deviceName, QString propName, QString numberName, QString value);
218  void newINDIText(QString deviceName, QString propName, QString fieldName, QString text);
219  void newINDIMessage(QString message);
220  void newINDILight(QString deviceName, QString propName);
221  void newINDIBLOBImage(QString deviceName, bool isLoaded);
222  void newLEDState(QString deviceName, QString propName); // to sync LED for properties
223 
224  void connectedHostChanged(QString);
225  void connectedChanged(bool);
226  void telescopeAdded(TelescopeLite *newTelescope);
227  void telescopeRemoved(TelescopeLite *delTelescope);
228  void telescopeConnected(TelescopeLite *telescope);
229  void telescopeDisconnected();
230 
231  void lastUsedServerChanged();
232  void lastUsedPortChanged();
233  void lastUsedWebManagerPortChanged();
234 
235  private:
236  bool processBLOBasCCD(IBLOB *bp);
237 
238  /// Qml context
239  QQmlContext &context;
240  QList<DeviceInfoLite *> m_devices;
241  QString m_connectedHost;
242  bool m_connected { false };
243  char BLOBFilename[MAXINDIFILENAME];
244  QImage displayImage;
245  /// INDI Control Page
246  QObject* indiControlPage;
247  /// Manager for the JSON requests to the Web Manager
248  QNetworkAccessManager manager;
249  /// Network reply for querying profiles from the Web Manager
250  std::unique_ptr<QNetworkReply> webMProfilesReply;
251  /// Network reply for Web Manager status
252  std::unique_ptr<QNetworkReply> webMStatusReply;
253  /// Network reply to stop the active profile in the Web Manager
254  std::unique_ptr<QNetworkReply> webMStopProfileReply;
255  /// Network reply to start a profile in the Web Manager
256  std::unique_ptr<QNetworkReply> webMStartProfileReply;
257  /// Web Manager profiles
258  QStringList webMProfiles;
259  TelescopeLite *m_telescope { nullptr };
260 #ifdef ANDROID
261  QString defaultImageType;
262  QString defaultImagesLocation;
263 #endif
264 };
void setHost(ScriptableExtension *host)
void setIndiControlPage(QObject &page)
Set the INDI Control Page.
virtual bool removeProperty(ScriptableExtension *callerPrincipal, quint64 objId, const QString &propName)
QString message
This file is part of the KDE documentation.
Documentation copyright © 1996-2023 The KDE developers.
Generated on Mon May 8 2023 03:57:30 by doxygen 1.8.17 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.