summaryrefslogtreecommitdiffabout
path: root/kabc/addressbook.cpp
Unidiff
Diffstat (limited to 'kabc/addressbook.cpp') (more/less context) (show whitespace changes)
-rw-r--r--kabc/addressbook.cpp75
1 files changed, 68 insertions, 7 deletions
diff --git a/kabc/addressbook.cpp b/kabc/addressbook.cpp
index 16e1653..ec9f893 100644
--- a/kabc/addressbook.cpp
+++ b/kabc/addressbook.cpp
@@ -231,12 +231,13 @@ AddressBook::AddressBook( const QString &config, const QString &family )
231 231
232} 232}
233 233
234// the default family is "contact" 234// the default family is "contact"
235void AddressBook::init(const QString &config, const QString &family ) 235void AddressBook::init(const QString &config, const QString &family )
236{ 236{
237 blockLSEchange = false;
237 d = new AddressBookData; 238 d = new AddressBookData;
238 QString fami = family; 239 QString fami = family;
239 qDebug("new ab "); 240 qDebug("new ab ");
240 if (config != 0) { 241 if (config != 0) {
241 qDebug("config != 0 "); 242 qDebug("config != 0 ");
242 if ( family == "syncContact" ) { 243 if ( family == "syncContact" ) {
@@ -342,12 +343,13 @@ bool AddressBook::load()
342 343
343 // mark all addressees as unchanged 344 // mark all addressees as unchanged
344 Addressee::List::Iterator addrIt; 345 Addressee::List::Iterator addrIt;
345 for ( addrIt = d->mAddressees.begin(); addrIt != d->mAddressees.end(); ++addrIt ) 346 for ( addrIt = d->mAddressees.begin(); addrIt != d->mAddressees.end(); ++addrIt )
346 (*addrIt).setChanged( false ); 347 (*addrIt).setChanged( false );
347 348
349 blockLSEchange = true;
348 return ok; 350 return ok;
349} 351}
350 352
351bool AddressBook::save( Ticket *ticket ) 353bool AddressBook::save( Ticket *ticket )
352{ 354{
353 kdDebug(5700) << "AddressBook::save()"<< endl; 355 kdDebug(5700) << "AddressBook::save()"<< endl;
@@ -444,18 +446,20 @@ Ticket *AddressBook::requestSaveTicket( Resource *resource )
444 446
445 return 0; 447 return 0;
446} 448}
447 449
448void AddressBook::insertAddressee( const Addressee &a, bool setRev ) 450void AddressBook::insertAddressee( const Addressee &a, bool setRev )
449{ 451{
452 if ( blockLSEchange && setRev && a.uid().left( 19 ) == QString("last-syncAddressee-") ) {
453 return;
454 }
455 bool found = false;
450 Addressee::List::Iterator it; 456 Addressee::List::Iterator it;
451 for ( it = d->mAddressees.begin(); it != d->mAddressees.end(); ++it ) { 457 for ( it = d->mAddressees.begin(); it != d->mAddressees.end(); ++it ) {
452 if ( a.uid() == (*it).uid() ) { 458 if ( a.uid() == (*it).uid() ) {
453 if ( setRev && (*it).uid().left( 19 ) == QString("last-syncAddressee-") ) { 459
454 return;
455 }
456 bool changed = false; 460 bool changed = false;
457 Addressee addr = a; 461 Addressee addr = a;
458 if ( addr != (*it) ) 462 if ( addr != (*it) )
459 changed = true; 463 changed = true;
460 464
461 (*it) = a; 465 (*it) = a;
@@ -471,32 +475,87 @@ void AddressBook::insertAddressee( const Addressee &a, bool setRev )
471 dt.setTime( QTime (t.hour (), t.minute (), t.second () ) ); 475 dt.setTime( QTime (t.hour (), t.minute (), t.second () ) );
472 (*it).setRevision( dt ); 476 (*it).setRevision( dt );
473 } 477 }
474 (*it).setChanged( true ); 478 (*it).setChanged( true );
475 } 479 }
476 480
477 return; 481 found = true;
482 } else {
483 if ( (*it).uid() == QString("last-syncAddressee-") ) {
484 QString name = (*it).uid().mid( 19 );
485 Addressee b = a;
486 QString id = b.getID( name );
487 if ( ! id.isEmpty() ) {
488 QString des = (*it).note();
489 int startN;
490 if( (startN = des.find( id ) ) >= 0 ) {
491 int endN = des.find( ",", startN+1 );
492 des = des.left( startN ) + des.mid( endN+1 );
493 (*it).setNote( des );
494 }
478 } 495 }
479 } 496 }
497 }
498 }
499 if ( found )
500 return;
480 d->mAddressees.append( a ); 501 d->mAddressees.append( a );
481 Addressee& addr = d->mAddressees.last(); 502 Addressee& addr = d->mAddressees.last();
482 if ( addr.resource() == 0 ) 503 if ( addr.resource() == 0 )
483 addr.setResource( standardResource() ); 504 addr.setResource( standardResource() );
484 505
485 addr.setChanged( true ); 506 addr.setChanged( true );
486} 507}
487 508
488void AddressBook::removeAddressee( const Addressee &a ) 509void AddressBook::removeAddressee( const Addressee &a )
489{ 510{
490 Iterator it; 511 Iterator it;
512 Iterator it2;
513 bool found = false;
491 for ( it = begin(); it != end(); ++it ) { 514 for ( it = begin(); it != end(); ++it ) {
492 if ( a.uid() == (*it).uid() ) { 515 if ( a.uid() == (*it).uid() ) {
493 removeAddressee( it ); 516 found = true;
494 return; 517 it2 = it;
518 } else {
519 if ( (*it).uid() == QString("last-syncAddressee-") ) {
520 QString name = (*it).uid().mid( 19 );
521 Addressee b = a;
522 QString id = b.getID( name );
523 if ( ! id.isEmpty() ) {
524 QString des = (*it).note();
525 if( des.find( id ) < 0 ) {
526 des += id + ",";
527 (*it).setNote( des );
528 }
495 } 529 }
496 } 530 }
531
532 }
533 }
534
535 if ( found )
536 removeAddressee( it2 );
537
538}
539
540void AddressBook::removeDeletedAddressees()
541{
542 deleteRemovedAddressees();
543 Iterator it = begin();
544 Iterator it2 ;
545 QDateTime dt ( QDate( 2004,1,1) );
546 while ( it != end() ) {
547 (*it).setRevision( dt );
548 if ( (*it).tempSyncStat() == SYNC_TEMPSTATE_DELETE ) {
549 it2 = it;
550 ++it;
551 removeAddressee( it2 );
552 } else
553 ++it;
554 }
555 deleteRemovedAddressees();
497} 556}
498 557
499void AddressBook::removeAddressee( const Iterator &it ) 558void AddressBook::removeAddressee( const Iterator &it )
500{ 559{
501 d->mRemovedAddressees.append( (*it) ); 560 d->mRemovedAddressees.append( (*it) );
502 d->mAddressees.remove( it.d->mIt ); 561 d->mAddressees.remove( it.d->mIt );
@@ -520,26 +579,28 @@ Addressee AddressBook::findByUid( const QString &uid )
520 if ( uid == (*it).uid() ) { 579 if ( uid == (*it).uid() ) {
521 return *it; 580 return *it;
522 } 581 }
523 } 582 }
524 return Addressee(); 583 return Addressee();
525} 584}
585#if 0
526Addressee::List AddressBook::getExternLastSyncAddressees() 586Addressee::List AddressBook::getExternLastSyncAddressees()
527{ 587{
528 Addressee::List results; 588 Addressee::List results;
529 589
530 Iterator it; 590 Iterator it;
531 for ( it = begin(); it != end(); ++it ) { 591 for ( it = begin(); it != end(); ++it ) {
532 if ( (*it).uid().left( 19 ) == "last-syncAddressee-" ) { 592 if ( (*it).uid().left( 19 ) == "last-syncAddressee-" ) {
533 if ( (*it).familyName().left(3) == "E: " ) 593 if ( (*it).familyName().left(4) == "!E: " )
534 results.append( *it ); 594 results.append( *it );
535 } 595 }
536 } 596 }
537 597
538 return results; 598 return results;
539} 599}
600#endif
540void AddressBook::resetTempSyncStat() 601void AddressBook::resetTempSyncStat()
541{ 602{
542 Iterator it; 603 Iterator it;
543 for ( it = begin(); it != end(); ++it ) { 604 for ( it = begin(); it != end(); ++it ) {
544 (*it).setTempSyncStat ( SYNC_TEMPSTATE_INITIAL ); 605 (*it).setTempSyncStat ( SYNC_TEMPSTATE_INITIAL );
545 } 606 }