diff --git a/src/modules/locale/Config.cpp b/src/modules/locale/Config.cpp index cdd4e767f..5fa8b3c8b 100644 --- a/src/modules/locale/Config.cpp +++ b/src/modules/locale/Config.cpp @@ -22,6 +22,9 @@ #include "SetTimezoneJob.h" +#include "GlobalStorage.h" +#include "JobQueue.h" +#include "Settings.h" #include "locale/Label.h" #include "utils/Logger.h" #include "utils/Variant.h" @@ -154,6 +157,36 @@ Config::Config( QObject* parent ) , m_regionModel( std::make_unique< CalamaresUtils::Locale::CStringListModel >( ::timezoneData() ) ) , m_zonesModel( std::make_unique< CalamaresUtils::Locale::CStringListModel >() ) { + // Slightly unusual: connect to our *own* signals. Wherever the language + // or the location is changed, these signals are emitted, so hook up to + // them to update global storage accordingly. This simplifies code: + // we don't need to call an update-GS method, or introduce an intermediate + // update-thing-and-GS method. And everywhere where we **do** change + // language or location, we already emit the signal. + connect( this, &Config::currentLanguageStatusChanged, [&]() { + auto* gs = Calamares::JobQueue::instance()->globalStorage(); + gs->insert( "locale", m_selectedLocaleConfiguration.toBcp47() ); + } ); + + connect( this, &Config::currentLocationChanged, [&]() { + auto* gs = Calamares::JobQueue::instance()->globalStorage(); + 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 we're in chroot mode (normal install mode), then we immediately set the + // timezone on the live system. When debugging timezones, don't bother. +#ifndef DEBUG_TIMEZONES + if ( locationChanged && Calamares::Settings::instance()->doChroot() ) + { + QProcess::execute( "timedatectl", // depends on systemd + { "set-timezone", location->region() + '/' + location->zone() } ); + } +#endif + } ); } Config::~Config() {} diff --git a/src/modules/locale/LocalePage.cpp b/src/modules/locale/LocalePage.cpp index c312f39f6..0ea56a072 100644 --- a/src/modules/locale/LocalePage.cpp +++ b/src/modules/locale/LocalePage.cpp @@ -125,7 +125,6 @@ LocalePage::LocalePage( Config* config, QWidget* parent ) m_regionCombo->setModel( m_config->regionModel() ); m_regionCombo->currentIndexChanged( m_regionCombo->currentIndex() ); - updateGlobalStorage(); } @@ -148,47 +147,10 @@ void LocalePage::onActivate() { m_regionCombo->setFocus(); - updateGlobalLocale(); updateLocaleLabels(); } -void -LocalePage::updateGlobalLocale() -{ - auto* gs = Calamares::JobQueue::instance()->globalStorage(); - const QString bcp47 = m_config->localeConfiguration().toBcp47(); - gs->insert( "locale", bcp47 ); -} - - -void -LocalePage::updateGlobalStorage() -{ - auto* gs = Calamares::JobQueue::instance()->globalStorage(); - - const auto* location = m_config->currentLocation(); - bool locationChanged = ( location->region() != gs->value( "locationRegion" ) ) - || ( location->zone() != gs->value( "locationZone" ) ); - - gs->insert( "locationRegion", location->region() ); - gs->insert( "locationZone", location->zone() ); - - updateGlobalLocale(); - - // If we're in chroot mode (normal install mode), then we immediately set the - // timezone on the live system. When debugging timezones, don't bother. -#ifndef DEBUG_TIMEZONES - if ( locationChanged && Calamares::Settings::instance()->doChroot() ) - { - QProcess::execute( "timedatectl", // depends on systemd - { "set-timezone", location->region() + '/' + location->zone() } ); - } -#endif - - updateLocaleLabels(); -} - void LocalePage::regionChanged( int currentIndex ) { @@ -219,7 +181,6 @@ LocalePage::zoneChanged( int currentIndex ) { m_config->setCurrentLocation( m_regionCombo->currentData().toString(), m_zoneCombo->currentData().toString() ); } - updateGlobalStorage(); } void @@ -244,8 +205,6 @@ LocalePage::locationChanged( const CalamaresUtils::Locale::TZZone* location ) } m_zoneCombo->setCurrentIndex( index ); - - updateGlobalStorage(); } void @@ -257,7 +216,6 @@ LocalePage::changeLocale() if ( dlg && dlg->result() == QDialog::Accepted && !dlg->selectedLCLocale().isEmpty() ) { m_config->setLanguageExplicitly( dlg->selectedLCLocale() ); - updateGlobalLocale(); updateLocaleLabels(); } diff --git a/src/modules/locale/LocalePage.h b/src/modules/locale/LocalePage.h index b40aeb465..bf41f8f69 100644 --- a/src/modules/locale/LocalePage.h +++ b/src/modules/locale/LocalePage.h @@ -49,13 +49,6 @@ private: /// @brief Non-owning pointer to the ViewStep's config Config* m_config; - /** @brief Update the GS *locale* key with the selected system language. - * - * This uses whatever is set in m_selectedLocaleConfiguration as the language, - * and writes it to GS *locale* key (as a string, in BCP47 format). - */ - void updateGlobalLocale(); - void updateGlobalStorage(); void updateLocaleLabels(); void regionChanged( int currentIndex );