summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMontel Laurent <montel@kde.org>2016-09-23 05:47:47 (GMT)
committerMontel Laurent <montel@kde.org>2016-09-23 05:47:47 (GMT)
commit7e8711123e00712a8494a2f699231dbcc5ace0a7 (patch)
treea2d91674c67b0c8738472949c7cfc144944cee21
parent3bc1cccc689756e94a449c176a34067e918224b9 (diff)
Enable or not header style plugins
-rw-r--r--messageviewer/src/header/headerstylemenumanager.cpp10
-rw-r--r--messageviewer/src/header/headerstyleplugin.cpp12
-rw-r--r--messageviewer/src/header/headerstyleplugin.h4
-rw-r--r--messageviewer/src/header/headerstylepluginmanager.cpp85
4 files changed, 66 insertions, 45 deletions
diff --git a/messageviewer/src/header/headerstylemenumanager.cpp b/messageviewer/src/header/headerstylemenumanager.cpp
index f586d96..6f649b0 100644
--- a/messageviewer/src/header/headerstylemenumanager.cpp
+++ b/messageviewer/src/header/headerstylemenumanager.cpp
@@ -133,10 +133,12 @@ void HeaderStyleMenuManagerPrivate::initialize(KActionCollection *ac)
const QVector<MessageViewer::HeaderStylePlugin *> lstPlugin = MessageViewer::HeaderStylePluginManager::self()->pluginsList();
Q_FOREACH (MessageViewer::HeaderStylePlugin *plugin, lstPlugin) {
- MessageViewer::HeaderStyleInterface *interface = plugin->createView(headerMenu, group, ac, q);
- lstInterface.insert(plugin->name(), interface);
- q->connect(interface, &HeaderStyleInterface::styleChanged, q, &HeaderStyleMenuManager::slotStyleChanged);
- q->connect(interface, &HeaderStyleInterface::styleUpdated, q, &HeaderStyleMenuManager::styleUpdated);
+ if (plugin->isEnabled()) {
+ MessageViewer::HeaderStyleInterface *interface = plugin->createView(headerMenu, group, ac, q);
+ lstInterface.insert(plugin->name(), interface);
+ q->connect(interface, &HeaderStyleInterface::styleChanged, q, &HeaderStyleMenuManager::slotStyleChanged);
+ q->connect(interface, &HeaderStyleInterface::styleUpdated, q, &HeaderStyleMenuManager::styleUpdated);
+ }
}
}
diff --git a/messageviewer/src/header/headerstyleplugin.cpp b/messageviewer/src/header/headerstyleplugin.cpp
index bb694a2..1825ca7 100644
--- a/messageviewer/src/header/headerstyleplugin.cpp
+++ b/messageviewer/src/header/headerstyleplugin.cpp
@@ -24,9 +24,11 @@ class MessageViewer::HeaderStylePluginPrivate
{
public:
HeaderStylePluginPrivate()
+ : mIsEnabled(false)
{
}
+ bool mIsEnabled;
};
HeaderStylePlugin::HeaderStylePlugin(QObject *parent)
@@ -55,3 +57,13 @@ int HeaderStylePlugin::elidedTextSize() const
{
return -1;
}
+
+void HeaderStylePlugin::setIsEnabled(bool enabled)
+{
+ d->mIsEnabled = enabled;
+}
+
+bool HeaderStylePlugin::isEnabled() const
+{
+ return d->mIsEnabled;
+}
diff --git a/messageviewer/src/header/headerstyleplugin.h b/messageviewer/src/header/headerstyleplugin.h
index 1650c46..c350722 100644
--- a/messageviewer/src/header/headerstyleplugin.h
+++ b/messageviewer/src/header/headerstyleplugin.h
@@ -47,6 +47,10 @@ public:
virtual QString alignment() const;
virtual int elidedTextSize() const;
+
+ void setIsEnabled(bool enabled);
+ bool isEnabled() const;
+
private:
HeaderStylePluginPrivate *const d;
};
diff --git a/messageviewer/src/header/headerstylepluginmanager.cpp b/messageviewer/src/header/headerstylepluginmanager.cpp
index 718dc3a..bfbd92d 100644
--- a/messageviewer/src/header/headerstylepluginmanager.cpp
+++ b/messageviewer/src/header/headerstylepluginmanager.cpp
@@ -50,21 +50,19 @@ class HeaderStylePluginInfo
{
public:
HeaderStylePluginInfo()
- : plugin(Q_NULLPTR)
+ : plugin(Q_NULLPTR),
+ isEnabled(false)
{
}
- QString saveName() const;
- KPluginMetaData metaData;
+ QString metaDataFileNameBaseName;
+ QString metaDataFileName;
+ PimCommon::PluginUtilData pluginData;
MessageViewer::HeaderStylePlugin *plugin;
+ bool isEnabled;
};
-QString HeaderStylePluginInfo::saveName() const
-{
- return QFileInfo(metaData.fileName()).baseName();
-}
-
class MessageViewer::HeaderStylePluginManagerPrivate
{
public:
@@ -122,40 +120,42 @@ void HeaderStylePluginManagerPrivate::initializePluginList()
QList<int> listOrder;
while (i.hasPrevious()) {
HeaderStylePluginInfo info;
- info.metaData = i.previous();
-
- 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;
- }
- const QVariant p = info.metaData.rawData().value(QStringLiteral("X-KDE-MessageViewer-Header-Order")).toVariant();
- int order = -1;
- if (p.isValid()) {
- order = p.toInt();
- }
- int pos = 0;
- for (; pos < listOrder.count(); ++pos) {
- if (listOrder.at(pos) > order) {
- pos--;
- break;
- }
+ 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();
+ const QString version = data.version();
+ if (pluginVersion() == version) {
+
+ // only load plugins once, even if found multiple times!
+ if (unique.contains(info.metaDataFileNameBaseName)) {
+ continue;
+ }
+ const QVariant p = data.rawData().value(QStringLiteral("X-KDE-MessageViewer-Header-Order")).toVariant();
+ int order = -1;
+ if (p.isValid()) {
+ order = p.toInt();
+ }
+ int pos = 0;
+ for (; pos < listOrder.count(); ++pos) {
+ if (listOrder.at(pos) > order) {
+ pos--;
+ break;
}
- pos = qMax(0, pos);
- listOrder.insert(pos, order);
- info.plugin = Q_NULLPTR;
- mPluginList.insert(pos, info);
- unique.insert(info.saveName());
- } else {
- qCWarning(MESSAGEVIEWER_LOG) << "Plugin " << info.metaData.name() << " doesn't have correction plugin version. It will not be loaded.";
}
+ pos = qMax(0, pos);
+ listOrder.insert(pos, order);
+ info.plugin = Q_NULLPTR;
+ mPluginList.insert(pos, info);
+ unique.insert(info.metaDataFileNameBaseName);
+ } else {
+ qCWarning(MESSAGEVIEWER_LOG) << "Plugin " << data.name() << " doesn't have correction plugin version. It will not be loaded.";
}
}
QVector<HeaderStylePluginInfo>::iterator end(mPluginList.end());
@@ -178,9 +178,12 @@ QVector<MessageViewer::HeaderStylePlugin *> HeaderStylePluginManagerPrivate::plu
void HeaderStylePluginManagerPrivate::loadPlugin(HeaderStylePluginInfo *item)
{
- KPluginLoader pluginLoader(item->metaData.fileName());
+ KPluginLoader pluginLoader(item->metaDataFileName);
if (pluginLoader.factory()) {
- item->plugin = pluginLoader.factory()->create<MessageViewer::HeaderStylePlugin>(q, QVariantList() << item->saveName());
+ item->plugin = pluginLoader.factory()->create<MessageViewer::HeaderStylePlugin>(q, QVariantList() << item->metaDataFileNameBaseName);
+ item->plugin->setIsEnabled(item->isEnabled);
+ item->pluginData.mHasConfigureDialog = false;
+ mPluginDataList.append(item->pluginData);
}
}