From cf59e2884aa6e885e4c3c5c65a645006f4355c45 Mon Sep 17 00:00:00 2001 From: Adriaan de Groot Date: Tue, 24 Mar 2020 12:04:26 +0100 Subject: [PATCH 01/32] [welcome] Reduce warnings from moc-generated code --- src/modules/welcome/checker/ResultsListWidget.cpp | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/modules/welcome/checker/ResultsListWidget.cpp b/src/modules/welcome/checker/ResultsListWidget.cpp index f7442f721..275010b2f 100644 --- a/src/modules/welcome/checker/ResultsListWidget.cpp +++ b/src/modules/welcome/checker/ResultsListWidget.cpp @@ -288,4 +288,6 @@ ResultsListWidget::retranslate() } } +#include "utils/moc-warnings.h" + #include "ResultsListWidget.moc" From 1eec1a9fe79390c27be627631063d9f8a609214b Mon Sep 17 00:00:00 2001 From: Adriaan de Groot Date: Tue, 24 Mar 2020 13:43:19 +0100 Subject: [PATCH 02/32] [libcalamares] Fix typo in API - "asynchronouse" is not a thing --- src/libcalamares/network/Manager.cpp | 2 +- src/libcalamares/network/Manager.h | 2 +- src/modules/netinstall/NetInstallPage.cpp | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/libcalamares/network/Manager.cpp b/src/libcalamares/network/Manager.cpp index 6243b03b3..1d58efba9 100644 --- a/src/libcalamares/network/Manager.cpp +++ b/src/libcalamares/network/Manager.cpp @@ -276,7 +276,7 @@ Manager::synchronousGet( const QUrl& url, const RequestOptions& options ) } QNetworkReply* -Manager::asynchronouseGet( const QUrl& url, const CalamaresUtils::Network::RequestOptions& options ) +Manager::asynchronousGet( const QUrl& url, const CalamaresUtils::Network::RequestOptions& options ) { return asynchronousRun( d->nam(), url, options ); } diff --git a/src/libcalamares/network/Manager.h b/src/libcalamares/network/Manager.h index ddd42f27b..f392cdec0 100644 --- a/src/libcalamares/network/Manager.h +++ b/src/libcalamares/network/Manager.h @@ -146,7 +146,7 @@ public: * This may be a nullptr if an error occurs immediately. * The caller is responsible for cleaning up the reply (eventually). */ - QNetworkReply* asynchronouseGet( const QUrl& url, const RequestOptions& options = RequestOptions() ); + QNetworkReply* asynchronousGet( const QUrl& url, const RequestOptions& options = RequestOptions() ); private: class Private; diff --git a/src/modules/netinstall/NetInstallPage.cpp b/src/modules/netinstall/NetInstallPage.cpp index 352eb9f3e..e21814caa 100644 --- a/src/modules/netinstall/NetInstallPage.cpp +++ b/src/modules/netinstall/NetInstallPage.cpp @@ -187,7 +187,7 @@ NetInstallPage::loadGroupList( const QString& confUrl ) using namespace CalamaresUtils::Network; cDebug() << "NetInstall loading groups from" << confUrl; - QNetworkReply* reply = Manager::instance().asynchronouseGet( + QNetworkReply* reply = Manager::instance().asynchronousGet( QUrl( confUrl ), RequestOptions( RequestOptions::FakeUserAgent | RequestOptions::FollowRedirect, std::chrono::seconds( 30 ) ) ); From 1ec72512757f829c425fd6ecac9d0133eea592dd Mon Sep 17 00:00:00 2001 From: Adriaan de Groot Date: Tue, 24 Mar 2020 14:23:37 +0100 Subject: [PATCH 03/32] [libcalamares] Make isAtVeryEnd() internal --- src/libcalamaresui/ViewManager.cpp | 13 ++++++++++--- src/libcalamaresui/ViewManager.h | 6 ------ 2 files changed, 10 insertions(+), 9 deletions(-) diff --git a/src/libcalamaresui/ViewManager.cpp b/src/libcalamaresui/ViewManager.cpp index 96d4cc3a0..6ee0d5de3 100644 --- a/src/libcalamaresui/ViewManager.cpp +++ b/src/libcalamaresui/ViewManager.cpp @@ -29,8 +29,8 @@ #include "utils/Paste.h" #include "utils/Retranslator.h" #include "viewpages/BlankViewStep.h" -#include "viewpages/ViewStep.h" #include "viewpages/ExecutionViewStep.h" +#include "viewpages/ViewStep.h" #include #include @@ -309,6 +309,13 @@ stepIsExecute( const ViewStepList& steps, int index ) && ( qobject_cast< ExecutionViewStep* >( steps.at( index ) ) != nullptr ); } +static inline bool +isAtVeryEnd( const ViewStepList& steps, int index ) + +{ + return ( index >= steps.count() ) || ( index == steps.count() - 1 && steps.last()->isAtEnd() ); +} + void ViewManager::next() { @@ -412,7 +419,7 @@ ViewManager::updateButtonLabels() m_back->setText( tr( "&Back" ) ); // Cancel button changes label at the end - if ( isAtVeryEnd() ) + if ( isAtVeryEnd( m_steps, m_currentStep ) ) { m_quit->setText( tr( "&Done" ) ); m_quit->setToolTip( quitOnCompleteTooltip ); @@ -473,7 +480,7 @@ ViewManager::confirmCancelInstallation() const auto* const settings = Calamares::Settings::instance(); // When we're at the very end, then it's always OK to exit. - if ( isAtVeryEnd() ) + if ( isAtVeryEnd( m_steps, m_currentStep ) ) { return true; } diff --git a/src/libcalamaresui/ViewManager.h b/src/libcalamaresui/ViewManager.h index 7ca6eb377..a4bedd7bc 100644 --- a/src/libcalamaresui/ViewManager.h +++ b/src/libcalamaresui/ViewManager.h @@ -132,12 +132,6 @@ private: void updateButtonLabels(); void updateCancelEnabled( bool enabled ); - bool isAtVeryEnd() const - { - return ( m_currentStep >= m_steps.count() ) - || ( m_currentStep == m_steps.count() - 1 && m_steps.last()->isAtEnd() ); - } - static ViewManager* s_instance; ViewStepList m_steps; From 112895fddc8ab4827868d9d07ec692a68963f87e Mon Sep 17 00:00:00 2001 From: Adriaan de Groot Date: Tue, 24 Mar 2020 15:06:34 +0100 Subject: [PATCH 04/32] [libcalamares] Keep jobIndex in-sync with the jobs - Never skip updating the jobIndex, because it is used in emitProgress() to find which job to ask for status. --- src/libcalamares/JobQueue.cpp | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/src/libcalamares/JobQueue.cpp b/src/libcalamares/JobQueue.cpp index cf9d9ad65..209c4a416 100644 --- a/src/libcalamares/JobQueue.cpp +++ b/src/libcalamares/JobQueue.cpp @@ -69,6 +69,7 @@ public: if ( anyFailed && !job->isEmergency() ) { cDebug() << "Skipping non-emergency job" << job->prettyName(); + ++m_jobIndex; continue; } @@ -83,10 +84,8 @@ public: message = result.message(); details = result.details(); } - if ( !anyFailed ) - { - ++m_jobIndex; - } + emitProgress( 1.0 ); + ++m_jobIndex; } if ( anyFailed ) { From 184462a8758cb5eb51510a9960f90cde1451518b Mon Sep 17 00:00:00 2001 From: Adriaan de Groot Date: Tue, 24 Mar 2020 15:14:38 +0100 Subject: [PATCH 05/32] [libcalamares] Make status of JobQueue queryable - while the queue is executing (the thread is running jobs) the isRunning() method returns true. - re-work some internals to reset isRunning() before emitting finished() signal. --- src/libcalamares/JobQueue.cpp | 10 +++++++++- src/libcalamares/JobQueue.h | 6 ++++++ 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/src/libcalamares/JobQueue.cpp b/src/libcalamares/JobQueue.cpp index 209c4a416..6a2aa4cba 100644 --- a/src/libcalamares/JobQueue.cpp +++ b/src/libcalamares/JobQueue.cpp @@ -140,7 +140,7 @@ private: m_queue, "failed", Qt::QueuedConnection, Q_ARG( QString, message ), Q_ARG( QString, details ) ); } - void emitFinished() { QMetaObject::invokeMethod( m_queue, "finished", Qt::QueuedConnection ); } + void emitFinished() { QMetaObject::invokeMethod( m_queue, "finish", Qt::QueuedConnection ); } }; JobThread::~JobThread() {} @@ -195,6 +195,7 @@ JobQueue::start() Q_ASSERT( !m_thread->isRunning() ); m_thread->setJobs( std::move( m_jobs ) ); m_jobs.clear(); + m_finished = false; m_thread->start(); } @@ -216,4 +217,11 @@ JobQueue::enqueue( const JobList& jobs ) emit queueChanged( m_jobs ); } +void +JobQueue::finish() +{ + m_finished = true; + emit finished(); +} + } // namespace Calamares diff --git a/src/libcalamares/JobQueue.h b/src/libcalamares/JobQueue.h index a58b873d9..88a2bb0c3 100644 --- a/src/libcalamares/JobQueue.h +++ b/src/libcalamares/JobQueue.h @@ -45,6 +45,11 @@ public: void enqueue( const JobList& jobs ); void start(); + bool isRunning() const { return !m_finished; } + +public slots: + void finish(); + signals: void queueChanged( const JobList& jobs ); void progress( qreal percent, const QString& prettyName ); @@ -57,6 +62,7 @@ private: JobList m_jobs; JobThread* m_thread; GlobalStorage* m_storage; + bool m_finished = true; ///< Initially, not running }; } // namespace Calamares From 1d30c99d89515ccd06bdaa8b8adac75638608636 Mon Sep 17 00:00:00 2001 From: Adriaan de Groot Date: Tue, 24 Mar 2020 15:19:45 +0100 Subject: [PATCH 06/32] [libcalamaresui] The ExecutionViewStep is done when the queue is - While the queue is running, pretend that the EVS is not at the last page. FIXES #1351 --- src/libcalamaresui/viewpages/ExecutionViewStep.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/libcalamaresui/viewpages/ExecutionViewStep.cpp b/src/libcalamaresui/viewpages/ExecutionViewStep.cpp index 8ea918690..c9bc4b8c3 100644 --- a/src/libcalamaresui/viewpages/ExecutionViewStep.cpp +++ b/src/libcalamaresui/viewpages/ExecutionViewStep.cpp @@ -136,7 +136,7 @@ ExecutionViewStep::isAtBeginning() const bool ExecutionViewStep::isAtEnd() const { - return true; + return !JobQueue::instance()->isRunning(); } void From 71b55995ee8a31da2b6ecd80a337ac7edea06230 Mon Sep 17 00:00:00 2001 From: Adriaan de Groot Date: Tue, 24 Mar 2020 15:23:40 +0100 Subject: [PATCH 07/32] [dummypython] Fix up progress reporting - It's annoying to have 100% progress reported (from the processing of list items) and then have another 3 seconds delay. Unrelated to the issue-at-hand, but spotted in testing. --- src/modules/dummypython/main.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/modules/dummypython/main.py b/src/modules/dummypython/main.py index 2da9b4760..96de6030f 100644 --- a/src/modules/dummypython/main.py +++ b/src/modules/dummypython/main.py @@ -102,7 +102,7 @@ def run(): status = _("Dummy python step {}").format(str(c) + ":" + repr(k)) libcalamares.utils.debug(_("Dummy python step {}").format(str(k))) sleep(1) - libcalamares.job.setprogress(c * 1.0 / len(configlist)) + libcalamares.job.setprogress(c * 1.0 / (len(configlist)+1)) c += 1 sleep(3) From 2d095572974ec6021a8ed890cd014a0caa73644e Mon Sep 17 00:00:00 2001 From: Camilo Higuita Date: Tue, 24 Mar 2020 09:26:24 -0500 Subject: [PATCH 08/32] update wlecome to latest --- src/modules/welcome/CMakeLists.txt | 2 - src/modules/welcome/Config.cpp | 49 ++++++++++++++++++--- src/modules/welcome/Config.h | 30 ++++++++++--- src/modules/welcomeq/WelcomeQmlViewStep.cpp | 38 +++++++++++++++- 4 files changed, 103 insertions(+), 16 deletions(-) diff --git a/src/modules/welcome/CMakeLists.txt b/src/modules/welcome/CMakeLists.txt index 3298ba716..9700b1601 100644 --- a/src/modules/welcome/CMakeLists.txt +++ b/src/modules/welcome/CMakeLists.txt @@ -12,8 +12,6 @@ else() add_definitions( -DWITHOUT_LIBPARTED ) endif() -include_directories( ${PROJECT_BINARY_DIR}/src/libcalamaresui ) - set( CHECKER_SOURCES checker/CheckerContainer.cpp checker/GeneralRequirements.cpp diff --git a/src/modules/welcome/Config.cpp b/src/modules/welcome/Config.cpp index 1df4e1cab..2fa0ce156 100644 --- a/src/modules/welcome/Config.cpp +++ b/src/modules/welcome/Config.cpp @@ -27,9 +27,10 @@ void RequirementsModel::setRequirementsList( const Calamares::RequirementsList& requirements ) { + CALAMARES_RETRANSLATE_SLOT( &RequirementsModel::retranslate ) + emit beginResetModel(); m_requierements = requirements; - m_satisfiedRequirements = true; auto isUnSatisfied = []( const Calamares::RequirementEntry& e ) { return !e.satisfied; }; auto isMandatoryAndUnSatisfied = []( const Calamares::RequirementEntry& e ) { return e.mandatory && !e.satisfied; }; @@ -115,7 +116,7 @@ Config::retranslate() m_genericWelcomeMessage = message.arg( *Calamares::Branding::VersionedName ); emit genericWelcomeMessageChanged(); -// ui->supportButton->setText( tr( "%1 support" ).arg( *Calamares::Branding::ShortProductName ) ); + m_requirementsModel->retranslate(); } CalamaresUtils::Locale::LabelModel* @@ -231,6 +232,7 @@ QString Config::donateUrl() const void Config::setDonateUrl(const QString& url) { m_donateUrl = url; + emit donateUrlChanged(); } QString Config::knownIssuesUrl() const @@ -241,11 +243,13 @@ QString Config::knownIssuesUrl() const void Config::setKnownIssuesUrl(const QString& url) { m_knownIssuesUrl = url; + emit knownIssuesUrlChanged(); } void Config::setReleaseNotesUrl(const QString& url) { m_releaseNotesUrl = url; + emit releaseNotesUrlChanged(); } QString Config::releaseNotesUrl() const @@ -261,13 +265,46 @@ QString Config::supportUrl() const void Config::setSupportUrl(const QString& url) { m_supportUrl = url; + emit supportUrlChanged(); } +void RequirementsModel::retranslate() +{ + if ( !m_satisfiedRequirements ) + { + QString message; + const bool setup = Calamares::Settings::instance()->isSetupMode(); + if ( !m_satisfiedMandatory ) + { + message = setup ? tr( "This computer does not satisfy the minimum " + "requirements for setting up %1.
" + "Setup cannot continue. " + "Details..." ) + : tr( "This computer does not satisfy the minimum " + "requirements for installing %1.
" + "Installation cannot continue. " + "Details..." ); + }else + { + message = setup ? tr( "This computer does not satisfy some of the " + "recommended requirements for setting up %1.
" + "Setup can continue, but some features " + "might be disabled." ) + : tr( "This computer does not satisfy some of the " + "recommended requirements for installing %1.
" + "Installation can continue, but some features " + "might be disabled." ); + } + m_warningMessage = message.arg( *Calamares::Branding::ShortVersionedName ); + }else + { + m_warningMessage = tr( "This program will ask you some questions and " + "set up %2 on your computer." ) + .arg( *Calamares::Branding::ProductName ); + } - - - - + emit warningMessageChanged(); +} diff --git a/src/modules/welcome/Config.h b/src/modules/welcome/Config.h index 71f2120f9..2c7674ecd 100644 --- a/src/modules/welcome/Config.h +++ b/src/modules/welcome/Config.h @@ -32,6 +32,7 @@ class RequirementsModel : public QAbstractListModel Q_PROPERTY(bool satisfiedRequirements READ satisfiedRequirements NOTIFY satisfiedRequirementsChanged FINAL) Q_PROPERTY(bool satisfiedMandatory READ satisfiedMandatory NOTIFY satisfiedMandatoryChanged FINAL) + Q_PROPERTY( QString warningMessage READ warningMessage NOTIFY warningMessageChanged FINAL ) public: enum Roles : short @@ -71,6 +72,13 @@ public: return m_requierements.count(); } + QString warningMessage() const + { + return m_warningMessage; + } + + void retranslate(); + QVariant data(const QModelIndex& index, int role) const override; protected: @@ -81,9 +89,12 @@ private: bool m_satisfiedRequirements = false; bool m_satisfiedMandatory = false; + QString m_warningMessage; + signals: void satisfiedRequirementsChanged(bool value); void satisfiedMandatoryChanged(); + void warningMessageChanged(); }; @@ -101,10 +112,12 @@ class Config : public QObject Q_PROPERTY( QString genericWelcomeMessage MEMBER m_genericWelcomeMessage NOTIFY genericWelcomeMessageChanged FINAL ) Q_PROPERTY( QString warningMessage MEMBER m_warningMessage CONSTANT FINAL ) - Q_PROPERTY(QString supportUrl MEMBER m_supportUrl CONSTANT FINAL) - Q_PROPERTY(QString knownIssuesUrl MEMBER m_knownIssuesUrl CONSTANT FINAL) - Q_PROPERTY(QString releaseNotesUrl MEMBER m_releaseNotesUrl CONSTANT FINAL) - Q_PROPERTY(QString donateUrl MEMBER m_donateUrl CONSTANT FINAL) + Q_PROPERTY( QString supportUrl MEMBER m_supportUrl NOTIFY supportUrlChanged FINAL ) + Q_PROPERTY( QString knownIssuesUrl MEMBER m_knownIssuesUrl NOTIFY knownIssuesUrlChanged FINAL ) + Q_PROPERTY( QString releaseNotesUrl MEMBER m_releaseNotesUrl NOTIFY releaseNotesUrlChanged FINAL ) + Q_PROPERTY (QString donateUrl MEMBER m_donateUrl NOTIFY donateUrlChanged FINAL ) + + Q_PROPERTY( bool isNextEnabled MEMBER m_isNextEnabled NOTIFY isNextEnabledChanged FINAL ) public: Config( QObject* parent = nullptr ); @@ -144,9 +157,7 @@ private: bool m_isNextEnabled = false; CalamaresUtils::Locale::LabelModel* m_languages; - QString m_genericWelcomeMessage = tr("This program will ask you some questions and set up your installation"); - - QString m_warningMessage = tr("This program does not satisfy the minimum requirements for installing.\nInstallation can not continue"); + QString m_genericWelcomeMessage; QString m_supportUrl; QString m_knownIssuesUrl; @@ -158,6 +169,11 @@ signals: void localeIndexChanged( int localeIndex ); void isNextEnabledChanged( bool isNextEnabled ); void genericWelcomeMessageChanged(); + void supportUrlChanged(); + void knownIssuesUrlChanged(); + void releaseNotesUrlChanged(); + void donateUrlChanged(); + }; #endif diff --git a/src/modules/welcomeq/WelcomeQmlViewStep.cpp b/src/modules/welcomeq/WelcomeQmlViewStep.cpp index ef49dea32..0961ce67f 100644 --- a/src/modules/welcomeq/WelcomeQmlViewStep.cpp +++ b/src/modules/welcomeq/WelcomeQmlViewStep.cpp @@ -41,7 +41,7 @@ CALAMARES_PLUGIN_FACTORY_DEFINITION( WelcomeQmlViewStepFactory, registerPlugin< WelcomeQmlViewStep::WelcomeQmlViewStep( QObject* parent ) : Calamares::QmlViewStep(parent ) - , m_config( new Config( ) ) // the qml singleton takes ownership and deletes it + , m_config( new Config( this ) ) // the qml singleton takes ownership and deletes it // , m_nextEnabled( false ) , m_requirementsChecker( new GeneralRequirements( this ) ) @@ -98,10 +98,46 @@ WelcomeQmlViewStep::jobs() const return Calamares::JobList(); } +/** @brief Look up a URL for a button + * + * Looks up @p key in @p map; if it is a *boolean* value, then + * assume an old-style configuration, and fetch the string from + * the branding settings @p e. If it is a string, not a boolean, + * use it as-is. If not found, or a weird type, returns empty. + * + * This allows switching the showKnownIssuesUrl and similar settings + * in welcome.conf from a boolean (deferring to branding) to an + * actual string for immediate use. Empty strings, as well as + * "false" as a setting, will hide the buttons as before. + */ +static QString +jobOrBrandingSetting( Calamares::Branding::StringEntry e, const QVariantMap& map, const QString& key ) +{ + if ( !map.contains( key ) ) + { + return QString(); + } + auto v = map.value( key ); + if ( v.type() == QVariant::Bool ) + { + return v.toBool() ? ( *e ) : QString(); + } + if ( v.type() == QVariant::String ) + { + return v.toString(); + } + + return QString(); +} + void WelcomeQmlViewStep::setConfigurationMap( const QVariantMap& configurationMap ) { using Calamares::Branding; + m_config->setSupportUrl( jobOrBrandingSetting( Branding::SupportUrl, configurationMap, "showSupportUrl" ) ); + m_config->setKnownIssuesUrl( jobOrBrandingSetting( Branding::KnownIssuesUrl, configurationMap, "showKnownIssuesUrl" ) ); + m_config->setReleaseNotesUrl( jobOrBrandingSetting( Branding::ReleaseNotesUrl, configurationMap, "showReleaseNotesUrl" ) ); + m_config->setDonateUrl( CalamaresUtils::getString( configurationMap, "showDonateUrl" ) ); // TODO: expand Config class and set the remaining fields // with the configurationMap all those properties can be accesed withouth having to declare a property, get and setter for each From 1c0e69e1c21cb40eeb3a2537739427ca1c095748 Mon Sep 17 00:00:00 2001 From: Camilo Higuita Date: Tue, 24 Mar 2020 09:33:09 -0500 Subject: [PATCH 09/32] wraning message is not from conf but form the requirements model --- src/modules/welcome/Config.h | 1 - 1 file changed, 1 deletion(-) diff --git a/src/modules/welcome/Config.h b/src/modules/welcome/Config.h index 2c7674ecd..043866eb6 100644 --- a/src/modules/welcome/Config.h +++ b/src/modules/welcome/Config.h @@ -110,7 +110,6 @@ class Config : public QObject Q_PROPERTY (int localeIndex READ localeIndex WRITE setLocaleIndex NOTIFY localeIndexChanged) Q_PROPERTY( QString genericWelcomeMessage MEMBER m_genericWelcomeMessage NOTIFY genericWelcomeMessageChanged FINAL ) - Q_PROPERTY( QString warningMessage MEMBER m_warningMessage CONSTANT FINAL ) Q_PROPERTY( QString supportUrl MEMBER m_supportUrl NOTIFY supportUrlChanged FINAL ) Q_PROPERTY( QString knownIssuesUrl MEMBER m_knownIssuesUrl NOTIFY knownIssuesUrlChanged FINAL ) From 1de2a4ff14eb7200e7c1330ea09d41c09a7275c7 Mon Sep 17 00:00:00 2001 From: Adriaan de Groot Date: Tue, 24 Mar 2020 15:38:43 +0100 Subject: [PATCH 10/32] [libcalamares] Introduce quit-at-end - In some cases, it makes sense to close Calamares automatically when it is done. Set *quit-at-end* to do so -- although this probably also means you should remove the *finished* page. --- settings.conf | 8 ++++++++ src/libcalamares/Settings.cpp | 1 + src/libcalamares/Settings.h | 4 ++++ src/libcalamaresui/ViewManager.cpp | 4 ++++ 4 files changed, 17 insertions(+) diff --git a/settings.conf b/settings.conf index c2aa48a37..982f4ebbe 100644 --- a/settings.conf +++ b/settings.conf @@ -188,3 +188,11 @@ disable-cancel: false # # YAML: boolean. disable-cancel-during-exec: false + +# If this is set to true, then once the end of the sequence has +# been reached, the quit (done) button is clicked automatically +# and Calamares will close. Default is false: the user will see +# that the end of installation has been reached, and that things are ok. +# +# +quit-at-end: false diff --git a/src/libcalamares/Settings.cpp b/src/libcalamares/Settings.cpp index 7e1c15e30..da388ea32 100644 --- a/src/libcalamares/Settings.cpp +++ b/src/libcalamares/Settings.cpp @@ -232,6 +232,7 @@ Settings::Settings( const QString& settingsFilePath, bool debugMode ) m_isSetupMode = requireBool( config, "oem-setup", !m_doChroot ); m_disableCancel = requireBool( config, "disable-cancel", false ); m_disableCancelDuringExec = requireBool( config, "disable-cancel-during-exec", false ); + m_quitAtEnd = requireBool( config, "quit-at-end", false ); } catch ( YAML::Exception& e ) { diff --git a/src/libcalamares/Settings.h b/src/libcalamares/Settings.h index 94474c09c..3cedd6e2b 100644 --- a/src/libcalamares/Settings.h +++ b/src/libcalamares/Settings.h @@ -101,6 +101,9 @@ public: /** @brief Temporary setting of disable-cancel: can't cancel during exec. */ bool disableCancelDuringExec() const { return m_disableCancelDuringExec; } + /** @brief Is quit-at-end set? (Quit automatically when done) */ + bool quitAtEnd() const { return m_quitAtEnd; } + private: static Settings* s_instance; @@ -117,6 +120,7 @@ private: bool m_promptInstall; bool m_disableCancel; bool m_disableCancelDuringExec; + bool m_quitAtEnd; }; } // namespace Calamares diff --git a/src/libcalamaresui/ViewManager.cpp b/src/libcalamaresui/ViewManager.cpp index 6ee0d5de3..9972c3af9 100644 --- a/src/libcalamaresui/ViewManager.cpp +++ b/src/libcalamaresui/ViewManager.cpp @@ -426,6 +426,10 @@ ViewManager::updateButtonLabels() m_quit->setVisible( true ); // At end, always visible and enabled. setButtonIcon( m_quit, "dialog-ok-apply" ); updateCancelEnabled( true ); + if ( settings->quitAtEnd() ) + { + m_quit->click(); + } } else { From 6bef980636910c0d4e15df1aee303ee3b0804cde Mon Sep 17 00:00:00 2001 From: Adriaan de Groot Date: Tue, 24 Mar 2020 15:45:35 +0100 Subject: [PATCH 11/32] Changes: document quit-at-end --- CHANGES | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/CHANGES b/CHANGES index b8309028f..879769453 100644 --- a/CHANGES +++ b/CHANGES @@ -25,6 +25,11 @@ This release contains contributions from (alphabetically by first name): more configurable: the branding key *sidebar* controls it. The sidebar can be shown as a widget (default, as it has been), hidden, or use a new QML view which is more easily customised. + - A new `settings.conf` key *quit-at-end* will automatically close + Calamares (by clicking on the *Done* button) when the end of the + sequence is reached. If *finished* is the last module in the sequence, + this will run whatever it is configured for; you can also leave out + the finished page and Calamares will close after the exec parts. ## Modules ## - *packages* now reports more details in the installation progress-bar. From 8ff1996e1269494d4468b770248ad5d9c3fbbc7b Mon Sep 17 00:00:00 2001 From: Camilo Higuita Date: Tue, 24 Mar 2020 09:47:53 -0500 Subject: [PATCH 12/32] add the localq module and config to locale --- src/modules/locale/CMakeLists.txt | 1 + src/modules/locale/Config.cpp | 314 ++++++++++++++++++++++ src/modules/locale/Config.h | 84 ++++++ src/modules/localeq/CMakeLists.txt | 42 +++ src/modules/localeq/LocaleQmlViewStep.cpp | 203 ++++++++++++++ src/modules/localeq/LocaleQmlViewStep.h | 76 ++++++ src/modules/localeq/localeq.conf | 97 +++++++ src/modules/localeq/localeq.qml | 113 ++++++++ 8 files changed, 930 insertions(+) create mode 100644 src/modules/locale/Config.cpp create mode 100644 src/modules/locale/Config.h create mode 100644 src/modules/localeq/CMakeLists.txt create mode 100644 src/modules/localeq/LocaleQmlViewStep.cpp create mode 100644 src/modules/localeq/LocaleQmlViewStep.h create mode 100644 src/modules/localeq/localeq.conf create mode 100644 src/modules/localeq/localeq.qml diff --git a/src/modules/locale/CMakeLists.txt b/src/modules/locale/CMakeLists.txt index cae2ea41c..2643ff548 100644 --- a/src/modules/locale/CMakeLists.txt +++ b/src/modules/locale/CMakeLists.txt @@ -13,6 +13,7 @@ calamares_add_plugin( locale EXPORT_MACRO PLUGINDLLEXPORT_PRO SOURCES ${geoip_src} + Config.cpp LCLocaleDialog.cpp LocaleConfiguration.cpp LocalePage.cpp diff --git a/src/modules/locale/Config.cpp b/src/modules/locale/Config.cpp new file mode 100644 index 000000000..9bbbd5807 --- /dev/null +++ b/src/modules/locale/Config.cpp @@ -0,0 +1,314 @@ +/* === This file is part of Calamares - === + * + * Copyright 2019-2020, Adriaan de Groot + * + * Calamares is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * Calamares is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with Calamares. If not, see . + */ + +#include "Config.h" + +#include +#include + +#include "SetTimezoneJob.h" +#include "timezonewidget/timezonewidget.h" + +#include "GlobalStorage.h" +#include "JobQueue.h" +#include "LCLocaleDialog.h" +#include "Settings.h" + +#include "locale/Label.h" +#include "locale/TimeZone.h" +#include "utils/CalamaresUtilsGui.h" +#include "utils/Logger.h" +#include "utils/Retranslator.h" + +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(m_regionModel->item(m_regionModel->currentIndex()))->zones()); + updateLocaleLabels(); + }); + + connect(m_zonesModel, &CalamaresUtils::Locale::CStringListModel::currentIndexChanged, [&]() + { + updateLocaleLabels(); + }); +} + +Config::~Config() +{ + qDeleteAll( m_regionList ); +} + +CalamaresUtils::Locale::CStringListModel * +Config::zonesModel() const +{ + return m_zonesModel; +} + +CalamaresUtils::Locale::CStringListModel * +Config::regionModel() const +{ + return m_regionModel; +} + +void +Config::setLocaleInfo(const QString& initialRegion, const QString& initialZone, const QString& localeGenPath) +{ + using namespace CalamaresUtils::Locale; + + cDebug()<< "REGION MODEL SIZE" << initialRegion << initialZone; + auto* region = m_regionList.find< TZRegion >( initialRegion ); + if ( region && region->zones().find< TZZone >( initialZone ) ) + { + this->m_regionModel->setCurrentIndex(m_regionModel->indexOf(initialRegion)); + m_zonesModel->setList(region->zones()); + this->m_zonesModel->setCurrentIndex(m_zonesModel->indexOf(initialZone)); + } + else + { + this->m_regionModel->setCurrentIndex(m_regionModel->indexOf("America")); + m_zonesModel->setList(static_cast(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, + // and others ship a separate file /usr/share/i18n/SUPPORTED with a clean list of + // supported locales. We first try that one, and if it doesn't exist, we fall back + // to parsing the lines from locale.gen + m_localeGenLines.clear(); + QFile supported( "/usr/share/i18n/SUPPORTED" ); + QByteArray ba; + + 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 ) + { + m_localeGenLines.append( QString::fromLatin1( line.simplified() ) ); + } + } + else + { + QFile localeGen( localeGenPath ); + if ( localeGen.open( QIODevice::ReadOnly | QIODevice::Text ) ) + { + ba = localeGen.readAll(); + localeGen.close(); + } + else + { + cWarning() << "Cannot open file" << localeGenPath + << ". 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 ) + { + 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 ); + } + } + + 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() ? QLatin1String( "/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 ) ) + { + 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(); + updateLocaleLabels(); +} + +void Config::updateGlobalLocale() +{ + auto* gs = Calamares::JobQueue::instance()->globalStorage(); + const QString bcp47 = m_selectedLocaleConfiguration.toBcp47(); + gs->insert( "locale", bcp47 ); +} + +void Config::updateGlobalStorage() +{ + auto* gs = Calamares::JobQueue::instance()->globalStorage(); + + const auto* location = currentLocation(); + bool locationChanged = ( location->region() != gs->value( "locationRegion" ) ) + || ( location->zone() != gs->value( "locationZone" ) ); + + gs->insert( "locationRegion", location->region() ); + gs->insert( "locationZone", location->zone() ); + + updateGlobalLocale(); + + // 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. + #ifndef DEBUG_TIMEZONES + if ( locationChanged && Calamares::Settings::instance()->doChroot() ) + { + QProcess::execute( "timedatectl", // depends on systemd + { "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 ) + { + newLocale.setLanguage( m_selectedLocaleConfiguration.language() ); + } + if ( !m_selectedLocaleConfiguration.isEmpty() && m_selectedLocaleConfiguration.explicit_lc ) + { + newLocale.lc_numeric = m_selectedLocaleConfiguration.lc_numeric; + newLocale.lc_time = m_selectedLocaleConfiguration.lc_time; + newLocale.lc_monetary = m_selectedLocaleConfiguration.lc_monetary; + newLocale.lc_paper = m_selectedLocaleConfiguration.lc_paper; + newLocale.lc_name = m_selectedLocaleConfiguration.lc_name; + newLocale.lc_address = m_selectedLocaleConfiguration.lc_address; + newLocale.lc_telephone = m_selectedLocaleConfiguration.lc_telephone; + newLocale.lc_measurement = m_selectedLocaleConfiguration.lc_measurement; + newLocale.lc_identification = m_selectedLocaleConfiguration.lc_identification; + } + newLocale.explicit_lang = m_selectedLocaleConfiguration.explicit_lang; + newLocale.explicit_lc = m_selectedLocaleConfiguration.explicit_lc; + + m_selectedLocaleConfiguration = newLocale; + updateLocaleLabels(); +} + +void +Config::updateLocaleLabels() +{ + LocaleConfiguration lc + = m_selectedLocaleConfiguration.isEmpty() ? guessLocaleConfiguration() : m_selectedLocaleConfiguration; + auto labels = prettyLocaleStatus( lc ); + emit prettyStatusChanged(); +} + + +std::pair +Config::prettyLocaleStatus(const LocaleConfiguration& lc) const +{ + using CalamaresUtils::Locale::Label; + + Label lang( lc.language(), Label::LabelFormat::AlwaysWithCountry ); + Label num( lc.lc_numeric, Label::LabelFormat::AlwaysWithCountry ); + + return std::make_pair< QString, QString >( + tr( "The system language will be set to %1." ).arg( lang.label() ), + tr( "The numbers and dates locale will be set to %1." ).arg( num.label() ) ); +} + +Calamares::JobList Config::createJobs() +{ + QList< Calamares::job_ptr > list; + const CalamaresUtils::Locale::TZZone* location = currentLocation(); + + Calamares::Job* j = new SetTimezoneJob( location->region(), location->zone() ); + list.append( Calamares::job_ptr( j ) ); + + return list; +} + +LocaleConfiguration Config::guessLocaleConfiguration() const +{ + return LocaleConfiguration::fromLanguageAndLocation( + QLocale().name(), m_localeGenLines, currentLocation() ? currentLocation()->country() : "" ); +} + +QMap Config::localesMap() +{ + return m_selectedLocaleConfiguration.isEmpty() ? guessLocaleConfiguration().toMap() + : m_selectedLocaleConfiguration.toMap(); +} + +QString Config::prettyStatus() const +{ + QString status; + status += tr( "Set timezone to %1/%2.
" ).arg( m_regionModel->item(m_regionModel->currentIndex())->tr() ).arg( m_zonesModel->item(m_zonesModel->currentIndex())->tr() ); + + LocaleConfiguration lc + = m_selectedLocaleConfiguration.isEmpty() ? guessLocaleConfiguration() : m_selectedLocaleConfiguration; + auto labels = prettyLocaleStatus( lc ); + status += labels.first + "
"; + status += labels.second + "
"; + + return status; +} + + +const CalamaresUtils::Locale::TZZone * Config::currentLocation() const +{ + return static_cast(m_zonesModel->item(m_zonesModel->currentIndex())); +} diff --git a/src/modules/locale/Config.h b/src/modules/locale/Config.h new file mode 100644 index 000000000..2af83b398 --- /dev/null +++ b/src/modules/locale/Config.h @@ -0,0 +1,84 @@ +/* === This file is part of Calamares - === + * + * Copyright 2019-2020, Adriaan de Groot + * + * Calamares is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * Calamares is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with Calamares. If not, see . + */ + +#ifndef LOCALE_CONFIG_H +#define LOCALE_CONFIG_H + +#include +#include +#include +#include "Job.h" +#include "locale/TimeZone.h" +#include "LocaleConfiguration.h" +#include "timezonewidget/localeglobal.h" +#include + +class Config : public QObject +{ + Q_OBJECT + Q_PROPERTY(CalamaresUtils::Locale::CStringListModel * zonesModel READ zonesModel CONSTANT FINAL) + Q_PROPERTY(CalamaresUtils::Locale::CStringListModel * regionModel READ regionModel CONSTANT FINAL) + Q_PROPERTY(QString prettyStatus READ prettyStatus NOTIFY prettyStatusChanged FINAL) + +public: + Config( QObject* parent = nullptr ); + ~Config(); + CalamaresUtils::Locale::CStringListModel* regionModel() const; + CalamaresUtils::Locale::CStringListModel* zonesModel() const; + + void setLocaleInfo(const QString& initialRegion, const QString& initialZone, const QString& localeGenPath); + + Calamares::JobList createJobs(); + QMap< QString, QString > localesMap(); + QString prettyStatus() const; + +private: + CalamaresUtils::Locale::CStringPairList m_regionList; + CalamaresUtils::Locale::CStringListModel * m_regionModel; + CalamaresUtils::Locale::CStringListModel * m_zonesModel; + + LocaleConfiguration m_selectedLocaleConfiguration; + + QStringList m_localeGenLines; + int m_currentRegion = -1; + + bool m_blockTzWidgetSet; + + LocaleConfiguration guessLocaleConfiguration() const; + + // For the given locale config, return two strings describing + // the settings for language and numbers. + std::pair< QString, QString > prettyLocaleStatus( const LocaleConfiguration& ) const; + + /** @brief Update the GS *locale* key with the selected system language. + * + * This uses whatever is set in m_selectedLocaleConfiguration as the language, + * and writes it to GS *locale* key (as a string, in BCP47 format). + */ + void updateGlobalLocale(); + void updateGlobalStorage(); + void updateLocaleLabels(); + + const CalamaresUtils::Locale::TZZone* currentLocation() const; + +signals: + void prettyStatusChanged(); +}; + + +#endif diff --git a/src/modules/localeq/CMakeLists.txt b/src/modules/localeq/CMakeLists.txt new file mode 100644 index 000000000..99fac2a7e --- /dev/null +++ b/src/modules/localeq/CMakeLists.txt @@ -0,0 +1,42 @@ +# When debugging the timezone widget, add this debugging definition +# to have a debugging-friendly timezone widget, debug logging, +# and no intrusive timezone-setting while clicking around. +option( DEBUG_TIMEZONES "Debug-friendly timezone widget." OFF ) +if( DEBUG_TIMEZONES ) + add_definitions( -DDEBUG_TIMEZONES ) +endif() + +set( _locale ${CMAKE_CURRENT_SOURCE_DIR}/../locale ) + +include_directories( ${PROJECT_BINARY_DIR}/src/libcalamaresui ${CMAKE_CURRENT_SOURCE_DIR}/../../libcalamares ${_locale} ) + +calamares_add_plugin( localeq + TYPE viewmodule + EXPORT_MACRO PLUGINDLLEXPORT_PRO + SOURCES + ${geoip_src} + LocaleQmlViewStep.cpp + ${_locale}/LocaleConfiguration.cpp + ${_locale}/Config.cpp + ${_locale}/SetTimezoneJob.cpp + ${_locale}/timezonewidget/localeglobal.cpp + RESOURCES + ${_locale}/locale.qrc + LINK_PRIVATE_LIBRARIES + calamaresui + Qt5::Network + ${geoip_libs} + ${YAMLCPP_LIBRARY} + SHARED_LIB +) + +# add_executable( localeqmltest qmlmain.cpp Config.cpp LocaleQmlViewStep.cpp LocaleConfiguration.cpp timezonewidget/localeglobal.cpp SetTimezoneJob.cpp ${geoip_src} ) +# target_link_libraries( localeqmltest PRIVATE calamaresui Qt5::Core Qt5::Network Qt5::DBus ${geoip_libs}) +# set_target_properties( localeqmltest +# PROPERTIES +# ENABLE_EXPORTS TRUE +# RUNTIME_OUTPUT_NAME localeqmltest +# ) +# calamares_automoc( localeqmltest ) +# calamares_autouic( localeqmltest ) + diff --git a/src/modules/localeq/LocaleQmlViewStep.cpp b/src/modules/localeq/LocaleQmlViewStep.cpp new file mode 100644 index 000000000..8376b4f1d --- /dev/null +++ b/src/modules/localeq/LocaleQmlViewStep.cpp @@ -0,0 +1,203 @@ +/* === This file is part of Calamares - === + * + * Copyright 2014-2015, Teo Mrnjavac + * Copyright 2018,2020 Adriaan de Groot + * + * Calamares is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * Calamares is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with Calamares. If not, see . + */ + +#include "LocaleQmlViewStep.h" + +#include "GlobalStorage.h" +#include "JobQueue.h" + +#include "geoip/Handler.h" +#include "network/Manager.h" +#include "utils/CalamaresUtilsGui.h" +#include "utils/Logger.h" +#include "utils/Variant.h" +#include "utils/Yaml.h" + +#include "timezonewidget/localeglobal.h" + +#include "Branding.h" +#include "modulesystem/ModuleManager.h" +#include +#include +#include +#include + +CALAMARES_PLUGIN_FACTORY_DEFINITION( LocaleQmlViewStepFactory, registerPlugin< LocaleQmlViewStep >(); ) + +LocaleQmlViewStep::LocaleQmlViewStep( QObject* parent ) +: Calamares::QmlViewStep( parent ) +, m_config( new Config( this ) ) +, m_nextEnabled( false ) +, m_geoip( nullptr ) +{ + emit nextStatusChanged( m_nextEnabled ); +} + +QObject* +LocaleQmlViewStep::getConfig() +{ + return m_config; +} + +void +LocaleQmlViewStep::fetchGeoIpTimezone() +{ + if ( m_geoip && m_geoip->isValid() ) + { + m_startingTimezone = m_geoip->get(); + if ( !m_startingTimezone.isValid() ) + { + cWarning() << "GeoIP lookup at" << m_geoip->url() << "failed."; + } + } + + m_config->setLocaleInfo(m_startingTimezone.first, m_startingTimezone.second, m_localeGenPath); +} + +Calamares::RequirementsList LocaleQmlViewStep::checkRequirements() +{ + LocaleGlobal::init(); + if ( m_geoip && m_geoip->isValid() ) + { + auto& network = CalamaresUtils::Network::Manager::instance(); + if ( network.hasInternet() ) + { + fetchGeoIpTimezone(); + } + else + { + if ( network.synchronousPing( m_geoip->url() ) ) + { + fetchGeoIpTimezone(); + } + } + } + + return Calamares::RequirementsList(); +} + +QString +LocaleQmlViewStep::prettyName() const +{ + return tr( "Location" ); +} + +bool +LocaleQmlViewStep::isNextEnabled() const +{ + // TODO: should return true + return true; +} + +bool +LocaleQmlViewStep::isBackEnabled() const +{ + // TODO: should return true (it's weird that you are not allowed to have welcome *after* anything + return true; +} + + +bool +LocaleQmlViewStep::isAtBeginning() const +{ + // TODO: adjust to "pages" in the QML + return true; +} + + +bool +LocaleQmlViewStep::isAtEnd() const +{ + // TODO: adjust to "pages" in the QML + return true; +} + +Calamares::JobList +LocaleQmlViewStep::jobs() const +{ + return m_jobs; +} + +void LocaleQmlViewStep::onActivate() +{ + // TODO no sure if it is needed at all or for the abstract class to start something +} + +void LocaleQmlViewStep::onLeave() +{ + if ( true ) + { + m_jobs = m_config->createJobs(); +// m_prettyStatus = m_actualWidget->prettyStatus(); + + auto map = m_config->localesMap(); + QVariantMap vm; + for ( auto it = map.constBegin(); it != map.constEnd(); ++it ) + { + vm.insert( it.key(), it.value() ); + } + + Calamares::JobQueue::instance()->globalStorage()->insert( "localeConf", vm ); + } + else + { + m_jobs.clear(); + Calamares::JobQueue::instance()->globalStorage()->remove( "localeConf" ); + } +} + +void LocaleQmlViewStep::setConfigurationMap(const QVariantMap& configurationMap) +{ + QString region = CalamaresUtils::getString( configurationMap, "region" ); + QString zone = CalamaresUtils::getString( configurationMap, "zone" ); + if ( !region.isEmpty() && !zone.isEmpty() ) + { + m_startingTimezone = CalamaresUtils::GeoIP::RegionZonePair( region, zone ); + } + else + { + m_startingTimezone + = CalamaresUtils::GeoIP::RegionZonePair( QStringLiteral( "America" ), QStringLiteral( "New_York" ) ); + } + + m_localeGenPath = CalamaresUtils::getString( configurationMap, "localeGenPath" ); + if ( m_localeGenPath.isEmpty() ) + { + m_localeGenPath = QStringLiteral( "/etc/locale.gen" ); + } + + bool ok = false; + QVariantMap geoip = CalamaresUtils::getSubMap( configurationMap, "geoip", ok ); + if ( ok ) + { + QString url = CalamaresUtils::getString( geoip, "url" ); + QString style = CalamaresUtils::getString( geoip, "style" ); + QString selector = CalamaresUtils::getString( geoip, "selector" ); + + m_geoip = std::make_unique< CalamaresUtils::GeoIP::Handler >( style, url, selector ); + if ( !m_geoip->isValid() ) + { + cWarning() << "GeoIP Style" << style << "is not recognized."; + } + } + + checkRequirements(); + Calamares::QmlViewStep::setConfigurationMap( configurationMap ); // call parent implementation last + setContextProperty( "Localeq", m_config ); +} diff --git a/src/modules/localeq/LocaleQmlViewStep.h b/src/modules/localeq/LocaleQmlViewStep.h new file mode 100644 index 000000000..0639274d6 --- /dev/null +++ b/src/modules/localeq/LocaleQmlViewStep.h @@ -0,0 +1,76 @@ +/* === This file is part of Calamares - === + * + * Copyright 2019-2020 Adriaan de Groot + * + * Calamares is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * Calamares is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with Calamares. If not, see . + */ + +#ifndef LOCALE_QMLVIEWSTEP_H +#define LOCALE_QMLVIEWSTEP_H + +#include "Config.h" +#include "geoip/Handler.h" +#include "geoip/Interface.h" +#include "utils/PluginFactory.h" +#include "viewpages/QmlViewStep.h" +#include + +#include +#include + +#include + +class PLUGINDLLEXPORT LocaleQmlViewStep : public Calamares::QmlViewStep +{ + Q_OBJECT + +public: + explicit LocaleQmlViewStep( QObject* parent = nullptr ); + + QString prettyName() const override; + + bool isNextEnabled() const override; + bool isBackEnabled() const override; + + bool isAtBeginning() const override; + bool isAtEnd() const override; + + Calamares::JobList jobs() const override; + void onActivate() override; + void onLeave() override; + + void setConfigurationMap( const QVariantMap& configurationMap ) override; + QObject* getConfig() override; + + virtual Calamares::RequirementsList checkRequirements() override; + +private: + // TODO: a generic QML viewstep should return a config object from a method + Config *m_config; + + bool m_nextEnabled; + QString m_prettyStatus; + + CalamaresUtils::GeoIP::RegionZonePair m_startingTimezone; + QString m_localeGenPath; + + Calamares::JobList m_jobs; + std::unique_ptr< CalamaresUtils::GeoIP::Handler > m_geoip; + + void fetchGeoIpTimezone(); +}; + +CALAMARES_PLUGIN_FACTORY_DECLARATION( LocaleQmlViewStepFactory ) + +#endif diff --git a/src/modules/localeq/localeq.conf b/src/modules/localeq/localeq.conf new file mode 100644 index 000000000..4beb4fe85 --- /dev/null +++ b/src/modules/localeq/localeq.conf @@ -0,0 +1,97 @@ +--- +# This settings are used to set your default system time zone. +# Time zones are usually located under /usr/share/zoneinfo and +# provided by the 'tzdata' package of your Distribution. +# +# Distributions using systemd can list available +# time zones by using the timedatectl command. +# timedatectl list-timezones +# +# The starting timezone (e.g. the pin-on-the-map) when entering +# the locale page can be set through keys *region* and *zone*. +# If either is not set, defaults to America/New_York. +# +region: "America" +zone: "New_York" + + +# System locales are detected in the following order: +# +# - /usr/share/i18n/SUPPORTED +# - localeGenPath (defaults to /etc/locale.gen if not set) +# - 'locale -a' output +# +# Enable only when your Distribution is using an +# custom path for locale.gen +# +#localeGenPath: "PATH_TO/locale.gen" + +# GeoIP based Language settings: Leave commented out to disable GeoIP. +# +# GeoIP needs a working Internet connection. +# This can be managed from `welcome.conf` by adding +# internet to the list of required conditions. +# +# The configuration +# is in three parts: a *style*, which can be "json" or "xml" +# depending on the kind of data returned by the service, and +# a *url* where the data is retrieved, and an optional *selector* +# to pick the right field out of the returned data (e.g. field +# name in JSON or element name in XML). +# +# The default selector (when the setting is blank) is picked to +# work with existing JSON providers (which use "time_zone") and +# Ubiquity's XML providers (which use "TimeZone"). +# +# If the service configured via *url* uses +# a different attribute name (e.g. "timezone") in JSON or a +# different element tag (e.g. "") in XML, set this +# string to the name or tag to be used. +# +# In JSON: +# - if the string contains "." characters, this is used as a +# multi-level selector, e.g. "a.b" will select the timezone +# from data "{a: {b: "Europe/Amsterdam" } }". +# - each part of the string split by "." characters is used as +# a key into the JSON data. +# In XML: +# - all elements with the named tag (e.g. all TimeZone) elements +# from the document are checked; the first one with non-empty +# text value is used. +# +# +# An HTTP(S) request is made to *url*. The request should return +# valid data in a suitable format, depending on *style*; +# generally this includes a string value with the timezone +# in / format. For services that return data which +# does not follow the conventions of "suitable data" described +# below, *selector* may be used to pick different data. +# +# Note that this example URL works, but the service is shutting +# down in June 2018. +# +# Suitable JSON data looks like +# ``` +# {"time_zone":"America/New_York"} +# ``` +# Suitable XML data looks like +# ``` +# Europe/Brussels +# ``` +# +# To accommodate providers of GeoIP timezone data with peculiar timezone +# naming conventions, the following cleanups are performed automatically: +# - backslashes are removed +# - spaces are replaced with _ +# +# Legacy settings "geoipStyle", "geoipUrl" and "geoipSelector" +# in the top-level are still supported, but I'd advise against. +# +# To disable GeoIP checking, either comment-out the entire geoip section, +# or set the *style* key to an unsupported format (e.g. `none`). +# Also, note the analogous feature in src/modules/welcome/welcome.conf. +# +geoip: + style: "json" + url: "https://geoip.kde.org/v1/calamares" + selector: "" # leave blank for the default diff --git a/src/modules/localeq/localeq.qml b/src/modules/localeq/localeq.qml new file mode 100644 index 000000000..b186a0081 --- /dev/null +++ b/src/modules/localeq/localeq.qml @@ -0,0 +1,113 @@ +import io.calamares.modules 1.0 as Modules +import io.calamares.ui 1.0 + +import QtQuick 2.10 +import QtQuick.Controls 2.10 +import QtQuick.Layouts 1.3 +import org.kde.kirigami 2.7 as Kirigami +import QtGraphicalEffects 1.0 + +ResponsiveBase +{ + id: control + + Modules.Locale //locale handler + { + id: _locale + } + + title: stackView.currentItem.title + subtitle: stackView.currentItem.subtitle + message: stackView.currentItem.message + + stackView.initialItem: Item + { + id: _regionsListComponent + + property string title: qsTr("Region") + property string subtitle: qsTr("Pick your preferred region or use the default one based on your current location") + property string message: qsTr("Select your preferred zone within your location to continue with the installation") + + ListViewTemplate + { + id: _regionListView + anchors.centerIn: parent + implicitWidth: Math.min(parent.width, 500) + implicitHeight: Math.min(contentHeight, 500) + currentIndex: model.currentIndex + model: _locale.Config.regionModel + + delegate: ListItemDelegate + { + id: _delegate + label1.text: model.label + onClicked: + { + _regionListView.model.currentIndex = index + _stackView.push(_zonesListComponent) + } + } + + footer: RowLayout + { + width: parent.width + z: 99999 + Button + { + Layout.fillWidth: true + text: qsTr("Timezones") + icon.name: "go-previous" + onClicked: control.stackView.push(_zonesListComponent) + } + } + } + } + + + Component + { + id: _zonesListComponent + + Item + { + property string title: qsTr("Timezone") + property string subtitle: _locale.Config.prettyStatus + property string message: "" + ListViewTemplate + { + id: _zonesListView + anchors.centerIn: parent + implicitWidth: Math.min(parent.width, 500) + implicitHeight: Math.min(contentHeight, 500) + currentIndex: model.currentIndex + model: _locale.Config.zonesModel + + delegate: ListItemDelegate + { + id: _delegate + label1.text: model.label + onClicked: + { + _zonesListView.model.currentIndex = index + positionViewAtIndex(index, ListView.Center) + } + } + + footer: RowLayout + { + width: parent.width + z: 99999 + + Button + { + Layout.fillWidth: true + icon.name: "go-previous" + text: qsTr("Regions") + onClicked: control.stackView.pop() + } + } + } + } + } +} + From e02077d58e9519ef96578e6399fbf0d9f124972d Mon Sep 17 00:00:00 2001 From: Camilo Higuita Date: Tue, 24 Mar 2020 10:04:14 -0500 Subject: [PATCH 13/32] some models need to be updated to work with locale qml view step --- src/libcalamares/locale/Label.cpp | 2 -- src/libcalamares/locale/Label.h | 5 +--- src/libcalamares/locale/TimeZone.cpp | 29 ++++++++++++++++++++++- src/libcalamares/locale/TimeZone.h | 35 +++++++++++++++++++++++++--- 4 files changed, 61 insertions(+), 10 deletions(-) diff --git a/src/libcalamares/locale/Label.cpp b/src/libcalamares/locale/Label.cpp index 816246699..02583df8b 100644 --- a/src/libcalamares/locale/Label.cpp +++ b/src/libcalamares/locale/Label.cpp @@ -33,9 +33,7 @@ Label::Label( const QString& locale, LabelFormat format, QObject* parent ) : QObject( parent ) , m_locale( Label::getLocale( locale ) ) , m_localeId( locale.isEmpty() ? m_locale.name() : locale ) - { - //: language[name] (country[name]) QString longFormat = QObject::tr( "%1 (%2)" ); QString languageName = m_locale.nativeLanguageName(); diff --git a/src/libcalamares/locale/Label.h b/src/libcalamares/locale/Label.h index d7fa14453..bd596f53d 100644 --- a/src/libcalamares/locale/Label.h +++ b/src/libcalamares/locale/Label.h @@ -40,10 +40,6 @@ class Label : public QObject { Q_OBJECT - Q_PROPERTY( QString label READ label CONSTANT FINAL ) - Q_PROPERTY( QString englishLabel READ englishLabel CONSTANT FINAL ) - Q_PROPERTY( QString localeId MEMBER m_localeId CONSTANT FINAL ) - public: /** @brief Formatting option for label -- add (country) to label. */ enum class LabelFormat @@ -65,6 +61,7 @@ public: LabelFormat format = LabelFormat::IfNeededWithCountry, QObject* parent = nullptr ); + /** @brief Define a sorting order. * * Locales are sorted by their id, which means the ISO 2-letter code + country. diff --git a/src/libcalamares/locale/TimeZone.cpp b/src/libcalamares/locale/TimeZone.cpp index 58695ee0e..fb224f9c4 100644 --- a/src/libcalamares/locale/TimeZone.cpp +++ b/src/libcalamares/locale/TimeZone.cpp @@ -239,7 +239,12 @@ CStringListModel::CStringListModel( CStringPairList l ) { } -CStringListModel::~CStringListModel() {} +void CStringListModel::setList(CalamaresUtils::Locale::CStringPairList l) +{ + beginResetModel(); + m_list = l; + endResetModel(); +} int CStringListModel::rowCount( const QModelIndex& ) const @@ -264,6 +269,28 @@ CStringListModel::data( const QModelIndex& index, int role ) const return item ? ( role == Qt::DisplayRole ? item->tr() : item->key() ) : QVariant(); } +void +CStringListModel::setCurrentIndex(const int &index) +{ + if ( ( index < 0 ) || ( index >= m_list.count() ) ) + return; + + m_currentIndex = index; + emit currentIndexChanged(); +} + +int +CStringListModel::currentIndex() const +{ + return m_currentIndex; +} + +QHash +CStringListModel::roleNames() const +{ + return {{Qt::DisplayRole,"label"}, {Qt::UserRole, "key"}}; +} + const CStringPair* CStringListModel::item( int index ) const { diff --git a/src/libcalamares/locale/TimeZone.h b/src/libcalamares/locale/TimeZone.h index 3345e61f8..32c4622cf 100644 --- a/src/libcalamares/locale/TimeZone.h +++ b/src/libcalamares/locale/TimeZone.h @@ -44,8 +44,9 @@ namespace Locale * QPair because there is API that needs * C-style strings. */ -class CStringPair +class CStringPair : public QObject { + Q_OBJECT public: /// @brief An empty pair CStringPair() {} @@ -86,6 +87,7 @@ public: /// @brief A pair of strings for timezone regions (e.g. "America") class TZRegion : public CStringPair { + Q_OBJECT public: using CStringPair::CStringPair; virtual ~TZRegion() override; @@ -117,6 +119,7 @@ private: /// @brief A pair of strings for specific timezone names (e.g. "New_York") class TZZone : public CStringPair { + Q_OBJECT public: using CStringPair::CStringPair; QString tr() const override; @@ -137,21 +140,47 @@ protected: class CStringListModel : public QAbstractListModel { + Q_OBJECT + Q_PROPERTY(int currentIndex READ currentIndex WRITE setCurrentIndex NOTIFY currentIndexChanged) + public: /// @brief Create empty model - CStringListModel(); + CStringListModel() {}; /// @brief Create model from list (non-owning) CStringListModel( CStringPairList ); - virtual ~CStringListModel() override; int rowCount( const QModelIndex& parent ) const override; QVariant data( const QModelIndex& index, int role ) const override; const CStringPair* item( int index ) const; + QHash roleNames() const override; + + void setCurrentIndex(const int &index); + int currentIndex() const; + + void setList(CStringPairList); + + inline int indexOf(const QString &key) + { + const auto it = std::find_if(m_list.constBegin(), m_list.constEnd(), [&](const CalamaresUtils::Locale::CStringPair *item) -> bool + { + return item->key() == key; + + }); + + if(it != m_list.constEnd()) + return std::distance(m_list.constBegin(), it); + else return -1; + } + private: CStringPairList m_list; + int m_currentIndex = -1; + +signals: + void currentIndexChanged(); }; } // namespace Locale From b6b9f888fcc4db6969a331a86c05f5560ab17db1 Mon Sep 17 00:00:00 2001 From: Camilo Higuita Date: Tue, 24 Mar 2020 10:39:29 -0500 Subject: [PATCH 14/32] correct typo --- src/modules/welcome/Config.cpp | 77 ++++++++++++++++++++-------------- src/modules/welcome/Config.h | 9 ++-- 2 files changed, 52 insertions(+), 34 deletions(-) diff --git a/src/modules/welcome/Config.cpp b/src/modules/welcome/Config.cpp index 2fa0ce156..fdc532d7f 100644 --- a/src/modules/welcome/Config.cpp +++ b/src/modules/welcome/Config.cpp @@ -30,13 +30,13 @@ RequirementsModel::setRequirementsList( const Calamares::RequirementsList& requi CALAMARES_RETRANSLATE_SLOT( &RequirementsModel::retranslate ) emit beginResetModel(); - m_requierements = requirements; + m_requirements = requirements; auto isUnSatisfied = []( const Calamares::RequirementEntry& e ) { return !e.satisfied; }; auto isMandatoryAndUnSatisfied = []( const Calamares::RequirementEntry& e ) { return e.mandatory && !e.satisfied; }; - m_satisfiedRequirements = std::none_of( m_requierements.begin(), m_requierements.end(), isUnSatisfied ); - m_satisfiedMandatory = std::none_of( m_requierements.begin(), m_requierements.end(), isMandatoryAndUnSatisfied ); + m_satisfiedRequirements = std::none_of( m_requirements.begin(), m_requirements.end(), isUnSatisfied ); + m_satisfiedMandatory = std::none_of( m_requirements.begin(), m_requirements.end(), isMandatoryAndUnSatisfied ); emit satisfiedRequirementsChanged(m_satisfiedRequirements); emit satisfiedMandatoryChanged(); @@ -46,13 +46,13 @@ RequirementsModel::setRequirementsList( const Calamares::RequirementsList& requi int RequirementsModel::rowCount( const QModelIndex& ) const { - return m_requierements.count(); + return m_requirements.count(); } QVariant RequirementsModel::data( const QModelIndex& index, int role ) const { - const auto requirement = m_requierements.at( index.row() ); + const auto requirement = m_requirements.at( index.row() ); switch ( role ) { @@ -92,28 +92,12 @@ Config::Config( QObject* parent ) : QObject( parent ) initLanguages(); CALAMARES_RETRANSLATE_SLOT( &Config::retranslate ) - } void Config::retranslate() { - QString message; - - if ( Calamares::Settings::instance()->isSetupMode() ) - { - message = Calamares::Branding::instance()->welcomeStyleCalamares() - ? tr( "

Welcome to the Calamares setup program for %1.

" ) - : tr( "

Welcome to %1 setup.

" ); - } - else - { - message = Calamares::Branding::instance()->welcomeStyleCalamares() - ? tr( "

Welcome to the Calamares installer for %1.

" ) - : tr( "

Welcome to the %1 installer.

" ); - } - - m_genericWelcomeMessage = message.arg( *Calamares::Branding::VersionedName ); + m_genericWelcomeMessage = genericWelcomeMessage().arg( *Calamares::Branding::VersionedName ); emit genericWelcomeMessageChanged(); m_requirementsModel->retranslate(); @@ -224,51 +208,60 @@ Config::setIsNextEnabled( const bool& isNextEnabled ) emit isNextEnabledChanged( m_isNextEnabled ); } -QString Config::donateUrl() const +QString +Config::donateUrl() const { return m_donateUrl; } -void Config::setDonateUrl(const QString& url) +void +Config::setDonateUrl(const QString& url) { m_donateUrl = url; emit donateUrlChanged(); } -QString Config::knownIssuesUrl() const +QString +Config::knownIssuesUrl() const { return m_knownIssuesUrl; } -void Config::setKnownIssuesUrl(const QString& url) +void +Config::setKnownIssuesUrl(const QString& url) { m_knownIssuesUrl = url; emit knownIssuesUrlChanged(); } -void Config::setReleaseNotesUrl(const QString& url) +void +Config::setReleaseNotesUrl(const QString& url) { m_releaseNotesUrl = url; emit releaseNotesUrlChanged(); } -QString Config::releaseNotesUrl() const +QString +Config::releaseNotesUrl() const { return m_releaseNotesUrl; } -QString Config::supportUrl() const +QString +Config::supportUrl() const { return m_supportUrl; } -void Config::setSupportUrl(const QString& url) +void +Config::setSupportUrl(const QString& url) { m_supportUrl = url; emit supportUrlChanged(); } -void RequirementsModel::retranslate() +void +RequirementsModel::retranslate() { if ( !m_satisfiedRequirements ) { @@ -308,3 +301,25 @@ void RequirementsModel::retranslate() emit warningMessageChanged(); } + +QString +Config::genericWelcomeMessage() +{ + QString message; + + if ( Calamares::Settings::instance()->isSetupMode() ) + { + message = Calamares::Branding::instance()->welcomeStyleCalamares() + ? tr( "

Welcome to the Calamares setup program for %1.

" ) + : tr( "

Welcome to %1 setup.

" ); + } + else + { + message = Calamares::Branding::instance()->welcomeStyleCalamares() + ? tr( "

Welcome to the Calamares installer for %1.

" ) + : tr( "

Welcome to the %1 installer.

" ); + } + + return message; +} + diff --git a/src/modules/welcome/Config.h b/src/modules/welcome/Config.h index 043866eb6..a6de4c5dd 100644 --- a/src/modules/welcome/Config.h +++ b/src/modules/welcome/Config.h @@ -61,7 +61,7 @@ public: if(index > count() || index < 0) return *(new Calamares::RequirementEntry()); - return m_requierements.at(index); + return m_requirements.at(index); } @@ -69,7 +69,7 @@ public: int rowCount(const QModelIndex&) const override; int count() const { - return m_requierements.count(); + return m_requirements.count(); } QString warningMessage() const @@ -85,7 +85,7 @@ protected: QHash roleNames() const override; private: - Calamares::RequirementsList m_requierements; + Calamares::RequirementsList m_requirements; bool m_satisfiedRequirements = false; bool m_satisfiedMandatory = false; @@ -141,6 +141,9 @@ public: QString donateUrl() const; void setDonateUrl(const QString &url); + QString genericWelcomeMessage(); + + public slots: CalamaresUtils::Locale::LabelModel* languagesModel() const; void retranslate(); From b6228d137ca11353c94c784438d0f87630229b88 Mon Sep 17 00:00:00 2001 From: demmm Date: Tue, 24 Mar 2020 16:59:31 +0100 Subject: [PATCH 15/32] Adding popup warning/instructions for GPT with BIOS see https://github.com/calamares/calamares/issues/1339#issuecomment-600862507 this is a very generic warning, used downstream since 2016 stopped virtual all BIOS GPT failures and questions --- .../partition/gui/PartitionViewStep.cpp | 36 +++++++++++++++++++ 1 file changed, 36 insertions(+) diff --git a/src/modules/partition/gui/PartitionViewStep.cpp b/src/modules/partition/gui/PartitionViewStep.cpp index 28ed77409..1cfc010e5 100644 --- a/src/modules/partition/gui/PartitionViewStep.cpp +++ b/src/modules/partition/gui/PartitionViewStep.cpp @@ -402,7 +402,11 @@ PartitionViewStep::onLeave() if ( m_widget->currentWidget() == m_manualPartitionPage ) { + bool isEfi = false; if ( PartUtils::isEfiSystem() ) + isEfi = true; + + if ( isEfi ) { QString espMountPoint = Calamares::JobQueue::instance()->globalStorage()-> value( "efiSystemPartition" ).toString(); @@ -448,7 +452,39 @@ PartitionViewStep::onLeave() description ); } } + + if ( !isEfi ) + { + + cDebug() << "device: BIOS"; + + Partition* bios_p = m_core->findPartitionByMountPoint( "" ); + QString message; + QString description; + message = tr( "Option to use GPT on BIOS" ); + description = tr( "A GPT partition table is the best option for all " + "systems. This installer supports such a setup for " + "BIOS systems too." + "

" + "To configure a GPT partition table on BIOS, " + "(if not done so already) go back " + "and set the partion table to GPT, next create a 8 MB " + "unformatted partition with the " + "bios_grub flag enabled.

" + "An unformatted 8 MB partition is necessary " + "to start %1 on a BIOS system with GPT." ) + .arg( Calamares::Branding::instance()-> + string( Calamares::Branding::ShortProductName ) ); + + if ( !message.isEmpty() ) + { + QMessageBox::information( m_manualPartitionPage, + message, + description ); + } + } + Partition* root_p = m_core->findPartitionByMountPoint( "/" ); Partition* boot_p = m_core->findPartitionByMountPoint( "/boot" ); From b57e198c2947863d524508f53dbbdd668826d892 Mon Sep 17 00:00:00 2001 From: Adriaan de Groot Date: Tue, 24 Mar 2020 22:21:56 +0100 Subject: [PATCH 16/32] [partition] Apply coding style - This isn't particularly related to the change at hand, though. --- .../partition/gui/PartitionViewStep.cpp | 215 ++++++++++-------- 1 file changed, 125 insertions(+), 90 deletions(-) diff --git a/src/modules/partition/gui/PartitionViewStep.cpp b/src/modules/partition/gui/PartitionViewStep.cpp index 1cfc010e5..02ea5cb30 100644 --- a/src/modules/partition/gui/PartitionViewStep.cpp +++ b/src/modules/partition/gui/PartitionViewStep.cpp @@ -22,16 +22,16 @@ #include "gui/PartitionViewStep.h" #include "core/DeviceModel.h" -#include "core/PartitionActions.h" -#include "core/PartitionCoreModule.h" -#include "core/PartitionModel.h" #include "core/KPMHelpers.h" #include "core/OsproberEntry.h" #include "core/PartUtils.h" +#include "core/PartitionActions.h" +#include "core/PartitionCoreModule.h" +#include "core/PartitionModel.h" #include "gui/ChoicePage.h" -#include "gui/PartitionPage.h" #include "gui/PartitionBarsView.h" #include "gui/PartitionLabelsView.h" +#include "gui/PartitionPage.h" #include "Branding.h" #include "CalamaresVersion.h" @@ -55,13 +55,13 @@ #include #include #include +#include #include #include #include #include #include #include -#include PartitionViewStep::PartitionViewStep( QObject* parent ) : Calamares::ViewStep( parent ) @@ -77,7 +77,7 @@ PartitionViewStep::PartitionViewStep( QObject* parent ) m_widget->addWidget( m_waitingWidget ); CALAMARES_RETRANSLATE( m_waitingWidget->setText( tr( "Gathering system information..." ) ); ) - m_core = new PartitionCoreModule( this ); // Unusable before init is complete! + m_core = new PartitionCoreModule( this ); // Unusable before init is complete! // We're not done loading, but we need the configuration map first. } @@ -108,19 +108,21 @@ PartitionViewStep::continueLoading() m_waitingWidget->deleteLater(); m_waitingWidget = nullptr; - connect( m_core, &PartitionCoreModule::hasRootMountPointChanged, - this, &PartitionViewStep::nextStatusChanged ); - connect( m_choicePage, &ChoicePage::nextStatusChanged, - this, &PartitionViewStep::nextStatusChanged ); + connect( m_core, &PartitionCoreModule::hasRootMountPointChanged, this, &PartitionViewStep::nextStatusChanged ); + connect( m_choicePage, &ChoicePage::nextStatusChanged, this, &PartitionViewStep::nextStatusChanged ); } PartitionViewStep::~PartitionViewStep() { if ( m_choicePage && m_choicePage->parent() == nullptr ) + { m_choicePage->deleteLater(); + } if ( m_manualPartitionPage && m_manualPartitionPage->parent() == nullptr ) + { m_manualPartitionPage->deleteLater(); + } } @@ -154,7 +156,7 @@ PartitionViewStep::createSummaryWidget() const mainLayout->addLayout( formLayout ); QList< PartitionCoreModule::SummaryInfo > list = m_core->createSummaryInfo(); - if ( list.length() > 1 ) // There are changes on more than one disk + if ( list.length() > 1 ) // There are changes on more than one disk { //NOTE: all of this should only happen when Manual partitioning is active. // Any other choice should result in a list.length() == 1. @@ -165,15 +167,15 @@ PartitionViewStep::createSummaryWidget() const { case ChoicePage::Alongside: modeText = tr( "Install %1 alongside another operating system." ) - .arg( *Calamares::Branding::ShortVersionedName ); + .arg( *Calamares::Branding::ShortVersionedName ); break; case ChoicePage::Erase: - modeText = tr( "Erase disk and install %1." ) - .arg( *Calamares::Branding::ShortVersionedName ); + modeText + = tr( "Erase disk and install %1." ).arg( *Calamares::Branding::ShortVersionedName ); break; case ChoicePage::Replace: - modeText = tr( "Replace a partition with %1." ) - .arg( *Calamares::Branding::ShortVersionedName ); + modeText + = tr( "Replace a partition with %1." ).arg( *Calamares::Branding::ShortVersionedName ); break; case ChoicePage::NoChoice: case ChoicePage::Manual: @@ -184,42 +186,42 @@ PartitionViewStep::createSummaryWidget() const for ( const auto& info : list ) { QLabel* diskInfoLabel = new QLabel; - if ( list.length() == 1 ) // this is the only disk preview + if ( list.length() == 1 ) // this is the only disk preview { QString modeText; switch ( choice ) { case ChoicePage::Alongside: - modeText = tr( "Install %1 alongside another operating system on disk %2 (%3)." ) - .arg( *Calamares::Branding::ShortVersionedName ) - .arg( info.deviceNode ) - .arg( info.deviceName ); + modeText = tr( "Install %1 alongside another operating system on disk " + "%2 (%3)." ) + .arg( *Calamares::Branding::ShortVersionedName ) + .arg( info.deviceNode ) + .arg( info.deviceName ); break; case ChoicePage::Erase: modeText = tr( "Erase disk %2 (%3) and install %1." ) - .arg( *Calamares::Branding::ShortVersionedName ) - .arg( info.deviceNode ) - .arg( info.deviceName ); + .arg( *Calamares::Branding::ShortVersionedName ) + .arg( info.deviceNode ) + .arg( info.deviceName ); break; case ChoicePage::Replace: modeText = tr( "Replace a partition on disk %2 (%3) with %1." ) - .arg( *Calamares::Branding::ShortVersionedName ) - .arg( info.deviceNode ) - .arg( info.deviceName ); + .arg( *Calamares::Branding::ShortVersionedName ) + .arg( info.deviceNode ) + .arg( info.deviceName ); break; case ChoicePage::NoChoice: case ChoicePage::Manual: modeText = tr( "Manual partitioning on disk %1 (%2)." ) - .arg( info.deviceNode ) - .arg( info.deviceName ); + .arg( info.deviceNode ) + .arg( info.deviceName ); } diskInfoLabel->setText( modeText ); } - else // multiple disk previews! + else // multiple disk previews! { - diskInfoLabel->setText( tr( "Disk %1 (%2)" ) - .arg( info.deviceNode ) - .arg( info.deviceName ) ); + diskInfoLabel->setText( + tr( "Disk %1 (%2)" ).arg( info.deviceNode ).arg( info.deviceName ) ); } formLayout->addRow( diskInfoLabel ); @@ -227,10 +229,10 @@ PartitionViewStep::createSummaryWidget() const PartitionLabelsView* previewLabels; QVBoxLayout* field; - PartitionBarsView::NestedPartitionsMode mode = Calamares::JobQueue::instance()->globalStorage()-> - value( "drawNestedPartitions" ).toBool() ? - PartitionBarsView::DrawNestedPartitions : - PartitionBarsView::NoNestedPartitions; + PartitionBarsView::NestedPartitionsMode mode + = Calamares::JobQueue::instance()->globalStorage()->value( "drawNestedPartitions" ).toBool() + ? PartitionBarsView::DrawNestedPartitions + : PartitionBarsView::NoNestedPartitions; preview = new PartitionBarsView; preview->setNestedPartitionsMode( mode ); previewLabels = new PartitionLabelsView; @@ -268,7 +270,9 @@ PartitionViewStep::createSummaryWidget() const foreach ( const Calamares::job_ptr& job, jobs() ) { if ( !job->prettyDescription().isEmpty() ) + { jobsLines.append( job->prettyDescription() ); + } } if ( !jobsLines.isEmpty() ) { @@ -301,7 +305,9 @@ PartitionViewStep::next() m_widget->setCurrentWidget( m_manualPartitionPage ); m_manualPartitionPage->selectDeviceByIndex( m_choicePage->lastSelectedDeviceIndex() ); if ( m_core->isDirty() ) + { m_manualPartitionPage->onRevertClicked(); + } } cDebug() << "Choice applied: " << m_choicePage->currentChoice(); } @@ -329,10 +335,14 @@ bool PartitionViewStep::isNextEnabled() const { if ( m_choicePage && m_widget->currentWidget() == m_choicePage ) + { return m_choicePage->isNextEnabled(); + } if ( m_manualPartitionPage && m_widget->currentWidget() == m_manualPartitionPage ) + { return m_core->hasRootMountPoint(); + } return false; } @@ -349,7 +359,9 @@ bool PartitionViewStep::isAtBeginning() const { if ( m_widget->currentWidget() != m_choicePage ) + { return false; + } return true; } @@ -359,10 +371,11 @@ PartitionViewStep::isAtEnd() const { if ( m_widget->currentWidget() == m_choicePage ) { - if ( m_choicePage->currentChoice() == ChoicePage::Erase || - m_choicePage->currentChoice() == ChoicePage::Replace || - m_choicePage->currentChoice() == ChoicePage::Alongside ) + if ( m_choicePage->currentChoice() == ChoicePage::Erase || m_choicePage->currentChoice() == ChoicePage::Replace + || m_choicePage->currentChoice() == ChoicePage::Alongside ) + { return true; + } return false; } return true; @@ -381,11 +394,10 @@ PartitionViewStep::onActivate() } // if we're coming back to PVS from the next VS - if ( m_widget->currentWidget() == m_choicePage && - m_choicePage->currentChoice() == ChoicePage::Alongside ) + if ( m_widget->currentWidget() == m_choicePage && m_choicePage->currentChoice() == ChoicePage::Alongside ) { m_choicePage->applyActionChoice( ChoicePage::Alongside ); -// m_choicePage->reset(); + // m_choicePage->reset(); //FIXME: ReplaceWidget should be reset maybe? } } @@ -404,12 +416,14 @@ PartitionViewStep::onLeave() { bool isEfi = false; if ( PartUtils::isEfiSystem() ) + { isEfi = true; - + } + if ( isEfi ) { - QString espMountPoint = Calamares::JobQueue::instance()->globalStorage()-> - value( "efiSystemPartition" ).toString(); + QString espMountPoint + = Calamares::JobQueue::instance()->globalStorage()->value( "efiSystemPartition" ).toString(); Partition* esp = m_core->findPartitionByMountPoint( espMountPoint ); QString message; @@ -425,8 +439,8 @@ PartitionViewStep::onLeave() "%2.

" "You can continue without setting up an EFI system " "partition but your system may fail to start." ) - .arg( *Calamares::Branding::ShortProductName ) - .arg( espMountPoint ); + .arg( *Calamares::Branding::ShortProductName ) + .arg( espMountPoint ); } else if ( esp && !PartUtils::isEfiBootable( esp ) ) { @@ -440,24 +454,22 @@ PartitionViewStep::onLeave() "

" "You can continue without setting the flag but your " "system may fail to start." ) - .arg( *Calamares::Branding::ShortProductName ) - .arg( espMountPoint ); + .arg( *Calamares::Branding::ShortProductName ) + .arg( espMountPoint ); } if ( !message.isEmpty() ) { cWarning() << message; - QMessageBox::warning( m_manualPartitionPage, - message, - description ); + QMessageBox::warning( m_manualPartitionPage, message, description ); } } - + if ( !isEfi ) { - + cDebug() << "device: BIOS"; - + Partition* bios_p = m_core->findPartitionByMountPoint( "" ); QString message; QString description; @@ -474,17 +486,14 @@ PartitionViewStep::onLeave() "bios_grub flag enabled.

" "An unformatted 8 MB partition is necessary " "to start %1 on a BIOS system with GPT." ) - .arg( Calamares::Branding::instance()-> - string( Calamares::Branding::ShortProductName ) ); - + .arg( Calamares::Branding::instance()->string( Calamares::Branding::ShortProductName ) ); + if ( !message.isEmpty() ) { - QMessageBox::information( m_manualPartitionPage, - message, - description ); + QMessageBox::information( m_manualPartitionPage, message, description ); } } - + Partition* root_p = m_core->findPartitionByMountPoint( "/" ); Partition* boot_p = m_core->findPartitionByMountPoint( "/boot" ); @@ -495,8 +504,7 @@ PartitionViewStep::onLeave() // If the root partition is encrypted, and there's a separate boot // partition which is not encrypted - if ( root_p->fileSystem().type() == FileSystem::Luks && - boot_p->fileSystem().type() != FileSystem::Luks ) + if ( root_p->fileSystem().type() == FileSystem::Luks && boot_p->fileSystem().type() != FileSystem::Luks ) { message = tr( "Boot partition not encrypted" ); description = tr( "A separate boot partition was set up together with " @@ -512,9 +520,7 @@ PartitionViewStep::onLeave() "recreate it, selecting Encrypt " "in the partition creation window." ); - QMessageBox::warning( m_manualPartitionPage, - message, - description ); + QMessageBox::warning( m_manualPartitionPage, message, description ); } } } @@ -529,7 +535,9 @@ PartitionViewStep::setConfigurationMap( const QVariantMap& configurationMap ) Calamares::GlobalStorage* gs = Calamares::JobQueue::instance()->globalStorage(); QString efiSP = CalamaresUtils::getString( configurationMap, "efiSystemPartition" ); if ( efiSP.isEmpty() ) + { efiSP = QStringLiteral( "/boot/efi" ); + } gs->insert( "efiSystemPartition", efiSP ); // Set up firmwareType global storage entry. This is used, e.g. by the bootloader module. @@ -547,16 +555,22 @@ PartitionViewStep::setConfigurationMap( const QVariantMap& configurationMap ) // // This is a bit convoluted because there's legacy settings to handle as well // as the new-style list of choices, with mapping back-and-forth. - if ( configurationMap.contains( "userSwapChoices" ) && - ( configurationMap.contains( "ensureSuspendToDisk" ) || configurationMap.contains( "neverCreateSwap" ) ) ) + if ( configurationMap.contains( "userSwapChoices" ) + && ( configurationMap.contains( "ensureSuspendToDisk" ) || configurationMap.contains( "neverCreateSwap" ) ) ) + { cError() << "Partition-module configuration mixes old- and new-style swap settings."; + } if ( configurationMap.contains( "ensureSuspendToDisk" ) ) + { cWarning() << "Partition-module setting *ensureSuspendToDisk* is deprecated."; + } bool ensureSuspendToDisk = CalamaresUtils::getBool( configurationMap, "ensureSuspendToDisk", true ); if ( configurationMap.contains( "neverCreateSwap" ) ) + { cWarning() << "Partition-module setting *neverCreateSwap* is deprecated."; + } bool neverCreateSwap = CalamaresUtils::getBool( configurationMap, "neverCreateSwap", false ); QSet< PartitionActions::Choices::SwapChoice > choices; // Available swap choices @@ -571,7 +585,9 @@ PartitionViewStep::setConfigurationMap( const QVariantMap& configurationMap ) bool ok = false; auto v = PartitionActions::Choices::nameToChoice( item, ok ); if ( ok ) + { choices.insert( v ); + } } if ( choices.isEmpty() ) @@ -589,19 +605,28 @@ PartitionViewStep::setConfigurationMap( const QVariantMap& configurationMap ) { // Convert the legacy settings into a single setting for now. if ( neverCreateSwap ) + { choices.insert( PartitionActions::Choices::SwapChoice::NoSwap ); + } else if ( ensureSuspendToDisk ) + { choices.insert( PartitionActions::Choices::SwapChoice::FullSwap ); + } else + { choices.insert( PartitionActions::Choices::SwapChoice::SmallSwap ); + } } // Not all are supported right now // FIXME static const char unsupportedSetting[] = "Partition-module does not support *userSwapChoices* setting"; -#define COMPLAIN_UNSUPPORTED(x) \ +#define COMPLAIN_UNSUPPORTED( x ) \ if ( choices.contains( x ) ) \ - { cWarning() << unsupportedSetting << PartitionActions::Choices::choiceToName( x ); choices.remove( x ); } + { \ + cWarning() << unsupportedSetting << PartitionActions::Choices::choiceToName( x ); \ + choices.remove( x ); \ + } COMPLAIN_UNSUPPORTED( PartitionActions::Choices::SwapChoice::SwapFile ) COMPLAIN_UNSUPPORTED( PartitionActions::Choices::SwapChoice::ReuseSwap ) @@ -620,23 +645,35 @@ PartitionViewStep::setConfigurationMap( const QVariantMap& configurationMap ) // OTHER SETTINGS // gs->insert( "drawNestedPartitions", CalamaresUtils::getBool( configurationMap, "drawNestedPartitions", false ) ); - gs->insert( "alwaysShowPartitionLabels", CalamaresUtils::getBool( configurationMap, "alwaysShowPartitionLabels", true ) ); - gs->insert( "enableLuksAutomatedPartitioning", CalamaresUtils::getBool( configurationMap, "enableLuksAutomatedPartitioning", true ) ); - gs->insert( "allowManualPartitioning", CalamaresUtils::getBool( configurationMap, "allowManualPartitioning", true ) ); + gs->insert( "alwaysShowPartitionLabels", + CalamaresUtils::getBool( configurationMap, "alwaysShowPartitionLabels", true ) ); + gs->insert( "enableLuksAutomatedPartitioning", + CalamaresUtils::getBool( configurationMap, "enableLuksAutomatedPartitioning", true ) ); + gs->insert( "allowManualPartitioning", + CalamaresUtils::getBool( configurationMap, "allowManualPartitioning", true ) ); // The defaultFileSystemType setting needs a bit more processing, // as we want to cover various cases (such as different cases) QString fsName = CalamaresUtils::getString( configurationMap, "defaultFileSystemType" ); FileSystem::Type fsType; if ( fsName.isEmpty() ) - cWarning() << "Partition-module setting *defaultFileSystemType* is missing, will use ext4"; + { + cWarning() << "Partition-module setting *defaultFileSystemType* is missing, will use ext4"; + } QString fsRealName = PartUtils::findFS( fsName, &fsType ); if ( fsRealName == fsName ) + { cDebug() << "Partition-module setting *defaultFileSystemType*" << fsRealName; + } else if ( fsType != FileSystem::Unknown ) + { cWarning() << "Partition-module setting *defaultFileSystemType* changed" << fsRealName; + } else - cWarning() << "Partition-module setting *defaultFileSystemType* is bad (" << fsName << ") using" << fsRealName << "instead."; + { + cWarning() << "Partition-module setting *defaultFileSystemType* is bad (" << fsName << ") using" << fsRealName + << "instead."; + } gs->insert( "defaultFileSystemType", fsRealName ); @@ -644,21 +681,18 @@ PartitionViewStep::setConfigurationMap( const QVariantMap& configurationMap ) // because it could take a while. Then when it's done, we can set up the widgets // and remove the spinner. m_future = new QFutureWatcher< void >(); - connect( m_future, &QFutureWatcher< void >::finished, - this, [ this ] - { + connect( m_future, &QFutureWatcher< void >::finished, this, [this] { continueLoading(); this->m_future->deleteLater(); this->m_future = nullptr; } ); - QFuture< void > future = - QtConcurrent::run( this, &PartitionViewStep::initPartitionCoreModule ); + QFuture< void > future = QtConcurrent::run( this, &PartitionViewStep::initPartitionCoreModule ); m_future->setFuture( future ); if ( configurationMap.contains( "partitionLayout" ) ) { - m_core->initLayout( configurationMap.values( "partitionLayout" ).at(0).toList() ); + m_core->initLayout( configurationMap.values( "partitionLayout" ).at( 0 ).toList() ); } else { @@ -677,19 +711,20 @@ Calamares::RequirementsList PartitionViewStep::checkRequirements() { if ( m_future ) + { m_future->waitForFinished(); + } Calamares::RequirementsList l; - l.append( - { + l.append( { QLatin1String( "partitions" ), - []{ return tr( "has at least one disk device available." ); }, - []{ return tr( "There are no partitions to install on." ); }, + [] { return tr( "has at least one disk device available." ); }, + [] { return tr( "There are no partitions to install on." ); }, m_core->deviceModel()->rowCount() > 0, // satisfied #ifdef DEBUG_PARTITION_UNSAFE - false // optional + false // optional #else - true // required + true // required #endif } ); @@ -697,4 +732,4 @@ PartitionViewStep::checkRequirements() } -CALAMARES_PLUGIN_FACTORY_DEFINITION( PartitionViewStepFactory, registerPlugin(); ) +CALAMARES_PLUGIN_FACTORY_DEFINITION( PartitionViewStepFactory, registerPlugin< PartitionViewStep >(); ) From 26dd93b67c426d3ee33ebd472ff135e16d3b87c0 Mon Sep 17 00:00:00 2001 From: Adriaan de Groot Date: Tue, 24 Mar 2020 22:32:49 +0100 Subject: [PATCH 17/32] [partition] Simplify code - isEfi only used meaningfully once - if (isEfi) followed by if (!isEfi) can be simpler - create bios-but-not-GPT strings in one go - mark TODO that this should warn only if needed - use weird * notation for branding-strings --- .../partition/gui/PartitionViewStep.cpp | 31 ++++++------------- 1 file changed, 9 insertions(+), 22 deletions(-) diff --git a/src/modules/partition/gui/PartitionViewStep.cpp b/src/modules/partition/gui/PartitionViewStep.cpp index 02ea5cb30..6a1cde3a6 100644 --- a/src/modules/partition/gui/PartitionViewStep.cpp +++ b/src/modules/partition/gui/PartitionViewStep.cpp @@ -2,8 +2,9 @@ * * Copyright 2014, Aurélien Gâteau * Copyright 2014-2017, Teo Mrnjavac - * Copyright 2018-2019, Adriaan de Groot + * Copyright 2018-2019, 2020, Adriaan de Groot * Copyright 2019, Collabora Ltd + * Copyright 2020, Anke Boersma #include -// Qt #include #include #include @@ -414,13 +413,7 @@ PartitionViewStep::onLeave() if ( m_widget->currentWidget() == m_manualPartitionPage ) { - bool isEfi = false; if ( PartUtils::isEfiSystem() ) - { - isEfi = true; - } - - if ( isEfi ) { QString espMountPoint = Calamares::JobQueue::instance()->globalStorage()->value( "efiSystemPartition" ).toString(); @@ -464,18 +457,15 @@ PartitionViewStep::onLeave() QMessageBox::warning( m_manualPartitionPage, message, description ); } } - - if ( !isEfi ) + else { cDebug() << "device: BIOS"; + // TODO: this *always* warns, which might be annoying, so it'd be + // best to find a way to detect that bios_grub partition. - Partition* bios_p = m_core->findPartitionByMountPoint( "" ); - QString message; - QString description; - - message = tr( "Option to use GPT on BIOS" ); - description = tr( "A GPT partition table is the best option for all " + QString message = tr( "Option to use GPT on BIOS" ); + QString description = tr( "A GPT partition table is the best option for all " "systems. This installer supports such a setup for " "BIOS systems too." "

" @@ -486,12 +476,9 @@ PartitionViewStep::onLeave() "bios_grub flag enabled.

" "An unformatted 8 MB partition is necessary " "to start %1 on a BIOS system with GPT." ) - .arg( Calamares::Branding::instance()->string( Calamares::Branding::ShortProductName ) ); + .arg( *Calamares::Branding::ShortProductName ); - if ( !message.isEmpty() ) - { - QMessageBox::information( m_manualPartitionPage, message, description ); - } + QMessageBox::information( m_manualPartitionPage, message, description ); } Partition* root_p = m_core->findPartitionByMountPoint( "/" ); From 08b50129463da91c356683a21170222924a8bb92 Mon Sep 17 00:00:00 2001 From: Adriaan de Groot Date: Tue, 24 Mar 2020 22:48:14 +0100 Subject: [PATCH 18/32] [locale] Apply coding style to Config - ci/calamaresstyle - sort includes by kind (local module, Calamares, Qt, STL) - add copyright line --- src/modules/locale/Config.cpp | 122 ++++++++++++++++++---------------- src/modules/locale/Config.h | 25 ++++--- 2 files changed, 80 insertions(+), 67 deletions(-) diff --git a/src/modules/locale/Config.cpp b/src/modules/locale/Config.cpp index 9bbbd5807..47e7b7fcf 100644 --- a/src/modules/locale/Config.cpp +++ b/src/modules/locale/Config.cpp @@ -1,6 +1,7 @@ /* === This file is part of Calamares - === * * Copyright 2019-2020, Adriaan de Groot + * Copyright 2020, Camilo Higuita * * Calamares is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -18,15 +19,12 @@ #include "Config.h" -#include -#include - +#include "LCLocaleDialog.h" #include "SetTimezoneJob.h" #include "timezonewidget/timezonewidget.h" #include "GlobalStorage.h" #include "JobQueue.h" -#include "LCLocaleDialog.h" #include "Settings.h" #include "locale/Label.h" @@ -35,22 +33,25 @@ #include "utils/Logger.h" #include "utils/Retranslator.h" -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(m_regionModel->item(m_regionModel->currentIndex()))->zones()); - updateLocaleLabels(); - }); +#include +#include - 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(); - }); + } ); + + connect( + m_zonesModel, &CalamaresUtils::Locale::CStringListModel::currentIndexChanged, [&]() { updateLocaleLabels(); } ); } Config::~Config() @@ -58,37 +59,37 @@ Config::~Config() qDeleteAll( m_regionList ); } -CalamaresUtils::Locale::CStringListModel * +CalamaresUtils::Locale::CStringListModel* Config::zonesModel() const { return m_zonesModel; } -CalamaresUtils::Locale::CStringListModel * +CalamaresUtils::Locale::CStringListModel* Config::regionModel() const { return m_regionModel; } 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; - cDebug()<< "REGION MODEL SIZE" << initialRegion << initialZone; + cDebug() << "REGION MODEL SIZE" << initialRegion << initialZone; auto* region = m_regionList.find< TZRegion >( initialRegion ); if ( region && region->zones().find< TZZone >( initialZone ) ) { - this->m_regionModel->setCurrentIndex(m_regionModel->indexOf(initialRegion)); - m_zonesModel->setList(region->zones()); - this->m_zonesModel->setCurrentIndex(m_zonesModel->indexOf(initialZone)); + this->m_regionModel->setCurrentIndex( m_regionModel->indexOf( initialRegion ) ); + m_zonesModel->setList( region->zones() ); + this->m_zonesModel->setCurrentIndex( m_zonesModel->indexOf( initialZone ) ); } else { - this->m_regionModel->setCurrentIndex(m_regionModel->indexOf("America")); - m_zonesModel->setList(static_cast(m_regionModel->item(m_regionModel->currentIndex()))->zones()); - this->m_zonesModel->setCurrentIndex(m_zonesModel->indexOf("New_York")); - + this->m_regionModel->setCurrentIndex( m_regionModel->indexOf( "America" ) ); + m_zonesModel->setList( + 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, @@ -121,8 +122,8 @@ Config::setLocaleInfo(const QString& initialRegion, const QString& initialZone, 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(); @@ -155,13 +156,13 @@ Config::setLocaleInfo(const QString& initialRegion, const QString& initialZone, 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() ? QLatin1String( "/etc/locale.gen" ) : localeGenPath ) << "\n\tOR" - << "* a complete pre-compiled locale-gen database which allows complete locale -a output."; + << "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() ? QLatin1String( "/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. } @@ -192,20 +193,22 @@ Config::setLocaleInfo(const QString& initialRegion, const QString& initialZone, updateLocaleLabels(); } -void Config::updateGlobalLocale() +void +Config::updateGlobalLocale() { auto* gs = Calamares::JobQueue::instance()->globalStorage(); const QString bcp47 = m_selectedLocaleConfiguration.toBcp47(); gs->insert( "locale", bcp47 ); } -void Config::updateGlobalStorage() +void +Config::updateGlobalStorage() { auto* gs = Calamares::JobQueue::instance()->globalStorage(); const auto* location = currentLocation(); bool locationChanged = ( location->region() != gs->value( "locationRegion" ) ) - || ( location->zone() != gs->value( "locationZone" ) ); + || ( location->zone() != gs->value( "locationZone" ) ); gs->insert( "locationRegion", location->region() ); gs->insert( "locationZone", location->zone() ); @@ -214,13 +217,13 @@ void Config::updateGlobalStorage() // 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. - #ifndef DEBUG_TIMEZONES +#ifndef DEBUG_TIMEZONES if ( locationChanged && Calamares::Settings::instance()->doChroot() ) { QProcess::execute( "timedatectl", // depends on systemd { "set-timezone", location->region() + '/' + location->zone() } ); } - #endif +#endif // Preserve those settings that have been made explicit. auto newLocale = guessLocaleConfiguration(); @@ -251,14 +254,14 @@ void Config::updateLocaleLabels() { LocaleConfiguration lc - = m_selectedLocaleConfiguration.isEmpty() ? guessLocaleConfiguration() : m_selectedLocaleConfiguration; + = m_selectedLocaleConfiguration.isEmpty() ? guessLocaleConfiguration() : m_selectedLocaleConfiguration; auto labels = prettyLocaleStatus( lc ); emit prettyStatusChanged(); } -std::pair -Config::prettyLocaleStatus(const LocaleConfiguration& lc) const +std::pair< QString, QString > +Config::prettyLocaleStatus( const LocaleConfiguration& lc ) const { using CalamaresUtils::Locale::Label; @@ -267,10 +270,11 @@ Config::prettyLocaleStatus(const LocaleConfiguration& lc) const return std::make_pair< QString, QString >( tr( "The system language will be set to %1." ).arg( lang.label() ), - 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; const CalamaresUtils::Locale::TZZone* location = currentLocation(); @@ -281,25 +285,30 @@ Calamares::JobList Config::createJobs() return list; } -LocaleConfiguration Config::guessLocaleConfiguration() const +LocaleConfiguration +Config::guessLocaleConfiguration() const { return LocaleConfiguration::fromLanguageAndLocation( QLocale().name(), m_localeGenLines, currentLocation() ? currentLocation()->country() : "" ); } -QMap Config::localesMap() +QMap< QString, QString > +Config::localesMap() { return m_selectedLocaleConfiguration.isEmpty() ? guessLocaleConfiguration().toMap() - : m_selectedLocaleConfiguration.toMap(); + : m_selectedLocaleConfiguration.toMap(); } -QString Config::prettyStatus() const +QString +Config::prettyStatus() const { QString status; - status += tr( "Set timezone to %1/%2.
" ).arg( m_regionModel->item(m_regionModel->currentIndex())->tr() ).arg( m_zonesModel->item(m_zonesModel->currentIndex())->tr() ); + status += tr( "Set timezone to %1/%2.
" ) + .arg( m_regionModel->item( m_regionModel->currentIndex() )->tr() ) + .arg( m_zonesModel->item( m_zonesModel->currentIndex() )->tr() ); LocaleConfiguration lc - = m_selectedLocaleConfiguration.isEmpty() ? guessLocaleConfiguration() : m_selectedLocaleConfiguration; + = m_selectedLocaleConfiguration.isEmpty() ? guessLocaleConfiguration() : m_selectedLocaleConfiguration; auto labels = prettyLocaleStatus( lc ); status += labels.first + "
"; status += labels.second + "
"; @@ -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(m_zonesModel->item(m_zonesModel->currentIndex())); + return static_cast< const CalamaresUtils::Locale::TZZone* >( m_zonesModel->item( m_zonesModel->currentIndex() ) ); } diff --git a/src/modules/locale/Config.h b/src/modules/locale/Config.h index 2af83b398..9105cb071 100644 --- a/src/modules/locale/Config.h +++ b/src/modules/locale/Config.h @@ -1,6 +1,7 @@ /* === This file is part of Calamares - === * * Copyright 2019-2020, Adriaan de Groot + * Copyright 2020, Camilo Higuita * * Calamares is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -19,21 +20,23 @@ #ifndef LOCALE_CONFIG_H #define LOCALE_CONFIG_H -#include -#include -#include -#include "Job.h" -#include "locale/TimeZone.h" #include "LocaleConfiguration.h" #include "timezonewidget/localeglobal.h" + +#include "Job.h" +#include "locale/TimeZone.h" + +#include +#include + #include class Config : public QObject { Q_OBJECT - Q_PROPERTY(CalamaresUtils::Locale::CStringListModel * zonesModel READ zonesModel CONSTANT FINAL) - Q_PROPERTY(CalamaresUtils::Locale::CStringListModel * regionModel READ regionModel CONSTANT FINAL) - Q_PROPERTY(QString prettyStatus READ prettyStatus NOTIFY prettyStatusChanged FINAL) + Q_PROPERTY( CalamaresUtils::Locale::CStringListModel* zonesModel READ zonesModel CONSTANT FINAL ) + Q_PROPERTY( CalamaresUtils::Locale::CStringListModel* regionModel READ regionModel CONSTANT FINAL ) + Q_PROPERTY( QString prettyStatus READ prettyStatus NOTIFY prettyStatusChanged FINAL ) public: Config( QObject* parent = nullptr ); @@ -41,7 +44,7 @@ public: CalamaresUtils::Locale::CStringListModel* regionModel() 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(); QMap< QString, QString > localesMap(); @@ -49,8 +52,8 @@ public: private: CalamaresUtils::Locale::CStringPairList m_regionList; - CalamaresUtils::Locale::CStringListModel * m_regionModel; - CalamaresUtils::Locale::CStringListModel * m_zonesModel; + CalamaresUtils::Locale::CStringListModel* m_regionModel; + CalamaresUtils::Locale::CStringListModel* m_zonesModel; LocaleConfiguration m_selectedLocaleConfiguration; From 177d6fe861e917662fd0f8ce5360d81478e32e69 Mon Sep 17 00:00:00 2001 From: Adriaan de Groot Date: Tue, 24 Mar 2020 22:57:36 +0100 Subject: [PATCH 19/32] [libcalamares] Apply coding style --- src/libcalamares/locale/TimeZone.cpp | 11 ++++++---- src/libcalamares/locale/TimeZone.h | 30 ++++++++++++++++------------ 2 files changed, 24 insertions(+), 17 deletions(-) diff --git a/src/libcalamares/locale/TimeZone.cpp b/src/libcalamares/locale/TimeZone.cpp index fb224f9c4..9d9d7d18e 100644 --- a/src/libcalamares/locale/TimeZone.cpp +++ b/src/libcalamares/locale/TimeZone.cpp @@ -239,7 +239,8 @@ CStringListModel::CStringListModel( CStringPairList l ) { } -void CStringListModel::setList(CalamaresUtils::Locale::CStringPairList l) +void +CStringListModel::setList( CalamaresUtils::Locale::CStringPairList l ) { beginResetModel(); m_list = l; @@ -270,10 +271,12 @@ CStringListModel::data( const QModelIndex& index, int role ) const } void -CStringListModel::setCurrentIndex(const int &index) +CStringListModel::setCurrentIndex( const int& index ) { if ( ( index < 0 ) || ( index >= m_list.count() ) ) + { return; + } m_currentIndex = index; emit currentIndexChanged(); @@ -285,10 +288,10 @@ CStringListModel::currentIndex() const return m_currentIndex; } -QHash +QHash< int, QByteArray > CStringListModel::roleNames() const { - return {{Qt::DisplayRole,"label"}, {Qt::UserRole, "key"}}; + return { { Qt::DisplayRole, "label" }, { Qt::UserRole, "key" } }; } const CStringPair* diff --git a/src/libcalamares/locale/TimeZone.h b/src/libcalamares/locale/TimeZone.h index 32c4622cf..774bf8af3 100644 --- a/src/libcalamares/locale/TimeZone.h +++ b/src/libcalamares/locale/TimeZone.h @@ -141,7 +141,7 @@ protected: class CStringListModel : public QAbstractListModel { Q_OBJECT - Q_PROPERTY(int currentIndex READ currentIndex WRITE setCurrentIndex NOTIFY currentIndexChanged) + Q_PROPERTY( int currentIndex READ currentIndex WRITE setCurrentIndex NOTIFY currentIndexChanged ) public: /// @brief Create empty model @@ -154,24 +154,28 @@ public: QVariant data( const QModelIndex& index, int role ) const override; const CStringPair* item( int index ) const; - QHash roleNames() const override; + QHash< int, QByteArray > roleNames() const override; - void setCurrentIndex(const int &index); + void setCurrentIndex( const int& index ); int currentIndex() const; - void setList(CStringPairList); + void setList( CStringPairList ); - inline int indexOf(const QString &key) + inline int indexOf( const QString& key ) { - const auto it = std::find_if(m_list.constBegin(), m_list.constEnd(), [&](const CalamaresUtils::Locale::CStringPair *item) -> bool + const auto it = std::find_if( + m_list.constBegin(), m_list.constEnd(), [&]( const CalamaresUtils::Locale::CStringPair* item ) -> bool { + return item->key() == key; + } ); + + if ( it != m_list.constEnd() ) { - return item->key() == key; - - }); - - if(it != m_list.constEnd()) - return std::distance(m_list.constBegin(), it); - else return -1; + return std::distance( m_list.constBegin(), it ); + } + else + { + return -1; + } } From 4aeb774812125a83fd584860afe245bf3b739052 Mon Sep 17 00:00:00 2001 From: Adriaan de Groot Date: Tue, 24 Mar 2020 23:52:20 +0100 Subject: [PATCH 20/32] [libcalamares] POD don't bother with const& --- src/libcalamares/locale/TimeZone.cpp | 2 +- src/libcalamares/locale/TimeZone.h | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/libcalamares/locale/TimeZone.cpp b/src/libcalamares/locale/TimeZone.cpp index 9d9d7d18e..e25cf2144 100644 --- a/src/libcalamares/locale/TimeZone.cpp +++ b/src/libcalamares/locale/TimeZone.cpp @@ -271,7 +271,7 @@ CStringListModel::data( const QModelIndex& index, int role ) const } void -CStringListModel::setCurrentIndex( const int& index ) +CStringListModel::setCurrentIndex( int index ) { if ( ( index < 0 ) || ( index >= m_list.count() ) ) { diff --git a/src/libcalamares/locale/TimeZone.h b/src/libcalamares/locale/TimeZone.h index 774bf8af3..1f51c1040 100644 --- a/src/libcalamares/locale/TimeZone.h +++ b/src/libcalamares/locale/TimeZone.h @@ -156,7 +156,7 @@ public: const CStringPair* item( int index ) const; QHash< int, QByteArray > roleNames() const override; - void setCurrentIndex( const int& index ); + void setCurrentIndex( int index ); int currentIndex() const; void setList( CStringPairList ); From 998790d69c7766be9d800ffa9c344266ca4a98f2 Mon Sep 17 00:00:00 2001 From: Adriaan de Groot Date: Tue, 24 Mar 2020 23:52:57 +0100 Subject: [PATCH 21/32] [libcalamares] Warnings-- --- src/libcalamares/locale/TimeZone.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/libcalamares/locale/TimeZone.h b/src/libcalamares/locale/TimeZone.h index 1f51c1040..a557c2fb2 100644 --- a/src/libcalamares/locale/TimeZone.h +++ b/src/libcalamares/locale/TimeZone.h @@ -145,7 +145,7 @@ class CStringListModel : public QAbstractListModel public: /// @brief Create empty model - CStringListModel() {}; + CStringListModel() {} /// @brief Create model from list (non-owning) CStringListModel( CStringPairList ); From e3b4689cab6bf55a7658ea87af56497aceafa1d9 Mon Sep 17 00:00:00 2001 From: Adriaan de Groot Date: Wed, 25 Mar 2020 00:42:42 +0100 Subject: [PATCH 22/32] [libcalamares] Warnings-- - It's the perennial struggle between Qt index types and STL ones --- src/libcalamares/locale/TimeZone.h | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/libcalamares/locale/TimeZone.h b/src/libcalamares/locale/TimeZone.h index a557c2fb2..5f1e19801 100644 --- a/src/libcalamares/locale/TimeZone.h +++ b/src/libcalamares/locale/TimeZone.h @@ -170,7 +170,8 @@ public: if ( it != m_list.constEnd() ) { - return std::distance( m_list.constBegin(), it ); + // distance() is usually a long long + return int( std::distance( m_list.constBegin(), it ) ); } else { From 1ede7003c0947201d328a57765b4e5d7e2f31a9b Mon Sep 17 00:00:00 2001 From: Adriaan de Groot Date: Wed, 25 Mar 2020 11:41:39 +0100 Subject: [PATCH 23/32] [welcome] Apply coding style --- src/modules/welcome/Config.cpp | 147 ++++++++-------- src/modules/welcome/Config.h | 68 +++----- src/modules/welcome/WelcomePage.cpp | 15 +- src/modules/welcome/WelcomePage.h | 4 +- src/modules/welcome/WelcomeViewStep.cpp | 216 ++++++++++++------------ src/modules/welcome/WelcomeViewStep.h | 2 +- 6 files changed, 224 insertions(+), 228 deletions(-) diff --git a/src/modules/welcome/Config.cpp b/src/modules/welcome/Config.cpp index fdc532d7f..9b7c84cbc 100644 --- a/src/modules/welcome/Config.cpp +++ b/src/modules/welcome/Config.cpp @@ -17,10 +17,10 @@ */ #include "Config.h" -#include "utils/Logger.h" -#include "utils/Retranslator.h" #include "Branding.h" #include "Settings.h" +#include "utils/Logger.h" +#include "utils/Retranslator.h" #include @@ -38,7 +38,7 @@ RequirementsModel::setRequirementsList( const Calamares::RequirementsList& requi m_satisfiedRequirements = std::none_of( m_requirements.begin(), m_requirements.end(), isUnSatisfied ); m_satisfiedMandatory = std::none_of( m_requirements.begin(), m_requirements.end(), isMandatoryAndUnSatisfied ); - emit satisfiedRequirementsChanged(m_satisfiedRequirements); + emit satisfiedRequirementsChanged( m_satisfiedRequirements ); emit satisfiedMandatoryChanged(); emit endResetModel(); } @@ -54,40 +54,41 @@ RequirementsModel::data( const QModelIndex& index, int role ) const { const auto requirement = m_requirements.at( index.row() ); - switch ( role ) - { - case Roles::Name: - return requirement.name; - case Roles::Details: - return requirement.enumerationText(); - case Roles::NegatedText: - return requirement.negatedText(); - case Roles::Satisfied: - return requirement.satisfied; - case Roles::Mandatory: - return requirement.mandatory; - default: - return QVariant(); - } + switch ( role ) + { + case Roles::Name: + return requirement.name; + case Roles::Details: + return requirement.enumerationText(); + case Roles::NegatedText: + return requirement.negatedText(); + case Roles::Satisfied: + return requirement.satisfied; + case Roles::Mandatory: + return requirement.mandatory; + default: + return QVariant(); + } } -QHash +QHash< int, QByteArray > RequirementsModel::roleNames() const { - static QHash roles; - roles[Roles::Name] = "name"; - roles[Roles::Details] = "details"; - roles[Roles::NegatedText] = "negatedText"; - roles[Roles::Satisfied] = "satisfied"; - roles[Roles::Mandatory] = "mandatory"; - return roles; + static QHash< int, QByteArray > roles; + roles[ Roles::Name ] = "name"; + roles[ Roles::Details ] = "details"; + roles[ Roles::NegatedText ] = "negatedText"; + roles[ Roles::Satisfied ] = "satisfied"; + roles[ Roles::Mandatory ] = "mandatory"; + return roles; } -Config::Config( QObject* parent ) : QObject( parent ) - , m_requirementsModel( new RequirementsModel( this )) +Config::Config( QObject* parent ) + : QObject( parent ) + , m_requirementsModel( new RequirementsModel( this ) ) , m_languages( CalamaresUtils::Locale::availableTranslations() ) { - connect(m_requirementsModel, &RequirementsModel::satisfiedRequirementsChanged, this, &Config::setIsNextEnabled); + connect( m_requirementsModel, &RequirementsModel::satisfiedRequirementsChanged, this, &Config::setIsNextEnabled ); initLanguages(); @@ -106,13 +107,13 @@ Config::retranslate() CalamaresUtils::Locale::LabelModel* Config::languagesModel() const { - return m_languages; + return m_languages; } QString Config::languageIcon() const { - return m_languageIcon; + return m_languageIcon; } void @@ -131,7 +132,7 @@ Config::initLanguages() cDebug() << Logger::SubEntry << "Matching approximate locale" << defaultLocale.language(); matchedLocaleIndex - = m_languages->find( [&]( const QLocale& x ) { return x.language() == defaultLocale.language(); } ); + = m_languages->find( [&]( const QLocale& x ) { return x.language() == defaultLocale.language(); } ); } if ( matchedLocaleIndex < 0 ) @@ -154,7 +155,7 @@ Config::initLanguages() cDebug() << Logger::SubEntry << "Matched with index" << matchedLocaleIndex << name; CalamaresUtils::installTranslator( name, Calamares::Branding::instance()->translationsDirectory(), qApp ); - setLocaleIndex( matchedLocaleIndex ); + setLocaleIndex( matchedLocaleIndex ); } else { @@ -165,23 +166,26 @@ Config::initLanguages() void Config::setCountryCode( const QString& countryCode ) { - m_countryCode = countryCode; - setLocaleIndex(CalamaresUtils::Locale::availableTranslations()->find( m_countryCode )); + m_countryCode = countryCode; + setLocaleIndex( CalamaresUtils::Locale::availableTranslations()->find( m_countryCode ) ); - emit countryCodeChanged( m_countryCode ); + emit countryCodeChanged( m_countryCode ); } void -Config::setLanguageIcon(const QString &languageIcon ) +Config::setLanguageIcon( const QString& languageIcon ) { - m_languageIcon = languageIcon; + m_languageIcon = languageIcon; } void -Config::setLocaleIndex(const int& index) +Config::setLocaleIndex( const int& index ) { - if(index == m_localeIndex || index > CalamaresUtils::Locale::availableTranslations()->rowCount(QModelIndex()) || index < 0) + if ( index == m_localeIndex || index > CalamaresUtils::Locale::availableTranslations()->rowCount( QModelIndex() ) + || index < 0 ) + { return; + } m_localeIndex = index; @@ -189,8 +193,7 @@ Config::setLocaleIndex(const int& index) cDebug() << "Selected locale" << selectedLocale; QLocale::setDefault( selectedLocale ); - CalamaresUtils::installTranslator( - selectedLocale, Calamares::Branding::instance()->translationsDirectory(), qApp ); + CalamaresUtils::installTranslator( selectedLocale, Calamares::Branding::instance()->translationsDirectory(), qApp ); emit localeIndexChanged( m_localeIndex ); } @@ -215,7 +218,7 @@ Config::donateUrl() const } void -Config::setDonateUrl(const QString& url) +Config::setDonateUrl( const QString& url ) { m_donateUrl = url; emit donateUrlChanged(); @@ -228,17 +231,17 @@ Config::knownIssuesUrl() const } void -Config::setKnownIssuesUrl(const QString& url) +Config::setKnownIssuesUrl( const QString& url ) { m_knownIssuesUrl = url; emit knownIssuesUrlChanged(); } void -Config::setReleaseNotesUrl(const QString& url) +Config::setReleaseNotesUrl( const QString& url ) { - m_releaseNotesUrl = url; - emit releaseNotesUrlChanged(); + m_releaseNotesUrl = url; + emit releaseNotesUrlChanged(); } QString @@ -254,7 +257,7 @@ Config::supportUrl() const } void -Config::setSupportUrl(const QString& url) +Config::setSupportUrl( const QString& url ) { m_supportUrl = url; emit supportUrlChanged(); @@ -271,32 +274,33 @@ RequirementsModel::retranslate() if ( !m_satisfiedMandatory ) { message = setup ? tr( "This computer does not satisfy the minimum " - "requirements for setting up %1.
" - "Setup cannot continue. " - "Details..." ) - : tr( "This computer does not satisfy the minimum " - "requirements for installing %1.
" - "Installation cannot continue. " - "Details..." ); - - }else + "requirements for setting up %1.
" + "Setup cannot continue. " + "Details..." ) + : tr( "This computer does not satisfy the minimum " + "requirements for installing %1.
" + "Installation cannot continue. " + "Details..." ); + } + else { message = setup ? tr( "This computer does not satisfy some of the " - "recommended requirements for setting up %1.
" - "Setup can continue, but some features " - "might be disabled." ) - : tr( "This computer does not satisfy some of the " - "recommended requirements for installing %1.
" - "Installation can continue, but some features " - "might be disabled." ); + "recommended requirements for setting up %1.
" + "Setup can continue, but some features " + "might be disabled." ) + : tr( "This computer does not satisfy some of the " + "recommended requirements for installing %1.
" + "Installation can continue, but some features " + "might be disabled." ); } m_warningMessage = message.arg( *Calamares::Branding::ShortVersionedName ); - }else + } + else { m_warningMessage = tr( "This program will ask you some questions and " - "set up %2 on your computer." ) - .arg( *Calamares::Branding::ProductName ); + "set up %2 on your computer." ) + .arg( *Calamares::Branding::ProductName ); } emit warningMessageChanged(); @@ -310,16 +314,15 @@ Config::genericWelcomeMessage() if ( Calamares::Settings::instance()->isSetupMode() ) { message = Calamares::Branding::instance()->welcomeStyleCalamares() - ? tr( "

Welcome to the Calamares setup program for %1.

" ) - : tr( "

Welcome to %1 setup.

" ); + ? tr( "

Welcome to the Calamares setup program for %1.

" ) + : tr( "

Welcome to %1 setup.

" ); } else { message = Calamares::Branding::instance()->welcomeStyleCalamares() - ? tr( "

Welcome to the Calamares installer for %1.

" ) - : tr( "

Welcome to the %1 installer.

" ); + ? tr( "

Welcome to the Calamares installer for %1.

" ) + : tr( "

Welcome to the %1 installer.

" ); } return message; } - diff --git a/src/modules/welcome/Config.h b/src/modules/welcome/Config.h index a6de4c5dd..072bbfccf 100644 --- a/src/modules/welcome/Config.h +++ b/src/modules/welcome/Config.h @@ -19,9 +19,9 @@ #ifndef WELCOME_CONFIG_H #define WELCOME_CONFIG_H +#include "modulesystem/Requirement.h" #include #include -#include "modulesystem/Requirement.h" #include "locale/LabelModel.h" @@ -29,9 +29,9 @@ class RequirementsModel : public QAbstractListModel { Q_OBJECT using QAbstractListModel::QAbstractListModel; - Q_PROPERTY(bool satisfiedRequirements READ satisfiedRequirements NOTIFY satisfiedRequirementsChanged FINAL) + Q_PROPERTY( bool satisfiedRequirements READ satisfiedRequirements NOTIFY satisfiedRequirementsChanged FINAL ) - Q_PROPERTY(bool satisfiedMandatory READ satisfiedMandatory NOTIFY satisfiedMandatoryChanged FINAL) + Q_PROPERTY( bool satisfiedMandatory READ satisfiedMandatory NOTIFY satisfiedMandatoryChanged FINAL ) Q_PROPERTY( QString warningMessage READ warningMessage NOTIFY warningMessageChanged FINAL ) public: @@ -45,44 +45,33 @@ public: HasDetails }; - bool satisfiedRequirements() const - { - return m_satisfiedRequirements; - } + bool satisfiedRequirements() const { return m_satisfiedRequirements; } - bool satisfiedMandatory() const - { - return m_satisfiedMandatory; - } + bool satisfiedMandatory() const { return m_satisfiedMandatory; } - const Calamares::RequirementEntry& getEntry(const int& index) const + const Calamares::RequirementEntry& getEntry( const int& index ) const { - if(index > count() || index < 0) - return *(new Calamares::RequirementEntry()); - - return m_requirements.at(index); + if ( index > count() || index < 0 ) + { + return *( new Calamares::RequirementEntry() ); + } + return m_requirements.at( index ); } void setRequirementsList( const Calamares::RequirementsList& requirements ); - int rowCount(const QModelIndex&) const override; - int count() const - { - return m_requirements.count(); - } + int rowCount( const QModelIndex& ) const override; + int count() const { return m_requirements.count(); } - QString warningMessage() const - { - return m_warningMessage; - } + QString warningMessage() const { return m_warningMessage; } void retranslate(); - QVariant data(const QModelIndex& index, int role) const override; + QVariant data( const QModelIndex& index, int role ) const override; protected: - QHash roleNames() const override; + QHash< int, QByteArray > roleNames() const override; private: Calamares::RequirementsList m_requirements; @@ -92,7 +81,7 @@ private: QString m_warningMessage; signals: - void satisfiedRequirementsChanged(bool value); + void satisfiedRequirementsChanged( bool value ); void satisfiedMandatoryChanged(); void warningMessageChanged(); }; @@ -101,45 +90,45 @@ signals: class Config : public QObject { Q_OBJECT - Q_PROPERTY( CalamaresUtils::Locale::LabelModel* languagesModel READ languagesModel CONSTANT FINAL) + Q_PROPERTY( CalamaresUtils::Locale::LabelModel* languagesModel READ languagesModel CONSTANT FINAL ) Q_PROPERTY( RequirementsModel* requirementsModel MEMBER m_requirementsModel CONSTANT FINAL ) Q_PROPERTY( QString languageIcon READ languageIcon CONSTANT FINAL ) Q_PROPERTY( QString countryCode MEMBER m_countryCode NOTIFY countryCodeChanged FINAL ) - Q_PROPERTY (int localeIndex READ localeIndex WRITE setLocaleIndex NOTIFY localeIndexChanged) + Q_PROPERTY( int localeIndex READ localeIndex WRITE setLocaleIndex NOTIFY localeIndexChanged ) Q_PROPERTY( QString genericWelcomeMessage MEMBER m_genericWelcomeMessage NOTIFY genericWelcomeMessageChanged FINAL ) Q_PROPERTY( QString supportUrl MEMBER m_supportUrl NOTIFY supportUrlChanged FINAL ) Q_PROPERTY( QString knownIssuesUrl MEMBER m_knownIssuesUrl NOTIFY knownIssuesUrlChanged FINAL ) Q_PROPERTY( QString releaseNotesUrl MEMBER m_releaseNotesUrl NOTIFY releaseNotesUrlChanged FINAL ) - Q_PROPERTY (QString donateUrl MEMBER m_donateUrl NOTIFY donateUrlChanged FINAL ) + Q_PROPERTY( QString donateUrl MEMBER m_donateUrl NOTIFY donateUrlChanged FINAL ) Q_PROPERTY( bool isNextEnabled MEMBER m_isNextEnabled NOTIFY isNextEnabledChanged FINAL ) public: Config( QObject* parent = nullptr ); - void setCountryCode( const QString &countryCode ); - void setLanguageIcon( const QString &languageIcon ); - RequirementsModel& requirementsModel () const; + void setCountryCode( const QString& countryCode ); + void setLanguageIcon( const QString& languageIcon ); + RequirementsModel& requirementsModel() const; void setIsNextEnabled( const bool& isNextEnabled ); - void setLocaleIndex(const int &index); + void setLocaleIndex( const int& index ); int localeIndex() const { return m_localeIndex; } QString supportUrl() const; - void setSupportUrl(const QString &url); + void setSupportUrl( const QString& url ); QString knownIssuesUrl() const; - void setKnownIssuesUrl(const QString &url); + void setKnownIssuesUrl( const QString& url ); QString releaseNotesUrl() const; - void setReleaseNotesUrl(const QString &url); + void setReleaseNotesUrl( const QString& url ); QString donateUrl() const; - void setDonateUrl(const QString &url); + void setDonateUrl( const QString& url ); QString genericWelcomeMessage(); @@ -175,7 +164,6 @@ signals: void knownIssuesUrlChanged(); void releaseNotesUrlChanged(); void donateUrlChanged(); - }; #endif diff --git a/src/modules/welcome/WelcomePage.cpp b/src/modules/welcome/WelcomePage.cpp index 8ab1479f0..f55c70bdc 100644 --- a/src/modules/welcome/WelcomePage.cpp +++ b/src/modules/welcome/WelcomePage.cpp @@ -25,9 +25,9 @@ #include "Branding.h" #include "CalamaresVersion.h" +#include "Config.h" #include "Settings.h" #include "ViewManager.h" -#include "Config.h" #include "locale/LabelModel.h" #include "modulesystem/ModuleManager.h" @@ -44,7 +44,7 @@ #include #include -WelcomePage::WelcomePage( Config *conf, QWidget* parent ) +WelcomePage::WelcomePage( Config* conf, QWidget* parent ) : QWidget( parent ) , ui( new Ui::WelcomePage ) , m_checkingWidget( new CheckerContainer( conf->requirementsModel(), this ) ) @@ -84,13 +84,14 @@ WelcomePage::WelcomePage( Config *conf, QWidget* parent ) ui->verticalLayout->insertWidget( welcome_text_idx + 1, m_checkingWidget ); } -void WelcomePage::init() +void +WelcomePage::init() { //setup the url buttons - setupButton( WelcomePage::Button::Support, m_conf->supportUrl()); + setupButton( WelcomePage::Button::Support, m_conf->supportUrl() ); setupButton( WelcomePage::Button::KnownIssues, m_conf->knownIssuesUrl() ); setupButton( WelcomePage::Button::ReleaseNotes, m_conf->releaseNotesUrl() ); - setupButton( WelcomePage::Button::Donate, m_conf->donateUrl()); + setupButton( WelcomePage::Button::Donate, m_conf->donateUrl() ); //language icon auto icon = Calamares::Branding::instance()->image( m_conf->languageIcon(), QSize( 48, 48 ) ); @@ -113,7 +114,9 @@ WelcomePage::initLanguages() ui->languageWidget->setCurrentIndex( m_conf->localeIndex() ); connect( ui->languageWidget, - static_cast< void ( QComboBox::* )( int ) >( &QComboBox::currentIndexChanged ), m_conf, &Config::setLocaleIndex ); + static_cast< void ( QComboBox::* )( int ) >( &QComboBox::currentIndexChanged ), + m_conf, + &Config::setLocaleIndex ); } void diff --git a/src/modules/welcome/WelcomePage.h b/src/modules/welcome/WelcomePage.h index 0fb899d8e..17fedc812 100644 --- a/src/modules/welcome/WelcomePage.h +++ b/src/modules/welcome/WelcomePage.h @@ -36,7 +36,7 @@ class WelcomePage : public QWidget { Q_OBJECT public: - explicit WelcomePage( Config *conf, QWidget* parent = nullptr ); + explicit WelcomePage( Config* conf, QWidget* parent = nullptr ); enum class Button { @@ -75,7 +75,7 @@ private: CheckerContainer* m_checkingWidget; CalamaresUtils::Locale::LabelModel* m_languages; - Config *m_conf; + Config* m_conf; }; /** @brief Delegate to display language information in two columns. diff --git a/src/modules/welcome/WelcomeViewStep.cpp b/src/modules/welcome/WelcomeViewStep.cpp index fcf19ce19..c79d4771c 100644 --- a/src/modules/welcome/WelcomeViewStep.cpp +++ b/src/modules/welcome/WelcomeViewStep.cpp @@ -37,73 +37,73 @@ CALAMARES_PLUGIN_FACTORY_DEFINITION( WelcomeViewStepFactory, registerPlugin< WelcomeViewStep >(); ) WelcomeViewStep::WelcomeViewStep( QObject* parent ) - : Calamares::ViewStep( parent ) - , m_requirementsChecker( new GeneralRequirements( this ) ) - , m_conf( new Config(this) ) + : Calamares::ViewStep( parent ) + , m_requirementsChecker( new GeneralRequirements( this ) ) + , m_conf( new Config( this ) ) { - connect( Calamares::ModuleManager::instance(), - &Calamares::ModuleManager::requirementsComplete, - this, - &WelcomeViewStep::nextStatusChanged ); + connect( Calamares::ModuleManager::instance(), + &Calamares::ModuleManager::requirementsComplete, + this, + &WelcomeViewStep::nextStatusChanged ); // the instance of the qqc2 or qwidgets page - m_widget = new WelcomePage(m_conf); + m_widget = new WelcomePage( m_conf ); } WelcomeViewStep::~WelcomeViewStep() { - if ( m_widget && m_widget->parent() == nullptr ) - { - m_widget->deleteLater(); - } + if ( m_widget && m_widget->parent() == nullptr ) + { + m_widget->deleteLater(); + } } QString WelcomeViewStep::prettyName() const { - return tr( "Welcome" ); + return tr( "Welcome" ); } QWidget* WelcomeViewStep::widget() { - return m_widget; + return m_widget; } bool WelcomeViewStep::isNextEnabled() const { - return m_widget->verdict(); + return m_widget->verdict(); } bool WelcomeViewStep::isBackEnabled() const { - return false; + return false; } bool WelcomeViewStep::isAtBeginning() const { - return true; + return true; } bool WelcomeViewStep::isAtEnd() const { - return true; + return true; } Calamares::JobList WelcomeViewStep::jobs() const { - return Calamares::JobList(); + return Calamares::JobList(); } @@ -122,125 +122,127 @@ WelcomeViewStep::jobs() const static QString jobOrBrandingSetting( Calamares::Branding::StringEntry e, const QVariantMap& map, const QString& key ) { - if ( !map.contains( key ) ) - { - return QString(); - } - auto v = map.value( key ); - if ( v.type() == QVariant::Bool ) - { - return v.toBool() ? ( *e ) : QString(); - } - if ( v.type() == QVariant::String ) - { - return v.toString(); - } + if ( !map.contains( key ) ) + { + return QString(); + } + auto v = map.value( key ); + if ( v.type() == QVariant::Bool ) + { + return v.toBool() ? ( *e ) : QString(); + } + if ( v.type() == QVariant::String ) + { + return v.toString(); + } - return QString(); + return QString(); } void WelcomeViewStep::setConfigurationMap( const QVariantMap& configurationMap ) { - using Calamares::Branding; + using Calamares::Branding; - m_conf->setSupportUrl( jobOrBrandingSetting( Branding::SupportUrl, configurationMap, "showSupportUrl" ) ); - m_conf->setKnownIssuesUrl( jobOrBrandingSetting( Branding::KnownIssuesUrl, configurationMap, "showKnownIssuesUrl" ) ); - m_conf->setReleaseNotesUrl( jobOrBrandingSetting( Branding::ReleaseNotesUrl, configurationMap, "showReleaseNotesUrl" ) ); - m_conf->setDonateUrl( CalamaresUtils::getString( configurationMap, "showDonateUrl" ) ); + m_conf->setSupportUrl( jobOrBrandingSetting( Branding::SupportUrl, configurationMap, "showSupportUrl" ) ); + m_conf->setKnownIssuesUrl( + jobOrBrandingSetting( Branding::KnownIssuesUrl, configurationMap, "showKnownIssuesUrl" ) ); + m_conf->setReleaseNotesUrl( + jobOrBrandingSetting( Branding::ReleaseNotesUrl, configurationMap, "showReleaseNotesUrl" ) ); + m_conf->setDonateUrl( CalamaresUtils::getString( configurationMap, "showDonateUrl" ) ); - if ( configurationMap.contains( "requirements" ) - && configurationMap.value( "requirements" ).type() == QVariant::Map ) - { - m_requirementsChecker->setConfigurationMap( configurationMap.value( "requirements" ).toMap() ); + if ( configurationMap.contains( "requirements" ) + && configurationMap.value( "requirements" ).type() == QVariant::Map ) + { + m_requirementsChecker->setConfigurationMap( configurationMap.value( "requirements" ).toMap() ); m_conf->requirementsModel().setRequirementsList( checkRequirements() ); - } - else - cWarning() << "no valid requirements map found in welcome " - "module configuration."; + } + else + cWarning() << "no valid requirements map found in welcome " + "module configuration."; - bool ok = false; - QVariantMap geoip = CalamaresUtils::getSubMap( configurationMap, "geoip", ok ); - if ( ok ) - { - using FWString = QFutureWatcher< QString >; + bool ok = false; + QVariantMap geoip = CalamaresUtils::getSubMap( configurationMap, "geoip", ok ); + if ( ok ) + { + using FWString = QFutureWatcher< QString >; - auto* handler = new CalamaresUtils::GeoIP::Handler( CalamaresUtils::getString( geoip, "style" ), - CalamaresUtils::getString( geoip, "url" ), - CalamaresUtils::getString( geoip, "selector" ) ); - if ( handler->type() != CalamaresUtils::GeoIP::Handler::Type::None ) - { - auto* future = new FWString(); - connect( future, &FWString::finished, [view = this, f = future, h = handler]() { - QString countryResult = f->future().result(); - cDebug() << "GeoIP result for welcome=" << countryResult; - view->setCountry( countryResult, h ); - f->deleteLater(); - delete h; - } ); - future->setFuture( handler->queryRaw() ); - } - else - { - // Would not produce useful country code anyway. - delete handler; - } - } + auto* handler = new CalamaresUtils::GeoIP::Handler( CalamaresUtils::getString( geoip, "style" ), + CalamaresUtils::getString( geoip, "url" ), + CalamaresUtils::getString( geoip, "selector" ) ); + if ( handler->type() != CalamaresUtils::GeoIP::Handler::Type::None ) + { + auto* future = new FWString(); + connect( future, &FWString::finished, [view = this, f = future, h = handler]() { + QString countryResult = f->future().result(); + cDebug() << "GeoIP result for welcome=" << countryResult; + view->setCountry( countryResult, h ); + f->deleteLater(); + delete h; + } ); + future->setFuture( handler->queryRaw() ); + } + else + { + // Would not produce useful country code anyway. + delete handler; + } + } - QString language = CalamaresUtils::getString( configurationMap, "languageIcon" ); - if ( !language.isEmpty() ) - { + QString language = CalamaresUtils::getString( configurationMap, "languageIcon" ); + if ( !language.isEmpty() ) + { m_conf->setLanguageIcon( language ); - } + } - //here init the qml or qwidgets needed bits - m_widget->init(); + //here init the qml or qwidgets needed bits + m_widget->init(); } Calamares::RequirementsList WelcomeViewStep::checkRequirements() { - return m_requirementsChecker->checkRequirements(); + return m_requirementsChecker->checkRequirements(); } static inline void logGeoIPHandler( CalamaresUtils::GeoIP::Handler* handler ) { - if ( handler ) - { - cDebug() << Logger::SubEntry << "Obtained from" << handler->url() << " (" - << static_cast< int >( handler->type() ) << handler->selector() << ')'; - } + if ( handler ) + { + cDebug() << Logger::SubEntry << "Obtained from" << handler->url() << " (" + << static_cast< int >( handler->type() ) << handler->selector() << ')'; + } } void WelcomeViewStep::setCountry( const QString& countryCode, CalamaresUtils::GeoIP::Handler* handler ) { - if ( countryCode.length() != 2 ) - { - cDebug() << "Unusable country code" << countryCode; - logGeoIPHandler( handler ); - return; - } + if ( countryCode.length() != 2 ) + { + cDebug() << "Unusable country code" << countryCode; + logGeoIPHandler( handler ); + return; + } - auto c_l = CalamaresUtils::Locale::countryData( countryCode ); - if ( c_l.first == QLocale::Country::AnyCountry ) - { - cDebug() << "Unusable country code" << countryCode; - logGeoIPHandler( handler ); - return; - } - else - { - int r = CalamaresUtils::Locale::availableTranslations()->find( countryCode ); - if ( r < 0 ) - { - cDebug() << "Unusable country code" << countryCode << "(no suitable translation)"; - } - if ( ( r >= 0 ) && m_conf ) - { + auto c_l = CalamaresUtils::Locale::countryData( countryCode ); + if ( c_l.first == QLocale::Country::AnyCountry ) + { + cDebug() << "Unusable country code" << countryCode; + logGeoIPHandler( handler ); + return; + } + else + { + int r = CalamaresUtils::Locale::availableTranslations()->find( countryCode ); + if ( r < 0 ) + { + cDebug() << "Unusable country code" << countryCode << "(no suitable translation)"; + } + if ( ( r >= 0 ) && m_conf ) + { m_conf->setCountryCode( countryCode ); } - } + } } diff --git a/src/modules/welcome/WelcomeViewStep.h b/src/modules/welcome/WelcomeViewStep.h index 1d4baa759..d4b9b3019 100644 --- a/src/modules/welcome/WelcomeViewStep.h +++ b/src/modules/welcome/WelcomeViewStep.h @@ -75,7 +75,7 @@ public: private: WelcomePage* m_widget; GeneralRequirements* m_requirementsChecker; - Config *m_conf; + Config* m_conf; }; CALAMARES_PLUGIN_FACTORY_DECLARATION( WelcomeViewStepFactory ) From 81912f9e7d03b0cdaabf2d4cbc1c856a80f32b2c Mon Sep 17 00:00:00 2001 From: Adriaan de Groot Date: Wed, 25 Mar 2020 12:00:41 +0100 Subject: [PATCH 24/32] [welcome] Style in Config --- src/modules/welcome/Config.cpp | 1 + src/modules/welcome/Config.h | 10 +++++----- 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/src/modules/welcome/Config.cpp b/src/modules/welcome/Config.cpp index 9b7c84cbc..dd170929d 100644 --- a/src/modules/welcome/Config.cpp +++ b/src/modules/welcome/Config.cpp @@ -17,6 +17,7 @@ */ #include "Config.h" + #include "Branding.h" #include "Settings.h" #include "utils/Logger.h" diff --git a/src/modules/welcome/Config.h b/src/modules/welcome/Config.h index 072bbfccf..389a45eec 100644 --- a/src/modules/welcome/Config.h +++ b/src/modules/welcome/Config.h @@ -20,21 +20,22 @@ #define WELCOME_CONFIG_H #include "modulesystem/Requirement.h" +#include "locale/LabelModel.h" + #include #include -#include "locale/LabelModel.h" - +// TODO: move this (and modulesystem/Requirement) to libcalamares class RequirementsModel : public QAbstractListModel { Q_OBJECT - using QAbstractListModel::QAbstractListModel; Q_PROPERTY( bool satisfiedRequirements READ satisfiedRequirements NOTIFY satisfiedRequirementsChanged FINAL ) - Q_PROPERTY( bool satisfiedMandatory READ satisfiedMandatory NOTIFY satisfiedMandatoryChanged FINAL ) Q_PROPERTY( QString warningMessage READ warningMessage NOTIFY warningMessageChanged FINAL ) public: + using QAbstractListModel::QAbstractListModel; + enum Roles : short { Name, @@ -51,7 +52,6 @@ public: const Calamares::RequirementEntry& getEntry( const int& index ) const { - if ( index > count() || index < 0 ) { return *( new Calamares::RequirementEntry() ); From 875f79b49faa3a5887359a5ae6f902c6d465e3f9 Mon Sep 17 00:00:00 2001 From: Adriaan de Groot Date: Wed, 25 Mar 2020 12:08:27 +0100 Subject: [PATCH 25/32] [libcalamares] Drop unused parameter - the `parent` when installing a translator was not used, so drop it from the API. Chase some uses of the API, but leave welcome-modules broken: there's a merge of those coming. --- src/calamares/CalamaresApplication.cpp | 2 +- src/libcalamares/utils/Retranslator.cpp | 2 +- src/libcalamares/utils/Retranslator.h | 3 +-- 3 files changed, 3 insertions(+), 4 deletions(-) diff --git a/src/calamares/CalamaresApplication.cpp b/src/calamares/CalamaresApplication.cpp index 2d36f5a49..e9083c225 100644 --- a/src/calamares/CalamaresApplication.cpp +++ b/src/calamares/CalamaresApplication.cpp @@ -83,7 +83,7 @@ CalamaresApplication::init() initQmlPath(); initBranding(); - CalamaresUtils::installTranslator( QLocale::system(), QString(), this ); + CalamaresUtils::installTranslator( QLocale::system(), QString() ); setQuitOnLastWindowClosed( false ); setWindowIcon( QIcon( Calamares::Branding::instance()->imagePath( Calamares::Branding::ProductIcon ) ) ); diff --git a/src/libcalamares/utils/Retranslator.cpp b/src/libcalamares/utils/Retranslator.cpp index 767d0581e..4cd618d97 100644 --- a/src/libcalamares/utils/Retranslator.cpp +++ b/src/libcalamares/utils/Retranslator.cpp @@ -197,7 +197,7 @@ static QTranslator* s_tztranslator = nullptr; static QString s_translatorLocaleName; void -installTranslator( const QLocale& locale, const QString& brandingTranslationsPrefix, QObject* ) +installTranslator( const QLocale& locale, const QString& brandingTranslationsPrefix ) { loadSingletonTranslator( BrandingLoader( locale, brandingTranslationsPrefix ), s_brandingTranslator ); loadSingletonTranslator( TZLoader( locale ), s_tztranslator ); diff --git a/src/libcalamares/utils/Retranslator.h b/src/libcalamares/utils/Retranslator.h index af322e5b5..d62a3b751 100644 --- a/src/libcalamares/utils/Retranslator.h +++ b/src/libcalamares/utils/Retranslator.h @@ -36,9 +36,8 @@ namespace CalamaresUtils * @brief installTranslator changes the application language. * @param locale the new locale. * @param brandingTranslationsPrefix the branding path prefix, from Calamares::Branding. - * @param parent the parent QObject. */ -DLLEXPORT void installTranslator( const QLocale& locale, const QString& brandingTranslationsPrefix, QObject* parent ); +DLLEXPORT void installTranslator( const QLocale& locale, const QString& brandingTranslationsPrefix ); DLLEXPORT QString translatorLocaleName(); From ce244d85141c8f97a6f86e2f2e0eb8e208a23cf6 Mon Sep 17 00:00:00 2001 From: Adriaan de Groot Date: Wed, 25 Mar 2020 13:46:27 +0100 Subject: [PATCH 26/32] [welcome] Style in viewstep (unrelated to merge) --- src/modules/welcome/WelcomeViewStep.cpp | 7 +++---- src/modules/welcome/WelcomeViewStep.h | 20 ++++++++++---------- 2 files changed, 13 insertions(+), 14 deletions(-) diff --git a/src/modules/welcome/WelcomeViewStep.cpp b/src/modules/welcome/WelcomeViewStep.cpp index c79d4771c..848d319db 100644 --- a/src/modules/welcome/WelcomeViewStep.cpp +++ b/src/modules/welcome/WelcomeViewStep.cpp @@ -18,19 +18,18 @@ */ #include "WelcomeViewStep.h" -#include "Config.h" +#include "Config.h" #include "WelcomePage.h" #include "checker/GeneralRequirements.h" +#include "Branding.h" #include "geoip/Handler.h" #include "locale/Lookup.h" +#include "modulesystem/ModuleManager.h" #include "utils/Logger.h" #include "utils/Variant.h" -#include "Branding.h" -#include "modulesystem/ModuleManager.h" - #include #include diff --git a/src/modules/welcome/WelcomeViewStep.h b/src/modules/welcome/WelcomeViewStep.h index d4b9b3019..3265395fc 100644 --- a/src/modules/welcome/WelcomeViewStep.h +++ b/src/modules/welcome/WelcomeViewStep.h @@ -16,22 +16,22 @@ * along with Calamares. If not, see . */ -#ifndef WELCOMEPAGEPLUGIN_H -#define WELCOMEPAGEPLUGIN_H +#ifndef WELCOMEVIEWSTEP_H +#define WELCOMEVIEWSTEP_H + + +#include "DllMacro.h" +#include "modulesystem/Requirement.h" +#include "utils/PluginFactory.h" +#include "viewpages/ViewStep.h" #include - -#include -#include -#include - -#include - #include class WelcomePage; class GeneralRequirements; class Config; + namespace CalamaresUtils { namespace GeoIP @@ -80,4 +80,4 @@ private: CALAMARES_PLUGIN_FACTORY_DECLARATION( WelcomeViewStepFactory ) -#endif // WELCOMEPAGEPLUGIN_H +#endif // WELCOMEVIEWSTEP_H From 2a93c7e23620eee11da5e1a93ca000be2c4b7d31 Mon Sep 17 00:00:00 2001 From: Adriaan de Groot Date: Wed, 25 Mar 2020 13:48:10 +0100 Subject: [PATCH 27/32] [welcome] Chase changed API in master --- src/modules/welcome/Config.cpp | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/src/modules/welcome/Config.cpp b/src/modules/welcome/Config.cpp index dd170929d..43987f4b2 100644 --- a/src/modules/welcome/Config.cpp +++ b/src/modules/welcome/Config.cpp @@ -23,8 +23,6 @@ #include "utils/Logger.h" #include "utils/Retranslator.h" -#include - void RequirementsModel::setRequirementsList( const Calamares::RequirementsList& requirements ) { @@ -155,7 +153,7 @@ Config::initLanguages() QString name = m_languages->locale( matchedLocaleIndex ).name(); cDebug() << Logger::SubEntry << "Matched with index" << matchedLocaleIndex << name; - CalamaresUtils::installTranslator( name, Calamares::Branding::instance()->translationsDirectory(), qApp ); + CalamaresUtils::installTranslator( name, Calamares::Branding::instance()->translationsDirectory() ); setLocaleIndex( matchedLocaleIndex ); } else @@ -194,7 +192,7 @@ Config::setLocaleIndex( const int& index ) cDebug() << "Selected locale" << selectedLocale; QLocale::setDefault( selectedLocale ); - CalamaresUtils::installTranslator( selectedLocale, Calamares::Branding::instance()->translationsDirectory(), qApp ); + CalamaresUtils::installTranslator( selectedLocale, Calamares::Branding::instance()->translationsDirectory() ); emit localeIndexChanged( m_localeIndex ); } From 215bc46469cb2a97e6e602a2ba2a9a0d0337be53 Mon Sep 17 00:00:00 2001 From: Adriaan de Groot Date: Wed, 25 Mar 2020 13:54:54 +0100 Subject: [PATCH 28/32] [welcome] Update copyright years in about-popup --- src/modules/welcome/WelcomePage.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/modules/welcome/WelcomePage.cpp b/src/modules/welcome/WelcomePage.cpp index f55c70bdc..e4be00fe7 100644 --- a/src/modules/welcome/WelcomePage.cpp +++ b/src/modules/welcome/WelcomePage.cpp @@ -235,7 +235,7 @@ WelcomePage::showAboutBox() "%2
" "for %3


" "Copyright 2014-2017 Teo Mrnjavac <teo@kde.org>
" - "Copyright 2017-2019 Adriaan de Groot <groot@kde.org>
" + "Copyright 2017-2020 Adriaan de Groot <groot@kde.org>
" "Thanks to the Calamares team " "and the Calamares " "translators team.

" From ac08598176663dd4edbb1df8c3ea337499d5aee7 Mon Sep 17 00:00:00 2001 From: Adriaan de Groot Date: Wed, 25 Mar 2020 23:35:33 +0100 Subject: [PATCH 29/32] Branding: expand the stylesheet example - Mention that the sidebar menu can't be styled - Point to more documentation about styling - Give an example of styling buttons with an icon --- src/branding/default/stylesheet.qss | 65 +++++++++++++++++++++++++---- 1 file changed, 58 insertions(+), 7 deletions(-) diff --git a/src/branding/default/stylesheet.qss b/src/branding/default/stylesheet.qss index c5341ee0a..72dd91ba4 100644 --- a/src/branding/default/stylesheet.qss +++ b/src/branding/default/stylesheet.qss @@ -6,26 +6,72 @@ In principle, all parts can be styled through CSS. Missing parts should be filed as issues. The IDs are based on the object names in the C++ code. +You can use the Debug Dialog to find out object names: + - Open the debug dialog + - Choose tab *Tools* + - Click *Widget Tree* button +The list of object names is printed in the log. Documentation for styling Qt Widgets through a stylesheet can be found at https://doc.qt.io/qt-5/stylesheet-examples.html + https://doc.qt.io/qt-5/stylesheet-reference.html In Calamares, styling widget classes is supported (e.g. -using `QComboBox` as a selector). You can also use specific -object names (ids), which you can find through debugging tools. +using `QComboBox` as a selector). + +This example stylesheet has all the actual styling commented out. +The examples are not exhaustive. */ -/* Main application window. +/*** Generic Widgets. + * + * You can style **all** widgets of a given class by selecting + * the class name. Some widgets have specialized sub-selectors. + */ +/* +QPushButton { background-color: green; } +*/ + +/*** Main application window. + * + * The main application window has the sidebar, which in turn + * contains a logo and a list of items -- note that the list + * can **not** be styled, since it has its own custom C++ + * delegate code. + */ + +/* #mainApp { } -#logoApp { } #sidebarApp { } -#sidebarMenuApp { } +#logoApp { } */ -/* Partitioning module. +/*** Welcome module. + * + * There are plenty of parts, but the buttons are the most interesting + * ones (donate, release notes, ...). The little icon image can be + * styled through *qproperty-icon*, which is a little obscure. + * URLs can reference the QRC paths of the Calamares application + * or loaded via plugins or within the filesystem. There is no + * comprehensive list of available icons, though. + */ +/* +QPushButton#aboutButton { qproperty-icon: url(:/data/images/release.svg); } +#donateButton, +#supportButton, +#releaseNotesButton, +#knownIssuesButton { qproperty-icon: url(:/data/images/help.svg); } +*/ + +/*** Partitioning module. + * + * Many moving parts, which you will need to experiment with. + */ + +/* #bootInfoIcon { } #bootInfoLable { } #deviceInfoIcon { } @@ -34,8 +80,13 @@ object names (ids), which you can find through debugging tools. #partitionBarView { } */ -/* Licensing module. +/*** Licensing module. + * + * The licensing module paints individual widgets for each of + * the licenses. The item can be collapsed or expanded. + */ +/* #licenseItem { } #licenseItemFullText { } */ From df0a98b2a4a3bd9244700a76edc08e8b5a73428c Mon Sep 17 00:00:00 2001 From: Adriaan de Groot Date: Thu, 26 Mar 2020 10:48:03 +0100 Subject: [PATCH 30/32] Docs: make editorconfig for CMake explicit (4-space indents) --- .editorconfig | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/.editorconfig b/.editorconfig index d282d6273..d5851076b 100644 --- a/.editorconfig +++ b/.editorconfig @@ -7,6 +7,16 @@ charset = utf-8 end_of_line = lf trim_trailing_whitespace = true +[CMakeLists.txt] +indent_style = space +indent_size = 4 +insert_final_newline = true + +[*.cmake] +indent_style = space +indent_size = 4 +insert_final_newline = true + [*.{py,cpp,h}] indent_style = space indent_size = 4 From ba8811c62851f0412ac753d8fd1c633f7220ebdb Mon Sep 17 00:00:00 2001 From: Adriaan de Groot Date: Thu, 26 Mar 2020 11:08:55 +0100 Subject: [PATCH 31/32] [keyboard] Apply coding style - Include order - ci/calamaresstyle - modern alias for job-list --- src/modules/keyboard/KeyboardViewStep.cpp | 44 +++++++++++++---------- src/modules/keyboard/KeyboardViewStep.h | 11 +++--- 2 files changed, 30 insertions(+), 25 deletions(-) diff --git a/src/modules/keyboard/KeyboardViewStep.cpp b/src/modules/keyboard/KeyboardViewStep.cpp index 40a5385a3..472ffbe7e 100644 --- a/src/modules/keyboard/KeyboardViewStep.cpp +++ b/src/modules/keyboard/KeyboardViewStep.cpp @@ -18,12 +18,12 @@ #include "KeyboardViewStep.h" -#include "JobQueue.h" -#include "GlobalStorage.h" - #include "KeyboardPage.h" -CALAMARES_PLUGIN_FACTORY_DEFINITION( KeyboardViewStepFactory, registerPlugin(); ) +#include "GlobalStorage.h" +#include "JobQueue.h" + +CALAMARES_PLUGIN_FACTORY_DEFINITION( KeyboardViewStepFactory, registerPlugin< KeyboardViewStep >(); ) KeyboardViewStep::KeyboardViewStep( QObject* parent ) : Calamares::ViewStep( parent ) @@ -40,7 +40,9 @@ KeyboardViewStep::KeyboardViewStep( QObject* parent ) KeyboardViewStep::~KeyboardViewStep() { if ( m_widget && m_widget->parent() == nullptr ) + { m_widget->deleteLater(); + } } @@ -111,9 +113,7 @@ void KeyboardViewStep::onLeave() { m_widget->finalize(); - m_jobs = m_widget->createJobs( m_xOrgConfFileName, - m_convertedKeymapPath, - m_writeEtcDefaultKeyboard ); + m_jobs = m_widget->createJobs( m_xOrgConfFileName, m_convertedKeymapPath, m_writeEtcDefaultKeyboard ); m_prettyStatus = m_widget->prettyStatus(); } @@ -121,29 +121,35 @@ KeyboardViewStep::onLeave() void KeyboardViewStep::setConfigurationMap( const QVariantMap& configurationMap ) { - if ( configurationMap.contains( "xOrgConfFileName" ) && - configurationMap.value( "xOrgConfFileName" ).type() == QVariant::String && - !configurationMap.value( "xOrgConfFileName" ).toString().isEmpty() ) + if ( configurationMap.contains( "xOrgConfFileName" ) + && configurationMap.value( "xOrgConfFileName" ).type() == QVariant::String + && !configurationMap.value( "xOrgConfFileName" ).toString().isEmpty() ) { - m_xOrgConfFileName = configurationMap.value( "xOrgConfFileName" ) - .toString(); + m_xOrgConfFileName = configurationMap.value( "xOrgConfFileName" ).toString(); } else + { m_xOrgConfFileName = "00-keyboard.conf"; + } - if ( configurationMap.contains( "convertedKeymapPath" ) && - configurationMap.value( "convertedKeymapPath" ).type() == QVariant::String && - !configurationMap.value( "convertedKeymapPath" ).toString().isEmpty() ) + if ( configurationMap.contains( "convertedKeymapPath" ) + && configurationMap.value( "convertedKeymapPath" ).type() == QVariant::String + && !configurationMap.value( "convertedKeymapPath" ).toString().isEmpty() ) { - m_convertedKeymapPath = configurationMap.value( "convertedKeymapPath" ) - .toString(); + m_convertedKeymapPath = configurationMap.value( "convertedKeymapPath" ).toString(); } else + { m_convertedKeymapPath = QString(); + } - if ( configurationMap.contains( "writeEtcDefaultKeyboard" ) && - configurationMap.value( "writeEtcDefaultKeyboard" ).type() == QVariant::Bool ) + if ( configurationMap.contains( "writeEtcDefaultKeyboard" ) + && configurationMap.value( "writeEtcDefaultKeyboard" ).type() == QVariant::Bool ) + { m_writeEtcDefaultKeyboard = configurationMap.value( "writeEtcDefaultKeyboard" ).toBool(); + } else + { m_writeEtcDefaultKeyboard = true; + } } diff --git a/src/modules/keyboard/KeyboardViewStep.h b/src/modules/keyboard/KeyboardViewStep.h index ed072c834..208d50686 100644 --- a/src/modules/keyboard/KeyboardViewStep.h +++ b/src/modules/keyboard/KeyboardViewStep.h @@ -20,12 +20,11 @@ #ifndef KEYBOARDVIEWSTEP_H #define KEYBOARDVIEWSTEP_H -#include - +#include "DllMacro.h" #include "utils/PluginFactory.h" #include "viewpages/ViewStep.h" -#include "DllMacro.h" +#include class KeyboardPage; @@ -48,7 +47,7 @@ public: bool isAtBeginning() const override; bool isAtEnd() const override; - QList< Calamares::job_ptr > jobs() const override; + Calamares::JobList jobs() const override; void onActivate() override; void onLeave() override; @@ -64,9 +63,9 @@ private: QString m_convertedKeymapPath; bool m_writeEtcDefaultKeyboard; - QList< Calamares::job_ptr > m_jobs; + Calamares::JobList m_jobs; }; CALAMARES_PLUGIN_FACTORY_DECLARATION( KeyboardViewStepFactory ) -#endif // KEYBOARDVIEWSTEP_H +#endif // KEYBOARDVIEWSTEP_H From 463435db6872f2e127483d5ecefc812446140aec Mon Sep 17 00:00:00 2001 From: Adriaan de Groot Date: Thu, 26 Mar 2020 11:39:04 +0100 Subject: [PATCH 32/32] [localeq] De-cruft CMakeLists - Remove commented-out code - Fix layout - Update to modern CMake approach --- src/modules/localeq/CMakeLists.txt | 23 +++++------------------ 1 file changed, 5 insertions(+), 18 deletions(-) diff --git a/src/modules/localeq/CMakeLists.txt b/src/modules/localeq/CMakeLists.txt index 99fac2a7e..b9ee645fc 100644 --- a/src/modules/localeq/CMakeLists.txt +++ b/src/modules/localeq/CMakeLists.txt @@ -6,37 +6,24 @@ if( DEBUG_TIMEZONES ) add_definitions( -DDEBUG_TIMEZONES ) endif() +# Because we're sharing sources with the regular locale module set( _locale ${CMAKE_CURRENT_SOURCE_DIR}/../locale ) -include_directories( ${PROJECT_BINARY_DIR}/src/libcalamaresui ${CMAKE_CURRENT_SOURCE_DIR}/../../libcalamares ${_locale} ) +include_directories( ${_locale} ) calamares_add_plugin( localeq TYPE viewmodule EXPORT_MACRO PLUGINDLLEXPORT_PRO SOURCES - ${geoip_src} LocaleQmlViewStep.cpp - ${_locale}/LocaleConfiguration.cpp - ${_locale}/Config.cpp + ${_locale}/LocaleConfiguration.cpp + ${_locale}/Config.cpp ${_locale}/SetTimezoneJob.cpp - ${_locale}/timezonewidget/localeglobal.cpp + ${_locale}/timezonewidget/localeglobal.cpp RESOURCES ${_locale}/locale.qrc LINK_PRIVATE_LIBRARIES calamaresui Qt5::Network - ${geoip_libs} - ${YAMLCPP_LIBRARY} SHARED_LIB ) - -# add_executable( localeqmltest qmlmain.cpp Config.cpp LocaleQmlViewStep.cpp LocaleConfiguration.cpp timezonewidget/localeglobal.cpp SetTimezoneJob.cpp ${geoip_src} ) -# target_link_libraries( localeqmltest PRIVATE calamaresui Qt5::Core Qt5::Network Qt5::DBus ${geoip_libs}) -# set_target_properties( localeqmltest -# PROPERTIES -# ENABLE_EXPORTS TRUE -# RUNTIME_OUTPUT_NAME localeqmltest -# ) -# calamares_automoc( localeqmltest ) -# calamares_autouic( localeqmltest ) -