[welcome] Switch to the network service

- simplify configuration
 - use existing ping- and hasInternet()
This commit is contained in:
Adriaan de Groot 2019-08-20 10:57:02 -04:00
parent 4389c254df
commit e065008631
2 changed files with 16 additions and 26 deletions

View File

@ -25,12 +25,14 @@
#include "partman_devices.h" #include "partman_devices.h"
#include "modulesystem/Requirement.h" #include "modulesystem/Requirement.h"
#include "network/Manager.h"
#include "widgets/WaitingWidget.h" #include "widgets/WaitingWidget.h"
#include "utils/CalamaresUtilsGui.h" #include "utils/CalamaresUtilsGui.h"
#include "utils/Logger.h" #include "utils/Logger.h"
#include "utils/Retranslator.h" #include "utils/Retranslator.h"
#include "utils/CalamaresUtilsSystem.h" #include "utils/CalamaresUtilsSystem.h"
#include "utils/Units.h" #include "utils/Units.h"
#include "utils/Variant.h"
#include "Settings.h" #include "Settings.h"
#include "JobQueue.h" #include "JobQueue.h"
@ -245,16 +247,16 @@ GeneralRequirements::setConfigurationMap( const QVariantMap& configurationMap )
incompleteConfiguration = true; incompleteConfiguration = true;
} }
if ( configurationMap.contains( "internetCheckUrl" ) && QUrl checkInternetUrl;
configurationMap.value( "internetCheckUrl" ).type() == QVariant::String ) QString checkInternetSetting = CalamaresUtils::getString( configurationMap, "internetCheckUrl" );
if ( !checkInternetSetting.isEmpty() )
{ {
m_checkHasInternetUrl = configurationMap.value( "internetCheckUrl" ).toString().trimmed(); checkInternetUrl = QUrl( checkInternetSetting.trimmed() );
if ( m_checkHasInternetUrl.isEmpty() || if ( !checkInternetUrl.isValid() )
!QUrl( m_checkHasInternetUrl ).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)."; << "reverting to default (http://example.com).";
m_checkHasInternetUrl = "http://example.com"; checkInternetUrl = QUrl( "http://example.com" );
incompleteConfiguration = true; incompleteConfiguration = true;
} }
} }
@ -262,10 +264,13 @@ GeneralRequirements::setConfigurationMap( const QVariantMap& configurationMap )
{ {
cWarning() << "GeneralRequirements entry 'internetCheckUrl' is undefined in welcome.conf," cWarning() << "GeneralRequirements entry 'internetCheckUrl' is undefined in welcome.conf,"
"reverting to default (http://example.com)."; "reverting to default (http://example.com).";
checkInternetUrl = "http://example.com";
m_checkHasInternetUrl = "http://example.com";
incompleteConfiguration = true; incompleteConfiguration = true;
} }
if ( checkInternetUrl.isValid() )
{
CalamaresUtils::Network::Manager::instance().setCheckHasInternetUrl( checkInternetUrl );
}
if ( incompleteConfiguration ) if ( incompleteConfiguration )
{ {
@ -357,22 +362,8 @@ GeneralRequirements::checkHasPower()
bool bool
GeneralRequirements::checkHasInternet() GeneralRequirements::checkHasInternet()
{ {
// default to true in the QNetworkAccessManager::UnknownAccessibility case auto& nam = CalamaresUtils::Network::Manager::instance();
QNetworkAccessManager qnam; bool hasInternet = nam.checkHasInternet();
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 ); Calamares::JobQueue::instance()->globalStorage()->insert( "hasInternet", hasInternet );
return hasInternet; return hasInternet;
} }

View File

@ -48,7 +48,6 @@ private:
qreal m_requiredStorageGiB; qreal m_requiredStorageGiB;
qreal m_requiredRamGiB; qreal m_requiredRamGiB;
QString m_checkHasInternetUrl;
}; };
#endif // REQUIREMENTSCHECKER_H #endif // REQUIREMENTSCHECKER_H