diff options
Diffstat (limited to 'src/plugins/networkinformation/glib/qglibnetworkinformationbackend.cpp')
-rw-r--r-- | src/plugins/networkinformation/glib/qglibnetworkinformationbackend.cpp | 74 |
1 files changed, 27 insertions, 47 deletions
diff --git a/src/plugins/networkinformation/glib/qglibnetworkinformationbackend.cpp b/src/plugins/networkinformation/glib/qglibnetworkinformationbackend.cpp index f26079b041..0b45eb9ce3 100644 --- a/src/plugins/networkinformation/glib/qglibnetworkinformationbackend.cpp +++ b/src/plugins/networkinformation/glib/qglibnetworkinformationbackend.cpp @@ -1,41 +1,5 @@ -/**************************************************************************** -** -** Copyright (C) 2021 Ilya Fedin <fedin-ilja2010@ya.ru> -** Contact: https://www.qt.io/licensing/ -** -** This file is part of the QtNetwork module of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** Commercial License Usage -** Licensees holding valid commercial Qt licenses may use this file in -** accordance with the commercial license agreement provided with the -** Software or, alternatively, in accordance with the terms contained in -** a written agreement between you and The Qt Company. For licensing terms -** and conditions see https://www.qt.io/terms-conditions. For further -** information use the contact form at https://www.qt.io/contact-us. -** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 3 as published by the Free Software -** Foundation and appearing in the file LICENSE.LGPL3 included in the -** packaging of this file. Please review the following information to -** ensure the GNU Lesser General Public License version 3 requirements -** will be met: https://www.gnu.org/licenses/lgpl-3.0.html. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU -** General Public License version 2.0 or (at your option) the GNU General -** Public license version 3 or any later version approved by the KDE Free -** Qt Foundation. The licenses are as published by the Free Software -** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3 -** included in the packaging of this file. Please review the following -** information to ensure the GNU General Public License requirements will -** be met: https://www.gnu.org/licenses/gpl-2.0.html and -** https://www.gnu.org/licenses/gpl-3.0.html. -** -** $QT_END_LICENSE$ -** -****************************************************************************/ +// Copyright (C) 2021 Ilya Fedin <fedin-ilja2010@ya.ru> +// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only #include <QtNetwork/private/qnetworkinformation_p.h> @@ -45,6 +9,9 @@ #include <gio/gio.h> QT_BEGIN_NAMESPACE + +using namespace Qt::StringLiterals; + Q_DECLARE_LOGGING_CATEGORY(lcNetInfoGlib) Q_LOGGING_CATEGORY(lcNetInfoGlib, "qt.network.info.glib"); @@ -84,7 +51,8 @@ public: static QNetworkInformation::Features featuresSupportedStatic() { using Feature = QNetworkInformation::Feature; - return QNetworkInformation::Features(Feature::Reachability | Feature::CaptivePortal); + return QNetworkInformation::Features(Feature::Reachability | Feature::CaptivePortal + | Feature::Metered); } bool isValid() const; @@ -92,10 +60,12 @@ public: private: Q_DISABLE_COPY_MOVE(QGlibNetworkInformationBackend) - static void updateInformation(QGlibNetworkInformationBackend *backend); + static void updateConnectivity(QGlibNetworkInformationBackend *backend); + static void updateMetered(QGlibNetworkInformationBackend *backend); GNetworkMonitor *networkMonitor = nullptr; - gulong handlerId = 0; + gulong connectivityHandlerId = 0; + gulong meteredHandlerId = 0; }; class QGlibNetworkInformationBackendFactory : public QNetworkInformationBackendFactory @@ -128,23 +98,28 @@ private: QGlibNetworkInformationBackend::QGlibNetworkInformationBackend() : networkMonitor(g_network_monitor_get_default()) { - updateInformation(this); + updateConnectivity(this); + updateMetered(this); + + connectivityHandlerId = g_signal_connect_swapped(networkMonitor, "notify::connectivity", + G_CALLBACK(updateConnectivity), this); - handlerId = g_signal_connect_swapped(networkMonitor, "notify::connectivity", - G_CALLBACK(updateInformation), this); + meteredHandlerId = g_signal_connect_swapped(networkMonitor, "notify::network-metered", + G_CALLBACK(updateMetered), this); } QGlibNetworkInformationBackend::~QGlibNetworkInformationBackend() { - g_signal_handler_disconnect(networkMonitor, handlerId); + g_signal_handler_disconnect(networkMonitor, meteredHandlerId); + g_signal_handler_disconnect(networkMonitor, connectivityHandlerId); } bool QGlibNetworkInformationBackend::isValid() const { - return G_OBJECT_TYPE_NAME(networkMonitor) != QLatin1String("GNetworkMonitorBase"); + return QLatin1StringView(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 bool behindPortal = (connectivityState == G_NETWORK_CONNECTIVITY_PORTAL); @@ -152,6 +127,11 @@ void QGlibNetworkInformationBackend::updateInformation(QGlibNetworkInformationBa backend->setBehindCaptivePortal(behindPortal); } +void QGlibNetworkInformationBackend::updateMetered(QGlibNetworkInformationBackend *backend) +{ + backend->setMetered(g_network_monitor_get_network_metered(backend->networkMonitor)); +} + QT_END_NAMESPACE #include "qglibnetworkinformationbackend.moc" |