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 
16 #include <grantlee/context.h>
17 #include <grantlee/template.h>
18 
19 using namespace MessageViewer;
20 
21 TextMessagePartRenderer::TextMessagePartRenderer() = default;
22 
23 TextMessagePartRenderer::~TextMessagePartRenderer() = default;
24 
25 bool TextMessagePartRenderer::render(const MimeTreeParser::MessagePartPtr &msgPart, HtmlWriter *htmlWriter, RenderContext *context) const
26 {
27  Q_UNUSED(context)
28  auto mp = msgPart.dynamicCast<MimeTreeParser::TextMessagePart>();
29  if (!mp) {
30  return false;
31  }
32 
33  if (context->isHiddenHint(msgPart)) {
34  return true;
35  }
36 
37  const auto tmpAsIcon = context->displayHint(msgPart);
38  if (tmpAsIcon != MimeTreeParser::NoIcon) {
39  return context->renderWithFactory<MimeTreeParser::AttachmentMessagePart>(mp, htmlWriter);
40  }
41 
42  Grantlee::Template t;
43  Grantlee::Context c = MessagePartRendererManager::self()->createContext();
44  c.insert(QStringLiteral("block"), msgPart.data());
45  c.insert(QStringLiteral("showOnlyOneMimePart"), context->showOnlyOneMimePart());
46  c.insert(QStringLiteral("content"), QVariant::fromValue<GrantleeCallback>([mp, htmlWriter, context](Grantlee::OutputStream *) {
47  context->renderSubParts(mp, htmlWriter);
48  }));
49  t = MessagePartRendererManager::self()->loadByName(QStringLiteral("textmessagepart.html"));
50 
51  Grantlee::OutputStream s(htmlWriter->stream());
52  t->render(&s, &c);
53  return true;
54 }
T * data() const const
QTextStream * stream() const
Returns a QTextStream on device().
Definition: htmlwriter.cpp:53
An interface for HTML sinks.
Definition: htmlwriter.h:28
This file is part of the KDE documentation.
Documentation copyright © 1996-2021 The KDE developers.
Generated on Thu Dec 2 2021 23:06:10 by doxygen 1.8.11 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.