pluginmanager.h 4.79 KB
Newer Older
hjk's avatar
hjk committed
1
/****************************************************************************
con's avatar
con committed
2
**
3
** Copyright (C) 2014 Digia Plc and/or its subsidiary(-ies).
hjk's avatar
hjk committed
4
** Contact: http://www.qt-project.org/legal
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 12 13 14
** 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
** a written agreement between you and Digia.  For licensing terms and
** conditions see http://qt.digia.com/licensing.  For further information
** use the contact form at http://qt.digia.com/contact-us.
15
**
16
** GNU Lesser General Public License Usage
hjk's avatar
hjk committed
17 18 19 20 21 22 23 24 25
** Alternatively, 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.
**
** In addition, as a special exception, Digia gives you certain additional
** rights.  These rights are described in the Digia Qt LGPL Exception
con's avatar
con committed
26 27
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
**
hjk's avatar
hjk committed
28
****************************************************************************/
hjk's avatar
hjk committed
29

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

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

36 37
#include <QObject>
#include <QStringList>
con's avatar
con committed
38 39 40

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

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

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

class EXTENSIONSYSTEM_EXPORT PluginManager : public QObject
{
    Q_OBJECT

public:
    static PluginManager *instance();

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

    // Object pool operations
62 63 64
    static void addObject(QObject *obj);
    static void removeObject(QObject *obj);
    static QList<QObject *> allObjects();
hjk's avatar
hjk committed
65
    static QReadWriteLock *listLock();
66
    template <typename T> static QList<T *> getObjects()
con's avatar
con committed
67
    {
hjk's avatar
hjk committed
68
        QReadLocker lock(listLock());
con's avatar
con committed
69 70 71 72 73 74 75 76 77 78
        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;
    }
79
    template <typename T> static T *getObject()
con's avatar
con committed
80
    {
hjk's avatar
hjk committed
81
        QReadLocker lock(listLock());
con's avatar
con committed
82 83 84 85 86 87 88 89 90
        QList<QObject *> all = allObjects();
        T *result = 0;
        foreach (QObject *obj, all) {
            if ((result = Aggregation::query<T>(obj)) != 0)
                break;
        }
        return result;
    }

91 92
    static QObject *getObjectByName(const QString &name);
    static QObject *getObjectByClassName(const QString &className);
93

con's avatar
con committed
94
    // Plugin operations
95 96 97 98 99 100 101 102 103
    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
104

105
    // Settings
106 107 108 109 110
    static void setSettings(QSettings *settings);
    static QSettings *settings();
    static void setGlobalSettings(QSettings *settings);
    static QSettings *globalSettings();
    static void writeSettings();
111

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

122
    static QString serializedArguments();
123

124
    static bool testRunRequested();
125
    static QString testDataDirectory();
con's avatar
con committed
126

127
    static void profilingReport(const char *what, const PluginSpec *spec = 0);
128

129 130
    static QString platformName();

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

    void pluginsChanged();
Tobias Hunger's avatar
Tobias Hunger committed
136
    void initializationDone();
137 138

public slots:
139
    void remoteArguments(const QString &serializedArguments, QObject *socket);
140
    void shutdown();
141

con's avatar
con committed
142 143 144 145 146
private slots:
    void startTests();
    friend class Internal::PluginManagerPrivate;
};

hjk's avatar
hjk committed
147
} // namespace ExtensionSystem
con's avatar
con committed
148

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