Changed: #1206 Settings are located in a centralized place(plugin manager). Update core and example plugin.

This commit is contained in:
dnk-88 2011-02-12 18:07:05 +02:00
parent d306700e6e
commit 8b03a1d829
13 changed files with 142 additions and 97 deletions

View file

@ -183,7 +183,7 @@ CCameraControl::CCameraControl(QWidget *parent)
CCameraControl::~CCameraControl()
{
for(int i = 0; i < _cameraList.size(); ++i)
for(size_t i = 0; i < _cameraList.size(); ++i)
delete _cameraList[i];
_cameraList.clear();
}

View file

@ -23,16 +23,17 @@
#include <QtCore/QList>
#include <QtCore/QObject>
#include <QtCore/QStringList>
#include <QtCore/QSettings>
namespace ExtensionSystem
{
class IPluginSpec;
/**
@interface IPluginManager
@brief Interface for plugin system that manages the plugins, their life cycle and their registered objects.
@details The plugin manager is used for the following tasks:
- Manage plugins and their state
@interface IPluginManager
@brief Interface for plugin system that manages the plugins, their life cycle and their registered objects.
@details The plugin manager is used for the following tasks:
- Manage plugins and their state
- Manipulate a 'common object pool'
*/
class IPluginManager: public QObject
@ -53,6 +54,10 @@ public:
virtual QStringList getPluginPaths() const = 0;
virtual void setPluginPaths(const QStringList &paths) = 0;
virtual QList<ExtensionSystem::IPluginSpec *> plugins() const = 0;
// Settings
virtual void setSettings(QSettings *settings) = 0;
virtual QSettings *settings() const = 0;
Q_SIGNALS:
void objectAdded(QObject *obj);

View file

@ -28,14 +28,16 @@
namespace ExtensionSystem
{
CPluginManager::CPluginManager(QObject *parent):
IPluginManager(parent)
CPluginManager::CPluginManager(QObject *parent)
:IPluginManager(parent),
_settings(0)
{
}
CPluginManager::~CPluginManager()
{
stopAll();
deleteAll();
qDeleteAll(_pluginSpecs);
}
@ -92,8 +94,10 @@ void CPluginManager::loadPlugins()
Q_FOREACH (CPluginSpec *spec, _pluginSpecs)
setPluginState(spec, State::Initialized);
Q_FOREACH (CPluginSpec *spec, _pluginSpecs)
setPluginState(spec, State::Running);
QListIterator<CPluginSpec *> it(_pluginSpecs);
it.toBack();
while (it.hasPrevious())
setPluginState(it.previous(), State::Running);
Q_EMIT pluginsChanged();
}
@ -114,6 +118,24 @@ QList<IPluginSpec *> CPluginManager::plugins() const
return _ipluginSpecs;
}
void CPluginManager::setSettings(QSettings *settings)
{
_settings = settings;
}
QSettings *CPluginManager::settings() const
{
return _settings;
}
void CPluginManager::readSettings()
{
}
void CPluginManager::writeSettings()
{
}
void CPluginManager::readPluginPaths()
{
qDeleteAll(_pluginSpecs);
@ -176,9 +198,16 @@ void CPluginManager::stopAll()
{
Q_FOREACH (CPluginSpec *spec, _pluginSpecs)
setPluginState(spec, State::Stopped);
}
Q_FOREACH (CPluginSpec *spec, _pluginSpecs)
setPluginState(spec, State::Deleted);
void CPluginManager::deleteAll()
{
QListIterator<CPluginSpec *> it(_pluginSpecs);
it.toBack();
while (it.hasPrevious())
{
setPluginState(it.previous(), State::Deleted);
}
}
}; // namespace NLQT

View file

@ -50,14 +50,22 @@ public:
virtual QStringList getPluginPaths() const;
virtual void setPluginPaths(const QStringList &paths);
virtual QList<IPluginSpec *> plugins() const;
// Settings
virtual void setSettings(QSettings *settings);
virtual QSettings *settings() const;
void readSettings();
void writeSettings();
private:
void setPluginState(CPluginSpec *spec, int destState);
void readPluginPaths();
void stopAll();
void deleteAll();
mutable QReadWriteLock _lock;
QSettings *_settings;
QList<CPluginSpec *> _pluginSpecs;
QList<IPluginSpec *> _ipluginSpecs;
QStringList _pluginPaths;

View file

@ -21,6 +21,7 @@
// Qt includes
#include <QtCore/QDir>
#include <QtCore/QSettings>
#include <QtGui/QMessageBox>
#include <QtGui/QApplication>
#include <QtGui/QSplashScreen>
@ -112,11 +113,14 @@ sint main(int argc, char **argv)
#if defined(NL_OS_MAC)
QDir::setCurrent(qApp->applicationDirPath() + QString("/../Resources"));
CLibrary::addLibPath(
(qApp->applicationDirPath() + QString("/../PlugIns/nel")).toStdString());
CLibrary::addLibPath((qApp->applicationDirPath() + QString("/../PlugIns/nel")).toStdString());
#endif
Modules::init();
QSettings *settings = new QSettings(QSettings::IniFormat, QSettings::UserScope,
QLatin1String("Ryzom Core"), QLatin1String("ObjectViewerQt"));
Modules::plugMan().setSettings(settings);
// load and set remap extensions from config
Modules::config().configRemapExtensions();
@ -129,21 +133,20 @@ sint main(int argc, char **argv)
#if !defined(NL_OS_MAC)
Modules::plugMan().setPluginPaths(QStringList() << QString("./plugins"));
#else
Modules::plugMan().setPluginPaths(QStringList() <<
qApp->applicationDirPath() + QString("/../PlugIns/ovqt"));
Modules::plugMan().setPluginPaths(QStringList() <<
qApp->applicationDirPath() + QString("/../PlugIns/ovqt"));
#endif
Modules::plugMan().loadPlugins();
QStringList errors;
Q_FOREACH (ExtensionSystem::IPluginSpec *spec, Modules::plugMan().plugins())
if (spec->hasError())
errors.append(spec->fileName() + " : " + spec->errorString());
if (spec->hasError())
errors.append(spec->fileName() + " : " + spec->errorString());
if (!errors.isEmpty())
QMessageBox::warning(0,
QCoreApplication::translate("Application", "Object Viewer Qt - Plugin loader messages"),
errors.join(QString::fromLatin1("\n\n")));
QMessageBox::warning(0, QCoreApplication::translate("Application", "Object Viewer Qt - Plugin loader messages"),
errors.join(QString::fromLatin1("\n\n")));
splash->finish(&Modules::mainWin());
int result = app.exec();

View file

@ -40,59 +40,64 @@ bool CorePlugin::initialize(ExtensionSystem::IPluginManager *pluginManager, QStr
{
Q_UNUSED(errorString);
_plugMan = pluginManager;
// for old ovqt
QMainWindow *wnd = qobject_cast<QMainWindow *>(objectByName("CMainWindow"));
if (!wnd)
{
*errorString = tr("Not found QMainWindow Object Viewer Qt.");
return false;
}
oldOVQT = false;
_plugMan->addObject(new CSearchPathsSettingsPage(wnd));
_plugMan->addObject(new CSearchPathsSettingsPage(this));
return true;
}
void CorePlugin::extensionsInitialized()
{
// for old ovqt
_pluginView = new ExtensionSystem::CPluginView(_plugMan);
QMenu *toolsMenu = qobject_cast<QMenu *>(objectByName("ovqt.Menu.Tools"));
QMenu *helpMenu = qobject_cast<QMenu *>(objectByName("ovqt.Menu.Help"));
nlassert(toolsMenu);
nlassert(helpMenu);
QAction *newAction = toolsMenu->addAction(tr("New settings"));
QAction *newAction2 = helpMenu->addAction(tr("About plugins"));
newAction->setIcon(QIcon(Constants::ICON_SETTINGS));
connect(newAction, SIGNAL(triggered()), this, SLOT(execSettings()));
connect(newAction2, SIGNAL(triggered()), _pluginView, SLOT(show()));
_mainWindow = new CMainWindow(_plugMan);
#ifdef Q_WS_X11
_mainWindow->setAttribute(Qt::WA_TranslucentBackground);
_mainWindow->setAttribute(Qt::WA_NoSystemBackground, false);
QPalette pal = _mainWindow->palette();
QColor bg = pal.window().color();
bg.setAlpha(180);
pal.setColor(QPalette::Window, bg);
_mainWindow->setPalette(pal);
_mainWindow->ensurePolished(); // workaround Oxygen filling the background
_mainWindow->setAttribute(Qt::WA_StyledBackground, false);
#endif
if (QtWin::isCompositionEnabled())
// for old ovqt
QMainWindow *wnd = qobject_cast<QMainWindow *>(objectByName("CMainWindow"));
if (wnd)
{
QtWin::extendFrameIntoClientArea(_mainWindow);
_mainWindow->setContentsMargins(0, 0, 0, 0);
_pluginView = new ExtensionSystem::CPluginView(_plugMan);
QMenu *toolsMenu = qobject_cast<QMenu *>(objectByName("ovqt.Menu.Tools"));
QMenu *helpMenu = qobject_cast<QMenu *>(objectByName("ovqt.Menu.Help"));
nlassert(toolsMenu);
nlassert(helpMenu);
QAction *newAction = toolsMenu->addAction(tr("New settings"));
QAction *newAction2 = helpMenu->addAction(tr("About plugins"));
newAction->setIcon(QIcon(Constants::ICON_SETTINGS));
connect(newAction, SIGNAL(triggered()), this, SLOT(execSettings()));
connect(newAction2, SIGNAL(triggered()), _pluginView, SLOT(show()));
oldOVQT = true;
}
else
{
_mainWindow = new CMainWindow(_plugMan);
#ifdef Q_WS_X11
_mainWindow->setAttribute(Qt::WA_TranslucentBackground);
_mainWindow->setAttribute(Qt::WA_NoSystemBackground, false);
QPalette pal = _mainWindow->palette();
QColor bg = pal.window().color();
bg.setAlpha(180);
pal.setColor(QPalette::Window, bg);
_mainWindow->setPalette(pal);
_mainWindow->ensurePolished(); // workaround Oxygen filling the background
_mainWindow->setAttribute(Qt::WA_StyledBackground, false);
#endif
if (QtWin::isCompositionEnabled())
{
QtWin::extendFrameIntoClientArea(_mainWindow);
_mainWindow->setContentsMargins(0, 0, 0, 0);
}
_mainWindow->show();
}
_mainWindow->show();
}
void CorePlugin::shutdown()
{
delete _mainWindow;
delete _pluginView;
if (!oldOVQT)
{
delete _mainWindow;
delete _pluginView;
}
}
void CorePlugin::execSettings()

View file

@ -58,6 +58,21 @@ public:
QObject *objectByName(const QString &name) const;
ExtensionSystem::IPluginSpec *pluginByName(const QString &name) const;
ExtensionSystem::IPluginManager *pluginManager() const { return _plugMan; }
template <typename Type>
QList<Type *> getObjects() const
{
QList<QObject *> all = _plugMan->allObjects();
QList<Type *> objects;
Q_FOREACH(QObject *obj, all)
{
Type *typeObj = qobject_cast<Type *>(obj);
if (typeObj)
objects.append(typeObj);
}
return objects;
}
protected:
NLMISC::CLibraryContext *_LibContext;
@ -69,6 +84,8 @@ private:
ExtensionSystem::IPluginManager *_plugMan;
ExtensionSystem::CPluginView *_pluginView;
CMainWindow *_mainWindow;
bool oldOVQT;
};
} // namespace Core

View file

@ -96,6 +96,11 @@ void CMainWindow::about()
"<p> Author: dnk-88 <p>Compiled on %1 %2").arg(__DATE__).arg(__TIME__));
}
void CMainWindow::closeEvent(QCloseEvent *event)
{
QMainWindow::closeEvent(event);
}
void CMainWindow::createActions()
{
_openAction = new QAction(tr("&Open..."), this);

View file

@ -50,6 +50,8 @@ private Q_SLOTS:
const QString &page = QString(),
QWidget *parent = 0);
void about();
protected:
virtual void closeEvent(QCloseEvent *event);
private:
void createActions();

View file

@ -15,7 +15,7 @@
</property>
<layout class="QGridLayout" name="gridLayout">
<property name="margin">
<number>9</number>
<number>0</number>
</property>
<item row="0" column="0">
<widget class="QGroupBox" name="searchPathsGroupBox">

View file

@ -14,6 +14,9 @@
<string>Form</string>
</property>
<layout class="QGridLayout" name="gridLayout_2">
<property name="margin">
<number>0</number>
</property>
<item row="0" column="0" colspan="2">
<widget class="QGroupBox" name="groupBox">
<property name="title">

View file

@ -24,42 +24,13 @@ bool MyPlugin::initialize(ExtensionSystem::IPluginManager *pluginManager, QStrin
Q_UNUSED(errorString);
_plugMan = pluginManager;
QMainWindow *wnd = qobject_cast<QMainWindow *>(objectByName("CMainWindow"));
_plugMan->addObject(new CExampleSettingsPage(wnd));
if (!wnd)
{
*errorString = tr("Not found QMainWindow Object Viewer Qt.");
return false;
}
QMenu *helpMenu = qobject_cast<QMenu *>(objectByName("ovqt.Menu.Tools"));
if (!helpMenu)
{
*errorString = tr("Not found QMenu Help.");
return false;
}
_plugMan->addObject(new CExampleAppPage());
_plugMan->addObject(new CExampleSettingsPage(this));
_plugMan->addObject(new CExampleAppPage(this));
return true;
}
void MyPlugin::extensionsInitialized()
{
QMenu *helpMenu = qobject_cast<QMenu *>(objectByName("ovqt.Menu.Help"));
nlassert(helpMenu);
helpMenu->addSeparator();
QAction *newAction = helpMenu->addAction("MyPlugin");
connect(newAction, SIGNAL(triggered()), this, SLOT(execMessageBox()));
}
void MyPlugin::execMessageBox()
{
QMainWindow *wnd = qobject_cast<QMainWindow *>(objectByName("CMainWindow"));
nlassert(wnd);
QMessageBox msgBox;
msgBox.setText(wnd->objectName() + QString(": width=%1,height=%2").arg(wnd->width()).arg(wnd->height()));
msgBox.exec();
}
void MyPlugin::setNelContext(NLMISC::INelContext *nelContext)

View file

@ -46,9 +46,6 @@ public:
QObject *objectByName(const QString &name) const;
ExtensionSystem::IPluginSpec *pluginByName(const QString &name) const;
private Q_SLOTS:
void execMessageBox();
protected:
NLMISC::CLibraryContext *_LibContext;