[license] Move translation / retranslation to LicenseWidget

- Language change didn't otherwise apply to the license items
This commit is contained in:
Adriaan de Groot 2019-04-21 13:50:06 +02:00
parent 1235207ead
commit cb80d47682
4 changed files with 75 additions and 55 deletions

View File

@ -121,6 +121,8 @@ void
LicensePage::setEntries( const QList< LicenseEntry >& entriesList )
{
CalamaresUtils::clearLayout( ui->licenseEntriesLayout );
m_entries.clear();
m_entries.reserve( entriesList.count() );
const bool required = std::any_of( entriesList.cbegin(), entriesList.cend(), []( const LicenseEntry& e ){ return e.m_required; });
if ( entriesList.isEmpty() )
@ -153,11 +155,16 @@ LicensePage::setEntries( const QList< LicenseEntry >& entriesList )
"be installed, and open source alternatives will be used instead." ) );
}
ui->retranslateUi( this );
for ( const auto& w : m_entries )
w->retranslateUi();
)
for ( const LicenseEntry& entry : entriesList )
{
ui->licenseEntriesLayout->addWidget( new LicenseWidget( entry ) );
LicenseWidget* w = new LicenseWidget( entry );
ui->licenseEntriesLayout->addWidget( w );
m_entries.append( w );
}
ui->licenseEntriesLayout->addStretch();
}

View File

@ -32,6 +32,8 @@ namespace Ui
class LicensePage;
}
class LicenseWidget;
struct LicenseEntry
{
enum class Type
@ -94,7 +96,7 @@ private:
bool m_allLicensesOptional; //< all the licenses passed to setEntries are not-required
Ui::LicensePage* ui;
QList< LicenseWidget* > m_entries;
};
#endif //LICENSEPAGE_H

View File

@ -28,6 +28,8 @@
LicenseWidget::LicenseWidget( LicenseEntry entry, QWidget* parent )
: QWidget( parent )
, m_entry( std::move( entry ) )
, m_label( new QLabel( this ) )
, m_viewLicenseLabel( new QLabel( this ) )
{
QPalette pal( palette() );
pal.setColor( QPalette::Background, palette().background().color().lighter( 108 ) );
@ -39,63 +41,68 @@ LicenseWidget::LicenseWidget( LicenseEntry entry, QWidget* parent )
QHBoxLayout* wiLayout = new QHBoxLayout;
setLayout( wiLayout );
QLabel* label = new QLabel( this );
label->setWordWrap( true );
wiLayout->addWidget( label );
label->setSizePolicy( QSizePolicy::Preferred, QSizePolicy::Minimum );
QString productDescription;
switch ( entry.m_type )
{
case LicenseEntry::Type::Driver:
//: %1 is an untranslatable product name, example: Creative Audigy driver
productDescription = tr( "<strong>%1 driver</strong><br/>"
"by %2" )
.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( "<strong>%1 graphics driver</strong><br/>"
"<font color=\"Grey\">by %2</font>" )
.arg( entry.m_prettyName )
.arg( entry.m_prettyVendor );
break;
case LicenseEntry::Type::BrowserPlugin:
productDescription = tr( "<strong>%1 browser plugin</strong><br/>"
"<font color=\"Grey\">by %2</font>" )
.arg( entry.m_prettyName )
.arg( entry.m_prettyVendor );
break;
case LicenseEntry::Type::Codec:
productDescription = tr( "<strong>%1 codec</strong><br/>"
"<font color=\"Grey\">by %2</font>" )
.arg( entry.m_prettyName )
.arg( entry.m_prettyVendor );
break;
case LicenseEntry::Type::Package:
productDescription = tr( "<strong>%1 package</strong><br/>"
"<font color=\"Grey\">by %2</font>" )
.arg( entry.m_prettyName )
.arg( entry.m_prettyVendor );
break;
case LicenseEntry::Type::Software:
productDescription = tr( "<strong>%1</strong><br/>"
"<font color=\"Grey\">by %2</font>" )
.arg( entry.m_prettyName )
.arg( entry.m_prettyVendor );
}
label->setText( productDescription );
m_label->setWordWrap( true );
m_label->setSizePolicy( QSizePolicy::Preferred, QSizePolicy::Minimum );
wiLayout->addWidget( m_label );
QLabel* viewLicenseLabel = new QLabel( this );
wiLayout->addWidget( viewLicenseLabel );
viewLicenseLabel->setSizePolicy( QSizePolicy::Preferred, QSizePolicy::Preferred );
viewLicenseLabel->setOpenExternalLinks( true );
viewLicenseLabel->setAlignment( Qt::AlignVCenter | Qt::AlignRight );
viewLicenseLabel->setText( tr( "<a href=\"%1\">view license agreement</a>" )
.arg( entry.m_url.toString() ) );
m_viewLicenseLabel->setSizePolicy( QSizePolicy::Preferred, QSizePolicy::Preferred );
m_viewLicenseLabel->setOpenExternalLinks( true );
m_viewLicenseLabel->setAlignment( Qt::AlignVCenter | Qt::AlignRight );
wiLayout->addWidget( m_viewLicenseLabel );
retranslateUi();
}
LicenseWidget::~LicenseWidget()
{
}
void LicenseWidget::retranslateUi()
{
QString productDescription;
switch ( m_entry.m_type )
{
case LicenseEntry::Type::Driver:
//: %1 is an untranslatable product name, example: Creative Audigy driver
productDescription = tr( "<strong>%1 driver</strong><br/>"
"by %2" )
.arg( m_entry.m_prettyName )
.arg( m_entry.m_prettyVendor );
break;
case LicenseEntry::Type::GpuDriver:
//: %1 is usually a vendor name, example: Nvidia graphics driver
productDescription = tr( "<strong>%1 graphics driver</strong><br/>"
"<font color=\"Grey\">by %2</font>" )
.arg( m_entry.m_prettyName )
.arg( m_entry.m_prettyVendor );
break;
case LicenseEntry::Type::BrowserPlugin:
productDescription = tr( "<strong>%1 browser plugin</strong><br/>"
"<font color=\"Grey\">by %2</font>" )
.arg( m_entry.m_prettyName )
.arg( m_entry.m_prettyVendor );
break;
case LicenseEntry::Type::Codec:
productDescription = tr( "<strong>%1 codec</strong><br/>"
"<font color=\"Grey\">by %2</font>" )
.arg( m_entry.m_prettyName )
.arg( m_entry.m_prettyVendor );
break;
case LicenseEntry::Type::Package:
productDescription = tr( "<strong>%1 package</strong><br/>"
"<font color=\"Grey\">by %2</font>" )
.arg( m_entry.m_prettyName )
.arg( m_entry.m_prettyVendor );
break;
case LicenseEntry::Type::Software:
productDescription = tr( "<strong>%1</strong><br/>"
"<font color=\"Grey\">by %2</font>" )
.arg( m_entry.m_prettyName )
.arg( m_entry.m_prettyVendor );
}
m_label->setText( productDescription );
m_viewLicenseLabel->setText( tr( "<a href=\"%1\">view license agreement</a>" )
.arg( m_entry.m_url.toString() ) );
}

View File

@ -33,7 +33,11 @@ public:
LicenseWidget( LicenseEntry e, QWidget* parent = nullptr );
virtual ~LicenseWidget() override;
void retranslateUi();
private:
LicenseEntry m_entry;
QLabel *m_label;
QLabel *m_viewLicenseLabel;
} ;
#endif