From 937f33244144f1d834086fe34b064631f0b2cad1 Mon Sep 17 00:00:00 2001 From: Adriaan de Groot Date: Sat, 20 Apr 2019 11:52:22 -0400 Subject: [PATCH] [license] Refactor LicenseEntry - Follow Calamares conventions for member naming - Switch to struct since everything is public anyway --- src/modules/license/LicensePage.cpp | 49 +++++++++++++++-------------- src/modules/license/LicensePage.h | 22 +++++++------ 2 files changed, 39 insertions(+), 32 deletions(-) diff --git a/src/modules/license/LicensePage.cpp b/src/modules/license/LicensePage.cpp index cf43ba66b..f21c222a2 100644 --- a/src/modules/license/LicensePage.cpp +++ b/src/modules/license/LicensePage.cpp @@ -41,8 +41,8 @@ #include #include -static const NamedEnumTable< LicenseEntry::Type >& -typeNames() +const NamedEnumTable< LicenseEntry::Type >& +LicenseEntry::typeNames() { static const NamedEnumTable< LicenseEntry::Type > names{ { QStringLiteral( "software" ), LicenseEntry::Type::Software}, @@ -61,15 +61,18 @@ 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() ); + m_id = conf[ "id" ].toString(); + m_prettyName = conf[ "name" ].toString(); + m_prettyVendor = conf.value( "vendor" ).toString(); + m_url = QUrl( conf[ "url" ].toString() ); - required = CalamaresUtils::getBool( conf, "required", false ); + m_required = CalamaresUtils::getBool( conf, "required", false ); bool ok = false; - type = typeNames().find( conf.value( "type", "software" ).toString(), ok ); + QString typeString = conf.value( "type", "software" ).toString(); + m_type = typeNames().find( typeString, ok ); + if ( !ok ) + cWarning() << "License entry" << m_id << "has unknown type" << typeString << "(using 'software')"; } LicensePage::LicensePage(QWidget *parent) @@ -134,7 +137,7 @@ LicensePage::setEntries( const QList< LicenseEntry >& entriesList ) bool required = false; for ( const LicenseEntry& entry : entriesList ) { - if ( entry.required ) + if ( entry.m_required ) { required = true; break; @@ -187,45 +190,45 @@ LicensePage::setEntries( const QList< LicenseEntry >& entriesList ) label->setSizePolicy( QSizePolicy::Preferred, QSizePolicy::Minimum ); QString productDescription; - switch ( entry.type ) + switch ( entry.m_type ) { case LicenseEntry::Type::Driver: //: %1 is an untranslatable product name, example: Creative Audigy driver productDescription = tr( "%1 driver
" "by %2" ) - .arg( entry.prettyName ) - .arg( entry.prettyVendor ); + .arg( entry.m_prettyName ) + .arg( entry.m_prettyVendor ); break; case LicenseEntry::Type::GpuDriver: //: %1 is usually a vendor name, example: Nvidia graphics driver productDescription = tr( "%1 graphics driver
" "by %2" ) - .arg( entry.prettyName ) - .arg( entry.prettyVendor ); + .arg( entry.m_prettyName ) + .arg( entry.m_prettyVendor ); break; case LicenseEntry::Type::BrowserPlugin: productDescription = tr( "%1 browser plugin
" "by %2" ) - .arg( entry.prettyName ) - .arg( entry.prettyVendor ); + .arg( entry.m_prettyName ) + .arg( entry.m_prettyVendor ); break; case LicenseEntry::Type::Codec: productDescription = tr( "%1 codec
" "by %2" ) - .arg( entry.prettyName ) - .arg( entry.prettyVendor ); + .arg( entry.m_prettyName ) + .arg( entry.m_prettyVendor ); break; case LicenseEntry::Type::Package: productDescription = tr( "%1 package
" "by %2" ) - .arg( entry.prettyName ) - .arg( entry.prettyVendor ); + .arg( entry.m_prettyName ) + .arg( entry.m_prettyVendor ); break; case LicenseEntry::Type::Software: productDescription = tr( "%1
" "by %2" ) - .arg( entry.prettyName ) - .arg( entry.prettyVendor ); + .arg( entry.m_prettyName ) + .arg( entry.m_prettyVendor ); } label->setText( productDescription ); @@ -235,7 +238,7 @@ LicensePage::setEntries( const QList< LicenseEntry >& entriesList ) viewLicenseLabel->setOpenExternalLinks( true ); viewLicenseLabel->setAlignment( Qt::AlignVCenter | Qt::AlignRight ); viewLicenseLabel->setText( tr( "view license agreement" ) - .arg( entry.url.toString() ) ); + .arg( entry.m_url.toString() ) ); ui->licenseEntriesLayout->addWidget( widget ); } diff --git a/src/modules/license/LicensePage.h b/src/modules/license/LicensePage.h index f0d490a8b..4fbd163eb 100644 --- a/src/modules/license/LicensePage.h +++ b/src/modules/license/LicensePage.h @@ -22,6 +22,8 @@ #ifndef LICENSEPAGE_H #define LICENSEPAGE_H +#include "utils/NamedEnum.h" + #include #include @@ -30,9 +32,8 @@ namespace Ui class LicensePage; } -class LicenseEntry +struct LicenseEntry { -public: enum class Type { Software = 0, @@ -43,17 +44,20 @@ public: Package }; + /// @brief Lookup table for the enums + const NamedEnumTable< Type >& typeNames(); + LicenseEntry( const QVariantMap& conf ); LicenseEntry( const LicenseEntry& ) = default; - bool isValid() const { return !id.isEmpty(); } + bool isValid() const { return !m_id.isEmpty(); } - QString id; - QString prettyName; - QString prettyVendor; - Type type; - QUrl url; - bool required; + QString m_id; + QString m_prettyName; + QString m_prettyVendor; + Type m_type; + QUrl m_url; + bool m_required; }; class LicensePage : public QWidget