pluginmanager.h 5.66 KB
Newer Older
hjk's avatar
hjk committed
1
/****************************************************************************
con's avatar
con committed
2
**
Eike Ziller's avatar
Eike Ziller committed
3 4
** Copyright (C) 2015 The Qt Company Ltd.
** Contact: http://www.qt.io/licensing
con's avatar
con committed
5
**
hjk's avatar
hjk committed
6
** This file is part of Qt Creator.
con's avatar
con committed
7
**
hjk's avatar
hjk committed
8 9 10 11
** Commercial License Usage
** Licensees holding valid commercial Qt licenses may use this file in
** accordance with the commercial license agreement provided with the
** Software or, alternatively, in accordance with the terms contained in
Eike Ziller's avatar
Eike Ziller committed
12 13
** a written agreement between you and The Qt Company.  For licensing terms and
** conditions see http://www.qt.io/terms-conditions.  For further information
Eike Ziller's avatar
Eike Ziller committed
14
** use the contact form at http://www.qt.io/contact-us.
15
**
16
** GNU Lesser General Public License Usage
hjk's avatar
hjk committed
17
** Alternatively, this file may be used under the terms of the GNU Lesser
Eike Ziller's avatar
Eike Ziller committed
18 19 20 21 22 23
** General Public License version 2.1 or version 3 as published by the Free
** Software Foundation and appearing in the file LICENSE.LGPLv21 and
** LICENSE.LGPLv3 included in the packaging of this file.  Please review the
** following information to ensure the GNU Lesser General Public License
** requirements will be met: https://www.gnu.org/licenses/lgpl.html and
** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
hjk's avatar
hjk committed
24
**
Eike Ziller's avatar
Eike Ziller committed
25 26
** In addition, as a special exception, The Qt Company gives you certain additional
** rights.  These rights are described in The Qt Company LGPL Exception
con's avatar
con committed
27 28
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
**
hjk's avatar
hjk committed
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
#include <QObject>
#include <QStringList>
con's avatar
con committed
39 40 41

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

namespace ExtensionSystem {
46
class PluginCollection;
hjk's avatar
hjk committed
47 48
class IPlugin;
class PluginSpec;
hjk's avatar
hjk committed
49

50
namespace Internal { class PluginManagerPrivate; }
con's avatar
con committed
51 52 53 54 55 56 57 58 59

class EXTENSIONSYSTEM_EXPORT PluginManager : public QObject
{
    Q_OBJECT

public:
    static PluginManager *instance();

    PluginManager();
hjk's avatar
hjk committed
60
    ~PluginManager();
con's avatar
con committed
61 62

    // Object pool operations
63 64 65
    static void addObject(QObject *obj);
    static void removeObject(QObject *obj);
    static QList<QObject *> allObjects();
hjk's avatar
hjk committed
66
    static QReadWriteLock *listLock();
67
    template <typename T> static QList<T *> getObjects()
con's avatar
con committed
68
    {
hjk's avatar
hjk committed
69
        QReadLocker lock(listLock());
con's avatar
con committed
70 71 72
        QList<T *> results;
        QList<QObject *> all = allObjects();
        foreach (QObject *obj, all) {
73 74
            T *result = qobject_cast<T *>(obj);
            if (result)
con's avatar
con committed
75 76 77 78
                results += result;
        }
        return results;
    }
79 80 81 82 83 84 85 86 87 88 89 90 91
    template <typename T, typename Predicate>
    static QList<T *> getObjects(Predicate predicate)
    {
        QReadLocker lock(listLock());
        QList<T *> results;
        QList<QObject *> all = allObjects();
        foreach (QObject *obj, all) {
            T *result = qobject_cast<T *>(obj);
            if (result && predicate(result))
                results += result;
        }
        return results;
    }
92
    template <typename T> static T *getObject()
con's avatar
con committed
93
    {
hjk's avatar
hjk committed
94
        QReadLocker lock(listLock());
con's avatar
con committed
95 96
        QList<QObject *> all = allObjects();
        foreach (QObject *obj, all) {
97 98
            if (T *result = qobject_cast<T *>(obj))
                return result;
con's avatar
con committed
99
        }
100
        return 0;
con's avatar
con committed
101
    }
102 103 104 105 106 107 108 109 110 111 112
    template <typename T, typename Predicate> static T *getObject(Predicate predicate)
    {
        QReadLocker lock(listLock());
        QList<QObject *> all = allObjects();
        foreach (QObject *obj, all) {
            if (T *result = qobject_cast<T *>(obj))
                if (predicate(result))
                    return result;
        }
        return 0;
    }
con's avatar
con committed
113

114 115
    static QObject *getObjectByName(const QString &name);
    static QObject *getObjectByClassName(const QString &className);
116

con's avatar
con committed
117
    // Plugin operations
118 119 120 121
    static QList<PluginSpec *> loadQueue();
    static void loadPlugins();
    static QStringList pluginPaths();
    static void setPluginPaths(const QStringList &paths);
122 123
    static QString pluginIID();
    static void setPluginIID(const QString &iid);
124 125 126
    static QList<PluginSpec *> plugins();
    static QHash<QString, PluginCollection *> pluginCollections();
    static bool hasError();
127 128
    static QSet<PluginSpec *> pluginsRequiringPlugin(PluginSpec *spec);
    static QSet<PluginSpec *> pluginsRequiredByPlugin(PluginSpec *spec);
con's avatar
con committed
129

130
    // Settings
131 132 133 134 135
    static void setSettings(QSettings *settings);
    static QSettings *settings();
    static void setGlobalSettings(QSettings *settings);
    static QSettings *globalSettings();
    static void writeSettings();
136

con's avatar
con committed
137
    // command line arguments
138 139
    static QStringList arguments();
    static bool parseOptions(const QStringList &args,
con's avatar
con committed
140 141 142 143
        const QMap<QString, bool> &appOptions,
        QMap<QString, QString> *foundAppOptions,
        QString *errorString);
    static void formatOptions(QTextStream &str, int optionIndentation, int descriptionIndentation);
144 145
    static void formatPluginOptions(QTextStream &str, int optionIndentation, int descriptionIndentation);
    static void formatPluginVersions(QTextStream &str);
con's avatar
con committed
146

147
    static QString serializedArguments();
148

149
    static bool testRunRequested();
con's avatar
con committed
150

151
    static void profilingReport(const char *what, const PluginSpec *spec = 0);
152

153 154
    static QString platformName();

con's avatar
con committed
155 156 157 158 159
signals:
    void objectAdded(QObject *obj);
    void aboutToRemoveObject(QObject *obj);

    void pluginsChanged();
Tobias Hunger's avatar
Tobias Hunger committed
160
    void initializationDone();
161
    void testsFinished(int failedTests);
162 163

public slots:
164
    void remoteArguments(const QString &serializedArguments, QObject *socket);
165
    void shutdown();
166

con's avatar
con committed
167 168 169
    friend class Internal::PluginManagerPrivate;
};

hjk's avatar
hjk committed
170
} // namespace ExtensionSystem
con's avatar
con committed
171

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