mirror of
https://github.com/parchlinux/calamares.git
synced 2025-06-30 10:55:37 -04:00
[locale] Move the GS updating to the Config object
- since all locale changes need to be entered into GS anyway, this is something the Config object can do because it is the source of truth for locale settings. - drop all the GS settings from the Page.
This commit is contained in:
parent
f7c2e4a3e7
commit
1de2210d29
3 changed files with 33 additions and 49 deletions
|
@ -22,6 +22,9 @@
|
||||||
|
|
||||||
#include "SetTimezoneJob.h"
|
#include "SetTimezoneJob.h"
|
||||||
|
|
||||||
|
#include "GlobalStorage.h"
|
||||||
|
#include "JobQueue.h"
|
||||||
|
#include "Settings.h"
|
||||||
#include "locale/Label.h"
|
#include "locale/Label.h"
|
||||||
#include "utils/Logger.h"
|
#include "utils/Logger.h"
|
||||||
#include "utils/Variant.h"
|
#include "utils/Variant.h"
|
||||||
|
@ -154,6 +157,36 @@ Config::Config( QObject* parent )
|
||||||
, m_regionModel( std::make_unique< CalamaresUtils::Locale::CStringListModel >( ::timezoneData() ) )
|
, m_regionModel( std::make_unique< CalamaresUtils::Locale::CStringListModel >( ::timezoneData() ) )
|
||||||
, m_zonesModel( std::make_unique< CalamaresUtils::Locale::CStringListModel >() )
|
, 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() {}
|
Config::~Config() {}
|
||||||
|
|
|
@ -125,7 +125,6 @@ LocalePage::LocalePage( Config* config, QWidget* parent )
|
||||||
|
|
||||||
m_regionCombo->setModel( m_config->regionModel() );
|
m_regionCombo->setModel( m_config->regionModel() );
|
||||||
m_regionCombo->currentIndexChanged( m_regionCombo->currentIndex() );
|
m_regionCombo->currentIndexChanged( m_regionCombo->currentIndex() );
|
||||||
updateGlobalStorage();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -148,47 +147,10 @@ void
|
||||||
LocalePage::onActivate()
|
LocalePage::onActivate()
|
||||||
{
|
{
|
||||||
m_regionCombo->setFocus();
|
m_regionCombo->setFocus();
|
||||||
updateGlobalLocale();
|
|
||||||
updateLocaleLabels();
|
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
|
void
|
||||||
LocalePage::regionChanged( int currentIndex )
|
LocalePage::regionChanged( int currentIndex )
|
||||||
{
|
{
|
||||||
|
@ -219,7 +181,6 @@ LocalePage::zoneChanged( int currentIndex )
|
||||||
{
|
{
|
||||||
m_config->setCurrentLocation( m_regionCombo->currentData().toString(), m_zoneCombo->currentData().toString() );
|
m_config->setCurrentLocation( m_regionCombo->currentData().toString(), m_zoneCombo->currentData().toString() );
|
||||||
}
|
}
|
||||||
updateGlobalStorage();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
|
@ -244,8 +205,6 @@ LocalePage::locationChanged( const CalamaresUtils::Locale::TZZone* location )
|
||||||
}
|
}
|
||||||
|
|
||||||
m_zoneCombo->setCurrentIndex( index );
|
m_zoneCombo->setCurrentIndex( index );
|
||||||
|
|
||||||
updateGlobalStorage();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
|
@ -257,7 +216,6 @@ LocalePage::changeLocale()
|
||||||
if ( dlg && dlg->result() == QDialog::Accepted && !dlg->selectedLCLocale().isEmpty() )
|
if ( dlg && dlg->result() == QDialog::Accepted && !dlg->selectedLCLocale().isEmpty() )
|
||||||
{
|
{
|
||||||
m_config->setLanguageExplicitly( dlg->selectedLCLocale() );
|
m_config->setLanguageExplicitly( dlg->selectedLCLocale() );
|
||||||
updateGlobalLocale();
|
|
||||||
updateLocaleLabels();
|
updateLocaleLabels();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -49,13 +49,6 @@ private:
|
||||||
/// @brief Non-owning pointer to the ViewStep's config
|
/// @brief Non-owning pointer to the ViewStep's config
|
||||||
Config* m_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 updateLocaleLabels();
|
||||||
|
|
||||||
void regionChanged( int currentIndex );
|
void regionChanged( int currentIndex );
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue