• Skip to content
  • Skip to link menu
Trinity API Reference
  • Trinity API Reference
  • tdeabc
 

tdeabc

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

tdeabc

Skip menu "tdeabc"
  • Main Page
  • Namespace List
  • Class Hierarchy
  • Alphabetical List
  • Class List
  • File List
  • Namespace Members
  • Class Members
  • Related Pages

tdeabc

Skip menu "tdeabc"
  • arts
  • dcop
  • dnssd
  • interfaces
  •   kspeech
  •     interface
  •     library
  •   tdetexteditor
  • kate
  • kded
  • kdoctools
  • kimgio
  • kjs
  • libtdemid
  • libtdescreensaver
  • tdeabc
  • tdecmshell
  • tdecore
  • tdefx
  • tdehtml
  • tdeinit
  • tdeio
  •   bookmarks
  •   httpfilter
  •   kpasswdserver
  •   kssl
  •   tdefile
  •   tdeio
  •   tdeioexec
  • tdeioslave
  •   http
  • tdemdi
  •   tdemdi
  • tdenewstuff
  • tdeparts
  • tdeprint
  • tderandr
  • tderesources
  • tdespell2
  • tdesu
  • tdeui
  • tdeunittest
  • tdeutils
  • tdewallet
Generated for tdeabc by doxygen 1.9.4
This website is maintained by Timothy Pearson.