Changeset View
Changeset View
Standalone View
Standalone View
messageviewer/src/messagepartthemes/default/defaultrenderer.cpp
Show All 17 Lines | |||||
18 | */ | 18 | */ | ||
19 | 19 | | |||
20 | #include "defaultrenderer.h" | 20 | #include "defaultrenderer.h" | ||
21 | 21 | | |||
22 | #include "defaultrenderer_p.h" | 22 | #include "defaultrenderer_p.h" | ||
23 | 23 | | |||
24 | #include "messageviewer_debug.h" | 24 | #include "messageviewer_debug.h" | ||
25 | 25 | | |||
26 | #include "cachehtmlwriter.h" | | |||
27 | #include "converthtmltoplaintext.h" | 26 | #include "converthtmltoplaintext.h" | ||
28 | #include "messagepartrendererbase.h" | 27 | #include "messagepartrendererbase.h" | ||
29 | #include "messagepartrendererfactory.h" | 28 | #include "messagepartrendererfactory.h" | ||
30 | #include "htmlblock.h" | 29 | #include "htmlblock.h" | ||
31 | 30 | | |||
32 | #include "utils/iconnamecache.h" | 31 | #include "utils/iconnamecache.h" | ||
33 | #include "utils/mimetype.h" | 32 | #include "utils/mimetype.h" | ||
34 | #include "viewer/csshelperbase.h" | 33 | #include "viewer/csshelperbase.h" | ||
Show All 16 Lines | |||||
51 | #include <QUrl> | 50 | #include <QUrl> | ||
52 | 51 | | |||
53 | #include <grantlee/context.h> | 52 | #include <grantlee/context.h> | ||
54 | #include <grantlee/engine.h> | 53 | #include <grantlee/engine.h> | ||
55 | #include <grantlee/metatype.h> | 54 | #include <grantlee/metatype.h> | ||
56 | #include <grantlee/templateloader.h> | 55 | #include <grantlee/templateloader.h> | ||
57 | #include <grantlee/template.h> | 56 | #include <grantlee/template.h> | ||
58 | 57 | | |||
59 | #include <functional> | | |||
60 | | ||||
61 | using namespace MimeTreeParser; | 58 | using namespace MimeTreeParser; | ||
62 | using namespace MessageViewer; | 59 | using namespace MessageViewer; | ||
63 | 60 | | |||
64 | typedef std::function<void(Grantlee::OutputStream *stream)> GrantleeCallback; | | |||
65 | Q_DECLARE_METATYPE(GrantleeCallback) | | |||
66 | | ||||
67 | Q_DECLARE_METATYPE(GpgME::DecryptionResult::Recipient) | 61 | Q_DECLARE_METATYPE(GpgME::DecryptionResult::Recipient) | ||
68 | Q_DECLARE_METATYPE(const QGpgME::Protocol *) | 62 | Q_DECLARE_METATYPE(const QGpgME::Protocol *) | ||
69 | 63 | | |||
70 | static const int SIG_FRAME_COL_UNDEF = 99; | 64 | static const int SIG_FRAME_COL_UNDEF = 99; | ||
71 | #define SIG_FRAME_COL_RED -1 | 65 | #define SIG_FRAME_COL_RED -1 | ||
72 | #define SIG_FRAME_COL_YELLOW 0 | 66 | #define SIG_FRAME_COL_YELLOW 0 | ||
73 | #define SIG_FRAME_COL_GREEN 1 | 67 | #define SIG_FRAME_COL_GREEN 1 | ||
74 | QString sigStatusToString(const QGpgME::Protocol *cryptProto, int status_code, GpgME::Signature::Summary summary, int &frameColor, bool &showKeyInfos) | 68 | QString sigStatusToString(const QGpgME::Protocol *cryptProto, int status_code, GpgME::Signature::Summary summary, int &frameColor, bool &showKeyInfos) | ||
▲ Show 20 Lines • Show All 235 Lines • ▼ Show 20 Line(s) | 287 | { | |||
310 | s = s.replace(QRegExp(QStringLiteral("<body[^>]*>"), Qt::CaseInsensitive), QString()).trimmed(); | 304 | s = s.replace(QRegExp(QStringLiteral("<body[^>]*>"), Qt::CaseInsensitive), QString()).trimmed(); | ||
311 | s = s.replace(QRegExp(QStringLiteral("</html>$"), Qt::CaseInsensitive), QString()).trimmed(); | 305 | s = s.replace(QRegExp(QStringLiteral("</html>$"), Qt::CaseInsensitive), QString()).trimmed(); | ||
312 | s = s.replace(QRegExp(QStringLiteral("</body>$"), Qt::CaseInsensitive), QString()).trimmed(); | 306 | s = s.replace(QRegExp(QStringLiteral("</body>$"), Qt::CaseInsensitive), QString()).trimmed(); | ||
313 | return s; | 307 | return s; | ||
314 | } | 308 | } | ||
315 | 309 | | |||
316 | DefaultRendererPrivate::DefaultRendererPrivate(const MessagePart::Ptr &msgPart, CSSHelperBase *cssHelper, HtmlWriter *writer, const MessagePartRendererFactory *rendererFactory) | 310 | DefaultRendererPrivate::DefaultRendererPrivate(const MessagePart::Ptr &msgPart, CSSHelperBase *cssHelper, HtmlWriter *writer, const MessagePartRendererFactory *rendererFactory) | ||
317 | : mMsgPart(msgPart) | 311 | : mMsgPart(msgPart) | ||
318 | , mOldWriter(writer) | | |||
319 | , mCSSHelper(cssHelper) | 312 | , mCSSHelper(cssHelper) | ||
320 | , mRendererFactory(rendererFactory) | 313 | , mRendererFactory(rendererFactory) | ||
321 | { | 314 | { | ||
322 | mHtml = renderFactory(mMsgPart, nullptr); | 315 | renderFactory(mMsgPart, writer); | ||
323 | } | 316 | } | ||
324 | 317 | | |||
325 | DefaultRendererPrivate::~DefaultRendererPrivate() | 318 | DefaultRendererPrivate::~DefaultRendererPrivate() | ||
326 | { | 319 | { | ||
327 | } | 320 | } | ||
328 | 321 | | |||
329 | CSSHelperBase *DefaultRendererPrivate::cssHelper() const | 322 | CSSHelperBase *DefaultRendererPrivate::cssHelper() const | ||
330 | { | 323 | { | ||
331 | return mCSSHelper; | 324 | return mCSSHelper; | ||
332 | } | 325 | } | ||
333 | 326 | | |||
334 | Interface::ObjectTreeSource *DefaultRendererPrivate::source() const | 327 | Interface::ObjectTreeSource *DefaultRendererPrivate::source() const | ||
335 | { | 328 | { | ||
336 | return mMsgPart->source(); | 329 | return mMsgPart->source(); | ||
337 | } | 330 | } | ||
338 | 331 | | |||
339 | void DefaultRendererPrivate::renderSubParts(const MessagePart::Ptr &msgPart, HtmlWriter *htmlWriter) | 332 | void DefaultRendererPrivate::renderSubParts(const MessagePart::Ptr &msgPart, HtmlWriter *htmlWriter) | ||
340 | { | 333 | { | ||
341 | foreach (const auto &m, msgPart->subParts()) | 334 | foreach (const auto &m, msgPart->subParts()) | ||
342 | htmlWriter->write(renderFactory(m, htmlWriter)); | 335 | renderFactory(m, htmlWriter); | ||
343 | } | 336 | } | ||
344 | 337 | | |||
345 | void DefaultRendererPrivate::render(const MessagePartList::Ptr &mp, HtmlWriter *htmlWriter) | 338 | void DefaultRendererPrivate::render(const MessagePartList::Ptr &mp, HtmlWriter *htmlWriter) | ||
346 | { | 339 | { | ||
347 | HTMLBlock::Ptr rBlock; | 340 | HTMLBlock::Ptr rBlock; | ||
348 | HTMLBlock::Ptr aBlock; | 341 | HTMLBlock::Ptr aBlock; | ||
349 | 342 | | |||
350 | if (mp->isRoot()) { | 343 | if (mp->isRoot()) { | ||
▲ Show 20 Lines • Show All 494 Lines • ▼ Show 20 Line(s) | 837 | if (!mRendererFactory) | |||
845 | return false; | 838 | return false; | ||
846 | for (auto r : mRendererFactory->typeRegistry(className)) { | 839 | for (auto r : mRendererFactory->typeRegistry(className)) { | ||
847 | if (r->render(msgPart, htmlWriter, this)) | 840 | if (r->render(msgPart, htmlWriter, this)) | ||
848 | return true; | 841 | return true; | ||
849 | } | 842 | } | ||
850 | return false; | 843 | return false; | ||
851 | } | 844 | } | ||
852 | 845 | | |||
853 | QString DefaultRendererPrivate::renderFactory(const MessagePart::Ptr &msgPart, HtmlWriter *_htmlWriter) | 846 | void DefaultRendererPrivate::renderFactory(const MessagePart::Ptr &msgPart, HtmlWriter *htmlWriter) | ||
854 | { | 847 | { | ||
855 | auto htmlWriter = QSharedPointer<CacheHtmlWriter>(new CacheHtmlWriter(mOldWriter)); | | |||
856 | const QString className = QString::fromUtf8(msgPart->metaObject()->className()); | 848 | const QString className = QString::fromUtf8(msgPart->metaObject()->className()); | ||
857 | 849 | | |||
858 | if (renderWithFactory(className, msgPart, htmlWriter.data())) | 850 | if (renderWithFactory(className, msgPart, htmlWriter)) | ||
859 | return htmlWriter->html(); | 851 | return; | ||
860 | 852 | | |||
861 | if (className == QStringLiteral("MimeTreeParser::MessagePartList")) { | 853 | if (className == QStringLiteral("MimeTreeParser::MessagePartList")) { | ||
862 | auto mp = msgPart.dynamicCast<MessagePartList>(); | 854 | auto mp = msgPart.dynamicCast<MessagePartList>(); | ||
863 | if (mp) { | 855 | if (mp) { | ||
864 | render(mp, htmlWriter.data()); | 856 | render(mp, htmlWriter); | ||
865 | } | 857 | } | ||
866 | } else if (className == QStringLiteral("MimeTreeParser::MimeMessagePart")) { | 858 | } else if (className == QStringLiteral("MimeTreeParser::MimeMessagePart")) { | ||
867 | auto mp = msgPart.dynamicCast<MimeMessagePart>(); | 859 | auto mp = msgPart.dynamicCast<MimeMessagePart>(); | ||
868 | if (mp) { | 860 | if (mp) { | ||
869 | render(mp, htmlWriter.data()); | 861 | render(mp, htmlWriter); | ||
870 | } | 862 | } | ||
871 | } else if (className == QStringLiteral("MimeTreeParser::EncapsulatedRfc822MessagePart")) { | 863 | } else if (className == QStringLiteral("MimeTreeParser::EncapsulatedRfc822MessagePart")) { | ||
872 | auto mp = msgPart.dynamicCast<EncapsulatedRfc822MessagePart>(); | 864 | auto mp = msgPart.dynamicCast<EncapsulatedRfc822MessagePart>(); | ||
873 | if (mp) { | 865 | if (mp) { | ||
874 | render(mp, htmlWriter.data()); | 866 | render(mp, htmlWriter); | ||
875 | } | 867 | } | ||
876 | } else if (className == QStringLiteral("MimeTreeParser::HtmlMessagePart")) { | 868 | } else if (className == QStringLiteral("MimeTreeParser::HtmlMessagePart")) { | ||
877 | auto mp = msgPart.dynamicCast<HtmlMessagePart>(); | 869 | auto mp = msgPart.dynamicCast<HtmlMessagePart>(); | ||
878 | if (mp) { | 870 | if (mp) { | ||
879 | render(mp, htmlWriter.data()); | 871 | render(mp, htmlWriter); | ||
880 | } | 872 | } | ||
881 | } else if (className == QStringLiteral("MimeTreeParser::SignedMessagePart")) { | 873 | } else if (className == QStringLiteral("MimeTreeParser::SignedMessagePart")) { | ||
882 | auto mp = msgPart.dynamicCast<SignedMessagePart>(); | 874 | auto mp = msgPart.dynamicCast<SignedMessagePart>(); | ||
883 | if (mp) { | 875 | if (mp) { | ||
884 | render(mp, htmlWriter.data()); | 876 | render(mp, htmlWriter); | ||
885 | } | 877 | } | ||
886 | } else if (className == QStringLiteral("MimeTreeParser::EncryptedMessagePart")) { | 878 | } else if (className == QStringLiteral("MimeTreeParser::EncryptedMessagePart")) { | ||
887 | auto mp = msgPart.dynamicCast<EncryptedMessagePart>(); | 879 | auto mp = msgPart.dynamicCast<EncryptedMessagePart>(); | ||
888 | if (mp) { | 880 | if (mp) { | ||
889 | render(mp, htmlWriter.data()); | 881 | render(mp, htmlWriter); | ||
890 | } | 882 | } | ||
891 | } else if (className == QStringLiteral("MimeTreeParser::AlternativeMessagePart")) { | 883 | } else if (className == QStringLiteral("MimeTreeParser::AlternativeMessagePart")) { | ||
892 | auto mp = msgPart.dynamicCast<AlternativeMessagePart>(); | 884 | auto mp = msgPart.dynamicCast<AlternativeMessagePart>(); | ||
893 | if (mp) { | 885 | if (mp) { | ||
894 | render(mp, htmlWriter.data()); | 886 | render(mp, htmlWriter); | ||
895 | } | 887 | } | ||
896 | } else if (className == QStringLiteral("MimeTreeParser::CertMessagePart")) { | 888 | } else if (className == QStringLiteral("MimeTreeParser::CertMessagePart")) { | ||
897 | auto mp = msgPart.dynamicCast<CertMessagePart>(); | 889 | auto mp = msgPart.dynamicCast<CertMessagePart>(); | ||
898 | if (mp) { | 890 | if (mp) { | ||
899 | render(mp, htmlWriter.data()); | 891 | render(mp, htmlWriter); | ||
900 | } | 892 | } | ||
901 | } else if (auto mp = msgPart.dynamicCast<LegacyPluginMessagePart>()) { | 893 | } else if (auto mp = msgPart.dynamicCast<LegacyPluginMessagePart>()) { | ||
902 | return mp->formatOutput(); | 894 | htmlWriter->write(mp->formatOutput()); | ||
903 | } else { | 895 | } else { | ||
904 | qCWarning(MESSAGEVIEWER_LOG) << "We got a unkonwn classname, using default behaviour for " | 896 | qCWarning(MESSAGEVIEWER_LOG) << "We got a unkonwn classname, using default behaviour for " | ||
905 | << className; | 897 | << className; | ||
906 | } | 898 | } | ||
907 | return htmlWriter->html(); | | |||
908 | } | 899 | } | ||
909 | 900 | | |||
910 | DefaultRenderer::DefaultRenderer(const MimeTreeParser::MessagePart::Ptr &msgPart, CSSHelperBase *cssHelper, MimeTreeParser::HtmlWriter *writer) | 901 | DefaultRenderer::DefaultRenderer(const MimeTreeParser::MessagePart::Ptr &msgPart, CSSHelperBase *cssHelper, MimeTreeParser::HtmlWriter *writer) | ||
911 | : d(new MimeTreeParser::DefaultRendererPrivate(msgPart, cssHelper, writer, MessagePartRendererFactory::instance())) | 902 | : d(new MimeTreeParser::DefaultRendererPrivate(msgPart, cssHelper, writer, MessagePartRendererFactory::instance())) | ||
912 | { | 903 | { | ||
913 | } | 904 | } | ||
914 | 905 | | |||
915 | DefaultRenderer::~DefaultRenderer() | 906 | DefaultRenderer::~DefaultRenderer() | ||
916 | { | 907 | { | ||
917 | delete d; | 908 | delete d; | ||
918 | } | 909 | } | ||
919 | | ||||
920 | QString DefaultRenderer::html() const | | |||
921 | { | | |||
922 | return d->mHtml; | | |||
923 | } | |