Kstars

portselector.h
1 /*
2  SPDX-FileCopyrightText: 2021 Jasem Mutlaq <[email protected]>
3 
4  SPDX-License-Identifier: GPL-2.0-or-later
5 */
6 
7 #pragma once
8 
9 #include <QDialog>
10 #include <QStandardItemModel>
11 #include <QJsonObject>
12 #include <QLabel>
13 #include <QComboBox>
14 #include <QLineEdit>
15 #include <QHBoxLayout>
16 
17 #include <KLed>
18 
19 #include <memory>
20 
21 #include "indi/indistd.h"
22 #include "profileinfo.h"
23 
24 namespace Selector
25 {
26 
27 typedef enum
28 {
29  CONNECTION_SERIAL,
30  CONNECTION_NETWORK,
31  CONNECTION_NONE
32 
33 } ConnectionMode;
34 
35 
36 class Device : public QObject
37 {
38  Q_OBJECT
39 
40  public:
41  explicit Device(ISD::GenericDevice *device, QGridLayout *grid, uint8_t row);
42 
43  const QString name() const
44  {
45  return m_Name;
46  }
47 
48  uint8_t systemPortCount() const;
49 
50  ConnectionMode activeConnectionMode()
51  {
52  return m_ActiveConnectionMode;
53  }
54 
55  // Create GUI
56  bool initGUI();
57  // Sync GUI to data
58  void syncGUI();
59 
60  private:
61  void processText(ITextVectorProperty *tvp);
62  void processSwitch(ISwitchVectorProperty *svp);
63  void setConnected();
64  void setDisconnected();
65  void setConnectionMode(ConnectionMode mode);
66 
67  // N.B. JM: Using smart pointers doesn't work very well in Qt widget parent/child
68  // scheme and can lead to double deletion, so we're sticking to regular pointers.
69  // General
70  KLed *m_LED {nullptr};
71  QLabel *m_Label {nullptr};
72  QPushButton *m_ConnectB {nullptr};
73  QPushButton *m_DisconnectB {nullptr};
74  // Serial
75  QPushButton *m_SerialB {nullptr};
76  QComboBox *m_Ports {nullptr};
77  QComboBox *m_BaudRates {nullptr};
78  // Network
79  QPushButton *m_NetworkB {nullptr};
80  QLineEdit *m_HostName {nullptr};
81  QLineEdit *m_HostPort {nullptr};
82  QPushButton *m_HostProtocolTCP {nullptr};
83  QPushButton *m_HostProtocolUDP {nullptr};
84 
85  QMap<IPState, QColor> ColorCode;
86  ConnectionMode m_ConnectionMode { CONNECTION_NONE };
87 
88 
89  QString m_Name;
90  ISD::GenericDevice *m_Device {nullptr};
91  QGridLayout *m_Grid{nullptr};
92  uint8_t m_Row {0};
93  ConnectionMode m_ActiveConnectionMode {CONNECTION_NONE};
94 
95  static const QStringList BAUD_RATES;
96  static const QString ACTIVE_STYLESHEET;
97 };
98 
99 class Dialog : public QDialog
100 {
101  public:
102  explicit Dialog(QWidget *parent = nullptr);
103 
104  // Initialize device
105  void addDevice(ISD::GenericDevice * devices);
106  void removeDevice(const QString &name);
107 
108  bool shouldShow() const;
109 
110  bool empty() const
111  {
112  return m_Devices.empty();
113  }
114 
115  private:
116 
117  std::vector <std::unique_ptr< Device>> m_Devices;
118  QGridLayout *m_Layout {nullptr};
119 };
120 
121 }
Q_OBJECTQ_OBJECT
QString name(StandardShortcut id)
This file is part of the KDE documentation.
Documentation copyright © 1996-2022 The KDE developers.
Generated on Mon Aug 15 2022 04:04:03 by doxygen 1.8.17 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.