summaryrefslogtreecommitdiffabout
Unidiff
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,214 +1,215 @@
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 <qdatastream.h> 21#include <qdatastream.h>
22#include <qstring.h> 22#include <qstring.h>
23#include <qregexp.h>
23 24
24#include "agent.h" 25#include "agent.h"
25#include "key.h" 26#include "key.h"
26#include "picture.h" 27#include "picture.h"
27#include "secrecy.h" 28#include "secrecy.h"
28#include "sound.h" 29#include "sound.h"
29 30
30#include "vcardtool.h" 31#include "vcardtool.h"
31 32
32using namespace KABC; 33using namespace KABC;
33 34
34VCardTool::VCardTool() 35VCardTool::VCardTool()
35{ 36{
36 mAddressTypeMap.insert( "dom", Address::Dom ); 37 mAddressTypeMap.insert( "dom", Address::Dom );
37 mAddressTypeMap.insert( "intl", Address::Intl ); 38 mAddressTypeMap.insert( "intl", Address::Intl );
38 mAddressTypeMap.insert( "postal", Address::Postal ); 39 mAddressTypeMap.insert( "postal", Address::Postal );
39 mAddressTypeMap.insert( "parcel", Address::Parcel ); 40 mAddressTypeMap.insert( "parcel", Address::Parcel );
40 mAddressTypeMap.insert( "home", Address::Home ); 41 mAddressTypeMap.insert( "home", Address::Home );
41 mAddressTypeMap.insert( "work", Address::Work ); 42 mAddressTypeMap.insert( "work", Address::Work );
42 mAddressTypeMap.insert( "pref", Address::Pref ); 43 mAddressTypeMap.insert( "pref", Address::Pref );
43 44
44 mPhoneTypeMap.insert( "HOME", PhoneNumber::Home ); 45 mPhoneTypeMap.insert( "HOME", PhoneNumber::Home );
45 mPhoneTypeMap.insert( "WORK", PhoneNumber::Work ); 46 mPhoneTypeMap.insert( "WORK", PhoneNumber::Work );
46 mPhoneTypeMap.insert( "MSG", PhoneNumber::Msg ); 47 mPhoneTypeMap.insert( "MSG", PhoneNumber::Msg );
47 mPhoneTypeMap.insert( "PREF", PhoneNumber::Pref ); 48 mPhoneTypeMap.insert( "PREF", PhoneNumber::Pref );
48 mPhoneTypeMap.insert( "VOICE", PhoneNumber::Voice ); 49 mPhoneTypeMap.insert( "VOICE", PhoneNumber::Voice );
49 mPhoneTypeMap.insert( "FAX", PhoneNumber::Fax ); 50 mPhoneTypeMap.insert( "FAX", PhoneNumber::Fax );
50 mPhoneTypeMap.insert( "CELL", PhoneNumber::Cell ); 51 mPhoneTypeMap.insert( "CELL", PhoneNumber::Cell );
51 mPhoneTypeMap.insert( "VIDEO", PhoneNumber::Video ); 52 mPhoneTypeMap.insert( "VIDEO", PhoneNumber::Video );
52 mPhoneTypeMap.insert( "BBS", PhoneNumber::Bbs ); 53 mPhoneTypeMap.insert( "BBS", PhoneNumber::Bbs );
53 mPhoneTypeMap.insert( "MODEM", PhoneNumber::Modem ); 54 mPhoneTypeMap.insert( "MODEM", PhoneNumber::Modem );
54 mPhoneTypeMap.insert( "CAR", PhoneNumber::Car ); 55 mPhoneTypeMap.insert( "CAR", PhoneNumber::Car );
55 mPhoneTypeMap.insert( "ISDN", PhoneNumber::Isdn ); 56 mPhoneTypeMap.insert( "ISDN", PhoneNumber::Isdn );
56 mPhoneTypeMap.insert( "PCS", PhoneNumber::Pcs ); 57 mPhoneTypeMap.insert( "PCS", PhoneNumber::Pcs );
57 mPhoneTypeMap.insert( "PAGER", PhoneNumber::Pager ); 58 mPhoneTypeMap.insert( "PAGER", PhoneNumber::Pager );
58} 59}
59 60
60VCardTool::~VCardTool() 61VCardTool::~VCardTool()
61{ 62{
62} 63}
63 64
64// TODO: make list a const& 65// TODO: make list a const&
65QString VCardTool::createVCards( Addressee::List list, VCard::Version version ) 66QString VCardTool::createVCards( Addressee::List list, VCard::Version version )
66{ 67{
67 VCard::List vCardList; 68 VCard::List vCardList;
68 static const QRegExp semiExp(";"); 69 static const QRegExp semiExp(";");
69 70
70 Addressee::List::ConstIterator addrIt; 71 Addressee::List::ConstIterator addrIt;
71 Addressee::List::ConstIterator listEnd( list.end() ); 72 Addressee::List::ConstIterator listEnd( list.end() );
72 for ( addrIt = list.begin(); addrIt != listEnd; ++addrIt ) { 73 for ( addrIt = list.begin(); addrIt != listEnd; ++addrIt ) {
73 VCard card; 74 VCard card;
74 QStringList::ConstIterator strIt; 75 QStringList::ConstIterator strIt;
75 76
76 // ADR + LABEL 77 // ADR + LABEL
77 const Address::List addresses = (*addrIt).addresses(); 78 const Address::List addresses = (*addrIt).addresses();
78 for ( Address::List::ConstIterator it = addresses.begin(); it != addresses.end(); ++it ) { 79 for ( Address::List::ConstIterator it = addresses.begin(); it != addresses.end(); ++it ) {
79 QStringList address; 80 QStringList address;
80 81
81 bool isEmpty = ( (*it).postOfficeBox().isEmpty() && 82 bool isEmpty = ( (*it).postOfficeBox().isEmpty() &&
82 (*it).extended().isEmpty() && 83 (*it).extended().isEmpty() &&
83 (*it).street().isEmpty() && 84 (*it).street().isEmpty() &&
84 (*it).locality().isEmpty() && 85 (*it).locality().isEmpty() &&
85 (*it).region().isEmpty() && 86 (*it).region().isEmpty() &&
86 (*it).postalCode().isEmpty() && 87 (*it).postalCode().isEmpty() &&
87 (*it).country().isEmpty() ); 88 (*it).country().isEmpty() );
88 89
89 address.append( (*it).postOfficeBox().replace( semiExp, "\\;" ) ); 90 address.append( (*it).postOfficeBox().replace( semiExp, "\\;" ) );
90 address.append( (*it).extended().replace( semiExp, "\\;" ) ); 91 address.append( (*it).extended().replace( semiExp, "\\;" ) );
91 address.append( (*it).street().replace( semiExp, "\\;" ) ); 92 address.append( (*it).street().replace( semiExp, "\\;" ) );
92 address.append( (*it).locality().replace( semiExp, "\\;" ) ); 93 address.append( (*it).locality().replace( semiExp, "\\;" ) );
93 address.append( (*it).region().replace( semiExp, "\\;" ) ); 94 address.append( (*it).region().replace( semiExp, "\\;" ) );
94 address.append( (*it).postalCode().replace( semiExp, "\\;" ) ); 95 address.append( (*it).postalCode().replace( semiExp, "\\;" ) );
95 address.append( (*it).country().replace( semiExp, "\\;" ) ); 96 address.append( (*it).country().replace( semiExp, "\\;" ) );
96 97
97 VCardLine adrLine( "ADR", address.join( ";" ) ); 98 VCardLine adrLine( "ADR", address.join( ";" ) );
98 if ( version == VCard::v2_1 ) { 99 if ( version == VCard::v2_1 ) {
99 adrLine.addParameter( "CHARSET", "UTF-8" ); 100 adrLine.addParameter( "CHARSET", "UTF-8" );
100 adrLine.addParameter( "ENCODING", "8BIT" ); 101 adrLine.addParameter( "ENCODING", "8BIT" );
101 } 102 }
102 103
103 VCardLine labelLine( "LABEL", (*it).label() ); 104 VCardLine labelLine( "LABEL", (*it).label() );
104 if ( version == VCard::v2_1 ) { 105 if ( version == VCard::v2_1 ) {
105 labelLine.addParameter( "CHARSET", "UTF-8" ); 106 labelLine.addParameter( "CHARSET", "UTF-8" );
106 labelLine.addParameter( "ENCODING", "8BIT" ); 107 labelLine.addParameter( "ENCODING", "8BIT" );
107 } 108 }
108 109
109 bool hasLabel = !(*it).label().isEmpty(); 110 bool hasLabel = !(*it).label().isEmpty();
110 QMap<QString, int>::ConstIterator typeIt; 111 QMap<QString, int>::ConstIterator typeIt;
111 for ( typeIt = mAddressTypeMap.begin(); typeIt != mAddressTypeMap.end(); ++typeIt ) { 112 for ( typeIt = mAddressTypeMap.begin(); typeIt != mAddressTypeMap.end(); ++typeIt ) {
112 if ( typeIt.data() & (*it).type() ) { 113 if ( typeIt.data() & (*it).type() ) {
113 adrLine.addParameter( "TYPE", typeIt.key() ); 114 adrLine.addParameter( "TYPE", typeIt.key() );
114 if ( hasLabel ) 115 if ( hasLabel )
115 labelLine.addParameter( "TYPE", typeIt.key() ); 116 labelLine.addParameter( "TYPE", typeIt.key() );
116 } 117 }
117 } 118 }
118 119
119 if ( !isEmpty ) 120 if ( !isEmpty )
120 card.addLine( adrLine ); 121 card.addLine( adrLine );
121 if ( hasLabel ) 122 if ( hasLabel )
122 card.addLine( labelLine ); 123 card.addLine( labelLine );
123 } 124 }
124 125
125 // AGENT 126 // AGENT
126 card.addLine( createAgent( version, (*addrIt).agent() ) ); 127 card.addLine( createAgent( version, (*addrIt).agent() ) );
127 128
128 // BDAY 129 // BDAY
129 card.addLine( VCardLine( "BDAY", createDateTime( (*addrIt).birthday() ) ) ); 130 card.addLine( VCardLine( "BDAY", createDateTime( (*addrIt).birthday() ) ) );
130 131
131 // CATEGORIES 132 // CATEGORIES
132 if ( version == VCard::v3_0 ) { 133 if ( version == VCard::v3_0 ) {
133 QStringList categories = (*addrIt).categories(); 134 QStringList categories = (*addrIt).categories();
134 QStringList::Iterator catIt; 135 QStringList::Iterator catIt;
135 for ( catIt = categories.begin(); catIt != categories.end(); ++catIt ) 136 for ( catIt = categories.begin(); catIt != categories.end(); ++catIt )
136 (*catIt).replace( QRegExp(","), "\\," ); 137 (*catIt).replace( QRegExp(","), "\\," );
137 138
138 VCardLine catLine( "CATEGORIES", categories.join( "," ) ); 139 VCardLine catLine( "CATEGORIES", categories.join( "," ) );
139 if ( version == VCard::v2_1 ) { 140 if ( version == VCard::v2_1 ) {
140 catLine.addParameter( "CHARSET", "UTF-8" ); 141 catLine.addParameter( "CHARSET", "UTF-8" );
141 catLine.addParameter( "ENCODING", "8BIT" ); 142 catLine.addParameter( "ENCODING", "8BIT" );
142 } 143 }
143 144
144 card.addLine( catLine ); 145 card.addLine( catLine );
145 } 146 }
146 147
147 // CLASS 148 // CLASS
148 if ( version == VCard::v3_0 ) { 149 if ( version == VCard::v3_0 ) {
149 card.addLine( createSecrecy( (*addrIt).secrecy() ) ); 150 card.addLine( createSecrecy( (*addrIt).secrecy() ) );
150 } 151 }
151 152
152 // EMAIL 153 // EMAIL
153 const QStringList emails = (*addrIt).emails(); 154 const QStringList emails = (*addrIt).emails();
154 bool pref = true; 155 bool pref = true;
155 for ( strIt = emails.begin(); strIt != emails.end(); ++strIt ) { 156 for ( strIt = emails.begin(); strIt != emails.end(); ++strIt ) {
156 VCardLine line( "EMAIL", *strIt ); 157 VCardLine line( "EMAIL", *strIt );
157 if ( version == VCard::v2_1 ) { 158 if ( version == VCard::v2_1 ) {
158 line.addParameter( "CHARSET", "UTF-8" ); 159 line.addParameter( "CHARSET", "UTF-8" );
159 line.addParameter( "ENCODING", "8BIT" ); 160 line.addParameter( "ENCODING", "8BIT" );
160 } 161 }
161 if ( pref == true && emails.count() > 1 ) { 162 if ( pref == true && emails.count() > 1 ) {
162 line.addParameter( "TYPE", "PREF" ); 163 line.addParameter( "TYPE", "PREF" );
163 pref = false; 164 pref = false;
164 } 165 }
165 card.addLine( line ); 166 card.addLine( line );
166 } 167 }
167 168
168 // FN 169 // FN
169 VCardLine fnLine( "FN", (*addrIt).formattedName() ); 170 VCardLine fnLine( "FN", (*addrIt).formattedName() );
170 if ( version == VCard::v2_1 ) { 171 if ( version == VCard::v2_1 ) {
171 fnLine.addParameter( "CHARSET", "UTF-8" ); 172 fnLine.addParameter( "CHARSET", "UTF-8" );
172 fnLine.addParameter( "ENCODING", "8BIT" ); 173 fnLine.addParameter( "ENCODING", "8BIT" );
173 } 174 }
174 card.addLine( fnLine ); 175 card.addLine( fnLine );
175 176
176 // GEO 177 // GEO
177 Geo geo = (*addrIt).geo(); 178 Geo geo = (*addrIt).geo();
178 if ( geo.isValid() ) { 179 if ( geo.isValid() ) {
179 QString str; 180 QString str;
180 str.sprintf( "%.6f;%.6f", geo.latitude(), geo.longitude() ); 181 str.sprintf( "%.6f;%.6f", geo.latitude(), geo.longitude() );
181 card.addLine( VCardLine( "GEO", str ) ); 182 card.addLine( VCardLine( "GEO", str ) );
182 } 183 }
183 184
184 // KEY 185 // KEY
185 const Key::List keys = (*addrIt).keys(); 186 const Key::List keys = (*addrIt).keys();
186 Key::List::ConstIterator keyIt; 187 Key::List::ConstIterator keyIt;
187 for ( keyIt = keys.begin(); keyIt != keys.end(); ++keyIt ) 188 for ( keyIt = keys.begin(); keyIt != keys.end(); ++keyIt )
188 card.addLine( createKey( *keyIt ) ); 189 card.addLine( createKey( *keyIt ) );
189 190
190 // LOGO 191 // LOGO
191 card.addLine( createPicture( "LOGO", (*addrIt).logo() ) ); 192 card.addLine( createPicture( "LOGO", (*addrIt).logo() ) );
192 193
193 // MAILER 194 // MAILER
194 VCardLine mailerLine( "MAILER", (*addrIt).mailer() ); 195 VCardLine mailerLine( "MAILER", (*addrIt).mailer() );
195 if ( version == VCard::v2_1 ) { 196 if ( version == VCard::v2_1 ) {
196 mailerLine.addParameter( "CHARSET", "UTF-8" ); 197 mailerLine.addParameter( "CHARSET", "UTF-8" );
197 mailerLine.addParameter( "ENCODING", "8BIT" ); 198 mailerLine.addParameter( "ENCODING", "8BIT" );
198 } 199 }
199 card.addLine( mailerLine ); 200 card.addLine( mailerLine );
200 201
201 // N 202 // N
202 QStringList name; 203 QStringList name;
203 name.append( (*addrIt).familyName().replace( semiExp, "\\;" ) ); 204 name.append( (*addrIt).familyName().replace( semiExp, "\\;" ) );
204 name.append( (*addrIt).givenName().replace( semiExp, "\\;" ) ); 205 name.append( (*addrIt).givenName().replace( semiExp, "\\;" ) );
205 name.append( (*addrIt).additionalName().replace( semiExp, "\\;" ) ); 206 name.append( (*addrIt).additionalName().replace( semiExp, "\\;" ) );
206 name.append( (*addrIt).prefix().replace( semiExp, "\\;" ) ); 207 name.append( (*addrIt).prefix().replace( semiExp, "\\;" ) );
207 name.append( (*addrIt).suffix().replace( semiExp, "\\;" ) ); 208 name.append( (*addrIt).suffix().replace( semiExp, "\\;" ) );
208 209
209 VCardLine nLine( "N", name.join( ";" ) ); 210 VCardLine nLine( "N", name.join( ";" ) );
210 if ( version == VCard::v2_1 ) { 211 if ( version == VCard::v2_1 ) {
211 nLine.addParameter( "CHARSET", "UTF-8" ); 212 nLine.addParameter( "CHARSET", "UTF-8" );
212 nLine.addParameter( "ENCODING", "8BIT" ); 213 nLine.addParameter( "ENCODING", "8BIT" );
213 } 214 }
214 card.addLine( nLine ); 215 card.addLine( nLine );