From 11d3f10e26cb75f2bb9e49537c3d79ee12261e6f Mon Sep 17 00:00:00 2001 From: Adriaan de Groot Date: Tue, 10 Sep 2019 14:18:47 +0200 Subject: [PATCH] [locale] Dispose of waiting widget - Do the async GeoIP checking in the async requirements-checking phase - Do not return any requirements results -- we just need the async bit - Drop the waiting widget, since it's not needed (done by the requirements phase) --- src/modules/locale/LocaleViewStep.cpp | 43 +++++++++++++++++---------- src/modules/locale/LocaleViewStep.h | 5 ++-- 2 files changed, 30 insertions(+), 18 deletions(-) diff --git a/src/modules/locale/LocaleViewStep.cpp b/src/modules/locale/LocaleViewStep.cpp index 89baf23c2..4acfcb2de 100644 --- a/src/modules/locale/LocaleViewStep.cpp +++ b/src/modules/locale/LocaleViewStep.cpp @@ -27,7 +27,7 @@ #include "JobQueue.h" #include "geoip/Handler.h" - +#include "network/Manager.h" #include "utils/CalamaresUtilsGui.h" #include "utils/Logger.h" #include "utils/Variant.h" @@ -43,7 +43,6 @@ CALAMARES_PLUGIN_FACTORY_DEFINITION( LocaleViewStepFactory, registerPlugin< Loca LocaleViewStep::LocaleViewStep( QObject* parent ) : Calamares::ViewStep( parent ) , m_widget( new QWidget() ) - , m_waitingWidget( nullptr ) , m_actualWidget( nullptr ) , m_nextEnabled( false ) , m_geoip( nullptr ) @@ -68,12 +67,6 @@ LocaleViewStep::~LocaleViewStep() void LocaleViewStep::setUpPage() { - if ( m_waitingWidget ) - { - m_widget->layout()->removeWidget( m_waitingWidget ); - m_waitingWidget->deleteLater(); - } - if ( !m_actualWidget ) { m_actualWidget = new LocalePage(); @@ -117,12 +110,6 @@ LocaleViewStep::prettyStatus() const QWidget* LocaleViewStep::widget() { - // If none of the inner widgets is already created, create the spinner - if ( !m_actualWidget && !m_waitingWidget ) - { - m_waitingWidget = new WaitingWidget( tr( "Loading location data..." ) ); - m_widget->layout()->addWidget( m_waitingWidget ); - } return m_widget; } @@ -165,10 +152,11 @@ LocaleViewStep::jobs() const void LocaleViewStep::onActivate() { - if ( m_actualWidget ) + if ( !m_actualWidget ) { - m_actualWidget->onActivate(); + setUpPage(); } + m_actualWidget->onActivate(); } @@ -235,3 +223,26 @@ LocaleViewStep::setConfigurationMap( const QVariantMap& configurationMap ) } } } + +Calamares::RequirementsList +LocaleViewStep::checkRequirements() +{ + LocaleGlobal::init(); + if ( m_geoip && m_geoip->isValid() ) + { + auto& network = CalamaresUtils::Network::Manager::instance(); + if ( network.hasInternet() ) + { + fetchGeoIpTimezone(); + } + else + { + if ( network.synchronousPing( m_geoip->url() ) ) + { + fetchGeoIpTimezone(); + } + } + } + + return Calamares::RequirementsList(); +} diff --git a/src/modules/locale/LocaleViewStep.h b/src/modules/locale/LocaleViewStep.h index a6c28d78d..0bb0e34a6 100644 --- a/src/modules/locale/LocaleViewStep.h +++ b/src/modules/locale/LocaleViewStep.h @@ -61,14 +61,15 @@ public: void setConfigurationMap( const QVariantMap& configurationMap ) override; + /// @brief Do setup (returns empty list) asynchronously + virtual Calamares::RequirementsList checkRequirements(); + private slots: void setUpPage(); private: void fetchGeoIpTimezone(); QWidget* m_widget; - QFutureWatcher< void > m_initWatcher; - WaitingWidget* m_waitingWidget; LocalePage* m_actualWidget; bool m_nextEnabled;