[locale] Move status strings from Page to Config

- the config knows the status and how to describe it,
  fetch the strings from there.
This commit is contained in:
Adriaan de Groot 2020-07-21 15:51:49 +02:00
parent 855b21a7db
commit ef08ff6ac0
5 changed files with 43 additions and 34 deletions

View File

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

View File

@ -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 <br/>
*/
QString prettyStatus() const;
public Q_SLOTS:
const QStringList& supportedLocales() const { return m_localeGenLines; }
CalamaresUtils::Locale::CStringListModel* regionModel() const { return m_regionModel.get(); }

View File

@ -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.<br/>" ).arg( m_regionCombo->currentText() ).arg( m_zoneCombo->currentText() );
LocaleConfiguration lc = m_config->localeConfiguration();
auto labels = prettyLocaleStatus( lc );
status += labels.first + "<br/>";
status += labels.second + "<br/>";
return status;
}
void
LocalePage::onActivate()

View File

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

View File

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