summaryrefslogtreecommitdiffabout
Side-by-side diff
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--kabc/vcardparser/vcardtool.cpp1
1 files changed, 1 insertions, 0 deletions
diff --git a/kabc/vcardparser/vcardtool.cpp b/kabc/vcardparser/vcardtool.cpp
index 32b6c1e..0cf72c0 100644
--- a/kabc/vcardparser/vcardtool.cpp
+++ b/kabc/vcardparser/vcardtool.cpp
@@ -1,118 +1,119 @@
/*
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 "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 );
}
VCardTool::~VCardTool()
{
}
// TODO: make list a const&
QString VCardTool::createVCards( Addressee::List list, VCard::Version version )
{
VCard::List vCardList;
static const QRegExp semiExp(";");
Addressee::List::ConstIterator addrIt;
Addressee::List::ConstIterator listEnd( list.end() );
for ( addrIt = list.begin(); addrIt != listEnd; ++addrIt ) {
VCard card;
QStringList::ConstIterator strIt;
// ADR + LABEL
const Address::List addresses = (*addrIt).addresses();
for ( Address::List::ConstIterator it = addresses.begin(); it != addresses.end(); ++it ) {
QStringList address;
bool isEmpty = ( (*it).postOfficeBox().isEmpty() &&
(*it).extended().isEmpty() &&
(*it).street().isEmpty() &&
(*it).locality().isEmpty() &&
(*it).region().isEmpty() &&
(*it).postalCode().isEmpty() &&
(*it).country().isEmpty() );
address.append( (*it).postOfficeBox().replace( semiExp, "\\;" ) );
address.append( (*it).extended().replace( semiExp, "\\;" ) );
address.append( (*it).street().replace( semiExp, "\\;" ) );
address.append( (*it).locality().replace( semiExp, "\\;" ) );
address.append( (*it).region().replace( semiExp, "\\;" ) );
address.append( (*it).postalCode().replace( semiExp, "\\;" ) );
address.append( (*it).country().replace( semiExp, "\\;" ) );
VCardLine adrLine( "ADR", address.join( ";" ) );
if ( version == VCard::v2_1 ) {
adrLine.addParameter( "CHARSET", "UTF-8" );
adrLine.addParameter( "ENCODING", "8BIT" );
}
VCardLine labelLine( "LABEL", (*it).label() );
if ( version == VCard::v2_1 ) {
labelLine.addParameter( "CHARSET", "UTF-8" );
labelLine.addParameter( "ENCODING", "8BIT" );
}
bool hasLabel = !(*it).label().isEmpty();
QMap<QString, int>::ConstIterator typeIt;
for ( typeIt = mAddressTypeMap.begin(); typeIt != mAddressTypeMap.end(); ++typeIt ) {
if ( typeIt.data() & (*it).type() ) {
adrLine.addParameter( "TYPE", typeIt.key() );
if ( hasLabel )
labelLine.addParameter( "TYPE", typeIt.key() );
}
}