File indexing completed on 2024-04-14 14:10:54

0001 /*
0002     SPDX-FileCopyrightText: 2001 Jasem Mutlaq <mutlaqja@ikarustech.com>
0003 
0004     SPDX-License-Identifier: GPL-2.0-or-later
0005 */
0006 
0007 #pragma once
0008 
0009 #include "ui_devmanager.h"
0010 
0011 #include <QFrame>
0012 #include <QHash>
0013 #include <QIcon>
0014 #include <QList>
0015 
0016 #include <lilxml.h>
0017 
0018 #ifndef _WIN32
0019 #include <unistd.h>
0020 #endif
0021 
0022 class QTreeWidgetItem;
0023 
0024 class DeviceManager;
0025 class INDI_D;
0026 class KStars;
0027 
0028 struct INDIHostsInfo
0029 {
0030     QString name;
0031     QString hostname;
0032     QString portnumber;
0033     bool isConnected { false };
0034     DeviceManager *deviceManager { nullptr };
0035 };
0036 
0037 class IDevice : public QObject
0038 {
0039         Q_OBJECT
0040 
0041     public:
0042         enum DeviceStatus
0043         {
0044             DEV_START,
0045             DEV_TERMINATE
0046         };
0047         enum XMLSource
0048         {
0049             PRIMARY_XML,
0050             THIRD_PARTY_XML,
0051             EM_XML
0052         };
0053 
0054         IDevice(const QString &inName, const QString &inLabel, const QString &inDriver, const QString &inVersion);
0055         ~IDevice();
0056 
0057         void clear();
0058         QString getServerBuffer();
0059 
0060         QString tree_label;
0061         QString unique_label;
0062         QString name;
0063         QString driver;
0064         QString version;
0065         QString id;
0066         QString port;
0067         DeviceStatus state;
0068         XMLSource xmlSource;
0069 
0070         DeviceManager *deviceManager;
0071         int type { 0 };
0072 
0073         /* Telescope specific attributes */
0074         double focal_length { 0 };
0075         double aperture { 0 };
0076 };
0077 
0078 class DeviceManagerUI : public QFrame, public Ui::devManager
0079 {
0080         Q_OBJECT
0081 
0082     public:
0083         explicit DeviceManagerUI(QWidget *parent = nullptr);
0084 
0085         QIcon runningPix;
0086         QIcon stopPix;
0087         QIcon connected;
0088         QIcon disconnected;
0089         QIcon localMode;
0090         QIcon serverMode;
0091 
0092     public slots:
0093         void makePortEditable(QTreeWidgetItem *selectedItem, int column);
0094 };
0095 
0096 class INDIDriver : public QDialog
0097 {
0098         Q_OBJECT
0099 
0100     public:
0101         enum
0102         {
0103             LOCAL_NAME_COLUMN = 0,
0104             LOCAL_STATUS_COLUMN,
0105             LOCAL_MODE_COLUMN,
0106             LOCAL_VERSION_COLUMN,
0107             LOCAL_PORT_COLUMN
0108         };
0109         enum
0110         {
0111             HOST_STATUS_COLUMN = 0,
0112             HOST_NAME_COLUMN,
0113             HOST_PORT_COLUMN
0114         };
0115 
0116         explicit INDIDriver(KStars *ks);
0117         ~INDIDriver();
0118 
0119         bool readXMLDrivers();
0120         void processXMLDriver(QString &driverName);
0121         bool buildDeviceGroup(XMLEle *root, char errmsg[]);
0122         bool buildDriverElement(XMLEle *root, QTreeWidgetItem *DGroup, int groupType, char errmsg[]);
0123 
0124         int getINDIPort(int customPort);
0125         bool isDeviceRunning(const QString &deviceLabel);
0126 
0127         void saveHosts();
0128 
0129         void processLocalTree(IDevice::DeviceStatus dev_request);
0130         void processRemoteTree(IDevice::DeviceStatus dev_request);
0131         IDevice *findDeviceByLabel(const QString &label);
0132 
0133     public slots:
0134         void enableDevice(INDI_D *device);
0135         void disableDevice(INDI_D *device);
0136 
0137         void resizeDeviceColumn();
0138         void updateLocalTab();
0139         void updateClientTab();
0140 
0141         void updateMenuActions();
0142 
0143         void addINDIHost();
0144         void modifyINDIHost();
0145         void removeINDIHost();
0146         void activateRunService();
0147         void activateStopService();
0148         void activateHostConnection();
0149         void activateHostDisconnection();
0150         void newTelescopeDiscovered();
0151         void newCCDDiscovered();
0152         void updateCustomDrivers();
0153 
0154     public:
0155         KStars *ksw { nullptr };
0156         DeviceManagerUI *ui { nullptr };
0157         QList<IDevice *> devices;
0158         QTreeWidgetItem *lastGroup { nullptr };
0159         QTreeWidgetItem *lastDevice { nullptr };
0160         QHash<QString, QString> driversList;
0161         int currentPort { 0 };
0162         IDevice::XMLSource xmlSource;
0163 
0164     signals:
0165         void newDevice();
0166         void newTelescope();
0167         void newCCD();
0168 };