summaryrefslogtreecommitdiffabout
authorulf69 <ulf69>2004-10-08 00:24:58 (UTC)
committer ulf69 <ulf69>2004-10-08 00:24:58 (UTC)
commit309df8e8df3a17602f948025b7951b21ec5c3fed (patch) (unidiff)
treef1b504be724510bd8d49b106cd1b98e09187c547
parent91e43b55a0ddf6a6f39f4ed3ae828ddad6ec89a5 (diff)
downloadkdepimpi-309df8e8df3a17602f948025b7951b21ec5c3fed.zip
kdepimpi-309df8e8df3a17602f948025b7951b21ec5c3fed.tar.gz
kdepimpi-309df8e8df3a17602f948025b7951b21ec5c3fed.tar.bz2
*** empty log message ***
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--pwmanager/pwmanager/pwmdoc.cpp36
-rw-r--r--pwmanager/pwmanager/pwmdoc.h38
-rw-r--r--pwmanager/pwmanager/serializer.cpp2
3 files changed, 58 insertions, 18 deletions
diff --git a/pwmanager/pwmanager/pwmdoc.cpp b/pwmanager/pwmanager/pwmdoc.cpp
index 76a45f4..ab3238a 100644
--- a/pwmanager/pwmanager/pwmdoc.cpp
+++ b/pwmanager/pwmanager/pwmdoc.cpp
@@ -2034,1267 +2034,1279 @@ bool PwMDoc::compareString(const string &s1, const string &s2, bool caseSensitiv
2034 return false; 2034 return false;
2035} 2035}
2036 2036
2037bool PwMDoc::findCategory(const QString &name, unsigned int *index) 2037bool PwMDoc::findCategory(const QString &name, unsigned int *index)
2038{ 2038{
2039 vector<PwMCategoryItem>::iterator i = dti.dta.begin(), 2039 vector<PwMCategoryItem>::iterator i = dti.dta.begin(),
2040 end = dti.dta.end(); 2040 end = dti.dta.end();
2041 while (i != end) { 2041 while (i != end) {
2042 if ((*i).name == name.latin1()) { 2042 if ((*i).name == name.latin1()) {
2043 if (index) { 2043 if (index) {
2044 *index = i - dti.dta.begin(); 2044 *index = i - dti.dta.begin();
2045 } 2045 }
2046 return true; 2046 return true;
2047 } 2047 }
2048 ++i; 2048 ++i;
2049 } 2049 }
2050 return false; 2050 return false;
2051} 2051}
2052 2052
2053bool PwMDoc::renameCategory(const QString &category, const QString &newName) 2053bool PwMDoc::renameCategory(const QString &category, const QString &newName)
2054{ 2054{
2055 unsigned int cat = 0; 2055 unsigned int cat = 0;
2056 2056
2057 if (!findCategory(category, &cat)) 2057 if (!findCategory(category, &cat))
2058 return false; 2058 return false;
2059 2059
2060 return renameCategory(cat, newName); 2060 return renameCategory(cat, newName);
2061} 2061}
2062 2062
2063bool PwMDoc::renameCategory(unsigned int category, const QString &newName, 2063bool PwMDoc::renameCategory(unsigned int category, const QString &newName,
2064 bool dontFlagDirty) 2064 bool dontFlagDirty)
2065{ 2065{
2066 if (category > numCategories() - 1) 2066 if (category > numCategories() - 1)
2067 return false; 2067 return false;
2068 2068
2069 dti.dta[category].name = newName.latin1(); 2069 dti.dta[category].name = newName.latin1();
2070 if (!dontFlagDirty) 2070 if (!dontFlagDirty)
2071 flagDirty(); 2071 flagDirty();
2072 2072
2073 return true; 2073 return true;
2074} 2074}
2075 2075
2076bool PwMDoc::delCategory(const QString &category) 2076bool PwMDoc::delCategory(const QString &category)
2077{ 2077{
2078 unsigned int cat = 0; 2078 unsigned int cat = 0;
2079 2079
2080 if (!findCategory(category, &cat)) 2080 if (!findCategory(category, &cat))
2081 return false; 2081 return false;
2082 2082
2083 return delCategory(cat); 2083 return delCategory(cat);
2084} 2084}
2085 2085
2086bool PwMDoc::delCategory(unsigned int category, bool dontFlagDirty) 2086bool PwMDoc::delCategory(unsigned int category, bool dontFlagDirty)
2087{ 2087{
2088 if (category > numCategories() - 1) 2088 if (category > numCategories() - 1)
2089 return false; 2089 return false;
2090 2090
2091 // We don't delete it, if it is the last existing 2091 // We don't delete it, if it is the last existing
2092 // category! Instead we rename it to "Default". 2092 // category! Instead we rename it to "Default".
2093 if (numCategories() > 1) { 2093 if (numCategories() > 1) {
2094 dti.dta.erase(dti.dta.begin() + category); 2094 dti.dta.erase(dti.dta.begin() + category);
2095 } else { 2095 } else {
2096 renameCategory(category, DEFAULT_CATEGORY, dontFlagDirty); 2096 renameCategory(category, DEFAULT_CATEGORY, dontFlagDirty);
2097 return true; 2097 return true;
2098 } 2098 }
2099 if (!dontFlagDirty) 2099 if (!dontFlagDirty)
2100 flagDirty(); 2100 flagDirty();
2101 2101
2102 return true; 2102 return true;
2103} 2103}
2104 2104
2105void PwMDoc::delAllEmptyCat(bool dontFlagDirty) 2105void PwMDoc::delAllEmptyCat(bool dontFlagDirty)
2106{ 2106{
2107 vector<PwMCategoryItem>::iterator begin = dti.dta.begin(), 2107 vector<PwMCategoryItem>::iterator begin = dti.dta.begin(),
2108 end = dti.dta.end(), 2108 end = dti.dta.end(),
2109 i = begin; 2109 i = begin;
2110 while (i != end) { 2110 while (i != end) {
2111 if (i->d.empty()) { 2111 if (i->d.empty()) {
2112 delCategory(begin - i, dontFlagDirty); 2112 delCategory(begin - i, dontFlagDirty);
2113 } 2113 }
2114 ++i; 2114 ++i;
2115 } 2115 }
2116} 2116}
2117 2117
2118void PwMDoc::getCategoryList(vector<string> *list) 2118void PwMDoc::getCategoryList(vector<string> *list)
2119{ 2119{
2120 PWM_ASSERT(list); 2120 PWM_ASSERT(list);
2121 list->clear(); 2121 list->clear();
2122 vector<PwMCategoryItem>::iterator i = dti.dta.begin(), 2122 vector<PwMCategoryItem>::iterator i = dti.dta.begin(),
2123 end = dti.dta.end(); 2123 end = dti.dta.end();
2124 while (i != end) { 2124 while (i != end) {
2125 list->push_back(i->name); 2125 list->push_back(i->name);
2126 ++i; 2126 ++i;
2127 } 2127 }
2128} 2128}
2129 2129
2130void PwMDoc::getCategoryList(QStringList *list) 2130void PwMDoc::getCategoryList(QStringList *list)
2131{ 2131{
2132 PWM_ASSERT(list); 2132 PWM_ASSERT(list);
2133 list->clear(); 2133 list->clear();
2134 vector<PwMCategoryItem>::iterator i = dti.dta.begin(), 2134 vector<PwMCategoryItem>::iterator i = dti.dta.begin(),
2135 end = dti.dta.end(); 2135 end = dti.dta.end();
2136 while (i != end) { 2136 while (i != end) {
2137#ifndef PWM_EMBEDDED 2137#ifndef PWM_EMBEDDED
2138 list->push_back(i->name.c_str()); 2138 list->push_back(i->name.c_str());
2139#else 2139#else
2140 list->append(i->name.c_str()); 2140 list->append(i->name.c_str());
2141#endif 2141#endif
2142 ++i; 2142 ++i;
2143 } 2143 }
2144} 2144}
2145 2145
2146void PwMDoc::getEntryList(const QString &category, QStringList *list) 2146void PwMDoc::getEntryList(const QString &category, QStringList *list)
2147{ 2147{
2148 PWM_ASSERT(list); 2148 PWM_ASSERT(list);
2149 unsigned int cat = 0; 2149 unsigned int cat = 0;
2150 if (!findCategory(category, &cat)) { 2150 if (!findCategory(category, &cat)) {
2151 list->clear(); 2151 list->clear();
2152 return; 2152 return;
2153 } 2153 }
2154 getEntryList(cat, list); 2154 getEntryList(cat, list);
2155} 2155}
2156 2156
2157void PwMDoc::getEntryList(const QString &category, vector<string> *list) 2157void PwMDoc::getEntryList(const QString &category, vector<string> *list)
2158{ 2158{
2159 PWM_ASSERT(list); 2159 PWM_ASSERT(list);
2160 unsigned int cat = 0; 2160 unsigned int cat = 0;
2161 if (!findCategory(category, &cat)) { 2161 if (!findCategory(category, &cat)) {
2162 list->clear(); 2162 list->clear();
2163 return; 2163 return;
2164 } 2164 }
2165 getEntryList(cat, list); 2165 getEntryList(cat, list);
2166} 2166}
2167 2167
2168void PwMDoc::getEntryList(unsigned int category, vector<string> *list) 2168void PwMDoc::getEntryList(unsigned int category, vector<string> *list)
2169{ 2169{
2170 PWM_ASSERT(list); 2170 PWM_ASSERT(list);
2171 list->clear(); 2171 list->clear();
2172 vector<PwMDataItem>::iterator begin = dti.dta[category].d.begin(), 2172 vector<PwMDataItem>::iterator begin = dti.dta[category].d.begin(),
2173 end = dti.dta[category].d.end(), 2173 end = dti.dta[category].d.end(),
2174 i = begin; 2174 i = begin;
2175 while (i != end) { 2175 while (i != end) {
2176 list->push_back(i->desc); 2176 list->push_back(i->desc);
2177 ++i; 2177 ++i;
2178 } 2178 }
2179} 2179}
2180 2180
2181void PwMDoc::getEntryList(unsigned int category, QStringList *list) 2181void PwMDoc::getEntryList(unsigned int category, QStringList *list)
2182{ 2182{
2183 PWM_ASSERT(list); 2183 PWM_ASSERT(list);
2184 list->clear(); 2184 list->clear();
2185 vector<PwMDataItem>::iterator begin = dti.dta[category].d.begin(), 2185 vector<PwMDataItem>::iterator begin = dti.dta[category].d.begin(),
2186 end = dti.dta[category].d.end(), 2186 end = dti.dta[category].d.end(),
2187 i = begin; 2187 i = begin;
2188 while (i != end) { 2188 while (i != end) {
2189#ifndef PWM_EMBEDDED 2189#ifndef PWM_EMBEDDED
2190 list->push_back(i->desc.c_str()); 2190 list->push_back(i->desc.c_str());
2191#else 2191#else
2192 list->append(i->desc.c_str()); 2192 list->append(i->desc.c_str());
2193#endif 2193#endif
2194 ++i; 2194 ++i;
2195 } 2195 }
2196} 2196}
2197 2197
2198bool PwMDoc::execLauncher(const QString &category, unsigned int entryIndex) 2198bool PwMDoc::execLauncher(const QString &category, unsigned int entryIndex)
2199{ 2199{
2200 unsigned int cat = 0; 2200 unsigned int cat = 0;
2201 2201
2202 if (!findCategory(category, &cat)) 2202 if (!findCategory(category, &cat))
2203 return false; 2203 return false;
2204 2204
2205 return execLauncher(cat, entryIndex); 2205 return execLauncher(cat, entryIndex);
2206} 2206}
2207 2207
2208bool PwMDoc::execLauncher(unsigned int category, unsigned int entryIndex) 2208bool PwMDoc::execLauncher(unsigned int category, unsigned int entryIndex)
2209{ 2209{
2210 if (geteuid() == 0) { 2210 if (geteuid() == 0) {
2211 rootAlertMsgBox(); 2211 rootAlertMsgBox();
2212 return false; 2212 return false;
2213 } 2213 }
2214 QString command(dti.dta[category].d[entryIndex].launcher.c_str()); 2214 QString command(dti.dta[category].d[entryIndex].launcher.c_str());
2215 bool wasLocked = isLocked(category, entryIndex); 2215 bool wasLocked = isLocked(category, entryIndex);
2216 2216
2217 if (command.find("$p") != -1) { 2217 if (command.find("$p") != -1) {
2218 /* the user requested the password to be included 2218 /* the user requested the password to be included
2219 * into the command. We have to ask for the password, 2219 * into the command. We have to ask for the password,
2220 * if it's locked. We do that by unlocking the entry 2220 * if it's locked. We do that by unlocking the entry
2221 */ 2221 */
2222 if (!lockAt(category, entryIndex, false)) 2222 if (!lockAt(category, entryIndex, false))
2223 return false; 2223 return false;
2224 } 2224 }
2225#ifndef PWM_EMBEDDED 2225#ifndef PWM_EMBEDDED
2226 command.replace("$d", dti.dta[category].d[entryIndex].desc.c_str()); 2226 command.replace("$d", dti.dta[category].d[entryIndex].desc.c_str());
2227 command.replace("$n", dti.dta[category].d[entryIndex].name.c_str()); 2227 command.replace("$n", dti.dta[category].d[entryIndex].name.c_str());
2228 command.replace("$p", dti.dta[category].d[entryIndex].pw.c_str()); 2228 command.replace("$p", dti.dta[category].d[entryIndex].pw.c_str());
2229 command.replace("$u", dti.dta[category].d[entryIndex].url.c_str()); 2229 command.replace("$u", dti.dta[category].d[entryIndex].url.c_str());
2230 command.replace("$c", dti.dta[category].d[entryIndex].comment.c_str()); 2230 command.replace("$c", dti.dta[category].d[entryIndex].comment.c_str());
2231#else 2231#else
2232 command.replace(QRegExp("$d"), dti.dta[category].d[entryIndex].desc.c_str()); 2232 command.replace(QRegExp("$d"), dti.dta[category].d[entryIndex].desc.c_str());
2233 command.replace(QRegExp("$n"), dti.dta[category].d[entryIndex].name.c_str()); 2233 command.replace(QRegExp("$n"), dti.dta[category].d[entryIndex].name.c_str());
2234 command.replace(QRegExp("$p"), dti.dta[category].d[entryIndex].pw.c_str()); 2234 command.replace(QRegExp("$p"), dti.dta[category].d[entryIndex].pw.c_str());
2235 command.replace(QRegExp("$u"), dti.dta[category].d[entryIndex].url.c_str()); 2235 command.replace(QRegExp("$u"), dti.dta[category].d[entryIndex].url.c_str());
2236 command.replace(QRegExp("$c"), dti.dta[category].d[entryIndex].comment.c_str()); 2236 command.replace(QRegExp("$c"), dti.dta[category].d[entryIndex].comment.c_str());
2237#endif 2237#endif
2238 command.append(" &"); 2238 command.append(" &");
2239 2239
2240 QString customXterm(conf()->confGlobXtermCommand()); 2240 QString customXterm(conf()->confGlobXtermCommand());
2241 if (!customXterm.isEmpty()) 2241 if (!customXterm.isEmpty())
2242 command = customXterm + " " + command; 2242 command = customXterm + " " + command;
2243 2243
2244 system(command.latin1()); 2244 system(command.latin1());
2245 2245
2246 lockAt(category, entryIndex, wasLocked); 2246 lockAt(category, entryIndex, wasLocked);
2247 return true; 2247 return true;
2248} 2248}
2249 2249
2250bool PwMDoc::goToURL(const QString &category, unsigned int entryIndex) 2250bool PwMDoc::goToURL(const QString &category, unsigned int entryIndex)
2251{ 2251{
2252 unsigned int cat = 0; 2252 unsigned int cat = 0;
2253 2253
2254 if (!findCategory(category, &cat)) 2254 if (!findCategory(category, &cat))
2255 return false; 2255 return false;
2256 2256
2257 return goToURL(cat, entryIndex); 2257 return goToURL(cat, entryIndex);
2258} 2258}
2259 2259
2260bool PwMDoc::goToURL(unsigned int category, unsigned int entryIndex) 2260bool PwMDoc::goToURL(unsigned int category, unsigned int entryIndex)
2261{ 2261{
2262 if (geteuid() == 0) { 2262 if (geteuid() == 0) {
2263 rootAlertMsgBox(); 2263 rootAlertMsgBox();
2264 return false; 2264 return false;
2265 } 2265 }
2266 QString url(dti.dta[category].d[entryIndex].url.c_str()); 2266 QString url(dti.dta[category].d[entryIndex].url.c_str());
2267 if (url.isEmpty()) 2267 if (url.isEmpty())
2268 return false; 2268 return false;
2269 2269
2270 QString customBrowser(conf()->confGlobBrowserCommand()); 2270 QString customBrowser(conf()->confGlobBrowserCommand());
2271 if (!customBrowser.isEmpty()) { 2271 if (!customBrowser.isEmpty()) {
2272 browserProc.clearArguments(); 2272 browserProc.clearArguments();
2273 browserProc << customBrowser << url; 2273 browserProc << customBrowser << url;
2274 if (browserProc.start(KProcess::DontCare)) 2274 if (browserProc.start(KProcess::DontCare))
2275 return true; 2275 return true;
2276 } 2276 }
2277 2277
2278 browserProc.clearArguments(); 2278 browserProc.clearArguments();
2279 browserProc << "konqueror" << url; 2279 browserProc << "konqueror" << url;
2280 if (browserProc.start(KProcess::DontCare)) 2280 if (browserProc.start(KProcess::DontCare))
2281 return true; 2281 return true;
2282 2282
2283 browserProc.clearArguments(); 2283 browserProc.clearArguments();
2284 browserProc << "mozilla" << url; 2284 browserProc << "mozilla" << url;
2285 if (browserProc.start(KProcess::DontCare)) 2285 if (browserProc.start(KProcess::DontCare))
2286 return true; 2286 return true;
2287 2287
2288 browserProc.clearArguments(); 2288 browserProc.clearArguments();
2289 browserProc << "opera" << url; 2289 browserProc << "opera" << url;
2290 if (browserProc.start(KProcess::DontCare)) 2290 if (browserProc.start(KProcess::DontCare))
2291 return true; 2291 return true;
2292 return false; 2292 return false;
2293} 2293}
2294 2294
2295PwMerror PwMDoc::exportToText(const QString *file) 2295PwMerror PwMDoc::exportToText(const QString *file)
2296{ 2296{
2297 PWM_ASSERT(file); 2297 PWM_ASSERT(file);
2298 if (QFile::exists(*file)) { 2298 if (QFile::exists(*file)) {
2299 if (!QFile::remove(*file)) 2299 if (!QFile::remove(*file))
2300 return e_accessFile; 2300 return e_accessFile;
2301 } 2301 }
2302 QFile f(*file); 2302 QFile f(*file);
2303 if (!f.open(IO_ReadWrite)) 2303 if (!f.open(IO_ReadWrite))
2304 return e_openFile; 2304 return e_openFile;
2305 2305
2306 if (!unlockAll_tempoary()) { 2306 if (!unlockAll_tempoary()) {
2307 f.close(); 2307 f.close();
2308 return e_lock; 2308 return e_lock;
2309 } 2309 }
2310 2310
2311 // write header 2311 // write header
2312 string header = i18n("Password table generated by\nPwM v").latin1(); 2312 string header = i18n("Password table generated by\nPwM v").latin1();
2313 header += PACKAGE_VER; 2313 header += PACKAGE_VER;
2314 header += i18n("\non ").latin1(); 2314 header += i18n("\non ").latin1();
2315 QDate currDate = QDate::currentDate(); 2315 QDate currDate = QDate::currentDate();
2316 QTime currTime = QTime::currentTime(); 2316 QTime currTime = QTime::currentTime();
2317 2317
2318#ifndef PWM_EMBEDDED 2318#ifndef PWM_EMBEDDED
2319 header += currDate.toString("ddd MMMM d ").latin1(); 2319 header += currDate.toString("ddd MMMM d ").latin1();
2320 header += currTime.toString("hh:mm:ss ").latin1(); 2320 header += currTime.toString("hh:mm:ss ").latin1();
2321#else 2321#else
2322 QString dfs = KGlobal::locale()->dateFormatShort(); 2322 QString dfs = KGlobal::locale()->dateFormatShort();
2323 bool ampm = KGlobal::locale()->use12Clock(); 2323 bool ampm = KGlobal::locale()->use12Clock();
2324 KGlobal::locale()->setDateFormatShort("%A %B %d"); 2324 KGlobal::locale()->setDateFormatShort("%A %B %d");
2325 KGlobal::locale()->setHore24Format(true); 2325 KGlobal::locale()->setHore24Format(true);
2326 2326
2327 header += KGlobal::locale()->formatDate(currDate, true, KLocale::Userdefined); 2327 header += KGlobal::locale()->formatDate(currDate, true, KLocale::Userdefined);
2328 header += KGlobal::locale()->formatTime(currTime, true); 2328 header += KGlobal::locale()->formatTime(currTime, true);
2329 KGlobal::locale()->setDateFormatShort(dfs); 2329 KGlobal::locale()->setDateFormatShort(dfs);
2330 KGlobal::locale()->setHore24Format(!ampm); 2330 KGlobal::locale()->setHore24Format(!ampm);
2331 2331
2332#endif 2332#endif
2333 header += tostr(currDate.year()); 2333 header += tostr(currDate.year());
2334 header += "\n==============================\n\n"; 2334 header += "\n==============================\n\n";
2335 2335
2336 2336
2337#ifndef PWM_EMBEDDED 2337#ifndef PWM_EMBEDDED
2338 if (f.writeBlock(header.c_str(), header.length()) != (Q_LONG)header.length()) { 2338 if (f.writeBlock(header.c_str(), header.length()) != (Q_LONG)header.length()) {
2339 unlockAll_tempoary(true); 2339 unlockAll_tempoary(true);
2340 f.close(); 2340 f.close();
2341 return e_writeFile; 2341 return e_writeFile;
2342 } 2342 }
2343#else 2343#else
2344 if (f.writeBlock(header.c_str(), header.length()) != (long)header.length()) { 2344 if (f.writeBlock(header.c_str(), header.length()) != (long)header.length()) {
2345 unlockAll_tempoary(true); 2345 unlockAll_tempoary(true);
2346 f.close(); 2346 f.close();
2347 return e_writeFile; 2347 return e_writeFile;
2348 } 2348 }
2349#endif 2349#endif
2350 unsigned int i, numCat = numCategories(); 2350 unsigned int i, numCat = numCategories();
2351 unsigned int j, numEnt; 2351 unsigned int j, numEnt;
2352 string exp; 2352 string exp;
2353 for (i = 0; i < numCat; ++i) { 2353 for (i = 0; i < numCat; ++i) {
2354 numEnt = numEntries(i); 2354 numEnt = numEntries(i);
2355 2355
2356 exp = "\n== Category: "; 2356 exp = "\n== Category: ";
2357 exp += dti.dta[i].name; 2357 exp += dti.dta[i].name;
2358 exp += " ==\n"; 2358 exp += " ==\n";
2359#ifndef PWM_EMBEDDED 2359#ifndef PWM_EMBEDDED
2360 if (f.writeBlock(exp.c_str(), exp.length()) != (Q_LONG)exp.length()) { 2360 if (f.writeBlock(exp.c_str(), exp.length()) != (Q_LONG)exp.length()) {
2361 unlockAll_tempoary(true); 2361 unlockAll_tempoary(true);
2362 f.close(); 2362 f.close();
2363 return e_writeFile; 2363 return e_writeFile;
2364 } 2364 }
2365#else 2365#else
2366 if (f.writeBlock(exp.c_str(), exp.length()) != (long)exp.length()) { 2366 if (f.writeBlock(exp.c_str(), exp.length()) != (long)exp.length()) {
2367 unlockAll_tempoary(true); 2367 unlockAll_tempoary(true);
2368 f.close(); 2368 f.close();
2369 return e_writeFile; 2369 return e_writeFile;
2370 } 2370 }
2371#endif 2371#endif
2372 for (j = 0; j < numEnt; ++j) { 2372 for (j = 0; j < numEnt; ++j) {
2373 exp = "\n-- "; 2373 exp = "\n-- ";
2374 exp += dti.dta[i].d[j].desc; 2374 exp += dti.dta[i].d[j].desc;
2375 exp += " --\n"; 2375 exp += " --\n";
2376 2376
2377 exp += i18n("Username: ").latin1(); 2377 exp += i18n("Username: ").latin1();
2378 exp += dti.dta[i].d[j].name; 2378 exp += dti.dta[i].d[j].name;
2379 exp += "\n"; 2379 exp += "\n";
2380 2380
2381 exp += i18n("Password: ").latin1(); 2381 exp += i18n("Password: ").latin1();
2382 exp += dti.dta[i].d[j].pw; 2382 exp += dti.dta[i].d[j].pw;
2383 exp += "\n"; 2383 exp += "\n";
2384 2384
2385 exp += i18n("Comment: ").latin1(); 2385 exp += i18n("Comment: ").latin1();
2386 exp += dti.dta[i].d[j].comment; 2386 exp += dti.dta[i].d[j].comment;
2387 exp += "\n"; 2387 exp += "\n";
2388 2388
2389 exp += i18n("URL: ").latin1(); 2389 exp += i18n("URL: ").latin1();
2390 exp += dti.dta[i].d[j].url; 2390 exp += dti.dta[i].d[j].url;
2391 exp += "\n"; 2391 exp += "\n";
2392 2392
2393 exp += i18n("Launcher: ").latin1(); 2393 exp += i18n("Launcher: ").latin1();
2394 exp += dti.dta[i].d[j].launcher; 2394 exp += dti.dta[i].d[j].launcher;
2395 exp += "\n"; 2395 exp += "\n";
2396 2396
2397#ifndef PWM_EMBEDDED 2397#ifndef PWM_EMBEDDED
2398 if (f.writeBlock(exp.c_str(), exp.length()) != (Q_LONG)exp.length()) { 2398 if (f.writeBlock(exp.c_str(), exp.length()) != (Q_LONG)exp.length()) {
2399 unlockAll_tempoary(true); 2399 unlockAll_tempoary(true);
2400 f.close(); 2400 f.close();
2401 return e_writeFile; 2401 return e_writeFile;
2402 } 2402 }
2403#else 2403#else
2404 if (f.writeBlock(exp.c_str(), exp.length()) != (long)exp.length()) { 2404 if (f.writeBlock(exp.c_str(), exp.length()) != (long)exp.length()) {
2405 unlockAll_tempoary(true); 2405 unlockAll_tempoary(true);
2406 f.close(); 2406 f.close();
2407 return e_writeFile; 2407 return e_writeFile;
2408 } 2408 }
2409#endif 2409#endif
2410 } 2410 }
2411 } 2411 }
2412 unlockAll_tempoary(true); 2412 unlockAll_tempoary(true);
2413 f.close(); 2413 f.close();
2414 2414
2415 return e_success; 2415 return e_success;
2416} 2416}
2417 2417
2418PwMerror PwMDoc::importFromText(const QString *file, int format) 2418PwMerror PwMDoc::importFromText(const QString *file, int format)
2419{ 2419{
2420 PWM_ASSERT(file); 2420 PWM_ASSERT(file);
2421 if (format == 0) 2421 if (format == 0)
2422 return importText_PwM(file); 2422 return importText_PwM(file);
2423 else if (format == -1) { 2423 else if (format == -1) {
2424 // probe for all formats 2424 // probe for all formats
2425 if (importText_PwM(file) == e_success) 2425 if (importText_PwM(file) == e_success)
2426 return e_success; 2426 return e_success;
2427 dti.clear(); 2427 dti.clear();
2428 emitDataChanged(this); 2428 emitDataChanged(this);
2429 // add next format here... 2429 // add next format here...
2430 return e_fileFormat; 2430 return e_fileFormat;
2431 } 2431 }
2432 return e_invalidArg; 2432 return e_invalidArg;
2433} 2433}
2434 2434
2435PwMerror PwMDoc::importText_PwM(const QString *file) 2435PwMerror PwMDoc::importText_PwM(const QString *file)
2436{ 2436{
2437 PWM_ASSERT(file); 2437 PWM_ASSERT(file);
2438 FILE *f; 2438 FILE *f;
2439 int tmp; 2439 int tmp;
2440 ssize_t ret; 2440 ssize_t ret;
2441 string curCat; 2441 string curCat;
2442 unsigned int entriesRead = 0; 2442 unsigned int entriesRead = 0;
2443 PwMDataItem currItem; 2443 PwMDataItem currItem;
2444 f = fopen(file->latin1(), "r"); 2444 f = fopen(file->latin1(), "r");
2445 if (!f) 2445 if (!f)
2446 return e_openFile; 2446 return e_openFile;
2447 size_t ch_tmp_size = 1024; 2447 size_t ch_tmp_size = 1024;
2448 char *ch_tmp = (char*)malloc(ch_tmp_size); 2448 char *ch_tmp = (char*)malloc(ch_tmp_size);
2449 if (!ch_tmp) { 2449 if (!ch_tmp) {
2450 fclose(f); 2450 fclose(f);
2451 return e_outOfMem; 2451 return e_outOfMem;
2452 } 2452 }
2453 2453
2454 // - check header 2454 // - check header
2455 if (getline(&ch_tmp, &ch_tmp_size, f) == -1) // skip first line. 2455 if (getline(&ch_tmp, &ch_tmp_size, f) == -1) // skip first line.
2456 goto formatError; 2456 goto formatError;
2457 // check version-string and return version in "ch_tmp". 2457 // check version-string and return version in "ch_tmp".
2458 if (fscanf(f, "PwM v%s", ch_tmp) != 1) { 2458 if (fscanf(f, "PwM v%s", ch_tmp) != 1) {
2459 // header not recognized as PwM generated header 2459 // header not recognized as PwM generated header
2460 goto formatError; 2460 goto formatError;
2461 } 2461 }
2462 // set filepointer behind version-string-line previously checked 2462 // set filepointer behind version-string-line previously checked
2463 if (getline(&ch_tmp, &ch_tmp_size, f) == -1) 2463 if (getline(&ch_tmp, &ch_tmp_size, f) == -1)
2464 goto formatError; 2464 goto formatError;
2465 // skip next line containing the build-date 2465 // skip next line containing the build-date
2466 if (getline(&ch_tmp, &ch_tmp_size, f) == -1) 2466 if (getline(&ch_tmp, &ch_tmp_size, f) == -1)
2467 goto formatError; 2467 goto formatError;
2468 // read header termination line 2468 // read header termination line
2469 if (getline(&ch_tmp, &ch_tmp_size, f) == -1) 2469 if (getline(&ch_tmp, &ch_tmp_size, f) == -1)
2470 goto formatError; 2470 goto formatError;
2471 if (strcmp(ch_tmp, "==============================\n")) 2471 if (strcmp(ch_tmp, "==============================\n"))
2472 goto formatError; 2472 goto formatError;
2473 2473
2474 // - read entries 2474 // - read entries
2475 do { 2475 do {
2476 // find beginning of next category 2476 // find beginning of next category
2477 do { 2477 do {
2478 tmp = fgetc(f); 2478 tmp = fgetc(f);
2479 } while (tmp == '\n' && tmp != EOF); 2479 } while (tmp == '\n' && tmp != EOF);
2480 if (tmp == EOF) 2480 if (tmp == EOF)
2481 break; 2481 break;
2482 2482
2483 // decrement filepos by one 2483 // decrement filepos by one
2484 fseek(f, -1, SEEK_CUR); 2484 fseek(f, -1, SEEK_CUR);
2485 // read cat-name 2485 // read cat-name
2486 if (getline(&ch_tmp, &ch_tmp_size, f) == -1) 2486 if (getline(&ch_tmp, &ch_tmp_size, f) == -1)
2487 goto formatError; 2487 goto formatError;
2488 // check cat-name format 2488 // check cat-name format
2489 if (memcmp(ch_tmp, "== Category: ", 13) != 0) 2489 if (memcmp(ch_tmp, "== Category: ", 13) != 0)
2490 goto formatError; 2490 goto formatError;
2491 if (memcmp(ch_tmp + (strlen(ch_tmp) - 1 - 3), " ==", 3) != 0) 2491 if (memcmp(ch_tmp + (strlen(ch_tmp) - 1 - 3), " ==", 3) != 0)
2492 goto formatError; 2492 goto formatError;
2493 // copy cat-name 2493 // copy cat-name
2494 curCat.assign(ch_tmp + 13, strlen(ch_tmp) - 1 - 16); 2494 curCat.assign(ch_tmp + 13, strlen(ch_tmp) - 1 - 16);
2495 2495
2496 do { 2496 do {
2497 // find beginning of next entry 2497 // find beginning of next entry
2498 do { 2498 do {
2499 tmp = fgetc(f); 2499 tmp = fgetc(f);
2500 } while (tmp == '\n' && tmp != EOF && tmp != '='); 2500 } while (tmp == '\n' && tmp != EOF && tmp != '=');
2501 if (tmp == EOF) 2501 if (tmp == EOF)
2502 break; 2502 break;
2503 if (tmp == '=') { 2503 if (tmp == '=') {
2504 fseek(f, -1, SEEK_CUR); 2504 fseek(f, -1, SEEK_CUR);
2505 break; 2505 break;
2506 } 2506 }
2507 // decrement filepos by one 2507 // decrement filepos by one
2508 fseek(f, -1, SEEK_CUR); 2508 fseek(f, -1, SEEK_CUR);
2509 // read desc-line 2509 // read desc-line
2510 if (getline(&ch_tmp, &ch_tmp_size, f) == -1) 2510 if (getline(&ch_tmp, &ch_tmp_size, f) == -1)
2511 goto formatError; 2511 goto formatError;
2512 // check desc-line format 2512 // check desc-line format
2513 if (memcmp(ch_tmp, "-- ", 3) != 0) 2513 if (memcmp(ch_tmp, "-- ", 3) != 0)
2514 goto formatError; 2514 goto formatError;
2515 if (memcmp(ch_tmp + (strlen(ch_tmp) - 1 - 3), " --", 3) != 0) 2515 if (memcmp(ch_tmp + (strlen(ch_tmp) - 1 - 3), " --", 3) != 0)
2516 goto formatError; 2516 goto formatError;
2517 // add desc-line 2517 // add desc-line
2518 currItem.desc.assign(ch_tmp + 3, strlen(ch_tmp) - 1 - 6); 2518 currItem.desc.assign(ch_tmp + 3, strlen(ch_tmp) - 1 - 6);
2519 2519
2520 // read username-line 2520 // read username-line
2521 if ((ret = getline(&ch_tmp, &ch_tmp_size, f)) == -1) 2521 if ((ret = getline(&ch_tmp, &ch_tmp_size, f)) == -1)
2522 goto formatError; 2522 goto formatError;
2523 if (!textExtractEntry_PwM(ch_tmp, ret, &currItem.name)) 2523 if (!textExtractEntry_PwM(ch_tmp, ret, &currItem.name))
2524 goto formatError; 2524 goto formatError;
2525 2525
2526 // read pw-line 2526 // read pw-line
2527 if ((ret = getline(&ch_tmp, &ch_tmp_size, f)) == -1) 2527 if ((ret = getline(&ch_tmp, &ch_tmp_size, f)) == -1)
2528 goto formatError; 2528 goto formatError;
2529 if (!textExtractEntry_PwM(ch_tmp, ret, &currItem.pw)) 2529 if (!textExtractEntry_PwM(ch_tmp, ret, &currItem.pw))
2530 goto formatError; 2530 goto formatError;
2531 2531
2532 // read comment-line 2532 // read comment-line
2533 if ((ret = getline(&ch_tmp, &ch_tmp_size, f)) == -1) 2533 if ((ret = getline(&ch_tmp, &ch_tmp_size, f)) == -1)
2534 goto formatError; 2534 goto formatError;
2535 if (!textExtractEntry_PwM(ch_tmp, ret, &currItem.comment)) 2535 if (!textExtractEntry_PwM(ch_tmp, ret, &currItem.comment))
2536 goto formatError; 2536 goto formatError;
2537 2537
2538 // read URL-line 2538 // read URL-line
2539 if ((ret = getline(&ch_tmp, &ch_tmp_size, f)) == -1) 2539 if ((ret = getline(&ch_tmp, &ch_tmp_size, f)) == -1)
2540 goto formatError; 2540 goto formatError;
2541 if (!textExtractEntry_PwM(ch_tmp, ret, &currItem.url)) 2541 if (!textExtractEntry_PwM(ch_tmp, ret, &currItem.url))
2542 goto formatError; 2542 goto formatError;
2543 2543
2544 // read launcher-line 2544 // read launcher-line
2545 if ((ret = getline(&ch_tmp, &ch_tmp_size, f)) == -1) 2545 if ((ret = getline(&ch_tmp, &ch_tmp_size, f)) == -1)
2546 goto formatError; 2546 goto formatError;
2547 if (!textExtractEntry_PwM(ch_tmp, ret, &currItem.launcher)) 2547 if (!textExtractEntry_PwM(ch_tmp, ret, &currItem.launcher))
2548 goto formatError; 2548 goto formatError;
2549 2549
2550 currItem.lockStat = true; 2550 currItem.lockStat = true;
2551 currItem.listViewPos = -1; 2551 currItem.listViewPos = -1;
2552 addEntry(curCat.c_str(), &currItem, true); 2552 addEntry(curCat.c_str(), &currItem, true);
2553 ++entriesRead; 2553 ++entriesRead;
2554 } while (1); 2554 } while (1);
2555 } while (1); 2555 } while (1);
2556 if (!entriesRead) 2556 if (!entriesRead)
2557 goto formatError; 2557 goto formatError;
2558 2558
2559 free(ch_tmp); 2559 free(ch_tmp);
2560 fclose(f); 2560 fclose(f);
2561 flagDirty(); 2561 flagDirty();
2562 return e_success; 2562 return e_success;
2563 2563
2564 formatError: 2564 formatError:
2565 free(ch_tmp); 2565 free(ch_tmp);
2566 fclose(f); 2566 fclose(f);
2567 return e_fileFormat; 2567 return e_fileFormat;
2568} 2568}
2569 2569
2570bool PwMDoc::textExtractEntry_PwM(const char *in, ssize_t in_size, string *out) 2570bool PwMDoc::textExtractEntry_PwM(const char *in, ssize_t in_size, string *out)
2571{ 2571{
2572 PWM_ASSERT(in && out); 2572 PWM_ASSERT(in && out);
2573 ssize_t i = 0, len = in_size - 1; 2573 ssize_t i = 0, len = in_size - 1;
2574 while (i < len) { 2574 while (i < len) {
2575 if (in[i] == ':') 2575 if (in[i] == ':')
2576 break; 2576 break;
2577 ++i; 2577 ++i;
2578 } 2578 }
2579 i += 2; 2579 i += 2;
2580 *out = ""; 2580 *out = "";
2581 out->append(in + i, in_size - i - 1); 2581 out->append(in + i, in_size - i - 1);
2582 return true; 2582 return true;
2583} 2583}
2584 2584
2585PwMerror PwMDoc::exportToGpasman(const QString *file) 2585PwMerror PwMDoc::exportToGpasman(const QString *file)
2586{ 2586{
2587 PWM_ASSERT(file); 2587 PWM_ASSERT(file);
2588 GpasmanFile gp; 2588 GpasmanFile gp;
2589 int ret; 2589 int ret;
2590 2590
2591 if (!unlockAll_tempoary()) 2591 if (!unlockAll_tempoary())
2592 return e_lock; 2592 return e_lock;
2593 2593
2594 QString gpmPassword; 2594 QString gpmPassword;
2595 while (1) { 2595 while (1) {
2596 gpmPassword = requestNewMpw(0); 2596 gpmPassword = requestNewMpw(0);
2597 if (gpmPassword == "") { 2597 if (gpmPassword == "") {
2598 unlockAll_tempoary(true); 2598 unlockAll_tempoary(true);
2599 return e_noPw; 2599 return e_noPw;
2600 } 2600 }
2601 if (gpmPassword.length() < 4) { 2601 if (gpmPassword.length() < 4) {
2602 gpmPwLenErrMsgBox(); 2602 gpmPwLenErrMsgBox();
2603 } else { 2603 } else {
2604 break; 2604 break;
2605 } 2605 }
2606 } 2606 }
2607 2607
2608 ret = gp.save_init(file->latin1(), gpmPassword.latin1()); 2608 ret = gp.save_init(file->latin1(), gpmPassword.latin1());
2609 if (ret != 1) { 2609 if (ret != 1) {
2610 unlockAll_tempoary(true); 2610 unlockAll_tempoary(true);
2611 return e_accessFile; 2611 return e_accessFile;
2612 } 2612 }
2613 2613
2614 char *entry[4]; 2614 char *entry[4];
2615 unsigned int numCat = numCategories(), i; 2615 unsigned int numCat = numCategories(), i;
2616 unsigned int numEntr, j; 2616 unsigned int numEntr, j;
2617 int descLen, nameLen, pwLen, commentLen; 2617 int descLen, nameLen, pwLen, commentLen;
2618 for (i = 0; i < numCat; ++i) { 2618 for (i = 0; i < numCat; ++i) {
2619 numEntr = numEntries(i); 2619 numEntr = numEntries(i);
2620 for (j = 0; j < numEntr; ++j) { 2620 for (j = 0; j < numEntr; ++j) {
2621 descLen = dti.dta[i].d[j].desc.length(); 2621 descLen = dti.dta[i].d[j].desc.length();
2622 nameLen = dti.dta[i].d[j].name.length(); 2622 nameLen = dti.dta[i].d[j].name.length();
2623 pwLen = dti.dta[i].d[j].pw.length(); 2623 pwLen = dti.dta[i].d[j].pw.length();
2624 commentLen = dti.dta[i].d[j].comment.length(); 2624 commentLen = dti.dta[i].d[j].comment.length();
2625 entry[0] = new char[descLen + 1]; 2625 entry[0] = new char[descLen + 1];
2626 entry[1] = new char[nameLen + 1]; 2626 entry[1] = new char[nameLen + 1];
2627 entry[2] = new char[pwLen + 1]; 2627 entry[2] = new char[pwLen + 1];
2628 entry[3] = new char[commentLen + 1]; 2628 entry[3] = new char[commentLen + 1];
2629 strcpy(entry[0], descLen == 0 ? " " : dti.dta[i].d[j].desc.c_str()); 2629 strcpy(entry[0], descLen == 0 ? " " : dti.dta[i].d[j].desc.c_str());
2630 strcpy(entry[1], nameLen == 0 ? " " : dti.dta[i].d[j].name.c_str()); 2630 strcpy(entry[1], nameLen == 0 ? " " : dti.dta[i].d[j].name.c_str());
2631 strcpy(entry[2], pwLen == 0 ? " " : dti.dta[i].d[j].pw.c_str()); 2631 strcpy(entry[2], pwLen == 0 ? " " : dti.dta[i].d[j].pw.c_str());
2632 strcpy(entry[3], commentLen == 0 ? " " : dti.dta[i].d[j].comment.c_str()); 2632 strcpy(entry[3], commentLen == 0 ? " " : dti.dta[i].d[j].comment.c_str());
2633 entry[0][descLen == 0 ? descLen + 1 : descLen] = '\0'; 2633 entry[0][descLen == 0 ? descLen + 1 : descLen] = '\0';
2634 entry[1][nameLen == 0 ? nameLen + 1 : nameLen] = '\0'; 2634 entry[1][nameLen == 0 ? nameLen + 1 : nameLen] = '\0';
2635 entry[2][pwLen == 0 ? pwLen + 1 : pwLen] = '\0'; 2635 entry[2][pwLen == 0 ? pwLen + 1 : pwLen] = '\0';
2636 entry[3][commentLen == 0 ? commentLen + 1 : commentLen] = '\0'; 2636 entry[3][commentLen == 0 ? commentLen + 1 : commentLen] = '\0';
2637 2637
2638 ret = gp.save_entry(entry); 2638 ret = gp.save_entry(entry);
2639 if (ret == -1){ 2639 if (ret == -1){
2640 delete [] entry[0]; 2640 delete [] entry[0];
2641 delete [] entry[1]; 2641 delete [] entry[1];
2642 delete [] entry[2]; 2642 delete [] entry[2];
2643 delete [] entry[3]; 2643 delete [] entry[3];
2644 gp.save_finalize(); 2644 gp.save_finalize();
2645 unlockAll_tempoary(true); 2645 unlockAll_tempoary(true);
2646 return e_writeFile; 2646 return e_writeFile;
2647 } 2647 }
2648 2648
2649 delete [] entry[0]; 2649 delete [] entry[0];
2650 delete [] entry[1]; 2650 delete [] entry[1];
2651 delete [] entry[2]; 2651 delete [] entry[2];
2652 delete [] entry[3]; 2652 delete [] entry[3];
2653 } 2653 }
2654 } 2654 }
2655 unlockAll_tempoary(true); 2655 unlockAll_tempoary(true);
2656 if (gp.save_finalize() == -1) 2656 if (gp.save_finalize() == -1)
2657 return e_writeFile; 2657 return e_writeFile;
2658 2658
2659 return e_success; 2659 return e_success;
2660} 2660}
2661 2661
2662PwMerror PwMDoc::importFromGpasman(const QString *file) 2662PwMerror PwMDoc::importFromGpasman(const QString *file)
2663{ 2663{
2664 PWM_ASSERT(file); 2664 PWM_ASSERT(file);
2665 QString pw = requestMpw(false); 2665 QString pw = requestMpw(false);
2666 if (pw == "") 2666 if (pw == "")
2667 return e_noPw; 2667 return e_noPw;
2668 GpasmanFile gp; 2668 GpasmanFile gp;
2669 int ret, i; 2669 int ret, i;
2670 PwMerror ret2; 2670 PwMerror ret2;
2671 char *entry[4]; 2671 char *entry[4];
2672 PwMDataItem tmpData; 2672 PwMDataItem tmpData;
2673 ret = gp.load_init(file->latin1(), pw.latin1()); 2673 ret = gp.load_init(file->latin1(), pw.latin1());
2674 if (ret != 1) 2674 if (ret != 1)
2675 return e_accessFile; 2675 return e_accessFile;
2676 2676
2677 do { 2677 do {
2678 ret = gp.load_entry(entry); 2678 ret = gp.load_entry(entry);
2679 if(ret != 1) 2679 if(ret != 1)
2680 break; 2680 break;
2681 tmpData.desc = entry[0]; 2681 tmpData.desc = entry[0];
2682 tmpData.name = entry[1]; 2682 tmpData.name = entry[1];
2683 tmpData.pw = entry[2]; 2683 tmpData.pw = entry[2];
2684 tmpData.comment = entry[3]; 2684 tmpData.comment = entry[3];
2685 tmpData.lockStat = true; 2685 tmpData.lockStat = true;
2686 tmpData.listViewPos = -1; 2686 tmpData.listViewPos = -1;
2687 ret2 = addEntry(DEFAULT_CATEGORY, &tmpData, true); 2687 ret2 = addEntry(DEFAULT_CATEGORY, &tmpData, true);
2688 for (i = 0; i < 4; ++i) 2688 for (i = 0; i < 4; ++i)
2689 free(entry[i]); 2689 free(entry[i]);
2690 if (ret2 == e_maxAllowedEntr) { 2690 if (ret2 == e_maxAllowedEntr) {
2691 gp.load_finalize(); 2691 gp.load_finalize();
2692 return e_maxAllowedEntr; 2692 return e_maxAllowedEntr;
2693 } 2693 }
2694 } while (1); 2694 } while (1);
2695 gp.load_finalize(); 2695 gp.load_finalize();
2696 if (isDocEmpty()) 2696 if (isDocEmpty())
2697 return e_wrongPw; // we assume this. 2697 return e_wrongPw; // we assume this.
2698 2698
2699 flagDirty(); 2699 flagDirty();
2700 return e_success; 2700 return e_success;
2701} 2701}
2702 2702
2703void PwMDoc::ensureLvp() 2703void PwMDoc::ensureLvp()
2704{ 2704{
2705 if (isDocEmpty()) 2705 if (isDocEmpty())
2706 return; 2706 return;
2707 2707
2708 vector< vector<PwMDataItem>::iterator > undefined; 2708 vector< vector<PwMDataItem>::iterator > undefined;
2709 vector< vector<PwMDataItem>::iterator >::iterator undefBegin, 2709 vector< vector<PwMDataItem>::iterator >::iterator undefBegin,
2710 undefEnd, 2710 undefEnd,
2711 undefI; 2711 undefI;
2712 vector<PwMCategoryItem>::iterator catBegin = dti.dta.begin(), 2712 vector<PwMCategoryItem>::iterator catBegin = dti.dta.begin(),
2713 catEnd = dti.dta.end(), 2713 catEnd = dti.dta.end(),
2714 catI = catBegin; 2714 catI = catBegin;
2715 vector<PwMDataItem>::iterator entrBegin, entrEnd, entrI; 2715 vector<PwMDataItem>::iterator entrBegin, entrEnd, entrI;
2716 int lvpTop, tmpLvp; 2716 int lvpTop, tmpLvp;
2717 2717
2718 while (catI != catEnd) { 2718 while (catI != catEnd) {
2719 lvpTop = -1; 2719 lvpTop = -1;
2720 undefined.clear(); 2720 undefined.clear();
2721 2721
2722 entrBegin = catI->d.begin(); 2722 entrBegin = catI->d.begin();
2723 entrEnd = catI->d.end(); 2723 entrEnd = catI->d.end();
2724 entrI = entrBegin; 2724 entrI = entrBegin;
2725 2725
2726 while (entrI != entrEnd) { 2726 while (entrI != entrEnd) {
2727 tmpLvp = entrI->listViewPos; 2727 tmpLvp = entrI->listViewPos;
2728 if (tmpLvp == -1) 2728 if (tmpLvp == -1)
2729 undefined.push_back(entrI); 2729 undefined.push_back(entrI);
2730 else if (tmpLvp > lvpTop) 2730 else if (tmpLvp > lvpTop)
2731 lvpTop = tmpLvp; 2731 lvpTop = tmpLvp;
2732 ++entrI; 2732 ++entrI;
2733 } 2733 }
2734 undefBegin = undefined.begin(); 2734 undefBegin = undefined.begin();
2735 undefEnd = undefined.end(); 2735 undefEnd = undefined.end();
2736 undefI = undefBegin; 2736 undefI = undefBegin;
2737 while (undefI != undefEnd) { 2737 while (undefI != undefEnd) {
2738 (*undefI)->listViewPos = ++lvpTop; 2738 (*undefI)->listViewPos = ++lvpTop;
2739 ++undefI; 2739 ++undefI;
2740 } 2740 }
2741 ++catI; 2741 ++catI;
2742 } 2742 }
2743} 2743}
2744 2744
2745QString PwMDoc::getTitle() 2745QString PwMDoc::getTitle()
2746{ 2746{
2747 /* NOTE: We have to ensure, that the returned title 2747 /* NOTE: We have to ensure, that the returned title
2748 * is unique and not reused somewhere else while 2748 * is unique and not reused somewhere else while
2749 * this document is valid (open). 2749 * this document is valid (open).
2750 */ 2750 */
2751 QString title(getFilename()); 2751 QString title(getFilename());
2752 if (title.isEmpty()) { 2752 if (title.isEmpty()) {
2753 if (unnamedNum == 0) { 2753 if (unnamedNum == 0) {
2754 unnamedNum = PwMDocList::getNewUnnamedNumber(); 2754 unnamedNum = PwMDocList::getNewUnnamedNumber();
2755 PWM_ASSERT(unnamedNum != 0); 2755 PWM_ASSERT(unnamedNum != 0);
2756 } 2756 }
2757 title = DEFAULT_TITLE; 2757 title = DEFAULT_TITLE;
2758 title += " "; 2758 title += " ";
2759 title += tostr(unnamedNum).c_str(); 2759 title += tostr(unnamedNum).c_str();
2760 } 2760 }
2761 return title; 2761 return title;
2762} 2762}
2763 2763
2764bool PwMDoc::tryDelete() 2764bool PwMDoc::tryDelete()
2765{ 2765{
2766 if (deleted) 2766 if (deleted)
2767 return true; 2767 return true;
2768 int ret; 2768 int ret;
2769 if (isDirty()) { 2769 if (isDirty()) {
2770 ret = dirtyAskSave(getTitle()); 2770 ret = dirtyAskSave(getTitle());
2771 if (ret == 0) { // save to disk 2771 if (ret == 0) { // save to disk
2772 if (!saveDocUi(this)) 2772 if (!saveDocUi(this))
2773 goto out_ignore; 2773 goto out_ignore;
2774 } else if (ret == 1) { // don't save and delete 2774 } else if (ret == 1) { // don't save and delete
2775 goto out_accept; 2775 goto out_accept;
2776 } else { // cancel operation 2776 } else { // cancel operation
2777 goto out_ignore; 2777 goto out_ignore;
2778 } 2778 }
2779 } 2779 }
2780out_accept: 2780out_accept:
2781 deleted = true; 2781 deleted = true;
2782 delete this; 2782 delete this;
2783 return true; 2783 return true;
2784out_ignore: 2784out_ignore:
2785 return false; 2785 return false;
2786} 2786}
2787 2787
2788 2788
2789 2789
2790#ifdef PWM_EMBEDDED 2790#ifdef PWM_EMBEDDED
2791//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. 2792//US it could have been defined as static, but I did not want to.
2793PwMerror PwMDoc::syncronize(KSyncManager* manager, PwMDoc* syncLocal , PwMDoc* syncRemote, int mode ) 2793PwMerror PwMDoc::syncronize(KSyncManager* manager, PwMDoc* syncLocal , PwMDoc* syncRemote, int mode )
2794{ 2794{
2795 int addedPasswordsLocal = 0; 2795 int addedPasswordsLocal = 0;
2796 int addedPasswordsRemote = 0; 2796 int addedPasswordsRemote = 0;
2797 int deletedPasswordsRemote = 0; 2797 int deletedPasswordsRemote = 0;
2798 int deletedPasswordsLocal = 0; 2798 int deletedPasswordsLocal = 0;
2799 int changedLocal = 0; 2799 int changedLocal = 0;
2800 int changedRemote = 0; 2800 int changedRemote = 0;
2801 2801
2802 PwMSyncItem* syncItemLocal; 2802 PwMSyncItem syncItemLocal;
2803 PwMSyncItem* syncItemRemote; 2803 PwMSyncItem syncItemRemote;
2804 2804
2805 QString mCurrentSyncName = manager->getCurrentSyncName(); 2805 QString mCurrentSyncName = manager->getCurrentSyncName();
2806 QString mCurrentSyncDevice = manager->getCurrentSyncDevice(); 2806 QString mCurrentSyncDevice = manager->getCurrentSyncDevice();
2807 2807
2808 bool fullDateRange = false; 2808 bool fullDateRange = false;
2809 int take; 2809 int take;
2810 // local->resetTempSyncStat(); 2810 // local->resetTempSyncStat();
2811 QDateTime mLastSync = QDateTime::currentDateTime(); 2811 QDateTime mLastSync = QDateTime::currentDateTime();
2812 QDateTime modifiedSync = mLastSync; 2812 QDateTime modifiedSync = mLastSync;
2813 2813
2814 unsigned int index; 2814 unsigned int index;
2815 //Step 1. Find syncinfo in Local file and create if not existent. 2815 //Step 1. Find syncinfo in Local file and create if not existent.
2816 bool found = syncLocal->findSyncData(mCurrentSyncDevice, &index); 2816 bool found = syncLocal->findSyncData(mCurrentSyncDevice, &index);
2817 if (found == false) 2817 if (found == false)
2818 { 2818 {
2819 PwMSyncItem newSyncItemLocal; 2819 PwMSyncItem newSyncItemLocal;
2820 newSyncItemLocal.syncName = mCurrentSyncDevice; 2820 newSyncItemLocal.syncName = mCurrentSyncDevice;
2821 newSyncItemLocal.lastSyncDate = mLastSync; 2821 newSyncItemLocal.lastSyncDate = mLastSync;
2822 syncLocal->addSyncDataEntry(&newSyncItemLocal, true); 2822 syncLocal->addSyncDataEntry(&newSyncItemLocal, true);
2823 found = syncLocal->findSyncData(mCurrentSyncDevice, &index); 2823 found = syncLocal->findSyncData(mCurrentSyncDevice, &index);
2824 if (found == false) { 2824 if (found == false) {
2825 qDebug("PwMDoc::syncronize : newly created local sync data could not be found"); 2825 qDebug("PwMDoc::syncronize : newly created local sync data could not be found");
2826 return e_syncError; 2826 return e_syncError;
2827 } 2827 }
2828 } 2828 }
2829 2829
2830 syncItemLocal = syncLocal->getSyncDataEntry(index); 2830 syncItemLocal = syncLocal->getSyncDataEntry(index);
2831 qDebug("Last Sync %s ", syncItemLocal->lastSyncDate.toString().latin1()); 2831 qDebug("Last Sync %s ", syncItemLocal.lastSyncDate.toString().latin1());
2832 2832
2833 //Step 2. Find syncinfo in remote file and create if not existent. 2833 //Step 2. Find syncinfo in remote file and create if not existent.
2834 found = syncRemote->findSyncData(mCurrentSyncName, &index); 2834 found = syncRemote->findSyncData(mCurrentSyncName, &index);
2835 if (found == false) 2835 if (found == false)
2836 { 2836 {
2837 qDebug("FULLDATE 1"); 2837 qDebug("FULLDATE 1");
2838 fullDateRange = true; 2838 fullDateRange = true;
2839 PwMSyncItem newSyncItemRemote; 2839 PwMSyncItem newSyncItemRemote;
2840 newSyncItemRemote.syncName = mCurrentSyncName; 2840 newSyncItemRemote.syncName = mCurrentSyncName;
2841 newSyncItemRemote.lastSyncDate = mLastSync; 2841 newSyncItemRemote.lastSyncDate = mLastSync;
2842 syncRemote->addSyncDataEntry(&newSyncItemRemote, true); 2842 syncRemote->addSyncDataEntry(&newSyncItemRemote, true);
2843 found = syncRemote->findSyncData(mCurrentSyncName, &index); 2843 found = syncRemote->findSyncData(mCurrentSyncName, &index);
2844 if (found == false) { 2844 if (found == false) {
2845 qDebug("PwMDoc::syncronize : newly created remote sync data could not be found"); 2845 qDebug("PwMDoc::syncronize : newly created remote sync data could not be found");
2846 return e_syncError; 2846 return e_syncError;
2847 } 2847 }
2848 } 2848 }
2849 2849
2850 syncItemRemote = syncRemote->getSyncDataEntry(index); 2850 syncItemRemote = syncRemote->getSyncDataEntry(index);
2851 //and remove the found entry here. We will reenter it later again. 2851 //and remove the found entry here. We will reenter it later again.
2852 syncRemote->delSyncDataEntry(index, true); 2852 syncRemote->delSyncDataEntry(index, true);
2853 2853
2854 2854
2855 if ( syncItemLocal->lastSyncDate == mLastSync ) { 2855 if ( syncItemLocal.lastSyncDate == mLastSync ) {
2856 qDebug("FULLDATE 2"); 2856 qDebug("FULLDATE 2");
2857 fullDateRange = true; 2857 fullDateRange = true;
2858 } 2858 }
2859 2859
2860 if ( ! fullDateRange ) { 2860 if ( ! fullDateRange ) {
2861 if ( syncItemLocal->lastSyncDate != syncItemRemote->lastSyncDate ) { 2861 if ( syncItemLocal.lastSyncDate != syncItemRemote->lastSyncDate ) {
2862 2862
2863 // qDebug("set fulldate to true %s %s" ,addresseeLSync->dtStart().toString().latin1(), addresseeRSync->dtStart().toString().latin1() ); 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()); 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; 2865 fullDateRange = true;
2866 qDebug("FULLDATE 3 %s %s", syncItemLocal->lastSyncDate.toString().latin1() , syncItemRemote->lastSyncDate.toString().latin1() ); 2866 qDebug("FULLDATE 3 %s %s", syncItemLocal.lastSyncDate.toString().latin1() , syncItemRemote.lastSyncDate.toString().latin1() );
2867 } 2867 }
2868 } 2868 }
2869 // fullDateRange = true; // debug only! 2869 // fullDateRange = true; // debug only!
2870 if ( fullDateRange ) 2870 if ( fullDateRange )
2871 mLastSync = QDateTime::currentDateTime().addDays( -100*365); 2871 mLastSync = QDateTime::currentDateTime().addDays( -100*365);
2872 else 2872 else
2873 mLastSync = syncItemLocal->lastSyncDate; 2873 mLastSync = syncItemLocal->lastSyncDate;
2874 2874
2875 2875
2876 qDebug("*************************** "); 2876 qDebug("*************************** ");
2877 // qDebug("mLastAddressbookSync %s ",mLastAddressbookSync.toString().latin1() ); 2877 // qDebug("mLastAddressbookSync %s ",mLastAddressbookSync.toString().latin1() );
2878 QStringList er = syncRemote->getIDEntryList(); 2878 QStringList er = syncRemote->getIDEntryList();
2879 PwMDataItem* inRemote ;//= er.first(); 2879 PwMDataItem* inRemote ;//= er.first();
2880 PwMDataItem* inLocal; 2880 PwMDataItem* inLocal;
2881 unsigned int catLocal, indexLocal; 2881 unsigned int catLocal, indexLocal;
2882 unsigned int catRemote, indexRemote; 2882 unsigned int catRemote, indexRemote;
2883 2883
2884 QString uid; 2884 QString uid;
2885 manager->showProgressBar(0, i18n("Syncing - close to abort!"), er.count()); 2885 manager->showProgressBar(0, i18n("Syncing - close to abort!"), er.count());
2886 2886
2887 int modulo = (er.count()/10)+1; 2887 int modulo = (er.count()/10)+1;
2888 unsigned int incCounter = 0; 2888 unsigned int incCounter = 0;
2889 while ( incCounter < er.count()) { 2889 while ( incCounter < er.count()) {
2890 if (manager->isProgressBarCanceled()) 2890 if (manager->isProgressBarCanceled())
2891 return e_syncError; 2891 return e_syncError;
2892 if ( incCounter % modulo == 0 ) 2892 if ( incCounter % modulo == 0 )
2893 manager->showProgressBar(incCounter); 2893 manager->showProgressBar(incCounter);
2894 2894
2895 uid = er[ incCounter ]; 2895 uid = er[ incCounter ];
2896 qDebug("sync uid %s from remote file", uid.latin1()); 2896 qDebug("sync uid %s from remote file", uid.latin1());
2897 2897
2898 qApp->processEvents(); 2898 qApp->processEvents();
2899 2899
2900 inLocal = syncLocal->findEntryByID( uid, &catLocal, &indexLocal ); 2900 inLocal = syncLocal->findEntryByID( uid, &catLocal, &indexLocal );
2901 inRemote = syncRemote->findEntryByID( uid, &catRemote, &indexRemote ); 2901 inRemote = syncRemote->findEntryByID( uid, &catRemote, &indexRemote );
2902 PWM_ASSERT(inRemote); 2902 PWM_ASSERT(inRemote);
2903 if ( inLocal != 0 ) { // maybe conflict - same uid in both files 2903 if ( inLocal != 0 ) { // maybe conflict - same uid in both files
2904 if ( (take = takePwMDataItem( inLocal, inRemote, mLastSync, mode, fullDateRange) ) ) { 2904 if ( (take = takePwMDataItem( inLocal, inRemote, mLastSync, mode, fullDateRange) ) ) {
2905 //qDebug("take %d %s ", take, inL.summary().latin1()); 2905 //qDebug("take %d %s ", take, inL.summary().latin1());
2906 if ( take == 3 ) 2906 if ( take == 3 )
2907 return e_syncError; 2907 return e_syncError;
2908 if ( take == 1 ) {// take local 2908 if ( take == 1 ) {// take local
2909 //US syncRemote->removeAddressee( inRemote ); 2909 //US syncRemote->removeAddressee( inRemote );
2910 (*inRemote) = (*inLocal); 2910 (*inRemote) = (*inLocal);
2911 //US syncRemote->insertAddressee( inRemote , false); 2911 //US syncRemote->insertAddressee( inRemote , false);
2912 ++changedRemote; 2912 ++changedRemote;
2913 } else { // take == 2 take remote 2913 } else { // take == 2 take remote
2914 //US syncLocal->removeAddressee( inLocal ); 2914 //US syncLocal->removeAddressee( inLocal );
2915 (*inLocal) = (*inRemote); 2915 (*inLocal) = (*inRemote);
2916 //US syncLocal->insertAddressee( inLocal , false ); 2916 //US syncLocal->insertAddressee( inLocal , false );
2917 ++changedLocal; 2917 ++changedLocal;
2918 } 2918 }
2919 } 2919 }
2920 } else { // no conflict 2920 } else { // no conflict
2921 if ( inRemote->meta.update > mLastSync || mode == 5 ) { 2921 if ( inRemote->meta.update > mLastSync || mode == 5 ) {
2922 inRemote->meta.update = modifiedSync; 2922 inRemote->meta.update = modifiedSync;
2923
2924 //first check if we have a matching category in the local file
2925 const string* remotecat = syncRemote->getCategory(catRemote);
2923 //US syncRemote->insertAddressee( inRemote, false ); 2926 //US syncRemote->insertAddressee( inRemote, false );
2924 //US syncLocal->insertAddressee( inRemote, false ); 2927 //US syncLocal->insertAddressee( inRemote, false );
2925 syncLocal->addEntry("newcategory", inRemote, true, false); 2928 syncLocal->addEntry(remotecat->c_str(), inRemote, true, false);
2926 2929
2927 ++addedPasswordsLocal; 2930 ++addedPasswordsLocal;
2928 } else { 2931 } else {
2929 // pending checkExternSyncAddressee(addresseeRSyncSharp, inR); 2932 // pending checkExternSyncAddressee(addresseeRSyncSharp, inR);
2930 syncRemote->delEntry(catRemote, indexRemote, true); 2933 syncRemote->delEntry(catRemote, indexRemote, true);
2931 //USsyncRemote->removeAddressee( inRemote ); 2934 //USsyncRemote->removeAddressee( inRemote );
2932 ++deletedPasswordsRemote; 2935 ++deletedPasswordsRemote;
2933 } 2936 }
2934 } 2937 }
2935 2938
2936 ++incCounter; 2939 ++incCounter;
2937 } 2940 }
2938 2941
2939 2942
2940 er.clear(); 2943 er.clear();
2941 QStringList el = syncLocal->getIDEntryList(); 2944 QStringList el = syncLocal->getIDEntryList();
2942 modulo = (el.count()/10)+1; 2945 modulo = (el.count()/10)+1;
2943 2946
2944 manager->showProgressBar(0, i18n("Add / remove addressees"), el.count()); 2947 manager->showProgressBar(0, i18n("Add / remove addressees"), el.count());
2945 incCounter = 0; 2948 incCounter = 0;
2946 while ( incCounter < el.count()) { 2949 while ( incCounter < el.count()) {
2947 qApp->processEvents(); 2950 qApp->processEvents();
2948 if (manager->isProgressBarCanceled()) 2951 if (manager->isProgressBarCanceled())
2949 return e_syncError; 2952 return e_syncError;
2950 if ( incCounter % modulo == 0 ) 2953 if ( incCounter % modulo == 0 )
2951 manager->showProgressBar(incCounter); 2954 manager->showProgressBar(incCounter);
2952 uid = el[ incCounter ]; 2955 uid = el[ incCounter ];
2953 2956
2954 inLocal = syncLocal->findEntryByID( uid, &catLocal, &indexLocal ); 2957 inLocal = syncLocal->findEntryByID( uid, &catLocal, &indexLocal );
2955 inRemote = syncRemote->findEntryByID( uid, &catRemote, &indexRemote ); 2958 inRemote = syncRemote->findEntryByID( uid, &catRemote, &indexRemote );
2959 PWM_ASSERT(inLocal);
2960
2956 if ( inRemote == 0 ) { 2961 if ( inRemote == 0 ) {
2957 if ( inLocal->meta.update < mLastSync && mode != 4 ) { 2962 if ( inLocal->meta.update < mLastSync && mode != 4 ) {
2958 // pending checkExternSyncAddressee(addresseeLSyncSharp, inL); 2963 // pending checkExternSyncAddressee(addresseeLSyncSharp, inL);
2959 syncLocal->delEntry(catLocal, indexLocal, true); 2964 syncLocal->delEntry(catLocal, indexLocal, true);
2960 //USsyncLocal->removeAddressee( inLocal ); 2965 //USsyncLocal->removeAddressee( inLocal );
2961 ++deletedPasswordsLocal; 2966 ++deletedPasswordsLocal;
2962 } else { 2967 } else {
2963 if ( ! manager->mWriteBackExistingOnly ) { 2968 if ( ! manager->mWriteBackExistingOnly ) {
2964 ++addedPasswordsRemote; 2969 ++addedPasswordsRemote;
2965 inLocal->meta.update = modifiedSync; 2970 inLocal->meta.update = modifiedSync;
2971
2972 //first check if we have a matching category in the remote file
2973 const string* localcat = syncLocal->getCategory(catLocal);
2974
2966 //USsyncLocal->insertAddressee( inLocal, false ); 2975 //USsyncLocal->insertAddressee( inLocal, false );
2967 (*inRemote) = (*inLocal); 2976 PwMDataItem newEntry;
2977 newEntry = *inLocal;
2978 inRemote = &newEntry;
2979
2968 //USsyncRemote->insertAddressee( inRemote, false ); 2980 //USsyncRemote->insertAddressee( inRemote, false );
2969 syncRemote->addEntry("newcategory", inRemote, true, false); 2981 syncRemote->addEntry(localcat->c_str(), inRemote, true, false);
2970 2982
2971 } 2983 }
2972 } 2984 }
2973 2985
2974 } 2986 }
2975 ++incCounter; 2987 ++incCounter;
2976 } 2988 }
2977 el.clear(); 2989 el.clear();
2978 manager->hideProgressBar(); 2990 manager->hideProgressBar();
2979 2991
2980 // Now write the info back into the sync data space of the files 2992 // Now write the info back into the sync data space of the files
2981 2993
2982 mLastSync = QDateTime::currentDateTime().addSecs( 1 ); 2994 mLastSync = QDateTime::currentDateTime().addSecs( 1 );
2983 // get rid of micro seconds 2995 // get rid of micro seconds
2984 QTime t = mLastSync.time(); 2996 QTime t = mLastSync.time();
2985 mLastSync.setTime( QTime (t.hour (), t.minute (), t.second () ) ); 2997 mLastSync.setTime( QTime (t.hour (), t.minute (), t.second () ) );
2986 2998
2987 2999
2988 syncItemLocal->lastSyncDate = mLastSync; 3000 syncItemLocal.lastSyncDate = mLastSync;
2989 syncItemRemote->lastSyncDate = mLastSync; 3001 syncItemRemote.lastSyncDate = mLastSync;
2990 3002
2991 // addresseeRSync.setRole( i18n("!Remote from: ")+mCurrentSyncName ) ; 3003 // addresseeRSync.setRole( i18n("!Remote from: ")+mCurrentSyncName ) ;
2992 // addresseeLSync.setRole(i18n("!Local from: ") + mCurrentSyncName ); 3004 // addresseeLSync.setRole(i18n("!Local from: ") + mCurrentSyncName );
2993 3005
2994 syncRemote->addSyncDataEntry( syncItemRemote, false ); 3006 syncRemote->addSyncDataEntry( syncItemRemote, false );
2995 syncLocal->addSyncDataEntry( syncItemLocal, false ); 3007 syncLocal->addSyncDataEntry( syncItemLocal, false );
2996 QString mes; 3008 QString mes;
2997 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 ); 3009 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 );
2998 if ( manager->mShowSyncSummary ) { 3010 if ( manager->mShowSyncSummary ) {
2999 KMessageBox::information(0, mes, i18n("PWM/Pi Synchronization") ); 3011 KMessageBox::information(0, mes, i18n("PWM/Pi Synchronization") );
3000 } 3012 }
3001 qDebug( mes ); 3013 qDebug( mes );
3002 return e_success; 3014 return e_success;
3003} 3015}
3004 3016
3005 3017
3006int PwMDoc::takePwMDataItem( PwMDataItem* local, PwMDataItem* remote, QDateTime lastSync, int mode , bool full ) 3018int PwMDoc::takePwMDataItem( PwMDataItem* local, PwMDataItem* remote, QDateTime lastSync, int mode , bool full )
3007{ 3019{
3008 // 0 equal 3020 // 0 equal
3009 // 1 take local 3021 // 1 take local
3010 // 2 take remote 3022 // 2 take remote
3011 // 3 cancel 3023 // 3 cancel
3012 QDateTime localMod = local->meta.update; 3024 QDateTime localMod = local->meta.update;
3013 QDateTime remoteMod = remote->meta.update; 3025 QDateTime remoteMod = remote->meta.update;
3014 3026
3015 //US QString mCurrentSyncDevice = syncManager->getCurrentSyncDevice(); 3027 //US QString mCurrentSyncDevice = syncManager->getCurrentSyncDevice();
3016 3028
3017 if ( localMod == remoteMod ) 3029 if ( localMod == remoteMod )
3018 return 0; 3030 return 0;
3019 3031
3020 qDebug(" %d %d conflict on %s %s ", mode, full, local->desc.c_str(), remote->desc.c_str() ); 3032 qDebug(" %d %d conflict on %s %s ", mode, full, local->desc.c_str(), remote->desc.c_str() );
3021 3033
3022 //qDebug("%s %d %s %d", local->lastModified().toString().latin1() , localMod, remote->lastModified().toString().latin1(), remoteMod); 3034 //qDebug("%s %d %s %d", local->lastModified().toString().latin1() , localMod, remote->lastModified().toString().latin1(), remoteMod);
3023 //qDebug("%d %d %d %d ", local->lastModified().time().second(), local->lastModified().time().msec(), remote->lastModified().time().second(), remote->lastModified().time().msec() ); 3035 //qDebug("%d %d %d %d ", local->lastModified().time().second(), local->lastModified().time().msec(), remote->lastModified().time().second(), remote->lastModified().time().msec() );
3024 //full = true; //debug only 3036 //full = true; //debug only
3025 if ( full ) { 3037 if ( full ) {
3026 bool equ = true;//US ( (*local) == (*remote) ); 3038 bool equ = true;//US ( (*local) == (*remote) );
3027 if ( equ ) { 3039 if ( equ ) {
3028 //qDebug("equal "); 3040 //qDebug("equal ");
3029 if ( mode < SYNC_PREF_FORCE_LOCAL ) 3041 if ( mode < SYNC_PREF_FORCE_LOCAL )
3030 return 0; 3042 return 0;
3031 3043
3032 }//else //debug only 3044 }//else //debug only
3033 //qDebug("not equal %s %s ", local->summary().latin1(), remote->summary().latin1()); 3045 //qDebug("not equal %s %s ", local->summary().latin1(), remote->summary().latin1());
3034 } 3046 }
3035 3047
3036 int result; 3048 int result;
3037 bool localIsNew; 3049 bool localIsNew;
3038 //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() ); 3050 //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() );
3039 3051
3040 if ( full && mode < SYNC_PREF_NEWEST ) 3052 if ( full && mode < SYNC_PREF_NEWEST )
3041 mode = SYNC_PREF_ASK; 3053 mode = SYNC_PREF_ASK;
3042 3054
3043 switch( mode ) { 3055 switch( mode ) {
3044 case SYNC_PREF_LOCAL: 3056 case SYNC_PREF_LOCAL:
3045 if ( lastSync > remoteMod ) 3057 if ( lastSync > remoteMod )
3046 return 1; 3058 return 1;
3047 if ( lastSync > localMod ) 3059 if ( lastSync > localMod )
3048 return 2; 3060 return 2;
3049 return 1; 3061 return 1;
3050 break; 3062 break;
3051 case SYNC_PREF_REMOTE: 3063 case SYNC_PREF_REMOTE:
3052 if ( lastSync > remoteMod ) 3064 if ( lastSync > remoteMod )
3053 return 1; 3065 return 1;
3054 if ( lastSync > localMod ) 3066 if ( lastSync > localMod )
3055 return 2; 3067 return 2;
3056 return 2; 3068 return 2;
3057 break; 3069 break;
3058 case SYNC_PREF_NEWEST: 3070 case SYNC_PREF_NEWEST:
3059 if ( localMod > remoteMod ) 3071 if ( localMod > remoteMod )
3060 return 1; 3072 return 1;
3061 else 3073 else
3062 return 2; 3074 return 2;
3063 break; 3075 break;
3064 case SYNC_PREF_ASK: 3076 case SYNC_PREF_ASK:
3065 //qDebug("lsy %s --- lo %s --- re %s ", lastSync.toString().latin1(), localMod.toString().latin1(), remoteMod.toString().latin1() ); 3077 //qDebug("lsy %s --- lo %s --- re %s ", lastSync.toString().latin1(), localMod.toString().latin1(), remoteMod.toString().latin1() );
3066 if ( lastSync > remoteMod ) 3078 if ( lastSync > remoteMod )
3067 return 1; 3079 return 1;
3068 if ( lastSync > localMod ) 3080 if ( lastSync > localMod )
3069 return 2; 3081 return 2;
3070 localIsNew = localMod >= remoteMod; 3082 localIsNew = localMod >= remoteMod;
3071 //qDebug("conflict! ************************************** "); 3083 //qDebug("conflict! ************************************** ");
3072 { 3084 {
3073 PwMDataItemChooser acd ( *local,*remote, localIsNew , 0/*this*/ ); 3085 PwMDataItemChooser acd ( *local,*remote, localIsNew , 0/*this*/ );
3074 result = acd.executeD(localIsNew); 3086 result = acd.executeD(localIsNew);
3075 return result; 3087 return result;
3076 } 3088 }
3077 break; 3089 break;
3078 case SYNC_PREF_FORCE_LOCAL: 3090 case SYNC_PREF_FORCE_LOCAL:
3079 return 1; 3091 return 1;
3080 break; 3092 break;
3081 case SYNC_PREF_FORCE_REMOTE: 3093 case SYNC_PREF_FORCE_REMOTE:
3082 return 2; 3094 return 2;
3083 break; 3095 break;
3084 3096
3085 default: 3097 default:
3086 // SYNC_PREF_TAKE_BOTH not implemented 3098 // SYNC_PREF_TAKE_BOTH not implemented
3087 break; 3099 break;
3088 } 3100 }
3089 return 0; 3101 return 0;
3090} 3102}
3091 3103
3092 3104
3093 3105
3094 3106
3095//this are the overwritten callbackmethods from the syncinterface 3107//this are the overwritten callbackmethods from the syncinterface
3096bool PwMDoc::sync(KSyncManager* manager, QString filename, int mode) 3108bool PwMDoc::sync(KSyncManager* manager, QString filename, int mode)
3097{ 3109{
3098 QString mCurrentSyncDevice = manager->getCurrentSyncDevice(); 3110 QString mCurrentSyncDevice = manager->getCurrentSyncDevice();
3099 3111
3100 //1) unlock local file first if necessary (ask for password) 3112 //1) unlock local file first if necessary (ask for password)
3101 if (this->isDeepLocked()) { 3113 if (this->isDeepLocked()) {
3102 PwMerror ret = this->deepLock(false); 3114 PwMerror ret = this->deepLock(false);
3103 if (ret != e_success) 3115 if (ret != e_success)
3104 return false; 3116 return false;
3105 } 3117 }
3106 3118
3107 //2) construct and open a new doc on the stack(automatic cleanup) for remote file. 3119 //2) construct and open a new doc on the stack(automatic cleanup) for remote file.
3108 PwMDoc syncTarget(this, "synctarget"); 3120 PwMDoc syncTarget(this, "synctarget");
3109 PwMDoc* pSyncTarget = &syncTarget; 3121 PwMDoc* pSyncTarget = &syncTarget;
3110 3122
3111 3123
3112 PwMerror err = pSyncTarget->openDoc(&filename, 1 /*== open with all entries locked*/); 3124 PwMerror err = pSyncTarget->openDoc(&filename, 1 /*== open with all entries locked*/);
3113 3125
3114 if (err == e_alreadyOpen) { 3126 if (err == e_alreadyOpen) {
3115 PwMDocList::listItem li; 3127 PwMDocList::listItem li;
3116 if (getOpenDocList()->find(filename.latin1(), &li)) 3128 if (getOpenDocList()->find(filename.latin1(), &li))
3117 pSyncTarget = li.doc; 3129 pSyncTarget = li.doc;
3118 else { 3130 else {
3119 qDebug("PwmDoc::sync: sync failed. Error %i while opening file %s",err, filename.latin1()); 3131 qDebug("PwmDoc::sync: sync failed. Error %i while opening file %s",err, filename.latin1());
3120 return false; 3132 return false;
3121 } 3133 }
3122 } 3134 }
3123 else if (err != e_success) { 3135 else if (err != e_success) {
3124 qDebug("PwmDoc::sync: sync failed. Error %i while opening file %s",err, filename.latin1()); 3136 qDebug("PwmDoc::sync: sync failed. Error %i while opening file %s",err, filename.latin1());
3125 return false; 3137 return false;
3126 } 3138 }
3127 3139
3128 qDebug("PWM file loaded %s,sync mode %d",filename.latin1(), mode ); 3140 qDebug("PWM file loaded %s,sync mode %d",filename.latin1(), mode );
3129 3141
3130 3142
3131 //3) unlock remote file first if necessary (ask for password) 3143 //3) unlock remote file first if necessary (ask for password)
3132 if (pSyncTarget->isDeepLocked()) { 3144 if (pSyncTarget->isDeepLocked()) {
3133 PwMerror ret = pSyncTarget->deepLock(false); 3145 PwMerror ret = pSyncTarget->deepLock(false);
3134 if (ret != e_success) 3146 if (ret != e_success)
3135 return false; 3147 return false;
3136 } 3148 }
3137 3149
3138 3150
3139 err = syncronize(manager, this, pSyncTarget, mode ); 3151 err = syncronize(manager, this, pSyncTarget, mode );
3140 3152
3141 if (err == e_success) { 3153 if (err == e_success) {
3142 if ( manager->mWriteBackFile ){ 3154 if ( manager->mWriteBackFile ){
3143 qDebug("Saving remote PWManager file"); 3155 qDebug("Saving remote PWManager file");
3144 err = pSyncTarget->saveDoc(conf()->confGlobCompression()); 3156 err = pSyncTarget->saveDoc(conf()->confGlobCompression());
3145 if (err != e_success) { 3157 if (err != e_success) {
3146 qDebug("PwmDoc::sync: Sync failed. Error %i while storing file %s",err, filename.latin1()); 3158 qDebug("PwmDoc::sync: Sync failed. Error %i while storing file %s",err, filename.latin1());
3147 return false; 3159 return false;
3148 } 3160 }
3149 } 3161 }
3150 3162
3151 flagDirty(); 3163 flagDirty();
3152 return true; 3164 return true;
3153 } 3165 }
3154 else { 3166 else {
3155 return false; 3167 return false;
3156 } 3168 }
3157} 3169}
3158 3170
3159//called by the syncmanager to indicate that the work has to marked as dirty. 3171//called by the syncmanager to indicate that the work has to marked as dirty.
3160void PwMDoc::sync_setModified() 3172void PwMDoc::sync_setModified()
3161{ 3173{
3162 flagDirty(); 3174 flagDirty();
3163} 3175}
3164 3176
3165//called by the syncmanager to ask if the dirty flag is set. 3177//called by the syncmanager to ask if the dirty flag is set.
3166bool PwMDoc::sync_isModified() 3178bool PwMDoc::sync_isModified()
3167{ 3179{
3168 return isDirty(); 3180 return isDirty();
3169} 3181}
3170 3182
3171//called by the syncmanager to indicate that the work has to be saved. 3183//called by the syncmanager to indicate that the work has to be saved.
3172void PwMDoc::sync_save() 3184void PwMDoc::sync_save()
3173{ 3185{
3174 saveDoc(conf()->confGlobCompression()); 3186 saveDoc(conf()->confGlobCompression());
3175} 3187}
3176#endif 3188#endif
3177 3189
3178 3190
3179bool PwMDoc::findSyncData(const QString &syncname, unsigned int *index) 3191bool PwMDoc::findSyncData(const QString &syncname, unsigned int *index)
3180{ 3192{
3181 vector<PwMSyncItem>::iterator i = dti.syncDta.begin(), 3193 vector<PwMSyncItem>::iterator i = dti.syncDta.begin(),
3182 end = dti.syncDta.end(); 3194 end = dti.syncDta.end();
3183 3195
3184 while (i != end) { 3196 while (i != end) {
3185 if ((*i).syncName == syncname.latin1()) { 3197 if ((*i).syncName == syncname.latin1()) {
3186 if (index) { 3198 if (index) {
3187 *index = i - dti.syncDta.begin(); 3199 *index = i - dti.syncDta.begin();
3188 } 3200 }
3189 return true; 3201 return true;
3190 } 3202 }
3191 ++i; 3203 ++i;
3192 } 3204 }
3193 return false; 3205 return false;
3194}; 3206};
3195 3207
3196/** add new syncdataentry */ 3208/** add new syncdataentry */
3197PwMerror PwMDoc::addSyncDataEntry(PwMSyncItem *d, bool dontFlagDirty) 3209PwMerror PwMDoc::addSyncDataEntry(PwMSyncItem *d, bool dontFlagDirty)
3198{ 3210{
3199 PWM_ASSERT(d); 3211 PWM_ASSERT(d);
3200 3212
3201 if (isDeepLocked()) { 3213 if (isDeepLocked()) {
3202 PwMerror ret; 3214 PwMerror ret;
3203 ret = deepLock(false); 3215 ret = deepLock(false);
3204 if (ret != e_success) 3216 if (ret != e_success)
3205 return e_lock; 3217 return e_lock;
3206 } 3218 }
3207 unsigned int index; 3219 unsigned int index;
3208 3220
3209 const QString tmp = d->syncName.c_str(); 3221 const QString tmp = d->syncName.c_str();
3210 bool exists = findSyncData(d->syncName.c_str(), &index); 3222 bool exists = findSyncData(d->syncName.c_str(), &index);
3211 3223
3212 if (exists == true) { 3224 if (exists == true) {
3213 // DOH! We found this entry. 3225 // DOH! We found this entry.
3214 return e_entryExists; 3226 return e_entryExists;
3215 } 3227 }
3216 3228
3217 dti.syncDta.push_back(*d); 3229 dti.syncDta.push_back(*d);
3218 3230
3219 if (!dontFlagDirty) 3231 if (!dontFlagDirty)
3220 flagDirty(); 3232 flagDirty();
3221 return e_success; 3233 return e_success;
3222} 3234}
3223 3235
3224 3236
3225 3237
3226/** delete syncdata entry */ 3238/** delete syncdata entry */
3227bool PwMDoc::delSyncDataEntry(unsigned int index, bool dontFlagDirty) 3239bool PwMDoc::delSyncDataEntry(unsigned int index, bool dontFlagDirty)
3228{ 3240{
3229 if (isDeepLocked()) 3241 if (isDeepLocked())
3230 return false; 3242 return false;
3231 if (index > dti.syncDta.size() - 1) 3243 if (index > dti.syncDta.size() - 1)
3232 return false; 3244 return false;
3233 3245
3234 // delete entry 3246 // delete entry
3235 dti.syncDta.erase(dti.syncDta.begin() + index); 3247 dti.syncDta.erase(dti.syncDta.begin() + index);
3236 3248
3237 if (!dontFlagDirty) 3249 if (!dontFlagDirty)
3238 flagDirty(); 3250 flagDirty();
3239 return true; 3251 return true;
3240} 3252}
3241 3253
3242 3254
3243PwMDataItem* PwMDoc::findEntryByID(const QString &uid, unsigned int *category, unsigned int *index) 3255PwMDataItem* PwMDoc::findEntryByID(const QString &uid, unsigned int *category, unsigned int *index)
3244{ 3256{
3245 vector<PwMCategoryItem>::iterator catcounter = dti.dta.begin(), 3257 vector<PwMCategoryItem>::iterator catcounter = dti.dta.begin(),
3246 catend = dti.dta.end(); 3258 catend = dti.dta.end();
3247 3259
3248 vector<PwMDataItem>::iterator entrBegin, entrEnd, entrI; 3260 vector<PwMDataItem>::iterator entrBegin, entrEnd, entrI;
3249 3261
3250 while (catcounter != catend) { 3262 while (catcounter != catend) {
3251 entrBegin = catcounter->d.begin(); 3263 entrBegin = catcounter->d.begin();
3252 entrEnd = catcounter->d.end(); 3264 entrEnd = catcounter->d.end();
3253 entrI = entrBegin; 3265 entrI = entrBegin;
3254 while (entrI != entrEnd) { 3266 while (entrI != entrEnd) {
3255 if ((*entrI).meta.uniqueid == uid.latin1()) { 3267 if ((*entrI).meta.uniqueid == uid.latin1()) {
3256 if (category) 3268 if (category)
3257 *category = catcounter - dti.dta.begin(); 3269 *category = catcounter - dti.dta.begin();
3258 if (index) 3270 if (index)
3259 *index = entrI - entrBegin; 3271 *index = entrI - entrBegin;
3260 3272
3261 return &(*entrI); 3273 return &(*entrI);
3262 } 3274 }
3263 ++entrI; 3275 ++entrI;
3264 } 3276 }
3265 ++catcounter; 3277 ++catcounter;
3266 } 3278 }
3267 3279
3268 return 0; 3280 return 0;
3269} 3281}
3270 3282
3271QStringList PwMDoc::getIDEntryList() 3283QStringList PwMDoc::getIDEntryList()
3272{ 3284{
3273 QStringList results; 3285 QStringList results;
3274 3286
3275 vector<PwMCategoryItem>::iterator catcounter = dti.dta.begin(), 3287 vector<PwMCategoryItem>::iterator catcounter = dti.dta.begin(),
3276 catend = dti.dta.end(); 3288 catend = dti.dta.end();
3277 3289
3278 vector<PwMDataItem>::iterator entrBegin, entrEnd, entrI; 3290 vector<PwMDataItem>::iterator entrBegin, entrEnd, entrI;
3279 3291
3280 while (catcounter != catend) { 3292 while (catcounter != catend) {
3281 entrBegin = catcounter->d.begin(); 3293 entrBegin = catcounter->d.begin();
3282 entrEnd = catcounter->d.end(); 3294 entrEnd = catcounter->d.end();
3283 entrI = entrBegin; 3295 entrI = entrBegin;
3284 while (entrI != entrEnd) { 3296 while (entrI != entrEnd) {
3285 results.append( (*entrI).meta.uniqueid ); 3297 results.append( (*entrI).meta.uniqueid.c_str() );
3286 ++entrI; 3298 ++entrI;
3287 } 3299 }
3288 ++catcounter; 3300 ++catcounter;
3289 } 3301 }
3290 3302
3291 return results; 3303 return results;
3292} 3304}
3293 3305
3294 3306
3295 3307
3296 3308
3297 3309
3298#ifndef PWM_EMBEDDED 3310#ifndef PWM_EMBEDDED
3299#include "pwmdoc.moc" 3311#include "pwmdoc.moc"
3300#endif 3312#endif
diff --git a/pwmanager/pwmanager/pwmdoc.h b/pwmanager/pwmanager/pwmdoc.h
index 91277f6..ddab7f3 100644
--- a/pwmanager/pwmanager/pwmdoc.h
+++ b/pwmanager/pwmanager/pwmdoc.h
@@ -1,778 +1,806 @@
1/*************************************************************************** 1/***************************************************************************
2 * * 2 * *
3 * copyright (C) 2003, 2004 by Michael Buesch * 3 * copyright (C) 2003, 2004 by Michael Buesch *
4 * email: mbuesch@freenet.de * 4 * email: mbuesch@freenet.de *
5 * * 5 * *
6 * This program is free software; you can redistribute it and/or modify * 6 * This program is free software; you can redistribute it and/or modify *
7 * it under the terms of the GNU General Public License version 2 * 7 * it under the terms of the GNU General Public License version 2 *
8 * as published by the Free Software Foundation. * 8 * as published by the Free Software Foundation. *
9 * * 9 * *
10 ***************************************************************************/ 10 ***************************************************************************/
11 11
12/*************************************************************************** 12/***************************************************************************
13 * copyright (C) 2004 by Ulf Schenk 13 * copyright (C) 2004 by Ulf Schenk
14 * This file is originaly based on version 2.0 of pwmanager 14 * This file is originaly based on version 2.0 of pwmanager
15 * and was modified to run on embedded devices that run microkde 15 * and was modified to run on embedded devices that run microkde
16 * 16 *
17 * $Id$ 17 * $Id$
18 **************************************************************************/ 18 **************************************************************************/
19 19
20#ifndef __PWMDOC_H 20#ifndef __PWMDOC_H
21#define __PWMDOC_H 21#define __PWMDOC_H
22 22
23 #define PWM_FILE_VER (static_cast<char>(0x05)) 23 #define PWM_FILE_VER (static_cast<char>(0x05))
24 24
25 #define PWM_HASH_SHA1 (static_cast<char>(0x01)) 25 #define PWM_HASH_SHA1 (static_cast<char>(0x01))
26 #define PWM_HASH_SHA256 (static_cast<char>(0x02)) 26 #define PWM_HASH_SHA256 (static_cast<char>(0x02))
27 #define PWM_HASH_SHA384 (static_cast<char>(0x03)) 27 #define PWM_HASH_SHA384 (static_cast<char>(0x03))
28 #define PWM_HASH_SHA512 (static_cast<char>(0x04)) 28 #define PWM_HASH_SHA512 (static_cast<char>(0x04))
29 #define PWM_HASH_MD5 (static_cast<char>(0x05)) 29 #define PWM_HASH_MD5 (static_cast<char>(0x05))
30 #define PWM_HASH_RMD160 (static_cast<char>(0x06)) 30 #define PWM_HASH_RMD160 (static_cast<char>(0x06))
31 #define PWM_HASH_TIGER (static_cast<char>(0x07)) 31 #define PWM_HASH_TIGER (static_cast<char>(0x07))
32 32
33 #define PWM_CRYPT_BLOWFISH(static_cast<char>(0x01)) 33 #define PWM_CRYPT_BLOWFISH(static_cast<char>(0x01))
34 #define PWM_CRYPT_AES128(static_cast<char>(0x02)) 34 #define PWM_CRYPT_AES128(static_cast<char>(0x02))
35 #define PWM_CRYPT_AES192(static_cast<char>(0x03)) 35 #define PWM_CRYPT_AES192(static_cast<char>(0x03))
36 #define PWM_CRYPT_AES256(static_cast<char>(0x04)) 36 #define PWM_CRYPT_AES256(static_cast<char>(0x04))
37 #define PWM_CRYPT_3DES (static_cast<char>(0x05)) 37 #define PWM_CRYPT_3DES (static_cast<char>(0x05))
38 #define PWM_CRYPT_TWOFISH(static_cast<char>(0x06)) 38 #define PWM_CRYPT_TWOFISH(static_cast<char>(0x06))
39 #define PWM_CRYPT_TWOFISH128(static_cast<char>(0x07)) 39 #define PWM_CRYPT_TWOFISH128(static_cast<char>(0x07))
40 40
41 #define PWM_COMPRESS_NONE(static_cast<char>(0x00)) 41 #define PWM_COMPRESS_NONE(static_cast<char>(0x00))
42 #define PWM_COMPRESS_GZIP(static_cast<char>(0x01)) 42 #define PWM_COMPRESS_GZIP(static_cast<char>(0x01))
43 #define PWM_COMPRESS_BZIP2(static_cast<char>(0x02)) 43 #define PWM_COMPRESS_BZIP2(static_cast<char>(0x02))
44 44
45 #define DEFAULT_MAX_ENTRIES(~(static_cast<unsigned int>(0))) 45 #define DEFAULT_MAX_ENTRIES(~(static_cast<unsigned int>(0)))
46 #define FILE_ID_HEADER "PWM_PASSWORD_FILE" 46 #define FILE_ID_HEADER "PWM_PASSWORD_FILE"
47 47
48 48
49#include "pwmexception.h" 49#include "pwmexception.h"
50#include "pwmdocui.h" 50#include "pwmdocui.h"
51 51
52#include <qobject.h> 52#include <qobject.h>
53#include <qtimer.h> 53#include <qtimer.h>
54#include <qdatetime.h> 54#include <qdatetime.h>
55 55
56#include <kprocess.h> 56#include <kprocess.h>
57 57
58#ifndef PWM_EMBEDDED 58#ifndef PWM_EMBEDDED
59#include "configuration.h" 59#include "configuration.h"
60#else 60#else
61#include <kapplication.h> 61#include <kapplication.h>
62#include <ksyncmanager.h> 62#include <ksyncmanager.h>
63#endif 63#endif
64 64
65#include <string> 65#include <string>
66#include <vector> 66#include <vector>
67#include <utility> 67#include <utility>
68 68
69using std::vector; 69using std::vector;
70using std::string; 70using std::string;
71using std::pair; 71using std::pair;
72 72
73/* used in findEntry() function */ 73/* used in findEntry() function */
74 #define SEARCH_IN_DESC (1) 74 #define SEARCH_IN_DESC (1)
75 #define SEARCH_IN_NAME (1 << 1) 75 #define SEARCH_IN_NAME (1 << 1)
76 #define SEARCH_IN_PW (1 << 2) 76 #define SEARCH_IN_PW (1 << 2)
77 #define SEARCH_IN_COMMENT(1 << 3) 77 #define SEARCH_IN_COMMENT(1 << 3)
78 #define SEARCH_IN_URL (1 << 4) 78 #define SEARCH_IN_URL (1 << 4)
79 #define SEARCH_IN_LAUNCHER(1 << 5) 79 #define SEARCH_IN_LAUNCHER(1 << 5)
80 #define SEARCH_IN_ALL (SEARCH_IN_DESC | SEARCH_IN_NAME| \ 80 #define SEARCH_IN_ALL (SEARCH_IN_DESC | SEARCH_IN_NAME| \
81 SEARCH_IN_PW | SEARCH_IN_COMMENT| \ 81 SEARCH_IN_PW | SEARCH_IN_COMMENT| \
82 SEARCH_IN_URL| SEARCH_IN_LAUNCHER) 82 SEARCH_IN_URL| SEARCH_IN_LAUNCHER)
83 83
84/** document deeplocked. Data is out for lunch to disk */ 84/** document deeplocked. Data is out for lunch to disk */
85 #define DOC_STAT_DEEPLOCKED (1) 85 #define DOC_STAT_DEEPLOCKED (1)
86/** encrypted document on disk is dirty. data has to go to disk. */ 86/** encrypted document on disk is dirty. data has to go to disk. */
87 #define DOC_STAT_DISK_DIRTY (1 << 1) 87 #define DOC_STAT_DISK_DIRTY (1 << 1)
88/** we are using a chipcard to encrypt the data */ 88/** we are using a chipcard to encrypt the data */
89 #define DOC_STAT_USE_CHIPCARD (1 << 2) 89 #define DOC_STAT_USE_CHIPCARD (1 << 2)
90/** use "currentPw" to unlock. (This flag is set/unset by a timer) */ 90/** use "currentPw" to unlock. (This flag is set/unset by a timer) */
91 #define DOC_STAT_UNLOCK_WITHOUT_PW(1 << 3) 91 #define DOC_STAT_UNLOCK_WITHOUT_PW(1 << 3)
92 92
93class PwMDoc; 93class PwMDoc;
94class PwMView; 94class PwMView;
95class QFile; 95class QFile;
96 96
97/* meta data for a PwMDataItem */ 97/* meta data for a PwMDataItem */
98struct PwMMetaData 98struct PwMMetaData
99{ 99{
100 PwMMetaData() 100 PwMMetaData()
101 : updateInt (0) 101 : updateInt (0)
102 { } 102 { }
103 /** creation date of the PwMDataItem to which 103 /** creation date of the PwMDataItem to which
104 * this meta data belongs. 104 * this meta data belongs.
105 */ 105 */
106 QDateTimecreate; 106 QDateTimecreate;
107 /** becomes valid on this date */ 107 /** becomes valid on this date */
108 QDateTimevalid; 108 QDateTimevalid;
109 /** expire date */ 109 /** expire date */
110 QDateTimeexpire; 110 QDateTimeexpire;
111 /** update date (last updated at this date) */ 111 /** update date (last updated at this date) */
112 QDateTimeupdate; 112 QDateTimeupdate;
113 /** update interval (in minutes). Time since the 113 /** update interval (in minutes). Time since the
114 * last update to remind the user to update the item. 114 * last update to remind the user to update the item.
115 * 0 disables. 115 * 0 disables.
116 */ 116 */
117 unsigned long updateInt; 117 unsigned long updateInt;
118 118
119 //US ENH: enhancements of the filestructure 119 //US ENH: enhancements of the filestructure
120 /* each entry gets a unique id assigned */ 120 /* each entry gets a unique id assigned */
121 QString uniqueid; 121 string uniqueid;
122 122
123 123
124 void clear() 124 void clear()
125 { 125 {
126 create = QDateTime(); 126 create = QDateTime();
127 expire = QDateTime(); 127 expire = QDateTime();
128 update = QDateTime(); 128 update = QDateTime();
129 updateInt = 0; 129 updateInt = 0;
130 uniqueid = KApplication::randomString(8); 130 uniqueid = KApplication::randomString(8);
131 } 131 }
132
133 PwMMetaData& operator = (const PwMMetaData& x)
134 {
135 create = x.create;
136 expire = x.expire;
137 update = x.update;
138 updateInt = x.updateInt;
139 uniqueid = x.uniqueid;
140 return *this;
141 }
142
132 inline bool isValid() const 143 inline bool isValid() const
133 { 144 {
134 if (valid.isNull()) 145 if (valid.isNull())
135 return true; 146 return true;
136 return (valid < QDateTime::currentDateTime()); 147 return (valid < QDateTime::currentDateTime());
137 } 148 }
138 inline bool isExpired() const 149 inline bool isExpired() const
139 { 150 {
140 if (expire.isNull()) 151 if (expire.isNull())
141 return false; 152 return false;
142 return (expire < QDateTime::currentDateTime()); 153 return (expire < QDateTime::currentDateTime());
143 } 154 }
144 inline bool isUpdateIntOver() const 155 inline bool isUpdateIntOver() const
145 { 156 {
146 if (updateInt == 0 || 157 if (updateInt == 0 ||
147 update.isNull()) 158 update.isNull())
148 return false; 159 return false;
149 QDateTime d(update); 160 QDateTime d(update);
150 return (d.addSecs(updateInt * 60) < QDateTime::currentDateTime()); 161 return (d.addSecs(updateInt * 60) < QDateTime::currentDateTime());
151 } 162 }
152}; 163};
153 164
154struct PwMDataItem 165struct PwMDataItem
155{ 166{
156 PwMDataItem() 167 PwMDataItem()
157 : lockStat (true) 168 : lockStat (true)
158 , listViewPos (-1) 169 , listViewPos (-1)
159 , binary (false) 170 , binary (false)
160 , rev (0) 171 , rev (0)
161 { } 172 { }
162 173
163 /** password description */ 174 /** password description */
164 stringdesc; 175 stringdesc;
165 /** user-name */ 176 /** user-name */
166 stringname; 177 stringname;
167 /** the password itself */ 178 /** the password itself */
168 stringpw; 179 stringpw;
169 /** some comment */ 180 /** some comment */
170 stringcomment; 181 stringcomment;
171 /** an URL string */ 182 /** an URL string */
172 stringurl; 183 stringurl;
173 /** launcher. Can be executed as a system() command */ 184 /** launcher. Can be executed as a system() command */
174 stringlauncher; 185 stringlauncher;
175 /** locking status. If locked (true), pw is not emitted through getEntry() */ 186 /** locking status. If locked (true), pw is not emitted through getEntry() */
176 boollockStat; 187 boollockStat;
177 /** position of this item in main "list-view" 188 /** position of this item in main "list-view"
178 * If -1, the position is not yet specified and should be appended to the list 189 * If -1, the position is not yet specified and should be appended to the list
179 */ 190 */
180 intlistViewPos; 191 intlistViewPos;
181 /** does this entry contain binary data? */ 192 /** does this entry contain binary data? */
182 bool binary; 193 bool binary;
183 /** meta data for this data item. */ 194 /** meta data for this data item. */
184 PwMMetaData meta; 195 PwMMetaData meta;
185 /** data revision counter. This counter can be used 196 /** data revision counter. This counter can be used
186 * to easily, efficiently determine if this data item 197 * to easily, efficiently determine if this data item
187 * has changed since some time. 198 * has changed since some time.
188 * This counter is incremented on every update. 199 * This counter is incremented on every update.
189 */ 200 */
190 unsigned int rev; 201 unsigned int rev;
191 202
192 void clear(bool clearMeta = true) 203 void clear(bool clearMeta = true)
193 { 204 {
194 /* NOTE: Don't use .clear() here to be 205 /* NOTE: Don't use .clear() here to be
195 * backward compatible with gcc-2 (Debian Woody) 206 * backward compatible with gcc-2 (Debian Woody)
196 */ 207 */
197 desc = ""; 208 desc = "";
198 name = ""; 209 name = "";
199 pw = ""; 210 pw = "";
200 comment = ""; 211 comment = "";
201 url = ""; 212 url = "";
202 launcher = ""; 213 launcher = "";
203 lockStat = true; 214 lockStat = true;
204 listViewPos = -1; 215 listViewPos = -1;
205 binary = false; 216 binary = false;
206 if (clearMeta) 217 if (clearMeta)
207 meta.clear(); 218 meta.clear();
208 } 219 }
220
221 PwMDataItem& operator = (const PwMDataItem& x)
222 {
223 qDebug("oper=%s", x.desc.c_str());
224 desc = x.desc;
225 name = x.name;
226 pw = x.pw;
227 comment = x.comment;
228 url = x.url;
229 launcher = x.launcher;
230 lockStat = x.lockStat;
231 listViewPos = x.listViewPos;
232 binary = x.binary;
233 meta = x.meta;
234 rev = x.rev;
235 return *this;
236 }
209 237
210}; 238};
211 239
212struct PwMCategoryItem 240struct PwMCategoryItem
213{ 241{
214 /** all PwMDataItems (all passwords) within this category */ 242 /** all PwMDataItems (all passwords) within this category */
215 vector<PwMDataItem>d; 243 vector<PwMDataItem>d;
216 /** category name/description */ 244 /** category name/description */
217 string name; 245 string name;
218 246
219 void clear() 247 void clear()
220 { 248 {
221 d.clear(); 249 d.clear();
222 name = ""; 250 name = "";
223 } 251 }
224}; 252};
225 253
226struct PwMSyncItem 254struct PwMSyncItem
227{ 255{
228 string syncName; 256 string syncName;
229 QDateTime lastSyncDate; 257 QDateTime lastSyncDate;
230 258
231 void clear() 259 void clear()
232 { 260 {
233 lastSyncDate = QDateTime(); 261 lastSyncDate = QDateTime();
234 syncName = ""; 262 syncName = "";
235 } 263 }
236}; 264};
237 265
238struct PwMItem 266struct PwMItem
239{ 267{
240 vector<PwMCategoryItem> dta; 268 vector<PwMCategoryItem> dta;
241 vector<PwMSyncItem> syncDta; 269 vector<PwMSyncItem> syncDta;
242 270
243 void clear() 271 void clear()
244 { 272 {
245 dta.clear(); 273 dta.clear();
246 syncDta.clear(); 274 syncDta.clear();
247 } 275 }
248}; 276};
249 277
250 278
251/** "Function Object" for sort()ing PwMDataItem::listViewPos */ 279/** "Function Object" for sort()ing PwMDataItem::listViewPos */
252class dta_lvp_greater 280class dta_lvp_greater
253{ 281{
254public: 282public:
255 bool operator() (const pair<unsigned int, unsigned int> &d1, 283 bool operator() (const pair<unsigned int, unsigned int> &d1,
256 const pair<unsigned int, unsigned int> &d2) 284 const pair<unsigned int, unsigned int> &d2)
257 { 285 {
258 return d1.second > d2.second; 286 return d1.second > d2.second;
259 } 287 }
260}; 288};
261 289
262/** list of PwMDoc documents and it's IDs */ 290/** list of PwMDoc documents and it's IDs */
263class PwMDocList 291class PwMDocList
264{ 292{
265public: 293public:
266 struct listItem 294 struct listItem
267 { 295 {
268 /** document filename (known as ID, here) */ 296 /** document filename (known as ID, here) */
269 string docId; 297 string docId;
270 /** pointer to the document class */ 298 /** pointer to the document class */
271 PwMDoc *doc; 299 PwMDoc *doc;
272 }; 300 };
273 301
274 PwMDocList() {} 302 PwMDocList() {}
275 303
276 /** add a new item to the list */ 304 /** add a new item to the list */
277 void add(PwMDoc *doc, const string &id); 305 void add(PwMDoc *doc, const string &id);
278 /** changes the contents of an existing item */ 306 /** changes the contents of an existing item */
279 void edit(PwMDoc *doc, const string &newId); 307 void edit(PwMDoc *doc, const string &newId);
280 /** remove the given item */ 308 /** remove the given item */
281 void del(PwMDoc *doc); 309 void del(PwMDoc *doc);
282 /** get the item at index */ 310 /** get the item at index */
283 listItem getAt(int index) 311 listItem getAt(int index)
284 { return docList[index]; } 312 { return docList[index]; }
285 /** find an entry with this id */ 313 /** find an entry with this id */
286 bool find(const string &id, listItem *ret = 0); 314 bool find(const string &id, listItem *ret = 0);
287 /** returns a copy of the list */ 315 /** returns a copy of the list */
288 const vector<listItem>* getList() const 316 const vector<listItem>* getList() const
289 { return &docList; } 317 { return &docList; }
290 318
291 319
292 /** returns a new unique number to extend the name of 320 /** returns a new unique number to extend the name of
293 * an unnamed document. 321 * an unnamed document.
294 */ 322 */
295 static unsigned int getNewUnnamedNumber() 323 static unsigned int getNewUnnamedNumber()
296 { return unnamedDocCnt++; } 324 { return unnamedDocCnt++; }
297 325
298protected: 326protected:
299 /* Hm, I think we shouldn't really use a "list" here, should we? 327 /* Hm, I think we shouldn't really use a "list" here, should we?
300 * So I decided to actually use a vector. 328 * So I decided to actually use a vector.
301 */ 329 */
302 vector<listItem> docList; 330 vector<listItem> docList;
303 /** This value is used to get a new number for yet unnamed 331 /** This value is used to get a new number for yet unnamed
304 * documents. It is incremented on every request. So it's 332 * documents. It is incremented on every request. So it's
305 * theoretically possible to overflow it, but... :) 333 * theoretically possible to overflow it, but... :)
306 */ 334 */
307 static unsigned int unnamedDocCnt; 335 static unsigned int unnamedDocCnt;
308}; 336};
309 337
310/** implements timers for the document */ 338/** implements timers for the document */
311class DocTimer : public QObject 339class DocTimer : public QObject
312{ 340{
313 Q_OBJECT 341 Q_OBJECT
314public: 342public:
315 enum TimerIDs 343 enum TimerIDs
316 { 344 {
317 id_mpwTimer, 345 id_mpwTimer,
318 id_autoLockTimer, 346 id_autoLockTimer,
319 id_metaCheckTimer 347 id_metaCheckTimer
320 }; 348 };
321 349
322public: 350public:
323 DocTimer(PwMDoc *_doc); 351 DocTimer(PwMDoc *_doc);
324 ~DocTimer(); 352 ~DocTimer();
325 353
326 /** start the timer */ 354 /** start the timer */
327 void start(TimerIDs timer); 355 void start(TimerIDs timer);
328 /** stop the timer */ 356 /** stop the timer */
329 void stop(TimerIDs timer); 357 void stop(TimerIDs timer);
330 /** get the lock for a timer. 358 /** get the lock for a timer.
331 * This lock is a recursive lock. When a lock is 359 * This lock is a recursive lock. When a lock is
332 * held, the timer will be stopped and timeout is 360 * held, the timer will be stopped and timeout is
333 * guaranteed to not happen 361 * guaranteed to not happen
334 */ 362 */
335 void getLock(TimerIDs timer); 363 void getLock(TimerIDs timer);
336 /** put a recursive timer lock */ 364 /** put a recursive timer lock */
337 void putLock(TimerIDs timer); 365 void putLock(TimerIDs timer);
338 366
339protected slots: 367protected slots:
340 /** timeout slot for the mpw timer */ 368 /** timeout slot for the mpw timer */
341 void mpwTimeout(); 369 void mpwTimeout();
342 /** timeout slot for the autoLock timer */ 370 /** timeout slot for the autoLock timer */
343 void autoLockTimeout(); 371 void autoLockTimeout();
344 /** timeout slot for the metaCheck timer */ 372 /** timeout slot for the metaCheck timer */
345 void metaCheckTimeout(); 373 void metaCheckTimeout();
346 374
347protected: 375protected:
348 /** pointer to the document associated with this timer. */ 376 /** pointer to the document associated with this timer. */
349 PwMDoc *doc; 377 PwMDoc *doc;
350 /** timer object for mpw timer */ 378 /** timer object for mpw timer */
351 QTimer *mpwTimer; 379 QTimer *mpwTimer;
352 /** timer object for the autoLock timer */ 380 /** timer object for the autoLock timer */
353 QTimer *autoLockTimer; 381 QTimer *autoLockTimer;
354 /** timer object for the metaCheck timer */ 382 /** timer object for the metaCheck timer */
355 QTimer *metaCheckTimer; 383 QTimer *metaCheckTimer;
356 /** lock counter for the mpw timer */ 384 /** lock counter for the mpw timer */
357 unsigned int mpwLock; 385 unsigned int mpwLock;
358 /** lock counter for the autoLock timer */ 386 /** lock counter for the autoLock timer */
359 unsigned int autoLockLock; 387 unsigned int autoLockLock;
360 /** lock counter for the metaCheck timer */ 388 /** lock counter for the metaCheck timer */
361 unsigned int metaCheckLock; 389 unsigned int metaCheckLock;
362}; 390};
363 391
364/** Document class for PwM */ 392/** Document class for PwM */
365//US ENH: derived from KSyncInterfaces, to get called by PwM when a sync is required. 393//US ENH: derived from KSyncInterfaces, to get called by PwM when a sync is required.
366// But PwMDoc is handling the sync by itself. 394// But PwMDoc is handling the sync by itself.
367class PwMDoc : public PwMDocUi, public KSyncInterface 395class PwMDoc : public PwMDocUi, public KSyncInterface
368 396
369{ 397{
370 Q_OBJECT 398 Q_OBJECT
371 friend class DocTimer; 399 friend class DocTimer;
372 400
373public: 401public:
374 /** construtor */ 402 /** construtor */
375 PwMDoc(QObject* parent = 0, const char *name = 0); 403 PwMDoc(QObject* parent = 0, const char *name = 0);
376 /** destructor */ 404 /** destructor */
377 ~PwMDoc(); 405 ~PwMDoc();
378 406
379 /** returns a pointer to a list of all open documents */ 407 /** returns a pointer to a list of all open documents */
380 static PwMDocList* getOpenDocList() 408 static PwMDocList* getOpenDocList()
381 { return &openDocList; } 409 { return &openDocList; }
382 410
383 /** flag document dirty. dta changed */ 411 /** flag document dirty. dta changed */
384 void flagDirty() 412 void flagDirty()
385 { 413 {
386 setDocStatFlag(DOC_STAT_DISK_DIRTY); 414 setDocStatFlag(DOC_STAT_DISK_DIRTY);
387 emitDataChanged(this); 415 emitDataChanged(this);
388 } 416 }
389 /** modified? */ 417 /** modified? */
390 bool isDirty() 418 bool isDirty()
391 { return getDocStatFlag(DOC_STAT_DISK_DIRTY); } 419 { return getDocStatFlag(DOC_STAT_DISK_DIRTY); }
392 /** save document to disk */ 420 /** save document to disk */
393 PwMerror saveDoc(char compress, const QString *file = 0); 421 PwMerror saveDoc(char compress, const QString *file = 0);
394 /** read document from file. 422 /** read document from file.
395 * "openLocked is must be set to either of these values: 423 * "openLocked is must be set to either of these values:
396 * 0 == open with all entries unlocked 424 * 0 == open with all entries unlocked
397 * 1 == open with all entries locked 425 * 1 == open with all entries locked
398 * 2 == open deep-locked 426 * 2 == open deep-locked
399 */ 427 */
400 PwMerror openDoc(const QString *file, int openLocked); 428 PwMerror openDoc(const QString *file, int openLocked);
401 /** export document to ascii-textfile */ 429 /** export document to ascii-textfile */
402 PwMerror exportToText(const QString *file); 430 PwMerror exportToText(const QString *file);
403 /** export document to gpasman / kpasman file */ 431 /** export document to gpasman / kpasman file */
404 PwMerror exportToGpasman(const QString *file); 432 PwMerror exportToGpasman(const QString *file);
405 /** import document from ascii-textfile */ 433 /** import document from ascii-textfile */
406 PwMerror importFromText(const QString *file, int format = -1); 434 PwMerror importFromText(const QString *file, int format = -1);
407 /** import document from gpasman / kpasman file */ 435 /** import document from gpasman / kpasman file */
408 PwMerror importFromGpasman(const QString *file); 436 PwMerror importFromGpasman(const QString *file);
409 /** add new entry */ 437 /** add new entry */
410 PwMerror addEntry(const QString &category, PwMDataItem *d, 438 PwMerror addEntry(const QString &category, PwMDataItem *d,
411 bool dontFlagDirty = false, bool updateMeta = true); 439 bool dontFlagDirty = false, bool updateMeta = true);
412 /** add new category. This function doesn't flag the document dirty! */ 440 /** add new category. This function doesn't flag the document dirty! */
413 PwMerror addCategory(const QString &category, unsigned int *categoryIndex, 441 PwMerror addCategory(const QString &category, unsigned int *categoryIndex,
414 bool checkIfExist = true); 442 bool checkIfExist = true);
415 /** rename an existing category */ 443 /** rename an existing category */
416 bool renameCategory(const QString &category, const QString &newName); 444 bool renameCategory(const QString &category, const QString &newName);
417 /** rename an existing category */ 445 /** rename an existing category */
418 bool renameCategory(unsigned int category, const QString &newName, 446 bool renameCategory(unsigned int category, const QString &newName,
419 bool dontFlagDirty = false); 447 bool dontFlagDirty = false);
420 /** delete an existing category */ 448 /** delete an existing category */
421 bool delCategory(const QString &category); 449 bool delCategory(const QString &category);
422 /** delete an existing category */ 450 /** delete an existing category */
423 bool delCategory(unsigned int category, bool dontFlagDirty = false); 451 bool delCategory(unsigned int category, bool dontFlagDirty = false);
424 /** returns a list of all category-names */ 452 /** returns a list of all category-names */
425 void getCategoryList(vector<string> *list); 453 void getCategoryList(vector<string> *list);
426 /** returns a list of all category-names */ 454 /** returns a list of all category-names */
427 void getCategoryList(QStringList *list); 455 void getCategoryList(QStringList *list);
428 /** returns a list of all entry-descs in the given category */ 456 /** returns a list of all entry-descs in the given category */
429 void getEntryList(const QString &category, QStringList *list); 457 void getEntryList(const QString &category, QStringList *list);
430 /** returns a list of all entry-descs in the given category */ 458 /** returns a list of all entry-descs in the given category */
431 void getEntryList(const QString &category, vector<string> *list); 459 void getEntryList(const QString &category, vector<string> *list);
432 /** returns a list of all entry-descs in the given category */ 460 /** returns a list of all entry-descs in the given category */
433 void getEntryList(unsigned int category, vector<string> *list); 461 void getEntryList(unsigned int category, vector<string> *list);
434 /** returns a list of all entry-descs in the given category */ 462 /** returns a list of all entry-descs in the given category */
435 void getEntryList(unsigned int category, QStringList *list); 463 void getEntryList(unsigned int category, QStringList *list);
436 /** delete entry */ 464 /** delete entry */
437 bool delEntry(const QString &category, unsigned int index, bool dontFlagDirty = false); 465 bool delEntry(const QString &category, unsigned int index, bool dontFlagDirty = false);
438 /** delete entry */ 466 /** delete entry */
439 bool delEntry(unsigned int category, unsigned int index, bool dontFlagDirty = false); 467 bool delEntry(unsigned int category, unsigned int index, bool dontFlagDirty = false);
440 /** edit entry */ 468 /** edit entry */
441 bool editEntry(const QString &oldCategory, const QString &newCategory, 469 bool editEntry(const QString &oldCategory, const QString &newCategory,
442 unsigned int index, PwMDataItem *d, bool updateMeta = true); 470 unsigned int index, PwMDataItem *d, bool updateMeta = true);
443 /** edit entry */ 471 /** edit entry */
444 bool editEntry(unsigned int oldCategory, const QString &newCategory, 472 bool editEntry(unsigned int oldCategory, const QString &newCategory,
445 unsigned int index, PwMDataItem *d, bool updateMeta = true); 473 unsigned int index, PwMDataItem *d, bool updateMeta = true);
446 /** finds the category with the "name" and return it's index */ 474 /** finds the category with the "name" and return it's index */
447 bool findCategory(const QString &name, unsigned int *index); 475 bool findCategory(const QString &name, unsigned int *index);
448 /** search for an entry "find" and check while searching only for 476 /** search for an entry "find" and check while searching only for
449 * the data-fields specified by "searchIn". To set the "searchIn" 477 * the data-fields specified by "searchIn". To set the "searchIn"
450 * value, we may use one or more of the SEARCH_IN_* defines at 478 * value, we may use one or more of the SEARCH_IN_* defines at
451 * the top of this header-file. It returns the positions of all 479 * the top of this header-file. It returns the positions of all
452 * matched entries in "foundPositions". If "breakAfterFound" is true, 480 * matched entries in "foundPositions". If "breakAfterFound" is true,
453 * the function terminates after the first occurence of the entry 481 * the function terminates after the first occurence of the entry
454 * and doesn't go on searching. So foundPositions->size() is never 482 * and doesn't go on searching. So foundPositions->size() is never
455 * > 1 if breakAfterFound is true. 483 * > 1 if breakAfterFound is true.
456 */ 484 */
457 void findEntry(unsigned int category, PwMDataItem find, unsigned int searchIn, 485 void findEntry(unsigned int category, PwMDataItem find, unsigned int searchIn,
458 vector<unsigned int> *foundPositions, bool breakAfterFound = false, 486 vector<unsigned int> *foundPositions, bool breakAfterFound = false,
459 bool caseSensitive = true, bool exactWordMatch = true, 487 bool caseSensitive = true, bool exactWordMatch = true,
460 bool sortByLvp = false); 488 bool sortByLvp = false);
461 /** see the above funtion. This function allows to set the category by name. */ 489 /** see the above funtion. This function allows to set the category by name. */
462 void findEntry(const QString &category, PwMDataItem find, unsigned int searchIn, 490 void findEntry(const QString &category, PwMDataItem find, unsigned int searchIn,
463 vector<unsigned int> *foundPositions, bool breakAfterFound = false, 491 vector<unsigned int> *foundPositions, bool breakAfterFound = false,
464 bool caseSensitive = true, bool exactWordMatch = true, 492 bool caseSensitive = true, bool exactWordMatch = true,
465 bool sortByLvp = false); 493 bool sortByLvp = false);
466 /** returns number of entries */ 494 /** returns number of entries */
467 unsigned int numEntries(const QString &category); 495 unsigned int numEntries(const QString &category);
468 unsigned int numEntries(unsigned int category) 496 unsigned int numEntries(unsigned int category)
469 { return dti.dta[category].d.size(); } 497 { return dti.dta[category].d.size(); }
470 /** returns number of categories */ 498 /** returns number of categories */
471 unsigned int numCategories() 499 unsigned int numCategories()
472 { return dti.dta.size(); } 500 { return dti.dta.size(); }
473 /** returns the name of the category at "index" */ 501 /** returns the name of the category at "index" */
474 const string* getCategory(unsigned int index) 502 const string* getCategory(unsigned int index)
475 { return (&(dti.dta[index].name)); } 503 { return (&(dti.dta[index].name)); }
476 504
477 /** returns the data of item at "index". 505 /** returns the data of item at "index".
478 * It unlocks the entry if it's locked and unlockIfLocked is true. 506 * It unlocks the entry if it's locked and unlockIfLocked is true.
479 * If the entry is locked, but unlockIfLocked is false, it'll not return 507 * If the entry is locked, but unlockIfLocked is false, it'll not return
480 * the pw. 508 * the pw.
481 */ 509 */
482 bool getEntry(const QString &category, unsigned int index, 510 bool getEntry(const QString &category, unsigned int index,
483 PwMDataItem *d, bool unlockIfLocked = false); 511 PwMDataItem *d, bool unlockIfLocked = false);
484 bool getEntry(unsigned int category, unsigned int index, 512 bool getEntry(unsigned int category, unsigned int index,
485 PwMDataItem *d, bool unlockIfLocked = false); 513 PwMDataItem *d, bool unlockIfLocked = false);
486 /** returns the comment-string by looking at the category 514 /** returns the comment-string by looking at the category
487 * and the listViewPos 515 * and the listViewPos
488 */ 516 */
489 PwMerror getCommentByLvp(const QString &category, int listViewPos, 517 PwMerror getCommentByLvp(const QString &category, int listViewPos,
490 string *foundComment); 518 string *foundComment);
491 /** checks if a password is already available. (currentPw) */ 519 /** checks if a password is already available. (currentPw) */
492 bool isPwAvailable() 520 bool isPwAvailable()
493 { return (currentPw != ""); } 521 { return (currentPw != ""); }
494 /** un/lock entry at "index". If needed, ask for password. */ 522 /** un/lock entry at "index". If needed, ask for password. */
495 bool lockAt(const QString &category, unsigned int index, 523 bool lockAt(const QString &category, unsigned int index,
496 bool lock = true); 524 bool lock = true);
497 bool lockAt(unsigned int category, unsigned int index, 525 bool lockAt(unsigned int category, unsigned int index,
498 bool lock = true); 526 bool lock = true);
499 /** returns the lock-status at "index" */ 527 /** returns the lock-status at "index" */
500 bool isLocked(const QString &category, unsigned int index); 528 bool isLocked(const QString &category, unsigned int index);
501 bool isLocked(unsigned int category, unsigned int index) 529 bool isLocked(unsigned int category, unsigned int index)
502 { return dti.dta[category].d[index].lockStat; } 530 { return dti.dta[category].d[index].lockStat; }
503 /** returns the deeplock status */ 531 /** returns the deeplock status */
504 bool isDeepLocked() 532 bool isDeepLocked()
505 { return getDocStatFlag(DOC_STAT_DEEPLOCKED); } 533 { return getDocStatFlag(DOC_STAT_DEEPLOCKED); }
506 /** (un)lock all entries */ 534 /** (un)lock all entries */
507 bool lockAll(bool lock); 535 bool lockAll(bool lock);
508 /** unlocks all entries tempoarly. 536 /** unlocks all entries tempoarly.
509 * 1st NOTE: Be very careful with this function! :) 537 * 1st NOTE: Be very careful with this function! :)
510 * 2nd NOTE: After you have called unlockAll_Tempoary(); , 538 * 2nd NOTE: After you have called unlockAll_Tempoary(); ,
511 * please DON'T forget to call unlockAll_Tempoary(true); 539 * please DON'T forget to call unlockAll_Tempoary(true);
512 * _before_ the user (or someone else) is able to change 540 * _before_ the user (or someone else) is able to change
513 * the document! 541 * the document!
514 * 3rd NOTE: Please DON'T change "dta" while the data is tempoary 542 * 3rd NOTE: Please DON'T change "dta" while the data is tempoary
515 * unlocked! This will cause corruption. 543 * unlocked! This will cause corruption.
516 */ 544 */
517 bool unlockAll_tempoary(bool revert = false); 545 bool unlockAll_tempoary(bool revert = false);
518 /** deep-(un)locks the document. 546 /** deep-(un)locks the document.
519 * deep-locking writes all data to the file, deletes all data 547 * deep-locking writes all data to the file, deletes all data
520 * in memory, but doesn't close the document. 548 * in memory, but doesn't close the document.
521 * deep-locking is only available, if the user previously saved 549 * deep-locking is only available, if the user previously saved
522 * the doc to a file (with a password). 550 * the doc to a file (with a password).
523 * If "saveToFile" is false, it does NOT write the data to the file! 551 * If "saveToFile" is false, it does NOT write the data to the file!
524 */ 552 */
525 PwMerror deepLock(bool lock = true, bool saveToFile = true); 553 PwMerror deepLock(bool lock = true, bool saveToFile = true);
526 /** is unlockable without pw? */ 554 /** is unlockable without pw? */
527 bool unlockWoPw() 555 bool unlockWoPw()
528 { return getDocStatFlag(DOC_STAT_UNLOCK_WITHOUT_PW); } 556 { return getDocStatFlag(DOC_STAT_UNLOCK_WITHOUT_PW); }
529 /** get the "currentPassword" */ 557 /** get the "currentPassword" */
530 const QString& getCurrentPw() 558 const QString& getCurrentPw()
531 { return currentPw; } 559 { return currentPw; }
532 /** open a window and request the user to change the mpw */ 560 /** open a window and request the user to change the mpw */
533 void changeCurrentPw(); 561 void changeCurrentPw();
534 /** set the "listViewPos" variable of "dta" */ 562 /** set the "listViewPos" variable of "dta" */
535 void setListViewPos(const QString &category, unsigned int index, 563 void setListViewPos(const QString &category, unsigned int index,
536 int pos); 564 int pos);
537 /** set the "listViewPos" variable of "dta" */ 565 /** set the "listViewPos" variable of "dta" */
538 void setListViewPos(unsigned int category, unsigned int index, 566 void setListViewPos(unsigned int category, unsigned int index,
539 int pos); 567 int pos);
540 /** get the "listViewPos" variable of "dta" */ 568 /** get the "listViewPos" variable of "dta" */
541 int getListViewPos(const QString &category, unsigned int index); 569 int getListViewPos(const QString &category, unsigned int index);
542 /** set the maximum number of entries allowed */ 570 /** set the maximum number of entries allowed */
543 void setMaxNumEntries(unsigned int num = DEFAULT_MAX_ENTRIES) 571 void setMaxNumEntries(unsigned int num = DEFAULT_MAX_ENTRIES)
544 { maxEntries = num; } 572 { maxEntries = num; }
545 /** get the maximum number of entries allowed */ 573 /** get the maximum number of entries allowed */
546 unsigned int getMaxNumEntries() 574 unsigned int getMaxNumEntries()
547 { return maxEntries; } 575 { return maxEntries; }
548 /** ensure all listViewPos of all dta items are set. (are ! -1). 576 /** ensure all listViewPos of all dta items are set. (are ! -1).
549 * If there are some undefined entries, add them to the end of 577 * If there are some undefined entries, add them to the end of
550 * the listViewPos(itions). */ 578 * the listViewPos(itions). */
551 void ensureLvp(); 579 void ensureLvp();
552 /** execute the "launcher" of this entry */ 580 /** execute the "launcher" of this entry */
553 bool execLauncher(const QString &category, unsigned int entryIndex); 581 bool execLauncher(const QString &category, unsigned int entryIndex);
554 /** see above */ 582 /** see above */
555 bool execLauncher(unsigned int category, unsigned int entryIndex); 583 bool execLauncher(unsigned int category, unsigned int entryIndex);
556 /** open a browser with the URL-section of the given entry */ 584 /** open a browser with the URL-section of the given entry */
557 bool goToURL(const QString &category, unsigned int entryIndex); 585 bool goToURL(const QString &category, unsigned int entryIndex);
558 /** see above */ 586 /** see above */
559 bool goToURL(unsigned int category, unsigned int entryIndex); 587 bool goToURL(unsigned int category, unsigned int entryIndex);
560 /** returns true if there is no entry present in the document. 588 /** returns true if there is no entry present in the document.
561 * Note: The "default" Category is present everytime, so 589 * Note: The "default" Category is present everytime, so
562 * it's checked for it's entries. 590 * it's checked for it's entries.
563 */ 591 */
564 bool isDocEmpty() 592 bool isDocEmpty()
565 { 593 {
566 if (numCategories() > 1) 594 if (numCategories() > 1)
567 return false; 595 return false;
568 if (numEntries(0)) 596 if (numEntries(0))
569 return false; 597 return false;
570 return true; 598 return true;
571 } 599 }
572 /** returns the filename of this doc */ 600 /** returns the filename of this doc */
573 const QString& getFilename() 601 const QString& getFilename()
574 { return filename; } 602 { return filename; }
575 /** returns the title of the doc */ 603 /** returns the title of the doc */
576 QString getTitle(); 604 QString getTitle();
577 /** sets the list-view-pointer hold in the doc */ 605 /** sets the list-view-pointer hold in the doc */
578 void setListViewPointer(PwMView *_listView) 606 void setListViewPointer(PwMView *_listView)
579 { listView = _listView; } 607 { listView = _listView; }
580 /** returns the list-view-pointer */ 608 /** returns the list-view-pointer */
581 PwMView * getListViewPointer() 609 PwMView * getListViewPointer()
582 { return listView; } 610 { return listView; }
583 /** try to delete the doc. The user may be asked to save 611 /** try to delete the doc. The user may be asked to save
584 * the data. The user may cancel the whole operation. 612 * the data. The user may cancel the whole operation.
585 * false is returned, then. 613 * false is returned, then.
586 */ 614 */
587 bool tryDelete(); 615 bool tryDelete();
588 /** is the doc deleted? (with tryDelete() ) */ 616 /** is the doc deleted? (with tryDelete() ) */
589 bool isDeleted() 617 bool isDeleted()
590 { return deleted; } 618 { return deleted; }
591 /** returns the document timer object */ 619 /** returns the document timer object */
592 DocTimer * timer() 620 DocTimer * timer()
593 { return _timer; } 621 { return _timer; }
594 /** get a lock on the dataChanged signal. 622 /** get a lock on the dataChanged signal.
595 * If someone is holding a lock, the signal is not emitted. 623 * If someone is holding a lock, the signal is not emitted.
596 */ 624 */
597 void getDataChangedLock() 625 void getDataChangedLock()
598 { ++dataChangedLock; } 626 { ++dataChangedLock; }
599 /** put the dataChanged lock */ 627 /** put the dataChanged lock */
600 void putDataChangedLock() 628 void putDataChangedLock()
601 { --dataChangedLock; } 629 { --dataChangedLock; }
602 /** returns the revision count of the item at cat/index */ 630 /** returns the revision count of the item at cat/index */
603 unsigned int getEntryRevCnt(unsigned int category, unsigned int index) 631 unsigned int getEntryRevCnt(unsigned int category, unsigned int index)
604 { return dti.dta[category].d[index].rev; } 632 { return dti.dta[category].d[index].rev; }
605 /** returns a const pointer to the entries meta */ 633 /** returns a const pointer to the entries meta */
606 const PwMMetaData * getEntryMeta(unsigned int category, unsigned int index) 634 const PwMMetaData * getEntryMeta(unsigned int category, unsigned int index)
607 { return &(dti.dta[category].d[index].meta); } 635 { return &(dti.dta[category].d[index].meta); }
608 /** is the entry at "category" "index" a binary entry? */ 636 /** is the entry at "category" "index" a binary entry? */
609 bool isBinEntry(unsigned int category, unsigned int index) 637 bool isBinEntry(unsigned int category, unsigned int index)
610 { return dti.dta[category].d[index].binary; } 638 { return dti.dta[category].d[index].binary; }
611 639
612public slots: 640public slots:
613 /** wrapper for PwMTray */ 641 /** wrapper for PwMTray */
614 void _deepUnlock(); 642 void _deepUnlock();
615 643
616signals: 644signals:
617 /** the data of the document has changed and must be updated 645 /** the data of the document has changed and must be updated
618 * in all views. 646 * in all views.
619 * NOTE: use emitDataChanged(PwMDoc *document) to emit this signal! 647 * NOTE: use emitDataChanged(PwMDoc *document) to emit this signal!
620 */ 648 */
621 void dataChanged(PwMDoc *document); 649 void dataChanged(PwMDoc *document);
622 /** the document class is going to close. This signal may be 650 /** the document class is going to close. This signal may be
623 * used to nofify all views, that the user closed the document, 651 * used to nofify all views, that the user closed the document,
624 * so the views can go down, too. 652 * so the views can go down, too.
625 */ 653 */
626 void docClosed(PwMDoc *document); 654 void docClosed(PwMDoc *document);
627 /** somebody just opened the document */ 655 /** somebody just opened the document */
628 void docOpened(PwMDoc *document); 656 void docOpened(PwMDoc *document);
629 /** this document object just got created */ 657 /** this document object just got created */
630 void docCreated(PwMDoc *document); 658 void docCreated(PwMDoc *document);
631 659
632public: 660public:
633 /** emit the dataChanged signal after checking for a lock */ 661 /** emit the dataChanged signal after checking for a lock */
634 void emitDataChanged(PwMDoc *document) 662 void emitDataChanged(PwMDoc *document)
635 { 663 {
636 if (!dataChangedLock) 664 if (!dataChangedLock)
637 emit dataChanged(document); 665 emit dataChanged(document);
638 } 666 }
639 667
640protected: 668protected:
641 /** current file for this doc */ 669 /** current file for this doc */
642 QString filename; 670 QString filename;
643//US ENH: we need a place where we keep the syncentries. So I invented 671//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 672// struct PwMItem, that has a vector of PwMCategoryItem and vector of PwMSyncItem
645 /** holds all data */ 673 /** holds all data */
646 PwMItem dti; 674 PwMItem dti;
647 /** maximum number of entries */ 675 /** maximum number of entries */
648 unsigned int maxEntries; 676 unsigned int maxEntries;
649 /** currently used password to encrypt data */ 677 /** currently used password to encrypt data */
650 QString currentPw; 678 QString currentPw;
651 /** current global document status flags */ 679 /** current global document status flags */
652 unsigned int curDocStat; 680 unsigned int curDocStat;
653 /** browser process for goToURL() */ 681 /** browser process for goToURL() */
654 KProcess browserProc; 682 KProcess browserProc;
655 /** pointer to the list-view, using this document. 683 /** pointer to the list-view, using this document.
656 * As there can only be one list-view per doc, we 684 * As there can only be one list-view per doc, we
657 * don't need a list here. 685 * don't need a list here.
658 */ 686 */
659 PwMView *listView; 687 PwMView *listView;
660 /** unnamedNum is used to store the "unnamed counter" 688 /** unnamedNum is used to store the "unnamed counter"
661 * for this document, while it's unnamed. If it's 0, 689 * for this document, while it's unnamed. If it's 0,
662 * we have to get a new unique one. 690 * we have to get a new unique one.
663 */ 691 */
664 unsigned int unnamedNum; 692 unsigned int unnamedNum;
665 /** is this doc going to be deleted (executing in destructor context) */ 693 /** is this doc going to be deleted (executing in destructor context) */
666 bool deleted; 694 bool deleted;
667 /** document timer */ 695 /** document timer */
668 DocTimer *_timer; 696 DocTimer *_timer;
669 /** lock counter for the "dataChanged" signal */ 697 /** lock counter for the "dataChanged" signal */
670 unsigned int dataChangedLock; 698 unsigned int dataChangedLock;
671 699
672 /** list of all open documents */ 700 /** list of all open documents */
673 static PwMDocList openDocList; 701 static PwMDocList openDocList;
674 702
675protected: 703protected:
676 /** serialize "dta" and return it in "d". */ 704 /** serialize "dta" and return it in "d". */
677 bool serializeDta(string *d); 705 bool serializeDta(string *d);
678 /** de-serialize "d" and overwrite "dta" */ 706 /** de-serialize "d" and overwrite "dta" */
679 bool deSerializeDta(const string *d, bool entriesLocked); 707 bool deSerializeDta(const string *d, bool entriesLocked);
680 /** write header to file */ 708 /** write header to file */
681 PwMerror writeFileHeader(char keyHash, char dataHash, char crypt, char compress, 709 PwMerror writeFileHeader(char keyHash, char dataHash, char crypt, char compress,
682 QString *pw, QFile *f); 710 QString *pw, QFile *f);
683 /** write data-hash to file */ 711 /** write data-hash to file */
684 PwMerror writeDataHash(char dataHash, string *d, QFile *f); 712 PwMerror writeDataHash(char dataHash, string *d, QFile *f);
685 /** check header. Read header info and verify key-hash and filever. 713 /** check header. Read header info and verify key-hash and filever.
686 * returns length of header in "headerLength" */ 714 * returns length of header in "headerLength" */
687 PwMerror checkHeader(char *cryptAlgo, QString *pw, char *compress, 715 PwMerror checkHeader(char *cryptAlgo, QString *pw, char *compress,
688 unsigned int *headerLength, char *dataHashType, 716 unsigned int *headerLength, char *dataHashType,
689 string *dataHash, QFile *f); 717 string *dataHash, QFile *f);
690 /** check the data-hash */ 718 /** check the data-hash */
691 PwMerror checkDataHash(char dataHashType, const string *dataHash, const string *dataStream); 719 PwMerror checkDataHash(char dataHashType, const string *dataHash, const string *dataStream);
692 /** encrypt data "d" and write to "filename" */ 720 /** encrypt data "d" and write to "filename" */
693 PwMerror encrypt(string *d, const QString *pw, QFile *f, char algo); 721 PwMerror encrypt(string *d, const QString *pw, QFile *f, char algo);
694 /** read data from file beginning at "pos", decrypt and return it */ 722 /** read data from file beginning at "pos", decrypt and return it */
695 PwMerror decrypt(string *d, unsigned int pos, const QString *pw, char algo, QFile *f); 723 PwMerror decrypt(string *d, unsigned int pos, const QString *pw, char algo, QFile *f);
696 /** compress the data */ 724 /** compress the data */
697 bool compressDta(string *d, char algo); 725 bool compressDta(string *d, char algo);
698 /** uncompress the data */ 726 /** uncompress the data */
699 bool decompressDta(string *d, char algo); 727 bool decompressDta(string *d, char algo);
700 /** internal import function for a text-file generated by PwM. 728 /** internal import function for a text-file generated by PwM.
701 * If this is not a valid PwM-exported file, it returns e_fileFormat */ 729 * If this is not a valid PwM-exported file, it returns e_fileFormat */
702 PwMerror importText_PwM(const QString *file); 730 PwMerror importText_PwM(const QString *file);
703 /** PwM-text-import helper function to extract the name/pw/comment out 731 /** PwM-text-import helper function to extract the name/pw/comment out
704 * of one entry-line */ 732 * of one entry-line */
705 bool textExtractEntry_PwM(const char *in, ssize_t in_size, string *out); 733 bool textExtractEntry_PwM(const char *in, ssize_t in_size, string *out);
706 /** compare two strings */ 734 /** compare two strings */
707 bool compareString(const string &s1, const string &s2, bool caseSensitive, 735 bool compareString(const string &s1, const string &s2, bool caseSensitive,
708 bool exactWordMatch); 736 bool exactWordMatch);
709 /** clears all document-data */ 737 /** clears all document-data */
710 void clearDoc(); 738 void clearDoc();
711 /** delete all empty categories */ 739 /** delete all empty categories */
712 void delAllEmptyCat(bool dontFlagDirty); 740 void delAllEmptyCat(bool dontFlagDirty);
713 /** set a document status flag */ 741 /** set a document status flag */
714 void setDocStatFlag(unsigned int statFlag) 742 void setDocStatFlag(unsigned int statFlag)
715 { curDocStat |= statFlag; } 743 { curDocStat |= statFlag; }
716 /** unset a document status flag */ 744 /** unset a document status flag */
717 void unsetDocStatFlag(unsigned int statFlag) 745 void unsetDocStatFlag(unsigned int statFlag)
718 { curDocStat &= ~statFlag; } 746 { curDocStat &= ~statFlag; }
719 /** get a document status flag */ 747 /** get a document status flag */
720 bool getDocStatFlag(unsigned int statFlag) const 748 bool getDocStatFlag(unsigned int statFlag) const
721 { return (curDocStat & statFlag); } 749 { return (curDocStat & statFlag); }
722 /** set the "currentPassword" */ 750 /** set the "currentPassword" */
723 void setCurrentPw(const QString &pw) 751 void setCurrentPw(const QString &pw)
724 { 752 {
725 currentPw = pw; 753 currentPw = pw;
726 setDocStatFlag(DOC_STAT_DISK_DIRTY); 754 setDocStatFlag(DOC_STAT_DISK_DIRTY);
727 } 755 }
728 /** make a backup-copy of the given file */ 756 /** make a backup-copy of the given file */
729 bool backupFile(const QString &filePath); 757 bool backupFile(const QString &filePath);
730 /** copy a file from src to dst */ 758 /** copy a file from src to dst */
731 bool copyFile(const QString &src, const QString &dst); 759 bool copyFile(const QString &src, const QString &dst);
732 760
733 761
734 public: 762 public:
735#ifdef PWM_EMBEDDED 763#ifdef PWM_EMBEDDED
736 //US ENH: this is the magic function that syncronizes the local doc with the remote doc. 764 //US ENH: this is the magic function that syncronizes the local doc with the remote doc.
737 PwMerror syncronize(KSyncManager* manager, PwMDoc* syncLocal, PwMDoc* syncRemote, int mode ); 765 PwMerror syncronize(KSyncManager* manager, PwMDoc* syncLocal, PwMDoc* syncRemote, int mode );
738 766
739 //takePwMDataItem returns the following values 767 //takePwMDataItem returns the following values
740 // 0 equal 768 // 0 equal
741 // 1 take local 769 // 1 take local
742 // 2 take remote 770 // 2 take remote
743 // 3 cancel 771 // 3 cancel
744 int takePwMDataItem( PwMDataItem* local, PwMDataItem* remote, QDateTime lastSync, int mode , bool full ); 772 int takePwMDataItem( PwMDataItem* local, PwMDataItem* remote, QDateTime lastSync, int mode , bool full );
745 773
746 //the following methods are the overwritten callbackmethods from the syncinterface 774 //the following methods are the overwritten callbackmethods from the syncinterface
747 virtual bool sync(KSyncManager* manager, QString filename, int mode); 775 virtual bool sync(KSyncManager* manager, QString filename, int mode);
748 776
749 //called by the syncmanager to indicate that the work has to be marked as dirty. 777 //called by the syncmanager to indicate that the work has to be marked as dirty.
750 virtual void sync_setModified(); 778 virtual void sync_setModified();
751 //called by the syncmanager to ask if the dirty flag is set. 779 //called by the syncmanager to ask if the dirty flag is set.
752 virtual bool sync_isModified(); 780 virtual bool sync_isModified();
753 //called by the syncmanager to indicate that the work has to be saved. 781 //called by the syncmanager to indicate that the work has to be saved.
754 virtual void sync_save(); 782 virtual void sync_save();
755 783
756#endif 784#endif
757 private: 785 private:
758 //US ENH: helpermethods to access the sync data for a certain syncname. 786 //US ENH: helpermethods to access the sync data for a certain syncname.
759 // It returns the syncdatas index 787 // It returns the syncdatas index
760 bool findSyncData(const QString &syncname, unsigned int *index); 788 bool findSyncData(const QString &syncname, unsigned int *index);
761 789
762 /** add new syncdataentry */ 790 /** add new syncdataentry */
763 PwMerror addSyncDataEntry(PwMSyncItem *d, bool dontFlagDirty = false); 791 PwMerror addSyncDataEntry(PwMSyncItem *d, bool dontFlagDirty = false);
764 792
765 /** returns a pointer to the syncdata */ 793 /** returns a pointer to the syncdata */
766 PwMSyncItem* getSyncDataEntry(unsigned int index) 794 PwMSyncItem getSyncDataEntry(unsigned int index)
767 { return &(dti.syncDta[index]); } 795 { return *(dti.syncDta[index]); }
768 796
769 /** delete entry */ 797 /** delete entry */
770 bool delSyncDataEntry(unsigned int index, bool dontFlagDirty = false); 798 bool delSyncDataEntry(unsigned int index, bool dontFlagDirty = false);
771 799
772 PwMDataItem* findEntryByID(const QString &uid, unsigned int *category, unsigned int *index); 800 PwMDataItem* findEntryByID(const QString &uid, unsigned int *category, unsigned int *index);
773 801
774 QStringList getIDEntryList(); 802 QStringList getIDEntryList();
775 803
776}; 804};
777 805
778#endif 806#endif
diff --git a/pwmanager/pwmanager/serializer.cpp b/pwmanager/pwmanager/serializer.cpp
index f615082..74b3354 100644
--- a/pwmanager/pwmanager/serializer.cpp
+++ b/pwmanager/pwmanager/serializer.cpp
@@ -1,756 +1,756 @@
1/*************************************************************************** 1/***************************************************************************
2 * * 2 * *
3 * copyright (C) 2004 by Michael Buesch * 3 * copyright (C) 2004 by Michael Buesch *
4 * email: mbuesch@freenet.de * 4 * email: mbuesch@freenet.de *
5 * * 5 * *
6 * This program is free software; you can redistribute it and/or modify * 6 * This program is free software; you can redistribute it and/or modify *
7 * it under the terms of the GNU General Public License version 2 * 7 * it under the terms of the GNU General Public License version 2 *
8 * as published by the Free Software Foundation. * 8 * as published by the Free Software Foundation. *
9 * * 9 * *
10 ***************************************************************************/ 10 ***************************************************************************/
11 11
12 12
13/*************************************************************************** 13/***************************************************************************
14 * copyright (C) 2004 by Ulf Schenk 14 * copyright (C) 2004 by Ulf Schenk
15 * This file is originaly based on version 2.0 of pwmanager 15 * This file is originaly based on version 2.0 of pwmanager
16 * and was modified to run on embedded devices that run microkde 16 * and was modified to run on embedded devices that run microkde
17 * 17 *
18 * $Id$ 18 * $Id$
19 **************************************************************************/ 19 **************************************************************************/
20 20
21#include "serializer.h" 21#include "serializer.h"
22#include "pwmexception.h" 22#include "pwmexception.h"
23 23
24#ifdef PWM_EMBEDDED 24#ifdef PWM_EMBEDDED
25#include <kglobal.h> 25#include <kglobal.h>
26#include <klocale.h> 26#include <klocale.h>
27#endif 27#endif
28 28
29/* enable/disable serializer debugging (0/1) */ 29/* enable/disable serializer debugging (0/1) */
30 #define SERIALIZER_DEBUG1 30 #define SERIALIZER_DEBUG1
31/* use the old xml tags for writing (0/1) */ 31/* use the old xml tags for writing (0/1) */
32 #define USE_OLD_TAGS 0 32 #define USE_OLD_TAGS 0
33/* write a CDATA section (0/1) */ 33/* write a CDATA section (0/1) */
34 #define WRITE_CDATA_SEC 0 34 #define WRITE_CDATA_SEC 0
35 35
36 36
37 #define META_CREATE_DATE"c" 37 #define META_CREATE_DATE"c"
38 #define META_VALID_DATE "v" 38 #define META_VALID_DATE "v"
39 #define META_EXPIRE_DATE"e" 39 #define META_EXPIRE_DATE"e"
40 #define META_UPDATE_DATE"u" 40 #define META_UPDATE_DATE"u"
41 #define META_UPDATE_INT "i" 41 #define META_UPDATE_INT "i"
42//US ENH : uniqueid 42//US ENH : uniqueid
43#define META_UNIQUEID "n" 43#define META_UNIQUEID "n"
44#define SYNC_ROOT "s" 44#define SYNC_ROOT "s"
45#define SYNC_TARGET_PREFIX "t" 45#define SYNC_TARGET_PREFIX "t"
46#define SYNC_TARGET_NAME "n" 46#define SYNC_TARGET_NAME "n"
47 47
48 48
49/* This is compatibility stuff. 49/* This is compatibility stuff.
50 * The names of the entries have changed and here are the 50 * The names of the entries have changed and here are the
51 * new and old ones 51 * new and old ones
52 */ 52 */
53 #define ROOT_MAGIC_OLD "PwM-xml-dat" 53 #define ROOT_MAGIC_OLD "PwM-xml-dat"
54 #define VER_STR_OLD "ver" 54 #define VER_STR_OLD "ver"
55 #define COMPAT_VER_OLD "0x02" 55 #define COMPAT_VER_OLD "0x02"
56 #define CAT_ROOT_OLD "categories" 56 #define CAT_ROOT_OLD "categories"
57 #define CAT_PREFIX_OLD "cat_" 57 #define CAT_PREFIX_OLD "cat_"
58 #define CAT_NAME_OLD "name" 58 #define CAT_NAME_OLD "name"
59 #define ENTRY_PREFIX_OLD"entry_" 59 #define ENTRY_PREFIX_OLD"entry_"
60 #define ENTRY_DESC_OLD "desc" 60 #define ENTRY_DESC_OLD "desc"
61 #define ENTRY_NAME_OLD "name" 61 #define ENTRY_NAME_OLD "name"
62 #define ENTRY_PW_OLD "pw" 62 #define ENTRY_PW_OLD "pw"
63 #define ENTRY_COMMENT_OLD"comment" 63 #define ENTRY_COMMENT_OLD"comment"
64 #define ENTRY_URL_OLD "url" 64 #define ENTRY_URL_OLD "url"
65 #define ENTRY_LAUNCHER_OLD"launcher" 65 #define ENTRY_LAUNCHER_OLD"launcher"
66 #define ENTRY_LVP_OLD "listViewPos" 66 #define ENTRY_LVP_OLD "listViewPos"
67 #define ENTRY_BIN_OLD "b" 67 #define ENTRY_BIN_OLD "b"
68 #define ENTRY_META_OLD "m" 68 #define ENTRY_META_OLD "m"
69 69
70 #define ROOT_MAGIC_NEW "P" 70 #define ROOT_MAGIC_NEW "P"
71 #define VER_STR_NEW "v" 71 #define VER_STR_NEW "v"
72 #define COMPAT_VER_NEW "2" 72 #define COMPAT_VER_NEW "2"
73 #define CAT_ROOT_NEW "c" 73 #define CAT_ROOT_NEW "c"
74 #define CAT_PREFIX_NEW "c" 74 #define CAT_PREFIX_NEW "c"
75 #define CAT_NAME_NEW "n" 75 #define CAT_NAME_NEW "n"
76 #define ENTRY_PREFIX_NEW"e" 76 #define ENTRY_PREFIX_NEW"e"
77 #define ENTRY_DESC_NEW "d" 77 #define ENTRY_DESC_NEW "d"
78 #define ENTRY_NAME_NEW "n" 78 #define ENTRY_NAME_NEW "n"
79 #define ENTRY_PW_NEW "p" 79 #define ENTRY_PW_NEW "p"
80 #define ENTRY_COMMENT_NEW"c" 80 #define ENTRY_COMMENT_NEW"c"
81 #define ENTRY_URL_NEW "u" 81 #define ENTRY_URL_NEW "u"
82 #define ENTRY_LAUNCHER_NEW"l" 82 #define ENTRY_LAUNCHER_NEW"l"
83 #define ENTRY_LVP_NEW "v" 83 #define ENTRY_LVP_NEW "v"
84 #define ENTRY_BIN_NEW ENTRY_BIN_OLD 84 #define ENTRY_BIN_NEW ENTRY_BIN_OLD
85 #define ENTRY_META_NEW ENTRY_META_OLD 85 #define ENTRY_META_NEW ENTRY_META_OLD
86 86
87#if USE_OLD_TAGS != 0 87#if USE_OLD_TAGS != 0
88 # define ROOT_MAGIC_WR ROOT_MAGIC_OLD 88 # define ROOT_MAGIC_WR ROOT_MAGIC_OLD
89 # define VER_STR_WR VER_STR_OLD 89 # define VER_STR_WR VER_STR_OLD
90 # define COMPAT_VER_WR COMPAT_VER_OLD 90 # define COMPAT_VER_WR COMPAT_VER_OLD
91 # define CAT_ROOT_WR CAT_ROOT_OLD 91 # define CAT_ROOT_WR CAT_ROOT_OLD
92 # define CAT_PREFIX_WR CAT_PREFIX_OLD 92 # define CAT_PREFIX_WR CAT_PREFIX_OLD
93 # define CAT_NAME_WR CAT_NAME_OLD 93 # define CAT_NAME_WR CAT_NAME_OLD
94 # define ENTRY_PREFIX_WRENTRY_PREFIX_OLD 94 # define ENTRY_PREFIX_WRENTRY_PREFIX_OLD
95 # define ENTRY_DESC_WR ENTRY_DESC_OLD 95 # define ENTRY_DESC_WR ENTRY_DESC_OLD
96 # define ENTRY_NAME_WR ENTRY_NAME_OLD 96 # define ENTRY_NAME_WR ENTRY_NAME_OLD
97 # define ENTRY_PW_WR ENTRY_PW_OLD 97 # define ENTRY_PW_WR ENTRY_PW_OLD
98 # define ENTRY_COMMENT_WRENTRY_COMMENT_OLD 98 # define ENTRY_COMMENT_WRENTRY_COMMENT_OLD
99 # define ENTRY_URL_WR ENTRY_URL_OLD 99 # define ENTRY_URL_WR ENTRY_URL_OLD
100 # define ENTRY_LAUNCHER_WRENTRY_LAUNCHER_OLD 100 # define ENTRY_LAUNCHER_WRENTRY_LAUNCHER_OLD
101 # define ENTRY_LVP_WR ENTRY_LVP_OLD 101 # define ENTRY_LVP_WR ENTRY_LVP_OLD
102 # define ENTRY_BIN_WR ENTRY_BIN_OLD 102 # define ENTRY_BIN_WR ENTRY_BIN_OLD
103 # define ENTRY_META_WR ENTRY_META_OLD 103 # define ENTRY_META_WR ENTRY_META_OLD
104#else 104#else
105 # define ROOT_MAGIC_WR ROOT_MAGIC_NEW 105 # define ROOT_MAGIC_WR ROOT_MAGIC_NEW
106 # define VER_STR_WR VER_STR_NEW 106 # define VER_STR_WR VER_STR_NEW
107 # define COMPAT_VER_WR COMPAT_VER_NEW 107 # define COMPAT_VER_WR COMPAT_VER_NEW
108 # define CAT_ROOT_WR CAT_ROOT_NEW 108 # define CAT_ROOT_WR CAT_ROOT_NEW
109 # define CAT_PREFIX_WR CAT_PREFIX_NEW 109 # define CAT_PREFIX_WR CAT_PREFIX_NEW
110 # define CAT_NAME_WR CAT_NAME_NEW 110 # define CAT_NAME_WR CAT_NAME_NEW
111 # define ENTRY_PREFIX_WRENTRY_PREFIX_NEW 111 # define ENTRY_PREFIX_WRENTRY_PREFIX_NEW
112 # define ENTRY_DESC_WR ENTRY_DESC_NEW 112 # define ENTRY_DESC_WR ENTRY_DESC_NEW
113 # define ENTRY_NAME_WR ENTRY_NAME_NEW 113 # define ENTRY_NAME_WR ENTRY_NAME_NEW
114 # define ENTRY_PW_WR ENTRY_PW_NEW 114 # define ENTRY_PW_WR ENTRY_PW_NEW
115 # define ENTRY_COMMENT_WRENTRY_COMMENT_NEW 115 # define ENTRY_COMMENT_WRENTRY_COMMENT_NEW
116 # define ENTRY_URL_WR ENTRY_URL_NEW 116 # define ENTRY_URL_WR ENTRY_URL_NEW
117 # define ENTRY_LAUNCHER_WRENTRY_LAUNCHER_NEW 117 # define ENTRY_LAUNCHER_WRENTRY_LAUNCHER_NEW
118 # define ENTRY_LVP_WR ENTRY_LVP_NEW 118 # define ENTRY_LVP_WR ENTRY_LVP_NEW
119 # define ENTRY_BIN_WR ENTRY_BIN_NEW 119 # define ENTRY_BIN_WR ENTRY_BIN_NEW
120 # define ENTRY_META_WR ENTRY_META_NEW 120 # define ENTRY_META_WR ENTRY_META_NEW
121#endif 121#endif
122 122
123 123
124Serializer::Serializer() 124Serializer::Serializer()
125{ 125{
126 defaultLockStat = true; 126 defaultLockStat = true;
127//US BUG: I needed to specify a document name. Otherwise impl will not be created for serializing 127//US BUG: I needed to specify a document name. Otherwise impl will not be created for serializing
128#ifndef PWM_EMBEDDED 128#ifndef PWM_EMBEDDED
129 domDoc = new QDomDocument; 129 domDoc = new QDomDocument;
130#else 130#else
131 domDoc = new QDomDocument("mydoc"); 131 domDoc = new QDomDocument("mydoc");
132#endif 132#endif
133} 133}
134 134
135Serializer::Serializer(const QCString &buffer) 135Serializer::Serializer(const QCString &buffer)
136{ 136{
137 defaultLockStat = true; 137 defaultLockStat = true;
138//US BUG: I needed to specify a document name. Otherwise impl will not be created for serializing 138//US BUG: I needed to specify a document name. Otherwise impl will not be created for serializing
139#ifndef PWM_EMBEDDED 139#ifndef PWM_EMBEDDED
140 domDoc = new QDomDocument; 140 domDoc = new QDomDocument;
141#else 141#else
142 domDoc = new QDomDocument("mydoc"); 142 domDoc = new QDomDocument("mydoc");
143#endif 143#endif
144 144
145 if (!parseXml(buffer)) { 145 if (!parseXml(buffer)) {
146 delete domDoc; 146 delete domDoc;
147#ifndef PWM_EMBEDDED 147#ifndef PWM_EMBEDDED
148 throw PwMException(PwMException::EX_PARSE); 148 throw PwMException(PwMException::EX_PARSE);
149#else 149#else
150 qDebug("Serializer::Serializer : Parse Exception "); 150 qDebug("Serializer::Serializer : Parse Exception ");
151#endif 151#endif
152 } 152 }
153} 153}
154 154
155Serializer::~Serializer() 155Serializer::~Serializer()
156{ 156{
157 delete_ifnot_null(domDoc); 157 delete_ifnot_null(domDoc);
158} 158}
159 159
160void Serializer::clear() 160void Serializer::clear()
161{ 161{
162 delete_ifnot_null(domDoc); 162 delete_ifnot_null(domDoc);
163 domDoc = new QDomDocument; 163 domDoc = new QDomDocument;
164} 164}
165 165
166bool Serializer::parseXml(const QCString &buffer) 166bool Serializer::parseXml(const QCString &buffer)
167{ 167{
168 PWM_ASSERT(domDoc); 168 PWM_ASSERT(domDoc);
169#ifndef PWM_EMBEDDED 169#ifndef PWM_EMBEDDED
170 if (!domDoc->setContent(buffer, true)) 170 if (!domDoc->setContent(buffer, true))
171 return false; 171 return false;
172#else 172#else
173 if (!domDoc->setContent(buffer)) 173 if (!domDoc->setContent(buffer))
174 return false; 174 return false;
175#endif 175#endif
176 if (!checkValid()) 176 if (!checkValid())
177 return false; 177 return false;
178 return true; 178 return true;
179} 179}
180 180
181QCString Serializer::getXml() 181QCString Serializer::getXml()
182{ 182{
183 PWM_ASSERT(domDoc); 183 PWM_ASSERT(domDoc);
184 184
185#ifndef PWM_EMBEDDED 185#ifndef PWM_EMBEDDED
186#if defined(PWM_DEBUG) && SERIALIZER_DEBUG != 0 186#if defined(PWM_DEBUG) && SERIALIZER_DEBUG != 0
187 QCString tmp(domDoc->toCString(8)); 187 QCString tmp(domDoc->toCString(8));
188 printDebug("<BEGIN Serializer::getXml() dump>\n"); 188 printDebug("<BEGIN Serializer::getXml() dump>\n");
189 cout << tmp << endl; 189 cout << tmp << endl;
190 printDebug("<END Serializer::getXml() dump>"); 190 printDebug("<END Serializer::getXml() dump>");
191#endif // DEBUG 191#endif // DEBUG
192 192
193 QCString ret(domDoc->toCString(0)); 193 QCString ret(domDoc->toCString(0));
194 ret.replace('\n', ""); 194 ret.replace('\n', "");
195 return ret; 195 return ret;
196#else 196#else
197 197
198#if defined(PWM_DEBUG) && SERIALIZER_DEBUG != 0 198#if defined(PWM_DEBUG) && SERIALIZER_DEBUG != 0
199 QCString tmp(" " + domDoc->toCString()); 199 QCString tmp(" " + domDoc->toCString());
200 printDebug("<BEGIN Serializer::getXml() dump>\n"); 200 printDebug("<BEGIN Serializer::getXml() dump>\n");
201 qDebug(tmp); 201 qDebug(tmp);
202 cout << tmp << endl; 202 cout << tmp << endl;
203 printDebug("<END Serializer::getXml() dump>"); 203 printDebug("<END Serializer::getXml() dump>");
204#endif // DEBUG 204#endif // DEBUG
205 205
206 QCString ret(domDoc->toCString()); 206 QCString ret(domDoc->toCString());
207 ret.replace(QRegExp("\n"), ""); 207 ret.replace(QRegExp("\n"), "");
208 return ret; 208 return ret;
209 209
210#endif 210#endif
211} 211}
212 212
213bool Serializer::serialize(PwMItem &dta) 213bool Serializer::serialize(PwMItem &dta)
214{ 214{
215 PWM_ASSERT(domDoc); 215 PWM_ASSERT(domDoc);
216 QDomElement root(genNewRoot()); 216 QDomElement root(genNewRoot());
217 QDomElement catNode(domDoc->createElement(CAT_ROOT_WR)); 217 QDomElement catNode(domDoc->createElement(CAT_ROOT_WR));
218 QDomElement syncNode(domDoc->createElement(SYNC_ROOT)); 218 QDomElement syncNode(domDoc->createElement(SYNC_ROOT));
219 if (!addSyncData(&syncNode, dta.syncDta)) 219 if (!addSyncData(&syncNode, dta.syncDta))
220 return false; 220 return false;
221 root.appendChild(syncNode); 221 root.appendChild(syncNode);
222 if (!addCategories(&catNode, dta.dta)) 222 if (!addCategories(&catNode, dta.dta))
223 return false; 223 return false;
224 root.appendChild(catNode); 224 root.appendChild(catNode);
225 return true; 225 return true;
226} 226}
227 227
228bool Serializer::deSerialize(PwMItem *dta) 228bool Serializer::deSerialize(PwMItem *dta)
229{ 229{
230 PWM_ASSERT(domDoc); 230 PWM_ASSERT(domDoc);
231 PWM_ASSERT(dta); 231 PWM_ASSERT(dta);
232 QDomElement root(domDoc->documentElement()); 232 QDomElement root(domDoc->documentElement());
233 QDomNode n; 233 QDomNode n;
234 234
235 dta->clear(); 235 dta->clear();
236 for (n = root.firstChild(); !n.isNull(); n = n.nextSibling()) { 236 for (n = root.firstChild(); !n.isNull(); n = n.nextSibling()) {
237 // find <categories> ... </categories> 237 // find <categories> ... </categories>
238 // <c> ... </c> 238 // <c> ... </c>
239 if (n.nodeName() == CAT_ROOT_NEW || 239 if (n.nodeName() == CAT_ROOT_NEW ||
240 n.nodeName() == CAT_ROOT_OLD) { 240 n.nodeName() == CAT_ROOT_OLD) {
241 if (!readCategories(n, &(dta->dta))) { 241 if (!readCategories(n, &(dta->dta))) {
242 return false; 242 return false;
243 } 243 }
244 continue; 244 continue;
245 } 245 }
246 else if (n.nodeName() == SYNC_ROOT) { 246 else if (n.nodeName() == SYNC_ROOT) {
247 if (!readSyncData(n, &(dta->syncDta))) { 247 if (!readSyncData(n, &(dta->syncDta))) {
248 return false; 248 return false;
249 } 249 }
250 continue; 250 continue;
251 } 251 }
252 252
253 /* NOTE: We can stop processing here, as we 253 /* NOTE: We can stop processing here, as we
254 * don't have more nodes in root, yet. 254 * don't have more nodes in root, yet.
255 */ 255 */
256 return false; 256 return false;
257 257
258 } 258 }
259 return true; 259 return true;
260} 260}
261 261
262bool Serializer::readCategories(const QDomNode &n, 262bool Serializer::readCategories(const QDomNode &n,
263 vector<PwMCategoryItem> *dta) 263 vector<PwMCategoryItem> *dta)
264{ 264{
265 QDomNodeList nl(n.childNodes()); 265 QDomNodeList nl(n.childNodes());
266 QDomNode cur; 266 QDomNode cur;
267 QString name; 267 QString name;
268 unsigned int numCat = nl.count(), i; 268 unsigned int numCat = nl.count(), i;
269 PwMCategoryItem curCat; 269 PwMCategoryItem curCat;
270 vector<PwMDataItem> curEntr; 270 vector<PwMDataItem> curEntr;
271 271
272 if (!numCat) { 272 if (!numCat) {
273 printDebug("Serializer::readCategories(): empty"); 273 printDebug("Serializer::readCategories(): empty");
274 return false; 274 return false;
275 } 275 }
276 for (i = 0; i < numCat; ++i) { 276 for (i = 0; i < numCat; ++i) {
277 cur = nl.item(i); 277 cur = nl.item(i);
278 if (cur.nodeName().left(1) == CAT_PREFIX_NEW || 278 if (cur.nodeName().left(1) == CAT_PREFIX_NEW ||
279 cur.nodeName().left(4) == CAT_PREFIX_OLD) { 279 cur.nodeName().left(4) == CAT_PREFIX_OLD) {
280 name = cur.toElement().attribute(CAT_NAME_NEW); 280 name = cur.toElement().attribute(CAT_NAME_NEW);
281 if (name == QString::null) 281 if (name == QString::null)
282 name = cur.toElement().attribute(CAT_NAME_OLD); 282 name = cur.toElement().attribute(CAT_NAME_OLD);
283 PWM_ASSERT(name != QString::null); 283 PWM_ASSERT(name != QString::null);
284 PWM_ASSERT(name != ""); 284 PWM_ASSERT(name != "");
285 curCat.clear(); 285 curCat.clear();
286 curCat.name = name.latin1(); 286 curCat.name = name.latin1();
287 if (!readEntries(cur, &curEntr)) { 287 if (!readEntries(cur, &curEntr)) {
288 dta->clear(); 288 dta->clear();
289 return false; 289 return false;
290 } 290 }
291 curCat.d = curEntr; 291 curCat.d = curEntr;
292 dta->push_back(curCat); 292 dta->push_back(curCat);
293 } else { 293 } else {
294 printDebug("Serializer::readCategories(): uh? not a category?"); 294 printDebug("Serializer::readCategories(): uh? not a category?");
295 } 295 }
296 } 296 }
297 return true; 297 return true;
298} 298}
299 299
300bool Serializer::readEntries(const QDomNode &n, 300bool Serializer::readEntries(const QDomNode &n,
301 vector<PwMDataItem> *dta) 301 vector<PwMDataItem> *dta)
302{ 302{
303 QDomNodeList nl(n.childNodes()); 303 QDomNodeList nl(n.childNodes());
304 QDomNode cur; 304 QDomNode cur;
305 unsigned int numEntr = nl.count(), i; 305 unsigned int numEntr = nl.count(), i;
306 PwMDataItem curEntr; 306 PwMDataItem curEntr;
307 307
308 dta->clear(); 308 dta->clear();
309 for (i = 0; i < numEntr; ++i) { 309 for (i = 0; i < numEntr; ++i) {
310 cur = nl.item(i); 310 cur = nl.item(i);
311 if (cur.nodeName().left(1) == ENTRY_PREFIX_NEW || 311 if (cur.nodeName().left(1) == ENTRY_PREFIX_NEW ||
312 cur.nodeName().left(6) == ENTRY_PREFIX_OLD) { 312 cur.nodeName().left(6) == ENTRY_PREFIX_OLD) {
313 if (!extractEntry(cur, &curEntr)) { 313 if (!extractEntry(cur, &curEntr)) {
314 return false; 314 return false;
315 } 315 }
316 dta->push_back(curEntr); 316 dta->push_back(curEntr);
317 } else { 317 } else {
318 printDebug("Serializer::readEntries(): hm? not an entry?"); 318 printDebug("Serializer::readEntries(): hm? not an entry?");
319 } 319 }
320 } 320 }
321 return true; 321 return true;
322} 322}
323 323
324bool Serializer::extractEntry(const QDomNode &n, 324bool Serializer::extractEntry(const QDomNode &n,
325 PwMDataItem *dta) 325 PwMDataItem *dta)
326{ 326{
327 QDomNodeList nl(n.childNodes()); 327 QDomNodeList nl(n.childNodes());
328 QDomNode cur, cdata; 328 QDomNode cur, cdata;
329 unsigned int cnt = nl.count(), i; 329 unsigned int cnt = nl.count(), i;
330 QString name, text; 330 QString name, text;
331 331
332 if (!cnt) { 332 if (!cnt) {
333 printDebug("Serializer::extractEntry(): empty"); 333 printDebug("Serializer::extractEntry(): empty");
334 return false; 334 return false;
335 } 335 }
336 dta->clear(); 336 dta->clear();
337 for (i = 0; i < cnt; ++i) { 337 for (i = 0; i < cnt; ++i) {
338 cur = nl.item(i); 338 cur = nl.item(i);
339 name = cur.nodeName(); 339 name = cur.nodeName();
340 cdata = cur.firstChild(); 340 cdata = cur.firstChild();
341 if (unlikely(cdata.isCDATASection())) { 341 if (unlikely(cdata.isCDATASection())) {
342 text = cdata.toCDATASection().data(); 342 text = cdata.toCDATASection().data();
343 } else if (likely(cur.isElement())) { 343 } else if (likely(cur.isElement())) {
344 text = cur.toElement().text(); 344 text = cur.toElement().text();
345 } else { 345 } else {
346 printDebug("Serializer::extractEntry(): neither CDATA nor element."); 346 printDebug("Serializer::extractEntry(): neither CDATA nor element.");
347 return false; 347 return false;
348 } 348 }
349 if (text == " ") 349 if (text == " ")
350 text = ""; // for backward compatibility. 350 text = ""; // for backward compatibility.
351 if (name == ENTRY_DESC_NEW || 351 if (name == ENTRY_DESC_NEW ||
352 name == ENTRY_DESC_OLD) { 352 name == ENTRY_DESC_OLD) {
353 dta->desc = unescapeEntryData(text).latin1(); 353 dta->desc = unescapeEntryData(text).latin1();
354 } else if (name == ENTRY_NAME_NEW || 354 } else if (name == ENTRY_NAME_NEW ||
355 name == ENTRY_NAME_OLD) { 355 name == ENTRY_NAME_OLD) {
356 dta->name = unescapeEntryData(text).latin1(); 356 dta->name = unescapeEntryData(text).latin1();
357 } else if (name == ENTRY_PW_NEW || 357 } else if (name == ENTRY_PW_NEW ||
358 name == ENTRY_PW_OLD) { 358 name == ENTRY_PW_OLD) {
359 dta->pw = unescapeEntryData(text).latin1(); 359 dta->pw = unescapeEntryData(text).latin1();
360 } else if (name == ENTRY_COMMENT_NEW || 360 } else if (name == ENTRY_COMMENT_NEW ||
361 name == ENTRY_COMMENT_OLD) { 361 name == ENTRY_COMMENT_OLD) {
362 dta->comment = unescapeEntryData(text).latin1(); 362 dta->comment = unescapeEntryData(text).latin1();
363 } else if (name == ENTRY_URL_NEW || 363 } else if (name == ENTRY_URL_NEW ||
364 name == ENTRY_URL_OLD) { 364 name == ENTRY_URL_OLD) {
365 dta->url = unescapeEntryData(text).latin1(); 365 dta->url = unescapeEntryData(text).latin1();
366 } else if (name == ENTRY_LAUNCHER_NEW || 366 } else if (name == ENTRY_LAUNCHER_NEW ||
367 name == ENTRY_LAUNCHER_OLD) { 367 name == ENTRY_LAUNCHER_OLD) {
368 dta->launcher = unescapeEntryData(text).latin1(); 368 dta->launcher = unescapeEntryData(text).latin1();
369 } else if (name == ENTRY_LVP_NEW || 369 } else if (name == ENTRY_LVP_NEW ||
370 name == ENTRY_LVP_OLD) { 370 name == ENTRY_LVP_OLD) {
371 dta->listViewPos = strtol(text.latin1(), 0, 10); 371 dta->listViewPos = strtol(text.latin1(), 0, 10);
372 } else if (name == ENTRY_BIN_NEW) { 372 } else if (name == ENTRY_BIN_NEW) {
373 // ENTRY_BIN_NEW == ENTRY_BIN_OLD 373 // ENTRY_BIN_NEW == ENTRY_BIN_OLD
374 if (text == "0") { 374 if (text == "0") {
375 dta->binary = false; 375 dta->binary = false;
376 } else { 376 } else {
377 dta->binary = true; 377 dta->binary = true;
378 } 378 }
379 } else if (name == ENTRY_META_NEW) { 379 } else if (name == ENTRY_META_NEW) {
380 // ENTRY_META_NEW == ENTRY_META_OLD 380 // ENTRY_META_NEW == ENTRY_META_OLD
381 if (!extractMeta(cur, &dta->meta)) 381 if (!extractMeta(cur, &dta->meta))
382 return false; 382 return false;
383 } else { 383 } else {
384 printDebug(string("Serializer::extractEntry(): invalid: ") 384 printDebug(string("Serializer::extractEntry(): invalid: ")
385 + name.latin1()); 385 + name.latin1());
386 } 386 }
387 } 387 }
388 dta->lockStat = defaultLockStat; 388 dta->lockStat = defaultLockStat;
389 return true; 389 return true;
390} 390}
391 391
392bool Serializer::extractMeta(const QDomNode &n, 392bool Serializer::extractMeta(const QDomNode &n,
393 PwMMetaData *dta) 393 PwMMetaData *dta)
394{ 394{
395 QDomNode cur(n.firstChild()); 395 QDomNode cur(n.firstChild());
396 QString name, val; 396 QString name, val;
397 while (!cur.isNull()) { 397 while (!cur.isNull()) {
398 name = cur.nodeName(); 398 name = cur.nodeName();
399 val = cur.toElement().text(); 399 val = cur.toElement().text();
400 if (val == "") { 400 if (val == "") {
401 cur = cur.nextSibling(); 401 cur = cur.nextSibling();
402 continue; 402 continue;
403 } 403 }
404#ifndef PWM_EMBEDDED 404#ifndef PWM_EMBEDDED
405 if (name == META_CREATE_DATE) { 405 if (name == META_CREATE_DATE) {
406 dta->create = QDateTime::fromString(val, Qt::ISODate); 406 dta->create = QDateTime::fromString(val, Qt::ISODate);
407 } else if (name == META_VALID_DATE) { 407 } else if (name == META_VALID_DATE) {
408 dta->valid = QDateTime::fromString(val, Qt::ISODate); 408 dta->valid = QDateTime::fromString(val, Qt::ISODate);
409 } else if (name == META_EXPIRE_DATE) { 409 } else if (name == META_EXPIRE_DATE) {
410 dta->expire = QDateTime::fromString(val, Qt::ISODate); 410 dta->expire = QDateTime::fromString(val, Qt::ISODate);
411 } else if (name == META_UPDATE_DATE) { 411 } else if (name == META_UPDATE_DATE) {
412 dta->update = QDateTime::fromString(val, Qt::ISODate); 412 dta->update = QDateTime::fromString(val, Qt::ISODate);
413 } else if (name == META_UPDATE_INT) { 413 } else if (name == META_UPDATE_INT) {
414 dta->updateInt = strtoul(val.latin1(), 0, 10); 414 dta->updateInt = strtoul(val.latin1(), 0, 10);
415 } else if (name == META_UNIQUEID) { 415 } else if (name == META_UNIQUEID) {
416 dta->uniqueid = unescapeEntryData(val).latin1(); 416 dta->uniqueid = unescapeEntryData(val).latin1();
417 } else { 417 } else {
418 printDebug(string("extractMeta(): invalid: ") 418 printDebug(string("extractMeta(): invalid: ")
419 + name.latin1()); 419 + name.latin1());
420 } 420 }
421#else 421#else
422 422
423 423
424 bool ok = true; 424 bool ok = true;
425 425
426 if (name == META_CREATE_DATE) { 426 if (name == META_CREATE_DATE) {
427 dta->create = KGlobal::locale()->readDateTime(val, KLocale::ISODate, &ok); 427 dta->create = KGlobal::locale()->readDateTime(val, KLocale::ISODate, &ok);
428 } else if (name == META_VALID_DATE) { 428 } else if (name == META_VALID_DATE) {
429 dta->valid = KGlobal::locale()->readDateTime(val, KLocale::ISODate, &ok); 429 dta->valid = KGlobal::locale()->readDateTime(val, KLocale::ISODate, &ok);
430 } else if (name == META_EXPIRE_DATE) { 430 } else if (name == META_EXPIRE_DATE) {
431 dta->expire = KGlobal::locale()->readDateTime(val, KLocale::ISODate, &ok); 431 dta->expire = KGlobal::locale()->readDateTime(val, KLocale::ISODate, &ok);
432 } else if (name == META_UPDATE_DATE) { 432 } else if (name == META_UPDATE_DATE) {
433 dta->update = KGlobal::locale()->readDateTime(val, KLocale::ISODate, &ok); 433 dta->update = KGlobal::locale()->readDateTime(val, KLocale::ISODate, &ok);
434 } else if (name == META_UPDATE_INT) { 434 } else if (name == META_UPDATE_INT) {
435 dta->updateInt = strtoul(val.latin1(), 0, 10); 435 dta->updateInt = strtoul(val.latin1(), 0, 10);
436 } else if (name == META_UNIQUEID) { 436 } else if (name == META_UNIQUEID) {
437 dta->uniqueid = unescapeEntryData(val).latin1(); 437 dta->uniqueid = unescapeEntryData(val).latin1();
438 } else { 438 } else {
439 printDebug(string("extractMeta(): invalid: ") 439 printDebug(string("extractMeta(): invalid: ")
440 + name.latin1()); 440 + name.latin1());
441 } 441 }
442 442
443 if (ok == false) 443 if (ok == false)
444 qDebug("Serializer::extractMeta invalid date or time !!!!!!!!!!!!!"); 444 qDebug("Serializer::extractMeta invalid date or time !!!!!!!!!!!!!");
445 445
446 446
447#endif 447#endif
448 cur = cur.nextSibling(); 448 cur = cur.nextSibling();
449 } 449 }
450 return true; 450 return true;
451} 451}
452 452
453bool Serializer::checkValid() 453bool Serializer::checkValid()
454{ 454{
455 PWM_ASSERT(domDoc); 455 PWM_ASSERT(domDoc);
456 QDomElement root(domDoc->documentElement()); 456 QDomElement root(domDoc->documentElement());
457 if (root.nodeName() != ROOT_MAGIC_NEW && 457 if (root.nodeName() != ROOT_MAGIC_NEW &&
458 root.nodeName() != ROOT_MAGIC_OLD) { 458 root.nodeName() != ROOT_MAGIC_OLD) {
459 printDebug("Serializer: wrong magic"); 459 printDebug("Serializer: wrong magic");
460 return false; 460 return false;
461 } 461 }
462 if (root.attribute(VER_STR_NEW) != COMPAT_VER_NEW && 462 if (root.attribute(VER_STR_NEW) != COMPAT_VER_NEW &&
463 root.attribute(VER_STR_OLD) != COMPAT_VER_OLD) { 463 root.attribute(VER_STR_OLD) != COMPAT_VER_OLD) {
464 printDebug("Serializer: wrong version"); 464 printDebug("Serializer: wrong version");
465 return false; 465 return false;
466 } 466 }
467 return true; 467 return true;
468} 468}
469 469
470QDomElement Serializer::genNewRoot() 470QDomElement Serializer::genNewRoot()
471{ 471{
472 PWM_ASSERT(domDoc); 472 PWM_ASSERT(domDoc);
473 QDomElement root(domDoc->createElement(ROOT_MAGIC_WR)); 473 QDomElement root(domDoc->createElement(ROOT_MAGIC_WR));
474 root.setAttribute(VER_STR_WR, COMPAT_VER_WR); 474 root.setAttribute(VER_STR_WR, COMPAT_VER_WR);
475 domDoc->appendChild(root); 475 domDoc->appendChild(root);
476 return root; 476 return root;
477} 477}
478 478
479bool Serializer::addCategories(QDomElement *e, 479bool Serializer::addCategories(QDomElement *e,
480 const vector<PwMCategoryItem> &dta) 480 const vector<PwMCategoryItem> &dta)
481{ 481{
482 unsigned int numCat = dta.size(), i; 482 unsigned int numCat = dta.size(), i;
483 QString curId, curName; 483 QString curId, curName;
484 QDomElement curCat; 484 QDomElement curCat;
485 485
486 for (i = 0; i < numCat; ++i) { 486 for (i = 0; i < numCat; ++i) {
487 curId = CAT_PREFIX_WR; 487 curId = CAT_PREFIX_WR;
488 curId += tostr(i).c_str(); 488 curId += tostr(i).c_str();
489 curName = dta[i].name.c_str(); 489 curName = dta[i].name.c_str();
490 curCat = domDoc->createElement(curId); 490 curCat = domDoc->createElement(curId);
491 curCat.setAttribute(CAT_NAME_WR, curName); 491 curCat.setAttribute(CAT_NAME_WR, curName);
492 if (!addEntries(&curCat, dta[i].d)) { 492 if (!addEntries(&curCat, dta[i].d)) {
493 return false; 493 return false;
494 } 494 }
495 e->appendChild(curCat); 495 e->appendChild(curCat);
496 } 496 }
497 return true; 497 return true;
498} 498}
499 499
500bool Serializer::addEntries(QDomElement *e, 500bool Serializer::addEntries(QDomElement *e,
501 const vector<PwMDataItem> &dta) 501 const vector<PwMDataItem> &dta)
502{ 502{
503 unsigned int numEntr = dta.size(), i; 503 unsigned int numEntr = dta.size(), i;
504 QString curId; 504 QString curId;
505 QDomElement curEntr; 505 QDomElement curEntr;
506 506
507 for (i = 0; i < numEntr; ++i) { 507 for (i = 0; i < numEntr; ++i) {
508 curId = ENTRY_PREFIX_WR; 508 curId = ENTRY_PREFIX_WR;
509 curId += tostr(i).c_str(); 509 curId += tostr(i).c_str();
510 curEntr = domDoc->createElement(curId); 510 curEntr = domDoc->createElement(curId);
511 if (!writeEntry(&curEntr, dta[i])) { 511 if (!writeEntry(&curEntr, dta[i])) {
512 return false; 512 return false;
513 } 513 }
514 e->appendChild(curEntr); 514 e->appendChild(curEntr);
515 } 515 }
516 return true; 516 return true;
517} 517}
518 518
519bool Serializer::writeEntry(QDomElement *e, 519bool Serializer::writeEntry(QDomElement *e,
520 const PwMDataItem &_dta) 520 const PwMDataItem &_dta)
521{ 521{
522#if WRITE_CDATA_SEC != 0 522#if WRITE_CDATA_SEC != 0
523 # define new_text(x)domDoc->createCDATASection(x) 523 # define new_text(x)domDoc->createCDATASection(x)
524 QDomCDATASection curText; 524 QDomCDATASection curText;
525#else 525#else
526 # define new_text(x)domDoc->createTextNode(x) 526 # define new_text(x)domDoc->createTextNode(x)
527 QDomText curText; 527 QDomText curText;
528#endif 528#endif
529 529
530 QDomText plainText; 530 QDomText plainText;
531 QDomElement tag; 531 QDomElement tag;
532 532
533 // begin -- This is for compatibility with the old serializer 533 // begin -- This is for compatibility with the old serializer
534 PwMDataItem dta = _dta; 534 PwMDataItem dta = _dta;
535 if (!dta.desc.size()) 535 if (!dta.desc.size())
536 dta.desc = " "; 536 dta.desc = " ";
537 if (!dta.name.size()) 537 if (!dta.name.size())
538 dta.name = " "; 538 dta.name = " ";
539 if (!dta.pw.size()) 539 if (!dta.pw.size())
540 dta.pw = " "; 540 dta.pw = " ";
541 if (!dta.comment.size()) 541 if (!dta.comment.size())
542 dta.comment = " "; 542 dta.comment = " ";
543 if (!dta.url.size()) 543 if (!dta.url.size())
544 dta.url = " "; 544 dta.url = " ";
545 if (!dta.launcher.size()) 545 if (!dta.launcher.size())
546 dta.launcher = " "; 546 dta.launcher = " ";
547 // end -- This is for compatibility with the old serializer 547 // end -- This is for compatibility with the old serializer
548 548
549 tag = domDoc->createElement(ENTRY_DESC_WR); 549 tag = domDoc->createElement(ENTRY_DESC_WR);
550 curText = new_text(escapeEntryData(dta.desc.c_str())); 550 curText = new_text(escapeEntryData(dta.desc.c_str()));
551 tag.appendChild(curText); 551 tag.appendChild(curText);
552 e->appendChild(tag); 552 e->appendChild(tag);
553 553
554 tag = domDoc->createElement(ENTRY_NAME_WR); 554 tag = domDoc->createElement(ENTRY_NAME_WR);
555 curText = new_text(escapeEntryData(dta.name.c_str())); 555 curText = new_text(escapeEntryData(dta.name.c_str()));
556 tag.appendChild(curText); 556 tag.appendChild(curText);
557 e->appendChild(tag); 557 e->appendChild(tag);
558 558
559 tag = domDoc->createElement(ENTRY_PW_WR); 559 tag = domDoc->createElement(ENTRY_PW_WR);
560 curText = new_text(escapeEntryData(dta.pw.c_str())); 560 curText = new_text(escapeEntryData(dta.pw.c_str()));
561 tag.appendChild(curText); 561 tag.appendChild(curText);
562 e->appendChild(tag); 562 e->appendChild(tag);
563 563
564 tag = domDoc->createElement(ENTRY_COMMENT_WR); 564 tag = domDoc->createElement(ENTRY_COMMENT_WR);
565 curText = new_text(escapeEntryData(dta.comment.c_str())); 565 curText = new_text(escapeEntryData(dta.comment.c_str()));
566 tag.appendChild(curText); 566 tag.appendChild(curText);
567 e->appendChild(tag); 567 e->appendChild(tag);
568 568
569 tag = domDoc->createElement(ENTRY_URL_WR); 569 tag = domDoc->createElement(ENTRY_URL_WR);
570 curText = new_text(escapeEntryData(dta.url.c_str())); 570 curText = new_text(escapeEntryData(dta.url.c_str()));
571 tag.appendChild(curText); 571 tag.appendChild(curText);
572 e->appendChild(tag); 572 e->appendChild(tag);
573 573
574 tag = domDoc->createElement(ENTRY_LAUNCHER_WR); 574 tag = domDoc->createElement(ENTRY_LAUNCHER_WR);
575 curText = new_text(escapeEntryData(dta.launcher.c_str())); 575 curText = new_text(escapeEntryData(dta.launcher.c_str()));
576 tag.appendChild(curText); 576 tag.appendChild(curText);
577 e->appendChild(tag); 577 e->appendChild(tag);
578 578
579 tag = domDoc->createElement(ENTRY_LVP_WR); 579 tag = domDoc->createElement(ENTRY_LVP_WR);
580 plainText = domDoc->createTextNode(tostr(dta.listViewPos).c_str()); 580 plainText = domDoc->createTextNode(tostr(dta.listViewPos).c_str());
581 tag.appendChild(plainText); 581 tag.appendChild(plainText);
582 e->appendChild(tag); 582 e->appendChild(tag);
583 583
584 tag = domDoc->createElement(ENTRY_BIN_WR); 584 tag = domDoc->createElement(ENTRY_BIN_WR);
585 if (dta.binary) 585 if (dta.binary)
586 plainText = domDoc->createTextNode("1"); 586 plainText = domDoc->createTextNode("1");
587 else 587 else
588 plainText = domDoc->createTextNode("0"); 588 plainText = domDoc->createTextNode("0");
589 tag.appendChild(plainText); 589 tag.appendChild(plainText);
590 e->appendChild(tag); 590 e->appendChild(tag);
591 591
592 tag = domDoc->createElement(ENTRY_META_WR); 592 tag = domDoc->createElement(ENTRY_META_WR);
593 if (!writeMeta(&tag, dta.meta)) 593 if (!writeMeta(&tag, dta.meta))
594 return false; 594 return false;
595 e->appendChild(tag); 595 e->appendChild(tag);
596 596
597#undef new_text 597#undef new_text
598 return true; 598 return true;
599} 599}
600 600
601bool Serializer::writeMeta(QDomElement *e, 601bool Serializer::writeMeta(QDomElement *e,
602 const PwMMetaData &dta) 602 const PwMMetaData &dta)
603{ 603{
604 QDomText text; 604 QDomText text;
605 QDomElement tag; 605 QDomElement tag;
606 606
607 tag = domDoc->createElement(META_CREATE_DATE); 607 tag = domDoc->createElement(META_CREATE_DATE);
608#ifndef PWM_EMBEDDED 608#ifndef PWM_EMBEDDED
609 text = domDoc->createTextNode(dta.create.toString(Qt::ISODate)); 609 text = domDoc->createTextNode(dta.create.toString(Qt::ISODate));
610#else 610#else
611 text = domDoc->createTextNode(KGlobal::locale()->formatDateTime(dta.create, KLocale::ISODate)); 611 text = domDoc->createTextNode(KGlobal::locale()->formatDateTime(dta.create, KLocale::ISODate));
612#endif 612#endif
613 tag.appendChild(text); 613 tag.appendChild(text);
614 e->appendChild(tag); 614 e->appendChild(tag);
615 615
616 tag = domDoc->createElement(META_VALID_DATE); 616 tag = domDoc->createElement(META_VALID_DATE);
617#ifndef PWM_EMBEDDED 617#ifndef PWM_EMBEDDED
618 text = domDoc->createTextNode(dta.valid.toString(Qt::ISODate)); 618 text = domDoc->createTextNode(dta.valid.toString(Qt::ISODate));
619#else 619#else
620 text = domDoc->createTextNode(KGlobal::locale()->formatDateTime(dta.valid, KLocale::ISODate)); 620 text = domDoc->createTextNode(KGlobal::locale()->formatDateTime(dta.valid, KLocale::ISODate));
621#endif 621#endif
622 tag.appendChild(text); 622 tag.appendChild(text);
623 e->appendChild(tag); 623 e->appendChild(tag);
624 624
625 tag = domDoc->createElement(META_EXPIRE_DATE); 625 tag = domDoc->createElement(META_EXPIRE_DATE);
626#ifndef PWM_EMBEDDED 626#ifndef PWM_EMBEDDED
627 text = domDoc->createTextNode(dta.expire.toString(Qt::ISODate)); 627 text = domDoc->createTextNode(dta.expire.toString(Qt::ISODate));
628#else 628#else
629 text = domDoc->createTextNode(KGlobal::locale()->formatDateTime(dta.expire, KLocale::ISODate)); 629 text = domDoc->createTextNode(KGlobal::locale()->formatDateTime(dta.expire, KLocale::ISODate));
630#endif 630#endif
631 tag.appendChild(text); 631 tag.appendChild(text);
632 e->appendChild(tag); 632 e->appendChild(tag);
633 633
634 tag = domDoc->createElement(META_UPDATE_DATE); 634 tag = domDoc->createElement(META_UPDATE_DATE);
635#ifndef PWM_EMBEDDED 635#ifndef PWM_EMBEDDED
636 text = domDoc->createTextNode(dta.update.toString(Qt::ISODate)); 636 text = domDoc->createTextNode(dta.update.toString(Qt::ISODate));
637#else 637#else
638 text = domDoc->createTextNode(KGlobal::locale()->formatDateTime(dta.update, KLocale::ISODate)); 638 text = domDoc->createTextNode(KGlobal::locale()->formatDateTime(dta.update, KLocale::ISODate));
639#endif 639#endif
640 tag.appendChild(text); 640 tag.appendChild(text);
641 e->appendChild(tag); 641 e->appendChild(tag);
642 642
643 tag = domDoc->createElement(META_UPDATE_INT); 643 tag = domDoc->createElement(META_UPDATE_INT);
644 text = domDoc->createTextNode(tostr(dta.updateInt).c_str()); 644 text = domDoc->createTextNode(tostr(dta.updateInt).c_str());
645 tag.appendChild(text); 645 tag.appendChild(text);
646 e->appendChild(tag); 646 e->appendChild(tag);
647 647
648 tag = domDoc->createElement(META_UNIQUEID); 648 tag = domDoc->createElement(META_UNIQUEID);
649 text = domDoc->createTextNode(escapeEntryData(dta.uniqueid)); 649 text = domDoc->createTextNode(escapeEntryData(dta.uniqueid.c_str()));
650 tag.appendChild(text); 650 tag.appendChild(text);
651 e->appendChild(tag); 651 e->appendChild(tag);
652 652
653#undef new_text 653#undef new_text
654 return true; 654 return true;
655} 655}
656 656
657QString Serializer::escapeEntryData(QString dta) 657QString Serializer::escapeEntryData(QString dta)
658{ 658{
659#ifndef PWM_EMBEDDED 659#ifndef PWM_EMBEDDED
660 dta.replace('\n', "$>--endl--<$"); 660 dta.replace('\n', "$>--endl--<$");
661 dta.replace("]]>", "||>"); 661 dta.replace("]]>", "||>");
662#else 662#else
663 dta.replace(QRegExp("\n"), "$>--endl--<$"); 663 dta.replace(QRegExp("\n"), "$>--endl--<$");
664 dta.replace(QRegExp("]]>"), "||>"); 664 dta.replace(QRegExp("]]>"), "||>");
665#endif 665#endif
666 return dta; 666 return dta;
667} 667}
668 668
669QString Serializer::unescapeEntryData(QString dta) 669QString Serializer::unescapeEntryData(QString dta)
670{ 670{
671#ifndef PWM_EMBEDDED 671#ifndef PWM_EMBEDDED
672 dta.replace("$>--endl--<$", "\n"); 672 dta.replace("$>--endl--<$", "\n");
673 dta.replace("||>", "]]>"); 673 dta.replace("||>", "]]>");
674#else 674#else
675 dta.replace(QRegExp("$>--endl--<$"), "\n"); 675 dta.replace(QRegExp("$>--endl--<$"), "\n");
676 dta.replace(QRegExp("||>"), "]]>"); 676 dta.replace(QRegExp("||>"), "]]>");
677#endif 677#endif
678 return dta; 678 return dta;
679} 679}
680 680
681 681
682//US ENH: the following methods are getting used to write/read sync entries 682//US ENH: the following methods are getting used to write/read sync entries
683/** read the syncentries in the node "n" */ 683/** read the syncentries in the node "n" */
684bool Serializer::readSyncData(const QDomNode &n, vector<PwMSyncItem> *dta) 684bool Serializer::readSyncData(const QDomNode &n, vector<PwMSyncItem> *dta)
685{ 685{
686 QDomNodeList nl(n.childNodes()); 686 QDomNodeList nl(n.childNodes());
687 QDomNode cur; 687 QDomNode cur;
688 688
689 QString devicename, val; 689 QString devicename, val;
690 unsigned int numSync = nl.count(), i; 690 unsigned int numSync = nl.count(), i;
691 PwMSyncItem curSync; 691 PwMSyncItem curSync;
692 bool ok = true; 692 bool ok = true;
693 693
694 if (!numSync) { 694 if (!numSync) {
695 //no sync entries is a possible result 695 //no sync entries is a possible result
696 printDebug("Serializer::readSyncData(): empty"); 696 printDebug("Serializer::readSyncData(): empty");
697 return true; 697 return true;
698 } 698 }
699 for (i = 0; i < numSync; ++i) { 699 for (i = 0; i < numSync; ++i) {
700 cur = nl.item(i); 700 cur = nl.item(i);
701 if (cur.nodeName().left(1) == SYNC_TARGET_PREFIX) { 701 if (cur.nodeName().left(1) == SYNC_TARGET_PREFIX) {
702 devicename = cur.toElement().attribute(SYNC_TARGET_NAME); 702 devicename = cur.toElement().attribute(SYNC_TARGET_NAME);
703 val = cur.toElement().text(); 703 val = cur.toElement().text();
704 704
705 if ((val == "") || (devicename == QString::null)) { 705 if ((val == "") || (devicename == QString::null)) {
706 printDebug("Serializer::readSyncData(): empty synctarget name or syncdate"); 706 printDebug("Serializer::readSyncData(): empty synctarget name or syncdate");
707 continue; 707 continue;
708 } 708 }
709 709
710 curSync.syncName = devicename; 710 curSync.syncName = devicename;
711#ifndef PWM_EMBEDDED 711#ifndef PWM_EMBEDDED
712 curSync.lastSyncDate = QDateTime::fromString(val, Qt::ISODate); 712 curSync.lastSyncDate = QDateTime::fromString(val, Qt::ISODate);
713#else 713#else
714 curSync.lastSyncDate = KGlobal::locale()->readDateTime(val, KLocale::ISODate, &ok); 714 curSync.lastSyncDate = KGlobal::locale()->readDateTime(val, KLocale::ISODate, &ok);
715 if (ok == false) 715 if (ok == false)
716 qDebug("Serializer::readSyncData(): could not parse syncdate:%s",val.latin1()); 716 qDebug("Serializer::readSyncData(): could not parse syncdate:%s",val.latin1());
717 717
718#endif 718#endif
719 dta->push_back(curSync); 719 dta->push_back(curSync);
720 } 720 }
721 } 721 }
722 return true; 722 return true;
723 723
724} 724}
725 725
726 726
727 727
728bool Serializer::addSyncData(QDomElement *e, 728bool Serializer::addSyncData(QDomElement *e,
729 const vector<PwMSyncItem> &dta) 729 const vector<PwMSyncItem> &dta)
730{ 730{
731 unsigned int numSync = dta.size(), i; 731 unsigned int numSync = dta.size(), i;
732 QString curId, curDeviceName; 732 QString curId, curDeviceName;
733 QDomElement curSync, curSyncDate; 733 QDomElement curSync, curSyncDate;
734 QDomText text; 734 QDomText text;
735 735
736 for (i = 0; i < numSync; ++i) { 736 for (i = 0; i < numSync; ++i) {
737 curId = SYNC_TARGET_PREFIX; 737 curId = SYNC_TARGET_PREFIX;
738 curId += tostr(i).c_str(); 738 curId += tostr(i).c_str();
739 curDeviceName = dta[i].syncName.c_str(); 739 curDeviceName = dta[i].syncName.c_str();
740 curSync = domDoc->createElement(curId); 740 curSync = domDoc->createElement(curId);
741 curSync.setAttribute(SYNC_TARGET_NAME, curDeviceName); 741 curSync.setAttribute(SYNC_TARGET_NAME, curDeviceName);
742 742
743#ifndef PWM_EMBEDDED 743#ifndef PWM_EMBEDDED
744 text = domDoc->createTextNode(dta[i].lastSyncDate.toString(Qt::ISODate)); 744 text = domDoc->createTextNode(dta[i].lastSyncDate.toString(Qt::ISODate));
745#else 745#else
746 text = domDoc->createTextNode(KGlobal::locale()->formatDateTime(dta[i].lastSyncDate, KLocale::ISODate)); 746 text = domDoc->createTextNode(KGlobal::locale()->formatDateTime(dta[i].lastSyncDate, KLocale::ISODate));
747#endif 747#endif
748 curSyncDate.appendChild(text); 748 curSyncDate.appendChild(text);
749 curSync.appendChild(curSyncDate); 749 curSync.appendChild(curSyncDate);
750 750
751 e->appendChild(curSync); 751 e->appendChild(curSync);
752 752
753 } 753 }
754 return true; 754 return true;
755} 755}
756 756