-rw-r--r-- | kabc/addressbook.cpp | 22 |
1 files changed, 20 insertions, 2 deletions
diff --git a/kabc/addressbook.cpp b/kabc/addressbook.cpp index f9e4387..fe59fcb 100644 --- a/kabc/addressbook.cpp +++ b/kabc/addressbook.cpp | |||
@@ -693,532 +693,550 @@ bool AddressBook::saveAB() | |||
693 | Iterator ait; | 693 | Iterator ait; |
694 | for ( ait = begin(); ait != end(); ++ait ) { | 694 | for ( ait = begin(); ait != end(); ++ait ) { |
695 | if ( !(*ait).IDStr().isEmpty() ) { | 695 | if ( !(*ait).IDStr().isEmpty() ) { |
696 | (*ait).insertCustom( "KADDRESSBOOK", "X-ExternalID", (*ait).IDStr() ); | 696 | (*ait).insertCustom( "KADDRESSBOOK", "X-ExternalID", (*ait).IDStr() ); |
697 | } | 697 | } |
698 | } | 698 | } |
699 | KRES::Manager<Resource>::ActiveIterator it; | 699 | KRES::Manager<Resource>::ActiveIterator it; |
700 | KRES::Manager<Resource> *manager = d->mManager; | 700 | KRES::Manager<Resource> *manager = d->mManager; |
701 | qDebug("SaveAB::saving..." ); | 701 | qDebug("SaveAB::saving..." ); |
702 | for ( it = manager->activeBegin(); it != manager->activeEnd(); ++it ) { | 702 | for ( it = manager->activeBegin(); it != manager->activeEnd(); ++it ) { |
703 | qDebug("SaveAB::checking resource..." ); | 703 | qDebug("SaveAB::checking resource..." ); |
704 | if ( (*it)->readOnly() ) | 704 | if ( (*it)->readOnly() ) |
705 | qDebug("SaveAB::resource is readonly." ); | 705 | qDebug("SaveAB::resource is readonly." ); |
706 | if ( (*it)->isOpen() ) | 706 | if ( (*it)->isOpen() ) |
707 | qDebug("SaveAB::resource is open" ); | 707 | qDebug("SaveAB::resource is open" ); |
708 | 708 | ||
709 | if ( !(*it)->readOnly() && (*it)->isOpen() ) { | 709 | if ( !(*it)->readOnly() && (*it)->isOpen() ) { |
710 | Ticket *ticket = requestSaveTicket( *it ); | 710 | Ticket *ticket = requestSaveTicket( *it ); |
711 | qDebug("SaveAB::StdAddressBook::save '%s'", (*it)->resourceName().latin1() ); | 711 | qDebug("SaveAB::StdAddressBook::save '%s'", (*it)->resourceName().latin1() ); |
712 | if ( !ticket ) { | 712 | if ( !ticket ) { |
713 | qDebug( i18n( "SaveAB::Unable to save to resource '%1'. It is locked." ) | 713 | qDebug( i18n( "SaveAB::Unable to save to resource '%1'. It is locked." ) |
714 | .arg( (*it)->resourceName() ) ); | 714 | .arg( (*it)->resourceName() ) ); |
715 | return false; | 715 | return false; |
716 | } | 716 | } |
717 | 717 | ||
718 | //if ( !save( ticket ) ) | 718 | //if ( !save( ticket ) ) |
719 | if ( ticket->resource() ) { | 719 | if ( ticket->resource() ) { |
720 | QString name = ticket->resource()->resourceName(); | 720 | QString name = ticket->resource()->resourceName(); |
721 | if ( ! ticket->resource()->save( ticket ) ) | 721 | if ( ! ticket->resource()->save( ticket ) ) |
722 | ok = false; | 722 | ok = false; |
723 | else | 723 | else |
724 | qDebug("SaveAB::resource saved '%s'", name.latin1() ); | 724 | qDebug("SaveAB::resource saved '%s'", name.latin1() ); |
725 | 725 | ||
726 | } else | 726 | } else |
727 | ok = false; | 727 | ok = false; |
728 | 728 | ||
729 | } | 729 | } |
730 | } | 730 | } |
731 | return ok; | 731 | return ok; |
732 | } | 732 | } |
733 | 733 | ||
734 | AddressBook::Iterator AddressBook::begin() | 734 | AddressBook::Iterator AddressBook::begin() |
735 | { | 735 | { |
736 | Iterator it = Iterator(); | 736 | Iterator it = Iterator(); |
737 | it.d->mIt = d->mAddressees.begin(); | 737 | it.d->mIt = d->mAddressees.begin(); |
738 | return it; | 738 | return it; |
739 | } | 739 | } |
740 | 740 | ||
741 | AddressBook::ConstIterator AddressBook::begin() const | 741 | AddressBook::ConstIterator AddressBook::begin() const |
742 | { | 742 | { |
743 | ConstIterator it = ConstIterator(); | 743 | ConstIterator it = ConstIterator(); |
744 | it.d->mIt = d->mAddressees.begin(); | 744 | it.d->mIt = d->mAddressees.begin(); |
745 | return it; | 745 | return it; |
746 | } | 746 | } |
747 | 747 | ||
748 | AddressBook::Iterator AddressBook::end() | 748 | AddressBook::Iterator AddressBook::end() |
749 | { | 749 | { |
750 | Iterator it = Iterator(); | 750 | Iterator it = Iterator(); |
751 | it.d->mIt = d->mAddressees.end(); | 751 | it.d->mIt = d->mAddressees.end(); |
752 | return it; | 752 | return it; |
753 | } | 753 | } |
754 | 754 | ||
755 | AddressBook::ConstIterator AddressBook::end() const | 755 | AddressBook::ConstIterator AddressBook::end() const |
756 | { | 756 | { |
757 | ConstIterator it = ConstIterator(); | 757 | ConstIterator it = ConstIterator(); |
758 | it.d->mIt = d->mAddressees.end(); | 758 | it.d->mIt = d->mAddressees.end(); |
759 | return it; | 759 | return it; |
760 | } | 760 | } |
761 | 761 | ||
762 | void AddressBook::clear() | 762 | void AddressBook::clear() |
763 | { | 763 | { |
764 | d->mAddressees.clear(); | 764 | d->mAddressees.clear(); |
765 | } | 765 | } |
766 | 766 | ||
767 | Ticket *AddressBook::requestSaveTicket( Resource *resource ) | 767 | Ticket *AddressBook::requestSaveTicket( Resource *resource ) |
768 | { | 768 | { |
769 | kdDebug(5700) << "AddressBook::requestSaveTicket()" << endl; | 769 | kdDebug(5700) << "AddressBook::requestSaveTicket()" << endl; |
770 | 770 | ||
771 | if ( !resource ) | 771 | if ( !resource ) |
772 | { | 772 | { |
773 | qDebug("AddressBook::requestSaveTicket no resource" ); | 773 | qDebug("AddressBook::requestSaveTicket no resource" ); |
774 | resource = standardResource(); | 774 | resource = standardResource(); |
775 | } | 775 | } |
776 | 776 | ||
777 | KRES::Manager<Resource>::ActiveIterator it; | 777 | KRES::Manager<Resource>::ActiveIterator it; |
778 | for ( it = d->mManager->activeBegin(); it != d->mManager->activeEnd(); ++it ) { | 778 | for ( it = d->mManager->activeBegin(); it != d->mManager->activeEnd(); ++it ) { |
779 | if ( (*it) == resource ) { | 779 | if ( (*it) == resource ) { |
780 | if ( (*it)->readOnly() || !(*it)->isOpen() ) | 780 | if ( (*it)->readOnly() || !(*it)->isOpen() ) |
781 | return 0; | 781 | return 0; |
782 | else | 782 | else |
783 | return (*it)->requestSaveTicket(); | 783 | return (*it)->requestSaveTicket(); |
784 | } | 784 | } |
785 | } | 785 | } |
786 | 786 | ||
787 | return 0; | 787 | return 0; |
788 | } | 788 | } |
789 | //void insertAddressee( const Addressee &, bool setRev = true, bool takeResource = false); | 789 | //void insertAddressee( const Addressee &, bool setRev = true, bool takeResource = false); |
790 | void AddressBook::insertAddressee( const Addressee &a, bool setRev, bool takeResource ) | 790 | void AddressBook::insertAddressee( const Addressee &a, bool setRev, bool takeResource ) |
791 | { | 791 | { |
792 | if ( blockLSEchange && setRev && a.uid().left( 19 ) == QString("last-syncAddressee-") ) { | 792 | if ( blockLSEchange && setRev && a.uid().left( 19 ) == QString("last-syncAddressee-") ) { |
793 | //qDebug("block insert "); | 793 | //qDebug("block insert "); |
794 | return; | 794 | return; |
795 | } | 795 | } |
796 | //qDebug("inserting.... %s ",a.uid().latin1() ); | 796 | //qDebug("inserting.... %s ",a.uid().latin1() ); |
797 | bool found = false; | 797 | bool found = false; |
798 | Addressee::List::Iterator it; | 798 | Addressee::List::Iterator it; |
799 | for ( it = d->mAddressees.begin(); it != d->mAddressees.end(); ++it ) { | 799 | for ( it = d->mAddressees.begin(); it != d->mAddressees.end(); ++it ) { |
800 | if ( a.uid() == (*it).uid() ) { | 800 | if ( a.uid() == (*it).uid() ) { |
801 | 801 | ||
802 | bool changed = false; | 802 | bool changed = false; |
803 | Addressee addr = a; | 803 | Addressee addr = a; |
804 | if ( addr != (*it) ) | 804 | if ( addr != (*it) ) |
805 | changed = true; | 805 | changed = true; |
806 | 806 | ||
807 | if ( takeResource ) { | 807 | if ( takeResource ) { |
808 | Resource * res = (*it).resource(); | 808 | Resource * res = (*it).resource(); |
809 | (*it) = a; | 809 | (*it) = a; |
810 | (*it).setResource( res ); | 810 | (*it).setResource( res ); |
811 | } else { | 811 | } else { |
812 | (*it) = a; | 812 | (*it) = a; |
813 | if ( (*it).resource() == 0 ) | 813 | if ( (*it).resource() == 0 ) |
814 | (*it).setResource( standardResource() ); | 814 | (*it).setResource( standardResource() ); |
815 | } | 815 | } |
816 | if ( changed ) { | 816 | if ( changed ) { |
817 | if ( setRev ) { | 817 | if ( setRev ) { |
818 | (*it).setRevision( QDateTime::currentDateTime() ); | 818 | (*it).setRevision( QDateTime::currentDateTime() ); |
819 | } | 819 | } |
820 | (*it).setChanged( true ); | 820 | (*it).setChanged( true ); |
821 | } | 821 | } |
822 | 822 | ||
823 | found = true; | 823 | found = true; |
824 | } else { | 824 | } else { |
825 | if ( (*it).uid().left( 19 ) == QString("last-syncAddressee-") ) { | 825 | if ( (*it).uid().left( 19 ) == QString("last-syncAddressee-") ) { |
826 | QString name = (*it).uid().mid( 19 ); | 826 | QString name = (*it).uid().mid( 19 ); |
827 | Addressee b = a; | 827 | Addressee b = a; |
828 | QString id = b.getID( name ); | 828 | QString id = b.getID( name ); |
829 | if ( ! id.isEmpty() ) { | 829 | if ( ! id.isEmpty() ) { |
830 | QString des = (*it).note(); | 830 | QString des = (*it).note(); |
831 | int startN; | 831 | int startN; |
832 | if( (startN = des.find( id ) ) >= 0 ) { | 832 | if( (startN = des.find( id ) ) >= 0 ) { |
833 | int endN = des.find( ",", startN+1 ); | 833 | int endN = des.find( ",", startN+1 ); |
834 | des = des.left( startN ) + des.mid( endN+1 ); | 834 | des = des.left( startN ) + des.mid( endN+1 ); |
835 | (*it).setNote( des ); | 835 | (*it).setNote( des ); |
836 | } | 836 | } |
837 | } | 837 | } |
838 | } | 838 | } |
839 | } | 839 | } |
840 | } | 840 | } |
841 | if ( found ) | 841 | if ( found ) |
842 | return; | 842 | return; |
843 | 843 | ||
844 | d->mAddressees.append( a ); | 844 | d->mAddressees.append( a ); |
845 | Addressee& addr = d->mAddressees.last(); | 845 | Addressee& addr = d->mAddressees.last(); |
846 | if ( addr.resource() == 0 ) | 846 | if ( addr.resource() == 0 ) |
847 | addr.setResource( standardResource() ); | 847 | addr.setResource( standardResource() ); |
848 | addr.setChanged( true ); | 848 | addr.setChanged( true ); |
849 | } | 849 | } |
850 | 850 | ||
851 | void AddressBook::removeAddressee( const Addressee &a ) | 851 | void AddressBook::removeAddressee( const Addressee &a ) |
852 | { | 852 | { |
853 | Iterator it; | 853 | Iterator it; |
854 | Iterator it2; | 854 | Iterator it2; |
855 | bool found = false; | 855 | bool found = false; |
856 | for ( it = begin(); it != end(); ++it ) { | 856 | for ( it = begin(); it != end(); ++it ) { |
857 | if ( a.uid() == (*it).uid() ) { | 857 | if ( a.uid() == (*it).uid() ) { |
858 | found = true; | 858 | found = true; |
859 | it2 = it; | 859 | it2 = it; |
860 | } else { | 860 | } else { |
861 | if ( (*it).uid().left( 19 ) == QString("last-syncAddressee-") ) { | 861 | if ( (*it).uid().left( 19 ) == QString("last-syncAddressee-") ) { |
862 | QString name = (*it).uid().mid( 19 ); | 862 | QString name = (*it).uid().mid( 19 ); |
863 | Addressee b = a; | 863 | Addressee b = a; |
864 | QString id = b.getID( name ); | 864 | QString id = b.getID( name ); |
865 | if ( ! id.isEmpty() ) { | 865 | if ( ! id.isEmpty() ) { |
866 | QString des = (*it).note(); | 866 | QString des = (*it).note(); |
867 | if( des.find( id ) < 0 ) { | 867 | if( des.find( id ) < 0 ) { |
868 | des += id + ","; | 868 | des += id + ","; |
869 | (*it).setNote( des ); | 869 | (*it).setNote( des ); |
870 | } | 870 | } |
871 | } | 871 | } |
872 | } | 872 | } |
873 | 873 | ||
874 | } | 874 | } |
875 | } | 875 | } |
876 | 876 | ||
877 | if ( found ) | 877 | if ( found ) |
878 | removeAddressee( it2 ); | 878 | removeAddressee( it2 ); |
879 | 879 | ||
880 | } | 880 | } |
881 | 881 | ||
882 | void AddressBook::removeSyncAddressees( bool removeDeleted ) | 882 | void AddressBook::removeSyncAddressees( bool removeDeleted ) |
883 | { | 883 | { |
884 | Iterator it = begin(); | 884 | Iterator it = begin(); |
885 | Iterator it2 ; | 885 | Iterator it2 ; |
886 | QDateTime dt ( QDate( 2003,1,1) ); | 886 | QDateTime dt ( QDate( 2003,1,1) ); |
887 | while ( it != end() ) { | 887 | while ( it != end() ) { |
888 | (*it).setRevision( dt ); | 888 | (*it).setRevision( dt ); |
889 | if (( *it).IDStr() != "changed" ) { | 889 | if (( *it).IDStr() != "changed" ) { |
890 | // "changed" is used for tagging changed addressees when syncing with KDE or OL | 890 | // "changed" is used for tagging changed addressees when syncing with KDE or OL |
891 | (*it).removeCustom( "KADDRESSBOOK", "X-ExternalID" ); | 891 | (*it).removeCustom( "KADDRESSBOOK", "X-ExternalID" ); |
892 | (*it).setIDStr(":"); | 892 | (*it).setIDStr(":"); |
893 | } | 893 | } |
894 | if ( ( (*it).tempSyncStat() == SYNC_TEMPSTATE_DELETE && removeDeleted )|| (*it).uid().left( 19 ) == QString("last-syncAddressee-")) { | 894 | if ( ( (*it).tempSyncStat() == SYNC_TEMPSTATE_DELETE && removeDeleted )|| (*it).uid().left( 19 ) == QString("last-syncAddressee-")) { |
895 | it2 = it; | 895 | it2 = it; |
896 | //qDebug("removing %s ",(*it).uid().latin1() ); | 896 | //qDebug("removing %s ",(*it).uid().latin1() ); |
897 | ++it; | 897 | ++it; |
898 | removeAddressee( it2 ); | 898 | removeAddressee( it2 ); |
899 | } else { | 899 | } else { |
900 | //qDebug("skipping %s ",(*it).uid().latin1() ); | 900 | //qDebug("skipping %s ",(*it).uid().latin1() ); |
901 | if ( removeDeleted ) { | 901 | if ( removeDeleted ) { |
902 | // we have no postprocessing in the resource, we have to do it here | 902 | // we have no postprocessing in the resource, we have to do it here |
903 | // we have to compute csum for all, because it could be the first sync | 903 | // we have to compute csum for all, because it could be the first sync |
904 | (*it).setTempSyncStat( SYNC_TEMPSTATE_NEW_ID ); | 904 | (*it).setTempSyncStat( SYNC_TEMPSTATE_NEW_ID ); |
905 | } | 905 | } |
906 | ++it; | 906 | ++it; |
907 | } | 907 | } |
908 | } | 908 | } |
909 | deleteRemovedAddressees(); | 909 | deleteRemovedAddressees(); |
910 | } | 910 | } |
911 | 911 | ||
912 | void AddressBook::removeAddressee( const Iterator &it ) | 912 | void AddressBook::removeAddressee( const Iterator &it ) |
913 | { | 913 | { |
914 | d->mRemovedAddressees.append( (*it) ); | 914 | d->mRemovedAddressees.append( (*it) ); |
915 | d->mAddressees.remove( it.d->mIt ); | 915 | d->mAddressees.remove( it.d->mIt ); |
916 | } | 916 | } |
917 | 917 | ||
918 | AddressBook::Iterator AddressBook::find( const Addressee &a ) | 918 | AddressBook::Iterator AddressBook::find( const Addressee &a ) |
919 | { | 919 | { |
920 | Iterator it; | 920 | Iterator it; |
921 | for ( it = begin(); it != end(); ++it ) { | 921 | for ( it = begin(); it != end(); ++it ) { |
922 | if ( a.uid() == (*it).uid() ) { | 922 | if ( a.uid() == (*it).uid() ) { |
923 | return it; | 923 | return it; |
924 | } | 924 | } |
925 | } | 925 | } |
926 | return end(); | 926 | return end(); |
927 | } | 927 | } |
928 | 928 | ||
929 | Addressee AddressBook::findByUid( const QString &uid ) | 929 | Addressee AddressBook::findByUid( const QString &uid ) |
930 | { | 930 | { |
931 | Iterator it; | 931 | Iterator it; |
932 | for ( it = begin(); it != end(); ++it ) { | 932 | for ( it = begin(); it != end(); ++it ) { |
933 | if ( uid == (*it).uid() ) { | 933 | if ( uid == (*it).uid() ) { |
934 | return *it; | 934 | return *it; |
935 | } | 935 | } |
936 | } | 936 | } |
937 | return Addressee(); | 937 | return Addressee(); |
938 | } | 938 | } |
939 | void AddressBook::preExternSync( AddressBook* aBook, const QString& csd , bool isSubset ) | 939 | void AddressBook::preExternSync( AddressBook* aBook, const QString& csd , bool isSubset ) |
940 | { | 940 | { |
941 | //qDebug("AddressBook::preExternSync "); | 941 | //qDebug("AddressBook::preExternSync "); |
942 | AddressBook::Iterator it; | 942 | AddressBook::Iterator it; |
943 | for ( it = begin(); it != end(); ++it ) { | 943 | for ( it = begin(); it != end(); ++it ) { |
944 | (*it).setID( csd, (*it).externalUID() ); | 944 | (*it).setID( csd, (*it).externalUID() ); |
945 | (*it).computeCsum( csd ); | 945 | (*it).computeCsum( csd ); |
946 | } | 946 | } |
947 | mergeAB( aBook ,csd, isSubset ); | 947 | mergeAB( aBook ,csd, isSubset ); |
948 | } | 948 | } |
949 | void AddressBook::preOLSync( AddressBook* aBook, const QString& csd ) | ||
950 | { | ||
951 | //qDebug("AddressBook::preExternSync "); | ||
952 | AddressBook::Iterator it; | ||
953 | for ( it = begin(); it != end(); ++it ) { | ||
954 | (*it).setID( csd, (*it).externalUID() ); | ||
955 | (*it).computeCsum( csd ); | ||
956 | } | ||
957 | |||
958 | Addressee ad; | ||
959 | for ( it = begin(); it != end(); ++it ) { | ||
960 | ad = aBook->findByExternUid( (*it).externalUID(), csd ); | ||
961 | if ( !ad.isEmpty() ) { | ||
962 | (*it).mergeOLContact( ad ); | ||
963 | } | ||
964 | } | ||
965 | } | ||
949 | void AddressBook::postExternSync( AddressBook* aBook , const QString& csd, bool setID) | 966 | void AddressBook::postExternSync( AddressBook* aBook , const QString& csd, bool setID) |
950 | { | 967 | { |
951 | //qDebug("AddressBook::postExternSync "); | 968 | //qDebug("AddressBook::postExternSync "); |
952 | AddressBook::Iterator it; | 969 | AddressBook::Iterator it; |
953 | int foundEmpty = 0; | 970 | int foundEmpty = 0; |
954 | for ( it = begin(); it != end(); ++it ) { | 971 | for ( it = begin(); it != end(); ++it ) { |
955 | //qDebug("check uid %s ", (*it).uid().latin1() ); | 972 | //qDebug("check uid %s ", (*it).uid().latin1() ); |
956 | if ( (*it).tempSyncStat() == SYNC_TEMPSTATE_NEW_ID || | 973 | if ( (*it).tempSyncStat() == SYNC_TEMPSTATE_NEW_ID || |
957 | (*it).tempSyncStat() == SYNC_TEMPSTATE_NEW_CSUM || | 974 | (*it).tempSyncStat() == SYNC_TEMPSTATE_NEW_CSUM || |
958 | (*it).tempSyncStat() == SYNC_TEMPSTATE_ADDED_EXTERNAL) { | 975 | (*it).tempSyncStat() == SYNC_TEMPSTATE_ADDED_EXTERNAL) { |
959 | Addressee ad = aBook->findByUid( ( (*it).uid() )); | 976 | Addressee ad = aBook->findByUid( ( (*it).uid() )); |
960 | if ( ad.isEmpty() ) { | 977 | if ( ad.isEmpty() ) { |
961 | ++foundEmpty; | 978 | ++foundEmpty; |
962 | //qDebug("postExternSync:addressee is empty: %s ", (*it).uid().latin1()); | 979 | //qDebug("postExternSync:addressee is empty: %s ", (*it).uid().latin1()); |
963 | //qDebug("-- formatted name %s ",(*it).formattedName().latin1() ); | 980 | //qDebug("-- formatted name %s ",(*it).formattedName().latin1() ); |
964 | } else { | 981 | } else { |
965 | (*it).setIDStr(":"); | 982 | (*it).setIDStr(":"); |
966 | if ( setID ) { | 983 | if ( setID ) { |
967 | if ( (*it).tempSyncStat() == SYNC_TEMPSTATE_NEW_ID ) | 984 | if ( (*it).tempSyncStat() == SYNC_TEMPSTATE_NEW_ID ) |
968 | ad.setID( csd, (*it).externalUID() ); | 985 | ad.setID( csd, (*it).externalUID() );{ |
986 | } | ||
969 | } else | 987 | } else |
970 | ad.setID( csd, (*it).uid() ); | 988 | ad.setID( csd, (*it).uid() ); |
971 | (*it).computeCsum( csd ); | 989 | (*it).computeCsum( csd ); |
972 | ad.setCsum( csd, (*it).getCsum( csd ) ); | 990 | ad.setCsum( csd, (*it).getCsum( csd ) ); |
973 | //qDebug("CSUM %s ",(*it).getCsum( csd ).latin1() ); | 991 | //qDebug("CSUM %s ",(*it).getCsum( csd ).latin1() ); |
974 | aBook->insertAddressee( ad , false); | 992 | aBook->insertAddressee( ad , false); |
975 | } | 993 | } |
976 | } | 994 | } |
977 | } | 995 | } |
978 | if ( foundEmpty ) { | 996 | if ( foundEmpty ) { |
979 | qDebug("postExternSync:%d empty addressees found:\n probably filtered out by incoming sync filter.",foundEmpty ); | 997 | qDebug("postExternSync:%d empty addressees found:\n probably filtered out by incoming sync filter.",foundEmpty ); |
980 | } | 998 | } |
981 | 999 | ||
982 | } | 1000 | } |
983 | 1001 | ||
984 | bool AddressBook::containsExternalUid( const QString& uid ) | 1002 | bool AddressBook::containsExternalUid( const QString& uid ) |
985 | { | 1003 | { |
986 | Iterator it; | 1004 | Iterator it; |
987 | for ( it = begin(); it != end(); ++it ) { | 1005 | for ( it = begin(); it != end(); ++it ) { |
988 | if ( uid == (*it).externalUID( ) ) | 1006 | if ( uid == (*it).externalUID( ) ) |
989 | return true; | 1007 | return true; |
990 | } | 1008 | } |
991 | return false; | 1009 | return false; |
992 | } | 1010 | } |
993 | const Addressee AddressBook::findByExternUid( const QString& uid , const QString& profile ) const | 1011 | const Addressee AddressBook::findByExternUid( const QString& uid , const QString& profile ) const |
994 | { | 1012 | { |
995 | ConstIterator it; | 1013 | ConstIterator it; |
996 | for ( it = begin(); it != end(); ++it ) { | 1014 | for ( it = begin(); it != end(); ++it ) { |
997 | if ( uid == (*it).getID( profile ) ) | 1015 | if ( uid == (*it).getID( profile ) ) |
998 | return (*it); | 1016 | return (*it); |
999 | } | 1017 | } |
1000 | return Addressee(); | 1018 | return Addressee(); |
1001 | } | 1019 | } |
1002 | void AddressBook::mergeAB( AddressBook *aBook, const QString& profile , bool isSubset ) | 1020 | void AddressBook::mergeAB( AddressBook *aBook, const QString& profile , bool isSubset ) |
1003 | { | 1021 | { |
1004 | Iterator it; | 1022 | Iterator it; |
1005 | Addressee ad; | 1023 | Addressee ad; |
1006 | for ( it = begin(); it != end(); ++it ) { | 1024 | for ( it = begin(); it != end(); ++it ) { |
1007 | ad = aBook->findByExternUid( (*it).externalUID(), profile ); | 1025 | ad = aBook->findByExternUid( (*it).externalUID(), profile ); |
1008 | if ( !ad.isEmpty() ) { | 1026 | if ( !ad.isEmpty() ) { |
1009 | (*it).mergeContact( ad ,isSubset); | 1027 | (*it).mergeContact( ad ,isSubset); |
1010 | } | 1028 | } |
1011 | } | 1029 | } |
1012 | #if 0 | 1030 | #if 0 |
1013 | // test only | 1031 | // test only |
1014 | for ( it = begin(); it != end(); ++it ) { | 1032 | for ( it = begin(); it != end(); ++it ) { |
1015 | 1033 | ||
1016 | qDebug("uid %s ", (*it).uid().latin1()); | 1034 | qDebug("uid %s ", (*it).uid().latin1()); |
1017 | } | 1035 | } |
1018 | #endif | 1036 | #endif |
1019 | } | 1037 | } |
1020 | 1038 | ||
1021 | #if 0 | 1039 | #if 0 |
1022 | Addressee::List AddressBook::getExternLastSyncAddressees() | 1040 | Addressee::List AddressBook::getExternLastSyncAddressees() |
1023 | { | 1041 | { |
1024 | Addressee::List results; | 1042 | Addressee::List results; |
1025 | 1043 | ||
1026 | Iterator it; | 1044 | Iterator it; |
1027 | for ( it = begin(); it != end(); ++it ) { | 1045 | for ( it = begin(); it != end(); ++it ) { |
1028 | if ( (*it).uid().left( 19 ) == "last-syncAddressee-" ) { | 1046 | if ( (*it).uid().left( 19 ) == "last-syncAddressee-" ) { |
1029 | if ( (*it).familyName().left(4) == "!E: " ) | 1047 | if ( (*it).familyName().left(4) == "!E: " ) |
1030 | results.append( *it ); | 1048 | results.append( *it ); |
1031 | } | 1049 | } |
1032 | } | 1050 | } |
1033 | 1051 | ||
1034 | return results; | 1052 | return results; |
1035 | } | 1053 | } |
1036 | #endif | 1054 | #endif |
1037 | void AddressBook::resetTempSyncStat() | 1055 | void AddressBook::resetTempSyncStat() |
1038 | { | 1056 | { |
1039 | Iterator it; | 1057 | Iterator it; |
1040 | for ( it = begin(); it != end(); ++it ) { | 1058 | for ( it = begin(); it != end(); ++it ) { |
1041 | (*it).setTempSyncStat ( SYNC_TEMPSTATE_INITIAL ); | 1059 | (*it).setTempSyncStat ( SYNC_TEMPSTATE_INITIAL ); |
1042 | } | 1060 | } |
1043 | 1061 | ||
1044 | } | 1062 | } |
1045 | 1063 | ||
1046 | QStringList AddressBook:: uidList() | 1064 | QStringList AddressBook:: uidList() |
1047 | { | 1065 | { |
1048 | QStringList results; | 1066 | QStringList results; |
1049 | Iterator it; | 1067 | Iterator it; |
1050 | for ( it = begin(); it != end(); ++it ) { | 1068 | for ( it = begin(); it != end(); ++it ) { |
1051 | results.append( (*it).uid() ); | 1069 | results.append( (*it).uid() ); |
1052 | } | 1070 | } |
1053 | return results; | 1071 | return results; |
1054 | } | 1072 | } |
1055 | 1073 | ||
1056 | 1074 | ||
1057 | Addressee::List AddressBook::allAddressees() | 1075 | Addressee::List AddressBook::allAddressees() |
1058 | { | 1076 | { |
1059 | return d->mAddressees; | 1077 | return d->mAddressees; |
1060 | 1078 | ||
1061 | } | 1079 | } |
1062 | 1080 | ||
1063 | Addressee::List AddressBook::findByName( const QString &name ) | 1081 | Addressee::List AddressBook::findByName( const QString &name ) |
1064 | { | 1082 | { |
1065 | Addressee::List results; | 1083 | Addressee::List results; |
1066 | 1084 | ||
1067 | Iterator it; | 1085 | Iterator it; |
1068 | for ( it = begin(); it != end(); ++it ) { | 1086 | for ( it = begin(); it != end(); ++it ) { |
1069 | if ( name == (*it).realName() ) { | 1087 | if ( name == (*it).realName() ) { |
1070 | results.append( *it ); | 1088 | results.append( *it ); |
1071 | } | 1089 | } |
1072 | } | 1090 | } |
1073 | 1091 | ||
1074 | return results; | 1092 | return results; |
1075 | } | 1093 | } |
1076 | 1094 | ||
1077 | Addressee::List AddressBook::findByEmail( const QString &email ) | 1095 | Addressee::List AddressBook::findByEmail( const QString &email ) |
1078 | { | 1096 | { |
1079 | Addressee::List results; | 1097 | Addressee::List results; |
1080 | QStringList mailList; | 1098 | QStringList mailList; |
1081 | 1099 | ||
1082 | Iterator it; | 1100 | Iterator it; |
1083 | for ( it = begin(); it != end(); ++it ) { | 1101 | for ( it = begin(); it != end(); ++it ) { |
1084 | mailList = (*it).emails(); | 1102 | mailList = (*it).emails(); |
1085 | for ( QStringList::Iterator ite = mailList.begin(); ite != mailList.end(); ++ite ) { | 1103 | for ( QStringList::Iterator ite = mailList.begin(); ite != mailList.end(); ++ite ) { |
1086 | if ( email == (*ite) ) { | 1104 | if ( email == (*ite) ) { |
1087 | results.append( *it ); | 1105 | results.append( *it ); |
1088 | } | 1106 | } |
1089 | } | 1107 | } |
1090 | } | 1108 | } |
1091 | 1109 | ||
1092 | return results; | 1110 | return results; |
1093 | } | 1111 | } |
1094 | 1112 | ||
1095 | Addressee::List AddressBook::findByCategory( const QString &category ) | 1113 | Addressee::List AddressBook::findByCategory( const QString &category ) |
1096 | { | 1114 | { |
1097 | Addressee::List results; | 1115 | Addressee::List results; |
1098 | 1116 | ||
1099 | Iterator it; | 1117 | Iterator it; |
1100 | for ( it = begin(); it != end(); ++it ) { | 1118 | for ( it = begin(); it != end(); ++it ) { |
1101 | if ( (*it).hasCategory( category) ) { | 1119 | if ( (*it).hasCategory( category) ) { |
1102 | results.append( *it ); | 1120 | results.append( *it ); |
1103 | } | 1121 | } |
1104 | } | 1122 | } |
1105 | 1123 | ||
1106 | return results; | 1124 | return results; |
1107 | } | 1125 | } |
1108 | 1126 | ||
1109 | void AddressBook::dump() const | 1127 | void AddressBook::dump() const |
1110 | { | 1128 | { |
1111 | kdDebug(5700) << "AddressBook::dump() --- begin ---" << endl; | 1129 | kdDebug(5700) << "AddressBook::dump() --- begin ---" << endl; |
1112 | 1130 | ||
1113 | ConstIterator it; | 1131 | ConstIterator it; |
1114 | for( it = begin(); it != end(); ++it ) { | 1132 | for( it = begin(); it != end(); ++it ) { |
1115 | (*it).dump(); | 1133 | (*it).dump(); |
1116 | } | 1134 | } |
1117 | 1135 | ||
1118 | kdDebug(5700) << "AddressBook::dump() --- end ---" << endl; | 1136 | kdDebug(5700) << "AddressBook::dump() --- end ---" << endl; |
1119 | } | 1137 | } |
1120 | 1138 | ||
1121 | QString AddressBook::identifier() | 1139 | QString AddressBook::identifier() |
1122 | { | 1140 | { |
1123 | QStringList identifier; | 1141 | QStringList identifier; |
1124 | 1142 | ||
1125 | 1143 | ||
1126 | KRES::Manager<Resource>::ActiveIterator it; | 1144 | KRES::Manager<Resource>::ActiveIterator it; |
1127 | for ( it = d->mManager->activeBegin(); it != d->mManager->activeEnd(); ++it ) { | 1145 | for ( it = d->mManager->activeBegin(); it != d->mManager->activeEnd(); ++it ) { |
1128 | if ( !(*it)->identifier().isEmpty() ) | 1146 | if ( !(*it)->identifier().isEmpty() ) |
1129 | identifier.append( (*it)->identifier() ); | 1147 | identifier.append( (*it)->identifier() ); |
1130 | } | 1148 | } |
1131 | 1149 | ||
1132 | return identifier.join( ":" ); | 1150 | return identifier.join( ":" ); |
1133 | } | 1151 | } |
1134 | 1152 | ||
1135 | Field::List AddressBook::fields( int category ) | 1153 | Field::List AddressBook::fields( int category ) |
1136 | { | 1154 | { |
1137 | if ( d->mAllFields.isEmpty() ) { | 1155 | if ( d->mAllFields.isEmpty() ) { |
1138 | d->mAllFields = Field::allFields(); | 1156 | d->mAllFields = Field::allFields(); |
1139 | } | 1157 | } |
1140 | 1158 | ||
1141 | if ( category == Field::All ) return d->mAllFields; | 1159 | if ( category == Field::All ) return d->mAllFields; |
1142 | 1160 | ||
1143 | Field::List result; | 1161 | Field::List result; |
1144 | Field::List::ConstIterator it; | 1162 | Field::List::ConstIterator it; |
1145 | for( it = d->mAllFields.begin(); it != d->mAllFields.end(); ++it ) { | 1163 | for( it = d->mAllFields.begin(); it != d->mAllFields.end(); ++it ) { |
1146 | if ( (*it)->category() & category ) result.append( *it ); | 1164 | if ( (*it)->category() & category ) result.append( *it ); |
1147 | } | 1165 | } |
1148 | 1166 | ||
1149 | return result; | 1167 | return result; |
1150 | } | 1168 | } |
1151 | 1169 | ||
1152 | bool AddressBook::addCustomField( const QString &label, int category, | 1170 | bool AddressBook::addCustomField( const QString &label, int category, |
1153 | const QString &key, const QString &app ) | 1171 | const QString &key, const QString &app ) |
1154 | { | 1172 | { |
1155 | if ( d->mAllFields.isEmpty() ) { | 1173 | if ( d->mAllFields.isEmpty() ) { |
1156 | d->mAllFields = Field::allFields(); | 1174 | d->mAllFields = Field::allFields(); |
1157 | } | 1175 | } |
1158 | //US QString a = app.isNull() ? KGlobal::instance()->instanceName() : app; | 1176 | //US QString a = app.isNull() ? KGlobal::instance()->instanceName() : app; |
1159 | QString a = app.isNull() ? KGlobal::getAppName() : app; | 1177 | QString a = app.isNull() ? KGlobal::getAppName() : app; |
1160 | 1178 | ||
1161 | QString k = key.isNull() ? label : key; | 1179 | QString k = key.isNull() ? label : key; |
1162 | 1180 | ||
1163 | Field *field = Field::createCustomField( label, category, k, a ); | 1181 | Field *field = Field::createCustomField( label, category, k, a ); |
1164 | 1182 | ||
1165 | if ( !field ) return false; | 1183 | if ( !field ) return false; |
1166 | 1184 | ||
1167 | d->mAllFields.append( field ); | 1185 | d->mAllFields.append( field ); |
1168 | 1186 | ||
1169 | return true; | 1187 | return true; |
1170 | } | 1188 | } |
1171 | 1189 | ||
1172 | QDataStream &KABC::operator<<( QDataStream &s, const AddressBook &ab ) | 1190 | QDataStream &KABC::operator<<( QDataStream &s, const AddressBook &ab ) |
1173 | { | 1191 | { |
1174 | if (!ab.d) return s; | 1192 | if (!ab.d) return s; |
1175 | 1193 | ||
1176 | return s << ab.d->mAddressees; | 1194 | return s << ab.d->mAddressees; |
1177 | } | 1195 | } |
1178 | 1196 | ||
1179 | QDataStream &KABC::operator>>( QDataStream &s, AddressBook &ab ) | 1197 | QDataStream &KABC::operator>>( QDataStream &s, AddressBook &ab ) |
1180 | { | 1198 | { |
1181 | if (!ab.d) return s; | 1199 | if (!ab.d) return s; |
1182 | 1200 | ||
1183 | s >> ab.d->mAddressees; | 1201 | s >> ab.d->mAddressees; |
1184 | 1202 | ||
1185 | return s; | 1203 | return s; |
1186 | } | 1204 | } |
1187 | 1205 | ||
1188 | bool AddressBook::addResource( Resource *resource ) | 1206 | bool AddressBook::addResource( Resource *resource ) |
1189 | { | 1207 | { |
1190 | if ( !resource->open() ) { | 1208 | if ( !resource->open() ) { |
1191 | kdDebug(5700) << "AddressBook::addResource(): can't add resource" << endl; | 1209 | kdDebug(5700) << "AddressBook::addResource(): can't add resource" << endl; |
1192 | return false; | 1210 | return false; |
1193 | } | 1211 | } |
1194 | 1212 | ||
1195 | resource->setAddressBook( this ); | 1213 | resource->setAddressBook( this ); |
1196 | 1214 | ||
1197 | d->mManager->add( resource ); | 1215 | d->mManager->add( resource ); |
1198 | return true; | 1216 | return true; |
1199 | } | 1217 | } |
1200 | void AddressBook::removeResources() | 1218 | void AddressBook::removeResources() |
1201 | { | 1219 | { |
1202 | //remove all possible resources. This should cleanup the configfile. | 1220 | //remove all possible resources. This should cleanup the configfile. |
1203 | QPtrList<KABC::Resource> mResources = resources(); | 1221 | QPtrList<KABC::Resource> mResources = resources(); |
1204 | 1222 | ||
1205 | QPtrListIterator<KABC::Resource> it(mResources); | 1223 | QPtrListIterator<KABC::Resource> it(mResources); |
1206 | for ( ; it.current(); ++it ) { | 1224 | for ( ; it.current(); ++it ) { |
1207 | KABC::Resource *res = it.current(); | 1225 | KABC::Resource *res = it.current(); |
1208 | removeResource(res); | 1226 | removeResource(res); |
1209 | } | 1227 | } |
1210 | } | 1228 | } |
1211 | 1229 | ||
1212 | bool AddressBook::removeResource( Resource *resource ) | 1230 | bool AddressBook::removeResource( Resource *resource ) |
1213 | { | 1231 | { |
1214 | resource->close(); | 1232 | resource->close(); |
1215 | 1233 | ||
1216 | if ( resource == standardResource() ) | 1234 | if ( resource == standardResource() ) |
1217 | d->mManager->setStandardResource( 0 ); | 1235 | d->mManager->setStandardResource( 0 ); |
1218 | 1236 | ||
1219 | resource->setAddressBook( 0 ); | 1237 | resource->setAddressBook( 0 ); |
1220 | 1238 | ||
1221 | d->mManager->remove( resource ); | 1239 | d->mManager->remove( resource ); |
1222 | return true; | 1240 | return true; |
1223 | } | 1241 | } |
1224 | 1242 | ||