PluginSpec: Naming and encapsulation improvements

Prefer enabled state as a property as opposed to disabled state, and
make setter correspond to getter. Also move setters into private.

Change-Id: I5d002a12f4e540d5b38cc5865490d056ec75f296
Reviewed-by: Daniel Teske <daniel.teske@theqtcompany.com>
This commit is contained in:
Eike Ziller
2015-03-31 09:55:50 +02:00
parent fcc6b11230
commit d456fd0b8a
7 changed files with 72 additions and 64 deletions

View File

@@ -30,6 +30,8 @@
#include "optionsparser.h" #include "optionsparser.h"
#include "pluginspec_p.h"
#include <QCoreApplication> #include <QCoreApplication>
using namespace ExtensionSystem; using namespace ExtensionSystem;
@@ -151,7 +153,7 @@ bool OptionsParser::checkForLoadOption()
.arg(m_currentArg); .arg(m_currentArg);
m_hasError = true; m_hasError = true;
} else { } else {
spec->setForceEnabled(true); spec->d->setForceEnabled(true);
m_isDependencyRefreshNeeded = true; m_isDependencyRefreshNeeded = true;
} }
} }
@@ -170,7 +172,7 @@ bool OptionsParser::checkForNoLoadOption()
"The plugin \"%1\" does not exist.").arg(m_currentArg); "The plugin \"%1\" does not exist.").arg(m_currentArg);
m_hasError = true; m_hasError = true;
} else { } else {
spec->setForceDisabled(true); spec->d->setForceDisabled(true);
m_isDependencyRefreshNeeded = true; m_isDependencyRefreshNeeded = true;
} }
} }

View File

@@ -48,7 +48,7 @@ PluginErrorOverview::PluginErrorOverview(QWidget *parent) :
foreach (PluginSpec *spec, PluginManager::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->isEnabledInSettings() && !spec->isDisabledIndirectly()) { if (spec->hasError() && spec->isEnabledBySettings() && !spec->isDisabledIndirectly()) {
QListWidgetItem *item = new QListWidgetItem(spec->name()); QListWidgetItem *item = new QListWidgetItem(spec->name());
item->setData(Qt::UserRole, qVariantFromValue(spec)); item->setData(Qt::UserRole, qVariantFromValue(spec));
m_ui->pluginList->addItem(item); m_ui->pluginList->addItem(item);

View File

@@ -376,7 +376,7 @@ 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.
if (spec->hasError() && spec->isEnabledInSettings() && !spec->isDisabledIndirectly()) if (spec->hasError() && spec->isEnabledBySettings() && !spec->isDisabledIndirectly())
return true; return true;
} }
return false; return false;
@@ -820,9 +820,9 @@ void PluginManagerPrivate::writeSettings()
QStringList tempDisabledPlugins; QStringList tempDisabledPlugins;
QStringList tempForceEnabledPlugins; QStringList tempForceEnabledPlugins;
foreach (PluginSpec *spec, pluginSpecs) { foreach (PluginSpec *spec, pluginSpecs) {
if (!spec->isDisabledByDefault() && !spec->isEnabledInSettings()) if (spec->isEnabledByDefault() && !spec->isEnabledBySettings())
tempDisabledPlugins.append(spec->name()); tempDisabledPlugins.append(spec->name());
if (spec->isDisabledByDefault() && spec->isEnabledInSettings()) if (!spec->isEnabledByDefault() && spec->isEnabledBySettings())
tempForceEnabledPlugins.append(spec->name()); tempForceEnabledPlugins.append(spec->name());
} }
@@ -1398,17 +1398,17 @@ void PluginManagerPrivate::readPluginPaths()
} }
// defaultDisabledPlugins and defaultEnabledPlugins from install settings // defaultDisabledPlugins and defaultEnabledPlugins from install settings
// is used to override the defaults read from the plugin spec // is used to override the defaults read from the plugin spec
if (!spec->isDisabledByDefault() && defaultDisabledPlugins.contains(spec->name())) { if (spec->isEnabledByDefault() && defaultDisabledPlugins.contains(spec->name())) {
spec->setDisabledByDefault(true); spec->d->setEnabledByDefault(false);
spec->setEnabled(false); spec->d->setEnabledBySettings(false);
} else if (spec->isDisabledByDefault() && defaultEnabledPlugins.contains(spec->name())) { } else if (!spec->isEnabledByDefault() && defaultEnabledPlugins.contains(spec->name())) {
spec->setDisabledByDefault(false); spec->d->setEnabledByDefault(true);
spec->setEnabled(true); spec->d->setEnabledBySettings(true);
} }
if (spec->isDisabledByDefault() && forceEnabledPlugins.contains(spec->name())) if (!spec->isEnabledByDefault() && forceEnabledPlugins.contains(spec->name()))
spec->setEnabled(true); spec->d->setEnabledBySettings(true);
if (!spec->isDisabledByDefault() && disabledPlugins.contains(spec->name())) if (spec->isEnabledByDefault() && disabledPlugins.contains(spec->name()))
spec->setEnabled(false); spec->d->setEnabledBySettings(false);
collection->addPlugin(spec); collection->addPlugin(spec);
pluginSpecs.append(spec); pluginSpecs.append(spec);
@@ -1452,10 +1452,10 @@ void PluginManagerPrivate::enableOnlyTestedSpecs()
} }
} }
foreach (PluginSpec *spec, pluginSpecs) foreach (PluginSpec *spec, pluginSpecs)
spec->setForceDisabled(true); spec->d->setForceDisabled(true);
foreach (PluginSpec *spec, specsForTests) { foreach (PluginSpec *spec, specsForTests) {
spec->setForceDisabled(false); spec->d->setForceDisabled(false);
spec->setForceEnabled(true); spec->d->setForceEnabled(true);
} }
} }

View File

@@ -271,26 +271,25 @@ bool PluginSpec::isExperimental() const
} }
/*! /*!
Returns whether the plugin is disabled by default. Returns whether the plugin is enabled by default.
This might be because the plugin is experimental, or because A plugin might be disabled because the plugin is experimental, or because
the plugin manager's settings define it as disabled by default. the install settings define it as disabled by default.
*/ */
bool PluginSpec::isDisabledByDefault() const bool PluginSpec::isEnabledByDefault() const
{ {
return d->disabledByDefault; return d->enabledByDefault;
} }
/*! /*!
Returns whether the plugin should be loaded at startup. True by default. Returns whether the plugin should be loaded at startup,
taking into account the default enabled state, and the user's settings.
The user can change it from the Plugin settings.
\note This function returns true even if a plugin is disabled because its \note This function returns true even if a plugin is disabled because its
dependencies were not loaded, or an error occurred during loading it. dependencies were not loaded, or an error occurred during loading it.
*/ */
bool PluginSpec::isEnabledInSettings() const bool PluginSpec::isEnabledBySettings() const
{ {
return d->enabledInSettings; return d->enabledBySettings;
} }
/*! /*!
@@ -300,7 +299,7 @@ bool PluginSpec::isEnabledInSettings() const
bool PluginSpec::isEffectivelyEnabled() const bool PluginSpec::isEffectivelyEnabled() const
{ {
if (d->disabledIndirectly if (d->disabledIndirectly
|| (!d->enabledInSettings && !d->forceEnabled) || (!d->enabledBySettings && !d->forceEnabled)
|| d->forceDisabled) { || d->forceDisabled) {
return false; return false;
} }
@@ -485,8 +484,8 @@ namespace {
PluginSpecPrivate::PluginSpecPrivate(PluginSpec *spec) PluginSpecPrivate::PluginSpecPrivate(PluginSpec *spec)
: required(false), : required(false),
experimental(false), experimental(false),
disabledByDefault(false), enabledByDefault(true),
enabledInSettings(true), enabledBySettings(true),
disabledIndirectly(false), disabledIndirectly(false),
forceEnabled(false), forceEnabled(false),
forceDisabled(false), forceDisabled(false),
@@ -535,28 +534,28 @@ bool PluginSpecPrivate::read(const QString &fileName)
return true; return true;
} }
void PluginSpec::setEnabled(bool value) void PluginSpecPrivate::setEnabledBySettings(bool value)
{ {
d->enabledInSettings = value; enabledBySettings = value;
} }
void PluginSpec::setDisabledByDefault(bool value) void PluginSpecPrivate::setEnabledByDefault(bool value)
{ {
d->disabledByDefault = value; enabledByDefault = value;
} }
void PluginSpec::setForceEnabled(bool value) void PluginSpecPrivate::setForceEnabled(bool value)
{ {
d->forceEnabled = value; forceEnabled = value;
if (value) if (value)
d->forceDisabled = false; forceDisabled = false;
} }
void PluginSpec::setForceDisabled(bool value) void PluginSpecPrivate::setForceDisabled(bool value)
{ {
if (value) if (value)
d->forceEnabled = false; forceEnabled = false;
d->forceDisabled = value; forceDisabled = value;
} }
/*! /*!
@@ -687,12 +686,12 @@ bool PluginSpecPrivate::readMetaData(const QJsonObject &metaData)
value = pluginInfo.value(QLatin1String(PLUGIN_DISABLED_BY_DEFAULT)); value = pluginInfo.value(QLatin1String(PLUGIN_DISABLED_BY_DEFAULT));
if (!value.isUndefined() && !value.isBool()) if (!value.isUndefined() && !value.isBool())
return reportError(msgValueIsNotABool(PLUGIN_DISABLED_BY_DEFAULT)); return reportError(msgValueIsNotABool(PLUGIN_DISABLED_BY_DEFAULT));
disabledByDefault = value.toBool(false); enabledByDefault = !value.toBool(false);
qCDebug(pluginLog) << "disabledByDefault =" << disabledByDefault; qCDebug(pluginLog) << "enabledByDefault =" << enabledByDefault;
if (experimental) if (experimental)
disabledByDefault = true; enabledByDefault = false;
enabledInSettings = !disabledByDefault; enabledBySettings = enabledByDefault;
value = pluginInfo.value(QLatin1String(VENDOR)); value = pluginInfo.value(QLatin1String(VENDOR));
if (!value.isUndefined() && !value.isString()) if (!value.isUndefined() && !value.isString())
@@ -913,7 +912,7 @@ bool PluginSpecPrivate::resolveDependencies(const QList<PluginSpec *> &specs)
void PluginSpecPrivate::disableIndirectlyIfDependencyDisabled() void PluginSpecPrivate::disableIndirectlyIfDependencyDisabled()
{ {
if (!enabledInSettings) if (!enabledBySettings)
return; return;
if (disabledIndirectly) if (disabledIndirectly)

View File

@@ -45,11 +45,15 @@ QT_END_NAMESPACE
namespace ExtensionSystem { namespace ExtensionSystem {
namespace Internal { namespace Internal {
class PluginSpecPrivate;
class PluginManagerPrivate; class OptionsParser;
} class PluginSpecPrivate;
class PluginManagerPrivate;
} // Internal
class IPlugin; class IPlugin;
class PluginItem;
struct EXTENSIONSYSTEM_EXPORT PluginDependency struct EXTENSIONSYSTEM_EXPORT PluginDependency
{ {
@@ -97,8 +101,8 @@ public:
bool isAvailableForHostPlatform() const; bool isAvailableForHostPlatform() const;
bool isRequired() const; bool isRequired() const;
bool isExperimental() const; bool isExperimental() const;
bool isDisabledByDefault() const; bool isEnabledByDefault() const;
bool isEnabledInSettings() const; bool isEnabledBySettings() const;
bool isEffectivelyEnabled() const; bool isEffectivelyEnabled() const;
bool isDisabledIndirectly() const; bool isDisabledIndirectly() const;
bool isForceEnabled() const; bool isForceEnabled() const;
@@ -112,11 +116,6 @@ public:
QString location() const; QString location() const;
QString filePath() const; QString filePath() const;
void setEnabled(bool value);
void setDisabledByDefault(bool value);
void setForceEnabled(bool value);
void setForceDisabled(bool value);
QStringList arguments() const; QStringList arguments() const;
void setArguments(const QStringList &arguments); void setArguments(const QStringList &arguments);
void addArgument(const QString &argument); void addArgument(const QString &argument);
@@ -138,6 +137,8 @@ private:
PluginSpec(); PluginSpec();
Internal::PluginSpecPrivate *d; Internal::PluginSpecPrivate *d;
friend class PluginItem;
friend class Internal::OptionsParser;
friend class Internal::PluginManagerPrivate; friend class Internal::PluginManagerPrivate;
friend class Internal::PluginSpecPrivate; friend class Internal::PluginSpecPrivate;
}; };

View File

@@ -66,6 +66,11 @@ public:
IPlugin::ShutdownFlag stop(); IPlugin::ShutdownFlag stop();
void kill(); void kill();
void setEnabledBySettings(bool value);
void setEnabledByDefault(bool value);
void setForceEnabled(bool value);
void setForceDisabled(bool value);
QPluginLoader loader; QPluginLoader loader;
QString name; QString name;
@@ -73,7 +78,7 @@ public:
QString compatVersion; QString compatVersion;
bool required; bool required;
bool experimental; bool experimental;
bool disabledByDefault; bool enabledByDefault;
QString vendor; QString vendor;
QString copyright; QString copyright;
QString license; QString license;
@@ -82,7 +87,7 @@ public:
QString category; QString category;
QRegExp platformSpecification; QRegExp platformSpecification;
QVector<PluginDependency> dependencies; QVector<PluginDependency> dependencies;
bool enabledInSettings; bool enabledBySettings;
bool disabledIndirectly; bool disabledIndirectly;
bool forceEnabled; bool forceEnabled;
bool forceDisabled; bool forceDisabled;

View File

@@ -31,6 +31,7 @@
#include "pluginview.h" #include "pluginview.h"
#include "pluginmanager.h" #include "pluginmanager.h"
#include "pluginspec.h" #include "pluginspec.h"
#include "pluginspec_p.h"
#include "plugincollection.h" #include "plugincollection.h"
#include <utils/algorithm.h> #include <utils/algorithm.h>
@@ -130,7 +131,7 @@ public:
return PluginView::tr("Plugin is required."); return PluginView::tr("Plugin is required.");
} else { } else {
if (role == Qt::CheckStateRole) if (role == Qt::CheckStateRole)
return m_spec->isEnabledInSettings() ? Qt::Checked : Qt::Unchecked; return m_spec->isEnabledBySettings() ? Qt::Checked : Qt::Unchecked;
if (role == Qt::ToolTipRole) if (role == Qt::ToolTipRole)
return PluginView::tr("Load on startup"); return PluginView::tr("Load on startup");
} }
@@ -153,7 +154,7 @@ public:
bool setData(int column, const QVariant &data, int role) bool setData(int column, const QVariant &data, int role)
{ {
if (column == LoadedColumn && role == Qt::CheckStateRole) { if (column == LoadedColumn && role == Qt::CheckStateRole) {
m_spec->setEnabled(data.toBool()); m_spec->d->setEnabledBySettings(data.toBool());
updateColumn(column); updateColumn(column);
parent()->updateColumn(column); parent()->updateColumn(column);
emit m_view->pluginSettingsChanged(m_spec); emit m_view->pluginSettingsChanged(m_spec);
@@ -167,7 +168,7 @@ public:
if (m_spec->isRequired() || !m_spec->isAvailableForHostPlatform()) if (m_spec->isRequired() || !m_spec->isAvailableForHostPlatform())
return false; return false;
foreach (PluginSpec *spec, m_view->m_pluginDependencies.value(m_spec)) foreach (PluginSpec *spec, m_view->m_pluginDependencies.value(m_spec))
if (!spec->isEnabledInSettings()) if (!spec->isEnabledBySettings())
return false; return false;
return true; return true;
} }
@@ -213,7 +214,7 @@ public:
foreach (PluginSpec *spec, m_plugins) { foreach (PluginSpec *spec, m_plugins) {
if (spec->hasError()) if (spec->hasError())
return icon(ErrorIcon); return icon(ErrorIcon);
if (!spec->isEnabledInSettings()) if (!spec->isEnabledBySettings())
return icon(NotLoadedIcon); return icon(NotLoadedIcon);
} }
return icon(OkIcon); return icon(OkIcon);
@@ -226,7 +227,7 @@ public:
if (role == Qt::CheckStateRole) { if (role == Qt::CheckStateRole) {
int checkedCount = 0; int checkedCount = 0;
foreach (PluginSpec *spec, m_plugins) { foreach (PluginSpec *spec, m_plugins) {
if (spec->isEnabledInSettings()) if (spec->isEnabledBySettings())
++checkedCount; ++checkedCount;
} }