[locale] Sanitize Config signals and slots
- remove the weirdly-structured prettyStatus and similar: the Config object has human-readable status strings (three, for location, language, and LC-formats) which can be normal properties with signals. - Implement prettyStatus in the view step by querying the Config.
This commit is contained in:
parent
ef08ff6ac0
commit
f7c2e4a3e7
@ -192,6 +192,7 @@ Config::setCurrentLocation( const CalamaresUtils::Locale::TZZone* location )
|
|||||||
if ( !m_selectedLocaleConfiguration.explicit_lang )
|
if ( !m_selectedLocaleConfiguration.explicit_lang )
|
||||||
{
|
{
|
||||||
m_selectedLocaleConfiguration.setLanguage( newLocale.language() );
|
m_selectedLocaleConfiguration.setLanguage( newLocale.language() );
|
||||||
|
emit currentLanguageStatusChanged( currentLanguageStatus() );
|
||||||
}
|
}
|
||||||
if ( !m_selectedLocaleConfiguration.explicit_lc )
|
if ( !m_selectedLocaleConfiguration.explicit_lc )
|
||||||
{
|
{
|
||||||
@ -204,6 +205,8 @@ Config::setCurrentLocation( const CalamaresUtils::Locale::TZZone* location )
|
|||||||
m_selectedLocaleConfiguration.lc_telephone = newLocale.lc_telephone;
|
m_selectedLocaleConfiguration.lc_telephone = newLocale.lc_telephone;
|
||||||
m_selectedLocaleConfiguration.lc_measurement = newLocale.lc_measurement;
|
m_selectedLocaleConfiguration.lc_measurement = newLocale.lc_measurement;
|
||||||
m_selectedLocaleConfiguration.lc_identification = newLocale.lc_identification;
|
m_selectedLocaleConfiguration.lc_identification = newLocale.lc_identification;
|
||||||
|
|
||||||
|
emit currentLCStatusChanged( currentLCStatus() );
|
||||||
}
|
}
|
||||||
emit currentLocationChanged( m_currentLocation );
|
emit currentLocationChanged( m_currentLocation );
|
||||||
}
|
}
|
||||||
@ -228,6 +231,8 @@ Config::setLanguageExplicitly( const QString& language )
|
|||||||
{
|
{
|
||||||
m_selectedLocaleConfiguration.setLanguage( language );
|
m_selectedLocaleConfiguration.setLanguage( language );
|
||||||
m_selectedLocaleConfiguration.explicit_lang = true;
|
m_selectedLocaleConfiguration.explicit_lang = true;
|
||||||
|
|
||||||
|
emit currentLanguageStatusChanged( currentLanguageStatus() );
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
@ -244,33 +249,37 @@ Config::setLCLocaleExplicitly( const QString& locale )
|
|||||||
m_selectedLocaleConfiguration.lc_measurement = locale;
|
m_selectedLocaleConfiguration.lc_measurement = locale;
|
||||||
m_selectedLocaleConfiguration.lc_identification = locale;
|
m_selectedLocaleConfiguration.lc_identification = locale;
|
||||||
m_selectedLocaleConfiguration.explicit_lc = true;
|
m_selectedLocaleConfiguration.explicit_lc = true;
|
||||||
}
|
|
||||||
|
|
||||||
std::pair< QString, QString >
|
emit currentLCStatusChanged( currentLCStatus() );
|
||||||
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
|
QString
|
||||||
Config::prettyStatus() const
|
Config::currentLocationStatus() const
|
||||||
{
|
{
|
||||||
QString br( QStringLiteral("<br/>"));
|
return tr( "Set timezone to %1/%2." ).arg( m_currentLocation->region(), m_currentLocation->zone() );
|
||||||
QString status;
|
}
|
||||||
status += tr( "Set timezone to %1/%2." ).arg( m_currentLocation->region(), m_currentLocation->zone() ) + br;
|
|
||||||
|
|
||||||
auto labels = prettyLocaleStatus();
|
static inline QString
|
||||||
status += labels.first + br;
|
localeLabel( const QString& s )
|
||||||
status += labels.second + br;
|
{
|
||||||
|
using CalamaresUtils::Locale::Label;
|
||||||
|
|
||||||
return status;
|
Label lang( s, Label::LabelFormat::AlwaysWithCountry );
|
||||||
|
return lang.label();
|
||||||
|
}
|
||||||
|
|
||||||
|
QString
|
||||||
|
Config::currentLanguageStatus() const
|
||||||
|
{
|
||||||
|
return tr( "The system language will be set to %1." )
|
||||||
|
.arg( localeLabel( m_selectedLocaleConfiguration.language() ) );
|
||||||
|
}
|
||||||
|
|
||||||
|
QString
|
||||||
|
Config::currentLCStatus() const
|
||||||
|
{
|
||||||
|
return tr( "The numbers and dates locale will be set to %1." )
|
||||||
|
.arg( localeLabel( m_selectedLocaleConfiguration.lc_numeric ) );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -36,10 +36,14 @@ class Config : public QObject
|
|||||||
Q_PROPERTY( const QStringList& supportedLocales READ supportedLocales CONSTANT FINAL )
|
Q_PROPERTY( const QStringList& supportedLocales READ supportedLocales CONSTANT FINAL )
|
||||||
Q_PROPERTY( CalamaresUtils::Locale::CStringListModel* zonesModel READ zonesModel CONSTANT FINAL )
|
Q_PROPERTY( CalamaresUtils::Locale::CStringListModel* zonesModel READ zonesModel CONSTANT FINAL )
|
||||||
Q_PROPERTY( CalamaresUtils::Locale::CStringListModel* regionModel READ regionModel CONSTANT FINAL )
|
Q_PROPERTY( CalamaresUtils::Locale::CStringListModel* regionModel READ regionModel CONSTANT FINAL )
|
||||||
Q_PROPERTY( const CalamaresUtils::Locale::CStringPairList& timezoneData READ timezoneData CONSTANT FINAL )
|
|
||||||
Q_PROPERTY( const CalamaresUtils::Locale::TZZone* currentLocation READ currentLocation WRITE setCurrentLocation
|
Q_PROPERTY( const CalamaresUtils::Locale::TZZone* currentLocation READ currentLocation WRITE setCurrentLocation
|
||||||
NOTIFY currentLocationChanged )
|
NOTIFY currentLocationChanged )
|
||||||
|
|
||||||
|
Q_PROPERTY( QString currentLocationStatus READ currentLocationStatus NOTIFY currentLanguageStatusChanged )
|
||||||
|
Q_PROPERTY( QString currentLanguageStatus READ currentLanguageStatus NOTIFY currentLanguageStatusChanged )
|
||||||
|
Q_PROPERTY( QString currentLCStatus READ currentLCStatus NOTIFY currentLCStatusChanged )
|
||||||
|
|
||||||
public:
|
public:
|
||||||
Config( QObject* parent = nullptr );
|
Config( QObject* parent = nullptr );
|
||||||
~Config();
|
~Config();
|
||||||
@ -47,25 +51,37 @@ public:
|
|||||||
void setConfigurationMap( const QVariantMap& );
|
void setConfigurationMap( const QVariantMap& );
|
||||||
Calamares::JobList createJobs();
|
Calamares::JobList createJobs();
|
||||||
|
|
||||||
/** @brief Human-readable status for language and LC
|
// Underlying data for the models
|
||||||
*
|
const CalamaresUtils::Locale::CStringPairList& timezoneData() const;
|
||||||
* 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;
|
|
||||||
|
|
||||||
|
/** @brief The currently selected location (timezone)
|
||||||
|
*
|
||||||
|
* The location is a pointer into the date that timezoneData() returns.
|
||||||
|
* It is possible to return nullptr, if no location has been picked yet.
|
||||||
|
*/
|
||||||
|
const CalamaresUtils::Locale::TZZone* currentLocation() const { return m_currentLocation; }
|
||||||
|
|
||||||
|
/// locale configuration (LC_* and LANG) based solely on the current location.
|
||||||
|
LocaleConfiguration automaticLocaleConfiguration() const;
|
||||||
|
/// locale configuration that takes explicit settings into account
|
||||||
|
LocaleConfiguration localeConfiguration() const;
|
||||||
|
|
||||||
|
/// The human-readable description of what timezone is used
|
||||||
|
QString currentLocationStatus() const;
|
||||||
|
/// The human-readable description of what language is used
|
||||||
|
QString currentLanguageStatus() const;
|
||||||
|
/// The human-readable description of what locale (LC_*) is used
|
||||||
|
QString currentLCStatus() const;
|
||||||
|
|
||||||
public Q_SLOTS:
|
|
||||||
const QStringList& supportedLocales() const { return m_localeGenLines; }
|
const QStringList& supportedLocales() const { return m_localeGenLines; }
|
||||||
CalamaresUtils::Locale::CStringListModel* regionModel() const { return m_regionModel.get(); }
|
CalamaresUtils::Locale::CStringListModel* regionModel() const { return m_regionModel.get(); }
|
||||||
CalamaresUtils::Locale::CStringListModel* zonesModel() const { return m_zonesModel.get(); }
|
CalamaresUtils::Locale::CStringListModel* zonesModel() const { return m_zonesModel.get(); }
|
||||||
// Underlying data for the models
|
|
||||||
const CalamaresUtils::Locale::CStringPairList& timezoneData() const;
|
public Q_SLOTS:
|
||||||
|
/// Set a language by user-choice, overriding future location changes
|
||||||
|
void setLanguageExplicitly( const QString& language );
|
||||||
|
/// Set LC (formats) by user-choice, overriding future location changes
|
||||||
|
void setLCLocaleExplicitly( const QString& locale );
|
||||||
|
|
||||||
/** @brief Sets a location by name
|
/** @brief Sets a location by name
|
||||||
*
|
*
|
||||||
@ -82,25 +98,11 @@ public Q_SLOTS:
|
|||||||
*/
|
*/
|
||||||
void setCurrentLocation( const CalamaresUtils::Locale::TZZone* location );
|
void setCurrentLocation( const CalamaresUtils::Locale::TZZone* location );
|
||||||
|
|
||||||
/** @brief The currently selected location (timezone)
|
|
||||||
*
|
|
||||||
* The location is a pointer into the date that timezoneData() returns.
|
|
||||||
* It is possible to return nullptr, if no location has been picked yet.
|
|
||||||
*/
|
|
||||||
const CalamaresUtils::Locale::TZZone* currentLocation() const { return m_currentLocation; }
|
|
||||||
|
|
||||||
/// locale configuration (LC_* and LANG) based solely on the current location.
|
|
||||||
LocaleConfiguration automaticLocaleConfiguration() const;
|
|
||||||
/// locale configuration that takes explicit settings into account
|
|
||||||
LocaleConfiguration localeConfiguration() const;
|
|
||||||
|
|
||||||
/// Set a language by user-choice, overriding future location changes
|
|
||||||
void setLanguageExplicitly( const QString& language );
|
|
||||||
/// Set LC (formats) by user-choice, overriding future location changes
|
|
||||||
void setLCLocaleExplicitly( const QString& locale );
|
|
||||||
|
|
||||||
signals:
|
signals:
|
||||||
void currentLocationChanged( const CalamaresUtils::Locale::TZZone* location );
|
void currentLocationChanged( const CalamaresUtils::Locale::TZZone* location ) const;
|
||||||
|
void currentLocationStatusChanged( const QString& ) const;
|
||||||
|
void currentLanguageStatusChanged( const QString& ) const;
|
||||||
|
void currentLCStatusChanged( const QString& ) const;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
/// A list of supported locale identifiers (e.g. "en_US.UTF-8")
|
/// A list of supported locale identifiers (e.g. "en_US.UTF-8")
|
||||||
|
@ -106,6 +106,8 @@ LocalePage::LocalePage( Config* config, QWidget* parent )
|
|||||||
setMinimumWidth( m_tzWidget->width() );
|
setMinimumWidth( m_tzWidget->width() );
|
||||||
setLayout( mainLayout );
|
setLayout( mainLayout );
|
||||||
|
|
||||||
|
connect( config, &Config::currentLCStatusChanged, m_formatsLabel, &QLabel::setText );
|
||||||
|
connect( config, &Config::currentLanguageStatusChanged, m_localeLabel, &QLabel::setText );
|
||||||
connect( config, &Config::currentLocationChanged, m_tzWidget, &TimeZoneWidget::setCurrentLocation );
|
connect( config, &Config::currentLocationChanged, m_tzWidget, &TimeZoneWidget::setCurrentLocation );
|
||||||
connect( config, &Config::currentLocationChanged, this, &LocalePage::locationChanged );
|
connect( config, &Config::currentLocationChanged, this, &LocalePage::locationChanged );
|
||||||
connect( m_tzWidget,
|
connect( m_tzWidget,
|
||||||
@ -137,14 +139,11 @@ LocalePage::updateLocaleLabels()
|
|||||||
m_zoneLabel->setText( tr( "Zone:" ) );
|
m_zoneLabel->setText( tr( "Zone:" ) );
|
||||||
m_localeChangeButton->setText( tr( "&Change..." ) );
|
m_localeChangeButton->setText( tr( "&Change..." ) );
|
||||||
m_formatsChangeButton->setText( tr( "&Change..." ) );
|
m_formatsChangeButton->setText( tr( "&Change..." ) );
|
||||||
|
m_localeLabel->setText( m_config->currentLanguageStatus() );
|
||||||
auto labels = m_config->prettyLocaleStatus();
|
m_formatsLabel->setText( m_config->currentLCStatus() );
|
||||||
m_localeLabel->setText( labels.first );
|
|
||||||
m_formatsLabel->setText( labels.second );
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
void
|
void
|
||||||
LocalePage::onActivate()
|
LocalePage::onActivate()
|
||||||
{
|
{
|
||||||
|
@ -104,7 +104,8 @@ LocaleViewStep::prettyName() const
|
|||||||
QString
|
QString
|
||||||
LocaleViewStep::prettyStatus() const
|
LocaleViewStep::prettyStatus() const
|
||||||
{
|
{
|
||||||
return m_prettyStatus;
|
QStringList l { m_config->currentLocationStatus(), m_config->currentLanguageStatus(), m_config->currentLCStatus() };
|
||||||
|
return l.join( QStringLiteral( "<br/>" ) );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -167,7 +168,6 @@ LocaleViewStep::onLeave()
|
|||||||
if ( m_actualWidget )
|
if ( m_actualWidget )
|
||||||
{
|
{
|
||||||
m_jobs = m_config->createJobs();
|
m_jobs = m_config->createJobs();
|
||||||
m_prettyStatus = m_config->prettyStatus();
|
|
||||||
|
|
||||||
auto map = m_config->localeConfiguration().toMap();
|
auto map = m_config->localeConfiguration().toMap();
|
||||||
QVariantMap vm;
|
QVariantMap vm;
|
||||||
|
@ -70,7 +70,6 @@ private:
|
|||||||
|
|
||||||
LocalePage* m_actualWidget;
|
LocalePage* m_actualWidget;
|
||||||
bool m_nextEnabled;
|
bool m_nextEnabled;
|
||||||
QString m_prettyStatus;
|
|
||||||
|
|
||||||
Calamares::JobList m_jobs;
|
Calamares::JobList m_jobs;
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user