summaryrefslogtreecommitdiffabout
authorzautrix <zautrix>2004-09-20 00:12:42 (UTC)
committer zautrix <zautrix>2004-09-20 00:12:42 (UTC)
commitb01b669d88fa195261d29ecf73b1c69e608a5ebc (patch) (side-by-side diff)
treec0e79d45242a764b49470d07a9c95be156c121cc
parent3da2cfeab2edbe64a17251662e56668fe143f7a3 (diff)
downloadkdepimpi-b01b669d88fa195261d29ecf73b1c69e608a5ebc.zip
kdepimpi-b01b669d88fa195261d29ecf73b1c69e608a5ebc.tar.gz
kdepimpi-b01b669d88fa195261d29ecf73b1c69e608a5ebc.tar.bz2
more AB sync
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--kabc/addressbook.cpp27
-rw-r--r--kabc/addressbook.h3
-rw-r--r--kabc/addressee.cpp6
-rw-r--r--kabc/plugins/qtopia/qtopiaconverter.cpp2
-rw-r--r--kabc/plugins/qtopia/resourceqtopia.cpp79
-rw-r--r--kaddressbook/kabcore.cpp58
-rw-r--r--korganizer/calendarview.cpp44
7 files changed, 153 insertions, 66 deletions
diff --git a/kabc/addressbook.cpp b/kabc/addressbook.cpp
index 86dc7c2..17b9ba2 100644
--- a/kabc/addressbook.cpp
+++ b/kabc/addressbook.cpp
@@ -553,7 +553,6 @@ void AddressBook::removeAddressee( const Addressee &a )
}
-void AddressBook::removeDeletedAddressees()
+void AddressBook::removeSyncAddressees( bool removeDeleted )
{
- deleteRemovedAddressees();
Iterator it = begin();
Iterator it2 ;
@@ -563,10 +562,10 @@ void AddressBook::removeDeletedAddressees()
(*it).removeCustom( "KADDRESSBOOK", "X-ExternalID" );
(*it).setIDStr("");
- if ( (*it).tempSyncStat() == SYNC_TEMPSTATE_DELETE || (*it).uid().left( 19 ) == QString("last-syncAddressee-")) {
+ if ( ( (*it).tempSyncStat() == SYNC_TEMPSTATE_DELETE && removeDeleted )|| (*it).uid().left( 19 ) == QString("last-syncAddressee-")) {
it2 = it;
//qDebug("removing %s ",(*it).uid().latin1() );
++it;
removeAddressee( it2 );
- } else {
+ } else {
//qDebug("skipping %s ",(*it).uid().latin1() );
++it;
@@ -618,9 +617,10 @@ void AddressBook::postExternSync( AddressBook* aBook , const QString& csd)
AddressBook::Iterator it;
for ( it = begin(); it != end(); ++it ) {
+ qDebug("check uid %s ", (*it).uid().latin1() );
if ( (*it).tempSyncStat() == SYNC_TEMPSTATE_NEW_ID ||
(*it).tempSyncStat() == SYNC_TEMPSTATE_NEW_CSUM ) {
Addressee ad = aBook->findByUid( ( (*it).uid() ));
if ( ad.isEmpty() ) {
- qDebug("ERROR ad empty ");
+ qDebug("postExternSync:ERROR addressee is empty: %s ", (*it).uid().latin1());
} else {
(*it).computeCsum( csd );
@@ -634,5 +634,13 @@ void AddressBook::postExternSync( AddressBook* aBook , const QString& csd)
}
-
+bool AddressBook::containsExternalUid( const QString& uid )
+{
+ Iterator it;
+ for ( it = begin(); it != end(); ++it ) {
+ if ( uid == (*it).externalUID( ) )
+ return true;
+ }
+ return false;
+}
Addressee AddressBook::findByExternUid( const QString& uid , const QString& profile )
{
@@ -654,4 +662,11 @@ void AddressBook::mergeAB( AddressBook *aBook, const QString& profile )
}
}
+#if 0
+ // test only
+ for ( it = begin(); it != end(); ++it ) {
+
+ qDebug("uid %s ", (*it).uid().latin1());
+ }
+#endif
}
diff --git a/kabc/addressbook.h b/kabc/addressbook.h
index 157dc56..8f62f0d 100644
--- a/kabc/addressbook.h
+++ b/kabc/addressbook.h
@@ -293,7 +293,8 @@ class AddressBook : public QObject
void resetTempSyncStat();
QStringList uidList();
- void removeDeletedAddressees();
+ void removeSyncAddressees( bool removeDeleted = false );
void mergeAB( AddressBook *aBook, const QString& profile );
Addressee findByExternUid( const QString& uid , const QString& profile );
+ bool containsExternalUid( const QString& uid );
void preExternSync( AddressBook* aBook, const QString& csd );
diff --git a/kabc/addressee.cpp b/kabc/addressee.cpp
index fda62f1..e241281 100644
--- a/kabc/addressee.cpp
+++ b/kabc/addressee.cpp
@@ -96,5 +96,5 @@ Addressee::Addressee()
mData->resource = 0;
mData->mExternalId = ":";
- mData->revision = QDateTime ( QDate( 2004,1,1));
+ mData->revision = QDateTime ( QDate( 2003,1,1));
mData->mTempSyncStat = SYNC_TEMPSTATE_INITIAL;
}
@@ -309,4 +309,6 @@ void Addressee::mergeContact( const Addressee& ad )
// merging custom;
// merging keys
+ qDebug("merge contact %s ", ad.uid().latin1());
+ setUid( ad.uid() );
}
@@ -380,4 +382,5 @@ void Addressee::setOriginalExternalUID( const QString &id )
detach();
mData->empty = false;
+ qDebug("*******Set orig uid %s ", id.latin1());
mData->originalExternalUID = id;
}
@@ -392,4 +395,5 @@ void Addressee::setUid( const QString &id )
if ( id == mData->uid ) return;
detach();
+ qDebug("****setuid %s ", id.latin1());
mData->empty = false;
mData->uid = id;
diff --git a/kabc/plugins/qtopia/qtopiaconverter.cpp b/kabc/plugins/qtopia/qtopiaconverter.cpp
index de45e63..430c7b3 100644
--- a/kabc/plugins/qtopia/qtopiaconverter.cpp
+++ b/kabc/plugins/qtopia/qtopiaconverter.cpp
@@ -87,5 +87,5 @@ bool QtopiaConverter::qtopiaToAddressee( const PimContact &contact, Addressee &a
exuid = exuid.left( ente-1 );
addr.setExternalUID( exuid );
- //qDebug("QtopiaConverter:set uid %s ",addr.externalUID().latin1() );
+ qDebug("QtopiaConverter:set %s uid %s ",addr.originalExternalUID().latin1(),addr.externalUID().latin1() );
// email
diff --git a/kabc/plugins/qtopia/resourceqtopia.cpp b/kabc/plugins/qtopia/resourceqtopia.cpp
index 935a1cf..1f90fcb 100644
--- a/kabc/plugins/qtopia/resourceqtopia.cpp
+++ b/kabc/plugins/qtopia/resourceqtopia.cpp
@@ -198,32 +198,87 @@ bool ResourceQtopia::save( Ticket *ticket )
KABC::AddressBook::Iterator it;
bool res;
-
+ KABC::Addressee::List changedAddressees;
+ QStringList addedUID;
for ( it = addressBook()->begin(); it != addressBook()->end(); ++it ) {
//KABC::Addressee addressee = (*it);
+ // qDebug("AAAfor uid %s ", (*it).originalExternalUID().latin1() );
if ( (*it).tempSyncStat() != SYNC_TEMPSTATE_NEW_EXTERNAL ) {
QUuid uid( (*it).originalExternalUID() );
bool ok;
PimContact c = mAccess->contactForId( uid, &ok );
+ qDebug("ResourceQtopia::save:Found %d for uid %s ", ok,(*it).originalExternalUID().latin1() );
res = mConverter->addresseeToQtopia( *it, c );
if (res == true) {
if ( (*it).tempSyncStat() == SYNC_TEMPSTATE_ADDED_EXTERNAL ) {
- mAccess->addContact(c);
- KABC::Addressee addressee;
- mConverter->qtopiaToAddressee( c, addressee );
- addressee.setTempSyncStat( SYNC_TEMPSTATE_NEW_ID );
- addressBook()->insertAddressee( addressee );
+ qDebug("skipping adding of contact ");
+ continue;
+ PimContact e;
+ AddressBookAccess Access2;
+ Access2.addContact(e);
+ const PimContact* contact;
+ bool res;
+ QString uid2, Ouid;
+ AddressBookIterator itt(Access2);
+ for (contact=itt.toFirst(); itt.current(); ++itt)
+ {
+ contact = itt.current();
+ QString exuid = contact->uid().toString();
+ Ouid =exuid;
+ int ente = exuid.find( "-0000");
+ if ( exuid.left(1) == "{" )
+ exuid = exuid.mid(1);
+ if ( ente > -1 )
+ exuid = exuid.left( ente-1 );
+ uid2 = exuid;
+ qDebug("trying find uid ");
+ if ( !addressBook()->containsExternalUid( uid2 ) ) {
+ qDebug("ab not contains ");
+ if ( !addedUID.contains( uid2 )) {
+ qDebug("list not contains ");
+ break;
+ }
+ }
+
+ }
+ if ( !itt.current()) {
+ qDebug("ERROR uid ");
+ continue;
+ }
+ else
+ qDebug("ADD uid detected ");
+
+
+ QUuid uid3( Ouid);
+ PimContact d = Access2.contactForId( uid3, &ok );
+ if ( ! ok ) {
+ qDebug("ADD: Error getting new uid ");
+ } else {
+ qDebug("NEW UID found ");
+ PimContact g = mAccess->contactForId( c.uid(), &ok );
+ KABC::Addressee addressee;
+ mConverter->qtopiaToAddressee( g, addressee );
+ addressee.setUid((*it).uid() );
+ addressee.setTempSyncStat( SYNC_TEMPSTATE_NEW_ID );
+ changedAddressees.append( addressee );
+ addedUID.append( uid2 );
+ }
+
} else if ( (*it).tempSyncStat() == SYNC_TEMPSTATE_DELETE ) {
+ qDebug("Remove contact ");
if ( ok )
mAccess->removeContact(c);
else
- qDebug("Error revoe contact from qtopia ");
+ qDebug("Error remove contact from qtopia ");
} else if ( (*it).tempSyncStat() != SYNC_TEMPSTATE_NEW_EXTERNAL ) {
if ( ok ) {
+ qDebug("Update contact ");
mAccess->updateContact(c);
+ PimContact g = mAccess->contactForId( c.uid(), &ok );
KABC::Addressee addressee;
- mConverter->qtopiaToAddressee( c, addressee );
+ mConverter->qtopiaToAddressee( g, addressee );
+ addressee.setUid((*it).uid() );
addressee.setTempSyncStat( SYNC_TEMPSTATE_NEW_CSUM );
- addressBook()->insertAddressee( addressee );
+ changedAddressees.append( addressee );
}
else
@@ -238,5 +293,9 @@ bool ResourceQtopia::save( Ticket *ticket )
}
- // mAccess->addressBookUpdated();
+ KABC::Addressee::List::Iterator it2;
+ for ( it2 = changedAddressees.begin(); it2 != changedAddressees.end(); ++it2 )
+ addressBook()->insertAddressee((*it2));
+
+
mDirWatch.startScan();
diff --git a/kaddressbook/kabcore.cpp b/kaddressbook/kabcore.cpp
index 8f3ca9b..f8683e7 100644
--- a/kaddressbook/kabcore.cpp
+++ b/kaddressbook/kabcore.cpp
@@ -2550,26 +2550,28 @@ int KABCore::takeAddressee( KABC::Addressee* local, KABC::Addressee* remote, i
// 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 ) );
}
@@ -2579,5 +2581,5 @@ int KABCore::takeAddressee( KABC::Addressee* local, KABC::Addressee* remote, i
mode = SYNC_PREF_ASK;
} else {
- if ( local->revision() == remote->revision() )
+ if ( localMod == remoteMod )
return 0;
@@ -2585,5 +2587,5 @@ int KABCore::takeAddressee( KABC::Addressee* local, KABC::Addressee* remote, i
// 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
@@ -2610,19 +2612,19 @@ int KABCore::takeAddressee( KABC::Addressee* local, KABC::Addressee* remote, i
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
@@ -2630,10 +2632,10 @@ int KABCore::takeAddressee( KABC::Addressee* local, KABC::Addressee* remote, i
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! ************************************** ");
{
@@ -2787,4 +2789,8 @@ bool KABCore::synchronizeAddressbooks( KABC::AddressBook* local, KABC::AddressBo
++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 );
@@ -2926,7 +2932,8 @@ bool KABCore::syncAB(QString filename, int mode)
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 {
@@ -2937,8 +2944,7 @@ bool KABCore::syncAB(QString filename, int mode)
} 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;
@@ -2967,9 +2973,9 @@ bool KABCore::syncAB(QString filename, int mode)
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 );
diff --git a/korganizer/calendarview.cpp b/korganizer/calendarview.cpp
index 0c75632..8e83723 100644
--- a/korganizer/calendarview.cpp
+++ b/korganizer/calendarview.cpp
@@ -727,4 +727,6 @@ int CalendarView::takeEvent( Incidence* local, Incidence* remote, int mode , b
// 3 cancel
QDateTime lastSync = mLastCalendarSync;
+ QDateTime localMod = local->lastModified();
+ QDateTime remoteMod = remote->lastModified();
if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL ) {
bool remCh, locCh;
@@ -732,21 +734,21 @@ int CalendarView::takeEvent( Incidence* local, Incidence* remote, int mode , b
//if ( remCh )
//qDebug("loc %s rem %s", local->getCsum(mCurrentSyncDevice).latin1(), remote->getCsum(mCurrentSyncDevice).latin1() );
- locCh = ( local->lastModified() > mLastCalendarSync );
+ locCh = ( localMod > mLastCalendarSync );
if ( !remCh && ! locCh ) {
//qDebug("both not changed ");
- lastSync = local->lastModified().addDays(1);
+ lastSync = localMod.addDays(1);
if ( mode <= SYNC_PREF_ASK )
return 0;
} else {
if ( locCh ) {
- //qDebug("loc changed %d %s %s", local->revision() , local->lastModified().toString().latin1(), mLastCalendarSync.toString().latin1());
- lastSync = local->lastModified().addDays( -1 );
+ //qDebug("loc changed %d %s %s", local->revision() , localMod.toString().latin1(), mLastCalendarSync.toString().latin1());
+ lastSync = localMod.addDays( -1 );
if ( !remCh )
- remote->setLastModified( lastSync.addDays( -1 ) );
+ remoteMod = ( lastSync.addDays( -1 ) );
} else {
//qDebug(" not loc changed ");
- lastSync = local->lastModified().addDays( 1 );
+ lastSync = localMod.addDays( 1 );
if ( remCh )
- remote->setLastModified( lastSync.addDays( 1 ) );
+ remoteMod =( lastSync.addDays( 1 ) );
}
@@ -756,5 +758,5 @@ int CalendarView::takeEvent( Incidence* local, Incidence* remote, int mode , b
mode = SYNC_PREF_ASK;
} else {
- if ( local->lastModified() == remote->lastModified() )
+ if ( localMod == remoteMod )
if ( local->revision() == remote->revision() )
return 0;
@@ -763,6 +765,6 @@ int CalendarView::takeEvent( Incidence* local, Incidence* remote, int mode , b
// 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() );
+ //qDebug("%s %d %s %d", localMod.toString().latin1() , local->revision(), remoteMod.toString().latin1(), remote->revision());
+ //qDebug("%d %d %d %d ", localMod.time().second(), localMod.time().msec(), remoteMod.time().second(), remoteMod.time().msec() );
//full = true; //debug only
if ( full ) {
@@ -788,5 +790,5 @@ int CalendarView::takeEvent( Incidence* local, Incidence* remote, int mode , b
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() );
+ //qDebug("%s -- %s mLastCalendarSync %s lastsync %s --- local %s remote %s ",local->summary().latin1(), remote->summary().latin1(),mLastCalendarSync.toString().latin1() ,lastSync.toString().latin1() , localMod.toString().latin1() , remoteMod.toString().latin1() );
if ( full && mode < SYNC_PREF_NEWEST )
@@ -795,19 +797,19 @@ int CalendarView::takeEvent( Incidence* local, Incidence* remote, int mode , b
switch( mode ) {
case SYNC_PREF_LOCAL:
- if ( lastSync > remote->lastModified() )
+ if ( lastSync > remoteMod )
return 1;
- if ( lastSync > local->lastModified() )
+ if ( lastSync > localMod )
return 2;
return 1;
break;
case SYNC_PREF_REMOTE:
- if ( lastSync > remote->lastModified() )
+ if ( lastSync > remoteMod )
return 1;
- if ( lastSync > local->lastModified() )
+ if ( lastSync > localMod )
return 2;
return 2;
break;
case SYNC_PREF_NEWEST:
- if ( local->lastModified() > remote->lastModified() )
+ if ( localMod > remoteMod )
return 1;
else
@@ -815,11 +817,11 @@ int CalendarView::takeEvent( Incidence* local, Incidence* remote, int mode , b
break;
case SYNC_PREF_ASK:
- //qDebug("lsy %s --- lo %s --- re %s ", lastSync.toString().latin1(), local->lastModified().toString().latin1(), remote->lastModified().toString().latin1() );
- if ( lastSync > remote->lastModified() )
+ //qDebug("lsy %s --- lo %s --- re %s ", lastSync.toString().latin1(), localMod.toString().latin1(), remoteMod.toString().latin1() );
+ if ( lastSync > remoteMod )
return 1;
- if ( lastSync > local->lastModified() )
+ if ( lastSync > localMod )
return 2;
- //qDebug("lsy %s --- lo %s --- re %s ", lastSync.toString().latin1(), local->lastModified().toString().latin1(), remote->lastModified().toString().latin1() );
- localIsNew = local->lastModified() >= remote->lastModified();
+ //qDebug("lsy %s --- lo %s --- re %s ", lastSync.toString().latin1(), localMod.toString().latin1(), remoteMod.toString().latin1() );
+ localIsNew = localMod >= remoteMod;
if ( localIsNew )
getEventViewerDialog()->setColorMode( 1 );