Commit a9960322 authored by Sandro Knauß's avatar Sandro Knauß

Move TextPartRendered handling

parent 6e112a47
......@@ -162,6 +162,7 @@ set(libmessageviewer_messagepartthemes_default_SRCS
messagepartthemes/default/partrendered.cpp
messagepartthemes/default/rendererpluginfactorysingleton.cpp
messagepartthemes/default/plugins/messagepartrenderer.cpp
messagepartthemes/default/plugins/textmessagepartrenderer.cpp
messagepartthemes/default/plugins/plugins.cpp
messagepartthemes/default/plugins/quotehtml.cpp
messagepartthemes/default/messagepartrenderbase.cpp
......
......@@ -509,44 +509,6 @@ public:
}
}
QString DefaultRendererPrivate::render(const TextMessagePart::Ptr &mp)
{
KMime::Content *node = mp->mNode;
NodeHelper *nodeHelper = mp->mOtp->nodeHelper();
if (mp->isHidden()) {
return QString();
}
Grantlee::Template t;
Grantlee::Context c = MessageViewer::MessagePartRendererManager::self()->createContext();
QObject block;
c.insert(QStringLiteral("block"), &block);
block.setProperty("showTextFrame", mp->showTextFrame());
block.setProperty("label", MessageCore::StringUtil::quoteHtmlChars(NodeHelper::fileName(node), true));
block.setProperty("comment", MessageCore::StringUtil::quoteHtmlChars(node->contentDescription()->asUnicodeString(), true));
block.setProperty("link", nodeHelper->asHREF(node, QStringLiteral("body")));
block.setProperty("showLink", mp->showLink());
block.setProperty("dir", alignText());
t = MessageViewer::MessagePartRendererManager::self()->loadByName(QStringLiteral(":/textmessagepart.html"));
auto _htmlWriter = QSharedPointer<CacheHtmlWriter>(new CacheHtmlWriter(mOldWriter));
renderSubParts(mp, _htmlWriter);
c.insert(QStringLiteral("content"), _htmlWriter->html);
auto htmlWriter = QSharedPointer<CacheHtmlWriter>(new CacheHtmlWriter(mOldWriter));
{
HTMLBlock::Ptr aBlock;
if (mp->isAttachment()) {
aBlock = HTMLBlock::Ptr(new AttachmentMarkBlock(htmlWriter.data(), mp->attachmentNode()));
}
const auto html = t->render(&c);
htmlWriter->queue(html);
}
return htmlWriter->html;
}
QString DefaultRendererPrivate::render(const HtmlMessagePart::Ptr &mp)
{
Grantlee::Template t = MessageViewer::MessagePartRendererManager::self()->loadByName(QStringLiteral(":/htmlmessagepart.html"));
......@@ -1064,11 +1026,6 @@ public:
if (mp) {
return render(mp);
}
} else if (className == QStringLiteral("MimeTreeParser::TextMessagePart")) {
auto mp = msgPart.dynamicCast<TextMessagePart>();
if (mp) {
return render(mp);
}
} else if (className == QStringLiteral("MimeTreeParser::HtmlMessagePart")) {
auto mp = msgPart.dynamicCast<HtmlMessagePart>();
if (mp) {
......
......@@ -55,7 +55,6 @@ public:
QString render(const MimeMessagePart::Ptr &mp);
QString render(const EncapsulatedRfc822MessagePart::Ptr &mp);
QString render(const AttachmentMessagePart::Ptr &mp);
QString render(const TextMessagePart::Ptr &mp);
QString render(const HtmlMessagePart::Ptr &mp);
QString renderEncrypted(const EncryptedMessagePart::Ptr &mp);
QString renderSigned(const SignedMessagePart::Ptr &mp);
......
......@@ -150,3 +150,79 @@ QString HtmlOnlyPartRendered::html()
return ret;
}
TextPartRendered::TextPartRendered(MimeTreeParser::TextMessagePart::Ptr mp)
: mShowAttachmentBlock(false)
, mAttachmentNode(nullptr)
{
auto node = mp->mNode;
auto nodeHelper = mp->mOtp->nodeHelper();
if (mp->isHidden()) {
return;
}
Grantlee::Template t;
Grantlee::Context c = MessageViewer::MessagePartRendererManager::self()->createContext();
QObject block;
c.insert(QStringLiteral("block"), &block);
block.setProperty("showTextFrame", mp->showTextFrame());
block.setProperty("label", MessageCore::StringUtil::quoteHtmlChars(MimeTreeParser::NodeHelper::fileName(node), true));
block.setProperty("comment", MessageCore::StringUtil::quoteHtmlChars(node->contentDescription()->asUnicodeString(), true));
block.setProperty("link", nodeHelper->asHREF(node, QStringLiteral("body")));
block.setProperty("showLink", mp->showLink());
block.setProperty("dir", alignText());
t = MessageViewer::MessagePartRendererManager::self()->loadByName(QStringLiteral(":/textmessagepart.html"));
mSubList = renderSubParts(mp);
QString content;
foreach(auto part, mSubList) {
content += part->html();
}
qDebug() << "content" << content;
c.insert(QStringLiteral("content"), content);
mShowAttachmentBlock = mp->isAttachment();
mHtml = t->render(&c);
mAttachmentNode = mp->attachmentNode();
}
TextPartRendered::~TextPartRendered()
{
}
QMap<QByteArray, QString> TextPartRendered::embededParts()
{
QMap<QByteArray, QString> ret;
foreach(auto part, mSubList) {
//ret += part->embededParts();
}
return ret;
}
QString TextPartRendered::extraHeader()
{
QString ret;
foreach(auto part, mSubList) {
ret += part->extraHeader();
}
return ret;
}
QString TextPartRendered::html()
{
MimeTreeParser::AttachmentMarkBlock block(nullptr, mAttachmentNode);
QString ret;
if (mShowAttachmentBlock) {
ret += block.enter();
}
ret += mHtml;
ret += block.exit();
return ret;
}
......@@ -29,6 +29,8 @@ namespace MimeTreeParser
{
class MessagePart;
typedef QSharedPointer<MessagePart> MessagePartPtr;
class TextMessagePart;
typedef QSharedPointer<TextMessagePart> TextMessagePartPtr;
class DefaultRendererPrivate;
}
......@@ -89,4 +91,21 @@ private:
KMime::Content *mAttachmentNode;
};
class TextPartRendered : public PartRendered
{
public:
TextPartRendered(MimeTreeParser::TextMessagePartPtr part);
virtual ~TextPartRendered();
QString html() Q_DECL_OVERRIDE;
QMap<QByteArray, QString> embededParts() Q_DECL_OVERRIDE;
QString extraHeader() Q_DECL_OVERRIDE;
private:
QString mHtml;
QVector<QSharedPointer<PartRendered>> mSubList;
bool mShowAttachmentBlock;
KMime::Content *mAttachmentNode;
};
#endif
......@@ -18,6 +18,7 @@
*/
#include "messagepartrenderer.h"
#include "textmessagepartrenderer.h"
#include "../messagepartrendererfactorybase_p.h"
......@@ -26,4 +27,5 @@ using namespace MessageViewer;
void MessagePartRendererFactoryBasePrivate::initalize_builtin_renderers()
{
insert(QStringLiteral("MimeTreeParser::MessagePart"), new MessagePartRenderer());
insert(QStringLiteral("MimeTreeParser::TextMessagePart"), new TextMessagePartRenderer());
}
/*
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 "textmessagepartrenderer.h"
#include "quotehtml.h"
#include "../partrendered.h"
#include "../defaultrenderer_p.h"
TextMessagePartRenderer::TextMessagePartRenderer()
{
}
TextMessagePartRenderer::~TextMessagePartRenderer()
{
}
QSharedPointer<PartRendered> TextMessagePartRenderer::render(DefaultRendererPrivate *drp, const MimeTreeParser::Interface::MessagePartPtr &msgPart) const
{
auto mp = msgPart.dynamicCast<TextMessagePart>();
if (mp) {
return QSharedPointer<PartRendered>(new TextPartRendered(mp));
}
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_TEXTMESSAGEPARTRENDERER_H__
#define __MESSAGEVIEWER_DEFAULTRENDERER_TEXTMESSAGEPARTRENDERER_H__
#include "../messagepartrendererbase.h"
#include <QSharedPointer>
class TextMessagePartRenderer : public MessagePartRendererBase
{
public:
TextMessagePartRenderer();
virtual ~TextMessagePartRenderer();
QSharedPointer<PartRendered> render(MimeTreeParser::DefaultRendererPrivate *drp, const MimeTreeParser::Interface::MessagePartPtr &msgPart) const Q_DECL_OVERRIDE;
};
#endif
......@@ -36,6 +36,8 @@
class QTextCodec;
class PartPrivate;
class TextPartRendered;
class AttachmentMessagePartRenderer;
namespace GpgME
{
......@@ -193,6 +195,8 @@ private:
bool mDecryptMessage;
bool mIsHidden;
friend class ::TextPartRendered;
friend class ::AttachmentMessagePartRenderer;
friend class DefaultRendererPrivate;
friend class ObjectTreeParser;
friend class ::PartPrivate;
......
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