Qt 6.x
The Qt SDK
Loading...
Searching...
No Matches
qnetworkinformation_p.h
Go to the documentation of this file.
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_P_H
5#define QNETWORKINFORMATION_P_H
6
7//
8// W A R N I N G
9// -------------
10//
11// This file is not part of the Qt API. It exists for the convenience
12// of the Network Information API. This header file may change from
13// version to version without notice, or even be removed.
14//
15// We mean it.
16//
17
18#include <QtNetwork/private/qtnetworkglobal_p.h>
19
20#include <QtNetwork/qnetworkinformation.h>
21
22#include <QtCore/qloggingcategory.h>
23
25
26class Q_NETWORK_EXPORT QNetworkInformationBackend : public QObject
27{
29
32
33public:
34 static inline const char16_t PluginNames[4][22] = {
35 { u"networklistmanager" },
36 { u"scnetworkreachability" },
37 { u"android" },
38 { u"networkmanager" },
39 };
40 static constexpr int PluginNamesWindowsIndex = 0;
41 static constexpr int PluginNamesAppleIndex = 1;
42 static constexpr int PluginNamesAndroidIndex = 2;
43 static constexpr int PluginNamesLinuxIndex = 3;
44
47
48 virtual QString name() const = 0;
49 virtual QNetworkInformation::Features featuresSupported() const = 0;
50
51 Reachability reachability() const { return m_reachability; }
52 bool behindCaptivePortal() const { return m_behindCaptivePortal; }
53 TransportMedium transportMedium() const { return m_transportMedium; }
54 bool isMetered() const { return m_metered; }
55
58 void behindCaptivePortalChanged(bool behindPortal);
60 void isMeteredChanged(bool isMetered);
61
62protected:
64 {
65 if (m_reachability != reachability) {
66 m_reachability = reachability;
67 emit reachabilityChanged(reachability);
68 }
69 }
70
71 void setBehindCaptivePortal(bool behindPortal)
72 {
73 if (m_behindCaptivePortal != behindPortal) {
74 m_behindCaptivePortal = behindPortal;
75 emit behindCaptivePortalChanged(behindPortal);
76 }
77 }
78
80 {
81 if (m_transportMedium != medium) {
82 m_transportMedium = medium;
84 }
85 }
86
87 void setMetered(bool isMetered)
88 {
89 if (m_metered != isMetered) {
90 m_metered = isMetered;
91 emit isMeteredChanged(isMetered);
92 }
93 }
94
95private:
96 Reachability m_reachability = Reachability::Unknown;
97 TransportMedium m_transportMedium = TransportMedium::Unknown;
98 bool m_behindCaptivePortal = false;
99 bool m_metered = false;
100
101 Q_DISABLE_COPY_MOVE(QNetworkInformationBackend)
104};
105
106class Q_NETWORK_EXPORT QNetworkInformationBackendFactory : public QObject
107{
109
110 using Features = QNetworkInformation::Features;
111
112public:
115 virtual QString name() const = 0;
116 virtual QNetworkInformationBackend *create(Features requiredFeatures) const = 0;
117 virtual Features featuresSupported() const = 0;
118
119private:
120 Q_DISABLE_COPY_MOVE(QNetworkInformationBackendFactory)
121};
122#define QNetworkInformationBackendFactory_iid "org.qt-project.Qt.NetworkInformationBackendFactory"
124
126
127#endif
static void transportMediumChanged(JNIEnv *env, jobject obj, jint enumValue)
QNetworkInformationBackendFactory provides the interface for creating instances of QNetworkInformatio...
virtual QString name() const =0
Backend name, return the same in QNetworkInformationBackend::name().
virtual Features featuresSupported() const =0
Features supported, return the same in QNetworkInformationBackend::featuresSupported().
virtual QNetworkInformationBackend * create(Features requiredFeatures) const =0
Create and return an instance of QNetworkInformationBackend.
QNetworkInformationBackend provides the interface with which QNetworkInformation does all of its actu...
void transportMediumChanged(TransportMedium medium)
~QNetworkInformationBackend() override
void isMeteredChanged(bool isMetered)
TransportMedium transportMedium() const
virtual QNetworkInformation::Features featuresSupported() const =0
Features supported, return the same in QNetworkInformationBackendFactory::featuresSupported().
void setTransportMedium(TransportMedium medium)
void behindCaptivePortalChanged(bool behindPortal)
virtual QString name() const =0
Backend name, return the same in QNetworkInformationBackendFactory::name().
void reachabilityChanged(Reachability reachability)
You should not emit this signal manually, call setReachability() instead which will emit this signal ...
void setBehindCaptivePortal(bool behindPortal)
QNetworkInformationBackend()=default
Reachability reachability() const
void setReachability(QNetworkInformation::Reachability reachability)
Call this when reachability has changed.
\inmodule QtNetwork
Reachability
\value Unknown If this value is returned then we may be connected but the OS has still not confirmed ...
\inmodule QtCore
Definition qobject.h:90
\macro QT_RESTRICTED_CAST_FROM_ASCII
Definition qstring.h:127
Combined button and popup list for selecting options.
#define QNetworkInformationBackendFactory_iid
#define Q_DECLARE_INTERFACE(IFace, IId)
Definition qobject.h:420
#define Q_OBJECT
#define Q_SIGNALS
#define emit