Enroute Flight Navigation
A navigation app for VFR pilots
ConnectionInfo.h
1/***************************************************************************
2 * Copyright (C) 2024 by Stefan Kebekus *
3 * stefan.kebekus@gmail.com *
4 * *
5 * This program is free software; you can redistribute it and/or modify *
6 * it under the terms of the GNU General Public License as published by *
7 * the Free Software Foundation; either version 3 of the License, or *
8 * (at your option) any later version. *
9 * *
10 * This program is distributed in the hope that it will be useful, *
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
13 * GNU General Public License for more details. *
14 * *
15 * You should have received a copy of the GNU General Public License *
16 * along with this program; if not, write to the *
17 * Free Software Foundation, Inc., *
18 * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
19 ***************************************************************************/
20
21#pragma once
22
23#include <QBluetoothDeviceInfo>
24#include <QQmlEngine>
25
26#if __has_include (<QSerialPortInfo>)
27#include <QSerialPortInfo>
28#endif
29
30using namespace Qt::Literals::StringLiterals;
31
32
33namespace Traffic {
34
42 Q_GADGET
43 QML_VALUE_TYPE(connectionInfo)
44
45 friend QDataStream& operator<<(QDataStream& stream, const Traffic::ConnectionInfo &connectionInfo);
46 friend QDataStream& operator>>(QDataStream& stream, Traffic::ConnectionInfo& connectionInfo);
47
48public:
60 Q_ENUM(Type)
61
62
67 ConnectionInfo() = default;
68
79 explicit ConnectionInfo(const QBluetoothDeviceInfo& info, bool canonical=false);
80
81#if __has_include (<QSerialPortInfo>)
91 explicit ConnectionInfo(const QSerialPortInfo& info, bool canonical=false);
92#endif
93
103 explicit ConnectionInfo(quint16 port, bool canonical=false);
104
116 explicit ConnectionInfo(const QString& host, quint16 port, bool canonical=false);
117
121 struct OgnInfo{};
122
130 explicit ConnectionInfo(const OgnInfo& info);
131
132 //
133 // Properties
134 //
135
144 Q_PROPERTY(bool canConnect READ canConnect CONSTANT)
145
146
153 Q_PROPERTY(bool canonical READ canonical CONSTANT)
154
161 Q_PROPERTY(QString description READ description CONSTANT)
162
168 Q_PROPERTY(QString hostn READ host CONSTANT)
169
176 Q_PROPERTY(QString icon READ icon CONSTANT)
177
183 Q_PROPERTY(QString name READ name CONSTANT)
184
190 Q_PROPERTY(Traffic::ConnectionInfo::Type type READ type CONSTANT)
191
192
193
194 //
195 // Getter Methods
196 //
197
203 [[nodiscard]] bool canConnect() const { return m_canConnect; }
204
210 [[nodiscard]] bool canonical() const { return m_canonical; }
211
217 [[nodiscard]] QString description() const { return m_description; }
218
224 [[nodiscard]] QString host() const { return m_host; }
225
231 [[nodiscard]] QString icon() const { return m_icon; }
232
238 [[nodiscard]] QString name() const { return m_name; }
239
245 [[nodiscard]] Traffic::ConnectionInfo::Type type() const { return m_type; }
246
247
248
249 //
250 // Methods
251 //
252
261 [[nodiscard]] QBluetoothDeviceInfo bluetoothDeviceInfo() const { return m_bluetoothDeviceInfo; }
262
270 [[nodiscard]] bool operator== (const Traffic::ConnectionInfo& other) const = default;
271
278 [[nodiscard]] quint16 port() const { return m_port; }
279
293 [[nodiscard]] bool sameConnectionAs(const Traffic::ConnectionInfo& other) const;
294
305 bool operator< (const Traffic::ConnectionInfo& other) const;
306
307private:
308 //
309 // Properties
310 //
311 bool m_canConnect { false };
312 bool m_canonical { false };
313 QString m_description;
314 QString m_icon{u"/icons/material/ic_delete.svg"_s};
315 QString m_name { QObject::tr("Invalid Device", "Traffic::ConnectionInfo") };
317
318 //
319 // Private members, depending on m_type
320 //
321 QBluetoothDeviceInfo m_bluetoothDeviceInfo;
322 quint16 m_port{0};
323 QString m_host;
324};
325
331QDataStream& operator<<(QDataStream& stream, const Traffic::ConnectionInfo &connectionInfo);
332
338QDataStream& operator>>(QDataStream& stream, Traffic::ConnectionInfo& connectionInfo);
339
340} // namespace Traffic
Connection to a traffic data receiver.
bool operator==(const Traffic::ConnectionInfo &other) const =default
Equality of ConnectionInfos.
Traffic::ConnectionInfo::Type type() const
Getter function for the property with the same name.
Traffic::ConnectionInfo::Type type
Type.
quint16 port() const
Port.
bool canonical() const
Getter function for the property with the same name.
QString name() const
Getter function for the property with the same name.
bool canonical
Canonicity.
ConnectionInfo()=default
Default constructor.
QString description() const
Getter function for the property with the same name.
ConnectionInfo(const OgnInfo &info)
Constructor for OGN Connections.
bool sameConnectionAs(const Traffic::ConnectionInfo &other) const
Equality of connection.
QString icon() const
Getter function for the property with the same name.
QBluetoothDeviceInfo bluetoothDeviceInfo() const
Bluetooth Device Info.
QString host() const
Getter function for the property with the same name.
bool canConnect
Connectability.
ConnectionInfo(quint16 port, bool canonical=false)
Constructor for UDP Connections.
bool operator<(const Traffic::ConnectionInfo &other) const
Comparison.
ConnectionInfo(const QString &host, quint16 port, bool canonical=false)
Constructor for TCP Connections.
QString description
Description.
Constructor parameter for OGN connections.