summaryrefslogtreecommitdiffabout
authorzautrix <zautrix>2004-09-18 14:22:10 (UTC)
committer zautrix <zautrix>2004-09-18 14:22:10 (UTC)
commitca8fcf3fd4dc068747d8f31e2189145b22853d55 (patch) (side-by-side diff)
tree29417ffd55d1c4186922a64ed0cdf1c6a1cc69a3
parentbb16660f29fc709791aa0ee4cb63a40710a994a8 (diff)
downloadkdepimpi-ca8fcf3fd4dc068747d8f31e2189145b22853d55.zip
kdepimpi-ca8fcf3fd4dc068747d8f31e2189145b22853d55.tar.gz
kdepimpi-ca8fcf3fd4dc068747d8f31e2189145b22853d55.tar.bz2
more AB sync
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--kabc/addressbook.cpp15
-rw-r--r--kabc/addressbook.h3
-rw-r--r--kaddressbook/kabcore.cpp206
3 files changed, 105 insertions, 119 deletions
diff --git a/kabc/addressbook.cpp b/kabc/addressbook.cpp
index 9332e21..6e8d027 100644
--- a/kabc/addressbook.cpp
+++ b/kabc/addressbook.cpp
@@ -530,7 +530,5 @@ Addressee::List AddressBook::getExternLastSyncAddressees()
void AddressBook::resetTempSyncStat()
{
-
-
- Iterator it;
+ Iterator it;
for ( it = begin(); it != end(); ++it ) {
(*it).setTempSyncStat ( SYNC_TEMPSTATE_INITIAL );
@@ -538,5 +536,14 @@ void AddressBook::resetTempSyncStat()
}
-
+
+QStringList AddressBook:: uidList()
+{
+ QStringList results;
+ Iterator it;
+ for ( it = begin(); it != end(); ++it ) {
+ results.append( (*it).uid() );
+ }
+ return results;
+}
diff --git a/kabc/addressbook.h b/kabc/addressbook.h
index 05225f9..650a638 100644
--- a/kabc/addressbook.h
+++ b/kabc/addressbook.h
@@ -291,5 +291,6 @@ class AddressBook : public QObject
// sync stuff
Addressee::List getExternLastSyncAddressees();
- void resetTempSyncStat();
+ void resetTempSyncStat();
+ QStringList uidList();
diff --git a/kaddressbook/kabcore.cpp b/kaddressbook/kabcore.cpp
index 53c63ff..f497541 100644
--- a/kaddressbook/kabcore.cpp
+++ b/kaddressbook/kabcore.cpp
@@ -34,4 +34,5 @@ $Id$
#include <klocale.h>
#include <kfiledialog.h>
+#include <qprogressbar.h>
#ifndef KAB_EMBEDDED
@@ -40,4 +41,5 @@ $Id$
#include <qfile.h>
#include <qapplicaton.h>
+#include <qprogressbar.h>
#include <qlayout.h>
#include <qregexp.h>
@@ -2598,10 +2600,9 @@ bool KABCore::synchronizeAddressbooks( KABC::AddressBook* local, KABC::AddressBo
#endif
- #if 0
//qDebug("*************************** ");
qDebug("mLastAddressbookSync %s ",mLastAddressbookSync.toString().latin1() );
- QPtrList<Incidence> er = remote->rawIncidences();
- Incidence* inR = er.first();
- Incidence* inL;
+ QStringList er = remote->uidList();
+ Addressee inR ;//= er.first();
+ Addressee inL;
QProgressBar bar( er.count(),0 );
bar.setCaption (i18n("Syncing - close to abort!") );
@@ -2617,48 +2618,48 @@ bool KABCore::synchronizeAddressbooks( KABC::AddressBook* local, KABC::AddressBo
int modulo = (er.count()/10)+1;
int incCounter = 0;
- while ( inR ) {
+ while ( incCounter < er.count()) {
if ( ! bar.isVisible() )
return false;
if ( incCounter % modulo == 0 )
bar.setProgress( incCounter );
- ++incCounter;
- uid = inR->uid();
+ uid = er[ incCounter ];
bool skipIncidence = false;
- if ( uid.left(15) == QString("last-syncAddressee-") )
+ if ( uid.left(20) == QString("last-syncAddressee-") )
skipIncidence = true;
QString idS;
- qApp->processAddressees();
+ qApp->processEvents();
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());
+ inL = local->findByUid( uid );
+ inR = remote->findByUid( uid );
+ //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 ) {
+ //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) );
+ if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL ) {
+ inL.setCsum( mCurrentSyncDevice, inR.getCsum(mCurrentSyncDevice) );
+ local->insertAddressee( inL );
+ }
else
- idS = inR->IDStr();
- remote->deleteIncidence( inR );
- if ( inL->revision() < maxrev )
- inL->setRevision( maxrev );
- inR = inL->clone();
- inR->setTempSyncStat( SYNC_TEMPSTATE_INITIAL );
+ idS = inR.IDStr();
+ remote->removeAddressee( inR );
+ inR = inL;
+ inR.setTempSyncStat( SYNC_TEMPSTATE_INITIAL );
if ( mGlobalSyncMode != SYNC_MODE_EXTERNAL )
- inR->setIDStr( idS );
- remote->addIncidence( inR );
+ inR.setIDStr( idS );
+ inR.setResource( 0 );
+ remote->insertAddressee( 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 );
+ idS = inL.IDStr();
+ local->removeAddressee( inL );
+ inL = inR;
+ inL.setIDStr( idS );
+ inL.setResource( 0 );
+ local->insertAddressee( inL );
++changedLocal;
}
@@ -2666,26 +2667,27 @@ bool KABCore::synchronizeAddressbooks( KABC::AddressBook* local, KABC::AddressBo
} 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 );
+ QString des = addresseeLSync.note();
+ QString pref = "a";
+ if ( des.find(pref+ inR.getID(mCurrentSyncDevice) +"," ) >= 0 && mode != 5) { // delete it
+ inR.setTempSyncStat( SYNC_TEMPSTATE_DELETE );
++deletedAddresseeR;
} else {
- inR->setLastModified( modifiedCalendar );
- inL = inR->clone();
- local->addIncidence( inL );
+ inR.setRevision( modifiedCalendar );
+ remote->insertAddressee( inR );
+ inL = inR;
+ inL.setResource( 0 );
+ local->insertAddressee( inL );
++addedAddressee;
}
} else {
- if ( inR->lastModified() > mLastAddressbookSync || mode == 5 ) {
- inR->setLastModified( modifiedCalendar );
- local->addIncidence( inR->clone() );
+ if ( inR.revision() > mLastAddressbookSync || mode == 5 ) {
+ inR.setRevision( modifiedCalendar );
+ remote->insertAddressee( inR );
+ inR.setResource( 0 );
+ local->insertAddressee( inR );
++addedAddressee;
} else {
- checkExternSyncAddressee(addresseeRSyncSharp, inR);
- remote->deleteIncidence( inR );
+ // pending checkExternSyncAddressee(addresseeRSyncSharp, inR);
+ remote->removeAddressee( inR );
++deletedAddresseeR;
}
@@ -2693,8 +2695,8 @@ bool KABCore::synchronizeAddressbooks( KABC::AddressBook* local, KABC::AddressBo
}
}
- inR = er.next();
+ ++incCounter;
}
- QPtrList<Incidence> el = local->rawIncidences();
- inL = el.first();
+ er.clear();
+ QStringList el = remote->uidList();
modulo = (el.count()/10)+1;
bar.setCaption (i18n("Add / remove addressees") );
@@ -2702,48 +2704,52 @@ bool KABCore::synchronizeAddressbooks( KABC::AddressBook* local, KABC::AddressBo
bar.show();
incCounter = 0;
-
- while ( inL ) {
+ while ( incCounter < el.count()) {
- qApp->processAddressees();
+ qApp->processEvents();
if ( ! bar.isVisible() )
return false;
if ( incCounter % modulo == 0 )
bar.setProgress( incCounter );
- ++incCounter;
- uid = inL->uid();
+ uid = el[ incCounter ];
bool skipIncidence = false;
- if ( uid.left(15) == QString("last-syncAddressee-") )
+ if ( uid.left(20) == QString("last-syncAddressee-") )
skipIncidence = true;
- if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL && inL->type() == "Journal" )
+ if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL )
skipIncidence = true;
if ( !skipIncidence ) {
- inR = remote->incidence( uid );
- if ( ! inR ) {
+ inL = local->findByUid( uid );
+ inR = remote->findByUid( uid );
+ if ( inR.isEmpty() ) {
if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL ) {
- if ( !inL->getID(mCurrentSyncDevice).isEmpty() && mode != 4 ) {
- checkExternSyncAddressee(addresseeLSyncSharp, inL);
- local->deleteIncidence( inL );
+ if ( !inL.getID(mCurrentSyncDevice).isEmpty() && mode != 4 ) {
+ // pending checkExternSyncAddressee(addresseeLSyncSharp, inL);
+ local->removeAddressee( inL );
++deletedAddresseeL;
} else {
- if ( ! KOPrefs::instance()->mWriteBackExistingOnly ) {
- inL->removeID(mCurrentSyncDevice );
+ if ( ! KABPrefs::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 );
+ //qDebug("remote added Incidence %s ", inL.summary().latin1());
+ inL.setRevision( modifiedCalendar );
+ local->insertAddressee( inL );
+ inR = inL;
+ inR.setTempSyncStat( SYNC_TEMPSTATE_INITIAL );
+ inR.setResource( 0 );
+ remote->insertAddressee( inR );
}
}
} else {
- if ( inL->lastModified() < mLastAddressbookSync && mode != 4 ) {
- checkExternSyncAddressee(addresseeLSyncSharp, inL);
- local->deleteIncidence( inL );
+ if ( inL.revision() < mLastAddressbookSync && mode != 4 ) {
+ // pending checkExternSyncAddressee(addresseeLSyncSharp, inL);
+ local->removeAddressee( inL );
++deletedAddresseeL;
} else {
- if ( ! KOPrefs::instance()->mWriteBackExistingOnly ) {
+ if ( ! KABPrefs::instance()->mWriteBackExistingOnly ) {
++addedAddresseeR;
- inL->setLastModified( modifiedCalendar );
- remote->addIncidence( inL->clone() );
+ inL.setRevision( modifiedCalendar );
+ local->insertAddressee( inL );
+ inR = inL;
+ inR.setResource( 0 );
+ remote->insertAddressee( inR );
}
}
@@ -2751,46 +2757,18 @@ bool KABCore::synchronizeAddressbooks( KABC::AddressBook* local, KABC::AddressBo
}
}
- inL = el.next();
+ ++incCounter;
}
+ el.clear();
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();
- }
- }
+
+ #if 0
+
bar.hide();
mLastAddressbookSync = QDateTime::currentDateTime().addSecs( 1 );
- addresseeLSync->setReadOnly( false );
- addresseeLSync->setDtStart( mLastAddressbookSync );
- addresseeRSync->setDtStart( mLastAddressbookSync );
- addresseeLSync->setDtEnd( mLastAddressbookSync.addSecs( 3600 ) );
- addresseeRSync->setDtEnd( mLastAddressbookSync.addSecs( 3600 ) );
- addresseeRSync->setLocation( i18n("Remote from: ")+mCurrentSyncName ) ;
- addresseeLSync->setLocation(i18n("Local from: ") + mCurrentSyncName );
- addresseeLSync->setReadOnly( true );
+ addresseeLSync.setRevision( mLastAddressbookSync );
+ addresseeRSync.setRevision( mLastAddressbookSync );
+ addresseeRSync.setLocation( i18n("Remote from: ")+mCurrentSyncName ) ;
+ addresseeLSync.setLocation(i18n("Local from: ") + mCurrentSyncName );
+ addresseeLSync.setReadOnly( true );
if ( mGlobalSyncMode == SYNC_MODE_NORMAL)
remote->addAddressee( addresseeRSync );