Commit e3c354d8 authored by Eike Ziller's avatar Eike Ziller Committed by hjk

Make PluginManager mostly static.

Change-Id: Ib938aa4999c7c418a82304c5cca2e8748ef9d228
Reviewed-by: default avatarhjk <qthjk@ovi.com>
parent 9daa3400
......@@ -61,6 +61,8 @@
#include <qtsystemexceptionhandler.h>
#endif
using namespace ExtensionSystem;
enum { OptionIndent = 4, DescriptionIndent = 34 };
static const char appNameC[] = "Qt Creator";
......@@ -89,7 +91,7 @@ static const char SETTINGS_OPTION[] = "-settingspath";
static const char PID_OPTION[] = "-pid";
#endif
typedef QList<ExtensionSystem::PluginSpec *> PluginSpecSet;
typedef QList<PluginSpec *> PluginSpecSet;
// Helpers for displaying messages. Note that there is no console on Windows.
#ifdef Q_OS_WIN
......@@ -128,24 +130,23 @@ static void displayError(const QString &t)
#endif
static void printVersion(const ExtensionSystem::PluginSpec *coreplugin,
const ExtensionSystem::PluginManager &pm)
static void printVersion(const PluginSpec *coreplugin)
{
QString version;
QTextStream str(&version);
str << '\n' << appNameC << ' ' << coreplugin->version()<< " based on Qt " << qVersion() << "\n\n";
pm.formatPluginVersions(str);
PluginManager::formatPluginVersions(str);
str << '\n' << coreplugin->copyright() << '\n';
displayHelpText(version);
}
static void printHelp(const QString &a0, const ExtensionSystem::PluginManager &pm)
static void printHelp(const QString &a0)
{
QString help;
QTextStream str(&help);
str << "Usage: " << a0 << fixedOptionsC;
ExtensionSystem::PluginManager::formatOptions(str, OptionIndent, DescriptionIndent);
pm.formatPluginOptions(str, OptionIndent, DescriptionIndent);
PluginManager::formatOptions(str, OptionIndent, DescriptionIndent);
PluginManager::formatPluginOptions(str, OptionIndent, DescriptionIndent);
displayHelpText(help);
}
......@@ -264,10 +265,10 @@ int main(int argc, char **argv)
QSettings *globalSettings = new QSettings(QSettings::IniFormat, QSettings::SystemScope,
QLatin1String(Core::Constants::IDE_SETTINGSVARIANT_STR),
QLatin1String("QtCreator"));
ExtensionSystem::PluginManager pluginManager;
pluginManager.setFileExtension(QLatin1String("pluginspec"));
pluginManager.setGlobalSettings(globalSettings);
pluginManager.setSettings(settings);
PluginManager pluginManager;
PluginManager::setFileExtension(QLatin1String("pluginspec"));
PluginManager::setGlobalSettings(globalSettings);
PluginManager::setSettings(settings);
QTranslator translator;
QTranslator qtTranslator;
......@@ -323,7 +324,7 @@ int main(int argc, char **argv)
#endif
// Load
const QStringList pluginPaths = getPluginPaths();
pluginManager.setPluginPaths(pluginPaths);
PluginManager::setPluginPaths(pluginPaths);
QMap<QString, QString> foundAppOptions;
if (arguments.size() > 1) {
......@@ -338,16 +339,16 @@ int main(int argc, char **argv)
appOptions.insert(QLatin1String(PID_OPTION), true);
#endif
QString errorMessage;
if (!pluginManager.parseOptions(arguments, appOptions, &foundAppOptions, &errorMessage)) {
if (!PluginManager::parseOptions(arguments, appOptions, &foundAppOptions, &errorMessage)) {
displayError(errorMessage);
printHelp(QFileInfo(app.applicationFilePath()).baseName(), pluginManager);
printHelp(QFileInfo(app.applicationFilePath()).baseName());
return -1;
}
}
const PluginSpecSet plugins = pluginManager.plugins();
ExtensionSystem::PluginSpec *coreplugin = 0;
foreach (ExtensionSystem::PluginSpec *spec, plugins) {
const PluginSpecSet plugins = PluginManager::plugins();
PluginSpec *coreplugin = 0;
foreach (PluginSpec *spec, plugins) {
if (spec->name() == QLatin1String(corePluginNameC)) {
coreplugin = spec;
break;
......@@ -364,14 +365,14 @@ int main(int argc, char **argv)
return 1;
}
if (foundAppOptions.contains(QLatin1String(VERSION_OPTION))) {
printVersion(coreplugin, pluginManager);
printVersion(coreplugin);
return 0;
}
if (foundAppOptions.contains(QLatin1String(HELP_OPTION1))
|| foundAppOptions.contains(QLatin1String(HELP_OPTION2))
|| foundAppOptions.contains(QLatin1String(HELP_OPTION3))
|| foundAppOptions.contains(QLatin1String(HELP_OPTION4))) {
printHelp(QFileInfo(app.applicationFilePath()).baseName(), pluginManager);
printHelp(QFileInfo(app.applicationFilePath()).baseName());
return 0;
}
......@@ -387,7 +388,7 @@ int main(int argc, char **argv)
#endif
if (app.isRunning() && (pid != -1 || foundAppOptions.contains(QLatin1String(CLIENT_OPTION)))) {
if (app.sendMessage(pluginManager.serializedArguments(), 5000 /*timeout*/, pid))
if (app.sendMessage(PluginManager::serializedArguments(), 5000 /*timeout*/, pid))
return 0;
// Message could not be send, maybe it was in the process of quitting
......@@ -395,7 +396,7 @@ int main(int argc, char **argv)
// Nah app is still running, ask the user
int button = askMsgSendFailed();
while(button == QMessageBox::Retry) {
if (app.sendMessage(pluginManager.serializedArguments(), 5000 /*timeout*/, pid))
if (app.sendMessage(PluginManager::serializedArguments(), 5000 /*timeout*/, pid))
return 0;
if (!app.isRunning(pid)) // App quit while we were trying so start a new creator
button = QMessageBox::Yes;
......@@ -407,13 +408,13 @@ int main(int argc, char **argv)
}
}
pluginManager.loadPlugins();
PluginManager::loadPlugins();
if (coreplugin->hasError()) {
displayError(msgCoreLoadFailure(coreplugin->errorString()));
return 1;
}
if (pluginManager.hasError()) {
ExtensionSystem::PluginErrorOverview errorOverview(&pluginManager);
if (PluginManager::hasError()) {
PluginErrorOverview errorOverview;
errorOverview.exec();
}
......@@ -430,7 +431,7 @@ int main(int argc, char **argv)
#ifdef WITH_TESTS
// Do this after the event loop has started
if (pluginManager.runningTests())
if (PluginManager::runningTests())
QTimer::singleShot(100, &pluginManager, SLOT(startTests()));
#endif
......
......@@ -23,7 +23,6 @@ HEADERS += pluginerrorview.h \
pluginspec.h \
pluginspec_p.h \
pluginview.h \
pluginview_p.h \
optionsparser.h \
plugincollection.h \
pluginerroroverview.h
......
......@@ -185,9 +185,8 @@ IPlugin::IPlugin()
*/
IPlugin::~IPlugin()
{
PluginManager *pm = PluginManager::instance();
foreach (QObject *obj, d->addedObjectsInReverseOrder)
pm->removeObject(obj);
PluginManager::removeObject(obj);
qDeleteAll(d->addedObjectsInReverseOrder);
d->addedObjectsInReverseOrder.clear();
delete d;
......@@ -211,7 +210,7 @@ PluginSpec *IPlugin::pluginSpec() const
*/
void IPlugin::addObject(QObject *obj)
{
PluginManager::instance()->addObject(obj);
PluginManager::addObject(obj);
}
/*!
......@@ -227,7 +226,7 @@ void IPlugin::addObject(QObject *obj)
void IPlugin::addAutoReleasedObject(QObject *obj)
{
d->addedObjectsInReverseOrder.prepend(obj);
PluginManager::instance()->addObject(obj);
PluginManager::addObject(obj);
}
/*!
......@@ -237,6 +236,6 @@ void IPlugin::addAutoReleasedObject(QObject *obj)
*/
void IPlugin::removeObject(QObject *obj)
{
PluginManager::instance()->removeObject(obj);
PluginManager::removeObject(obj);
}
......@@ -44,7 +44,7 @@ class PluginErrorOverviewPrivate : public QObject
{
Q_OBJECT
public:
PluginErrorOverviewPrivate(PluginManager *manager, QDialog *dialog);
PluginErrorOverviewPrivate(QDialog *dialog);
~PluginErrorOverviewPrivate();
private slots:
......@@ -52,7 +52,6 @@ private slots:
private:
Ui::PluginErrorOverview *m_ui;
PluginManager *m_manager;
};
} // Internal
......@@ -61,9 +60,9 @@ private:
using namespace ExtensionSystem;
using namespace ExtensionSystem::Internal;
PluginErrorOverview::PluginErrorOverview(PluginManager *manager, QWidget *parent) :
PluginErrorOverview::PluginErrorOverview(QWidget *parent) :
QDialog(parent),
d(new PluginErrorOverviewPrivate(manager, this))
d(new PluginErrorOverviewPrivate(this))
{
}
......@@ -72,14 +71,13 @@ PluginErrorOverview::~PluginErrorOverview()
delete d;
}
PluginErrorOverviewPrivate::PluginErrorOverviewPrivate(PluginManager *manager, QDialog *dialog)
: m_ui(new Ui::PluginErrorOverview),
m_manager(manager)
PluginErrorOverviewPrivate::PluginErrorOverviewPrivate(QDialog *dialog)
: m_ui(new Ui::PluginErrorOverview)
{
m_ui->setupUi(dialog);
m_ui->buttonBox->addButton(tr("Continue"), QDialogButtonBox::AcceptRole);
foreach (PluginSpec *spec, m_manager->plugins()) {
foreach (PluginSpec *spec, PluginManager::plugins()) {
// only show errors on startup if plugin is enabled.
if (spec->hasError() && spec->isEnabled() && !spec->isDisabledIndirectly()) {
QListWidgetItem *item = new QListWidgetItem(spec->name());
......
......@@ -50,7 +50,7 @@ class EXTENSIONSYSTEM_EXPORT PluginErrorOverview : public QDialog
Q_OBJECT
public:
explicit PluginErrorOverview(PluginManager *manager, QWidget *parent = 0);
explicit PluginErrorOverview(QWidget *parent = 0);
~PluginErrorOverview();
private:
......
......@@ -290,7 +290,7 @@ PluginManager::~PluginManager()
*/
void PluginManager::addObject(QObject *obj)
{
d->addObject(obj);
m_instance->d->addObject(obj);
}
/*!
......@@ -300,7 +300,7 @@ void PluginManager::addObject(QObject *obj)
*/
void PluginManager::removeObject(QObject *obj)
{
d->removeObject(obj);
m_instance->d->removeObject(obj);
}
/*!
......@@ -310,9 +310,9 @@ void PluginManager::removeObject(QObject *obj)
\sa PluginManager::getObject()
\sa PluginManager::getObjects()
*/
QList<QObject *> PluginManager::allObjects() const
QList<QObject *> PluginManager::allObjects()
{
return d->allObjects;
return m_instance->d->allObjects;
}
/*!
......@@ -326,7 +326,7 @@ QList<QObject *> PluginManager::allObjects() const
*/
void PluginManager::loadPlugins()
{
return d->loadPlugins();
return m_instance->d->loadPlugins();
}
/*!
......@@ -334,7 +334,7 @@ void PluginManager::loadPlugins()
Returns true if any plugin has errors even though it is enabled.
Most useful to call after loadPlugins().
*/
bool PluginManager::hasError() const
bool PluginManager::hasError()
{
foreach (PluginSpec *spec, plugins()) {
// only show errors on startup if plugin is enabled.
......@@ -360,9 +360,9 @@ void PluginManager::shutdown()
\sa setPluginPaths()
*/
QStringList PluginManager::pluginPaths() const
QStringList PluginManager::pluginPaths()
{
return d->pluginPaths;
return m_instance->d->pluginPaths;
}
/*!
......@@ -376,7 +376,7 @@ QStringList PluginManager::pluginPaths() const
*/
void PluginManager::setPluginPaths(const QStringList &paths)
{
d->setPluginPaths(paths);
m_instance->d->setPluginPaths(paths);
}
/*!
......@@ -386,9 +386,9 @@ void PluginManager::setPluginPaths(const QStringList &paths)
\sa setFileExtension()
*/
QString PluginManager::fileExtension() const
QString PluginManager::fileExtension()
{
return d->extension;
return m_instance->d->extension;
}
/*!
......@@ -400,7 +400,7 @@ QString PluginManager::fileExtension() const
*/
void PluginManager::setFileExtension(const QString &extension)
{
d->extension = extension;
m_instance->d->extension = extension;
}
/*!
......@@ -409,7 +409,7 @@ void PluginManager::setFileExtension(const QString &extension)
*/
void PluginManager::setSettings(QSettings *settings)
{
d->setSettings(settings);
m_instance->d->setSettings(settings);
}
/*!
......@@ -418,28 +418,28 @@ void PluginManager::setSettings(QSettings *settings)
*/
void PluginManager::setGlobalSettings(QSettings *settings)
{
d->setGlobalSettings(settings);
m_instance->d->setGlobalSettings(settings);
}
/*!
Returns the user specific settings used for information about enabled/disabled plugins.
*/
QSettings *PluginManager::settings() const
QSettings *PluginManager::settings()
{
return d->settings;
return m_instance->d->settings;
}
/*!
Returns the global (user-independent) settings used for information about default disabled plugins.
*/
QSettings *PluginManager::globalSettings() const
QSettings *PluginManager::globalSettings()
{
return d->globalSettings;
return m_instance->d->globalSettings;
}
void PluginManager::writeSettings()
{
d->writeSettings();
m_instance->d->writeSettings();
}
/*!
......@@ -447,9 +447,9 @@ void PluginManager::writeSettings()
The arguments left over after parsing (Neither startup nor plugin
arguments). Typically, this will be the list of files to open.
*/
QStringList PluginManager::arguments() const
QStringList PluginManager::arguments()
{
return d->arguments;
return m_instance->d->arguments;
}
/*!
......@@ -462,14 +462,14 @@ QStringList PluginManager::arguments() const
\sa setPluginPaths()
*/
QList<PluginSpec *> PluginManager::plugins() const
QList<PluginSpec *> PluginManager::plugins()
{
return d->pluginSpecs;
return m_instance->d->pluginSpecs;
}
QHash<QString, PluginCollection *> PluginManager::pluginCollections() const
QHash<QString, PluginCollection *> PluginManager::pluginCollections()
{
return d->pluginCategories;
return m_instance->d->pluginCategories;
}
/*!
......@@ -485,7 +485,7 @@ QHash<QString, PluginCollection *> PluginManager::pluginCollections() const
static const char argumentKeywordC[] = ":arguments";
QString PluginManager::serializedArguments() const
QString PluginManager::serializedArguments()
{
const QChar separator = QLatin1Char('|');
QString rc;
......@@ -499,13 +499,13 @@ QString PluginManager::serializedArguments() const
rc += ps->arguments().join(QString(separator));
}
}
if (!d->arguments.isEmpty()) {
if (!m_instance->d->arguments.isEmpty()) {
if (!rc.isEmpty())
rc += separator;
rc += QLatin1String(argumentKeywordC);
// If the argument appears to be a file, make it absolute
// when sending to another instance.
foreach(const QString &argument, d->arguments) {
foreach (const QString &argument, m_instance->d->arguments) {
rc += separator;
const QFileInfo fi(argument);
if (fi.exists() && fi.isRelative()) {
......@@ -578,7 +578,7 @@ bool PluginManager::parseOptions(const QStringList &args,
QMap<QString, QString> *foundAppOptions,
QString *errorString)
{
OptionsParser options(args, appOptions, foundAppOptions, errorString, d);
OptionsParser options(args, appOptions, foundAppOptions, errorString, m_instance->d);
return options.parse();
}
......@@ -633,12 +633,12 @@ void PluginManager::formatOptions(QTextStream &str, int optionIndentation, int d
Format the plugin options of the plugin specs for command line help.
*/
void PluginManager::formatPluginOptions(QTextStream &str, int optionIndentation, int descriptionIndentation) const
void PluginManager::formatPluginOptions(QTextStream &str, int optionIndentation, int descriptionIndentation)
{
typedef PluginSpec::PluginArgumentDescriptions PluginArgumentDescriptions;
// Check plugins for options
const PluginSpecSet::const_iterator pcend = d->pluginSpecs.constEnd();
for (PluginSpecSet::const_iterator pit = d->pluginSpecs.constBegin(); pit != pcend; ++pit) {
const PluginSpecSet::const_iterator pcend = m_instance->d->pluginSpecs.constEnd();
for (PluginSpecSet::const_iterator pit = m_instance->d->pluginSpecs.constBegin(); pit != pcend; ++pit) {
const PluginArgumentDescriptions pargs = (*pit)->argumentDescriptions();
if (!pargs.empty()) {
str << "\nPlugin: " << (*pit)->name() << '\n';
......@@ -655,10 +655,10 @@ void PluginManager::formatPluginOptions(QTextStream &str, int optionIndentation,
Format the version of the plugin specs for command line help.
*/
void PluginManager::formatPluginVersions(QTextStream &str) const
void PluginManager::formatPluginVersions(QTextStream &str)
{
const PluginSpecSet::const_iterator cend = d->pluginSpecs.constEnd();
for (PluginSpecSet::const_iterator it = d->pluginSpecs.constBegin(); it != cend; ++it) {
const PluginSpecSet::const_iterator cend = m_instance->d->pluginSpecs.constEnd();
for (PluginSpecSet::const_iterator it = m_instance->d->pluginSpecs.constBegin(); it != cend; ++it) {
const PluginSpec *ps = *it;
str << " " << ps->name() << ' ' << ps->version() << ' ' << ps->description() << '\n';
}
......@@ -699,16 +699,16 @@ void PluginManager::startTests()
* \fn bool PluginManager::runningTests() const
* \internal
*/
bool PluginManager::runningTests() const
bool PluginManager::runningTests()
{
return !d->testSpecs.isEmpty();
return !m_instance->d->testSpecs.isEmpty();
}
/*!
* \fn QString PluginManager::testDataDirectory() const
* \internal
*/
QString PluginManager::testDataDirectory() const
QString PluginManager::testDataDirectory()
{
QByteArray ba = qgetenv("QTCREATOR_TEST_DIR");
QString s = QString::fromLocal8Bit(ba.constData(), ba.size());
......@@ -728,7 +728,7 @@ QString PluginManager::testDataDirectory() const
void PluginManager::profilingReport(const char *what, const PluginSpec *spec)
{
d->profilingReport(what, spec);
m_instance->d->profilingReport(what, spec);
}
......@@ -739,7 +739,7 @@ void PluginManager::profilingReport(const char *what, const PluginSpec *spec)
*/
QList<PluginSpec *> PluginManager::loadQueue()
{
return d->loadQueue();
return m_instance->d->loadQueue();
}
//============PluginManagerPrivate===========
......@@ -1286,9 +1286,9 @@ void PluginManagerPrivate::profilingReport(const char *what, const PluginSpec *s
\sa addObject()
*/
QObject *PluginManager::getObjectByName(const QString &name) const
QObject *PluginManager::getObjectByName(const QString &name)
{
QReadLocker lock(&m_lock);
QReadLocker lock(&m_instance->m_lock);
QList<QObject *> all = allObjects();
foreach (QObject *obj, all) {
if (obj->objectName() == name)
......@@ -1303,10 +1303,10 @@ QObject *PluginManager::getObjectByName(const QString &name) const
\sa addObject()
*/
QObject *PluginManager::getObjectByClassName(const QString &className) const
QObject *PluginManager::getObjectByClassName(const QString &className)
{
const QByteArray ba = className.toUtf8();
QReadLocker lock(&m_lock);
QReadLocker lock(&m_instance->m_lock);
QList<QObject *> all = allObjects();
foreach (QObject *obj, all) {
if (obj->inherits(ba.constData()))
......
......@@ -66,12 +66,12 @@ public:
virtual ~PluginManager();
// Object pool operations
void addObject(QObject *obj);
void removeObject(QObject *obj);
QList<QObject *> allObjects() const;
template <typename T> QList<T *> getObjects() const
static void addObject(QObject *obj);
static void removeObject(QObject *obj);
static QList<QObject *> allObjects();
template <typename T> static QList<T *> getObjects()
{
QReadLocker lock(&m_lock);
QReadLocker lock(&m_instance->m_lock);
QList<T *> results;
QList<QObject *> all = allObjects();
QList<T *> result;
......@@ -82,9 +82,9 @@ public:
}
return results;
}
template <typename T> T *getObject() const
template <typename T> static T *getObject()
{
QReadLocker lock(&m_lock);
QReadLocker lock(&m_instance->m_lock);
QList<QObject *> all = allObjects();
T *result = 0;
foreach (QObject *obj, all) {
......@@ -94,43 +94,43 @@ public:
return result;
}
QObject *getObjectByName(const QString &name) const;
QObject *getObjectByClassName(const QString &className) const;
static QObject *getObjectByName(const QString &name);
static QObject *getObjectByClassName(const QString &className);
// Plugin operations
QList<PluginSpec *> loadQueue();
void loadPlugins();
QStringList pluginPaths() const;
void setPluginPaths(const QStringList &paths);
QList<PluginSpec *> plugins() const;
QHash<QString, PluginCollection *> pluginCollections() const;
void setFileExtension(const QString &extension);
QString fileExtension() const;
bool hasError() const;
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();
// Settings
void setSettings(QSettings *settings);
QSettings *settings() const;
void setGlobalSettings(QSettings *settings);
QSettings *globalSettings() const;
void writeSettings();
static void setSettings(QSettings *settings);
static QSettings *settings();
static void setGlobalSettings(QSettings *settings);
static QSettings *globalSettings();
static void writeSettings();
// command line arguments
QStringList arguments() const;
bool parseOptions(const QStringList &args,
static QStringList arguments();
static bool parseOptions(const QStringList &args,
const QMap<QString, bool> &appOptions,
QMap<QString, QString> *foundAppOptions,
QString *errorString);
static void formatOptions(QTextStream &str, int optionIndentation, int descriptionIndentation);
void formatPluginOptions(QTextStream &str, int optionIndentation, int descriptionIndentation) const;
void formatPluginVersions(QTextStream &str) const;
static void formatPluginOptions(QTextStream &str, int optionIndentation, int descriptionIndentation);
static void formatPluginVersions(QTextStream &str);
QString serializedArguments() const;
static QString serializedArguments();
bool runningTests() const;
QString testDataDirectory() const;
static bool runningTests();
static QString testDataDirectory();
void profilingReport(const char *what, const PluginSpec *spec = 0);
static void profilingReport(const char *what, const PluginSpec *spec = 0);
signals:
void objectAdded(QObject *obj);
......