From cd44f548f59857f55c78f9ad291a5a55905b6c14 Mon Sep 17 00:00:00 2001 From: Adriaan de Groot Date: Wed, 6 May 2020 14:29:35 +0200 Subject: [PATCH 1/7] [libcalamaresui] Add donateUrl to the branding settings SEE #1384 --- src/branding/default/branding.desc | 1 + src/libcalamaresui/Branding.cpp | 3 ++- src/libcalamaresui/Branding.h | 3 ++- 3 files changed, 5 insertions(+), 2 deletions(-) diff --git a/src/branding/default/branding.desc b/src/branding/default/branding.desc index 720bcc25d..2e6a02bba 100644 --- a/src/branding/default/branding.desc +++ b/src/branding/default/branding.desc @@ -103,6 +103,7 @@ strings: supportUrl: https://github.com/calamares/calamares/issues knownIssuesUrl: https://calamares.io/about/ releaseNotesUrl: https://calamares.io/about/ + donateUrl: https://kde.org/community/donations/index.php # These images are loaded from the branding module directory. # diff --git a/src/libcalamaresui/Branding.cpp b/src/libcalamaresui/Branding.cpp index bd2d94c5c..ae8f3910f 100644 --- a/src/libcalamaresui/Branding.cpp +++ b/src/libcalamaresui/Branding.cpp @@ -67,7 +67,8 @@ const QStringList Branding::s_stringEntryStrings = "productUrl", "supportUrl", "knownIssuesUrl", - "releaseNotesUrl" + "releaseNotesUrl", + "donateUrl" }; diff --git a/src/libcalamaresui/Branding.h b/src/libcalamaresui/Branding.h index 0a275448f..0ba66a192 100644 --- a/src/libcalamaresui/Branding.h +++ b/src/libcalamaresui/Branding.h @@ -61,7 +61,8 @@ public: ProductUrl, SupportUrl, KnownIssuesUrl, - ReleaseNotesUrl + ReleaseNotesUrl, + DonateUrl }; Q_ENUM( StringEntry ) From e65a0ee6179aa5d186f6f9d08094a1976bd0e219 Mon Sep 17 00:00:00 2001 From: Adriaan de Groot Date: Wed, 6 May 2020 14:37:59 +0200 Subject: [PATCH 2/7] [welcome] Update welcome example - donate **does** have a corresponding branding setting - show that "false" is a valid setting --- src/modules/welcome/welcome.conf | 11 ++--------- 1 file changed, 2 insertions(+), 9 deletions(-) diff --git a/src/modules/welcome/welcome.conf b/src/modules/welcome/welcome.conf index 0361830aa..224bc6ded 100644 --- a/src/modules/welcome/welcome.conf +++ b/src/modules/welcome/welcome.conf @@ -14,15 +14,8 @@ # which will hide the button. showSupportUrl: true showKnownIssuesUrl: true -showReleaseNotesUrl: true - -# If this Url is set to something non-empty, a "donate" -# button is added to the welcome page alongside the -# others (see settings, above). Clicking the button opens -# the corresponding link. (This button has no corresponding -# branding.desc string) -# -# showDonateUrl: https://kde.org/community/donations/ +showReleaseNotesUrl: false +showDonateUrl: https://kde.org/community/donations/ # Requirements checking. These are general, generic, things # that are checked. They may not match with the actual requirements From 120a2b0f033e0002288011f081256c6ce3c198ea Mon Sep 17 00:00:00 2001 From: Adriaan de Groot Date: Wed, 6 May 2020 15:08:31 +0200 Subject: [PATCH 3/7] [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 From a7a6c937eacffd825f804d3c1caf651a34bbd227 Mon Sep 17 00:00:00 2001 From: Adriaan de Groot Date: Wed, 6 May 2020 15:23:27 +0200 Subject: [PATCH 4/7] [libcalamaresui] Add needed includes - Return type QPixmap means we should definitely #include it --- src/libcalamaresui/Branding.h | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/libcalamaresui/Branding.h b/src/libcalamaresui/Branding.h index 0ba66a192..ce694a644 100644 --- a/src/libcalamaresui/Branding.h +++ b/src/libcalamaresui/Branding.h @@ -28,6 +28,8 @@ #include #include +#include +#include #include namespace YAML From 6434374bf3e5f8672cf2255d4a8c4a61b78830c7 Mon Sep 17 00:00:00 2001 From: Adriaan de Groot Date: Wed, 6 May 2020 15:24:08 +0200 Subject: [PATCH 5/7] [welcome] Move languageIcon loading into the Config object - The QML module had an additional check that the normal one did not; add it in the merged code. --- src/modules/welcome/Config.cpp | 11 +++++++++++ src/modules/welcome/WelcomeViewStep.cpp | 6 ------ src/modules/welcomeq/WelcomeQmlViewStep.cpp | 10 ---------- 3 files changed, 11 insertions(+), 16 deletions(-) diff --git a/src/modules/welcome/Config.cpp b/src/modules/welcome/Config.cpp index 95e029728..1be331f62 100644 --- a/src/modules/welcome/Config.cpp +++ b/src/modules/welcome/Config.cpp @@ -22,6 +22,7 @@ #include "Settings.h" #include "utils/Logger.h" #include "utils/Retranslator.h" +#include "utils/Variant.h" Config::Config( QObject* parent ) : QObject( parent ) @@ -289,4 +290,14 @@ Config::setConfigurationMap( const QVariantMap& configurationMap ) setReleaseNotesUrl( jobOrBrandingSetting( Branding::ReleaseNotesUrl, configurationMap, "showReleaseNotesUrl" ) ); setDonateUrl( jobOrBrandingSetting( Branding::DonateUrl, configurationMap, "showDonateUrl" ) ); + + QString language = CalamaresUtils::getString( configurationMap, "languageIcon" ); + if ( !language.isEmpty() ) + { + auto icon = Calamares::Branding::instance()->image( language, QSize( 48, 48 ) ); + if ( !icon.isNull() ) + { + setLanguageIcon( language ); + } + } } diff --git a/src/modules/welcome/WelcomeViewStep.cpp b/src/modules/welcome/WelcomeViewStep.cpp index f6d0a878e..2060286c8 100644 --- a/src/modules/welcome/WelcomeViewStep.cpp +++ b/src/modules/welcome/WelcomeViewStep.cpp @@ -151,12 +151,6 @@ WelcomeViewStep::setConfigurationMap( const QVariantMap& configurationMap ) } } - QString language = CalamaresUtils::getString( configurationMap, "languageIcon" ); - if ( !language.isEmpty() ) - { - m_conf->setLanguageIcon( language ); - } - //here init the qml or qwidgets needed bits m_widget->init(); } diff --git a/src/modules/welcomeq/WelcomeQmlViewStep.cpp b/src/modules/welcomeq/WelcomeQmlViewStep.cpp index ac915e771..cb63a1e03 100644 --- a/src/modules/welcomeq/WelcomeQmlViewStep.cpp +++ b/src/modules/welcomeq/WelcomeQmlViewStep.cpp @@ -144,16 +144,6 @@ WelcomeQmlViewStep::setConfigurationMap( const QVariantMap& configurationMap ) } } - QString language = CalamaresUtils::getString( configurationMap, "languageIcon" ); - if ( !language.isEmpty() ) - { - auto icon = Calamares::Branding::instance()->image( language, QSize( 48, 48 ) ); - if ( !icon.isNull() ) - { - m_config->setLanguageIcon(language); - } - } - Calamares::QmlViewStep::setConfigurationMap( configurationMap ); // call parent implementation last setContextProperty( "Welcome", m_config ); } From 713132d4af2a4322f9d55eb27f0c05cdfa316c00 Mon Sep 17 00:00:00 2001 From: Adriaan de Groot Date: Wed, 6 May 2020 15:46:23 +0200 Subject: [PATCH 6/7] [welcome] Move GeoIP loading into Config - The Config object can handle GeoIP loading on its own. Both View steps that used this had a derpy view->setCountry() that didn't really do anything with the view anymore. --- src/modules/welcome/Config.cpp | 102 ++++++++++++++++++-- src/modules/welcome/WelcomeViewStep.cpp | 73 -------------- src/modules/welcomeq/WelcomeQmlViewStep.cpp | 76 --------------- 3 files changed, 93 insertions(+), 158 deletions(-) diff --git a/src/modules/welcome/Config.cpp b/src/modules/welcome/Config.cpp index 1be331f62..51f82ba99 100644 --- a/src/modules/welcome/Config.cpp +++ b/src/modules/welcome/Config.cpp @@ -20,10 +20,14 @@ #include "Branding.h" #include "Settings.h" +#include "geoip/Handler.h" +#include "locale/Lookup.h" #include "utils/Logger.h" #include "utils/Retranslator.h" #include "utils/Variant.h" +#include + Config::Config( QObject* parent ) : QObject( parent ) , m_requirementsModel( new Calamares::RequirementsModel( this ) ) @@ -279,6 +283,93 @@ jobOrBrandingSetting( Calamares::Branding::StringEntry e, const QVariantMap& map return QString(); } +static inline void +setLanguageIcon( Config* c, const QVariantMap& configurationMap ) +{ + QString language = CalamaresUtils::getString( configurationMap, "languageIcon" ); + if ( !language.isEmpty() ) + { + auto icon = Calamares::Branding::instance()->image( language, QSize( 48, 48 ) ); + if ( !icon.isNull() ) + { + c->setLanguageIcon( language ); + } + } +} + +static inline void +logGeoIPHandler( CalamaresUtils::GeoIP::Handler* handler ) +{ + if ( handler ) + { + cDebug() << Logger::SubEntry << "Obtained from" << handler->url() << " (" + << static_cast< int >( handler->type() ) << handler->selector() << ')'; + } +} + +static void +setCountry( Config* config, const QString& countryCode, CalamaresUtils::GeoIP::Handler* handler ) +{ + 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 ) && config ) + { + config->setCountryCode( countryCode ); + } + } +} + +static inline void +setGeoIP( Config* c, const QVariantMap& configurationMap ) +{ + 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(); + QObject::connect( future, &FWString::finished, [ config = c, f = future, h = handler ]() { + QString countryResult = f->future().result(); + cDebug() << "GeoIP result for welcome=" << countryResult; + ::setCountry( config, countryResult, h ); + f->deleteLater(); + delete h; + } ); + future->setFuture( handler->queryRaw() ); + } + else + { + // Would not produce useful country code anyway. + delete handler; + } + } +} + void Config::setConfigurationMap( const QVariantMap& configurationMap ) { @@ -291,13 +382,6 @@ Config::setConfigurationMap( const QVariantMap& configurationMap ) jobOrBrandingSetting( Branding::ReleaseNotesUrl, configurationMap, "showReleaseNotesUrl" ) ); setDonateUrl( jobOrBrandingSetting( Branding::DonateUrl, configurationMap, "showDonateUrl" ) ); - QString language = CalamaresUtils::getString( configurationMap, "languageIcon" ); - if ( !language.isEmpty() ) - { - auto icon = Calamares::Branding::instance()->image( language, QSize( 48, 48 ) ); - if ( !icon.isNull() ) - { - setLanguageIcon( language ); - } - } + ::setLanguageIcon( this, configurationMap ); + ::setGeoIP( this, configurationMap ); } diff --git a/src/modules/welcome/WelcomeViewStep.cpp b/src/modules/welcome/WelcomeViewStep.cpp index 2060286c8..486102ccb 100644 --- a/src/modules/welcome/WelcomeViewStep.cpp +++ b/src/modules/welcome/WelcomeViewStep.cpp @@ -24,15 +24,10 @@ #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 -#include - CALAMARES_PLUGIN_FACTORY_DEFINITION( WelcomeViewStepFactory, registerPlugin< WelcomeViewStep >(); ) WelcomeViewStep::WelcomeViewStep( QObject* parent ) @@ -123,34 +118,6 @@ WelcomeViewStep::setConfigurationMap( const QVariantMap& configurationMap ) 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 >; - - 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; - } - } - //here init the qml or qwidgets needed bits m_widget->init(); } @@ -161,43 +128,3 @@ WelcomeViewStep::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() << ')'; - } -} - -void -WelcomeViewStep::setCountry( const QString& countryCode, CalamaresUtils::GeoIP::Handler* handler ) -{ - 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 ) - { - m_conf->setCountryCode( countryCode ); - } - } -} diff --git a/src/modules/welcomeq/WelcomeQmlViewStep.cpp b/src/modules/welcomeq/WelcomeQmlViewStep.cpp index cb63a1e03..4869673bb 100644 --- a/src/modules/welcomeq/WelcomeQmlViewStep.cpp +++ b/src/modules/welcomeq/WelcomeQmlViewStep.cpp @@ -21,22 +21,15 @@ #include "checker/GeneralRequirements.h" -#include "geoip/Handler.h" #include "locale/LabelModel.h" -#include "locale/Lookup.h" #include "utils/Logger.h" #include "utils/Variant.h" #include "utils/Dirs.h" #include "Branding.h" #include "modulesystem/ModuleManager.h" -#include #include "utils/Yaml.h" -#include -#include -#include - CALAMARES_PLUGIN_FACTORY_DEFINITION( WelcomeQmlViewStepFactory, registerPlugin< WelcomeQmlViewStep >(); ) WelcomeQmlViewStep::WelcomeQmlViewStep( QObject* parent ) @@ -116,34 +109,6 @@ WelcomeQmlViewStep::setConfigurationMap( const QVariantMap& configurationMap ) 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 >; - - 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; - } - } - Calamares::QmlViewStep::setConfigurationMap( configurationMap ); // call parent implementation last setContextProperty( "Welcome", m_config ); } @@ -160,44 +125,3 @@ WelcomeQmlViewStep::getConfig() return m_config; } -static inline void -logGeoIPHandler( CalamaresUtils::GeoIP::Handler* handler ) -{ - if ( handler ) - { - cDebug() << Logger::SubEntry << "Obtained from" << handler->url() << " (" - << static_cast< int >( handler->type() ) << handler->selector() << ')'; - } -} - -void -WelcomeQmlViewStep::setCountry( const QString& countryCode, CalamaresUtils::GeoIP::Handler* handler ) -{ - 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 ) ) - { - // TODO: update Config to point to selected language - m_config->setCountryCode( countryCode ); - } - } -} From 5dc358093e3e1facceb59a457158ed37af8c0884 Mon Sep 17 00:00:00 2001 From: Adriaan de Groot Date: Wed, 6 May 2020 15:52:56 +0200 Subject: [PATCH 7/7] [welcome] Apply coding style --- src/modules/welcome/Config.cpp | 12 +++++------- src/modules/welcome/WelcomePage.cpp | 2 +- src/modules/welcome/WelcomeViewStep.cpp | 1 - 3 files changed, 6 insertions(+), 9 deletions(-) diff --git a/src/modules/welcome/Config.cpp b/src/modules/welcome/Config.cpp index 51f82ba99..8ca20af7e 100644 --- a/src/modules/welcome/Config.cpp +++ b/src/modules/welcome/Config.cpp @@ -108,7 +108,7 @@ Config::initLanguages() QLocale defaultLocale = QLocale( QLocale::system().name() ); cDebug() << "Matching locale" << defaultLocale; - int matchedLocaleIndex = m_languages->find( [ & ]( const QLocale& x ) { + int matchedLocaleIndex = m_languages->find( [&]( const QLocale& x ) { return x.language() == defaultLocale.language() && x.country() == defaultLocale.country(); } ); @@ -117,7 +117,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 ) @@ -353,7 +353,7 @@ setGeoIP( Config* c, const QVariantMap& configurationMap ) if ( handler->type() != CalamaresUtils::GeoIP::Handler::Type::None ) { auto* future = new FWString(); - QObject::connect( future, &FWString::finished, [ config = c, f = future, h = handler ]() { + QObject::connect( future, &FWString::finished, [config = c, f = future, h = handler]() { QString countryResult = f->future().result(); cDebug() << "GeoIP result for welcome=" << countryResult; ::setCountry( config, countryResult, h ); @@ -376,10 +376,8 @@ 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" ) ); + setKnownIssuesUrl( jobOrBrandingSetting( Branding::KnownIssuesUrl, configurationMap, "showKnownIssuesUrl" ) ); + setReleaseNotesUrl( jobOrBrandingSetting( Branding::ReleaseNotesUrl, configurationMap, "showReleaseNotesUrl" ) ); setDonateUrl( jobOrBrandingSetting( Branding::DonateUrl, configurationMap, "showDonateUrl" ) ); ::setLanguageIcon( this, configurationMap ); diff --git a/src/modules/welcome/WelcomePage.cpp b/src/modules/welcome/WelcomePage.cpp index 15b5f5a69..dc955613c 100644 --- a/src/modules/welcome/WelcomePage.cpp +++ b/src/modules/welcome/WelcomePage.cpp @@ -173,7 +173,7 @@ WelcomePage::setupButton( Button role, const QString& url ) { auto size = 2 * QSize( CalamaresUtils::defaultFontHeight(), CalamaresUtils::defaultFontHeight() ); button->setIcon( CalamaresUtils::defaultPixmap( icon, CalamaresUtils::Original, size ) ); - connect( button, &QPushButton::clicked, [ u ]() { QDesktopServices::openUrl( u ); } ); + connect( button, &QPushButton::clicked, [u]() { QDesktopServices::openUrl( u ); } ); } else { diff --git a/src/modules/welcome/WelcomeViewStep.cpp b/src/modules/welcome/WelcomeViewStep.cpp index 486102ccb..e4e56c44c 100644 --- a/src/modules/welcome/WelcomeViewStep.cpp +++ b/src/modules/welcome/WelcomeViewStep.cpp @@ -127,4 +127,3 @@ WelcomeViewStep::checkRequirements() { return m_requirementsChecker->checkRequirements(); } -