Commit ad38782f authored by Laurent Montel's avatar Laurent Montel 😁
Browse files

Port QNetworkConfigurationManager in qt6

parent 98f93c5b
Pipeline #173651 passed with stage
in 8 minutes and 22 seconds
......@@ -34,8 +34,12 @@
#endif
#include <QCommandLineParser>
#include <QNetworkConfiguration>
#if QT_VERSION < QT_VERSION_CHECK(6, 0, 0)
#include <QNetworkConfigurationManager>
#else
#include <QNetworkInformation>
#endif
#include <QNetworkConfiguration>
#include <QPointer>
#include <QSettings>
#include <QTimer>
......@@ -804,7 +808,11 @@ void AgentBasePrivate::slotNetworkStatusChange(bool isOnline)
void AgentBasePrivate::slotResumedFromSuspend()
{
if (mNeedsNetwork) {
#if QT_VERSION < QT_VERSION_CHECK(6, 0, 0)
slotNetworkStatusChange(mNetworkManager->isOnline());
#else
slotNetworkStatusChange(QNetworkInformation::instance()->reachability() != QNetworkInformation::Reachability::Online);
#endif
}
}
......@@ -976,7 +984,7 @@ void AgentBase::setNeedsNetwork(bool needsNetwork)
}
d->mNeedsNetwork = needsNetwork;
#if QT_VERSION < QT_VERSION_CHECK(6, 0, 0)
if (d->mNeedsNetwork) {
d->mNetworkManager = new QNetworkConfigurationManager(this);
connect(d->mNetworkManager, &QNetworkConfigurationManager::onlineStateChanged, d, &AgentBasePrivate::slotNetworkStatusChange, Qt::UniqueConnection);
......@@ -986,6 +994,10 @@ void AgentBase::setNeedsNetwork(bool needsNetwork)
d->mNetworkManager = nullptr;
setOnlineInternal(d->mDesiredOnlineState);
}
#else
QNetworkInformation::load(QNetworkInformation::Feature::Reachability);
connect(QNetworkInformation::instance(), &QNetworkInformation::reachabilityChanged, d, &AgentBasePrivate::slotNetworkStatusChange, Qt::UniqueConnection);
#endif
}
void AgentBase::setOnline(bool state)
......@@ -1025,10 +1037,17 @@ void AgentBase::setOnlineInternal(bool state)
{
Q_D(AgentBase);
if (state && d->mNeedsNetwork) {
#if QT_VERSION < QT_VERSION_CHECK(6, 0, 0)
if (!d->mNetworkManager->isOnline()) {
// Don't go online if the resource needs network but there is none
state = false;
}
#else
if (QNetworkInformation::instance()->reachability() != QNetworkInformation::Reachability::Online) {
// Don't go online if the resource needs network but there is none
state = false;
}
#endif
}
d->mOnline = state;
......
......@@ -100,8 +100,9 @@ public:
QTimer *mTemporaryOfflineTimer = nullptr;
QEventLoopLocker *mEventLoopLocker = nullptr;
#if QT_VERSION < QT_VERSION_CHECK(6, 0, 0)
QNetworkConfigurationManager *mNetworkManager = nullptr;
#endif
public Q_SLOTS:
// Dump the contents of the current ChangeReplay
Q_SCRIPTABLE QString dumpNotificationListToString() const;
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment