summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMontel Laurent <montel@kde.org>2016-09-22 20:13:04 (GMT)
committerMontel Laurent <montel@kde.org>2016-09-22 20:13:04 (GMT)
commit8320de5fb56348d1dd54d1e5af246a5a688423e0 (patch)
treed7b39b98dd595e8af57756ec5b26774f986df51b
parentfa5ead4e626590cfa06d22720b6d1757792d4095 (diff)
Minor optimization. Allow to store info about support of configuration
-rw-r--r--src/genericplugins/abstractgenericplugin.cpp13
-rw-r--r--src/genericplugins/abstractgenericplugin.h6
-rw-r--r--src/genericplugins/genericpluginmanager.cpp57
-rw-r--r--src/genericplugins/plugininterface.cpp12
-rw-r--r--src/genericplugins/pluginutil.h4
5 files changed, 57 insertions, 35 deletions
diff --git a/src/genericplugins/abstractgenericplugin.cpp b/src/genericplugins/abstractgenericplugin.cpp
index f9d00ba..34cc73b 100644
--- a/src/genericplugins/abstractgenericplugin.cpp
+++ b/src/genericplugins/abstractgenericplugin.cpp
@@ -20,7 +20,8 @@
using namespace PimCommon;
AbstractGenericPlugin::AbstractGenericPlugin(QObject *parent)
- : QObject(parent)
+ : QObject(parent),
+ mIsEnabled(true)
{
}
@@ -45,4 +46,14 @@ bool AbstractGenericPlugin::hasConfigureDialog() const
return false;
}
+void AbstractGenericPlugin::setIsEnabled(bool enabled)
+{
+ mIsEnabled = enabled;
+}
+
+bool AbstractGenericPlugin::isEnabled() const
+{
+ return mIsEnabled;
+}
+
diff --git a/src/genericplugins/abstractgenericplugin.h b/src/genericplugins/abstractgenericplugin.h
index b167e51..cf5d35f 100644
--- a/src/genericplugins/abstractgenericplugin.h
+++ b/src/genericplugins/abstractgenericplugin.h
@@ -35,6 +35,12 @@ public:
virtual bool hasPopupMenuSupport() const;
virtual bool hasToolBarSupport() const;
virtual bool hasConfigureDialog() const;
+
+ void setIsEnabled(bool enabled);
+ bool isEnabled() const;
+
+private:
+ bool mIsEnabled;
};
}
#endif // AbstractGENERICPLUGIN_H
diff --git a/src/genericplugins/genericpluginmanager.cpp b/src/genericplugins/genericpluginmanager.cpp
index 2abf05d..5395011 100644
--- a/src/genericplugins/genericpluginmanager.cpp
+++ b/src/genericplugins/genericpluginmanager.cpp
@@ -55,21 +55,18 @@ class GenericPluginInfo
{
public:
GenericPluginInfo()
- : plugin(Q_NULLPTR)
+ : plugin(Q_NULLPTR),
+ isEnabled(true)
{
}
- QString saveName() const;
-
- KPluginMetaData metaData;
+ QString metaDataFileNameBaseName;
+ QString metaDataFileName;
+ PimCommon::PluginUtilData pluginData;
PimCommon::GenericPlugin *plugin;
+ bool isEnabled;
};
-QString GenericPluginInfo::saveName() const
-{
- return QFileInfo(metaData.fileName()).baseName();
-}
-
namespace
{
QString pluginVersion()
@@ -131,24 +128,25 @@ bool GenericPluginManagerPrivate::initializePlugins()
QSet<QString> unique;
while (i.hasPrevious()) {
GenericPluginInfo info;
- info.metaData = i.previous();
-
- const PimCommon::PluginUtilData pluginData = PimCommon::PluginUtil::createPluginMetaData(info.metaData);
- mPluginDataList.append(pluginData);
-
- const bool isPluginActivated = PimCommon::PluginUtil::isPluginActivated(pair.first, pair.second, pluginData.mEnableByDefault, pluginData.mIdentifier);
- if (isPluginActivated) {
- if (pluginVersion() == info.metaData.version()) {
- // only load plugins once, even if found multiple times!
- if (unique.contains(info.saveName())) {
- continue;
- }
- info.plugin = Q_NULLPTR;
- mPluginList.push_back(info);
- unique.insert(info.saveName());
- } else {
- qCWarning(PIMCOMMON_LOG) << "Plugin " << info.metaData.name() << " doesn't have correction plugin version. It will not be loaded.";
+ const KPluginMetaData data = i.previous();
+
+ //1) get plugin data => name/description etc.
+ info.pluginData = PimCommon::PluginUtil::createPluginMetaData(data);
+ //2) look at if plugin is activated
+ const bool isPluginActivated = PimCommon::PluginUtil::isPluginActivated(pair.first, pair.second, info.pluginData.mEnableByDefault, info.pluginData.mIdentifier);
+ info.isEnabled = isPluginActivated;
+ info.metaDataFileNameBaseName = QFileInfo(data.fileName()).baseName();
+ info.metaDataFileName = data.fileName();
+ if (pluginVersion() == data.version()) {
+ // only load plugins once, even if found multiple times!
+ if (unique.contains(info.metaDataFileNameBaseName)) {
+ continue;
}
+ info.plugin = Q_NULLPTR;
+ mPluginList.push_back(info);
+ unique.insert(info.metaDataFileNameBaseName);
+ } else {
+ qCWarning(PIMCOMMON_LOG) << "Plugin " << data.name() << " doesn't have correction plugin version. It will not be loaded.";
}
}
QVector<GenericPluginInfo>::iterator end(mPluginList.end());
@@ -177,9 +175,12 @@ QVector<GenericPlugin *> GenericPluginManagerPrivate::pluginsList() const
void GenericPluginManagerPrivate::loadPlugin(GenericPluginInfo *item)
{
- KPluginLoader pluginLoader(item->metaData.fileName());
+ KPluginLoader pluginLoader(item->metaDataFileName);
if (pluginLoader.factory()) {
- item->plugin = pluginLoader.factory()->create<PimCommon::GenericPlugin>(q, QVariantList() << item->saveName());
+ item->plugin = pluginLoader.factory()->create<PimCommon::GenericPlugin>(q, QVariantList() << item->metaDataFileNameBaseName);
+ item->plugin->setIsEnabled(item->isEnabled);
+ item->pluginData.mHasConfigureDialog = item->plugin->hasConfigureDialog();
+ mPluginDataList.append(item->pluginData);
}
}
diff --git a/src/genericplugins/plugininterface.cpp b/src/genericplugins/plugininterface.cpp
index a7e59cc..1c6fa00 100644
--- a/src/genericplugins/plugininterface.cpp
+++ b/src/genericplugins/plugininterface.cpp
@@ -85,11 +85,13 @@ void PluginInterface::createPluginInterface()
return;
}
Q_FOREACH (PimCommon::GenericPlugin *plugin, PimCommon::GenericPluginManager::self()->pluginsList()) {
- PimCommon::GenericPluginInterface *interface = static_cast<PimCommon::GenericPluginInterface *>(plugin->createInterface(d->mActionCollection, this));
- interface->setParentWidget(d->mParentWidget);
- interface->setPlugin(plugin);
- connect(interface, &PimCommon::GenericPluginInterface::emitPluginActivated, this, &PluginInterface::slotPluginActivated);
- d->mListGenericInterface.append(interface);
+ if (plugin->isEnabled()) {
+ PimCommon::GenericPluginInterface *interface = static_cast<PimCommon::GenericPluginInterface *>(plugin->createInterface(d->mActionCollection, this));
+ interface->setParentWidget(d->mParentWidget);
+ interface->setPlugin(plugin);
+ connect(interface, &PimCommon::GenericPluginInterface::emitPluginActivated, this, &PluginInterface::slotPluginActivated);
+ d->mListGenericInterface.append(interface);
+ }
}
}
diff --git a/src/genericplugins/pluginutil.h b/src/genericplugins/pluginutil.h
index b7e1719..2dca490 100644
--- a/src/genericplugins/pluginutil.h
+++ b/src/genericplugins/pluginutil.h
@@ -32,7 +32,8 @@ class PIMCOMMON_EXPORT PluginUtilData
{
public:
PluginUtilData()
- : mEnableByDefault(false)
+ : mEnableByDefault(false),
+ mHasConfigureDialog(false)
{
}
@@ -40,6 +41,7 @@ public:
QString mIdentifier;
QString mName;
bool mEnableByDefault;
+ bool mHasConfigureDialog;
};
namespace PluginUtil