Use LocaleConfiguration in LocalePage. Add relevant widgets.
Also fix error reporting. Move guesswork to LocaleConfiguration + a total rewrite. Locale is now a LocaleConfiguration, that converts to QMap.
This commit is contained in:
parent
f60f1c6220
commit
8f44f76443
@ -81,6 +81,17 @@ LocalePage::LocalePage( QWidget* parent )
|
||||
localeLayout->addWidget( m_localeChangeButton );
|
||||
mainLayout->addLayout( localeLayout );
|
||||
|
||||
QBoxLayout* formatsLayout = new QHBoxLayout;
|
||||
m_formatsLabel = new QLabel( this );
|
||||
m_formatsLabel->setWordWrap( true );
|
||||
m_formatsLabel->setSizePolicy( QSizePolicy::Expanding, QSizePolicy::Preferred );
|
||||
formatsLayout->addWidget( m_formatsLabel );
|
||||
|
||||
m_formatsChangeButton = new QPushButton( this );
|
||||
m_formatsChangeButton->setSizePolicy( QSizePolicy::Preferred, QSizePolicy::Preferred );
|
||||
formatsLayout->addWidget( m_formatsChangeButton );
|
||||
mainLayout->addLayout( formatsLayout );
|
||||
|
||||
setLayout( mainLayout );
|
||||
|
||||
connect( m_regionCombo,
|
||||
@ -146,31 +157,68 @@ LocalePage::LocalePage( QWidget* parent )
|
||||
} );
|
||||
|
||||
connect( m_localeChangeButton, &QPushButton::clicked,
|
||||
[this]()
|
||||
[this]
|
||||
{
|
||||
LCLocaleDialog* dlg = new LCLocaleDialog( lcLocale(),
|
||||
m_localeGenLines,
|
||||
this );
|
||||
LCLocaleDialog* dlg =
|
||||
new LCLocaleDialog( m_selectedLocaleConfiguration.isEmpty() ?
|
||||
guessLocaleConfiguration().lang :
|
||||
m_selectedLocaleConfiguration.lang,
|
||||
m_localeGenLines,
|
||||
this );
|
||||
dlg->exec();
|
||||
if ( dlg->result() == QDialog::Accepted &&
|
||||
!dlg->selectedLCLocale().isEmpty() )
|
||||
{
|
||||
m_selectedLocale = dlg->selectedLCLocale();
|
||||
m_localeLabel->setText( tr( "The system locale is set to %1." )
|
||||
.arg( prettyLCLocale( m_selectedLocale ) ) );
|
||||
m_selectedLocaleConfiguration.lang = dlg->selectedLCLocale();
|
||||
m_localeLabel->setText( tr( "The system language will be set to %1." )
|
||||
.arg( prettyLCLocale(
|
||||
m_selectedLocaleConfiguration.lang ) ) );
|
||||
}
|
||||
|
||||
dlg->deleteLater();
|
||||
} );
|
||||
|
||||
connect( m_formatsChangeButton, &QPushButton::clicked,
|
||||
[this]
|
||||
{
|
||||
LCLocaleDialog* dlg =
|
||||
new LCLocaleDialog( m_selectedLocaleConfiguration.isEmpty() ?
|
||||
guessLocaleConfiguration().lc_numeric :
|
||||
m_selectedLocaleConfiguration.lc_numeric,
|
||||
m_localeGenLines,
|
||||
this );
|
||||
dlg->exec();
|
||||
if ( dlg->result() == QDialog::Accepted &&
|
||||
!dlg->selectedLCLocale().isEmpty() )
|
||||
{
|
||||
// TODO: improve the granularity of this setting.
|
||||
m_selectedLocaleConfiguration.lc_numeric = dlg->selectedLCLocale();
|
||||
m_selectedLocaleConfiguration.lc_time = dlg->selectedLCLocale();
|
||||
m_selectedLocaleConfiguration.lc_monetary = dlg->selectedLCLocale();
|
||||
m_selectedLocaleConfiguration.lc_paper = dlg->selectedLCLocale();
|
||||
m_selectedLocaleConfiguration.lc_name = dlg->selectedLCLocale();
|
||||
m_selectedLocaleConfiguration.lc_address = dlg->selectedLCLocale();
|
||||
m_selectedLocaleConfiguration.lc_telephone = dlg->selectedLCLocale();
|
||||
m_selectedLocaleConfiguration.lc_measurement = dlg->selectedLCLocale();
|
||||
m_selectedLocaleConfiguration.lc_identification = dlg->selectedLCLocale();
|
||||
|
||||
m_formatsLabel->setText( tr( "The numbers and dates locale will be set to %1." )
|
||||
.arg( prettyLCLocale(
|
||||
m_selectedLocaleConfiguration.lc_numeric ) ) );
|
||||
}
|
||||
|
||||
dlg->deleteLater();
|
||||
|
||||
} );
|
||||
|
||||
CALAMARES_RETRANSLATE(
|
||||
m_regionLabel->setText( tr( "Region:" ) );
|
||||
m_zoneLabel->setText( tr( "Zone:" ) );
|
||||
|
||||
m_localeLabel->setText( tr( "The system locale is set to %1." )
|
||||
.arg( prettyLCLocale( lcLocale() ) ) );
|
||||
updateLocaleLabels();
|
||||
|
||||
m_localeChangeButton->setText( tr( "&Change..." ) );
|
||||
m_formatsChangeButton->setText( tr( "&Change..." ) );
|
||||
)
|
||||
}
|
||||
|
||||
@ -179,6 +227,20 @@ LocalePage::~LocalePage()
|
||||
{}
|
||||
|
||||
|
||||
void
|
||||
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 ) ) );
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
LocalePage::init( const QString& initialRegion,
|
||||
const QString& initialZone,
|
||||
@ -284,7 +346,15 @@ LocalePage::init( const QString& initialRegion,
|
||||
|
||||
if ( m_localeGenLines.isEmpty() )
|
||||
{
|
||||
cDebug() << "WARNING: cannot get list of supported locales from anywhere.";
|
||||
cDebug() << "WARNING: cannot acquire a list of available locales."
|
||||
<< "The locale and localecfg modules will be broken as long as this "
|
||||
"system does not provide"
|
||||
<< " * a /usr/share/i18n/SUPPORTED file"
|
||||
<< "\tOR"
|
||||
<< " * a well-formed /etc/locale.gen"
|
||||
<< "\tOR"
|
||||
<< " * a complete pre-compiled locale-gen database which allows complete locale -a output.";
|
||||
|
||||
return; // something went wrong and there's nothing we can do about it.
|
||||
}
|
||||
|
||||
@ -297,6 +367,8 @@ LocalePage::init( const QString& initialRegion,
|
||||
else
|
||||
++it;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
@ -325,10 +397,12 @@ LocalePage::createJobs()
|
||||
}
|
||||
|
||||
|
||||
QString
|
||||
LocalePage::lcLocale()
|
||||
QMap< QString, QString >
|
||||
LocalePage::localesMap()
|
||||
{
|
||||
return m_selectedLocale.isEmpty() ? guessLCLocale() : m_selectedLocale;
|
||||
return m_selectedLocaleConfiguration.isEmpty() ?
|
||||
guessLocaleConfiguration().toMap() :
|
||||
m_selectedLocaleConfiguration.toMap();
|
||||
}
|
||||
|
||||
|
||||
@ -339,66 +413,32 @@ LocalePage::onActivate()
|
||||
}
|
||||
|
||||
|
||||
QString
|
||||
LocalePage::guessLCLocale()
|
||||
LocaleConfiguration
|
||||
LocalePage::guessLocaleConfiguration()
|
||||
{
|
||||
QLocale myLocale = QLocale();
|
||||
QLocale myLocale = QLocale(); // User-selected language
|
||||
|
||||
// If we cannot say anything about available locales
|
||||
if ( m_localeGenLines.isEmpty() )
|
||||
return "en_US.UTF-8 UTF-8";
|
||||
|
||||
QString myLanguage = myLocale.name().split( '_' ).first();
|
||||
QStringList linesForLanguage;
|
||||
foreach ( QString line, m_localeGenLines )
|
||||
{
|
||||
if ( line.startsWith( myLanguage ) )
|
||||
linesForLanguage.append( line );
|
||||
cDebug() << "WARNING: cannot acquire a list of available locales."
|
||||
<< "The locale and localecfg modules will be broken as long as this "
|
||||
"system does not provide"
|
||||
<< " * a /usr/share/i18n/SUPPORTED file"
|
||||
<< "\tOR"
|
||||
<< " * a well-formed /etc/locale.gen"
|
||||
<< "\tOR"
|
||||
<< " * a complete pre-compiled locale-gen database which allows complete locale -a output.";
|
||||
return LocaleConfiguration::createDefault();
|
||||
}
|
||||
|
||||
if ( linesForLanguage.length() == 0 )
|
||||
return "en_US.UTF-8 UTF-8";
|
||||
else if ( linesForLanguage.length() == 1 )
|
||||
return linesForLanguage.first();
|
||||
else
|
||||
{
|
||||
QStringList linesForLanguageUtf;
|
||||
foreach ( QString line, linesForLanguage )
|
||||
{
|
||||
if ( line.contains( "UTF-8" ) )
|
||||
linesForLanguageUtf.append( line );
|
||||
}
|
||||
QString myLanguageLocale = myLocale.name();
|
||||
if ( myLanguageLocale.isEmpty() )
|
||||
return LocaleConfiguration::createDefault();
|
||||
|
||||
if ( linesForLanguageUtf.length() == 1 )
|
||||
return linesForLanguageUtf.first();
|
||||
}
|
||||
|
||||
// FIXME: use reverse geocoding to guess the country
|
||||
QString prefix = myLocale.name();
|
||||
QStringList linesForLanguageAndCountry;
|
||||
foreach ( QString line, linesForLanguage )
|
||||
{
|
||||
if ( line.startsWith( prefix ) )
|
||||
linesForLanguageAndCountry.append( line );
|
||||
}
|
||||
|
||||
if ( linesForLanguageAndCountry.length() == 0 )
|
||||
return "en_US.UTF-8 UTF-8";
|
||||
else if ( linesForLanguageAndCountry.length() == 1 )
|
||||
return linesForLanguageAndCountry.first();
|
||||
else
|
||||
{
|
||||
QStringList linesForLanguageAndCountryUtf;
|
||||
foreach ( QString line, linesForLanguageAndCountry )
|
||||
{
|
||||
if ( line.contains( "UTF-8" ) )
|
||||
linesForLanguageAndCountryUtf.append( line );
|
||||
}
|
||||
|
||||
if ( linesForLanguageAndCountryUtf.length() == 1 )
|
||||
return linesForLanguageAndCountryUtf.first();
|
||||
}
|
||||
|
||||
return "en_US.UTF-8 UTF-8";
|
||||
return LocaleConfiguration::fromLanguageAndLocation( myLanguageLocale,
|
||||
m_localeGenLines,
|
||||
m_tzWidget->getCurrentLocation().country );
|
||||
}
|
||||
|
||||
|
||||
@ -419,4 +459,7 @@ LocalePage::updateGlobalStorage()
|
||||
->insert( "locationRegion", location.region );
|
||||
Calamares::JobQueue::instance()->globalStorage()
|
||||
->insert( "locationZone", location.zone );
|
||||
|
||||
m_selectedLocaleConfiguration = guessLocaleConfiguration();
|
||||
updateLocaleLabels();
|
||||
}
|
||||
|
@ -21,6 +21,8 @@
|
||||
|
||||
#include "Typedefs.h"
|
||||
|
||||
#include "LocaleConfiguration.h"
|
||||
|
||||
#include <QWidget>
|
||||
|
||||
class QComboBox;
|
||||
@ -43,14 +45,15 @@ public:
|
||||
|
||||
QList< Calamares::job_ptr > createJobs();
|
||||
|
||||
QString lcLocale();
|
||||
QMap< QString, QString > localesMap();
|
||||
|
||||
void onActivate();
|
||||
|
||||
private:
|
||||
QString guessLCLocale();
|
||||
QString prettyLCLocale( const QString& lcLocale );
|
||||
LocaleConfiguration guessLocaleConfiguration();
|
||||
QString prettyLCLocale( const QString& localesMap );
|
||||
void updateGlobalStorage();
|
||||
void updateLocaleLabels();
|
||||
|
||||
TimeZoneWidget* m_tzWidget;
|
||||
QComboBox* m_regionCombo;
|
||||
@ -60,8 +63,10 @@ private:
|
||||
QLabel* m_zoneLabel;
|
||||
QLabel* m_localeLabel;
|
||||
QPushButton* m_localeChangeButton;
|
||||
QLabel* m_formatsLabel;
|
||||
QPushButton* m_formatsChangeButton;
|
||||
|
||||
QString m_selectedLocale;
|
||||
LocaleConfiguration m_selectedLocaleConfiguration;
|
||||
|
||||
QStringList m_localeGenLines;
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user