author | ulf69 <ulf69> | 2004-10-08 00:24:58 (UTC) |
---|---|---|
committer | ulf69 <ulf69> | 2004-10-08 00:24:58 (UTC) |
commit | 309df8e8df3a17602f948025b7951b21ec5c3fed (patch) (unidiff) | |
tree | f1b504be724510bd8d49b106cd1b98e09187c547 | |
parent | 91e43b55a0ddf6a6f39f4ed3ae828ddad6ec89a5 (diff) | |
download | kdepimpi-309df8e8df3a17602f948025b7951b21ec5c3fed.zip kdepimpi-309df8e8df3a17602f948025b7951b21ec5c3fed.tar.gz kdepimpi-309df8e8df3a17602f948025b7951b21ec5c3fed.tar.bz2 |
*** empty log message ***
-rw-r--r-- | pwmanager/pwmanager/pwmdoc.cpp | 36 | ||||
-rw-r--r-- | pwmanager/pwmanager/pwmdoc.h | 38 | ||||
-rw-r--r-- | pwmanager/pwmanager/serializer.cpp | 2 |
3 files changed, 58 insertions, 18 deletions
diff --git a/pwmanager/pwmanager/pwmdoc.cpp b/pwmanager/pwmanager/pwmdoc.cpp index 76a45f4..ab3238a 100644 --- a/pwmanager/pwmanager/pwmdoc.cpp +++ b/pwmanager/pwmanager/pwmdoc.cpp | |||
@@ -2706,380 +2706,392 @@ void PwMDoc::ensureLvp() | |||
2706 | return; | 2706 | return; |
2707 | 2707 | ||
2708 | vector< vector<PwMDataItem>::iterator > undefined; | 2708 | vector< vector<PwMDataItem>::iterator > undefined; |
2709 | vector< vector<PwMDataItem>::iterator >::iterator undefBegin, | 2709 | vector< vector<PwMDataItem>::iterator >::iterator undefBegin, |
2710 | undefEnd, | 2710 | undefEnd, |
2711 | undefI; | 2711 | undefI; |
2712 | vector<PwMCategoryItem>::iterator catBegin = dti.dta.begin(), | 2712 | vector<PwMCategoryItem>::iterator catBegin = dti.dta.begin(), |
2713 | catEnd = dti.dta.end(), | 2713 | catEnd = dti.dta.end(), |
2714 | catI = catBegin; | 2714 | catI = catBegin; |
2715 | vector<PwMDataItem>::iterator entrBegin, entrEnd, entrI; | 2715 | vector<PwMDataItem>::iterator entrBegin, entrEnd, entrI; |
2716 | int lvpTop, tmpLvp; | 2716 | int lvpTop, tmpLvp; |
2717 | 2717 | ||
2718 | while (catI != catEnd) { | 2718 | while (catI != catEnd) { |
2719 | lvpTop = -1; | 2719 | lvpTop = -1; |
2720 | undefined.clear(); | 2720 | undefined.clear(); |
2721 | 2721 | ||
2722 | entrBegin = catI->d.begin(); | 2722 | entrBegin = catI->d.begin(); |
2723 | entrEnd = catI->d.end(); | 2723 | entrEnd = catI->d.end(); |
2724 | entrI = entrBegin; | 2724 | entrI = entrBegin; |
2725 | 2725 | ||
2726 | while (entrI != entrEnd) { | 2726 | while (entrI != entrEnd) { |
2727 | tmpLvp = entrI->listViewPos; | 2727 | tmpLvp = entrI->listViewPos; |
2728 | if (tmpLvp == -1) | 2728 | if (tmpLvp == -1) |
2729 | undefined.push_back(entrI); | 2729 | undefined.push_back(entrI); |
2730 | else if (tmpLvp > lvpTop) | 2730 | else if (tmpLvp > lvpTop) |
2731 | lvpTop = tmpLvp; | 2731 | lvpTop = tmpLvp; |
2732 | ++entrI; | 2732 | ++entrI; |
2733 | } | 2733 | } |
2734 | undefBegin = undefined.begin(); | 2734 | undefBegin = undefined.begin(); |
2735 | undefEnd = undefined.end(); | 2735 | undefEnd = undefined.end(); |
2736 | undefI = undefBegin; | 2736 | undefI = undefBegin; |
2737 | while (undefI != undefEnd) { | 2737 | while (undefI != undefEnd) { |
2738 | (*undefI)->listViewPos = ++lvpTop; | 2738 | (*undefI)->listViewPos = ++lvpTop; |
2739 | ++undefI; | 2739 | ++undefI; |
2740 | } | 2740 | } |
2741 | ++catI; | 2741 | ++catI; |
2742 | } | 2742 | } |
2743 | } | 2743 | } |
2744 | 2744 | ||
2745 | QString PwMDoc::getTitle() | 2745 | QString PwMDoc::getTitle() |
2746 | { | 2746 | { |
2747 | /* NOTE: We have to ensure, that the returned title | 2747 | /* NOTE: We have to ensure, that the returned title |
2748 | * is unique and not reused somewhere else while | 2748 | * is unique and not reused somewhere else while |
2749 | * this document is valid (open). | 2749 | * this document is valid (open). |
2750 | */ | 2750 | */ |
2751 | QString title(getFilename()); | 2751 | QString title(getFilename()); |
2752 | if (title.isEmpty()) { | 2752 | if (title.isEmpty()) { |
2753 | if (unnamedNum == 0) { | 2753 | if (unnamedNum == 0) { |
2754 | unnamedNum = PwMDocList::getNewUnnamedNumber(); | 2754 | unnamedNum = PwMDocList::getNewUnnamedNumber(); |
2755 | PWM_ASSERT(unnamedNum != 0); | 2755 | PWM_ASSERT(unnamedNum != 0); |
2756 | } | 2756 | } |
2757 | title = DEFAULT_TITLE; | 2757 | title = DEFAULT_TITLE; |
2758 | title += " "; | 2758 | title += " "; |
2759 | title += tostr(unnamedNum).c_str(); | 2759 | title += tostr(unnamedNum).c_str(); |
2760 | } | 2760 | } |
2761 | return title; | 2761 | return title; |
2762 | } | 2762 | } |
2763 | 2763 | ||
2764 | bool PwMDoc::tryDelete() | 2764 | bool PwMDoc::tryDelete() |
2765 | { | 2765 | { |
2766 | if (deleted) | 2766 | if (deleted) |
2767 | return true; | 2767 | return true; |
2768 | int ret; | 2768 | int ret; |
2769 | if (isDirty()) { | 2769 | if (isDirty()) { |
2770 | ret = dirtyAskSave(getTitle()); | 2770 | ret = dirtyAskSave(getTitle()); |
2771 | if (ret == 0) { // save to disk | 2771 | if (ret == 0) { // save to disk |
2772 | if (!saveDocUi(this)) | 2772 | if (!saveDocUi(this)) |
2773 | goto out_ignore; | 2773 | goto out_ignore; |
2774 | } else if (ret == 1) { // don't save and delete | 2774 | } else if (ret == 1) { // don't save and delete |
2775 | goto out_accept; | 2775 | goto out_accept; |
2776 | } else { // cancel operation | 2776 | } else { // cancel operation |
2777 | goto out_ignore; | 2777 | goto out_ignore; |
2778 | } | 2778 | } |
2779 | } | 2779 | } |
2780 | out_accept: | 2780 | out_accept: |
2781 | deleted = true; | 2781 | deleted = true; |
2782 | delete this; | 2782 | delete this; |
2783 | return true; | 2783 | return true; |
2784 | out_ignore: | 2784 | out_ignore: |
2785 | return false; | 2785 | return false; |
2786 | } | 2786 | } |
2787 | 2787 | ||
2788 | 2788 | ||
2789 | 2789 | ||
2790 | #ifdef PWM_EMBEDDED | 2790 | #ifdef PWM_EMBEDDED |
2791 | //US ENH: this is the magic function that syncronizes the this doc with the remote doc | 2791 | //US ENH: this is the magic function that syncronizes the this doc with the remote doc |
2792 | //US it could have been defined as static, but I did not want to. | 2792 | //US it could have been defined as static, but I did not want to. |
2793 | PwMerror PwMDoc::syncronize(KSyncManager* manager, PwMDoc* syncLocal , PwMDoc* syncRemote, int mode ) | 2793 | PwMerror PwMDoc::syncronize(KSyncManager* manager, PwMDoc* syncLocal , PwMDoc* syncRemote, int mode ) |
2794 | { | 2794 | { |
2795 | int addedPasswordsLocal = 0; | 2795 | int addedPasswordsLocal = 0; |
2796 | int addedPasswordsRemote = 0; | 2796 | int addedPasswordsRemote = 0; |
2797 | int deletedPasswordsRemote = 0; | 2797 | int deletedPasswordsRemote = 0; |
2798 | int deletedPasswordsLocal = 0; | 2798 | int deletedPasswordsLocal = 0; |
2799 | int changedLocal = 0; | 2799 | int changedLocal = 0; |
2800 | int changedRemote = 0; | 2800 | int changedRemote = 0; |
2801 | 2801 | ||
2802 | PwMSyncItem* syncItemLocal; | 2802 | PwMSyncItem syncItemLocal; |
2803 | PwMSyncItem* syncItemRemote; | 2803 | PwMSyncItem syncItemRemote; |
2804 | 2804 | ||
2805 | QString mCurrentSyncName = manager->getCurrentSyncName(); | 2805 | QString mCurrentSyncName = manager->getCurrentSyncName(); |
2806 | QString mCurrentSyncDevice = manager->getCurrentSyncDevice(); | 2806 | QString mCurrentSyncDevice = manager->getCurrentSyncDevice(); |
2807 | 2807 | ||
2808 | bool fullDateRange = false; | 2808 | bool fullDateRange = false; |
2809 | int take; | 2809 | int take; |
2810 | // local->resetTempSyncStat(); | 2810 | // local->resetTempSyncStat(); |
2811 | QDateTime mLastSync = QDateTime::currentDateTime(); | 2811 | QDateTime mLastSync = QDateTime::currentDateTime(); |
2812 | QDateTime modifiedSync = mLastSync; | 2812 | QDateTime modifiedSync = mLastSync; |
2813 | 2813 | ||
2814 | unsigned int index; | 2814 | unsigned int index; |
2815 | //Step 1. Find syncinfo in Local file and create if not existent. | 2815 | //Step 1. Find syncinfo in Local file and create if not existent. |
2816 | bool found = syncLocal->findSyncData(mCurrentSyncDevice, &index); | 2816 | bool found = syncLocal->findSyncData(mCurrentSyncDevice, &index); |
2817 | if (found == false) | 2817 | if (found == false) |
2818 | { | 2818 | { |
2819 | PwMSyncItem newSyncItemLocal; | 2819 | PwMSyncItem newSyncItemLocal; |
2820 | newSyncItemLocal.syncName = mCurrentSyncDevice; | 2820 | newSyncItemLocal.syncName = mCurrentSyncDevice; |
2821 | newSyncItemLocal.lastSyncDate = mLastSync; | 2821 | newSyncItemLocal.lastSyncDate = mLastSync; |
2822 | syncLocal->addSyncDataEntry(&newSyncItemLocal, true); | 2822 | syncLocal->addSyncDataEntry(&newSyncItemLocal, true); |
2823 | found = syncLocal->findSyncData(mCurrentSyncDevice, &index); | 2823 | found = syncLocal->findSyncData(mCurrentSyncDevice, &index); |
2824 | if (found == false) { | 2824 | if (found == false) { |
2825 | qDebug("PwMDoc::syncronize : newly created local sync data could not be found"); | 2825 | qDebug("PwMDoc::syncronize : newly created local sync data could not be found"); |
2826 | return e_syncError; | 2826 | return e_syncError; |
2827 | } | 2827 | } |
2828 | } | 2828 | } |
2829 | 2829 | ||
2830 | syncItemLocal = syncLocal->getSyncDataEntry(index); | 2830 | syncItemLocal = syncLocal->getSyncDataEntry(index); |
2831 | qDebug("Last Sync %s ", syncItemLocal->lastSyncDate.toString().latin1()); | 2831 | qDebug("Last Sync %s ", syncItemLocal.lastSyncDate.toString().latin1()); |
2832 | 2832 | ||
2833 | //Step 2. Find syncinfo in remote file and create if not existent. | 2833 | //Step 2. Find syncinfo in remote file and create if not existent. |
2834 | found = syncRemote->findSyncData(mCurrentSyncName, &index); | 2834 | found = syncRemote->findSyncData(mCurrentSyncName, &index); |
2835 | if (found == false) | 2835 | if (found == false) |
2836 | { | 2836 | { |
2837 | qDebug("FULLDATE 1"); | 2837 | qDebug("FULLDATE 1"); |
2838 | fullDateRange = true; | 2838 | fullDateRange = true; |
2839 | PwMSyncItem newSyncItemRemote; | 2839 | PwMSyncItem newSyncItemRemote; |
2840 | newSyncItemRemote.syncName = mCurrentSyncName; | 2840 | newSyncItemRemote.syncName = mCurrentSyncName; |
2841 | newSyncItemRemote.lastSyncDate = mLastSync; | 2841 | newSyncItemRemote.lastSyncDate = mLastSync; |
2842 | syncRemote->addSyncDataEntry(&newSyncItemRemote, true); | 2842 | syncRemote->addSyncDataEntry(&newSyncItemRemote, true); |
2843 | found = syncRemote->findSyncData(mCurrentSyncName, &index); | 2843 | found = syncRemote->findSyncData(mCurrentSyncName, &index); |
2844 | if (found == false) { | 2844 | if (found == false) { |
2845 | qDebug("PwMDoc::syncronize : newly created remote sync data could not be found"); | 2845 | qDebug("PwMDoc::syncronize : newly created remote sync data could not be found"); |
2846 | return e_syncError; | 2846 | return e_syncError; |
2847 | } | 2847 | } |
2848 | } | 2848 | } |
2849 | 2849 | ||
2850 | syncItemRemote = syncRemote->getSyncDataEntry(index); | 2850 | syncItemRemote = syncRemote->getSyncDataEntry(index); |
2851 | //and remove the found entry here. We will reenter it later again. | 2851 | //and remove the found entry here. We will reenter it later again. |
2852 | syncRemote->delSyncDataEntry(index, true); | 2852 | syncRemote->delSyncDataEntry(index, true); |
2853 | 2853 | ||
2854 | 2854 | ||
2855 | if ( syncItemLocal->lastSyncDate == mLastSync ) { | 2855 | if ( syncItemLocal.lastSyncDate == mLastSync ) { |
2856 | qDebug("FULLDATE 2"); | 2856 | qDebug("FULLDATE 2"); |
2857 | fullDateRange = true; | 2857 | fullDateRange = true; |
2858 | } | 2858 | } |
2859 | 2859 | ||
2860 | if ( ! fullDateRange ) { | 2860 | if ( ! fullDateRange ) { |
2861 | if ( syncItemLocal->lastSyncDate != syncItemRemote->lastSyncDate ) { | 2861 | if ( syncItemLocal.lastSyncDate != syncItemRemote->lastSyncDate ) { |
2862 | 2862 | ||
2863 | // qDebug("set fulldate to true %s %s" ,addresseeLSync->dtStart().toString().latin1(), addresseeRSync->dtStart().toString().latin1() ); | 2863 | // qDebug("set fulldate to true %s %s" ,addresseeLSync->dtStart().toString().latin1(), addresseeRSync->dtStart().toString().latin1() ); |
2864 | //qDebug("%d %d %d %d ", addresseeLSync->dtStart().time().second(), addresseeLSync->dtStart().time().msec() , addresseeRSync->dtStart().time().second(), addresseeRSync->dtStart().time().msec()); | 2864 | //qDebug("%d %d %d %d ", addresseeLSync->dtStart().time().second(), addresseeLSync->dtStart().time().msec() , addresseeRSync->dtStart().time().second(), addresseeRSync->dtStart().time().msec()); |
2865 | fullDateRange = true; | 2865 | fullDateRange = true; |
2866 | qDebug("FULLDATE 3 %s %s", syncItemLocal->lastSyncDate.toString().latin1() , syncItemRemote->lastSyncDate.toString().latin1() ); | 2866 | qDebug("FULLDATE 3 %s %s", syncItemLocal.lastSyncDate.toString().latin1() , syncItemRemote.lastSyncDate.toString().latin1() ); |
2867 | } | 2867 | } |
2868 | } | 2868 | } |
2869 | // fullDateRange = true; // debug only! | 2869 | // fullDateRange = true; // debug only! |
2870 | if ( fullDateRange ) | 2870 | if ( fullDateRange ) |
2871 | mLastSync = QDateTime::currentDateTime().addDays( -100*365); | 2871 | mLastSync = QDateTime::currentDateTime().addDays( -100*365); |
2872 | else | 2872 | else |
2873 | mLastSync = syncItemLocal->lastSyncDate; | 2873 | mLastSync = syncItemLocal->lastSyncDate; |
2874 | 2874 | ||
2875 | 2875 | ||
2876 | qDebug("*************************** "); | 2876 | qDebug("*************************** "); |
2877 | // qDebug("mLastAddressbookSync %s ",mLastAddressbookSync.toString().latin1() ); | 2877 | // qDebug("mLastAddressbookSync %s ",mLastAddressbookSync.toString().latin1() ); |
2878 | QStringList er = syncRemote->getIDEntryList(); | 2878 | QStringList er = syncRemote->getIDEntryList(); |
2879 | PwMDataItem* inRemote ;//= er.first(); | 2879 | PwMDataItem* inRemote ;//= er.first(); |
2880 | PwMDataItem* inLocal; | 2880 | PwMDataItem* inLocal; |
2881 | unsigned int catLocal, indexLocal; | 2881 | unsigned int catLocal, indexLocal; |
2882 | unsigned int catRemote, indexRemote; | 2882 | unsigned int catRemote, indexRemote; |
2883 | 2883 | ||
2884 | QString uid; | 2884 | QString uid; |
2885 | manager->showProgressBar(0, i18n("Syncing - close to abort!"), er.count()); | 2885 | manager->showProgressBar(0, i18n("Syncing - close to abort!"), er.count()); |
2886 | 2886 | ||
2887 | int modulo = (er.count()/10)+1; | 2887 | int modulo = (er.count()/10)+1; |
2888 | unsigned int incCounter = 0; | 2888 | unsigned int incCounter = 0; |
2889 | while ( incCounter < er.count()) { | 2889 | while ( incCounter < er.count()) { |
2890 | if (manager->isProgressBarCanceled()) | 2890 | if (manager->isProgressBarCanceled()) |
2891 | return e_syncError; | 2891 | return e_syncError; |
2892 | if ( incCounter % modulo == 0 ) | 2892 | if ( incCounter % modulo == 0 ) |
2893 | manager->showProgressBar(incCounter); | 2893 | manager->showProgressBar(incCounter); |
2894 | 2894 | ||
2895 | uid = er[ incCounter ]; | 2895 | uid = er[ incCounter ]; |
2896 | qDebug("sync uid %s from remote file", uid.latin1()); | 2896 | qDebug("sync uid %s from remote file", uid.latin1()); |
2897 | 2897 | ||
2898 | qApp->processEvents(); | 2898 | qApp->processEvents(); |
2899 | 2899 | ||
2900 | inLocal = syncLocal->findEntryByID( uid, &catLocal, &indexLocal ); | 2900 | inLocal = syncLocal->findEntryByID( uid, &catLocal, &indexLocal ); |
2901 | inRemote = syncRemote->findEntryByID( uid, &catRemote, &indexRemote ); | 2901 | inRemote = syncRemote->findEntryByID( uid, &catRemote, &indexRemote ); |
2902 | PWM_ASSERT(inRemote); | 2902 | PWM_ASSERT(inRemote); |
2903 | if ( inLocal != 0 ) { // maybe conflict - same uid in both files | 2903 | if ( inLocal != 0 ) { // maybe conflict - same uid in both files |
2904 | if ( (take = takePwMDataItem( inLocal, inRemote, mLastSync, mode, fullDateRange) ) ) { | 2904 | if ( (take = takePwMDataItem( inLocal, inRemote, mLastSync, mode, fullDateRange) ) ) { |
2905 | //qDebug("take %d %s ", take, inL.summary().latin1()); | 2905 | //qDebug("take %d %s ", take, inL.summary().latin1()); |
2906 | if ( take == 3 ) | 2906 | if ( take == 3 ) |
2907 | return e_syncError; | 2907 | return e_syncError; |
2908 | if ( take == 1 ) {// take local | 2908 | if ( take == 1 ) {// take local |
2909 | //US syncRemote->removeAddressee( inRemote ); | 2909 | //US syncRemote->removeAddressee( inRemote ); |
2910 | (*inRemote) = (*inLocal); | 2910 | (*inRemote) = (*inLocal); |
2911 | //US syncRemote->insertAddressee( inRemote , false); | 2911 | //US syncRemote->insertAddressee( inRemote , false); |
2912 | ++changedRemote; | 2912 | ++changedRemote; |
2913 | } else { // take == 2 take remote | 2913 | } else { // take == 2 take remote |
2914 | //US syncLocal->removeAddressee( inLocal ); | 2914 | //US syncLocal->removeAddressee( inLocal ); |
2915 | (*inLocal) = (*inRemote); | 2915 | (*inLocal) = (*inRemote); |
2916 | //US syncLocal->insertAddressee( inLocal , false ); | 2916 | //US syncLocal->insertAddressee( inLocal , false ); |
2917 | ++changedLocal; | 2917 | ++changedLocal; |
2918 | } | 2918 | } |
2919 | } | 2919 | } |
2920 | } else { // no conflict | 2920 | } else { // no conflict |
2921 | if ( inRemote->meta.update > mLastSync || mode == 5 ) { | 2921 | if ( inRemote->meta.update > mLastSync || mode == 5 ) { |
2922 | inRemote->meta.update = modifiedSync; | 2922 | inRemote->meta.update = modifiedSync; |
2923 | |||
2924 | //first check if we have a matching category in the local file | ||
2925 | const string* remotecat = syncRemote->getCategory(catRemote); | ||
2923 | //US syncRemote->insertAddressee( inRemote, false ); | 2926 | //US syncRemote->insertAddressee( inRemote, false ); |
2924 | //US syncLocal->insertAddressee( inRemote, false ); | 2927 | //US syncLocal->insertAddressee( inRemote, false ); |
2925 | syncLocal->addEntry("newcategory", inRemote, true, false); | 2928 | syncLocal->addEntry(remotecat->c_str(), inRemote, true, false); |
2926 | 2929 | ||
2927 | ++addedPasswordsLocal; | 2930 | ++addedPasswordsLocal; |
2928 | } else { | 2931 | } else { |
2929 | // pending checkExternSyncAddressee(addresseeRSyncSharp, inR); | 2932 | // pending checkExternSyncAddressee(addresseeRSyncSharp, inR); |
2930 | syncRemote->delEntry(catRemote, indexRemote, true); | 2933 | syncRemote->delEntry(catRemote, indexRemote, true); |
2931 | //USsyncRemote->removeAddressee( inRemote ); | 2934 | //USsyncRemote->removeAddressee( inRemote ); |
2932 | ++deletedPasswordsRemote; | 2935 | ++deletedPasswordsRemote; |
2933 | } | 2936 | } |
2934 | } | 2937 | } |
2935 | 2938 | ||
2936 | ++incCounter; | 2939 | ++incCounter; |
2937 | } | 2940 | } |
2938 | 2941 | ||
2939 | 2942 | ||
2940 | er.clear(); | 2943 | er.clear(); |
2941 | QStringList el = syncLocal->getIDEntryList(); | 2944 | QStringList el = syncLocal->getIDEntryList(); |
2942 | modulo = (el.count()/10)+1; | 2945 | modulo = (el.count()/10)+1; |
2943 | 2946 | ||
2944 | manager->showProgressBar(0, i18n("Add / remove addressees"), el.count()); | 2947 | manager->showProgressBar(0, i18n("Add / remove addressees"), el.count()); |
2945 | incCounter = 0; | 2948 | incCounter = 0; |
2946 | while ( incCounter < el.count()) { | 2949 | while ( incCounter < el.count()) { |
2947 | qApp->processEvents(); | 2950 | qApp->processEvents(); |
2948 | if (manager->isProgressBarCanceled()) | 2951 | if (manager->isProgressBarCanceled()) |
2949 | return e_syncError; | 2952 | return e_syncError; |
2950 | if ( incCounter % modulo == 0 ) | 2953 | if ( incCounter % modulo == 0 ) |
2951 | manager->showProgressBar(incCounter); | 2954 | manager->showProgressBar(incCounter); |
2952 | uid = el[ incCounter ]; | 2955 | uid = el[ incCounter ]; |
2953 | 2956 | ||
2954 | inLocal = syncLocal->findEntryByID( uid, &catLocal, &indexLocal ); | 2957 | inLocal = syncLocal->findEntryByID( uid, &catLocal, &indexLocal ); |
2955 | inRemote = syncRemote->findEntryByID( uid, &catRemote, &indexRemote ); | 2958 | inRemote = syncRemote->findEntryByID( uid, &catRemote, &indexRemote ); |
2959 | PWM_ASSERT(inLocal); | ||
2960 | |||
2956 | if ( inRemote == 0 ) { | 2961 | if ( inRemote == 0 ) { |
2957 | if ( inLocal->meta.update < mLastSync && mode != 4 ) { | 2962 | if ( inLocal->meta.update < mLastSync && mode != 4 ) { |
2958 | // pending checkExternSyncAddressee(addresseeLSyncSharp, inL); | 2963 | // pending checkExternSyncAddressee(addresseeLSyncSharp, inL); |
2959 | syncLocal->delEntry(catLocal, indexLocal, true); | 2964 | syncLocal->delEntry(catLocal, indexLocal, true); |
2960 | //USsyncLocal->removeAddressee( inLocal ); | 2965 | //USsyncLocal->removeAddressee( inLocal ); |
2961 | ++deletedPasswordsLocal; | 2966 | ++deletedPasswordsLocal; |
2962 | } else { | 2967 | } else { |
2963 | if ( ! manager->mWriteBackExistingOnly ) { | 2968 | if ( ! manager->mWriteBackExistingOnly ) { |
2964 | ++addedPasswordsRemote; | 2969 | ++addedPasswordsRemote; |
2965 | inLocal->meta.update = modifiedSync; | 2970 | inLocal->meta.update = modifiedSync; |
2971 | |||
2972 | //first check if we have a matching category in the remote file | ||
2973 | const string* localcat = syncLocal->getCategory(catLocal); | ||
2974 | |||
2966 | //USsyncLocal->insertAddressee( inLocal, false ); | 2975 | //USsyncLocal->insertAddressee( inLocal, false ); |
2967 | (*inRemote) = (*inLocal); | 2976 | PwMDataItem newEntry; |
2977 | newEntry = *inLocal; | ||
2978 | inRemote = &newEntry; | ||
2979 | |||
2968 | //USsyncRemote->insertAddressee( inRemote, false ); | 2980 | //USsyncRemote->insertAddressee( inRemote, false ); |
2969 | syncRemote->addEntry("newcategory", inRemote, true, false); | 2981 | syncRemote->addEntry(localcat->c_str(), inRemote, true, false); |
2970 | 2982 | ||
2971 | } | 2983 | } |
2972 | } | 2984 | } |
2973 | 2985 | ||
2974 | } | 2986 | } |
2975 | ++incCounter; | 2987 | ++incCounter; |
2976 | } | 2988 | } |
2977 | el.clear(); | 2989 | el.clear(); |
2978 | manager->hideProgressBar(); | 2990 | manager->hideProgressBar(); |
2979 | 2991 | ||
2980 | // Now write the info back into the sync data space of the files | 2992 | // Now write the info back into the sync data space of the files |
2981 | 2993 | ||
2982 | mLastSync = QDateTime::currentDateTime().addSecs( 1 ); | 2994 | mLastSync = QDateTime::currentDateTime().addSecs( 1 ); |
2983 | // get rid of micro seconds | 2995 | // get rid of micro seconds |
2984 | QTime t = mLastSync.time(); | 2996 | QTime t = mLastSync.time(); |
2985 | mLastSync.setTime( QTime (t.hour (), t.minute (), t.second () ) ); | 2997 | mLastSync.setTime( QTime (t.hour (), t.minute (), t.second () ) ); |
2986 | 2998 | ||
2987 | 2999 | ||
2988 | syncItemLocal->lastSyncDate = mLastSync; | 3000 | syncItemLocal.lastSyncDate = mLastSync; |
2989 | syncItemRemote->lastSyncDate = mLastSync; | 3001 | syncItemRemote.lastSyncDate = mLastSync; |
2990 | 3002 | ||
2991 | // addresseeRSync.setRole( i18n("!Remote from: ")+mCurrentSyncName ) ; | 3003 | // addresseeRSync.setRole( i18n("!Remote from: ")+mCurrentSyncName ) ; |
2992 | // addresseeLSync.setRole(i18n("!Local from: ") + mCurrentSyncName ); | 3004 | // addresseeLSync.setRole(i18n("!Local from: ") + mCurrentSyncName ); |
2993 | 3005 | ||
2994 | syncRemote->addSyncDataEntry( syncItemRemote, false ); | 3006 | syncRemote->addSyncDataEntry( syncItemRemote, false ); |
2995 | syncLocal->addSyncDataEntry( syncItemLocal, false ); | 3007 | syncLocal->addSyncDataEntry( syncItemLocal, false ); |
2996 | QString mes; | 3008 | QString mes; |
2997 | mes .sprintf( i18n("Synchronization summary:\n\n %d items added to local\n %d items added to remote\n %d items updated on local\n %d items updated on remote\n %d items deleted on local\n %d items deleted on remote\n"),addedPasswordsLocal, addedPasswordsRemote, changedLocal, changedRemote, deletedPasswordsLocal, deletedPasswordsRemote ); | 3009 | mes .sprintf( i18n("Synchronization summary:\n\n %d items added to local\n %d items added to remote\n %d items updated on local\n %d items updated on remote\n %d items deleted on local\n %d items deleted on remote\n"),addedPasswordsLocal, addedPasswordsRemote, changedLocal, changedRemote, deletedPasswordsLocal, deletedPasswordsRemote ); |
2998 | if ( manager->mShowSyncSummary ) { | 3010 | if ( manager->mShowSyncSummary ) { |
2999 | KMessageBox::information(0, mes, i18n("PWM/Pi Synchronization") ); | 3011 | KMessageBox::information(0, mes, i18n("PWM/Pi Synchronization") ); |
3000 | } | 3012 | } |
3001 | qDebug( mes ); | 3013 | qDebug( mes ); |
3002 | return e_success; | 3014 | return e_success; |
3003 | } | 3015 | } |
3004 | 3016 | ||
3005 | 3017 | ||
3006 | int PwMDoc::takePwMDataItem( PwMDataItem* local, PwMDataItem* remote, QDateTime lastSync, int mode , bool full ) | 3018 | int PwMDoc::takePwMDataItem( PwMDataItem* local, PwMDataItem* remote, QDateTime lastSync, int mode , bool full ) |
3007 | { | 3019 | { |
3008 | // 0 equal | 3020 | // 0 equal |
3009 | // 1 take local | 3021 | // 1 take local |
3010 | // 2 take remote | 3022 | // 2 take remote |
3011 | // 3 cancel | 3023 | // 3 cancel |
3012 | QDateTime localMod = local->meta.update; | 3024 | QDateTime localMod = local->meta.update; |
3013 | QDateTime remoteMod = remote->meta.update; | 3025 | QDateTime remoteMod = remote->meta.update; |
3014 | 3026 | ||
3015 | //US QString mCurrentSyncDevice = syncManager->getCurrentSyncDevice(); | 3027 | //US QString mCurrentSyncDevice = syncManager->getCurrentSyncDevice(); |
3016 | 3028 | ||
3017 | if ( localMod == remoteMod ) | 3029 | if ( localMod == remoteMod ) |
3018 | return 0; | 3030 | return 0; |
3019 | 3031 | ||
3020 | qDebug(" %d %d conflict on %s %s ", mode, full, local->desc.c_str(), remote->desc.c_str() ); | 3032 | qDebug(" %d %d conflict on %s %s ", mode, full, local->desc.c_str(), remote->desc.c_str() ); |
3021 | 3033 | ||
3022 | //qDebug("%s %d %s %d", local->lastModified().toString().latin1() , localMod, remote->lastModified().toString().latin1(), remoteMod); | 3034 | //qDebug("%s %d %s %d", local->lastModified().toString().latin1() , localMod, remote->lastModified().toString().latin1(), remoteMod); |
3023 | //qDebug("%d %d %d %d ", local->lastModified().time().second(), local->lastModified().time().msec(), remote->lastModified().time().second(), remote->lastModified().time().msec() ); | 3035 | //qDebug("%d %d %d %d ", local->lastModified().time().second(), local->lastModified().time().msec(), remote->lastModified().time().second(), remote->lastModified().time().msec() ); |
3024 | //full = true; //debug only | 3036 | //full = true; //debug only |
3025 | if ( full ) { | 3037 | if ( full ) { |
3026 | bool equ = true;//US ( (*local) == (*remote) ); | 3038 | bool equ = true;//US ( (*local) == (*remote) ); |
3027 | if ( equ ) { | 3039 | if ( equ ) { |
3028 | //qDebug("equal "); | 3040 | //qDebug("equal "); |
3029 | if ( mode < SYNC_PREF_FORCE_LOCAL ) | 3041 | if ( mode < SYNC_PREF_FORCE_LOCAL ) |
3030 | return 0; | 3042 | return 0; |
3031 | 3043 | ||
3032 | }//else //debug only | 3044 | }//else //debug only |
3033 | //qDebug("not equal %s %s ", local->summary().latin1(), remote->summary().latin1()); | 3045 | //qDebug("not equal %s %s ", local->summary().latin1(), remote->summary().latin1()); |
3034 | } | 3046 | } |
3035 | 3047 | ||
3036 | int result; | 3048 | int result; |
3037 | bool localIsNew; | 3049 | bool localIsNew; |
3038 | //qDebug("%s -- %s mLastCalendarSync %s lastsync %s --- local %s remote %s ",local->summary().latin1(), remote->summary().latin1(),mLastCalendarSync.toString().latin1() ,lastSync.toString().latin1() , local->lastModified().toString().latin1() , remote->lastModified().toString().latin1() ); | 3050 | //qDebug("%s -- %s mLastCalendarSync %s lastsync %s --- local %s remote %s ",local->summary().latin1(), remote->summary().latin1(),mLastCalendarSync.toString().latin1() ,lastSync.toString().latin1() , local->lastModified().toString().latin1() , remote->lastModified().toString().latin1() ); |
3039 | 3051 | ||
3040 | if ( full && mode < SYNC_PREF_NEWEST ) | 3052 | if ( full && mode < SYNC_PREF_NEWEST ) |
3041 | mode = SYNC_PREF_ASK; | 3053 | mode = SYNC_PREF_ASK; |
3042 | 3054 | ||
3043 | switch( mode ) { | 3055 | switch( mode ) { |
3044 | case SYNC_PREF_LOCAL: | 3056 | case SYNC_PREF_LOCAL: |
3045 | if ( lastSync > remoteMod ) | 3057 | if ( lastSync > remoteMod ) |
3046 | return 1; | 3058 | return 1; |
3047 | if ( lastSync > localMod ) | 3059 | if ( lastSync > localMod ) |
3048 | return 2; | 3060 | return 2; |
3049 | return 1; | 3061 | return 1; |
3050 | break; | 3062 | break; |
3051 | case SYNC_PREF_REMOTE: | 3063 | case SYNC_PREF_REMOTE: |
3052 | if ( lastSync > remoteMod ) | 3064 | if ( lastSync > remoteMod ) |
3053 | return 1; | 3065 | return 1; |
3054 | if ( lastSync > localMod ) | 3066 | if ( lastSync > localMod ) |
3055 | return 2; | 3067 | return 2; |
3056 | return 2; | 3068 | return 2; |
3057 | break; | 3069 | break; |
3058 | case SYNC_PREF_NEWEST: | 3070 | case SYNC_PREF_NEWEST: |
3059 | if ( localMod > remoteMod ) | 3071 | if ( localMod > remoteMod ) |
3060 | return 1; | 3072 | return 1; |
3061 | else | 3073 | else |
3062 | return 2; | 3074 | return 2; |
3063 | break; | 3075 | break; |
3064 | case SYNC_PREF_ASK: | 3076 | case SYNC_PREF_ASK: |
3065 | //qDebug("lsy %s --- lo %s --- re %s ", lastSync.toString().latin1(), localMod.toString().latin1(), remoteMod.toString().latin1() ); | 3077 | //qDebug("lsy %s --- lo %s --- re %s ", lastSync.toString().latin1(), localMod.toString().latin1(), remoteMod.toString().latin1() ); |
3066 | if ( lastSync > remoteMod ) | 3078 | if ( lastSync > remoteMod ) |
3067 | return 1; | 3079 | return 1; |
3068 | if ( lastSync > localMod ) | 3080 | if ( lastSync > localMod ) |
3069 | return 2; | 3081 | return 2; |
3070 | localIsNew = localMod >= remoteMod; | 3082 | localIsNew = localMod >= remoteMod; |
3071 | //qDebug("conflict! ************************************** "); | 3083 | //qDebug("conflict! ************************************** "); |
3072 | { | 3084 | { |
3073 | PwMDataItemChooser acd ( *local,*remote, localIsNew , 0/*this*/ ); | 3085 | PwMDataItemChooser acd ( *local,*remote, localIsNew , 0/*this*/ ); |
3074 | result = acd.executeD(localIsNew); | 3086 | result = acd.executeD(localIsNew); |
3075 | return result; | 3087 | return result; |
3076 | } | 3088 | } |
3077 | break; | 3089 | break; |
3078 | case SYNC_PREF_FORCE_LOCAL: | 3090 | case SYNC_PREF_FORCE_LOCAL: |
3079 | return 1; | 3091 | return 1; |
3080 | break; | 3092 | break; |
3081 | case SYNC_PREF_FORCE_REMOTE: | 3093 | case SYNC_PREF_FORCE_REMOTE: |
3082 | return 2; | 3094 | return 2; |
3083 | break; | 3095 | break; |
3084 | 3096 | ||
3085 | default: | 3097 | default: |
@@ -3189,112 +3201,112 @@ bool PwMDoc::findSyncData(const QString &syncname, unsigned int *index) | |||
3189 | return true; | 3201 | return true; |
3190 | } | 3202 | } |
3191 | ++i; | 3203 | ++i; |
3192 | } | 3204 | } |
3193 | return false; | 3205 | return false; |
3194 | }; | 3206 | }; |
3195 | 3207 | ||
3196 | /** add new syncdataentry */ | 3208 | /** add new syncdataentry */ |
3197 | PwMerror PwMDoc::addSyncDataEntry(PwMSyncItem *d, bool dontFlagDirty) | 3209 | PwMerror PwMDoc::addSyncDataEntry(PwMSyncItem *d, bool dontFlagDirty) |
3198 | { | 3210 | { |
3199 | PWM_ASSERT(d); | 3211 | PWM_ASSERT(d); |
3200 | 3212 | ||
3201 | if (isDeepLocked()) { | 3213 | if (isDeepLocked()) { |
3202 | PwMerror ret; | 3214 | PwMerror ret; |
3203 | ret = deepLock(false); | 3215 | ret = deepLock(false); |
3204 | if (ret != e_success) | 3216 | if (ret != e_success) |
3205 | return e_lock; | 3217 | return e_lock; |
3206 | } | 3218 | } |
3207 | unsigned int index; | 3219 | unsigned int index; |
3208 | 3220 | ||
3209 | const QString tmp = d->syncName.c_str(); | 3221 | const QString tmp = d->syncName.c_str(); |
3210 | bool exists = findSyncData(d->syncName.c_str(), &index); | 3222 | bool exists = findSyncData(d->syncName.c_str(), &index); |
3211 | 3223 | ||
3212 | if (exists == true) { | 3224 | if (exists == true) { |
3213 | // DOH! We found this entry. | 3225 | // DOH! We found this entry. |
3214 | return e_entryExists; | 3226 | return e_entryExists; |
3215 | } | 3227 | } |
3216 | 3228 | ||
3217 | dti.syncDta.push_back(*d); | 3229 | dti.syncDta.push_back(*d); |
3218 | 3230 | ||
3219 | if (!dontFlagDirty) | 3231 | if (!dontFlagDirty) |
3220 | flagDirty(); | 3232 | flagDirty(); |
3221 | return e_success; | 3233 | return e_success; |
3222 | } | 3234 | } |
3223 | 3235 | ||
3224 | 3236 | ||
3225 | 3237 | ||
3226 | /** delete syncdata entry */ | 3238 | /** delete syncdata entry */ |
3227 | bool PwMDoc::delSyncDataEntry(unsigned int index, bool dontFlagDirty) | 3239 | bool PwMDoc::delSyncDataEntry(unsigned int index, bool dontFlagDirty) |
3228 | { | 3240 | { |
3229 | if (isDeepLocked()) | 3241 | if (isDeepLocked()) |
3230 | return false; | 3242 | return false; |
3231 | if (index > dti.syncDta.size() - 1) | 3243 | if (index > dti.syncDta.size() - 1) |
3232 | return false; | 3244 | return false; |
3233 | 3245 | ||
3234 | // delete entry | 3246 | // delete entry |
3235 | dti.syncDta.erase(dti.syncDta.begin() + index); | 3247 | dti.syncDta.erase(dti.syncDta.begin() + index); |
3236 | 3248 | ||
3237 | if (!dontFlagDirty) | 3249 | if (!dontFlagDirty) |
3238 | flagDirty(); | 3250 | flagDirty(); |
3239 | return true; | 3251 | return true; |
3240 | } | 3252 | } |
3241 | 3253 | ||
3242 | 3254 | ||
3243 | PwMDataItem* PwMDoc::findEntryByID(const QString &uid, unsigned int *category, unsigned int *index) | 3255 | PwMDataItem* PwMDoc::findEntryByID(const QString &uid, unsigned int *category, unsigned int *index) |
3244 | { | 3256 | { |
3245 | vector<PwMCategoryItem>::iterator catcounter = dti.dta.begin(), | 3257 | vector<PwMCategoryItem>::iterator catcounter = dti.dta.begin(), |
3246 | catend = dti.dta.end(); | 3258 | catend = dti.dta.end(); |
3247 | 3259 | ||
3248 | vector<PwMDataItem>::iterator entrBegin, entrEnd, entrI; | 3260 | vector<PwMDataItem>::iterator entrBegin, entrEnd, entrI; |
3249 | 3261 | ||
3250 | while (catcounter != catend) { | 3262 | while (catcounter != catend) { |
3251 | entrBegin = catcounter->d.begin(); | 3263 | entrBegin = catcounter->d.begin(); |
3252 | entrEnd = catcounter->d.end(); | 3264 | entrEnd = catcounter->d.end(); |
3253 | entrI = entrBegin; | 3265 | entrI = entrBegin; |
3254 | while (entrI != entrEnd) { | 3266 | while (entrI != entrEnd) { |
3255 | if ((*entrI).meta.uniqueid == uid.latin1()) { | 3267 | if ((*entrI).meta.uniqueid == uid.latin1()) { |
3256 | if (category) | 3268 | if (category) |
3257 | *category = catcounter - dti.dta.begin(); | 3269 | *category = catcounter - dti.dta.begin(); |
3258 | if (index) | 3270 | if (index) |
3259 | *index = entrI - entrBegin; | 3271 | *index = entrI - entrBegin; |
3260 | 3272 | ||
3261 | return &(*entrI); | 3273 | return &(*entrI); |
3262 | } | 3274 | } |
3263 | ++entrI; | 3275 | ++entrI; |
3264 | } | 3276 | } |
3265 | ++catcounter; | 3277 | ++catcounter; |
3266 | } | 3278 | } |
3267 | 3279 | ||
3268 | return 0; | 3280 | return 0; |
3269 | } | 3281 | } |
3270 | 3282 | ||
3271 | QStringList PwMDoc::getIDEntryList() | 3283 | QStringList PwMDoc::getIDEntryList() |
3272 | { | 3284 | { |
3273 | QStringList results; | 3285 | QStringList results; |
3274 | 3286 | ||
3275 | vector<PwMCategoryItem>::iterator catcounter = dti.dta.begin(), | 3287 | vector<PwMCategoryItem>::iterator catcounter = dti.dta.begin(), |
3276 | catend = dti.dta.end(); | 3288 | catend = dti.dta.end(); |
3277 | 3289 | ||
3278 | vector<PwMDataItem>::iterator entrBegin, entrEnd, entrI; | 3290 | vector<PwMDataItem>::iterator entrBegin, entrEnd, entrI; |
3279 | 3291 | ||
3280 | while (catcounter != catend) { | 3292 | while (catcounter != catend) { |
3281 | entrBegin = catcounter->d.begin(); | 3293 | entrBegin = catcounter->d.begin(); |
3282 | entrEnd = catcounter->d.end(); | 3294 | entrEnd = catcounter->d.end(); |
3283 | entrI = entrBegin; | 3295 | entrI = entrBegin; |
3284 | while (entrI != entrEnd) { | 3296 | while (entrI != entrEnd) { |
3285 | results.append( (*entrI).meta.uniqueid ); | 3297 | results.append( (*entrI).meta.uniqueid.c_str() ); |
3286 | ++entrI; | 3298 | ++entrI; |
3287 | } | 3299 | } |
3288 | ++catcounter; | 3300 | ++catcounter; |
3289 | } | 3301 | } |
3290 | 3302 | ||
3291 | return results; | 3303 | return results; |
3292 | } | 3304 | } |
3293 | 3305 | ||
3294 | 3306 | ||
3295 | 3307 | ||
3296 | 3308 | ||
3297 | 3309 | ||
3298 | #ifndef PWM_EMBEDDED | 3310 | #ifndef PWM_EMBEDDED |
3299 | #include "pwmdoc.moc" | 3311 | #include "pwmdoc.moc" |
3300 | #endif | 3312 | #endif |
diff --git a/pwmanager/pwmanager/pwmdoc.h b/pwmanager/pwmanager/pwmdoc.h index 91277f6..ddab7f3 100644 --- a/pwmanager/pwmanager/pwmdoc.h +++ b/pwmanager/pwmanager/pwmdoc.h | |||
@@ -23,282 +23,310 @@ | |||
23 | #define PWM_FILE_VER (static_cast<char>(0x05)) | 23 | #define PWM_FILE_VER (static_cast<char>(0x05)) |
24 | 24 | ||
25 | #define PWM_HASH_SHA1 (static_cast<char>(0x01)) | 25 | #define PWM_HASH_SHA1 (static_cast<char>(0x01)) |
26 | #define PWM_HASH_SHA256 (static_cast<char>(0x02)) | 26 | #define PWM_HASH_SHA256 (static_cast<char>(0x02)) |
27 | #define PWM_HASH_SHA384 (static_cast<char>(0x03)) | 27 | #define PWM_HASH_SHA384 (static_cast<char>(0x03)) |
28 | #define PWM_HASH_SHA512 (static_cast<char>(0x04)) | 28 | #define PWM_HASH_SHA512 (static_cast<char>(0x04)) |
29 | #define PWM_HASH_MD5 (static_cast<char>(0x05)) | 29 | #define PWM_HASH_MD5 (static_cast<char>(0x05)) |
30 | #define PWM_HASH_RMD160 (static_cast<char>(0x06)) | 30 | #define PWM_HASH_RMD160 (static_cast<char>(0x06)) |
31 | #define PWM_HASH_TIGER (static_cast<char>(0x07)) | 31 | #define PWM_HASH_TIGER (static_cast<char>(0x07)) |
32 | 32 | ||
33 | #define PWM_CRYPT_BLOWFISH(static_cast<char>(0x01)) | 33 | #define PWM_CRYPT_BLOWFISH(static_cast<char>(0x01)) |
34 | #define PWM_CRYPT_AES128(static_cast<char>(0x02)) | 34 | #define PWM_CRYPT_AES128(static_cast<char>(0x02)) |
35 | #define PWM_CRYPT_AES192(static_cast<char>(0x03)) | 35 | #define PWM_CRYPT_AES192(static_cast<char>(0x03)) |
36 | #define PWM_CRYPT_AES256(static_cast<char>(0x04)) | 36 | #define PWM_CRYPT_AES256(static_cast<char>(0x04)) |
37 | #define PWM_CRYPT_3DES (static_cast<char>(0x05)) | 37 | #define PWM_CRYPT_3DES (static_cast<char>(0x05)) |
38 | #define PWM_CRYPT_TWOFISH(static_cast<char>(0x06)) | 38 | #define PWM_CRYPT_TWOFISH(static_cast<char>(0x06)) |
39 | #define PWM_CRYPT_TWOFISH128(static_cast<char>(0x07)) | 39 | #define PWM_CRYPT_TWOFISH128(static_cast<char>(0x07)) |
40 | 40 | ||
41 | #define PWM_COMPRESS_NONE(static_cast<char>(0x00)) | 41 | #define PWM_COMPRESS_NONE(static_cast<char>(0x00)) |
42 | #define PWM_COMPRESS_GZIP(static_cast<char>(0x01)) | 42 | #define PWM_COMPRESS_GZIP(static_cast<char>(0x01)) |
43 | #define PWM_COMPRESS_BZIP2(static_cast<char>(0x02)) | 43 | #define PWM_COMPRESS_BZIP2(static_cast<char>(0x02)) |
44 | 44 | ||
45 | #define DEFAULT_MAX_ENTRIES(~(static_cast<unsigned int>(0))) | 45 | #define DEFAULT_MAX_ENTRIES(~(static_cast<unsigned int>(0))) |
46 | #define FILE_ID_HEADER "PWM_PASSWORD_FILE" | 46 | #define FILE_ID_HEADER "PWM_PASSWORD_FILE" |
47 | 47 | ||
48 | 48 | ||
49 | #include "pwmexception.h" | 49 | #include "pwmexception.h" |
50 | #include "pwmdocui.h" | 50 | #include "pwmdocui.h" |
51 | 51 | ||
52 | #include <qobject.h> | 52 | #include <qobject.h> |
53 | #include <qtimer.h> | 53 | #include <qtimer.h> |
54 | #include <qdatetime.h> | 54 | #include <qdatetime.h> |
55 | 55 | ||
56 | #include <kprocess.h> | 56 | #include <kprocess.h> |
57 | 57 | ||
58 | #ifndef PWM_EMBEDDED | 58 | #ifndef PWM_EMBEDDED |
59 | #include "configuration.h" | 59 | #include "configuration.h" |
60 | #else | 60 | #else |
61 | #include <kapplication.h> | 61 | #include <kapplication.h> |
62 | #include <ksyncmanager.h> | 62 | #include <ksyncmanager.h> |
63 | #endif | 63 | #endif |
64 | 64 | ||
65 | #include <string> | 65 | #include <string> |
66 | #include <vector> | 66 | #include <vector> |
67 | #include <utility> | 67 | #include <utility> |
68 | 68 | ||
69 | using std::vector; | 69 | using std::vector; |
70 | using std::string; | 70 | using std::string; |
71 | using std::pair; | 71 | using std::pair; |
72 | 72 | ||
73 | /* used in findEntry() function */ | 73 | /* used in findEntry() function */ |
74 | #define SEARCH_IN_DESC (1) | 74 | #define SEARCH_IN_DESC (1) |
75 | #define SEARCH_IN_NAME (1 << 1) | 75 | #define SEARCH_IN_NAME (1 << 1) |
76 | #define SEARCH_IN_PW (1 << 2) | 76 | #define SEARCH_IN_PW (1 << 2) |
77 | #define SEARCH_IN_COMMENT(1 << 3) | 77 | #define SEARCH_IN_COMMENT(1 << 3) |
78 | #define SEARCH_IN_URL (1 << 4) | 78 | #define SEARCH_IN_URL (1 << 4) |
79 | #define SEARCH_IN_LAUNCHER(1 << 5) | 79 | #define SEARCH_IN_LAUNCHER(1 << 5) |
80 | #define SEARCH_IN_ALL (SEARCH_IN_DESC | SEARCH_IN_NAME| \ | 80 | #define SEARCH_IN_ALL (SEARCH_IN_DESC | SEARCH_IN_NAME| \ |
81 | SEARCH_IN_PW | SEARCH_IN_COMMENT| \ | 81 | SEARCH_IN_PW | SEARCH_IN_COMMENT| \ |
82 | SEARCH_IN_URL| SEARCH_IN_LAUNCHER) | 82 | SEARCH_IN_URL| SEARCH_IN_LAUNCHER) |
83 | 83 | ||
84 | /** document deeplocked. Data is out for lunch to disk */ | 84 | /** document deeplocked. Data is out for lunch to disk */ |
85 | #define DOC_STAT_DEEPLOCKED (1) | 85 | #define DOC_STAT_DEEPLOCKED (1) |
86 | /** encrypted document on disk is dirty. data has to go to disk. */ | 86 | /** encrypted document on disk is dirty. data has to go to disk. */ |
87 | #define DOC_STAT_DISK_DIRTY (1 << 1) | 87 | #define DOC_STAT_DISK_DIRTY (1 << 1) |
88 | /** we are using a chipcard to encrypt the data */ | 88 | /** we are using a chipcard to encrypt the data */ |
89 | #define DOC_STAT_USE_CHIPCARD (1 << 2) | 89 | #define DOC_STAT_USE_CHIPCARD (1 << 2) |
90 | /** use "currentPw" to unlock. (This flag is set/unset by a timer) */ | 90 | /** use "currentPw" to unlock. (This flag is set/unset by a timer) */ |
91 | #define DOC_STAT_UNLOCK_WITHOUT_PW(1 << 3) | 91 | #define DOC_STAT_UNLOCK_WITHOUT_PW(1 << 3) |
92 | 92 | ||
93 | class PwMDoc; | 93 | class PwMDoc; |
94 | class PwMView; | 94 | class PwMView; |
95 | class QFile; | 95 | class QFile; |
96 | 96 | ||
97 | /* meta data for a PwMDataItem */ | 97 | /* meta data for a PwMDataItem */ |
98 | struct PwMMetaData | 98 | struct PwMMetaData |
99 | { | 99 | { |
100 | PwMMetaData() | 100 | PwMMetaData() |
101 | : updateInt (0) | 101 | : updateInt (0) |
102 | { } | 102 | { } |
103 | /** creation date of the PwMDataItem to which | 103 | /** creation date of the PwMDataItem to which |
104 | * this meta data belongs. | 104 | * this meta data belongs. |
105 | */ | 105 | */ |
106 | QDateTimecreate; | 106 | QDateTimecreate; |
107 | /** becomes valid on this date */ | 107 | /** becomes valid on this date */ |
108 | QDateTimevalid; | 108 | QDateTimevalid; |
109 | /** expire date */ | 109 | /** expire date */ |
110 | QDateTimeexpire; | 110 | QDateTimeexpire; |
111 | /** update date (last updated at this date) */ | 111 | /** update date (last updated at this date) */ |
112 | QDateTimeupdate; | 112 | QDateTimeupdate; |
113 | /** update interval (in minutes). Time since the | 113 | /** update interval (in minutes). Time since the |
114 | * last update to remind the user to update the item. | 114 | * last update to remind the user to update the item. |
115 | * 0 disables. | 115 | * 0 disables. |
116 | */ | 116 | */ |
117 | unsigned long updateInt; | 117 | unsigned long updateInt; |
118 | 118 | ||
119 | //US ENH: enhancements of the filestructure | 119 | //US ENH: enhancements of the filestructure |
120 | /* each entry gets a unique id assigned */ | 120 | /* each entry gets a unique id assigned */ |
121 | QString uniqueid; | 121 | string uniqueid; |
122 | 122 | ||
123 | 123 | ||
124 | void clear() | 124 | void clear() |
125 | { | 125 | { |
126 | create = QDateTime(); | 126 | create = QDateTime(); |
127 | expire = QDateTime(); | 127 | expire = QDateTime(); |
128 | update = QDateTime(); | 128 | update = QDateTime(); |
129 | updateInt = 0; | 129 | updateInt = 0; |
130 | uniqueid = KApplication::randomString(8); | 130 | uniqueid = KApplication::randomString(8); |
131 | } | 131 | } |
132 | |||
133 | PwMMetaData& operator = (const PwMMetaData& x) | ||
134 | { | ||
135 | create = x.create; | ||
136 | expire = x.expire; | ||
137 | update = x.update; | ||
138 | updateInt = x.updateInt; | ||
139 | uniqueid = x.uniqueid; | ||
140 | return *this; | ||
141 | } | ||
142 | |||
132 | inline bool isValid() const | 143 | inline bool isValid() const |
133 | { | 144 | { |
134 | if (valid.isNull()) | 145 | if (valid.isNull()) |
135 | return true; | 146 | return true; |
136 | return (valid < QDateTime::currentDateTime()); | 147 | return (valid < QDateTime::currentDateTime()); |
137 | } | 148 | } |
138 | inline bool isExpired() const | 149 | inline bool isExpired() const |
139 | { | 150 | { |
140 | if (expire.isNull()) | 151 | if (expire.isNull()) |
141 | return false; | 152 | return false; |
142 | return (expire < QDateTime::currentDateTime()); | 153 | return (expire < QDateTime::currentDateTime()); |
143 | } | 154 | } |
144 | inline bool isUpdateIntOver() const | 155 | inline bool isUpdateIntOver() const |
145 | { | 156 | { |
146 | if (updateInt == 0 || | 157 | if (updateInt == 0 || |
147 | update.isNull()) | 158 | update.isNull()) |
148 | return false; | 159 | return false; |
149 | QDateTime d(update); | 160 | QDateTime d(update); |
150 | return (d.addSecs(updateInt * 60) < QDateTime::currentDateTime()); | 161 | return (d.addSecs(updateInt * 60) < QDateTime::currentDateTime()); |
151 | } | 162 | } |
152 | }; | 163 | }; |
153 | 164 | ||
154 | struct PwMDataItem | 165 | struct PwMDataItem |
155 | { | 166 | { |
156 | PwMDataItem() | 167 | PwMDataItem() |
157 | : lockStat (true) | 168 | : lockStat (true) |
158 | , listViewPos (-1) | 169 | , listViewPos (-1) |
159 | , binary (false) | 170 | , binary (false) |
160 | , rev (0) | 171 | , rev (0) |
161 | { } | 172 | { } |
162 | 173 | ||
163 | /** password description */ | 174 | /** password description */ |
164 | stringdesc; | 175 | stringdesc; |
165 | /** user-name */ | 176 | /** user-name */ |
166 | stringname; | 177 | stringname; |
167 | /** the password itself */ | 178 | /** the password itself */ |
168 | stringpw; | 179 | stringpw; |
169 | /** some comment */ | 180 | /** some comment */ |
170 | stringcomment; | 181 | stringcomment; |
171 | /** an URL string */ | 182 | /** an URL string */ |
172 | stringurl; | 183 | stringurl; |
173 | /** launcher. Can be executed as a system() command */ | 184 | /** launcher. Can be executed as a system() command */ |
174 | stringlauncher; | 185 | stringlauncher; |
175 | /** locking status. If locked (true), pw is not emitted through getEntry() */ | 186 | /** locking status. If locked (true), pw is not emitted through getEntry() */ |
176 | boollockStat; | 187 | boollockStat; |
177 | /** position of this item in main "list-view" | 188 | /** position of this item in main "list-view" |
178 | * If -1, the position is not yet specified and should be appended to the list | 189 | * If -1, the position is not yet specified and should be appended to the list |
179 | */ | 190 | */ |
180 | intlistViewPos; | 191 | intlistViewPos; |
181 | /** does this entry contain binary data? */ | 192 | /** does this entry contain binary data? */ |
182 | bool binary; | 193 | bool binary; |
183 | /** meta data for this data item. */ | 194 | /** meta data for this data item. */ |
184 | PwMMetaData meta; | 195 | PwMMetaData meta; |
185 | /** data revision counter. This counter can be used | 196 | /** data revision counter. This counter can be used |
186 | * to easily, efficiently determine if this data item | 197 | * to easily, efficiently determine if this data item |
187 | * has changed since some time. | 198 | * has changed since some time. |
188 | * This counter is incremented on every update. | 199 | * This counter is incremented on every update. |
189 | */ | 200 | */ |
190 | unsigned int rev; | 201 | unsigned int rev; |
191 | 202 | ||
192 | void clear(bool clearMeta = true) | 203 | void clear(bool clearMeta = true) |
193 | { | 204 | { |
194 | /* NOTE: Don't use .clear() here to be | 205 | /* NOTE: Don't use .clear() here to be |
195 | * backward compatible with gcc-2 (Debian Woody) | 206 | * backward compatible with gcc-2 (Debian Woody) |
196 | */ | 207 | */ |
197 | desc = ""; | 208 | desc = ""; |
198 | name = ""; | 209 | name = ""; |
199 | pw = ""; | 210 | pw = ""; |
200 | comment = ""; | 211 | comment = ""; |
201 | url = ""; | 212 | url = ""; |
202 | launcher = ""; | 213 | launcher = ""; |
203 | lockStat = true; | 214 | lockStat = true; |
204 | listViewPos = -1; | 215 | listViewPos = -1; |
205 | binary = false; | 216 | binary = false; |
206 | if (clearMeta) | 217 | if (clearMeta) |
207 | meta.clear(); | 218 | meta.clear(); |
208 | } | 219 | } |
220 | |||
221 | PwMDataItem& operator = (const PwMDataItem& x) | ||
222 | { | ||
223 | qDebug("oper=%s", x.desc.c_str()); | ||
224 | desc = x.desc; | ||
225 | name = x.name; | ||
226 | pw = x.pw; | ||
227 | comment = x.comment; | ||
228 | url = x.url; | ||
229 | launcher = x.launcher; | ||
230 | lockStat = x.lockStat; | ||
231 | listViewPos = x.listViewPos; | ||
232 | binary = x.binary; | ||
233 | meta = x.meta; | ||
234 | rev = x.rev; | ||
235 | return *this; | ||
236 | } | ||
209 | 237 | ||
210 | }; | 238 | }; |
211 | 239 | ||
212 | struct PwMCategoryItem | 240 | struct PwMCategoryItem |
213 | { | 241 | { |
214 | /** all PwMDataItems (all passwords) within this category */ | 242 | /** all PwMDataItems (all passwords) within this category */ |
215 | vector<PwMDataItem>d; | 243 | vector<PwMDataItem>d; |
216 | /** category name/description */ | 244 | /** category name/description */ |
217 | string name; | 245 | string name; |
218 | 246 | ||
219 | void clear() | 247 | void clear() |
220 | { | 248 | { |
221 | d.clear(); | 249 | d.clear(); |
222 | name = ""; | 250 | name = ""; |
223 | } | 251 | } |
224 | }; | 252 | }; |
225 | 253 | ||
226 | struct PwMSyncItem | 254 | struct PwMSyncItem |
227 | { | 255 | { |
228 | string syncName; | 256 | string syncName; |
229 | QDateTime lastSyncDate; | 257 | QDateTime lastSyncDate; |
230 | 258 | ||
231 | void clear() | 259 | void clear() |
232 | { | 260 | { |
233 | lastSyncDate = QDateTime(); | 261 | lastSyncDate = QDateTime(); |
234 | syncName = ""; | 262 | syncName = ""; |
235 | } | 263 | } |
236 | }; | 264 | }; |
237 | 265 | ||
238 | struct PwMItem | 266 | struct PwMItem |
239 | { | 267 | { |
240 | vector<PwMCategoryItem> dta; | 268 | vector<PwMCategoryItem> dta; |
241 | vector<PwMSyncItem> syncDta; | 269 | vector<PwMSyncItem> syncDta; |
242 | 270 | ||
243 | void clear() | 271 | void clear() |
244 | { | 272 | { |
245 | dta.clear(); | 273 | dta.clear(); |
246 | syncDta.clear(); | 274 | syncDta.clear(); |
247 | } | 275 | } |
248 | }; | 276 | }; |
249 | 277 | ||
250 | 278 | ||
251 | /** "Function Object" for sort()ing PwMDataItem::listViewPos */ | 279 | /** "Function Object" for sort()ing PwMDataItem::listViewPos */ |
252 | class dta_lvp_greater | 280 | class dta_lvp_greater |
253 | { | 281 | { |
254 | public: | 282 | public: |
255 | bool operator() (const pair<unsigned int, unsigned int> &d1, | 283 | bool operator() (const pair<unsigned int, unsigned int> &d1, |
256 | const pair<unsigned int, unsigned int> &d2) | 284 | const pair<unsigned int, unsigned int> &d2) |
257 | { | 285 | { |
258 | return d1.second > d2.second; | 286 | return d1.second > d2.second; |
259 | } | 287 | } |
260 | }; | 288 | }; |
261 | 289 | ||
262 | /** list of PwMDoc documents and it's IDs */ | 290 | /** list of PwMDoc documents and it's IDs */ |
263 | class PwMDocList | 291 | class PwMDocList |
264 | { | 292 | { |
265 | public: | 293 | public: |
266 | struct listItem | 294 | struct listItem |
267 | { | 295 | { |
268 | /** document filename (known as ID, here) */ | 296 | /** document filename (known as ID, here) */ |
269 | string docId; | 297 | string docId; |
270 | /** pointer to the document class */ | 298 | /** pointer to the document class */ |
271 | PwMDoc *doc; | 299 | PwMDoc *doc; |
272 | }; | 300 | }; |
273 | 301 | ||
274 | PwMDocList() {} | 302 | PwMDocList() {} |
275 | 303 | ||
276 | /** add a new item to the list */ | 304 | /** add a new item to the list */ |
277 | void add(PwMDoc *doc, const string &id); | 305 | void add(PwMDoc *doc, const string &id); |
278 | /** changes the contents of an existing item */ | 306 | /** changes the contents of an existing item */ |
279 | void edit(PwMDoc *doc, const string &newId); | 307 | void edit(PwMDoc *doc, const string &newId); |
280 | /** remove the given item */ | 308 | /** remove the given item */ |
281 | void del(PwMDoc *doc); | 309 | void del(PwMDoc *doc); |
282 | /** get the item at index */ | 310 | /** get the item at index */ |
283 | listItem getAt(int index) | 311 | listItem getAt(int index) |
284 | { return docList[index]; } | 312 | { return docList[index]; } |
285 | /** find an entry with this id */ | 313 | /** find an entry with this id */ |
286 | bool find(const string &id, listItem *ret = 0); | 314 | bool find(const string &id, listItem *ret = 0); |
287 | /** returns a copy of the list */ | 315 | /** returns a copy of the list */ |
288 | const vector<listItem>* getList() const | 316 | const vector<listItem>* getList() const |
289 | { return &docList; } | 317 | { return &docList; } |
290 | 318 | ||
291 | 319 | ||
292 | /** returns a new unique number to extend the name of | 320 | /** returns a new unique number to extend the name of |
293 | * an unnamed document. | 321 | * an unnamed document. |
294 | */ | 322 | */ |
295 | static unsigned int getNewUnnamedNumber() | 323 | static unsigned int getNewUnnamedNumber() |
296 | { return unnamedDocCnt++; } | 324 | { return unnamedDocCnt++; } |
297 | 325 | ||
298 | protected: | 326 | protected: |
299 | /* Hm, I think we shouldn't really use a "list" here, should we? | 327 | /* Hm, I think we shouldn't really use a "list" here, should we? |
300 | * So I decided to actually use a vector. | 328 | * So I decided to actually use a vector. |
301 | */ | 329 | */ |
302 | vector<listItem> docList; | 330 | vector<listItem> docList; |
303 | /** This value is used to get a new number for yet unnamed | 331 | /** This value is used to get a new number for yet unnamed |
304 | * documents. It is incremented on every request. So it's | 332 | * documents. It is incremented on every request. So it's |
@@ -670,109 +698,109 @@ protected: | |||
670 | unsigned int dataChangedLock; | 698 | unsigned int dataChangedLock; |
671 | 699 | ||
672 | /** list of all open documents */ | 700 | /** list of all open documents */ |
673 | static PwMDocList openDocList; | 701 | static PwMDocList openDocList; |
674 | 702 | ||
675 | protected: | 703 | protected: |
676 | /** serialize "dta" and return it in "d". */ | 704 | /** serialize "dta" and return it in "d". */ |
677 | bool serializeDta(string *d); | 705 | bool serializeDta(string *d); |
678 | /** de-serialize "d" and overwrite "dta" */ | 706 | /** de-serialize "d" and overwrite "dta" */ |
679 | bool deSerializeDta(const string *d, bool entriesLocked); | 707 | bool deSerializeDta(const string *d, bool entriesLocked); |
680 | /** write header to file */ | 708 | /** write header to file */ |
681 | PwMerror writeFileHeader(char keyHash, char dataHash, char crypt, char compress, | 709 | PwMerror writeFileHeader(char keyHash, char dataHash, char crypt, char compress, |
682 | QString *pw, QFile *f); | 710 | QString *pw, QFile *f); |
683 | /** write data-hash to file */ | 711 | /** write data-hash to file */ |
684 | PwMerror writeDataHash(char dataHash, string *d, QFile *f); | 712 | PwMerror writeDataHash(char dataHash, string *d, QFile *f); |
685 | /** check header. Read header info and verify key-hash and filever. | 713 | /** check header. Read header info and verify key-hash and filever. |
686 | * returns length of header in "headerLength" */ | 714 | * returns length of header in "headerLength" */ |
687 | PwMerror checkHeader(char *cryptAlgo, QString *pw, char *compress, | 715 | PwMerror checkHeader(char *cryptAlgo, QString *pw, char *compress, |
688 | unsigned int *headerLength, char *dataHashType, | 716 | unsigned int *headerLength, char *dataHashType, |
689 | string *dataHash, QFile *f); | 717 | string *dataHash, QFile *f); |
690 | /** check the data-hash */ | 718 | /** check the data-hash */ |
691 | PwMerror checkDataHash(char dataHashType, const string *dataHash, const string *dataStream); | 719 | PwMerror checkDataHash(char dataHashType, const string *dataHash, const string *dataStream); |
692 | /** encrypt data "d" and write to "filename" */ | 720 | /** encrypt data "d" and write to "filename" */ |
693 | PwMerror encrypt(string *d, const QString *pw, QFile *f, char algo); | 721 | PwMerror encrypt(string *d, const QString *pw, QFile *f, char algo); |
694 | /** read data from file beginning at "pos", decrypt and return it */ | 722 | /** read data from file beginning at "pos", decrypt and return it */ |
695 | PwMerror decrypt(string *d, unsigned int pos, const QString *pw, char algo, QFile *f); | 723 | PwMerror decrypt(string *d, unsigned int pos, const QString *pw, char algo, QFile *f); |
696 | /** compress the data */ | 724 | /** compress the data */ |
697 | bool compressDta(string *d, char algo); | 725 | bool compressDta(string *d, char algo); |
698 | /** uncompress the data */ | 726 | /** uncompress the data */ |
699 | bool decompressDta(string *d, char algo); | 727 | bool decompressDta(string *d, char algo); |
700 | /** internal import function for a text-file generated by PwM. | 728 | /** internal import function for a text-file generated by PwM. |
701 | * If this is not a valid PwM-exported file, it returns e_fileFormat */ | 729 | * If this is not a valid PwM-exported file, it returns e_fileFormat */ |
702 | PwMerror importText_PwM(const QString *file); | 730 | PwMerror importText_PwM(const QString *file); |
703 | /** PwM-text-import helper function to extract the name/pw/comment out | 731 | /** PwM-text-import helper function to extract the name/pw/comment out |
704 | * of one entry-line */ | 732 | * of one entry-line */ |
705 | bool textExtractEntry_PwM(const char *in, ssize_t in_size, string *out); | 733 | bool textExtractEntry_PwM(const char *in, ssize_t in_size, string *out); |
706 | /** compare two strings */ | 734 | /** compare two strings */ |
707 | bool compareString(const string &s1, const string &s2, bool caseSensitive, | 735 | bool compareString(const string &s1, const string &s2, bool caseSensitive, |
708 | bool exactWordMatch); | 736 | bool exactWordMatch); |
709 | /** clears all document-data */ | 737 | /** clears all document-data */ |
710 | void clearDoc(); | 738 | void clearDoc(); |
711 | /** delete all empty categories */ | 739 | /** delete all empty categories */ |
712 | void delAllEmptyCat(bool dontFlagDirty); | 740 | void delAllEmptyCat(bool dontFlagDirty); |
713 | /** set a document status flag */ | 741 | /** set a document status flag */ |
714 | void setDocStatFlag(unsigned int statFlag) | 742 | void setDocStatFlag(unsigned int statFlag) |
715 | { curDocStat |= statFlag; } | 743 | { curDocStat |= statFlag; } |
716 | /** unset a document status flag */ | 744 | /** unset a document status flag */ |
717 | void unsetDocStatFlag(unsigned int statFlag) | 745 | void unsetDocStatFlag(unsigned int statFlag) |
718 | { curDocStat &= ~statFlag; } | 746 | { curDocStat &= ~statFlag; } |
719 | /** get a document status flag */ | 747 | /** get a document status flag */ |
720 | bool getDocStatFlag(unsigned int statFlag) const | 748 | bool getDocStatFlag(unsigned int statFlag) const |
721 | { return (curDocStat & statFlag); } | 749 | { return (curDocStat & statFlag); } |
722 | /** set the "currentPassword" */ | 750 | /** set the "currentPassword" */ |
723 | void setCurrentPw(const QString &pw) | 751 | void setCurrentPw(const QString &pw) |
724 | { | 752 | { |
725 | currentPw = pw; | 753 | currentPw = pw; |
726 | setDocStatFlag(DOC_STAT_DISK_DIRTY); | 754 | setDocStatFlag(DOC_STAT_DISK_DIRTY); |
727 | } | 755 | } |
728 | /** make a backup-copy of the given file */ | 756 | /** make a backup-copy of the given file */ |
729 | bool backupFile(const QString &filePath); | 757 | bool backupFile(const QString &filePath); |
730 | /** copy a file from src to dst */ | 758 | /** copy a file from src to dst */ |
731 | bool copyFile(const QString &src, const QString &dst); | 759 | bool copyFile(const QString &src, const QString &dst); |
732 | 760 | ||
733 | 761 | ||
734 | public: | 762 | public: |
735 | #ifdef PWM_EMBEDDED | 763 | #ifdef PWM_EMBEDDED |
736 | //US ENH: this is the magic function that syncronizes the local doc with the remote doc. | 764 | //US ENH: this is the magic function that syncronizes the local doc with the remote doc. |
737 | PwMerror syncronize(KSyncManager* manager, PwMDoc* syncLocal, PwMDoc* syncRemote, int mode ); | 765 | PwMerror syncronize(KSyncManager* manager, PwMDoc* syncLocal, PwMDoc* syncRemote, int mode ); |
738 | 766 | ||
739 | //takePwMDataItem returns the following values | 767 | //takePwMDataItem returns the following values |
740 | // 0 equal | 768 | // 0 equal |
741 | // 1 take local | 769 | // 1 take local |
742 | // 2 take remote | 770 | // 2 take remote |
743 | // 3 cancel | 771 | // 3 cancel |
744 | int takePwMDataItem( PwMDataItem* local, PwMDataItem* remote, QDateTime lastSync, int mode , bool full ); | 772 | int takePwMDataItem( PwMDataItem* local, PwMDataItem* remote, QDateTime lastSync, int mode , bool full ); |
745 | 773 | ||
746 | //the following methods are the overwritten callbackmethods from the syncinterface | 774 | //the following methods are the overwritten callbackmethods from the syncinterface |
747 | virtual bool sync(KSyncManager* manager, QString filename, int mode); | 775 | virtual bool sync(KSyncManager* manager, QString filename, int mode); |
748 | 776 | ||
749 | //called by the syncmanager to indicate that the work has to be marked as dirty. | 777 | //called by the syncmanager to indicate that the work has to be marked as dirty. |
750 | virtual void sync_setModified(); | 778 | virtual void sync_setModified(); |
751 | //called by the syncmanager to ask if the dirty flag is set. | 779 | //called by the syncmanager to ask if the dirty flag is set. |
752 | virtual bool sync_isModified(); | 780 | virtual bool sync_isModified(); |
753 | //called by the syncmanager to indicate that the work has to be saved. | 781 | //called by the syncmanager to indicate that the work has to be saved. |
754 | virtual void sync_save(); | 782 | virtual void sync_save(); |
755 | 783 | ||
756 | #endif | 784 | #endif |
757 | private: | 785 | private: |
758 | //US ENH: helpermethods to access the sync data for a certain syncname. | 786 | //US ENH: helpermethods to access the sync data for a certain syncname. |
759 | // It returns the syncdatas index | 787 | // It returns the syncdatas index |
760 | bool findSyncData(const QString &syncname, unsigned int *index); | 788 | bool findSyncData(const QString &syncname, unsigned int *index); |
761 | 789 | ||
762 | /** add new syncdataentry */ | 790 | /** add new syncdataentry */ |
763 | PwMerror addSyncDataEntry(PwMSyncItem *d, bool dontFlagDirty = false); | 791 | PwMerror addSyncDataEntry(PwMSyncItem *d, bool dontFlagDirty = false); |
764 | 792 | ||
765 | /** returns a pointer to the syncdata */ | 793 | /** returns a pointer to the syncdata */ |
766 | PwMSyncItem* getSyncDataEntry(unsigned int index) | 794 | PwMSyncItem getSyncDataEntry(unsigned int index) |
767 | { return &(dti.syncDta[index]); } | 795 | { return *(dti.syncDta[index]); } |
768 | 796 | ||
769 | /** delete entry */ | 797 | /** delete entry */ |
770 | bool delSyncDataEntry(unsigned int index, bool dontFlagDirty = false); | 798 | bool delSyncDataEntry(unsigned int index, bool dontFlagDirty = false); |
771 | 799 | ||
772 | PwMDataItem* findEntryByID(const QString &uid, unsigned int *category, unsigned int *index); | 800 | PwMDataItem* findEntryByID(const QString &uid, unsigned int *category, unsigned int *index); |
773 | 801 | ||
774 | QStringList getIDEntryList(); | 802 | QStringList getIDEntryList(); |
775 | 803 | ||
776 | }; | 804 | }; |
777 | 805 | ||
778 | #endif | 806 | #endif |
diff --git a/pwmanager/pwmanager/serializer.cpp b/pwmanager/pwmanager/serializer.cpp index f615082..74b3354 100644 --- a/pwmanager/pwmanager/serializer.cpp +++ b/pwmanager/pwmanager/serializer.cpp | |||
@@ -553,193 +553,193 @@ bool Serializer::writeEntry(QDomElement *e, | |||
553 | 553 | ||
554 | tag = domDoc->createElement(ENTRY_NAME_WR); | 554 | tag = domDoc->createElement(ENTRY_NAME_WR); |
555 | curText = new_text(escapeEntryData(dta.name.c_str())); | 555 | curText = new_text(escapeEntryData(dta.name.c_str())); |
556 | tag.appendChild(curText); | 556 | tag.appendChild(curText); |
557 | e->appendChild(tag); | 557 | e->appendChild(tag); |
558 | 558 | ||
559 | tag = domDoc->createElement(ENTRY_PW_WR); | 559 | tag = domDoc->createElement(ENTRY_PW_WR); |
560 | curText = new_text(escapeEntryData(dta.pw.c_str())); | 560 | curText = new_text(escapeEntryData(dta.pw.c_str())); |
561 | tag.appendChild(curText); | 561 | tag.appendChild(curText); |
562 | e->appendChild(tag); | 562 | e->appendChild(tag); |
563 | 563 | ||
564 | tag = domDoc->createElement(ENTRY_COMMENT_WR); | 564 | tag = domDoc->createElement(ENTRY_COMMENT_WR); |
565 | curText = new_text(escapeEntryData(dta.comment.c_str())); | 565 | curText = new_text(escapeEntryData(dta.comment.c_str())); |
566 | tag.appendChild(curText); | 566 | tag.appendChild(curText); |
567 | e->appendChild(tag); | 567 | e->appendChild(tag); |
568 | 568 | ||
569 | tag = domDoc->createElement(ENTRY_URL_WR); | 569 | tag = domDoc->createElement(ENTRY_URL_WR); |
570 | curText = new_text(escapeEntryData(dta.url.c_str())); | 570 | curText = new_text(escapeEntryData(dta.url.c_str())); |
571 | tag.appendChild(curText); | 571 | tag.appendChild(curText); |
572 | e->appendChild(tag); | 572 | e->appendChild(tag); |
573 | 573 | ||
574 | tag = domDoc->createElement(ENTRY_LAUNCHER_WR); | 574 | tag = domDoc->createElement(ENTRY_LAUNCHER_WR); |
575 | curText = new_text(escapeEntryData(dta.launcher.c_str())); | 575 | curText = new_text(escapeEntryData(dta.launcher.c_str())); |
576 | tag.appendChild(curText); | 576 | tag.appendChild(curText); |
577 | e->appendChild(tag); | 577 | e->appendChild(tag); |
578 | 578 | ||
579 | tag = domDoc->createElement(ENTRY_LVP_WR); | 579 | tag = domDoc->createElement(ENTRY_LVP_WR); |
580 | plainText = domDoc->createTextNode(tostr(dta.listViewPos).c_str()); | 580 | plainText = domDoc->createTextNode(tostr(dta.listViewPos).c_str()); |
581 | tag.appendChild(plainText); | 581 | tag.appendChild(plainText); |
582 | e->appendChild(tag); | 582 | e->appendChild(tag); |
583 | 583 | ||
584 | tag = domDoc->createElement(ENTRY_BIN_WR); | 584 | tag = domDoc->createElement(ENTRY_BIN_WR); |
585 | if (dta.binary) | 585 | if (dta.binary) |
586 | plainText = domDoc->createTextNode("1"); | 586 | plainText = domDoc->createTextNode("1"); |
587 | else | 587 | else |
588 | plainText = domDoc->createTextNode("0"); | 588 | plainText = domDoc->createTextNode("0"); |
589 | tag.appendChild(plainText); | 589 | tag.appendChild(plainText); |
590 | e->appendChild(tag); | 590 | e->appendChild(tag); |
591 | 591 | ||
592 | tag = domDoc->createElement(ENTRY_META_WR); | 592 | tag = domDoc->createElement(ENTRY_META_WR); |
593 | if (!writeMeta(&tag, dta.meta)) | 593 | if (!writeMeta(&tag, dta.meta)) |
594 | return false; | 594 | return false; |
595 | e->appendChild(tag); | 595 | e->appendChild(tag); |
596 | 596 | ||
597 | #undef new_text | 597 | #undef new_text |
598 | return true; | 598 | return true; |
599 | } | 599 | } |
600 | 600 | ||
601 | bool Serializer::writeMeta(QDomElement *e, | 601 | bool Serializer::writeMeta(QDomElement *e, |
602 | const PwMMetaData &dta) | 602 | const PwMMetaData &dta) |
603 | { | 603 | { |
604 | QDomText text; | 604 | QDomText text; |
605 | QDomElement tag; | 605 | QDomElement tag; |
606 | 606 | ||
607 | tag = domDoc->createElement(META_CREATE_DATE); | 607 | tag = domDoc->createElement(META_CREATE_DATE); |
608 | #ifndef PWM_EMBEDDED | 608 | #ifndef PWM_EMBEDDED |
609 | text = domDoc->createTextNode(dta.create.toString(Qt::ISODate)); | 609 | text = domDoc->createTextNode(dta.create.toString(Qt::ISODate)); |
610 | #else | 610 | #else |
611 | text = domDoc->createTextNode(KGlobal::locale()->formatDateTime(dta.create, KLocale::ISODate)); | 611 | text = domDoc->createTextNode(KGlobal::locale()->formatDateTime(dta.create, KLocale::ISODate)); |
612 | #endif | 612 | #endif |
613 | tag.appendChild(text); | 613 | tag.appendChild(text); |
614 | e->appendChild(tag); | 614 | e->appendChild(tag); |
615 | 615 | ||
616 | tag = domDoc->createElement(META_VALID_DATE); | 616 | tag = domDoc->createElement(META_VALID_DATE); |
617 | #ifndef PWM_EMBEDDED | 617 | #ifndef PWM_EMBEDDED |
618 | text = domDoc->createTextNode(dta.valid.toString(Qt::ISODate)); | 618 | text = domDoc->createTextNode(dta.valid.toString(Qt::ISODate)); |
619 | #else | 619 | #else |
620 | text = domDoc->createTextNode(KGlobal::locale()->formatDateTime(dta.valid, KLocale::ISODate)); | 620 | text = domDoc->createTextNode(KGlobal::locale()->formatDateTime(dta.valid, KLocale::ISODate)); |
621 | #endif | 621 | #endif |
622 | tag.appendChild(text); | 622 | tag.appendChild(text); |
623 | e->appendChild(tag); | 623 | e->appendChild(tag); |
624 | 624 | ||
625 | tag = domDoc->createElement(META_EXPIRE_DATE); | 625 | tag = domDoc->createElement(META_EXPIRE_DATE); |
626 | #ifndef PWM_EMBEDDED | 626 | #ifndef PWM_EMBEDDED |
627 | text = domDoc->createTextNode(dta.expire.toString(Qt::ISODate)); | 627 | text = domDoc->createTextNode(dta.expire.toString(Qt::ISODate)); |
628 | #else | 628 | #else |
629 | text = domDoc->createTextNode(KGlobal::locale()->formatDateTime(dta.expire, KLocale::ISODate)); | 629 | text = domDoc->createTextNode(KGlobal::locale()->formatDateTime(dta.expire, KLocale::ISODate)); |
630 | #endif | 630 | #endif |
631 | tag.appendChild(text); | 631 | tag.appendChild(text); |
632 | e->appendChild(tag); | 632 | e->appendChild(tag); |
633 | 633 | ||
634 | tag = domDoc->createElement(META_UPDATE_DATE); | 634 | tag = domDoc->createElement(META_UPDATE_DATE); |
635 | #ifndef PWM_EMBEDDED | 635 | #ifndef PWM_EMBEDDED |
636 | text = domDoc->createTextNode(dta.update.toString(Qt::ISODate)); | 636 | text = domDoc->createTextNode(dta.update.toString(Qt::ISODate)); |
637 | #else | 637 | #else |
638 | text = domDoc->createTextNode(KGlobal::locale()->formatDateTime(dta.update, KLocale::ISODate)); | 638 | text = domDoc->createTextNode(KGlobal::locale()->formatDateTime(dta.update, KLocale::ISODate)); |
639 | #endif | 639 | #endif |
640 | tag.appendChild(text); | 640 | tag.appendChild(text); |
641 | e->appendChild(tag); | 641 | e->appendChild(tag); |
642 | 642 | ||
643 | tag = domDoc->createElement(META_UPDATE_INT); | 643 | tag = domDoc->createElement(META_UPDATE_INT); |
644 | text = domDoc->createTextNode(tostr(dta.updateInt).c_str()); | 644 | text = domDoc->createTextNode(tostr(dta.updateInt).c_str()); |
645 | tag.appendChild(text); | 645 | tag.appendChild(text); |
646 | e->appendChild(tag); | 646 | e->appendChild(tag); |
647 | 647 | ||
648 | tag = domDoc->createElement(META_UNIQUEID); | 648 | tag = domDoc->createElement(META_UNIQUEID); |
649 | text = domDoc->createTextNode(escapeEntryData(dta.uniqueid)); | 649 | text = domDoc->createTextNode(escapeEntryData(dta.uniqueid.c_str())); |
650 | tag.appendChild(text); | 650 | tag.appendChild(text); |
651 | e->appendChild(tag); | 651 | e->appendChild(tag); |
652 | 652 | ||
653 | #undef new_text | 653 | #undef new_text |
654 | return true; | 654 | return true; |
655 | } | 655 | } |
656 | 656 | ||
657 | QString Serializer::escapeEntryData(QString dta) | 657 | QString Serializer::escapeEntryData(QString dta) |
658 | { | 658 | { |
659 | #ifndef PWM_EMBEDDED | 659 | #ifndef PWM_EMBEDDED |
660 | dta.replace('\n', "$>--endl--<$"); | 660 | dta.replace('\n', "$>--endl--<$"); |
661 | dta.replace("]]>", "||>"); | 661 | dta.replace("]]>", "||>"); |
662 | #else | 662 | #else |
663 | dta.replace(QRegExp("\n"), "$>--endl--<$"); | 663 | dta.replace(QRegExp("\n"), "$>--endl--<$"); |
664 | dta.replace(QRegExp("]]>"), "||>"); | 664 | dta.replace(QRegExp("]]>"), "||>"); |
665 | #endif | 665 | #endif |
666 | return dta; | 666 | return dta; |
667 | } | 667 | } |
668 | 668 | ||
669 | QString Serializer::unescapeEntryData(QString dta) | 669 | QString Serializer::unescapeEntryData(QString dta) |
670 | { | 670 | { |
671 | #ifndef PWM_EMBEDDED | 671 | #ifndef PWM_EMBEDDED |
672 | dta.replace("$>--endl--<$", "\n"); | 672 | dta.replace("$>--endl--<$", "\n"); |
673 | dta.replace("||>", "]]>"); | 673 | dta.replace("||>", "]]>"); |
674 | #else | 674 | #else |
675 | dta.replace(QRegExp("$>--endl--<$"), "\n"); | 675 | dta.replace(QRegExp("$>--endl--<$"), "\n"); |
676 | dta.replace(QRegExp("||>"), "]]>"); | 676 | dta.replace(QRegExp("||>"), "]]>"); |
677 | #endif | 677 | #endif |
678 | return dta; | 678 | return dta; |
679 | } | 679 | } |
680 | 680 | ||
681 | 681 | ||
682 | //US ENH: the following methods are getting used to write/read sync entries | 682 | //US ENH: the following methods are getting used to write/read sync entries |
683 | /** read the syncentries in the node "n" */ | 683 | /** read the syncentries in the node "n" */ |
684 | bool Serializer::readSyncData(const QDomNode &n, vector<PwMSyncItem> *dta) | 684 | bool Serializer::readSyncData(const QDomNode &n, vector<PwMSyncItem> *dta) |
685 | { | 685 | { |
686 | QDomNodeList nl(n.childNodes()); | 686 | QDomNodeList nl(n.childNodes()); |
687 | QDomNode cur; | 687 | QDomNode cur; |
688 | 688 | ||
689 | QString devicename, val; | 689 | QString devicename, val; |
690 | unsigned int numSync = nl.count(), i; | 690 | unsigned int numSync = nl.count(), i; |
691 | PwMSyncItem curSync; | 691 | PwMSyncItem curSync; |
692 | bool ok = true; | 692 | bool ok = true; |
693 | 693 | ||
694 | if (!numSync) { | 694 | if (!numSync) { |
695 | //no sync entries is a possible result | 695 | //no sync entries is a possible result |
696 | printDebug("Serializer::readSyncData(): empty"); | 696 | printDebug("Serializer::readSyncData(): empty"); |
697 | return true; | 697 | return true; |
698 | } | 698 | } |
699 | for (i = 0; i < numSync; ++i) { | 699 | for (i = 0; i < numSync; ++i) { |
700 | cur = nl.item(i); | 700 | cur = nl.item(i); |
701 | if (cur.nodeName().left(1) == SYNC_TARGET_PREFIX) { | 701 | if (cur.nodeName().left(1) == SYNC_TARGET_PREFIX) { |
702 | devicename = cur.toElement().attribute(SYNC_TARGET_NAME); | 702 | devicename = cur.toElement().attribute(SYNC_TARGET_NAME); |
703 | val = cur.toElement().text(); | 703 | val = cur.toElement().text(); |
704 | 704 | ||
705 | if ((val == "") || (devicename == QString::null)) { | 705 | if ((val == "") || (devicename == QString::null)) { |
706 | printDebug("Serializer::readSyncData(): empty synctarget name or syncdate"); | 706 | printDebug("Serializer::readSyncData(): empty synctarget name or syncdate"); |
707 | continue; | 707 | continue; |
708 | } | 708 | } |
709 | 709 | ||
710 | curSync.syncName = devicename; | 710 | curSync.syncName = devicename; |
711 | #ifndef PWM_EMBEDDED | 711 | #ifndef PWM_EMBEDDED |
712 | curSync.lastSyncDate = QDateTime::fromString(val, Qt::ISODate); | 712 | curSync.lastSyncDate = QDateTime::fromString(val, Qt::ISODate); |
713 | #else | 713 | #else |
714 | curSync.lastSyncDate = KGlobal::locale()->readDateTime(val, KLocale::ISODate, &ok); | 714 | curSync.lastSyncDate = KGlobal::locale()->readDateTime(val, KLocale::ISODate, &ok); |
715 | if (ok == false) | 715 | if (ok == false) |
716 | qDebug("Serializer::readSyncData(): could not parse syncdate:%s",val.latin1()); | 716 | qDebug("Serializer::readSyncData(): could not parse syncdate:%s",val.latin1()); |
717 | 717 | ||
718 | #endif | 718 | #endif |
719 | dta->push_back(curSync); | 719 | dta->push_back(curSync); |
720 | } | 720 | } |
721 | } | 721 | } |
722 | return true; | 722 | return true; |
723 | 723 | ||
724 | } | 724 | } |
725 | 725 | ||
726 | 726 | ||
727 | 727 | ||
728 | bool Serializer::addSyncData(QDomElement *e, | 728 | bool Serializer::addSyncData(QDomElement *e, |
729 | const vector<PwMSyncItem> &dta) | 729 | const vector<PwMSyncItem> &dta) |
730 | { | 730 | { |
731 | unsigned int numSync = dta.size(), i; | 731 | unsigned int numSync = dta.size(), i; |
732 | QString curId, curDeviceName; | 732 | QString curId, curDeviceName; |
733 | QDomElement curSync, curSyncDate; | 733 | QDomElement curSync, curSyncDate; |
734 | QDomText text; | 734 | QDomText text; |
735 | 735 | ||
736 | for (i = 0; i < numSync; ++i) { | 736 | for (i = 0; i < numSync; ++i) { |
737 | curId = SYNC_TARGET_PREFIX; | 737 | curId = SYNC_TARGET_PREFIX; |
738 | curId += tostr(i).c_str(); | 738 | curId += tostr(i).c_str(); |
739 | curDeviceName = dta[i].syncName.c_str(); | 739 | curDeviceName = dta[i].syncName.c_str(); |
740 | curSync = domDoc->createElement(curId); | 740 | curSync = domDoc->createElement(curId); |
741 | curSync.setAttribute(SYNC_TARGET_NAME, curDeviceName); | 741 | curSync.setAttribute(SYNC_TARGET_NAME, curDeviceName); |
742 | 742 | ||
743 | #ifndef PWM_EMBEDDED | 743 | #ifndef PWM_EMBEDDED |
744 | text = domDoc->createTextNode(dta[i].lastSyncDate.toString(Qt::ISODate)); | 744 | text = domDoc->createTextNode(dta[i].lastSyncDate.toString(Qt::ISODate)); |
745 | #else | 745 | #else |