summaryrefslogtreecommitdiffabout
path: root/kabc
authorzautrix <zautrix>2005-03-10 22:11:30 (UTC)
committer zautrix <zautrix>2005-03-10 22:11:30 (UTC)
commitb6845008e161e1bb355a32767c3e3f89ff8e5c01 (patch) (unidiff)
treeb1618c2a81ee8fa26d00332352fde82f2e3e51c9 /kabc
parent6e3c3178fa8e0c421753c08506b4a91bbcecc26f (diff)
downloadkdepimpi-b6845008e161e1bb355a32767c3e3f89ff8e5c01.zip
kdepimpi-b6845008e161e1bb355a32767c3e3f89ff8e5c01.tar.gz
kdepimpi-b6845008e161e1bb355a32767c3e3f89ff8e5c01.tar.bz2
quoted printable for kapi
Diffstat (limited to 'kabc') (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 @@
23using namespace KABC; 23using namespace KABC;
24 24
25VCard::VCard() 25VCard::VCard()
26 : mLineMap( 0 )
27{ 26{
28} 27}
29 28
30VCard::VCard( const VCard& vcard ) 29VCard::VCard( const VCard& vcard )
31 : mLineMap( 0 )
32{ 30{
33 if ( vcard.mLineMap ) { 31 mLineMap = vcard.mLineMap;
34 if ( !mLineMap )
35 mLineMap = new QMap<QString, QValueList<VCardLine> >;
36
37 *mLineMap = *(vcard.mLineMap);
38 } else {
39 delete mLineMap;
40 mLineMap = 0;
41 }
42} 32}
43 33
44VCard::~VCard() 34VCard::~VCard()
45{ 35{
46 delete mLineMap;
47 mLineMap = 0;
48} 36}
49 37
50VCard& VCard::operator=( const VCard& vcard ) 38VCard& VCard::operator=( const VCard& vcard )
@@ -52,91 +40,77 @@ VCard& VCard::operator=( const VCard& vcard )
52 if ( &vcard == this ) 40 if ( &vcard == this )
53 return *this; 41 return *this;
54 42
55 if ( vcard.mLineMap ) { 43 mLineMap = vcard.mLineMap;
56 if ( !mLineMap )
57 mLineMap = new QMap<QString, QValueList<VCardLine> >;
58
59 *mLineMap = *(vcard.mLineMap);
60 } else {
61 delete mLineMap;
62 mLineMap = 0;
63 }
64 44
65 return *this; 45 return *this;
66} 46}
67 47
68void VCard::clear() 48void VCard::clear()
69{ 49{
70 if ( mLineMap ) 50 mLineMap.clear();
71 mLineMap->clear();
72} 51}
73 52
74QStringList VCard::identifiers() const 53QStringList VCard::identifiers() const
75{ 54{
76 if ( !mLineMap ) 55 //return mLineMap.keys();
77 return QStringList(); 56//PP re: US method QMap::keys() not available yet. SO collect the data manually
78 else { 57
79//US method QMap::keys() not available yet. SO collect the data manually
80//US return mLineMap->keys();
81
82 QStringList result; 58 QStringList result;
83 59
84 QMap< QString, VCardLine::List >::ConstIterator it; 60 QMap<QString, VCardLine::List>::ConstIterator it;
85 for( it = mLineMap->begin(); it != mLineMap->end(); ++it ) { 61 for( it = mLineMap.begin(); it != mLineMap.end(); ++it ) {
86 result << it.key().latin1(); 62 result << it.key().latin1();
87 } 63 }
88 return result; 64 return result;
89 }
90} 65}
91 66
92void VCard::addLine( const VCardLine& line ) 67void VCard::addLine( const VCardLine& line )
93{ 68{
94 if ( !mLineMap ) 69 mLineMap[ line.identifier() ].append( line );
95 mLineMap = new QMap<QString, QValueList<VCardLine> >;
96
97 (*mLineMap)[ line.identifier() ].append( line );
98} 70}
99 71
100VCardLine::List VCard::lines( const QString& identifier ) 72VCardLine::List VCard::lines( const QString& identifier ) const
101{ 73{
102 if ( !mLineMap ) 74 LineMap::ConstIterator it = mLineMap.find( identifier );
75 if ( it == mLineMap.end() )
103 return VCardLine::List(); 76 return VCardLine::List();
104 else 77
105 return (*mLineMap)[ identifier ]; 78 return *it;
106} 79}
107 80
108VCardLine VCard::line( const QString& identifier ) 81VCardLine VCard::line( const QString& identifier ) const
109{ 82{
110 if ( !mLineMap ) 83 LineMap::ConstIterator it = mLineMap.find( identifier );
84 if ( it == mLineMap.end() )
85 return VCardLine();
86
87 if ( (*it).isEmpty() )
111 return VCardLine(); 88 return VCardLine();
112 else 89 else
113 return (*mLineMap)[ identifier ][ 0 ]; 90 return (*it).first();
114} 91}
115 92
116void VCard::setVersion( Version version ) 93void VCard::setVersion( Version version )
117{ 94{
118 if ( !mLineMap ) 95 mLineMap.remove( "VERSION" );
119 mLineMap = new QMap<QString, QValueList<VCardLine> >; 96
120 else {
121//US mLineMap->erase( "VERSION" );
122 mLineMap->remove( "VERSION" );
123 }
124 VCardLine line; 97 VCardLine line;
125 line.setIdentifier( "VERSION" ); 98 line.setIdentifier( "VERSION" );
126 if ( version == v2_1 ) 99 if ( version == v2_1 )
127 line.setIdentifier( "2.1" ); 100 line.setIdentifier( "2.1" );
128 if ( version == v3_0 ) 101 else if ( version == v3_0 )
129 line.setIdentifier( "3.0" ); 102 line.setIdentifier( "3.0" );
130 103
131 (*mLineMap)[ "VERSION" ].append( line ); 104 mLineMap[ "VERSION" ].append( line );
132} 105}
133 106
134VCard::Version VCard::version() const 107VCard::Version VCard::version() const
135{ 108{
136 if ( !mLineMap ) 109 LineMap::ConstIterator versionEntry = mLineMap.find( "VERSION" );
110 if ( versionEntry == mLineMap.end() )
137 return v3_0; 111 return v3_0;
138 112
139 VCardLine line = (*mLineMap)[ "VERSION" ][ 0 ]; 113 VCardLine line = ( *versionEntry )[ 0 ];
140 if ( line.value() == "2.1" ) 114 if ( line.value() == "2.1" )
141 return v2_1; 115 return v2_1;
142 else 116 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 @@
18 Boston, MA 02111-1307, USA. 18 Boston, MA 02111-1307, USA.
19*/ 19*/
20 20
21#ifndef VCARD_H 21#ifndef VCARDPARSER_VCARD_H
22#define VCARD_H 22#define VCARDPARSER_VCARD_H
23 23
24#include "vcardline.h" 24#include "vcardline.h"
25#include <qmap.h> 25#include <qmap.h>
@@ -32,6 +32,7 @@ class VCard
32{ 32{
33 public: 33 public:
34 typedef QValueList<VCard> List; 34 typedef QValueList<VCard> List;
35 typedef QMap< QString, VCardLine::List > LineMap;
35 36
36 enum Version { v2_1, v3_0 }; 37 enum Version { v2_1, v3_0 };
37 38
@@ -61,12 +62,12 @@ class VCard
61 /** 62 /**
62 * Returns all lines of the vcard with a special identifier. 63 * Returns all lines of the vcard with a special identifier.
63 */ 64 */
64 VCardLine::List lines( const QString& identifier ); 65 VCardLine::List lines( const QString& identifier ) const;
65 66
66 /** 67 /**
67 * Returns only the first line of the vcard with a special identifier. 68 * Returns only the first line of the vcard with a special identifier.
68 */ 69 */
69 VCardLine line( const QString& identifier ); 70 VCardLine line( const QString& identifier ) const;
70 71
71 /** 72 /**
72 * Set the version of the vCard. 73 * Set the version of the vCard.
@@ -79,7 +80,7 @@ class VCard
79 Version version() const; 80 Version version() const;
80 81
81 private: 82 private:
82 QMap< QString, VCardLine::List > *mLineMap; 83 LineMap mLineMap;
83 84
84 class VCardPrivate; 85 class VCardPrivate;
85 VCardPrivate *d; 86 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 @@
22 22
23using namespace KABC; 23using namespace KABC;
24 24
25class VCardLine::VCardLinePrivate
26{
27 public:
28 QString mGroup;
29};
30
25VCardLine::VCardLine() 31VCardLine::VCardLine()
26 : mParamMap( 0 ) 32 : d( 0 )
27{ 33{
28} 34}
29 35
30VCardLine::VCardLine( const QString &identifier ) 36VCardLine::VCardLine( const QString &identifier )
31 : mParamMap( 0 ) 37 : d( 0 )
32{ 38{
33 mIdentifier = identifier; 39 mIdentifier = identifier;
34} 40}
35 41
36VCardLine::VCardLine( const QString &identifier, const QVariant &value ) 42VCardLine::VCardLine( const QString &identifier, const QString &value )
37 : mParamMap( 0 ) 43 : d( 0 )
38{ 44{
39 mIdentifier = identifier; 45 mIdentifier = identifier;
40 mValue = value; 46 mValue.assign( value.data(), value.length() );
41} 47}
42 48
43VCardLine::VCardLine( const VCardLine& line ) 49VCardLine::VCardLine( const VCardLine& line )
44 : mParamMap( 0 ) 50 : d( 0 )
45{ 51{
46 if ( line.mParamMap ) { 52 mParamMap = line.mParamMap;
47 if ( !mParamMap )
48 mParamMap = new QMap<QString, QStringList>;
49
50 *mParamMap = *(line.mParamMap);
51 } else {
52 delete mParamMap;
53 mParamMap = 0;
54 }
55
56 mValue = line.mValue; 53 mValue = line.mValue;
57 mIdentifier = line.mIdentifier; 54 mIdentifier = line.mIdentifier;
58} 55}
59 56
60VCardLine::~VCardLine() 57VCardLine::~VCardLine()
61{ 58{
62 delete mParamMap; 59 delete d;
63 mParamMap = 0; 60 d = 0;
64} 61}
65 62
66VCardLine& VCardLine::operator=( const VCardLine& line ) 63VCardLine& VCardLine::operator=( const VCardLine& line )
@@ -68,16 +65,7 @@ VCardLine& VCardLine::operator=( const VCardLine& line )
68 if ( &line == this ) 65 if ( &line == this )
69 return *this; 66 return *this;
70 67
71 if ( line.mParamMap ) { 68 mParamMap = line.mParamMap;
72 if ( !mParamMap )
73 mParamMap = new QMap<QString, QStringList>;
74
75 *mParamMap = *(line.mParamMap);
76 } else {
77 delete mParamMap;
78 mParamMap = 0;
79 }
80
81 mValue = line.mValue; 69 mValue = line.mValue;
82 mIdentifier = line.mIdentifier; 70 mIdentifier = line.mIdentifier;
83 71
@@ -93,56 +81,91 @@ QString VCardLine::identifier() const
93{ 81{
94 return mIdentifier; 82 return mIdentifier;
95} 83}
96void VCardLine::setValue( const QVariant& value ) 84
85void VCardLine::setValue( const QString& value )
86{
87 mValue.duplicate( value.data(), value.length() );
88}
89
90void VCardLine::setValue( const QByteArray& value )
97{ 91{
98 mValue = value; 92 mValue = value;
99} 93}
100 94
101QVariant VCardLine::value() const 95QVariant VCardLine::value() const
102{ 96{
97 return QVariant( QCString( mValue.data(), mValue.size()+1 ) );
98}
99
100QByteArray VCardLine::valueBytes() const
101{
103 return mValue; 102 return mValue;
104} 103}
105 104
105void VCardLine::setGroup( const QString& group )
106{
107 if ( !d )
108 d = new VCardLinePrivate();
109
110 d->mGroup = group;
111}
112
113QString VCardLine::group() const
114{
115 if ( d )
116 return d->mGroup;
117 else
118 return QString();
119}
120
121bool VCardLine::hasGroup() const
122{
123 if ( !d )
124 return false;
125 else
126 return d->mGroup.isEmpty();
127}
128
106QStringList VCardLine::parameterList() const 129QStringList VCardLine::parameterList() const
107{ 130{
108 if ( !mParamMap ) 131 //return mParamMap.keys();
109 return QStringList();
110 else {
111//US method QMap::keys() not available yet. SO collect the data manually 132//US method QMap::keys() not available yet. SO collect the data manually
112//US return mParamMap->keys(); 133//US return mParamMap->keys();
113 134
114 QStringList result; 135 QStringList result;
115 136
116 QMap<QString, QStringList>::ConstIterator it; 137 QMap<QString, QStringList>::ConstIterator it;
117 for( it = mParamMap->begin(); it != mParamMap->end(); ++it ) { 138 for( it = mParamMap.begin(); it != mParamMap.end(); ++it ) {
118 result << it.key().latin1(); 139 result << it.key().latin1();
119 } 140 }
120 return result; 141 return result;
121 }
122} 142}
123 143
124void VCardLine::addParameter( const QString& param, const QString& value ) 144void VCardLine::addParameter( const QString& param, const QString& value )
125{ 145{
126 if ( !mParamMap ) 146 QStringList &list = mParamMap[ param ];
127 mParamMap = new QMap<QString, QStringList>; 147 if ( list.findIndex( value ) == -1 ) // not included yet
128
129 QStringList &list = (*mParamMap)[ param ];
130 if ( list.find( value ) == list.end() ) // not included yet
131 list.append( value ); 148 list.append( value );
132} 149}
133 150
134QStringList VCardLine::parameters( const QString& param ) const 151QStringList VCardLine::parameters( const QString& param ) const
135{ 152{
136 if ( !mParamMap ) 153 ParamMap::ConstIterator it = mParamMap.find( param );
154 if ( it == mParamMap.end() )
137 return QStringList(); 155 return QStringList();
138 else 156 else
139 return (*mParamMap)[ param ]; 157 return *it;
140} 158}
141 159
142QString VCardLine::parameter( const QString& param ) const 160QString VCardLine::parameter( const QString& param ) const
143{ 161{
144 if ( !mParamMap ) 162 ParamMap::ConstIterator it = mParamMap.find( param );
163 if ( it == mParamMap.end() )
145 return QString::null; 164 return QString::null;
146 else 165 else {
147 return (*mParamMap)[ param ][ 0 ]; 166 if ( (*it).isEmpty() )
167 return QString::null;
168 else
169 return (*it).first();
170 }
148} 171}
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 @@
23 23
24#include <qstringlist.h> 24#include <qstringlist.h>
25#include <qvaluelist.h> 25#include <qvaluelist.h>
26#include <qcstring.h>
26#include <qvariant.h> 27#include <qvariant.h>
27#include <qmap.h> 28#include <qmap.h>
28#include <qstring.h> 29#include <qstring.h>
@@ -33,10 +34,11 @@ class VCardLine
33{ 34{
34 public: 35 public:
35 typedef QValueList<VCardLine> List; 36 typedef QValueList<VCardLine> List;
37 typedef QMap<QString, QStringList> ParamMap;
36 38
37 VCardLine(); 39 VCardLine();
38 VCardLine( const QString &identifier ); 40 VCardLine( const QString &identifier );
39 VCardLine( const QString &identifier, const QVariant &value ); 41 VCardLine( const QString &identifier, const QString &value );
40 VCardLine( const VCardLine& ); 42 VCardLine( const VCardLine& );
41 43
42 ~VCardLine(); 44 ~VCardLine();
@@ -56,12 +58,29 @@ class VCardLine
56 /** 58 /**
57 * Sets the value of of this line. 59 * Sets the value of of this line.
58 */ 60 */
59 void setValue( const QVariant& value ); 61 void setValue( const QString& value );
62 void setValue( const QByteArray& value );
60 63
61 /** 64 /**
62 * Returns the value of this line. 65 * Returns the value of this line.
63 */ 66 */
64 QVariant value() const; 67 QVariant value() const;
68 QByteArray valueBytes() const;
69
70 /**
71 * Sets the group the line belongs to.
72 */
73 void setGroup( const QString& group );
74
75 /**
76 * Returns the group the line belongs to.
77 */
78 QString group() const;
79
80 /**
81 * Returns whether the line belongs to a group.
82 */
83 bool hasGroup() const;
65 84
66 /** 85 /**
67 * Returns all parameters. 86 * Returns all parameters.
@@ -75,20 +94,20 @@ class VCardLine
75 94
76 /** 95 /**
77 * Returns the values of a special parameter. 96 * Returns the values of a special parameter.
78 * You can get a list of all parameters with @ref paramList(). 97 * You can get a list of all parameters with paramList().
79 */ 98 */
80 QStringList parameters( const QString& param ) const; 99 QStringList parameters( const QString& param ) const;
81 100
82 /** 101 /**
83 * Returns only the first value of a special parameter. 102 * Returns only the first value of a special parameter.
84 * You can get a list of all parameters with @ref paramList(). 103 * You can get a list of all parameters with paramList().
85 */ 104 */
86 QString parameter( const QString& param ) const; 105 QString parameter( const QString& param ) const;
87 106
88 private: 107 private:
89 QMap< QString, QStringList > *mParamMap; 108 ParamMap mParamMap;
90 QString mIdentifier; 109 QString mIdentifier;
91 QVariant mValue; 110 QByteArray mValue;
92 111
93 class VCardLinePrivate; 112 class VCardLinePrivate;
94 VCardLinePrivate *d; 113 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()
38 38
39VCard::List VCardParser::parseVCards( const QString& text ) 39VCard::List VCardParser::parseVCards( const QString& text )
40{ 40{
41 static QRegExp sep( "[\x0d\x0a]" );
42
41 VCard currentVCard; 43 VCard currentVCard;
42 VCard::List vCardList; 44 VCard::List vCardList;
43 QString currentLine; 45 QString currentLine;
44 46
45 QStringList lines = QStringList::split( QRegExp( "[\x0d\x0a]" ), text ); 47 const QStringList lines = QStringList::split( sep, text );
46 QStringList::Iterator it; 48 QStringList::ConstIterator it;
47 49
48 bool inVCard = false; 50 bool inVCard = false;
49 for ( it = lines.begin(); it != lines.end(); ++it ) { 51 QStringList::ConstIterator linesEnd( lines.end() );
52 for ( it = lines.begin(); it != linesEnd; ++it ) {
50 53
51 if ( (*it).isEmpty() ) // empty line 54 if ( (*it).isEmpty() ) // empty line
52 continue; 55 continue;
53 56
54 if ( (*it)[ 0 ] == ' ' || (*it)[ 0 ] == '\t' ) { // folded line => append to previous 57 if ( (*it)[ 0 ] == ' ' || (*it)[ 0 ] == '\t' ) { // folded line => append to previous
55 currentLine += (*it).remove( 0, 1 ); 58 currentLine += QString( *it ).remove( 0, 1 );
56 continue; 59 continue;
57 } else { 60 } else {
58 if ( inVCard && !currentLine.isEmpty() ) { // now parse the line 61 if ( inVCard && !currentLine.isEmpty() ) { // now parse the line
@@ -63,66 +66,79 @@ VCard::List VCardParser::parseVCards( const QString& text )
63 } 66 }
64 67
65 VCardLine vCardLine; 68 VCardLine vCardLine;
66 QString key = currentLine.left( colon ).stripWhiteSpace(); 69 const QString key = currentLine.left( colon ).stripWhiteSpace();
67 QString value = currentLine.mid( colon + 1 ); 70 QString value = currentLine.mid( colon + 1 );
68 71
69 QStringList params = QStringList::split( ';', key ); 72 QStringList params = QStringList::split( ';', key );
70 vCardLine.setIdentifier( params[0] ); 73
74 // check for group
75 if ( params[0].find( '.' ) != -1 ) {
76 const QStringList groupList = QStringList::split( '.', params[0] );
77 vCardLine.setGroup( groupList[0] );
78 vCardLine.setIdentifier( groupList[1] );
79 } else
80 vCardLine.setIdentifier( params[0] );
81
71 if ( params.count() > 1 ) { // find all parameters 82 if ( params.count() > 1 ) { // find all parameters
72 for ( uint i = 1; i < params.count(); ++i ) { 83 QStringList::ConstIterator paramIt = params.begin();
73 QStringList pair = QStringList::split( '=', params[i] ); 84 for ( ++paramIt; paramIt != params.end(); ++paramIt ) {
74//US if ( pair.size() == 1 ) { 85 QStringList pair = QStringList::split( '=', *paramIt );
75 if ( pair.count() == 1 ) { 86 if ( pair.count() == 1 ) {
87 // correct the fucking 2.1 'standard'
88 if ( pair[0].lower() == "quoted-printable" ) {
89 pair[0] = "encoding";
90 pair[1] = "quoted-printable";
91 } else if ( pair[0].lower() == "base64" ) {
92 pair[0] = "encoding";
93 pair[1] = "base64";
94 } else {
76 pair.prepend( "type" ); 95 pair.prepend( "type" );
96 }
77 } 97 }
78 if ( pair[1].contains( ',' ) ) { // parameter in type=x,y,z format 98 // This is pretty much a faster pair[1].contains( ',' )...
79 QStringList args = QStringList::split( ',', pair[ 1 ] ); 99 if ( pair[1].find( ',' ) != -1 ) { // parameter in type=x,y,z format
80 for ( uint j = 0; j < args.count(); ++j ) 100 const QStringList args = QStringList::split( ',', pair[ 1 ] );
81 vCardLine.addParameter( pair[0].lower(), args[j] ); 101 QStringList::ConstIterator argIt;
102 for ( argIt = args.begin(); argIt != args.end(); ++argIt )
103 vCardLine.addParameter( pair[0].lower(), *argIt );
82 } else 104 } else
83 vCardLine.addParameter( pair[0].lower(), pair[1] ); 105 vCardLine.addParameter( pair[0].lower(), pair[1] );
84 } 106 }
85 } 107 }
86 108
87 params = vCardLine.parameterList(); 109 params = vCardLine.parameterList();
88 if ( params.contains( "encoding" ) ) { // have to decode the data 110 if ( params.findIndex( "encoding" ) != -1 ) { // have to decode the data
89#if 0
90 QByteArray input, output; 111 QByteArray input, output;
91 input = value.local8Bit(); 112 if ( vCardLine.parameter( "encoding" ).lower() == "b" ||
92 if ( vCardLine.parameter( "encoding" ).lower() == "b" ) 113 vCardLine.parameter( "encoding" ).lower() == "base64" ) {
114 input = value.local8Bit();
93 KCodecs::base64Decode( input, output ); 115 KCodecs::base64Decode( input, output );
94 else if ( vCardLine.parameter( "encoding" ).lower() == "quoted-printable" ) 116 } else if ( vCardLine.parameter( "encoding" ).lower() == "quoted-printable" ) {
117 // join any qp-folded lines
118 while ( value.mid(value.length()-1,1) == "=" && it != linesEnd ) {
119 value = value.remove( value.length()-1, 1 ) + (*it);
120 ++it;
121 }
122 input = value.local8Bit();
95 KCodecs::quotedPrintableDecode( input, output ); 123 KCodecs::quotedPrintableDecode( input, output );
96 124 }
97 //qDebug("VCardParser::parseVCards has to be verified"); 125//PP our vcards are *supposed* to be in UTF-8
98 //US I am not sure if this is correct 126// if ( vCardLine.parameter( "charset" ).lower() == "utf-8" ) {
99 //US vCardLine.setValue( output ); 127// vCardLine.setValue( QString::fromUtf8( output.data(), output.size() ) );
100 QCString cs(output); 128// } else
101 qDebug("len1 %d len2 %d ",input.size(), output.size( )); 129 vCardLine.setValue( output );
102#endif 130//PP our vcards are *supposed* to be in UTF-8
103 QCString cs = value.local8Bit(); 131// } else if ( vCardLine.parameter( "charset" ).lower() == "utf-8" ) {
104 qDebug("****************************************** "); 132// vCardLine.setValue( QString::fromUtf8( value.ascii() ) );
105 qDebug("************* WARNING ******************** "); 133 } else
106 qDebug("****************************************** ");
107 qDebug("Make sure, the decoding is done after");
108 qDebug("QVariant conversion!");
109 qDebug("Insert Line DECODING OKAY, where this is implemented");
110 // use for decoding the above code!
111 vCardLine.setValue( cs );
112 } else {
113
114 //qDebug("VCardParser::parseVCards has to be verified");
115//US vCardLine.setValue( value.replace( "\\n", "\n" ) );
116 vCardLine.setValue( value.replace( QRegExp("\\\\n"), "\n" ) ); 134 vCardLine.setValue( value.replace( QRegExp("\\\\n"), "\n" ) );
117 }
118 135
119 currentVCard.addLine( vCardLine ); 136 currentVCard.addLine( vCardLine );
120 } 137 }
138
121 // we do not save the start and end tag as vcardline 139 // we do not save the start and end tag as vcardline
122 if ( (*it).lower().startsWith( "begin:vcard" ) ) { 140 if ( (*it).lower().startsWith( "begin:vcard" ) ) {
123 inVCard = true; 141 inVCard = true;
124 //qDebug("VCardParser::parseVCards has to be verified");
125//US currentLine.setLength( 0 );
126 currentLine = ""; 142 currentLine = "";
127 currentVCard.clear(); // flush vcard 143 currentVCard.clear(); // flush vcard
128 continue; 144 continue;
@@ -131,8 +147,6 @@ VCard::List VCardParser::parseVCards( const QString& text )
131 if ( (*it).lower().startsWith( "end:vcard" ) ) { 147 if ( (*it).lower().startsWith( "end:vcard" ) ) {
132 inVCard = false; 148 inVCard = false;
133 vCardList.append( currentVCard ); 149 vCardList.append( currentVCard );
134 //qDebug("VCardParser::parseVCards has to be verified");
135//US currentLine.setLength( 0 );
136 currentLine = ""; 150 currentLine = "";
137 currentVCard.clear(); // flush vcard 151 currentVCard.clear(); // flush vcard
138 continue; 152 continue;
@@ -155,28 +169,30 @@ QString VCardParser::createVCards( const VCard::List& list )
155 QStringList values; 169 QStringList values;
156 QStringList::ConstIterator identIt; 170 QStringList::ConstIterator identIt;
157 QStringList::Iterator paramIt; 171 QStringList::Iterator paramIt;
158 QStringList::Iterator valueIt; 172 QStringList::ConstIterator valueIt;
159 173
160 VCardLine::List lines; 174 VCardLine::List lines;
161 VCardLine::List::Iterator lineIt; 175 VCardLine::List::ConstIterator lineIt;
162 VCard::List::ConstIterator cardIt; 176 VCard::List::ConstIterator cardIt;
163 177
164 bool hasEncoding; 178 bool hasEncoding;
165 179
166
167 // iterate over the cards 180 // iterate over the cards
168 for ( cardIt = list.begin(); cardIt != list.end(); ++cardIt ) { 181 VCard::List::ConstIterator listEnd( list.end() );
182 for ( cardIt = list.begin(); cardIt != listEnd; ++cardIt ) {
169 text.append( "BEGIN:VCARD\r\n" ); 183 text.append( "BEGIN:VCARD\r\n" );
170 184
171 idents = (*cardIt).identifiers(); 185 idents = (*cardIt).identifiers();
172 for ( identIt = idents.begin(); identIt != idents.end(); ++identIt ) { 186 for ( identIt = idents.begin(); identIt != idents.end(); ++identIt ) {
173 VCard card = (*cardIt); 187 lines = (*cardIt).lines( (*identIt) );
174 lines = card.lines( (*identIt) );
175 188
176 // iterate over the lines 189 // iterate over the lines
177 for ( lineIt = lines.begin(); lineIt != lines.end(); ++lineIt ) { 190 for ( lineIt = lines.begin(); lineIt != lines.end(); ++lineIt ) {
178 if ( !(*lineIt).value().asString().isEmpty() ) { 191 if ( !(*lineIt).value().asString().isEmpty() ) {
179 textLine = (*lineIt).identifier(); 192 if ( (*lineIt).hasGroup() )
193 textLine = (*lineIt).group() + "." + (*lineIt).identifier();
194 else
195 textLine = (*lineIt).identifier();
180 196
181 params = (*lineIt).parameterList(); 197 params = (*lineIt).parameterList();
182 hasEncoding = false; 198 hasEncoding = false;
@@ -198,24 +214,15 @@ QString VCardParser::createVCards( const VCard::List& list )
198 214
199 if ( hasEncoding ) { // have to encode the data 215 if ( hasEncoding ) { // have to encode the data
200 QByteArray input, output; 216 QByteArray input, output;
201 217 input = (*lineIt).valueBytes();
202 qDebug("VCardParser::createVCards has to be verified");
203//US input = (*lineIt).value().toByteArray();
204
205//US I am not sure if this is correct
206 QCString cs ((*lineIt).value().toCString());
207 input = cs;
208
209 if ( encodingType == "b" ) 218 if ( encodingType == "b" )
210 KCodecs::base64Encode( input, output ); 219 KCodecs::base64Encode( input, output );
211 else if ( encodingType == "quoted-printable" ) 220 else if ( encodingType == "quoted-printable" )
212 KCodecs::quotedPrintableEncode( input, output ); 221 KCodecs::quotedPrintableEncode( input, output );
213 textLine.append( ":" + QString( output ) ); 222 textLine.append( ":" + QString( output ) );
214 } else { 223 } else
215 qDebug("VCardParser::createVCards has to be verified");
216//US textLine.append( ":" + (*lineIt).value().asString().replace( "\n", "\\n" ) );
217 textLine.append( ":" + (*lineIt).value().asString().replace( QRegExp("\n"), "\\n" ) ); 224 textLine.append( ":" + (*lineIt).value().asString().replace( QRegExp("\n"), "\\n" ) );
218 } 225
219 if ( textLine.length() > FOLD_WIDTH ) { // we have to fold the line 226 if ( textLine.length() > FOLD_WIDTH ) { // we have to fold the line
220 for ( uint i = 0; i <= ( textLine.length() / FOLD_WIDTH ); ++i ) 227 for ( uint i = 0; i <= ( textLine.length() / FOLD_WIDTH ); ++i )
221 text.append( ( i == 0 ? "" : " " ) + textLine.mid( i * FOLD_WIDTH, FOLD_WIDTH ) + "\r\n" ); 228 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 @@
20 20
21#include <qdatastream.h> 21#include <qdatastream.h>
22#include <qstring.h> 22#include <qstring.h>
23#include <qregexp.h>
24#include <kmdcodec.h>
25 23
26#include "agent.h" 24#include "agent.h"
27#include "key.h" 25#include "key.h"
@@ -57,71 +55,69 @@ VCardTool::VCardTool()
57 mPhoneTypeMap.insert( "ISDN", PhoneNumber::Isdn ); 55 mPhoneTypeMap.insert( "ISDN", PhoneNumber::Isdn );
58 mPhoneTypeMap.insert( "PCS", PhoneNumber::Pcs ); 56 mPhoneTypeMap.insert( "PCS", PhoneNumber::Pcs );
59 mPhoneTypeMap.insert( "PAGER", PhoneNumber::Pager ); 57 mPhoneTypeMap.insert( "PAGER", PhoneNumber::Pager );
60 mPhoneTypeMap.insert( "SIP", PhoneNumber::Sip );
61} 58}
62 59
63VCardTool::~VCardTool() 60VCardTool::~VCardTool()
64{ 61{
65} 62}
66 63
64// TODO: make list a const&
67QString VCardTool::createVCards( Addressee::List list, VCard::Version version ) 65QString VCardTool::createVCards( Addressee::List list, VCard::Version version )
68{ 66{
69 VCard::List vCardList; 67 VCard::List vCardList;
68 static const QRegExp semiExp(";");
70 69
71 Addressee::List::Iterator addrIt; 70 Addressee::List::ConstIterator addrIt;
72 for ( addrIt = list.begin(); addrIt != list.end(); ++addrIt ) { 71 Addressee::List::ConstIterator listEnd( list.end() );
72 for ( addrIt = list.begin(); addrIt != listEnd; ++addrIt ) {
73 VCard card; 73 VCard card;
74 QStringList::ConstIterator strIt; 74 QStringList::ConstIterator strIt;
75 75
76 // ADR + LABEL 76 // ADR + LABEL
77 Address::List addresses = (*addrIt).addresses(); 77 const Address::List addresses = (*addrIt).addresses();
78 for ( Address::List::Iterator it = addresses.begin(); it != addresses.end(); ++it ) { 78 for ( Address::List::ConstIterator it = addresses.begin(); it != addresses.end(); ++it ) {
79 QStringList address; 79 QStringList address;
80 80
81/*US 81 bool isEmpty = ( (*it).postOfficeBox().isEmpty() &&
82 address.append( (*it).postOfficeBox().replace( ';', "\\;" ) ); 82 (*it).extended().isEmpty() &&
83 address.append( (*it).extended().replace( ';', "\\;" ) ); 83 (*it).street().isEmpty() &&
84 address.append( (*it).street().replace( ';', "\\;" ) ); 84 (*it).locality().isEmpty() &&
85 address.append( (*it).locality().replace( ';', "\\;" ) ); 85 (*it).region().isEmpty() &&
86 address.append( (*it).region().replace( ';', "\\;" ) ); 86 (*it).postalCode().isEmpty() &&
87 address.append( (*it).postalCode().replace( ';', "\\;" ) ); 87 (*it).country().isEmpty() );
88 address.append( (*it).country().replace( ';', "\\;" ) ); 88
89*/ 89 address.append( (*it).postOfficeBox().replace( semiExp, "\\;" ) );
90//US using the old implementation instead 90 address.append( (*it).extended().replace( semiExp, "\\;" ) );
91 //qDebug("VCardTool::createVCards has to be verified"); 91 address.append( (*it).street().replace( semiExp, "\\;" ) );
92 address.append( (*it).postOfficeBox().replace( QRegExp(";"), "\\;" ) ); 92 address.append( (*it).locality().replace( semiExp, "\\;" ) );
93 address.append( (*it).extended().replace( QRegExp(";"), "\\;" ) ); 93 address.append( (*it).region().replace( semiExp, "\\;" ) );
94 address.append( (*it).street().replace( QRegExp(";"), "\\;" ) ); 94 address.append( (*it).postalCode().replace( semiExp, "\\;" ) );
95 address.append( (*it).locality().replace( QRegExp(";"), "\\;" ) ); 95 address.append( (*it).country().replace( semiExp, "\\;" ) );
96 address.append( (*it).region().replace( QRegExp(";"), "\\;" ) );
97 address.append( (*it).postalCode().replace( QRegExp(";"), "\\;" ) );
98 address.append( (*it).country().replace( QRegExp(";"), "\\;" ) );
99 96
100 VCardLine adrLine( "ADR", address.join( ";" ) ); 97 VCardLine adrLine( "ADR", address.join( ";" ) );
98 if ( version == VCard::v2_1 ) {
99 adrLine.addParameter( "CHARSET", "UTF-8" );
100 adrLine.addParameter( "ENCODING", "8BIT" );
101 }
102
101 VCardLine labelLine( "LABEL", (*it).label() ); 103 VCardLine labelLine( "LABEL", (*it).label() );
104 if ( version == VCard::v2_1 ) {
105 labelLine.addParameter( "CHARSET", "UTF-8" );
106 labelLine.addParameter( "ENCODING", "8BIT" );
107 }
102 108
103 bool hasLabel = !(*it).label().isEmpty(); 109 bool hasLabel = !(*it).label().isEmpty();
104 QMap<QString, int>::Iterator typeIt; 110 QMap<QString, int>::ConstIterator typeIt;
105 for ( typeIt = mAddressTypeMap.begin(); typeIt != mAddressTypeMap.end(); ++typeIt ) { 111 for ( typeIt = mAddressTypeMap.begin(); typeIt != mAddressTypeMap.end(); ++typeIt ) {
106 if ( typeIt.data() & (*it).type() ) { 112 if ( typeIt.data() & (*it).type() ) {
107 if ( version == VCard::v3_0 ) { 113 adrLine.addParameter( "TYPE", typeIt.key() );
108 adrLine.addParameter( "TYPE", typeIt.key().lower() ); 114 if ( hasLabel )
109 } 115 labelLine.addParameter( "TYPE", typeIt.key() );
110 else {
111 adrLine.addParameter( "TYPE", typeIt.key() );
112 }
113 if ( hasLabel ) {
114 if ( version == VCard::v3_0 ) {
115 labelLine.addParameter( "TYPE", typeIt.key().lower() );
116 }
117 else {
118 labelLine.addParameter( "TYPE", typeIt.key() );
119 }
120 }
121 } 116 }
122 } 117 }
123 118
124 card.addLine( adrLine ); 119 if ( !isEmpty )
120 card.addLine( adrLine );
125 if ( hasLabel ) 121 if ( hasLabel )
126 card.addLine( labelLine ); 122 card.addLine( labelLine );
127 } 123 }
@@ -137,26 +133,32 @@ QString VCardTool::createVCards( Addressee::List list, VCard::Version version )
137 QStringList categories = (*addrIt).categories(); 133 QStringList categories = (*addrIt).categories();
138 QStringList::Iterator catIt; 134 QStringList::Iterator catIt;
139 for ( catIt = categories.begin(); catIt != categories.end(); ++catIt ) 135 for ( catIt = categories.begin(); catIt != categories.end(); ++catIt )
140 {
141//US using the old implementation instead
142 // qDebug("VCardTool::createVCards has to be verified");
143//US (*catIt).replace( ',', "\\," );
144 (*catIt).replace( QRegExp(","), "\\," ); 136 (*catIt).replace( QRegExp(","), "\\," );
137
138 VCardLine catLine( "CATEGORIES", categories.join( "," ) );
139 if ( version == VCard::v2_1 ) {
140 catLine.addParameter( "CHARSET", "UTF-8" );
141 catLine.addParameter( "ENCODING", "8BIT" );
145 } 142 }
146 card.addLine( VCardLine( "CATEGORIES", categories.join( "," ) ) ); 143
144 card.addLine( catLine );
147 } 145 }
148 146
149 // CLASS 147 // CLASS
150 if ( version == VCard::v3_0 ) { 148 if ( version == VCard::v3_0 ) {
151 card.addLine( createSecrecy( (*addrIt).secrecy() ) ); 149 card.addLine( createSecrecy( (*addrIt).secrecy() ) );
152 } 150 }
153 151
154 // EMAIL 152 // EMAIL
155 QStringList emails = (*addrIt).emails(); 153 const QStringList emails = (*addrIt).emails();
156 bool pref = true; 154 bool pref = true;
157 for ( strIt = emails.begin(); strIt != emails.end(); ++strIt ) { 155 for ( strIt = emails.begin(); strIt != emails.end(); ++strIt ) {
158 VCardLine line( "EMAIL", *strIt ); 156 VCardLine line( "EMAIL", *strIt );
159 if ( pref == true ) { 157 if ( version == VCard::v2_1 ) {
158 line.addParameter( "CHARSET", "UTF-8" );
159 line.addParameter( "ENCODING", "8BIT" );
160 }
161 if ( pref == true && emails.count() > 1 ) {
160 line.addParameter( "TYPE", "PREF" ); 162 line.addParameter( "TYPE", "PREF" );
161 pref = false; 163 pref = false;
162 } 164 }
@@ -164,7 +166,12 @@ QString VCardTool::createVCards( Addressee::List list, VCard::Version version )
164 } 166 }
165 167
166 // FN 168 // FN
167 card.addLine( VCardLine( "FN", (*addrIt).formattedName() ) ); 169 VCardLine fnLine( "FN", (*addrIt).formattedName() );
170 if ( version == VCard::v2_1 ) {
171 fnLine.addParameter( "CHARSET", "UTF-8" );
172 fnLine.addParameter( "ENCODING", "8BIT" );
173 }
174 card.addLine( fnLine );
168 175
169 // GEO 176 // GEO
170 Geo geo = (*addrIt).geo(); 177 Geo geo = (*addrIt).geo();
@@ -175,7 +182,7 @@ QString VCardTool::createVCards( Addressee::List list, VCard::Version version )
175 } 182 }
176 183
177 // KEY 184 // KEY
178 Key::List keys = (*addrIt).keys(); 185 const Key::List keys = (*addrIt).keys();
179 Key::List::ConstIterator keyIt; 186 Key::List::ConstIterator keyIt;
180 for ( keyIt = keys.begin(); keyIt != keys.end(); ++keyIt ) 187 for ( keyIt = keys.begin(); keyIt != keys.end(); ++keyIt )
181 card.addLine( createKey( *keyIt ) ); 188 card.addLine( createKey( *keyIt ) );
@@ -184,37 +191,55 @@ QString VCardTool::createVCards( Addressee::List list, VCard::Version version )
184 card.addLine( createPicture( "LOGO", (*addrIt).logo() ) ); 191 card.addLine( createPicture( "LOGO", (*addrIt).logo() ) );
185 192
186 // MAILER 193 // MAILER
187 card.addLine( VCardLine( "MAILER", (*addrIt).mailer() ) ); 194 VCardLine mailerLine( "MAILER", (*addrIt).mailer() );
195 if ( version == VCard::v2_1 ) {
196 mailerLine.addParameter( "CHARSET", "UTF-8" );
197 mailerLine.addParameter( "ENCODING", "8BIT" );
198 }
199 card.addLine( mailerLine );
188 200
189 // N 201 // N
190 QStringList name; 202 QStringList name;
191//US using the old implementation instead 203 name.append( (*addrIt).familyName().replace( semiExp, "\\;" ) );
192 //qDebug("VCardTool::createVCards has to be verified"); 204 name.append( (*addrIt).givenName().replace( semiExp, "\\;" ) );
193/*US 205 name.append( (*addrIt).additionalName().replace( semiExp, "\\;" ) );
194 name.append( (*addrIt).familyName().replace( ';', "\\;" ) ); 206 name.append( (*addrIt).prefix().replace( semiExp, "\\;" ) );
195 name.append( (*addrIt).givenName().replace( ';', "\\;" ) ); 207 name.append( (*addrIt).suffix().replace( semiExp, "\\;" ) );
196 name.append( (*addrIt).additionalName().replace( ';', "\\;" ) ); 208
197 name.append( (*addrIt).prefix().replace( ';', "\\;" ) ); 209 VCardLine nLine( "N", name.join( ";" ) );
198 name.append( (*addrIt).suffix().replace( ';', "\\;" ) ); 210 if ( version == VCard::v2_1 ) {
199*/ 211 nLine.addParameter( "CHARSET", "UTF-8" );
200 name.append( (*addrIt).familyName().replace( QRegExp(";"), "\\;" ) ); 212 nLine.addParameter( "ENCODING", "8BIT" );
201 name.append( (*addrIt).givenName().replace( QRegExp(";"), "\\;" ) ); 213 }
202 name.append( (*addrIt).additionalName().replace( QRegExp(";"), "\\;" ) ); 214 card.addLine( nLine );
203 name.append( (*addrIt).prefix().replace( QRegExp(";"), "\\;" ) ); 215
204 name.append( (*addrIt).suffix().replace( QRegExp(";"), "\\;" ) ); 216 // NAME
205 217 VCardLine nameLine( "NAME", (*addrIt).name() );
206 if ( !name.join( "" ).isEmpty() ) 218 if ( version == VCard::v2_1 ) {
207 card.addLine( VCardLine( "N", name.join( ";" ) ) ); 219 nameLine.addParameter( "CHARSET", "UTF-8" );
220 nameLine.addParameter( "ENCODING", "8BIT" );
221 }
222 card.addLine( nameLine );
208 223
209 // NICKNAME 224 // NICKNAME
210 if ( version == VCard::v3_0 ) 225 if ( version == VCard::v3_0 )
211 card.addLine( VCardLine( "NICKNAME", (*addrIt).nickName() ) ); 226 card.addLine( VCardLine( "NICKNAME", (*addrIt).nickName() ) );
212 227
213 // NOTE 228 // NOTE
214 card.addLine( VCardLine( "NOTE", (*addrIt).note() ) ); 229 VCardLine noteLine( "NOTE", (*addrIt).note() );
230 if ( version == VCard::v2_1 ) {
231 noteLine.addParameter( "CHARSET", "UTF-8" );
232 noteLine.addParameter( "ENCODING", "8BIT" );
233 }
234 card.addLine( noteLine );
215 235
216 // ORG 236 // ORG
217 card.addLine( VCardLine( "ORG", (*addrIt).organization() ) ); 237 VCardLine orgLine( "ORG", (*addrIt).organization() );
238 if ( version == VCard::v2_1 ) {
239 orgLine.addParameter( "CHARSET", "UTF-8" );
240 orgLine.addParameter( "ENCODING", "8BIT" );
241 }
242 card.addLine( orgLine );
218 243
219 // PHOTO 244 // PHOTO
220 card.addLine( createPicture( "PHOTO", (*addrIt).photo() ) ); 245 card.addLine( createPicture( "PHOTO", (*addrIt).photo() ) );
@@ -227,7 +252,12 @@ QString VCardTool::createVCards( Addressee::List list, VCard::Version version )
227 card.addLine( VCardLine( "REV", createDateTime( (*addrIt).revision() ) ) ); 252 card.addLine( VCardLine( "REV", createDateTime( (*addrIt).revision() ) ) );
228 253
229 // ROLE 254 // ROLE
230 card.addLine( VCardLine( "ROLE", (*addrIt).role() ) ); 255 VCardLine roleLine( "ROLE", (*addrIt).role() );
256 if ( version == VCard::v2_1 ) {
257 roleLine.addParameter( "CHARSET", "UTF-8" );
258 roleLine.addParameter( "ENCODING", "8BIT" );
259 }
260 card.addLine( roleLine );
231 261
232 // SORT-STRING 262 // SORT-STRING
233 if ( version == VCard::v3_0 ) 263 if ( version == VCard::v3_0 )
@@ -237,25 +267,27 @@ QString VCardTool::createVCards( Addressee::List list, VCard::Version version )
237 card.addLine( createSound( (*addrIt).sound() ) ); 267 card.addLine( createSound( (*addrIt).sound() ) );
238 268
239 // TEL 269 // TEL
240 PhoneNumber::List phoneNumbers = (*addrIt).phoneNumbers(); 270 const PhoneNumber::List phoneNumbers = (*addrIt).phoneNumbers();
241 PhoneNumber::List::ConstIterator phoneIt; 271 PhoneNumber::List::ConstIterator phoneIt;
242 for ( phoneIt = phoneNumbers.begin(); phoneIt != phoneNumbers.end(); ++phoneIt ) { 272 for ( phoneIt = phoneNumbers.begin(); phoneIt != phoneNumbers.end(); ++phoneIt ) {
243 VCardLine line( "TEL", (*phoneIt).number() ); 273 VCardLine line( "TEL", (*phoneIt).number() );
244 274
245 QMap<QString, int>::Iterator typeIt; 275 QMap<QString, int>::ConstIterator typeIt;
246 for ( typeIt = mPhoneTypeMap.begin(); typeIt != mPhoneTypeMap.end(); ++typeIt ) { 276 for ( typeIt = mPhoneTypeMap.begin(); typeIt != mPhoneTypeMap.end(); ++typeIt ) {
247 if ( typeIt.data() & (*phoneIt).type() ) 277 if ( typeIt.data() & (*phoneIt).type() )
248 if ( version == VCard::v3_0 ) 278 line.addParameter( "TYPE", typeIt.key() );
249 line.addParameter( "TYPE", typeIt.key().lower() );
250 else
251 line.addParameter( "TYPE", typeIt.key() );
252 } 279 }
253 280
254 card.addLine( line ); 281 card.addLine( line );
255 } 282 }
256 283
257 // TITLE 284 // TITLE
258 card.addLine( VCardLine( "TITLE", (*addrIt).title() ) ); 285 VCardLine titleLine( "TITLE", (*addrIt).title() );
286 if ( version == VCard::v2_1 ) {
287 titleLine.addParameter( "CHARSET", "UTF-8" );
288 titleLine.addParameter( "ENCODING", "8BIT" );
289 }
290 card.addLine( titleLine );
259 291
260 // TZ 292 // TZ
261 TimeZone timeZone = (*addrIt).timeZone(); 293 TimeZone timeZone = (*addrIt).timeZone();
@@ -286,14 +318,19 @@ QString VCardTool::createVCards( Addressee::List list, VCard::Version version )
286 card.addLine( VCardLine( "VERSION", "3.0" ) ); 318 card.addLine( VCardLine( "VERSION", "3.0" ) );
287 319
288 // X- 320 // X-
289 QStringList customs = (*addrIt).customs(); 321 const QStringList customs = (*addrIt).customs();
290 for ( strIt = customs.begin(); strIt != customs.end(); ++strIt ) { 322 for ( strIt = customs.begin(); strIt != customs.end(); ++strIt ) {
291 QString identifier = "X-" + (*strIt).left( (*strIt).find( ":" ) ); 323 QString identifier = "X-" + (*strIt).left( (*strIt).find( ":" ) );
292 QString value = (*strIt).mid( (*strIt).find( ":" ) + 1 ); 324 QString value = (*strIt).mid( (*strIt).find( ":" ) + 1 );
293 if ( value.isEmpty() ) 325 if ( value.isEmpty() )
294 continue; 326 continue;
295 327
296 card.addLine( VCardLine( identifier, value ) ); 328 VCardLine line( identifier, value );
329 if ( version == VCard::v2_1 ) {
330 line.addParameter( "CHARSET", "UTF-8" );
331 line.addParameter( "ENCODING", "8BIT" );
332 }
333 card.addLine( line );
297 } 334 }
298 335
299 vCardList.append( card ); 336 vCardList.append( card );
@@ -304,37 +341,38 @@ QString VCardTool::createVCards( Addressee::List list, VCard::Version version )
304 341
305Addressee::List VCardTool::parseVCards( const QString& vcard ) 342Addressee::List VCardTool::parseVCards( const QString& vcard )
306{ 343{
307 QChar semicolonSep( ';' ); 344 static const QChar semicolonSep( ';' );
308 QChar commaSep( ',' ); 345 static const QChar commaSep( ',' );
309 QString identifier; 346 QString identifier;
310 347
311 Addressee::List addrList; 348 Addressee::List addrList;
312 VCard::List vCardList = VCardParser::parseVCards( vcard ); 349 const VCard::List vCardList = VCardParser::parseVCards( vcard );
313 VCard::List::Iterator cardIt; 350
314 for ( cardIt = vCardList.begin(); cardIt != vCardList.end(); ++cardIt ) { 351 VCard::List::ConstIterator cardIt;
352 VCard::List::ConstIterator listEnd( vCardList.end() );
353 for ( cardIt = vCardList.begin(); cardIt != listEnd; ++cardIt ) {
315 Addressee addr; 354 Addressee addr;
316 QStringList idents = (*cardIt).identifiers(); 355
356 const QStringList idents = (*cardIt).identifiers();
317 QStringList::ConstIterator identIt; 357 QStringList::ConstIterator identIt;
318 for ( identIt = idents.begin(); identIt != idents.end(); ++identIt ) { 358 QStringList::ConstIterator identEnd( idents.end() );
319 VCard card = (*cardIt); 359 for ( identIt = idents.begin(); identIt != identEnd; ++identIt ) {
320 VCardLine::List lines = card.lines( (*identIt) ); 360 const VCardLine::List lines = (*cardIt).lines( (*identIt) );
321 VCardLine::List::Iterator lineIt; 361 VCardLine::List::ConstIterator lineIt;
322 362
323 // iterate over the lines 363 // iterate over the lines
324 for ( lineIt = lines.begin(); lineIt != lines.end(); ++lineIt ) { 364 for ( lineIt = lines.begin(); lineIt != lines.end(); ++lineIt ) {
325 QStringList params = (*lineIt).parameterList();
326
327 identifier = (*lineIt).identifier().lower(); 365 identifier = (*lineIt).identifier().lower();
328 // ADR 366 // ADR
329 if ( identifier == "adr" ) { 367 if ( identifier == "adr" ) {
330 Address address; 368 Address address;
331 QStringList addrParts = splitString( semicolonSep, (*lineIt).value().asString() ); 369 const QStringList addrParts = splitString( semicolonSep, (*lineIt).value().asString() );
332 if ( addrParts.count() > 0 ) 370 if ( addrParts.count() > 0 )
333 address.setPostOfficeBox( addrParts[ 0 ] ); 371 address.setPostOfficeBox( addrParts[ 0 ] );
334 if ( addrParts.count() > 1 ) 372 if ( addrParts.count() > 1 )
335 address.setExtended( addrParts[ 1 ] ); 373 address.setExtended( addrParts[ 1 ] );
336 if ( addrParts.count() > 2 ) 374 if ( addrParts.count() > 2 )
337 address.setStreet( addrParts[ 2 ].replace ( QRegExp("\\\\n") , "\n") ); 375 address.setStreet( addrParts[ 2 ] );
338 if ( addrParts.count() > 3 ) 376 if ( addrParts.count() > 3 )
339 address.setLocality( addrParts[ 3 ] ); 377 address.setLocality( addrParts[ 3 ] );
340 if ( addrParts.count() > 4 ) 378 if ( addrParts.count() > 4 )
@@ -346,50 +384,47 @@ Addressee::List VCardTool::parseVCards( const QString& vcard )
346 384
347 int type = 0; 385 int type = 0;
348 386
349 QStringList types = (*lineIt).parameters( "type" ); 387 const QStringList types = (*lineIt).parameters( "type" );
350 for ( QStringList::Iterator it = types.begin(); it != types.end(); ++it ) 388 for ( QStringList::ConstIterator it = types.begin(); it != types.end(); ++it )
351 type += mAddressTypeMap[ (*it).lower() ]; 389 type += mAddressTypeMap[ (*it).lower() ];
352 390
353 if ( !type )
354 type = Address::Home; // default
355
356 address.setType( type ); 391 address.setType( type );
357 addr.insertAddress( address ); 392 addr.insertAddress( address );
358 } 393 }
359 394
360 // AGENT 395 // AGENT
361 if ( identifier == "agent" ) 396 else if ( identifier == "agent" )
362 addr.setAgent( parseAgent( *lineIt ) ); 397 addr.setAgent( parseAgent( *lineIt ) );
363 398
364 // BDAY 399 // BDAY
365 if ( identifier == "bday" ) 400 else if ( identifier == "bday" )
366 addr.setBirthday( parseDateTime( (*lineIt).value().asString() ) ); 401 addr.setBirthday( parseDateTime( (*lineIt).value().asString() ) );
367 402
368 // CATEGORIES 403 // CATEGORIES
369 if ( identifier == "categories" ) { 404 else if ( identifier == "categories" ) {
370 QStringList categories = splitString( commaSep, (*lineIt).value().asString() ); 405 const QStringList categories = splitString( commaSep, (*lineIt).value().asString() );
371 addr.setCategories( categories ); 406 addr.setCategories( categories );
372 } 407 }
373 408
374 // CLASS 409 // CLASS
375 if ( identifier == "class" ) 410 else if ( identifier == "class" )
376 addr.setSecrecy( parseSecrecy( *lineIt ) ); 411 addr.setSecrecy( parseSecrecy( *lineIt ) );
377 412
378 // EMAIL 413 // EMAIL
379 if ( identifier == "email" ) { 414 else if ( identifier == "email" ) {
380 QStringList types = (*lineIt).parameters( "type" ); 415 const QStringList types = (*lineIt).parameters( "type" );
381 addr.insertEmail( (*lineIt).value().asString(), types.contains( "PREF" ) ); 416 addr.insertEmail( (*lineIt).value().asString(), types.findIndex( "PREF" ) != -1 );
382 } 417 }
383 418
384 // FN 419 // FN
385 if ( identifier == "fn" ) 420 else if ( identifier == "fn" )
386 addr.setFormattedName( (*lineIt).value().asString() ); 421 addr.setFormattedName( (*lineIt).value().asString() );
387 422
388 // GEO 423 // GEO
389 if ( identifier == "geo" ) { 424 else if ( identifier == "geo" ) {
390 Geo geo; 425 Geo geo;
391 426
392 QStringList geoParts = QStringList::split( ';', (*lineIt).value().asString(), true ); 427 const QStringList geoParts = QStringList::split( ';', (*lineIt).value().asString(), true );
393 geo.setLatitude( geoParts[ 0 ].toFloat() ); 428 geo.setLatitude( geoParts[ 0 ].toFloat() );
394 geo.setLongitude( geoParts[ 1 ].toFloat() ); 429 geo.setLongitude( geoParts[ 1 ].toFloat() );
395 430
@@ -397,41 +432,47 @@ Addressee::List VCardTool::parseVCards( const QString& vcard )
397 } 432 }
398 433
399 // KEY 434 // KEY
400 if ( identifier == "key" ) 435 else if ( identifier == "key" )
401 addr.insertKey( parseKey( *lineIt ) ); 436 addr.insertKey( parseKey( *lineIt ) );
402 437
403 // LABEL 438 // LABEL
404 if ( identifier == "label" ) { 439 else if ( identifier == "label" ) {
405 int type = 0; 440 int type = 0;
406 441
407 QStringList types = (*lineIt).parameters( "type" ); 442 const QStringList types = (*lineIt).parameters( "type" );
408 for ( QStringList::Iterator it = types.begin(); it != types.end(); ++it ) 443 for ( QStringList::ConstIterator it = types.begin(); it != types.end(); ++it )
409 type += mAddressTypeMap[ (*it).lower() ]; 444 type += mAddressTypeMap[ (*it).lower() ];
410 445
411 if ( !type ) 446 bool available = false;
412 type = Address::Home;
413
414 KABC::Address::List addressList = addr.addresses(); 447 KABC::Address::List addressList = addr.addresses();
415 KABC::Address::List::Iterator it; 448 KABC::Address::List::Iterator it;
416 for ( it = addressList.begin(); it != addressList.end(); ++it ) { 449 for ( it = addressList.begin(); it != addressList.end(); ++it ) {
417 if ( (*it).type() == type ) { 450 if ( (*it).type() == type ) {
418 (*it).setLabel( (*lineIt).value().asString() ); 451 (*it).setLabel( (*lineIt).value().asString() );
419 addr.insertAddress( *it ); 452 addr.insertAddress( *it );
453 available = true;
454 break;
420 } 455 }
421 } 456 }
457
458 if ( !available ) { // a standalone LABEL tag
459 KABC::Address address( type );
460 address.setLabel( (*lineIt).value().asString() );
461 addr.insertAddress( address );
462 }
422 } 463 }
423 464
424 // LOGO 465 // LOGO
425 if ( identifier == "logo" ) 466 else if ( identifier == "logo" )
426 addr.setLogo( parsePicture( *lineIt ) ); 467 addr.setLogo( parsePicture( *lineIt ) );
427 468
428 // MAILER 469 // MAILER
429 if ( identifier == "mailer" ) 470 else if ( identifier == "mailer" )
430 addr.setMailer( (*lineIt).value().asString() ); 471 addr.setMailer( (*lineIt).value().asString() );
431 472
432 // N 473 // N
433 if ( identifier == "n" ) { 474 else if ( identifier == "n" ) {
434 QStringList nameParts = splitString( semicolonSep, (*lineIt).value().asString() ); 475 const QStringList nameParts = splitString( semicolonSep, (*lineIt).value().asString() );
435 if ( nameParts.count() > 0 ) 476 if ( nameParts.count() > 0 )
436 addr.setFamilyName( nameParts[ 0 ] ); 477 addr.setFamilyName( nameParts[ 0 ] );
437 if ( nameParts.count() > 1 ) 478 if ( nameParts.count() > 1 )
@@ -444,78 +485,70 @@ Addressee::List VCardTool::parseVCards( const QString& vcard )
444 addr.setSuffix( nameParts[ 4 ] ); 485 addr.setSuffix( nameParts[ 4 ] );
445 } 486 }
446 487
488 // NAME
489 else if ( identifier == "name" )
490 addr.setName( (*lineIt).value().asString() );
491
447 // NICKNAME 492 // NICKNAME
448 if ( identifier == "nickname" ) 493 else if ( identifier == "nickname" )
449 addr.setNickName( (*lineIt).value().asString() ); 494 addr.setNickName( (*lineIt).value().asString() );
450 495
451 // NOTE 496 // NOTE
452 if ( identifier == "note" ) { 497 else if ( identifier == "note" )
453// #ifdef DESKTOP_VERSION 498 addr.setNote( (*lineIt).value().asString() );
454// addr.setNote( (*lineIt).value().asString() );
455// #else
456 QString note = (*lineIt).value().asString();
457 if ( ! note.isEmpty() )
458 addr.setNote( note.replace ( QRegExp("\\\\n") , "\n") );
459 else
460 addr.setNote( note );
461 //#endif
462 }
463 499
464 // ORGANIZATION 500 // ORGANIZATION
465 if ( identifier == "org" ) 501 else if ( identifier == "org" )
466 addr.setOrganization( (*lineIt).value().asString() ); 502 addr.setOrganization( (*lineIt).value().asString() );
467 503
468 // PHOTO 504 // PHOTO
469 if ( identifier == "photo" ) 505 else if ( identifier == "photo" )
470 addr.setPhoto( parsePicture( *lineIt ) ); 506 addr.setPhoto( parsePicture( *lineIt ) );
471 507
472 // PROID 508 // PROID
473 if ( identifier == "prodid" ) 509 else if ( identifier == "prodid" )
474 addr.setProductId( (*lineIt).value().asString() ); 510 addr.setProductId( (*lineIt).value().asString() );
475 511
476 // REV 512 // REV
477 if ( identifier == "rev" ) 513 else if ( identifier == "rev" )
478 addr.setRevision( parseDateTime( (*lineIt).value().asString() ) ); 514 addr.setRevision( parseDateTime( (*lineIt).value().asString() ) );
479 515
480 // ROLE 516 // ROLE
481 if ( identifier == "role" ) 517 else if ( identifier == "role" )
482 addr.setRole( (*lineIt).value().asString() ); 518 addr.setRole( (*lineIt).value().asString() );
483 519
484 // SORT-STRING 520 // SORT-STRING
485 if ( identifier == "sort-string" ) 521 else if ( identifier == "sort-string" )
486 addr.setSortString( (*lineIt).value().asString() ); 522 addr.setSortString( (*lineIt).value().asString() );
487 523
488 // SOUND 524 // SOUND
489 if ( identifier == "sound" ) 525 else if ( identifier == "sound" )
490 addr.setSound( parseSound( *lineIt ) ); 526 addr.setSound( parseSound( *lineIt ) );
491 527
492 // TEL 528 // TEL
493 if ( identifier == "tel" ) { 529 else if ( identifier == "tel" ) {
494 PhoneNumber phone; 530 PhoneNumber phone;
495 phone.setNumber( (*lineIt).value().asString() ); 531 phone.setNumber( (*lineIt).value().asString() );
496 532
497 int type = 0; 533 int type = 0;
498 534
499 QStringList types = (*lineIt).parameters( "type" ); 535 const QStringList types = (*lineIt).parameters( "type" );
500 for ( QStringList::Iterator it = types.begin(); it != types.end(); ++it ) 536 for ( QStringList::ConstIterator it = types.begin(); it != types.end(); ++it )
501 type += mPhoneTypeMap[(*it).upper()]; 537 type += mPhoneTypeMap[(*it).upper()];
502 538
503 if ( !type )
504 type = PhoneNumber::Home; // default
505
506 phone.setType( type ); 539 phone.setType( type );
507 540
508 addr.insertPhoneNumber( phone ); 541 addr.insertPhoneNumber( phone );
509 } 542 }
510 543
511 // TITLE 544 // TITLE
512 if ( identifier == "title" ) 545 else if ( identifier == "title" )
513 addr.setTitle( (*lineIt).value().asString() ); 546 addr.setTitle( (*lineIt).value().asString() );
514 547
515 // TZ 548 // TZ
516 if ( identifier == "tz" ) { 549 else if ( identifier == "tz" ) {
517 TimeZone tz; 550 TimeZone tz;
518 QString date = (*lineIt).value().asString(); 551 const QString date = (*lineIt).value().asString();
519 552
520 int hours = date.mid( 1, 2).toInt(); 553 int hours = date.mid( 1, 2).toInt();
521 int minutes = date.mid( 4, 2 ).toInt(); 554 int minutes = date.mid( 4, 2 ).toInt();
@@ -527,16 +560,16 @@ Addressee::List VCardTool::parseVCards( const QString& vcard )
527 } 560 }
528 561
529 // UID 562 // UID
530 if ( identifier == "uid" ) 563 else if ( identifier == "uid" )
531 addr.setUid( (*lineIt).value().asString() ); 564 addr.setUid( (*lineIt).value().asString() );
532 565
533 // URL 566 // URL
534 if ( identifier == "url" ) 567 else if ( identifier == "url" )
535 addr.setUrl( (*lineIt).value().asString() ); 568 addr.setUrl( KURL( (*lineIt).value().asString() ) );
536 569
537 // X- 570 // X-
538 if ( identifier.startsWith( "x-" ) ) { 571 else if ( identifier.startsWith( "x-" ) ) {
539 QString key = (*lineIt).identifier().mid( 2 ); 572 const QString key = (*lineIt).identifier().mid( 2 );
540 int dash = key.find( "-" ); 573 int dash = key.find( "-" );
541 addr.insertCustom( key.left( dash ), key.mid( dash + 1 ), (*lineIt).value().asString() ); 574 addr.insertCustom( key.left( dash ), key.mid( dash + 1 ), (*lineIt).value().asString() );
542 } 575 }
@@ -593,64 +626,44 @@ QString VCardTool::createDateTime( const QDateTime &dateTime )
593 626
594Picture VCardTool::parsePicture( const VCardLine &line ) 627Picture VCardTool::parsePicture( const VCardLine &line )
595{ 628{
596 Picture pic; 629 Picture pic;
597 630
598 QStringList params = line.parameterList(); 631 const QStringList params = line.parameterList();
599 if ( params.contains( "encoding" ) ) { 632 if ( params.findIndex( "encoding" ) != -1 ) {
600 QCString cs(line.value().asCString()); 633 QImage img;
601 QByteArray input, output; 634 img.loadFromData( line.valueBytes() );
602 input = line.value().asCString(); 635 pic.setData( img );
603 if ( line.parameter( "encoding" ).lower() == "b" ) 636 } else if ( params.findIndex( "value" ) != -1 ) {
604 KCodecs::base64Decode( input, output ); 637 if ( line.parameter( "value" ).lower() == "uri" )
605 else if ( line.parameter( "encoding" ).lower() == "quoted-printable" ) 638 pic.setUrl( line.value().asString() );
606 KCodecs::quotedPrintableDecode( input, output ); 639 }
607 640
608 qDebug("********** DECODING OKAY ************** (picture)"); 641 if ( params.findIndex( "type" ) != -1 )
609 pic.setData( QImage(output) ); 642 pic.setType( line.parameter( "type" ) );
610 643
611 } 644 return pic;
612 else if ( params.contains( "value" ) ) {
613 if ( line.parameter( "value" ).lower() == "uri" )
614 pic.setUrl( line.value().asString() );
615 }
616
617 if ( params.contains( "type" ) )
618 pic.setType( line.parameter( "type" ) );
619
620 return pic;
621} 645}
622 646
623VCardLine VCardTool::createPicture( const QString &identifier, const Picture &pic ) 647VCardLine VCardTool::createPicture( const QString &identifier, const Picture &pic )
624{ 648{
625 // LR fixed
626 VCardLine line( identifier ); 649 VCardLine line( identifier );
627 650
628 if ( pic.isIntern() ) { 651 if ( pic.isIntern() ) {
629 if ( !pic.data().isNull() ) { 652 if ( !pic.data().isNull() ) {
630#if 0
631 QByteArray input; 653 QByteArray input;
632 QDataStream s( input, IO_WriteOnly ); 654 QDataStream s( input, IO_WriteOnly );
633 s.setVersion( 4 ); 655 s.setVersion( 4 );
634 s << pic.data(); 656 s << pic.data();
635 line.setValue( input ); 657 line.setValue( input );
636#else
637 QCString input;
638 QDataStream s( input, IO_WriteOnly );
639 s.setVersion( 4 );
640 s << pic.data();
641 //QCString cs(line.value().asCString());
642 //QImage qi(cs);
643 line.setValue( input );
644#endif
645
646 line.addParameter( "encoding", "b" ); 658 line.addParameter( "encoding", "b" );
647 line.addParameter( "type", "image/png" ); 659 line.addParameter( "type", "image/png" );
648 } 660 }
649 } else if ( !pic.url().isEmpty() ) { 661 } else if ( !pic.url().isEmpty() ) {
662 QByteArray ba;
650 line.setValue( pic.url() ); 663 line.setValue( pic.url() );
651 line.addParameter( "value", "URI" ); 664 line.addParameter( "value", "URI" );
652 } 665 }
653 666
654 return line; 667 return line;
655} 668}
656 669
@@ -658,15 +671,10 @@ Sound VCardTool::parseSound( const VCardLine &line )
658{ 671{
659 Sound snd; 672 Sound snd;
660 673
661 QStringList params = line.parameterList(); 674 const QStringList params = line.parameterList();
662 if ( params.contains( "encoding" ) ) { 675 if ( params.findIndex( "encoding" ) != -1 )
663 qDebug("VCardTool::parseSound has to be verified"); 676 snd.setData( line.valueBytes() );
664//US snd.setData( line.value().asByteArray() ); 677 else if ( params.findIndex( "value" ) != -1 ) {
665//US I am not sure if this is correct
666 QCString cs(line.value().asCString());
667 snd.setData( cs );
668 }
669 else if ( params.contains( "value" ) ) {
670 if ( line.parameter( "value" ).lower() == "uri" ) 678 if ( line.parameter( "value" ).lower() == "uri" )
671 snd.setUrl( line.value().asString() ); 679 snd.setUrl( line.value().asString() );
672 } 680 }
@@ -685,14 +693,7 @@ VCardLine VCardTool::createSound( const Sound &snd )
685 693
686 if ( snd.isIntern() ) { 694 if ( snd.isIntern() ) {
687 if ( !snd.data().isEmpty() ) { 695 if ( !snd.data().isEmpty() ) {
688 qDebug("VCardTool::createSound has to be verified"); 696 line.setValue( snd.data() );
689//US line.setValue( snd.data() );
690
691//US I am not sure if this is correct
692 QCString cs(snd.data());
693 line.setValue( cs );
694
695
696 line.addParameter( "encoding", "b" ); 697 line.addParameter( "encoding", "b" );
697 // TODO: need to store sound type!!! 698 // TODO: need to store sound type!!!
698 } 699 }
@@ -708,19 +709,13 @@ Key VCardTool::parseKey( const VCardLine &line )
708{ 709{
709 Key key; 710 Key key;
710 711
711 QStringList params = line.parameterList(); 712 const QStringList params = line.parameterList();
712 if ( params.contains( "encoding" ) ) { 713 if ( params.findIndex( "encoding" ) != -1 )
713 qDebug("VCardTool::parseKey has to be verified"); 714 key.setBinaryData( line.valueBytes() );
714//US key.setBinaryData( line.value().asByteArray() );
715
716//US I am not sure if this is correct
717 QCString cs( line.value().asCString() );
718 key.setBinaryData( cs );
719 }
720 else 715 else
721 key.setTextData( line.value().asString() ); 716 key.setTextData( line.value().asString() );
722 717
723 if ( params.contains( "type" ) ) { 718 if ( params.findIndex( "type" ) != -1 ) {
724 if ( line.parameter( "type" ).lower() == "x509" ) 719 if ( line.parameter( "type" ).lower() == "x509" )
725 key.setType( Key::X509 ); 720 key.setType( Key::X509 );
726 else if ( line.parameter( "type" ).lower() == "pgp" ) 721 else if ( line.parameter( "type" ).lower() == "pgp" )
@@ -740,13 +735,7 @@ VCardLine VCardTool::createKey( const Key &key )
740 735
741 if ( key.isBinary() ) { 736 if ( key.isBinary() ) {
742 if ( !key.binaryData().isEmpty() ) { 737 if ( !key.binaryData().isEmpty() ) {
743 qDebug("VCardTool::createKey has to be verified"); 738 line.setValue( key.binaryData() );
744//US line.setValue( key.binaryData() );
745//US I am not sure if this is correct
746 QCString cs(key.binaryData());
747 line.setValue( cs );
748
749
750 line.addParameter( "encoding", "b" ); 739 line.addParameter( "encoding", "b" );
751 } 740 }
752 } else if ( !key.textData().isEmpty() ) 741 } else if ( !key.textData().isEmpty() )
@@ -796,29 +785,19 @@ Agent VCardTool::parseAgent( const VCardLine &line )
796{ 785{
797 Agent agent; 786 Agent agent;
798 787
799 QStringList params = line.parameterList(); 788 const QStringList params = line.parameterList();
800 if ( params.contains( "value" ) ) { 789 if ( params.findIndex( "value" ) != -1 ) {
801 if ( line.parameter( "value" ).lower() == "uri" ) 790 if ( line.parameter( "value" ).lower() == "uri" )
802 agent.setUrl( line.value().asString() ); 791 agent.setUrl( line.value().asString() );
803 } else { 792 } else {
804 QString str = line.value().asString(); 793 QString str = line.value().asString();
805 794 str.replace( QRegExp("\\\\n"), "\r\n" );
806//US using the old implementation instead 795 str.replace( QRegExp("\\\\N"), "\r\n" );
807 qDebug("VCardTool::parseAgent has to be verified"); 796 str.replace( QRegExp("\\\\;"), ";" );
808/*US 797 str.replace( QRegExp("\\\\:"), ":" );
809 str.replace( "\\n", "\r\n" ); 798 str.replace( QRegExp("\\\\,"), "," );
810 str.replace( "\\N", "\r\n" ); 799
811 str.replace( "\\;", ";" ); 800 const Addressee::List list = parseVCards( str );
812 str.replace( "\\:", ":" );
813 str.replace( "\\,", "," );
814*/
815 str.replace( QRegExp("\\\\n") , "\r\n" );
816 str.replace( QRegExp("\\\\N") , "\r\n" );
817 str.replace( QRegExp("\\\\;") , ";" );
818 str.replace( QRegExp("\\\\:") , ":" );
819 str.replace( QRegExp("\\\\,") , "," );
820
821 Addressee::List list = parseVCards( str );
822 if ( list.count() > 0 ) { 801 if ( list.count() > 0 ) {
823 Addressee *addr = new Addressee; 802 Addressee *addr = new Addressee;
824 *addr = list[ 0 ]; 803 *addr = list[ 0 ];
@@ -839,16 +818,7 @@ VCardLine VCardTool::createAgent( VCard::Version version, const Agent &agent )
839 list.append( *agent.addressee() ); 818 list.append( *agent.addressee() );
840 819
841 QString str = createVCards( list, version ); 820 QString str = createVCards( list, version );
842 821 str.replace( QRegExp("\\r\\n"), "\\n" );
843//US using the old implementation instead
844 qDebug("VCardTool::createAgent has to be verified");
845/*US
846 str.replace( "\r\n", "\\n" );
847 str.replace( ";", "\\;" );
848 str.replace( ":", "\\:" );
849 str.replace( ",", "\\," );
850*/
851 str.replace( QRegExp("\r\n"), "\\n" );
852 str.replace( QRegExp(";"), "\\;" ); 822 str.replace( QRegExp(";"), "\\;" );
853 str.replace( QRegExp(":"), "\\:" ); 823 str.replace( QRegExp(":"), "\\:" );
854 str.replace( QRegExp(","), "\\," ); 824 str.replace( QRegExp(","), "\\," );
@@ -883,7 +853,7 @@ QStringList VCardTool::splitString( const QChar &sep, const QString &str )
883 if ( pos != 0 ) { 853 if ( pos != 0 ) {
884 value.replace( pos - 1, 2, sep ); 854 value.replace( pos - 1, 2, sep );
885 pos = value.find( sep, pos ); 855 pos = value.find( sep, pos );
886 } else 856 } else
887 pos = value.find( sep, pos + 1 ); 857 pos = value.find( sep, pos + 1 );
888 } 858 }
889 } 859 }