Commit 68c49a65 authored by Lasse Holmstedt's avatar Lasse Holmstedt

Plugin manager for enabling/disabling plugins

Go to About Plugins and enable/disable plugins from there.

Reviewed-by: mae
parent f4487c4c
......@@ -202,7 +202,6 @@ int main(int argc, char **argv)
QLatin1String("Nokia"), QLatin1String("QtCreator"));
locale = settings.value("General/OverrideLanguage", locale).toString();
const QString &creatorTrPath = QCoreApplication::applicationDirPath()
+ QLatin1String(SHARE_PATH "/translations");
if (translator.load(QLatin1String("qtcreator_") + locale, creatorTrPath)) {
......
......@@ -19,14 +19,16 @@ HEADERS += pluginerrorview.h \
pluginspec_p.h \
pluginview.h \
pluginview_p.h \
optionsparser.h
optionsparser.h \
plugincollection.h
SOURCES += pluginerrorview.cpp \
plugindetailsview.cpp \
iplugin.cpp \
pluginmanager.cpp \
pluginspec.cpp \
pluginview.cpp \
optionsparser.cpp
optionsparser.cpp \
plugincollection.cpp
FORMS += pluginview.ui \
pluginerrorview.ui \
plugindetailsview.ui
......
......@@ -128,8 +128,7 @@ bool OptionsParser::checkForNoLoadOption()
"The plugin '%1' does not exist.").arg(m_currentArg);
m_hasError = true;
} else {
m_pmPrivate->pluginSpecs.removeAll(spec);
delete spec;
m_pmPrivate->removePluginSpec(spec);
m_isDependencyRefreshNeeded = true;
}
}
......
#include "plugincollection.h"
#include "pluginspec.h"
namespace ExtensionSystem {
PluginCollection::PluginCollection(const QString& name) :
m_name(name)
{
}
PluginCollection::~PluginCollection()
{
}
QString PluginCollection::name() const
{
return m_name;
}
void PluginCollection::addPlugin(PluginSpec *spec)
{
m_plugins.append(spec);
}
void PluginCollection::removePlugin(PluginSpec *spec)
{
m_plugins.removeOne(spec);
}
QList<PluginSpec *> PluginCollection::plugins() const
{
return m_plugins;
}
}
#ifndef PLUGINCOLLECTION_H
#define PLUGINCOLLECTION_H
#include <QList>
#include <QString>
#include "extensionsystem_global.h"
namespace ExtensionSystem {
class PluginSpec;
class EXTENSIONSYSTEM_EXPORT PluginCollection
{
public:
explicit PluginCollection(const QString& name);
~PluginCollection();
QString name() const;
void addPlugin(PluginSpec *spec);
void removePlugin(PluginSpec *spec);
QList<PluginSpec *> plugins() const;
private:
QString m_name;
QList<PluginSpec *> m_plugins;
};
}
#endif // PLUGINCOLLECTION_H
......@@ -78,6 +78,10 @@ void PluginDetailsView::update(PluginSpec *spec)
m_ui->vendor->setText(spec->vendor());
const QString link = QString::fromLatin1("<a href=\"%1\">%1</a>").arg(spec->url());
m_ui->url->setText(link);
QString component = tr("None");
if (!spec->category().isEmpty())
component = spec->category();
m_ui->component->setText(component);
m_ui->location->setText(QDir::toNativeSeparators(spec->filePath()));
m_ui->description->setText(spec->description());
m_ui->copyright->setText(spec->copyright());
......
......@@ -66,7 +66,7 @@
<item row="3" column="1">
<widget class="QLabel" name="vendor"/>
</item>
<item row="4" column="0">
<item row="5" column="0">
<widget class="QLabel" name="label_6">
<property name="text">
<string>Url:</string>
......@@ -76,14 +76,14 @@
</property>
</widget>
</item>
<item row="4" column="1">
<item row="5" column="1">
<widget class="QLabel" name="url">
<property name="openExternalLinks">
<bool>true</bool>
</property>
</widget>
</item>
<item row="5" column="0">
<item row="6" column="0">
<widget class="QLabel" name="label_7">
<property name="text">
<string>Location:</string>
......@@ -93,14 +93,14 @@
</property>
</widget>
</item>
<item row="5" column="1">
<item row="6" column="1">
<widget class="QLabel" name="location">
<property name="wordWrap">
<bool>false</bool>
</property>
</widget>
</item>
<item row="6" column="0">
<item row="7" column="0">
<layout class="QVBoxLayout">
<item>
<widget class="QLabel" name="label_8">
......@@ -127,7 +127,7 @@
</item>
</layout>
</item>
<item row="6" column="1">
<item row="7" column="1">
<widget class="QTextEdit" name="description">
<property name="tabChangesFocus">
<bool>true</bool>
......@@ -137,7 +137,7 @@
</property>
</widget>
</item>
<item row="7" column="0">
<item row="8" column="0">
<widget class="QLabel" name="label_5">
<property name="text">
<string>Copyright:</string>
......@@ -147,10 +147,10 @@
</property>
</widget>
</item>
<item row="7" column="1">
<item row="8" column="1">
<widget class="QLabel" name="copyright"/>
</item>
<item row="8" column="0">
<item row="9" column="0">
<layout class="QVBoxLayout">
<item>
<widget class="QLabel" name="label_9">
......@@ -177,7 +177,7 @@
</item>
</layout>
</item>
<item row="8" column="1">
<item row="9" column="1">
<widget class="QTextEdit" name="license">
<property name="tabChangesFocus">
<bool>true</bool>
......@@ -187,7 +187,7 @@
</property>
</widget>
</item>
<item row="9" column="0">
<item row="10" column="0">
<layout class="QVBoxLayout">
<item>
<widget class="QLabel" name="label_10">
......@@ -214,9 +214,26 @@
</item>
</layout>
</item>
<item row="9" column="1">
<item row="10" column="1">
<widget class="QListWidget" name="dependencies"/>
</item>
<item row="4" column="0">
<widget class="QLabel" name="label_11">
<property name="text">
<string>Group:</string>
</property>
<property name="alignment">
<set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
</property>
</widget>
</item>
<item row="4" column="1">
<widget class="QLabel" name="component">
<property name="text">
<string/>
</property>
</widget>
</item>
</layout>
</widget>
<resources/>
......
......@@ -33,6 +33,7 @@
#include "pluginspec_p.h"
#include "optionsparser.h"
#include "iplugin.h"
#include "plugincollection.h"
#include <QtCore/QMetaProperty>
#include <QtCore/QDir>
......@@ -40,11 +41,14 @@
#include <QtCore/QWriteLocker>
#include <QtCore/QTime>
#include <QtCore/QDateTime>
#include <QtCore/QSettings>
#include <QtDebug>
#ifdef WITH_TESTS
#include <QTest>
#endif
static const char * const C_IGNORED_PLUGINS = "Plugins/Ignored";
typedef QList<ExtensionSystem::PluginSpec *> PluginSpecSet;
enum { debugLeaks = 0 };
......@@ -297,6 +301,16 @@ void PluginManager::setFileExtension(const QString &extension)
d->extension = extension;
}
void PluginManager::loadSettings()
{
d->loadSettings();
}
void PluginManager::writeSettings()
{
d->writeSettings();
}
/*!
\fn QStringList PluginManager::arguments() const
The arguments left over after parsing (Neither startup nor plugin
......@@ -322,6 +336,11 @@ QList<PluginSpec *> PluginManager::plugins() const
return d->pluginSpecs;
}
QHash<QString, PluginCollection *> PluginManager::pluginCollections() const
{
return d->pluginCategories;
}
/*!
\fn QString PluginManager::serializedArguments() const
......@@ -593,11 +612,35 @@ PluginManagerPrivate::~PluginManagerPrivate()
{
stopAll();
qDeleteAll(pluginSpecs);
qDeleteAll(pluginCategories);
if (!allObjects.isEmpty()) {
qDebug() << "There are" << allObjects.size() << "objects left in the plugin manager pool: " << allObjects;
}
}
void PluginManagerPrivate::writeSettings()
{
QSettings settings(QSettings::IniFormat, QSettings::UserScope,
QLatin1String("Nokia"), QLatin1String("QtCreator"));
QStringList notLoadedPlugins;
foreach(PluginSpec *spec, pluginSpecs) {
if (!spec->loadOnStartup())
notLoadedPlugins.append(spec->name());
}
settings.setValue(QLatin1String(C_IGNORED_PLUGINS), notLoadedPlugins);
}
void PluginManagerPrivate::loadSettings()
{
const QSettings settings(QSettings::IniFormat, QSettings::UserScope,
QLatin1String("Nokia"), QLatin1String("QtCreator"));
notLoadedPlugins = settings.value(QLatin1String(C_IGNORED_PLUGINS)).toStringList();
}
void PluginManagerPrivate::stopAll()
{
QList<PluginSpec *> queue = loadQueue();
......@@ -719,9 +762,11 @@ bool PluginManagerPrivate::loadQueue(PluginSpec *spec, QList<PluginSpec *> &queu
circularityCheckQueue.append(spec);
// check if we have the dependencies
if (spec->state() == PluginSpec::Invalid || spec->state() == PluginSpec::Read) {
spec->d->hasError = true;
spec->d->errorString += "\n";
spec->d->errorString += PluginManager::tr("Cannot load plugin because dependencies are not resolved");
if (!spec->d->ignoreOnStartup && spec->d->loadOnStartup) {
spec->d->hasError = true;
spec->d->errorString += "\n";
spec->d->errorString += PluginManager::tr("Cannot load plugin because dependencies are not resolved");
}
return false;
}
// add dependencies
......@@ -745,8 +790,9 @@ bool PluginManagerPrivate::loadQueue(PluginSpec *spec, QList<PluginSpec *> &queu
*/
void PluginManagerPrivate::loadPlugin(PluginSpec *spec, PluginSpec::State destState)
{
if (spec->hasError())
if (spec->hasError() || spec->ignoreOnStartup())
return;
switch (destState) {
case PluginSpec::Running:
profilingReport(">initializeExtensions", spec);
......@@ -796,6 +842,7 @@ void PluginManagerPrivate::loadPlugin(PluginSpec *spec, PluginSpec::State destSt
void PluginManagerPrivate::setPluginPaths(const QStringList &paths)
{
pluginPaths = paths;
loadSettings();
readPluginPaths();
}
......@@ -805,8 +852,10 @@ void PluginManagerPrivate::setPluginPaths(const QStringList &paths)
*/
void PluginManagerPrivate::readPluginPaths()
{
qDeleteAll(pluginCategories);
qDeleteAll(pluginSpecs);
pluginSpecs.clear();
pluginCategories.clear();
QStringList specFiles;
QStringList searchPaths = pluginPaths;
......@@ -820,9 +869,25 @@ void PluginManagerPrivate::readPluginPaths()
foreach (const QFileInfo &subdir, dirs)
searchPaths << subdir.absoluteFilePath();
}
defaultCollection = new PluginCollection(QString());
pluginCategories.insert("", defaultCollection);
foreach (const QString &specFile, specFiles) {
PluginSpec *spec = new PluginSpec;
spec->d->read(specFile);
PluginCollection *collection = 0;
// find correct plugin collection or create a new one
if (pluginCategories.contains(spec->category()))
collection = pluginCategories.value(spec->category());
else {
collection = new PluginCollection(spec->category());
pluginCategories.insert(spec->category(), collection);
}
if (notLoadedPlugins.contains(spec->name()))
spec->setLoadOnStartup(false);
collection->addPlugin(spec);
pluginSpecs.append(spec);
}
resolveDependencies();
......@@ -862,6 +927,21 @@ PluginSpec *PluginManagerPrivate::pluginForOption(const QString &option, bool *r
return 0;
}
void PluginManagerPrivate::removePluginSpec(PluginSpec *spec)
{
pluginSpecs.removeAll(spec);
if (pluginCategories.contains(spec->category()))
pluginCategories.value(spec->category())->removePlugin(spec);
foreach(PluginSpec *dep, spec->dependencySpecs()) {
dep->removeDependentPlugin(spec);
}
delete spec;
spec = 0;
}
PluginSpec *PluginManagerPrivate::pluginByName(const QString &name) const
{
foreach (PluginSpec *spec, pluginSpecs)
......
......@@ -42,7 +42,7 @@ class QTextStream;
QT_END_NAMESPACE
namespace ExtensionSystem {
class PluginCollection;
namespace Internal {
class PluginManagerPrivate;
}
......@@ -95,9 +95,14 @@ public:
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;
// Settings
void loadSettings();
void writeSettings();
// command line arguments
QStringList arguments() const;
bool parseOptions(const QStringList &args,
......
......@@ -45,6 +45,7 @@ QT_END_NAMESPACE
namespace ExtensionSystem {
class PluginManager;
class PluginCollection;
namespace Internal {
......@@ -68,12 +69,17 @@ public:
void resolveDependencies();
void initProfiling();
void profilingReport(const char *what, const PluginSpec *spec = 0);
void loadSettings();
void writeSettings();
void removePluginSpec(PluginSpec *spec);
QHash<QString, PluginCollection *> pluginCategories;
QList<PluginSpec *> pluginSpecs;
QList<PluginSpec *> testSpecs;
QStringList pluginPaths;
QString extension;
QList<QObject *> allObjects; // ### make this a QList<QPointer<QObject> > > ?
QStringList notLoadedPlugins;
QStringList arguments;
QScopedPointer<QTime> m_profileTimer;
......@@ -87,6 +93,7 @@ public:
static PluginSpec *createSpec();
static PluginSpecPrivate *privateSpec(PluginSpec *spec);
private:
PluginCollection *defaultCollection;
PluginManager *q;
void readPluginPaths();
......
......@@ -226,6 +226,30 @@ QString PluginSpec::url() const
return d->url;
}
/*!
\fn QString PluginSpec::category() const
The category that the plugin belongs to. Categories are groups of plugins which allow for keeping them together in the UI.
Returns an empty string if the plugin does not belong to a category.
*/
QString PluginSpec::category() const
{
return d->category;
}
/*!
\fn bool PluginSpec::loadOnStartup() const
True if the plugin is loaded at startup. True by default - the user can change it from the Plugin settings.
*/
bool PluginSpec::loadOnStartup() const
{
return d->loadOnStartup;
}
bool PluginSpec::ignoreOnStartup() const
{
return d->ignoreOnStartup;
}
/*!
\fn QList<PluginDependency> PluginSpec::dependencies() const
The plugin dependencies. This is valid after the PluginSpec::Read state is reached.
......@@ -358,6 +382,33 @@ QList<PluginSpec *> PluginSpec::dependencySpecs() const
return d->dependencySpecs;
}
/*!
\fn QList<PluginSpec *> PluginSpec::providesSpecs() const
Returns the list of plugins that depend on this one.
\sa PluginSpec::dependencySpecs()
*/
QList<PluginSpec *> PluginSpec::providesSpecs() const
{
return d->providesSpecs;
}
/*!
\fn void PluginSpec::addDependentPlugin(PluginSpec *dependent)
Adds a dependent the list of plugins that depend on this one.
\sa PluginSpec::providesSpecs()
*/
void PluginSpec::addDependentPlugin(PluginSpec *dependent)
{
d->providesSpecs.append(dependent);
}
void PluginSpec::removeDependentPlugin(PluginSpec *dependent)
{
d->providesSpecs.removeOne(dependent);
}
//==========PluginSpecPrivate==================
namespace {
......@@ -370,6 +421,7 @@ namespace {
const char * const LICENSE = "license";
const char * const DESCRIPTION = "description";
const char * const URL = "url";
const char * const CATEGORY = "category";
const char * const DEPENDENCYLIST = "dependencyList";
const char * const DEPENDENCY = "dependency";
const char * const DEPENDENCY_NAME = "name";
......@@ -384,7 +436,10 @@ namespace {
\internal
*/
PluginSpecPrivate::PluginSpecPrivate(PluginSpec *spec)
: plugin(0),
:
loadOnStartup(true),
ignoreOnStartup(false),
plugin(0),
state(PluginSpec::Invalid),
hasError(false),
q(spec)
......@@ -405,6 +460,7 @@ bool PluginSpecPrivate::read(const QString &fileName)
= license
= description
= url
= category
= location
= "";
state = PluginSpec::Invalid;
......@@ -440,6 +496,16 @@ bool PluginSpecPrivate::read(const QString &fileName)
return true;
}
void PluginSpec::setLoadOnStartup(bool value)
{
d->loadOnStartup = value;
}
void PluginSpec::setIgnoreOnStartup(bool value)
{
d->ignoreOnStartup = value;
}
/*!
\fn bool PluginSpecPrivate::reportError(const QString &err)
\internal
......@@ -523,6 +589,8 @@ void PluginSpecPrivate::readPluginSpec(QXmlStreamReader &reader)
description = reader.readElementText().trimmed();
else if (element == URL)
url = reader.readElementText().trimmed();
else if (element == CATEGORY)
category = reader.readElementText().trimmed();
else if (element == DEPENDENCYLIST)
readDependencies(reader);
else if (element == ARGUMENTLIST)
......@@ -725,9 +793,15 @@ bool PluginSpecPrivate::resolveDependencies(const QList<PluginSpec *> &specs)
QList<PluginSpec *> resolvedDependencies;
foreach (const PluginDependency &dependency, dependencies) {
PluginSpec *found = 0;
foreach (PluginSpec *spec, specs) {
if (spec->provides(dependency.name, dependency.version)) {
found = spec;
if (!spec->loadOnStartup() || spec->ignoreOnStartup())
ignoreOnStartup = true;
spec->addDependentPlugin(q);
break;
}
}
......@@ -743,8 +817,12 @@ bool PluginSpecPrivate::resolveDependencies(const QList<PluginSpec *> &specs)
}
if (hasError)
return false;
dependencySpecs = resolvedDependencies;
state = PluginSpec::Resolved;
if (loadOnStartup && !ignoreOnStartup)
state = PluginSpec::Resolved;
return true;
}
......
......@@ -78,6 +78,10 @@ public:
QString license() const;
QString description() const;
QString url() const;
QString category() const;
bool loadOnStartup() const;
// true if loading was not done due to user unselecting this plugin or its dependencies
bool ignoreOnStartup() const;
QList<PluginDependency> dependencies() const;
typedef QList<PluginArgumentDescription> PluginArgumentDescriptions;
......@@ -87,6 +91,9 @@ public:
QString location() const;
QString filePath() const;
void setLoadOnStartup(bool value);
void setIgnoreOnStartup(bool value);
QStringList arguments() const;
void setArguments(const QStringList &arguments);
void addArgument(const QString &argument);
......@@ -96,6 +103,13 @@ public:
// dependency specs, valid after 'Resolved' state is reached
QList<PluginSpec *> dependencySpecs() const;
// list of plugins that depend on this - e.g. this plugins provides for them
QList<PluginSpec *> providesSpecs() const;
// add/remove from providesSpecs
void addDependentPlugin(PluginSpec *dependent);
void removeDependentPlugin(PluginSpec *dependent);
// linked plugin instance, valid after 'Loaded' state is reached
IPlugin *plugin() const;
......
......@@ -67,12 +67,16 @@ public:
QString license;
QString description;
QString url;
QString category;
QList<PluginDependency> dependencies;
bool loadOnStartup;
bool ignoreOnStartup;
QString location;
QString filePath;
QStringList arguments;
QList<PluginSpec *> providesSpecs;
QList<PluginSpec *> dependencySpecs;
PluginSpec::PluginArgumentDescriptions argumentDescriptions;
IPlugin *plugin;
......
This diff is collapsed.
......@@ -32,7 +32,9 @@
#include "extensionsystem_global.h"
#include <QtCore/QHash>
#include <QtGui/QWidget>
#include <QtGui/QIcon>
QT_BEGIN_NAMESPACE
class QTreeWidgetItem;
......@@ -42,6 +44,7 @@ namespace ExtensionSystem {
class PluginManager;
class PluginSpec;
class PluginCollection;
namespace Internal {
class PluginViewPrivate;
......@@ -63,15 +66,30 @@ public:
signals:
void currentPluginChanged(ExtensionSystem::PluginSpec *spec);
void pluginActivated(ExtensionSystem::PluginSpec *spec);
void pluginSettingsChanged(ExtensionSystem::PluginSpec *spec);
private slots:
void updatePluginSettings(QTreeWidgetItem *item, int column);
void updateList();
void selectPlugin(QTreeWidgetItem *current);