-rw-r--r-- | pwmanager/pwmanager/pwmdoc.cpp | 102 | ||||
-rw-r--r-- | pwmanager/pwmanager/pwmdoc.h | 23 |
2 files changed, 60 insertions, 65 deletions
diff --git a/pwmanager/pwmanager/pwmdoc.cpp b/pwmanager/pwmanager/pwmdoc.cpp index 2a7b11d..e9906a4 100644 --- a/pwmanager/pwmanager/pwmdoc.cpp +++ b/pwmanager/pwmanager/pwmdoc.cpp | |||
@@ -2781,109 +2781,130 @@ PwMerror PwMDoc::importFromGpasman(const QString *file) | |||
2781 | if(ret != 1) | 2781 | if(ret != 1) |
2782 | break; | 2782 | break; |
2783 | tmpData.desc = entry[0]; | 2783 | tmpData.desc = entry[0]; |
2784 | tmpData.name = entry[1]; | 2784 | tmpData.name = entry[1]; |
2785 | tmpData.pw = entry[2]; | 2785 | tmpData.pw = entry[2]; |
2786 | tmpData.comment = entry[3]; | 2786 | tmpData.comment = entry[3]; |
2787 | tmpData.lockStat = true; | 2787 | tmpData.lockStat = true; |
2788 | tmpData.listViewPos = -1; | 2788 | tmpData.listViewPos = -1; |
2789 | ret2 = addEntry(DEFAULT_CATEGORY, &tmpData, true); | 2789 | ret2 = addEntry(DEFAULT_CATEGORY, &tmpData, true); |
2790 | for (i = 0; i < 4; ++i) | 2790 | for (i = 0; i < 4; ++i) |
2791 | free(entry[i]); | 2791 | free(entry[i]); |
2792 | if (ret2 == e_maxAllowedEntr) { | 2792 | if (ret2 == e_maxAllowedEntr) { |
2793 | gp.load_finalize(); | 2793 | gp.load_finalize(); |
2794 | return e_maxAllowedEntr; | 2794 | return e_maxAllowedEntr; |
2795 | } | 2795 | } |
2796 | } while (1); | 2796 | } while (1); |
2797 | gp.load_finalize(); | 2797 | gp.load_finalize(); |
2798 | if (isDocEmpty()) | 2798 | if (isDocEmpty()) |
2799 | return e_wrongPw; // we assume this. | 2799 | return e_wrongPw; // we assume this. |
2800 | 2800 | ||
2801 | flagDirty(); | 2801 | flagDirty(); |
2802 | return e_success; | 2802 | return e_success; |
2803 | } | 2803 | } |
2804 | 2804 | ||
2805 | |||
2806 | //US: we use the stl sort algorythm to sort all elements in the order | ||
2807 | //of its listViewPos (in the order 1,2,3,5,...,x,-1, -1, -1 | ||
2808 | struct PwMDataItemListViewPosSort | ||
2809 | { | ||
2810 | bool operator()(PwMDataItem* rpStart, PwMDataItem* rpEnd) | ||
2811 | { | ||
2812 | //qDebug("pwMDoc::PwMDataItemListViewPosSort()"); | ||
2813 | if ((rpEnd)->listViewPos < 0) | ||
2814 | return false; | ||
2815 | else | ||
2816 | return (rpStart)->listViewPos < (rpEnd)->listViewPos; | ||
2817 | } | ||
2818 | }; | ||
2819 | |||
2805 | void PwMDoc::ensureLvp() | 2820 | void PwMDoc::ensureLvp() |
2806 | { | 2821 | { |
2807 | if (isDocEmpty()) | 2822 | if (isDocEmpty()) |
2808 | return; | 2823 | return; |
2809 | 2824 | ||
2810 | //US ENH BUG: when using syncronizing, this way of sorting | 2825 | //US ENH BUG: when using syncronizing, this way of sorting |
2811 | //is not sufficient, because there might be empty spaces | 2826 | //is not sufficient, because there might be empty spaces |
2812 | // at the beginning. But this algorythm only can add elements | 2827 | // at the beginning. But the old algorythm only can add elements |
2813 | //to the end.The result are crashes because of listoverflows | 2828 | //to the end.The result are crashes because of list overflows |
2814 | //we need something to fill all gaps. | 2829 | //we need something to fill all gaps. |
2815 | vector< vector<PwMDataItem>::iterator > undefined; | 2830 | vector<PwMDataItem*> sorted; |
2816 | vector< vector<PwMDataItem>::iterator > sorted; | 2831 | vector< PwMDataItem*>::iterator sortedBegin, |
2817 | vector< vector<PwMDataItem>::iterator >::iterator undefBegin, | 2832 | sortedEnd, |
2818 | undefEnd, | 2833 | sortedI; |
2819 | undefI; | ||
2820 | vector< vector<PwMDataItem>::iterator >::iterator sortedBegin, | ||
2821 | sortedEnd, | ||
2822 | sortedI; | ||
2823 | vector<PwMCategoryItem>::iterator catBegin = dti.dta.begin(), | 2834 | vector<PwMCategoryItem>::iterator catBegin = dti.dta.begin(), |
2824 | catEnd = dti.dta.end(), | 2835 | catEnd = dti.dta.end(), |
2825 | catI = catBegin; | 2836 | catI = catBegin; |
2826 | vector<PwMDataItem>::iterator entrBegin, entrEnd, entrI; | 2837 | vector<PwMDataItem>::iterator entrBegin, entrEnd, entrI; |
2827 | int lvpTop, tmpLvp; | 2838 | int lvpTop, tmpLvp; |
2828 | 2839 | ||
2840 | //qDebug("collect:"); | ||
2841 | |||
2829 | while (catI != catEnd) { | 2842 | while (catI != catEnd) { |
2830 | lvpTop = -1; | 2843 | lvpTop = -1; |
2831 | undefined.clear(); | 2844 | sorted.clear(); |
2832 | 2845 | ||
2833 | entrBegin = catI->d.begin(); | 2846 | entrBegin = catI->d.begin(); |
2834 | entrEnd = catI->d.end(); | 2847 | entrEnd = catI->d.end(); |
2835 | entrI = entrBegin; | 2848 | entrI = entrBegin; |
2836 | 2849 | ||
2850 | //US: we use the stl sort algorythm to sort all elements in the order | ||
2851 | //of its listViewPos (in the order 1,2,2,3,5,...,x,-1, -1, -1 | ||
2837 | while (entrI != entrEnd) { | 2852 | while (entrI != entrEnd) { |
2838 | tmpLvp = entrI->listViewPos; | 2853 | //qDebug("found: %s, pos=%i", (*entrI).desc.c_str(), (*entrI).listViewPos); |
2839 | if (tmpLvp == -1) | 2854 | sorted.push_back((PwMDataItem*)&(*entrI)); |
2840 | undefined.push_back(entrI); | 2855 | ++entrI; |
2841 | else | ||
2842 | sorted[tmpLvp] = entrI; | ||
2843 | //US else if (tmpLvp > lvpTop) | ||
2844 | //US lvpTop = tmpLvp; | ||
2845 | ++entrI; | ||
2846 | } | 2856 | } |
2847 | 2857 | ||
2848 | //now we have all undefied in the collection. Now insert the existing | 2858 | sortedBegin = sorted.begin(); |
2859 | sortedEnd = sorted.end(); | ||
2860 | |||
2861 | sort(sortedBegin, sortedEnd, PwMDataItemListViewPosSort()); | ||
2862 | |||
2863 | // qDebug("resort:"); | ||
2864 | //now we have all sorted in a collection | ||
2865 | //Now start with the sorted and reset listviewpos. | ||
2849 | sortedBegin = sorted.begin(); | 2866 | sortedBegin = sorted.begin(); |
2850 | sortedEnd = sorted.end(); | 2867 | sortedEnd = sorted.end(); |
2851 | sortedI = sortedBegin; | 2868 | sortedI = sortedBegin; |
2852 | 2869 | ||
2853 | while (sortedI != sortedEnd) { | 2870 | while (sortedI != sortedEnd) { |
2854 | tmpLvp = (*sortedI)->listViewPos; | 2871 | // qDebug("reset defined: %s, from pos=%i to pos=%i", (*sortedI)->desc.c_str(), (*sortedI)->listViewPos, lvpTop+1); |
2855 | undefined[tmpLvp] = *sortedI; | 2872 | (*sortedI)->listViewPos = ++lvpTop; |
2856 | ++sortedI; | 2873 | ++sortedI; |
2857 | } | 2874 | } |
2858 | 2875 | ||
2859 | undefBegin = undefined.begin(); | 2876 | /*/debug |
2860 | undefEnd = undefined.end(); | 2877 | entrBegin = catI->d.begin(); |
2861 | undefI = undefBegin; | 2878 | entrEnd = catI->d.end(); |
2862 | while (undefI != undefEnd) { | 2879 | entrI = entrBegin; |
2863 | (*undefI)->listViewPos = ++lvpTop; | 2880 | |
2864 | ++undefI; | 2881 | while (entrI != entrEnd) { |
2882 | qDebug("check: %s, pos=%i", (*entrI).desc.c_str(), (*entrI).listViewPos); | ||
2883 | ++entrI; | ||
2865 | } | 2884 | } |
2885 | */ | ||
2886 | |||
2866 | ++catI; | 2887 | ++catI; |
2867 | } | 2888 | } |
2868 | } | 2889 | } |
2869 | 2890 | ||
2870 | QString PwMDoc::getTitle() | 2891 | QString PwMDoc::getTitle() |
2871 | { | 2892 | { |
2872 | /* NOTE: We have to ensure, that the returned title | 2893 | /* NOTE: We have to ensure, that the returned title |
2873 | * is unique and not reused somewhere else while | 2894 | * is unique and not reused somewhere else while |
2874 | * this document is valid (open). | 2895 | * this document is valid (open). |
2875 | */ | 2896 | */ |
2876 | QString title(getFilename()); | 2897 | QString title(getFilename()); |
2877 | 2898 | ||
2878 | //US ENH: The whole filename on PDAs is too long. So use only the last characters | 2899 | //US ENH: The whole filename on PDAs is too long. So use only the last characters |
2879 | if (QApplication::desktop()->width() < 640) | 2900 | if (QApplication::desktop()->width() < 640) |
2880 | { | 2901 | { |
2881 | if (title.length() > 30) | 2902 | if (title.length() > 30) |
2882 | title = "..." + title.right(30); | 2903 | title = "..." + title.right(30); |
2883 | 2904 | ||
2884 | } | 2905 | } |
2885 | 2906 | ||
2886 | 2907 | ||
2887 | if (title.isEmpty()) { | 2908 | if (title.isEmpty()) { |
2888 | if (unnamedNum == 0) { | 2909 | if (unnamedNum == 0) { |
2889 | unnamedNum = PwMDocList::getNewUnnamedNumber(); | 2910 | unnamedNum = PwMDocList::getNewUnnamedNumber(); |
@@ -2975,102 +2996,100 @@ PwMerror PwMDoc::syncronize(KSyncManager* manager, PwMDoc* syncLocal , PwMDoc* s | |||
2975 | newSyncItemRemote.syncName = mCurrentSyncName; | 2996 | newSyncItemRemote.syncName = mCurrentSyncName; |
2976 | newSyncItemRemote.lastSyncDate = mLastSync; | 2997 | newSyncItemRemote.lastSyncDate = mLastSync; |
2977 | syncRemote->addSyncDataEntry(&newSyncItemRemote, true); | 2998 | syncRemote->addSyncDataEntry(&newSyncItemRemote, true); |
2978 | found = syncRemote->findSyncData(mCurrentSyncName, &index); | 2999 | found = syncRemote->findSyncData(mCurrentSyncName, &index); |
2979 | if (found == false) { | 3000 | if (found == false) { |
2980 | qDebug("PwMDoc::syncronize : newly created remote sync data could not be found"); | 3001 | qDebug("PwMDoc::syncronize : newly created remote sync data could not be found"); |
2981 | return e_syncError; | 3002 | return e_syncError; |
2982 | } | 3003 | } |
2983 | } | 3004 | } |
2984 | 3005 | ||
2985 | syncItemRemote = syncRemote->getSyncDataEntry(index); | 3006 | syncItemRemote = syncRemote->getSyncDataEntry(index); |
2986 | qDebug("Last Sync Remote %s ", syncItemRemote->lastSyncDate.toString().latin1()); | 3007 | qDebug("Last Sync Remote %s ", syncItemRemote->lastSyncDate.toString().latin1()); |
2987 | //and remove the found entry here. We will reenter it later again. | 3008 | //and remove the found entry here. We will reenter it later again. |
2988 | //US syncRemote->delSyncDataEntry(index, true); | 3009 | //US syncRemote->delSyncDataEntry(index, true); |
2989 | 3010 | ||
2990 | 3011 | ||
2991 | if ( syncItemLocal->lastSyncDate == mLastSync ) { | 3012 | if ( syncItemLocal->lastSyncDate == mLastSync ) { |
2992 | qDebug("FULLDATE 2"); | 3013 | qDebug("FULLDATE 2"); |
2993 | fullDateRange = true; | 3014 | fullDateRange = true; |
2994 | } | 3015 | } |
2995 | 3016 | ||
2996 | if ( ! fullDateRange ) { | 3017 | if ( ! fullDateRange ) { |
2997 | if ( syncItemLocal->lastSyncDate != syncItemRemote->lastSyncDate ) { | 3018 | if ( syncItemLocal->lastSyncDate != syncItemRemote->lastSyncDate ) { |
2998 | 3019 | ||
2999 | // qDebug("set fulldate to true %s %s" ,syncItemLocal->lastSyncDate.toString().latin1(), syncItemRemote->lastSyncDate.toString().latin1() ); | ||
3000 | // qDebug("%d %d %d %d ", syncItemLocal->lastSyncDate.time().second(), addresseeLSync->dtStart().time().msec() , addresseeRSync->dtStart().time().second(), addresseeRSync->dtStart().time().msec()); | ||
3001 | fullDateRange = true; | 3020 | fullDateRange = true; |
3002 | qDebug("FULLDATE 3 %s %s", syncItemLocal->lastSyncDate.toString().latin1() , syncItemRemote->lastSyncDate.toString().latin1() ); | 3021 | qDebug("FULLDATE 3 %s %s", syncItemLocal->lastSyncDate.toString().latin1() , syncItemRemote->lastSyncDate.toString().latin1() ); |
3003 | } | 3022 | } |
3004 | } | 3023 | } |
3005 | // fullDateRange = true; // debug only! | 3024 | // fullDateRange = true; // debug only! |
3006 | if ( fullDateRange ) | 3025 | if ( fullDateRange ) |
3007 | mLastSync = QDateTime::currentDateTime().addDays( -100*365); | 3026 | mLastSync = QDateTime::currentDateTime().addDays( -100*365); |
3008 | else | 3027 | else |
3009 | mLastSync = syncItemLocal->lastSyncDate; | 3028 | mLastSync = syncItemLocal->lastSyncDate; |
3010 | 3029 | ||
3011 | 3030 | ||
3012 | qDebug("*************************** "); | 3031 | qDebug("*************************** "); |
3013 | qDebug("mLastSync %s ",mLastSync.toString().latin1() ); | 3032 | qDebug("mLastSync %s ",mLastSync.toString().latin1() ); |
3014 | QStringList er = syncRemote->getIDEntryList(); | 3033 | QStringList er = syncRemote->getIDEntryList(); |
3015 | PwMDataItem* inRemote ;//= er.first(); | 3034 | PwMDataItem* inRemote ;//= er.first(); |
3016 | PwMDataItem* inLocal; | 3035 | PwMDataItem* inLocal; |
3017 | unsigned int catLocal, indexLocal; | 3036 | unsigned int catLocal, indexLocal; |
3018 | unsigned int catRemote, indexRemote; | 3037 | unsigned int catRemote, indexRemote; |
3019 | 3038 | ||
3020 | QString uid; | 3039 | QString uid; |
3021 | manager->showProgressBar(0, i18n("Syncing - close to abort!"), er.count()); | 3040 | manager->showProgressBar(0, i18n("Syncing - close to abort!"), er.count()); |
3022 | 3041 | ||
3023 | int modulo = (er.count()/10)+1; | 3042 | int modulo = (er.count()/10)+1; |
3024 | unsigned int incCounter = 0; | 3043 | unsigned int incCounter = 0; |
3025 | while ( incCounter < er.count()) { | 3044 | while ( incCounter < er.count()) { |
3026 | if (manager->isProgressBarCanceled()) | 3045 | if (manager->isProgressBarCanceled()) |
3027 | return e_syncError; | 3046 | return e_syncError; |
3028 | if ( incCounter % modulo == 0 ) | 3047 | if ( incCounter % modulo == 0 ) |
3029 | manager->showProgressBar(incCounter); | 3048 | manager->showProgressBar(incCounter); |
3030 | 3049 | ||
3031 | uid = er[ incCounter ]; | 3050 | uid = er[ incCounter ]; |
3032 | qDebug("sync uid %s from remote file", uid.latin1()); | 3051 | qDebug("sync uid %s from remote file", uid.latin1()); |
3033 | 3052 | ||
3034 | qApp->processEvents(); | 3053 | qApp->processEvents(); |
3035 | 3054 | ||
3036 | inLocal = syncLocal->findEntryByID( uid, &catLocal, &indexLocal ); | 3055 | inLocal = syncLocal->findEntryByID( uid, &catLocal, &indexLocal ); |
3037 | inRemote = syncRemote->findEntryByID( uid, &catRemote, &indexRemote ); | 3056 | inRemote = syncRemote->findEntryByID( uid, &catRemote, &indexRemote ); |
3038 | PWM_ASSERT(inRemote); | 3057 | PWM_ASSERT(inRemote); |
3039 | if ( inLocal != 0 ) { // maybe conflict - same uid in both files | 3058 | if ( inLocal != 0 ) { // maybe conflict - same uid in both files |
3040 | if ( (take = takePwMDataItem( inLocal, inRemote, mLastSync, mode, fullDateRange) ) ) { | 3059 | if ( (take = takePwMDataItem( inLocal, inRemote, mLastSync, mode, fullDateRange) ) ) { |
3041 | qDebug("take %d %s ", take, inLocal->desc.c_str()); | 3060 | qDebug("take %d %s ", take, inLocal->desc.c_str()); |
3042 | if ( take == 3 ) | 3061 | if ( take == 3 ) |
3043 | return e_syncError; | 3062 | return e_syncError; |
3044 | if ( take == 1 ) {// take local | 3063 | if ( take == 1 ) {// take local |
3045 | //US syncRemote->removeAddressee( inRemote ); | 3064 | int oldlistpos = inRemote->listViewPos; |
3046 | (*inRemote) = (*inLocal); | 3065 | (*inRemote) = (*inLocal); |
3047 | //US syncRemote->insertAddressee( inRemote , false); | 3066 | inRemote->listViewPos = oldlistpos; |
3048 | ++changedRemote; | 3067 | ++changedRemote; |
3049 | } else { // take == 2 take remote | 3068 | } else { // take == 2 take remote |
3050 | //US syncLocal->removeAddressee( inLocal ); | 3069 | int oldlistpos = inLocal->listViewPos; |
3051 | (*inLocal) = (*inRemote); | 3070 | (*inLocal) = (*inRemote); |
3052 | //US syncLocal->insertAddressee( inLocal , false ); | 3071 | inLocal->listViewPos = oldlistpos; |
3053 | ++changedLocal; | 3072 | ++changedLocal; |
3054 | } | 3073 | } |
3055 | } | 3074 | } |
3056 | } else { // no conflict | 3075 | } else { // no conflict |
3057 | if ( inRemote->meta.update > mLastSync || mode == 5 ) { | 3076 | if ( inRemote->meta.update > mLastSync || mode == 5 ) { |
3058 | inRemote->meta.update = modifiedSync; | 3077 | inRemote->meta.update = modifiedSync; |
3059 | 3078 | ||
3060 | //first check if we have a matching category in the local file | 3079 | //first check if we have a matching category in the local file |
3061 | const string* remotecat = syncRemote->getCategory(catRemote); | 3080 | const string* remotecat = syncRemote->getCategory(catRemote); |
3062 | //US syncRemote->insertAddressee( inRemote, false ); | 3081 | //US syncRemote->insertAddressee( inRemote, false ); |
3063 | //US syncLocal->insertAddressee( inRemote, false ); | 3082 | //US syncLocal->insertAddressee( inRemote, false ); |
3064 | syncLocal->addEntry(remotecat->c_str(), inRemote, true, false); | 3083 | syncLocal->addEntry(remotecat->c_str(), inRemote, true, false); |
3065 | 3084 | ||
3066 | ++addedPasswordsLocal; | 3085 | ++addedPasswordsLocal; |
3067 | } else { | 3086 | } else { |
3068 | // pending checkExternSyncAddressee(addresseeRSyncSharp, inR); | 3087 | // pending checkExternSyncAddressee(addresseeRSyncSharp, inR); |
3069 | syncRemote->delEntry(catRemote, indexRemote, true); | 3088 | syncRemote->delEntry(catRemote, indexRemote, true); |
3070 | //USsyncRemote->removeAddressee( inRemote ); | 3089 | //USsyncRemote->removeAddressee( inRemote ); |
3071 | ++deletedPasswordsRemote; | 3090 | ++deletedPasswordsRemote; |
3072 | } | 3091 | } |
3073 | } | 3092 | } |
3074 | 3093 | ||
3075 | ++incCounter; | 3094 | ++incCounter; |
3076 | } | 3095 | } |
@@ -3116,91 +3135,86 @@ PwMerror PwMDoc::syncronize(KSyncManager* manager, PwMDoc* syncLocal , PwMDoc* s | |||
3116 | 3135 | ||
3117 | //USsyncRemote->insertAddressee( inRemote, false ); | 3136 | //USsyncRemote->insertAddressee( inRemote, false ); |
3118 | syncRemote->addEntry(localcat->c_str(), inRemote, true, false); | 3137 | syncRemote->addEntry(localcat->c_str(), inRemote, true, false); |
3119 | 3138 | ||
3120 | } | 3139 | } |
3121 | } | 3140 | } |
3122 | 3141 | ||
3123 | } | 3142 | } |
3124 | ++incCounter; | 3143 | ++incCounter; |
3125 | } | 3144 | } |
3126 | el.clear(); | 3145 | el.clear(); |
3127 | manager->hideProgressBar(); | 3146 | manager->hideProgressBar(); |
3128 | 3147 | ||
3129 | // Now write the info back into the sync data space of the files | 3148 | // Now write the info back into the sync data space of the files |
3130 | 3149 | ||
3131 | mLastSync = QDateTime::currentDateTime().addSecs( 1 ); | 3150 | mLastSync = QDateTime::currentDateTime().addSecs( 1 ); |
3132 | // get rid of micro seconds | 3151 | // get rid of micro seconds |
3133 | QTime t = mLastSync.time(); | 3152 | QTime t = mLastSync.time(); |
3134 | mLastSync.setTime( QTime (t.hour (), t.minute (), t.second () ) ); | 3153 | mLastSync.setTime( QTime (t.hour (), t.minute (), t.second () ) ); |
3135 | 3154 | ||
3136 | 3155 | ||
3137 | syncItemLocal->lastSyncDate = mLastSync; | 3156 | syncItemLocal->lastSyncDate = mLastSync; |
3138 | syncItemRemote->lastSyncDate = mLastSync; | 3157 | syncItemRemote->lastSyncDate = mLastSync; |
3139 | 3158 | ||
3140 | // addresseeRSync.setRole( i18n("!Remote from: ")+mCurrentSyncName ) ; | ||
3141 | // addresseeLSync.setRole(i18n("!Local from: ") + mCurrentSyncName ); | ||
3142 | |||
3143 | //US syncRemote->addSyncDataEntry( syncItemRemote, false ); | ||
3144 | //US syncLocal->addSyncDataEntry( syncItemLocal, false ); | ||
3145 | QString mes; | 3159 | QString mes; |
3146 | mes .sprintf( i18n("Synchronization summary:\n\n %d items added to local\n %d items added to remote\n %d items updated on local\n %d items updated on remote\n %d items deleted on local\n %d items deleted on remote\n"),addedPasswordsLocal, addedPasswordsRemote, changedLocal, changedRemote, deletedPasswordsLocal, deletedPasswordsRemote ); | 3160 | mes .sprintf( i18n("Synchronization summary:\n\n %d items added to local\n %d items added to remote\n %d items updated on local\n %d items updated on remote\n %d items deleted on local\n %d items deleted on remote\n"),addedPasswordsLocal, addedPasswordsRemote, changedLocal, changedRemote, deletedPasswordsLocal, deletedPasswordsRemote ); |
3147 | if ( manager->mShowSyncSummary ) { | 3161 | if ( manager->mShowSyncSummary ) { |
3148 | KMessageBox::information(0, mes, i18n("PWM/Pi Synchronization") ); | 3162 | KMessageBox::information(0, mes, i18n("PWM/Pi Synchronization") ); |
3149 | } | 3163 | } |
3150 | qDebug( mes ); | 3164 | qDebug( mes ); |
3151 | return e_success; | 3165 | return e_success; |
3152 | } | 3166 | } |
3153 | 3167 | ||
3154 | 3168 | ||
3155 | int PwMDoc::takePwMDataItem( PwMDataItem* local, PwMDataItem* remote, QDateTime lastSync, int mode , bool full ) | 3169 | int PwMDoc::takePwMDataItem( PwMDataItem* local, PwMDataItem* remote, QDateTime lastSync, int mode , bool full ) |
3156 | { | 3170 | { |
3157 | // 0 equal | 3171 | // 0 equal |
3158 | // 1 take local | 3172 | // 1 take local |
3159 | // 2 take remote | 3173 | // 2 take remote |
3160 | // 3 cancel | 3174 | // 3 cancel |
3161 | QDateTime localMod = local->meta.update; | 3175 | QDateTime localMod = local->meta.update; |
3162 | QDateTime remoteMod = remote->meta.update; | 3176 | QDateTime remoteMod = remote->meta.update; |
3163 | 3177 | ||
3164 | //US QString mCurrentSyncDevice = syncManager->getCurrentSyncDevice(); | 3178 | //US QString mCurrentSyncDevice = syncManager->getCurrentSyncDevice(); |
3165 | 3179 | ||
3166 | if ( localMod == remoteMod ) | 3180 | if ( localMod == remoteMod ) |
3167 | return 0; | 3181 | return 0; |
3168 | 3182 | ||
3169 | qDebug(" %d %d conflict on %s %s ", mode, full, local->desc.c_str(), remote->desc.c_str() ); | 3183 | qDebug(" %d %d conflict on %s %s ", mode, full, local->desc.c_str(), remote->desc.c_str() ); |
3170 | 3184 | ||
3171 | //qDebug("%s %d %s %d", local->lastModified().toString().latin1() , localMod, remote->lastModified().toString().latin1(), remoteMod); | 3185 | //qDebug("%s %d %s %d", local->lastModified().toString().latin1() , localMod, remote->lastModified().toString().latin1(), remoteMod); |
3172 | //qDebug("%d %d %d %d ", local->lastModified().time().second(), local->lastModified().time().msec(), remote->lastModified().time().second(), remote->lastModified().time().msec() ); | 3186 | //qDebug("%d %d %d %d ", local->lastModified().time().second(), local->lastModified().time().msec(), remote->lastModified().time().second(), remote->lastModified().time().msec() ); |
3173 | full = true; //debug only | 3187 | //full = true; //debug only |
3174 | if ( full ) { | 3188 | if ( full ) { |
3175 | bool equ = ( (*local) == (*remote) ); | 3189 | bool equ = ( (*local) == (*remote) ); |
3176 | if ( equ ) { | 3190 | if ( equ ) { |
3177 | qDebug("equal "); | 3191 | //qDebug("equal "); |
3178 | if ( mode < SYNC_PREF_FORCE_LOCAL ) | 3192 | if ( mode < SYNC_PREF_FORCE_LOCAL ) |
3179 | return 0; | 3193 | return 0; |
3180 | 3194 | ||
3181 | }else //debug only | 3195 | }//else //debug only |
3182 | qDebug("not equal %s %s ", local->desc.c_str(), remote->desc.c_str()); | 3196 | //qDebug("not equal %s %s ", local->desc.c_str(), remote->desc.c_str()); |
3183 | } | 3197 | } |
3184 | 3198 | ||
3185 | int result; | 3199 | int result; |
3186 | bool localIsNew; | 3200 | bool localIsNew; |
3187 | //qDebug("%s -- %s mLastCalendarSync %s lastsync %s --- local %s remote %s ",local->summary().latin1(), remote->summary().latin1(),mLastCalendarSync.toString().latin1() ,lastSync.toString().latin1() , local->lastModified().toString().latin1() , remote->lastModified().toString().latin1() ); | 3201 | //qDebug("%s -- %s mLastCalendarSync %s lastsync %s --- local %s remote %s ",local->summary().latin1(), remote->summary().latin1(),mLastCalendarSync.toString().latin1() ,lastSync.toString().latin1() , local->lastModified().toString().latin1() , remote->lastModified().toString().latin1() ); |
3188 | 3202 | ||
3189 | if ( full && mode < SYNC_PREF_NEWEST ) | 3203 | if ( full && mode < SYNC_PREF_NEWEST ) |
3190 | mode = SYNC_PREF_ASK; | 3204 | mode = SYNC_PREF_ASK; |
3191 | 3205 | ||
3192 | switch( mode ) { | 3206 | switch( mode ) { |
3193 | case SYNC_PREF_LOCAL: | 3207 | case SYNC_PREF_LOCAL: |
3194 | if ( lastSync > remoteMod ) | 3208 | if ( lastSync > remoteMod ) |
3195 | return 1; | 3209 | return 1; |
3196 | if ( lastSync > localMod ) | 3210 | if ( lastSync > localMod ) |
3197 | return 2; | 3211 | return 2; |
3198 | return 1; | 3212 | return 1; |
3199 | break; | 3213 | break; |
3200 | case SYNC_PREF_REMOTE: | 3214 | case SYNC_PREF_REMOTE: |
3201 | if ( lastSync > remoteMod ) | 3215 | if ( lastSync > remoteMod ) |
3202 | return 1; | 3216 | return 1; |
3203 | if ( lastSync > localMod ) | 3217 | if ( lastSync > localMod ) |
3204 | return 2; | 3218 | return 2; |
3205 | return 2; | 3219 | return 2; |
3206 | break; | 3220 | break; |
diff --git a/pwmanager/pwmanager/pwmdoc.h b/pwmanager/pwmanager/pwmdoc.h index 6a1dd30..535fb92 100644 --- a/pwmanager/pwmanager/pwmdoc.h +++ b/pwmanager/pwmanager/pwmdoc.h | |||
@@ -188,80 +188,61 @@ struct PwMDataItem | |||
188 | * has changed since some time. | 188 | * has changed since some time. |
189 | * This counter is incremented on every update. | 189 | * This counter is incremented on every update. |
190 | */ | 190 | */ |
191 | unsigned int rev; | 191 | unsigned int rev; |
192 | 192 | ||
193 | void clear(bool clearMeta = true) | 193 | void clear(bool clearMeta = true) |
194 | { | 194 | { |
195 | /* NOTE: Don't use .clear() here to be | 195 | /* NOTE: Don't use .clear() here to be |
196 | * backward compatible with gcc-2 (Debian Woody) | 196 | * backward compatible with gcc-2 (Debian Woody) |
197 | */ | 197 | */ |
198 | desc = ""; | 198 | desc = ""; |
199 | name = ""; | 199 | name = ""; |
200 | pw = ""; | 200 | pw = ""; |
201 | comment = ""; | 201 | comment = ""; |
202 | url = ""; | 202 | url = ""; |
203 | launcher = ""; | 203 | launcher = ""; |
204 | lockStat = true; | 204 | lockStat = true; |
205 | listViewPos = -1; | 205 | listViewPos = -1; |
206 | binary = false; | 206 | binary = false; |
207 | if (clearMeta) | 207 | if (clearMeta) |
208 | meta.clear(); | 208 | meta.clear(); |
209 | } | 209 | } |
210 | //US ENH: we need this operator to compare two items if we have no unique ids | 210 | //US ENH: we need this operator to compare two items if we have no unique ids |
211 | //available. Generaly this happens before the first sync | 211 | //available. Generaly this happens before the first sync |
212 | |||
212 | bool PwMDataItem::operator==( const PwMDataItem &a ) const | 213 | bool PwMDataItem::operator==( const PwMDataItem &a ) const |
213 | { | 214 | { |
214 | qDebug("oper==%s", a.desc.c_str()); | 215 | //qDebug("oper==%s", a.desc.c_str()); |
215 | if ( desc != a.desc ) return false; | 216 | if ( desc != a.desc ) return false; |
216 | if ( name != a.name ) return false; | 217 | if ( name != a.name ) return false; |
217 | if ( pw != a.pw ) return false; | 218 | if ( pw != a.pw ) return false; |
218 | if ( comment != a.comment ) return false; | 219 | if ( comment != a.comment ) return false; |
219 | if ( url != a.url ) return false; | 220 | if ( url != a.url ) return false; |
220 | if ( launcher != a.launcher ) return false; | 221 | if ( launcher != a.launcher ) return false; |
221 | //all other field will not be checked. | 222 | //all other field will not be checked. |
222 | return true; | 223 | return true; |
223 | } | 224 | } |
224 | |||
225 | //US ENH:this operator is used to copy an elements data during syncronization | ||
226 | //Attention: listViewPos will not be copied. So the position will stay the same. | ||
227 | PwMDataItem& operator = (const PwMDataItem& x) | ||
228 | { | ||
229 | // qDebug("oper=%s", x.desc.c_str()); | ||
230 | desc = x.desc; | ||
231 | name = x.name; | ||
232 | pw = x.pw; | ||
233 | comment = x.comment; | ||
234 | url = x.url; | ||
235 | launcher = x.launcher; | ||
236 | lockStat = x.lockStat; | ||
237 | //Do not copy listViewPos!!! listViewPos = x.listViewPos; | ||
238 | binary = x.binary; | ||
239 | meta = x.meta; | ||
240 | rev = x.rev; | ||
241 | return *this; | ||
242 | } | ||
243 | |||
244 | }; | 225 | }; |
245 | 226 | ||
246 | struct PwMCategoryItem | 227 | struct PwMCategoryItem |
247 | { | 228 | { |
248 | /** all PwMDataItems (all passwords) within this category */ | 229 | /** all PwMDataItems (all passwords) within this category */ |
249 | vector<PwMDataItem>d; | 230 | vector<PwMDataItem>d; |
250 | /** category name/description */ | 231 | /** category name/description */ |
251 | string name; | 232 | string name; |
252 | 233 | ||
253 | void clear() | 234 | void clear() |
254 | { | 235 | { |
255 | d.clear(); | 236 | d.clear(); |
256 | name = ""; | 237 | name = ""; |
257 | } | 238 | } |
258 | }; | 239 | }; |
259 | 240 | ||
260 | struct PwMSyncItem | 241 | struct PwMSyncItem |
261 | { | 242 | { |
262 | string syncName; | 243 | string syncName; |
263 | QDateTime lastSyncDate; | 244 | QDateTime lastSyncDate; |
264 | 245 | ||
265 | void clear() | 246 | void clear() |
266 | { | 247 | { |
267 | lastSyncDate = QDateTime(); | 248 | lastSyncDate = QDateTime(); |