pluginmanager_p.h 4.78 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
** 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.
23
**
hjk's avatar
hjk committed
24 25
** 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
#ifndef PLUGINMANAGER_P_H
#define PLUGINMANAGER_P_H

#include "pluginspec.h"

35 36 37 38
#include <QSet>
#include <QStringList>
#include <QObject>
#include <QScopedPointer>
39 40 41

QT_BEGIN_NAMESPACE
class QTime;
42
class QTimer;
43
class QSettings;
Friedemann Kleint's avatar
Friedemann Kleint committed
44
class QEventLoop;
45
QT_END_NAMESPACE
con's avatar
con committed
46 47 48 49

namespace ExtensionSystem {

class PluginManager;
50
class PluginCollection;
con's avatar
con committed
51 52 53 54 55

namespace Internal {

class PluginSpecPrivate;

56
class EXTENSIONSYSTEM_EXPORT PluginManagerPrivate : QObject
con's avatar
con committed
57
{
58
    Q_OBJECT
con's avatar
con committed
59 60 61 62 63 64 65 66 67 68
public:
    PluginManagerPrivate(PluginManager *pluginManager);
    virtual ~PluginManagerPrivate();

    // Object pool operations
    void addObject(QObject *obj);
    void removeObject(QObject *obj);

    // Plugin operations
    void loadPlugins();
69
    void shutdown();
con's avatar
con committed
70 71 72 73
    void setPluginPaths(const QStringList &paths);
    QList<PluginSpec *> loadQueue();
    void loadPlugin(PluginSpec *spec, PluginSpec::State destState);
    void resolveDependencies();
74
    void initProfiling();
75
    void profilingSummary() const;
76
    void profilingReport(const char *what, const PluginSpec *spec = 0);
77
    void setSettings(QSettings *settings);
78
    void setGlobalSettings(QSettings *settings);
79
    void readSettings();
80
    void writeSettings();
81
    void disablePluginIndirectly(PluginSpec *spec);
con's avatar
con committed
82

83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99
    class TestSpec {
    public:
        TestSpec(PluginSpec *pluginSpec, const QStringList &testFunctions = QStringList())
            : pluginSpec(pluginSpec), testFunctions(testFunctions) {}
        PluginSpec *pluginSpec;
        QStringList testFunctions;
    };

    bool containsTestSpec(PluginSpec *pluginSpec) const
    {
        foreach (const TestSpec &testSpec, testSpecs) {
            if (testSpec.pluginSpec == pluginSpec)
                return true;
        }
        return false;
    }

100
    QHash<QString, PluginCollection *> pluginCategories;
101
    QList<PluginSpec *> pluginSpecs;
102
    QList<TestSpec> testSpecs;
con's avatar
con committed
103 104 105
    QStringList pluginPaths;
    QString extension;
    QList<QObject *> allObjects; // ### make this a QList<QPointer<QObject> > > ?
106
    QStringList defaultDisabledPlugins;
con's avatar
con committed
107
    QStringList disabledPlugins;
108
    QStringList forceEnabledPlugins;
109 110 111 112
    // delayed initialization
    QTimer *delayedInitializeTimer;
    QList<PluginSpec *> delayedInitializeQueue;
    // ansynchronous shutdown
113 114
    QList<PluginSpec *> asynchronousPlugins; // plugins that have requested async shutdown
    QEventLoop *shutdownEventLoop; // used for async shutdown
con's avatar
con committed
115 116

    QStringList arguments;
117
    QScopedPointer<QTime> m_profileTimer;
118
    QHash<const PluginSpec *, int> m_profileTotal;
119
    int m_profileElapsedMS;
120
    unsigned m_profilingVerbosity;
121
    QSettings *settings;
122
    QSettings *globalSettings;
con's avatar
con committed
123 124 125 126 127 128 129 130

    // Look in argument descriptions of the specs for the option.
    PluginSpec *pluginForOption(const QString &option, bool *requiresArgument) const;
    PluginSpec *pluginByName(const QString &name) const;

    // used by tests
    static PluginSpec *createSpec();
    static PluginSpecPrivate *privateSpec(PluginSpec *spec);
131 132

private slots:
133
    void nextDelayedInitialize();
134 135
    void asyncShutdownFinished();

con's avatar
con committed
136
private:
137
    PluginCollection *defaultCollection;
con's avatar
con committed
138 139 140 141 142 143 144
    PluginManager *q;

    void readPluginPaths();
    bool loadQueue(PluginSpec *spec,
            QList<PluginSpec *> &queue,
            QList<PluginSpec *> &circularityCheckQueue);
    void stopAll();
145
    void deleteAll();
con's avatar
con committed
146 147 148 149 150 151
};

} // namespace Internal
} // namespace ExtensionSystem

#endif // PLUGINMANAGER_P_H