Files
qt-creator/src/libs/extensionsystem/pluginmanager.h

165 lines
5.2 KiB
C
Raw Normal View History

/****************************************************************************
2008-12-02 12:01:29 +01:00
**
** Copyright (C) 2016 The Qt Company Ltd.
** Contact: https://www.qt.io/licensing/
2008-12-02 12:01:29 +01:00
**
** This file is part of Qt Creator.
2008-12-02 12:01:29 +01:00
**
** 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 The Qt Company. For licensing terms
** and conditions see https://www.qt.io/terms-conditions. For further
** information use the contact form at https://www.qt.io/contact-us.
**
** GNU General Public License Usage
** Alternatively, this file may be used under the terms of the GNU
** General Public License version 3 as published by the Free Software
** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT
** included in the packaging of this file. Please review the following
** information to ensure the GNU General Public License requirements will
** be met: https://www.gnu.org/licenses/gpl-3.0.html.
2010-12-17 16:01:08 +01:00
**
****************************************************************************/
2008-12-02 14:09:21 +01:00
#pragma once
2008-12-02 12:01:29 +01:00
#include "extensionsystem_global.h"
#include <aggregation/aggregate.h>
#include <QObject>
#include <QStringList>
2008-12-02 12:01:29 +01:00
QT_BEGIN_NAMESPACE
class QTextStream;
class QSettings;
2008-12-02 12:01:29 +01:00
QT_END_NAMESPACE
namespace ExtensionSystem {
class IPlugin;
class PluginSpec;
namespace Internal { class PluginManagerPrivate; }
2008-12-02 12:01:29 +01:00
class EXTENSIONSYSTEM_EXPORT PluginManager : public QObject
{
Q_OBJECT
public:
static PluginManager *instance();
PluginManager();
~PluginManager();
2008-12-02 12:01:29 +01:00
// Object pool operations
static void addObject(QObject *obj);
static void removeObject(QObject *obj);
static QList<QObject *> allObjects();
static QReadWriteLock *listLock();
template <typename T> static QList<T *> getObjects()
2008-12-02 12:01:29 +01:00
{
QReadLocker lock(listLock());
2008-12-02 12:01:29 +01:00
QList<T *> results;
QList<QObject *> all = allObjects();
foreach (QObject *obj, all) {
T *result = qobject_cast<T *>(obj);
if (result)
2008-12-02 12:01:29 +01:00
results += result;
}
return results;
}
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;
}
template <typename T> static T *getObject()
2008-12-02 12:01:29 +01:00
{
QReadLocker lock(listLock());
2008-12-02 12:01:29 +01:00
QList<QObject *> all = allObjects();
foreach (QObject *obj, all) {
if (T *result = qobject_cast<T *>(obj))
return result;
2008-12-02 12:01:29 +01:00
}
return 0;
2008-12-02 12:01:29 +01:00
}
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;
}
2008-12-02 12:01:29 +01:00
static QObject *getObjectByName(const QString &name);
static QObject *getObjectByClassName(const QString &className);
2008-12-02 12:01:29 +01:00
// Plugin operations
static QList<PluginSpec *> loadQueue();
static void loadPlugins();
static QStringList pluginPaths();
static void setPluginPaths(const QStringList &paths);
static QString pluginIID();
static void setPluginIID(const QString &iid);
static QList<PluginSpec *> plugins();
static QHash<QString, QList<PluginSpec *>> pluginCollections();
static bool hasError();
static QSet<PluginSpec *> pluginsRequiringPlugin(PluginSpec *spec);
static QSet<PluginSpec *> pluginsRequiredByPlugin(PluginSpec *spec);
2008-12-02 12:01:29 +01:00
// Settings
static void setSettings(QSettings *settings);
static QSettings *settings();
static void setGlobalSettings(QSettings *settings);
static QSettings *globalSettings();
static void writeSettings();
2008-12-02 12:01:29 +01:00
// command line arguments
static QStringList arguments();
static bool parseOptions(const QStringList &args,
2008-12-02 12:01:29 +01:00
const QMap<QString, bool> &appOptions,
QMap<QString, QString> *foundAppOptions,
QString *errorString);
static void formatOptions(QTextStream &str, int optionIndentation, int descriptionIndentation);
static void formatPluginOptions(QTextStream &str, int optionIndentation, int descriptionIndentation);
static void formatPluginVersions(QTextStream &str);
2008-12-02 12:01:29 +01:00
static QString serializedArguments();
static bool testRunRequested();
2008-12-02 12:01:29 +01:00
static void profilingReport(const char *what, const PluginSpec *spec = 0);
static QString platformName();
static bool isInitializationDone();
void remoteArguments(const QString &serializedArguments, QObject *socket);
void shutdown();
2008-12-02 12:01:29 +01:00
signals:
void objectAdded(QObject *obj);
void aboutToRemoveObject(QObject *obj);
void pluginsChanged();
void initializationDone();
void testsFinished(int failedTests);
2008-12-02 12:01:29 +01:00
friend class Internal::PluginManagerPrivate;
};
2008-12-02 14:09:21 +01:00
} // namespace ExtensionSystem