Commit 6e112a47 authored by Sandro Knauß's avatar Sandro Knauß

Move MessagePart handling

parent f1b66506
......@@ -547,21 +547,6 @@ public:
return htmlWriter->html;
}
QString DefaultRendererPrivate::render(const MessagePart::Ptr mp)
{
auto htmlWriter = QSharedPointer<CacheHtmlWriter>(new CacheHtmlWriter(mOldWriter));
{
HTMLBlock::Ptr aBlock;
if (mp->isAttachment()) {
aBlock = HTMLBlock::Ptr(new AttachmentMarkBlock(htmlWriter.data(), mp->attachmentNode()));
}
htmlWriter->queue(quotedHTML(mp->text()));
}
return htmlWriter->html;
}
QString DefaultRendererPrivate::render(const HtmlMessagePart::Ptr &mp)
{
Grantlee::Template t = MessageViewer::MessagePartRendererManager::self()->loadByName(QStringLiteral(":/htmlmessagepart.html"));
......@@ -632,7 +617,12 @@ public:
}
c.insert(QStringLiteral("content"), _htmlWriter->html);
} else if (!metaData.inProgress) {
c.insert(QStringLiteral("content"), render(mp.dynamicCast<MessagePart>()));
auto part = renderWithFactory(QStringLiteral("MimeTreeParser::MessagePart"), mp);
if (part) {
c.insert(QStringLiteral("content"), part->html());
} else {
c.insert(QStringLiteral("content"), QStringLiteral());
}
}
c.insert(QStringLiteral("cryptoProto"), QVariant::fromValue(mp->mCryptoProto));
......@@ -678,7 +668,12 @@ public:
}
c.insert(QStringLiteral("content"), _htmlWriter->html);
} else if (!metaData.inProgress) {
c.insert(QStringLiteral("content"), render(mp.dynamicCast<MessagePart>()));
auto part = renderWithFactory(QStringLiteral("MimeTreeParser::MessagePart"), mp);
if (part) {
c.insert(QStringLiteral("content"), part->html());
} else {
c.insert(QStringLiteral("content"), QStringLiteral());
}
}
c.insert(QStringLiteral("cryptoProto"), QVariant::fromValue(cryptoProto));
......@@ -907,7 +902,10 @@ public:
if (mp->hasSubParts()) {
renderSubParts(mp, htmlWriter);
} else if (!metaData.inProgress) {
htmlWriter->queue(render(mp.dynamicCast<MessagePart>()));
auto part = renderWithFactory(QStringLiteral("MimeTreeParser::MessagePart"), mp);
if (part) {
htmlWriter->queue(part->html());
}
}
}
return htmlWriter->html;
......@@ -938,7 +936,10 @@ public:
if (mp->hasSubParts()) {
renderSubParts(mp, htmlWriter);
} else if (!metaData.inProgress) {
htmlWriter->queue(render(mp.dynamicCast<MessagePart>()));
auto part = renderWithFactory(QStringLiteral("MimeTreeParser::MessagePart"), mp);
if (part) {
htmlWriter->queue(part->html());
}
}
}
return htmlWriter->html;
......@@ -1093,11 +1094,6 @@ public:
if (mp) {
return render(mp);
}
} else if (className == QStringLiteral("MimeTreeParser::MessagePart")) {
auto mp = msgPart.dynamicCast<MessagePart>();
if (mp) {
return render(mp);
}
}
qCDebug(MESSAGEVIEWER_LOG) << "We got a unkonwn classname, using default behaviour for " << className;
......
......@@ -56,7 +56,6 @@ public:
QString render(const EncapsulatedRfc822MessagePart::Ptr &mp);
QString render(const AttachmentMessagePart::Ptr &mp);
QString render(const TextMessagePart::Ptr &mp);
QString render(const MessagePart::Ptr mp);
QString render(const HtmlMessagePart::Ptr &mp);
QString renderEncrypted(const EncryptedMessagePart::Ptr &mp);
QString renderSigned(const SignedMessagePart::Ptr &mp);
......
......@@ -114,3 +114,39 @@ QMap<QByteArray, QString> WrapperPartRendered::embededParts()
{
return mEmbeded;
}
HtmlOnlyPartRendered::HtmlOnlyPartRendered(MimeTreeParser::MessagePart::Ptr mp, const QString &html)
: mHtml(html)
{
mShowAttachmentBlock = mp->isAttachment();
mAttachmentNode = mp->attachmentNode();
}
HtmlOnlyPartRendered::~HtmlOnlyPartRendered()
{
}
QMap<QByteArray, QString> HtmlOnlyPartRendered::embededParts()
{
return QMap<QByteArray, QString>();
}
QString HtmlOnlyPartRendered::extraHeader()
{
return QString();
}
QString HtmlOnlyPartRendered::html()
{
MimeTreeParser::AttachmentMarkBlock block(nullptr, mAttachmentNode);
QString ret;
if (mShowAttachmentBlock) {
ret += block.enter();
}
ret += mHtml;
ret += block.exit();
return ret;
}
......@@ -69,4 +69,24 @@ private:
QString mHead;
QMap<QByteArray, QString> mEmbeded;
};
class HtmlOnlyPartRendered : public PartRendered
{
public:
HtmlOnlyPartRendered(MimeTreeParser::MessagePartPtr part, const QString &html);
virtual ~HtmlOnlyPartRendered();
QString html() Q_DECL_OVERRIDE;
QMap<QByteArray, QString> embededParts() Q_DECL_OVERRIDE;
QString extraHeader() Q_DECL_OVERRIDE;
protected:
void setHtml(const QString &html);
private:
QString mHtml;
bool mShowAttachmentBlock;
KMime::Content *mAttachmentNode;
};
#endif
/*
Copyright (c) 2016 Sandro Knauß <sknauss@kde.org>
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 "messagepartrenderer.h"
#include "quotehtml.h"
#include "../partrendered.h"
#include "../defaultrenderer_p.h"
MessagePartRenderer::MessagePartRenderer()
{
}
MessagePartRenderer::~MessagePartRenderer()
{
}
QSharedPointer<PartRendered> MessagePartRenderer::render(MimeTreeParser::DefaultRendererPrivate *drp, const MimeTreeParser::Interface::MessagePartPtr &msgPart) const
{
auto mp = msgPart.dynamicCast<MimeTreeParser::MessagePart>();
if (mp) {
return QSharedPointer<PartRendered>(new HtmlOnlyPartRendered(mp, quotedHTML(mp->text(), mp->source(), drp->cssHelper())));
}
return QSharedPointer<PartRendered>();
}
/*
Copyright (c) 2016 Sandro Knauß <sknauss@kde.org>
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_DEFAULTRENDERER_MESSAGEPARTRENDERER_H__
#define __MESSAGEVIEWER_DEFAULTRENDERER_MESSAGEPARTRENDERER_H__
#include "../messagepartrendererbase.h"
#include <QSharedPointer>
class MessagePartRenderer : public MessagePartRendererBase
{
public:
MessagePartRenderer();
virtual ~MessagePartRenderer();
QSharedPointer<PartRendered> render(MimeTreeParser::DefaultRendererPrivate *drp, const MimeTreeParser::Interface::MessagePartPtr &msgPart) const Q_DECL_OVERRIDE;
};
#endif
......@@ -17,10 +17,13 @@
02110-1301, USA.
*/
#include "messagepartrenderer.h"
#include "../messagepartrendererfactorybase_p.h"
using namespace MessageViewer;
void MessagePartRendererFactoryBasePrivate::initalize_builtin_renderers()
{
insert(QStringLiteral("MimeTreeParser::MessagePart"), new MessagePartRenderer());
}
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment