From 2e47c248acfa193297bca527a846e137262d89c2 Mon Sep 17 00:00:00 2001 From: Teo Mrnjavac Date: Fri, 11 Jul 2014 14:40:15 +0200 Subject: [PATCH] Load modules by phase, in preparation for actually using new settings. --- src/libcalamares/Typedefs.h | 8 +++ src/libcalamaresui/Settings.cpp | 30 +++++------ src/libcalamaresui/Settings.h | 11 ++-- .../modulesystem/ModuleManager.cpp | 53 ++++++++++--------- .../modulesystem/ModuleManager.h | 10 +++- 5 files changed, 61 insertions(+), 51 deletions(-) diff --git a/src/libcalamares/Typedefs.h b/src/libcalamares/Typedefs.h index 03f603e91..c71c3a695 100644 --- a/src/libcalamares/Typedefs.h +++ b/src/libcalamares/Typedefs.h @@ -27,6 +27,14 @@ class Job; typedef QSharedPointer< Job > job_ptr; +enum Phase +{ + Phase_NULL = 0, + Prepare, + Install, + PostInstall +}; + } //ns #endif // TYPEDEFS_H diff --git a/src/libcalamaresui/Settings.cpp b/src/libcalamaresui/Settings.cpp index 65749f330..de3873dce 100644 --- a/src/libcalamaresui/Settings.cpp +++ b/src/libcalamaresui/Settings.cpp @@ -112,30 +112,26 @@ Settings::Settings( bool debugMode, QObject* parent ) QStringList -Settings::modulesSearchPaths() +Settings::modulesSearchPaths() const { return m_modulesSearchPaths; } QStringList -Settings::modulesPrepare() +Settings::modules( Phase phase ) const { - return m_modulesPrepareList; -} - - -QStringList -Settings::modulesInstall() -{ - return m_modulesInstallList; -} - - -QStringList -Settings::modulesPostInstall() -{ - return m_modulesPostInstallList; + switch ( phase ) + { + case Prepare: + return m_modulesPrepareList; + case Install: + return m_modulesInstallList; + case PostInstall: + return m_modulesPostInstallList; + default: + return QStringList(); + } } diff --git a/src/libcalamaresui/Settings.h b/src/libcalamaresui/Settings.h index 35d99653a..da7a6cff2 100644 --- a/src/libcalamaresui/Settings.h +++ b/src/libcalamaresui/Settings.h @@ -20,6 +20,7 @@ #define SETTINGS_H #include "UiDllMacro.h" +#include "Typedefs.h" #include #include @@ -37,19 +38,15 @@ public: static Settings* instance(); //TODO: load from JSON then emit ready - QStringList modulesSearchPaths(); - - QStringList modulesPrepare(); - - QStringList modulesInstall(); - - QStringList modulesPostInstall(); + QStringList modulesSearchPaths() const; + QStringList modules( Phase phase ) const; private: static Settings* s_instance; QStringList m_modulesSearchPaths; + QStringList m_modulesPrepareList; QStringList m_modulesInstallList; QStringList m_modulesPostInstallList; diff --git a/src/libcalamaresui/modulesystem/ModuleManager.cpp b/src/libcalamaresui/modulesystem/ModuleManager.cpp index 16f0e5b6e..7b7131357 100644 --- a/src/libcalamaresui/modulesystem/ModuleManager.cpp +++ b/src/libcalamaresui/modulesystem/ModuleManager.cpp @@ -69,9 +69,35 @@ ModuleManager::module( const QString& name ) void -ModuleManager::loadModulesPrepare() +ModuleManager::loadModules( Phase phase ) { - QTimer::singleShot( 0, this, SLOT( doLoadModulesPrepare() ) ); + //FIXME: When we depend on Qt 5.4 this ugly hack should be replaced with + // QTimer::singleShot. + QTimer* timer = new QTimer(); + timer->setSingleShot( true ); + connect( timer, &QTimer::timeout, + this, [ this, timer, phase ]() + { + foreach ( const QString& moduleName, Settings::instance()->modules( phase ) ) + { + if ( !m_availableModules.contains( moduleName ) ) + { + cDebug() << "Module" << moduleName << "not found in module search paths." + << "\nCalamares will now quit."; + qApp->quit(); + } + recursiveLoad( moduleName ); + } + emit modulesLoaded(); + // Loading sequence: + // 1) deps are already fine. check if we have all the modules needed by the roster + // 2) ask ModuleManager to load them from the list provided by Settings + // 3) MM must load them asyncly but one at a time, by calling Module::loadSelf + // 4) Module must have subclasses that reimplement loadSelf for various module types + + timer->deleteLater(); + }); + timer->start( 0 ); } @@ -133,29 +159,6 @@ ModuleManager::doInit() } -void -ModuleManager::doLoadModulesPrepare() -{ - foreach ( const QString& moduleName, Settings::instance()->modulesPrepare() ) - { - if ( !m_availableModules.contains( moduleName ) ) - { - cDebug() << "Module" << moduleName << "not found in module search paths." - << "\nCalamares will now quit."; - qApp->quit(); - } - recursiveLoad( moduleName ); - } - emit modulesLoaded(); - - //IDEA: - // 1) deps are already fine. check if we have all the modules needed by the roster - // 2) ask MM to load them from the list provided by Settings - // 3) MM must load them asyncly but one at a time, by calling Module::loadSelf - // 4) Module must have subclasses that reimplement loadSelf for various module types -} - - void ModuleManager::recursiveLoad( const QString& moduleName ) { diff --git a/src/libcalamaresui/modulesystem/ModuleManager.h b/src/libcalamaresui/modulesystem/ModuleManager.h index 2ccb6921c..19d113c65 100644 --- a/src/libcalamaresui/modulesystem/ModuleManager.h +++ b/src/libcalamaresui/modulesystem/ModuleManager.h @@ -20,6 +20,7 @@ #define MODULELOADER_H #include "Module.h" +#include "Typedefs.h" #include #include @@ -37,12 +38,18 @@ public: explicit ModuleManager( const QStringList& paths, QObject* parent = nullptr ); virtual ~ModuleManager(); + /** + * @brief init goes through the module search directories and gets a list of + * modules available for loading, along with their metadata. + * This information is stored as a map of Module* objects, indexed by name. + */ void init(); QStringList availableModules(); Module* module( const QString& name ); - void loadModulesPrepare(); + void loadModules( Phase phase ); + void loadModulesPrepare() { loadModules( Prepare ); } signals: void initDone(); @@ -50,7 +57,6 @@ signals: private slots: void doInit(); - void doLoadModulesPrepare(); private: void recursiveLoad( const QString& moduleName );