Messagelib

htmlblock.cpp
1 /*
2  SPDX-FileCopyrightText: 2015 Sandro Knauß <[email protected]>
3 
4  SPDX-License-Identifier: LGPL-2.0-or-later
5 */
6 
7 #include "htmlblock.h"
8 
9 #include "interfaces/htmlwriter.h"
10 
11 #include <KMime/Content>
12 
13 #include <QApplication>
14 
15 using namespace MessageViewer;
16 
17 HTMLBlock::HTMLBlock() = default;
18 
19 HTMLBlock::~HTMLBlock() = default;
20 
21 QString HTMLBlock::dir() const
22 {
23  return QApplication::isRightToLeft() ? QStringLiteral("rtl") : QStringLiteral("ltr");
24 }
25 
26 QString HTMLBlock::enter()
27 {
28  if (!entered) {
29  entered = true;
30  return enterString();
31  }
32  return {};
33 }
34 
35 QString HTMLBlock::exit()
36 {
37  if (entered) {
38  entered = false;
39  return exitString();
40  }
41  return {};
42 }
43 
44 AttachmentMarkBlock::AttachmentMarkBlock(HtmlWriter *writer, KMime::Content *node)
45  : mNode(node)
46  , mWriter(writer)
47 {
48  internalEnter();
49 }
50 
51 AttachmentMarkBlock::~AttachmentMarkBlock()
52 {
53  internalExit();
54 }
55 
56 void AttachmentMarkBlock::internalEnter()
57 {
58  if (mWriter) {
59  mWriter->write(enter());
60  }
61 }
62 
63 void AttachmentMarkBlock::internalExit()
64 {
65  if (mWriter) {
66  mWriter->write(exit());
67  }
68 }
69 
70 QString AttachmentMarkBlock::enterString() const
71 {
72  const QString index = mNode->index().toString();
73  return QStringLiteral("<a name=\"att%1\"></a>").arg(index) + QStringLiteral("<div id=\"attachmentDiv%1\">\n").arg(index);
74 }
75 
76 QString AttachmentMarkBlock::exitString() const
77 {
78  return QStringLiteral("</div>");
79 }
80 
81 RootBlock::RootBlock(HtmlWriter *writer)
82  : HTMLBlock()
83  , mWriter(writer)
84 {
85  internalEnter();
86 }
87 
88 RootBlock::~RootBlock()
89 {
90  internalExit();
91 }
92 
93 void RootBlock::internalEnter()
94 {
95  if (mWriter) {
96  mWriter->write(enter());
97  }
98 }
99 
100 void RootBlock::internalExit()
101 {
102  if (mWriter) {
103  mWriter->write(exit());
104  }
105 }
106 
107 QString RootBlock::enterString() const
108 {
109  return QStringLiteral("<div style=\"position: relative; word-wrap: break-word\">\n");
110 }
111 
112 QString RootBlock::exitString() const
113 {
114  return QStringLiteral("</div>\n");
115 }
void write(const QString &html)
Write out a chunk of text.
Definition: htmlwriter.cpp:27
ContentIndex index() const
QString toString() const
The HTMLBlock class.
Definition: htmlblock.h:25
bool isRightToLeft()
An interface for HTML sinks.
Definition: htmlwriter.h:28
QString arg(qlonglong a, int fieldWidth, int base, QChar fillChar) const const
This file is part of the KDE documentation.
Documentation copyright © 1996-2023 The KDE developers.
Generated on Wed Mar 22 2023 04:07:14 by doxygen 1.8.17 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.