Kstars

portselector.h
1/*
2 SPDX-FileCopyrightText: 2021 Jasem Mutlaq <mutlaqja@ikarustech.com>
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
24namespace Selector
25{
26
27typedef enum
28{
29 CONNECTION_SERIAL,
30 CONNECTION_NETWORK,
31 CONNECTION_NONE
32
33} ConnectionMode;
34
35
36class Device : public QObject
37{
39
40 public:
41 explicit Device(const QSharedPointer<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 updateProperty(INDI::Property prop);
62 void setConnected();
63 void setDisconnected();
64 void setConnectionMode(ConnectionMode mode);
65
66 // N.B. JM: Using smart pointers doesn't work very well in Qt widget parent/child
67 // scheme and can lead to double deletion, so we're sticking to regular pointers.
68 // General
69 KLed *m_LED {nullptr};
70 QLabel *m_Label {nullptr};
71 QPushButton *m_ConnectB {nullptr};
72 QPushButton *m_DisconnectB {nullptr};
73 // Serial
74 QPushButton *m_SerialB {nullptr};
75 QComboBox *m_Ports {nullptr};
76 QComboBox *m_BaudRates {nullptr};
77 // Network
78 QPushButton *m_NetworkB {nullptr};
79 QLineEdit *m_HostName {nullptr};
80 QLineEdit *m_HostPort {nullptr};
81 QPushButton *m_HostProtocolTCP {nullptr};
82 QPushButton *m_HostProtocolUDP {nullptr};
83
84 QMap<IPState, QColor> ColorCode;
85 ConnectionMode m_ConnectionMode { CONNECTION_NONE };
86
87
88 QString m_Name;
90 QGridLayout *m_Grid{nullptr};
91 uint8_t m_Row {0};
92 ConnectionMode m_ActiveConnectionMode {CONNECTION_NONE};
93
94 static const QStringList BAUD_RATES;
95 static const QString ACTIVE_STYLESHEET;
96};
97
98class Dialog : public QDialog
99{
100 public:
101 explicit Dialog(QWidget *parent = nullptr);
102
103 // Initialize device
104 void addDevice(const QSharedPointer<ISD::GenericDevice> &device);
105 void removeDevice(const QString &name);
106
107 bool shouldShow() const;
108
109 bool empty() const
110 {
111 return m_Devices.empty();
112 }
113
114 private:
115
116 std::vector <std::unique_ptr< Device>> m_Devices;
117 QGridLayout *m_Layout {nullptr};
118};
119
120}
Q_OBJECTQ_OBJECT
QObject * parent() const const
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Mon Nov 4 2024 16:38:42 by doxygen 1.12.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.