summaryrefslogtreecommitdiffabout
path: root/kabc/vcard21parser.cpp
Unidiff
Diffstat (limited to 'kabc/vcard21parser.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r--kabc/vcard21parser.cpp40
1 files changed, 23 insertions, 17 deletions
diff --git a/kabc/vcard21parser.cpp b/kabc/vcard21parser.cpp
index 60d02b8..e24a9dc 100644
--- a/kabc/vcard21parser.cpp
+++ b/kabc/vcard21parser.cpp
@@ -22,16 +22,18 @@
22Enhanced Version of the file for platform independent KDE tools. 22Enhanced Version of the file for platform independent KDE tools.
23Copyright (c) 2004 Ulf Schenk 23Copyright (c) 2004 Ulf Schenk
24 24
25$Id$ 25$Id$
26*/ 26*/
27 27
28#include <qmap.h> 28#include <qmap.h>
29#include <qregexp.h> 29#include <qregexp.h>
30//Added by qt3to4:
31#include <Q3ValueList>
30#include <kmdcodec.h> 32#include <kmdcodec.h>
31 33
32#include "vcard21parser.h" 34#include "vcard21parser.h"
33#include "vcardconverter.h" 35#include "vcardconverter.h"
34 36
35using namespace KABC; 37using namespace KABC;
36 38
37bool VCardLineX::isValid() const 39bool VCardLineX::isValid() const
@@ -40,17 +42,17 @@ bool VCardLineX::isValid() const
40 if ( name == VCARD_BEGIN_N || name == VCARD_END_N ) 42 if ( name == VCARD_BEGIN_N || name == VCARD_END_N )
41 return false; 43 return false;
42 44
43 if ( name[0] == 'x' && name[1] == '-' ) // A custom x- line 45 if ( name[0] == 'x' && name[1] == '-' ) // A custom x- line
44 return true; 46 return true;
45 47
46 // This is long but it makes it a bit faster (and saves me from using 48 // This is long but it makes it a bit faster (and saves me from using
47 // a tree which is probably the ideal situation, but a bit memory heavy) 49 // a tree which is probably the ideal situation, but a bit memory heavy)
48 switch( name[0] ) { 50 switch( name[0].unicode() ) {
49 case 'a': 51 case 'a':
50 if ( name == VCARD_ADR && qualified && 52 if ( name == VCARD_ADR && qualified &&
51 (qualifiers.contains(VCARD_ADR_DOM) || 53 (qualifiers.contains(VCARD_ADR_DOM) ||
52 qualifiers.contains(VCARD_ADR_INTL) || 54 qualifiers.contains(VCARD_ADR_INTL) ||
53 qualifiers.contains(VCARD_ADR_POSTAL) || 55 qualifiers.contains(VCARD_ADR_POSTAL) ||
54 qualifiers.contains(VCARD_ADR_HOME) || 56 qualifiers.contains(VCARD_ADR_HOME) ||
55 qualifiers.contains(VCARD_ADR_WORK) || 57 qualifiers.contains(VCARD_ADR_WORK) ||
56 qualifiers.contains(VCARD_ADR_PREF) 58 qualifiers.contains(VCARD_ADR_PREF)
@@ -264,17 +266,17 @@ KABC::Addressee VCard21Parser::readFromString( const QString &data)
264 addressee.setUrl(KURL(tmpStr)); 266 addressee.setUrl(KURL(tmpStr));
265 } 267 }
266 268
267 //set the addressee's birthday 269 //set the addressee's birthday
268 tmpStr = mVCard->getValue(VCARD_BDAY); 270 tmpStr = mVCard->getValue(VCARD_BDAY);
269 addressee.setBirthday(VCardStringToDate(tmpStr)); 271 addressee.setBirthday(VCardStringToDate(tmpStr));
270 272
271 //set the addressee's phone numbers 273 //set the addressee's phone numbers
272 for ( QValueListIterator<VCardLineX> i = mVCard->_vcdata->begin();i != mVCard->_vcdata->end(); ++i ) { 274 for ( Q3ValueListIterator<VCardLineX> i = mVCard->_vcdata->begin();i != mVCard->_vcdata->end(); ++i ) {
273 if ( (*i).name == VCARD_TEL ) { 275 if ( (*i).name == VCARD_TEL ) {
274 int type = 0; 276 int type = 0;
275 if ( (*i).qualified ) { 277 if ( (*i).qualified ) {
276 if ( (*i).qualifiers.contains( VCARD_TEL_HOME ) ) 278 if ( (*i).qualifiers.contains( VCARD_TEL_HOME ) )
277 type |= PhoneNumber::Home; 279 type |= PhoneNumber::Home;
278 if ( (*i).qualifiers.contains( VCARD_TEL_WORK ) ) 280 if ( (*i).qualifiers.contains( VCARD_TEL_WORK ) )
279 type |= PhoneNumber::Work; 281 type |= PhoneNumber::Work;
280 if ( (*i).qualifiers.contains( VCARD_TEL_PREF ) ) 282 if ( (*i).qualifiers.contains( VCARD_TEL_PREF ) )
@@ -303,17 +305,17 @@ KABC::Addressee VCard21Parser::readFromString( const QString &data)
303 type |= PhoneNumber::Pcs; 305 type |= PhoneNumber::Pcs;
304 306
305 } 307 }
306 addressee.insertPhoneNumber( PhoneNumber( (*i).parameters[ 0 ], type ) ); 308 addressee.insertPhoneNumber( PhoneNumber( (*i).parameters[ 0 ], type ) );
307 } 309 }
308 } 310 }
309 addressee.makePhoneNumbersOLcompatible(); 311 addressee.makePhoneNumbersOLcompatible();
310 //set the addressee's addresses 312 //set the addressee's addresses
311 for ( QValueListIterator<VCardLineX> i = mVCard->_vcdata->begin();i != mVCard->_vcdata->end(); ++i ) { 313 for ( Q3ValueListIterator<VCardLineX> i = mVCard->_vcdata->begin();i != mVCard->_vcdata->end(); ++i ) {
312 if ( (*i).name == VCARD_ADR ) { 314 if ( (*i).name == VCARD_ADR ) {
313 int type = 0; 315 int type = 0;
314 if ( (*i).qualified ) { 316 if ( (*i).qualified ) {
315 if ( (*i).qualifiers.contains( VCARD_ADR_DOM ) ) 317 if ( (*i).qualifiers.contains( VCARD_ADR_DOM ) )
316 type |= Address::Dom; 318 type |= Address::Dom;
317 if ( (*i).qualifiers.contains( VCARD_ADR_INTL ) ) 319 if ( (*i).qualifiers.contains( VCARD_ADR_INTL ) )
318 type |= Address::Intl; 320 type |= Address::Intl;
319 if ( (*i).qualifiers.contains( VCARD_ADR_POSTAL ) ) 321 if ( (*i).qualifiers.contains( VCARD_ADR_POSTAL ) )
@@ -322,17 +324,20 @@ KABC::Addressee VCard21Parser::readFromString( const QString &data)
322 type |= Address::Parcel; 324 type |= Address::Parcel;
323 if ( (*i).qualifiers.contains( VCARD_ADR_HOME ) ) 325 if ( (*i).qualifiers.contains( VCARD_ADR_HOME ) )
324 type |= Address::Home; 326 type |= Address::Home;
325 if ( (*i).qualifiers.contains( VCARD_ADR_WORK ) ) 327 if ( (*i).qualifiers.contains( VCARD_ADR_WORK ) )
326 type |= Address::Work; 328 type |= Address::Work;
327 if ( (*i).qualifiers.contains( VCARD_ADR_PREF ) ) 329 if ( (*i).qualifiers.contains( VCARD_ADR_PREF ) )
328 type |= Address::Pref; 330 type |= Address::Pref;
329 } 331 }
330 addressee.insertAddress( readAddressFromQStringList( (*i).parameters, type ) ); 332 QStringList tmp;
333 for(Q3ValueList<QString>::const_iterator ii=(*i).parameters.begin();ii!=(*i).parameters.end();++ii)
334 tmp.push_back(*ii);
335 addressee.insertAddress( readAddressFromQStringList( tmp, type ) );
331 } 336 }
332 } 337 }
333 338
334 //set the addressee's delivery label 339 //set the addressee's delivery label
335 tmpStr = mVCard->getValue(VCARD_LABEL); 340 tmpStr = mVCard->getValue(VCARD_LABEL);
336 if (!tmpStr.isEmpty()) { 341 if (!tmpStr.isEmpty()) {
337qDebug("VCard21Parser::readFromString please verify if replace is correct"); 342qDebug("VCard21Parser::readFromString please verify if replace is correct");
338//US tmpStr.replace("\r\n","\n"); 343//US tmpStr.replace("\r\n","\n");
@@ -403,20 +408,20 @@ KABC::Address VCard21Parser::readAddressFromQStringList ( const QStringList &dat
403} 408}
404 409
405 410
406VCard21ParserImpl *VCard21ParserImpl::parseVCard( const QString& vc, int *err ) 411VCard21ParserImpl *VCard21ParserImpl::parseVCard( const QString& vc, int *err )
407{ 412{
408 int _err = 0; 413 int _err = 0;
409 int _state = VC_STATE_BEGIN; 414 int _state = VC_STATE_BEGIN;
410 415
411 QValueList<VCardLineX> *_vcdata; 416 Q3ValueList<VCardLineX> *_vcdata;
412 QValueList<QString> lines; 417 QStringList lines;
413 418
414 _vcdata = new QValueList<VCardLineX>; 419 _vcdata = new Q3ValueList<VCardLineX>;
415 420
416 lines = QStringList::split( QRegExp( "[\x0d\x0a]" ), vc ); 421 lines = QStringList::split( QRegExp( "[\x0d\x0a]" ), vc );
417 422
418 // for each line in the vCard 423 // for each line in the vCard
419 for ( QStringList::Iterator j = lines.begin(); j != lines.end(); ++j ) { 424 for ( QStringList::Iterator j = lines.begin(); j != lines.end(); ++j ) {
420 VCardLineX _vcl; 425 VCardLineX _vcl;
421 426
422 // take spaces off the end - ugly but necessary hack 427 // take spaces off the end - ugly but necessary hack
@@ -496,18 +501,18 @@ VCard21ParserImpl *VCard21ParserImpl::parseVCard( const QString& vc, int *err )
496 if ( qp ) { // join any split lines 501 if ( qp ) { // join any split lines
497 while ( value.at( value.length() - 1 ) == '=' ) { 502 while ( value.at( value.length() - 1 ) == '=' ) {
498 value.remove( value.length() - 1, 1 ); 503 value.remove( value.length() - 1, 1 );
499 value.append(*( ++j )); 504 value.append(*( ++j ));
500 } 505 }
501 } 506 }
502 _vcl.parameters = QStringList::split( ';', value, true ); 507 _vcl.parameters = QStringList::split( ';', value, true );
503 if ( qp ) { // decode the quoted printable 508 if ( qp ) { // decode the quoted printable
504 for ( QStringList::Iterator z = _vcl.parameters.begin(); z != _vcl.parameters.end(); ++z ) 509 for ( QLinkedList<QString>::Iterator z = _vcl.parameters.begin(); z != _vcl.parameters.end(); ++z )
505 *z = KCodecs::quotedPrintableDecode( (*z).latin1() ); 510 *z = KCodecs::quotedPrintableDecode( (Q3CString)(*z).latin1() );
506 } 511 }
507 } 512 }
508 } else { 513 } else {
509 _err = VC_ERR_INTERNAL; 514 _err = VC_ERR_INTERNAL;
510 break; 515 break;
511 } 516 }
512 517
513 // validate VCardLineX 518 // validate VCardLineX
@@ -538,70 +543,71 @@ VCard21ParserImpl *VCard21ParserImpl::parseVCard( const QString& vc, int *err )
538 if ( _err != 0 ) { 543 if ( _err != 0 ) {
539 delete _vcdata; 544 delete _vcdata;
540 return 0; 545 return 0;
541 } 546 }
542 547
543 return new VCard21ParserImpl( _vcdata ); 548 return new VCard21ParserImpl( _vcdata );
544} 549}
545 550
546VCard21ParserImpl::VCard21ParserImpl(QValueList<VCardLineX> *_vcd) : _vcdata(_vcd) 551VCard21ParserImpl::VCard21ParserImpl(Q3ValueList<VCardLineX> *_vcd) : _vcdata(_vcd)
547{ 552{
548} 553}
549 554
550 555
551QString VCard21ParserImpl::getValue(const QString& name, const QString& qualifier) 556QString VCard21ParserImpl::getValue(const QString& name, const QString& qualifier)
552{ 557{
553 QString failed; 558 QString failed;
554 const QString lowname = name.lower(); 559 const QString lowname = name.lower();
555 const QString lowqualifier = qualifier.lower(); 560 const QString lowqualifier = qualifier.lower();
556 561
557 for (QValueListIterator<VCardLineX> i = _vcdata->begin();i != _vcdata->end();++i) { 562 for (Q3ValueListIterator<VCardLineX> i = _vcdata->begin();i != _vcdata->end();++i) {
558 if ((*i).name == lowname && (*i).qualified && (*i).qualifiers.contains(lowqualifier)) { 563 if ((*i).name == lowname && (*i).qualified && (*i).qualifiers.contains(lowqualifier)) {
559 if ((*i).parameters.count() > 0) 564 if ((*i).parameters.count() > 0)
560 return (*i).parameters[0]; 565 return (*i).parameters[0];
561 else return failed; 566 else return failed;
562 } 567 }
563 } 568 }
564 return failed; 569 return failed;
565} 570}
566 571
567 572
568QString VCard21ParserImpl::getValue(const QString& name) 573QString VCard21ParserImpl::getValue(const QString& name)
569{ 574{
570 QString failed; 575 QString failed;
571 const QString lowname = name.lower(); 576 const QString lowname = name.lower();
572 577
573 for (QValueListIterator<VCardLineX> i = _vcdata->begin();i != _vcdata->end();++i) { 578 for (Q3ValueListIterator<VCardLineX> i = _vcdata->begin();i != _vcdata->end();++i) {
574 if ((*i).name == lowname && !(*i).qualified) { 579 if ((*i).name == lowname && !(*i).qualified) {
575 if ((*i).parameters.count() > 0) 580 if ((*i).parameters.count() > 0)
576 return (*i).parameters[0]; 581 return (*i).parameters[0];
577 else return failed; 582 else return failed;
578 } 583 }
579 } 584 }
580 return failed; 585 return failed;
581} 586}
582 587
583 588
584QStringList VCard21ParserImpl::getValues(const QString& name) 589QStringList VCard21ParserImpl::getValues(const QString& name)
585{ 590{
586 const QString lowname = name.lower(); 591 const QString lowname = name.lower();
587 for (QValueListIterator<VCardLineX> i = _vcdata->begin();i != _vcdata->end();++i) { 592 for (Q3ValueListIterator<VCardLineX> i = _vcdata->begin();i != _vcdata->end();++i) {
588 if ((*i).name == lowname && !(*i).qualified) 593 if ((*i).name == lowname && !(*i).qualified) {
589 return (*i).parameters; 594 return QStringList( (*i).parameters );
595 }
590 } 596 }
591 // failed. 597 // failed.
592 return QStringList(); 598 return QStringList();
593} 599}
594 600
595QStringList VCard21ParserImpl::getValues(const QString& name, const QString& qualifier) 601QStringList VCard21ParserImpl::getValues(const QString& name, const QString& qualifier)
596{ 602{
597 const QString lowname = name.lower(); 603 const QString lowname = name.lower();
598 const QString lowqualifier = qualifier.lower(); 604 const QString lowqualifier = qualifier.lower();
599 for (QValueListIterator<VCardLineX> i = _vcdata->begin();i != _vcdata->end();++i) { 605 for (Q3ValueListIterator<VCardLineX> i = _vcdata->begin();i != _vcdata->end();++i) {
600 if ((*i).name == lowname && (*i).qualified && (*i).qualifiers.contains(lowqualifier)) 606 if ((*i).name == lowname && (*i).qualified && (*i).qualifiers.contains(lowqualifier))
601 return (*i).parameters; 607 return QStringList( (*i).parameters );
602 } 608 }
603 // failed. 609 // failed.
604 return QStringList(); 610 return QStringList();
605} 611}
606 612
607 613