Differential D8102 Diff 20290 messageviewer/src/messagepartthemes/default/plugins/attachmentmessagepartrenderer.cpp
Changeset View
Changeset View
Standalone View
Standalone View
messageviewer/src/messagepartthemes/default/plugins/attachmentmessagepartrenderer.cpp
Show All 16 Lines | 1 | /* | |||
---|---|---|---|---|---|
17 | 02110-1301, USA. | 17 | 02110-1301, USA. | ||
18 | */ | 18 | */ | ||
19 | 19 | | |||
20 | #include "attachmentmessagepartrenderer.h" | 20 | #include "attachmentmessagepartrenderer.h" | ||
21 | 21 | | |||
22 | #include "quotehtml.h" | 22 | #include "quotehtml.h" | ||
23 | 23 | | |||
24 | #include "utils/mimetype.h" | 24 | #include "utils/mimetype.h" | ||
25 | #include "../partrendered.h" | 25 | #include "../htmlblock.h" | ||
26 | #include "../defaultrenderer_p.h" | 26 | #include "../defaultrenderer_p.h" | ||
27 | #include "../messagepartrenderermanager.h" | 27 | #include "../messagepartrenderermanager.h" | ||
28 | 28 | | |||
29 | #include <MessageCore/StringUtil> | 29 | #include <MessageCore/StringUtil> | ||
30 | #include <MimeTreeParser/HtmlWriter> | ||||
30 | 31 | | |||
31 | #include <KIconLoader> | 32 | #include <KIconLoader> | ||
32 | #include <KLocalizedString> | 33 | #include <KLocalizedString> | ||
33 | #include <QUrl> | 34 | #include <QUrl> | ||
34 | 35 | | |||
35 | AttachmentMessagePartRenderer::AttachmentMessagePartRenderer() | 36 | AttachmentMessagePartRenderer::AttachmentMessagePartRenderer() | ||
36 | { | 37 | { | ||
37 | } | 38 | } | ||
38 | 39 | | |||
39 | AttachmentMessagePartRenderer::~AttachmentMessagePartRenderer() | 40 | AttachmentMessagePartRenderer::~AttachmentMessagePartRenderer() | ||
40 | { | 41 | { | ||
41 | } | 42 | } | ||
42 | 43 | | |||
43 | QSharedPointer<PartRendered> AttachmentMessagePartRenderer::render(DefaultRendererPrivate *drp, const MimeTreeParser::MessagePartPtr &msgPart) | 44 | bool AttachmentMessagePartRenderer::render(MimeTreeParser::DefaultRendererPrivate* drp, const MimeTreeParser::MessagePartPtr& msgPart, MimeTreeParser::HtmlWriter* htmlWriter) const | ||
44 | const | | |||
45 | { | 45 | { | ||
46 | auto mp = msgPart.dynamicCast<AttachmentMessagePart>(); | 46 | auto mp = msgPart.dynamicCast<AttachmentMessagePart>(); | ||
47 | if (!mp) { | 47 | if (!mp) { | ||
48 | return QSharedPointer<PartRendered>(); | 48 | return false; | ||
49 | } | 49 | } | ||
50 | 50 | | |||
51 | KMime::Content *node = mp->content(); | 51 | KMime::Content *node = mp->content(); | ||
52 | NodeHelper *nodeHelper = mp->mOtp->nodeHelper(); | 52 | NodeHelper *nodeHelper = mp->mOtp->nodeHelper(); | ||
53 | 53 | | |||
54 | if (mp->isHidden()) { | 54 | if (mp->isHidden()) { | ||
55 | return QSharedPointer<PartRendered>(new EmptyPartRendered()); | 55 | return true; | ||
56 | } | 56 | } | ||
57 | 57 | | |||
58 | const auto tmpAsIcon = mp->asIcon(); | 58 | const auto tmpAsIcon = mp->asIcon(); | ||
59 | 59 | | |||
60 | if (tmpAsIcon == MimeTreeParser::NoIcon) { | 60 | if (tmpAsIcon == MimeTreeParser::NoIcon) { | ||
61 | return drp->renderWithFactory(QStringLiteral("MimeTreeParser::TextMessagePart"), mp); | 61 | return drp->renderWithFactory(QStringLiteral("MimeTreeParser::TextMessagePart"), mp, htmlWriter); | ||
62 | } | 62 | } | ||
63 | 63 | | |||
64 | Grantlee::Template t = MessageViewer::MessagePartRendererManager::self()->loadByName(QStringLiteral( | 64 | Grantlee::Template t = MessageViewer::MessagePartRendererManager::self()->loadByName(QStringLiteral( | ||
65 | ":/asiconpart.html")); | 65 | ":/asiconpart.html")); | ||
66 | Grantlee::Context c = MessageViewer::MessagePartRendererManager::self()->createContext(); | 66 | Grantlee::Context c = MessageViewer::MessagePartRendererManager::self()->createContext(); | ||
67 | QObject block; | 67 | QObject block; | ||
68 | c.insert(QStringLiteral("block"), &block); | 68 | c.insert(QStringLiteral("block"), &block); | ||
69 | 69 | | |||
Show All 34 Lines | |||||
104 | comment = MessageCore::StringUtil::quoteHtmlChars(comment, true); | 104 | comment = MessageCore::StringUtil::quoteHtmlChars(comment, true); | ||
105 | if (label == comment) { | 105 | if (label == comment) { | ||
106 | comment.clear(); | 106 | comment.clear(); | ||
107 | } | 107 | } | ||
108 | 108 | | |||
109 | block.setProperty("label", label); | 109 | block.setProperty("label", label); | ||
110 | block.setProperty("comment", comment); | 110 | block.setProperty("comment", comment); | ||
111 | 111 | | |||
112 | const auto html = t->render(&c); | 112 | MimeTreeParser::AttachmentMarkBlock attBlock(nullptr, mp->attachmentContent()); | ||
113 | return QSharedPointer<PartRendered>(new HtmlOnlyPartRendered(mp, html)); | 113 | if (mp->isAttachment()) | ||
114 | htmlWriter->write(attBlock.enter()); | ||||
115 | | ||||
116 | Grantlee::OutputStream s(htmlWriter->stream()); | ||||
117 | t->render(&s, &c); | ||||
118 | htmlWriter->write(attBlock.exit()); | ||||
119 | | ||||
120 | return true; | ||||
114 | } | 121 | } |