pluginmanager.h 4.59 KB
Newer Older
1
/**************************************************************************
con's avatar
con committed
2 3 4
**
** This file is part of Qt Creator
**
hjk's avatar
hjk committed
5
** Copyright (c) 2012 Nokia Corporation and/or its subsidiary(-ies).
con's avatar
con committed
6
**
Eike Ziller's avatar
Eike Ziller committed
7
** Contact: http://www.qt-project.org/
con's avatar
con committed
8
**
9
**
10
** GNU Lesser General Public License Usage
11
**
hjk's avatar
hjk committed
12 13 14 15 16 17
** This file may be used under the terms of the GNU Lesser General Public
** License version 2.1 as published by the Free Software Foundation and
** appearing in the file LICENSE.LGPL included in the packaging of this file.
** Please review the following information to ensure the GNU Lesser General
** Public License version 2.1 requirements will be met:
** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
18
**
con's avatar
con committed
19
** In addition, as a special exception, Nokia gives you certain additional
hjk's avatar
hjk committed
20
** rights. These rights are described in the Nokia Qt LGPL Exception
con's avatar
con committed
21 22
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
**
hjk's avatar
hjk committed
23 24 25 26 27
** Other Usage
**
** Alternatively, this file may be used in accordance with the terms and
** conditions contained in a signed written agreement between you and Nokia.
**
con's avatar
con committed
28
**
29
**************************************************************************/
hjk's avatar
hjk committed
30

con's avatar
con committed
31 32 33 34 35 36
#ifndef EXTENSIONSYSTEM_PLUGINMANAGER_H
#define EXTENSIONSYSTEM_PLUGINMANAGER_H

#include "extensionsystem_global.h"
#include <aggregation/aggregate.h>

37 38 39
#include <QObject>
#include <QReadWriteLock>
#include <QStringList>
con's avatar
con committed
40 41 42

QT_BEGIN_NAMESPACE
class QTextStream;
43
class QSettings;
con's avatar
con committed
44 45 46
QT_END_NAMESPACE

namespace ExtensionSystem {
47
class PluginCollection;
hjk's avatar
hjk committed
48

con's avatar
con committed
49
namespace Internal {
hjk's avatar
hjk committed
50
class PluginManagerPrivate;
con's avatar
con committed
51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66
}

class IPlugin;
class PluginSpec;

class EXTENSIONSYSTEM_EXPORT PluginManager : public QObject
{
    Q_OBJECT

public:
    static PluginManager *instance();

    PluginManager();
    virtual ~PluginManager();

    // Object pool operations
67 68 69 70
    static void addObject(QObject *obj);
    static void removeObject(QObject *obj);
    static QList<QObject *> allObjects();
    template <typename T> static QList<T *> getObjects()
con's avatar
con committed
71
    {
72
        QReadLocker lock(&m_instance->m_lock);
con's avatar
con committed
73 74 75 76 77 78 79 80 81 82
        QList<T *> results;
        QList<QObject *> all = allObjects();
        QList<T *> result;
        foreach (QObject *obj, all) {
            result = Aggregation::query_all<T>(obj);
            if (!result.isEmpty())
                results += result;
        }
        return results;
    }
83
    template <typename T> static T *getObject()
con's avatar
con committed
84
    {
85
        QReadLocker lock(&m_instance->m_lock);
con's avatar
con committed
86 87 88 89 90 91 92 93 94
        QList<QObject *> all = allObjects();
        T *result = 0;
        foreach (QObject *obj, all) {
            if ((result = Aggregation::query<T>(obj)) != 0)
                break;
        }
        return result;
    }

95 96
    static QObject *getObjectByName(const QString &name);
    static QObject *getObjectByClassName(const QString &className);
97

con's avatar
con committed
98
    // Plugin operations
99 100 101 102 103 104 105 106 107
    static QList<PluginSpec *> loadQueue();
    static void loadPlugins();
    static QStringList pluginPaths();
    static void setPluginPaths(const QStringList &paths);
    static QList<PluginSpec *> plugins();
    static QHash<QString, PluginCollection *> pluginCollections();
    static void setFileExtension(const QString &extension);
    static QString fileExtension();
    static bool hasError();
con's avatar
con committed
108

109
    // Settings
110 111 112 113 114
    static void setSettings(QSettings *settings);
    static QSettings *settings();
    static void setGlobalSettings(QSettings *settings);
    static QSettings *globalSettings();
    static void writeSettings();
115

con's avatar
con committed
116
    // command line arguments
117 118
    static QStringList arguments();
    static bool parseOptions(const QStringList &args,
con's avatar
con committed
119 120 121 122
        const QMap<QString, bool> &appOptions,
        QMap<QString, QString> *foundAppOptions,
        QString *errorString);
    static void formatOptions(QTextStream &str, int optionIndentation, int descriptionIndentation);
123 124
    static void formatPluginOptions(QTextStream &str, int optionIndentation, int descriptionIndentation);
    static void formatPluginVersions(QTextStream &str);
con's avatar
con committed
125

126
    static QString serializedArguments();
127

128 129
    static bool runningTests();
    static QString testDataDirectory();
con's avatar
con committed
130

131
    static void profilingReport(const char *what, const PluginSpec *spec = 0);
132

con's avatar
con committed
133 134 135 136 137
signals:
    void objectAdded(QObject *obj);
    void aboutToRemoveObject(QObject *obj);

    void pluginsChanged();
Tobias Hunger's avatar
Tobias Hunger committed
138
    void initializationDone();
139 140 141

public slots:
    void remoteArguments(const QString &serializedArguments);
142
    void shutdown();
143

con's avatar
con committed
144 145 146 147 148 149 150 151 152 153 154
private slots:
    void startTests();

private:
    Internal::PluginManagerPrivate *d;
    static PluginManager *m_instance;
    mutable QReadWriteLock m_lock;

    friend class Internal::PluginManagerPrivate;
};

hjk's avatar
hjk committed
155
} // namespace ExtensionSystem
con's avatar
con committed
156

hjk's avatar
hjk committed
157
#endif // EXTENSIONSYSTEM_PLUGINMANAGER_H