From ef08ff6ac09cb3f10937a6001f2dd08d6c198980 Mon Sep 17 00:00:00 2001 From: Adriaan de Groot Date: Tue, 21 Jul 2020 15:51:49 +0200 Subject: [PATCH] [locale] Move status strings from Page to Config - the config knows the status and how to describe it, fetch the strings from there. --- src/modules/locale/Config.cpp | 28 +++++++++++++++++++++++++++ src/modules/locale/Config.h | 13 +++++++++++++ src/modules/locale/LocalePage.cpp | 28 +-------------------------- src/modules/locale/LocalePage.h | 6 ------ src/modules/locale/LocaleViewStep.cpp | 2 +- 5 files changed, 43 insertions(+), 34 deletions(-) diff --git a/src/modules/locale/Config.cpp b/src/modules/locale/Config.cpp index c19569d43..8893d387a 100644 --- a/src/modules/locale/Config.cpp +++ b/src/modules/locale/Config.cpp @@ -22,6 +22,7 @@ #include "SetTimezoneJob.h" +#include "locale/Label.h" #include "utils/Logger.h" #include "utils/Variant.h" @@ -245,6 +246,33 @@ Config::setLCLocaleExplicitly( const QString& locale ) m_selectedLocaleConfiguration.explicit_lc = true; } +std::pair< QString, QString > +Config::prettyLocaleStatus() const +{ + using CalamaresUtils::Locale::Label; + + Label lang( m_selectedLocaleConfiguration.language(), Label::LabelFormat::AlwaysWithCountry ); + Label num( m_selectedLocaleConfiguration.lc_numeric, Label::LabelFormat::AlwaysWithCountry ); + + return std::make_pair< QString, QString >( + tr( "The system language will be set to %1." ).arg( lang.label() ), + tr( "The numbers and dates locale will be set to %1." ).arg( num.label() ) ); +} + +QString +Config::prettyStatus() const +{ + QString br( QStringLiteral("
")); + QString status; + status += tr( "Set timezone to %1/%2." ).arg( m_currentLocation->region(), m_currentLocation->zone() ) + br; + + auto labels = prettyLocaleStatus(); + status += labels.first + br; + status += labels.second + br; + + return status; +} + void Config::setConfigurationMap( const QVariantMap& configurationMap ) diff --git a/src/modules/locale/Config.h b/src/modules/locale/Config.h index ff9125c13..91ed8f1be 100644 --- a/src/modules/locale/Config.h +++ b/src/modules/locale/Config.h @@ -47,6 +47,19 @@ public: void setConfigurationMap( const QVariantMap& ); Calamares::JobList createJobs(); + /** @brief Human-readable status for language and LC + * + * For the current locale config, return two strings describing + * the settings for language and numbers. + */ + std::pair< QString, QString > prettyLocaleStatus() const; + /** @brief Human-readable zone, language and LC status + * + * Concatenates all three strings with
+ */ + QString prettyStatus() const; + + public Q_SLOTS: const QStringList& supportedLocales() const { return m_localeGenLines; } CalamaresUtils::Locale::CStringListModel* regionModel() const { return m_regionModel.get(); } diff --git a/src/modules/locale/LocalePage.cpp b/src/modules/locale/LocalePage.cpp index 58ea4a81c..fb3433d23 100644 --- a/src/modules/locale/LocalePage.cpp +++ b/src/modules/locale/LocalePage.cpp @@ -138,38 +138,12 @@ LocalePage::updateLocaleLabels() m_localeChangeButton->setText( tr( "&Change..." ) ); m_formatsChangeButton->setText( tr( "&Change..." ) ); - LocaleConfiguration lc = m_config->localeConfiguration(); - auto labels = prettyLocaleStatus( lc ); + auto labels = m_config->prettyLocaleStatus(); m_localeLabel->setText( labels.first ); m_formatsLabel->setText( labels.second ); } -std::pair< QString, QString > -LocalePage::prettyLocaleStatus( const LocaleConfiguration& lc ) const -{ - using CalamaresUtils::Locale::Label; - Label lang( lc.language(), Label::LabelFormat::AlwaysWithCountry ); - Label num( lc.lc_numeric, Label::LabelFormat::AlwaysWithCountry ); - - return std::make_pair< QString, QString >( - tr( "The system language will be set to %1." ).arg( lang.label() ), - tr( "The numbers and dates locale will be set to %1." ).arg( num.label() ) ); -} - -QString -LocalePage::prettyStatus() const -{ - QString status; - status += tr( "Set timezone to %1/%2.
" ).arg( m_regionCombo->currentText() ).arg( m_zoneCombo->currentText() ); - - LocaleConfiguration lc = m_config->localeConfiguration(); - auto labels = prettyLocaleStatus( lc ); - status += labels.first + "
"; - status += labels.second + "
"; - - return status; -} void LocalePage::onActivate() diff --git a/src/modules/locale/LocalePage.h b/src/modules/locale/LocalePage.h index 3a4dd93a9..b40aeb465 100644 --- a/src/modules/locale/LocalePage.h +++ b/src/modules/locale/LocalePage.h @@ -43,18 +43,12 @@ public: explicit LocalePage( class Config* config, QWidget* parent = nullptr ); virtual ~LocalePage(); - QString prettyStatus() const; - void onActivate(); private: /// @brief Non-owning pointer to the ViewStep's config Config* m_config; - // For the given locale config, return two strings describing - // the settings for language and numbers. - std::pair< QString, QString > prettyLocaleStatus( const LocaleConfiguration& ) const; - /** @brief Update the GS *locale* key with the selected system language. * * This uses whatever is set in m_selectedLocaleConfiguration as the language, diff --git a/src/modules/locale/LocaleViewStep.cpp b/src/modules/locale/LocaleViewStep.cpp index c7ed8766b..00752ebb6 100644 --- a/src/modules/locale/LocaleViewStep.cpp +++ b/src/modules/locale/LocaleViewStep.cpp @@ -167,7 +167,7 @@ LocaleViewStep::onLeave() if ( m_actualWidget ) { m_jobs = m_config->createJobs(); - m_prettyStatus = m_actualWidget->prettyStatus(); + m_prettyStatus = m_config->prettyStatus(); auto map = m_config->localeConfiguration().toMap(); QVariantMap vm;