Diffstat (limited to 'kabc/vcardparser/vcardtool.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r-- | kabc/vcardparser/vcardtool.cpp | 1 |
1 files changed, 1 insertions, 0 deletions
diff --git a/kabc/vcardparser/vcardtool.cpp b/kabc/vcardparser/vcardtool.cpp index 71f29d7..3fb212e 100644 --- a/kabc/vcardparser/vcardtool.cpp +++ b/kabc/vcardparser/vcardtool.cpp @@ -1,315 +1,316 @@ /* This file is part of libkabc. Copyright (c) 2003 Tobias Koenig <tokoe@kde.org> This library is free software; you can redistribute it and/or modify it under the terms of the GNU Library General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public License for more details. You should have received a copy of the GNU Library General Public License along with this library; see the file COPYING.LIB. If not, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ #include <qdatastream.h> #include <qstring.h> #include <qregexp.h> #include <kmdcodec.h> #include "agent.h" #include "key.h" #include "picture.h" #include "secrecy.h" #include "sound.h" #include "vcardtool.h" using namespace KABC; VCardTool::VCardTool() { mAddressTypeMap.insert( "dom", Address::Dom ); mAddressTypeMap.insert( "intl", Address::Intl ); mAddressTypeMap.insert( "postal", Address::Postal ); mAddressTypeMap.insert( "parcel", Address::Parcel ); mAddressTypeMap.insert( "home", Address::Home ); mAddressTypeMap.insert( "work", Address::Work ); mAddressTypeMap.insert( "pref", Address::Pref ); mPhoneTypeMap.insert( "HOME", PhoneNumber::Home ); mPhoneTypeMap.insert( "WORK", PhoneNumber::Work ); mPhoneTypeMap.insert( "MSG", PhoneNumber::Msg ); mPhoneTypeMap.insert( "PREF", PhoneNumber::Pref ); mPhoneTypeMap.insert( "VOICE", PhoneNumber::Voice ); mPhoneTypeMap.insert( "FAX", PhoneNumber::Fax ); mPhoneTypeMap.insert( "CELL", PhoneNumber::Cell ); mPhoneTypeMap.insert( "VIDEO", PhoneNumber::Video ); mPhoneTypeMap.insert( "BBS", PhoneNumber::Bbs ); mPhoneTypeMap.insert( "MODEM", PhoneNumber::Modem ); mPhoneTypeMap.insert( "CAR", PhoneNumber::Car ); mPhoneTypeMap.insert( "ISDN", PhoneNumber::Isdn ); mPhoneTypeMap.insert( "PCS", PhoneNumber::Pcs ); mPhoneTypeMap.insert( "PAGER", PhoneNumber::Pager ); + mPhoneTypeMap.insert( "SIP", PhoneNumber::Sip ); } VCardTool::~VCardTool() { } QString VCardTool::createVCards( Addressee::List list, VCard::Version version ) { VCard::List vCardList; Addressee::List::Iterator addrIt; for ( addrIt = list.begin(); addrIt != list.end(); ++addrIt ) { VCard card; QStringList::ConstIterator strIt; // ADR + LABEL Address::List addresses = (*addrIt).addresses(); for ( Address::List::Iterator it = addresses.begin(); it != addresses.end(); ++it ) { QStringList address; /*US address.append( (*it).postOfficeBox().replace( ';', "\\;" ) ); address.append( (*it).extended().replace( ';', "\\;" ) ); address.append( (*it).street().replace( ';', "\\;" ) ); address.append( (*it).locality().replace( ';', "\\;" ) ); address.append( (*it).region().replace( ';', "\\;" ) ); address.append( (*it).postalCode().replace( ';', "\\;" ) ); address.append( (*it).country().replace( ';', "\\;" ) ); */ //US using the old implementation instead //qDebug("VCardTool::createVCards has to be verified"); address.append( (*it).postOfficeBox().replace( QRegExp(";"), "\\;" ) ); address.append( (*it).extended().replace( QRegExp(";"), "\\;" ) ); address.append( (*it).street().replace( QRegExp(";"), "\\;" ) ); address.append( (*it).locality().replace( QRegExp(";"), "\\;" ) ); address.append( (*it).region().replace( QRegExp(";"), "\\;" ) ); address.append( (*it).postalCode().replace( QRegExp(";"), "\\;" ) ); address.append( (*it).country().replace( QRegExp(";"), "\\;" ) ); VCardLine adrLine( "ADR", address.join( ";" ) ); VCardLine labelLine( "LABEL", (*it).label() ); bool hasLabel = !(*it).label().isEmpty(); QMap<QString, int>::Iterator typeIt; for ( typeIt = mAddressTypeMap.begin(); typeIt != mAddressTypeMap.end(); ++typeIt ) { if ( typeIt.data() & (*it).type() ) { if ( version == VCard::v3_0 ) { adrLine.addParameter( "TYPE", typeIt.key().lower() ); } else { adrLine.addParameter( "TYPE", typeIt.key() ); } if ( hasLabel ) { if ( version == VCard::v3_0 ) { labelLine.addParameter( "TYPE", typeIt.key().lower() ); } else { labelLine.addParameter( "TYPE", typeIt.key() ); } } } } card.addLine( adrLine ); if ( hasLabel ) card.addLine( labelLine ); } // AGENT card.addLine( createAgent( version, (*addrIt).agent() ) ); // BDAY card.addLine( VCardLine( "BDAY", createDateTime( (*addrIt).birthday() ) ) ); // CATEGORIES if ( version == VCard::v3_0 ) { QStringList categories = (*addrIt).categories(); QStringList::Iterator catIt; for ( catIt = categories.begin(); catIt != categories.end(); ++catIt ) { //US using the old implementation instead // qDebug("VCardTool::createVCards has to be verified"); //US (*catIt).replace( ',', "\\," ); (*catIt).replace( QRegExp(","), "\\," ); } card.addLine( VCardLine( "CATEGORIES", categories.join( "," ) ) ); } // CLASS if ( version == VCard::v3_0 ) { card.addLine( createSecrecy( (*addrIt).secrecy() ) ); } // EMAIL QStringList emails = (*addrIt).emails(); bool pref = true; for ( strIt = emails.begin(); strIt != emails.end(); ++strIt ) { VCardLine line( "EMAIL", *strIt ); if ( pref == true ) { line.addParameter( "TYPE", "PREF" ); pref = false; } card.addLine( line ); } // FN card.addLine( VCardLine( "FN", (*addrIt).formattedName() ) ); // GEO Geo geo = (*addrIt).geo(); if ( geo.isValid() ) { QString str; str.sprintf( "%.6f;%.6f", geo.latitude(), geo.longitude() ); card.addLine( VCardLine( "GEO", str ) ); } // KEY Key::List keys = (*addrIt).keys(); Key::List::ConstIterator keyIt; for ( keyIt = keys.begin(); keyIt != keys.end(); ++keyIt ) card.addLine( createKey( *keyIt ) ); // LOGO card.addLine( createPicture( "LOGO", (*addrIt).logo() ) ); // MAILER card.addLine( VCardLine( "MAILER", (*addrIt).mailer() ) ); // N QStringList name; //US using the old implementation instead //qDebug("VCardTool::createVCards has to be verified"); /*US name.append( (*addrIt).familyName().replace( ';', "\\;" ) ); name.append( (*addrIt).givenName().replace( ';', "\\;" ) ); name.append( (*addrIt).additionalName().replace( ';', "\\;" ) ); name.append( (*addrIt).prefix().replace( ';', "\\;" ) ); name.append( (*addrIt).suffix().replace( ';', "\\;" ) ); */ name.append( (*addrIt).familyName().replace( QRegExp(";"), "\\;" ) ); name.append( (*addrIt).givenName().replace( QRegExp(";"), "\\;" ) ); name.append( (*addrIt).additionalName().replace( QRegExp(";"), "\\;" ) ); name.append( (*addrIt).prefix().replace( QRegExp(";"), "\\;" ) ); name.append( (*addrIt).suffix().replace( QRegExp(";"), "\\;" ) ); if ( !name.join( "" ).isEmpty() ) card.addLine( VCardLine( "N", name.join( ";" ) ) ); // NICKNAME if ( version == VCard::v3_0 ) card.addLine( VCardLine( "NICKNAME", (*addrIt).nickName() ) ); // NOTE card.addLine( VCardLine( "NOTE", (*addrIt).note() ) ); // ORG card.addLine( VCardLine( "ORG", (*addrIt).organization() ) ); // PHOTO card.addLine( createPicture( "PHOTO", (*addrIt).photo() ) ); // PROID if ( version == VCard::v3_0 ) card.addLine( VCardLine( "PRODID", (*addrIt).productId() ) ); // REV card.addLine( VCardLine( "REV", createDateTime( (*addrIt).revision() ) ) ); // ROLE card.addLine( VCardLine( "ROLE", (*addrIt).role() ) ); // SORT-STRING if ( version == VCard::v3_0 ) card.addLine( VCardLine( "SORT-STRING", (*addrIt).sortString() ) ); // SOUND card.addLine( createSound( (*addrIt).sound() ) ); // TEL PhoneNumber::List phoneNumbers = (*addrIt).phoneNumbers(); PhoneNumber::List::ConstIterator phoneIt; for ( phoneIt = phoneNumbers.begin(); phoneIt != phoneNumbers.end(); ++phoneIt ) { VCardLine line( "TEL", (*phoneIt).number() ); QMap<QString, int>::Iterator typeIt; for ( typeIt = mPhoneTypeMap.begin(); typeIt != mPhoneTypeMap.end(); ++typeIt ) { if ( typeIt.data() & (*phoneIt).type() ) if ( version == VCard::v3_0 ) line.addParameter( "TYPE", typeIt.key().lower() ); else line.addParameter( "TYPE", typeIt.key() ); } card.addLine( line ); } // TITLE card.addLine( VCardLine( "TITLE", (*addrIt).title() ) ); // TZ TimeZone timeZone = (*addrIt).timeZone(); if ( timeZone.isValid() ) { QString str; int neg = 1; if ( timeZone.offset() < 0 ) neg = -1; str.sprintf( "%c%02d:%02d", ( timeZone.offset() >= 0 ? '+' : '-' ), ( timeZone.offset() / 60 ) * neg, ( timeZone.offset() % 60 ) * neg ); card.addLine( VCardLine( "TZ", str ) ); } // UID card.addLine( VCardLine( "UID", (*addrIt).uid() ) ); // URL card.addLine( VCardLine( "URL", (*addrIt).url().url() ) ); // VERSION if ( version == VCard::v2_1 ) card.addLine( VCardLine( "VERSION", "2.1" ) ); if ( version == VCard::v3_0 ) card.addLine( VCardLine( "VERSION", "3.0" ) ); // X- QStringList customs = (*addrIt).customs(); for ( strIt = customs.begin(); strIt != customs.end(); ++strIt ) { QString identifier = "X-" + (*strIt).left( (*strIt).find( ":" ) ); QString value = (*strIt).mid( (*strIt).find( ":" ) + 1 ); if ( value.isEmpty() ) continue; card.addLine( VCardLine( identifier, value ) ); } vCardList.append( card ); } return VCardParser::createVCards( vCardList ); } Addressee::List VCardTool::parseVCards( const QString& vcard ) { QChar semicolonSep( ';' ); QChar commaSep( ',' ); QString identifier; Addressee::List addrList; VCard::List vCardList = VCardParser::parseVCards( vcard ); VCard::List::Iterator cardIt; for ( cardIt = vCardList.begin(); cardIt != vCardList.end(); ++cardIt ) { Addressee addr; QStringList idents = (*cardIt).identifiers(); |