[locale] Apply coding style
This commit is contained in:
parent
21dde80a65
commit
3093f635e2
@ -35,8 +35,8 @@
|
|||||||
#include <QBoxLayout>
|
#include <QBoxLayout>
|
||||||
#include <QComboBox>
|
#include <QComboBox>
|
||||||
#include <QLabel>
|
#include <QLabel>
|
||||||
#include <QPushButton>
|
|
||||||
#include <QProcess>
|
#include <QProcess>
|
||||||
|
#include <QPushButton>
|
||||||
|
|
||||||
LocalePage::LocalePage( QWidget* parent )
|
LocalePage::LocalePage( QWidget* parent )
|
||||||
: QWidget( parent )
|
: QWidget( parent )
|
||||||
@ -109,8 +109,7 @@ LocalePage::LocalePage( QWidget* parent )
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
LocalePage::~LocalePage()
|
LocalePage::~LocalePage() {}
|
||||||
{}
|
|
||||||
|
|
||||||
|
|
||||||
void
|
void
|
||||||
@ -121,9 +120,8 @@ LocalePage::updateLocaleLabels()
|
|||||||
m_localeChangeButton->setText( tr( "&Change..." ) );
|
m_localeChangeButton->setText( tr( "&Change..." ) );
|
||||||
m_formatsChangeButton->setText( tr( "&Change..." ) );
|
m_formatsChangeButton->setText( tr( "&Change..." ) );
|
||||||
|
|
||||||
LocaleConfiguration lc = m_selectedLocaleConfiguration.isEmpty() ?
|
LocaleConfiguration lc
|
||||||
guessLocaleConfiguration() :
|
= m_selectedLocaleConfiguration.isEmpty() ? guessLocaleConfiguration() : m_selectedLocaleConfiguration;
|
||||||
m_selectedLocaleConfiguration;
|
|
||||||
auto labels = prettyLocaleStatus( lc );
|
auto labels = prettyLocaleStatus( lc );
|
||||||
m_localeLabel->setText( labels.first );
|
m_localeLabel->setText( labels.first );
|
||||||
m_formatsLabel->setText( labels.second );
|
m_formatsLabel->setText( labels.second );
|
||||||
@ -131,9 +129,7 @@ LocalePage::updateLocaleLabels()
|
|||||||
|
|
||||||
|
|
||||||
void
|
void
|
||||||
LocalePage::init( const QString& initialRegion,
|
LocalePage::init( const QString& initialRegion, const QString& initialZone, const QString& localeGenPath )
|
||||||
const QString& initialZone,
|
|
||||||
const QString& localeGenPath )
|
|
||||||
{
|
{
|
||||||
m_regionCombo->blockSignals( true );
|
m_regionCombo->blockSignals( true );
|
||||||
m_zoneCombo->blockSignals( true );
|
m_zoneCombo->blockSignals( true );
|
||||||
@ -155,19 +151,18 @@ LocalePage::init( const QString& initialRegion,
|
|||||||
m_regionCombo->currentIndexChanged( m_regionCombo->currentIndex() );
|
m_regionCombo->currentIndexChanged( m_regionCombo->currentIndex() );
|
||||||
|
|
||||||
// Default location
|
// Default location
|
||||||
auto containsLocation = []( const QList< LocaleGlobal::Location >& locations,
|
auto containsLocation = []( const QList< LocaleGlobal::Location >& locations, const QString& zone ) -> bool {
|
||||||
const QString& zone ) -> bool
|
|
||||||
{
|
|
||||||
for ( const LocaleGlobal::Location& location : locations )
|
for ( const LocaleGlobal::Location& location : locations )
|
||||||
{
|
{
|
||||||
if ( location.zone == zone )
|
if ( location.zone == zone )
|
||||||
|
{
|
||||||
return true;
|
return true;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
};
|
};
|
||||||
|
|
||||||
if ( keys.contains( initialRegion ) &&
|
if ( keys.contains( initialRegion ) && containsLocation( regions.value( initialRegion ), initialZone ) )
|
||||||
containsLocation( regions.value( initialRegion ), initialZone ) )
|
|
||||||
{
|
{
|
||||||
m_tzWidget->setCurrentLocation( initialRegion, initialZone );
|
m_tzWidget->setCurrentLocation( initialRegion, initialZone );
|
||||||
}
|
}
|
||||||
@ -185,14 +180,13 @@ LocalePage::init( const QString& initialRegion,
|
|||||||
QFile supported( "/usr/share/i18n/SUPPORTED" );
|
QFile supported( "/usr/share/i18n/SUPPORTED" );
|
||||||
QByteArray ba;
|
QByteArray ba;
|
||||||
|
|
||||||
if ( supported.exists() &&
|
if ( supported.exists() && supported.open( QIODevice::ReadOnly | QIODevice::Text ) )
|
||||||
supported.open( QIODevice::ReadOnly | QIODevice::Text ) )
|
|
||||||
{
|
{
|
||||||
ba = supported.readAll();
|
ba = supported.readAll();
|
||||||
supported.close();
|
supported.close();
|
||||||
|
|
||||||
const auto lines = ba.split( '\n' );
|
const auto lines = ba.split( '\n' );
|
||||||
for ( const QByteArray &line : lines )
|
for ( const QByteArray& line : lines )
|
||||||
{
|
{
|
||||||
m_localeGenLines.append( QString::fromLatin1( line.simplified() ) );
|
m_localeGenLines.append( QString::fromLatin1( line.simplified() ) );
|
||||||
}
|
}
|
||||||
@ -208,28 +202,32 @@ LocalePage::init( const QString& initialRegion,
|
|||||||
else
|
else
|
||||||
{
|
{
|
||||||
cWarning() << "Cannot open file" << localeGenPath
|
cWarning() << "Cannot open file" << localeGenPath
|
||||||
<< ". Assuming the supported languages are already built into "
|
<< ". Assuming the supported languages are already built into "
|
||||||
"the locale archive.";
|
"the locale archive.";
|
||||||
QProcess localeA;
|
QProcess localeA;
|
||||||
localeA.start( "locale", QStringList() << "-a" );
|
localeA.start( "locale", QStringList() << "-a" );
|
||||||
localeA.waitForFinished();
|
localeA.waitForFinished();
|
||||||
ba = localeA.readAllStandardOutput();
|
ba = localeA.readAllStandardOutput();
|
||||||
}
|
}
|
||||||
const auto lines = ba.split( '\n' );
|
const auto lines = ba.split( '\n' );
|
||||||
for ( const QByteArray &line : lines )
|
for ( const QByteArray& line : lines )
|
||||||
{
|
{
|
||||||
if ( line.startsWith( "## " ) ||
|
if ( line.startsWith( "## " ) || line.startsWith( "# " ) || line.simplified() == "#" )
|
||||||
line.startsWith( "# " ) ||
|
{
|
||||||
line.simplified() == "#" )
|
|
||||||
continue;
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
QString lineString = QString::fromLatin1( line.simplified() );
|
QString lineString = QString::fromLatin1( line.simplified() );
|
||||||
if ( lineString.startsWith( "#" ) )
|
if ( lineString.startsWith( "#" ) )
|
||||||
|
{
|
||||||
lineString.remove( '#' );
|
lineString.remove( '#' );
|
||||||
|
}
|
||||||
lineString = lineString.simplified();
|
lineString = lineString.simplified();
|
||||||
|
|
||||||
if ( lineString.isEmpty() )
|
if ( lineString.isEmpty() )
|
||||||
|
{
|
||||||
continue;
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
m_localeGenLines.append( lineString );
|
m_localeGenLines.append( lineString );
|
||||||
}
|
}
|
||||||
@ -238,41 +236,44 @@ LocalePage::init( const QString& initialRegion,
|
|||||||
if ( m_localeGenLines.isEmpty() )
|
if ( m_localeGenLines.isEmpty() )
|
||||||
{
|
{
|
||||||
cWarning() << "cannot acquire a list of available locales."
|
cWarning() << "cannot acquire a list of available locales."
|
||||||
<< "The locale and localecfg modules will be broken as long as this "
|
<< "The locale and localecfg modules will be broken as long as this "
|
||||||
"system does not provide"
|
"system does not provide"
|
||||||
<< "\n\t "
|
<< "\n\t "
|
||||||
<< "* a well-formed"
|
<< "* a well-formed" << supported.fileName() << "\n\tOR"
|
||||||
<< supported.fileName()
|
<< "* a well-formed"
|
||||||
<< "\n\tOR"
|
<< ( localeGenPath.isEmpty() ? QLatin1Literal( "/etc/locale.gen" ) : localeGenPath ) << "\n\tOR"
|
||||||
<< "* a well-formed"
|
<< "* a complete pre-compiled locale-gen database which allows complete locale -a output.";
|
||||||
<< (localeGenPath.isEmpty() ? QLatin1Literal("/etc/locale.gen") : localeGenPath)
|
return; // something went wrong and there's nothing we can do about it.
|
||||||
<< "\n\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.
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Assuming we have a list of supported locales, we usually only want UTF-8 ones
|
// Assuming we have a list of supported locales, we usually only want UTF-8 ones
|
||||||
// because it's not 1995.
|
// because it's not 1995.
|
||||||
for ( auto it = m_localeGenLines.begin(); it != m_localeGenLines.end(); )
|
for ( auto it = m_localeGenLines.begin(); it != m_localeGenLines.end(); )
|
||||||
{
|
{
|
||||||
if ( !it->contains( "UTF-8", Qt::CaseInsensitive ) &&
|
if ( !it->contains( "UTF-8", Qt::CaseInsensitive ) && !it->contains( "utf8", Qt::CaseInsensitive ) )
|
||||||
!it->contains( "utf8", Qt::CaseInsensitive ) )
|
{
|
||||||
it = m_localeGenLines.erase( it );
|
it = m_localeGenLines.erase( it );
|
||||||
|
}
|
||||||
else
|
else
|
||||||
|
{
|
||||||
++it;
|
++it;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// We strip " UTF-8" from "en_US.UTF-8 UTF-8" because it's redundant redundant.
|
// We strip " UTF-8" from "en_US.UTF-8 UTF-8" because it's redundant redundant.
|
||||||
for ( auto it = m_localeGenLines.begin(); it != m_localeGenLines.end(); ++it )
|
for ( auto it = m_localeGenLines.begin(); it != m_localeGenLines.end(); ++it )
|
||||||
{
|
{
|
||||||
if ( it->endsWith( " UTF-8" ) )
|
if ( it->endsWith( " UTF-8" ) )
|
||||||
|
{
|
||||||
it->chop( 6 );
|
it->chop( 6 );
|
||||||
|
}
|
||||||
*it = it->simplified();
|
*it = it->simplified();
|
||||||
}
|
}
|
||||||
updateGlobalStorage();
|
updateGlobalStorage();
|
||||||
}
|
}
|
||||||
|
|
||||||
std::pair< QString, QString > LocalePage::prettyLocaleStatus( const LocaleConfiguration& lc ) const
|
std::pair< QString, QString >
|
||||||
|
LocalePage::prettyLocaleStatus( const LocaleConfiguration& lc ) const
|
||||||
{
|
{
|
||||||
using CalamaresUtils::Locale::Label;
|
using CalamaresUtils::Locale::Label;
|
||||||
|
|
||||||
@ -288,14 +289,11 @@ QString
|
|||||||
LocalePage::prettyStatus() const
|
LocalePage::prettyStatus() const
|
||||||
{
|
{
|
||||||
QString status;
|
QString status;
|
||||||
status += tr( "Set timezone to %1/%2.<br/>" )
|
status += tr( "Set timezone to %1/%2.<br/>" ).arg( m_regionCombo->currentText() ).arg( m_zoneCombo->currentText() );
|
||||||
.arg( m_regionCombo->currentText() )
|
|
||||||
.arg( m_zoneCombo->currentText() );
|
|
||||||
|
|
||||||
LocaleConfiguration lc = m_selectedLocaleConfiguration.isEmpty() ?
|
LocaleConfiguration lc
|
||||||
guessLocaleConfiguration() :
|
= m_selectedLocaleConfiguration.isEmpty() ? guessLocaleConfiguration() : m_selectedLocaleConfiguration;
|
||||||
m_selectedLocaleConfiguration;
|
auto labels = prettyLocaleStatus( lc );
|
||||||
auto labels = prettyLocaleStatus(lc);
|
|
||||||
status += labels.first + "<br/>";
|
status += labels.first + "<br/>";
|
||||||
status += labels.second + "<br/>";
|
status += labels.second + "<br/>";
|
||||||
|
|
||||||
@ -319,9 +317,8 @@ LocalePage::createJobs()
|
|||||||
QMap< QString, QString >
|
QMap< QString, QString >
|
||||||
LocalePage::localesMap()
|
LocalePage::localesMap()
|
||||||
{
|
{
|
||||||
return m_selectedLocaleConfiguration.isEmpty() ?
|
return m_selectedLocaleConfiguration.isEmpty() ? guessLocaleConfiguration().toMap()
|
||||||
guessLocaleConfiguration().toMap() :
|
: m_selectedLocaleConfiguration.toMap();
|
||||||
m_selectedLocaleConfiguration.toMap();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -329,8 +326,7 @@ void
|
|||||||
LocalePage::onActivate()
|
LocalePage::onActivate()
|
||||||
{
|
{
|
||||||
m_regionCombo->setFocus();
|
m_regionCombo->setFocus();
|
||||||
if ( m_selectedLocaleConfiguration.isEmpty() ||
|
if ( m_selectedLocaleConfiguration.isEmpty() || !m_selectedLocaleConfiguration.explicit_lang )
|
||||||
!m_selectedLocaleConfiguration.explicit_lang )
|
|
||||||
{
|
{
|
||||||
auto newLocale = guessLocaleConfiguration();
|
auto newLocale = guessLocaleConfiguration();
|
||||||
m_selectedLocaleConfiguration.setLanguage( newLocale.language() );
|
m_selectedLocaleConfiguration.setLanguage( newLocale.language() );
|
||||||
@ -343,16 +339,15 @@ LocalePage::onActivate()
|
|||||||
LocaleConfiguration
|
LocaleConfiguration
|
||||||
LocalePage::guessLocaleConfiguration() const
|
LocalePage::guessLocaleConfiguration() const
|
||||||
{
|
{
|
||||||
return LocaleConfiguration::fromLanguageAndLocation( QLocale().name(),
|
return LocaleConfiguration::fromLanguageAndLocation(
|
||||||
m_localeGenLines,
|
QLocale().name(), m_localeGenLines, m_tzWidget->getCurrentLocation().country );
|
||||||
m_tzWidget->getCurrentLocation().country );
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void
|
void
|
||||||
LocalePage::updateGlobalLocale()
|
LocalePage::updateGlobalLocale()
|
||||||
{
|
{
|
||||||
auto *gs = Calamares::JobQueue::instance()->globalStorage();
|
auto* gs = Calamares::JobQueue::instance()->globalStorage();
|
||||||
const QString bcp47 = m_selectedLocaleConfiguration.toBcp47();
|
const QString bcp47 = m_selectedLocaleConfiguration.toBcp47();
|
||||||
gs->insert( "locale", bcp47 );
|
gs->insert( "locale", bcp47 );
|
||||||
}
|
}
|
||||||
@ -361,11 +356,11 @@ LocalePage::updateGlobalLocale()
|
|||||||
void
|
void
|
||||||
LocalePage::updateGlobalStorage()
|
LocalePage::updateGlobalStorage()
|
||||||
{
|
{
|
||||||
auto *gs = Calamares::JobQueue::instance()->globalStorage();
|
auto* gs = Calamares::JobQueue::instance()->globalStorage();
|
||||||
|
|
||||||
LocaleGlobal::Location location = m_tzWidget->getCurrentLocation();
|
LocaleGlobal::Location location = m_tzWidget->getCurrentLocation();
|
||||||
bool locationChanged = ( location.region != gs->value( "locationRegion" ) ) ||
|
bool locationChanged
|
||||||
( location.zone != gs->value( "locationZone" ) );
|
= ( location.region != gs->value( "locationRegion" ) ) || ( location.zone != gs->value( "locationZone" ) );
|
||||||
|
|
||||||
gs->insert( "locationRegion", location.region );
|
gs->insert( "locationRegion", location.region );
|
||||||
gs->insert( "locationZone", location.zone );
|
gs->insert( "locationZone", location.zone );
|
||||||
@ -378,18 +373,17 @@ LocalePage::updateGlobalStorage()
|
|||||||
if ( locationChanged && Calamares::Settings::instance()->doChroot() )
|
if ( locationChanged && Calamares::Settings::instance()->doChroot() )
|
||||||
{
|
{
|
||||||
QProcess::execute( "timedatectl", // depends on systemd
|
QProcess::execute( "timedatectl", // depends on systemd
|
||||||
{ "set-timezone",
|
{ "set-timezone", location.region + '/' + location.zone } );
|
||||||
location.region + '/' + location.zone } );
|
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
// Preserve those settings that have been made explicit.
|
// Preserve those settings that have been made explicit.
|
||||||
auto newLocale = guessLocaleConfiguration();
|
auto newLocale = guessLocaleConfiguration();
|
||||||
if ( !m_selectedLocaleConfiguration.isEmpty() &&
|
if ( !m_selectedLocaleConfiguration.isEmpty() && m_selectedLocaleConfiguration.explicit_lang )
|
||||||
m_selectedLocaleConfiguration.explicit_lang )
|
{
|
||||||
newLocale.setLanguage( m_selectedLocaleConfiguration.language() );
|
newLocale.setLanguage( m_selectedLocaleConfiguration.language() );
|
||||||
if ( !m_selectedLocaleConfiguration.isEmpty() &&
|
}
|
||||||
m_selectedLocaleConfiguration.explicit_lc )
|
if ( !m_selectedLocaleConfiguration.isEmpty() && m_selectedLocaleConfiguration.explicit_lc )
|
||||||
{
|
{
|
||||||
newLocale.lc_numeric = m_selectedLocaleConfiguration.lc_numeric;
|
newLocale.lc_numeric = m_selectedLocaleConfiguration.lc_numeric;
|
||||||
newLocale.lc_time = m_selectedLocaleConfiguration.lc_time;
|
newLocale.lc_time = m_selectedLocaleConfiguration.lc_time;
|
||||||
@ -455,14 +449,18 @@ LocalePage::locationChanged( LocaleGlobal::Location location )
|
|||||||
// Set region index
|
// Set region index
|
||||||
int index = m_regionCombo->findData( location.region );
|
int index = m_regionCombo->findData( location.region );
|
||||||
if ( index < 0 )
|
if ( index < 0 )
|
||||||
|
{
|
||||||
return;
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
m_regionCombo->setCurrentIndex( index );
|
m_regionCombo->setCurrentIndex( index );
|
||||||
|
|
||||||
// Set zone index
|
// Set zone index
|
||||||
index = m_zoneCombo->findData( location.zone );
|
index = m_zoneCombo->findData( location.zone );
|
||||||
if ( index < 0 )
|
if ( index < 0 )
|
||||||
|
{
|
||||||
return;
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
m_zoneCombo->setCurrentIndex( index );
|
m_zoneCombo->setCurrentIndex( index );
|
||||||
|
|
||||||
@ -474,15 +472,13 @@ LocalePage::locationChanged( LocaleGlobal::Location location )
|
|||||||
void
|
void
|
||||||
LocalePage::changeLocale()
|
LocalePage::changeLocale()
|
||||||
{
|
{
|
||||||
LCLocaleDialog* dlg =
|
LCLocaleDialog* dlg
|
||||||
new LCLocaleDialog( m_selectedLocaleConfiguration.isEmpty() ?
|
= new LCLocaleDialog( m_selectedLocaleConfiguration.isEmpty() ? guessLocaleConfiguration().language()
|
||||||
guessLocaleConfiguration().language() :
|
: m_selectedLocaleConfiguration.language(),
|
||||||
m_selectedLocaleConfiguration.language(),
|
m_localeGenLines,
|
||||||
m_localeGenLines,
|
this );
|
||||||
this );
|
|
||||||
dlg->exec();
|
dlg->exec();
|
||||||
if ( dlg->result() == QDialog::Accepted &&
|
if ( dlg->result() == QDialog::Accepted && !dlg->selectedLCLocale().isEmpty() )
|
||||||
!dlg->selectedLCLocale().isEmpty() )
|
|
||||||
{
|
{
|
||||||
m_selectedLocaleConfiguration.setLanguage( dlg->selectedLCLocale() );
|
m_selectedLocaleConfiguration.setLanguage( dlg->selectedLCLocale() );
|
||||||
m_selectedLocaleConfiguration.explicit_lang = true;
|
m_selectedLocaleConfiguration.explicit_lang = true;
|
||||||
@ -497,15 +493,13 @@ LocalePage::changeLocale()
|
|||||||
void
|
void
|
||||||
LocalePage::changeFormats()
|
LocalePage::changeFormats()
|
||||||
{
|
{
|
||||||
LCLocaleDialog* dlg =
|
LCLocaleDialog* dlg
|
||||||
new LCLocaleDialog( m_selectedLocaleConfiguration.isEmpty() ?
|
= new LCLocaleDialog( m_selectedLocaleConfiguration.isEmpty() ? guessLocaleConfiguration().lc_numeric
|
||||||
guessLocaleConfiguration().lc_numeric :
|
: m_selectedLocaleConfiguration.lc_numeric,
|
||||||
m_selectedLocaleConfiguration.lc_numeric,
|
m_localeGenLines,
|
||||||
m_localeGenLines,
|
this );
|
||||||
this );
|
|
||||||
dlg->exec();
|
dlg->exec();
|
||||||
if ( dlg->result() == QDialog::Accepted &&
|
if ( dlg->result() == QDialog::Accepted && !dlg->selectedLCLocale().isEmpty() )
|
||||||
!dlg->selectedLCLocale().isEmpty() )
|
|
||||||
{
|
{
|
||||||
// TODO: improve the granularity of this setting.
|
// TODO: improve the granularity of this setting.
|
||||||
m_selectedLocaleConfiguration.lc_numeric = dlg->selectedLCLocale();
|
m_selectedLocaleConfiguration.lc_numeric = dlg->selectedLCLocale();
|
||||||
@ -523,5 +517,4 @@ LocalePage::changeFormats()
|
|||||||
}
|
}
|
||||||
|
|
||||||
dlg->deleteLater();
|
dlg->deleteLater();
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -39,9 +39,7 @@ public:
|
|||||||
explicit LocalePage( QWidget* parent = nullptr );
|
explicit LocalePage( QWidget* parent = nullptr );
|
||||||
virtual ~LocalePage();
|
virtual ~LocalePage();
|
||||||
|
|
||||||
void init( const QString& initialRegion,
|
void init( const QString& initialRegion, const QString& initialZone, const QString& localeGenPath );
|
||||||
const QString& initialZone,
|
|
||||||
const QString& localeGenPath );
|
|
||||||
|
|
||||||
QString prettyStatus() const;
|
QString prettyStatus() const;
|
||||||
|
|
||||||
@ -91,4 +89,4 @@ private:
|
|||||||
bool m_blockTzWidgetSet;
|
bool m_blockTzWidgetSet;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // LOCALEPAGE_H
|
#endif // LOCALEPAGE_H
|
||||||
|
Loading…
Reference in New Issue
Block a user