ModuleLoader ==> ModuleManager

This commit is contained in:
Teo Mrnjavac 2014-06-24 18:01:11 +02:00
parent c23d198923
commit 205250e7c4
7 changed files with 47 additions and 22 deletions

View File

@ -11,7 +11,7 @@ set( calamaresSources
CalamaresApplication.cpp CalamaresApplication.cpp
CalamaresWindow.cpp CalamaresWindow.cpp
Module.cpp Module.cpp
ModuleLoader.cpp ModuleManager.cpp
ViewManager.cpp ViewManager.cpp
Settings.cpp Settings.cpp
YamlUtils.cpp YamlUtils.cpp

View File

@ -20,10 +20,11 @@
#include "CalamaresWindow.h" #include "CalamaresWindow.h"
#include "CalamaresVersion.h" #include "CalamaresVersion.h"
#include "ModuleLoader.h" #include "ModuleManager.h"
#include "Settings.h" #include "Settings.h"
#include "utils/CalamaresUtils.h" #include "utils/CalamaresUtils.h"
#include "utils/Logger.h" #include "utils/Logger.h"
#include "ViewManager.h"
CalamaresApplication::CalamaresApplication( int& argc, char *argv[] ) CalamaresApplication::CalamaresApplication( int& argc, char *argv[] )
@ -112,11 +113,11 @@ CalamaresApplication::initBranding()
void void
CalamaresApplication::initPlugins() CalamaresApplication::initPlugins()
{ {
m_moduleLoader = new Calamares::ModuleLoader( m_moduleManager = new Calamares::ModuleManager(
Calamares::Settings::instance()->modulesSearchPaths(), this ); Calamares::Settings::instance()->modulesSearchPaths(), this );
connect( m_moduleLoader, &Calamares::ModuleLoader::done, connect( m_moduleManager, &Calamares::ModuleManager::ready,
this, &CalamaresApplication::onPluginsReady ); this, &CalamaresApplication::onPluginsReady );
m_moduleLoader->start(); m_moduleManager->start();
} }
@ -126,6 +127,13 @@ CalamaresApplication::onPluginsReady()
initJobQueue(); initJobQueue();
m_mainwindow = new CalamaresWindow(); m_mainwindow = new CalamaresWindow();
// foreach ( QString moduleName, Calamares::Settings::instance()->viewModulesPrepare() )
// {
// Q_ASSERT( m_moduleManager->availableModules().contains( moduleName ) );
// m_moduleManager->module( moduleName )->loadSelf();
// }
m_mainwindow->show(); m_mainwindow->show();
} }

View File

@ -27,7 +27,7 @@ class CalamaresWindow;
namespace Calamares namespace Calamares
{ {
class ModuleLoader; class ModuleManager;
} }
class CalamaresApplication : public QApplication class CalamaresApplication : public QApplication
@ -53,7 +53,7 @@ private:
void initJobQueue(); void initJobQueue();
CalamaresWindow* m_mainwindow; CalamaresWindow* m_mainwindow;
Calamares::ModuleLoader* m_moduleLoader; Calamares::ModuleManager* m_moduleManager;
bool m_debugMode; bool m_debugMode;
//QPointer< Calamares::JobQueue > m_jobQueue; //QPointer< Calamares::JobQueue > m_jobQueue;

View File

@ -81,7 +81,7 @@ operator>>( const YAML::Node& node, Calamares::Module& m )
Calamares::Module* Calamares::Module*
Calamares::Module::loadFromFile( const QString& path ) Calamares::Module::fromConfigFile( const QString& path )
{ {
QFile metadataFile( path ); QFile metadataFile( path );
if ( metadataFile.exists() && metadataFile.open( QFile::ReadOnly | QFile::Text ) ) if ( metadataFile.exists() && metadataFile.open( QFile::ReadOnly | QFile::Text ) )

View File

@ -42,7 +42,7 @@ namespace Calamares
class UIDLLEXPORT Module class UIDLLEXPORT Module
{ {
public: public:
static Module* loadFromFile( const QString& path ); static Module* fromConfigFile( const QString& path );
QString name(); QString name();
QStringList requiredModules(); QStringList requiredModules();

View File

@ -16,7 +16,7 @@
* along with Calamares. If not, see <http://www.gnu.org/licenses/>. * along with Calamares. If not, see <http://www.gnu.org/licenses/>.
*/ */
#include "ModuleLoader.h" #include "ModuleManager.h"
#include "utils/Logger.h" #include "utils/Logger.h"
@ -30,13 +30,13 @@
namespace Calamares namespace Calamares
{ {
ModuleLoader::ModuleLoader( const QStringList& paths, QObject* parent ) ModuleManager::ModuleManager( const QStringList& paths, QObject* parent )
: QObject( parent ) : QObject( parent )
, m_paths( paths ) , m_paths( paths )
{ {
} }
ModuleLoader::~ModuleLoader() ModuleManager::~ModuleManager()
{ {
foreach ( Module* m, m_availableModules ) foreach ( Module* m, m_availableModules )
{ {
@ -46,14 +46,28 @@ ModuleLoader::~ModuleLoader()
void void
ModuleLoader::start() ModuleManager::start()
{ {
QTimer::singleShot( 0, this, SLOT( doWork() ) ); QTimer::singleShot( 0, this, SLOT( doWork() ) );
} }
QStringList
ModuleManager::availableModules()
{
return m_availableModules.keys();
}
Module*
ModuleManager::module( const QString& name )
{
return m_availableModules.value( name );
}
void void
ModuleLoader::doWork() ModuleManager::doWork()
{ {
// We start from a list of paths in m_paths. Each of those is a directory that // 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. // might (should) contain Calamares modules of any type/interface.
@ -82,7 +96,7 @@ ModuleLoader::doWork()
continue; continue;
} }
Module* moduleInfo = Module::loadFromFile( metadataFileInfo.absoluteFilePath() ); Module* moduleInfo = Module::fromConfigFile( metadataFileInfo.absoluteFilePath() );
if ( moduleInfo && if ( moduleInfo &&
( moduleInfo->name() == currentDir.dirName() ) && ( moduleInfo->name() == currentDir.dirName() ) &&
@ -106,12 +120,12 @@ ModuleLoader::doWork()
// At this point m_availableModules is filled with whatever was found in the // At this point m_availableModules is filled with whatever was found in the
// search paths. // search paths.
checkDependencies(); checkDependencies();
emit done(); emit ready();
} }
void void
ModuleLoader::checkDependencies() ModuleManager::checkDependencies()
{ {
// This goes through the map of available modules, and deletes those whose // This goes through the map of available modules, and deletes those whose
// dependencies are not met, if any. // dependencies are not met, if any.

View File

@ -30,17 +30,20 @@ namespace Calamares
class Module; class Module;
class ModuleLoader : public QObject class ModuleManager : public QObject
{ {
Q_OBJECT Q_OBJECT
public: public:
explicit ModuleLoader( const QStringList& paths, QObject* parent = 0 ); explicit ModuleManager( const QStringList& paths, QObject* parent = 0 );
virtual ~ModuleLoader(); virtual ~ModuleManager();
void start(); void start();
QStringList availableModules();
Module* module( const QString& name );
signals: signals:
void done(); void ready();
private slots: private slots:
void doWork(); void doWork();