summaryrefslogtreecommitdiffabout
authorzautrix <zautrix>2004-09-18 08:51:10 (UTC)
committer zautrix <zautrix>2004-09-18 08:51:10 (UTC)
commit4ec7c78ebd2c5a79ff224e9b07d9a3164f7fe602 (patch) (side-by-side diff)
tree0beaebd8819f1fc4a36fb8fc115ff97ac43c3db3
parent983b010853dfadfec3638e2afd90e522985f67fb (diff)
downloadkdepimpi-4ec7c78ebd2c5a79ff224e9b07d9a3164f7fe602.zip
kdepimpi-4ec7c78ebd2c5a79ff224e9b07d9a3164f7fe602.tar.gz
kdepimpi-4ec7c78ebd2c5a79ff224e9b07d9a3164f7fe602.tar.bz2
more AB sync
Diffstat (more/less context) (show whitespace changes)
-rw-r--r--kaddressbook/kabcore.cpp291
1 files changed, 276 insertions, 15 deletions
diff --git a/kaddressbook/kabcore.cpp b/kaddressbook/kabcore.cpp
index e912941..1196360 100644
--- a/kaddressbook/kabcore.cpp
+++ b/kaddressbook/kabcore.cpp
@@ -2515,13 +2515,283 @@ QString KABCore::getPassword( )
}
bool KABCore::synchronizeAddressbooks( KABC::AddressBook* local, KABC::AddressBook* remote,int mode)
{
+#if 0
+ bool syncOK = true;
+ int addedAddressee = 0;
+ int addedAddresseeR = 0;
+ int deletedAddresseeR = 0;
+ int deletedAddresseeL = 0;
+ int changedLocal = 0;
+ int changedRemote = 0;
+ //QPtrList<Addressee> el = local->rawAddressees();
+ Addressee* addresseeR;
+ QString uid;
+ int take;
+ Addressee* addresseeL;
+ Addressee* addresseeRSync;
+ Addressee* addresseeLSync;
+ QPtrList<Addressee> addresseeRSyncSharp = remote->getExternLastSyncAddressees();
+ QPtrList<Addressee> addresseeLSyncSharp = local->getExternLastSyncAddressees();
+ bool fullDateRange = false;
+ local->resetTempSyncStat();
+ mLastCalendarSync = QDateTime::currentDateTime();
+ QDateTime modifiedCalendar = mLastCalendarSync;;
+ addresseeLSync = getLastSyncAddressee();
+ addresseeR = remote->addressee("last-syncAddressee-"+mCurrentSyncName );
+ if ( addresseeR ) {
+ addresseeRSync = (Addressee*) addresseeR->clone();
+ remote->deleteAddressee(addresseeR );
+ } else {
+ if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL ) {
+ addresseeRSync = (Addressee*)addresseeLSync->clone();
+ } else {
+ fullDateRange = true;
+ addresseeRSync = new Addressee();
+ addresseeRSync->setSummary(mCurrentSyncName + i18n(" - sync addressee"));
+ addresseeRSync->setUid("last-syncAddressee-"+mCurrentSyncName );
+ addresseeRSync->setDtStart( mLastCalendarSync );
+ addresseeRSync->setDtEnd( mLastCalendarSync.addSecs( 7200 ) );
+ addresseeRSync->setCategories( i18n("SyncAddressee") );
}
-bool KABCore::syncAB(QString filename, int mode)
-{
+ }
+ if ( addresseeLSync->dtStart() == mLastCalendarSync )
+ fullDateRange = true;
+ if ( ! fullDateRange ) {
+ if ( addresseeLSync->dtStart() != addresseeRSync->dtStart() ) {
+ // 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;
+ }
+ }
+ if ( fullDateRange )
+ mLastCalendarSync = QDateTime::currentDateTime().addDays( -100*365);
+ else
+ mLastCalendarSync = addresseeLSync->dtStart();
+ // for resyncing if own file has changed
+ if ( mCurrentSyncDevice == "deleteaftersync" ) {
+ mLastCalendarSync = loadedFileVersion;
+ qDebug("setting mLastCalendarSync ");
+ }
+ //qDebug("*************************** ");
+ qDebug("mLastCalendarSync %s ",mLastCalendarSync.toString().latin1() );
+ QPtrList<Incidence> er = remote->rawIncidences();
+ Incidence* inR = er.first();
+ Incidence* inL;
+ QProgressBar bar( er.count(),0 );
+ bar.setCaption (i18n("Syncing - close to abort!") );
+
+ int w = 300;
+ if ( QApplication::desktop()->width() < 320 )
+ w = 220;
+ int h = bar.sizeHint().height() ;
+ int dw = QApplication::desktop()->width();
+ int dh = QApplication::desktop()->height();
+ bar.setGeometry( (dw-w)/2, (dh - h )/2 ,w,h );
+ bar.show();
+ int modulo = (er.count()/10)+1;
+ int incCounter = 0;
+ while ( inR ) {
+ if ( ! bar.isVisible() )
+ return false;
+ if ( incCounter % modulo == 0 )
+ bar.setProgress( incCounter );
+ ++incCounter;
+ uid = inR->uid();
+ bool skipIncidence = false;
+ if ( uid.left(15) == QString("last-syncAddressee-") )
+ skipIncidence = true;
+ QString idS;
+ qApp->processAddressees();
+ if ( !skipIncidence ) {
+ inL = local->incidence( uid );
+ if ( inL ) { // maybe conflict - same uid in both calendars
+ int maxrev = inL->revision();
+ if ( maxrev < inR->revision() )
+ maxrev = inR->revision();
+ if ( (take = takeAddressee( inL, inR, mode, fullDateRange )) > 0 ) {
+ //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) );
+ else
+ idS = inR->IDStr();
+ remote->deleteIncidence( inR );
+ if ( inL->revision() < maxrev )
+ inL->setRevision( maxrev );
+ inR = inL->clone();
+ inR->setTempSyncStat( SYNC_TEMPSTATE_INITIAL );
+ if ( mGlobalSyncMode != SYNC_MODE_EXTERNAL )
+ inR->setIDStr( idS );
+ remote->addIncidence( inR );
+ ++changedRemote;
+ } else {
+ if ( inR->revision() < maxrev )
+ inR->setRevision( maxrev );
+ idS = inL->IDStr();
+ local->deleteIncidence( inL );
+ inL = inR->clone();
+ inL->setIDStr( idS );
+ local->addIncidence( inL );
+ ++changedLocal;
+ }
+ }
+ } else { // no conflict
+ if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL ) {
+ QString des = addresseeLSync->description();
+ QString pref = "e";
+ if ( inR->type() == "Todo" )
+ pref = "t";
+ if ( des.find(pref+ inR->getID(mCurrentSyncDevice) +"," ) >= 0 && mode != 5) { // delete it
+ inR->setTempSyncStat( SYNC_TEMPSTATE_DELETE );
+ //remote->deleteIncidence( inR );
+ ++deletedAddresseeR;
+ } else {
+ inR->setLastModified( modifiedCalendar );
+ inL = inR->clone();
+ local->addIncidence( inL );
+ ++addedAddressee;
+ }
+ } else {
+ if ( inR->lastModified() > mLastCalendarSync || mode == 5 ) {
+ inR->setLastModified( modifiedCalendar );
+ local->addIncidence( inR->clone() );
+ ++addedAddressee;
+ } else {
+ checkExternSyncAddressee(addresseeRSyncSharp, inR);
+ remote->deleteIncidence( inR );
+ ++deletedAddresseeR;
+ }
+ }
+ }
+ }
+ inR = er.next();
+ }
+ QPtrList<Incidence> el = local->rawIncidences();
+ inL = el.first();
+ modulo = (el.count()/10)+1;
+ bar.setCaption (i18n("Add / remove addressees") );
+ bar.setTotalSteps ( el.count() ) ;
+ bar.show();
+ incCounter = 0;
+
+ while ( inL ) {
+
+ qApp->processAddressees();
+ if ( ! bar.isVisible() )
+ return false;
+ if ( incCounter % modulo == 0 )
+ bar.setProgress( incCounter );
+ ++incCounter;
+ uid = inL->uid();
+ bool skipIncidence = false;
+ if ( uid.left(15) == QString("last-syncAddressee-") )
+ skipIncidence = true;
+ if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL && inL->type() == "Journal" )
+ skipIncidence = true;
+ if ( !skipIncidence ) {
+ inR = remote->incidence( uid );
+ if ( ! inR ) {
+ if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL ) {
+ if ( !inL->getID(mCurrentSyncDevice).isEmpty() && mode != 4 ) {
+ checkExternSyncAddressee(addresseeLSyncSharp, inL);
+ local->deleteIncidence( inL );
+ ++deletedAddresseeL;
+ } else {
+ if ( ! KOPrefs::instance()->mWriteBackExistingOnly ) {
+ inL->removeID(mCurrentSyncDevice );
+ ++addedAddresseeR;
+ //qDebug("remote added Incidence %s ", inL->summary().latin1());
+ inL->setLastModified( modifiedCalendar );
+ inR = inL->clone();
+ inR->setTempSyncStat( SYNC_TEMPSTATE_INITIAL );
+ remote->addIncidence( inR );
+ }
+ }
+ } else {
+ if ( inL->lastModified() < mLastCalendarSync && mode != 4 ) {
+ checkExternSyncAddressee(addresseeLSyncSharp, inL);
+ local->deleteIncidence( inL );
+ ++deletedAddresseeL;
+ } else {
+ if ( ! KOPrefs::instance()->mWriteBackExistingOnly ) {
+ ++addedAddresseeR;
+ inL->setLastModified( modifiedCalendar );
+ remote->addIncidence( inL->clone() );
+ }
+ }
+ }
+ }
+ }
+ inL = el.next();
+ }
+ int delFut = 0;
+ if ( KOPrefs::instance()->mWriteBackInFuture ) {
+ er = remote->rawIncidences();
+ inR = er.first();
+ QDateTime dt;
+ QDateTime cur = QDateTime::currentDateTime();
+ QDateTime end = cur.addSecs( KOPrefs::instance()->mWriteBackInFuture * 3600 *24 *7 );
+ while ( inR ) {
+ if ( inR->type() == "Todo" ) {
+ Todo * t = (Todo*)inR;
+ if ( t->hasDueDate() )
+ dt = t->dtDue();
+ else
+ dt = cur.addSecs( 62 );
+ }
+ else if (inR->type() == "Addressee" ) {
+ bool ok;
+ dt = inR->getNextOccurence( cur, &ok );
+ if ( !ok )
+ dt = cur.addSecs( -62 );
+ }
+ else
+ dt = inR->dtStart();
+ if ( dt < cur || dt > end ) {
+ remote->deleteIncidence( inR );
+ ++delFut;
+ }
+ inR = er.next();
+ }
+ }
+ bar.hide();
+ mLastCalendarSync = QDateTime::currentDateTime().addSecs( 1 );
+ addresseeLSync->setReadOnly( false );
+ addresseeLSync->setDtStart( mLastCalendarSync );
+ addresseeRSync->setDtStart( mLastCalendarSync );
+ addresseeLSync->setDtEnd( mLastCalendarSync.addSecs( 3600 ) );
+ addresseeRSync->setDtEnd( mLastCalendarSync.addSecs( 3600 ) );
+ addresseeRSync->setLocation( i18n("Remote from: ")+mCurrentSyncName ) ;
+ addresseeLSync->setLocation(i18n("Local from: ") + mCurrentSyncName );
+ addresseeLSync->setReadOnly( true );
+ if ( mGlobalSyncMode == SYNC_MODE_NORMAL)
+ remote->addAddressee( addresseeRSync );
+ 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 ) {
+ 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)
+{
+ //pending prepare addresseeview for output
+ //pending detect, if remote file has REV field. if not switch to external sync
mGlobalSyncMode = SYNC_MODE_NORMAL;
AddressBook abLocal(filename,"syncContact");
bool syncOK = false;
@@ -2536,6 +2806,7 @@ bool KABCore::syncAB(QString filename, int mode)
if ( syncOK ) {
if ( KABPrefs::instance()->mWriteBackFile )
{
+ qDebug("saving remote AB ");
abLocal.saveAB();
}
}
@@ -2543,16 +2814,10 @@ bool KABCore::syncAB(QString filename, int mode)
}
if ( syncOK )
- ;//updateView();
+ mViewManager->refreshView();
return syncOK;
#if 0
- mGlobalSyncMode = SYNC_MODE_NORMAL;
- CalendarLocal* calendar = new CalendarLocal();
- calendar->setTimeZoneId(KOPrefs::instance()->mTimeZoneId);
- FileStorage* storage = new FileStorage( calendar );
- bool syncOK = false;
- storage->setFileName( filename );
- // qDebug("loading ... ");
+
if ( storage->load(KOPrefs::instance()->mUseQuicksave) ) {
getEventViewerDialog()->setSyncMode( true );
syncOK = synchronizeCalendar( mCalendar, calendar, mode );
@@ -2566,11 +2831,7 @@ bool KABCore::syncAB(QString filename, int mode)
}
setModified();
}
- delete storage;
- delete calendar;
- if ( syncOK )
- updateView();
- return syncOK;
+
#endif
}