7#include "plugineditorinitmanager.h"
8#include "messagecomposer_debug.h"
9#include "plugineditorinit.h"
10#include <KPluginFactory>
11#include <KPluginMetaData>
16class PluginEditorInitInfo
19 PluginEditorInitInfo() =
default;
21 PimCommon::PluginUtilData pluginData;
22 QString metaDataFileNameBaseName;
23 QString metaDataFileName;
25 PluginEditorInit *plugin =
nullptr;
26 bool isEnabled =
true;
31QString pluginEditorInitVersion()
33 return QStringLiteral(
"1.0");
37class MessageComposer::PluginEditorInitManagerPrivate
40 PluginEditorInitManagerPrivate(PluginEditorInitManager *qq)
46 void loadPlugin(PluginEditorInitInfo *item);
47 [[nodiscard]] QList<PluginEditorInit *> pluginsList()
const;
48 void initializePlugins();
49 [[nodiscard]] QString configPrefixSettingKey()
const;
50 [[nodiscard]] QString configGroupName()
const;
51 [[nodiscard]] QList<PimCommon::PluginUtilData> pluginsDataList()
const;
52 [[nodiscard]] PluginEditorInit *pluginFromIdentifier(
const QString &
id);
54 QList<PluginEditorInitInfo> mPluginList;
57 QList<PimCommon::PluginUtilData> mPluginDataList;
58 PluginEditorInitManager *
const q;
61QString PluginEditorInitManagerPrivate::configGroupName()
const
63 return QStringLiteral(
"KMailPluginEditorInit");
66QString PluginEditorInitManagerPrivate::configPrefixSettingKey()
const
68 return QStringLiteral(
"PluginEditorInit");
71QList<PimCommon::PluginUtilData> PluginEditorInitManagerPrivate::pluginsDataList()
const
73 return mPluginDataList;
76void PluginEditorInitManagerPrivate::initializePlugins()
80 const QPair<QStringList, QStringList> pair = PimCommon::PluginUtil::loadPluginSetting(configGroupName(), configPrefixSettingKey());
82 QListIterator<KPluginMetaData> i(plugins);
84 while (i.hasPrevious()) {
85 PluginEditorInitInfo info;
86 const KPluginMetaData data = i.previous();
89 info.pluginData = PimCommon::PluginUtil::createPluginMetaData(data);
91 const bool isPluginActivated =
92 PimCommon::PluginUtil::isPluginActivated(pair.first, pair.second, info.pluginData.mEnableByDefault, info.pluginData.mIdentifier);
93 info.isEnabled = isPluginActivated;
94 info.metaDataFileNameBaseName = QFileInfo(data.
fileName()).baseName();
95 info.metaDataFileName = data.
fileName();
97 if (pluginEditorInitVersion() == data.
version()) {
98 info.plugin =
nullptr;
99 mPluginList.push_back(info);
101 qCWarning(MESSAGECOMPOSER_LOG) <<
"Plugin " << data.
name() <<
" doesn't have correction plugin version. It will not be loaded.";
104 QList<PluginEditorInitInfo>::iterator
end(mPluginList.end());
105 for (QList<PluginEditorInitInfo>::iterator it = mPluginList.begin(); it != end; ++it) {
110void PluginEditorInitManagerPrivate::loadPlugin(PluginEditorInitInfo *item)
112 if (
auto plugin = KPluginFactory::instantiatePlugin<PluginEditorInit>(item->data, q, QVariantList() << item->metaDataFileName).plugin) {
113 item->plugin = plugin;
114 item->plugin->setIsEnabled(item->isEnabled);
115 item->pluginData.mHasConfigureDialog = item->plugin->hasConfigureDialog();
116 mPluginDataList.append(item->pluginData);
120QList<PluginEditorInit *> PluginEditorInitManagerPrivate::pluginsList()
const
122 QList<PluginEditorInit *> lst;
125 if (
auto plugin = (*it).plugin) {
132PluginEditorInit *PluginEditorInitManagerPrivate::pluginFromIdentifier(
const QString &
id)
136 if ((*it).pluginData.mIdentifier ==
id) {
143PluginEditorInitManager::PluginEditorInitManager(QObject *parent)
145 , d(new MessageComposer::PluginEditorInitManagerPrivate(this))
149PluginEditorInitManager::~PluginEditorInitManager() =
default;
153 static PluginEditorInitManager s_self;
157QList<PluginEditorInit *> PluginEditorInitManager::pluginsList()
const
159 return d->pluginsList();
162QString PluginEditorInitManager::configGroupName()
const
164 return d->configGroupName();
167QString PluginEditorInitManager::configPrefixSettingKey()
const
169 return d->configPrefixSettingKey();
172QList<PimCommon::PluginUtilData> PluginEditorInitManager::pluginsDataList()
const
174 return d->pluginsDataList();
177PluginEditorInit *PluginEditorInitManager::pluginFromIdentifier(
const QString &
id)
179 return d->pluginFromIdentifier(
id);
182#include "moc_plugineditorinitmanager.cpp"
The PluginEditorInitManager class.
The PluginEditorInit class.
const QList< QKeySequence > & end()
Simple interface that both EncryptJob and SignEncryptJob implement so the composer can extract some e...