[locale] Apply coding style

main
Adriaan de Groot 5 years ago
parent 21dde80a65
commit 3093f635e2

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

@ -39,9 +39,7 @@ public:
explicit LocalePage( QWidget* parent = nullptr );
virtual ~LocalePage();
void init( const QString& initialRegion,
const QString& initialZone,
const QString& localeGenPath );
void init( const QString& initialRegion, const QString& initialZone, const QString& localeGenPath );
QString prettyStatus() const;
@ -91,4 +89,4 @@ private:
bool m_blockTzWidgetSet;
};
#endif // LOCALEPAGE_H
#endif // LOCALEPAGE_H

Loading…
Cancel
Save