diff --git a/messageviewer/src/CMakeLists.txt b/messageviewer/src/CMakeLists.txt --- a/messageviewer/src/CMakeLists.txt +++ b/messageviewer/src/CMakeLists.txt @@ -165,6 +165,7 @@ messagepartthemes/default/plugins/textmessagepartrenderer.cpp messagepartthemes/default/plugins/quotehtml.cpp messagepartthemes/default/messagepartrenderbase.cpp + messagepartthemes/default/messagepartrenderplugin.cpp messagepartthemes/default/messagepartrendererfactory.cpp ) @@ -366,6 +367,16 @@ RELATIVE viewerplugins ) +ecm_generate_headers(MessageViewer_Camelcaserenderer_HEADERS + HEADER_NAMES + HtmlBlock + MessagePartRendererBase + MessagePartRenderPlugin + REQUIRED_HEADERS MessageViewer_renderer_HEADERS + PREFIX MessageViewer + RELATIVE messagepartthemes/default + ) + ecm_generate_pri_file(BASE_NAME MessageViewer LIB_NAME KF5MessageViewer DEPS "PimCommon MessageCore AkonadiCore AkonadiMime Contacts Libkleo MimeTreeParser" FILENAME_VAR PRI_FILENAME INCLUDE_INSTALL_DIR ${KDE_INSTALL_INCLUDEDIR_KF5}/MessageViewer @@ -384,6 +395,7 @@ ${MessageViewer_Camelcaseantispam_HEADERS} ${MessageViewer_Camelfindbar_HEADERS} ${MessageViewer_Camelcasescam_HEADERS} + ${MessageViewer_Camelcaserenderer_HEADERS} DESTINATION ${KDE_INSTALL_INCLUDEDIR_KF5}/MessageViewer COMPONENT Devel ) @@ -401,6 +413,7 @@ ${MessageViewer_widgets_HEADERS} ${MessageViewer_antispam_HEADERS} ${MessageViewer_findbar_HEADERS} + ${MessageViewer_renderer_HEADERS} ${CMAKE_CURRENT_BINARY_DIR}/messageviewer_export.h ${CMAKE_CURRENT_BINARY_DIR}/globalsettings_messageviewer.h ${CMAKE_CURRENT_BINARY_DIR}/messageviewer_debug.h diff --git a/messageviewer/src/messagepartthemes/default/defaultrenderer.cpp b/messageviewer/src/messagepartthemes/default/defaultrenderer.cpp --- a/messageviewer/src/messagepartthemes/default/defaultrenderer.cpp +++ b/messageviewer/src/messagepartthemes/default/defaultrenderer.cpp @@ -861,12 +861,11 @@ { if (!mRendererFactory) return false; - const auto registry = mRendererFactory->typeRegistry(className); - if (registry.empty()) - return false; - - const auto plugin = registry.at(0); - return plugin->render(msgPart, htmlWriter, this); + for (auto r : mRendererFactory->typeRegistry(className)) { + if (r->render(msgPart, htmlWriter, this)) + return true; + } + return false; } QString DefaultRendererPrivate::renderFactory(const MessagePart::Ptr &msgPart, HtmlWriter *_htmlWriter) diff --git a/messageviewer/src/messagepartthemes/default/htmlblock.h b/messageviewer/src/messagepartthemes/default/htmlblock.h --- a/messageviewer/src/messagepartthemes/default/htmlblock.h +++ b/messageviewer/src/messagepartthemes/default/htmlblock.h @@ -20,6 +20,8 @@ #ifndef __MIMETREEPARSER_HTMLBLOCK_H__ #define __MIMETREEPARSER_HTMLBLOCK_H__ +#include "messageviewer_export.h" + #include #include @@ -30,7 +32,7 @@ namespace MimeTreeParser { class HtmlWriter; -class HTMLBlock +class MESSAGEVIEWER_EXPORT HTMLBlock { public: typedef QSharedPointer Ptr; @@ -53,7 +55,7 @@ // The attachment mark is a div that is placed around the attchment. It is used for drawing // a yellow border around the attachment when scrolling to it. When scrolling to it, the border // color of the div is changed, see KMReaderWin::scrollToAttachment(). -class AttachmentMarkBlock : public HTMLBlock +class MESSAGEVIEWER_EXPORT AttachmentMarkBlock : public HTMLBlock { public: AttachmentMarkBlock(MimeTreeParser::HtmlWriter *writer, KMime::Content *node); diff --git a/messageviewer/src/messagepartthemes/default/messagepartrendererbase.h b/messageviewer/src/messagepartthemes/default/messagepartrendererbase.h --- a/messageviewer/src/messagepartthemes/default/messagepartrendererbase.h +++ b/messageviewer/src/messagepartthemes/default/messagepartrendererbase.h @@ -47,16 +47,16 @@ class CSSHelperBase; -class RenderContext +class MESSAGEVIEWER_EXPORT RenderContext { public: virtual ~RenderContext(); virtual CSSHelperBase* cssHelper() const = 0; virtual bool renderWithFactory(const QString &className, const MimeTreeParser::MessagePartPtr &msgPart, MimeTreeParser::HtmlWriter *writer) = 0; }; -class MessagePartRendererBase +class MESSAGEVIEWER_EXPORT MessagePartRendererBase { public: MessagePartRendererBase(); diff --git a/messageviewer/src/messagepartthemes/default/messagepartrendererfactory.cpp b/messageviewer/src/messagepartthemes/default/messagepartrendererfactory.cpp --- a/messageviewer/src/messagepartthemes/default/messagepartrendererfactory.cpp +++ b/messageviewer/src/messagepartthemes/default/messagepartrendererfactory.cpp @@ -30,14 +30,20 @@ #include "messagepartrendererfactory.h" #include "messagepartrendererfactory_p.h" +#include "messagepartrenderplugin.h" #include "messagepartrendererbase.h" #include "messageviewer_debug.h" #include "plugins/attachmentmessagepartrenderer.h" #include "plugins/messagepartrenderer.h" #include "plugins/textmessagepartrenderer.h" +#include + +#include +#include + using namespace MessageViewer; void MessagePartRendererFactoryPrivate::setup() @@ -50,7 +56,33 @@ void MessagePartRendererFactoryPrivate::loadPlugins() { - qCDebug(MESSAGEVIEWER_LOG) << "plugin loading is not enabled in libmimetreeparser"; + KPluginLoader::forEachPlugin(QStringLiteral("messageviewer/bodypartformatter"), [this](const QString &path) { + QPluginLoader loader(path); + const auto pluginData = loader.metaData().value(QLatin1String("MetaData")).toObject().value(QLatin1String("renderer")).toArray(); + if (pluginData.isEmpty()) { + qCWarning(MESSAGEVIEWER_LOG) << "Plugin" << path << "has no meta data."; + return; + } + + auto plugin = qobject_cast(loader.instance()); + if (!plugin) { + qCWarning(MESSAGEVIEWER_LOG) << path << "is not a MessagePartRendererPlugin"; + return; + } + + MessagePartRendererBase *renderer = nullptr; + for (int i = 0; (renderer = plugin->renderer(i)) && i < pluginData.size(); ++i) { + const auto metaData = pluginData.at(i).toObject(); + const auto type = metaData.value(QLatin1String("type")).toString(); + if (type.isEmpty()) { + qCWarning(MESSAGEVIEWER_LOG) << path << "returned empty type specification for index" << i; + break; + } + // TODO add plugin priority like we have for BPFs + qCDebug(MESSAGEVIEWER_LOG) << "renderer plugin for " << type; + insert(type, renderer/*, priority*/); + } + }); } void MessagePartRendererFactoryPrivate::initalize_builtin_renderers() diff --git a/messageviewer/src/messagepartthemes/default/messagepartrenderplugin.h b/messageviewer/src/messagepartthemes/default/messagepartrenderplugin.h new file mode 100644 --- /dev/null +++ b/messageviewer/src/messagepartthemes/default/messagepartrenderplugin.h @@ -0,0 +1,45 @@ +/* + Copyright (c) 2017 Volker Krause + + This library is free software; you can redistribute it and/or modify it + under the terms of the GNU Library General Public License as published by + the Free Software Foundation; either version 2 of the License, or (at your + option) any later version. + + This library is distributed in the hope that it will be useful, but WITHOUT + ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public + License for more details. + + You should have received a copy of the GNU Library General Public License + along with this library; see the file COPYING.LIB. If not, write to the + Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA + 02110-1301, USA. +*/ + +#ifndef MESSAGEVIEWER_MESSAGEPARTRENDERPLUGIN_H +#define MESSAGEVIEWER_MESSAGEPARTRENDERPLUGIN_H + +#include "messageviewer_export.h" + +#include + +namespace MessageViewer { + +class MessagePartRendererBase; + +/** + * Plugin interface for MessagePartRendererBase instances. + */ +class MESSAGEVIEWER_EXPORT MessagePartRenderPlugin +{ +public: + virtual ~MessagePartRenderPlugin(); + virtual MessagePartRendererBase* renderer(int index) = 0; +}; + +} + +Q_DECLARE_INTERFACE(MessageViewer::MessagePartRenderPlugin, "org.kde.messageviewer.messagepartrenderer/1.0") + +#endif // MESSAGEVIEWER_MESSAGEPARTRENDERPLUGIN_H diff --git a/messageviewer/src/messagepartthemes/default/messagepartrenderplugin.cpp b/messageviewer/src/messagepartthemes/default/messagepartrenderplugin.cpp new file mode 100644 --- /dev/null +++ b/messageviewer/src/messagepartthemes/default/messagepartrenderplugin.cpp @@ -0,0 +1,24 @@ +/* + Copyright (c) 2017 Volker Krause + + This library is free software; you can redistribute it and/or modify it + under the terms of the GNU Library General Public License as published by + the Free Software Foundation; either version 2 of the License, or (at your + option) any later version. + + This library is distributed in the hope that it will be useful, but WITHOUT + ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public + License for more details. + + You should have received a copy of the GNU Library General Public License + along with this library; see the file COPYING.LIB. If not, write to the + Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA + 02110-1301, USA. +*/ + +#include "messagepartrenderplugin.h" + +using namespace MessageViewer; + +MessagePartRenderPlugin::~MessagePartRenderPlugin() = default;