diff options
author | Christian Mollekopf <chrigi_1@fastmail.fm> | 2016-01-21 11:36:43 +0100 |
---|---|---|
committer | Christian Mollekopf <chrigi_1@fastmail.fm> | 2016-01-21 11:36:43 +0100 |
commit | bf96cfa0d75d256e036c76ec64f0f456014f2739 (patch) | |
tree | 3ab0ff603dfccb9f28040af3a1559b01af09aa3f /framework/mail/stringhtmlwriter.cpp | |
parent | e4e11ba46f4ccce5f9ca63ab758a132d945061e8 (diff) | |
parent | 9a3059769a0bf9dbf81e523c9245d2aa98420bb5 (diff) | |
download | kube-bf96cfa0d75d256e036c76ec64f0f456014f2739.tar.gz kube-bf96cfa0d75d256e036c76ec64f0f456014f2739.zip |
Merge remote-tracking branch 'origin/dev/libotp' into develop
Conflicts:
framework/mail/CMakeLists.txt
Diffstat (limited to 'framework/mail/stringhtmlwriter.cpp')
-rw-r--r-- | framework/mail/stringhtmlwriter.cpp | 134 |
1 files changed, 134 insertions, 0 deletions
diff --git a/framework/mail/stringhtmlwriter.cpp b/framework/mail/stringhtmlwriter.cpp new file mode 100644 index 00000000..2c84dc6f --- /dev/null +++ b/framework/mail/stringhtmlwriter.cpp | |||
@@ -0,0 +1,134 @@ | |||
1 | /* -*- c++ -*- | ||
2 | filehtmlwriter.cpp | ||
3 | |||
4 | This file is part of KMail, the KDE mail client. | ||
5 | Copyright (c) 2003 Marc Mutz <mutz@kde.org> | ||
6 | |||
7 | KMail is free software; you can redistribute it and/or modify it | ||
8 | under the terms of the GNU General Public License, version 2, as | ||
9 | published by the Free Software Foundation. | ||
10 | |||
11 | KMail is distributed in the hope that it will be useful, but | ||
12 | WITHOUT ANY WARRANTY; without even the implied warranty of | ||
13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
14 | General Public License for more details. | ||
15 | |||
16 | You should have received a copy of the GNU General Public License | ||
17 | along with this program; if not, write to the Free Software | ||
18 | Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA | ||
19 | |||
20 | In addition, as a special exception, the copyright holders give | ||
21 | permission to link the code of this program with any edition of | ||
22 | the Qt library by Trolltech AS, Norway (or with modified versions | ||
23 | of Qt that use the same license as Qt), and distribute linked | ||
24 | combinations including the two. You must obey the GNU General | ||
25 | Public License in all respects for all of the code used other than | ||
26 | Qt. If you modify this file, you may extend this exception to | ||
27 | your version of the file, but you are not obligated to do so. If | ||
28 | you do not wish to do so, delete this exception statement from | ||
29 | your version. | ||
30 | */ | ||
31 | |||
32 | #include "stringhtmlwriter.h" | ||
33 | |||
34 | #include <QDebug> | ||
35 | #include <QTextStream> | ||
36 | |||
37 | StringHtmlWriter::StringHtmlWriter() | ||
38 | : MessageViewer::HtmlWriter() | ||
39 | , mState(Ended) | ||
40 | { | ||
41 | } | ||
42 | |||
43 | StringHtmlWriter::~StringHtmlWriter() | ||
44 | { | ||
45 | } | ||
46 | |||
47 | void StringHtmlWriter::begin(const QString &css) | ||
48 | { | ||
49 | if (mState != Ended) { | ||
50 | qWarning() << "begin() called on non-ended session!"; | ||
51 | reset(); | ||
52 | } | ||
53 | |||
54 | mState = Begun; | ||
55 | mExtraHead.clear(); | ||
56 | mHtml.clear(); | ||
57 | |||
58 | if (!css.isEmpty()) { | ||
59 | write(QLatin1String("<!-- CSS Definitions \n") + css + QLatin1String("-->\n")); | ||
60 | } | ||
61 | } | ||
62 | |||
63 | void StringHtmlWriter::end() | ||
64 | { | ||
65 | if (mState != Begun) { | ||
66 | qWarning() << "Called on non-begun or queued session!"; | ||
67 | } | ||
68 | |||
69 | if (!mExtraHead.isEmpty()) { | ||
70 | insertExtraHead(); | ||
71 | mExtraHead.clear(); | ||
72 | } | ||
73 | mState = Ended; | ||
74 | } | ||
75 | |||
76 | void StringHtmlWriter::reset() | ||
77 | { | ||
78 | if (mState != Ended) { | ||
79 | mHtml.clear(); | ||
80 | mExtraHead.clear(); | ||
81 | mState = Begun; // don't run into end()'s warning | ||
82 | end(); | ||
83 | mState = Ended; | ||
84 | } | ||
85 | } | ||
86 | |||
87 | void StringHtmlWriter::write(const QString &str) | ||
88 | { | ||
89 | if (mState != Begun) { | ||
90 | qWarning() << "Called in Ended or Queued state!"; | ||
91 | } | ||
92 | mHtml.append(str); | ||
93 | } | ||
94 | |||
95 | void StringHtmlWriter::queue(const QString &str) | ||
96 | { | ||
97 | write(str); | ||
98 | } | ||
99 | |||
100 | void StringHtmlWriter::flush() | ||
101 | { | ||
102 | mState = Begun; // don't run into end()'s warning | ||
103 | end(); | ||
104 | } | ||
105 | |||
106 | void StringHtmlWriter::embedPart(const QByteArray &contentId, const QString &url) | ||
107 | { | ||
108 | write("<!-- embedPart(contentID=" + contentId + ", url=" + url + ") -->\n"); | ||
109 | } | ||
110 | void StringHtmlWriter::extraHead(const QString &extraHead) | ||
111 | { | ||
112 | if (mState != Ended) { | ||
113 | qWarning() << "Called on non-started session!"; | ||
114 | } | ||
115 | mExtraHead.append(extraHead); | ||
116 | } | ||
117 | |||
118 | |||
119 | void StringHtmlWriter::insertExtraHead() | ||
120 | { | ||
121 | const QString headTag(QStringLiteral("<head>")); | ||
122 | const int index = mHtml.indexOf(headTag); | ||
123 | if (index != -1) { | ||
124 | mHtml.insert(index + headTag.length(), mExtraHead); | ||
125 | } | ||
126 | } | ||
127 | |||
128 | QString StringHtmlWriter::html() const | ||
129 | { | ||
130 | if (mState != Ended) { | ||
131 | qWarning() << "Called on non-ended session!"; | ||
132 | } | ||
133 | return mHtml; | ||
134 | } | ||