author | ulf69 <ulf69> | 2004-09-29 01:42:40 (UTC) |
---|---|---|
committer | ulf69 <ulf69> | 2004-09-29 01:42:40 (UTC) |
commit | af63a131d742aff8e448e5fe0f3e62b11a4d9a33 (patch) (unidiff) | |
tree | 2b299c6a4b365bf938c7b6269cd51bf38b0d9d99 | |
parent | bb0e15259ccb1883410435ad76eb0de08b7e2069 (diff) | |
download | kdepimpi-af63a131d742aff8e448e5fe0f3e62b11a4d9a33.zip kdepimpi-af63a131d742aff8e448e5fe0f3e62b11a4d9a33.tar.gz kdepimpi-af63a131d742aff8e448e5fe0f3e62b11a4d9a33.tar.bz2 |
added some debug output
-rw-r--r-- | pwmanager/pwmanager/serializer.cpp | 2 |
1 files changed, 1 insertions, 1 deletions
diff --git a/pwmanager/pwmanager/serializer.cpp b/pwmanager/pwmanager/serializer.cpp index fcdcec3..9377e3d 100644 --- a/pwmanager/pwmanager/serializer.cpp +++ b/pwmanager/pwmanager/serializer.cpp | |||
@@ -1,677 +1,677 @@ | |||
1 | /*************************************************************************** | 1 | /*************************************************************************** |
2 | * * | 2 | * * |
3 | * copyright (C) 2004 by Michael Buesch * | 3 | * copyright (C) 2004 by Michael Buesch * |
4 | * email: mbuesch@freenet.de * | 4 | * email: mbuesch@freenet.de * |
5 | * * | 5 | * * |
6 | * This program is free software; you can redistribute it and/or modify * | 6 | * This program is free software; you can redistribute it and/or modify * |
7 | * it under the terms of the GNU General Public License version 2 * | 7 | * it under the terms of the GNU General Public License version 2 * |
8 | * as published by the Free Software Foundation. * | 8 | * as published by the Free Software Foundation. * |
9 | * * | 9 | * * |
10 | ***************************************************************************/ | 10 | ***************************************************************************/ |
11 | 11 | ||
12 | 12 | ||
13 | /*************************************************************************** | 13 | /*************************************************************************** |
14 | * copyright (C) 2004 by Ulf Schenk | 14 | * copyright (C) 2004 by Ulf Schenk |
15 | * This file is originaly based on version 2.0 of pwmanager | 15 | * This file is originaly based on version 2.0 of pwmanager |
16 | * and was modified to run on embedded devices that run microkde | 16 | * and was modified to run on embedded devices that run microkde |
17 | * | 17 | * |
18 | * $Id$ | 18 | * $Id$ |
19 | **************************************************************************/ | 19 | **************************************************************************/ |
20 | 20 | ||
21 | #include "serializer.h" | 21 | #include "serializer.h" |
22 | #include "pwmexception.h" | 22 | #include "pwmexception.h" |
23 | 23 | ||
24 | #ifdef PWM_EMBEDDED | 24 | #ifdef PWM_EMBEDDED |
25 | #include <kglobal.h> | 25 | #include <kglobal.h> |
26 | #include <klocale.h> | 26 | #include <klocale.h> |
27 | #endif | 27 | #endif |
28 | 28 | ||
29 | /* enable/disable serializer debugging (0/1) */ | 29 | /* enable/disable serializer debugging (0/1) */ |
30 | #define SERIALIZER_DEBUG1 | 30 | #define SERIALIZER_DEBUG1 |
31 | /* use the old xml tags for writing (0/1) */ | 31 | /* use the old xml tags for writing (0/1) */ |
32 | #define USE_OLD_TAGS 0 | 32 | #define USE_OLD_TAGS 0 |
33 | /* write a CDATA section (0/1) */ | 33 | /* write a CDATA section (0/1) */ |
34 | #define WRITE_CDATA_SEC 0 | 34 | #define WRITE_CDATA_SEC 0 |
35 | 35 | ||
36 | 36 | ||
37 | #define META_CREATE_DATE"c" | 37 | #define META_CREATE_DATE"c" |
38 | #define META_VALID_DATE "v" | 38 | #define META_VALID_DATE "v" |
39 | #define META_EXPIRE_DATE"e" | 39 | #define META_EXPIRE_DATE"e" |
40 | #define META_UPDATE_DATE"u" | 40 | #define META_UPDATE_DATE"u" |
41 | #define META_UPDATE_INT "i" | 41 | #define META_UPDATE_INT "i" |
42 | //US ENH : uniqueid | 42 | //US ENH : uniqueid |
43 | #define META_UNIQUEID "n" | 43 | #define META_UNIQUEID "n" |
44 | 44 | ||
45 | /* This is compatibility stuff. | 45 | /* This is compatibility stuff. |
46 | * The names of the entries have changed and here are the | 46 | * The names of the entries have changed and here are the |
47 | * new and old ones | 47 | * new and old ones |
48 | */ | 48 | */ |
49 | #define ROOT_MAGIC_OLD "PwM-xml-dat" | 49 | #define ROOT_MAGIC_OLD "PwM-xml-dat" |
50 | #define VER_STR_OLD "ver" | 50 | #define VER_STR_OLD "ver" |
51 | #define COMPAT_VER_OLD "0x02" | 51 | #define COMPAT_VER_OLD "0x02" |
52 | #define CAT_ROOT_OLD "categories" | 52 | #define CAT_ROOT_OLD "categories" |
53 | #define CAT_PREFIX_OLD "cat_" | 53 | #define CAT_PREFIX_OLD "cat_" |
54 | #define CAT_NAME_OLD "name" | 54 | #define CAT_NAME_OLD "name" |
55 | #define ENTRY_PREFIX_OLD"entry_" | 55 | #define ENTRY_PREFIX_OLD"entry_" |
56 | #define ENTRY_DESC_OLD "desc" | 56 | #define ENTRY_DESC_OLD "desc" |
57 | #define ENTRY_NAME_OLD "name" | 57 | #define ENTRY_NAME_OLD "name" |
58 | #define ENTRY_PW_OLD "pw" | 58 | #define ENTRY_PW_OLD "pw" |
59 | #define ENTRY_COMMENT_OLD"comment" | 59 | #define ENTRY_COMMENT_OLD"comment" |
60 | #define ENTRY_URL_OLD "url" | 60 | #define ENTRY_URL_OLD "url" |
61 | #define ENTRY_LAUNCHER_OLD"launcher" | 61 | #define ENTRY_LAUNCHER_OLD"launcher" |
62 | #define ENTRY_LVP_OLD "listViewPos" | 62 | #define ENTRY_LVP_OLD "listViewPos" |
63 | #define ENTRY_BIN_OLD "b" | 63 | #define ENTRY_BIN_OLD "b" |
64 | #define ENTRY_META_OLD "m" | 64 | #define ENTRY_META_OLD "m" |
65 | 65 | ||
66 | #define ROOT_MAGIC_NEW "P" | 66 | #define ROOT_MAGIC_NEW "P" |
67 | #define VER_STR_NEW "v" | 67 | #define VER_STR_NEW "v" |
68 | #define COMPAT_VER_NEW "2" | 68 | #define COMPAT_VER_NEW "2" |
69 | #define CAT_ROOT_NEW "c" | 69 | #define CAT_ROOT_NEW "c" |
70 | #define CAT_PREFIX_NEW "c" | 70 | #define CAT_PREFIX_NEW "c" |
71 | #define CAT_NAME_NEW "n" | 71 | #define CAT_NAME_NEW "n" |
72 | #define ENTRY_PREFIX_NEW"e" | 72 | #define ENTRY_PREFIX_NEW"e" |
73 | #define ENTRY_DESC_NEW "d" | 73 | #define ENTRY_DESC_NEW "d" |
74 | #define ENTRY_NAME_NEW "n" | 74 | #define ENTRY_NAME_NEW "n" |
75 | #define ENTRY_PW_NEW "p" | 75 | #define ENTRY_PW_NEW "p" |
76 | #define ENTRY_COMMENT_NEW"c" | 76 | #define ENTRY_COMMENT_NEW"c" |
77 | #define ENTRY_URL_NEW "u" | 77 | #define ENTRY_URL_NEW "u" |
78 | #define ENTRY_LAUNCHER_NEW"l" | 78 | #define ENTRY_LAUNCHER_NEW"l" |
79 | #define ENTRY_LVP_NEW "v" | 79 | #define ENTRY_LVP_NEW "v" |
80 | #define ENTRY_BIN_NEW ENTRY_BIN_OLD | 80 | #define ENTRY_BIN_NEW ENTRY_BIN_OLD |
81 | #define ENTRY_META_NEW ENTRY_META_OLD | 81 | #define ENTRY_META_NEW ENTRY_META_OLD |
82 | 82 | ||
83 | #if USE_OLD_TAGS != 0 | 83 | #if USE_OLD_TAGS != 0 |
84 | # define ROOT_MAGIC_WR ROOT_MAGIC_OLD | 84 | # define ROOT_MAGIC_WR ROOT_MAGIC_OLD |
85 | # define VER_STR_WR VER_STR_OLD | 85 | # define VER_STR_WR VER_STR_OLD |
86 | # define COMPAT_VER_WR COMPAT_VER_OLD | 86 | # define COMPAT_VER_WR COMPAT_VER_OLD |
87 | # define CAT_ROOT_WR CAT_ROOT_OLD | 87 | # define CAT_ROOT_WR CAT_ROOT_OLD |
88 | # define CAT_PREFIX_WR CAT_PREFIX_OLD | 88 | # define CAT_PREFIX_WR CAT_PREFIX_OLD |
89 | # define CAT_NAME_WR CAT_NAME_OLD | 89 | # define CAT_NAME_WR CAT_NAME_OLD |
90 | # define ENTRY_PREFIX_WRENTRY_PREFIX_OLD | 90 | # define ENTRY_PREFIX_WRENTRY_PREFIX_OLD |
91 | # define ENTRY_DESC_WR ENTRY_DESC_OLD | 91 | # define ENTRY_DESC_WR ENTRY_DESC_OLD |
92 | # define ENTRY_NAME_WR ENTRY_NAME_OLD | 92 | # define ENTRY_NAME_WR ENTRY_NAME_OLD |
93 | # define ENTRY_PW_WR ENTRY_PW_OLD | 93 | # define ENTRY_PW_WR ENTRY_PW_OLD |
94 | # define ENTRY_COMMENT_WRENTRY_COMMENT_OLD | 94 | # define ENTRY_COMMENT_WRENTRY_COMMENT_OLD |
95 | # define ENTRY_URL_WR ENTRY_URL_OLD | 95 | # define ENTRY_URL_WR ENTRY_URL_OLD |
96 | # define ENTRY_LAUNCHER_WRENTRY_LAUNCHER_OLD | 96 | # define ENTRY_LAUNCHER_WRENTRY_LAUNCHER_OLD |
97 | # define ENTRY_LVP_WR ENTRY_LVP_OLD | 97 | # define ENTRY_LVP_WR ENTRY_LVP_OLD |
98 | # define ENTRY_BIN_WR ENTRY_BIN_OLD | 98 | # define ENTRY_BIN_WR ENTRY_BIN_OLD |
99 | # define ENTRY_META_WR ENTRY_META_OLD | 99 | # define ENTRY_META_WR ENTRY_META_OLD |
100 | #else | 100 | #else |
101 | # define ROOT_MAGIC_WR ROOT_MAGIC_NEW | 101 | # define ROOT_MAGIC_WR ROOT_MAGIC_NEW |
102 | # define VER_STR_WR VER_STR_NEW | 102 | # define VER_STR_WR VER_STR_NEW |
103 | # define COMPAT_VER_WR COMPAT_VER_NEW | 103 | # define COMPAT_VER_WR COMPAT_VER_NEW |
104 | # define CAT_ROOT_WR CAT_ROOT_NEW | 104 | # define CAT_ROOT_WR CAT_ROOT_NEW |
105 | # define CAT_PREFIX_WR CAT_PREFIX_NEW | 105 | # define CAT_PREFIX_WR CAT_PREFIX_NEW |
106 | # define CAT_NAME_WR CAT_NAME_NEW | 106 | # define CAT_NAME_WR CAT_NAME_NEW |
107 | # define ENTRY_PREFIX_WRENTRY_PREFIX_NEW | 107 | # define ENTRY_PREFIX_WRENTRY_PREFIX_NEW |
108 | # define ENTRY_DESC_WR ENTRY_DESC_NEW | 108 | # define ENTRY_DESC_WR ENTRY_DESC_NEW |
109 | # define ENTRY_NAME_WR ENTRY_NAME_NEW | 109 | # define ENTRY_NAME_WR ENTRY_NAME_NEW |
110 | # define ENTRY_PW_WR ENTRY_PW_NEW | 110 | # define ENTRY_PW_WR ENTRY_PW_NEW |
111 | # define ENTRY_COMMENT_WRENTRY_COMMENT_NEW | 111 | # define ENTRY_COMMENT_WRENTRY_COMMENT_NEW |
112 | # define ENTRY_URL_WR ENTRY_URL_NEW | 112 | # define ENTRY_URL_WR ENTRY_URL_NEW |
113 | # define ENTRY_LAUNCHER_WRENTRY_LAUNCHER_NEW | 113 | # define ENTRY_LAUNCHER_WRENTRY_LAUNCHER_NEW |
114 | # define ENTRY_LVP_WR ENTRY_LVP_NEW | 114 | # define ENTRY_LVP_WR ENTRY_LVP_NEW |
115 | # define ENTRY_BIN_WR ENTRY_BIN_NEW | 115 | # define ENTRY_BIN_WR ENTRY_BIN_NEW |
116 | # define ENTRY_META_WR ENTRY_META_NEW | 116 | # define ENTRY_META_WR ENTRY_META_NEW |
117 | #endif | 117 | #endif |
118 | 118 | ||
119 | 119 | ||
120 | Serializer::Serializer() | 120 | Serializer::Serializer() |
121 | { | 121 | { |
122 | defaultLockStat = true; | 122 | defaultLockStat = true; |
123 | //US BUG: I needed to specify a document name. Otherwise impl will not be created for serializing | 123 | //US BUG: I needed to specify a document name. Otherwise impl will not be created for serializing |
124 | #ifndef PWM_EMBEDDED | 124 | #ifndef PWM_EMBEDDED |
125 | domDoc = new QDomDocument; | 125 | domDoc = new QDomDocument; |
126 | #else | 126 | #else |
127 | domDoc = new QDomDocument("mydoc"); | 127 | domDoc = new QDomDocument("mydoc"); |
128 | #endif | 128 | #endif |
129 | } | 129 | } |
130 | 130 | ||
131 | Serializer::Serializer(const QCString &buffer) | 131 | Serializer::Serializer(const QCString &buffer) |
132 | { | 132 | { |
133 | defaultLockStat = true; | 133 | defaultLockStat = true; |
134 | //US BUG: I needed to specify a document name. Otherwise impl will not be created for serializing | 134 | //US BUG: I needed to specify a document name. Otherwise impl will not be created for serializing |
135 | #ifndef PWM_EMBEDDED | 135 | #ifndef PWM_EMBEDDED |
136 | domDoc = new QDomDocument; | 136 | domDoc = new QDomDocument; |
137 | #else | 137 | #else |
138 | domDoc = new QDomDocument("mydoc"); | 138 | domDoc = new QDomDocument("mydoc"); |
139 | #endif | 139 | #endif |
140 | 140 | ||
141 | if (!parseXml(buffer)) { | 141 | if (!parseXml(buffer)) { |
142 | delete domDoc; | 142 | delete domDoc; |
143 | #ifndef PWM_EMBEDDED | 143 | #ifndef PWM_EMBEDDED |
144 | throw PwMException(PwMException::EX_PARSE); | 144 | throw PwMException(PwMException::EX_PARSE); |
145 | #else | 145 | #else |
146 | qDebug("Serializer::Serializer : Parse Exception "); | 146 | qDebug("Serializer::Serializer : Parse Exception "); |
147 | #endif | 147 | #endif |
148 | } | 148 | } |
149 | } | 149 | } |
150 | 150 | ||
151 | Serializer::~Serializer() | 151 | Serializer::~Serializer() |
152 | { | 152 | { |
153 | delete_ifnot_null(domDoc); | 153 | delete_ifnot_null(domDoc); |
154 | } | 154 | } |
155 | 155 | ||
156 | void Serializer::clear() | 156 | void Serializer::clear() |
157 | { | 157 | { |
158 | delete_ifnot_null(domDoc); | 158 | delete_ifnot_null(domDoc); |
159 | domDoc = new QDomDocument; | 159 | domDoc = new QDomDocument; |
160 | } | 160 | } |
161 | 161 | ||
162 | bool Serializer::parseXml(const QCString &buffer) | 162 | bool Serializer::parseXml(const QCString &buffer) |
163 | { | 163 | { |
164 | PWM_ASSERT(domDoc); | 164 | PWM_ASSERT(domDoc); |
165 | #ifndef PWM_EMBEDDED | 165 | #ifndef PWM_EMBEDDED |
166 | if (!domDoc->setContent(buffer, true)) | 166 | if (!domDoc->setContent(buffer, true)) |
167 | return false; | 167 | return false; |
168 | #else | 168 | #else |
169 | if (!domDoc->setContent(buffer)) | 169 | if (!domDoc->setContent(buffer)) |
170 | return false; | 170 | return false; |
171 | #endif | 171 | #endif |
172 | if (!checkValid()) | 172 | if (!checkValid()) |
173 | return false; | 173 | return false; |
174 | return true; | 174 | return true; |
175 | } | 175 | } |
176 | 176 | ||
177 | QCString Serializer::getXml() | 177 | QCString Serializer::getXml() |
178 | { | 178 | { |
179 | PWM_ASSERT(domDoc); | 179 | PWM_ASSERT(domDoc); |
180 | 180 | ||
181 | #ifndef PWM_EMBEDDED | 181 | #ifndef PWM_EMBEDDED |
182 | #if defined(PWM_DEBUG) && SERIALIZER_DEBUG != 0 | 182 | #if defined(PWM_DEBUG) && SERIALIZER_DEBUG != 0 |
183 | QCString tmp(domDoc->toCString(8)); | 183 | QCString tmp(domDoc->toCString(8)); |
184 | printDebug("<BEGIN Serializer::getXml() dump>\n"); | 184 | printDebug("<BEGIN Serializer::getXml() dump>\n"); |
185 | cout << tmp << endl; | 185 | cout << tmp << endl; |
186 | printDebug("<END Serializer::getXml() dump>"); | 186 | printDebug("<END Serializer::getXml() dump>"); |
187 | #endif // DEBUG | 187 | #endif // DEBUG |
188 | 188 | ||
189 | QCString ret(domDoc->toCString(0)); | 189 | QCString ret(domDoc->toCString(0)); |
190 | ret.replace('\n', ""); | 190 | ret.replace('\n', ""); |
191 | return ret; | 191 | return ret; |
192 | #else | 192 | #else |
193 | 193 | ||
194 | #if defined(PWM_DEBUG) && SERIALIZER_DEBUG != 0 | 194 | #if defined(PWM_DEBUG) && SERIALIZER_DEBUG != 0 |
195 | QCString tmp(" " + domDoc->toCString()); | 195 | QCString tmp(" " + domDoc->toCString()); |
196 | printDebug("<BEGIN Serializer::getXml() dump>\n"); | 196 | printDebug("<BEGIN Serializer::getXml() dump>\n"); |
197 | qDebug(tmp); | 197 | qDebug(tmp); |
198 | cout << tmp << endl; | 198 | cout << tmp << endl; |
199 | printDebug("<END Serializer::getXml() dump>"); | 199 | printDebug("<END Serializer::getXml() dump>"); |
200 | #endif // DEBUG | 200 | #endif // DEBUG |
201 | 201 | ||
202 | QCString ret(domDoc->toCString()); | 202 | QCString ret(domDoc->toCString()); |
203 | ret.replace(QRegExp("\n"), ""); | 203 | ret.replace(QRegExp("\n"), ""); |
204 | return ret; | 204 | return ret; |
205 | 205 | ||
206 | #endif | 206 | #endif |
207 | } | 207 | } |
208 | 208 | ||
209 | bool Serializer::serialize(const vector<PwMCategoryItem> &dta) | 209 | bool Serializer::serialize(const vector<PwMCategoryItem> &dta) |
210 | { | 210 | { |
211 | PWM_ASSERT(domDoc); | 211 | PWM_ASSERT(domDoc); |
212 | QDomElement root(genNewRoot()); | 212 | QDomElement root(genNewRoot()); |
213 | QDomElement catNode(domDoc->createElement(CAT_ROOT_WR)); | 213 | QDomElement catNode(domDoc->createElement(CAT_ROOT_WR)); |
214 | root.appendChild(catNode); | 214 | root.appendChild(catNode); |
215 | if (!addCategories(&catNode, dta)) | 215 | if (!addCategories(&catNode, dta)) |
216 | return false; | 216 | return false; |
217 | return true; | 217 | return true; |
218 | } | 218 | } |
219 | 219 | ||
220 | bool Serializer::deSerialize(vector<PwMCategoryItem> *dta) | 220 | bool Serializer::deSerialize(vector<PwMCategoryItem> *dta) |
221 | { | 221 | { |
222 | PWM_ASSERT(domDoc); | 222 | PWM_ASSERT(domDoc); |
223 | PWM_ASSERT(dta); | 223 | PWM_ASSERT(dta); |
224 | QDomElement root(domDoc->documentElement()); | 224 | QDomElement root(domDoc->documentElement()); |
225 | QDomNode n; | 225 | QDomNode n; |
226 | 226 | ||
227 | dta->clear(); | 227 | dta->clear(); |
228 | for (n = root.firstChild(); !n.isNull(); n = n.nextSibling()) { | 228 | for (n = root.firstChild(); !n.isNull(); n = n.nextSibling()) { |
229 | // find <categories> ... </categories> | 229 | // find <categories> ... </categories> |
230 | // <c> ... </c> | 230 | // <c> ... </c> |
231 | if (n.nodeName() == CAT_ROOT_NEW || | 231 | if (n.nodeName() == CAT_ROOT_NEW || |
232 | n.nodeName() == CAT_ROOT_OLD) { | 232 | n.nodeName() == CAT_ROOT_OLD) { |
233 | if (!readCategories(n, dta)) { | 233 | if (!readCategories(n, dta)) { |
234 | return false; | 234 | return false; |
235 | } | 235 | } |
236 | 236 | ||
237 | /* NOTE: We can stop processing here, as we | 237 | /* NOTE: We can stop processing here, as we |
238 | * don't have more nodes in root, yet. | 238 | * don't have more nodes in root, yet. |
239 | */ | 239 | */ |
240 | return true; | 240 | return true; |
241 | } | 241 | } |
242 | } | 242 | } |
243 | return false; | 243 | return false; |
244 | } | 244 | } |
245 | 245 | ||
246 | bool Serializer::readCategories(const QDomNode &n, | 246 | bool Serializer::readCategories(const QDomNode &n, |
247 | vector<PwMCategoryItem> *dta) | 247 | vector<PwMCategoryItem> *dta) |
248 | { | 248 | { |
249 | QDomNodeList nl(n.childNodes()); | 249 | QDomNodeList nl(n.childNodes()); |
250 | QDomNode cur; | 250 | QDomNode cur; |
251 | QString name; | 251 | QString name; |
252 | unsigned int numCat = nl.count(), i; | 252 | unsigned int numCat = nl.count(), i; |
253 | PwMCategoryItem curCat; | 253 | PwMCategoryItem curCat; |
254 | vector<PwMDataItem> curEntr; | 254 | vector<PwMDataItem> curEntr; |
255 | 255 | ||
256 | if (!numCat) { | 256 | if (!numCat) { |
257 | printDebug("Serializer::readCategories(): empty"); | 257 | printDebug("Serializer::readCategories(): empty"); |
258 | return false; | 258 | return false; |
259 | } | 259 | } |
260 | for (i = 0; i < numCat; ++i) { | 260 | for (i = 0; i < numCat; ++i) { |
261 | cur = nl.item(i); | 261 | cur = nl.item(i); |
262 | if (cur.nodeName().left(1) == CAT_PREFIX_NEW || | 262 | if (cur.nodeName().left(1) == CAT_PREFIX_NEW || |
263 | cur.nodeName().left(4) == CAT_PREFIX_OLD) { | 263 | cur.nodeName().left(4) == CAT_PREFIX_OLD) { |
264 | name = cur.toElement().attribute(CAT_NAME_NEW); | 264 | name = cur.toElement().attribute(CAT_NAME_NEW); |
265 | if (name == QString::null) | 265 | if (name == QString::null) |
266 | name = cur.toElement().attribute(CAT_NAME_OLD); | 266 | name = cur.toElement().attribute(CAT_NAME_OLD); |
267 | PWM_ASSERT(name != QString::null); | 267 | PWM_ASSERT(name != QString::null); |
268 | PWM_ASSERT(name != ""); | 268 | PWM_ASSERT(name != ""); |
269 | curCat.clear(); | 269 | curCat.clear(); |
270 | curCat.name = name.latin1(); | 270 | curCat.name = name.latin1(); |
271 | if (!readEntries(cur, &curEntr)) { | 271 | if (!readEntries(cur, &curEntr)) { |
272 | dta->clear(); | 272 | dta->clear(); |
273 | return false; | 273 | return false; |
274 | } | 274 | } |
275 | curCat.d = curEntr; | 275 | curCat.d = curEntr; |
276 | dta->push_back(curCat); | 276 | dta->push_back(curCat); |
277 | } else { | 277 | } else { |
278 | printDebug("Serializer::readCategories(): uh? not a category?"); | 278 | printDebug("Serializer::readCategories(): uh? not a category?"); |
279 | } | 279 | } |
280 | } | 280 | } |
281 | return true; | 281 | return true; |
282 | } | 282 | } |
283 | 283 | ||
284 | bool Serializer::readEntries(const QDomNode &n, | 284 | bool Serializer::readEntries(const QDomNode &n, |
285 | vector<PwMDataItem> *dta) | 285 | vector<PwMDataItem> *dta) |
286 | { | 286 | { |
287 | QDomNodeList nl(n.childNodes()); | 287 | QDomNodeList nl(n.childNodes()); |
288 | QDomNode cur; | 288 | QDomNode cur; |
289 | unsigned int numEntr = nl.count(), i; | 289 | unsigned int numEntr = nl.count(), i; |
290 | PwMDataItem curEntr; | 290 | PwMDataItem curEntr; |
291 | 291 | ||
292 | dta->clear(); | 292 | dta->clear(); |
293 | for (i = 0; i < numEntr; ++i) { | 293 | for (i = 0; i < numEntr; ++i) { |
294 | cur = nl.item(i); | 294 | cur = nl.item(i); |
295 | if (cur.nodeName().left(1) == ENTRY_PREFIX_NEW || | 295 | if (cur.nodeName().left(1) == ENTRY_PREFIX_NEW || |
296 | cur.nodeName().left(6) == ENTRY_PREFIX_OLD) { | 296 | cur.nodeName().left(6) == ENTRY_PREFIX_OLD) { |
297 | if (!extractEntry(cur, &curEntr)) { | 297 | if (!extractEntry(cur, &curEntr)) { |
298 | return false; | 298 | return false; |
299 | } | 299 | } |
300 | dta->push_back(curEntr); | 300 | dta->push_back(curEntr); |
301 | } else { | 301 | } else { |
302 | printDebug("Serializer::readEntries(): hm? not an entry?"); | 302 | printDebug("Serializer::readEntries(): hm? not an entry?"); |
303 | } | 303 | } |
304 | } | 304 | } |
305 | return true; | 305 | return true; |
306 | } | 306 | } |
307 | 307 | ||
308 | bool Serializer::extractEntry(const QDomNode &n, | 308 | bool Serializer::extractEntry(const QDomNode &n, |
309 | PwMDataItem *dta) | 309 | PwMDataItem *dta) |
310 | { | 310 | { |
311 | QDomNodeList nl(n.childNodes()); | 311 | QDomNodeList nl(n.childNodes()); |
312 | QDomNode cur, cdata; | 312 | QDomNode cur, cdata; |
313 | unsigned int cnt = nl.count(), i; | 313 | unsigned int cnt = nl.count(), i; |
314 | QString name, text; | 314 | QString name, text; |
315 | 315 | ||
316 | if (!cnt) { | 316 | if (!cnt) { |
317 | printDebug("Serializer::extractEntry(): empty"); | 317 | printDebug("Serializer::extractEntry(): empty"); |
318 | return false; | 318 | return false; |
319 | } | 319 | } |
320 | dta->clear(); | 320 | dta->clear(); |
321 | for (i = 0; i < cnt; ++i) { | 321 | for (i = 0; i < cnt; ++i) { |
322 | cur = nl.item(i); | 322 | cur = nl.item(i); |
323 | name = cur.nodeName(); | 323 | name = cur.nodeName(); |
324 | cdata = cur.firstChild(); | 324 | cdata = cur.firstChild(); |
325 | if (unlikely(cdata.isCDATASection())) { | 325 | if (unlikely(cdata.isCDATASection())) { |
326 | text = cdata.toCDATASection().data(); | 326 | text = cdata.toCDATASection().data(); |
327 | } else if (likely(cur.isElement())) { | 327 | } else if (likely(cur.isElement())) { |
328 | text = cur.toElement().text(); | 328 | text = cur.toElement().text(); |
329 | } else { | 329 | } else { |
330 | printDebug("Serializer::extractEntry(): neither CDATA nor element."); | 330 | printDebug("Serializer::extractEntry(): neither CDATA nor element."); |
331 | return false; | 331 | return false; |
332 | } | 332 | } |
333 | if (text == " ") | 333 | if (text == " ") |
334 | text = ""; // for backward compatibility. | 334 | text = ""; // for backward compatibility. |
335 | if (name == ENTRY_DESC_NEW || | 335 | if (name == ENTRY_DESC_NEW || |
336 | name == ENTRY_DESC_OLD) { | 336 | name == ENTRY_DESC_OLD) { |
337 | dta->desc = unescapeEntryData(text).latin1(); | 337 | dta->desc = unescapeEntryData(text).latin1(); |
338 | } else if (name == ENTRY_NAME_NEW || | 338 | } else if (name == ENTRY_NAME_NEW || |
339 | name == ENTRY_NAME_OLD) { | 339 | name == ENTRY_NAME_OLD) { |
340 | dta->name = unescapeEntryData(text).latin1(); | 340 | dta->name = unescapeEntryData(text).latin1(); |
341 | } else if (name == ENTRY_PW_NEW || | 341 | } else if (name == ENTRY_PW_NEW || |
342 | name == ENTRY_PW_OLD) { | 342 | name == ENTRY_PW_OLD) { |
343 | dta->pw = unescapeEntryData(text).latin1(); | 343 | dta->pw = unescapeEntryData(text).latin1(); |
344 | } else if (name == ENTRY_COMMENT_NEW || | 344 | } else if (name == ENTRY_COMMENT_NEW || |
345 | name == ENTRY_COMMENT_OLD) { | 345 | name == ENTRY_COMMENT_OLD) { |
346 | dta->comment = unescapeEntryData(text).latin1(); | 346 | dta->comment = unescapeEntryData(text).latin1(); |
347 | } else if (name == ENTRY_URL_NEW || | 347 | } else if (name == ENTRY_URL_NEW || |
348 | name == ENTRY_URL_OLD) { | 348 | name == ENTRY_URL_OLD) { |
349 | dta->url = unescapeEntryData(text).latin1(); | 349 | dta->url = unescapeEntryData(text).latin1(); |
350 | } else if (name == ENTRY_LAUNCHER_NEW || | 350 | } else if (name == ENTRY_LAUNCHER_NEW || |
351 | name == ENTRY_LAUNCHER_OLD) { | 351 | name == ENTRY_LAUNCHER_OLD) { |
352 | dta->launcher = unescapeEntryData(text).latin1(); | 352 | dta->launcher = unescapeEntryData(text).latin1(); |
353 | } else if (name == ENTRY_LVP_NEW || | 353 | } else if (name == ENTRY_LVP_NEW || |
354 | name == ENTRY_LVP_OLD) { | 354 | name == ENTRY_LVP_OLD) { |
355 | dta->listViewPos = strtol(text.latin1(), 0, 10); | 355 | dta->listViewPos = strtol(text.latin1(), 0, 10); |
356 | } else if (name == ENTRY_BIN_NEW) { | 356 | } else if (name == ENTRY_BIN_NEW) { |
357 | // ENTRY_BIN_NEW == ENTRY_BIN_OLD | 357 | // ENTRY_BIN_NEW == ENTRY_BIN_OLD |
358 | if (text == "0") { | 358 | if (text == "0") { |
359 | dta->binary = false; | 359 | dta->binary = false; |
360 | } else { | 360 | } else { |
361 | dta->binary = true; | 361 | dta->binary = true; |
362 | } | 362 | } |
363 | } else if (name == ENTRY_META_NEW) { | 363 | } else if (name == ENTRY_META_NEW) { |
364 | // ENTRY_META_NEW == ENTRY_META_OLD | 364 | // ENTRY_META_NEW == ENTRY_META_OLD |
365 | if (!extractMeta(cur, &dta->meta)) | 365 | if (!extractMeta(cur, &dta->meta)) |
366 | return false; | 366 | return false; |
367 | } else { | 367 | } else { |
368 | printDebug(string("Serializer::extractEntry(): invalid: ") | 368 | printDebug(string("Serializer::extractEntry(): invalid: ") |
369 | + name.latin1()); | 369 | + name.latin1()); |
370 | } | 370 | } |
371 | } | 371 | } |
372 | dta->lockStat = defaultLockStat; | 372 | dta->lockStat = defaultLockStat; |
373 | return true; | 373 | return true; |
374 | } | 374 | } |
375 | 375 | ||
376 | bool Serializer::extractMeta(const QDomNode &n, | 376 | bool Serializer::extractMeta(const QDomNode &n, |
377 | PwMMetaData *dta) | 377 | PwMMetaData *dta) |
378 | { | 378 | { |
379 | QDomNode cur(n.firstChild()); | 379 | QDomNode cur(n.firstChild()); |
380 | QString name, val; | 380 | QString name, val; |
381 | while (!cur.isNull()) { | 381 | while (!cur.isNull()) { |
382 | name = cur.nodeName(); | 382 | name = cur.nodeName(); |
383 | val = cur.toElement().text(); | 383 | val = cur.toElement().text(); |
384 | if (val == "") { | 384 | if (val == "") { |
385 | cur = cur.nextSibling(); | 385 | cur = cur.nextSibling(); |
386 | continue; | 386 | continue; |
387 | } | 387 | } |
388 | #ifndef PWM_EMBEDDED | 388 | #ifndef PWM_EMBEDDED |
389 | if (name == META_CREATE_DATE) { | 389 | if (name == META_CREATE_DATE) { |
390 | dta->create = QDateTime::fromString(val, Qt::ISODate); | 390 | dta->create = QDateTime::fromString(val, Qt::ISODate); |
391 | } else if (name == META_VALID_DATE) { | 391 | } else if (name == META_VALID_DATE) { |
392 | dta->valid = QDateTime::fromString(val, Qt::ISODate); | 392 | dta->valid = QDateTime::fromString(val, Qt::ISODate); |
393 | } else if (name == META_EXPIRE_DATE) { | 393 | } else if (name == META_EXPIRE_DATE) { |
394 | dta->expire = QDateTime::fromString(val, Qt::ISODate); | 394 | dta->expire = QDateTime::fromString(val, Qt::ISODate); |
395 | } else if (name == META_UPDATE_DATE) { | 395 | } else if (name == META_UPDATE_DATE) { |
396 | dta->update = QDateTime::fromString(val, Qt::ISODate); | 396 | dta->update = QDateTime::fromString(val, Qt::ISODate); |
397 | } else if (name == META_UPDATE_INT) { | 397 | } else if (name == META_UPDATE_INT) { |
398 | dta->updateInt = strtoul(val.latin1(), 0, 10); | 398 | dta->updateInt = strtoul(val.latin1(), 0, 10); |
399 | } else if (name == META_UNIQUEID) { | 399 | } else if (name == META_UNIQUEID) { |
400 | dta->uniqueid = unescapeEntryData(val).latin1(); | 400 | dta->uniqueid = unescapeEntryData(val).latin1(); |
401 | } else { | 401 | } else { |
402 | printDebug(string("extractMeta(): invalid: ") | 402 | printDebug(string("extractMeta(): invalid: ") |
403 | + name.latin1()); | 403 | + name.latin1()); |
404 | } | 404 | } |
405 | #else | 405 | #else |
406 | 406 | ||
407 | QDateTime m_dt; | 407 | QDateTime m_dt; |
408 | 408 | ||
409 | if ((name == META_CREATE_DATE) || | 409 | if ((name == META_CREATE_DATE) || |
410 | (name == META_VALID_DATE) || | 410 | (name == META_VALID_DATE) || |
411 | (name == META_EXPIRE_DATE) || | 411 | (name == META_EXPIRE_DATE) || |
412 | (name == META_UPDATE_DATE)) | 412 | (name == META_UPDATE_DATE)) |
413 | { | 413 | { |
414 | int pos = val.find("T"); | 414 | int pos = val.find("T"); |
415 | QString date = val.left(pos); | 415 | QString date = val.left(pos); |
416 | QString time = val.mid(pos+1); | 416 | QString time = val.mid(pos+1); |
417 | qDebug("Serializer::extractMeta : date=%s ,time=%s",date.latin1(), time.latin1() ); | 417 | qDebug("Serializer::extractMeta from %s to date=%s ,time=%s",val.latin1(), date.latin1(), time.latin1() ); |
418 | bool ok1, ok2; | 418 | bool ok1, ok2; |
419 | 419 | ||
420 | QDate m_date = KGlobal::locale()->readDate(date, &ok1); | 420 | QDate m_date = KGlobal::locale()->readDate(date, &ok1); |
421 | QTime m_time = KGlobal::locale()->readTime(time, &ok2); | 421 | QTime m_time = KGlobal::locale()->readTime(time, &ok2); |
422 | if ((ok1 == false) || (ok2 == false)) | 422 | if ((ok1 == false) || (ok2 == false)) |
423 | qDebug("Serializer::extractMeta invalid date or time !!!!!!!!!!!!!"); | 423 | qDebug("Serializer::extractMeta invalid date or time !!!!!!!!!!!!!"); |
424 | m_dt.setDate(m_date); | 424 | m_dt.setDate(m_date); |
425 | m_dt.setTime(m_time); | 425 | m_dt.setTime(m_time); |
426 | } | 426 | } |
427 | 427 | ||
428 | 428 | ||
429 | if (name == META_CREATE_DATE) { | 429 | if (name == META_CREATE_DATE) { |
430 | dta->create = m_dt; | 430 | dta->create = m_dt; |
431 | } else if (name == META_VALID_DATE) { | 431 | } else if (name == META_VALID_DATE) { |
432 | dta->valid = m_dt; | 432 | dta->valid = m_dt; |
433 | } else if (name == META_EXPIRE_DATE) { | 433 | } else if (name == META_EXPIRE_DATE) { |
434 | dta->expire = m_dt; | 434 | dta->expire = m_dt; |
435 | } else if (name == META_UPDATE_DATE) { | 435 | } else if (name == META_UPDATE_DATE) { |
436 | dta->update = m_dt; | 436 | dta->update = m_dt; |
437 | } else if (name == META_UPDATE_INT) { | 437 | } else if (name == META_UPDATE_INT) { |
438 | dta->updateInt = strtoul(val.latin1(), 0, 10); | 438 | dta->updateInt = strtoul(val.latin1(), 0, 10); |
439 | } else if (name == META_UNIQUEID) { | 439 | } else if (name == META_UNIQUEID) { |
440 | dta->uniqueid = unescapeEntryData(val).latin1(); | 440 | dta->uniqueid = unescapeEntryData(val).latin1(); |
441 | } else { | 441 | } else { |
442 | printDebug(string("extractMeta(): invalid: ") | 442 | printDebug(string("extractMeta(): invalid: ") |
443 | + name.latin1()); | 443 | + name.latin1()); |
444 | } | 444 | } |
445 | #endif | 445 | #endif |
446 | cur = cur.nextSibling(); | 446 | cur = cur.nextSibling(); |
447 | } | 447 | } |
448 | return true; | 448 | return true; |
449 | } | 449 | } |
450 | 450 | ||
451 | bool Serializer::checkValid() | 451 | bool Serializer::checkValid() |
452 | { | 452 | { |
453 | PWM_ASSERT(domDoc); | 453 | PWM_ASSERT(domDoc); |
454 | QDomElement root(domDoc->documentElement()); | 454 | QDomElement root(domDoc->documentElement()); |
455 | if (root.nodeName() != ROOT_MAGIC_NEW && | 455 | if (root.nodeName() != ROOT_MAGIC_NEW && |
456 | root.nodeName() != ROOT_MAGIC_OLD) { | 456 | root.nodeName() != ROOT_MAGIC_OLD) { |
457 | printDebug("Serializer: wrong magic"); | 457 | printDebug("Serializer: wrong magic"); |
458 | return false; | 458 | return false; |
459 | } | 459 | } |
460 | if (root.attribute(VER_STR_NEW) != COMPAT_VER_NEW && | 460 | if (root.attribute(VER_STR_NEW) != COMPAT_VER_NEW && |
461 | root.attribute(VER_STR_OLD) != COMPAT_VER_OLD) { | 461 | root.attribute(VER_STR_OLD) != COMPAT_VER_OLD) { |
462 | printDebug("Serializer: wrong version"); | 462 | printDebug("Serializer: wrong version"); |
463 | return false; | 463 | return false; |
464 | } | 464 | } |
465 | return true; | 465 | return true; |
466 | } | 466 | } |
467 | 467 | ||
468 | QDomElement Serializer::genNewRoot() | 468 | QDomElement Serializer::genNewRoot() |
469 | { | 469 | { |
470 | PWM_ASSERT(domDoc); | 470 | PWM_ASSERT(domDoc); |
471 | QDomElement root(domDoc->createElement(ROOT_MAGIC_WR)); | 471 | QDomElement root(domDoc->createElement(ROOT_MAGIC_WR)); |
472 | root.setAttribute(VER_STR_WR, COMPAT_VER_WR); | 472 | root.setAttribute(VER_STR_WR, COMPAT_VER_WR); |
473 | domDoc->appendChild(root); | 473 | domDoc->appendChild(root); |
474 | return root; | 474 | return root; |
475 | } | 475 | } |
476 | 476 | ||
477 | bool Serializer::addCategories(QDomElement *e, | 477 | bool Serializer::addCategories(QDomElement *e, |
478 | const vector<PwMCategoryItem> &dta) | 478 | const vector<PwMCategoryItem> &dta) |
479 | { | 479 | { |
480 | unsigned int numCat = dta.size(), i; | 480 | unsigned int numCat = dta.size(), i; |
481 | QString curId, curName; | 481 | QString curId, curName; |
482 | QDomElement curCat; | 482 | QDomElement curCat; |
483 | 483 | ||
484 | for (i = 0; i < numCat; ++i) { | 484 | for (i = 0; i < numCat; ++i) { |
485 | curId = CAT_PREFIX_WR; | 485 | curId = CAT_PREFIX_WR; |
486 | curId += tostr(i).c_str(); | 486 | curId += tostr(i).c_str(); |
487 | curName = dta[i].name.c_str(); | 487 | curName = dta[i].name.c_str(); |
488 | curCat = domDoc->createElement(curId); | 488 | curCat = domDoc->createElement(curId); |
489 | curCat.setAttribute(CAT_NAME_WR, curName); | 489 | curCat.setAttribute(CAT_NAME_WR, curName); |
490 | if (!addEntries(&curCat, dta[i].d)) { | 490 | if (!addEntries(&curCat, dta[i].d)) { |
491 | return false; | 491 | return false; |
492 | } | 492 | } |
493 | e->appendChild(curCat); | 493 | e->appendChild(curCat); |
494 | } | 494 | } |
495 | return true; | 495 | return true; |
496 | } | 496 | } |
497 | 497 | ||
498 | bool Serializer::addEntries(QDomElement *e, | 498 | bool Serializer::addEntries(QDomElement *e, |
499 | const vector<PwMDataItem> &dta) | 499 | const vector<PwMDataItem> &dta) |
500 | { | 500 | { |
501 | unsigned int numEntr = dta.size(), i; | 501 | unsigned int numEntr = dta.size(), i; |
502 | QString curId; | 502 | QString curId; |
503 | QDomElement curEntr; | 503 | QDomElement curEntr; |
504 | 504 | ||
505 | for (i = 0; i < numEntr; ++i) { | 505 | for (i = 0; i < numEntr; ++i) { |
506 | curId = ENTRY_PREFIX_WR; | 506 | curId = ENTRY_PREFIX_WR; |
507 | curId += tostr(i).c_str(); | 507 | curId += tostr(i).c_str(); |
508 | curEntr = domDoc->createElement(curId); | 508 | curEntr = domDoc->createElement(curId); |
509 | if (!writeEntry(&curEntr, dta[i])) { | 509 | if (!writeEntry(&curEntr, dta[i])) { |
510 | return false; | 510 | return false; |
511 | } | 511 | } |
512 | e->appendChild(curEntr); | 512 | e->appendChild(curEntr); |
513 | } | 513 | } |
514 | return true; | 514 | return true; |
515 | } | 515 | } |
516 | 516 | ||
517 | bool Serializer::writeEntry(QDomElement *e, | 517 | bool Serializer::writeEntry(QDomElement *e, |
518 | const PwMDataItem &_dta) | 518 | const PwMDataItem &_dta) |
519 | { | 519 | { |
520 | #if WRITE_CDATA_SEC != 0 | 520 | #if WRITE_CDATA_SEC != 0 |
521 | # define new_text(x)domDoc->createCDATASection(x) | 521 | # define new_text(x)domDoc->createCDATASection(x) |
522 | QDomCDATASection curText; | 522 | QDomCDATASection curText; |
523 | #else | 523 | #else |
524 | # define new_text(x)domDoc->createTextNode(x) | 524 | # define new_text(x)domDoc->createTextNode(x) |
525 | QDomText curText; | 525 | QDomText curText; |
526 | #endif | 526 | #endif |
527 | 527 | ||
528 | QDomText plainText; | 528 | QDomText plainText; |
529 | QDomElement tag; | 529 | QDomElement tag; |
530 | 530 | ||
531 | // begin -- This is for compatibility with the old serializer | 531 | // begin -- This is for compatibility with the old serializer |
532 | PwMDataItem dta = _dta; | 532 | PwMDataItem dta = _dta; |
533 | if (!dta.desc.size()) | 533 | if (!dta.desc.size()) |
534 | dta.desc = " "; | 534 | dta.desc = " "; |
535 | if (!dta.name.size()) | 535 | if (!dta.name.size()) |
536 | dta.name = " "; | 536 | dta.name = " "; |
537 | if (!dta.pw.size()) | 537 | if (!dta.pw.size()) |
538 | dta.pw = " "; | 538 | dta.pw = " "; |
539 | if (!dta.comment.size()) | 539 | if (!dta.comment.size()) |
540 | dta.comment = " "; | 540 | dta.comment = " "; |
541 | if (!dta.url.size()) | 541 | if (!dta.url.size()) |
542 | dta.url = " "; | 542 | dta.url = " "; |
543 | if (!dta.launcher.size()) | 543 | if (!dta.launcher.size()) |
544 | dta.launcher = " "; | 544 | dta.launcher = " "; |
545 | // end -- This is for compatibility with the old serializer | 545 | // end -- This is for compatibility with the old serializer |
546 | 546 | ||
547 | tag = domDoc->createElement(ENTRY_DESC_WR); | 547 | tag = domDoc->createElement(ENTRY_DESC_WR); |
548 | curText = new_text(escapeEntryData(dta.desc.c_str())); | 548 | curText = new_text(escapeEntryData(dta.desc.c_str())); |
549 | tag.appendChild(curText); | 549 | tag.appendChild(curText); |
550 | e->appendChild(tag); | 550 | e->appendChild(tag); |
551 | 551 | ||
552 | tag = domDoc->createElement(ENTRY_NAME_WR); | 552 | tag = domDoc->createElement(ENTRY_NAME_WR); |
553 | curText = new_text(escapeEntryData(dta.name.c_str())); | 553 | curText = new_text(escapeEntryData(dta.name.c_str())); |
554 | tag.appendChild(curText); | 554 | tag.appendChild(curText); |
555 | e->appendChild(tag); | 555 | e->appendChild(tag); |
556 | 556 | ||
557 | tag = domDoc->createElement(ENTRY_PW_WR); | 557 | tag = domDoc->createElement(ENTRY_PW_WR); |
558 | curText = new_text(escapeEntryData(dta.pw.c_str())); | 558 | curText = new_text(escapeEntryData(dta.pw.c_str())); |
559 | tag.appendChild(curText); | 559 | tag.appendChild(curText); |
560 | e->appendChild(tag); | 560 | e->appendChild(tag); |
561 | 561 | ||
562 | tag = domDoc->createElement(ENTRY_COMMENT_WR); | 562 | tag = domDoc->createElement(ENTRY_COMMENT_WR); |
563 | curText = new_text(escapeEntryData(dta.comment.c_str())); | 563 | curText = new_text(escapeEntryData(dta.comment.c_str())); |
564 | tag.appendChild(curText); | 564 | tag.appendChild(curText); |
565 | e->appendChild(tag); | 565 | e->appendChild(tag); |
566 | 566 | ||
567 | tag = domDoc->createElement(ENTRY_URL_WR); | 567 | tag = domDoc->createElement(ENTRY_URL_WR); |
568 | curText = new_text(escapeEntryData(dta.url.c_str())); | 568 | curText = new_text(escapeEntryData(dta.url.c_str())); |
569 | tag.appendChild(curText); | 569 | tag.appendChild(curText); |
570 | e->appendChild(tag); | 570 | e->appendChild(tag); |
571 | 571 | ||
572 | tag = domDoc->createElement(ENTRY_LAUNCHER_WR); | 572 | tag = domDoc->createElement(ENTRY_LAUNCHER_WR); |
573 | curText = new_text(escapeEntryData(dta.launcher.c_str())); | 573 | curText = new_text(escapeEntryData(dta.launcher.c_str())); |
574 | tag.appendChild(curText); | 574 | tag.appendChild(curText); |
575 | e->appendChild(tag); | 575 | e->appendChild(tag); |
576 | 576 | ||
577 | tag = domDoc->createElement(ENTRY_LVP_WR); | 577 | tag = domDoc->createElement(ENTRY_LVP_WR); |
578 | plainText = domDoc->createTextNode(tostr(dta.listViewPos).c_str()); | 578 | plainText = domDoc->createTextNode(tostr(dta.listViewPos).c_str()); |
579 | tag.appendChild(plainText); | 579 | tag.appendChild(plainText); |
580 | e->appendChild(tag); | 580 | e->appendChild(tag); |
581 | 581 | ||
582 | tag = domDoc->createElement(ENTRY_BIN_WR); | 582 | tag = domDoc->createElement(ENTRY_BIN_WR); |
583 | if (dta.binary) | 583 | if (dta.binary) |
584 | plainText = domDoc->createTextNode("1"); | 584 | plainText = domDoc->createTextNode("1"); |
585 | else | 585 | else |
586 | plainText = domDoc->createTextNode("0"); | 586 | plainText = domDoc->createTextNode("0"); |
587 | tag.appendChild(plainText); | 587 | tag.appendChild(plainText); |
588 | e->appendChild(tag); | 588 | e->appendChild(tag); |
589 | 589 | ||
590 | tag = domDoc->createElement(ENTRY_META_WR); | 590 | tag = domDoc->createElement(ENTRY_META_WR); |
591 | if (!writeMeta(&tag, dta.meta)) | 591 | if (!writeMeta(&tag, dta.meta)) |
592 | return false; | 592 | return false; |
593 | e->appendChild(tag); | 593 | e->appendChild(tag); |
594 | 594 | ||
595 | #undef new_text | 595 | #undef new_text |
596 | return true; | 596 | return true; |
597 | } | 597 | } |
598 | 598 | ||
599 | bool Serializer::writeMeta(QDomElement *e, | 599 | bool Serializer::writeMeta(QDomElement *e, |
600 | const PwMMetaData &dta) | 600 | const PwMMetaData &dta) |
601 | { | 601 | { |
602 | QDomText text; | 602 | QDomText text; |
603 | QDomElement tag; | 603 | QDomElement tag; |
604 | 604 | ||
605 | tag = domDoc->createElement(META_CREATE_DATE); | 605 | tag = domDoc->createElement(META_CREATE_DATE); |
606 | #ifndef PWM_EMBEDDED | 606 | #ifndef PWM_EMBEDDED |
607 | text = domDoc->createTextNode(dta.create.toString(Qt::ISODate)); | 607 | text = domDoc->createTextNode(dta.create.toString(Qt::ISODate)); |
608 | #else | 608 | #else |
609 | text = domDoc->createTextNode(KGlobal::locale()->formatDateTime(dta.create, KLocale::ISODate)); | 609 | text = domDoc->createTextNode(KGlobal::locale()->formatDateTime(dta.create, KLocale::ISODate)); |
610 | #endif | 610 | #endif |
611 | tag.appendChild(text); | 611 | tag.appendChild(text); |
612 | e->appendChild(tag); | 612 | e->appendChild(tag); |
613 | 613 | ||
614 | tag = domDoc->createElement(META_VALID_DATE); | 614 | tag = domDoc->createElement(META_VALID_DATE); |
615 | #ifndef PWM_EMBEDDED | 615 | #ifndef PWM_EMBEDDED |
616 | text = domDoc->createTextNode(dta.valid.toString(Qt::ISODate)); | 616 | text = domDoc->createTextNode(dta.valid.toString(Qt::ISODate)); |
617 | #else | 617 | #else |
618 | text = domDoc->createTextNode(KGlobal::locale()->formatDateTime(dta.valid, KLocale::ISODate)); | 618 | text = domDoc->createTextNode(KGlobal::locale()->formatDateTime(dta.valid, KLocale::ISODate)); |
619 | #endif | 619 | #endif |
620 | tag.appendChild(text); | 620 | tag.appendChild(text); |
621 | e->appendChild(tag); | 621 | e->appendChild(tag); |
622 | 622 | ||
623 | tag = domDoc->createElement(META_EXPIRE_DATE); | 623 | tag = domDoc->createElement(META_EXPIRE_DATE); |
624 | #ifndef PWM_EMBEDDED | 624 | #ifndef PWM_EMBEDDED |
625 | text = domDoc->createTextNode(dta.expire.toString(Qt::ISODate)); | 625 | text = domDoc->createTextNode(dta.expire.toString(Qt::ISODate)); |
626 | #else | 626 | #else |
627 | text = domDoc->createTextNode(KGlobal::locale()->formatDateTime(dta.expire, KLocale::ISODate)); | 627 | text = domDoc->createTextNode(KGlobal::locale()->formatDateTime(dta.expire, KLocale::ISODate)); |
628 | #endif | 628 | #endif |
629 | tag.appendChild(text); | 629 | tag.appendChild(text); |
630 | e->appendChild(tag); | 630 | e->appendChild(tag); |
631 | 631 | ||
632 | tag = domDoc->createElement(META_UPDATE_DATE); | 632 | tag = domDoc->createElement(META_UPDATE_DATE); |
633 | #ifndef PWM_EMBEDDED | 633 | #ifndef PWM_EMBEDDED |
634 | text = domDoc->createTextNode(dta.update.toString(Qt::ISODate)); | 634 | text = domDoc->createTextNode(dta.update.toString(Qt::ISODate)); |
635 | #else | 635 | #else |
636 | text = domDoc->createTextNode(KGlobal::locale()->formatDateTime(dta.update, KLocale::ISODate)); | 636 | text = domDoc->createTextNode(KGlobal::locale()->formatDateTime(dta.update, KLocale::ISODate)); |
637 | #endif | 637 | #endif |
638 | tag.appendChild(text); | 638 | tag.appendChild(text); |
639 | e->appendChild(tag); | 639 | e->appendChild(tag); |
640 | 640 | ||
641 | tag = domDoc->createElement(META_UPDATE_INT); | 641 | tag = domDoc->createElement(META_UPDATE_INT); |
642 | text = domDoc->createTextNode(tostr(dta.updateInt).c_str()); | 642 | text = domDoc->createTextNode(tostr(dta.updateInt).c_str()); |
643 | tag.appendChild(text); | 643 | tag.appendChild(text); |
644 | e->appendChild(tag); | 644 | e->appendChild(tag); |
645 | 645 | ||
646 | tag = domDoc->createElement(META_UNIQUEID); | 646 | tag = domDoc->createElement(META_UNIQUEID); |
647 | text = domDoc->createTextNode(escapeEntryData(dta.uniqueid)); | 647 | text = domDoc->createTextNode(escapeEntryData(dta.uniqueid)); |
648 | tag.appendChild(text); | 648 | tag.appendChild(text); |
649 | e->appendChild(tag); | 649 | e->appendChild(tag); |
650 | 650 | ||
651 | #undef new_text | 651 | #undef new_text |
652 | return true; | 652 | return true; |
653 | } | 653 | } |
654 | 654 | ||
655 | QString Serializer::escapeEntryData(QString dta) | 655 | QString Serializer::escapeEntryData(QString dta) |
656 | { | 656 | { |
657 | #ifndef PWM_EMBEDDED | 657 | #ifndef PWM_EMBEDDED |
658 | dta.replace('\n', "$>--endl--<$"); | 658 | dta.replace('\n', "$>--endl--<$"); |
659 | dta.replace("]]>", "||>"); | 659 | dta.replace("]]>", "||>"); |
660 | #else | 660 | #else |
661 | dta.replace(QRegExp("\n"), "$>--endl--<$"); | 661 | dta.replace(QRegExp("\n"), "$>--endl--<$"); |
662 | dta.replace(QRegExp("]]>"), "||>"); | 662 | dta.replace(QRegExp("]]>"), "||>"); |
663 | #endif | 663 | #endif |
664 | return dta; | 664 | return dta; |
665 | } | 665 | } |
666 | 666 | ||
667 | QString Serializer::unescapeEntryData(QString dta) | 667 | QString Serializer::unescapeEntryData(QString dta) |
668 | { | 668 | { |
669 | #ifndef PWM_EMBEDDED | 669 | #ifndef PWM_EMBEDDED |
670 | dta.replace("$>--endl--<$", "\n"); | 670 | dta.replace("$>--endl--<$", "\n"); |
671 | dta.replace("||>", "]]>"); | 671 | dta.replace("||>", "]]>"); |
672 | #else | 672 | #else |
673 | dta.replace(QRegExp("$>--endl--<$"), "\n"); | 673 | dta.replace(QRegExp("$>--endl--<$"), "\n"); |
674 | dta.replace(QRegExp("||>"), "]]>"); | 674 | dta.replace(QRegExp("||>"), "]]>"); |
675 | #endif | 675 | #endif |
676 | return dta; | 676 | return dta; |
677 | } | 677 | } |