[license] Tidy code

- Move retranslation to a separate slot to allow it to be
   formatted nicely.
 - Use calculated m_allLicensesOptional in retranslation.
 - Untangle determining if all licenses are optional; std::none_of
   returns true on an empty list.
This commit is contained in:
Adriaan de Groot 2019-11-26 22:37:25 +01:00
parent fae1fdae1c
commit ec605adf3f
2 changed files with 31 additions and 25 deletions

View File

@ -126,7 +126,6 @@ LicensePage::LicensePage( QWidget* parent )
CALAMARES_RETRANSLATE( ui->acceptCheckBox->setText( tr( "I accept the terms and conditions above." ) ); )
}
void
LicensePage::setEntries( const QList< LicenseEntry >& entriesList )
{
@ -134,27 +133,36 @@ LicensePage::setEntries( const QList< LicenseEntry >& entriesList )
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() )
{
m_allLicensesOptional = true;
}
else
{
m_allLicensesOptional = !required;
}
auto isRequired = []( const LicenseEntry& e ) { return e.m_required; };
m_allLicensesOptional = std::none_of( entriesList.cbegin(), entriesList.cend(), isRequired );
checkAcceptance( false );
CALAMARES_RETRANSLATE( if ( required ) {
for ( const LicenseEntry& entry : entriesList )
{
LicenseWidget* w = new LicenseWidget( entry );
ui->licenseEntriesLayout->addWidget( w );
m_entries.append( w );
}
ui->licenseEntriesLayout->addStretch();
CALAMARES_RETRANSLATE_SLOT( &LicensePage::retranslate )
}
void
LicensePage::retranslate()
{
if ( !m_allLicensesOptional )
{
ui->mainText->setText( tr( "<h1>License Agreement</h1>"
"This setup procedure will install proprietary "
"software that is subject to licensing terms." ) );
ui->additionalText->setText( tr( "Please review the End User License "
"Agreements (EULAs) above.<br/>"
"If you do not agree with the terms, the setup procedure cannot continue." ) );
} else {
}
else
{
ui->mainText->setText( tr( "<h1>License Agreement</h1>"
"This setup procedure can install proprietary "
"software that is subject to licensing terms "
@ -164,18 +172,13 @@ LicensePage::setEntries( const QList< LicenseEntry >& entriesList )
"Agreements (EULAs) above.<br/>"
"If you do not agree with the terms, proprietary software will not "
"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 )
{
LicenseWidget* w = new LicenseWidget( entry );
ui->licenseEntriesLayout->addWidget( w );
m_entries.append( w );
}
ui->licenseEntriesLayout->addStretch();
ui->retranslateUi( this );
for ( const auto& w : m_entries )
{
w->retranslateUi();
}
}

View File

@ -83,10 +83,13 @@ public slots:
* - the user has ticked the "OK" box.
* This function calls updateGlobalStorage() as needed, and updates
* the appearance of the page as needed. @p checked indicates whether
* the checkbox has been ticked or not.
* the checkbox has been ticked or not. (e.g. when @p checked is true,
* you can continue regardless)
*/
void checkAcceptance( bool checked );
void retranslate();
signals:
void nextStatusChanged( bool status );