Diffstat (limited to 'kabc/vcardparser/vcardtool.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r-- | kabc/vcardparser/vcardtool.cpp | 484 |
1 files changed, 227 insertions, 257 deletions
diff --git a/kabc/vcardparser/vcardtool.cpp b/kabc/vcardparser/vcardtool.cpp index d1f823b..32b6c1e 100644 --- a/kabc/vcardparser/vcardtool.cpp +++ b/kabc/vcardparser/vcardtool.cpp @@ -22,4 +22,2 @@ #include <qstring.h> -#include <qregexp.h> -#include <kmdcodec.h> @@ -59,3 +57,2 @@ VCardTool::VCardTool() mPhoneTypeMap.insert( "PAGER", PhoneNumber::Pager ); - mPhoneTypeMap.insert( "SIP", PhoneNumber::Sip ); } @@ -66,2 +63,3 @@ VCardTool::~VCardTool() +// TODO: make list a const& QString VCardTool::createVCards( Addressee::List list, VCard::Version version ) @@ -69,5 +67,7 @@ QString VCardTool::createVCards( Addressee::List list, VCard::Version version ) VCard::List vCardList; + static const QRegExp semiExp(";"); - Addressee::List::Iterator addrIt; - for ( addrIt = list.begin(); addrIt != list.end(); ++addrIt ) { + Addressee::List::ConstIterator addrIt; + Addressee::List::ConstIterator listEnd( list.end() ); + for ( addrIt = list.begin(); addrIt != listEnd; ++addrIt ) { VCard card; @@ -76,46 +76,41 @@ QString VCardTool::createVCards( Addressee::List list, VCard::Version version ) // ADR + LABEL - Address::List addresses = (*addrIt).addresses(); - for ( Address::List::Iterator it = addresses.begin(); it != addresses.end(); ++it ) { + const Address::List addresses = (*addrIt).addresses(); + for ( Address::List::ConstIterator it = addresses.begin(); it != addresses.end(); ++it ) { QStringList address; -/*US - address.append( (*it).postOfficeBox().replace( ';', "\\;" ) ); - address.append( (*it).extended().replace( ';', "\\;" ) ); - address.append( (*it).street().replace( ';', "\\;" ) ); - address.append( (*it).locality().replace( ';', "\\;" ) ); - address.append( (*it).region().replace( ';', "\\;" ) ); - address.append( (*it).postalCode().replace( ';', "\\;" ) ); - address.append( (*it).country().replace( ';', "\\;" ) ); -*/ -//US using the old implementation instead - //qDebug("VCardTool::createVCards has to be verified"); - address.append( (*it).postOfficeBox().replace( QRegExp(";"), "\\;" ) ); - address.append( (*it).extended().replace( QRegExp(";"), "\\;" ) ); - address.append( (*it).street().replace( QRegExp(";"), "\\;" ) ); - address.append( (*it).locality().replace( QRegExp(";"), "\\;" ) ); - address.append( (*it).region().replace( QRegExp(";"), "\\;" ) ); - address.append( (*it).postalCode().replace( QRegExp(";"), "\\;" ) ); - address.append( (*it).country().replace( QRegExp(";"), "\\;" ) ); + bool isEmpty = ( (*it).postOfficeBox().isEmpty() && + (*it).extended().isEmpty() && + (*it).street().isEmpty() && + (*it).locality().isEmpty() && + (*it).region().isEmpty() && + (*it).postalCode().isEmpty() && + (*it).country().isEmpty() ); + + address.append( (*it).postOfficeBox().replace( semiExp, "\\;" ) ); + address.append( (*it).extended().replace( semiExp, "\\;" ) ); + address.append( (*it).street().replace( semiExp, "\\;" ) ); + address.append( (*it).locality().replace( semiExp, "\\;" ) ); + address.append( (*it).region().replace( semiExp, "\\;" ) ); + address.append( (*it).postalCode().replace( semiExp, "\\;" ) ); + address.append( (*it).country().replace( semiExp, "\\;" ) ); VCardLine adrLine( "ADR", address.join( ";" ) ); + if ( version == VCard::v2_1 ) { + adrLine.addParameter( "CHARSET", "UTF-8" ); + adrLine.addParameter( "ENCODING", "8BIT" ); + } + VCardLine labelLine( "LABEL", (*it).label() ); + if ( version == VCard::v2_1 ) { + labelLine.addParameter( "CHARSET", "UTF-8" ); + labelLine.addParameter( "ENCODING", "8BIT" ); + } bool hasLabel = !(*it).label().isEmpty(); - QMap<QString, int>::Iterator typeIt; + QMap<QString, int>::ConstIterator typeIt; for ( typeIt = mAddressTypeMap.begin(); typeIt != mAddressTypeMap.end(); ++typeIt ) { if ( typeIt.data() & (*it).type() ) { - if ( version == VCard::v3_0 ) { - adrLine.addParameter( "TYPE", typeIt.key().lower() ); - } - else { - adrLine.addParameter( "TYPE", typeIt.key() ); - } - if ( hasLabel ) { - if ( version == VCard::v3_0 ) { - labelLine.addParameter( "TYPE", typeIt.key().lower() ); - } - else { - labelLine.addParameter( "TYPE", typeIt.key() ); - } - } + adrLine.addParameter( "TYPE", typeIt.key() ); + if ( hasLabel ) + labelLine.addParameter( "TYPE", typeIt.key() ); } @@ -123,3 +118,4 @@ QString VCardTool::createVCards( Addressee::List list, VCard::Version version ) - card.addLine( adrLine ); + if ( !isEmpty ) + card.addLine( adrLine ); if ( hasLabel ) @@ -139,9 +135,11 @@ QString VCardTool::createVCards( Addressee::List list, VCard::Version version ) for ( catIt = categories.begin(); catIt != categories.end(); ++catIt ) - { -//US using the old implementation instead - // qDebug("VCardTool::createVCards has to be verified"); -//US (*catIt).replace( ',', "\\," ); (*catIt).replace( QRegExp(","), "\\," ); + + VCardLine catLine( "CATEGORIES", categories.join( "," ) ); + if ( version == VCard::v2_1 ) { + catLine.addParameter( "CHARSET", "UTF-8" ); + catLine.addParameter( "ENCODING", "8BIT" ); } - card.addLine( VCardLine( "CATEGORIES", categories.join( "," ) ) ); + + card.addLine( catLine ); } @@ -152,5 +150,5 @@ QString VCardTool::createVCards( Addressee::List list, VCard::Version version ) } - + // EMAIL - QStringList emails = (*addrIt).emails(); + const QStringList emails = (*addrIt).emails(); bool pref = true; @@ -158,3 +156,7 @@ QString VCardTool::createVCards( Addressee::List list, VCard::Version version ) VCardLine line( "EMAIL", *strIt ); - if ( pref == true ) { + if ( version == VCard::v2_1 ) { + line.addParameter( "CHARSET", "UTF-8" ); + line.addParameter( "ENCODING", "8BIT" ); + } + if ( pref == true && emails.count() > 1 ) { line.addParameter( "TYPE", "PREF" ); @@ -166,3 +168,8 @@ QString VCardTool::createVCards( Addressee::List list, VCard::Version version ) // FN - card.addLine( VCardLine( "FN", (*addrIt).formattedName() ) ); + VCardLine fnLine( "FN", (*addrIt).formattedName() ); + if ( version == VCard::v2_1 ) { + fnLine.addParameter( "CHARSET", "UTF-8" ); + fnLine.addParameter( "ENCODING", "8BIT" ); + } + card.addLine( fnLine ); @@ -177,3 +184,3 @@ QString VCardTool::createVCards( Addressee::List list, VCard::Version version ) // KEY - Key::List keys = (*addrIt).keys(); + const Key::List keys = (*addrIt).keys(); Key::List::ConstIterator keyIt; @@ -186,3 +193,8 @@ QString VCardTool::createVCards( Addressee::List list, VCard::Version version ) // MAILER - card.addLine( VCardLine( "MAILER", (*addrIt).mailer() ) ); + VCardLine mailerLine( "MAILER", (*addrIt).mailer() ); + if ( version == VCard::v2_1 ) { + mailerLine.addParameter( "CHARSET", "UTF-8" ); + mailerLine.addParameter( "ENCODING", "8BIT" ); + } + card.addLine( mailerLine ); @@ -190,19 +202,22 @@ QString VCardTool::createVCards( Addressee::List list, VCard::Version version ) QStringList name; -//US using the old implementation instead - //qDebug("VCardTool::createVCards has to be verified"); -/*US - name.append( (*addrIt).familyName().replace( ';', "\\;" ) ); - name.append( (*addrIt).givenName().replace( ';', "\\;" ) ); - name.append( (*addrIt).additionalName().replace( ';', "\\;" ) ); - name.append( (*addrIt).prefix().replace( ';', "\\;" ) ); - name.append( (*addrIt).suffix().replace( ';', "\\;" ) ); -*/ - name.append( (*addrIt).familyName().replace( QRegExp(";"), "\\;" ) ); - name.append( (*addrIt).givenName().replace( QRegExp(";"), "\\;" ) ); - name.append( (*addrIt).additionalName().replace( QRegExp(";"), "\\;" ) ); - name.append( (*addrIt).prefix().replace( QRegExp(";"), "\\;" ) ); - name.append( (*addrIt).suffix().replace( QRegExp(";"), "\\;" ) ); - - if ( !name.join( "" ).isEmpty() ) - card.addLine( VCardLine( "N", name.join( ";" ) ) ); + name.append( (*addrIt).familyName().replace( semiExp, "\\;" ) ); + name.append( (*addrIt).givenName().replace( semiExp, "\\;" ) ); + name.append( (*addrIt).additionalName().replace( semiExp, "\\;" ) ); + name.append( (*addrIt).prefix().replace( semiExp, "\\;" ) ); + name.append( (*addrIt).suffix().replace( semiExp, "\\;" ) ); + + VCardLine nLine( "N", name.join( ";" ) ); + if ( version == VCard::v2_1 ) { + nLine.addParameter( "CHARSET", "UTF-8" ); + nLine.addParameter( "ENCODING", "8BIT" ); + } + card.addLine( nLine ); + + // NAME + VCardLine nameLine( "NAME", (*addrIt).name() ); + if ( version == VCard::v2_1 ) { + nameLine.addParameter( "CHARSET", "UTF-8" ); + nameLine.addParameter( "ENCODING", "8BIT" ); + } + card.addLine( nameLine ); @@ -213,6 +228,16 @@ QString VCardTool::createVCards( Addressee::List list, VCard::Version version ) // NOTE - card.addLine( VCardLine( "NOTE", (*addrIt).note() ) ); + VCardLine noteLine( "NOTE", (*addrIt).note() ); + if ( version == VCard::v2_1 ) { + noteLine.addParameter( "CHARSET", "UTF-8" ); + noteLine.addParameter( "ENCODING", "8BIT" ); + } + card.addLine( noteLine ); // ORG - card.addLine( VCardLine( "ORG", (*addrIt).organization() ) ); + VCardLine orgLine( "ORG", (*addrIt).organization() ); + if ( version == VCard::v2_1 ) { + orgLine.addParameter( "CHARSET", "UTF-8" ); + orgLine.addParameter( "ENCODING", "8BIT" ); + } + card.addLine( orgLine ); @@ -229,3 +254,8 @@ QString VCardTool::createVCards( Addressee::List list, VCard::Version version ) // ROLE - card.addLine( VCardLine( "ROLE", (*addrIt).role() ) ); + VCardLine roleLine( "ROLE", (*addrIt).role() ); + if ( version == VCard::v2_1 ) { + roleLine.addParameter( "CHARSET", "UTF-8" ); + roleLine.addParameter( "ENCODING", "8BIT" ); + } + card.addLine( roleLine ); @@ -239,3 +269,3 @@ QString VCardTool::createVCards( Addressee::List list, VCard::Version version ) // TEL - PhoneNumber::List phoneNumbers = (*addrIt).phoneNumbers(); + const PhoneNumber::List phoneNumbers = (*addrIt).phoneNumbers(); PhoneNumber::List::ConstIterator phoneIt; @@ -244,9 +274,6 @@ QString VCardTool::createVCards( Addressee::List list, VCard::Version version ) - QMap<QString, int>::Iterator typeIt; + QMap<QString, int>::ConstIterator typeIt; for ( typeIt = mPhoneTypeMap.begin(); typeIt != mPhoneTypeMap.end(); ++typeIt ) { if ( typeIt.data() & (*phoneIt).type() ) - if ( version == VCard::v3_0 ) - line.addParameter( "TYPE", typeIt.key().lower() ); - else - line.addParameter( "TYPE", typeIt.key() ); + line.addParameter( "TYPE", typeIt.key() ); } @@ -257,3 +284,8 @@ QString VCardTool::createVCards( Addressee::List list, VCard::Version version ) // TITLE - card.addLine( VCardLine( "TITLE", (*addrIt).title() ) ); + VCardLine titleLine( "TITLE", (*addrIt).title() ); + if ( version == VCard::v2_1 ) { + titleLine.addParameter( "CHARSET", "UTF-8" ); + titleLine.addParameter( "ENCODING", "8BIT" ); + } + card.addLine( titleLine ); @@ -288,3 +320,3 @@ QString VCardTool::createVCards( Addressee::List list, VCard::Version version ) // X- - QStringList customs = (*addrIt).customs(); + const QStringList customs = (*addrIt).customs(); for ( strIt = customs.begin(); strIt != customs.end(); ++strIt ) { @@ -295,3 +327,8 @@ QString VCardTool::createVCards( Addressee::List list, VCard::Version version ) - card.addLine( VCardLine( identifier, value ) ); + VCardLine line( identifier, value ); + if ( version == VCard::v2_1 ) { + line.addParameter( "CHARSET", "UTF-8" ); + line.addParameter( "ENCODING", "8BIT" ); + } + card.addLine( line ); } @@ -306,4 +343,4 @@ Addressee::List VCardTool::parseVCards( const QString& vcard ) { - QChar semicolonSep( ';' ); - QChar commaSep( ',' ); + static const QChar semicolonSep( ';' ); + static const QChar commaSep( ',' ); QString identifier; @@ -311,12 +348,15 @@ Addressee::List VCardTool::parseVCards( const QString& vcard ) Addressee::List addrList; - VCard::List vCardList = VCardParser::parseVCards( vcard ); - VCard::List::Iterator cardIt; - for ( cardIt = vCardList.begin(); cardIt != vCardList.end(); ++cardIt ) { + const VCard::List vCardList = VCardParser::parseVCards( vcard ); + + VCard::List::ConstIterator cardIt; + VCard::List::ConstIterator listEnd( vCardList.end() ); + for ( cardIt = vCardList.begin(); cardIt != listEnd; ++cardIt ) { Addressee addr; - QStringList idents = (*cardIt).identifiers(); + + const QStringList idents = (*cardIt).identifiers(); QStringList::ConstIterator identIt; - for ( identIt = idents.begin(); identIt != idents.end(); ++identIt ) { - VCard card = (*cardIt); - VCardLine::List lines = card.lines( (*identIt) ); - VCardLine::List::Iterator lineIt; + QStringList::ConstIterator identEnd( idents.end() ); + for ( identIt = idents.begin(); identIt != identEnd; ++identIt ) { + const VCardLine::List lines = (*cardIt).lines( (*identIt) ); + VCardLine::List::ConstIterator lineIt; @@ -324,4 +364,2 @@ Addressee::List VCardTool::parseVCards( const QString& vcard ) for ( lineIt = lines.begin(); lineIt != lines.end(); ++lineIt ) { - QStringList params = (*lineIt).parameterList(); - identifier = (*lineIt).identifier().lower(); @@ -330,3 +368,3 @@ Addressee::List VCardTool::parseVCards( const QString& vcard ) Address address; - QStringList addrParts = splitString( semicolonSep, (*lineIt).value().asString() ); + const QStringList addrParts = splitString( semicolonSep, (*lineIt).value().asString() ); if ( addrParts.count() > 0 ) @@ -336,3 +374,3 @@ Addressee::List VCardTool::parseVCards( const QString& vcard ) if ( addrParts.count() > 2 ) - address.setStreet( addrParts[ 2 ].replace ( QRegExp("\\\\n") , "\n") ); + address.setStreet( addrParts[ 2 ] ); if ( addrParts.count() > 3 ) @@ -348,9 +386,6 @@ Addressee::List VCardTool::parseVCards( const QString& vcard ) - QStringList types = (*lineIt).parameters( "type" ); - for ( QStringList::Iterator it = types.begin(); it != types.end(); ++it ) + const QStringList types = (*lineIt).parameters( "type" ); + for ( QStringList::ConstIterator it = types.begin(); it != types.end(); ++it ) type += mAddressTypeMap[ (*it).lower() ]; - if ( !type ) - type = Address::Home; // default - address.setType( type ); @@ -360,3 +395,3 @@ Addressee::List VCardTool::parseVCards( const QString& vcard ) // AGENT - if ( identifier == "agent" ) + else if ( identifier == "agent" ) addr.setAgent( parseAgent( *lineIt ) ); @@ -364,3 +399,3 @@ Addressee::List VCardTool::parseVCards( const QString& vcard ) // BDAY - if ( identifier == "bday" ) + else if ( identifier == "bday" ) addr.setBirthday( parseDateTime( (*lineIt).value().asString() ) ); @@ -368,4 +403,4 @@ Addressee::List VCardTool::parseVCards( const QString& vcard ) // CATEGORIES - if ( identifier == "categories" ) { - QStringList categories = splitString( commaSep, (*lineIt).value().asString() ); + else if ( identifier == "categories" ) { + const QStringList categories = splitString( commaSep, (*lineIt).value().asString() ); addr.setCategories( categories ); @@ -374,3 +409,3 @@ Addressee::List VCardTool::parseVCards( const QString& vcard ) // CLASS - if ( identifier == "class" ) + else if ( identifier == "class" ) addr.setSecrecy( parseSecrecy( *lineIt ) ); @@ -378,5 +413,5 @@ Addressee::List VCardTool::parseVCards( const QString& vcard ) // EMAIL - if ( identifier == "email" ) { - QStringList types = (*lineIt).parameters( "type" ); - addr.insertEmail( (*lineIt).value().asString(), types.contains( "PREF" ) ); + else if ( identifier == "email" ) { + const QStringList types = (*lineIt).parameters( "type" ); + addr.insertEmail( (*lineIt).value().asString(), types.findIndex( "PREF" ) != -1 ); } @@ -384,3 +419,3 @@ Addressee::List VCardTool::parseVCards( const QString& vcard ) // FN - if ( identifier == "fn" ) + else if ( identifier == "fn" ) addr.setFormattedName( (*lineIt).value().asString() ); @@ -388,6 +423,6 @@ Addressee::List VCardTool::parseVCards( const QString& vcard ) // GEO - if ( identifier == "geo" ) { + else if ( identifier == "geo" ) { Geo geo; - QStringList geoParts = QStringList::split( ';', (*lineIt).value().asString(), true ); + const QStringList geoParts = QStringList::split( ';', (*lineIt).value().asString(), true ); geo.setLatitude( geoParts[ 0 ].toFloat() ); @@ -399,3 +434,3 @@ Addressee::List VCardTool::parseVCards( const QString& vcard ) // KEY - if ( identifier == "key" ) + else if ( identifier == "key" ) addr.insertKey( parseKey( *lineIt ) ); @@ -403,12 +438,10 @@ Addressee::List VCardTool::parseVCards( const QString& vcard ) // LABEL - if ( identifier == "label" ) { + else if ( identifier == "label" ) { int type = 0; - QStringList types = (*lineIt).parameters( "type" ); - for ( QStringList::Iterator it = types.begin(); it != types.end(); ++it ) + const QStringList types = (*lineIt).parameters( "type" ); + for ( QStringList::ConstIterator it = types.begin(); it != types.end(); ++it ) type += mAddressTypeMap[ (*it).lower() ]; - if ( !type ) - type = Address::Home; - + bool available = false; KABC::Address::List addressList = addr.addresses(); @@ -419,4 +452,12 @@ Addressee::List VCardTool::parseVCards( const QString& vcard ) addr.insertAddress( *it ); + available = true; + break; } } + + if ( !available ) { // a standalone LABEL tag + KABC::Address address( type ); + address.setLabel( (*lineIt).value().asString() ); + addr.insertAddress( address ); + } } @@ -424,3 +465,3 @@ Addressee::List VCardTool::parseVCards( const QString& vcard ) // LOGO - if ( identifier == "logo" ) + else if ( identifier == "logo" ) addr.setLogo( parsePicture( *lineIt ) ); @@ -428,3 +469,3 @@ Addressee::List VCardTool::parseVCards( const QString& vcard ) // MAILER - if ( identifier == "mailer" ) + else if ( identifier == "mailer" ) addr.setMailer( (*lineIt).value().asString() ); @@ -432,4 +473,4 @@ Addressee::List VCardTool::parseVCards( const QString& vcard ) // N - if ( identifier == "n" ) { - QStringList nameParts = splitString( semicolonSep, (*lineIt).value().asString() ); + else if ( identifier == "n" ) { + const QStringList nameParts = splitString( semicolonSep, (*lineIt).value().asString() ); if ( nameParts.count() > 0 ) @@ -446,4 +487,8 @@ Addressee::List VCardTool::parseVCards( const QString& vcard ) + // NAME + else if ( identifier == "name" ) + addr.setName( (*lineIt).value().asString() ); + // NICKNAME - if ( identifier == "nickname" ) + else if ( identifier == "nickname" ) addr.setNickName( (*lineIt).value().asString() ); @@ -451,16 +496,7 @@ Addressee::List VCardTool::parseVCards( const QString& vcard ) // NOTE - if ( identifier == "note" ) { -// #ifdef DESKTOP_VERSION -// addr.setNote( (*lineIt).value().asString() ); -// #else - QString note = (*lineIt).value().asString(); - if ( ! note.isEmpty() ) - addr.setNote( note.replace ( QRegExp("\\\\n") , "\n") ); - else - addr.setNote( note ); - //#endif - } + else if ( identifier == "note" ) + addr.setNote( (*lineIt).value().asString() ); // ORGANIZATION - if ( identifier == "org" ) + else if ( identifier == "org" ) addr.setOrganization( (*lineIt).value().asString() ); @@ -468,3 +504,3 @@ Addressee::List VCardTool::parseVCards( const QString& vcard ) // PHOTO - if ( identifier == "photo" ) + else if ( identifier == "photo" ) addr.setPhoto( parsePicture( *lineIt ) ); @@ -472,3 +508,3 @@ Addressee::List VCardTool::parseVCards( const QString& vcard ) // PROID - if ( identifier == "prodid" ) + else if ( identifier == "prodid" ) addr.setProductId( (*lineIt).value().asString() ); @@ -476,3 +512,3 @@ Addressee::List VCardTool::parseVCards( const QString& vcard ) // REV - if ( identifier == "rev" ) + else if ( identifier == "rev" ) addr.setRevision( parseDateTime( (*lineIt).value().asString() ) ); @@ -480,3 +516,3 @@ Addressee::List VCardTool::parseVCards( const QString& vcard ) // ROLE - if ( identifier == "role" ) + else if ( identifier == "role" ) addr.setRole( (*lineIt).value().asString() ); @@ -484,3 +520,3 @@ Addressee::List VCardTool::parseVCards( const QString& vcard ) // SORT-STRING - if ( identifier == "sort-string" ) + else if ( identifier == "sort-string" ) addr.setSortString( (*lineIt).value().asString() ); @@ -488,3 +524,3 @@ Addressee::List VCardTool::parseVCards( const QString& vcard ) // SOUND - if ( identifier == "sound" ) + else if ( identifier == "sound" ) addr.setSound( parseSound( *lineIt ) ); @@ -492,3 +528,3 @@ Addressee::List VCardTool::parseVCards( const QString& vcard ) // TEL - if ( identifier == "tel" ) { + else if ( identifier == "tel" ) { PhoneNumber phone; @@ -498,9 +534,6 @@ Addressee::List VCardTool::parseVCards( const QString& vcard ) - QStringList types = (*lineIt).parameters( "type" ); - for ( QStringList::Iterator it = types.begin(); it != types.end(); ++it ) + const QStringList types = (*lineIt).parameters( "type" ); + for ( QStringList::ConstIterator it = types.begin(); it != types.end(); ++it ) type += mPhoneTypeMap[(*it).upper()]; - if ( !type ) - type = PhoneNumber::Home; // default - phone.setType( type ); @@ -511,3 +544,3 @@ Addressee::List VCardTool::parseVCards( const QString& vcard ) // TITLE - if ( identifier == "title" ) + else if ( identifier == "title" ) addr.setTitle( (*lineIt).value().asString() ); @@ -515,5 +548,5 @@ Addressee::List VCardTool::parseVCards( const QString& vcard ) // TZ - if ( identifier == "tz" ) { + else if ( identifier == "tz" ) { TimeZone tz; - QString date = (*lineIt).value().asString(); + const QString date = (*lineIt).value().asString(); @@ -529,3 +562,3 @@ Addressee::List VCardTool::parseVCards( const QString& vcard ) // UID - if ( identifier == "uid" ) + else if ( identifier == "uid" ) addr.setUid( (*lineIt).value().asString() ); @@ -533,8 +566,8 @@ Addressee::List VCardTool::parseVCards( const QString& vcard ) // URL - if ( identifier == "url" ) - addr.setUrl( (*lineIt).value().asString() ); + else if ( identifier == "url" ) + addr.setUrl( KURL( (*lineIt).value().asString() ) ); // X- - if ( identifier.startsWith( "x-" ) ) { - QString key = (*lineIt).identifier().mid( 2 ); + else if ( identifier.startsWith( "x-" ) ) { + const QString key = (*lineIt).identifier().mid( 2 ); int dash = key.find( "-" ); @@ -595,27 +628,18 @@ Picture VCardTool::parsePicture( const VCardLine &line ) { - Picture pic; - - QStringList params = line.parameterList(); - if ( params.contains( "encoding" ) ) { - QCString cs(line.value().asCString()); - QByteArray input, output; - input = line.value().asCString(); - if ( line.parameter( "encoding" ).lower() == "b" ) - KCodecs::base64Decode( input, output ); - else if ( line.parameter( "encoding" ).lower() == "quoted-printable" ) - KCodecs::quotedPrintableDecode( input, output ); - - qDebug("********** DECODING OKAY ************** (picture)"); - pic.setData( QImage(output) ); - - } - else if ( params.contains( "value" ) ) { - if ( line.parameter( "value" ).lower() == "uri" ) - pic.setUrl( line.value().asString() ); - } - - if ( params.contains( "type" ) ) - pic.setType( line.parameter( "type" ) ); - - return pic; + Picture pic; + + const QStringList params = line.parameterList(); + if ( params.findIndex( "encoding" ) != -1 ) { + QImage img; + img.loadFromData( line.valueBytes() ); + pic.setData( img ); + } else if ( params.findIndex( "value" ) != -1 ) { + if ( line.parameter( "value" ).lower() == "uri" ) + pic.setUrl( line.value().asString() ); + } + + if ( params.findIndex( "type" ) != -1 ) + pic.setType( line.parameter( "type" ) ); + + return pic; } @@ -624,3 +648,2 @@ VCardLine VCardTool::createPicture( const QString &identifier, const Picture &pi { - // LR fixed VCardLine line( identifier ); @@ -629,3 +652,2 @@ VCardLine VCardTool::createPicture( const QString &identifier, const Picture &pi if ( !pic.data().isNull() ) { -#if 0 QByteArray input; @@ -635,12 +657,2 @@ VCardLine VCardTool::createPicture( const QString &identifier, const Picture &pi line.setValue( input ); -#else - QCString input; - QDataStream s( input, IO_WriteOnly ); - s.setVersion( 4 ); - s << pic.data(); - //QCString cs(line.value().asCString()); - //QImage qi(cs); - line.setValue( input ); -#endif - line.addParameter( "encoding", "b" ); @@ -649,2 +661,3 @@ VCardLine VCardTool::createPicture( const QString &identifier, const Picture &pi } else if ( !pic.url().isEmpty() ) { + QByteArray ba; line.setValue( pic.url() ); @@ -652,3 +665,3 @@ VCardLine VCardTool::createPicture( const QString &identifier, const Picture &pi } - + return line; @@ -660,11 +673,6 @@ Sound VCardTool::parseSound( const VCardLine &line ) - QStringList params = line.parameterList(); - if ( params.contains( "encoding" ) ) { - qDebug("VCardTool::parseSound has to be verified"); -//US snd.setData( line.value().asByteArray() ); -//US I am not sure if this is correct - QCString cs(line.value().asCString()); - snd.setData( cs ); - } - else if ( params.contains( "value" ) ) { + const QStringList params = line.parameterList(); + if ( params.findIndex( "encoding" ) != -1 ) + snd.setData( line.valueBytes() ); + else if ( params.findIndex( "value" ) != -1 ) { if ( line.parameter( "value" ).lower() == "uri" ) @@ -687,10 +695,3 @@ VCardLine VCardTool::createSound( const Sound &snd ) if ( !snd.data().isEmpty() ) { - qDebug("VCardTool::createSound has to be verified"); -//US line.setValue( snd.data() ); - -//US I am not sure if this is correct - QCString cs(snd.data()); - line.setValue( cs ); - - + line.setValue( snd.data() ); line.addParameter( "encoding", "b" ); @@ -710,11 +711,5 @@ Key VCardTool::parseKey( const VCardLine &line ) - QStringList params = line.parameterList(); - if ( params.contains( "encoding" ) ) { - qDebug("VCardTool::parseKey has to be verified"); -//US key.setBinaryData( line.value().asByteArray() ); - -//US I am not sure if this is correct - QCString cs( line.value().asCString() ); - key.setBinaryData( cs ); - } + const QStringList params = line.parameterList(); + if ( params.findIndex( "encoding" ) != -1 ) + key.setBinaryData( line.valueBytes() ); else @@ -722,3 +717,3 @@ Key VCardTool::parseKey( const VCardLine &line ) - if ( params.contains( "type" ) ) { + if ( params.findIndex( "type" ) != -1 ) { if ( line.parameter( "type" ).lower() == "x509" ) @@ -742,9 +737,3 @@ VCardLine VCardTool::createKey( const Key &key ) if ( !key.binaryData().isEmpty() ) { - qDebug("VCardTool::createKey has to be verified"); -//US line.setValue( key.binaryData() ); -//US I am not sure if this is correct - QCString cs(key.binaryData()); - line.setValue( cs ); - - + line.setValue( key.binaryData() ); line.addParameter( "encoding", "b" ); @@ -798,4 +787,4 @@ Agent VCardTool::parseAgent( const VCardLine &line ) - QStringList params = line.parameterList(); - if ( params.contains( "value" ) ) { + const QStringList params = line.parameterList(); + if ( params.findIndex( "value" ) != -1 ) { if ( line.parameter( "value" ).lower() == "uri" ) @@ -804,19 +793,9 @@ Agent VCardTool::parseAgent( const VCardLine &line ) QString str = line.value().asString(); - -//US using the old implementation instead - qDebug("VCardTool::parseAgent has to be verified"); -/*US - str.replace( "\\n", "\r\n" ); - str.replace( "\\N", "\r\n" ); - str.replace( "\\;", ";" ); - str.replace( "\\:", ":" ); - str.replace( "\\,", "," ); -*/ - str.replace( QRegExp("\\\\n") , "\r\n" ); - str.replace( QRegExp("\\\\N") , "\r\n" ); - str.replace( QRegExp("\\\\;") , ";" ); - str.replace( QRegExp("\\\\:") , ":" ); - str.replace( QRegExp("\\\\,") , "," ); - - Addressee::List list = parseVCards( str ); + str.replace( QRegExp("\\\\n"), "\r\n" ); + str.replace( QRegExp("\\\\N"), "\r\n" ); + str.replace( QRegExp("\\\\;"), ";" ); + str.replace( QRegExp("\\\\:"), ":" ); + str.replace( QRegExp("\\\\,"), "," ); + + const Addressee::List list = parseVCards( str ); if ( list.count() > 0 ) { @@ -841,12 +820,3 @@ VCardLine VCardTool::createAgent( VCard::Version version, const Agent &agent ) QString str = createVCards( list, version ); - -//US using the old implementation instead - qDebug("VCardTool::createAgent has to be verified"); -/*US - str.replace( "\r\n", "\\n" ); - str.replace( ";", "\\;" ); - str.replace( ":", "\\:" ); - str.replace( ",", "\\," ); -*/ - str.replace( QRegExp("\r\n"), "\\n" ); + str.replace( QRegExp("\\r\\n"), "\\n" ); str.replace( QRegExp(";"), "\\;" ); @@ -885,3 +855,3 @@ QStringList VCardTool::splitString( const QChar &sep, const QString &str ) pos = value.find( sep, pos ); - } else + } else pos = value.find( sep, pos + 1 ); |