summaryrefslogtreecommitdiffabout
path: root/kabc
Unidiff
Diffstat (limited to 'kabc') (more/less context) (show whitespace changes)
-rw-r--r--kabc/addressbook.cpp25
-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.cpp75
5 files changed, 95 insertions, 16 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 )
552 552
553} 553}
554 554
555void AddressBook::removeDeletedAddressees() 555void AddressBook::removeSyncAddressees( bool removeDeleted )
556{ 556{
557 deleteRemovedAddressees();
558 Iterator it = begin(); 557 Iterator it = begin();
559 Iterator it2 ; 558 Iterator it2 ;
560 QDateTime dt ( QDate( 2004,1,1) ); 559 QDateTime dt ( QDate( 2004,1,1) );
@@ -562,7 +561,7 @@ void AddressBook::removeDeletedAddressees()
562 (*it).setRevision( dt ); 561 (*it).setRevision( dt );
563 (*it).removeCustom( "KADDRESSBOOK", "X-ExternalID" ); 562 (*it).removeCustom( "KADDRESSBOOK", "X-ExternalID" );
564 (*it).setIDStr(""); 563 (*it).setIDStr("");
565 if ( (*it).tempSyncStat() == SYNC_TEMPSTATE_DELETE || (*it).uid().left( 19 ) == QString("last-syncAddressee-")) { 564 if ( ( (*it).tempSyncStat() == SYNC_TEMPSTATE_DELETE && removeDeleted )|| (*it).uid().left( 19 ) == QString("last-syncAddressee-")) {
566 it2 = it; 565 it2 = it;
567 //qDebug("removing %s ",(*it).uid().latin1() ); 566 //qDebug("removing %s ",(*it).uid().latin1() );
568 ++it; 567 ++it;
@@ -617,11 +616,12 @@ void AddressBook::postExternSync( AddressBook* aBook , const QString& csd)
617 qDebug("AddressBook::postExternSync "); 616 qDebug("AddressBook::postExternSync ");
618 AddressBook::Iterator it; 617 AddressBook::Iterator it;
619 for ( it = begin(); it != end(); ++it ) { 618 for ( it = begin(); it != end(); ++it ) {
619 qDebug("check uid %s ", (*it).uid().latin1() );
620 if ( (*it).tempSyncStat() == SYNC_TEMPSTATE_NEW_ID || 620 if ( (*it).tempSyncStat() == SYNC_TEMPSTATE_NEW_ID ||
621 (*it).tempSyncStat() == SYNC_TEMPSTATE_NEW_CSUM ) { 621 (*it).tempSyncStat() == SYNC_TEMPSTATE_NEW_CSUM ) {
622 Addressee ad = aBook->findByUid( ( (*it).uid() )); 622 Addressee ad = aBook->findByUid( ( (*it).uid() ));
623 if ( ad.isEmpty() ) { 623 if ( ad.isEmpty() ) {
624 qDebug("ERROR ad empty "); 624 qDebug("postExternSync:ERROR addressee is empty: %s ", (*it).uid().latin1());
625 } else { 625 } else {
626 (*it).computeCsum( csd ); 626 (*it).computeCsum( csd );
627 if ( (*it).tempSyncStat() == SYNC_TEMPSTATE_NEW_ID ) 627 if ( (*it).tempSyncStat() == SYNC_TEMPSTATE_NEW_ID )
@@ -633,7 +633,15 @@ void AddressBook::postExternSync( AddressBook* aBook , const QString& csd)
633 } 633 }
634} 634}
635 635
636 636bool AddressBook::containsExternalUid( const QString& uid )
637{
638 Iterator it;
639 for ( it = begin(); it != end(); ++it ) {
640 if ( uid == (*it).externalUID( ) )
641 return true;
642 }
643 return false;
644}
637Addressee AddressBook::findByExternUid( const QString& uid , const QString& profile ) 645Addressee AddressBook::findByExternUid( const QString& uid , const QString& profile )
638{ 646{
639 Iterator it; 647 Iterator it;
@@ -653,6 +661,13 @@ void AddressBook::mergeAB( AddressBook *aBook, const QString& profile )
653 (*it).mergeContact( ad ); 661 (*it).mergeContact( ad );
654 } 662 }
655 } 663 }
664#if 0
665 // test only
666 for ( it = begin(); it != end(); ++it ) {
667
668 qDebug("uid %s ", (*it).uid().latin1());
669 }
670#endif
656} 671}
657 672
658#if 0 673#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
292 //Addressee::List getExternLastSyncAddressees(); 292 //Addressee::List getExternLastSyncAddressees();
293 void resetTempSyncStat(); 293 void resetTempSyncStat();
294 QStringList uidList(); 294 QStringList uidList();
295 void removeDeletedAddressees(); 295 void removeSyncAddressees( bool removeDeleted = false );
296 void mergeAB( AddressBook *aBook, const QString& profile ); 296 void mergeAB( AddressBook *aBook, const QString& profile );
297 Addressee findByExternUid( const QString& uid , const QString& profile ); 297 Addressee findByExternUid( const QString& uid , const QString& profile );
298 bool containsExternalUid( const QString& uid );
298 299
299 void preExternSync( AddressBook* aBook, const QString& csd ); 300 void preExternSync( AddressBook* aBook, const QString& csd );
300 void postExternSync( AddressBook* aBook, const QString& csd ); 301 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()
95 mData->changed = false; 95 mData->changed = false;
96 mData->resource = 0; 96 mData->resource = 0;
97 mData->mExternalId = ":"; 97 mData->mExternalId = ":";
98 mData->revision = QDateTime ( QDate( 2004,1,1)); 98 mData->revision = QDateTime ( QDate( 2003,1,1));
99 mData->mTempSyncStat = SYNC_TEMPSTATE_INITIAL; 99 mData->mTempSyncStat = SYNC_TEMPSTATE_INITIAL;
100} 100}
101 101
@@ -308,6 +308,8 @@ void Addressee::mergeContact( const Addressee& ad )
308 // merging categories; 308 // merging categories;
309 // merging custom; 309 // merging custom;
310 // merging keys 310 // merging keys
311 qDebug("merge contact %s ", ad.uid().latin1());
312 setUid( ad.uid() );
311} 313}
312 314
313void Addressee::removeID(const QString &prof) 315void Addressee::removeID(const QString &prof)
@@ -379,6 +381,7 @@ void Addressee::setOriginalExternalUID( const QString &id )
379 if ( id == mData->originalExternalUID ) return; 381 if ( id == mData->originalExternalUID ) return;
380 detach(); 382 detach();
381 mData->empty = false; 383 mData->empty = false;
384 qDebug("*******Set orig uid %s ", id.latin1());
382 mData->originalExternalUID = id; 385 mData->originalExternalUID = id;
383} 386}
384 387
@@ -391,6 +394,7 @@ void Addressee::setUid( const QString &id )
391{ 394{
392 if ( id == mData->uid ) return; 395 if ( id == mData->uid ) return;
393 detach(); 396 detach();
397 qDebug("****setuid %s ", id.latin1());
394 mData->empty = false; 398 mData->empty = false;
395 mData->uid = id; 399 mData->uid = id;
396} 400}
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
86 if ( ente > -1 ) 86 if ( ente > -1 )
87 exuid = exuid.left( ente-1 ); 87 exuid = exuid.left( ente-1 );
88 addr.setExternalUID( exuid ); 88 addr.setExternalUID( exuid );
89 //qDebug("QtopiaConverter:set uid %s ",addr.externalUID().latin1() ); 89 qDebug("QtopiaConverter:set %s uid %s ",addr.originalExternalUID().latin1(),addr.externalUID().latin1() );
90 90
91 // email 91 // email
92 QStringList emails = contact.emailList(); 92 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 )
197 197
198 KABC::AddressBook::Iterator it; 198 KABC::AddressBook::Iterator it;
199 bool res; 199 bool res;
200 200 KABC::Addressee::List changedAddressees;
201 QStringList addedUID;
201 for ( it = addressBook()->begin(); it != addressBook()->end(); ++it ) { 202 for ( it = addressBook()->begin(); it != addressBook()->end(); ++it ) {
202 //KABC::Addressee addressee = (*it); 203 //KABC::Addressee addressee = (*it);
204 // qDebug("AAAfor uid %s ", (*it).originalExternalUID().latin1() );
203 if ( (*it).tempSyncStat() != SYNC_TEMPSTATE_NEW_EXTERNAL ) { 205 if ( (*it).tempSyncStat() != SYNC_TEMPSTATE_NEW_EXTERNAL ) {
204 QUuid uid( (*it).originalExternalUID() ); 206 QUuid uid( (*it).originalExternalUID() );
205 bool ok; 207 bool ok;
206 PimContact c = mAccess->contactForId( uid, &ok ); 208 PimContact c = mAccess->contactForId( uid, &ok );
209 qDebug("ResourceQtopia::save:Found %d for uid %s ", ok,(*it).originalExternalUID().latin1() );
207 res = mConverter->addresseeToQtopia( *it, c ); 210 res = mConverter->addresseeToQtopia( *it, c );
208 if (res == true) { 211 if (res == true) {
209 if ( (*it).tempSyncStat() == SYNC_TEMPSTATE_ADDED_EXTERNAL ) { 212 if ( (*it).tempSyncStat() == SYNC_TEMPSTATE_ADDED_EXTERNAL ) {
210 mAccess->addContact(c); 213 qDebug("skipping adding of contact ");
214 continue;
215 PimContact e;
216 AddressBookAccess Access2;
217 Access2.addContact(e);
218 const PimContact* contact;
219 bool res;
220 QString uid2, Ouid;
221 AddressBookIterator itt(Access2);
222 for (contact=itt.toFirst(); itt.current(); ++itt)
223 {
224 contact = itt.current();
225 QString exuid = contact->uid().toString();
226 Ouid =exuid;
227 int ente = exuid.find( "-0000");
228 if ( exuid.left(1) == "{" )
229 exuid = exuid.mid(1);
230 if ( ente > -1 )
231 exuid = exuid.left( ente-1 );
232 uid2 = exuid;
233 qDebug("trying find uid ");
234 if ( !addressBook()->containsExternalUid( uid2 ) ) {
235 qDebug("ab not contains ");
236 if ( !addedUID.contains( uid2 )) {
237 qDebug("list not contains ");
238 break;
239 }
240 }
241
242 }
243 if ( !itt.current()) {
244 qDebug("ERROR uid ");
245 continue;
246 }
247 else
248 qDebug("ADD uid detected ");
249
250
251 QUuid uid3( Ouid);
252 PimContact d = Access2.contactForId( uid3, &ok );
253 if ( ! ok ) {
254 qDebug("ADD: Error getting new uid ");
255 } else {
256 qDebug("NEW UID found ");
257 PimContact g = mAccess->contactForId( c.uid(), &ok );
211 KABC::Addressee addressee; 258 KABC::Addressee addressee;
212 mConverter->qtopiaToAddressee( c, addressee ); 259 mConverter->qtopiaToAddressee( g, addressee );
260 addressee.setUid((*it).uid() );
213 addressee.setTempSyncStat( SYNC_TEMPSTATE_NEW_ID ); 261 addressee.setTempSyncStat( SYNC_TEMPSTATE_NEW_ID );
214 addressBook()->insertAddressee( addressee ); 262 changedAddressees.append( addressee );
263 addedUID.append( uid2 );
264 }
265
215 266
216 } else if ( (*it).tempSyncStat() == SYNC_TEMPSTATE_DELETE ) { 267 } else if ( (*it).tempSyncStat() == SYNC_TEMPSTATE_DELETE ) {
268 qDebug("Remove contact ");
217 if ( ok ) 269 if ( ok )
218 mAccess->removeContact(c); 270 mAccess->removeContact(c);
219 else 271 else
220 qDebug("Error revoe contact from qtopia "); 272 qDebug("Error remove contact from qtopia ");
221 } else if ( (*it).tempSyncStat() != SYNC_TEMPSTATE_NEW_EXTERNAL ) { 273 } else if ( (*it).tempSyncStat() != SYNC_TEMPSTATE_NEW_EXTERNAL ) {
222 if ( ok ) { 274 if ( ok ) {
275 qDebug("Update contact ");
223 mAccess->updateContact(c); 276 mAccess->updateContact(c);
277 PimContact g = mAccess->contactForId( c.uid(), &ok );
224 KABC::Addressee addressee; 278 KABC::Addressee addressee;
225 mConverter->qtopiaToAddressee( c, addressee ); 279 mConverter->qtopiaToAddressee( g, addressee );
280 addressee.setUid((*it).uid() );
226 addressee.setTempSyncStat( SYNC_TEMPSTATE_NEW_CSUM ); 281 addressee.setTempSyncStat( SYNC_TEMPSTATE_NEW_CSUM );
227 addressBook()->insertAddressee( addressee ); 282 changedAddressees.append( addressee );
228 } 283 }
229 else 284 else
230 qDebug("Error update contact from qtopia "); 285 qDebug("Error update contact from qtopia ");
@@ -237,7 +292,11 @@ bool ResourceQtopia::save( Ticket *ticket )
237 } 292 }
238 } 293 }
239 294
240 // mAccess->addressBookUpdated(); 295 KABC::Addressee::List::Iterator it2;
296 for ( it2 = changedAddressees.begin(); it2 != changedAddressees.end(); ++it2 )
297 addressBook()->insertAddressee((*it2));
298
299
241 300
242 mDirWatch.startScan(); 301 mDirWatch.startScan();
243 302