-rw-r--r-- | pwmanager/pwmanager/pwmdoc.cpp | 10 | ||||
-rw-r--r-- | pwmanager/pwmanager/pwmdoc.h | 20 |
2 files changed, 24 insertions, 6 deletions
diff --git a/pwmanager/pwmanager/pwmdoc.cpp b/pwmanager/pwmanager/pwmdoc.cpp index fd17ce5..9043acc 100644 --- a/pwmanager/pwmanager/pwmdoc.cpp +++ b/pwmanager/pwmanager/pwmdoc.cpp | |||
@@ -2639,863 +2639,861 @@ PwMerror PwMDoc::importText_PwM(const QString *file) | |||
2639 | 2639 | ||
2640 | // decrement filepos by one | 2640 | // decrement filepos by one |
2641 | f.at(f.at()-1); | 2641 | f.at(f.at()-1); |
2642 | // read cat-name | 2642 | // read cat-name |
2643 | if (f.readLine(ch_tmp, ch_tmp_size) == -1) | 2643 | if (f.readLine(ch_tmp, ch_tmp_size) == -1) |
2644 | goto formatError; | 2644 | goto formatError; |
2645 | // check cat-name format | 2645 | // check cat-name format |
2646 | if (memcmp(ch_tmp, "== Category: ", 13) != 0) | 2646 | if (memcmp(ch_tmp, "== Category: ", 13) != 0) |
2647 | goto formatError; | 2647 | goto formatError; |
2648 | if (memcmp(ch_tmp + (strlen(ch_tmp) - 1 - 3), " ==", 3) != 0) | 2648 | if (memcmp(ch_tmp + (strlen(ch_tmp) - 1 - 3), " ==", 3) != 0) |
2649 | goto formatError; | 2649 | goto formatError; |
2650 | // copy cat-name | 2650 | // copy cat-name |
2651 | curCat.assign(ch_tmp + 13, strlen(ch_tmp) - 1 - 16); | 2651 | curCat.assign(ch_tmp + 13, strlen(ch_tmp) - 1 - 16); |
2652 | 2652 | ||
2653 | do { | 2653 | do { |
2654 | // find beginning of next entry | 2654 | // find beginning of next entry |
2655 | do { | 2655 | do { |
2656 | tmp = f.getch(); | 2656 | tmp = f.getch(); |
2657 | } while (tmp == '\n' && tmp != EOF && tmp != '='); | 2657 | } while (tmp == '\n' && tmp != EOF && tmp != '='); |
2658 | if (tmp == EOF) | 2658 | if (tmp == EOF) |
2659 | break; | 2659 | break; |
2660 | if (tmp == '=') { | 2660 | if (tmp == '=') { |
2661 | f.at(f.at()-1); | 2661 | f.at(f.at()-1); |
2662 | break; | 2662 | break; |
2663 | } | 2663 | } |
2664 | // decrement filepos by one | 2664 | // decrement filepos by one |
2665 | f.at(f.at()-1); | 2665 | f.at(f.at()-1); |
2666 | // read desc-line | 2666 | // read desc-line |
2667 | if (f.readLine(ch_tmp, ch_tmp_size) == -1) | 2667 | if (f.readLine(ch_tmp, ch_tmp_size) == -1) |
2668 | goto formatError; | 2668 | goto formatError; |
2669 | // check desc-line format | 2669 | // check desc-line format |
2670 | if (memcmp(ch_tmp, "-- ", 3) != 0) | 2670 | if (memcmp(ch_tmp, "-- ", 3) != 0) |
2671 | goto formatError; | 2671 | goto formatError; |
2672 | if (memcmp(ch_tmp + (strlen(ch_tmp) - 1 - 3), " --", 3) != 0) | 2672 | if (memcmp(ch_tmp + (strlen(ch_tmp) - 1 - 3), " --", 3) != 0) |
2673 | goto formatError; | 2673 | goto formatError; |
2674 | // add desc-line | 2674 | // add desc-line |
2675 | currItem.desc.assign(ch_tmp + 3, strlen(ch_tmp) - 1 - 6); | 2675 | currItem.desc.assign(ch_tmp + 3, strlen(ch_tmp) - 1 - 6); |
2676 | 2676 | ||
2677 | // read username-line | 2677 | // read username-line |
2678 | if ((ret = f.readLine(ch_tmp, ch_tmp_size)) == -1) | 2678 | if ((ret = f.readLine(ch_tmp, ch_tmp_size)) == -1) |
2679 | goto formatError; | 2679 | goto formatError; |
2680 | if (!textExtractEntry_PwM(ch_tmp, ret, &currItem.name)) | 2680 | if (!textExtractEntry_PwM(ch_tmp, ret, &currItem.name)) |
2681 | goto formatError; | 2681 | goto formatError; |
2682 | 2682 | ||
2683 | // read pw-line | 2683 | // read pw-line |
2684 | if ((ret = f.readLine(ch_tmp, ch_tmp_size)) == -1) | 2684 | if ((ret = f.readLine(ch_tmp, ch_tmp_size)) == -1) |
2685 | goto formatError; | 2685 | goto formatError; |
2686 | if (!textExtractEntry_PwM(ch_tmp, ret, &currItem.pw)) | 2686 | if (!textExtractEntry_PwM(ch_tmp, ret, &currItem.pw)) |
2687 | goto formatError; | 2687 | goto formatError; |
2688 | 2688 | ||
2689 | // read comment-line | 2689 | // read comment-line |
2690 | if ((ret = f.readLine(ch_tmp, ch_tmp_size)) == -1) | 2690 | if ((ret = f.readLine(ch_tmp, ch_tmp_size)) == -1) |
2691 | goto formatError; | 2691 | goto formatError; |
2692 | if (!textExtractEntry_PwM(ch_tmp, ret, &currItem.comment)) | 2692 | if (!textExtractEntry_PwM(ch_tmp, ret, &currItem.comment)) |
2693 | goto formatError; | 2693 | goto formatError; |
2694 | 2694 | ||
2695 | // read URL-line | 2695 | // read URL-line |
2696 | if ((ret = f.readLine(ch_tmp, ch_tmp_size)) == -1) | 2696 | if ((ret = f.readLine(ch_tmp, ch_tmp_size)) == -1) |
2697 | goto formatError; | 2697 | goto formatError; |
2698 | if (!textExtractEntry_PwM(ch_tmp, ret, &currItem.url)) | 2698 | if (!textExtractEntry_PwM(ch_tmp, ret, &currItem.url)) |
2699 | goto formatError; | 2699 | goto formatError; |
2700 | 2700 | ||
2701 | // read launcher-line | 2701 | // read launcher-line |
2702 | if ((ret = f.readLine(ch_tmp, ch_tmp_size)) == -1) | 2702 | if ((ret = f.readLine(ch_tmp, ch_tmp_size)) == -1) |
2703 | goto formatError; | 2703 | goto formatError; |
2704 | if (!textExtractEntry_PwM(ch_tmp, ret, &currItem.launcher)) | 2704 | if (!textExtractEntry_PwM(ch_tmp, ret, &currItem.launcher)) |
2705 | goto formatError; | 2705 | goto formatError; |
2706 | 2706 | ||
2707 | currItem.lockStat = true; | 2707 | currItem.lockStat = true; |
2708 | currItem.listViewPos = -1; | 2708 | currItem.listViewPos = -1; |
2709 | addEntry(curCat.c_str(), &currItem, true); | 2709 | addEntry(curCat.c_str(), &currItem, true); |
2710 | ++entriesRead; | 2710 | ++entriesRead; |
2711 | } while (1); | 2711 | } while (1); |
2712 | } while (1); | 2712 | } while (1); |
2713 | if (!entriesRead) | 2713 | if (!entriesRead) |
2714 | goto formatError; | 2714 | goto formatError; |
2715 | 2715 | ||
2716 | free(ch_tmp); | 2716 | free(ch_tmp); |
2717 | f.close(); | 2717 | f.close(); |
2718 | flagDirty(); | 2718 | flagDirty(); |
2719 | return e_success; | 2719 | return e_success; |
2720 | 2720 | ||
2721 | formatError: | 2721 | formatError: |
2722 | free(ch_tmp); | 2722 | free(ch_tmp); |
2723 | f.close(); | 2723 | f.close(); |
2724 | return e_fileFormat; | 2724 | return e_fileFormat; |
2725 | 2725 | ||
2726 | #endif | 2726 | #endif |
2727 | 2727 | ||
2728 | } | 2728 | } |
2729 | 2729 | ||
2730 | bool PwMDoc::textExtractEntry_PwM(const char *in, ssize_t in_size, string *out) | 2730 | bool PwMDoc::textExtractEntry_PwM(const char *in, ssize_t in_size, string *out) |
2731 | { | 2731 | { |
2732 | PWM_ASSERT(in && out); | 2732 | PWM_ASSERT(in && out); |
2733 | ssize_t i = 0, len = in_size - 1; | 2733 | ssize_t i = 0, len = in_size - 1; |
2734 | while (i < len) { | 2734 | while (i < len) { |
2735 | if (in[i] == ':') | 2735 | if (in[i] == ':') |
2736 | break; | 2736 | break; |
2737 | ++i; | 2737 | ++i; |
2738 | } | 2738 | } |
2739 | i += 2; | 2739 | i += 2; |
2740 | *out = ""; | 2740 | *out = ""; |
2741 | out->append(in + i, in_size - i - 1); | 2741 | out->append(in + i, in_size - i - 1); |
2742 | return true; | 2742 | return true; |
2743 | } | 2743 | } |
2744 | 2744 | ||
2745 | PwMerror PwMDoc::exportToGpasman(const QString *file) | 2745 | PwMerror PwMDoc::exportToGpasman(const QString *file) |
2746 | { | 2746 | { |
2747 | PWM_ASSERT(file); | 2747 | PWM_ASSERT(file); |
2748 | GpasmanFile gp; | 2748 | GpasmanFile gp; |
2749 | int ret; | 2749 | int ret; |
2750 | 2750 | ||
2751 | if (!unlockAll_tempoary()) | 2751 | if (!unlockAll_tempoary()) |
2752 | return e_lock; | 2752 | return e_lock; |
2753 | 2753 | ||
2754 | QString gpmPassword; | 2754 | QString gpmPassword; |
2755 | while (1) { | 2755 | while (1) { |
2756 | gpmPassword = requestNewMpw(0); | 2756 | gpmPassword = requestNewMpw(0); |
2757 | if (gpmPassword == "") { | 2757 | if (gpmPassword == "") { |
2758 | unlockAll_tempoary(true); | 2758 | unlockAll_tempoary(true); |
2759 | return e_noPw; | 2759 | return e_noPw; |
2760 | } | 2760 | } |
2761 | if (gpmPassword.length() < 4) { | 2761 | if (gpmPassword.length() < 4) { |
2762 | gpmPwLenErrMsgBox(); | 2762 | gpmPwLenErrMsgBox(); |
2763 | } else { | 2763 | } else { |
2764 | break; | 2764 | break; |
2765 | } | 2765 | } |
2766 | } | 2766 | } |
2767 | 2767 | ||
2768 | ret = gp.save_init(file->latin1(), gpmPassword.latin1()); | 2768 | ret = gp.save_init(file->latin1(), gpmPassword.latin1()); |
2769 | if (ret != 1) { | 2769 | if (ret != 1) { |
2770 | unlockAll_tempoary(true); | 2770 | unlockAll_tempoary(true); |
2771 | return e_accessFile; | 2771 | return e_accessFile; |
2772 | } | 2772 | } |
2773 | 2773 | ||
2774 | char *entry[4]; | 2774 | char *entry[4]; |
2775 | unsigned int numCat = numCategories(), i; | 2775 | unsigned int numCat = numCategories(), i; |
2776 | unsigned int numEntr, j; | 2776 | unsigned int numEntr, j; |
2777 | int descLen, nameLen, pwLen, commentLen; | 2777 | int descLen, nameLen, pwLen, commentLen; |
2778 | for (i = 0; i < numCat; ++i) { | 2778 | for (i = 0; i < numCat; ++i) { |
2779 | numEntr = numEntries(i); | 2779 | numEntr = numEntries(i); |
2780 | for (j = 0; j < numEntr; ++j) { | 2780 | for (j = 0; j < numEntr; ++j) { |
2781 | descLen = dti.dta[i].d[j].desc.length(); | 2781 | descLen = dti.dta[i].d[j].desc.length(); |
2782 | nameLen = dti.dta[i].d[j].name.length(); | 2782 | nameLen = dti.dta[i].d[j].name.length(); |
2783 | pwLen = dti.dta[i].d[j].pw.length(); | 2783 | pwLen = dti.dta[i].d[j].pw.length(); |
2784 | commentLen = dti.dta[i].d[j].comment.length(); | 2784 | commentLen = dti.dta[i].d[j].comment.length(); |
2785 | entry[0] = new char[descLen + 1]; | 2785 | entry[0] = new char[descLen + 1]; |
2786 | entry[1] = new char[nameLen + 1]; | 2786 | entry[1] = new char[nameLen + 1]; |
2787 | entry[2] = new char[pwLen + 1]; | 2787 | entry[2] = new char[pwLen + 1]; |
2788 | entry[3] = new char[commentLen + 1]; | 2788 | entry[3] = new char[commentLen + 1]; |
2789 | strcpy(entry[0], descLen == 0 ? " " : dti.dta[i].d[j].desc.c_str()); | 2789 | strcpy(entry[0], descLen == 0 ? " " : dti.dta[i].d[j].desc.c_str()); |
2790 | strcpy(entry[1], nameLen == 0 ? " " : dti.dta[i].d[j].name.c_str()); | 2790 | strcpy(entry[1], nameLen == 0 ? " " : dti.dta[i].d[j].name.c_str()); |
2791 | strcpy(entry[2], pwLen == 0 ? " " : dti.dta[i].d[j].pw.c_str()); | 2791 | strcpy(entry[2], pwLen == 0 ? " " : dti.dta[i].d[j].pw.c_str()); |
2792 | strcpy(entry[3], commentLen == 0 ? " " : dti.dta[i].d[j].comment.c_str()); | 2792 | strcpy(entry[3], commentLen == 0 ? " " : dti.dta[i].d[j].comment.c_str()); |
2793 | entry[0][descLen == 0 ? descLen + 1 : descLen] = '\0'; | 2793 | entry[0][descLen == 0 ? descLen + 1 : descLen] = '\0'; |
2794 | entry[1][nameLen == 0 ? nameLen + 1 : nameLen] = '\0'; | 2794 | entry[1][nameLen == 0 ? nameLen + 1 : nameLen] = '\0'; |
2795 | entry[2][pwLen == 0 ? pwLen + 1 : pwLen] = '\0'; | 2795 | entry[2][pwLen == 0 ? pwLen + 1 : pwLen] = '\0'; |
2796 | entry[3][commentLen == 0 ? commentLen + 1 : commentLen] = '\0'; | 2796 | entry[3][commentLen == 0 ? commentLen + 1 : commentLen] = '\0'; |
2797 | 2797 | ||
2798 | ret = gp.save_entry(entry); | 2798 | ret = gp.save_entry(entry); |
2799 | if (ret == -1){ | 2799 | if (ret == -1){ |
2800 | delete [] entry[0]; | 2800 | delete [] entry[0]; |
2801 | delete [] entry[1]; | 2801 | delete [] entry[1]; |
2802 | delete [] entry[2]; | 2802 | delete [] entry[2]; |
2803 | delete [] entry[3]; | 2803 | delete [] entry[3]; |
2804 | gp.save_finalize(); | 2804 | gp.save_finalize(); |
2805 | unlockAll_tempoary(true); | 2805 | unlockAll_tempoary(true); |
2806 | return e_writeFile; | 2806 | return e_writeFile; |
2807 | } | 2807 | } |
2808 | 2808 | ||
2809 | delete [] entry[0]; | 2809 | delete [] entry[0]; |
2810 | delete [] entry[1]; | 2810 | delete [] entry[1]; |
2811 | delete [] entry[2]; | 2811 | delete [] entry[2]; |
2812 | delete [] entry[3]; | 2812 | delete [] entry[3]; |
2813 | } | 2813 | } |
2814 | } | 2814 | } |
2815 | unlockAll_tempoary(true); | 2815 | unlockAll_tempoary(true); |
2816 | if (gp.save_finalize() == -1) | 2816 | if (gp.save_finalize() == -1) |
2817 | return e_writeFile; | 2817 | return e_writeFile; |
2818 | 2818 | ||
2819 | return e_success; | 2819 | return e_success; |
2820 | } | 2820 | } |
2821 | 2821 | ||
2822 | PwMerror PwMDoc::importFromGpasman(const QString *file) | 2822 | PwMerror PwMDoc::importFromGpasman(const QString *file) |
2823 | { | 2823 | { |
2824 | PWM_ASSERT(file); | 2824 | PWM_ASSERT(file); |
2825 | QString pw = requestMpw(false); | 2825 | QString pw = requestMpw(false); |
2826 | if (pw == "") | 2826 | if (pw == "") |
2827 | return e_noPw; | 2827 | return e_noPw; |
2828 | GpasmanFile gp; | 2828 | GpasmanFile gp; |
2829 | int ret, i; | 2829 | int ret, i; |
2830 | PwMerror ret2; | 2830 | PwMerror ret2; |
2831 | char *entry[4]; | 2831 | char *entry[4]; |
2832 | PwMDataItem tmpData; | 2832 | PwMDataItem tmpData; |
2833 | ret = gp.load_init(file->latin1(), pw.latin1()); | 2833 | ret = gp.load_init(file->latin1(), pw.latin1()); |
2834 | if (ret != 1) | 2834 | if (ret != 1) |
2835 | return e_accessFile; | 2835 | return e_accessFile; |
2836 | 2836 | ||
2837 | do { | 2837 | do { |
2838 | ret = gp.load_entry(entry); | 2838 | ret = gp.load_entry(entry); |
2839 | if(ret != 1) | 2839 | if(ret != 1) |
2840 | break; | 2840 | break; |
2841 | tmpData.desc = entry[0]; | 2841 | tmpData.desc = entry[0]; |
2842 | tmpData.name = entry[1]; | 2842 | tmpData.name = entry[1]; |
2843 | tmpData.pw = entry[2]; | 2843 | tmpData.pw = entry[2]; |
2844 | tmpData.comment = entry[3]; | 2844 | tmpData.comment = entry[3]; |
2845 | tmpData.lockStat = true; | 2845 | tmpData.lockStat = true; |
2846 | tmpData.listViewPos = -1; | 2846 | tmpData.listViewPos = -1; |
2847 | ret2 = addEntry(DEFAULT_CATEGORY, &tmpData, true); | 2847 | ret2 = addEntry(DEFAULT_CATEGORY, &tmpData, true); |
2848 | for (i = 0; i < 4; ++i) | 2848 | for (i = 0; i < 4; ++i) |
2849 | free(entry[i]); | 2849 | free(entry[i]); |
2850 | if (ret2 == e_maxAllowedEntr) { | 2850 | if (ret2 == e_maxAllowedEntr) { |
2851 | gp.load_finalize(); | 2851 | gp.load_finalize(); |
2852 | return e_maxAllowedEntr; | 2852 | return e_maxAllowedEntr; |
2853 | } | 2853 | } |
2854 | } while (1); | 2854 | } while (1); |
2855 | gp.load_finalize(); | 2855 | gp.load_finalize(); |
2856 | if (isDocEmpty()) | 2856 | if (isDocEmpty()) |
2857 | return e_wrongPw; // we assume this. | 2857 | return e_wrongPw; // we assume this. |
2858 | 2858 | ||
2859 | flagDirty(); | 2859 | flagDirty(); |
2860 | return e_success; | 2860 | return e_success; |
2861 | } | 2861 | } |
2862 | 2862 | ||
2863 | 2863 | ||
2864 | //US: we use the stl sort algorythm to sort all elements in the order | 2864 | //US: we use the stl sort algorythm to sort all elements in the order |
2865 | //of its listViewPos (in the order 1,2,3,5,...,x,-1, -1, -1 | 2865 | //of its listViewPos (in the order 1,2,3,5,...,x,-1, -1, -1 |
2866 | struct PwMDataItemListViewPosSort | 2866 | struct PwMDataItemListViewPosSort |
2867 | { | 2867 | { |
2868 | bool operator()(PwMDataItem* rpStart, PwMDataItem* rpEnd) | 2868 | bool operator()(PwMDataItem* rpStart, PwMDataItem* rpEnd) |
2869 | { | 2869 | { |
2870 | //qDebug("pwMDoc::PwMDataItemListViewPosSort()"); | 2870 | //qDebug("pwMDoc::PwMDataItemListViewPosSort()"); |
2871 | if ((rpEnd)->listViewPos < 0) | 2871 | if ((rpEnd)->listViewPos < 0) |
2872 | return false; | 2872 | return false; |
2873 | else | 2873 | else |
2874 | return (rpStart)->listViewPos < (rpEnd)->listViewPos; | 2874 | return (rpStart)->listViewPos < (rpEnd)->listViewPos; |
2875 | } | 2875 | } |
2876 | }; | 2876 | }; |
2877 | 2877 | ||
2878 | void PwMDoc::ensureLvp() | 2878 | void PwMDoc::ensureLvp() |
2879 | { | 2879 | { |
2880 | if (isDocEmpty()) | 2880 | if (isDocEmpty()) |
2881 | return; | 2881 | return; |
2882 | 2882 | ||
2883 | //US ENH BUG: when using syncronizing, this way of sorting | 2883 | //US ENH BUG: when using syncronizing, this way of sorting |
2884 | //is not sufficient, because there might be empty spaces | 2884 | //is not sufficient, because there might be empty spaces |
2885 | // at the beginning. But the old algorythm only can add elements | 2885 | // at the beginning. But the old algorythm only can add elements |
2886 | //to the end.The result are crashes because of list overflows | 2886 | //to the end.The result are crashes because of list overflows |
2887 | //we need something to fill all gaps. | 2887 | //we need something to fill all gaps. |
2888 | vector<PwMDataItem*> sorted; | 2888 | vector<PwMDataItem*> sorted; |
2889 | vector< PwMDataItem*>::iterator sortedBegin, | 2889 | vector< PwMDataItem*>::iterator sortedBegin, |
2890 | sortedEnd, | 2890 | sortedEnd, |
2891 | sortedI; | 2891 | sortedI; |
2892 | vector<PwMCategoryItem>::iterator catBegin = dti.dta.begin(), | 2892 | vector<PwMCategoryItem>::iterator catBegin = dti.dta.begin(), |
2893 | catEnd = dti.dta.end(), | 2893 | catEnd = dti.dta.end(), |
2894 | catI = catBegin; | 2894 | catI = catBegin; |
2895 | vector<PwMDataItem>::iterator entrBegin, entrEnd, entrI; | 2895 | vector<PwMDataItem>::iterator entrBegin, entrEnd, entrI; |
2896 | int lvpTop, tmpLvp; | 2896 | int lvpTop, tmpLvp; |
2897 | 2897 | ||
2898 | //qDebug("collect:"); | 2898 | //qDebug("collect:"); |
2899 | 2899 | ||
2900 | while (catI != catEnd) { | 2900 | while (catI != catEnd) { |
2901 | lvpTop = -1; | 2901 | lvpTop = -1; |
2902 | sorted.clear(); | 2902 | sorted.clear(); |
2903 | 2903 | ||
2904 | entrBegin = catI->d.begin(); | 2904 | entrBegin = catI->d.begin(); |
2905 | entrEnd = catI->d.end(); | 2905 | entrEnd = catI->d.end(); |
2906 | entrI = entrBegin; | 2906 | entrI = entrBegin; |
2907 | 2907 | ||
2908 | //US: we use the stl sort algorythm to sort all elements in the order | 2908 | //US: we use the stl sort algorythm to sort all elements in the order |
2909 | //of its listViewPos (in the order 1,2,2,3,5,...,x,-1, -1, -1 | 2909 | //of its listViewPos (in the order 1,2,2,3,5,...,x,-1, -1, -1 |
2910 | while (entrI != entrEnd) { | 2910 | while (entrI != entrEnd) { |
2911 | //qDebug("found: %s, pos=%i", (*entrI).desc.c_str(), (*entrI).listViewPos); | 2911 | //qDebug("found: %s, pos=%i", (*entrI).desc.c_str(), (*entrI).listViewPos); |
2912 | sorted.push_back((PwMDataItem*)&(*entrI)); | 2912 | sorted.push_back((PwMDataItem*)&(*entrI)); |
2913 | ++entrI; | 2913 | ++entrI; |
2914 | } | 2914 | } |
2915 | 2915 | ||
2916 | sortedBegin = sorted.begin(); | 2916 | sortedBegin = sorted.begin(); |
2917 | sortedEnd = sorted.end(); | 2917 | sortedEnd = sorted.end(); |
2918 | 2918 | ||
2919 | sort(sortedBegin, sortedEnd, PwMDataItemListViewPosSort()); | 2919 | sort(sortedBegin, sortedEnd, PwMDataItemListViewPosSort()); |
2920 | 2920 | ||
2921 | // qDebug("resort:"); | 2921 | // qDebug("resort:"); |
2922 | //now we have all sorted in a collection | 2922 | //now we have all sorted in a collection |
2923 | //Now start with the sorted and reset listviewpos. | 2923 | //Now start with the sorted and reset listviewpos. |
2924 | sortedBegin = sorted.begin(); | 2924 | sortedBegin = sorted.begin(); |
2925 | sortedEnd = sorted.end(); | 2925 | sortedEnd = sorted.end(); |
2926 | sortedI = sortedBegin; | 2926 | sortedI = sortedBegin; |
2927 | 2927 | ||
2928 | while (sortedI != sortedEnd) { | 2928 | while (sortedI != sortedEnd) { |
2929 | // qDebug("reset defined: %s, from pos=%i to pos=%i", (*sortedI)->desc.c_str(), (*sortedI)->listViewPos, lvpTop+1); | 2929 | // qDebug("reset defined: %s, from pos=%i to pos=%i", (*sortedI)->desc.c_str(), (*sortedI)->listViewPos, lvpTop+1); |
2930 | (*sortedI)->listViewPos = ++lvpTop; | 2930 | (*sortedI)->listViewPos = ++lvpTop; |
2931 | ++sortedI; | 2931 | ++sortedI; |
2932 | } | 2932 | } |
2933 | 2933 | ||
2934 | /*/debug | 2934 | /*/debug |
2935 | entrBegin = catI->d.begin(); | 2935 | entrBegin = catI->d.begin(); |
2936 | entrEnd = catI->d.end(); | 2936 | entrEnd = catI->d.end(); |
2937 | entrI = entrBegin; | 2937 | entrI = entrBegin; |
2938 | 2938 | ||
2939 | while (entrI != entrEnd) { | 2939 | while (entrI != entrEnd) { |
2940 | qDebug("check: %s, pos=%i", (*entrI).desc.c_str(), (*entrI).listViewPos); | 2940 | qDebug("check: %s, pos=%i", (*entrI).desc.c_str(), (*entrI).listViewPos); |
2941 | ++entrI; | 2941 | ++entrI; |
2942 | } | 2942 | } |
2943 | */ | 2943 | */ |
2944 | 2944 | ||
2945 | ++catI; | 2945 | ++catI; |
2946 | } | 2946 | } |
2947 | } | 2947 | } |
2948 | 2948 | ||
2949 | QString PwMDoc::getTitle() | 2949 | QString PwMDoc::getTitle() |
2950 | { | 2950 | { |
2951 | /* NOTE: We have to ensure, that the returned title | 2951 | /* NOTE: We have to ensure, that the returned title |
2952 | * is unique and not reused somewhere else while | 2952 | * is unique and not reused somewhere else while |
2953 | * this document is valid (open). | 2953 | * this document is valid (open). |
2954 | */ | 2954 | */ |
2955 | QString title(getFilename()); | 2955 | QString title(getFilename()); |
2956 | 2956 | ||
2957 | //US ENH: The whole filename on PDAs is too long. So use only the last characters | 2957 | //US ENH: The whole filename on PDAs is too long. So use only the last characters |
2958 | if (QApplication::desktop()->width() < 640) | 2958 | if (QApplication::desktop()->width() < 640) |
2959 | { | 2959 | { |
2960 | if (title.length() > 30) | 2960 | if (title.length() > 30) |
2961 | title = "..." + title.right(30); | 2961 | title = "..." + title.right(30); |
2962 | 2962 | ||
2963 | } | 2963 | } |
2964 | 2964 | ||
2965 | 2965 | ||
2966 | if (title.isEmpty()) { | 2966 | if (title.isEmpty()) { |
2967 | if (unnamedNum == 0) { | 2967 | if (unnamedNum == 0) { |
2968 | unnamedNum = PwMDocList::getNewUnnamedNumber(); | 2968 | unnamedNum = PwMDocList::getNewUnnamedNumber(); |
2969 | PWM_ASSERT(unnamedNum != 0); | 2969 | PWM_ASSERT(unnamedNum != 0); |
2970 | } | 2970 | } |
2971 | title = DEFAULT_TITLE; | 2971 | title = DEFAULT_TITLE; |
2972 | title += " "; | 2972 | title += " "; |
2973 | title += tostr(unnamedNum).c_str(); | 2973 | title += tostr(unnamedNum).c_str(); |
2974 | } | 2974 | } |
2975 | return title; | 2975 | return title; |
2976 | } | 2976 | } |
2977 | 2977 | ||
2978 | bool PwMDoc::tryDelete() | 2978 | bool PwMDoc::tryDelete() |
2979 | { | 2979 | { |
2980 | 2980 | ||
2981 | if (deleted) | 2981 | if (deleted) |
2982 | return true; | 2982 | return true; |
2983 | int ret; | 2983 | int ret; |
2984 | if (isDirty()) { | 2984 | if (isDirty()) { |
2985 | ret = dirtyAskSave(getTitle()); | 2985 | ret = dirtyAskSave(getTitle()); |
2986 | if (ret == 0) { // save to disk | 2986 | if (ret == 0) { // save to disk |
2987 | if (!saveDocUi(this)) | 2987 | if (!saveDocUi(this)) |
2988 | goto out_ignore; | 2988 | goto out_ignore; |
2989 | } else if (ret == 1) { // don't save and delete | 2989 | } else if (ret == 1) { // don't save and delete |
2990 | goto out_accept; | 2990 | goto out_accept; |
2991 | } else { // cancel operation | 2991 | } else { // cancel operation |
2992 | goto out_ignore; | 2992 | goto out_ignore; |
2993 | } | 2993 | } |
2994 | } | 2994 | } |
2995 | out_accept: | 2995 | out_accept: |
2996 | deleted = true; | 2996 | deleted = true; |
2997 | delete this; | 2997 | delete this; |
2998 | return true; | 2998 | return true; |
2999 | out_ignore: | 2999 | out_ignore: |
3000 | return false; | 3000 | return false; |
3001 | } | 3001 | } |
3002 | 3002 | ||
3003 | 3003 | ||
3004 | 3004 | ||
3005 | #ifdef PWM_EMBEDDED | 3005 | #ifdef PWM_EMBEDDED |
3006 | //US ENH: this is the magic function that syncronizes the this doc with the remote doc | 3006 | //US ENH: this is the magic function that syncronizes the this doc with the remote doc |
3007 | //US it could have been defined as static, but I did not want to. | 3007 | //US it could have been defined as static, but I did not want to. |
3008 | PwMerror PwMDoc::syncronize(KSyncManager* manager, PwMDoc* syncLocal , PwMDoc* syncRemote, int mode ) | 3008 | PwMerror PwMDoc::syncronize(KSyncManager* manager, PwMDoc* syncLocal , PwMDoc* syncRemote, int mode ) |
3009 | { | 3009 | { |
3010 | int addedPasswordsLocal = 0; | 3010 | int addedPasswordsLocal = 0; |
3011 | int addedPasswordsRemote = 0; | 3011 | int addedPasswordsRemote = 0; |
3012 | int deletedPasswordsRemote = 0; | 3012 | int deletedPasswordsRemote = 0; |
3013 | int deletedPasswordsLocal = 0; | 3013 | int deletedPasswordsLocal = 0; |
3014 | int changedLocal = 0; | 3014 | int changedLocal = 0; |
3015 | int changedRemote = 0; | 3015 | int changedRemote = 0; |
3016 | 3016 | ||
3017 | PwMSyncItem* syncItemLocal; | 3017 | PwMSyncItem* syncItemLocal; |
3018 | PwMSyncItem* syncItemRemote; | 3018 | PwMSyncItem* syncItemRemote; |
3019 | 3019 | ||
3020 | QString mCurrentSyncName = manager->getCurrentSyncName(); | 3020 | QString mCurrentSyncName = manager->getCurrentSyncName(); |
3021 | QString mCurrentSyncDevice = manager->getCurrentSyncDevice(); | 3021 | QString mCurrentSyncDevice = manager->getCurrentSyncDevice(); |
3022 | 3022 | ||
3023 | bool mSyncLauncher = true; | ||
3024 | |||
3023 | bool fullDateRange = false; | 3025 | bool fullDateRange = false; |
3024 | int take; | 3026 | int take; |
3025 | // local->resetTempSyncStat(); | 3027 | // local->resetTempSyncStat(); |
3026 | QDateTime mLastSync = QDateTime::currentDateTime(); | 3028 | QDateTime mLastSync = QDateTime::currentDateTime(); |
3027 | QDateTime modifiedSync = mLastSync; | 3029 | QDateTime modifiedSync = mLastSync; |
3028 | 3030 | ||
3029 | unsigned int index; | 3031 | unsigned int index; |
3030 | //Step 1. Find syncinfo in Local file and create if not existent. | 3032 | //Step 1. Find syncinfo in Local file and create if not existent. |
3031 | bool found = syncLocal->findSyncData(mCurrentSyncDevice, &index); | 3033 | bool found = syncLocal->findSyncData(mCurrentSyncDevice, &index); |
3032 | if (found == false) | 3034 | if (found == false) |
3033 | { | 3035 | { |
3034 | PwMSyncItem newSyncItemLocal; | 3036 | PwMSyncItem newSyncItemLocal; |
3035 | newSyncItemLocal.syncName = mCurrentSyncDevice.latin1(); | 3037 | newSyncItemLocal.syncName = mCurrentSyncDevice.latin1(); |
3036 | newSyncItemLocal.lastSyncDate = mLastSync; | 3038 | newSyncItemLocal.lastSyncDate = mLastSync; |
3037 | syncLocal->addSyncDataEntry(&newSyncItemLocal, true); | 3039 | syncLocal->addSyncDataEntry(&newSyncItemLocal, true); |
3038 | found = syncLocal->findSyncData(mCurrentSyncDevice, &index); | 3040 | found = syncLocal->findSyncData(mCurrentSyncDevice, &index); |
3039 | if (found == false) { | 3041 | if (found == false) { |
3040 | qDebug("PwMDoc::syncronize : newly created local sync data could not be found"); | 3042 | qDebug("PwMDoc::syncronize : newly created local sync data could not be found"); |
3041 | return e_syncError; | 3043 | return e_syncError; |
3042 | } | 3044 | } |
3043 | } | 3045 | } |
3044 | 3046 | ||
3045 | syncItemLocal = syncLocal->getSyncDataEntry(index); | 3047 | syncItemLocal = syncLocal->getSyncDataEntry(index); |
3046 | qDebug("Last Sync Local %s ", syncItemLocal->lastSyncDate.toString().latin1()); | 3048 | qDebug("Last Sync Local %s ", syncItemLocal->lastSyncDate.toString().latin1()); |
3047 | 3049 | ||
3048 | //Step 2. Find syncinfo in remote file and create if not existent. | 3050 | //Step 2. Find syncinfo in remote file and create if not existent. |
3049 | found = syncRemote->findSyncData(mCurrentSyncName, &index); | 3051 | found = syncRemote->findSyncData(mCurrentSyncName, &index); |
3050 | if (found == false) | 3052 | if (found == false) |
3051 | { | 3053 | { |
3052 | qDebug("FULLDATE 1"); | 3054 | qDebug("FULLDATE 1"); |
3053 | fullDateRange = true; | 3055 | fullDateRange = true; |
3054 | PwMSyncItem newSyncItemRemote; | 3056 | PwMSyncItem newSyncItemRemote; |
3055 | newSyncItemRemote.syncName = mCurrentSyncName.latin1(); | 3057 | newSyncItemRemote.syncName = mCurrentSyncName.latin1(); |
3056 | newSyncItemRemote.lastSyncDate = mLastSync; | 3058 | newSyncItemRemote.lastSyncDate = mLastSync; |
3057 | syncRemote->addSyncDataEntry(&newSyncItemRemote, true); | 3059 | syncRemote->addSyncDataEntry(&newSyncItemRemote, true); |
3058 | found = syncRemote->findSyncData(mCurrentSyncName, &index); | 3060 | found = syncRemote->findSyncData(mCurrentSyncName, &index); |
3059 | if (found == false) { | 3061 | if (found == false) { |
3060 | qDebug("PwMDoc::syncronize : newly created remote sync data could not be found"); | 3062 | qDebug("PwMDoc::syncronize : newly created remote sync data could not be found"); |
3061 | return e_syncError; | 3063 | return e_syncError; |
3062 | } | 3064 | } |
3063 | } | 3065 | } |
3064 | 3066 | ||
3065 | syncItemRemote = syncRemote->getSyncDataEntry(index); | 3067 | syncItemRemote = syncRemote->getSyncDataEntry(index); |
3066 | qDebug("Last Sync Remote %s ", syncItemRemote->lastSyncDate.toString().latin1()); | 3068 | qDebug("Last Sync Remote %s ", syncItemRemote->lastSyncDate.toString().latin1()); |
3067 | //and remove the found entry here. We will reenter it later again. | 3069 | //and remove the found entry here. We will reenter it later again. |
3068 | //US syncRemote->delSyncDataEntry(index, true); | 3070 | //US syncRemote->delSyncDataEntry(index, true); |
3069 | 3071 | ||
3070 | 3072 | ||
3071 | if ( syncItemLocal->lastSyncDate == mLastSync ) { | 3073 | if ( syncItemLocal->lastSyncDate == mLastSync ) { |
3072 | qDebug("FULLDATE 2"); | 3074 | qDebug("FULLDATE 2"); |
3073 | fullDateRange = true; | 3075 | fullDateRange = true; |
3074 | } | 3076 | } |
3075 | 3077 | ||
3076 | if ( ! fullDateRange ) { | 3078 | if ( ! fullDateRange ) { |
3077 | if ( syncItemLocal->lastSyncDate != syncItemRemote->lastSyncDate ) { | 3079 | if ( syncItemLocal->lastSyncDate != syncItemRemote->lastSyncDate ) { |
3078 | 3080 | ||
3079 | fullDateRange = true; | 3081 | fullDateRange = true; |
3080 | qDebug("FULLDATE 3 %s %s", syncItemLocal->lastSyncDate.toString().latin1() , syncItemRemote->lastSyncDate.toString().latin1() ); | 3082 | qDebug("FULLDATE 3 %s %s", syncItemLocal->lastSyncDate.toString().latin1() , syncItemRemote->lastSyncDate.toString().latin1() ); |
3081 | } | 3083 | } |
3082 | } | 3084 | } |
3083 | // fullDateRange = true; // debug only! | 3085 | // fullDateRange = true; // debug only! |
3084 | if ( fullDateRange ) | 3086 | if ( fullDateRange ) |
3085 | mLastSync = QDateTime::currentDateTime().addDays( -100*365); | 3087 | mLastSync = QDateTime::currentDateTime().addDays( -100*365); |
3086 | else | 3088 | else |
3087 | mLastSync = syncItemLocal->lastSyncDate; | 3089 | mLastSync = syncItemLocal->lastSyncDate; |
3088 | 3090 | ||
3089 | 3091 | ||
3090 | qDebug("*************************** "); | 3092 | qDebug("*************************** "); |
3091 | qDebug("mLastSync %s ",mLastSync.toString().latin1() ); | 3093 | qDebug("mLastSync %s ",mLastSync.toString().latin1() ); |
3092 | QStringList er = syncRemote->getIDEntryList(); | 3094 | QStringList er = syncRemote->getIDEntryList(); |
3093 | PwMDataItem* inRemote ;//= er.first(); | 3095 | PwMDataItem* inRemote ;//= er.first(); |
3094 | PwMDataItem* inLocal; | 3096 | PwMDataItem* inLocal; |
3095 | unsigned int catLocal, indexLocal; | 3097 | unsigned int catLocal, indexLocal; |
3096 | unsigned int catRemote, indexRemote; | 3098 | unsigned int catRemote, indexRemote; |
3097 | 3099 | ||
3098 | QString uid; | 3100 | QString uid; |
3099 | manager->showProgressBar(0, i18n("Syncing - close to abort!"), er.count()); | 3101 | manager->showProgressBar(0, i18n("Syncing - close to abort!"), er.count()); |
3100 | 3102 | ||
3101 | int modulo = (er.count()/10)+1; | 3103 | int modulo = (er.count()/10)+1; |
3102 | unsigned int incCounter = 0; | 3104 | unsigned int incCounter = 0; |
3103 | while ( incCounter < er.count()) { | 3105 | while ( incCounter < er.count()) { |
3104 | if (manager->isProgressBarCanceled()) | 3106 | if (manager->isProgressBarCanceled()) |
3105 | return e_syncError; | 3107 | return e_syncError; |
3106 | if ( incCounter % modulo == 0 ) | 3108 | if ( incCounter % modulo == 0 ) |
3107 | manager->showProgressBar(incCounter); | 3109 | manager->showProgressBar(incCounter); |
3108 | 3110 | ||
3109 | uid = er[ incCounter ]; | 3111 | uid = er[ incCounter ]; |
3110 | qDebug("sync uid %s from remote file", uid.latin1()); | 3112 | qDebug("sync uid %s from remote file", uid.latin1()); |
3111 | 3113 | ||
3112 | qApp->processEvents(); | 3114 | qApp->processEvents(); |
3113 | 3115 | ||
3114 | inLocal = syncLocal->findEntryByID( uid, &catLocal, &indexLocal ); | 3116 | inLocal = syncLocal->findEntryByID( uid, &catLocal, &indexLocal ); |
3115 | inRemote = syncRemote->findEntryByID( uid, &catRemote, &indexRemote ); | 3117 | inRemote = syncRemote->findEntryByID( uid, &catRemote, &indexRemote ); |
3116 | PWM_ASSERT(inRemote); | 3118 | PWM_ASSERT(inRemote); |
3117 | if ( inLocal != 0 ) { // maybe conflict - same uid in both files | 3119 | if ( inLocal != 0 ) { // maybe conflict - same uid in both files |
3118 | if ( (take = takePwMDataItem( inLocal, inRemote, mLastSync, mode, fullDateRange) ) ) { | 3120 | if ( (take = takePwMDataItem( inLocal, inRemote, mLastSync, mode, fullDateRange) ) ) { |
3119 | qDebug("take %d %s ", take, inLocal->desc.c_str()); | 3121 | qDebug("take %d %s ", take, inLocal->desc.c_str()); |
3120 | if ( take == 3 ) | 3122 | if ( take == 3 ) |
3121 | return e_syncError; | 3123 | return e_syncError; |
3122 | if ( take == 1 ) {// take local | 3124 | if ( take == 1 ) {// take local |
3123 | int oldlistpos = inRemote->listViewPos; | 3125 | inRemote->syncItem(*inLocal, mSyncLauncher); |
3124 | (*inRemote) = (*inLocal); | ||
3125 | inRemote->listViewPos = oldlistpos; | ||
3126 | ++changedRemote; | 3126 | ++changedRemote; |
3127 | } else { // take == 2 take remote | 3127 | } else { // take == 2 take remote |
3128 | int oldlistpos = inLocal->listViewPos; | 3128 | inLocal->syncItem(*inRemote, mSyncLauncher); |
3129 | (*inLocal) = (*inRemote); | ||
3130 | inLocal->listViewPos = oldlistpos; | ||
3131 | ++changedLocal; | 3129 | ++changedLocal; |
3132 | } | 3130 | } |
3133 | } | 3131 | } |
3134 | } else { // no conflict | 3132 | } else { // no conflict |
3135 | if ( inRemote->meta.update > mLastSync || mode == 5 ) { | 3133 | if ( inRemote->meta.update > mLastSync || mode == 5 ) { |
3136 | inRemote->meta.update = modifiedSync; | 3134 | inRemote->meta.update = modifiedSync; |
3137 | 3135 | ||
3138 | //first check if we have a matching category in the local file | 3136 | //first check if we have a matching category in the local file |
3139 | const string* remotecat = syncRemote->getCategory(catRemote); | 3137 | const string* remotecat = syncRemote->getCategory(catRemote); |
3140 | syncLocal->addEntry(remotecat->c_str(), inRemote, true, false); | 3138 | syncLocal->addEntry(remotecat->c_str(), inRemote, true, false); |
3141 | 3139 | ||
3142 | ++addedPasswordsLocal; | 3140 | ++addedPasswordsLocal; |
3143 | } else { | 3141 | } else { |
3144 | // pending checkExternSyncAddressee(addresseeRSyncSharp, inR); | 3142 | // pending checkExternSyncAddressee(addresseeRSyncSharp, inR); |
3145 | syncRemote->delEntry(catRemote, indexRemote, true); | 3143 | syncRemote->delEntry(catRemote, indexRemote, true); |
3146 | ++deletedPasswordsRemote; | 3144 | ++deletedPasswordsRemote; |
3147 | } | 3145 | } |
3148 | } | 3146 | } |
3149 | 3147 | ||
3150 | ++incCounter; | 3148 | ++incCounter; |
3151 | } | 3149 | } |
3152 | 3150 | ||
3153 | 3151 | ||
3154 | er.clear(); | 3152 | er.clear(); |
3155 | QStringList el = syncLocal->getIDEntryList(); | 3153 | QStringList el = syncLocal->getIDEntryList(); |
3156 | modulo = (el.count()/10)+1; | 3154 | modulo = (el.count()/10)+1; |
3157 | 3155 | ||
3158 | manager->showProgressBar(0, i18n("Add / remove addressees"), el.count()); | 3156 | manager->showProgressBar(0, i18n("Add / remove addressees"), el.count()); |
3159 | incCounter = 0; | 3157 | incCounter = 0; |
3160 | while ( incCounter < el.count()) { | 3158 | while ( incCounter < el.count()) { |
3161 | qApp->processEvents(); | 3159 | qApp->processEvents(); |
3162 | if (manager->isProgressBarCanceled()) | 3160 | if (manager->isProgressBarCanceled()) |
3163 | return e_syncError; | 3161 | return e_syncError; |
3164 | if ( incCounter % modulo == 0 ) | 3162 | if ( incCounter % modulo == 0 ) |
3165 | manager->showProgressBar(incCounter); | 3163 | manager->showProgressBar(incCounter); |
3166 | uid = el[ incCounter ]; | 3164 | uid = el[ incCounter ]; |
3167 | qDebug("sync uid %s from local file", uid.latin1()); | 3165 | qDebug("sync uid %s from local file", uid.latin1()); |
3168 | 3166 | ||
3169 | inLocal = syncLocal->findEntryByID( uid, &catLocal, &indexLocal ); | 3167 | inLocal = syncLocal->findEntryByID( uid, &catLocal, &indexLocal ); |
3170 | inRemote = syncRemote->findEntryByID( uid, &catRemote, &indexRemote ); | 3168 | inRemote = syncRemote->findEntryByID( uid, &catRemote, &indexRemote ); |
3171 | PWM_ASSERT(inLocal); | 3169 | PWM_ASSERT(inLocal); |
3172 | 3170 | ||
3173 | if ( inRemote == 0 ) { | 3171 | if ( inRemote == 0 ) { |
3174 | if ( inLocal->meta.update < mLastSync && mode != 4 ) { | 3172 | if ( inLocal->meta.update < mLastSync && mode != 4 ) { |
3175 | // pending checkExternSyncAddressee(addresseeLSyncSharp, inL); | 3173 | // pending checkExternSyncAddressee(addresseeLSyncSharp, inL); |
3176 | syncLocal->delEntry(catLocal, indexLocal, true); | 3174 | syncLocal->delEntry(catLocal, indexLocal, true); |
3177 | ++deletedPasswordsLocal; | 3175 | ++deletedPasswordsLocal; |
3178 | } else { | 3176 | } else { |
3179 | if ( ! manager->mWriteBackExistingOnly ) { | 3177 | if ( ! manager->mWriteBackExistingOnly ) { |
3180 | ++addedPasswordsRemote; | 3178 | ++addedPasswordsRemote; |
3181 | inLocal->meta.update = modifiedSync; | 3179 | inLocal->meta.update = modifiedSync; |
3182 | 3180 | ||
3183 | //first check if we have a matching category in the remote file | 3181 | //first check if we have a matching category in the remote file |
3184 | const string* localcat = syncLocal->getCategory(catLocal); | 3182 | const string* localcat = syncLocal->getCategory(catLocal); |
3185 | 3183 | ||
3186 | PwMDataItem newEntry; | 3184 | PwMDataItem newEntry; |
3187 | newEntry = *inLocal; | 3185 | newEntry = *inLocal; |
3188 | inRemote = &newEntry; | 3186 | inRemote = &newEntry; |
3189 | 3187 | ||
3190 | //USsyncRemote->insertAddressee( inRemote, false ); | 3188 | //USsyncRemote->insertAddressee( inRemote, false ); |
3191 | syncRemote->addEntry(localcat->c_str(), inRemote, true, false); | 3189 | syncRemote->addEntry(localcat->c_str(), inRemote, true, false); |
3192 | 3190 | ||
3193 | } | 3191 | } |
3194 | } | 3192 | } |
3195 | 3193 | ||
3196 | } | 3194 | } |
3197 | ++incCounter; | 3195 | ++incCounter; |
3198 | } | 3196 | } |
3199 | el.clear(); | 3197 | el.clear(); |
3200 | manager->hideProgressBar(); | 3198 | manager->hideProgressBar(); |
3201 | 3199 | ||
3202 | // Now write the info back into the sync data space of the files | 3200 | // Now write the info back into the sync data space of the files |
3203 | 3201 | ||
3204 | mLastSync = QDateTime::currentDateTime().addSecs( 1 ); | 3202 | mLastSync = QDateTime::currentDateTime().addSecs( 1 ); |
3205 | // get rid of micro seconds | 3203 | // get rid of micro seconds |
3206 | QTime t = mLastSync.time(); | 3204 | QTime t = mLastSync.time(); |
3207 | mLastSync.setTime( QTime (t.hour (), t.minute (), t.second () ) ); | 3205 | mLastSync.setTime( QTime (t.hour (), t.minute (), t.second () ) ); |
3208 | 3206 | ||
3209 | 3207 | ||
3210 | syncItemLocal->lastSyncDate = mLastSync; | 3208 | syncItemLocal->lastSyncDate = mLastSync; |
3211 | syncItemRemote->lastSyncDate = mLastSync; | 3209 | syncItemRemote->lastSyncDate = mLastSync; |
3212 | 3210 | ||
3213 | QString mes; | 3211 | QString mes; |
3214 | 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 ); | 3212 | 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 ); |
3215 | if ( manager->mShowSyncSummary ) { | 3213 | if ( manager->mShowSyncSummary ) { |
3216 | KMessageBox::information(0, mes, i18n("PWM/Pi Synchronization") ); | 3214 | KMessageBox::information(0, mes, i18n("PWM/Pi Synchronization") ); |
3217 | } | 3215 | } |
3218 | qDebug( mes ); | 3216 | qDebug( mes ); |
3219 | return e_success; | 3217 | return e_success; |
3220 | } | 3218 | } |
3221 | 3219 | ||
3222 | 3220 | ||
3223 | int PwMDoc::takePwMDataItem( PwMDataItem* local, PwMDataItem* remote, QDateTime lastSync, int mode , bool full ) | 3221 | int PwMDoc::takePwMDataItem( PwMDataItem* local, PwMDataItem* remote, QDateTime lastSync, int mode , bool full ) |
3224 | { | 3222 | { |
3225 | // 0 equal | 3223 | // 0 equal |
3226 | // 1 take local | 3224 | // 1 take local |
3227 | // 2 take remote | 3225 | // 2 take remote |
3228 | // 3 cancel | 3226 | // 3 cancel |
3229 | QDateTime localMod = local->meta.update; | 3227 | QDateTime localMod = local->meta.update; |
3230 | QDateTime remoteMod = remote->meta.update; | 3228 | QDateTime remoteMod = remote->meta.update; |
3231 | 3229 | ||
3232 | if ( localMod == remoteMod ) | 3230 | if ( localMod == remoteMod ) |
3233 | return 0; | 3231 | return 0; |
3234 | 3232 | ||
3235 | qDebug(" %d %d conflict on %s %s ", mode, full, local->desc.c_str(), remote->desc.c_str() ); | 3233 | qDebug(" %d %d conflict on %s %s ", mode, full, local->desc.c_str(), remote->desc.c_str() ); |
3236 | 3234 | ||
3237 | //qDebug("%s %d %s %d", local->lastModified().toString().latin1() , localMod, remote->lastModified().toString().latin1(), remoteMod); | 3235 | //qDebug("%s %d %s %d", local->lastModified().toString().latin1() , localMod, remote->lastModified().toString().latin1(), remoteMod); |
3238 | //qDebug("%d %d %d %d ", local->lastModified().time().second(), local->lastModified().time().msec(), remote->lastModified().time().second(), remote->lastModified().time().msec() ); | 3236 | //qDebug("%d %d %d %d ", local->lastModified().time().second(), local->lastModified().time().msec(), remote->lastModified().time().second(), remote->lastModified().time().msec() ); |
3239 | //full = true; //debug only | 3237 | //full = true; //debug only |
3240 | if ( full ) { | 3238 | if ( full ) { |
3241 | bool equ = ( (*local) == (*remote) ); | 3239 | bool equ = ( (*local) == (*remote) ); |
3242 | if ( equ ) { | 3240 | if ( equ ) { |
3243 | //qDebug("equal "); | 3241 | //qDebug("equal "); |
3244 | if ( mode < SYNC_PREF_FORCE_LOCAL ) | 3242 | if ( mode < SYNC_PREF_FORCE_LOCAL ) |
3245 | return 0; | 3243 | return 0; |
3246 | 3244 | ||
3247 | }//else //debug only | 3245 | }//else //debug only |
3248 | //qDebug("not equal %s %s ", local->desc.c_str(), remote->desc.c_str()); | 3246 | //qDebug("not equal %s %s ", local->desc.c_str(), remote->desc.c_str()); |
3249 | } | 3247 | } |
3250 | 3248 | ||
3251 | int result; | 3249 | int result; |
3252 | bool localIsNew; | 3250 | bool localIsNew; |
3253 | //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() ); | 3251 | //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() ); |
3254 | 3252 | ||
3255 | if ( full && mode < SYNC_PREF_NEWEST ) | 3253 | if ( full && mode < SYNC_PREF_NEWEST ) |
3256 | mode = SYNC_PREF_ASK; | 3254 | mode = SYNC_PREF_ASK; |
3257 | 3255 | ||
3258 | switch( mode ) { | 3256 | switch( mode ) { |
3259 | case SYNC_PREF_LOCAL: | 3257 | case SYNC_PREF_LOCAL: |
3260 | if ( lastSync > remoteMod ) | 3258 | if ( lastSync > remoteMod ) |
3261 | return 1; | 3259 | return 1; |
3262 | if ( lastSync > localMod ) | 3260 | if ( lastSync > localMod ) |
3263 | return 2; | 3261 | return 2; |
3264 | return 1; | 3262 | return 1; |
3265 | break; | 3263 | break; |
3266 | case SYNC_PREF_REMOTE: | 3264 | case SYNC_PREF_REMOTE: |
3267 | if ( lastSync > remoteMod ) | 3265 | if ( lastSync > remoteMod ) |
3268 | return 1; | 3266 | return 1; |
3269 | if ( lastSync > localMod ) | 3267 | if ( lastSync > localMod ) |
3270 | return 2; | 3268 | return 2; |
3271 | return 2; | 3269 | return 2; |
3272 | break; | 3270 | break; |
3273 | case SYNC_PREF_NEWEST: | 3271 | case SYNC_PREF_NEWEST: |
3274 | if ( localMod > remoteMod ) | 3272 | if ( localMod > remoteMod ) |
3275 | return 1; | 3273 | return 1; |
3276 | else | 3274 | else |
3277 | return 2; | 3275 | return 2; |
3278 | break; | 3276 | break; |
3279 | case SYNC_PREF_ASK: | 3277 | case SYNC_PREF_ASK: |
3280 | //qDebug("lsy %s --- lo %s --- re %s ", lastSync.toString().latin1(), localMod.toString().latin1(), remoteMod.toString().latin1() ); | 3278 | //qDebug("lsy %s --- lo %s --- re %s ", lastSync.toString().latin1(), localMod.toString().latin1(), remoteMod.toString().latin1() ); |
3281 | if ( lastSync > remoteMod ) | 3279 | if ( lastSync > remoteMod ) |
3282 | return 1; | 3280 | return 1; |
3283 | if ( lastSync > localMod ) | 3281 | if ( lastSync > localMod ) |
3284 | return 2; | 3282 | return 2; |
3285 | localIsNew = localMod >= remoteMod; | 3283 | localIsNew = localMod >= remoteMod; |
3286 | //qDebug("conflict! ************************************** "); | 3284 | //qDebug("conflict! ************************************** "); |
3287 | { | 3285 | { |
3288 | PwMDataItemChooser acd ( *local,*remote, localIsNew , 0/*this*/ ); | 3286 | PwMDataItemChooser acd ( *local,*remote, localIsNew , 0/*this*/ ); |
3289 | result = acd.executeD(localIsNew); | 3287 | result = acd.executeD(localIsNew); |
3290 | return result; | 3288 | return result; |
3291 | } | 3289 | } |
3292 | break; | 3290 | break; |
3293 | case SYNC_PREF_FORCE_LOCAL: | 3291 | case SYNC_PREF_FORCE_LOCAL: |
3294 | return 1; | 3292 | return 1; |
3295 | break; | 3293 | break; |
3296 | case SYNC_PREF_FORCE_REMOTE: | 3294 | case SYNC_PREF_FORCE_REMOTE: |
3297 | return 2; | 3295 | return 2; |
3298 | break; | 3296 | break; |
3299 | 3297 | ||
3300 | default: | 3298 | default: |
3301 | // SYNC_PREF_TAKE_BOTH not implemented | 3299 | // SYNC_PREF_TAKE_BOTH not implemented |
3302 | break; | 3300 | break; |
3303 | } | 3301 | } |
3304 | return 0; | 3302 | return 0; |
3305 | } | 3303 | } |
3306 | 3304 | ||
3307 | void PwMDoc::removeSyncInfo( QString syncProfile) | 3305 | void PwMDoc::removeSyncInfo( QString syncProfile) |
3308 | { | 3306 | { |
3309 | qDebug("PwMDoc::not implemented: removeSyncInfo for profile %s ", syncProfile.latin1()); | 3307 | qDebug("PwMDoc::not implemented: removeSyncInfo for profile %s ", syncProfile.latin1()); |
3310 | } | 3308 | } |
3311 | 3309 | ||
3312 | 3310 | ||
3313 | //this are the overwritten callbackmethods from the syncinterface | 3311 | //this are the overwritten callbackmethods from the syncinterface |
3314 | bool PwMDoc::sync(KSyncManager* manager, QString filename, int mode) | 3312 | bool PwMDoc::sync(KSyncManager* manager, QString filename, int mode) |
3315 | { | 3313 | { |
3316 | QString mCurrentSyncDevice = manager->getCurrentSyncDevice(); | 3314 | QString mCurrentSyncDevice = manager->getCurrentSyncDevice(); |
3317 | 3315 | ||
3318 | //1) unlock local file first if necessary (ask for password) | 3316 | //1) unlock local file first if necessary (ask for password) |
3319 | if (this->isDeepLocked()) { | 3317 | if (this->isDeepLocked()) { |
3320 | PwMerror ret = this->deepLock(false); | 3318 | PwMerror ret = this->deepLock(false); |
3321 | if (ret != e_success) | 3319 | if (ret != e_success) |
3322 | return false; | 3320 | return false; |
3323 | } | 3321 | } |
3324 | 3322 | ||
3325 | //2) construct and open a new doc on the stack(automatic cleanup of remote file). | 3323 | //2) construct and open a new doc on the stack(automatic cleanup of remote file). |
3326 | PwMDoc syncTarget(this, "synctarget"); | 3324 | PwMDoc syncTarget(this, "synctarget"); |
3327 | PwMDoc* pSyncTarget = &syncTarget; | 3325 | PwMDoc* pSyncTarget = &syncTarget; |
3328 | 3326 | ||
3329 | 3327 | ||
3330 | PwMerror err = pSyncTarget->openDoc(&filename, 1 /*== open with all entries locked*/); | 3328 | PwMerror err = pSyncTarget->openDoc(&filename, 1 /*== open with all entries locked*/); |
3331 | 3329 | ||
3332 | if (err == e_alreadyOpen) { | 3330 | if (err == e_alreadyOpen) { |
3333 | PwMDocList::listItem li; | 3331 | PwMDocList::listItem li; |
3334 | if (getOpenDocList()->find(filename.latin1(), &li)) | 3332 | if (getOpenDocList()->find(filename.latin1(), &li)) |
3335 | pSyncTarget = li.doc; | 3333 | pSyncTarget = li.doc; |
3336 | else { | 3334 | else { |
3337 | qDebug("PwmDoc::sync: sync failed. Error %i while opening file %s",err, filename.latin1()); | 3335 | qDebug("PwmDoc::sync: sync failed. Error %i while opening file %s",err, filename.latin1()); |
3338 | return false; | 3336 | return false; |
3339 | } | 3337 | } |
3340 | } | 3338 | } |
3341 | else if (err != e_success) { | 3339 | else if (err != e_success) { |
3342 | qDebug("PwmDoc::sync: sync failed. Error %i while opening file %s",err, filename.latin1()); | 3340 | qDebug("PwmDoc::sync: sync failed. Error %i while opening file %s",err, filename.latin1()); |
3343 | return false; | 3341 | return false; |
3344 | } | 3342 | } |
3345 | 3343 | ||
3346 | qDebug("PWM file loaded %s,sync mode %d",filename.latin1(), mode ); | 3344 | qDebug("PWM file loaded %s,sync mode %d",filename.latin1(), mode ); |
3347 | 3345 | ||
3348 | 3346 | ||
3349 | //3) unlock remote file first if necessary (ask for password) | 3347 | //3) unlock remote file first if necessary (ask for password) |
3350 | if (pSyncTarget->isDeepLocked()) { | 3348 | if (pSyncTarget->isDeepLocked()) { |
3351 | PwMerror ret = pSyncTarget->deepLock(false); | 3349 | PwMerror ret = pSyncTarget->deepLock(false); |
3352 | if (ret != e_success) | 3350 | if (ret != e_success) |
3353 | return false; | 3351 | return false; |
3354 | } | 3352 | } |
3355 | 3353 | ||
3356 | 3354 | ||
3357 | err = syncronize(manager, this, pSyncTarget, mode ); | 3355 | err = syncronize(manager, this, pSyncTarget, mode ); |
3358 | 3356 | ||
3359 | if (err == e_success) { | 3357 | if (err == e_success) { |
3360 | if ( manager->mWriteBackFile ){ | 3358 | if ( manager->mWriteBackFile ){ |
3361 | qDebug("Saving remote PWManager file"); | 3359 | qDebug("Saving remote PWManager file"); |
3362 | err = pSyncTarget->saveDoc(conf()->confGlobCompression()); | 3360 | err = pSyncTarget->saveDoc(conf()->confGlobCompression()); |
3363 | if (err != e_success) { | 3361 | if (err != e_success) { |
3364 | qDebug("PwmDoc::sync: Sync failed. Error %i while storing file %s",err, filename.latin1()); | 3362 | qDebug("PwmDoc::sync: Sync failed. Error %i while storing file %s",err, filename.latin1()); |
3365 | return false; | 3363 | return false; |
3366 | } | 3364 | } |
3367 | } | 3365 | } |
3368 | 3366 | ||
3369 | flagDirty(); | 3367 | flagDirty(); |
3370 | return true; | 3368 | return true; |
3371 | } | 3369 | } |
3372 | else { | 3370 | else { |
3373 | return false; | 3371 | return false; |
3374 | } | 3372 | } |
3375 | } | 3373 | } |
3376 | 3374 | ||
3377 | #endif | 3375 | #endif |
3378 | 3376 | ||
3379 | 3377 | ||
3380 | bool PwMDoc::findSyncData(const QString &syncname, unsigned int *index) | 3378 | bool PwMDoc::findSyncData(const QString &syncname, unsigned int *index) |
3381 | { | 3379 | { |
3382 | vector<PwMSyncItem>::iterator i = dti.syncDta.begin(), | 3380 | vector<PwMSyncItem>::iterator i = dti.syncDta.begin(), |
3383 | end = dti.syncDta.end(); | 3381 | end = dti.syncDta.end(); |
3384 | 3382 | ||
3385 | while (i != end) { | 3383 | while (i != end) { |
3386 | if ((*i).syncName == syncname.latin1()) { | 3384 | if ((*i).syncName == syncname.latin1()) { |
3387 | if (index) { | 3385 | if (index) { |
3388 | *index = i - dti.syncDta.begin(); | 3386 | *index = i - dti.syncDta.begin(); |
3389 | } | 3387 | } |
3390 | return true; | 3388 | return true; |
3391 | } | 3389 | } |
3392 | ++i; | 3390 | ++i; |
3393 | } | 3391 | } |
3394 | return false; | 3392 | return false; |
3395 | }; | 3393 | }; |
3396 | 3394 | ||
3397 | /** add new syncdataentry */ | 3395 | /** add new syncdataentry */ |
3398 | PwMerror PwMDoc::addSyncDataEntry(PwMSyncItem *d, bool dontFlagDirty) | 3396 | PwMerror PwMDoc::addSyncDataEntry(PwMSyncItem *d, bool dontFlagDirty) |
3399 | { | 3397 | { |
3400 | PWM_ASSERT(d); | 3398 | PWM_ASSERT(d); |
3401 | 3399 | ||
3402 | if (isDeepLocked()) { | 3400 | if (isDeepLocked()) { |
3403 | PwMerror ret; | 3401 | PwMerror ret; |
3404 | ret = deepLock(false); | 3402 | ret = deepLock(false); |
3405 | if (ret != e_success) | 3403 | if (ret != e_success) |
3406 | return e_lock; | 3404 | return e_lock; |
3407 | } | 3405 | } |
3408 | unsigned int index; | 3406 | unsigned int index; |
3409 | 3407 | ||
3410 | const QString tmp = d->syncName.c_str(); | 3408 | const QString tmp = d->syncName.c_str(); |
3411 | bool exists = findSyncData(d->syncName.c_str(), &index); | 3409 | bool exists = findSyncData(d->syncName.c_str(), &index); |
3412 | 3410 | ||
3413 | if (exists == true) { | 3411 | if (exists == true) { |
3414 | // DOH! We found this entry. | 3412 | // DOH! We found this entry. |
3415 | return e_entryExists; | 3413 | return e_entryExists; |
3416 | } | 3414 | } |
3417 | 3415 | ||
3418 | dti.syncDta.push_back(*d); | 3416 | dti.syncDta.push_back(*d); |
3419 | 3417 | ||
3420 | if (!dontFlagDirty) | 3418 | if (!dontFlagDirty) |
3421 | flagDirty(); | 3419 | flagDirty(); |
3422 | return e_success; | 3420 | return e_success; |
3423 | } | 3421 | } |
3424 | 3422 | ||
3425 | 3423 | ||
3426 | 3424 | ||
3427 | /** delete syncdata entry */ | 3425 | /** delete syncdata entry */ |
3428 | bool PwMDoc::delSyncDataEntry(unsigned int index, bool dontFlagDirty) | 3426 | bool PwMDoc::delSyncDataEntry(unsigned int index, bool dontFlagDirty) |
3429 | { | 3427 | { |
3430 | if (isDeepLocked()) | 3428 | if (isDeepLocked()) |
3431 | return false; | 3429 | return false; |
3432 | if (index > dti.syncDta.size() - 1) | 3430 | if (index > dti.syncDta.size() - 1) |
3433 | return false; | 3431 | return false; |
3434 | 3432 | ||
3435 | // delete entry | 3433 | // delete entry |
3436 | dti.syncDta.erase(dti.syncDta.begin() + index); | 3434 | dti.syncDta.erase(dti.syncDta.begin() + index); |
3437 | 3435 | ||
3438 | if (!dontFlagDirty) | 3436 | if (!dontFlagDirty) |
3439 | flagDirty(); | 3437 | flagDirty(); |
3440 | return true; | 3438 | return true; |
3441 | } | 3439 | } |
3442 | 3440 | ||
3443 | 3441 | ||
3444 | PwMDataItem* PwMDoc::findEntryByID(const QString &uid, unsigned int *category, unsigned int *index) | 3442 | PwMDataItem* PwMDoc::findEntryByID(const QString &uid, unsigned int *category, unsigned int *index) |
3445 | { | 3443 | { |
3446 | vector<PwMCategoryItem>::iterator catcounter = dti.dta.begin(), | 3444 | vector<PwMCategoryItem>::iterator catcounter = dti.dta.begin(), |
3447 | catend = dti.dta.end(); | 3445 | catend = dti.dta.end(); |
3448 | 3446 | ||
3449 | vector<PwMDataItem>::iterator entrBegin, entrEnd, entrI; | 3447 | vector<PwMDataItem>::iterator entrBegin, entrEnd, entrI; |
3450 | 3448 | ||
3451 | while (catcounter != catend) { | 3449 | while (catcounter != catend) { |
3452 | entrBegin = catcounter->d.begin(); | 3450 | entrBegin = catcounter->d.begin(); |
3453 | entrEnd = catcounter->d.end(); | 3451 | entrEnd = catcounter->d.end(); |
3454 | entrI = entrBegin; | 3452 | entrI = entrBegin; |
3455 | while (entrI != entrEnd) { | 3453 | while (entrI != entrEnd) { |
3456 | if ((*entrI).meta.uniqueid == uid.latin1()) { | 3454 | if ((*entrI).meta.uniqueid == uid.latin1()) { |
3457 | if (category) | 3455 | if (category) |
3458 | *category = catcounter - dti.dta.begin(); | 3456 | *category = catcounter - dti.dta.begin(); |
3459 | if (index) | 3457 | if (index) |
3460 | *index = entrI - entrBegin; | 3458 | *index = entrI - entrBegin; |
3461 | 3459 | ||
3462 | return &(*entrI); | 3460 | return &(*entrI); |
3463 | } | 3461 | } |
3464 | ++entrI; | 3462 | ++entrI; |
3465 | } | 3463 | } |
3466 | ++catcounter; | 3464 | ++catcounter; |
3467 | } | 3465 | } |
3468 | 3466 | ||
3469 | return 0; | 3467 | return 0; |
3470 | } | 3468 | } |
3471 | 3469 | ||
3472 | QStringList PwMDoc::getIDEntryList() | 3470 | QStringList PwMDoc::getIDEntryList() |
3473 | { | 3471 | { |
3474 | QStringList results; | 3472 | QStringList results; |
3475 | 3473 | ||
3476 | vector<PwMCategoryItem>::iterator catcounter = dti.dta.begin(), | 3474 | vector<PwMCategoryItem>::iterator catcounter = dti.dta.begin(), |
3477 | catend = dti.dta.end(); | 3475 | catend = dti.dta.end(); |
3478 | 3476 | ||
3479 | vector<PwMDataItem>::iterator entrBegin, entrEnd, entrI; | 3477 | vector<PwMDataItem>::iterator entrBegin, entrEnd, entrI; |
3480 | 3478 | ||
3481 | while (catcounter != catend) { | 3479 | while (catcounter != catend) { |
3482 | entrBegin = catcounter->d.begin(); | 3480 | entrBegin = catcounter->d.begin(); |
3483 | entrEnd = catcounter->d.end(); | 3481 | entrEnd = catcounter->d.end(); |
3484 | entrI = entrBegin; | 3482 | entrI = entrBegin; |
3485 | while (entrI != entrEnd) { | 3483 | while (entrI != entrEnd) { |
3486 | results.append( (*entrI).meta.uniqueid.c_str() ); | 3484 | results.append( (*entrI).meta.uniqueid.c_str() ); |
3487 | ++entrI; | 3485 | ++entrI; |
3488 | } | 3486 | } |
3489 | ++catcounter; | 3487 | ++catcounter; |
3490 | } | 3488 | } |
3491 | 3489 | ||
3492 | return results; | 3490 | return results; |
3493 | } | 3491 | } |
3494 | 3492 | ||
3495 | 3493 | ||
3496 | 3494 | ||
3497 | 3495 | ||
3498 | 3496 | ||
3499 | #ifndef PWM_EMBEDDED | 3497 | #ifndef PWM_EMBEDDED |
3500 | #include "pwmdoc.moc" | 3498 | #include "pwmdoc.moc" |
3501 | #endif | 3499 | #endif |
diff --git a/pwmanager/pwmanager/pwmdoc.h b/pwmanager/pwmanager/pwmdoc.h index e419c24..09923ab 100644 --- a/pwmanager/pwmanager/pwmdoc.h +++ b/pwmanager/pwmanager/pwmdoc.h | |||
@@ -1,610 +1,630 @@ | |||
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 1.1 of pwmanager | 14 | * This file is originaly based on version 1.1 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 | #ifdef _WIN32_ | 22 | #ifdef _WIN32_ |
23 | #define ssize_t unsigned int | 23 | #define ssize_t unsigned int |
24 | #endif | 24 | #endif |
25 | #define PWM_FILE_VER (static_cast<char>(0x05)) | 25 | #define PWM_FILE_VER (static_cast<char>(0x05)) |
26 | 26 | ||
27 | #define PWM_HASH_SHA1 (static_cast<char>(0x01)) | 27 | #define PWM_HASH_SHA1 (static_cast<char>(0x01)) |
28 | #define PWM_HASH_SHA256 (static_cast<char>(0x02)) | 28 | #define PWM_HASH_SHA256 (static_cast<char>(0x02)) |
29 | #define PWM_HASH_SHA384 (static_cast<char>(0x03)) | 29 | #define PWM_HASH_SHA384 (static_cast<char>(0x03)) |
30 | #define PWM_HASH_SHA512 (static_cast<char>(0x04)) | 30 | #define PWM_HASH_SHA512 (static_cast<char>(0x04)) |
31 | #define PWM_HASH_MD5 (static_cast<char>(0x05)) | 31 | #define PWM_HASH_MD5 (static_cast<char>(0x05)) |
32 | #define PWM_HASH_RMD160 (static_cast<char>(0x06)) | 32 | #define PWM_HASH_RMD160 (static_cast<char>(0x06)) |
33 | #define PWM_HASH_TIGER (static_cast<char>(0x07)) | 33 | #define PWM_HASH_TIGER (static_cast<char>(0x07)) |
34 | 34 | ||
35 | #define PWM_CRYPT_BLOWFISH(static_cast<char>(0x01)) | 35 | #define PWM_CRYPT_BLOWFISH(static_cast<char>(0x01)) |
36 | #define PWM_CRYPT_AES128(static_cast<char>(0x02)) | 36 | #define PWM_CRYPT_AES128(static_cast<char>(0x02)) |
37 | #define PWM_CRYPT_AES192(static_cast<char>(0x03)) | 37 | #define PWM_CRYPT_AES192(static_cast<char>(0x03)) |
38 | #define PWM_CRYPT_AES256(static_cast<char>(0x04)) | 38 | #define PWM_CRYPT_AES256(static_cast<char>(0x04)) |
39 | #define PWM_CRYPT_3DES (static_cast<char>(0x05)) | 39 | #define PWM_CRYPT_3DES (static_cast<char>(0x05)) |
40 | #define PWM_CRYPT_TWOFISH(static_cast<char>(0x06)) | 40 | #define PWM_CRYPT_TWOFISH(static_cast<char>(0x06)) |
41 | #define PWM_CRYPT_TWOFISH128(static_cast<char>(0x07)) | 41 | #define PWM_CRYPT_TWOFISH128(static_cast<char>(0x07)) |
42 | 42 | ||
43 | #define PWM_COMPRESS_NONE(static_cast<char>(0x00)) | 43 | #define PWM_COMPRESS_NONE(static_cast<char>(0x00)) |
44 | #define PWM_COMPRESS_GZIP(static_cast<char>(0x01)) | 44 | #define PWM_COMPRESS_GZIP(static_cast<char>(0x01)) |
45 | #define PWM_COMPRESS_BZIP2(static_cast<char>(0x02)) | 45 | #define PWM_COMPRESS_BZIP2(static_cast<char>(0x02)) |
46 | 46 | ||
47 | #define DEFAULT_MAX_ENTRIES(~(static_cast<unsigned int>(0))) | 47 | #define DEFAULT_MAX_ENTRIES(~(static_cast<unsigned int>(0))) |
48 | #define FILE_ID_HEADER "PWM_PASSWORD_FILE" | 48 | #define FILE_ID_HEADER "PWM_PASSWORD_FILE" |
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 | ||
71 | using std::vector; | 71 | using std::vector; |
72 | using std::string; | 72 | using std::string; |
73 | using std::pair; | 73 | using 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 | ||
95 | class PwMDoc; | 95 | class PwMDoc; |
96 | class PwMView; | 96 | class PwMView; |
97 | class QFile; | 97 | class QFile; |
98 | 98 | ||
99 | /* meta data for a PwMDataItem */ | 99 | /* meta data for a PwMDataItem */ |
100 | struct PwMMetaData | 100 | struct 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 | ||
157 | struct PwMDataItem | 157 | struct 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 | |||
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. | ||
230 | bool PwMDataItem::syncItem(const PwMDataItem &a, bool syncLauncher=true ) | ||
231 | { | ||
232 | desc = a.desc; | ||
233 | name = a.name; | ||
234 | pw = a.pw; | ||
235 | comment = a.comment; | ||
236 | url = a.url; | ||
237 | if (syncLauncher == true) | ||
238 | launcher = a.launcher; | ||
239 | meta = a.meta; | ||
240 | binary = a.binary; | ||
241 | lockStat = a.lockStat; | ||
242 | rev = a.rev; | ||
243 | |||
244 | return true; | ||
245 | } | ||
246 | |||
227 | }; | 247 | }; |
228 | 248 | ||
229 | struct PwMCategoryItem | 249 | struct PwMCategoryItem |
230 | { | 250 | { |
231 | /** all PwMDataItems (all passwords) within this category */ | 251 | /** all PwMDataItems (all passwords) within this category */ |
232 | vector<PwMDataItem>d; | 252 | vector<PwMDataItem>d; |
233 | /** category name/description */ | 253 | /** category name/description */ |
234 | string name; | 254 | string name; |
235 | 255 | ||
236 | void clear() | 256 | void clear() |
237 | { | 257 | { |
238 | d.clear(); | 258 | d.clear(); |
239 | name = ""; | 259 | name = ""; |
240 | } | 260 | } |
241 | }; | 261 | }; |
242 | 262 | ||
243 | struct PwMSyncItem | 263 | struct PwMSyncItem |
244 | { | 264 | { |
245 | string syncName; | 265 | string syncName; |
246 | QDateTime lastSyncDate; | 266 | QDateTime lastSyncDate; |
247 | 267 | ||
248 | void clear() | 268 | void clear() |
249 | { | 269 | { |
250 | lastSyncDate = QDateTime(); | 270 | lastSyncDate = QDateTime(); |
251 | syncName = ""; | 271 | syncName = ""; |
252 | } | 272 | } |
253 | }; | 273 | }; |
254 | 274 | ||
255 | struct PwMItem | 275 | struct PwMItem |
256 | { | 276 | { |
257 | vector<PwMCategoryItem> dta; | 277 | vector<PwMCategoryItem> dta; |
258 | vector<PwMSyncItem> syncDta; | 278 | vector<PwMSyncItem> syncDta; |
259 | 279 | ||
260 | void clear() | 280 | void clear() |
261 | { | 281 | { |
262 | dta.clear(); | 282 | dta.clear(); |
263 | syncDta.clear(); | 283 | syncDta.clear(); |
264 | } | 284 | } |
265 | }; | 285 | }; |
266 | 286 | ||
267 | 287 | ||
268 | /** "Function Object" for sort()ing PwMDataItem::listViewPos */ | 288 | /** "Function Object" for sort()ing PwMDataItem::listViewPos */ |
269 | class dta_lvp_greater | 289 | class dta_lvp_greater |
270 | { | 290 | { |
271 | public: | 291 | public: |
272 | bool operator() (const pair<unsigned int, unsigned int> &d1, | 292 | bool operator() (const pair<unsigned int, unsigned int> &d1, |
273 | const pair<unsigned int, unsigned int> &d2) | 293 | const pair<unsigned int, unsigned int> &d2) |
274 | { | 294 | { |
275 | return d1.second > d2.second; | 295 | return d1.second > d2.second; |
276 | } | 296 | } |
277 | }; | 297 | }; |
278 | 298 | ||
279 | /** list of PwMDoc documents and it's IDs */ | 299 | /** list of PwMDoc documents and it's IDs */ |
280 | class PwMDocList | 300 | class PwMDocList |
281 | { | 301 | { |
282 | public: | 302 | public: |
283 | struct listItem | 303 | struct listItem |
284 | { | 304 | { |
285 | /** document filename (known as ID, here) */ | 305 | /** document filename (known as ID, here) */ |
286 | string docId; | 306 | string docId; |
287 | /** pointer to the document class */ | 307 | /** pointer to the document class */ |
288 | PwMDoc *doc; | 308 | PwMDoc *doc; |
289 | }; | 309 | }; |
290 | 310 | ||
291 | PwMDocList() {} | 311 | PwMDocList() {} |
292 | 312 | ||
293 | /** add a new item to the list */ | 313 | /** add a new item to the list */ |
294 | void add(PwMDoc *doc, const string &id); | 314 | void add(PwMDoc *doc, const string &id); |
295 | /** changes the contents of an existing item */ | 315 | /** changes the contents of an existing item */ |
296 | void edit(PwMDoc *doc, const string &newId); | 316 | void edit(PwMDoc *doc, const string &newId); |
297 | /** remove the given item */ | 317 | /** remove the given item */ |
298 | void del(PwMDoc *doc); | 318 | void del(PwMDoc *doc); |
299 | /** get the item at index */ | 319 | /** get the item at index */ |
300 | listItem getAt(int index) | 320 | listItem getAt(int index) |
301 | { return docList[index]; } | 321 | { return docList[index]; } |
302 | /** find an entry with this id */ | 322 | /** find an entry with this id */ |
303 | bool find(const string &id, listItem *ret = 0); | 323 | bool find(const string &id, listItem *ret = 0); |
304 | /** returns a copy of the list */ | 324 | /** returns a copy of the list */ |
305 | const vector<listItem>* getList() const | 325 | const vector<listItem>* getList() const |
306 | { return &docList; } | 326 | { return &docList; } |
307 | 327 | ||
308 | 328 | ||
309 | /** returns a new unique number to extend the name of | 329 | /** returns a new unique number to extend the name of |
310 | * an unnamed document. | 330 | * an unnamed document. |
311 | */ | 331 | */ |
312 | static unsigned int getNewUnnamedNumber() | 332 | static unsigned int getNewUnnamedNumber() |
313 | { return unnamedDocCnt++; } | 333 | { return unnamedDocCnt++; } |
314 | 334 | ||
315 | protected: | 335 | protected: |
316 | /* Hm, I think we shouldn't really use a "list" here, should we? | 336 | /* Hm, I think we shouldn't really use a "list" here, should we? |
317 | * So I decided to actually use a vector. | 337 | * So I decided to actually use a vector. |
318 | */ | 338 | */ |
319 | vector<listItem> docList; | 339 | vector<listItem> docList; |
320 | /** This value is used to get a new number for yet unnamed | 340 | /** This value is used to get a new number for yet unnamed |
321 | * documents. It is incremented on every request. So it's | 341 | * documents. It is incremented on every request. So it's |
322 | * theoretically possible to overflow it, but... :) | 342 | * theoretically possible to overflow it, but... :) |
323 | */ | 343 | */ |
324 | static unsigned int unnamedDocCnt; | 344 | static unsigned int unnamedDocCnt; |
325 | }; | 345 | }; |
326 | 346 | ||
327 | /** implements timers for the document */ | 347 | /** implements timers for the document */ |
328 | class DocTimer : public QObject | 348 | class DocTimer : public QObject |
329 | { | 349 | { |
330 | Q_OBJECT | 350 | Q_OBJECT |
331 | public: | 351 | public: |
332 | enum TimerIDs | 352 | enum TimerIDs |
333 | { | 353 | { |
334 | id_mpwTimer, | 354 | id_mpwTimer, |
335 | id_autoLockTimer, | 355 | id_autoLockTimer, |
336 | id_metaCheckTimer | 356 | id_metaCheckTimer |
337 | }; | 357 | }; |
338 | 358 | ||
339 | public: | 359 | public: |
340 | DocTimer(PwMDoc *_doc); | 360 | DocTimer(PwMDoc *_doc); |
341 | ~DocTimer(); | 361 | ~DocTimer(); |
342 | 362 | ||
343 | /** start the timer */ | 363 | /** start the timer */ |
344 | void start(TimerIDs timer); | 364 | void start(TimerIDs timer); |
345 | /** stop the timer */ | 365 | /** stop the timer */ |
346 | void stop(TimerIDs timer); | 366 | void stop(TimerIDs timer); |
347 | /** get the lock for a timer. | 367 | /** get the lock for a timer. |
348 | * This lock is a recursive lock. When a lock is | 368 | * This lock is a recursive lock. When a lock is |
349 | * held, the timer will be stopped and timeout is | 369 | * held, the timer will be stopped and timeout is |
350 | * guaranteed to not happen | 370 | * guaranteed to not happen |
351 | */ | 371 | */ |
352 | void getLock(TimerIDs timer); | 372 | void getLock(TimerIDs timer); |
353 | /** put a recursive timer lock */ | 373 | /** put a recursive timer lock */ |
354 | void putLock(TimerIDs timer); | 374 | void putLock(TimerIDs timer); |
355 | 375 | ||
356 | protected slots: | 376 | protected slots: |
357 | /** timeout slot for the mpw timer */ | 377 | /** timeout slot for the mpw timer */ |
358 | void mpwTimeout(); | 378 | void mpwTimeout(); |
359 | /** timeout slot for the autoLock timer */ | 379 | /** timeout slot for the autoLock timer */ |
360 | void autoLockTimeout(); | 380 | void autoLockTimeout(); |
361 | /** timeout slot for the metaCheck timer */ | 381 | /** timeout slot for the metaCheck timer */ |
362 | void metaCheckTimeout(); | 382 | void metaCheckTimeout(); |
363 | 383 | ||
364 | protected: | 384 | protected: |
365 | /** pointer to the document associated with this timer. */ | 385 | /** pointer to the document associated with this timer. */ |
366 | PwMDoc *doc; | 386 | PwMDoc *doc; |
367 | /** timer object for mpw timer */ | 387 | /** timer object for mpw timer */ |
368 | QTimer *mpwTimer; | 388 | QTimer *mpwTimer; |
369 | /** timer object for the autoLock timer */ | 389 | /** timer object for the autoLock timer */ |
370 | QTimer *autoLockTimer; | 390 | QTimer *autoLockTimer; |
371 | /** timer object for the metaCheck timer */ | 391 | /** timer object for the metaCheck timer */ |
372 | QTimer *metaCheckTimer; | 392 | QTimer *metaCheckTimer; |
373 | /** lock counter for the mpw timer */ | 393 | /** lock counter for the mpw timer */ |
374 | unsigned int mpwLock; | 394 | unsigned int mpwLock; |
375 | /** lock counter for the autoLock timer */ | 395 | /** lock counter for the autoLock timer */ |
376 | unsigned int autoLockLock; | 396 | unsigned int autoLockLock; |
377 | /** lock counter for the metaCheck timer */ | 397 | /** lock counter for the metaCheck timer */ |
378 | unsigned int metaCheckLock; | 398 | unsigned int metaCheckLock; |
379 | }; | 399 | }; |
380 | 400 | ||
381 | /** Document class for PwM */ | 401 | /** Document class for PwM */ |
382 | //US ENH: derived from KSyncInterfaces, to get called by PwM when a sync is required. | 402 | //US ENH: derived from KSyncInterfaces, to get called by PwM when a sync is required. |
383 | // But PwMDoc is handling the sync by itself. | 403 | // But PwMDoc is handling the sync by itself. |
384 | class PwMDoc : public PwMDocUi, public KSyncInterface | 404 | class PwMDoc : public PwMDocUi, public KSyncInterface |
385 | 405 | ||
386 | { | 406 | { |
387 | Q_OBJECT | 407 | Q_OBJECT |
388 | friend class DocTimer; | 408 | friend class DocTimer; |
389 | 409 | ||
390 | public: | 410 | public: |
391 | /** construtor */ | 411 | /** construtor */ |
392 | PwMDoc(QObject* parent = 0, const char *name = 0); | 412 | PwMDoc(QObject* parent = 0, const char *name = 0); |
393 | /** destructor */ | 413 | /** destructor */ |
394 | ~PwMDoc(); | 414 | ~PwMDoc(); |
395 | 415 | ||
396 | /** returns a pointer to a list of all open documents */ | 416 | /** returns a pointer to a list of all open documents */ |
397 | static PwMDocList* getOpenDocList() | 417 | static PwMDocList* getOpenDocList() |
398 | { return &openDocList; } | 418 | { return &openDocList; } |
399 | 419 | ||
400 | /** flag document dirty. dta changed */ | 420 | /** flag document dirty. dta changed */ |
401 | void flagDirty() | 421 | void flagDirty() |
402 | { | 422 | { |
403 | setDocStatFlag(DOC_STAT_DISK_DIRTY); | 423 | setDocStatFlag(DOC_STAT_DISK_DIRTY); |
404 | emitDataChanged(this); | 424 | emitDataChanged(this); |
405 | } | 425 | } |
406 | /** modified? */ | 426 | /** modified? */ |
407 | bool isDirty() | 427 | bool isDirty() |
408 | { return getDocStatFlag(DOC_STAT_DISK_DIRTY); } | 428 | { return getDocStatFlag(DOC_STAT_DISK_DIRTY); } |
409 | /** save document to disk */ | 429 | /** save document to disk */ |
410 | PwMerror saveDoc(char compress, const QString *file = 0); | 430 | PwMerror saveDoc(char compress, const QString *file = 0); |
411 | /** read document from file. | 431 | /** read document from file. |
412 | * "openLocked is must be set to either of these values: | 432 | * "openLocked is must be set to either of these values: |
413 | * 0 == open with all entries unlocked | 433 | * 0 == open with all entries unlocked |
414 | * 1 == open with all entries locked | 434 | * 1 == open with all entries locked |
415 | * 2 == open deep-locked | 435 | * 2 == open deep-locked |
416 | */ | 436 | */ |
417 | PwMerror openDoc(const QString *file, int openLocked); | 437 | PwMerror openDoc(const QString *file, int openLocked); |
418 | /** export document to ascii-textfile */ | 438 | /** export document to ascii-textfile */ |
419 | PwMerror exportToText(const QString *file); | 439 | PwMerror exportToText(const QString *file); |
420 | /** export document to gpasman / kpasman file */ | 440 | /** export document to gpasman / kpasman file */ |
421 | PwMerror exportToGpasman(const QString *file); | 441 | PwMerror exportToGpasman(const QString *file); |
422 | /** import document from ascii-textfile */ | 442 | /** import document from ascii-textfile */ |
423 | PwMerror importFromText(const QString *file, int format = -1); | 443 | PwMerror importFromText(const QString *file, int format = -1); |
424 | /** import document from gpasman / kpasman file */ | 444 | /** import document from gpasman / kpasman file */ |
425 | PwMerror importFromGpasman(const QString *file); | 445 | PwMerror importFromGpasman(const QString *file); |
426 | /** add new entry */ | 446 | /** add new entry */ |
427 | PwMerror addEntry(const QString &category, PwMDataItem *d, | 447 | PwMerror addEntry(const QString &category, PwMDataItem *d, |
428 | bool dontFlagDirty = false, bool updateMeta = true); | 448 | bool dontFlagDirty = false, bool updateMeta = true); |
429 | /** add new category. This function doesn't flag the document dirty! */ | 449 | /** add new category. This function doesn't flag the document dirty! */ |
430 | PwMerror addCategory(const QString &category, unsigned int *categoryIndex, | 450 | PwMerror addCategory(const QString &category, unsigned int *categoryIndex, |
431 | bool checkIfExist = true); | 451 | bool checkIfExist = true); |
432 | /** rename an existing category */ | 452 | /** rename an existing category */ |
433 | bool renameCategory(const QString &category, const QString &newName); | 453 | bool renameCategory(const QString &category, const QString &newName); |
434 | /** rename an existing category */ | 454 | /** rename an existing category */ |
435 | bool renameCategory(unsigned int category, const QString &newName, | 455 | bool renameCategory(unsigned int category, const QString &newName, |
436 | bool dontFlagDirty = false); | 456 | bool dontFlagDirty = false); |
437 | /** delete an existing category */ | 457 | /** delete an existing category */ |
438 | bool delCategory(const QString &category); | 458 | bool delCategory(const QString &category); |
439 | /** delete an existing category */ | 459 | /** delete an existing category */ |
440 | bool delCategory(unsigned int category, bool dontFlagDirty = false); | 460 | bool delCategory(unsigned int category, bool dontFlagDirty = false); |
441 | /** returns a list of all category-names */ | 461 | /** returns a list of all category-names */ |
442 | void getCategoryList(vector<string> *list); | 462 | void getCategoryList(vector<string> *list); |
443 | /** returns a list of all category-names */ | 463 | /** returns a list of all category-names */ |
444 | void getCategoryList(QStringList *list); | 464 | void getCategoryList(QStringList *list); |
445 | /** returns a list of all entry-descs in the given category */ | 465 | /** returns a list of all entry-descs in the given category */ |
446 | void getEntryList(const QString &category, QStringList *list); | 466 | void getEntryList(const QString &category, QStringList *list); |
447 | /** returns a list of all entry-descs in the given category */ | 467 | /** returns a list of all entry-descs in the given category */ |
448 | void getEntryList(const QString &category, vector<string> *list); | 468 | void getEntryList(const QString &category, vector<string> *list); |
449 | /** returns a list of all entry-descs in the given category */ | 469 | /** returns a list of all entry-descs in the given category */ |
450 | void getEntryList(unsigned int category, vector<string> *list); | 470 | void getEntryList(unsigned int category, vector<string> *list); |
451 | /** returns a list of all entry-descs in the given category */ | 471 | /** returns a list of all entry-descs in the given category */ |
452 | void getEntryList(unsigned int category, QStringList *list); | 472 | void getEntryList(unsigned int category, QStringList *list); |
453 | /** delete entry */ | 473 | /** delete entry */ |
454 | bool delEntry(const QString &category, unsigned int index, bool dontFlagDirty = false); | 474 | bool delEntry(const QString &category, unsigned int index, bool dontFlagDirty = false); |
455 | /** delete entry */ | 475 | /** delete entry */ |
456 | bool delEntry(unsigned int category, unsigned int index, bool dontFlagDirty = false); | 476 | bool delEntry(unsigned int category, unsigned int index, bool dontFlagDirty = false); |
457 | /** edit entry */ | 477 | /** edit entry */ |
458 | bool editEntry(const QString &oldCategory, const QString &newCategory, | 478 | bool editEntry(const QString &oldCategory, const QString &newCategory, |
459 | unsigned int index, PwMDataItem *d, bool updateMeta = true); | 479 | unsigned int index, PwMDataItem *d, bool updateMeta = true); |
460 | /** edit entry */ | 480 | /** edit entry */ |
461 | bool editEntry(unsigned int oldCategory, const QString &newCategory, | 481 | bool editEntry(unsigned int oldCategory, const QString &newCategory, |
462 | unsigned int index, PwMDataItem *d, bool updateMeta = true); | 482 | unsigned int index, PwMDataItem *d, bool updateMeta = true); |
463 | /** finds the category with the "name" and return it's index */ | 483 | /** finds the category with the "name" and return it's index */ |
464 | bool findCategory(const QString &name, unsigned int *index); | 484 | bool findCategory(const QString &name, unsigned int *index); |
465 | /** search for an entry "find" and check while searching only for | 485 | /** search for an entry "find" and check while searching only for |
466 | * the data-fields specified by "searchIn". To set the "searchIn" | 486 | * the data-fields specified by "searchIn". To set the "searchIn" |
467 | * value, we may use one or more of the SEARCH_IN_* defines at | 487 | * value, we may use one or more of the SEARCH_IN_* defines at |
468 | * the top of this header-file. It returns the positions of all | 488 | * the top of this header-file. It returns the positions of all |
469 | * matched entries in "foundPositions". If "breakAfterFound" is true, | 489 | * matched entries in "foundPositions". If "breakAfterFound" is true, |
470 | * the function terminates after the first occurence of the entry | 490 | * the function terminates after the first occurence of the entry |
471 | * and doesn't go on searching. So foundPositions->size() is never | 491 | * and doesn't go on searching. So foundPositions->size() is never |
472 | * > 1 if breakAfterFound is true. | 492 | * > 1 if breakAfterFound is true. |
473 | */ | 493 | */ |
474 | void findEntry(unsigned int category, PwMDataItem find, unsigned int searchIn, | 494 | void findEntry(unsigned int category, PwMDataItem find, unsigned int searchIn, |
475 | vector<unsigned int> *foundPositions, bool breakAfterFound = false, | 495 | vector<unsigned int> *foundPositions, bool breakAfterFound = false, |
476 | bool caseSensitive = true, bool exactWordMatch = true, | 496 | bool caseSensitive = true, bool exactWordMatch = true, |
477 | bool sortByLvp = false); | 497 | bool sortByLvp = false); |
478 | /** see the above funtion. This function allows to set the category by name. */ | 498 | /** see the above funtion. This function allows to set the category by name. */ |
479 | void findEntry(const QString &category, PwMDataItem find, unsigned int searchIn, | 499 | void findEntry(const QString &category, PwMDataItem find, unsigned int searchIn, |
480 | vector<unsigned int> *foundPositions, bool breakAfterFound = false, | 500 | vector<unsigned int> *foundPositions, bool breakAfterFound = false, |
481 | bool caseSensitive = true, bool exactWordMatch = true, | 501 | bool caseSensitive = true, bool exactWordMatch = true, |
482 | bool sortByLvp = false); | 502 | bool sortByLvp = false); |
483 | /** returns number of entries */ | 503 | /** returns number of entries */ |
484 | unsigned int numEntries(const QString &category); | 504 | unsigned int numEntries(const QString &category); |
485 | unsigned int numEntries(unsigned int category) | 505 | unsigned int numEntries(unsigned int category) |
486 | { return dti.dta[category].d.size(); } | 506 | { return dti.dta[category].d.size(); } |
487 | /** returns number of categories */ | 507 | /** returns number of categories */ |
488 | unsigned int numCategories() | 508 | unsigned int numCategories() |
489 | { return dti.dta.size(); } | 509 | { return dti.dta.size(); } |
490 | /** returns the name of the category at "index" */ | 510 | /** returns the name of the category at "index" */ |
491 | const string* getCategory(unsigned int index) | 511 | const string* getCategory(unsigned int index) |
492 | { return (&(dti.dta[index].name)); } | 512 | { return (&(dti.dta[index].name)); } |
493 | 513 | ||
494 | /** returns the data of item at "index". | 514 | /** returns the data of item at "index". |
495 | * It unlocks the entry if it's locked and unlockIfLocked is true. | 515 | * It unlocks the entry if it's locked and unlockIfLocked is true. |
496 | * If the entry is locked, but unlockIfLocked is false, it'll not return | 516 | * If the entry is locked, but unlockIfLocked is false, it'll not return |
497 | * the pw. | 517 | * the pw. |
498 | */ | 518 | */ |
499 | bool getEntry(const QString &category, unsigned int index, | 519 | bool getEntry(const QString &category, unsigned int index, |
500 | PwMDataItem *d, bool unlockIfLocked = false); | 520 | PwMDataItem *d, bool unlockIfLocked = false); |
501 | bool getEntry(unsigned int category, unsigned int index, | 521 | bool getEntry(unsigned int category, unsigned int index, |
502 | PwMDataItem *d, bool unlockIfLocked = false); | 522 | PwMDataItem *d, bool unlockIfLocked = false); |
503 | /** returns the comment-string by looking at the category | 523 | /** returns the comment-string by looking at the category |
504 | * and the listViewPos | 524 | * and the listViewPos |
505 | */ | 525 | */ |
506 | PwMerror getCommentByLvp(const QString &category, int listViewPos, | 526 | PwMerror getCommentByLvp(const QString &category, int listViewPos, |
507 | string *foundComment); | 527 | string *foundComment); |
508 | /** checks if a password is already available. (currentPw) */ | 528 | /** checks if a password is already available. (currentPw) */ |
509 | bool isPwAvailable() | 529 | bool isPwAvailable() |
510 | { return (currentPw != ""); } | 530 | { return (currentPw != ""); } |
511 | /** un/lock entry at "index". If needed, ask for password. */ | 531 | /** un/lock entry at "index". If needed, ask for password. */ |
512 | bool lockAt(const QString &category, unsigned int index, | 532 | bool lockAt(const QString &category, unsigned int index, |
513 | bool lock = true); | 533 | bool lock = true); |
514 | bool lockAt(unsigned int category, unsigned int index, | 534 | bool lockAt(unsigned int category, unsigned int index, |
515 | bool lock = true); | 535 | bool lock = true); |
516 | /** returns the lock-status at "index" */ | 536 | /** returns the lock-status at "index" */ |
517 | bool isLocked(const QString &category, unsigned int index); | 537 | bool isLocked(const QString &category, unsigned int index); |
518 | bool isLocked(unsigned int category, unsigned int index) | 538 | bool isLocked(unsigned int category, unsigned int index) |
519 | { return dti.dta[category].d[index].lockStat; } | 539 | { return dti.dta[category].d[index].lockStat; } |
520 | /** returns the deeplock status */ | 540 | /** returns the deeplock status */ |
521 | bool isDeepLocked() | 541 | bool isDeepLocked() |
522 | { return getDocStatFlag(DOC_STAT_DEEPLOCKED); } | 542 | { return getDocStatFlag(DOC_STAT_DEEPLOCKED); } |
523 | /** (un)lock all entries */ | 543 | /** (un)lock all entries */ |
524 | bool lockAll(bool lock); | 544 | bool lockAll(bool lock); |
525 | /** unlocks all entries tempoarly. | 545 | /** unlocks all entries tempoarly. |
526 | * 1st NOTE: Be very careful with this function! :) | 546 | * 1st NOTE: Be very careful with this function! :) |
527 | * 2nd NOTE: After you have called unlockAll_Tempoary(); , | 547 | * 2nd NOTE: After you have called unlockAll_Tempoary(); , |
528 | * please DON'T forget to call unlockAll_Tempoary(true); | 548 | * please DON'T forget to call unlockAll_Tempoary(true); |
529 | * _before_ the user (or someone else) is able to change | 549 | * _before_ the user (or someone else) is able to change |
530 | * the document! | 550 | * the document! |
531 | * 3rd NOTE: Please DON'T change "dta" while the data is tempoary | 551 | * 3rd NOTE: Please DON'T change "dta" while the data is tempoary |
532 | * unlocked! This will cause corruption. | 552 | * unlocked! This will cause corruption. |
533 | */ | 553 | */ |
534 | bool unlockAll_tempoary(bool revert = false); | 554 | bool unlockAll_tempoary(bool revert = false); |
535 | /** deep-(un)locks the document. | 555 | /** deep-(un)locks the document. |
536 | * deep-locking writes all data to the file, deletes all data | 556 | * deep-locking writes all data to the file, deletes all data |
537 | * in memory, but doesn't close the document. | 557 | * in memory, but doesn't close the document. |
538 | * deep-locking is only available, if the user previously saved | 558 | * deep-locking is only available, if the user previously saved |
539 | * the doc to a file (with a password). | 559 | * the doc to a file (with a password). |
540 | * If "saveToFile" is false, it does NOT write the data to the file! | 560 | * If "saveToFile" is false, it does NOT write the data to the file! |
541 | */ | 561 | */ |
542 | PwMerror deepLock(bool lock = true, bool saveToFile = true); | 562 | PwMerror deepLock(bool lock = true, bool saveToFile = true); |
543 | /** is unlockable without pw? */ | 563 | /** is unlockable without pw? */ |
544 | bool unlockWoPw() | 564 | bool unlockWoPw() |
545 | { return getDocStatFlag(DOC_STAT_UNLOCK_WITHOUT_PW); } | 565 | { return getDocStatFlag(DOC_STAT_UNLOCK_WITHOUT_PW); } |
546 | /** get the "currentPassword" */ | 566 | /** get the "currentPassword" */ |
547 | const QString& getCurrentPw() | 567 | const QString& getCurrentPw() |
548 | { return currentPw; } | 568 | { return currentPw; } |
549 | /** open a window and request the user to change the mpw */ | 569 | /** open a window and request the user to change the mpw */ |
550 | void changeCurrentPw(); | 570 | void changeCurrentPw(); |
551 | /** set the "listViewPos" variable of "dta" */ | 571 | /** set the "listViewPos" variable of "dta" */ |
552 | void setListViewPos(const QString &category, unsigned int index, | 572 | void setListViewPos(const QString &category, unsigned int index, |
553 | int pos); | 573 | int pos); |
554 | /** set the "listViewPos" variable of "dta" */ | 574 | /** set the "listViewPos" variable of "dta" */ |
555 | void setListViewPos(unsigned int category, unsigned int index, | 575 | void setListViewPos(unsigned int category, unsigned int index, |
556 | int pos); | 576 | int pos); |
557 | /** get the "listViewPos" variable of "dta" */ | 577 | /** get the "listViewPos" variable of "dta" */ |
558 | int getListViewPos(const QString &category, unsigned int index); | 578 | int getListViewPos(const QString &category, unsigned int index); |
559 | /** set the maximum number of entries allowed */ | 579 | /** set the maximum number of entries allowed */ |
560 | void setMaxNumEntries(unsigned int num = DEFAULT_MAX_ENTRIES) | 580 | void setMaxNumEntries(unsigned int num = DEFAULT_MAX_ENTRIES) |
561 | { maxEntries = num; } | 581 | { maxEntries = num; } |
562 | /** get the maximum number of entries allowed */ | 582 | /** get the maximum number of entries allowed */ |
563 | unsigned int getMaxNumEntries() | 583 | unsigned int getMaxNumEntries() |
564 | { return maxEntries; } | 584 | { return maxEntries; } |
565 | /** ensure all listViewPos of all dta items are set. (are ! -1). | 585 | /** ensure all listViewPos of all dta items are set. (are ! -1). |
566 | * If there are some undefined entries, add them to the end of | 586 | * If there are some undefined entries, add them to the end of |
567 | * the listViewPos(itions). */ | 587 | * the listViewPos(itions). */ |
568 | void ensureLvp(); | 588 | void ensureLvp(); |
569 | /** execute the "launcher" of this entry */ | 589 | /** execute the "launcher" of this entry */ |
570 | bool execLauncher(const QString &category, unsigned int entryIndex); | 590 | bool execLauncher(const QString &category, unsigned int entryIndex); |
571 | /** see above */ | 591 | /** see above */ |
572 | bool execLauncher(unsigned int category, unsigned int entryIndex); | 592 | bool execLauncher(unsigned int category, unsigned int entryIndex); |
573 | /** open a browser with the URL-section of the given entry */ | 593 | /** open a browser with the URL-section of the given entry */ |
574 | bool goToURL(const QString &category, unsigned int entryIndex); | 594 | bool goToURL(const QString &category, unsigned int entryIndex); |
575 | /** see above */ | 595 | /** see above */ |
576 | bool goToURL(unsigned int category, unsigned int entryIndex); | 596 | bool goToURL(unsigned int category, unsigned int entryIndex); |
577 | /** returns true if there is no entry present in the document. | 597 | /** returns true if there is no entry present in the document. |
578 | * Note: The "default" Category is present everytime, so | 598 | * Note: The "default" Category is present everytime, so |
579 | * it's checked for it's entries. | 599 | * it's checked for it's entries. |
580 | */ | 600 | */ |
581 | bool isDocEmpty() | 601 | bool isDocEmpty() |
582 | { | 602 | { |
583 | if (numCategories() > 1) | 603 | if (numCategories() > 1) |
584 | return false; | 604 | return false; |
585 | if (numEntries(0)) | 605 | if (numEntries(0)) |
586 | return false; | 606 | return false; |
587 | return true; | 607 | return true; |
588 | } | 608 | } |
589 | /** returns the filename of this doc */ | 609 | /** returns the filename of this doc */ |
590 | const QString& getFilename() | 610 | const QString& getFilename() |
591 | { return filename; } | 611 | { return filename; } |
592 | /** returns the title of the doc */ | 612 | /** returns the title of the doc */ |
593 | QString getTitle(); | 613 | QString getTitle(); |
594 | /** sets the list-view-pointer hold in the doc */ | 614 | /** sets the list-view-pointer hold in the doc */ |
595 | void setListViewPointer(PwMView *_listView) | 615 | void setListViewPointer(PwMView *_listView) |
596 | { listView = _listView; } | 616 | { listView = _listView; } |
597 | /** returns the list-view-pointer */ | 617 | /** returns the list-view-pointer */ |
598 | PwMView * getListViewPointer() | 618 | PwMView * getListViewPointer() |
599 | { return listView; } | 619 | { return listView; } |
600 | /** try to delete the doc. The user may be asked to save | 620 | /** try to delete the doc. The user may be asked to save |
601 | * the data. The user may cancel the whole operation. | 621 | * the data. The user may cancel the whole operation. |
602 | * false is returned, then. | 622 | * false is returned, then. |
603 | */ | 623 | */ |
604 | bool tryDelete(); | 624 | bool tryDelete(); |
605 | /** is the doc deleted? (with tryDelete() ) */ | 625 | /** is the doc deleted? (with tryDelete() ) */ |
606 | bool isDeleted() | 626 | bool isDeleted() |
607 | { return deleted; } | 627 | { return deleted; } |
608 | /** returns the document timer object */ | 628 | /** returns the document timer object */ |
609 | DocTimer * timer() | 629 | DocTimer * timer() |
610 | { return _timer; } | 630 | { return _timer; } |