summaryrefslogtreecommitdiffabout
Unidiff
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--kabc/vcardformatimpl.cpp11
-rw-r--r--kabc/vcardformatimpl.h5
2 files changed, 16 insertions, 0 deletions
diff --git a/kabc/vcardformatimpl.cpp b/kabc/vcardformatimpl.cpp
index 1bf2cde..ede5773 100644
--- a/kabc/vcardformatimpl.cpp
+++ b/kabc/vcardformatimpl.cpp
@@ -1,466 +1,477 @@
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
44int VCardFormatImpl::debug = -1;
45
46VCardFormatImpl::VCardFormatImpl()
47{
48 debug = (getenv("KABC_DEBUG") != 0);
49}
50
44bool VCardFormatImpl::load( Addressee &addressee, QFile *file ) 51bool VCardFormatImpl::load( Addressee &addressee, QFile *file )
45{ 52{
46 kdDebug(5700) << "VCardFormat::load()" << endl; 53 kdDebug(5700) << "VCardFormat::load()" << endl;
47 54
48 QByteArray fdata = file->readAll(); 55 QByteArray fdata = file->readAll();
49 QCString data(fdata.data(), fdata.size()+1); 56 QCString data(fdata.data(), fdata.size()+1);
50 57
51 VCardEntity e( data ); 58 VCardEntity e( data );
52 59
53 VCardListIterator it( e.cardList() ); 60 VCardListIterator it( e.cardList() );
54 61
55 if ( it.current() ) { 62 if ( it.current() ) {
56//US VCard v(*it.current()); 63//US VCard v(*it.current());
57//US loadAddressee( addressee, v ); 64//US loadAddressee( addressee, v );
58 loadAddressee( addressee, it.current() ); 65 loadAddressee( addressee, it.current() );
59 return true; 66 return true;
60 } 67 }
61 68
62 return false; 69 return false;
63} 70}
64 71
65bool VCardFormatImpl::loadAll( AddressBook *addressBook, Resource *resource, QFile *file ) 72bool VCardFormatImpl::loadAll( AddressBook *addressBook, Resource *resource, QFile *file )
66{ 73{
67 kdDebug(5700) << "VCardFormat::loadAll()" << endl; 74 kdDebug(5700) << "VCardFormat::loadAll()" << endl;
68 75
69 QByteArray fdata = file->readAll(); 76 QByteArray fdata = file->readAll();
70 QCString data(fdata.data(), fdata.size()+1); 77 QCString data(fdata.data(), fdata.size()+1);
71 78
72 VCardEntity e( data ); 79 VCardEntity e( data );
73 80
74 VCardListIterator it( e.cardList() ); 81 VCardListIterator it( e.cardList() );
75 82
76 for (; it.current(); ++it) { 83 for (; it.current(); ++it) {
77//US VCard v(*it.current()); 84//US VCard v(*it.current());
78 Addressee addressee; 85 Addressee addressee;
79//US loadAddressee( addressee, v ); 86//US loadAddressee( addressee, v );
80 loadAddressee( addressee, it.current() ); 87 loadAddressee( addressee, it.current() );
81 addressee.setResource( resource ); 88 addressee.setResource( resource );
82 addressBook->insertAddressee( addressee ); 89 addressBook->insertAddressee( addressee );
90 if (debug == true)
91 {
92 printf("address %s loaded successfully\n", addressee.formattedName().latin1());
93 }
83 } 94 }
84 95
85 return true; 96 return true;
86} 97}
87 98
88void VCardFormatImpl::save( const Addressee &addressee, QFile *file ) 99void VCardFormatImpl::save( const Addressee &addressee, QFile *file )
89{ 100{
90 VCardEntity vcards; 101 VCardEntity vcards;
91 VCardList vcardlist; 102 VCardList vcardlist;
92 vcardlist.setAutoDelete( true ); 103 vcardlist.setAutoDelete( true );
93 104
94 VCard *v = new VCard; 105 VCard *v = new VCard;
95 106
96 saveAddressee( addressee, v, false ); 107 saveAddressee( addressee, v, false );
97 108
98 vcardlist.append( v ); 109 vcardlist.append( v );
99 vcards.setCardList( vcardlist ); 110 vcards.setCardList( vcardlist );
100 111
101 QCString vcardData = vcards.asString(); 112 QCString vcardData = vcards.asString();
102 file->writeBlock( (const char*)vcardData, vcardData.length() ); 113 file->writeBlock( (const char*)vcardData, vcardData.length() );
103} 114}
104 115
105void VCardFormatImpl::saveAll( AddressBook *ab, Resource *resource, QFile *file ) 116void VCardFormatImpl::saveAll( AddressBook *ab, Resource *resource, QFile *file )
106{ 117{
107 VCardEntity vcards; 118 VCardEntity vcards;
108 VCardList vcardlist; 119 VCardList vcardlist;
109 vcardlist.setAutoDelete( true ); 120 vcardlist.setAutoDelete( true );
110 121
111 AddressBook::Iterator it; 122 AddressBook::Iterator it;
112 for ( it = ab->begin(); it != ab->end(); ++it ) { 123 for ( it = ab->begin(); it != ab->end(); ++it ) {
113 if ( (*it).resource() == resource ) { 124 if ( (*it).resource() == resource ) {
114 VCard *v = new VCard; 125 VCard *v = new VCard;
115 saveAddressee( (*it), v, false ); 126 saveAddressee( (*it), v, false );
116 (*it).setChanged( false ); 127 (*it).setChanged( false );
117 vcardlist.append( v ); 128 vcardlist.append( v );
118 } 129 }
119 } 130 }
120 131
121 vcards.setCardList( vcardlist ); 132 vcards.setCardList( vcardlist );
122 133
123 QCString vcardData = vcards.asString(); 134 QCString vcardData = vcards.asString();
124 file->writeBlock( (const char*)vcardData, vcardData.length() ); 135 file->writeBlock( (const char*)vcardData, vcardData.length() );
125} 136}
126 137
127bool VCardFormatImpl::loadAddressee( Addressee& addressee, VCard *v ) 138bool VCardFormatImpl::loadAddressee( Addressee& addressee, VCard *v )
128{ 139{
129 QPtrList<ContentLine> contentLines = v->contentLineList(); 140 QPtrList<ContentLine> contentLines = v->contentLineList();
130 ContentLine *cl; 141 ContentLine *cl;
131 142
132 for( cl = contentLines.first(); cl; cl = contentLines.next() ) { 143 for( cl = contentLines.first(); cl; cl = contentLines.next() ) {
133 QCString n = cl->name(); 144 QCString n = cl->name();
134 if ( n.left( 2 ) == "X-" ) { 145 if ( n.left( 2 ) == "X-" ) {
135 n = n.mid( 2 ); 146 n = n.mid( 2 );
136 int posDash = n.find( "-" ); 147 int posDash = n.find( "-" );
137 addressee.insertCustom( QString::fromUtf8( n.left( posDash ) ), 148 addressee.insertCustom( QString::fromUtf8( n.left( posDash ) ),
138 QString::fromUtf8( n.mid( posDash + 1 ) ), 149 QString::fromUtf8( n.mid( posDash + 1 ) ),
139 QString::fromUtf8( cl->value()->asString() ) ); 150 QString::fromUtf8( cl->value()->asString() ) );
140 continue; 151 continue;
141 } 152 }
142 153
143 EntityType type = cl->entityType(); 154 EntityType type = cl->entityType();
144 switch( type ) { 155 switch( type ) {
145 156
146 case EntityUID: 157 case EntityUID:
147 addressee.setUid( readTextValue( cl ) ); 158 addressee.setUid( readTextValue( cl ) );
148 break; 159 break;
149 160
150 case EntityEmail: 161 case EntityEmail:
151 addressee.insertEmail( readTextValue( cl ) ); 162 addressee.insertEmail( readTextValue( cl ) );
152 break; 163 break;
153 164
154 case EntityName: 165 case EntityName:
155 addressee.setName( readTextValue( cl ) ); 166 addressee.setName( readTextValue( cl ) );
156 break; 167 break;
157 168
158 case EntityFullName: 169 case EntityFullName:
159 addressee.setFormattedName( readTextValue( cl ) ); 170 addressee.setFormattedName( readTextValue( cl ) );
160 break; 171 break;
161 172
162 case EntityURL: 173 case EntityURL:
163 addressee.setUrl( KURL( readTextValue( cl ) ) ); 174 addressee.setUrl( KURL( readTextValue( cl ) ) );
164 break; 175 break;
165 176
166 case EntityNickname: 177 case EntityNickname:
167 addressee.setNickName( readTextValue( cl ) ); 178 addressee.setNickName( readTextValue( cl ) );
168 break; 179 break;
169 180
170 case EntityLabel: 181 case EntityLabel:
171 // not yet supported by kabc 182 // not yet supported by kabc
172 break; 183 break;
173 184
174 case EntityMailer: 185 case EntityMailer:
175 addressee.setMailer( readTextValue( cl ) ); 186 addressee.setMailer( readTextValue( cl ) );
176 break; 187 break;
177 188
178 case EntityTitle: 189 case EntityTitle:
179 addressee.setTitle( readTextValue( cl ) ); 190 addressee.setTitle( readTextValue( cl ) );
180 break; 191 break;
181 192
182 case EntityRole: 193 case EntityRole:
183 addressee.setRole( readTextValue( cl ) ); 194 addressee.setRole( readTextValue( cl ) );
184 break; 195 break;
185 196
186 case EntityOrganisation: 197 case EntityOrganisation:
187 addressee.setOrganization( readTextValue( cl ) ); 198 addressee.setOrganization( readTextValue( cl ) );
188 break; 199 break;
189 200
190 case EntityNote: 201 case EntityNote:
191 addressee.setNote( readTextValue( cl ) ); 202 addressee.setNote( readTextValue( cl ) );
192 break; 203 break;
193 204
194 case EntityProductID: 205 case EntityProductID:
195 addressee.setProductId( readTextValue( cl ) ); 206 addressee.setProductId( readTextValue( cl ) );
196 break; 207 break;
197 208
198 case EntitySortString: 209 case EntitySortString:
199 addressee.setSortString( readTextValue( cl ) ); 210 addressee.setSortString( readTextValue( cl ) );
200 break; 211 break;
201 212
202 case EntityN: 213 case EntityN:
203 readNValue( cl, addressee ); 214 readNValue( cl, addressee );
204 break; 215 break;
205 216
206 case EntityAddress: 217 case EntityAddress:
207 addressee.insertAddress( readAddressValue( cl ) ); 218 addressee.insertAddress( readAddressValue( cl ) );
208 break; 219 break;
209 220
210 case EntityTelephone: 221 case EntityTelephone:
211 addressee.insertPhoneNumber( readTelephoneValue( cl ) ); 222 addressee.insertPhoneNumber( readTelephoneValue( cl ) );
212 break; 223 break;
213 224
214 case EntityCategories: 225 case EntityCategories:
215 addressee.setCategories( QStringList::split( ",", readTextValue( cl ) ) ); 226 addressee.setCategories( QStringList::split( ",", readTextValue( cl ) ) );
216 break; 227 break;
217 228
218 case EntityBirthday: 229 case EntityBirthday:
219 addressee.setBirthday( readDateValue( cl ) ); 230 addressee.setBirthday( readDateValue( cl ) );
220 break; 231 break;
221 232
222 case EntityRevision: 233 case EntityRevision:
223 addressee.setRevision( readDateTimeValue( cl ) ); 234 addressee.setRevision( readDateTimeValue( cl ) );
224 break; 235 break;
225 236
226 case EntityGeo: 237 case EntityGeo:
227 addressee.setGeo( readGeoValue( cl ) ); 238 addressee.setGeo( readGeoValue( cl ) );
228 break; 239 break;
229 240
230 case EntityTimeZone: 241 case EntityTimeZone:
231 addressee.setTimeZone( readUTCValue( cl ) ); 242 addressee.setTimeZone( readUTCValue( cl ) );
232 break; 243 break;
233 244
234 case EntityVersion: 245 case EntityVersion:
235 break; 246 break;
236 247
237 case EntityClass: 248 case EntityClass:
238 addressee.setSecrecy( readClassValue( cl ) ); 249 addressee.setSecrecy( readClassValue( cl ) );
239 break; 250 break;
240 251
241 case EntityKey: 252 case EntityKey:
242 addressee.insertKey( readKeyValue( cl ) ); 253 addressee.insertKey( readKeyValue( cl ) );
243 break; 254 break;
244 255
245 case EntityPhoto: 256 case EntityPhoto:
246 addressee.setPhoto( readPictureValue( cl, EntityPhoto, addressee ) ); 257 addressee.setPhoto( readPictureValue( cl, EntityPhoto, addressee ) );
247 break; 258 break;
248 259
249 case EntityLogo: 260 case EntityLogo:
250 addressee.setLogo( readPictureValue( cl, EntityLogo, addressee ) ); 261 addressee.setLogo( readPictureValue( cl, EntityLogo, addressee ) );
251 break; 262 break;
252 263
253 case EntityAgent: 264 case EntityAgent:
254 addressee.setAgent( readAgentValue( cl ) ); 265 addressee.setAgent( readAgentValue( cl ) );
255 break; 266 break;
256 267
257 case EntitySound: 268 case EntitySound:
258 addressee.setSound( readSoundValue( cl, addressee ) ); 269 addressee.setSound( readSoundValue( cl, addressee ) );
259 break; 270 break;
260 271
261 default: 272 default:
262 kdDebug(5700) << "VCardFormat::load(): Unsupported entity: " 273 kdDebug(5700) << "VCardFormat::load(): Unsupported entity: "
263 << int( type ) << ": " << cl->asString() << endl; 274 << int( type ) << ": " << cl->asString() << endl;
264 qDebug("VCardFormat::load(): Unsupported entity: %i: %s ", int(type), (const char*)cl->asString()); 275 qDebug("VCardFormat::load(): Unsupported entity: %i: %s ", int(type), (const char*)cl->asString());
265 break; 276 break;
266 } 277 }
267 } 278 }
268 279
269 for( cl = contentLines.first(); cl; cl = contentLines.next() ) { 280 for( cl = contentLines.first(); cl; cl = contentLines.next() ) {
270 EntityType type = cl->entityType(); 281 EntityType type = cl->entityType();
271 if ( type == EntityLabel ) { 282 if ( type == EntityLabel ) {
272 int type = readAddressParam( cl ); 283 int type = readAddressParam( cl );
273 Address address = addressee.address( type ); 284 Address address = addressee.address( type );
274 if ( address.isEmpty() ) 285 if ( address.isEmpty() )
275 address.setType( type ); 286 address.setType( type );
276 287
277 address.setLabel( QString::fromUtf8( cl->value()->asString() ) ); 288 address.setLabel( QString::fromUtf8( cl->value()->asString() ) );
278 addressee.insertAddress( address ); 289 addressee.insertAddress( address );
279 } 290 }
280 } 291 }
281 292
282 return true; 293 return true;
283} 294}
284 295
285void VCardFormatImpl::saveAddressee( const Addressee &addressee, VCard *v, bool intern ) 296void VCardFormatImpl::saveAddressee( const Addressee &addressee, VCard *v, bool intern )
286{ 297{
287//US ContentLine cl; 298//US ContentLine cl;
288//US QString value; 299//US QString value;
289 300
290 addTextValue( v, EntityName, addressee.name() ); 301 addTextValue( v, EntityName, addressee.name() );
291 addTextValue( v, EntityUID, addressee.uid() ); 302 addTextValue( v, EntityUID, addressee.uid() );
292 addTextValue( v, EntityFullName, addressee.formattedName() ); 303 addTextValue( v, EntityFullName, addressee.formattedName() );
293 304
294 QStringList emails = addressee.emails(); 305 QStringList emails = addressee.emails();
295 QStringList::ConstIterator it4; 306 QStringList::ConstIterator it4;
296 for( it4 = emails.begin(); it4 != emails.end(); ++it4 ) { 307 for( it4 = emails.begin(); it4 != emails.end(); ++it4 ) {
297 addTextValue( v, EntityEmail, *it4 ); 308 addTextValue( v, EntityEmail, *it4 );
298 } 309 }
299 310
300 QStringList customs = addressee.customs(); 311 QStringList customs = addressee.customs();
301 QStringList::ConstIterator it5; 312 QStringList::ConstIterator it5;
302 for( it5 = customs.begin(); it5 != customs.end(); ++it5 ) { 313 for( it5 = customs.begin(); it5 != customs.end(); ++it5 ) {
303 addCustomValue( v, *it5 ); 314 addCustomValue( v, *it5 );
304 } 315 }
305 316
306 addTextValue( v, EntityURL, addressee.url().url() ); 317 addTextValue( v, EntityURL, addressee.url().url() );
307 318
308 addNValue( v, addressee ); 319 addNValue( v, addressee );
309 320
310 addTextValue( v, EntityNickname, addressee.nickName() ); 321 addTextValue( v, EntityNickname, addressee.nickName() );
311 addTextValue( v, EntityMailer, addressee.mailer() ); 322 addTextValue( v, EntityMailer, addressee.mailer() );
312 addTextValue( v, EntityTitle, addressee.title() ); 323 addTextValue( v, EntityTitle, addressee.title() );
313 addTextValue( v, EntityRole, addressee.role() ); 324 addTextValue( v, EntityRole, addressee.role() );
314 addTextValue( v, EntityOrganisation, addressee.organization() ); 325 addTextValue( v, EntityOrganisation, addressee.organization() );
315 addTextValue( v, EntityNote, addressee.note() ); 326 addTextValue( v, EntityNote, addressee.note() );
316 addTextValue( v, EntityProductID, addressee.productId() ); 327 addTextValue( v, EntityProductID, addressee.productId() );
317 addTextValue( v, EntitySortString, addressee.sortString() ); 328 addTextValue( v, EntitySortString, addressee.sortString() );
318 329
319 Address::List addresses = addressee.addresses(); 330 Address::List addresses = addressee.addresses();
320 Address::List::ConstIterator it3; 331 Address::List::ConstIterator it3;
321 for( it3 = addresses.begin(); it3 != addresses.end(); ++it3 ) { 332 for( it3 = addresses.begin(); it3 != addresses.end(); ++it3 ) {
322 addAddressValue( v, *it3 ); 333 addAddressValue( v, *it3 );
323 addLabelValue( v, *it3 ); 334 addLabelValue( v, *it3 );
324 } 335 }
325 336
326 PhoneNumber::List phoneNumbers = addressee.phoneNumbers(); 337 PhoneNumber::List phoneNumbers = addressee.phoneNumbers();
327 PhoneNumber::List::ConstIterator it2; 338 PhoneNumber::List::ConstIterator it2;
328 for( it2 = phoneNumbers.begin(); it2 != phoneNumbers.end(); ++it2 ) { 339 for( it2 = phoneNumbers.begin(); it2 != phoneNumbers.end(); ++it2 ) {
329 addTelephoneValue( v, *it2 ); 340 addTelephoneValue( v, *it2 );
330 } 341 }
331 342
332 Key::List keys = addressee.keys(); 343 Key::List keys = addressee.keys();
333 Key::List::ConstIterator it6; 344 Key::List::ConstIterator it6;
334 for( it6 = keys.begin(); it6 != keys.end(); ++it6 ) { 345 for( it6 = keys.begin(); it6 != keys.end(); ++it6 ) {
335 addKeyValue( v, *it6 ); 346 addKeyValue( v, *it6 );
336 } 347 }
337 348
338 addTextValue( v, EntityCategories, addressee.categories().join(",") ); 349 addTextValue( v, EntityCategories, addressee.categories().join(",") );
339 350
340 addDateValue( v, EntityBirthday, addressee.birthday().date() ); 351 addDateValue( v, EntityBirthday, addressee.birthday().date() );
341 addDateTimeValue( v, EntityRevision, addressee.revision() ); 352 addDateTimeValue( v, EntityRevision, addressee.revision() );
342 addGeoValue( v, addressee.geo() ); 353 addGeoValue( v, addressee.geo() );
343 addUTCValue( v, addressee.timeZone() ); 354 addUTCValue( v, addressee.timeZone() );
344 355
345 addClassValue( v, addressee.secrecy() ); 356 addClassValue( v, addressee.secrecy() );
346 357
347 addPictureValue( v, EntityPhoto, addressee.photo(), addressee, intern ); 358 addPictureValue( v, EntityPhoto, addressee.photo(), addressee, intern );
348 addPictureValue( v, EntityLogo, addressee.logo(), addressee, intern ); 359 addPictureValue( v, EntityLogo, addressee.logo(), addressee, intern );
349 360
350 addAgentValue( v, addressee.agent() ); 361 addAgentValue( v, addressee.agent() );
351 362
352 addSoundValue( v, addressee.sound(), addressee, intern ); 363 addSoundValue( v, addressee.sound(), addressee, intern );
353} 364}
354 365
355void VCardFormatImpl::addCustomValue( VCard *v, const QString &txt ) 366void VCardFormatImpl::addCustomValue( VCard *v, const QString &txt )
356{ 367{
357 if ( txt.isEmpty() ) return; 368 if ( txt.isEmpty() ) return;
358 369
359 ContentLine cl; 370 ContentLine cl;
360 cl.setName( "X-" + txt.left( txt.find( ":" ) ).utf8() ); 371 cl.setName( "X-" + txt.left( txt.find( ":" ) ).utf8() );
361 QString value = txt.mid( txt.find( ":" ) + 1 ); 372 QString value = txt.mid( txt.find( ":" ) + 1 );
362 if ( value.isEmpty() ) 373 if ( value.isEmpty() )
363 return; 374 return;
364 cl.setValue( new TextValue( value.utf8() ) ); 375 cl.setValue( new TextValue( value.utf8() ) );
365 v->add(cl); 376 v->add(cl);
366} 377}
367 378
368void VCardFormatImpl::addTextValue( VCard *v, EntityType type, const QString &txt ) 379void VCardFormatImpl::addTextValue( VCard *v, EntityType type, const QString &txt )
369{ 380{
370 if ( txt.isEmpty() ) return; 381 if ( txt.isEmpty() ) return;
371 382
372 ContentLine cl; 383 ContentLine cl;
373 cl.setName( EntityTypeToParamName( type ) ); 384 cl.setName( EntityTypeToParamName( type ) );
374 cl.setValue( new TextValue( txt.utf8() ) ); 385 cl.setValue( new TextValue( txt.utf8() ) );
375 v->add(cl); 386 v->add(cl);
376} 387}
377 388
378void VCardFormatImpl::addDateValue( VCard *vcard, EntityType type, 389void VCardFormatImpl::addDateValue( VCard *vcard, EntityType type,
379 const QDate &date ) 390 const QDate &date )
380{ 391{
381 if ( !date.isValid() ) return; 392 if ( !date.isValid() ) return;
382 393
383 ContentLine cl; 394 ContentLine cl;
384 cl.setName( EntityTypeToParamName( type ) ); 395 cl.setName( EntityTypeToParamName( type ) );
385 396
386 DateValue *v = new DateValue( date ); 397 DateValue *v = new DateValue( date );
387 cl.setValue( v ); 398 cl.setValue( v );
388 vcard->add(cl); 399 vcard->add(cl);
389} 400}
390 401
391void VCardFormatImpl::addDateTimeValue( VCard *vcard, EntityType type, 402void VCardFormatImpl::addDateTimeValue( VCard *vcard, EntityType type,
392 const QDateTime &dateTime ) 403 const QDateTime &dateTime )
393{ 404{
394 if ( !dateTime.isValid() ) return; 405 if ( !dateTime.isValid() ) return;
395 406
396 ContentLine cl; 407 ContentLine cl;
397 cl.setName( EntityTypeToParamName( type ) ); 408 cl.setName( EntityTypeToParamName( type ) );
398 409
399 DateValue *v = new DateValue( dateTime ); 410 DateValue *v = new DateValue( dateTime );
400 cl.setValue( v ); 411 cl.setValue( v );
401 vcard->add(cl); 412 vcard->add(cl);
402} 413}
403 414
404void VCardFormatImpl::addAddressValue( VCard *vcard, const Address &a ) 415void VCardFormatImpl::addAddressValue( VCard *vcard, const Address &a )
405{ 416{
406 if ( a.isEmpty() ) 417 if ( a.isEmpty() )
407 return; 418 return;
408 419
409 ContentLine cl; 420 ContentLine cl;
410 cl.setName( EntityTypeToParamName( EntityAddress ) ); 421 cl.setName( EntityTypeToParamName( EntityAddress ) );
411 422
412 AdrValue *v = new AdrValue; 423 AdrValue *v = new AdrValue;
413 v->setPOBox( a.postOfficeBox().utf8() ); 424 v->setPOBox( a.postOfficeBox().utf8() );
414 v->setExtAddress( a.extended().utf8() ); 425 v->setExtAddress( a.extended().utf8() );
415 v->setStreet( a.street().utf8() ); 426 v->setStreet( a.street().utf8() );
416 v->setLocality( a.locality().utf8() ); 427 v->setLocality( a.locality().utf8() );
417 v->setRegion( a.region().utf8() ); 428 v->setRegion( a.region().utf8() );
418 v->setPostCode( a.postalCode().utf8() ); 429 v->setPostCode( a.postalCode().utf8() );
419 v->setCountryName( a.country().utf8() ); 430 v->setCountryName( a.country().utf8() );
420 cl.setValue( v ); 431 cl.setValue( v );
421 432
422 addAddressParam( &cl, a.type() ); 433 addAddressParam( &cl, a.type() );
423 434
424 vcard->add( cl ); 435 vcard->add( cl );
425} 436}
426 437
427void VCardFormatImpl::addLabelValue( VCard *vcard, const Address &a ) 438void VCardFormatImpl::addLabelValue( VCard *vcard, const Address &a )
428{ 439{
429 if ( a.label().isEmpty() ) return; 440 if ( a.label().isEmpty() ) return;
430 441
431 ContentLine cl; 442 ContentLine cl;
432 cl.setName( EntityTypeToParamName( EntityLabel ) ); 443 cl.setName( EntityTypeToParamName( EntityLabel ) );
433 cl.setValue( new TextValue( a.label().utf8() ) ); 444 cl.setValue( new TextValue( a.label().utf8() ) );
434 445
435 addAddressParam( &cl, a.type() ); 446 addAddressParam( &cl, a.type() );
436 447
437 vcard->add( cl ); 448 vcard->add( cl );
438} 449}
439 450
440void VCardFormatImpl::addAddressParam( ContentLine *cl, int type ) 451void VCardFormatImpl::addAddressParam( ContentLine *cl, int type )
441{ 452{
442 ParamList params; 453 ParamList params;
443 if ( type & Address::Dom ) params.append( new Param( "TYPE", "dom" ) ); 454 if ( type & Address::Dom ) params.append( new Param( "TYPE", "dom" ) );
444 if ( type & Address::Intl ) params.append( new Param( "TYPE", "intl" ) ); 455 if ( type & Address::Intl ) params.append( new Param( "TYPE", "intl" ) );
445 if ( type & Address::Parcel ) params.append( new Param( "TYPE", "parcel" ) ); 456 if ( type & Address::Parcel ) params.append( new Param( "TYPE", "parcel" ) );
446 if ( type & Address::Postal ) params.append( new Param( "TYPE", "postal" ) ); 457 if ( type & Address::Postal ) params.append( new Param( "TYPE", "postal" ) );
447 if ( type & Address::Work ) params.append( new Param( "TYPE", "work" ) ); 458 if ( type & Address::Work ) params.append( new Param( "TYPE", "work" ) );
448 if ( type & Address::Home ) params.append( new Param( "TYPE", "home" ) ); 459 if ( type & Address::Home ) params.append( new Param( "TYPE", "home" ) );
449 if ( type & Address::Pref ) params.append( new Param( "TYPE", "pref" ) ); 460 if ( type & Address::Pref ) params.append( new Param( "TYPE", "pref" ) );
450 cl->setParamList( params ); 461 cl->setParamList( params );
451} 462}
452 463
453void VCardFormatImpl::addGeoValue( VCard *vcard, const Geo &geo ) 464void VCardFormatImpl::addGeoValue( VCard *vcard, const Geo &geo )
454{ 465{
455 if ( !geo.isValid() ) return; 466 if ( !geo.isValid() ) return;
456 467
457 ContentLine cl; 468 ContentLine cl;
458 cl.setName( EntityTypeToParamName( EntityGeo ) ); 469 cl.setName( EntityTypeToParamName( EntityGeo ) );
459 470
460 GeoValue *v = new GeoValue; 471 GeoValue *v = new GeoValue;
461 v->setLatitude( geo.latitude() ); 472 v->setLatitude( geo.latitude() );
462 v->setLongitude( geo.longitude() ); 473 v->setLongitude( geo.longitude() );
463 474
464 cl.setValue( v ); 475 cl.setValue( v );
465 vcard->add(cl); 476 vcard->add(cl);
466} 477}
diff --git a/kabc/vcardformatimpl.h b/kabc/vcardformatimpl.h
index fa3d55f..4821047 100644
--- a/kabc/vcardformatimpl.h
+++ b/kabc/vcardformatimpl.h
@@ -1,112 +1,117 @@
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 VCardFormatImpl();
53
52 bool load( Addressee &, QFile *file ); 54 bool load( Addressee &, QFile *file );
53 bool loadAll( AddressBook *, Resource *, QFile *file ); 55 bool loadAll( AddressBook *, Resource *, QFile *file );
54 void save( const Addressee &, QFile *file ); 56 void save( const Addressee &, QFile *file );
55 void saveAll( AddressBook *, Resource *, QFile *file ); 57 void saveAll( AddressBook *, Resource *, QFile *file );
56 58
57 bool readFromString( const QString &vcard, Addressee &addr ); 59 bool readFromString( const QString &vcard, Addressee &addr );
58 bool writeToString( const Addressee &addressee, QString &vcard ); 60 bool writeToString( const Addressee &addressee, QString &vcard );
59 61
60 protected: 62 protected:
61 bool loadAddressee( Addressee &, VCARD::VCard * ); 63 bool loadAddressee( Addressee &, VCARD::VCard * );
62 void saveAddressee( const Addressee &, VCARD::VCard *, bool intern ); 64 void saveAddressee( const Addressee &, VCARD::VCard *, bool intern );
63 65
64 void addTextValue (VCARD::VCard *, VCARD::EntityType, const QString & ); 66 void addTextValue (VCARD::VCard *, VCARD::EntityType, const QString & );
65 QString readTextValue( VCARD::ContentLine * ); 67 QString readTextValue( VCARD::ContentLine * );
66 68
67 void addDateValue( VCARD::VCard *, VCARD::EntityType, const QDate & ); 69 void addDateValue( VCARD::VCard *, VCARD::EntityType, const QDate & );
68 QDate readDateValue( VCARD::ContentLine * ); 70 QDate readDateValue( VCARD::ContentLine * );
69 71
70 void addDateTimeValue( VCARD::VCard *, VCARD::EntityType, const QDateTime & ); 72 void addDateTimeValue( VCARD::VCard *, VCARD::EntityType, const QDateTime & );
71 QDateTime readDateTimeValue( VCARD::ContentLine * ); 73 QDateTime readDateTimeValue( VCARD::ContentLine * );
72 74
73 void addAddressValue( VCARD::VCard *, const Address & ); 75 void addAddressValue( VCARD::VCard *, const Address & );
74 Address readAddressValue( VCARD::ContentLine * ); 76 Address readAddressValue( VCARD::ContentLine * );
75 77
76 void addLabelValue( VCARD::VCard *, const Address & ); 78 void addLabelValue( VCARD::VCard *, const Address & );
77 79
78 void addTelephoneValue( VCARD::VCard *, const PhoneNumber & ); 80 void addTelephoneValue( VCARD::VCard *, const PhoneNumber & );
79 PhoneNumber readTelephoneValue( VCARD::ContentLine * ); 81 PhoneNumber readTelephoneValue( VCARD::ContentLine * );
80 82
81 void addNValue( VCARD::VCard *, const Addressee & ); 83 void addNValue( VCARD::VCard *, const Addressee & );
82 void readNValue( VCARD::ContentLine *, Addressee & ); 84 void readNValue( VCARD::ContentLine *, Addressee & );
83 85
84 void addCustomValue( VCARD::VCard *, const QString & ); 86 void addCustomValue( VCARD::VCard *, const QString & );
85 87
86 void addAddressParam( VCARD::ContentLine *, int ); 88 void addAddressParam( VCARD::ContentLine *, int );
87 int readAddressParam( VCARD::ContentLine * ); 89 int readAddressParam( VCARD::ContentLine * );
88 90
89 void addGeoValue( VCARD::VCard *, const Geo & ); 91 void addGeoValue( VCARD::VCard *, const Geo & );
90 Geo readGeoValue( VCARD::ContentLine * ); 92 Geo readGeoValue( VCARD::ContentLine * );
91 93
92 void addUTCValue( VCARD::VCard *, const TimeZone & ); 94 void addUTCValue( VCARD::VCard *, const TimeZone & );
93 TimeZone readUTCValue( VCARD::ContentLine * ); 95 TimeZone readUTCValue( VCARD::ContentLine * );
94 96
95 void addClassValue( VCARD::VCard *, const Secrecy & ); 97 void addClassValue( VCARD::VCard *, const Secrecy & );
96 Secrecy readClassValue( VCARD::ContentLine * ); 98 Secrecy readClassValue( VCARD::ContentLine * );
97 99
98 void addKeyValue( VCARD::VCard *, const Key & ); 100 void addKeyValue( VCARD::VCard *, const Key & );
99 Key readKeyValue( VCARD::ContentLine * ); 101 Key readKeyValue( VCARD::ContentLine * );
100 102
101 void addPictureValue( VCARD::VCard *, VCARD::EntityType, const Picture &, const Addressee &, bool ); 103 void addPictureValue( VCARD::VCard *, VCARD::EntityType, const Picture &, const Addressee &, bool );
102 Picture readPictureValue( VCARD::ContentLine *, VCARD::EntityType, const Addressee &addr ); 104 Picture readPictureValue( VCARD::ContentLine *, VCARD::EntityType, const Addressee &addr );
103 105
104 void addSoundValue( VCARD::VCard *, const Sound &, const Addressee &, bool ); 106 void addSoundValue( VCARD::VCard *, const Sound &, const Addressee &, bool );
105 Sound readSoundValue( VCARD::ContentLine *, const Addressee &addr ); 107 Sound readSoundValue( VCARD::ContentLine *, const Addressee &addr );
106 108
107 void addAgentValue( VCARD::VCard *, const Agent & ); 109 void addAgentValue( VCARD::VCard *, const Agent & );
108 Agent readAgentValue( VCARD::ContentLine * ); 110 Agent readAgentValue( VCARD::ContentLine * );
111
112 private:
113 static int debug;
109}; 114};
110 115
111} 116}
112#endif 117#endif