pluginmanager.h 4.89 KB
Newer Older
hjk's avatar
hjk committed
1
/****************************************************************************
con's avatar
con committed
2
**
3
** Copyright (C) 2013 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 38
#include <QObject>
#include <QReadWriteLock>
#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

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

class IPlugin;
class PluginSpec;

class EXTENSIONSYSTEM_EXPORT PluginManager : public QObject
{
    Q_OBJECT

public:
    static PluginManager *instance();

    PluginManager();
    virtual ~PluginManager();

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

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

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

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

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

125
    static QString serializedArguments();
126

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

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

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

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

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

con's avatar
con committed
143 144 145 146 147 148 149 150 151 152 153
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
154
} // namespace ExtensionSystem
con's avatar
con committed
155

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