-rw-r--r-- | kaddressbook/kabcore.cpp | 14 |
1 files changed, 9 insertions, 5 deletions
diff --git a/kaddressbook/kabcore.cpp b/kaddressbook/kabcore.cpp index bdc5bd8..c75b4bc 100644 --- a/kaddressbook/kabcore.cpp +++ b/kaddressbook/kabcore.cpp @@ -2543,317 +2543,321 @@ bool KABCore::synchronizeAddressbooks( KABC::AddressBook* local, KABC::AddressBo // KABC::Addressee::List addresseeRSyncSharp = remote->getExternLastSyncAddressees(); //KABC::Addressee::List addresseeLSyncSharp = local->getExternLastSyncAddressees(); bool fullDateRange = false; local->resetTempSyncStat(); mLastAddressbookSync = QDateTime::currentDateTime(); if ( syncManager->syncWithDesktop() ) { // remote->removeSyncInfo( QString());//remove all info if ( KSyncManager::mRequestedSyncEvent.isValid() ) { mLastAddressbookSync = KSyncManager::mRequestedSyncEvent; qDebug("using extern time for calendar sync: %s ", mLastAddressbookSync.toString().latin1() ); } else { qDebug("KSyncManager::mRequestedSyncEvent has invalid datatime "); } } QDateTime modifiedCalendar = mLastAddressbookSync; addresseeLSync = getLastSyncAddressee(); qDebug("Last Sync %s ", addresseeLSync.revision().toString().latin1()); addresseeR = remote->findByUid("last-syncAddressee-"+mCurrentSyncName ); if ( !addresseeR.isEmpty() ) { addresseeRSync = addresseeR; remote->removeAddressee(addresseeR ); } else { if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL ) { addresseeRSync = addresseeLSync ; } else { qDebug("FULLDATE 1"); fullDateRange = true; Addressee newAdd; addresseeRSync = newAdd; addresseeRSync.setFamilyName(mCurrentSyncName + i18n(" - sync addressee")); addresseeRSync.setUid("last-syncAddressee-"+mCurrentSyncName ); addresseeRSync.setRevision( mLastAddressbookSync ); addresseeRSync.setCategories( i18n("SyncAddressee") ); } } 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() ); } } // fullDateRange = true; // debug only! if ( fullDateRange ) mLastAddressbookSync = QDateTime::currentDateTime().addDays( -100*365); else mLastAddressbookSync = addresseeLSync.revision(); // for resyncing if own file has changed // PENDING fixme later when implemented #if 0 if ( mCurrentSyncDevice == "deleteaftersync" ) { mLastAddressbookSync = loadedFileVersion; qDebug("setting mLastAddressbookSync "); } #endif //qDebug("*************************** "); // qDebug("mLastAddressbookSync %s ",mLastAddressbookSync.toString().latin1() ); QStringList er = remote->uidList(); Addressee inR ;//= er.first(); Addressee inL; syncManager->showProgressBar(0, i18n("Syncing - close to abort!"), er.count()); int modulo = (er.count()/10)+1; int incCounter = 0; while ( incCounter < er.count()) { if (syncManager->isProgressBarCanceled()) return false; if ( incCounter % modulo == 0 ) syncManager->showProgressBar(incCounter); uid = er[ incCounter ]; bool skipIncidence = false; if ( uid.left(19) == QString("last-syncAddressee-") ) skipIncidence = true; QString idS,OidS; qApp->processEvents(); if ( !skipIncidence ) { inL = local->findByUid( uid ); inR = remote->findByUid( uid ); //inL.setResource( 0 ); //inR.setResource( 0 ); if ( !inL.isEmpty() ) { // maybe conflict - same uid in both calendars if ( !inL.resource() || inL.resource()->includeInSync() ) { 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 ( take == 1 ) {// take local ********************** if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL ) { inL.setCsum( mCurrentSyncDevice, inR.getCsum(mCurrentSyncDevice) ); inL.setID( mCurrentSyncDevice, inR.getID(mCurrentSyncDevice) ); local->insertAddressee( inL, false ); idS = inR.externalUID(); OidS = inR.originalExternalUID(); } else idS = inR.IDStr(); remote->removeAddressee( inR ); inR = inL; inR.setTempSyncStat( SYNC_TEMPSTATE_INITIAL ); if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL ) { inR.setOriginalExternalUID( OidS ); inR.setExternalUID( idS ); if ( syncManager->syncWithDesktop() ) inR.setIDStr("changed" ); //inR.insertCustom( "KADDRESSBOOK", "X-KDESYNC","changed" ); } else { inR.setIDStr( idS ); } inR.setResource( 0 ); remote->insertAddressee( inR , false); ++changedRemote; - } else { // take == 2 take remote + } 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 ); if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL ) { inL.setCsum( mCurrentSyncDevice, inR.getCsum(mCurrentSyncDevice) ); inL.setID( mCurrentSyncDevice, inR.getID(mCurrentSyncDevice) ); } inL.setResource( 0 ); local->insertAddressee( inL , false ); ++changedLocal; } } } - } else { // no conflict + } else { // no conflict ********** add or delete remote if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL ) { QString des = addresseeLSync.note(); if ( des.find( inR.getID(mCurrentSyncDevice) +"," ) >= 0 && mode != 5) { // delete it inR.setTempSyncStat( SYNC_TEMPSTATE_DELETE ); remote->insertAddressee( inR, false ); ++deletedAddresseeR; } else { inR.setRevision( modifiedCalendar ); remote->insertAddressee( inR, false ); - inL = inR; + inL = inR; + inL.setIDStr( ":" ); + inL.setCsum( mCurrentSyncDevice, inR.getCsum(mCurrentSyncDevice) ); + inL.setID( mCurrentSyncDevice, inR.getID(mCurrentSyncDevice) ); inL.setResource( 0 ); local->insertAddressee( inL , false); ++addedAddressee; } } else { if ( inR.revision() > mLastAddressbookSync || mode == 5 ) { inR.setRevision( modifiedCalendar ); remote->insertAddressee( inR, false ); inR.setResource( 0 ); local->insertAddressee( inR, false ); ++addedAddressee; } else { // pending checkExternSyncAddressee(addresseeRSyncSharp, inR); remote->removeAddressee( inR ); ++deletedAddresseeR; } } } } ++incCounter; } er.clear(); QStringList el = local->uidList(); modulo = (el.count()/10)+1; syncManager->showProgressBar(0, i18n("Add / remove addressees"), el.count()); incCounter = 0; while ( incCounter < el.count()) { qApp->processEvents(); if (syncManager->isProgressBarCanceled()) return false; if ( incCounter % modulo == 0 ) syncManager->showProgressBar(incCounter); uid = el[ incCounter ]; bool skipIncidence = false; if ( uid.left(19) == QString("last-syncAddressee-") ) skipIncidence = true; if ( !skipIncidence ) { inL = local->findByUid( uid ); if ( !inL.resource() || inL.resource()->includeInSync() ) { inR = remote->findByUid( uid ); - if ( inR.isEmpty() ) { + if ( inR.isEmpty() ) { / no conflict ********** add or delete local if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL ) { if ( !inL.getID(mCurrentSyncDevice).isEmpty() && mode != 4 ) { // pending checkExternSyncAddressee(addresseeLSyncSharp, inL); local->removeAddressee( inL ); ++deletedAddresseeL; } else { if ( ! syncManager->mWriteBackExistingOnly ) { inL.removeID(mCurrentSyncDevice ); ++addedAddresseeR; inL.setRevision( modifiedCalendar ); local->insertAddressee( inL, false ); inR = inL; inR.setTempSyncStat( SYNC_TEMPSTATE_ADDED_EXTERNAL ); inR.setResource( 0 ); remote->insertAddressee( inR, false ); } } } else { if ( inL.revision() < mLastAddressbookSync && mode != 4 ) { // pending checkExternSyncAddressee(addresseeLSyncSharp, inL); local->removeAddressee( inL ); ++deletedAddresseeL; } else { if ( ! syncManager->mWriteBackExistingOnly ) { ++addedAddresseeR; inL.setRevision( modifiedCalendar ); local->insertAddressee( inL, false ); inR = inL; + inR.setIDStr( ":" ); inR.setResource( 0 ); remote->insertAddressee( inR, false ); } } } } } } ++incCounter; } el.clear(); syncManager->hideProgressBar(); mLastAddressbookSync = QDateTime::currentDateTime().addSecs( 1 ); // get rid of micro seconds QTime t = mLastAddressbookSync.time(); mLastAddressbookSync.setTime( QTime (t.hour (), t.minute (), t.second () ) ); addresseeLSync.setRevision( mLastAddressbookSync ); addresseeRSync.setRevision( mLastAddressbookSync ); addresseeRSync.setRole( i18n("!Remote from: ")+mCurrentSyncName ) ; addresseeLSync.setRole(i18n("!Local from: ") + mCurrentSyncName ); addresseeRSync.setGivenName( i18n("!DO NOT EDIT!") ) ; addresseeLSync.setGivenName(i18n("!DO NOT EDIT!") ); addresseeRSync.setOrganization( "!"+mLastAddressbookSync.toString() ) ; addresseeLSync.setOrganization("!"+ mLastAddressbookSync.toString() ); addresseeRSync.setNote( "" ) ; addresseeLSync.setNote( "" ); if ( mGlobalSyncMode == SYNC_MODE_NORMAL) 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 ); qDebug( mes ); if ( syncManager->mShowSyncSummary ) { if ( KMessageBox::Cancel == KMessageBox::warningContinueCancel(this, mes, i18n("KA/Pi Synchronization"),i18n("Write back"))) { qDebug("cancelled "); return false; } } return syncOK; } //this is a overwritten callbackmethods from the syncinterface bool KABCore::sync(KSyncManager* manager, QString filename, int mode) { //pending prepare addresseeview for output //pending detect, if remote file has REV field. if not switch to external sync mGlobalSyncMode = SYNC_MODE_NORMAL; QString mCurrentSyncDevice = manager->getCurrentSyncDevice(); 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, true ); } else { external = !manager->mIsKapiFile; if ( external ) { qDebug("Setting vcf mode to external "); mGlobalSyncMode = SYNC_MODE_EXTERNAL; AddressBook::Iterator it; for ( it = abLocal.begin(); it != abLocal.end(); ++it ) { (*it).setID( mCurrentSyncDevice, (*it).uid() ); (*it).computeCsum( mCurrentSyncDevice ); } } } //AddressBook::Iterator it; //QStringList vcards; //for ( it = abLocal.begin(); it != abLocal.end(); ++it ) { // qDebug("Name %s ", (*it).familyName().latin1()); //} syncOK = synchronizeAddressbooks( mAddressBook, &abLocal, mode ); if ( syncOK ) { if ( syncManager->mWriteBackFile ) { if ( external ) abLocal.removeSyncAddressees( !isXML); qDebug("Saving remote AB "); if ( ! abLocal.saveAB()) qDebug("Error writing back AB to file "); if ( external ) { // afterwrite processing abLocal.postExternSync( mAddressBook,mCurrentSyncDevice ,isXML); } } } setModified(); |