summaryrefslogtreecommitdiffstats
path: root/framework/src/domain/mimetreeparser/otp/queuehtmlwriter.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'framework/src/domain/mimetreeparser/otp/queuehtmlwriter.cpp')
-rw-r--r--framework/src/domain/mimetreeparser/otp/queuehtmlwriter.cpp136
1 files changed, 136 insertions, 0 deletions
diff --git a/framework/src/domain/mimetreeparser/otp/queuehtmlwriter.cpp b/framework/src/domain/mimetreeparser/otp/queuehtmlwriter.cpp
new file mode 100644
index 00000000..ea17bf5c
--- /dev/null
+++ b/framework/src/domain/mimetreeparser/otp/queuehtmlwriter.cpp
@@ -0,0 +1,136 @@
1/*
2 Copyright (c) 2015 Sandro Knauß <sknauss@kde.org>
3
4 This library is free software; you can redistribute it and/or modify it
5 under the terms of the GNU Library General Public License as published by
6 the Free Software Foundation; either version 2 of the License, or (at your
7 option) any later version.
8
9 This library is distributed in the hope that it will be useful, but WITHOUT
10 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public
12 License for more details.
13
14 You should have received a copy of the GNU Library General Public License
15 along with this library; see the file COPYING.LIB. If not, write to the
16 Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
17 02110-1301, USA.
18*/
19
20#include "queuehtmlwriter.h"
21
22#include "mimetreeparser_debug.h"
23
24#include<QByteArray>
25#include<QString>
26
27using namespace MimeTreeParser;
28
29QueueHtmlWriter::QueueHtmlWriter(HtmlWriter *base)
30 : HtmlWriter()
31 , mBase(base)
32{
33}
34
35QueueHtmlWriter::~QueueHtmlWriter()
36{
37}
38
39void QueueHtmlWriter::setBase(HtmlWriter *base)
40{
41 mBase = base;
42}
43
44void QueueHtmlWriter::begin(const QString &css)
45{
46 Command cmd;
47 cmd.type = Command::Begin;
48 cmd.s = css;
49 mQueue.append(cmd);
50}
51
52void QueueHtmlWriter::end()
53{
54 Command cmd;
55 cmd.type = Command::End;
56 mQueue.append(cmd);
57}
58
59void QueueHtmlWriter::reset()
60{
61 Command cmd;
62 cmd.type = Command::Reset;
63 mQueue.append(cmd);
64}
65
66void QueueHtmlWriter::write(const QString &str)
67{
68 Command cmd;
69 cmd.type = Command::Write;
70 cmd.s = str;
71 mQueue.append(cmd);
72}
73
74void QueueHtmlWriter::queue(const QString &str)
75{
76 Command cmd;
77 cmd.type = Command::Queue;
78 cmd.s = str;
79 mQueue.append(cmd);
80}
81
82void QueueHtmlWriter::flush()
83{
84 Command cmd;
85 cmd.type = Command::Flush;
86 mQueue.append(cmd);
87}
88
89void QueueHtmlWriter::replay()
90{
91 foreach (const auto &entry, mQueue) {
92 switch (entry.type) {
93 case Command::Begin:
94 mBase->begin(entry.s);
95 break;
96 case Command::End:
97 mBase->end();
98 break;
99 case Command::Reset:
100 mBase->reset();
101 break;
102 case Command::Write:
103 mBase->write(entry.s);
104 break;
105 case Command::Queue:
106 mBase->queue(entry.s);
107 break;
108 case Command::Flush:
109 mBase->flush();
110 break;
111 case Command::EmbedPart:
112 mBase->embedPart(entry.b, entry.s);
113 break;
114 case Command::ExtraHead:
115 mBase->extraHead(entry.s);
116 break;
117 }
118 }
119}
120
121void QueueHtmlWriter::embedPart(const QByteArray &contentId, const QString &url)
122{
123 Command cmd;
124 cmd.type = Command::EmbedPart;
125 cmd.s = url;
126 cmd.b = contentId;
127 mQueue.append(cmd);
128}
129void QueueHtmlWriter::extraHead(const QString &extra)
130{
131 Command cmd;
132 cmd.type = Command::ExtraHead;
133 cmd.s = extra;
134 mQueue.append(cmd);
135}
136