author | Michael Krelin <hacker@klever.net> | 2007-07-04 11:23:42 (UTC) |
---|---|---|
committer | Michael Krelin <hacker@klever.net> | 2007-07-04 11:23:42 (UTC) |
commit | a08aff328d4393031d5ba7d622c2b05705a89d73 (patch) (side-by-side diff) | |
tree | 8ee90d686081c52e7c69b5ce946e9b1a7d690001 /kabc/vcard21parser.cpp | |
parent | 11edc920afe4f274c0964436633aa632c8288a40 (diff) | |
download | kdepimpi-a08aff328d4393031d5ba7d622c2b05705a89d73.zip kdepimpi-a08aff328d4393031d5ba7d622c2b05705a89d73.tar.gz kdepimpi-a08aff328d4393031d5ba7d622c2b05705a89d73.tar.bz2 |
initial public commit of qt4 portp1
-rw-r--r-- | kabc/vcard21parser.cpp | 40 |
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 @@ -18,43 +18,45 @@ Boston, MA 02111-1307, USA. */ /* Enhanced Version of the file for platform independent KDE tools. Copyright (c) 2004 Ulf Schenk $Id$ */ #include <qmap.h> #include <qregexp.h> +//Added by qt3to4: +#include <Q3ValueList> #include <kmdcodec.h> #include "vcard21parser.h" #include "vcardconverter.h" using namespace KABC; bool VCardLineX::isValid() const { // Invalid: if it is "begin:vcard" or "end:vcard" if ( name == VCARD_BEGIN_N || name == VCARD_END_N ) return false; if ( name[0] == 'x' && name[1] == '-' ) // A custom x- line return true; // This is long but it makes it a bit faster (and saves me from using // a tree which is probably the ideal situation, but a bit memory heavy) - switch( name[0] ) { + switch( name[0].unicode() ) { case 'a': if ( name == VCARD_ADR && qualified && (qualifiers.contains(VCARD_ADR_DOM) || qualifiers.contains(VCARD_ADR_INTL) || qualifiers.contains(VCARD_ADR_POSTAL) || qualifiers.contains(VCARD_ADR_HOME) || qualifiers.contains(VCARD_ADR_WORK) || qualifiers.contains(VCARD_ADR_PREF) ) ) return true; if ( name == VCARD_AGENT ) @@ -260,25 +262,25 @@ KABC::Addressee VCard21Parser::readFromString( const QString &data) tmpStr = mVCard->getValue(VCARD_URL); if (tmpStr.isEmpty()) tmpStr = mVCard->getValue(VCARD_URL, VCARD_ADR_WORK); if (tmpStr.isEmpty()) tmpStr = mVCard->getValue(VCARD_URL, VCARD_ADR_HOME); if (!tmpStr.isEmpty()) { addressee.setUrl(KURL(tmpStr)); } //set the addressee's birthday tmpStr = mVCard->getValue(VCARD_BDAY); addressee.setBirthday(VCardStringToDate(tmpStr)); //set the addressee's phone numbers - for ( QValueListIterator<VCardLineX> i = mVCard->_vcdata->begin();i != mVCard->_vcdata->end(); ++i ) { + for ( Q3ValueListIterator<VCardLineX> i = mVCard->_vcdata->begin();i != mVCard->_vcdata->end(); ++i ) { if ( (*i).name == VCARD_TEL ) { int type = 0; if ( (*i).qualified ) { if ( (*i).qualifiers.contains( VCARD_TEL_HOME ) ) type |= PhoneNumber::Home; if ( (*i).qualifiers.contains( VCARD_TEL_WORK ) ) type |= PhoneNumber::Work; if ( (*i).qualifiers.contains( VCARD_TEL_PREF ) ) type |= PhoneNumber::Pref; if ( (*i).qualifiers.contains( VCARD_TEL_VOICE ) ) type |= PhoneNumber::Voice; if ( (*i).qualifiers.contains( VCARD_TEL_FAX ) ) @@ -299,44 +301,47 @@ KABC::Addressee VCard21Parser::readFromString( const QString &data) type |= PhoneNumber::Isdn; if ( (*i).qualifiers.contains( VCARD_TEL_VIDEO ) ) type |= PhoneNumber::Video; if ( (*i).qualifiers.contains( VCARD_TEL_PCS ) ) type |= PhoneNumber::Pcs; } addressee.insertPhoneNumber( PhoneNumber( (*i).parameters[ 0 ], type ) ); } } addressee.makePhoneNumbersOLcompatible(); //set the addressee's addresses - for ( QValueListIterator<VCardLineX> i = mVCard->_vcdata->begin();i != mVCard->_vcdata->end(); ++i ) { + for ( Q3ValueListIterator<VCardLineX> i = mVCard->_vcdata->begin();i != mVCard->_vcdata->end(); ++i ) { if ( (*i).name == VCARD_ADR ) { int type = 0; if ( (*i).qualified ) { if ( (*i).qualifiers.contains( VCARD_ADR_DOM ) ) type |= Address::Dom; if ( (*i).qualifiers.contains( VCARD_ADR_INTL ) ) type |= Address::Intl; if ( (*i).qualifiers.contains( VCARD_ADR_POSTAL ) ) type |= Address::Postal; if ( (*i).qualifiers.contains( VCARD_ADR_PARCEL ) ) type |= Address::Parcel; if ( (*i).qualifiers.contains( VCARD_ADR_HOME ) ) type |= Address::Home; if ( (*i).qualifiers.contains( VCARD_ADR_WORK ) ) type |= Address::Work; if ( (*i).qualifiers.contains( VCARD_ADR_PREF ) ) type |= Address::Pref; } - addressee.insertAddress( readAddressFromQStringList( (*i).parameters, type ) ); + QStringList tmp; + for(Q3ValueList<QString>::const_iterator ii=(*i).parameters.begin();ii!=(*i).parameters.end();++ii) + tmp.push_back(*ii); + addressee.insertAddress( readAddressFromQStringList( tmp, type ) ); } } //set the addressee's delivery label tmpStr = mVCard->getValue(VCARD_LABEL); if (!tmpStr.isEmpty()) { qDebug("VCard21Parser::readFromString please verify if replace is correct"); //US tmpStr.replace("\r\n","\n"); tmpStr.replace( QRegExp("\r\n"), "\n" ); Address tmpAddress; tmpAddress.setLabel(tmpStr); addressee.insertAddress(tmpAddress); @@ -399,28 +404,28 @@ KABC::Address VCard21Parser::readAddressFromQStringList ( const QStringList &dat if ( data.count() > 6 ) mAddress.setCountry( data[6] ); return mAddress; } VCard21ParserImpl *VCard21ParserImpl::parseVCard( const QString& vc, int *err ) { int _err = 0; int _state = VC_STATE_BEGIN; - QValueList<VCardLineX> *_vcdata; - QValueList<QString> lines; + Q3ValueList<VCardLineX> *_vcdata; + QStringList lines; - _vcdata = new QValueList<VCardLineX>; + _vcdata = new Q3ValueList<VCardLineX>; lines = QStringList::split( QRegExp( "[\x0d\x0a]" ), vc ); // for each line in the vCard for ( QStringList::Iterator j = lines.begin(); j != lines.end(); ++j ) { VCardLineX _vcl; // take spaces off the end - ugly but necessary hack for ( int g = (*j).length()-1; g > 0 && (*j)[g].isSpace(); --g ) (*j)[g] = 0; // first token: @@ -492,26 +497,26 @@ VCard21ParserImpl *VCard21ParserImpl::parseVCard( const QString& vc, int *err ) do { value += *( ++j ); } while ( (*j).at( (*j).length() - 1 ) != '=' ); } else { if ( qp ) { // join any split lines while ( value.at( value.length() - 1 ) == '=' ) { value.remove( value.length() - 1, 1 ); value.append(*( ++j )); } } _vcl.parameters = QStringList::split( ';', value, true ); if ( qp ) { // decode the quoted printable - for ( QStringList::Iterator z = _vcl.parameters.begin(); z != _vcl.parameters.end(); ++z ) - *z = KCodecs::quotedPrintableDecode( (*z).latin1() ); + for ( QLinkedList<QString>::Iterator z = _vcl.parameters.begin(); z != _vcl.parameters.end(); ++z ) + *z = KCodecs::quotedPrintableDecode( (Q3CString)(*z).latin1() ); } } } else { _err = VC_ERR_INTERNAL; break; } // validate VCardLineX if ( !_vcl.isValid() ) { _err = VC_ERR_INVALID_LINE; break; } @@ -534,74 +539,75 @@ VCard21ParserImpl *VCard21ParserImpl::parseVCard( const QString& vc, int *err ) // if the vCard was valid. if ( err ) *err = _err; if ( _err != 0 ) { delete _vcdata; return 0; } return new VCard21ParserImpl( _vcdata ); } -VCard21ParserImpl::VCard21ParserImpl(QValueList<VCardLineX> *_vcd) : _vcdata(_vcd) +VCard21ParserImpl::VCard21ParserImpl(Q3ValueList<VCardLineX> *_vcd) : _vcdata(_vcd) { } QString VCard21ParserImpl::getValue(const QString& name, const QString& qualifier) { QString failed; const QString lowname = name.lower(); const QString lowqualifier = qualifier.lower(); - for (QValueListIterator<VCardLineX> i = _vcdata->begin();i != _vcdata->end();++i) { + for (Q3ValueListIterator<VCardLineX> i = _vcdata->begin();i != _vcdata->end();++i) { if ((*i).name == lowname && (*i).qualified && (*i).qualifiers.contains(lowqualifier)) { if ((*i).parameters.count() > 0) return (*i).parameters[0]; else return failed; } } return failed; } QString VCard21ParserImpl::getValue(const QString& name) { QString failed; const QString lowname = name.lower(); - for (QValueListIterator<VCardLineX> i = _vcdata->begin();i != _vcdata->end();++i) { + for (Q3ValueListIterator<VCardLineX> i = _vcdata->begin();i != _vcdata->end();++i) { if ((*i).name == lowname && !(*i).qualified) { if ((*i).parameters.count() > 0) return (*i).parameters[0]; else return failed; } } return failed; } QStringList VCard21ParserImpl::getValues(const QString& name) { const QString lowname = name.lower(); - for (QValueListIterator<VCardLineX> i = _vcdata->begin();i != _vcdata->end();++i) { - if ((*i).name == lowname && !(*i).qualified) - return (*i).parameters; + for (Q3ValueListIterator<VCardLineX> i = _vcdata->begin();i != _vcdata->end();++i) { + if ((*i).name == lowname && !(*i).qualified) { + return QStringList( (*i).parameters ); + } } // failed. return QStringList(); } QStringList VCard21ParserImpl::getValues(const QString& name, const QString& qualifier) { const QString lowname = name.lower(); const QString lowqualifier = qualifier.lower(); - for (QValueListIterator<VCardLineX> i = _vcdata->begin();i != _vcdata->end();++i) { + for (Q3ValueListIterator<VCardLineX> i = _vcdata->begin();i != _vcdata->end();++i) { if ((*i).name == lowname && (*i).qualified && (*i).qualifiers.contains(lowqualifier)) - return (*i).parameters; + return QStringList( (*i).parameters ); } // failed. return QStringList(); } |