Changeset View
Changeset View
Standalone View
Standalone View
messageviewer/src/messagepartthemes/default/defaultrenderer.cpp
Show All 22 Lines | |||||
23 | 23 | | |||
24 | #include "messageviewer_debug.h" | 24 | #include "messageviewer_debug.h" | ||
25 | 25 | | |||
26 | #include "cachehtmlwriter.h" | 26 | #include "cachehtmlwriter.h" | ||
27 | #include "converthtmltoplaintext.h" | 27 | #include "converthtmltoplaintext.h" | ||
28 | #include "messagepartrendererbase.h" | 28 | #include "messagepartrendererbase.h" | ||
29 | #include "messagepartrendererfactory.h" | 29 | #include "messagepartrendererfactory.h" | ||
30 | #include "htmlblock.h" | 30 | #include "htmlblock.h" | ||
31 | #include "partrendered.h" | | |||
32 | 31 | | |||
33 | #include "utils/iconnamecache.h" | 32 | #include "utils/iconnamecache.h" | ||
34 | #include "utils/mimetype.h" | 33 | #include "utils/mimetype.h" | ||
35 | #include "viewer/csshelperbase.h" | 34 | #include "viewer/csshelperbase.h" | ||
36 | #include "messagepartrenderermanager.h" | 35 | #include "messagepartrenderermanager.h" | ||
37 | 36 | | |||
38 | #include <MimeTreeParser/BufferedHtmlWriter> | 37 | #include <MimeTreeParser/BufferedHtmlWriter> | ||
39 | #include <MimeTreeParser/MessagePart> | 38 | #include <MimeTreeParser/MessagePart> | ||
▲ Show 20 Lines • Show All 427 Lines • ▼ Show 20 Line(s) | 465 | { | |||
467 | HTMLBlock::Ptr rBlock; | 466 | HTMLBlock::Ptr rBlock; | ||
468 | if (node && mp->isRoot()) { | 467 | if (node && mp->isRoot()) { | ||
469 | rBlock = HTMLBlock::Ptr(new RootBlock(_htmlWriter.data())); | 468 | rBlock = HTMLBlock::Ptr(new RootBlock(_htmlWriter.data())); | ||
470 | } | 469 | } | ||
471 | renderSubParts(mp, _htmlWriter.data()); | 470 | renderSubParts(mp, _htmlWriter.data()); | ||
472 | } | 471 | } | ||
473 | c.insert(QStringLiteral("content"), _htmlWriter->html()); | 472 | c.insert(QStringLiteral("content"), _htmlWriter->html()); | ||
474 | } else if (!metaData.inProgress) { | 473 | } else if (!metaData.inProgress) { | ||
475 | auto part = renderWithFactory(QStringLiteral("MimeTreeParser::MessagePart"), mp); | 474 | CacheHtmlWriter nestedWriter(htmlWriter); | ||
476 | if (part) { | 475 | if (renderWithFactory(QStringLiteral("MimeTreeParser::MessagePart"), mp, &nestedWriter)) { | ||
477 | c.insert(QStringLiteral("content"), part->html()); | 476 | c.insert(QStringLiteral("content"), nestedWriter.html()); | ||
478 | } else { | 477 | } else { | ||
479 | c.insert(QStringLiteral("content"), QString()); | 478 | c.insert(QStringLiteral("content"), QString()); | ||
480 | } | 479 | } | ||
481 | } | 480 | } | ||
482 | 481 | | |||
483 | c.insert(QStringLiteral("cryptoProto"), QVariant::fromValue(mp->mCryptoProto)); | 482 | c.insert(QStringLiteral("cryptoProto"), QVariant::fromValue(mp->mCryptoProto)); | ||
484 | if (mp->mDecryptRecipients.size() > 0) { | 483 | if (mp->mDecryptRecipients.size() > 0) { | ||
485 | c.insert(QStringLiteral("decryptedRecipients"), | 484 | c.insert(QStringLiteral("decryptedRecipients"), | ||
Show All 37 Lines | 521 | { | |||
523 | HTMLBlock::Ptr rBlock; | 522 | HTMLBlock::Ptr rBlock; | ||
524 | if (mp->isRoot()) { | 523 | if (mp->isRoot()) { | ||
525 | rBlock = HTMLBlock::Ptr(new RootBlock(_htmlWriter.data())); | 524 | rBlock = HTMLBlock::Ptr(new RootBlock(_htmlWriter.data())); | ||
526 | } | 525 | } | ||
527 | renderSubParts(mp, _htmlWriter.data()); | 526 | renderSubParts(mp, _htmlWriter.data()); | ||
528 | } | 527 | } | ||
529 | c.insert(QStringLiteral("content"), _htmlWriter->html()); | 528 | c.insert(QStringLiteral("content"), _htmlWriter->html()); | ||
530 | } else if (!metaData.inProgress) { | 529 | } else if (!metaData.inProgress) { | ||
531 | auto part = renderWithFactory(QStringLiteral("MimeTreeParser::MessagePart"), mp); | 530 | CacheHtmlWriter nestedWriter(htmlWriter); | ||
532 | if (part) { | 531 | if (renderWithFactory(QStringLiteral("MimeTreeParser::MessagePart"), mp, &nestedWriter)) { | ||
533 | c.insert(QStringLiteral("content"), part->html()); | 532 | c.insert(QStringLiteral("content"), nestedWriter.html()); | ||
534 | } else { | 533 | } else { | ||
535 | c.insert(QStringLiteral("content"), QString()); | 534 | c.insert(QStringLiteral("content"), QString()); | ||
536 | } | 535 | } | ||
537 | } | 536 | } | ||
538 | 537 | | |||
539 | c.insert(QStringLiteral("cryptoProto"), QVariant::fromValue(cryptoProto)); | 538 | c.insert(QStringLiteral("cryptoProto"), QVariant::fromValue(cryptoProto)); | ||
540 | c.insert(QStringLiteral("block"), &block); | 539 | c.insert(QStringLiteral("block"), &block); | ||
541 | 540 | | |||
▲ Show 20 Lines • Show All 223 Lines • ▼ Show 20 Line(s) | 754 | { | |||
765 | 764 | | |||
766 | HTMLBlock::Ptr aBlock; | 765 | HTMLBlock::Ptr aBlock; | ||
767 | if (mp->isAttachment()) { | 766 | if (mp->isAttachment()) { | ||
768 | aBlock = HTMLBlock::Ptr(new AttachmentMarkBlock(htmlWriter, mp->attachmentContent())); | 767 | aBlock = HTMLBlock::Ptr(new AttachmentMarkBlock(htmlWriter, mp->attachmentContent())); | ||
769 | } | 768 | } | ||
770 | if (mp->hasSubParts()) { | 769 | if (mp->hasSubParts()) { | ||
771 | renderSubParts(mp, htmlWriter); | 770 | renderSubParts(mp, htmlWriter); | ||
772 | } else if (!metaData.inProgress) { | 771 | } else if (!metaData.inProgress) { | ||
773 | auto part = renderWithFactory(QStringLiteral("MimeTreeParser::MessagePart"), mp); | 772 | renderWithFactory(QStringLiteral("MimeTreeParser::MessagePart"), mp, htmlWriter); | ||
774 | if (part) { | | |||
775 | htmlWriter->write(part->html()); | | |||
776 | } | | |||
777 | } | 773 | } | ||
778 | } | 774 | } | ||
779 | 775 | | |||
780 | void DefaultRendererPrivate::render(const EncryptedMessagePart::Ptr &mp, HtmlWriter *htmlWriter) | 776 | void DefaultRendererPrivate::render(const EncryptedMessagePart::Ptr &mp, HtmlWriter *htmlWriter) | ||
781 | { | 777 | { | ||
782 | const auto metaData = *mp->partMetaData(); | 778 | const auto metaData = *mp->partMetaData(); | ||
783 | 779 | | |||
784 | if (metaData.isEncrypted || metaData.inProgress) { | 780 | if (metaData.isEncrypted || metaData.inProgress) { | ||
785 | HTMLBlock::Ptr aBlock; | 781 | HTMLBlock::Ptr aBlock; | ||
786 | if (mp->isAttachment()) { | 782 | if (mp->isAttachment()) { | ||
787 | aBlock = HTMLBlock::Ptr(new AttachmentMarkBlock(htmlWriter, mp->attachmentContent())); | 783 | aBlock = HTMLBlock::Ptr(new AttachmentMarkBlock(htmlWriter, mp->attachmentContent())); | ||
788 | } | 784 | } | ||
789 | renderEncrypted(mp, htmlWriter); | 785 | renderEncrypted(mp, htmlWriter); | ||
790 | return; | 786 | return; | ||
791 | } | 787 | } | ||
792 | 788 | | |||
793 | HTMLBlock::Ptr aBlock; | 789 | HTMLBlock::Ptr aBlock; | ||
794 | if (mp->isAttachment()) { | 790 | if (mp->isAttachment()) { | ||
795 | aBlock = HTMLBlock::Ptr(new AttachmentMarkBlock(htmlWriter, mp->attachmentContent())); | 791 | aBlock = HTMLBlock::Ptr(new AttachmentMarkBlock(htmlWriter, mp->attachmentContent())); | ||
796 | } | 792 | } | ||
797 | 793 | | |||
798 | if (mp->hasSubParts()) { | 794 | if (mp->hasSubParts()) { | ||
799 | renderSubParts(mp, htmlWriter); | 795 | renderSubParts(mp, htmlWriter); | ||
800 | } else if (!metaData.inProgress) { | 796 | } else if (!metaData.inProgress) { | ||
801 | auto part = renderWithFactory(QStringLiteral("MimeTreeParser::MessagePart"), mp); | 797 | renderWithFactory(QStringLiteral("MimeTreeParser::MessagePart"), mp, htmlWriter); | ||
802 | if (part) { | | |||
803 | htmlWriter->write(part->html()); | | |||
804 | } | | |||
805 | } | 798 | } | ||
806 | } | 799 | } | ||
807 | 800 | | |||
808 | void DefaultRendererPrivate::render(const AlternativeMessagePart::Ptr &mp, HtmlWriter *htmlWriter) | 801 | void DefaultRendererPrivate::render(const AlternativeMessagePart::Ptr &mp, HtmlWriter *htmlWriter) | ||
809 | { | 802 | { | ||
810 | HTMLBlock::Ptr aBlock; | 803 | HTMLBlock::Ptr aBlock; | ||
811 | if (mp->isAttachment()) { | 804 | if (mp->isAttachment()) { | ||
812 | aBlock = HTMLBlock::Ptr(new AttachmentMarkBlock(htmlWriter, mp->attachmentContent())); | 805 | aBlock = HTMLBlock::Ptr(new AttachmentMarkBlock(htmlWriter, mp->attachmentContent())); | ||
▲ Show 20 Lines • Show All 46 Lines • ▼ Show 20 Line(s) | 826 | { | |||
859 | HTMLBlock::Ptr aBlock; | 852 | HTMLBlock::Ptr aBlock; | ||
860 | if (mp->isAttachment()) { | 853 | if (mp->isAttachment()) { | ||
861 | aBlock = HTMLBlock::Ptr(new AttachmentMarkBlock(htmlWriter, mp->attachmentContent())); | 854 | aBlock = HTMLBlock::Ptr(new AttachmentMarkBlock(htmlWriter, mp->attachmentContent())); | ||
862 | } | 855 | } | ||
863 | Grantlee::OutputStream s(htmlWriter->stream()); | 856 | Grantlee::OutputStream s(htmlWriter->stream()); | ||
864 | t->render(&s, &c); | 857 | t->render(&s, &c); | ||
865 | } | 858 | } | ||
866 | 859 | | |||
867 | QSharedPointer<PartRendered> DefaultRendererPrivate::renderWithFactory(QString className, const MessagePart::Ptr &msgPart) | 860 | bool DefaultRendererPrivate::renderWithFactory(const QString &className, const MessagePart::Ptr &msgPart, HtmlWriter *htmlWriter) | ||
868 | { | 861 | { | ||
869 | if (mRendererFactory) { | 862 | if (!mRendererFactory) | ||
863 | return false; | ||||
870 | const auto registry = mRendererFactory->typeRegistry(className); | 864 | const auto registry = mRendererFactory->typeRegistry(className); | ||
865 | if (registry.empty()) | ||||
866 | return false; | ||||
871 | 867 | | |||
872 | if (registry.size() > 0) { | | |||
873 | const auto plugin = registry.at(0); | 868 | const auto plugin = registry.at(0); | ||
knauss: we need a loop here to get all plugins. the registry.at(0) was just a shortcut to test my idea… | |||||
The loop is coming in the patch adding proper plugin handling (still WIP). Rewinding the stream to a defined restore point is possible if we need that, similar to what QIODevice::start/commit/rollbackTransaction do for the read direction. vkrause: The loop is coming in the patch adding proper plugin handling (still WIP).
Rewinding the… | |||||
I think rewinding the stream is really nessary, so that we have the control over what ends up in the stream. in future we may be not have control who is writing plugins and i think a bad plugin should not fuckup the whole rendering. knauss: I think rewinding the stream is really nessary, so that we have the control over what ends up… | |||||
Sure, we can do that whenever the problem arises. The old plugin interface was affected by the same issue, didn't seem to be a problem so far. vkrause: Sure, we can do that whenever the problem arises. The old plugin interface was affected by the… | |||||
874 | return plugin->render(this, msgPart); | 869 | return plugin->render(this, msgPart, htmlWriter); | ||
875 | } | | |||
876 | } | | |||
877 | | ||||
878 | return QSharedPointer<PartRendered>(); | | |||
879 | } | 870 | } | ||
880 | 871 | | |||
881 | QString DefaultRendererPrivate::renderFactory(const MessagePart::Ptr &msgPart, HtmlWriter *_htmlWriter) | 872 | QString DefaultRendererPrivate::renderFactory(const MessagePart::Ptr &msgPart, HtmlWriter *_htmlWriter) | ||
882 | { | 873 | { | ||
874 | auto htmlWriter = QSharedPointer<CacheHtmlWriter>(new CacheHtmlWriter(mOldWriter)); | ||||
883 | const QString className = QString::fromUtf8(msgPart->metaObject()->className()); | 875 | const QString className = QString::fromUtf8(msgPart->metaObject()->className()); | ||
884 | 876 | | |||
885 | const auto rendered = renderWithFactory(className, msgPart); | 877 | if (renderWithFactory(className, msgPart, htmlWriter.data())) | ||
886 | if (rendered) { | 878 | return htmlWriter->html(); | ||
887 | const auto parts = rendered->embededParts(); | | |||
888 | foreach (auto key, parts.keys()) { | | |||
889 | _htmlWriter->embedPart(key, parts.value(key)); | | |||
890 | } | | |||
891 | | ||||
892 | foreach (auto entry, rendered->extraHeader()) { | | |||
893 | _htmlWriter->extraHead(entry); | | |||
894 | } | | |||
895 | | ||||
896 | return rendered->html(); | | |||
897 | } | | |||
898 | 879 | | |||
899 | auto htmlWriter = QSharedPointer<CacheHtmlWriter>(new CacheHtmlWriter(mOldWriter)); | | |||
900 | if (className == QStringLiteral("MimeTreeParser::MessagePartList")) { | 880 | if (className == QStringLiteral("MimeTreeParser::MessagePartList")) { | ||
901 | auto mp = msgPart.dynamicCast<MessagePartList>(); | 881 | auto mp = msgPart.dynamicCast<MessagePartList>(); | ||
902 | if (mp) { | 882 | if (mp) { | ||
903 | render(mp, htmlWriter.data()); | 883 | render(mp, htmlWriter.data()); | ||
904 | } | 884 | } | ||
905 | } else if (className == QStringLiteral("MimeTreeParser::MimeMessagePart")) { | 885 | } else if (className == QStringLiteral("MimeTreeParser::MimeMessagePart")) { | ||
906 | auto mp = msgPart.dynamicCast<MimeMessagePart>(); | 886 | auto mp = msgPart.dynamicCast<MimeMessagePart>(); | ||
907 | if (mp) { | 887 | if (mp) { | ||
▲ Show 20 Lines • Show All 55 Lines • Show Last 20 Lines |
we need a loop here to get all plugins. the registry.at(0) was just a shortcut to test my idea ( but its outofscope here). But here the streaming api has a big disadvantage, because you need to trust, that the plugin don't write anything to htmlWriter if it don't handle the MessagePart otherwise things get messed up in htmlWriter. Or can you somehow seek the output again, when a plugin don't handle the part aka return false?