[license] Refactor LicenseEntry
- Follow Calamares conventions for member naming - Switch to struct since everything is public anyway
This commit is contained in:
parent
dc006d58b2
commit
937f332441
@ -41,8 +41,8 @@
|
|||||||
#include <QComboBox>
|
#include <QComboBox>
|
||||||
#include <QMessageBox>
|
#include <QMessageBox>
|
||||||
|
|
||||||
static const NamedEnumTable< LicenseEntry::Type >&
|
const NamedEnumTable< LicenseEntry::Type >&
|
||||||
typeNames()
|
LicenseEntry::typeNames()
|
||||||
{
|
{
|
||||||
static const NamedEnumTable< LicenseEntry::Type > names{
|
static const NamedEnumTable< LicenseEntry::Type > names{
|
||||||
{ QStringLiteral( "software" ), LicenseEntry::Type::Software},
|
{ QStringLiteral( "software" ), LicenseEntry::Type::Software},
|
||||||
@ -61,15 +61,18 @@ LicenseEntry::LicenseEntry(const QVariantMap& conf)
|
|||||||
if ( !conf.contains( "id" ) || !conf.contains( "name" ) || !conf.contains( "url" ) )
|
if ( !conf.contains( "id" ) || !conf.contains( "name" ) || !conf.contains( "url" ) )
|
||||||
return;
|
return;
|
||||||
|
|
||||||
id = conf[ "id" ].toString();
|
m_id = conf[ "id" ].toString();
|
||||||
prettyName = conf[ "name" ].toString();
|
m_prettyName = conf[ "name" ].toString();
|
||||||
prettyVendor = conf.value( "vendor" ).toString();
|
m_prettyVendor = conf.value( "vendor" ).toString();
|
||||||
url = QUrl( conf[ "url" ].toString() );
|
m_url = QUrl( conf[ "url" ].toString() );
|
||||||
|
|
||||||
required = CalamaresUtils::getBool( conf, "required", false );
|
m_required = CalamaresUtils::getBool( conf, "required", false );
|
||||||
|
|
||||||
bool ok = 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)
|
LicensePage::LicensePage(QWidget *parent)
|
||||||
@ -134,7 +137,7 @@ LicensePage::setEntries( const QList< LicenseEntry >& entriesList )
|
|||||||
bool required = false;
|
bool required = false;
|
||||||
for ( const LicenseEntry& entry : entriesList )
|
for ( const LicenseEntry& entry : entriesList )
|
||||||
{
|
{
|
||||||
if ( entry.required )
|
if ( entry.m_required )
|
||||||
{
|
{
|
||||||
required = true;
|
required = true;
|
||||||
break;
|
break;
|
||||||
@ -187,45 +190,45 @@ LicensePage::setEntries( const QList< LicenseEntry >& entriesList )
|
|||||||
label->setSizePolicy( QSizePolicy::Preferred, QSizePolicy::Minimum );
|
label->setSizePolicy( QSizePolicy::Preferred, QSizePolicy::Minimum );
|
||||||
|
|
||||||
QString productDescription;
|
QString productDescription;
|
||||||
switch ( entry.type )
|
switch ( entry.m_type )
|
||||||
{
|
{
|
||||||
case LicenseEntry::Type::Driver:
|
case LicenseEntry::Type::Driver:
|
||||||
//: %1 is an untranslatable product name, example: Creative Audigy driver
|
//: %1 is an untranslatable product name, example: Creative Audigy driver
|
||||||
productDescription = tr( "<strong>%1 driver</strong><br/>"
|
productDescription = tr( "<strong>%1 driver</strong><br/>"
|
||||||
"by %2" )
|
"by %2" )
|
||||||
.arg( entry.prettyName )
|
.arg( entry.m_prettyName )
|
||||||
.arg( entry.prettyVendor );
|
.arg( entry.m_prettyVendor );
|
||||||
break;
|
break;
|
||||||
case LicenseEntry::Type::GpuDriver:
|
case LicenseEntry::Type::GpuDriver:
|
||||||
//: %1 is usually a vendor name, example: Nvidia graphics driver
|
//: %1 is usually a vendor name, example: Nvidia graphics driver
|
||||||
productDescription = tr( "<strong>%1 graphics driver</strong><br/>"
|
productDescription = tr( "<strong>%1 graphics driver</strong><br/>"
|
||||||
"<font color=\"Grey\">by %2</font>" )
|
"<font color=\"Grey\">by %2</font>" )
|
||||||
.arg( entry.prettyName )
|
.arg( entry.m_prettyName )
|
||||||
.arg( entry.prettyVendor );
|
.arg( entry.m_prettyVendor );
|
||||||
break;
|
break;
|
||||||
case LicenseEntry::Type::BrowserPlugin:
|
case LicenseEntry::Type::BrowserPlugin:
|
||||||
productDescription = tr( "<strong>%1 browser plugin</strong><br/>"
|
productDescription = tr( "<strong>%1 browser plugin</strong><br/>"
|
||||||
"<font color=\"Grey\">by %2</font>" )
|
"<font color=\"Grey\">by %2</font>" )
|
||||||
.arg( entry.prettyName )
|
.arg( entry.m_prettyName )
|
||||||
.arg( entry.prettyVendor );
|
.arg( entry.m_prettyVendor );
|
||||||
break;
|
break;
|
||||||
case LicenseEntry::Type::Codec:
|
case LicenseEntry::Type::Codec:
|
||||||
productDescription = tr( "<strong>%1 codec</strong><br/>"
|
productDescription = tr( "<strong>%1 codec</strong><br/>"
|
||||||
"<font color=\"Grey\">by %2</font>" )
|
"<font color=\"Grey\">by %2</font>" )
|
||||||
.arg( entry.prettyName )
|
.arg( entry.m_prettyName )
|
||||||
.arg( entry.prettyVendor );
|
.arg( entry.m_prettyVendor );
|
||||||
break;
|
break;
|
||||||
case LicenseEntry::Type::Package:
|
case LicenseEntry::Type::Package:
|
||||||
productDescription = tr( "<strong>%1 package</strong><br/>"
|
productDescription = tr( "<strong>%1 package</strong><br/>"
|
||||||
"<font color=\"Grey\">by %2</font>" )
|
"<font color=\"Grey\">by %2</font>" )
|
||||||
.arg( entry.prettyName )
|
.arg( entry.m_prettyName )
|
||||||
.arg( entry.prettyVendor );
|
.arg( entry.m_prettyVendor );
|
||||||
break;
|
break;
|
||||||
case LicenseEntry::Type::Software:
|
case LicenseEntry::Type::Software:
|
||||||
productDescription = tr( "<strong>%1</strong><br/>"
|
productDescription = tr( "<strong>%1</strong><br/>"
|
||||||
"<font color=\"Grey\">by %2</font>" )
|
"<font color=\"Grey\">by %2</font>" )
|
||||||
.arg( entry.prettyName )
|
.arg( entry.m_prettyName )
|
||||||
.arg( entry.prettyVendor );
|
.arg( entry.m_prettyVendor );
|
||||||
}
|
}
|
||||||
label->setText( productDescription );
|
label->setText( productDescription );
|
||||||
|
|
||||||
@ -235,7 +238,7 @@ LicensePage::setEntries( const QList< LicenseEntry >& entriesList )
|
|||||||
viewLicenseLabel->setOpenExternalLinks( true );
|
viewLicenseLabel->setOpenExternalLinks( true );
|
||||||
viewLicenseLabel->setAlignment( Qt::AlignVCenter | Qt::AlignRight );
|
viewLicenseLabel->setAlignment( Qt::AlignVCenter | Qt::AlignRight );
|
||||||
viewLicenseLabel->setText( tr( "<a href=\"%1\">view license agreement</a>" )
|
viewLicenseLabel->setText( tr( "<a href=\"%1\">view license agreement</a>" )
|
||||||
.arg( entry.url.toString() ) );
|
.arg( entry.m_url.toString() ) );
|
||||||
|
|
||||||
ui->licenseEntriesLayout->addWidget( widget );
|
ui->licenseEntriesLayout->addWidget( widget );
|
||||||
}
|
}
|
||||||
|
@ -22,6 +22,8 @@
|
|||||||
#ifndef LICENSEPAGE_H
|
#ifndef LICENSEPAGE_H
|
||||||
#define LICENSEPAGE_H
|
#define LICENSEPAGE_H
|
||||||
|
|
||||||
|
#include "utils/NamedEnum.h"
|
||||||
|
|
||||||
#include <QWidget>
|
#include <QWidget>
|
||||||
#include <QUrl>
|
#include <QUrl>
|
||||||
|
|
||||||
@ -30,9 +32,8 @@ namespace Ui
|
|||||||
class LicensePage;
|
class LicensePage;
|
||||||
}
|
}
|
||||||
|
|
||||||
class LicenseEntry
|
struct LicenseEntry
|
||||||
{
|
{
|
||||||
public:
|
|
||||||
enum class Type
|
enum class Type
|
||||||
{
|
{
|
||||||
Software = 0,
|
Software = 0,
|
||||||
@ -43,17 +44,20 @@ public:
|
|||||||
Package
|
Package
|
||||||
};
|
};
|
||||||
|
|
||||||
|
/// @brief Lookup table for the enums
|
||||||
|
const NamedEnumTable< Type >& typeNames();
|
||||||
|
|
||||||
LicenseEntry( const QVariantMap& conf );
|
LicenseEntry( const QVariantMap& conf );
|
||||||
LicenseEntry( const LicenseEntry& ) = default;
|
LicenseEntry( const LicenseEntry& ) = default;
|
||||||
|
|
||||||
bool isValid() const { return !id.isEmpty(); }
|
bool isValid() const { return !m_id.isEmpty(); }
|
||||||
|
|
||||||
QString id;
|
QString m_id;
|
||||||
QString prettyName;
|
QString m_prettyName;
|
||||||
QString prettyVendor;
|
QString m_prettyVendor;
|
||||||
Type type;
|
Type m_type;
|
||||||
QUrl url;
|
QUrl m_url;
|
||||||
bool required;
|
bool m_required;
|
||||||
};
|
};
|
||||||
|
|
||||||
class LicensePage : public QWidget
|
class LicensePage : public QWidget
|
||||||
|
Loading…
Reference in New Issue
Block a user