author | ulf69 <ulf69> | 2004-10-06 06:18:43 (UTC) |
---|---|---|
committer | ulf69 <ulf69> | 2004-10-06 06:18:43 (UTC) |
commit | 8e5089d2f2011e38d811ae0fc6b6d4edaeaf89b8 (patch) (unidiff) | |
tree | 8d8ca7401ce699ee3aca98cace5561beb4104710 | |
parent | 904cbf4f2a418d3cadc74a6168a4565ae6ebc3c5 (diff) | |
download | kdepimpi-8e5089d2f2011e38d811ae0fc6b6d4edaeaf89b8.zip kdepimpi-8e5089d2f2011e38d811ae0fc6b6d4edaeaf89b8.tar.gz kdepimpi-8e5089d2f2011e38d811ae0fc6b6d4edaeaf89b8.tar.bz2 |
*** empty log message ***
-rw-r--r-- | pwmanager/pwmanager/pwmdoc.cpp | 48 |
1 files changed, 40 insertions, 8 deletions
diff --git a/pwmanager/pwmanager/pwmdoc.cpp b/pwmanager/pwmanager/pwmdoc.cpp index 4e8a603..6c1a9c0 100644 --- a/pwmanager/pwmanager/pwmdoc.cpp +++ b/pwmanager/pwmanager/pwmdoc.cpp | |||
@@ -2512,757 +2512,789 @@ PwMerror PwMDoc::importText_PwM(const QString *file) | |||
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 | 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()); | ||
2897 | |||
2896 | qApp->processEvents(); | 2898 | qApp->processEvents(); |
2897 | 2899 | ||
2898 | inLocal = syncLocal->findEntryByID( uid, &catLocal, &indexLocal ); | 2900 | inLocal = syncLocal->findEntryByID( uid, &catLocal, &indexLocal ); |
2899 | inRemote = syncRemote->findEntryByID( uid, &catRemote, &indexRemote ); | 2901 | inRemote = syncRemote->findEntryByID( uid, &catRemote, &indexRemote ); |
2902 | PWM_ASSERT(inRemote); | ||
2900 | if ( inLocal != 0 ) { // maybe conflict - same uid in both files | 2903 | if ( inLocal != 0 ) { // maybe conflict - same uid in both files |
2901 | if ( (take = takePwMDataItem( inLocal, inRemote, mLastSync, mode, fullDateRange) ) ) { | 2904 | if ( (take = takePwMDataItem( inLocal, inRemote, mLastSync, mode, fullDateRange) ) ) { |
2902 | //qDebug("take %d %s ", take, inL.summary().latin1()); | 2905 | //qDebug("take %d %s ", take, inL.summary().latin1()); |
2903 | if ( take == 3 ) | 2906 | if ( take == 3 ) |
2904 | return e_syncError; | 2907 | return e_syncError; |
2905 | if ( take == 1 ) {// take local | 2908 | if ( take == 1 ) {// take local |
2906 | //US syncRemote->removeAddressee( inRemote ); | 2909 | //US syncRemote->removeAddressee( inRemote ); |
2907 | (*inRemote) = (*inLocal); | 2910 | (*inRemote) = (*inLocal); |
2908 | //US syncRemote->insertAddressee( inRemote , false); | 2911 | //US syncRemote->insertAddressee( inRemote , false); |
2909 | ++changedRemote; | 2912 | ++changedRemote; |
2910 | } else { // take == 2 take remote | 2913 | } else { // take == 2 take remote |
2911 | //US syncLocal->removeAddressee( inLocal ); | 2914 | //US syncLocal->removeAddressee( inLocal ); |
2912 | (*inLocal) = (*inRemote); | 2915 | (*inLocal) = (*inRemote); |
2913 | //US syncLocal->insertAddressee( inLocal , false ); | 2916 | //US syncLocal->insertAddressee( inLocal , false ); |
2914 | ++changedLocal; | 2917 | ++changedLocal; |
2915 | } | 2918 | } |
2916 | } | 2919 | } |
2917 | } else { // no conflict | 2920 | } else { // no conflict |
2918 | if ( inRemote->meta.update > mLastSync || mode == 5 ) { | 2921 | if ( inRemote->meta.update > mLastSync || mode == 5 ) { |
2919 | inRemote->meta.update = modifiedSync; | 2922 | inRemote->meta.update = modifiedSync; |
2920 | //US syncRemote->insertAddressee( inRemote, false ); | 2923 | //US syncRemote->insertAddressee( inRemote, false ); |
2921 | //US syncLocal->insertAddressee( inRemote, false ); | 2924 | //US syncLocal->insertAddressee( inRemote, false ); |
2922 | syncLocal->addEntry("newcategory", inRemote, true, false); | 2925 | syncLocal->addEntry("newcategory", inRemote, true, false); |
2923 | 2926 | ||
2924 | ++addedPasswordsLocal; | 2927 | ++addedPasswordsLocal; |
2925 | } else { | 2928 | } else { |
2926 | // pending checkExternSyncAddressee(addresseeRSyncSharp, inR); | 2929 | // pending checkExternSyncAddressee(addresseeRSyncSharp, inR); |
2927 | syncRemote->delEntry(catRemote, indexRemote, true); | 2930 | syncRemote->delEntry(catRemote, indexRemote, true); |
2928 | //USsyncRemote->removeAddressee( inRemote ); | 2931 | //USsyncRemote->removeAddressee( inRemote ); |
2929 | ++deletedPasswordsRemote; | 2932 | ++deletedPasswordsRemote; |
2930 | } | 2933 | } |
2931 | } | 2934 | } |
2932 | 2935 | ||
2933 | ++incCounter; | 2936 | ++incCounter; |
2934 | } | 2937 | } |
2935 | 2938 | ||
2936 | 2939 | ||
2937 | er.clear(); | 2940 | er.clear(); |
2938 | QStringList el = syncLocal->getIDEntryList(); | 2941 | QStringList el = syncLocal->getIDEntryList(); |
2939 | modulo = (el.count()/10)+1; | 2942 | modulo = (el.count()/10)+1; |
2940 | 2943 | ||
2941 | manager->showProgressBar(0, i18n("Add / remove addressees"), el.count()); | 2944 | manager->showProgressBar(0, i18n("Add / remove addressees"), el.count()); |
2942 | incCounter = 0; | 2945 | incCounter = 0; |
2943 | while ( incCounter < el.count()) { | 2946 | while ( incCounter < el.count()) { |
2944 | qApp->processEvents(); | 2947 | qApp->processEvents(); |
2945 | if (manager->isProgressBarCanceled()) | 2948 | if (manager->isProgressBarCanceled()) |
2946 | return e_syncError; | 2949 | return e_syncError; |
2947 | if ( incCounter % modulo == 0 ) | 2950 | if ( incCounter % modulo == 0 ) |
2948 | manager->showProgressBar(incCounter); | 2951 | manager->showProgressBar(incCounter); |
2949 | uid = el[ incCounter ]; | 2952 | uid = el[ incCounter ]; |
2950 | 2953 | ||
2951 | inLocal = syncLocal->findEntryByID( uid, &catLocal, &indexLocal ); | 2954 | inLocal = syncLocal->findEntryByID( uid, &catLocal, &indexLocal ); |
2952 | inRemote = syncRemote->findEntryByID( uid, &catRemote, &indexRemote ); | 2955 | inRemote = syncRemote->findEntryByID( uid, &catRemote, &indexRemote ); |
2953 | if ( inRemote == 0 ) { | 2956 | if ( inRemote == 0 ) { |
2954 | if ( inLocal->meta.update < mLastSync && mode != 4 ) { | 2957 | if ( inLocal->meta.update < mLastSync && mode != 4 ) { |
2955 | // pending checkExternSyncAddressee(addresseeLSyncSharp, inL); | 2958 | // pending checkExternSyncAddressee(addresseeLSyncSharp, inL); |
2956 | syncLocal->delEntry(catLocal, indexLocal, true); | 2959 | syncLocal->delEntry(catLocal, indexLocal, true); |
2957 | //USsyncLocal->removeAddressee( inLocal ); | 2960 | //USsyncLocal->removeAddressee( inLocal ); |
2958 | ++deletedPasswordsLocal; | 2961 | ++deletedPasswordsLocal; |
2959 | } else { | 2962 | } else { |
2960 | if ( ! PWMPrefs::instance()->mWriteBackExistingOnly ) { | 2963 | if ( ! PWMPrefs::instance()->mWriteBackExistingOnly ) { |
2961 | ++addedPasswordsRemote; | 2964 | ++addedPasswordsRemote; |
2962 | inLocal->meta.update = modifiedSync; | 2965 | inLocal->meta.update = modifiedSync; |
2963 | //USsyncLocal->insertAddressee( inLocal, false ); | 2966 | //USsyncLocal->insertAddressee( inLocal, false ); |
2964 | (*inRemote) = (*inLocal); | 2967 | (*inRemote) = (*inLocal); |
2965 | //USsyncRemote->insertAddressee( inRemote, false ); | 2968 | //USsyncRemote->insertAddressee( inRemote, false ); |
2966 | syncRemote->addEntry("newcategory", inRemote, true, false); | 2969 | syncRemote->addEntry("newcategory", inRemote, true, false); |
2967 | 2970 | ||
2968 | } | 2971 | } |
2969 | } | 2972 | } |
2970 | 2973 | ||
2971 | } | 2974 | } |
2972 | ++incCounter; | 2975 | ++incCounter; |
2973 | } | 2976 | } |
2974 | el.clear(); | 2977 | el.clear(); |
2975 | manager->hideProgressBar(); | 2978 | manager->hideProgressBar(); |
2976 | 2979 | ||
2977 | // Now write the info back into the sync data space of the files | 2980 | // Now write the info back into the sync data space of the files |
2978 | 2981 | ||
2979 | mLastSync = QDateTime::currentDateTime().addSecs( 1 ); | 2982 | mLastSync = QDateTime::currentDateTime().addSecs( 1 ); |
2980 | // get rid of micro seconds | 2983 | // get rid of micro seconds |
2981 | QTime t = mLastSync.time(); | 2984 | QTime t = mLastSync.time(); |
2982 | mLastSync.setTime( QTime (t.hour (), t.minute (), t.second () ) ); | 2985 | mLastSync.setTime( QTime (t.hour (), t.minute (), t.second () ) ); |
2983 | 2986 | ||
2984 | 2987 | ||
2985 | syncItemLocal->lastSyncDate = mLastSync; | 2988 | syncItemLocal->lastSyncDate = mLastSync; |
2986 | syncItemRemote->lastSyncDate = mLastSync; | 2989 | syncItemRemote->lastSyncDate = mLastSync; |
2987 | 2990 | ||
2988 | // addresseeRSync.setRole( i18n("!Remote from: ")+mCurrentSyncName ) ; | 2991 | // addresseeRSync.setRole( i18n("!Remote from: ")+mCurrentSyncName ) ; |
2989 | // addresseeLSync.setRole(i18n("!Local from: ") + mCurrentSyncName ); | 2992 | // addresseeLSync.setRole(i18n("!Local from: ") + mCurrentSyncName ); |
2990 | 2993 | ||
2991 | syncRemote->addSyncDataEntry( syncItemRemote, false ); | 2994 | syncRemote->addSyncDataEntry( syncItemRemote, false ); |
2992 | syncLocal->addSyncDataEntry( syncItemLocal, false ); | 2995 | syncLocal->addSyncDataEntry( syncItemLocal, false ); |
2993 | QString mes; | 2996 | QString mes; |
2994 | mes .sprintf( i18n("Synchronization summary:\n\n %d items added to local\n %d items added to remote\n %d items updated on local\n %d items updated on remote\n %d items deleted on local\n %d items deleted on remote\n"),addedPasswordsLocal, addedPasswordsRemote, changedLocal, changedRemote, deletedPasswordsLocal, deletedPasswordsRemote ); | 2997 | mes .sprintf( i18n("Synchronization summary:\n\n %d items added to local\n %d items added to remote\n %d items updated on local\n %d items updated on remote\n %d items deleted on local\n %d items deleted on remote\n"),addedPasswordsLocal, addedPasswordsRemote, changedLocal, changedRemote, deletedPasswordsLocal, deletedPasswordsRemote ); |
2995 | if ( PWMPrefs::instance()->mShowSyncSummary ) { | 2998 | if ( PWMPrefs::instance()->mShowSyncSummary ) { |
2996 | KMessageBox::information(0, mes, i18n("PWM/Pi Synchronization") ); | 2999 | KMessageBox::information(0, mes, i18n("PWM/Pi Synchronization") ); |
2997 | } | 3000 | } |
2998 | qDebug( mes ); | 3001 | qDebug( mes ); |
2999 | return e_success; | 3002 | return e_success; |
3000 | } | 3003 | } |
3001 | 3004 | ||
3002 | 3005 | ||
3003 | int PwMDoc::takePwMDataItem( PwMDataItem* local, PwMDataItem* remote, QDateTime lastSync, int mode , bool full ) | 3006 | int PwMDoc::takePwMDataItem( PwMDataItem* local, PwMDataItem* remote, QDateTime lastSync, int mode , bool full ) |
3004 | { | 3007 | { |
3005 | // 0 equal | 3008 | // 0 equal |
3006 | // 1 take local | 3009 | // 1 take local |
3007 | // 2 take remote | 3010 | // 2 take remote |
3008 | // 3 cancel | 3011 | // 3 cancel |
3009 | QDateTime localMod = local->meta.update; | 3012 | QDateTime localMod = local->meta.update; |
3010 | QDateTime remoteMod = remote->meta.update; | 3013 | QDateTime remoteMod = remote->meta.update; |
3011 | 3014 | ||
3012 | //US QString mCurrentSyncDevice = syncManager->getCurrentSyncDevice(); | 3015 | //US QString mCurrentSyncDevice = syncManager->getCurrentSyncDevice(); |
3013 | 3016 | ||
3014 | if ( localMod == remoteMod ) | 3017 | if ( localMod == remoteMod ) |
3015 | return 0; | 3018 | return 0; |
3016 | 3019 | ||
3017 | qDebug(" %d %d conflict on %s %s ", mode, full, local->desc.c_str(), remote->desc.c_str() ); | 3020 | qDebug(" %d %d conflict on %s %s ", mode, full, local->desc.c_str(), remote->desc.c_str() ); |
3018 | 3021 | ||
3019 | //qDebug("%s %d %s %d", local->lastModified().toString().latin1() , localMod, remote->lastModified().toString().latin1(), remoteMod); | 3022 | //qDebug("%s %d %s %d", local->lastModified().toString().latin1() , localMod, remote->lastModified().toString().latin1(), remoteMod); |
3020 | //qDebug("%d %d %d %d ", local->lastModified().time().second(), local->lastModified().time().msec(), remote->lastModified().time().second(), remote->lastModified().time().msec() ); | 3023 | //qDebug("%d %d %d %d ", local->lastModified().time().second(), local->lastModified().time().msec(), remote->lastModified().time().second(), remote->lastModified().time().msec() ); |
3021 | //full = true; //debug only | 3024 | //full = true; //debug only |
3022 | if ( full ) { | 3025 | if ( full ) { |
3023 | bool equ = true;//US ( (*local) == (*remote) ); | 3026 | bool equ = true;//US ( (*local) == (*remote) ); |
3024 | if ( equ ) { | 3027 | if ( equ ) { |
3025 | //qDebug("equal "); | 3028 | //qDebug("equal "); |
3026 | if ( mode < SYNC_PREF_FORCE_LOCAL ) | 3029 | if ( mode < SYNC_PREF_FORCE_LOCAL ) |
3027 | return 0; | 3030 | return 0; |
3028 | 3031 | ||
3029 | }//else //debug only | 3032 | }//else //debug only |
3030 | //qDebug("not equal %s %s ", local->summary().latin1(), remote->summary().latin1()); | 3033 | //qDebug("not equal %s %s ", local->summary().latin1(), remote->summary().latin1()); |
3031 | } | 3034 | } |
3032 | 3035 | ||
3033 | int result; | 3036 | int result; |
3034 | bool localIsNew; | 3037 | bool localIsNew; |
3035 | //qDebug("%s -- %s mLastCalendarSync %s lastsync %s --- local %s remote %s ",local->summary().latin1(), remote->summary().latin1(),mLastCalendarSync.toString().latin1() ,lastSync.toString().latin1() , local->lastModified().toString().latin1() , remote->lastModified().toString().latin1() ); | 3038 | //qDebug("%s -- %s mLastCalendarSync %s lastsync %s --- local %s remote %s ",local->summary().latin1(), remote->summary().latin1(),mLastCalendarSync.toString().latin1() ,lastSync.toString().latin1() , local->lastModified().toString().latin1() , remote->lastModified().toString().latin1() ); |
3036 | 3039 | ||
3037 | if ( full && mode < SYNC_PREF_NEWEST ) | 3040 | if ( full && mode < SYNC_PREF_NEWEST ) |
3038 | mode = SYNC_PREF_ASK; | 3041 | mode = SYNC_PREF_ASK; |
3039 | 3042 | ||
3040 | switch( mode ) { | 3043 | switch( mode ) { |
3041 | case SYNC_PREF_LOCAL: | 3044 | case SYNC_PREF_LOCAL: |
3042 | if ( lastSync > remoteMod ) | 3045 | if ( lastSync > remoteMod ) |
3043 | return 1; | 3046 | return 1; |
3044 | if ( lastSync > localMod ) | 3047 | if ( lastSync > localMod ) |
3045 | return 2; | 3048 | return 2; |
3046 | return 1; | 3049 | return 1; |
3047 | break; | 3050 | break; |
3048 | case SYNC_PREF_REMOTE: | 3051 | case SYNC_PREF_REMOTE: |
3049 | if ( lastSync > remoteMod ) | 3052 | if ( lastSync > remoteMod ) |
3050 | return 1; | 3053 | return 1; |
3051 | if ( lastSync > localMod ) | 3054 | if ( lastSync > localMod ) |
3052 | return 2; | 3055 | return 2; |
3053 | return 2; | 3056 | return 2; |
3054 | break; | 3057 | break; |
3055 | case SYNC_PREF_NEWEST: | 3058 | case SYNC_PREF_NEWEST: |
3056 | if ( localMod > remoteMod ) | 3059 | if ( localMod > remoteMod ) |
3057 | return 1; | 3060 | return 1; |
3058 | else | 3061 | else |
3059 | return 2; | 3062 | return 2; |
3060 | break; | 3063 | break; |
3061 | case SYNC_PREF_ASK: | 3064 | case SYNC_PREF_ASK: |
3062 | //qDebug("lsy %s --- lo %s --- re %s ", lastSync.toString().latin1(), localMod.toString().latin1(), remoteMod.toString().latin1() ); | 3065 | //qDebug("lsy %s --- lo %s --- re %s ", lastSync.toString().latin1(), localMod.toString().latin1(), remoteMod.toString().latin1() ); |
3063 | if ( lastSync > remoteMod ) | 3066 | if ( lastSync > remoteMod ) |
3064 | return 1; | 3067 | return 1; |
3065 | if ( lastSync > localMod ) | 3068 | if ( lastSync > localMod ) |
3066 | return 2; | 3069 | return 2; |
3067 | localIsNew = localMod >= remoteMod; | 3070 | localIsNew = localMod >= remoteMod; |
3068 | //qDebug("conflict! ************************************** "); | 3071 | //qDebug("conflict! ************************************** "); |
3069 | { | 3072 | { |
3070 | PwMDataItemChooser acd ( *local,*remote, localIsNew , 0/*this*/ ); | 3073 | PwMDataItemChooser acd ( *local,*remote, localIsNew , 0/*this*/ ); |
3071 | result = acd.executeD(localIsNew); | 3074 | result = acd.executeD(localIsNew); |
3072 | return result; | 3075 | return result; |
3073 | } | 3076 | } |
3074 | break; | 3077 | break; |
3075 | case SYNC_PREF_FORCE_LOCAL: | 3078 | case SYNC_PREF_FORCE_LOCAL: |
3076 | return 1; | 3079 | return 1; |
3077 | break; | 3080 | break; |
3078 | case SYNC_PREF_FORCE_REMOTE: | 3081 | case SYNC_PREF_FORCE_REMOTE: |
3079 | return 2; | 3082 | return 2; |
3080 | break; | 3083 | break; |
3081 | 3084 | ||
3082 | default: | 3085 | default: |
3083 | // SYNC_PREF_TAKE_BOTH not implemented | 3086 | // SYNC_PREF_TAKE_BOTH not implemented |
3084 | break; | 3087 | break; |
3085 | } | 3088 | } |
3086 | return 0; | 3089 | return 0; |
3087 | } | 3090 | } |
3088 | 3091 | ||
3089 | 3092 | ||
3090 | 3093 | ||
3091 | 3094 | ||
3092 | //this are the overwritten callbackmethods from the syncinterface | 3095 | //this are the overwritten callbackmethods from the syncinterface |
3093 | bool PwMDoc::sync(KSyncManager* manager, QString filename, int mode) | 3096 | bool PwMDoc::sync(KSyncManager* manager, QString filename, int mode) |
3094 | { | 3097 | { |
3095 | QString mCurrentSyncDevice = manager->getCurrentSyncDevice(); | 3098 | QString mCurrentSyncDevice = manager->getCurrentSyncDevice(); |
3096 | 3099 | ||
3097 | // construct on the stack = automatic cleanup. | 3100 | //1) unlock local file first if necessary (ask for password) |
3101 | if (this->isDeepLocked()) { | ||
3102 | PwMerror ret = this->deepLock(false); | ||
3103 | if (ret != e_success) | ||
3104 | return false; | ||
3105 | } | ||
3106 | |||
3107 | //2) construct and open a new doc on the stack(automatic cleanup) for remote file. | ||
3098 | PwMDoc syncTarget(this, "synctarget"); | 3108 | PwMDoc syncTarget(this, "synctarget"); |
3109 | PwMDoc* pSyncTarget = &syncTarget; | ||
3110 | |||
3099 | 3111 | ||
3100 | PwMerror err = syncTarget.openDoc(&filename, 2 /*== deeplocked*/); | 3112 | PwMerror err = pSyncTarget->openDoc(&filename, 1 /*== open with all entries locked*/); |
3101 | 3113 | ||
3102 | if (err != e_success) | 3114 | if (err == e_alreadyOpen) { |
3115 | PwMDocList::listItem li; | ||
3116 | if (getOpenDocList()->find(filename.latin1(), &li)) | ||
3117 | pSyncTarget = li.doc; | ||
3118 | else { | ||
3119 | qDebug("PwmDoc::sync: sync failed. Error %i while opening file %s",err, filename.latin1()); | ||
3120 | return false; | ||
3121 | } | ||
3122 | } | ||
3123 | else if (err != e_success) { | ||
3124 | qDebug("PwmDoc::sync: sync failed. Error %i while opening file %s",err, filename.latin1()); | ||
3103 | return false; | 3125 | return false; |
3104 | 3126 | } | |
3127 | |||
3105 | qDebug("PWM file loaded %s,sync mode %d",filename.latin1(), mode ); | 3128 | qDebug("PWM file loaded %s,sync mode %d",filename.latin1(), mode ); |
3106 | 3129 | ||
3130 | |||
3131 | //3) unlock remote file first if necessary (ask for password) | ||
3132 | if (pSyncTarget->isDeepLocked()) { | ||
3133 | PwMerror ret = pSyncTarget->deepLock(false); | ||
3134 | if (ret != e_success) | ||
3135 | return false; | ||
3136 | } | ||
3137 | |||
3107 | 3138 | ||
3108 | err = syncronize(manager, this, &syncTarget, mode ); | 3139 | err = syncronize(manager, this, pSyncTarget, mode ); |
3109 | 3140 | ||
3110 | if (err == e_success) { | 3141 | if (err == e_success) { |
3111 | if ( PWMPrefs::instance()->mWriteBackFile ){ | 3142 | if ( PWMPrefs::instance()->mWriteBackFile ){ |
3112 | qDebug("Saving remote PWManager file"); | 3143 | qDebug("Saving remote PWManager file"); |
3113 | err = syncTarget.saveDoc(conf()->confGlobCompression()); | 3144 | err = pSyncTarget->saveDoc(conf()->confGlobCompression()); |
3114 | if (err != e_success) | 3145 | if (err != e_success) { |
3146 | qDebug("PwmDoc::sync: Sync failed. Error %i while storing file %s",err, filename.latin1()); | ||
3115 | return false; | 3147 | return false; |
3116 | 3148 | } | |
3117 | } | 3149 | } |
3118 | 3150 | ||
3119 | flagDirty(); | 3151 | flagDirty(); |
3120 | return true; | 3152 | return true; |
3121 | } | 3153 | } |
3122 | else { | 3154 | else { |
3123 | return false; | 3155 | return false; |
3124 | } | 3156 | } |
3125 | } | 3157 | } |
3126 | 3158 | ||
3127 | //called by the syncmanager to indicate that the work has to marked as dirty. | 3159 | //called by the syncmanager to indicate that the work has to marked as dirty. |
3128 | void PwMDoc::sync_setModified() | 3160 | void PwMDoc::sync_setModified() |
3129 | { | 3161 | { |
3130 | flagDirty(); | 3162 | flagDirty(); |
3131 | } | 3163 | } |
3132 | 3164 | ||
3133 | //called by the syncmanager to ask if the dirty flag is set. | 3165 | //called by the syncmanager to ask if the dirty flag is set. |
3134 | bool PwMDoc::sync_isModified() | 3166 | bool PwMDoc::sync_isModified() |
3135 | { | 3167 | { |
3136 | return isDirty(); | 3168 | return isDirty(); |
3137 | } | 3169 | } |
3138 | 3170 | ||
3139 | //called by the syncmanager to indicate that the work has to be saved. | 3171 | //called by the syncmanager to indicate that the work has to be saved. |
3140 | void PwMDoc::sync_save() | 3172 | void PwMDoc::sync_save() |
3141 | { | 3173 | { |
3142 | saveDoc(conf()->confGlobCompression()); | 3174 | saveDoc(conf()->confGlobCompression()); |
3143 | } | 3175 | } |
3144 | #endif | 3176 | #endif |
3145 | 3177 | ||
3146 | 3178 | ||
3147 | bool PwMDoc::findSyncData(const QString &syncname, unsigned int *index) | 3179 | bool PwMDoc::findSyncData(const QString &syncname, unsigned int *index) |
3148 | { | 3180 | { |
3149 | vector<PwMSyncItem>::iterator i = dti.syncDta.begin(), | 3181 | vector<PwMSyncItem>::iterator i = dti.syncDta.begin(), |
3150 | end = dti.syncDta.end(); | 3182 | end = dti.syncDta.end(); |
3151 | 3183 | ||
3152 | while (i != end) { | 3184 | while (i != end) { |
3153 | if ((*i).syncName == syncname.latin1()) { | 3185 | if ((*i).syncName == syncname.latin1()) { |
3154 | if (index) { | 3186 | if (index) { |
3155 | *index = i - dti.syncDta.begin(); | 3187 | *index = i - dti.syncDta.begin(); |
3156 | } | 3188 | } |
3157 | return true; | 3189 | return true; |
3158 | } | 3190 | } |
3159 | ++i; | 3191 | ++i; |
3160 | } | 3192 | } |
3161 | return false; | 3193 | return false; |
3162 | }; | 3194 | }; |
3163 | 3195 | ||
3164 | /** add new syncdataentry */ | 3196 | /** add new syncdataentry */ |
3165 | PwMerror PwMDoc::addSyncDataEntry(PwMSyncItem *d, bool dontFlagDirty) | 3197 | PwMerror PwMDoc::addSyncDataEntry(PwMSyncItem *d, bool dontFlagDirty) |
3166 | { | 3198 | { |
3167 | PWM_ASSERT(d); | 3199 | PWM_ASSERT(d); |
3168 | 3200 | ||
3169 | if (isDeepLocked()) { | 3201 | if (isDeepLocked()) { |
3170 | PwMerror ret; | 3202 | PwMerror ret; |
3171 | ret = deepLock(false); | 3203 | ret = deepLock(false); |
3172 | if (ret != e_success) | 3204 | if (ret != e_success) |
3173 | return e_lock; | 3205 | return e_lock; |
3174 | } | 3206 | } |
3175 | unsigned int index; | 3207 | unsigned int index; |
3176 | 3208 | ||
3177 | const QString tmp = d->syncName.c_str(); | 3209 | const QString tmp = d->syncName.c_str(); |
3178 | bool exists = findSyncData(d->syncName.c_str(), &index); | 3210 | bool exists = findSyncData(d->syncName.c_str(), &index); |
3179 | 3211 | ||
3180 | if (exists == true) { | 3212 | if (exists == true) { |
3181 | // DOH! We found this entry. | 3213 | // DOH! We found this entry. |
3182 | return e_entryExists; | 3214 | return e_entryExists; |
3183 | } | 3215 | } |
3184 | 3216 | ||
3185 | dti.syncDta.push_back(*d); | 3217 | dti.syncDta.push_back(*d); |
3186 | 3218 | ||
3187 | if (!dontFlagDirty) | 3219 | if (!dontFlagDirty) |
3188 | flagDirty(); | 3220 | flagDirty(); |
3189 | return e_success; | 3221 | return e_success; |
3190 | } | 3222 | } |
3191 | 3223 | ||
3192 | 3224 | ||
3193 | 3225 | ||
3194 | /** delete syncdata entry */ | 3226 | /** delete syncdata entry */ |
3195 | bool PwMDoc::delSyncDataEntry(unsigned int index, bool dontFlagDirty) | 3227 | bool PwMDoc::delSyncDataEntry(unsigned int index, bool dontFlagDirty) |
3196 | { | 3228 | { |
3197 | if (isDeepLocked()) | 3229 | if (isDeepLocked()) |
3198 | return false; | 3230 | return false; |
3199 | if (index > dti.syncDta.size() - 1) | 3231 | if (index > dti.syncDta.size() - 1) |
3200 | return false; | 3232 | return false; |
3201 | 3233 | ||
3202 | // delete entry | 3234 | // delete entry |
3203 | dti.syncDta.erase(dti.syncDta.begin() + index); | 3235 | dti.syncDta.erase(dti.syncDta.begin() + index); |
3204 | 3236 | ||
3205 | if (!dontFlagDirty) | 3237 | if (!dontFlagDirty) |
3206 | flagDirty(); | 3238 | flagDirty(); |
3207 | return true; | 3239 | return true; |
3208 | } | 3240 | } |
3209 | 3241 | ||
3210 | 3242 | ||
3211 | PwMDataItem* PwMDoc::findEntryByID(const QString &uid, unsigned int *category, unsigned int *index) | 3243 | PwMDataItem* PwMDoc::findEntryByID(const QString &uid, unsigned int *category, unsigned int *index) |
3212 | { | 3244 | { |
3213 | vector<PwMCategoryItem>::iterator catcounter = dti.dta.begin(), | 3245 | vector<PwMCategoryItem>::iterator catcounter = dti.dta.begin(), |
3214 | catend = dti.dta.end(); | 3246 | catend = dti.dta.end(); |
3215 | 3247 | ||
3216 | vector<PwMDataItem>::iterator entrBegin, entrEnd, entrI; | 3248 | vector<PwMDataItem>::iterator entrBegin, entrEnd, entrI; |
3217 | 3249 | ||
3218 | while (catcounter != catend) { | 3250 | while (catcounter != catend) { |
3219 | entrBegin = catcounter->d.begin(); | 3251 | entrBegin = catcounter->d.begin(); |
3220 | entrEnd = catcounter->d.end(); | 3252 | entrEnd = catcounter->d.end(); |
3221 | entrI = entrBegin; | 3253 | entrI = entrBegin; |
3222 | while (entrI != entrEnd) { | 3254 | while (entrI != entrEnd) { |
3223 | if ((*entrI).meta.uniqueid == uid.latin1()) { | 3255 | if ((*entrI).meta.uniqueid == uid.latin1()) { |
3224 | if (category) | 3256 | if (category) |
3225 | *category = catcounter - dti.dta.begin(); | 3257 | *category = catcounter - dti.dta.begin(); |
3226 | if (index) | 3258 | if (index) |
3227 | *index = entrI - entrBegin; | 3259 | *index = entrI - entrBegin; |
3228 | 3260 | ||
3229 | return &(*entrI); | 3261 | return &(*entrI); |
3230 | } | 3262 | } |
3231 | ++entrI; | 3263 | ++entrI; |
3232 | } | 3264 | } |
3233 | ++catcounter; | 3265 | ++catcounter; |
3234 | } | 3266 | } |
3235 | 3267 | ||
3236 | return 0; | 3268 | return 0; |
3237 | } | 3269 | } |
3238 | 3270 | ||
3239 | QStringList PwMDoc::getIDEntryList() | 3271 | QStringList PwMDoc::getIDEntryList() |
3240 | { | 3272 | { |
3241 | QStringList results; | 3273 | QStringList results; |
3242 | 3274 | ||
3243 | vector<PwMCategoryItem>::iterator catcounter = dti.dta.begin(), | 3275 | vector<PwMCategoryItem>::iterator catcounter = dti.dta.begin(), |
3244 | catend = dti.dta.end(); | 3276 | catend = dti.dta.end(); |
3245 | 3277 | ||
3246 | vector<PwMDataItem>::iterator entrBegin, entrEnd, entrI; | 3278 | vector<PwMDataItem>::iterator entrBegin, entrEnd, entrI; |
3247 | 3279 | ||
3248 | while (catcounter != catend) { | 3280 | while (catcounter != catend) { |
3249 | entrBegin = catcounter->d.begin(); | 3281 | entrBegin = catcounter->d.begin(); |
3250 | entrEnd = catcounter->d.end(); | 3282 | entrEnd = catcounter->d.end(); |
3251 | entrI = entrBegin; | 3283 | entrI = entrBegin; |
3252 | while (entrI != entrEnd) { | 3284 | while (entrI != entrEnd) { |
3253 | results.append( (*entrI).meta.uniqueid ); | 3285 | results.append( (*entrI).meta.uniqueid ); |
3254 | ++entrI; | 3286 | ++entrI; |
3255 | } | 3287 | } |
3256 | ++catcounter; | 3288 | ++catcounter; |
3257 | } | 3289 | } |
3258 | 3290 | ||
3259 | return results; | 3291 | return results; |
3260 | } | 3292 | } |
3261 | 3293 | ||
3262 | 3294 | ||
3263 | 3295 | ||
3264 | 3296 | ||
3265 | 3297 | ||
3266 | #ifndef PWM_EMBEDDED | 3298 | #ifndef PWM_EMBEDDED |
3267 | #include "pwmdoc.moc" | 3299 | #include "pwmdoc.moc" |
3268 | #endif | 3300 | #endif |