summaryrefslogtreecommitdiffabout
Unidiff
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--kabc/vcard/ContentLine.cpp1
-rw-r--r--kabc/vcardformatimpl.cpp8
-rw-r--r--kabc/vcardparser/vcardparser.cpp2
-rw-r--r--kabc/vcardparser/vcardtool.cpp10
4 files changed, 11 insertions, 10 deletions
diff --git a/kabc/vcard/ContentLine.cpp b/kabc/vcard/ContentLine.cpp
index f7e04a9..c368172 100644
--- a/kabc/vcard/ContentLine.cpp
+++ b/kabc/vcard/ContentLine.cpp
@@ -1,320 +1,321 @@
1/* 1/*
2 libvcard - vCard parsing library for vCard version 3.0 2 libvcard - vCard parsing library for vCard version 3.0
3 3
4 Copyright (C) 1999 Rik Hemsley rik@kde.org 4 Copyright (C) 1999 Rik Hemsley rik@kde.org
5 5
6 Permission is hereby granted, free of charge, to any person obtaining a copy 6 Permission is hereby granted, free of charge, to any person obtaining a copy
7 of this software and associated documentation files (the "Software"), to 7 of this software and associated documentation files (the "Software"), to
8 deal in the Software without restriction, including without limitation the 8 deal in the Software without restriction, including without limitation the
9 rights to use, copy, modify, merge, publish, distribute, sublicense, and/or 9 rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
10 sell copies of the Software, and to permit persons to whom the Software is 10 sell copies of the Software, and to permit persons to whom the Software is
11 furnished to do so, subject to the following conditions: 11 furnished to do so, subject to the following conditions:
12 12
13 The above copyright notice and this permission notice shall be included in 13 The above copyright notice and this permission notice shall be included in
14 all copies or substantial portions of the Software. 14 all copies or substantial portions of the Software.
15 15
16 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19 AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN 19 AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
20 ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION 20 ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
21 WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 21 WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
22*/ 22*/
23 23
24#include <qcstring.h> 24#include <qcstring.h>
25#include <qstrlist.h> 25#include <qstrlist.h>
26#include <qregexp.h> 26#include <qregexp.h>
27 27
28#include <kdebug.h> 28#include <kdebug.h>
29 29
30#include <VCardAdrParam.h> 30#include <VCardAdrParam.h>
31#include <VCardAgentParam.h> 31#include <VCardAgentParam.h>
32#include <VCardDateParam.h> 32#include <VCardDateParam.h>
33#include <VCardEmailParam.h> 33#include <VCardEmailParam.h>
34#include <VCardImageParam.h> 34#include <VCardImageParam.h>
35#include <VCardSourceParam.h> 35#include <VCardSourceParam.h>
36#include <VCardTelParam.h> 36#include <VCardTelParam.h>
37#include <VCardTextBinParam.h> 37#include <VCardTextBinParam.h>
38#include <VCardTextParam.h> 38#include <VCardTextParam.h>
39 39
40#include <VCardAdrValue.h> 40#include <VCardAdrValue.h>
41#include <VCardAgentValue.h> 41#include <VCardAgentValue.h>
42#include <VCardDateValue.h> 42#include <VCardDateValue.h>
43#include <VCardImageValue.h> 43#include <VCardImageValue.h>
44#include <VCardTextValue.h> 44#include <VCardTextValue.h>
45#include <VCardTextBinValue.h> 45#include <VCardTextBinValue.h>
46#include <VCardLangValue.h> 46#include <VCardLangValue.h>
47#include <VCardNValue.h> 47#include <VCardNValue.h>
48#include <VCardURIValue.h> 48#include <VCardURIValue.h>
49#include <VCardSoundValue.h> 49#include <VCardSoundValue.h>
50#include <VCardClassValue.h> 50#include <VCardClassValue.h>
51#include <VCardFloatValue.h> 51#include <VCardFloatValue.h>
52#include <VCardOrgValue.h> 52#include <VCardOrgValue.h>
53#include <VCardTelValue.h> 53#include <VCardTelValue.h>
54#include <VCardTextListValue.h> 54#include <VCardTextListValue.h>
55#include <VCardUTCValue.h> 55#include <VCardUTCValue.h>
56#include <VCardGeoValue.h> 56#include <VCardGeoValue.h>
57 57
58#include <VCardRToken.h> 58#include <VCardRToken.h>
59#include <VCardContentLine.h> 59#include <VCardContentLine.h>
60 60
61#include <VCardEntity.h> 61#include <VCardEntity.h>
62#include <VCardEnum.h> 62#include <VCardEnum.h>
63#include <VCardDefines.h> 63#include <VCardDefines.h>
64 64
65using namespace VCARD; 65using namespace VCARD;
66 66
67ContentLine::ContentLine() 67ContentLine::ContentLine()
68 :Entity(), 68 :Entity(),
69 value_(0), 69 value_(0),
70 paramType_( ParamUnknown ), 70 paramType_( ParamUnknown ),
71 valueType_( ValueUnknown ), 71 valueType_( ValueUnknown ),
72 entityType_( EntityUnknown ) 72 entityType_( EntityUnknown )
73{ 73{
74 paramList_.setAutoDelete( TRUE ); 74 paramList_.setAutoDelete( TRUE );
75} 75}
76 76
77ContentLine::ContentLine(const ContentLine & x) 77ContentLine::ContentLine(const ContentLine & x)
78 :Entity(x), 78 :Entity(x),
79 group_ (x.group_), 79 group_ (x.group_),
80 name_ (x.name_), 80 name_ (x.name_),
81 /*US paramList_(x.paramList_),*/ 81 /*US paramList_(x.paramList_),*/
82 value_(x.value_->clone()), 82 value_(x.value_->clone()),
83 paramType_(x.paramType_), 83 paramType_(x.paramType_),
84 valueType_(x.valueType_), 84 valueType_(x.valueType_),
85 entityType_(x.entityType_) 85 entityType_(x.entityType_)
86{ 86{
87 paramList_.setAutoDelete( TRUE ); 87 paramList_.setAutoDelete( TRUE );
88 88
89 89
90 ParamListIterator it(x.paramList_); 90 ParamListIterator it(x.paramList_);
91 for (; it.current(); ++it) 91 for (; it.current(); ++it)
92 { 92 {
93 Param *p = new Param; 93 Param *p = new Param;
94 p->setName( it.current()->name() ); 94 p->setName( it.current()->name() );
95 p->setValue( it.current()->value() ); 95 p->setValue( it.current()->value() );
96 paramList_.append(p); 96 paramList_.append(p);
97 } 97 }
98 98
99} 99}
100 100
101ContentLine::ContentLine(const QCString & s) 101ContentLine::ContentLine(const QCString & s)
102 :Entity(s), 102 :Entity(s),
103 value_(0), 103 value_(0),
104 paramType_( ParamUnknown ), 104 paramType_( ParamUnknown ),
105 valueType_( ValueUnknown ), 105 valueType_( ValueUnknown ),
106 entityType_( EntityUnknown ) 106 entityType_( EntityUnknown )
107{ 107{
108 paramList_.setAutoDelete( TRUE ); 108 paramList_.setAutoDelete( TRUE );
109} 109}
110 110
111 ContentLine & 111 ContentLine &
112ContentLine::operator = (ContentLine & x) 112ContentLine::operator = (ContentLine & x)
113{ 113{
114 if (*this == x) return *this; 114 if (*this == x) return *this;
115 115
116 ParamListIterator it(x.paramList_); 116 ParamListIterator it(x.paramList_);
117 for (; it.current(); ++it) 117 for (; it.current(); ++it)
118 { 118 {
119 Param *p = new Param; 119 Param *p = new Param;
120 p->setName( it.current()->name() ); 120 p->setName( it.current()->name() );
121 p->setValue( it.current()->value() ); 121 p->setValue( it.current()->value() );
122 paramList_.append(p); 122 paramList_.append(p);
123 } 123 }
124 124
125 value_ = x.value_->clone(); 125 value_ = x.value_->clone();
126 126
127 Entity::operator = (x); 127 Entity::operator = (x);
128 return *this; 128 return *this;
129} 129}
130 130
131 ContentLine & 131 ContentLine &
132ContentLine::operator = (const QCString & s) 132ContentLine::operator = (const QCString & s)
133{ 133{
134 Entity::operator = (s); 134 Entity::operator = (s);
135 delete value_; 135 delete value_;
136 value_ = 0; 136 value_ = 0;
137 return *this; 137 return *this;
138} 138}
139 139
140 bool 140 bool
141ContentLine::operator == (ContentLine & x) 141ContentLine::operator == (ContentLine & x)
142{ 142{
143 x.parse(); 143 x.parse();
144 144
145 QPtrListIterator<Param> it(x.paramList()); 145 QPtrListIterator<Param> it(x.paramList());
146 146
147 if (!paramList_.find(it.current())) 147 if (!paramList_.find(it.current()))
148 return false; 148 return false;
149 149
150 return true; 150 return true;
151} 151}
152 152
153ContentLine::~ContentLine() 153ContentLine::~ContentLine()
154{ 154{
155 delete value_; 155 delete value_;
156 value_ = 0; 156 value_ = 0;
157} 157}
158 158
159 void 159 void
160ContentLine::_parse() 160ContentLine::_parse()
161{ 161{
162 vDebug("parse"); 162 vDebug("parse");
163 163
164 // Unqote newlines 164 // Unqote newlines
165 strRep_ = strRep_.replace( QRegExp( "\\\\n" ), "\n" ); 165 strRep_ = strRep_.replace( QRegExp( "\\\\n" ), "\n" );
166 166
167 int split = strRep_.find(':'); 167 int split = strRep_.find(':');
168 168
169 if (split == -1) { // invalid content line 169 if (split == -1) { // invalid content line
170 vDebug("No ':'"); 170 vDebug("No ':'");
171 return; 171 return;
172 } 172 }
173 173
174 QCString firstPart(strRep_.left(split)); 174 QCString firstPart(strRep_.left(split));
175 QCString valuePart(strRep_.mid(split + 1)); 175 QCString valuePart(strRep_.mid(split + 1));
176 176
177 split = firstPart.find('.'); 177 split = firstPart.find('.');
178 178
179 if (split != -1) { 179 if (split != -1) {
180 group_ = firstPart.left(split); 180 group_ = firstPart.left(split);
181 firstPart= firstPart.mid(split + 1); 181 firstPart= firstPart.mid(split + 1);
182 } 182 }
183 183
184 vDebug("Group == " + group_); 184 vDebug("Group == " + group_);
185 vDebug("firstPart == " + firstPart); 185 vDebug("firstPart == " + firstPart);
186 vDebug("valuePart == " + valuePart); 186 vDebug("valuePart == " + valuePart);
187 187
188 // Now we have the group, the name and param list together and the value. 188 // Now we have the group, the name and param list together and the value.
189 189
190 QStrList l; 190 QStrList l;
191 191
192 RTokenise(firstPart, ";", l); 192 RTokenise(firstPart, ";", l);
193 193
194 if (l.count() == 0) {// invalid - no name ! 194 if (l.count() == 0) {// invalid - no name !
195 vDebug("No name for this content line !"); 195 vDebug("No name for this content line !");
196 return; 196 return;
197 } 197 }
198 198
199 name_ = l.at(0); 199 name_ = l.at(0);
200 200
201 // Now we have the name, so the rest of 'l' is the params. 201 // Now we have the name, so the rest of 'l' is the params.
202 // Remove the name part. 202 // Remove the name part.
203 l.remove(0u); 203 l.remove(0u);
204 204
205 entityType_= EntityNameToEntityType(name_); 205 entityType_= EntityNameToEntityType(name_);
206 paramType_= EntityTypeToParamType(entityType_); 206 paramType_= EntityTypeToParamType(entityType_);
207 207
208 unsigned int i = 0; 208 unsigned int i = 0;
209 209
210 // For each parameter, create a new parameter of the correct type. 210 // For each parameter, create a new parameter of the correct type.
211 211
212 QStrListIterator it(l); 212 QStrListIterator it(l);
213 213
214 for (; it.current(); ++it, i++) { 214 for (; it.current(); ++it, i++) {
215 215
216 QCString str = *it; 216 QCString str = *it;
217 217
218 split = str.find("="); 218 split = str.find("=");
219 if (split < 0 ) { 219 if (split < 0 ) {
220 vDebug("No '=' in paramter."); 220 vDebug("No '=' in paramter.");
221 continue; 221 continue;
222 } 222 }
223 223
224 QCString paraName = str.left(split); 224 QCString paraName = str.left(split);
225 QCString paraValue = str.mid(split + 1); 225 QCString paraValue = str.mid(split + 1);
226 226
227 QStrList paraValues; 227 QStrList paraValues;
228 RTokenise(paraValue, ",", paraValues); 228 RTokenise(paraValue, ",", paraValues);
229 229
230 QStrListIterator it2( paraValues ); 230 QStrListIterator it2( paraValues );
231 231
232 for(; it2.current(); ++it2) { 232 for(; it2.current(); ++it2) {
233 233
234 Param *p = new Param; 234 Param *p = new Param;
235 p->setName( paraName ); 235 p->setName( paraName );
236 p->setValue( *it2 ); 236 p->setValue( *it2 );
237 237
238 paramList_.append(p); 238 paramList_.append(p);
239 } 239 }
240 } 240 }
241 241
242 // Create a new value of the correct type. 242 // Create a new value of the correct type.
243 243
244 valueType_ = EntityTypeToValueType(entityType_); 244 valueType_ = EntityTypeToValueType(entityType_);
245 245
246 //kdDebug(5710) << "valueType: " << valueType_ << endl; 246 //kdDebug(5710) << "valueType: " << valueType_ << endl;
247 247
248 switch (valueType_) { 248 switch (valueType_) {
249 249
250 case ValueSound: value_ = new SoundValue;break; 250 case ValueSound: value_ = new SoundValue;break;
251 case ValueAgent: value_ = new AgentValue;break; 251 case ValueAgent: value_ = new AgentValue;break;
252 case ValueAddress: value_ = new AdrValue; break; 252 case ValueAddress: value_ = new AdrValue; break;
253 case ValueTel: value_ = new TelValue; break; 253 case ValueTel: value_ = new TelValue; break;
254 case ValueTextBin: value_ = new TextBinValue;break; 254 case ValueTextBin: value_ = new TextBinValue;break;
255 case ValueOrg: value_ = new OrgValue; break; 255 case ValueOrg: value_ = new OrgValue; break;
256 case ValueN: value_ = new NValue; break; 256 case ValueN: value_ = new NValue; break;
257 case ValueUTC: value_ = new UTCValue; break; 257 case ValueUTC: value_ = new UTCValue; break;
258 case ValueURI: value_ = new URIValue; break; 258 case ValueURI: value_ = new URIValue; break;
259 case ValueClass: value_ = new ClassValue;break; 259 case ValueClass: value_ = new ClassValue;break;
260 case ValueFloat: value_ = new FloatValue;break; 260 case ValueFloat: value_ = new FloatValue;break;
261 case ValueImage: value_ = new ImageValue;break; 261 case ValueImage: value_ = new ImageValue;break;
262 case ValueDate: value_ = new DateValue; break; 262 case ValueDate: value_ = new DateValue; break;
263 case ValueTextList: value_ = new TextListValue;break; 263 case ValueTextList: value_ = new TextListValue;break;
264 case ValueGeo: value_ = new GeoValue; break; 264 case ValueGeo: value_ = new GeoValue; break;
265 case ValueText: 265 case ValueText:
266 case ValueUnknown: 266 case ValueUnknown:
267 default: value_ = new TextValue; break; 267 default: value_ = new TextValue; break;
268 } 268 }
269 269
270 *value_ = valuePart; 270 *value_ = valuePart;
271} 271}
272 272
273 void 273 void
274ContentLine::_assemble() 274ContentLine::_assemble()
275{ 275{
276 vDebug("Assemble (argl) - my name is \"" + name_ + "\""); 276 vDebug("Assemble (argl) - my name is \"" + name_ + "\"");
277 strRep_.truncate(0); 277 strRep_.truncate(0);
278 278
279 QCString line; 279 QCString line;
280 280
281 if (!group_.isEmpty()) 281 if (!group_.isEmpty())
282 line += group_ + '.'; 282 line += group_ + '.';
283 283
284 line += name_; 284 line += name_;
285 285
286 vDebug("Adding parameters"); 286 vDebug("Adding parameters");
287 ParamListIterator it(paramList_); 287 ParamListIterator it(paramList_);
288 288
289 for (; it.current(); ++it) 289 for (; it.current(); ++it)
290 line += ";" + it.current()->asString(); 290 line += ";" + it.current()->asString();
291 291
292 vDebug("Adding value"); 292 vDebug("Adding value");
293 if (value_ != 0) 293 if (value_ != 0)
294 line += ":" + value_->asString(); 294 line += ":" + value_->asString();
295 else 295 else
296 vDebug("No value"); 296 vDebug("No value");
297 297
298 // Quote newlines 298 // Quote newlines
299 line = line.replace( QRegExp( "\n" ), "\\n" ); 299 line = line.replace( QRegExp( "\n" ), "\\n" );
300 300
301 // Fold lines longer than 72 chars 301 // Fold lines longer than 72 chars
302 const int maxLen = 72; 302 const int maxLen = 72;
303 uint cursor = 0; 303 uint cursor = 0;
304 while( line.length() > ( cursor + 1 ) * maxLen ) { 304 while( line.length() > ( cursor + 1 ) * maxLen ) {
305 strRep_ += line.mid( cursor * maxLen, maxLen ); 305 strRep_ += line.mid( cursor * maxLen, maxLen );
306 strRep_ += "\r\n "; 306 strRep_ += "\r\n ";
307 ++cursor; 307 ++cursor;
308 } 308 }
309 strRep_ += line.mid( cursor * maxLen ); 309 strRep_ += line.mid( cursor * maxLen );
310 //qDebug("ContentLine::_assemble()\n%s*****", strRep_.data());
310} 311}
311 312
312 void 313 void
313ContentLine::clear() 314ContentLine::clear()
314{ 315{
315 group_.truncate(0); 316 group_.truncate(0);
316 name_.truncate(0); 317 name_.truncate(0);
317 paramList_.clear(); 318 paramList_.clear();
318 delete value_; 319 delete value_;
319 value_ = 0; 320 value_ = 0;
320} 321}
diff --git a/kabc/vcardformatimpl.cpp b/kabc/vcardformatimpl.cpp
index ede5773..c31af46 100644
--- a/kabc/vcardformatimpl.cpp
+++ b/kabc/vcardformatimpl.cpp
@@ -339,707 +339,707 @@ void VCardFormatImpl::saveAddressee( const Addressee &addressee, VCard *v, bool
339 for( it2 = phoneNumbers.begin(); it2 != phoneNumbers.end(); ++it2 ) { 339 for( it2 = phoneNumbers.begin(); it2 != phoneNumbers.end(); ++it2 ) {
340 addTelephoneValue( v, *it2 ); 340 addTelephoneValue( v, *it2 );
341 } 341 }
342 342
343 Key::List keys = addressee.keys(); 343 Key::List keys = addressee.keys();
344 Key::List::ConstIterator it6; 344 Key::List::ConstIterator it6;
345 for( it6 = keys.begin(); it6 != keys.end(); ++it6 ) { 345 for( it6 = keys.begin(); it6 != keys.end(); ++it6 ) {
346 addKeyValue( v, *it6 ); 346 addKeyValue( v, *it6 );
347 } 347 }
348 348
349 addTextValue( v, EntityCategories, addressee.categories().join(",") ); 349 addTextValue( v, EntityCategories, addressee.categories().join(",") );
350 350
351 addDateValue( v, EntityBirthday, addressee.birthday().date() ); 351 addDateValue( v, EntityBirthday, addressee.birthday().date() );
352 addDateTimeValue( v, EntityRevision, addressee.revision() ); 352 addDateTimeValue( v, EntityRevision, addressee.revision() );
353 addGeoValue( v, addressee.geo() ); 353 addGeoValue( v, addressee.geo() );
354 addUTCValue( v, addressee.timeZone() ); 354 addUTCValue( v, addressee.timeZone() );
355 355
356 addClassValue( v, addressee.secrecy() ); 356 addClassValue( v, addressee.secrecy() );
357 357
358 addPictureValue( v, EntityPhoto, addressee.photo(), addressee, intern ); 358 addPictureValue( v, EntityPhoto, addressee.photo(), addressee, intern );
359 addPictureValue( v, EntityLogo, addressee.logo(), addressee, intern ); 359 addPictureValue( v, EntityLogo, addressee.logo(), addressee, intern );
360 360
361 addAgentValue( v, addressee.agent() ); 361 addAgentValue( v, addressee.agent() );
362 362
363 addSoundValue( v, addressee.sound(), addressee, intern ); 363 addSoundValue( v, addressee.sound(), addressee, intern );
364} 364}
365 365
366void VCardFormatImpl::addCustomValue( VCard *v, const QString &txt ) 366void VCardFormatImpl::addCustomValue( VCard *v, const QString &txt )
367{ 367{
368 if ( txt.isEmpty() ) return; 368 if ( txt.isEmpty() ) return;
369 369
370 ContentLine cl; 370 ContentLine cl;
371 cl.setName( "X-" + txt.left( txt.find( ":" ) ).utf8() ); 371 cl.setName( "X-" + txt.left( txt.find( ":" ) ).utf8() );
372 QString value = txt.mid( txt.find( ":" ) + 1 ); 372 QString value = txt.mid( txt.find( ":" ) + 1 );
373 if ( value.isEmpty() ) 373 if ( value.isEmpty() )
374 return; 374 return;
375 cl.setValue( new TextValue( value.utf8() ) ); 375 cl.setValue( new TextValue( value.utf8() ) );
376 v->add(cl); 376 v->add(cl);
377} 377}
378 378
379void VCardFormatImpl::addTextValue( VCard *v, EntityType type, const QString &txt ) 379void VCardFormatImpl::addTextValue( VCard *v, EntityType type, const QString &txt )
380{ 380{
381 if ( txt.isEmpty() ) return; 381 if ( txt.isEmpty() ) return;
382 382
383 ContentLine cl; 383 ContentLine cl;
384 cl.setName( EntityTypeToParamName( type ) ); 384 cl.setName( EntityTypeToParamName( type ) );
385 cl.setValue( new TextValue( txt.utf8() ) ); 385 cl.setValue( new TextValue( txt.utf8() ) );
386 v->add(cl); 386 v->add(cl);
387} 387}
388 388
389void VCardFormatImpl::addDateValue( VCard *vcard, EntityType type, 389void VCardFormatImpl::addDateValue( VCard *vcard, EntityType type,
390 const QDate &date ) 390 const QDate &date )
391{ 391{
392 if ( !date.isValid() ) return; 392 if ( !date.isValid() ) return;
393 393
394 ContentLine cl; 394 ContentLine cl;
395 cl.setName( EntityTypeToParamName( type ) ); 395 cl.setName( EntityTypeToParamName( type ) );
396 396
397 DateValue *v = new DateValue( date ); 397 DateValue *v = new DateValue( date );
398 cl.setValue( v ); 398 cl.setValue( v );
399 vcard->add(cl); 399 vcard->add(cl);
400} 400}
401 401
402void VCardFormatImpl::addDateTimeValue( VCard *vcard, EntityType type, 402void VCardFormatImpl::addDateTimeValue( VCard *vcard, EntityType type,
403 const QDateTime &dateTime ) 403 const QDateTime &dateTime )
404{ 404{
405 if ( !dateTime.isValid() ) return; 405 if ( !dateTime.isValid() ) return;
406 406
407 ContentLine cl; 407 ContentLine cl;
408 cl.setName( EntityTypeToParamName( type ) ); 408 cl.setName( EntityTypeToParamName( type ) );
409 409
410 DateValue *v = new DateValue( dateTime ); 410 DateValue *v = new DateValue( dateTime );
411 cl.setValue( v ); 411 cl.setValue( v );
412 vcard->add(cl); 412 vcard->add(cl);
413} 413}
414 414
415void VCardFormatImpl::addAddressValue( VCard *vcard, const Address &a ) 415void VCardFormatImpl::addAddressValue( VCard *vcard, const Address &a )
416{ 416{
417 if ( a.isEmpty() ) 417 if ( a.isEmpty() )
418 return; 418 return;
419 419
420 ContentLine cl; 420 ContentLine cl;
421 cl.setName( EntityTypeToParamName( EntityAddress ) ); 421 cl.setName( EntityTypeToParamName( EntityAddress ) );
422 422
423 AdrValue *v = new AdrValue; 423 AdrValue *v = new AdrValue;
424 v->setPOBox( a.postOfficeBox().utf8() ); 424 v->setPOBox( a.postOfficeBox().utf8() );
425 v->setExtAddress( a.extended().utf8() ); 425 v->setExtAddress( a.extended().utf8() );
426 v->setStreet( a.street().utf8() ); 426 v->setStreet( a.street().utf8() );
427 v->setLocality( a.locality().utf8() ); 427 v->setLocality( a.locality().utf8() );
428 v->setRegion( a.region().utf8() ); 428 v->setRegion( a.region().utf8() );
429 v->setPostCode( a.postalCode().utf8() ); 429 v->setPostCode( a.postalCode().utf8() );
430 v->setCountryName( a.country().utf8() ); 430 v->setCountryName( a.country().utf8() );
431 cl.setValue( v ); 431 cl.setValue( v );
432 432
433 addAddressParam( &cl, a.type() ); 433 addAddressParam( &cl, a.type() );
434 434
435 vcard->add( cl ); 435 vcard->add( cl );
436} 436}
437 437
438void VCardFormatImpl::addLabelValue( VCard *vcard, const Address &a ) 438void VCardFormatImpl::addLabelValue( VCard *vcard, const Address &a )
439{ 439{
440 if ( a.label().isEmpty() ) return; 440 if ( a.label().isEmpty() ) return;
441 441
442 ContentLine cl; 442 ContentLine cl;
443 cl.setName( EntityTypeToParamName( EntityLabel ) ); 443 cl.setName( EntityTypeToParamName( EntityLabel ) );
444 cl.setValue( new TextValue( a.label().utf8() ) ); 444 cl.setValue( new TextValue( a.label().utf8() ) );
445 445
446 addAddressParam( &cl, a.type() ); 446 addAddressParam( &cl, a.type() );
447 447
448 vcard->add( cl ); 448 vcard->add( cl );
449} 449}
450 450
451void VCardFormatImpl::addAddressParam( ContentLine *cl, int type ) 451void VCardFormatImpl::addAddressParam( ContentLine *cl, int type )
452{ 452{
453 ParamList params; 453 ParamList params;
454 if ( type & Address::Dom ) params.append( new Param( "TYPE", "dom" ) ); 454 if ( type & Address::Dom ) params.append( new Param( "TYPE", "dom" ) );
455 if ( type & Address::Intl ) params.append( new Param( "TYPE", "intl" ) ); 455 if ( type & Address::Intl ) params.append( new Param( "TYPE", "intl" ) );
456 if ( type & Address::Parcel ) params.append( new Param( "TYPE", "parcel" ) ); 456 if ( type & Address::Parcel ) params.append( new Param( "TYPE", "parcel" ) );
457 if ( type & Address::Postal ) params.append( new Param( "TYPE", "postal" ) ); 457 if ( type & Address::Postal ) params.append( new Param( "TYPE", "postal" ) );
458 if ( type & Address::Work ) params.append( new Param( "TYPE", "work" ) ); 458 if ( type & Address::Work ) params.append( new Param( "TYPE", "work" ) );
459 if ( type & Address::Home ) params.append( new Param( "TYPE", "home" ) ); 459 if ( type & Address::Home ) params.append( new Param( "TYPE", "home" ) );
460 if ( type & Address::Pref ) params.append( new Param( "TYPE", "pref" ) ); 460 if ( type & Address::Pref ) params.append( new Param( "TYPE", "pref" ) );
461 cl->setParamList( params ); 461 cl->setParamList( params );
462} 462}
463 463
464void VCardFormatImpl::addGeoValue( VCard *vcard, const Geo &geo ) 464void VCardFormatImpl::addGeoValue( VCard *vcard, const Geo &geo )
465{ 465{
466 if ( !geo.isValid() ) return; 466 if ( !geo.isValid() ) return;
467 467
468 ContentLine cl; 468 ContentLine cl;
469 cl.setName( EntityTypeToParamName( EntityGeo ) ); 469 cl.setName( EntityTypeToParamName( EntityGeo ) );
470 470
471 GeoValue *v = new GeoValue; 471 GeoValue *v = new GeoValue;
472 v->setLatitude( geo.latitude() ); 472 v->setLatitude( geo.latitude() );
473 v->setLongitude( geo.longitude() ); 473 v->setLongitude( geo.longitude() );
474 474
475 cl.setValue( v ); 475 cl.setValue( v );
476 vcard->add(cl); 476 vcard->add(cl);
477} 477}
478 478
479void VCardFormatImpl::addUTCValue( VCard *vcard, const TimeZone &tz ) 479void VCardFormatImpl::addUTCValue( VCard *vcard, const TimeZone &tz )
480{ 480{
481 if ( !tz.isValid() ) return; 481 if ( !tz.isValid() ) return;
482 482
483 ContentLine cl; 483 ContentLine cl;
484 cl.setName( EntityTypeToParamName( EntityTimeZone ) ); 484 cl.setName( EntityTypeToParamName( EntityTimeZone ) );
485 485
486 UTCValue *v = new UTCValue; 486 UTCValue *v = new UTCValue;
487 487
488 v->setPositive( tz.offset() >= 0 ); 488 v->setPositive( tz.offset() >= 0 );
489 v->setHour( (tz.offset() / 60) * ( tz.offset() >= 0 ? 1 : -1 ) ); 489 v->setHour( (tz.offset() / 60) * ( tz.offset() >= 0 ? 1 : -1 ) );
490 v->setMinute( (tz.offset() % 60) * ( tz.offset() >= 0 ? 1 : -1 ) ); 490 v->setMinute( (tz.offset() % 60) * ( tz.offset() >= 0 ? 1 : -1 ) );
491 491
492 cl.setValue( v ); 492 cl.setValue( v );
493 vcard->add(cl); 493 vcard->add(cl);
494} 494}
495 495
496void VCardFormatImpl::addClassValue( VCard *vcard, const Secrecy &secrecy ) 496void VCardFormatImpl::addClassValue( VCard *vcard, const Secrecy &secrecy )
497{ 497{
498 ContentLine cl; 498 ContentLine cl;
499 cl.setName( EntityTypeToParamName( EntityClass ) ); 499 cl.setName( EntityTypeToParamName( EntityClass ) );
500 500
501 ClassValue *v = new ClassValue; 501 ClassValue *v = new ClassValue;
502 switch ( secrecy.type() ) { 502 switch ( secrecy.type() ) {
503 case Secrecy::Public: 503 case Secrecy::Public:
504 v->setType( (int)ClassValue::Public ); 504 v->setType( (int)ClassValue::Public );
505 break; 505 break;
506 case Secrecy::Private: 506 case Secrecy::Private:
507 v->setType( (int)ClassValue::Private ); 507 v->setType( (int)ClassValue::Private );
508 break; 508 break;
509 case Secrecy::Confidential: 509 case Secrecy::Confidential:
510 v->setType( (int)ClassValue::Confidential ); 510 v->setType( (int)ClassValue::Confidential );
511 break; 511 break;
512 } 512 }
513 513
514 cl.setValue( v ); 514 cl.setValue( v );
515 vcard->add(cl); 515 vcard->add(cl);
516} 516}
517 517
518 518
519Address VCardFormatImpl::readAddressValue( ContentLine *cl ) 519Address VCardFormatImpl::readAddressValue( ContentLine *cl )
520{ 520{
521 Address a; 521 Address a;
522 AdrValue *v = (AdrValue *)cl->value(); 522 AdrValue *v = (AdrValue *)cl->value();
523 a.setPostOfficeBox( QString::fromUtf8( v->poBox() ) ); 523 a.setPostOfficeBox( QString::fromUtf8( v->poBox() ) );
524 a.setExtended( QString::fromUtf8( v->extAddress() ) ); 524 a.setExtended( QString::fromUtf8( v->extAddress() ) );
525 a.setStreet( QString::fromUtf8( v->street() ) ); 525 a.setStreet( QString::fromUtf8( v->street() ) );
526 a.setLocality( QString::fromUtf8( v->locality() ) ); 526 a.setLocality( QString::fromUtf8( v->locality() ) );
527 a.setRegion( QString::fromUtf8( v->region() ) ); 527 a.setRegion( QString::fromUtf8( v->region() ) );
528 a.setPostalCode( QString::fromUtf8( v->postCode() ) ); 528 a.setPostalCode( QString::fromUtf8( v->postCode() ) );
529 a.setCountry( QString::fromUtf8( v->countryName() ) ); 529 a.setCountry( QString::fromUtf8( v->countryName() ) );
530 530
531 a.setType( readAddressParam( cl ) ); 531 a.setType( readAddressParam( cl ) );
532 532
533 return a; 533 return a;
534} 534}
535 535
536int VCardFormatImpl::readAddressParam( ContentLine *cl ) 536int VCardFormatImpl::readAddressParam( ContentLine *cl )
537{ 537{
538 int type = 0; 538 int type = 0;
539 ParamList params = cl->paramList(); 539 ParamList params = cl->paramList();
540 ParamListIterator it( params ); 540 ParamListIterator it( params );
541 QCString tmpStr; 541 QCString tmpStr;
542 for( ; it.current(); ++it ) { 542 for( ; it.current(); ++it ) {
543 if ( (*it)->name().upper() == "TYPE" ) { 543 if ( (*it)->name().upper() == "TYPE" ) {
544 tmpStr = (*it)->value().lower(); 544 tmpStr = (*it)->value().lower();
545 if ( tmpStr == "dom" ) type |= Address::Dom; 545 if ( tmpStr == "dom" ) type |= Address::Dom;
546 else if ( tmpStr == "intl" ) type |= Address::Intl; 546 else if ( tmpStr == "intl" ) type |= Address::Intl;
547 else if ( tmpStr == "parcel" ) type |= Address::Parcel; 547 else if ( tmpStr == "parcel" ) type |= Address::Parcel;
548 else if ( tmpStr == "postal" ) type |= Address::Postal; 548 else if ( tmpStr == "postal" ) type |= Address::Postal;
549 else if ( tmpStr == "work" ) type |= Address::Work; 549 else if ( tmpStr == "work" ) type |= Address::Work;
550 else if ( tmpStr == "home" ) type |= Address::Home; 550 else if ( tmpStr == "home" ) type |= Address::Home;
551 else if ( tmpStr == "pref" ) type |= Address::Pref; 551 else if ( tmpStr == "pref" ) type |= Address::Pref;
552 } 552 }
553 } 553 }
554 return type; 554 return type;
555} 555}
556 556
557void VCardFormatImpl::addNValue( VCard *vcard, const Addressee &a ) 557void VCardFormatImpl::addNValue( VCard *vcard, const Addressee &a )
558{ 558{
559 ContentLine cl; 559 ContentLine cl;
560 cl.setName(EntityTypeToParamName( EntityN ) ); 560 cl.setName(EntityTypeToParamName( EntityN ) );
561 NValue *v = new NValue; 561 NValue *v = new NValue;
562 v->setFamily( a.familyName().utf8() ); 562 v->setFamily( a.familyName().utf8() );
563 v->setGiven( a.givenName().utf8() ); 563 v->setGiven( a.givenName().utf8() );
564 v->setMiddle( a.additionalName().utf8() ); 564 v->setMiddle( a.additionalName().utf8() );
565 v->setPrefix( a.prefix().utf8() ); 565 v->setPrefix( a.prefix().utf8() );
566 v->setSuffix( a.suffix().utf8() ); 566 v->setSuffix( a.suffix().utf8() );
567 567
568 cl.setValue( v ); 568 cl.setValue( v );
569 vcard->add(cl); 569 vcard->add(cl);
570} 570}
571 571
572void VCardFormatImpl::readNValue( ContentLine *cl, Addressee &a ) 572void VCardFormatImpl::readNValue( ContentLine *cl, Addressee &a )
573{ 573{
574 NValue *v = (NValue *)cl->value(); 574 NValue *v = (NValue *)cl->value();
575 a.setFamilyName( QString::fromUtf8( v->family() ) ); 575 a.setFamilyName( QString::fromUtf8( v->family() ) );
576 a.setGivenName( QString::fromUtf8( v->given() ) ); 576 a.setGivenName( QString::fromUtf8( v->given() ) );
577 a.setAdditionalName( QString::fromUtf8( v->middle() ) ); 577 a.setAdditionalName( QString::fromUtf8( v->middle() ) );
578 a.setPrefix( QString::fromUtf8( v->prefix() ) ); 578 a.setPrefix( QString::fromUtf8( v->prefix() ) );
579 a.setSuffix( QString::fromUtf8( v->suffix() ) ); 579 a.setSuffix( QString::fromUtf8( v->suffix() ) );
580} 580}
581 581
582void VCardFormatImpl::addTelephoneValue( VCard *v, const PhoneNumber &p ) 582void VCardFormatImpl::addTelephoneValue( VCard *v, const PhoneNumber &p )
583{ 583{
584 if ( p.number().isEmpty() ) 584 if ( p.number().isEmpty() )
585 return; 585 return;
586 586
587 ContentLine cl; 587 ContentLine cl;
588 cl.setName(EntityTypeToParamName(EntityTelephone)); 588 cl.setName(EntityTypeToParamName(EntityTelephone));
589 cl.setValue(new TelValue( p.number().utf8() )); 589 cl.setValue(new TelValue( p.number().utf8() ));
590 590
591 ParamList params; 591 ParamList params;
592 if( p.type() & PhoneNumber::Home ) params.append( new Param( "TYPE", "home" ) ); 592 if( p.type() & PhoneNumber::Home ) params.append( new Param( "TYPE", "home" ) );
593 if( p.type() & PhoneNumber::Work ) params.append( new Param( "TYPE", "work" ) ); 593 if( p.type() & PhoneNumber::Work ) params.append( new Param( "TYPE", "work" ) );
594 if( p.type() & PhoneNumber::Msg ) params.append( new Param( "TYPE", "msg" ) ); 594 if( p.type() & PhoneNumber::Msg ) params.append( new Param( "TYPE", "msg" ) );
595 if( p.type() & PhoneNumber::Pref ) params.append( new Param( "TYPE", "pref" ) ); 595 if( p.type() & PhoneNumber::Pref ) params.append( new Param( "TYPE", "pref" ) );
596 if( p.type() & PhoneNumber::Voice ) params.append( new Param( "TYPE", "voice" ) ); 596 if( p.type() & PhoneNumber::Voice ) params.append( new Param( "TYPE", "voice" ) );
597 if( p.type() & PhoneNumber::Fax ) params.append( new Param( "TYPE", "fax" ) ); 597 if( p.type() & PhoneNumber::Fax ) params.append( new Param( "TYPE", "fax" ) );
598 if( p.type() & PhoneNumber::Cell ) params.append( new Param( "TYPE", "cell" ) ); 598 if( p.type() & PhoneNumber::Cell ) params.append( new Param( "TYPE", "cell" ) );
599 if( p.type() & PhoneNumber::Video ) params.append( new Param( "TYPE", "video" ) ); 599 if( p.type() & PhoneNumber::Video ) params.append( new Param( "TYPE", "video" ) );
600 if( p.type() & PhoneNumber::Bbs ) params.append( new Param( "TYPE", "bbs" ) ); 600 if( p.type() & PhoneNumber::Bbs ) params.append( new Param( "TYPE", "bbs" ) );
601 if( p.type() & PhoneNumber::Modem ) params.append( new Param( "TYPE", "modem" ) ); 601 if( p.type() & PhoneNumber::Modem ) params.append( new Param( "TYPE", "modem" ) );
602 if( p.type() & PhoneNumber::Car ) params.append( new Param( "TYPE", "car" ) ); 602 if( p.type() & PhoneNumber::Car ) params.append( new Param( "TYPE", "car" ) );
603 if( p.type() & PhoneNumber::Isdn ) params.append( new Param( "TYPE", "isdn" ) ); 603 if( p.type() & PhoneNumber::Isdn ) params.append( new Param( "TYPE", "isdn" ) );
604 if( p.type() & PhoneNumber::Pcs ) params.append( new Param( "TYPE", "pcs" ) ); 604 if( p.type() & PhoneNumber::Pcs ) params.append( new Param( "TYPE", "pcs" ) );
605 if( p.type() & PhoneNumber::Pager ) params.append( new Param( "TYPE", "pager" ) ); 605 if( p.type() & PhoneNumber::Pager ) params.append( new Param( "TYPE", "pager" ) );
606 if( p.type() & PhoneNumber::Sip ) params.append( new Param( "TYPE", "sip" ) ); 606 if( p.type() & PhoneNumber::Sip ) params.append( new Param( "TYPE", "sip" ) );
607 cl.setParamList( params ); 607 cl.setParamList( params );
608 608
609 v->add(cl); 609 v->add(cl);
610} 610}
611 611
612PhoneNumber VCardFormatImpl::readTelephoneValue( ContentLine *cl ) 612PhoneNumber VCardFormatImpl::readTelephoneValue( ContentLine *cl )
613{ 613{
614 PhoneNumber p; 614 PhoneNumber p;
615 TelValue *value = (TelValue *)cl->value(); 615 TelValue *value = (TelValue *)cl->value();
616 p.setNumber( QString::fromUtf8( value->asString() ) ); 616 p.setNumber( QString::fromUtf8( value->asString() ) );
617 617
618 int type = 0; 618 int type = 0;
619 ParamList params = cl->paramList(); 619 ParamList params = cl->paramList();
620 ParamListIterator it( params ); 620 ParamListIterator it( params );
621 QCString tmpStr; 621 QCString tmpStr;
622 for( ; it.current(); ++it ) { 622 for( ; it.current(); ++it ) {
623 if ( (*it)->name() == "TYPE" ) { 623 if ( (*it)->name() == "TYPE" ) {
624 tmpStr = (*it)->value().lower(); 624 tmpStr = (*it)->value().lower();
625 if ( tmpStr == "home" ) type |= PhoneNumber::Home; 625 if ( tmpStr == "home" ) type |= PhoneNumber::Home;
626 else if ( tmpStr == "work" ) type |= PhoneNumber::Work; 626 else if ( tmpStr == "work" ) type |= PhoneNumber::Work;
627 else if ( tmpStr == "msg" ) type |= PhoneNumber::Msg; 627 else if ( tmpStr == "msg" ) type |= PhoneNumber::Msg;
628 else if ( tmpStr == "pref" ) type |= PhoneNumber::Pref; 628 else if ( tmpStr == "pref" ) type |= PhoneNumber::Pref;
629 else if ( tmpStr == "voice" ) type |= PhoneNumber::Voice; 629 else if ( tmpStr == "voice" ) type |= PhoneNumber::Voice;
630 else if ( tmpStr == "fax" ) type |= PhoneNumber::Fax; 630 else if ( tmpStr == "fax" ) type |= PhoneNumber::Fax;
631 else if ( tmpStr == "cell" ) type |= PhoneNumber::Cell; 631 else if ( tmpStr == "cell" ) type |= PhoneNumber::Cell;
632 else if ( tmpStr == "video" ) type |= PhoneNumber::Video; 632 else if ( tmpStr == "video" ) type |= PhoneNumber::Video;
633 else if ( tmpStr == "bbs" ) type |= PhoneNumber::Bbs; 633 else if ( tmpStr == "bbs" ) type |= PhoneNumber::Bbs;
634 else if ( tmpStr == "modem" ) type |= PhoneNumber::Modem; 634 else if ( tmpStr == "modem" ) type |= PhoneNumber::Modem;
635 else if ( tmpStr == "car" ) type |= PhoneNumber::Car; 635 else if ( tmpStr == "car" ) type |= PhoneNumber::Car;
636 else if ( tmpStr == "isdn" ) type |= PhoneNumber::Isdn; 636 else if ( tmpStr == "isdn" ) type |= PhoneNumber::Isdn;
637 else if ( tmpStr == "pcs" ) type |= PhoneNumber::Pcs; 637 else if ( tmpStr == "pcs" ) type |= PhoneNumber::Pcs;
638 else if ( tmpStr == "pager" ) type |= PhoneNumber::Pager; 638 else if ( tmpStr == "pager" ) type |= PhoneNumber::Pager;
639 else if ( tmpStr == "sip" ) type |= PhoneNumber::Sip; 639 else if ( tmpStr == "sip" ) type |= PhoneNumber::Sip;
640 } 640 }
641 } 641 }
642 p.setType( type ); 642 p.setType( type );
643 643
644 return p; 644 return p;
645} 645}
646 646
647QString VCardFormatImpl::readTextValue( ContentLine *cl ) 647QString VCardFormatImpl::readTextValue( ContentLine *cl )
648{ 648{
649 VCARD::Value *value = cl->value(); 649 VCARD::Value *value = cl->value();
650 if ( value ) { 650 if ( value ) {
651 return QString::fromUtf8( value->asString() ); 651 return QString::fromUtf8( value->asString() );
652 } else { 652 } else {
653 kdDebug(5700) << "No value: " << cl->asString() << endl; 653 kdDebug(5700) << "No value: " << cl->asString() << endl;
654 qDebug("No value: %s", (const char*)(cl->asString())); 654 qDebug("No value: %s", (const char*)(cl->asString()));
655 return QString::null; 655 return QString::null;
656 } 656 }
657} 657}
658 658
659QDate VCardFormatImpl::readDateValue( ContentLine *cl ) 659QDate VCardFormatImpl::readDateValue( ContentLine *cl )
660{ 660{
661 DateValue *dateValue = (DateValue *)cl->value(); 661 DateValue *dateValue = (DateValue *)cl->value();
662 if ( dateValue ) 662 if ( dateValue )
663 return dateValue->qdate(); 663 return dateValue->qdate();
664 else 664 else
665 return QDate(); 665 return QDate();
666} 666}
667 667
668QDateTime VCardFormatImpl::readDateTimeValue( ContentLine *cl ) 668QDateTime VCardFormatImpl::readDateTimeValue( ContentLine *cl )
669{ 669{
670 DateValue *dateValue = (DateValue *)cl->value(); 670 DateValue *dateValue = (DateValue *)cl->value();
671 if ( dateValue ) 671 if ( dateValue )
672 return dateValue->qdt(); 672 return dateValue->qdt();
673 else 673 else
674 return QDateTime(); 674 return QDateTime();
675} 675}
676 676
677Geo VCardFormatImpl::readGeoValue( ContentLine *cl ) 677Geo VCardFormatImpl::readGeoValue( ContentLine *cl )
678{ 678{
679 GeoValue *geoValue = (GeoValue *)cl->value(); 679 GeoValue *geoValue = (GeoValue *)cl->value();
680 if ( geoValue ) { 680 if ( geoValue ) {
681 Geo geo( geoValue->latitude(), geoValue->longitude() ); 681 Geo geo( geoValue->latitude(), geoValue->longitude() );
682 return geo; 682 return geo;
683 } else 683 } else
684 return Geo(); 684 return Geo();
685} 685}
686 686
687TimeZone VCardFormatImpl::readUTCValue( ContentLine *cl ) 687TimeZone VCardFormatImpl::readUTCValue( ContentLine *cl )
688{ 688{
689 UTCValue *utcValue = (UTCValue *)cl->value(); 689 UTCValue *utcValue = (UTCValue *)cl->value();
690 if ( utcValue ) { 690 if ( utcValue ) {
691 TimeZone tz; 691 TimeZone tz;
692 tz.setOffset(((utcValue->hour()*60)+utcValue->minute())*(utcValue->positive() ? 1 : -1)); 692 tz.setOffset(((utcValue->hour()*60)+utcValue->minute())*(utcValue->positive() ? 1 : -1));
693 return tz; 693 return tz;
694 } else 694 } else
695 return TimeZone(); 695 return TimeZone();
696} 696}
697 697
698Secrecy VCardFormatImpl::readClassValue( ContentLine *cl ) 698Secrecy VCardFormatImpl::readClassValue( ContentLine *cl )
699{ 699{
700 ClassValue *classValue = (ClassValue *)cl->value(); 700 ClassValue *classValue = (ClassValue *)cl->value();
701 if ( classValue ) { 701 if ( classValue ) {
702 Secrecy secrecy; 702 Secrecy secrecy;
703 switch ( classValue->type() ) { 703 switch ( classValue->type() ) {
704 case ClassValue::Public: 704 case ClassValue::Public:
705 secrecy.setType( Secrecy::Public ); 705 secrecy.setType( Secrecy::Public );
706 break; 706 break;
707 case ClassValue::Private: 707 case ClassValue::Private:
708 secrecy.setType( Secrecy::Private ); 708 secrecy.setType( Secrecy::Private );
709 break; 709 break;
710 case ClassValue::Confidential: 710 case ClassValue::Confidential:
711 secrecy.setType( Secrecy::Confidential ); 711 secrecy.setType( Secrecy::Confidential );
712 break; 712 break;
713 } 713 }
714 714
715 return secrecy; 715 return secrecy;
716 } else 716 } else
717 return Secrecy(); 717 return Secrecy();
718} 718}
719 719
720void VCardFormatImpl::addKeyValue( VCARD::VCard *vcard, const Key &key ) 720void VCardFormatImpl::addKeyValue( VCARD::VCard *vcard, const Key &key )
721{ 721{
722 ContentLine cl; 722 ContentLine cl;
723 cl.setName( EntityTypeToParamName( EntityKey ) ); 723 cl.setName( EntityTypeToParamName( EntityKey ) );
724 724
725 ParamList params; 725 ParamList params;
726 if ( key.isBinary() ) { 726 if ( key.isBinary() ) {
727 cl.setValue( new TextValue( KCodecs::base64Encode( key.binaryData() ) ) ); 727 cl.setValue( new TextValue( KCodecs::base64Encode( key.binaryData() ) ) );
728 params.append( new Param( "ENCODING", "b" ) ); 728 params.append( new Param( "ENCODING", "b" ) );
729 } else { 729 } else {
730 cl.setValue( new TextValue( key.textData().utf8() ) ); 730 cl.setValue( new TextValue( key.textData().utf8() ) );
731 } 731 }
732 732
733 switch ( key.type() ) { 733 switch ( key.type() ) {
734 case Key::X509: 734 case Key::X509:
735 params.append( new Param( "TYPE", "X509" ) ); 735 params.append( new Param( "TYPE", "X509" ) );
736 break; 736 break;
737 case Key::PGP: 737 case Key::PGP:
738 params.append( new Param( "TYPE", "PGP" ) ); 738 params.append( new Param( "TYPE", "PGP" ) );
739 break; 739 break;
740 case Key::Custom: 740 case Key::Custom:
741 params.append( new Param( "TYPE", key.customTypeString().utf8() ) ); 741 params.append( new Param( "TYPE", key.customTypeString().utf8() ) );
742 break; 742 break;
743 } 743 }
744 744
745 cl.setParamList( params ); 745 cl.setParamList( params );
746 vcard->add( cl ); 746 vcard->add( cl );
747} 747}
748 748
749Key VCardFormatImpl::readKeyValue( VCARD::ContentLine *cl ) 749Key VCardFormatImpl::readKeyValue( VCARD::ContentLine *cl )
750{ 750{
751 Key key; 751 Key key;
752 bool isBinary = false; 752 bool isBinary = false;
753 TextValue *v = (TextValue *)cl->value(); 753 TextValue *v = (TextValue *)cl->value();
754 754
755 ParamList params = cl->paramList(); 755 ParamList params = cl->paramList();
756 ParamListIterator it( params ); 756 ParamListIterator it( params );
757 for( ; it.current(); ++it ) { 757 for( ; it.current(); ++it ) {
758 if ( (*it)->name() == "ENCODING" && (*it)->value() == "b" ) 758 if ( (*it)->name() == "ENCODING" && (*it)->value() == "b" )
759 isBinary = true; 759 isBinary = true;
760 if ( (*it)->name() == "TYPE" ) { 760 if ( (*it)->name() == "TYPE" ) {
761 if ( (*it)->value().isEmpty() ) 761 if ( (*it)->value().isEmpty() )
762 continue; 762 continue;
763 if ( (*it)->value() == "X509" ) 763 if ( (*it)->value() == "X509" )
764 key.setType( Key::X509 ); 764 key.setType( Key::X509 );
765 else if ( (*it)->value() == "PGP" ) 765 else if ( (*it)->value() == "PGP" )
766 key.setType( Key::PGP ); 766 key.setType( Key::PGP );
767 else { 767 else {
768 key.setType( Key::Custom ); 768 key.setType( Key::Custom );
769 key.setCustomTypeString( QString::fromUtf8( (*it)->value() ) ); 769 key.setCustomTypeString( QString::fromUtf8( (*it)->value() ) );
770 } 770 }
771 } 771 }
772 } 772 }
773 773
774 774
775 if ( isBinary ) { 775 if ( isBinary ) {
776 QByteArray data; 776 QByteArray data;
777 KCodecs::base64Decode( v->asString().stripWhiteSpace(), data ); 777 KCodecs::base64Decode( v->asString().stripWhiteSpace(), data );
778 key.setBinaryData( data ); 778 key.setBinaryData( data );
779 } else { 779 } else {
780 key.setTextData( QString::fromUtf8( v->asString() ) ); 780 key.setTextData( QString::fromUtf8( v->asString() ) );
781 } 781 }
782 782
783 return key; 783 return key;
784} 784}
785 785
786 786
787void VCardFormatImpl::addAgentValue( VCARD::VCard *vcard, const Agent &agent ) 787void VCardFormatImpl::addAgentValue( VCARD::VCard *vcard, const Agent &agent )
788{ 788{
789 if ( agent.isIntern() && !agent.addressee() ) 789 if ( agent.isIntern() && !agent.addressee() )
790 return; 790 return;
791 791
792 if ( !agent.isIntern() && agent.url().isEmpty() ) 792 if ( !agent.isIntern() && agent.url().isEmpty() )
793 return; 793 return;
794 794
795 ContentLine cl; 795 ContentLine cl;
796 cl.setName( EntityTypeToParamName( EntityAgent ) ); 796 cl.setName( EntityTypeToParamName( EntityAgent ) );
797 797
798 ParamList params; 798 ParamList params;
799 if ( agent.isIntern() ) { 799 if ( agent.isIntern() ) {
800 QString vstr; 800 QString vstr;
801 Addressee *addr = agent.addressee(); 801 Addressee *addr = agent.addressee();
802 if ( addr ) { 802 if ( addr ) {
803 writeToString( (*addr), vstr ); 803 writeToString( (*addr), vstr );
804 804
805 qDebug("VCardFormatImpl::addAgentValue please verify if replace is correct"); 805 qDebug("VCardFormatImpl::addAgentValue please verify if replace is correct");
806/*US 806/*US
807 vstr.replace( ":", "\\:" ); 807 vstr.replace( ":", "\\:" );
808 vstr.replace( ",", "\\," ); 808 vstr.replace( ",", "\\," );
809 vstr.replace( ";", "\\;" ); 809 vstr.replace( ";", "\\;" );
810 vstr.replace( "\r\n", "\\n" ); 810 vstr.replace( "\r\n", "\\n" );
811*/ 811*/
812 vstr.replace( QRegExp(":"), "\\:" ); 812 vstr.replace( QRegExp(":"), "\\:" );
813 vstr.replace( QRegExp(","), "\\," ); 813 vstr.replace( QRegExp(","), "\\," );
814 vstr.replace( QRegExp(";"), "\\;" ); 814 vstr.replace( QRegExp(";"), "\\;" );
815 vstr.replace( QRegExp("\r\n"), "\\n" ); 815 vstr.replace( QRegExp("\r\n"), "\\n" );
816 816
817 cl.setValue( new TextValue( vstr.utf8() ) ); 817 cl.setValue( new TextValue( vstr.utf8() ) );
818 } else 818 } else
819 return; 819 return;
820 } else { 820 } else {
821 cl.setValue( new TextValue( agent.url().utf8() ) ); 821 cl.setValue( new TextValue( agent.url().utf8() ) );
822 params.append( new Param( "VALUE", "uri" ) ); 822 params.append( new Param( "VALUE", "uri" ) );
823 } 823 }
824 824
825 cl.setParamList( params ); 825 cl.setParamList( params );
826 vcard->add( cl ); 826 vcard->add( cl );
827} 827}
828 828
829Agent VCardFormatImpl::readAgentValue( VCARD::ContentLine *cl ) 829Agent VCardFormatImpl::readAgentValue( VCARD::ContentLine *cl )
830{ 830{
831 Agent agent; 831 Agent agent;
832 bool isIntern = true; 832 bool isIntern = true;
833 TextValue *v = (TextValue *)cl->value(); 833 TextValue *v = (TextValue *)cl->value();
834 834
835 ParamList params = cl->paramList(); 835 ParamList params = cl->paramList();
836 ParamListIterator it( params ); 836 ParamListIterator it( params );
837 for( ; it.current(); ++it ) { 837 for( ; it.current(); ++it ) {
838 if ( (*it)->name() == "VALUE" && (*it)->value() == "uri" ) 838 if ( (*it)->name() == "VALUE" && (*it)->value() == "uri" )
839 isIntern = false; 839 isIntern = false;
840 } 840 }
841 841
842 if ( isIntern ) { 842 if ( isIntern ) {
843 QString vstr = QString::fromUtf8( v->asString() ); 843 QString vstr = QString::fromUtf8( v->asString() );
844 qDebug("VCardFormatImpl::addAgentValue please verify if replace is correct"); 844 qDebug("VCardFormatImpl::addAgentValue please verify if replace is correct");
845/*US 845/*US
846 vstr.replace( "\\n", "\r\n" ); 846 vstr.replace( "\\n", "\r\n" );
847 vstr.replace( "\\:", ":" ); 847 vstr.replace( "\\:", ":" );
848 vstr.replace( "\\,", "," ); 848 vstr.replace( "\\,", "," );
849 vstr.replace( "\\;", ";" ); 849 vstr.replace( "\\;", ";" );
850*/ 850*/
851 vstr.replace( QRegExp("\\n"), "\r\n" ); 851 vstr.replace( QRegExp("\\\\n"), "\r\n" );
852 vstr.replace( QRegExp("\\:"), ":" ); 852 vstr.replace( QRegExp("\\\\:"), ":" );
853 vstr.replace( QRegExp("\\,"), "," ); 853 vstr.replace( QRegExp("\\\\,"), "," );
854 vstr.replace( QRegExp("\\;"), ";" ); 854 vstr.replace( QRegExp("\\\\;"), ";" );
855 855
856 Addressee *addr = new Addressee; 856 Addressee *addr = new Addressee;
857 readFromString( vstr, *addr ); 857 readFromString( vstr, *addr );
858 agent.setAddressee( addr ); 858 agent.setAddressee( addr );
859 } else { 859 } else {
860 agent.setUrl( QString::fromUtf8( v->asString() ) ); 860 agent.setUrl( QString::fromUtf8( v->asString() ) );
861 } 861 }
862 862
863 return agent; 863 return agent;
864} 864}
865 865
866void VCardFormatImpl::addPictureValue( VCARD::VCard *vcard, VCARD::EntityType type, const Picture &pic, const Addressee &addr, bool intern ) 866void VCardFormatImpl::addPictureValue( VCARD::VCard *vcard, VCARD::EntityType type, const Picture &pic, const Addressee &addr, bool intern )
867{ 867{
868 ContentLine cl; 868 ContentLine cl;
869 cl.setName( EntityTypeToParamName( type ) ); 869 cl.setName( EntityTypeToParamName( type ) );
870 870
871 if ( pic.isIntern() && pic.data().isNull() ) 871 if ( pic.isIntern() && pic.data().isNull() )
872 return; 872 return;
873 873
874 if ( !pic.isIntern() && pic.url().isEmpty() ) 874 if ( !pic.isIntern() && pic.url().isEmpty() )
875 return; 875 return;
876 876
877 ParamList params; 877 ParamList params;
878 if ( pic.isIntern() ) { 878 if ( pic.isIntern() ) {
879 QImage img = pic.data(); 879 QImage img = pic.data();
880 if ( intern ) { // only for vCard export we really write the data inline 880 if ( intern ) { // only for vCard export we really write the data inline
881 QByteArray data; 881 QByteArray data;
882 QDataStream s( data, IO_WriteOnly ); 882 QDataStream s( data, IO_WriteOnly );
883 s.setVersion( 4 ); // to produce valid png files 883 s.setVersion( 4 ); // to produce valid png files
884 s << img; 884 s << img;
885 cl.setValue( new TextValue( KCodecs::base64Encode( data ) ) ); 885 cl.setValue( new TextValue( KCodecs::base64Encode( data ) ) );
886 886
887 } else { // save picture in cache 887 } else { // save picture in cache
888 QString dir; 888 QString dir;
889 if ( type == EntityPhoto ) 889 if ( type == EntityPhoto )
890 dir = "photos"; 890 dir = "photos";
891 if ( type == EntityLogo ) 891 if ( type == EntityLogo )
892 dir = "logos"; 892 dir = "logos";
893 893
894 img.save( locateLocal( "data", "kabc/" + dir + "/" + addr.uid() ), pic.type().utf8() ); 894 img.save( locateLocal( "data", "kabc/" + dir + "/" + addr.uid() ), pic.type().utf8() );
895 cl.setValue( new TextValue( "<dummy>" ) ); 895 cl.setValue( new TextValue( "<dummy>" ) );
896 } 896 }
897 params.append( new Param( "ENCODING", "b" ) ); 897 params.append( new Param( "ENCODING", "b" ) );
898 if ( !pic.type().isEmpty() ) 898 if ( !pic.type().isEmpty() )
899 params.append( new Param( "TYPE", pic.type().utf8() ) ); 899 params.append( new Param( "TYPE", pic.type().utf8() ) );
900 } else { 900 } else {
901 901
902 cl.setValue( new TextValue( pic.url().utf8() ) ); 902 cl.setValue( new TextValue( pic.url().utf8() ) );
903 params.append( new Param( "VALUE", "uri" ) ); 903 params.append( new Param( "VALUE", "uri" ) );
904 } 904 }
905 905
906 cl.setParamList( params ); 906 cl.setParamList( params );
907 vcard->add( cl ); 907 vcard->add( cl );
908} 908}
909 909
910Picture VCardFormatImpl::readPictureValue( VCARD::ContentLine *cl, VCARD::EntityType type, const Addressee &addr ) 910Picture VCardFormatImpl::readPictureValue( VCARD::ContentLine *cl, VCARD::EntityType type, const Addressee &addr )
911{ 911{
912 Picture pic; 912 Picture pic;
913 bool isInline = false; 913 bool isInline = false;
914 QString picType; 914 QString picType;
915 TextValue *v = (TextValue *)cl->value(); 915 TextValue *v = (TextValue *)cl->value();
916 916
917 ParamList params = cl->paramList(); 917 ParamList params = cl->paramList();
918 ParamListIterator it( params ); 918 ParamListIterator it( params );
919 for( ; it.current(); ++it ) { 919 for( ; it.current(); ++it ) {
920 if ( (*it)->name() == "ENCODING" && (*it)->value() == "b" ) 920 if ( (*it)->name() == "ENCODING" && (*it)->value() == "b" )
921 isInline = true; 921 isInline = true;
922 if ( (*it)->name() == "TYPE" && !(*it)->value().isEmpty() ) 922 if ( (*it)->name() == "TYPE" && !(*it)->value().isEmpty() )
923 picType = QString::fromUtf8( (*it)->value() ); 923 picType = QString::fromUtf8( (*it)->value() );
924 } 924 }
925 925
926 if ( isInline ) { 926 if ( isInline ) {
927 QImage img; 927 QImage img;
928 if ( v->asString() == "<dummy>" ) { // no picture inline stored => picture is in cache 928 if ( v->asString() == "<dummy>" ) { // no picture inline stored => picture is in cache
929 QString dir; 929 QString dir;
930 if ( type == EntityPhoto ) 930 if ( type == EntityPhoto )
931 dir = "photos"; 931 dir = "photos";
932 if ( type == EntityLogo ) 932 if ( type == EntityLogo )
933 dir = "logos"; 933 dir = "logos";
934 934
935 img.load( locateLocal( "data", "kabc/" + dir + "/" + addr.uid() ) ); 935 img.load( locateLocal( "data", "kabc/" + dir + "/" + addr.uid() ) );
936 } else { 936 } else {
937 QByteArray data; 937 QByteArray data;
938 KCodecs::base64Decode( v->asString(), data ); 938 KCodecs::base64Decode( v->asString(), data );
939 img.loadFromData( data ); 939 img.loadFromData( data );
940 } 940 }
941 pic.setData( img ); 941 pic.setData( img );
942 pic.setType( picType ); 942 pic.setType( picType );
943 } else { 943 } else {
944 pic.setUrl( QString::fromUtf8( v->asString() ) ); 944 pic.setUrl( QString::fromUtf8( v->asString() ) );
945 } 945 }
946 946
947 return pic; 947 return pic;
948} 948}
949 949
950void VCardFormatImpl::addSoundValue( VCARD::VCard *vcard, const Sound &sound, const Addressee &addr, bool intern ) 950void VCardFormatImpl::addSoundValue( VCARD::VCard *vcard, const Sound &sound, const Addressee &addr, bool intern )
951{ 951{
952 ContentLine cl; 952 ContentLine cl;
953 cl.setName( EntityTypeToParamName( EntitySound ) ); 953 cl.setName( EntityTypeToParamName( EntitySound ) );
954 954
955 if ( sound.isIntern() && sound.data().isNull() ) 955 if ( sound.isIntern() && sound.data().isNull() )
956 return; 956 return;
957 957
958 if ( !sound.isIntern() && sound.url().isEmpty() ) 958 if ( !sound.isIntern() && sound.url().isEmpty() )
959 return; 959 return;
960 960
961 ParamList params; 961 ParamList params;
962 if ( sound.isIntern() ) { 962 if ( sound.isIntern() ) {
963 QByteArray data = sound.data(); 963 QByteArray data = sound.data();
964 if ( intern ) { // only for vCard export we really write the data inline 964 if ( intern ) { // only for vCard export we really write the data inline
965 cl.setValue( new TextValue( KCodecs::base64Encode( data ) ) ); 965 cl.setValue( new TextValue( KCodecs::base64Encode( data ) ) );
966 } else { // save sound in cache 966 } else { // save sound in cache
967 QFile file( locateLocal( "data", "kabc/sounds/" + addr.uid() ) ); 967 QFile file( locateLocal( "data", "kabc/sounds/" + addr.uid() ) );
968 if ( file.open( IO_WriteOnly ) ) { 968 if ( file.open( IO_WriteOnly ) ) {
969 file.writeBlock( data ); 969 file.writeBlock( data );
970 } 970 }
971 cl.setValue( new TextValue( "<dummy>" ) ); 971 cl.setValue( new TextValue( "<dummy>" ) );
972 } 972 }
973 params.append( new Param( "ENCODING", "b" ) ); 973 params.append( new Param( "ENCODING", "b" ) );
974 } else { 974 } else {
975 cl.setValue( new TextValue( sound.url().utf8() ) ); 975 cl.setValue( new TextValue( sound.url().utf8() ) );
976 params.append( new Param( "VALUE", "uri" ) ); 976 params.append( new Param( "VALUE", "uri" ) );
977 } 977 }
978 978
979 cl.setParamList( params ); 979 cl.setParamList( params );
980 vcard->add( cl ); 980 vcard->add( cl );
981} 981}
982 982
983Sound VCardFormatImpl::readSoundValue( VCARD::ContentLine *cl, const Addressee &addr ) 983Sound VCardFormatImpl::readSoundValue( VCARD::ContentLine *cl, const Addressee &addr )
984{ 984{
985 Sound sound; 985 Sound sound;
986 bool isInline = false; 986 bool isInline = false;
987 TextValue *v = (TextValue *)cl->value(); 987 TextValue *v = (TextValue *)cl->value();
988 988
989 ParamList params = cl->paramList(); 989 ParamList params = cl->paramList();
990 ParamListIterator it( params ); 990 ParamListIterator it( params );
991 for( ; it.current(); ++it ) { 991 for( ; it.current(); ++it ) {
992 if ( (*it)->name() == "ENCODING" && (*it)->value() == "b" ) 992 if ( (*it)->name() == "ENCODING" && (*it)->value() == "b" )
993 isInline = true; 993 isInline = true;
994 } 994 }
995 995
996 if ( isInline ) { 996 if ( isInline ) {
997 QByteArray data; 997 QByteArray data;
998 if ( v->asString() == "<dummy>" ) { // no sound inline stored => sound is in cache 998 if ( v->asString() == "<dummy>" ) { // no sound inline stored => sound is in cache
999 QFile file( locateLocal( "data", "kabc/sounds/" + addr.uid() ) ); 999 QFile file( locateLocal( "data", "kabc/sounds/" + addr.uid() ) );
1000 if ( file.open( IO_ReadOnly ) ) { 1000 if ( file.open( IO_ReadOnly ) ) {
1001 data = file.readAll(); 1001 data = file.readAll();
1002 file.close(); 1002 file.close();
1003 } 1003 }
1004 } else { 1004 } else {
1005 KCodecs::base64Decode( v->asString(), data ); 1005 KCodecs::base64Decode( v->asString(), data );
1006 } 1006 }
1007 sound.setData( data ); 1007 sound.setData( data );
1008 } else { 1008 } else {
1009 sound.setUrl( QString::fromUtf8( v->asString() ) ); 1009 sound.setUrl( QString::fromUtf8( v->asString() ) );
1010 } 1010 }
1011 1011
1012 return sound; 1012 return sound;
1013} 1013}
1014 1014
1015bool VCardFormatImpl::readFromString( const QString &vcard, Addressee &addressee ) 1015bool VCardFormatImpl::readFromString( const QString &vcard, Addressee &addressee )
1016{ 1016{
1017 VCardEntity e( vcard.utf8() ); 1017 VCardEntity e( vcard.utf8() );
1018 VCardListIterator it( e.cardList() ); 1018 VCardListIterator it( e.cardList() );
1019 1019
1020 if ( it.current() ) { 1020 if ( it.current() ) {
1021//US VCard v(*it.current()); 1021//US VCard v(*it.current());
1022//US loadAddressee( addressee, v ); 1022//US loadAddressee( addressee, v );
1023 loadAddressee( addressee, it.current() ); 1023 loadAddressee( addressee, it.current() );
1024 return true; 1024 return true;
1025 } 1025 }
1026 1026
1027 return false; 1027 return false;
1028} 1028}
1029 1029
1030bool VCardFormatImpl::writeToString( const Addressee &addressee, QString &vcard ) 1030bool VCardFormatImpl::writeToString( const Addressee &addressee, QString &vcard )
1031{ 1031{
1032 VCardEntity vcards; 1032 VCardEntity vcards;
1033 VCardList vcardlist; 1033 VCardList vcardlist;
1034 vcardlist.setAutoDelete( true ); 1034 vcardlist.setAutoDelete( true );
1035 1035
1036 VCard *v = new VCard; 1036 VCard *v = new VCard;
1037 1037
1038 saveAddressee( addressee, v, true ); 1038 saveAddressee( addressee, v, true );
1039 1039
1040 vcardlist.append( v ); 1040 vcardlist.append( v );
1041 vcards.setCardList( vcardlist ); 1041 vcards.setCardList( vcardlist );
1042 vcard = QString::fromUtf8( vcards.asString() ); 1042 vcard = QString::fromUtf8( vcards.asString() );
1043 1043
1044 return true; 1044 return true;
1045} 1045}
diff --git a/kabc/vcardparser/vcardparser.cpp b/kabc/vcardparser/vcardparser.cpp
index 9ea084d..bec2a0c 100644
--- a/kabc/vcardparser/vcardparser.cpp
+++ b/kabc/vcardparser/vcardparser.cpp
@@ -1,233 +1,233 @@
1/* 1/*
2 This file is part of libkabc. 2 This file is part of libkabc.
3 Copyright (c) 2003 Tobias Koenig <tokoe@kde.org> 3 Copyright (c) 2003 Tobias Koenig <tokoe@kde.org>
4 4
5 This library is free software; you can redistribute it and/or 5 This library is free software; you can redistribute it and/or
6 modify it under the terms of the GNU Library General Public 6 modify it under the terms of the GNU Library General Public
7 License as published by the Free Software Foundation; either 7 License as published by the Free Software Foundation; either
8 version 2 of the License, or (at your option) any later version. 8 version 2 of the License, or (at your option) any later version.
9 9
10 This library is distributed in the hope that it will be useful, 10 This library is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of 11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Library General Public License for more details. 13 Library General Public License for more details.
14 14
15 You should have received a copy of the GNU Library General Public License 15 You should have received a copy of the GNU Library General Public License
16 along with this library; see the file COPYING.LIB. If not, write to 16 along with this library; see the file COPYING.LIB. If not, write to
17 the Free Software Foundation, Inc., 59 Temple Place - Suite 330, 17 the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
18 Boston, MA 02111-1307, USA. 18 Boston, MA 02111-1307, USA.
19*/ 19*/
20 20
21#include <qregexp.h> 21#include <qregexp.h>
22 22
23#include <kmdcodec.h> 23#include <kmdcodec.h>
24 24
25#include "vcardparser.h" 25#include "vcardparser.h"
26 26
27#define FOLD_WIDTH 75 27#define FOLD_WIDTH 75
28 28
29using namespace KABC; 29using namespace KABC;
30 30
31VCardParser::VCardParser() 31VCardParser::VCardParser()
32{ 32{
33} 33}
34 34
35VCardParser::~VCardParser() 35VCardParser::~VCardParser()
36{ 36{
37} 37}
38 38
39VCard::List VCardParser::parseVCards( const QString& text ) 39VCard::List VCardParser::parseVCards( const QString& text )
40{ 40{
41 VCard currentVCard; 41 VCard currentVCard;
42 VCard::List vCardList; 42 VCard::List vCardList;
43 QString currentLine; 43 QString currentLine;
44 44
45 QStringList lines = QStringList::split( QRegExp( "[\x0d\x0a]" ), text ); 45 QStringList lines = QStringList::split( QRegExp( "[\x0d\x0a]" ), text );
46 QStringList::Iterator it; 46 QStringList::Iterator it;
47 47
48 bool inVCard = false; 48 bool inVCard = false;
49 for ( it = lines.begin(); it != lines.end(); ++it ) { 49 for ( it = lines.begin(); it != lines.end(); ++it ) {
50 50
51 if ( (*it).isEmpty() ) // empty line 51 if ( (*it).isEmpty() ) // empty line
52 continue; 52 continue;
53 53
54 if ( (*it)[ 0 ] == ' ' || (*it)[ 0 ] == '\t' ) { // folded line => append to previous 54 if ( (*it)[ 0 ] == ' ' || (*it)[ 0 ] == '\t' ) { // folded line => append to previous
55 currentLine += (*it).remove( 0, 1 ); 55 currentLine += (*it).remove( 0, 1 );
56 continue; 56 continue;
57 } else { 57 } else {
58 if ( inVCard && !currentLine.isEmpty() ) { // now parse the line 58 if ( inVCard && !currentLine.isEmpty() ) { // now parse the line
59 int colon = currentLine.find( ':' ); 59 int colon = currentLine.find( ':' );
60 if ( colon == -1 ) { // invalid line 60 if ( colon == -1 ) { // invalid line
61 currentLine = (*it); 61 currentLine = (*it);
62 continue; 62 continue;
63 } 63 }
64 64
65 VCardLine vCardLine; 65 VCardLine vCardLine;
66 QString key = currentLine.left( colon ).stripWhiteSpace(); 66 QString key = currentLine.left( colon ).stripWhiteSpace();
67 QString value = currentLine.mid( colon + 1 ); 67 QString value = currentLine.mid( colon + 1 );
68 68
69 QStringList params = QStringList::split( ';', key ); 69 QStringList params = QStringList::split( ';', key );
70 vCardLine.setIdentifier( params[0] ); 70 vCardLine.setIdentifier( params[0] );
71 if ( params.count() > 1 ) { // find all parameters 71 if ( params.count() > 1 ) { // find all parameters
72 for ( uint i = 1; i < params.count(); ++i ) { 72 for ( uint i = 1; i < params.count(); ++i ) {
73 QStringList pair = QStringList::split( '=', params[i] ); 73 QStringList pair = QStringList::split( '=', params[i] );
74//US if ( pair.size() == 1 ) { 74//US if ( pair.size() == 1 ) {
75 if ( pair.count() == 1 ) { 75 if ( pair.count() == 1 ) {
76 pair.prepend( "type" ); 76 pair.prepend( "type" );
77 } 77 }
78 if ( pair[1].contains( ',' ) ) { // parameter in type=x,y,z format 78 if ( pair[1].contains( ',' ) ) { // parameter in type=x,y,z format
79 QStringList args = QStringList::split( ',', pair[ 1 ] ); 79 QStringList args = QStringList::split( ',', pair[ 1 ] );
80 for ( uint j = 0; j < args.count(); ++j ) 80 for ( uint j = 0; j < args.count(); ++j )
81 vCardLine.addParameter( pair[0].lower(), args[j] ); 81 vCardLine.addParameter( pair[0].lower(), args[j] );
82 } else 82 } else
83 vCardLine.addParameter( pair[0].lower(), pair[1] ); 83 vCardLine.addParameter( pair[0].lower(), pair[1] );
84 } 84 }
85 } 85 }
86 86
87 params = vCardLine.parameterList(); 87 params = vCardLine.parameterList();
88 if ( params.contains( "encoding" ) ) { // have to decode the data 88 if ( params.contains( "encoding" ) ) { // have to decode the data
89#if 0 89#if 0
90 QByteArray input, output; 90 QByteArray input, output;
91 input = value.local8Bit(); 91 input = value.local8Bit();
92 if ( vCardLine.parameter( "encoding" ).lower() == "b" ) 92 if ( vCardLine.parameter( "encoding" ).lower() == "b" )
93 KCodecs::base64Decode( input, output ); 93 KCodecs::base64Decode( input, output );
94 else if ( vCardLine.parameter( "encoding" ).lower() == "quoted-printable" ) 94 else if ( vCardLine.parameter( "encoding" ).lower() == "quoted-printable" )
95 KCodecs::quotedPrintableDecode( input, output ); 95 KCodecs::quotedPrintableDecode( input, output );
96 96
97 //qDebug("VCardParser::parseVCards has to be verified"); 97 //qDebug("VCardParser::parseVCards has to be verified");
98 //US I am not sure if this is correct 98 //US I am not sure if this is correct
99 //US vCardLine.setValue( output ); 99 //US vCardLine.setValue( output );
100 QCString cs(output); 100 QCString cs(output);
101 qDebug("len1 %d len2 %d ",input.size(), output.size( )); 101 qDebug("len1 %d len2 %d ",input.size(), output.size( ));
102#endif 102#endif
103 QCString cs = value.local8Bit(); 103 QCString cs = value.local8Bit();
104 qDebug("****************************************** "); 104 qDebug("****************************************** ");
105 qDebug("************* WARNING ******************** "); 105 qDebug("************* WARNING ******************** ");
106 qDebug("****************************************** "); 106 qDebug("****************************************** ");
107 qDebug("Make sure, the decoding is done after"); 107 qDebug("Make sure, the decoding is done after");
108 qDebug("QVariant conversion!"); 108 qDebug("QVariant conversion!");
109 qDebug("Insert Line DECODING OKAY, where this is implemented"); 109 qDebug("Insert Line DECODING OKAY, where this is implemented");
110 // use for decoding the above code! 110 // use for decoding the above code!
111 vCardLine.setValue( cs ); 111 vCardLine.setValue( cs );
112 } else { 112 } else {
113 113
114 //qDebug("VCardParser::parseVCards has to be verified"); 114 //qDebug("VCardParser::parseVCards has to be verified");
115//US vCardLine.setValue( value.replace( "\\n", "\n" ) ); 115//US vCardLine.setValue( value.replace( "\\n", "\n" ) );
116 vCardLine.setValue( value.replace( QRegExp("\\n"), "\n" ) ); 116 vCardLine.setValue( value.replace( QRegExp("\\\\n"), "\n" ) );
117 } 117 }
118 118
119 currentVCard.addLine( vCardLine ); 119 currentVCard.addLine( vCardLine );
120 } 120 }
121 // we do not save the start and end tag as vcardline 121 // we do not save the start and end tag as vcardline
122 if ( (*it).lower().startsWith( "begin:vcard" ) ) { 122 if ( (*it).lower().startsWith( "begin:vcard" ) ) {
123 inVCard = true; 123 inVCard = true;
124 //qDebug("VCardParser::parseVCards has to be verified"); 124 //qDebug("VCardParser::parseVCards has to be verified");
125//US currentLine.setLength( 0 ); 125//US currentLine.setLength( 0 );
126 currentLine = ""; 126 currentLine = "";
127 currentVCard.clear(); // flush vcard 127 currentVCard.clear(); // flush vcard
128 continue; 128 continue;
129 } 129 }
130 130
131 if ( (*it).lower().startsWith( "end:vcard" ) ) { 131 if ( (*it).lower().startsWith( "end:vcard" ) ) {
132 inVCard = false; 132 inVCard = false;
133 vCardList.append( currentVCard ); 133 vCardList.append( currentVCard );
134 //qDebug("VCardParser::parseVCards has to be verified"); 134 //qDebug("VCardParser::parseVCards has to be verified");
135//US currentLine.setLength( 0 ); 135//US currentLine.setLength( 0 );
136 currentLine = ""; 136 currentLine = "";
137 currentVCard.clear(); // flush vcard 137 currentVCard.clear(); // flush vcard
138 continue; 138 continue;
139 } 139 }
140 140
141 currentLine = (*it); 141 currentLine = (*it);
142 } 142 }
143 } 143 }
144 144
145 return vCardList; 145 return vCardList;
146} 146}
147 147
148QString VCardParser::createVCards( const VCard::List& list ) 148QString VCardParser::createVCards( const VCard::List& list )
149{ 149{
150 QString text; 150 QString text;
151 QString textLine; 151 QString textLine;
152 QString encodingType; 152 QString encodingType;
153 QStringList idents; 153 QStringList idents;
154 QStringList params; 154 QStringList params;
155 QStringList values; 155 QStringList values;
156 QStringList::ConstIterator identIt; 156 QStringList::ConstIterator identIt;
157 QStringList::Iterator paramIt; 157 QStringList::Iterator paramIt;
158 QStringList::Iterator valueIt; 158 QStringList::Iterator valueIt;
159 159
160 VCardLine::List lines; 160 VCardLine::List lines;
161 VCardLine::List::Iterator lineIt; 161 VCardLine::List::Iterator lineIt;
162 VCard::List::ConstIterator cardIt; 162 VCard::List::ConstIterator cardIt;
163 163
164 bool hasEncoding; 164 bool hasEncoding;
165 165
166 166
167 // iterate over the cards 167 // iterate over the cards
168 for ( cardIt = list.begin(); cardIt != list.end(); ++cardIt ) { 168 for ( cardIt = list.begin(); cardIt != list.end(); ++cardIt ) {
169 text.append( "BEGIN:VCARD\r\n" ); 169 text.append( "BEGIN:VCARD\r\n" );
170 170
171 idents = (*cardIt).identifiers(); 171 idents = (*cardIt).identifiers();
172 for ( identIt = idents.begin(); identIt != idents.end(); ++identIt ) { 172 for ( identIt = idents.begin(); identIt != idents.end(); ++identIt ) {
173 VCard card = (*cardIt); 173 VCard card = (*cardIt);
174 lines = card.lines( (*identIt) ); 174 lines = card.lines( (*identIt) );
175 175
176 // iterate over the lines 176 // iterate over the lines
177 for ( lineIt = lines.begin(); lineIt != lines.end(); ++lineIt ) { 177 for ( lineIt = lines.begin(); lineIt != lines.end(); ++lineIt ) {
178 if ( !(*lineIt).value().asString().isEmpty() ) { 178 if ( !(*lineIt).value().asString().isEmpty() ) {
179 textLine = (*lineIt).identifier(); 179 textLine = (*lineIt).identifier();
180 180
181 params = (*lineIt).parameterList(); 181 params = (*lineIt).parameterList();
182 hasEncoding = false; 182 hasEncoding = false;
183 if ( params.count() > 0 ) { // we have parameters 183 if ( params.count() > 0 ) { // we have parameters
184 for ( paramIt = params.begin(); paramIt != params.end(); ++paramIt ) { 184 for ( paramIt = params.begin(); paramIt != params.end(); ++paramIt ) {
185 if ( (*paramIt) == "encoding" ) { 185 if ( (*paramIt) == "encoding" ) {
186 hasEncoding = true; 186 hasEncoding = true;
187 encodingType = (*lineIt).parameter( "encoding" ).lower(); 187 encodingType = (*lineIt).parameter( "encoding" ).lower();
188 } 188 }
189 189
190 values = (*lineIt).parameters( *paramIt ); 190 values = (*lineIt).parameters( *paramIt );
191 for ( valueIt = values.begin(); valueIt != values.end(); ++valueIt ) { 191 for ( valueIt = values.begin(); valueIt != values.end(); ++valueIt ) {
192 textLine.append( ";" + (*paramIt).upper() ); 192 textLine.append( ";" + (*paramIt).upper() );
193 if ( !(*valueIt).isEmpty() ) 193 if ( !(*valueIt).isEmpty() )
194 textLine.append( "=" + (*valueIt) ); 194 textLine.append( "=" + (*valueIt) );
195 } 195 }
196 } 196 }
197 } 197 }
198 198
199 if ( hasEncoding ) { // have to encode the data 199 if ( hasEncoding ) { // have to encode the data
200 QByteArray input, output; 200 QByteArray input, output;
201 201
202 qDebug("VCardParser::createVCards has to be verified"); 202 qDebug("VCardParser::createVCards has to be verified");
203//US input = (*lineIt).value().toByteArray(); 203//US input = (*lineIt).value().toByteArray();
204 204
205//US I am not sure if this is correct 205//US I am not sure if this is correct
206 QCString cs ((*lineIt).value().toCString()); 206 QCString cs ((*lineIt).value().toCString());
207 input = cs; 207 input = cs;
208 208
209 if ( encodingType == "b" ) 209 if ( encodingType == "b" )
210 KCodecs::base64Encode( input, output ); 210 KCodecs::base64Encode( input, output );
211 else if ( encodingType == "quoted-printable" ) 211 else if ( encodingType == "quoted-printable" )
212 KCodecs::quotedPrintableEncode( input, output ); 212 KCodecs::quotedPrintableEncode( input, output );
213 textLine.append( ":" + QString( output ) ); 213 textLine.append( ":" + QString( output ) );
214 } else { 214 } else {
215 qDebug("VCardParser::createVCards has to be verified"); 215 qDebug("VCardParser::createVCards has to be verified");
216//US textLine.append( ":" + (*lineIt).value().asString().replace( "\n", "\\n" ) ); 216//US textLine.append( ":" + (*lineIt).value().asString().replace( "\n", "\\n" ) );
217 textLine.append( ":" + (*lineIt).value().asString().replace( QRegExp("\n"), "\\n" ) ); 217 textLine.append( ":" + (*lineIt).value().asString().replace( QRegExp("\n"), "\\n" ) );
218 } 218 }
219 if ( textLine.length() > FOLD_WIDTH ) { // we have to fold the line 219 if ( textLine.length() > FOLD_WIDTH ) { // we have to fold the line
220 for ( uint i = 0; i <= ( textLine.length() / FOLD_WIDTH ); ++i ) 220 for ( uint i = 0; i <= ( textLine.length() / FOLD_WIDTH ); ++i )
221 text.append( ( i == 0 ? "" : " " ) + textLine.mid( i * FOLD_WIDTH, FOLD_WIDTH ) + "\r\n" ); 221 text.append( ( i == 0 ? "" : " " ) + textLine.mid( i * FOLD_WIDTH, FOLD_WIDTH ) + "\r\n" );
222 } else 222 } else
223 text.append( textLine + "\r\n" ); 223 text.append( textLine + "\r\n" );
224 } 224 }
225 } 225 }
226 } 226 }
227 227
228 text.append( "END:VCARD\r\n" ); 228 text.append( "END:VCARD\r\n" );
229 text.append( "\r\n" ); 229 text.append( "\r\n" );
230 } 230 }
231 231
232 return text; 232 return text;
233} 233}
diff --git a/kabc/vcardparser/vcardtool.cpp b/kabc/vcardparser/vcardtool.cpp
index 3fb212e..d1f823b 100644
--- a/kabc/vcardparser/vcardtool.cpp
+++ b/kabc/vcardparser/vcardtool.cpp
@@ -303,596 +303,596 @@ QString VCardTool::createVCards( Addressee::List list, VCard::Version version )
303} 303}
304 304
305Addressee::List VCardTool::parseVCards( const QString& vcard ) 305Addressee::List VCardTool::parseVCards( const QString& vcard )
306{ 306{
307 QChar semicolonSep( ';' ); 307 QChar semicolonSep( ';' );
308 QChar commaSep( ',' ); 308 QChar commaSep( ',' );
309 QString identifier; 309 QString identifier;
310 310
311 Addressee::List addrList; 311 Addressee::List addrList;
312 VCard::List vCardList = VCardParser::parseVCards( vcard ); 312 VCard::List vCardList = VCardParser::parseVCards( vcard );
313 VCard::List::Iterator cardIt; 313 VCard::List::Iterator cardIt;
314 for ( cardIt = vCardList.begin(); cardIt != vCardList.end(); ++cardIt ) { 314 for ( cardIt = vCardList.begin(); cardIt != vCardList.end(); ++cardIt ) {
315 Addressee addr; 315 Addressee addr;
316 QStringList idents = (*cardIt).identifiers(); 316 QStringList idents = (*cardIt).identifiers();
317 QStringList::ConstIterator identIt; 317 QStringList::ConstIterator identIt;
318 for ( identIt = idents.begin(); identIt != idents.end(); ++identIt ) { 318 for ( identIt = idents.begin(); identIt != idents.end(); ++identIt ) {
319 VCard card = (*cardIt); 319 VCard card = (*cardIt);
320 VCardLine::List lines = card.lines( (*identIt) ); 320 VCardLine::List lines = card.lines( (*identIt) );
321 VCardLine::List::Iterator lineIt; 321 VCardLine::List::Iterator lineIt;
322 322
323 // iterate over the lines 323 // iterate over the lines
324 for ( lineIt = lines.begin(); lineIt != lines.end(); ++lineIt ) { 324 for ( lineIt = lines.begin(); lineIt != lines.end(); ++lineIt ) {
325 QStringList params = (*lineIt).parameterList(); 325 QStringList params = (*lineIt).parameterList();
326 326
327 identifier = (*lineIt).identifier().lower(); 327 identifier = (*lineIt).identifier().lower();
328 // ADR 328 // ADR
329 if ( identifier == "adr" ) { 329 if ( identifier == "adr" ) {
330 Address address; 330 Address address;
331 QStringList addrParts = splitString( semicolonSep, (*lineIt).value().asString() ); 331 QStringList addrParts = splitString( semicolonSep, (*lineIt).value().asString() );
332 if ( addrParts.count() > 0 ) 332 if ( addrParts.count() > 0 )
333 address.setPostOfficeBox( addrParts[ 0 ] ); 333 address.setPostOfficeBox( addrParts[ 0 ] );
334 if ( addrParts.count() > 1 ) 334 if ( addrParts.count() > 1 )
335 address.setExtended( addrParts[ 1 ] ); 335 address.setExtended( addrParts[ 1 ] );
336 if ( addrParts.count() > 2 ) 336 if ( addrParts.count() > 2 )
337 address.setStreet( addrParts[ 2 ].replace ( QRegExp("\\\\n") , "\n") ); 337 address.setStreet( addrParts[ 2 ].replace ( QRegExp("\\\\n") , "\n") );
338 if ( addrParts.count() > 3 ) 338 if ( addrParts.count() > 3 )
339 address.setLocality( addrParts[ 3 ] ); 339 address.setLocality( addrParts[ 3 ] );
340 if ( addrParts.count() > 4 ) 340 if ( addrParts.count() > 4 )
341 address.setRegion( addrParts[ 4 ] ); 341 address.setRegion( addrParts[ 4 ] );
342 if ( addrParts.count() > 5 ) 342 if ( addrParts.count() > 5 )
343 address.setPostalCode( addrParts[ 5 ] ); 343 address.setPostalCode( addrParts[ 5 ] );
344 if ( addrParts.count() > 6 ) 344 if ( addrParts.count() > 6 )
345 address.setCountry( addrParts[ 6 ] ); 345 address.setCountry( addrParts[ 6 ] );
346 346
347 int type = 0; 347 int type = 0;
348 348
349 QStringList types = (*lineIt).parameters( "type" ); 349 QStringList types = (*lineIt).parameters( "type" );
350 for ( QStringList::Iterator it = types.begin(); it != types.end(); ++it ) 350 for ( QStringList::Iterator it = types.begin(); it != types.end(); ++it )
351 type += mAddressTypeMap[ (*it).lower() ]; 351 type += mAddressTypeMap[ (*it).lower() ];
352 352
353 if ( !type ) 353 if ( !type )
354 type = Address::Home; // default 354 type = Address::Home; // default
355 355
356 address.setType( type ); 356 address.setType( type );
357 addr.insertAddress( address ); 357 addr.insertAddress( address );
358 } 358 }
359 359
360 // AGENT 360 // AGENT
361 if ( identifier == "agent" ) 361 if ( identifier == "agent" )
362 addr.setAgent( parseAgent( *lineIt ) ); 362 addr.setAgent( parseAgent( *lineIt ) );
363 363
364 // BDAY 364 // BDAY
365 if ( identifier == "bday" ) 365 if ( identifier == "bday" )
366 addr.setBirthday( parseDateTime( (*lineIt).value().asString() ) ); 366 addr.setBirthday( parseDateTime( (*lineIt).value().asString() ) );
367 367
368 // CATEGORIES 368 // CATEGORIES
369 if ( identifier == "categories" ) { 369 if ( identifier == "categories" ) {
370 QStringList categories = splitString( commaSep, (*lineIt).value().asString() ); 370 QStringList categories = splitString( commaSep, (*lineIt).value().asString() );
371 addr.setCategories( categories ); 371 addr.setCategories( categories );
372 } 372 }
373 373
374 // CLASS 374 // CLASS
375 if ( identifier == "class" ) 375 if ( identifier == "class" )
376 addr.setSecrecy( parseSecrecy( *lineIt ) ); 376 addr.setSecrecy( parseSecrecy( *lineIt ) );
377 377
378 // EMAIL 378 // EMAIL
379 if ( identifier == "email" ) { 379 if ( identifier == "email" ) {
380 QStringList types = (*lineIt).parameters( "type" ); 380 QStringList types = (*lineIt).parameters( "type" );
381 addr.insertEmail( (*lineIt).value().asString(), types.contains( "PREF" ) ); 381 addr.insertEmail( (*lineIt).value().asString(), types.contains( "PREF" ) );
382 } 382 }
383 383
384 // FN 384 // FN
385 if ( identifier == "fn" ) 385 if ( identifier == "fn" )
386 addr.setFormattedName( (*lineIt).value().asString() ); 386 addr.setFormattedName( (*lineIt).value().asString() );
387 387
388 // GEO 388 // GEO
389 if ( identifier == "geo" ) { 389 if ( identifier == "geo" ) {
390 Geo geo; 390 Geo geo;
391 391
392 QStringList geoParts = QStringList::split( ';', (*lineIt).value().asString(), true ); 392 QStringList geoParts = QStringList::split( ';', (*lineIt).value().asString(), true );
393 geo.setLatitude( geoParts[ 0 ].toFloat() ); 393 geo.setLatitude( geoParts[ 0 ].toFloat() );
394 geo.setLongitude( geoParts[ 1 ].toFloat() ); 394 geo.setLongitude( geoParts[ 1 ].toFloat() );
395 395
396 addr.setGeo( geo ); 396 addr.setGeo( geo );
397 } 397 }
398 398
399 // KEY 399 // KEY
400 if ( identifier == "key" ) 400 if ( identifier == "key" )
401 addr.insertKey( parseKey( *lineIt ) ); 401 addr.insertKey( parseKey( *lineIt ) );
402 402
403 // LABEL 403 // LABEL
404 if ( identifier == "label" ) { 404 if ( identifier == "label" ) {
405 int type = 0; 405 int type = 0;
406 406
407 QStringList types = (*lineIt).parameters( "type" ); 407 QStringList types = (*lineIt).parameters( "type" );
408 for ( QStringList::Iterator it = types.begin(); it != types.end(); ++it ) 408 for ( QStringList::Iterator it = types.begin(); it != types.end(); ++it )
409 type += mAddressTypeMap[ (*it).lower() ]; 409 type += mAddressTypeMap[ (*it).lower() ];
410 410
411 if ( !type ) 411 if ( !type )
412 type = Address::Home; 412 type = Address::Home;
413 413
414 KABC::Address::List addressList = addr.addresses(); 414 KABC::Address::List addressList = addr.addresses();
415 KABC::Address::List::Iterator it; 415 KABC::Address::List::Iterator it;
416 for ( it = addressList.begin(); it != addressList.end(); ++it ) { 416 for ( it = addressList.begin(); it != addressList.end(); ++it ) {
417 if ( (*it).type() == type ) { 417 if ( (*it).type() == type ) {
418 (*it).setLabel( (*lineIt).value().asString() ); 418 (*it).setLabel( (*lineIt).value().asString() );
419 addr.insertAddress( *it ); 419 addr.insertAddress( *it );
420 } 420 }
421 } 421 }
422 } 422 }
423 423
424 // LOGO 424 // LOGO
425 if ( identifier == "logo" ) 425 if ( identifier == "logo" )
426 addr.setLogo( parsePicture( *lineIt ) ); 426 addr.setLogo( parsePicture( *lineIt ) );
427 427
428 // MAILER 428 // MAILER
429 if ( identifier == "mailer" ) 429 if ( identifier == "mailer" )
430 addr.setMailer( (*lineIt).value().asString() ); 430 addr.setMailer( (*lineIt).value().asString() );
431 431
432 // N 432 // N
433 if ( identifier == "n" ) { 433 if ( identifier == "n" ) {
434 QStringList nameParts = splitString( semicolonSep, (*lineIt).value().asString() ); 434 QStringList nameParts = splitString( semicolonSep, (*lineIt).value().asString() );
435 if ( nameParts.count() > 0 ) 435 if ( nameParts.count() > 0 )
436 addr.setFamilyName( nameParts[ 0 ] ); 436 addr.setFamilyName( nameParts[ 0 ] );
437 if ( nameParts.count() > 1 ) 437 if ( nameParts.count() > 1 )
438 addr.setGivenName( nameParts[ 1 ] ); 438 addr.setGivenName( nameParts[ 1 ] );
439 if ( nameParts.count() > 2 ) 439 if ( nameParts.count() > 2 )
440 addr.setAdditionalName( nameParts[ 2 ] ); 440 addr.setAdditionalName( nameParts[ 2 ] );
441 if ( nameParts.count() > 3 ) 441 if ( nameParts.count() > 3 )
442 addr.setPrefix( nameParts[ 3 ] ); 442 addr.setPrefix( nameParts[ 3 ] );
443 if ( nameParts.count() > 4 ) 443 if ( nameParts.count() > 4 )
444 addr.setSuffix( nameParts[ 4 ] ); 444 addr.setSuffix( nameParts[ 4 ] );
445 } 445 }
446 446
447 // NICKNAME 447 // NICKNAME
448 if ( identifier == "nickname" ) 448 if ( identifier == "nickname" )
449 addr.setNickName( (*lineIt).value().asString() ); 449 addr.setNickName( (*lineIt).value().asString() );
450 450
451 // NOTE 451 // NOTE
452 if ( identifier == "note" ) { 452 if ( identifier == "note" ) {
453// #ifdef DESKTOP_VERSION 453// #ifdef DESKTOP_VERSION
454// addr.setNote( (*lineIt).value().asString() ); 454// addr.setNote( (*lineIt).value().asString() );
455// #else 455// #else
456 QString note = (*lineIt).value().asString(); 456 QString note = (*lineIt).value().asString();
457 if ( ! note.isEmpty() ) 457 if ( ! note.isEmpty() )
458 addr.setNote( note.replace ( QRegExp("\\\\n") , "\n") ); 458 addr.setNote( note.replace ( QRegExp("\\\\n") , "\n") );
459 else 459 else
460 addr.setNote( note ); 460 addr.setNote( note );
461 //#endif 461 //#endif
462 } 462 }
463 463
464 // ORGANIZATION 464 // ORGANIZATION
465 if ( identifier == "org" ) 465 if ( identifier == "org" )
466 addr.setOrganization( (*lineIt).value().asString() ); 466 addr.setOrganization( (*lineIt).value().asString() );
467 467
468 // PHOTO 468 // PHOTO
469 if ( identifier == "photo" ) 469 if ( identifier == "photo" )
470 addr.setPhoto( parsePicture( *lineIt ) ); 470 addr.setPhoto( parsePicture( *lineIt ) );
471 471
472 // PROID 472 // PROID
473 if ( identifier == "prodid" ) 473 if ( identifier == "prodid" )
474 addr.setProductId( (*lineIt).value().asString() ); 474 addr.setProductId( (*lineIt).value().asString() );
475 475
476 // REV 476 // REV
477 if ( identifier == "rev" ) 477 if ( identifier == "rev" )
478 addr.setRevision( parseDateTime( (*lineIt).value().asString() ) ); 478 addr.setRevision( parseDateTime( (*lineIt).value().asString() ) );
479 479
480 // ROLE 480 // ROLE
481 if ( identifier == "role" ) 481 if ( identifier == "role" )
482 addr.setRole( (*lineIt).value().asString() ); 482 addr.setRole( (*lineIt).value().asString() );
483 483
484 // SORT-STRING 484 // SORT-STRING
485 if ( identifier == "sort-string" ) 485 if ( identifier == "sort-string" )
486 addr.setSortString( (*lineIt).value().asString() ); 486 addr.setSortString( (*lineIt).value().asString() );
487 487
488 // SOUND 488 // SOUND
489 if ( identifier == "sound" ) 489 if ( identifier == "sound" )
490 addr.setSound( parseSound( *lineIt ) ); 490 addr.setSound( parseSound( *lineIt ) );
491 491
492 // TEL 492 // TEL
493 if ( identifier == "tel" ) { 493 if ( identifier == "tel" ) {
494 PhoneNumber phone; 494 PhoneNumber phone;
495 phone.setNumber( (*lineIt).value().asString() ); 495 phone.setNumber( (*lineIt).value().asString() );
496 496
497 int type = 0; 497 int type = 0;
498 498
499 QStringList types = (*lineIt).parameters( "type" ); 499 QStringList types = (*lineIt).parameters( "type" );
500 for ( QStringList::Iterator it = types.begin(); it != types.end(); ++it ) 500 for ( QStringList::Iterator it = types.begin(); it != types.end(); ++it )
501 type += mPhoneTypeMap[(*it).upper()]; 501 type += mPhoneTypeMap[(*it).upper()];
502 502
503 if ( !type ) 503 if ( !type )
504 type = PhoneNumber::Home; // default 504 type = PhoneNumber::Home; // default
505 505
506 phone.setType( type ); 506 phone.setType( type );
507 507
508 addr.insertPhoneNumber( phone ); 508 addr.insertPhoneNumber( phone );
509 } 509 }
510 510
511 // TITLE 511 // TITLE
512 if ( identifier == "title" ) 512 if ( identifier == "title" )
513 addr.setTitle( (*lineIt).value().asString() ); 513 addr.setTitle( (*lineIt).value().asString() );
514 514
515 // TZ 515 // TZ
516 if ( identifier == "tz" ) { 516 if ( identifier == "tz" ) {
517 TimeZone tz; 517 TimeZone tz;
518 QString date = (*lineIt).value().asString(); 518 QString date = (*lineIt).value().asString();
519 519
520 int hours = date.mid( 1, 2).toInt(); 520 int hours = date.mid( 1, 2).toInt();
521 int minutes = date.mid( 4, 2 ).toInt(); 521 int minutes = date.mid( 4, 2 ).toInt();
522 int offset = ( hours * 60 ) + minutes; 522 int offset = ( hours * 60 ) + minutes;
523 offset = offset * ( date[ 0 ] == '+' ? 1 : -1 ); 523 offset = offset * ( date[ 0 ] == '+' ? 1 : -1 );
524 524
525 tz.setOffset( offset ); 525 tz.setOffset( offset );
526 addr.setTimeZone( tz ); 526 addr.setTimeZone( tz );
527 } 527 }
528 528
529 // UID 529 // UID
530 if ( identifier == "uid" ) 530 if ( identifier == "uid" )
531 addr.setUid( (*lineIt).value().asString() ); 531 addr.setUid( (*lineIt).value().asString() );
532 532
533 // URL 533 // URL
534 if ( identifier == "url" ) 534 if ( identifier == "url" )
535 addr.setUrl( (*lineIt).value().asString() ); 535 addr.setUrl( (*lineIt).value().asString() );
536 536
537 // X- 537 // X-
538 if ( identifier.startsWith( "x-" ) ) { 538 if ( identifier.startsWith( "x-" ) ) {
539 QString key = (*lineIt).identifier().mid( 2 ); 539 QString key = (*lineIt).identifier().mid( 2 );
540 int dash = key.find( "-" ); 540 int dash = key.find( "-" );
541 addr.insertCustom( key.left( dash ), key.mid( dash + 1 ), (*lineIt).value().asString() ); 541 addr.insertCustom( key.left( dash ), key.mid( dash + 1 ), (*lineIt).value().asString() );
542 } 542 }
543 } 543 }
544 } 544 }
545 545
546 addrList.append( addr ); 546 addrList.append( addr );
547 } 547 }
548 548
549 return addrList; 549 return addrList;
550} 550}
551 551
552QDateTime VCardTool::parseDateTime( const QString &str ) 552QDateTime VCardTool::parseDateTime( const QString &str )
553{ 553{
554 QDateTime dateTime; 554 QDateTime dateTime;
555 555
556 if ( str.find( '-' ) == -1 ) { // is base format (yyyymmdd) 556 if ( str.find( '-' ) == -1 ) { // is base format (yyyymmdd)
557 dateTime.setDate( QDate( str.left( 4 ).toInt(), str.mid( 4, 2 ).toInt(), 557 dateTime.setDate( QDate( str.left( 4 ).toInt(), str.mid( 4, 2 ).toInt(),
558 str.mid( 6, 2 ).toInt() ) ); 558 str.mid( 6, 2 ).toInt() ) );
559 559
560 if ( str.find( 'T' ) ) // has time information yyyymmddThh:mm:ss 560 if ( str.find( 'T' ) ) // has time information yyyymmddThh:mm:ss
561 dateTime.setTime( QTime( str.mid( 11, 2 ).toInt(), str.mid( 14, 2 ).toInt(), 561 dateTime.setTime( QTime( str.mid( 11, 2 ).toInt(), str.mid( 14, 2 ).toInt(),
562 str.mid( 17, 2 ).toInt() ) ); 562 str.mid( 17, 2 ).toInt() ) );
563 563
564 } else { // is extended format yyyy-mm-dd 564 } else { // is extended format yyyy-mm-dd
565 dateTime.setDate( QDate( str.left( 4 ).toInt(), str.mid( 5, 2 ).toInt(), 565 dateTime.setDate( QDate( str.left( 4 ).toInt(), str.mid( 5, 2 ).toInt(),
566 str.mid( 8, 2 ).toInt() ) ); 566 str.mid( 8, 2 ).toInt() ) );
567 567
568 if ( str.find( 'T' ) ) // has time information yyyy-mm-ddThh:mm:ss 568 if ( str.find( 'T' ) ) // has time information yyyy-mm-ddThh:mm:ss
569 dateTime.setTime( QTime( str.mid( 11, 2 ).toInt(), str.mid( 14, 2 ).toInt(), 569 dateTime.setTime( QTime( str.mid( 11, 2 ).toInt(), str.mid( 14, 2 ).toInt(),
570 str.mid( 17, 2 ).toInt() ) ); 570 str.mid( 17, 2 ).toInt() ) );
571 } 571 }
572 572
573 return dateTime; 573 return dateTime;
574} 574}
575 575
576QString VCardTool::createDateTime( const QDateTime &dateTime ) 576QString VCardTool::createDateTime( const QDateTime &dateTime )
577{ 577{
578 QString str; 578 QString str;
579 579
580 if ( dateTime.date().isValid() ) { 580 if ( dateTime.date().isValid() ) {
581 str.sprintf( "%4d-%02d-%02d", dateTime.date().year(), dateTime.date().month(), 581 str.sprintf( "%4d-%02d-%02d", dateTime.date().year(), dateTime.date().month(),
582 dateTime.date().day() ); 582 dateTime.date().day() );
583 if ( dateTime.time().isValid() ) { 583 if ( dateTime.time().isValid() ) {
584 QString tmp; 584 QString tmp;
585 tmp.sprintf( "T%02d:%02d:%02dZ", dateTime.time().hour(), dateTime.time().minute(), 585 tmp.sprintf( "T%02d:%02d:%02dZ", dateTime.time().hour(), dateTime.time().minute(),
586 dateTime.time().second() ); 586 dateTime.time().second() );
587 str += tmp; 587 str += tmp;
588 } 588 }
589 } 589 }
590 590
591 return str; 591 return str;
592} 592}
593 593
594Picture VCardTool::parsePicture( const VCardLine &line ) 594Picture VCardTool::parsePicture( const VCardLine &line )
595{ 595{
596 Picture pic; 596 Picture pic;
597 597
598 QStringList params = line.parameterList(); 598 QStringList params = line.parameterList();
599 if ( params.contains( "encoding" ) ) { 599 if ( params.contains( "encoding" ) ) {
600 QCString cs(line.value().asCString()); 600 QCString cs(line.value().asCString());
601 QByteArray input, output; 601 QByteArray input, output;
602 input = line.value().asCString(); 602 input = line.value().asCString();
603 if ( line.parameter( "encoding" ).lower() == "b" ) 603 if ( line.parameter( "encoding" ).lower() == "b" )
604 KCodecs::base64Decode( input, output ); 604 KCodecs::base64Decode( input, output );
605 else if ( line.parameter( "encoding" ).lower() == "quoted-printable" ) 605 else if ( line.parameter( "encoding" ).lower() == "quoted-printable" )
606 KCodecs::quotedPrintableDecode( input, output ); 606 KCodecs::quotedPrintableDecode( input, output );
607 607
608 qDebug("********** DECODING OKAY ************** (picture)"); 608 qDebug("********** DECODING OKAY ************** (picture)");
609 pic.setData( QImage(output) ); 609 pic.setData( QImage(output) );
610 610
611 } 611 }
612 else if ( params.contains( "value" ) ) { 612 else if ( params.contains( "value" ) ) {
613 if ( line.parameter( "value" ).lower() == "uri" ) 613 if ( line.parameter( "value" ).lower() == "uri" )
614 pic.setUrl( line.value().asString() ); 614 pic.setUrl( line.value().asString() );
615 } 615 }
616 616
617 if ( params.contains( "type" ) ) 617 if ( params.contains( "type" ) )
618 pic.setType( line.parameter( "type" ) ); 618 pic.setType( line.parameter( "type" ) );
619 619
620 return pic; 620 return pic;
621} 621}
622 622
623VCardLine VCardTool::createPicture( const QString &identifier, const Picture &pic ) 623VCardLine VCardTool::createPicture( const QString &identifier, const Picture &pic )
624{ 624{
625 // LR fixed 625 // LR fixed
626 VCardLine line( identifier ); 626 VCardLine line( identifier );
627 627
628 if ( pic.isIntern() ) { 628 if ( pic.isIntern() ) {
629 if ( !pic.data().isNull() ) { 629 if ( !pic.data().isNull() ) {
630#if 0 630#if 0
631 QByteArray input; 631 QByteArray input;
632 QDataStream s( input, IO_WriteOnly ); 632 QDataStream s( input, IO_WriteOnly );
633 s.setVersion( 4 ); 633 s.setVersion( 4 );
634 s << pic.data(); 634 s << pic.data();
635 line.setValue( input ); 635 line.setValue( input );
636#else 636#else
637 QCString input; 637 QCString input;
638 QDataStream s( input, IO_WriteOnly ); 638 QDataStream s( input, IO_WriteOnly );
639 s.setVersion( 4 ); 639 s.setVersion( 4 );
640 s << pic.data(); 640 s << pic.data();
641 //QCString cs(line.value().asCString()); 641 //QCString cs(line.value().asCString());
642 //QImage qi(cs); 642 //QImage qi(cs);
643 line.setValue( input ); 643 line.setValue( input );
644#endif 644#endif
645 645
646 line.addParameter( "encoding", "b" ); 646 line.addParameter( "encoding", "b" );
647 line.addParameter( "type", "image/png" ); 647 line.addParameter( "type", "image/png" );
648 } 648 }
649 } else if ( !pic.url().isEmpty() ) { 649 } else if ( !pic.url().isEmpty() ) {
650 line.setValue( pic.url() ); 650 line.setValue( pic.url() );
651 line.addParameter( "value", "URI" ); 651 line.addParameter( "value", "URI" );
652 } 652 }
653 653
654 return line; 654 return line;
655} 655}
656 656
657Sound VCardTool::parseSound( const VCardLine &line ) 657Sound VCardTool::parseSound( const VCardLine &line )
658{ 658{
659 Sound snd; 659 Sound snd;
660 660
661 QStringList params = line.parameterList(); 661 QStringList params = line.parameterList();
662 if ( params.contains( "encoding" ) ) { 662 if ( params.contains( "encoding" ) ) {
663 qDebug("VCardTool::parseSound has to be verified"); 663 qDebug("VCardTool::parseSound has to be verified");
664//US snd.setData( line.value().asByteArray() ); 664//US snd.setData( line.value().asByteArray() );
665//US I am not sure if this is correct 665//US I am not sure if this is correct
666 QCString cs(line.value().asCString()); 666 QCString cs(line.value().asCString());
667 snd.setData( cs ); 667 snd.setData( cs );
668 } 668 }
669 else if ( params.contains( "value" ) ) { 669 else if ( params.contains( "value" ) ) {
670 if ( line.parameter( "value" ).lower() == "uri" ) 670 if ( line.parameter( "value" ).lower() == "uri" )
671 snd.setUrl( line.value().asString() ); 671 snd.setUrl( line.value().asString() );
672 } 672 }
673 673
674/* TODO: support sound types 674/* TODO: support sound types
675 if ( params.contains( "type" ) ) 675 if ( params.contains( "type" ) )
676 snd.setType( line.parameter( "type" ) ); 676 snd.setType( line.parameter( "type" ) );
677*/ 677*/
678 678
679 return snd; 679 return snd;
680} 680}
681 681
682VCardLine VCardTool::createSound( const Sound &snd ) 682VCardLine VCardTool::createSound( const Sound &snd )
683{ 683{
684 VCardLine line( "SOUND" ); 684 VCardLine line( "SOUND" );
685 685
686 if ( snd.isIntern() ) { 686 if ( snd.isIntern() ) {
687 if ( !snd.data().isEmpty() ) { 687 if ( !snd.data().isEmpty() ) {
688 qDebug("VCardTool::createSound has to be verified"); 688 qDebug("VCardTool::createSound has to be verified");
689//US line.setValue( snd.data() ); 689//US line.setValue( snd.data() );
690 690
691//US I am not sure if this is correct 691//US I am not sure if this is correct
692 QCString cs(snd.data()); 692 QCString cs(snd.data());
693 line.setValue( cs ); 693 line.setValue( cs );
694 694
695 695
696 line.addParameter( "encoding", "b" ); 696 line.addParameter( "encoding", "b" );
697 // TODO: need to store sound type!!! 697 // TODO: need to store sound type!!!
698 } 698 }
699 } else if ( !snd.url().isEmpty() ) { 699 } else if ( !snd.url().isEmpty() ) {
700 line.setValue( snd.url() ); 700 line.setValue( snd.url() );
701 line.addParameter( "value", "URI" ); 701 line.addParameter( "value", "URI" );
702 } 702 }
703 703
704 return line; 704 return line;
705} 705}
706 706
707Key VCardTool::parseKey( const VCardLine &line ) 707Key VCardTool::parseKey( const VCardLine &line )
708{ 708{
709 Key key; 709 Key key;
710 710
711 QStringList params = line.parameterList(); 711 QStringList params = line.parameterList();
712 if ( params.contains( "encoding" ) ) { 712 if ( params.contains( "encoding" ) ) {
713 qDebug("VCardTool::parseKey has to be verified"); 713 qDebug("VCardTool::parseKey has to be verified");
714//US key.setBinaryData( line.value().asByteArray() ); 714//US key.setBinaryData( line.value().asByteArray() );
715 715
716//US I am not sure if this is correct 716//US I am not sure if this is correct
717 QCString cs( line.value().asCString() ); 717 QCString cs( line.value().asCString() );
718 key.setBinaryData( cs ); 718 key.setBinaryData( cs );
719 } 719 }
720 else 720 else
721 key.setTextData( line.value().asString() ); 721 key.setTextData( line.value().asString() );
722 722
723 if ( params.contains( "type" ) ) { 723 if ( params.contains( "type" ) ) {
724 if ( line.parameter( "type" ).lower() == "x509" ) 724 if ( line.parameter( "type" ).lower() == "x509" )
725 key.setType( Key::X509 ); 725 key.setType( Key::X509 );
726 else if ( line.parameter( "type" ).lower() == "pgp" ) 726 else if ( line.parameter( "type" ).lower() == "pgp" )
727 key.setType( Key::PGP ); 727 key.setType( Key::PGP );
728 else { 728 else {
729 key.setType( Key::Custom ); 729 key.setType( Key::Custom );
730 key.setCustomTypeString( line.parameter( "type" ) ); 730 key.setCustomTypeString( line.parameter( "type" ) );
731 } 731 }
732 } 732 }
733 733
734 return key; 734 return key;
735} 735}
736 736
737VCardLine VCardTool::createKey( const Key &key ) 737VCardLine VCardTool::createKey( const Key &key )
738{ 738{
739 VCardLine line( "KEY" ); 739 VCardLine line( "KEY" );
740 740
741 if ( key.isBinary() ) { 741 if ( key.isBinary() ) {
742 if ( !key.binaryData().isEmpty() ) { 742 if ( !key.binaryData().isEmpty() ) {
743 qDebug("VCardTool::createKey has to be verified"); 743 qDebug("VCardTool::createKey has to be verified");
744//US line.setValue( key.binaryData() ); 744//US line.setValue( key.binaryData() );
745//US I am not sure if this is correct 745//US I am not sure if this is correct
746 QCString cs(key.binaryData()); 746 QCString cs(key.binaryData());
747 line.setValue( cs ); 747 line.setValue( cs );
748 748
749 749
750 line.addParameter( "encoding", "b" ); 750 line.addParameter( "encoding", "b" );
751 } 751 }
752 } else if ( !key.textData().isEmpty() ) 752 } else if ( !key.textData().isEmpty() )
753 line.setValue( key.textData() ); 753 line.setValue( key.textData() );
754 754
755 if ( key.type() == Key::X509 ) 755 if ( key.type() == Key::X509 )
756 line.addParameter( "type", "X509" ); 756 line.addParameter( "type", "X509" );
757 else if ( key.type() == Key::PGP ) 757 else if ( key.type() == Key::PGP )
758 line.addParameter( "type", "PGP" ); 758 line.addParameter( "type", "PGP" );
759 else if ( key.type() == Key::Custom ) 759 else if ( key.type() == Key::Custom )
760 line.addParameter( "type", key.customTypeString() ); 760 line.addParameter( "type", key.customTypeString() );
761 761
762 return line; 762 return line;
763} 763}
764 764
765Secrecy VCardTool::parseSecrecy( const VCardLine &line ) 765Secrecy VCardTool::parseSecrecy( const VCardLine &line )
766{ 766{
767 Secrecy secrecy; 767 Secrecy secrecy;
768 768
769 if ( line.value().asString().lower() == "public" ) 769 if ( line.value().asString().lower() == "public" )
770 secrecy.setType( Secrecy::Public ); 770 secrecy.setType( Secrecy::Public );
771 if ( line.value().asString().lower() == "private" ) 771 if ( line.value().asString().lower() == "private" )
772 secrecy.setType( Secrecy::Private ); 772 secrecy.setType( Secrecy::Private );
773 if ( line.value().asString().lower() == "confidential" ) 773 if ( line.value().asString().lower() == "confidential" )
774 secrecy.setType( Secrecy::Confidential ); 774 secrecy.setType( Secrecy::Confidential );
775 775
776 return secrecy; 776 return secrecy;
777} 777}
778 778
779VCardLine VCardTool::createSecrecy( const Secrecy &secrecy ) 779VCardLine VCardTool::createSecrecy( const Secrecy &secrecy )
780{ 780{
781 VCardLine line( "CLASS" ); 781 VCardLine line( "CLASS" );
782 782
783 int type = secrecy.type(); 783 int type = secrecy.type();
784 784
785 if ( type == Secrecy::Public ) 785 if ( type == Secrecy::Public )
786 line.setValue( "PUBLIC" ); 786 line.setValue( "PUBLIC" );
787 else if ( type == Secrecy::Private ) 787 else if ( type == Secrecy::Private )
788 line.setValue( "PRIVATE" ); 788 line.setValue( "PRIVATE" );
789 else if ( type == Secrecy::Confidential ) 789 else if ( type == Secrecy::Confidential )
790 line.setValue( "CONFIDENTIAL" ); 790 line.setValue( "CONFIDENTIAL" );
791 791
792 return line; 792 return line;
793} 793}
794 794
795Agent VCardTool::parseAgent( const VCardLine &line ) 795Agent VCardTool::parseAgent( const VCardLine &line )
796{ 796{
797 Agent agent; 797 Agent agent;
798 798
799 QStringList params = line.parameterList(); 799 QStringList params = line.parameterList();
800 if ( params.contains( "value" ) ) { 800 if ( params.contains( "value" ) ) {
801 if ( line.parameter( "value" ).lower() == "uri" ) 801 if ( line.parameter( "value" ).lower() == "uri" )
802 agent.setUrl( line.value().asString() ); 802 agent.setUrl( line.value().asString() );
803 } else { 803 } else {
804 QString str = line.value().asString(); 804 QString str = line.value().asString();
805 805
806//US using the old implementation instead 806//US using the old implementation instead
807 qDebug("VCardTool::parseAgent has to be verified"); 807 qDebug("VCardTool::parseAgent has to be verified");
808/*US 808/*US
809 str.replace( "\\n", "\r\n" ); 809 str.replace( "\\n", "\r\n" );
810 str.replace( "\\N", "\r\n" ); 810 str.replace( "\\N", "\r\n" );
811 str.replace( "\\;", ";" ); 811 str.replace( "\\;", ";" );
812 str.replace( "\\:", ":" ); 812 str.replace( "\\:", ":" );
813 str.replace( "\\,", "," ); 813 str.replace( "\\,", "," );
814*/ 814*/
815 str.replace( QRegExp("\\n") , "\r\n" ); 815 str.replace( QRegExp("\\\\n") , "\r\n" );
816 str.replace( QRegExp("\\N") , "\r\n" ); 816 str.replace( QRegExp("\\\\N") , "\r\n" );
817 str.replace( QRegExp("\\;") , ";" ); 817 str.replace( QRegExp("\\\\;") , ";" );
818 str.replace( QRegExp("\\:") , ":" ); 818 str.replace( QRegExp("\\\\:") , ":" );
819 str.replace( QRegExp("\\,") , "," ); 819 str.replace( QRegExp("\\\\,") , "," );
820 820
821 Addressee::List list = parseVCards( str ); 821 Addressee::List list = parseVCards( str );
822 if ( list.count() > 0 ) { 822 if ( list.count() > 0 ) {
823 Addressee *addr = new Addressee; 823 Addressee *addr = new Addressee;
824 *addr = list[ 0 ]; 824 *addr = list[ 0 ];
825 agent.setAddressee( addr ); 825 agent.setAddressee( addr );
826 } 826 }
827 } 827 }
828 828
829 return agent; 829 return agent;
830} 830}
831 831
832VCardLine VCardTool::createAgent( VCard::Version version, const Agent &agent ) 832VCardLine VCardTool::createAgent( VCard::Version version, const Agent &agent )
833{ 833{
834 VCardLine line( "AGENT" ); 834 VCardLine line( "AGENT" );
835 835
836 if ( agent.isIntern() ) { 836 if ( agent.isIntern() ) {
837 if ( agent.addressee() != 0 ) { 837 if ( agent.addressee() != 0 ) {
838 Addressee::List list; 838 Addressee::List list;
839 list.append( *agent.addressee() ); 839 list.append( *agent.addressee() );
840 840
841 QString str = createVCards( list, version ); 841 QString str = createVCards( list, version );
842 842
843//US using the old implementation instead 843//US using the old implementation instead
844 qDebug("VCardTool::createAgent has to be verified"); 844 qDebug("VCardTool::createAgent has to be verified");
845/*US 845/*US
846 str.replace( "\r\n", "\\n" ); 846 str.replace( "\r\n", "\\n" );
847 str.replace( ";", "\\;" ); 847 str.replace( ";", "\\;" );
848 str.replace( ":", "\\:" ); 848 str.replace( ":", "\\:" );
849 str.replace( ",", "\\," ); 849 str.replace( ",", "\\," );
850*/ 850*/
851 str.replace( QRegExp("\r\n"), "\\n" ); 851 str.replace( QRegExp("\r\n"), "\\n" );
852 str.replace( QRegExp(";"), "\\;" ); 852 str.replace( QRegExp(";"), "\\;" );
853 str.replace( QRegExp(":"), "\\:" ); 853 str.replace( QRegExp(":"), "\\:" );
854 str.replace( QRegExp(","), "\\," ); 854 str.replace( QRegExp(","), "\\," );
855 line.setValue( str ); 855 line.setValue( str );
856 } 856 }
857 } else if ( !agent.url().isEmpty() ) { 857 } else if ( !agent.url().isEmpty() ) {
858 line.setValue( agent.url() ); 858 line.setValue( agent.url() );
859 line.addParameter( "value", "URI" ); 859 line.addParameter( "value", "URI" );
860 } 860 }
861 861
862 return line; 862 return line;
863} 863}
864 864
865QStringList VCardTool::splitString( const QChar &sep, const QString &str ) 865QStringList VCardTool::splitString( const QChar &sep, const QString &str )
866{ 866{
867 QStringList list; 867 QStringList list;
868 QString value( str ); 868 QString value( str );
869 869
870 int start = 0; 870 int start = 0;
871 int pos = value.find( sep, start ); 871 int pos = value.find( sep, start );
872 872
873 while ( pos != -1 ) { 873 while ( pos != -1 ) {
874 if ( value[ pos - 1 ] != '\\' ) { 874 if ( value[ pos - 1 ] != '\\' ) {
875 if ( pos > start && pos <= (int)value.length() ) 875 if ( pos > start && pos <= (int)value.length() )
876 list << value.mid( start, pos - start ); 876 list << value.mid( start, pos - start );
877 else 877 else
878 list << QString::null; 878 list << QString::null;
879 879
880 start = pos + 1; 880 start = pos + 1;
881 pos = value.find( sep, start ); 881 pos = value.find( sep, start );
882 } else { 882 } else {
883 if ( pos != 0 ) { 883 if ( pos != 0 ) {
884 value.replace( pos - 1, 2, sep ); 884 value.replace( pos - 1, 2, sep );
885 pos = value.find( sep, pos ); 885 pos = value.find( sep, pos );
886 } else 886 } else
887 pos = value.find( sep, pos + 1 ); 887 pos = value.find( sep, pos + 1 );
888 } 888 }
889 } 889 }
890 890
891 int l = value.length() - 1; 891 int l = value.length() - 1;
892 if ( value.mid( start, l - start + 1 ).length() > 0 ) 892 if ( value.mid( start, l - start + 1 ).length() > 0 )
893 list << value.mid( start, l - start + 1 ); 893 list << value.mid( start, l - start + 1 );
894 else 894 else
895 list << QString::null; 895 list << QString::null;
896 896
897 return list; 897 return list;
898} 898}