Messagelib

textmessagepartrenderer.cpp
1 /*
2  SPDX-FileCopyrightText: 2016 Sandro KnauƟ <[email protected]>
3 
4  SPDX-License-Identifier: LGPL-2.0-or-later
5 */
6 
7 #include "textmessagepartrenderer.h"
8 
9 #include "../messagepartrenderermanager.h"
10 
11 #include "interfaces/htmlwriter.h"
12 #include <MessageCore/StringUtil>
13 #if QT_VERSION < QT_VERSION_CHECK(6, 0, 0)
14 #include <grantlee/context.h>
15 #include <grantlee/template.h>
16 #else
17 #include <KTextTemplate/Context>
18 #include <KTextTemplate/Template>
19 #endif
20 
21 using namespace MessageViewer;
22 
23 TextMessagePartRenderer::TextMessagePartRenderer() = default;
24 
25 TextMessagePartRenderer::~TextMessagePartRenderer() = default;
26 
27 bool TextMessagePartRenderer::render(const MimeTreeParser::MessagePartPtr &msgPart, HtmlWriter *htmlWriter, RenderContext *context) const
28 {
29  Q_UNUSED(context)
30  auto mp = msgPart.dynamicCast<MimeTreeParser::TextMessagePart>();
31  if (!mp) {
32  return false;
33  }
34 
35  if (context->isHiddenHint(msgPart)) {
36  return true;
37  }
38 
39  if (context->displayHint(msgPart) != MimeTreeParser::NoIcon) {
40  return context->renderWithFactory<MimeTreeParser::AttachmentMessagePart>(mp, htmlWriter);
41  }
42 #if QT_VERSION < QT_VERSION_CHECK(6, 0, 0)
43  Grantlee::Template t;
44  Grantlee::Context c = MessagePartRendererManager::self()->createContext();
45 #else
47  KTextTemplate::Context c = MessagePartRendererManager::self()->createContext();
48 #endif
49  c.insert(QStringLiteral("block"), msgPart.data());
50  c.insert(QStringLiteral("showOnlyOneMimePart"), context->showOnlyOneMimePart());
51 #if QT_VERSION < QT_VERSION_CHECK(6, 0, 0)
52  c.insert(QStringLiteral("content"), QVariant::fromValue<GrantleeCallback>([mp, htmlWriter, context](Grantlee::OutputStream *) {
53  context->renderSubParts(mp, htmlWriter);
54  }));
55 #else
56  c.insert(QStringLiteral("content"), QVariant::fromValue<GrantleeCallback>([mp, htmlWriter, context](KTextTemplate::OutputStream *) {
57  context->renderSubParts(mp, htmlWriter);
58  }));
59 #endif
60 
61  t = MessagePartRendererManager::self()->loadByName(QStringLiteral("textmessagepart.html"));
62 #if QT_VERSION < QT_VERSION_CHECK(6, 0, 0)
63  Grantlee::OutputStream s(htmlWriter->stream());
64 #else
65  KTextTemplate::OutputStream s(htmlWriter->stream());
66 #endif
67  t->render(&s, &c);
68  return true;
69 }
void insert(const QString &name, const QVariant &variant)
T * data() const const
An interface for HTML sinks.
Definition: htmlwriter.h:28
QString render(Context *c) const
QTextStream * stream() const
Returns a QTextStream on device().
Definition: htmlwriter.cpp:53
QSharedPointer< X > dynamicCast() const const
This file is part of the KDE documentation.
Documentation copyright © 1996-2023 The KDE developers.
Generated on Fri Mar 24 2023 04:08:32 by doxygen 1.8.17 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.