diff --git a/src/modules/locale/Config.cpp b/src/modules/locale/Config.cpp index 228f863e5..5bbe20038 100644 --- a/src/modules/locale/Config.cpp +++ b/src/modules/locale/Config.cpp @@ -148,6 +148,45 @@ loadLocales( const QString& localeGenPath ) return localeGenLines; } +static bool +updateGSLocation( Calamares::GlobalStorage* gs, const CalamaresUtils::Locale::TimeZoneData* location ) +{ + const QString regionKey = QStringLiteral( "locationRegion" ); + const QString zoneKey = QStringLiteral( "locationZone" ); + + if ( !location ) + { + if ( gs->contains( regionKey ) || gs->contains( zoneKey ) ) + { + gs->remove( regionKey ); + gs->remove( zoneKey ); + return true; + } + return false; + } + + // Update the GS region and zone (and possibly the live timezone) + bool locationChanged + = ( location->region() != gs->value( regionKey ) ) || ( location->zone() != gs->value( zoneKey ) ); + + gs->insert( regionKey, location->region() ); + gs->insert( zoneKey, location->zone() ); + + return locationChanged; +} + +static void +updateGSLocale( Calamares::GlobalStorage* gs, const LocaleConfiguration& locale ) +{ + auto map = locale.toMap(); + QVariantMap vm; + for ( auto it = map.constBegin(); it != map.constEnd(); ++it ) + { + vm.insert( it.key(), it.value() ); + } + gs->insert( "localeConf", vm ); +} + Config::Config( QObject* parent ) : QObject( parent ) , m_regionModel( std::make_unique< CalamaresUtils::Locale::RegionsModel >() ) @@ -166,31 +205,17 @@ Config::Config( QObject* parent ) } ); connect( this, &Config::currentLCCodeChanged, [&]() { - auto* gs = Calamares::JobQueue::instance()->globalStorage(); - // Update GS localeConf (the LC_ variables) - auto map = localeConfiguration().toMap(); - QVariantMap vm; - for ( auto it = map.constBegin(); it != map.constEnd(); ++it ) - { - vm.insert( it.key(), it.value() ); - } - gs->insert( "localeConf", vm ); + updateGSLocale( Calamares::JobQueue::instance()->globalStorage(), localeConfiguration() ); } ); connect( this, &Config::currentLocationChanged, [&]() { - auto* gs = Calamares::JobQueue::instance()->globalStorage(); + const bool locationChanged + = updateGSLocation( Calamares::JobQueue::instance()->globalStorage(), currentLocation() ); - // Update the GS region and zone (and possibly the live timezone) - const auto* location = currentLocation(); - bool locationChanged = ( location->region() != gs->value( "locationRegion" ) ) - || ( location->zone() != gs->value( "locationZone" ) ); - - gs->insert( "locationRegion", location->region() ); - gs->insert( "locationZone", location->zone() ); if ( locationChanged && m_adjustLiveTimezone ) { QProcess::execute( "timedatectl", // depends on systemd - { "set-timezone", location->region() + '/' + location->zone() } ); + { "set-timezone", currentTimezoneCode() } ); } emit currentTimezoneCodeChanged( currentTimezoneCode() ); @@ -487,6 +512,15 @@ Config::createJobs() return list; } +void +Config::finalizeGlobalStorage() const +{ + auto* gs = Calamares::JobQueue::instance()->globalStorage(); + updateGSLocale( gs, localeConfiguration() ); + updateGSLocation( gs, currentLocation() ); +} + + void Config::startGeoIP() { diff --git a/src/modules/locale/Config.h b/src/modules/locale/Config.h index 2a44f4d24..d95606d99 100644 --- a/src/modules/locale/Config.h +++ b/src/modules/locale/Config.h @@ -66,6 +66,7 @@ public: ~Config(); void setConfigurationMap( const QVariantMap& ); + void finalizeGlobalStorage() const; Calamares::JobList createJobs(); /// locale configuration (LC_* and LANG) based solely on the current location. diff --git a/src/modules/locale/LocaleViewStep.cpp b/src/modules/locale/LocaleViewStep.cpp index a85c87e4f..9ffb96c25 100644 --- a/src/modules/locale/LocaleViewStep.cpp +++ b/src/modules/locale/LocaleViewStep.cpp @@ -138,6 +138,7 @@ LocaleViewStep::jobs() const void LocaleViewStep::onActivate() { + m_config->setCurrentLocation(); // Finalize the location if ( !m_actualWidget ) { setUpPage(); @@ -149,6 +150,7 @@ LocaleViewStep::onActivate() void LocaleViewStep::onLeave() { + m_config->finalizeGlobalStorage(); } diff --git a/src/modules/localeq/LocaleQmlViewStep.cpp b/src/modules/localeq/LocaleQmlViewStep.cpp index cbcc5f78e..d60664a8f 100644 --- a/src/modules/localeq/LocaleQmlViewStep.cpp +++ b/src/modules/localeq/LocaleQmlViewStep.cpp @@ -86,6 +86,12 @@ LocaleQmlViewStep::onActivate() QmlViewStep::onActivate(); } +void +LocaleQmlViewStep::onLeave() +{ + m_config->finalizeGlobalStorage(); +} + void LocaleQmlViewStep::setConfigurationMap( const QVariantMap& configurationMap ) { diff --git a/src/modules/localeq/LocaleQmlViewStep.h b/src/modules/localeq/LocaleQmlViewStep.h index e2b8a9e13..bbafd5abb 100644 --- a/src/modules/localeq/LocaleQmlViewStep.h +++ b/src/modules/localeq/LocaleQmlViewStep.h @@ -44,6 +44,7 @@ public: bool isAtEnd() const override; virtual void onActivate() override; + virtual void onLeave() override; Calamares::JobList jobs() const override;