[locale] Apply coding style
This commit is contained in:
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,8 +180,7 @@ 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();
|
||||
@ -218,18 +212,22 @@ LocalePage::init( const QString& initialRegion,
|
||||
const auto lines = ba.split( '\n' );
|
||||
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 );
|
||||
}
|
||||
@ -241,12 +239,9 @@ LocalePage::init( const QString& initialRegion,
|
||||
<< "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"
|
||||
<< supported.fileName()
|
||||
<< "\n\tOR"
|
||||
<< "* a well-formed"
|
||||
<< (localeGenPath.isEmpty() ? QLatin1Literal("/etc/locale.gen") : localeGenPath)
|
||||
<< "\n\tOR"
|
||||
<< ( 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.
|
||||
}
|
||||
@ -255,24 +250,30 @@ LocalePage::init( const QString& initialRegion,
|
||||
// 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,13 +289,10 @@ QString
|
||||
LocalePage::prettyStatus() const
|
||||
{
|
||||
QString status;
|
||||
status += tr( "Set timezone to %1/%2.<br/>" )
|
||||
.arg( m_regionCombo->currentText() )
|
||||
.arg( m_zoneCombo->currentText() );
|
||||
status += tr( "Set timezone to %1/%2.<br/>" ).arg( m_regionCombo->currentText() ).arg( m_zoneCombo->currentText() );
|
||||
|
||||
LocaleConfiguration lc = m_selectedLocaleConfiguration.isEmpty() ?
|
||||
guessLocaleConfiguration() :
|
||||
m_selectedLocaleConfiguration;
|
||||
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,9 +339,8 @@ 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 );
|
||||
}
|
||||
|
||||
|
||||
@ -364,8 +359,8 @@ LocalePage::updateGlobalStorage()
|
||||
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(),
|
||||
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,
|
||||
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;
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user