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
@@ -552,9 +552,8 @@ void AddressBook::removeAddressee( const Addressee &a )
}
-void AddressBook::removeDeletedAddressees()
+void AddressBook::removeSyncAddressees( bool removeDeleted )
{
- deleteRemovedAddressees();
Iterator it = begin();
Iterator it2 ;
QDateTime dt ( QDate( 2004,1,1) );
@@ -562,12 +561,12 @@ void AddressBook::removeDeletedAddressees()
(*it).setRevision( dt );
(*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;
}
@@ -617,11 +616,12 @@ void AddressBook::postExternSync( AddressBook* aBook , const QString& csd)
qDebug("AddressBook::postExternSync ");
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 );
if ( (*it).tempSyncStat() == SYNC_TEMPSTATE_NEW_ID )
@@ -633,7 +633,15 @@ 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 )
{
Iterator it;
@@ -653,6 +661,13 @@ void AddressBook::mergeAB( AddressBook *aBook, const QString& profile )
(*it).mergeContact( ad );
}
}
+#if 0
+ // test only
+ for ( it = begin(); it != end(); ++it ) {
+
+ qDebug("uid %s ", (*it).uid().latin1());
+ }
+#endif
}
#if 0
diff --git a/kabc/addressbook.h b/kabc/addressbook.h
index 157dc56..8f62f0d 100644
--- a/kabc/addressbook.h
+++ b/kabc/addressbook.h
@@ -292,9 +292,10 @@ class AddressBook : public QObject
//Addressee::List getExternLastSyncAddressees();
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 );
void postExternSync( 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
@@ -95,7 +95,7 @@ Addressee::Addressee()
mData->changed = false;
mData->resource = 0;
mData->mExternalId = ":";
- mData->revision = QDateTime ( QDate( 2004,1,1));
+ mData->revision = QDateTime ( QDate( 2003,1,1));
mData->mTempSyncStat = SYNC_TEMPSTATE_INITIAL;
}
@@ -308,6 +308,8 @@ void Addressee::mergeContact( const Addressee& ad )
// merging categories;
// merging custom;
// merging keys
+ qDebug("merge contact %s ", ad.uid().latin1());
+ setUid( ad.uid() );
}
void Addressee::removeID(const QString &prof)
@@ -379,6 +381,7 @@ void Addressee::setOriginalExternalUID( const QString &id )
if ( id == mData->originalExternalUID ) return;
detach();
mData->empty = false;
+ qDebug("*******Set orig uid %s ", id.latin1());
mData->originalExternalUID = id;
}
@@ -391,6 +394,7 @@ 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
@@ -86,7 +86,7 @@ bool QtopiaConverter::qtopiaToAddressee( const PimContact &contact, Addressee &a
if ( ente > -1 )
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
QStringList emails = contact.emailList();
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
@@ -197,34 +197,89 @@ 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
qDebug("Error update contact from qtopia ");
@@ -237,7 +292,11 @@ 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
@@ -2549,28 +2549,30 @@ int KABCore::takeAddressee( KABC::Addressee* local, KABC::Addressee* remote, i
// 2 take remote
// 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 ) );
}
}
@@ -2578,13 +2580,13 @@ int KABCore::takeAddressee( KABC::Addressee* local, KABC::Addressee* remote, i
if ( mode < SYNC_PREF_ASK )
mode = SYNC_PREF_ASK;
} else {
- if ( local->revision() == remote->revision() )
+ if ( localMod == remoteMod )
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("%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
if ( full ) {
@@ -2609,32 +2611,32 @@ 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
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() )
+ //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! ************************************** ");
{
KPIM::AddresseeChooser acd ( *local,*remote, localIsNew , this );
@@ -2786,6 +2788,10 @@ bool KABCore::synchronizeAddressbooks( KABC::AddressBook* local, KABC::AddressBo
remote->insertAddressee( inR , false);
++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 );
inL = inR;
@@ -2925,9 +2931,10 @@ bool KABCore::syncAB(QString filename, int mode)
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 );
} else {
Addressee lse = mAddressBook->findByUid( "last-syncAddressee-"+mCurrentSyncDevice );
@@ -2936,10 +2943,9 @@ bool KABCore::syncAB(QString filename, int mode)
external = true;
} 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;
}
@@ -2966,11 +2972,11 @@ bool KABCore::syncAB(QString filename, int mode)
if ( syncOK ) {
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
@@ -726,28 +726,30 @@ int CalendarView::takeEvent( Incidence* local, Incidence* remote, int mode , b
// 2 take remote
// 3 cancel
QDateTime lastSync = mLastCalendarSync;
+ QDateTime localMod = local->lastModified();
+ QDateTime remoteMod = remote->lastModified();
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->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 ) );
}
}
@@ -755,15 +757,15 @@ int CalendarView::takeEvent( Incidence* local, Incidence* remote, int mode , b
if ( mode < SYNC_PREF_ASK )
mode = SYNC_PREF_ASK;
} else {
- if ( local->lastModified() == remote->lastModified() )
+ if ( localMod == remoteMod )
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() );
+ //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 ) {
bool equ = false;
@@ -787,40 +789,40 @@ 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 )
mode = SYNC_PREF_ASK;
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
return 2;
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 );
else