diff --git a/src/calamares/Module.cpp b/src/calamares/Module.cpp index f4071c9eb..16ddec66a 100644 --- a/src/calamares/Module.cpp +++ b/src/calamares/Module.cpp @@ -118,3 +118,10 @@ Calamares::Module::name() { return m_name; } + + +QStringList +Calamares::Module::requiredModules() +{ + return m_requiredModules; +} diff --git a/src/calamares/Module.h b/src/calamares/Module.h index c938a6cda..51c5929c2 100644 --- a/src/calamares/Module.h +++ b/src/calamares/Module.h @@ -45,6 +45,7 @@ public: static Module* loadFromFile( const QString& path ); QString name(); + QStringList requiredModules(); enum Type { diff --git a/src/calamares/ModuleLoader.cpp b/src/calamares/ModuleLoader.cpp index ee21e9a23..1e00a8162 100644 --- a/src/calamares/ModuleLoader.cpp +++ b/src/calamares/ModuleLoader.cpp @@ -23,6 +23,7 @@ #include #include +#include #define MODULE_CONFIG_FILENAME "module.conf" @@ -45,7 +46,14 @@ ModuleLoader::~ModuleLoader() void -ModuleLoader::exec() +ModuleLoader::start() +{ + QTimer::singleShot( 0, this, SLOT( doWork() ) ); +} + + +void +ModuleLoader::doWork() { // We start from a list of paths in m_paths. Each of those is a directory that // might (should) contain Calamares modules of any type/interface. @@ -98,6 +106,37 @@ ModuleLoader::exec() } // At this point m_availableModules is filled with whatever was found in the // search paths. + checkDependencies(); + emit done(); +} + + +void +ModuleLoader::checkDependencies() +{ + // This goes through the map of available modules, and deletes those whose + // dependencies are not met, if any. + bool somethingWasRemovedBecauseOfUnmetDependencies = false; + forever + { + for ( auto it = m_availableModules.begin(); + it != m_availableModules.end(); ++it ) + { + foreach ( QString depName, (*it)->requiredModules() ) + { + if ( !m_availableModules.contains( depName ) ) + { + somethingWasRemovedBecauseOfUnmetDependencies = true; + m_availableModules.erase( it ); + break; + } + } + if ( somethingWasRemovedBecauseOfUnmetDependencies ) + break; + } + if ( !somethingWasRemovedBecauseOfUnmetDependencies ) + break; + } } } diff --git a/src/calamares/ModuleLoader.h b/src/calamares/ModuleLoader.h index c5920b068..2a7ff5d36 100644 --- a/src/calamares/ModuleLoader.h +++ b/src/calamares/ModuleLoader.h @@ -37,12 +37,17 @@ public: explicit ModuleLoader( const QStringList& paths, QObject* parent = 0 ); virtual ~ModuleLoader(); - void exec(); + void start(); signals: void done(); +private slots: + void doWork(); + private: + void checkDependencies(); + QMap< QString, Module* > m_availableModules; QStringList m_paths;