From dc006d58b222ed725494b0ad5a7a875fd8d2a002 Mon Sep 17 00:00:00 2001 From: Adriaan de Groot Date: Sat, 20 Apr 2019 11:43:19 -0400 Subject: [PATCH] [license] Use NamedEnum --- src/modules/license/LicensePage.cpp | 37 +++++++++++++++++------------ 1 file changed, 22 insertions(+), 15 deletions(-) diff --git a/src/modules/license/LicensePage.cpp b/src/modules/license/LicensePage.cpp index acbbd8737..cf43ba66b 100644 --- a/src/modules/license/LicensePage.cpp +++ b/src/modules/license/LicensePage.cpp @@ -22,13 +22,16 @@ #include "LicensePage.h" #include "ui_LicensePage.h" + #include "JobQueue.h" #include "GlobalStorage.h" -#include "utils/Logger.h" +#include "ViewManager.h" + #include "utils/CalamaresUtils.h" #include "utils/CalamaresUtilsGui.h" +#include "utils/Logger.h" +#include "utils/NamedEnum.h" #include "utils/Retranslator.h" -#include "ViewManager.h" #include #include @@ -38,6 +41,21 @@ #include #include +static const NamedEnumTable< LicenseEntry::Type >& +typeNames() +{ + static const NamedEnumTable< LicenseEntry::Type > names{ + { QStringLiteral( "software" ), LicenseEntry::Type::Software}, + { QStringLiteral( "driver" ), LicenseEntry::Type::Driver }, + { QStringLiteral( "gpudriver" ), LicenseEntry::Type::GpuDriver }, + { QStringLiteral( "browserplugin" ), LicenseEntry::Type::BrowserPlugin}, + { QStringLiteral( "codec" ), LicenseEntry::Type::Codec }, + { QStringLiteral( "package" ), LicenseEntry::Type::Package } + }; + + return names; +} + LicenseEntry::LicenseEntry(const QVariantMap& conf) { if ( !conf.contains( "id" ) || !conf.contains( "name" ) || !conf.contains( "url" ) ) @@ -50,19 +68,8 @@ LicenseEntry::LicenseEntry(const QVariantMap& conf) 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; + bool ok = false; + type = typeNames().find( conf.value( "type", "software" ).toString(), ok ); } LicensePage::LicensePage(QWidget *parent)