author | zautrix <zautrix> | 2004-09-20 00:12:42 (UTC) |
---|---|---|
committer | zautrix <zautrix> | 2004-09-20 00:12:42 (UTC) |
commit | b01b669d88fa195261d29ecf73b1c69e608a5ebc (patch) (unidiff) | |
tree | c0e79d45242a764b49470d07a9c95be156c121cc /kabc/addressbook.cpp | |
parent | 3da2cfeab2edbe64a17251662e56668fe143f7a3 (diff) | |
download | kdepimpi-b01b669d88fa195261d29ecf73b1c69e608a5ebc.zip kdepimpi-b01b669d88fa195261d29ecf73b1c69e608a5ebc.tar.gz kdepimpi-b01b669d88fa195261d29ecf73b1c69e608a5ebc.tar.bz2 |
more AB sync
-rw-r--r-- | kabc/addressbook.cpp | 27 |
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 | |||
@@ -531,64 +531,63 @@ void AddressBook::removeAddressee( const Addressee &a ) | |||
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 | ||
555 | void AddressBook::removeDeletedAddressees() | 555 | void 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 | ||
578 | void AddressBook::removeAddressee( const Iterator &it ) | 577 | void 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 | ||
584 | AddressBook::Iterator AddressBook::find( const Addressee &a ) | 583 | AddressBook::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 | ||
@@ -596,84 +595,100 @@ Addressee 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 | } |
605 | void AddressBook::preExternSync( AddressBook* aBook, const QString& csd ) | 604 | void 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 | } |
615 | void AddressBook::postExternSync( AddressBook* aBook , const QString& csd) | 614 | void 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 | 636 | bool 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 | } | ||
637 | Addressee AddressBook::findByExternUid( const QString& uid , const QString& profile ) | 645 | Addressee 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 | } |
646 | void AddressBook::mergeAB( AddressBook *aBook, const QString& profile ) | 654 | void 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 |
659 | Addressee::List AddressBook::getExternLastSyncAddressees() | 674 | Addressee::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 |
674 | void AddressBook::resetTempSyncStat() | 689 | void 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 | } |