summaryrefslogtreecommitdiffabout
Unidiff
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--pwmanager/pwmanager/serializer.cpp2
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
@@ -161,513 +161,513 @@ void Serializer::clear()
161 161
162bool Serializer::parseXml(const QCString &buffer) 162bool 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
177QCString Serializer::getXml() 177QCString 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
209bool Serializer::serialize(const vector<PwMCategoryItem> &dta) 209bool 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
220bool Serializer::deSerialize(vector<PwMCategoryItem> *dta) 220bool 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
246bool Serializer::readCategories(const QDomNode &n, 246bool 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
284bool Serializer::readEntries(const QDomNode &n, 284bool 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
308bool Serializer::extractEntry(const QDomNode &n, 308bool 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
376bool Serializer::extractMeta(const QDomNode &n, 376bool 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
451bool Serializer::checkValid() 451bool 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
468QDomElement Serializer::genNewRoot() 468QDomElement 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
477bool Serializer::addCategories(QDomElement *e, 477bool 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
498bool Serializer::addEntries(QDomElement *e, 498bool 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
517bool Serializer::writeEntry(QDomElement *e, 517bool 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
599bool Serializer::writeMeta(QDomElement *e, 599bool 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
655QString Serializer::escapeEntryData(QString dta) 655QString 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
667QString Serializer::unescapeEntryData(QString dta) 667QString 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");