Commit 7a390be1 authored by Sandro Knauß's avatar Sandro Knauß 🐝 Committed by Laurent Montel
Browse files

Do not render parts that are rendered by plugins several times.

The plugins are still not aware of the new API so we need to use the
QueueHtmlWriter.
parent d8d0f65a
......@@ -29,6 +29,7 @@
#include "messagepartrenderermanager.h"
#include <MimeTreeParser/HtmlWriter>
#include <MimeTreeParser/QueueHtmlWriter>
#include <MimeTreeParser/MessagePart>
#include <MimeTreeParser/ObjectTreeParser>
#include <GrantleeTheme/QtResourceTemplateLoader>
......@@ -469,6 +470,12 @@ public:
const auto m = _m.dynamicCast<MessagePart>();
if (m) {
htmlWriter->queue(renderFactory(m, htmlWriter));
} else {
auto hw = dynamic_cast<MimeTreeParser::QueueHtmlWriter *>(_m->htmlWriter());
if (hw) {
hw->setBase(htmlWriter.data());
_m->html(false);
}
}
}
}
......
......@@ -88,6 +88,7 @@ ecm_generate_headers(MimeTreeParser_Camelcaseinterfaces_HEADERS
ecm_generate_headers(MimeTreeParser_Camelcasehtmlwriter_HEADERS
HEADER_NAMES
FileHtmlWriter
QueueHtmlWriter
REQUIRED_HEADERS MimeTreeParser_htmlwriter_HEADERS
PREFIX MimeTreeParser
RELATIVE htmlwriter
......
......@@ -36,6 +36,11 @@ QueueHtmlWriter::~QueueHtmlWriter()
{
}
void QueueHtmlWriter::setBase(HtmlWriter *base)
{
mBase = base;
}
void QueueHtmlWriter::begin(const QString &css)
{
Command cmd;
......
......@@ -53,6 +53,8 @@ public:
explicit QueueHtmlWriter(MimeTreeParser::HtmlWriter *base);
virtual ~QueueHtmlWriter();
void setBase(HtmlWriter *base);
void begin(const QString &cssDefs) Q_DECL_OVERRIDE;
void end() Q_DECL_OVERRIDE;
void reset() Q_DECL_OVERRIDE;
......
......@@ -52,10 +52,18 @@ public:
: mHtmlWriter(Q_NULLPTR)
, mPart(part)
, mParentPart(Q_NULLPTR)
, mCreatedWriter(false)
, q(mp)
{
}
~MessagePartPrivate()
{
if (mCreatedWriter) {
delete mHtmlWriter;
}
}
MimeTreeParser::HtmlWriter *htmlWriter()
{
if (!mHtmlWriter && mPart) {
......@@ -67,6 +75,7 @@ public:
MimeTreeParser::HtmlWriter *mHtmlWriter;
const BodyPart *mPart;
MessagePart *mParentPart;
bool mCreatedWriter;
private:
MessagePart *q;
......@@ -137,9 +146,7 @@ void MessagePart::setHtmlWriter(MimeTreeParser::HtmlWriter *htmlWriter) const
MessagePart::Ptr BodyPartFormatter::process(BodyPart &part) const
{
auto mp = MessagePart::Ptr(new MessagePart(part));
const auto ret = format(&part, mp->htmlWriter());
if (ret != Failed) {
return mp;
}
return MessagePart::Ptr();
mp->setHtmlWriter(new QueueHtmlWriter(mp->htmlWriter()));
mp->d->mCreatedWriter = true;
return mp;
}
......@@ -246,7 +246,7 @@ bool ObjectTreeParser::processType(KMime::Content *node, ProcessResult &processR
break;
} else if (dynamic_cast<MimeTreeParser::Interface::MessagePart *>(result.data())) {
QObject *asyncResultObserver = allowAsync() ? mSource->sourceObject() : Q_NULLPTR;
const auto r = formatter->format(&part, htmlWriter(), asyncResultObserver);
const auto r = formatter->format(&part, result->htmlWriter(), asyncResultObserver);
if (r == Interface::BodyPartFormatter::AsIcon) {
processResult.setNeverDisplayInline(true);
formatter->adaptProcessResult(processResult);
......@@ -260,6 +260,12 @@ bool ObjectTreeParser::processType(KMime::Content *node, ProcessResult &processR
}
bRendered = true;
break;
} else if (r == Interface::BodyPartFormatter::Ok) {
processResult.setNeverDisplayInline(true);
formatter->adaptProcessResult(processResult);
mpRet = result;
bRendered = true;
break;
}
continue;
} else {
......
Supports Markdown
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