KTextAddons

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 "texttranslator_debug.h"
9#include <QNetworkInformation>
10using namespace TextTranslator;
11
12Q_GLOBAL_STATIC(NetworkManager, s_pNetworkManagerSelf)
13
14NetworkManager::NetworkManager(QObject *parent)
15 : QObject(parent)
16{
17 QNetworkInformation::instance()->loadBackendByFeatures(QNetworkInformation::Feature::Reachability);
19 Q_EMIT networkStatusChanged(newReachability == QNetworkInformation::Reachability::Online);
20 });
21}
22
23NetworkManager::~NetworkManager()
24{
25}
26
27NetworkManager *NetworkManager::self()
28{
29 return s_pNetworkManagerSelf();
30}
31
32bool NetworkManager::isOnline() const
33{
34 if (QNetworkInformation::loadBackendByFeatures(QNetworkInformation::Feature::Reachability)) {
35 return QNetworkInformation::instance()->reachability() == QNetworkInformation::Reachability::Online;
36 } else {
37 qCWarning(TEXTTRANSLATOR_LOG) << "Couldn't find a working backend for QNetworkInformation";
38 return false;
39 }
40}
41
42#include "moc_networkmanager.cpp"
QNetworkInformation * instance()
bool loadBackendByFeatures(Features features)
void reachabilityChanged(Reachability newReachability)
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 Fri Nov 22 2024 12:02:03 by doxygen 1.12.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.