[libcalamares] Re-vamp RequirementsChecker

- Give the ModuleManager a RequirementsModel -- that is the source
  of truth about the module-requirements of the modules managed
  by that particular ModuleManager.
- Let the RequirementsChecker operate on a given RequirementsModel.
This commit is contained in:
Adriaan de Groot 2020-05-11 15:35:03 +02:00
parent 039065ee4a
commit b7c60cec66
6 changed files with 21 additions and 39 deletions

View File

@ -20,6 +20,7 @@
#include "modulesystem/Module.h"
#include "modulesystem/Requirement.h"
#include "modulesystem/RequirementsModel.h"
#include "utils/Logger.h"
#include <QFuture>
@ -63,14 +64,14 @@ check( Module* const& m, RequirementsChecker* c )
QObject::tr( "Requirements checking for module <i>%1</i> is complete." ).arg( m->name() ) );
}
RequirementsChecker::RequirementsChecker( QVector< Module* > modules, QObject* parent )
RequirementsChecker::RequirementsChecker( QVector< Module* > modules, RequirementsModel* model, QObject* parent )
: QObject( parent )
, m_modules( std::move( modules ) )
, m_model( model )
, m_progressTimer( nullptr )
, m_progressTimeouts( 0 )
{
m_watchers.reserve( m_modules.count() );
m_collectedRequirements.reserve( m_modules.count() );
registerMetatypes();
}
@ -114,19 +115,8 @@ RequirementsChecker::finished()
m_progressTimer = nullptr;
}
bool acceptable = true;
int count = 0;
for ( const auto& r : m_collectedRequirements )
{
if ( r.mandatory && !r.satisfied )
{
cDebug() << Logger::SubEntry << "requirement" << count << r.name << "is not satisfied.";
acceptable = false;
}
++count;
}
emit requirementsComplete( acceptable );
m_model->describe();
emit requirementsComplete( m_model->satisfiedMandatory() );
QTimer::singleShot( 0, this, &RequirementsChecker::done );
}
}
@ -134,11 +124,7 @@ RequirementsChecker::finished()
void
RequirementsChecker::addCheckedRequirements( RequirementsList l )
{
static QMutex addMutex;
{
QMutexLocker lock( &addMutex );
m_collectedRequirements.append( l );
}
m_model->addRequirementsList( l );
cDebug() << "Added" << l.count() << "requirement results";
emit requirementsResult( l );
}

View File

@ -29,6 +29,7 @@ namespace Calamares
{
class Module;
class RequirementsModel;
/** @brief A manager-class that checks all the module requirements
*
@ -40,7 +41,7 @@ class RequirementsChecker : public QObject
Q_OBJECT
public:
RequirementsChecker( QVector< Module* > modules, QObject* parent = nullptr );
RequirementsChecker( QVector< Module* > modules, RequirementsModel* model, QObject* parent = nullptr );
virtual ~RequirementsChecker() override;
public Q_SLOTS:
@ -75,7 +76,7 @@ private:
using Watcher = QFutureWatcher< void >;
QVector< Watcher* > m_watchers;
RequirementsList m_collectedRequirements;
RequirementsModel* m_model;
QTimer* m_progressTimer;
unsigned m_progressTimeouts;

View File

@ -23,16 +23,6 @@
namespace Calamares
{
void
RequirementsModel::setRequirementsList( const Calamares::RequirementsList& requirements )
{
QMutexLocker l( &m_addLock );
emit beginResetModel();
m_requirements = requirements;
changeRequirementsList();
emit endResetModel();
}
void
RequirementsModel::addRequirementsList( const Calamares::RequirementsList& requirements )
{

View File

@ -28,6 +28,8 @@
namespace Calamares
{
class RequirementsChecker;
/** @brief System requirements from each module and their checked-status
*
* A Calamares module can have system requirements (e.g. check for
@ -39,6 +41,8 @@ namespace Calamares
*/
class DLLEXPORT RequirementsModel : public QAbstractListModel
{
friend class RequirementsChecker;
Q_OBJECT
Q_PROPERTY( bool satisfiedRequirements READ satisfiedRequirements NOTIFY satisfiedRequirementsChanged FINAL )
Q_PROPERTY( bool satisfiedMandatory READ satisfiedMandatory NOTIFY satisfiedMandatoryChanged FINAL )
@ -62,11 +66,6 @@ public:
///@brief Are all the **mandatory** requirements satisfied?
bool satisfiedMandatory() const { return m_satisfiedMandatory; }
///@brief Replace the entire list of requirements; resets the model
void setRequirementsList( const Calamares::RequirementsList& requirements );
///@brief Append some requirements; resets the model
void addRequirementsList( const Calamares::RequirementsList& requirements );
QVariant data( const QModelIndex& index, int role ) const override;
int rowCount( const QModelIndex& ) const override;
int count() const { return m_requirements.count(); }
@ -81,6 +80,9 @@ signals:
protected:
QHash< int, QByteArray > roleNames() const override;
///@brief Append some requirements; resets the model
void addRequirementsList( const Calamares::RequirementsList& requirements );
private:
///@brief Implementation for {set,add}RequirementsList
void changeRequirementsList();

View File

@ -24,6 +24,7 @@
#include "Settings.h"
#include "modulesystem/Module.h"
#include "modulesystem/RequirementsChecker.h"
#include "modulesystem/RequirementsModel.h"
#include "utils/Logger.h"
#include "utils/Yaml.h"
#include "viewpages/ExecutionViewStep.h"
@ -46,6 +47,7 @@ ModuleManager::instance()
ModuleManager::ModuleManager( const QStringList& paths, QObject* parent )
: QObject( parent )
, m_paths( paths )
, m_requirementsModel( new RequirementsModel( this ) )
{
Q_ASSERT( !s_instance );
s_instance = this;
@ -355,7 +357,7 @@ ModuleManager::checkRequirements()
modules[ count++ ] = module;
}
RequirementsChecker* rq = new RequirementsChecker( modules, this );
RequirementsChecker* rq = new RequirementsChecker( modules, m_requirementsModel, this );
connect( rq, &RequirementsChecker::requirementsResult, this, &ModuleManager::requirementsResult );
connect( rq, &RequirementsChecker::requirementsComplete, this, &ModuleManager::requirementsComplete );
connect( rq, &RequirementsChecker::requirementsProgress, this, &ModuleManager::requirementsProgress );

View File

@ -32,7 +32,7 @@ namespace Calamares
{
class Module;
struct RequirementEntry; // from Requirement.h
class RequirementsModel;
/**
* @brief The ModuleManager class is a singleton which manages Calamares modules.
@ -130,6 +130,7 @@ private:
QMap< QString, QString > m_moduleDirectoriesByModuleName;
QMap< ModuleSystem::InstanceKey, Module* > m_loadedModulesByInstanceKey;
const QStringList m_paths;
RequirementsModel* m_requirementsModel;
static ModuleManager* s_instance;
};