author | zautrix <zautrix> | 2005-04-08 22:05:03 (UTC) |
---|---|---|
committer | zautrix <zautrix> | 2005-04-08 22:05:03 (UTC) |
commit | 9667e6f2589d5b2080cca928814f382761f8dda6 (patch) (side-by-side diff) | |
tree | 438bcb5c041de0804284cf457cbc97a367dadf37 /kabc/vcardparser | |
parent | c0f1d38e29ee0d0a1d1dcb5bda08089923926b41 (diff) | |
download | kdepimpi-9667e6f2589d5b2080cca928814f382761f8dda6.zip kdepimpi-9667e6f2589d5b2080cca928814f382761f8dda6.tar.gz kdepimpi-9667e6f2589d5b2080cca928814f382761f8dda6.tar.bz2 |
utf8 kapi import fix
-rw-r--r-- | kabc/vcardparser/vcard.cpp | 2 | ||||
-rw-r--r-- | kabc/vcardparser/vcardline.cpp | 14 | ||||
-rw-r--r-- | kabc/vcardparser/vcardline.h | 7 | ||||
-rw-r--r-- | kabc/vcardparser/vcardparser.cpp | 8 | ||||
-rw-r--r-- | kabc/vcardparser/vcardtool.cpp | 86 |
5 files changed, 61 insertions, 56 deletions
diff --git a/kabc/vcardparser/vcard.cpp b/kabc/vcardparser/vcard.cpp index 24fd498..bc9f208 100644 --- a/kabc/vcardparser/vcard.cpp +++ b/kabc/vcardparser/vcard.cpp @@ -111,7 +111,7 @@ VCard::Version VCard::version() const return v3_0; VCardLine line = ( *versionEntry )[ 0 ]; - if ( line.value() == "2.1" ) + if ( line.valueString() == "2.1" ) return v2_1; else return v3_0; diff --git a/kabc/vcardparser/vcardline.cpp b/kabc/vcardparser/vcardline.cpp index 0972a35..8df2d32 100644 --- a/kabc/vcardparser/vcardline.cpp +++ b/kabc/vcardparser/vcardline.cpp @@ -82,19 +82,23 @@ QString VCardLine::identifier() const return mIdentifier; } -void VCardLine::setValue( const QString& value ) +void VCardLine::setValueString( const QString& value ) { - mValue.duplicate( value.data(), value.length() ); + setValueCString( value.utf8() ); +} +void VCardLine::setValueCString( const QCString& value ) +{ + mValue.duplicate( value.data(), value.length() ); } -void VCardLine::setValue( const QByteArray& value ) +void VCardLine::setValueBytes( const QByteArray& value ) { mValue = value; } -QVariant VCardLine::value() const +QString VCardLine::valueString() const { - return QVariant( QCString( mValue.data(), mValue.size()+1 ) ); + return QString::fromUtf8( mValue.data(), mValue.size() ); } QByteArray VCardLine::valueBytes() const diff --git a/kabc/vcardparser/vcardline.h b/kabc/vcardparser/vcardline.h index 6e74b38..8dc9322 100644 --- a/kabc/vcardparser/vcardline.h +++ b/kabc/vcardparser/vcardline.h @@ -58,13 +58,14 @@ class VCardLine /** * Sets the value of of this line. */ - void setValue( const QString& value ); - void setValue( const QByteArray& value ); + void setValueString( const QString& value ); + void setValueCString( const QCString& value ); + void setValueBytes( const QByteArray& value ); /** * Returns the value of this line. */ - QVariant value() const; + QString valueString() const; QByteArray valueBytes() const; /** diff --git a/kabc/vcardparser/vcardparser.cpp b/kabc/vcardparser/vcardparser.cpp index 7fae011..11622a0 100644 --- a/kabc/vcardparser/vcardparser.cpp +++ b/kabc/vcardparser/vcardparser.cpp @@ -126,12 +126,12 @@ VCard::List VCardParser::parseVCards( const QString& text ) // if ( vCardLine.parameter( "charset" ).lower() == "utf-8" ) { // vCardLine.setValue( QString::fromUtf8( output.data(), output.size() ) ); // } else - vCardLine.setValue( output ); + vCardLine.setValueBytes( output ); //PP our vcards are *supposed* to be in UTF-8 // } else if ( vCardLine.parameter( "charset" ).lower() == "utf-8" ) { // vCardLine.setValue( QString::fromUtf8( value.ascii() ) ); } else - vCardLine.setValue( value.replace( QRegExp("\\\\n"), "\n" ) ); + vCardLine.setValueString( value.replace( QRegExp("\\\\n"), "\n" ) ); currentVCard.addLine( vCardLine ); } @@ -188,7 +188,7 @@ QString VCardParser::createVCards( const VCard::List& list ) // iterate over the lines for ( lineIt = lines.begin(); lineIt != lines.end(); ++lineIt ) { - if ( !(*lineIt).value().asString().isEmpty() ) { + if ( !(*lineIt).valueString().isEmpty() ) { if ( (*lineIt).hasGroup() ) textLine = (*lineIt).group() + "." + (*lineIt).identifier(); else @@ -221,7 +221,7 @@ QString VCardParser::createVCards( const VCard::List& list ) KCodecs::quotedPrintableEncode( input, output ); textLine.append( ":" + QString( output ) ); } else - textLine.append( ":" + (*lineIt).value().asString().replace( QRegExp("\n"), "\\n" ) ); + textLine.append( ":" + (*lineIt).valueString().replace( QRegExp("\n"), "\\n" ) ); if ( textLine.length() > FOLD_WIDTH ) { // we have to fold the line for ( uint i = 0; i <= ( textLine.length() / FOLD_WIDTH ); ++i ) diff --git a/kabc/vcardparser/vcardtool.cpp b/kabc/vcardparser/vcardtool.cpp index 0cf72c0..c3d92b6 100644 --- a/kabc/vcardparser/vcardtool.cpp +++ b/kabc/vcardparser/vcardtool.cpp @@ -367,7 +367,7 @@ Addressee::List VCardTool::parseVCards( const QString& vcard ) // ADR if ( identifier == "adr" ) { Address address; - const QStringList addrParts = splitString( semicolonSep, (*lineIt).value().asString() ); + const QStringList addrParts = splitString( semicolonSep, (*lineIt).valueString() ); if ( addrParts.count() > 0 ) address.setPostOfficeBox( addrParts[ 0 ] ); if ( addrParts.count() > 1 ) @@ -399,11 +399,11 @@ Addressee::List VCardTool::parseVCards( const QString& vcard ) // BDAY else if ( identifier == "bday" ) - addr.setBirthday( parseDateTime( (*lineIt).value().asString() ) ); + addr.setBirthday( parseDateTime( (*lineIt).valueString() ) ); // CATEGORIES else if ( identifier == "categories" ) { - const QStringList categories = splitString( commaSep, (*lineIt).value().asString() ); + const QStringList categories = splitString( commaSep, (*lineIt).valueString() ); addr.setCategories( categories ); } @@ -414,18 +414,18 @@ Addressee::List VCardTool::parseVCards( const QString& vcard ) // EMAIL else if ( identifier == "email" ) { const QStringList types = (*lineIt).parameters( "type" ); - addr.insertEmail( (*lineIt).value().asString(), types.findIndex( "PREF" ) != -1 ); + addr.insertEmail( (*lineIt).valueString(), types.findIndex( "PREF" ) != -1 ); } // FN else if ( identifier == "fn" ) - addr.setFormattedName( (*lineIt).value().asString() ); + addr.setFormattedName( (*lineIt).valueString() ); // GEO else if ( identifier == "geo" ) { Geo geo; - const QStringList geoParts = QStringList::split( ';', (*lineIt).value().asString(), true ); + const QStringList geoParts = QStringList::split( ';', (*lineIt).valueString(), true ); geo.setLatitude( geoParts[ 0 ].toFloat() ); geo.setLongitude( geoParts[ 1 ].toFloat() ); @@ -449,7 +449,7 @@ Addressee::List VCardTool::parseVCards( const QString& vcard ) KABC::Address::List::Iterator it; for ( it = addressList.begin(); it != addressList.end(); ++it ) { if ( (*it).type() == type ) { - (*it).setLabel( (*lineIt).value().asString() ); + (*it).setLabel( (*lineIt).valueString() ); addr.insertAddress( *it ); available = true; break; @@ -458,7 +458,7 @@ Addressee::List VCardTool::parseVCards( const QString& vcard ) if ( !available ) { // a standalone LABEL tag KABC::Address address( type ); - address.setLabel( (*lineIt).value().asString() ); + address.setLabel( (*lineIt).valueString() ); addr.insertAddress( address ); } } @@ -469,11 +469,11 @@ Addressee::List VCardTool::parseVCards( const QString& vcard ) // MAILER else if ( identifier == "mailer" ) - addr.setMailer( (*lineIt).value().asString() ); + addr.setMailer( (*lineIt).valueString() ); // N else if ( identifier == "n" ) { - const QStringList nameParts = splitString( semicolonSep, (*lineIt).value().asString() ); + const QStringList nameParts = splitString( semicolonSep, (*lineIt).valueString() ); if ( nameParts.count() > 0 ) addr.setFamilyName( nameParts[ 0 ] ); if ( nameParts.count() > 1 ) @@ -488,19 +488,19 @@ Addressee::List VCardTool::parseVCards( const QString& vcard ) // NAME else if ( identifier == "name" ) - addr.setName( (*lineIt).value().asString() ); + addr.setName( (*lineIt).valueString() ); // NICKNAME else if ( identifier == "nickname" ) - addr.setNickName( (*lineIt).value().asString() ); + addr.setNickName( (*lineIt).valueString() ); // NOTE else if ( identifier == "note" ) - addr.setNote( (*lineIt).value().asString() ); + addr.setNote( (*lineIt).valueString() ); // ORGANIZATION else if ( identifier == "org" ) - addr.setOrganization( (*lineIt).value().asString() ); + addr.setOrganization( (*lineIt).valueString() ); // PHOTO else if ( identifier == "photo" ) @@ -508,19 +508,19 @@ Addressee::List VCardTool::parseVCards( const QString& vcard ) // PROID else if ( identifier == "prodid" ) - addr.setProductId( (*lineIt).value().asString() ); + addr.setProductId( (*lineIt).valueString() ); // REV else if ( identifier == "rev" ) - addr.setRevision( parseDateTime( (*lineIt).value().asString() ) ); + addr.setRevision( parseDateTime( (*lineIt).valueString() ) ); // ROLE else if ( identifier == "role" ) - addr.setRole( (*lineIt).value().asString() ); + addr.setRole( (*lineIt).valueString() ); // SORT-STRING else if ( identifier == "sort-string" ) - addr.setSortString( (*lineIt).value().asString() ); + addr.setSortString( (*lineIt).valueString() ); // SOUND else if ( identifier == "sound" ) @@ -529,7 +529,7 @@ Addressee::List VCardTool::parseVCards( const QString& vcard ) // TEL else if ( identifier == "tel" ) { PhoneNumber phone; - phone.setNumber( (*lineIt).value().asString() ); + phone.setNumber( (*lineIt).valueString() ); int type = 0; @@ -544,12 +544,12 @@ Addressee::List VCardTool::parseVCards( const QString& vcard ) // TITLE else if ( identifier == "title" ) - addr.setTitle( (*lineIt).value().asString() ); + addr.setTitle( (*lineIt).valueString() ); // TZ else if ( identifier == "tz" ) { TimeZone tz; - const QString date = (*lineIt).value().asString(); + const QString date = (*lineIt).valueString(); int hours = date.mid( 1, 2).toInt(); int minutes = date.mid( 4, 2 ).toInt(); @@ -562,17 +562,17 @@ Addressee::List VCardTool::parseVCards( const QString& vcard ) // UID else if ( identifier == "uid" ) - addr.setUid( (*lineIt).value().asString() ); + addr.setUid( (*lineIt).valueString() ); // URL else if ( identifier == "url" ) - addr.setUrl( KURL( (*lineIt).value().asString() ) ); + addr.setUrl( KURL( (*lineIt).valueString() ) ); // X- else if ( identifier.startsWith( "x-" ) ) { const QString key = (*lineIt).identifier().mid( 2 ); int dash = key.find( "-" ); - addr.insertCustom( key.left( dash ), key.mid( dash + 1 ), (*lineIt).value().asString() ); + addr.insertCustom( key.left( dash ), key.mid( dash + 1 ), (*lineIt).valueString() ); } } } @@ -636,7 +636,7 @@ Picture VCardTool::parsePicture( const VCardLine &line ) pic.setData( img ); } else if ( params.findIndex( "value" ) != -1 ) { if ( line.parameter( "value" ).lower() == "uri" ) - pic.setUrl( line.value().asString() ); + pic.setUrl( line.valueString() ); } if ( params.findIndex( "type" ) != -1 ) @@ -655,13 +655,13 @@ VCardLine VCardTool::createPicture( const QString &identifier, const Picture &pi QDataStream s( input, IO_WriteOnly ); s.setVersion( 4 ); s << pic.data(); - line.setValue( input ); + line.setValueBytes( input ); line.addParameter( "encoding", "b" ); line.addParameter( "type", "image/png" ); } } else if ( !pic.url().isEmpty() ) { QByteArray ba; - line.setValue( pic.url() ); + line.setValueString( pic.url() ); line.addParameter( "value", "URI" ); } @@ -677,7 +677,7 @@ Sound VCardTool::parseSound( const VCardLine &line ) snd.setData( line.valueBytes() ); else if ( params.findIndex( "value" ) != -1 ) { if ( line.parameter( "value" ).lower() == "uri" ) - snd.setUrl( line.value().asString() ); + snd.setUrl( line.valueString() ); } /* TODO: support sound types @@ -694,12 +694,12 @@ VCardLine VCardTool::createSound( const Sound &snd ) if ( snd.isIntern() ) { if ( !snd.data().isEmpty() ) { - line.setValue( snd.data() ); + line.setValueBytes( snd.data() ); line.addParameter( "encoding", "b" ); // TODO: need to store sound type!!! } } else if ( !snd.url().isEmpty() ) { - line.setValue( snd.url() ); + line.setValueString( snd.url() ); line.addParameter( "value", "URI" ); } @@ -714,7 +714,7 @@ Key VCardTool::parseKey( const VCardLine &line ) if ( params.findIndex( "encoding" ) != -1 ) key.setBinaryData( line.valueBytes() ); else - key.setTextData( line.value().asString() ); + key.setTextData( line.valueString() ); if ( params.findIndex( "type" ) != -1 ) { if ( line.parameter( "type" ).lower() == "x509" ) @@ -736,11 +736,11 @@ VCardLine VCardTool::createKey( const Key &key ) if ( key.isBinary() ) { if ( !key.binaryData().isEmpty() ) { - line.setValue( key.binaryData() ); + line.setValueBytes( key.binaryData() ); line.addParameter( "encoding", "b" ); } } else if ( !key.textData().isEmpty() ) - line.setValue( key.textData() ); + line.setValueString( key.textData() ); if ( key.type() == Key::X509 ) line.addParameter( "type", "X509" ); @@ -756,11 +756,11 @@ Secrecy VCardTool::parseSecrecy( const VCardLine &line ) { Secrecy secrecy; - if ( line.value().asString().lower() == "public" ) + if ( line.valueString().lower() == "public" ) secrecy.setType( Secrecy::Public ); - if ( line.value().asString().lower() == "private" ) + if ( line.valueString().lower() == "private" ) secrecy.setType( Secrecy::Private ); - if ( line.value().asString().lower() == "confidential" ) + if ( line.valueString().lower() == "confidential" ) secrecy.setType( Secrecy::Confidential ); return secrecy; @@ -773,11 +773,11 @@ VCardLine VCardTool::createSecrecy( const Secrecy &secrecy ) int type = secrecy.type(); if ( type == Secrecy::Public ) - line.setValue( "PUBLIC" ); + line.setValueString( "PUBLIC" ); else if ( type == Secrecy::Private ) - line.setValue( "PRIVATE" ); + line.setValueString( "PRIVATE" ); else if ( type == Secrecy::Confidential ) - line.setValue( "CONFIDENTIAL" ); + line.setValueString( "CONFIDENTIAL" ); return line; } @@ -789,9 +789,9 @@ Agent VCardTool::parseAgent( const VCardLine &line ) const QStringList params = line.parameterList(); if ( params.findIndex( "value" ) != -1 ) { if ( line.parameter( "value" ).lower() == "uri" ) - agent.setUrl( line.value().asString() ); + agent.setUrl( line.valueString() ); } else { - QString str = line.value().asString(); + QString str = line.valueString(); str.replace( QRegExp("\\\\n"), "\r\n" ); str.replace( QRegExp("\\\\N"), "\r\n" ); str.replace( QRegExp("\\\\;"), ";" ); @@ -823,10 +823,10 @@ VCardLine VCardTool::createAgent( VCard::Version version, const Agent &agent ) str.replace( QRegExp(";"), "\\;" ); str.replace( QRegExp(":"), "\\:" ); str.replace( QRegExp(","), "\\," ); - line.setValue( str ); + line.setValueString( str ); } } else if ( !agent.url().isEmpty() ) { - line.setValue( agent.url() ); + line.setValueString( agent.url() ); line.addParameter( "value", "URI" ); } |