1 | // Copyright (C) 2021 The Qt Company Ltd. |
2 | // SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only |
3 | |
4 | #ifndef QNETWORKINFORMATION_H |
5 | #define QNETWORKINFORMATION_H |
6 | |
7 | #include <QtNetwork/qtnetworkglobal.h> |
8 | #include <QtCore/qobject.h> |
9 | #include <QtCore/qstringview.h> |
10 | #include <QtCore/qstringlist.h> |
11 | |
12 | QT_BEGIN_NAMESPACE |
13 | |
14 | class QNetworkInformationBackend; |
15 | class QNetworkInformationPrivate; |
16 | struct QNetworkInformationDeleter; |
17 | class Q_NETWORK_EXPORT QNetworkInformation : public QObject |
18 | { |
19 | Q_OBJECT |
20 | Q_DECLARE_PRIVATE(QNetworkInformation) |
21 | Q_PROPERTY(Reachability reachability READ reachability NOTIFY reachabilityChanged) |
22 | Q_PROPERTY(bool isBehindCaptivePortal READ isBehindCaptivePortal |
23 | NOTIFY isBehindCaptivePortalChanged) |
24 | Q_PROPERTY(TransportMedium transportMedium READ transportMedium NOTIFY transportMediumChanged) |
25 | Q_PROPERTY(bool isMetered READ isMetered NOTIFY isMeteredChanged) |
26 | public: |
27 | enum class Reachability { |
28 | Unknown, |
29 | Disconnected, |
30 | Local, |
31 | Site, |
32 | Online, |
33 | }; |
34 | Q_ENUM(Reachability) |
35 | |
36 | enum class TransportMedium { |
37 | Unknown, |
38 | Ethernet, |
39 | Cellular, |
40 | WiFi, |
41 | Bluetooth, |
42 | }; |
43 | Q_ENUM(TransportMedium) |
44 | |
45 | enum class Feature { |
46 | Reachability = 0x1, |
47 | CaptivePortal = 0x2, |
48 | TransportMedium = 0x4, |
49 | Metered = 0x8, |
50 | }; |
51 | Q_DECLARE_FLAGS(Features, Feature) |
52 | Q_FLAG(Features) |
53 | |
54 | Reachability reachability() const; |
55 | |
56 | bool isBehindCaptivePortal() const; |
57 | |
58 | TransportMedium transportMedium() const; |
59 | |
60 | bool isMetered() const; |
61 | |
62 | QString backendName() const; |
63 | |
64 | bool supports(Features features) const; |
65 | Features supportedFeatures() const; |
66 | |
67 | static bool loadDefaultBackend(); |
68 | static bool loadBackendByName(QStringView backend); |
69 | static bool loadBackendByFeatures(Features features); |
70 | #if QT_DEPRECATED_SINCE(6,4) |
71 | QT_DEPRECATED_VERSION_X_6_4("Use loadBackendByName" ) static bool load(QStringView backend); |
72 | QT_DEPRECATED_VERSION_X_6_4("Use loadBackendByFeatures" ) static bool load(Features features); |
73 | #endif |
74 | static QStringList availableBackends(); |
75 | static QNetworkInformation *instance(); |
76 | |
77 | Q_SIGNALS: |
78 | void reachabilityChanged(Reachability newReachability); |
79 | void isBehindCaptivePortalChanged(bool state); |
80 | void transportMediumChanged(TransportMedium current); |
81 | void isMeteredChanged(bool isMetered); |
82 | |
83 | private: |
84 | friend struct QNetworkInformationDeleter; |
85 | friend class QNetworkInformationPrivate; |
86 | QNetworkInformation(QNetworkInformationBackend *backend); |
87 | ~QNetworkInformation() override; |
88 | |
89 | Q_DISABLE_COPY_MOVE(QNetworkInformation) |
90 | }; |
91 | |
92 | Q_DECLARE_OPERATORS_FOR_FLAGS(QNetworkInformation::Features) |
93 | |
94 | QT_END_NAMESPACE |
95 | |
96 | #endif |
97 | |