-rw-r--r-- | kabc/addressbook.cpp | 26 |
1 files changed, 10 insertions, 16 deletions
diff --git a/kabc/addressbook.cpp b/kabc/addressbook.cpp index 6194d6d..4c4ae09 100644 --- a/kabc/addressbook.cpp +++ b/kabc/addressbook.cpp | |||
@@ -533,65 +533,64 @@ void AddressBook::removeUntagged() | |||
533 | for ( ait = begin(); ait != end(); ++ait ) { | 533 | for ( ait = begin(); ait != end(); ++ait ) { |
534 | if ( todelete ) | 534 | if ( todelete ) |
535 | removeAddressee( todel ); | 535 | removeAddressee( todel ); |
536 | if (!(*ait).tagged()) { | 536 | if (!(*ait).tagged()) { |
537 | todelete = true; | 537 | todelete = true; |
538 | todel = ait; | 538 | todel = ait; |
539 | } else | 539 | } else |
540 | todelete = false; | 540 | todelete = false; |
541 | } | 541 | } |
542 | if ( todelete ) | 542 | if ( todelete ) |
543 | removeAddressee( todel ); | 543 | removeAddressee( todel ); |
544 | deleteRemovedAddressees(); | 544 | deleteRemovedAddressees(); |
545 | } | 545 | } |
546 | void AddressBook::smplifyAddressees() | 546 | void AddressBook::smplifyAddressees() |
547 | { | 547 | { |
548 | Iterator ait; | 548 | Iterator ait; |
549 | for ( ait = begin(); ait != end(); ++ait ) { | 549 | for ( ait = begin(); ait != end(); ++ait ) { |
550 | (*ait).simplifyEmails(); | 550 | (*ait).simplifyEmails(); |
551 | (*ait).simplifyPhoneNumbers(); | 551 | (*ait).simplifyPhoneNumbers(); |
552 | (*ait).simplifyPhoneNumberTypes(); | 552 | (*ait).simplifyPhoneNumberTypes(); |
553 | (*ait).simplifyAddresses(); | 553 | (*ait).simplifyAddresses(); |
554 | } | 554 | } |
555 | } | 555 | } |
556 | void AddressBook::removeSyncInfo( QString syncProfile) | 556 | void AddressBook::removeSyncInfo( QString syncProfile) |
557 | { | 557 | { |
558 | Iterator ait; | 558 | Iterator ait; |
559 | for ( ait = begin(); ait != end(); ++ait ) { | 559 | for ( ait = begin(); ait != end(); ++ait ) { |
560 | (*ait).removeID( syncProfile ); | 560 | (*ait).removeID( syncProfile ); |
561 | } | 561 | } |
562 | if ( syncProfile.isEmpty() ) { | 562 | if ( syncProfile.isEmpty() ) { |
563 | Iterator it = begin(); | 563 | Iterator it = begin(); |
564 | Iterator it2 ; | 564 | Iterator it2 ; |
565 | QDateTime dt ( QDate( 2004,1,1) ); | ||
566 | while ( it != end() ) { | 565 | while ( it != end() ) { |
567 | if ( (*it).uid().left( 19 ) == QString("last-syncAddressee-") ) { | 566 | if ( (*it).uid().left( 19 ) == QString("last-syncAddressee-") ) { |
568 | it2 = it; | 567 | it2 = it; |
569 | //qDebug("removing %s ",(*it).uid().latin1() ); | 568 | //qDebug("removing %s ",(*it).uid().latin1() ); |
570 | ++it; | 569 | ++it; |
571 | removeAddressee( it2 ); | 570 | removeAddressee( it2 ); |
572 | } else { | 571 | } else { |
573 | //qDebug("skipping %s ",(*it).uid().latin1() ); | 572 | //qDebug("skipping %s ",(*it).uid().latin1() ); |
574 | ++it; | 573 | ++it; |
575 | } | 574 | } |
576 | } | 575 | } |
577 | } else { | 576 | } else { |
578 | Addressee lse; | 577 | Addressee lse; |
579 | lse = findByUid( "last-syncAddressee-"+ syncProfile ); | 578 | lse = findByUid( "last-syncAddressee-"+ syncProfile ); |
580 | if ( ! lse.isEmpty() ) | 579 | if ( ! lse.isEmpty() ) |
581 | removeAddressee( lse ); | 580 | removeAddressee( lse ); |
582 | } | 581 | } |
583 | 582 | ||
584 | } | 583 | } |
585 | void AddressBook::preparePhoneSync( QString currentSyncDevice, bool isPreSync ) | 584 | void AddressBook::preparePhoneSync( QString currentSyncDevice, bool isPreSync ) |
586 | { | 585 | { |
587 | Iterator ait; | 586 | Iterator ait; |
588 | for ( ait = begin(); ait != end(); ++ait ) { | 587 | for ( ait = begin(); ait != end(); ++ait ) { |
589 | QString id = (*ait).IDStr(); | 588 | QString id = (*ait).IDStr(); |
590 | (*ait).setIDStr( ":"); | 589 | (*ait).setIDStr( ":"); |
591 | (*ait).setExternalUID( id ); | 590 | (*ait).setExternalUID( id ); |
592 | (*ait).setOriginalExternalUID( id ); | 591 | (*ait).setOriginalExternalUID( id ); |
593 | if ( isPreSync ) | 592 | if ( isPreSync ) |
594 | (*ait).setTempSyncStat( SYNC_TEMPSTATE_NEW_EXTERNAL ); | 593 | (*ait).setTempSyncStat( SYNC_TEMPSTATE_NEW_EXTERNAL ); |
595 | else { | 594 | else { |
596 | (*ait).setTempSyncStat( SYNC_TEMPSTATE_NEW_ID ); | 595 | (*ait).setTempSyncStat( SYNC_TEMPSTATE_NEW_ID ); |
597 | (*ait).setID( currentSyncDevice,id ); | 596 | (*ait).setID( currentSyncDevice,id ); |
@@ -757,223 +756,218 @@ Ticket *AddressBook::requestSaveTicket( Resource *resource ) | |||
757 | 756 | ||
758 | return 0; | 757 | return 0; |
759 | } | 758 | } |
760 | //void insertAddressee( const Addressee &, bool setRev = true, bool takeResource = false); | 759 | //void insertAddressee( const Addressee &, bool setRev = true, bool takeResource = false); |
761 | void AddressBook::insertAddressee( const Addressee &a, bool setRev, bool takeResource ) | 760 | void AddressBook::insertAddressee( const Addressee &a, bool setRev, bool takeResource ) |
762 | { | 761 | { |
763 | if ( blockLSEchange && setRev && a.uid().left( 19 ) == QString("last-syncAddressee-") ) { | 762 | if ( blockLSEchange && setRev && a.uid().left( 19 ) == QString("last-syncAddressee-") ) { |
764 | //qDebug("block insert "); | 763 | //qDebug("block insert "); |
765 | return; | 764 | return; |
766 | } | 765 | } |
767 | //qDebug("inserting.... %s ",a.uid().latin1() ); | 766 | //qDebug("inserting.... %s ",a.uid().latin1() ); |
768 | bool found = false; | 767 | bool found = false; |
769 | Addressee::List::Iterator it; | 768 | Addressee::List::Iterator it; |
770 | for ( it = d->mAddressees.begin(); it != d->mAddressees.end(); ++it ) { | 769 | for ( it = d->mAddressees.begin(); it != d->mAddressees.end(); ++it ) { |
771 | if ( a.uid() == (*it).uid() ) { | 770 | if ( a.uid() == (*it).uid() ) { |
772 | 771 | ||
773 | bool changed = false; | 772 | bool changed = false; |
774 | Addressee addr = a; | 773 | Addressee addr = a; |
775 | if ( addr != (*it) ) | 774 | if ( addr != (*it) ) |
776 | changed = true; | 775 | changed = true; |
777 | 776 | ||
778 | if ( takeResource ) { | 777 | if ( takeResource ) { |
779 | Resource * res = (*it).resource(); | 778 | Resource * res = (*it).resource(); |
780 | (*it) = a; | 779 | (*it) = a; |
781 | (*it).setResource( res ); | 780 | (*it).setResource( res ); |
782 | } else { | 781 | } else { |
783 | (*it) = a; | 782 | (*it) = a; |
784 | if ( (*it).resource() == 0 ) | 783 | if ( (*it).resource() == 0 ) |
785 | (*it).setResource( standardResource() ); | 784 | (*it).setResource( standardResource() ); |
786 | } | 785 | } |
787 | if ( changed ) { | 786 | if ( changed ) { |
788 | if ( setRev ) { | 787 | if ( setRev ) { |
789 | 788 | (*it).setRevision( QDateTime::currentDateTime() ); | |
790 | // get rid of micro seconds | ||
791 | QDateTime dt = QDateTime::currentDateTime(); | ||
792 | QTime t = dt.time(); | ||
793 | dt.setTime( QTime (t.hour (), t.minute (), t.second () ) ); | ||
794 | (*it).setRevision( dt ); | ||
795 | } | 789 | } |
796 | (*it).setChanged( true ); | 790 | (*it).setChanged( true ); |
797 | } | 791 | } |
798 | 792 | ||
799 | found = true; | 793 | found = true; |
800 | } else { | 794 | } else { |
801 | if ( (*it).uid().left( 19 ) == QString("last-syncAddressee-") ) { | 795 | if ( (*it).uid().left( 19 ) == QString("last-syncAddressee-") ) { |
802 | QString name = (*it).uid().mid( 19 ); | 796 | QString name = (*it).uid().mid( 19 ); |
803 | Addressee b = a; | 797 | Addressee b = a; |
804 | QString id = b.getID( name ); | 798 | QString id = b.getID( name ); |
805 | if ( ! id.isEmpty() ) { | 799 | if ( ! id.isEmpty() ) { |
806 | QString des = (*it).note(); | 800 | QString des = (*it).note(); |
807 | int startN; | 801 | int startN; |
808 | if( (startN = des.find( id ) ) >= 0 ) { | 802 | if( (startN = des.find( id ) ) >= 0 ) { |
809 | int endN = des.find( ",", startN+1 ); | 803 | int endN = des.find( ",", startN+1 ); |
810 | des = des.left( startN ) + des.mid( endN+1 ); | 804 | des = des.left( startN ) + des.mid( endN+1 ); |
811 | (*it).setNote( des ); | 805 | (*it).setNote( des ); |
812 | } | 806 | } |
813 | } | 807 | } |
814 | } | 808 | } |
815 | } | 809 | } |
816 | } | 810 | } |
817 | if ( found ) | 811 | if ( found ) |
818 | return; | 812 | return; |
813 | |||
819 | d->mAddressees.append( a ); | 814 | d->mAddressees.append( a ); |
820 | Addressee& addr = d->mAddressees.last(); | 815 | Addressee& addr = d->mAddressees.last(); |
821 | if ( addr.resource() == 0 ) | 816 | if ( addr.resource() == 0 ) |
822 | addr.setResource( standardResource() ); | 817 | addr.setResource( standardResource() ); |
823 | |||
824 | addr.setChanged( true ); | 818 | addr.setChanged( true ); |
825 | } | 819 | } |
826 | 820 | ||
827 | void AddressBook::removeAddressee( const Addressee &a ) | 821 | void AddressBook::removeAddressee( const Addressee &a ) |
828 | { | 822 | { |
829 | Iterator it; | 823 | Iterator it; |
830 | Iterator it2; | 824 | Iterator it2; |
831 | bool found = false; | 825 | bool found = false; |
832 | for ( it = begin(); it != end(); ++it ) { | 826 | for ( it = begin(); it != end(); ++it ) { |
833 | if ( a.uid() == (*it).uid() ) { | 827 | if ( a.uid() == (*it).uid() ) { |
834 | found = true; | 828 | found = true; |
835 | it2 = it; | 829 | it2 = it; |
836 | } else { | 830 | } else { |
837 | if ( (*it).uid().left( 19 ) == QString("last-syncAddressee-") ) { | 831 | if ( (*it).uid().left( 19 ) == QString("last-syncAddressee-") ) { |
838 | QString name = (*it).uid().mid( 19 ); | 832 | QString name = (*it).uid().mid( 19 ); |
839 | Addressee b = a; | 833 | Addressee b = a; |
840 | QString id = b.getID( name ); | 834 | QString id = b.getID( name ); |
841 | if ( ! id.isEmpty() ) { | 835 | if ( ! id.isEmpty() ) { |
842 | QString des = (*it).note(); | 836 | QString des = (*it).note(); |
843 | if( des.find( id ) < 0 ) { | 837 | if( des.find( id ) < 0 ) { |
844 | des += id + ","; | 838 | des += id + ","; |
845 | (*it).setNote( des ); | 839 | (*it).setNote( des ); |
846 | } | 840 | } |
847 | } | 841 | } |
848 | } | 842 | } |
849 | 843 | ||
850 | } | 844 | } |
851 | } | 845 | } |
852 | 846 | ||
853 | if ( found ) | 847 | if ( found ) |
854 | removeAddressee( it2 ); | 848 | removeAddressee( it2 ); |
855 | 849 | ||
856 | } | 850 | } |
857 | 851 | ||
858 | void AddressBook::removeSyncAddressees( bool removeDeleted ) | 852 | void AddressBook::removeSyncAddressees( bool removeDeleted ) |
859 | { | 853 | { |
860 | Iterator it = begin(); | 854 | Iterator it = begin(); |
861 | Iterator it2 ; | 855 | Iterator it2 ; |
862 | QDateTime dt ( QDate( 2004,1,1) ); | 856 | QDateTime dt ( QDate( 2003,1,1) ); |
863 | while ( it != end() ) { | 857 | while ( it != end() ) { |
864 | (*it).setRevision( dt ); | 858 | (*it).setRevision( dt ); |
865 | if (( *it).IDStr() != "changed" ) { | 859 | if (( *it).IDStr() != "changed" ) { |
866 | // "changed" is used for tagging changed addressees when syncing with KDE or OL | 860 | // "changed" is used for tagging changed addressees when syncing with KDE or OL |
867 | (*it).removeCustom( "KADDRESSBOOK", "X-ExternalID" ); | 861 | (*it).removeCustom( "KADDRESSBOOK", "X-ExternalID" ); |
868 | (*it).setIDStr(""); | 862 | (*it).setIDStr(":"); |
869 | } | 863 | } |
870 | if ( ( (*it).tempSyncStat() == SYNC_TEMPSTATE_DELETE && removeDeleted )|| (*it).uid().left( 19 ) == QString("last-syncAddressee-")) { | 864 | if ( ( (*it).tempSyncStat() == SYNC_TEMPSTATE_DELETE && removeDeleted )|| (*it).uid().left( 19 ) == QString("last-syncAddressee-")) { |
871 | it2 = it; | 865 | it2 = it; |
872 | //qDebug("removing %s ",(*it).uid().latin1() ); | 866 | //qDebug("removing %s ",(*it).uid().latin1() ); |
873 | ++it; | 867 | ++it; |
874 | removeAddressee( it2 ); | 868 | removeAddressee( it2 ); |
875 | } else { | 869 | } else { |
876 | //qDebug("skipping %s ",(*it).uid().latin1() ); | 870 | //qDebug("skipping %s ",(*it).uid().latin1() ); |
877 | if ( removeDeleted ) { | 871 | if ( removeDeleted ) { |
878 | // we have no postprocessing in the resource, we have to do it here | 872 | // we have no postprocessing in the resource, we have to do it here |
879 | // we have to compute csum for all, because it could be the first sync | 873 | // we have to compute csum for all, because it could be the first sync |
880 | (*it).setTempSyncStat( SYNC_TEMPSTATE_NEW_ID ); | 874 | (*it).setTempSyncStat( SYNC_TEMPSTATE_NEW_ID ); |
881 | |||
882 | |||
883 | } | 875 | } |
884 | ++it; | 876 | ++it; |
885 | } | 877 | } |
886 | } | 878 | } |
887 | deleteRemovedAddressees(); | 879 | deleteRemovedAddressees(); |
888 | } | 880 | } |
889 | 881 | ||
890 | void AddressBook::removeAddressee( const Iterator &it ) | 882 | void AddressBook::removeAddressee( const Iterator &it ) |
891 | { | 883 | { |
892 | d->mRemovedAddressees.append( (*it) ); | 884 | d->mRemovedAddressees.append( (*it) ); |
893 | d->mAddressees.remove( it.d->mIt ); | 885 | d->mAddressees.remove( it.d->mIt ); |
894 | } | 886 | } |
895 | 887 | ||
896 | AddressBook::Iterator AddressBook::find( const Addressee &a ) | 888 | AddressBook::Iterator AddressBook::find( const Addressee &a ) |
897 | { | 889 | { |
898 | Iterator it; | 890 | Iterator it; |
899 | for ( it = begin(); it != end(); ++it ) { | 891 | for ( it = begin(); it != end(); ++it ) { |
900 | if ( a.uid() == (*it).uid() ) { | 892 | if ( a.uid() == (*it).uid() ) { |
901 | return it; | 893 | return it; |
902 | } | 894 | } |
903 | } | 895 | } |
904 | return end(); | 896 | return end(); |
905 | } | 897 | } |
906 | 898 | ||
907 | Addressee AddressBook::findByUid( const QString &uid ) | 899 | Addressee AddressBook::findByUid( const QString &uid ) |
908 | { | 900 | { |
909 | Iterator it; | 901 | Iterator it; |
910 | for ( it = begin(); it != end(); ++it ) { | 902 | for ( it = begin(); it != end(); ++it ) { |
911 | if ( uid == (*it).uid() ) { | 903 | if ( uid == (*it).uid() ) { |
912 | return *it; | 904 | return *it; |
913 | } | 905 | } |
914 | } | 906 | } |
915 | return Addressee(); | 907 | return Addressee(); |
916 | } | 908 | } |
917 | void AddressBook::preExternSync( AddressBook* aBook, const QString& csd , bool isSubset ) | 909 | void AddressBook::preExternSync( AddressBook* aBook, const QString& csd , bool isSubset ) |
918 | { | 910 | { |
919 | //qDebug("AddressBook::preExternSync "); | 911 | //qDebug("AddressBook::preExternSync "); |
920 | AddressBook::Iterator it; | 912 | AddressBook::Iterator it; |
921 | for ( it = begin(); it != end(); ++it ) { | 913 | for ( it = begin(); it != end(); ++it ) { |
922 | (*it).setID( csd, (*it).externalUID() ); | 914 | (*it).setID( csd, (*it).externalUID() ); |
923 | (*it).computeCsum( csd ); | 915 | (*it).computeCsum( csd ); |
924 | } | 916 | } |
925 | mergeAB( aBook ,csd, isSubset ); | 917 | mergeAB( aBook ,csd, isSubset ); |
926 | } | 918 | } |
927 | void AddressBook::postExternSync( AddressBook* aBook , const QString& csd, bool setID) | 919 | void AddressBook::postExternSync( AddressBook* aBook , const QString& csd, bool setID) |
928 | { | 920 | { |
929 | //qDebug("AddressBook::postExternSync "); | 921 | //qDebug("AddressBook::postExternSync "); |
930 | AddressBook::Iterator it; | 922 | AddressBook::Iterator it; |
931 | for ( it = begin(); it != end(); ++it ) { | 923 | for ( it = begin(); it != end(); ++it ) { |
932 | //qDebug("check uid %s ", (*it).uid().latin1() ); | 924 | //qDebug("check uid %s ", (*it).uid().latin1() ); |
933 | if ( (*it).tempSyncStat() == SYNC_TEMPSTATE_NEW_ID || | 925 | if ( (*it).tempSyncStat() == SYNC_TEMPSTATE_NEW_ID || |
934 | (*it).tempSyncStat() == SYNC_TEMPSTATE_NEW_CSUM ) { | 926 | (*it).tempSyncStat() == SYNC_TEMPSTATE_NEW_CSUM || |
927 | (*it).tempSyncStat() == SYNC_TEMPSTATE_ADDED_EXTERNAL) { | ||
935 | Addressee ad = aBook->findByUid( ( (*it).uid() )); | 928 | Addressee ad = aBook->findByUid( ( (*it).uid() )); |
936 | if ( ad.isEmpty() ) { | 929 | if ( ad.isEmpty() ) { |
937 | qDebug("postExternSync:ERROR addressee is empty: %s ", (*it).uid().latin1()); | 930 | qDebug("postExternSync:ERROR addressee is empty: %s ", (*it).uid().latin1()); |
938 | } else { | 931 | } else { |
939 | (*it).setIDStr(":"); | 932 | (*it).setIDStr(":"); |
940 | (*it).computeCsum( csd ); | ||
941 | if ( setID ) { | 933 | if ( setID ) { |
942 | if ( (*it).tempSyncStat() == SYNC_TEMPSTATE_NEW_ID ) | 934 | if ( (*it).tempSyncStat() == SYNC_TEMPSTATE_NEW_ID ) |
943 | ad.setID( csd, (*it).externalUID() ); | 935 | ad.setID( csd, (*it).externalUID() ); |
944 | } else | 936 | } else |
945 | ad.setID( csd, (*it).uid() ); | 937 | ad.setID( csd, (*it).uid() ); |
938 | (*it).computeCsum( csd ); | ||
946 | ad.setCsum( csd, (*it).getCsum( csd ) ); | 939 | ad.setCsum( csd, (*it).getCsum( csd ) ); |
947 | aBook->insertAddressee( ad ); | 940 | //qDebug("CSUM %s ",(*it).getCsum( csd ).latin1() ); |
941 | aBook->insertAddressee( ad , false); | ||
948 | } | 942 | } |
949 | } | 943 | } |
950 | } | 944 | } |
951 | } | 945 | } |
952 | 946 | ||
953 | bool AddressBook::containsExternalUid( const QString& uid ) | 947 | bool AddressBook::containsExternalUid( const QString& uid ) |
954 | { | 948 | { |
955 | Iterator it; | 949 | Iterator it; |
956 | for ( it = begin(); it != end(); ++it ) { | 950 | for ( it = begin(); it != end(); ++it ) { |
957 | if ( uid == (*it).externalUID( ) ) | 951 | if ( uid == (*it).externalUID( ) ) |
958 | return true; | 952 | return true; |
959 | } | 953 | } |
960 | return false; | 954 | return false; |
961 | } | 955 | } |
962 | Addressee AddressBook::findByExternUid( const QString& uid , const QString& profile ) | 956 | Addressee AddressBook::findByExternUid( const QString& uid , const QString& profile ) |
963 | { | 957 | { |
964 | Iterator it; | 958 | Iterator it; |
965 | for ( it = begin(); it != end(); ++it ) { | 959 | for ( it = begin(); it != end(); ++it ) { |
966 | if ( uid == (*it).getID( profile ) ) | 960 | if ( uid == (*it).getID( profile ) ) |
967 | return (*it); | 961 | return (*it); |
968 | } | 962 | } |
969 | return Addressee(); | 963 | return Addressee(); |
970 | } | 964 | } |
971 | void AddressBook::mergeAB( AddressBook *aBook, const QString& profile , bool isSubset ) | 965 | void AddressBook::mergeAB( AddressBook *aBook, const QString& profile , bool isSubset ) |
972 | { | 966 | { |
973 | Iterator it; | 967 | Iterator it; |
974 | Addressee ad; | 968 | Addressee ad; |
975 | for ( it = begin(); it != end(); ++it ) { | 969 | for ( it = begin(); it != end(); ++it ) { |
976 | ad = aBook->findByExternUid( (*it).externalUID(), profile ); | 970 | ad = aBook->findByExternUid( (*it).externalUID(), profile ); |
977 | if ( !ad.isEmpty() ) { | 971 | if ( !ad.isEmpty() ) { |
978 | (*it).mergeContact( ad ,isSubset); | 972 | (*it).mergeContact( ad ,isSubset); |
979 | } | 973 | } |