From b7a86fd99821b86ffa92a20e47dac2ed10f78ab3 Mon Sep 17 00:00:00 2001 From: dfighter1985 Date: Mon, 9 Jun 2014 01:14:13 +0200 Subject: [PATCH] Plugin loading, with issues.. --- .../src/extension_system/plugin_manager.cpp | 60 +++++++++++++++++-- .../src/extension_system/plugin_manager.h | 1 + .../src/plugins/core/context_manager.cpp | 10 +--- .../studio/src/plugins/core/context_manager.h | 3 +- .../src/plugins/core/plugin_view_dialog.cpp | 15 ++++- 5 files changed, 72 insertions(+), 17 deletions(-) diff --git a/code/studio/src/extension_system/plugin_manager.cpp b/code/studio/src/extension_system/plugin_manager.cpp index c9f40e7bd..508a4b81b 100644 --- a/code/studio/src/extension_system/plugin_manager.cpp +++ b/code/studio/src/extension_system/plugin_manager.cpp @@ -114,8 +114,62 @@ void PluginManager::loadPlugins() Q_EMIT pluginsChanged(); } +bool PluginManager::loadPluginSpec( const char *plugin ) +{ + nlinfo( "Loading plugin spec %s", plugin ); + + PluginSpec *spec = new PluginSpec; + spec->m_pluginManager = this; + if( !spec->setSpecFileName( plugin ) ) + { + nlinfo( "Error loading plugin spec %s", plugin ); + return false; + } + + m_pluginSpecs.append( spec ); + m_ipluginSpecs.append( spec ); + + return true; +} + bool PluginManager::loadPlugin( const char *plugin ) { + if( !loadPluginSpec( plugin ) ) + return false; + + ExtensionSystem::PluginSpec *spec = m_pluginSpecs.last(); + + if( !spec->resolveDependencies( m_pluginSpecs ) ) + { + nlinfo( "Error resolving dependencies for plugin spec %s", plugin ); + return false; + } + + if( !spec->loadLibrary() ) + { + nlinfo( "Error loading plugin %s", spec->fileName().toUtf8().data() ); + return false; + } + + if( !spec->initializePlugin() ) + { + nlinfo( "Error initializing plugin %s", spec->fileName().toUtf8().data() ); + spec->kill(); + return false; + } + + if( !spec->initializeExtensions() ) + { + nlinfo( "Error starting plugin %s", spec->fileName().toUtf8().data() ); + spec->stop(); + spec->kill(); + return false; + } + + nlinfo( "Loaded plugin %s ( %s )", spec->name().data(), spec->fileName().toUtf8().data() ); + + Q_EMIT pluginsChanged(); + return true; } @@ -262,11 +316,7 @@ void PluginManager::readPluginPaths() Q_FOREACH (const QString &pluginFile, pluginsList) { - PluginSpec *spec = new PluginSpec; - spec->m_pluginManager = this; - spec->setSpecFileName(pluginFile); - m_pluginSpecs.append(spec); - m_ipluginSpecs.append(spec); + loadPluginSpec( pluginFile.toUtf8().data() ); } Q_EMIT pluginsChanged(); diff --git a/code/studio/src/extension_system/plugin_manager.h b/code/studio/src/extension_system/plugin_manager.h index 10130ffc4..9b0d7a0dc 100644 --- a/code/studio/src/extension_system/plugin_manager.h +++ b/code/studio/src/extension_system/plugin_manager.h @@ -51,6 +51,7 @@ public: virtual QList plugins() const; QList loadQueue(); + bool loadPluginSpec( const char *plugin ); bool loadPlugin( const char *plugin ); bool unloadPlugin( ExtensionSystem::IPluginSpec *plugin ); void removePlugin( ExtensionSystem::IPluginSpec *plugin ); diff --git a/code/studio/src/plugins/core/context_manager.cpp b/code/studio/src/plugins/core/context_manager.cpp index d81f62cf1..3b02b411c 100644 --- a/code/studio/src/plugins/core/context_manager.cpp +++ b/code/studio/src/plugins/core/context_manager.cpp @@ -36,13 +36,11 @@ struct ContextManagerPrivate Core::MainWindow *m_mainWindow; QTabWidget *m_tabWidget; QVector m_contexts; - int m_oldCurrent; }; ContextManagerPrivate::ContextManagerPrivate(Core::MainWindow *mainWindow, QTabWidget *tabWidget) : m_mainWindow(mainWindow), - m_tabWidget(tabWidget), - m_oldCurrent(-1) + m_tabWidget(tabWidget) { } @@ -145,11 +143,7 @@ void ContextManager::currentTabChanged(int index) if (index >= 0) { IContext *context = d->m_contexts.at(index); - IContext *oldContext = 0; - if (d->m_oldCurrent >= 0) - oldContext = d->m_contexts.at(d->m_oldCurrent); - d->m_oldCurrent = index; - Q_EMIT currentContextChanged(context, oldContext); + Q_EMIT currentContextChanged(context); } } diff --git a/code/studio/src/plugins/core/context_manager.h b/code/studio/src/plugins/core/context_manager.h index 8151648e7..9b0a62c7e 100644 --- a/code/studio/src/plugins/core/context_manager.h +++ b/code/studio/src/plugins/core/context_manager.h @@ -51,8 +51,7 @@ public: void unregisterUndoStack(QUndoStack *stack); Q_SIGNALS: - // the default argument '=0' is important for connects without the oldContext argument. - void currentContextChanged(Core::IContext *context, Core::IContext *oldContext = 0); + void currentContextChanged(Core::IContext *context); public Q_SLOTS: void activateContext(const QString &id); diff --git a/code/studio/src/plugins/core/plugin_view_dialog.cpp b/code/studio/src/plugins/core/plugin_view_dialog.cpp index bf62d4632..c47a1c75d 100644 --- a/code/studio/src/plugins/core/plugin_view_dialog.cpp +++ b/code/studio/src/plugins/core/plugin_view_dialog.cpp @@ -155,7 +155,18 @@ void PluginView::onLoadClicked() return; } - this->m_pluginManager->loadPlugin( f.toAscii().data() ); + QApplication::setOverrideCursor( Qt::WaitCursor ); + bool success = m_pluginManager->loadPlugin( f.toAscii().data() ); + QApplication::setOverrideCursor( Qt::ArrowCursor ); + + if( !success ) + { + QMessageBox::warning( this, + tr( "Loading plugin" ), + tr( "Error loading plugin!" ) ); + } } -} /* namespace Core */ \ No newline at end of file + +} /* namespace Core */ +