Changeset View
Changeset View
Standalone View
Standalone View
messageviewer/src/htmlwriter/queuehtmlwriter.cpp
- This file was added.
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 "messageviewer_debug.h" | ||||
23 | | ||||
24 | #include<QByteArray> | ||||
25 | #include<QString> | ||||
26 | | ||||
27 | using namespace MessageViewer; | ||||
28 | | ||||
29 | QueueHtmlWriter::QueueHtmlWriter(HtmlWriter *base) | ||||
30 | : HtmlWriter() | ||||
31 | , mBase(base) | ||||
32 | { | ||||
33 | } | ||||
34 | | ||||
35 | QueueHtmlWriter::~QueueHtmlWriter() | ||||
36 | { | ||||
37 | } | ||||
38 | | ||||
39 | void QueueHtmlWriter::begin(const QString &css) | ||||
40 | { | ||||
41 | Command cmd; | ||||
42 | cmd.type = Command::Begin; | ||||
43 | cmd.s = css; | ||||
44 | mQueue.append(cmd); | ||||
45 | } | ||||
46 | | ||||
47 | void QueueHtmlWriter::end() | ||||
48 | { | ||||
49 | Command cmd; | ||||
50 | cmd.type = Command::End; | ||||
51 | mQueue.append(cmd); | ||||
52 | } | ||||
53 | | ||||
54 | void QueueHtmlWriter::reset() | ||||
55 | { | ||||
56 | Command cmd; | ||||
57 | cmd.type = Command::Reset; | ||||
58 | mQueue.append(cmd); | ||||
59 | } | ||||
60 | | ||||
61 | void QueueHtmlWriter::write(const QString &str) | ||||
62 | { | ||||
63 | Command cmd; | ||||
64 | cmd.type = Command::Write; | ||||
65 | cmd.s = str; | ||||
66 | mQueue.append(cmd); | ||||
67 | } | ||||
68 | | ||||
69 | void QueueHtmlWriter::queue(const QString &str) | ||||
70 | { | ||||
71 | Command cmd; | ||||
72 | cmd.type = Command::Queue; | ||||
73 | cmd.s = str; | ||||
74 | mQueue.append(cmd); | ||||
75 | } | ||||
76 | | ||||
77 | void QueueHtmlWriter::flush() | ||||
78 | { | ||||
79 | Command cmd; | ||||
80 | cmd.type = Command::Flush; | ||||
81 | mQueue.append(cmd); | ||||
82 | } | ||||
83 | | ||||
84 | void QueueHtmlWriter::replay() | ||||
85 | { | ||||
86 | foreach(auto entry, mQueue) | ||||
87 | { | ||||
88 | switch(entry.type) { | ||||
89 | case Command::Begin: | ||||
90 | mBase->begin(entry.s); | ||||
91 | break; | ||||
92 | case Command::End: | ||||
93 | mBase->end(); | ||||
94 | break; | ||||
95 | case Command::Reset: | ||||
96 | mBase->reset(); | ||||
97 | break; | ||||
98 | case Command::Write: | ||||
99 | mBase->write(entry.s); | ||||
100 | break; | ||||
101 | case Command::Queue: | ||||
102 | mBase->queue(entry.s); | ||||
103 | break; | ||||
104 | case Command::Flush: | ||||
105 | mBase->flush(); | ||||
106 | break; | ||||
107 | case Command::EmbedPart: | ||||
108 | mBase->embedPart(entry.b, entry.s); | ||||
109 | break; | ||||
110 | case Command::ExtraHead: | ||||
111 | mBase->extraHead(entry.s); | ||||
112 | break; | ||||
113 | } | ||||
114 | } | ||||
115 | } | ||||
116 | | ||||
117 | void QueueHtmlWriter::embedPart(const QByteArray &contentId, const QString &url) | ||||
118 | { | ||||
119 | Command cmd; | ||||
120 | cmd.type = Command::EmbedPart; | ||||
121 | cmd.s = url; | ||||
122 | cmd.b = contentId; | ||||
123 | mQueue.append(cmd); | ||||
124 | } | ||||
125 | void QueueHtmlWriter::extraHead(const QString &extra) | ||||
126 | { | ||||
127 | Command cmd; | ||||
128 | cmd.type = Command::ExtraHead; | ||||
129 | cmd.s = extra; | ||||
130 | mQueue.append(cmd); | ||||
131 | } | ||||
132 | No newline at end of file |