[welcome] Drop RequirementsModel

- Use the one from libcalamares
- Massage warning message into Config after it was removed from the model
This commit is contained in:
Adriaan de Groot 2020-04-02 21:52:05 +02:00
parent e5562a5069
commit ca7733c8e4
6 changed files with 69 additions and 185 deletions

View File

@ -23,71 +23,12 @@
#include "utils/Logger.h" #include "utils/Logger.h"
#include "utils/Retranslator.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 ) Config::Config( QObject* parent )
: QObject( parent ) : QObject( parent )
, m_requirementsModel( new RequirementsModel( this ) ) , m_requirementsModel( new Calamares::RequirementsModel( this ) )
, m_languages( CalamaresUtils::Locale::availableTranslations() ) , m_languages( CalamaresUtils::Locale::availableTranslations() )
{ {
connect( m_requirementsModel, &RequirementsModel::satisfiedRequirementsChanged, this, &Config::setIsNextEnabled ); connect( m_requirementsModel, &Calamares::RequirementsModel::satisfiedRequirementsChanged, this, &Config::setIsNextEnabled );
initLanguages(); initLanguages();
@ -100,7 +41,44 @@ Config::retranslate()
m_genericWelcomeMessage = genericWelcomeMessage().arg( *Calamares::Branding::VersionedName ); m_genericWelcomeMessage = genericWelcomeMessage().arg( *Calamares::Branding::VersionedName );
emit genericWelcomeMessageChanged(); 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.<br/>"
"Setup cannot continue. "
"<a href=\"#details\">Details...</a>" )
: tr( "This computer does not satisfy the minimum "
"requirements for installing %1.<br/>"
"Installation cannot continue. "
"<a href=\"#details\">Details...</a>" );
}
else
{
message = setup ? tr( "This computer does not satisfy some of the "
"recommended requirements for setting up %1.<br/>"
"Setup can continue, but some features "
"might be disabled." )
: tr( "This computer does not satisfy some of the "
"recommended requirements for installing %1.<br/>"
"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* CalamaresUtils::Locale::LabelModel*
@ -197,7 +175,7 @@ Config::setLocaleIndex( const int& index )
emit localeIndexChanged( m_localeIndex ); emit localeIndexChanged( m_localeIndex );
} }
RequirementsModel& Calamares::RequirementsModel&
Config::requirementsModel() const Config::requirementsModel() const
{ {
return *m_requirementsModel; return *m_requirementsModel;
@ -262,51 +240,8 @@ Config::setSupportUrl( const QString& url )
emit supportUrlChanged(); 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.<br/>"
"Setup cannot continue. "
"<a href=\"#details\">Details...</a>" )
: tr( "This computer does not satisfy the minimum "
"requirements for installing %1.<br/>"
"Installation cannot continue. "
"<a href=\"#details\">Details...</a>" );
}
else
{
message = setup ? tr( "This computer does not satisfy some of the "
"recommended requirements for setting up %1.<br/>"
"Setup can continue, but some features "
"might be disabled." )
: tr( "This computer does not satisfy some of the "
"recommended requirements for installing %1.<br/>"
"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 QString
Config::genericWelcomeMessage() Config::genericWelcomeMessage() const
{ {
QString message; QString message;
@ -325,3 +260,8 @@ Config::genericWelcomeMessage()
return message; return message;
} }
QString Config::warningMessage() const
{
return m_warningMessage;
}

View File

@ -19,79 +19,18 @@
#ifndef WELCOME_CONFIG_H #ifndef WELCOME_CONFIG_H
#define WELCOME_CONFIG_H #define WELCOME_CONFIG_H
#include "modulesystem/Requirement.h"
#include "locale/LabelModel.h" #include "locale/LabelModel.h"
#include "modulesystem/Requirement.h"
#include "modulesystem/RequirementsModel.h"
#include <QObject> #include <QObject>
#include <QUrl> #include <QUrl>
// 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 class Config : public QObject
{ {
Q_OBJECT Q_OBJECT
Q_PROPERTY( CalamaresUtils::Locale::LabelModel* languagesModel READ languagesModel CONSTANT FINAL ) 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 ) 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( int localeIndex READ localeIndex WRITE setLocaleIndex NOTIFY localeIndexChanged )
Q_PROPERTY( QString genericWelcomeMessage MEMBER m_genericWelcomeMessage NOTIFY genericWelcomeMessageChanged FINAL ) 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 supportUrl MEMBER m_supportUrl NOTIFY supportUrlChanged FINAL )
Q_PROPERTY( QString knownIssuesUrl MEMBER m_knownIssuesUrl NOTIFY knownIssuesUrlChanged FINAL ) Q_PROPERTY( QString knownIssuesUrl MEMBER m_knownIssuesUrl NOTIFY knownIssuesUrlChanged FINAL )
@ -111,7 +51,7 @@ public:
Config( QObject* parent = nullptr ); Config( QObject* parent = nullptr );
void setCountryCode( const QString& countryCode ); void setCountryCode( const QString& countryCode );
void setLanguageIcon( const QString& languageIcon ); void setLanguageIcon( const QString& languageIcon );
RequirementsModel& requirementsModel() const; Calamares::RequirementsModel& requirementsModel() const;
void setIsNextEnabled( const bool& isNextEnabled ); void setIsNextEnabled( const bool& isNextEnabled );
@ -130,8 +70,8 @@ public:
QString donateUrl() const; QString donateUrl() const;
void setDonateUrl( const QString& url ); void setDonateUrl( const QString& url );
QString genericWelcomeMessage(); QString genericWelcomeMessage() const;
QString warningMessage() const;
public slots: public slots:
CalamaresUtils::Locale::LabelModel* languagesModel() const; CalamaresUtils::Locale::LabelModel* languagesModel() const;
@ -141,7 +81,7 @@ public slots:
private: private:
void initLanguages(); void initLanguages();
QVariantMap m_configurationMap; QVariantMap m_configurationMap;
RequirementsModel* m_requirementsModel; Calamares::RequirementsModel* m_requirementsModel;
QString m_languageIcon; QString m_languageIcon;
QString m_countryCode; QString m_countryCode;
int m_localeIndex = 0; int m_localeIndex = 0;
@ -149,6 +89,7 @@ private:
CalamaresUtils::Locale::LabelModel* m_languages; CalamaresUtils::Locale::LabelModel* m_languages;
QString m_genericWelcomeMessage; QString m_genericWelcomeMessage;
QString m_warningMessage;
QString m_supportUrl; QString m_supportUrl;
QString m_knownIssuesUrl; QString m_knownIssuesUrl;
@ -159,7 +100,10 @@ signals:
void countryCodeChanged( QString countryCode ); void countryCodeChanged( QString countryCode );
void localeIndexChanged( int localeIndex ); void localeIndexChanged( int localeIndex );
void isNextEnabledChanged( bool isNextEnabled ); void isNextEnabledChanged( bool isNextEnabled );
void genericWelcomeMessageChanged(); void genericWelcomeMessageChanged();
void warningMessageChanged();
void supportUrlChanged(); void supportUrlChanged();
void knownIssuesUrlChanged(); void knownIssuesUrlChanged();
void releaseNotesUrlChanged(); void releaseNotesUrlChanged();

View File

@ -31,7 +31,7 @@
#include <QHBoxLayout> #include <QHBoxLayout>
CheckerContainer::CheckerContainer( const RequirementsModel &model, QWidget* parent ) CheckerContainer::CheckerContainer( const Calamares::RequirementsModel &model, QWidget* parent )
: QWidget( parent ) : QWidget( parent )
, m_waitingWidget( new WaitingWidget( QString(), this ) ) , m_waitingWidget( new WaitingWidget( QString(), this ) )
, m_checkerWidget( nullptr ) , m_checkerWidget( nullptr )

View File

@ -40,7 +40,7 @@ class CheckerContainer : public QWidget
{ {
Q_OBJECT Q_OBJECT
public: public:
explicit CheckerContainer(const RequirementsModel &model, QWidget* parent = nullptr ); explicit CheckerContainer(const Calamares::RequirementsModel &model, QWidget* parent = nullptr );
virtual ~CheckerContainer(); virtual ~CheckerContainer();
bool verdict() const; bool verdict() const;
@ -58,7 +58,7 @@ protected:
bool m_verdict; bool m_verdict;
private: private:
const RequirementsModel &m_model; const Calamares::RequirementsModel &m_model;
} ; } ;
#endif #endif

View File

@ -47,7 +47,7 @@
static void static void
createResultWidgets( QLayout* layout, createResultWidgets( QLayout* layout,
QList< ResultWidget* >& resultWidgets, QList< ResultWidget* >& resultWidgets,
const RequirementsModel &model, const Calamares::RequirementsModel &model,
std::function< bool( const Calamares::RequirementEntry& ) > predicate std::function< bool( const Calamares::RequirementEntry& ) > predicate
) )
{ {
@ -94,18 +94,18 @@ public:
* The list must continue to exist for the lifetime of the dialog, * The list must continue to exist for the lifetime of the dialog,
* or UB happens. * or UB happens.
*/ */
ResultsListDialog( const RequirementsModel& model, QWidget* parent ); ResultsListDialog( const Calamares::RequirementsModel& model, QWidget* parent );
virtual ~ResultsListDialog(); virtual ~ResultsListDialog();
private: private:
QLabel* m_title; QLabel* m_title;
QList< ResultWidget* > m_resultWidgets; ///< One widget for each entry with details available QList< ResultWidget* > m_resultWidgets; ///< One widget for each entry with details available
const RequirementsModel& m_model; const Calamares::RequirementsModel& m_model;
void retranslate(); void retranslate();
}; };
ResultsListDialog::ResultsListDialog( const RequirementsModel& model, QWidget* parent) ResultsListDialog::ResultsListDialog( const Calamares::RequirementsModel& model, QWidget* parent)
: QDialog( parent ) : QDialog( parent )
, m_model( model ) , 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 ) : QWidget( parent )
, m_model( model ) , m_model( model )
{ {

View File

@ -30,7 +30,7 @@ class ResultsListWidget : public QWidget
{ {
Q_OBJECT Q_OBJECT
public: public:
explicit ResultsListWidget(const RequirementsModel &model, QWidget* parent); explicit ResultsListWidget(const Calamares::RequirementsModel &model, QWidget* parent);
private: private:
/// @brief A link in the explanatory text has been clicked /// @brief A link in the explanatory text has been clicked
@ -38,7 +38,7 @@ private:
void retranslate(); void retranslate();
QLabel* m_explanation = nullptr; ///< Explanatory text above the list, with link 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 QList< ResultWidget* > m_resultWidgets; ///< One widget for each unsatisfied entry
}; };