author | ulf69 <ulf69> | 2004-10-19 00:49:09 (UTC) |
---|---|---|
committer | ulf69 <ulf69> | 2004-10-19 00:49:09 (UTC) |
commit | da724334d46c01ee9d4f04101dab5d048c35c833 (patch) (unidiff) | |
tree | 5169852bd5e26992c9d55558dc54cf1b5ee57ae8 | |
parent | 9120b7e74bb928a7c148d27abb130990f8977a31 (diff) | |
download | kdepimpi-da724334d46c01ee9d4f04101dab5d048c35c833.zip kdepimpi-da724334d46c01ee9d4f04101dab5d048c35c833.tar.gz kdepimpi-da724334d46c01ee9d4f04101dab5d048c35c833.tar.bz2 |
final changes to have syncronisation in place
-rw-r--r-- | pwmanager/pwmanager/pwmdoc.cpp | 92 | ||||
-rw-r--r-- | pwmanager/pwmanager/pwmdoc.h | 23 |
2 files changed, 55 insertions, 60 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 | |||
@@ -2802,6 +2802,21 @@ PwMerror PwMDoc::importFromGpasman(const QString *file) | |||
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()) |
@@ -2809,15 +2824,11 @@ void PwMDoc::ensureLvp() | |||
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 listoverflows |
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, | ||
2818 | undefEnd, | ||
2819 | undefI; | ||
2820 | vector< vector<PwMDataItem>::iterator >::iterator sortedBegin, | ||
2821 | sortedEnd, | 2832 | sortedEnd, |
2822 | sortedI; | 2833 | sortedI; |
2823 | vector<PwMCategoryItem>::iterator catBegin = dti.dta.begin(), | 2834 | vector<PwMCategoryItem>::iterator catBegin = dti.dta.begin(), |
@@ -2826,43 +2837,53 @@ void PwMDoc::ensureLvp() | |||
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); | ||
2841 | else | ||
2842 | sorted[tmpLvp] = entrI; | ||
2843 | //US else if (tmpLvp > lvpTop) | ||
2844 | //US lvpTop = tmpLvp; | ||
2845 | ++entrI; | 2855 | ++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 | } |
@@ -2996,8 +3017,6 @@ PwMerror PwMDoc::syncronize(KSyncManager* manager, PwMDoc* syncLocal , PwMDoc* s | |||
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 | } |
@@ -3042,14 +3061,14 @@ PwMerror PwMDoc::syncronize(KSyncManager* manager, PwMDoc* syncLocal , PwMDoc* s | |||
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 | } |
@@ -3137,11 +3156,6 @@ PwMerror PwMDoc::syncronize(KSyncManager* manager, PwMDoc* syncLocal , PwMDoc* s | |||
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 ) { |
@@ -3170,16 +3184,16 @@ int PwMDoc::takePwMDataItem( PwMDataItem* local, PwMDataItem* remote, QDateTime | |||
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; |
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 | |||
@@ -209,9 +209,10 @@ struct PwMDataItem | |||
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; |
@@ -221,26 +222,6 @@ struct PwMDataItem | |||
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 |