diff --git a/src/modules/locale/LocaleViewStep.cpp b/src/modules/locale/LocaleViewStep.cpp index a9b9da456..bbd2d07a1 100644 --- a/src/modules/locale/LocaleViewStep.cpp +++ b/src/modules/locale/LocaleViewStep.cpp @@ -45,6 +45,7 @@ LocaleViewStep::LocaleViewStep( QObject* parent ) , m_widget( new QWidget() ) , m_actualWidget( new LocalePage() ) , m_nextEnabled( false ) + , m_geoip( nullptr ) { QBoxLayout* mainLayout = new QHBoxLayout; m_widget->setLayout( mainLayout ); @@ -55,8 +56,10 @@ LocaleViewStep::LocaleViewStep( QObject* parent ) connect( &m_initWatcher, &QFutureWatcher< void >::finished, this, [=] { bool hasInternet = Calamares::JobQueue::instance()->globalStorage()->value( "hasInternet" ).toBool(); - if ( m_geoipUrl.isEmpty() || !hasInternet ) + if ( !m_geoip || !hasInternet ) + { setUpPage(); + } else { fetchGeoIpTimezone(); @@ -65,8 +68,10 @@ LocaleViewStep::LocaleViewStep( QObject* parent ) QFuture< void > initFuture = QtConcurrent::run( [=] { LocaleGlobal::init(); - if ( m_geoipUrl.isEmpty() ) + if ( !m_geoip ) + { return; + } Calamares::GlobalStorage* gs = Calamares::JobQueue::instance()->globalStorage(); @@ -109,19 +114,14 @@ LocaleViewStep::setUpPage() void LocaleViewStep::fetchGeoIpTimezone() { - CalamaresUtils::GeoIP::Handler h( m_geoipStyle, m_geoipUrl, m_geoipSelector ); - if ( h.isValid() ) + if ( m_geoip && m_geoip->isValid() ) { - m_startingTimezone = h.get(); + m_startingTimezone = m_geoip->get(); if ( !m_startingTimezone.isValid() ) { - cWarning() << "GeoIP lookup at" << m_geoipUrl << "failed."; + cWarning() << "GeoIP lookup at" << m_geoip->url() << "failed."; } } - else - { - cWarning() << "GeoIP Style" << m_geoipStyle << "is not recognized."; - } setUpPage(); } @@ -233,8 +233,14 @@ LocaleViewStep::setConfigurationMap( const QVariantMap& configurationMap ) QVariantMap geoip = CalamaresUtils::getSubMap( configurationMap, "geoip", ok ); if ( ok ) { - m_geoipUrl = CalamaresUtils::getString( geoip, "url" ); - m_geoipStyle = CalamaresUtils::getString( geoip, "style" ); - m_geoipSelector = CalamaresUtils::getString( geoip, "selector" ); + QString url = CalamaresUtils::getString( geoip, "url" ); + QString style = CalamaresUtils::getString( geoip, "style" ); + QString selector = CalamaresUtils::getString( geoip, "selector" ); + + m_geoip = std::make_unique< CalamaresUtils::GeoIP::Handler >( style, url, selector ); + if ( !m_geoip->isValid() ) + { + cWarning() << "GeoIP Style" << style << "is not recognized."; + } } } diff --git a/src/modules/locale/LocaleViewStep.h b/src/modules/locale/LocaleViewStep.h index b04b34651..a6c28d78d 100644 --- a/src/modules/locale/LocaleViewStep.h +++ b/src/modules/locale/LocaleViewStep.h @@ -20,6 +20,7 @@ #ifndef LOCALEVIEWSTEP_H #define LOCALEVIEWSTEP_H +#include "geoip/Handler.h" #include "geoip/Interface.h" #include "utils/PluginFactory.h" #include "viewpages/ViewStep.h" @@ -29,6 +30,8 @@ #include #include +#include + class LocalePage; class WaitingWidget; @@ -74,11 +77,8 @@ private: CalamaresUtils::GeoIP::RegionZonePair m_startingTimezone; QString m_localeGenPath; - QString m_geoipUrl; // The URL, depening on style might be modified on lookup - QString m_geoipStyle; // String selecting which kind of geoip data to expect - QString m_geoipSelector; // String selecting data from the geoip lookup - QList< Calamares::job_ptr > m_jobs; + std::unique_ptr< CalamaresUtils::GeoIP::Handler > m_geoip; }; CALAMARES_PLUGIN_FACTORY_DECLARATION( LocaleViewStepFactory )