-rw-r--r-- | kabc/vcardformatimpl.cpp | 25 |
1 files changed, 14 insertions, 11 deletions
diff --git a/kabc/vcardformatimpl.cpp b/kabc/vcardformatimpl.cpp index 580c28b..2417874 100644 --- a/kabc/vcardformatimpl.cpp +++ b/kabc/vcardformatimpl.cpp | |||
@@ -23,16 +23,19 @@ 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 | #include <qfile.h> | 28 | #include <qfile.h> |
29 | #include <qregexp.h> | 29 | #include <qregexp.h> |
30 | #include <qapplication.h> | 30 | #include <qapplication.h> |
31 | //Added by qt3to4: | ||
32 | #include <Q3CString> | ||
33 | #include <Q3PtrList> | ||
31 | 34 | ||
32 | #include <kdebug.h> | 35 | #include <kdebug.h> |
33 | #include <kmdcodec.h> | 36 | #include <kmdcodec.h> |
34 | #include <kstandarddirs.h> | 37 | #include <kstandarddirs.h> |
35 | #include <ktempfile.h> | 38 | #include <ktempfile.h> |
36 | 39 | ||
37 | #include <VCard.h> | 40 | #include <VCard.h> |
38 | 41 | ||
@@ -49,17 +52,17 @@ VCardFormatImpl::VCardFormatImpl() | |||
49 | debug = (getenv("KABC_DEBUG") != 0); | 52 | debug = (getenv("KABC_DEBUG") != 0); |
50 | } | 53 | } |
51 | 54 | ||
52 | bool VCardFormatImpl::load( Addressee &addressee, QFile *file ) | 55 | bool VCardFormatImpl::load( Addressee &addressee, QFile *file ) |
53 | { | 56 | { |
54 | kdDebug(5700) << "VCardFormat::load()" << endl; | 57 | kdDebug(5700) << "VCardFormat::load()" << endl; |
55 | 58 | ||
56 | QByteArray fdata = file->readAll(); | 59 | QByteArray fdata = file->readAll(); |
57 | QCString data(fdata.data(), fdata.size()+1); | 60 | Q3CString data(fdata.data(), fdata.size()+1); |
58 | 61 | ||
59 | VCardEntity e( data ); | 62 | VCardEntity e( data ); |
60 | 63 | ||
61 | VCardListIterator it( e.cardList() ); | 64 | VCardListIterator it( e.cardList() ); |
62 | 65 | ||
63 | if ( it.current() ) { | 66 | if ( it.current() ) { |
64 | //US VCard v(*it.current()); | 67 | //US VCard v(*it.current()); |
65 | //US loadAddressee( addressee, v ); | 68 | //US loadAddressee( addressee, v ); |
@@ -70,17 +73,17 @@ bool VCardFormatImpl::load( Addressee &addressee, QFile *file ) | |||
70 | return false; | 73 | return false; |
71 | } | 74 | } |
72 | 75 | ||
73 | 76 | ||
74 | #include <kmessagebox.h> | 77 | #include <kmessagebox.h> |
75 | bool VCardFormatImpl::loadAll( AddressBook *addressBook, Resource *resource, QFile *file ) | 78 | bool VCardFormatImpl::loadAll( AddressBook *addressBook, Resource *resource, QFile *file ) |
76 | { | 79 | { |
77 | 80 | ||
78 | QCString data(file->readAll().data(), file->size()+1); | 81 | Q3CString data(file->readAll().data(), file->size()+1); |
79 | VCardEntity e( data ); | 82 | VCardEntity e( data ); |
80 | 83 | ||
81 | VCardListIterator it( e.cardList() ); | 84 | VCardListIterator it( e.cardList() ); |
82 | 85 | ||
83 | for (; it.current(); ++it) { | 86 | for (; it.current(); ++it) { |
84 | //US VCard v(*it.current()); | 87 | //US VCard v(*it.current()); |
85 | Addressee addressee; | 88 | Addressee addressee; |
86 | //US loadAddressee( addressee, v ); | 89 | //US loadAddressee( addressee, v ); |
@@ -103,17 +106,17 @@ void VCardFormatImpl::save( const Addressee &addressee, QFile *file ) | |||
103 | 106 | ||
104 | VCard *v = new VCard; | 107 | VCard *v = new VCard; |
105 | 108 | ||
106 | saveAddressee( addressee, v, false ); | 109 | saveAddressee( addressee, v, false ); |
107 | 110 | ||
108 | vcardlist.append( v ); | 111 | vcardlist.append( v ); |
109 | vcards.setCardList( vcardlist ); | 112 | vcards.setCardList( vcardlist ); |
110 | 113 | ||
111 | QCString vcardData = vcards.asString(); | 114 | Q3CString vcardData = vcards.asString(); |
112 | file->writeBlock( (const char*)vcardData, vcardData.length() ); | 115 | file->writeBlock( (const char*)vcardData, vcardData.length() ); |
113 | } | 116 | } |
114 | 117 | ||
115 | void VCardFormatImpl::saveAll( AddressBook *ab, Resource *resource, QFile *file ) | 118 | void VCardFormatImpl::saveAll( AddressBook *ab, Resource *resource, QFile *file ) |
116 | { | 119 | { |
117 | 120 | ||
118 | AddressBook::Iterator it; | 121 | AddressBook::Iterator it; |
119 | for ( it = ab->begin(); it != ab->end(); ++it ) { | 122 | for ( it = ab->begin(); it != ab->end(); ++it ) { |
@@ -124,21 +127,21 @@ void VCardFormatImpl::saveAll( AddressBook *ab, Resource *resource, QFile *file | |||
124 | } | 127 | } |
125 | } | 128 | } |
126 | // for memory usage status test only | 129 | // for memory usage status test only |
127 | // KMessageBox::information ( 0, "Stoppppp", QString("Stop ") ); | 130 | // KMessageBox::information ( 0, "Stoppppp", QString("Stop ") ); |
128 | } | 131 | } |
129 | 132 | ||
130 | bool VCardFormatImpl::loadAddressee( Addressee& addressee, VCard *v ) | 133 | bool VCardFormatImpl::loadAddressee( Addressee& addressee, VCard *v ) |
131 | { | 134 | { |
132 | QPtrList<ContentLine> contentLines = v->contentLineList(); | 135 | Q3PtrList<ContentLine> contentLines = v->contentLineList(); |
133 | ContentLine *cl; | 136 | ContentLine *cl; |
134 | 137 | ||
135 | for( cl = contentLines.first(); cl; cl = contentLines.next() ) { | 138 | for( cl = contentLines.first(); cl; cl = contentLines.next() ) { |
136 | QCString n = cl->name(); | 139 | Q3CString n = cl->name(); |
137 | if ( n.left( 2 ) == "X-" ) { | 140 | if ( n.left( 2 ) == "X-" ) { |
138 | n = n.mid( 2 ); | 141 | n = n.mid( 2 ); |
139 | int posDash = n.find( "-" ); | 142 | int posDash = n.find( "-" ); |
140 | addressee.insertCustom( QString::fromUtf8( n.left( posDash ) ), | 143 | addressee.insertCustom( QString::fromUtf8( n.left( posDash ) ), |
141 | QString::fromUtf8( n.mid( posDash + 1 ) ), | 144 | QString::fromUtf8( n.mid( posDash + 1 ) ), |
142 | QString::fromUtf8( cl->value()->asString() ) ); | 145 | QString::fromUtf8( cl->value()->asString() ) ); |
143 | continue; | 146 | continue; |
144 | } | 147 | } |
@@ -214,17 +217,17 @@ bool VCardFormatImpl::loadAddressee( Addressee& addressee, VCard *v ) | |||
214 | addressee.insertPhoneNumber( readTelephoneValue( cl ) ); | 217 | addressee.insertPhoneNumber( readTelephoneValue( cl ) ); |
215 | break; | 218 | break; |
216 | 219 | ||
217 | case EntityCategories: | 220 | case EntityCategories: |
218 | addressee.setCategories( QStringList::split( ",", readTextValue( cl ) ) ); | 221 | addressee.setCategories( QStringList::split( ",", readTextValue( cl ) ) ); |
219 | break; | 222 | break; |
220 | 223 | ||
221 | case EntityBirthday: | 224 | case EntityBirthday: |
222 | addressee.setBirthday( readDateValue( cl ) ); | 225 | addressee.setBirthday( (QDateTime) readDateValue( cl ) ); |
223 | break; | 226 | break; |
224 | 227 | ||
225 | case EntityRevision: | 228 | case EntityRevision: |
226 | addressee.setRevision( readDateTimeValue( cl ) ); | 229 | addressee.setRevision( readDateTimeValue( cl ) ); |
227 | break; | 230 | break; |
228 | 231 | ||
229 | case EntityGeo: | 232 | case EntityGeo: |
230 | addressee.setGeo( readGeoValue( cl ) ); | 233 | addressee.setGeo( readGeoValue( cl ) ); |
@@ -525,17 +528,17 @@ Address VCardFormatImpl::readAddressValue( ContentLine *cl ) | |||
525 | return a; | 528 | return a; |
526 | } | 529 | } |
527 | 530 | ||
528 | int VCardFormatImpl::readAddressParam( ContentLine *cl ) | 531 | int VCardFormatImpl::readAddressParam( ContentLine *cl ) |
529 | { | 532 | { |
530 | int type = 0; | 533 | int type = 0; |
531 | ParamList params = cl->paramList(); | 534 | ParamList params = cl->paramList(); |
532 | ParamListIterator it( params ); | 535 | ParamListIterator it( params ); |
533 | QCString tmpStr; | 536 | Q3CString tmpStr; |
534 | for( ; it.current(); ++it ) { | 537 | for( ; it.current(); ++it ) { |
535 | if ( (*it)->name().upper() == "TYPE" ) { | 538 | if ( (*it)->name().upper() == "TYPE" ) { |
536 | tmpStr = (*it)->value().lower(); | 539 | tmpStr = (*it)->value().lower(); |
537 | if ( tmpStr == "dom" ) type |= Address::Dom; | 540 | if ( tmpStr == "dom" ) type |= Address::Dom; |
538 | else if ( tmpStr == "intl" ) type |= Address::Intl; | 541 | else if ( tmpStr == "intl" ) type |= Address::Intl; |
539 | else if ( tmpStr == "parcel" ) type |= Address::Parcel; | 542 | else if ( tmpStr == "parcel" ) type |= Address::Parcel; |
540 | else if ( tmpStr == "postal" ) type |= Address::Postal; | 543 | else if ( tmpStr == "postal" ) type |= Address::Postal; |
541 | else if ( tmpStr == "work" ) type |= Address::Work; | 544 | else if ( tmpStr == "work" ) type |= Address::Work; |
@@ -604,17 +607,17 @@ PhoneNumber VCardFormatImpl::readTelephoneValue( ContentLine *cl ) | |||
604 | { | 607 | { |
605 | PhoneNumber p; | 608 | PhoneNumber p; |
606 | TelValue *value = (TelValue *)cl->value(); | 609 | TelValue *value = (TelValue *)cl->value(); |
607 | p.setNumber( QString::fromUtf8( value->asString() ) ); | 610 | p.setNumber( QString::fromUtf8( value->asString() ) ); |
608 | 611 | ||
609 | int type = 0; | 612 | int type = 0; |
610 | ParamList params = cl->paramList(); | 613 | ParamList params = cl->paramList(); |
611 | ParamListIterator it( params ); | 614 | ParamListIterator it( params ); |
612 | QCString tmpStr; | 615 | Q3CString tmpStr; |
613 | for( ; it.current(); ++it ) { | 616 | for( ; it.current(); ++it ) { |
614 | if ( (*it)->name() == "TYPE" ) { | 617 | if ( (*it)->name() == "TYPE" ) { |
615 | tmpStr = (*it)->value().lower(); | 618 | tmpStr = (*it)->value().lower(); |
616 | if ( tmpStr == "home" ) type |= PhoneNumber::Home; | 619 | if ( tmpStr == "home" ) type |= PhoneNumber::Home; |
617 | else if ( tmpStr == "work" ) type |= PhoneNumber::Work; | 620 | else if ( tmpStr == "work" ) type |= PhoneNumber::Work; |
618 | else if ( tmpStr == "msg" ) type |= PhoneNumber::Msg; | 621 | else if ( tmpStr == "msg" ) type |= PhoneNumber::Msg; |
619 | else if ( tmpStr == "pref" ) type |= PhoneNumber::Pref; | 622 | else if ( tmpStr == "pref" ) type |= PhoneNumber::Pref; |
620 | else if ( tmpStr == "voice" ) type |= PhoneNumber::Voice; | 623 | else if ( tmpStr == "voice" ) type |= PhoneNumber::Voice; |
@@ -865,17 +868,17 @@ void VCardFormatImpl::addPictureValue( VCARD::VCard *vcard, VCARD::EntityType ty | |||
865 | if ( !pic.isIntern() && pic.url().isEmpty() ) | 868 | if ( !pic.isIntern() && pic.url().isEmpty() ) |
866 | return; | 869 | return; |
867 | 870 | ||
868 | ParamList params; | 871 | ParamList params; |
869 | if ( pic.isIntern() ) { | 872 | if ( pic.isIntern() ) { |
870 | QImage img = pic.data(); | 873 | QImage img = pic.data(); |
871 | if ( intern ) { // only for vCard export we really write the data inline | 874 | if ( intern ) { // only for vCard export we really write the data inline |
872 | QByteArray data; | 875 | QByteArray data; |
873 | QDataStream s( data, IO_WriteOnly ); | 876 | QDataStream s( &data, QIODevice::WriteOnly ); |
874 | s.setVersion( 4 ); // to produce valid png files | 877 | s.setVersion( 4 ); // to produce valid png files |
875 | s << img; | 878 | s << img; |
876 | cl.setValue( new TextValue( KCodecs::base64Encode( data ) ) ); | 879 | cl.setValue( new TextValue( KCodecs::base64Encode( data ) ) ); |
877 | params.append( new Param( "ENCODING", "b" ) ); | 880 | params.append( new Param( "ENCODING", "b" ) ); |
878 | if ( !pic.type().isEmpty() ) | 881 | if ( !pic.type().isEmpty() ) |
879 | params.append( new Param( "TYPE", pic.type().utf8() ) ); | 882 | params.append( new Param( "TYPE", pic.type().utf8() ) ); |
880 | } else { // save picture in cache | 883 | } else { // save picture in cache |
881 | QString dir; | 884 | QString dir; |
@@ -954,17 +957,17 @@ void VCardFormatImpl::addSoundValue( VCARD::VCard *vcard, const Sound &sound, co | |||
954 | 957 | ||
955 | ParamList params; | 958 | ParamList params; |
956 | if ( sound.isIntern() ) { | 959 | if ( sound.isIntern() ) { |
957 | QByteArray data = sound.data(); | 960 | QByteArray data = sound.data(); |
958 | if ( intern ) { // only for vCard export we really write the data inline | 961 | if ( intern ) { // only for vCard export we really write the data inline |
959 | cl.setValue( new TextValue( KCodecs::base64Encode( data ) ) ); | 962 | cl.setValue( new TextValue( KCodecs::base64Encode( data ) ) ); |
960 | } else { // save sound in cache | 963 | } else { // save sound in cache |
961 | QFile file( locateLocal( "data", "kabc/sounds/" + addr.uid() ) ); | 964 | QFile file( locateLocal( "data", "kabc/sounds/" + addr.uid() ) ); |
962 | if ( file.open( IO_WriteOnly ) ) { | 965 | if ( file.open( QIODevice::WriteOnly ) ) { |
963 | file.writeBlock( data ); | 966 | file.writeBlock( data ); |
964 | } | 967 | } |
965 | cl.setValue( new TextValue( "<dummy>" ) ); | 968 | cl.setValue( new TextValue( "<dummy>" ) ); |
966 | } | 969 | } |
967 | params.append( new Param( "ENCODING", "b" ) ); | 970 | params.append( new Param( "ENCODING", "b" ) ); |
968 | } else { | 971 | } else { |
969 | cl.setValue( new TextValue( sound.url().utf8() ) ); | 972 | cl.setValue( new TextValue( sound.url().utf8() ) ); |
970 | params.append( new Param( "VALUE", "uri" ) ); | 973 | params.append( new Param( "VALUE", "uri" ) ); |
@@ -986,17 +989,17 @@ Sound VCardFormatImpl::readSoundValue( VCARD::ContentLine *cl, const Addressee & | |||
986 | if ( (*it)->name() == "ENCODING" && (*it)->value() == "b" ) | 989 | if ( (*it)->name() == "ENCODING" && (*it)->value() == "b" ) |
987 | isInline = true; | 990 | isInline = true; |
988 | } | 991 | } |
989 | 992 | ||
990 | if ( isInline ) { | 993 | if ( isInline ) { |
991 | QByteArray data; | 994 | QByteArray data; |
992 | if ( v->asString() == "<dummy>" ) { // no sound inline stored => sound is in cache | 995 | if ( v->asString() == "<dummy>" ) { // no sound inline stored => sound is in cache |
993 | QFile file( locateLocal( "data", "kabc/sounds/" + addr.uid() ) ); | 996 | QFile file( locateLocal( "data", "kabc/sounds/" + addr.uid() ) ); |
994 | if ( file.open( IO_ReadOnly ) ) { | 997 | if ( file.open( QIODevice::ReadOnly ) ) { |
995 | data = file.readAll(); | 998 | data = file.readAll(); |
996 | file.close(); | 999 | file.close(); |
997 | } | 1000 | } |
998 | } else { | 1001 | } else { |
999 | KCodecs::base64Decode( v->asString(), data ); | 1002 | KCodecs::base64Decode( v->asString(), data ); |
1000 | } | 1003 | } |
1001 | sound.setData( data ); | 1004 | sound.setData( data ); |
1002 | } else { | 1005 | } else { |