summaryrefslogtreecommitdiffabout
Unidiff
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--pwmanager/pwmanager/pwmdoc.cpp102
-rw-r--r--pwmanager/pwmanager/pwmdoc.h23
2 files changed, 60 insertions, 65 deletions
diff --git a/pwmanager/pwmanager/pwmdoc.cpp b/pwmanager/pwmanager/pwmdoc.cpp
index 2a7b11d..e9906a4 100644
--- a/pwmanager/pwmanager/pwmdoc.cpp
+++ b/pwmanager/pwmanager/pwmdoc.cpp
@@ -2549,884 +2549,898 @@ PwMerror PwMDoc::importText_PwM(const QString *file)
2549 if (f.readLine(ch_tmp, ch_tmp_size) == -1) // skip first line. 2549 if (f.readLine(ch_tmp, ch_tmp_size) == -1) // skip first line.
2550 goto formatError; 2550 goto formatError;
2551 2551
2552 //US read fileversion first, then check if ok. 2552 //US read fileversion first, then check if ok.
2553 if (f.readLine(ch_tmp, ch_tmp_size) == -1) 2553 if (f.readLine(ch_tmp, ch_tmp_size) == -1)
2554 goto formatError; 2554 goto formatError;
2555 2555
2556 // check version-string and return version in "ch_tmp". 2556 // check version-string and return version in "ch_tmp".
2557 //US if (fscanf(f, "PwM v%s", ch_tmp) != 1) { 2557 //US if (fscanf(f, "PwM v%s", ch_tmp) != 1) {
2558 //US // header not recognized as PwM generated header 2558 //US // header not recognized as PwM generated header
2559 //US goto formatError; 2559 //US goto formatError;
2560 //US} 2560 //US}
2561 //US set filepointer behind version-string-line previously checked 2561 //US set filepointer behind version-string-line previously checked
2562 //US if (f.readLine(ch_tmp, ch_tmp_size) == -1) 2562 //US if (f.readLine(ch_tmp, ch_tmp_size) == -1)
2563 //US goto formatError; 2563 //US goto formatError;
2564 // skip next line containing the build-date 2564 // skip next line containing the build-date
2565 if (f.readLine(ch_tmp, ch_tmp_size) == -1) 2565 if (f.readLine(ch_tmp, ch_tmp_size) == -1)
2566 goto formatError; 2566 goto formatError;
2567 // read header termination line 2567 // read header termination line
2568 if (f.readLine(ch_tmp, ch_tmp_size) == -1) 2568 if (f.readLine(ch_tmp, ch_tmp_size) == -1)
2569 goto formatError; 2569 goto formatError;
2570 if (strcmp(ch_tmp, "==============================\n")) 2570 if (strcmp(ch_tmp, "==============================\n"))
2571 goto formatError; 2571 goto formatError;
2572 2572
2573 // - read entries 2573 // - read entries
2574 do { 2574 do {
2575 // find beginning of next category 2575 // find beginning of next category
2576 do { 2576 do {
2577 tmp = f.getch(); 2577 tmp = f.getch();
2578 } while (tmp == '\n' && tmp != EOF); 2578 } while (tmp == '\n' && tmp != EOF);
2579 if (tmp == EOF) 2579 if (tmp == EOF)
2580 break; 2580 break;
2581 2581
2582 // decrement filepos by one 2582 // decrement filepos by one
2583 f.at(f.at()-1); 2583 f.at(f.at()-1);
2584 // read cat-name 2584 // read cat-name
2585 if (f.readLine(ch_tmp, ch_tmp_size) == -1) 2585 if (f.readLine(ch_tmp, ch_tmp_size) == -1)
2586 goto formatError; 2586 goto formatError;
2587 // check cat-name format 2587 // check cat-name format
2588 if (memcmp(ch_tmp, "== Category: ", 13) != 0) 2588 if (memcmp(ch_tmp, "== Category: ", 13) != 0)
2589 goto formatError; 2589 goto formatError;
2590 if (memcmp(ch_tmp + (strlen(ch_tmp) - 1 - 3), " ==", 3) != 0) 2590 if (memcmp(ch_tmp + (strlen(ch_tmp) - 1 - 3), " ==", 3) != 0)
2591 goto formatError; 2591 goto formatError;
2592 // copy cat-name 2592 // copy cat-name
2593 curCat.assign(ch_tmp + 13, strlen(ch_tmp) - 1 - 16); 2593 curCat.assign(ch_tmp + 13, strlen(ch_tmp) - 1 - 16);
2594 2594
2595 do { 2595 do {
2596 // find beginning of next entry 2596 // find beginning of next entry
2597 do { 2597 do {
2598 tmp = f.getch(); 2598 tmp = f.getch();
2599 } while (tmp == '\n' && tmp != EOF && tmp != '='); 2599 } while (tmp == '\n' && tmp != EOF && tmp != '=');
2600 if (tmp == EOF) 2600 if (tmp == EOF)
2601 break; 2601 break;
2602 if (tmp == '=') { 2602 if (tmp == '=') {
2603 f.at(f.at()-1); 2603 f.at(f.at()-1);
2604 break; 2604 break;
2605 } 2605 }
2606 // decrement filepos by one 2606 // decrement filepos by one
2607 f.at(f.at()-1); 2607 f.at(f.at()-1);
2608 // read desc-line 2608 // read desc-line
2609 if (f.readLine(ch_tmp, ch_tmp_size) == -1) 2609 if (f.readLine(ch_tmp, ch_tmp_size) == -1)
2610 goto formatError; 2610 goto formatError;
2611 // check desc-line format 2611 // check desc-line format
2612 if (memcmp(ch_tmp, "-- ", 3) != 0) 2612 if (memcmp(ch_tmp, "-- ", 3) != 0)
2613 goto formatError; 2613 goto formatError;
2614 if (memcmp(ch_tmp + (strlen(ch_tmp) - 1 - 3), " --", 3) != 0) 2614 if (memcmp(ch_tmp + (strlen(ch_tmp) - 1 - 3), " --", 3) != 0)
2615 goto formatError; 2615 goto formatError;
2616 // add desc-line 2616 // add desc-line
2617 currItem.desc.assign(ch_tmp + 3, strlen(ch_tmp) - 1 - 6); 2617 currItem.desc.assign(ch_tmp + 3, strlen(ch_tmp) - 1 - 6);
2618 2618
2619 // read username-line 2619 // read username-line
2620 if ((ret = f.readLine(ch_tmp, ch_tmp_size)) == -1) 2620 if ((ret = f.readLine(ch_tmp, ch_tmp_size)) == -1)
2621 goto formatError; 2621 goto formatError;
2622 if (!textExtractEntry_PwM(ch_tmp, ret, &currItem.name)) 2622 if (!textExtractEntry_PwM(ch_tmp, ret, &currItem.name))
2623 goto formatError; 2623 goto formatError;
2624 2624
2625 // read pw-line 2625 // read pw-line
2626 if ((ret = f.readLine(ch_tmp, ch_tmp_size)) == -1) 2626 if ((ret = f.readLine(ch_tmp, ch_tmp_size)) == -1)
2627 goto formatError; 2627 goto formatError;
2628 if (!textExtractEntry_PwM(ch_tmp, ret, &currItem.pw)) 2628 if (!textExtractEntry_PwM(ch_tmp, ret, &currItem.pw))
2629 goto formatError; 2629 goto formatError;
2630 2630
2631 // read comment-line 2631 // read comment-line
2632 if ((ret = f.readLine(ch_tmp, ch_tmp_size)) == -1) 2632 if ((ret = f.readLine(ch_tmp, ch_tmp_size)) == -1)
2633 goto formatError; 2633 goto formatError;
2634 if (!textExtractEntry_PwM(ch_tmp, ret, &currItem.comment)) 2634 if (!textExtractEntry_PwM(ch_tmp, ret, &currItem.comment))
2635 goto formatError; 2635 goto formatError;
2636 2636
2637 // read URL-line 2637 // read URL-line
2638 if ((ret = f.readLine(ch_tmp, ch_tmp_size)) == -1) 2638 if ((ret = f.readLine(ch_tmp, ch_tmp_size)) == -1)
2639 goto formatError; 2639 goto formatError;
2640 if (!textExtractEntry_PwM(ch_tmp, ret, &currItem.url)) 2640 if (!textExtractEntry_PwM(ch_tmp, ret, &currItem.url))
2641 goto formatError; 2641 goto formatError;
2642 2642
2643 // read launcher-line 2643 // read launcher-line
2644 if ((ret = f.readLine(ch_tmp, ch_tmp_size)) == -1) 2644 if ((ret = f.readLine(ch_tmp, ch_tmp_size)) == -1)
2645 goto formatError; 2645 goto formatError;
2646 if (!textExtractEntry_PwM(ch_tmp, ret, &currItem.launcher)) 2646 if (!textExtractEntry_PwM(ch_tmp, ret, &currItem.launcher))
2647 goto formatError; 2647 goto formatError;
2648 2648
2649 currItem.lockStat = true; 2649 currItem.lockStat = true;
2650 currItem.listViewPos = -1; 2650 currItem.listViewPos = -1;
2651 addEntry(curCat.c_str(), &currItem, true); 2651 addEntry(curCat.c_str(), &currItem, true);
2652 ++entriesRead; 2652 ++entriesRead;
2653 } while (1); 2653 } while (1);
2654 } while (1); 2654 } while (1);
2655 if (!entriesRead) 2655 if (!entriesRead)
2656 goto formatError; 2656 goto formatError;
2657 2657
2658 free(ch_tmp); 2658 free(ch_tmp);
2659 f.close(); 2659 f.close();
2660 flagDirty(); 2660 flagDirty();
2661 return e_success; 2661 return e_success;
2662 2662
2663 formatError: 2663 formatError:
2664 free(ch_tmp); 2664 free(ch_tmp);
2665 f.close(); 2665 f.close();
2666 return e_fileFormat; 2666 return e_fileFormat;
2667 2667
2668#endif 2668#endif
2669 2669
2670} 2670}
2671 2671
2672bool PwMDoc::textExtractEntry_PwM(const char *in, ssize_t in_size, string *out) 2672bool PwMDoc::textExtractEntry_PwM(const char *in, ssize_t in_size, string *out)
2673{ 2673{
2674 PWM_ASSERT(in && out); 2674 PWM_ASSERT(in && out);
2675 ssize_t i = 0, len = in_size - 1; 2675 ssize_t i = 0, len = in_size - 1;
2676 while (i < len) { 2676 while (i < len) {
2677 if (in[i] == ':') 2677 if (in[i] == ':')
2678 break; 2678 break;
2679 ++i; 2679 ++i;
2680 } 2680 }
2681 i += 2; 2681 i += 2;
2682 *out = ""; 2682 *out = "";
2683 out->append(in + i, in_size - i - 1); 2683 out->append(in + i, in_size - i - 1);
2684 return true; 2684 return true;
2685} 2685}
2686 2686
2687PwMerror PwMDoc::exportToGpasman(const QString *file) 2687PwMerror PwMDoc::exportToGpasman(const QString *file)
2688{ 2688{
2689 PWM_ASSERT(file); 2689 PWM_ASSERT(file);
2690 GpasmanFile gp; 2690 GpasmanFile gp;
2691 int ret; 2691 int ret;
2692 2692
2693 if (!unlockAll_tempoary()) 2693 if (!unlockAll_tempoary())
2694 return e_lock; 2694 return e_lock;
2695 2695
2696 QString gpmPassword; 2696 QString gpmPassword;
2697 while (1) { 2697 while (1) {
2698 gpmPassword = requestNewMpw(0); 2698 gpmPassword = requestNewMpw(0);
2699 if (gpmPassword == "") { 2699 if (gpmPassword == "") {
2700 unlockAll_tempoary(true); 2700 unlockAll_tempoary(true);
2701 return e_noPw; 2701 return e_noPw;
2702 } 2702 }
2703 if (gpmPassword.length() < 4) { 2703 if (gpmPassword.length() < 4) {
2704 gpmPwLenErrMsgBox(); 2704 gpmPwLenErrMsgBox();
2705 } else { 2705 } else {
2706 break; 2706 break;
2707 } 2707 }
2708 } 2708 }
2709 2709
2710 ret = gp.save_init(file->latin1(), gpmPassword.latin1()); 2710 ret = gp.save_init(file->latin1(), gpmPassword.latin1());
2711 if (ret != 1) { 2711 if (ret != 1) {
2712 unlockAll_tempoary(true); 2712 unlockAll_tempoary(true);
2713 return e_accessFile; 2713 return e_accessFile;
2714 } 2714 }
2715 2715
2716 char *entry[4]; 2716 char *entry[4];
2717 unsigned int numCat = numCategories(), i; 2717 unsigned int numCat = numCategories(), i;
2718 unsigned int numEntr, j; 2718 unsigned int numEntr, j;
2719 int descLen, nameLen, pwLen, commentLen; 2719 int descLen, nameLen, pwLen, commentLen;
2720 for (i = 0; i < numCat; ++i) { 2720 for (i = 0; i < numCat; ++i) {
2721 numEntr = numEntries(i); 2721 numEntr = numEntries(i);
2722 for (j = 0; j < numEntr; ++j) { 2722 for (j = 0; j < numEntr; ++j) {
2723 descLen = dti.dta[i].d[j].desc.length(); 2723 descLen = dti.dta[i].d[j].desc.length();
2724 nameLen = dti.dta[i].d[j].name.length(); 2724 nameLen = dti.dta[i].d[j].name.length();
2725 pwLen = dti.dta[i].d[j].pw.length(); 2725 pwLen = dti.dta[i].d[j].pw.length();
2726 commentLen = dti.dta[i].d[j].comment.length(); 2726 commentLen = dti.dta[i].d[j].comment.length();
2727 entry[0] = new char[descLen + 1]; 2727 entry[0] = new char[descLen + 1];
2728 entry[1] = new char[nameLen + 1]; 2728 entry[1] = new char[nameLen + 1];
2729 entry[2] = new char[pwLen + 1]; 2729 entry[2] = new char[pwLen + 1];
2730 entry[3] = new char[commentLen + 1]; 2730 entry[3] = new char[commentLen + 1];
2731 strcpy(entry[0], descLen == 0 ? " " : dti.dta[i].d[j].desc.c_str()); 2731 strcpy(entry[0], descLen == 0 ? " " : dti.dta[i].d[j].desc.c_str());
2732 strcpy(entry[1], nameLen == 0 ? " " : dti.dta[i].d[j].name.c_str()); 2732 strcpy(entry[1], nameLen == 0 ? " " : dti.dta[i].d[j].name.c_str());
2733 strcpy(entry[2], pwLen == 0 ? " " : dti.dta[i].d[j].pw.c_str()); 2733 strcpy(entry[2], pwLen == 0 ? " " : dti.dta[i].d[j].pw.c_str());
2734 strcpy(entry[3], commentLen == 0 ? " " : dti.dta[i].d[j].comment.c_str()); 2734 strcpy(entry[3], commentLen == 0 ? " " : dti.dta[i].d[j].comment.c_str());
2735 entry[0][descLen == 0 ? descLen + 1 : descLen] = '\0'; 2735 entry[0][descLen == 0 ? descLen + 1 : descLen] = '\0';
2736 entry[1][nameLen == 0 ? nameLen + 1 : nameLen] = '\0'; 2736 entry[1][nameLen == 0 ? nameLen + 1 : nameLen] = '\0';
2737 entry[2][pwLen == 0 ? pwLen + 1 : pwLen] = '\0'; 2737 entry[2][pwLen == 0 ? pwLen + 1 : pwLen] = '\0';
2738 entry[3][commentLen == 0 ? commentLen + 1 : commentLen] = '\0'; 2738 entry[3][commentLen == 0 ? commentLen + 1 : commentLen] = '\0';
2739 2739
2740 ret = gp.save_entry(entry); 2740 ret = gp.save_entry(entry);
2741 if (ret == -1){ 2741 if (ret == -1){
2742 delete [] entry[0]; 2742 delete [] entry[0];
2743 delete [] entry[1]; 2743 delete [] entry[1];
2744 delete [] entry[2]; 2744 delete [] entry[2];
2745 delete [] entry[3]; 2745 delete [] entry[3];
2746 gp.save_finalize(); 2746 gp.save_finalize();
2747 unlockAll_tempoary(true); 2747 unlockAll_tempoary(true);
2748 return e_writeFile; 2748 return e_writeFile;
2749 } 2749 }
2750 2750
2751 delete [] entry[0]; 2751 delete [] entry[0];
2752 delete [] entry[1]; 2752 delete [] entry[1];
2753 delete [] entry[2]; 2753 delete [] entry[2];
2754 delete [] entry[3]; 2754 delete [] entry[3];
2755 } 2755 }
2756 } 2756 }
2757 unlockAll_tempoary(true); 2757 unlockAll_tempoary(true);
2758 if (gp.save_finalize() == -1) 2758 if (gp.save_finalize() == -1)
2759 return e_writeFile; 2759 return e_writeFile;
2760 2760
2761 return e_success; 2761 return e_success;
2762} 2762}
2763 2763
2764PwMerror PwMDoc::importFromGpasman(const QString *file) 2764PwMerror PwMDoc::importFromGpasman(const QString *file)
2765{ 2765{
2766 PWM_ASSERT(file); 2766 PWM_ASSERT(file);
2767 QString pw = requestMpw(false); 2767 QString pw = requestMpw(false);
2768 if (pw == "") 2768 if (pw == "")
2769 return e_noPw; 2769 return e_noPw;
2770 GpasmanFile gp; 2770 GpasmanFile gp;
2771 int ret, i; 2771 int ret, i;
2772 PwMerror ret2; 2772 PwMerror ret2;
2773 char *entry[4]; 2773 char *entry[4];
2774 PwMDataItem tmpData; 2774 PwMDataItem tmpData;
2775 ret = gp.load_init(file->latin1(), pw.latin1()); 2775 ret = gp.load_init(file->latin1(), pw.latin1());
2776 if (ret != 1) 2776 if (ret != 1)
2777 return e_accessFile; 2777 return e_accessFile;
2778 2778
2779 do { 2779 do {
2780 ret = gp.load_entry(entry); 2780 ret = gp.load_entry(entry);
2781 if(ret != 1) 2781 if(ret != 1)
2782 break; 2782 break;
2783 tmpData.desc = entry[0]; 2783 tmpData.desc = entry[0];
2784 tmpData.name = entry[1]; 2784 tmpData.name = entry[1];
2785 tmpData.pw = entry[2]; 2785 tmpData.pw = entry[2];
2786 tmpData.comment = entry[3]; 2786 tmpData.comment = entry[3];
2787 tmpData.lockStat = true; 2787 tmpData.lockStat = true;
2788 tmpData.listViewPos = -1; 2788 tmpData.listViewPos = -1;
2789 ret2 = addEntry(DEFAULT_CATEGORY, &tmpData, true); 2789 ret2 = addEntry(DEFAULT_CATEGORY, &tmpData, true);
2790 for (i = 0; i < 4; ++i) 2790 for (i = 0; i < 4; ++i)
2791 free(entry[i]); 2791 free(entry[i]);
2792 if (ret2 == e_maxAllowedEntr) { 2792 if (ret2 == e_maxAllowedEntr) {
2793 gp.load_finalize(); 2793 gp.load_finalize();
2794 return e_maxAllowedEntr; 2794 return e_maxAllowedEntr;
2795 } 2795 }
2796 } while (1); 2796 } while (1);
2797 gp.load_finalize(); 2797 gp.load_finalize();
2798 if (isDocEmpty()) 2798 if (isDocEmpty())
2799 return e_wrongPw; // we assume this. 2799 return e_wrongPw; // we assume this.
2800 2800
2801 flagDirty(); 2801 flagDirty();
2802 return e_success; 2802 return e_success;
2803} 2803}
2804 2804
2805
2806//US: we use the stl sort algorythm to sort all elements in the order
2807//of its listViewPos (in the order 1,2,3,5,...,x,-1, -1, -1
2808struct PwMDataItemListViewPosSort
2809{
2810 bool operator()(PwMDataItem* rpStart, PwMDataItem* rpEnd)
2811 {
2812 //qDebug("pwMDoc::PwMDataItemListViewPosSort()");
2813 if ((rpEnd)->listViewPos < 0)
2814 return false;
2815 else
2816 return (rpStart)->listViewPos < (rpEnd)->listViewPos;
2817 }
2818};
2819
2805void PwMDoc::ensureLvp() 2820void PwMDoc::ensureLvp()
2806{ 2821{
2807 if (isDocEmpty()) 2822 if (isDocEmpty())
2808 return; 2823 return;
2809 2824
2810 //US ENH BUG: when using syncronizing, this way of sorting 2825 //US ENH BUG: when using syncronizing, this way of sorting
2811 //is not sufficient, because there might be empty spaces 2826 //is not sufficient, because there might be empty spaces
2812 // at the beginning. But this algorythm only can add elements 2827 // at the beginning. But the old algorythm only can add elements
2813 //to the end.The result are crashes because of listoverflows 2828 //to the end.The result are crashes because of list overflows
2814 //we need something to fill all gaps. 2829 //we need something to fill all gaps.
2815 vector< vector<PwMDataItem>::iterator > undefined; 2830 vector<PwMDataItem*> sorted;
2816 vector< vector<PwMDataItem>::iterator > sorted; 2831 vector< PwMDataItem*>::iterator sortedBegin,
2817 vector< vector<PwMDataItem>::iterator >::iterator undefBegin, 2832 sortedEnd,
2818 undefEnd, 2833 sortedI;
2819 undefI;
2820 vector< vector<PwMDataItem>::iterator >::iterator sortedBegin,
2821 sortedEnd,
2822 sortedI;
2823 vector<PwMCategoryItem>::iterator catBegin = dti.dta.begin(), 2834 vector<PwMCategoryItem>::iterator catBegin = dti.dta.begin(),
2824 catEnd = dti.dta.end(), 2835 catEnd = dti.dta.end(),
2825 catI = catBegin; 2836 catI = catBegin;
2826 vector<PwMDataItem>::iterator entrBegin, entrEnd, entrI; 2837 vector<PwMDataItem>::iterator entrBegin, entrEnd, entrI;
2827 int lvpTop, tmpLvp; 2838 int lvpTop, tmpLvp;
2828 2839
2840 //qDebug("collect:");
2841
2829 while (catI != catEnd) { 2842 while (catI != catEnd) {
2830 lvpTop = -1; 2843 lvpTop = -1;
2831 undefined.clear(); 2844 sorted.clear();
2832 2845
2833 entrBegin = catI->d.begin(); 2846 entrBegin = catI->d.begin();
2834 entrEnd = catI->d.end(); 2847 entrEnd = catI->d.end();
2835 entrI = entrBegin; 2848 entrI = entrBegin;
2836 2849
2850 //US: we use the stl sort algorythm to sort all elements in the order
2851 //of its listViewPos (in the order 1,2,2,3,5,...,x,-1, -1, -1
2837 while (entrI != entrEnd) { 2852 while (entrI != entrEnd) {
2838 tmpLvp = entrI->listViewPos; 2853 //qDebug("found: %s, pos=%i", (*entrI).desc.c_str(), (*entrI).listViewPos);
2839 if (tmpLvp == -1) 2854 sorted.push_back((PwMDataItem*)&(*entrI));
2840 undefined.push_back(entrI); 2855 ++entrI;
2841 else
2842 sorted[tmpLvp] = entrI;
2843 //US else if (tmpLvp > lvpTop)
2844 //US lvpTop = tmpLvp;
2845 ++entrI;
2846 } 2856 }
2847 2857
2848 //now we have all undefied in the collection. Now insert the existing 2858 sortedBegin = sorted.begin();
2859 sortedEnd = sorted.end();
2860
2861 sort(sortedBegin, sortedEnd, PwMDataItemListViewPosSort());
2862
2863 // qDebug("resort:");
2864 //now we have all sorted in a collection
2865 //Now start with the sorted and reset listviewpos.
2849 sortedBegin = sorted.begin(); 2866 sortedBegin = sorted.begin();
2850 sortedEnd = sorted.end(); 2867 sortedEnd = sorted.end();
2851 sortedI = sortedBegin; 2868 sortedI = sortedBegin;
2852 2869
2853 while (sortedI != sortedEnd) { 2870 while (sortedI != sortedEnd) {
2854 tmpLvp = (*sortedI)->listViewPos; 2871 // qDebug("reset defined: %s, from pos=%i to pos=%i", (*sortedI)->desc.c_str(), (*sortedI)->listViewPos, lvpTop+1);
2855 undefined[tmpLvp] = *sortedI; 2872 (*sortedI)->listViewPos = ++lvpTop;
2856 ++sortedI; 2873 ++sortedI;
2857 } 2874 }
2858 2875
2859 undefBegin = undefined.begin(); 2876 /*/debug
2860 undefEnd = undefined.end(); 2877 entrBegin = catI->d.begin();
2861 undefI = undefBegin; 2878 entrEnd = catI->d.end();
2862 while (undefI != undefEnd) { 2879 entrI = entrBegin;
2863 (*undefI)->listViewPos = ++lvpTop; 2880
2864 ++undefI; 2881 while (entrI != entrEnd) {
2882 qDebug("check: %s, pos=%i", (*entrI).desc.c_str(), (*entrI).listViewPos);
2883 ++entrI;
2865 } 2884 }
2885 */
2886
2866 ++catI; 2887 ++catI;
2867 } 2888 }
2868} 2889}
2869 2890
2870QString PwMDoc::getTitle() 2891QString PwMDoc::getTitle()
2871{ 2892{
2872 /* NOTE: We have to ensure, that the returned title 2893 /* NOTE: We have to ensure, that the returned title
2873 * is unique and not reused somewhere else while 2894 * is unique and not reused somewhere else while
2874 * this document is valid (open). 2895 * this document is valid (open).
2875 */ 2896 */
2876 QString title(getFilename()); 2897 QString title(getFilename());
2877 2898
2878 //US ENH: The whole filename on PDAs is too long. So use only the last characters 2899 //US ENH: The whole filename on PDAs is too long. So use only the last characters
2879 if (QApplication::desktop()->width() < 640) 2900 if (QApplication::desktop()->width() < 640)
2880 { 2901 {
2881 if (title.length() > 30) 2902 if (title.length() > 30)
2882 title = "..." + title.right(30); 2903 title = "..." + title.right(30);
2883 2904
2884 } 2905 }
2885 2906
2886 2907
2887 if (title.isEmpty()) { 2908 if (title.isEmpty()) {
2888 if (unnamedNum == 0) { 2909 if (unnamedNum == 0) {
2889 unnamedNum = PwMDocList::getNewUnnamedNumber(); 2910 unnamedNum = PwMDocList::getNewUnnamedNumber();
2890 PWM_ASSERT(unnamedNum != 0); 2911 PWM_ASSERT(unnamedNum != 0);
2891 } 2912 }
2892 title = DEFAULT_TITLE; 2913 title = DEFAULT_TITLE;
2893 title += " "; 2914 title += " ";
2894 title += tostr(unnamedNum).c_str(); 2915 title += tostr(unnamedNum).c_str();
2895 } 2916 }
2896 return title; 2917 return title;
2897} 2918}
2898 2919
2899bool PwMDoc::tryDelete() 2920bool PwMDoc::tryDelete()
2900{ 2921{
2901 if (deleted) 2922 if (deleted)
2902 return true; 2923 return true;
2903 int ret; 2924 int ret;
2904 if (isDirty()) { 2925 if (isDirty()) {
2905 ret = dirtyAskSave(getTitle()); 2926 ret = dirtyAskSave(getTitle());
2906 if (ret == 0) { // save to disk 2927 if (ret == 0) { // save to disk
2907 if (!saveDocUi(this)) 2928 if (!saveDocUi(this))
2908 goto out_ignore; 2929 goto out_ignore;
2909 } else if (ret == 1) { // don't save and delete 2930 } else if (ret == 1) { // don't save and delete
2910 goto out_accept; 2931 goto out_accept;
2911 } else { // cancel operation 2932 } else { // cancel operation
2912 goto out_ignore; 2933 goto out_ignore;
2913 } 2934 }
2914 } 2935 }
2915out_accept: 2936out_accept:
2916 deleted = true; 2937 deleted = true;
2917 delete this; 2938 delete this;
2918 return true; 2939 return true;
2919out_ignore: 2940out_ignore:
2920 return false; 2941 return false;
2921} 2942}
2922 2943
2923 2944
2924 2945
2925#ifdef PWM_EMBEDDED 2946#ifdef PWM_EMBEDDED
2926//US ENH: this is the magic function that syncronizes the this doc with the remote doc 2947//US ENH: this is the magic function that syncronizes the this doc with the remote doc
2927//US it could have been defined as static, but I did not want to. 2948//US it could have been defined as static, but I did not want to.
2928PwMerror PwMDoc::syncronize(KSyncManager* manager, PwMDoc* syncLocal , PwMDoc* syncRemote, int mode ) 2949PwMerror PwMDoc::syncronize(KSyncManager* manager, PwMDoc* syncLocal , PwMDoc* syncRemote, int mode )
2929{ 2950{
2930 int addedPasswordsLocal = 0; 2951 int addedPasswordsLocal = 0;
2931 int addedPasswordsRemote = 0; 2952 int addedPasswordsRemote = 0;
2932 int deletedPasswordsRemote = 0; 2953 int deletedPasswordsRemote = 0;
2933 int deletedPasswordsLocal = 0; 2954 int deletedPasswordsLocal = 0;
2934 int changedLocal = 0; 2955 int changedLocal = 0;
2935 int changedRemote = 0; 2956 int changedRemote = 0;
2936 2957
2937 PwMSyncItem* syncItemLocal; 2958 PwMSyncItem* syncItemLocal;
2938 PwMSyncItem* syncItemRemote; 2959 PwMSyncItem* syncItemRemote;
2939 2960
2940 QString mCurrentSyncName = manager->getCurrentSyncName(); 2961 QString mCurrentSyncName = manager->getCurrentSyncName();
2941 QString mCurrentSyncDevice = manager->getCurrentSyncDevice(); 2962 QString mCurrentSyncDevice = manager->getCurrentSyncDevice();
2942 2963
2943 bool fullDateRange = false; 2964 bool fullDateRange = false;
2944 int take; 2965 int take;
2945 // local->resetTempSyncStat(); 2966 // local->resetTempSyncStat();
2946 QDateTime mLastSync = QDateTime::currentDateTime(); 2967 QDateTime mLastSync = QDateTime::currentDateTime();
2947 QDateTime modifiedSync = mLastSync; 2968 QDateTime modifiedSync = mLastSync;
2948 2969
2949 unsigned int index; 2970 unsigned int index;
2950 //Step 1. Find syncinfo in Local file and create if not existent. 2971 //Step 1. Find syncinfo in Local file and create if not existent.
2951 bool found = syncLocal->findSyncData(mCurrentSyncDevice, &index); 2972 bool found = syncLocal->findSyncData(mCurrentSyncDevice, &index);
2952 if (found == false) 2973 if (found == false)
2953 { 2974 {
2954 PwMSyncItem newSyncItemLocal; 2975 PwMSyncItem newSyncItemLocal;
2955 newSyncItemLocal.syncName = mCurrentSyncDevice; 2976 newSyncItemLocal.syncName = mCurrentSyncDevice;
2956 newSyncItemLocal.lastSyncDate = mLastSync; 2977 newSyncItemLocal.lastSyncDate = mLastSync;
2957 syncLocal->addSyncDataEntry(&newSyncItemLocal, true); 2978 syncLocal->addSyncDataEntry(&newSyncItemLocal, true);
2958 found = syncLocal->findSyncData(mCurrentSyncDevice, &index); 2979 found = syncLocal->findSyncData(mCurrentSyncDevice, &index);
2959 if (found == false) { 2980 if (found == false) {
2960 qDebug("PwMDoc::syncronize : newly created local sync data could not be found"); 2981 qDebug("PwMDoc::syncronize : newly created local sync data could not be found");
2961 return e_syncError; 2982 return e_syncError;
2962 } 2983 }
2963 } 2984 }
2964 2985
2965 syncItemLocal = syncLocal->getSyncDataEntry(index); 2986 syncItemLocal = syncLocal->getSyncDataEntry(index);
2966 qDebug("Last Sync Local %s ", syncItemLocal->lastSyncDate.toString().latin1()); 2987 qDebug("Last Sync Local %s ", syncItemLocal->lastSyncDate.toString().latin1());
2967 2988
2968 //Step 2. Find syncinfo in remote file and create if not existent. 2989 //Step 2. Find syncinfo in remote file and create if not existent.
2969 found = syncRemote->findSyncData(mCurrentSyncName, &index); 2990 found = syncRemote->findSyncData(mCurrentSyncName, &index);
2970 if (found == false) 2991 if (found == false)
2971 { 2992 {
2972 qDebug("FULLDATE 1"); 2993 qDebug("FULLDATE 1");
2973 fullDateRange = true; 2994 fullDateRange = true;
2974 PwMSyncItem newSyncItemRemote; 2995 PwMSyncItem newSyncItemRemote;
2975 newSyncItemRemote.syncName = mCurrentSyncName; 2996 newSyncItemRemote.syncName = mCurrentSyncName;
2976 newSyncItemRemote.lastSyncDate = mLastSync; 2997 newSyncItemRemote.lastSyncDate = mLastSync;
2977 syncRemote->addSyncDataEntry(&newSyncItemRemote, true); 2998 syncRemote->addSyncDataEntry(&newSyncItemRemote, true);
2978 found = syncRemote->findSyncData(mCurrentSyncName, &index); 2999 found = syncRemote->findSyncData(mCurrentSyncName, &index);
2979 if (found == false) { 3000 if (found == false) {
2980 qDebug("PwMDoc::syncronize : newly created remote sync data could not be found"); 3001 qDebug("PwMDoc::syncronize : newly created remote sync data could not be found");
2981 return e_syncError; 3002 return e_syncError;
2982 } 3003 }
2983 } 3004 }
2984 3005
2985 syncItemRemote = syncRemote->getSyncDataEntry(index); 3006 syncItemRemote = syncRemote->getSyncDataEntry(index);
2986 qDebug("Last Sync Remote %s ", syncItemRemote->lastSyncDate.toString().latin1()); 3007 qDebug("Last Sync Remote %s ", syncItemRemote->lastSyncDate.toString().latin1());
2987 //and remove the found entry here. We will reenter it later again. 3008 //and remove the found entry here. We will reenter it later again.
2988 //US syncRemote->delSyncDataEntry(index, true); 3009 //US syncRemote->delSyncDataEntry(index, true);
2989 3010
2990 3011
2991 if ( syncItemLocal->lastSyncDate == mLastSync ) { 3012 if ( syncItemLocal->lastSyncDate == mLastSync ) {
2992 qDebug("FULLDATE 2"); 3013 qDebug("FULLDATE 2");
2993 fullDateRange = true; 3014 fullDateRange = true;
2994 } 3015 }
2995 3016
2996 if ( ! fullDateRange ) { 3017 if ( ! fullDateRange ) {
2997 if ( syncItemLocal->lastSyncDate != syncItemRemote->lastSyncDate ) { 3018 if ( syncItemLocal->lastSyncDate != syncItemRemote->lastSyncDate ) {
2998 3019
2999 // qDebug("set fulldate to true %s %s" ,syncItemLocal->lastSyncDate.toString().latin1(), syncItemRemote->lastSyncDate.toString().latin1() );
3000 // qDebug("%d %d %d %d ", syncItemLocal->lastSyncDate.time().second(), addresseeLSync->dtStart().time().msec() , addresseeRSync->dtStart().time().second(), addresseeRSync->dtStart().time().msec());
3001 fullDateRange = true; 3020 fullDateRange = true;
3002 qDebug("FULLDATE 3 %s %s", syncItemLocal->lastSyncDate.toString().latin1() , syncItemRemote->lastSyncDate.toString().latin1() ); 3021 qDebug("FULLDATE 3 %s %s", syncItemLocal->lastSyncDate.toString().latin1() , syncItemRemote->lastSyncDate.toString().latin1() );
3003 } 3022 }
3004 } 3023 }
3005 // fullDateRange = true; // debug only! 3024 // fullDateRange = true; // debug only!
3006 if ( fullDateRange ) 3025 if ( fullDateRange )
3007 mLastSync = QDateTime::currentDateTime().addDays( -100*365); 3026 mLastSync = QDateTime::currentDateTime().addDays( -100*365);
3008 else 3027 else
3009 mLastSync = syncItemLocal->lastSyncDate; 3028 mLastSync = syncItemLocal->lastSyncDate;
3010 3029
3011 3030
3012 qDebug("*************************** "); 3031 qDebug("*************************** ");
3013 qDebug("mLastSync %s ",mLastSync.toString().latin1() ); 3032 qDebug("mLastSync %s ",mLastSync.toString().latin1() );
3014 QStringList er = syncRemote->getIDEntryList(); 3033 QStringList er = syncRemote->getIDEntryList();
3015 PwMDataItem* inRemote ;//= er.first(); 3034 PwMDataItem* inRemote ;//= er.first();
3016 PwMDataItem* inLocal; 3035 PwMDataItem* inLocal;
3017 unsigned int catLocal, indexLocal; 3036 unsigned int catLocal, indexLocal;
3018 unsigned int catRemote, indexRemote; 3037 unsigned int catRemote, indexRemote;
3019 3038
3020 QString uid; 3039 QString uid;
3021 manager->showProgressBar(0, i18n("Syncing - close to abort!"), er.count()); 3040 manager->showProgressBar(0, i18n("Syncing - close to abort!"), er.count());
3022 3041
3023 int modulo = (er.count()/10)+1; 3042 int modulo = (er.count()/10)+1;
3024 unsigned int incCounter = 0; 3043 unsigned int incCounter = 0;
3025 while ( incCounter < er.count()) { 3044 while ( incCounter < er.count()) {
3026 if (manager->isProgressBarCanceled()) 3045 if (manager->isProgressBarCanceled())
3027 return e_syncError; 3046 return e_syncError;
3028 if ( incCounter % modulo == 0 ) 3047 if ( incCounter % modulo == 0 )
3029 manager->showProgressBar(incCounter); 3048 manager->showProgressBar(incCounter);
3030 3049
3031 uid = er[ incCounter ]; 3050 uid = er[ incCounter ];
3032 qDebug("sync uid %s from remote file", uid.latin1()); 3051 qDebug("sync uid %s from remote file", uid.latin1());
3033 3052
3034 qApp->processEvents(); 3053 qApp->processEvents();
3035 3054
3036 inLocal = syncLocal->findEntryByID( uid, &catLocal, &indexLocal ); 3055 inLocal = syncLocal->findEntryByID( uid, &catLocal, &indexLocal );
3037 inRemote = syncRemote->findEntryByID( uid, &catRemote, &indexRemote ); 3056 inRemote = syncRemote->findEntryByID( uid, &catRemote, &indexRemote );
3038 PWM_ASSERT(inRemote); 3057 PWM_ASSERT(inRemote);
3039 if ( inLocal != 0 ) { // maybe conflict - same uid in both files 3058 if ( inLocal != 0 ) { // maybe conflict - same uid in both files
3040 if ( (take = takePwMDataItem( inLocal, inRemote, mLastSync, mode, fullDateRange) ) ) { 3059 if ( (take = takePwMDataItem( inLocal, inRemote, mLastSync, mode, fullDateRange) ) ) {
3041 qDebug("take %d %s ", take, inLocal->desc.c_str()); 3060 qDebug("take %d %s ", take, inLocal->desc.c_str());
3042 if ( take == 3 ) 3061 if ( take == 3 )
3043 return e_syncError; 3062 return e_syncError;
3044 if ( take == 1 ) {// take local 3063 if ( take == 1 ) {// take local
3045 //US syncRemote->removeAddressee( inRemote ); 3064 int oldlistpos = inRemote->listViewPos;
3046 (*inRemote) = (*inLocal); 3065 (*inRemote) = (*inLocal);
3047 //US syncRemote->insertAddressee( inRemote , false); 3066 inRemote->listViewPos = oldlistpos;
3048 ++changedRemote; 3067 ++changedRemote;
3049 } else { // take == 2 take remote 3068 } else { // take == 2 take remote
3050 //US syncLocal->removeAddressee( inLocal ); 3069 int oldlistpos = inLocal->listViewPos;
3051 (*inLocal) = (*inRemote); 3070 (*inLocal) = (*inRemote);
3052 //US syncLocal->insertAddressee( inLocal , false ); 3071 inLocal->listViewPos = oldlistpos;
3053 ++changedLocal; 3072 ++changedLocal;
3054 } 3073 }
3055 } 3074 }
3056 } else { // no conflict 3075 } else { // no conflict
3057 if ( inRemote->meta.update > mLastSync || mode == 5 ) { 3076 if ( inRemote->meta.update > mLastSync || mode == 5 ) {
3058 inRemote->meta.update = modifiedSync; 3077 inRemote->meta.update = modifiedSync;
3059 3078
3060 //first check if we have a matching category in the local file 3079 //first check if we have a matching category in the local file
3061 const string* remotecat = syncRemote->getCategory(catRemote); 3080 const string* remotecat = syncRemote->getCategory(catRemote);
3062 //US syncRemote->insertAddressee( inRemote, false ); 3081 //US syncRemote->insertAddressee( inRemote, false );
3063 //US syncLocal->insertAddressee( inRemote, false ); 3082 //US syncLocal->insertAddressee( inRemote, false );
3064 syncLocal->addEntry(remotecat->c_str(), inRemote, true, false); 3083 syncLocal->addEntry(remotecat->c_str(), inRemote, true, false);
3065 3084
3066 ++addedPasswordsLocal; 3085 ++addedPasswordsLocal;
3067 } else { 3086 } else {
3068 // pending checkExternSyncAddressee(addresseeRSyncSharp, inR); 3087 // pending checkExternSyncAddressee(addresseeRSyncSharp, inR);
3069 syncRemote->delEntry(catRemote, indexRemote, true); 3088 syncRemote->delEntry(catRemote, indexRemote, true);
3070 //USsyncRemote->removeAddressee( inRemote ); 3089 //USsyncRemote->removeAddressee( inRemote );
3071 ++deletedPasswordsRemote; 3090 ++deletedPasswordsRemote;
3072 } 3091 }
3073 } 3092 }
3074 3093
3075 ++incCounter; 3094 ++incCounter;
3076 } 3095 }
3077 3096
3078 3097
3079 er.clear(); 3098 er.clear();
3080 QStringList el = syncLocal->getIDEntryList(); 3099 QStringList el = syncLocal->getIDEntryList();
3081 modulo = (el.count()/10)+1; 3100 modulo = (el.count()/10)+1;
3082 3101
3083 manager->showProgressBar(0, i18n("Add / remove addressees"), el.count()); 3102 manager->showProgressBar(0, i18n("Add / remove addressees"), el.count());
3084 incCounter = 0; 3103 incCounter = 0;
3085 while ( incCounter < el.count()) { 3104 while ( incCounter < el.count()) {
3086 qApp->processEvents(); 3105 qApp->processEvents();
3087 if (manager->isProgressBarCanceled()) 3106 if (manager->isProgressBarCanceled())
3088 return e_syncError; 3107 return e_syncError;
3089 if ( incCounter % modulo == 0 ) 3108 if ( incCounter % modulo == 0 )
3090 manager->showProgressBar(incCounter); 3109 manager->showProgressBar(incCounter);
3091 uid = el[ incCounter ]; 3110 uid = el[ incCounter ];
3092 qDebug("sync uid %s from local file", uid.latin1()); 3111 qDebug("sync uid %s from local file", uid.latin1());
3093 3112
3094 inLocal = syncLocal->findEntryByID( uid, &catLocal, &indexLocal ); 3113 inLocal = syncLocal->findEntryByID( uid, &catLocal, &indexLocal );
3095 inRemote = syncRemote->findEntryByID( uid, &catRemote, &indexRemote ); 3114 inRemote = syncRemote->findEntryByID( uid, &catRemote, &indexRemote );
3096 PWM_ASSERT(inLocal); 3115 PWM_ASSERT(inLocal);
3097 3116
3098 if ( inRemote == 0 ) { 3117 if ( inRemote == 0 ) {
3099 if ( inLocal->meta.update < mLastSync && mode != 4 ) { 3118 if ( inLocal->meta.update < mLastSync && mode != 4 ) {
3100 // pending checkExternSyncAddressee(addresseeLSyncSharp, inL); 3119 // pending checkExternSyncAddressee(addresseeLSyncSharp, inL);
3101 syncLocal->delEntry(catLocal, indexLocal, true); 3120 syncLocal->delEntry(catLocal, indexLocal, true);
3102 //USsyncLocal->removeAddressee( inLocal ); 3121 //USsyncLocal->removeAddressee( inLocal );
3103 ++deletedPasswordsLocal; 3122 ++deletedPasswordsLocal;
3104 } else { 3123 } else {
3105 if ( ! manager->mWriteBackExistingOnly ) { 3124 if ( ! manager->mWriteBackExistingOnly ) {
3106 ++addedPasswordsRemote; 3125 ++addedPasswordsRemote;
3107 inLocal->meta.update = modifiedSync; 3126 inLocal->meta.update = modifiedSync;
3108 3127
3109 //first check if we have a matching category in the remote file 3128 //first check if we have a matching category in the remote file
3110 const string* localcat = syncLocal->getCategory(catLocal); 3129 const string* localcat = syncLocal->getCategory(catLocal);
3111 3130
3112 //USsyncLocal->insertAddressee( inLocal, false ); 3131 //USsyncLocal->insertAddressee( inLocal, false );
3113 PwMDataItem newEntry; 3132 PwMDataItem newEntry;
3114 newEntry = *inLocal; 3133 newEntry = *inLocal;
3115 inRemote = &newEntry; 3134 inRemote = &newEntry;
3116 3135
3117 //USsyncRemote->insertAddressee( inRemote, false ); 3136 //USsyncRemote->insertAddressee( inRemote, false );
3118 syncRemote->addEntry(localcat->c_str(), inRemote, true, false); 3137 syncRemote->addEntry(localcat->c_str(), inRemote, true, false);
3119 3138
3120 } 3139 }
3121 } 3140 }
3122 3141
3123 } 3142 }
3124 ++incCounter; 3143 ++incCounter;
3125 } 3144 }
3126 el.clear(); 3145 el.clear();
3127 manager->hideProgressBar(); 3146 manager->hideProgressBar();
3128 3147
3129 // Now write the info back into the sync data space of the files 3148 // Now write the info back into the sync data space of the files
3130 3149
3131 mLastSync = QDateTime::currentDateTime().addSecs( 1 ); 3150 mLastSync = QDateTime::currentDateTime().addSecs( 1 );
3132 // get rid of micro seconds 3151 // get rid of micro seconds
3133 QTime t = mLastSync.time(); 3152 QTime t = mLastSync.time();
3134 mLastSync.setTime( QTime (t.hour (), t.minute (), t.second () ) ); 3153 mLastSync.setTime( QTime (t.hour (), t.minute (), t.second () ) );
3135 3154
3136 3155
3137 syncItemLocal->lastSyncDate = mLastSync; 3156 syncItemLocal->lastSyncDate = mLastSync;
3138 syncItemRemote->lastSyncDate = mLastSync; 3157 syncItemRemote->lastSyncDate = mLastSync;
3139 3158
3140 // addresseeRSync.setRole( i18n("!Remote from: ")+mCurrentSyncName ) ;
3141 // addresseeLSync.setRole(i18n("!Local from: ") + mCurrentSyncName );
3142
3143 //US syncRemote->addSyncDataEntry( syncItemRemote, false );
3144 //US syncLocal->addSyncDataEntry( syncItemLocal, false );
3145 QString mes; 3159 QString mes;
3146 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 ); 3160 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 );
3147 if ( manager->mShowSyncSummary ) { 3161 if ( manager->mShowSyncSummary ) {
3148 KMessageBox::information(0, mes, i18n("PWM/Pi Synchronization") ); 3162 KMessageBox::information(0, mes, i18n("PWM/Pi Synchronization") );
3149 } 3163 }
3150 qDebug( mes ); 3164 qDebug( mes );
3151 return e_success; 3165 return e_success;
3152} 3166}
3153 3167
3154 3168
3155int PwMDoc::takePwMDataItem( PwMDataItem* local, PwMDataItem* remote, QDateTime lastSync, int mode , bool full ) 3169int PwMDoc::takePwMDataItem( PwMDataItem* local, PwMDataItem* remote, QDateTime lastSync, int mode , bool full )
3156{ 3170{
3157 // 0 equal 3171 // 0 equal
3158 // 1 take local 3172 // 1 take local
3159 // 2 take remote 3173 // 2 take remote
3160 // 3 cancel 3174 // 3 cancel
3161 QDateTime localMod = local->meta.update; 3175 QDateTime localMod = local->meta.update;
3162 QDateTime remoteMod = remote->meta.update; 3176 QDateTime remoteMod = remote->meta.update;
3163 3177
3164 //US QString mCurrentSyncDevice = syncManager->getCurrentSyncDevice(); 3178 //US QString mCurrentSyncDevice = syncManager->getCurrentSyncDevice();
3165 3179
3166 if ( localMod == remoteMod ) 3180 if ( localMod == remoteMod )
3167 return 0; 3181 return 0;
3168 3182
3169 qDebug(" %d %d conflict on %s %s ", mode, full, local->desc.c_str(), remote->desc.c_str() ); 3183 qDebug(" %d %d conflict on %s %s ", mode, full, local->desc.c_str(), remote->desc.c_str() );
3170 3184
3171 //qDebug("%s %d %s %d", local->lastModified().toString().latin1() , localMod, remote->lastModified().toString().latin1(), remoteMod); 3185 //qDebug("%s %d %s %d", local->lastModified().toString().latin1() , localMod, remote->lastModified().toString().latin1(), remoteMod);
3172 //qDebug("%d %d %d %d ", local->lastModified().time().second(), local->lastModified().time().msec(), remote->lastModified().time().second(), remote->lastModified().time().msec() ); 3186 //qDebug("%d %d %d %d ", local->lastModified().time().second(), local->lastModified().time().msec(), remote->lastModified().time().second(), remote->lastModified().time().msec() );
3173 full = true; //debug only 3187 //full = true; //debug only
3174 if ( full ) { 3188 if ( full ) {
3175 bool equ = ( (*local) == (*remote) ); 3189 bool equ = ( (*local) == (*remote) );
3176 if ( equ ) { 3190 if ( equ ) {
3177 qDebug("equal "); 3191 //qDebug("equal ");
3178 if ( mode < SYNC_PREF_FORCE_LOCAL ) 3192 if ( mode < SYNC_PREF_FORCE_LOCAL )
3179 return 0; 3193 return 0;
3180 3194
3181 }else //debug only 3195 }//else //debug only
3182 qDebug("not equal %s %s ", local->desc.c_str(), remote->desc.c_str()); 3196 //qDebug("not equal %s %s ", local->desc.c_str(), remote->desc.c_str());
3183 } 3197 }
3184 3198
3185 int result; 3199 int result;
3186 bool localIsNew; 3200 bool localIsNew;
3187 //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() ); 3201 //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() );
3188 3202
3189 if ( full && mode < SYNC_PREF_NEWEST ) 3203 if ( full && mode < SYNC_PREF_NEWEST )
3190 mode = SYNC_PREF_ASK; 3204 mode = SYNC_PREF_ASK;
3191 3205
3192 switch( mode ) { 3206 switch( mode ) {
3193 case SYNC_PREF_LOCAL: 3207 case SYNC_PREF_LOCAL:
3194 if ( lastSync > remoteMod ) 3208 if ( lastSync > remoteMod )
3195 return 1; 3209 return 1;
3196 if ( lastSync > localMod ) 3210 if ( lastSync > localMod )
3197 return 2; 3211 return 2;
3198 return 1; 3212 return 1;
3199 break; 3213 break;
3200 case SYNC_PREF_REMOTE: 3214 case SYNC_PREF_REMOTE:
3201 if ( lastSync > remoteMod ) 3215 if ( lastSync > remoteMod )
3202 return 1; 3216 return 1;
3203 if ( lastSync > localMod ) 3217 if ( lastSync > localMod )
3204 return 2; 3218 return 2;
3205 return 2; 3219 return 2;
3206 break; 3220 break;
3207 case SYNC_PREF_NEWEST: 3221 case SYNC_PREF_NEWEST:
3208 if ( localMod > remoteMod ) 3222 if ( localMod > remoteMod )
3209 return 1; 3223 return 1;
3210 else 3224 else
3211 return 2; 3225 return 2;
3212 break; 3226 break;
3213 case SYNC_PREF_ASK: 3227 case SYNC_PREF_ASK:
3214 //qDebug("lsy %s --- lo %s --- re %s ", lastSync.toString().latin1(), localMod.toString().latin1(), remoteMod.toString().latin1() ); 3228 //qDebug("lsy %s --- lo %s --- re %s ", lastSync.toString().latin1(), localMod.toString().latin1(), remoteMod.toString().latin1() );
3215 if ( lastSync > remoteMod ) 3229 if ( lastSync > remoteMod )
3216 return 1; 3230 return 1;
3217 if ( lastSync > localMod ) 3231 if ( lastSync > localMod )
3218 return 2; 3232 return 2;
3219 localIsNew = localMod >= remoteMod; 3233 localIsNew = localMod >= remoteMod;
3220 //qDebug("conflict! ************************************** "); 3234 //qDebug("conflict! ************************************** ");
3221 { 3235 {
3222 PwMDataItemChooser acd ( *local,*remote, localIsNew , 0/*this*/ ); 3236 PwMDataItemChooser acd ( *local,*remote, localIsNew , 0/*this*/ );
3223 result = acd.executeD(localIsNew); 3237 result = acd.executeD(localIsNew);
3224 return result; 3238 return result;
3225 } 3239 }
3226 break; 3240 break;
3227 case SYNC_PREF_FORCE_LOCAL: 3241 case SYNC_PREF_FORCE_LOCAL:
3228 return 1; 3242 return 1;
3229 break; 3243 break;
3230 case SYNC_PREF_FORCE_REMOTE: 3244 case SYNC_PREF_FORCE_REMOTE:
3231 return 2; 3245 return 2;
3232 break; 3246 break;
3233 3247
3234 default: 3248 default:
3235 // SYNC_PREF_TAKE_BOTH not implemented 3249 // SYNC_PREF_TAKE_BOTH not implemented
3236 break; 3250 break;
3237 } 3251 }
3238 return 0; 3252 return 0;
3239} 3253}
3240 3254
3241 3255
3242 3256
3243 3257
3244//this are the overwritten callbackmethods from the syncinterface 3258//this are the overwritten callbackmethods from the syncinterface
3245bool PwMDoc::sync(KSyncManager* manager, QString filename, int mode) 3259bool PwMDoc::sync(KSyncManager* manager, QString filename, int mode)
3246{ 3260{
3247 QString mCurrentSyncDevice = manager->getCurrentSyncDevice(); 3261 QString mCurrentSyncDevice = manager->getCurrentSyncDevice();
3248 3262
3249 //1) unlock local file first if necessary (ask for password) 3263 //1) unlock local file first if necessary (ask for password)
3250 if (this->isDeepLocked()) { 3264 if (this->isDeepLocked()) {
3251 PwMerror ret = this->deepLock(false); 3265 PwMerror ret = this->deepLock(false);
3252 if (ret != e_success) 3266 if (ret != e_success)
3253 return false; 3267 return false;
3254 } 3268 }
3255 3269
3256 //2) construct and open a new doc on the stack(automatic cleanup of remote file). 3270 //2) construct and open a new doc on the stack(automatic cleanup of remote file).
3257 PwMDoc syncTarget(this, "synctarget"); 3271 PwMDoc syncTarget(this, "synctarget");
3258 PwMDoc* pSyncTarget = &syncTarget; 3272 PwMDoc* pSyncTarget = &syncTarget;
3259 3273
3260 3274
3261 PwMerror err = pSyncTarget->openDoc(&filename, 1 /*== open with all entries locked*/); 3275 PwMerror err = pSyncTarget->openDoc(&filename, 1 /*== open with all entries locked*/);
3262 3276
3263 if (err == e_alreadyOpen) { 3277 if (err == e_alreadyOpen) {
3264 PwMDocList::listItem li; 3278 PwMDocList::listItem li;
3265 if (getOpenDocList()->find(filename.latin1(), &li)) 3279 if (getOpenDocList()->find(filename.latin1(), &li))
3266 pSyncTarget = li.doc; 3280 pSyncTarget = li.doc;
3267 else { 3281 else {
3268 qDebug("PwmDoc::sync: sync failed. Error %i while opening file %s",err, filename.latin1()); 3282 qDebug("PwmDoc::sync: sync failed. Error %i while opening file %s",err, filename.latin1());
3269 return false; 3283 return false;
3270 } 3284 }
3271 } 3285 }
3272 else if (err != e_success) { 3286 else if (err != e_success) {
3273 qDebug("PwmDoc::sync: sync failed. Error %i while opening file %s",err, filename.latin1()); 3287 qDebug("PwmDoc::sync: sync failed. Error %i while opening file %s",err, filename.latin1());
3274 return false; 3288 return false;
3275 } 3289 }
3276 3290
3277 qDebug("PWM file loaded %s,sync mode %d",filename.latin1(), mode ); 3291 qDebug("PWM file loaded %s,sync mode %d",filename.latin1(), mode );
3278 3292
3279 3293
3280 //3) unlock remote file first if necessary (ask for password) 3294 //3) unlock remote file first if necessary (ask for password)
3281 if (pSyncTarget->isDeepLocked()) { 3295 if (pSyncTarget->isDeepLocked()) {
3282 PwMerror ret = pSyncTarget->deepLock(false); 3296 PwMerror ret = pSyncTarget->deepLock(false);
3283 if (ret != e_success) 3297 if (ret != e_success)
3284 return false; 3298 return false;
3285 } 3299 }
3286 3300
3287 3301
3288 err = syncronize(manager, this, pSyncTarget, mode ); 3302 err = syncronize(manager, this, pSyncTarget, mode );
3289 3303
3290 if (err == e_success) { 3304 if (err == e_success) {
3291 if ( manager->mWriteBackFile ){ 3305 if ( manager->mWriteBackFile ){
3292 qDebug("Saving remote PWManager file"); 3306 qDebug("Saving remote PWManager file");
3293 err = pSyncTarget->saveDoc(conf()->confGlobCompression()); 3307 err = pSyncTarget->saveDoc(conf()->confGlobCompression());
3294 if (err != e_success) { 3308 if (err != e_success) {
3295 qDebug("PwmDoc::sync: Sync failed. Error %i while storing file %s",err, filename.latin1()); 3309 qDebug("PwmDoc::sync: Sync failed. Error %i while storing file %s",err, filename.latin1());
3296 return false; 3310 return false;
3297 } 3311 }
3298 } 3312 }
3299 3313
3300 flagDirty(); 3314 flagDirty();
3301 return true; 3315 return true;
3302 } 3316 }
3303 else { 3317 else {
3304 return false; 3318 return false;
3305 } 3319 }
3306} 3320}
3307 3321
3308#endif 3322#endif
3309 3323
3310 3324
3311bool PwMDoc::findSyncData(const QString &syncname, unsigned int *index) 3325bool PwMDoc::findSyncData(const QString &syncname, unsigned int *index)
3312{ 3326{
3313 vector<PwMSyncItem>::iterator i = dti.syncDta.begin(), 3327 vector<PwMSyncItem>::iterator i = dti.syncDta.begin(),
3314 end = dti.syncDta.end(); 3328 end = dti.syncDta.end();
3315 3329
3316 while (i != end) { 3330 while (i != end) {
3317 if ((*i).syncName == syncname.latin1()) { 3331 if ((*i).syncName == syncname.latin1()) {
3318 if (index) { 3332 if (index) {
3319 *index = i - dti.syncDta.begin(); 3333 *index = i - dti.syncDta.begin();
3320 } 3334 }
3321 return true; 3335 return true;
3322 } 3336 }
3323 ++i; 3337 ++i;
3324 } 3338 }
3325 return false; 3339 return false;
3326}; 3340};
3327 3341
3328/** add new syncdataentry */ 3342/** add new syncdataentry */
3329PwMerror PwMDoc::addSyncDataEntry(PwMSyncItem *d, bool dontFlagDirty) 3343PwMerror PwMDoc::addSyncDataEntry(PwMSyncItem *d, bool dontFlagDirty)
3330{ 3344{
3331 PWM_ASSERT(d); 3345 PWM_ASSERT(d);
3332 3346
3333 if (isDeepLocked()) { 3347 if (isDeepLocked()) {
3334 PwMerror ret; 3348 PwMerror ret;
3335 ret = deepLock(false); 3349 ret = deepLock(false);
3336 if (ret != e_success) 3350 if (ret != e_success)
3337 return e_lock; 3351 return e_lock;
3338 } 3352 }
3339 unsigned int index; 3353 unsigned int index;
3340 3354
3341 const QString tmp = d->syncName.c_str(); 3355 const QString tmp = d->syncName.c_str();
3342 bool exists = findSyncData(d->syncName.c_str(), &index); 3356 bool exists = findSyncData(d->syncName.c_str(), &index);
3343 3357
3344 if (exists == true) { 3358 if (exists == true) {
3345 // DOH! We found this entry. 3359 // DOH! We found this entry.
3346 return e_entryExists; 3360 return e_entryExists;
3347 } 3361 }
3348 3362
3349 dti.syncDta.push_back(*d); 3363 dti.syncDta.push_back(*d);
3350 3364
3351 if (!dontFlagDirty) 3365 if (!dontFlagDirty)
3352 flagDirty(); 3366 flagDirty();
3353 return e_success; 3367 return e_success;
3354} 3368}
3355 3369
3356 3370
3357 3371
3358/** delete syncdata entry */ 3372/** delete syncdata entry */
3359bool PwMDoc::delSyncDataEntry(unsigned int index, bool dontFlagDirty) 3373bool PwMDoc::delSyncDataEntry(unsigned int index, bool dontFlagDirty)
3360{ 3374{
3361 if (isDeepLocked()) 3375 if (isDeepLocked())
3362 return false; 3376 return false;
3363 if (index > dti.syncDta.size() - 1) 3377 if (index > dti.syncDta.size() - 1)
3364 return false; 3378 return false;
3365 3379
3366 // delete entry 3380 // delete entry
3367 dti.syncDta.erase(dti.syncDta.begin() + index); 3381 dti.syncDta.erase(dti.syncDta.begin() + index);
3368 3382
3369 if (!dontFlagDirty) 3383 if (!dontFlagDirty)
3370 flagDirty(); 3384 flagDirty();
3371 return true; 3385 return true;
3372} 3386}
3373 3387
3374 3388
3375PwMDataItem* PwMDoc::findEntryByID(const QString &uid, unsigned int *category, unsigned int *index) 3389PwMDataItem* PwMDoc::findEntryByID(const QString &uid, unsigned int *category, unsigned int *index)
3376{ 3390{
3377 vector<PwMCategoryItem>::iterator catcounter = dti.dta.begin(), 3391 vector<PwMCategoryItem>::iterator catcounter = dti.dta.begin(),
3378 catend = dti.dta.end(); 3392 catend = dti.dta.end();
3379 3393
3380 vector<PwMDataItem>::iterator entrBegin, entrEnd, entrI; 3394 vector<PwMDataItem>::iterator entrBegin, entrEnd, entrI;
3381 3395
3382 while (catcounter != catend) { 3396 while (catcounter != catend) {
3383 entrBegin = catcounter->d.begin(); 3397 entrBegin = catcounter->d.begin();
3384 entrEnd = catcounter->d.end(); 3398 entrEnd = catcounter->d.end();
3385 entrI = entrBegin; 3399 entrI = entrBegin;
3386 while (entrI != entrEnd) { 3400 while (entrI != entrEnd) {
3387 if ((*entrI).meta.uniqueid == uid.latin1()) { 3401 if ((*entrI).meta.uniqueid == uid.latin1()) {
3388 if (category) 3402 if (category)
3389 *category = catcounter - dti.dta.begin(); 3403 *category = catcounter - dti.dta.begin();
3390 if (index) 3404 if (index)
3391 *index = entrI - entrBegin; 3405 *index = entrI - entrBegin;
3392 3406
3393 return &(*entrI); 3407 return &(*entrI);
3394 } 3408 }
3395 ++entrI; 3409 ++entrI;
3396 } 3410 }
3397 ++catcounter; 3411 ++catcounter;
3398 } 3412 }
3399 3413
3400 return 0; 3414 return 0;
3401} 3415}
3402 3416
3403QStringList PwMDoc::getIDEntryList() 3417QStringList PwMDoc::getIDEntryList()
3404{ 3418{
3405 QStringList results; 3419 QStringList results;
3406 3420
3407 vector<PwMCategoryItem>::iterator catcounter = dti.dta.begin(), 3421 vector<PwMCategoryItem>::iterator catcounter = dti.dta.begin(),
3408 catend = dti.dta.end(); 3422 catend = dti.dta.end();
3409 3423
3410 vector<PwMDataItem>::iterator entrBegin, entrEnd, entrI; 3424 vector<PwMDataItem>::iterator entrBegin, entrEnd, entrI;
3411 3425
3412 while (catcounter != catend) { 3426 while (catcounter != catend) {
3413 entrBegin = catcounter->d.begin(); 3427 entrBegin = catcounter->d.begin();
3414 entrEnd = catcounter->d.end(); 3428 entrEnd = catcounter->d.end();
3415 entrI = entrBegin; 3429 entrI = entrBegin;
3416 while (entrI != entrEnd) { 3430 while (entrI != entrEnd) {
3417 results.append( (*entrI).meta.uniqueid.c_str() ); 3431 results.append( (*entrI).meta.uniqueid.c_str() );
3418 ++entrI; 3432 ++entrI;
3419 } 3433 }
3420 ++catcounter; 3434 ++catcounter;
3421 } 3435 }
3422 3436
3423 return results; 3437 return results;
3424} 3438}
3425 3439
3426 3440
3427 3441
3428 3442
3429 3443
3430#ifndef PWM_EMBEDDED 3444#ifndef PWM_EMBEDDED
3431#include "pwmdoc.moc" 3445#include "pwmdoc.moc"
3432#endif 3446#endif
diff --git a/pwmanager/pwmanager/pwmdoc.h b/pwmanager/pwmanager/pwmdoc.h
index 6a1dd30..535fb92 100644
--- a/pwmanager/pwmanager/pwmdoc.h
+++ b/pwmanager/pwmanager/pwmdoc.h
@@ -1,499 +1,480 @@
1/*************************************************************************** 1/***************************************************************************
2 * * 2 * *
3 * copyright (C) 2003, 2004 by Michael Buesch * 3 * copyright (C) 2003, 2004 by Michael Buesch *
4 * email: mbuesch@freenet.de * 4 * email: mbuesch@freenet.de *
5 * * 5 * *
6 * This program is free software; you can redistribute it and/or modify * 6 * This program is free software; you can redistribute it and/or modify *
7 * it under the terms of the GNU General Public License version 2 * 7 * it under the terms of the GNU General Public License version 2 *
8 * as published by the Free Software Foundation. * 8 * as published by the Free Software Foundation. *
9 * * 9 * *
10 ***************************************************************************/ 10 ***************************************************************************/
11 11
12/*************************************************************************** 12/***************************************************************************
13 * copyright (C) 2004 by Ulf Schenk 13 * copyright (C) 2004 by Ulf Schenk
14 * This file is originaly based on version 2.0 of pwmanager 14 * This file is originaly based on version 2.0 of pwmanager
15 * and was modified to run on embedded devices that run microkde 15 * and was modified to run on embedded devices that run microkde
16 * 16 *
17 * $Id$ 17 * $Id$
18 **************************************************************************/ 18 **************************************************************************/
19 19
20#ifndef __PWMDOC_H 20#ifndef __PWMDOC_H
21#define __PWMDOC_H 21#define __PWMDOC_H
22 22
23 #define PWM_FILE_VER (static_cast<char>(0x05)) 23 #define PWM_FILE_VER (static_cast<char>(0x05))
24 24
25 #define PWM_HASH_SHA1 (static_cast<char>(0x01)) 25 #define PWM_HASH_SHA1 (static_cast<char>(0x01))
26 #define PWM_HASH_SHA256 (static_cast<char>(0x02)) 26 #define PWM_HASH_SHA256 (static_cast<char>(0x02))
27 #define PWM_HASH_SHA384 (static_cast<char>(0x03)) 27 #define PWM_HASH_SHA384 (static_cast<char>(0x03))
28 #define PWM_HASH_SHA512 (static_cast<char>(0x04)) 28 #define PWM_HASH_SHA512 (static_cast<char>(0x04))
29 #define PWM_HASH_MD5 (static_cast<char>(0x05)) 29 #define PWM_HASH_MD5 (static_cast<char>(0x05))
30 #define PWM_HASH_RMD160 (static_cast<char>(0x06)) 30 #define PWM_HASH_RMD160 (static_cast<char>(0x06))
31 #define PWM_HASH_TIGER (static_cast<char>(0x07)) 31 #define PWM_HASH_TIGER (static_cast<char>(0x07))
32 32
33 #define PWM_CRYPT_BLOWFISH(static_cast<char>(0x01)) 33 #define PWM_CRYPT_BLOWFISH(static_cast<char>(0x01))
34 #define PWM_CRYPT_AES128(static_cast<char>(0x02)) 34 #define PWM_CRYPT_AES128(static_cast<char>(0x02))
35 #define PWM_CRYPT_AES192(static_cast<char>(0x03)) 35 #define PWM_CRYPT_AES192(static_cast<char>(0x03))
36 #define PWM_CRYPT_AES256(static_cast<char>(0x04)) 36 #define PWM_CRYPT_AES256(static_cast<char>(0x04))
37 #define PWM_CRYPT_3DES (static_cast<char>(0x05)) 37 #define PWM_CRYPT_3DES (static_cast<char>(0x05))
38 #define PWM_CRYPT_TWOFISH(static_cast<char>(0x06)) 38 #define PWM_CRYPT_TWOFISH(static_cast<char>(0x06))
39 #define PWM_CRYPT_TWOFISH128(static_cast<char>(0x07)) 39 #define PWM_CRYPT_TWOFISH128(static_cast<char>(0x07))
40 40
41 #define PWM_COMPRESS_NONE(static_cast<char>(0x00)) 41 #define PWM_COMPRESS_NONE(static_cast<char>(0x00))
42 #define PWM_COMPRESS_GZIP(static_cast<char>(0x01)) 42 #define PWM_COMPRESS_GZIP(static_cast<char>(0x01))
43 #define PWM_COMPRESS_BZIP2(static_cast<char>(0x02)) 43 #define PWM_COMPRESS_BZIP2(static_cast<char>(0x02))
44 44
45 #define DEFAULT_MAX_ENTRIES(~(static_cast<unsigned int>(0))) 45 #define DEFAULT_MAX_ENTRIES(~(static_cast<unsigned int>(0)))
46 #define FILE_ID_HEADER "PWM_PASSWORD_FILE" 46 #define FILE_ID_HEADER "PWM_PASSWORD_FILE"
47 47
48 48
49#include "pwmexception.h" 49#include "pwmexception.h"
50#include "pwmdocui.h" 50#include "pwmdocui.h"
51 51
52#include <qobject.h> 52#include <qobject.h>
53#include <qtimer.h> 53#include <qtimer.h>
54#include <qdatetime.h> 54#include <qdatetime.h>
55 55
56#include <kprocess.h> 56#include <kprocess.h>
57 57
58#ifndef PWM_EMBEDDED 58#ifndef PWM_EMBEDDED
59#include "configuration.h" 59#include "configuration.h"
60#else 60#else
61#include <kapplication.h> 61#include <kapplication.h>
62#include <ksyncmanager.h> 62#include <ksyncmanager.h>
63#endif 63#endif
64 64
65#include <string> 65#include <string>
66#include <vector> 66#include <vector>
67#include <utility> 67#include <utility>
68 68
69using std::vector; 69using std::vector;
70using std::string; 70using std::string;
71using std::pair; 71using std::pair;
72 72
73/* used in findEntry() function */ 73/* used in findEntry() function */
74 #define SEARCH_IN_DESC (1) 74 #define SEARCH_IN_DESC (1)
75 #define SEARCH_IN_NAME (1 << 1) 75 #define SEARCH_IN_NAME (1 << 1)
76 #define SEARCH_IN_PW (1 << 2) 76 #define SEARCH_IN_PW (1 << 2)
77 #define SEARCH_IN_COMMENT(1 << 3) 77 #define SEARCH_IN_COMMENT(1 << 3)
78 #define SEARCH_IN_URL (1 << 4) 78 #define SEARCH_IN_URL (1 << 4)
79 #define SEARCH_IN_LAUNCHER(1 << 5) 79 #define SEARCH_IN_LAUNCHER(1 << 5)
80 #define SEARCH_IN_ALL (SEARCH_IN_DESC | SEARCH_IN_NAME| \ 80 #define SEARCH_IN_ALL (SEARCH_IN_DESC | SEARCH_IN_NAME| \
81 SEARCH_IN_PW | SEARCH_IN_COMMENT| \ 81 SEARCH_IN_PW | SEARCH_IN_COMMENT| \
82 SEARCH_IN_URL| SEARCH_IN_LAUNCHER) 82 SEARCH_IN_URL| SEARCH_IN_LAUNCHER)
83 83
84/** document deeplocked. Data is out for lunch to disk */ 84/** document deeplocked. Data is out for lunch to disk */
85 #define DOC_STAT_DEEPLOCKED (1) 85 #define DOC_STAT_DEEPLOCKED (1)
86/** encrypted document on disk is dirty. data has to go to disk. */ 86/** encrypted document on disk is dirty. data has to go to disk. */
87 #define DOC_STAT_DISK_DIRTY (1 << 1) 87 #define DOC_STAT_DISK_DIRTY (1 << 1)
88/** we are using a chipcard to encrypt the data */ 88/** we are using a chipcard to encrypt the data */
89 #define DOC_STAT_USE_CHIPCARD (1 << 2) 89 #define DOC_STAT_USE_CHIPCARD (1 << 2)
90/** use "currentPw" to unlock. (This flag is set/unset by a timer) */ 90/** use "currentPw" to unlock. (This flag is set/unset by a timer) */
91 #define DOC_STAT_UNLOCK_WITHOUT_PW(1 << 3) 91 #define DOC_STAT_UNLOCK_WITHOUT_PW(1 << 3)
92 92
93class PwMDoc; 93class PwMDoc;
94class PwMView; 94class PwMView;
95class QFile; 95class QFile;
96 96
97/* meta data for a PwMDataItem */ 97/* meta data for a PwMDataItem */
98struct PwMMetaData 98struct PwMMetaData
99{ 99{
100 PwMMetaData() 100 PwMMetaData()
101 : updateInt (0) 101 : updateInt (0)
102 { } 102 { }
103 /** creation date of the PwMDataItem to which 103 /** creation date of the PwMDataItem to which
104 * this meta data belongs. 104 * this meta data belongs.
105 */ 105 */
106 QDateTimecreate; 106 QDateTimecreate;
107 /** becomes valid on this date */ 107 /** becomes valid on this date */
108 QDateTimevalid; 108 QDateTimevalid;
109 /** expire date */ 109 /** expire date */
110 QDateTimeexpire; 110 QDateTimeexpire;
111 /** update date (last updated at this date) */ 111 /** update date (last updated at this date) */
112 QDateTimeupdate; 112 QDateTimeupdate;
113 /** update interval (in minutes). Time since the 113 /** update interval (in minutes). Time since the
114 * last update to remind the user to update the item. 114 * last update to remind the user to update the item.
115 * 0 disables. 115 * 0 disables.
116 */ 116 */
117 unsigned long updateInt; 117 unsigned long updateInt;
118 118
119 //US ENH: enhancements of the filestructure 119 //US ENH: enhancements of the filestructure
120 /* each entry gets a unique id assigned */ 120 /* each entry gets a unique id assigned */
121 string uniqueid; 121 string uniqueid;
122 122
123 123
124 void clear() 124 void clear()
125 { 125 {
126 create = QDateTime(); 126 create = QDateTime();
127 expire = QDateTime(); 127 expire = QDateTime();
128 update = QDateTime(); 128 update = QDateTime();
129 updateInt = 0; 129 updateInt = 0;
130 uniqueid = KApplication::randomString(8); 130 uniqueid = KApplication::randomString(8);
131 } 131 }
132 132
133 inline bool isValid() const 133 inline bool isValid() const
134 { 134 {
135 if (valid.isNull()) 135 if (valid.isNull())
136 return true; 136 return true;
137 return (valid < QDateTime::currentDateTime()); 137 return (valid < QDateTime::currentDateTime());
138 } 138 }
139 inline bool isExpired() const 139 inline bool isExpired() const
140 { 140 {
141 if (expire.isNull()) 141 if (expire.isNull())
142 return false; 142 return false;
143 return (expire < QDateTime::currentDateTime()); 143 return (expire < QDateTime::currentDateTime());
144 } 144 }
145 inline bool isUpdateIntOver() const 145 inline bool isUpdateIntOver() const
146 { 146 {
147 if (updateInt == 0 || 147 if (updateInt == 0 ||
148 update.isNull()) 148 update.isNull())
149 return false; 149 return false;
150 QDateTime d(update); 150 QDateTime d(update);
151 return (d.addSecs(updateInt * 60) < QDateTime::currentDateTime()); 151 return (d.addSecs(updateInt * 60) < QDateTime::currentDateTime());
152 } 152 }
153}; 153};
154 154
155struct PwMDataItem 155struct PwMDataItem
156{ 156{
157 PwMDataItem() 157 PwMDataItem()
158 : lockStat (true) 158 : lockStat (true)
159 , listViewPos (-1) 159 , listViewPos (-1)
160 , binary (false) 160 , binary (false)
161 , rev (0) 161 , rev (0)
162 { } 162 { }
163 163
164 /** password description */ 164 /** password description */
165 stringdesc; 165 stringdesc;
166 /** user-name */ 166 /** user-name */
167 stringname; 167 stringname;
168 /** the password itself */ 168 /** the password itself */
169 stringpw; 169 stringpw;
170 /** some comment */ 170 /** some comment */
171 stringcomment; 171 stringcomment;
172 /** an URL string */ 172 /** an URL string */
173 stringurl; 173 stringurl;
174 /** launcher. Can be executed as a system() command */ 174 /** launcher. Can be executed as a system() command */
175 stringlauncher; 175 stringlauncher;
176 /** locking status. If locked (true), pw is not emitted through getEntry() */ 176 /** locking status. If locked (true), pw is not emitted through getEntry() */
177 boollockStat; 177 boollockStat;
178 /** position of this item in main "list-view" 178 /** position of this item in main "list-view"
179 * If -1, the position is not yet specified and should be appended to the list 179 * If -1, the position is not yet specified and should be appended to the list
180 */ 180 */
181 intlistViewPos; 181 intlistViewPos;
182 /** does this entry contain binary data? */ 182 /** does this entry contain binary data? */
183 bool binary; 183 bool binary;
184 /** meta data for this data item. */ 184 /** meta data for this data item. */
185 PwMMetaData meta; 185 PwMMetaData meta;
186 /** data revision counter. This counter can be used 186 /** data revision counter. This counter can be used
187 * to easily, efficiently determine if this data item 187 * to easily, efficiently determine if this data item
188 * has changed since some time. 188 * has changed since some time.
189 * This counter is incremented on every update. 189 * This counter is incremented on every update.
190 */ 190 */
191 unsigned int rev; 191 unsigned int rev;
192 192
193 void clear(bool clearMeta = true) 193 void clear(bool clearMeta = true)
194 { 194 {
195 /* NOTE: Don't use .clear() here to be 195 /* NOTE: Don't use .clear() here to be
196 * backward compatible with gcc-2 (Debian Woody) 196 * backward compatible with gcc-2 (Debian Woody)
197 */ 197 */
198 desc = ""; 198 desc = "";
199 name = ""; 199 name = "";
200 pw = ""; 200 pw = "";
201 comment = ""; 201 comment = "";
202 url = ""; 202 url = "";
203 launcher = ""; 203 launcher = "";
204 lockStat = true; 204 lockStat = true;
205 listViewPos = -1; 205 listViewPos = -1;
206 binary = false; 206 binary = false;
207 if (clearMeta) 207 if (clearMeta)
208 meta.clear(); 208 meta.clear();
209 } 209 }
210 //US ENH: we need this operator to compare two items if we have no unique ids 210 //US ENH: we need this operator to compare two items if we have no unique ids
211 //available. Generaly this happens before the first sync 211 //available. Generaly this happens before the first sync
212
212 bool PwMDataItem::operator==( const PwMDataItem &a ) const 213 bool PwMDataItem::operator==( const PwMDataItem &a ) const
213 { 214 {
214 qDebug("oper==%s", a.desc.c_str()); 215 //qDebug("oper==%s", a.desc.c_str());
215 if ( desc != a.desc ) return false; 216 if ( desc != a.desc ) return false;
216 if ( name != a.name ) return false; 217 if ( name != a.name ) return false;
217 if ( pw != a.pw ) return false; 218 if ( pw != a.pw ) return false;
218 if ( comment != a.comment ) return false; 219 if ( comment != a.comment ) return false;
219 if ( url != a.url ) return false; 220 if ( url != a.url ) return false;
220 if ( launcher != a.launcher ) return false; 221 if ( launcher != a.launcher ) return false;
221 //all other field will not be checked. 222 //all other field will not be checked.
222 return true; 223 return true;
223 } 224 }
224
225 //US ENH:this operator is used to copy an elements data during syncronization
226 //Attention: listViewPos will not be copied. So the position will stay the same.
227 PwMDataItem& operator = (const PwMDataItem& x)
228 {
229 // qDebug("oper=%s", x.desc.c_str());
230 desc = x.desc;
231 name = x.name;
232 pw = x.pw;
233 comment = x.comment;
234 url = x.url;
235 launcher = x.launcher;
236 lockStat = x.lockStat;
237 //Do not copy listViewPos!!! listViewPos = x.listViewPos;
238 binary = x.binary;
239 meta = x.meta;
240 rev = x.rev;
241 return *this;
242 }
243
244}; 225};
245 226
246struct PwMCategoryItem 227struct PwMCategoryItem
247{ 228{
248 /** all PwMDataItems (all passwords) within this category */ 229 /** all PwMDataItems (all passwords) within this category */
249 vector<PwMDataItem>d; 230 vector<PwMDataItem>d;
250 /** category name/description */ 231 /** category name/description */
251 string name; 232 string name;
252 233
253 void clear() 234 void clear()
254 { 235 {
255 d.clear(); 236 d.clear();
256 name = ""; 237 name = "";
257 } 238 }
258}; 239};
259 240
260struct PwMSyncItem 241struct PwMSyncItem
261{ 242{
262 string syncName; 243 string syncName;
263 QDateTime lastSyncDate; 244 QDateTime lastSyncDate;
264 245
265 void clear() 246 void clear()
266 { 247 {
267 lastSyncDate = QDateTime(); 248 lastSyncDate = QDateTime();
268 syncName = ""; 249 syncName = "";
269 } 250 }
270}; 251};
271 252
272struct PwMItem 253struct PwMItem
273{ 254{
274 vector<PwMCategoryItem> dta; 255 vector<PwMCategoryItem> dta;
275 vector<PwMSyncItem> syncDta; 256 vector<PwMSyncItem> syncDta;
276 257
277 void clear() 258 void clear()
278 { 259 {
279 dta.clear(); 260 dta.clear();
280 syncDta.clear(); 261 syncDta.clear();
281 } 262 }
282}; 263};
283 264
284 265
285/** "Function Object" for sort()ing PwMDataItem::listViewPos */ 266/** "Function Object" for sort()ing PwMDataItem::listViewPos */
286class dta_lvp_greater 267class dta_lvp_greater
287{ 268{
288public: 269public:
289 bool operator() (const pair<unsigned int, unsigned int> &d1, 270 bool operator() (const pair<unsigned int, unsigned int> &d1,
290 const pair<unsigned int, unsigned int> &d2) 271 const pair<unsigned int, unsigned int> &d2)
291 { 272 {
292 return d1.second > d2.second; 273 return d1.second > d2.second;
293 } 274 }
294}; 275};
295 276
296/** list of PwMDoc documents and it's IDs */ 277/** list of PwMDoc documents and it's IDs */
297class PwMDocList 278class PwMDocList
298{ 279{
299public: 280public:
300 struct listItem 281 struct listItem
301 { 282 {
302 /** document filename (known as ID, here) */ 283 /** document filename (known as ID, here) */
303 string docId; 284 string docId;
304 /** pointer to the document class */ 285 /** pointer to the document class */
305 PwMDoc *doc; 286 PwMDoc *doc;
306 }; 287 };
307 288
308 PwMDocList() {} 289 PwMDocList() {}
309 290
310 /** add a new item to the list */ 291 /** add a new item to the list */
311 void add(PwMDoc *doc, const string &id); 292 void add(PwMDoc *doc, const string &id);
312 /** changes the contents of an existing item */ 293 /** changes the contents of an existing item */
313 void edit(PwMDoc *doc, const string &newId); 294 void edit(PwMDoc *doc, const string &newId);
314 /** remove the given item */ 295 /** remove the given item */
315 void del(PwMDoc *doc); 296 void del(PwMDoc *doc);
316 /** get the item at index */ 297 /** get the item at index */
317 listItem getAt(int index) 298 listItem getAt(int index)
318 { return docList[index]; } 299 { return docList[index]; }
319 /** find an entry with this id */ 300 /** find an entry with this id */
320 bool find(const string &id, listItem *ret = 0); 301 bool find(const string &id, listItem *ret = 0);
321 /** returns a copy of the list */ 302 /** returns a copy of the list */
322 const vector<listItem>* getList() const 303 const vector<listItem>* getList() const
323 { return &docList; } 304 { return &docList; }
324 305
325 306
326 /** returns a new unique number to extend the name of 307 /** returns a new unique number to extend the name of
327 * an unnamed document. 308 * an unnamed document.
328 */ 309 */
329 static unsigned int getNewUnnamedNumber() 310 static unsigned int getNewUnnamedNumber()
330 { return unnamedDocCnt++; } 311 { return unnamedDocCnt++; }
331 312
332protected: 313protected:
333 /* Hm, I think we shouldn't really use a "list" here, should we? 314 /* Hm, I think we shouldn't really use a "list" here, should we?
334 * So I decided to actually use a vector. 315 * So I decided to actually use a vector.
335 */ 316 */
336 vector<listItem> docList; 317 vector<listItem> docList;
337 /** This value is used to get a new number for yet unnamed 318 /** This value is used to get a new number for yet unnamed
338 * documents. It is incremented on every request. So it's 319 * documents. It is incremented on every request. So it's
339 * theoretically possible to overflow it, but... :) 320 * theoretically possible to overflow it, but... :)
340 */ 321 */
341 static unsigned int unnamedDocCnt; 322 static unsigned int unnamedDocCnt;
342}; 323};
343 324
344/** implements timers for the document */ 325/** implements timers for the document */
345class DocTimer : public QObject 326class DocTimer : public QObject
346{ 327{
347 Q_OBJECT 328 Q_OBJECT
348public: 329public:
349 enum TimerIDs 330 enum TimerIDs
350 { 331 {
351 id_mpwTimer, 332 id_mpwTimer,
352 id_autoLockTimer, 333 id_autoLockTimer,
353 id_metaCheckTimer 334 id_metaCheckTimer
354 }; 335 };
355 336
356public: 337public:
357 DocTimer(PwMDoc *_doc); 338 DocTimer(PwMDoc *_doc);
358 ~DocTimer(); 339 ~DocTimer();
359 340
360 /** start the timer */ 341 /** start the timer */
361 void start(TimerIDs timer); 342 void start(TimerIDs timer);
362 /** stop the timer */ 343 /** stop the timer */
363 void stop(TimerIDs timer); 344 void stop(TimerIDs timer);
364 /** get the lock for a timer. 345 /** get the lock for a timer.
365 * This lock is a recursive lock. When a lock is 346 * This lock is a recursive lock. When a lock is
366 * held, the timer will be stopped and timeout is 347 * held, the timer will be stopped and timeout is
367 * guaranteed to not happen 348 * guaranteed to not happen
368 */ 349 */
369 void getLock(TimerIDs timer); 350 void getLock(TimerIDs timer);
370 /** put a recursive timer lock */ 351 /** put a recursive timer lock */
371 void putLock(TimerIDs timer); 352 void putLock(TimerIDs timer);
372 353
373protected slots: 354protected slots:
374 /** timeout slot for the mpw timer */ 355 /** timeout slot for the mpw timer */
375 void mpwTimeout(); 356 void mpwTimeout();
376 /** timeout slot for the autoLock timer */ 357 /** timeout slot for the autoLock timer */
377 void autoLockTimeout(); 358 void autoLockTimeout();
378 /** timeout slot for the metaCheck timer */ 359 /** timeout slot for the metaCheck timer */
379 void metaCheckTimeout(); 360 void metaCheckTimeout();
380 361
381protected: 362protected:
382 /** pointer to the document associated with this timer. */ 363 /** pointer to the document associated with this timer. */
383 PwMDoc *doc; 364 PwMDoc *doc;
384 /** timer object for mpw timer */ 365 /** timer object for mpw timer */
385 QTimer *mpwTimer; 366 QTimer *mpwTimer;
386 /** timer object for the autoLock timer */ 367 /** timer object for the autoLock timer */
387 QTimer *autoLockTimer; 368 QTimer *autoLockTimer;
388 /** timer object for the metaCheck timer */ 369 /** timer object for the metaCheck timer */
389 QTimer *metaCheckTimer; 370 QTimer *metaCheckTimer;
390 /** lock counter for the mpw timer */ 371 /** lock counter for the mpw timer */
391 unsigned int mpwLock; 372 unsigned int mpwLock;
392 /** lock counter for the autoLock timer */ 373 /** lock counter for the autoLock timer */
393 unsigned int autoLockLock; 374 unsigned int autoLockLock;
394 /** lock counter for the metaCheck timer */ 375 /** lock counter for the metaCheck timer */
395 unsigned int metaCheckLock; 376 unsigned int metaCheckLock;
396}; 377};
397 378
398/** Document class for PwM */ 379/** Document class for PwM */
399//US ENH: derived from KSyncInterfaces, to get called by PwM when a sync is required. 380//US ENH: derived from KSyncInterfaces, to get called by PwM when a sync is required.
400// But PwMDoc is handling the sync by itself. 381// But PwMDoc is handling the sync by itself.
401class PwMDoc : public PwMDocUi, public KSyncInterface 382class PwMDoc : public PwMDocUi, public KSyncInterface
402 383
403{ 384{
404 Q_OBJECT 385 Q_OBJECT
405 friend class DocTimer; 386 friend class DocTimer;
406 387
407public: 388public:
408 /** construtor */ 389 /** construtor */
409 PwMDoc(QObject* parent = 0, const char *name = 0); 390 PwMDoc(QObject* parent = 0, const char *name = 0);
410 /** destructor */ 391 /** destructor */
411 ~PwMDoc(); 392 ~PwMDoc();
412 393
413 /** returns a pointer to a list of all open documents */ 394 /** returns a pointer to a list of all open documents */
414 static PwMDocList* getOpenDocList() 395 static PwMDocList* getOpenDocList()
415 { return &openDocList; } 396 { return &openDocList; }
416 397
417 /** flag document dirty. dta changed */ 398 /** flag document dirty. dta changed */
418 void flagDirty() 399 void flagDirty()
419 { 400 {
420 setDocStatFlag(DOC_STAT_DISK_DIRTY); 401 setDocStatFlag(DOC_STAT_DISK_DIRTY);
421 emitDataChanged(this); 402 emitDataChanged(this);
422 } 403 }
423 /** modified? */ 404 /** modified? */
424 bool isDirty() 405 bool isDirty()
425 { return getDocStatFlag(DOC_STAT_DISK_DIRTY); } 406 { return getDocStatFlag(DOC_STAT_DISK_DIRTY); }
426 /** save document to disk */ 407 /** save document to disk */
427 PwMerror saveDoc(char compress, const QString *file = 0); 408 PwMerror saveDoc(char compress, const QString *file = 0);
428 /** read document from file. 409 /** read document from file.
429 * "openLocked is must be set to either of these values: 410 * "openLocked is must be set to either of these values:
430 * 0 == open with all entries unlocked 411 * 0 == open with all entries unlocked
431 * 1 == open with all entries locked 412 * 1 == open with all entries locked
432 * 2 == open deep-locked 413 * 2 == open deep-locked
433 */ 414 */
434 PwMerror openDoc(const QString *file, int openLocked); 415 PwMerror openDoc(const QString *file, int openLocked);
435 /** export document to ascii-textfile */ 416 /** export document to ascii-textfile */
436 PwMerror exportToText(const QString *file); 417 PwMerror exportToText(const QString *file);
437 /** export document to gpasman / kpasman file */ 418 /** export document to gpasman / kpasman file */
438 PwMerror exportToGpasman(const QString *file); 419 PwMerror exportToGpasman(const QString *file);
439 /** import document from ascii-textfile */ 420 /** import document from ascii-textfile */
440 PwMerror importFromText(const QString *file, int format = -1); 421 PwMerror importFromText(const QString *file, int format = -1);
441 /** import document from gpasman / kpasman file */ 422 /** import document from gpasman / kpasman file */
442 PwMerror importFromGpasman(const QString *file); 423 PwMerror importFromGpasman(const QString *file);
443 /** add new entry */ 424 /** add new entry */
444 PwMerror addEntry(const QString &category, PwMDataItem *d, 425 PwMerror addEntry(const QString &category, PwMDataItem *d,
445 bool dontFlagDirty = false, bool updateMeta = true); 426 bool dontFlagDirty = false, bool updateMeta = true);
446 /** add new category. This function doesn't flag the document dirty! */ 427 /** add new category. This function doesn't flag the document dirty! */
447 PwMerror addCategory(const QString &category, unsigned int *categoryIndex, 428 PwMerror addCategory(const QString &category, unsigned int *categoryIndex,
448 bool checkIfExist = true); 429 bool checkIfExist = true);
449 /** rename an existing category */ 430 /** rename an existing category */
450 bool renameCategory(const QString &category, const QString &newName); 431 bool renameCategory(const QString &category, const QString &newName);
451 /** rename an existing category */ 432 /** rename an existing category */
452 bool renameCategory(unsigned int category, const QString &newName, 433 bool renameCategory(unsigned int category, const QString &newName,
453 bool dontFlagDirty = false); 434 bool dontFlagDirty = false);
454 /** delete an existing category */ 435 /** delete an existing category */
455 bool delCategory(const QString &category); 436 bool delCategory(const QString &category);
456 /** delete an existing category */ 437 /** delete an existing category */
457 bool delCategory(unsigned int category, bool dontFlagDirty = false); 438 bool delCategory(unsigned int category, bool dontFlagDirty = false);
458 /** returns a list of all category-names */ 439 /** returns a list of all category-names */
459 void getCategoryList(vector<string> *list); 440 void getCategoryList(vector<string> *list);
460 /** returns a list of all category-names */ 441 /** returns a list of all category-names */
461 void getCategoryList(QStringList *list); 442 void getCategoryList(QStringList *list);
462 /** returns a list of all entry-descs in the given category */ 443 /** returns a list of all entry-descs in the given category */
463 void getEntryList(const QString &category, QStringList *list); 444 void getEntryList(const QString &category, QStringList *list);
464 /** returns a list of all entry-descs in the given category */ 445 /** returns a list of all entry-descs in the given category */
465 void getEntryList(const QString &category, vector<string> *list); 446 void getEntryList(const QString &category, vector<string> *list);
466 /** returns a list of all entry-descs in the given category */ 447 /** returns a list of all entry-descs in the given category */
467 void getEntryList(unsigned int category, vector<string> *list); 448 void getEntryList(unsigned int category, vector<string> *list);
468 /** returns a list of all entry-descs in the given category */ 449 /** returns a list of all entry-descs in the given category */
469 void getEntryList(unsigned int category, QStringList *list); 450 void getEntryList(unsigned int category, QStringList *list);
470 /** delete entry */ 451 /** delete entry */
471 bool delEntry(const QString &category, unsigned int index, bool dontFlagDirty = false); 452 bool delEntry(const QString &category, unsigned int index, bool dontFlagDirty = false);
472 /** delete entry */ 453 /** delete entry */
473 bool delEntry(unsigned int category, unsigned int index, bool dontFlagDirty = false); 454 bool delEntry(unsigned int category, unsigned int index, bool dontFlagDirty = false);
474 /** edit entry */ 455 /** edit entry */
475 bool editEntry(const QString &oldCategory, const QString &newCategory, 456 bool editEntry(const QString &oldCategory, const QString &newCategory,
476 unsigned int index, PwMDataItem *d, bool updateMeta = true); 457 unsigned int index, PwMDataItem *d, bool updateMeta = true);
477 /** edit entry */ 458 /** edit entry */
478 bool editEntry(unsigned int oldCategory, const QString &newCategory, 459 bool editEntry(unsigned int oldCategory, const QString &newCategory,
479 unsigned int index, PwMDataItem *d, bool updateMeta = true); 460 unsigned int index, PwMDataItem *d, bool updateMeta = true);
480 /** finds the category with the "name" and return it's index */ 461 /** finds the category with the "name" and return it's index */
481 bool findCategory(const QString &name, unsigned int *index); 462 bool findCategory(const QString &name, unsigned int *index);
482 /** search for an entry "find" and check while searching only for 463 /** search for an entry "find" and check while searching only for
483 * the data-fields specified by "searchIn". To set the "searchIn" 464 * the data-fields specified by "searchIn". To set the "searchIn"
484 * value, we may use one or more of the SEARCH_IN_* defines at 465 * value, we may use one or more of the SEARCH_IN_* defines at
485 * the top of this header-file. It returns the positions of all 466 * the top of this header-file. It returns the positions of all
486 * matched entries in "foundPositions". If "breakAfterFound" is true, 467 * matched entries in "foundPositions". If "breakAfterFound" is true,
487 * the function terminates after the first occurence of the entry 468 * the function terminates after the first occurence of the entry
488 * and doesn't go on searching. So foundPositions->size() is never 469 * and doesn't go on searching. So foundPositions->size() is never
489 * > 1 if breakAfterFound is true. 470 * > 1 if breakAfterFound is true.
490 */ 471 */
491 void findEntry(unsigned int category, PwMDataItem find, unsigned int searchIn, 472 void findEntry(unsigned int category, PwMDataItem find, unsigned int searchIn,
492 vector<unsigned int> *foundPositions, bool breakAfterFound = false, 473 vector<unsigned int> *foundPositions, bool breakAfterFound = false,
493 bool caseSensitive = true, bool exactWordMatch = true, 474 bool caseSensitive = true, bool exactWordMatch = true,
494 bool sortByLvp = false); 475 bool sortByLvp = false);
495 /** see the above funtion. This function allows to set the category by name. */ 476 /** see the above funtion. This function allows to set the category by name. */
496 void findEntry(const QString &category, PwMDataItem find, unsigned int searchIn, 477 void findEntry(const QString &category, PwMDataItem find, unsigned int searchIn,
497 vector<unsigned int> *foundPositions, bool breakAfterFound = false, 478 vector<unsigned int> *foundPositions, bool breakAfterFound = false,
498 bool caseSensitive = true, bool exactWordMatch = true, 479 bool caseSensitive = true, bool exactWordMatch = true,
499 bool sortByLvp = false); 480 bool sortByLvp = false);