[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 "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;
}

View File

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