[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>
#include <QProcess>
Config::Config( QObject* parent )
: QObject( parent )
, m_regionList( CalamaresUtils::Locale::TZRegion::fromZoneTab() ) , m_regionList( CalamaresUtils::Locale::TZRegion::fromZoneTab() )
, m_regionModel( new CalamaresUtils::Locale::CStringListModel( m_regionList ) ) , m_regionModel( new CalamaresUtils::Locale::CStringListModel( m_regionList ) )
, m_zonesModel( new CalamaresUtils::Locale::CStringListModel() ) , m_zonesModel( new CalamaresUtils::Locale::CStringListModel() )
, m_blockTzWidgetSet( false ) , m_blockTzWidgetSet( false )
{ {
connect(m_regionModel, &CalamaresUtils::Locale::CStringListModel::currentIndexChanged, [&]() connect( m_regionModel, &CalamaresUtils::Locale::CStringListModel::currentIndexChanged, [&]() {
{ m_zonesModel->setList( static_cast< const CalamaresUtils::Locale::TZRegion* >(
m_zonesModel->setList(static_cast<const CalamaresUtils::Locale::TZRegion*>(m_regionModel->item(m_regionModel->currentIndex()))->zones()); m_regionModel->item( m_regionModel->currentIndex() ) )
->zones() );
updateLocaleLabels(); updateLocaleLabels();
} ); } );
connect(m_zonesModel, &CalamaresUtils::Locale::CStringListModel::currentIndexChanged, [&]() connect(
{ m_zonesModel, &CalamaresUtils::Locale::CStringListModel::currentIndexChanged, [&]() { updateLocaleLabels(); } );
updateLocaleLabels();
});
} }
Config::~Config() Config::~Config()
@ -86,9 +87,9 @@ Config::setLocaleInfo(const QString& initialRegion, const QString& 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(
static_cast< const TZRegion* >( m_regionModel->item( m_regionModel->currentIndex() ) )->zones() );
this->m_zonesModel->setCurrentIndex( m_zonesModel->indexOf( "New_York" ) ); 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();
@ -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,13 +20,15 @@
#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