summaryrefslogtreecommitdiffabout
path: root/kabc/vcardformatimpl.cpp
Side-by-side diff
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
@@ -15,138 +15,141 @@
You should have received a copy of the GNU Library General Public License
along with this library; see the file COPYING.LIB. If not, write to
the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
Boston, MA 02111-1307, USA.
*/
/*
Enhanced Version of the file for platform independent KDE tools.
Copyright (c) 2004 Ulf Schenk
$Id$
*/
#include <qfile.h>
#include <qregexp.h>
#include <qapplication.h>
+//Added by qt3to4:
+#include <Q3CString>
+#include <Q3PtrList>
#include <kdebug.h>
#include <kmdcodec.h>
#include <kstandarddirs.h>
#include <ktempfile.h>
#include <VCard.h>
#include "addressbook.h"
#include "vcardformatimpl.h"
using namespace KABC;
using namespace VCARD;
int VCardFormatImpl::debug = -1;
VCardFormatImpl::VCardFormatImpl()
{
debug = (getenv("KABC_DEBUG") != 0);
}
bool VCardFormatImpl::load( Addressee &addressee, QFile *file )
{
kdDebug(5700) << "VCardFormat::load()" << endl;
QByteArray fdata = file->readAll();
- QCString data(fdata.data(), fdata.size()+1);
+ Q3CString data(fdata.data(), fdata.size()+1);
VCardEntity e( data );
VCardListIterator it( e.cardList() );
if ( it.current() ) {
//US VCard v(*it.current());
//US loadAddressee( addressee, v );
loadAddressee( addressee, it.current() );
return true;
}
return false;
}
#include <kmessagebox.h>
bool VCardFormatImpl::loadAll( AddressBook *addressBook, Resource *resource, QFile *file )
{
- QCString data(file->readAll().data(), file->size()+1);
+ Q3CString data(file->readAll().data(), file->size()+1);
VCardEntity e( data );
VCardListIterator it( e.cardList() );
for (; it.current(); ++it) {
//US VCard v(*it.current());
Addressee addressee;
//US loadAddressee( addressee, v );
loadAddressee( addressee, it.current() );
addressee.setResource( resource );
addressBook->insertAddressee( addressee );
if (debug == true)
{
printf("address %s loaded successfully\n", addressee.formattedName().latin1());
}
}
return true;
}
void VCardFormatImpl::save( const Addressee &addressee, QFile *file )
{
VCardEntity vcards;
VCardList vcardlist;
vcardlist.setAutoDelete( true );
VCard *v = new VCard;
saveAddressee( addressee, v, false );
vcardlist.append( v );
vcards.setCardList( vcardlist );
- QCString vcardData = vcards.asString();
+ Q3CString vcardData = vcards.asString();
file->writeBlock( (const char*)vcardData, vcardData.length() );
}
void VCardFormatImpl::saveAll( AddressBook *ab, Resource *resource, QFile *file )
{
AddressBook::Iterator it;
for ( it = ab->begin(); it != ab->end(); ++it ) {
if ( (*it).resource() == resource ) {
save((*it),file);
qApp->processEvents();
(*it).setChanged( false );
}
}
// for memory usage status test only
// KMessageBox::information ( 0, "Stoppppp", QString("Stop ") );
}
bool VCardFormatImpl::loadAddressee( Addressee& addressee, VCard *v )
{
- QPtrList<ContentLine> contentLines = v->contentLineList();
+ Q3PtrList<ContentLine> contentLines = v->contentLineList();
ContentLine *cl;
for( cl = contentLines.first(); cl; cl = contentLines.next() ) {
- QCString n = cl->name();
+ Q3CString n = cl->name();
if ( n.left( 2 ) == "X-" ) {
n = n.mid( 2 );
int posDash = n.find( "-" );
addressee.insertCustom( QString::fromUtf8( n.left( posDash ) ),
QString::fromUtf8( n.mid( posDash + 1 ) ),
QString::fromUtf8( cl->value()->asString() ) );
continue;
}
EntityType type = cl->entityType();
switch( type ) {
case EntityUID:
addressee.setUid( readTextValue( cl ) );
break;
@@ -206,33 +209,33 @@ bool VCardFormatImpl::loadAddressee( Addressee& addressee, VCard *v )
readNValue( cl, addressee );
break;
case EntityAddress:
addressee.insertAddress( readAddressValue( cl ) );
break;
case EntityTelephone:
addressee.insertPhoneNumber( readTelephoneValue( cl ) );
break;
case EntityCategories:
addressee.setCategories( QStringList::split( ",", readTextValue( cl ) ) );
break;
case EntityBirthday:
- addressee.setBirthday( readDateValue( cl ) );
+ addressee.setBirthday( (QDateTime) readDateValue( cl ) );
break;
case EntityRevision:
addressee.setRevision( readDateTimeValue( cl ) );
break;
case EntityGeo:
addressee.setGeo( readGeoValue( cl ) );
break;
case EntityTimeZone:
addressee.setTimeZone( readUTCValue( cl ) );
break;
case EntityVersion:
break;
@@ -517,33 +520,33 @@ Address VCardFormatImpl::readAddressValue( ContentLine *cl )
a.setStreet( QString::fromUtf8( v->street() ) );
a.setLocality( QString::fromUtf8( v->locality() ) );
a.setRegion( QString::fromUtf8( v->region() ) );
a.setPostalCode( QString::fromUtf8( v->postCode() ) );
a.setCountry( QString::fromUtf8( v->countryName() ) );
a.setType( readAddressParam( cl ) );
return a;
}
int VCardFormatImpl::readAddressParam( ContentLine *cl )
{
int type = 0;
ParamList params = cl->paramList();
ParamListIterator it( params );
- QCString tmpStr;
+ Q3CString tmpStr;
for( ; it.current(); ++it ) {
if ( (*it)->name().upper() == "TYPE" ) {
tmpStr = (*it)->value().lower();
if ( tmpStr == "dom" ) type |= Address::Dom;
else if ( tmpStr == "intl" ) type |= Address::Intl;
else if ( tmpStr == "parcel" ) type |= Address::Parcel;
else if ( tmpStr == "postal" ) type |= Address::Postal;
else if ( tmpStr == "work" ) type |= Address::Work;
else if ( tmpStr == "home" ) type |= Address::Home;
else if ( tmpStr == "pref" ) type |= Address::Pref;
}
}
return type;
}
void VCardFormatImpl::addNValue( VCard *vcard, const Addressee &a )
@@ -596,33 +599,33 @@ void VCardFormatImpl::addTelephoneValue( VCard *v, const PhoneNumber &p )
if( p.type() & PhoneNumber::Pcs ) params.append( new Param( "TYPE", "pcs" ) );
if( p.type() & PhoneNumber::Pager ) params.append( new Param( "TYPE", "pager" ) );
cl.setParamList( params );
v->add(cl);
}
PhoneNumber VCardFormatImpl::readTelephoneValue( ContentLine *cl )
{
PhoneNumber p;
TelValue *value = (TelValue *)cl->value();
p.setNumber( QString::fromUtf8( value->asString() ) );
int type = 0;
ParamList params = cl->paramList();
ParamListIterator it( params );
- QCString tmpStr;
+ Q3CString tmpStr;
for( ; it.current(); ++it ) {
if ( (*it)->name() == "TYPE" ) {
tmpStr = (*it)->value().lower();
if ( tmpStr == "home" ) type |= PhoneNumber::Home;
else if ( tmpStr == "work" ) type |= PhoneNumber::Work;
else if ( tmpStr == "msg" ) type |= PhoneNumber::Msg;
else if ( tmpStr == "pref" ) type |= PhoneNumber::Pref;
else if ( tmpStr == "voice" ) type |= PhoneNumber::Voice;
else if ( tmpStr == "fax" ) type |= PhoneNumber::Fax;
else if ( tmpStr == "cell" ) type |= PhoneNumber::Cell;
else if ( tmpStr == "video" ) type |= PhoneNumber::Video;
else if ( tmpStr == "bbs" ) type |= PhoneNumber::Bbs;
else if ( tmpStr == "modem" ) type |= PhoneNumber::Modem;
else if ( tmpStr == "car" ) type |= PhoneNumber::Car;
else if ( tmpStr == "isdn" ) type |= PhoneNumber::Isdn;
else if ( tmpStr == "pcs" ) type |= PhoneNumber::Pcs;
@@ -857,33 +860,33 @@ Agent VCardFormatImpl::readAgentValue( VCARD::ContentLine *cl )
void VCardFormatImpl::addPictureValue( VCARD::VCard *vcard, VCARD::EntityType type, const Picture &pic, const Addressee &addr, bool intern )
{
ContentLine cl;
cl.setName( EntityTypeToParamName( type ) );
// qDebug( "IIIMMMMM %s",QImage::outputFormatList ().join("-").latin1() );
if ( pic.isIntern() && pic.data().isNull() )
return;
if ( !pic.isIntern() && pic.url().isEmpty() )
return;
ParamList params;
if ( pic.isIntern() ) {
QImage img = pic.data();
if ( intern ) { // only for vCard export we really write the data inline
QByteArray data;
- QDataStream s( data, IO_WriteOnly );
+ QDataStream s( &data, QIODevice::WriteOnly );
s.setVersion( 4 ); // to produce valid png files
s << img;
cl.setValue( new TextValue( KCodecs::base64Encode( data ) ) );
params.append( new Param( "ENCODING", "b" ) );
if ( !pic.type().isEmpty() )
params.append( new Param( "TYPE", pic.type().utf8() ) );
} else { // save picture in cache
QString dir;
if ( type == EntityPhoto )
dir = "photos";
if ( type == EntityLogo )
dir = "logos";
QString imUrl = locateLocal( "data", "kabc/" + dir + "/" + addr.uid() );
KABC::Picture* ppic =(KABC::Picture*) &pic;
ppic->setUrl( imUrl );
img.save(imUrl, "PNG" );
@@ -946,65 +949,65 @@ void VCardFormatImpl::addSoundValue( VCARD::VCard *vcard, const Sound &sound, co
ContentLine cl;
cl.setName( EntityTypeToParamName( EntitySound ) );
if ( sound.isIntern() && sound.data().isNull() )
return;
if ( !sound.isIntern() && sound.url().isEmpty() )
return;
ParamList params;
if ( sound.isIntern() ) {
QByteArray data = sound.data();
if ( intern ) { // only for vCard export we really write the data inline
cl.setValue( new TextValue( KCodecs::base64Encode( data ) ) );
} else { // save sound in cache
QFile file( locateLocal( "data", "kabc/sounds/" + addr.uid() ) );
- if ( file.open( IO_WriteOnly ) ) {
+ if ( file.open( QIODevice::WriteOnly ) ) {
file.writeBlock( data );
}
cl.setValue( new TextValue( "<dummy>" ) );
}
params.append( new Param( "ENCODING", "b" ) );
} else {
cl.setValue( new TextValue( sound.url().utf8() ) );
params.append( new Param( "VALUE", "uri" ) );
}
cl.setParamList( params );
vcard->add( cl );
}
Sound VCardFormatImpl::readSoundValue( VCARD::ContentLine *cl, const Addressee &addr )
{
Sound sound;
bool isInline = false;
TextValue *v = (TextValue *)cl->value();
ParamList params = cl->paramList();
ParamListIterator it( params );
for( ; it.current(); ++it ) {
if ( (*it)->name() == "ENCODING" && (*it)->value() == "b" )
isInline = true;
}
if ( isInline ) {
QByteArray data;
if ( v->asString() == "<dummy>" ) { // no sound inline stored => sound is in cache
QFile file( locateLocal( "data", "kabc/sounds/" + addr.uid() ) );
- if ( file.open( IO_ReadOnly ) ) {
+ if ( file.open( QIODevice::ReadOnly ) ) {
data = file.readAll();
file.close();
}
} else {
KCodecs::base64Decode( v->asString(), data );
}
sound.setData( data );
} else {
sound.setUrl( QString::fromUtf8( v->asString() ) );
}
return sound;
}
bool VCardFormatImpl::readFromString( const QString &vcard, Addressee &addressee )
{