Commit f77a5f6a authored by Sandro Knauß's avatar Sandro Knauß

Move AttachmentMessagePart handling

parent a9960322
......@@ -161,6 +161,7 @@ set(libmessageviewer_messagepartthemes_default_SRCS
messagepartthemes/default/messagepartrenderermanager.cpp
messagepartthemes/default/partrendered.cpp
messagepartthemes/default/rendererpluginfactorysingleton.cpp
messagepartthemes/default/plugins/attachmentmessagepartrenderer.cpp
messagepartthemes/default/plugins/messagepartrenderer.cpp
messagepartthemes/default/plugins/textmessagepartrenderer.cpp
messagepartthemes/default/plugins/plugins.cpp
......
......@@ -437,78 +437,6 @@ public:
return htmlWriter->html;
}
QString DefaultRendererPrivate::render(const AttachmentMessagePart::Ptr &mp)
{
KMime::Content *node = mp->mNode;
NodeHelper *nodeHelper = mp->mOtp->nodeHelper();
if (mp->isHidden()) {
return QString();
}
const auto tmpAsIcon = mp->asIcon();
Grantlee::Template t;
Grantlee::Context c = MessageViewer::MessagePartRendererManager::self()->createContext();
QObject block;
c.insert(QStringLiteral("block"), &block);
block.setProperty("showTextFrame", mp->showTextFrame());
block.setProperty("label", MessageCore::StringUtil::quoteHtmlChars(NodeHelper::fileName(node), true));
block.setProperty("comment", MessageCore::StringUtil::quoteHtmlChars(node->contentDescription()->asUnicodeString(), true));
block.setProperty("link", nodeHelper->asHREF(node, QStringLiteral("body")));
block.setProperty("showLink", mp->showLink());
block.setProperty("dir", alignText());
if (tmpAsIcon != MimeTreeParser::NoIcon) {
t = MessageViewer::MessagePartRendererManager::self()->loadByName(QStringLiteral(":/asiconpart.html"));
block.setProperty("iconSize", MessageViewer::MessagePartRendererManager::self()->iconCurrentSize());
block.setProperty("inline", (tmpAsIcon == MimeTreeParser::IconInline));
QString iconPath;
if (tmpAsIcon == MimeTreeParser::IconInline) {
iconPath = nodeHelper->writeNodeToTempFile(node);
} else {
iconPath = MessageViewer::Util::iconPathForContent(node, KIconLoader::Desktop);
if (iconPath.right(14) == QLatin1String("mime_empty.png")) {
nodeHelper->magicSetType(node);
iconPath = MessageViewer::Util::iconPathForContent(node, KIconLoader::Desktop);
}
}
block.setProperty("iconPath", QUrl::fromLocalFile(iconPath).url());
const QString name = node->contentType()->name();
QString label = name.isEmpty() ? NodeHelper::fileName(node) : name;
QString comment = node->contentDescription()->asUnicodeString();
if (label.isEmpty()) {
label = i18nc("display name for an unnamed attachment", "Unnamed");
}
label = MessageCore::StringUtil::quoteHtmlChars(label, true);
comment = MessageCore::StringUtil::quoteHtmlChars(comment, true);
if (label == comment) {
comment.clear();
}
block.setProperty("label", label);
block.setProperty("comment", comment);
auto htmlWriter = QSharedPointer<CacheHtmlWriter>(new CacheHtmlWriter(mOldWriter));
{
HTMLBlock::Ptr aBlock;
if (mp->isAttachment()) {
aBlock = HTMLBlock::Ptr(new AttachmentMarkBlock(htmlWriter.data(), mp->attachmentNode()));
}
const auto html = t->render(&c);
htmlWriter->queue(html);
}
return htmlWriter->html;
} else {
return render(mp.dynamicCast<TextMessagePart>());
}
}
QString DefaultRendererPrivate::render(const HtmlMessagePart::Ptr &mp)
{
Grantlee::Template t = MessageViewer::MessagePartRendererManager::self()->loadByName(QStringLiteral(":/htmlmessagepart.html"));
......@@ -1021,11 +949,6 @@ public:
if (mp) {
return render(mp);
}
} else if (className == QStringLiteral("MimeTreeParser::AttachmentMessagePart")) {
auto mp = msgPart.dynamicCast<AttachmentMessagePart>();
if (mp) {
return render(mp);
}
} else if (className == QStringLiteral("MimeTreeParser::HtmlMessagePart")) {
auto mp = msgPart.dynamicCast<HtmlMessagePart>();
if (mp) {
......
......@@ -54,7 +54,6 @@ public:
QString render(const MessagePartList::Ptr &mp);
QString render(const MimeMessagePart::Ptr &mp);
QString render(const EncapsulatedRfc822MessagePart::Ptr &mp);
QString render(const AttachmentMessagePart::Ptr &mp);
QString render(const HtmlMessagePart::Ptr &mp);
QString renderEncrypted(const EncryptedMessagePart::Ptr &mp);
QString renderSigned(const SignedMessagePart::Ptr &mp);
......
......@@ -88,6 +88,29 @@ QVector<QSharedPointer<PartRendered>> PartRendered::renderSubParts(MimeTreeParse
return ret;
}
EmptyPartRendered::EmptyPartRendered()
{
}
EmptyPartRendered::~EmptyPartRendered()
{
}
QString EmptyPartRendered::extraHeader()
{
return QString();
}
QString EmptyPartRendered::html()
{
return QString();
}
QMap<QByteArray, QString> EmptyPartRendered::embededParts()
{
return QMap<QByteArray, QString>();
}
WrapperPartRendered::WrapperPartRendered(CacheHtmlWriter *htmlWriter)
: PartRendered()
{
......
......@@ -55,6 +55,16 @@ public:
protected:
QVector<QSharedPointer<PartRendered>> renderSubParts(MimeTreeParser::MessagePartPtr mp);
};
class EmptyPartRendered : public PartRendered
{
public:
EmptyPartRendered();
virtual ~EmptyPartRendered();
QString html() Q_DECL_OVERRIDE;
QMap<QByteArray, QString> embededParts() Q_DECL_OVERRIDE;
QString extraHeader() Q_DECL_OVERRIDE;
};
class WrapperPartRendered : public PartRendered
{
......
/*
Copyright (c) 2016 Sandro Knauß <sknauss@kde.org>
This library is free software; you can redistribute it and/or modify it
under the terms of the GNU Library General Public License as published by
the Free Software Foundation; either version 2 of the License, or (at your
option) any later version.
This library is distributed in the hope that it will be useful, but WITHOUT
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public
License for more details.
You should have received a copy of the GNU Library General Public License
along with this library; see the file COPYING.LIB. If not, write to the
Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
02110-1301, USA.
*/
#include "attachmentmessagepartrenderer.h"
#include "quotehtml.h"
#include "utils/mimetype.h"
#include "../partrendered.h"
#include "../defaultrenderer_p.h"
#include "../messagepartrenderermanager.h"
#include <MessageCore/StringUtil>
#include <KIconLoader>
#include <KLocalizedString>
#include <QUrl>
AttachmentMessagePartRenderer::AttachmentMessagePartRenderer()
{
}
AttachmentMessagePartRenderer::~AttachmentMessagePartRenderer()
{
}
QSharedPointer<PartRendered> AttachmentMessagePartRenderer::render(DefaultRendererPrivate *drp, const MimeTreeParser::Interface::MessagePartPtr &msgPart) const
{
auto mp = msgPart.dynamicCast<AttachmentMessagePart>();
if (!mp) {
return QSharedPointer<PartRendered>();
}
KMime::Content *node = mp->mNode;
NodeHelper *nodeHelper = mp->mOtp->nodeHelper();
if (mp->isHidden()) {
return QSharedPointer<PartRendered>(new EmptyPartRendered());
}
const auto tmpAsIcon = mp->asIcon();
if (tmpAsIcon == MimeTreeParser::NoIcon) {
return drp->renderWithFactory(QStringLiteral("MimeTreeParser::TextMessagePart"), mp);
}
Grantlee::Template t = MessageViewer::MessagePartRendererManager::self()->loadByName(QStringLiteral(":/asiconpart.html"));
Grantlee::Context c = MessageViewer::MessagePartRendererManager::self()->createContext();
QObject block;
c.insert(QStringLiteral("block"), &block);
block.setProperty("showTextFrame", mp->showTextFrame());
block.setProperty("label", MessageCore::StringUtil::quoteHtmlChars(NodeHelper::fileName(node), true));
block.setProperty("comment", MessageCore::StringUtil::quoteHtmlChars(node->contentDescription()->asUnicodeString(), true));
block.setProperty("link", nodeHelper->asHREF(node, QStringLiteral("body")));
block.setProperty("showLink", mp->showLink());
block.setProperty("dir", drp->alignText());
block.setProperty("iconSize", MessageViewer::MessagePartRendererManager::self()->iconCurrentSize());
block.setProperty("inline", (tmpAsIcon == MimeTreeParser::IconInline));
QString iconPath;
if (tmpAsIcon == MimeTreeParser::IconInline) {
iconPath = nodeHelper->writeNodeToTempFile(node);
} else {
iconPath = MessageViewer::Util::iconPathForContent(node, KIconLoader::Desktop);
if (iconPath.right(14) == QLatin1String("mime_empty.png")) {
nodeHelper->magicSetType(node);
iconPath = MessageViewer::Util::iconPathForContent(node, KIconLoader::Desktop);
}
}
block.setProperty("iconPath", QUrl::fromLocalFile(iconPath).url());
const QString name = node->contentType()->name();
QString label = name.isEmpty() ? NodeHelper::fileName(node) : name;
QString comment = node->contentDescription()->asUnicodeString();
if (label.isEmpty()) {
label = i18nc("display name for an unnamed attachment", "Unnamed");
}
label = MessageCore::StringUtil::quoteHtmlChars(label, true);
comment = MessageCore::StringUtil::quoteHtmlChars(comment, true);
if (label == comment) {
comment.clear();
}
block.setProperty("label", label);
block.setProperty("comment", comment);
const auto html = t->render(&c);
return QSharedPointer<PartRendered>(new HtmlOnlyPartRendered(mp, html));
}
/*
Copyright (c) 2016 Sandro Knauß <sknauss@kde.org>
This library is free software; you can redistribute it and/or modify it
under the terms of the GNU Library General Public License as published by
the Free Software Foundation; either version 2 of the License, or (at your
option) any later version.
This library is distributed in the hope that it will be useful, but WITHOUT
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public
License for more details.
You should have received a copy of the GNU Library General Public License
along with this library; see the file COPYING.LIB. If not, write to the
Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
02110-1301, USA.
*/
#ifndef __MESSAGEVIEWER_DEFAULTRENDERER_ATTACHMENTMESSAGEPARTRENDERER_H__
#define __MESSAGEVIEWER_DEFAULTRENDERER_ATTACHMENTMESSAGEPARTRENDERER_H__
#include "../messagepartrendererbase.h"
#include <QSharedPointer>
class AttachmentMessagePartRenderer : public MessagePartRendererBase
{
public:
AttachmentMessagePartRenderer();
virtual ~AttachmentMessagePartRenderer();
QSharedPointer<PartRendered> render(MimeTreeParser::DefaultRendererPrivate *drp, const MimeTreeParser::Interface::MessagePartPtr &msgPart) const Q_DECL_OVERRIDE;
};
#endif
......@@ -17,6 +17,7 @@
02110-1301, USA.
*/
#include "attachmentmessagepartrenderer.h"
#include "messagepartrenderer.h"
#include "textmessagepartrenderer.h"
......@@ -28,4 +29,5 @@ void MessagePartRendererFactoryBasePrivate::initalize_builtin_renderers()
{
insert(QStringLiteral("MimeTreeParser::MessagePart"), new MessagePartRenderer());
insert(QStringLiteral("MimeTreeParser::TextMessagePart"), new TextMessagePartRenderer());
insert(QStringLiteral("MimeTreeParser::AttachmentMessagePart"), new AttachmentMessagePartRenderer());
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment