Diffstat (limited to 'pwmanager/pwmanager/serializer.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r-- | pwmanager/pwmanager/serializer.cpp | 109 |
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 @@ -43,2 +43,6 @@ #define META_UNIQUEID "n" +#define SYNC_ROOT "s" +#define SYNC_TARGET_PREFIX "t" +#define SYNC_TARGET_NAME "n" + @@ -208,3 +212,3 @@ QCString Serializer::getXml() -bool Serializer::serialize(const vector<PwMCategoryItem> &dta) +bool Serializer::serialize(PwMItem &dta) { @@ -213,5 +217,9 @@ bool Serializer::serialize(const vector<PwMCategoryItem> &dta) 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; @@ -219,3 +227,3 @@ bool Serializer::serialize(const vector<PwMCategoryItem> &dta) -bool Serializer::deSerialize(vector<PwMCategoryItem> *dta) +bool Serializer::deSerialize(PwMItem *dta) { @@ -232,5 +240,13 @@ bool Serializer::deSerialize(vector<PwMCategoryItem> *dta) 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; + } @@ -239,6 +255,6 @@ bool Serializer::deSerialize(vector<PwMCategoryItem> *dta) */ - return true; - } + return false; + } - return false; + return true; } @@ -663 +679,78 @@ QString Serializer::unescapeEntryData(QString 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; +} + |