summaryrefslogtreecommitdiffstats
path: root/src/network/kernel
diff options
context:
space:
mode:
authorMårten Nordheim <marten.nordheim@qt.io>2021-05-21 16:36:57 +0200
committerMårten Nordheim <marten.nordheim@qt.io>2021-05-31 17:25:22 +0200
commitda955aadf5d5189b4f8de3eb2ed1b2f2f129cb28 (patch)
treeb18fa8e5b1ca49971b9e3e97be4d263cdea8a67d /src/network/kernel
parent69982182a394618d4f121d2938d7d76196fe78f6 (diff)
QNetworkInformation: Behind captive portal
This patch adds the API, with no supporting backends Task-number: QTBUG-93848 Change-Id: I50454717f928819e1b990df91872675e842f9987 Reviewed-by: Edward Welbourne <edward.welbourne@qt.io> Reviewed-by: Timur Pocheptsov <timur.pocheptsov@qt.io>
Diffstat (limited to 'src/network/kernel')
-rw-r--r--src/network/kernel/qnetworkinformation.cpp36
-rw-r--r--src/network/kernel/qnetworkinformation.h12
-rw-r--r--src/network/kernel/qnetworkinformation_p.h12
3 files changed, 60 insertions, 0 deletions
diff --git a/src/network/kernel/qnetworkinformation.cpp b/src/network/kernel/qnetworkinformation.cpp
index c36b1c4698..c1e184f961 100644
--- a/src/network/kernel/qnetworkinformation.cpp
+++ b/src/network/kernel/qnetworkinformation.cpp
@@ -471,6 +471,21 @@ QNetworkInformationBackendFactory::~QNetworkInformationBackendFactory()
*/
/*!
+ \enum QNetworkInformation::TriState
+ \since 6.2
+
+ A bool with a 3rd, unknown, state.
+
+ \value False
+ Known to be \c{false}.
+ \value True
+ Known to be \c{true}.
+ \value Unknown
+ The state cannot be determined at present, either because the query is
+ not supported on this platform or because the OS lacks the information.
+*/
+
+/*!
\internal ctor
*/
QNetworkInformation::QNetworkInformation(QNetworkInformationBackend *backend)
@@ -478,6 +493,9 @@ QNetworkInformation::QNetworkInformation(QNetworkInformationBackend *backend)
{
connect(backend, &QNetworkInformationBackend::reachabilityChanged, this,
[this]() { emit reachabilityChanged(d_func()->backend->reachability()); });
+ connect(backend, &QNetworkInformationBackend::behindCaptivePortalChanged, this, [this]() {
+ emit behindCaptivePortalChanged(d_func()->backend->behindCaptivePortal());
+ });
}
/*!
@@ -505,6 +523,24 @@ QNetworkInformation::Reachability QNetworkInformation::reachability() const
}
/*!
+ \property QNetworkInformation::behindCaptivePortal
+ \brief Lets you know if the user's device is behind a captive portal.
+ \since 6.2
+
+ This property indicates if the user's device is currently behind a captive
+ portal. This functionality relies on the operating system's detection of
+ captive portals and is not supported on systems that don't report this.
+ On systems where this is not supported this will always return
+ TriState::Unknown.
+
+ \sa TriState
+*/
+QNetworkInformation::TriState QNetworkInformation::behindCaptivePortal() const
+{
+ return d_func()->backend->behindCaptivePortal();
+}
+
+/*!
Returns the name of the currently loaded backend.
*/
QString QNetworkInformation::backendName() const
diff --git a/src/network/kernel/qnetworkinformation.h b/src/network/kernel/qnetworkinformation.h
index 07f4fe873d..6e700747bb 100644
--- a/src/network/kernel/qnetworkinformation.h
+++ b/src/network/kernel/qnetworkinformation.h
@@ -55,6 +55,7 @@ class Q_NETWORK_EXPORT QNetworkInformation : public QObject
Q_OBJECT
Q_DECLARE_PRIVATE(QNetworkInformation)
Q_PROPERTY(Reachability reachability READ reachability NOTIFY reachabilityChanged)
+ Q_PROPERTY(TriState behindCaptivePortal READ behindCaptivePortal NOTIFY behindCaptivePortalChanged)
public:
enum class Reachability {
Unknown,
@@ -65,14 +66,24 @@ public:
};
Q_ENUM(Reachability)
+ enum class TriState {
+ False,
+ True,
+ Unknown,
+ };
+ Q_ENUM(TriState)
+
enum class Feature {
Reachability = 0x1,
+ CaptivePortal = 0x2,
};
Q_DECLARE_FLAGS(Features, Feature)
Q_FLAG(Features)
Reachability reachability() const;
+ TriState behindCaptivePortal() const;
+
QString backendName() const;
bool supports(Features features) const;
@@ -84,6 +95,7 @@ public:
Q_SIGNALS:
void reachabilityChanged(Reachability newReachability);
+ void behindCaptivePortalChanged(TriState state);
private:
friend struct QNetworkInformationDeleter;
diff --git a/src/network/kernel/qnetworkinformation_p.h b/src/network/kernel/qnetworkinformation_p.h
index 8cb31e6641..c71e7787a4 100644
--- a/src/network/kernel/qnetworkinformation_p.h
+++ b/src/network/kernel/qnetworkinformation_p.h
@@ -70,9 +70,11 @@ public:
virtual QNetworkInformation::Features featuresSupported() const = 0;
QNetworkInformation::Reachability reachability() const { return m_reachability; }
+ QNetworkInformation::TriState behindCaptivePortal() const { return m_behindCaptivePortal; }
Q_SIGNALS:
void reachabilityChanged();
+ void behindCaptivePortalChanged();
protected:
void setReachability(QNetworkInformation::Reachability reachability)
@@ -83,8 +85,18 @@ protected:
}
}
+ void setBehindCaptivePortal(QNetworkInformation::TriState behindPortal)
+ {
+ if (m_behindCaptivePortal != behindPortal) {
+ m_behindCaptivePortal = behindPortal;
+ emit behindCaptivePortalChanged();
+ }
+ }
+
private:
QNetworkInformation::Reachability m_reachability = QNetworkInformation::Reachability::Unknown;
+ QNetworkInformation::TriState m_behindCaptivePortal =
+ QNetworkInformation::TriState::Unknown;
Q_DISABLE_COPY_MOVE(QNetworkInformationBackend)
friend class QNetworkInformation;