From 0827d29d592577a8dfe0d30dc2608bf8e1c3068d Mon Sep 17 00:00:00 2001 From: dnk-88 Date: Wed, 14 Sep 2011 01:47:27 +0300 Subject: [PATCH] Changed: #1193 Added the feature of enable/disable plugins on startup program. --- .../src/extension_system/iplugin.h | 2 +- .../src/extension_system/iplugin_manager.h | 2 +- .../src/extension_system/iplugin_spec.h | 6 +- .../src/extension_system/plugin_manager.cpp | 43 +++++++++++- .../src/extension_system/plugin_spec.cpp | 26 ++++++- .../src/extension_system/plugin_spec.h | 12 +++- .../tools/3d/object_viewer_qt/src/main.cpp | 21 ++---- .../src/plugins/core/core_plugin.cpp | 5 +- .../src/plugins/core/main_window.cpp | 6 +- .../src/plugins/core/main_window.h | 2 +- .../src/plugins/core/plugin_view_dialog.cpp | 67 ++++++++++++++----- .../src/plugins/core/plugin_view_dialog.h | 27 +++++--- .../src/plugins/core/plugin_view_dialog.ui | 18 ++--- 13 files changed, 171 insertions(+), 66 deletions(-) diff --git a/code/nel/tools/3d/object_viewer_qt/src/extension_system/iplugin.h b/code/nel/tools/3d/object_viewer_qt/src/extension_system/iplugin.h index fc2e0736b..864028501 100644 --- a/code/nel/tools/3d/object_viewer_qt/src/extension_system/iplugin.h +++ b/code/nel/tools/3d/object_viewer_qt/src/extension_system/iplugin.h @@ -105,6 +105,6 @@ public: }; //namespace ExtensionSystem -Q_DECLARE_INTERFACE(ExtensionSystem::IPlugin, "dev.ryzom.com.ObjectViewerQt.IPlugin/0.9.1") +Q_DECLARE_INTERFACE(ExtensionSystem::IPlugin, "dev.ryzom.com.ObjectViewerQt.IPlugin/0.9.2") #endif // IPLUGIN_H diff --git a/code/nel/tools/3d/object_viewer_qt/src/extension_system/iplugin_manager.h b/code/nel/tools/3d/object_viewer_qt/src/extension_system/iplugin_manager.h index 05d4b832c..e38748e77 100644 --- a/code/nel/tools/3d/object_viewer_qt/src/extension_system/iplugin_manager.h +++ b/code/nel/tools/3d/object_viewer_qt/src/extension_system/iplugin_manager.h @@ -98,7 +98,7 @@ public: { QList all = allObjects(); QObject *result = 0; - Q_FOREACH (QObject *qobj, all) + Q_FOREACH(QObject *qobj, all) { if (qobj->objectName() == name) { diff --git a/code/nel/tools/3d/object_viewer_qt/src/extension_system/iplugin_spec.h b/code/nel/tools/3d/object_viewer_qt/src/extension_system/iplugin_spec.h index f0c62fec7..45895c36f 100644 --- a/code/nel/tools/3d/object_viewer_qt/src/extension_system/iplugin_spec.h +++ b/code/nel/tools/3d/object_viewer_qt/src/extension_system/iplugin_spec.h @@ -71,9 +71,13 @@ public: virtual IPlugin *plugin() const = 0; // state - virtual int getState() const = 0; + virtual int state() const = 0; virtual bool hasError() const = 0; virtual QString errorString() const = 0; + + /// Enables/disables load this plugin after restart the program + virtual void setEnabled(bool enabled) = 0; + virtual bool isEnabled() const = 0; }; } // namespace ExtensionSystem diff --git a/code/nel/tools/3d/object_viewer_qt/src/extension_system/plugin_manager.cpp b/code/nel/tools/3d/object_viewer_qt/src/extension_system/plugin_manager.cpp index be5f18c74..3b2431a07 100644 --- a/code/nel/tools/3d/object_viewer_qt/src/extension_system/plugin_manager.cpp +++ b/code/nel/tools/3d/object_viewer_qt/src/extension_system/plugin_manager.cpp @@ -34,6 +34,7 @@ CPluginManager::CPluginManager(QObject *parent) CPluginManager::~CPluginManager() { + writeSettings(); stopAll(); deleteAll(); qDeleteAll(m_pluginSpecs); @@ -114,6 +115,7 @@ void CPluginManager::setPluginPaths(const QStringList &paths) { m_pluginPaths = paths; readPluginPaths(); + readSettings(); } QList CPluginManager::plugins() const @@ -133,10 +135,41 @@ QSettings *CPluginManager::settings() const void CPluginManager::readSettings() { + if (m_settings) + { + QStringList blackList; + m_settings->beginGroup("PluginManager"); + blackList = m_settings->value("BlackList").toStringList(); + m_settings->endGroup(); + Q_FOREACH (CPluginSpec *spec, m_pluginSpecs) + { + QString pluginName = spec->fileName(); + + if (blackList.contains(pluginName)) + { + spec->setEnabled(false); + spec->setEnabledStartup(false); + } + } + } } void CPluginManager::writeSettings() { + if (m_settings) + { + QStringList blackList; + Q_FOREACH(CPluginSpec *spec, m_pluginSpecs) + { + nlinfo(spec->fileName().toStdString().c_str()); + if (!spec->isEnabled()) + blackList.push_back(spec->fileName()); + } + m_settings->beginGroup("PluginManager"); + m_settings->setValue("BlackList", blackList); + m_settings->endGroup(); + m_settings->sync(); + } } void CPluginManager::readPluginPaths() @@ -176,7 +209,11 @@ void CPluginManager::readPluginPaths() void CPluginManager::setPluginState(CPluginSpec *spec, int destState) { - if (spec->hasError() || spec->getState() != destState-1) + if (spec->hasError() || spec->state() != destState-1) + return; + + // plugin in black list + if (!spec->isEnabledStartup()) return; switch (destState) @@ -198,7 +235,7 @@ void CPluginManager::setPluginState(CPluginSpec *spec, int destState) } Q_FOREACH (const CPluginSpec *depSpec, spec->dependencySpecs()) { - if (depSpec->getState() != destState) + if (depSpec->state() != destState) { spec->m_hasError = true; spec->m_errorString = tr("Cannot initializing plugin because dependency failed to load: %1\nReason: %2") @@ -251,7 +288,7 @@ bool CPluginManager::loadQueue(CPluginSpec *spec, QList &queue, } circularityCheckQueue.append(spec); // check if we have the dependencies - if (spec->getState() == State::Invalid || spec->getState() == State::Read) + if (spec->state() == State::Invalid || spec->state() == State::Read) { queue.append(spec); return false; diff --git a/code/nel/tools/3d/object_viewer_qt/src/extension_system/plugin_spec.cpp b/code/nel/tools/3d/object_viewer_qt/src/extension_system/plugin_spec.cpp index d77d90962..6e15e1181 100644 --- a/code/nel/tools/3d/object_viewer_qt/src/extension_system/plugin_spec.cpp +++ b/code/nel/tools/3d/object_viewer_qt/src/extension_system/plugin_spec.cpp @@ -40,6 +40,8 @@ CPluginSpec::CPluginSpec() m_vendor(""), m_description(""), m_state(State::Invalid), + m_enabled(true), + m_enabledStartup(true), m_hasError(false), m_errorString(""), m_plugin(0), @@ -82,12 +84,12 @@ QString CPluginSpec::fileName() const return m_fileName; } -IPlugin* CPluginSpec::plugin() const +IPlugin *CPluginSpec::plugin() const { return m_plugin; } -int CPluginSpec::getState() const +int CPluginSpec::state() const { return m_state; } @@ -124,6 +126,16 @@ bool CPluginSpec::setFileName(const QString &fileName) return true; } +void CPluginSpec::setEnabled(bool enabled) +{ + m_enabled = enabled; +} + +bool CPluginSpec::isEnabled() const +{ + return m_enabled; +} + bool CPluginSpec::loadLibrary() { if (m_hasError) @@ -259,6 +271,16 @@ void CPluginSpec::kill() m_state = State::Deleted; } +void CPluginSpec::setEnabledStartup(bool enabled) +{ + m_enabledStartup = enabled; +} + +bool CPluginSpec::isEnabledStartup() const +{ + return m_enabledStartup; +} + bool CPluginSpec::reportError(const QString &err) { m_errorString = err; diff --git a/code/nel/tools/3d/object_viewer_qt/src/extension_system/plugin_spec.h b/code/nel/tools/3d/object_viewer_qt/src/extension_system/plugin_spec.h index 0cc895ada..5d9605de7 100644 --- a/code/nel/tools/3d/object_viewer_qt/src/extension_system/plugin_spec.h +++ b/code/nel/tools/3d/object_viewer_qt/src/extension_system/plugin_spec.h @@ -41,11 +41,15 @@ public: virtual IPlugin *plugin() const; // state - virtual int getState() const; + virtual int state() const; virtual bool hasError() const; virtual QString errorString() const; QList dependencySpecs() const; + /// Enables/disables load this plugin after restart the program + virtual void setEnabled(bool enabled); + virtual bool isEnabled() const; + private: CPluginSpec(); @@ -57,6 +61,11 @@ private: void stop(); void kill(); + /// Enables/disables load this plugin on startup the program + /// Method is used for disabling startup plugin by pluginmanager + void setEnabledStartup(bool enabled); + bool isEnabledStartup() const; + bool reportError(const QString &err); QString m_location; @@ -69,6 +78,7 @@ private: QString m_description; int m_state; + bool m_enabled, m_enabledStartup; bool m_hasError; QString m_errorString; diff --git a/code/nel/tools/3d/object_viewer_qt/src/main.cpp b/code/nel/tools/3d/object_viewer_qt/src/main.cpp index 050b7716c..1ddcc5565 100644 --- a/code/nel/tools/3d/object_viewer_qt/src/main.cpp +++ b/code/nel/tools/3d/object_viewer_qt/src/main.cpp @@ -132,7 +132,7 @@ sint main(int argc, char **argv) QSettings::setDefaultFormat(QSettings::IniFormat); QSettings *settings = new QSettings(QSettings::IniFormat, QSettings::UserScope, - QLatin1String("RyzomCore"), QLatin1String(appNameC)); + QLatin1String("RyzomCore"), QLatin1String(appNameC)); QTranslator translator; QTranslator qtTranslator; @@ -162,17 +162,8 @@ sint main(int argc, char **argv) splash->hide(); - const QList plugins = pluginManager.plugins(); - ExtensionSystem::IPluginSpec *corePlugin = 0; - Q_FOREACH(ExtensionSystem::IPluginSpec *spec, plugins) - { - if (spec->name() == QLatin1String("Core")) - { - corePlugin = spec; - break; - } - } - + ExtensionSystem::IPluginSpec *corePlugin = pluginManager.pluginByName("Core"); + if (!corePlugin) { QDir absolutePluginPaths(pluginPaths.join(QLatin1String(","))); @@ -183,8 +174,8 @@ sint main(int argc, char **argv) QString newPath = QFileDialog::getExistingDirectory(0, QCoreApplication::translate("Application", "Change the plugins path"), QDir::homePath()); bool ok; QString text = QInputDialog::getText(0, QCoreApplication::translate("Application", "Enter the plugins path"), - QCoreApplication::translate("Application", "Plugin path:"), QLineEdit::Normal, - newPath, &ok); + QCoreApplication::translate("Application", "Plugin path:"), QLineEdit::Normal, + newPath, &ok); if (ok && !text.isEmpty()) settings->setValue("PluginPath", text); settings->sync(); @@ -203,7 +194,7 @@ sint main(int argc, char **argv) if (!errors.isEmpty()) QMessageBox::warning(0, QCoreApplication::translate("Application", "Object Viewer Qt - Plugin loader messages"), - errors.join(QString::fromLatin1("\n\n"))); + errors.join(QString::fromLatin1("\n\n"))); int result = app.exec(); return result; diff --git a/code/nel/tools/3d/object_viewer_qt/src/plugins/core/core_plugin.cpp b/code/nel/tools/3d/object_viewer_qt/src/plugins/core/core_plugin.cpp index 92e776068..8aef51f2a 100644 --- a/code/nel/tools/3d/object_viewer_qt/src/plugins/core/core_plugin.cpp +++ b/code/nel/tools/3d/object_viewer_qt/src/plugins/core/core_plugin.cpp @@ -37,6 +37,8 @@ using namespace Core; CorePlugin::CorePlugin() + : m_plugMan(0), + m_mainWindow(0) { } @@ -49,7 +51,8 @@ CorePlugin::~CorePlugin() qDeleteAll(m_autoReleaseObjects); m_autoReleaseObjects.clear(); - delete m_mainWindow; + if (m_mainWindow) + delete m_mainWindow; } bool CorePlugin::initialize(ExtensionSystem::IPluginManager *pluginManager, QString *errorString) diff --git a/code/nel/tools/3d/object_viewer_qt/src/plugins/core/main_window.cpp b/code/nel/tools/3d/object_viewer_qt/src/plugins/core/main_window.cpp index caaeb4d5c..2105b8b1b 100644 --- a/code/nel/tools/3d/object_viewer_qt/src/plugins/core/main_window.cpp +++ b/code/nel/tools/3d/object_viewer_qt/src/plugins/core/main_window.cpp @@ -107,8 +107,8 @@ bool MainWindow::initialize(QString *errorString) void MainWindow::extensionsInitialized() { readSettings(); - connect(m_contextManager, SIGNAL(currentContextChanged(Core::IContext*)), - this, SLOT(updateContext(Core::IContext*))); + connect(m_contextManager, SIGNAL(currentContextChanged(Core::IContext *)), + this, SLOT(updateContext(Core::IContext *))); if (m_contextManager->currentContext() != NULL) updateContext(m_contextManager->currentContext()); show(); @@ -437,7 +437,7 @@ void MainWindow::createStatusBar() void MainWindow::createDialogs() { - m_pluginView = new ExtensionSystem::CPluginView(m_pluginManager, this); + m_pluginView = new PluginView(m_pluginManager, this); // Create undo/redo command list m_dockWidget = new QDockWidget("Command List", this); diff --git a/code/nel/tools/3d/object_viewer_qt/src/plugins/core/main_window.h b/code/nel/tools/3d/object_viewer_qt/src/plugins/core/main_window.h index d594692ee..48ce93a15 100644 --- a/code/nel/tools/3d/object_viewer_qt/src/plugins/core/main_window.h +++ b/code/nel/tools/3d/object_viewer_qt/src/plugins/core/main_window.h @@ -93,7 +93,7 @@ private: void writeSettings(); ExtensionSystem::IPluginManager *m_pluginManager; - ExtensionSystem::CPluginView *m_pluginView; + PluginView *m_pluginView; MenuManager *m_menuManager; ContextManager *m_contextManager; CoreImpl *m_coreImpl; diff --git a/code/nel/tools/3d/object_viewer_qt/src/plugins/core/plugin_view_dialog.cpp b/code/nel/tools/3d/object_viewer_qt/src/plugins/core/plugin_view_dialog.cpp index b45d46418..175902d39 100644 --- a/code/nel/tools/3d/object_viewer_qt/src/plugins/core/plugin_view_dialog.cpp +++ b/code/nel/tools/3d/object_viewer_qt/src/plugins/core/plugin_view_dialog.cpp @@ -16,11 +16,12 @@ // along with this program. If not, see . #include "plugin_view_dialog.h" +#include "core_constants.h" + +#include "nel/misc/debug.h" // Qt includes #include -#include -#include #include #include #include @@ -29,45 +30,79 @@ #include "../../extension_system/iplugin_spec.h" #include "../../extension_system/iplugin_manager.h" -namespace ExtensionSystem +namespace Core { -CPluginView::CPluginView(IPluginManager *pluginManager, QWidget *parent) - : QDialog(parent) +PluginView::PluginView(ExtensionSystem::IPluginManager *pluginManager, QWidget *parent) + : QDialog(parent), + m_checkStateColumn(0) { - _ui.setupUi(this); - _pluginManager = pluginManager; + m_ui.setupUi(this); + m_pluginManager = pluginManager; - connect(_pluginManager, SIGNAL(pluginsChanged()), this, SLOT(updateList())); + connect(m_pluginManager, SIGNAL(pluginsChanged()), this, SLOT(updateList())); + connect(this, SIGNAL(accepted()), this, SLOT(updateSettings())); + // WhiteList is list of plugins which can not disable. + m_whiteList << Constants::OVQT_CORE_PLUGIN; updateList(); } -CPluginView::~CPluginView() +PluginView::~PluginView() { } -void CPluginView::updateList() +void PluginView::updateList() { static QIcon okIcon = QApplication::style()->standardIcon(QStyle::SP_DialogApplyButton); static QIcon errorIcon = QApplication::style()->standardIcon(QStyle::SP_DialogCancelButton); + static QIcon notLoadedIcon = QApplication::style()->standardIcon(QStyle::SP_DialogResetButton); + + m_specToItem.clear(); QList items; - Q_FOREACH (IPluginSpec *spec, _pluginManager->plugins()) + Q_FOREACH (ExtensionSystem::IPluginSpec *spec, m_pluginManager->plugins()) { QTreeWidgetItem *item = new QTreeWidgetItem(QStringList() - << "" << spec->name() << QString("%1").arg(spec->version()) << spec->vendor() << QDir::toNativeSeparators(spec->filePath())); - item->setIcon(0, spec->hasError() ? errorIcon : okIcon); + + bool ok = !spec->hasError(); + QIcon icon = ok ? okIcon : errorIcon; + if (ok && (spec->state() != ExtensionSystem::State::Running)) + icon = notLoadedIcon; + + item->setIcon(m_checkStateColumn, icon); + + if (!m_whiteList.contains(spec->name())) + item->setCheckState(m_checkStateColumn, spec->isEnabled() ? Qt::Checked : Qt::Unchecked); + items.append(item); + m_specToItem.insert(spec, item); } - _ui.pluginTreeWidget->clear(); + m_ui.pluginTreeWidget->clear(); if (!items.isEmpty()) - _ui.pluginTreeWidget->addTopLevelItems(items); + m_ui.pluginTreeWidget->addTopLevelItems(items); + + m_ui.pluginTreeWidget->resizeColumnToContents(m_checkStateColumn); } -} /* namespace NLQT */ \ No newline at end of file +void PluginView::updateSettings() +{ + Q_FOREACH (ExtensionSystem::IPluginSpec *spec, m_pluginManager->plugins()) + { + if (m_specToItem.contains(spec) && (!m_whiteList.contains(spec->name()))) + { + QTreeWidgetItem *item = m_specToItem.value(spec); + if (item->checkState(m_checkStateColumn) == Qt::Checked) + spec->setEnabled(true); + else + spec->setEnabled(false); + } + } +} + +} /* namespace Core */ \ No newline at end of file diff --git a/code/nel/tools/3d/object_viewer_qt/src/plugins/core/plugin_view_dialog.h b/code/nel/tools/3d/object_viewer_qt/src/plugins/core/plugin_view_dialog.h index 0f12b64a3..aae16749d 100644 --- a/code/nel/tools/3d/object_viewer_qt/src/plugins/core/plugin_view_dialog.h +++ b/code/nel/tools/3d/object_viewer_qt/src/plugins/core/plugin_view_dialog.h @@ -20,28 +20,39 @@ #include "ui_plugin_view_dialog.h" +#include +#include + namespace ExtensionSystem { - class IPluginManager; +class IPluginSpec; +} -class CPluginView: public QDialog +namespace Core +{ + +class PluginView: public QDialog { Q_OBJECT public: - CPluginView(IPluginManager *pluginManager, QWidget *parent = 0); - ~CPluginView(); + PluginView(ExtensionSystem::IPluginManager *pluginManager, QWidget *parent = 0); + ~PluginView(); private Q_SLOTS: void updateList(); + void updateSettings(); private: - IPluginManager *_pluginManager; - Ui::CPluginView _ui; -}; /* class CPluginView */ + const int m_checkStateColumn; + QMap m_specToItem; + QStringList m_whiteList; + ExtensionSystem::IPluginManager *m_pluginManager; + Ui::PluginView m_ui; +}; /* class PluginView */ -} /* namespace NLQT */ +} /* namespace Core */ #endif // PLUGIN_VIEW_H diff --git a/code/nel/tools/3d/object_viewer_qt/src/plugins/core/plugin_view_dialog.ui b/code/nel/tools/3d/object_viewer_qt/src/plugins/core/plugin_view_dialog.ui index 2fb0f568e..60a9b9c46 100644 --- a/code/nel/tools/3d/object_viewer_qt/src/plugins/core/plugin_view_dialog.ui +++ b/code/nel/tools/3d/object_viewer_qt/src/plugins/core/plugin_view_dialog.ui @@ -1,13 +1,13 @@ - CPluginView - + PluginView + 0 0 - 691 - 249 + 756 + 296 @@ -37,14 +37,6 @@ true - - 100 - - - - State - - Name @@ -126,7 +118,7 @@ closePushButton clicked() - CPluginView + PluginView accept()