From ca7733c8e43f71c8f85216012d250ae0a2ce21c2 Mon Sep 17 00:00:00 2001 From: Adriaan de Groot Date: Thu, 2 Apr 2020 21:52:05 +0200 Subject: [PATCH] [welcome] Drop RequirementsModel - Use the one from libcalamares - Massage warning message into Config after it was removed from the model --- src/modules/welcome/Config.cpp | 154 ++++++------------ src/modules/welcome/Config.h | 80 ++------- .../welcome/checker/CheckerContainer.cpp | 2 +- .../welcome/checker/CheckerContainer.h | 4 +- .../welcome/checker/ResultsListWidget.cpp | 10 +- .../welcome/checker/ResultsListWidget.h | 4 +- 6 files changed, 69 insertions(+), 185 deletions(-) diff --git a/src/modules/welcome/Config.cpp b/src/modules/welcome/Config.cpp index 43987f4b2..7258382c4 100644 --- a/src/modules/welcome/Config.cpp +++ b/src/modules/welcome/Config.cpp @@ -23,71 +23,12 @@ #include "utils/Logger.h" #include "utils/Retranslator.h" -void -RequirementsModel::setRequirementsList( const Calamares::RequirementsList& requirements ) -{ - CALAMARES_RETRANSLATE_SLOT( &RequirementsModel::retranslate ) - - emit beginResetModel(); - m_requirements = requirements; - - auto isUnSatisfied = []( const Calamares::RequirementEntry& e ) { return !e.satisfied; }; - auto isMandatoryAndUnSatisfied = []( const Calamares::RequirementEntry& e ) { return e.mandatory && !e.satisfied; }; - - m_satisfiedRequirements = std::none_of( m_requirements.begin(), m_requirements.end(), isUnSatisfied ); - m_satisfiedMandatory = std::none_of( m_requirements.begin(), m_requirements.end(), isMandatoryAndUnSatisfied ); - - emit satisfiedRequirementsChanged( m_satisfiedRequirements ); - emit satisfiedMandatoryChanged(); - emit endResetModel(); -} - -int -RequirementsModel::rowCount( const QModelIndex& ) const -{ - return m_requirements.count(); -} - -QVariant -RequirementsModel::data( const QModelIndex& index, int role ) const -{ - const auto requirement = m_requirements.at( index.row() ); - - switch ( role ) - { - case Roles::Name: - return requirement.name; - case Roles::Details: - return requirement.enumerationText(); - case Roles::NegatedText: - return requirement.negatedText(); - case Roles::Satisfied: - return requirement.satisfied; - case Roles::Mandatory: - return requirement.mandatory; - default: - return QVariant(); - } -} - -QHash< int, QByteArray > -RequirementsModel::roleNames() const -{ - static QHash< int, QByteArray > roles; - roles[ Roles::Name ] = "name"; - roles[ Roles::Details ] = "details"; - roles[ Roles::NegatedText ] = "negatedText"; - roles[ Roles::Satisfied ] = "satisfied"; - roles[ Roles::Mandatory ] = "mandatory"; - return roles; -} - Config::Config( QObject* parent ) : QObject( parent ) - , m_requirementsModel( new RequirementsModel( this ) ) + , m_requirementsModel( new Calamares::RequirementsModel( this ) ) , m_languages( CalamaresUtils::Locale::availableTranslations() ) { - connect( m_requirementsModel, &RequirementsModel::satisfiedRequirementsChanged, this, &Config::setIsNextEnabled ); + connect( m_requirementsModel, &Calamares::RequirementsModel::satisfiedRequirementsChanged, this, &Config::setIsNextEnabled ); initLanguages(); @@ -100,7 +41,44 @@ Config::retranslate() m_genericWelcomeMessage = genericWelcomeMessage().arg( *Calamares::Branding::VersionedName ); emit genericWelcomeMessageChanged(); - m_requirementsModel->retranslate(); + if ( !m_requirementsModel->satisfiedRequirements() ) + { + QString message; + const bool setup = Calamares::Settings::instance()->isSetupMode(); + + if ( !m_requirementsModel->satisfiedMandatory() ) + { + message = setup ? tr( "This computer does not satisfy the minimum " + "requirements for setting up %1.
" + "Setup cannot continue. " + "Details..." ) + : tr( "This computer does not satisfy the minimum " + "requirements for installing %1.
" + "Installation cannot continue. " + "Details..." ); + } + else + { + message = setup ? tr( "This computer does not satisfy some of the " + "recommended requirements for setting up %1.
" + "Setup can continue, but some features " + "might be disabled." ) + : tr( "This computer does not satisfy some of the " + "recommended requirements for installing %1.
" + "Installation can continue, but some features " + "might be disabled." ); + } + + m_warningMessage = message.arg( *Calamares::Branding::ShortVersionedName ); + } + else + { + m_warningMessage = tr( "This program will ask you some questions and " + "set up %2 on your computer." ) + .arg( *Calamares::Branding::ProductName ); + } + + emit warningMessageChanged(); } CalamaresUtils::Locale::LabelModel* @@ -197,7 +175,7 @@ Config::setLocaleIndex( const int& index ) emit localeIndexChanged( m_localeIndex ); } -RequirementsModel& +Calamares::RequirementsModel& Config::requirementsModel() const { return *m_requirementsModel; @@ -262,51 +240,8 @@ Config::setSupportUrl( const QString& url ) emit supportUrlChanged(); } -void -RequirementsModel::retranslate() -{ - if ( !m_satisfiedRequirements ) - { - QString message; - const bool setup = Calamares::Settings::instance()->isSetupMode(); - - if ( !m_satisfiedMandatory ) - { - message = setup ? tr( "This computer does not satisfy the minimum " - "requirements for setting up %1.
" - "Setup cannot continue. " - "Details..." ) - : tr( "This computer does not satisfy the minimum " - "requirements for installing %1.
" - "Installation cannot continue. " - "Details..." ); - } - else - { - message = setup ? tr( "This computer does not satisfy some of the " - "recommended requirements for setting up %1.
" - "Setup can continue, but some features " - "might be disabled." ) - : tr( "This computer does not satisfy some of the " - "recommended requirements for installing %1.
" - "Installation can continue, but some features " - "might be disabled." ); - } - - m_warningMessage = message.arg( *Calamares::Branding::ShortVersionedName ); - } - else - { - m_warningMessage = tr( "This program will ask you some questions and " - "set up %2 on your computer." ) - .arg( *Calamares::Branding::ProductName ); - } - - emit warningMessageChanged(); -} - QString -Config::genericWelcomeMessage() +Config::genericWelcomeMessage() const { QString message; @@ -325,3 +260,8 @@ Config::genericWelcomeMessage() return message; } + +QString Config::warningMessage() const +{ + return m_warningMessage; +} diff --git a/src/modules/welcome/Config.h b/src/modules/welcome/Config.h index 389a45eec..e8cb35e52 100644 --- a/src/modules/welcome/Config.h +++ b/src/modules/welcome/Config.h @@ -19,79 +19,18 @@ #ifndef WELCOME_CONFIG_H #define WELCOME_CONFIG_H -#include "modulesystem/Requirement.h" #include "locale/LabelModel.h" +#include "modulesystem/Requirement.h" +#include "modulesystem/RequirementsModel.h" #include #include -// TODO: move this (and modulesystem/Requirement) to libcalamares -class RequirementsModel : public QAbstractListModel -{ - Q_OBJECT - Q_PROPERTY( bool satisfiedRequirements READ satisfiedRequirements NOTIFY satisfiedRequirementsChanged FINAL ) - Q_PROPERTY( bool satisfiedMandatory READ satisfiedMandatory NOTIFY satisfiedMandatoryChanged FINAL ) - Q_PROPERTY( QString warningMessage READ warningMessage NOTIFY warningMessageChanged FINAL ) - -public: - using QAbstractListModel::QAbstractListModel; - - enum Roles : short - { - Name, - Satisfied, - Mandatory, - Details, - NegatedText, - HasDetails - }; - - bool satisfiedRequirements() const { return m_satisfiedRequirements; } - - bool satisfiedMandatory() const { return m_satisfiedMandatory; } - - const Calamares::RequirementEntry& getEntry( const int& index ) const - { - if ( index > count() || index < 0 ) - { - return *( new Calamares::RequirementEntry() ); - } - - return m_requirements.at( index ); - } - - void setRequirementsList( const Calamares::RequirementsList& requirements ); - int rowCount( const QModelIndex& ) const override; - int count() const { return m_requirements.count(); } - - QString warningMessage() const { return m_warningMessage; } - - void retranslate(); - - QVariant data( const QModelIndex& index, int role ) const override; - -protected: - QHash< int, QByteArray > roleNames() const override; - -private: - Calamares::RequirementsList m_requirements; - bool m_satisfiedRequirements = false; - bool m_satisfiedMandatory = false; - - QString m_warningMessage; - -signals: - void satisfiedRequirementsChanged( bool value ); - void satisfiedMandatoryChanged(); - void warningMessageChanged(); -}; - - class Config : public QObject { Q_OBJECT Q_PROPERTY( CalamaresUtils::Locale::LabelModel* languagesModel READ languagesModel CONSTANT FINAL ) - Q_PROPERTY( RequirementsModel* requirementsModel MEMBER m_requirementsModel CONSTANT FINAL ) + Q_PROPERTY( Calamares::RequirementsModel* requirementsModel MEMBER m_requirementsModel CONSTANT FINAL ) Q_PROPERTY( QString languageIcon READ languageIcon CONSTANT FINAL ) @@ -99,6 +38,7 @@ class Config : public QObject Q_PROPERTY( int localeIndex READ localeIndex WRITE setLocaleIndex NOTIFY localeIndexChanged ) Q_PROPERTY( QString genericWelcomeMessage MEMBER m_genericWelcomeMessage NOTIFY genericWelcomeMessageChanged FINAL ) + Q_PROPERTY( QString warningMessage READ warningMessage NOTIFY warningMessageChanged FINAL ) Q_PROPERTY( QString supportUrl MEMBER m_supportUrl NOTIFY supportUrlChanged FINAL ) Q_PROPERTY( QString knownIssuesUrl MEMBER m_knownIssuesUrl NOTIFY knownIssuesUrlChanged FINAL ) @@ -111,7 +51,7 @@ public: Config( QObject* parent = nullptr ); void setCountryCode( const QString& countryCode ); void setLanguageIcon( const QString& languageIcon ); - RequirementsModel& requirementsModel() const; + Calamares::RequirementsModel& requirementsModel() const; void setIsNextEnabled( const bool& isNextEnabled ); @@ -130,8 +70,8 @@ public: QString donateUrl() const; void setDonateUrl( const QString& url ); - QString genericWelcomeMessage(); - + QString genericWelcomeMessage() const; + QString warningMessage() const; public slots: CalamaresUtils::Locale::LabelModel* languagesModel() const; @@ -141,7 +81,7 @@ public slots: private: void initLanguages(); QVariantMap m_configurationMap; - RequirementsModel* m_requirementsModel; + Calamares::RequirementsModel* m_requirementsModel; QString m_languageIcon; QString m_countryCode; int m_localeIndex = 0; @@ -149,6 +89,7 @@ private: CalamaresUtils::Locale::LabelModel* m_languages; QString m_genericWelcomeMessage; + QString m_warningMessage; QString m_supportUrl; QString m_knownIssuesUrl; @@ -159,7 +100,10 @@ signals: void countryCodeChanged( QString countryCode ); void localeIndexChanged( int localeIndex ); void isNextEnabledChanged( bool isNextEnabled ); + void genericWelcomeMessageChanged(); + void warningMessageChanged(); + void supportUrlChanged(); void knownIssuesUrlChanged(); void releaseNotesUrlChanged(); diff --git a/src/modules/welcome/checker/CheckerContainer.cpp b/src/modules/welcome/checker/CheckerContainer.cpp index 0e790fbb4..10da425ab 100644 --- a/src/modules/welcome/checker/CheckerContainer.cpp +++ b/src/modules/welcome/checker/CheckerContainer.cpp @@ -31,7 +31,7 @@ #include -CheckerContainer::CheckerContainer( const RequirementsModel &model, QWidget* parent ) +CheckerContainer::CheckerContainer( const Calamares::RequirementsModel &model, QWidget* parent ) : QWidget( parent ) , m_waitingWidget( new WaitingWidget( QString(), this ) ) , m_checkerWidget( nullptr ) diff --git a/src/modules/welcome/checker/CheckerContainer.h b/src/modules/welcome/checker/CheckerContainer.h index f38f198ea..5ebefa36e 100644 --- a/src/modules/welcome/checker/CheckerContainer.h +++ b/src/modules/welcome/checker/CheckerContainer.h @@ -40,7 +40,7 @@ class CheckerContainer : public QWidget { Q_OBJECT public: - explicit CheckerContainer(const RequirementsModel &model, QWidget* parent = nullptr ); + explicit CheckerContainer(const Calamares::RequirementsModel &model, QWidget* parent = nullptr ); virtual ~CheckerContainer(); bool verdict() const; @@ -58,7 +58,7 @@ protected: bool m_verdict; private: - const RequirementsModel &m_model; + const Calamares::RequirementsModel &m_model; } ; #endif diff --git a/src/modules/welcome/checker/ResultsListWidget.cpp b/src/modules/welcome/checker/ResultsListWidget.cpp index 275010b2f..c16cda4c4 100644 --- a/src/modules/welcome/checker/ResultsListWidget.cpp +++ b/src/modules/welcome/checker/ResultsListWidget.cpp @@ -47,7 +47,7 @@ static void createResultWidgets( QLayout* layout, QList< ResultWidget* >& resultWidgets, - const RequirementsModel &model, + const Calamares::RequirementsModel &model, std::function< bool( const Calamares::RequirementEntry& ) > predicate ) { @@ -94,18 +94,18 @@ public: * The list must continue to exist for the lifetime of the dialog, * or UB happens. */ - ResultsListDialog( const RequirementsModel& model, QWidget* parent ); + ResultsListDialog( const Calamares::RequirementsModel& model, QWidget* parent ); virtual ~ResultsListDialog(); private: QLabel* m_title; QList< ResultWidget* > m_resultWidgets; ///< One widget for each entry with details available - const RequirementsModel& m_model; + const Calamares::RequirementsModel& m_model; void retranslate(); }; -ResultsListDialog::ResultsListDialog( const RequirementsModel& model, QWidget* parent) +ResultsListDialog::ResultsListDialog( const Calamares::RequirementsModel& model, QWidget* parent) : QDialog( parent ) , m_model( model ) { @@ -151,7 +151,7 @@ ResultsListDialog::retranslate() } -ResultsListWidget::ResultsListWidget( const RequirementsModel &model, QWidget* parent ) +ResultsListWidget::ResultsListWidget( const Calamares::RequirementsModel &model, QWidget* parent ) : QWidget( parent ) , m_model( model ) { diff --git a/src/modules/welcome/checker/ResultsListWidget.h b/src/modules/welcome/checker/ResultsListWidget.h index eb1bdb611..05a8adfa4 100644 --- a/src/modules/welcome/checker/ResultsListWidget.h +++ b/src/modules/welcome/checker/ResultsListWidget.h @@ -30,7 +30,7 @@ class ResultsListWidget : public QWidget { Q_OBJECT public: - explicit ResultsListWidget(const RequirementsModel &model, QWidget* parent); + explicit ResultsListWidget(const Calamares::RequirementsModel &model, QWidget* parent); private: /// @brief A link in the explanatory text has been clicked @@ -38,7 +38,7 @@ private: void retranslate(); QLabel* m_explanation = nullptr; ///< Explanatory text above the list, with link - const RequirementsModel &m_model; + const Calamares::RequirementsModel &m_model; QList< ResultWidget* > m_resultWidgets; ///< One widget for each unsatisfied entry };