diff --git a/src/modules/license/LicensePage.cpp b/src/modules/license/LicensePage.cpp index 1c1129513..29ed4d555 100644 --- a/src/modules/license/LicensePage.cpp +++ b/src/modules/license/LicensePage.cpp @@ -106,24 +106,9 @@ LicensePage::LicensePage(QWidget *parent) "padding: 2px; }" ); ui->acceptFrame->layout()->setMargin( CalamaresUtils::defaultFontHeight() / 2 ); - connect( ui->acceptCheckBox, &QCheckBox::toggled, - this, [ this ]( bool checked ) - { - 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 ); - } ); + updateGlobalStorage( false ); // Have not agreed yet + + connect( ui->acceptCheckBox, &QCheckBox::toggled, this, &LicensePage::checkAcceptance ); CALAMARES_RETRANSLATE( 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 ); 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; - nextStatusChanged( m_isNextEnabled ); + checkAcceptance( false ); CALAMARES_RETRANSLATE( if ( required ) @@ -245,3 +233,28 @@ LicensePage::isNextEnabled() const { 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 ); +} diff --git a/src/modules/license/LicensePage.h b/src/modules/license/LicensePage.h index b2e343602..1af83269a 100644 --- a/src/modules/license/LicensePage.h +++ b/src/modules/license/LicensePage.h @@ -70,13 +70,31 @@ public: void setEntries( const QList< LicenseEntry >& entriesList ); 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: void nextStatusChanged( bool status ); private: - Ui::LicensePage* ui; + /** @brief Update the global storage "licenseAgree" key. */ + void updateGlobalStorage( bool v ); bool m_isNextEnabled; + bool m_allLicensesOptional; //< all the licenses passed to setEntries are not-required + + Ui::LicensePage* ui; + }; #endif //LICENSEPAGE_H