author | zautrix <zautrix> | 2004-09-20 00:12:42 (UTC) |
---|---|---|
committer | zautrix <zautrix> | 2004-09-20 00:12:42 (UTC) |
commit | b01b669d88fa195261d29ecf73b1c69e608a5ebc (patch) (side-by-side diff) | |
tree | c0e79d45242a764b49470d07a9c95be156c121cc /kaddressbook | |
parent | 3da2cfeab2edbe64a17251662e56668fe143f7a3 (diff) | |
download | kdepimpi-b01b669d88fa195261d29ecf73b1c69e608a5ebc.zip kdepimpi-b01b669d88fa195261d29ecf73b1c69e608a5ebc.tar.gz kdepimpi-b01b669d88fa195261d29ecf73b1c69e608a5ebc.tar.bz2 |
more AB sync
-rw-r--r-- | kaddressbook/kabcore.cpp | 58 |
1 files changed, 32 insertions, 26 deletions
diff --git a/kaddressbook/kabcore.cpp b/kaddressbook/kabcore.cpp index 8f3ca9b..f8683e7 100644 --- a/kaddressbook/kabcore.cpp +++ b/kaddressbook/kabcore.cpp @@ -2546,48 +2546,50 @@ int KABCore::takeAddressee( KABC::Addressee* local, KABC::Addressee* remote, i // int zaurusStat() const; // 0 equal // 1 take local // 2 take remote // 3 cancel QDateTime lastSync = mLastAddressbookSync; + QDateTime localMod = local->revision(); + QDateTime remoteMod = remote->revision(); if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL ) { bool remCh, locCh; remCh = ( remote->getCsum(mCurrentSyncDevice) != local->getCsum(mCurrentSyncDevice) ); - //qDebug("loc %s rem %s", local->getCsum(mCurrentSyncDevice).latin1(), remote->getCsum(mCurrentSyncDevice).latin1() ); - locCh = ( local->revision() > mLastAddressbookSync ); + qDebug("loc %s rem %s", local->getCsum(mCurrentSyncDevice).latin1(), remote->getCsum(mCurrentSyncDevice).latin1() ); + locCh = ( localMod > mLastAddressbookSync ); if ( !remCh && ! locCh ) { - //qDebug("both not changed "); - lastSync = local->revision().addDays(1); + qDebug("both not changed "); + lastSync = localMod.addDays(1); if ( mode <= SYNC_PREF_ASK ) return 0; } else { if ( locCh ) { - //qDebug("loc changed %s %s", local->revision().toString().latin1(), mLastAddressbookSync.toString().latin1()); - lastSync = local->revision().addDays( -1 ); + qDebug("loc changed %s %s", localMod.toString().latin1(), mLastAddressbookSync.toString().latin1()); + lastSync = localMod.addDays( -1 ); if ( !remCh ) - remote->setRevision( lastSync.addDays( -1 ) ); + remoteMod =( lastSync.addDays( -1 ) ); } else { //qDebug(" not loc changed "); - lastSync = local->revision().addDays( 1 ); + lastSync = localMod.addDays( 1 ); if ( remCh ) - remote->setRevision( lastSync.addDays( 1 ) ); + remoteMod =( lastSync.addDays( 1 ) ); } } full = true; if ( mode < SYNC_PREF_ASK ) mode = SYNC_PREF_ASK; } else { - if ( local->revision() == remote->revision() ) + if ( localMod == remoteMod ) return 0; } // qDebug(" %d %d conflict on %s %s ", mode, full, local->summary().latin1(), remote->summary().latin1() ); - //qDebug("%s %d %s %d", local->lastModified().toString().latin1() , local->revision(), remote->lastModified().toString().latin1(), remote->revision()); + //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 if ( full ) { bool equ = ( (*local) == (*remote) ); if ( equ ) { //qDebug("equal "); @@ -2606,38 +2608,38 @@ int KABCore::takeAddressee( KABC::Addressee* local, KABC::Addressee* remote, i if ( full && mode < SYNC_PREF_NEWEST ) mode = SYNC_PREF_ASK; switch( mode ) { case SYNC_PREF_LOCAL: - if ( lastSync > remote->revision() ) + if ( lastSync > remoteMod ) return 1; - if ( lastSync > local->revision() ) + if ( lastSync > localMod ) return 2; return 1; break; case SYNC_PREF_REMOTE: - if ( lastSync > remote->revision() ) + if ( lastSync > remoteMod ) return 1; - if ( lastSync > local->revision() ) + if ( lastSync > localMod ) return 2; return 2; break; case SYNC_PREF_NEWEST: - if ( local->revision() > remote->revision() ) + if ( localMod > remoteMod ) return 1; else return 2; break; case SYNC_PREF_ASK: - //qDebug("lsy %s --- lo %s --- re %s ", lastSync.toString().latin1(), local->revision().toString().latin1(), remote->revision().toString().latin1() ); - if ( lastSync > remote->revision() ) + //qDebug("lsy %s --- lo %s --- re %s ", lastSync.toString().latin1(), localMod.toString().latin1(), remoteMod.toString().latin1() ); + if ( lastSync > remoteMod ) return 1; - if ( lastSync > local->revision() ) + if ( lastSync > localMod ) return 2; - localIsNew = local->revision() >= remote->revision(); + localIsNew = localMod >= remoteMod; //qDebug("conflict! ************************************** "); { KPIM::AddresseeChooser acd ( *local,*remote, localIsNew , this ); result = acd.executeD(localIsNew); return result; } @@ -2783,12 +2785,16 @@ bool KABCore::synchronizeAddressbooks( KABC::AddressBook* local, KABC::AddressBo inR.setIDStr( idS ); } inR.setResource( 0 ); remote->insertAddressee( inR , false); ++changedRemote; } else { // take == 2 take remote + if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL ) { + if ( inR.revision().date().year() < 2004 ) + inR.setRevision( modifiedCalendar ); + } idS = inL.IDStr(); local->removeAddressee( inL ); inL = inR; inL.setIDStr( idS ); inL.setResource( 0 ); local->insertAddressee( inL , false ); @@ -2922,27 +2928,27 @@ bool KABCore::syncAB(QString filename, int mode) mGlobalSyncMode = SYNC_MODE_NORMAL; AddressBook abLocal(filename,"syncContact"); bool syncOK = false; if ( abLocal.load() ) { qDebug("AB loaded %s,sync mode %d",filename.latin1(), mode ); bool external = false; - + bool isXML = false; if ( filename.right(4) == ".xml") { mGlobalSyncMode = SYNC_MODE_EXTERNAL; + isXML = true; abLocal.preExternSync( mAddressBook ,mCurrentSyncDevice ); } else { Addressee lse = mAddressBook->findByUid( "last-syncAddressee-"+mCurrentSyncDevice ); if ( ! lse.isEmpty() ) { if ( lse.familyName().left(4) == "!E: " ) external = true; } else { bool found = false; - QDateTime dt( QDate( 2004,1,1)); AddressBook::Iterator it; for ( it = abLocal.begin(); it != abLocal.end(); ++it ) { - if ( (*it).revision() != dt ) { + if ( (*it).revision().date().year() > 2003 ) { found = true; break; } } external = ! found; } @@ -2963,17 +2969,17 @@ bool KABCore::syncAB(QString filename, int mode) // qDebug("Name %s ", (*it).familyName().latin1()); //} syncOK = synchronizeAddressbooks( mAddressBook, &abLocal, mode ); if ( syncOK ) { if ( KABPrefs::instance()->mWriteBackFile ) { - if ( external && filename.right(4) != ".xml") - abLocal.removeDeletedAddressees(); + if ( external ) + abLocal.removeSyncAddressees( !isXML); qDebug("Saving remote AB "); abLocal.saveAB(); - if ( external && filename.right(4) == ".xml") { + if ( isXML ) { // afterwrite processing abLocal.postExternSync( mAddressBook,mCurrentSyncDevice ); } } } setModified(); |