-rw-r--r-- | kabc/addressbook.cpp | 3 | ||||
-rw-r--r-- | kabc/addressbook.h | 2 | ||||
-rw-r--r-- | kabc/addressee.cpp | 1 | ||||
-rw-r--r-- | kaddressbook/kabcore.cpp | 198 | ||||
-rw-r--r-- | kaddressbook/kabcore.h | 1 |
5 files changed, 169 insertions, 36 deletions
diff --git a/kabc/addressbook.cpp b/kabc/addressbook.cpp index 6e8d027..3ec0795 100644 --- a/kabc/addressbook.cpp +++ b/kabc/addressbook.cpp @@ -445,7 +445,7 @@ Ticket *AddressBook::requestSaveTicket( Resource *resource ) return 0; } -void AddressBook::insertAddressee( const Addressee &a ) +void AddressBook::insertAddressee( const Addressee &a, bool setRev ) { Addressee::List::Iterator it; for ( it = d->mAddressees.begin(); it != d->mAddressees.end(); ++it ) { @@ -460,6 +460,7 @@ void AddressBook::insertAddressee( const Addressee &a ) (*it).setResource( standardResource() ); if ( changed ) { + if ( setRev ) (*it).setRevision( QDateTime::currentDateTime() ); (*it).setChanged( true ); } diff --git a/kabc/addressbook.h b/kabc/addressbook.h index 650a638..253de68 100644 --- a/kabc/addressbook.h +++ b/kabc/addressbook.h @@ -173,7 +173,7 @@ class AddressBook : public QObject unique id already exists in the address book it it replaced by the new one. If not the new object is appended to the address book. */ - void insertAddressee( const Addressee & ); + void insertAddressee( const Addressee &, bool setRev = true ); /** Removes entry from the address book. diff --git a/kabc/addressee.cpp b/kabc/addressee.cpp index fb32f6e..7f04d8f 100644 --- a/kabc/addressee.cpp +++ b/kabc/addressee.cpp @@ -93,6 +93,7 @@ Addressee::Addressee() mData->changed = false; mData->resource = 0; mData->mExternalId = ":"; + mData->revision = QDateTime ( QDate( 2004,1,1)); mTempSyncStat = SYNC_TEMPSTATE_INITIAL; } diff --git a/kaddressbook/kabcore.cpp b/kaddressbook/kabcore.cpp index f497541..226d5e4 100644 --- a/kaddressbook/kabcore.cpp +++ b/kaddressbook/kabcore.cpp @@ -2523,7 +2523,8 @@ KABC::Addressee KABCore::getLastSyncAddressee() //qDebug("CurrentSyncDevice %s ",mCurrentSyncDevice .latin1() ); lse = mAddressBook->findByUid( "last-syncAddressee-"+mCurrentSyncDevice ); if (lse.isEmpty()) { - lse.setUid( "last-syncEvent-"+mCurrentSyncDevice ); + qDebug("Creating new last-syncAddressee "); + lse.setUid( "last-syncAddressee-"+mCurrentSyncDevice ); QString sum = ""; if ( KABPrefs::instance()->mExternSyncProfiles.contains( mCurrentSyncDevice ) ) sum = "E: "; @@ -2534,7 +2535,140 @@ KABC::Addressee KABCore::getLastSyncAddressee() } return lse; } +int KABCore::takeAddressee( KABC::Addressee* local, KABC::Addressee* remote, int mode , bool full ) +{ + + //void setZaurusId(int id); + // int zaurusId() const; + // void setZaurusUid(int id); + // int zaurusUid() const; + // void setZaurusStat(int id); + // int zaurusStat() const; + // 0 equal + // 1 take local + // 2 take remote + // 3 cancel + QDateTime lastSync = mLastAddressbookSync; + if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL ) { + bool remCh, locCh; + remCh = ( remote->getCsum(mCurrentSyncDevice) != local->getCsum(mCurrentSyncDevice) ); + //if ( remCh ) + //qDebug("loc %s rem %s", local->getCsum(mCurrentSyncDevice).latin1(), remote->getCsum(mCurrentSyncDevice).latin1() ); + locCh = ( local->revision() > mLastAddressbookSync ); + if ( !remCh && ! locCh ) { + //qDebug("both not changed "); + lastSync = local->revision().addDays(1); + } else { + if ( locCh ) { + //qDebug("loc changed %d %s %s", local->revision() , local->lastModified().toString().latin1(), mLastCalendarSync.toString().latin1()); + lastSync = local->revision().addDays( -1 ); + if ( !remCh ) + remote->setRevision( lastSync.addDays( -1 ) ); + } else { + //qDebug(" not loc changed "); + lastSync = local->revision().addDays( 1 ); + if ( remCh ) + remote->setRevision( lastSync.addDays( 1 ) ); + + } + } + full = true; + if ( mode < SYNC_PREF_ASK ) + mode = SYNC_PREF_ASK; + } else { + if ( local->revision() == remote->revision() ) + 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("%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 "); + if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL ) { + local->setCsum( mCurrentSyncDevice, remote->getCsum(mCurrentSyncDevice) ); + } + if ( mode < SYNC_PREF_FORCE_LOCAL ) + return 0; + + }//else //debug only + //qDebug("not equal %s %s ", local->summary().latin1(), remote->summary().latin1()); + } + 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 > remote->revision() ) + return 1; + if ( lastSync > local->revision() ) + return 2; + return 1; + break; + case SYNC_PREF_REMOTE: + if ( lastSync > remote->revision() ) + return 1; + if ( lastSync > local->revision() ) + return 2; + return 2; + break; + case SYNC_PREF_NEWEST: + if ( local->revision() > remote->revision() ) + 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() ) + return 1; + if ( lastSync > local->revision() ) + return 2; + //qDebug("lsy %s --- lo %s --- re %s ", lastSync.toString().latin1(), local->revision().toString().latin1(), remote->revision().toString().latin1() ); + localIsNew = local->revision() >= remote->revision(); +#if 0 + if ( localIsNew ) + getEventViewerDialog()->setColorMode( 1 ); + else + getEventViewerDialog()->setColorMode( 2 ); + getEventViewerDialog()->setIncidence(local); + if ( localIsNew ) + getEventViewerDialog()->setColorMode( 2 ); + else + getEventViewerDialog()->setColorMode( 1 ); + getEventViewerDialog()->addIncidence(remote); + getEventViewerDialog()->setColorMode( 0 ); + //qDebug("local %d remote %d ",local->relatedTo(),remote->relatedTo() ); + getEventViewerDialog()->setCaption( mCurrentSyncDevice +i18n(" : Conflict! Please choose entry!")); + getEventViewerDialog()->showMe(); + result = getEventViewerDialog()->executeS( localIsNew ); +#endif + qDebug("conflict! ************************************** "); + result = 1; + return result; + + break; + case SYNC_PREF_FORCE_LOCAL: + return 1; + break; + case SYNC_PREF_FORCE_REMOTE: + return 2; + break; + + default: + // SYNC_PREF_TAKE_BOTH not implemented + break; + } + return 0; +} bool KABCore::synchronizeAddressbooks( KABC::AddressBook* local, KABC::AddressBook* remote,int mode) { bool syncOK = true; @@ -2558,6 +2692,7 @@ bool KABCore::synchronizeAddressbooks( KABC::AddressBook* local, KABC::AddressBo mLastAddressbookSync = QDateTime::currentDateTime(); QDateTime modifiedCalendar = mLastAddressbookSync;; addresseeLSync = getLastSyncAddressee(); + qDebug("Last Sync %s ", addresseeLSync.revision().toString().latin1()); addresseeR = remote->findByUid("last-syncAddressee-"+mCurrentSyncName ); if ( !addresseeR.isEmpty() ) { addresseeRSync = addresseeR; @@ -2567,6 +2702,7 @@ bool KABCore::synchronizeAddressbooks( KABC::AddressBook* local, KABC::AddressBo if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL ) { addresseeRSync = addresseeLSync ; } else { + qDebug("FULLDATE 1"); fullDateRange = true; Addressee newAdd; addresseeRSync = newAdd; @@ -2576,14 +2712,17 @@ bool KABCore::synchronizeAddressbooks( KABC::AddressBook* local, KABC::AddressBo addresseeRSync.setCategories( i18n("SyncAddressee") ); } } - if ( addresseeLSync.revision() == mLastAddressbookSync ) + if ( addresseeLSync.revision() == mLastAddressbookSync ) { + qDebug("FULLDATE 2"); fullDateRange = true; + } if ( ! fullDateRange ) { if ( addresseeLSync.revision() != addresseeRSync.revision() ) { // qDebug("set fulldate to true %s %s" ,addresseeLSync->dtStart().toString().latin1(), addresseeRSync->dtStart().toString().latin1() ); //qDebug("%d %d %d %d ", addresseeLSync->dtStart().time().second(), addresseeLSync->dtStart().time().msec() , addresseeRSync->dtStart().time().second(), addresseeRSync->dtStart().time().msec()); fullDateRange = true; + qDebug("FULLDATE 3 %s %s", addresseeLSync.revision().toString().latin1() , addresseeRSync.revision().toString().latin1() ); } } if ( fullDateRange ) @@ -2634,15 +2773,14 @@ bool KABCore::synchronizeAddressbooks( KABC::AddressBook* local, KABC::AddressBo //inL.setResource( 0 ); //inR.setResource( 0 ); if ( !inL.isEmpty() ) { // maybe conflict - same uid in both calendars - // pending if ( (take = takeAddressee( inL, inR, mode, fullDateRange )) > 0 ) { - if ( true ) { + if ( take = takeAddressee( &inL, &inR, mode, fullDateRange ) ) { //qDebug("take %d %s ", take, inL.summary().latin1()); if ( take == 3 ) return false; if ( take == 1 ) {// take local if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL ) { inL.setCsum( mCurrentSyncDevice, inR.getCsum(mCurrentSyncDevice) ); - local->insertAddressee( inL ); + local->insertAddressee( inL, false ); } else idS = inR.IDStr(); @@ -2652,7 +2790,7 @@ bool KABCore::synchronizeAddressbooks( KABC::AddressBook* local, KABC::AddressBo if ( mGlobalSyncMode != SYNC_MODE_EXTERNAL ) inR.setIDStr( idS ); inR.setResource( 0 ); - remote->insertAddressee( inR ); + remote->insertAddressee( inR , false); ++changedRemote; } else { idS = inL.IDStr(); @@ -2660,7 +2798,7 @@ bool KABCore::synchronizeAddressbooks( KABC::AddressBook* local, KABC::AddressBo inL = inR; inL.setIDStr( idS ); inL.setResource( 0 ); - local->insertAddressee( inL ); + local->insertAddressee( inL , false ); ++changedLocal; } } @@ -2673,18 +2811,18 @@ bool KABCore::synchronizeAddressbooks( KABC::AddressBook* local, KABC::AddressBo ++deletedAddresseeR; } else { inR.setRevision( modifiedCalendar ); - remote->insertAddressee( inR ); + remote->insertAddressee( inR, false ); inL = inR; inL.setResource( 0 ); - local->insertAddressee( inL ); + local->insertAddressee( inL , false); ++addedAddressee; } } else { if ( inR.revision() > mLastAddressbookSync || mode == 5 ) { inR.setRevision( modifiedCalendar ); - remote->insertAddressee( inR ); + remote->insertAddressee( inR, false ); inR.setResource( 0 ); - local->insertAddressee( inR ); + local->insertAddressee( inR, false ); ++addedAddressee; } else { // pending checkExternSyncAddressee(addresseeRSyncSharp, inR); @@ -2731,11 +2869,11 @@ bool KABCore::synchronizeAddressbooks( KABC::AddressBook* local, KABC::AddressBo ++addedAddresseeR; //qDebug("remote added Incidence %s ", inL.summary().latin1()); inL.setRevision( modifiedCalendar ); - local->insertAddressee( inL ); + local->insertAddressee( inL, false ); inR = inL; inR.setTempSyncStat( SYNC_TEMPSTATE_INITIAL ); inR.setResource( 0 ); - remote->insertAddressee( inR ); + remote->insertAddressee( inR, false ); } } } else { @@ -2747,10 +2885,10 @@ bool KABCore::synchronizeAddressbooks( KABC::AddressBook* local, KABC::AddressBo if ( ! KABPrefs::instance()->mWriteBackExistingOnly ) { ++addedAddresseeR; inL.setRevision( modifiedCalendar ); - local->insertAddressee( inL ); + local->insertAddressee( inL, false ); inR = inL; inR.setResource( 0 ); - remote->insertAddressee( inR ); + remote->insertAddressee( inR, false ); } } } @@ -2759,35 +2897,27 @@ bool KABCore::synchronizeAddressbooks( KABC::AddressBook* local, KABC::AddressBo ++incCounter; } el.clear(); - int delFut = 0; - #if 0 + bar.hide(); mLastAddressbookSync = QDateTime::currentDateTime().addSecs( 1 ); addresseeLSync.setRevision( mLastAddressbookSync ); addresseeRSync.setRevision( mLastAddressbookSync ); - addresseeRSync.setLocation( i18n("Remote from: ")+mCurrentSyncName ) ; - addresseeLSync.setLocation(i18n("Local from: ") + mCurrentSyncName ); - addresseeLSync.setReadOnly( true ); + addresseeRSync.setGivenName( i18n("Remote from: ")+mCurrentSyncName ) ; + addresseeLSync.setGivenName(i18n("Local from: ") + mCurrentSyncName ); if ( mGlobalSyncMode == SYNC_MODE_NORMAL) - remote->addAddressee( addresseeRSync ); + remote->insertAddressee( addresseeRSync, false ); + local->insertAddressee( addresseeLSync, 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"),addedAddressee, addedAddresseeR, changedLocal, changedRemote, deletedAddresseeL, deletedAddresseeR ); - QString delmess; - if ( delFut ) { - delmess.sprintf( i18n("%d items skipped on remote,\nbecause they are in the past or\nmore than %d weeks in the future.\n"),delFut, KOPrefs::instance()->mWriteBackInFuture ); - mes += delmess; - } - if ( KOPrefs::instance()->mShowSyncSummary ) { + if ( KABPrefs::instance()->mShowSyncSummary ) { KMessageBox::information(this, mes, i18n("KO/Pi Synchronization") ); } qDebug( mes ); - mCalendar->checkAlarmForIncidence( 0, true ); return syncOK; -#endif - return false; } + bool KABCore::syncAB(QString filename, int mode) { @@ -2799,10 +2929,10 @@ bool KABCore::syncAB(QString filename, int mode) if ( abLocal.load() ) { qDebug("AB loaded %s mode %d",filename.latin1(), mode ); AddressBook::Iterator it; - QStringList vcards; - for ( it = abLocal.begin(); it != abLocal.end(); ++it ) { - qDebug("Name %s ", (*it).familyName().latin1()); - } + //QStringList vcards; + //for ( it = abLocal.begin(); it != abLocal.end(); ++it ) { + // qDebug("Name %s ", (*it).familyName().latin1()); + //} syncOK = synchronizeAddressbooks( mAddressBook, &abLocal, mode ); if ( syncOK ) { if ( KABPrefs::instance()->mWriteBackFile ) diff --git a/kaddressbook/kabcore.h b/kaddressbook/kabcore.h index c67cee6..f01f306 100644 --- a/kaddressbook/kabcore.h +++ b/kaddressbook/kabcore.h @@ -474,6 +474,7 @@ class KABCore : public QWidget bool synchronizeAddressbooks( KABC::AddressBook* local, KABC::AddressBook* remote,int mode); KABC::Addressee getLastSyncAddressee(); QDateTime mLastAddressbookSync; + int takeAddressee( KABC::Addressee* local, KABC::Addressee* remote, int mode , bool full ); public slots: void confSync(); // ********************* |