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 7f0ab6e48c
commit c7b860c0f6
13 changed files with 142 additions and 97 deletions

View file

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

View file

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

View file

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

View file

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

View file

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

View file

@ -40,59 +40,64 @@ bool CorePlugin::initialize(ExtensionSystem::IPluginManager *pluginManager, QStr
{ {
Q_UNUSED(errorString); Q_UNUSED(errorString);
_plugMan = pluginManager; _plugMan = pluginManager;
// for old ovqt oldOVQT = false;
QMainWindow *wnd = qobject_cast<QMainWindow *>(objectByName("CMainWindow"));
if (!wnd)
{
*errorString = tr("Not found QMainWindow Object Viewer Qt.");
return false;
}
_plugMan->addObject(new CSearchPathsSettingsPage(wnd)); _plugMan->addObject(new CSearchPathsSettingsPage(this));
return true; return true;
} }
void CorePlugin::extensionsInitialized() void CorePlugin::extensionsInitialized()
{ {
// for old ovqt
_pluginView = new ExtensionSystem::CPluginView(_plugMan); _pluginView = new ExtensionSystem::CPluginView(_plugMan);
QMenu *toolsMenu = qobject_cast<QMenu *>(objectByName("ovqt.Menu.Tools")); // for old ovqt
QMenu *helpMenu = qobject_cast<QMenu *>(objectByName("ovqt.Menu.Help")); QMainWindow *wnd = qobject_cast<QMainWindow *>(objectByName("CMainWindow"));
nlassert(toolsMenu); if (wnd)
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())
{ {
QtWin::extendFrameIntoClientArea(_mainWindow); _pluginView = new ExtensionSystem::CPluginView(_plugMan);
_mainWindow->setContentsMargins(0, 0, 0, 0); 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() void CorePlugin::shutdown()
{ {
delete _mainWindow; if (!oldOVQT)
delete _pluginView; {
delete _mainWindow;
delete _pluginView;
}
} }
void CorePlugin::execSettings() void CorePlugin::execSettings()

View file

@ -58,6 +58,21 @@ public:
QObject *objectByName(const QString &name) const; QObject *objectByName(const QString &name) const;
ExtensionSystem::IPluginSpec *pluginByName(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: protected:
NLMISC::CLibraryContext *_LibContext; NLMISC::CLibraryContext *_LibContext;
@ -69,6 +84,8 @@ private:
ExtensionSystem::IPluginManager *_plugMan; ExtensionSystem::IPluginManager *_plugMan;
ExtensionSystem::CPluginView *_pluginView; ExtensionSystem::CPluginView *_pluginView;
CMainWindow *_mainWindow; CMainWindow *_mainWindow;
bool oldOVQT;
}; };
} // namespace Core } // namespace Core

View file

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

View file

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

View file

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

View file

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

View file

@ -24,42 +24,13 @@ bool MyPlugin::initialize(ExtensionSystem::IPluginManager *pluginManager, QStrin
Q_UNUSED(errorString); Q_UNUSED(errorString);
_plugMan = pluginManager; _plugMan = pluginManager;
QMainWindow *wnd = qobject_cast<QMainWindow *>(objectByName("CMainWindow")); _plugMan->addObject(new CExampleSettingsPage(this));
_plugMan->addObject(new CExampleSettingsPage(wnd)); _plugMan->addObject(new CExampleAppPage(this));
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());
return true; return true;
} }
void MyPlugin::extensionsInitialized() 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) void MyPlugin::setNelContext(NLMISC::INelContext *nelContext)

View file

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