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 | Q_CLASSINFO("RegisterEnumClassesUnscoped" , "false" ) |
27 | public: |
28 | enum class Reachability { |
29 | Unknown, |
30 | Disconnected, |
31 | Local, |
32 | Site, |
33 | Online, |
34 | }; |
35 | Q_ENUM(Reachability) |
36 | |
37 | enum class TransportMedium { |
38 | Unknown, |
39 | Ethernet, |
40 | Cellular, |
41 | WiFi, |
42 | Bluetooth, |
43 | }; |
44 | Q_ENUM(TransportMedium) |
45 | |
46 | enum class Feature { |
47 | Reachability = 0x1, |
48 | CaptivePortal = 0x2, |
49 | TransportMedium = 0x4, |
50 | Metered = 0x8, |
51 | }; |
52 | Q_DECLARE_FLAGS(Features, Feature) |
53 | Q_FLAG(Features) |
54 | |
55 | Reachability reachability() const; |
56 | |
57 | bool isBehindCaptivePortal() const; |
58 | |
59 | TransportMedium transportMedium() const; |
60 | |
61 | bool isMetered() const; |
62 | |
63 | QString backendName() const; |
64 | |
65 | bool supports(Features features) const; |
66 | Features supportedFeatures() const; |
67 | |
68 | static bool loadDefaultBackend(); |
69 | static bool loadBackendByName(QStringView backend); |
70 | static bool loadBackendByFeatures(Features features); |
71 | #if QT_DEPRECATED_SINCE(6,4) |
72 | QT_DEPRECATED_VERSION_X_6_4("Use loadBackendByName" ) static bool load(QStringView backend); |
73 | QT_DEPRECATED_VERSION_X_6_4("Use loadBackendByFeatures" ) static bool load(Features features); |
74 | #endif |
75 | static QStringList availableBackends(); |
76 | static QNetworkInformation *instance(); |
77 | |
78 | Q_SIGNALS: |
79 | void reachabilityChanged(QNetworkInformation::Reachability newReachability); |
80 | void isBehindCaptivePortalChanged(bool state); |
81 | void transportMediumChanged(QNetworkInformation::TransportMedium current); |
82 | void isMeteredChanged(bool isMetered); |
83 | |
84 | private: |
85 | friend struct QNetworkInformationDeleter; |
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 | |