[locale] Apply coding style to Config

- ci/calamaresstyle
- sort includes by kind (local module, Calamares, Qt, STL)
- add copyright line
This commit is contained in:
Adriaan de Groot 2020-03-24 22:48:14 +01:00
parent 412a8043a9
commit 08b5012946
2 changed files with 80 additions and 67 deletions

View File

@ -1,6 +1,7 @@
/* === This file is part of Calamares - <https://github.com/calamares> === /* === This file is part of Calamares - <https://github.com/calamares> ===
* *
* Copyright 2019-2020, Adriaan de Groot <groot@kde.org> * Copyright 2019-2020, Adriaan de Groot <groot@kde.org>
* Copyright 2020, Camilo Higuita <milo.h@aol.com>
* *
* Calamares is free software: you can redistribute it and/or modify * Calamares is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by * it under the terms of the GNU General Public License as published by
@ -18,15 +19,12 @@
#include "Config.h" #include "Config.h"
#include <QDebug> #include "LCLocaleDialog.h"
#include <QProcess>
#include "SetTimezoneJob.h" #include "SetTimezoneJob.h"
#include "timezonewidget/timezonewidget.h" #include "timezonewidget/timezonewidget.h"
#include "GlobalStorage.h" #include "GlobalStorage.h"
#include "JobQueue.h" #include "JobQueue.h"
#include "LCLocaleDialog.h"
#include "Settings.h" #include "Settings.h"
#include "locale/Label.h" #include "locale/Label.h"
@ -35,22 +33,25 @@
#include "utils/Logger.h" #include "utils/Logger.h"
#include "utils/Retranslator.h" #include "utils/Retranslator.h"
Config::Config(QObject *parent) : QObject(parent) #include <QDebug>
, m_regionList( CalamaresUtils::Locale::TZRegion::fromZoneTab() ) #include <QProcess>
, m_regionModel( new CalamaresUtils::Locale::CStringListModel ( m_regionList ) )
, m_zonesModel( new CalamaresUtils::Locale::CStringListModel ( ) )
, m_blockTzWidgetSet( false )
{
connect(m_regionModel, &CalamaresUtils::Locale::CStringListModel::currentIndexChanged, [&]()
{
m_zonesModel->setList(static_cast<const CalamaresUtils::Locale::TZRegion*>(m_regionModel->item(m_regionModel->currentIndex()))->zones());
updateLocaleLabels();
});
connect(m_zonesModel, &CalamaresUtils::Locale::CStringListModel::currentIndexChanged, [&]() Config::Config( QObject* parent )
{ : QObject( parent )
, m_regionList( CalamaresUtils::Locale::TZRegion::fromZoneTab() )
, m_regionModel( new CalamaresUtils::Locale::CStringListModel( m_regionList ) )
, m_zonesModel( new CalamaresUtils::Locale::CStringListModel() )
, m_blockTzWidgetSet( false )
{
connect( m_regionModel, &CalamaresUtils::Locale::CStringListModel::currentIndexChanged, [&]() {
m_zonesModel->setList( static_cast< const CalamaresUtils::Locale::TZRegion* >(
m_regionModel->item( m_regionModel->currentIndex() ) )
->zones() );
updateLocaleLabels(); updateLocaleLabels();
}); } );
connect(
m_zonesModel, &CalamaresUtils::Locale::CStringListModel::currentIndexChanged, [&]() { updateLocaleLabels(); } );
} }
Config::~Config() Config::~Config()
@ -58,37 +59,37 @@ Config::~Config()
qDeleteAll( m_regionList ); qDeleteAll( m_regionList );
} }
CalamaresUtils::Locale::CStringListModel * CalamaresUtils::Locale::CStringListModel*
Config::zonesModel() const Config::zonesModel() const
{ {
return m_zonesModel; return m_zonesModel;
} }
CalamaresUtils::Locale::CStringListModel * CalamaresUtils::Locale::CStringListModel*
Config::regionModel() const Config::regionModel() const
{ {
return m_regionModel; return m_regionModel;
} }
void void
Config::setLocaleInfo(const QString& initialRegion, const QString& initialZone, const QString& localeGenPath) Config::setLocaleInfo( const QString& initialRegion, const QString& initialZone, const QString& localeGenPath )
{ {
using namespace CalamaresUtils::Locale; using namespace CalamaresUtils::Locale;
cDebug()<< "REGION MODEL SIZE" << initialRegion << initialZone; cDebug() << "REGION MODEL SIZE" << initialRegion << initialZone;
auto* region = m_regionList.find< TZRegion >( initialRegion ); auto* region = m_regionList.find< TZRegion >( initialRegion );
if ( region && region->zones().find< TZZone >( initialZone ) ) if ( region && region->zones().find< TZZone >( initialZone ) )
{ {
this->m_regionModel->setCurrentIndex(m_regionModel->indexOf(initialRegion)); this->m_regionModel->setCurrentIndex( m_regionModel->indexOf( initialRegion ) );
m_zonesModel->setList(region->zones()); m_zonesModel->setList( region->zones() );
this->m_zonesModel->setCurrentIndex(m_zonesModel->indexOf(initialZone)); this->m_zonesModel->setCurrentIndex( m_zonesModel->indexOf( initialZone ) );
} }
else else
{ {
this->m_regionModel->setCurrentIndex(m_regionModel->indexOf("America")); this->m_regionModel->setCurrentIndex( m_regionModel->indexOf( "America" ) );
m_zonesModel->setList(static_cast<const TZRegion*>(m_regionModel->item(m_regionModel->currentIndex()))->zones()); m_zonesModel->setList(
this->m_zonesModel->setCurrentIndex(m_zonesModel->indexOf("New_York")); static_cast< const TZRegion* >( m_regionModel->item( m_regionModel->currentIndex() ) )->zones() );
this->m_zonesModel->setCurrentIndex( m_zonesModel->indexOf( "New_York" ) );
} }
// Some distros come with a meaningfully commented and easy to parse locale.gen, // Some distros come with a meaningfully commented and easy to parse locale.gen,
@ -192,14 +193,16 @@ Config::setLocaleInfo(const QString& initialRegion, const QString& initialZone,
updateLocaleLabels(); updateLocaleLabels();
} }
void Config::updateGlobalLocale() void
Config::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 );
} }
void Config::updateGlobalStorage() void
Config::updateGlobalStorage()
{ {
auto* gs = Calamares::JobQueue::instance()->globalStorage(); auto* gs = Calamares::JobQueue::instance()->globalStorage();
@ -214,13 +217,13 @@ void Config::updateGlobalStorage()
// If we're in chroot mode (normal install mode), then we immediately set the // If we're in chroot mode (normal install mode), then we immediately set the
// timezone on the live system. When debugging timezones, don't bother. // timezone on the live system. When debugging timezones, don't bother.
#ifndef DEBUG_TIMEZONES #ifndef DEBUG_TIMEZONES
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", location->region() + '/' + location->zone() } ); { "set-timezone", 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();
@ -257,8 +260,8 @@ Config::updateLocaleLabels()
} }
std::pair<QString, QString> std::pair< QString, QString >
Config::prettyLocaleStatus(const LocaleConfiguration& lc) const Config::prettyLocaleStatus( const LocaleConfiguration& lc ) const
{ {
using CalamaresUtils::Locale::Label; using CalamaresUtils::Locale::Label;
@ -270,7 +273,8 @@ Config::prettyLocaleStatus(const LocaleConfiguration& lc) const
tr( "The numbers and dates locale will be set to %1." ).arg( num.label() ) ); tr( "The numbers and dates locale will be set to %1." ).arg( num.label() ) );
} }
Calamares::JobList Config::createJobs() Calamares::JobList
Config::createJobs()
{ {
QList< Calamares::job_ptr > list; QList< Calamares::job_ptr > list;
const CalamaresUtils::Locale::TZZone* location = currentLocation(); const CalamaresUtils::Locale::TZZone* location = currentLocation();
@ -281,22 +285,27 @@ Calamares::JobList Config::createJobs()
return list; return list;
} }
LocaleConfiguration Config::guessLocaleConfiguration() const LocaleConfiguration
Config::guessLocaleConfiguration() const
{ {
return LocaleConfiguration::fromLanguageAndLocation( return LocaleConfiguration::fromLanguageAndLocation(
QLocale().name(), m_localeGenLines, currentLocation() ? currentLocation()->country() : "" ); QLocale().name(), m_localeGenLines, currentLocation() ? currentLocation()->country() : "" );
} }
QMap<QString, QString> Config::localesMap() QMap< QString, QString >
Config::localesMap()
{ {
return m_selectedLocaleConfiguration.isEmpty() ? guessLocaleConfiguration().toMap() return m_selectedLocaleConfiguration.isEmpty() ? guessLocaleConfiguration().toMap()
: m_selectedLocaleConfiguration.toMap(); : m_selectedLocaleConfiguration.toMap();
} }
QString Config::prettyStatus() const QString
Config::prettyStatus() const
{ {
QString status; QString status;
status += tr( "Set timezone to %1/%2.<br/>" ).arg( m_regionModel->item(m_regionModel->currentIndex())->tr() ).arg( m_zonesModel->item(m_zonesModel->currentIndex())->tr() ); status += tr( "Set timezone to %1/%2.<br/>" )
.arg( m_regionModel->item( m_regionModel->currentIndex() )->tr() )
.arg( m_zonesModel->item( m_zonesModel->currentIndex() )->tr() );
LocaleConfiguration lc LocaleConfiguration lc
= m_selectedLocaleConfiguration.isEmpty() ? guessLocaleConfiguration() : m_selectedLocaleConfiguration; = m_selectedLocaleConfiguration.isEmpty() ? guessLocaleConfiguration() : m_selectedLocaleConfiguration;
@ -308,7 +317,8 @@ QString Config::prettyStatus() const
} }
const CalamaresUtils::Locale::TZZone * Config::currentLocation() const const CalamaresUtils::Locale::TZZone*
Config::currentLocation() const
{ {
return static_cast<const CalamaresUtils::Locale::TZZone*>(m_zonesModel->item(m_zonesModel->currentIndex())); return static_cast< const CalamaresUtils::Locale::TZZone* >( m_zonesModel->item( m_zonesModel->currentIndex() ) );
} }

View File

@ -1,6 +1,7 @@
/* === This file is part of Calamares - <https://github.com/calamares> === /* === This file is part of Calamares - <https://github.com/calamares> ===
* *
* Copyright 2019-2020, Adriaan de Groot <groot@kde.org> * Copyright 2019-2020, Adriaan de Groot <groot@kde.org>
* Copyright 2020, Camilo Higuita <milo.h@aol.com>
* *
* Calamares is free software: you can redistribute it and/or modify * Calamares is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by * it under the terms of the GNU General Public License as published by
@ -19,21 +20,23 @@
#ifndef LOCALE_CONFIG_H #ifndef LOCALE_CONFIG_H
#define LOCALE_CONFIG_H #define LOCALE_CONFIG_H
#include <QObject>
#include <QUrl>
#include <QAbstractListModel>
#include "Job.h"
#include "locale/TimeZone.h"
#include "LocaleConfiguration.h" #include "LocaleConfiguration.h"
#include "timezonewidget/localeglobal.h" #include "timezonewidget/localeglobal.h"
#include "Job.h"
#include "locale/TimeZone.h"
#include <QAbstractListModel>
#include <QObject>
#include <memory> #include <memory>
class Config : public QObject class Config : public QObject
{ {
Q_OBJECT Q_OBJECT
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(QString prettyStatus READ prettyStatus NOTIFY prettyStatusChanged FINAL) Q_PROPERTY( QString prettyStatus READ prettyStatus NOTIFY prettyStatusChanged FINAL )
public: public:
Config( QObject* parent = nullptr ); Config( QObject* parent = nullptr );
@ -41,7 +44,7 @@ public:
CalamaresUtils::Locale::CStringListModel* regionModel() const; CalamaresUtils::Locale::CStringListModel* regionModel() const;
CalamaresUtils::Locale::CStringListModel* zonesModel() const; CalamaresUtils::Locale::CStringListModel* zonesModel() const;
void setLocaleInfo(const QString& initialRegion, const QString& initialZone, const QString& localeGenPath); void setLocaleInfo( const QString& initialRegion, const QString& initialZone, const QString& localeGenPath );
Calamares::JobList createJobs(); Calamares::JobList createJobs();
QMap< QString, QString > localesMap(); QMap< QString, QString > localesMap();
@ -49,8 +52,8 @@ public:
private: private:
CalamaresUtils::Locale::CStringPairList m_regionList; CalamaresUtils::Locale::CStringPairList m_regionList;
CalamaresUtils::Locale::CStringListModel * m_regionModel; CalamaresUtils::Locale::CStringListModel* m_regionModel;
CalamaresUtils::Locale::CStringListModel * m_zonesModel; CalamaresUtils::Locale::CStringListModel* m_zonesModel;
LocaleConfiguration m_selectedLocaleConfiguration; LocaleConfiguration m_selectedLocaleConfiguration;