summaryrefslogtreecommitdiffabout
path: root/pwmanager/pwmanager/serializer.cpp
Side-by-side diff
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
@@ -42,4 +42,8 @@
//US ENH : uniqueid
#define META_UNIQUEID "n"
+#define SYNC_ROOT "s"
+#define SYNC_TARGET_PREFIX "t"
+#define SYNC_TARGET_NAME "n"
+
/* This is compatibility stuff.
@@ -207,16 +211,20 @@ QCString Serializer::getXml()
}
-bool Serializer::serialize(const vector<PwMCategoryItem> &dta)
+bool Serializer::serialize(PwMItem &dta)
{
PWM_ASSERT(domDoc);
QDomElement root(genNewRoot());
QDomElement catNode(domDoc->createElement(CAT_ROOT_WR));
- root.appendChild(catNode);
- if (!addCategories(&catNode, dta))
+ QDomElement syncNode(domDoc->createElement(SYNC_ROOT));
+ if (!addSyncData(&syncNode, dta.syncDta))
return false;
+ root.appendChild(syncNode);
+ if (!addCategories(&catNode, dta.dta))
+ return false;
+ root.appendChild(catNode);
return true;
}
-bool Serializer::deSerialize(vector<PwMCategoryItem> *dta)
+bool Serializer::deSerialize(PwMItem *dta)
{
PWM_ASSERT(domDoc);
@@ -231,15 +239,23 @@ bool Serializer::deSerialize(vector<PwMCategoryItem> *dta)
if (n.nodeName() == CAT_ROOT_NEW ||
n.nodeName() == CAT_ROOT_OLD) {
- if (!readCategories(n, dta)) {
+ if (!readCategories(n, &(dta->dta))) {
return false;
}
+ continue;
+ }
+ else if (n.nodeName() == SYNC_ROOT) {
+ if (!readSyncData(n, &(dta->syncDta))) {
+ return false;
+ }
+ continue;
+ }
/* NOTE: We can stop processing here, as we
* don't have more nodes in root, yet.
*/
- return true;
- }
+ return false;
+
}
- return false;
+ return true;
}
@@ -662,2 +678,79 @@ QString Serializer::unescapeEntryData(QString dta)
return dta;
}
+
+
+//US ENH: the following methods are getting used to write/read sync entries
+/** read the syncentries in the node "n" */
+bool Serializer::readSyncData(const QDomNode &n, vector<PwMSyncItem> *dta)
+{
+ QDomNodeList nl(n.childNodes());
+ QDomNode cur;
+
+ QString devicename, val;
+ unsigned int numSync = nl.count(), i;
+ PwMSyncItem curSync;
+ bool ok = true;
+
+ if (!numSync) {
+ //no sync entries is a possible result
+ printDebug("Serializer::readSyncData(): empty");
+ return true;
+ }
+ for (i = 0; i < numSync; ++i) {
+ cur = nl.item(i);
+ if (cur.nodeName().left(1) == SYNC_TARGET_PREFIX) {
+ devicename = cur.toElement().attribute(SYNC_TARGET_NAME);
+ val = cur.toElement().text();
+
+ if ((val == "") || (devicename == QString::null)) {
+ printDebug("Serializer::readSyncData(): empty synctarget name or syncdate");
+ continue;
+ }
+
+ curSync.syncName = devicename;
+#ifndef PWM_EMBEDDED
+ curSync.lastSyncDate = QDateTime::fromString(val, Qt::ISODate);
+#else
+ curSync.lastSyncDate = KGlobal::locale()->readDateTime(val, KLocale::ISODate, &ok);
+ if (ok == false)
+ qDebug("Serializer::readSyncData(): could not parse syncdate:%s",val.latin1());
+
+#endif
+ dta->push_back(curSync);
+ }
+ }
+ return true;
+
+}
+
+
+
+bool Serializer::addSyncData(QDomElement *e,
+ const vector<PwMSyncItem> &dta)
+{
+ unsigned int numSync = dta.size(), i;
+ QString curId, curDeviceName;
+ QDomElement curSync, curSyncDate;
+ QDomText text;
+
+ for (i = 0; i < numSync; ++i) {
+ curId = SYNC_TARGET_PREFIX;
+ curId += tostr(i).c_str();
+ curDeviceName = dta[i].syncName.c_str();
+ curSync = domDoc->createElement(curId);
+ curSync.setAttribute(SYNC_TARGET_NAME, curDeviceName);
+
+#ifndef PWM_EMBEDDED
+ text = domDoc->createTextNode(dta[i].lastSyncDate.toString(Qt::ISODate));
+#else
+ text = domDoc->createTextNode(KGlobal::locale()->formatDateTime(dta[i].lastSyncDate, KLocale::ISODate));
+#endif
+ curSyncDate.appendChild(text);
+ curSync.appendChild(curSyncDate);
+
+ e->appendChild(curSync);
+
+ }
+ return true;
+}
+