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
@@ -25,12 +25,15 @@ Copyright (c) 2004 Ulf Schenk
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
@@ -51,13 +54,13 @@ VCardFormatImpl::VCardFormatImpl()
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() ) {
@@ -72,13 +75,13 @@ bool VCardFormatImpl::load( Addressee &addressee, QFile *file )
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());
@@ -105,13 +108,13 @@ void VCardFormatImpl::save( const Addressee &addressee, QFile *file )
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
@@ -126,17 +129,17 @@ void VCardFormatImpl::saveAll( AddressBook *ab, Resource *resource, QFile *file
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() ) );
@@ -216,13 +219,13 @@ bool VCardFormatImpl::loadAddressee( Addressee& addressee, VCard *v )
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
@@ -527,13 +530,13 @@ Address VCardFormatImpl::readAddressValue( ContentLine *cl )
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;
@@ -606,13 +609,13 @@ PhoneNumber VCardFormatImpl::readTelephoneValue( ContentLine *cl )
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;
@@ -867,13 +870,13 @@ void VCardFormatImpl::addPictureValue( VCARD::VCard *vcard, VCARD::EntityType ty
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() ) );
@@ -956,13 +959,13 @@ void VCardFormatImpl::addSoundValue( VCARD::VCard *vcard, const Sound &sound, co
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 {
@@ -988,13 +991,13 @@ Sound VCardFormatImpl::readSoundValue( VCARD::ContentLine *cl, const Addressee &
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 }