summaryrefslogtreecommitdiffabout
authorulf69 <ulf69>2004-08-20 00:36:50 (UTC)
committer ulf69 <ulf69>2004-08-20 00:36:50 (UTC)
commitd39b363278224b969d4c2945d32968c980b5d842 (patch) (unidiff)
tree418087aff444216ddb08fcd94fa7fdbfa6d46947
parentf4149cef5f3be19d64c9c53130a62de0ec28ee44 (diff)
downloadkdepimpi-d39b363278224b969d4c2945d32968c980b5d842.zip
kdepimpi-d39b363278224b969d4c2945d32968c980b5d842.tar.gz
kdepimpi-d39b363278224b969d4c2945d32968c980b5d842.tar.bz2
performance optimization during vCard loading
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--kabc/vcardformatimpl.cpp51
-rw-r--r--kabc/vcardformatimpl.h4
2 files changed, 29 insertions, 26 deletions
diff --git a/kabc/vcardformatimpl.cpp b/kabc/vcardformatimpl.cpp
index 3fcaf94..bd9a57b 100644
--- a/kabc/vcardformatimpl.cpp
+++ b/kabc/vcardformatimpl.cpp
@@ -1,1027 +1,1030 @@
1/* 1/*
2 This file is part of libkabc. 2 This file is part of libkabc.
3 Copyright (c) 2001 Cornelius Schumacher <schumacher@kde.org> 3 Copyright (c) 2001 Cornelius Schumacher <schumacher@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/* 21/*
22Enhanced Version of the file for platform independent KDE tools. 22Enhanced Version of the file for platform independent KDE tools.
23Copyright (c) 2004 Ulf Schenk 23Copyright (c) 2004 Ulf Schenk
24 24
25$Id$ 25$Id$
26*/ 26*/
27 27
28#include <qfile.h> 28#include <qfile.h>
29#include <qregexp.h> 29#include <qregexp.h>
30 30
31#include <kdebug.h> 31#include <kdebug.h>
32#include <kmdcodec.h> 32#include <kmdcodec.h>
33#include <kstandarddirs.h> 33#include <kstandarddirs.h>
34#include <ktempfile.h> 34#include <ktempfile.h>
35 35
36#include <VCard.h> 36#include <VCard.h>
37 37
38#include "addressbook.h" 38#include "addressbook.h"
39#include "vcardformatimpl.h" 39#include "vcardformatimpl.h"
40 40
41using namespace KABC; 41using namespace KABC;
42using namespace VCARD; 42using namespace VCARD;
43 43
44bool VCardFormatImpl::load( Addressee &addressee, QFile *file ) 44bool VCardFormatImpl::load( Addressee &addressee, QFile *file )
45{ 45{
46 kdDebug(5700) << "VCardFormat::load()" << endl; 46 kdDebug(5700) << "VCardFormat::load()" << endl;
47 47
48 QByteArray fdata = file->readAll(); 48 QByteArray fdata = file->readAll();
49 QCString data(fdata.data(), fdata.size()+1); 49 QCString data(fdata.data(), fdata.size()+1);
50 50
51 VCardEntity e( data ); 51 VCardEntity e( data );
52 52
53 VCardListIterator it( e.cardList() ); 53 VCardListIterator it( e.cardList() );
54 54
55 if ( it.current() ) { 55 if ( it.current() ) {
56 VCard v(*it.current()); 56//US VCard v(*it.current());
57 loadAddressee( addressee, v ); 57//US loadAddressee( addressee, v );
58 loadAddressee( addressee, it.current() );
58 return true; 59 return true;
59 } 60 }
60 61
61 return false; 62 return false;
62} 63}
63 64
64bool VCardFormatImpl::loadAll( AddressBook *addressBook, Resource *resource, QFile *file ) 65bool VCardFormatImpl::loadAll( AddressBook *addressBook, Resource *resource, QFile *file )
65{ 66{
66 kdDebug(5700) << "VCardFormat::loadAll()" << endl; 67 kdDebug(5700) << "VCardFormat::loadAll()" << endl;
67 68
68 QByteArray fdata = file->readAll(); 69 QByteArray fdata = file->readAll();
69 QCString data(fdata.data(), fdata.size()+1); 70 QCString data(fdata.data(), fdata.size()+1);
70 71
71 VCardEntity e( data ); 72 VCardEntity e( data );
72 73
73 VCardListIterator it( e.cardList() ); 74 VCardListIterator it( e.cardList() );
74 75
75 for (; it.current(); ++it) { 76 for (; it.current(); ++it) {
76 VCard v(*it.current()); 77//US VCard v(*it.current());
77 Addressee addressee; 78 Addressee addressee;
78 loadAddressee( addressee, v ); 79//US loadAddressee( addressee, v );
80 loadAddressee( addressee, it.current() );
79 addressee.setResource( resource ); 81 addressee.setResource( resource );
80 addressBook->insertAddressee( addressee ); 82 addressBook->insertAddressee( addressee );
81 } 83 }
82 84
83 return true; 85 return true;
84} 86}
85 87
86void VCardFormatImpl::save( const Addressee &addressee, QFile *file ) 88void VCardFormatImpl::save( const Addressee &addressee, QFile *file )
87{ 89{
88 VCardEntity vcards; 90 VCardEntity vcards;
89 VCardList vcardlist; 91 VCardList vcardlist;
90 vcardlist.setAutoDelete( true ); 92 vcardlist.setAutoDelete( true );
91 93
92 VCard *v = new VCard; 94 VCard *v = new VCard;
93 95
94 saveAddressee( addressee, v, false ); 96 saveAddressee( addressee, v, false );
95 97
96 vcardlist.append( v ); 98 vcardlist.append( v );
97 vcards.setCardList( vcardlist ); 99 vcards.setCardList( vcardlist );
98 100
99 QCString vcardData = vcards.asString(); 101 QCString vcardData = vcards.asString();
100 file->writeBlock( (const char*)vcardData, vcardData.length() ); 102 file->writeBlock( (const char*)vcardData, vcardData.length() );
101} 103}
102 104
103void VCardFormatImpl::saveAll( AddressBook *ab, Resource *resource, QFile *file ) 105void VCardFormatImpl::saveAll( AddressBook *ab, Resource *resource, QFile *file )
104{ 106{
105 VCardEntity vcards; 107 VCardEntity vcards;
106 VCardList vcardlist; 108 VCardList vcardlist;
107 vcardlist.setAutoDelete( true ); 109 vcardlist.setAutoDelete( true );
108 110
109 AddressBook::Iterator it; 111 AddressBook::Iterator it;
110 for ( it = ab->begin(); it != ab->end(); ++it ) { 112 for ( it = ab->begin(); it != ab->end(); ++it ) {
111 if ( (*it).resource() == resource ) { 113 if ( (*it).resource() == resource ) {
112 VCard *v = new VCard; 114 VCard *v = new VCard;
113 saveAddressee( (*it), v, false ); 115 saveAddressee( (*it), v, false );
114 (*it).setChanged( false ); 116 (*it).setChanged( false );
115 vcardlist.append( v ); 117 vcardlist.append( v );
116 } 118 }
117 } 119 }
118 120
119 vcards.setCardList( vcardlist ); 121 vcards.setCardList( vcardlist );
120 122
121 QCString vcardData = vcards.asString(); 123 QCString vcardData = vcards.asString();
122 file->writeBlock( (const char*)vcardData, vcardData.length() ); 124 file->writeBlock( (const char*)vcardData, vcardData.length() );
123} 125}
124 126
125bool VCardFormatImpl::loadAddressee( Addressee& addressee, VCard &v ) 127bool VCardFormatImpl::loadAddressee( Addressee& addressee, VCard *v )
126{ 128{
127 QPtrList<ContentLine> contentLines = v.contentLineList(); 129 QPtrList<ContentLine> contentLines = v->contentLineList();
128 ContentLine *cl; 130 ContentLine *cl;
129 131
130 for( cl = contentLines.first(); cl; cl = contentLines.next() ) { 132 for( cl = contentLines.first(); cl; cl = contentLines.next() ) {
131 QCString n = cl->name(); 133 QCString n = cl->name();
132 if ( n.left( 2 ) == "X-" ) { 134 if ( n.left( 2 ) == "X-" ) {
133 n = n.mid( 2 ); 135 n = n.mid( 2 );
134 int posDash = n.find( "-" ); 136 int posDash = n.find( "-" );
135 addressee.insertCustom( QString::fromUtf8( n.left( posDash ) ), 137 addressee.insertCustom( QString::fromUtf8( n.left( posDash ) ),
136 QString::fromUtf8( n.mid( posDash + 1 ) ), 138 QString::fromUtf8( n.mid( posDash + 1 ) ),
137 QString::fromUtf8( cl->value()->asString() ) ); 139 QString::fromUtf8( cl->value()->asString() ) );
138 continue; 140 continue;
139 } 141 }
140 142
141 EntityType type = cl->entityType(); 143 EntityType type = cl->entityType();
142 switch( type ) { 144 switch( type ) {
143 145
144 case EntityUID: 146 case EntityUID:
145 addressee.setUid( readTextValue( cl ) ); 147 addressee.setUid( readTextValue( cl ) );
146 break; 148 break;
147 149
148 case EntityEmail: 150 case EntityEmail:
149 addressee.insertEmail( readTextValue( cl ) ); 151 addressee.insertEmail( readTextValue( cl ) );
150 break; 152 break;
151 153
152 case EntityName: 154 case EntityName:
153 addressee.setName( readTextValue( cl ) ); 155 addressee.setName( readTextValue( cl ) );
154 break; 156 break;
155 157
156 case EntityFullName: 158 case EntityFullName:
157 addressee.setFormattedName( readTextValue( cl ) ); 159 addressee.setFormattedName( readTextValue( cl ) );
158 break; 160 break;
159 161
160 case EntityURL: 162 case EntityURL:
161 addressee.setUrl( KURL( readTextValue( cl ) ) ); 163 addressee.setUrl( KURL( readTextValue( cl ) ) );
162 break; 164 break;
163 165
164 case EntityNickname: 166 case EntityNickname:
165 addressee.setNickName( readTextValue( cl ) ); 167 addressee.setNickName( readTextValue( cl ) );
166 break; 168 break;
167 169
168 case EntityLabel: 170 case EntityLabel:
169 // not yet supported by kabc 171 // not yet supported by kabc
170 break; 172 break;
171 173
172 case EntityMailer: 174 case EntityMailer:
173 addressee.setMailer( readTextValue( cl ) ); 175 addressee.setMailer( readTextValue( cl ) );
174 break; 176 break;
175 177
176 case EntityTitle: 178 case EntityTitle:
177 addressee.setTitle( readTextValue( cl ) ); 179 addressee.setTitle( readTextValue( cl ) );
178 break; 180 break;
179 181
180 case EntityRole: 182 case EntityRole:
181 addressee.setRole( readTextValue( cl ) ); 183 addressee.setRole( readTextValue( cl ) );
182 break; 184 break;
183 185
184 case EntityOrganisation: 186 case EntityOrganisation:
185 addressee.setOrganization( readTextValue( cl ) ); 187 addressee.setOrganization( readTextValue( cl ) );
186 break; 188 break;
187 189
188 case EntityNote: 190 case EntityNote:
189 addressee.setNote( readTextValue( cl ) ); 191 addressee.setNote( readTextValue( cl ) );
190 break; 192 break;
191 193
192 case EntityProductID: 194 case EntityProductID:
193 addressee.setProductId( readTextValue( cl ) ); 195 addressee.setProductId( readTextValue( cl ) );
194 break; 196 break;
195 197
196 case EntitySortString: 198 case EntitySortString:
197 addressee.setSortString( readTextValue( cl ) ); 199 addressee.setSortString( readTextValue( cl ) );
198 break; 200 break;
199 201
200 case EntityN: 202 case EntityN:
201 readNValue( cl, addressee ); 203 readNValue( cl, addressee );
202 break; 204 break;
203 205
204 case EntityAddress: 206 case EntityAddress:
205 addressee.insertAddress( readAddressValue( cl ) ); 207 addressee.insertAddress( readAddressValue( cl ) );
206 break; 208 break;
207 209
208 case EntityTelephone: 210 case EntityTelephone:
209 addressee.insertPhoneNumber( readTelephoneValue( cl ) ); 211 addressee.insertPhoneNumber( readTelephoneValue( cl ) );
210 break; 212 break;
211 213
212 case EntityCategories: 214 case EntityCategories:
213 addressee.setCategories( QStringList::split( ",", readTextValue( cl ) ) ); 215 addressee.setCategories( QStringList::split( ",", readTextValue( cl ) ) );
214 break; 216 break;
215 217
216 case EntityBirthday: 218 case EntityBirthday:
217 addressee.setBirthday( readDateValue( cl ) ); 219 addressee.setBirthday( readDateValue( cl ) );
218 break; 220 break;
219 221
220 case EntityRevision: 222 case EntityRevision:
221 addressee.setRevision( readDateTimeValue( cl ) ); 223 addressee.setRevision( readDateTimeValue( cl ) );
222 break; 224 break;
223 225
224 case EntityGeo: 226 case EntityGeo:
225 addressee.setGeo( readGeoValue( cl ) ); 227 addressee.setGeo( readGeoValue( cl ) );
226 break; 228 break;
227 229
228 case EntityTimeZone: 230 case EntityTimeZone:
229 addressee.setTimeZone( readUTCValue( cl ) ); 231 addressee.setTimeZone( readUTCValue( cl ) );
230 break; 232 break;
231 233
232 case EntityVersion: 234 case EntityVersion:
233 break; 235 break;
234 236
235 case EntityClass: 237 case EntityClass:
236 addressee.setSecrecy( readClassValue( cl ) ); 238 addressee.setSecrecy( readClassValue( cl ) );
237 break; 239 break;
238 240
239 case EntityKey: 241 case EntityKey:
240 addressee.insertKey( readKeyValue( cl ) ); 242 addressee.insertKey( readKeyValue( cl ) );
241 break; 243 break;
242 244
243 case EntityPhoto: 245 case EntityPhoto:
244 addressee.setPhoto( readPictureValue( cl, EntityPhoto, addressee ) ); 246 addressee.setPhoto( readPictureValue( cl, EntityPhoto, addressee ) );
245 break; 247 break;
246 248
247 case EntityLogo: 249 case EntityLogo:
248 addressee.setLogo( readPictureValue( cl, EntityLogo, addressee ) ); 250 addressee.setLogo( readPictureValue( cl, EntityLogo, addressee ) );
249 break; 251 break;
250 252
251 case EntityAgent: 253 case EntityAgent:
252 addressee.setAgent( readAgentValue( cl ) ); 254 addressee.setAgent( readAgentValue( cl ) );
253 break; 255 break;
254 256
255 case EntitySound: 257 case EntitySound:
256 addressee.setSound( readSoundValue( cl, addressee ) ); 258 addressee.setSound( readSoundValue( cl, addressee ) );
257 break; 259 break;
258 260
259 default: 261 default:
260 kdDebug(5700) << "VCardFormat::load(): Unsupported entity: " 262 kdDebug(5700) << "VCardFormat::load(): Unsupported entity: "
261 << int( type ) << ": " << cl->asString() << endl; 263 << int( type ) << ": " << cl->asString() << endl;
262 break; 264 break;
263 } 265 }
264 } 266 }
265 267
266 for( cl = contentLines.first(); cl; cl = contentLines.next() ) { 268 for( cl = contentLines.first(); cl; cl = contentLines.next() ) {
267 EntityType type = cl->entityType(); 269 EntityType type = cl->entityType();
268 if ( type == EntityLabel ) { 270 if ( type == EntityLabel ) {
269 int type = readAddressParam( cl ); 271 int type = readAddressParam( cl );
270 Address address = addressee.address( type ); 272 Address address = addressee.address( type );
271 if ( address.isEmpty() ) 273 if ( address.isEmpty() )
272 address.setType( type ); 274 address.setType( type );
273 275
274 address.setLabel( QString::fromUtf8( cl->value()->asString() ) ); 276 address.setLabel( QString::fromUtf8( cl->value()->asString() ) );
275 addressee.insertAddress( address ); 277 addressee.insertAddress( address );
276 } 278 }
277 } 279 }
278 280
279 return true; 281 return true;
280} 282}
281 283
282void VCardFormatImpl::saveAddressee( const Addressee &addressee, VCard *v, bool intern ) 284void VCardFormatImpl::saveAddressee( const Addressee &addressee, VCard *v, bool intern )
283{ 285{
284 ContentLine cl; 286 ContentLine cl;
285 QString value; 287 QString value;
286 288
287 addTextValue( v, EntityName, addressee.name() ); 289 addTextValue( v, EntityName, addressee.name() );
288 addTextValue( v, EntityUID, addressee.uid() ); 290 addTextValue( v, EntityUID, addressee.uid() );
289 addTextValue( v, EntityFullName, addressee.formattedName() ); 291 addTextValue( v, EntityFullName, addressee.formattedName() );
290 292
291 QStringList emails = addressee.emails(); 293 QStringList emails = addressee.emails();
292 QStringList::ConstIterator it4; 294 QStringList::ConstIterator it4;
293 for( it4 = emails.begin(); it4 != emails.end(); ++it4 ) { 295 for( it4 = emails.begin(); it4 != emails.end(); ++it4 ) {
294 addTextValue( v, EntityEmail, *it4 ); 296 addTextValue( v, EntityEmail, *it4 );
295 } 297 }
296 298
297 QStringList customs = addressee.customs(); 299 QStringList customs = addressee.customs();
298 QStringList::ConstIterator it5; 300 QStringList::ConstIterator it5;
299 for( it5 = customs.begin(); it5 != customs.end(); ++it5 ) { 301 for( it5 = customs.begin(); it5 != customs.end(); ++it5 ) {
300 addCustomValue( v, *it5 ); 302 addCustomValue( v, *it5 );
301 } 303 }
302 304
303 addTextValue( v, EntityURL, addressee.url().url() ); 305 addTextValue( v, EntityURL, addressee.url().url() );
304 306
305 addNValue( v, addressee ); 307 addNValue( v, addressee );
306 308
307 addTextValue( v, EntityNickname, addressee.nickName() ); 309 addTextValue( v, EntityNickname, addressee.nickName() );
308 addTextValue( v, EntityMailer, addressee.mailer() ); 310 addTextValue( v, EntityMailer, addressee.mailer() );
309 addTextValue( v, EntityTitle, addressee.title() ); 311 addTextValue( v, EntityTitle, addressee.title() );
310 addTextValue( v, EntityRole, addressee.role() ); 312 addTextValue( v, EntityRole, addressee.role() );
311 addTextValue( v, EntityOrganisation, addressee.organization() ); 313 addTextValue( v, EntityOrganisation, addressee.organization() );
312 addTextValue( v, EntityNote, addressee.note() ); 314 addTextValue( v, EntityNote, addressee.note() );
313 addTextValue( v, EntityProductID, addressee.productId() ); 315 addTextValue( v, EntityProductID, addressee.productId() );
314 addTextValue( v, EntitySortString, addressee.sortString() ); 316 addTextValue( v, EntitySortString, addressee.sortString() );
315 317
316 Address::List addresses = addressee.addresses(); 318 Address::List addresses = addressee.addresses();
317 Address::List::ConstIterator it3; 319 Address::List::ConstIterator it3;
318 for( it3 = addresses.begin(); it3 != addresses.end(); ++it3 ) { 320 for( it3 = addresses.begin(); it3 != addresses.end(); ++it3 ) {
319 addAddressValue( v, *it3 ); 321 addAddressValue( v, *it3 );
320 addLabelValue( v, *it3 ); 322 addLabelValue( v, *it3 );
321 } 323 }
322 324
323 PhoneNumber::List phoneNumbers = addressee.phoneNumbers(); 325 PhoneNumber::List phoneNumbers = addressee.phoneNumbers();
324 PhoneNumber::List::ConstIterator it2; 326 PhoneNumber::List::ConstIterator it2;
325 for( it2 = phoneNumbers.begin(); it2 != phoneNumbers.end(); ++it2 ) { 327 for( it2 = phoneNumbers.begin(); it2 != phoneNumbers.end(); ++it2 ) {
326 addTelephoneValue( v, *it2 ); 328 addTelephoneValue( v, *it2 );
327 } 329 }
328 330
329 Key::List keys = addressee.keys(); 331 Key::List keys = addressee.keys();
330 Key::List::ConstIterator it6; 332 Key::List::ConstIterator it6;
331 for( it6 = keys.begin(); it6 != keys.end(); ++it6 ) { 333 for( it6 = keys.begin(); it6 != keys.end(); ++it6 ) {
332 addKeyValue( v, *it6 ); 334 addKeyValue( v, *it6 );
333 } 335 }
334 336
335 addTextValue( v, EntityCategories, addressee.categories().join(",") ); 337 addTextValue( v, EntityCategories, addressee.categories().join(",") );
336 338
337 addDateValue( v, EntityBirthday, addressee.birthday().date() ); 339 addDateValue( v, EntityBirthday, addressee.birthday().date() );
338 addDateTimeValue( v, EntityRevision, addressee.revision() ); 340 addDateTimeValue( v, EntityRevision, addressee.revision() );
339 addGeoValue( v, addressee.geo() ); 341 addGeoValue( v, addressee.geo() );
340 addUTCValue( v, addressee.timeZone() ); 342 addUTCValue( v, addressee.timeZone() );
341 343
342 addClassValue( v, addressee.secrecy() ); 344 addClassValue( v, addressee.secrecy() );
343 345
344 addPictureValue( v, EntityPhoto, addressee.photo(), addressee, intern ); 346 addPictureValue( v, EntityPhoto, addressee.photo(), addressee, intern );
345 addPictureValue( v, EntityLogo, addressee.logo(), addressee, intern ); 347 addPictureValue( v, EntityLogo, addressee.logo(), addressee, intern );
346 348
347 addAgentValue( v, addressee.agent() ); 349 addAgentValue( v, addressee.agent() );
348 350
349 addSoundValue( v, addressee.sound(), addressee, intern ); 351 addSoundValue( v, addressee.sound(), addressee, intern );
350} 352}
351 353
352void VCardFormatImpl::addCustomValue( VCard *v, const QString &txt ) 354void VCardFormatImpl::addCustomValue( VCard *v, const QString &txt )
353{ 355{
354 if ( txt.isEmpty() ) return; 356 if ( txt.isEmpty() ) return;
355 357
356 ContentLine cl; 358 ContentLine cl;
357 cl.setName( "X-" + txt.left( txt.find( ":" ) ).utf8() ); 359 cl.setName( "X-" + txt.left( txt.find( ":" ) ).utf8() );
358 QString value = txt.mid( txt.find( ":" ) + 1 ); 360 QString value = txt.mid( txt.find( ":" ) + 1 );
359 if ( value.isEmpty() ) 361 if ( value.isEmpty() )
360 return; 362 return;
361 cl.setValue( new TextValue( value.utf8() ) ); 363 cl.setValue( new TextValue( value.utf8() ) );
362 v->add(cl); 364 v->add(cl);
363} 365}
364 366
365void VCardFormatImpl::addTextValue( VCard *v, EntityType type, const QString &txt ) 367void VCardFormatImpl::addTextValue( VCard *v, EntityType type, const QString &txt )
366{ 368{
367 if ( txt.isEmpty() ) return; 369 if ( txt.isEmpty() ) return;
368 370
369 ContentLine cl; 371 ContentLine cl;
370 cl.setName( EntityTypeToParamName( type ) ); 372 cl.setName( EntityTypeToParamName( type ) );
371 cl.setValue( new TextValue( txt.utf8() ) ); 373 cl.setValue( new TextValue( txt.utf8() ) );
372 v->add(cl); 374 v->add(cl);
373} 375}
374 376
375void VCardFormatImpl::addDateValue( VCard *vcard, EntityType type, 377void VCardFormatImpl::addDateValue( VCard *vcard, EntityType type,
376 const QDate &date ) 378 const QDate &date )
377{ 379{
378 if ( !date.isValid() ) return; 380 if ( !date.isValid() ) return;
379 381
380 ContentLine cl; 382 ContentLine cl;
381 cl.setName( EntityTypeToParamName( type ) ); 383 cl.setName( EntityTypeToParamName( type ) );
382 384
383 DateValue *v = new DateValue( date ); 385 DateValue *v = new DateValue( date );
384 cl.setValue( v ); 386 cl.setValue( v );
385 vcard->add(cl); 387 vcard->add(cl);
386} 388}
387 389
388void VCardFormatImpl::addDateTimeValue( VCard *vcard, EntityType type, 390void VCardFormatImpl::addDateTimeValue( VCard *vcard, EntityType type,
389 const QDateTime &dateTime ) 391 const QDateTime &dateTime )
390{ 392{
391 if ( !dateTime.isValid() ) return; 393 if ( !dateTime.isValid() ) return;
392 394
393 ContentLine cl; 395 ContentLine cl;
394 cl.setName( EntityTypeToParamName( type ) ); 396 cl.setName( EntityTypeToParamName( type ) );
395 397
396 DateValue *v = new DateValue( dateTime ); 398 DateValue *v = new DateValue( dateTime );
397 cl.setValue( v ); 399 cl.setValue( v );
398 vcard->add(cl); 400 vcard->add(cl);
399} 401}
400 402
401void VCardFormatImpl::addAddressValue( VCard *vcard, const Address &a ) 403void VCardFormatImpl::addAddressValue( VCard *vcard, const Address &a )
402{ 404{
403 if ( a.isEmpty() ) 405 if ( a.isEmpty() )
404 return; 406 return;
405 407
406 ContentLine cl; 408 ContentLine cl;
407 cl.setName( EntityTypeToParamName( EntityAddress ) ); 409 cl.setName( EntityTypeToParamName( EntityAddress ) );
408 410
409 AdrValue *v = new AdrValue; 411 AdrValue *v = new AdrValue;
410 v->setPOBox( a.postOfficeBox().utf8() ); 412 v->setPOBox( a.postOfficeBox().utf8() );
411 v->setExtAddress( a.extended().utf8() ); 413 v->setExtAddress( a.extended().utf8() );
412 v->setStreet( a.street().utf8() ); 414 v->setStreet( a.street().utf8() );
413 v->setLocality( a.locality().utf8() ); 415 v->setLocality( a.locality().utf8() );
414 v->setRegion( a.region().utf8() ); 416 v->setRegion( a.region().utf8() );
415 v->setPostCode( a.postalCode().utf8() ); 417 v->setPostCode( a.postalCode().utf8() );
416 v->setCountryName( a.country().utf8() ); 418 v->setCountryName( a.country().utf8() );
417 cl.setValue( v ); 419 cl.setValue( v );
418 420
419 addAddressParam( &cl, a.type() ); 421 addAddressParam( &cl, a.type() );
420 422
421 vcard->add( cl ); 423 vcard->add( cl );
422} 424}
423 425
424void VCardFormatImpl::addLabelValue( VCard *vcard, const Address &a ) 426void VCardFormatImpl::addLabelValue( VCard *vcard, const Address &a )
425{ 427{
426 if ( a.label().isEmpty() ) return; 428 if ( a.label().isEmpty() ) return;
427 429
428 ContentLine cl; 430 ContentLine cl;
429 cl.setName( EntityTypeToParamName( EntityLabel ) ); 431 cl.setName( EntityTypeToParamName( EntityLabel ) );
430 cl.setValue( new TextValue( a.label().utf8() ) ); 432 cl.setValue( new TextValue( a.label().utf8() ) );
431 433
432 addAddressParam( &cl, a.type() ); 434 addAddressParam( &cl, a.type() );
433 435
434 vcard->add( cl ); 436 vcard->add( cl );
435} 437}
436 438
437void VCardFormatImpl::addAddressParam( ContentLine *cl, int type ) 439void VCardFormatImpl::addAddressParam( ContentLine *cl, int type )
438{ 440{
439 ParamList params; 441 ParamList params;
440 if ( type & Address::Dom ) params.append( new Param( "TYPE", "dom" ) ); 442 if ( type & Address::Dom ) params.append( new Param( "TYPE", "dom" ) );
441 if ( type & Address::Intl ) params.append( new Param( "TYPE", "intl" ) ); 443 if ( type & Address::Intl ) params.append( new Param( "TYPE", "intl" ) );
442 if ( type & Address::Parcel ) params.append( new Param( "TYPE", "parcel" ) ); 444 if ( type & Address::Parcel ) params.append( new Param( "TYPE", "parcel" ) );
443 if ( type & Address::Postal ) params.append( new Param( "TYPE", "postal" ) ); 445 if ( type & Address::Postal ) params.append( new Param( "TYPE", "postal" ) );
444 if ( type & Address::Work ) params.append( new Param( "TYPE", "work" ) ); 446 if ( type & Address::Work ) params.append( new Param( "TYPE", "work" ) );
445 if ( type & Address::Home ) params.append( new Param( "TYPE", "home" ) ); 447 if ( type & Address::Home ) params.append( new Param( "TYPE", "home" ) );
446 if ( type & Address::Pref ) params.append( new Param( "TYPE", "pref" ) ); 448 if ( type & Address::Pref ) params.append( new Param( "TYPE", "pref" ) );
447 cl->setParamList( params ); 449 cl->setParamList( params );
448} 450}
449 451
450void VCardFormatImpl::addGeoValue( VCard *vcard, const Geo &geo ) 452void VCardFormatImpl::addGeoValue( VCard *vcard, const Geo &geo )
451{ 453{
452 if ( !geo.isValid() ) return; 454 if ( !geo.isValid() ) return;
453 455
454 ContentLine cl; 456 ContentLine cl;
455 cl.setName( EntityTypeToParamName( EntityGeo ) ); 457 cl.setName( EntityTypeToParamName( EntityGeo ) );
456 458
457 GeoValue *v = new GeoValue; 459 GeoValue *v = new GeoValue;
458 v->setLatitude( geo.latitude() ); 460 v->setLatitude( geo.latitude() );
459 v->setLongitude( geo.longitude() ); 461 v->setLongitude( geo.longitude() );
460 462
461 cl.setValue( v ); 463 cl.setValue( v );
462 vcard->add(cl); 464 vcard->add(cl);
463} 465}
464 466
465void VCardFormatImpl::addUTCValue( VCard *vcard, const TimeZone &tz ) 467void VCardFormatImpl::addUTCValue( VCard *vcard, const TimeZone &tz )
466{ 468{
467 if ( !tz.isValid() ) return; 469 if ( !tz.isValid() ) return;
468 470
469 ContentLine cl; 471 ContentLine cl;
470 cl.setName( EntityTypeToParamName( EntityTimeZone ) ); 472 cl.setName( EntityTypeToParamName( EntityTimeZone ) );
471 473
472 UTCValue *v = new UTCValue; 474 UTCValue *v = new UTCValue;
473 475
474 v->setPositive( tz.offset() >= 0 ); 476 v->setPositive( tz.offset() >= 0 );
475 v->setHour( (tz.offset() / 60) * ( tz.offset() >= 0 ? 1 : -1 ) ); 477 v->setHour( (tz.offset() / 60) * ( tz.offset() >= 0 ? 1 : -1 ) );
476 v->setMinute( (tz.offset() % 60) * ( tz.offset() >= 0 ? 1 : -1 ) ); 478 v->setMinute( (tz.offset() % 60) * ( tz.offset() >= 0 ? 1 : -1 ) );
477 479
478 cl.setValue( v ); 480 cl.setValue( v );
479 vcard->add(cl); 481 vcard->add(cl);
480} 482}
481 483
482void VCardFormatImpl::addClassValue( VCard *vcard, const Secrecy &secrecy ) 484void VCardFormatImpl::addClassValue( VCard *vcard, const Secrecy &secrecy )
483{ 485{
484 ContentLine cl; 486 ContentLine cl;
485 cl.setName( EntityTypeToParamName( EntityClass ) ); 487 cl.setName( EntityTypeToParamName( EntityClass ) );
486 488
487 ClassValue *v = new ClassValue; 489 ClassValue *v = new ClassValue;
488 switch ( secrecy.type() ) { 490 switch ( secrecy.type() ) {
489 case Secrecy::Public: 491 case Secrecy::Public:
490 v->setType( (int)ClassValue::Public ); 492 v->setType( (int)ClassValue::Public );
491 break; 493 break;
492 case Secrecy::Private: 494 case Secrecy::Private:
493 v->setType( (int)ClassValue::Private ); 495 v->setType( (int)ClassValue::Private );
494 break; 496 break;
495 case Secrecy::Confidential: 497 case Secrecy::Confidential:
496 v->setType( (int)ClassValue::Confidential ); 498 v->setType( (int)ClassValue::Confidential );
497 break; 499 break;
498 } 500 }
499 501
500 cl.setValue( v ); 502 cl.setValue( v );
501 vcard->add(cl); 503 vcard->add(cl);
502} 504}
503 505
504 506
505Address VCardFormatImpl::readAddressValue( ContentLine *cl ) 507Address VCardFormatImpl::readAddressValue( ContentLine *cl )
506{ 508{
507 Address a; 509 Address a;
508 AdrValue *v = (AdrValue *)cl->value(); 510 AdrValue *v = (AdrValue *)cl->value();
509 a.setPostOfficeBox( QString::fromUtf8( v->poBox() ) ); 511 a.setPostOfficeBox( QString::fromUtf8( v->poBox() ) );
510 a.setExtended( QString::fromUtf8( v->extAddress() ) ); 512 a.setExtended( QString::fromUtf8( v->extAddress() ) );
511 a.setStreet( QString::fromUtf8( v->street() ) ); 513 a.setStreet( QString::fromUtf8( v->street() ) );
512 a.setLocality( QString::fromUtf8( v->locality() ) ); 514 a.setLocality( QString::fromUtf8( v->locality() ) );
513 a.setRegion( QString::fromUtf8( v->region() ) ); 515 a.setRegion( QString::fromUtf8( v->region() ) );
514 a.setPostalCode( QString::fromUtf8( v->postCode() ) ); 516 a.setPostalCode( QString::fromUtf8( v->postCode() ) );
515 a.setCountry( QString::fromUtf8( v->countryName() ) ); 517 a.setCountry( QString::fromUtf8( v->countryName() ) );
516 518
517 a.setType( readAddressParam( cl ) ); 519 a.setType( readAddressParam( cl ) );
518 520
519 return a; 521 return a;
520} 522}
521 523
522int VCardFormatImpl::readAddressParam( ContentLine *cl ) 524int VCardFormatImpl::readAddressParam( ContentLine *cl )
523{ 525{
524 int type = 0; 526 int type = 0;
525 ParamList params = cl->paramList(); 527 ParamList params = cl->paramList();
526 ParamListIterator it( params ); 528 ParamListIterator it( params );
527 QCString tmpStr; 529 QCString tmpStr;
528 for( ; it.current(); ++it ) { 530 for( ; it.current(); ++it ) {
529 if ( (*it)->name().upper() == "TYPE" ) { 531 if ( (*it)->name().upper() == "TYPE" ) {
530 tmpStr = (*it)->value().lower(); 532 tmpStr = (*it)->value().lower();
531 if ( tmpStr == "dom" ) type |= Address::Dom; 533 if ( tmpStr == "dom" ) type |= Address::Dom;
532 else if ( tmpStr == "intl" ) type |= Address::Intl; 534 else if ( tmpStr == "intl" ) type |= Address::Intl;
533 else if ( tmpStr == "parcel" ) type |= Address::Parcel; 535 else if ( tmpStr == "parcel" ) type |= Address::Parcel;
534 else if ( tmpStr == "postal" ) type |= Address::Postal; 536 else if ( tmpStr == "postal" ) type |= Address::Postal;
535 else if ( tmpStr == "work" ) type |= Address::Work; 537 else if ( tmpStr == "work" ) type |= Address::Work;
536 else if ( tmpStr == "home" ) type |= Address::Home; 538 else if ( tmpStr == "home" ) type |= Address::Home;
537 else if ( tmpStr == "pref" ) type |= Address::Pref; 539 else if ( tmpStr == "pref" ) type |= Address::Pref;
538 } 540 }
539 } 541 }
540 return type; 542 return type;
541} 543}
542 544
543void VCardFormatImpl::addNValue( VCard *vcard, const Addressee &a ) 545void VCardFormatImpl::addNValue( VCard *vcard, const Addressee &a )
544{ 546{
545 ContentLine cl; 547 ContentLine cl;
546 cl.setName(EntityTypeToParamName( EntityN ) ); 548 cl.setName(EntityTypeToParamName( EntityN ) );
547 NValue *v = new NValue; 549 NValue *v = new NValue;
548 v->setFamily( a.familyName().utf8() ); 550 v->setFamily( a.familyName().utf8() );
549 v->setGiven( a.givenName().utf8() ); 551 v->setGiven( a.givenName().utf8() );
550 v->setMiddle( a.additionalName().utf8() ); 552 v->setMiddle( a.additionalName().utf8() );
551 v->setPrefix( a.prefix().utf8() ); 553 v->setPrefix( a.prefix().utf8() );
552 v->setSuffix( a.suffix().utf8() ); 554 v->setSuffix( a.suffix().utf8() );
553 555
554 cl.setValue( v ); 556 cl.setValue( v );
555 vcard->add(cl); 557 vcard->add(cl);
556} 558}
557 559
558void VCardFormatImpl::readNValue( ContentLine *cl, Addressee &a ) 560void VCardFormatImpl::readNValue( ContentLine *cl, Addressee &a )
559{ 561{
560 NValue *v = (NValue *)cl->value(); 562 NValue *v = (NValue *)cl->value();
561 a.setFamilyName( QString::fromUtf8( v->family() ) ); 563 a.setFamilyName( QString::fromUtf8( v->family() ) );
562 a.setGivenName( QString::fromUtf8( v->given() ) ); 564 a.setGivenName( QString::fromUtf8( v->given() ) );
563 a.setAdditionalName( QString::fromUtf8( v->middle() ) ); 565 a.setAdditionalName( QString::fromUtf8( v->middle() ) );
564 a.setPrefix( QString::fromUtf8( v->prefix() ) ); 566 a.setPrefix( QString::fromUtf8( v->prefix() ) );
565 a.setSuffix( QString::fromUtf8( v->suffix() ) ); 567 a.setSuffix( QString::fromUtf8( v->suffix() ) );
566} 568}
567 569
568void VCardFormatImpl::addTelephoneValue( VCard *v, const PhoneNumber &p ) 570void VCardFormatImpl::addTelephoneValue( VCard *v, const PhoneNumber &p )
569{ 571{
570 if ( p.number().isEmpty() ) 572 if ( p.number().isEmpty() )
571 return; 573 return;
572 574
573 ContentLine cl; 575 ContentLine cl;
574 cl.setName(EntityTypeToParamName(EntityTelephone)); 576 cl.setName(EntityTypeToParamName(EntityTelephone));
575 cl.setValue(new TelValue( p.number().utf8() )); 577 cl.setValue(new TelValue( p.number().utf8() ));
576 578
577 ParamList params; 579 ParamList params;
578 if( p.type() & PhoneNumber::Home ) params.append( new Param( "TYPE", "home" ) ); 580 if( p.type() & PhoneNumber::Home ) params.append( new Param( "TYPE", "home" ) );
579 if( p.type() & PhoneNumber::Work ) params.append( new Param( "TYPE", "work" ) ); 581 if( p.type() & PhoneNumber::Work ) params.append( new Param( "TYPE", "work" ) );
580 if( p.type() & PhoneNumber::Msg ) params.append( new Param( "TYPE", "msg" ) ); 582 if( p.type() & PhoneNumber::Msg ) params.append( new Param( "TYPE", "msg" ) );
581 if( p.type() & PhoneNumber::Pref ) params.append( new Param( "TYPE", "pref" ) ); 583 if( p.type() & PhoneNumber::Pref ) params.append( new Param( "TYPE", "pref" ) );
582 if( p.type() & PhoneNumber::Voice ) params.append( new Param( "TYPE", "voice" ) ); 584 if( p.type() & PhoneNumber::Voice ) params.append( new Param( "TYPE", "voice" ) );
583 if( p.type() & PhoneNumber::Fax ) params.append( new Param( "TYPE", "fax" ) ); 585 if( p.type() & PhoneNumber::Fax ) params.append( new Param( "TYPE", "fax" ) );
584 if( p.type() & PhoneNumber::Cell ) params.append( new Param( "TYPE", "cell" ) ); 586 if( p.type() & PhoneNumber::Cell ) params.append( new Param( "TYPE", "cell" ) );
585 if( p.type() & PhoneNumber::Video ) params.append( new Param( "TYPE", "video" ) ); 587 if( p.type() & PhoneNumber::Video ) params.append( new Param( "TYPE", "video" ) );
586 if( p.type() & PhoneNumber::Bbs ) params.append( new Param( "TYPE", "bbs" ) ); 588 if( p.type() & PhoneNumber::Bbs ) params.append( new Param( "TYPE", "bbs" ) );
587 if( p.type() & PhoneNumber::Modem ) params.append( new Param( "TYPE", "modem" ) ); 589 if( p.type() & PhoneNumber::Modem ) params.append( new Param( "TYPE", "modem" ) );
588 if( p.type() & PhoneNumber::Car ) params.append( new Param( "TYPE", "car" ) ); 590 if( p.type() & PhoneNumber::Car ) params.append( new Param( "TYPE", "car" ) );
589 if( p.type() & PhoneNumber::Isdn ) params.append( new Param( "TYPE", "isdn" ) ); 591 if( p.type() & PhoneNumber::Isdn ) params.append( new Param( "TYPE", "isdn" ) );
590 if( p.type() & PhoneNumber::Pcs ) params.append( new Param( "TYPE", "pcs" ) ); 592 if( p.type() & PhoneNumber::Pcs ) params.append( new Param( "TYPE", "pcs" ) );
591 if( p.type() & PhoneNumber::Pager ) params.append( new Param( "TYPE", "pager" ) ); 593 if( p.type() & PhoneNumber::Pager ) params.append( new Param( "TYPE", "pager" ) );
592 cl.setParamList( params ); 594 cl.setParamList( params );
593 595
594 v->add(cl); 596 v->add(cl);
595} 597}
596 598
597PhoneNumber VCardFormatImpl::readTelephoneValue( ContentLine *cl ) 599PhoneNumber VCardFormatImpl::readTelephoneValue( ContentLine *cl )
598{ 600{
599 PhoneNumber p; 601 PhoneNumber p;
600 TelValue *value = (TelValue *)cl->value(); 602 TelValue *value = (TelValue *)cl->value();
601 p.setNumber( QString::fromUtf8( value->asString() ) ); 603 p.setNumber( QString::fromUtf8( value->asString() ) );
602 604
603 int type = 0; 605 int type = 0;
604 ParamList params = cl->paramList(); 606 ParamList params = cl->paramList();
605 ParamListIterator it( params ); 607 ParamListIterator it( params );
606 QCString tmpStr; 608 QCString tmpStr;
607 for( ; it.current(); ++it ) { 609 for( ; it.current(); ++it ) {
608 if ( (*it)->name() == "TYPE" ) { 610 if ( (*it)->name() == "TYPE" ) {
609 tmpStr = (*it)->value().lower(); 611 tmpStr = (*it)->value().lower();
610 if ( tmpStr == "home" ) type |= PhoneNumber::Home; 612 if ( tmpStr == "home" ) type |= PhoneNumber::Home;
611 else if ( tmpStr == "work" ) type |= PhoneNumber::Work; 613 else if ( tmpStr == "work" ) type |= PhoneNumber::Work;
612 else if ( tmpStr == "msg" ) type |= PhoneNumber::Msg; 614 else if ( tmpStr == "msg" ) type |= PhoneNumber::Msg;
613 else if ( tmpStr == "pref" ) type |= PhoneNumber::Pref; 615 else if ( tmpStr == "pref" ) type |= PhoneNumber::Pref;
614 else if ( tmpStr == "voice" ) type |= PhoneNumber::Voice; 616 else if ( tmpStr == "voice" ) type |= PhoneNumber::Voice;
615 else if ( tmpStr == "fax" ) type |= PhoneNumber::Fax; 617 else if ( tmpStr == "fax" ) type |= PhoneNumber::Fax;
616 else if ( tmpStr == "cell" ) type |= PhoneNumber::Cell; 618 else if ( tmpStr == "cell" ) type |= PhoneNumber::Cell;
617 else if ( tmpStr == "video" ) type |= PhoneNumber::Video; 619 else if ( tmpStr == "video" ) type |= PhoneNumber::Video;
618 else if ( tmpStr == "bbs" ) type |= PhoneNumber::Bbs; 620 else if ( tmpStr == "bbs" ) type |= PhoneNumber::Bbs;
619 else if ( tmpStr == "modem" ) type |= PhoneNumber::Modem; 621 else if ( tmpStr == "modem" ) type |= PhoneNumber::Modem;
620 else if ( tmpStr == "car" ) type |= PhoneNumber::Car; 622 else if ( tmpStr == "car" ) type |= PhoneNumber::Car;
621 else if ( tmpStr == "isdn" ) type |= PhoneNumber::Isdn; 623 else if ( tmpStr == "isdn" ) type |= PhoneNumber::Isdn;
622 else if ( tmpStr == "pcs" ) type |= PhoneNumber::Pcs; 624 else if ( tmpStr == "pcs" ) type |= PhoneNumber::Pcs;
623 else if ( tmpStr == "pager" ) type |= PhoneNumber::Pager; 625 else if ( tmpStr == "pager" ) type |= PhoneNumber::Pager;
624 } 626 }
625 } 627 }
626 p.setType( type ); 628 p.setType( type );
627 629
628 return p; 630 return p;
629} 631}
630 632
631QString VCardFormatImpl::readTextValue( ContentLine *cl ) 633QString VCardFormatImpl::readTextValue( ContentLine *cl )
632{ 634{
633 VCARD::Value *value = cl->value(); 635 VCARD::Value *value = cl->value();
634 if ( value ) { 636 if ( value ) {
635 return QString::fromUtf8( value->asString() ); 637 return QString::fromUtf8( value->asString() );
636 } else { 638 } else {
637 kdDebug(5700) << "No value: " << cl->asString() << endl; 639 kdDebug(5700) << "No value: " << cl->asString() << endl;
638 return QString::null; 640 return QString::null;
639 } 641 }
640} 642}
641 643
642QDate VCardFormatImpl::readDateValue( ContentLine *cl ) 644QDate VCardFormatImpl::readDateValue( ContentLine *cl )
643{ 645{
644 DateValue *dateValue = (DateValue *)cl->value(); 646 DateValue *dateValue = (DateValue *)cl->value();
645 if ( dateValue ) 647 if ( dateValue )
646 return dateValue->qdate(); 648 return dateValue->qdate();
647 else 649 else
648 return QDate(); 650 return QDate();
649} 651}
650 652
651QDateTime VCardFormatImpl::readDateTimeValue( ContentLine *cl ) 653QDateTime VCardFormatImpl::readDateTimeValue( ContentLine *cl )
652{ 654{
653 DateValue *dateValue = (DateValue *)cl->value(); 655 DateValue *dateValue = (DateValue *)cl->value();
654 if ( dateValue ) 656 if ( dateValue )
655 return dateValue->qdt(); 657 return dateValue->qdt();
656 else 658 else
657 return QDateTime(); 659 return QDateTime();
658} 660}
659 661
660Geo VCardFormatImpl::readGeoValue( ContentLine *cl ) 662Geo VCardFormatImpl::readGeoValue( ContentLine *cl )
661{ 663{
662 GeoValue *geoValue = (GeoValue *)cl->value(); 664 GeoValue *geoValue = (GeoValue *)cl->value();
663 if ( geoValue ) { 665 if ( geoValue ) {
664 Geo geo( geoValue->latitude(), geoValue->longitude() ); 666 Geo geo( geoValue->latitude(), geoValue->longitude() );
665 return geo; 667 return geo;
666 } else 668 } else
667 return Geo(); 669 return Geo();
668} 670}
669 671
670TimeZone VCardFormatImpl::readUTCValue( ContentLine *cl ) 672TimeZone VCardFormatImpl::readUTCValue( ContentLine *cl )
671{ 673{
672 UTCValue *utcValue = (UTCValue *)cl->value(); 674 UTCValue *utcValue = (UTCValue *)cl->value();
673 if ( utcValue ) { 675 if ( utcValue ) {
674 TimeZone tz; 676 TimeZone tz;
675 tz.setOffset(((utcValue->hour()*60)+utcValue->minute())*(utcValue->positive() ? 1 : -1)); 677 tz.setOffset(((utcValue->hour()*60)+utcValue->minute())*(utcValue->positive() ? 1 : -1));
676 return tz; 678 return tz;
677 } else 679 } else
678 return TimeZone(); 680 return TimeZone();
679} 681}
680 682
681Secrecy VCardFormatImpl::readClassValue( ContentLine *cl ) 683Secrecy VCardFormatImpl::readClassValue( ContentLine *cl )
682{ 684{
683 ClassValue *classValue = (ClassValue *)cl->value(); 685 ClassValue *classValue = (ClassValue *)cl->value();
684 if ( classValue ) { 686 if ( classValue ) {
685 Secrecy secrecy; 687 Secrecy secrecy;
686 switch ( classValue->type() ) { 688 switch ( classValue->type() ) {
687 case ClassValue::Public: 689 case ClassValue::Public:
688 secrecy.setType( Secrecy::Public ); 690 secrecy.setType( Secrecy::Public );
689 break; 691 break;
690 case ClassValue::Private: 692 case ClassValue::Private:
691 secrecy.setType( Secrecy::Private ); 693 secrecy.setType( Secrecy::Private );
692 break; 694 break;
693 case ClassValue::Confidential: 695 case ClassValue::Confidential:
694 secrecy.setType( Secrecy::Confidential ); 696 secrecy.setType( Secrecy::Confidential );
695 break; 697 break;
696 } 698 }
697 699
698 return secrecy; 700 return secrecy;
699 } else 701 } else
700 return Secrecy(); 702 return Secrecy();
701} 703}
702 704
703void VCardFormatImpl::addKeyValue( VCARD::VCard *vcard, const Key &key ) 705void VCardFormatImpl::addKeyValue( VCARD::VCard *vcard, const Key &key )
704{ 706{
705 ContentLine cl; 707 ContentLine cl;
706 cl.setName( EntityTypeToParamName( EntityKey ) ); 708 cl.setName( EntityTypeToParamName( EntityKey ) );
707 709
708 ParamList params; 710 ParamList params;
709 if ( key.isBinary() ) { 711 if ( key.isBinary() ) {
710 cl.setValue( new TextValue( KCodecs::base64Encode( key.binaryData() ) ) ); 712 cl.setValue( new TextValue( KCodecs::base64Encode( key.binaryData() ) ) );
711 params.append( new Param( "ENCODING", "b" ) ); 713 params.append( new Param( "ENCODING", "b" ) );
712 } else { 714 } else {
713 cl.setValue( new TextValue( key.textData().utf8() ) ); 715 cl.setValue( new TextValue( key.textData().utf8() ) );
714 } 716 }
715 717
716 switch ( key.type() ) { 718 switch ( key.type() ) {
717 case Key::X509: 719 case Key::X509:
718 params.append( new Param( "TYPE", "X509" ) ); 720 params.append( new Param( "TYPE", "X509" ) );
719 break; 721 break;
720 case Key::PGP: 722 case Key::PGP:
721 params.append( new Param( "TYPE", "PGP" ) ); 723 params.append( new Param( "TYPE", "PGP" ) );
722 break; 724 break;
723 case Key::Custom: 725 case Key::Custom:
724 params.append( new Param( "TYPE", key.customTypeString().utf8() ) ); 726 params.append( new Param( "TYPE", key.customTypeString().utf8() ) );
725 break; 727 break;
726 } 728 }
727 729
728 cl.setParamList( params ); 730 cl.setParamList( params );
729 vcard->add( cl ); 731 vcard->add( cl );
730} 732}
731 733
732Key VCardFormatImpl::readKeyValue( VCARD::ContentLine *cl ) 734Key VCardFormatImpl::readKeyValue( VCARD::ContentLine *cl )
733{ 735{
734 Key key; 736 Key key;
735 bool isBinary = false; 737 bool isBinary = false;
736 TextValue *v = (TextValue *)cl->value(); 738 TextValue *v = (TextValue *)cl->value();
737 739
738 ParamList params = cl->paramList(); 740 ParamList params = cl->paramList();
739 ParamListIterator it( params ); 741 ParamListIterator it( params );
740 for( ; it.current(); ++it ) { 742 for( ; it.current(); ++it ) {
741 if ( (*it)->name() == "ENCODING" && (*it)->value() == "b" ) 743 if ( (*it)->name() == "ENCODING" && (*it)->value() == "b" )
742 isBinary = true; 744 isBinary = true;
743 if ( (*it)->name() == "TYPE" ) { 745 if ( (*it)->name() == "TYPE" ) {
744 if ( (*it)->value().isEmpty() ) 746 if ( (*it)->value().isEmpty() )
745 continue; 747 continue;
746 if ( (*it)->value() == "X509" ) 748 if ( (*it)->value() == "X509" )
747 key.setType( Key::X509 ); 749 key.setType( Key::X509 );
748 else if ( (*it)->value() == "PGP" ) 750 else if ( (*it)->value() == "PGP" )
749 key.setType( Key::PGP ); 751 key.setType( Key::PGP );
750 else { 752 else {
751 key.setType( Key::Custom ); 753 key.setType( Key::Custom );
752 key.setCustomTypeString( QString::fromUtf8( (*it)->value() ) ); 754 key.setCustomTypeString( QString::fromUtf8( (*it)->value() ) );
753 } 755 }
754 } 756 }
755 } 757 }
756 758
757 759
758 if ( isBinary ) { 760 if ( isBinary ) {
759 QByteArray data; 761 QByteArray data;
760 KCodecs::base64Decode( v->asString().stripWhiteSpace(), data ); 762 KCodecs::base64Decode( v->asString().stripWhiteSpace(), data );
761 key.setBinaryData( data ); 763 key.setBinaryData( data );
762 } else { 764 } else {
763 key.setTextData( QString::fromUtf8( v->asString() ) ); 765 key.setTextData( QString::fromUtf8( v->asString() ) );
764 } 766 }
765 767
766 return key; 768 return key;
767} 769}
768 770
769 771
770void VCardFormatImpl::addAgentValue( VCARD::VCard *vcard, const Agent &agent ) 772void VCardFormatImpl::addAgentValue( VCARD::VCard *vcard, const Agent &agent )
771{ 773{
772 if ( agent.isIntern() && !agent.addressee() ) 774 if ( agent.isIntern() && !agent.addressee() )
773 return; 775 return;
774 776
775 if ( !agent.isIntern() && agent.url().isEmpty() ) 777 if ( !agent.isIntern() && agent.url().isEmpty() )
776 return; 778 return;
777 779
778 ContentLine cl; 780 ContentLine cl;
779 cl.setName( EntityTypeToParamName( EntityAgent ) ); 781 cl.setName( EntityTypeToParamName( EntityAgent ) );
780 782
781 ParamList params; 783 ParamList params;
782 if ( agent.isIntern() ) { 784 if ( agent.isIntern() ) {
783 QString vstr; 785 QString vstr;
784 Addressee *addr = agent.addressee(); 786 Addressee *addr = agent.addressee();
785 if ( addr ) { 787 if ( addr ) {
786 writeToString( (*addr), vstr ); 788 writeToString( (*addr), vstr );
787 789
788 qDebug("VCardFormatImpl::addAgentValue please verify if replace is correct"); 790 qDebug("VCardFormatImpl::addAgentValue please verify if replace is correct");
789/*US 791/*US
790 vstr.replace( ":", "\\:" ); 792 vstr.replace( ":", "\\:" );
791 vstr.replace( ",", "\\," ); 793 vstr.replace( ",", "\\," );
792 vstr.replace( ";", "\\;" ); 794 vstr.replace( ";", "\\;" );
793 vstr.replace( "\r\n", "\\n" ); 795 vstr.replace( "\r\n", "\\n" );
794*/ 796*/
795 vstr.replace( QRegExp(":"), "\\:" ); 797 vstr.replace( QRegExp(":"), "\\:" );
796 vstr.replace( QRegExp(","), "\\," ); 798 vstr.replace( QRegExp(","), "\\," );
797 vstr.replace( QRegExp(";"), "\\;" ); 799 vstr.replace( QRegExp(";"), "\\;" );
798 vstr.replace( QRegExp("\r\n"), "\\n" ); 800 vstr.replace( QRegExp("\r\n"), "\\n" );
799 801
800 cl.setValue( new TextValue( vstr.utf8() ) ); 802 cl.setValue( new TextValue( vstr.utf8() ) );
801 } else 803 } else
802 return; 804 return;
803 } else { 805 } else {
804 cl.setValue( new TextValue( agent.url().utf8() ) ); 806 cl.setValue( new TextValue( agent.url().utf8() ) );
805 params.append( new Param( "VALUE", "uri" ) ); 807 params.append( new Param( "VALUE", "uri" ) );
806 } 808 }
807 809
808 cl.setParamList( params ); 810 cl.setParamList( params );
809 vcard->add( cl ); 811 vcard->add( cl );
810} 812}
811 813
812Agent VCardFormatImpl::readAgentValue( VCARD::ContentLine *cl ) 814Agent VCardFormatImpl::readAgentValue( VCARD::ContentLine *cl )
813{ 815{
814 Agent agent; 816 Agent agent;
815 bool isIntern = true; 817 bool isIntern = true;
816 TextValue *v = (TextValue *)cl->value(); 818 TextValue *v = (TextValue *)cl->value();
817 819
818 ParamList params = cl->paramList(); 820 ParamList params = cl->paramList();
819 ParamListIterator it( params ); 821 ParamListIterator it( params );
820 for( ; it.current(); ++it ) { 822 for( ; it.current(); ++it ) {
821 if ( (*it)->name() == "VALUE" && (*it)->value() == "uri" ) 823 if ( (*it)->name() == "VALUE" && (*it)->value() == "uri" )
822 isIntern = false; 824 isIntern = false;
823 } 825 }
824 826
825 if ( isIntern ) { 827 if ( isIntern ) {
826 QString vstr = QString::fromUtf8( v->asString() ); 828 QString vstr = QString::fromUtf8( v->asString() );
827 qDebug("VCardFormatImpl::addAgentValue please verify if replace is correct"); 829 qDebug("VCardFormatImpl::addAgentValue please verify if replace is correct");
828/*US 830/*US
829 vstr.replace( "\\n", "\r\n" ); 831 vstr.replace( "\\n", "\r\n" );
830 vstr.replace( "\\:", ":" ); 832 vstr.replace( "\\:", ":" );
831 vstr.replace( "\\,", "," ); 833 vstr.replace( "\\,", "," );
832 vstr.replace( "\\;", ";" ); 834 vstr.replace( "\\;", ";" );
833*/ 835*/
834 vstr.replace( QRegExp("\\n"), "\r\n" ); 836 vstr.replace( QRegExp("\\n"), "\r\n" );
835 vstr.replace( QRegExp("\\:"), ":" ); 837 vstr.replace( QRegExp("\\:"), ":" );
836 vstr.replace( QRegExp("\\,"), "," ); 838 vstr.replace( QRegExp("\\,"), "," );
837 vstr.replace( QRegExp("\\;"), ";" ); 839 vstr.replace( QRegExp("\\;"), ";" );
838 840
839 Addressee *addr = new Addressee; 841 Addressee *addr = new Addressee;
840 readFromString( vstr, *addr ); 842 readFromString( vstr, *addr );
841 agent.setAddressee( addr ); 843 agent.setAddressee( addr );
842 } else { 844 } else {
843 agent.setUrl( QString::fromUtf8( v->asString() ) ); 845 agent.setUrl( QString::fromUtf8( v->asString() ) );
844 } 846 }
845 847
846 return agent; 848 return agent;
847} 849}
848 850
849void VCardFormatImpl::addPictureValue( VCARD::VCard *vcard, VCARD::EntityType type, const Picture &pic, const Addressee &addr, bool intern ) 851void VCardFormatImpl::addPictureValue( VCARD::VCard *vcard, VCARD::EntityType type, const Picture &pic, const Addressee &addr, bool intern )
850{ 852{
851 ContentLine cl; 853 ContentLine cl;
852 cl.setName( EntityTypeToParamName( type ) ); 854 cl.setName( EntityTypeToParamName( type ) );
853 855
854 if ( pic.isIntern() && pic.data().isNull() ) 856 if ( pic.isIntern() && pic.data().isNull() )
855 return; 857 return;
856 858
857 if ( !pic.isIntern() && pic.url().isEmpty() ) 859 if ( !pic.isIntern() && pic.url().isEmpty() )
858 return; 860 return;
859 861
860 ParamList params; 862 ParamList params;
861 if ( pic.isIntern() ) { 863 if ( pic.isIntern() ) {
862 QImage img = pic.data(); 864 QImage img = pic.data();
863 if ( intern ) { // only for vCard export we really write the data inline 865 if ( intern ) { // only for vCard export we really write the data inline
864 QByteArray data; 866 QByteArray data;
865 QDataStream s( data, IO_WriteOnly ); 867 QDataStream s( data, IO_WriteOnly );
866 s.setVersion( 4 ); // to produce valid png files 868 s.setVersion( 4 ); // to produce valid png files
867 s << img; 869 s << img;
868 cl.setValue( new TextValue( KCodecs::base64Encode( data ) ) ); 870 cl.setValue( new TextValue( KCodecs::base64Encode( data ) ) );
869 871
870 } else { // save picture in cache 872 } else { // save picture in cache
871 QString dir; 873 QString dir;
872 if ( type == EntityPhoto ) 874 if ( type == EntityPhoto )
873 dir = "photos"; 875 dir = "photos";
874 if ( type == EntityLogo ) 876 if ( type == EntityLogo )
875 dir = "logos"; 877 dir = "logos";
876 878
877 img.save( locateLocal( "data", "kabc/" + dir + "/" + addr.uid() ), pic.type().utf8() ); 879 img.save( locateLocal( "data", "kabc/" + dir + "/" + addr.uid() ), pic.type().utf8() );
878 cl.setValue( new TextValue( "<dummy>" ) ); 880 cl.setValue( new TextValue( "<dummy>" ) );
879 } 881 }
880 params.append( new Param( "ENCODING", "b" ) ); 882 params.append( new Param( "ENCODING", "b" ) );
881 if ( !pic.type().isEmpty() ) 883 if ( !pic.type().isEmpty() )
882 params.append( new Param( "TYPE", pic.type().utf8() ) ); 884 params.append( new Param( "TYPE", pic.type().utf8() ) );
883 } else { 885 } else {
884 886
885 cl.setValue( new TextValue( pic.url().utf8() ) ); 887 cl.setValue( new TextValue( pic.url().utf8() ) );
886 params.append( new Param( "VALUE", "uri" ) ); 888 params.append( new Param( "VALUE", "uri" ) );
887 } 889 }
888 890
889 cl.setParamList( params ); 891 cl.setParamList( params );
890 vcard->add( cl ); 892 vcard->add( cl );
891} 893}
892 894
893Picture VCardFormatImpl::readPictureValue( VCARD::ContentLine *cl, VCARD::EntityType type, const Addressee &addr ) 895Picture VCardFormatImpl::readPictureValue( VCARD::ContentLine *cl, VCARD::EntityType type, const Addressee &addr )
894{ 896{
895 Picture pic; 897 Picture pic;
896 bool isInline = false; 898 bool isInline = false;
897 QString picType; 899 QString picType;
898 TextValue *v = (TextValue *)cl->value(); 900 TextValue *v = (TextValue *)cl->value();
899 901
900 ParamList params = cl->paramList(); 902 ParamList params = cl->paramList();
901 ParamListIterator it( params ); 903 ParamListIterator it( params );
902 for( ; it.current(); ++it ) { 904 for( ; it.current(); ++it ) {
903 if ( (*it)->name() == "ENCODING" && (*it)->value() == "b" ) 905 if ( (*it)->name() == "ENCODING" && (*it)->value() == "b" )
904 isInline = true; 906 isInline = true;
905 if ( (*it)->name() == "TYPE" && !(*it)->value().isEmpty() ) 907 if ( (*it)->name() == "TYPE" && !(*it)->value().isEmpty() )
906 picType = QString::fromUtf8( (*it)->value() ); 908 picType = QString::fromUtf8( (*it)->value() );
907 } 909 }
908 910
909 if ( isInline ) { 911 if ( isInline ) {
910 QImage img; 912 QImage img;
911 if ( v->asString() == "<dummy>" ) { // no picture inline stored => picture is in cache 913 if ( v->asString() == "<dummy>" ) { // no picture inline stored => picture is in cache
912 QString dir; 914 QString dir;
913 if ( type == EntityPhoto ) 915 if ( type == EntityPhoto )
914 dir = "photos"; 916 dir = "photos";
915 if ( type == EntityLogo ) 917 if ( type == EntityLogo )
916 dir = "logos"; 918 dir = "logos";
917 919
918 img.load( locateLocal( "data", "kabc/" + dir + "/" + addr.uid() ) ); 920 img.load( locateLocal( "data", "kabc/" + dir + "/" + addr.uid() ) );
919 } else { 921 } else {
920 QByteArray data; 922 QByteArray data;
921 KCodecs::base64Decode( v->asString(), data ); 923 KCodecs::base64Decode( v->asString(), data );
922 img.loadFromData( data ); 924 img.loadFromData( data );
923 } 925 }
924 pic.setData( img ); 926 pic.setData( img );
925 pic.setType( picType ); 927 pic.setType( picType );
926 } else { 928 } else {
927 pic.setUrl( QString::fromUtf8( v->asString() ) ); 929 pic.setUrl( QString::fromUtf8( v->asString() ) );
928 } 930 }
929 931
930 return pic; 932 return pic;
931} 933}
932 934
933void VCardFormatImpl::addSoundValue( VCARD::VCard *vcard, const Sound &sound, const Addressee &addr, bool intern ) 935void VCardFormatImpl::addSoundValue( VCARD::VCard *vcard, const Sound &sound, const Addressee &addr, bool intern )
934{ 936{
935 ContentLine cl; 937 ContentLine cl;
936 cl.setName( EntityTypeToParamName( EntitySound ) ); 938 cl.setName( EntityTypeToParamName( EntitySound ) );
937 939
938 if ( sound.isIntern() && sound.data().isNull() ) 940 if ( sound.isIntern() && sound.data().isNull() )
939 return; 941 return;
940 942
941 if ( !sound.isIntern() && sound.url().isEmpty() ) 943 if ( !sound.isIntern() && sound.url().isEmpty() )
942 return; 944 return;
943 945
944 ParamList params; 946 ParamList params;
945 if ( sound.isIntern() ) { 947 if ( sound.isIntern() ) {
946 QByteArray data = sound.data(); 948 QByteArray data = sound.data();
947 if ( intern ) { // only for vCard export we really write the data inline 949 if ( intern ) { // only for vCard export we really write the data inline
948 cl.setValue( new TextValue( KCodecs::base64Encode( data ) ) ); 950 cl.setValue( new TextValue( KCodecs::base64Encode( data ) ) );
949 } else { // save sound in cache 951 } else { // save sound in cache
950 QFile file( locateLocal( "data", "kabc/sounds/" + addr.uid() ) ); 952 QFile file( locateLocal( "data", "kabc/sounds/" + addr.uid() ) );
951 if ( file.open( IO_WriteOnly ) ) { 953 if ( file.open( IO_WriteOnly ) ) {
952 file.writeBlock( data ); 954 file.writeBlock( data );
953 } 955 }
954 cl.setValue( new TextValue( "<dummy>" ) ); 956 cl.setValue( new TextValue( "<dummy>" ) );
955 } 957 }
956 params.append( new Param( "ENCODING", "b" ) ); 958 params.append( new Param( "ENCODING", "b" ) );
957 } else { 959 } else {
958 cl.setValue( new TextValue( sound.url().utf8() ) ); 960 cl.setValue( new TextValue( sound.url().utf8() ) );
959 params.append( new Param( "VALUE", "uri" ) ); 961 params.append( new Param( "VALUE", "uri" ) );
960 } 962 }
961 963
962 cl.setParamList( params ); 964 cl.setParamList( params );
963 vcard->add( cl ); 965 vcard->add( cl );
964} 966}
965 967
966Sound VCardFormatImpl::readSoundValue( VCARD::ContentLine *cl, const Addressee &addr ) 968Sound VCardFormatImpl::readSoundValue( VCARD::ContentLine *cl, const Addressee &addr )
967{ 969{
968 Sound sound; 970 Sound sound;
969 bool isInline = false; 971 bool isInline = false;
970 TextValue *v = (TextValue *)cl->value(); 972 TextValue *v = (TextValue *)cl->value();
971 973
972 ParamList params = cl->paramList(); 974 ParamList params = cl->paramList();
973 ParamListIterator it( params ); 975 ParamListIterator it( params );
974 for( ; it.current(); ++it ) { 976 for( ; it.current(); ++it ) {
975 if ( (*it)->name() == "ENCODING" && (*it)->value() == "b" ) 977 if ( (*it)->name() == "ENCODING" && (*it)->value() == "b" )
976 isInline = true; 978 isInline = true;
977 } 979 }
978 980
979 if ( isInline ) { 981 if ( isInline ) {
980 QByteArray data; 982 QByteArray data;
981 if ( v->asString() == "<dummy>" ) { // no sound inline stored => sound is in cache 983 if ( v->asString() == "<dummy>" ) { // no sound inline stored => sound is in cache
982 QFile file( locateLocal( "data", "kabc/sounds/" + addr.uid() ) ); 984 QFile file( locateLocal( "data", "kabc/sounds/" + addr.uid() ) );
983 if ( file.open( IO_ReadOnly ) ) { 985 if ( file.open( IO_ReadOnly ) ) {
984 data = file.readAll(); 986 data = file.readAll();
985 file.close(); 987 file.close();
986 } 988 }
987 } else { 989 } else {
988 KCodecs::base64Decode( v->asString(), data ); 990 KCodecs::base64Decode( v->asString(), data );
989 } 991 }
990 sound.setData( data ); 992 sound.setData( data );
991 } else { 993 } else {
992 sound.setUrl( QString::fromUtf8( v->asString() ) ); 994 sound.setUrl( QString::fromUtf8( v->asString() ) );
993 } 995 }
994 996
995 return sound; 997 return sound;
996} 998}
997 999
998bool VCardFormatImpl::readFromString( const QString &vcard, Addressee &addressee ) 1000bool VCardFormatImpl::readFromString( const QString &vcard, Addressee &addressee )
999{ 1001{
1000 VCardEntity e( vcard.utf8() ); 1002 VCardEntity e( vcard.utf8() );
1001 VCardListIterator it( e.cardList() ); 1003 VCardListIterator it( e.cardList() );
1002 1004
1003 if ( it.current() ) { 1005 if ( it.current() ) {
1004 VCard v(*it.current()); 1006//US VCard v(*it.current());
1005 loadAddressee( addressee, v ); 1007//US loadAddressee( addressee, v );
1008 loadAddressee( addressee, it.current() );
1006 return true; 1009 return true;
1007 } 1010 }
1008 1011
1009 return false; 1012 return false;
1010} 1013}
1011 1014
1012bool VCardFormatImpl::writeToString( const Addressee &addressee, QString &vcard ) 1015bool VCardFormatImpl::writeToString( const Addressee &addressee, QString &vcard )
1013{ 1016{
1014 VCardEntity vcards; 1017 VCardEntity vcards;
1015 VCardList vcardlist; 1018 VCardList vcardlist;
1016 vcardlist.setAutoDelete( true ); 1019 vcardlist.setAutoDelete( true );
1017 1020
1018 VCard *v = new VCard; 1021 VCard *v = new VCard;
1019 1022
1020 saveAddressee( addressee, v, true ); 1023 saveAddressee( addressee, v, true );
1021 1024
1022 vcardlist.append( v ); 1025 vcardlist.append( v );
1023 vcards.setCardList( vcardlist ); 1026 vcards.setCardList( vcardlist );
1024 vcard = QString::fromUtf8( vcards.asString() ); 1027 vcard = QString::fromUtf8( vcards.asString() );
1025 1028
1026 return true; 1029 return true;
1027} 1030}
diff --git a/kabc/vcardformatimpl.h b/kabc/vcardformatimpl.h
index 2dd68d9..fa3d55f 100644
--- a/kabc/vcardformatimpl.h
+++ b/kabc/vcardformatimpl.h
@@ -1,112 +1,112 @@
1/* 1/*
2 This file is part of libkabc. 2 This file is part of libkabc.
3 Copyright (c) 2001 Cornelius Schumacher <schumacher@kde.org> 3 Copyright (c) 2001 Cornelius Schumacher <schumacher@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/* 21/*
22Enhanced Version of the file for platform independent KDE tools. 22Enhanced Version of the file for platform independent KDE tools.
23Copyright (c) 2004 Ulf Schenk 23Copyright (c) 2004 Ulf Schenk
24 24
25$Id$ 25$Id$
26*/ 26*/
27 27
28#ifndef KABC_VCARDFORMATIMPL_H 28#ifndef KABC_VCARDFORMATIMPL_H
29#define KABC_VCARDFORMATIMPL_H 29#define KABC_VCARDFORMATIMPL_H
30 30
31#include <qstring.h> 31#include <qstring.h>
32#include <qfile.h> 32#include <qfile.h>
33 33
34#include "address.h" 34#include "address.h"
35#include "addressee.h" 35#include "addressee.h"
36 36
37#include <VCard.h> 37#include <VCard.h>
38 38
39namespace KABC { 39namespace KABC {
40 40
41class AddressBook; 41class AddressBook;
42 42
43/** 43/**
44 @short Implementation of vCard backend for address book. 44 @short Implementation of vCard backend for address book.
45 45
46 This class implements reading and writing of address book information using 46 This class implements reading and writing of address book information using
47 the vCard format. It requires the vCard lib from kdepim. 47 the vCard format. It requires the vCard lib from kdepim.
48*/ 48*/
49class VCardFormatImpl 49class VCardFormatImpl
50{ 50{
51 public: 51 public:
52 bool load( Addressee &, QFile *file ); 52 bool load( Addressee &, QFile *file );
53 bool loadAll( AddressBook *, Resource *, QFile *file ); 53 bool loadAll( AddressBook *, Resource *, QFile *file );
54 void save( const Addressee &, QFile *file ); 54 void save( const Addressee &, QFile *file );
55 void saveAll( AddressBook *, Resource *, QFile *file ); 55 void saveAll( AddressBook *, Resource *, QFile *file );
56 56
57 bool readFromString( const QString &vcard, Addressee &addr ); 57 bool readFromString( const QString &vcard, Addressee &addr );
58 bool writeToString( const Addressee &addressee, QString &vcard ); 58 bool writeToString( const Addressee &addressee, QString &vcard );
59 59
60 protected: 60 protected:
61 bool loadAddressee( Addressee &, VCARD::VCard & ); 61 bool loadAddressee( Addressee &, VCARD::VCard * );
62 void saveAddressee( const Addressee &, VCARD::VCard *, bool intern ); 62 void saveAddressee( const Addressee &, VCARD::VCard *, bool intern );
63 63
64 void addTextValue (VCARD::VCard *, VCARD::EntityType, const QString & ); 64 void addTextValue (VCARD::VCard *, VCARD::EntityType, const QString & );
65 QString readTextValue( VCARD::ContentLine * ); 65 QString readTextValue( VCARD::ContentLine * );
66 66
67 void addDateValue( VCARD::VCard *, VCARD::EntityType, const QDate & ); 67 void addDateValue( VCARD::VCard *, VCARD::EntityType, const QDate & );
68 QDate readDateValue( VCARD::ContentLine * ); 68 QDate readDateValue( VCARD::ContentLine * );
69 69
70 void addDateTimeValue( VCARD::VCard *, VCARD::EntityType, const QDateTime & ); 70 void addDateTimeValue( VCARD::VCard *, VCARD::EntityType, const QDateTime & );
71 QDateTime readDateTimeValue( VCARD::ContentLine * ); 71 QDateTime readDateTimeValue( VCARD::ContentLine * );
72 72
73 void addAddressValue( VCARD::VCard *, const Address & ); 73 void addAddressValue( VCARD::VCard *, const Address & );
74 Address readAddressValue( VCARD::ContentLine * ); 74 Address readAddressValue( VCARD::ContentLine * );
75 75
76 void addLabelValue( VCARD::VCard *, const Address & ); 76 void addLabelValue( VCARD::VCard *, const Address & );
77 77
78 void addTelephoneValue( VCARD::VCard *, const PhoneNumber & ); 78 void addTelephoneValue( VCARD::VCard *, const PhoneNumber & );
79 PhoneNumber readTelephoneValue( VCARD::ContentLine * ); 79 PhoneNumber readTelephoneValue( VCARD::ContentLine * );
80 80
81 void addNValue( VCARD::VCard *, const Addressee & ); 81 void addNValue( VCARD::VCard *, const Addressee & );
82 void readNValue( VCARD::ContentLine *, Addressee & ); 82 void readNValue( VCARD::ContentLine *, Addressee & );
83 83
84 void addCustomValue( VCARD::VCard *, const QString & ); 84 void addCustomValue( VCARD::VCard *, const QString & );
85 85
86 void addAddressParam( VCARD::ContentLine *, int ); 86 void addAddressParam( VCARD::ContentLine *, int );
87 int readAddressParam( VCARD::ContentLine * ); 87 int readAddressParam( VCARD::ContentLine * );
88 88
89 void addGeoValue( VCARD::VCard *, const Geo & ); 89 void addGeoValue( VCARD::VCard *, const Geo & );
90 Geo readGeoValue( VCARD::ContentLine * ); 90 Geo readGeoValue( VCARD::ContentLine * );
91 91
92 void addUTCValue( VCARD::VCard *, const TimeZone & ); 92 void addUTCValue( VCARD::VCard *, const TimeZone & );
93 TimeZone readUTCValue( VCARD::ContentLine * ); 93 TimeZone readUTCValue( VCARD::ContentLine * );
94 94
95 void addClassValue( VCARD::VCard *, const Secrecy & ); 95 void addClassValue( VCARD::VCard *, const Secrecy & );
96 Secrecy readClassValue( VCARD::ContentLine * ); 96 Secrecy readClassValue( VCARD::ContentLine * );
97 97
98 void addKeyValue( VCARD::VCard *, const Key & ); 98 void addKeyValue( VCARD::VCard *, const Key & );
99 Key readKeyValue( VCARD::ContentLine * ); 99 Key readKeyValue( VCARD::ContentLine * );
100 100
101 void addPictureValue( VCARD::VCard *, VCARD::EntityType, const Picture &, const Addressee &, bool ); 101 void addPictureValue( VCARD::VCard *, VCARD::EntityType, const Picture &, const Addressee &, bool );
102 Picture readPictureValue( VCARD::ContentLine *, VCARD::EntityType, const Addressee &addr ); 102 Picture readPictureValue( VCARD::ContentLine *, VCARD::EntityType, const Addressee &addr );
103 103
104 void addSoundValue( VCARD::VCard *, const Sound &, const Addressee &, bool ); 104 void addSoundValue( VCARD::VCard *, const Sound &, const Addressee &, bool );
105 Sound readSoundValue( VCARD::ContentLine *, const Addressee &addr ); 105 Sound readSoundValue( VCARD::ContentLine *, const Addressee &addr );
106 106
107 void addAgentValue( VCARD::VCard *, const Agent & ); 107 void addAgentValue( VCARD::VCard *, const Agent & );
108 Agent readAgentValue( VCARD::ContentLine * ); 108 Agent readAgentValue( VCARD::ContentLine * );
109}; 109};
110 110
111} 111}
112#endif 112#endif