Differential D8114 Diff 20301 messageviewer/src/messagepartthemes/default/messagepartrendererfactory.cpp
Changeset View
Changeset View
Standalone View
Standalone View
messageviewer/src/messagepartthemes/default/messagepartrendererfactory.cpp
Show All 24 Lines | 1 | /* | |||
---|---|---|---|---|---|
25 | Qt. If you modify this file, you may extend this exception to | 25 | Qt. If you modify this file, you may extend this exception to | ||
26 | your version of the file, but you are not obligated to do so. If | 26 | your version of the file, but you are not obligated to do so. If | ||
27 | you do not wish to do so, delete this exception statement from | 27 | you do not wish to do so, delete this exception statement from | ||
28 | your version. | 28 | your version. | ||
29 | */ | 29 | */ | ||
30 | 30 | | |||
31 | #include "messagepartrendererfactory.h" | 31 | #include "messagepartrendererfactory.h" | ||
32 | #include "messagepartrendererfactory_p.h" | 32 | #include "messagepartrendererfactory_p.h" | ||
33 | #include "messagepartrenderplugin.h" | ||||
33 | 34 | | |||
34 | #include "messagepartrendererbase.h" | 35 | #include "messagepartrendererbase.h" | ||
35 | #include "messageviewer_debug.h" | 36 | #include "messageviewer_debug.h" | ||
36 | 37 | | |||
37 | #include "plugins/attachmentmessagepartrenderer.h" | 38 | #include "plugins/attachmentmessagepartrenderer.h" | ||
38 | #include "plugins/messagepartrenderer.h" | 39 | #include "plugins/messagepartrenderer.h" | ||
39 | #include "plugins/textmessagepartrenderer.h" | 40 | #include "plugins/textmessagepartrenderer.h" | ||
40 | 41 | | |||
42 | #include <KPluginLoader> | ||||
43 | | ||||
44 | #include <QJsonArray> | ||||
45 | #include <QJsonObject> | ||||
46 | | ||||
41 | using namespace MessageViewer; | 47 | using namespace MessageViewer; | ||
42 | 48 | | |||
43 | void MessagePartRendererFactoryPrivate::setup() | 49 | void MessagePartRendererFactoryPrivate::setup() | ||
44 | { | 50 | { | ||
45 | if (mAll.isEmpty()) { | 51 | if (mAll.isEmpty()) { | ||
46 | initalize_builtin_renderers(); | 52 | initalize_builtin_renderers(); | ||
47 | loadPlugins(); | 53 | loadPlugins(); | ||
48 | } | 54 | } | ||
49 | } | 55 | } | ||
50 | 56 | | |||
51 | void MessagePartRendererFactoryPrivate::loadPlugins() | 57 | void MessagePartRendererFactoryPrivate::loadPlugins() | ||
52 | { | 58 | { | ||
53 | qCDebug(MESSAGEVIEWER_LOG) << "plugin loading is not enabled in libmimetreeparser"; | 59 | KPluginLoader::forEachPlugin(QStringLiteral("messageviewer/bodypartformatter"), [this](const QString &path) { | ||
60 | QPluginLoader loader(path); | ||||
61 | const auto pluginData = loader.metaData().value(QLatin1String("MetaData")).toObject().value(QLatin1String("renderer")).toArray(); | ||||
62 | if (pluginData.isEmpty()) { | ||||
63 | qCWarning(MESSAGEVIEWER_LOG) << "Plugin" << path << "has no meta data."; | ||||
64 | return; | ||||
65 | } | ||||
66 | | ||||
67 | auto plugin = qobject_cast<MessagePartRenderPlugin*>(loader.instance()); | ||||
68 | if (!plugin) { | ||||
69 | qCWarning(MESSAGEVIEWER_LOG) << path << "is not a MessagePartRendererPlugin"; | ||||
70 | return; | ||||
71 | } | ||||
72 | | ||||
73 | MessagePartRendererBase *renderer = nullptr; | ||||
74 | for (int i = 0; (renderer = plugin->renderer(i)) && i < pluginData.size(); ++i) { | ||||
75 | const auto metaData = pluginData.at(i).toObject(); | ||||
76 | const auto type = metaData.value(QLatin1String("type")).toString(); | ||||
77 | if (type.isEmpty()) { | ||||
78 | qCWarning(MESSAGEVIEWER_LOG) << path << "returned empty type specification for index" << i; | ||||
79 | break; | ||||
80 | } | ||||
81 | // TODO add plugin priority like we have for BPFs | ||||
82 | qCDebug(MESSAGEVIEWER_LOG) << "renderer plugin for " << type; | ||||
83 | insert(type, renderer/*, priority*/); | ||||
84 | } | ||||
85 | }); | ||||
54 | } | 86 | } | ||
55 | 87 | | |||
56 | void MessagePartRendererFactoryPrivate::initalize_builtin_renderers() | 88 | void MessagePartRendererFactoryPrivate::initalize_builtin_renderers() | ||
57 | { | 89 | { | ||
58 | insert(QStringLiteral("MimeTreeParser::MessagePart"), new MessagePartRenderer()); | 90 | insert(QStringLiteral("MimeTreeParser::MessagePart"), new MessagePartRenderer()); | ||
59 | insert(QStringLiteral("MimeTreeParser::TextMessagePart"), new TextMessagePartRenderer()); | 91 | insert(QStringLiteral("MimeTreeParser::TextMessagePart"), new TextMessagePartRenderer()); | ||
60 | insert(QStringLiteral("MimeTreeParser::AttachmentMessagePart"), new AttachmentMessagePartRenderer()); | 92 | insert(QStringLiteral("MimeTreeParser::AttachmentMessagePart"), new AttachmentMessagePartRenderer()); | ||
61 | } | 93 | } | ||
Show All 32 Lines |