[welcome] refactoring of the checkHasInternet() function.

This commit is contained in:
Philip 2017-01-28 10:31:09 +01:00
parent f16890ac36
commit 56b21bbb20

View File

@ -36,7 +36,9 @@
#include <QFile> #include <QFile>
#include <QFileInfo> #include <QFileInfo>
#include <QLabel> #include <QLabel>
#include <QNetworkAccessManager> #include <QNetworkConfigurationManager>
#include <QNetworkConfiguration>
#include <QProcess> #include <QProcess>
#include <QTimer> #include <QTimer>
@ -337,8 +339,20 @@ RequirementsChecker::checkHasPower()
bool bool
RequirementsChecker::checkHasInternet() RequirementsChecker::checkHasInternet()
{ {
// default to true in the QNetworkAccessManager::UnknownAccessibility case // doc from: https://doc.qt.io/qt-5/qnetworkconfigurationmanager.html#isOnline
bool hasInternet = QNetworkAccessManager(this).networkAccessible() != QNetworkAccessManager::NotAccessible; bool hasInternet = false;
QNetworkConfigurationManager mgr;
QList<QNetworkConfiguration> activeConfigs = mgr.allConfigurations(QNetworkConfiguration::Active);
if (activeConfigs.count() > 0) {
Q_ASSERT(mgr.isOnline());
hasInternet = mgr.isOnline();
}
else {
Q_ASSERT(!mgr.isOnline());
}
Calamares::JobQueue::instance()->globalStorage()->insert( "hasInternet", hasInternet ); Calamares::JobQueue::instance()->globalStorage()->insert( "hasInternet", hasInternet );
return hasInternet; return hasInternet;
} }