Commit 1fb129aa authored by Volker Krause's avatar Volker Krause

Move URL handling from the processing to the rendering plugin

Summary:
As a side-effect of the now gone URL handling dependency in the BPF
factory we can now merge the BPF factory code all into MTP rather than
splitting it over two libraries.

Reviewers: knauss

Reviewed By: knauss

Subscribers: #kde_pim

Tags: #kde_pim

Differential Revision: https://phabricator.kde.org/D8175
parent b0224174
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)
......
......@@ -59,8 +59,6 @@ set(libmessageviewer_mailviewer_SRCS
)
set(libmessageviewer_viewer_SRCS
viewer/bodypartformatterfactory.cpp
viewer/bodypartformatterfactorysingleton.cpp
viewer/csshelper.cpp
viewer/csshelperbase.cpp
viewer/editorwatcher.cpp
......@@ -282,7 +280,6 @@ ecm_generate_headers(MessageViewer_Camelcaseviewer_HEADERS
ObjectTreeEmptySource
EditorWatcher
Stl_Util
BodyPartFormatterFactory
REQUIRED_HEADERS MessageViewer_viewer_HEADERS
PREFIX MessageViewer
RELATIVE viewer
......
......@@ -46,7 +46,7 @@ namespace MessageViewer {
class Viewer;
}
namespace MimeTreeParser {
namespace MessageViewer {
namespace Interface {
/**
* @short An interface to body part reader link handlers
......
......@@ -24,7 +24,7 @@
#include <gpgme++/key.h>
#include <MimeTreeParser/AttachmentStrategy>
#include <MimeTreeParser/BodyPartFormatterBaseFactory>
#include <MimeTreeParser/BodyPartFormatterFactory>
#include <MimeTreeParser/ObjectTreeSource>
#include <MessageViewer/ObjectTreeEmptySource>
......@@ -106,9 +106,9 @@ public:
return mShowExpandQuotesMark;
}
const MimeTreeParser::BodyPartFormatterBaseFactory *bodyPartFormatterFactory() override
const MimeTreeParser::BodyPartFormatterFactory *bodyPartFormatterFactory() override
{
return &mBodyPartFormatterBaseFactory;
return &mBodyPartFormatterFactory;
}
bool decryptMessage() const override
......@@ -172,7 +172,7 @@ private:
MimeTreeParser::HtmlWriter *mWriter;
MessageViewer::CSSHelperBase *mCSSHelper;
QString mAttachmentStrategy;
MimeTreeParser::BodyPartFormatterBaseFactory mBodyPartFormatterBaseFactory;
MimeTreeParser::BodyPartFormatterFactory mBodyPartFormatterFactory;
bool mHtmlLoadExternal;
bool mDecryptMessage;
bool mShowSignatureDetails;
......
......@@ -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 @@ void MessagePartRendererFactoryPrivate::loadPlugins()
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);
}
});
}
......
......@@ -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;
}
......@@ -24,7 +24,11 @@
#include <QtPlugin>
namespace MessageViewer {
namespace Interface {
class BodyPartURLHandler;
}
class MessagePartRendererBase;
/**
......@@ -35,6 +39,7 @@ class MESSAGEVIEWER_EXPORT MessagePartRenderPlugin
public:
virtual ~MessagePartRenderPlugin();
virtual MessagePartRendererBase *renderer(int index) = 0;
virtual const Interface::BodyPartURLHandler *urlHandler(int idx) const;
};
}
......
/*
bodypartformatterfactory.cpp
This file is part of KMail, the KDE mail client.
Copyright (c) 2004 Marc Mutz <mutz@kde.org>,
Ingo Kloecker <kloecker@kde.org>
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 <MimeTreeParser/BodyPartFormatter>
#include <KPluginLoader>
#include <QJsonArray>
#include <QJsonObject>
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<MimeTreeParser::Interface::BodyPartFormatterPlugin *>(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);
}
});
}
/*
bodypartformatterfactory.h
This file is part of KMail, the KDE mail client.
Copyright (c) 2004 Marc Mutz <mutz@kde.org>,
Ingo Kloecker <kloecker@kde.org>
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 <MimeTreeParser/BodyPartFormatterBaseFactory>
namespace MessageViewer {
class MESSAGEVIEWER_EXPORT BodyPartFormatterFactory : public MimeTreeParser::
BodyPartFormatterBaseFactory
{
public:
BodyPartFormatterFactory();
~BodyPartFormatterFactory();
protected:
void loadPlugins() override;
};
}
#endif // __MESSAGEVIEWER_BODYPARTFORMATTERFACTORY_H__
/*
Copyright (c) 2016 Sandro Knauß <sknauss@kde.org>
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 <QSharedPointer>
using namespace MessageViewer;
static QSharedPointer<MimeTreeParser::BodyPartFormatterBaseFactory> singleton;
const MimeTreeParser::BodyPartFormatterBaseFactory *MessageViewer::
bodyPartFormatterBaseFactoryInstance()
{
if (!singleton) {
singleton = QSharedPointer<MimeTreeParser::BodyPartFormatterBaseFactory>(
new BodyPartFormatterFactory());
}
return singleton.data();
}
/*
Copyright (c) 2016 Sandro Knauß <sknauss@kde.org>
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
......@@ -23,11 +23,10 @@
#include <MimeTreeParser/AttachmentStrategy>
#include <MimeTreeParser/BodyPartFormatter>
#include <MimeTreeParser/BodyPartFormatterFactory>
#include "messagepartthemes/default/defaultrenderer.h"
#include "bodypartformatterfactorysingleton.h"
using namespace MessageViewer;
namespace MessageViewer {
......@@ -131,9 +130,9 @@ bool EmptySource::showExpandQuotesMark() const
return false;
}
const MimeTreeParser::BodyPartFormatterBaseFactory *EmptySource::bodyPartFormatterFactory()
const MimeTreeParser::BodyPartFormatterFactory *EmptySource::bodyPartFormatterFactory()
{
return bodyPartFormatterBaseFactoryInstance();
return MimeTreeParser::BodyPartFormatterFactory::instance();
}
bool EmptySource::isPrinting() const
......
......@@ -50,7 +50,7 @@ public:
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:
......
......@@ -19,7 +19,7 @@
#include "objecttreeviewersource.h"
#include "csshelper.h"
#include "bodypartformatterfactorysingleton.h"
#include <MimeTreeParser/BodyPartFormatterFactory>
#include <MimeTreeParser/BodyPartFormatter>
#include "messagepartthemes/default/defaultrenderer.h"
......@@ -119,9 +119,9 @@ bool MailViewerSource::showExpandQuotesMark() const
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
......
......@@ -47,7 +47,7 @@ public:
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:
......
......@@ -350,22 +350,22 @@ public:
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<const MimeTreeParser::Interface::BodyPartURLHandler *> BodyPartHandlerList;
typedef QVector<const Interface::BodyPartURLHandler *> BodyPartHandlerList;
BodyPartHandlerList mHandlers;
};
URLHandlerManager::BodyPartURLHandlerManager::~BodyPartURLHandlerManager()
{
for_each(mHandlers.begin(), mHandlers.end(),
DeleteAndSetToZero<MimeTreeParser::Interface::BodyPartURLHandler>());
DeleteAndSetToZero<Interface::BodyPartURLHandler>());
}
void URLHandlerManager::BodyPartURLHandlerManager::registerHandler(
const MimeTreeParser::Interface::BodyPartURLHandler *handler)
const Interface::BodyPartURLHandler *handler)
{
if (!handler) {
return;
......@@ -375,7 +375,7 @@ void URLHandlerManager::BodyPartURLHandlerManager::registerHandler(
}
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 @@ void URLHandlerManager::unregisterHandler(const MimeTreeParser::URLHandler *hand
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);
......
......@@ -40,18 +40,16 @@ class QUrl;
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 <mutz@kde.org>
......@@ -69,8 +67,8 @@ public:
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;
......
......@@ -17,7 +17,7 @@
02110-1301, USA.
*/
#include "viewer/bodypartformatterbasefactory.h"
#include "viewer/bodypartformatterfactory.h"
#include "interfaces/bodypartformatter.h"
#include <qtest.h>
......@@ -28,7 +28,7 @@ class DummyFormatter : public Interface::BodyPartFormatter
{
};
class TestFactory : public BodyPartFormatterBaseFactory
class TestFactory : public BodyPartFormatterFactory
{
public:
void loadPlugins() override
......
......@@ -24,7 +24,7 @@
#include <gpgme++/key.h>
#include <MimeTreeParser/AttachmentStrategy>
#include <MimeTreeParser/BodyPartFormatter>
#include <MimeTreeParser/BodyPartFormatterBaseFactory>
#include <MimeTreeParser/BodyPartFormatterFactory>
#include <MimeTreeParser/MessagePart>
#include <MimeTreeParser/ObjectTreeSource>
......@@ -91,9 +91,9 @@ public:
return false;
}
const BodyPartFormatterBaseFactory *bodyPartFormatterFactory() override
const BodyPartFormatterFactory *bodyPartFormatterFactory() override
{
return &mBodyPartFormatterBaseFactory;
return &mBodyPartFormatterFactory;
}
bool decryptMessage() const override
......@@ -162,7 +162,7 @@ public:
private:
MimeTreeParser::HtmlWriter *mWriter = nullptr;
QString mAttachmentStrategy;
BodyPartFormatterBaseFactory mBodyPartFormatterBaseFactory;
BodyPartFormatterFactory mBodyPartFormatterFactory;
MimeTreeParser::Util::HtmlMode mPreferredMode;
bool mHtmlLoadExternal = false;
bool mDecryptMessage = false;
......
......@@ -27,7 +27,7 @@ set(libmimetreeparser_main_SRCS
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 @@ set(mimetreeparser_temporaryfile_SRCS
ecm_generate_headers(MimeTreeParser_Camelcaseviewer_HEADERS
HEADER_NAMES
AttachmentStrategy
BodyPartFormatterBaseFactory
BodyPartFormatterFactory
Enums
MessagePart
NodeHelper
......@@ -156,6 +156,7 @@ target_link_libraries(KF5MimeTreeParser
QGpgme
KF5::Codecs
KF5::I18n
KF5::CoreAddons
KF5::Mime
Qt5::Gui
)
......
......@@ -54,9 +54,3 @@ MimeTreeParser::MessagePart::Ptr BodyPartFormatter::process(BodyPart &part) cons
BodyPartFormatterPlugin::~BodyPartFormatterPlugin()
{
}
const BodyPartURLHandler *BodyPartFormatterPlugin::urlHandler(int idx) const
{
Q_UNUSED(idx);
return nullptr;
}
......@@ -100,7 +100,6 @@ public:
virtual ~BodyPartFormatterPlugin();
virtual const BodyPartFormatter *bodyPartFormatter(int idx) const = 0;
virtual const BodyPartURLHandler *urlHandler(int idx) const;
};
} // namespace Interface
}
......
......@@ -31,7 +31,7 @@ class QTextCodec;
namespace MimeTreeParser {
class HtmlWriter;
class AttachmentStrategy;
class BodyPartFormatterBaseFactory;
class BodyPartFormatterFactory;
class MessagePart;
typedef QSharedPointer<MessagePart> MessagePartPtr;
}
......@@ -87,7 +87,7 @@ public:
virtual bool showExpandQuotesMark() const = 0;
virtual const BodyPartFormatterBaseFactory *bodyPartFormatterFactory() = 0;
virtual const BodyPartFormatterFactory *bodyPartFormatterFactory() = 0;
virtual void render(const MessagePartPtr &msgPart, HtmlWriter *htmlWriter) = 0;
......
......@@ -45,8 +45,8 @@
#include "interfaces/bodypart.h"
#include "interfaces/htmlwriter.h"