File indexing completed on 2025-03-09 04:54:40
0001 /* 0002 SPDX-FileCopyrightText: 2009 Klarälvdalens Datakonsult AB, a KDAB Group company, info@kdab.net 0003 SPDX-FileCopyrightText: 2009 Andras Mantia <andras@kdab.net> 0004 0005 SPDX-License-Identifier: GPL-2.0-or-later 0006 */ 0007 0008 #include "objecttreeemptysource.h" 0009 #include "viewer/attachmentstrategy.h" 0010 #include "viewer/csshelperbase.h" 0011 #include "viewer/viewer_p.h" 0012 0013 #include <MimeTreeParser/BodyPartFormatter> 0014 #include <MimeTreeParser/BodyPartFormatterFactory> 0015 0016 #include "messagepartthemes/default/defaultrenderer.h" 0017 0018 #include "messageviewer_debug.h" 0019 0020 using namespace MessageViewer; 0021 0022 namespace MessageViewer 0023 { 0024 class EmptySourcePrivate 0025 { 0026 public: 0027 EmptySourcePrivate() = default; 0028 0029 bool mAllowDecryption = false; 0030 }; 0031 } 0032 0033 EmptySource::EmptySource() 0034 : MimeTreeParser::Interface::ObjectTreeSource() 0035 , d(new MessageViewer::EmptySourcePrivate) 0036 { 0037 } 0038 0039 EmptySource::~EmptySource() = default; 0040 0041 bool EmptySource::decryptMessage() const 0042 { 0043 return d->mAllowDecryption; 0044 } 0045 0046 bool EmptySource::htmlLoadExternal() const 0047 { 0048 return false; 0049 } 0050 0051 void EmptySource::setHtmlMode(MimeTreeParser::Util::HtmlMode mode, const QList<MimeTreeParser::Util::HtmlMode> &availableModes) 0052 { 0053 Q_UNUSED(mode) 0054 Q_UNUSED(availableModes) 0055 } 0056 0057 MimeTreeParser::Util::HtmlMode EmptySource::preferredMode() const 0058 { 0059 return MimeTreeParser::Util::Html; 0060 } 0061 0062 void EmptySource::setAllowDecryption(bool allowDecryption) 0063 { 0064 d->mAllowDecryption = allowDecryption; 0065 } 0066 0067 QByteArray EmptySource::overrideCodecName() const 0068 { 0069 return {}; 0070 } 0071 0072 QString EmptySource::createMessageHeader(KMime::Message *message) 0073 { 0074 Q_UNUSED(message) 0075 return {}; // do nothing 0076 } 0077 0078 const AttachmentStrategy *EmptySource::attachmentStrategy() const 0079 { 0080 return AttachmentStrategy::smart(); 0081 } 0082 0083 HtmlWriter *EmptySource::htmlWriter() const 0084 { 0085 return nullptr; 0086 } 0087 0088 CSSHelperBase *EmptySource::cssHelper() const 0089 { 0090 return nullptr; 0091 } 0092 0093 bool EmptySource::autoImportKeys() const 0094 { 0095 return true; 0096 } 0097 0098 const MimeTreeParser::BodyPartFormatterFactory *EmptySource::bodyPartFormatterFactory() 0099 { 0100 return MimeTreeParser::BodyPartFormatterFactory::instance(); 0101 } 0102 0103 void EmptySource::render(const MimeTreeParser::MessagePartPtr &msgPart, bool showOnlyOneMimePart) 0104 { 0105 if (!htmlWriter()) { 0106 qCWarning(MESSAGEVIEWER_LOG) << "no htmlWriter - skipping rendering."; 0107 return; 0108 } 0109 0110 auto renderer = DefaultRenderer(cssHelper()); 0111 renderer.setAttachmentStrategy(attachmentStrategy()); 0112 renderer.setCreateMessageHeader(std::bind(&EmptySource::createMessageHeader, this, std::placeholders::_1)); 0113 renderer.setHtmlLoadExternal(htmlLoadExternal()); 0114 renderer.setIsPrinting(isPrinting()); 0115 renderer.setLevelQuote(levelQuote()); 0116 renderer.setShowEmoticons(showEmoticons()); 0117 renderer.setShowExpandQuotesMark(showExpandQuotesMark()); 0118 renderer.setShowOnlyOneMimePart(showOnlyOneMimePart); 0119 renderer.setShowSignatureDetails(showSignatureDetails()); 0120 renderer.setShowEncryptionDetails(showEncryptionDetails()); 0121 0122 renderer.render(msgPart, htmlWriter()); 0123 } 0124 0125 bool EmptySource::isPrinting() const 0126 { 0127 return false; 0128 } 0129 0130 bool EmptySource::showEmoticons() const 0131 { 0132 return false; 0133 } 0134 0135 bool EmptySource::showExpandQuotesMark() const 0136 { 0137 return false; 0138 } 0139 0140 bool EmptySource::showSignatureDetails() const 0141 { 0142 return false; 0143 } 0144 0145 bool EmptySource::showEncryptionDetails() const 0146 { 0147 return false; 0148 } 0149 0150 int EmptySource::levelQuote() const 0151 { 0152 return 1; 0153 }