2 ******************************************************************************
4 * @file pluginmanager.h
5 * @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2010.
6 * Parts by Nokia Corporation (qt-info@nokia.com) Copyright (C) 2009.
8 * @see The GNU Public License (GPL) Version 3
12 *****************************************************************************/
14 * This program is free software; you can redistribute it and/or modify
15 * it under the terms of the GNU General Public License as published by
16 * the Free Software Foundation; either version 3 of the License, or
17 * (at your option) any later version.
19 * This program is distributed in the hope that it will be useful, but
20 * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
21 * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
24 * You should have received a copy of the GNU General Public License along
25 * with this program; if not, write to the Free Software Foundation, Inc.,
26 * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
29 #ifndef EXTENSIONSYSTEM_PLUGINMANAGER_H
30 #define EXTENSIONSYSTEM_PLUGINMANAGER_H
32 #include "extensionsystem_global.h"
33 #include <aggregation/aggregate.h>
35 #include <QtCore/QObject>
36 #include <QtCore/QStringList>
37 #include <QtCore/QReadWriteLock>
43 namespace ExtensionSystem
{
45 class PluginManagerPrivate
;
51 class EXTENSIONSYSTEM_EXPORT PluginManager
: public QObject
{
52 Q_DISABLE_COPY(PluginManager
)
56 static PluginManager
*instance();
57 bool allPluginsLoaded()
59 return m_allPluginsLoaded
;
62 virtual ~PluginManager();
64 // Object pool operations
65 void addObject(QObject
*obj
);
66 void removeObject(QObject
*obj
);
67 QList
<QObject
*> allObjects() const;
68 template <typename T
> QList
<T
*> getObjects() const
70 QReadLocker
lock(&m_lock
);
73 QList
<QObject
*> all
= allObjects();
75 foreach(QObject
* obj
, all
) {
76 result
= Aggregation::query_all
<T
>(obj
);
77 if (!result
.isEmpty()) {
83 template <typename T
> T
*getObject() const
85 QReadLocker
lock(&m_lock
);
87 QList
<QObject
*> all
= allObjects();
89 foreach(QObject
* obj
, all
) {
90 if ((result
= Aggregation::query
<T
>(obj
)) != 0) {
99 QStringList
pluginPaths() const;
100 void setPluginPaths(const QStringList
&paths
);
101 QList
<PluginSpec
*> plugins() const;
102 void setFileExtension(const QString
&extension
);
103 QString
fileExtension() const;
105 // command line arguments
106 QStringList
arguments() const;
107 bool parseOptions(const QStringList
&args
,
108 const QMap
<QString
, bool> &appOptions
,
109 QMap
<QString
, QString
> *foundAppOptions
,
110 QString
*errorString
);
111 static void formatOptions(QTextStream
&str
, int optionIndentation
, int descriptionIndentation
);
112 void formatPluginOptions(QTextStream
&str
, int optionIndentation
, int descriptionIndentation
) const;
113 void formatPluginVersions(QTextStream
&str
) const;
115 bool runningTests() const;
116 QString
testDataDirectory() const;
119 void objectAdded(QObject
*obj
);
120 void aboutToRemoveObject(QObject
*obj
);
122 void pluginAboutToBeLoaded(ExtensionSystem::PluginSpec
*pluginSpec
);
123 void pluginsChanged();
124 void pluginsLoadEnded();
129 Internal::PluginManagerPrivate
*d
;
130 static PluginManager
*m_instance
;
131 mutable QReadWriteLock m_lock
;
132 bool m_allPluginsLoaded
;
134 friend class Internal::PluginManagerPrivate
;
136 } // namespace ExtensionSystem
138 #endif // EXTENSIONSYSTEM_PLUGINMANAGER_H