summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorVolker Krause <[email protected]>2017-09-30 21:16:48 +0200
committerVolker Krause <[email protected]>2017-10-03 11:09:01 +0200
commita5ff3a0c0c356252ea54be8774fd4583260d77c2 (patch)
tree1a8cc52f4df81c196b89fdc8b04f119d77d7a764
parentc5be8cab54d677093829124cd5eaaadf00981a53 (diff)
Cleanup HtmlWriter API
Summary: - merge Interface::HtmlWriter and HtmlWriter - remove queue() and flush(), which with the single synchronous buffer send to WebEngine have no meanings anymore - remove the unused CSS argument to begin() - remove TeeHtmlWriter, its debugging use has been superseded by the much more convenient direct access to the HTML source code in the mail source view This prepares the next step of making HtmlWriter conceptually a QIODevice, so we can use it directly with Grantlee's streaming API. Reviewers: knauss Reviewed By: knauss Subscribers: #kde_pim Tags: #kde_pim Differential Revision: https://phabricator.kde.org/D8083
-rw-r--r--messagecomposer/autotests/testhtmlwriter.h14
-rw-r--r--messageviewer/src/CMakeLists.txt5
-rw-r--r--messageviewer/src/htmlwriter/teehtmlwriter.cpp119
-rw-r--r--messageviewer/src/htmlwriter/teehtmlwriter.h71
-rw-r--r--messageviewer/src/htmlwriter/webengineparthtmlwriter.cpp15
-rw-r--r--messageviewer/src/htmlwriter/webengineparthtmlwriter.h4
-rw-r--r--messageviewer/src/messagepartthemes/default/autotests/rendertest.cpp14
-rw-r--r--messageviewer/src/messagepartthemes/default/autotests/util.h18
-rw-r--r--messageviewer/src/messagepartthemes/default/defaultrenderer.cpp32
-rw-r--r--messageviewer/src/messagepartthemes/default/htmlblock.cpp8
-rw-r--r--messageviewer/src/messagepartthemes/default/partrendered.cpp17
-rw-r--r--messageviewer/src/viewer/viewer_p.cpp34
-rw-r--r--mimetreeparser/autotests/util.h18
-rw-r--r--mimetreeparser/src/htmlwriter/filehtmlwriter.cpp11
-rw-r--r--mimetreeparser/src/htmlwriter/filehtmlwriter.h5
-rw-r--r--mimetreeparser/src/interfaces/htmlwriter.cpp4
-rw-r--r--mimetreeparser/src/interfaces/htmlwriter.h62
-rw-r--r--mimetreeparser/src/viewer/messagepart.cpp5
-rw-r--r--mimetreeparser/src/viewer/objecttreeparser.cpp2
19 files changed, 57 insertions, 401 deletions
diff --git a/messagecomposer/autotests/testhtmlwriter.h b/messagecomposer/autotests/testhtmlwriter.h
index a5a5932..1aaa923 100644
--- a/messagecomposer/autotests/testhtmlwriter.h
+++ b/messagecomposer/autotests/testhtmlwriter.h
@@ -36,7 +36,7 @@ public:
{
}
- void begin(const QString &) override
+ void begin() override
{
}
@@ -48,18 +48,6 @@ public:
{
}
- void reset() override
- {
- }
-
- void queue(const QString &) override
- {
- }
-
- void flush() override
- {
- }
-
void embedPart(const QByteArray &, const QString &) override
{
}
diff --git a/messageviewer/src/CMakeLists.txt b/messageviewer/src/CMakeLists.txt
index 663829b..05c5bd8 100644
--- a/messageviewer/src/CMakeLists.txt
+++ b/messageviewer/src/CMakeLists.txt
@@ -138,10 +138,6 @@ set(libmessageviewer_htmlwriter_webengine_SRCS
htmlwriter/webengineembedpart.cpp
)
-set(libmessageviewer_htmlwriter_SRCS
- htmlwriter/teehtmlwriter.cpp
- )
-
set(libmessageviewer_antispam_SRCS
antispam/spamheaderanalyzer.cpp
antispam/antispamconfig.cpp
@@ -185,7 +181,6 @@ set(libmessageviewer_SRCS
${libmessageviewer_scamdetection_SRCS}
${libmessageviewer_findbar_SRCS}
${libmessageviewer_utils_SRCS}
- ${libmessageviewer_htmlwriter_SRCS}
${libmessageviewer_antispam_SRCS}
${libmessageviewer_job_SRCS}
${libmessageviewer_viewerplugins_SRCS}
diff --git a/messageviewer/src/htmlwriter/teehtmlwriter.cpp b/messageviewer/src/htmlwriter/teehtmlwriter.cpp
deleted file mode 100644
index df2ca38..0000000
--- a/messageviewer/src/htmlwriter/teehtmlwriter.cpp
+++ /dev/null
@@ -1,119 +0,0 @@
-/* -*- c++ -*-
- teehtmlwriter.cpp
-
- This file is part of KMail, the KDE mail client.
- Copyright (c) 2003 Marc Mutz <[email protected]>
-
- KMail is free software; you can redistribute it and/or modify it
- under the terms of the GNU General Public License, version 2, as
- published by the Free Software Foundation.
-
- 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 "teehtmlwriter.h"
-
-namespace MessageViewer {
-TeeHtmlWriter::TeeHtmlWriter(HtmlWriter *writer1, MimeTreeParser::HtmlWriter *writer2)
- : MimeTreeParser::HtmlWriter()
-{
- if (writer1) {
- mWriters.append(writer1);
- }
- if (writer2) {
- mWriters.append(writer2);
- }
-}
-
-TeeHtmlWriter::~TeeHtmlWriter()
-{
- for (QList<HtmlWriter *>::Iterator it = mWriters.begin(); it != mWriters.end(); ++it) {
- delete(*it);
- }
-}
-
-void TeeHtmlWriter::addHtmlWriter(HtmlWriter *writer)
-{
- if (writer) {
- mWriters.append(writer);
- }
-}
-
-void TeeHtmlWriter::begin(const QString &css)
-{
- QList<HtmlWriter *>::const_iterator end(mWriters.constEnd());
- for (QList<HtmlWriter *>::const_iterator it = mWriters.constBegin(); it != end; ++it) {
- (*it)->begin(css);
- }
-}
-
-void TeeHtmlWriter::end()
-{
- QList<HtmlWriter *>::const_iterator end(mWriters.constEnd());
- for (QList<HtmlWriter *>::const_iterator it = mWriters.constBegin(); it != end; ++it) {
- (*it)->end();
- }
-}
-
-void TeeHtmlWriter::reset()
-{
- QList<HtmlWriter *>::const_iterator end(mWriters.constEnd());
- for (QList<HtmlWriter *>::const_iterator it = mWriters.constBegin(); it != end; ++it) {
- (*it)->reset();
- }
-}
-
-void TeeHtmlWriter::write(const QString &str)
-{
- QList<HtmlWriter *>::const_iterator end(mWriters.constEnd());
- for (QList<HtmlWriter *>::const_iterator it = mWriters.constBegin(); it != end; ++it) {
- (*it)->write(str);
- }
-}
-
-void TeeHtmlWriter::queue(const QString &str)
-{
- QList<HtmlWriter *>::const_iterator end(mWriters.constEnd());
- for (QList<HtmlWriter *>::const_iterator it = mWriters.constBegin(); it != end; ++it) {
- (*it)->queue(str);
- }
-}
-
-void TeeHtmlWriter::flush()
-{
- QList<HtmlWriter *>::const_iterator end(mWriters.constEnd());
- for (QList<HtmlWriter *>::const_iterator it = mWriters.constBegin(); it != end; ++it) {
- (*it)->flush();
- }
-}
-
-void TeeHtmlWriter::embedPart(const QByteArray &contentId, const QString &url)
-{
- QList<HtmlWriter *>::const_iterator end(mWriters.constEnd());
- for (QList<HtmlWriter *>::const_iterator it = mWriters.constBegin(); it != end; ++it) {
- (*it)->embedPart(contentId, url);
- }
-}
-
-void TeeHtmlWriter::extraHead(const QString &)
-{
-}
-} //
diff --git a/messageviewer/src/htmlwriter/teehtmlwriter.h b/messageviewer/src/htmlwriter/teehtmlwriter.h
deleted file mode 100644
index 3f25f3a..0000000
--- a/messageviewer/src/htmlwriter/teehtmlwriter.h
+++ /dev/null
@@ -1,71 +0,0 @@
-/* -*- c++ -*-
- teehtmlwriter.h
-
- This file is part of KMail, the KDE mail client.
- Copyright (c) 2003 Marc Mutz <[email protected]>
-
- KMail is free software; you can redistribute it and/or modify it
- under the terms of the GNU General Public License, version 2, as
- published by the Free Software Foundation.
-
- 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_TEEHTMLWRITER_H__
-#define __MESSAGEVIEWER_TEEHTMLWRITER_H__
-
-#include <MimeTreeParser/HtmlWriter>
-
-#include <QList>
-
-class QString;
-
-namespace MessageViewer {
-/** @short A HtmlWriter that dispatches all calls to a list of other HtmlWriters
- @author Marc Mutz <[email protected]>
- **/
-class TeeHtmlWriter : public MimeTreeParser::HtmlWriter
-{
-public:
- explicit TeeHtmlWriter(HtmlWriter *writer1 = nullptr, MimeTreeParser::HtmlWriter *writer2 = nullptr);
- virtual ~TeeHtmlWriter();
-
- void addHtmlWriter(HtmlWriter *writer);
-
- //
- // HtmlWriter Interface
- //
- void begin(const QString &cssDefs) override;
- void end() override;
- void reset() override;
- void write(const QString &str) override;
- void queue(const QString &str) override;
- void flush() override;
- void embedPart(const QByteArray &contentId, const QString &url) override;
- void extraHead(const QString &str) override;
-
-private:
- /** We own the HtmlWriters added to us! */
- QList<HtmlWriter *> mWriters;
-};
-} // namespace MessageViewer
-
-#endif // __MESSAGEVIEWER_TEEHTMLWRITER_H__
diff --git a/messageviewer/src/htmlwriter/webengineparthtmlwriter.cpp b/messageviewer/src/htmlwriter/webengineparthtmlwriter.cpp
index 1a19f78..26e18ed 100644
--- a/messageviewer/src/htmlwriter/webengineparthtmlwriter.cpp
+++ b/messageviewer/src/htmlwriter/webengineparthtmlwriter.cpp
@@ -40,10 +40,8 @@ WebEnginePartHtmlWriter::~WebEnginePartHtmlWriter()
{
}
-void WebEnginePartHtmlWriter::begin(const QString &css)
+void WebEnginePartHtmlWriter::begin()
{
- // The stylesheet is now included CSSHelper::htmlHead()
- Q_UNUSED(css);
if (mState != Ended) {
qCWarning(MESSAGEVIEWER_LOG) << "begin() called on non-ended session!";
reset();
@@ -90,17 +88,6 @@ void WebEnginePartHtmlWriter::write(const QString &str)
mHtml.append(str);
}
-void WebEnginePartHtmlWriter::queue(const QString &str)
-{
- write(str);
-}
-
-void WebEnginePartHtmlWriter::flush()
-{
- mState = Begun; // don't run into end()'s warning
- end();
-}
-
void WebEnginePartHtmlWriter::embedPart(const QByteArray &contentId, const QString &contentURL)
{
MessageViewer::WebEngineEmbedPart::self()->addEmbedPart(contentId, contentURL);
diff --git a/messageviewer/src/htmlwriter/webengineparthtmlwriter.h b/messageviewer/src/htmlwriter/webengineparthtmlwriter.h
index 382b7fa..07a8868 100644
--- a/messageviewer/src/htmlwriter/webengineparthtmlwriter.h
+++ b/messageviewer/src/htmlwriter/webengineparthtmlwriter.h
@@ -35,12 +35,10 @@ public:
explicit WebEnginePartHtmlWriter(MailWebEngineView *view, QObject *parent = nullptr);
~WebEnginePartHtmlWriter();
- void begin(const QString &cssDefs) override;
+ void begin() override;
void end() override;
void reset() override;
void write(const QString &str) override;
- void queue(const QString &str) override;
- void flush() override;
void embedPart(const QByteArray &contentId, const QString &url) override;
void extraHead(const QString &str) override;
diff --git a/messageviewer/src/messagepartthemes/default/autotests/rendertest.cpp b/messageviewer/src/messagepartthemes/default/autotests/rendertest.cpp
index b148d01..d6d8ce0 100644
--- a/messageviewer/src/messagepartthemes/default/autotests/rendertest.cpp
+++ b/messageviewer/src/messagepartthemes/default/autotests/rendertest.cpp
@@ -333,13 +333,12 @@ void RenderTest::testRender()
connect(&nodeHelper, &MimeTreeParser::NodeHelper::update, &loop, &QEventLoop::quit);
otp.setAllowAsync(bAsync);
- fileWriter.begin(QString());
- fileWriter.queue(cssHelper.htmlHead(false));
+ fileWriter.begin();
+ fileWriter.write(cssHelper.htmlHead(false));
otp.parseObjectTree(msg.data());
- fileWriter.queue(QStringLiteral("</body></html>"));
- fileWriter.flush();
+ fileWriter.write(QStringLiteral("</body></html>"));
fileWriter.end();
if (!bAsync) {
@@ -351,13 +350,12 @@ void RenderTest::testRender()
MimeTreeParser::ObjectTreeParser otp(&testSource, &nodeHelper);
otp.setAllowAsync(bAsync);
- fileWriter.begin(QString());
- fileWriter.queue(cssHelper.htmlHead(false));
+ fileWriter.begin();
+ fileWriter.write(cssHelper.htmlHead(false));
otp.parseObjectTree(msg.data());
- fileWriter.queue(QStringLiteral("</body></html>"));
- fileWriter.flush();
+ fileWriter.write(QStringLiteral("</body></html>"));
fileWriter.end();
testRenderTree(otp.parsedPart());
diff --git a/messageviewer/src/messagepartthemes/default/autotests/util.h b/messageviewer/src/messagepartthemes/default/autotests/util.h
index d5bacd4..a8f4994 100644
--- a/messageviewer/src/messagepartthemes/default/autotests/util.h
+++ b/messageviewer/src/messagepartthemes/default/autotests/util.h
@@ -38,31 +38,19 @@ public:
{
}
- void begin(const QString &) override
+ void begin() override
{
}
- void write(const QString &) override
+ void write(const QString &str) override
{
+ html += str;
}
void end() override
{
}
- void reset() override
- {
- }
-
- void queue(const QString &str) override
- {
- html.append(str);
- }
-
- void flush() override
- {
- }
-
void embedPart(const QByteArray &, const QString &) override
{
}
diff --git a/messageviewer/src/messagepartthemes/default/defaultrenderer.cpp b/messageviewer/src/messagepartthemes/default/defaultrenderer.cpp
index 7406947..277bd62 100644
--- a/messageviewer/src/messagepartthemes/default/defaultrenderer.cpp
+++ b/messageviewer/src/messagepartthemes/default/defaultrenderer.cpp
@@ -320,9 +320,9 @@ public:
{
}
- void begin(const QString &text) override
+ void begin() override
{
- mBaseWriter->begin(text);
+ mBaseWriter->begin();
}
void write(const QString &str) override
@@ -340,16 +340,6 @@ public:
mBaseWriter->reset();
}
- void queue(const QString &str) override
- {
- html.append(str);
- }
-
- void flush() override
- {
- mBaseWriter->flush();
- }
-
void embedPart(const QByteArray &contentId, const QString &url) override
{
mBaseWriter->embedPart(contentId, url);
@@ -395,7 +385,7 @@ Interface::ObjectTreeSource *DefaultRendererPrivate::source() const
void DefaultRendererPrivate::renderSubParts(const MessagePart::Ptr &msgPart, const QSharedPointer<CacheHtmlWriter> &htmlWriter)
{
foreach (const auto &m, msgPart->subParts())
- htmlWriter->queue(renderFactory(m, htmlWriter));
+ htmlWriter->write(renderFactory(m, htmlWriter));
}
QString DefaultRendererPrivate::render(const MessagePartList::Ptr &mp)
@@ -471,7 +461,7 @@ QString DefaultRendererPrivate::render(const EncapsulatedRfc822MessagePart::Ptr
= HTMLBlock::Ptr(new AttachmentMarkBlock(htmlWriter.data(), mp->attachmentContent()));
}
const auto html = t->render(&c);
- htmlWriter->queue(html);
+ htmlWriter->write(html);
}
return htmlWriter->html;
}
@@ -523,7 +513,7 @@ QString DefaultRendererPrivate::render(const HtmlMessagePart::Ptr &mp)
= HTMLBlock::Ptr(new AttachmentMarkBlock(htmlWriter.data(), mp->attachmentContent()));
}
const auto html = t->render(&c);
- htmlWriter->queue(html);
+ htmlWriter->write(html);
}
return htmlWriter->html;
}
@@ -842,7 +832,7 @@ QString DefaultRendererPrivate::render(const SignedMessagePart::Ptr &mp)
= HTMLBlock::Ptr(new AttachmentMarkBlock(htmlWriter.data(),
mp->attachmentContent()));
}
- htmlWriter->queue(renderSigned(mp));
+ htmlWriter->write(renderSigned(mp));
}
return htmlWriter->html;
}
@@ -857,7 +847,7 @@ QString DefaultRendererPrivate::render(const SignedMessagePart::Ptr &mp)
} else if (!metaData.inProgress) {
auto part = renderWithFactory(QStringLiteral("MimeTreeParser::MessagePart"), mp);
if (part) {
- htmlWriter->queue(part->html());
+ htmlWriter->write(part->html());
}
}
}
@@ -877,7 +867,7 @@ QString DefaultRendererPrivate::render(const EncryptedMessagePart::Ptr &mp)
= HTMLBlock::Ptr(new AttachmentMarkBlock(htmlWriter.data(),
mp->attachmentContent()));
}
- htmlWriter->queue(renderEncrypted(mp));
+ htmlWriter->write(renderEncrypted(mp));
}
return htmlWriter->html;
}
@@ -894,7 +884,7 @@ QString DefaultRendererPrivate::render(const EncryptedMessagePart::Ptr &mp)
} else if (!metaData.inProgress) {
auto part = renderWithFactory(QStringLiteral("MimeTreeParser::MessagePart"), mp);
if (part) {
- htmlWriter->queue(part->html());
+ htmlWriter->write(part->html());
}
}
}
@@ -925,7 +915,7 @@ QString DefaultRendererPrivate::render(const AlternativeMessagePart::Ptr &mp)
part = mp->mChildParts[mode];
}
- htmlWriter->queue(render(part));
+ htmlWriter->write(render(part));
}
return htmlWriter->html;
}
@@ -965,7 +955,7 @@ QString DefaultRendererPrivate::render(const CertMessagePart::Ptr &mp)
= HTMLBlock::Ptr(new AttachmentMarkBlock(htmlWriter.data(), mp->attachmentContent()));
}
const auto html = t->render(&c);
- htmlWriter->queue(html);
+ htmlWriter->write(html);
}
return htmlWriter->html;
}
diff --git a/messageviewer/src/messagepartthemes/default/htmlblock.cpp b/messageviewer/src/messagepartthemes/default/htmlblock.cpp
index 5c228c3..c062fc1 100644
--- a/messageviewer/src/messagepartthemes/default/htmlblock.cpp
+++ b/messageviewer/src/messagepartthemes/default/htmlblock.cpp
@@ -75,14 +75,14 @@ AttachmentMarkBlock::~AttachmentMarkBlock()
void AttachmentMarkBlock::internalEnter()
{
if (mWriter) {
- mWriter->queue(enter());
+ mWriter->write(enter());
}
}
void AttachmentMarkBlock::internalExit()
{
if (mWriter) {
- mWriter->queue(exit());
+ mWriter->write(exit());
}
}
@@ -113,14 +113,14 @@ RootBlock::~RootBlock()
void RootBlock::internalEnter()
{
if (mWriter) {
- mWriter->queue(enter());
+ mWriter->write(enter());
}
}
void RootBlock::internalExit()
{
if (mWriter) {
- mWriter->queue(exit());
+ mWriter->write(exit());
}
}
diff --git a/messageviewer/src/messagepartthemes/default/partrendered.cpp b/messageviewer/src/messagepartthemes/default/partrendered.cpp
index 1075e47..d90a6dd 100644
--- a/messageviewer/src/messagepartthemes/default/partrendered.cpp
+++ b/messageviewer/src/messagepartthemes/default/partrendered.cpp
@@ -48,7 +48,7 @@ public:
{
}
- void begin(const QString &text) override
+ void begin() override
{
}
@@ -61,19 +61,6 @@ public:
{
}
- void reset() override
- {
- }
-
- void queue(const QString &str) override
- {
- html.append(str);
- }
-
- void flush() override
- {
- }
-
void embedPart(const QByteArray &contentId, const QString &url) override
{
embedParts.insert(contentId, url);
@@ -109,7 +96,7 @@ QVector<QSharedPointer<PartRendered> > PartRendered::renderSubParts(
foreach (const auto &_m, mp->subParts()) {
CacheHtmlWriter cacheWriter;
DefaultRenderer::Ptr renderer = mp->source()->messagePartTheme(_m);
- cacheWriter.queue(renderer->html());
+ cacheWriter.write(renderer->html());
ret.append(QSharedPointer<WrapperPartRendered>(new WrapperPartRendered(&cacheWriter)));
}
return ret;
diff --git a/messageviewer/src/viewer/viewer_p.cpp b/messageviewer/src/viewer/viewer_p.cpp
index 1148675..9dd8470 100644
--- a/messageviewer/src/viewer/viewer_p.cpp
+++ b/messageviewer/src/viewer/viewer_p.cpp
@@ -19,7 +19,6 @@
with this program; if not, write to the Free Software Foundation, Inc.,
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
-//#define MESSAGEVIEWER_READER_HTML_DEBUG 1
#include "viewer_p.h"
#include "viewer.h"
@@ -45,10 +44,6 @@
#include "viewerplugins/viewerplugintoolmanager.h"
#include <KContacts/VCardConverter>
#include "htmlwriter/webengineembedpart.h"
-#ifdef MESSAGEVIEWER_READER_HTML_DEBUG
-#include <MimeMessagePart/FileHtmlWriter>
-#include "htmlwriter/teehtmlwriter.h"
-#endif
#include <PimCommon/NetworkUtil>
#include <unistd.h> // link()
//KDE includes
@@ -905,8 +900,8 @@ void ViewerPrivate::displayMessage()
setDisplayFormatMessageOverwrite(attr->messageFormat());
}
- htmlWriter()->begin(QString());
- htmlWriter()->queue(mCSSHelper->htmlHead(mUseFixedFont));
+ htmlWriter()->begin();
+ htmlWriter()->write(mCSSHelper->htmlHead(mUseFixedFont));
if (!mMainWindow) {
q->setWindowTitle(mMessage->subject()->asUnicodeString());
@@ -926,7 +921,7 @@ void ViewerPrivate::displayMessage()
mBackgroundError = scheme.background(KColorScheme::NegativeBackground).color();
}
- htmlWriter()->queue(QStringLiteral(
+ htmlWriter()->write(QStringLiteral(
"<div style=\"background:%1;color:%2;border:1px solid %3\">%4</div>").arg(
mBackgroundError.
name(),
@@ -936,7 +931,7 @@ void ViewerPrivate::displayMessage()
mForegroundError
.
name(), attr->message().toHtmlEscaped()));
- htmlWriter()->queue(QStringLiteral("<p></p>"));
+ htmlWriter()->write(QStringLiteral("<p></p>"));
}
parseContent(mMessage.data());
@@ -945,7 +940,7 @@ void ViewerPrivate::displayMessage()
#endif
mColorBar->update();
- htmlWriter()->queue(QStringLiteral("</body></html>"));
+ htmlWriter()->write(QStringLiteral("</body></html>"));
connect(mViewer, &MailWebEngineView::loadFinished, this,
&ViewerPrivate::executeCustomScriptsAfterLoading, Qt::UniqueConnection);
connect(
@@ -958,7 +953,7 @@ void ViewerPrivate::displayMessage()
"attachmentInjectionPoint"));
mViewer->addScript(js, QStringLiteral("attachment_injection"), QWebEngineScript::DocumentReady);
- htmlWriter()->flush();
+ htmlWriter()->end();
}
void ViewerPrivate::collectionFetchedForStoringDecryptedMessage(KJob *job)
@@ -1070,7 +1065,7 @@ void ViewerPrivate::parseContent(KMime::Content *content)
KMime::Message *message = dynamic_cast<KMime::Message *>(content);
if (message) {
- htmlWriter()->queue(writeMsgHeader(message, hasVCard ? vCardContent : nullptr, true));
+ htmlWriter()->write(writeMsgHeader(message, hasVCard ? vCardContent : nullptr, true));
}
// Pass control to the OTP now, which does the real work
@@ -1150,12 +1145,7 @@ void ViewerPrivate::initHtmlWidget()
{
if (!htmlWriter()) {
mPartHtmlWriter = new WebEnginePartHtmlWriter(mViewer, nullptr);
-#ifdef MESSAGEVIEWER_READER_HTML_DEBUG
- mHtmlWriter = new TeeHtmlWriter(new FileHtmlWriter(QString()),
- mPartHtmlWriter);
-#else
mHtmlWriter = mPartHtmlWriter;
-#endif
}
connect(mViewer->page(), &QWebEnginePage::linkHovered,
this, &ViewerPrivate::slotUrlOn);
@@ -1458,13 +1448,13 @@ void ViewerPrivate::setMessagePart(KMime::Content *node)
}
}
- htmlWriter()->begin(QString());
- htmlWriter()->queue(mCSSHelper->htmlHead(mUseFixedFont));
+ htmlWriter()->begin();
+ htmlWriter()->write(mCSSHelper->htmlHead(mUseFixedFont));
parseContent(node);
- htmlWriter()->queue(QStringLiteral("</body></html>"));
- htmlWriter()->flush();
+ htmlWriter()->write(QStringLiteral("</body></html>"));
+ htmlWriter()->end();
}
}
@@ -2354,7 +2344,7 @@ void ViewerPrivate::updateReaderWin()
#ifndef QT_NO_TREEVIEW
mMimePartTree->hide();
#endif
- htmlWriter()->begin(QString());
+ htmlWriter()->begin();
htmlWriter()->write(mCSSHelper->htmlHead(mUseFixedFont) + QLatin1String("</body></html>"));
htmlWriter()->end();
}
diff --git a/mimetreeparser/autotests/util.h b/mimetreeparser/autotests/util.h
index 6278507..32dee68 100644
--- a/mimetreeparser/autotests/util.h
+++ b/mimetreeparser/autotests/util.h
@@ -31,31 +31,19 @@ public:
{
}
- void begin(const QString &) override
+ void begin() override
{
}
- void write(const QString &) override
+ void write(const QString &str) override
{
+ html += str;
}
void end() override
{
}
- void reset() override
- {
- }
-
- void queue(const QString &str) override
- {
- html.append(str);
- }
-
- void flush() override
- {
- }
-
void embedPart(const QByteArray &, const QString &) override
{
}
diff --git a/mimetreeparser/src/htmlwriter/filehtmlwriter.cpp b/mimetreeparser/src/htmlwriter/filehtmlwriter.cpp
index 9b41dc7..79e6c7f 100644
--- a/mimetreeparser/src/htmlwriter/filehtmlwriter.cpp
+++ b/mimetreeparser/src/htmlwriter/filehtmlwriter.cpp
@@ -49,12 +49,9 @@ FileHtmlWriter::~FileHtmlWriter()
}
}
-void FileHtmlWriter::begin(const QString &css)
+void FileHtmlWriter::begin()
{
openOrWarn();
- if (!css.isEmpty()) {
- write(QLatin1String("<!-- CSS Definitions \n") + css + QLatin1String("-->\n"));
- }
}
void FileHtmlWriter::end()
@@ -75,12 +72,6 @@ void FileHtmlWriter::reset()
void FileHtmlWriter::write(const QString &str)
{
mStream << str;
- flush();
-}
-
-void FileHtmlWriter::queue(const QString &str)
-{
- write(str);
}
void FileHtmlWriter::flush()
diff --git a/mimetreeparser/src/htmlwriter/filehtmlwriter.h b/mimetreeparser/src/htmlwriter/filehtmlwriter.h
index 9a4dce4..cde0567 100644
--- a/mimetreeparser/src/htmlwriter/filehtmlwriter.h
+++ b/mimetreeparser/src/htmlwriter/filehtmlwriter.h
@@ -47,15 +47,14 @@ public:
explicit FileHtmlWriter(const QString &filename);
virtual ~FileHtmlWriter();
- void begin(const QString &cssDefs) override;
+ void begin() override;
void end() override;
void reset() override;
void write(const QString &str) override;
- void queue(const QString &str) override;
- void flush() override;
void embedPart(const QByteArray &contentId, const QString &url) override;
void extraHead(const QString &str) override;
private:
+ void flush();
void openOrWarn();
private:
diff --git a/mimetreeparser/src/interfaces/htmlwriter.cpp b/mimetreeparser/src/interfaces/htmlwriter.cpp
index 9f8359a..2a17792 100644
--- a/mimetreeparser/src/interfaces/htmlwriter.cpp
+++ b/mimetreeparser/src/interfaces/htmlwriter.cpp
@@ -30,10 +30,10 @@
#include "htmlwriter.h"
-MimeTreeParser::Interface::HtmlWriter::~HtmlWriter()
+MimeTreeParser::HtmlWriter::~HtmlWriter()
{
}
-MimeTreeParser::HtmlWriter::~HtmlWriter()
+void MimeTreeParser::HtmlWriter::reset()
{
}
diff --git a/mimetreeparser/src/interfaces/htmlwriter.h b/mimetreeparser/src/interfaces/htmlwriter.h
index ab3f56d..767e7aa 100644
--- a/mimetreeparser/src/interfaces/htmlwriter.h
+++ b/mimetreeparser/src/interfaces/htmlwriter.h
@@ -44,72 +44,22 @@ namespace MimeTreeParser {
* @author Marc Mutz <[email protected]>
*
*/
-namespace Interface {
class MIMETREEPARSER_EXPORT HtmlWriter
{
public:
virtual ~HtmlWriter();
/** Signal the begin of stuff to write, and give the CSS definitions */
- virtual void begin(const QString &cssDefinitions) = 0;
+ virtual void begin() = 0;
/** Write out a chunk of text. No HTML escaping is performed. */
virtual void write(const QString &html) = 0;
/** Signal the end of stuff to write. */
virtual void end() = 0;
-};
-}
-
-/**
- * @short An interface to HTML sinks
- * @author Marc Mutz <[email protected]>
- *
- * @deprecated KMail should be ported to Interface::HtmlWriter. This
- * interface exposes internal working models. The queuing
- * vs. writing() issues exposed here should be hidden by using two
- * different implementations of KHTMLPartHtmlWriter: one for
- * queuing, and one for writing. This should be fixed before the
- * release, so we an keep the plugin interface stable.
- *
- * Operate this interface in one and only one of the following two
- * modes:
- *
- * @section Sync Mode
- *
- * In sync mode, use #begin() to initiate a session, then
- * #write() some chunks of HTML code and finally #end() the session.
- *
- * @section Async Mode
- *
- * In async mode, use #begin() to initialize a session, then
- * #queue() some chunks of HTML code and finally end the
- * session by calling #flush().
- *
- * Queued HTML code is fed to the html sink using a timer. For this
- * to work, control must return to the event loop so timer events
- * are delivered.
- *
- * @section Combined mode
- *
- * You may combine the two modes in the following way only. Any
- * number of #write() calls can precede #queue() calls,
- * but once a chunk has been queued, you @em must @em not
- * #write() more data, only #queue() it.
- *
- * Naturally, whenever you queued data in a given session, that
- * session must be ended by calling #flush(), not #end().
- */
-class MIMETREEPARSER_EXPORT HtmlWriter : public Interface::HtmlWriter
-{
-public:
- virtual ~HtmlWriter();
-
- /** Stop all possibly pending processing in order to be able to
- * call #begin() again. */
- virtual void reset() = 0;
-
- virtual void queue(const QString &str) = 0;
- /** (Start) flushing internal buffers, if any. */
- virtual void flush() = 0;
+ /**
+ * Stop all possibly pending processing in order to be able to
+ * call #begin() again.
+ */
+ virtual void reset();
/**
* Embed a part with Content-ID @p contentId, using url @p url.
diff --git a/mimetreeparser/src/viewer/messagepart.cpp b/mimetreeparser/src/viewer/messagepart.cpp
index e70b17c..1de2407 100644
--- a/mimetreeparser/src/viewer/messagepart.cpp
+++ b/mimetreeparser/src/viewer/messagepart.cpp
@@ -208,14 +208,11 @@ bool MessagePart::hasSubParts() const
class LegacyHtmlWriter : public HtmlWriter
{
public:
- void begin(const QString&) override {}
+ void begin() override {}
void end() override {}
void extraHead(const QString&) override {}
void embedPart(const QByteArray&, const QString&) override {}
- void flush() override {}
- void queue(const QString &str) override { text += str; }
void write(const QString &html) override { text += html; }
- void reset() override {}
QString text;
};
diff --git a/mimetreeparser/src/viewer/objecttreeparser.cpp b/mimetreeparser/src/viewer/objecttreeparser.cpp
index 3ebfb23..b873f61 100644
--- a/mimetreeparser/src/viewer/objecttreeparser.cpp
+++ b/mimetreeparser/src/viewer/objecttreeparser.cpp
@@ -186,7 +186,7 @@ void ObjectTreeParser::parseObjectTree(KMime::Content *node)
if (htmlWriter()) {
const auto renderer = mSource->messagePartTheme(mParsedPart);
if (renderer) {
- htmlWriter()->queue(renderer->html());
+ htmlWriter()->write(renderer->html());
}
}
}