[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 <QFileInfo>
#include <QLabel>
#include <QNetworkAccessManager>
#include <QNetworkConfigurationManager>
#include <QNetworkConfiguration>
#include <QProcess>
#include <QTimer>
@ -337,8 +339,20 @@ RequirementsChecker::checkHasPower()
bool
RequirementsChecker::checkHasInternet()
{
// default to true in the QNetworkAccessManager::UnknownAccessibility case
bool hasInternet = QNetworkAccessManager(this).networkAccessible() != QNetworkAccessManager::NotAccessible;
// doc from: https://doc.qt.io/qt-5/qnetworkconfigurationmanager.html#isOnline
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 );
return hasInternet;
}