Members of the KDE Community are recommended to subscribe to the kde-community mailing list at https://mail.kde.org/mailman/listinfo/kde-community to allow them to participate in important discussions and receive other important announcements

Commit 24c9f573 authored by Sandro Knauß's avatar Sandro Knauß

move DefaultRendererPrivate into MessageViewer namespace

Reviewers: vkrause

Subscribers: #kde_pim

Tags: #kde_pim

Differential Revision: https://phabricator.kde.org/D8584
parent 14891a09
......@@ -378,9 +378,9 @@ void DefaultRendererPrivate::render(const EncapsulatedRfc822MessagePart::Ptr &mp
c.insert(QStringLiteral("block"), &block);
block.setProperty("link",
mp->nodeHelper()->asHREF(mp->mMessage.data(), QStringLiteral("body")));
mp->nodeHelper()->asHREF(mp->message().data(), QStringLiteral("body")));
c.insert(QStringLiteral("msgHeader"), mp->source()->createMessageHeader(mp->mMessage.data()));
c.insert(QStringLiteral("msgHeader"), mp->source()->createMessageHeader(mp->message().data()));
c.insert(QStringLiteral("content"), QVariant::fromValue<GrantleeCallback>([this, mp, htmlWriter](Grantlee::OutputStream *) {
renderSubParts(mp, htmlWriter);
}));
......@@ -403,7 +403,7 @@ void DefaultRendererPrivate::render(const HtmlMessagePart::Ptr &mp, HtmlWriter *
c.insert(QStringLiteral("block"), &block);
auto preferredMode = mp->source()->preferredMode();
bool isHtmlPreferred = (preferredMode == Util::Html) || (preferredMode == Util::MultipartHtml);
bool isHtmlPreferred = (preferredMode == MimeTreeParser::Util::Html) || (preferredMode == MimeTreeParser::Util::MultipartHtml);
const bool isPrinting = mp->source()->isPrinting();
block.setProperty("htmlMail", isHtmlPreferred);
block.setProperty("loadExternal", mp->source()->htmlLoadExternal());
......@@ -411,7 +411,7 @@ void DefaultRendererPrivate::render(const HtmlMessagePart::Ptr &mp, HtmlWriter *
{
QString extraHead;
//laurent: FIXME port to async method webengine
QString bodyText = processHtml(mp->mBodyHTML, extraHead);
QString bodyText = processHtml(mp->bodyHtml(), extraHead);
if (isHtmlPreferred) {
mp->nodeHelper()->setNodeDisplayedEmbedded(mp->content(), true);
......@@ -425,12 +425,12 @@ void DefaultRendererPrivate::render(const HtmlMessagePart::Ptr &mp, HtmlWriter *
{
ConvertHtmlToPlainText convert;
convert.setHtmlString(mp->mBodyHTML);
convert.setHtmlString(mp->bodyHtml());
QString plaintext = convert.generatePlainText();
plaintext.replace(QLatin1Char('\n'), QStringLiteral("<br>"));
c.insert(QStringLiteral("plaintext"), plaintext);
}
mp->source()->setHtmlMode(Util::Html, QList<Util::HtmlMode>() << Util::Html);
mp->source()->setHtmlMode(MimeTreeParser::Util::Html, QList<MimeTreeParser::Util::HtmlMode>() << MimeTreeParser::Util::Html);
HTMLBlock::Ptr aBlock;
if (mp->isAttachment()) {
......@@ -464,10 +464,10 @@ void DefaultRendererPrivate::renderEncrypted(const EncryptedMessagePart::Ptr &mp
}));
}
c.insert(QStringLiteral("cryptoProto"), QVariant::fromValue(mp->mCryptoProto));
if (!mp->mDecryptRecipients.empty()) {
c.insert(QStringLiteral("cryptoProto"), QVariant::fromValue(mp->cryptoProto()));
if (!mp->decryptRecipients().empty()) {
c.insert(QStringLiteral("decryptedRecipients"),
QVariant::fromValue(mp->mDecryptRecipients));
QVariant::fromValue(mp->decryptRecipients()));
}
c.insert(QStringLiteral("block"), &block);
......@@ -479,7 +479,7 @@ void DefaultRendererPrivate::renderEncrypted(const EncryptedMessagePart::Ptr &mp
"document-decrypt"),
KIconLoader::Small)).url());
block.setProperty("errorText", metaData.errorText);
block.setProperty("noSecKey", mp->mNoSecKey);
block.setProperty("noSecKey", mp->isNoSecKey());
Grantlee::OutputStream s(htmlWriter->stream());
t->render(&s, &c);
......@@ -489,7 +489,7 @@ void DefaultRendererPrivate::renderSigned(const SignedMessagePart::Ptr &mp, Html
{
KMime::Content *node = mp->content();
const auto metaData = *mp->partMetaData();
auto cryptoProto = mp->mCryptoProto;
auto cryptoProto = mp->cryptoProto();
const bool isSMIME = cryptoProto && (cryptoProto == QGpgME::smime());
......@@ -625,7 +625,7 @@ void DefaultRendererPrivate::renderSigned(const SignedMessagePart::Ptr &mp, Html
mClass = QStringLiteral("signOkKeyOk");
// extra hint for green case
// that email addresses in DN do not match fromAddress
QString msgFrom(KEmailAddress::extractEmailAddress(mp->mFromAddress));
QString msgFrom(KEmailAddress::extractEmailAddress(mp->fromAddress()));
QString certificate;
if (metaData.keyId.isEmpty()) {
certificate = i18n("certificate");
......@@ -790,9 +790,9 @@ void DefaultRendererPrivate::render(const AlternativeMessagePart::Ptr &mp, HtmlW
}
}
}
MimeMessagePart::Ptr part(mp->mChildParts.first());
if (mp->mChildParts.contains(mode)) {
part = mp->mChildParts[mode];
MimeMessagePart::Ptr part(mp->childParts().first());
if (mp->childParts().contains(mode)) {
part = mp->childParts()[mode];
}
render(part, htmlWriter);
......@@ -800,7 +800,7 @@ void DefaultRendererPrivate::render(const AlternativeMessagePart::Ptr &mp, HtmlW
void DefaultRendererPrivate::render(const CertMessagePart::Ptr &mp, HtmlWriter *htmlWriter)
{
const GpgME::ImportResult &importResult(mp->mImportResult);
const GpgME::ImportResult &importResult(mp->importResult());
Grantlee::Template t = MessageViewer::MessagePartRendererManager::self()->loadByName(QStringLiteral(
":/certmessagepart.html"));
Grantlee::Context c = MessageViewer::MessagePartRendererManager::self()->createContext();
......@@ -921,7 +921,7 @@ bool DefaultRendererPrivate::isHiddenHint(const MimeTreeParser::MessagePart::Ptr
const AttachmentStrategy *const as = mAttachmentStrategy;
const bool defaultHidden(as && as->defaultDisplay(content) == AttachmentStrategy::None);
auto preferredMode = source()->preferredMode();
bool isHtmlPreferred = (preferredMode == Util::Html) || (preferredMode == Util::MultipartHtml);
bool isHtmlPreferred = (preferredMode == MimeTreeParser::Util::Html) || (preferredMode == MimeTreeParser::Util::MultipartHtml);
QByteArray mediaType("text");
if (content->contentType(false) && !content->contentType()->mediaType().isEmpty()
......@@ -958,7 +958,7 @@ bool DefaultRendererPrivate::isHiddenHint(const MimeTreeParser::MessagePart::Ptr
return hidden;
}
MimeTreeParser::IconType MimeTreeParser::DefaultRendererPrivate::displayHint(const MimeTreeParser::MessagePart::Ptr& msgPart)
MimeTreeParser::IconType DefaultRendererPrivate::displayHint(const MimeTreeParser::MessagePart::Ptr& msgPart)
{
auto mp = msgPart.dynamicCast<MimeTreeParser::AttachmentMessagePart>();
auto content = msgPart->content();
......@@ -969,7 +969,7 @@ MimeTreeParser::IconType MimeTreeParser::DefaultRendererPrivate::displayHint(con
const bool defaultHidden(as && as->defaultDisplay(content) == AttachmentStrategy::None);
const bool showOnlyOneMimePart(mShowOnlyOneMimePart);
auto preferredMode = source()->preferredMode();
bool isHtmlPreferred = (preferredMode == Util::Html) || (preferredMode == Util::MultipartHtml);
bool isHtmlPreferred = (preferredMode == MimeTreeParser::Util::Html) || (preferredMode == MimeTreeParser::Util::MultipartHtml);
QByteArray mediaType("text");
if (content->contentType(false) && !content->contentType()->mediaType().isEmpty()
......@@ -1019,7 +1019,7 @@ MimeTreeParser::IconType MimeTreeParser::DefaultRendererPrivate::displayHint(con
}
DefaultRenderer::DefaultRenderer(CSSHelperBase *cssHelper)
: d(new MimeTreeParser::DefaultRendererPrivate(cssHelper, MessagePartRendererFactory::instance()))
: d(new DefaultRendererPrivate(cssHelper, MessagePartRendererFactory::instance()))
{
}
......
......@@ -23,12 +23,12 @@
#include <QSharedPointer>
namespace MimeTreeParser {
class DefaultRendererPrivate;
class MessagePart;
typedef QSharedPointer<MessagePart> MessagePartPtr;
}
namespace MessageViewer {
class DefaultRendererPrivate;
class HtmlWriter;
class AttachmentStrategy;
class CSSHelperBase;
......@@ -43,7 +43,7 @@ public:
void setAttachmentStrategy(const AttachmentStrategy *strategy);
void render(const MimeTreeParser::MessagePartPtr &msgPart, HtmlWriter *writer);
private:
MimeTreeParser::DefaultRendererPrivate *d;
DefaultRendererPrivate *d;
};
}
#endif //__MIMETREEPARSER_MAILRENDERER_H__
#endif //__MESSAGEVIEWER_MAILRENDERER_H__
......@@ -24,19 +24,13 @@
#include <MimeTreeParser/MessagePart>
using namespace MimeTreeParser;
using namespace MessageViewer;
namespace MessageViewer {
class AttachmentStrategy;
class MessagePartRendererFactory;
class CSSHelperBase;
class HtmlWriter;
}
namespace MimeTreeParser {
class DefaultRendererPrivate : public MessageViewer::RenderContext
class DefaultRendererPrivate : public RenderContext
{
public:
DefaultRendererPrivate(CSSHelperBase *cssHelper, const MessagePartRendererFactory *rendererFactory);
......@@ -44,32 +38,32 @@ public:
CSSHelperBase *cssHelper() const override;
Interface::ObjectTreeSource *source() const;
MimeTreeParser::Interface::ObjectTreeSource *source() const;
void renderSubParts(const MessagePart::Ptr &msgPart, MessageViewer::HtmlWriter *htmlWriter) override;
void renderSubParts(const MimeTreeParser::MessagePart::Ptr &msgPart, HtmlWriter *htmlWriter) override;
void render(const MessagePartList::Ptr &mp, MessageViewer::HtmlWriter *htmlWriter);
void render(const MimeMessagePart::Ptr &mp, MessageViewer::HtmlWriter *htmlWriter);
void render(const EncapsulatedRfc822MessagePart::Ptr &mp, MessageViewer::HtmlWriter *htmlWriter);
void render(const HtmlMessagePart::Ptr &mp, MessageViewer::HtmlWriter *htmlWriter);
void renderEncrypted(const EncryptedMessagePart::Ptr &mp, MessageViewer::HtmlWriter *htmlWriter);
void renderSigned(const SignedMessagePart::Ptr &mp, MessageViewer::HtmlWriter *htmlWriter);
void render(const SignedMessagePart::Ptr &mp, MessageViewer::HtmlWriter *htmlWriter);
void render(const EncryptedMessagePart::Ptr &mp, MessageViewer::HtmlWriter *htmlWriter);
void render(const AlternativeMessagePart::Ptr &mp, MessageViewer::HtmlWriter *htmlWriter);
void render(const CertMessagePart::Ptr &mp, MessageViewer::HtmlWriter *htmlWriter);
bool renderWithFactory(const QMetaObject *mo, const MessagePart::Ptr &msgPart, MessageViewer::HtmlWriter *writer) override;
void render(const MimeTreeParser::MessagePartList::Ptr &mp, HtmlWriter *htmlWriter);
void render(const MimeTreeParser::MimeMessagePart::Ptr &mp, HtmlWriter *htmlWriter);
void render(const MimeTreeParser::EncapsulatedRfc822MessagePart::Ptr &mp, HtmlWriter *htmlWriter);
void render(const MimeTreeParser::HtmlMessagePart::Ptr &mp, HtmlWriter *htmlWriter);
void renderEncrypted(const MimeTreeParser::EncryptedMessagePart::Ptr &mp, HtmlWriter *htmlWriter);
void renderSigned(const MimeTreeParser::SignedMessagePart::Ptr &mp, HtmlWriter *htmlWriter);
void render(const MimeTreeParser::SignedMessagePart::Ptr &mp, HtmlWriter *htmlWriter);
void render(const MimeTreeParser::EncryptedMessagePart::Ptr &mp, HtmlWriter *htmlWriter);
void render(const MimeTreeParser::AlternativeMessagePart::Ptr &mp, HtmlWriter *htmlWriter);
void render(const MimeTreeParser::CertMessagePart::Ptr &mp, HtmlWriter *htmlWriter);
bool renderWithFactory(const QMetaObject *mo, const MimeTreeParser::MessagePart::Ptr &msgPart, HtmlWriter *writer) override;
using RenderContext::renderWithFactory;
void renderFactory(const MessagePart::Ptr &msgPart, MessageViewer::HtmlWriter *htmlWriter);
void renderFactory(const MimeTreeParser::MessagePart::Ptr &msgPart, HtmlWriter *htmlWriter);
bool isHiddenHint(const MimeTreeParser::MessagePart::Ptr &msgPart) override;
MimeTreeParser::IconType displayHint(const MimeTreeParser::MessagePart::Ptr &msgPart) override;
bool mShowOnlyOneMimePart = false;
MessagePart::Ptr mMsgPart;
MimeTreeParser::MessagePart::Ptr mMsgPart;
CSSHelperBase *mCSSHelper = nullptr;
const MessageViewer::MessagePartRendererFactory *mRendererFactory = nullptr;
const MessageViewer::AttachmentStrategy *mAttachmentStrategy = nullptr;
const MessagePartRendererFactory *mRendererFactory = nullptr;
const AttachmentStrategy *mAttachmentStrategy = nullptr;
};
}
#endif
......@@ -22,7 +22,6 @@
#include "quotehtml.h"
#include "utils/mimetype.h"
#include "../defaultrenderer_p.h"
#include "../messagepartrenderermanager.h"
#include <MessageCore/StringUtil>
......@@ -44,7 +43,7 @@ AttachmentMessagePartRenderer::~AttachmentMessagePartRenderer()
bool AttachmentMessagePartRenderer::render(const MimeTreeParser::MessagePartPtr &msgPart, HtmlWriter *htmlWriter, RenderContext *context) const
{
auto mp = msgPart.dynamicCast<AttachmentMessagePart>();
auto mp = msgPart.dynamicCast<MimeTreeParser::AttachmentMessagePart>();
if (!mp) {
return false;
}
......@@ -73,7 +72,7 @@ bool AttachmentMessagePartRenderer::render(const MimeTreeParser::MessagePartPtr
} else {
iconPath = MessageViewer::Util::iconPathForContent(node, KIconLoader::Desktop);
if (iconPath.right(14) == QLatin1String("mime_empty.png")) {
NodeHelper::magicSetType(node);
MimeTreeParser::NodeHelper::magicSetType(node);
iconPath = MessageViewer::Util::iconPathForContent(node, KIconLoader::Desktop);
}
}
......
......@@ -21,7 +21,6 @@
#include "quotehtml.h"
#include "../defaultrenderer_p.h"
#include "../messagepartrenderermanager.h"
#include <MessageCore/StringUtil>
......@@ -43,7 +42,7 @@ TextMessagePartRenderer::~TextMessagePartRenderer()
bool TextMessagePartRenderer::render(const MimeTreeParser::MessagePartPtr &msgPart, HtmlWriter *htmlWriter, RenderContext *context) const
{
Q_UNUSED(context);
auto mp = msgPart.dynamicCast<TextMessagePart>();
auto mp = msgPart.dynamicCast<MimeTreeParser::TextMessagePart>();
if (!mp) {
return false;
}
......
......@@ -488,6 +488,11 @@ bool HtmlMessagePart::isHtml() const
return true;
}
QString HtmlMessagePart::bodyHtml() const
{
return mBodyHTML;
}
//-----MimeMessageBlock----------------------
MimeMessagePart::MimeMessagePart(ObjectTreeParser *otp, KMime::Content *node, bool onlyOneMimePart)
......@@ -608,6 +613,11 @@ void AlternativeMessagePart::fix() const
}
}
const QMap<Util::HtmlMode, MimeMessagePart::Ptr> &AlternativeMessagePart::childParts() const
{
return mChildParts;
}
bool AlternativeMessagePart::isHtml() const
{
return mChildParts.contains(Util::MultipartHtml);
......@@ -660,6 +670,11 @@ QString CertMessagePart::text() const
return QString();
}
const GpgME::ImportResult &CertMessagePart::importResult() const
{
return mImportResult;
}
//-----SignedMessageBlock---------------------
SignedMessagePart::SignedMessagePart(ObjectTreeParser *otp, const QString &text, const QGpgME::Protocol *cryptoProto, const QString &fromAddress, KMime::Content *node)
: MessagePart(otp, text)
......@@ -976,6 +991,16 @@ QString SignedMessagePart::htmlContent() const
}
}
const QGpgME::Protocol *SignedMessagePart::cryptoProto() const
{
return mCryptoProto;
}
QString SignedMessagePart::fromAddress() const
{
return mFromAddress;
}
//-----CryptMessageBlock---------------------
EncryptedMessagePart::EncryptedMessagePart(ObjectTreeParser *otp, const QString &text, const QGpgME::Protocol *cryptoProto, const QString &fromAddress, KMime::Content *node)
: MessagePart(otp, text)
......@@ -1025,6 +1050,11 @@ bool EncryptedMessagePart::isDecryptable() const
return partMetaData()->isDecryptable;
}
bool EncryptedMessagePart::isNoSecKey() const
{
return mNoSecKey;
}
bool EncryptedMessagePart::passphraseError() const
{
return mPassphraseError;
......@@ -1272,6 +1302,21 @@ QString EncryptedMessagePart::text() const
}
}
const QGpgME::Protocol *EncryptedMessagePart::cryptoProto() const
{
return mCryptoProto;
}
QString EncryptedMessagePart::fromAddress() const
{
return mFromAddress;
}
const std::vector<std::pair<GpgME::DecryptionResult::Recipient, GpgME::Key>> &EncryptedMessagePart::decryptRecipients() const
{
return mDecryptRecipients;
}
EncapsulatedRfc822MessagePart::EncapsulatedRfc822MessagePart(ObjectTreeParser *otp, KMime::Content *node, const KMime::Message::Ptr &message)
: MessagePart(otp, QString())
, mMessage(message)
......@@ -1308,3 +1353,8 @@ QString EncapsulatedRfc822MessagePart::text() const
void EncapsulatedRfc822MessagePart::fix() const
{
}
const KMime::Message::Ptr EncapsulatedRfc822MessagePart::message() const
{
return mMessage;
}
......@@ -246,12 +246,12 @@ public:
void fix() const override;
bool isHtml() const override;
QString bodyHtml() const;
private:
Interface::ObjectTreeSource *mSource;
QString mBodyHTML;
QByteArray mCharset;
friend class DefaultRendererPrivate;
};
class MIMETREEPARSER_EXPORT AlternativeMessagePart : public MessagePart
......@@ -274,13 +274,15 @@ public:
QList<Util::HtmlMode> availableModes();
void fix() const override;
const QMap<Util::HtmlMode, MimeMessagePart::Ptr> &childParts() const;
private:
Util::HtmlMode mPreferredMode;
QMap<Util::HtmlMode, KMime::Content *> mChildNodes;
QMap<Util::HtmlMode, MimeMessagePart::Ptr> mChildParts;
friend class DefaultRendererPrivate;
friend class ObjectTreeParser;
friend class MultiPartAlternativeBodyPartFormatter;
};
......@@ -295,11 +297,12 @@ public:
QString text() const override;
const GpgME::ImportResult &importResult() const;
private:
bool mAutoImport;
GpgME::ImportResult mImportResult;
const QGpgME::Protocol *mCryptoProto;
friend class DefaultRendererPrivate;
};
class MIMETREEPARSER_EXPORT EncapsulatedRfc822MessagePart : public MessagePart
......@@ -313,10 +316,11 @@ public:
QString text() const override;
void fix() const override;
const KMime::Message::Ptr message() const;
private:
const KMime::Message::Ptr mMessage;
friend class DefaultRendererPrivate;
};
class MIMETREEPARSER_EXPORT EncryptedMessagePart : public MessagePart
......@@ -324,6 +328,7 @@ class MIMETREEPARSER_EXPORT EncryptedMessagePart : public MessagePart
Q_OBJECT
Q_PROPERTY(bool decryptMessage READ decryptMessage WRITE setDecryptMessage)
Q_PROPERTY(bool isEncrypted READ isEncrypted)
Q_PROPERTY(bool isNoSecKey READ isNoSecKey)
Q_PROPERTY(bool passphraseError READ passphraseError)
public:
typedef QSharedPointer<EncryptedMessagePart> Ptr;
......@@ -341,6 +346,7 @@ public:
bool isDecryptable() const;
bool isNoSecKey() const;
bool passphraseError() const;
void startDecryption(const QByteArray &text, const QTextCodec *aCodec);
......@@ -351,6 +357,11 @@ public:
QString plaintextContent() const override;
QString htmlContent() const override;
const QGpgME::Protocol *cryptoProto() const;
QString fromAddress() const;
const std::vector<std::pair<GpgME::DecryptionResult::Recipient, GpgME::Key>> &decryptRecipients() const;
private:
/** Handles the dectyptioon of a given content
* returns true if the decryption was successfull
......@@ -367,7 +378,6 @@ protected:
QByteArray mVerifiedText;
std::vector<std::pair<GpgME::DecryptionResult::Recipient, GpgME::Key> > mDecryptRecipients;
friend class DefaultRendererPrivate;
friend class EncryptedBodyPartFormatter;
};
......@@ -393,6 +403,9 @@ public:
QString plaintextContent() const override;
QString htmlContent() const override;
const QGpgME::Protocol *cryptoProto() const;
QString fromAddress() const;
private:
/** Handles the verification of data
* If signature is empty it is handled as inline signature otherwise as detached signature mode.
......@@ -410,7 +423,6 @@ protected:
QByteArray mVerifiedText;
friend EncryptedMessagePart;
friend class DefaultRendererPrivate;
};
}
......
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