diff --git a/CMakeLists.txt b/CMakeLists.txt --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,5 +1,5 @@ cmake_minimum_required(VERSION 3.0) -set(PIM_VERSION "5.6.50") +set(PIM_VERSION "5.6.51") if (POLICY CMP0053) cmake_policy(SET CMP0053 NEW) diff --git a/messageviewer/src/CMakeLists.txt b/messageviewer/src/CMakeLists.txt --- a/messageviewer/src/CMakeLists.txt +++ b/messageviewer/src/CMakeLists.txt @@ -59,8 +59,6 @@ ) set(libmessageviewer_viewer_SRCS - viewer/bodypartformatterfactory.cpp - viewer/bodypartformatterfactorysingleton.cpp viewer/csshelper.cpp viewer/csshelperbase.cpp viewer/editorwatcher.cpp @@ -282,7 +280,6 @@ ObjectTreeEmptySource EditorWatcher Stl_Util - BodyPartFormatterFactory REQUIRED_HEADERS MessageViewer_viewer_HEADERS PREFIX MessageViewer RELATIVE viewer diff --git a/messageviewer/src/interfaces/bodyparturlhandler.h b/messageviewer/src/interfaces/bodyparturlhandler.h --- a/messageviewer/src/interfaces/bodyparturlhandler.h +++ b/messageviewer/src/interfaces/bodyparturlhandler.h @@ -46,7 +46,7 @@ class Viewer; } -namespace MimeTreeParser { +namespace MessageViewer { namespace Interface { /** * @short An interface to body part reader link handlers diff --git a/messageviewer/src/messagepartthemes/default/autotests/setupenv.h b/messageviewer/src/messagepartthemes/default/autotests/setupenv.h --- a/messageviewer/src/messagepartthemes/default/autotests/setupenv.h +++ b/messageviewer/src/messagepartthemes/default/autotests/setupenv.h @@ -24,7 +24,7 @@ #include #include -#include +#include #include #include @@ -106,9 +106,9 @@ return mShowExpandQuotesMark; } - const MimeTreeParser::BodyPartFormatterBaseFactory *bodyPartFormatterFactory() override + const MimeTreeParser::BodyPartFormatterFactory *bodyPartFormatterFactory() override { - return &mBodyPartFormatterBaseFactory; + return &mBodyPartFormatterFactory; } bool decryptMessage() const override @@ -172,7 +172,7 @@ MimeTreeParser::HtmlWriter *mWriter; MessageViewer::CSSHelperBase *mCSSHelper; QString mAttachmentStrategy; - MimeTreeParser::BodyPartFormatterBaseFactory mBodyPartFormatterBaseFactory; + MimeTreeParser::BodyPartFormatterFactory mBodyPartFormatterFactory; bool mHtmlLoadExternal; bool mDecryptMessage; bool mShowSignatureDetails; 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 @@ -31,6 +31,7 @@ #include "messagepartrendererfactory.h" #include "messagepartrendererfactory_p.h" #include "messagepartrenderplugin.h" +#include "viewer/urlhandlermanager.h" #include "messagepartrendererbase.h" #include "messageviewer_debug.h" @@ -82,6 +83,11 @@ qCDebug(MESSAGEVIEWER_LOG) << "renderer plugin for " << type; insert(type, renderer /*, priority*/); } + + const Interface::BodyPartURLHandler *handler = nullptr; + for (int i = 0; (handler = plugin->urlHandler(i)); ++i) { + URLHandlerManager::instance()->registerHandler(handler); + } }); } diff --git a/messageviewer/src/messagepartthemes/default/messagepartrenderplugin.h b/messageviewer/src/messagepartthemes/default/messagepartrenderplugin.h --- a/messageviewer/src/messagepartthemes/default/messagepartrenderplugin.h +++ b/messageviewer/src/messagepartthemes/default/messagepartrenderplugin.h @@ -24,7 +24,11 @@ #include + namespace MessageViewer { +namespace Interface { +class BodyPartURLHandler; +} class MessagePartRendererBase; /** @@ -35,6 +39,7 @@ public: virtual ~MessagePartRenderPlugin(); virtual MessagePartRendererBase *renderer(int index) = 0; + virtual const Interface::BodyPartURLHandler *urlHandler(int idx) const; }; } diff --git a/messageviewer/src/messagepartthemes/default/messagepartrenderplugin.cpp b/messageviewer/src/messagepartthemes/default/messagepartrenderplugin.cpp --- a/messageviewer/src/messagepartthemes/default/messagepartrenderplugin.cpp +++ b/messageviewer/src/messagepartthemes/default/messagepartrenderplugin.cpp @@ -19,6 +19,14 @@ #include "messagepartrenderplugin.h" +#include "interfaces/bodyparturlhandler.h" + using namespace MessageViewer; MessagePartRenderPlugin::~MessagePartRenderPlugin() = default; + +const Interface::BodyPartURLHandler *MessagePartRenderPlugin::urlHandler(int idx) const +{ + Q_UNUSED(idx); + return nullptr; +} diff --git a/messageviewer/src/viewer/bodypartformatterfactory.h b/messageviewer/src/viewer/bodypartformatterfactory.h deleted file mode 100644 --- a/messageviewer/src/viewer/bodypartformatterfactory.h +++ /dev/null @@ -1,54 +0,0 @@ -/* - bodypartformatterfactory.h - - This file is part of KMail, the KDE mail client. - Copyright (c) 2004 Marc Mutz , - Ingo Kloecker - - KMail is free software; you can redistribute it and/or modify it - under the terms of the GNU General Public License as published by - the Free Software Foundation; either version 2 of the License, or - (at your option) any later version. - - KMail 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 - General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program; if not, write to the Free Software - Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA - - In addition, as a special exception, the copyright holders give - permission to link the code of this program with any edition of - the Qt library by Trolltech AS, Norway (or with modified versions - of Qt that use the same license as Qt), and distribute linked - combinations including the two. You must obey the GNU General - Public License in all respects for all of the code used other than - Qt. If you modify this file, you may extend this exception to - your version of the file, but you are not obligated to do so. If - you do not wish to do so, delete this exception statement from - your version. -*/ - -#ifndef __MESSAGEVIEWER_BODYPARTFORMATTERFACTORY_H__ -#define __MESSAGEVIEWER_BODYPARTFORMATTERFACTORY_H__ - -#include "messageviewer_export.h" - -#include - -namespace MessageViewer { -class MESSAGEVIEWER_EXPORT BodyPartFormatterFactory : public MimeTreeParser:: - BodyPartFormatterBaseFactory -{ -public: - BodyPartFormatterFactory(); - ~BodyPartFormatterFactory(); - -protected: - void loadPlugins() override; -}; -} - -#endif // __MESSAGEVIEWER_BODYPARTFORMATTERFACTORY_H__ diff --git a/messageviewer/src/viewer/bodypartformatterfactory.cpp b/messageviewer/src/viewer/bodypartformatterfactory.cpp deleted file mode 100644 --- a/messageviewer/src/viewer/bodypartformatterfactory.cpp +++ /dev/null @@ -1,94 +0,0 @@ -/* - bodypartformatterfactory.cpp - - This file is part of KMail, the KDE mail client. - Copyright (c) 2004 Marc Mutz , - Ingo Kloecker - - KMail is free software; you can redistribute it and/or modify it - under the terms of the GNU General Public License as published by - the Free Software Foundation; either version 2 of the License, or - (at your option) any later version. - - KMail 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 - General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program; if not, write to the Free Software - Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA - - In addition, as a special exception, the copyright holders give - permission to link the code of this program with any edition of - the Qt library by Trolltech AS, Norway (or with modified versions - of Qt that use the same license as Qt), and distribute linked - combinations including the two. You must obey the GNU General - Public License in all respects for all of the code used other than - Qt. If you modify this file, you may extend this exception to - your version of the file, but you are not obligated to do so. If - you do not wish to do so, delete this exception statement from - your version. -*/ - -#include "bodypartformatterfactory.h" -#include "urlhandlermanager.h" -#include "messageviewer_debug.h" - -#include - -#include - -#include -#include - -using namespace MessageViewer; - -BodyPartFormatterFactory::BodyPartFormatterFactory() - : MimeTreeParser::BodyPartFormatterBaseFactory() -{ -} - -BodyPartFormatterFactory::~BodyPartFormatterFactory() -{ -} - -void BodyPartFormatterFactory::loadPlugins() -{ - KPluginLoader::forEachPlugin(QStringLiteral("messageviewer/bodypartformatter"), [this](const QString &path) { - QPluginLoader loader(path); - const auto formatterData = loader.metaData().value(QLatin1String("MetaData")).toObject().value(QLatin1String("formatter")).toArray(); - if (formatterData.isEmpty()) { - qCWarning(MESSAGEVIEWER_LOG) << "Plugin" << path << "has no meta data."; - return; - } - - auto plugin = qobject_cast(loader.instance()); - if (!plugin) { - qCWarning(MESSAGEVIEWER_LOG) << "BodyPartFormatterFactory: plugin" << path - << "is not valid!"; - return; - } - - const MimeTreeParser::Interface::BodyPartFormatter *bfp = nullptr; - for (int i = 0; (bfp = plugin->bodyPartFormatter(i)) && i < formatterData.size(); ++i) { - const auto metaData = formatterData.at(i).toObject(); - const auto mimetype = metaData.value(QLatin1String("mimetype")).toString(); - if (mimetype.isEmpty()) { - qCWarning(MESSAGEVIEWER_LOG) << "BodyPartFormatterFactory: plugin" << path - << "returned empty mimetype specification for index" - << i; - break; - } - // priority should always be higher than the built-in ones, otherwise what's the point? - const auto priority = metaData.value(QLatin1String("priority")).toInt() + 100; - qCDebug(MESSAGEVIEWER_LOG) << "plugin for " << mimetype << priority; - insert(mimetype, bfp, priority); - } - - const MimeTreeParser::Interface::BodyPartURLHandler *handler = nullptr; - for (int i = 0; (handler = plugin->urlHandler(i)); ++i) { - URLHandlerManager::instance()->registerHandler(handler); - } - }); -} diff --git a/messageviewer/src/viewer/bodypartformatterfactorysingleton.h b/messageviewer/src/viewer/bodypartformatterfactorysingleton.h deleted file mode 100644 --- a/messageviewer/src/viewer/bodypartformatterfactorysingleton.h +++ /dev/null @@ -1,40 +0,0 @@ -/* - Copyright (c) 2016 Sandro Knauß - - KMail is free software; you can redistribute it and/or modify it - under the terms of the GNU General Public License as published by - the Free Software Foundation; either version 2 of the License, or - (at your option) any later version. - - KMail 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 - General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program; if not, write to the Free Software - Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA - - In addition, as a special exception, the copyright holders give - permission to link the code of this program with any edition of - the Qt library by Trolltech AS, Norway (or with modified versions - of Qt that use the same license as Qt), and distribute linked - combinations including the two. You must obey the GNU General - Public License in all respects for all of the code used other than - Qt. If you modify this file, you may extend this exception to - your version of the file, but you are not obligated to do so. If - you do not wish to do so, delete this exception statement from - your version. -*/ - -#ifndef __MESSAGEVIEWER_BODYPARTFORMATTERFACTORYSIGNLETON_P_H__ -#define __MESSAGEVIEWER_BODYPARTFORMATTERFACTORYSIGNLETON_P_H__ - -namespace MimeTreeParser { -class BodyPartFormatterBaseFactory; -} - -namespace MessageViewer { -const MimeTreeParser::BodyPartFormatterBaseFactory *bodyPartFormatterBaseFactoryInstance(); -} -#endif diff --git a/messageviewer/src/viewer/bodypartformatterfactorysingleton.cpp b/messageviewer/src/viewer/bodypartformatterfactorysingleton.cpp deleted file mode 100644 --- a/messageviewer/src/viewer/bodypartformatterfactorysingleton.cpp +++ /dev/null @@ -1,48 +0,0 @@ -/* - Copyright (c) 2016 Sandro Knauß - - KMail is free software; you can redistribute it and/or modify it - under the terms of the GNU General Public License as published by - the Free Software Foundation; either version 2 of the License, or - (at your option) any later version. - - KMail 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 - General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program; if not, write to the Free Software - Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA - - In addition, as a special exception, the copyright holders give - permission to link the code of this program with any edition of - the Qt library by Trolltech AS, Norway (or with modified versions - of Qt that use the same license as Qt), and distribute linked - combinations including the two. You must obey the GNU General - Public License in all respects for all of the code used other than - Qt. If you modify this file, you may extend this exception to - your version of the file, but you are not obligated to do so. If - you do not wish to do so, delete this exception statement from - your version. -*/ - -#include "bodypartformatterfactorysingleton.h" -#include "bodypartformatterfactory.h" - -#include - -using namespace MessageViewer; - -static QSharedPointer singleton; - -const MimeTreeParser::BodyPartFormatterBaseFactory *MessageViewer:: -bodyPartFormatterBaseFactoryInstance() -{ - if (!singleton) { - singleton = QSharedPointer( - new BodyPartFormatterFactory()); - } - - return singleton.data(); -} diff --git a/messageviewer/src/viewer/objecttreeemptysource.h b/messageviewer/src/viewer/objecttreeemptysource.h --- a/messageviewer/src/viewer/objecttreeemptysource.h +++ b/messageviewer/src/viewer/objecttreeemptysource.h @@ -50,7 +50,7 @@ bool autoImportKeys() const override; bool showEmoticons() const override; bool showExpandQuotesMark() const override; - const MimeTreeParser::BodyPartFormatterBaseFactory *bodyPartFormatterFactory() override; + const MimeTreeParser::BodyPartFormatterFactory *bodyPartFormatterFactory() override; void render(const MimeTreeParser::MessagePartPtr &msgPart, MimeTreeParser::HtmlWriter *htmlWriter) override; bool isPrinting() const override; private: diff --git a/messageviewer/src/viewer/objecttreeemptysource.cpp b/messageviewer/src/viewer/objecttreeemptysource.cpp --- a/messageviewer/src/viewer/objecttreeemptysource.cpp +++ b/messageviewer/src/viewer/objecttreeemptysource.cpp @@ -23,11 +23,10 @@ #include #include +#include #include "messagepartthemes/default/defaultrenderer.h" -#include "bodypartformatterfactorysingleton.h" - using namespace MessageViewer; namespace MessageViewer { @@ -131,9 +130,9 @@ return false; } -const MimeTreeParser::BodyPartFormatterBaseFactory *EmptySource::bodyPartFormatterFactory() +const MimeTreeParser::BodyPartFormatterFactory *EmptySource::bodyPartFormatterFactory() { - return bodyPartFormatterBaseFactoryInstance(); + return MimeTreeParser::BodyPartFormatterFactory::instance(); } bool EmptySource::isPrinting() const diff --git a/messageviewer/src/viewer/objecttreeviewersource.h b/messageviewer/src/viewer/objecttreeviewersource.h --- a/messageviewer/src/viewer/objecttreeviewersource.h +++ b/messageviewer/src/viewer/objecttreeviewersource.h @@ -47,7 +47,7 @@ bool autoImportKeys() const override; bool showEmoticons() const override; bool showExpandQuotesMark() const override; - const MimeTreeParser::BodyPartFormatterBaseFactory *bodyPartFormatterFactory() override; + const MimeTreeParser::BodyPartFormatterFactory *bodyPartFormatterFactory() override; void render(const MimeTreeParser::MessagePartPtr &msgPart, MimeTreeParser::HtmlWriter *htmlWriter) override; bool isPrinting() const override; private: diff --git a/messageviewer/src/viewer/objecttreeviewersource.cpp b/messageviewer/src/viewer/objecttreeviewersource.cpp --- a/messageviewer/src/viewer/objecttreeviewersource.cpp +++ b/messageviewer/src/viewer/objecttreeviewersource.cpp @@ -19,7 +19,7 @@ #include "objecttreeviewersource.h" #include "csshelper.h" -#include "bodypartformatterfactorysingleton.h" +#include #include #include "messagepartthemes/default/defaultrenderer.h" @@ -119,9 +119,9 @@ return MessageViewer::MessageViewerSettings::self()->showExpandQuotesMark(); } -const MimeTreeParser::BodyPartFormatterBaseFactory *MailViewerSource::bodyPartFormatterFactory() +const MimeTreeParser::BodyPartFormatterFactory *MailViewerSource::bodyPartFormatterFactory() { - return bodyPartFormatterBaseFactoryInstance(); + return MimeTreeParser::BodyPartFormatterFactory::instance(); } bool MailViewerSource::isPrinting() const diff --git a/messageviewer/src/viewer/urlhandlermanager.h b/messageviewer/src/viewer/urlhandlermanager.h --- a/messageviewer/src/viewer/urlhandlermanager.h +++ b/messageviewer/src/viewer/urlhandlermanager.h @@ -40,18 +40,16 @@ class QString; class QPoint; -namespace MessageViewer { -class ViewerPrivate; +namespace MimeTreeParser { +class URLHandler; } -namespace MimeTreeParser { +namespace MessageViewer { namespace Interface { class BodyPartURLHandler; } -class URLHandler; -} +class ViewerPrivate; -namespace MessageViewer { /** * @short Singleton to manage the list of URLHandlers * @author Marc Mutz @@ -69,8 +67,8 @@ void registerHandler(const MimeTreeParser::URLHandler *handler); void unregisterHandler(const MimeTreeParser::URLHandler *handler); - void registerHandler(const MimeTreeParser::Interface::BodyPartURLHandler *handler); - void unregisterHandler(const MimeTreeParser::Interface::BodyPartURLHandler *handler); + void registerHandler(const Interface::BodyPartURLHandler *handler); + void unregisterHandler(const Interface::BodyPartURLHandler *handler); bool handleClick(const QUrl &url, ViewerPrivate *w = nullptr) const; bool handleShiftClick(const QUrl &url, ViewerPrivate *window = nullptr) const; diff --git a/messageviewer/src/viewer/urlhandlermanager.cpp b/messageviewer/src/viewer/urlhandlermanager.cpp --- a/messageviewer/src/viewer/urlhandlermanager.cpp +++ b/messageviewer/src/viewer/urlhandlermanager.cpp @@ -350,22 +350,22 @@ bool handleContextMenuRequest(const QUrl &, const QPoint &, ViewerPrivate *) const override; QString statusBarMessage(const QUrl &, ViewerPrivate *) const override; - void registerHandler(const MimeTreeParser::Interface::BodyPartURLHandler *handler); - void unregisterHandler(const MimeTreeParser::Interface::BodyPartURLHandler *handler); + void registerHandler(const Interface::BodyPartURLHandler *handler); + void unregisterHandler(const Interface::BodyPartURLHandler *handler); private: - typedef QVector BodyPartHandlerList; + typedef QVector BodyPartHandlerList; BodyPartHandlerList mHandlers; }; URLHandlerManager::BodyPartURLHandlerManager::~BodyPartURLHandlerManager() { for_each(mHandlers.begin(), mHandlers.end(), - DeleteAndSetToZero()); + DeleteAndSetToZero()); } void URLHandlerManager::BodyPartURLHandlerManager::registerHandler( - const MimeTreeParser::Interface::BodyPartURLHandler *handler) + const Interface::BodyPartURLHandler *handler) { if (!handler) { return; @@ -375,7 +375,7 @@ } void URLHandlerManager::BodyPartURLHandlerManager::unregisterHandler( - const MimeTreeParser::Interface::BodyPartURLHandler *handler) + const Interface::BodyPartURLHandler *handler) { // don't delete them, only remove them from the list! mHandlers.erase(remove(mHandlers.begin(), mHandlers.end(), handler), mHandlers.end()); @@ -517,15 +517,14 @@ mHandlers.erase(remove(mHandlers.begin(), mHandlers.end(), handler), mHandlers.end()); } -void URLHandlerManager::registerHandler(const MimeTreeParser::Interface::BodyPartURLHandler *handler) +void URLHandlerManager::registerHandler(const Interface::BodyPartURLHandler *handler) { if (mBodyPartURLHandlerManager) { mBodyPartURLHandlerManager->registerHandler(handler); } } -void URLHandlerManager::unregisterHandler( - const MimeTreeParser::Interface::BodyPartURLHandler *handler) +void URLHandlerManager::unregisterHandler(const Interface::BodyPartURLHandler *handler) { if (mBodyPartURLHandlerManager) { mBodyPartURLHandlerManager->unregisterHandler(handler); diff --git a/mimetreeparser/autotests/bodypartformatterbasefactorytest.cpp b/mimetreeparser/autotests/bodypartformatterbasefactorytest.cpp --- a/mimetreeparser/autotests/bodypartformatterbasefactorytest.cpp +++ b/mimetreeparser/autotests/bodypartformatterbasefactorytest.cpp @@ -17,7 +17,7 @@ 02110-1301, USA. */ -#include "viewer/bodypartformatterbasefactory.h" +#include "viewer/bodypartformatterfactory.h" #include "interfaces/bodypartformatter.h" #include @@ -28,7 +28,7 @@ { }; -class TestFactory : public BodyPartFormatterBaseFactory +class TestFactory : public BodyPartFormatterFactory { public: void loadPlugins() override diff --git a/mimetreeparser/autotests/setupenv.h b/mimetreeparser/autotests/setupenv.h --- a/mimetreeparser/autotests/setupenv.h +++ b/mimetreeparser/autotests/setupenv.h @@ -24,7 +24,7 @@ #include #include #include -#include +#include #include #include @@ -91,9 +91,9 @@ return false; } - const BodyPartFormatterBaseFactory *bodyPartFormatterFactory() override + const BodyPartFormatterFactory *bodyPartFormatterFactory() override { - return &mBodyPartFormatterBaseFactory; + return &mBodyPartFormatterFactory; } bool decryptMessage() const override @@ -162,7 +162,7 @@ private: MimeTreeParser::HtmlWriter *mWriter = nullptr; QString mAttachmentStrategy; - BodyPartFormatterBaseFactory mBodyPartFormatterBaseFactory; + BodyPartFormatterFactory mBodyPartFormatterFactory; MimeTreeParser::Util::HtmlMode mPreferredMode; bool mHtmlLoadExternal = false; bool mDecryptMessage = false; diff --git a/mimetreeparser/src/CMakeLists.txt b/mimetreeparser/src/CMakeLists.txt --- a/mimetreeparser/src/CMakeLists.txt +++ b/mimetreeparser/src/CMakeLists.txt @@ -27,7 +27,7 @@ utils/util.cpp viewer/attachmentstrategy.cpp viewer/bodypartformatter.cpp - viewer/bodypartformatterbasefactory.cpp + viewer/bodypartformatterfactory.cpp viewer/cryptohelper.cpp viewer/nodehelper.cpp viewer/objecttreeparser.cpp @@ -52,7 +52,7 @@ ecm_generate_headers(MimeTreeParser_Camelcaseviewer_HEADERS HEADER_NAMES AttachmentStrategy - BodyPartFormatterBaseFactory + BodyPartFormatterFactory Enums MessagePart NodeHelper @@ -156,6 +156,7 @@ QGpgme KF5::Codecs KF5::I18n + KF5::CoreAddons KF5::Mime Qt5::Gui ) diff --git a/mimetreeparser/src/interfaces/bodypartformatter.h b/mimetreeparser/src/interfaces/bodypartformatter.h --- a/mimetreeparser/src/interfaces/bodypartformatter.h +++ b/mimetreeparser/src/interfaces/bodypartformatter.h @@ -100,7 +100,6 @@ virtual ~BodyPartFormatterPlugin(); virtual const BodyPartFormatter *bodyPartFormatter(int idx) const = 0; - virtual const BodyPartURLHandler *urlHandler(int idx) const; }; } // namespace Interface } diff --git a/mimetreeparser/src/interfaces/bodypartformatter.cpp b/mimetreeparser/src/interfaces/bodypartformatter.cpp --- a/mimetreeparser/src/interfaces/bodypartformatter.cpp +++ b/mimetreeparser/src/interfaces/bodypartformatter.cpp @@ -54,9 +54,3 @@ BodyPartFormatterPlugin::~BodyPartFormatterPlugin() { } - -const BodyPartURLHandler *BodyPartFormatterPlugin::urlHandler(int idx) const -{ - Q_UNUSED(idx); - return nullptr; -} diff --git a/mimetreeparser/src/interfaces/objecttreesource.h b/mimetreeparser/src/interfaces/objecttreesource.h --- a/mimetreeparser/src/interfaces/objecttreesource.h +++ b/mimetreeparser/src/interfaces/objecttreesource.h @@ -31,7 +31,7 @@ namespace MimeTreeParser { class HtmlWriter; class AttachmentStrategy; -class BodyPartFormatterBaseFactory; +class BodyPartFormatterFactory; class MessagePart; typedef QSharedPointer MessagePartPtr; } @@ -87,7 +87,7 @@ virtual bool showExpandQuotesMark() const = 0; - virtual const BodyPartFormatterBaseFactory *bodyPartFormatterFactory() = 0; + virtual const BodyPartFormatterFactory *bodyPartFormatterFactory() = 0; virtual void render(const MessagePartPtr &msgPart, HtmlWriter *htmlWriter) = 0; diff --git a/mimetreeparser/src/viewer/bodypartformatter.cpp b/mimetreeparser/src/viewer/bodypartformatter.cpp --- a/mimetreeparser/src/viewer/bodypartformatter.cpp +++ b/mimetreeparser/src/viewer/bodypartformatter.cpp @@ -45,8 +45,8 @@ #include "interfaces/bodypart.h" #include "interfaces/htmlwriter.h" -#include "viewer/bodypartformatterbasefactory.h" -#include "viewer/bodypartformatterbasefactory_p.h" +#include "viewer/bodypartformatterfactory.h" +#include "viewer/bodypartformatterfactory_p.h" #include "viewer/attachmentstrategy.h" #include "viewer/objecttreeparser.h" @@ -157,7 +157,7 @@ } } // anon namespace -void BodyPartFormatterBaseFactoryPrivate::messageviewer_create_builtin_bodypart_formatters() +void BodyPartFormatterFactoryPrivate::messageviewer_create_builtin_bodypart_formatters() { insert(QStringLiteral("application/pkcs7-mime"), ApplicationPkcs7MimeBodyPartFormatter::create()); insert(QStringLiteral("application/x-pkcs7-mime"), ApplicationPkcs7MimeBodyPartFormatter::create()); diff --git a/mimetreeparser/src/viewer/bodypartformatterbasefactory.h b/mimetreeparser/src/viewer/bodypartformatterfactory.h rename from mimetreeparser/src/viewer/bodypartformatterbasefactory.h rename to mimetreeparser/src/viewer/bodypartformatterfactory.h --- a/mimetreeparser/src/viewer/bodypartformatterbasefactory.h +++ b/mimetreeparser/src/viewer/bodypartformatterfactory.h @@ -31,8 +31,8 @@ your version. */ -#ifndef __MIMETREEPARSER_BODYPARTFORMATTERBASEFACTORY_H__ -#define __MIMETREEPARSER_BODYPARTFORMATTERBASEFACTORY_H__ +#ifndef __MIMETREEPARSER_BODYPARTFORMATTERFACTORY_H__ +#define __MIMETREEPARSER_BODYPARTFORMATTERFACTORY_H__ #include "mimetreeparser_export.h" @@ -44,14 +44,16 @@ class BodyPartFormatter; } -class BodyPartFormatterBaseFactoryPrivate; +class BodyPartFormatterFactoryPrivate; /** The place to obtain BodyPartFormatter candidates for a given mime type. */ -class MIMETREEPARSER_EXPORT BodyPartFormatterBaseFactory +class MIMETREEPARSER_EXPORT BodyPartFormatterFactory { public: - BodyPartFormatterBaseFactory(); - virtual ~BodyPartFormatterBaseFactory(); + BodyPartFormatterFactory(); + virtual ~BodyPartFormatterFactory(); + + static BodyPartFormatterFactory* instance(); /** * Returns all suitable formatters for the given mimetype. @@ -65,9 +67,9 @@ virtual void loadPlugins(); private: - Q_DISABLE_COPY(BodyPartFormatterBaseFactory) - BodyPartFormatterBaseFactoryPrivate *d; - friend class BodyPartFormatterBaseFactoryPrivate; + Q_DISABLE_COPY(BodyPartFormatterFactory) + BodyPartFormatterFactoryPrivate *d; + friend class BodyPartFormatterFactoryPrivate; }; } diff --git a/mimetreeparser/src/viewer/bodypartformatterbasefactory.cpp b/mimetreeparser/src/viewer/bodypartformatterfactory.cpp rename from mimetreeparser/src/viewer/bodypartformatterbasefactory.cpp rename to mimetreeparser/src/viewer/bodypartformatterfactory.cpp --- a/mimetreeparser/src/viewer/bodypartformatterbasefactory.cpp +++ b/mimetreeparser/src/viewer/bodypartformatterfactory.cpp @@ -31,32 +31,37 @@ your version. */ -#include "bodypartformatterbasefactory.h" -#include "bodypartformatterbasefactory_p.h" +#include "bodypartformatterfactory.h" +#include "bodypartformatterfactory_p.h" +#include "interfaces/bodypartformatter.h" #include "mimetreeparser_debug.h" +#include + +#include +#include #include #include #include using namespace MimeTreeParser; -BodyPartFormatterBaseFactoryPrivate::BodyPartFormatterBaseFactoryPrivate(BodyPartFormatterBaseFactory *factory) +BodyPartFormatterFactoryPrivate::BodyPartFormatterFactoryPrivate(BodyPartFormatterFactory *factory) : q(factory) { } -void BodyPartFormatterBaseFactoryPrivate::setup() +void BodyPartFormatterFactoryPrivate::setup() { if (registry.empty()) { messageviewer_create_builtin_bodypart_formatters(); q->loadPlugins(); } assert(!registry.empty()); } -void BodyPartFormatterBaseFactoryPrivate::insert(const QString &mimeType, const Interface::BodyPartFormatter *formatter, int priority) +void BodyPartFormatterFactoryPrivate::insert(const QString &mimeType, const Interface::BodyPartFormatter *formatter, int priority) { if (mimeType.isEmpty() || !formatter) { return; @@ -75,7 +80,7 @@ }); } -void BodyPartFormatterBaseFactoryPrivate::appendFormattersForType(const QString &mimeType, QVector &formatters) +void BodyPartFormatterFactoryPrivate::appendFormattersForType(const QString &mimeType, QVector &formatters) { const auto it = registry.constFind(mimeType); if (it == registry.constEnd()) { @@ -86,22 +91,28 @@ } } -BodyPartFormatterBaseFactory::BodyPartFormatterBaseFactory() - : d(new BodyPartFormatterBaseFactoryPrivate(this)) +BodyPartFormatterFactory::BodyPartFormatterFactory() + : d(new BodyPartFormatterFactoryPrivate(this)) { } -BodyPartFormatterBaseFactory::~BodyPartFormatterBaseFactory() +BodyPartFormatterFactory::~BodyPartFormatterFactory() { delete d; } -void BodyPartFormatterBaseFactory::insert(const QString &mimeType, const Interface::BodyPartFormatter *formatter, int priority) +BodyPartFormatterFactory* BodyPartFormatterFactory::instance() +{ + static BodyPartFormatterFactory s_instance; + return &s_instance; +} + +void BodyPartFormatterFactory::insert(const QString &mimeType, const Interface::BodyPartFormatter *formatter, int priority) { d->insert(mimeType.toLower(), formatter, priority); } -QVector BodyPartFormatterBaseFactory::formattersForType(const QString &mimeType) const +QVector BodyPartFormatterFactory::formattersForType(const QString &mimeType) const { QVector r; d->setup(); @@ -142,7 +153,37 @@ return r; } -void BodyPartFormatterBaseFactory::loadPlugins() +void BodyPartFormatterFactory::loadPlugins() { - qCDebug(MIMETREEPARSER_LOG) << "plugin loading is not enabled in libmimetreeparser"; + KPluginLoader::forEachPlugin(QStringLiteral("messageviewer/bodypartformatter"), [this](const QString &path) { + QPluginLoader loader(path); + const auto formatterData = loader.metaData().value(QLatin1String("MetaData")).toObject().value(QLatin1String("formatter")).toArray(); + if (formatterData.isEmpty()) { + qCWarning(MIMETREEPARSER_LOG) << "Plugin" << path << "has no meta data."; + return; + } + + auto plugin = qobject_cast(loader.instance()); + if (!plugin) { + qCWarning(MIMETREEPARSER_LOG) << "BodyPartFormatterFactory: plugin" << path + << "is not valid!"; + return; + } + + const MimeTreeParser::Interface::BodyPartFormatter *bfp = nullptr; + for (int i = 0; (bfp = plugin->bodyPartFormatter(i)) && i < formatterData.size(); ++i) { + const auto metaData = formatterData.at(i).toObject(); + const auto mimetype = metaData.value(QLatin1String("mimetype")).toString(); + if (mimetype.isEmpty()) { + qCWarning(MIMETREEPARSER_LOG) << "BodyPartFormatterFactory: plugin" << path + << "returned empty mimetype specification for index" + << i; + break; + } + // priority should always be higher than the built-in ones, otherwise what's the point? + const auto priority = metaData.value(QLatin1String("priority")).toInt() + 100; + qCDebug(MIMETREEPARSER_LOG) << "plugin for " << mimetype << priority; + insert(mimetype, bfp, priority); + } + }); } diff --git a/mimetreeparser/src/viewer/bodypartformatterbasefactory_p.h b/mimetreeparser/src/viewer/bodypartformatterfactory_p.h rename from mimetreeparser/src/viewer/bodypartformatterbasefactory_p.h rename to mimetreeparser/src/viewer/bodypartformatterfactory_p.h --- a/mimetreeparser/src/viewer/bodypartformatterbasefactory_p.h +++ b/mimetreeparser/src/viewer/bodypartformatterfactory_p.h @@ -31,27 +31,27 @@ your version. */ -#ifndef __MIMETREEPARSER_BODYPARTFORMATTERBASEFACTORY_P_H__ -#define __MIMETREEPARSER_BODYPARTFORMATTERBASEFACTORY_P_H__ +#ifndef __MIMETREEPARSER_BODYPARTFORMATTERFACTORY_P_H__ +#define __MIMETREEPARSER_BODYPARTFORMATTERFACTORY_P_H__ #include #include namespace MimeTreeParser { -class BodyPartFormatterBaseFactory; +class BodyPartFormatterFactory; -class BodyPartFormatterBaseFactoryPrivate +class BodyPartFormatterFactoryPrivate { public: - BodyPartFormatterBaseFactoryPrivate(BodyPartFormatterBaseFactory *factory); - ~BodyPartFormatterBaseFactoryPrivate() = default; + BodyPartFormatterFactoryPrivate(BodyPartFormatterFactory *factory); + ~BodyPartFormatterFactoryPrivate() = default; void setup(); void messageviewer_create_builtin_bodypart_formatters(); //defined in bodypartformatter.cpp void insert(const QString &mimeType, const Interface::BodyPartFormatter *formatter, int priority = 0); void appendFormattersForType(const QString &mimeType, QVector &formatters); - BodyPartFormatterBaseFactory *q; + BodyPartFormatterFactory *q; struct FormatterInfo { const Interface::BodyPartFormatter *formatter = nullptr; int priority = 0; diff --git a/mimetreeparser/src/viewer/objecttreeparser.cpp b/mimetreeparser/src/viewer/objecttreeparser.cpp --- a/mimetreeparser/src/viewer/objecttreeparser.cpp +++ b/mimetreeparser/src/viewer/objecttreeparser.cpp @@ -37,7 +37,7 @@ #include "objecttreeparser.h" #include "attachmentstrategy.h" -#include "bodypartformatterbasefactory.h" +#include "bodypartformatterfactory.h" #include "nodehelper.h" #include "messagepart.h" #include "partnodebodypart.h"