mirror of
https://port.numenaute.org/aleajactaest/khanat-opennel-code.git
synced 2024-12-23 09:28:45 +00:00
Changed: #1193 Added the feature of enable/disable plugins on startup program.
This commit is contained in:
parent
ac60393862
commit
4af62dfa63
13 changed files with 171 additions and 66 deletions
|
@ -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
|
||||
|
|
|
@ -98,7 +98,7 @@ public:
|
|||
{
|
||||
QList<QObject *> all = allObjects();
|
||||
QObject *result = 0;
|
||||
Q_FOREACH (QObject *qobj, all)
|
||||
Q_FOREACH(QObject *qobj, all)
|
||||
{
|
||||
if (qobj->objectName() == name)
|
||||
{
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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<IPluginSpec *> 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<CPluginSpec *> &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;
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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<CPluginSpec *> 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;
|
||||
|
||||
|
|
|
@ -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<ExtensionSystem::IPluginSpec *> 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;
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -16,11 +16,12 @@
|
|||
// along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
#include "plugin_view_dialog.h"
|
||||
#include "core_constants.h"
|
||||
|
||||
#include "nel/misc/debug.h"
|
||||
|
||||
// Qt includes
|
||||
#include <QtCore/QDir>
|
||||
#include <QtCore/QString>
|
||||
#include <QtCore/QStringList>
|
||||
#include <QtGui/QIcon>
|
||||
#include <QtGui/QStyle>
|
||||
#include <QtGui/QTreeWidgetItem>
|
||||
|
@ -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<QTreeWidgetItem *> 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 */
|
||||
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 */
|
|
@ -20,28 +20,39 @@
|
|||
|
||||
#include "ui_plugin_view_dialog.h"
|
||||
|
||||
#include <QtCore/QMap>
|
||||
#include <QtCore/QStringList>
|
||||
|
||||
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<ExtensionSystem::IPluginSpec *, QTreeWidgetItem *> m_specToItem;
|
||||
QStringList m_whiteList;
|
||||
ExtensionSystem::IPluginManager *m_pluginManager;
|
||||
Ui::PluginView m_ui;
|
||||
}; /* class PluginView */
|
||||
|
||||
} /* namespace NLQT */
|
||||
} /* namespace Core */
|
||||
|
||||
#endif // PLUGIN_VIEW_H
|
||||
|
|
|
@ -1,13 +1,13 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<ui version="4.0">
|
||||
<class>CPluginView</class>
|
||||
<widget class="QDialog" name="CPluginView">
|
||||
<class>PluginView</class>
|
||||
<widget class="QDialog" name="PluginView">
|
||||
<property name="geometry">
|
||||
<rect>
|
||||
<x>0</x>
|
||||
<y>0</y>
|
||||
<width>691</width>
|
||||
<height>249</height>
|
||||
<width>756</width>
|
||||
<height>296</height>
|
||||
</rect>
|
||||
</property>
|
||||
<property name="windowTitle">
|
||||
|
@ -37,14 +37,6 @@
|
|||
<property name="sortingEnabled">
|
||||
<bool>true</bool>
|
||||
</property>
|
||||
<attribute name="headerDefaultSectionSize">
|
||||
<number>100</number>
|
||||
</attribute>
|
||||
<column>
|
||||
<property name="text">
|
||||
<string>State</string>
|
||||
</property>
|
||||
</column>
|
||||
<column>
|
||||
<property name="text">
|
||||
<string>Name</string>
|
||||
|
@ -126,7 +118,7 @@
|
|||
<connection>
|
||||
<sender>closePushButton</sender>
|
||||
<signal>clicked()</signal>
|
||||
<receiver>CPluginView</receiver>
|
||||
<receiver>PluginView</receiver>
|
||||
<slot>accept()</slot>
|
||||
<hints>
|
||||
<hint type="sourcelabel">
|
||||
|
|
Loading…
Reference in a new issue