summaryrefslogtreecommitdiffabout
path: root/pwmanager/pwmanager/serializer.cpp
authorulf69 <ulf69>2004-10-06 00:35:59 (UTC)
committer ulf69 <ulf69>2004-10-06 00:35:59 (UTC)
commit904cbf4f2a418d3cadc74a6168a4565ae6ebc3c5 (patch) (unidiff)
tree22bb491b5886234a0ed21b882df73732ea99bf84 /pwmanager/pwmanager/serializer.cpp
parent07fa092b413b7cde1bd4fc797ce0b30adcb8668d (diff)
downloadkdepimpi-904cbf4f2a418d3cadc74a6168a4565ae6ebc3c5.zip
kdepimpi-904cbf4f2a418d3cadc74a6168a4565ae6ebc3c5.tar.gz
kdepimpi-904cbf4f2a418d3cadc74a6168a4565ae6ebc3c5.tar.bz2
*** empty log message ***
Diffstat (limited to 'pwmanager/pwmanager/serializer.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r--pwmanager/pwmanager/serializer.cpp109
1 files changed, 101 insertions, 8 deletions
diff --git a/pwmanager/pwmanager/serializer.cpp b/pwmanager/pwmanager/serializer.cpp
index a54ba8a..f615082 100644
--- a/pwmanager/pwmanager/serializer.cpp
+++ b/pwmanager/pwmanager/serializer.cpp
@@ -41,6 +41,10 @@
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#define SYNC_ROOT "s"
45#define SYNC_TARGET_PREFIX "t"
46#define SYNC_TARGET_NAME "n"
47
44 48
45/* This is compatibility stuff. 49/* This is compatibility stuff.
46 * The names of the entries have changed and here are the 50 * The names of the entries have changed and here are the
@@ -206,18 +210,22 @@ QCString Serializer::getXml()
206#endif 210#endif
207} 211}
208 212
209bool Serializer::serialize(const vector<PwMCategoryItem> &dta) 213bool Serializer::serialize(PwMItem &dta)
210{ 214{
211 PWM_ASSERT(domDoc); 215 PWM_ASSERT(domDoc);
212 QDomElement root(genNewRoot()); 216 QDomElement root(genNewRoot());
213 QDomElement catNode(domDoc->createElement(CAT_ROOT_WR)); 217 QDomElement catNode(domDoc->createElement(CAT_ROOT_WR));
214 root.appendChild(catNode); 218 QDomElement syncNode(domDoc->createElement(SYNC_ROOT));
215 if (!addCategories(&catNode, dta)) 219 if (!addSyncData(&syncNode, dta.syncDta))
216 return false; 220 return false;
221 root.appendChild(syncNode);
222 if (!addCategories(&catNode, dta.dta))
223 return false;
224 root.appendChild(catNode);
217 return true; 225 return true;
218} 226}
219 227
220bool Serializer::deSerialize(vector<PwMCategoryItem> *dta) 228bool Serializer::deSerialize(PwMItem *dta)
221{ 229{
222 PWM_ASSERT(domDoc); 230 PWM_ASSERT(domDoc);
223 PWM_ASSERT(dta); 231 PWM_ASSERT(dta);
@@ -230,17 +238,25 @@ bool Serializer::deSerialize(vector<PwMCategoryItem> *dta)
230 // <c> ... </c> 238 // <c> ... </c>
231 if (n.nodeName() == CAT_ROOT_NEW || 239 if (n.nodeName() == CAT_ROOT_NEW ||
232 n.nodeName() == CAT_ROOT_OLD) { 240 n.nodeName() == CAT_ROOT_OLD) {
233 if (!readCategories(n, dta)) { 241 if (!readCategories(n, &(dta->dta))) {
234 return false; 242 return false;
235 } 243 }
244 continue;
245 }
246 else if (n.nodeName() == SYNC_ROOT) {
247 if (!readSyncData(n, &(dta->syncDta))) {
248 return false;
249 }
250 continue;
251 }
236 252
237 /* NOTE: We can stop processing here, as we 253 /* NOTE: We can stop processing here, as we
238 * don't have more nodes in root, yet. 254 * don't have more nodes in root, yet.
239 */ 255 */
240 return true; 256 return false;
241 } 257
242 } 258 }
243 return false; 259 return true;
244} 260}
245 261
246bool Serializer::readCategories(const QDomNode &n, 262bool Serializer::readCategories(const QDomNode &n,
@@ -661,3 +677,80 @@ QString Serializer::unescapeEntryData(QString dta)
661#endif 677#endif
662 return dta; 678 return dta;
663} 679}
680
681
682//US ENH: the following methods are getting used to write/read sync entries
683/** read the syncentries in the node "n" */
684bool Serializer::readSyncData(const QDomNode &n, vector<PwMSyncItem> *dta)
685{
686 QDomNodeList nl(n.childNodes());
687 QDomNode cur;
688
689 QString devicename, val;
690 unsigned int numSync = nl.count(), i;
691 PwMSyncItem curSync;
692 bool ok = true;
693
694 if (!numSync) {
695 //no sync entries is a possible result
696 printDebug("Serializer::readSyncData(): empty");
697 return true;
698 }
699 for (i = 0; i < numSync; ++i) {
700 cur = nl.item(i);
701 if (cur.nodeName().left(1) == SYNC_TARGET_PREFIX) {
702 devicename = cur.toElement().attribute(SYNC_TARGET_NAME);
703 val = cur.toElement().text();
704
705 if ((val == "") || (devicename == QString::null)) {
706 printDebug("Serializer::readSyncData(): empty synctarget name or syncdate");
707 continue;
708 }
709
710 curSync.syncName = devicename;
711#ifndef PWM_EMBEDDED
712 curSync.lastSyncDate = QDateTime::fromString(val, Qt::ISODate);
713#else
714 curSync.lastSyncDate = KGlobal::locale()->readDateTime(val, KLocale::ISODate, &ok);
715 if (ok == false)
716 qDebug("Serializer::readSyncData(): could not parse syncdate:%s",val.latin1());
717
718#endif
719 dta->push_back(curSync);
720 }
721 }
722 return true;
723
724}
725
726
727
728bool Serializer::addSyncData(QDomElement *e,
729 const vector<PwMSyncItem> &dta)
730{
731 unsigned int numSync = dta.size(), i;
732 QString curId, curDeviceName;
733 QDomElement curSync, curSyncDate;
734 QDomText text;
735
736 for (i = 0; i < numSync; ++i) {
737 curId = SYNC_TARGET_PREFIX;
738 curId += tostr(i).c_str();
739 curDeviceName = dta[i].syncName.c_str();
740 curSync = domDoc->createElement(curId);
741 curSync.setAttribute(SYNC_TARGET_NAME, curDeviceName);
742
743#ifndef PWM_EMBEDDED
744 text = domDoc->createTextNode(dta[i].lastSyncDate.toString(Qt::ISODate));
745#else
746 text = domDoc->createTextNode(KGlobal::locale()->formatDateTime(dta[i].lastSyncDate, KLocale::ISODate));
747#endif
748 curSyncDate.appendChild(text);
749 curSync.appendChild(curSyncDate);
750
751 e->appendChild(curSync);
752
753 }
754 return true;
755}
756