From 120a2b0f033e0002288011f081256c6ce3c198ea Mon Sep 17 00:00:00 2001 From: Adriaan de Groot Date: Wed, 6 May 2020 15:08:31 +0200 Subject: [PATCH] [welcome] Move get-the-show*Url code into Config - Since this is configuration-loading, put it in the Config class; reduces code duplication between welcome and welcomeq. --- src/modules/welcome/Config.cpp | 45 +++++++++++++++++++++ src/modules/welcome/Config.h | 2 + src/modules/welcome/WelcomeViewStep.cpp | 41 +------------------ src/modules/welcomeq/WelcomeQmlViewStep.cpp | 40 +----------------- 4 files changed, 49 insertions(+), 79 deletions(-) diff --git a/src/modules/welcome/Config.cpp b/src/modules/welcome/Config.cpp index 6612fd030..95e029728 100644 --- a/src/modules/welcome/Config.cpp +++ b/src/modules/welcome/Config.cpp @@ -245,3 +245,48 @@ Config::warningMessage() const { return m_warningMessage; } + +/** @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() ? ( Calamares::Branding::instance()->string( e ) ) : QString(); + } + if ( v.type() == QVariant::String ) + { + return v.toString(); + } + + return QString(); +} + +void +Config::setConfigurationMap( const QVariantMap& configurationMap ) +{ + using Calamares::Branding; + + setSupportUrl( jobOrBrandingSetting( Branding::SupportUrl, configurationMap, "showSupportUrl" ) ); + setKnownIssuesUrl( + jobOrBrandingSetting( Branding::KnownIssuesUrl, configurationMap, "showKnownIssuesUrl" ) ); + setReleaseNotesUrl( + jobOrBrandingSetting( Branding::ReleaseNotesUrl, configurationMap, "showReleaseNotesUrl" ) ); + setDonateUrl( jobOrBrandingSetting( Branding::DonateUrl, configurationMap, "showDonateUrl" ) ); +} diff --git a/src/modules/welcome/Config.h b/src/modules/welcome/Config.h index db26ec169..0123482f3 100644 --- a/src/modules/welcome/Config.h +++ b/src/modules/welcome/Config.h @@ -50,6 +50,8 @@ class Config : public QObject public: Config( QObject* parent = nullptr ); + void setConfigurationMap( const QVariantMap& ); + Calamares::RequirementsModel& requirementsModel() const; void setCountryCode( const QString& countryCode ); diff --git a/src/modules/welcome/WelcomeViewStep.cpp b/src/modules/welcome/WelcomeViewStep.cpp index 8e6ca13ed..f6d0a878e 100644 --- a/src/modules/welcome/WelcomeViewStep.cpp +++ b/src/modules/welcome/WelcomeViewStep.cpp @@ -107,49 +107,10 @@ WelcomeViewStep::jobs() const } -/** @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() ? ( Calamares::Branding::instance()->string( e ) ) : QString(); - } - if ( v.type() == QVariant::String ) - { - return v.toString(); - } - - return QString(); -} - void WelcomeViewStep::setConfigurationMap( const QVariantMap& configurationMap ) { - 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->setConfigurationMap( configurationMap ); if ( configurationMap.contains( "requirements" ) && configurationMap.value( "requirements" ).type() == QVariant::Map ) diff --git a/src/modules/welcomeq/WelcomeQmlViewStep.cpp b/src/modules/welcomeq/WelcomeQmlViewStep.cpp index fcda52314..ac915e771 100644 --- a/src/modules/welcomeq/WelcomeQmlViewStep.cpp +++ b/src/modules/welcomeq/WelcomeQmlViewStep.cpp @@ -98,48 +98,10 @@ 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() ? ( Calamares::Branding::instance()->string( 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 accessed without having to declare a property, get and setter for each + m_config->setConfigurationMap( configurationMap ); // TODO: figure out how the requirements (held by ModuleManager) should be accessible // to QML as a model. //will be model as a qvariantmap containing a alert level and the message string