Messagelib

attachmentmessagepartrenderer.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 "attachmentmessagepartrenderer.h"
8
9#include "../messagepartrenderermanager.h"
10#include "utils/mimetype.h"
11
12#include "interfaces/htmlwriter.h"
13#include <MessageCore/StringUtil>
14
15#include <KIconLoader>
16#include <QUrl>
17
18using namespace MessageViewer;
19
20AttachmentMessagePartRenderer::AttachmentMessagePartRenderer() = default;
21
22AttachmentMessagePartRenderer::~AttachmentMessagePartRenderer() = default;
23
24bool AttachmentMessagePartRenderer::render(const MimeTreeParser::MessagePartPtr &msgPart, HtmlWriter *htmlWriter, RenderContext *context) const
25{
27 if (!mp) {
28 return false;
29 }
30
31 KMime::Content *node = mp->content();
32 if (context->isHiddenHint(msgPart)) {
33 return true;
34 }
35
36 const auto tmpAsIcon = context->displayHint(msgPart);
37
38 if (tmpAsIcon == MimeTreeParser::NoIcon) {
39 return context->renderWithFactory<MimeTreeParser::TextMessagePart>(mp, htmlWriter);
40 }
41
42 KTextTemplate::Template t = MessageViewer::MessagePartRendererManager::self()->loadByName(QStringLiteral("asiconpart.html"));
43 KTextTemplate::Context c = MessageViewer::MessagePartRendererManager::self()->createContext();
44 c.insert(QStringLiteral("block"), msgPart.data());
45
46 msgPart->setProperty("inline", (tmpAsIcon == MimeTreeParser::IconInline));
47
48 QString iconPath;
49 if (tmpAsIcon == MimeTreeParser::IconInline) {
50 iconPath = QUrl::fromLocalFile(mp->temporaryFilePath()).toString();
51 } else {
52 iconPath = MessageViewer::Util::iconPathForContent(node, KIconLoader::Desktop);
53 if (iconPath.right(14) == QLatin1StringView("mime_empty.png")) {
55 iconPath = MessageViewer::Util::iconPathForContent(node, KIconLoader::Desktop);
56 }
57 }
58 msgPart->setProperty("iconPath", iconPath);
59 KTextTemplate::OutputStream s(htmlWriter->stream());
60 t->render(&s, &c);
61 return true;
62}
Content * content(const ContentIndex &index) const
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().
static void magicSetType(KMime::Content *node, bool autoDecode=true)
Set the 'Content-Type' by mime-magic from the contents of the body.
T * data() const const
QSharedPointer< X > dynamicCast() const const
QString right(qsizetype n) const const
QUrl fromLocalFile(const QString &localFile)
QString toString(FormattingOptions options) const const
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Mon Nov 4 2024 16:33:26 by doxygen 1.12.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.