QNI: glib support for the isMetered API
Task-number: QTBUG-91024 Change-Id: Ieb46b87dde58a65a108f215c9c30695c02a51982 Reviewed-by: Mårten Nordheim <marten.nordheim@qt.io> (cherry picked from commit 7a8b403bd3568b04779cb1495a40dffe4fba945d) Reviewed-by: Qt Cherry-pick Bot <cherrypick_bot@qt-project.org>
This commit is contained in:
parent
0af27bf836
commit
baec3249f1
@ -51,7 +51,8 @@ public:
|
|||||||
static QNetworkInformation::Features featuresSupportedStatic()
|
static QNetworkInformation::Features featuresSupportedStatic()
|
||||||
{
|
{
|
||||||
using Feature = QNetworkInformation::Feature;
|
using Feature = QNetworkInformation::Feature;
|
||||||
return QNetworkInformation::Features(Feature::Reachability | Feature::CaptivePortal);
|
return QNetworkInformation::Features(Feature::Reachability | Feature::CaptivePortal
|
||||||
|
| Feature::Metered);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool isValid() const;
|
bool isValid() const;
|
||||||
@ -59,10 +60,12 @@ public:
|
|||||||
private:
|
private:
|
||||||
Q_DISABLE_COPY_MOVE(QGlibNetworkInformationBackend)
|
Q_DISABLE_COPY_MOVE(QGlibNetworkInformationBackend)
|
||||||
|
|
||||||
static void updateInformation(QGlibNetworkInformationBackend *backend);
|
static void updateConnectivity(QGlibNetworkInformationBackend *backend);
|
||||||
|
static void updateMetered(QGlibNetworkInformationBackend *backend);
|
||||||
|
|
||||||
GNetworkMonitor *networkMonitor = nullptr;
|
GNetworkMonitor *networkMonitor = nullptr;
|
||||||
gulong handlerId = 0;
|
gulong connectivityHandlerId = 0;
|
||||||
|
gulong meteredHandlerId = 0;
|
||||||
};
|
};
|
||||||
|
|
||||||
class QGlibNetworkInformationBackendFactory : public QNetworkInformationBackendFactory
|
class QGlibNetworkInformationBackendFactory : public QNetworkInformationBackendFactory
|
||||||
@ -95,15 +98,20 @@ private:
|
|||||||
QGlibNetworkInformationBackend::QGlibNetworkInformationBackend()
|
QGlibNetworkInformationBackend::QGlibNetworkInformationBackend()
|
||||||
: networkMonitor(g_network_monitor_get_default())
|
: networkMonitor(g_network_monitor_get_default())
|
||||||
{
|
{
|
||||||
updateInformation(this);
|
updateConnectivity(this);
|
||||||
|
updateMetered(this);
|
||||||
|
|
||||||
handlerId = g_signal_connect_swapped(networkMonitor, "notify::connectivity",
|
connectivityHandlerId = g_signal_connect_swapped(networkMonitor, "notify::connectivity",
|
||||||
G_CALLBACK(updateInformation), this);
|
G_CALLBACK(updateConnectivity), this);
|
||||||
|
|
||||||
|
meteredHandlerId = g_signal_connect_swapped(networkMonitor, "notify::network-metered",
|
||||||
|
G_CALLBACK(updateMetered), this);
|
||||||
}
|
}
|
||||||
|
|
||||||
QGlibNetworkInformationBackend::~QGlibNetworkInformationBackend()
|
QGlibNetworkInformationBackend::~QGlibNetworkInformationBackend()
|
||||||
{
|
{
|
||||||
g_signal_handler_disconnect(networkMonitor, handlerId);
|
g_signal_handler_disconnect(networkMonitor, meteredHandlerId);
|
||||||
|
g_signal_handler_disconnect(networkMonitor, connectivityHandlerId);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool QGlibNetworkInformationBackend::isValid() const
|
bool QGlibNetworkInformationBackend::isValid() const
|
||||||
@ -111,7 +119,7 @@ bool QGlibNetworkInformationBackend::isValid() const
|
|||||||
return G_OBJECT_TYPE_NAME(networkMonitor) != "GNetworkMonitorBase"_L1;
|
return G_OBJECT_TYPE_NAME(networkMonitor) != "GNetworkMonitorBase"_L1;
|
||||||
}
|
}
|
||||||
|
|
||||||
void QGlibNetworkInformationBackend::updateInformation(QGlibNetworkInformationBackend *backend)
|
void QGlibNetworkInformationBackend::updateConnectivity(QGlibNetworkInformationBackend *backend)
|
||||||
{
|
{
|
||||||
const auto connectivityState = g_network_monitor_get_connectivity(backend->networkMonitor);
|
const auto connectivityState = g_network_monitor_get_connectivity(backend->networkMonitor);
|
||||||
const bool behindPortal = (connectivityState == G_NETWORK_CONNECTIVITY_PORTAL);
|
const bool behindPortal = (connectivityState == G_NETWORK_CONNECTIVITY_PORTAL);
|
||||||
@ -119,6 +127,11 @@ void QGlibNetworkInformationBackend::updateInformation(QGlibNetworkInformationBa
|
|||||||
backend->setBehindCaptivePortal(behindPortal);
|
backend->setBehindCaptivePortal(behindPortal);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void QGlibNetworkInformationBackend::updateMetered(QGlibNetworkInformationBackend *backend)
|
||||||
|
{
|
||||||
|
backend->setMetered(g_network_monitor_get_network_metered(backend->networkMonitor));
|
||||||
|
}
|
||||||
|
|
||||||
QT_END_NAMESPACE
|
QT_END_NAMESPACE
|
||||||
|
|
||||||
#include "qglibnetworkinformationbackend.moc"
|
#include "qglibnetworkinformationbackend.moc"
|
||||||
|
Loading…
x
Reference in New Issue
Block a user