author | ulf69 <ulf69> | 2004-10-06 00:35:59 (UTC) |
---|---|---|
committer | ulf69 <ulf69> | 2004-10-06 00:35:59 (UTC) |
commit | 904cbf4f2a418d3cadc74a6168a4565ae6ebc3c5 (patch) (unidiff) | |
tree | 22bb491b5886234a0ed21b882df73732ea99bf84 | |
parent | 07fa092b413b7cde1bd4fc797ce0b30adcb8668d (diff) | |
download | kdepimpi-904cbf4f2a418d3cadc74a6168a4565ae6ebc3c5.zip kdepimpi-904cbf4f2a418d3cadc74a6168a4565ae6ebc3c5.tar.gz kdepimpi-904cbf4f2a418d3cadc74a6168a4565ae6ebc3c5.tar.bz2 |
*** empty log message ***
-rw-r--r-- | pwmanager/pwmanager/pwmanagerE.pro | 2 | ||||
-rw-r--r-- | pwmanager/pwmanager/pwmdoc.cpp | 568 | ||||
-rw-r--r-- | pwmanager/pwmanager/pwmdoc.h | 70 | ||||
-rw-r--r-- | pwmanager/pwmanager/pwmdocui.cpp | 2 | ||||
-rw-r--r-- | pwmanager/pwmanager/pwmexception.h | 1 | ||||
-rw-r--r-- | pwmanager/pwmanager/pwmview.cpp | 64 | ||||
-rw-r--r-- | pwmanager/pwmanager/pwmview.h | 22 | ||||
-rw-r--r-- | pwmanager/pwmanager/serializer.cpp | 109 | ||||
-rw-r--r-- | pwmanager/pwmanager/serializer.h | 17 |
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 | |||
@@ -8,5 +8,5 @@ MOC_DIR = moc/$(PLATFORM) | |||
8 | DESTDIR=$(QPEDIR)/bin | 8 | DESTDIR=$(QPEDIR)/bin |
9 | 9 | ||
10 | INCLUDEPATH += . ../../qtcompat ../../qtcompat/xml ../../libkdepim ../../microkde ../../microkde/kdecore ../../microkde/kdeui ../../microkde/kutils $(QPEDIR)/include | 10 | INCLUDEPATH += . ../../ ../../qtcompat ../../qtcompat/xml ../../libkdepim ../../microkde ../../microkde/kdecore ../../microkde/kdeui ../../microkde/kutils $(QPEDIR)/include |
11 | DEFINES += PWM_EMBEDDED | 11 | DEFINES += PWM_EMBEDDED |
12 | #enable this setting if you want debugoutput for pwmanager | 12 | #enable this setting if you want debugoutput for pwmanager |
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 | |||
@@ -36,4 +36,8 @@ | |||
36 | #endif | 36 | #endif |
37 | 37 | ||
38 | #include <kmessagebox.h> | ||
39 | #include <libkcal/syncdefines.h> | ||
40 | |||
41 | |||
38 | #ifdef CONFIG_KWALLETIF | 42 | #ifdef CONFIG_KWALLETIF |
39 | # include "kwalletemu.h" | 43 | # include "kwalletemu.h" |
@@ -1008,5 +1012,5 @@ PwMerror PwMDoc::addEntry(const QString &category, PwMDataItem *d, | |||
1008 | d->meta.update = d->meta.create; | 1012 | d->meta.update = d->meta.create; |
1009 | } | 1013 | } |
1010 | dta[cat].d.push_back(*d); | 1014 | dti.dta[cat].d.push_back(*d); |
1011 | 1015 | ||
1012 | delAllEmptyCat(true); | 1016 | delAllEmptyCat(true); |
@@ -1032,7 +1036,7 @@ PwMerror PwMDoc::addCategory(const QString &category, unsigned int *categoryInde | |||
1032 | PwMCategoryItem item; | 1036 | PwMCategoryItem item; |
1033 | item.name = category.latin1(); | 1037 | item.name = category.latin1(); |
1034 | dta.push_back(item); | 1038 | dti.dta.push_back(item); |
1035 | if (categoryIndex) | 1039 | if (categoryIndex) |
1036 | *categoryIndex = dta.size() - 1; | 1040 | *categoryIndex = dti.dta.size() - 1; |
1037 | return e_success; | 1041 | return e_success; |
1038 | } | 1042 | } |
@@ -1054,5 +1058,5 @@ bool PwMDoc::delEntry(unsigned int category, unsigned int index, bool dontFlagDi | |||
1054 | if (isDeepLocked()) | 1058 | if (isDeepLocked()) |
1055 | return false; | 1059 | return false; |
1056 | if (index > dta[category].d.size() - 1) | 1060 | if (index > dti.dta[category].d.size() - 1) |
1057 | return false; | 1061 | return false; |
1058 | getDataChangedLock(); | 1062 | getDataChangedLock(); |
@@ -1062,8 +1066,8 @@ bool PwMDoc::delEntry(unsigned int category, unsigned int index, bool dontFlagDi | |||
1062 | } | 1066 | } |
1063 | putDataChangedLock(); | 1067 | putDataChangedLock(); |
1064 | int lvPos = dta[category].d[index].listViewPos; | 1068 | int lvPos = dti.dta[category].d[index].listViewPos; |
1065 | 1069 | ||
1066 | // delete entry | 1070 | // delete entry |
1067 | dta[category].d.erase(dta[category].d.begin() + index); | 1071 | dti.dta[category].d.erase(dti.dta[category].d.begin() + index); |
1068 | 1072 | ||
1069 | unsigned int i, entries = numEntries(category); | 1073 | unsigned int i, entries = numEntries(category); |
@@ -1077,6 +1081,6 @@ bool PwMDoc::delEntry(unsigned int category, unsigned int index, bool dontFlagDi | |||
1077 | for (i = 0; i < entries; ++i) { | 1081 | for (i = 0; i < entries; ++i) { |
1078 | // decrement all listViewPositions that are greater than the deleted. | 1082 | // decrement all listViewPositions that are greater than the deleted. |
1079 | if (dta[category].d[i].listViewPos > lvPos) | 1083 | if (dti.dta[category].d[i].listViewPos > lvPos) |
1080 | --dta[category].d[i].listViewPos; | 1084 | --dti.dta[category].d[i].listViewPos; |
1081 | } | 1085 | } |
1082 | 1086 | ||
@@ -1111,5 +1115,5 @@ bool PwMDoc::editEntry(unsigned int oldCategory, const QString &newCategory, | |||
1111 | } | 1115 | } |
1112 | } | 1116 | } |
1113 | if (dta[oldCategory].name != newCategory.latin1()) { | 1117 | if (dti.dta[oldCategory].name != newCategory.latin1()) { |
1114 | // the user changed the category. | 1118 | // the user changed the category. |
1115 | PwMerror ret; | 1119 | PwMerror ret; |
@@ -1121,6 +1125,6 @@ bool PwMDoc::editEntry(unsigned int oldCategory, const QString &newCategory, | |||
1121 | return false; | 1125 | return false; |
1122 | } else { | 1126 | } else { |
1123 | d->rev = dta[oldCategory].d[index].rev + 1; // increment revision counter. | 1127 | d->rev = dti.dta[oldCategory].d[index].rev + 1; // increment revision counter. |
1124 | dta[oldCategory].d[index] = *d; | 1128 | dti.dta[oldCategory].d[index] = *d; |
1125 | } | 1129 | } |
1126 | flagDirty(); | 1130 | flagDirty(); |
@@ -1144,5 +1148,5 @@ bool PwMDoc::serializeDta(string *d) | |||
1144 | PWM_ASSERT(d); | 1148 | PWM_ASSERT(d); |
1145 | Serializer ser; | 1149 | Serializer ser; |
1146 | if (!ser.serialize(dta)) | 1150 | if (!ser.serialize(dti)) |
1147 | return false; | 1151 | return false; |
1148 | d->assign(ser.getXml()); | 1152 | d->assign(ser.getXml()); |
@@ -1160,5 +1164,5 @@ bool PwMDoc::deSerializeDta(const string *d, bool entriesLocked) | |||
1160 | Serializer ser(d->c_str()); | 1164 | Serializer ser(d->c_str()); |
1161 | ser.setDefaultLockStat(entriesLocked); | 1165 | ser.setDefaultLockStat(entriesLocked); |
1162 | if (!ser.deSerialize(&dta)) | 1166 | if (!ser.deSerialize(&dti)) |
1163 | return false; | 1167 | return false; |
1164 | } catch (PwMException) { | 1168 | } catch (PwMException) { |
@@ -1168,5 +1172,5 @@ bool PwMDoc::deSerializeDta(const string *d, bool entriesLocked) | |||
1168 | Serializer ser(d->c_str()); | 1172 | Serializer ser(d->c_str()); |
1169 | ser.setDefaultLockStat(entriesLocked); | 1173 | ser.setDefaultLockStat(entriesLocked); |
1170 | if (!ser.deSerialize(&dta)) | 1174 | if (!ser.deSerialize(&dti)) |
1171 | return false; | 1175 | return false; |
1172 | #endif | 1176 | #endif |
@@ -1193,5 +1197,5 @@ bool PwMDoc::getEntry(unsigned int category, unsigned int index, | |||
1193 | PwMDataItem *d, bool unlockIfLocked) | 1197 | PwMDataItem *d, bool unlockIfLocked) |
1194 | { | 1198 | { |
1195 | if (index > dta[category].d.size() - 1) | 1199 | if (index > dti.dta[category].d.size() - 1) |
1196 | return false; | 1200 | return false; |
1197 | 1201 | ||
@@ -1210,5 +1214,5 @@ bool PwMDoc::getEntry(unsigned int category, unsigned int index, | |||
1210 | } | 1214 | } |
1211 | 1215 | ||
1212 | *d = dta[category].d[index]; | 1216 | *d = dti.dta[category].d[index]; |
1213 | if (locked) | 1217 | if (locked) |
1214 | d->pw = LOCKED_STRING.latin1(); | 1218 | d->pw = LOCKED_STRING.latin1(); |
@@ -1228,7 +1232,7 @@ PwMerror PwMDoc::getCommentByLvp(const QString &category, int listViewPos, | |||
1228 | unsigned int i, entries = numEntries(cat); | 1232 | unsigned int i, entries = numEntries(cat); |
1229 | for (i = 0; i < entries; ++i) { | 1233 | for (i = 0; i < entries; ++i) { |
1230 | if (dta[cat].d[i].listViewPos == listViewPos) { | 1234 | if (dti.dta[cat].d[i].listViewPos == listViewPos) { |
1231 | *foundComment = dta[cat].d[i].comment; | 1235 | *foundComment = dti.dta[cat].d[i].comment; |
1232 | if (dta[cat].d[i].binary) | 1236 | if (dti.dta[cat].d[i].binary) |
1233 | return e_binEntry; | 1237 | return e_binEntry; |
1234 | return e_normalEntry; | 1238 | return e_normalEntry; |
@@ -1491,5 +1495,5 @@ bool PwMDoc::lockAt(unsigned int category, unsigned int index, | |||
1491 | return false; | 1495 | return false; |
1492 | } | 1496 | } |
1493 | if (lock == dta[category].d[index].lockStat) | 1497 | if (lock == dti.dta[category].d[index].lockStat) |
1494 | return true; | 1498 | return true; |
1495 | 1499 | ||
@@ -1515,6 +1519,6 @@ bool PwMDoc::lockAt(unsigned int category, unsigned int index, | |||
1515 | } | 1519 | } |
1516 | 1520 | ||
1517 | dta[category].d[index].lockStat = lock; | 1521 | dti.dta[category].d[index].lockStat = lock; |
1518 | dta[category].d[index].rev++; // increment revision counter. | 1522 | dti.dta[category].d[index].rev++; // increment revision counter. |
1519 | 1523 | ||
1520 | emitDataChanged(this); | 1524 | emitDataChanged(this); |
@@ -1572,6 +1576,6 @@ bool PwMDoc::lockAll(bool lock) | |||
1572 | } | 1576 | } |
1573 | 1577 | ||
1574 | vector<PwMCategoryItem>::iterator catBegin = dta.begin(), | 1578 | vector<PwMCategoryItem>::iterator catBegin = dti.dta.begin(), |
1575 | catEnd = dta.end(), | 1579 | catEnd = dti.dta.end(), |
1576 | catI = catBegin; | 1580 | catI = catBegin; |
1577 | vector<PwMDataItem>::iterator entrBegin, entrEnd, entrI; | 1581 | vector<PwMDataItem>::iterator entrBegin, entrEnd, entrI; |
@@ -1646,6 +1650,6 @@ bool PwMDoc::unlockAll_tempoary(bool revert) | |||
1646 | return false; | 1650 | return false; |
1647 | } | 1651 | } |
1648 | vector<PwMCategoryItem>::iterator catBegin = dta.begin(), | 1652 | vector<PwMCategoryItem>::iterator catBegin = dti.dta.begin(), |
1649 | catEnd = dta.end(), | 1653 | catEnd = dti.dta.end(), |
1650 | catI = catBegin; | 1654 | catI = catBegin; |
1651 | vector<PwMDataItem>::iterator entrBegin, entrEnd, entrI; | 1655 | vector<PwMDataItem>::iterator entrBegin, entrEnd, entrI; |
@@ -1730,6 +1734,6 @@ bool PwMDoc::unlockAll_tempoary(bool revert) | |||
1730 | } else { | 1734 | } else { |
1731 | // first check if it's needed to unlock some entries | 1735 | // first check if it's needed to unlock some entries |
1732 | vector<PwMCategoryItem>::iterator catBegin = dta.begin(), | 1736 | vector<PwMCategoryItem>::iterator catBegin = dti.dta.begin(), |
1733 | catEnd = dta.end(), | 1737 | catEnd = dti.dta.end(), |
1734 | catI = catBegin; | 1738 | catI = catBegin; |
1735 | vector<PwMDataItem>::iterator entrBegin, entrEnd, entrI; | 1739 | vector<PwMDataItem>::iterator entrBegin, entrEnd, entrI; |
@@ -1776,6 +1780,6 @@ bool PwMDoc::unlockAll_tempoary(bool revert) | |||
1776 | oldLockStates = new vector< vector<bool> >; | 1780 | oldLockStates = new vector< vector<bool> >; |
1777 | vector<bool> tmp_vec; | 1781 | vector<bool> tmp_vec; |
1778 | vector<PwMCategoryItem>::iterator catBegin = dta.begin(), | 1782 | vector<PwMCategoryItem>::iterator catBegin = dti.dta.begin(), |
1779 | catEnd = dta.end(), | 1783 | catEnd = dti.dta.end(), |
1780 | catI = catBegin; | 1784 | catI = catBegin; |
1781 | vector<PwMDataItem>::iterator entrBegin, entrEnd, entrI; | 1785 | vector<PwMDataItem>::iterator entrBegin, entrEnd, entrI; |
@@ -1861,8 +1865,8 @@ void PwMDoc::_deepUnlock() | |||
1861 | void PwMDoc::clearDoc() | 1865 | void PwMDoc::clearDoc() |
1862 | { | 1866 | { |
1863 | dta.clear(); | 1867 | dti.clear(); |
1864 | PwMCategoryItem d; | 1868 | PwMCategoryItem d; |
1865 | d.name = DEFAULT_CATEGORY.latin1(); | 1869 | d.name = DEFAULT_CATEGORY.latin1(); |
1866 | dta.push_back(d); | 1870 | dti.dta.push_back(d); |
1867 | currentPw = ""; | 1871 | currentPw = ""; |
1868 | unsetDocStatFlag(DOC_STAT_UNLOCK_WITHOUT_PW); | 1872 | unsetDocStatFlag(DOC_STAT_UNLOCK_WITHOUT_PW); |
@@ -1899,5 +1903,5 @@ void PwMDoc::setListViewPos(unsigned int category, unsigned int index, | |||
1899 | int pos) | 1903 | int pos) |
1900 | { | 1904 | { |
1901 | dta[category].d[index].listViewPos = pos; | 1905 | dti.dta[category].d[index].listViewPos = pos; |
1902 | 1906 | ||
1903 | /* FIXME workaround: don't flag dirty, because this function sometimes | 1907 | /* FIXME workaround: don't flag dirty, because this function sometimes |
@@ -1919,5 +1923,5 @@ int PwMDoc::getListViewPos(const QString &category, unsigned int index) | |||
1919 | } | 1923 | } |
1920 | 1924 | ||
1921 | return dta[cat].d[index].listViewPos; | 1925 | return dti.dta[cat].d[index].listViewPos; |
1922 | } | 1926 | } |
1923 | 1927 | ||
@@ -1933,5 +1937,5 @@ void PwMDoc::findEntry(unsigned int category, PwMDataItem find, unsigned int sea | |||
1933 | for (i = 0; i < entries; ++i) { | 1937 | for (i = 0; i < entries; ++i) { |
1934 | if (searchIn & SEARCH_IN_DESC) { | 1938 | if (searchIn & SEARCH_IN_DESC) { |
1935 | if (!compareString(find.desc, dta[category].d[i].desc, | 1939 | if (!compareString(find.desc, dti.dta[category].d[i].desc, |
1936 | caseSensitive, exactWordMatch)) { | 1940 | caseSensitive, exactWordMatch)) { |
1937 | continue; | 1941 | continue; |
@@ -1939,5 +1943,5 @@ void PwMDoc::findEntry(unsigned int category, PwMDataItem find, unsigned int sea | |||
1939 | } | 1943 | } |
1940 | if (searchIn & SEARCH_IN_NAME) { | 1944 | if (searchIn & SEARCH_IN_NAME) { |
1941 | if (!compareString(find.name, dta[category].d[i].name, | 1945 | if (!compareString(find.name, dti.dta[category].d[i].name, |
1942 | caseSensitive, exactWordMatch)) { | 1946 | caseSensitive, exactWordMatch)) { |
1943 | continue; | 1947 | continue; |
@@ -1948,5 +1952,5 @@ void PwMDoc::findEntry(unsigned int category, PwMDataItem find, unsigned int sea | |||
1948 | getDataChangedLock(); | 1952 | getDataChangedLock(); |
1949 | lockAt(category, i, false); | 1953 | lockAt(category, i, false); |
1950 | if (!compareString(find.pw, dta[category].d[i].pw, | 1954 | if (!compareString(find.pw, dti.dta[category].d[i].pw, |
1951 | caseSensitive, exactWordMatch)) { | 1955 | caseSensitive, exactWordMatch)) { |
1952 | lockAt(category, i, wasLocked); | 1956 | lockAt(category, i, wasLocked); |
@@ -1958,5 +1962,5 @@ void PwMDoc::findEntry(unsigned int category, PwMDataItem find, unsigned int sea | |||
1958 | } | 1962 | } |
1959 | if (searchIn & SEARCH_IN_COMMENT) { | 1963 | if (searchIn & SEARCH_IN_COMMENT) { |
1960 | if (!compareString(find.comment, dta[category].d[i].comment, | 1964 | if (!compareString(find.comment, dti.dta[category].d[i].comment, |
1961 | caseSensitive, exactWordMatch)) { | 1965 | caseSensitive, exactWordMatch)) { |
1962 | continue; | 1966 | continue; |
@@ -1964,5 +1968,5 @@ void PwMDoc::findEntry(unsigned int category, PwMDataItem find, unsigned int sea | |||
1964 | } | 1968 | } |
1965 | if (searchIn & SEARCH_IN_URL) { | 1969 | if (searchIn & SEARCH_IN_URL) { |
1966 | if (!compareString(find.url, dta[category].d[i].url, | 1970 | if (!compareString(find.url, dti.dta[category].d[i].url, |
1967 | caseSensitive, exactWordMatch)) { | 1971 | caseSensitive, exactWordMatch)) { |
1968 | continue; | 1972 | continue; |
@@ -1970,5 +1974,5 @@ void PwMDoc::findEntry(unsigned int category, PwMDataItem find, unsigned int sea | |||
1970 | } | 1974 | } |
1971 | if (searchIn & SEARCH_IN_LAUNCHER) { | 1975 | if (searchIn & SEARCH_IN_LAUNCHER) { |
1972 | if (!compareString(find.launcher, dta[category].d[i].launcher, | 1976 | if (!compareString(find.launcher, dti.dta[category].d[i].launcher, |
1973 | caseSensitive, exactWordMatch)) { | 1977 | caseSensitive, exactWordMatch)) { |
1974 | continue; | 1978 | continue; |
@@ -1990,5 +1994,5 @@ void PwMDoc::findEntry(unsigned int category, PwMDataItem find, unsigned int sea | |||
1990 | for (i = 0; i < items; ++i) { | 1994 | for (i = 0; i < items; ++i) { |
1991 | tmp_pair.first = (*foundPositions)[i]; | 1995 | tmp_pair.first = (*foundPositions)[i]; |
1992 | tmp_pair.second = dta[category].d[(*foundPositions)[i]].listViewPos; | 1996 | tmp_pair.second = dti.dta[category].d[(*foundPositions)[i]].listViewPos; |
1993 | tmp_vec.push_back(tmp_pair); | 1997 | tmp_vec.push_back(tmp_pair); |
1994 | } | 1998 | } |
@@ -2033,10 +2037,10 @@ bool PwMDoc::compareString(const string &s1, const string &s2, bool caseSensitiv | |||
2033 | bool PwMDoc::findCategory(const QString &name, unsigned int *index) | 2037 | bool PwMDoc::findCategory(const QString &name, unsigned int *index) |
2034 | { | 2038 | { |
2035 | vector<PwMCategoryItem>::iterator i = dta.begin(), | 2039 | vector<PwMCategoryItem>::iterator i = dti.dta.begin(), |
2036 | end = dta.end(); | 2040 | end = dti.dta.end(); |
2037 | while (i != end) { | 2041 | while (i != end) { |
2038 | if ((*i).name == name.latin1()) { | 2042 | if ((*i).name == name.latin1()) { |
2039 | if (index) { | 2043 | if (index) { |
2040 | *index = i - dta.begin(); | 2044 | *index = i - dti.dta.begin(); |
2041 | } | 2045 | } |
2042 | return true; | 2046 | return true; |
@@ -2063,5 +2067,5 @@ bool PwMDoc::renameCategory(unsigned int category, const QString &newName, | |||
2063 | return false; | 2067 | return false; |
2064 | 2068 | ||
2065 | dta[category].name = newName.latin1(); | 2069 | dti.dta[category].name = newName.latin1(); |
2066 | if (!dontFlagDirty) | 2070 | if (!dontFlagDirty) |
2067 | flagDirty(); | 2071 | flagDirty(); |
@@ -2088,5 +2092,5 @@ bool PwMDoc::delCategory(unsigned int category, bool dontFlagDirty) | |||
2088 | // category! Instead we rename it to "Default". | 2092 | // category! Instead we rename it to "Default". |
2089 | if (numCategories() > 1) { | 2093 | if (numCategories() > 1) { |
2090 | dta.erase(dta.begin() + category); | 2094 | dti.dta.erase(dti.dta.begin() + category); |
2091 | } else { | 2095 | } else { |
2092 | renameCategory(category, DEFAULT_CATEGORY, dontFlagDirty); | 2096 | renameCategory(category, DEFAULT_CATEGORY, dontFlagDirty); |
@@ -2101,6 +2105,6 @@ bool PwMDoc::delCategory(unsigned int category, bool dontFlagDirty) | |||
2101 | void PwMDoc::delAllEmptyCat(bool dontFlagDirty) | 2105 | void PwMDoc::delAllEmptyCat(bool dontFlagDirty) |
2102 | { | 2106 | { |
2103 | vector<PwMCategoryItem>::iterator begin = dta.begin(), | 2107 | vector<PwMCategoryItem>::iterator begin = dti.dta.begin(), |
2104 | end = dta.end(), | 2108 | end = dti.dta.end(), |
2105 | i = begin; | 2109 | i = begin; |
2106 | while (i != end) { | 2110 | while (i != end) { |
@@ -2116,6 +2120,6 @@ void PwMDoc::getCategoryList(vector<string> *list) | |||
2116 | PWM_ASSERT(list); | 2120 | PWM_ASSERT(list); |
2117 | list->clear(); | 2121 | list->clear(); |
2118 | vector<PwMCategoryItem>::iterator i = dta.begin(), | 2122 | vector<PwMCategoryItem>::iterator i = dti.dta.begin(), |
2119 | end = dta.end(); | 2123 | end = dti.dta.end(); |
2120 | while (i != end) { | 2124 | while (i != end) { |
2121 | list->push_back(i->name); | 2125 | list->push_back(i->name); |
@@ -2128,6 +2132,6 @@ void PwMDoc::getCategoryList(QStringList *list) | |||
2128 | PWM_ASSERT(list); | 2132 | PWM_ASSERT(list); |
2129 | list->clear(); | 2133 | list->clear(); |
2130 | vector<PwMCategoryItem>::iterator i = dta.begin(), | 2134 | vector<PwMCategoryItem>::iterator i = dti.dta.begin(), |
2131 | end = dta.end(); | 2135 | end = dti.dta.end(); |
2132 | while (i != end) { | 2136 | while (i != end) { |
2133 | #ifndef PWM_EMBEDDED | 2137 | #ifndef PWM_EMBEDDED |
@@ -2166,6 +2170,6 @@ void PwMDoc::getEntryList(unsigned int category, vector<string> *list) | |||
2166 | PWM_ASSERT(list); | 2170 | PWM_ASSERT(list); |
2167 | list->clear(); | 2171 | list->clear(); |
2168 | vector<PwMDataItem>::iterator begin = dta[category].d.begin(), | 2172 | vector<PwMDataItem>::iterator begin = dti.dta[category].d.begin(), |
2169 | end = dta[category].d.end(), | 2173 | end = dti.dta[category].d.end(), |
2170 | i = begin; | 2174 | i = begin; |
2171 | while (i != end) { | 2175 | while (i != end) { |
@@ -2179,6 +2183,6 @@ void PwMDoc::getEntryList(unsigned int category, QStringList *list) | |||
2179 | PWM_ASSERT(list); | 2183 | PWM_ASSERT(list); |
2180 | list->clear(); | 2184 | list->clear(); |
2181 | vector<PwMDataItem>::iterator begin = dta[category].d.begin(), | 2185 | vector<PwMDataItem>::iterator begin = dti.dta[category].d.begin(), |
2182 | end = dta[category].d.end(), | 2186 | end = dti.dta[category].d.end(), |
2183 | i = begin; | 2187 | i = begin; |
2184 | while (i != end) { | 2188 | while (i != end) { |
@@ -2208,5 +2212,5 @@ bool PwMDoc::execLauncher(unsigned int category, unsigned int entryIndex) | |||
2208 | return false; | 2212 | return false; |
2209 | } | 2213 | } |
2210 | QString command(dta[category].d[entryIndex].launcher.c_str()); | 2214 | QString command(dti.dta[category].d[entryIndex].launcher.c_str()); |
2211 | bool wasLocked = isLocked(category, entryIndex); | 2215 | bool wasLocked = isLocked(category, entryIndex); |
2212 | 2216 | ||
@@ -2220,15 +2224,15 @@ bool PwMDoc::execLauncher(unsigned int category, unsigned int entryIndex) | |||
2220 | } | 2224 | } |
2221 | #ifndef PWM_EMBEDDED | 2225 | #ifndef PWM_EMBEDDED |
2222 | command.replace("$d", dta[category].d[entryIndex].desc.c_str()); | 2226 | command.replace("$d", dti.dta[category].d[entryIndex].desc.c_str()); |
2223 | command.replace("$n", dta[category].d[entryIndex].name.c_str()); | 2227 | command.replace("$n", dti.dta[category].d[entryIndex].name.c_str()); |
2224 | command.replace("$p", dta[category].d[entryIndex].pw.c_str()); | 2228 | command.replace("$p", dti.dta[category].d[entryIndex].pw.c_str()); |
2225 | command.replace("$u", dta[category].d[entryIndex].url.c_str()); | 2229 | command.replace("$u", dti.dta[category].d[entryIndex].url.c_str()); |
2226 | command.replace("$c", dta[category].d[entryIndex].comment.c_str()); | 2230 | command.replace("$c", dti.dta[category].d[entryIndex].comment.c_str()); |
2227 | #else | 2231 | #else |
2228 | command.replace(QRegExp("$d"), dta[category].d[entryIndex].desc.c_str()); | 2232 | command.replace(QRegExp("$d"), dti.dta[category].d[entryIndex].desc.c_str()); |
2229 | command.replace(QRegExp("$n"), dta[category].d[entryIndex].name.c_str()); | 2233 | command.replace(QRegExp("$n"), dti.dta[category].d[entryIndex].name.c_str()); |
2230 | command.replace(QRegExp("$p"), dta[category].d[entryIndex].pw.c_str()); | 2234 | command.replace(QRegExp("$p"), dti.dta[category].d[entryIndex].pw.c_str()); |
2231 | command.replace(QRegExp("$u"), dta[category].d[entryIndex].url.c_str()); | 2235 | command.replace(QRegExp("$u"), dti.dta[category].d[entryIndex].url.c_str()); |
2232 | command.replace(QRegExp("$c"), dta[category].d[entryIndex].comment.c_str()); | 2236 | command.replace(QRegExp("$c"), dti.dta[category].d[entryIndex].comment.c_str()); |
2233 | #endif | 2237 | #endif |
2234 | command.append(" &"); | 2238 | command.append(" &"); |
@@ -2260,5 +2264,5 @@ bool PwMDoc::goToURL(unsigned int category, unsigned int entryIndex) | |||
2260 | return false; | 2264 | return false; |
2261 | } | 2265 | } |
2262 | QString url(dta[category].d[entryIndex].url.c_str()); | 2266 | QString url(dti.dta[category].d[entryIndex].url.c_str()); |
2263 | if (url.isEmpty()) | 2267 | if (url.isEmpty()) |
2264 | return false; | 2268 | return false; |
@@ -2351,5 +2355,5 @@ PwMerror PwMDoc::exportToText(const QString *file) | |||
2351 | 2355 | ||
2352 | exp = "\n== Category: "; | 2356 | exp = "\n== Category: "; |
2353 | exp += dta[i].name; | 2357 | exp += dti.dta[i].name; |
2354 | exp += " ==\n"; | 2358 | exp += " ==\n"; |
2355 | #ifndef PWM_EMBEDDED | 2359 | #ifndef PWM_EMBEDDED |
@@ -2368,25 +2372,25 @@ PwMerror PwMDoc::exportToText(const QString *file) | |||
2368 | for (j = 0; j < numEnt; ++j) { | 2372 | for (j = 0; j < numEnt; ++j) { |
2369 | exp = "\n-- "; | 2373 | exp = "\n-- "; |
2370 | exp += dta[i].d[j].desc; | 2374 | exp += dti.dta[i].d[j].desc; |
2371 | exp += " --\n"; | 2375 | exp += " --\n"; |
2372 | 2376 | ||
2373 | exp += i18n("Username: ").latin1(); | 2377 | exp += i18n("Username: ").latin1(); |
2374 | exp += dta[i].d[j].name; | 2378 | exp += dti.dta[i].d[j].name; |
2375 | exp += "\n"; | 2379 | exp += "\n"; |
2376 | 2380 | ||
2377 | exp += i18n("Password: ").latin1(); | 2381 | exp += i18n("Password: ").latin1(); |
2378 | exp += dta[i].d[j].pw; | 2382 | exp += dti.dta[i].d[j].pw; |
2379 | exp += "\n"; | 2383 | exp += "\n"; |
2380 | 2384 | ||
2381 | exp += i18n("Comment: ").latin1(); | 2385 | exp += i18n("Comment: ").latin1(); |
2382 | exp += dta[i].d[j].comment; | 2386 | exp += dti.dta[i].d[j].comment; |
2383 | exp += "\n"; | 2387 | exp += "\n"; |
2384 | 2388 | ||
2385 | exp += i18n("URL: ").latin1(); | 2389 | exp += i18n("URL: ").latin1(); |
2386 | exp += dta[i].d[j].url; | 2390 | exp += dti.dta[i].d[j].url; |
2387 | exp += "\n"; | 2391 | exp += "\n"; |
2388 | 2392 | ||
2389 | exp += i18n("Launcher: ").latin1(); | 2393 | exp += i18n("Launcher: ").latin1(); |
2390 | exp += dta[i].d[j].launcher; | 2394 | exp += dti.dta[i].d[j].launcher; |
2391 | exp += "\n"; | 2395 | exp += "\n"; |
2392 | 2396 | ||
@@ -2421,5 +2425,5 @@ PwMerror PwMDoc::importFromText(const QString *file, int format) | |||
2421 | if (importText_PwM(file) == e_success) | 2425 | if (importText_PwM(file) == e_success) |
2422 | return e_success; | 2426 | return e_success; |
2423 | dta.clear(); | 2427 | dti.clear(); |
2424 | emitDataChanged(this); | 2428 | emitDataChanged(this); |
2425 | // add next format here... | 2429 | // add next format here... |
@@ -2615,16 +2619,16 @@ PwMerror PwMDoc::exportToGpasman(const QString *file) | |||
2615 | numEntr = numEntries(i); | 2619 | numEntr = numEntries(i); |
2616 | for (j = 0; j < numEntr; ++j) { | 2620 | for (j = 0; j < numEntr; ++j) { |
2617 | descLen = dta[i].d[j].desc.length(); | 2621 | descLen = dti.dta[i].d[j].desc.length(); |
2618 | nameLen = dta[i].d[j].name.length(); | 2622 | nameLen = dti.dta[i].d[j].name.length(); |
2619 | pwLen = dta[i].d[j].pw.length(); | 2623 | pwLen = dti.dta[i].d[j].pw.length(); |
2620 | commentLen = dta[i].d[j].comment.length(); | 2624 | commentLen = dti.dta[i].d[j].comment.length(); |
2621 | entry[0] = new char[descLen + 1]; | 2625 | entry[0] = new char[descLen + 1]; |
2622 | entry[1] = new char[nameLen + 1]; | 2626 | entry[1] = new char[nameLen + 1]; |
2623 | entry[2] = new char[pwLen + 1]; | 2627 | entry[2] = new char[pwLen + 1]; |
2624 | entry[3] = new char[commentLen + 1]; | 2628 | entry[3] = new char[commentLen + 1]; |
2625 | strcpy(entry[0], descLen == 0 ? " " : dta[i].d[j].desc.c_str()); | 2629 | strcpy(entry[0], descLen == 0 ? " " : dti.dta[i].d[j].desc.c_str()); |
2626 | strcpy(entry[1], nameLen == 0 ? " " : dta[i].d[j].name.c_str()); | 2630 | strcpy(entry[1], nameLen == 0 ? " " : dti.dta[i].d[j].name.c_str()); |
2627 | strcpy(entry[2], pwLen == 0 ? " " : dta[i].d[j].pw.c_str()); | 2631 | strcpy(entry[2], pwLen == 0 ? " " : dti.dta[i].d[j].pw.c_str()); |
2628 | strcpy(entry[3], commentLen == 0 ? " " : dta[i].d[j].comment.c_str()); | 2632 | strcpy(entry[3], commentLen == 0 ? " " : dti.dta[i].d[j].comment.c_str()); |
2629 | entry[0][descLen == 0 ? descLen + 1 : descLen] = '\0'; | 2633 | entry[0][descLen == 0 ? descLen + 1 : descLen] = '\0'; |
2630 | entry[1][nameLen == 0 ? nameLen + 1 : nameLen] = '\0'; | 2634 | entry[1][nameLen == 0 ? nameLen + 1 : nameLen] = '\0'; |
@@ -2706,6 +2710,6 @@ void PwMDoc::ensureLvp() | |||
2706 | undefEnd, | 2710 | undefEnd, |
2707 | undefI; | 2711 | undefI; |
2708 | vector<PwMCategoryItem>::iterator catBegin = dta.begin(), | 2712 | vector<PwMCategoryItem>::iterator catBegin = dti.dta.begin(), |
2709 | catEnd = dta.end(), | 2713 | catEnd = dti.dta.end(), |
2710 | catI = catBegin; | 2714 | catI = catBegin; |
2711 | vector<PwMDataItem>::iterator entrBegin, entrEnd, entrI; | 2715 | vector<PwMDataItem>::iterator entrBegin, entrEnd, entrI; |
@@ -2786,7 +2790,7 @@ out_ignore: | |||
2786 | #ifdef PWM_EMBEDDED | 2790 | #ifdef PWM_EMBEDDED |
2787 | //US ENH: this is the magic function that syncronizes the this doc with the remote doc | 2791 | //US ENH: this is the magic function that syncronizes the this doc with the remote doc |
2792 | //US it could have been defined as static, but I did not want to. | ||
2788 | PwMerror PwMDoc::syncronize(KSyncManager* manager, PwMDoc* syncLocal , PwMDoc* syncRemote, int mode ) | 2793 | PwMerror PwMDoc::syncronize(KSyncManager* manager, PwMDoc* syncLocal , PwMDoc* syncRemote, int mode ) |
2789 | { | 2794 | { |
2790 | bool syncOK = true; | ||
2791 | int addedPasswordsLocal = 0; | 2795 | int addedPasswordsLocal = 0; |
2792 | int addedPasswordsRemote = 0; | 2796 | int addedPasswordsRemote = 0; |
@@ -2796,19 +2800,293 @@ PwMerror PwMDoc::syncronize(KSyncManager* manager, PwMDoc* syncLocal , PwMDoc* s | |||
2796 | int changedRemote = 0; | 2800 | int changedRemote = 0; |
2797 | 2801 | ||
2802 | PwMSyncItem* syncItemLocal; | ||
2803 | PwMSyncItem* syncItemRemote; | ||
2804 | |||
2798 | QString mCurrentSyncName = manager->getCurrentSyncName(); | 2805 | QString mCurrentSyncName = manager->getCurrentSyncName(); |
2799 | QString mCurrentSyncDevice = manager->getCurrentSyncDevice(); | 2806 | QString mCurrentSyncDevice = manager->getCurrentSyncDevice(); |
2800 | 2807 | ||
2808 | bool fullDateRange = false; | ||
2809 | int take; | ||
2810 | // local->resetTempSyncStat(); | ||
2811 | QDateTime mLastSync = QDateTime::currentDateTime(); | ||
2812 | QDateTime modifiedSync = mLastSync; | ||
2813 | |||
2814 | unsigned int index; | ||
2815 | //Step 1. Find syncinfo in Local file and create if not existent. | ||
2816 | bool found = syncLocal->findSyncData(mCurrentSyncDevice, &index); | ||
2817 | if (found == false) | ||
2818 | { | ||
2819 | PwMSyncItem newSyncItemLocal; | ||
2820 | newSyncItemLocal.syncName = mCurrentSyncDevice; | ||
2821 | newSyncItemLocal.lastSyncDate = mLastSync; | ||
2822 | syncLocal->addSyncDataEntry(&newSyncItemLocal, true); | ||
2823 | found = syncLocal->findSyncData(mCurrentSyncDevice, &index); | ||
2824 | if (found == false) { | ||
2825 | qDebug("PwMDoc::syncronize : newly created local sync data could not be found"); | ||
2826 | return e_syncError; | ||
2827 | } | ||
2828 | } | ||
2829 | |||
2830 | syncItemLocal = syncLocal->getSyncDataEntry(index); | ||
2831 | qDebug("Last Sync %s ", syncItemLocal->lastSyncDate.toString().latin1()); | ||
2832 | |||
2833 | //Step 2. Find syncinfo in remote file and create if not existent. | ||
2834 | found = syncRemote->findSyncData(mCurrentSyncName, &index); | ||
2835 | if (found == false) | ||
2836 | { | ||
2837 | qDebug("FULLDATE 1"); | ||
2838 | fullDateRange = true; | ||
2839 | PwMSyncItem newSyncItemRemote; | ||
2840 | newSyncItemRemote.syncName = mCurrentSyncName; | ||
2841 | newSyncItemRemote.lastSyncDate = mLastSync; | ||
2842 | syncRemote->addSyncDataEntry(&newSyncItemRemote, true); | ||
2843 | found = syncRemote->findSyncData(mCurrentSyncName, &index); | ||
2844 | if (found == false) { | ||
2845 | qDebug("PwMDoc::syncronize : newly created remote sync data could not be found"); | ||
2846 | return e_syncError; | ||
2847 | } | ||
2848 | } | ||
2849 | |||
2850 | syncItemRemote = syncRemote->getSyncDataEntry(index); | ||
2851 | //and remove the found entry here. We will reenter it later again. | ||
2852 | syncRemote->delSyncDataEntry(index, true); | ||
2801 | 2853 | ||
2802 | 2854 | ||
2855 | if ( syncItemLocal->lastSyncDate == mLastSync ) { | ||
2856 | qDebug("FULLDATE 2"); | ||
2857 | fullDateRange = true; | ||
2858 | } | ||
2859 | |||
2860 | if ( ! fullDateRange ) { | ||
2861 | if ( syncItemLocal->lastSyncDate != syncItemRemote->lastSyncDate ) { | ||
2862 | |||
2863 | // qDebug("set fulldate to true %s %s" ,addresseeLSync->dtStart().toString().latin1(), addresseeRSync->dtStart().toString().latin1() ); | ||
2864 | //qDebug("%d %d %d %d ", addresseeLSync->dtStart().time().second(), addresseeLSync->dtStart().time().msec() , addresseeRSync->dtStart().time().second(), addresseeRSync->dtStart().time().msec()); | ||
2865 | fullDateRange = true; | ||
2866 | qDebug("FULLDATE 3 %s %s", syncItemLocal->lastSyncDate.toString().latin1() , syncItemRemote->lastSyncDate.toString().latin1() ); | ||
2867 | } | ||
2868 | } | ||
2869 | // fullDateRange = true; // debug only! | ||
2870 | if ( fullDateRange ) | ||
2871 | mLastSync = QDateTime::currentDateTime().addDays( -100*365); | ||
2872 | else | ||
2873 | mLastSync = syncItemLocal->lastSyncDate; | ||
2874 | |||
2875 | |||
2876 | qDebug("*************************** "); | ||
2877 | // qDebug("mLastAddressbookSync %s ",mLastAddressbookSync.toString().latin1() ); | ||
2878 | QStringList er = syncRemote->getIDEntryList(); | ||
2879 | PwMDataItem* inRemote ;//= er.first(); | ||
2880 | PwMDataItem* inLocal; | ||
2881 | unsigned int catLocal, indexLocal; | ||
2882 | unsigned int catRemote, indexRemote; | ||
2883 | |||
2884 | QString uid; | ||
2885 | manager->showProgressBar(0, i18n("Syncing - close to abort!"), er.count()); | ||
2886 | |||
2887 | int modulo = (er.count()/10)+1; | ||
2888 | unsigned int incCounter = 0; | ||
2889 | while ( incCounter < er.count()) { | ||
2890 | if (manager->isProgressBarCanceled()) | ||
2891 | return e_syncError; | ||
2892 | if ( incCounter % modulo == 0 ) | ||
2893 | manager->showProgressBar(incCounter); | ||
2894 | |||
2895 | uid = er[ incCounter ]; | ||
2896 | qApp->processEvents(); | ||
2897 | |||
2898 | inLocal = syncLocal->findEntryByID( uid, &catLocal, &indexLocal ); | ||
2899 | inRemote = syncRemote->findEntryByID( uid, &catRemote, &indexRemote ); | ||
2900 | if ( inLocal != 0 ) { // maybe conflict - same uid in both files | ||
2901 | if ( (take = takePwMDataItem( inLocal, inRemote, mLastSync, mode, fullDateRange) ) ) { | ||
2902 | //qDebug("take %d %s ", take, inL.summary().latin1()); | ||
2903 | if ( take == 3 ) | ||
2904 | return e_syncError; | ||
2905 | if ( take == 1 ) {// take local | ||
2906 | //US syncRemote->removeAddressee( inRemote ); | ||
2907 | (*inRemote) = (*inLocal); | ||
2908 | //US syncRemote->insertAddressee( inRemote , false); | ||
2909 | ++changedRemote; | ||
2910 | } else { // take == 2 take remote | ||
2911 | //US syncLocal->removeAddressee( inLocal ); | ||
2912 | (*inLocal) = (*inRemote); | ||
2913 | //US syncLocal->insertAddressee( inLocal , false ); | ||
2914 | ++changedLocal; | ||
2915 | } | ||
2916 | } | ||
2917 | } else { // no conflict | ||
2918 | if ( inRemote->meta.update > mLastSync || mode == 5 ) { | ||
2919 | inRemote->meta.update = modifiedSync; | ||
2920 | //US syncRemote->insertAddressee( inRemote, false ); | ||
2921 | //US syncLocal->insertAddressee( inRemote, false ); | ||
2922 | syncLocal->addEntry("newcategory", inRemote, true, false); | ||
2923 | |||
2924 | ++addedPasswordsLocal; | ||
2925 | } else { | ||
2926 | // pending checkExternSyncAddressee(addresseeRSyncSharp, inR); | ||
2927 | syncRemote->delEntry(catRemote, indexRemote, true); | ||
2928 | //USsyncRemote->removeAddressee( inRemote ); | ||
2929 | ++deletedPasswordsRemote; | ||
2930 | } | ||
2931 | } | ||
2932 | |||
2933 | ++incCounter; | ||
2934 | } | ||
2803 | 2935 | ||
2804 | 2936 | ||
2937 | er.clear(); | ||
2938 | QStringList el = syncLocal->getIDEntryList(); | ||
2939 | modulo = (el.count()/10)+1; | ||
2940 | |||
2941 | manager->showProgressBar(0, i18n("Add / remove addressees"), el.count()); | ||
2942 | incCounter = 0; | ||
2943 | while ( incCounter < el.count()) { | ||
2944 | qApp->processEvents(); | ||
2945 | if (manager->isProgressBarCanceled()) | ||
2946 | return e_syncError; | ||
2947 | if ( incCounter % modulo == 0 ) | ||
2948 | manager->showProgressBar(incCounter); | ||
2949 | uid = el[ incCounter ]; | ||
2950 | |||
2951 | inLocal = syncLocal->findEntryByID( uid, &catLocal, &indexLocal ); | ||
2952 | inRemote = syncRemote->findEntryByID( uid, &catRemote, &indexRemote ); | ||
2953 | if ( inRemote == 0 ) { | ||
2954 | if ( inLocal->meta.update < mLastSync && mode != 4 ) { | ||
2955 | // pending checkExternSyncAddressee(addresseeLSyncSharp, inL); | ||
2956 | syncLocal->delEntry(catLocal, indexLocal, true); | ||
2957 | //USsyncLocal->removeAddressee( inLocal ); | ||
2958 | ++deletedPasswordsLocal; | ||
2959 | } else { | ||
2960 | if ( ! PWMPrefs::instance()->mWriteBackExistingOnly ) { | ||
2961 | ++addedPasswordsRemote; | ||
2962 | inLocal->meta.update = modifiedSync; | ||
2963 | //USsyncLocal->insertAddressee( inLocal, false ); | ||
2964 | (*inRemote) = (*inLocal); | ||
2965 | //USsyncRemote->insertAddressee( inRemote, false ); | ||
2966 | syncRemote->addEntry("newcategory", inRemote, true, false); | ||
2967 | |||
2968 | } | ||
2969 | } | ||
2970 | |||
2971 | } | ||
2972 | ++incCounter; | ||
2973 | } | ||
2974 | el.clear(); | ||
2975 | manager->hideProgressBar(); | ||
2976 | |||
2977 | // Now write the info back into the sync data space of the files | ||
2805 | 2978 | ||
2979 | mLastSync = QDateTime::currentDateTime().addSecs( 1 ); | ||
2980 | // get rid of micro seconds | ||
2981 | QTime t = mLastSync.time(); | ||
2982 | mLastSync.setTime( QTime (t.hour (), t.minute (), t.second () ) ); | ||
2806 | 2983 | ||
2984 | |||
2985 | syncItemLocal->lastSyncDate = mLastSync; | ||
2986 | syncItemRemote->lastSyncDate = mLastSync; | ||
2807 | 2987 | ||
2988 | // addresseeRSync.setRole( i18n("!Remote from: ")+mCurrentSyncName ) ; | ||
2989 | // addresseeLSync.setRole(i18n("!Local from: ") + mCurrentSyncName ); | ||
2808 | 2990 | ||
2991 | syncRemote->addSyncDataEntry( syncItemRemote, false ); | ||
2992 | syncLocal->addSyncDataEntry( syncItemLocal, false ); | ||
2993 | QString mes; | ||
2994 | 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 ); | ||
2995 | if ( PWMPrefs::instance()->mShowSyncSummary ) { | ||
2996 | KMessageBox::information(0, mes, i18n("PWM/Pi Synchronization") ); | ||
2997 | } | ||
2998 | qDebug( mes ); | ||
2809 | return e_success; | 2999 | return e_success; |
2810 | } | 3000 | } |
2811 | 3001 | ||
2812 | 3002 | ||
3003 | int PwMDoc::takePwMDataItem( PwMDataItem* local, PwMDataItem* remote, QDateTime lastSync, int mode , bool full ) | ||
3004 | { | ||
3005 | // 0 equal | ||
3006 | // 1 take local | ||
3007 | // 2 take remote | ||
3008 | // 3 cancel | ||
3009 | QDateTime localMod = local->meta.update; | ||
3010 | QDateTime remoteMod = remote->meta.update; | ||
3011 | |||
3012 | //US QString mCurrentSyncDevice = syncManager->getCurrentSyncDevice(); | ||
3013 | |||
3014 | if ( localMod == remoteMod ) | ||
3015 | return 0; | ||
3016 | |||
3017 | qDebug(" %d %d conflict on %s %s ", mode, full, local->desc.c_str(), remote->desc.c_str() ); | ||
3018 | |||
3019 | //qDebug("%s %d %s %d", local->lastModified().toString().latin1() , localMod, remote->lastModified().toString().latin1(), remoteMod); | ||
3020 | //qDebug("%d %d %d %d ", local->lastModified().time().second(), local->lastModified().time().msec(), remote->lastModified().time().second(), remote->lastModified().time().msec() ); | ||
3021 | //full = true; //debug only | ||
3022 | if ( full ) { | ||
3023 | bool equ = true;//US ( (*local) == (*remote) ); | ||
3024 | if ( equ ) { | ||
3025 | //qDebug("equal "); | ||
3026 | if ( mode < SYNC_PREF_FORCE_LOCAL ) | ||
3027 | return 0; | ||
3028 | |||
3029 | }//else //debug only | ||
3030 | //qDebug("not equal %s %s ", local->summary().latin1(), remote->summary().latin1()); | ||
3031 | } | ||
3032 | |||
3033 | int result; | ||
3034 | bool localIsNew; | ||
3035 | //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() ); | ||
3036 | |||
3037 | if ( full && mode < SYNC_PREF_NEWEST ) | ||
3038 | mode = SYNC_PREF_ASK; | ||
3039 | |||
3040 | switch( mode ) { | ||
3041 | case SYNC_PREF_LOCAL: | ||
3042 | if ( lastSync > remoteMod ) | ||
3043 | return 1; | ||
3044 | if ( lastSync > localMod ) | ||
3045 | return 2; | ||
3046 | return 1; | ||
3047 | break; | ||
3048 | case SYNC_PREF_REMOTE: | ||
3049 | if ( lastSync > remoteMod ) | ||
3050 | return 1; | ||
3051 | if ( lastSync > localMod ) | ||
3052 | return 2; | ||
3053 | return 2; | ||
3054 | break; | ||
3055 | case SYNC_PREF_NEWEST: | ||
3056 | if ( localMod > remoteMod ) | ||
3057 | return 1; | ||
3058 | else | ||
3059 | return 2; | ||
3060 | break; | ||
3061 | case SYNC_PREF_ASK: | ||
3062 | //qDebug("lsy %s --- lo %s --- re %s ", lastSync.toString().latin1(), localMod.toString().latin1(), remoteMod.toString().latin1() ); | ||
3063 | if ( lastSync > remoteMod ) | ||
3064 | return 1; | ||
3065 | if ( lastSync > localMod ) | ||
3066 | return 2; | ||
3067 | localIsNew = localMod >= remoteMod; | ||
3068 | //qDebug("conflict! ************************************** "); | ||
3069 | { | ||
3070 | PwMDataItemChooser acd ( *local,*remote, localIsNew , 0/*this*/ ); | ||
3071 | result = acd.executeD(localIsNew); | ||
3072 | return result; | ||
3073 | } | ||
3074 | break; | ||
3075 | case SYNC_PREF_FORCE_LOCAL: | ||
3076 | return 1; | ||
3077 | break; | ||
3078 | case SYNC_PREF_FORCE_REMOTE: | ||
3079 | return 2; | ||
3080 | break; | ||
3081 | |||
3082 | default: | ||
3083 | // SYNC_PREF_TAKE_BOTH not implemented | ||
3084 | break; | ||
3085 | } | ||
3086 | return 0; | ||
3087 | } | ||
3088 | |||
3089 | |||
3090 | |||
2813 | 3091 | ||
2814 | //this are the overwritten callbackmethods from the syncinterface | 3092 | //this are the overwritten callbackmethods from the syncinterface |
@@ -2862,11 +3140,123 @@ bool PwMDoc::sync_isModified() | |||
2862 | void PwMDoc::sync_save() | 3140 | void PwMDoc::sync_save() |
2863 | { | 3141 | { |
2864 | PwMerror ret = saveDoc(conf()->confGlobCompression()); | 3142 | saveDoc(conf()->confGlobCompression()); |
2865 | } | 3143 | } |
2866 | |||
2867 | #endif | 3144 | #endif |
2868 | 3145 | ||
2869 | 3146 | ||
3147 | bool PwMDoc::findSyncData(const QString &syncname, unsigned int *index) | ||
3148 | { | ||
3149 | vector<PwMSyncItem>::iterator i = dti.syncDta.begin(), | ||
3150 | end = dti.syncDta.end(); | ||
3151 | |||
3152 | while (i != end) { | ||
3153 | if ((*i).syncName == syncname.latin1()) { | ||
3154 | if (index) { | ||
3155 | *index = i - dti.syncDta.begin(); | ||
3156 | } | ||
3157 | return true; | ||
3158 | } | ||
3159 | ++i; | ||
3160 | } | ||
3161 | return false; | ||
3162 | }; | ||
3163 | |||
3164 | /** add new syncdataentry */ | ||
3165 | PwMerror PwMDoc::addSyncDataEntry(PwMSyncItem *d, bool dontFlagDirty) | ||
3166 | { | ||
3167 | PWM_ASSERT(d); | ||
3168 | |||
3169 | if (isDeepLocked()) { | ||
3170 | PwMerror ret; | ||
3171 | ret = deepLock(false); | ||
3172 | if (ret != e_success) | ||
3173 | return e_lock; | ||
3174 | } | ||
3175 | unsigned int index; | ||
3176 | |||
3177 | const QString tmp = d->syncName.c_str(); | ||
3178 | bool exists = findSyncData(d->syncName.c_str(), &index); | ||
3179 | |||
3180 | if (exists == true) { | ||
3181 | // DOH! We found this entry. | ||
3182 | return e_entryExists; | ||
3183 | } | ||
3184 | |||
3185 | dti.syncDta.push_back(*d); | ||
3186 | |||
3187 | if (!dontFlagDirty) | ||
3188 | flagDirty(); | ||
3189 | return e_success; | ||
3190 | } | ||
3191 | |||
3192 | |||
2870 | 3193 | ||
3194 | /** delete syncdata entry */ | ||
3195 | bool PwMDoc::delSyncDataEntry(unsigned int index, bool dontFlagDirty) | ||
3196 | { | ||
3197 | if (isDeepLocked()) | ||
3198 | return false; | ||
3199 | if (index > dti.syncDta.size() - 1) | ||
3200 | return false; | ||
3201 | |||
3202 | // delete entry | ||
3203 | dti.syncDta.erase(dti.syncDta.begin() + index); | ||
3204 | |||
3205 | if (!dontFlagDirty) | ||
3206 | flagDirty(); | ||
3207 | return true; | ||
3208 | } | ||
3209 | |||
3210 | |||
3211 | PwMDataItem* PwMDoc::findEntryByID(const QString &uid, unsigned int *category, unsigned int *index) | ||
3212 | { | ||
3213 | vector<PwMCategoryItem>::iterator catcounter = dti.dta.begin(), | ||
3214 | catend = dti.dta.end(); | ||
3215 | |||
3216 | vector<PwMDataItem>::iterator entrBegin, entrEnd, entrI; | ||
3217 | |||
3218 | while (catcounter != catend) { | ||
3219 | entrBegin = catcounter->d.begin(); | ||
3220 | entrEnd = catcounter->d.end(); | ||
3221 | entrI = entrBegin; | ||
3222 | while (entrI != entrEnd) { | ||
3223 | if ((*entrI).meta.uniqueid == uid.latin1()) { | ||
3224 | if (category) | ||
3225 | *category = catcounter - dti.dta.begin(); | ||
3226 | if (index) | ||
3227 | *index = entrI - entrBegin; | ||
3228 | |||
3229 | return &(*entrI); | ||
3230 | } | ||
3231 | ++entrI; | ||
3232 | } | ||
3233 | ++catcounter; | ||
3234 | } | ||
3235 | |||
3236 | return 0; | ||
3237 | } | ||
3238 | |||
3239 | QStringList PwMDoc::getIDEntryList() | ||
3240 | { | ||
3241 | QStringList results; | ||
3242 | |||
3243 | vector<PwMCategoryItem>::iterator catcounter = dti.dta.begin(), | ||
3244 | catend = dti.dta.end(); | ||
3245 | |||
3246 | vector<PwMDataItem>::iterator entrBegin, entrEnd, entrI; | ||
3247 | |||
3248 | while (catcounter != catend) { | ||
3249 | entrBegin = catcounter->d.begin(); | ||
3250 | entrEnd = catcounter->d.end(); | ||
3251 | entrI = entrBegin; | ||
3252 | while (entrI != entrEnd) { | ||
3253 | results.append( (*entrI).meta.uniqueid ); | ||
3254 | ++entrI; | ||
3255 | } | ||
3256 | ++catcounter; | ||
3257 | } | ||
3258 | |||
3259 | return results; | ||
3260 | } | ||
2871 | 3261 | ||
2872 | 3262 | ||
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 | |||
@@ -207,4 +207,5 @@ struct PwMDataItem | |||
207 | meta.clear(); | 207 | meta.clear(); |
208 | } | 208 | } |
209 | |||
209 | }; | 210 | }; |
210 | 211 | ||
@@ -223,4 +224,29 @@ struct PwMCategoryItem | |||
223 | }; | 224 | }; |
224 | 225 | ||
226 | struct PwMSyncItem | ||
227 | { | ||
228 | string syncName; | ||
229 | QDateTime lastSyncDate; | ||
230 | |||
231 | void clear() | ||
232 | { | ||
233 | lastSyncDate = QDateTime(); | ||
234 | syncName = ""; | ||
235 | } | ||
236 | }; | ||
237 | |||
238 | struct PwMItem | ||
239 | { | ||
240 | vector<PwMCategoryItem> dta; | ||
241 | vector<PwMSyncItem> syncDta; | ||
242 | |||
243 | void clear() | ||
244 | { | ||
245 | dta.clear(); | ||
246 | syncDta.clear(); | ||
247 | } | ||
248 | }; | ||
249 | |||
250 | |||
225 | /** "Function Object" for sort()ing PwMDataItem::listViewPos */ | 251 | /** "Function Object" for sort()ing PwMDataItem::listViewPos */ |
226 | class dta_lvp_greater | 252 | class dta_lvp_greater |
@@ -441,11 +467,12 @@ public: | |||
441 | unsigned int numEntries(const QString &category); | 467 | unsigned int numEntries(const QString &category); |
442 | unsigned int numEntries(unsigned int category) | 468 | unsigned int numEntries(unsigned int category) |
443 | { return dta[category].d.size(); } | 469 | { return dti.dta[category].d.size(); } |
444 | /** returns number of categories */ | 470 | /** returns number of categories */ |
445 | unsigned int numCategories() | 471 | unsigned int numCategories() |
446 | { return dta.size(); } | 472 | { return dti.dta.size(); } |
447 | /** returns the name of the category at "index" */ | 473 | /** returns the name of the category at "index" */ |
448 | const string* getCategory(unsigned int index) | 474 | const string* getCategory(unsigned int index) |
449 | { return (&(dta[index].name)); } | 475 | { return (&(dti.dta[index].name)); } |
476 | |||
450 | /** returns the data of item at "index". | 477 | /** returns the data of item at "index". |
451 | * It unlocks the entry if it's locked and unlockIfLocked is true. | 478 | * It unlocks the entry if it's locked and unlockIfLocked is true. |
@@ -473,5 +500,5 @@ public: | |||
473 | bool isLocked(const QString &category, unsigned int index); | 500 | bool isLocked(const QString &category, unsigned int index); |
474 | bool isLocked(unsigned int category, unsigned int index) | 501 | bool isLocked(unsigned int category, unsigned int index) |
475 | { return dta[category].d[index].lockStat; } | 502 | { return dti.dta[category].d[index].lockStat; } |
476 | /** returns the deeplock status */ | 503 | /** returns the deeplock status */ |
477 | bool isDeepLocked() | 504 | bool isDeepLocked() |
@@ -575,11 +602,11 @@ public: | |||
575 | /** returns the revision count of the item at cat/index */ | 602 | /** returns the revision count of the item at cat/index */ |
576 | unsigned int getEntryRevCnt(unsigned int category, unsigned int index) | 603 | unsigned int getEntryRevCnt(unsigned int category, unsigned int index) |
577 | { return dta[category].d[index].rev; } | 604 | { return dti.dta[category].d[index].rev; } |
578 | /** returns a const pointer to the entries meta */ | 605 | /** returns a const pointer to the entries meta */ |
579 | const PwMMetaData * getEntryMeta(unsigned int category, unsigned int index) | 606 | const PwMMetaData * getEntryMeta(unsigned int category, unsigned int index) |
580 | { return &(dta[category].d[index].meta); } | 607 | { return &(dti.dta[category].d[index].meta); } |
581 | /** is the entry at "category" "index" a binary entry? */ | 608 | /** is the entry at "category" "index" a binary entry? */ |
582 | bool isBinEntry(unsigned int category, unsigned int index) | 609 | bool isBinEntry(unsigned int category, unsigned int index) |
583 | { return dta[category].d[index].binary; } | 610 | { return dti.dta[category].d[index].binary; } |
584 | 611 | ||
585 | public slots: | 612 | public slots: |
@@ -614,6 +641,8 @@ protected: | |||
614 | /** current file for this doc */ | 641 | /** current file for this doc */ |
615 | QString filename; | 642 | QString filename; |
643 | //US ENH: we need a place where we keep the syncentries. So I invented | ||
644 | // struct PwMItem, that has a vector of PwMCategoryItem and vector of PwMSyncItem | ||
616 | /** holds all data */ | 645 | /** holds all data */ |
617 | vector<PwMCategoryItem> dta; | 646 | PwMItem dti; |
618 | /** maximum number of entries */ | 647 | /** maximum number of entries */ |
619 | unsigned int maxEntries; | 648 | unsigned int maxEntries; |
@@ -708,4 +737,10 @@ protected: | |||
708 | PwMerror syncronize(KSyncManager* manager, PwMDoc* syncLocal, PwMDoc* syncRemote, int mode ); | 737 | PwMerror syncronize(KSyncManager* manager, PwMDoc* syncLocal, PwMDoc* syncRemote, int mode ); |
709 | 738 | ||
739 | //takePwMDataItem returns the following values | ||
740 | // 0 equal | ||
741 | // 1 take local | ||
742 | // 2 take remote | ||
743 | // 3 cancel | ||
744 | int takePwMDataItem( PwMDataItem* local, PwMDataItem* remote, QDateTime lastSync, int mode , bool full ); | ||
710 | 745 | ||
711 | //the following methods are the overwritten callbackmethods from the syncinterface | 746 | //the following methods are the overwritten callbackmethods from the syncinterface |
@@ -718,5 +753,24 @@ protected: | |||
718 | //called by the syncmanager to indicate that the work has to be saved. | 753 | //called by the syncmanager to indicate that the work has to be saved. |
719 | virtual void sync_save(); | 754 | virtual void sync_save(); |
755 | |||
720 | #endif | 756 | #endif |
757 | private: | ||
758 | //US ENH: helpermethods to access the sync data for a certain syncname. | ||
759 | // It returns the syncdatas index | ||
760 | bool findSyncData(const QString &syncname, unsigned int *index); | ||
761 | |||
762 | /** add new syncdataentry */ | ||
763 | PwMerror addSyncDataEntry(PwMSyncItem *d, bool dontFlagDirty = false); | ||
764 | |||
765 | /** returns a pointer to the syncdata */ | ||
766 | PwMSyncItem* getSyncDataEntry(unsigned int index) | ||
767 | { return &(dti.syncDta[index]); } | ||
768 | |||
769 | /** delete entry */ | ||
770 | bool delSyncDataEntry(unsigned int index, bool dontFlagDirty = false); | ||
771 | |||
772 | PwMDataItem* findEntryByID(const QString &uid, unsigned int *category, unsigned int *index); | ||
773 | |||
774 | QStringList getIDEntryList(); | ||
721 | 775 | ||
722 | }; | 776 | }; |
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 | |||
@@ -277,5 +277,5 @@ bool PwMDocUi::saveDocUi(PwMDoc *doc) | |||
277 | KMessageBox::error(currentView, | 277 | KMessageBox::error(currentView, |
278 | i18n("Error: Couldn't write to file.\n" | 278 | i18n("Error: Couldn't write to file.\n" |
279 | "Please check if you have permission to " | 279 | "Please check if you have permission to\n" |
280 | "write to the file in that directory."), | 280 | "write to the file in that directory."), |
281 | i18n("error while writing")); | 281 | i18n("error while writing")); |
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 | |||
@@ -160,4 +160,5 @@ enum PwMerror { | |||
160 | e_binEntry, | 160 | e_binEntry, |
161 | e_normalEntry, | 161 | e_normalEntry, |
162 | e_syncError, | ||
162 | 163 | ||
163 | e_generic | 164 | e_generic |
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 | |||
@@ -36,4 +36,5 @@ | |||
36 | #include <qpoint.h> | 36 | #include <qpoint.h> |
37 | #include <qapplication.h> | 37 | #include <qapplication.h> |
38 | #include <qlayout.h> | ||
38 | 39 | ||
39 | //US ENH: wouldn't it be a good idea if we could use this consts everywhere else. | 40 | //US ENH: wouldn't it be a good idea if we could use this consts everywhere else. |
@@ -456,4 +457,67 @@ void PwMView::copyCommentToClip() | |||
456 | } | 457 | } |
457 | 458 | ||
459 | |||
460 | |||
461 | |||
462 | PwMDataItemChooser::PwMDataItemChooser( PwMDataItem loc, PwMDataItem rem, bool takeloc, QWidget *parent, const char *name ) : KDialogBase(parent,name, | ||
463 | true ,i18n("Conflict! Please choose Entry!"),Ok|User1|Close,Close, false) | ||
464 | { | ||
465 | findButton( Close )->setText( i18n("Cancel Sync")); | ||
466 | findButton( Ok )->setText( i18n("Remote")); | ||
467 | findButton( User1 )->setText( i18n("Local")); | ||
468 | QWidget* topframe = new QWidget( this ); | ||
469 | setMainWidget( topframe ); | ||
470 | QBoxLayout* bl; | ||
471 | if ( QApplication::desktop()->width() < 640 ) { | ||
472 | bl = new QVBoxLayout( topframe ); | ||
473 | } else { | ||
474 | bl = new QHBoxLayout( topframe ); | ||
475 | } | ||
476 | QVBox* subframe = new QVBox( topframe ); | ||
477 | bl->addWidget(subframe ); | ||
478 | QLabel* lab = new QLabel( i18n("Local Entry"), subframe ); | ||
479 | if ( takeloc ) | ||
480 | lab->setBackgroundColor(Qt::green.light() ); | ||
481 | // AddresseeView * av = new AddresseeView( subframe ); | ||
482 | // av->setAddressee( loc ); | ||
483 | subframe = new QVBox( topframe ); | ||
484 | bl->addWidget(subframe ); | ||
485 | lab = new QLabel( i18n("Remote Entry"), subframe ); | ||
486 | if ( !takeloc ) | ||
487 | lab->setBackgroundColor(Qt::green.light() ); | ||
488 | // av = new AddresseeView( subframe ); | ||
489 | // av->setAddressee( rem ); | ||
490 | QObject::connect(findButton( Ok ),SIGNAL(clicked()),this, SLOT(slot_remote())); | ||
491 | QObject::connect(this,SIGNAL(user1Clicked()),this, SLOT(slot_local())); | ||
492 | #ifndef DESKTOP_VERSION | ||
493 | showMaximized(); | ||
494 | #else | ||
495 | resize ( 640, 400 ); | ||
496 | #endif | ||
497 | } | ||
498 | |||
499 | int PwMDataItemChooser::executeD( bool local ) | ||
500 | { | ||
501 | mSyncResult = 3; | ||
502 | if ( local ) | ||
503 | findButton( User1 )->setFocus(); | ||
504 | else | ||
505 | findButton( Ok )->setFocus(); | ||
506 | exec(); | ||
507 | return mSyncResult; | ||
508 | } | ||
509 | void PwMDataItemChooser::slot_remote() | ||
510 | { | ||
511 | mSyncResult = 2; | ||
512 | accept(); | ||
513 | } | ||
514 | void PwMDataItemChooser::slot_local() | ||
515 | { | ||
516 | mSyncResult = 1; | ||
517 | accept(); | ||
518 | } | ||
519 | |||
520 | |||
521 | |||
458 | #ifndef PWM_EMBEDDED | 522 | #ifndef PWM_EMBEDDED |
459 | #include "pwmview.moc" | 523 | #include "pwmview.moc" |
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 | |||
@@ -37,4 +37,5 @@ | |||
37 | #include <kconfig.h> | 37 | #include <kconfig.h> |
38 | #include <klocale.h> | 38 | #include <klocale.h> |
39 | #include <kdialogbase.h> | ||
39 | 40 | ||
40 | #include <qevent.h> | 41 | #include <qevent.h> |
@@ -148,3 +149,24 @@ private: | |||
148 | }; | 149 | }; |
149 | 150 | ||
151 | |||
152 | //US ENH we need this chooser when syncing results in a conflict | ||
153 | class PwMDataItemChooser : public KDialogBase | ||
154 | { | ||
155 | Q_OBJECT | ||
156 | |||
157 | public: | ||
158 | PwMDataItemChooser( PwMDataItem loc, PwMDataItem rem, bool takeloc, QWidget *parent = 0, const char *name = 0 ); | ||
159 | |||
160 | int executeD( bool local ); | ||
161 | |||
162 | private: | ||
163 | int mSyncResult; | ||
164 | |||
165 | private slots: | ||
166 | void slot_remote(); | ||
167 | void slot_local(); | ||
168 | |||
169 | }; | ||
170 | |||
171 | |||
150 | #endif | 172 | #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 | |||
@@ -42,4 +42,8 @@ | |||
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. |
@@ -207,16 +211,20 @@ QCString Serializer::getXml() | |||
207 | } | 211 | } |
208 | 212 | ||
209 | bool Serializer::serialize(const vector<PwMCategoryItem> &dta) | 213 | bool 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 | ||
220 | bool Serializer::deSerialize(vector<PwMCategoryItem> *dta) | 228 | bool Serializer::deSerialize(PwMItem *dta) |
221 | { | 229 | { |
222 | PWM_ASSERT(domDoc); | 230 | PWM_ASSERT(domDoc); |
@@ -231,15 +239,23 @@ bool Serializer::deSerialize(vector<PwMCategoryItem> *dta) | |||
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 | ||
@@ -662,2 +678,79 @@ QString Serializer::unescapeEntryData(QString dta) | |||
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" */ | ||
684 | bool 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 | |||
728 | bool 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 | |||
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 | |||
@@ -52,7 +52,8 @@ public: | |||
52 | QCString getXml(); | 52 | QCString getXml(); |
53 | /** serialize "dta" and store it as XML data */ | 53 | /** serialize "dta" and store it as XML data */ |
54 | bool serialize(const vector<PwMCategoryItem> &dta); | 54 | //US ENH: we need to serialize and deserialize not only categories, but also synctargets |
55 | bool serialize(PwMItem &dta); | ||
55 | /** deserialize the (parsed) XML data and store it in "dta" */ | 56 | /** deserialize the (parsed) XML data and store it in "dta" */ |
56 | bool deSerialize(vector<PwMCategoryItem> *dta); | 57 | bool deSerialize(PwMItem *dta); |
57 | /** sets the initial default lockStat we should assign */ | 58 | /** sets the initial default lockStat we should assign */ |
58 | void setDefaultLockStat(bool stat) | 59 | void setDefaultLockStat(bool stat) |
@@ -98,4 +99,16 @@ protected: | |||
98 | /** un-escape illegal characters out of the given entry data string */ | 99 | /** un-escape illegal characters out of the given entry data string */ |
99 | QString unescapeEntryData(QString dta); | 100 | QString unescapeEntryData(QString dta); |
101 | |||
102 | |||
103 | |||
104 | //US ENH: the following methods are getting used to write/read sync entries | ||
105 | /** read the syncentries in the node "n" */ | ||
106 | bool readSyncData(const QDomNode &n, | ||
107 | vector<PwMSyncItem> *dta); | ||
108 | |||
109 | /** add new syncentries to the XML data stream in e */ | ||
110 | bool addSyncData(QDomElement *e, | ||
111 | const vector<PwMSyncItem> &dta); | ||
112 | |||
100 | }; | 113 | }; |
101 | 114 | ||