-rw-r--r-- | kabc/vcardformatimpl.cpp | 48 |
1 files changed, 26 insertions, 22 deletions
diff --git a/kabc/vcardformatimpl.cpp b/kabc/vcardformatimpl.cpp index f90f813..3fcaf94 100644 --- a/kabc/vcardformatimpl.cpp +++ b/kabc/vcardformatimpl.cpp @@ -335,477 +335,481 @@ void VCardFormatImpl::saveAddressee( const Addressee &addressee, VCard *v, bool addTextValue( v, EntityCategories, addressee.categories().join(",") ); addDateValue( v, EntityBirthday, addressee.birthday().date() ); addDateTimeValue( v, EntityRevision, addressee.revision() ); addGeoValue( v, addressee.geo() ); addUTCValue( v, addressee.timeZone() ); addClassValue( v, addressee.secrecy() ); addPictureValue( v, EntityPhoto, addressee.photo(), addressee, intern ); addPictureValue( v, EntityLogo, addressee.logo(), addressee, intern ); addAgentValue( v, addressee.agent() ); addSoundValue( v, addressee.sound(), addressee, intern ); } void VCardFormatImpl::addCustomValue( VCard *v, const QString &txt ) { if ( txt.isEmpty() ) return; ContentLine cl; cl.setName( "X-" + txt.left( txt.find( ":" ) ).utf8() ); QString value = txt.mid( txt.find( ":" ) + 1 ); if ( value.isEmpty() ) return; cl.setValue( new TextValue( value.utf8() ) ); v->add(cl); } void VCardFormatImpl::addTextValue( VCard *v, EntityType type, const QString &txt ) { if ( txt.isEmpty() ) return; ContentLine cl; cl.setName( EntityTypeToParamName( type ) ); cl.setValue( new TextValue( txt.utf8() ) ); v->add(cl); } void VCardFormatImpl::addDateValue( VCard *vcard, EntityType type, const QDate &date ) { if ( !date.isValid() ) return; ContentLine cl; cl.setName( EntityTypeToParamName( type ) ); DateValue *v = new DateValue( date ); cl.setValue( v ); vcard->add(cl); } void VCardFormatImpl::addDateTimeValue( VCard *vcard, EntityType type, const QDateTime &dateTime ) { if ( !dateTime.isValid() ) return; ContentLine cl; cl.setName( EntityTypeToParamName( type ) ); DateValue *v = new DateValue( dateTime ); cl.setValue( v ); vcard->add(cl); } void VCardFormatImpl::addAddressValue( VCard *vcard, const Address &a ) { if ( a.isEmpty() ) return; ContentLine cl; cl.setName( EntityTypeToParamName( EntityAddress ) ); AdrValue *v = new AdrValue; v->setPOBox( a.postOfficeBox().utf8() ); v->setExtAddress( a.extended().utf8() ); v->setStreet( a.street().utf8() ); v->setLocality( a.locality().utf8() ); v->setRegion( a.region().utf8() ); v->setPostCode( a.postalCode().utf8() ); v->setCountryName( a.country().utf8() ); cl.setValue( v ); addAddressParam( &cl, a.type() ); vcard->add( cl ); } void VCardFormatImpl::addLabelValue( VCard *vcard, const Address &a ) { if ( a.label().isEmpty() ) return; ContentLine cl; cl.setName( EntityTypeToParamName( EntityLabel ) ); cl.setValue( new TextValue( a.label().utf8() ) ); addAddressParam( &cl, a.type() ); vcard->add( cl ); } void VCardFormatImpl::addAddressParam( ContentLine *cl, int type ) { ParamList params; if ( type & Address::Dom ) params.append( new Param( "TYPE", "dom" ) ); if ( type & Address::Intl ) params.append( new Param( "TYPE", "intl" ) ); if ( type & Address::Parcel ) params.append( new Param( "TYPE", "parcel" ) ); if ( type & Address::Postal ) params.append( new Param( "TYPE", "postal" ) ); if ( type & Address::Work ) params.append( new Param( "TYPE", "work" ) ); if ( type & Address::Home ) params.append( new Param( "TYPE", "home" ) ); if ( type & Address::Pref ) params.append( new Param( "TYPE", "pref" ) ); cl->setParamList( params ); } void VCardFormatImpl::addGeoValue( VCard *vcard, const Geo &geo ) { if ( !geo.isValid() ) return; ContentLine cl; cl.setName( EntityTypeToParamName( EntityGeo ) ); GeoValue *v = new GeoValue; v->setLatitude( geo.latitude() ); v->setLongitude( geo.longitude() ); cl.setValue( v ); vcard->add(cl); } void VCardFormatImpl::addUTCValue( VCard *vcard, const TimeZone &tz ) { if ( !tz.isValid() ) return; ContentLine cl; cl.setName( EntityTypeToParamName( EntityTimeZone ) ); UTCValue *v = new UTCValue; v->setPositive( tz.offset() >= 0 ); v->setHour( (tz.offset() / 60) * ( tz.offset() >= 0 ? 1 : -1 ) ); v->setMinute( (tz.offset() % 60) * ( tz.offset() >= 0 ? 1 : -1 ) ); cl.setValue( v ); vcard->add(cl); } void VCardFormatImpl::addClassValue( VCard *vcard, const Secrecy &secrecy ) { ContentLine cl; cl.setName( EntityTypeToParamName( EntityClass ) ); ClassValue *v = new ClassValue; switch ( secrecy.type() ) { case Secrecy::Public: v->setType( (int)ClassValue::Public ); break; case Secrecy::Private: v->setType( (int)ClassValue::Private ); break; case Secrecy::Confidential: v->setType( (int)ClassValue::Confidential ); break; } cl.setValue( v ); vcard->add(cl); } Address VCardFormatImpl::readAddressValue( ContentLine *cl ) { Address a; AdrValue *v = (AdrValue *)cl->value(); a.setPostOfficeBox( QString::fromUtf8( v->poBox() ) ); a.setExtended( QString::fromUtf8( v->extAddress() ) ); 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; for( ; it.current(); ++it ) { - if ( (*it)->name() == "TYPE" ) { - if ( (*it)->value() == "dom" ) type |= Address::Dom; - else if ( (*it)->value() == "intl" ) type |= Address::Intl; - else if ( (*it)->value() == "parcel" ) type |= Address::Parcel; - else if ( (*it)->value() == "postal" ) type |= Address::Postal; - else if ( (*it)->value() == "work" ) type |= Address::Work; - else if ( (*it)->value() == "home" ) type |= Address::Home; - else if ( (*it)->value() == "pref" ) type |= Address::Pref; + 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 ) { ContentLine cl; cl.setName(EntityTypeToParamName( EntityN ) ); NValue *v = new NValue; v->setFamily( a.familyName().utf8() ); v->setGiven( a.givenName().utf8() ); v->setMiddle( a.additionalName().utf8() ); v->setPrefix( a.prefix().utf8() ); v->setSuffix( a.suffix().utf8() ); cl.setValue( v ); vcard->add(cl); } void VCardFormatImpl::readNValue( ContentLine *cl, Addressee &a ) { NValue *v = (NValue *)cl->value(); a.setFamilyName( QString::fromUtf8( v->family() ) ); a.setGivenName( QString::fromUtf8( v->given() ) ); a.setAdditionalName( QString::fromUtf8( v->middle() ) ); a.setPrefix( QString::fromUtf8( v->prefix() ) ); a.setSuffix( QString::fromUtf8( v->suffix() ) ); } void VCardFormatImpl::addTelephoneValue( VCard *v, const PhoneNumber &p ) { if ( p.number().isEmpty() ) return; ContentLine cl; cl.setName(EntityTypeToParamName(EntityTelephone)); cl.setValue(new TelValue( p.number().utf8() )); ParamList params; if( p.type() & PhoneNumber::Home ) params.append( new Param( "TYPE", "home" ) ); if( p.type() & PhoneNumber::Work ) params.append( new Param( "TYPE", "work" ) ); if( p.type() & PhoneNumber::Msg ) params.append( new Param( "TYPE", "msg" ) ); if( p.type() & PhoneNumber::Pref ) params.append( new Param( "TYPE", "pref" ) ); if( p.type() & PhoneNumber::Voice ) params.append( new Param( "TYPE", "voice" ) ); if( p.type() & PhoneNumber::Fax ) params.append( new Param( "TYPE", "fax" ) ); if( p.type() & PhoneNumber::Cell ) params.append( new Param( "TYPE", "cell" ) ); if( p.type() & PhoneNumber::Video ) params.append( new Param( "TYPE", "video" ) ); if( p.type() & PhoneNumber::Bbs ) params.append( new Param( "TYPE", "bbs" ) ); if( p.type() & PhoneNumber::Modem ) params.append( new Param( "TYPE", "modem" ) ); if( p.type() & PhoneNumber::Car ) params.append( new Param( "TYPE", "car" ) ); if( p.type() & PhoneNumber::Isdn ) params.append( new Param( "TYPE", "isdn" ) ); 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; for( ; it.current(); ++it ) { if ( (*it)->name() == "TYPE" ) { - if ( (*it)->value() == "home" ) type |= PhoneNumber::Home; - else if ( (*it)->value() == "work" ) type |= PhoneNumber::Work; - else if ( (*it)->value() == "msg" ) type |= PhoneNumber::Msg; - else if ( (*it)->value() == "pref" ) type |= PhoneNumber::Pref; - else if ( (*it)->value() == "voice" ) type |= PhoneNumber::Voice; - else if ( (*it)->value() == "fax" ) type |= PhoneNumber::Fax; - else if ( (*it)->value() == "cell" ) type |= PhoneNumber::Cell; - else if ( (*it)->value() == "video" ) type |= PhoneNumber::Video; - else if ( (*it)->value() == "bbs" ) type |= PhoneNumber::Bbs; - else if ( (*it)->value() == "modem" ) type |= PhoneNumber::Modem; - else if ( (*it)->value() == "car" ) type |= PhoneNumber::Car; - else if ( (*it)->value() == "isdn" ) type |= PhoneNumber::Isdn; - else if ( (*it)->value() == "pcs" ) type |= PhoneNumber::Pcs; - else if ( (*it)->value() == "pager" ) type |= PhoneNumber::Pager; + 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; + else if ( tmpStr == "pager" ) type |= PhoneNumber::Pager; } } p.setType( type ); return p; } QString VCardFormatImpl::readTextValue( ContentLine *cl ) { VCARD::Value *value = cl->value(); if ( value ) { return QString::fromUtf8( value->asString() ); } else { kdDebug(5700) << "No value: " << cl->asString() << endl; return QString::null; } } QDate VCardFormatImpl::readDateValue( ContentLine *cl ) { DateValue *dateValue = (DateValue *)cl->value(); if ( dateValue ) return dateValue->qdate(); else return QDate(); } QDateTime VCardFormatImpl::readDateTimeValue( ContentLine *cl ) { DateValue *dateValue = (DateValue *)cl->value(); if ( dateValue ) return dateValue->qdt(); else return QDateTime(); } Geo VCardFormatImpl::readGeoValue( ContentLine *cl ) { GeoValue *geoValue = (GeoValue *)cl->value(); if ( geoValue ) { Geo geo( geoValue->latitude(), geoValue->longitude() ); return geo; } else return Geo(); } TimeZone VCardFormatImpl::readUTCValue( ContentLine *cl ) { UTCValue *utcValue = (UTCValue *)cl->value(); if ( utcValue ) { TimeZone tz; tz.setOffset(((utcValue->hour()*60)+utcValue->minute())*(utcValue->positive() ? 1 : -1)); return tz; } else return TimeZone(); } Secrecy VCardFormatImpl::readClassValue( ContentLine *cl ) { ClassValue *classValue = (ClassValue *)cl->value(); if ( classValue ) { Secrecy secrecy; switch ( classValue->type() ) { case ClassValue::Public: secrecy.setType( Secrecy::Public ); break; case ClassValue::Private: secrecy.setType( Secrecy::Private ); break; case ClassValue::Confidential: secrecy.setType( Secrecy::Confidential ); break; } return secrecy; } else return Secrecy(); } void VCardFormatImpl::addKeyValue( VCARD::VCard *vcard, const Key &key ) { ContentLine cl; cl.setName( EntityTypeToParamName( EntityKey ) ); ParamList params; if ( key.isBinary() ) { cl.setValue( new TextValue( KCodecs::base64Encode( key.binaryData() ) ) ); params.append( new Param( "ENCODING", "b" ) ); } else { cl.setValue( new TextValue( key.textData().utf8() ) ); } switch ( key.type() ) { case Key::X509: params.append( new Param( "TYPE", "X509" ) ); break; case Key::PGP: params.append( new Param( "TYPE", "PGP" ) ); break; case Key::Custom: params.append( new Param( "TYPE", key.customTypeString().utf8() ) ); break; } cl.setParamList( params ); vcard->add( cl ); } Key VCardFormatImpl::readKeyValue( VCARD::ContentLine *cl ) { Key key; bool isBinary = false; TextValue *v = (TextValue *)cl->value(); ParamList params = cl->paramList(); ParamListIterator it( params ); for( ; it.current(); ++it ) { if ( (*it)->name() == "ENCODING" && (*it)->value() == "b" ) isBinary = true; if ( (*it)->name() == "TYPE" ) { if ( (*it)->value().isEmpty() ) continue; if ( (*it)->value() == "X509" ) key.setType( Key::X509 ); else if ( (*it)->value() == "PGP" ) key.setType( Key::PGP ); else { key.setType( Key::Custom ); key.setCustomTypeString( QString::fromUtf8( (*it)->value() ) ); } } } if ( isBinary ) { QByteArray data; KCodecs::base64Decode( v->asString().stripWhiteSpace(), data ); key.setBinaryData( data ); } else { key.setTextData( QString::fromUtf8( v->asString() ) ); } return key; } void VCardFormatImpl::addAgentValue( VCARD::VCard *vcard, const Agent &agent ) { if ( agent.isIntern() && !agent.addressee() ) return; if ( !agent.isIntern() && agent.url().isEmpty() ) return; ContentLine cl; cl.setName( EntityTypeToParamName( EntityAgent ) ); ParamList params; if ( agent.isIntern() ) { QString vstr; Addressee *addr = agent.addressee(); if ( addr ) { writeToString( (*addr), vstr ); qDebug("VCardFormatImpl::addAgentValue please verify if replace is correct"); /*US vstr.replace( ":", "\\:" ); vstr.replace( ",", "\\," ); vstr.replace( ";", "\\;" ); vstr.replace( "\r\n", "\\n" ); */ vstr.replace( QRegExp(":"), "\\:" ); vstr.replace( QRegExp(","), "\\," ); vstr.replace( QRegExp(";"), "\\;" ); vstr.replace( QRegExp("\r\n"), "\\n" ); cl.setValue( new TextValue( vstr.utf8() ) ); } else return; } else { cl.setValue( new TextValue( agent.url().utf8() ) ); params.append( new Param( "VALUE", "uri" ) ); } cl.setParamList( params ); vcard->add( cl ); } Agent VCardFormatImpl::readAgentValue( VCARD::ContentLine *cl ) { Agent agent; bool isIntern = true; |