From 614bd3c6de8dc25c6e890c000a4e2648799b371c Mon Sep 17 00:00:00 2001 From: Adriaan de Groot Date: Fri, 22 Mar 2019 19:31:39 +0100 Subject: [PATCH] [license] Move logic to LicenseEntry class --- src/modules/license/LicensePage.cpp | 28 ++++++++++++++++++++++ src/modules/license/LicensePage.h | 5 ++++ src/modules/license/LicenseViewStep.cpp | 31 +++---------------------- 3 files changed, 36 insertions(+), 28 deletions(-) diff --git a/src/modules/license/LicensePage.cpp b/src/modules/license/LicensePage.cpp index 8fe0a581f..acbbd8737 100644 --- a/src/modules/license/LicensePage.cpp +++ b/src/modules/license/LicensePage.cpp @@ -25,6 +25,7 @@ #include "JobQueue.h" #include "GlobalStorage.h" #include "utils/Logger.h" +#include "utils/CalamaresUtils.h" #include "utils/CalamaresUtilsGui.h" #include "utils/Retranslator.h" #include "ViewManager.h" @@ -37,6 +38,33 @@ #include #include +LicenseEntry::LicenseEntry(const QVariantMap& conf) +{ + if ( !conf.contains( "id" ) || !conf.contains( "name" ) || !conf.contains( "url" ) ) + return; + + id = conf[ "id" ].toString(); + prettyName = conf[ "name" ].toString(); + prettyVendor = conf.value( "vendor" ).toString(); + url = QUrl( conf[ "url" ].toString() ); + + required = CalamaresUtils::getBool( conf, "required", false ); + + QString entryType = conf.value( "type", "software" ).toString(); + if ( entryType == "driver" ) + type = LicenseEntry::Type::Driver; + else if ( entryType == "gpudriver" ) + type = LicenseEntry::Type::GpuDriver; + else if ( entryType == "browserplugin" ) + type = LicenseEntry::Type::BrowserPlugin; + else if ( entryType == "codec" ) + type = LicenseEntry::Type::Codec; + else if ( entryType == "package" ) + type = LicenseEntry::Type::Package; + else + type = LicenseEntry::Type::Software; +} + LicensePage::LicensePage(QWidget *parent) : QWidget( parent ) , ui( new Ui::LicensePage ) diff --git a/src/modules/license/LicensePage.h b/src/modules/license/LicensePage.h index 03801467c..f0d490a8b 100644 --- a/src/modules/license/LicensePage.h +++ b/src/modules/license/LicensePage.h @@ -43,6 +43,11 @@ public: Package }; + LicenseEntry( const QVariantMap& conf ); + LicenseEntry( const LicenseEntry& ) = default; + + bool isValid() const { return !id.isEmpty(); } + QString id; QString prettyName; QString prettyVendor; diff --git a/src/modules/license/LicenseViewStep.cpp b/src/modules/license/LicenseViewStep.cpp index d7a4c4930..f5f4b6e2b 100644 --- a/src/modules/license/LicenseViewStep.cpp +++ b/src/modules/license/LicenseViewStep.cpp @@ -106,34 +106,9 @@ LicenseViewStep::setConfigurationMap( const QVariantMap& configurationMap ) if ( entryV.type() != QVariant::Map ) continue; - QVariantMap entryMap = entryV.toMap(); - if ( !entryMap.contains( "id" ) || - !entryMap.contains( "name" ) || - !entryMap.contains( "url" ) ) - continue; - - LicenseEntry entry; - entry.id = entryMap[ "id" ].toString(); - entry.prettyName = entryMap[ "name" ].toString(); - entry.prettyVendor =entryMap.value( "vendor" ).toString(); - entry.url = QUrl( entryMap[ "url" ].toString() ); - entry.required = entryMap.value( "required", QVariant( false ) ).toBool(); - - QString entryType = entryMap.value( "type", "software" ).toString(); - if ( entryType == "driver" ) - entry.type = LicenseEntry::Type::Driver; - else if ( entryType == "gpudriver" ) - entry.type = LicenseEntry::Type::GpuDriver; - else if ( entryType == "browserplugin" ) - entry.type = LicenseEntry::Type::BrowserPlugin; - else if ( entryType == "codec" ) - entry.type = LicenseEntry::Type::Codec; - else if ( entryType == "package" ) - entry.type = LicenseEntry::Type::Package; - else - entry.type = LicenseEntry::Type::Software; - - entriesList.append( entry ); + LicenseEntry entry( entryV.toMap() ); + if ( entry.isValid() ) + entriesList.append( entry ); } }