summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMontel Laurent <montel@kde.org>2016-09-23 05:13:45 (GMT)
committerMontel Laurent <montel@kde.org>2016-09-23 05:13:45 (GMT)
commit3887f1b38a8ed20801545f64fbcebc20e54a9ae8 (patch)
treef13f4c0084e0cf45a7aca1b4933257667fbe8854
parent32323cd0e854469267f1833e8afcdf5d57563437 (diff)
Allow to define if plugin is enable or not
-rw-r--r--messagecomposer/src/plugineditorcheckbeforesend/plugineditorcheckbeforesend.cpp12
-rw-r--r--messagecomposer/src/plugineditorcheckbeforesend/plugineditorcheckbeforesend.h4
-rw-r--r--messagecomposer/src/plugineditorcheckbeforesend/plugineditorcheckbeforesendmanager.cpp58
3 files changed, 45 insertions, 29 deletions
diff --git a/messagecomposer/src/plugineditorcheckbeforesend/plugineditorcheckbeforesend.cpp b/messagecomposer/src/plugineditorcheckbeforesend/plugineditorcheckbeforesend.cpp
index 8b0c2a4..8a120d3 100644
--- a/messagecomposer/src/plugineditorcheckbeforesend/plugineditorcheckbeforesend.cpp
+++ b/messagecomposer/src/plugineditorcheckbeforesend/plugineditorcheckbeforesend.cpp
@@ -25,9 +25,11 @@ class MessageComposer::PluginEditorCheckBeforeSendPrivate
{
public:
PluginEditorCheckBeforeSendPrivate()
+ : mIsEnabled(false)
{
}
+ bool mIsEnabled;
};
PluginEditorCheckBeforeSend::PluginEditorCheckBeforeSend(QObject *parent)
@@ -63,3 +65,13 @@ QString PluginEditorCheckBeforeSend::description() const
{
return {};
}
+
+void PluginEditorCheckBeforeSend::setIsEnabled(bool enabled)
+{
+ d->mIsEnabled = enabled;
+}
+
+bool PluginEditorCheckBeforeSend::isEnabled() const
+{
+ return d->mIsEnabled;
+}
diff --git a/messagecomposer/src/plugineditorcheckbeforesend/plugineditorcheckbeforesend.h b/messagecomposer/src/plugineditorcheckbeforesend/plugineditorcheckbeforesend.h
index 5285efe..f164c6a 100644
--- a/messagecomposer/src/plugineditorcheckbeforesend/plugineditorcheckbeforesend.h
+++ b/messagecomposer/src/plugineditorcheckbeforesend/plugineditorcheckbeforesend.h
@@ -68,6 +68,10 @@ public:
virtual QString description() const;
+ void setIsEnabled(bool enabled);
+ bool isEnabled() const;
+
+
Q_SIGNALS:
void configChanged();
diff --git a/messagecomposer/src/plugineditorcheckbeforesend/plugineditorcheckbeforesendmanager.cpp b/messagecomposer/src/plugineditorcheckbeforesend/plugineditorcheckbeforesendmanager.cpp
index 15b388b..a6ee029 100644
--- a/messagecomposer/src/plugineditorcheckbeforesend/plugineditorcheckbeforesendmanager.cpp
+++ b/messagecomposer/src/plugineditorcheckbeforesend/plugineditorcheckbeforesendmanager.cpp
@@ -47,14 +47,16 @@ class PluginEditorCheckBeforeSendInfo
{
public:
PluginEditorCheckBeforeSendInfo()
- : plugin(Q_NULLPTR)
+ : plugin(Q_NULLPTR),
+ isEnabled(true)
{
}
- QString saveName() const;
-
- KPluginMetaData metaData;
+ QString metaDataFileNameBaseName;
+ QString metaDataFileName;
+ PimCommon::PluginUtilData pluginData;
PluginEditorCheckBeforeSend *plugin;
+ bool isEnabled;
};
Q_GLOBAL_STATIC(PluginEditorCheckBeforeSendManagerInstancePrivate, sInstance)
@@ -115,25 +117,25 @@ bool PluginEditorCheckBeforeSendManagerPrivate::initializePlugins()
QSet<QString> unique;
while (i.hasPrevious()) {
PluginEditorCheckBeforeSendInfo info;
- info.metaData = i.previous();
-
- //Store plugin info
- 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(MESSAGECOMPOSER_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(MESSAGECOMPOSER_LOG) << "Plugin " << data.name() << " doesn't have correction plugin version. It will not be loaded.";
}
}
QVector<PluginEditorCheckBeforeSendInfo>::iterator end(mPluginList.end());
@@ -145,9 +147,12 @@ bool PluginEditorCheckBeforeSendManagerPrivate::initializePlugins()
void PluginEditorCheckBeforeSendManagerPrivate::loadPlugin(PluginEditorCheckBeforeSendInfo *item)
{
- KPluginLoader pluginLoader(item->metaData.fileName());
+ KPluginLoader pluginLoader(item->metaDataFileName);
if (pluginLoader.factory()) {
- item->plugin = pluginLoader.factory()->create<PluginEditorCheckBeforeSend>(q, QVariantList() << item->saveName());
+ item->plugin = pluginLoader.factory()->create<PluginEditorCheckBeforeSend>(q, QVariantList() << item->metaDataFileNameBaseName);
+ item->plugin->setIsEnabled(item->isEnabled);
+ item->pluginData.mHasConfigureDialog = item->plugin->hasConfigureDialog();
+ mPluginDataList.append(item->pluginData);
}
}
@@ -179,11 +184,6 @@ PluginEditorCheckBeforeSendManager *PluginEditorCheckBeforeSendManager::self()
return sInstance->pluginManager;
}
-QString PluginEditorCheckBeforeSendInfo::saveName() const
-{
- return QFileInfo(metaData.fileName()).baseName();
-}
-
QVector<PluginEditorCheckBeforeSend *> PluginEditorCheckBeforeSendManager::pluginsList() const
{
return d->pluginsList();