From 9737041e66bb51c7be8ca4dda3bc8b7c09654426 Mon Sep 17 00:00:00 2001 From: Adriaan de Groot Date: Tue, 8 Aug 2017 17:29:44 +0430 Subject: [PATCH] Locale: extend prettyStatus() Add description of language and number formats to pretty status. This is shown in the summary page. Refactor a little to produce the strings only in one place. Constify methods. FIXES: #564 --- src/modules/locale/LocaleConfiguration.cpp | 2 +- src/modules/locale/LocaleConfiguration.h | 2 +- src/modules/locale/LocalePage.cpp | 28 ++++++++++++++++------ src/modules/locale/LocalePage.h | 9 +++++-- 4 files changed, 30 insertions(+), 11 deletions(-) diff --git a/src/modules/locale/LocaleConfiguration.cpp b/src/modules/locale/LocaleConfiguration.cpp index 3631befec..b8f5f6a9e 100644 --- a/src/modules/locale/LocaleConfiguration.cpp +++ b/src/modules/locale/LocaleConfiguration.cpp @@ -272,7 +272,7 @@ LocaleConfiguration::fromLanguageAndLocation( const QString& languageLocale, bool -LocaleConfiguration::isEmpty() +LocaleConfiguration::isEmpty() const { return lang.isEmpty() && lc_numeric.isEmpty() && diff --git a/src/modules/locale/LocaleConfiguration.h b/src/modules/locale/LocaleConfiguration.h index a93ddffac..073d19a5b 100644 --- a/src/modules/locale/LocaleConfiguration.h +++ b/src/modules/locale/LocaleConfiguration.h @@ -33,7 +33,7 @@ public: const QStringList& availableLocales, const QString& countryCode ); - bool isEmpty(); + bool isEmpty() const; // These become all uppercase in locale.conf, but we keep them lowercase here to // avoid confusion with locale.h. diff --git a/src/modules/locale/LocalePage.cpp b/src/modules/locale/LocalePage.cpp index c950b415c..4882b1684 100644 --- a/src/modules/locale/LocalePage.cpp +++ b/src/modules/locale/LocalePage.cpp @@ -233,11 +233,9 @@ LocalePage::updateLocaleLabels() LocaleConfiguration lc = m_selectedLocaleConfiguration.isEmpty() ? guessLocaleConfiguration() : m_selectedLocaleConfiguration; - m_localeLabel->setText( tr( "The system language will be set to %1." ) - .arg( prettyLCLocale( lc.lang ) ) ); - - m_formatsLabel->setText( tr( "The numbers and dates locale will be set to %1." ) - .arg( prettyLCLocale( lc.lc_numeric ) ) ); + auto labels = prettyLocaleStatus( lc ); + m_localeLabel->setText( labels.first ); + m_formatsLabel->setText( labels.second ); } @@ -383,6 +381,15 @@ LocalePage::init( const QString& initialRegion, updateGlobalStorage(); } +std::pair< QString, QString > LocalePage::prettyLocaleStatus( const LocaleConfiguration& lc ) const +{ + return std::make_pair< QString, QString >( + tr( "The system language will be set to %1." ) + .arg( prettyLCLocale( lc.lang ) ), + tr( "The numbers and dates locale will be set to %1." ) + .arg( prettyLCLocale( lc.lc_numeric ) ) + ); +} QString LocalePage::prettyStatus() const @@ -392,6 +399,13 @@ LocalePage::prettyStatus() const .arg( m_regionCombo->currentText() ) .arg( m_zoneCombo->currentText() ); + LocaleConfiguration lc = m_selectedLocaleConfiguration.isEmpty() ? + guessLocaleConfiguration() : + m_selectedLocaleConfiguration; + auto labels = prettyLocaleStatus(lc); + status += labels.first + "
"; + status += labels.second + "
"; + return status; } @@ -433,7 +447,7 @@ LocalePage::onActivate() LocaleConfiguration -LocalePage::guessLocaleConfiguration() +LocalePage::guessLocaleConfiguration() const { QLocale myLocale; // User-selected language @@ -455,7 +469,7 @@ LocalePage::guessLocaleConfiguration() QString -LocalePage::prettyLCLocale( const QString& lcLocale ) +LocalePage::prettyLCLocale( const QString& lcLocale ) const { QString localeString = lcLocale; if ( localeString.endsWith( " UTF-8" ) ) diff --git a/src/modules/locale/LocalePage.h b/src/modules/locale/LocalePage.h index 3615016e5..27a7362e3 100644 --- a/src/modules/locale/LocalePage.h +++ b/src/modules/locale/LocalePage.h @@ -50,8 +50,13 @@ public: void onActivate(); private: - LocaleConfiguration guessLocaleConfiguration(); - QString prettyLCLocale( const QString& localesMap ); + LocaleConfiguration guessLocaleConfiguration() const; + QString prettyLCLocale( const QString& localesMap ) const; + + // For the given locale config, return two strings describing + // the settings for language and numbers. + std::pair< QString, QString > prettyLocaleStatus( const LocaleConfiguration& ) const; + void updateGlobalStorage(); void updateLocaleLabels();