Commit 207a25a7 authored by Sandro Knauß's avatar Sandro Knauß
Browse files

Move writePartIcon from otp to messagepart

parent 152bf4b4
......@@ -1346,6 +1346,55 @@ void TextMessagePart::parseContent()
}
}
void TextMessagePart::writePartIcon()
{
HtmlWriter *writer = mOtp->htmlWriter();
NodeHelper *nodeHelper = mOtp->nodeHelper();
if (!writer || !mNode || mAsIcon == MimeTreeParser::NoIcon) {
return;
}
const QString name = mNode->contentType()->name();
QString label = name.isEmpty() ? NodeHelper::fileName(mNode) : name;
if (label.isEmpty()) {
label = i18nc("display name for an unnamed attachment", "Unnamed");
}
label = MessageCore::StringUtil::quoteHtmlChars(label, true);
QString comment = mNode->contentDescription()->asUnicodeString();
comment = MessageCore::StringUtil::quoteHtmlChars(comment, true);
if (label == comment) {
comment.clear();
}
QString href = nodeHelper->asHREF(mNode, QStringLiteral("body"));
if (mAsIcon == MimeTreeParser::IconInline) {
const QString fileName = nodeHelper->writeNodeToTempFile(mNode);
// show the filename of the image below the embedded image
writer->queue(QLatin1String("<hr/><div><a href=\"") + href + QLatin1String("\">"
"<img align=\"center\" src=\"") + QUrl::fromLocalFile(fileName).url() + QLatin1String("\" border=\"0\" style=\"max-width: 100%\"/></a>"
"</div>"
"<div><a href=\"") + href + QLatin1String("\">") + label + QLatin1String("</a>"
"</div>"
"<div>") + comment + QLatin1String("</div>"));
} else {
// show the filename next to the image
const QString iconName = QUrl::fromLocalFile(nodeHelper->iconName(mNode)).url();
if (iconName.right(14) == QLatin1String("mime_empty.png")) {
nodeHelper->magicSetType(mNode);
//iconName = nodeHelper->iconName( mNode );
}
const int iconSize = KIconLoader::global()->currentSize(KIconLoader::Desktop);
writer->queue(QStringLiteral("<hr/><div><a href=\"%1\">").arg(href) +
QStringLiteral("<img align=\"center\" height=\"%1\" width=\"%1\" src=\"%2\" border=\"0\" style=\"max-width: 100%\" alt=\"\"/>").arg(QString::number(iconSize), iconName) +
label + QStringLiteral("</a></div>") +
QStringLiteral("<div>%1</div>").arg(comment));
}
}
void TextMessagePart::html(bool decorate)
{
const HTMLBlock::Ptr aBlock(attachmentBlock());
......@@ -1357,7 +1406,7 @@ void TextMessagePart::html(bool decorate)
}
if (mAsIcon != MimeTreeParser::NoIcon) {
mOtp->writePartIcon(mNode, (mAsIcon == MimeTreeParser::IconInline));
writePartIcon();
} else {
MessagePartList::htmlInternal(decorate);
}
......
......@@ -311,6 +311,7 @@ public:
private:
void parseContent();
void writePartIcon();
KMime::Content *mNode;
KMMsgSignatureState mSignatureState;
KMMsgEncryptionState mEncryptionState;
......
......@@ -54,9 +54,6 @@
#include "utils/mimetype.h"
#include <MessageCore/NodeHelper>
#include <MessageCore/StringUtil>
#include <Libkleo/CryptoBackendFactory>
#include <KMime/Headers>
#include <KMime/Message>
......@@ -69,7 +66,7 @@
#include <QByteArray>
#include <QFile>
#include <QTextCodec>
#include <QTextDocument>
#include <QUrl>
// other includes
#include <sstream>
......@@ -486,52 +483,6 @@ void ObjectTreeParser::setPlainTextContent(QString plainTextContent)
mPlainTextContent = plainTextContent;
}
void ObjectTreeParser::writePartIcon(KMime::Content *msgPart, bool inlineImage)
{
if (!htmlWriter() || !msgPart) {
return;
}
const QString name = msgPart->contentType()->name();
QString label = name.isEmpty() ? NodeHelper::fileName(msgPart) : name;
if (label.isEmpty()) {
label = i18nc("display name for an unnamed attachment", "Unnamed");
}
label = StringUtil::quoteHtmlChars(label, true);
QString comment = msgPart->contentDescription()->asUnicodeString();
comment = StringUtil::quoteHtmlChars(comment, true);
if (label == comment) {
comment.clear();
}
QString href = mNodeHelper->asHREF(msgPart, QStringLiteral("body"));
if (inlineImage) {
const QString fileName = mNodeHelper->writeNodeToTempFile(msgPart);
// show the filename of the image below the embedded image
htmlWriter()->queue(QLatin1String("<hr/><div><a href=\"") + href + QLatin1String("\">"
"<img align=\"center\" src=\"") + QUrl::fromLocalFile(fileName).url() + QLatin1String("\" border=\"0\" style=\"max-width: 100%\"/></a>"
"</div>"
"<div><a href=\"") + href + QLatin1String("\">") + label + QLatin1String("</a>"
"</div>"
"<div>") + comment + QLatin1String("</div>"));
} else {
// show the filename next to the image
const QString iconName = QUrl::fromLocalFile(mNodeHelper->iconName(msgPart)).url();
if (iconName.right(14) == QLatin1String("mime_empty.png")) {
mNodeHelper->magicSetType(msgPart);
//iconName = mNodeHelper->iconName( msgPart );
}
const int iconSize = KIconLoader::global()->currentSize(KIconLoader::Desktop);
htmlWriter()->queue(QStringLiteral("<hr/><div><a href=\"%1\">").arg(href) +
QStringLiteral("<img align=\"center\" height=\"%1\" width=\"%1\" src=\"%2\" border=\"0\" style=\"max-width: 100%\" alt=\"\"/>").arg(QString::number(iconSize), iconName) +
label + QStringLiteral("</a></div>") +
QStringLiteral("<div>%1</div>").arg(comment));
}
}
static QString iconToDataUrl(const QString &iconPath)
{
QFile f(iconPath);
......
......@@ -362,8 +362,6 @@ private:
Interface::MessagePartPtr defaultHandling(KMime::Content *node, ProcessResult &result);
public:// (during refactoring)
void writePartIcon(KMime::Content *msgPart, bool inlineImage = false);
/** Change the string to `quoted' html (meaning, that the quoted
part of the message get italized */
QString quotedHTML(const QString &pos, bool decorate);
......
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