-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 | |||
@@ -459,293 +459,308 @@ Ticket *AddressBook::requestSaveTicket( Resource *resource ) | |||
459 | 459 | ||
460 | return 0; | 460 | return 0; |
461 | } | 461 | } |
462 | 462 | ||
463 | void AddressBook::insertAddressee( const Addressee &a, bool setRev ) | 463 | void AddressBook::insertAddressee( const Addressee &a, bool setRev ) |
464 | { | 464 | { |
465 | if ( blockLSEchange && setRev && a.uid().left( 19 ) == QString("last-syncAddressee-") ) { | 465 | if ( blockLSEchange && setRev && a.uid().left( 19 ) == QString("last-syncAddressee-") ) { |
466 | //qDebug("block insert "); | 466 | //qDebug("block insert "); |
467 | return; | 467 | return; |
468 | } | 468 | } |
469 | //qDebug("inserting.... %s ",a.uid().latin1() ); | 469 | //qDebug("inserting.... %s ",a.uid().latin1() ); |
470 | bool found = false; | 470 | bool found = false; |
471 | Addressee::List::Iterator it; | 471 | Addressee::List::Iterator it; |
472 | for ( it = d->mAddressees.begin(); it != d->mAddressees.end(); ++it ) { | 472 | for ( it = d->mAddressees.begin(); it != d->mAddressees.end(); ++it ) { |
473 | if ( a.uid() == (*it).uid() ) { | 473 | if ( a.uid() == (*it).uid() ) { |
474 | 474 | ||
475 | bool changed = false; | 475 | bool changed = false; |
476 | Addressee addr = a; | 476 | Addressee addr = a; |
477 | if ( addr != (*it) ) | 477 | if ( addr != (*it) ) |
478 | changed = true; | 478 | changed = true; |
479 | 479 | ||
480 | (*it) = a; | 480 | (*it) = a; |
481 | if ( (*it).resource() == 0 ) | 481 | if ( (*it).resource() == 0 ) |
482 | (*it).setResource( standardResource() ); | 482 | (*it).setResource( standardResource() ); |
483 | 483 | ||
484 | if ( changed ) { | 484 | if ( changed ) { |
485 | if ( setRev ) { | 485 | if ( setRev ) { |
486 | 486 | ||
487 | // get rid of micro seconds | 487 | // get rid of micro seconds |
488 | QDateTime dt = QDateTime::currentDateTime(); | 488 | QDateTime dt = QDateTime::currentDateTime(); |
489 | QTime t = dt.time(); | 489 | QTime t = dt.time(); |
490 | dt.setTime( QTime (t.hour (), t.minute (), t.second () ) ); | 490 | dt.setTime( QTime (t.hour (), t.minute (), t.second () ) ); |
491 | (*it).setRevision( dt ); | 491 | (*it).setRevision( dt ); |
492 | } | 492 | } |
493 | (*it).setChanged( true ); | 493 | (*it).setChanged( true ); |
494 | } | 494 | } |
495 | 495 | ||
496 | found = true; | 496 | found = true; |
497 | } else { | 497 | } else { |
498 | if ( (*it).uid().left( 19 ) == QString("last-syncAddressee-") ) { | 498 | if ( (*it).uid().left( 19 ) == QString("last-syncAddressee-") ) { |
499 | QString name = (*it).uid().mid( 19 ); | 499 | QString name = (*it).uid().mid( 19 ); |
500 | Addressee b = a; | 500 | Addressee b = a; |
501 | QString id = b.getID( name ); | 501 | QString id = b.getID( name ); |
502 | if ( ! id.isEmpty() ) { | 502 | if ( ! id.isEmpty() ) { |
503 | QString des = (*it).note(); | 503 | QString des = (*it).note(); |
504 | int startN; | 504 | int startN; |
505 | if( (startN = des.find( id ) ) >= 0 ) { | 505 | if( (startN = des.find( id ) ) >= 0 ) { |
506 | int endN = des.find( ",", startN+1 ); | 506 | int endN = des.find( ",", startN+1 ); |
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 | ||
524 | void AddressBook::removeAddressee( const Addressee &a ) | 524 | void 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 | ||
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 | ||
595 | Addressee AddressBook::findByUid( const QString &uid ) | 594 | 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 | } |
680 | 695 | ||
681 | } | 696 | } |
682 | 697 | ||
683 | QStringList AddressBook:: uidList() | 698 | QStringList 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 | ||
694 | Addressee::List AddressBook::allAddressees() | 709 | Addressee::List AddressBook::allAddressees() |
695 | { | 710 | { |
696 | return d->mAddressees; | 711 | return d->mAddressees; |
697 | 712 | ||
698 | } | 713 | } |
699 | 714 | ||
700 | Addressee::List AddressBook::findByName( const QString &name ) | 715 | Addressee::List AddressBook::findByName( const QString &name ) |
701 | { | 716 | { |
702 | Addressee::List results; | 717 | Addressee::List results; |
703 | 718 | ||
704 | Iterator it; | 719 | Iterator it; |
705 | for ( it = begin(); it != end(); ++it ) { | 720 | for ( it = begin(); it != end(); ++it ) { |
706 | if ( name == (*it).realName() ) { | 721 | if ( name == (*it).realName() ) { |
707 | results.append( *it ); | 722 | results.append( *it ); |
708 | } | 723 | } |
709 | } | 724 | } |
710 | 725 | ||
711 | return results; | 726 | return results; |
712 | } | 727 | } |
713 | 728 | ||
714 | Addressee::List AddressBook::findByEmail( const QString &email ) | 729 | Addressee::List AddressBook::findByEmail( const QString &email ) |
715 | { | 730 | { |
716 | Addressee::List results; | 731 | Addressee::List results; |
717 | QStringList mailList; | 732 | QStringList mailList; |
718 | 733 | ||
719 | Iterator it; | 734 | Iterator it; |
720 | for ( it = begin(); it != end(); ++it ) { | 735 | for ( it = begin(); it != end(); ++it ) { |
721 | mailList = (*it).emails(); | 736 | mailList = (*it).emails(); |
722 | for ( QStringList::Iterator ite = mailList.begin(); ite != mailList.end(); ++ite ) { | 737 | for ( QStringList::Iterator ite = mailList.begin(); ite != mailList.end(); ++ite ) { |
723 | if ( email == (*ite) ) { | 738 | if ( email == (*ite) ) { |
724 | results.append( *it ); | 739 | results.append( *it ); |
725 | } | 740 | } |
726 | } | 741 | } |
727 | } | 742 | } |
728 | 743 | ||
729 | return results; | 744 | return results; |
730 | } | 745 | } |
731 | 746 | ||
732 | Addressee::List AddressBook::findByCategory( const QString &category ) | 747 | Addressee::List AddressBook::findByCategory( const QString &category ) |
733 | { | 748 | { |
734 | Addressee::List results; | 749 | Addressee::List results; |
735 | 750 | ||
736 | Iterator it; | 751 | Iterator it; |
737 | for ( it = begin(); it != end(); ++it ) { | 752 | for ( it = begin(); it != end(); ++it ) { |
738 | if ( (*it).hasCategory( category) ) { | 753 | if ( (*it).hasCategory( category) ) { |
739 | results.append( *it ); | 754 | results.append( *it ); |
740 | } | 755 | } |
741 | } | 756 | } |
742 | 757 | ||
743 | return results; | 758 | return results; |
744 | } | 759 | } |
745 | 760 | ||
746 | void AddressBook::dump() const | 761 | void AddressBook::dump() const |
747 | { | 762 | { |
748 | kdDebug(5700) << "AddressBook::dump() --- begin ---" << endl; | 763 | kdDebug(5700) << "AddressBook::dump() --- begin ---" << endl; |
749 | 764 | ||
750 | ConstIterator it; | 765 | ConstIterator it; |
751 | for( it = begin(); it != end(); ++it ) { | 766 | for( it = begin(); it != end(); ++it ) { |