From 4b7403d115a485ef679f0e35d09a92dd50316197 Mon Sep 17 00:00:00 2001 From: Adriaan de Groot Date: Thu, 23 Jul 2020 11:11:18 +0200 Subject: [PATCH] [localeq] Re-do with new Config - remove stray and useless TODOs - remove unnecessary empty overrides - clean up includes - drop all the code that is now in Config Since the business logic (setting locations, maintaining GS, ...) is all in the Config object, the ViewStep is remarkably simple: hook up a UI to the Config, which in the case of QML is done automatically. --- src/modules/localeq/LocaleQmlViewStep.cpp | 135 ++-------------------- src/modules/localeq/LocaleQmlViewStep.h | 26 +---- 2 files changed, 11 insertions(+), 150 deletions(-) diff --git a/src/modules/localeq/LocaleQmlViewStep.cpp b/src/modules/localeq/LocaleQmlViewStep.cpp index 4354cb7bd..7891f73fd 100644 --- a/src/modules/localeq/LocaleQmlViewStep.cpp +++ b/src/modules/localeq/LocaleQmlViewStep.cpp @@ -19,30 +19,13 @@ #include "LocaleQmlViewStep.h" -#include "GlobalStorage.h" -#include "JobQueue.h" - -#include "geoip/Handler.h" -#include "network/Manager.h" -#include "utils/CalamaresUtilsGui.h" #include "utils/Logger.h" -#include "utils/Variant.h" -#include "utils/Yaml.h" - -#include "Branding.h" -#include "modulesystem/ModuleManager.h" -#include -#include -#include -#include CALAMARES_PLUGIN_FACTORY_DEFINITION( LocaleQmlViewStepFactory, registerPlugin< LocaleQmlViewStep >(); ) LocaleQmlViewStep::LocaleQmlViewStep( QObject* parent ) -: Calamares::QmlViewStep( parent ) -, m_config( new Config( this ) ) -, m_nextEnabled( false ) -, m_geoip( nullptr ) + : Calamares::QmlViewStep( parent ) + , m_config( std::make_unique< Config >( this ) ) { emit nextStatusChanged( m_nextEnabled ); } @@ -50,43 +33,7 @@ LocaleQmlViewStep::LocaleQmlViewStep( QObject* parent ) QObject* LocaleQmlViewStep::getConfig() { - return m_config; -} - -void -LocaleQmlViewStep::fetchGeoIpTimezone() -{ - if ( m_geoip && m_geoip->isValid() ) - { - m_startingTimezone = m_geoip->get(); - if ( !m_startingTimezone.isValid() ) - { - cWarning() << "GeoIP lookup at" << m_geoip->url() << "failed."; - } - } - - // m_config->setLocaleInfo(m_startingTimezone.first, m_startingTimezone.second, m_localeGenPath); -} - -Calamares::RequirementsList LocaleQmlViewStep::checkRequirements() -{ - 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(); + return m_config.get(); } QString @@ -98,14 +45,12 @@ LocaleQmlViewStep::prettyName() const bool LocaleQmlViewStep::isNextEnabled() const { - // TODO: should return true return true; } bool LocaleQmlViewStep::isBackEnabled() const { - // TODO: should return true (it's weird that you are not allowed to have welcome *after* anything return true; } @@ -113,7 +58,6 @@ LocaleQmlViewStep::isBackEnabled() const bool LocaleQmlViewStep::isAtBeginning() const { - // TODO: adjust to "pages" in the QML return true; } @@ -121,81 +65,18 @@ LocaleQmlViewStep::isAtBeginning() const bool LocaleQmlViewStep::isAtEnd() const { - // TODO: adjust to "pages" in the QML return true; } Calamares::JobList LocaleQmlViewStep::jobs() const { - return m_jobs; + return m_config->createJobs(); } -void LocaleQmlViewStep::onActivate() +void +LocaleQmlViewStep::setConfigurationMap( const QVariantMap& configurationMap ) { - // TODO no sure if it is needed at all or for the abstract class to start something -} - -void LocaleQmlViewStep::onLeave() -{ -#if 0 - if ( true ) - { - m_jobs = m_config->createJobs(); -// m_prettyStatus = m_actualWidget->prettyStatus(); - - auto map = m_config->localesMap(); - QVariantMap vm; - for ( auto it = map.constBegin(); it != map.constEnd(); ++it ) - { - vm.insert( it.key(), it.value() ); - } - - Calamares::JobQueue::instance()->globalStorage()->insert( "localeConf", vm ); - } - else - { - m_jobs.clear(); - Calamares::JobQueue::instance()->globalStorage()->remove( "localeConf" ); - } -#endif -} - -void LocaleQmlViewStep::setConfigurationMap(const QVariantMap& configurationMap) -{ - QString region = CalamaresUtils::getString( configurationMap, "region" ); - QString zone = CalamaresUtils::getString( configurationMap, "zone" ); - if ( !region.isEmpty() && !zone.isEmpty() ) - { - m_startingTimezone = CalamaresUtils::GeoIP::RegionZonePair( region, zone ); - } - else - { - m_startingTimezone - = CalamaresUtils::GeoIP::RegionZonePair( QStringLiteral( "America" ), QStringLiteral( "New_York" ) ); - } - - m_localeGenPath = CalamaresUtils::getString( configurationMap, "localeGenPath" ); - if ( m_localeGenPath.isEmpty() ) - { - m_localeGenPath = QStringLiteral( "/etc/locale.gen" ); - } - - bool ok = false; - QVariantMap geoip = CalamaresUtils::getSubMap( configurationMap, "geoip", ok ); - if ( ok ) - { - 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."; - } - } - - checkRequirements(); - Calamares::QmlViewStep::setConfigurationMap( configurationMap ); // call parent implementation last + m_config->setConfigurationMap( configurationMap ); + Calamares::QmlViewStep::setConfigurationMap( configurationMap ); // call parent implementation last } diff --git a/src/modules/localeq/LocaleQmlViewStep.h b/src/modules/localeq/LocaleQmlViewStep.h index 0639274d6..20689e149 100644 --- a/src/modules/localeq/LocaleQmlViewStep.h +++ b/src/modules/localeq/LocaleQmlViewStep.h @@ -20,14 +20,10 @@ #define LOCALE_QMLVIEWSTEP_H #include "Config.h" -#include "geoip/Handler.h" -#include "geoip/Interface.h" + +#include "DllMacro.h" #include "utils/PluginFactory.h" #include "viewpages/QmlViewStep.h" -#include - -#include -#include #include @@ -47,28 +43,12 @@ public: bool isAtEnd() const override; Calamares::JobList jobs() const override; - void onActivate() override; - void onLeave() override; void setConfigurationMap( const QVariantMap& configurationMap ) override; QObject* getConfig() override; - virtual Calamares::RequirementsList checkRequirements() override; - private: - // TODO: a generic QML viewstep should return a config object from a method - Config *m_config; - - bool m_nextEnabled; - QString m_prettyStatus; - - CalamaresUtils::GeoIP::RegionZonePair m_startingTimezone; - QString m_localeGenPath; - - Calamares::JobList m_jobs; - std::unique_ptr< CalamaresUtils::GeoIP::Handler > m_geoip; - - void fetchGeoIpTimezone(); + std::unique_ptr< Config > m_config; }; CALAMARES_PLUGIN_FACTORY_DECLARATION( LocaleQmlViewStepFactory )