summaryrefslogtreecommitdiffabout
Unidiff
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--pwmanager/pwmanager/pwmdoc.cpp102
-rw-r--r--pwmanager/pwmanager/pwmdoc.h23
2 files changed, 60 insertions, 65 deletions
diff --git a/pwmanager/pwmanager/pwmdoc.cpp b/pwmanager/pwmanager/pwmdoc.cpp
index 2a7b11d..e9906a4 100644
--- a/pwmanager/pwmanager/pwmdoc.cpp
+++ b/pwmanager/pwmanager/pwmdoc.cpp
@@ -2804,2 +2804,17 @@ PwMerror PwMDoc::importFromGpasman(const QString *file)
2804 2804
2805
2806//US: we use the stl sort algorythm to sort all elements in the order
2807//of its listViewPos (in the order 1,2,3,5,...,x,-1, -1, -1
2808struct PwMDataItemListViewPosSort
2809{
2810 bool operator()(PwMDataItem* rpStart, PwMDataItem* rpEnd)
2811 {
2812 //qDebug("pwMDoc::PwMDataItemListViewPosSort()");
2813 if ((rpEnd)->listViewPos < 0)
2814 return false;
2815 else
2816 return (rpStart)->listViewPos < (rpEnd)->listViewPos;
2817 }
2818};
2819
2805void PwMDoc::ensureLvp() 2820void PwMDoc::ensureLvp()
@@ -2811,13 +2826,9 @@ void PwMDoc::ensureLvp()
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(),
@@ -2828,5 +2839,7 @@ void PwMDoc::ensureLvp()
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
@@ -2836,14 +2849,18 @@ void PwMDoc::ensureLvp()
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();
@@ -2853,14 +2870,18 @@ void PwMDoc::ensureLvp()
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;
@@ -2998,4 +3019,2 @@ PwMerror PwMDoc::syncronize(KSyncManager* manager, PwMDoc* syncLocal , PwMDoc* s
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;
@@ -3044,10 +3063,10 @@ PwMerror PwMDoc::syncronize(KSyncManager* manager, PwMDoc* syncLocal , PwMDoc* s
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;
@@ -3139,7 +3158,2 @@ PwMerror PwMDoc::syncronize(KSyncManager* manager, PwMDoc* syncLocal , PwMDoc* s
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;
@@ -3172,3 +3186,3 @@ int PwMDoc::takePwMDataItem( PwMDataItem* local, PwMDataItem* remote, QDateTime
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 ) {
@@ -3176,3 +3190,3 @@ int PwMDoc::takePwMDataItem( PwMDataItem* local, PwMDataItem* remote, QDateTime
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 )
@@ -3180,4 +3194,4 @@ int PwMDoc::takePwMDataItem( PwMDataItem* local, PwMDataItem* remote, QDateTime
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 }
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
@@ -211,5 +211,6 @@ struct PwMDataItem
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;
@@ -223,22 +224,2 @@ struct PwMDataItem
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};