summaryrefslogtreecommitdiffstats
path: root/framework/src/domain/mimetreeparser/otp/filehtmlwriter.cpp
diff options
context:
space:
mode:
authorChristian Mollekopf <chrigi_1@fastmail.fm>2017-05-23 19:13:13 +0200
committerChristian Mollekopf <chrigi_1@fastmail.fm>2017-05-23 19:13:13 +0200
commitb968ea8ed364238c57c3e74cf2c122cb897cfbea (patch)
tree7a2dca2199906413a2d0b7d075ded0e4d5ffb69f /framework/src/domain/mimetreeparser/otp/filehtmlwriter.cpp
parentc1ca732bafc60f5c140ef5516e32bd46503bf68c (diff)
downloadkube-b968ea8ed364238c57c3e74cf2c122cb897cfbea.tar.gz
kube-b968ea8ed364238c57c3e74cf2c122cb897cfbea.zip
Builds but doesn't link, no formatters yet
Diffstat (limited to 'framework/src/domain/mimetreeparser/otp/filehtmlwriter.cpp')
-rw-r--r--framework/src/domain/mimetreeparser/otp/filehtmlwriter.cpp119
1 files changed, 119 insertions, 0 deletions
diff --git a/framework/src/domain/mimetreeparser/otp/filehtmlwriter.cpp b/framework/src/domain/mimetreeparser/otp/filehtmlwriter.cpp
new file mode 100644
index 00000000..a143f944
--- /dev/null
+++ b/framework/src/domain/mimetreeparser/otp/filehtmlwriter.cpp
@@ -0,0 +1,119 @@
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 "filehtmlwriter.h"
33
34#include "mimetreeparser_debug.h"
35
36namespace MimeTreeParser
37{
38
39FileHtmlWriter::FileHtmlWriter(const QString &filename)
40 : HtmlWriter(),
41 mFile(filename.isEmpty() ? QStringLiteral("filehtmlwriter.out") : filename)
42{
43}
44
45FileHtmlWriter::~FileHtmlWriter()
46{
47 if (mFile.isOpen()) {
48 qCWarning(MIMETREEPARSER_LOG) << "FileHtmlWriter: file still open!";
49 mStream.setDevice(nullptr);
50 mFile.close();
51 }
52}
53
54void FileHtmlWriter::begin(const QString &css)
55{
56 openOrWarn();
57 if (!css.isEmpty()) {
58 write(QLatin1String("<!-- CSS Definitions \n") + css + QLatin1String("-->\n"));
59 }
60}
61
62void FileHtmlWriter::end()
63{
64 flush();
65 mStream.setDevice(nullptr);
66 mFile.close();
67}
68
69void FileHtmlWriter::reset()
70{
71 if (mFile.isOpen()) {
72 mStream.setDevice(nullptr);
73 mFile.close();
74 }
75}
76
77void FileHtmlWriter::write(const QString &str)
78{
79 mStream << str;
80 flush();
81}
82
83void FileHtmlWriter::queue(const QString &str)
84{
85 write(str);
86}
87
88void FileHtmlWriter::flush()
89{
90 mStream.flush();
91 mFile.flush();
92}
93
94void FileHtmlWriter::openOrWarn()
95{
96 if (mFile.isOpen()) {
97 qCWarning(MIMETREEPARSER_LOG) << "FileHtmlWriter: file still open!";
98 mStream.setDevice(nullptr);
99 mFile.close();
100 }
101 if (!mFile.open(QIODevice::WriteOnly)) {
102 qCWarning(MIMETREEPARSER_LOG) << "FileHtmlWriter: Cannot open file" << mFile.fileName();
103 } else {
104 mStream.setDevice(&mFile);
105 mStream.setCodec("UTF-8");
106 }
107}
108
109void FileHtmlWriter::embedPart(const QByteArray &contentId, const QString &url)
110{
111 mStream << "<!-- embedPart(contentID=" << contentId << ", url=" << url << ") -->" << endl;
112 flush();
113}
114void FileHtmlWriter::extraHead(const QString &)
115{
116
117}
118
119} //