summaryrefslogtreecommitdiffabout
authorzautrix <zautrix>2005-03-11 07:56:35 (UTC)
committer zautrix <zautrix>2005-03-11 07:56:35 (UTC)
commitee802b5ac60e084365e60ee2bdc0b8a9e8e72c66 (patch) (unidiff)
treeee14e30b5bb0a9519cb211f94e917f985be42e5f
parentb6845008e161e1bb355a32767c3e3f89ff8e5c01 (diff)
downloadkdepimpi-ee802b5ac60e084365e60ee2bdc0b8a9e8e72c66.zip
kdepimpi-ee802b5ac60e084365e60ee2bdc0b8a9e8e72c66.tar.gz
kdepimpi-ee802b5ac60e084365e60ee2bdc0b8a9e8e72c66.tar.bz2
missing include
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,534 +1,535 @@
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 );
215 216
216 // NAME 217 // NAME
217 VCardLine nameLine( "NAME", (*addrIt).name() ); 218 VCardLine nameLine( "NAME", (*addrIt).name() );
218 if ( version == VCard::v2_1 ) { 219 if ( version == VCard::v2_1 ) {
219 nameLine.addParameter( "CHARSET", "UTF-8" ); 220 nameLine.addParameter( "CHARSET", "UTF-8" );
220 nameLine.addParameter( "ENCODING", "8BIT" ); 221 nameLine.addParameter( "ENCODING", "8BIT" );
221 } 222 }
222 card.addLine( nameLine ); 223 card.addLine( nameLine );
223 224
224 // NICKNAME 225 // NICKNAME
225 if ( version == VCard::v3_0 ) 226 if ( version == VCard::v3_0 )
226 card.addLine( VCardLine( "NICKNAME", (*addrIt).nickName() ) ); 227 card.addLine( VCardLine( "NICKNAME", (*addrIt).nickName() ) );
227 228
228 // NOTE 229 // NOTE
229 VCardLine noteLine( "NOTE", (*addrIt).note() ); 230 VCardLine noteLine( "NOTE", (*addrIt).note() );
230 if ( version == VCard::v2_1 ) { 231 if ( version == VCard::v2_1 ) {
231 noteLine.addParameter( "CHARSET", "UTF-8" ); 232 noteLine.addParameter( "CHARSET", "UTF-8" );
232 noteLine.addParameter( "ENCODING", "8BIT" ); 233 noteLine.addParameter( "ENCODING", "8BIT" );
233 } 234 }
234 card.addLine( noteLine ); 235 card.addLine( noteLine );
235 236
236 // ORG 237 // ORG
237 VCardLine orgLine( "ORG", (*addrIt).organization() ); 238 VCardLine orgLine( "ORG", (*addrIt).organization() );
238 if ( version == VCard::v2_1 ) { 239 if ( version == VCard::v2_1 ) {
239 orgLine.addParameter( "CHARSET", "UTF-8" ); 240 orgLine.addParameter( "CHARSET", "UTF-8" );
240 orgLine.addParameter( "ENCODING", "8BIT" ); 241 orgLine.addParameter( "ENCODING", "8BIT" );
241 } 242 }
242 card.addLine( orgLine ); 243 card.addLine( orgLine );
243 244
244 // PHOTO 245 // PHOTO
245 card.addLine( createPicture( "PHOTO", (*addrIt).photo() ) ); 246 card.addLine( createPicture( "PHOTO", (*addrIt).photo() ) );
246 247
247 // PROID 248 // PROID
248 if ( version == VCard::v3_0 ) 249 if ( version == VCard::v3_0 )
249 card.addLine( VCardLine( "PRODID", (*addrIt).productId() ) ); 250 card.addLine( VCardLine( "PRODID", (*addrIt).productId() ) );
250 251
251 // REV 252 // REV
252 card.addLine( VCardLine( "REV", createDateTime( (*addrIt).revision() ) ) ); 253 card.addLine( VCardLine( "REV", createDateTime( (*addrIt).revision() ) ) );
253 254
254 // ROLE 255 // ROLE
255 VCardLine roleLine( "ROLE", (*addrIt).role() ); 256 VCardLine roleLine( "ROLE", (*addrIt).role() );
256 if ( version == VCard::v2_1 ) { 257 if ( version == VCard::v2_1 ) {
257 roleLine.addParameter( "CHARSET", "UTF-8" ); 258 roleLine.addParameter( "CHARSET", "UTF-8" );
258 roleLine.addParameter( "ENCODING", "8BIT" ); 259 roleLine.addParameter( "ENCODING", "8BIT" );
259 } 260 }
260 card.addLine( roleLine ); 261 card.addLine( roleLine );
261 262
262 // SORT-STRING 263 // SORT-STRING
263 if ( version == VCard::v3_0 ) 264 if ( version == VCard::v3_0 )
264 card.addLine( VCardLine( "SORT-STRING", (*addrIt).sortString() ) ); 265 card.addLine( VCardLine( "SORT-STRING", (*addrIt).sortString() ) );
265 266
266 // SOUND 267 // SOUND
267 card.addLine( createSound( (*addrIt).sound() ) ); 268 card.addLine( createSound( (*addrIt).sound() ) );
268 269
269 // TEL 270 // TEL
270 const PhoneNumber::List phoneNumbers = (*addrIt).phoneNumbers(); 271 const PhoneNumber::List phoneNumbers = (*addrIt).phoneNumbers();
271 PhoneNumber::List::ConstIterator phoneIt; 272 PhoneNumber::List::ConstIterator phoneIt;
272 for ( phoneIt = phoneNumbers.begin(); phoneIt != phoneNumbers.end(); ++phoneIt ) { 273 for ( phoneIt = phoneNumbers.begin(); phoneIt != phoneNumbers.end(); ++phoneIt ) {
273 VCardLine line( "TEL", (*phoneIt).number() ); 274 VCardLine line( "TEL", (*phoneIt).number() );
274 275
275 QMap<QString, int>::ConstIterator typeIt; 276 QMap<QString, int>::ConstIterator typeIt;
276 for ( typeIt = mPhoneTypeMap.begin(); typeIt != mPhoneTypeMap.end(); ++typeIt ) { 277 for ( typeIt = mPhoneTypeMap.begin(); typeIt != mPhoneTypeMap.end(); ++typeIt ) {
277 if ( typeIt.data() & (*phoneIt).type() ) 278 if ( typeIt.data() & (*phoneIt).type() )
278 line.addParameter( "TYPE", typeIt.key() ); 279 line.addParameter( "TYPE", typeIt.key() );
279 } 280 }
280 281
281 card.addLine( line ); 282 card.addLine( line );
282 } 283 }
283 284
284 // TITLE 285 // TITLE
285 VCardLine titleLine( "TITLE", (*addrIt).title() ); 286 VCardLine titleLine( "TITLE", (*addrIt).title() );
286 if ( version == VCard::v2_1 ) { 287 if ( version == VCard::v2_1 ) {
287 titleLine.addParameter( "CHARSET", "UTF-8" ); 288 titleLine.addParameter( "CHARSET", "UTF-8" );
288 titleLine.addParameter( "ENCODING", "8BIT" ); 289 titleLine.addParameter( "ENCODING", "8BIT" );
289 } 290 }
290 card.addLine( titleLine ); 291 card.addLine( titleLine );
291 292
292 // TZ 293 // TZ
293 TimeZone timeZone = (*addrIt).timeZone(); 294 TimeZone timeZone = (*addrIt).timeZone();
294 if ( timeZone.isValid() ) { 295 if ( timeZone.isValid() ) {
295 QString str; 296 QString str;
296 297
297 int neg = 1; 298 int neg = 1;
298 if ( timeZone.offset() < 0 ) 299 if ( timeZone.offset() < 0 )
299 neg = -1; 300 neg = -1;
300 301
301 str.sprintf( "%c%02d:%02d", ( timeZone.offset() >= 0 ? '+' : '-' ), 302 str.sprintf( "%c%02d:%02d", ( timeZone.offset() >= 0 ? '+' : '-' ),
302 ( timeZone.offset() / 60 ) * neg, 303 ( timeZone.offset() / 60 ) * neg,
303 ( timeZone.offset() % 60 ) * neg ); 304 ( timeZone.offset() % 60 ) * neg );
304 305
305 card.addLine( VCardLine( "TZ", str ) ); 306 card.addLine( VCardLine( "TZ", str ) );
306 } 307 }
307 308
308 // UID 309 // UID
309 card.addLine( VCardLine( "UID", (*addrIt).uid() ) ); 310 card.addLine( VCardLine( "UID", (*addrIt).uid() ) );
310 311
311 // URL 312 // URL
312 card.addLine( VCardLine( "URL", (*addrIt).url().url() ) ); 313 card.addLine( VCardLine( "URL", (*addrIt).url().url() ) );
313 314
314 // VERSION 315 // VERSION
315 if ( version == VCard::v2_1 ) 316 if ( version == VCard::v2_1 )
316 card.addLine( VCardLine( "VERSION", "2.1" ) ); 317 card.addLine( VCardLine( "VERSION", "2.1" ) );
317 if ( version == VCard::v3_0 ) 318 if ( version == VCard::v3_0 )
318 card.addLine( VCardLine( "VERSION", "3.0" ) ); 319 card.addLine( VCardLine( "VERSION", "3.0" ) );
319 320
320 // X- 321 // X-
321 const QStringList customs = (*addrIt).customs(); 322 const QStringList customs = (*addrIt).customs();
322 for ( strIt = customs.begin(); strIt != customs.end(); ++strIt ) { 323 for ( strIt = customs.begin(); strIt != customs.end(); ++strIt ) {
323 QString identifier = "X-" + (*strIt).left( (*strIt).find( ":" ) ); 324 QString identifier = "X-" + (*strIt).left( (*strIt).find( ":" ) );
324 QString value = (*strIt).mid( (*strIt).find( ":" ) + 1 ); 325 QString value = (*strIt).mid( (*strIt).find( ":" ) + 1 );
325 if ( value.isEmpty() ) 326 if ( value.isEmpty() )
326 continue; 327 continue;
327 328
328 VCardLine line( identifier, value ); 329 VCardLine line( identifier, value );
329 if ( version == VCard::v2_1 ) { 330 if ( version == VCard::v2_1 ) {
330 line.addParameter( "CHARSET", "UTF-8" ); 331 line.addParameter( "CHARSET", "UTF-8" );
331 line.addParameter( "ENCODING", "8BIT" ); 332 line.addParameter( "ENCODING", "8BIT" );
332 } 333 }
333 card.addLine( line ); 334 card.addLine( line );
334 } 335 }
335 336
336 vCardList.append( card ); 337 vCardList.append( card );
337 } 338 }
338 339
339 return VCardParser::createVCards( vCardList ); 340 return VCardParser::createVCards( vCardList );
340} 341}
341 342
342Addressee::List VCardTool::parseVCards( const QString& vcard ) 343Addressee::List VCardTool::parseVCards( const QString& vcard )
343{ 344{
344 static const QChar semicolonSep( ';' ); 345 static const QChar semicolonSep( ';' );
345 static const QChar commaSep( ',' ); 346 static const QChar commaSep( ',' );
346 QString identifier; 347 QString identifier;
347 348
348 Addressee::List addrList; 349 Addressee::List addrList;
349 const VCard::List vCardList = VCardParser::parseVCards( vcard ); 350 const VCard::List vCardList = VCardParser::parseVCards( vcard );
350 351
351 VCard::List::ConstIterator cardIt; 352 VCard::List::ConstIterator cardIt;
352 VCard::List::ConstIterator listEnd( vCardList.end() ); 353 VCard::List::ConstIterator listEnd( vCardList.end() );
353 for ( cardIt = vCardList.begin(); cardIt != listEnd; ++cardIt ) { 354 for ( cardIt = vCardList.begin(); cardIt != listEnd; ++cardIt ) {
354 Addressee addr; 355 Addressee addr;
355 356
356 const QStringList idents = (*cardIt).identifiers(); 357 const QStringList idents = (*cardIt).identifiers();
357 QStringList::ConstIterator identIt; 358 QStringList::ConstIterator identIt;
358 QStringList::ConstIterator identEnd( idents.end() ); 359 QStringList::ConstIterator identEnd( idents.end() );
359 for ( identIt = idents.begin(); identIt != identEnd; ++identIt ) { 360 for ( identIt = idents.begin(); identIt != identEnd; ++identIt ) {
360 const VCardLine::List lines = (*cardIt).lines( (*identIt) ); 361 const VCardLine::List lines = (*cardIt).lines( (*identIt) );
361 VCardLine::List::ConstIterator lineIt; 362 VCardLine::List::ConstIterator lineIt;
362 363
363 // iterate over the lines 364 // iterate over the lines
364 for ( lineIt = lines.begin(); lineIt != lines.end(); ++lineIt ) { 365 for ( lineIt = lines.begin(); lineIt != lines.end(); ++lineIt ) {
365 identifier = (*lineIt).identifier().lower(); 366 identifier = (*lineIt).identifier().lower();
366 // ADR 367 // ADR
367 if ( identifier == "adr" ) { 368 if ( identifier == "adr" ) {
368 Address address; 369 Address address;
369 const QStringList addrParts = splitString( semicolonSep, (*lineIt).value().asString() ); 370 const QStringList addrParts = splitString( semicolonSep, (*lineIt).value().asString() );
370 if ( addrParts.count() > 0 ) 371 if ( addrParts.count() > 0 )
371 address.setPostOfficeBox( addrParts[ 0 ] ); 372 address.setPostOfficeBox( addrParts[ 0 ] );
372 if ( addrParts.count() > 1 ) 373 if ( addrParts.count() > 1 )
373 address.setExtended( addrParts[ 1 ] ); 374 address.setExtended( addrParts[ 1 ] );
374 if ( addrParts.count() > 2 ) 375 if ( addrParts.count() > 2 )
375 address.setStreet( addrParts[ 2 ] ); 376 address.setStreet( addrParts[ 2 ] );
376 if ( addrParts.count() > 3 ) 377 if ( addrParts.count() > 3 )
377 address.setLocality( addrParts[ 3 ] ); 378 address.setLocality( addrParts[ 3 ] );
378 if ( addrParts.count() > 4 ) 379 if ( addrParts.count() > 4 )
379 address.setRegion( addrParts[ 4 ] ); 380 address.setRegion( addrParts[ 4 ] );
380 if ( addrParts.count() > 5 ) 381 if ( addrParts.count() > 5 )
381 address.setPostalCode( addrParts[ 5 ] ); 382 address.setPostalCode( addrParts[ 5 ] );
382 if ( addrParts.count() > 6 ) 383 if ( addrParts.count() > 6 )
383 address.setCountry( addrParts[ 6 ] ); 384 address.setCountry( addrParts[ 6 ] );
384 385
385 int type = 0; 386 int type = 0;
386 387
387 const QStringList types = (*lineIt).parameters( "type" ); 388 const QStringList types = (*lineIt).parameters( "type" );
388 for ( QStringList::ConstIterator it = types.begin(); it != types.end(); ++it ) 389 for ( QStringList::ConstIterator it = types.begin(); it != types.end(); ++it )
389 type += mAddressTypeMap[ (*it).lower() ]; 390 type += mAddressTypeMap[ (*it).lower() ];
390 391
391 address.setType( type ); 392 address.setType( type );
392 addr.insertAddress( address ); 393 addr.insertAddress( address );
393 } 394 }
394 395
395 // AGENT 396 // AGENT
396 else if ( identifier == "agent" ) 397 else if ( identifier == "agent" )
397 addr.setAgent( parseAgent( *lineIt ) ); 398 addr.setAgent( parseAgent( *lineIt ) );
398 399
399 // BDAY 400 // BDAY
400 else if ( identifier == "bday" ) 401 else if ( identifier == "bday" )
401 addr.setBirthday( parseDateTime( (*lineIt).value().asString() ) ); 402 addr.setBirthday( parseDateTime( (*lineIt).value().asString() ) );
402 403
403 // CATEGORIES 404 // CATEGORIES
404 else if ( identifier == "categories" ) { 405 else if ( identifier == "categories" ) {
405 const QStringList categories = splitString( commaSep, (*lineIt).value().asString() ); 406 const QStringList categories = splitString( commaSep, (*lineIt).value().asString() );
406 addr.setCategories( categories ); 407 addr.setCategories( categories );
407 } 408 }
408 409
409 // CLASS 410 // CLASS
410 else if ( identifier == "class" ) 411 else if ( identifier == "class" )
411 addr.setSecrecy( parseSecrecy( *lineIt ) ); 412 addr.setSecrecy( parseSecrecy( *lineIt ) );
412 413
413 // EMAIL 414 // EMAIL
414 else if ( identifier == "email" ) { 415 else if ( identifier == "email" ) {
415 const QStringList types = (*lineIt).parameters( "type" ); 416 const QStringList types = (*lineIt).parameters( "type" );
416 addr.insertEmail( (*lineIt).value().asString(), types.findIndex( "PREF" ) != -1 ); 417 addr.insertEmail( (*lineIt).value().asString(), types.findIndex( "PREF" ) != -1 );
417 } 418 }
418 419
419 // FN 420 // FN
420 else if ( identifier == "fn" ) 421 else if ( identifier == "fn" )
421 addr.setFormattedName( (*lineIt).value().asString() ); 422 addr.setFormattedName( (*lineIt).value().asString() );
422 423
423 // GEO 424 // GEO
424 else if ( identifier == "geo" ) { 425 else if ( identifier == "geo" ) {
425 Geo geo; 426 Geo geo;
426 427
427 const QStringList geoParts = QStringList::split( ';', (*lineIt).value().asString(), true ); 428 const QStringList geoParts = QStringList::split( ';', (*lineIt).value().asString(), true );
428 geo.setLatitude( geoParts[ 0 ].toFloat() ); 429 geo.setLatitude( geoParts[ 0 ].toFloat() );
429 geo.setLongitude( geoParts[ 1 ].toFloat() ); 430 geo.setLongitude( geoParts[ 1 ].toFloat() );
430 431
431 addr.setGeo( geo ); 432 addr.setGeo( geo );
432 } 433 }
433 434
434 // KEY 435 // KEY
435 else if ( identifier == "key" ) 436 else if ( identifier == "key" )
436 addr.insertKey( parseKey( *lineIt ) ); 437 addr.insertKey( parseKey( *lineIt ) );
437 438
438 // LABEL 439 // LABEL
439 else if ( identifier == "label" ) { 440 else if ( identifier == "label" ) {
440 int type = 0; 441 int type = 0;
441 442
442 const QStringList types = (*lineIt).parameters( "type" ); 443 const QStringList types = (*lineIt).parameters( "type" );
443 for ( QStringList::ConstIterator it = types.begin(); it != types.end(); ++it ) 444 for ( QStringList::ConstIterator it = types.begin(); it != types.end(); ++it )
444 type += mAddressTypeMap[ (*it).lower() ]; 445 type += mAddressTypeMap[ (*it).lower() ];
445 446
446 bool available = false; 447 bool available = false;
447 KABC::Address::List addressList = addr.addresses(); 448 KABC::Address::List addressList = addr.addresses();
448 KABC::Address::List::Iterator it; 449 KABC::Address::List::Iterator it;
449 for ( it = addressList.begin(); it != addressList.end(); ++it ) { 450 for ( it = addressList.begin(); it != addressList.end(); ++it ) {
450 if ( (*it).type() == type ) { 451 if ( (*it).type() == type ) {
451 (*it).setLabel( (*lineIt).value().asString() ); 452 (*it).setLabel( (*lineIt).value().asString() );
452 addr.insertAddress( *it ); 453 addr.insertAddress( *it );
453 available = true; 454 available = true;
454 break; 455 break;
455 } 456 }
456 } 457 }
457 458
458 if ( !available ) { // a standalone LABEL tag 459 if ( !available ) { // a standalone LABEL tag
459 KABC::Address address( type ); 460 KABC::Address address( type );
460 address.setLabel( (*lineIt).value().asString() ); 461 address.setLabel( (*lineIt).value().asString() );
461 addr.insertAddress( address ); 462 addr.insertAddress( address );
462 } 463 }
463 } 464 }
464 465
465 // LOGO 466 // LOGO
466 else if ( identifier == "logo" ) 467 else if ( identifier == "logo" )
467 addr.setLogo( parsePicture( *lineIt ) ); 468 addr.setLogo( parsePicture( *lineIt ) );
468 469
469 // MAILER 470 // MAILER
470 else if ( identifier == "mailer" ) 471 else if ( identifier == "mailer" )
471 addr.setMailer( (*lineIt).value().asString() ); 472 addr.setMailer( (*lineIt).value().asString() );
472 473
473 // N 474 // N
474 else if ( identifier == "n" ) { 475 else if ( identifier == "n" ) {
475 const QStringList nameParts = splitString( semicolonSep, (*lineIt).value().asString() ); 476 const QStringList nameParts = splitString( semicolonSep, (*lineIt).value().asString() );
476 if ( nameParts.count() > 0 ) 477 if ( nameParts.count() > 0 )
477 addr.setFamilyName( nameParts[ 0 ] ); 478 addr.setFamilyName( nameParts[ 0 ] );
478 if ( nameParts.count() > 1 ) 479 if ( nameParts.count() > 1 )
479 addr.setGivenName( nameParts[ 1 ] ); 480 addr.setGivenName( nameParts[ 1 ] );
480 if ( nameParts.count() > 2 ) 481 if ( nameParts.count() > 2 )
481 addr.setAdditionalName( nameParts[ 2 ] ); 482 addr.setAdditionalName( nameParts[ 2 ] );
482 if ( nameParts.count() > 3 ) 483 if ( nameParts.count() > 3 )
483 addr.setPrefix( nameParts[ 3 ] ); 484 addr.setPrefix( nameParts[ 3 ] );
484 if ( nameParts.count() > 4 ) 485 if ( nameParts.count() > 4 )
485 addr.setSuffix( nameParts[ 4 ] ); 486 addr.setSuffix( nameParts[ 4 ] );
486 } 487 }
487 488
488 // NAME 489 // NAME
489 else if ( identifier == "name" ) 490 else if ( identifier == "name" )
490 addr.setName( (*lineIt).value().asString() ); 491 addr.setName( (*lineIt).value().asString() );
491 492
492 // NICKNAME 493 // NICKNAME
493 else if ( identifier == "nickname" ) 494 else if ( identifier == "nickname" )
494 addr.setNickName( (*lineIt).value().asString() ); 495 addr.setNickName( (*lineIt).value().asString() );
495 496
496 // NOTE 497 // NOTE
497 else if ( identifier == "note" ) 498 else if ( identifier == "note" )
498 addr.setNote( (*lineIt).value().asString() ); 499 addr.setNote( (*lineIt).value().asString() );
499 500
500 // ORGANIZATION 501 // ORGANIZATION
501 else if ( identifier == "org" ) 502 else if ( identifier == "org" )
502 addr.setOrganization( (*lineIt).value().asString() ); 503 addr.setOrganization( (*lineIt).value().asString() );
503 504
504 // PHOTO 505 // PHOTO
505 else if ( identifier == "photo" ) 506 else if ( identifier == "photo" )
506 addr.setPhoto( parsePicture( *lineIt ) ); 507 addr.setPhoto( parsePicture( *lineIt ) );
507 508
508 // PROID 509 // PROID
509 else if ( identifier == "prodid" ) 510 else if ( identifier == "prodid" )
510 addr.setProductId( (*lineIt).value().asString() ); 511 addr.setProductId( (*lineIt).value().asString() );
511 512
512 // REV 513 // REV
513 else if ( identifier == "rev" ) 514 else if ( identifier == "rev" )
514 addr.setRevision( parseDateTime( (*lineIt).value().asString() ) ); 515 addr.setRevision( parseDateTime( (*lineIt).value().asString() ) );
515 516
516 // ROLE 517 // ROLE
517 else if ( identifier == "role" ) 518 else if ( identifier == "role" )
518 addr.setRole( (*lineIt).value().asString() ); 519 addr.setRole( (*lineIt).value().asString() );
519 520
520 // SORT-STRING 521 // SORT-STRING
521 else if ( identifier == "sort-string" ) 522 else if ( identifier == "sort-string" )
522 addr.setSortString( (*lineIt).value().asString() ); 523 addr.setSortString( (*lineIt).value().asString() );
523 524
524 // SOUND 525 // SOUND
525 else if ( identifier == "sound" ) 526 else if ( identifier == "sound" )
526 addr.setSound( parseSound( *lineIt ) ); 527 addr.setSound( parseSound( *lineIt ) );
527 528
528 // TEL 529 // TEL
529 else if ( identifier == "tel" ) { 530 else if ( identifier == "tel" ) {
530 PhoneNumber phone; 531 PhoneNumber phone;
531 phone.setNumber( (*lineIt).value().asString() ); 532 phone.setNumber( (*lineIt).value().asString() );
532 533
533 int type = 0; 534 int type = 0;
534 535