summaryrefslogtreecommitdiffabout
path: root/kabc/addressbook.cpp
Unidiff
Diffstat (limited to 'kabc/addressbook.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r--kabc/addressbook.cpp27
1 files changed, 21 insertions, 6 deletions
diff --git a/kabc/addressbook.cpp b/kabc/addressbook.cpp
index 86dc7c2..17b9ba2 100644
--- a/kabc/addressbook.cpp
+++ b/kabc/addressbook.cpp
@@ -507,197 +507,212 @@ void AddressBook::insertAddressee( const Addressee &a, bool setRev )
507 des = des.left( startN ) + des.mid( endN+1 ); 507 des = des.left( startN ) + des.mid( endN+1 );
508 (*it).setNote( des ); 508 (*it).setNote( des );
509 } 509 }
510 } 510 }
511 } 511 }
512 } 512 }
513 } 513 }
514 if ( found ) 514 if ( found )
515 return; 515 return;
516 d->mAddressees.append( a ); 516 d->mAddressees.append( a );
517 Addressee& addr = d->mAddressees.last(); 517 Addressee& addr = d->mAddressees.last();
518 if ( addr.resource() == 0 ) 518 if ( addr.resource() == 0 )
519 addr.setResource( standardResource() ); 519 addr.setResource( standardResource() );
520 520
521 addr.setChanged( true ); 521 addr.setChanged( true );
522} 522}
523 523
524void AddressBook::removeAddressee( const Addressee &a ) 524void AddressBook::removeAddressee( const Addressee &a )
525{ 525{
526 Iterator it; 526 Iterator it;
527 Iterator it2; 527 Iterator it2;
528 bool found = false; 528 bool found = false;
529 for ( it = begin(); it != end(); ++it ) { 529 for ( it = begin(); it != end(); ++it ) {
530 if ( a.uid() == (*it).uid() ) { 530 if ( a.uid() == (*it).uid() ) {
531 found = true; 531 found = true;
532 it2 = it; 532 it2 = it;
533 } else { 533 } else {
534 if ( (*it).uid().left( 19 ) == QString("last-syncAddressee-") ) { 534 if ( (*it).uid().left( 19 ) == QString("last-syncAddressee-") ) {
535 QString name = (*it).uid().mid( 19 ); 535 QString name = (*it).uid().mid( 19 );
536 Addressee b = a; 536 Addressee b = a;
537 QString id = b.getID( name ); 537 QString id = b.getID( name );
538 if ( ! id.isEmpty() ) { 538 if ( ! id.isEmpty() ) {
539 QString des = (*it).note(); 539 QString des = (*it).note();
540 if( des.find( id ) < 0 ) { 540 if( des.find( id ) < 0 ) {
541 des += id + ","; 541 des += id + ",";
542 (*it).setNote( des ); 542 (*it).setNote( des );
543 } 543 }
544 } 544 }
545 } 545 }
546 546
547 } 547 }
548 } 548 }
549 549
550 if ( found ) 550 if ( found )
551 removeAddressee( it2 ); 551 removeAddressee( it2 );
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) );
561 while ( it != end() ) { 560 while ( it != end() ) {
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;
569 removeAddressee( it2 ); 568 removeAddressee( it2 );
570 } else { 569 } else {
571 //qDebug("skipping %s ",(*it).uid().latin1() ); 570 //qDebug("skipping %s ",(*it).uid().latin1() );
572 ++it; 571 ++it;
573 } 572 }
574 } 573 }
575 deleteRemovedAddressees(); 574 deleteRemovedAddressees();
576} 575}
577 576
578void AddressBook::removeAddressee( const Iterator &it ) 577void AddressBook::removeAddressee( const Iterator &it )
579{ 578{
580 d->mRemovedAddressees.append( (*it) ); 579 d->mRemovedAddressees.append( (*it) );
581 d->mAddressees.remove( it.d->mIt ); 580 d->mAddressees.remove( it.d->mIt );
582} 581}
583 582
584AddressBook::Iterator AddressBook::find( const Addressee &a ) 583AddressBook::Iterator AddressBook::find( const Addressee &a )
585{ 584{
586 Iterator it; 585 Iterator it;
587 for ( it = begin(); it != end(); ++it ) { 586 for ( it = begin(); it != end(); ++it ) {
588 if ( a.uid() == (*it).uid() ) { 587 if ( a.uid() == (*it).uid() ) {
589 return it; 588 return it;
590 } 589 }
591 } 590 }
592 return end(); 591 return end();
593} 592}
594 593
595Addressee AddressBook::findByUid( const QString &uid ) 594Addressee AddressBook::findByUid( const QString &uid )
596{ 595{
597 Iterator it; 596 Iterator it;
598 for ( it = begin(); it != end(); ++it ) { 597 for ( it = begin(); it != end(); ++it ) {
599 if ( uid == (*it).uid() ) { 598 if ( uid == (*it).uid() ) {
600 return *it; 599 return *it;
601 } 600 }
602 } 601 }
603 return Addressee(); 602 return Addressee();
604} 603}
605void AddressBook::preExternSync( AddressBook* aBook, const QString& csd ) 604void AddressBook::preExternSync( AddressBook* aBook, const QString& csd )
606{ 605{
607 qDebug("AddressBook::preExternSync "); 606 qDebug("AddressBook::preExternSync ");
608 AddressBook::Iterator it; 607 AddressBook::Iterator it;
609 for ( it = begin(); it != end(); ++it ) { 608 for ( it = begin(); it != end(); ++it ) {
610 (*it).setID( csd, (*it).externalUID() ); 609 (*it).setID( csd, (*it).externalUID() );
611 (*it).computeCsum( csd ); 610 (*it).computeCsum( csd );
612 } 611 }
613 mergeAB( aBook ,csd ); 612 mergeAB( aBook ,csd );
614} 613}
615void AddressBook::postExternSync( AddressBook* aBook , const QString& csd) 614void AddressBook::postExternSync( AddressBook* aBook , const QString& csd)
616{ 615{
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 )
628 ad.setID( csd, (*it).externalUID() ); 628 ad.setID( csd, (*it).externalUID() );
629 ad.setCsum( csd, (*it).getCsum( csd ) ); 629 ad.setCsum( csd, (*it).getCsum( csd ) );
630 aBook->insertAddressee( ad ); 630 aBook->insertAddressee( ad );
631 } 631 }
632 } 632 }
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;
640 for ( it = begin(); it != end(); ++it ) { 648 for ( it = begin(); it != end(); ++it ) {
641 if ( uid == (*it).getID( profile ) ) 649 if ( uid == (*it).getID( profile ) )
642 return (*it); 650 return (*it);
643 } 651 }
644 return Addressee(); 652 return Addressee();
645} 653}
646void AddressBook::mergeAB( AddressBook *aBook, const QString& profile ) 654void AddressBook::mergeAB( AddressBook *aBook, const QString& profile )
647{ 655{
648 Iterator it; 656 Iterator it;
649 Addressee ad; 657 Addressee ad;
650 for ( it = begin(); it != end(); ++it ) { 658 for ( it = begin(); it != end(); ++it ) {
651 ad = aBook->findByExternUid( (*it).externalUID(), profile ); 659 ad = aBook->findByExternUid( (*it).externalUID(), profile );
652 if ( !ad.isEmpty() ) { 660 if ( !ad.isEmpty() ) {
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
659Addressee::List AddressBook::getExternLastSyncAddressees() 674Addressee::List AddressBook::getExternLastSyncAddressees()
660{ 675{
661 Addressee::List results; 676 Addressee::List results;
662 677
663 Iterator it; 678 Iterator it;
664 for ( it = begin(); it != end(); ++it ) { 679 for ( it = begin(); it != end(); ++it ) {
665 if ( (*it).uid().left( 19 ) == "last-syncAddressee-" ) { 680 if ( (*it).uid().left( 19 ) == "last-syncAddressee-" ) {
666 if ( (*it).familyName().left(4) == "!E: " ) 681 if ( (*it).familyName().left(4) == "!E: " )
667 results.append( *it ); 682 results.append( *it );
668 } 683 }
669 } 684 }
670 685
671 return results; 686 return results;
672} 687}
673#endif 688#endif
674void AddressBook::resetTempSyncStat() 689void AddressBook::resetTempSyncStat()
675{ 690{
676 Iterator it; 691 Iterator it;
677 for ( it = begin(); it != end(); ++it ) { 692 for ( it = begin(); it != end(); ++it ) {
678 (*it).setTempSyncStat ( SYNC_TEMPSTATE_INITIAL ); 693 (*it).setTempSyncStat ( SYNC_TEMPSTATE_INITIAL );
679 } 694 }
680 695
681} 696}
682 697
683QStringList AddressBook:: uidList() 698QStringList AddressBook:: uidList()
684{ 699{
685 QStringList results; 700 QStringList results;
686 Iterator it; 701 Iterator it;
687 for ( it = begin(); it != end(); ++it ) { 702 for ( it = begin(); it != end(); ++it ) {
688 results.append( (*it).uid() ); 703 results.append( (*it).uid() );
689 } 704 }
690 return results; 705 return results;
691} 706}
692 707
693 708
694Addressee::List AddressBook::allAddressees() 709Addressee::List AddressBook::allAddressees()
695{ 710{
696 return d->mAddressees; 711 return d->mAddressees;
697 712
698} 713}
699 714
700Addressee::List AddressBook::findByName( const QString &name ) 715Addressee::List AddressBook::findByName( const QString &name )
701{ 716{
702 Addressee::List results; 717 Addressee::List results;
703 718