[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.
This commit is contained in:
parent
d90d451f42
commit
4b7403d115
@ -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 <QQmlEngine>
|
||||
#include <QFutureWatcher>
|
||||
#include <QPixmap>
|
||||
#include <QVariant>
|
||||
|
||||
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();
|
||||
m_config->setConfigurationMap( configurationMap );
|
||||
Calamares::QmlViewStep::setConfigurationMap( configurationMap ); // call parent implementation last
|
||||
}
|
||||
|
@ -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 <DllMacro.h>
|
||||
|
||||
#include <QFutureWatcher>
|
||||
#include <QObject>
|
||||
|
||||
#include <memory>
|
||||
|
||||
@ -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 )
|
||||
|
Loading…
Reference in New Issue
Block a user