author | ulf69 <ulf69> | 2004-10-13 22:15:49 (UTC) |
---|---|---|
committer | ulf69 <ulf69> | 2004-10-13 22:15:49 (UTC) |
commit | 7c2a228f94d8bcb783ce6f3527cb2daa9221217b (patch) (unidiff) | |
tree | 2c009f3dfd2d9897a53d0e02a067f3fff36d970b | |
parent | 737183a5abd7d7b02048e8a939bafd0a8e803918 (diff) | |
download | kdepimpi-7c2a228f94d8bcb783ce6f3527cb2daa9221217b.zip kdepimpi-7c2a228f94d8bcb783ce6f3527cb2daa9221217b.tar.gz kdepimpi-7c2a228f94d8bcb783ce6f3527cb2daa9221217b.tar.bz2 |
changes to make sync working
-rw-r--r-- | pwmanager/pwmanager/pwmdoc.cpp | 22 | ||||
-rw-r--r-- | pwmanager/pwmanager/pwmdoc.h | 4 |
2 files changed, 13 insertions, 13 deletions
diff --git a/pwmanager/pwmanager/pwmdoc.cpp b/pwmanager/pwmanager/pwmdoc.cpp index ab3238a..3f2f042 100644 --- a/pwmanager/pwmanager/pwmdoc.cpp +++ b/pwmanager/pwmanager/pwmdoc.cpp | |||
@@ -2290,1023 +2290,1023 @@ bool PwMDoc::goToURL(unsigned int category, unsigned int entryIndex) | |||
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 | ||
2295 | PwMerror PwMDoc::exportToText(const QString *file) | 2295 | PwMerror 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 | ||
2418 | PwMerror PwMDoc::importFromText(const QString *file, int format) | 2418 | PwMerror 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 | ||
2435 | PwMerror PwMDoc::importText_PwM(const QString *file) | 2435 | PwMerror 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 | ||
2570 | bool PwMDoc::textExtractEntry_PwM(const char *in, ssize_t in_size, string *out) | 2570 | bool 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 | ||
2585 | PwMerror PwMDoc::exportToGpasman(const QString *file) | 2585 | PwMerror 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 | ||
2662 | PwMerror PwMDoc::importFromGpasman(const QString *file) | 2662 | PwMerror 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 | ||
2703 | void PwMDoc::ensureLvp() | 2703 | void 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 | ||
2745 | QString PwMDoc::getTitle() | 2745 | QString 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 | ||
2764 | bool PwMDoc::tryDelete() | 2764 | bool 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 | } |
2780 | out_accept: | 2780 | out_accept: |
2781 | deleted = true; | 2781 | deleted = true; |
2782 | delete this; | 2782 | delete this; |
2783 | return true; | 2783 | return true; |
2784 | out_ignore: | 2784 | out_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. |
2793 | PwMerror PwMDoc::syncronize(KSyncManager* manager, PwMDoc* syncLocal , PwMDoc* syncRemote, int mode ) | 2793 | PwMerror 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 | //US 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 | 2923 | ||
2924 | //first check if we have a matching category in the local file | 2924 | //first check if we have a matching category in the local file |
2925 | const string* remotecat = syncRemote->getCategory(catRemote); | 2925 | const string* remotecat = syncRemote->getCategory(catRemote); |
2926 | //US syncRemote->insertAddressee( inRemote, false ); | 2926 | //US syncRemote->insertAddressee( inRemote, false ); |
2927 | //US syncLocal->insertAddressee( inRemote, false ); | 2927 | //US syncLocal->insertAddressee( inRemote, false ); |
2928 | syncLocal->addEntry(remotecat->c_str(), inRemote, true, false); | 2928 | syncLocal->addEntry(remotecat->c_str(), inRemote, true, false); |
2929 | 2929 | ||
2930 | ++addedPasswordsLocal; | 2930 | ++addedPasswordsLocal; |
2931 | } else { | 2931 | } else { |
2932 | // pending checkExternSyncAddressee(addresseeRSyncSharp, inR); | 2932 | // pending checkExternSyncAddressee(addresseeRSyncSharp, inR); |
2933 | syncRemote->delEntry(catRemote, indexRemote, true); | 2933 | syncRemote->delEntry(catRemote, indexRemote, true); |
2934 | //USsyncRemote->removeAddressee( inRemote ); | 2934 | //USsyncRemote->removeAddressee( inRemote ); |
2935 | ++deletedPasswordsRemote; | 2935 | ++deletedPasswordsRemote; |
2936 | } | 2936 | } |
2937 | } | 2937 | } |
2938 | 2938 | ||
2939 | ++incCounter; | 2939 | ++incCounter; |
2940 | } | 2940 | } |
2941 | 2941 | ||
2942 | 2942 | ||
2943 | er.clear(); | 2943 | er.clear(); |
2944 | QStringList el = syncLocal->getIDEntryList(); | 2944 | QStringList el = syncLocal->getIDEntryList(); |
2945 | modulo = (el.count()/10)+1; | 2945 | modulo = (el.count()/10)+1; |
2946 | 2946 | ||
2947 | manager->showProgressBar(0, i18n("Add / remove addressees"), el.count()); | 2947 | manager->showProgressBar(0, i18n("Add / remove addressees"), el.count()); |
2948 | incCounter = 0; | 2948 | incCounter = 0; |
2949 | while ( incCounter < el.count()) { | 2949 | while ( incCounter < el.count()) { |
2950 | qApp->processEvents(); | 2950 | qApp->processEvents(); |
2951 | if (manager->isProgressBarCanceled()) | 2951 | if (manager->isProgressBarCanceled()) |
2952 | return e_syncError; | 2952 | return e_syncError; |
2953 | if ( incCounter % modulo == 0 ) | 2953 | if ( incCounter % modulo == 0 ) |
2954 | manager->showProgressBar(incCounter); | 2954 | manager->showProgressBar(incCounter); |
2955 | uid = el[ incCounter ]; | 2955 | uid = el[ incCounter ]; |
2956 | 2956 | ||
2957 | inLocal = syncLocal->findEntryByID( uid, &catLocal, &indexLocal ); | 2957 | inLocal = syncLocal->findEntryByID( uid, &catLocal, &indexLocal ); |
2958 | inRemote = syncRemote->findEntryByID( uid, &catRemote, &indexRemote ); | 2958 | inRemote = syncRemote->findEntryByID( uid, &catRemote, &indexRemote ); |
2959 | PWM_ASSERT(inLocal); | 2959 | PWM_ASSERT(inLocal); |
2960 | 2960 | ||
2961 | if ( inRemote == 0 ) { | 2961 | if ( inRemote == 0 ) { |
2962 | if ( inLocal->meta.update < mLastSync && mode != 4 ) { | 2962 | if ( inLocal->meta.update < mLastSync && mode != 4 ) { |
2963 | // pending checkExternSyncAddressee(addresseeLSyncSharp, inL); | 2963 | // pending checkExternSyncAddressee(addresseeLSyncSharp, inL); |
2964 | syncLocal->delEntry(catLocal, indexLocal, true); | 2964 | syncLocal->delEntry(catLocal, indexLocal, true); |
2965 | //USsyncLocal->removeAddressee( inLocal ); | 2965 | //USsyncLocal->removeAddressee( inLocal ); |
2966 | ++deletedPasswordsLocal; | 2966 | ++deletedPasswordsLocal; |
2967 | } else { | 2967 | } else { |
2968 | if ( ! manager->mWriteBackExistingOnly ) { | 2968 | if ( ! manager->mWriteBackExistingOnly ) { |
2969 | ++addedPasswordsRemote; | 2969 | ++addedPasswordsRemote; |
2970 | inLocal->meta.update = modifiedSync; | 2970 | inLocal->meta.update = modifiedSync; |
2971 | 2971 | ||
2972 | //first check if we have a matching category in the remote file | 2972 | //first check if we have a matching category in the remote file |
2973 | const string* localcat = syncLocal->getCategory(catLocal); | 2973 | const string* localcat = syncLocal->getCategory(catLocal); |
2974 | 2974 | ||
2975 | //USsyncLocal->insertAddressee( inLocal, false ); | 2975 | //USsyncLocal->insertAddressee( inLocal, false ); |
2976 | PwMDataItem newEntry; | 2976 | PwMDataItem newEntry; |
2977 | newEntry = *inLocal; | 2977 | newEntry = *inLocal; |
2978 | inRemote = &newEntry; | 2978 | inRemote = &newEntry; |
2979 | 2979 | ||
2980 | //USsyncRemote->insertAddressee( inRemote, false ); | 2980 | //USsyncRemote->insertAddressee( inRemote, false ); |
2981 | syncRemote->addEntry(localcat->c_str(), inRemote, true, false); | 2981 | syncRemote->addEntry(localcat->c_str(), inRemote, true, false); |
2982 | 2982 | ||
2983 | } | 2983 | } |
2984 | } | 2984 | } |
2985 | 2985 | ||
2986 | } | 2986 | } |
2987 | ++incCounter; | 2987 | ++incCounter; |
2988 | } | 2988 | } |
2989 | el.clear(); | 2989 | el.clear(); |
2990 | manager->hideProgressBar(); | 2990 | manager->hideProgressBar(); |
2991 | 2991 | ||
2992 | // 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 |
2993 | 2993 | ||
2994 | mLastSync = QDateTime::currentDateTime().addSecs( 1 ); | 2994 | mLastSync = QDateTime::currentDateTime().addSecs( 1 ); |
2995 | // get rid of micro seconds | 2995 | // get rid of micro seconds |
2996 | QTime t = mLastSync.time(); | 2996 | QTime t = mLastSync.time(); |
2997 | mLastSync.setTime( QTime (t.hour (), t.minute (), t.second () ) ); | 2997 | mLastSync.setTime( QTime (t.hour (), t.minute (), t.second () ) ); |
2998 | 2998 | ||
2999 | 2999 | ||
3000 | syncItemLocal.lastSyncDate = mLastSync; | 3000 | syncItemLocal->lastSyncDate = mLastSync; |
3001 | syncItemRemote.lastSyncDate = mLastSync; | 3001 | syncItemRemote->lastSyncDate = mLastSync; |
3002 | 3002 | ||
3003 | // addresseeRSync.setRole( i18n("!Remote from: ")+mCurrentSyncName ) ; | 3003 | // addresseeRSync.setRole( i18n("!Remote from: ")+mCurrentSyncName ) ; |
3004 | // addresseeLSync.setRole(i18n("!Local from: ") + mCurrentSyncName ); | 3004 | // addresseeLSync.setRole(i18n("!Local from: ") + mCurrentSyncName ); |
3005 | 3005 | ||
3006 | syncRemote->addSyncDataEntry( syncItemRemote, false ); | 3006 | //US syncRemote->addSyncDataEntry( syncItemRemote, false ); |
3007 | syncLocal->addSyncDataEntry( syncItemLocal, false ); | 3007 | //US syncLocal->addSyncDataEntry( syncItemLocal, false ); |
3008 | QString mes; | 3008 | QString mes; |
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 ); | 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 ); |
3010 | if ( manager->mShowSyncSummary ) { | 3010 | if ( manager->mShowSyncSummary ) { |
3011 | KMessageBox::information(0, mes, i18n("PWM/Pi Synchronization") ); | 3011 | KMessageBox::information(0, mes, i18n("PWM/Pi Synchronization") ); |
3012 | } | 3012 | } |
3013 | qDebug( mes ); | 3013 | qDebug( mes ); |
3014 | return e_success; | 3014 | return e_success; |
3015 | } | 3015 | } |
3016 | 3016 | ||
3017 | 3017 | ||
3018 | int PwMDoc::takePwMDataItem( PwMDataItem* local, PwMDataItem* remote, QDateTime lastSync, int mode , bool full ) | 3018 | int PwMDoc::takePwMDataItem( PwMDataItem* local, PwMDataItem* remote, QDateTime lastSync, int mode , bool full ) |
3019 | { | 3019 | { |
3020 | // 0 equal | 3020 | // 0 equal |
3021 | // 1 take local | 3021 | // 1 take local |
3022 | // 2 take remote | 3022 | // 2 take remote |
3023 | // 3 cancel | 3023 | // 3 cancel |
3024 | QDateTime localMod = local->meta.update; | 3024 | QDateTime localMod = local->meta.update; |
3025 | QDateTime remoteMod = remote->meta.update; | 3025 | QDateTime remoteMod = remote->meta.update; |
3026 | 3026 | ||
3027 | //US QString mCurrentSyncDevice = syncManager->getCurrentSyncDevice(); | 3027 | //US QString mCurrentSyncDevice = syncManager->getCurrentSyncDevice(); |
3028 | 3028 | ||
3029 | if ( localMod == remoteMod ) | 3029 | if ( localMod == remoteMod ) |
3030 | return 0; | 3030 | return 0; |
3031 | 3031 | ||
3032 | 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() ); |
3033 | 3033 | ||
3034 | //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); |
3035 | //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() ); |
3036 | //full = true; //debug only | 3036 | //full = true; //debug only |
3037 | if ( full ) { | 3037 | if ( full ) { |
3038 | bool equ = true;//US ( (*local) == (*remote) ); | 3038 | bool equ = true;//US ( (*local) == (*remote) ); |
3039 | if ( equ ) { | 3039 | if ( equ ) { |
3040 | //qDebug("equal "); | 3040 | //qDebug("equal "); |
3041 | if ( mode < SYNC_PREF_FORCE_LOCAL ) | 3041 | if ( mode < SYNC_PREF_FORCE_LOCAL ) |
3042 | return 0; | 3042 | return 0; |
3043 | 3043 | ||
3044 | }//else //debug only | 3044 | }//else //debug only |
3045 | //qDebug("not equal %s %s ", local->summary().latin1(), remote->summary().latin1()); | 3045 | //qDebug("not equal %s %s ", local->summary().latin1(), remote->summary().latin1()); |
3046 | } | 3046 | } |
3047 | 3047 | ||
3048 | int result; | 3048 | int result; |
3049 | bool localIsNew; | 3049 | bool localIsNew; |
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() ); | 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() ); |
3051 | 3051 | ||
3052 | if ( full && mode < SYNC_PREF_NEWEST ) | 3052 | if ( full && mode < SYNC_PREF_NEWEST ) |
3053 | mode = SYNC_PREF_ASK; | 3053 | mode = SYNC_PREF_ASK; |
3054 | 3054 | ||
3055 | switch( mode ) { | 3055 | switch( mode ) { |
3056 | case SYNC_PREF_LOCAL: | 3056 | case SYNC_PREF_LOCAL: |
3057 | if ( lastSync > remoteMod ) | 3057 | if ( lastSync > remoteMod ) |
3058 | return 1; | 3058 | return 1; |
3059 | if ( lastSync > localMod ) | 3059 | if ( lastSync > localMod ) |
3060 | return 2; | 3060 | return 2; |
3061 | return 1; | 3061 | return 1; |
3062 | break; | 3062 | break; |
3063 | case SYNC_PREF_REMOTE: | 3063 | case SYNC_PREF_REMOTE: |
3064 | if ( lastSync > remoteMod ) | 3064 | if ( lastSync > remoteMod ) |
3065 | return 1; | 3065 | return 1; |
3066 | if ( lastSync > localMod ) | 3066 | if ( lastSync > localMod ) |
3067 | return 2; | 3067 | return 2; |
3068 | return 2; | 3068 | return 2; |
3069 | break; | 3069 | break; |
3070 | case SYNC_PREF_NEWEST: | 3070 | case SYNC_PREF_NEWEST: |
3071 | if ( localMod > remoteMod ) | 3071 | if ( localMod > remoteMod ) |
3072 | return 1; | 3072 | return 1; |
3073 | else | 3073 | else |
3074 | return 2; | 3074 | return 2; |
3075 | break; | 3075 | break; |
3076 | case SYNC_PREF_ASK: | 3076 | case SYNC_PREF_ASK: |
3077 | //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() ); |
3078 | if ( lastSync > remoteMod ) | 3078 | if ( lastSync > remoteMod ) |
3079 | return 1; | 3079 | return 1; |
3080 | if ( lastSync > localMod ) | 3080 | if ( lastSync > localMod ) |
3081 | return 2; | 3081 | return 2; |
3082 | localIsNew = localMod >= remoteMod; | 3082 | localIsNew = localMod >= remoteMod; |
3083 | //qDebug("conflict! ************************************** "); | 3083 | //qDebug("conflict! ************************************** "); |
3084 | { | 3084 | { |
3085 | PwMDataItemChooser acd ( *local,*remote, localIsNew , 0/*this*/ ); | 3085 | PwMDataItemChooser acd ( *local,*remote, localIsNew , 0/*this*/ ); |
3086 | result = acd.executeD(localIsNew); | 3086 | result = acd.executeD(localIsNew); |
3087 | return result; | 3087 | return result; |
3088 | } | 3088 | } |
3089 | break; | 3089 | break; |
3090 | case SYNC_PREF_FORCE_LOCAL: | 3090 | case SYNC_PREF_FORCE_LOCAL: |
3091 | return 1; | 3091 | return 1; |
3092 | break; | 3092 | break; |
3093 | case SYNC_PREF_FORCE_REMOTE: | 3093 | case SYNC_PREF_FORCE_REMOTE: |
3094 | return 2; | 3094 | return 2; |
3095 | break; | 3095 | break; |
3096 | 3096 | ||
3097 | default: | 3097 | default: |
3098 | // SYNC_PREF_TAKE_BOTH not implemented | 3098 | // SYNC_PREF_TAKE_BOTH not implemented |
3099 | break; | 3099 | break; |
3100 | } | 3100 | } |
3101 | return 0; | 3101 | return 0; |
3102 | } | 3102 | } |
3103 | 3103 | ||
3104 | 3104 | ||
3105 | 3105 | ||
3106 | 3106 | ||
3107 | //this are the overwritten callbackmethods from the syncinterface | 3107 | //this are the overwritten callbackmethods from the syncinterface |
3108 | bool PwMDoc::sync(KSyncManager* manager, QString filename, int mode) | 3108 | bool PwMDoc::sync(KSyncManager* manager, QString filename, int mode) |
3109 | { | 3109 | { |
3110 | QString mCurrentSyncDevice = manager->getCurrentSyncDevice(); | 3110 | QString mCurrentSyncDevice = manager->getCurrentSyncDevice(); |
3111 | 3111 | ||
3112 | //1) unlock local file first if necessary (ask for password) | 3112 | //1) unlock local file first if necessary (ask for password) |
3113 | if (this->isDeepLocked()) { | 3113 | if (this->isDeepLocked()) { |
3114 | PwMerror ret = this->deepLock(false); | 3114 | PwMerror ret = this->deepLock(false); |
3115 | if (ret != e_success) | 3115 | if (ret != e_success) |
3116 | return false; | 3116 | return false; |
3117 | } | 3117 | } |
3118 | 3118 | ||
3119 | //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. |
3120 | PwMDoc syncTarget(this, "synctarget"); | 3120 | PwMDoc syncTarget(this, "synctarget"); |
3121 | PwMDoc* pSyncTarget = &syncTarget; | 3121 | PwMDoc* pSyncTarget = &syncTarget; |
3122 | 3122 | ||
3123 | 3123 | ||
3124 | PwMerror err = pSyncTarget->openDoc(&filename, 1 /*== open with all entries locked*/); | 3124 | PwMerror err = pSyncTarget->openDoc(&filename, 1 /*== open with all entries locked*/); |
3125 | 3125 | ||
3126 | if (err == e_alreadyOpen) { | 3126 | if (err == e_alreadyOpen) { |
3127 | PwMDocList::listItem li; | 3127 | PwMDocList::listItem li; |
3128 | if (getOpenDocList()->find(filename.latin1(), &li)) | 3128 | if (getOpenDocList()->find(filename.latin1(), &li)) |
3129 | pSyncTarget = li.doc; | 3129 | pSyncTarget = li.doc; |
3130 | else { | 3130 | else { |
3131 | 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()); |
3132 | return false; | 3132 | return false; |
3133 | } | 3133 | } |
3134 | } | 3134 | } |
3135 | else if (err != e_success) { | 3135 | else if (err != e_success) { |
3136 | 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()); |
3137 | return false; | 3137 | return false; |
3138 | } | 3138 | } |
3139 | 3139 | ||
3140 | qDebug("PWM file loaded %s,sync mode %d",filename.latin1(), mode ); | 3140 | qDebug("PWM file loaded %s,sync mode %d",filename.latin1(), mode ); |
3141 | 3141 | ||
3142 | 3142 | ||
3143 | //3) unlock remote file first if necessary (ask for password) | 3143 | //3) unlock remote file first if necessary (ask for password) |
3144 | if (pSyncTarget->isDeepLocked()) { | 3144 | if (pSyncTarget->isDeepLocked()) { |
3145 | PwMerror ret = pSyncTarget->deepLock(false); | 3145 | PwMerror ret = pSyncTarget->deepLock(false); |
3146 | if (ret != e_success) | 3146 | if (ret != e_success) |
3147 | return false; | 3147 | return false; |
3148 | } | 3148 | } |
3149 | 3149 | ||
3150 | 3150 | ||
3151 | err = syncronize(manager, this, pSyncTarget, mode ); | 3151 | err = syncronize(manager, this, pSyncTarget, mode ); |
3152 | 3152 | ||
3153 | if (err == e_success) { | 3153 | if (err == e_success) { |
3154 | if ( manager->mWriteBackFile ){ | 3154 | if ( manager->mWriteBackFile ){ |
3155 | qDebug("Saving remote PWManager file"); | 3155 | qDebug("Saving remote PWManager file"); |
3156 | err = pSyncTarget->saveDoc(conf()->confGlobCompression()); | 3156 | err = pSyncTarget->saveDoc(conf()->confGlobCompression()); |
3157 | if (err != e_success) { | 3157 | if (err != e_success) { |
3158 | 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()); |
3159 | return false; | 3159 | return false; |
3160 | } | 3160 | } |
3161 | } | 3161 | } |
3162 | 3162 | ||
3163 | flagDirty(); | 3163 | flagDirty(); |
3164 | return true; | 3164 | return true; |
3165 | } | 3165 | } |
3166 | else { | 3166 | else { |
3167 | return false; | 3167 | return false; |
3168 | } | 3168 | } |
3169 | } | 3169 | } |
3170 | 3170 | ||
3171 | //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. |
3172 | void PwMDoc::sync_setModified() | 3172 | void PwMDoc::sync_setModified() |
3173 | { | 3173 | { |
3174 | flagDirty(); | 3174 | flagDirty(); |
3175 | } | 3175 | } |
3176 | 3176 | ||
3177 | //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. |
3178 | bool PwMDoc::sync_isModified() | 3178 | bool PwMDoc::sync_isModified() |
3179 | { | 3179 | { |
3180 | return isDirty(); | 3180 | return isDirty(); |
3181 | } | 3181 | } |
3182 | 3182 | ||
3183 | //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. |
3184 | void PwMDoc::sync_save() | 3184 | void PwMDoc::sync_save() |
3185 | { | 3185 | { |
3186 | saveDoc(conf()->confGlobCompression()); | 3186 | saveDoc(conf()->confGlobCompression()); |
3187 | } | 3187 | } |
3188 | #endif | 3188 | #endif |
3189 | 3189 | ||
3190 | 3190 | ||
3191 | bool PwMDoc::findSyncData(const QString &syncname, unsigned int *index) | 3191 | bool PwMDoc::findSyncData(const QString &syncname, unsigned int *index) |
3192 | { | 3192 | { |
3193 | vector<PwMSyncItem>::iterator i = dti.syncDta.begin(), | 3193 | vector<PwMSyncItem>::iterator i = dti.syncDta.begin(), |
3194 | end = dti.syncDta.end(); | 3194 | end = dti.syncDta.end(); |
3195 | 3195 | ||
3196 | while (i != end) { | 3196 | while (i != end) { |
3197 | if ((*i).syncName == syncname.latin1()) { | 3197 | if ((*i).syncName == syncname.latin1()) { |
3198 | if (index) { | 3198 | if (index) { |
3199 | *index = i - dti.syncDta.begin(); | 3199 | *index = i - dti.syncDta.begin(); |
3200 | } | 3200 | } |
3201 | return true; | 3201 | return true; |
3202 | } | 3202 | } |
3203 | ++i; | 3203 | ++i; |
3204 | } | 3204 | } |
3205 | return false; | 3205 | return false; |
3206 | }; | 3206 | }; |
3207 | 3207 | ||
3208 | /** add new syncdataentry */ | 3208 | /** add new syncdataentry */ |
3209 | PwMerror PwMDoc::addSyncDataEntry(PwMSyncItem *d, bool dontFlagDirty) | 3209 | PwMerror PwMDoc::addSyncDataEntry(PwMSyncItem *d, bool dontFlagDirty) |
3210 | { | 3210 | { |
3211 | PWM_ASSERT(d); | 3211 | PWM_ASSERT(d); |
3212 | 3212 | ||
3213 | if (isDeepLocked()) { | 3213 | if (isDeepLocked()) { |
3214 | PwMerror ret; | 3214 | PwMerror ret; |
3215 | ret = deepLock(false); | 3215 | ret = deepLock(false); |
3216 | if (ret != e_success) | 3216 | if (ret != e_success) |
3217 | return e_lock; | 3217 | return e_lock; |
3218 | } | 3218 | } |
3219 | unsigned int index; | 3219 | unsigned int index; |
3220 | 3220 | ||
3221 | const QString tmp = d->syncName.c_str(); | 3221 | const QString tmp = d->syncName.c_str(); |
3222 | bool exists = findSyncData(d->syncName.c_str(), &index); | 3222 | bool exists = findSyncData(d->syncName.c_str(), &index); |
3223 | 3223 | ||
3224 | if (exists == true) { | 3224 | if (exists == true) { |
3225 | // DOH! We found this entry. | 3225 | // DOH! We found this entry. |
3226 | return e_entryExists; | 3226 | return e_entryExists; |
3227 | } | 3227 | } |
3228 | 3228 | ||
3229 | dti.syncDta.push_back(*d); | 3229 | dti.syncDta.push_back(*d); |
3230 | 3230 | ||
3231 | if (!dontFlagDirty) | 3231 | if (!dontFlagDirty) |
3232 | flagDirty(); | 3232 | flagDirty(); |
3233 | return e_success; | 3233 | return e_success; |
3234 | } | 3234 | } |
3235 | 3235 | ||
3236 | 3236 | ||
3237 | 3237 | ||
3238 | /** delete syncdata entry */ | 3238 | /** delete syncdata entry */ |
3239 | bool PwMDoc::delSyncDataEntry(unsigned int index, bool dontFlagDirty) | 3239 | bool PwMDoc::delSyncDataEntry(unsigned int index, bool dontFlagDirty) |
3240 | { | 3240 | { |
3241 | if (isDeepLocked()) | 3241 | if (isDeepLocked()) |
3242 | return false; | 3242 | return false; |
3243 | if (index > dti.syncDta.size() - 1) | 3243 | if (index > dti.syncDta.size() - 1) |
3244 | return false; | 3244 | return false; |
3245 | 3245 | ||
3246 | // delete entry | 3246 | // delete entry |
3247 | dti.syncDta.erase(dti.syncDta.begin() + index); | 3247 | dti.syncDta.erase(dti.syncDta.begin() + index); |
3248 | 3248 | ||
3249 | if (!dontFlagDirty) | 3249 | if (!dontFlagDirty) |
3250 | flagDirty(); | 3250 | flagDirty(); |
3251 | return true; | 3251 | return true; |
3252 | } | 3252 | } |
3253 | 3253 | ||
3254 | 3254 | ||
3255 | PwMDataItem* PwMDoc::findEntryByID(const QString &uid, unsigned int *category, unsigned int *index) | 3255 | PwMDataItem* PwMDoc::findEntryByID(const QString &uid, unsigned int *category, unsigned int *index) |
3256 | { | 3256 | { |
3257 | vector<PwMCategoryItem>::iterator catcounter = dti.dta.begin(), | 3257 | vector<PwMCategoryItem>::iterator catcounter = dti.dta.begin(), |
3258 | catend = dti.dta.end(); | 3258 | catend = dti.dta.end(); |
3259 | 3259 | ||
3260 | vector<PwMDataItem>::iterator entrBegin, entrEnd, entrI; | 3260 | vector<PwMDataItem>::iterator entrBegin, entrEnd, entrI; |
3261 | 3261 | ||
3262 | while (catcounter != catend) { | 3262 | while (catcounter != catend) { |
3263 | entrBegin = catcounter->d.begin(); | 3263 | entrBegin = catcounter->d.begin(); |
3264 | entrEnd = catcounter->d.end(); | 3264 | entrEnd = catcounter->d.end(); |
3265 | entrI = entrBegin; | 3265 | entrI = entrBegin; |
3266 | while (entrI != entrEnd) { | 3266 | while (entrI != entrEnd) { |
3267 | if ((*entrI).meta.uniqueid == uid.latin1()) { | 3267 | if ((*entrI).meta.uniqueid == uid.latin1()) { |
3268 | if (category) | 3268 | if (category) |
3269 | *category = catcounter - dti.dta.begin(); | 3269 | *category = catcounter - dti.dta.begin(); |
3270 | if (index) | 3270 | if (index) |
3271 | *index = entrI - entrBegin; | 3271 | *index = entrI - entrBegin; |
3272 | 3272 | ||
3273 | return &(*entrI); | 3273 | return &(*entrI); |
3274 | } | 3274 | } |
3275 | ++entrI; | 3275 | ++entrI; |
3276 | } | 3276 | } |
3277 | ++catcounter; | 3277 | ++catcounter; |
3278 | } | 3278 | } |
3279 | 3279 | ||
3280 | return 0; | 3280 | return 0; |
3281 | } | 3281 | } |
3282 | 3282 | ||
3283 | QStringList PwMDoc::getIDEntryList() | 3283 | QStringList PwMDoc::getIDEntryList() |
3284 | { | 3284 | { |
3285 | QStringList results; | 3285 | QStringList results; |
3286 | 3286 | ||
3287 | vector<PwMCategoryItem>::iterator catcounter = dti.dta.begin(), | 3287 | vector<PwMCategoryItem>::iterator catcounter = dti.dta.begin(), |
3288 | catend = dti.dta.end(); | 3288 | catend = dti.dta.end(); |
3289 | 3289 | ||
3290 | vector<PwMDataItem>::iterator entrBegin, entrEnd, entrI; | 3290 | vector<PwMDataItem>::iterator entrBegin, entrEnd, entrI; |
3291 | 3291 | ||
3292 | while (catcounter != catend) { | 3292 | while (catcounter != catend) { |
3293 | entrBegin = catcounter->d.begin(); | 3293 | entrBegin = catcounter->d.begin(); |
3294 | entrEnd = catcounter->d.end(); | 3294 | entrEnd = catcounter->d.end(); |
3295 | entrI = entrBegin; | 3295 | entrI = entrBegin; |
3296 | while (entrI != entrEnd) { | 3296 | while (entrI != entrEnd) { |
3297 | results.append( (*entrI).meta.uniqueid.c_str() ); | 3297 | results.append( (*entrI).meta.uniqueid.c_str() ); |
3298 | ++entrI; | 3298 | ++entrI; |
3299 | } | 3299 | } |
3300 | ++catcounter; | 3300 | ++catcounter; |
3301 | } | 3301 | } |
3302 | 3302 | ||
3303 | return results; | 3303 | return results; |
3304 | } | 3304 | } |
3305 | 3305 | ||
3306 | 3306 | ||
3307 | 3307 | ||
3308 | 3308 | ||
3309 | 3309 | ||
3310 | #ifndef PWM_EMBEDDED | 3310 | #ifndef PWM_EMBEDDED |
3311 | #include "pwmdoc.moc" | 3311 | #include "pwmdoc.moc" |
3312 | #endif | 3312 | #endif |
diff --git a/pwmanager/pwmanager/pwmdoc.h b/pwmanager/pwmanager/pwmdoc.h index ddab7f3..2e9547e 100644 --- a/pwmanager/pwmanager/pwmdoc.h +++ b/pwmanager/pwmanager/pwmdoc.h | |||
@@ -282,525 +282,525 @@ class dta_lvp_greater | |||
282 | public: | 282 | public: |
283 | bool operator() (const pair<unsigned int, unsigned int> &d1, | 283 | bool operator() (const pair<unsigned int, unsigned int> &d1, |
284 | const pair<unsigned int, unsigned int> &d2) | 284 | const pair<unsigned int, unsigned int> &d2) |
285 | { | 285 | { |
286 | return d1.second > d2.second; | 286 | return d1.second > d2.second; |
287 | } | 287 | } |
288 | }; | 288 | }; |
289 | 289 | ||
290 | /** list of PwMDoc documents and it's IDs */ | 290 | /** list of PwMDoc documents and it's IDs */ |
291 | class PwMDocList | 291 | class PwMDocList |
292 | { | 292 | { |
293 | public: | 293 | public: |
294 | struct listItem | 294 | struct listItem |
295 | { | 295 | { |
296 | /** document filename (known as ID, here) */ | 296 | /** document filename (known as ID, here) */ |
297 | string docId; | 297 | string docId; |
298 | /** pointer to the document class */ | 298 | /** pointer to the document class */ |
299 | PwMDoc *doc; | 299 | PwMDoc *doc; |
300 | }; | 300 | }; |
301 | 301 | ||
302 | PwMDocList() {} | 302 | PwMDocList() {} |
303 | 303 | ||
304 | /** add a new item to the list */ | 304 | /** add a new item to the list */ |
305 | void add(PwMDoc *doc, const string &id); | 305 | void add(PwMDoc *doc, const string &id); |
306 | /** changes the contents of an existing item */ | 306 | /** changes the contents of an existing item */ |
307 | void edit(PwMDoc *doc, const string &newId); | 307 | void edit(PwMDoc *doc, const string &newId); |
308 | /** remove the given item */ | 308 | /** remove the given item */ |
309 | void del(PwMDoc *doc); | 309 | void del(PwMDoc *doc); |
310 | /** get the item at index */ | 310 | /** get the item at index */ |
311 | listItem getAt(int index) | 311 | listItem getAt(int index) |
312 | { return docList[index]; } | 312 | { return docList[index]; } |
313 | /** find an entry with this id */ | 313 | /** find an entry with this id */ |
314 | bool find(const string &id, listItem *ret = 0); | 314 | bool find(const string &id, listItem *ret = 0); |
315 | /** returns a copy of the list */ | 315 | /** returns a copy of the list */ |
316 | const vector<listItem>* getList() const | 316 | const vector<listItem>* getList() const |
317 | { return &docList; } | 317 | { return &docList; } |
318 | 318 | ||
319 | 319 | ||
320 | /** returns a new unique number to extend the name of | 320 | /** returns a new unique number to extend the name of |
321 | * an unnamed document. | 321 | * an unnamed document. |
322 | */ | 322 | */ |
323 | static unsigned int getNewUnnamedNumber() | 323 | static unsigned int getNewUnnamedNumber() |
324 | { return unnamedDocCnt++; } | 324 | { return unnamedDocCnt++; } |
325 | 325 | ||
326 | protected: | 326 | protected: |
327 | /* 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? |
328 | * So I decided to actually use a vector. | 328 | * So I decided to actually use a vector. |
329 | */ | 329 | */ |
330 | vector<listItem> docList; | 330 | vector<listItem> docList; |
331 | /** 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 |
332 | * documents. It is incremented on every request. So it's | 332 | * documents. It is incremented on every request. So it's |
333 | * theoretically possible to overflow it, but... :) | 333 | * theoretically possible to overflow it, but... :) |
334 | */ | 334 | */ |
335 | static unsigned int unnamedDocCnt; | 335 | static unsigned int unnamedDocCnt; |
336 | }; | 336 | }; |
337 | 337 | ||
338 | /** implements timers for the document */ | 338 | /** implements timers for the document */ |
339 | class DocTimer : public QObject | 339 | class DocTimer : public QObject |
340 | { | 340 | { |
341 | Q_OBJECT | 341 | Q_OBJECT |
342 | public: | 342 | public: |
343 | enum TimerIDs | 343 | enum TimerIDs |
344 | { | 344 | { |
345 | id_mpwTimer, | 345 | id_mpwTimer, |
346 | id_autoLockTimer, | 346 | id_autoLockTimer, |
347 | id_metaCheckTimer | 347 | id_metaCheckTimer |
348 | }; | 348 | }; |
349 | 349 | ||
350 | public: | 350 | public: |
351 | DocTimer(PwMDoc *_doc); | 351 | DocTimer(PwMDoc *_doc); |
352 | ~DocTimer(); | 352 | ~DocTimer(); |
353 | 353 | ||
354 | /** start the timer */ | 354 | /** start the timer */ |
355 | void start(TimerIDs timer); | 355 | void start(TimerIDs timer); |
356 | /** stop the timer */ | 356 | /** stop the timer */ |
357 | void stop(TimerIDs timer); | 357 | void stop(TimerIDs timer); |
358 | /** get the lock for a timer. | 358 | /** get the lock for a timer. |
359 | * This lock is a recursive lock. When a lock is | 359 | * This lock is a recursive lock. When a lock is |
360 | * held, the timer will be stopped and timeout is | 360 | * held, the timer will be stopped and timeout is |
361 | * guaranteed to not happen | 361 | * guaranteed to not happen |
362 | */ | 362 | */ |
363 | void getLock(TimerIDs timer); | 363 | void getLock(TimerIDs timer); |
364 | /** put a recursive timer lock */ | 364 | /** put a recursive timer lock */ |
365 | void putLock(TimerIDs timer); | 365 | void putLock(TimerIDs timer); |
366 | 366 | ||
367 | protected slots: | 367 | protected slots: |
368 | /** timeout slot for the mpw timer */ | 368 | /** timeout slot for the mpw timer */ |
369 | void mpwTimeout(); | 369 | void mpwTimeout(); |
370 | /** timeout slot for the autoLock timer */ | 370 | /** timeout slot for the autoLock timer */ |
371 | void autoLockTimeout(); | 371 | void autoLockTimeout(); |
372 | /** timeout slot for the metaCheck timer */ | 372 | /** timeout slot for the metaCheck timer */ |
373 | void metaCheckTimeout(); | 373 | void metaCheckTimeout(); |
374 | 374 | ||
375 | protected: | 375 | protected: |
376 | /** pointer to the document associated with this timer. */ | 376 | /** pointer to the document associated with this timer. */ |
377 | PwMDoc *doc; | 377 | PwMDoc *doc; |
378 | /** timer object for mpw timer */ | 378 | /** timer object for mpw timer */ |
379 | QTimer *mpwTimer; | 379 | QTimer *mpwTimer; |
380 | /** timer object for the autoLock timer */ | 380 | /** timer object for the autoLock timer */ |
381 | QTimer *autoLockTimer; | 381 | QTimer *autoLockTimer; |
382 | /** timer object for the metaCheck timer */ | 382 | /** timer object for the metaCheck timer */ |
383 | QTimer *metaCheckTimer; | 383 | QTimer *metaCheckTimer; |
384 | /** lock counter for the mpw timer */ | 384 | /** lock counter for the mpw timer */ |
385 | unsigned int mpwLock; | 385 | unsigned int mpwLock; |
386 | /** lock counter for the autoLock timer */ | 386 | /** lock counter for the autoLock timer */ |
387 | unsigned int autoLockLock; | 387 | unsigned int autoLockLock; |
388 | /** lock counter for the metaCheck timer */ | 388 | /** lock counter for the metaCheck timer */ |
389 | unsigned int metaCheckLock; | 389 | unsigned int metaCheckLock; |
390 | }; | 390 | }; |
391 | 391 | ||
392 | /** Document class for PwM */ | 392 | /** Document class for PwM */ |
393 | //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. |
394 | // But PwMDoc is handling the sync by itself. | 394 | // But PwMDoc is handling the sync by itself. |
395 | class PwMDoc : public PwMDocUi, public KSyncInterface | 395 | class PwMDoc : public PwMDocUi, public KSyncInterface |
396 | 396 | ||
397 | { | 397 | { |
398 | Q_OBJECT | 398 | Q_OBJECT |
399 | friend class DocTimer; | 399 | friend class DocTimer; |
400 | 400 | ||
401 | public: | 401 | public: |
402 | /** construtor */ | 402 | /** construtor */ |
403 | PwMDoc(QObject* parent = 0, const char *name = 0); | 403 | PwMDoc(QObject* parent = 0, const char *name = 0); |
404 | /** destructor */ | 404 | /** destructor */ |
405 | ~PwMDoc(); | 405 | ~PwMDoc(); |
406 | 406 | ||
407 | /** returns a pointer to a list of all open documents */ | 407 | /** returns a pointer to a list of all open documents */ |
408 | static PwMDocList* getOpenDocList() | 408 | static PwMDocList* getOpenDocList() |
409 | { return &openDocList; } | 409 | { return &openDocList; } |
410 | 410 | ||
411 | /** flag document dirty. dta changed */ | 411 | /** flag document dirty. dta changed */ |
412 | void flagDirty() | 412 | void flagDirty() |
413 | { | 413 | { |
414 | setDocStatFlag(DOC_STAT_DISK_DIRTY); | 414 | setDocStatFlag(DOC_STAT_DISK_DIRTY); |
415 | emitDataChanged(this); | 415 | emitDataChanged(this); |
416 | } | 416 | } |
417 | /** modified? */ | 417 | /** modified? */ |
418 | bool isDirty() | 418 | bool isDirty() |
419 | { return getDocStatFlag(DOC_STAT_DISK_DIRTY); } | 419 | { return getDocStatFlag(DOC_STAT_DISK_DIRTY); } |
420 | /** save document to disk */ | 420 | /** save document to disk */ |
421 | PwMerror saveDoc(char compress, const QString *file = 0); | 421 | PwMerror saveDoc(char compress, const QString *file = 0); |
422 | /** read document from file. | 422 | /** read document from file. |
423 | * "openLocked is must be set to either of these values: | 423 | * "openLocked is must be set to either of these values: |
424 | * 0 == open with all entries unlocked | 424 | * 0 == open with all entries unlocked |
425 | * 1 == open with all entries locked | 425 | * 1 == open with all entries locked |
426 | * 2 == open deep-locked | 426 | * 2 == open deep-locked |
427 | */ | 427 | */ |
428 | PwMerror openDoc(const QString *file, int openLocked); | 428 | PwMerror openDoc(const QString *file, int openLocked); |
429 | /** export document to ascii-textfile */ | 429 | /** export document to ascii-textfile */ |
430 | PwMerror exportToText(const QString *file); | 430 | PwMerror exportToText(const QString *file); |
431 | /** export document to gpasman / kpasman file */ | 431 | /** export document to gpasman / kpasman file */ |
432 | PwMerror exportToGpasman(const QString *file); | 432 | PwMerror exportToGpasman(const QString *file); |
433 | /** import document from ascii-textfile */ | 433 | /** import document from ascii-textfile */ |
434 | PwMerror importFromText(const QString *file, int format = -1); | 434 | PwMerror importFromText(const QString *file, int format = -1); |
435 | /** import document from gpasman / kpasman file */ | 435 | /** import document from gpasman / kpasman file */ |
436 | PwMerror importFromGpasman(const QString *file); | 436 | PwMerror importFromGpasman(const QString *file); |
437 | /** add new entry */ | 437 | /** add new entry */ |
438 | PwMerror addEntry(const QString &category, PwMDataItem *d, | 438 | PwMerror addEntry(const QString &category, PwMDataItem *d, |
439 | bool dontFlagDirty = false, bool updateMeta = true); | 439 | bool dontFlagDirty = false, bool updateMeta = true); |
440 | /** add new category. This function doesn't flag the document dirty! */ | 440 | /** add new category. This function doesn't flag the document dirty! */ |
441 | PwMerror addCategory(const QString &category, unsigned int *categoryIndex, | 441 | PwMerror addCategory(const QString &category, unsigned int *categoryIndex, |
442 | bool checkIfExist = true); | 442 | bool checkIfExist = true); |
443 | /** rename an existing category */ | 443 | /** rename an existing category */ |
444 | bool renameCategory(const QString &category, const QString &newName); | 444 | bool renameCategory(const QString &category, const QString &newName); |
445 | /** rename an existing category */ | 445 | /** rename an existing category */ |
446 | bool renameCategory(unsigned int category, const QString &newName, | 446 | bool renameCategory(unsigned int category, const QString &newName, |
447 | bool dontFlagDirty = false); | 447 | bool dontFlagDirty = false); |
448 | /** delete an existing category */ | 448 | /** delete an existing category */ |
449 | bool delCategory(const QString &category); | 449 | bool delCategory(const QString &category); |
450 | /** delete an existing category */ | 450 | /** delete an existing category */ |
451 | bool delCategory(unsigned int category, bool dontFlagDirty = false); | 451 | bool delCategory(unsigned int category, bool dontFlagDirty = false); |
452 | /** returns a list of all category-names */ | 452 | /** returns a list of all category-names */ |
453 | void getCategoryList(vector<string> *list); | 453 | void getCategoryList(vector<string> *list); |
454 | /** returns a list of all category-names */ | 454 | /** returns a list of all category-names */ |
455 | void getCategoryList(QStringList *list); | 455 | void getCategoryList(QStringList *list); |
456 | /** returns a list of all entry-descs in the given category */ | 456 | /** returns a list of all entry-descs in the given category */ |
457 | void getEntryList(const QString &category, QStringList *list); | 457 | void getEntryList(const QString &category, QStringList *list); |
458 | /** returns a list of all entry-descs in the given category */ | 458 | /** returns a list of all entry-descs in the given category */ |
459 | void getEntryList(const QString &category, vector<string> *list); | 459 | void getEntryList(const QString &category, vector<string> *list); |
460 | /** returns a list of all entry-descs in the given category */ | 460 | /** returns a list of all entry-descs in the given category */ |
461 | void getEntryList(unsigned int category, vector<string> *list); | 461 | void getEntryList(unsigned int category, vector<string> *list); |
462 | /** returns a list of all entry-descs in the given category */ | 462 | /** returns a list of all entry-descs in the given category */ |
463 | void getEntryList(unsigned int category, QStringList *list); | 463 | void getEntryList(unsigned int category, QStringList *list); |
464 | /** delete entry */ | 464 | /** delete entry */ |
465 | bool delEntry(const QString &category, unsigned int index, bool dontFlagDirty = false); | 465 | bool delEntry(const QString &category, unsigned int index, bool dontFlagDirty = false); |
466 | /** delete entry */ | 466 | /** delete entry */ |
467 | bool delEntry(unsigned int category, unsigned int index, bool dontFlagDirty = false); | 467 | bool delEntry(unsigned int category, unsigned int index, bool dontFlagDirty = false); |
468 | /** edit entry */ | 468 | /** edit entry */ |
469 | bool editEntry(const QString &oldCategory, const QString &newCategory, | 469 | bool editEntry(const QString &oldCategory, const QString &newCategory, |
470 | unsigned int index, PwMDataItem *d, bool updateMeta = true); | 470 | unsigned int index, PwMDataItem *d, bool updateMeta = true); |
471 | /** edit entry */ | 471 | /** edit entry */ |
472 | bool editEntry(unsigned int oldCategory, const QString &newCategory, | 472 | bool editEntry(unsigned int oldCategory, const QString &newCategory, |
473 | unsigned int index, PwMDataItem *d, bool updateMeta = true); | 473 | unsigned int index, PwMDataItem *d, bool updateMeta = true); |
474 | /** finds the category with the "name" and return it's index */ | 474 | /** finds the category with the "name" and return it's index */ |
475 | bool findCategory(const QString &name, unsigned int *index); | 475 | bool findCategory(const QString &name, unsigned int *index); |
476 | /** search for an entry "find" and check while searching only for | 476 | /** search for an entry "find" and check while searching only for |
477 | * the data-fields specified by "searchIn". To set the "searchIn" | 477 | * the data-fields specified by "searchIn". To set the "searchIn" |
478 | * 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 |
479 | * 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 |
480 | * matched entries in "foundPositions". If "breakAfterFound" is true, | 480 | * matched entries in "foundPositions". If "breakAfterFound" is true, |
481 | * the function terminates after the first occurence of the entry | 481 | * the function terminates after the first occurence of the entry |
482 | * and doesn't go on searching. So foundPositions->size() is never | 482 | * and doesn't go on searching. So foundPositions->size() is never |
483 | * > 1 if breakAfterFound is true. | 483 | * > 1 if breakAfterFound is true. |
484 | */ | 484 | */ |
485 | void findEntry(unsigned int category, PwMDataItem find, unsigned int searchIn, | 485 | void findEntry(unsigned int category, PwMDataItem find, unsigned int searchIn, |
486 | vector<unsigned int> *foundPositions, bool breakAfterFound = false, | 486 | vector<unsigned int> *foundPositions, bool breakAfterFound = false, |
487 | bool caseSensitive = true, bool exactWordMatch = true, | 487 | bool caseSensitive = true, bool exactWordMatch = true, |
488 | bool sortByLvp = false); | 488 | bool sortByLvp = false); |
489 | /** 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. */ |
490 | void findEntry(const QString &category, PwMDataItem find, unsigned int searchIn, | 490 | void findEntry(const QString &category, PwMDataItem find, unsigned int searchIn, |
491 | vector<unsigned int> *foundPositions, bool breakAfterFound = false, | 491 | vector<unsigned int> *foundPositions, bool breakAfterFound = false, |
492 | bool caseSensitive = true, bool exactWordMatch = true, | 492 | bool caseSensitive = true, bool exactWordMatch = true, |
493 | bool sortByLvp = false); | 493 | bool sortByLvp = false); |
494 | /** returns number of entries */ | 494 | /** returns number of entries */ |
495 | unsigned int numEntries(const QString &category); | 495 | unsigned int numEntries(const QString &category); |
496 | unsigned int numEntries(unsigned int category) | 496 | unsigned int numEntries(unsigned int category) |
497 | { return dti.dta[category].d.size(); } | 497 | { return dti.dta[category].d.size(); } |
498 | /** returns number of categories */ | 498 | /** returns number of categories */ |
499 | unsigned int numCategories() | 499 | unsigned int numCategories() |
500 | { return dti.dta.size(); } | 500 | { return dti.dta.size(); } |
501 | /** returns the name of the category at "index" */ | 501 | /** returns the name of the category at "index" */ |
502 | const string* getCategory(unsigned int index) | 502 | const string* getCategory(unsigned int index) |
503 | { return (&(dti.dta[index].name)); } | 503 | { return (&(dti.dta[index].name)); } |
504 | 504 | ||
505 | /** returns the data of item at "index". | 505 | /** returns the data of item at "index". |
506 | * 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. |
507 | * 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 |
508 | * the pw. | 508 | * the pw. |
509 | */ | 509 | */ |
510 | bool getEntry(const QString &category, unsigned int index, | 510 | bool getEntry(const QString &category, unsigned int index, |
511 | PwMDataItem *d, bool unlockIfLocked = false); | 511 | PwMDataItem *d, bool unlockIfLocked = false); |
512 | bool getEntry(unsigned int category, unsigned int index, | 512 | bool getEntry(unsigned int category, unsigned int index, |
513 | PwMDataItem *d, bool unlockIfLocked = false); | 513 | PwMDataItem *d, bool unlockIfLocked = false); |
514 | /** returns the comment-string by looking at the category | 514 | /** returns the comment-string by looking at the category |
515 | * and the listViewPos | 515 | * and the listViewPos |
516 | */ | 516 | */ |
517 | PwMerror getCommentByLvp(const QString &category, int listViewPos, | 517 | PwMerror getCommentByLvp(const QString &category, int listViewPos, |
518 | string *foundComment); | 518 | string *foundComment); |
519 | /** checks if a password is already available. (currentPw) */ | 519 | /** checks if a password is already available. (currentPw) */ |
520 | bool isPwAvailable() | 520 | bool isPwAvailable() |
521 | { return (currentPw != ""); } | 521 | { return (currentPw != ""); } |
522 | /** un/lock entry at "index". If needed, ask for password. */ | 522 | /** un/lock entry at "index". If needed, ask for password. */ |
523 | bool lockAt(const QString &category, unsigned int index, | 523 | bool lockAt(const QString &category, unsigned int index, |
524 | bool lock = true); | 524 | bool lock = true); |
525 | bool lockAt(unsigned int category, unsigned int index, | 525 | bool lockAt(unsigned int category, unsigned int index, |
526 | bool lock = true); | 526 | bool lock = true); |
527 | /** returns the lock-status at "index" */ | 527 | /** returns the lock-status at "index" */ |
528 | bool isLocked(const QString &category, unsigned int index); | 528 | bool isLocked(const QString &category, unsigned int index); |
529 | bool isLocked(unsigned int category, unsigned int index) | 529 | bool isLocked(unsigned int category, unsigned int index) |
530 | { return dti.dta[category].d[index].lockStat; } | 530 | { return dti.dta[category].d[index].lockStat; } |
531 | /** returns the deeplock status */ | 531 | /** returns the deeplock status */ |
532 | bool isDeepLocked() | 532 | bool isDeepLocked() |
533 | { return getDocStatFlag(DOC_STAT_DEEPLOCKED); } | 533 | { return getDocStatFlag(DOC_STAT_DEEPLOCKED); } |
534 | /** (un)lock all entries */ | 534 | /** (un)lock all entries */ |
535 | bool lockAll(bool lock); | 535 | bool lockAll(bool lock); |
536 | /** unlocks all entries tempoarly. | 536 | /** unlocks all entries tempoarly. |
537 | * 1st NOTE: Be very careful with this function! :) | 537 | * 1st NOTE: Be very careful with this function! :) |
538 | * 2nd NOTE: After you have called unlockAll_Tempoary(); , | 538 | * 2nd NOTE: After you have called unlockAll_Tempoary(); , |
539 | * please DON'T forget to call unlockAll_Tempoary(true); | 539 | * please DON'T forget to call unlockAll_Tempoary(true); |
540 | * _before_ the user (or someone else) is able to change | 540 | * _before_ the user (or someone else) is able to change |
541 | * the document! | 541 | * the document! |
542 | * 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 |
543 | * unlocked! This will cause corruption. | 543 | * unlocked! This will cause corruption. |
544 | */ | 544 | */ |
545 | bool unlockAll_tempoary(bool revert = false); | 545 | bool unlockAll_tempoary(bool revert = false); |
546 | /** deep-(un)locks the document. | 546 | /** deep-(un)locks the document. |
547 | * deep-locking writes all data to the file, deletes all data | 547 | * deep-locking writes all data to the file, deletes all data |
548 | * in memory, but doesn't close the document. | 548 | * in memory, but doesn't close the document. |
549 | * deep-locking is only available, if the user previously saved | 549 | * deep-locking is only available, if the user previously saved |
550 | * the doc to a file (with a password). | 550 | * the doc to a file (with a password). |
551 | * 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! |
552 | */ | 552 | */ |
553 | PwMerror deepLock(bool lock = true, bool saveToFile = true); | 553 | PwMerror deepLock(bool lock = true, bool saveToFile = true); |
554 | /** is unlockable without pw? */ | 554 | /** is unlockable without pw? */ |
555 | bool unlockWoPw() | 555 | bool unlockWoPw() |
556 | { return getDocStatFlag(DOC_STAT_UNLOCK_WITHOUT_PW); } | 556 | { return getDocStatFlag(DOC_STAT_UNLOCK_WITHOUT_PW); } |
557 | /** get the "currentPassword" */ | 557 | /** get the "currentPassword" */ |
558 | const QString& getCurrentPw() | 558 | const QString& getCurrentPw() |
559 | { return currentPw; } | 559 | { return currentPw; } |
560 | /** open a window and request the user to change the mpw */ | 560 | /** open a window and request the user to change the mpw */ |
561 | void changeCurrentPw(); | 561 | void changeCurrentPw(); |
562 | /** set the "listViewPos" variable of "dta" */ | 562 | /** set the "listViewPos" variable of "dta" */ |
563 | void setListViewPos(const QString &category, unsigned int index, | 563 | void setListViewPos(const QString &category, unsigned int index, |
564 | int pos); | 564 | int pos); |
565 | /** set the "listViewPos" variable of "dta" */ | 565 | /** set the "listViewPos" variable of "dta" */ |
566 | void setListViewPos(unsigned int category, unsigned int index, | 566 | void setListViewPos(unsigned int category, unsigned int index, |
567 | int pos); | 567 | int pos); |
568 | /** get the "listViewPos" variable of "dta" */ | 568 | /** get the "listViewPos" variable of "dta" */ |
569 | int getListViewPos(const QString &category, unsigned int index); | 569 | int getListViewPos(const QString &category, unsigned int index); |
570 | /** set the maximum number of entries allowed */ | 570 | /** set the maximum number of entries allowed */ |
571 | void setMaxNumEntries(unsigned int num = DEFAULT_MAX_ENTRIES) | 571 | void setMaxNumEntries(unsigned int num = DEFAULT_MAX_ENTRIES) |
572 | { maxEntries = num; } | 572 | { maxEntries = num; } |
573 | /** get the maximum number of entries allowed */ | 573 | /** get the maximum number of entries allowed */ |
574 | unsigned int getMaxNumEntries() | 574 | unsigned int getMaxNumEntries() |
575 | { return maxEntries; } | 575 | { return maxEntries; } |
576 | /** ensure all listViewPos of all dta items are set. (are ! -1). | 576 | /** ensure all listViewPos of all dta items are set. (are ! -1). |
577 | * 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 |
578 | * the listViewPos(itions). */ | 578 | * the listViewPos(itions). */ |
579 | void ensureLvp(); | 579 | void ensureLvp(); |
580 | /** execute the "launcher" of this entry */ | 580 | /** execute the "launcher" of this entry */ |
581 | bool execLauncher(const QString &category, unsigned int entryIndex); | 581 | bool execLauncher(const QString &category, unsigned int entryIndex); |
582 | /** see above */ | 582 | /** see above */ |
583 | bool execLauncher(unsigned int category, unsigned int entryIndex); | 583 | bool execLauncher(unsigned int category, unsigned int entryIndex); |
584 | /** open a browser with the URL-section of the given entry */ | 584 | /** open a browser with the URL-section of the given entry */ |
585 | bool goToURL(const QString &category, unsigned int entryIndex); | 585 | bool goToURL(const QString &category, unsigned int entryIndex); |
586 | /** see above */ | 586 | /** see above */ |
587 | bool goToURL(unsigned int category, unsigned int entryIndex); | 587 | bool goToURL(unsigned int category, unsigned int entryIndex); |
588 | /** returns true if there is no entry present in the document. | 588 | /** returns true if there is no entry present in the document. |
589 | * Note: The "default" Category is present everytime, so | 589 | * Note: The "default" Category is present everytime, so |
590 | * it's checked for it's entries. | 590 | * it's checked for it's entries. |
591 | */ | 591 | */ |
592 | bool isDocEmpty() | 592 | bool isDocEmpty() |
593 | { | 593 | { |
594 | if (numCategories() > 1) | 594 | if (numCategories() > 1) |
595 | return false; | 595 | return false; |
596 | if (numEntries(0)) | 596 | if (numEntries(0)) |
597 | return false; | 597 | return false; |
598 | return true; | 598 | return true; |
599 | } | 599 | } |
600 | /** returns the filename of this doc */ | 600 | /** returns the filename of this doc */ |
601 | const QString& getFilename() | 601 | const QString& getFilename() |
602 | { return filename; } | 602 | { return filename; } |
603 | /** returns the title of the doc */ | 603 | /** returns the title of the doc */ |
604 | QString getTitle(); | 604 | QString getTitle(); |
605 | /** sets the list-view-pointer hold in the doc */ | 605 | /** sets the list-view-pointer hold in the doc */ |
606 | void setListViewPointer(PwMView *_listView) | 606 | void setListViewPointer(PwMView *_listView) |
607 | { listView = _listView; } | 607 | { listView = _listView; } |
608 | /** returns the list-view-pointer */ | 608 | /** returns the list-view-pointer */ |
609 | PwMView * getListViewPointer() | 609 | PwMView * getListViewPointer() |
610 | { return listView; } | 610 | { return listView; } |
611 | /** 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 |
612 | * the data. The user may cancel the whole operation. | 612 | * the data. The user may cancel the whole operation. |
613 | * false is returned, then. | 613 | * false is returned, then. |
614 | */ | 614 | */ |
615 | bool tryDelete(); | 615 | bool tryDelete(); |
616 | /** is the doc deleted? (with tryDelete() ) */ | 616 | /** is the doc deleted? (with tryDelete() ) */ |
617 | bool isDeleted() | 617 | bool isDeleted() |
618 | { return deleted; } | 618 | { return deleted; } |
619 | /** returns the document timer object */ | 619 | /** returns the document timer object */ |
620 | DocTimer * timer() | 620 | DocTimer * timer() |
621 | { return _timer; } | 621 | { return _timer; } |
622 | /** get a lock on the dataChanged signal. | 622 | /** get a lock on the dataChanged signal. |
623 | * If someone is holding a lock, the signal is not emitted. | 623 | * If someone is holding a lock, the signal is not emitted. |
624 | */ | 624 | */ |
625 | void getDataChangedLock() | 625 | void getDataChangedLock() |
626 | { ++dataChangedLock; } | 626 | { ++dataChangedLock; } |
627 | /** put the dataChanged lock */ | 627 | /** put the dataChanged lock */ |
628 | void putDataChangedLock() | 628 | void putDataChangedLock() |
629 | { --dataChangedLock; } | 629 | { --dataChangedLock; } |
630 | /** returns the revision count of the item at cat/index */ | 630 | /** returns the revision count of the item at cat/index */ |
631 | unsigned int getEntryRevCnt(unsigned int category, unsigned int index) | 631 | unsigned int getEntryRevCnt(unsigned int category, unsigned int index) |
632 | { return dti.dta[category].d[index].rev; } | 632 | { return dti.dta[category].d[index].rev; } |
633 | /** returns a const pointer to the entries meta */ | 633 | /** returns a const pointer to the entries meta */ |
634 | const PwMMetaData * getEntryMeta(unsigned int category, unsigned int index) | 634 | const PwMMetaData * getEntryMeta(unsigned int category, unsigned int index) |
635 | { return &(dti.dta[category].d[index].meta); } | 635 | { return &(dti.dta[category].d[index].meta); } |
636 | /** is the entry at "category" "index" a binary entry? */ | 636 | /** is the entry at "category" "index" a binary entry? */ |
637 | bool isBinEntry(unsigned int category, unsigned int index) | 637 | bool isBinEntry(unsigned int category, unsigned int index) |
638 | { return dti.dta[category].d[index].binary; } | 638 | { return dti.dta[category].d[index].binary; } |
639 | 639 | ||
640 | public slots: | 640 | public slots: |
641 | /** wrapper for PwMTray */ | 641 | /** wrapper for PwMTray */ |
642 | void _deepUnlock(); | 642 | void _deepUnlock(); |
643 | 643 | ||
644 | signals: | 644 | signals: |
645 | /** the data of the document has changed and must be updated | 645 | /** the data of the document has changed and must be updated |
646 | * in all views. | 646 | * in all views. |
647 | * NOTE: use emitDataChanged(PwMDoc *document) to emit this signal! | 647 | * NOTE: use emitDataChanged(PwMDoc *document) to emit this signal! |
648 | */ | 648 | */ |
649 | void dataChanged(PwMDoc *document); | 649 | void dataChanged(PwMDoc *document); |
650 | /** the document class is going to close. This signal may be | 650 | /** the document class is going to close. This signal may be |
651 | * used to nofify all views, that the user closed the document, | 651 | * used to nofify all views, that the user closed the document, |
652 | * so the views can go down, too. | 652 | * so the views can go down, too. |
653 | */ | 653 | */ |
654 | void docClosed(PwMDoc *document); | 654 | void docClosed(PwMDoc *document); |
655 | /** somebody just opened the document */ | 655 | /** somebody just opened the document */ |
656 | void docOpened(PwMDoc *document); | 656 | void docOpened(PwMDoc *document); |
657 | /** this document object just got created */ | 657 | /** this document object just got created */ |
658 | void docCreated(PwMDoc *document); | 658 | void docCreated(PwMDoc *document); |
659 | 659 | ||
660 | public: | 660 | public: |
661 | /** emit the dataChanged signal after checking for a lock */ | 661 | /** emit the dataChanged signal after checking for a lock */ |
662 | void emitDataChanged(PwMDoc *document) | 662 | void emitDataChanged(PwMDoc *document) |
663 | { | 663 | { |
664 | if (!dataChangedLock) | 664 | if (!dataChangedLock) |
665 | emit dataChanged(document); | 665 | emit dataChanged(document); |
666 | } | 666 | } |
667 | 667 | ||
668 | protected: | 668 | protected: |
669 | /** current file for this doc */ | 669 | /** current file for this doc */ |
670 | QString filename; | 670 | QString filename; |
671 | //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 |
672 | // 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 |
673 | /** holds all data */ | 673 | /** holds all data */ |
674 | PwMItem dti; | 674 | PwMItem dti; |
675 | /** maximum number of entries */ | 675 | /** maximum number of entries */ |
676 | unsigned int maxEntries; | 676 | unsigned int maxEntries; |
677 | /** currently used password to encrypt data */ | 677 | /** currently used password to encrypt data */ |
678 | QString currentPw; | 678 | QString currentPw; |
679 | /** current global document status flags */ | 679 | /** current global document status flags */ |
680 | unsigned int curDocStat; | 680 | unsigned int curDocStat; |
681 | /** browser process for goToURL() */ | 681 | /** browser process for goToURL() */ |
682 | KProcess browserProc; | 682 | KProcess browserProc; |
683 | /** pointer to the list-view, using this document. | 683 | /** pointer to the list-view, using this document. |
684 | * As there can only be one list-view per doc, we | 684 | * As there can only be one list-view per doc, we |
685 | * don't need a list here. | 685 | * don't need a list here. |
686 | */ | 686 | */ |
687 | PwMView *listView; | 687 | PwMView *listView; |
688 | /** unnamedNum is used to store the "unnamed counter" | 688 | /** unnamedNum is used to store the "unnamed counter" |
689 | * for this document, while it's unnamed. If it's 0, | 689 | * for this document, while it's unnamed. If it's 0, |
690 | * we have to get a new unique one. | 690 | * we have to get a new unique one. |
691 | */ | 691 | */ |
692 | unsigned int unnamedNum; | 692 | unsigned int unnamedNum; |
693 | /** is this doc going to be deleted (executing in destructor context) */ | 693 | /** is this doc going to be deleted (executing in destructor context) */ |
694 | bool deleted; | 694 | bool deleted; |
695 | /** document timer */ | 695 | /** document timer */ |
696 | DocTimer *_timer; | 696 | DocTimer *_timer; |
697 | /** lock counter for the "dataChanged" signal */ | 697 | /** lock counter for the "dataChanged" signal */ |
698 | unsigned int dataChangedLock; | 698 | unsigned int dataChangedLock; |
699 | 699 | ||
700 | /** list of all open documents */ | 700 | /** list of all open documents */ |
701 | static PwMDocList openDocList; | 701 | static PwMDocList openDocList; |
702 | 702 | ||
703 | protected: | 703 | protected: |
704 | /** serialize "dta" and return it in "d". */ | 704 | /** serialize "dta" and return it in "d". */ |
705 | bool serializeDta(string *d); | 705 | bool serializeDta(string *d); |
706 | /** de-serialize "d" and overwrite "dta" */ | 706 | /** de-serialize "d" and overwrite "dta" */ |
707 | bool deSerializeDta(const string *d, bool entriesLocked); | 707 | bool deSerializeDta(const string *d, bool entriesLocked); |
708 | /** write header to file */ | 708 | /** write header to file */ |
709 | PwMerror writeFileHeader(char keyHash, char dataHash, char crypt, char compress, | 709 | PwMerror writeFileHeader(char keyHash, char dataHash, char crypt, char compress, |
710 | QString *pw, QFile *f); | 710 | QString *pw, QFile *f); |
711 | /** write data-hash to file */ | 711 | /** write data-hash to file */ |
712 | PwMerror writeDataHash(char dataHash, string *d, QFile *f); | 712 | PwMerror writeDataHash(char dataHash, string *d, QFile *f); |
713 | /** check header. Read header info and verify key-hash and filever. | 713 | /** check header. Read header info and verify key-hash and filever. |
714 | * returns length of header in "headerLength" */ | 714 | * returns length of header in "headerLength" */ |
715 | PwMerror checkHeader(char *cryptAlgo, QString *pw, char *compress, | 715 | PwMerror checkHeader(char *cryptAlgo, QString *pw, char *compress, |
716 | unsigned int *headerLength, char *dataHashType, | 716 | unsigned int *headerLength, char *dataHashType, |
717 | string *dataHash, QFile *f); | 717 | string *dataHash, QFile *f); |
718 | /** check the data-hash */ | 718 | /** check the data-hash */ |
719 | PwMerror checkDataHash(char dataHashType, const string *dataHash, const string *dataStream); | 719 | PwMerror checkDataHash(char dataHashType, const string *dataHash, const string *dataStream); |
720 | /** encrypt data "d" and write to "filename" */ | 720 | /** encrypt data "d" and write to "filename" */ |
721 | PwMerror encrypt(string *d, const QString *pw, QFile *f, char algo); | 721 | PwMerror encrypt(string *d, const QString *pw, QFile *f, char algo); |
722 | /** read data from file beginning at "pos", decrypt and return it */ | 722 | /** read data from file beginning at "pos", decrypt and return it */ |
723 | 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); |
724 | /** compress the data */ | 724 | /** compress the data */ |
725 | bool compressDta(string *d, char algo); | 725 | bool compressDta(string *d, char algo); |
726 | /** uncompress the data */ | 726 | /** uncompress the data */ |
727 | bool decompressDta(string *d, char algo); | 727 | bool decompressDta(string *d, char algo); |
728 | /** internal import function for a text-file generated by PwM. | 728 | /** internal import function for a text-file generated by PwM. |
729 | * 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 */ |
730 | PwMerror importText_PwM(const QString *file); | 730 | PwMerror importText_PwM(const QString *file); |
731 | /** 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 |
732 | * of one entry-line */ | 732 | * of one entry-line */ |
733 | 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); |
734 | /** compare two strings */ | 734 | /** compare two strings */ |
735 | bool compareString(const string &s1, const string &s2, bool caseSensitive, | 735 | bool compareString(const string &s1, const string &s2, bool caseSensitive, |
736 | bool exactWordMatch); | 736 | bool exactWordMatch); |
737 | /** clears all document-data */ | 737 | /** clears all document-data */ |
738 | void clearDoc(); | 738 | void clearDoc(); |
739 | /** delete all empty categories */ | 739 | /** delete all empty categories */ |
740 | void delAllEmptyCat(bool dontFlagDirty); | 740 | void delAllEmptyCat(bool dontFlagDirty); |
741 | /** set a document status flag */ | 741 | /** set a document status flag */ |
742 | void setDocStatFlag(unsigned int statFlag) | 742 | void setDocStatFlag(unsigned int statFlag) |
743 | { curDocStat |= statFlag; } | 743 | { curDocStat |= statFlag; } |
744 | /** unset a document status flag */ | 744 | /** unset a document status flag */ |
745 | void unsetDocStatFlag(unsigned int statFlag) | 745 | void unsetDocStatFlag(unsigned int statFlag) |
746 | { curDocStat &= ~statFlag; } | 746 | { curDocStat &= ~statFlag; } |
747 | /** get a document status flag */ | 747 | /** get a document status flag */ |
748 | bool getDocStatFlag(unsigned int statFlag) const | 748 | bool getDocStatFlag(unsigned int statFlag) const |
749 | { return (curDocStat & statFlag); } | 749 | { return (curDocStat & statFlag); } |
750 | /** set the "currentPassword" */ | 750 | /** set the "currentPassword" */ |
751 | void setCurrentPw(const QString &pw) | 751 | void setCurrentPw(const QString &pw) |
752 | { | 752 | { |
753 | currentPw = pw; | 753 | currentPw = pw; |
754 | setDocStatFlag(DOC_STAT_DISK_DIRTY); | 754 | setDocStatFlag(DOC_STAT_DISK_DIRTY); |
755 | } | 755 | } |
756 | /** make a backup-copy of the given file */ | 756 | /** make a backup-copy of the given file */ |
757 | bool backupFile(const QString &filePath); | 757 | bool backupFile(const QString &filePath); |
758 | /** copy a file from src to dst */ | 758 | /** copy a file from src to dst */ |
759 | bool copyFile(const QString &src, const QString &dst); | 759 | bool copyFile(const QString &src, const QString &dst); |
760 | 760 | ||
761 | 761 | ||
762 | public: | 762 | public: |
763 | #ifdef PWM_EMBEDDED | 763 | #ifdef PWM_EMBEDDED |
764 | //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. |
765 | PwMerror syncronize(KSyncManager* manager, PwMDoc* syncLocal, PwMDoc* syncRemote, int mode ); | 765 | PwMerror syncronize(KSyncManager* manager, PwMDoc* syncLocal, PwMDoc* syncRemote, int mode ); |
766 | 766 | ||
767 | //takePwMDataItem returns the following values | 767 | //takePwMDataItem returns the following values |
768 | // 0 equal | 768 | // 0 equal |
769 | // 1 take local | 769 | // 1 take local |
770 | // 2 take remote | 770 | // 2 take remote |
771 | // 3 cancel | 771 | // 3 cancel |
772 | 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 ); |
773 | 773 | ||
774 | //the following methods are the overwritten callbackmethods from the syncinterface | 774 | //the following methods are the overwritten callbackmethods from the syncinterface |
775 | virtual bool sync(KSyncManager* manager, QString filename, int mode); | 775 | virtual bool sync(KSyncManager* manager, QString filename, int mode); |
776 | 776 | ||
777 | //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. |
778 | virtual void sync_setModified(); | 778 | virtual void sync_setModified(); |
779 | //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. |
780 | virtual bool sync_isModified(); | 780 | virtual bool sync_isModified(); |
781 | //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. |
782 | virtual void sync_save(); | 782 | virtual void sync_save(); |
783 | 783 | ||
784 | #endif | 784 | #endif |
785 | private: | 785 | private: |
786 | //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. |
787 | // It returns the syncdatas index | 787 | // It returns the syncdatas index |
788 | bool findSyncData(const QString &syncname, unsigned int *index); | 788 | bool findSyncData(const QString &syncname, unsigned int *index); |
789 | 789 | ||
790 | /** add new syncdataentry */ | 790 | /** add new syncdataentry */ |
791 | PwMerror addSyncDataEntry(PwMSyncItem *d, bool dontFlagDirty = false); | 791 | PwMerror addSyncDataEntry(PwMSyncItem *d, bool dontFlagDirty = false); |
792 | 792 | ||
793 | /** returns a pointer to the syncdata */ | 793 | /** returns a pointer to the syncdata */ |
794 | PwMSyncItem getSyncDataEntry(unsigned int index) | 794 | PwMSyncItem* getSyncDataEntry(unsigned int index) |
795 | { return *(dti.syncDta[index]); } | 795 | { return &(dti.syncDta[index]); } |
796 | 796 | ||
797 | /** delete entry */ | 797 | /** delete entry */ |
798 | bool delSyncDataEntry(unsigned int index, bool dontFlagDirty = false); | 798 | bool delSyncDataEntry(unsigned int index, bool dontFlagDirty = false); |
799 | 799 | ||
800 | PwMDataItem* findEntryByID(const QString &uid, unsigned int *category, unsigned int *index); | 800 | PwMDataItem* findEntryByID(const QString &uid, unsigned int *category, unsigned int *index); |
801 | 801 | ||
802 | QStringList getIDEntryList(); | 802 | QStringList getIDEntryList(); |
803 | 803 | ||
804 | }; | 804 | }; |
805 | 805 | ||
806 | #endif | 806 | #endif |