summaryrefslogtreecommitdiffabout
path: root/pwmanager
Side-by-side diff
Diffstat (limited to 'pwmanager') (more/less context) (show whitespace changes)
-rw-r--r--pwmanager/pwmanager/pwmdoc.cpp92
-rw-r--r--pwmanager/pwmanager/pwmdoc.h23
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
@@ -2793,85 +2793,106 @@ PwMerror PwMDoc::importFromGpasman(const QString *file)
gp.load_finalize();
return e_maxAllowedEntr;
}
} while (1);
gp.load_finalize();
if (isDocEmpty())
return e_wrongPw; // we assume this.
flagDirty();
return e_success;
}
+
+//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()
{
if (isDocEmpty())
return;
//US ENH BUG: when using syncronizing, this way of sorting
//is not sufficient, because there might be empty spaces
- // at the beginning. But this algorythm only can add elements
+ // at the beginning. But the old algorythm only can add elements
//to the end.The result are crashes because of listoverflows
//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,
+ vector<PwMDataItem*> sorted;
+ vector< PwMDataItem*>::iterator sortedBegin,
sortedEnd,
sortedI;
vector<PwMCategoryItem>::iterator catBegin = dti.dta.begin(),
catEnd = dti.dta.end(),
catI = catBegin;
vector<PwMDataItem>::iterator entrBegin, entrEnd, entrI;
int lvpTop, tmpLvp;
+ //qDebug("collect:");
+
while (catI != catEnd) {
lvpTop = -1;
- undefined.clear();
+ sorted.clear();
entrBegin = catI->d.begin();
entrEnd = catI->d.end();
entrI = entrBegin;
+ //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;
+ //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();
sortedEnd = sorted.end();
sortedI = sortedBegin;
while (sortedI != sortedEnd) {
- tmpLvp = (*sortedI)->listViewPos;
- undefined[tmpLvp] = *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;
}
}
QString PwMDoc::getTitle()
{
/* NOTE: We have to ensure, that the returned title
* is unique and not reused somewhere else while
* this document is valid (open).
*/
QString title(getFilename());
@@ -2987,26 +3008,24 @@ PwMerror PwMDoc::syncronize(KSyncManager* manager, PwMDoc* syncLocal , PwMDoc* s
//and remove the found entry here. We will reenter it later again.
//US syncRemote->delSyncDataEntry(index, true);
if ( syncItemLocal->lastSyncDate == mLastSync ) {
qDebug("FULLDATE 2");
fullDateRange = true;
}
if ( ! fullDateRange ) {
if ( syncItemLocal->lastSyncDate != syncItemRemote->lastSyncDate ) {
- // 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;
qDebug("FULLDATE 3 %s %s", syncItemLocal->lastSyncDate.toString().latin1() , syncItemRemote->lastSyncDate.toString().latin1() );
}
}
// fullDateRange = true; // debug only!
if ( fullDateRange )
mLastSync = QDateTime::currentDateTime().addDays( -100*365);
else
mLastSync = syncItemLocal->lastSyncDate;
qDebug("*************************** ");
@@ -3033,32 +3052,32 @@ PwMerror PwMDoc::syncronize(KSyncManager* manager, PwMDoc* syncLocal , PwMDoc* s
qApp->processEvents();
inLocal = syncLocal->findEntryByID( uid, &catLocal, &indexLocal );
inRemote = syncRemote->findEntryByID( uid, &catRemote, &indexRemote );
PWM_ASSERT(inRemote);
if ( inLocal != 0 ) { // maybe conflict - same uid in both files
if ( (take = takePwMDataItem( inLocal, inRemote, mLastSync, mode, fullDateRange) ) ) {
qDebug("take %d %s ", take, inLocal->desc.c_str());
if ( take == 3 )
return e_syncError;
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;
}
}
} else { // no conflict
if ( inRemote->meta.update > mLastSync || mode == 5 ) {
inRemote->meta.update = modifiedSync;
//first check if we have a matching category in the local file
const string* remotecat = syncRemote->getCategory(catRemote);
//US syncRemote->insertAddressee( inRemote, false );
//US syncLocal->insertAddressee( inRemote, false );
syncLocal->addEntry(remotecat->c_str(), inRemote, true, false);
@@ -3128,29 +3147,24 @@ PwMerror PwMDoc::syncronize(KSyncManager* manager, PwMDoc* syncLocal , PwMDoc* s
// Now write the info back into the sync data space of the files
mLastSync = QDateTime::currentDateTime().addSecs( 1 );
// get rid of micro seconds
QTime t = mLastSync.time();
mLastSync.setTime( QTime (t.hour (), t.minute (), t.second () ) );
syncItemLocal->lastSyncDate = mLastSync;
syncItemRemote->lastSyncDate = mLastSync;
- // addresseeRSync.setRole( i18n("!Remote from: ")+mCurrentSyncName ) ;
- // addresseeLSync.setRole(i18n("!Local from: ") + mCurrentSyncName );
-
- //US syncRemote->addSyncDataEntry( syncItemRemote, false );
- //US syncLocal->addSyncDataEntry( syncItemLocal, false );
QString mes;
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 );
if ( manager->mShowSyncSummary ) {
KMessageBox::information(0, mes, i18n("PWM/Pi Synchronization") );
}
qDebug( mes );
return e_success;
}
int PwMDoc::takePwMDataItem( PwMDataItem* local, PwMDataItem* remote, QDateTime lastSync, int mode , bool full )
{
@@ -3161,34 +3175,34 @@ int PwMDoc::takePwMDataItem( PwMDataItem* local, PwMDataItem* remote, QDateTime
QDateTime localMod = local->meta.update;
QDateTime remoteMod = remote->meta.update;
//US QString mCurrentSyncDevice = syncManager->getCurrentSyncDevice();
if ( localMod == remoteMod )
return 0;
qDebug(" %d %d conflict on %s %s ", mode, full, local->desc.c_str(), remote->desc.c_str() );
//qDebug("%s %d %s %d", local->lastModified().toString().latin1() , localMod, remote->lastModified().toString().latin1(), remoteMod);
//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 ) {
bool equ = ( (*local) == (*remote) );
if ( equ ) {
- qDebug("equal ");
+ //qDebug("equal ");
if ( mode < SYNC_PREF_FORCE_LOCAL )
return 0;
- }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());
}
int result;
bool localIsNew;
//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() );
if ( full && mode < SYNC_PREF_NEWEST )
mode = SYNC_PREF_ASK;
switch( mode ) {
case SYNC_PREF_LOCAL:
if ( lastSync > remoteMod )
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
@@ -200,56 +200,37 @@ struct PwMDataItem
pw = "";
comment = "";
url = "";
launcher = "";
lockStat = true;
listViewPos = -1;
binary = false;
if (clearMeta)
meta.clear();
}
//US ENH: we need this operator to compare two items if we have no unique ids
//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;
if ( name != a.name ) return false;
if ( pw != a.pw ) return false;
if ( comment != a.comment ) return false;
if ( url != a.url ) return false;
if ( launcher != a.launcher ) return false;
//all other field will not be checked.
return true;
}
-
- //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;
- }
-
};
struct PwMCategoryItem
{
/** all PwMDataItems (all passwords) within this category */
vector<PwMDataItem> d;
/** category name/description */
string name;
void clear()
{
d.clear();