summaryrefslogtreecommitdiffabout
path: root/pwmanager
authorulf69 <ulf69>2004-10-06 00:35:59 (UTC)
committer ulf69 <ulf69>2004-10-06 00:35:59 (UTC)
commit904cbf4f2a418d3cadc74a6168a4565ae6ebc3c5 (patch) (side-by-side diff)
tree22bb491b5886234a0ed21b882df73732ea99bf84 /pwmanager
parent07fa092b413b7cde1bd4fc797ce0b30adcb8668d (diff)
downloadkdepimpi-904cbf4f2a418d3cadc74a6168a4565ae6ebc3c5.zip
kdepimpi-904cbf4f2a418d3cadc74a6168a4565ae6ebc3c5.tar.gz
kdepimpi-904cbf4f2a418d3cadc74a6168a4565ae6ebc3c5.tar.bz2
*** empty log message ***
Diffstat (limited to 'pwmanager') (more/less context) (ignore whitespace changes)
-rw-r--r--pwmanager/pwmanager/pwmanagerE.pro2
-rw-r--r--pwmanager/pwmanager/pwmdoc.cpp568
-rw-r--r--pwmanager/pwmanager/pwmdoc.h70
-rw-r--r--pwmanager/pwmanager/pwmdocui.cpp2
-rw-r--r--pwmanager/pwmanager/pwmexception.h1
-rw-r--r--pwmanager/pwmanager/pwmview.cpp64
-rw-r--r--pwmanager/pwmanager/pwmview.h22
-rw-r--r--pwmanager/pwmanager/serializer.cpp109
-rw-r--r--pwmanager/pwmanager/serializer.h17
9 files changed, 746 insertions, 109 deletions
diff --git a/pwmanager/pwmanager/pwmanagerE.pro b/pwmanager/pwmanager/pwmanagerE.pro
index 2558aca..95f5bf3 100644
--- a/pwmanager/pwmanager/pwmanagerE.pro
+++ b/pwmanager/pwmanager/pwmanagerE.pro
@@ -9,3 +9,3 @@ DESTDIR=$(QPEDIR)/bin
-INCLUDEPATH += . ../../qtcompat ../../qtcompat/xml ../../libkdepim ../../microkde ../../microkde/kdecore ../../microkde/kdeui ../../microkde/kutils $(QPEDIR)/include
+INCLUDEPATH += . ../../ ../../qtcompat ../../qtcompat/xml ../../libkdepim ../../microkde ../../microkde/kdecore ../../microkde/kdeui ../../microkde/kutils $(QPEDIR)/include
DEFINES += PWM_EMBEDDED
diff --git a/pwmanager/pwmanager/pwmdoc.cpp b/pwmanager/pwmanager/pwmdoc.cpp
index 82fc746..4e8a603 100644
--- a/pwmanager/pwmanager/pwmdoc.cpp
+++ b/pwmanager/pwmanager/pwmdoc.cpp
@@ -37,2 +37,6 @@
+#include <kmessagebox.h>
+#include <libkcal/syncdefines.h>
+
+
#ifdef CONFIG_KWALLETIF
@@ -1009,3 +1013,3 @@ PwMerror PwMDoc::addEntry(const QString &category, PwMDataItem *d,
}
- dta[cat].d.push_back(*d);
+ dti.dta[cat].d.push_back(*d);
@@ -1033,5 +1037,5 @@ PwMerror PwMDoc::addCategory(const QString &category, unsigned int *categoryInde
item.name = category.latin1();
- dta.push_back(item);
+ dti.dta.push_back(item);
if (categoryIndex)
- *categoryIndex = dta.size() - 1;
+ *categoryIndex = dti.dta.size() - 1;
return e_success;
@@ -1055,3 +1059,3 @@ bool PwMDoc::delEntry(unsigned int category, unsigned int index, bool dontFlagDi
return false;
- if (index > dta[category].d.size() - 1)
+ if (index > dti.dta[category].d.size() - 1)
return false;
@@ -1063,6 +1067,6 @@ bool PwMDoc::delEntry(unsigned int category, unsigned int index, bool dontFlagDi
putDataChangedLock();
- int lvPos = dta[category].d[index].listViewPos;
+ int lvPos = dti.dta[category].d[index].listViewPos;
// delete entry
- dta[category].d.erase(dta[category].d.begin() + index);
+ dti.dta[category].d.erase(dti.dta[category].d.begin() + index);
@@ -1078,4 +1082,4 @@ bool PwMDoc::delEntry(unsigned int category, unsigned int index, bool dontFlagDi
// decrement all listViewPositions that are greater than the deleted.
- if (dta[category].d[i].listViewPos > lvPos)
- --dta[category].d[i].listViewPos;
+ if (dti.dta[category].d[i].listViewPos > lvPos)
+ --dti.dta[category].d[i].listViewPos;
}
@@ -1112,3 +1116,3 @@ bool PwMDoc::editEntry(unsigned int oldCategory, const QString &newCategory,
}
- if (dta[oldCategory].name != newCategory.latin1()) {
+ if (dti.dta[oldCategory].name != newCategory.latin1()) {
// the user changed the category.
@@ -1122,4 +1126,4 @@ bool PwMDoc::editEntry(unsigned int oldCategory, const QString &newCategory,
} else {
- d->rev = dta[oldCategory].d[index].rev + 1; // increment revision counter.
- dta[oldCategory].d[index] = *d;
+ d->rev = dti.dta[oldCategory].d[index].rev + 1; // increment revision counter.
+ dti.dta[oldCategory].d[index] = *d;
}
@@ -1145,3 +1149,3 @@ bool PwMDoc::serializeDta(string *d)
Serializer ser;
- if (!ser.serialize(dta))
+ if (!ser.serialize(dti))
return false;
@@ -1161,3 +1165,3 @@ bool PwMDoc::deSerializeDta(const string *d, bool entriesLocked)
ser.setDefaultLockStat(entriesLocked);
- if (!ser.deSerialize(&dta))
+ if (!ser.deSerialize(&dti))
return false;
@@ -1169,3 +1173,3 @@ bool PwMDoc::deSerializeDta(const string *d, bool entriesLocked)
ser.setDefaultLockStat(entriesLocked);
- if (!ser.deSerialize(&dta))
+ if (!ser.deSerialize(&dti))
return false;
@@ -1194,3 +1198,3 @@ bool PwMDoc::getEntry(unsigned int category, unsigned int index,
{
- if (index > dta[category].d.size() - 1)
+ if (index > dti.dta[category].d.size() - 1)
return false;
@@ -1211,3 +1215,3 @@ bool PwMDoc::getEntry(unsigned int category, unsigned int index,
- *d = dta[category].d[index];
+ *d = dti.dta[category].d[index];
if (locked)
@@ -1229,5 +1233,5 @@ PwMerror PwMDoc::getCommentByLvp(const QString &category, int listViewPos,
for (i = 0; i < entries; ++i) {
- if (dta[cat].d[i].listViewPos == listViewPos) {
- *foundComment = dta[cat].d[i].comment;
- if (dta[cat].d[i].binary)
+ if (dti.dta[cat].d[i].listViewPos == listViewPos) {
+ *foundComment = dti.dta[cat].d[i].comment;
+ if (dti.dta[cat].d[i].binary)
return e_binEntry;
@@ -1492,3 +1496,3 @@ bool PwMDoc::lockAt(unsigned int category, unsigned int index,
}
- if (lock == dta[category].d[index].lockStat)
+ if (lock == dti.dta[category].d[index].lockStat)
return true;
@@ -1516,4 +1520,4 @@ bool PwMDoc::lockAt(unsigned int category, unsigned int index,
- dta[category].d[index].lockStat = lock;
- dta[category].d[index].rev++; // increment revision counter.
+ dti.dta[category].d[index].lockStat = lock;
+ dti.dta[category].d[index].rev++; // increment revision counter.
@@ -1573,4 +1577,4 @@ bool PwMDoc::lockAll(bool lock)
- vector<PwMCategoryItem>::iterator catBegin = dta.begin(),
- catEnd = dta.end(),
+ vector<PwMCategoryItem>::iterator catBegin = dti.dta.begin(),
+ catEnd = dti.dta.end(),
catI = catBegin;
@@ -1647,4 +1651,4 @@ bool PwMDoc::unlockAll_tempoary(bool revert)
}
- vector<PwMCategoryItem>::iterator catBegin = dta.begin(),
- catEnd = dta.end(),
+ vector<PwMCategoryItem>::iterator catBegin = dti.dta.begin(),
+ catEnd = dti.dta.end(),
catI = catBegin;
@@ -1731,4 +1735,4 @@ bool PwMDoc::unlockAll_tempoary(bool revert)
// first check if it's needed to unlock some entries
- vector<PwMCategoryItem>::iterator catBegin = dta.begin(),
- catEnd = dta.end(),
+ vector<PwMCategoryItem>::iterator catBegin = dti.dta.begin(),
+ catEnd = dti.dta.end(),
catI = catBegin;
@@ -1777,4 +1781,4 @@ bool PwMDoc::unlockAll_tempoary(bool revert)
vector<bool> tmp_vec;
- vector<PwMCategoryItem>::iterator catBegin = dta.begin(),
- catEnd = dta.end(),
+ vector<PwMCategoryItem>::iterator catBegin = dti.dta.begin(),
+ catEnd = dti.dta.end(),
catI = catBegin;
@@ -1862,6 +1866,6 @@ void PwMDoc::clearDoc()
{
- dta.clear();
+ dti.clear();
PwMCategoryItem d;
d.name = DEFAULT_CATEGORY.latin1();
- dta.push_back(d);
+ dti.dta.push_back(d);
currentPw = "";
@@ -1900,3 +1904,3 @@ void PwMDoc::setListViewPos(unsigned int category, unsigned int index,
{
- dta[category].d[index].listViewPos = pos;
+ dti.dta[category].d[index].listViewPos = pos;
@@ -1920,3 +1924,3 @@ int PwMDoc::getListViewPos(const QString &category, unsigned int index)
- return dta[cat].d[index].listViewPos;
+ return dti.dta[cat].d[index].listViewPos;
}
@@ -1934,3 +1938,3 @@ void PwMDoc::findEntry(unsigned int category, PwMDataItem find, unsigned int sea
if (searchIn & SEARCH_IN_DESC) {
- if (!compareString(find.desc, dta[category].d[i].desc,
+ if (!compareString(find.desc, dti.dta[category].d[i].desc,
caseSensitive, exactWordMatch)) {
@@ -1940,3 +1944,3 @@ void PwMDoc::findEntry(unsigned int category, PwMDataItem find, unsigned int sea
if (searchIn & SEARCH_IN_NAME) {
- if (!compareString(find.name, dta[category].d[i].name,
+ if (!compareString(find.name, dti.dta[category].d[i].name,
caseSensitive, exactWordMatch)) {
@@ -1949,3 +1953,3 @@ void PwMDoc::findEntry(unsigned int category, PwMDataItem find, unsigned int sea
lockAt(category, i, false);
- if (!compareString(find.pw, dta[category].d[i].pw,
+ if (!compareString(find.pw, dti.dta[category].d[i].pw,
caseSensitive, exactWordMatch)) {
@@ -1959,3 +1963,3 @@ void PwMDoc::findEntry(unsigned int category, PwMDataItem find, unsigned int sea
if (searchIn & SEARCH_IN_COMMENT) {
- if (!compareString(find.comment, dta[category].d[i].comment,
+ if (!compareString(find.comment, dti.dta[category].d[i].comment,
caseSensitive, exactWordMatch)) {
@@ -1965,3 +1969,3 @@ void PwMDoc::findEntry(unsigned int category, PwMDataItem find, unsigned int sea
if (searchIn & SEARCH_IN_URL) {
- if (!compareString(find.url, dta[category].d[i].url,
+ if (!compareString(find.url, dti.dta[category].d[i].url,
caseSensitive, exactWordMatch)) {
@@ -1971,3 +1975,3 @@ void PwMDoc::findEntry(unsigned int category, PwMDataItem find, unsigned int sea
if (searchIn & SEARCH_IN_LAUNCHER) {
- if (!compareString(find.launcher, dta[category].d[i].launcher,
+ if (!compareString(find.launcher, dti.dta[category].d[i].launcher,
caseSensitive, exactWordMatch)) {
@@ -1991,3 +1995,3 @@ void PwMDoc::findEntry(unsigned int category, PwMDataItem find, unsigned int sea
tmp_pair.first = (*foundPositions)[i];
- tmp_pair.second = dta[category].d[(*foundPositions)[i]].listViewPos;
+ tmp_pair.second = dti.dta[category].d[(*foundPositions)[i]].listViewPos;
tmp_vec.push_back(tmp_pair);
@@ -2034,4 +2038,4 @@ bool PwMDoc::findCategory(const QString &name, unsigned int *index)
{
- vector<PwMCategoryItem>::iterator i = dta.begin(),
- end = dta.end();
+ vector<PwMCategoryItem>::iterator i = dti.dta.begin(),
+ end = dti.dta.end();
while (i != end) {
@@ -2039,3 +2043,3 @@ bool PwMDoc::findCategory(const QString &name, unsigned int *index)
if (index) {
- *index = i - dta.begin();
+ *index = i - dti.dta.begin();
}
@@ -2064,3 +2068,3 @@ bool PwMDoc::renameCategory(unsigned int category, const QString &newName,
- dta[category].name = newName.latin1();
+ dti.dta[category].name = newName.latin1();
if (!dontFlagDirty)
@@ -2089,3 +2093,3 @@ bool PwMDoc::delCategory(unsigned int category, bool dontFlagDirty)
if (numCategories() > 1) {
- dta.erase(dta.begin() + category);
+ dti.dta.erase(dti.dta.begin() + category);
} else {
@@ -2102,4 +2106,4 @@ void PwMDoc::delAllEmptyCat(bool dontFlagDirty)
{
- vector<PwMCategoryItem>::iterator begin = dta.begin(),
- end = dta.end(),
+ vector<PwMCategoryItem>::iterator begin = dti.dta.begin(),
+ end = dti.dta.end(),
i = begin;
@@ -2117,4 +2121,4 @@ void PwMDoc::getCategoryList(vector<string> *list)
list->clear();
- vector<PwMCategoryItem>::iterator i = dta.begin(),
- end = dta.end();
+ vector<PwMCategoryItem>::iterator i = dti.dta.begin(),
+ end = dti.dta.end();
while (i != end) {
@@ -2129,4 +2133,4 @@ void PwMDoc::getCategoryList(QStringList *list)
list->clear();
- vector<PwMCategoryItem>::iterator i = dta.begin(),
- end = dta.end();
+ vector<PwMCategoryItem>::iterator i = dti.dta.begin(),
+ end = dti.dta.end();
while (i != end) {
@@ -2167,4 +2171,4 @@ void PwMDoc::getEntryList(unsigned int category, vector<string> *list)
list->clear();
- vector<PwMDataItem>::iterator begin = dta[category].d.begin(),
- end = dta[category].d.end(),
+ vector<PwMDataItem>::iterator begin = dti.dta[category].d.begin(),
+ end = dti.dta[category].d.end(),
i = begin;
@@ -2180,4 +2184,4 @@ void PwMDoc::getEntryList(unsigned int category, QStringList *list)
list->clear();
- vector<PwMDataItem>::iterator begin = dta[category].d.begin(),
- end = dta[category].d.end(),
+ vector<PwMDataItem>::iterator begin = dti.dta[category].d.begin(),
+ end = dti.dta[category].d.end(),
i = begin;
@@ -2209,3 +2213,3 @@ bool PwMDoc::execLauncher(unsigned int category, unsigned int entryIndex)
}
- QString command(dta[category].d[entryIndex].launcher.c_str());
+ QString command(dti.dta[category].d[entryIndex].launcher.c_str());
bool wasLocked = isLocked(category, entryIndex);
@@ -2221,13 +2225,13 @@ bool PwMDoc::execLauncher(unsigned int category, unsigned int entryIndex)
#ifndef PWM_EMBEDDED
- command.replace("$d", dta[category].d[entryIndex].desc.c_str());
- command.replace("$n", dta[category].d[entryIndex].name.c_str());
- command.replace("$p", dta[category].d[entryIndex].pw.c_str());
- command.replace("$u", dta[category].d[entryIndex].url.c_str());
- command.replace("$c", dta[category].d[entryIndex].comment.c_str());
+ command.replace("$d", dti.dta[category].d[entryIndex].desc.c_str());
+ command.replace("$n", dti.dta[category].d[entryIndex].name.c_str());
+ command.replace("$p", dti.dta[category].d[entryIndex].pw.c_str());
+ command.replace("$u", dti.dta[category].d[entryIndex].url.c_str());
+ command.replace("$c", dti.dta[category].d[entryIndex].comment.c_str());
#else
- command.replace(QRegExp("$d"), dta[category].d[entryIndex].desc.c_str());
- command.replace(QRegExp("$n"), dta[category].d[entryIndex].name.c_str());
- command.replace(QRegExp("$p"), dta[category].d[entryIndex].pw.c_str());
- command.replace(QRegExp("$u"), dta[category].d[entryIndex].url.c_str());
- command.replace(QRegExp("$c"), dta[category].d[entryIndex].comment.c_str());
+ command.replace(QRegExp("$d"), dti.dta[category].d[entryIndex].desc.c_str());
+ command.replace(QRegExp("$n"), dti.dta[category].d[entryIndex].name.c_str());
+ command.replace(QRegExp("$p"), dti.dta[category].d[entryIndex].pw.c_str());
+ command.replace(QRegExp("$u"), dti.dta[category].d[entryIndex].url.c_str());
+ command.replace(QRegExp("$c"), dti.dta[category].d[entryIndex].comment.c_str());
#endif
@@ -2261,3 +2265,3 @@ bool PwMDoc::goToURL(unsigned int category, unsigned int entryIndex)
}
- QString url(dta[category].d[entryIndex].url.c_str());
+ QString url(dti.dta[category].d[entryIndex].url.c_str());
if (url.isEmpty())
@@ -2352,3 +2356,3 @@ PwMerror PwMDoc::exportToText(const QString *file)
exp = "\n== Category: ";
- exp += dta[i].name;
+ exp += dti.dta[i].name;
exp += " ==\n";
@@ -2369,3 +2373,3 @@ PwMerror PwMDoc::exportToText(const QString *file)
exp = "\n-- ";
- exp += dta[i].d[j].desc;
+ exp += dti.dta[i].d[j].desc;
exp += " --\n";
@@ -2373,3 +2377,3 @@ PwMerror PwMDoc::exportToText(const QString *file)
exp += i18n("Username: ").latin1();
- exp += dta[i].d[j].name;
+ exp += dti.dta[i].d[j].name;
exp += "\n";
@@ -2377,3 +2381,3 @@ PwMerror PwMDoc::exportToText(const QString *file)
exp += i18n("Password: ").latin1();
- exp += dta[i].d[j].pw;
+ exp += dti.dta[i].d[j].pw;
exp += "\n";
@@ -2381,3 +2385,3 @@ PwMerror PwMDoc::exportToText(const QString *file)
exp += i18n("Comment: ").latin1();
- exp += dta[i].d[j].comment;
+ exp += dti.dta[i].d[j].comment;
exp += "\n";
@@ -2385,3 +2389,3 @@ PwMerror PwMDoc::exportToText(const QString *file)
exp += i18n("URL: ").latin1();
- exp += dta[i].d[j].url;
+ exp += dti.dta[i].d[j].url;
exp += "\n";
@@ -2389,3 +2393,3 @@ PwMerror PwMDoc::exportToText(const QString *file)
exp += i18n("Launcher: ").latin1();
- exp += dta[i].d[j].launcher;
+ exp += dti.dta[i].d[j].launcher;
exp += "\n";
@@ -2422,3 +2426,3 @@ PwMerror PwMDoc::importFromText(const QString *file, int format)
return e_success;
- dta.clear();
+ dti.clear();
emitDataChanged(this);
@@ -2616,6 +2620,6 @@ PwMerror PwMDoc::exportToGpasman(const QString *file)
for (j = 0; j < numEntr; ++j) {
- descLen = dta[i].d[j].desc.length();
- nameLen = dta[i].d[j].name.length();
- pwLen = dta[i].d[j].pw.length();
- commentLen = dta[i].d[j].comment.length();
+ descLen = dti.dta[i].d[j].desc.length();
+ nameLen = dti.dta[i].d[j].name.length();
+ pwLen = dti.dta[i].d[j].pw.length();
+ commentLen = dti.dta[i].d[j].comment.length();
entry[0] = new char[descLen + 1];
@@ -2624,6 +2628,6 @@ PwMerror PwMDoc::exportToGpasman(const QString *file)
entry[3] = new char[commentLen + 1];
- strcpy(entry[0], descLen == 0 ? " " : dta[i].d[j].desc.c_str());
- strcpy(entry[1], nameLen == 0 ? " " : dta[i].d[j].name.c_str());
- strcpy(entry[2], pwLen == 0 ? " " : dta[i].d[j].pw.c_str());
- strcpy(entry[3], commentLen == 0 ? " " : dta[i].d[j].comment.c_str());
+ strcpy(entry[0], descLen == 0 ? " " : dti.dta[i].d[j].desc.c_str());
+ strcpy(entry[1], nameLen == 0 ? " " : dti.dta[i].d[j].name.c_str());
+ strcpy(entry[2], pwLen == 0 ? " " : dti.dta[i].d[j].pw.c_str());
+ strcpy(entry[3], commentLen == 0 ? " " : dti.dta[i].d[j].comment.c_str());
entry[0][descLen == 0 ? descLen + 1 : descLen] = '\0';
@@ -2707,4 +2711,4 @@ void PwMDoc::ensureLvp()
undefI;
- vector<PwMCategoryItem>::iterator catBegin = dta.begin(),
- catEnd = dta.end(),
+ vector<PwMCategoryItem>::iterator catBegin = dti.dta.begin(),
+ catEnd = dti.dta.end(),
catI = catBegin;
@@ -2787,5 +2791,5 @@ out_ignore:
//US ENH: this is the magic function that syncronizes the this doc with the remote doc
+//US it could have been defined as static, but I did not want to.
PwMerror PwMDoc::syncronize(KSyncManager* manager, PwMDoc* syncLocal , PwMDoc* syncRemote, int mode )
{
- bool syncOK = true;
int addedPasswordsLocal = 0;
@@ -2797,2 +2801,5 @@ PwMerror PwMDoc::syncronize(KSyncManager* manager, PwMDoc* syncLocal , PwMDoc* s
+ PwMSyncItem* syncItemLocal;
+ PwMSyncItem* syncItemRemote;
+
QString mCurrentSyncName = manager->getCurrentSyncName();
@@ -2800,10 +2807,193 @@ PwMerror PwMDoc::syncronize(KSyncManager* manager, PwMDoc* syncLocal , PwMDoc* s
+ bool fullDateRange = false;
+ int take;
+ // local->resetTempSyncStat();
+ QDateTime mLastSync = QDateTime::currentDateTime();
+ QDateTime modifiedSync = mLastSync;
+
+ unsigned int index;
+ //Step 1. Find syncinfo in Local file and create if not existent.
+ bool found = syncLocal->findSyncData(mCurrentSyncDevice, &index);
+ if (found == false)
+ {
+ PwMSyncItem newSyncItemLocal;
+ newSyncItemLocal.syncName = mCurrentSyncDevice;
+ newSyncItemLocal.lastSyncDate = mLastSync;
+ syncLocal->addSyncDataEntry(&newSyncItemLocal, true);
+ found = syncLocal->findSyncData(mCurrentSyncDevice, &index);
+ if (found == false) {
+ qDebug("PwMDoc::syncronize : newly created local sync data could not be found");
+ return e_syncError;
+ }
+ }
+
+ syncItemLocal = syncLocal->getSyncDataEntry(index);
+ qDebug("Last Sync %s ", syncItemLocal->lastSyncDate.toString().latin1());
+
+ //Step 2. Find syncinfo in remote file and create if not existent.
+ found = syncRemote->findSyncData(mCurrentSyncName, &index);
+ if (found == false)
+ {
+ qDebug("FULLDATE 1");
+ fullDateRange = true;
+ PwMSyncItem newSyncItemRemote;
+ newSyncItemRemote.syncName = mCurrentSyncName;
+ newSyncItemRemote.lastSyncDate = mLastSync;
+ syncRemote->addSyncDataEntry(&newSyncItemRemote, true);
+ found = syncRemote->findSyncData(mCurrentSyncName, &index);
+ if (found == false) {
+ qDebug("PwMDoc::syncronize : newly created remote sync data could not be found");
+ return e_syncError;
+ }
+ }
+
+ syncItemRemote = syncRemote->getSyncDataEntry(index);
+ //and remove the found entry here. We will reenter it later again.
+ syncRemote->delSyncDataEntry(index, true);
+ if ( syncItemLocal->lastSyncDate == mLastSync ) {
+ qDebug("FULLDATE 2");
+ fullDateRange = true;
+ }
+
+ if ( ! fullDateRange ) {
+ if ( syncItemLocal->lastSyncDate != syncItemRemote->lastSyncDate ) {
+
+ // qDebug("set fulldate to true %s %s" ,addresseeLSync->dtStart().toString().latin1(), addresseeRSync->dtStart().toString().latin1() );
+ //qDebug("%d %d %d %d ", addresseeLSync->dtStart().time().second(), addresseeLSync->dtStart().time().msec() , addresseeRSync->dtStart().time().second(), addresseeRSync->dtStart().time().msec());
+ fullDateRange = true;
+ qDebug("FULLDATE 3 %s %s", syncItemLocal->lastSyncDate.toString().latin1() , syncItemRemote->lastSyncDate.toString().latin1() );
+ }
+ }
+ // fullDateRange = true; // debug only!
+ if ( fullDateRange )
+ mLastSync = QDateTime::currentDateTime().addDays( -100*365);
+ else
+ mLastSync = syncItemLocal->lastSyncDate;
+
+
+ qDebug("*************************** ");
+ // qDebug("mLastAddressbookSync %s ",mLastAddressbookSync.toString().latin1() );
+ QStringList er = syncRemote->getIDEntryList();
+ PwMDataItem* inRemote ;//= er.first();
+ PwMDataItem* inLocal;
+ unsigned int catLocal, indexLocal;
+ unsigned int catRemote, indexRemote;
+
+ QString uid;
+ manager->showProgressBar(0, i18n("Syncing - close to abort!"), er.count());
+
+ int modulo = (er.count()/10)+1;
+ unsigned int incCounter = 0;
+ while ( incCounter < er.count()) {
+ if (manager->isProgressBarCanceled())
+ return e_syncError;
+ if ( incCounter % modulo == 0 )
+ manager->showProgressBar(incCounter);
+
+ uid = er[ incCounter ];
+ qApp->processEvents();
+
+ inLocal = syncLocal->findEntryByID( uid, &catLocal, &indexLocal );
+ inRemote = syncRemote->findEntryByID( uid, &catRemote, &indexRemote );
+ if ( inLocal != 0 ) { // maybe conflict - same uid in both files
+ if ( (take = takePwMDataItem( inLocal, inRemote, mLastSync, mode, fullDateRange) ) ) {
+ //qDebug("take %d %s ", take, inL.summary().latin1());
+ if ( take == 3 )
+ return e_syncError;
+ if ( take == 1 ) {// take local
+ //US syncRemote->removeAddressee( inRemote );
+ (*inRemote) = (*inLocal);
+ //US syncRemote->insertAddressee( inRemote , false);
+ ++changedRemote;
+ } else { // take == 2 take remote
+ //US syncLocal->removeAddressee( inLocal );
+ (*inLocal) = (*inRemote);
+ //US syncLocal->insertAddressee( inLocal , false );
+ ++changedLocal;
+ }
+ }
+ } else { // no conflict
+ if ( inRemote->meta.update > mLastSync || mode == 5 ) {
+ inRemote->meta.update = modifiedSync;
+ //US syncRemote->insertAddressee( inRemote, false );
+ //US syncLocal->insertAddressee( inRemote, false );
+ syncLocal->addEntry("newcategory", inRemote, true, false);
+
+ ++addedPasswordsLocal;
+ } else {
+ // pending checkExternSyncAddressee(addresseeRSyncSharp, inR);
+ syncRemote->delEntry(catRemote, indexRemote, true);
+ //USsyncRemote->removeAddressee( inRemote );
+ ++deletedPasswordsRemote;
+ }
+ }
+
+ ++incCounter;
+ }
+ er.clear();
+ QStringList el = syncLocal->getIDEntryList();
+ modulo = (el.count()/10)+1;
+
+ manager->showProgressBar(0, i18n("Add / remove addressees"), el.count());
+ incCounter = 0;
+ while ( incCounter < el.count()) {
+ qApp->processEvents();
+ if (manager->isProgressBarCanceled())
+ return e_syncError;
+ if ( incCounter % modulo == 0 )
+ manager->showProgressBar(incCounter);
+ uid = el[ incCounter ];
+
+ inLocal = syncLocal->findEntryByID( uid, &catLocal, &indexLocal );
+ inRemote = syncRemote->findEntryByID( uid, &catRemote, &indexRemote );
+ if ( inRemote == 0 ) {
+ if ( inLocal->meta.update < mLastSync && mode != 4 ) {
+ // pending checkExternSyncAddressee(addresseeLSyncSharp, inL);
+ syncLocal->delEntry(catLocal, indexLocal, true);
+ //USsyncLocal->removeAddressee( inLocal );
+ ++deletedPasswordsLocal;
+ } else {
+ if ( ! PWMPrefs::instance()->mWriteBackExistingOnly ) {
+ ++addedPasswordsRemote;
+ inLocal->meta.update = modifiedSync;
+ //USsyncLocal->insertAddressee( inLocal, false );
+ (*inRemote) = (*inLocal);
+ //USsyncRemote->insertAddressee( inRemote, false );
+ syncRemote->addEntry("newcategory", inRemote, true, false);
+
+ }
+ }
+
+ }
+ ++incCounter;
+ }
+ el.clear();
+ manager->hideProgressBar();
+
+ // Now write the info back into the sync data space of the files
+ mLastSync = QDateTime::currentDateTime().addSecs( 1 );
+ // get rid of micro seconds
+ QTime t = mLastSync.time();
+ mLastSync.setTime( QTime (t.hour (), t.minute (), t.second () ) );
+
+ syncItemLocal->lastSyncDate = mLastSync;
+ syncItemRemote->lastSyncDate = mLastSync;
+ // addresseeRSync.setRole( i18n("!Remote from: ")+mCurrentSyncName ) ;
+ // addresseeLSync.setRole(i18n("!Local from: ") + mCurrentSyncName );
+ syncRemote->addSyncDataEntry( syncItemRemote, false );
+ syncLocal->addSyncDataEntry( syncItemLocal, false );
+ QString mes;
+ mes .sprintf( i18n("Synchronization summary:\n\n %d items added to local\n %d items added to remote\n %d items updated on local\n %d items updated on remote\n %d items deleted on local\n %d items deleted on remote\n"),addedPasswordsLocal, addedPasswordsRemote, changedLocal, changedRemote, deletedPasswordsLocal, deletedPasswordsRemote );
+ if ( PWMPrefs::instance()->mShowSyncSummary ) {
+ KMessageBox::information(0, mes, i18n("PWM/Pi Synchronization") );
+ }
+ qDebug( mes );
return e_success;
@@ -2812,2 +3002,90 @@ PwMerror PwMDoc::syncronize(KSyncManager* manager, PwMDoc* syncLocal , PwMDoc* s
+int PwMDoc::takePwMDataItem( PwMDataItem* local, PwMDataItem* remote, QDateTime lastSync, int mode , bool full )
+{
+ // 0 equal
+ // 1 take local
+ // 2 take remote
+ // 3 cancel
+ QDateTime localMod = local->meta.update;
+ QDateTime remoteMod = remote->meta.update;
+
+ //US QString mCurrentSyncDevice = syncManager->getCurrentSyncDevice();
+
+ if ( localMod == remoteMod )
+ return 0;
+
+ qDebug(" %d %d conflict on %s %s ", mode, full, local->desc.c_str(), remote->desc.c_str() );
+
+ //qDebug("%s %d %s %d", local->lastModified().toString().latin1() , localMod, remote->lastModified().toString().latin1(), remoteMod);
+ //qDebug("%d %d %d %d ", local->lastModified().time().second(), local->lastModified().time().msec(), remote->lastModified().time().second(), remote->lastModified().time().msec() );
+ //full = true; //debug only
+ if ( full ) {
+ bool equ = true;//US ( (*local) == (*remote) );
+ if ( equ ) {
+ //qDebug("equal ");
+ if ( mode < SYNC_PREF_FORCE_LOCAL )
+ return 0;
+
+ }//else //debug only
+ //qDebug("not equal %s %s ", local->summary().latin1(), remote->summary().latin1());
+ }
+
+ int result;
+ bool localIsNew;
+ //qDebug("%s -- %s mLastCalendarSync %s lastsync %s --- local %s remote %s ",local->summary().latin1(), remote->summary().latin1(),mLastCalendarSync.toString().latin1() ,lastSync.toString().latin1() , local->lastModified().toString().latin1() , remote->lastModified().toString().latin1() );
+
+ if ( full && mode < SYNC_PREF_NEWEST )
+ mode = SYNC_PREF_ASK;
+
+ switch( mode ) {
+ case SYNC_PREF_LOCAL:
+ if ( lastSync > remoteMod )
+ return 1;
+ if ( lastSync > localMod )
+ return 2;
+ return 1;
+ break;
+ case SYNC_PREF_REMOTE:
+ if ( lastSync > remoteMod )
+ return 1;
+ if ( lastSync > localMod )
+ return 2;
+ return 2;
+ break;
+ case SYNC_PREF_NEWEST:
+ if ( localMod > remoteMod )
+ return 1;
+ else
+ return 2;
+ break;
+ case SYNC_PREF_ASK:
+ //qDebug("lsy %s --- lo %s --- re %s ", lastSync.toString().latin1(), localMod.toString().latin1(), remoteMod.toString().latin1() );
+ if ( lastSync > remoteMod )
+ return 1;
+ if ( lastSync > localMod )
+ return 2;
+ localIsNew = localMod >= remoteMod;
+ //qDebug("conflict! ************************************** ");
+ {
+ PwMDataItemChooser acd ( *local,*remote, localIsNew , 0/*this*/ );
+ result = acd.executeD(localIsNew);
+ return result;
+ }
+ break;
+ case SYNC_PREF_FORCE_LOCAL:
+ return 1;
+ break;
+ case SYNC_PREF_FORCE_REMOTE:
+ return 2;
+ break;
+
+ default:
+ // SYNC_PREF_TAKE_BOTH not implemented
+ break;
+ }
+ return 0;
+}
+
+
+
@@ -2863,5 +3141,4 @@ void PwMDoc::sync_save()
{
- PwMerror ret = saveDoc(conf()->confGlobCompression());
+ saveDoc(conf()->confGlobCompression());
}
-
#endif
@@ -2869,3 +3146,116 @@ void PwMDoc::sync_save()
+bool PwMDoc::findSyncData(const QString &syncname, unsigned int *index)
+{
+ vector<PwMSyncItem>::iterator i = dti.syncDta.begin(),
+ end = dti.syncDta.end();
+
+ while (i != end) {
+ if ((*i).syncName == syncname.latin1()) {
+ if (index) {
+ *index = i - dti.syncDta.begin();
+ }
+ return true;
+ }
+ ++i;
+ }
+ return false;
+};
+
+/** add new syncdataentry */
+PwMerror PwMDoc::addSyncDataEntry(PwMSyncItem *d, bool dontFlagDirty)
+{
+ PWM_ASSERT(d);
+
+ if (isDeepLocked()) {
+ PwMerror ret;
+ ret = deepLock(false);
+ if (ret != e_success)
+ return e_lock;
+ }
+ unsigned int index;
+
+ const QString tmp = d->syncName.c_str();
+ bool exists = findSyncData(d->syncName.c_str(), &index);
+
+ if (exists == true) {
+ // DOH! We found this entry.
+ return e_entryExists;
+ }
+
+ dti.syncDta.push_back(*d);
+
+ if (!dontFlagDirty)
+ flagDirty();
+ return e_success;
+}
+
+
+/** delete syncdata entry */
+bool PwMDoc::delSyncDataEntry(unsigned int index, bool dontFlagDirty)
+{
+ if (isDeepLocked())
+ return false;
+ if (index > dti.syncDta.size() - 1)
+ return false;
+
+ // delete entry
+ dti.syncDta.erase(dti.syncDta.begin() + index);
+
+ if (!dontFlagDirty)
+ flagDirty();
+ return true;
+}
+
+
+PwMDataItem* PwMDoc::findEntryByID(const QString &uid, unsigned int *category, unsigned int *index)
+{
+ vector<PwMCategoryItem>::iterator catcounter = dti.dta.begin(),
+ catend = dti.dta.end();
+
+ vector<PwMDataItem>::iterator entrBegin, entrEnd, entrI;
+
+ while (catcounter != catend) {
+ entrBegin = catcounter->d.begin();
+ entrEnd = catcounter->d.end();
+ entrI = entrBegin;
+ while (entrI != entrEnd) {
+ if ((*entrI).meta.uniqueid == uid.latin1()) {
+ if (category)
+ *category = catcounter - dti.dta.begin();
+ if (index)
+ *index = entrI - entrBegin;
+
+ return &(*entrI);
+ }
+ ++entrI;
+ }
+ ++catcounter;
+ }
+
+ return 0;
+}
+
+QStringList PwMDoc::getIDEntryList()
+{
+ QStringList results;
+
+ vector<PwMCategoryItem>::iterator catcounter = dti.dta.begin(),
+ catend = dti.dta.end();
+
+ vector<PwMDataItem>::iterator entrBegin, entrEnd, entrI;
+
+ while (catcounter != catend) {
+ entrBegin = catcounter->d.begin();
+ entrEnd = catcounter->d.end();
+ entrI = entrBegin;
+ while (entrI != entrEnd) {
+ results.append( (*entrI).meta.uniqueid );
+ ++entrI;
+ }
+ ++catcounter;
+ }
+
+ return results;
+}
diff --git a/pwmanager/pwmanager/pwmdoc.h b/pwmanager/pwmanager/pwmdoc.h
index ea4d687..91277f6 100644
--- a/pwmanager/pwmanager/pwmdoc.h
+++ b/pwmanager/pwmanager/pwmdoc.h
@@ -208,2 +208,3 @@ struct PwMDataItem
}
+
};
@@ -224,2 +225,27 @@ struct PwMCategoryItem
+struct PwMSyncItem
+{
+ string syncName;
+ QDateTime lastSyncDate;
+
+ void clear()
+ {
+ lastSyncDate = QDateTime();
+ syncName = "";
+ }
+};
+
+struct PwMItem
+{
+ vector<PwMCategoryItem> dta;
+ vector<PwMSyncItem> syncDta;
+
+ void clear()
+ {
+ dta.clear();
+ syncDta.clear();
+ }
+};
+
+
/** "Function Object" for sort()ing PwMDataItem::listViewPos */
@@ -442,9 +468,10 @@ public:
unsigned int numEntries(unsigned int category)
- { return dta[category].d.size(); }
+ { return dti.dta[category].d.size(); }
/** returns number of categories */
unsigned int numCategories()
- { return dta.size(); }
+ { return dti.dta.size(); }
/** returns the name of the category at "index" */
const string* getCategory(unsigned int index)
- { return (&(dta[index].name)); }
+ { return (&(dti.dta[index].name)); }
+
/** returns the data of item at "index".
@@ -474,3 +501,3 @@ public:
bool isLocked(unsigned int category, unsigned int index)
- { return dta[category].d[index].lockStat; }
+ { return dti.dta[category].d[index].lockStat; }
/** returns the deeplock status */
@@ -576,9 +603,9 @@ public:
unsigned int getEntryRevCnt(unsigned int category, unsigned int index)
- { return dta[category].d[index].rev; }
+ { return dti.dta[category].d[index].rev; }
/** returns a const pointer to the entries meta */
const PwMMetaData * getEntryMeta(unsigned int category, unsigned int index)
- { return &(dta[category].d[index].meta); }
+ { return &(dti.dta[category].d[index].meta); }
/** is the entry at "category" "index" a binary entry? */
bool isBinEntry(unsigned int category, unsigned int index)
- { return dta[category].d[index].binary; }
+ { return dti.dta[category].d[index].binary; }
@@ -615,4 +642,6 @@ protected:
QString filename;
+//US ENH: we need a place where we keep the syncentries. So I invented
+// struct PwMItem, that has a vector of PwMCategoryItem and vector of PwMSyncItem
/** holds all data */
- vector<PwMCategoryItem> dta;
+ PwMItem dti;
/** maximum number of entries */
@@ -709,2 +738,8 @@ protected:
+ //takePwMDataItem returns the following values
+ // 0 equal
+ // 1 take local
+ // 2 take remote
+ // 3 cancel
+ int takePwMDataItem( PwMDataItem* local, PwMDataItem* remote, QDateTime lastSync, int mode , bool full );
@@ -719,3 +754,22 @@ protected:
virtual void sync_save();
+
#endif
+ private:
+ //US ENH: helpermethods to access the sync data for a certain syncname.
+ // It returns the syncdatas index
+ bool findSyncData(const QString &syncname, unsigned int *index);
+
+ /** add new syncdataentry */
+ PwMerror addSyncDataEntry(PwMSyncItem *d, bool dontFlagDirty = false);
+
+ /** returns a pointer to the syncdata */
+ PwMSyncItem* getSyncDataEntry(unsigned int index)
+ { return &(dti.syncDta[index]); }
+
+ /** delete entry */
+ bool delSyncDataEntry(unsigned int index, bool dontFlagDirty = false);
+
+ PwMDataItem* findEntryByID(const QString &uid, unsigned int *category, unsigned int *index);
+
+ QStringList getIDEntryList();
diff --git a/pwmanager/pwmanager/pwmdocui.cpp b/pwmanager/pwmanager/pwmdocui.cpp
index 5e675fc..41afa6a 100644
--- a/pwmanager/pwmanager/pwmdocui.cpp
+++ b/pwmanager/pwmanager/pwmdocui.cpp
@@ -278,3 +278,3 @@ bool PwMDocUi::saveDocUi(PwMDoc *doc)
i18n("Error: Couldn't write to file.\n"
- "Please check if you have permission to "
+ "Please check if you have permission to\n"
"write to the file in that directory."),
diff --git a/pwmanager/pwmanager/pwmexception.h b/pwmanager/pwmanager/pwmexception.h
index c8a8c0f..301ebd7 100644
--- a/pwmanager/pwmanager/pwmexception.h
+++ b/pwmanager/pwmanager/pwmexception.h
@@ -161,2 +161,3 @@ enum PwMerror {
e_normalEntry,
+ e_syncError,
diff --git a/pwmanager/pwmanager/pwmview.cpp b/pwmanager/pwmanager/pwmview.cpp
index d192119..e23ce25 100644
--- a/pwmanager/pwmanager/pwmview.cpp
+++ b/pwmanager/pwmanager/pwmview.cpp
@@ -37,2 +37,3 @@
#include <qapplication.h>
+#include <qlayout.h>
@@ -457,2 +458,65 @@ void PwMView::copyCommentToClip()
+
+
+
+PwMDataItemChooser::PwMDataItemChooser( PwMDataItem loc, PwMDataItem rem, bool takeloc, QWidget *parent, const char *name ) : KDialogBase(parent,name,
+ true ,i18n("Conflict! Please choose Entry!"),Ok|User1|Close,Close, false)
+{
+ findButton( Close )->setText( i18n("Cancel Sync"));
+ findButton( Ok )->setText( i18n("Remote"));
+ findButton( User1 )->setText( i18n("Local"));
+ QWidget* topframe = new QWidget( this );
+ setMainWidget( topframe );
+ QBoxLayout* bl;
+ if ( QApplication::desktop()->width() < 640 ) {
+ bl = new QVBoxLayout( topframe );
+ } else {
+ bl = new QHBoxLayout( topframe );
+ }
+ QVBox* subframe = new QVBox( topframe );
+ bl->addWidget(subframe );
+ QLabel* lab = new QLabel( i18n("Local Entry"), subframe );
+ if ( takeloc )
+ lab->setBackgroundColor(Qt::green.light() );
+ // AddresseeView * av = new AddresseeView( subframe );
+ // av->setAddressee( loc );
+ subframe = new QVBox( topframe );
+ bl->addWidget(subframe );
+ lab = new QLabel( i18n("Remote Entry"), subframe );
+ if ( !takeloc )
+ lab->setBackgroundColor(Qt::green.light() );
+ // av = new AddresseeView( subframe );
+ // av->setAddressee( rem );
+ QObject::connect(findButton( Ok ),SIGNAL(clicked()),this, SLOT(slot_remote()));
+ QObject::connect(this,SIGNAL(user1Clicked()),this, SLOT(slot_local()));
+#ifndef DESKTOP_VERSION
+ showMaximized();
+#else
+ resize ( 640, 400 );
+#endif
+}
+
+int PwMDataItemChooser::executeD( bool local )
+{
+ mSyncResult = 3;
+ if ( local )
+ findButton( User1 )->setFocus();
+ else
+ findButton( Ok )->setFocus();
+ exec();
+ return mSyncResult;
+}
+void PwMDataItemChooser::slot_remote()
+{
+ mSyncResult = 2;
+ accept();
+}
+void PwMDataItemChooser::slot_local()
+{
+ mSyncResult = 1;
+ accept();
+}
+
+
+
#ifndef PWM_EMBEDDED
diff --git a/pwmanager/pwmanager/pwmview.h b/pwmanager/pwmanager/pwmview.h
index 5a326d3..75cce51 100644
--- a/pwmanager/pwmanager/pwmview.h
+++ b/pwmanager/pwmanager/pwmview.h
@@ -38,2 +38,3 @@
#include <klocale.h>
+#include <kdialogbase.h>
@@ -149,2 +150,23 @@ private:
+
+//US ENH we need this chooser when syncing results in a conflict
+class PwMDataItemChooser : public KDialogBase
+{
+ Q_OBJECT
+
+ public:
+ PwMDataItemChooser( PwMDataItem loc, PwMDataItem rem, bool takeloc, QWidget *parent = 0, const char *name = 0 );
+
+ int executeD( bool local );
+
+ private:
+ int mSyncResult;
+
+ private slots:
+ void slot_remote();
+ void slot_local();
+
+};
+
+
#endif
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;
+}
+
diff --git a/pwmanager/pwmanager/serializer.h b/pwmanager/pwmanager/serializer.h
index 245fcee..ee61b94 100644
--- a/pwmanager/pwmanager/serializer.h
+++ b/pwmanager/pwmanager/serializer.h
@@ -53,5 +53,6 @@ public:
/** serialize "dta" and store it as XML data */
- bool serialize(const vector<PwMCategoryItem> &dta);
+ //US ENH: we need to serialize and deserialize not only categories, but also synctargets
+ bool serialize(PwMItem &dta);
/** deserialize the (parsed) XML data and store it in "dta" */
- bool deSerialize(vector<PwMCategoryItem> *dta);
+ bool deSerialize(PwMItem *dta);
/** sets the initial default lockStat we should assign */
@@ -99,2 +100,14 @@ protected:
QString unescapeEntryData(QString dta);
+
+
+
+ //US ENH: the following methods are getting used to write/read sync entries
+ /** read the syncentries in the node "n" */
+ bool readSyncData(const QDomNode &n,
+ vector<PwMSyncItem> *dta);
+
+ /** add new syncentries to the XML data stream in e */
+ bool addSyncData(QDomElement *e,
+ const vector<PwMSyncItem> &dta);
+
};