From 904cbf4f2a418d3cadc74a6168a4565ae6ebc3c5 Mon Sep 17 00:00:00 2001 From: ulf69 Date: Wed, 06 Oct 2004 00:35:59 +0000 Subject: *** empty log message *** --- (limited to 'pwmanager/pwmanager/serializer.cpp') 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 @@ #define META_UPDATE_INT "i" //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. * The names of the entries have changed and here are the @@ -206,18 +210,22 @@ QCString Serializer::getXml() #endif } -bool Serializer::serialize(const vector &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 *dta) +bool Serializer::deSerialize(PwMItem *dta) { PWM_ASSERT(domDoc); PWM_ASSERT(dta); @@ -230,17 +238,25 @@ bool Serializer::deSerialize(vector *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; } bool Serializer::readCategories(const QDomNode &n, @@ -661,3 +677,80 @@ QString Serializer::unescapeEntryData(QString dta) #endif 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 *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 &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; +} + -- cgit v0.9.0.2