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 cb05198a authored by Sandro Knauß's avatar Sandro Knauß

drawFrame is a property of the renderer and not of the parser

Summary: move logic to renderer and delete from parser

Test Plan: make tests and view some sample mail in kmail

Reviewers: #kde_pim, vkrause

Tags: #kde_pim

Differential Revision: https://phabricator.kde.org/D8620
parent 24c9f573
......@@ -24,9 +24,9 @@
#include "setupenv.h"
#include "testcsshelper.h"
#include <MimeTreeParser/FileHtmlWriter>
#include <MimeTreeParser/ObjectTreeParser>
#include <MimeTreeParser/MessagePart>
#include <MessageViewer/FileHtmlWriter>
#include <QString>
#include <QTest>
......@@ -66,20 +66,20 @@ void ShowOnlyMimePartTest::testDrawFrame()
const KMime::Message::Ptr msg(Test::readAndParseMail(QStringLiteral("frametest.mbox")));
// render the mail
MimeTreeParser::FileHtmlWriter fileWriter(outFileName);
FileHtmlWriter fileWriter(outFileName);
QImage paintDevice;
Test::TestCSSHelper cssHelper(&paintDevice);
MimeTreeParser::NodeHelper nodeHelper;
Test::ObjectTreeSource testSource(&fileWriter, &cssHelper);
MimeTreeParser::ObjectTreeParser otp(&testSource, &nodeHelper, showOnlyMimePart);
MimeTreeParser::ObjectTreeParser otp(&testSource, &nodeHelper);
fileWriter.begin();
fileWriter.write(cssHelper.htmlHead(false));
QVERIFY(msg->contents().size() > content);
otp.parseObjectTree(msg->contents().at(content));
otp.parseObjectTree(msg->contents().at(content), showOnlyMimePart);
fileWriter.write(QStringLiteral("</body></html>"));
fileWriter.end();
......@@ -113,20 +113,20 @@ void ShowOnlyMimePartTest::testRelated()
const KMime::Message::Ptr msg(Test::readAndParseMail(QStringLiteral("html-multipart-related.mbox")));
// render the mail
MimeTreeParser::FileHtmlWriter fileWriter(outFileName);
FileHtmlWriter fileWriter(outFileName);
QImage paintDevice;
Test::TestCSSHelper cssHelper(&paintDevice);
MimeTreeParser::NodeHelper nodeHelper;
Test::ObjectTreeSource testSource(&fileWriter, &cssHelper);
MimeTreeParser::ObjectTreeParser otp(&testSource, &nodeHelper, showOnlyMimePart);
MimeTreeParser::ObjectTreeParser otp(&testSource, &nodeHelper);
fileWriter.begin();
fileWriter.write(cssHelper.htmlHead(false));
QVERIFY(msg->contents().size() > content);
otp.parseObjectTree(msg->contents().at(content));
otp.parseObjectTree(msg->contents().at(content), showOnlyMimePart);
fileWriter.write(QStringLiteral("</body></html>"));
fileWriter.end();
......
......@@ -1018,6 +1018,11 @@ MimeTreeParser::IconType DefaultRendererPrivate::displayHint(const MimeTreeParse
return MimeTreeParser::NoIcon;
}
bool DefaultRendererPrivate::showOnlyOneMimePart() const
{
return mShowOnlyOneMimePart;
}
DefaultRenderer::DefaultRenderer(CSSHelperBase *cssHelper)
: d(new DefaultRendererPrivate(cssHelper, MessagePartRendererFactory::instance()))
{
......
......@@ -58,6 +58,7 @@ public:
bool isHiddenHint(const MimeTreeParser::MessagePart::Ptr &msgPart) override;
MimeTreeParser::IconType displayHint(const MimeTreeParser::MessagePart::Ptr &msgPart) override;
bool showOnlyOneMimePart() const override;
bool mShowOnlyOneMimePart = false;
MimeTreeParser::MessagePart::Ptr mMsgPart;
......
......@@ -64,6 +64,7 @@ public:
virtual bool isHiddenHint(const MimeTreeParser::MessagePart::Ptr &msgPart) = 0;
virtual MimeTreeParser::IconType displayHint(const MimeTreeParser::MessagePart::Ptr &msgPart) = 0;
virtual bool showOnlyOneMimePart() const = 0;
protected:
virtual bool renderWithFactory(const QMetaObject *mo, const MimeTreeParser::MessagePart::Ptr &msgPart, HtmlWriter *writer) = 0;
......
......@@ -54,6 +54,7 @@ bool TextMessagePartRenderer::render(const MimeTreeParser::MessagePartPtr &msgPa
Grantlee::Template t;
Grantlee::Context c = MessagePartRendererManager::self()->createContext();
c.insert(QStringLiteral("block"), msgPart.data());
c.insert(QStringLiteral("showOnlyOneMimePart"), context->showOnlyOneMimePart());
c.insert(QStringLiteral("content"), QVariant::fromValue<GrantleeCallback>([mp, htmlWriter, context](Grantlee::OutputStream *) {
context->renderSubParts(mp, htmlWriter);
}));
......
......@@ -2,7 +2,7 @@
<a name="att{{block.attachmentIndex}}"></a>
<div id="attachmentDiv{{block.attachmentIndex}}">
{% endif %}
{% if block.showTextFrame %}
{% if not showOnlyOneMimePart and not block.isFirstTextPart and block.hasLabel %}
<table cellspacing="1" class="textAtm">
<tr class="textAtmH">
<td dir="{{global.dir}}">
......
......@@ -43,16 +43,11 @@ MessagePart::Ptr TextPlainBodyPartFormatter::process(Interface::BodyPart &part)
KMime::Content *node = part.content();
const bool isFirstTextPart = (node->topLevel()->textContent() == node);
QString label = NodeHelper::fileName(node);
const bool bDrawFrame = !isFirstTextPart
&& !label.isEmpty();
TextMessagePart::Ptr mp;
if (isFirstTextPart) {
mp = TextMessagePart::Ptr(new TextMessagePart(part.objectTreeParser(), node, bDrawFrame, part.source()->decryptMessage()));
mp = TextMessagePart::Ptr(new TextMessagePart(part.objectTreeParser(), node, part.source()->decryptMessage()));
} else {
mp = TextMessagePart::Ptr(new AttachmentMessagePart(part.objectTreeParser(), node, bDrawFrame, part.source()->decryptMessage()));
mp = TextMessagePart::Ptr(new AttachmentMessagePart(part.objectTreeParser(), node, part.source()->decryptMessage()));
}
part.processResult()->setInlineSignatureState(mp->signatureState());
......
......@@ -65,7 +65,7 @@ public:
MessagePart::Ptr process(Interface::BodyPart &part) const override
{
KMime::Content *node = part.content();
const auto mp = AttachmentMessagePart::Ptr(new AttachmentMessagePart(part.objectTreeParser(), node, false, part.source()->decryptMessage()));
const auto mp = AttachmentMessagePart::Ptr(new AttachmentMessagePart(part.objectTreeParser(), node, part.source()->decryptMessage()));
part.processResult()->setInlineSignatureState(mp->signatureState());
part.processResult()->setInlineEncryptionState(mp->encryptionState());
part.processResult()->setNeverDisplayInline(true);
......@@ -100,7 +100,7 @@ public:
MessagePart::Ptr process(Interface::BodyPart &part) const override
{
KMime::Content *node = part.content();
auto mp = AttachmentMessagePart::Ptr(new AttachmentMessagePart(part.objectTreeParser(), node, false, part.source()->decryptMessage()));
auto mp = AttachmentMessagePart::Ptr(new AttachmentMessagePart(part.objectTreeParser(), node, part.source()->decryptMessage()));
mp->setIsImage(true);
part.processResult()->setInlineSignatureState(mp->signatureState());
part.processResult()->setInlineEncryptionState(mp->encryptionState());
......
......@@ -268,9 +268,8 @@ QString MessagePartList::htmlContent() const
//-----TextMessageBlock----------------------
TextMessagePart::TextMessagePart(ObjectTreeParser *otp, KMime::Content *node, bool drawFrame, bool decryptMessage)
TextMessagePart::TextMessagePart(ObjectTreeParser *otp, KMime::Content *node, bool decryptMessage)
: MessagePartList(otp)
, mDrawFrame(drawFrame)
, mDecryptMessage(decryptMessage)
{
if (!node) {
......@@ -384,14 +383,14 @@ bool TextMessagePart::showLink() const
return !temporaryFilePath().isEmpty();
}
bool TextMessagePart::showTextFrame() const
bool TextMessagePart::isFirstTextPart() const
{
return mDrawFrame;
return content()->topLevel()->textContent() == content();
}
void TextMessagePart::setShowTextFrame(bool showFrame)
bool TextMessagePart::hasLabel() const
{
mDrawFrame = showFrame;
return !NodeHelper::fileName(content()).isEmpty();
}
QString TextMessagePart::label() const
......@@ -420,8 +419,8 @@ QString TextMessagePart::temporaryFilePath() const
//-----AttachmentMessageBlock----------------------
AttachmentMessagePart::AttachmentMessagePart(ObjectTreeParser *otp, KMime::Content *node, bool drawFrame, bool decryptMessage)
: TextMessagePart(otp, node, drawFrame, decryptMessage)
AttachmentMessagePart::AttachmentMessagePart(ObjectTreeParser *otp, KMime::Content *node, bool decryptMessage)
: TextMessagePart(otp, node, decryptMessage)
, mIsImage(false)
, mNeverDisplayInline(false)
{
......
......@@ -179,13 +179,14 @@ enum IconType {
class MIMETREEPARSER_EXPORT TextMessagePart : public MessagePartList
{
Q_OBJECT
Q_PROPERTY(bool showTextFrame READ showTextFrame CONSTANT)
Q_PROPERTY(bool showLink READ showLink CONSTANT)
Q_PROPERTY(bool isFirstTextPart READ isFirstTextPart CONSTANT)
Q_PROPERTY(bool hasLabel READ hasLabel CONSTANT)
Q_PROPERTY(QString label READ label CONSTANT)
Q_PROPERTY(QString comment READ comment CONSTANT)
public:
typedef QSharedPointer<TextMessagePart> Ptr;
TextMessagePart(MimeTreeParser::ObjectTreeParser *otp, KMime::Content *node, bool drawFrame, bool decryptMessage);
TextMessagePart(MimeTreeParser::ObjectTreeParser *otp, KMime::Content *node, bool decryptMessage);
virtual ~TextMessagePart();
KMMsgSignatureState signatureState() const;
......@@ -194,8 +195,8 @@ public:
bool decryptMessage() const;
bool showLink() const;
bool showTextFrame() const;
void setShowTextFrame(bool showFrame);
bool isFirstTextPart() const;
bool hasLabel() const;
/** The attachment filename, or the closest approximation thereof we have. */
QString label() const;
......@@ -209,7 +210,6 @@ private:
KMMsgSignatureState mSignatureState;
KMMsgEncryptionState mEncryptionState;
bool mDrawFrame;
bool mDecryptMessage;
friend class ObjectTreeParser;
......@@ -220,7 +220,7 @@ class MIMETREEPARSER_EXPORT AttachmentMessagePart : public TextMessagePart
Q_OBJECT
public:
typedef QSharedPointer<AttachmentMessagePart> Ptr;
AttachmentMessagePart(MimeTreeParser::ObjectTreeParser *otp, KMime::Content *node, bool drawFrame, bool decryptMessage);
AttachmentMessagePart(MimeTreeParser::ObjectTreeParser *otp, KMime::Content *node, bool decryptMessage);
virtual ~AttachmentMessagePart();
bool neverDisplayInline() const;
......
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