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 "quotehtml.h"
10 
11 #include "../messagepartrenderermanager.h"
12 
13 #include "interfaces/htmlwriter.h"
14 #include <MessageCore/StringUtil>
15 #if QT_VERSION < QT_VERSION_CHECK(6, 0, 0)
16 #include <grantlee/context.h>
17 #include <grantlee/template.h>
18 #else
19 #include <KTextTemplate/context.h>
20 #include <KTextTemplate/template.h>
21 #endif
22 
23 using namespace MessageViewer;
24 
25 TextMessagePartRenderer::TextMessagePartRenderer() = default;
26 
27 TextMessagePartRenderer::~TextMessagePartRenderer() = default;
28 
29 bool TextMessagePartRenderer::render(const MimeTreeParser::MessagePartPtr &msgPart, HtmlWriter *htmlWriter, RenderContext *context) const
30 {
31  Q_UNUSED(context)
32  auto mp = msgPart.dynamicCast<MimeTreeParser::TextMessagePart>();
33  if (!mp) {
34  return false;
35  }
36 
37  if (context->isHiddenHint(msgPart)) {
38  return true;
39  }
40 
41  if (context->displayHint(msgPart) != MimeTreeParser::NoIcon) {
42  return context->renderWithFactory<MimeTreeParser::AttachmentMessagePart>(mp, htmlWriter);
43  }
44 #if QT_VERSION < QT_VERSION_CHECK(6, 0, 0)
45  Grantlee::Template t;
46  Grantlee::Context c = MessagePartRendererManager::self()->createContext();
47 #else
48  KTextTemplate::Template t;
49  KTextTemplate::Context c = MessagePartRendererManager::self()->createContext();
50 #endif
51  c.insert(QStringLiteral("block"), msgPart.data());
52  c.insert(QStringLiteral("showOnlyOneMimePart"), context->showOnlyOneMimePart());
53  c.insert(QStringLiteral("content"), QVariant::fromValue<GrantleeCallback>([mp, htmlWriter, context](Grantlee::OutputStream *) {
54  context->renderSubParts(mp, htmlWriter);
55  }));
56  t = MessagePartRendererManager::self()->loadByName(QStringLiteral("textmessagepart.html"));
57 #if QT_VERSION < QT_VERSION_CHECK(6, 0, 0)
58  Grantlee::OutputStream s(htmlWriter->stream());
59 #else
60  KTextTemplate::OutputStream s(htmlWriter->stream());
61 #endif
62  t->render(&s, &c);
63  return true;
64 }
T * data() const const
An interface for HTML sinks.
Definition: htmlwriter.h:28
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-2022 The KDE developers.
Generated on Thu May 19 2022 03:53:26 by doxygen 1.8.17 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.