summaryrefslogtreecommitdiffabout
path: root/kabc/vcardformatimpl.cpp
Unidiff
Diffstat (limited to 'kabc/vcardformatimpl.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r--kabc/vcardformatimpl.cpp25
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
@@ -7,154 +7,157 @@
7 License as published by the Free Software Foundation; either 7 License as published by the Free Software Foundation; either
8 version 2 of the License, or (at your option) any later version. 8 version 2 of the License, or (at your option) any later version.
9 9
10 This library is distributed in the hope that it will be useful, 10 This library is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of 11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Library General Public License for more details. 13 Library General Public License for more details.
14 14
15 You should have received a copy of the GNU Library General Public License 15 You should have received a copy of the GNU Library General Public License
16 along with this library; see the file COPYING.LIB. If not, write to 16 along with this library; see the file COPYING.LIB. If not, write to
17 the Free Software Foundation, Inc., 59 Temple Place - Suite 330, 17 the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
18 Boston, MA 02111-1307, USA. 18 Boston, MA 02111-1307, USA.
19*/ 19*/
20 20
21/* 21/*
22Enhanced Version of the file for platform independent KDE tools. 22Enhanced Version of the file for platform independent KDE tools.
23Copyright (c) 2004 Ulf Schenk 23Copyright (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
39#include "addressbook.h" 42#include "addressbook.h"
40#include "vcardformatimpl.h" 43#include "vcardformatimpl.h"
41 44
42using namespace KABC; 45using namespace KABC;
43using namespace VCARD; 46using namespace VCARD;
44 47
45int VCardFormatImpl::debug = -1; 48int VCardFormatImpl::debug = -1;
46 49
47VCardFormatImpl::VCardFormatImpl() 50VCardFormatImpl::VCardFormatImpl()
48{ 51{
49 debug = (getenv("KABC_DEBUG") != 0); 52 debug = (getenv("KABC_DEBUG") != 0);
50} 53}
51 54
52bool VCardFormatImpl::load( Addressee &addressee, QFile *file ) 55bool 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 );
66 loadAddressee( addressee, it.current() ); 69 loadAddressee( addressee, it.current() );
67 return true; 70 return true;
68 } 71 }
69 72
70 return false; 73 return false;
71} 74}
72 75
73 76
74#include <kmessagebox.h> 77#include <kmessagebox.h>
75bool VCardFormatImpl::loadAll( AddressBook *addressBook, Resource *resource, QFile *file ) 78bool 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 );
87 loadAddressee( addressee, it.current() ); 90 loadAddressee( addressee, it.current() );
88 addressee.setResource( resource ); 91 addressee.setResource( resource );
89 addressBook->insertAddressee( addressee ); 92 addressBook->insertAddressee( addressee );
90 if (debug == true) 93 if (debug == true)
91 { 94 {
92 printf("address %s loaded successfully\n", addressee.formattedName().latin1()); 95 printf("address %s loaded successfully\n", addressee.formattedName().latin1());
93 } 96 }
94 } 97 }
95 return true; 98 return true;
96} 99}
97 100
98void VCardFormatImpl::save( const Addressee &addressee, QFile *file ) 101void VCardFormatImpl::save( const Addressee &addressee, QFile *file )
99{ 102{
100 VCardEntity vcards; 103 VCardEntity vcards;
101 VCardList vcardlist; 104 VCardList vcardlist;
102 vcardlist.setAutoDelete( true ); 105 vcardlist.setAutoDelete( true );
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
115void VCardFormatImpl::saveAll( AddressBook *ab, Resource *resource, QFile *file ) 118void 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 ) {
120 if ( (*it).resource() == resource ) { 123 if ( (*it).resource() == resource ) {
121 save((*it),file); 124 save((*it),file);
122 qApp->processEvents(); 125 qApp->processEvents();
123 (*it).setChanged( false ); 126 (*it).setChanged( false );
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
130bool VCardFormatImpl::loadAddressee( Addressee& addressee, VCard *v ) 133bool 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 }
145 148
146 EntityType type = cl->entityType(); 149 EntityType type = cl->entityType();
147 switch( type ) { 150 switch( type ) {
148 151
149 case EntityUID: 152 case EntityUID:
150 addressee.setUid( readTextValue( cl ) ); 153 addressee.setUid( readTextValue( cl ) );
151 break; 154 break;
152 155
153 case EntityEmail: 156 case EntityEmail:
154 addressee.insertEmail( readTextValue( cl ) ); 157 addressee.insertEmail( readTextValue( cl ) );
155 break; 158 break;
156 159
157 case EntityName: 160 case EntityName:
158 addressee.setName( readTextValue( cl ) ); 161 addressee.setName( readTextValue( cl ) );
159 break; 162 break;
160 163
@@ -198,49 +201,49 @@ bool VCardFormatImpl::loadAddressee( Addressee& addressee, VCard *v )
198 addressee.setProductId( readTextValue( cl ) ); 201 addressee.setProductId( readTextValue( cl ) );
199 break; 202 break;
200 203
201 case EntitySortString: 204 case EntitySortString:
202 addressee.setSortString( readTextValue( cl ) ); 205 addressee.setSortString( readTextValue( cl ) );
203 break; 206 break;
204 207
205 case EntityN: 208 case EntityN:
206 readNValue( cl, addressee ); 209 readNValue( cl, addressee );
207 break; 210 break;
208 211
209 case EntityAddress: 212 case EntityAddress:
210 addressee.insertAddress( readAddressValue( cl ) ); 213 addressee.insertAddress( readAddressValue( cl ) );
211 break; 214 break;
212 215
213 case EntityTelephone: 216 case EntityTelephone:
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 ) );
231 break; 234 break;
232 235
233 case EntityTimeZone: 236 case EntityTimeZone:
234 addressee.setTimeZone( readUTCValue( cl ) ); 237 addressee.setTimeZone( readUTCValue( cl ) );
235 break; 238 break;
236 239
237 case EntityVersion: 240 case EntityVersion:
238 break; 241 break;
239 242
240 case EntityClass: 243 case EntityClass:
241 addressee.setSecrecy( readClassValue( cl ) ); 244 addressee.setSecrecy( readClassValue( cl ) );
242 break; 245 break;
243 246
244 case EntityKey: 247 case EntityKey:
245 addressee.insertKey( readKeyValue( cl ) ); 248 addressee.insertKey( readKeyValue( cl ) );
246 break; 249 break;
@@ -509,49 +512,49 @@ void VCardFormatImpl::addClassValue( VCard *vcard, const Secrecy &secrecy )
509 512
510 513
511Address VCardFormatImpl::readAddressValue( ContentLine *cl ) 514Address VCardFormatImpl::readAddressValue( ContentLine *cl )
512{ 515{
513 Address a; 516 Address a;
514 AdrValue *v = (AdrValue *)cl->value(); 517 AdrValue *v = (AdrValue *)cl->value();
515 a.setPostOfficeBox( QString::fromUtf8( v->poBox() ) ); 518 a.setPostOfficeBox( QString::fromUtf8( v->poBox() ) );
516 a.setExtended( QString::fromUtf8( v->extAddress() ) ); 519 a.setExtended( QString::fromUtf8( v->extAddress() ) );
517 a.setStreet( QString::fromUtf8( v->street() ) ); 520 a.setStreet( QString::fromUtf8( v->street() ) );
518 a.setLocality( QString::fromUtf8( v->locality() ) ); 521 a.setLocality( QString::fromUtf8( v->locality() ) );
519 a.setRegion( QString::fromUtf8( v->region() ) ); 522 a.setRegion( QString::fromUtf8( v->region() ) );
520 a.setPostalCode( QString::fromUtf8( v->postCode() ) ); 523 a.setPostalCode( QString::fromUtf8( v->postCode() ) );
521 a.setCountry( QString::fromUtf8( v->countryName() ) ); 524 a.setCountry( QString::fromUtf8( v->countryName() ) );
522 525
523 a.setType( readAddressParam( cl ) ); 526 a.setType( readAddressParam( cl ) );
524 527
525 return a; 528 return a;
526} 529}
527 530
528int VCardFormatImpl::readAddressParam( ContentLine *cl ) 531int 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;
542 else if ( tmpStr == "home" ) type |= Address::Home; 545 else if ( tmpStr == "home" ) type |= Address::Home;
543 else if ( tmpStr == "pref" ) type |= Address::Pref; 546 else if ( tmpStr == "pref" ) type |= Address::Pref;
544 } 547 }
545 } 548 }
546 return type; 549 return type;
547} 550}
548 551
549void VCardFormatImpl::addNValue( VCard *vcard, const Addressee &a ) 552void VCardFormatImpl::addNValue( VCard *vcard, const Addressee &a )
550{ 553{
551 ContentLine cl; 554 ContentLine cl;
552 cl.setName(EntityTypeToParamName( EntityN ) ); 555 cl.setName(EntityTypeToParamName( EntityN ) );
553 NValue *v = new NValue; 556 NValue *v = new NValue;
554 v->setFamily( a.familyName().utf8() ); 557 v->setFamily( a.familyName().utf8() );
555 v->setGiven( a.givenName().utf8() ); 558 v->setGiven( a.givenName().utf8() );
556 v->setMiddle( a.additionalName().utf8() ); 559 v->setMiddle( a.additionalName().utf8() );
557 v->setPrefix( a.prefix().utf8() ); 560 v->setPrefix( a.prefix().utf8() );
@@ -588,49 +591,49 @@ void VCardFormatImpl::addTelephoneValue( VCard *v, const PhoneNumber &p )
588 if( p.type() & PhoneNumber::Voice ) params.append( new Param( "TYPE", "voice" ) ); 591 if( p.type() & PhoneNumber::Voice ) params.append( new Param( "TYPE", "voice" ) );
589 if( p.type() & PhoneNumber::Fax ) params.append( new Param( "TYPE", "fax" ) ); 592 if( p.type() & PhoneNumber::Fax ) params.append( new Param( "TYPE", "fax" ) );
590 if( p.type() & PhoneNumber::Cell ) params.append( new Param( "TYPE", "cell" ) ); 593 if( p.type() & PhoneNumber::Cell ) params.append( new Param( "TYPE", "cell" ) );
591 if( p.type() & PhoneNumber::Video ) params.append( new Param( "TYPE", "video" ) ); 594 if( p.type() & PhoneNumber::Video ) params.append( new Param( "TYPE", "video" ) );
592 if( p.type() & PhoneNumber::Bbs ) params.append( new Param( "TYPE", "bbs" ) ); 595 if( p.type() & PhoneNumber::Bbs ) params.append( new Param( "TYPE", "bbs" ) );
593 if( p.type() & PhoneNumber::Modem ) params.append( new Param( "TYPE", "modem" ) ); 596 if( p.type() & PhoneNumber::Modem ) params.append( new Param( "TYPE", "modem" ) );
594 if( p.type() & PhoneNumber::Car ) params.append( new Param( "TYPE", "car" ) ); 597 if( p.type() & PhoneNumber::Car ) params.append( new Param( "TYPE", "car" ) );
595 if( p.type() & PhoneNumber::Isdn ) params.append( new Param( "TYPE", "isdn" ) ); 598 if( p.type() & PhoneNumber::Isdn ) params.append( new Param( "TYPE", "isdn" ) );
596 if( p.type() & PhoneNumber::Pcs ) params.append( new Param( "TYPE", "pcs" ) ); 599 if( p.type() & PhoneNumber::Pcs ) params.append( new Param( "TYPE", "pcs" ) );
597 if( p.type() & PhoneNumber::Pager ) params.append( new Param( "TYPE", "pager" ) ); 600 if( p.type() & PhoneNumber::Pager ) params.append( new Param( "TYPE", "pager" ) );
598 cl.setParamList( params ); 601 cl.setParamList( params );
599 602
600 v->add(cl); 603 v->add(cl);
601} 604}
602 605
603PhoneNumber VCardFormatImpl::readTelephoneValue( ContentLine *cl ) 606PhoneNumber 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;
621 else if ( tmpStr == "fax" ) type |= PhoneNumber::Fax; 624 else if ( tmpStr == "fax" ) type |= PhoneNumber::Fax;
622 else if ( tmpStr == "cell" ) type |= PhoneNumber::Cell; 625 else if ( tmpStr == "cell" ) type |= PhoneNumber::Cell;
623 else if ( tmpStr == "video" ) type |= PhoneNumber::Video; 626 else if ( tmpStr == "video" ) type |= PhoneNumber::Video;
624 else if ( tmpStr == "bbs" ) type |= PhoneNumber::Bbs; 627 else if ( tmpStr == "bbs" ) type |= PhoneNumber::Bbs;
625 else if ( tmpStr == "modem" ) type |= PhoneNumber::Modem; 628 else if ( tmpStr == "modem" ) type |= PhoneNumber::Modem;
626 else if ( tmpStr == "car" ) type |= PhoneNumber::Car; 629 else if ( tmpStr == "car" ) type |= PhoneNumber::Car;
627 else if ( tmpStr == "isdn" ) type |= PhoneNumber::Isdn; 630 else if ( tmpStr == "isdn" ) type |= PhoneNumber::Isdn;
628 else if ( tmpStr == "pcs" ) type |= PhoneNumber::Pcs; 631 else if ( tmpStr == "pcs" ) type |= PhoneNumber::Pcs;
629 else if ( tmpStr == "pager" ) type |= PhoneNumber::Pager; 632 else if ( tmpStr == "pager" ) type |= PhoneNumber::Pager;
630 } 633 }
631 } 634 }
632 p.setType( type ); 635 p.setType( type );
633 636
634 return p; 637 return p;
635} 638}
636 639
@@ -849,49 +852,49 @@ Agent VCardFormatImpl::readAgentValue( VCARD::ContentLine *cl )
849 } else { 852 } else {
850 agent.setUrl( QString::fromUtf8( v->asString() ) ); 853 agent.setUrl( QString::fromUtf8( v->asString() ) );
851 } 854 }
852 855
853 return agent; 856 return agent;
854} 857}
855 858
856#include <qstringlist.h> 859#include <qstringlist.h>
857void VCardFormatImpl::addPictureValue( VCARD::VCard *vcard, VCARD::EntityType type, const Picture &pic, const Addressee &addr, bool intern ) 860void VCardFormatImpl::addPictureValue( VCARD::VCard *vcard, VCARD::EntityType type, const Picture &pic, const Addressee &addr, bool intern )
858{ 861{
859 ContentLine cl; 862 ContentLine cl;
860 cl.setName( EntityTypeToParamName( type ) ); 863 cl.setName( EntityTypeToParamName( type ) );
861 // qDebug( "IIIMMMMM %s",QImage::outputFormatList ().join("-").latin1() ); 864 // qDebug( "IIIMMMMM %s",QImage::outputFormatList ().join("-").latin1() );
862 if ( pic.isIntern() && pic.data().isNull() ) 865 if ( pic.isIntern() && pic.data().isNull() )
863 return; 866 return;
864 867
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;
882 if ( type == EntityPhoto ) 885 if ( type == EntityPhoto )
883 dir = "photos"; 886 dir = "photos";
884 if ( type == EntityLogo ) 887 if ( type == EntityLogo )
885 dir = "logos"; 888 dir = "logos";
886 QString imUrl = locateLocal( "data", "kabc/" + dir + "/" + addr.uid() ); 889 QString imUrl = locateLocal( "data", "kabc/" + dir + "/" + addr.uid() );
887 KABC::Picture* ppic =(KABC::Picture*) &pic; 890 KABC::Picture* ppic =(KABC::Picture*) &pic;
888 ppic->setUrl( imUrl ); 891 ppic->setUrl( imUrl );
889 img.save(imUrl, "PNG" ); 892 img.save(imUrl, "PNG" );
890 cl.setValue( new TextValue( pic.url().utf8() ) ); 893 cl.setValue( new TextValue( pic.url().utf8() ) );
891 params.append( new Param( "VALUE", "uri" ) ); 894 params.append( new Param( "VALUE", "uri" ) );
892 } 895 }
893 896
894 } else { 897 } else {
895 898
896 cl.setValue( new TextValue( pic.url().utf8() ) ); 899 cl.setValue( new TextValue( pic.url().utf8() ) );
897 params.append( new Param( "VALUE", "uri" ) ); 900 params.append( new Param( "VALUE", "uri" ) );
@@ -938,81 +941,81 @@ Picture VCardFormatImpl::readPictureValue( VCARD::ContentLine *cl, VCARD::Entity
938 pic.setUrl( QString::fromUtf8( v->asString() ) ); 941 pic.setUrl( QString::fromUtf8( v->asString() ) );
939 } 942 }
940 943
941 return pic; 944 return pic;
942} 945}
943 946
944void VCardFormatImpl::addSoundValue( VCARD::VCard *vcard, const Sound &sound, const Addressee &addr, bool intern ) 947void VCardFormatImpl::addSoundValue( VCARD::VCard *vcard, const Sound &sound, const Addressee &addr, bool intern )
945{ 948{
946 ContentLine cl; 949 ContentLine cl;
947 cl.setName( EntityTypeToParamName( EntitySound ) ); 950 cl.setName( EntityTypeToParamName( EntitySound ) );
948 951
949 if ( sound.isIntern() && sound.data().isNull() ) 952 if ( sound.isIntern() && sound.data().isNull() )
950 return; 953 return;
951 954
952 if ( !sound.isIntern() && sound.url().isEmpty() ) 955 if ( !sound.isIntern() && sound.url().isEmpty() )
953 return; 956 return;
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" ) );
971 } 974 }
972 975
973 cl.setParamList( params ); 976 cl.setParamList( params );
974 vcard->add( cl ); 977 vcard->add( cl );
975} 978}
976 979
977Sound VCardFormatImpl::readSoundValue( VCARD::ContentLine *cl, const Addressee &addr ) 980Sound VCardFormatImpl::readSoundValue( VCARD::ContentLine *cl, const Addressee &addr )
978{ 981{
979 Sound sound; 982 Sound sound;
980 bool isInline = false; 983 bool isInline = false;
981 TextValue *v = (TextValue *)cl->value(); 984 TextValue *v = (TextValue *)cl->value();
982 985
983 ParamList params = cl->paramList(); 986 ParamList params = cl->paramList();
984 ParamListIterator it( params ); 987 ParamListIterator it( params );
985 for( ; it.current(); ++it ) { 988 for( ; it.current(); ++it ) {
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 {
1003 sound.setUrl( QString::fromUtf8( v->asString() ) ); 1006 sound.setUrl( QString::fromUtf8( v->asString() ) );
1004 } 1007 }
1005 1008
1006 return sound; 1009 return sound;
1007} 1010}
1008 1011
1009bool VCardFormatImpl::readFromString( const QString &vcard, Addressee &addressee ) 1012bool VCardFormatImpl::readFromString( const QString &vcard, Addressee &addressee )
1010{ 1013{
1011 VCardEntity e( vcard.utf8() ); 1014 VCardEntity e( vcard.utf8() );
1012 VCardListIterator it( e.cardList() ); 1015 VCardListIterator it( e.cardList() );
1013 1016
1014 if ( it.current() ) { 1017 if ( it.current() ) {
1015//US VCard v(*it.current()); 1018//US VCard v(*it.current());
1016//US loadAddressee( addressee, v ); 1019//US loadAddressee( addressee, v );
1017 loadAddressee( addressee, it.current() ); 1020 loadAddressee( addressee, it.current() );
1018 return true; 1021 return true;