author | ulf69 <ulf69> | 2004-06-30 22:07:56 (UTC) |
---|---|---|
committer | ulf69 <ulf69> | 2004-06-30 22:07:56 (UTC) |
commit | 1b7b7755bfbedddc72293b784577ded4e684bd6f (patch) (unidiff) | |
tree | ff4eba9b8bb53401d2000d70e73a40f7c330d577 /kabc/addressee.cpp | |
parent | c6f3a3f49498dca52d10418d845f4a84c0c6d941 (diff) | |
download | kdepimpi-1b7b7755bfbedddc72293b784577ded4e684bd6f.zip kdepimpi-1b7b7755bfbedddc72293b784577ded4e684bd6f.tar.gz kdepimpi-1b7b7755bfbedddc72293b784577ded4e684bd6f.tar.bz2 |
added a new field of type Resource. This allowes us to display in KAddressbook for each
Addressbookentry its location
-rw-r--r-- | kabc/addressee.cpp | 6 |
1 files changed, 6 insertions, 0 deletions
diff --git a/kabc/addressee.cpp b/kabc/addressee.cpp index 5cb194a..d484073 100644 --- a/kabc/addressee.cpp +++ b/kabc/addressee.cpp | |||
@@ -742,875 +742,881 @@ void Addressee::setPhoto( const Picture &photo ) | |||
742 | mData->photo = photo; | 742 | mData->photo = photo; |
743 | } | 743 | } |
744 | 744 | ||
745 | Picture Addressee::photo() const | 745 | Picture Addressee::photo() const |
746 | { | 746 | { |
747 | return mData->photo; | 747 | return mData->photo; |
748 | } | 748 | } |
749 | 749 | ||
750 | QString Addressee::photoLabel() | 750 | QString Addressee::photoLabel() |
751 | { | 751 | { |
752 | return i18n("Photo"); | 752 | return i18n("Photo"); |
753 | } | 753 | } |
754 | 754 | ||
755 | 755 | ||
756 | void Addressee::setSound( const Sound &sound ) | 756 | void Addressee::setSound( const Sound &sound ) |
757 | { | 757 | { |
758 | if ( sound == mData->sound ) return; | 758 | if ( sound == mData->sound ) return; |
759 | detach(); | 759 | detach(); |
760 | mData->empty = false; | 760 | mData->empty = false; |
761 | mData->sound = sound; | 761 | mData->sound = sound; |
762 | } | 762 | } |
763 | 763 | ||
764 | Sound Addressee::sound() const | 764 | Sound Addressee::sound() const |
765 | { | 765 | { |
766 | return mData->sound; | 766 | return mData->sound; |
767 | } | 767 | } |
768 | 768 | ||
769 | QString Addressee::soundLabel() | 769 | QString Addressee::soundLabel() |
770 | { | 770 | { |
771 | return i18n("Sound"); | 771 | return i18n("Sound"); |
772 | } | 772 | } |
773 | 773 | ||
774 | 774 | ||
775 | void Addressee::setAgent( const Agent &agent ) | 775 | void Addressee::setAgent( const Agent &agent ) |
776 | { | 776 | { |
777 | if ( agent == mData->agent ) return; | 777 | if ( agent == mData->agent ) return; |
778 | detach(); | 778 | detach(); |
779 | mData->empty = false; | 779 | mData->empty = false; |
780 | mData->agent = agent; | 780 | mData->agent = agent; |
781 | } | 781 | } |
782 | 782 | ||
783 | Agent Addressee::agent() const | 783 | Agent Addressee::agent() const |
784 | { | 784 | { |
785 | return mData->agent; | 785 | return mData->agent; |
786 | } | 786 | } |
787 | 787 | ||
788 | QString Addressee::agentLabel() | 788 | QString Addressee::agentLabel() |
789 | { | 789 | { |
790 | return i18n("Agent"); | 790 | return i18n("Agent"); |
791 | } | 791 | } |
792 | 792 | ||
793 | 793 | ||
794 | 794 | ||
795 | void Addressee::setNameFromString( const QString &str ) | 795 | void Addressee::setNameFromString( const QString &str ) |
796 | { | 796 | { |
797 | setFormattedName( str ); | 797 | setFormattedName( str ); |
798 | setName( str ); | 798 | setName( str ); |
799 | 799 | ||
800 | QStringList titles; | 800 | QStringList titles; |
801 | titles += i18n( "Dr." ); | 801 | titles += i18n( "Dr." ); |
802 | titles += i18n( "Miss" ); | 802 | titles += i18n( "Miss" ); |
803 | titles += i18n( "Mr." ); | 803 | titles += i18n( "Mr." ); |
804 | titles += i18n( "Mrs." ); | 804 | titles += i18n( "Mrs." ); |
805 | titles += i18n( "Ms." ); | 805 | titles += i18n( "Ms." ); |
806 | titles += i18n( "Prof." ); | 806 | titles += i18n( "Prof." ); |
807 | 807 | ||
808 | QStringList suffixes; | 808 | QStringList suffixes; |
809 | suffixes += i18n( "I" ); | 809 | suffixes += i18n( "I" ); |
810 | suffixes += i18n( "II" ); | 810 | suffixes += i18n( "II" ); |
811 | suffixes += i18n( "III" ); | 811 | suffixes += i18n( "III" ); |
812 | suffixes += i18n( "Jr." ); | 812 | suffixes += i18n( "Jr." ); |
813 | suffixes += i18n( "Sr." ); | 813 | suffixes += i18n( "Sr." ); |
814 | 814 | ||
815 | QStringList prefixes; | 815 | QStringList prefixes; |
816 | prefixes += "van"; | 816 | prefixes += "van"; |
817 | prefixes += "von"; | 817 | prefixes += "von"; |
818 | prefixes += "de"; | 818 | prefixes += "de"; |
819 | 819 | ||
820 | //US KConfig config( "kabcrc" ); | 820 | //US KConfig config( "kabcrc" ); |
821 | KConfig config( locateLocal( "config", "kabcrc") ); | 821 | KConfig config( locateLocal( "config", "kabcrc") ); |
822 | config.setGroup( "General" ); | 822 | config.setGroup( "General" ); |
823 | titles += config.readListEntry( "Prefixes" ); | 823 | titles += config.readListEntry( "Prefixes" ); |
824 | titles.remove( "" ); | 824 | titles.remove( "" ); |
825 | prefixes += config.readListEntry( "Inclusions" ); | 825 | prefixes += config.readListEntry( "Inclusions" ); |
826 | prefixes.remove( "" ); | 826 | prefixes.remove( "" ); |
827 | suffixes += config.readListEntry( "Suffixes" ); | 827 | suffixes += config.readListEntry( "Suffixes" ); |
828 | suffixes.remove( "" ); | 828 | suffixes.remove( "" ); |
829 | 829 | ||
830 | // clear all name parts | 830 | // clear all name parts |
831 | setPrefix( "" ); | 831 | setPrefix( "" ); |
832 | setGivenName( "" ); | 832 | setGivenName( "" ); |
833 | setAdditionalName( "" ); | 833 | setAdditionalName( "" ); |
834 | setFamilyName( "" ); | 834 | setFamilyName( "" ); |
835 | setSuffix( "" ); | 835 | setSuffix( "" ); |
836 | 836 | ||
837 | if ( str.isEmpty() ) | 837 | if ( str.isEmpty() ) |
838 | return; | 838 | return; |
839 | 839 | ||
840 | int i = str.find(','); | 840 | int i = str.find(','); |
841 | if( i < 0 ) { | 841 | if( i < 0 ) { |
842 | QStringList parts = QStringList::split( " ", str ); | 842 | QStringList parts = QStringList::split( " ", str ); |
843 | int leftOffset = 0; | 843 | int leftOffset = 0; |
844 | int rightOffset = parts.count() - 1; | 844 | int rightOffset = parts.count() - 1; |
845 | 845 | ||
846 | QString suffix; | 846 | QString suffix; |
847 | while ( rightOffset >= 0 ) { | 847 | while ( rightOffset >= 0 ) { |
848 | if ( suffixes.contains( parts[ rightOffset ] ) ) { | 848 | if ( suffixes.contains( parts[ rightOffset ] ) ) { |
849 | suffix.prepend(parts[ rightOffset ] + (suffix.isEmpty() ? "" : " ")); | 849 | suffix.prepend(parts[ rightOffset ] + (suffix.isEmpty() ? "" : " ")); |
850 | rightOffset--; | 850 | rightOffset--; |
851 | } else | 851 | } else |
852 | break; | 852 | break; |
853 | } | 853 | } |
854 | setSuffix( suffix ); | 854 | setSuffix( suffix ); |
855 | 855 | ||
856 | if ( rightOffset < 0 ) | 856 | if ( rightOffset < 0 ) |
857 | return; | 857 | return; |
858 | 858 | ||
859 | if ( rightOffset - 1 >= 0 && prefixes.contains( parts[ rightOffset - 1 ].lower() ) ) { | 859 | if ( rightOffset - 1 >= 0 && prefixes.contains( parts[ rightOffset - 1 ].lower() ) ) { |
860 | setFamilyName( parts[ rightOffset - 1 ] + " " + parts[ rightOffset ] ); | 860 | setFamilyName( parts[ rightOffset - 1 ] + " " + parts[ rightOffset ] ); |
861 | rightOffset--; | 861 | rightOffset--; |
862 | } else | 862 | } else |
863 | setFamilyName( parts[ rightOffset ] ); | 863 | setFamilyName( parts[ rightOffset ] ); |
864 | 864 | ||
865 | QString prefix; | 865 | QString prefix; |
866 | while ( leftOffset < rightOffset ) { | 866 | while ( leftOffset < rightOffset ) { |
867 | if ( titles.contains( parts[ leftOffset ] ) ) { | 867 | if ( titles.contains( parts[ leftOffset ] ) ) { |
868 | prefix.append( ( prefix.isEmpty() ? "" : " ") + parts[ leftOffset ] ); | 868 | prefix.append( ( prefix.isEmpty() ? "" : " ") + parts[ leftOffset ] ); |
869 | leftOffset++; | 869 | leftOffset++; |
870 | } else | 870 | } else |
871 | break; | 871 | break; |
872 | } | 872 | } |
873 | setPrefix( prefix ); | 873 | setPrefix( prefix ); |
874 | 874 | ||
875 | if ( leftOffset < rightOffset ) { | 875 | if ( leftOffset < rightOffset ) { |
876 | setGivenName( parts[ leftOffset ] ); | 876 | setGivenName( parts[ leftOffset ] ); |
877 | leftOffset++; | 877 | leftOffset++; |
878 | } | 878 | } |
879 | 879 | ||
880 | QString additionalName; | 880 | QString additionalName; |
881 | while ( leftOffset < rightOffset ) { | 881 | while ( leftOffset < rightOffset ) { |
882 | additionalName.append( ( additionalName.isEmpty() ? "" : " ") + parts[ leftOffset ] ); | 882 | additionalName.append( ( additionalName.isEmpty() ? "" : " ") + parts[ leftOffset ] ); |
883 | leftOffset++; | 883 | leftOffset++; |
884 | } | 884 | } |
885 | setAdditionalName( additionalName ); | 885 | setAdditionalName( additionalName ); |
886 | } else { | 886 | } else { |
887 | QString part1 = str.left( i ); | 887 | QString part1 = str.left( i ); |
888 | QString part2 = str.mid( i + 1 ); | 888 | QString part2 = str.mid( i + 1 ); |
889 | 889 | ||
890 | QStringList parts = QStringList::split( " ", part1 ); | 890 | QStringList parts = QStringList::split( " ", part1 ); |
891 | int leftOffset = 0; | 891 | int leftOffset = 0; |
892 | int rightOffset = parts.count() - 1; | 892 | int rightOffset = parts.count() - 1; |
893 | 893 | ||
894 | QString suffix; | 894 | QString suffix; |
895 | while ( rightOffset >= 0 ) { | 895 | while ( rightOffset >= 0 ) { |
896 | if ( suffixes.contains( parts[ rightOffset ] ) ) { | 896 | if ( suffixes.contains( parts[ rightOffset ] ) ) { |
897 | suffix.prepend(parts[ rightOffset ] + (suffix.isEmpty() ? "" : " ")); | 897 | suffix.prepend(parts[ rightOffset ] + (suffix.isEmpty() ? "" : " ")); |
898 | rightOffset--; | 898 | rightOffset--; |
899 | } else | 899 | } else |
900 | break; | 900 | break; |
901 | } | 901 | } |
902 | setSuffix( suffix ); | 902 | setSuffix( suffix ); |
903 | 903 | ||
904 | if ( rightOffset - 1 >= 0 && prefixes.contains( parts[ rightOffset - 1 ].lower() ) ) { | 904 | if ( rightOffset - 1 >= 0 && prefixes.contains( parts[ rightOffset - 1 ].lower() ) ) { |
905 | setFamilyName( parts[ rightOffset - 1 ] + " " + parts[ rightOffset ] ); | 905 | setFamilyName( parts[ rightOffset - 1 ] + " " + parts[ rightOffset ] ); |
906 | rightOffset--; | 906 | rightOffset--; |
907 | } else | 907 | } else |
908 | setFamilyName( parts[ rightOffset ] ); | 908 | setFamilyName( parts[ rightOffset ] ); |
909 | 909 | ||
910 | QString prefix; | 910 | QString prefix; |
911 | while ( leftOffset < rightOffset ) { | 911 | while ( leftOffset < rightOffset ) { |
912 | if ( titles.contains( parts[ leftOffset ] ) ) { | 912 | if ( titles.contains( parts[ leftOffset ] ) ) { |
913 | prefix.append( ( prefix.isEmpty() ? "" : " ") + parts[ leftOffset ] ); | 913 | prefix.append( ( prefix.isEmpty() ? "" : " ") + parts[ leftOffset ] ); |
914 | leftOffset++; | 914 | leftOffset++; |
915 | } else | 915 | } else |
916 | break; | 916 | break; |
917 | } | 917 | } |
918 | 918 | ||
919 | parts = QStringList::split( " ", part2 ); | 919 | parts = QStringList::split( " ", part2 ); |
920 | 920 | ||
921 | leftOffset = 0; | 921 | leftOffset = 0; |
922 | rightOffset = parts.count(); | 922 | rightOffset = parts.count(); |
923 | 923 | ||
924 | while ( leftOffset < rightOffset ) { | 924 | while ( leftOffset < rightOffset ) { |
925 | if ( titles.contains( parts[ leftOffset ] ) ) { | 925 | if ( titles.contains( parts[ leftOffset ] ) ) { |
926 | prefix.append( ( prefix.isEmpty() ? "" : " ") + parts[ leftOffset ] ); | 926 | prefix.append( ( prefix.isEmpty() ? "" : " ") + parts[ leftOffset ] ); |
927 | leftOffset++; | 927 | leftOffset++; |
928 | } else | 928 | } else |
929 | break; | 929 | break; |
930 | } | 930 | } |
931 | setPrefix( prefix ); | 931 | setPrefix( prefix ); |
932 | 932 | ||
933 | if ( leftOffset < rightOffset ) { | 933 | if ( leftOffset < rightOffset ) { |
934 | setGivenName( parts[ leftOffset ] ); | 934 | setGivenName( parts[ leftOffset ] ); |
935 | leftOffset++; | 935 | leftOffset++; |
936 | } | 936 | } |
937 | 937 | ||
938 | QString additionalName; | 938 | QString additionalName; |
939 | while ( leftOffset < rightOffset ) { | 939 | while ( leftOffset < rightOffset ) { |
940 | additionalName.append( ( additionalName.isEmpty() ? "" : " ") + parts[ leftOffset ] ); | 940 | additionalName.append( ( additionalName.isEmpty() ? "" : " ") + parts[ leftOffset ] ); |
941 | leftOffset++; | 941 | leftOffset++; |
942 | } | 942 | } |
943 | setAdditionalName( additionalName ); | 943 | setAdditionalName( additionalName ); |
944 | } | 944 | } |
945 | } | 945 | } |
946 | 946 | ||
947 | QString Addressee::realName() const | 947 | QString Addressee::realName() const |
948 | { | 948 | { |
949 | if ( !formattedName().isEmpty() ) | 949 | if ( !formattedName().isEmpty() ) |
950 | return formattedName(); | 950 | return formattedName(); |
951 | 951 | ||
952 | QString n = assembledName(); | 952 | QString n = assembledName(); |
953 | 953 | ||
954 | if ( n.isEmpty() ) | 954 | if ( n.isEmpty() ) |
955 | n = name(); | 955 | n = name(); |
956 | 956 | ||
957 | return n; | 957 | return n; |
958 | } | 958 | } |
959 | 959 | ||
960 | QString Addressee::assembledName() const | 960 | QString Addressee::assembledName() const |
961 | { | 961 | { |
962 | QString name = prefix() + " " + givenName() + " " + additionalName() + " " + | 962 | QString name = prefix() + " " + givenName() + " " + additionalName() + " " + |
963 | familyName() + " " + suffix(); | 963 | familyName() + " " + suffix(); |
964 | 964 | ||
965 | return name.simplifyWhiteSpace(); | 965 | return name.simplifyWhiteSpace(); |
966 | } | 966 | } |
967 | 967 | ||
968 | QString Addressee::fullEmail( const QString &email ) const | 968 | QString Addressee::fullEmail( const QString &email ) const |
969 | { | 969 | { |
970 | QString e; | 970 | QString e; |
971 | if ( email.isNull() ) { | 971 | if ( email.isNull() ) { |
972 | e = preferredEmail(); | 972 | e = preferredEmail(); |
973 | } else { | 973 | } else { |
974 | e = email; | 974 | e = email; |
975 | } | 975 | } |
976 | if ( e.isEmpty() ) return QString::null; | 976 | if ( e.isEmpty() ) return QString::null; |
977 | 977 | ||
978 | QString text; | 978 | QString text; |
979 | if ( realName().isEmpty() ) | 979 | if ( realName().isEmpty() ) |
980 | text = e; | 980 | text = e; |
981 | else | 981 | else |
982 | text = assembledName() + " <" + e + ">"; | 982 | text = assembledName() + " <" + e + ">"; |
983 | 983 | ||
984 | return text; | 984 | return text; |
985 | } | 985 | } |
986 | 986 | ||
987 | void Addressee::insertEmail( const QString &email, bool preferred ) | 987 | void Addressee::insertEmail( const QString &email, bool preferred ) |
988 | { | 988 | { |
989 | detach(); | 989 | detach(); |
990 | 990 | ||
991 | QStringList::Iterator it = mData->emails.find( email ); | 991 | QStringList::Iterator it = mData->emails.find( email ); |
992 | 992 | ||
993 | if ( it != mData->emails.end() ) { | 993 | if ( it != mData->emails.end() ) { |
994 | if ( !preferred || it == mData->emails.begin() ) return; | 994 | if ( !preferred || it == mData->emails.begin() ) return; |
995 | mData->emails.remove( it ); | 995 | mData->emails.remove( it ); |
996 | mData->emails.prepend( email ); | 996 | mData->emails.prepend( email ); |
997 | } else { | 997 | } else { |
998 | if ( preferred ) { | 998 | if ( preferred ) { |
999 | mData->emails.prepend( email ); | 999 | mData->emails.prepend( email ); |
1000 | } else { | 1000 | } else { |
1001 | mData->emails.append( email ); | 1001 | mData->emails.append( email ); |
1002 | } | 1002 | } |
1003 | } | 1003 | } |
1004 | } | 1004 | } |
1005 | 1005 | ||
1006 | void Addressee::removeEmail( const QString &email ) | 1006 | void Addressee::removeEmail( const QString &email ) |
1007 | { | 1007 | { |
1008 | detach(); | 1008 | detach(); |
1009 | 1009 | ||
1010 | QStringList::Iterator it = mData->emails.find( email ); | 1010 | QStringList::Iterator it = mData->emails.find( email ); |
1011 | if ( it == mData->emails.end() ) return; | 1011 | if ( it == mData->emails.end() ) return; |
1012 | 1012 | ||
1013 | mData->emails.remove( it ); | 1013 | mData->emails.remove( it ); |
1014 | } | 1014 | } |
1015 | 1015 | ||
1016 | QString Addressee::preferredEmail() const | 1016 | QString Addressee::preferredEmail() const |
1017 | { | 1017 | { |
1018 | if ( mData->emails.count() == 0 ) return QString::null; | 1018 | if ( mData->emails.count() == 0 ) return QString::null; |
1019 | else return mData->emails.first(); | 1019 | else return mData->emails.first(); |
1020 | } | 1020 | } |
1021 | 1021 | ||
1022 | QStringList Addressee::emails() const | 1022 | QStringList Addressee::emails() const |
1023 | { | 1023 | { |
1024 | return mData->emails; | 1024 | return mData->emails; |
1025 | } | 1025 | } |
1026 | void Addressee::setEmails( const QStringList& emails ) { | 1026 | void Addressee::setEmails( const QStringList& emails ) { |
1027 | detach(); | 1027 | detach(); |
1028 | mData->emails = emails; | 1028 | mData->emails = emails; |
1029 | } | 1029 | } |
1030 | void Addressee::insertPhoneNumber( const PhoneNumber &phoneNumber ) | 1030 | void Addressee::insertPhoneNumber( const PhoneNumber &phoneNumber ) |
1031 | { | 1031 | { |
1032 | detach(); | 1032 | detach(); |
1033 | mData->empty = false; | 1033 | mData->empty = false; |
1034 | 1034 | ||
1035 | PhoneNumber::List::Iterator it; | 1035 | PhoneNumber::List::Iterator it; |
1036 | for( it = mData->phoneNumbers.begin(); it != mData->phoneNumbers.end(); ++it ) { | 1036 | for( it = mData->phoneNumbers.begin(); it != mData->phoneNumbers.end(); ++it ) { |
1037 | if ( (*it).id() == phoneNumber.id() ) { | 1037 | if ( (*it).id() == phoneNumber.id() ) { |
1038 | *it = phoneNumber; | 1038 | *it = phoneNumber; |
1039 | return; | 1039 | return; |
1040 | } | 1040 | } |
1041 | } | 1041 | } |
1042 | mData->phoneNumbers.append( phoneNumber ); | 1042 | mData->phoneNumbers.append( phoneNumber ); |
1043 | } | 1043 | } |
1044 | 1044 | ||
1045 | void Addressee::removePhoneNumber( const PhoneNumber &phoneNumber ) | 1045 | void Addressee::removePhoneNumber( const PhoneNumber &phoneNumber ) |
1046 | { | 1046 | { |
1047 | detach(); | 1047 | detach(); |
1048 | 1048 | ||
1049 | PhoneNumber::List::Iterator it; | 1049 | PhoneNumber::List::Iterator it; |
1050 | for( it = mData->phoneNumbers.begin(); it != mData->phoneNumbers.end(); ++it ) { | 1050 | for( it = mData->phoneNumbers.begin(); it != mData->phoneNumbers.end(); ++it ) { |
1051 | if ( (*it).id() == phoneNumber.id() ) { | 1051 | if ( (*it).id() == phoneNumber.id() ) { |
1052 | mData->phoneNumbers.remove( it ); | 1052 | mData->phoneNumbers.remove( it ); |
1053 | return; | 1053 | return; |
1054 | } | 1054 | } |
1055 | } | 1055 | } |
1056 | } | 1056 | } |
1057 | 1057 | ||
1058 | PhoneNumber Addressee::phoneNumber( int type ) const | 1058 | PhoneNumber Addressee::phoneNumber( int type ) const |
1059 | { | 1059 | { |
1060 | PhoneNumber phoneNumber( "", type ); | 1060 | PhoneNumber phoneNumber( "", type ); |
1061 | PhoneNumber::List::ConstIterator it; | 1061 | PhoneNumber::List::ConstIterator it; |
1062 | for( it = mData->phoneNumbers.begin(); it != mData->phoneNumbers.end(); ++it ) { | 1062 | for( it = mData->phoneNumbers.begin(); it != mData->phoneNumbers.end(); ++it ) { |
1063 | if ( matchBinaryPattern( (*it).type(), type ) ) { | 1063 | if ( matchBinaryPattern( (*it).type(), type ) ) { |
1064 | if ( (*it).type() & PhoneNumber::Pref ) | 1064 | if ( (*it).type() & PhoneNumber::Pref ) |
1065 | return (*it); | 1065 | return (*it); |
1066 | else if ( phoneNumber.number().isEmpty() ) | 1066 | else if ( phoneNumber.number().isEmpty() ) |
1067 | phoneNumber = (*it); | 1067 | phoneNumber = (*it); |
1068 | } | 1068 | } |
1069 | } | 1069 | } |
1070 | 1070 | ||
1071 | return phoneNumber; | 1071 | return phoneNumber; |
1072 | } | 1072 | } |
1073 | 1073 | ||
1074 | PhoneNumber::List Addressee::phoneNumbers() const | 1074 | PhoneNumber::List Addressee::phoneNumbers() const |
1075 | { | 1075 | { |
1076 | return mData->phoneNumbers; | 1076 | return mData->phoneNumbers; |
1077 | } | 1077 | } |
1078 | 1078 | ||
1079 | PhoneNumber::List Addressee::phoneNumbers( int type ) const | 1079 | PhoneNumber::List Addressee::phoneNumbers( int type ) const |
1080 | { | 1080 | { |
1081 | PhoneNumber::List list; | 1081 | PhoneNumber::List list; |
1082 | 1082 | ||
1083 | PhoneNumber::List::ConstIterator it; | 1083 | PhoneNumber::List::ConstIterator it; |
1084 | for( it = mData->phoneNumbers.begin(); it != mData->phoneNumbers.end(); ++it ) { | 1084 | for( it = mData->phoneNumbers.begin(); it != mData->phoneNumbers.end(); ++it ) { |
1085 | if ( matchBinaryPattern( (*it).type(), type ) ) { | 1085 | if ( matchBinaryPattern( (*it).type(), type ) ) { |
1086 | list.append( *it ); | 1086 | list.append( *it ); |
1087 | } | 1087 | } |
1088 | } | 1088 | } |
1089 | return list; | 1089 | return list; |
1090 | } | 1090 | } |
1091 | 1091 | ||
1092 | PhoneNumber Addressee::findPhoneNumber( const QString &id ) const | 1092 | PhoneNumber Addressee::findPhoneNumber( const QString &id ) const |
1093 | { | 1093 | { |
1094 | PhoneNumber::List::ConstIterator it; | 1094 | PhoneNumber::List::ConstIterator it; |
1095 | for( it = mData->phoneNumbers.begin(); it != mData->phoneNumbers.end(); ++it ) { | 1095 | for( it = mData->phoneNumbers.begin(); it != mData->phoneNumbers.end(); ++it ) { |
1096 | if ( (*it).id() == id ) { | 1096 | if ( (*it).id() == id ) { |
1097 | return *it; | 1097 | return *it; |
1098 | } | 1098 | } |
1099 | } | 1099 | } |
1100 | return PhoneNumber(); | 1100 | return PhoneNumber(); |
1101 | } | 1101 | } |
1102 | 1102 | ||
1103 | void Addressee::insertKey( const Key &key ) | 1103 | void Addressee::insertKey( const Key &key ) |
1104 | { | 1104 | { |
1105 | detach(); | 1105 | detach(); |
1106 | mData->empty = false; | 1106 | mData->empty = false; |
1107 | 1107 | ||
1108 | Key::List::Iterator it; | 1108 | Key::List::Iterator it; |
1109 | for( it = mData->keys.begin(); it != mData->keys.end(); ++it ) { | 1109 | for( it = mData->keys.begin(); it != mData->keys.end(); ++it ) { |
1110 | if ( (*it).id() == key.id() ) { | 1110 | if ( (*it).id() == key.id() ) { |
1111 | *it = key; | 1111 | *it = key; |
1112 | return; | 1112 | return; |
1113 | } | 1113 | } |
1114 | } | 1114 | } |
1115 | mData->keys.append( key ); | 1115 | mData->keys.append( key ); |
1116 | } | 1116 | } |
1117 | 1117 | ||
1118 | void Addressee::removeKey( const Key &key ) | 1118 | void Addressee::removeKey( const Key &key ) |
1119 | { | 1119 | { |
1120 | detach(); | 1120 | detach(); |
1121 | 1121 | ||
1122 | Key::List::Iterator it; | 1122 | Key::List::Iterator it; |
1123 | for( it = mData->keys.begin(); it != mData->keys.end(); ++it ) { | 1123 | for( it = mData->keys.begin(); it != mData->keys.end(); ++it ) { |
1124 | if ( (*it).id() == key.id() ) { | 1124 | if ( (*it).id() == key.id() ) { |
1125 | mData->keys.remove( key ); | 1125 | mData->keys.remove( key ); |
1126 | return; | 1126 | return; |
1127 | } | 1127 | } |
1128 | } | 1128 | } |
1129 | } | 1129 | } |
1130 | 1130 | ||
1131 | Key Addressee::key( int type, QString customTypeString ) const | 1131 | Key Addressee::key( int type, QString customTypeString ) const |
1132 | { | 1132 | { |
1133 | Key::List::ConstIterator it; | 1133 | Key::List::ConstIterator it; |
1134 | for( it = mData->keys.begin(); it != mData->keys.end(); ++it ) { | 1134 | for( it = mData->keys.begin(); it != mData->keys.end(); ++it ) { |
1135 | if ( (*it).type() == type ) { | 1135 | if ( (*it).type() == type ) { |
1136 | if ( type == Key::Custom ) { | 1136 | if ( type == Key::Custom ) { |
1137 | if ( customTypeString.isEmpty() ) { | 1137 | if ( customTypeString.isEmpty() ) { |
1138 | return *it; | 1138 | return *it; |
1139 | } else { | 1139 | } else { |
1140 | if ( (*it).customTypeString() == customTypeString ) | 1140 | if ( (*it).customTypeString() == customTypeString ) |
1141 | return (*it); | 1141 | return (*it); |
1142 | } | 1142 | } |
1143 | } else { | 1143 | } else { |
1144 | return *it; | 1144 | return *it; |
1145 | } | 1145 | } |
1146 | } | 1146 | } |
1147 | } | 1147 | } |
1148 | return Key( QString(), type ); | 1148 | return Key( QString(), type ); |
1149 | } | 1149 | } |
1150 | void Addressee::setKeys( const Key::List& list ) { | 1150 | void Addressee::setKeys( const Key::List& list ) { |
1151 | detach(); | 1151 | detach(); |
1152 | mData->keys = list; | 1152 | mData->keys = list; |
1153 | } | 1153 | } |
1154 | 1154 | ||
1155 | Key::List Addressee::keys() const | 1155 | Key::List Addressee::keys() const |
1156 | { | 1156 | { |
1157 | return mData->keys; | 1157 | return mData->keys; |
1158 | } | 1158 | } |
1159 | 1159 | ||
1160 | Key::List Addressee::keys( int type, QString customTypeString ) const | 1160 | Key::List Addressee::keys( int type, QString customTypeString ) const |
1161 | { | 1161 | { |
1162 | Key::List list; | 1162 | Key::List list; |
1163 | 1163 | ||
1164 | Key::List::ConstIterator it; | 1164 | Key::List::ConstIterator it; |
1165 | for( it = mData->keys.begin(); it != mData->keys.end(); ++it ) { | 1165 | for( it = mData->keys.begin(); it != mData->keys.end(); ++it ) { |
1166 | if ( (*it).type() == type ) { | 1166 | if ( (*it).type() == type ) { |
1167 | if ( type == Key::Custom ) { | 1167 | if ( type == Key::Custom ) { |
1168 | if ( customTypeString.isEmpty() ) { | 1168 | if ( customTypeString.isEmpty() ) { |
1169 | list.append(*it); | 1169 | list.append(*it); |
1170 | } else { | 1170 | } else { |
1171 | if ( (*it).customTypeString() == customTypeString ) | 1171 | if ( (*it).customTypeString() == customTypeString ) |
1172 | list.append(*it); | 1172 | list.append(*it); |
1173 | } | 1173 | } |
1174 | } else { | 1174 | } else { |
1175 | list.append(*it); | 1175 | list.append(*it); |
1176 | } | 1176 | } |
1177 | } | 1177 | } |
1178 | } | 1178 | } |
1179 | return list; | 1179 | return list; |
1180 | } | 1180 | } |
1181 | 1181 | ||
1182 | Key Addressee::findKey( const QString &id ) const | 1182 | Key Addressee::findKey( const QString &id ) const |
1183 | { | 1183 | { |
1184 | Key::List::ConstIterator it; | 1184 | Key::List::ConstIterator it; |
1185 | for( it = mData->keys.begin(); it != mData->keys.end(); ++it ) { | 1185 | for( it = mData->keys.begin(); it != mData->keys.end(); ++it ) { |
1186 | if ( (*it).id() == id ) { | 1186 | if ( (*it).id() == id ) { |
1187 | return *it; | 1187 | return *it; |
1188 | } | 1188 | } |
1189 | } | 1189 | } |
1190 | return Key(); | 1190 | return Key(); |
1191 | } | 1191 | } |
1192 | 1192 | ||
1193 | QString Addressee::asString() const | 1193 | QString Addressee::asString() const |
1194 | { | 1194 | { |
1195 | return "Smith, agent Smith..."; | 1195 | return "Smith, agent Smith..."; |
1196 | } | 1196 | } |
1197 | 1197 | ||
1198 | void Addressee::dump() const | 1198 | void Addressee::dump() const |
1199 | { | 1199 | { |
1200 | return; | 1200 | return; |
1201 | kdDebug(5700) << "Addressee {" << endl; | 1201 | kdDebug(5700) << "Addressee {" << endl; |
1202 | 1202 | ||
1203 | kdDebug(5700) << " Uid: '" << uid() << "'" << endl; | 1203 | kdDebug(5700) << " Uid: '" << uid() << "'" << endl; |
1204 | 1204 | ||
1205 | kdDebug(5700) << " Name: '" << name() << "'" << endl; | 1205 | kdDebug(5700) << " Name: '" << name() << "'" << endl; |
1206 | kdDebug(5700) << " FormattedName: '" << formattedName() << "'" << endl; | 1206 | kdDebug(5700) << " FormattedName: '" << formattedName() << "'" << endl; |
1207 | kdDebug(5700) << " FamilyName: '" << familyName() << "'" << endl; | 1207 | kdDebug(5700) << " FamilyName: '" << familyName() << "'" << endl; |
1208 | kdDebug(5700) << " GivenName: '" << givenName() << "'" << endl; | 1208 | kdDebug(5700) << " GivenName: '" << givenName() << "'" << endl; |
1209 | kdDebug(5700) << " AdditionalName: '" << additionalName() << "'" << endl; | 1209 | kdDebug(5700) << " AdditionalName: '" << additionalName() << "'" << endl; |
1210 | kdDebug(5700) << " Prefix: '" << prefix() << "'" << endl; | 1210 | kdDebug(5700) << " Prefix: '" << prefix() << "'" << endl; |
1211 | kdDebug(5700) << " Suffix: '" << suffix() << "'" << endl; | 1211 | kdDebug(5700) << " Suffix: '" << suffix() << "'" << endl; |
1212 | kdDebug(5700) << " NickName: '" << nickName() << "'" << endl; | 1212 | kdDebug(5700) << " NickName: '" << nickName() << "'" << endl; |
1213 | kdDebug(5700) << " Birthday: '" << birthday().toString() << "'" << endl; | 1213 | kdDebug(5700) << " Birthday: '" << birthday().toString() << "'" << endl; |
1214 | kdDebug(5700) << " Mailer: '" << mailer() << "'" << endl; | 1214 | kdDebug(5700) << " Mailer: '" << mailer() << "'" << endl; |
1215 | kdDebug(5700) << " TimeZone: '" << timeZone().asString() << "'" << endl; | 1215 | kdDebug(5700) << " TimeZone: '" << timeZone().asString() << "'" << endl; |
1216 | kdDebug(5700) << " Geo: '" << geo().asString() << "'" << endl; | 1216 | kdDebug(5700) << " Geo: '" << geo().asString() << "'" << endl; |
1217 | kdDebug(5700) << " Title: '" << title() << "'" << endl; | 1217 | kdDebug(5700) << " Title: '" << title() << "'" << endl; |
1218 | kdDebug(5700) << " Role: '" << role() << "'" << endl; | 1218 | kdDebug(5700) << " Role: '" << role() << "'" << endl; |
1219 | kdDebug(5700) << " Organization: '" << organization() << "'" << endl; | 1219 | kdDebug(5700) << " Organization: '" << organization() << "'" << endl; |
1220 | kdDebug(5700) << " Note: '" << note() << "'" << endl; | 1220 | kdDebug(5700) << " Note: '" << note() << "'" << endl; |
1221 | kdDebug(5700) << " ProductId: '" << productId() << "'" << endl; | 1221 | kdDebug(5700) << " ProductId: '" << productId() << "'" << endl; |
1222 | kdDebug(5700) << " Revision: '" << revision().toString() << "'" << endl; | 1222 | kdDebug(5700) << " Revision: '" << revision().toString() << "'" << endl; |
1223 | kdDebug(5700) << " SortString: '" << sortString() << "'" << endl; | 1223 | kdDebug(5700) << " SortString: '" << sortString() << "'" << endl; |
1224 | kdDebug(5700) << " Url: '" << url().url() << "'" << endl; | 1224 | kdDebug(5700) << " Url: '" << url().url() << "'" << endl; |
1225 | kdDebug(5700) << " Secrecy: '" << secrecy().asString() << "'" << endl; | 1225 | kdDebug(5700) << " Secrecy: '" << secrecy().asString() << "'" << endl; |
1226 | kdDebug(5700) << " Logo: '" << logo().asString() << "'" << endl; | 1226 | kdDebug(5700) << " Logo: '" << logo().asString() << "'" << endl; |
1227 | kdDebug(5700) << " Photo: '" << photo().asString() << "'" << endl; | 1227 | kdDebug(5700) << " Photo: '" << photo().asString() << "'" << endl; |
1228 | kdDebug(5700) << " Sound: '" << sound().asString() << "'" << endl; | 1228 | kdDebug(5700) << " Sound: '" << sound().asString() << "'" << endl; |
1229 | kdDebug(5700) << " Agent: '" << agent().asString() << "'" << endl; | 1229 | kdDebug(5700) << " Agent: '" << agent().asString() << "'" << endl; |
1230 | 1230 | ||
1231 | kdDebug(5700) << " Emails {" << endl; | 1231 | kdDebug(5700) << " Emails {" << endl; |
1232 | QStringList e = emails(); | 1232 | QStringList e = emails(); |
1233 | QStringList::ConstIterator it; | 1233 | QStringList::ConstIterator it; |
1234 | for( it = e.begin(); it != e.end(); ++it ) { | 1234 | for( it = e.begin(); it != e.end(); ++it ) { |
1235 | kdDebug(5700) << " " << (*it) << endl; | 1235 | kdDebug(5700) << " " << (*it) << endl; |
1236 | } | 1236 | } |
1237 | kdDebug(5700) << " }" << endl; | 1237 | kdDebug(5700) << " }" << endl; |
1238 | 1238 | ||
1239 | kdDebug(5700) << " PhoneNumbers {" << endl; | 1239 | kdDebug(5700) << " PhoneNumbers {" << endl; |
1240 | PhoneNumber::List p = phoneNumbers(); | 1240 | PhoneNumber::List p = phoneNumbers(); |
1241 | PhoneNumber::List::ConstIterator it2; | 1241 | PhoneNumber::List::ConstIterator it2; |
1242 | for( it2 = p.begin(); it2 != p.end(); ++it2 ) { | 1242 | for( it2 = p.begin(); it2 != p.end(); ++it2 ) { |
1243 | kdDebug(5700) << " Type: " << int((*it2).type()) << " Number: " << (*it2).number() << endl; | 1243 | kdDebug(5700) << " Type: " << int((*it2).type()) << " Number: " << (*it2).number() << endl; |
1244 | } | 1244 | } |
1245 | kdDebug(5700) << " }" << endl; | 1245 | kdDebug(5700) << " }" << endl; |
1246 | 1246 | ||
1247 | Address::List a = addresses(); | 1247 | Address::List a = addresses(); |
1248 | Address::List::ConstIterator it3; | 1248 | Address::List::ConstIterator it3; |
1249 | for( it3 = a.begin(); it3 != a.end(); ++it3 ) { | 1249 | for( it3 = a.begin(); it3 != a.end(); ++it3 ) { |
1250 | (*it3).dump(); | 1250 | (*it3).dump(); |
1251 | } | 1251 | } |
1252 | 1252 | ||
1253 | kdDebug(5700) << " Keys {" << endl; | 1253 | kdDebug(5700) << " Keys {" << endl; |
1254 | Key::List k = keys(); | 1254 | Key::List k = keys(); |
1255 | Key::List::ConstIterator it4; | 1255 | Key::List::ConstIterator it4; |
1256 | for( it4 = k.begin(); it4 != k.end(); ++it4 ) { | 1256 | for( it4 = k.begin(); it4 != k.end(); ++it4 ) { |
1257 | kdDebug(5700) << " Type: " << int((*it4).type()) << | 1257 | kdDebug(5700) << " Type: " << int((*it4).type()) << |
1258 | " Key: " << (*it4).textData() << | 1258 | " Key: " << (*it4).textData() << |
1259 | " CustomString: " << (*it4).customTypeString() << endl; | 1259 | " CustomString: " << (*it4).customTypeString() << endl; |
1260 | } | 1260 | } |
1261 | kdDebug(5700) << " }" << endl; | 1261 | kdDebug(5700) << " }" << endl; |
1262 | 1262 | ||
1263 | kdDebug(5700) << "}" << endl; | 1263 | kdDebug(5700) << "}" << endl; |
1264 | } | 1264 | } |
1265 | 1265 | ||
1266 | 1266 | ||
1267 | void Addressee::insertAddress( const Address &address ) | 1267 | void Addressee::insertAddress( const Address &address ) |
1268 | { | 1268 | { |
1269 | detach(); | 1269 | detach(); |
1270 | mData->empty = false; | 1270 | mData->empty = false; |
1271 | 1271 | ||
1272 | Address::List::Iterator it; | 1272 | Address::List::Iterator it; |
1273 | for( it = mData->addresses.begin(); it != mData->addresses.end(); ++it ) { | 1273 | for( it = mData->addresses.begin(); it != mData->addresses.end(); ++it ) { |
1274 | if ( (*it).id() == address.id() ) { | 1274 | if ( (*it).id() == address.id() ) { |
1275 | *it = address; | 1275 | *it = address; |
1276 | return; | 1276 | return; |
1277 | } | 1277 | } |
1278 | } | 1278 | } |
1279 | mData->addresses.append( address ); | 1279 | mData->addresses.append( address ); |
1280 | } | 1280 | } |
1281 | 1281 | ||
1282 | void Addressee::removeAddress( const Address &address ) | 1282 | void Addressee::removeAddress( const Address &address ) |
1283 | { | 1283 | { |
1284 | detach(); | 1284 | detach(); |
1285 | 1285 | ||
1286 | Address::List::Iterator it; | 1286 | Address::List::Iterator it; |
1287 | for( it = mData->addresses.begin(); it != mData->addresses.end(); ++it ) { | 1287 | for( it = mData->addresses.begin(); it != mData->addresses.end(); ++it ) { |
1288 | if ( (*it).id() == address.id() ) { | 1288 | if ( (*it).id() == address.id() ) { |
1289 | mData->addresses.remove( it ); | 1289 | mData->addresses.remove( it ); |
1290 | return; | 1290 | return; |
1291 | } | 1291 | } |
1292 | } | 1292 | } |
1293 | } | 1293 | } |
1294 | 1294 | ||
1295 | Address Addressee::address( int type ) const | 1295 | Address Addressee::address( int type ) const |
1296 | { | 1296 | { |
1297 | Address address( type ); | 1297 | Address address( type ); |
1298 | Address::List::ConstIterator it; | 1298 | Address::List::ConstIterator it; |
1299 | for( it = mData->addresses.begin(); it != mData->addresses.end(); ++it ) { | 1299 | for( it = mData->addresses.begin(); it != mData->addresses.end(); ++it ) { |
1300 | if ( matchBinaryPattern( (*it).type(), type ) ) { | 1300 | if ( matchBinaryPattern( (*it).type(), type ) ) { |
1301 | if ( (*it).type() & Address::Pref ) | 1301 | if ( (*it).type() & Address::Pref ) |
1302 | return (*it); | 1302 | return (*it); |
1303 | else if ( address.isEmpty() ) | 1303 | else if ( address.isEmpty() ) |
1304 | address = (*it); | 1304 | address = (*it); |
1305 | } | 1305 | } |
1306 | } | 1306 | } |
1307 | 1307 | ||
1308 | return address; | 1308 | return address; |
1309 | } | 1309 | } |
1310 | 1310 | ||
1311 | Address::List Addressee::addresses() const | 1311 | Address::List Addressee::addresses() const |
1312 | { | 1312 | { |
1313 | return mData->addresses; | 1313 | return mData->addresses; |
1314 | } | 1314 | } |
1315 | 1315 | ||
1316 | Address::List Addressee::addresses( int type ) const | 1316 | Address::List Addressee::addresses( int type ) const |
1317 | { | 1317 | { |
1318 | Address::List list; | 1318 | Address::List list; |
1319 | 1319 | ||
1320 | Address::List::ConstIterator it; | 1320 | Address::List::ConstIterator it; |
1321 | for( it = mData->addresses.begin(); it != mData->addresses.end(); ++it ) { | 1321 | for( it = mData->addresses.begin(); it != mData->addresses.end(); ++it ) { |
1322 | if ( matchBinaryPattern( (*it).type(), type ) ) { | 1322 | if ( matchBinaryPattern( (*it).type(), type ) ) { |
1323 | list.append( *it ); | 1323 | list.append( *it ); |
1324 | } | 1324 | } |
1325 | } | 1325 | } |
1326 | 1326 | ||
1327 | return list; | 1327 | return list; |
1328 | } | 1328 | } |
1329 | 1329 | ||
1330 | Address Addressee::findAddress( const QString &id ) const | 1330 | Address Addressee::findAddress( const QString &id ) const |
1331 | { | 1331 | { |
1332 | Address::List::ConstIterator it; | 1332 | Address::List::ConstIterator it; |
1333 | for( it = mData->addresses.begin(); it != mData->addresses.end(); ++it ) { | 1333 | for( it = mData->addresses.begin(); it != mData->addresses.end(); ++it ) { |
1334 | if ( (*it).id() == id ) { | 1334 | if ( (*it).id() == id ) { |
1335 | return *it; | 1335 | return *it; |
1336 | } | 1336 | } |
1337 | } | 1337 | } |
1338 | return Address(); | 1338 | return Address(); |
1339 | } | 1339 | } |
1340 | 1340 | ||
1341 | void Addressee::insertCategory( const QString &c ) | 1341 | void Addressee::insertCategory( const QString &c ) |
1342 | { | 1342 | { |
1343 | detach(); | 1343 | detach(); |
1344 | mData->empty = false; | 1344 | mData->empty = false; |
1345 | 1345 | ||
1346 | if ( mData->categories.contains( c ) ) return; | 1346 | if ( mData->categories.contains( c ) ) return; |
1347 | 1347 | ||
1348 | mData->categories.append( c ); | 1348 | mData->categories.append( c ); |
1349 | } | 1349 | } |
1350 | 1350 | ||
1351 | void Addressee::removeCategory( const QString &c ) | 1351 | void Addressee::removeCategory( const QString &c ) |
1352 | { | 1352 | { |
1353 | detach(); | 1353 | detach(); |
1354 | 1354 | ||
1355 | QStringList::Iterator it = mData->categories.find( c ); | 1355 | QStringList::Iterator it = mData->categories.find( c ); |
1356 | if ( it == mData->categories.end() ) return; | 1356 | if ( it == mData->categories.end() ) return; |
1357 | 1357 | ||
1358 | mData->categories.remove( it ); | 1358 | mData->categories.remove( it ); |
1359 | } | 1359 | } |
1360 | 1360 | ||
1361 | bool Addressee::hasCategory( const QString &c ) const | 1361 | bool Addressee::hasCategory( const QString &c ) const |
1362 | { | 1362 | { |
1363 | return ( mData->categories.contains( c ) ); | 1363 | return ( mData->categories.contains( c ) ); |
1364 | } | 1364 | } |
1365 | 1365 | ||
1366 | void Addressee::setCategories( const QStringList &c ) | 1366 | void Addressee::setCategories( const QStringList &c ) |
1367 | { | 1367 | { |
1368 | detach(); | 1368 | detach(); |
1369 | mData->empty = false; | 1369 | mData->empty = false; |
1370 | 1370 | ||
1371 | mData->categories = c; | 1371 | mData->categories = c; |
1372 | } | 1372 | } |
1373 | 1373 | ||
1374 | QStringList Addressee::categories() const | 1374 | QStringList Addressee::categories() const |
1375 | { | 1375 | { |
1376 | return mData->categories; | 1376 | return mData->categories; |
1377 | } | 1377 | } |
1378 | 1378 | ||
1379 | void Addressee::insertCustom( const QString &app, const QString &name, | 1379 | void Addressee::insertCustom( const QString &app, const QString &name, |
1380 | const QString &value ) | 1380 | const QString &value ) |
1381 | { | 1381 | { |
1382 | if ( value.isNull() || name.isEmpty() || app.isEmpty() ) return; | 1382 | if ( value.isNull() || name.isEmpty() || app.isEmpty() ) return; |
1383 | 1383 | ||
1384 | detach(); | 1384 | detach(); |
1385 | mData->empty = false; | 1385 | mData->empty = false; |
1386 | 1386 | ||
1387 | QString qualifiedName = app + "-" + name + ":"; | 1387 | QString qualifiedName = app + "-" + name + ":"; |
1388 | 1388 | ||
1389 | QStringList::Iterator it; | 1389 | QStringList::Iterator it; |
1390 | for( it = mData->custom.begin(); it != mData->custom.end(); ++it ) { | 1390 | for( it = mData->custom.begin(); it != mData->custom.end(); ++it ) { |
1391 | if ( (*it).startsWith( qualifiedName ) ) { | 1391 | if ( (*it).startsWith( qualifiedName ) ) { |
1392 | (*it) = qualifiedName + value; | 1392 | (*it) = qualifiedName + value; |
1393 | return; | 1393 | return; |
1394 | } | 1394 | } |
1395 | } | 1395 | } |
1396 | 1396 | ||
1397 | mData->custom.append( qualifiedName + value ); | 1397 | mData->custom.append( qualifiedName + value ); |
1398 | } | 1398 | } |
1399 | 1399 | ||
1400 | void Addressee::removeCustom( const QString &app, const QString &name) | 1400 | void Addressee::removeCustom( const QString &app, const QString &name) |
1401 | { | 1401 | { |
1402 | detach(); | 1402 | detach(); |
1403 | 1403 | ||
1404 | QString qualifiedName = app + "-" + name + ":"; | 1404 | QString qualifiedName = app + "-" + name + ":"; |
1405 | 1405 | ||
1406 | QStringList::Iterator it; | 1406 | QStringList::Iterator it; |
1407 | for( it = mData->custom.begin(); it != mData->custom.end(); ++it ) { | 1407 | for( it = mData->custom.begin(); it != mData->custom.end(); ++it ) { |
1408 | if ( (*it).startsWith( qualifiedName ) ) { | 1408 | if ( (*it).startsWith( qualifiedName ) ) { |
1409 | mData->custom.remove( it ); | 1409 | mData->custom.remove( it ); |
1410 | return; | 1410 | return; |
1411 | } | 1411 | } |
1412 | } | 1412 | } |
1413 | } | 1413 | } |
1414 | 1414 | ||
1415 | QString Addressee::custom( const QString &app, const QString &name ) const | 1415 | QString Addressee::custom( const QString &app, const QString &name ) const |
1416 | { | 1416 | { |
1417 | QString qualifiedName = app + "-" + name + ":"; | 1417 | QString qualifiedName = app + "-" + name + ":"; |
1418 | QString value; | 1418 | QString value; |
1419 | 1419 | ||
1420 | QStringList::ConstIterator it; | 1420 | QStringList::ConstIterator it; |
1421 | for( it = mData->custom.begin(); it != mData->custom.end(); ++it ) { | 1421 | for( it = mData->custom.begin(); it != mData->custom.end(); ++it ) { |
1422 | if ( (*it).startsWith( qualifiedName ) ) { | 1422 | if ( (*it).startsWith( qualifiedName ) ) { |
1423 | value = (*it).mid( (*it).find( ":" ) + 1 ); | 1423 | value = (*it).mid( (*it).find( ":" ) + 1 ); |
1424 | break; | 1424 | break; |
1425 | } | 1425 | } |
1426 | } | 1426 | } |
1427 | 1427 | ||
1428 | return value; | 1428 | return value; |
1429 | } | 1429 | } |
1430 | 1430 | ||
1431 | void Addressee::setCustoms( const QStringList &l ) | 1431 | void Addressee::setCustoms( const QStringList &l ) |
1432 | { | 1432 | { |
1433 | detach(); | 1433 | detach(); |
1434 | mData->empty = false; | 1434 | mData->empty = false; |
1435 | 1435 | ||
1436 | mData->custom = l; | 1436 | mData->custom = l; |
1437 | } | 1437 | } |
1438 | 1438 | ||
1439 | QStringList Addressee::customs() const | 1439 | QStringList Addressee::customs() const |
1440 | { | 1440 | { |
1441 | return mData->custom; | 1441 | return mData->custom; |
1442 | } | 1442 | } |
1443 | 1443 | ||
1444 | void Addressee::parseEmailAddress( const QString &rawEmail, QString &fullName, | 1444 | void Addressee::parseEmailAddress( const QString &rawEmail, QString &fullName, |
1445 | QString &email) | 1445 | QString &email) |
1446 | { | 1446 | { |
1447 | int startPos, endPos, len; | 1447 | int startPos, endPos, len; |
1448 | QString partA, partB, result; | 1448 | QString partA, partB, result; |
1449 | char endCh = '>'; | 1449 | char endCh = '>'; |
1450 | 1450 | ||
1451 | startPos = rawEmail.find('<'); | 1451 | startPos = rawEmail.find('<'); |
1452 | if (startPos < 0) | 1452 | if (startPos < 0) |
1453 | { | 1453 | { |
1454 | startPos = rawEmail.find('('); | 1454 | startPos = rawEmail.find('('); |
1455 | endCh = ')'; | 1455 | endCh = ')'; |
1456 | } | 1456 | } |
1457 | if (startPos < 0) | 1457 | if (startPos < 0) |
1458 | { | 1458 | { |
1459 | // We couldn't find any separators, so we assume the whole string | 1459 | // We couldn't find any separators, so we assume the whole string |
1460 | // is the email address | 1460 | // is the email address |
1461 | email = rawEmail; | 1461 | email = rawEmail; |
1462 | fullName = ""; | 1462 | fullName = ""; |
1463 | } | 1463 | } |
1464 | else | 1464 | else |
1465 | { | 1465 | { |
1466 | // We have a start position, try to find an end | 1466 | // We have a start position, try to find an end |
1467 | endPos = rawEmail.find(endCh, startPos+1); | 1467 | endPos = rawEmail.find(endCh, startPos+1); |
1468 | 1468 | ||
1469 | if (endPos < 0) | 1469 | if (endPos < 0) |
1470 | { | 1470 | { |
1471 | // We couldn't find the end of the email address. We can only | 1471 | // We couldn't find the end of the email address. We can only |
1472 | // assume the entire string is the email address. | 1472 | // assume the entire string is the email address. |
1473 | email = rawEmail; | 1473 | email = rawEmail; |
1474 | fullName = ""; | 1474 | fullName = ""; |
1475 | } | 1475 | } |
1476 | else | 1476 | else |
1477 | { | 1477 | { |
1478 | // We have a start and end to the email address | 1478 | // We have a start and end to the email address |
1479 | 1479 | ||
1480 | // Grab the name part | 1480 | // Grab the name part |
1481 | fullName = rawEmail.left(startPos).stripWhiteSpace(); | 1481 | fullName = rawEmail.left(startPos).stripWhiteSpace(); |
1482 | 1482 | ||
1483 | // grab the email part | 1483 | // grab the email part |
1484 | email = rawEmail.mid(startPos+1, endPos-startPos-1).stripWhiteSpace(); | 1484 | email = rawEmail.mid(startPos+1, endPos-startPos-1).stripWhiteSpace(); |
1485 | 1485 | ||
1486 | // Check that we do not have any extra characters on the end of the | 1486 | // Check that we do not have any extra characters on the end of the |
1487 | // strings | 1487 | // strings |
1488 | len = fullName.length(); | 1488 | len = fullName.length(); |
1489 | if (fullName[0]=='"' && fullName[len-1]=='"') | 1489 | if (fullName[0]=='"' && fullName[len-1]=='"') |
1490 | fullName = fullName.mid(1, len-2); | 1490 | fullName = fullName.mid(1, len-2); |
1491 | else if (fullName[0]=='<' && fullName[len-1]=='>') | 1491 | else if (fullName[0]=='<' && fullName[len-1]=='>') |
1492 | fullName = fullName.mid(1, len-2); | 1492 | fullName = fullName.mid(1, len-2); |
1493 | else if (fullName[0]=='(' && fullName[len-1]==')') | 1493 | else if (fullName[0]=='(' && fullName[len-1]==')') |
1494 | fullName = fullName.mid(1, len-2); | 1494 | fullName = fullName.mid(1, len-2); |
1495 | } | 1495 | } |
1496 | } | 1496 | } |
1497 | } | 1497 | } |
1498 | 1498 | ||
1499 | void Addressee::setResource( Resource *resource ) | 1499 | void Addressee::setResource( Resource *resource ) |
1500 | { | 1500 | { |
1501 | detach(); | 1501 | detach(); |
1502 | mData->resource = resource; | 1502 | mData->resource = resource; |
1503 | } | 1503 | } |
1504 | 1504 | ||
1505 | Resource *Addressee::resource() const | 1505 | Resource *Addressee::resource() const |
1506 | { | 1506 | { |
1507 | return mData->resource; | 1507 | return mData->resource; |
1508 | } | 1508 | } |
1509 | 1509 | ||
1510 | //US | ||
1511 | QString Addressee::resourceLabel() | ||
1512 | { | ||
1513 | return i18n("Resource"); | ||
1514 | } | ||
1515 | |||
1510 | void Addressee::setChanged( bool value ) | 1516 | void Addressee::setChanged( bool value ) |
1511 | { | 1517 | { |
1512 | detach(); | 1518 | detach(); |
1513 | mData->changed = value; | 1519 | mData->changed = value; |
1514 | } | 1520 | } |
1515 | 1521 | ||
1516 | bool Addressee::changed() const | 1522 | bool Addressee::changed() const |
1517 | { | 1523 | { |
1518 | return mData->changed; | 1524 | return mData->changed; |
1519 | } | 1525 | } |
1520 | 1526 | ||
1521 | QDataStream &KABC::operator<<( QDataStream &s, const Addressee &a ) | 1527 | QDataStream &KABC::operator<<( QDataStream &s, const Addressee &a ) |
1522 | { | 1528 | { |
1523 | if (!a.mData) return s; | 1529 | if (!a.mData) return s; |
1524 | 1530 | ||
1525 | s << a.uid(); | 1531 | s << a.uid(); |
1526 | 1532 | ||
1527 | s << a.mData->name; | 1533 | s << a.mData->name; |
1528 | s << a.mData->formattedName; | 1534 | s << a.mData->formattedName; |
1529 | s << a.mData->familyName; | 1535 | s << a.mData->familyName; |
1530 | s << a.mData->givenName; | 1536 | s << a.mData->givenName; |
1531 | s << a.mData->additionalName; | 1537 | s << a.mData->additionalName; |
1532 | s << a.mData->prefix; | 1538 | s << a.mData->prefix; |
1533 | s << a.mData->suffix; | 1539 | s << a.mData->suffix; |
1534 | s << a.mData->nickName; | 1540 | s << a.mData->nickName; |
1535 | s << a.mData->birthday; | 1541 | s << a.mData->birthday; |
1536 | s << a.mData->mailer; | 1542 | s << a.mData->mailer; |
1537 | s << a.mData->timeZone; | 1543 | s << a.mData->timeZone; |
1538 | s << a.mData->geo; | 1544 | s << a.mData->geo; |
1539 | s << a.mData->title; | 1545 | s << a.mData->title; |
1540 | s << a.mData->role; | 1546 | s << a.mData->role; |
1541 | s << a.mData->organization; | 1547 | s << a.mData->organization; |
1542 | s << a.mData->note; | 1548 | s << a.mData->note; |
1543 | s << a.mData->productId; | 1549 | s << a.mData->productId; |
1544 | s << a.mData->revision; | 1550 | s << a.mData->revision; |
1545 | s << a.mData->sortString; | 1551 | s << a.mData->sortString; |
1546 | s << a.mData->url; | 1552 | s << a.mData->url; |
1547 | s << a.mData->secrecy; | 1553 | s << a.mData->secrecy; |
1548 | s << a.mData->logo; | 1554 | s << a.mData->logo; |
1549 | s << a.mData->photo; | 1555 | s << a.mData->photo; |
1550 | s << a.mData->sound; | 1556 | s << a.mData->sound; |
1551 | s << a.mData->agent; | 1557 | s << a.mData->agent; |
1552 | s << a.mData->phoneNumbers; | 1558 | s << a.mData->phoneNumbers; |
1553 | s << a.mData->addresses; | 1559 | s << a.mData->addresses; |
1554 | s << a.mData->emails; | 1560 | s << a.mData->emails; |
1555 | s << a.mData->categories; | 1561 | s << a.mData->categories; |
1556 | s << a.mData->custom; | 1562 | s << a.mData->custom; |
1557 | s << a.mData->keys; | 1563 | s << a.mData->keys; |
1558 | return s; | 1564 | return s; |
1559 | } | 1565 | } |
1560 | 1566 | ||
1561 | QDataStream &KABC::operator>>( QDataStream &s, Addressee &a ) | 1567 | QDataStream &KABC::operator>>( QDataStream &s, Addressee &a ) |
1562 | { | 1568 | { |
1563 | if (!a.mData) return s; | 1569 | if (!a.mData) return s; |
1564 | 1570 | ||
1565 | s >> a.mData->uid; | 1571 | s >> a.mData->uid; |
1566 | 1572 | ||
1567 | s >> a.mData->name; | 1573 | s >> a.mData->name; |
1568 | s >> a.mData->formattedName; | 1574 | s >> a.mData->formattedName; |
1569 | s >> a.mData->familyName; | 1575 | s >> a.mData->familyName; |
1570 | s >> a.mData->givenName; | 1576 | s >> a.mData->givenName; |
1571 | s >> a.mData->additionalName; | 1577 | s >> a.mData->additionalName; |
1572 | s >> a.mData->prefix; | 1578 | s >> a.mData->prefix; |
1573 | s >> a.mData->suffix; | 1579 | s >> a.mData->suffix; |
1574 | s >> a.mData->nickName; | 1580 | s >> a.mData->nickName; |
1575 | s >> a.mData->birthday; | 1581 | s >> a.mData->birthday; |
1576 | s >> a.mData->mailer; | 1582 | s >> a.mData->mailer; |
1577 | s >> a.mData->timeZone; | 1583 | s >> a.mData->timeZone; |
1578 | s >> a.mData->geo; | 1584 | s >> a.mData->geo; |
1579 | s >> a.mData->title; | 1585 | s >> a.mData->title; |
1580 | s >> a.mData->role; | 1586 | s >> a.mData->role; |
1581 | s >> a.mData->organization; | 1587 | s >> a.mData->organization; |
1582 | s >> a.mData->note; | 1588 | s >> a.mData->note; |
1583 | s >> a.mData->productId; | 1589 | s >> a.mData->productId; |
1584 | s >> a.mData->revision; | 1590 | s >> a.mData->revision; |
1585 | s >> a.mData->sortString; | 1591 | s >> a.mData->sortString; |
1586 | s >> a.mData->url; | 1592 | s >> a.mData->url; |
1587 | s >> a.mData->secrecy; | 1593 | s >> a.mData->secrecy; |
1588 | s >> a.mData->logo; | 1594 | s >> a.mData->logo; |
1589 | s >> a.mData->photo; | 1595 | s >> a.mData->photo; |
1590 | s >> a.mData->sound; | 1596 | s >> a.mData->sound; |
1591 | s >> a.mData->agent; | 1597 | s >> a.mData->agent; |
1592 | s >> a.mData->phoneNumbers; | 1598 | s >> a.mData->phoneNumbers; |
1593 | s >> a.mData->addresses; | 1599 | s >> a.mData->addresses; |
1594 | s >> a.mData->emails; | 1600 | s >> a.mData->emails; |
1595 | s >> a.mData->categories; | 1601 | s >> a.mData->categories; |
1596 | s >> a.mData->custom; | 1602 | s >> a.mData->custom; |
1597 | s >> a.mData->keys; | 1603 | s >> a.mData->keys; |
1598 | 1604 | ||
1599 | a.mData->empty = false; | 1605 | a.mData->empty = false; |
1600 | 1606 | ||
1601 | return s; | 1607 | return s; |
1602 | } | 1608 | } |
1603 | 1609 | ||
1604 | bool matchBinaryPattern( int value, int pattern ) | 1610 | bool matchBinaryPattern( int value, int pattern ) |
1605 | { | 1611 | { |
1606 | /** | 1612 | /** |
1607 | We want to match all telephonnumbers/addresses which have the bits in the | 1613 | We want to match all telephonnumbers/addresses which have the bits in the |
1608 | pattern set. More are allowed. | 1614 | pattern set. More are allowed. |
1609 | if pattern == 0 we have a special handling, then we want only those with | 1615 | if pattern == 0 we have a special handling, then we want only those with |
1610 | exactly no bit set. | 1616 | exactly no bit set. |
1611 | */ | 1617 | */ |
1612 | if ( pattern == 0 ) | 1618 | if ( pattern == 0 ) |
1613 | return ( value == 0 ); | 1619 | return ( value == 0 ); |
1614 | else | 1620 | else |
1615 | return ( pattern == ( pattern & value ) ); | 1621 | return ( pattern == ( pattern & value ) ); |
1616 | } | 1622 | } |