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:
59 Q_ENUM(Type)
60
61
66 ConnectionInfo() = default;
67
78 explicit ConnectionInfo(const QBluetoothDeviceInfo& info, bool canonical=false);
79
80#if __has_include (<QSerialPortInfo>)
90 explicit ConnectionInfo(const QSerialPortInfo& info, bool canonical=false);
91#endif
92
102 explicit ConnectionInfo(quint16 port, bool canonical=false);
103
115 explicit ConnectionInfo(const QString& host, quint16 port, bool canonical=false);
116
117
118
119 //
120 // Properties
121 //
122
131 Q_PROPERTY(bool canConnect READ canConnect CONSTANT)
132
133
140 Q_PROPERTY(bool canonical READ canonical CONSTANT)
141
148 Q_PROPERTY(QString description READ description CONSTANT)
149
155 Q_PROPERTY(QString hostn READ host CONSTANT)
156
163 Q_PROPERTY(QString icon READ icon CONSTANT)
164
170 Q_PROPERTY(QString name READ name CONSTANT)
171
177 Q_PROPERTY(Traffic::ConnectionInfo::Type type READ type CONSTANT)
178
179
180
181 //
182 // Getter Methods
183 //
184
190 [[nodiscard]] bool canConnect() const { return m_canConnect; }
191
197 [[nodiscard]] bool canonical() const { return m_canonical; }
198
204 [[nodiscard]] QString description() const { return m_description; }
205
211 [[nodiscard]] QString host() const { return m_host; }
212
218 [[nodiscard]] QString icon() const { return m_icon; }
219
225 [[nodiscard]] QString name() const { return m_name; }
226
232 [[nodiscard]] Traffic::ConnectionInfo::Type type() const { return m_type; }
233
234
235
236 //
237 // Methods
238 //
239
248 [[nodiscard]] QBluetoothDeviceInfo bluetoothDeviceInfo() const { return m_bluetoothDeviceInfo; }
249
257 [[nodiscard]] bool operator== (const Traffic::ConnectionInfo& other) const = default;
258
265 [[nodiscard]] quint16 port() const { return m_port; }
266
280 [[nodiscard]] bool sameConnectionAs(const Traffic::ConnectionInfo& other) const;
281
292 bool operator< (const Traffic::ConnectionInfo& other) const;
293
294private:
295 //
296 // Properties
297 //
298 bool m_canConnect { false };
299 bool m_canonical { false };
300 QString m_description;
301 QString m_icon{u"/icons/material/ic_delete.svg"_s};
302 QString m_name { QObject::tr("Invalid Device", "Traffic::ConnectionInfo") };
304
305 //
306 // Private members, depending on m_type
307 //
308 QBluetoothDeviceInfo m_bluetoothDeviceInfo;
309 quint16 m_port{0};
310 QString m_host;
311};
312
318QDataStream& operator<<(QDataStream& stream, const Traffic::ConnectionInfo &connectionInfo);
319
325QDataStream& operator>>(QDataStream& stream, Traffic::ConnectionInfo& connectionInfo);
326
327} // 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.
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.