diff --git a/src/modules/welcome/checker/RequirementsChecker.cpp b/src/modules/welcome/checker/RequirementsChecker.cpp index 3d7eb7da7..80bc92974 100644 --- a/src/modules/welcome/checker/RequirementsChecker.cpp +++ b/src/modules/welcome/checker/RequirementsChecker.cpp @@ -1,6 +1,6 @@ /* === This file is part of Calamares - === * - * Copyright 2014-2016, Teo Mrnjavac + * Copyright 2014-2017, Teo Mrnjavac * * Calamares is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -33,10 +33,13 @@ #include #include #include +#include #include #include #include #include +#include +#include #include #include @@ -222,6 +225,27 @@ RequirementsChecker::setConfigurationMap( const QVariantMap& configurationMap ) incompleteConfiguration = true; } + if ( configurationMap.contains( "internetCheckUrl" ) && + configurationMap.value( "internetCheckUrl" ).type() == QVariant::String ) + { + m_checkHasInternetUrl = configurationMap.value( "internetCheckUrl" ).toString().trimmed(); + if ( m_checkHasInternetUrl.isEmpty() || + !QUrl( m_checkHasInternetUrl ).isValid() ) + { + cDebug() << "Invalid internetCheckUrl in welcome.conf" << m_checkHasInternetUrl + << "reverting to default (http://example.com)."; + m_checkHasInternetUrl = "http://example.com"; + incompleteConfiguration = true; + } + } + else + { + cDebug() << "internetCheckUrl is undefined in welcome.conf, " + "reverting to default (http://example.com)."; + m_checkHasInternetUrl = "http://example.com"; + incompleteConfiguration = true; + } + if ( configurationMap.contains( "check" ) && configurationMap.value( "check" ).type() == QVariant::List ) { @@ -338,7 +362,21 @@ bool RequirementsChecker::checkHasInternet() { // default to true in the QNetworkAccessManager::UnknownAccessibility case - bool hasInternet = QNetworkAccessManager(this).networkAccessible() != QNetworkAccessManager::NotAccessible; + QNetworkAccessManager qnam( this ); + bool hasInternet = qnam.networkAccessible() == QNetworkAccessManager::Accessible; + + if ( !hasInternet && qnam.networkAccessible() == QNetworkAccessManager::UnknownAccessibility ) + { + QNetworkRequest req = QNetworkRequest( QUrl( m_checkHasInternetUrl ) ); + QNetworkReply* reply = qnam.get( req ); + QEventLoop loop; + connect( reply, &QNetworkReply::finished, + &loop, &QEventLoop::quit ); + loop.exec(); + if( reply->bytesAvailable() ) + hasInternet = true; + } + Calamares::JobQueue::instance()->globalStorage()->insert( "hasInternet", hasInternet ); return hasInternet; } diff --git a/src/modules/welcome/checker/RequirementsChecker.h b/src/modules/welcome/checker/RequirementsChecker.h index 75df70744..1e52d9fc5 100644 --- a/src/modules/welcome/checker/RequirementsChecker.h +++ b/src/modules/welcome/checker/RequirementsChecker.h @@ -1,6 +1,6 @@ /* === This file is part of Calamares - === * - * Copyright 2014-2015, Teo Mrnjavac + * Copyright 2014-2017, Teo Mrnjavac * * Calamares is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -69,6 +69,7 @@ private: QWidget* m_widget; qreal m_requiredStorageGB; qreal m_requiredRamGB; + QString m_checkHasInternetUrl; CheckerWidget* m_actualWidget; bool m_verdict; diff --git a/src/modules/welcome/welcome.conf b/src/modules/welcome/welcome.conf index aa8abb55a..f7cd72cec 100644 --- a/src/modules/welcome/welcome.conf +++ b/src/modules/welcome/welcome.conf @@ -6,6 +6,7 @@ showReleaseNotesUrl: true requirements: requiredStorage: 5.5 requiredRam: 1.0 + internetCheckUrl: http://google.com check: - storage - ram