[license] Handle the case where all the licenses are optional

- If all of the licenses are optional, you should be able to
   continue without accepting. Refactor to a single visible
   slot to check the conditions.
 - Always set the globalsettings value; to "false" on entry
   to make sure it's there.
 - When setting the list of entries, check the conditions
   (because if the list is empty, or all of them are optional,
   then it's ok to continue).

FIXES #1124
FIXES #1125
This commit is contained in:
Adriaan de Groot 2019-04-20 15:21:15 -04:00
parent c245238b89
commit d2957fbad3
2 changed files with 52 additions and 21 deletions

View File

@ -106,24 +106,9 @@ LicensePage::LicensePage(QWidget *parent)
"padding: 2px; }" ); "padding: 2px; }" );
ui->acceptFrame->layout()->setMargin( CalamaresUtils::defaultFontHeight() / 2 ); ui->acceptFrame->layout()->setMargin( CalamaresUtils::defaultFontHeight() / 2 );
connect( ui->acceptCheckBox, &QCheckBox::toggled, updateGlobalStorage( false ); // Have not agreed yet
this, [ this ]( bool checked )
{ connect( ui->acceptCheckBox, &QCheckBox::toggled, this, &LicensePage::checkAcceptance );
Calamares::JobQueue::instance()->globalStorage()->insert( "licenseAgree", checked );
m_isNextEnabled = checked;
if ( !checked )
{
ui->acceptFrame->setStyleSheet( "#acceptFrame { border: 1px solid red;"
"background-color: #fff8f8;"
"border-radius: 4px;"
"padding: 2px; }" );
}
else
{
ui->acceptFrame->setStyleSheet( "#acceptFrame { padding: 3px }" );
}
emit nextStatusChanged( checked );
} );
CALAMARES_RETRANSLATE( CALAMARES_RETRANSLATE(
ui->acceptCheckBox->setText( tr( "I accept the terms and conditions above." ) ); ui->acceptCheckBox->setText( tr( "I accept the terms and conditions above." ) );
@ -137,9 +122,12 @@ LicensePage::setEntries( const QList< LicenseEntry >& entriesList )
CalamaresUtils::clearLayout( ui->licenseEntriesLayout ); CalamaresUtils::clearLayout( ui->licenseEntriesLayout );
const bool required = std::any_of( entriesList.cbegin(), entriesList.cend(), []( const LicenseEntry& e ){ return e.m_required; }); 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;
m_isNextEnabled = !required; checkAcceptance( false );
nextStatusChanged( m_isNextEnabled );
CALAMARES_RETRANSLATE( CALAMARES_RETRANSLATE(
if ( required ) if ( required )
@ -245,3 +233,28 @@ LicensePage::isNextEnabled() const
{ {
return m_isNextEnabled; return m_isNextEnabled;
} }
void
LicensePage::updateGlobalStorage( bool v )
{
Calamares::JobQueue::instance()->globalStorage()->insert( "licenseAgree", v );
}
void LicensePage::checkAcceptance( bool checked )
{
updateGlobalStorage( checked );
m_isNextEnabled = checked || m_allLicensesOptional;
if ( !m_isNextEnabled )
{
ui->acceptFrame->setStyleSheet( "#acceptFrame { border: 1px solid red;"
"background-color: #fff8f8;"
"border-radius: 4px;"
"padding: 2px; }" );
}
else
{
ui->acceptFrame->setStyleSheet( "#acceptFrame { padding: 3px }" );
}
emit nextStatusChanged( checked );
}

View File

@ -70,13 +70,31 @@ public:
void setEntries( const QList< LicenseEntry >& entriesList ); void setEntries( const QList< LicenseEntry >& entriesList );
bool isNextEnabled() const; bool isNextEnabled() const;
public slots:
/** @brief Check if the user can continue
*
* The user can continue if
* - none of the licenses are required, or
* - 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.
*/
void checkAcceptance( bool checked );
signals: signals:
void nextStatusChanged( bool status ); void nextStatusChanged( bool status );
private: private:
Ui::LicensePage* ui; /** @brief Update the global storage "licenseAgree" key. */
void updateGlobalStorage( bool v );
bool m_isNextEnabled; bool m_isNextEnabled;
bool m_allLicensesOptional; //< all the licenses passed to setEntries are not-required
Ui::LicensePage* ui;
}; };
#endif //LICENSEPAGE_H #endif //LICENSEPAGE_H