Members of the KDE Community are recommended to subscribe to the kde-community mailing list at https://mail.kde.org/mailman/listinfo/kde-community to allow them to participate in important discussions and receive other important announcements

Commit 69411a52 authored by Sandro Knauß's avatar Sandro Knauß

make quotedHTML ObjectTreeSource independend

Summary:
All usage of ObjectTreeSource is renderer specific.
Move it up the stack to the RendererContext.

Test Plan: run tests inside messagelib/kdepim-addonos

Reviewers: vkrause

Subscribers: #kde_pim

Tags: #kde_pim

Differential Revision: https://phabricator.kde.org/D8889
parent 806f5771
......@@ -23,6 +23,7 @@
#include <MimeTreeParser/ObjectTreeParser>
#include <MessageViewer/BufferedHtmlWriter>
#include <MessageViewer/MessagePartRendererBase>
#include <MessageViewer/CSSHelperBase>
#include <MimeTreeParser/MessagePart>
#include <MessageViewer/IconNameCache>
......@@ -33,6 +34,63 @@ using namespace MessageViewer;
QTEST_GUILESS_MAIN(QuoteHtmlTest)
class MyRenderContext : public MessageViewer::RenderContext
{
public:
virtual ~MyRenderContext() {}
CSSHelperBase *cssHelper() const override
{
return mCssHelper;
}
void renderSubParts(const MimeTreeParser::MessagePart::Ptr &msgPart, HtmlWriter *htmlWriter) override
{
Q_UNUSED(msgPart);
Q_UNUSED(htmlWriter);
}
bool isHiddenHint(const MimeTreeParser::MessagePart::Ptr &msgPart) override
{
Q_UNUSED(msgPart);
return false;
}
MimeTreeParser::IconType displayHint(const MimeTreeParser::MessagePart::Ptr &msgPart) override
{
Q_UNUSED(msgPart);
return MimeTreeParser::IconType::NoIcon;
}
bool showEmoticons() const override
{
return false;
}
bool showExpandQuotesMark() const override
{
return mShowExpandQuotesMark;
}
int levelQuote() const override
{
return mLevelQuote;
}
bool mShowExpandQuotesMark = false;
int mLevelQuote = 1;
CSSHelperBase *mCssHelper = nullptr;
protected:
bool renderWithFactory(const QMetaObject *mo, const MimeTreeParser::MessagePart::Ptr &msgPart, HtmlWriter *writer) override
{
Q_UNUSED(mo);
Q_UNUSED(msgPart);
Q_UNUSED(writer);
return false;
}
};
void QuoteHtmlTest::initTestCase()
{
MessageViewer::Test::setupEnv();
......@@ -140,9 +198,10 @@ void QuoteHtmlTest::testQuoteHtml()
QFETCH(int, quotelevel);
BufferedHtmlWriter testWriter;
Test::CSSHelper testCSSHelper;
Test::ObjectTreeSource emptySource(&testWriter, &testCSSHelper);
emptySource.setShowExpandQuotesMark(showExpandQuotesMark);
emptySource.setLevelQuote(quotelevel);
MyRenderContext context;
context.mCssHelper = &testCSSHelper;
context.mLevelQuote = quotelevel;
context.mShowExpandQuotesMark = showExpandQuotesMark;
QCOMPARE(quotedHTML(data, &emptySource, &testCSSHelper), result);
QCOMPARE(quotedHTML(data, &context, &testCSSHelper), result);
}
......@@ -1033,11 +1033,27 @@ MimeTreeParser::IconType DefaultRendererPrivate::displayHint(const MimeTreeParse
return MimeTreeParser::NoIcon;
}
bool DefaultRendererPrivate::showEmoticons() const
{
return mShowEmoticons;
}
bool DefaultRendererPrivate::showExpandQuotesMark() const
{
return mShowExpandQuotesMark;
}
bool DefaultRendererPrivate::showOnlyOneMimePart() const
{
return mShowOnlyOneMimePart;
}
int DefaultRendererPrivate::levelQuote() const
{
return mLevelQuote;
}
DefaultRenderer::DefaultRenderer(CSSHelperBase *cssHelper)
: d(new DefaultRendererPrivate(cssHelper, MessagePartRendererFactory::instance()))
{
......@@ -1058,6 +1074,21 @@ void DefaultRenderer::setAttachmentStrategy(const AttachmentStrategy *strategy)
d->mAttachmentStrategy = strategy;
}
void DefaultRenderer::setShowEmoticons(bool showEmoticons)
{
d->mShowEmoticons = showEmoticons;
}
void DefaultRenderer::setShowExpandQuotesMark(bool showExpandQuotesMark)
{
d->mShowExpandQuotesMark = showExpandQuotesMark;
}
void DefaultRenderer::setLevelQuote(int levelQuote)
{
d->mLevelQuote = levelQuote;
}
void DefaultRenderer::render(const MimeTreeParser::MessagePart::Ptr &msgPart, HtmlWriter *writer)
{
d->mMsgPart = msgPart;
......
......@@ -41,6 +41,9 @@ public:
void setShowOnlyOneMimePart(bool onlyOneMimePart);
void setAttachmentStrategy(const AttachmentStrategy *strategy);
void setShowEmoticons(bool showEmoticons);
void setShowExpandQuotesMark(bool showExpandQuotesMark);
void setLevelQuote(int levelQuote);
void render(const MimeTreeParser::MessagePartPtr &msgPart, HtmlWriter *writer);
private:
DefaultRendererPrivate *d;
......
......@@ -58,13 +58,21 @@ public:
bool isHiddenHint(const MimeTreeParser::MessagePart::Ptr &msgPart) override;
MimeTreeParser::IconType displayHint(const MimeTreeParser::MessagePart::Ptr &msgPart) override;
bool showEmoticons() const override;
bool showExpandQuotesMark() const override;
bool showOnlyOneMimePart() const override;
int levelQuote() const override;
bool mShowOnlyOneMimePart = false;
MimeTreeParser::MessagePart::Ptr mMsgPart;
CSSHelperBase *mCSSHelper = nullptr;
const MessagePartRendererFactory *mRendererFactory = nullptr;
const AttachmentStrategy *mAttachmentStrategy = nullptr;
int mLevelQuote = 1;
bool mShowEmoticons = false;
bool mShowExpandQuotesMark = false;
bool mShowOnlyOneMimePart = false;
};
}
#endif
......@@ -64,7 +64,10 @@ public:
virtual bool isHiddenHint(const MimeTreeParser::MessagePart::Ptr &msgPart) = 0;
virtual MimeTreeParser::IconType displayHint(const MimeTreeParser::MessagePart::Ptr &msgPart) = 0;
virtual bool showEmoticons() const = 0;
virtual bool showExpandQuotesMark() const = 0;
virtual bool showOnlyOneMimePart() const = 0;
virtual int levelQuote() const = 0;
protected:
virtual bool renderWithFactory(const QMetaObject *mo, const MimeTreeParser::MessagePart::Ptr &msgPart, HtmlWriter *writer) = 0;
......
......@@ -43,7 +43,7 @@ bool MessagePartRenderer::render(const MimeTreeParser::MessagePartPtr &msgPart,
htmlWriter->write(block.enter());
}
htmlWriter->write(quotedHTML(msgPart->text(), msgPart->source(), context->cssHelper()));
htmlWriter->write(quotedHTML(msgPart->text(), context, context->cssHelper()));
htmlWriter->write(block.exit());
return true;
}
......@@ -22,7 +22,7 @@
#include "utils/iconnamecache.h"
#include "viewer/csshelperbase.h"
#include <MimeTreeParser/ObjectTreeSource>
#include <MessageViewer/MessagePartRendererBase>
#include <KTextToHTML>
......@@ -106,12 +106,12 @@ bool looksLikeParaBreak(const QString &s, unsigned int newLinePos)
return prevLineLength + wordLength + 1 < WRAP_COL;
}
QString quotedHTML(const QString &s, MimeTreeParser::Interface::ObjectTreeSource *source, MessageViewer::CSSHelperBase *cssHelper)
QString quotedHTML(const QString &s, MessageViewer::RenderContext *context, MessageViewer::CSSHelperBase *cssHelper)
{
Q_ASSERT(cssHelper);
KTextToHTML::Options convertFlags = KTextToHTML::PreserveSpaces | KTextToHTML::HighlightText;
if (source->showEmoticons()) {
if (context->showEmoticons()) {
convertFlags |= KTextToHTML::ReplaceSmileys;
}
QString htmlStr;
......@@ -143,7 +143,7 @@ QString quotedHTML(const QString &s, MimeTreeParser::Interface::ObjectTreeSource
QString collapseIconPath;
QString expandIconPath;
if (source->showExpandQuotesMark()) {
if (context->showExpandQuotesMark()) {
collapseIconPath = MessageViewer::IconNameCache::instance()->iconPathFromLocal(QStringLiteral(
"quotecollapse.png"));
expandIconPath
......@@ -191,8 +191,8 @@ QString quotedHTML(const QString &s, MimeTreeParser::Interface::ObjectTreeSource
bool actHidden = false;
// This quoted line needs be hidden
if (source->showExpandQuotesMark() && source->levelQuote() >= 0
&& source->levelQuote() <= actQuoteLevel) {
if (context->showExpandQuotesMark() && context->levelQuote() >= 0
&& context->levelQuote() <= actQuoteLevel) {
actHidden = true;
}
......@@ -212,7 +212,7 @@ QString quotedHTML(const QString &s, MimeTreeParser::Interface::ObjectTreeSource
if (actQuoteLevel == -1) {
htmlStr += normalStartTag;
} else {
if (source->showExpandQuotesMark()) {
if (context->showExpandQuotesMark()) {
// Add blockquote
if (previousQuoteDepth < actQuoteLevel) {
htmlStr
......
......@@ -22,16 +22,11 @@
#include <QString>
namespace MimeTreeParser {
namespace Interface {
class ObjectTreeSource;
}
}
namespace MessageViewer {
class CSSHelperBase;
class RenderContext;
}
QString quotedHTML(const QString &s, MimeTreeParser::Interface::ObjectTreeSource *source, MessageViewer::CSSHelperBase *cssHelper);
QString quotedHTML(const QString &s, MessageViewer::RenderContext *context, MessageViewer::CSSHelperBase *cssHelper);
#endif
......@@ -148,8 +148,13 @@ void EmptySource::render(const MimeTreeParser::MessagePartPtr &msgPart, bool sho
qCWarning(MESSAGEVIEWER_LOG) << "no htmlWriter - skipping rendering.";
return;
}
auto renderer = DefaultRenderer(cssHelper());
renderer.setShowOnlyOneMimePart(showOnlyOneMimePart);
renderer.setAttachmentStrategy(attachmentStrategy());
renderer.setLevelQuote(levelQuote());
renderer.setShowEmoticons(showEmoticons());
renderer.setShowExpandQuotesMark(showExpandQuotesMark());
renderer.setShowOnlyOneMimePart(showOnlyOneMimePart);
renderer.render(msgPart, htmlWriter());
}
......@@ -42,7 +42,6 @@ public:
void setHtmlMode(MimeTreeParser::Util::HtmlMode mode, const QList<MimeTreeParser::Util::HtmlMode> &availableModes) override;
MimeTreeParser::Util::HtmlMode preferredMode() const override;
void setAllowDecryption(bool allowDecryption);
int levelQuote() const override;
const QTextCodec *overrideCodec() override;
QString createMessageHeader(KMime::Message *message) override;
virtual const AttachmentStrategy *attachmentStrategy();
......@@ -50,11 +49,13 @@ public:
virtual CSSHelperBase *cssHelper();
bool autoImportKeys() const override;
bool showEmoticons() const override;
bool showExpandQuotesMark() const override;
const MimeTreeParser::BodyPartFormatterFactory *bodyPartFormatterFactory() override;
void render(const MimeTreeParser::MessagePartPtr &msgPart, bool showOnlyOneMimePart) override;
bool isPrinting() const override;
virtual bool showEmoticons() const;
virtual bool showExpandQuotesMark() const;
virtual int levelQuote() const;
private:
EmptySourcePrivate *const d;
};
......
......@@ -31,7 +31,7 @@
using namespace MessageViewer;
MailViewerSource::MailViewerSource(ViewerPrivate *viewer)
: MimeTreeParser::Interface::ObjectTreeSource()
: MessageViewer::EmptySource()
, mViewer(viewer)
{
}
......@@ -99,6 +99,11 @@ const AttachmentStrategy *MailViewerSource::attachmentStrategy()
return mViewer->attachmentStrategy();
}
CSSHelperBase *MailViewerSource::cssHelper()
{
return mViewer->cssHelper();
}
HtmlWriter *MailViewerSource::htmlWriter()
{
return mViewer->htmlWriter();
......@@ -119,20 +124,7 @@ bool MailViewerSource::showExpandQuotesMark() const
return MessageViewer::MessageViewerSettings::self()->showExpandQuotesMark();
}
const MimeTreeParser::BodyPartFormatterFactory *MailViewerSource::bodyPartFormatterFactory()
{
return MimeTreeParser::BodyPartFormatterFactory::instance();
}
bool MailViewerSource::isPrinting() const
{
return mViewer->mPrinting;
}
void MailViewerSource::render(const MimeTreeParser::MessagePartPtr &msgPart, bool showOnlyOneMimePart)
{
auto renderer = DefaultRenderer(mViewer->cssHelper());
renderer.setShowOnlyOneMimePart(showOnlyOneMimePart);
renderer.setAttachmentStrategy(attachmentStrategy());
renderer.render(msgPart, htmlWriter());
}
......@@ -20,7 +20,7 @@
#ifndef MAILVIEWER_OBJECTTREEVIEWERSOURCE_H
#define MAILVIEWER_OBJECTTREEVIEWERSOURCE_H
#include <MimeTreeParser/ObjectTreeSource>
#include "objecttreeemptysource.h"
class QString;
......@@ -30,7 +30,7 @@ class HtmlWriter;
class ViewerPrivate;
/** An ObjectTreeParser source working on a MailViewer object */
class MailViewerSource : public MimeTreeParser::Interface::ObjectTreeSource
class MailViewerSource : public MessageViewer::EmptySource
{
public:
explicit MailViewerSource(ViewerPrivate *viewer);
......@@ -43,14 +43,13 @@ public:
int levelQuote() const override;
const QTextCodec *overrideCodec() override;
QString createMessageHeader(KMime::Message *message) override;
const AttachmentStrategy *attachmentStrategy();
virtual HtmlWriter *htmlWriter();
const AttachmentStrategy *attachmentStrategy() override;
HtmlWriter *htmlWriter() override;
CSSHelperBase *cssHelper() override;
bool autoImportKeys() const override;
bool showEmoticons() const override;
bool showExpandQuotesMark() const override;
const MimeTreeParser::BodyPartFormatterFactory *bodyPartFormatterFactory() override;
void render(const MimeTreeParser::MessagePartPtr &msgPart, bool showOnlyOneMimePart) override;
bool isPrinting() const override;
private:
ViewerPrivate *mViewer = nullptr;
......
......@@ -31,7 +31,7 @@ macro(add_mimetreeparser_crypto_unittest _source)
KF5::MimeTreeParser
Qt5::Test
KF5::Mime
Gpgmepp
QGpgme
)
add_gpg_crypto_test(${_name} mimetreeparser-${_name})
endmacro ()
......
......@@ -63,16 +63,6 @@ public:
return true;
}
bool showEmoticons() const override
{
return false;
}
bool showExpandQuotesMark() const override
{
return false;
}
const BodyPartFormatterFactory *bodyPartFormatterFactory() override
{
return &mBodyPartFormatterFactory;
......@@ -114,11 +104,6 @@ public:
mPreferredMode = mode;
}
int levelQuote() const override
{
return 1;
}
const QTextCodec *overrideCodec() override
{
return nullptr;
......
......@@ -65,8 +65,6 @@ public:
/** Return true to include the signature details in the generated html */
virtual bool showSignatureDetails() const = 0;
virtual int levelQuote() const = 0;
/** The override codec that should be used for the mail */
virtual const QTextCodec *overrideCodec() = 0;
......@@ -75,10 +73,6 @@ public:
/** should keys be imported automatically **/
virtual bool autoImportKeys() const = 0;
virtual bool showEmoticons() const = 0;
virtual bool showExpandQuotesMark() const = 0;
virtual const BodyPartFormatterFactory *bodyPartFormatterFactory() = 0;
virtual void render(const MessagePartPtr &msgPart, bool showOnlyOneMimePart) = 0;
......
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