File indexing completed on 2025-03-09 04:54:35

0001 /*
0002    SPDX-FileCopyrightText: 2015 Sandro Knauß <sknauss@kde.org>
0003 
0004    SPDX-License-Identifier: LGPL-2.0-or-later
0005 */
0006 
0007 #include "htmlblock.h"
0008 
0009 #include "interfaces/htmlwriter.h"
0010 
0011 #include <KMime/Content>
0012 
0013 #include <QApplication>
0014 
0015 using namespace MessageViewer;
0016 
0017 HTMLBlock::HTMLBlock() = default;
0018 
0019 HTMLBlock::~HTMLBlock() = default;
0020 
0021 QString HTMLBlock::dir() const
0022 {
0023     return QApplication::isRightToLeft() ? QStringLiteral("rtl") : QStringLiteral("ltr");
0024 }
0025 
0026 QString HTMLBlock::enter()
0027 {
0028     if (!entered) {
0029         entered = true;
0030         return enterString();
0031     }
0032     return {};
0033 }
0034 
0035 QString HTMLBlock::exit()
0036 {
0037     if (entered) {
0038         entered = false;
0039         return exitString();
0040     }
0041     return {};
0042 }
0043 
0044 AttachmentMarkBlock::AttachmentMarkBlock(HtmlWriter *writer, KMime::Content *node)
0045     : mNode(node)
0046     , mWriter(writer)
0047 {
0048     internalEnter();
0049 }
0050 
0051 AttachmentMarkBlock::~AttachmentMarkBlock()
0052 {
0053     internalExit();
0054 }
0055 
0056 void AttachmentMarkBlock::internalEnter()
0057 {
0058     if (mWriter) {
0059         mWriter->write(enter());
0060     }
0061 }
0062 
0063 void AttachmentMarkBlock::internalExit()
0064 {
0065     if (mWriter) {
0066         mWriter->write(exit());
0067     }
0068 }
0069 
0070 QString AttachmentMarkBlock::enterString() const
0071 {
0072     const QString index = mNode->index().toString();
0073     return QStringLiteral("<a name=\"att%1\"></a>").arg(index) + QStringLiteral("<div id=\"attachmentDiv%1\">\n").arg(index);
0074 }
0075 
0076 QString AttachmentMarkBlock::exitString() const
0077 {
0078     return QStringLiteral("</div>");
0079 }
0080 
0081 RootBlock::RootBlock(HtmlWriter *writer)
0082     : HTMLBlock()
0083     , mWriter(writer)
0084 {
0085     internalEnter();
0086 }
0087 
0088 RootBlock::~RootBlock()
0089 {
0090     internalExit();
0091 }
0092 
0093 void RootBlock::internalEnter()
0094 {
0095     if (mWriter) {
0096         mWriter->write(enter());
0097     }
0098 }
0099 
0100 void RootBlock::internalExit()
0101 {
0102     if (mWriter) {
0103         mWriter->write(exit());
0104     }
0105 }
0106 
0107 QString RootBlock::enterString() const
0108 {
0109     return QStringLiteral("<div style=\"position: relative; word-wrap: break-word\">\n");
0110 }
0111 
0112 QString RootBlock::exitString() const
0113 {
0114     return QStringLiteral("</div>\n");
0115 }