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
This commit is contained in:
Adriaan de Groot 2017-08-08 17:29:44 +04:30
parent a718eb76cb
commit 9737041e66
4 changed files with 30 additions and 11 deletions

View File

@ -272,7 +272,7 @@ LocaleConfiguration::fromLanguageAndLocation( const QString& languageLocale,
bool
LocaleConfiguration::isEmpty()
LocaleConfiguration::isEmpty() const
{
return lang.isEmpty() &&
lc_numeric.isEmpty() &&

View File

@ -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.

View File

@ -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 + "<br/>";
status += labels.second + "<br/>";
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" ) )

View File

@ -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();