author | ulf69 <ulf69> | 2004-08-20 00:36:50 (UTC) |
---|---|---|
committer | ulf69 <ulf69> | 2004-08-20 00:36:50 (UTC) |
commit | d39b363278224b969d4c2945d32968c980b5d842 (patch) (unidiff) | |
tree | 418087aff444216ddb08fcd94fa7fdbfa6d46947 | |
parent | f4149cef5f3be19d64c9c53130a62de0ec28ee44 (diff) | |
download | kdepimpi-d39b363278224b969d4c2945d32968c980b5d842.zip kdepimpi-d39b363278224b969d4c2945d32968c980b5d842.tar.gz kdepimpi-d39b363278224b969d4c2945d32968c980b5d842.tar.bz2 |
performance optimization during vCard loading
-rw-r--r-- | kabc/vcardformatimpl.cpp | 51 | ||||
-rw-r--r-- | kabc/vcardformatimpl.h | 4 |
2 files changed, 29 insertions, 26 deletions
diff --git a/kabc/vcardformatimpl.cpp b/kabc/vcardformatimpl.cpp index 3fcaf94..bd9a57b 100644 --- a/kabc/vcardformatimpl.cpp +++ b/kabc/vcardformatimpl.cpp | |||
@@ -32,120 +32,122 @@ $Id$ | |||
32 | #include <kmdcodec.h> | 32 | #include <kmdcodec.h> |
33 | #include <kstandarddirs.h> | 33 | #include <kstandarddirs.h> |
34 | #include <ktempfile.h> | 34 | #include <ktempfile.h> |
35 | 35 | ||
36 | #include <VCard.h> | 36 | #include <VCard.h> |
37 | 37 | ||
38 | #include "addressbook.h" | 38 | #include "addressbook.h" |
39 | #include "vcardformatimpl.h" | 39 | #include "vcardformatimpl.h" |
40 | 40 | ||
41 | using namespace KABC; | 41 | using namespace KABC; |
42 | using namespace VCARD; | 42 | using namespace VCARD; |
43 | 43 | ||
44 | bool VCardFormatImpl::load( Addressee &addressee, QFile *file ) | 44 | bool VCardFormatImpl::load( Addressee &addressee, QFile *file ) |
45 | { | 45 | { |
46 | kdDebug(5700) << "VCardFormat::load()" << endl; | 46 | kdDebug(5700) << "VCardFormat::load()" << endl; |
47 | 47 | ||
48 | QByteArray fdata = file->readAll(); | 48 | QByteArray fdata = file->readAll(); |
49 | QCString data(fdata.data(), fdata.size()+1); | 49 | QCString data(fdata.data(), fdata.size()+1); |
50 | 50 | ||
51 | VCardEntity e( data ); | 51 | VCardEntity e( data ); |
52 | 52 | ||
53 | VCardListIterator it( e.cardList() ); | 53 | VCardListIterator it( e.cardList() ); |
54 | 54 | ||
55 | if ( it.current() ) { | 55 | if ( it.current() ) { |
56 | VCard v(*it.current()); | 56 | //US VCard v(*it.current()); |
57 | loadAddressee( addressee, v ); | 57 | //US loadAddressee( addressee, v ); |
58 | loadAddressee( addressee, it.current() ); | ||
58 | return true; | 59 | return true; |
59 | } | 60 | } |
60 | 61 | ||
61 | return false; | 62 | return false; |
62 | } | 63 | } |
63 | 64 | ||
64 | bool VCardFormatImpl::loadAll( AddressBook *addressBook, Resource *resource, QFile *file ) | 65 | bool VCardFormatImpl::loadAll( AddressBook *addressBook, Resource *resource, QFile *file ) |
65 | { | 66 | { |
66 | kdDebug(5700) << "VCardFormat::loadAll()" << endl; | 67 | kdDebug(5700) << "VCardFormat::loadAll()" << endl; |
67 | 68 | ||
68 | QByteArray fdata = file->readAll(); | 69 | QByteArray fdata = file->readAll(); |
69 | QCString data(fdata.data(), fdata.size()+1); | 70 | QCString data(fdata.data(), fdata.size()+1); |
70 | 71 | ||
71 | VCardEntity e( data ); | 72 | VCardEntity e( data ); |
72 | 73 | ||
73 | VCardListIterator it( e.cardList() ); | 74 | VCardListIterator it( e.cardList() ); |
74 | 75 | ||
75 | for (; it.current(); ++it) { | 76 | for (; it.current(); ++it) { |
76 | VCard v(*it.current()); | 77 | //US VCard v(*it.current()); |
77 | Addressee addressee; | 78 | Addressee addressee; |
78 | loadAddressee( addressee, v ); | 79 | //US loadAddressee( addressee, v ); |
80 | loadAddressee( addressee, it.current() ); | ||
79 | addressee.setResource( resource ); | 81 | addressee.setResource( resource ); |
80 | addressBook->insertAddressee( addressee ); | 82 | addressBook->insertAddressee( addressee ); |
81 | } | 83 | } |
82 | 84 | ||
83 | return true; | 85 | return true; |
84 | } | 86 | } |
85 | 87 | ||
86 | void VCardFormatImpl::save( const Addressee &addressee, QFile *file ) | 88 | void VCardFormatImpl::save( const Addressee &addressee, QFile *file ) |
87 | { | 89 | { |
88 | VCardEntity vcards; | 90 | VCardEntity vcards; |
89 | VCardList vcardlist; | 91 | VCardList vcardlist; |
90 | vcardlist.setAutoDelete( true ); | 92 | vcardlist.setAutoDelete( true ); |
91 | 93 | ||
92 | VCard *v = new VCard; | 94 | VCard *v = new VCard; |
93 | 95 | ||
94 | saveAddressee( addressee, v, false ); | 96 | saveAddressee( addressee, v, false ); |
95 | 97 | ||
96 | vcardlist.append( v ); | 98 | vcardlist.append( v ); |
97 | vcards.setCardList( vcardlist ); | 99 | vcards.setCardList( vcardlist ); |
98 | 100 | ||
99 | QCString vcardData = vcards.asString(); | 101 | QCString vcardData = vcards.asString(); |
100 | file->writeBlock( (const char*)vcardData, vcardData.length() ); | 102 | file->writeBlock( (const char*)vcardData, vcardData.length() ); |
101 | } | 103 | } |
102 | 104 | ||
103 | void VCardFormatImpl::saveAll( AddressBook *ab, Resource *resource, QFile *file ) | 105 | void VCardFormatImpl::saveAll( AddressBook *ab, Resource *resource, QFile *file ) |
104 | { | 106 | { |
105 | VCardEntity vcards; | 107 | VCardEntity vcards; |
106 | VCardList vcardlist; | 108 | VCardList vcardlist; |
107 | vcardlist.setAutoDelete( true ); | 109 | vcardlist.setAutoDelete( true ); |
108 | 110 | ||
109 | AddressBook::Iterator it; | 111 | AddressBook::Iterator it; |
110 | for ( it = ab->begin(); it != ab->end(); ++it ) { | 112 | for ( it = ab->begin(); it != ab->end(); ++it ) { |
111 | if ( (*it).resource() == resource ) { | 113 | if ( (*it).resource() == resource ) { |
112 | VCard *v = new VCard; | 114 | VCard *v = new VCard; |
113 | saveAddressee( (*it), v, false ); | 115 | saveAddressee( (*it), v, false ); |
114 | (*it).setChanged( false ); | 116 | (*it).setChanged( false ); |
115 | vcardlist.append( v ); | 117 | vcardlist.append( v ); |
116 | } | 118 | } |
117 | } | 119 | } |
118 | 120 | ||
119 | vcards.setCardList( vcardlist ); | 121 | vcards.setCardList( vcardlist ); |
120 | 122 | ||
121 | QCString vcardData = vcards.asString(); | 123 | QCString vcardData = vcards.asString(); |
122 | file->writeBlock( (const char*)vcardData, vcardData.length() ); | 124 | file->writeBlock( (const char*)vcardData, vcardData.length() ); |
123 | } | 125 | } |
124 | 126 | ||
125 | bool VCardFormatImpl::loadAddressee( Addressee& addressee, VCard &v ) | 127 | bool VCardFormatImpl::loadAddressee( Addressee& addressee, VCard *v ) |
126 | { | 128 | { |
127 | QPtrList<ContentLine> contentLines = v.contentLineList(); | 129 | QPtrList<ContentLine> contentLines = v->contentLineList(); |
128 | ContentLine *cl; | 130 | ContentLine *cl; |
129 | 131 | ||
130 | for( cl = contentLines.first(); cl; cl = contentLines.next() ) { | 132 | for( cl = contentLines.first(); cl; cl = contentLines.next() ) { |
131 | QCString n = cl->name(); | 133 | QCString n = cl->name(); |
132 | if ( n.left( 2 ) == "X-" ) { | 134 | if ( n.left( 2 ) == "X-" ) { |
133 | n = n.mid( 2 ); | 135 | n = n.mid( 2 ); |
134 | int posDash = n.find( "-" ); | 136 | int posDash = n.find( "-" ); |
135 | addressee.insertCustom( QString::fromUtf8( n.left( posDash ) ), | 137 | addressee.insertCustom( QString::fromUtf8( n.left( posDash ) ), |
136 | QString::fromUtf8( n.mid( posDash + 1 ) ), | 138 | QString::fromUtf8( n.mid( posDash + 1 ) ), |
137 | QString::fromUtf8( cl->value()->asString() ) ); | 139 | QString::fromUtf8( cl->value()->asString() ) ); |
138 | continue; | 140 | continue; |
139 | } | 141 | } |
140 | 142 | ||
141 | EntityType type = cl->entityType(); | 143 | EntityType type = cl->entityType(); |
142 | switch( type ) { | 144 | switch( type ) { |
143 | 145 | ||
144 | case EntityUID: | 146 | case EntityUID: |
145 | addressee.setUid( readTextValue( cl ) ); | 147 | addressee.setUid( readTextValue( cl ) ); |
146 | break; | 148 | break; |
147 | 149 | ||
148 | case EntityEmail: | 150 | case EntityEmail: |
149 | addressee.insertEmail( readTextValue( cl ) ); | 151 | addressee.insertEmail( readTextValue( cl ) ); |
150 | break; | 152 | break; |
151 | 153 | ||
@@ -763,146 +765,146 @@ Key VCardFormatImpl::readKeyValue( VCARD::ContentLine *cl ) | |||
763 | key.setTextData( QString::fromUtf8( v->asString() ) ); | 765 | key.setTextData( QString::fromUtf8( v->asString() ) ); |
764 | } | 766 | } |
765 | 767 | ||
766 | return key; | 768 | return key; |
767 | } | 769 | } |
768 | 770 | ||
769 | 771 | ||
770 | void VCardFormatImpl::addAgentValue( VCARD::VCard *vcard, const Agent &agent ) | 772 | void VCardFormatImpl::addAgentValue( VCARD::VCard *vcard, const Agent &agent ) |
771 | { | 773 | { |
772 | if ( agent.isIntern() && !agent.addressee() ) | 774 | if ( agent.isIntern() && !agent.addressee() ) |
773 | return; | 775 | return; |
774 | 776 | ||
775 | if ( !agent.isIntern() && agent.url().isEmpty() ) | 777 | if ( !agent.isIntern() && agent.url().isEmpty() ) |
776 | return; | 778 | return; |
777 | 779 | ||
778 | ContentLine cl; | 780 | ContentLine cl; |
779 | cl.setName( EntityTypeToParamName( EntityAgent ) ); | 781 | cl.setName( EntityTypeToParamName( EntityAgent ) ); |
780 | 782 | ||
781 | ParamList params; | 783 | ParamList params; |
782 | if ( agent.isIntern() ) { | 784 | if ( agent.isIntern() ) { |
783 | QString vstr; | 785 | QString vstr; |
784 | Addressee *addr = agent.addressee(); | 786 | Addressee *addr = agent.addressee(); |
785 | if ( addr ) { | 787 | if ( addr ) { |
786 | writeToString( (*addr), vstr ); | 788 | writeToString( (*addr), vstr ); |
787 | 789 | ||
788 | qDebug("VCardFormatImpl::addAgentValue please verify if replace is correct"); | 790 | qDebug("VCardFormatImpl::addAgentValue please verify if replace is correct"); |
789 | /*US | 791 | /*US |
790 | vstr.replace( ":", "\\:" ); | 792 | vstr.replace( ":", "\\:" ); |
791 | vstr.replace( ",", "\\," ); | 793 | vstr.replace( ",", "\\," ); |
792 | vstr.replace( ";", "\\;" ); | 794 | vstr.replace( ";", "\\;" ); |
793 | vstr.replace( "\r\n", "\\n" ); | 795 | vstr.replace( "\r\n", "\\n" ); |
794 | */ | 796 | */ |
795 | vstr.replace( QRegExp(":"), "\\:" ); | 797 | vstr.replace( QRegExp(":"), "\\:" ); |
796 | vstr.replace( QRegExp(","), "\\," ); | 798 | vstr.replace( QRegExp(","), "\\," ); |
797 | vstr.replace( QRegExp(";"), "\\;" ); | 799 | vstr.replace( QRegExp(";"), "\\;" ); |
798 | vstr.replace( QRegExp("\r\n"), "\\n" ); | 800 | vstr.replace( QRegExp("\r\n"), "\\n" ); |
799 | 801 | ||
800 | cl.setValue( new TextValue( vstr.utf8() ) ); | 802 | cl.setValue( new TextValue( vstr.utf8() ) ); |
801 | } else | 803 | } else |
802 | return; | 804 | return; |
803 | } else { | 805 | } else { |
804 | cl.setValue( new TextValue( agent.url().utf8() ) ); | 806 | cl.setValue( new TextValue( agent.url().utf8() ) ); |
805 | params.append( new Param( "VALUE", "uri" ) ); | 807 | params.append( new Param( "VALUE", "uri" ) ); |
806 | } | 808 | } |
807 | 809 | ||
808 | cl.setParamList( params ); | 810 | cl.setParamList( params ); |
809 | vcard->add( cl ); | 811 | vcard->add( cl ); |
810 | } | 812 | } |
811 | 813 | ||
812 | Agent VCardFormatImpl::readAgentValue( VCARD::ContentLine *cl ) | 814 | Agent VCardFormatImpl::readAgentValue( VCARD::ContentLine *cl ) |
813 | { | 815 | { |
814 | Agent agent; | 816 | Agent agent; |
815 | bool isIntern = true; | 817 | bool isIntern = true; |
816 | TextValue *v = (TextValue *)cl->value(); | 818 | TextValue *v = (TextValue *)cl->value(); |
817 | 819 | ||
818 | ParamList params = cl->paramList(); | 820 | ParamList params = cl->paramList(); |
819 | ParamListIterator it( params ); | 821 | ParamListIterator it( params ); |
820 | for( ; it.current(); ++it ) { | 822 | for( ; it.current(); ++it ) { |
821 | if ( (*it)->name() == "VALUE" && (*it)->value() == "uri" ) | 823 | if ( (*it)->name() == "VALUE" && (*it)->value() == "uri" ) |
822 | isIntern = false; | 824 | isIntern = false; |
823 | } | 825 | } |
824 | 826 | ||
825 | if ( isIntern ) { | 827 | if ( isIntern ) { |
826 | QString vstr = QString::fromUtf8( v->asString() ); | 828 | QString vstr = QString::fromUtf8( v->asString() ); |
827 | qDebug("VCardFormatImpl::addAgentValue please verify if replace is correct"); | 829 | qDebug("VCardFormatImpl::addAgentValue please verify if replace is correct"); |
828 | /*US | 830 | /*US |
829 | vstr.replace( "\\n", "\r\n" ); | 831 | vstr.replace( "\\n", "\r\n" ); |
830 | vstr.replace( "\\:", ":" ); | 832 | vstr.replace( "\\:", ":" ); |
831 | vstr.replace( "\\,", "," ); | 833 | vstr.replace( "\\,", "," ); |
832 | vstr.replace( "\\;", ";" ); | 834 | vstr.replace( "\\;", ";" ); |
833 | */ | 835 | */ |
834 | vstr.replace( QRegExp("\\n"), "\r\n" ); | 836 | vstr.replace( QRegExp("\\n"), "\r\n" ); |
835 | vstr.replace( QRegExp("\\:"), ":" ); | 837 | vstr.replace( QRegExp("\\:"), ":" ); |
836 | vstr.replace( QRegExp("\\,"), "," ); | 838 | vstr.replace( QRegExp("\\,"), "," ); |
837 | vstr.replace( QRegExp("\\;"), ";" ); | 839 | vstr.replace( QRegExp("\\;"), ";" ); |
838 | 840 | ||
839 | Addressee *addr = new Addressee; | 841 | Addressee *addr = new Addressee; |
840 | readFromString( vstr, *addr ); | 842 | readFromString( vstr, *addr ); |
841 | agent.setAddressee( addr ); | 843 | agent.setAddressee( addr ); |
842 | } else { | 844 | } else { |
843 | agent.setUrl( QString::fromUtf8( v->asString() ) ); | 845 | agent.setUrl( QString::fromUtf8( v->asString() ) ); |
844 | } | 846 | } |
845 | 847 | ||
846 | return agent; | 848 | return agent; |
847 | } | 849 | } |
848 | 850 | ||
849 | void VCardFormatImpl::addPictureValue( VCARD::VCard *vcard, VCARD::EntityType type, const Picture &pic, const Addressee &addr, bool intern ) | 851 | void VCardFormatImpl::addPictureValue( VCARD::VCard *vcard, VCARD::EntityType type, const Picture &pic, const Addressee &addr, bool intern ) |
850 | { | 852 | { |
851 | ContentLine cl; | 853 | ContentLine cl; |
852 | cl.setName( EntityTypeToParamName( type ) ); | 854 | cl.setName( EntityTypeToParamName( type ) ); |
853 | 855 | ||
854 | if ( pic.isIntern() && pic.data().isNull() ) | 856 | if ( pic.isIntern() && pic.data().isNull() ) |
855 | return; | 857 | return; |
856 | 858 | ||
857 | if ( !pic.isIntern() && pic.url().isEmpty() ) | 859 | if ( !pic.isIntern() && pic.url().isEmpty() ) |
858 | return; | 860 | return; |
859 | 861 | ||
860 | ParamList params; | 862 | ParamList params; |
861 | if ( pic.isIntern() ) { | 863 | if ( pic.isIntern() ) { |
862 | QImage img = pic.data(); | 864 | QImage img = pic.data(); |
863 | if ( intern ) { // only for vCard export we really write the data inline | 865 | if ( intern ) { // only for vCard export we really write the data inline |
864 | QByteArray data; | 866 | QByteArray data; |
865 | QDataStream s( data, IO_WriteOnly ); | 867 | QDataStream s( data, IO_WriteOnly ); |
866 | s.setVersion( 4 ); // to produce valid png files | 868 | s.setVersion( 4 ); // to produce valid png files |
867 | s << img; | 869 | s << img; |
868 | cl.setValue( new TextValue( KCodecs::base64Encode( data ) ) ); | 870 | cl.setValue( new TextValue( KCodecs::base64Encode( data ) ) ); |
869 | 871 | ||
870 | } else { // save picture in cache | 872 | } else { // save picture in cache |
871 | QString dir; | 873 | QString dir; |
872 | if ( type == EntityPhoto ) | 874 | if ( type == EntityPhoto ) |
873 | dir = "photos"; | 875 | dir = "photos"; |
874 | if ( type == EntityLogo ) | 876 | if ( type == EntityLogo ) |
875 | dir = "logos"; | 877 | dir = "logos"; |
876 | 878 | ||
877 | img.save( locateLocal( "data", "kabc/" + dir + "/" + addr.uid() ), pic.type().utf8() ); | 879 | img.save( locateLocal( "data", "kabc/" + dir + "/" + addr.uid() ), pic.type().utf8() ); |
878 | cl.setValue( new TextValue( "<dummy>" ) ); | 880 | cl.setValue( new TextValue( "<dummy>" ) ); |
879 | } | 881 | } |
880 | params.append( new Param( "ENCODING", "b" ) ); | 882 | params.append( new Param( "ENCODING", "b" ) ); |
881 | if ( !pic.type().isEmpty() ) | 883 | if ( !pic.type().isEmpty() ) |
882 | params.append( new Param( "TYPE", pic.type().utf8() ) ); | 884 | params.append( new Param( "TYPE", pic.type().utf8() ) ); |
883 | } else { | 885 | } else { |
884 | 886 | ||
885 | cl.setValue( new TextValue( pic.url().utf8() ) ); | 887 | cl.setValue( new TextValue( pic.url().utf8() ) ); |
886 | params.append( new Param( "VALUE", "uri" ) ); | 888 | params.append( new Param( "VALUE", "uri" ) ); |
887 | } | 889 | } |
888 | 890 | ||
889 | cl.setParamList( params ); | 891 | cl.setParamList( params ); |
890 | vcard->add( cl ); | 892 | vcard->add( cl ); |
891 | } | 893 | } |
892 | 894 | ||
893 | Picture VCardFormatImpl::readPictureValue( VCARD::ContentLine *cl, VCARD::EntityType type, const Addressee &addr ) | 895 | Picture VCardFormatImpl::readPictureValue( VCARD::ContentLine *cl, VCARD::EntityType type, const Addressee &addr ) |
894 | { | 896 | { |
895 | Picture pic; | 897 | Picture pic; |
896 | bool isInline = false; | 898 | bool isInline = false; |
897 | QString picType; | 899 | QString picType; |
898 | TextValue *v = (TextValue *)cl->value(); | 900 | TextValue *v = (TextValue *)cl->value(); |
899 | 901 | ||
900 | ParamList params = cl->paramList(); | 902 | ParamList params = cl->paramList(); |
901 | ParamListIterator it( params ); | 903 | ParamListIterator it( params ); |
902 | for( ; it.current(); ++it ) { | 904 | for( ; it.current(); ++it ) { |
903 | if ( (*it)->name() == "ENCODING" && (*it)->value() == "b" ) | 905 | if ( (*it)->name() == "ENCODING" && (*it)->value() == "b" ) |
904 | isInline = true; | 906 | isInline = true; |
905 | if ( (*it)->name() == "TYPE" && !(*it)->value().isEmpty() ) | 907 | if ( (*it)->name() == "TYPE" && !(*it)->value().isEmpty() ) |
906 | picType = QString::fromUtf8( (*it)->value() ); | 908 | picType = QString::fromUtf8( (*it)->value() ); |
907 | } | 909 | } |
908 | 910 | ||
@@ -980,48 +982,49 @@ Sound VCardFormatImpl::readSoundValue( VCARD::ContentLine *cl, const Addressee & | |||
980 | QByteArray data; | 982 | QByteArray data; |
981 | if ( v->asString() == "<dummy>" ) { // no sound inline stored => sound is in cache | 983 | if ( v->asString() == "<dummy>" ) { // no sound inline stored => sound is in cache |
982 | QFile file( locateLocal( "data", "kabc/sounds/" + addr.uid() ) ); | 984 | QFile file( locateLocal( "data", "kabc/sounds/" + addr.uid() ) ); |
983 | if ( file.open( IO_ReadOnly ) ) { | 985 | if ( file.open( IO_ReadOnly ) ) { |
984 | data = file.readAll(); | 986 | data = file.readAll(); |
985 | file.close(); | 987 | file.close(); |
986 | } | 988 | } |
987 | } else { | 989 | } else { |
988 | KCodecs::base64Decode( v->asString(), data ); | 990 | KCodecs::base64Decode( v->asString(), data ); |
989 | } | 991 | } |
990 | sound.setData( data ); | 992 | sound.setData( data ); |
991 | } else { | 993 | } else { |
992 | sound.setUrl( QString::fromUtf8( v->asString() ) ); | 994 | sound.setUrl( QString::fromUtf8( v->asString() ) ); |
993 | } | 995 | } |
994 | 996 | ||
995 | return sound; | 997 | return sound; |
996 | } | 998 | } |
997 | 999 | ||
998 | bool VCardFormatImpl::readFromString( const QString &vcard, Addressee &addressee ) | 1000 | bool VCardFormatImpl::readFromString( const QString &vcard, Addressee &addressee ) |
999 | { | 1001 | { |
1000 | VCardEntity e( vcard.utf8() ); | 1002 | VCardEntity e( vcard.utf8() ); |
1001 | VCardListIterator it( e.cardList() ); | 1003 | VCardListIterator it( e.cardList() ); |
1002 | 1004 | ||
1003 | if ( it.current() ) { | 1005 | if ( it.current() ) { |
1004 | VCard v(*it.current()); | 1006 | //US VCard v(*it.current()); |
1005 | loadAddressee( addressee, v ); | 1007 | //US loadAddressee( addressee, v ); |
1008 | loadAddressee( addressee, it.current() ); | ||
1006 | return true; | 1009 | return true; |
1007 | } | 1010 | } |
1008 | 1011 | ||
1009 | return false; | 1012 | return false; |
1010 | } | 1013 | } |
1011 | 1014 | ||
1012 | bool VCardFormatImpl::writeToString( const Addressee &addressee, QString &vcard ) | 1015 | bool VCardFormatImpl::writeToString( const Addressee &addressee, QString &vcard ) |
1013 | { | 1016 | { |
1014 | VCardEntity vcards; | 1017 | VCardEntity vcards; |
1015 | VCardList vcardlist; | 1018 | VCardList vcardlist; |
1016 | vcardlist.setAutoDelete( true ); | 1019 | vcardlist.setAutoDelete( true ); |
1017 | 1020 | ||
1018 | VCard *v = new VCard; | 1021 | VCard *v = new VCard; |
1019 | 1022 | ||
1020 | saveAddressee( addressee, v, true ); | 1023 | saveAddressee( addressee, v, true ); |
1021 | 1024 | ||
1022 | vcardlist.append( v ); | 1025 | vcardlist.append( v ); |
1023 | vcards.setCardList( vcardlist ); | 1026 | vcards.setCardList( vcardlist ); |
1024 | vcard = QString::fromUtf8( vcards.asString() ); | 1027 | vcard = QString::fromUtf8( vcards.asString() ); |
1025 | 1028 | ||
1026 | return true; | 1029 | return true; |
1027 | } | 1030 | } |
diff --git a/kabc/vcardformatimpl.h b/kabc/vcardformatimpl.h index 2dd68d9..fa3d55f 100644 --- a/kabc/vcardformatimpl.h +++ b/kabc/vcardformatimpl.h | |||
@@ -21,65 +21,65 @@ | |||
21 | /* | 21 | /* |
22 | Enhanced Version of the file for platform independent KDE tools. | 22 | Enhanced Version of the file for platform independent KDE tools. |
23 | Copyright (c) 2004 Ulf Schenk | 23 | Copyright (c) 2004 Ulf Schenk |
24 | 24 | ||
25 | $Id$ | 25 | $Id$ |
26 | */ | 26 | */ |
27 | 27 | ||
28 | #ifndef KABC_VCARDFORMATIMPL_H | 28 | #ifndef KABC_VCARDFORMATIMPL_H |
29 | #define KABC_VCARDFORMATIMPL_H | 29 | #define KABC_VCARDFORMATIMPL_H |
30 | 30 | ||
31 | #include <qstring.h> | 31 | #include <qstring.h> |
32 | #include <qfile.h> | 32 | #include <qfile.h> |
33 | 33 | ||
34 | #include "address.h" | 34 | #include "address.h" |
35 | #include "addressee.h" | 35 | #include "addressee.h" |
36 | 36 | ||
37 | #include <VCard.h> | 37 | #include <VCard.h> |
38 | 38 | ||
39 | namespace KABC { | 39 | namespace KABC { |
40 | 40 | ||
41 | class AddressBook; | 41 | class AddressBook; |
42 | 42 | ||
43 | /** | 43 | /** |
44 | @short Implementation of vCard backend for address book. | 44 | @short Implementation of vCard backend for address book. |
45 | 45 | ||
46 | This class implements reading and writing of address book information using | 46 | This class implements reading and writing of address book information using |
47 | the vCard format. It requires the vCard lib from kdepim. | 47 | the vCard format. It requires the vCard lib from kdepim. |
48 | */ | 48 | */ |
49 | class VCardFormatImpl | 49 | class VCardFormatImpl |
50 | { | 50 | { |
51 | public: | 51 | public: |
52 | bool load( Addressee &, QFile *file ); | 52 | bool load( Addressee &, QFile *file ); |
53 | bool loadAll( AddressBook *, Resource *, QFile *file ); | 53 | bool loadAll( AddressBook *, Resource *, QFile *file ); |
54 | void save( const Addressee &, QFile *file ); | 54 | void save( const Addressee &, QFile *file ); |
55 | void saveAll( AddressBook *, Resource *, QFile *file ); | 55 | void saveAll( AddressBook *, Resource *, QFile *file ); |
56 | 56 | ||
57 | bool readFromString( const QString &vcard, Addressee &addr ); | 57 | bool readFromString( const QString &vcard, Addressee &addr ); |
58 | bool writeToString( const Addressee &addressee, QString &vcard ); | 58 | bool writeToString( const Addressee &addressee, QString &vcard ); |
59 | 59 | ||
60 | protected: | 60 | protected: |
61 | bool loadAddressee( Addressee &, VCARD::VCard & ); | 61 | bool loadAddressee( Addressee &, VCARD::VCard * ); |
62 | void saveAddressee( const Addressee &, VCARD::VCard *, bool intern ); | 62 | void saveAddressee( const Addressee &, VCARD::VCard *, bool intern ); |
63 | 63 | ||
64 | void addTextValue (VCARD::VCard *, VCARD::EntityType, const QString & ); | 64 | void addTextValue (VCARD::VCard *, VCARD::EntityType, const QString & ); |
65 | QString readTextValue( VCARD::ContentLine * ); | 65 | QString readTextValue( VCARD::ContentLine * ); |
66 | 66 | ||
67 | void addDateValue( VCARD::VCard *, VCARD::EntityType, const QDate & ); | 67 | void addDateValue( VCARD::VCard *, VCARD::EntityType, const QDate & ); |
68 | QDate readDateValue( VCARD::ContentLine * ); | 68 | QDate readDateValue( VCARD::ContentLine * ); |
69 | 69 | ||
70 | void addDateTimeValue( VCARD::VCard *, VCARD::EntityType, const QDateTime & ); | 70 | void addDateTimeValue( VCARD::VCard *, VCARD::EntityType, const QDateTime & ); |
71 | QDateTime readDateTimeValue( VCARD::ContentLine * ); | 71 | QDateTime readDateTimeValue( VCARD::ContentLine * ); |
72 | 72 | ||
73 | void addAddressValue( VCARD::VCard *, const Address & ); | 73 | void addAddressValue( VCARD::VCard *, const Address & ); |
74 | Address readAddressValue( VCARD::ContentLine * ); | 74 | Address readAddressValue( VCARD::ContentLine * ); |
75 | 75 | ||
76 | void addLabelValue( VCARD::VCard *, const Address & ); | 76 | void addLabelValue( VCARD::VCard *, const Address & ); |
77 | 77 | ||
78 | void addTelephoneValue( VCARD::VCard *, const PhoneNumber & ); | 78 | void addTelephoneValue( VCARD::VCard *, const PhoneNumber & ); |
79 | PhoneNumber readTelephoneValue( VCARD::ContentLine * ); | 79 | PhoneNumber readTelephoneValue( VCARD::ContentLine * ); |
80 | 80 | ||
81 | void addNValue( VCARD::VCard *, const Addressee & ); | 81 | void addNValue( VCARD::VCard *, const Addressee & ); |
82 | void readNValue( VCARD::ContentLine *, Addressee & ); | 82 | void readNValue( VCARD::ContentLine *, Addressee & ); |
83 | 83 | ||
84 | void addCustomValue( VCARD::VCard *, const QString & ); | 84 | void addCustomValue( VCARD::VCard *, const QString & ); |
85 | 85 | ||