[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:
parent
039065ee4a
commit
b7c60cec66
@ -20,6 +20,7 @@
|
|||||||
|
|
||||||
#include "modulesystem/Module.h"
|
#include "modulesystem/Module.h"
|
||||||
#include "modulesystem/Requirement.h"
|
#include "modulesystem/Requirement.h"
|
||||||
|
#include "modulesystem/RequirementsModel.h"
|
||||||
#include "utils/Logger.h"
|
#include "utils/Logger.h"
|
||||||
|
|
||||||
#include <QFuture>
|
#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() ) );
|
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 )
|
: QObject( parent )
|
||||||
, m_modules( std::move( modules ) )
|
, m_modules( std::move( modules ) )
|
||||||
|
, m_model( model )
|
||||||
, m_progressTimer( nullptr )
|
, m_progressTimer( nullptr )
|
||||||
, m_progressTimeouts( 0 )
|
, m_progressTimeouts( 0 )
|
||||||
{
|
{
|
||||||
m_watchers.reserve( m_modules.count() );
|
m_watchers.reserve( m_modules.count() );
|
||||||
m_collectedRequirements.reserve( m_modules.count() );
|
|
||||||
|
|
||||||
registerMetatypes();
|
registerMetatypes();
|
||||||
}
|
}
|
||||||
@ -114,19 +115,8 @@ RequirementsChecker::finished()
|
|||||||
m_progressTimer = nullptr;
|
m_progressTimer = nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool acceptable = true;
|
m_model->describe();
|
||||||
int count = 0;
|
emit requirementsComplete( m_model->satisfiedMandatory() );
|
||||||
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 );
|
|
||||||
QTimer::singleShot( 0, this, &RequirementsChecker::done );
|
QTimer::singleShot( 0, this, &RequirementsChecker::done );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -134,11 +124,7 @@ RequirementsChecker::finished()
|
|||||||
void
|
void
|
||||||
RequirementsChecker::addCheckedRequirements( RequirementsList l )
|
RequirementsChecker::addCheckedRequirements( RequirementsList l )
|
||||||
{
|
{
|
||||||
static QMutex addMutex;
|
m_model->addRequirementsList( l );
|
||||||
{
|
|
||||||
QMutexLocker lock( &addMutex );
|
|
||||||
m_collectedRequirements.append( l );
|
|
||||||
}
|
|
||||||
cDebug() << "Added" << l.count() << "requirement results";
|
cDebug() << "Added" << l.count() << "requirement results";
|
||||||
emit requirementsResult( l );
|
emit requirementsResult( l );
|
||||||
}
|
}
|
||||||
|
@ -29,6 +29,7 @@ namespace Calamares
|
|||||||
{
|
{
|
||||||
|
|
||||||
class Module;
|
class Module;
|
||||||
|
class RequirementsModel;
|
||||||
|
|
||||||
/** @brief A manager-class that checks all the module requirements
|
/** @brief A manager-class that checks all the module requirements
|
||||||
*
|
*
|
||||||
@ -40,7 +41,7 @@ class RequirementsChecker : public QObject
|
|||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
|
|
||||||
public:
|
public:
|
||||||
RequirementsChecker( QVector< Module* > modules, QObject* parent = nullptr );
|
RequirementsChecker( QVector< Module* > modules, RequirementsModel* model, QObject* parent = nullptr );
|
||||||
virtual ~RequirementsChecker() override;
|
virtual ~RequirementsChecker() override;
|
||||||
|
|
||||||
public Q_SLOTS:
|
public Q_SLOTS:
|
||||||
@ -75,7 +76,7 @@ private:
|
|||||||
using Watcher = QFutureWatcher< void >;
|
using Watcher = QFutureWatcher< void >;
|
||||||
QVector< Watcher* > m_watchers;
|
QVector< Watcher* > m_watchers;
|
||||||
|
|
||||||
RequirementsList m_collectedRequirements;
|
RequirementsModel* m_model;
|
||||||
|
|
||||||
QTimer* m_progressTimer;
|
QTimer* m_progressTimer;
|
||||||
unsigned m_progressTimeouts;
|
unsigned m_progressTimeouts;
|
||||||
|
@ -23,16 +23,6 @@
|
|||||||
namespace Calamares
|
namespace Calamares
|
||||||
{
|
{
|
||||||
|
|
||||||
void
|
|
||||||
RequirementsModel::setRequirementsList( const Calamares::RequirementsList& requirements )
|
|
||||||
{
|
|
||||||
QMutexLocker l( &m_addLock );
|
|
||||||
emit beginResetModel();
|
|
||||||
m_requirements = requirements;
|
|
||||||
changeRequirementsList();
|
|
||||||
emit endResetModel();
|
|
||||||
}
|
|
||||||
|
|
||||||
void
|
void
|
||||||
RequirementsModel::addRequirementsList( const Calamares::RequirementsList& requirements )
|
RequirementsModel::addRequirementsList( const Calamares::RequirementsList& requirements )
|
||||||
{
|
{
|
||||||
|
@ -28,6 +28,8 @@
|
|||||||
|
|
||||||
namespace Calamares
|
namespace Calamares
|
||||||
{
|
{
|
||||||
|
class RequirementsChecker;
|
||||||
|
|
||||||
/** @brief System requirements from each module and their checked-status
|
/** @brief System requirements from each module and their checked-status
|
||||||
*
|
*
|
||||||
* A Calamares module can have system requirements (e.g. check for
|
* A Calamares module can have system requirements (e.g. check for
|
||||||
@ -39,6 +41,8 @@ namespace Calamares
|
|||||||
*/
|
*/
|
||||||
class DLLEXPORT RequirementsModel : public QAbstractListModel
|
class DLLEXPORT RequirementsModel : public QAbstractListModel
|
||||||
{
|
{
|
||||||
|
friend class RequirementsChecker;
|
||||||
|
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
Q_PROPERTY( bool satisfiedRequirements READ satisfiedRequirements NOTIFY satisfiedRequirementsChanged FINAL )
|
Q_PROPERTY( bool satisfiedRequirements READ satisfiedRequirements NOTIFY satisfiedRequirementsChanged FINAL )
|
||||||
Q_PROPERTY( bool satisfiedMandatory READ satisfiedMandatory NOTIFY satisfiedMandatoryChanged FINAL )
|
Q_PROPERTY( bool satisfiedMandatory READ satisfiedMandatory NOTIFY satisfiedMandatoryChanged FINAL )
|
||||||
@ -62,11 +66,6 @@ public:
|
|||||||
///@brief Are all the **mandatory** requirements satisfied?
|
///@brief Are all the **mandatory** requirements satisfied?
|
||||||
bool satisfiedMandatory() const { return m_satisfiedMandatory; }
|
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;
|
QVariant data( const QModelIndex& index, int role ) const override;
|
||||||
int rowCount( const QModelIndex& ) const override;
|
int rowCount( const QModelIndex& ) const override;
|
||||||
int count() const { return m_requirements.count(); }
|
int count() const { return m_requirements.count(); }
|
||||||
@ -81,6 +80,9 @@ signals:
|
|||||||
protected:
|
protected:
|
||||||
QHash< int, QByteArray > roleNames() const override;
|
QHash< int, QByteArray > roleNames() const override;
|
||||||
|
|
||||||
|
///@brief Append some requirements; resets the model
|
||||||
|
void addRequirementsList( const Calamares::RequirementsList& requirements );
|
||||||
|
|
||||||
private:
|
private:
|
||||||
///@brief Implementation for {set,add}RequirementsList
|
///@brief Implementation for {set,add}RequirementsList
|
||||||
void changeRequirementsList();
|
void changeRequirementsList();
|
||||||
|
@ -24,6 +24,7 @@
|
|||||||
#include "Settings.h"
|
#include "Settings.h"
|
||||||
#include "modulesystem/Module.h"
|
#include "modulesystem/Module.h"
|
||||||
#include "modulesystem/RequirementsChecker.h"
|
#include "modulesystem/RequirementsChecker.h"
|
||||||
|
#include "modulesystem/RequirementsModel.h"
|
||||||
#include "utils/Logger.h"
|
#include "utils/Logger.h"
|
||||||
#include "utils/Yaml.h"
|
#include "utils/Yaml.h"
|
||||||
#include "viewpages/ExecutionViewStep.h"
|
#include "viewpages/ExecutionViewStep.h"
|
||||||
@ -46,6 +47,7 @@ ModuleManager::instance()
|
|||||||
ModuleManager::ModuleManager( const QStringList& paths, QObject* parent )
|
ModuleManager::ModuleManager( const QStringList& paths, QObject* parent )
|
||||||
: QObject( parent )
|
: QObject( parent )
|
||||||
, m_paths( paths )
|
, m_paths( paths )
|
||||||
|
, m_requirementsModel( new RequirementsModel( this ) )
|
||||||
{
|
{
|
||||||
Q_ASSERT( !s_instance );
|
Q_ASSERT( !s_instance );
|
||||||
s_instance = this;
|
s_instance = this;
|
||||||
@ -355,7 +357,7 @@ ModuleManager::checkRequirements()
|
|||||||
modules[ count++ ] = module;
|
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::requirementsResult, this, &ModuleManager::requirementsResult );
|
||||||
connect( rq, &RequirementsChecker::requirementsComplete, this, &ModuleManager::requirementsComplete );
|
connect( rq, &RequirementsChecker::requirementsComplete, this, &ModuleManager::requirementsComplete );
|
||||||
connect( rq, &RequirementsChecker::requirementsProgress, this, &ModuleManager::requirementsProgress );
|
connect( rq, &RequirementsChecker::requirementsProgress, this, &ModuleManager::requirementsProgress );
|
||||||
|
@ -32,7 +32,7 @@ namespace Calamares
|
|||||||
{
|
{
|
||||||
|
|
||||||
class Module;
|
class Module;
|
||||||
struct RequirementEntry; // from Requirement.h
|
class RequirementsModel;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief The ModuleManager class is a singleton which manages Calamares modules.
|
* @brief The ModuleManager class is a singleton which manages Calamares modules.
|
||||||
@ -130,6 +130,7 @@ private:
|
|||||||
QMap< QString, QString > m_moduleDirectoriesByModuleName;
|
QMap< QString, QString > m_moduleDirectoriesByModuleName;
|
||||||
QMap< ModuleSystem::InstanceKey, Module* > m_loadedModulesByInstanceKey;
|
QMap< ModuleSystem::InstanceKey, Module* > m_loadedModulesByInstanceKey;
|
||||||
const QStringList m_paths;
|
const QStringList m_paths;
|
||||||
|
RequirementsModel* m_requirementsModel;
|
||||||
|
|
||||||
static ModuleManager* s_instance;
|
static ModuleManager* s_instance;
|
||||||
};
|
};
|
||||||
|
Loading…
Reference in New Issue
Block a user