summaryrefslogtreecommitdiffabout
path: root/pwmanager
authorulf69 <ulf69>2004-10-19 00:49:09 (UTC)
committer ulf69 <ulf69>2004-10-19 00:49:09 (UTC)
commitda724334d46c01ee9d4f04101dab5d048c35c833 (patch) (side-by-side diff)
tree5169852bd5e26992c9d55558dc54cf1b5ee57ae8 /pwmanager
parent9120b7e74bb928a7c148d27abb130990f8977a31 (diff)
downloadkdepimpi-da724334d46c01ee9d4f04101dab5d048c35c833.zip
kdepimpi-da724334d46c01ee9d4f04101dab5d048c35c833.tar.gz
kdepimpi-da724334d46c01ee9d4f04101dab5d048c35c833.tar.bz2
final changes to have syncronisation in place
Diffstat (limited to 'pwmanager') (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)
+
+//US: we use the stl sort algorythm to sort all elements in the order
+//of its listViewPos (in the order 1,2,3,5,...,x,-1, -1, -1
+struct PwMDataItemListViewPosSort
+{
+ bool operator()(PwMDataItem* rpStart, PwMDataItem* rpEnd)
+ {
+ //qDebug("pwMDoc::PwMDataItemListViewPosSort()");
+ if ((rpEnd)->listViewPos < 0)
+ return false;
+ else
+ return (rpStart)->listViewPos < (rpEnd)->listViewPos;
+ }
+};
+
void PwMDoc::ensureLvp()
@@ -2811,13 +2826,9 @@ void PwMDoc::ensureLvp()
//is not sufficient, because there might be empty spaces
- // at the beginning. But this algorythm only can add elements
- //to the end.The result are crashes because of listoverflows
+ // at the beginning. But the old algorythm only can add elements
+ //to the end.The result are crashes because of list overflows
//we need something to fill all gaps.
- vector< vector<PwMDataItem>::iterator > undefined;
- vector< vector<PwMDataItem>::iterator > sorted;
- vector< vector<PwMDataItem>::iterator >::iterator undefBegin,
- undefEnd,
- undefI;
- vector< vector<PwMDataItem>::iterator >::iterator sortedBegin,
- sortedEnd,
- sortedI;
+ vector<PwMDataItem*> sorted;
+ vector< PwMDataItem*>::iterator sortedBegin,
+ sortedEnd,
+ sortedI;
vector<PwMCategoryItem>::iterator catBegin = dti.dta.begin(),
@@ -2828,5 +2839,7 @@ void PwMDoc::ensureLvp()
+ //qDebug("collect:");
+
while (catI != catEnd) {
lvpTop = -1;
- undefined.clear();
+ sorted.clear();
@@ -2836,14 +2849,18 @@ void PwMDoc::ensureLvp()
+ //US: we use the stl sort algorythm to sort all elements in the order
+ //of its listViewPos (in the order 1,2,2,3,5,...,x,-1, -1, -1
while (entrI != entrEnd) {
- tmpLvp = entrI->listViewPos;
- if (tmpLvp == -1)
- undefined.push_back(entrI);
- else
- sorted[tmpLvp] = entrI;
- //US else if (tmpLvp > lvpTop)
- //US lvpTop = tmpLvp;
- ++entrI;
+ //qDebug("found: %s, pos=%i", (*entrI).desc.c_str(), (*entrI).listViewPos);
+ sorted.push_back((PwMDataItem*)&(*entrI));
+ ++entrI;
}
- //now we have all undefied in the collection. Now insert the existing
+ sortedBegin = sorted.begin();
+ sortedEnd = sorted.end();
+
+ sort(sortedBegin, sortedEnd, PwMDataItemListViewPosSort());
+
+ // qDebug("resort:");
+ //now we have all sorted in a collection
+ //Now start with the sorted and reset listviewpos.
sortedBegin = sorted.begin();
@@ -2853,14 +2870,18 @@ void PwMDoc::ensureLvp()
while (sortedI != sortedEnd) {
- tmpLvp = (*sortedI)->listViewPos;
- undefined[tmpLvp] = *sortedI;
- ++sortedI;
+ // qDebug("reset defined: %s, from pos=%i to pos=%i", (*sortedI)->desc.c_str(), (*sortedI)->listViewPos, lvpTop+1);
+ (*sortedI)->listViewPos = ++lvpTop;
+ ++sortedI;
}
- undefBegin = undefined.begin();
- undefEnd = undefined.end();
- undefI = undefBegin;
- while (undefI != undefEnd) {
- (*undefI)->listViewPos = ++lvpTop;
- ++undefI;
+ /*/debug
+ entrBegin = catI->d.begin();
+ entrEnd = catI->d.end();
+ entrI = entrBegin;
+
+ while (entrI != entrEnd) {
+ qDebug("check: %s, pos=%i", (*entrI).desc.c_str(), (*entrI).listViewPos);
+ ++entrI;
}
+ */
+
++catI;
@@ -2998,4 +3019,2 @@ PwMerror PwMDoc::syncronize(KSyncManager* manager, PwMDoc* syncLocal , PwMDoc* s
- // qDebug("set fulldate to true %s %s" ,syncItemLocal->lastSyncDate.toString().latin1(), syncItemRemote->lastSyncDate.toString().latin1() );
- // qDebug("%d %d %d %d ", syncItemLocal->lastSyncDate.time().second(), addresseeLSync->dtStart().time().msec() , addresseeRSync->dtStart().time().second(), addresseeRSync->dtStart().time().msec());
fullDateRange = true;
@@ -3044,10 +3063,10 @@ PwMerror PwMDoc::syncronize(KSyncManager* manager, PwMDoc* syncLocal , PwMDoc* s
if ( take == 1 ) {// take local
- //US syncRemote->removeAddressee( inRemote );
+ int oldlistpos = inRemote->listViewPos;
(*inRemote) = (*inLocal);
- //US syncRemote->insertAddressee( inRemote , false);
+ inRemote->listViewPos = oldlistpos;
++changedRemote;
} else { // take == 2 take remote
- //US syncLocal->removeAddressee( inLocal );
+ int oldlistpos = inLocal->listViewPos;
(*inLocal) = (*inRemote);
- //US syncLocal->insertAddressee( inLocal , false );
+ inLocal->listViewPos = oldlistpos;
++changedLocal;
@@ -3139,7 +3158,2 @@ PwMerror PwMDoc::syncronize(KSyncManager* manager, PwMDoc* syncLocal , PwMDoc* s
- // addresseeRSync.setRole( i18n("!Remote from: ")+mCurrentSyncName ) ;
- // addresseeLSync.setRole(i18n("!Local from: ") + mCurrentSyncName );
-
- //US syncRemote->addSyncDataEntry( syncItemRemote, false );
- //US syncLocal->addSyncDataEntry( syncItemLocal, false );
QString mes;
@@ -3172,3 +3186,3 @@ int PwMDoc::takePwMDataItem( PwMDataItem* local, PwMDataItem* remote, QDateTime
//qDebug("%d %d %d %d ", local->lastModified().time().second(), local->lastModified().time().msec(), remote->lastModified().time().second(), remote->lastModified().time().msec() );
- full = true; //debug only
+ //full = true; //debug only
if ( full ) {
@@ -3176,3 +3190,3 @@ int PwMDoc::takePwMDataItem( PwMDataItem* local, PwMDataItem* remote, QDateTime
if ( equ ) {
- qDebug("equal ");
+ //qDebug("equal ");
if ( mode < SYNC_PREF_FORCE_LOCAL )
@@ -3180,4 +3194,4 @@ int PwMDoc::takePwMDataItem( PwMDataItem* local, PwMDataItem* remote, QDateTime
- }else //debug only
- qDebug("not equal %s %s ", local->desc.c_str(), remote->desc.c_str());
+ }//else //debug only
+ //qDebug("not equal %s %s ", local->desc.c_str(), remote->desc.c_str());
}
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
//available. Generaly this happens before the first sync
+
bool PwMDataItem::operator==( const PwMDataItem &a ) const
{
- qDebug("oper==%s", a.desc.c_str());
+ //qDebug("oper==%s", a.desc.c_str());
if ( desc != a.desc ) return false;
@@ -223,22 +224,2 @@ struct PwMDataItem
}
-
- //US ENH:this operator is used to copy an elements data during syncronization
- //Attention: listViewPos will not be copied. So the position will stay the same.
- PwMDataItem& operator = (const PwMDataItem& x)
- {
- // qDebug("oper=%s", x.desc.c_str());
- desc = x.desc;
- name = x.name;
- pw = x.pw;
- comment = x.comment;
- url = x.url;
- launcher = x.launcher;
- lockStat = x.lockStat;
- //Do not copy listViewPos!!! listViewPos = x.listViewPos;
- binary = x.binary;
- meta = x.meta;
- rev = x.rev;
- return *this;
- }
-
};