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

Make PluginManager mostly static.



Change-Id: Ib938aa4999c7c418a82304c5cca2e8748ef9d228
Reviewed-by: default avatarhjk <qthjk@ovi.com>
parent 9daa3400
...@@ -61,6 +61,8 @@ ...@@ -61,6 +61,8 @@
#include <qtsystemexceptionhandler.h> #include <qtsystemexceptionhandler.h>
#endif #endif
using namespace ExtensionSystem;
enum { OptionIndent = 4, DescriptionIndent = 34 }; enum { OptionIndent = 4, DescriptionIndent = 34 };
static const char appNameC[] = "Qt Creator"; static const char appNameC[] = "Qt Creator";
...@@ -89,7 +91,7 @@ static const char SETTINGS_OPTION[] = "-settingspath"; ...@@ -89,7 +91,7 @@ static const char SETTINGS_OPTION[] = "-settingspath";
static const char PID_OPTION[] = "-pid"; static const char PID_OPTION[] = "-pid";
#endif #endif
typedef QList<ExtensionSystem::PluginSpec *> PluginSpecSet; typedef QList<PluginSpec *> PluginSpecSet;
// Helpers for displaying messages. Note that there is no console on Windows. // Helpers for displaying messages. Note that there is no console on Windows.
#ifdef Q_OS_WIN #ifdef Q_OS_WIN
...@@ -128,24 +130,23 @@ static void displayError(const QString &t) ...@@ -128,24 +130,23 @@ static void displayError(const QString &t)
#endif #endif
static void printVersion(const ExtensionSystem::PluginSpec *coreplugin, static void printVersion(const PluginSpec *coreplugin)
const ExtensionSystem::PluginManager &pm)
{ {
QString version; QString version;
QTextStream str(&version); QTextStream str(&version);
str << '\n' << appNameC << ' ' << coreplugin->version()<< " based on Qt " << qVersion() << "\n\n"; str << '\n' << appNameC << ' ' << coreplugin->version()<< " based on Qt " << qVersion() << "\n\n";
pm.formatPluginVersions(str); PluginManager::formatPluginVersions(str);
str << '\n' << coreplugin->copyright() << '\n'; str << '\n' << coreplugin->copyright() << '\n';
displayHelpText(version); displayHelpText(version);
} }
static void printHelp(const QString &a0, const ExtensionSystem::PluginManager &pm) static void printHelp(const QString &a0)
{ {
QString help; QString help;
QTextStream str(&help); QTextStream str(&help);
str << "Usage: " << a0 << fixedOptionsC; str << "Usage: " << a0 << fixedOptionsC;
ExtensionSystem::PluginManager::formatOptions(str, OptionIndent, DescriptionIndent); PluginManager::formatOptions(str, OptionIndent, DescriptionIndent);
pm.formatPluginOptions(str, OptionIndent, DescriptionIndent); PluginManager::formatPluginOptions(str, OptionIndent, DescriptionIndent);
displayHelpText(help); displayHelpText(help);
} }
...@@ -264,10 +265,10 @@ int main(int argc, char **argv) ...@@ -264,10 +265,10 @@ int main(int argc, char **argv)
QSettings *globalSettings = new QSettings(QSettings::IniFormat, QSettings::SystemScope, QSettings *globalSettings = new QSettings(QSettings::IniFormat, QSettings::SystemScope,
QLatin1String(Core::Constants::IDE_SETTINGSVARIANT_STR), QLatin1String(Core::Constants::IDE_SETTINGSVARIANT_STR),
QLatin1String("QtCreator")); QLatin1String("QtCreator"));
ExtensionSystem::PluginManager pluginManager; PluginManager pluginManager;
pluginManager.setFileExtension(QLatin1String("pluginspec")); PluginManager::setFileExtension(QLatin1String("pluginspec"));
pluginManager.setGlobalSettings(globalSettings); PluginManager::setGlobalSettings(globalSettings);
pluginManager.setSettings(settings); PluginManager::setSettings(settings);
QTranslator translator; QTranslator translator;
QTranslator qtTranslator; QTranslator qtTranslator;
...@@ -323,7 +324,7 @@ int main(int argc, char **argv) ...@@ -323,7 +324,7 @@ int main(int argc, char **argv)
#endif #endif
// Load // Load
const QStringList pluginPaths = getPluginPaths(); const QStringList pluginPaths = getPluginPaths();
pluginManager.setPluginPaths(pluginPaths); PluginManager::setPluginPaths(pluginPaths);
QMap<QString, QString> foundAppOptions; QMap<QString, QString> foundAppOptions;
if (arguments.size() > 1) { if (arguments.size() > 1) {
...@@ -338,16 +339,16 @@ int main(int argc, char **argv) ...@@ -338,16 +339,16 @@ int main(int argc, char **argv)
appOptions.insert(QLatin1String(PID_OPTION), true); appOptions.insert(QLatin1String(PID_OPTION), true);
#endif #endif
QString errorMessage; QString errorMessage;
if (!pluginManager.parseOptions(arguments, appOptions, &foundAppOptions, &errorMessage)) { if (!PluginManager::parseOptions(arguments, appOptions, &foundAppOptions, &errorMessage)) {
displayError(errorMessage); displayError(errorMessage);
printHelp(QFileInfo(app.applicationFilePath()).baseName(), pluginManager); printHelp(QFileInfo(app.applicationFilePath()).baseName());
return -1; return -1;
} }
} }
const PluginSpecSet plugins = pluginManager.plugins(); const PluginSpecSet plugins = PluginManager::plugins();
ExtensionSystem::PluginSpec *coreplugin = 0; PluginSpec *coreplugin = 0;
foreach (ExtensionSystem::PluginSpec *spec, plugins) { foreach (PluginSpec *spec, plugins) {
if (spec->name() == QLatin1String(corePluginNameC)) { if (spec->name() == QLatin1String(corePluginNameC)) {
coreplugin = spec; coreplugin = spec;
break; break;
...@@ -364,14 +365,14 @@ int main(int argc, char **argv) ...@@ -364,14 +365,14 @@ int main(int argc, char **argv)
return 1; return 1;
} }
if (foundAppOptions.contains(QLatin1String(VERSION_OPTION))) { if (foundAppOptions.contains(QLatin1String(VERSION_OPTION))) {
printVersion(coreplugin, pluginManager); printVersion(coreplugin);
return 0; return 0;
} }
if (foundAppOptions.contains(QLatin1String(HELP_OPTION1)) if (foundAppOptions.contains(QLatin1String(HELP_OPTION1))
|| foundAppOptions.contains(QLatin1String(HELP_OPTION2)) || foundAppOptions.contains(QLatin1String(HELP_OPTION2))
|| foundAppOptions.contains(QLatin1String(HELP_OPTION3)) || foundAppOptions.contains(QLatin1String(HELP_OPTION3))
|| foundAppOptions.contains(QLatin1String(HELP_OPTION4))) { || foundAppOptions.contains(QLatin1String(HELP_OPTION4))) {
printHelp(QFileInfo(app.applicationFilePath()).baseName(), pluginManager); printHelp(QFileInfo(app.applicationFilePath()).baseName());
return 0; return 0;
} }
...@@ -387,7 +388,7 @@ int main(int argc, char **argv) ...@@ -387,7 +388,7 @@ int main(int argc, char **argv)
#endif #endif
if (app.isRunning() && (pid != -1 || foundAppOptions.contains(QLatin1String(CLIENT_OPTION)))) { 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; return 0;
// Message could not be send, maybe it was in the process of quitting // Message could not be send, maybe it was in the process of quitting
...@@ -395,7 +396,7 @@ int main(int argc, char **argv) ...@@ -395,7 +396,7 @@ int main(int argc, char **argv)
// Nah app is still running, ask the user // Nah app is still running, ask the user
int button = askMsgSendFailed(); int button = askMsgSendFailed();
while(button == QMessageBox::Retry) { while(button == QMessageBox::Retry) {
if (app.sendMessage(pluginManager.serializedArguments(), 5000 /*timeout*/, pid)) if (app.sendMessage(PluginManager::serializedArguments(), 5000 /*timeout*/, pid))
return 0; return 0;
if (!app.isRunning(pid)) // App quit while we were trying so start a new creator if (!app.isRunning(pid)) // App quit while we were trying so start a new creator
button = QMessageBox::Yes; button = QMessageBox::Yes;
...@@ -407,13 +408,13 @@ int main(int argc, char **argv) ...@@ -407,13 +408,13 @@ int main(int argc, char **argv)
} }
} }
pluginManager.loadPlugins(); PluginManager::loadPlugins();
if (coreplugin->hasError()) { if (coreplugin->hasError()) {
displayError(msgCoreLoadFailure(coreplugin->errorString())); displayError(msgCoreLoadFailure(coreplugin->errorString()));
return 1; return 1;
} }
if (pluginManager.hasError()) { if (PluginManager::hasError()) {
ExtensionSystem::PluginErrorOverview errorOverview(&pluginManager); PluginErrorOverview errorOverview;
errorOverview.exec(); errorOverview.exec();
} }
...@@ -430,7 +431,7 @@ int main(int argc, char **argv) ...@@ -430,7 +431,7 @@ int main(int argc, char **argv)
#ifdef WITH_TESTS #ifdef WITH_TESTS
// Do this after the event loop has started // Do this after the event loop has started
if (pluginManager.runningTests()) if (PluginManager::runningTests())
QTimer::singleShot(100, &pluginManager, SLOT(startTests())); QTimer::singleShot(100, &pluginManager, SLOT(startTests()));
#endif #endif
......
...@@ -23,7 +23,6 @@ HEADERS += pluginerrorview.h \ ...@@ -23,7 +23,6 @@ HEADERS += pluginerrorview.h \
pluginspec.h \ pluginspec.h \
pluginspec_p.h \ pluginspec_p.h \
pluginview.h \ pluginview.h \
pluginview_p.h \
optionsparser.h \ optionsparser.h \
plugincollection.h \ plugincollection.h \
pluginerroroverview.h pluginerroroverview.h
......
...@@ -185,9 +185,8 @@ IPlugin::IPlugin() ...@@ -185,9 +185,8 @@ IPlugin::IPlugin()
*/ */
IPlugin::~IPlugin() IPlugin::~IPlugin()
{ {
PluginManager *pm = PluginManager::instance();
foreach (QObject *obj, d->addedObjectsInReverseOrder) foreach (QObject *obj, d->addedObjectsInReverseOrder)
pm->removeObject(obj); PluginManager::removeObject(obj);
qDeleteAll(d->addedObjectsInReverseOrder); qDeleteAll(d->addedObjectsInReverseOrder);
d->addedObjectsInReverseOrder.clear(); d->addedObjectsInReverseOrder.clear();
delete d; delete d;
...@@ -211,7 +210,7 @@ PluginSpec *IPlugin::pluginSpec() const ...@@ -211,7 +210,7 @@ PluginSpec *IPlugin::pluginSpec() const
*/ */
void IPlugin::addObject(QObject *obj) void IPlugin::addObject(QObject *obj)
{ {
PluginManager::instance()->addObject(obj); PluginManager::addObject(obj);
} }
/*! /*!
...@@ -227,7 +226,7 @@ void IPlugin::addObject(QObject *obj) ...@@ -227,7 +226,7 @@ void IPlugin::addObject(QObject *obj)
void IPlugin::addAutoReleasedObject(QObject *obj) void IPlugin::addAutoReleasedObject(QObject *obj)
{ {
d->addedObjectsInReverseOrder.prepend(obj); d->addedObjectsInReverseOrder.prepend(obj);
PluginManager::instance()->addObject(obj); PluginManager::addObject(obj);
} }
/*! /*!
...@@ -237,6 +236,6 @@ void IPlugin::addAutoReleasedObject(QObject *obj) ...@@ -237,6 +236,6 @@ void IPlugin::addAutoReleasedObject(QObject *obj)
*/ */
void IPlugin::removeObject(QObject *obj) void IPlugin::removeObject(QObject *obj)
{ {
PluginManager::instance()->removeObject(obj); PluginManager::removeObject(obj);
} }
...@@ -44,7 +44,7 @@ class PluginErrorOverviewPrivate : public QObject ...@@ -44,7 +44,7 @@ class PluginErrorOverviewPrivate : public QObject
{ {
Q_OBJECT Q_OBJECT
public: public:
PluginErrorOverviewPrivate(PluginManager *manager, QDialog *dialog); PluginErrorOverviewPrivate(QDialog *dialog);
~PluginErrorOverviewPrivate(); ~PluginErrorOverviewPrivate();
private slots: private slots:
...@@ -52,7 +52,6 @@ private slots: ...@@ -52,7 +52,6 @@ private slots:
private: private:
Ui::PluginErrorOverview *m_ui; Ui::PluginErrorOverview *m_ui;
PluginManager *m_manager;
}; };
} // Internal } // Internal
...@@ -61,9 +60,9 @@ private: ...@@ -61,9 +60,9 @@ private:
using namespace ExtensionSystem; using namespace ExtensionSystem;
using namespace ExtensionSystem::Internal; using namespace ExtensionSystem::Internal;
PluginErrorOverview::PluginErrorOverview(PluginManager *manager, QWidget *parent) : PluginErrorOverview::PluginErrorOverview(QWidget *parent) :
QDialog(parent), QDialog(parent),
d(new PluginErrorOverviewPrivate(manager, this)) d(new PluginErrorOverviewPrivate(this))
{ {
} }
...@@ -72,14 +71,13 @@ PluginErrorOverview::~PluginErrorOverview() ...@@ -72,14 +71,13 @@ PluginErrorOverview::~PluginErrorOverview()
delete d; delete d;
} }
PluginErrorOverviewPrivate::PluginErrorOverviewPrivate(PluginManager *manager, QDialog *dialog) PluginErrorOverviewPrivate::PluginErrorOverviewPrivate(QDialog *dialog)
: m_ui(new Ui::PluginErrorOverview), : m_ui(new Ui::PluginErrorOverview)
m_manager(manager)
{ {
m_ui->setupUi(dialog); m_ui->setupUi(dialog);
m_ui->buttonBox->addButton(tr("Continue"), QDialogButtonBox::AcceptRole); 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. // only show errors on startup if plugin is enabled.
if (spec->hasError() && spec->isEnabled() && !spec->isDisabledIndirectly()) { if (spec->hasError() && spec->isEnabled() && !spec->isDisabledIndirectly()) {
QListWidgetItem *item = new QListWidgetItem(spec->name()); QListWidgetItem *item = new QListWidgetItem(spec->name());
......
...@@ -50,7 +50,7 @@ class EXTENSIONSYSTEM_EXPORT PluginErrorOverview : public QDialog ...@@ -50,7 +50,7 @@ class EXTENSIONSYSTEM_EXPORT PluginErrorOverview : public QDialog
Q_OBJECT Q_OBJECT
public: public:
explicit PluginErrorOverview(PluginManager *manager, QWidget *parent = 0); explicit PluginErrorOverview(QWidget *parent = 0);
~PluginErrorOverview(); ~PluginErrorOverview();
private: private:
......
...@@ -290,7 +290,7 @@ PluginManager::~PluginManager() ...@@ -290,7 +290,7 @@ PluginManager::~PluginManager()
*/ */
void PluginManager::addObject(QObject *obj) void PluginManager::addObject(QObject *obj)
{ {
d->addObject(obj); m_instance->d->addObject(obj);
} }
/*! /*!
...@@ -300,7 +300,7 @@ void PluginManager::addObject(QObject *obj) ...@@ -300,7 +300,7 @@ void PluginManager::addObject(QObject *obj)
*/ */
void PluginManager::removeObject(QObject *obj) void PluginManager::removeObject(QObject *obj)
{ {
d->removeObject(obj); m_instance->d->removeObject(obj);
} }
/*! /*!
...@@ -310,9 +310,9 @@ void PluginManager::removeObject(QObject *obj) ...@@ -310,9 +310,9 @@ void PluginManager::removeObject(QObject *obj)
\sa PluginManager::getObject() \sa PluginManager::getObject()
\sa PluginManager::getObjects() \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 ...@@ -326,7 +326,7 @@ QList<QObject *> PluginManager::allObjects() const
*/ */
void PluginManager::loadPlugins() void PluginManager::loadPlugins()
{ {
return d->loadPlugins(); return m_instance->d->loadPlugins();
} }
/*! /*!
...@@ -334,7 +334,7 @@ void PluginManager::loadPlugins() ...@@ -334,7 +334,7 @@ void PluginManager::loadPlugins()
Returns true if any plugin has errors even though it is enabled. Returns true if any plugin has errors even though it is enabled.
Most useful to call after loadPlugins(). Most useful to call after loadPlugins().
*/ */
bool PluginManager::hasError() const bool PluginManager::hasError()
{ {
foreach (PluginSpec *spec, plugins()) { foreach (PluginSpec *spec, plugins()) {
// only show errors on startup if plugin is enabled. // only show errors on startup if plugin is enabled.
...@@ -360,9 +360,9 @@ void PluginManager::shutdown() ...@@ -360,9 +360,9 @@ void PluginManager::shutdown()
\sa setPluginPaths() \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 ...@@ -376,7 +376,7 @@ QStringList PluginManager::pluginPaths() const
*/ */
void PluginManager::setPluginPaths(const QStringList &paths) void PluginManager::setPluginPaths(const QStringList &paths)
{ {
d->setPluginPaths(paths); m_instance->d->setPluginPaths(paths);
} }
/*! /*!
...@@ -386,9 +386,9 @@ void PluginManager::setPluginPaths(const QStringList &paths) ...@@ -386,9 +386,9 @@ void PluginManager::setPluginPaths(const QStringList &paths)
\sa setFileExtension() \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 ...@@ -400,7 +400,7 @@ QString PluginManager::fileExtension() const
*/ */
void PluginManager::setFileExtension(const QString &extension) void PluginManager::setFileExtension(const QString &extension)
{ {
d->extension = extension; m_instance->d->extension = extension;
} }
/*! /*!
...@@ -409,7 +409,7 @@ void PluginManager::setFileExtension(const QString &extension) ...@@ -409,7 +409,7 @@ void PluginManager::setFileExtension(const QString &extension)
*/ */
void PluginManager::setSettings(QSettings *settings) void PluginManager::setSettings(QSettings *settings)
{ {
d->setSettings(settings); m_instance->d->setSettings(settings);
} }
/*! /*!
...@@ -418,28 +418,28 @@ void PluginManager::setSettings(QSettings *settings) ...@@ -418,28 +418,28 @@ void PluginManager::setSettings(QSettings *settings)
*/ */
void PluginManager::setGlobalSettings(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. 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. 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() void PluginManager::writeSettings()
{ {
d->writeSettings(); m_instance->d->writeSettings();
} }
/*! /*!
...@@ -447,9 +447,9 @@ void PluginManager::writeSettings() ...@@ -447,9 +447,9 @@ void PluginManager::writeSettings()
The arguments left over after parsing (Neither startup nor plugin The arguments left over after parsing (Neither startup nor plugin
arguments). Typically, this will be the list of files to open. 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 ...@@ -462,14 +462,14 @@ QStringList PluginManager::arguments() const
\sa setPluginPaths() \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;
} }
/*!