summaryrefslogtreecommitdiffabout
authorzautrix <zautrix>2005-03-10 22:11:30 (UTC)
committer zautrix <zautrix>2005-03-10 22:11:30 (UTC)
commitb6845008e161e1bb355a32767c3e3f89ff8e5c01 (patch) (side-by-side diff)
treeb1618c2a81ee8fa26d00332352fde82f2e3e51c9
parent6e3c3178fa8e0c421753c08506b4a91bbcecc26f (diff)
downloadkdepimpi-b6845008e161e1bb355a32767c3e3f89ff8e5c01.zip
kdepimpi-b6845008e161e1bb355a32767c3e3f89ff8e5c01.tar.gz
kdepimpi-b6845008e161e1bb355a32767c3e3f89ff8e5c01.tar.bz2
quoted printable for kapi
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--kabc/vcardparser/vcard.cpp84
-rw-r--r--kabc/vcardparser/vcard.h11
-rw-r--r--kabc/vcardparser/vcardline.cpp115
-rw-r--r--kabc/vcardparser/vcardline.h31
-rw-r--r--kabc/vcardparser/vcardparser.cpp131
-rw-r--r--kabc/vcardparser/vcardtool.cpp484
6 files changed, 425 insertions, 431 deletions
diff --git a/kabc/vcardparser/vcard.cpp b/kabc/vcardparser/vcard.cpp
index da97ec2..24fd498 100644
--- a/kabc/vcardparser/vcard.cpp
+++ b/kabc/vcardparser/vcard.cpp
@@ -23,28 +23,16 @@
using namespace KABC;
VCard::VCard()
- : mLineMap( 0 )
{
}
VCard::VCard( const VCard& vcard )
- : mLineMap( 0 )
{
- if ( vcard.mLineMap ) {
- if ( !mLineMap )
- mLineMap = new QMap<QString, QValueList<VCardLine> >;
-
- *mLineMap = *(vcard.mLineMap);
- } else {
- delete mLineMap;
- mLineMap = 0;
- }
+ mLineMap = vcard.mLineMap;
}
VCard::~VCard()
{
- delete mLineMap;
- mLineMap = 0;
}
VCard& VCard::operator=( const VCard& vcard )
@@ -52,91 +40,77 @@ VCard& VCard::operator=( const VCard& vcard )
if ( &vcard == this )
return *this;
- if ( vcard.mLineMap ) {
- if ( !mLineMap )
- mLineMap = new QMap<QString, QValueList<VCardLine> >;
-
- *mLineMap = *(vcard.mLineMap);
- } else {
- delete mLineMap;
- mLineMap = 0;
- }
+ mLineMap = vcard.mLineMap;
return *this;
}
void VCard::clear()
{
- if ( mLineMap )
- mLineMap->clear();
+ mLineMap.clear();
}
QStringList VCard::identifiers() const
{
- if ( !mLineMap )
- return QStringList();
- else {
-//US method QMap::keys() not available yet. SO collect the data manually
-//US return mLineMap->keys();
-
+ //return mLineMap.keys();
+//PP re: US method QMap::keys() not available yet. SO collect the data manually
+
QStringList result;
-
- QMap< QString, VCardLine::List >::ConstIterator it;
- for( it = mLineMap->begin(); it != mLineMap->end(); ++it ) {
+
+ QMap<QString, VCardLine::List>::ConstIterator it;
+ for( it = mLineMap.begin(); it != mLineMap.end(); ++it ) {
result << it.key().latin1();
}
return result;
- }
}
void VCard::addLine( const VCardLine& line )
{
- if ( !mLineMap )
- mLineMap = new QMap<QString, QValueList<VCardLine> >;
-
- (*mLineMap)[ line.identifier() ].append( line );
+ mLineMap[ line.identifier() ].append( line );
}
-VCardLine::List VCard::lines( const QString& identifier )
+VCardLine::List VCard::lines( const QString& identifier ) const
{
- if ( !mLineMap )
+ LineMap::ConstIterator it = mLineMap.find( identifier );
+ if ( it == mLineMap.end() )
return VCardLine::List();
- else
- return (*mLineMap)[ identifier ];
+
+ return *it;
}
-VCardLine VCard::line( const QString& identifier )
+VCardLine VCard::line( const QString& identifier ) const
{
- if ( !mLineMap )
+ LineMap::ConstIterator it = mLineMap.find( identifier );
+ if ( it == mLineMap.end() )
+ return VCardLine();
+
+ if ( (*it).isEmpty() )
return VCardLine();
else
- return (*mLineMap)[ identifier ][ 0 ];
+ return (*it).first();
}
void VCard::setVersion( Version version )
{
- if ( !mLineMap )
- mLineMap = new QMap<QString, QValueList<VCardLine> >;
- else {
-//US mLineMap->erase( "VERSION" );
- mLineMap->remove( "VERSION" );
- }
+ mLineMap.remove( "VERSION" );
+
VCardLine line;
line.setIdentifier( "VERSION" );
if ( version == v2_1 )
line.setIdentifier( "2.1" );
- if ( version == v3_0 )
+ else if ( version == v3_0 )
line.setIdentifier( "3.0" );
- (*mLineMap)[ "VERSION" ].append( line );
+ mLineMap[ "VERSION" ].append( line );
}
VCard::Version VCard::version() const
{
- if ( !mLineMap )
+ LineMap::ConstIterator versionEntry = mLineMap.find( "VERSION" );
+ if ( versionEntry == mLineMap.end() )
return v3_0;
- VCardLine line = (*mLineMap)[ "VERSION" ][ 0 ];
+ VCardLine line = ( *versionEntry )[ 0 ];
if ( line.value() == "2.1" )
return v2_1;
else
diff --git a/kabc/vcardparser/vcard.h b/kabc/vcardparser/vcard.h
index ce672b5..0bee441 100644
--- a/kabc/vcardparser/vcard.h
+++ b/kabc/vcardparser/vcard.h
@@ -18,8 +18,8 @@
Boston, MA 02111-1307, USA.
*/
-#ifndef VCARD_H
-#define VCARD_H
+#ifndef VCARDPARSER_VCARD_H
+#define VCARDPARSER_VCARD_H
#include "vcardline.h"
#include <qmap.h>
@@ -32,6 +32,7 @@ class VCard
{
public:
typedef QValueList<VCard> List;
+ typedef QMap< QString, VCardLine::List > LineMap;
enum Version { v2_1, v3_0 };
@@ -61,12 +62,12 @@ class VCard
/**
* Returns all lines of the vcard with a special identifier.
*/
- VCardLine::List lines( const QString& identifier );
+ VCardLine::List lines( const QString& identifier ) const;
/**
* Returns only the first line of the vcard with a special identifier.
*/
- VCardLine line( const QString& identifier );
+ VCardLine line( const QString& identifier ) const;
/**
* Set the version of the vCard.
@@ -79,7 +80,7 @@ class VCard
Version version() const;
private:
- QMap< QString, VCardLine::List > *mLineMap;
+ LineMap mLineMap;
class VCardPrivate;
VCardPrivate *d;
diff --git a/kabc/vcardparser/vcardline.cpp b/kabc/vcardparser/vcardline.cpp
index 84638f8..0972a35 100644
--- a/kabc/vcardparser/vcardline.cpp
+++ b/kabc/vcardparser/vcardline.cpp
@@ -22,45 +22,42 @@
using namespace KABC;
+class VCardLine::VCardLinePrivate
+{
+ public:
+ QString mGroup;
+};
+
VCardLine::VCardLine()
- : mParamMap( 0 )
+ : d( 0 )
{
}
VCardLine::VCardLine( const QString &identifier )
- : mParamMap( 0 )
+ : d( 0 )
{
mIdentifier = identifier;
}
-VCardLine::VCardLine( const QString &identifier, const QVariant &value )
- : mParamMap( 0 )
+VCardLine::VCardLine( const QString &identifier, const QString &value )
+ : d( 0 )
{
mIdentifier = identifier;
- mValue = value;
+ mValue.assign( value.data(), value.length() );
}
VCardLine::VCardLine( const VCardLine& line )
- : mParamMap( 0 )
+ : d( 0 )
{
- if ( line.mParamMap ) {
- if ( !mParamMap )
- mParamMap = new QMap<QString, QStringList>;
-
- *mParamMap = *(line.mParamMap);
- } else {
- delete mParamMap;
- mParamMap = 0;
- }
-
+ mParamMap = line.mParamMap;
mValue = line.mValue;
mIdentifier = line.mIdentifier;
}
VCardLine::~VCardLine()
{
- delete mParamMap;
- mParamMap = 0;
+ delete d;
+ d = 0;
}
VCardLine& VCardLine::operator=( const VCardLine& line )
@@ -68,16 +65,7 @@ VCardLine& VCardLine::operator=( const VCardLine& line )
if ( &line == this )
return *this;
- if ( line.mParamMap ) {
- if ( !mParamMap )
- mParamMap = new QMap<QString, QStringList>;
-
- *mParamMap = *(line.mParamMap);
- } else {
- delete mParamMap;
- mParamMap = 0;
- }
-
+ mParamMap = line.mParamMap;
mValue = line.mValue;
mIdentifier = line.mIdentifier;
@@ -93,56 +81,91 @@ QString VCardLine::identifier() const
{
return mIdentifier;
}
-void VCardLine::setValue( const QVariant& value )
+
+void VCardLine::setValue( const QString& value )
+{
+ mValue.duplicate( value.data(), value.length() );
+}
+
+void VCardLine::setValue( const QByteArray& value )
{
mValue = value;
}
QVariant VCardLine::value() const
{
+ return QVariant( QCString( mValue.data(), mValue.size()+1 ) );
+}
+
+QByteArray VCardLine::valueBytes() const
+{
return mValue;
}
+void VCardLine::setGroup( const QString& group )
+{
+ if ( !d )
+ d = new VCardLinePrivate();
+
+ d->mGroup = group;
+}
+
+QString VCardLine::group() const
+{
+ if ( d )
+ return d->mGroup;
+ else
+ return QString();
+}
+
+bool VCardLine::hasGroup() const
+{
+ if ( !d )
+ return false;
+ else
+ return d->mGroup.isEmpty();
+}
+
QStringList VCardLine::parameterList() const
{
- if ( !mParamMap )
- return QStringList();
- else {
+ //return mParamMap.keys();
//US method QMap::keys() not available yet. SO collect the data manually
//US return mParamMap->keys();
-
+
QStringList result;
-
+
QMap<QString, QStringList>::ConstIterator it;
- for( it = mParamMap->begin(); it != mParamMap->end(); ++it ) {
+ for( it = mParamMap.begin(); it != mParamMap.end(); ++it ) {
result << it.key().latin1();
}
return result;
- }
}
void VCardLine::addParameter( const QString& param, const QString& value )
{
- if ( !mParamMap )
- mParamMap = new QMap<QString, QStringList>;
-
- QStringList &list = (*mParamMap)[ param ];
- if ( list.find( value ) == list.end() ) // not included yet
+ QStringList &list = mParamMap[ param ];
+ if ( list.findIndex( value ) == -1 ) // not included yet
list.append( value );
}
QStringList VCardLine::parameters( const QString& param ) const
{
- if ( !mParamMap )
+ ParamMap::ConstIterator it = mParamMap.find( param );
+ if ( it == mParamMap.end() )
return QStringList();
else
- return (*mParamMap)[ param ];
+ return *it;
}
QString VCardLine::parameter( const QString& param ) const
{
- if ( !mParamMap )
+ ParamMap::ConstIterator it = mParamMap.find( param );
+ if ( it == mParamMap.end() )
return QString::null;
- else
- return (*mParamMap)[ param ][ 0 ];
+ else {
+ if ( (*it).isEmpty() )
+ return QString::null;
+ else
+ return (*it).first();
+ }
}
diff --git a/kabc/vcardparser/vcardline.h b/kabc/vcardparser/vcardline.h
index 78b61f8..6e74b38 100644
--- a/kabc/vcardparser/vcardline.h
+++ b/kabc/vcardparser/vcardline.h
@@ -23,6 +23,7 @@
#include <qstringlist.h>
#include <qvaluelist.h>
+#include <qcstring.h>
#include <qvariant.h>
#include <qmap.h>
#include <qstring.h>
@@ -33,10 +34,11 @@ class VCardLine
{
public:
typedef QValueList<VCardLine> List;
+ typedef QMap<QString, QStringList> ParamMap;
VCardLine();
VCardLine( const QString &identifier );
- VCardLine( const QString &identifier, const QVariant &value );
+ VCardLine( const QString &identifier, const QString &value );
VCardLine( const VCardLine& );
~VCardLine();
@@ -56,12 +58,29 @@ class VCardLine
/**
* Sets the value of of this line.
*/
- void setValue( const QVariant& value );
+ void setValue( const QString& value );
+ void setValue( const QByteArray& value );
/**
* Returns the value of this line.
*/
QVariant value() const;
+ QByteArray valueBytes() const;
+
+ /**
+ * Sets the group the line belongs to.
+ */
+ void setGroup( const QString& group );
+
+ /**
+ * Returns the group the line belongs to.
+ */
+ QString group() const;
+
+ /**
+ * Returns whether the line belongs to a group.
+ */
+ bool hasGroup() const;
/**
* Returns all parameters.
@@ -75,20 +94,20 @@ class VCardLine
/**
* Returns the values of a special parameter.
- * You can get a list of all parameters with @ref paramList().
+ * You can get a list of all parameters with paramList().
*/
QStringList parameters( const QString& param ) const;
/**
* Returns only the first value of a special parameter.
- * You can get a list of all parameters with @ref paramList().
+ * You can get a list of all parameters with paramList().
*/
QString parameter( const QString& param ) const;
private:
- QMap< QString, QStringList > *mParamMap;
+ ParamMap mParamMap;
QString mIdentifier;
- QVariant mValue;
+ QByteArray mValue;
class VCardLinePrivate;
VCardLinePrivate *d;
diff --git a/kabc/vcardparser/vcardparser.cpp b/kabc/vcardparser/vcardparser.cpp
index bec2a0c..7fae011 100644
--- a/kabc/vcardparser/vcardparser.cpp
+++ b/kabc/vcardparser/vcardparser.cpp
@@ -38,21 +38,24 @@ VCardParser::~VCardParser()
VCard::List VCardParser::parseVCards( const QString& text )
{
+ static QRegExp sep( "[\x0d\x0a]" );
+
VCard currentVCard;
VCard::List vCardList;
QString currentLine;
- QStringList lines = QStringList::split( QRegExp( "[\x0d\x0a]" ), text );
- QStringList::Iterator it;
+ const QStringList lines = QStringList::split( sep, text );
+ QStringList::ConstIterator it;
bool inVCard = false;
- for ( it = lines.begin(); it != lines.end(); ++it ) {
+ QStringList::ConstIterator linesEnd( lines.end() );
+ for ( it = lines.begin(); it != linesEnd; ++it ) {
if ( (*it).isEmpty() ) // empty line
continue;
if ( (*it)[ 0 ] == ' ' || (*it)[ 0 ] == '\t' ) { // folded line => append to previous
- currentLine += (*it).remove( 0, 1 );
+ currentLine += QString( *it ).remove( 0, 1 );
continue;
} else {
if ( inVCard && !currentLine.isEmpty() ) { // now parse the line
@@ -63,66 +66,79 @@ VCard::List VCardParser::parseVCards( const QString& text )
}
VCardLine vCardLine;
- QString key = currentLine.left( colon ).stripWhiteSpace();
+ const QString key = currentLine.left( colon ).stripWhiteSpace();
QString value = currentLine.mid( colon + 1 );
QStringList params = QStringList::split( ';', key );
- vCardLine.setIdentifier( params[0] );
+
+ // check for group
+ if ( params[0].find( '.' ) != -1 ) {
+ const QStringList groupList = QStringList::split( '.', params[0] );
+ vCardLine.setGroup( groupList[0] );
+ vCardLine.setIdentifier( groupList[1] );
+ } else
+ vCardLine.setIdentifier( params[0] );
+
if ( params.count() > 1 ) { // find all parameters
- for ( uint i = 1; i < params.count(); ++i ) {
- QStringList pair = QStringList::split( '=', params[i] );
-//US if ( pair.size() == 1 ) {
+ QStringList::ConstIterator paramIt = params.begin();
+ for ( ++paramIt; paramIt != params.end(); ++paramIt ) {
+ QStringList pair = QStringList::split( '=', *paramIt );
if ( pair.count() == 1 ) {
+ // correct the fucking 2.1 'standard'
+ if ( pair[0].lower() == "quoted-printable" ) {
+ pair[0] = "encoding";
+ pair[1] = "quoted-printable";
+ } else if ( pair[0].lower() == "base64" ) {
+ pair[0] = "encoding";
+ pair[1] = "base64";
+ } else {
pair.prepend( "type" );
+ }
}
- if ( pair[1].contains( ',' ) ) { // parameter in type=x,y,z format
- QStringList args = QStringList::split( ',', pair[ 1 ] );
- for ( uint j = 0; j < args.count(); ++j )
- vCardLine.addParameter( pair[0].lower(), args[j] );
+ // This is pretty much a faster pair[1].contains( ',' )...
+ if ( pair[1].find( ',' ) != -1 ) { // parameter in type=x,y,z format
+ const QStringList args = QStringList::split( ',', pair[ 1 ] );
+ QStringList::ConstIterator argIt;
+ for ( argIt = args.begin(); argIt != args.end(); ++argIt )
+ vCardLine.addParameter( pair[0].lower(), *argIt );
} else
vCardLine.addParameter( pair[0].lower(), pair[1] );
}
}
params = vCardLine.parameterList();
- if ( params.contains( "encoding" ) ) { // have to decode the data
-#if 0
+ if ( params.findIndex( "encoding" ) != -1 ) { // have to decode the data
QByteArray input, output;
- input = value.local8Bit();
- if ( vCardLine.parameter( "encoding" ).lower() == "b" )
+ if ( vCardLine.parameter( "encoding" ).lower() == "b" ||
+ vCardLine.parameter( "encoding" ).lower() == "base64" ) {
+ input = value.local8Bit();
KCodecs::base64Decode( input, output );
- else if ( vCardLine.parameter( "encoding" ).lower() == "quoted-printable" )
+ } else if ( vCardLine.parameter( "encoding" ).lower() == "quoted-printable" ) {
+ // join any qp-folded lines
+ while ( value.mid(value.length()-1,1) == "=" && it != linesEnd ) {
+ value = value.remove( value.length()-1, 1 ) + (*it);
+ ++it;
+ }
+ input = value.local8Bit();
KCodecs::quotedPrintableDecode( input, output );
-
- //qDebug("VCardParser::parseVCards has to be verified");
- //US I am not sure if this is correct
- //US vCardLine.setValue( output );
- QCString cs(output);
- qDebug("len1 %d len2 %d ",input.size(), output.size( ));
-#endif
- QCString cs = value.local8Bit();
- qDebug("****************************************** ");
- qDebug("************* WARNING ******************** ");
- qDebug("****************************************** ");
- qDebug("Make sure, the decoding is done after");
- qDebug("QVariant conversion!");
- qDebug("Insert Line DECODING OKAY, where this is implemented");
- // use for decoding the above code!
- vCardLine.setValue( cs );
- } else {
-
- //qDebug("VCardParser::parseVCards has to be verified");
-//US vCardLine.setValue( value.replace( "\\n", "\n" ) );
+ }
+//PP our vcards are *supposed* to be in UTF-8
+// if ( vCardLine.parameter( "charset" ).lower() == "utf-8" ) {
+// vCardLine.setValue( QString::fromUtf8( output.data(), output.size() ) );
+// } else
+ vCardLine.setValue( 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" ) );
- }
currentVCard.addLine( vCardLine );
}
+
// we do not save the start and end tag as vcardline
if ( (*it).lower().startsWith( "begin:vcard" ) ) {
inVCard = true;
- //qDebug("VCardParser::parseVCards has to be verified");
-//US currentLine.setLength( 0 );
currentLine = "";
currentVCard.clear(); // flush vcard
continue;
@@ -131,8 +147,6 @@ VCard::List VCardParser::parseVCards( const QString& text )
if ( (*it).lower().startsWith( "end:vcard" ) ) {
inVCard = false;
vCardList.append( currentVCard );
- //qDebug("VCardParser::parseVCards has to be verified");
-//US currentLine.setLength( 0 );
currentLine = "";
currentVCard.clear(); // flush vcard
continue;
@@ -155,28 +169,30 @@ QString VCardParser::createVCards( const VCard::List& list )
QStringList values;
QStringList::ConstIterator identIt;
QStringList::Iterator paramIt;
- QStringList::Iterator valueIt;
+ QStringList::ConstIterator valueIt;
VCardLine::List lines;
- VCardLine::List::Iterator lineIt;
+ VCardLine::List::ConstIterator lineIt;
VCard::List::ConstIterator cardIt;
bool hasEncoding;
-
// iterate over the cards
- for ( cardIt = list.begin(); cardIt != list.end(); ++cardIt ) {
+ VCard::List::ConstIterator listEnd( list.end() );
+ for ( cardIt = list.begin(); cardIt != listEnd; ++cardIt ) {
text.append( "BEGIN:VCARD\r\n" );
idents = (*cardIt).identifiers();
for ( identIt = idents.begin(); identIt != idents.end(); ++identIt ) {
- VCard card = (*cardIt);
- lines = card.lines( (*identIt) );
+ lines = (*cardIt).lines( (*identIt) );
// iterate over the lines
for ( lineIt = lines.begin(); lineIt != lines.end(); ++lineIt ) {
if ( !(*lineIt).value().asString().isEmpty() ) {
- textLine = (*lineIt).identifier();
+ if ( (*lineIt).hasGroup() )
+ textLine = (*lineIt).group() + "." + (*lineIt).identifier();
+ else
+ textLine = (*lineIt).identifier();
params = (*lineIt).parameterList();
hasEncoding = false;
@@ -198,24 +214,15 @@ QString VCardParser::createVCards( const VCard::List& list )
if ( hasEncoding ) { // have to encode the data
QByteArray input, output;
-
- qDebug("VCardParser::createVCards has to be verified");
-//US input = (*lineIt).value().toByteArray();
-
-//US I am not sure if this is correct
- QCString cs ((*lineIt).value().toCString());
- input = cs;
-
+ input = (*lineIt).valueBytes();
if ( encodingType == "b" )
KCodecs::base64Encode( input, output );
else if ( encodingType == "quoted-printable" )
KCodecs::quotedPrintableEncode( input, output );
textLine.append( ":" + QString( output ) );
- } else {
- qDebug("VCardParser::createVCards has to be verified");
-//US textLine.append( ":" + (*lineIt).value().asString().replace( "\n", "\\n" ) );
+ } else
textLine.append( ":" + (*lineIt).value().asString().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 )
text.append( ( i == 0 ? "" : " " ) + textLine.mid( i * FOLD_WIDTH, FOLD_WIDTH ) + "\r\n" );
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
@@ -20,8 +20,6 @@
#include <qdatastream.h>
#include <qstring.h>
-#include <qregexp.h>
-#include <kmdcodec.h>
#include "agent.h"
#include "key.h"
@@ -57,71 +55,69 @@ VCardTool::VCardTool()
mPhoneTypeMap.insert( "ISDN", PhoneNumber::Isdn );
mPhoneTypeMap.insert( "PCS", PhoneNumber::Pcs );
mPhoneTypeMap.insert( "PAGER", PhoneNumber::Pager );
- mPhoneTypeMap.insert( "SIP", PhoneNumber::Sip );
}
VCardTool::~VCardTool()
{
}
+// TODO: make list a const&
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;
QStringList::ConstIterator strIt;
// 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() );
}
}
- card.addLine( adrLine );
+ if ( !isEmpty )
+ card.addLine( adrLine );
if ( hasLabel )
card.addLine( labelLine );
}
@@ -137,26 +133,32 @@ QString VCardTool::createVCards( Addressee::List list, VCard::Version version )
QStringList categories = (*addrIt).categories();
QStringList::Iterator catIt;
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 );
}
// CLASS
if ( version == VCard::v3_0 ) {
card.addLine( createSecrecy( (*addrIt).secrecy() ) );
}
-
+
// EMAIL
- QStringList emails = (*addrIt).emails();
+ const QStringList emails = (*addrIt).emails();
bool pref = true;
for ( strIt = emails.begin(); strIt != emails.end(); ++strIt ) {
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" );
pref = false;
}
@@ -164,7 +166,12 @@ 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 );
// GEO
Geo geo = (*addrIt).geo();
@@ -175,7 +182,7 @@ 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;
for ( keyIt = keys.begin(); keyIt != keys.end(); ++keyIt )
card.addLine( createKey( *keyIt ) );
@@ -184,37 +191,55 @@ QString VCardTool::createVCards( Addressee::List list, VCard::Version version )
card.addLine( createPicture( "LOGO", (*addrIt).logo() ) );
// 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 );
// N
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 );
// NICKNAME
if ( version == VCard::v3_0 )
card.addLine( VCardLine( "NICKNAME", (*addrIt).nickName() ) );
// 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 );
// PHOTO
card.addLine( createPicture( "PHOTO", (*addrIt).photo() ) );
@@ -227,7 +252,12 @@ QString VCardTool::createVCards( Addressee::List list, VCard::Version version )
card.addLine( VCardLine( "REV", createDateTime( (*addrIt).revision() ) ) );
// 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 );
// SORT-STRING
if ( version == VCard::v3_0 )
@@ -237,25 +267,27 @@ QString VCardTool::createVCards( Addressee::List list, VCard::Version version )
card.addLine( createSound( (*addrIt).sound() ) );
// TEL
- PhoneNumber::List phoneNumbers = (*addrIt).phoneNumbers();
+ const PhoneNumber::List phoneNumbers = (*addrIt).phoneNumbers();
PhoneNumber::List::ConstIterator phoneIt;
for ( phoneIt = phoneNumbers.begin(); phoneIt != phoneNumbers.end(); ++phoneIt ) {
VCardLine line( "TEL", (*phoneIt).number() );
- 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() );
}
card.addLine( line );
}
// 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 );
// TZ
TimeZone timeZone = (*addrIt).timeZone();
@@ -286,14 +318,19 @@ QString VCardTool::createVCards( Addressee::List list, VCard::Version version )
card.addLine( VCardLine( "VERSION", "3.0" ) );
// X-
- QStringList customs = (*addrIt).customs();
+ const QStringList customs = (*addrIt).customs();
for ( strIt = customs.begin(); strIt != customs.end(); ++strIt ) {
QString identifier = "X-" + (*strIt).left( (*strIt).find( ":" ) );
QString value = (*strIt).mid( (*strIt).find( ":" ) + 1 );
if ( value.isEmpty() )
continue;
- 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 );
}
vCardList.append( card );
@@ -304,37 +341,38 @@ QString VCardTool::createVCards( Addressee::List list, VCard::Version version )
Addressee::List VCardTool::parseVCards( const QString& vcard )
{
- QChar semicolonSep( ';' );
- QChar commaSep( ',' );
+ static const QChar semicolonSep( ';' );
+ static const QChar commaSep( ',' );
QString identifier;
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;
// iterate over the lines
for ( lineIt = lines.begin(); lineIt != lines.end(); ++lineIt ) {
- QStringList params = (*lineIt).parameterList();
-
identifier = (*lineIt).identifier().lower();
// ADR
if ( identifier == "adr" ) {
Address address;
- QStringList addrParts = splitString( semicolonSep, (*lineIt).value().asString() );
+ const QStringList addrParts = splitString( semicolonSep, (*lineIt).value().asString() );
if ( addrParts.count() > 0 )
address.setPostOfficeBox( addrParts[ 0 ] );
if ( addrParts.count() > 1 )
address.setExtended( addrParts[ 1 ] );
if ( addrParts.count() > 2 )
- address.setStreet( addrParts[ 2 ].replace ( QRegExp("\\\\n") , "\n") );
+ address.setStreet( addrParts[ 2 ] );
if ( addrParts.count() > 3 )
address.setLocality( addrParts[ 3 ] );
if ( addrParts.count() > 4 )
@@ -346,50 +384,47 @@ Addressee::List VCardTool::parseVCards( const QString& vcard )
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; // default
-
address.setType( type );
addr.insertAddress( address );
}
// AGENT
- if ( identifier == "agent" )
+ else if ( identifier == "agent" )
addr.setAgent( parseAgent( *lineIt ) );
// BDAY
- if ( identifier == "bday" )
+ else if ( identifier == "bday" )
addr.setBirthday( parseDateTime( (*lineIt).value().asString() ) );
// 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 );
}
// CLASS
- if ( identifier == "class" )
+ else if ( identifier == "class" )
addr.setSecrecy( parseSecrecy( *lineIt ) );
// 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 );
}
// FN
- if ( identifier == "fn" )
+ else if ( identifier == "fn" )
addr.setFormattedName( (*lineIt).value().asString() );
// 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() );
geo.setLongitude( geoParts[ 1 ].toFloat() );
@@ -397,41 +432,47 @@ Addressee::List VCardTool::parseVCards( const QString& vcard )
}
// KEY
- if ( identifier == "key" )
+ else if ( identifier == "key" )
addr.insertKey( parseKey( *lineIt ) );
// 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();
KABC::Address::List::Iterator it;
for ( it = addressList.begin(); it != addressList.end(); ++it ) {
if ( (*it).type() == type ) {
(*it).setLabel( (*lineIt).value().asString() );
addr.insertAddress( *it );
+ available = true;
+ break;
}
}
+
+ if ( !available ) { // a standalone LABEL tag
+ KABC::Address address( type );
+ address.setLabel( (*lineIt).value().asString() );
+ addr.insertAddress( address );
+ }
}
// LOGO
- if ( identifier == "logo" )
+ else if ( identifier == "logo" )
addr.setLogo( parsePicture( *lineIt ) );
// MAILER
- if ( identifier == "mailer" )
+ else if ( identifier == "mailer" )
addr.setMailer( (*lineIt).value().asString() );
// 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 )
addr.setFamilyName( nameParts[ 0 ] );
if ( nameParts.count() > 1 )
@@ -444,78 +485,70 @@ Addressee::List VCardTool::parseVCards( const QString& vcard )
addr.setSuffix( nameParts[ 4 ] );
}
+ // NAME
+ else if ( identifier == "name" )
+ addr.setName( (*lineIt).value().asString() );
+
// NICKNAME
- if ( identifier == "nickname" )
+ else if ( identifier == "nickname" )
addr.setNickName( (*lineIt).value().asString() );
// 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() );
// PHOTO
- if ( identifier == "photo" )
+ else if ( identifier == "photo" )
addr.setPhoto( parsePicture( *lineIt ) );
// PROID
- if ( identifier == "prodid" )
+ else if ( identifier == "prodid" )
addr.setProductId( (*lineIt).value().asString() );
// REV
- if ( identifier == "rev" )
+ else if ( identifier == "rev" )
addr.setRevision( parseDateTime( (*lineIt).value().asString() ) );
// ROLE
- if ( identifier == "role" )
+ else if ( identifier == "role" )
addr.setRole( (*lineIt).value().asString() );
// SORT-STRING
- if ( identifier == "sort-string" )
+ else if ( identifier == "sort-string" )
addr.setSortString( (*lineIt).value().asString() );
// SOUND
- if ( identifier == "sound" )
+ else if ( identifier == "sound" )
addr.setSound( parseSound( *lineIt ) );
// TEL
- if ( identifier == "tel" ) {
+ else if ( identifier == "tel" ) {
PhoneNumber phone;
phone.setNumber( (*lineIt).value().asString() );
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 += mPhoneTypeMap[(*it).upper()];
- if ( !type )
- type = PhoneNumber::Home; // default
-
phone.setType( type );
addr.insertPhoneNumber( phone );
}
// TITLE
- if ( identifier == "title" )
+ else if ( identifier == "title" )
addr.setTitle( (*lineIt).value().asString() );
// TZ
- if ( identifier == "tz" ) {
+ else if ( identifier == "tz" ) {
TimeZone tz;
- QString date = (*lineIt).value().asString();
+ const QString date = (*lineIt).value().asString();
int hours = date.mid( 1, 2).toInt();
int minutes = date.mid( 4, 2 ).toInt();
@@ -527,16 +560,16 @@ Addressee::List VCardTool::parseVCards( const QString& vcard )
}
// UID
- if ( identifier == "uid" )
+ else if ( identifier == "uid" )
addr.setUid( (*lineIt).value().asString() );
// 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( "-" );
addr.insertCustom( key.left( dash ), key.mid( dash + 1 ), (*lineIt).value().asString() );
}
@@ -593,64 +626,44 @@ QString VCardTool::createDateTime( const QDateTime &dateTime )
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;
}
VCardLine VCardTool::createPicture( const QString &identifier, const Picture &pic )
{
- // LR fixed
VCardLine line( identifier );
if ( pic.isIntern() ) {
if ( !pic.data().isNull() ) {
-#if 0
QByteArray input;
QDataStream s( input, IO_WriteOnly );
s.setVersion( 4 );
s << pic.data();
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" );
line.addParameter( "type", "image/png" );
}
} else if ( !pic.url().isEmpty() ) {
+ QByteArray ba;
line.setValue( pic.url() );
line.addParameter( "value", "URI" );
}
-
+
return line;
}
@@ -658,15 +671,10 @@ Sound VCardTool::parseSound( const VCardLine &line )
{
Sound snd;
- 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" )
snd.setUrl( line.value().asString() );
}
@@ -685,14 +693,7 @@ VCardLine VCardTool::createSound( const Sound &snd )
if ( snd.isIntern() ) {
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" );
// TODO: need to store sound type!!!
}
@@ -708,19 +709,13 @@ Key VCardTool::parseKey( const VCardLine &line )
{
Key key;
- 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
key.setTextData( line.value().asString() );
- if ( params.contains( "type" ) ) {
+ if ( params.findIndex( "type" ) != -1 ) {
if ( line.parameter( "type" ).lower() == "x509" )
key.setType( Key::X509 );
else if ( line.parameter( "type" ).lower() == "pgp" )
@@ -740,13 +735,7 @@ VCardLine VCardTool::createKey( const Key &key )
if ( key.isBinary() ) {
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" );
}
} else if ( !key.textData().isEmpty() )
@@ -796,29 +785,19 @@ Agent VCardTool::parseAgent( const VCardLine &line )
{
Agent agent;
- QStringList params = line.parameterList();
- if ( params.contains( "value" ) ) {
+ const QStringList params = line.parameterList();
+ if ( params.findIndex( "value" ) != -1 ) {
if ( line.parameter( "value" ).lower() == "uri" )
agent.setUrl( line.value().asString() );
} else {
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 ) {
Addressee *addr = new Addressee;
*addr = list[ 0 ];
@@ -839,16 +818,7 @@ VCardLine VCardTool::createAgent( VCard::Version version, const Agent &agent )
list.append( *agent.addressee() );
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(";"), "\\;" );
str.replace( QRegExp(":"), "\\:" );
str.replace( QRegExp(","), "\\," );
@@ -883,7 +853,7 @@ QStringList VCardTool::splitString( const QChar &sep, const QString &str )
if ( pos != 0 ) {
value.replace( pos - 1, 2, sep );
pos = value.find( sep, pos );
- } else
+ } else
pos = value.find( sep, pos + 1 );
}
}