summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMontel Laurent <montel@kde.org>2016-09-07 05:53:52 (GMT)
committerMontel Laurent <montel@kde.org>2016-09-07 05:53:52 (GMT)
commitaa3e0280f9a6ed708415cd6e65d9c67b86b8b959 (patch)
treef4d9a47db4fb699f8ff8b46ecd65d5f954bb0240
parent7d2a64e762d5c3ffe6db0127666a8d16d675d608 (diff)
Allow to enable/disable plugin
-rw-r--r--src/genericplugins/genericpluginmanager.cpp18
1 files changed, 17 insertions, 1 deletions
diff --git a/src/genericplugins/genericpluginmanager.cpp b/src/genericplugins/genericpluginmanager.cpp
index 3a851c1..0f7d302 100644
--- a/src/genericplugins/genericpluginmanager.cpp
+++ b/src/genericplugins/genericpluginmanager.cpp
@@ -22,6 +22,8 @@
#include <kpluginmetadata.h>
#include <KPluginLoader>
#include <KPluginFactory>
+#include <KSharedConfig>
+#include <KConfigGroup>
#include <qfileinfo.h>
#include <QVariant>
#include <QSet>
@@ -104,13 +106,27 @@ bool GenericPluginManagerPrivate::initializePlugins()
const QVector<KPluginMetaData> plugins = KPluginLoader::findPlugins(pluginName, [](const KPluginMetaData & md) {
return md.serviceTypes().contains(s_serviceTypeName);
});
+
+ KSharedConfigPtr config = KSharedConfig::openConfig(QStringLiteral("pimpluginsrc"));
+ QStringList enabledPlugins;
+ QStringList disabledPlugins;
+ const QString groupPluginName = QStringLiteral("GenericPlugin%1").arg(pluginName);
+ if (config->hasGroup(groupPluginName)) {
+ KConfigGroup grp = config->group(groupPluginName);
+ enabledPlugins = grp.readEntry(QStringLiteral("PluginsEnabled"), QStringList());
+ disabledPlugins = grp.readEntry(QStringLiteral("PluginsDisabled"), QStringList());
+ }
+
QVectorIterator<KPluginMetaData> i(plugins);
i.toBack();
QSet<QString> unique;
while (i.hasPrevious()) {
GenericPluginInfo info;
info.metaData = i.previous();
- if (info.metaData.isEnabledByDefault()) {
+ const bool pluginEnabledByUser = enabledPlugins.contains(info.metaData.name());
+ const bool pluginDisabledByUser = disabledPlugins.contains(info.metaData.name());
+ if ((info.metaData.isEnabledByDefault() && !pluginDisabledByUser)
+ || (!info.metaData.isEnabledByDefault() && pluginEnabledByUser)) {
if (pluginVersion() == info.metaData.version()) {
// only load plugins once, even if found multiple times!
if (unique.contains(info.saveName())) {