summaryrefslogtreecommitdiffabout
path: root/kabc
authorzautrix <zautrix>2005-03-11 07:56:35 (UTC)
committer zautrix <zautrix>2005-03-11 07:56:35 (UTC)
commitee802b5ac60e084365e60ee2bdc0b8a9e8e72c66 (patch) (unidiff)
treeee14e30b5bb0a9519cb211f94e917f985be42e5f /kabc
parentb6845008e161e1bb355a32767c3e3f89ff8e5c01 (diff)
downloadkdepimpi-ee802b5ac60e084365e60ee2bdc0b8a9e8e72c66.zip
kdepimpi-ee802b5ac60e084365e60ee2bdc0b8a9e8e72c66.tar.gz
kdepimpi-ee802b5ac60e084365e60ee2bdc0b8a9e8e72c66.tar.bz2
missing include
Diffstat (limited to 'kabc') (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,868 +1,869 @@
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
535 const QStringList types = (*lineIt).parameters( "type" ); 536 const QStringList types = (*lineIt).parameters( "type" );
536 for ( QStringList::ConstIterator it = types.begin(); it != types.end(); ++it ) 537 for ( QStringList::ConstIterator it = types.begin(); it != types.end(); ++it )
537 type += mPhoneTypeMap[(*it).upper()]; 538 type += mPhoneTypeMap[(*it).upper()];
538 539
539 phone.setType( type ); 540 phone.setType( type );
540 541
541 addr.insertPhoneNumber( phone ); 542 addr.insertPhoneNumber( phone );
542 } 543 }
543 544
544 // TITLE 545 // TITLE
545 else if ( identifier == "title" ) 546 else if ( identifier == "title" )
546 addr.setTitle( (*lineIt).value().asString() ); 547 addr.setTitle( (*lineIt).value().asString() );
547 548
548 // TZ 549 // TZ
549 else if ( identifier == "tz" ) { 550 else if ( identifier == "tz" ) {
550 TimeZone tz; 551 TimeZone tz;
551 const QString date = (*lineIt).value().asString(); 552 const QString date = (*lineIt).value().asString();
552 553
553 int hours = date.mid( 1, 2).toInt(); 554 int hours = date.mid( 1, 2).toInt();
554 int minutes = date.mid( 4, 2 ).toInt(); 555 int minutes = date.mid( 4, 2 ).toInt();
555 int offset = ( hours * 60 ) + minutes; 556 int offset = ( hours * 60 ) + minutes;
556 offset = offset * ( date[ 0 ] == '+' ? 1 : -1 ); 557 offset = offset * ( date[ 0 ] == '+' ? 1 : -1 );
557 558
558 tz.setOffset( offset ); 559 tz.setOffset( offset );
559 addr.setTimeZone( tz ); 560 addr.setTimeZone( tz );
560 } 561 }
561 562
562 // UID 563 // UID
563 else if ( identifier == "uid" ) 564 else if ( identifier == "uid" )
564 addr.setUid( (*lineIt).value().asString() ); 565 addr.setUid( (*lineIt).value().asString() );
565 566
566 // URL 567 // URL
567 else if ( identifier == "url" ) 568 else if ( identifier == "url" )
568 addr.setUrl( KURL( (*lineIt).value().asString() ) ); 569 addr.setUrl( KURL( (*lineIt).value().asString() ) );
569 570
570 // X- 571 // X-
571 else if ( identifier.startsWith( "x-" ) ) { 572 else if ( identifier.startsWith( "x-" ) ) {
572 const QString key = (*lineIt).identifier().mid( 2 ); 573 const QString key = (*lineIt).identifier().mid( 2 );
573 int dash = key.find( "-" ); 574 int dash = key.find( "-" );
574 addr.insertCustom( key.left( dash ), key.mid( dash + 1 ), (*lineIt).value().asString() ); 575 addr.insertCustom( key.left( dash ), key.mid( dash + 1 ), (*lineIt).value().asString() );
575 } 576 }
576 } 577 }
577 } 578 }
578 579
579 addrList.append( addr ); 580 addrList.append( addr );
580 } 581 }
581 582
582 return addrList; 583 return addrList;
583} 584}
584 585
585QDateTime VCardTool::parseDateTime( const QString &str ) 586QDateTime VCardTool::parseDateTime( const QString &str )
586{ 587{
587 QDateTime dateTime; 588 QDateTime dateTime;
588 589
589 if ( str.find( '-' ) == -1 ) { // is base format (yyyymmdd) 590 if ( str.find( '-' ) == -1 ) { // is base format (yyyymmdd)
590 dateTime.setDate( QDate( str.left( 4 ).toInt(), str.mid( 4, 2 ).toInt(), 591 dateTime.setDate( QDate( str.left( 4 ).toInt(), str.mid( 4, 2 ).toInt(),
591 str.mid( 6, 2 ).toInt() ) ); 592 str.mid( 6, 2 ).toInt() ) );
592 593
593 if ( str.find( 'T' ) ) // has time information yyyymmddThh:mm:ss 594 if ( str.find( 'T' ) ) // has time information yyyymmddThh:mm:ss
594 dateTime.setTime( QTime( str.mid( 11, 2 ).toInt(), str.mid( 14, 2 ).toInt(), 595 dateTime.setTime( QTime( str.mid( 11, 2 ).toInt(), str.mid( 14, 2 ).toInt(),
595 str.mid( 17, 2 ).toInt() ) ); 596 str.mid( 17, 2 ).toInt() ) );
596 597
597 } else { // is extended format yyyy-mm-dd 598 } else { // is extended format yyyy-mm-dd
598 dateTime.setDate( QDate( str.left( 4 ).toInt(), str.mid( 5, 2 ).toInt(), 599 dateTime.setDate( QDate( str.left( 4 ).toInt(), str.mid( 5, 2 ).toInt(),
599 str.mid( 8, 2 ).toInt() ) ); 600 str.mid( 8, 2 ).toInt() ) );
600 601
601 if ( str.find( 'T' ) ) // has time information yyyy-mm-ddThh:mm:ss 602 if ( str.find( 'T' ) ) // has time information yyyy-mm-ddThh:mm:ss
602 dateTime.setTime( QTime( str.mid( 11, 2 ).toInt(), str.mid( 14, 2 ).toInt(), 603 dateTime.setTime( QTime( str.mid( 11, 2 ).toInt(), str.mid( 14, 2 ).toInt(),
603 str.mid( 17, 2 ).toInt() ) ); 604 str.mid( 17, 2 ).toInt() ) );
604 } 605 }
605 606
606 return dateTime; 607 return dateTime;
607} 608}
608 609
609QString VCardTool::createDateTime( const QDateTime &dateTime ) 610QString VCardTool::createDateTime( const QDateTime &dateTime )
610{ 611{
611 QString str; 612 QString str;
612 613
613 if ( dateTime.date().isValid() ) { 614 if ( dateTime.date().isValid() ) {
614 str.sprintf( "%4d-%02d-%02d", dateTime.date().year(), dateTime.date().month(), 615 str.sprintf( "%4d-%02d-%02d", dateTime.date().year(), dateTime.date().month(),
615 dateTime.date().day() ); 616 dateTime.date().day() );
616 if ( dateTime.time().isValid() ) { 617 if ( dateTime.time().isValid() ) {
617 QString tmp; 618 QString tmp;
618 tmp.sprintf( "T%02d:%02d:%02dZ", dateTime.time().hour(), dateTime.time().minute(), 619 tmp.sprintf( "T%02d:%02d:%02dZ", dateTime.time().hour(), dateTime.time().minute(),
619 dateTime.time().second() ); 620 dateTime.time().second() );
620 str += tmp; 621 str += tmp;
621 } 622 }
622 } 623 }
623 624
624 return str; 625 return str;
625} 626}
626 627
627Picture VCardTool::parsePicture( const VCardLine &line ) 628Picture VCardTool::parsePicture( const VCardLine &line )
628{ 629{
629 Picture pic; 630 Picture pic;
630 631
631 const QStringList params = line.parameterList(); 632 const QStringList params = line.parameterList();
632 if ( params.findIndex( "encoding" ) != -1 ) { 633 if ( params.findIndex( "encoding" ) != -1 ) {
633 QImage img; 634 QImage img;
634 img.loadFromData( line.valueBytes() ); 635 img.loadFromData( line.valueBytes() );
635 pic.setData( img ); 636 pic.setData( img );
636 } else if ( params.findIndex( "value" ) != -1 ) { 637 } else if ( params.findIndex( "value" ) != -1 ) {
637 if ( line.parameter( "value" ).lower() == "uri" ) 638 if ( line.parameter( "value" ).lower() == "uri" )
638 pic.setUrl( line.value().asString() ); 639 pic.setUrl( line.value().asString() );
639 } 640 }
640 641
641 if ( params.findIndex( "type" ) != -1 ) 642 if ( params.findIndex( "type" ) != -1 )
642 pic.setType( line.parameter( "type" ) ); 643 pic.setType( line.parameter( "type" ) );
643 644
644 return pic; 645 return pic;
645} 646}
646 647
647VCardLine VCardTool::createPicture( const QString &identifier, const Picture &pic ) 648VCardLine VCardTool::createPicture( const QString &identifier, const Picture &pic )
648{ 649{
649 VCardLine line( identifier ); 650 VCardLine line( identifier );
650 651
651 if ( pic.isIntern() ) { 652 if ( pic.isIntern() ) {
652 if ( !pic.data().isNull() ) { 653 if ( !pic.data().isNull() ) {
653 QByteArray input; 654 QByteArray input;
654 QDataStream s( input, IO_WriteOnly ); 655 QDataStream s( input, IO_WriteOnly );
655 s.setVersion( 4 ); 656 s.setVersion( 4 );
656 s << pic.data(); 657 s << pic.data();
657 line.setValue( input ); 658 line.setValue( input );
658 line.addParameter( "encoding", "b" ); 659 line.addParameter( "encoding", "b" );
659 line.addParameter( "type", "image/png" ); 660 line.addParameter( "type", "image/png" );
660 } 661 }
661 } else if ( !pic.url().isEmpty() ) { 662 } else if ( !pic.url().isEmpty() ) {
662 QByteArray ba; 663 QByteArray ba;
663 line.setValue( pic.url() ); 664 line.setValue( pic.url() );
664 line.addParameter( "value", "URI" ); 665 line.addParameter( "value", "URI" );
665 } 666 }
666 667
667 return line; 668 return line;
668} 669}
669 670
670Sound VCardTool::parseSound( const VCardLine &line ) 671Sound VCardTool::parseSound( const VCardLine &line )
671{ 672{
672 Sound snd; 673 Sound snd;
673 674
674 const QStringList params = line.parameterList(); 675 const QStringList params = line.parameterList();
675 if ( params.findIndex( "encoding" ) != -1 ) 676 if ( params.findIndex( "encoding" ) != -1 )
676 snd.setData( line.valueBytes() ); 677 snd.setData( line.valueBytes() );
677 else if ( params.findIndex( "value" ) != -1 ) { 678 else if ( params.findIndex( "value" ) != -1 ) {
678 if ( line.parameter( "value" ).lower() == "uri" ) 679 if ( line.parameter( "value" ).lower() == "uri" )
679 snd.setUrl( line.value().asString() ); 680 snd.setUrl( line.value().asString() );
680 } 681 }
681 682
682/* TODO: support sound types 683/* TODO: support sound types
683 if ( params.contains( "type" ) ) 684 if ( params.contains( "type" ) )
684 snd.setType( line.parameter( "type" ) ); 685 snd.setType( line.parameter( "type" ) );
685*/ 686*/
686 687
687 return snd; 688 return snd;
688} 689}
689 690
690VCardLine VCardTool::createSound( const Sound &snd ) 691VCardLine VCardTool::createSound( const Sound &snd )
691{ 692{
692 VCardLine line( "SOUND" ); 693 VCardLine line( "SOUND" );
693 694
694 if ( snd.isIntern() ) { 695 if ( snd.isIntern() ) {
695 if ( !snd.data().isEmpty() ) { 696 if ( !snd.data().isEmpty() ) {
696 line.setValue( snd.data() ); 697 line.setValue( snd.data() );
697 line.addParameter( "encoding", "b" ); 698 line.addParameter( "encoding", "b" );
698 // TODO: need to store sound type!!! 699 // TODO: need to store sound type!!!
699 } 700 }
700 } else if ( !snd.url().isEmpty() ) { 701 } else if ( !snd.url().isEmpty() ) {
701 line.setValue( snd.url() ); 702 line.setValue( snd.url() );
702 line.addParameter( "value", "URI" ); 703 line.addParameter( "value", "URI" );
703 } 704 }
704 705
705 return line; 706 return line;
706} 707}
707 708
708Key VCardTool::parseKey( const VCardLine &line ) 709Key VCardTool::parseKey( const VCardLine &line )
709{ 710{
710 Key key; 711 Key key;
711 712
712 const QStringList params = line.parameterList(); 713 const QStringList params = line.parameterList();
713 if ( params.findIndex( "encoding" ) != -1 ) 714 if ( params.findIndex( "encoding" ) != -1 )
714 key.setBinaryData( line.valueBytes() ); 715 key.setBinaryData( line.valueBytes() );
715 else 716 else
716 key.setTextData( line.value().asString() ); 717 key.setTextData( line.value().asString() );
717 718
718 if ( params.findIndex( "type" ) != -1 ) { 719 if ( params.findIndex( "type" ) != -1 ) {
719 if ( line.parameter( "type" ).lower() == "x509" ) 720 if ( line.parameter( "type" ).lower() == "x509" )
720 key.setType( Key::X509 ); 721 key.setType( Key::X509 );
721 else if ( line.parameter( "type" ).lower() == "pgp" ) 722 else if ( line.parameter( "type" ).lower() == "pgp" )
722 key.setType( Key::PGP ); 723 key.setType( Key::PGP );
723 else { 724 else {
724 key.setType( Key::Custom ); 725 key.setType( Key::Custom );
725 key.setCustomTypeString( line.parameter( "type" ) ); 726 key.setCustomTypeString( line.parameter( "type" ) );
726 } 727 }
727 } 728 }
728 729
729 return key; 730 return key;
730} 731}
731 732
732VCardLine VCardTool::createKey( const Key &key ) 733VCardLine VCardTool::createKey( const Key &key )
733{ 734{
734 VCardLine line( "KEY" ); 735 VCardLine line( "KEY" );
735 736
736 if ( key.isBinary() ) { 737 if ( key.isBinary() ) {
737 if ( !key.binaryData().isEmpty() ) { 738 if ( !key.binaryData().isEmpty() ) {
738 line.setValue( key.binaryData() ); 739 line.setValue( key.binaryData() );
739 line.addParameter( "encoding", "b" ); 740 line.addParameter( "encoding", "b" );
740 } 741 }
741 } else if ( !key.textData().isEmpty() ) 742 } else if ( !key.textData().isEmpty() )
742 line.setValue( key.textData() ); 743 line.setValue( key.textData() );
743 744
744 if ( key.type() == Key::X509 ) 745 if ( key.type() == Key::X509 )
745 line.addParameter( "type", "X509" ); 746 line.addParameter( "type", "X509" );
746 else if ( key.type() == Key::PGP ) 747 else if ( key.type() == Key::PGP )
747 line.addParameter( "type", "PGP" ); 748 line.addParameter( "type", "PGP" );
748 else if ( key.type() == Key::Custom ) 749 else if ( key.type() == Key::Custom )
749 line.addParameter( "type", key.customTypeString() ); 750 line.addParameter( "type", key.customTypeString() );
750 751
751 return line; 752 return line;
752} 753}
753 754
754Secrecy VCardTool::parseSecrecy( const VCardLine &line ) 755Secrecy VCardTool::parseSecrecy( const VCardLine &line )
755{ 756{
756 Secrecy secrecy; 757 Secrecy secrecy;
757 758
758 if ( line.value().asString().lower() == "public" ) 759 if ( line.value().asString().lower() == "public" )
759 secrecy.setType( Secrecy::Public ); 760 secrecy.setType( Secrecy::Public );
760 if ( line.value().asString().lower() == "private" ) 761 if ( line.value().asString().lower() == "private" )
761 secrecy.setType( Secrecy::Private ); 762 secrecy.setType( Secrecy::Private );
762 if ( line.value().asString().lower() == "confidential" ) 763 if ( line.value().asString().lower() == "confidential" )
763 secrecy.setType( Secrecy::Confidential ); 764 secrecy.setType( Secrecy::Confidential );
764 765
765 return secrecy; 766 return secrecy;
766} 767}
767 768
768VCardLine VCardTool::createSecrecy( const Secrecy &secrecy ) 769VCardLine VCardTool::createSecrecy( const Secrecy &secrecy )
769{ 770{
770 VCardLine line( "CLASS" ); 771 VCardLine line( "CLASS" );
771 772
772 int type = secrecy.type(); 773 int type = secrecy.type();
773 774
774 if ( type == Secrecy::Public ) 775 if ( type == Secrecy::Public )
775 line.setValue( "PUBLIC" ); 776 line.setValue( "PUBLIC" );
776 else if ( type == Secrecy::Private ) 777 else if ( type == Secrecy::Private )
777 line.setValue( "PRIVATE" ); 778 line.setValue( "PRIVATE" );
778 else if ( type == Secrecy::Confidential ) 779 else if ( type == Secrecy::Confidential )
779 line.setValue( "CONFIDENTIAL" ); 780 line.setValue( "CONFIDENTIAL" );
780 781
781 return line; 782 return line;
782} 783}
783 784
784Agent VCardTool::parseAgent( const VCardLine &line ) 785Agent VCardTool::parseAgent( const VCardLine &line )
785{ 786{
786 Agent agent; 787 Agent agent;
787 788
788 const QStringList params = line.parameterList(); 789 const QStringList params = line.parameterList();
789 if ( params.findIndex( "value" ) != -1 ) { 790 if ( params.findIndex( "value" ) != -1 ) {
790 if ( line.parameter( "value" ).lower() == "uri" ) 791 if ( line.parameter( "value" ).lower() == "uri" )
791 agent.setUrl( line.value().asString() ); 792 agent.setUrl( line.value().asString() );
792 } else { 793 } else {
793 QString str = line.value().asString(); 794 QString str = line.value().asString();
794 str.replace( QRegExp("\\\\n"), "\r\n" ); 795 str.replace( QRegExp("\\\\n"), "\r\n" );
795 str.replace( QRegExp("\\\\N"), "\r\n" ); 796 str.replace( QRegExp("\\\\N"), "\r\n" );
796 str.replace( QRegExp("\\\\;"), ";" ); 797 str.replace( QRegExp("\\\\;"), ";" );
797 str.replace( QRegExp("\\\\:"), ":" ); 798 str.replace( QRegExp("\\\\:"), ":" );
798 str.replace( QRegExp("\\\\,"), "," ); 799 str.replace( QRegExp("\\\\,"), "," );
799 800
800 const Addressee::List list = parseVCards( str ); 801 const Addressee::List list = parseVCards( str );
801 if ( list.count() > 0 ) { 802 if ( list.count() > 0 ) {
802 Addressee *addr = new Addressee; 803 Addressee *addr = new Addressee;
803 *addr = list[ 0 ]; 804 *addr = list[ 0 ];
804 agent.setAddressee( addr ); 805 agent.setAddressee( addr );
805 } 806 }
806 } 807 }
807 808
808 return agent; 809 return agent;
809} 810}
810 811
811VCardLine VCardTool::createAgent( VCard::Version version, const Agent &agent ) 812VCardLine VCardTool::createAgent( VCard::Version version, const Agent &agent )
812{ 813{
813 VCardLine line( "AGENT" ); 814 VCardLine line( "AGENT" );
814 815
815 if ( agent.isIntern() ) { 816 if ( agent.isIntern() ) {
816 if ( agent.addressee() != 0 ) { 817 if ( agent.addressee() != 0 ) {
817 Addressee::List list; 818 Addressee::List list;
818 list.append( *agent.addressee() ); 819 list.append( *agent.addressee() );
819 820
820 QString str = createVCards( list, version ); 821 QString str = createVCards( list, version );
821 str.replace( QRegExp("\\r\\n"), "\\n" ); 822 str.replace( QRegExp("\\r\\n"), "\\n" );
822 str.replace( QRegExp(";"), "\\;" ); 823 str.replace( QRegExp(";"), "\\;" );
823 str.replace( QRegExp(":"), "\\:" ); 824 str.replace( QRegExp(":"), "\\:" );
824 str.replace( QRegExp(","), "\\," ); 825 str.replace( QRegExp(","), "\\," );
825 line.setValue( str ); 826 line.setValue( str );
826 } 827 }
827 } else if ( !agent.url().isEmpty() ) { 828 } else if ( !agent.url().isEmpty() ) {
828 line.setValue( agent.url() ); 829 line.setValue( agent.url() );
829 line.addParameter( "value", "URI" ); 830 line.addParameter( "value", "URI" );
830 } 831 }
831 832
832 return line; 833 return line;
833} 834}
834 835
835QStringList VCardTool::splitString( const QChar &sep, const QString &str ) 836QStringList VCardTool::splitString( const QChar &sep, const QString &str )
836{ 837{
837 QStringList list; 838 QStringList list;
838 QString value( str ); 839 QString value( str );
839 840
840 int start = 0; 841 int start = 0;
841 int pos = value.find( sep, start ); 842 int pos = value.find( sep, start );
842 843
843 while ( pos != -1 ) { 844 while ( pos != -1 ) {
844 if ( value[ pos - 1 ] != '\\' ) { 845 if ( value[ pos - 1 ] != '\\' ) {
845 if ( pos > start && pos <= (int)value.length() ) 846 if ( pos > start && pos <= (int)value.length() )
846 list << value.mid( start, pos - start ); 847 list << value.mid( start, pos - start );
847 else 848 else
848 list << QString::null; 849 list << QString::null;
849 850
850 start = pos + 1; 851 start = pos + 1;
851 pos = value.find( sep, start ); 852 pos = value.find( sep, start );
852 } else { 853 } else {
853 if ( pos != 0 ) { 854 if ( pos != 0 ) {
854 value.replace( pos - 1, 2, sep ); 855 value.replace( pos - 1, 2, sep );
855 pos = value.find( sep, pos ); 856 pos = value.find( sep, pos );
856 } else 857 } else
857 pos = value.find( sep, pos + 1 ); 858 pos = value.find( sep, pos + 1 );
858 } 859 }
859 } 860 }
860 861
861 int l = value.length() - 1; 862 int l = value.length() - 1;
862 if ( value.mid( start, l - start + 1 ).length() > 0 ) 863 if ( value.mid( start, l - start + 1 ).length() > 0 )
863 list << value.mid( start, l - start + 1 ); 864 list << value.mid( start, l - start + 1 );
864 else 865 else
865 list << QString::null; 866 list << QString::null;
866 867
867 return list; 868 return list;
868} 869}