summaryrefslogtreecommitdiffabout
Unidiff
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--pwmanager/pwmanager/pwmdoc.cpp22
-rw-r--r--pwmanager/pwmanager/pwmdoc.h4
2 files changed, 25 insertions, 1 deletions
diff --git a/pwmanager/pwmanager/pwmdoc.cpp b/pwmanager/pwmanager/pwmdoc.cpp
index ddbf4f2..17cb74a 100644
--- a/pwmanager/pwmanager/pwmdoc.cpp
+++ b/pwmanager/pwmanager/pwmdoc.cpp
@@ -2544,961 +2544,981 @@ PwMerror PwMDoc::importText_PwM(const QString *file)
2544 // read username-line 2544 // read username-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.name)) 2547 if (!textExtractEntry_PwM(ch_tmp, ret, &currItem.name))
2548 goto formatError; 2548 goto formatError;
2549 2549
2550 // read pw-line 2550 // read pw-line
2551 if ((ret = getline(&ch_tmp, &ch_tmp_size, f)) == -1) 2551 if ((ret = getline(&ch_tmp, &ch_tmp_size, f)) == -1)
2552 goto formatError; 2552 goto formatError;
2553 if (!textExtractEntry_PwM(ch_tmp, ret, &currItem.pw)) 2553 if (!textExtractEntry_PwM(ch_tmp, ret, &currItem.pw))
2554 goto formatError; 2554 goto formatError;
2555 2555
2556 // read comment-line 2556 // read comment-line
2557 if ((ret = getline(&ch_tmp, &ch_tmp_size, f)) == -1) 2557 if ((ret = getline(&ch_tmp, &ch_tmp_size, f)) == -1)
2558 goto formatError; 2558 goto formatError;
2559 if (!textExtractEntry_PwM(ch_tmp, ret, &currItem.comment)) 2559 if (!textExtractEntry_PwM(ch_tmp, ret, &currItem.comment))
2560 goto formatError; 2560 goto formatError;
2561 2561
2562 // read URL-line 2562 // read URL-line
2563 if ((ret = getline(&ch_tmp, &ch_tmp_size, f)) == -1) 2563 if ((ret = getline(&ch_tmp, &ch_tmp_size, f)) == -1)
2564 goto formatError; 2564 goto formatError;
2565 if (!textExtractEntry_PwM(ch_tmp, ret, &currItem.url)) 2565 if (!textExtractEntry_PwM(ch_tmp, ret, &currItem.url))
2566 goto formatError; 2566 goto formatError;
2567 2567
2568 // read launcher-line 2568 // read launcher-line
2569 if ((ret = getline(&ch_tmp, &ch_tmp_size, f)) == -1) 2569 if ((ret = getline(&ch_tmp, &ch_tmp_size, f)) == -1)
2570 goto formatError; 2570 goto formatError;
2571 if (!textExtractEntry_PwM(ch_tmp, ret, &currItem.launcher)) 2571 if (!textExtractEntry_PwM(ch_tmp, ret, &currItem.launcher))
2572 goto formatError; 2572 goto formatError;
2573 2573
2574 currItem.lockStat = true; 2574 currItem.lockStat = true;
2575 currItem.listViewPos = -1; 2575 currItem.listViewPos = -1;
2576 addEntry(curCat.c_str(), &currItem, true); 2576 addEntry(curCat.c_str(), &currItem, true);
2577 ++entriesRead; 2577 ++entriesRead;
2578 } while (1); 2578 } while (1);
2579 } while (1); 2579 } while (1);
2580 if (!entriesRead) 2580 if (!entriesRead)
2581 goto formatError; 2581 goto formatError;
2582 2582
2583 free(ch_tmp); 2583 free(ch_tmp);
2584 fclose(f); 2584 fclose(f);
2585 flagDirty(); 2585 flagDirty();
2586 return e_success; 2586 return e_success;
2587 2587
2588 formatError: 2588 formatError:
2589 free(ch_tmp); 2589 free(ch_tmp);
2590 fclose(f); 2590 fclose(f);
2591 return e_fileFormat; 2591 return e_fileFormat;
2592#else 2592#else
2593 PWM_ASSERT(file); 2593 PWM_ASSERT(file);
2594 QFile f(file->latin1()); 2594 QFile f(file->latin1());
2595 int tmp; 2595 int tmp;
2596 ssize_t ret; 2596 ssize_t ret;
2597 string curCat; 2597 string curCat;
2598 unsigned int entriesRead = 0; 2598 unsigned int entriesRead = 0;
2599 PwMDataItem currItem; 2599 PwMDataItem currItem;
2600 bool res = f.open(IO_ReadOnly); 2600 bool res = f.open(IO_ReadOnly);
2601 if (res == false) 2601 if (res == false)
2602 return e_openFile; 2602 return e_openFile;
2603 2603
2604 unsigned int ch_tmp_size = 1024; 2604 unsigned int ch_tmp_size = 1024;
2605 char *ch_tmp = (char*)malloc(ch_tmp_size); 2605 char *ch_tmp = (char*)malloc(ch_tmp_size);
2606 if (!ch_tmp) { 2606 if (!ch_tmp) {
2607 f.close(); 2607 f.close();
2608 return e_outOfMem; 2608 return e_outOfMem;
2609 } 2609 }
2610 2610
2611 // - check header 2611 // - check header
2612 if (f.readLine(ch_tmp, ch_tmp_size) == -1) // skip first line. 2612 if (f.readLine(ch_tmp, ch_tmp_size) == -1) // skip first line.
2613 goto formatError; 2613 goto formatError;
2614 2614
2615 //US read fileversion first, then check if ok. 2615 //US read fileversion first, then check if ok.
2616 if (f.readLine(ch_tmp, ch_tmp_size) == -1) 2616 if (f.readLine(ch_tmp, ch_tmp_size) == -1)
2617 goto formatError; 2617 goto formatError;
2618 2618
2619 // check version-string and return version in "ch_tmp". 2619 // check version-string and return version in "ch_tmp".
2620 //US if (fscanf(f, "PwM v%s", ch_tmp) != 1) { 2620 //US if (fscanf(f, "PwM v%s", ch_tmp) != 1) {
2621 //US // header not recognized as PwM generated header 2621 //US // header not recognized as PwM generated header
2622 //US goto formatError; 2622 //US goto formatError;
2623 //US} 2623 //US}
2624 //US set filepointer behind version-string-line previously checked 2624 //US set filepointer behind version-string-line previously checked
2625 //US if (f.readLine(ch_tmp, ch_tmp_size) == -1) 2625 //US if (f.readLine(ch_tmp, ch_tmp_size) == -1)
2626 //US goto formatError; 2626 //US goto formatError;
2627 // skip next line containing the build-date 2627 // skip next line containing the build-date
2628 if (f.readLine(ch_tmp, ch_tmp_size) == -1) 2628 if (f.readLine(ch_tmp, ch_tmp_size) == -1)
2629 goto formatError; 2629 goto formatError;
2630 // read header termination line 2630 // read header termination line
2631 if (f.readLine(ch_tmp, ch_tmp_size) == -1) 2631 if (f.readLine(ch_tmp, ch_tmp_size) == -1)
2632 goto formatError; 2632 goto formatError;
2633 if (strcmp(ch_tmp, "==============================\n")) 2633 if (strcmp(ch_tmp, "==============================\n"))
2634 goto formatError; 2634 goto formatError;
2635 2635
2636 // - read entries 2636 // - read entries
2637 do { 2637 do {
2638 // find beginning of next category 2638 // find beginning of next category
2639 do { 2639 do {
2640 tmp = f.getch(); 2640 tmp = f.getch();
2641 } while (tmp == '\n' && tmp != EOF); 2641 } while (tmp == '\n' && tmp != EOF);
2642 if (tmp == EOF) 2642 if (tmp == EOF)
2643 break; 2643 break;
2644 2644
2645 // decrement filepos by one 2645 // decrement filepos by one
2646 f.at(f.at()-1); 2646 f.at(f.at()-1);
2647 // read cat-name 2647 // read cat-name
2648 if (f.readLine(ch_tmp, ch_tmp_size) == -1) 2648 if (f.readLine(ch_tmp, ch_tmp_size) == -1)
2649 goto formatError; 2649 goto formatError;
2650 // check cat-name format 2650 // check cat-name format
2651 if (memcmp(ch_tmp, "== Category: ", 13) != 0) 2651 if (memcmp(ch_tmp, "== Category: ", 13) != 0)
2652 goto formatError; 2652 goto formatError;
2653 if (memcmp(ch_tmp + (strlen(ch_tmp) - 1 - 3), " ==", 3) != 0) 2653 if (memcmp(ch_tmp + (strlen(ch_tmp) - 1 - 3), " ==", 3) != 0)
2654 goto formatError; 2654 goto formatError;
2655 // copy cat-name 2655 // copy cat-name
2656 curCat.assign(ch_tmp + 13, strlen(ch_tmp) - 1 - 16); 2656 curCat.assign(ch_tmp + 13, strlen(ch_tmp) - 1 - 16);
2657 2657
2658 do { 2658 do {
2659 // find beginning of next entry 2659 // find beginning of next entry
2660 do { 2660 do {
2661 tmp = f.getch(); 2661 tmp = f.getch();
2662 } while (tmp == '\n' && tmp != EOF && tmp != '='); 2662 } while (tmp == '\n' && tmp != EOF && tmp != '=');
2663 if (tmp == EOF) 2663 if (tmp == EOF)
2664 break; 2664 break;
2665 if (tmp == '=') { 2665 if (tmp == '=') {
2666 f.at(f.at()-1); 2666 f.at(f.at()-1);
2667 break; 2667 break;
2668 } 2668 }
2669 // decrement filepos by one 2669 // decrement filepos by one
2670 f.at(f.at()-1); 2670 f.at(f.at()-1);
2671 // read desc-line 2671 // read desc-line
2672 if (f.readLine(ch_tmp, ch_tmp_size) == -1) 2672 if (f.readLine(ch_tmp, ch_tmp_size) == -1)
2673 goto formatError; 2673 goto formatError;
2674 // check desc-line format 2674 // check desc-line format
2675 if (memcmp(ch_tmp, "-- ", 3) != 0) 2675 if (memcmp(ch_tmp, "-- ", 3) != 0)
2676 goto formatError; 2676 goto formatError;
2677 if (memcmp(ch_tmp + (strlen(ch_tmp) - 1 - 3), " --", 3) != 0) 2677 if (memcmp(ch_tmp + (strlen(ch_tmp) - 1 - 3), " --", 3) != 0)
2678 goto formatError; 2678 goto formatError;
2679 // add desc-line 2679 // add desc-line
2680 currItem.desc.assign(ch_tmp + 3, strlen(ch_tmp) - 1 - 6); 2680 currItem.desc.assign(ch_tmp + 3, strlen(ch_tmp) - 1 - 6);
2681 2681
2682 // read username-line 2682 // read username-line
2683 if ((ret = f.readLine(ch_tmp, ch_tmp_size)) == -1) 2683 if ((ret = f.readLine(ch_tmp, ch_tmp_size)) == -1)
2684 goto formatError; 2684 goto formatError;
2685 if (!textExtractEntry_PwM(ch_tmp, ret, &currItem.name)) 2685 if (!textExtractEntry_PwM(ch_tmp, ret, &currItem.name))
2686 goto formatError; 2686 goto formatError;
2687 2687
2688 // read pw-line 2688 // read pw-line
2689 if ((ret = f.readLine(ch_tmp, ch_tmp_size)) == -1) 2689 if ((ret = f.readLine(ch_tmp, ch_tmp_size)) == -1)
2690 goto formatError; 2690 goto formatError;
2691 if (!textExtractEntry_PwM(ch_tmp, ret, &currItem.pw)) 2691 if (!textExtractEntry_PwM(ch_tmp, ret, &currItem.pw))
2692 goto formatError; 2692 goto formatError;
2693 2693
2694 // read comment-line 2694 // read comment-line
2695 if ((ret = f.readLine(ch_tmp, ch_tmp_size)) == -1) 2695 if ((ret = f.readLine(ch_tmp, ch_tmp_size)) == -1)
2696 goto formatError; 2696 goto formatError;
2697 if (!textExtractEntry_PwM(ch_tmp, ret, &currItem.comment)) 2697 if (!textExtractEntry_PwM(ch_tmp, ret, &currItem.comment))
2698 goto formatError; 2698 goto formatError;
2699 2699
2700 // read URL-line 2700 // read URL-line
2701 if ((ret = f.readLine(ch_tmp, ch_tmp_size)) == -1) 2701 if ((ret = f.readLine(ch_tmp, ch_tmp_size)) == -1)
2702 goto formatError; 2702 goto formatError;
2703 if (!textExtractEntry_PwM(ch_tmp, ret, &currItem.url)) 2703 if (!textExtractEntry_PwM(ch_tmp, ret, &currItem.url))
2704 goto formatError; 2704 goto formatError;
2705 2705
2706 // read launcher-line 2706 // read launcher-line
2707 if ((ret = f.readLine(ch_tmp, ch_tmp_size)) == -1) 2707 if ((ret = f.readLine(ch_tmp, ch_tmp_size)) == -1)
2708 goto formatError; 2708 goto formatError;
2709 if (!textExtractEntry_PwM(ch_tmp, ret, &currItem.launcher)) 2709 if (!textExtractEntry_PwM(ch_tmp, ret, &currItem.launcher))
2710 goto formatError; 2710 goto formatError;
2711 2711
2712 currItem.lockStat = true; 2712 currItem.lockStat = true;
2713 currItem.listViewPos = -1; 2713 currItem.listViewPos = -1;
2714 addEntry(curCat.c_str(), &currItem, true); 2714 addEntry(curCat.c_str(), &currItem, true);
2715 ++entriesRead; 2715 ++entriesRead;
2716 } while (1); 2716 } while (1);
2717 } while (1); 2717 } while (1);
2718 if (!entriesRead) 2718 if (!entriesRead)
2719 goto formatError; 2719 goto formatError;
2720 2720
2721 free(ch_tmp); 2721 free(ch_tmp);
2722 f.close(); 2722 f.close();
2723 flagDirty(); 2723 flagDirty();
2724 return e_success; 2724 return e_success;
2725 2725
2726 formatError: 2726 formatError:
2727 free(ch_tmp); 2727 free(ch_tmp);
2728 f.close(); 2728 f.close();
2729 return e_fileFormat; 2729 return e_fileFormat;
2730 2730
2731#endif 2731#endif
2732 2732
2733} 2733}
2734 2734
2735bool PwMDoc::textExtractEntry_PwM(const char *in, ssize_t in_size, string *out) 2735bool PwMDoc::textExtractEntry_PwM(const char *in, ssize_t in_size, string *out)
2736{ 2736{
2737 PWM_ASSERT(in && out); 2737 PWM_ASSERT(in && out);
2738 ssize_t i = 0, len = in_size - 1; 2738 ssize_t i = 0, len = in_size - 1;
2739 while (i < len) { 2739 while (i < len) {
2740 if (in[i] == ':') 2740 if (in[i] == ':')
2741 break; 2741 break;
2742 ++i; 2742 ++i;
2743 } 2743 }
2744 i += 2; 2744 i += 2;
2745 *out = ""; 2745 *out = "";
2746 out->append(in + i, in_size - i - 1); 2746 out->append(in + i, in_size - i - 1);
2747 return true; 2747 return true;
2748} 2748}
2749 2749
2750PwMerror PwMDoc::exportToGpasman(const QString *file) 2750PwMerror PwMDoc::exportToGpasman(const QString *file)
2751{ 2751{
2752 PWM_ASSERT(file); 2752 PWM_ASSERT(file);
2753 GpasmanFile gp; 2753 GpasmanFile gp;
2754 int ret; 2754 int ret;
2755 2755
2756 if (!unlockAll_tempoary()) 2756 if (!unlockAll_tempoary())
2757 return e_lock; 2757 return e_lock;
2758 2758
2759 QString gpmPassword; 2759 QString gpmPassword;
2760 while (1) { 2760 while (1) {
2761 gpmPassword = requestNewMpw(0); 2761 gpmPassword = requestNewMpw(0);
2762 if (gpmPassword == "") { 2762 if (gpmPassword == "") {
2763 unlockAll_tempoary(true); 2763 unlockAll_tempoary(true);
2764 return e_noPw; 2764 return e_noPw;
2765 } 2765 }
2766 if (gpmPassword.length() < 4) { 2766 if (gpmPassword.length() < 4) {
2767 gpmPwLenErrMsgBox(); 2767 gpmPwLenErrMsgBox();
2768 } else { 2768 } else {
2769 break; 2769 break;
2770 } 2770 }
2771 } 2771 }
2772 2772
2773 ret = gp.save_init(file->latin1(), gpmPassword.latin1()); 2773 ret = gp.save_init(file->latin1(), gpmPassword.latin1());
2774 if (ret != 1) { 2774 if (ret != 1) {
2775 unlockAll_tempoary(true); 2775 unlockAll_tempoary(true);
2776 return e_accessFile; 2776 return e_accessFile;
2777 } 2777 }
2778 2778
2779 char *entry[4]; 2779 char *entry[4];
2780 unsigned int numCat = numCategories(), i; 2780 unsigned int numCat = numCategories(), i;
2781 unsigned int numEntr, j; 2781 unsigned int numEntr, j;
2782 int descLen, nameLen, pwLen, commentLen; 2782 int descLen, nameLen, pwLen, commentLen;
2783 for (i = 0; i < numCat; ++i) { 2783 for (i = 0; i < numCat; ++i) {
2784 numEntr = numEntries(i); 2784 numEntr = numEntries(i);
2785 for (j = 0; j < numEntr; ++j) { 2785 for (j = 0; j < numEntr; ++j) {
2786 descLen = dti.dta[i].d[j].desc.length(); 2786 descLen = dti.dta[i].d[j].desc.length();
2787 nameLen = dti.dta[i].d[j].name.length(); 2787 nameLen = dti.dta[i].d[j].name.length();
2788 pwLen = dti.dta[i].d[j].pw.length(); 2788 pwLen = dti.dta[i].d[j].pw.length();
2789 commentLen = dti.dta[i].d[j].comment.length(); 2789 commentLen = dti.dta[i].d[j].comment.length();
2790 entry[0] = new char[descLen + 1]; 2790 entry[0] = new char[descLen + 1];
2791 entry[1] = new char[nameLen + 1]; 2791 entry[1] = new char[nameLen + 1];
2792 entry[2] = new char[pwLen + 1]; 2792 entry[2] = new char[pwLen + 1];
2793 entry[3] = new char[commentLen + 1]; 2793 entry[3] = new char[commentLen + 1];
2794 strcpy(entry[0], descLen == 0 ? " " : dti.dta[i].d[j].desc.c_str()); 2794 strcpy(entry[0], descLen == 0 ? " " : dti.dta[i].d[j].desc.c_str());
2795 strcpy(entry[1], nameLen == 0 ? " " : dti.dta[i].d[j].name.c_str()); 2795 strcpy(entry[1], nameLen == 0 ? " " : dti.dta[i].d[j].name.c_str());
2796 strcpy(entry[2], pwLen == 0 ? " " : dti.dta[i].d[j].pw.c_str()); 2796 strcpy(entry[2], pwLen == 0 ? " " : dti.dta[i].d[j].pw.c_str());
2797 strcpy(entry[3], commentLen == 0 ? " " : dti.dta[i].d[j].comment.c_str()); 2797 strcpy(entry[3], commentLen == 0 ? " " : dti.dta[i].d[j].comment.c_str());
2798 entry[0][descLen == 0 ? descLen + 1 : descLen] = '\0'; 2798 entry[0][descLen == 0 ? descLen + 1 : descLen] = '\0';
2799 entry[1][nameLen == 0 ? nameLen + 1 : nameLen] = '\0'; 2799 entry[1][nameLen == 0 ? nameLen + 1 : nameLen] = '\0';
2800 entry[2][pwLen == 0 ? pwLen + 1 : pwLen] = '\0'; 2800 entry[2][pwLen == 0 ? pwLen + 1 : pwLen] = '\0';
2801 entry[3][commentLen == 0 ? commentLen + 1 : commentLen] = '\0'; 2801 entry[3][commentLen == 0 ? commentLen + 1 : commentLen] = '\0';
2802 2802
2803 ret = gp.save_entry(entry); 2803 ret = gp.save_entry(entry);
2804 if (ret == -1){ 2804 if (ret == -1){
2805 delete [] entry[0]; 2805 delete [] entry[0];
2806 delete [] entry[1]; 2806 delete [] entry[1];
2807 delete [] entry[2]; 2807 delete [] entry[2];
2808 delete [] entry[3]; 2808 delete [] entry[3];
2809 gp.save_finalize(); 2809 gp.save_finalize();
2810 unlockAll_tempoary(true); 2810 unlockAll_tempoary(true);
2811 return e_writeFile; 2811 return e_writeFile;
2812 } 2812 }
2813 2813
2814 delete [] entry[0]; 2814 delete [] entry[0];
2815 delete [] entry[1]; 2815 delete [] entry[1];
2816 delete [] entry[2]; 2816 delete [] entry[2];
2817 delete [] entry[3]; 2817 delete [] entry[3];
2818 } 2818 }
2819 } 2819 }
2820 unlockAll_tempoary(true); 2820 unlockAll_tempoary(true);
2821 if (gp.save_finalize() == -1) 2821 if (gp.save_finalize() == -1)
2822 return e_writeFile; 2822 return e_writeFile;
2823 2823
2824 return e_success; 2824 return e_success;
2825} 2825}
2826 2826
2827PwMerror PwMDoc::importFromGpasman(const QString *file) 2827PwMerror PwMDoc::importFromGpasman(const QString *file)
2828{ 2828{
2829 PWM_ASSERT(file); 2829 PWM_ASSERT(file);
2830 QString pw = requestMpw(false); 2830 QString pw = requestMpw(false);
2831 if (pw == "") 2831 if (pw == "")
2832 return e_noPw; 2832 return e_noPw;
2833 GpasmanFile gp; 2833 GpasmanFile gp;
2834 int ret, i; 2834 int ret, i;
2835 PwMerror ret2; 2835 PwMerror ret2;
2836 char *entry[4]; 2836 char *entry[4];
2837 PwMDataItem tmpData; 2837 PwMDataItem tmpData;
2838 ret = gp.load_init(file->latin1(), pw.latin1()); 2838 ret = gp.load_init(file->latin1(), pw.latin1());
2839 if (ret != 1) 2839 if (ret != 1)
2840 return e_accessFile; 2840 return e_accessFile;
2841 2841
2842 do { 2842 do {
2843 ret = gp.load_entry(entry); 2843 ret = gp.load_entry(entry);
2844 if(ret != 1) 2844 if(ret != 1)
2845 break; 2845 break;
2846 tmpData.desc = entry[0]; 2846 tmpData.desc = entry[0];
2847 tmpData.name = entry[1]; 2847 tmpData.name = entry[1];
2848 tmpData.pw = entry[2]; 2848 tmpData.pw = entry[2];
2849 tmpData.comment = entry[3]; 2849 tmpData.comment = entry[3];
2850 tmpData.lockStat = true; 2850 tmpData.lockStat = true;
2851 tmpData.listViewPos = -1; 2851 tmpData.listViewPos = -1;
2852 ret2 = addEntry(DEFAULT_CATEGORY, &tmpData, true); 2852 ret2 = addEntry(DEFAULT_CATEGORY, &tmpData, true);
2853 for (i = 0; i < 4; ++i) 2853 for (i = 0; i < 4; ++i)
2854 free(entry[i]); 2854 free(entry[i]);
2855 if (ret2 == e_maxAllowedEntr) { 2855 if (ret2 == e_maxAllowedEntr) {
2856 gp.load_finalize(); 2856 gp.load_finalize();
2857 return e_maxAllowedEntr; 2857 return e_maxAllowedEntr;
2858 } 2858 }
2859 } while (1); 2859 } while (1);
2860 gp.load_finalize(); 2860 gp.load_finalize();
2861 if (isDocEmpty()) 2861 if (isDocEmpty())
2862 return e_wrongPw; // we assume this. 2862 return e_wrongPw; // we assume this.
2863 2863
2864 flagDirty(); 2864 flagDirty();
2865 return e_success; 2865 return e_success;
2866} 2866}
2867 2867
2868 2868
2869//US: we use the stl sort algorythm to sort all elements in the order 2869//US: we use the stl sort algorythm to sort all elements in the order
2870//of its listViewPos (in the order 1,2,3,5,...,x,-1, -1, -1 2870//of its listViewPos (in the order 1,2,3,5,...,x,-1, -1, -1
2871struct PwMDataItemListViewPosSort 2871struct PwMDataItemListViewPosSort
2872{ 2872{
2873 bool operator()(PwMDataItem* rpStart, PwMDataItem* rpEnd) 2873 bool operator()(PwMDataItem* rpStart, PwMDataItem* rpEnd)
2874 { 2874 {
2875 //qDebug("pwMDoc::PwMDataItemListViewPosSort()"); 2875 //qDebug("pwMDoc::PwMDataItemListViewPosSort()");
2876 if ((rpEnd)->listViewPos < 0) 2876 if ((rpEnd)->listViewPos < 0)
2877 return false; 2877 return false;
2878 else 2878 else
2879 return (rpStart)->listViewPos < (rpEnd)->listViewPos; 2879 return (rpStart)->listViewPos < (rpEnd)->listViewPos;
2880 } 2880 }
2881}; 2881};
2882 2882
2883void PwMDoc::ensureLvp() 2883void PwMDoc::ensureLvp()
2884{ 2884{
2885 if (isDocEmpty()) 2885 if (isDocEmpty())
2886 return; 2886 return;
2887 2887
2888 //US ENH BUG: when using syncronizing, this way of sorting 2888 //US ENH BUG: when using syncronizing, this way of sorting
2889 //is not sufficient, because there might be empty spaces 2889 //is not sufficient, because there might be empty spaces
2890 // at the beginning. But the old algorythm only can add elements 2890 // at the beginning. But the old algorythm only can add elements
2891 //to the end.The result are crashes because of list overflows 2891 //to the end.The result are crashes because of list overflows
2892 //we need something to fill all gaps. 2892 //we need something to fill all gaps.
2893 vector<PwMDataItem*> sorted; 2893 vector<PwMDataItem*> sorted;
2894 vector< PwMDataItem*>::iterator sortedBegin, 2894 vector< PwMDataItem*>::iterator sortedBegin,
2895 sortedEnd, 2895 sortedEnd,
2896 sortedI; 2896 sortedI;
2897 vector<PwMCategoryItem>::iterator catBegin = dti.dta.begin(), 2897 vector<PwMCategoryItem>::iterator catBegin = dti.dta.begin(),
2898 catEnd = dti.dta.end(), 2898 catEnd = dti.dta.end(),
2899 catI = catBegin; 2899 catI = catBegin;
2900 vector<PwMDataItem>::iterator entrBegin, entrEnd, entrI; 2900 vector<PwMDataItem>::iterator entrBegin, entrEnd, entrI;
2901 int lvpTop, tmpLvp; 2901 int lvpTop, tmpLvp;
2902 2902
2903 //qDebug("collect:"); 2903 //qDebug("collect:");
2904 2904
2905 while (catI != catEnd) { 2905 while (catI != catEnd) {
2906 lvpTop = -1; 2906 lvpTop = -1;
2907 sorted.clear(); 2907 sorted.clear();
2908 2908
2909 entrBegin = catI->d.begin(); 2909 entrBegin = catI->d.begin();
2910 entrEnd = catI->d.end(); 2910 entrEnd = catI->d.end();
2911 entrI = entrBegin; 2911 entrI = entrBegin;
2912 2912
2913 //US: we use the stl sort algorythm to sort all elements in the order 2913 //US: we use the stl sort algorythm to sort all elements in the order
2914 //of its listViewPos (in the order 1,2,2,3,5,...,x,-1, -1, -1 2914 //of its listViewPos (in the order 1,2,2,3,5,...,x,-1, -1, -1
2915 while (entrI != entrEnd) { 2915 while (entrI != entrEnd) {
2916 //qDebug("found: %s, pos=%i", (*entrI).desc.c_str(), (*entrI).listViewPos); 2916 //qDebug("found: %s, pos=%i", (*entrI).desc.c_str(), (*entrI).listViewPos);
2917 sorted.push_back((PwMDataItem*)&(*entrI)); 2917 sorted.push_back((PwMDataItem*)&(*entrI));
2918 ++entrI; 2918 ++entrI;
2919 } 2919 }
2920 2920
2921 sortedBegin = sorted.begin(); 2921 sortedBegin = sorted.begin();
2922 sortedEnd = sorted.end(); 2922 sortedEnd = sorted.end();
2923 2923
2924 sort(sortedBegin, sortedEnd, PwMDataItemListViewPosSort()); 2924 sort(sortedBegin, sortedEnd, PwMDataItemListViewPosSort());
2925 2925
2926 // qDebug("resort:"); 2926 // qDebug("resort:");
2927 //now we have all sorted in a collection 2927 //now we have all sorted in a collection
2928 //Now start with the sorted and reset listviewpos. 2928 //Now start with the sorted and reset listviewpos.
2929 sortedBegin = sorted.begin(); 2929 sortedBegin = sorted.begin();
2930 sortedEnd = sorted.end(); 2930 sortedEnd = sorted.end();
2931 sortedI = sortedBegin; 2931 sortedI = sortedBegin;
2932 2932
2933 while (sortedI != sortedEnd) { 2933 while (sortedI != sortedEnd) {
2934 // qDebug("reset defined: %s, from pos=%i to pos=%i", (*sortedI)->desc.c_str(), (*sortedI)->listViewPos, lvpTop+1); 2934 // qDebug("reset defined: %s, from pos=%i to pos=%i", (*sortedI)->desc.c_str(), (*sortedI)->listViewPos, lvpTop+1);
2935 (*sortedI)->listViewPos = ++lvpTop; 2935 (*sortedI)->listViewPos = ++lvpTop;
2936 ++sortedI; 2936 ++sortedI;
2937 } 2937 }
2938 2938
2939 /*/debug 2939 /*/debug
2940 entrBegin = catI->d.begin(); 2940 entrBegin = catI->d.begin();
2941 entrEnd = catI->d.end(); 2941 entrEnd = catI->d.end();
2942 entrI = entrBegin; 2942 entrI = entrBegin;
2943 2943
2944 while (entrI != entrEnd) { 2944 while (entrI != entrEnd) {
2945 qDebug("check: %s, pos=%i", (*entrI).desc.c_str(), (*entrI).listViewPos); 2945 qDebug("check: %s, pos=%i", (*entrI).desc.c_str(), (*entrI).listViewPos);
2946 ++entrI; 2946 ++entrI;
2947 } 2947 }
2948 */ 2948 */
2949 2949
2950 ++catI; 2950 ++catI;
2951 } 2951 }
2952} 2952}
2953 2953
2954QString PwMDoc::getTitle() 2954QString PwMDoc::getTitle()
2955{ 2955{
2956 /* NOTE: We have to ensure, that the returned title 2956 /* NOTE: We have to ensure, that the returned title
2957 * is unique and not reused somewhere else while 2957 * is unique and not reused somewhere else while
2958 * this document is valid (open). 2958 * this document is valid (open).
2959 */ 2959 */
2960 QString title(getFilename()); 2960 QString title(getFilename());
2961 2961
2962 //US ENH: The whole filename on PDAs is too long. So use only the last characters 2962 //US ENH: The whole filename on PDAs is too long. So use only the last characters
2963 if (QApplication::desktop()->width() < 640) 2963 if (QApplication::desktop()->width() < 640)
2964 { 2964 {
2965 if (title.length() > 30) 2965 if (title.length() > 30)
2966 title = "..." + title.right(30); 2966 title = "..." + title.right(30);
2967 2967
2968 } 2968 }
2969 2969
2970 2970
2971 if (title.isEmpty()) { 2971 if (title.isEmpty()) {
2972 if (unnamedNum == 0) { 2972 if (unnamedNum == 0) {
2973 unnamedNum = PwMDocList::getNewUnnamedNumber(); 2973 unnamedNum = PwMDocList::getNewUnnamedNumber();
2974 PWM_ASSERT(unnamedNum != 0); 2974 PWM_ASSERT(unnamedNum != 0);
2975 } 2975 }
2976 title = DEFAULT_TITLE; 2976 title = DEFAULT_TITLE;
2977 title += " "; 2977 title += " ";
2978 title += tostr(unnamedNum).c_str(); 2978 title += tostr(unnamedNum).c_str();
2979 } 2979 }
2980 return title; 2980 return title;
2981} 2981}
2982 2982
2983bool PwMDoc::tryDelete() 2983bool PwMDoc::tryDelete()
2984{ 2984{
2985 2985
2986 if (deleted) 2986 if (deleted)
2987 return true; 2987 return true;
2988 int ret; 2988 int ret;
2989 if (isDirty()) { 2989 if (isDirty()) {
2990 ret = dirtyAskSave(getTitle()); 2990 ret = dirtyAskSave(getTitle());
2991 if (ret == 0) { // save to disk 2991 if (ret == 0) { // save to disk
2992 if (!saveDocUi(this)) 2992 if (!saveDocUi(this))
2993 goto out_ignore; 2993 goto out_ignore;
2994 } else if (ret == 1) { // don't save and delete 2994 } else if (ret == 1) { // don't save and delete
2995 goto out_accept; 2995 goto out_accept;
2996 } else { // cancel operation 2996 } else { // cancel operation
2997 goto out_ignore; 2997 goto out_ignore;
2998 } 2998 }
2999 } 2999 }
3000out_accept: 3000out_accept:
3001 deleted = true; 3001 deleted = true;
3002 delete this; 3002 delete this;
3003 return true; 3003 return true;
3004out_ignore: 3004out_ignore:
3005 return false; 3005 return false;
3006} 3006}
3007 3007
3008 3008
3009 3009
3010#ifdef PWM_EMBEDDED 3010#ifdef PWM_EMBEDDED
3011//US ENH: this is the magic function that syncronizes the this doc with the remote doc 3011//US ENH: this is the magic function that syncronizes the this doc with the remote doc
3012//US it could have been defined as static, but I did not want to. 3012//US it could have been defined as static, but I did not want to.
3013PwMerror PwMDoc::syncronize(KSyncManager* manager, PwMDoc* syncLocal , PwMDoc* syncRemote, int mode ) 3013PwMerror PwMDoc::syncronize(KSyncManager* manager, PwMDoc* syncLocal , PwMDoc* syncRemote, int mode )
3014{ 3014{
3015 int addedPasswordsLocal = 0; 3015 int addedPasswordsLocal = 0;
3016 int addedPasswordsRemote = 0; 3016 int addedPasswordsRemote = 0;
3017 int deletedPasswordsRemote = 0; 3017 int deletedPasswordsRemote = 0;
3018 int deletedPasswordsLocal = 0; 3018 int deletedPasswordsLocal = 0;
3019 int changedLocal = 0; 3019 int changedLocal = 0;
3020 int changedRemote = 0; 3020 int changedRemote = 0;
3021 3021
3022 PwMSyncItem* syncItemLocal; 3022 PwMSyncItem* syncItemLocal;
3023 PwMSyncItem* syncItemRemote; 3023 PwMSyncItem* syncItemRemote;
3024 3024
3025 QString mCurrentSyncName = manager->getCurrentSyncName(); 3025 QString mCurrentSyncName = manager->getCurrentSyncName();
3026 QString mCurrentSyncDevice = manager->getCurrentSyncDevice(); 3026 QString mCurrentSyncDevice = manager->getCurrentSyncDevice();
3027 3027
3028 bool mSyncLauncher = true; 3028 bool mSyncLauncher = true;
3029 3029
3030 bool fullDateRange = false; 3030 bool fullDateRange = false;
3031 int take; 3031 int take;
3032 // local->resetTempSyncStat(); 3032 // local->resetTempSyncStat();
3033 QDateTime mLastSync = QDateTime::currentDateTime(); 3033 QDateTime mLastSync = QDateTime::currentDateTime();
3034 QDateTime modifiedSync = mLastSync; 3034 QDateTime modifiedSync = mLastSync;
3035 3035
3036 unsigned int index; 3036 unsigned int index;
3037 //Step 1. Find syncinfo in Local file and create if not existent. 3037 //Step 1. Find syncinfo in Local file and create if not existent.
3038 bool found = syncLocal->findSyncData(mCurrentSyncDevice, &index); 3038 bool found = syncLocal->findSyncData(mCurrentSyncDevice, &index);
3039 if (found == false) 3039 if (found == false)
3040 { 3040 {
3041 PwMSyncItem newSyncItemLocal; 3041 PwMSyncItem newSyncItemLocal;
3042 newSyncItemLocal.syncName = mCurrentSyncDevice.latin1(); 3042 newSyncItemLocal.syncName = mCurrentSyncDevice.latin1();
3043 newSyncItemLocal.lastSyncDate = mLastSync; 3043 newSyncItemLocal.lastSyncDate = mLastSync;
3044 syncLocal->addSyncDataEntry(&newSyncItemLocal, true); 3044 syncLocal->addSyncDataEntry(&newSyncItemLocal, true);
3045 found = syncLocal->findSyncData(mCurrentSyncDevice, &index); 3045 found = syncLocal->findSyncData(mCurrentSyncDevice, &index);
3046 if (found == false) { 3046 if (found == false) {
3047 qDebug("PwMDoc::syncronize : newly created local sync data could not be found"); 3047 qDebug("PwMDoc::syncronize : newly created local sync data could not be found");
3048 return e_syncError; 3048 return e_syncError;
3049 } 3049 }
3050 } 3050 }
3051 3051
3052 syncItemLocal = syncLocal->getSyncDataEntry(index); 3052 syncItemLocal = syncLocal->getSyncDataEntry(index);
3053 qDebug("Last Sync Local %s ", syncItemLocal->lastSyncDate.toString().latin1()); 3053 qDebug("Last Sync Local %s ", syncItemLocal->lastSyncDate.toString().latin1());
3054 3054
3055 //Step 2. Find syncinfo in remote file and create if not existent. 3055 //Step 2. Find syncinfo in remote file and create if not existent.
3056 found = syncRemote->findSyncData(mCurrentSyncName, &index); 3056 found = syncRemote->findSyncData(mCurrentSyncName, &index);
3057 if (found == false) 3057 if (found == false)
3058 { 3058 {
3059 qDebug("FULLDATE 1"); 3059 qDebug("FULLDATE 1");
3060 fullDateRange = true; 3060 fullDateRange = true;
3061 PwMSyncItem newSyncItemRemote; 3061 PwMSyncItem newSyncItemRemote;
3062 newSyncItemRemote.syncName = mCurrentSyncName.latin1(); 3062 newSyncItemRemote.syncName = mCurrentSyncName.latin1();
3063 newSyncItemRemote.lastSyncDate = mLastSync; 3063 newSyncItemRemote.lastSyncDate = mLastSync;
3064 syncRemote->addSyncDataEntry(&newSyncItemRemote, true); 3064 syncRemote->addSyncDataEntry(&newSyncItemRemote, true);
3065 found = syncRemote->findSyncData(mCurrentSyncName, &index); 3065 found = syncRemote->findSyncData(mCurrentSyncName, &index);
3066 if (found == false) { 3066 if (found == false) {
3067 qDebug("PwMDoc::syncronize : newly created remote sync data could not be found"); 3067 qDebug("PwMDoc::syncronize : newly created remote sync data could not be found");
3068 return e_syncError; 3068 return e_syncError;
3069 } 3069 }
3070 } 3070 }
3071 3071
3072 syncItemRemote = syncRemote->getSyncDataEntry(index); 3072 syncItemRemote = syncRemote->getSyncDataEntry(index);
3073 qDebug("Last Sync Remote %s ", syncItemRemote->lastSyncDate.toString().latin1()); 3073 qDebug("Last Sync Remote %s ", syncItemRemote->lastSyncDate.toString().latin1());
3074 //and remove the found entry here. We will reenter it later again. 3074 //and remove the found entry here. We will reenter it later again.
3075 //US syncRemote->delSyncDataEntry(index, true); 3075 //US syncRemote->delSyncDataEntry(index, true);
3076 3076
3077 3077
3078 if ( syncItemLocal->lastSyncDate == mLastSync ) { 3078 if ( syncItemLocal->lastSyncDate == mLastSync ) {
3079 qDebug("FULLDATE 2"); 3079 qDebug("FULLDATE 2");
3080 fullDateRange = true; 3080 fullDateRange = true;
3081 } 3081 }
3082 3082
3083 if ( ! fullDateRange ) { 3083 if ( ! fullDateRange ) {
3084 if ( syncItemLocal->lastSyncDate != syncItemRemote->lastSyncDate ) { 3084 if ( syncItemLocal->lastSyncDate != syncItemRemote->lastSyncDate ) {
3085 3085
3086 fullDateRange = true; 3086 fullDateRange = true;
3087 qDebug("FULLDATE 3 %s %s", syncItemLocal->lastSyncDate.toString().latin1() , syncItemRemote->lastSyncDate.toString().latin1() ); 3087 qDebug("FULLDATE 3 %s %s", syncItemLocal->lastSyncDate.toString().latin1() , syncItemRemote->lastSyncDate.toString().latin1() );
3088 } 3088 }
3089 } 3089 }
3090 // fullDateRange = true; // debug only! 3090 // fullDateRange = true; // debug only!
3091 if ( fullDateRange ) 3091 if ( fullDateRange )
3092 mLastSync = QDateTime::currentDateTime().addDays( -100*365); 3092 mLastSync = QDateTime::currentDateTime().addDays( -100*365);
3093 else 3093 else
3094 mLastSync = syncItemLocal->lastSyncDate; 3094 mLastSync = syncItemLocal->lastSyncDate;
3095 3095
3096 3096
3097 qDebug("*************************** "); 3097 qDebug("*************************** ");
3098 qDebug("mLastSync %s ",mLastSync.toString().latin1() ); 3098 qDebug("mLastSync %s ",mLastSync.toString().latin1() );
3099 QStringList er = syncRemote->getIDEntryList(); 3099 QStringList er = syncRemote->getIDEntryList();
3100 PwMDataItem* inRemote ;//= er.first(); 3100 PwMDataItem* inRemote ;//= er.first();
3101 PwMDataItem* inLocal; 3101 PwMDataItem* inLocal;
3102 unsigned int catLocal, indexLocal; 3102 unsigned int catLocal, indexLocal;
3103 unsigned int catRemote, indexRemote; 3103 unsigned int catRemote, indexRemote;
3104 3104
3105 QString uid; 3105 QString uid;
3106 manager->showProgressBar(0, i18n("Syncing - close to abort!"), er.count()); 3106 manager->showProgressBar(0, i18n("Syncing - close to abort!"), er.count());
3107 3107
3108 int modulo = (er.count()/10)+1; 3108 int modulo = (er.count()/10)+1;
3109 unsigned int incCounter = 0; 3109 unsigned int incCounter = 0;
3110 while ( incCounter < er.count()) { 3110 while ( incCounter < er.count()) {
3111 if (manager->isProgressBarCanceled()) 3111 if (manager->isProgressBarCanceled())
3112 return e_syncError; 3112 return e_syncError;
3113 if ( incCounter % modulo == 0 ) 3113 if ( incCounter % modulo == 0 )
3114 manager->showProgressBar(incCounter); 3114 manager->showProgressBar(incCounter);
3115 3115
3116 uid = er[ incCounter ]; 3116 uid = er[ incCounter ];
3117 qDebug("sync uid %s from remote file", uid.latin1()); 3117 qDebug("sync uid %s from remote file", uid.latin1());
3118 3118
3119 qApp->processEvents(); 3119 qApp->processEvents();
3120 3120
3121 inLocal = syncLocal->findEntryByID( uid, &catLocal, &indexLocal ); 3121 inLocal = syncLocal->findEntryByID( uid, &catLocal, &indexLocal );
3122 inRemote = syncRemote->findEntryByID( uid, &catRemote, &indexRemote ); 3122 inRemote = syncRemote->findEntryByID( uid, &catRemote, &indexRemote );
3123 PWM_ASSERT(inRemote); 3123 PWM_ASSERT(inRemote);
3124 if ( inLocal != 0 ) { // maybe conflict - same uid in both files 3124 if ( inLocal != 0 ) { // maybe conflict - same uid in both files
3125 if ( (take = takePwMDataItem( inLocal, inRemote, mLastSync, mode, fullDateRange) ) ) { 3125 if ( (take = takePwMDataItem( inLocal, inRemote, mLastSync, mode, fullDateRange) ) ) {
3126 qDebug("take %d %s ", take, inLocal->desc.c_str()); 3126 qDebug("take %d %s ", take, inLocal->desc.c_str());
3127 if ( take == 3 ) 3127 if ( take == 3 )
3128 return e_syncError; 3128 return e_syncError;
3129 if ( take == 1 ) {// take local 3129 if ( take == 1 ) {// take local
3130 inRemote->syncItem(*inLocal, mSyncLauncher); 3130 inRemote->syncItem(*inLocal, mSyncLauncher);
3131 ++changedRemote; 3131 ++changedRemote;
3132 } else { // take == 2 take remote 3132 } else { // take == 2 take remote
3133 inLocal->syncItem(*inRemote, mSyncLauncher); 3133 inLocal->syncItem(*inRemote, mSyncLauncher);
3134 ++changedLocal; 3134 ++changedLocal;
3135 } 3135 }
3136 } 3136 }
3137 } else { // no conflict 3137 } else { // no conflict
3138 if ( inRemote->meta.update > mLastSync || mode == 5 ) { 3138 if ( inRemote->meta.update > mLastSync || mode == 5 ) {
3139 inRemote->meta.update = modifiedSync; 3139 inRemote->meta.update = modifiedSync;
3140 3140
3141 //first check if we have a matching category in the local file 3141 //first check if we have a matching category in the local file
3142 const string* remotecat = syncRemote->getCategory(catRemote); 3142 const string* remotecat = syncRemote->getCategory(catRemote);
3143 syncLocal->addEntry(remotecat->c_str(), inRemote, true, false); 3143 syncLocal->addEntry(remotecat->c_str(), inRemote, true, false);
3144 3144
3145 ++addedPasswordsLocal; 3145 ++addedPasswordsLocal;
3146 } else { 3146 } else {
3147 // pending checkExternSyncAddressee(addresseeRSyncSharp, inR); 3147 // pending checkExternSyncAddressee(addresseeRSyncSharp, inR);
3148 syncRemote->delEntry(catRemote, indexRemote, true); 3148 syncRemote->delEntry(catRemote, indexRemote, true);
3149 ++deletedPasswordsRemote; 3149 ++deletedPasswordsRemote;
3150 } 3150 }
3151 } 3151 }
3152 3152
3153 ++incCounter; 3153 ++incCounter;
3154 } 3154 }
3155 3155
3156 3156
3157 er.clear(); 3157 er.clear();
3158 QStringList el = syncLocal->getIDEntryList(); 3158 QStringList el = syncLocal->getIDEntryList();
3159 modulo = (el.count()/10)+1; 3159 modulo = (el.count()/10)+1;
3160 3160
3161 manager->showProgressBar(0, i18n("Add / remove addressees"), el.count()); 3161 manager->showProgressBar(0, i18n("Add / remove addressees"), el.count());
3162 incCounter = 0; 3162 incCounter = 0;
3163 while ( incCounter < el.count()) { 3163 while ( incCounter < el.count()) {
3164 qApp->processEvents(); 3164 qApp->processEvents();
3165 if (manager->isProgressBarCanceled()) 3165 if (manager->isProgressBarCanceled())
3166 return e_syncError; 3166 return e_syncError;
3167 if ( incCounter % modulo == 0 ) 3167 if ( incCounter % modulo == 0 )
3168 manager->showProgressBar(incCounter); 3168 manager->showProgressBar(incCounter);
3169 uid = el[ incCounter ]; 3169 uid = el[ incCounter ];
3170 qDebug("sync uid %s from local file", uid.latin1()); 3170 qDebug("sync uid %s from local file", uid.latin1());
3171 3171
3172 inLocal = syncLocal->findEntryByID( uid, &catLocal, &indexLocal ); 3172 inLocal = syncLocal->findEntryByID( uid, &catLocal, &indexLocal );
3173 inRemote = syncRemote->findEntryByID( uid, &catRemote, &indexRemote ); 3173 inRemote = syncRemote->findEntryByID( uid, &catRemote, &indexRemote );
3174 PWM_ASSERT(inLocal); 3174 PWM_ASSERT(inLocal);
3175 3175
3176 if ( inRemote == 0 ) { 3176 if ( inRemote == 0 ) {
3177 if ( inLocal->meta.update < mLastSync && mode != 4 ) { 3177 if ( inLocal->meta.update < mLastSync && mode != 4 ) {
3178 // pending checkExternSyncAddressee(addresseeLSyncSharp, inL); 3178 // pending checkExternSyncAddressee(addresseeLSyncSharp, inL);
3179 syncLocal->delEntry(catLocal, indexLocal, true); 3179 syncLocal->delEntry(catLocal, indexLocal, true);
3180 ++deletedPasswordsLocal; 3180 ++deletedPasswordsLocal;
3181 } else { 3181 } else {
3182 if ( ! manager->mWriteBackExistingOnly ) { 3182 if ( ! manager->mWriteBackExistingOnly ) {
3183 ++addedPasswordsRemote; 3183 ++addedPasswordsRemote;
3184 inLocal->meta.update = modifiedSync; 3184 inLocal->meta.update = modifiedSync;
3185 3185
3186 //first check if we have a matching category in the remote file 3186 //first check if we have a matching category in the remote file
3187 const string* localcat = syncLocal->getCategory(catLocal); 3187 const string* localcat = syncLocal->getCategory(catLocal);
3188 3188
3189 PwMDataItem newEntry; 3189 PwMDataItem newEntry;
3190 newEntry = *inLocal; 3190 newEntry = *inLocal;
3191 inRemote = &newEntry; 3191 inRemote = &newEntry;
3192 3192
3193 //USsyncRemote->insertAddressee( inRemote, false ); 3193 //USsyncRemote->insertAddressee( inRemote, false );
3194 syncRemote->addEntry(localcat->c_str(), inRemote, true, false); 3194 syncRemote->addEntry(localcat->c_str(), inRemote, true, false);
3195 3195
3196 } 3196 }
3197 } 3197 }
3198 3198
3199 } 3199 }
3200 ++incCounter; 3200 ++incCounter;
3201 } 3201 }
3202 el.clear(); 3202 el.clear();
3203 manager->hideProgressBar(); 3203 manager->hideProgressBar();
3204 3204
3205 // Now write the info back into the sync data space of the files 3205 // Now write the info back into the sync data space of the files
3206 3206
3207 mLastSync = QDateTime::currentDateTime().addSecs( 1 ); 3207 mLastSync = QDateTime::currentDateTime().addSecs( 1 );
3208 // get rid of micro seconds 3208 // get rid of micro seconds
3209 QTime t = mLastSync.time(); 3209 QTime t = mLastSync.time();
3210 mLastSync.setTime( QTime (t.hour (), t.minute (), t.second () ) ); 3210 mLastSync.setTime( QTime (t.hour (), t.minute (), t.second () ) );
3211 3211
3212 3212
3213 syncItemLocal->lastSyncDate = mLastSync; 3213 syncItemLocal->lastSyncDate = mLastSync;
3214 syncItemRemote->lastSyncDate = mLastSync; 3214 syncItemRemote->lastSyncDate = mLastSync;
3215 3215
3216 QString mes; 3216 QString mes;
3217 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 ); 3217 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 );
3218 if ( manager->mShowSyncSummary ) { 3218 if ( manager->mShowSyncSummary ) {
3219 KMessageBox::information(0, mes, i18n("PWM/Pi Synchronization") ); 3219 KMessageBox::information(0, mes, i18n("PWM/Pi Synchronization") );
3220 } 3220 }
3221 qDebug( mes ); 3221 qDebug( mes );
3222 return e_success; 3222 return e_success;
3223} 3223}
3224 3224
3225 3225
3226int PwMDoc::takePwMDataItem( PwMDataItem* local, PwMDataItem* remote, QDateTime lastSync, int mode , bool full ) 3226int PwMDoc::takePwMDataItem( PwMDataItem* local, PwMDataItem* remote, QDateTime lastSync, int mode , bool full )
3227{ 3227{
3228 // 0 equal 3228 // 0 equal
3229 // 1 take local 3229 // 1 take local
3230 // 2 take remote 3230 // 2 take remote
3231 // 3 cancel 3231 // 3 cancel
3232 QDateTime localMod = local->meta.update; 3232 QDateTime localMod = local->meta.update;
3233 QDateTime remoteMod = remote->meta.update; 3233 QDateTime remoteMod = remote->meta.update;
3234 3234
3235 if ( localMod == remoteMod ) 3235 if ( localMod == remoteMod )
3236 return 0; 3236 return 0;
3237 3237
3238 qDebug(" %d %d conflict on %s %s ", mode, full, local->desc.c_str(), remote->desc.c_str() ); 3238 qDebug(" %d %d conflict on %s %s ", mode, full, local->desc.c_str(), remote->desc.c_str() );
3239 3239
3240 //qDebug("%s %d %s %d", local->lastModified().toString().latin1() , localMod, remote->lastModified().toString().latin1(), remoteMod); 3240 //qDebug("%s %d %s %d", local->lastModified().toString().latin1() , localMod, remote->lastModified().toString().latin1(), remoteMod);
3241 //qDebug("%d %d %d %d ", local->lastModified().time().second(), local->lastModified().time().msec(), remote->lastModified().time().second(), remote->lastModified().time().msec() ); 3241 //qDebug("%d %d %d %d ", local->lastModified().time().second(), local->lastModified().time().msec(), remote->lastModified().time().second(), remote->lastModified().time().msec() );
3242 //full = true; //debug only 3242 //full = true; //debug only
3243 if ( full ) { 3243 if ( full ) {
3244 bool equ = ( (*local) == (*remote) ); 3244 bool equ = ( (*local) == (*remote) );
3245 if ( equ ) { 3245 if ( equ ) {
3246 //qDebug("equal "); 3246 //qDebug("equal ");
3247 if ( mode < SYNC_PREF_FORCE_LOCAL ) 3247 if ( mode < SYNC_PREF_FORCE_LOCAL )
3248 return 0; 3248 return 0;
3249 3249
3250 }//else //debug only 3250 }//else //debug only
3251 //qDebug("not equal %s %s ", local->desc.c_str(), remote->desc.c_str()); 3251 //qDebug("not equal %s %s ", local->desc.c_str(), remote->desc.c_str());
3252 } 3252 }
3253 3253
3254 int result; 3254 int result;
3255 bool localIsNew; 3255 bool localIsNew;
3256 //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() ); 3256 //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() );
3257 3257
3258 if ( full && mode < SYNC_PREF_NEWEST ) 3258 if ( full && mode < SYNC_PREF_NEWEST )
3259 mode = SYNC_PREF_ASK; 3259 mode = SYNC_PREF_ASK;
3260 3260
3261 switch( mode ) { 3261 switch( mode ) {
3262 case SYNC_PREF_LOCAL: 3262 case SYNC_PREF_LOCAL:
3263 if ( lastSync > remoteMod ) 3263 if ( lastSync > remoteMod )
3264 return 1; 3264 return 1;
3265 if ( lastSync > localMod ) 3265 if ( lastSync > localMod )
3266 return 2; 3266 return 2;
3267 return 1; 3267 return 1;
3268 break; 3268 break;
3269 case SYNC_PREF_REMOTE: 3269 case SYNC_PREF_REMOTE:
3270 if ( lastSync > remoteMod ) 3270 if ( lastSync > remoteMod )
3271 return 1; 3271 return 1;
3272 if ( lastSync > localMod ) 3272 if ( lastSync > localMod )
3273 return 2; 3273 return 2;
3274 return 2; 3274 return 2;
3275 break; 3275 break;
3276 case SYNC_PREF_NEWEST: 3276 case SYNC_PREF_NEWEST:
3277 if ( localMod > remoteMod ) 3277 if ( localMod > remoteMod )
3278 return 1; 3278 return 1;
3279 else 3279 else
3280 return 2; 3280 return 2;
3281 break; 3281 break;
3282 case SYNC_PREF_ASK: 3282 case SYNC_PREF_ASK:
3283 //qDebug("lsy %s --- lo %s --- re %s ", lastSync.toString().latin1(), localMod.toString().latin1(), remoteMod.toString().latin1() ); 3283 //qDebug("lsy %s --- lo %s --- re %s ", lastSync.toString().latin1(), localMod.toString().latin1(), remoteMod.toString().latin1() );
3284 if ( lastSync > remoteMod ) 3284 if ( lastSync > remoteMod )
3285 return 1; 3285 return 1;
3286 if ( lastSync > localMod ) 3286 if ( lastSync > localMod )
3287 return 2; 3287 return 2;
3288 localIsNew = localMod >= remoteMod; 3288 localIsNew = localMod >= remoteMod;
3289 //qDebug("conflict! ************************************** "); 3289 //qDebug("conflict! ************************************** ");
3290 { 3290 {
3291 PwMDataItemChooser acd ( *local,*remote, localIsNew , 0/*this*/ ); 3291 PwMDataItemChooser acd ( *local,*remote, localIsNew , 0/*this*/ );
3292 result = acd.executeD(localIsNew); 3292 result = acd.executeD(localIsNew);
3293 return result; 3293 return result;
3294 } 3294 }
3295 break; 3295 break;
3296 case SYNC_PREF_FORCE_LOCAL: 3296 case SYNC_PREF_FORCE_LOCAL:
3297 return 1; 3297 return 1;
3298 break; 3298 break;
3299 case SYNC_PREF_FORCE_REMOTE: 3299 case SYNC_PREF_FORCE_REMOTE:
3300 return 2; 3300 return 2;
3301 break; 3301 break;
3302 3302
3303 default: 3303 default:
3304 // SYNC_PREF_TAKE_BOTH not implemented 3304 // SYNC_PREF_TAKE_BOTH not implemented
3305 break; 3305 break;
3306 } 3306 }
3307 return 0; 3307 return 0;
3308} 3308}
3309 3309
3310void PwMDoc::removeSyncInfo( QString syncProfile) 3310void PwMDoc::removeSyncInfo( QString syncProfile)
3311{ 3311{
3312 qDebug("PwMDoc::not implemented: removeSyncInfo for profile %s ", syncProfile.latin1()); 3312 bool res, found;
3313 unsigned int count, i;
3314 if ( syncProfile.isEmpty() ) {
3315 count = numSyncDataEntries();
3316 for (i = count; count > 0; count-- ) {
3317 res = delSyncDataEntry(i-1, false);
3318 if (res == false) {
3319 qDebug("PwMDoc::removeSyncInfo: could not remove syncprofile");
3320 }
3321 }
3322 } else {
3323 found = findSyncData(syncProfile, &count);
3324 if (found == true)
3325 {
3326 res = delSyncDataEntry(count, false);
3327 if (res == false) {
3328 qDebug("PwMDoc::removeSyncInfo: could not remove %s", syncProfile.latin1());
3329
3330 }
3331 }
3332 }
3313} 3333}
3314 3334
3315 3335
3316//this are the overwritten callbackmethods from the syncinterface 3336//this are the overwritten callbackmethods from the syncinterface
3317bool PwMDoc::sync(KSyncManager* manager, QString filename, int mode) 3337bool PwMDoc::sync(KSyncManager* manager, QString filename, int mode)
3318{ 3338{
3319 QString mCurrentSyncDevice = manager->getCurrentSyncDevice(); 3339 QString mCurrentSyncDevice = manager->getCurrentSyncDevice();
3320 3340
3321 //1) unlock local file first if necessary (ask for password) 3341 //1) unlock local file first if necessary (ask for password)
3322 if (this->isDeepLocked()) { 3342 if (this->isDeepLocked()) {
3323 PwMerror ret = this->deepLock(false); 3343 PwMerror ret = this->deepLock(false);
3324 if (ret != e_success) 3344 if (ret != e_success)
3325 return false; 3345 return false;
3326 } 3346 }
3327 3347
3328 //2) construct and open a new doc on the stack(automatic cleanup of remote file). 3348 //2) construct and open a new doc on the stack(automatic cleanup of remote file).
3329 PwMDoc syncTarget(this, "synctarget"); 3349 PwMDoc syncTarget(this, "synctarget");
3330 PwMDoc* pSyncTarget = &syncTarget; 3350 PwMDoc* pSyncTarget = &syncTarget;
3331 3351
3332 3352
3333 PwMerror err = pSyncTarget->openDoc(&filename, 1 /*== open with all entries locked*/); 3353 PwMerror err = pSyncTarget->openDoc(&filename, 1 /*== open with all entries locked*/);
3334 3354
3335 if (err == e_alreadyOpen) { 3355 if (err == e_alreadyOpen) {
3336 PwMDocList::listItem li; 3356 PwMDocList::listItem li;
3337 if (getOpenDocList()->find(filename.latin1(), &li)) 3357 if (getOpenDocList()->find(filename.latin1(), &li))
3338 pSyncTarget = li.doc; 3358 pSyncTarget = li.doc;
3339 else { 3359 else {
3340 qDebug("PwmDoc::sync: sync failed. Error %i while opening file %s",err, filename.latin1()); 3360 qDebug("PwmDoc::sync: sync failed. Error %i while opening file %s",err, filename.latin1());
3341 return false; 3361 return false;
3342 } 3362 }
3343 } 3363 }
3344 else if (err != e_success) { 3364 else if (err != e_success) {
3345 qDebug("PwmDoc::sync: sync failed. Error %i while opening file %s",err, filename.latin1()); 3365 qDebug("PwmDoc::sync: sync failed. Error %i while opening file %s",err, filename.latin1());
3346 return false; 3366 return false;
3347 } 3367 }
3348 3368
3349 qDebug("PWM file loaded %s,sync mode %d",filename.latin1(), mode ); 3369 qDebug("PWM file loaded %s,sync mode %d",filename.latin1(), mode );
3350 3370
3351 3371
3352 //3) unlock remote file first if necessary (ask for password) 3372 //3) unlock remote file first if necessary (ask for password)
3353 if (pSyncTarget->isDeepLocked()) { 3373 if (pSyncTarget->isDeepLocked()) {
3354 PwMerror ret = pSyncTarget->deepLock(false); 3374 PwMerror ret = pSyncTarget->deepLock(false);
3355 if (ret != e_success) 3375 if (ret != e_success)
3356 return false; 3376 return false;
3357 } 3377 }
3358 3378
3359 3379
3360 err = syncronize(manager, this, pSyncTarget, mode ); 3380 err = syncronize(manager, this, pSyncTarget, mode );
3361 3381
3362 if (err == e_success) { 3382 if (err == e_success) {
3363 if ( manager->mWriteBackFile ){ 3383 if ( manager->mWriteBackFile ){
3364 qDebug("Saving remote PWManager file"); 3384 qDebug("Saving remote PWManager file");
3365 err = pSyncTarget->saveDoc(conf()->confGlobCompression()); 3385 err = pSyncTarget->saveDoc(conf()->confGlobCompression());
3366 if (err != e_success) { 3386 if (err != e_success) {
3367 qDebug("PwmDoc::sync: Sync failed. Error %i while storing file %s",err, filename.latin1()); 3387 qDebug("PwmDoc::sync: Sync failed. Error %i while storing file %s",err, filename.latin1());
3368 return false; 3388 return false;
3369 } 3389 }
3370 } 3390 }
3371 3391
3372 flagDirty(); 3392 flagDirty();
3373 return true; 3393 return true;
3374 } 3394 }
3375 else { 3395 else {
3376 return false; 3396 return false;
3377 } 3397 }
3378} 3398}
3379 3399
3380#endif 3400#endif
3381 3401
3382 3402
3383bool PwMDoc::findSyncData(const QString &syncname, unsigned int *index) 3403bool PwMDoc::findSyncData(const QString &syncname, unsigned int *index)
3384{ 3404{
3385 vector<PwMSyncItem>::iterator i = dti.syncDta.begin(), 3405 vector<PwMSyncItem>::iterator i = dti.syncDta.begin(),
3386 end = dti.syncDta.end(); 3406 end = dti.syncDta.end();
3387 3407
3388 while (i != end) { 3408 while (i != end) {
3389 if ((*i).syncName == syncname.latin1()) { 3409 if ((*i).syncName == syncname.latin1()) {
3390 if (index) { 3410 if (index) {
3391 *index = i - dti.syncDta.begin(); 3411 *index = i - dti.syncDta.begin();
3392 } 3412 }
3393 return true; 3413 return true;
3394 } 3414 }
3395 ++i; 3415 ++i;
3396 } 3416 }
3397 return false; 3417 return false;
3398}; 3418};
3399 3419
3400/** add new syncdataentry */ 3420/** add new syncdataentry */
3401PwMerror PwMDoc::addSyncDataEntry(PwMSyncItem *d, bool dontFlagDirty) 3421PwMerror PwMDoc::addSyncDataEntry(PwMSyncItem *d, bool dontFlagDirty)
3402{ 3422{
3403 PWM_ASSERT(d); 3423 PWM_ASSERT(d);
3404 3424
3405 if (isDeepLocked()) { 3425 if (isDeepLocked()) {
3406 PwMerror ret; 3426 PwMerror ret;
3407 ret = deepLock(false); 3427 ret = deepLock(false);
3408 if (ret != e_success) 3428 if (ret != e_success)
3409 return e_lock; 3429 return e_lock;
3410 } 3430 }
3411 unsigned int index; 3431 unsigned int index;
3412 3432
3413 const QString tmp = d->syncName.c_str(); 3433 const QString tmp = d->syncName.c_str();
3414 bool exists = findSyncData(d->syncName.c_str(), &index); 3434 bool exists = findSyncData(d->syncName.c_str(), &index);
3415 3435
3416 if (exists == true) { 3436 if (exists == true) {
3417 // DOH! We found this entry. 3437 // DOH! We found this entry.
3418 return e_entryExists; 3438 return e_entryExists;
3419 } 3439 }
3420 3440
3421 dti.syncDta.push_back(*d); 3441 dti.syncDta.push_back(*d);
3422 3442
3423 if (!dontFlagDirty) 3443 if (!dontFlagDirty)
3424 flagDirty(); 3444 flagDirty();
3425 return e_success; 3445 return e_success;
3426} 3446}
3427 3447
3428 3448
3429 3449
3430/** delete syncdata entry */ 3450/** delete syncdata entry */
3431bool PwMDoc::delSyncDataEntry(unsigned int index, bool dontFlagDirty) 3451bool PwMDoc::delSyncDataEntry(unsigned int index, bool dontFlagDirty)
3432{ 3452{
3433 if (isDeepLocked()) 3453 if (isDeepLocked())
3434 return false; 3454 return false;
3435 if (index > dti.syncDta.size() - 1) 3455 if (index > dti.syncDta.size() - 1)
3436 return false; 3456 return false;
3437 3457
3438 // delete entry 3458 // delete entry
3439 dti.syncDta.erase(dti.syncDta.begin() + index); 3459 dti.syncDta.erase(dti.syncDta.begin() + index);
3440 3460
3441 if (!dontFlagDirty) 3461 if (!dontFlagDirty)
3442 flagDirty(); 3462 flagDirty();
3443 return true; 3463 return true;
3444} 3464}
3445 3465
3446 3466
3447PwMDataItem* PwMDoc::findEntryByID(const QString &uid, unsigned int *category, unsigned int *index) 3467PwMDataItem* PwMDoc::findEntryByID(const QString &uid, unsigned int *category, unsigned int *index)
3448{ 3468{
3449 vector<PwMCategoryItem>::iterator catcounter = dti.dta.begin(), 3469 vector<PwMCategoryItem>::iterator catcounter = dti.dta.begin(),
3450 catend = dti.dta.end(); 3470 catend = dti.dta.end();
3451 3471
3452 vector<PwMDataItem>::iterator entrBegin, entrEnd, entrI; 3472 vector<PwMDataItem>::iterator entrBegin, entrEnd, entrI;
3453 3473
3454 while (catcounter != catend) { 3474 while (catcounter != catend) {
3455 entrBegin = catcounter->d.begin(); 3475 entrBegin = catcounter->d.begin();
3456 entrEnd = catcounter->d.end(); 3476 entrEnd = catcounter->d.end();
3457 entrI = entrBegin; 3477 entrI = entrBegin;
3458 while (entrI != entrEnd) { 3478 while (entrI != entrEnd) {
3459 if ((*entrI).meta.uniqueid == uid.latin1()) { 3479 if ((*entrI).meta.uniqueid == uid.latin1()) {
3460 if (category) 3480 if (category)
3461 *category = catcounter - dti.dta.begin(); 3481 *category = catcounter - dti.dta.begin();
3462 if (index) 3482 if (index)
3463 *index = entrI - entrBegin; 3483 *index = entrI - entrBegin;
3464 3484
3465 return &(*entrI); 3485 return &(*entrI);
3466 } 3486 }
3467 ++entrI; 3487 ++entrI;
3468 } 3488 }
3469 ++catcounter; 3489 ++catcounter;
3470 } 3490 }
3471 3491
3472 return 0; 3492 return 0;
3473} 3493}
3474 3494
3475QStringList PwMDoc::getIDEntryList() 3495QStringList PwMDoc::getIDEntryList()
3476{ 3496{
3477 QStringList results; 3497 QStringList results;
3478 3498
3479 vector<PwMCategoryItem>::iterator catcounter = dti.dta.begin(), 3499 vector<PwMCategoryItem>::iterator catcounter = dti.dta.begin(),
3480 catend = dti.dta.end(); 3500 catend = dti.dta.end();
3481 3501
3482 vector<PwMDataItem>::iterator entrBegin, entrEnd, entrI; 3502 vector<PwMDataItem>::iterator entrBegin, entrEnd, entrI;
3483 3503
3484 while (catcounter != catend) { 3504 while (catcounter != catend) {
3485 entrBegin = catcounter->d.begin(); 3505 entrBegin = catcounter->d.begin();
3486 entrEnd = catcounter->d.end(); 3506 entrEnd = catcounter->d.end();
3487 entrI = entrBegin; 3507 entrI = entrBegin;
3488 while (entrI != entrEnd) { 3508 while (entrI != entrEnd) {
3489 results.append( (*entrI).meta.uniqueid.c_str() ); 3509 results.append( (*entrI).meta.uniqueid.c_str() );
3490 ++entrI; 3510 ++entrI;
3491 } 3511 }
3492 ++catcounter; 3512 ++catcounter;
3493 } 3513 }
3494 3514
3495 return results; 3515 return results;
3496} 3516}
3497 3517
3498 3518
3499 3519
3500 3520
3501 3521
3502#ifndef PWM_EMBEDDED 3522#ifndef PWM_EMBEDDED
3503#include "pwmdoc.moc" 3523#include "pwmdoc.moc"
3504#endif 3524#endif
diff --git a/pwmanager/pwmanager/pwmdoc.h b/pwmanager/pwmanager/pwmdoc.h
index ef81dfc..138dd3d 100644
--- a/pwmanager/pwmanager/pwmdoc.h
+++ b/pwmanager/pwmanager/pwmdoc.h
@@ -49,775 +49,779 @@
49 49
50 50
51#include "pwmexception.h" 51#include "pwmexception.h"
52#include "pwmdocui.h" 52#include "pwmdocui.h"
53 53
54#include <qobject.h> 54#include <qobject.h>
55#include <qtimer.h> 55#include <qtimer.h>
56#include <qdatetime.h> 56#include <qdatetime.h>
57 57
58#include <kprocess.h> 58#include <kprocess.h>
59 59
60#ifndef PWM_EMBEDDED 60#ifndef PWM_EMBEDDED
61#include "configuration.h" 61#include "configuration.h"
62#else 62#else
63#include <kapplication.h> 63#include <kapplication.h>
64#include <ksyncmanager.h> 64#include <ksyncmanager.h>
65#endif 65#endif
66 66
67#include <string> 67#include <string>
68#include <vector> 68#include <vector>
69#include <utility> 69#include <utility>
70 70
71using std::vector; 71using std::vector;
72using std::string; 72using std::string;
73using std::pair; 73using std::pair;
74 74
75/* used in findEntry() function */ 75/* used in findEntry() function */
76 #define SEARCH_IN_DESC (1) 76 #define SEARCH_IN_DESC (1)
77 #define SEARCH_IN_NAME (1 << 1) 77 #define SEARCH_IN_NAME (1 << 1)
78 #define SEARCH_IN_PW (1 << 2) 78 #define SEARCH_IN_PW (1 << 2)
79 #define SEARCH_IN_COMMENT(1 << 3) 79 #define SEARCH_IN_COMMENT(1 << 3)
80 #define SEARCH_IN_URL (1 << 4) 80 #define SEARCH_IN_URL (1 << 4)
81 #define SEARCH_IN_LAUNCHER(1 << 5) 81 #define SEARCH_IN_LAUNCHER(1 << 5)
82 #define SEARCH_IN_ALL (SEARCH_IN_DESC | SEARCH_IN_NAME| \ 82 #define SEARCH_IN_ALL (SEARCH_IN_DESC | SEARCH_IN_NAME| \
83 SEARCH_IN_PW | SEARCH_IN_COMMENT| \ 83 SEARCH_IN_PW | SEARCH_IN_COMMENT| \
84 SEARCH_IN_URL| SEARCH_IN_LAUNCHER) 84 SEARCH_IN_URL| SEARCH_IN_LAUNCHER)
85 85
86/** document deeplocked. Data is out for lunch to disk */ 86/** document deeplocked. Data is out for lunch to disk */
87 #define DOC_STAT_DEEPLOCKED (1) 87 #define DOC_STAT_DEEPLOCKED (1)
88/** encrypted document on disk is dirty. data has to go to disk. */ 88/** encrypted document on disk is dirty. data has to go to disk. */
89 #define DOC_STAT_DISK_DIRTY (1 << 1) 89 #define DOC_STAT_DISK_DIRTY (1 << 1)
90/** we are using a chipcard to encrypt the data */ 90/** we are using a chipcard to encrypt the data */
91 #define DOC_STAT_USE_CHIPCARD (1 << 2) 91 #define DOC_STAT_USE_CHIPCARD (1 << 2)
92/** use "currentPw" to unlock. (This flag is set/unset by a timer) */ 92/** use "currentPw" to unlock. (This flag is set/unset by a timer) */
93 #define DOC_STAT_UNLOCK_WITHOUT_PW(1 << 3) 93 #define DOC_STAT_UNLOCK_WITHOUT_PW(1 << 3)
94 94
95class PwMDoc; 95class PwMDoc;
96class PwMView; 96class PwMView;
97class QFile; 97class QFile;
98 98
99/* meta data for a PwMDataItem */ 99/* meta data for a PwMDataItem */
100struct PwMMetaData 100struct PwMMetaData
101{ 101{
102 PwMMetaData() 102 PwMMetaData()
103 : updateInt (0) 103 : updateInt (0)
104 { } 104 { }
105 /** creation date of the PwMDataItem to which 105 /** creation date of the PwMDataItem to which
106 * this meta data belongs. 106 * this meta data belongs.
107 */ 107 */
108 QDateTimecreate; 108 QDateTimecreate;
109 /** becomes valid on this date */ 109 /** becomes valid on this date */
110 QDateTimevalid; 110 QDateTimevalid;
111 /** expire date */ 111 /** expire date */
112 QDateTimeexpire; 112 QDateTimeexpire;
113 /** update date (last updated at this date) */ 113 /** update date (last updated at this date) */
114 QDateTimeupdate; 114 QDateTimeupdate;
115 /** update interval (in minutes). Time since the 115 /** update interval (in minutes). Time since the
116 * last update to remind the user to update the item. 116 * last update to remind the user to update the item.
117 * 0 disables. 117 * 0 disables.
118 */ 118 */
119 unsigned long updateInt; 119 unsigned long updateInt;
120 120
121 //US ENH: enhancements of the filestructure 121 //US ENH: enhancements of the filestructure
122 /* each entry gets a unique id assigned */ 122 /* each entry gets a unique id assigned */
123 string uniqueid; 123 string uniqueid;
124 124
125 125
126 void clear() 126 void clear()
127 { 127 {
128 create = QDateTime(); 128 create = QDateTime();
129 expire = QDateTime(); 129 expire = QDateTime();
130 update = QDateTime(); 130 update = QDateTime();
131 updateInt = 0; 131 updateInt = 0;
132 uniqueid = KApplication::randomString(8).latin1(); 132 uniqueid = KApplication::randomString(8).latin1();
133 } 133 }
134 134
135 inline bool isValid() const 135 inline bool isValid() const
136 { 136 {
137 if (valid.isNull()) 137 if (valid.isNull())
138 return true; 138 return true;
139 return (valid < QDateTime::currentDateTime()); 139 return (valid < QDateTime::currentDateTime());
140 } 140 }
141 inline bool isExpired() const 141 inline bool isExpired() const
142 { 142 {
143 if (expire.isNull()) 143 if (expire.isNull())
144 return false; 144 return false;
145 return (expire < QDateTime::currentDateTime()); 145 return (expire < QDateTime::currentDateTime());
146 } 146 }
147 inline bool isUpdateIntOver() const 147 inline bool isUpdateIntOver() const
148 { 148 {
149 if (updateInt == 0 || 149 if (updateInt == 0 ||
150 update.isNull()) 150 update.isNull())
151 return false; 151 return false;
152 QDateTime d(update); 152 QDateTime d(update);
153 return (d.addSecs(updateInt * 60) < QDateTime::currentDateTime()); 153 return (d.addSecs(updateInt * 60) < QDateTime::currentDateTime());
154 } 154 }
155}; 155};
156 156
157struct PwMDataItem 157struct PwMDataItem
158{ 158{
159 PwMDataItem() 159 PwMDataItem()
160 : lockStat (true) 160 : lockStat (true)
161 , listViewPos (-1) 161 , listViewPos (-1)
162 , binary (false) 162 , binary (false)
163 , rev (0) 163 , rev (0)
164 { } 164 { }
165 165
166 /** password description */ 166 /** password description */
167 stringdesc; 167 stringdesc;
168 /** user-name */ 168 /** user-name */
169 stringname; 169 stringname;
170 /** the password itself */ 170 /** the password itself */
171 stringpw; 171 stringpw;
172 /** some comment */ 172 /** some comment */
173 stringcomment; 173 stringcomment;
174 /** an URL string */ 174 /** an URL string */
175 stringurl; 175 stringurl;
176 /** launcher. Can be executed as a system() command */ 176 /** launcher. Can be executed as a system() command */
177 stringlauncher; 177 stringlauncher;
178 /** locking status. If locked (true), pw is not emitted through getEntry() */ 178 /** locking status. If locked (true), pw is not emitted through getEntry() */
179 boollockStat; 179 boollockStat;
180 /** position of this item in main "list-view" 180 /** position of this item in main "list-view"
181 * If -1, the position is not yet specified and should be appended to the list 181 * If -1, the position is not yet specified and should be appended to the list
182 */ 182 */
183 intlistViewPos; 183 intlistViewPos;
184 /** does this entry contain binary data? */ 184 /** does this entry contain binary data? */
185 bool binary; 185 bool binary;
186 /** meta data for this data item. */ 186 /** meta data for this data item. */
187 PwMMetaData meta; 187 PwMMetaData meta;
188 /** data revision counter. This counter can be used 188 /** data revision counter. This counter can be used
189 * to easily, efficiently determine if this data item 189 * to easily, efficiently determine if this data item
190 * has changed since some time. 190 * has changed since some time.
191 * This counter is incremented on every update. 191 * This counter is incremented on every update.
192 */ 192 */
193 unsigned int rev; 193 unsigned int rev;
194 194
195 void clear(bool clearMeta = true) 195 void clear(bool clearMeta = true)
196 { 196 {
197 /* NOTE: Don't use .clear() here to be 197 /* NOTE: Don't use .clear() here to be
198 * backward compatible with gcc-2 (Debian Woody) 198 * backward compatible with gcc-2 (Debian Woody)
199 */ 199 */
200 desc = ""; 200 desc = "";
201 name = ""; 201 name = "";
202 pw = ""; 202 pw = "";
203 comment = ""; 203 comment = "";
204 url = ""; 204 url = "";
205 launcher = ""; 205 launcher = "";
206 lockStat = true; 206 lockStat = true;
207 listViewPos = -1; 207 listViewPos = -1;
208 binary = false; 208 binary = false;
209 if (clearMeta) 209 if (clearMeta)
210 meta.clear(); 210 meta.clear();
211 } 211 }
212 //US ENH: we need this operator to compare two items if we have no unique ids 212 //US ENH: we need this operator to compare two items if we have no unique ids
213 //available. Generaly this happens before the first sync 213 //available. Generaly this happens before the first sync
214 214
215 bool PwMDataItem::operator==( const PwMDataItem &a ) const 215 bool PwMDataItem::operator==( const PwMDataItem &a ) const
216 { 216 {
217 //qDebug("oper==%s", a.desc.c_str()); 217 //qDebug("oper==%s", a.desc.c_str());
218 if ( desc != a.desc ) return false; 218 if ( desc != a.desc ) return false;
219 if ( name != a.name ) return false; 219 if ( name != a.name ) return false;
220 if ( pw != a.pw ) return false; 220 if ( pw != a.pw ) return false;
221 if ( comment != a.comment ) return false; 221 if ( comment != a.comment ) return false;
222 if ( url != a.url ) return false; 222 if ( url != a.url ) return false;
223 if ( launcher != a.launcher ) return false; 223 if ( launcher != a.launcher ) return false;
224 //all other field will not be checked. 224 //all other field will not be checked.
225 return true; 225 return true;
226 } 226 }
227 227
228 //US ENH: this sync method actually copies all values from the parameter like the =operator 228 //US ENH: this sync method actually copies all values from the parameter like the =operator
229 //does with two exceptions: listViewPos will not be changed, and the launcher only if required. 229 //does with two exceptions: listViewPos will not be changed, and the launcher only if required.
230 bool PwMDataItem::syncItem(const PwMDataItem &a, bool syncLauncher=true ) 230 bool PwMDataItem::syncItem(const PwMDataItem &a, bool syncLauncher=true )
231 { 231 {
232 desc = a.desc; 232 desc = a.desc;
233 name = a.name; 233 name = a.name;
234 pw = a.pw; 234 pw = a.pw;
235 comment = a.comment; 235 comment = a.comment;
236 url = a.url; 236 url = a.url;
237 if (syncLauncher == true) 237 if (syncLauncher == true)
238 launcher = a.launcher; 238 launcher = a.launcher;
239 meta = a.meta; 239 meta = a.meta;
240 binary = a.binary; 240 binary = a.binary;
241 lockStat = a.lockStat; 241 lockStat = a.lockStat;
242 rev = a.rev; 242 rev = a.rev;
243 243
244 return true; 244 return true;
245 } 245 }
246 246
247}; 247};
248 248
249struct PwMCategoryItem 249struct PwMCategoryItem
250{ 250{
251 /** all PwMDataItems (all passwords) within this category */ 251 /** all PwMDataItems (all passwords) within this category */
252 vector<PwMDataItem>d; 252 vector<PwMDataItem>d;
253 /** category name/description */ 253 /** category name/description */
254 string name; 254 string name;
255 255
256 //US ENH: enhancements of the filestructure 256 //US ENH: enhancements of the filestructure
257 /* each category stores the text for description,name and password */ 257 /* each category stores the text for description,name and password */
258 string desc_text; 258 string desc_text;
259 string name_text; 259 string name_text;
260 string pw_text; 260 string pw_text;
261 261
262 void clear() 262 void clear()
263 { 263 {
264 d.clear(); 264 d.clear();
265 name = ""; 265 name = "";
266 desc_text = "Description"; 266 desc_text = "Description";
267 name_text = "Username"; 267 name_text = "Username";
268 pw_text = "Password"; 268 pw_text = "Password";
269 } 269 }
270}; 270};
271 271
272struct PwMSyncItem 272struct PwMSyncItem
273{ 273{
274 string syncName; 274 string syncName;
275 QDateTime lastSyncDate; 275 QDateTime lastSyncDate;
276 276
277 void clear() 277 void clear()
278 { 278 {
279 lastSyncDate = QDateTime(); 279 lastSyncDate = QDateTime();
280 syncName = ""; 280 syncName = "";
281 } 281 }
282}; 282};
283 283
284struct PwMItem 284struct PwMItem
285{ 285{
286 vector<PwMCategoryItem> dta; 286 vector<PwMCategoryItem> dta;
287 vector<PwMSyncItem> syncDta; 287 vector<PwMSyncItem> syncDta;
288 288
289 void clear() 289 void clear()
290 { 290 {
291 dta.clear(); 291 dta.clear();
292 syncDta.clear(); 292 syncDta.clear();
293 } 293 }
294}; 294};
295 295
296 296
297/** "Function Object" for sort()ing PwMDataItem::listViewPos */ 297/** "Function Object" for sort()ing PwMDataItem::listViewPos */
298class dta_lvp_greater 298class dta_lvp_greater
299{ 299{
300public: 300public:
301 bool operator() (const pair<unsigned int, unsigned int> &d1, 301 bool operator() (const pair<unsigned int, unsigned int> &d1,
302 const pair<unsigned int, unsigned int> &d2) 302 const pair<unsigned int, unsigned int> &d2)
303 { 303 {
304 return d1.second > d2.second; 304 return d1.second > d2.second;
305 } 305 }
306}; 306};
307 307
308/** list of PwMDoc documents and it's IDs */ 308/** list of PwMDoc documents and it's IDs */
309class PwMDocList 309class PwMDocList
310{ 310{
311public: 311public:
312 struct listItem 312 struct listItem
313 { 313 {
314 /** document filename (known as ID, here) */ 314 /** document filename (known as ID, here) */
315 string docId; 315 string docId;
316 /** pointer to the document class */ 316 /** pointer to the document class */
317 PwMDoc *doc; 317 PwMDoc *doc;
318 }; 318 };
319 319
320 PwMDocList() {} 320 PwMDocList() {}
321 321
322 /** add a new item to the list */ 322 /** add a new item to the list */
323 void add(PwMDoc *doc, const string &id); 323 void add(PwMDoc *doc, const string &id);
324 /** changes the contents of an existing item */ 324 /** changes the contents of an existing item */
325 void edit(PwMDoc *doc, const string &newId); 325 void edit(PwMDoc *doc, const string &newId);
326 /** remove the given item */ 326 /** remove the given item */
327 void del(PwMDoc *doc); 327 void del(PwMDoc *doc);
328 /** get the item at index */ 328 /** get the item at index */
329 listItem getAt(int index) 329 listItem getAt(int index)
330 { return docList[index]; } 330 { return docList[index]; }
331 /** find an entry with this id */ 331 /** find an entry with this id */
332 bool find(const string &id, listItem *ret = 0); 332 bool find(const string &id, listItem *ret = 0);
333 /** returns a copy of the list */ 333 /** returns a copy of the list */
334 const vector<listItem>* getList() const 334 const vector<listItem>* getList() const
335 { return &docList; } 335 { return &docList; }
336 336
337 337
338 /** returns a new unique number to extend the name of 338 /** returns a new unique number to extend the name of
339 * an unnamed document. 339 * an unnamed document.
340 */ 340 */
341 static unsigned int getNewUnnamedNumber() 341 static unsigned int getNewUnnamedNumber()
342 { return unnamedDocCnt++; } 342 { return unnamedDocCnt++; }
343 343
344protected: 344protected:
345 /* Hm, I think we shouldn't really use a "list" here, should we? 345 /* Hm, I think we shouldn't really use a "list" here, should we?
346 * So I decided to actually use a vector. 346 * So I decided to actually use a vector.
347 */ 347 */
348 vector<listItem> docList; 348 vector<listItem> docList;
349 /** This value is used to get a new number for yet unnamed 349 /** This value is used to get a new number for yet unnamed
350 * documents. It is incremented on every request. So it's 350 * documents. It is incremented on every request. So it's
351 * theoretically possible to overflow it, but... :) 351 * theoretically possible to overflow it, but... :)
352 */ 352 */
353 static unsigned int unnamedDocCnt; 353 static unsigned int unnamedDocCnt;
354}; 354};
355 355
356/** implements timers for the document */ 356/** implements timers for the document */
357class DocTimer : public QObject 357class DocTimer : public QObject
358{ 358{
359 Q_OBJECT 359 Q_OBJECT
360public: 360public:
361 enum TimerIDs 361 enum TimerIDs
362 { 362 {
363 id_mpwTimer, 363 id_mpwTimer,
364 id_autoLockTimer, 364 id_autoLockTimer,
365 id_metaCheckTimer 365 id_metaCheckTimer
366 }; 366 };
367 367
368public: 368public:
369 DocTimer(PwMDoc *_doc); 369 DocTimer(PwMDoc *_doc);
370 ~DocTimer(); 370 ~DocTimer();
371 371
372 /** start the timer */ 372 /** start the timer */
373 void start(TimerIDs timer); 373 void start(TimerIDs timer);
374 /** stop the timer */ 374 /** stop the timer */
375 void stop(TimerIDs timer); 375 void stop(TimerIDs timer);
376 /** get the lock for a timer. 376 /** get the lock for a timer.
377 * This lock is a recursive lock. When a lock is 377 * This lock is a recursive lock. When a lock is
378 * held, the timer will be stopped and timeout is 378 * held, the timer will be stopped and timeout is
379 * guaranteed to not happen 379 * guaranteed to not happen
380 */ 380 */
381 void getLock(TimerIDs timer); 381 void getLock(TimerIDs timer);
382 /** put a recursive timer lock */ 382 /** put a recursive timer lock */
383 void putLock(TimerIDs timer); 383 void putLock(TimerIDs timer);
384 384
385protected slots: 385protected slots:
386 /** timeout slot for the mpw timer */ 386 /** timeout slot for the mpw timer */
387 void mpwTimeout(); 387 void mpwTimeout();
388 /** timeout slot for the autoLock timer */ 388 /** timeout slot for the autoLock timer */
389 void autoLockTimeout(); 389 void autoLockTimeout();
390 /** timeout slot for the metaCheck timer */ 390 /** timeout slot for the metaCheck timer */
391 void metaCheckTimeout(); 391 void metaCheckTimeout();
392 392
393protected: 393protected:
394 /** pointer to the document associated with this timer. */ 394 /** pointer to the document associated with this timer. */
395 PwMDoc *doc; 395 PwMDoc *doc;
396 /** timer object for mpw timer */ 396 /** timer object for mpw timer */
397 QTimer *mpwTimer; 397 QTimer *mpwTimer;
398 /** timer object for the autoLock timer */ 398 /** timer object for the autoLock timer */
399 QTimer *autoLockTimer; 399 QTimer *autoLockTimer;
400 /** timer object for the metaCheck timer */ 400 /** timer object for the metaCheck timer */
401 QTimer *metaCheckTimer; 401 QTimer *metaCheckTimer;
402 /** lock counter for the mpw timer */ 402 /** lock counter for the mpw timer */
403 unsigned int mpwLock; 403 unsigned int mpwLock;
404 /** lock counter for the autoLock timer */ 404 /** lock counter for the autoLock timer */
405 unsigned int autoLockLock; 405 unsigned int autoLockLock;
406 /** lock counter for the metaCheck timer */ 406 /** lock counter for the metaCheck timer */
407 unsigned int metaCheckLock; 407 unsigned int metaCheckLock;
408}; 408};
409 409
410/** Document class for PwM */ 410/** Document class for PwM */
411//US ENH: derived from KSyncInterfaces, to get called by PwM when a sync is required. 411//US ENH: derived from KSyncInterfaces, to get called by PwM when a sync is required.
412// But PwMDoc is handling the sync by itself. 412// But PwMDoc is handling the sync by itself.
413class PwMDoc : public PwMDocUi, public KSyncInterface 413class PwMDoc : public PwMDocUi, public KSyncInterface
414 414
415{ 415{
416 Q_OBJECT 416 Q_OBJECT
417 friend class DocTimer; 417 friend class DocTimer;
418 418
419public: 419public:
420 /** construtor */ 420 /** construtor */
421 PwMDoc(QObject* parent = 0, const char *name = 0); 421 PwMDoc(QObject* parent = 0, const char *name = 0);
422 /** destructor */ 422 /** destructor */
423 ~PwMDoc(); 423 ~PwMDoc();
424 424
425 /** returns a pointer to a list of all open documents */ 425 /** returns a pointer to a list of all open documents */
426 static PwMDocList* getOpenDocList() 426 static PwMDocList* getOpenDocList()
427 { return &openDocList; } 427 { return &openDocList; }
428 428
429 /** flag document dirty. dta changed */ 429 /** flag document dirty. dta changed */
430 void flagDirty() 430 void flagDirty()
431 { 431 {
432 setDocStatFlag(DOC_STAT_DISK_DIRTY); 432 setDocStatFlag(DOC_STAT_DISK_DIRTY);
433 emitDataChanged(this); 433 emitDataChanged(this);
434 } 434 }
435 /** modified? */ 435 /** modified? */
436 bool isDirty() 436 bool isDirty()
437 { return getDocStatFlag(DOC_STAT_DISK_DIRTY); } 437 { return getDocStatFlag(DOC_STAT_DISK_DIRTY); }
438 /** save document to disk */ 438 /** save document to disk */
439 PwMerror saveDoc(char compress, const QString *file = 0); 439 PwMerror saveDoc(char compress, const QString *file = 0);
440 /** read document from file. 440 /** read document from file.
441 * "openLocked is must be set to either of these values: 441 * "openLocked is must be set to either of these values:
442 * 0 == open with all entries unlocked 442 * 0 == open with all entries unlocked
443 * 1 == open with all entries locked 443 * 1 == open with all entries locked
444 * 2 == open deep-locked 444 * 2 == open deep-locked
445 */ 445 */
446 PwMerror openDoc(const QString *file, int openLocked); 446 PwMerror openDoc(const QString *file, int openLocked);
447 /** export document to ascii-textfile */ 447 /** export document to ascii-textfile */
448 PwMerror exportToText(const QString *file); 448 PwMerror exportToText(const QString *file);
449 /** export document to gpasman / kpasman file */ 449 /** export document to gpasman / kpasman file */
450 PwMerror exportToGpasman(const QString *file); 450 PwMerror exportToGpasman(const QString *file);
451 /** import document from ascii-textfile */ 451 /** import document from ascii-textfile */
452 PwMerror importFromText(const QString *file, int format = -1); 452 PwMerror importFromText(const QString *file, int format = -1);
453 /** import document from gpasman / kpasman file */ 453 /** import document from gpasman / kpasman file */
454 PwMerror importFromGpasman(const QString *file); 454 PwMerror importFromGpasman(const QString *file);
455 /** add new entry */ 455 /** add new entry */
456 PwMerror addEntry(const QString &category, PwMDataItem *d, 456 PwMerror addEntry(const QString &category, PwMDataItem *d,
457 bool dontFlagDirty = false, bool updateMeta = true); 457 bool dontFlagDirty = false, bool updateMeta = true);
458 /** add new category. This function doesn't flag the document dirty! */ 458 /** add new category. This function doesn't flag the document dirty! */
459 PwMerror addCategory(const QString &category, unsigned int *categoryIndex, 459 PwMerror addCategory(const QString &category, unsigned int *categoryIndex,
460 bool checkIfExist = true); 460 bool checkIfExist = true);
461 /** rename an existing category */ 461 /** rename an existing category */
462 bool renameCategory(const QString &category, const QString &newName); 462 bool renameCategory(const QString &category, const QString &newName);
463 /** rename an existing category */ 463 /** rename an existing category */
464 bool renameCategory(unsigned int category, const QString &newName, 464 bool renameCategory(unsigned int category, const QString &newName,
465 bool dontFlagDirty = false); 465 bool dontFlagDirty = false);
466 /** delete an existing category */ 466 /** delete an existing category */
467 bool delCategory(const QString &category); 467 bool delCategory(const QString &category);
468 /** delete an existing category */ 468 /** delete an existing category */
469 bool delCategory(unsigned int category, bool dontFlagDirty = false); 469 bool delCategory(unsigned int category, bool dontFlagDirty = false);
470 /** returns a list of all category-names */ 470 /** returns a list of all category-names */
471 void getCategoryList(vector<string> *list); 471 void getCategoryList(vector<string> *list);
472 /** returns a list of all category-names */ 472 /** returns a list of all category-names */
473 void getCategoryList(QStringList *list); 473 void getCategoryList(QStringList *list);
474 /** returns a list of all entry-descs in the given category */ 474 /** returns a list of all entry-descs in the given category */
475 void getEntryList(const QString &category, QStringList *list); 475 void getEntryList(const QString &category, QStringList *list);
476 /** returns a list of all entry-descs in the given category */ 476 /** returns a list of all entry-descs in the given category */
477 void getEntryList(const QString &category, vector<string> *list); 477 void getEntryList(const QString &category, vector<string> *list);
478 /** returns a list of all entry-descs in the given category */ 478 /** returns a list of all entry-descs in the given category */
479 void getEntryList(unsigned int category, vector<string> *list); 479 void getEntryList(unsigned int category, vector<string> *list);
480 /** returns a list of all entry-descs in the given category */ 480 /** returns a list of all entry-descs in the given category */
481 void getEntryList(unsigned int category, QStringList *list); 481 void getEntryList(unsigned int category, QStringList *list);
482 /** delete entry */ 482 /** delete entry */
483 bool delEntry(const QString &category, unsigned int index, bool dontFlagDirty = false); 483 bool delEntry(const QString &category, unsigned int index, bool dontFlagDirty = false);
484 /** delete entry */ 484 /** delete entry */
485 bool delEntry(unsigned int category, unsigned int index, bool dontFlagDirty = false); 485 bool delEntry(unsigned int category, unsigned int index, bool dontFlagDirty = false);
486 /** edit entry */ 486 /** edit entry */
487 bool editEntry(const QString &oldCategory, const QString &newCategory, 487 bool editEntry(const QString &oldCategory, const QString &newCategory,
488 unsigned int index, PwMDataItem *d, bool updateMeta = true); 488 unsigned int index, PwMDataItem *d, bool updateMeta = true);
489 /** edit entry */ 489 /** edit entry */
490 bool editEntry(unsigned int oldCategory, const QString &newCategory, 490 bool editEntry(unsigned int oldCategory, const QString &newCategory,
491 unsigned int index, PwMDataItem *d, bool updateMeta = true); 491 unsigned int index, PwMDataItem *d, bool updateMeta = true);
492 /** finds the category with the "name" and return it's index */ 492 /** finds the category with the "name" and return it's index */
493 bool findCategory(const QString &name, unsigned int *index); 493 bool findCategory(const QString &name, unsigned int *index);
494 /** search for an entry "find" and check while searching only for 494 /** search for an entry "find" and check while searching only for
495 * the data-fields specified by "searchIn". To set the "searchIn" 495 * the data-fields specified by "searchIn". To set the "searchIn"
496 * value, we may use one or more of the SEARCH_IN_* defines at 496 * value, we may use one or more of the SEARCH_IN_* defines at
497 * the top of this header-file. It returns the positions of all 497 * the top of this header-file. It returns the positions of all
498 * matched entries in "foundPositions". If "breakAfterFound" is true, 498 * matched entries in "foundPositions". If "breakAfterFound" is true,
499 * the function terminates after the first occurence of the entry 499 * the function terminates after the first occurence of the entry
500 * and doesn't go on searching. So foundPositions->size() is never 500 * and doesn't go on searching. So foundPositions->size() is never
501 * > 1 if breakAfterFound is true. 501 * > 1 if breakAfterFound is true.
502 */ 502 */
503 void findEntry(unsigned int category, PwMDataItem find, unsigned int searchIn, 503 void findEntry(unsigned int category, PwMDataItem find, unsigned int searchIn,
504 vector<unsigned int> *foundPositions, bool breakAfterFound = false, 504 vector<unsigned int> *foundPositions, bool breakAfterFound = false,
505 bool caseSensitive = true, bool exactWordMatch = true, 505 bool caseSensitive = true, bool exactWordMatch = true,
506 bool sortByLvp = false); 506 bool sortByLvp = false);
507 /** see the above funtion. This function allows to set the category by name. */ 507 /** see the above funtion. This function allows to set the category by name. */
508 void findEntry(const QString &category, PwMDataItem find, unsigned int searchIn, 508 void findEntry(const QString &category, PwMDataItem find, unsigned int searchIn,
509 vector<unsigned int> *foundPositions, bool breakAfterFound = false, 509 vector<unsigned int> *foundPositions, bool breakAfterFound = false,
510 bool caseSensitive = true, bool exactWordMatch = true, 510 bool caseSensitive = true, bool exactWordMatch = true,
511 bool sortByLvp = false); 511 bool sortByLvp = false);
512 /** returns number of entries */ 512 /** returns number of entries */
513 unsigned int numEntries(const QString &category); 513 unsigned int numEntries(const QString &category);
514 unsigned int numEntries(unsigned int category) 514 unsigned int numEntries(unsigned int category)
515 { return dti.dta[category].d.size(); } 515 { return dti.dta[category].d.size(); }
516 /** returns number of categories */ 516 /** returns number of categories */
517 unsigned int numCategories() 517 unsigned int numCategories()
518 { return dti.dta.size(); } 518 { return dti.dta.size(); }
519 /** returns the name of the category at "index" */ 519 /** returns the name of the category at "index" */
520 const string* getCategory(unsigned int index) 520 const string* getCategory(unsigned int index)
521 { return (&(dti.dta[index].name)); } 521 { return (&(dti.dta[index].name)); }
522 522
523 /** returns the data of item at "index". 523 /** returns the data of item at "index".
524 * It unlocks the entry if it's locked and unlockIfLocked is true. 524 * It unlocks the entry if it's locked and unlockIfLocked is true.
525 * If the entry is locked, but unlockIfLocked is false, it'll not return 525 * If the entry is locked, but unlockIfLocked is false, it'll not return
526 * the pw. 526 * the pw.
527 */ 527 */
528 bool getEntry(const QString &category, unsigned int index, 528 bool getEntry(const QString &category, unsigned int index,
529 PwMDataItem *d, bool unlockIfLocked = false); 529 PwMDataItem *d, bool unlockIfLocked = false);
530 bool getEntry(unsigned int category, unsigned int index, 530 bool getEntry(unsigned int category, unsigned int index,
531 PwMDataItem *d, bool unlockIfLocked = false); 531 PwMDataItem *d, bool unlockIfLocked = false);
532 /** returns the comment-string by looking at the category 532 /** returns the comment-string by looking at the category
533 * and the listViewPos 533 * and the listViewPos
534 */ 534 */
535 PwMerror getCommentByLvp(const QString &category, int listViewPos, 535 PwMerror getCommentByLvp(const QString &category, int listViewPos,
536 string *foundComment); 536 string *foundComment);
537 /** checks if a password is already available. (currentPw) */ 537 /** checks if a password is already available. (currentPw) */
538 bool isPwAvailable() 538 bool isPwAvailable()
539 { return (currentPw != ""); } 539 { return (currentPw != ""); }
540 /** un/lock entry at "index". If needed, ask for password. */ 540 /** un/lock entry at "index". If needed, ask for password. */
541 bool lockAt(const QString &category, unsigned int index, 541 bool lockAt(const QString &category, unsigned int index,
542 bool lock = true); 542 bool lock = true);
543 bool lockAt(unsigned int category, unsigned int index, 543 bool lockAt(unsigned int category, unsigned int index,
544 bool lock = true); 544 bool lock = true);
545 /** returns the lock-status at "index" */ 545 /** returns the lock-status at "index" */
546 bool isLocked(const QString &category, unsigned int index); 546 bool isLocked(const QString &category, unsigned int index);
547 bool isLocked(unsigned int category, unsigned int index) 547 bool isLocked(unsigned int category, unsigned int index)
548 { return dti.dta[category].d[index].lockStat; } 548 { return dti.dta[category].d[index].lockStat; }
549 /** returns the deeplock status */ 549 /** returns the deeplock status */
550 bool isDeepLocked() 550 bool isDeepLocked()
551 { return getDocStatFlag(DOC_STAT_DEEPLOCKED); } 551 { return getDocStatFlag(DOC_STAT_DEEPLOCKED); }
552 /** (un)lock all entries */ 552 /** (un)lock all entries */
553 bool lockAll(bool lock); 553 bool lockAll(bool lock);
554 /** unlocks all entries tempoarly. 554 /** unlocks all entries tempoarly.
555 * 1st NOTE: Be very careful with this function! :) 555 * 1st NOTE: Be very careful with this function! :)
556 * 2nd NOTE: After you have called unlockAll_Tempoary(); , 556 * 2nd NOTE: After you have called unlockAll_Tempoary(); ,
557 * please DON'T forget to call unlockAll_Tempoary(true); 557 * please DON'T forget to call unlockAll_Tempoary(true);
558 * _before_ the user (or someone else) is able to change 558 * _before_ the user (or someone else) is able to change
559 * the document! 559 * the document!
560 * 3rd NOTE: Please DON'T change "dta" while the data is tempoary 560 * 3rd NOTE: Please DON'T change "dta" while the data is tempoary
561 * unlocked! This will cause corruption. 561 * unlocked! This will cause corruption.
562 */ 562 */
563 bool unlockAll_tempoary(bool revert = false); 563 bool unlockAll_tempoary(bool revert = false);
564 /** deep-(un)locks the document. 564 /** deep-(un)locks the document.
565 * deep-locking writes all data to the file, deletes all data 565 * deep-locking writes all data to the file, deletes all data
566 * in memory, but doesn't close the document. 566 * in memory, but doesn't close the document.
567 * deep-locking is only available, if the user previously saved 567 * deep-locking is only available, if the user previously saved
568 * the doc to a file (with a password). 568 * the doc to a file (with a password).
569 * If "saveToFile" is false, it does NOT write the data to the file! 569 * If "saveToFile" is false, it does NOT write the data to the file!
570 */ 570 */
571 PwMerror deepLock(bool lock = true, bool saveToFile = true); 571 PwMerror deepLock(bool lock = true, bool saveToFile = true);
572 /** is unlockable without pw? */ 572 /** is unlockable without pw? */
573 bool unlockWoPw() 573 bool unlockWoPw()
574 { return getDocStatFlag(DOC_STAT_UNLOCK_WITHOUT_PW); } 574 { return getDocStatFlag(DOC_STAT_UNLOCK_WITHOUT_PW); }
575 /** get the "currentPassword" */ 575 /** get the "currentPassword" */
576 const QString& getCurrentPw() 576 const QString& getCurrentPw()
577 { return currentPw; } 577 { return currentPw; }
578 /** open a window and request the user to change the mpw */ 578 /** open a window and request the user to change the mpw */
579 void changeCurrentPw(); 579 void changeCurrentPw();
580 /** set the "listViewPos" variable of "dta" */ 580 /** set the "listViewPos" variable of "dta" */
581 void setListViewPos(const QString &category, unsigned int index, 581 void setListViewPos(const QString &category, unsigned int index,
582 int pos); 582 int pos);
583 /** set the "listViewPos" variable of "dta" */ 583 /** set the "listViewPos" variable of "dta" */
584 void setListViewPos(unsigned int category, unsigned int index, 584 void setListViewPos(unsigned int category, unsigned int index,
585 int pos); 585 int pos);
586 /** get the "listViewPos" variable of "dta" */ 586 /** get the "listViewPos" variable of "dta" */
587 int getListViewPos(const QString &category, unsigned int index); 587 int getListViewPos(const QString &category, unsigned int index);
588 /** set the maximum number of entries allowed */ 588 /** set the maximum number of entries allowed */
589 void setMaxNumEntries(unsigned int num = DEFAULT_MAX_ENTRIES) 589 void setMaxNumEntries(unsigned int num = DEFAULT_MAX_ENTRIES)
590 { maxEntries = num; } 590 { maxEntries = num; }
591 /** get the maximum number of entries allowed */ 591 /** get the maximum number of entries allowed */
592 unsigned int getMaxNumEntries() 592 unsigned int getMaxNumEntries()
593 { return maxEntries; } 593 { return maxEntries; }
594 /** ensure all listViewPos of all dta items are set. (are ! -1). 594 /** ensure all listViewPos of all dta items are set. (are ! -1).
595 * If there are some undefined entries, add them to the end of 595 * If there are some undefined entries, add them to the end of
596 * the listViewPos(itions). */ 596 * the listViewPos(itions). */
597 void ensureLvp(); 597 void ensureLvp();
598 /** execute the "launcher" of this entry */ 598 /** execute the "launcher" of this entry */
599 bool execLauncher(const QString &category, unsigned int entryIndex); 599 bool execLauncher(const QString &category, unsigned int entryIndex);
600 /** see above */ 600 /** see above */
601 bool execLauncher(unsigned int category, unsigned int entryIndex); 601 bool execLauncher(unsigned int category, unsigned int entryIndex);
602 /** open a browser with the URL-section of the given entry */ 602 /** open a browser with the URL-section of the given entry */
603 bool goToURL(const QString &category, unsigned int entryIndex); 603 bool goToURL(const QString &category, unsigned int entryIndex);
604 /** see above */ 604 /** see above */
605 bool goToURL(unsigned int category, unsigned int entryIndex); 605 bool goToURL(unsigned int category, unsigned int entryIndex);
606 /** returns true if there is no entry present in the document. 606 /** returns true if there is no entry present in the document.
607 * Note: The "default" Category is present everytime, so 607 * Note: The "default" Category is present everytime, so
608 * it's checked for it's entries. 608 * it's checked for it's entries.
609 */ 609 */
610 bool isDocEmpty() 610 bool isDocEmpty()
611 { 611 {
612 if (numCategories() > 1) 612 if (numCategories() > 1)
613 return false; 613 return false;
614 if (numEntries(0)) 614 if (numEntries(0))
615 return false; 615 return false;
616 return true; 616 return true;
617 } 617 }
618 /** returns the filename of this doc */ 618 /** returns the filename of this doc */
619 const QString& getFilename() 619 const QString& getFilename()
620 { return filename; } 620 { return filename; }
621 /** returns the title of the doc */ 621 /** returns the title of the doc */
622 QString getTitle(); 622 QString getTitle();
623 /** sets the list-view-pointer hold in the doc */ 623 /** sets the list-view-pointer hold in the doc */
624 void setListViewPointer(PwMView *_listView) 624 void setListViewPointer(PwMView *_listView)
625 { listView = _listView; } 625 { listView = _listView; }
626 /** returns the list-view-pointer */ 626 /** returns the list-view-pointer */
627 PwMView * getListViewPointer() 627 PwMView * getListViewPointer()
628 { return listView; } 628 { return listView; }
629 /** try to delete the doc. The user may be asked to save 629 /** try to delete the doc. The user may be asked to save
630 * the data. The user may cancel the whole operation. 630 * the data. The user may cancel the whole operation.
631 * false is returned, then. 631 * false is returned, then.
632 */ 632 */
633 bool tryDelete(); 633 bool tryDelete();
634 /** is the doc deleted? (with tryDelete() ) */ 634 /** is the doc deleted? (with tryDelete() ) */
635 bool isDeleted() 635 bool isDeleted()
636 { return deleted; } 636 { return deleted; }
637 /** returns the document timer object */ 637 /** returns the document timer object */
638 DocTimer * timer() 638 DocTimer * timer()
639 { return _timer; } 639 { return _timer; }
640 /** get a lock on the dataChanged signal. 640 /** get a lock on the dataChanged signal.
641 * If someone is holding a lock, the signal is not emitted. 641 * If someone is holding a lock, the signal is not emitted.
642 */ 642 */
643 void getDataChangedLock() 643 void getDataChangedLock()
644 { ++dataChangedLock; } 644 { ++dataChangedLock; }
645 /** put the dataChanged lock */ 645 /** put the dataChanged lock */
646 void putDataChangedLock() 646 void putDataChangedLock()
647 { --dataChangedLock; } 647 { --dataChangedLock; }
648 /** returns the revision count of the item at cat/index */ 648 /** returns the revision count of the item at cat/index */
649 unsigned int getEntryRevCnt(unsigned int category, unsigned int index) 649 unsigned int getEntryRevCnt(unsigned int category, unsigned int index)
650 { return dti.dta[category].d[index].rev; } 650 { return dti.dta[category].d[index].rev; }
651 /** returns a const pointer to the entries meta */ 651 /** returns a const pointer to the entries meta */
652 const PwMMetaData * getEntryMeta(unsigned int category, unsigned int index) 652 const PwMMetaData * getEntryMeta(unsigned int category, unsigned int index)
653 { return &(dti.dta[category].d[index].meta); } 653 { return &(dti.dta[category].d[index].meta); }
654 /** is the entry at "category" "index" a binary entry? */ 654 /** is the entry at "category" "index" a binary entry? */
655 bool isBinEntry(unsigned int category, unsigned int index) 655 bool isBinEntry(unsigned int category, unsigned int index)
656 { return dti.dta[category].d[index].binary; } 656 { return dti.dta[category].d[index].binary; }
657 657
658public slots: 658public slots:
659 /** wrapper for PwMTray */ 659 /** wrapper for PwMTray */
660 void _deepUnlock(); 660 void _deepUnlock();
661 661
662signals: 662signals:
663 /** the data of the document has changed and must be updated 663 /** the data of the document has changed and must be updated
664 * in all views. 664 * in all views.
665 * NOTE: use emitDataChanged(PwMDoc *document) to emit this signal! 665 * NOTE: use emitDataChanged(PwMDoc *document) to emit this signal!
666 */ 666 */
667 void dataChanged(PwMDoc *document); 667 void dataChanged(PwMDoc *document);
668 /** the document class is going to close. This signal may be 668 /** the document class is going to close. This signal may be
669 * used to nofify all views, that the user closed the document, 669 * used to nofify all views, that the user closed the document,
670 * so the views can go down, too. 670 * so the views can go down, too.
671 */ 671 */
672 void docClosed(PwMDoc *document); 672 void docClosed(PwMDoc *document);
673 /** somebody just opened the document */ 673 /** somebody just opened the document */
674 void docOpened(PwMDoc *document); 674 void docOpened(PwMDoc *document);
675 /** this document object just got created */ 675 /** this document object just got created */
676 void docCreated(PwMDoc *document); 676 void docCreated(PwMDoc *document);
677 677
678public: 678public:
679 /** emit the dataChanged signal after checking for a lock */ 679 /** emit the dataChanged signal after checking for a lock */
680 void emitDataChanged(PwMDoc *document) 680 void emitDataChanged(PwMDoc *document)
681 { 681 {
682 if (!dataChangedLock) 682 if (!dataChangedLock)
683 emit dataChanged(document); 683 emit dataChanged(document);
684 } 684 }
685 685
686protected: 686protected:
687 /** current file for this doc */ 687 /** current file for this doc */
688 QString filename; 688 QString filename;
689//US ENH: we need a place where we keep the syncentries. So I invented 689//US ENH: we need a place where we keep the syncentries. So I invented
690// struct PwMItem, that has a vector of PwMCategoryItem and vector of PwMSyncItem 690// struct PwMItem, that has a vector of PwMCategoryItem and vector of PwMSyncItem
691 /** holds all data */ 691 /** holds all data */
692 PwMItem dti; 692 PwMItem dti;
693 /** maximum number of entries */ 693 /** maximum number of entries */
694 unsigned int maxEntries; 694 unsigned int maxEntries;
695 /** currently used password to encrypt data */ 695 /** currently used password to encrypt data */
696 QString currentPw; 696 QString currentPw;
697 /** current global document status flags */ 697 /** current global document status flags */
698 unsigned int curDocStat; 698 unsigned int curDocStat;
699 /** browser process for goToURL() */ 699 /** browser process for goToURL() */
700 KProcess browserProc; 700 KProcess browserProc;
701 /** pointer to the list-view, using this document. 701 /** pointer to the list-view, using this document.
702 * As there can only be one list-view per doc, we 702 * As there can only be one list-view per doc, we
703 * don't need a list here. 703 * don't need a list here.
704 */ 704 */
705 PwMView *listView; 705 PwMView *listView;
706 /** unnamedNum is used to store the "unnamed counter" 706 /** unnamedNum is used to store the "unnamed counter"
707 * for this document, while it's unnamed. If it's 0, 707 * for this document, while it's unnamed. If it's 0,
708 * we have to get a new unique one. 708 * we have to get a new unique one.
709 */ 709 */
710 unsigned int unnamedNum; 710 unsigned int unnamedNum;
711 /** is this doc going to be deleted (executing in destructor context) */ 711 /** is this doc going to be deleted (executing in destructor context) */
712 bool deleted; 712 bool deleted;
713 /** document timer */ 713 /** document timer */
714 DocTimer *_timer; 714 DocTimer *_timer;
715 /** lock counter for the "dataChanged" signal */ 715 /** lock counter for the "dataChanged" signal */
716 unsigned int dataChangedLock; 716 unsigned int dataChangedLock;
717 717
718 /** list of all open documents */ 718 /** list of all open documents */
719 static PwMDocList openDocList; 719 static PwMDocList openDocList;
720 720
721protected: 721protected:
722 /** serialize "dta" and return it in "d". */ 722 /** serialize "dta" and return it in "d". */
723 bool serializeDta(string *d); 723 bool serializeDta(string *d);
724 /** de-serialize "d" and overwrite "dta" */ 724 /** de-serialize "d" and overwrite "dta" */
725 bool deSerializeDta(const string *d, bool entriesLocked); 725 bool deSerializeDta(const string *d, bool entriesLocked);
726 /** write header to file */ 726 /** write header to file */
727 PwMerror writeFileHeader(char keyHash, char dataHash, char crypt, char compress, 727 PwMerror writeFileHeader(char keyHash, char dataHash, char crypt, char compress,
728 QString *pw, QFile *f); 728 QString *pw, QFile *f);
729 /** write data-hash to file */ 729 /** write data-hash to file */
730 PwMerror writeDataHash(char dataHash, string *d, QFile *f); 730 PwMerror writeDataHash(char dataHash, string *d, QFile *f);
731 /** check header. Read header info and verify key-hash and filever. 731 /** check header. Read header info and verify key-hash and filever.
732 * returns length of header in "headerLength" */ 732 * returns length of header in "headerLength" */
733 PwMerror checkHeader(char *cryptAlgo, QString *pw, char *compress, 733 PwMerror checkHeader(char *cryptAlgo, QString *pw, char *compress,
734 unsigned int *headerLength, char *dataHashType, 734 unsigned int *headerLength, char *dataHashType,
735 string *dataHash, QFile *f); 735 string *dataHash, QFile *f);
736 /** check the data-hash */ 736 /** check the data-hash */
737 PwMerror checkDataHash(char dataHashType, const string *dataHash, const string *dataStream); 737 PwMerror checkDataHash(char dataHashType, const string *dataHash, const string *dataStream);
738 /** encrypt data "d" and write to "filename" */ 738 /** encrypt data "d" and write to "filename" */
739 PwMerror encrypt(string *d, const QString *pw, QFile *f, char algo); 739 PwMerror encrypt(string *d, const QString *pw, QFile *f, char algo);
740 /** read data from file beginning at "pos", decrypt and return it */ 740 /** read data from file beginning at "pos", decrypt and return it */
741 PwMerror decrypt(string *d, unsigned int pos, const QString *pw, char algo, QFile *f); 741 PwMerror decrypt(string *d, unsigned int pos, const QString *pw, char algo, QFile *f);
742 /** compress the data */ 742 /** compress the data */
743 bool compressDta(string *d, char algo); 743 bool compressDta(string *d, char algo);
744 /** uncompress the data */ 744 /** uncompress the data */
745 bool decompressDta(string *d, char algo); 745 bool decompressDta(string *d, char algo);
746 /** internal import function for a text-file generated by PwM. 746 /** internal import function for a text-file generated by PwM.
747 * If this is not a valid PwM-exported file, it returns e_fileFormat */ 747 * If this is not a valid PwM-exported file, it returns e_fileFormat */
748 PwMerror importText_PwM(const QString *file); 748 PwMerror importText_PwM(const QString *file);
749 /** PwM-text-import helper function to extract the name/pw/comment out 749 /** PwM-text-import helper function to extract the name/pw/comment out
750 * of one entry-line */ 750 * of one entry-line */
751 bool textExtractEntry_PwM(const char *in, ssize_t in_size, string *out); 751 bool textExtractEntry_PwM(const char *in, ssize_t in_size, string *out);
752 /** compare two strings */ 752 /** compare two strings */
753 bool compareString(const string &s1, const string &s2, bool caseSensitive, 753 bool compareString(const string &s1, const string &s2, bool caseSensitive,
754 bool exactWordMatch); 754 bool exactWordMatch);
755 /** clears all document-data */ 755 /** clears all document-data */
756 void clearDoc(); 756 void clearDoc();
757 /** delete all empty categories */ 757 /** delete all empty categories */
758 void delAllEmptyCat(bool dontFlagDirty); 758 void delAllEmptyCat(bool dontFlagDirty);
759 /** set a document status flag */ 759 /** set a document status flag */
760 void setDocStatFlag(unsigned int statFlag) 760 void setDocStatFlag(unsigned int statFlag)
761 { curDocStat |= statFlag; } 761 { curDocStat |= statFlag; }
762 /** unset a document status flag */ 762 /** unset a document status flag */
763 void unsetDocStatFlag(unsigned int statFlag) 763 void unsetDocStatFlag(unsigned int statFlag)
764 { curDocStat &= ~statFlag; } 764 { curDocStat &= ~statFlag; }
765 /** get a document status flag */ 765 /** get a document status flag */
766 bool getDocStatFlag(unsigned int statFlag) const 766 bool getDocStatFlag(unsigned int statFlag) const
767 { return (curDocStat & statFlag); } 767 { return (curDocStat & statFlag); }
768 /** set the "currentPassword" */ 768 /** set the "currentPassword" */
769 void setCurrentPw(const QString &pw) 769 void setCurrentPw(const QString &pw)
770 { 770 {
771 currentPw = pw; 771 currentPw = pw;
772 setDocStatFlag(DOC_STAT_DISK_DIRTY); 772 setDocStatFlag(DOC_STAT_DISK_DIRTY);
773 } 773 }
774 /** make a backup-copy of the given file */ 774 /** make a backup-copy of the given file */
775 bool backupFile(const QString &filePath); 775 bool backupFile(const QString &filePath);
776 /** copy a file from src to dst */ 776 /** copy a file from src to dst */
777 bool copyFile(const QString &src, const QString &dst); 777 bool copyFile(const QString &src, const QString &dst);
778 778
779 779
780 public: 780 public:
781#ifdef PWM_EMBEDDED 781#ifdef PWM_EMBEDDED
782 //US ENH: this is the magic function that syncronizes the local doc with the remote doc. 782 //US ENH: this is the magic function that syncronizes the local doc with the remote doc.
783 PwMerror syncronize(KSyncManager* manager, PwMDoc* syncLocal, PwMDoc* syncRemote, int mode ); 783 PwMerror syncronize(KSyncManager* manager, PwMDoc* syncLocal, PwMDoc* syncRemote, int mode );
784 784
785 //takePwMDataItem returns the following values 785 //takePwMDataItem returns the following values
786 // 0 equal 786 // 0 equal
787 // 1 take local 787 // 1 take local
788 // 2 take remote 788 // 2 take remote
789 // 3 cancel 789 // 3 cancel
790 int takePwMDataItem( PwMDataItem* local, PwMDataItem* remote, QDateTime lastSync, int mode , bool full ); 790 int takePwMDataItem( PwMDataItem* local, PwMDataItem* remote, QDateTime lastSync, int mode , bool full );
791 791
792 //the following methods are the overwritten callbackmethods from the syncinterface 792 //the following methods are the overwritten callbackmethods from the syncinterface
793 virtual bool sync(KSyncManager* manager, QString filename, int mode); 793 virtual bool sync(KSyncManager* manager, QString filename, int mode);
794 virtual void removeSyncInfo( QString syncProfile); 794 virtual void removeSyncInfo( QString syncProfile);
795 795
796#endif 796#endif
797 //US ENH: helpermethods to return a whole category entry 797 //US ENH: helpermethods to return a whole category entry
798 /** returns a pointer to the categoryitem */ 798 /** returns a pointer to the categoryitem */
799 PwMCategoryItem* getCategoryEntry(unsigned int index) 799 PwMCategoryItem* getCategoryEntry(unsigned int index)
800 { return &(dti.dta[index]); } 800 { return &(dti.dta[index]); }
801 801
802 private: 802 private:
803 //US ENH: helpermethods to access the sync data for a certain syncname. 803 //US ENH: helpermethods to access the sync data for a certain syncname.
804 // It returns the syncdatas index 804 // It returns the syncdatas index
805 bool findSyncData(const QString &syncname, unsigned int *index); 805 bool findSyncData(const QString &syncname, unsigned int *index);
806 806
807 /** add new syncdataentry */ 807 /** add new syncdataentry */
808 PwMerror addSyncDataEntry(PwMSyncItem *d, bool dontFlagDirty = false); 808 PwMerror addSyncDataEntry(PwMSyncItem *d, bool dontFlagDirty = false);
809 809
810 /** returns a pointer to the syncdata */ 810 /** returns a pointer to the syncdata */
811 PwMSyncItem* getSyncDataEntry(unsigned int index) 811 PwMSyncItem* getSyncDataEntry(unsigned int index)
812 { return &(dti.syncDta[index]); } 812 { return &(dti.syncDta[index]); }
813 813
814 /** delete entry */ 814 /** delete entry */
815 bool delSyncDataEntry(unsigned int index, bool dontFlagDirty = false); 815 bool delSyncDataEntry(unsigned int index, bool dontFlagDirty = false);
816 816
817 /** returns number of categories */
818 unsigned int numSyncDataEntries()
819 { return dti.syncDta.size(); }
820
817 PwMDataItem* findEntryByID(const QString &uid, unsigned int *category, unsigned int *index); 821 PwMDataItem* findEntryByID(const QString &uid, unsigned int *category, unsigned int *index);
818 822
819 QStringList getIDEntryList(); 823 QStringList getIDEntryList();
820 824
821}; 825};
822 826
823#endif 827#endif