Pimcommon

networkmanager.cpp
1/*
2 SPDX-FileCopyrightText: 2016-2024 Laurent Montel <montel@kde.org>
3
4 SPDX-License-Identifier: GPL-2.0-or-later
5*/
6
7#include "networkmanager.h"
8#include "pimcommon_debug.h"
9#include <QNetworkInformation>
10using namespace PimCommon;
11
12Q_GLOBAL_STATIC(NetworkManager, s_pNetworkManagerSelf)
13
14NetworkManager::NetworkManager(QObject *parent)
15 : QObject(parent)
16{
17 QNetworkInformation::instance()->loadBackendByFeatures(QNetworkInformation::Feature::Reachability);
20 refreshStatus();
21}
22
23NetworkManager::~NetworkManager()
24{
25}
26
27NetworkManager *NetworkManager::self()
28{
29 return s_pNetworkManagerSelf();
30}
31
32bool NetworkManager::isOnline() const
33{
34 return m_isOnline;
35}
36
37void NetworkManager::refreshStatus()
38{
39 const auto info = QNetworkInformation::instance();
40 const bool newIsOnline = info->reachability() == QNetworkInformation::Reachability::Online && !info->isBehindCaptivePortal();
41 if (newIsOnline != m_isOnline) {
42 m_isOnline = newIsOnline;
43 Q_EMIT networkStatusChanged(m_isOnline);
44 }
45}
46
47#include "moc_networkmanager.cpp"
folderdialogacltab.h
QNetworkInformation * instance()
void isBehindCaptivePortalChanged(bool state)
bool loadBackendByFeatures(Features features)
void reachabilityChanged(Reachability newReachability)
Q_EMITQ_EMIT
QFuture< ArgsType< Signal > > connect(Sender *sender, Signal signal)
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Mon Nov 4 2024 16:39:22 by doxygen 1.12.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.