From e06500863101b6d3506c5710b81ab35e948fe2f6 Mon Sep 17 00:00:00 2001 From: Adriaan de Groot Date: Tue, 20 Aug 2019 10:57:02 -0400 Subject: [PATCH] [welcome] Switch to the network service - simplify configuration - use existing ping- and hasInternet() --- .../welcome/checker/GeneralRequirements.cpp | 41 ++++++++----------- .../welcome/checker/GeneralRequirements.h | 1 - 2 files changed, 16 insertions(+), 26 deletions(-) diff --git a/src/modules/welcome/checker/GeneralRequirements.cpp b/src/modules/welcome/checker/GeneralRequirements.cpp index 0e6133d3f..4787fe51d 100644 --- a/src/modules/welcome/checker/GeneralRequirements.cpp +++ b/src/modules/welcome/checker/GeneralRequirements.cpp @@ -25,12 +25,14 @@ #include "partman_devices.h" #include "modulesystem/Requirement.h" +#include "network/Manager.h" #include "widgets/WaitingWidget.h" #include "utils/CalamaresUtilsGui.h" #include "utils/Logger.h" #include "utils/Retranslator.h" #include "utils/CalamaresUtilsSystem.h" #include "utils/Units.h" +#include "utils/Variant.h" #include "Settings.h" #include "JobQueue.h" @@ -245,16 +247,16 @@ GeneralRequirements::setConfigurationMap( const QVariantMap& configurationMap ) incompleteConfiguration = true; } - if ( configurationMap.contains( "internetCheckUrl" ) && - configurationMap.value( "internetCheckUrl" ).type() == QVariant::String ) + QUrl checkInternetUrl; + QString checkInternetSetting = CalamaresUtils::getString( configurationMap, "internetCheckUrl" ); + if ( !checkInternetSetting.isEmpty() ) { - m_checkHasInternetUrl = configurationMap.value( "internetCheckUrl" ).toString().trimmed(); - if ( m_checkHasInternetUrl.isEmpty() || - !QUrl( m_checkHasInternetUrl ).isValid() ) + checkInternetUrl = QUrl( checkInternetSetting.trimmed() ); + if ( !checkInternetUrl.isValid() ) { - cWarning() << "GeneralRequirements entry 'internetCheckUrl' is invalid in welcome.conf" << m_checkHasInternetUrl + cWarning() << "GeneralRequirements entry 'internetCheckUrl' is invalid in welcome.conf" << checkInternetSetting << "reverting to default (http://example.com)."; - m_checkHasInternetUrl = "http://example.com"; + checkInternetUrl = QUrl( "http://example.com" ); incompleteConfiguration = true; } } @@ -262,10 +264,13 @@ GeneralRequirements::setConfigurationMap( const QVariantMap& configurationMap ) { cWarning() << "GeneralRequirements entry 'internetCheckUrl' is undefined in welcome.conf," "reverting to default (http://example.com)."; - - m_checkHasInternetUrl = "http://example.com"; + checkInternetUrl = "http://example.com"; incompleteConfiguration = true; } + if ( checkInternetUrl.isValid() ) + { + CalamaresUtils::Network::Manager::instance().setCheckHasInternetUrl( checkInternetUrl ); + } if ( incompleteConfiguration ) { @@ -357,22 +362,8 @@ GeneralRequirements::checkHasPower() bool GeneralRequirements::checkHasInternet() { - // default to true in the QNetworkAccessManager::UnknownAccessibility case - QNetworkAccessManager qnam; - 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; - } - + auto& nam = CalamaresUtils::Network::Manager::instance(); + bool hasInternet = nam.checkHasInternet(); Calamares::JobQueue::instance()->globalStorage()->insert( "hasInternet", hasInternet ); return hasInternet; } diff --git a/src/modules/welcome/checker/GeneralRequirements.h b/src/modules/welcome/checker/GeneralRequirements.h index 1efe118a6..8e5a6cd54 100644 --- a/src/modules/welcome/checker/GeneralRequirements.h +++ b/src/modules/welcome/checker/GeneralRequirements.h @@ -48,7 +48,6 @@ private: qreal m_requiredStorageGiB; qreal m_requiredRamGiB; - QString m_checkHasInternetUrl; }; #endif // REQUIREMENTSCHECKER_H