From 64a47da67f0ef533ca962a9ef8ed07eb1a9da8dc Mon Sep 17 00:00:00 2001 From: Roland Winklmeier Date: Tue, 24 Jan 2017 14:08:38 +0100 Subject: [PATCH] Use CApplication::isNetworkAccessible() wherever possible Up to now we had a mixture of different methods to detect whether network is connected, accessible or both. Even if they implied a different meaning, they were all doing the same and internally referred to almost the same code. Almost, since our implementation of CNetworkUtils::hasConnectedInterface refers to code from Qt 4.4. However, all of them returned a boolean status whether a network interface is generally up or not. Instead of maintaining our own version, use Qt functions. refs #869 --- src/blackcore/application.cpp | 4 ++-- src/blackcore/setupreader.cpp | 2 +- src/blackcore/threadedreader.cpp | 2 +- src/plugins/weatherdata/gfs/weatherdatagfs.cpp | 2 +- src/swiftguistandard/swiftguistdinit.cpp | 2 +- 5 files changed, 6 insertions(+), 6 deletions(-) diff --git a/src/blackcore/application.cpp b/src/blackcore/application.cpp index e19f5da0c..3ef5e488e 100644 --- a/src/blackcore/application.cpp +++ b/src/blackcore/application.cpp @@ -539,7 +539,7 @@ namespace BlackCore QNetworkReply *CApplication::postToNetwork(const QNetworkRequest &request, QHttpMultiPart *multiPart, const CSlot &callback) { - if (!this->isNetworkConnectedAndAccessible()) { return nullptr; } + if (!this->isNetworkAccessible()) { return nullptr; } if (QThread::currentThread() != this->m_accessManager.thread()) { multiPart->moveToThread(this->m_accessManager.thread()); @@ -1176,7 +1176,7 @@ namespace BlackCore QNetworkReply *CApplication::httpRequestImpl(const QNetworkRequest &request, const BlackMisc::CSlot &callback, int maxRedirects, std::function requestOrPostMethod) { if (this->m_shutdown) { return nullptr; } - if (!this->isNetworkConnectedAndAccessible()) { return nullptr; } + if (!this->isNetworkAccessible()) { return nullptr; } QWriteLocker locker(&m_accessManagerLock); Q_ASSERT_X(QCoreApplication::instance()->thread() == m_accessManager.thread(), Q_FUNC_INFO, "Network manager supposed to be in main thread"); if (QThread::currentThread() != this->m_accessManager.thread()) diff --git a/src/blackcore/setupreader.cpp b/src/blackcore/setupreader.cpp index a425481d6..d48b57977 100644 --- a/src/blackcore/setupreader.cpp +++ b/src/blackcore/setupreader.cpp @@ -197,7 +197,7 @@ namespace BlackCore CStatusMessageList CSetupReader::triggerReadSetup() { if (this->m_shutdown) { return CStatusMessage(this, CStatusMessage::SeverityError, "shutdown"); } - if (!CNetworkUtils::hasConnectedInterface()) + if (!sApp->isNetworkAccessible()) { const CStatusMessage m(this, CStatusMessage::SeverityError, "No network, cancelled reading of setup"); diff --git a/src/blackcore/threadedreader.cpp b/src/blackcore/threadedreader.cpp index 13d56cddd..4b7f77780 100644 --- a/src/blackcore/threadedreader.cpp +++ b/src/blackcore/threadedreader.cpp @@ -71,7 +71,7 @@ namespace BlackCore bool CThreadedReader::isNetworkConnectedAndAccessible() const { - return sApp->isNetworkConnectedAndAccessible(); + return sApp->isNetworkAccessible(); } void CThreadedReader::gracefulShutdown() diff --git a/src/plugins/weatherdata/gfs/weatherdatagfs.cpp b/src/plugins/weatherdata/gfs/weatherdatagfs.cpp index 2b28e3cee..14ef67ef3 100644 --- a/src/plugins/weatherdata/gfs/weatherdatagfs.cpp +++ b/src/plugins/weatherdata/gfs/weatherdatagfs.cpp @@ -65,7 +65,7 @@ namespace BlackWxPlugin m_maxRange = range; if (m_gribData.isEmpty()) { - if (!sApp->isNetworkConnectedAndAccessible()) + if (!sApp->isNetworkAccessible()) { CLogMessage(this).error("No weather download since network not accessible"); return; diff --git a/src/swiftguistandard/swiftguistdinit.cpp b/src/swiftguistandard/swiftguistdinit.cpp index ab0b7fb24..90866e471 100644 --- a/src/swiftguistandard/swiftguistdinit.cpp +++ b/src/swiftguistandard/swiftguistdinit.cpp @@ -153,7 +153,7 @@ void SwiftGuiStd::init() this->m_init = true; QTimer::singleShot(2500, this, &SwiftGuiStd::ps_verifyDataAvailability); - if (!CNetworkUtils::hasConnectedInterface()) + if (!sGui->isNetworkAccessible()) { CLogMessage(this).error("No network interface, software will not work properly"); }