Fix
[ryzomcore.git] / studio / src / extension_system / iplugin_manager.h
blob41c3e93b5c87617f5b3e30669ae91df325514c75
1 // Object Viewer Qt - MMORPG Framework <http://dev.ryzom.com/projects/nel/>
2 // Copyright (C) 2010-2011 Dzmitry KAMIAHIN (dnk-88) <dnk-88@tut.by>
3 //
4 // This source file has been modified by the following contributors:
5 // Copyright (C) 2010 Winch Gate Property Limited
6 // Copyright (C) 2014 Laszlo KIS-ADAM (dfighter) <dfighter1985@gmail.com>
7 //
8 // This program is free software: you can redistribute it and/or modify
9 // it under the terms of the GNU Affero General Public License as
10 // published by the Free Software Foundation, either version 3 of the
11 // License, or (at your option) any later version.
13 // This program is distributed in the hope that it will be useful,
14 // but WITHOUT ANY WARRANTY; without even the implied warranty of
15 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 // GNU Affero General Public License for more details.
18 // You should have received a copy of the GNU Affero General Public License
19 // along with this program. If not, see <http://www.gnu.org/licenses/>.
21 #ifndef IPLUGINMANAGER_H
22 #define IPLUGINMANAGER_H
24 #include "iplugin_spec.h"
26 #include <QtCore/QList>
27 #include <QtCore/QObject>
28 #include <QtCore/QStringList>
29 #include <QtCore/QSettings>
31 namespace ExtensionSystem
33 class IPluginSpec;
35 /**
36 @interface IPluginManager
37 @brief Interface for plugin system that manages the plugins, their life cycle and their registered objects.
38 @details The plugin manager is used for the following tasks:
39 - Manage plugins and their state
40 - Manipulate a 'common object pool'
42 class IPluginManager: public QObject
44 Q_OBJECT
45 public:
46 IPluginManager(QObject *parent = 0): QObject(parent) {}
47 virtual ~IPluginManager() {}
49 // Object pool operations
50 virtual void addObject(QObject *obj) = 0;
51 virtual void removeObject(QObject *obj) = 0;
52 virtual QList<QObject *> allObjects() const = 0;
54 // Plugin operations
55 virtual void loadPlugins() = 0;
56 virtual QStringList getPluginPaths() const = 0;
57 virtual void setPluginPaths(const QStringList &paths) = 0;
58 virtual QList<ExtensionSystem::IPluginSpec *> plugins() const = 0;
60 virtual bool loadPlugin( const QString &plugin ) = 0;
61 virtual bool unloadPlugin( ExtensionSystem::IPluginSpec *plugin ) = 0;
63 // Settings
64 virtual void setSettings(QSettings *settings) = 0;
65 virtual QSettings *settings() const = 0;
67 // Auxiliary operations
69 /// Retrieve all objects of a given type from the object pool.
70 template <typename T>
71 QList<T *> getObjects() const
73 QList<QObject *> all = allObjects();
74 QList<T *> objects;
75 Q_FOREACH(QObject *obj, all)
77 T *tObj = qobject_cast<T *>(obj);
78 if (tObj)
79 objects.append(tObj);
81 return objects;
84 /// Retrieve the object of a given type from the object pool.
85 template <typename T>
86 T *getObject() const
88 QList<QObject *> all = allObjects();
89 T *result = 0;
90 Q_FOREACH(QObject *obj, all)
92 T *tObj = qobject_cast<T *>(obj);
93 if (tObj)
95 result = tObj;
96 break;
99 return result;
102 QObject *objectByName(const QString &name) const
104 QList<QObject *> all = allObjects();
105 QObject *result = 0;
106 Q_FOREACH(QObject *qobj, all)
108 if (qobj->objectName() == name)
110 result = qobj;
111 break;
114 return result;
117 ExtensionSystem::IPluginSpec *pluginByName(const QString &name) const
119 QList<ExtensionSystem::IPluginSpec *> all = plugins();
120 ExtensionSystem::IPluginSpec *result = 0;
121 Q_FOREACH (ExtensionSystem::IPluginSpec *spec, all)
123 if (spec->name() == name)
125 result = spec;
126 break;
129 return result;
132 Q_SIGNALS:
133 /// Signal that \a obj has been added to the object pool.
134 void objectAdded(QObject *obj);
136 /// Signal that \a obj will be removed from the object pool.
137 void aboutToRemoveObject(QObject *obj);
139 /// Signal that the list of available plugins has changed.
140 void pluginsChanged();
142 void pluginCount( int count );
144 void pluginLoading( const char *plugin );
145 void pluginInitializing( const char *plugin );
146 void pluginStarting( const char *plugin );
148 void pluginsLoaded();
149 void pluginsInitialized();
150 void pluginsStarted();
153 }; // namespace ExtensionSystem
155 #endif // IPLUGINMANAGER_H