-rw-r--r-- | kabc/addressbook.cpp | 8 |
1 files changed, 4 insertions, 4 deletions
diff --git a/kabc/addressbook.cpp b/kabc/addressbook.cpp index 19c26eb..8882259 100644 --- a/kabc/addressbook.cpp +++ b/kabc/addressbook.cpp | |||
@@ -674,442 +674,442 @@ AddressBook::ConstIterator AddressBook::begin() const | |||
674 | it.d->mIt = d->mAddressees.begin(); | 674 | it.d->mIt = d->mAddressees.begin(); |
675 | return it; | 675 | return it; |
676 | } | 676 | } |
677 | 677 | ||
678 | AddressBook::Iterator AddressBook::end() | 678 | AddressBook::Iterator AddressBook::end() |
679 | { | 679 | { |
680 | Iterator it = Iterator(); | 680 | Iterator it = Iterator(); |
681 | it.d->mIt = d->mAddressees.end(); | 681 | it.d->mIt = d->mAddressees.end(); |
682 | return it; | 682 | return it; |
683 | } | 683 | } |
684 | 684 | ||
685 | AddressBook::ConstIterator AddressBook::end() const | 685 | AddressBook::ConstIterator AddressBook::end() const |
686 | { | 686 | { |
687 | ConstIterator it = ConstIterator(); | 687 | ConstIterator it = ConstIterator(); |
688 | it.d->mIt = d->mAddressees.end(); | 688 | it.d->mIt = d->mAddressees.end(); |
689 | return it; | 689 | return it; |
690 | } | 690 | } |
691 | 691 | ||
692 | void AddressBook::clear() | 692 | void AddressBook::clear() |
693 | { | 693 | { |
694 | d->mAddressees.clear(); | 694 | d->mAddressees.clear(); |
695 | } | 695 | } |
696 | 696 | ||
697 | Ticket *AddressBook::requestSaveTicket( Resource *resource ) | 697 | Ticket *AddressBook::requestSaveTicket( Resource *resource ) |
698 | { | 698 | { |
699 | kdDebug(5700) << "AddressBook::requestSaveTicket()" << endl; | 699 | kdDebug(5700) << "AddressBook::requestSaveTicket()" << endl; |
700 | 700 | ||
701 | if ( !resource ) | 701 | if ( !resource ) |
702 | { | 702 | { |
703 | qDebug("AddressBook::requestSaveTicket no resource" ); | 703 | qDebug("AddressBook::requestSaveTicket no resource" ); |
704 | resource = standardResource(); | 704 | resource = standardResource(); |
705 | } | 705 | } |
706 | 706 | ||
707 | KRES::Manager<Resource>::ActiveIterator it; | 707 | KRES::Manager<Resource>::ActiveIterator it; |
708 | for ( it = d->mManager->activeBegin(); it != d->mManager->activeEnd(); ++it ) { | 708 | for ( it = d->mManager->activeBegin(); it != d->mManager->activeEnd(); ++it ) { |
709 | if ( (*it) == resource ) { | 709 | if ( (*it) == resource ) { |
710 | if ( (*it)->readOnly() || !(*it)->isOpen() ) | 710 | if ( (*it)->readOnly() || !(*it)->isOpen() ) |
711 | return 0; | 711 | return 0; |
712 | else | 712 | else |
713 | return (*it)->requestSaveTicket(); | 713 | return (*it)->requestSaveTicket(); |
714 | } | 714 | } |
715 | } | 715 | } |
716 | 716 | ||
717 | return 0; | 717 | return 0; |
718 | } | 718 | } |
719 | //void insertAddressee( const Addressee &, bool setRev = true, bool takeResource = false); | 719 | //void insertAddressee( const Addressee &, bool setRev = true, bool takeResource = false); |
720 | void AddressBook::insertAddressee( const Addressee &a, bool setRev, bool takeResource ) | 720 | void AddressBook::insertAddressee( const Addressee &a, bool setRev, bool takeResource ) |
721 | { | 721 | { |
722 | if ( blockLSEchange && setRev && a.uid().left( 19 ) == QString("last-syncAddressee-") ) { | 722 | if ( blockLSEchange && setRev && a.uid().left( 19 ) == QString("last-syncAddressee-") ) { |
723 | //qDebug("block insert "); | 723 | //qDebug("block insert "); |
724 | return; | 724 | return; |
725 | } | 725 | } |
726 | //qDebug("inserting.... %s ",a.uid().latin1() ); | 726 | //qDebug("inserting.... %s ",a.uid().latin1() ); |
727 | bool found = false; | 727 | bool found = false; |
728 | Addressee::List::Iterator it; | 728 | Addressee::List::Iterator it; |
729 | for ( it = d->mAddressees.begin(); it != d->mAddressees.end(); ++it ) { | 729 | for ( it = d->mAddressees.begin(); it != d->mAddressees.end(); ++it ) { |
730 | if ( a.uid() == (*it).uid() ) { | 730 | if ( a.uid() == (*it).uid() ) { |
731 | 731 | ||
732 | bool changed = false; | 732 | bool changed = false; |
733 | Addressee addr = a; | 733 | Addressee addr = a; |
734 | if ( addr != (*it) ) | 734 | if ( addr != (*it) ) |
735 | changed = true; | 735 | changed = true; |
736 | 736 | ||
737 | if ( takeResource ) { | 737 | if ( takeResource ) { |
738 | Resource * res = (*it).resource(); | 738 | Resource * res = (*it).resource(); |
739 | (*it) = a; | 739 | (*it) = a; |
740 | (*it).setResource( res ); | 740 | (*it).setResource( res ); |
741 | } else { | 741 | } else { |
742 | (*it) = a; | 742 | (*it) = a; |
743 | if ( (*it).resource() == 0 ) | 743 | if ( (*it).resource() == 0 ) |
744 | (*it).setResource( standardResource() ); | 744 | (*it).setResource( standardResource() ); |
745 | } | 745 | } |
746 | if ( changed ) { | 746 | if ( changed ) { |
747 | if ( setRev ) { | 747 | if ( setRev ) { |
748 | 748 | ||
749 | // get rid of micro seconds | 749 | // get rid of micro seconds |
750 | QDateTime dt = QDateTime::currentDateTime(); | 750 | QDateTime dt = QDateTime::currentDateTime(); |
751 | QTime t = dt.time(); | 751 | QTime t = dt.time(); |
752 | dt.setTime( QTime (t.hour (), t.minute (), t.second () ) ); | 752 | dt.setTime( QTime (t.hour (), t.minute (), t.second () ) ); |
753 | (*it).setRevision( dt ); | 753 | (*it).setRevision( dt ); |
754 | } | 754 | } |
755 | (*it).setChanged( true ); | 755 | (*it).setChanged( true ); |
756 | } | 756 | } |
757 | 757 | ||
758 | found = true; | 758 | found = true; |
759 | } else { | 759 | } else { |
760 | if ( (*it).uid().left( 19 ) == QString("last-syncAddressee-") ) { | 760 | if ( (*it).uid().left( 19 ) == QString("last-syncAddressee-") ) { |
761 | QString name = (*it).uid().mid( 19 ); | 761 | QString name = (*it).uid().mid( 19 ); |
762 | Addressee b = a; | 762 | Addressee b = a; |
763 | QString id = b.getID( name ); | 763 | QString id = b.getID( name ); |
764 | if ( ! id.isEmpty() ) { | 764 | if ( ! id.isEmpty() ) { |
765 | QString des = (*it).note(); | 765 | QString des = (*it).note(); |
766 | int startN; | 766 | int startN; |
767 | if( (startN = des.find( id ) ) >= 0 ) { | 767 | if( (startN = des.find( id ) ) >= 0 ) { |
768 | int endN = des.find( ",", startN+1 ); | 768 | int endN = des.find( ",", startN+1 ); |
769 | des = des.left( startN ) + des.mid( endN+1 ); | 769 | des = des.left( startN ) + des.mid( endN+1 ); |
770 | (*it).setNote( des ); | 770 | (*it).setNote( des ); |
771 | } | 771 | } |
772 | } | 772 | } |
773 | } | 773 | } |
774 | } | 774 | } |
775 | } | 775 | } |
776 | if ( found ) | 776 | if ( found ) |
777 | return; | 777 | return; |
778 | d->mAddressees.append( a ); | 778 | d->mAddressees.append( a ); |
779 | Addressee& addr = d->mAddressees.last(); | 779 | Addressee& addr = d->mAddressees.last(); |
780 | if ( addr.resource() == 0 ) | 780 | if ( addr.resource() == 0 ) |
781 | addr.setResource( standardResource() ); | 781 | addr.setResource( standardResource() ); |
782 | 782 | ||
783 | addr.setChanged( true ); | 783 | addr.setChanged( true ); |
784 | } | 784 | } |
785 | 785 | ||
786 | void AddressBook::removeAddressee( const Addressee &a ) | 786 | void AddressBook::removeAddressee( const Addressee &a ) |
787 | { | 787 | { |
788 | Iterator it; | 788 | Iterator it; |
789 | Iterator it2; | 789 | Iterator it2; |
790 | bool found = false; | 790 | bool found = false; |
791 | for ( it = begin(); it != end(); ++it ) { | 791 | for ( it = begin(); it != end(); ++it ) { |
792 | if ( a.uid() == (*it).uid() ) { | 792 | if ( a.uid() == (*it).uid() ) { |
793 | found = true; | 793 | found = true; |
794 | it2 = it; | 794 | it2 = it; |
795 | } else { | 795 | } else { |
796 | if ( (*it).uid().left( 19 ) == QString("last-syncAddressee-") ) { | 796 | if ( (*it).uid().left( 19 ) == QString("last-syncAddressee-") ) { |
797 | QString name = (*it).uid().mid( 19 ); | 797 | QString name = (*it).uid().mid( 19 ); |
798 | Addressee b = a; | 798 | Addressee b = a; |
799 | QString id = b.getID( name ); | 799 | QString id = b.getID( name ); |
800 | if ( ! id.isEmpty() ) { | 800 | if ( ! id.isEmpty() ) { |
801 | QString des = (*it).note(); | 801 | QString des = (*it).note(); |
802 | if( des.find( id ) < 0 ) { | 802 | if( des.find( id ) < 0 ) { |
803 | des += id + ","; | 803 | des += id + ","; |
804 | (*it).setNote( des ); | 804 | (*it).setNote( des ); |
805 | } | 805 | } |
806 | } | 806 | } |
807 | } | 807 | } |
808 | 808 | ||
809 | } | 809 | } |
810 | } | 810 | } |
811 | 811 | ||
812 | if ( found ) | 812 | if ( found ) |
813 | removeAddressee( it2 ); | 813 | removeAddressee( it2 ); |
814 | 814 | ||
815 | } | 815 | } |
816 | 816 | ||
817 | void AddressBook::removeSyncAddressees( bool removeDeleted ) | 817 | void AddressBook::removeSyncAddressees( bool removeDeleted ) |
818 | { | 818 | { |
819 | Iterator it = begin(); | 819 | Iterator it = begin(); |
820 | Iterator it2 ; | 820 | Iterator it2 ; |
821 | QDateTime dt ( QDate( 2004,1,1) ); | 821 | QDateTime dt ( QDate( 2004,1,1) ); |
822 | while ( it != end() ) { | 822 | while ( it != end() ) { |
823 | (*it).setRevision( dt ); | 823 | (*it).setRevision( dt ); |
824 | (*it).removeCustom( "KADDRESSBOOK", "X-ExternalID" ); | 824 | (*it).removeCustom( "KADDRESSBOOK", "X-ExternalID" ); |
825 | (*it).setIDStr(""); | 825 | (*it).setIDStr(""); |
826 | if ( ( (*it).tempSyncStat() == SYNC_TEMPSTATE_DELETE && removeDeleted )|| (*it).uid().left( 19 ) == QString("last-syncAddressee-")) { | 826 | if ( ( (*it).tempSyncStat() == SYNC_TEMPSTATE_DELETE && removeDeleted )|| (*it).uid().left( 19 ) == QString("last-syncAddressee-")) { |
827 | it2 = it; | 827 | it2 = it; |
828 | //qDebug("removing %s ",(*it).uid().latin1() ); | 828 | //qDebug("removing %s ",(*it).uid().latin1() ); |
829 | ++it; | 829 | ++it; |
830 | removeAddressee( it2 ); | 830 | removeAddressee( it2 ); |
831 | } else { | 831 | } else { |
832 | //qDebug("skipping %s ",(*it).uid().latin1() ); | 832 | //qDebug("skipping %s ",(*it).uid().latin1() ); |
833 | ++it; | 833 | ++it; |
834 | } | 834 | } |
835 | } | 835 | } |
836 | deleteRemovedAddressees(); | 836 | deleteRemovedAddressees(); |
837 | } | 837 | } |
838 | 838 | ||
839 | void AddressBook::removeAddressee( const Iterator &it ) | 839 | void AddressBook::removeAddressee( const Iterator &it ) |
840 | { | 840 | { |
841 | d->mRemovedAddressees.append( (*it) ); | 841 | d->mRemovedAddressees.append( (*it) ); |
842 | d->mAddressees.remove( it.d->mIt ); | 842 | d->mAddressees.remove( it.d->mIt ); |
843 | } | 843 | } |
844 | 844 | ||
845 | AddressBook::Iterator AddressBook::find( const Addressee &a ) | 845 | AddressBook::Iterator AddressBook::find( const Addressee &a ) |
846 | { | 846 | { |
847 | Iterator it; | 847 | Iterator it; |
848 | for ( it = begin(); it != end(); ++it ) { | 848 | for ( it = begin(); it != end(); ++it ) { |
849 | if ( a.uid() == (*it).uid() ) { | 849 | if ( a.uid() == (*it).uid() ) { |
850 | return it; | 850 | return it; |
851 | } | 851 | } |
852 | } | 852 | } |
853 | return end(); | 853 | return end(); |
854 | } | 854 | } |
855 | 855 | ||
856 | Addressee AddressBook::findByUid( const QString &uid ) | 856 | Addressee AddressBook::findByUid( const QString &uid ) |
857 | { | 857 | { |
858 | Iterator it; | 858 | Iterator it; |
859 | for ( it = begin(); it != end(); ++it ) { | 859 | for ( it = begin(); it != end(); ++it ) { |
860 | if ( uid == (*it).uid() ) { | 860 | if ( uid == (*it).uid() ) { |
861 | return *it; | 861 | return *it; |
862 | } | 862 | } |
863 | } | 863 | } |
864 | return Addressee(); | 864 | return Addressee(); |
865 | } | 865 | } |
866 | void AddressBook::preExternSync( AddressBook* aBook, const QString& csd ) | 866 | void AddressBook::preExternSync( AddressBook* aBook, const QString& csd , bool isSubset ) |
867 | { | 867 | { |
868 | //qDebug("AddressBook::preExternSync "); | 868 | //qDebug("AddressBook::preExternSync "); |
869 | AddressBook::Iterator it; | 869 | AddressBook::Iterator it; |
870 | for ( it = begin(); it != end(); ++it ) { | 870 | for ( it = begin(); it != end(); ++it ) { |
871 | (*it).setID( csd, (*it).externalUID() ); | 871 | (*it).setID( csd, (*it).externalUID() ); |
872 | (*it).computeCsum( csd ); | 872 | (*it).computeCsum( csd ); |
873 | } | 873 | } |
874 | mergeAB( aBook ,csd ); | 874 | mergeAB( aBook ,csd, isSubset ); |
875 | } | 875 | } |
876 | void AddressBook::postExternSync( AddressBook* aBook , const QString& csd) | 876 | void AddressBook::postExternSync( AddressBook* aBook , const QString& csd) |
877 | { | 877 | { |
878 | //qDebug("AddressBook::postExternSync "); | 878 | //qDebug("AddressBook::postExternSync "); |
879 | AddressBook::Iterator it; | 879 | AddressBook::Iterator it; |
880 | for ( it = begin(); it != end(); ++it ) { | 880 | for ( it = begin(); it != end(); ++it ) { |
881 | // qDebug("check uid %s ", (*it).uid().latin1() ); | 881 | // qDebug("check uid %s ", (*it).uid().latin1() ); |
882 | if ( (*it).tempSyncStat() == SYNC_TEMPSTATE_NEW_ID || | 882 | if ( (*it).tempSyncStat() == SYNC_TEMPSTATE_NEW_ID || |
883 | (*it).tempSyncStat() == SYNC_TEMPSTATE_NEW_CSUM ) { | 883 | (*it).tempSyncStat() == SYNC_TEMPSTATE_NEW_CSUM ) { |
884 | Addressee ad = aBook->findByUid( ( (*it).uid() )); | 884 | Addressee ad = aBook->findByUid( ( (*it).uid() )); |
885 | if ( ad.isEmpty() ) { | 885 | if ( ad.isEmpty() ) { |
886 | qDebug("postExternSync:ERROR addressee is empty: %s ", (*it).uid().latin1()); | 886 | qDebug("postExternSync:ERROR addressee is empty: %s ", (*it).uid().latin1()); |
887 | } else { | 887 | } else { |
888 | (*it).computeCsum( csd ); | 888 | (*it).computeCsum( csd ); |
889 | if ( (*it).tempSyncStat() == SYNC_TEMPSTATE_NEW_ID ) | 889 | if ( (*it).tempSyncStat() == SYNC_TEMPSTATE_NEW_ID ) |
890 | ad.setID( csd, (*it).externalUID() ); | 890 | ad.setID( csd, (*it).externalUID() ); |
891 | ad.setCsum( csd, (*it).getCsum( csd ) ); | 891 | ad.setCsum( csd, (*it).getCsum( csd ) ); |
892 | aBook->insertAddressee( ad ); | 892 | aBook->insertAddressee( ad ); |
893 | } | 893 | } |
894 | } | 894 | } |
895 | } | 895 | } |
896 | } | 896 | } |
897 | 897 | ||
898 | bool AddressBook::containsExternalUid( const QString& uid ) | 898 | bool AddressBook::containsExternalUid( const QString& uid ) |
899 | { | 899 | { |
900 | Iterator it; | 900 | Iterator it; |
901 | for ( it = begin(); it != end(); ++it ) { | 901 | for ( it = begin(); it != end(); ++it ) { |
902 | if ( uid == (*it).externalUID( ) ) | 902 | if ( uid == (*it).externalUID( ) ) |
903 | return true; | 903 | return true; |
904 | } | 904 | } |
905 | return false; | 905 | return false; |
906 | } | 906 | } |
907 | Addressee AddressBook::findByExternUid( const QString& uid , const QString& profile ) | 907 | Addressee AddressBook::findByExternUid( const QString& uid , const QString& profile ) |
908 | { | 908 | { |
909 | Iterator it; | 909 | Iterator it; |
910 | for ( it = begin(); it != end(); ++it ) { | 910 | for ( it = begin(); it != end(); ++it ) { |
911 | if ( uid == (*it).getID( profile ) ) | 911 | if ( uid == (*it).getID( profile ) ) |
912 | return (*it); | 912 | return (*it); |
913 | } | 913 | } |
914 | return Addressee(); | 914 | return Addressee(); |
915 | } | 915 | } |
916 | void AddressBook::mergeAB( AddressBook *aBook, const QString& profile ) | 916 | void AddressBook::mergeAB( AddressBook *aBook, const QString& profile , bool isSubset ) |
917 | { | 917 | { |
918 | Iterator it; | 918 | Iterator it; |
919 | Addressee ad; | 919 | Addressee ad; |
920 | for ( it = begin(); it != end(); ++it ) { | 920 | for ( it = begin(); it != end(); ++it ) { |
921 | ad = aBook->findByExternUid( (*it).externalUID(), profile ); | 921 | ad = aBook->findByExternUid( (*it).externalUID(), profile ); |
922 | if ( !ad.isEmpty() ) { | 922 | if ( !ad.isEmpty() ) { |
923 | (*it).mergeContact( ad ); | 923 | (*it).mergeContact( ad ,isSubset); |
924 | } | 924 | } |
925 | } | 925 | } |
926 | #if 0 | 926 | #if 0 |
927 | // test only | 927 | // test only |
928 | for ( it = begin(); it != end(); ++it ) { | 928 | for ( it = begin(); it != end(); ++it ) { |
929 | 929 | ||
930 | qDebug("uid %s ", (*it).uid().latin1()); | 930 | qDebug("uid %s ", (*it).uid().latin1()); |
931 | } | 931 | } |
932 | #endif | 932 | #endif |
933 | } | 933 | } |
934 | 934 | ||
935 | #if 0 | 935 | #if 0 |
936 | Addressee::List AddressBook::getExternLastSyncAddressees() | 936 | Addressee::List AddressBook::getExternLastSyncAddressees() |
937 | { | 937 | { |
938 | Addressee::List results; | 938 | Addressee::List results; |
939 | 939 | ||
940 | Iterator it; | 940 | Iterator it; |
941 | for ( it = begin(); it != end(); ++it ) { | 941 | for ( it = begin(); it != end(); ++it ) { |
942 | if ( (*it).uid().left( 19 ) == "last-syncAddressee-" ) { | 942 | if ( (*it).uid().left( 19 ) == "last-syncAddressee-" ) { |
943 | if ( (*it).familyName().left(4) == "!E: " ) | 943 | if ( (*it).familyName().left(4) == "!E: " ) |
944 | results.append( *it ); | 944 | results.append( *it ); |
945 | } | 945 | } |
946 | } | 946 | } |
947 | 947 | ||
948 | return results; | 948 | return results; |
949 | } | 949 | } |
950 | #endif | 950 | #endif |
951 | void AddressBook::resetTempSyncStat() | 951 | void AddressBook::resetTempSyncStat() |
952 | { | 952 | { |
953 | Iterator it; | 953 | Iterator it; |
954 | for ( it = begin(); it != end(); ++it ) { | 954 | for ( it = begin(); it != end(); ++it ) { |
955 | (*it).setTempSyncStat ( SYNC_TEMPSTATE_INITIAL ); | 955 | (*it).setTempSyncStat ( SYNC_TEMPSTATE_INITIAL ); |
956 | } | 956 | } |
957 | 957 | ||
958 | } | 958 | } |
959 | 959 | ||
960 | QStringList AddressBook:: uidList() | 960 | QStringList AddressBook:: uidList() |
961 | { | 961 | { |
962 | QStringList results; | 962 | QStringList results; |
963 | Iterator it; | 963 | Iterator it; |
964 | for ( it = begin(); it != end(); ++it ) { | 964 | for ( it = begin(); it != end(); ++it ) { |
965 | results.append( (*it).uid() ); | 965 | results.append( (*it).uid() ); |
966 | } | 966 | } |
967 | return results; | 967 | return results; |
968 | } | 968 | } |
969 | 969 | ||
970 | 970 | ||
971 | Addressee::List AddressBook::allAddressees() | 971 | Addressee::List AddressBook::allAddressees() |
972 | { | 972 | { |
973 | return d->mAddressees; | 973 | return d->mAddressees; |
974 | 974 | ||
975 | } | 975 | } |
976 | 976 | ||
977 | Addressee::List AddressBook::findByName( const QString &name ) | 977 | Addressee::List AddressBook::findByName( const QString &name ) |
978 | { | 978 | { |
979 | Addressee::List results; | 979 | Addressee::List results; |
980 | 980 | ||
981 | Iterator it; | 981 | Iterator it; |
982 | for ( it = begin(); it != end(); ++it ) { | 982 | for ( it = begin(); it != end(); ++it ) { |
983 | if ( name == (*it).realName() ) { | 983 | if ( name == (*it).realName() ) { |
984 | results.append( *it ); | 984 | results.append( *it ); |
985 | } | 985 | } |
986 | } | 986 | } |
987 | 987 | ||
988 | return results; | 988 | return results; |
989 | } | 989 | } |
990 | 990 | ||
991 | Addressee::List AddressBook::findByEmail( const QString &email ) | 991 | Addressee::List AddressBook::findByEmail( const QString &email ) |
992 | { | 992 | { |
993 | Addressee::List results; | 993 | Addressee::List results; |
994 | QStringList mailList; | 994 | QStringList mailList; |
995 | 995 | ||
996 | Iterator it; | 996 | Iterator it; |
997 | for ( it = begin(); it != end(); ++it ) { | 997 | for ( it = begin(); it != end(); ++it ) { |
998 | mailList = (*it).emails(); | 998 | mailList = (*it).emails(); |
999 | for ( QStringList::Iterator ite = mailList.begin(); ite != mailList.end(); ++ite ) { | 999 | for ( QStringList::Iterator ite = mailList.begin(); ite != mailList.end(); ++ite ) { |
1000 | if ( email == (*ite) ) { | 1000 | if ( email == (*ite) ) { |
1001 | results.append( *it ); | 1001 | results.append( *it ); |
1002 | } | 1002 | } |
1003 | } | 1003 | } |
1004 | } | 1004 | } |
1005 | 1005 | ||
1006 | return results; | 1006 | return results; |
1007 | } | 1007 | } |
1008 | 1008 | ||
1009 | Addressee::List AddressBook::findByCategory( const QString &category ) | 1009 | Addressee::List AddressBook::findByCategory( const QString &category ) |
1010 | { | 1010 | { |
1011 | Addressee::List results; | 1011 | Addressee::List results; |
1012 | 1012 | ||
1013 | Iterator it; | 1013 | Iterator it; |
1014 | for ( it = begin(); it != end(); ++it ) { | 1014 | for ( it = begin(); it != end(); ++it ) { |
1015 | if ( (*it).hasCategory( category) ) { | 1015 | if ( (*it).hasCategory( category) ) { |
1016 | results.append( *it ); | 1016 | results.append( *it ); |
1017 | } | 1017 | } |
1018 | } | 1018 | } |
1019 | 1019 | ||
1020 | return results; | 1020 | return results; |
1021 | } | 1021 | } |
1022 | 1022 | ||
1023 | void AddressBook::dump() const | 1023 | void AddressBook::dump() const |
1024 | { | 1024 | { |
1025 | kdDebug(5700) << "AddressBook::dump() --- begin ---" << endl; | 1025 | kdDebug(5700) << "AddressBook::dump() --- begin ---" << endl; |
1026 | 1026 | ||
1027 | ConstIterator it; | 1027 | ConstIterator it; |
1028 | for( it = begin(); it != end(); ++it ) { | 1028 | for( it = begin(); it != end(); ++it ) { |
1029 | (*it).dump(); | 1029 | (*it).dump(); |
1030 | } | 1030 | } |
1031 | 1031 | ||
1032 | kdDebug(5700) << "AddressBook::dump() --- end ---" << endl; | 1032 | kdDebug(5700) << "AddressBook::dump() --- end ---" << endl; |
1033 | } | 1033 | } |
1034 | 1034 | ||
1035 | QString AddressBook::identifier() | 1035 | QString AddressBook::identifier() |
1036 | { | 1036 | { |
1037 | QStringList identifier; | 1037 | QStringList identifier; |
1038 | 1038 | ||
1039 | 1039 | ||
1040 | KRES::Manager<Resource>::ActiveIterator it; | 1040 | KRES::Manager<Resource>::ActiveIterator it; |
1041 | for ( it = d->mManager->activeBegin(); it != d->mManager->activeEnd(); ++it ) { | 1041 | for ( it = d->mManager->activeBegin(); it != d->mManager->activeEnd(); ++it ) { |
1042 | if ( !(*it)->identifier().isEmpty() ) | 1042 | if ( !(*it)->identifier().isEmpty() ) |
1043 | identifier.append( (*it)->identifier() ); | 1043 | identifier.append( (*it)->identifier() ); |
1044 | } | 1044 | } |
1045 | 1045 | ||
1046 | return identifier.join( ":" ); | 1046 | return identifier.join( ":" ); |
1047 | } | 1047 | } |
1048 | 1048 | ||
1049 | Field::List AddressBook::fields( int category ) | 1049 | Field::List AddressBook::fields( int category ) |
1050 | { | 1050 | { |
1051 | if ( d->mAllFields.isEmpty() ) { | 1051 | if ( d->mAllFields.isEmpty() ) { |
1052 | d->mAllFields = Field::allFields(); | 1052 | d->mAllFields = Field::allFields(); |
1053 | } | 1053 | } |
1054 | 1054 | ||
1055 | if ( category == Field::All ) return d->mAllFields; | 1055 | if ( category == Field::All ) return d->mAllFields; |
1056 | 1056 | ||
1057 | Field::List result; | 1057 | Field::List result; |
1058 | Field::List::ConstIterator it; | 1058 | Field::List::ConstIterator it; |
1059 | for( it = d->mAllFields.begin(); it != d->mAllFields.end(); ++it ) { | 1059 | for( it = d->mAllFields.begin(); it != d->mAllFields.end(); ++it ) { |
1060 | if ( (*it)->category() & category ) result.append( *it ); | 1060 | if ( (*it)->category() & category ) result.append( *it ); |
1061 | } | 1061 | } |
1062 | 1062 | ||
1063 | return result; | 1063 | return result; |
1064 | } | 1064 | } |
1065 | 1065 | ||
1066 | bool AddressBook::addCustomField( const QString &label, int category, | 1066 | bool AddressBook::addCustomField( const QString &label, int category, |
1067 | const QString &key, const QString &app ) | 1067 | const QString &key, const QString &app ) |
1068 | { | 1068 | { |
1069 | if ( d->mAllFields.isEmpty() ) { | 1069 | if ( d->mAllFields.isEmpty() ) { |
1070 | d->mAllFields = Field::allFields(); | 1070 | d->mAllFields = Field::allFields(); |
1071 | } | 1071 | } |
1072 | //US QString a = app.isNull() ? KGlobal::instance()->instanceName() : app; | 1072 | //US QString a = app.isNull() ? KGlobal::instance()->instanceName() : app; |
1073 | QString a = app.isNull() ? KGlobal::getAppName() : app; | 1073 | QString a = app.isNull() ? KGlobal::getAppName() : app; |
1074 | 1074 | ||
1075 | QString k = key.isNull() ? label : key; | 1075 | QString k = key.isNull() ? label : key; |
1076 | 1076 | ||
1077 | Field *field = Field::createCustomField( label, category, k, a ); | 1077 | Field *field = Field::createCustomField( label, category, k, a ); |
1078 | 1078 | ||
1079 | if ( !field ) return false; | 1079 | if ( !field ) return false; |
1080 | 1080 | ||
1081 | d->mAllFields.append( field ); | 1081 | d->mAllFields.append( field ); |
1082 | 1082 | ||
1083 | return true; | 1083 | return true; |
1084 | } | 1084 | } |
1085 | 1085 | ||
1086 | QDataStream &KABC::operator<<( QDataStream &s, const AddressBook &ab ) | 1086 | QDataStream &KABC::operator<<( QDataStream &s, const AddressBook &ab ) |
1087 | { | 1087 | { |
1088 | if (!ab.d) return s; | 1088 | if (!ab.d) return s; |
1089 | 1089 | ||
1090 | return s << ab.d->mAddressees; | 1090 | return s << ab.d->mAddressees; |
1091 | } | 1091 | } |
1092 | 1092 | ||
1093 | QDataStream &KABC::operator>>( QDataStream &s, AddressBook &ab ) | 1093 | QDataStream &KABC::operator>>( QDataStream &s, AddressBook &ab ) |
1094 | { | 1094 | { |
1095 | if (!ab.d) return s; | 1095 | if (!ab.d) return s; |
1096 | 1096 | ||
1097 | s >> ab.d->mAddressees; | 1097 | s >> ab.d->mAddressees; |
1098 | 1098 | ||
1099 | return s; | 1099 | return s; |
1100 | } | 1100 | } |
1101 | 1101 | ||
1102 | bool AddressBook::addResource( Resource *resource ) | 1102 | bool AddressBook::addResource( Resource *resource ) |
1103 | { | 1103 | { |
1104 | if ( !resource->open() ) { | 1104 | if ( !resource->open() ) { |
1105 | kdDebug(5700) << "AddressBook::addResource(): can't add resource" << endl; | 1105 | kdDebug(5700) << "AddressBook::addResource(): can't add resource" << endl; |
1106 | return false; | 1106 | return false; |
1107 | } | 1107 | } |
1108 | 1108 | ||
1109 | resource->setAddressBook( this ); | 1109 | resource->setAddressBook( this ); |
1110 | 1110 | ||
1111 | d->mManager->add( resource ); | 1111 | d->mManager->add( resource ); |
1112 | return true; | 1112 | return true; |
1113 | } | 1113 | } |
1114 | 1114 | ||
1115 | bool AddressBook::removeResource( Resource *resource ) | 1115 | bool AddressBook::removeResource( Resource *resource ) |