Diffstat (limited to 'libopie/pim/ocontactaccessbackend_vcard.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r-- | libopie/pim/ocontactaccessbackend_vcard.cpp | 22 |
1 files changed, 20 insertions, 2 deletions
diff --git a/libopie/pim/ocontactaccessbackend_vcard.cpp b/libopie/pim/ocontactaccessbackend_vcard.cpp index 270bef3..b60c5be 100644 --- a/libopie/pim/ocontactaccessbackend_vcard.cpp +++ b/libopie/pim/ocontactaccessbackend_vcard.cpp | |||
@@ -1,43 +1,58 @@ | |||
1 | /* | 1 | /* |
2 | * VCard Backend for the OPIE-Contact Database. | 2 | * VCard Backend for the OPIE-Contact Database. |
3 | * | 3 | * |
4 | * Copyright (C) 2000 Trolltech AS. All rights reserved. | 4 | * Copyright (C) 2000 Trolltech AS. All rights reserved. |
5 | * Copyright (c) 2002 by Stefan Eilers (Eilers.Stefan@epost.de) | 5 | * Copyright (c) 2002 by Stefan Eilers (Eilers.Stefan@epost.de) |
6 | * | 6 | * |
7 | * ===================================================================== | 7 | * ===================================================================== |
8 | *This program is free software; you can redistribute it and/or | 8 | *This program is free software; you can redistribute it and/or |
9 | *modify it under the terms of the GNU Library General Public | 9 | *modify it under the terms of the GNU Library General Public |
10 | * License as published by the Free Software Foundation; either | 10 | * License as published by the Free Software Foundation; either |
11 | * version 2 of the License, or (at your option) any later version. | 11 | * version 2 of the License, or (at your option) any later version. |
12 | * ===================================================================== | 12 | * ===================================================================== |
13 | * ToDo: | 13 | * ToDo: |
14 | * | 14 | * |
15 | * ===================================================================== | 15 | * ===================================================================== |
16 | * Version: $Id$ | 16 | * Version: $Id$ |
17 | * ===================================================================== | 17 | * ===================================================================== |
18 | * History: | 18 | * History: |
19 | * $Log$ | 19 | * $Log$ |
20 | * Revision 1.11 2003/08/01 12:30:16 eilers | ||
21 | * Merging changes from BRANCH_1_0 to HEAD | ||
22 | * | ||
23 | * Revision 1.10.4.3 2003/07/23 08:54:37 eilers | ||
24 | * Default email was added to the list of all emails, which already contains | ||
25 | * the default email.. | ||
26 | * This closes bug #1045 | ||
27 | * | ||
28 | * Revision 1.10.4.2 2003/07/23 08:44:45 eilers | ||
29 | * Importing of Notes in vcard files wasn't implemented. | ||
30 | * Closes bug #1044 | ||
31 | * | ||
32 | * Revision 1.10.4.1 2003/06/02 13:37:49 eilers | ||
33 | * Fixing memory leak | ||
34 | * | ||
20 | * Revision 1.10 2003/04/13 18:07:10 zecke | 35 | * Revision 1.10 2003/04/13 18:07:10 zecke |
21 | * More API doc | 36 | * More API doc |
22 | * QString -> const QString& | 37 | * QString -> const QString& |
23 | * QString = 0l -> QString::null | 38 | * QString = 0l -> QString::null |
24 | * | 39 | * |
25 | * Revision 1.9 2003/03/21 10:33:09 eilers | 40 | * Revision 1.9 2003/03/21 10:33:09 eilers |
26 | * Merged speed optimized xml backend for contacts to main. | 41 | * Merged speed optimized xml backend for contacts to main. |
27 | * Added QDateTime to querybyexample. For instance, it is now possible to get | 42 | * Added QDateTime to querybyexample. For instance, it is now possible to get |
28 | * all Birthdays/Anniversaries between two dates. This should be used | 43 | * all Birthdays/Anniversaries between two dates. This should be used |
29 | * to show all birthdays in the datebook.. | 44 | * to show all birthdays in the datebook.. |
30 | * This change is sourcecode backward compatible but you have to upgrade | 45 | * This change is sourcecode backward compatible but you have to upgrade |
31 | * the binaries for today-addressbook. | 46 | * the binaries for today-addressbook. |
32 | * | 47 | * |
33 | * Revision 1.8 2003/02/21 16:52:49 zecke | 48 | * Revision 1.8 2003/02/21 16:52:49 zecke |
34 | * -Remove old Todo classes they're deprecated and today I already using the | 49 | * -Remove old Todo classes they're deprecated and today I already using the |
35 | * new API | 50 | * new API |
36 | * -Guard against self assignment in OTodo | 51 | * -Guard against self assignment in OTodo |
37 | * -Add test apps for OPIM | 52 | * -Add test apps for OPIM |
38 | * -Opiefied Event classes | 53 | * -Opiefied Event classes |
39 | * -Added TimeZone handling and pinning of TimeZones to OEvent | 54 | * -Added TimeZone handling and pinning of TimeZones to OEvent |
40 | * -Adjust ORecur and the widget to better timezone behaviour | 55 | * -Adjust ORecur and the widget to better timezone behaviour |
41 | * | 56 | * |
42 | * Revision 1.7 2003/02/16 22:25:46 zecke | 57 | * Revision 1.7 2003/02/16 22:25:46 zecke |
43 | * 0000276 Fix for that bug.. or better temp workaround | 58 | * 0000276 Fix for that bug.. or better temp workaround |
@@ -130,48 +145,49 @@ bool OContactAccessBackend_VCard::load () | |||
130 | bool OContactAccessBackend_VCard::reload() | 145 | bool OContactAccessBackend_VCard::reload() |
131 | { | 146 | { |
132 | return load(); | 147 | return load(); |
133 | } | 148 | } |
134 | bool OContactAccessBackend_VCard::save() | 149 | bool OContactAccessBackend_VCard::save() |
135 | { | 150 | { |
136 | if (!m_dirty ) | 151 | if (!m_dirty ) |
137 | return true; | 152 | return true; |
138 | 153 | ||
139 | QFileDirect file( m_file ); | 154 | QFileDirect file( m_file ); |
140 | if (!file.open(IO_WriteOnly ) ) | 155 | if (!file.open(IO_WriteOnly ) ) |
141 | return false; | 156 | return false; |
142 | 157 | ||
143 | VObject *obj; | 158 | VObject *obj; |
144 | obj = newVObject( VCCalProp ); | 159 | obj = newVObject( VCCalProp ); |
145 | addPropValue( obj, VCVersionProp, "1.0" ); | 160 | addPropValue( obj, VCVersionProp, "1.0" ); |
146 | 161 | ||
147 | VObject *vo; | 162 | VObject *vo; |
148 | for(QMap<int, OContact>::ConstIterator it=m_map.begin(); it !=m_map.end(); ++it ){ | 163 | for(QMap<int, OContact>::ConstIterator it=m_map.begin(); it !=m_map.end(); ++it ){ |
149 | vo = createVObject( *it ); | 164 | vo = createVObject( *it ); |
150 | writeVObject( file.directHandle() , vo ); | 165 | writeVObject( file.directHandle() , vo ); |
151 | cleanVObject( vo ); | 166 | cleanVObject( vo ); |
152 | } | 167 | } |
153 | cleanStrTbl(); | 168 | cleanStrTbl(); |
169 | deleteVObject( obj ); | ||
154 | 170 | ||
155 | m_dirty = false; | 171 | m_dirty = false; |
156 | return true; | 172 | return true; |
157 | 173 | ||
158 | 174 | ||
159 | } | 175 | } |
160 | void OContactAccessBackend_VCard::clear () | 176 | void OContactAccessBackend_VCard::clear () |
161 | { | 177 | { |
162 | m_map.clear(); | 178 | m_map.clear(); |
163 | m_dirty = true; // ??? sure ? (se) | 179 | m_dirty = true; // ??? sure ? (se) |
164 | } | 180 | } |
165 | 181 | ||
166 | bool OContactAccessBackend_VCard::add ( const OContact& newcontact ) | 182 | bool OContactAccessBackend_VCard::add ( const OContact& newcontact ) |
167 | { | 183 | { |
168 | m_map.insert( newcontact.uid(), newcontact ); | 184 | m_map.insert( newcontact.uid(), newcontact ); |
169 | m_dirty = true; | 185 | m_dirty = true; |
170 | return true; | 186 | return true; |
171 | } | 187 | } |
172 | 188 | ||
173 | bool OContactAccessBackend_VCard::remove ( int uid ) | 189 | bool OContactAccessBackend_VCard::remove ( int uid ) |
174 | { | 190 | { |
175 | m_map.remove( uid ); | 191 | m_map.remove( uid ); |
176 | m_dirty = true; | 192 | m_dirty = true; |
177 | return true; | 193 | return true; |
@@ -425,49 +441,51 @@ OContact OContactAccessBackend_VCard::parseVObject( VObject *obj ) | |||
425 | } | 441 | } |
426 | else if ( name == "X-Qtopia-Assistant" ) { | 442 | else if ( name == "X-Qtopia-Assistant" ) { |
427 | c.setAssistant( value ); | 443 | c.setAssistant( value ); |
428 | } | 444 | } |
429 | else if ( name == "X-Qtopia-Spouse" ) { | 445 | else if ( name == "X-Qtopia-Spouse" ) { |
430 | c.setSpouse( value ); | 446 | c.setSpouse( value ); |
431 | } | 447 | } |
432 | else if ( name == "X-Qtopia-Gender" ) { | 448 | else if ( name == "X-Qtopia-Gender" ) { |
433 | c.setGender( value ); | 449 | c.setGender( value ); |
434 | } | 450 | } |
435 | else if ( name == "X-Qtopia-Anniversary" ) { | 451 | else if ( name == "X-Qtopia-Anniversary" ) { |
436 | c.setAnniversary( convVCardDateToDate( value ) ); | 452 | c.setAnniversary( convVCardDateToDate( value ) ); |
437 | } | 453 | } |
438 | else if ( name == "X-Qtopia-Nickname" ) { | 454 | else if ( name == "X-Qtopia-Nickname" ) { |
439 | c.setNickname( value ); | 455 | c.setNickname( value ); |
440 | } | 456 | } |
441 | else if ( name == "X-Qtopia-Children" ) { | 457 | else if ( name == "X-Qtopia-Children" ) { |
442 | c.setChildren( value ); | 458 | c.setChildren( value ); |
443 | } | 459 | } |
444 | else if ( name == VCBirthDateProp ) { | 460 | else if ( name == VCBirthDateProp ) { |
445 | // Reading Birthdate regarding RFC 2425 (5.8.4) | 461 | // Reading Birthdate regarding RFC 2425 (5.8.4) |
446 | c.setBirthday( convVCardDateToDate( value ) ); | 462 | c.setBirthday( convVCardDateToDate( value ) ); |
447 | 463 | ||
448 | } | 464 | } |
449 | 465 | else if ( name == VCCommentProp ) { | |
466 | c.setNotes( value ); | ||
467 | } | ||
450 | #if 0 | 468 | #if 0 |
451 | else { | 469 | else { |
452 | printf("Name: %s, value=%s\n", name.data(), vObjectStringZValue( o ) ); | 470 | printf("Name: %s, value=%s\n", name.data(), vObjectStringZValue( o ) ); |
453 | VObjectIterator nit; | 471 | VObjectIterator nit; |
454 | initPropIterator( &nit, o ); | 472 | initPropIterator( &nit, o ); |
455 | while( moreIteration( &nit ) ) { | 473 | while( moreIteration( &nit ) ) { |
456 | VObject *o = nextVObject( &nit ); | 474 | VObject *o = nextVObject( &nit ); |
457 | QCString name = vObjectName( o ); | 475 | QCString name = vObjectName( o ); |
458 | QString value = vObjectStringZValue( o ); | 476 | QString value = vObjectStringZValue( o ); |
459 | printf(" subprop: %s = %s\n", name.data(), value.latin1() ); | 477 | printf(" subprop: %s = %s\n", name.data(), value.latin1() ); |
460 | } | 478 | } |
461 | } | 479 | } |
462 | #endif | 480 | #endif |
463 | } | 481 | } |
464 | c.setFileAs(); | 482 | c.setFileAs(); |
465 | return c; | 483 | return c; |
466 | } | 484 | } |
467 | 485 | ||
468 | 486 | ||
469 | VObject* OContactAccessBackend_VCard::createVObject( const OContact &c ) | 487 | VObject* OContactAccessBackend_VCard::createVObject( const OContact &c ) |
470 | { | 488 | { |
471 | VObject *vcard = newVObject( VCCardProp ); | 489 | VObject *vcard = newVObject( VCCardProp ); |
472 | safeAddPropValue( vcard, VCVersionProp, "2.1" ); | 490 | safeAddPropValue( vcard, VCVersionProp, "2.1" ); |
473 | safeAddPropValue( vcard, VCLastRevisedProp, TimeConversion::toISO8601( QDateTime::currentDateTime() ) ); | 491 | safeAddPropValue( vcard, VCLastRevisedProp, TimeConversion::toISO8601( QDateTime::currentDateTime() ) ); |
@@ -513,49 +531,49 @@ VObject* OContactAccessBackend_VCard::createVObject( const OContact &c ) | |||
513 | safeAddPropValue( work_adr, VCRegionProp, c.businessState() ); | 531 | safeAddPropValue( work_adr, VCRegionProp, c.businessState() ); |
514 | safeAddPropValue( work_adr, VCPostalCodeProp, c.businessZip() ); | 532 | safeAddPropValue( work_adr, VCPostalCodeProp, c.businessZip() ); |
515 | safeAddPropValue( work_adr, VCCountryNameProp, c.businessCountry() ); | 533 | safeAddPropValue( work_adr, VCCountryNameProp, c.businessCountry() ); |
516 | 534 | ||
517 | VObject *work_phone = safeAddPropValue( vcard, VCTelephoneProp, c.businessPhone() ); | 535 | VObject *work_phone = safeAddPropValue( vcard, VCTelephoneProp, c.businessPhone() ); |
518 | safeAddProp( work_phone, VCWorkProp ); | 536 | safeAddProp( work_phone, VCWorkProp ); |
519 | work_phone = safeAddPropValue( vcard, VCTelephoneProp, c.businessMobile() ); | 537 | work_phone = safeAddPropValue( vcard, VCTelephoneProp, c.businessMobile() ); |
520 | safeAddProp( work_phone, VCWorkProp ); | 538 | safeAddProp( work_phone, VCWorkProp ); |
521 | safeAddProp( work_phone, VCCellularProp ); | 539 | safeAddProp( work_phone, VCCellularProp ); |
522 | work_phone = safeAddPropValue( vcard, VCTelephoneProp, c.businessFax() ); | 540 | work_phone = safeAddPropValue( vcard, VCTelephoneProp, c.businessFax() ); |
523 | safeAddProp( work_phone, VCWorkProp ); | 541 | safeAddProp( work_phone, VCWorkProp ); |
524 | safeAddProp( work_phone, VCFaxProp ); | 542 | safeAddProp( work_phone, VCFaxProp ); |
525 | work_phone = safeAddPropValue( vcard, VCTelephoneProp, c.businessPager() ); | 543 | work_phone = safeAddPropValue( vcard, VCTelephoneProp, c.businessPager() ); |
526 | safeAddProp( work_phone, VCWorkProp ); | 544 | safeAddProp( work_phone, VCWorkProp ); |
527 | safeAddProp( work_phone, VCPagerProp ); | 545 | safeAddProp( work_phone, VCPagerProp ); |
528 | 546 | ||
529 | url = safeAddPropValue( vcard, VCURLProp, c.businessWebpage() ); | 547 | url = safeAddPropValue( vcard, VCURLProp, c.businessWebpage() ); |
530 | safeAddProp( url, VCWorkProp ); | 548 | safeAddProp( url, VCWorkProp ); |
531 | 549 | ||
532 | VObject *title = safeAddPropValue( vcard, VCTitleProp, c.jobTitle() ); | 550 | VObject *title = safeAddPropValue( vcard, VCTitleProp, c.jobTitle() ); |
533 | safeAddProp( title, VCWorkProp ); | 551 | safeAddProp( title, VCWorkProp ); |
534 | 552 | ||
535 | 553 | ||
536 | QStringList emails = c.emailList(); | 554 | QStringList emails = c.emailList(); |
537 | emails.prepend( c.defaultEmail() ); | 555 | // emails.prepend( c.defaultEmail() ); Fix for bugreport #1045 |
538 | for( QStringList::Iterator it = emails.begin(); it != emails.end(); ++it ) { | 556 | for( QStringList::Iterator it = emails.begin(); it != emails.end(); ++it ) { |
539 | VObject *email = safeAddPropValue( vcard, VCEmailAddressProp, *it ); | 557 | VObject *email = safeAddPropValue( vcard, VCEmailAddressProp, *it ); |
540 | safeAddProp( email, VCInternetProp ); | 558 | safeAddProp( email, VCInternetProp ); |
541 | } | 559 | } |
542 | 560 | ||
543 | safeAddPropValue( vcard, VCNoteProp, c.notes() ); | 561 | safeAddPropValue( vcard, VCNoteProp, c.notes() ); |
544 | 562 | ||
545 | // Exporting Birthday regarding RFC 2425 (5.8.4) | 563 | // Exporting Birthday regarding RFC 2425 (5.8.4) |
546 | if ( c.birthday().isValid() ){ | 564 | if ( c.birthday().isValid() ){ |
547 | qWarning("Exporting birthday as: %s", convDateToVCardDate( c.birthday() ).latin1() ); | 565 | qWarning("Exporting birthday as: %s", convDateToVCardDate( c.birthday() ).latin1() ); |
548 | safeAddPropValue( vcard, VCBirthDateProp, convDateToVCardDate( c.birthday() ) ); | 566 | safeAddPropValue( vcard, VCBirthDateProp, convDateToVCardDate( c.birthday() ) ); |
549 | } | 567 | } |
550 | 568 | ||
551 | if ( !c.company().isEmpty() || !c.department().isEmpty() || !c.office().isEmpty() ) { | 569 | if ( !c.company().isEmpty() || !c.department().isEmpty() || !c.office().isEmpty() ) { |
552 | VObject *org = safeAddProp( vcard, VCOrgProp ); | 570 | VObject *org = safeAddProp( vcard, VCOrgProp ); |
553 | safeAddPropValue( org, VCOrgNameProp, c.company() ); | 571 | safeAddPropValue( org, VCOrgNameProp, c.company() ); |
554 | safeAddPropValue( org, VCOrgUnitProp, c.department() ); | 572 | safeAddPropValue( org, VCOrgUnitProp, c.department() ); |
555 | safeAddPropValue( org, VCOrgUnit2Prop, c.office() ); | 573 | safeAddPropValue( org, VCOrgUnit2Prop, c.office() ); |
556 | } | 574 | } |
557 | 575 | ||
558 | // some values we have to export as custom fields | 576 | // some values we have to export as custom fields |
559 | safeAddPropValue( vcard, "X-Qtopia-Profession", c.profession() ); | 577 | safeAddPropValue( vcard, "X-Qtopia-Profession", c.profession() ); |
560 | safeAddPropValue( vcard, "X-Qtopia-Manager", c.manager() ); | 578 | safeAddPropValue( vcard, "X-Qtopia-Manager", c.manager() ); |
561 | safeAddPropValue( vcard, "X-Qtopia-Assistant", c.assistant() ); | 579 | safeAddPropValue( vcard, "X-Qtopia-Assistant", c.assistant() ); |