Messagelib

textmessagepartrenderer.cpp
1/*
2 SPDX-FileCopyrightText: 2016 Sandro Knauß <sknauss@kde.org>
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 <KTextTemplate/Context>
13#include <KTextTemplate/Template>
14#include <MessageCore/StringUtil>
15
16using namespace MessageViewer;
17
18TextMessagePartRenderer::TextMessagePartRenderer() = default;
19
20TextMessagePartRenderer::~TextMessagePartRenderer() = default;
21
22bool TextMessagePartRenderer::render(const MimeTreeParser::MessagePartPtr &msgPart, HtmlWriter *htmlWriter, RenderContext *context) const
23{
24 Q_UNUSED(context)
26 if (!mp) {
27 return false;
28 }
29
30 if (context->isHiddenHint(msgPart)) {
31 return true;
32 }
33
34 if (context->displayHint(msgPart) != MimeTreeParser::NoIcon) {
35 return context->renderWithFactory<MimeTreeParser::AttachmentMessagePart>(mp, htmlWriter);
36 }
38 KTextTemplate::Context c = MessagePartRendererManager::self()->createContext();
39 c.insert(QStringLiteral("block"), msgPart.data());
40 c.insert(QStringLiteral("showOnlyOneMimePart"), context->showOnlyOneMimePart());
41 c.insert(QStringLiteral("content"), QVariant::fromValue<KTextTemplateCallback>([mp, htmlWriter, context](KTextTemplate::OutputStream *) {
42 context->renderSubParts(mp, htmlWriter);
43 }));
44
45 t = MessagePartRendererManager::self()->loadByName(QStringLiteral("textmessagepart.html"));
46 KTextTemplate::OutputStream s(htmlWriter->stream());
47 t->render(&s, &c);
48 return true;
49}
void insert(const QString &name, const QVariant &variant)
QString render(Context *c) const
An interface for HTML sinks.
Definition htmlwriter.h:29
QTextStream * stream() const
Returns a QTextStream on device().
T * data() const const
QSharedPointer< X > dynamicCast() const const
QVariant fromValue(T &&value)
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Sat Dec 21 2024 16:59:13 by doxygen 1.12.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.