summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSandro KnauƟ <sknauss@kde.org>2016-07-26 10:26:08 (GMT)
committerMontel Laurent <montel@kde.org>2016-07-26 11:15:55 (GMT)
commit7a390be1796480bfa5ee2d390f551527be056b65 (patch)
treeb739117f18b0b80aea16a7e2656722f0e129df9d
parentd8d0f65a88ccf524b8d2fb88fe9d5ad07409fd52 (diff)
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.
-rw-r--r--messageviewer/src/messagepartthemes/default/defaultrenderer.cpp7
-rw-r--r--mimetreeparser/src/CMakeLists.txt1
-rw-r--r--mimetreeparser/src/htmlwriter/queuehtmlwriter.cpp5
-rw-r--r--mimetreeparser/src/htmlwriter/queuehtmlwriter.h2
-rw-r--r--mimetreeparser/src/interfaces/bodypartformatter.cpp17
-rw-r--r--mimetreeparser/src/viewer/objecttreeparser.cpp8
6 files changed, 34 insertions, 6 deletions
diff --git a/messageviewer/src/messagepartthemes/default/defaultrenderer.cpp b/messageviewer/src/messagepartthemes/default/defaultrenderer.cpp
index 6156f28..4c48a5d 100644
--- a/messageviewer/src/messagepartthemes/default/defaultrenderer.cpp
+++ b/messageviewer/src/messagepartthemes/default/defaultrenderer.cpp
@@ -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);
+ }
}
}
}
diff --git a/mimetreeparser/src/CMakeLists.txt b/mimetreeparser/src/CMakeLists.txt
index df121c6..f45f559 100644
--- a/mimetreeparser/src/CMakeLists.txt
+++ b/mimetreeparser/src/CMakeLists.txt
@@ -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
diff --git a/mimetreeparser/src/htmlwriter/queuehtmlwriter.cpp b/mimetreeparser/src/htmlwriter/queuehtmlwriter.cpp
index 824657a..df53bb3 100644
--- a/mimetreeparser/src/htmlwriter/queuehtmlwriter.cpp
+++ b/mimetreeparser/src/htmlwriter/queuehtmlwriter.cpp
@@ -36,6 +36,11 @@ QueueHtmlWriter::~QueueHtmlWriter()
{
}
+void QueueHtmlWriter::setBase(HtmlWriter *base)
+{
+ mBase = base;
+}
+
void QueueHtmlWriter::begin(const QString &css)
{
Command cmd;
diff --git a/mimetreeparser/src/htmlwriter/queuehtmlwriter.h b/mimetreeparser/src/htmlwriter/queuehtmlwriter.h
index 27b083f..d3b31f9 100644
--- a/mimetreeparser/src/htmlwriter/queuehtmlwriter.h
+++ b/mimetreeparser/src/htmlwriter/queuehtmlwriter.h
@@ -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;
diff --git a/mimetreeparser/src/interfaces/bodypartformatter.cpp b/mimetreeparser/src/interfaces/bodypartformatter.cpp
index 38eb9e4..50c1057 100644
--- a/mimetreeparser/src/interfaces/bodypartformatter.cpp
+++ b/mimetreeparser/src/interfaces/bodypartformatter.cpp
@@ -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;
}
diff --git a/mimetreeparser/src/viewer/objecttreeparser.cpp b/mimetreeparser/src/viewer/objecttreeparser.cpp
index d17c508..fe6cf9d 100644
--- a/mimetreeparser/src/viewer/objecttreeparser.cpp
+++ b/mimetreeparser/src/viewer/objecttreeparser.cpp
@@ -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 {