summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMontel Laurent <montel@kde.org>2016-09-23 05:56:09 (GMT)
committerMontel Laurent <montel@kde.org>2016-09-23 05:56:09 (GMT)
commit713468d395efb7865e7f7857f2f0401f2732a64e (patch)
tree17e398a66cfa811d062a9328d572eb60ed251be7
parent7e8711123e00712a8494a2f699231dbcc5ace0a7 (diff)
Allow to show or not viewerplugin
-rw-r--r--messageviewer/src/viewerplugins/viewerplugin.cpp12
-rw-r--r--messageviewer/src/viewerplugins/viewerplugin.h3
-rw-r--r--messageviewer/src/viewerplugins/viewerpluginmanager.cpp58
-rw-r--r--messageviewer/src/viewerplugins/viewerplugintoolmanager.cpp8
4 files changed, 51 insertions, 30 deletions
diff --git a/messageviewer/src/viewerplugins/viewerplugin.cpp b/messageviewer/src/viewerplugins/viewerplugin.cpp
index fe6d0ec..45225d1 100644
--- a/messageviewer/src/viewerplugins/viewerplugin.cpp
+++ b/messageviewer/src/viewerplugins/viewerplugin.cpp
@@ -25,9 +25,11 @@ class MessageViewer::ViewerPluginPrivate
{
public:
ViewerPluginPrivate()
+ : mEnabled(false)
{
}
+ bool mEnabled;
};
ViewerPlugin::ViewerPlugin(QObject *parent)
@@ -42,3 +44,13 @@ ViewerPlugin::~ViewerPlugin()
delete d;
}
+void ViewerPlugin::setIsEnabled(bool enabled)
+{
+ d->mEnabled = enabled;
+}
+
+bool ViewerPlugin::isEnabled() const
+{
+ return d->mEnabled;
+}
+
diff --git a/messageviewer/src/viewerplugins/viewerplugin.h b/messageviewer/src/viewerplugins/viewerplugin.h
index e8504a8..00b2779 100644
--- a/messageviewer/src/viewerplugins/viewerplugin.h
+++ b/messageviewer/src/viewerplugins/viewerplugin.h
@@ -38,6 +38,9 @@ public:
virtual MessageViewer::ViewerPluginInterface *createView(QWidget *parent, KActionCollection *ac) = 0;
virtual QString viewerPluginName() const = 0;
+ void setIsEnabled(bool enabled);
+ bool isEnabled() const;
+
private:
ViewerPluginPrivate *const d;
};
diff --git a/messageviewer/src/viewerplugins/viewerpluginmanager.cpp b/messageviewer/src/viewerplugins/viewerpluginmanager.cpp
index 0caef65..3f78efa 100644
--- a/messageviewer/src/viewerplugins/viewerpluginmanager.cpp
+++ b/messageviewer/src/viewerplugins/viewerpluginmanager.cpp
@@ -54,21 +54,19 @@ class ViewerPluginInfo
{
public:
ViewerPluginInfo()
- : plugin(Q_NULLPTR)
+ : plugin(Q_NULLPTR),
+ isEnabled(false)
{
}
- QString saveName() const;
- KPluginMetaData metaData;
+ QString metaDataFileNameBaseName;
+ QString metaDataFileName;
+ PimCommon::PluginUtilData pluginData;
MessageViewer::ViewerPlugin *plugin;
+ bool isEnabled;
};
-QString ViewerPluginInfo::saveName() const
-{
- return QFileInfo(metaData.fileName()).baseName();
-}
-
class MessageViewer::ViewerPluginManagerPrivate
{
public:
@@ -135,24 +133,27 @@ bool ViewerPluginManagerPrivate::initializePluginList()
QSet<QString> unique;
while (i.hasPrevious()) {
ViewerPluginInfo 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) {
- const QString version = info.metaData.version();
- if (pluginVersion() == 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(MESSAGEVIEWER_LOG) << "Plugin name :" << info.metaData.name() << " doesn't have correct plugin version. Please update it";
+
+ 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(MESSAGEVIEWER_LOG) << "Plugin name :" << data.name() << " doesn't have correct plugin version. Please update it";
}
}
QVector<ViewerPluginInfo>::iterator end(mPluginList.end());
@@ -164,9 +165,12 @@ bool ViewerPluginManagerPrivate::initializePluginList()
void ViewerPluginManagerPrivate::loadPlugin(ViewerPluginInfo *item)
{
- KPluginLoader pluginLoader(item->metaData.fileName());
+ KPluginLoader pluginLoader(item->metaDataFileName);
if (pluginLoader.factory()) {
- item->plugin = pluginLoader.factory()->create<MessageViewer::ViewerPlugin>(q, QVariantList() << item->saveName());
+ item->plugin = pluginLoader.factory()->create<MessageViewer::ViewerPlugin>(q, QVariantList() << item->metaDataFileNameBaseName);
+ item->plugin->setIsEnabled(item->isEnabled);
+ item->pluginData.mHasConfigureDialog = false; //TODO add support
+ mPluginDataList.append(item->pluginData);
}
}
diff --git a/messageviewer/src/viewerplugins/viewerplugintoolmanager.cpp b/messageviewer/src/viewerplugins/viewerplugintoolmanager.cpp
index 44f8ef8..f5188cc 100644
--- a/messageviewer/src/viewerplugins/viewerplugintoolmanager.cpp
+++ b/messageviewer/src/viewerplugins/viewerplugintoolmanager.cpp
@@ -75,9 +75,11 @@ void ViewerPluginToolManagerPrivate::createView()
{
QVector<MessageViewer::ViewerPlugin *> listPlugin = MessageViewer::ViewerPluginManager::self()->pluginsList();
Q_FOREACH (MessageViewer::ViewerPlugin *plugin, listPlugin) {
- MessageViewer::ViewerPluginInterface *interface = plugin->createView(mParentWidget, mActionCollection);
- q->connect(interface, &MessageViewer::ViewerPluginInterface::activatePlugin, q, &ViewerPluginToolManager::activatePlugin);
- mListInterface.append(interface);
+ if (plugin->isEnabled()) {
+ MessageViewer::ViewerPluginInterface *interface = plugin->createView(mParentWidget, mActionCollection);
+ q->connect(interface, &MessageViewer::ViewerPluginInterface::activatePlugin, q, &ViewerPluginToolManager::activatePlugin);
+ mListInterface.append(interface);
+ }
}
}