-rw-r--r-- | libopie/pim/ocontactaccessbackend_vcard.cpp | 37 | ||||
-rw-r--r-- | libopie/pim/ocontactaccessbackend_vcard.h | 4 | ||||
-rw-r--r-- | libopie2/opiepim/backend/ocontactaccessbackend_vcard.cpp | 37 | ||||
-rw-r--r-- | libopie2/opiepim/backend/ocontactaccessbackend_vcard.h | 4 |
4 files changed, 56 insertions, 26 deletions
diff --git a/libopie/pim/ocontactaccessbackend_vcard.cpp b/libopie/pim/ocontactaccessbackend_vcard.cpp index 09ae37b..ca9e410 100644 --- a/libopie/pim/ocontactaccessbackend_vcard.cpp +++ b/libopie/pim/ocontactaccessbackend_vcard.cpp | |||
@@ -1,51 +1,54 @@ | |||
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.5 2002/12/07 13:26:22 eilers | ||
21 | * Fixing bug in storing anniversary.. | ||
22 | * | ||
20 | * Revision 1.4 2002/11/13 14:14:51 eilers | 23 | * Revision 1.4 2002/11/13 14:14:51 eilers |
21 | * Added sorted for Contacts.. | 24 | * Added sorted for Contacts.. |
22 | * | 25 | * |
23 | * Revision 1.3 2002/11/11 16:41:09 kergoth | 26 | * Revision 1.3 2002/11/11 16:41:09 kergoth |
24 | * no default arguments in implementation | 27 | * no default arguments in implementation |
25 | * | 28 | * |
26 | * Revision 1.2 2002/11/10 15:41:53 eilers | 29 | * Revision 1.2 2002/11/10 15:41:53 eilers |
27 | * Bugfixes.. | 30 | * Bugfixes.. |
28 | * | 31 | * |
29 | * Revision 1.1 2002/11/09 14:34:52 eilers | 32 | * Revision 1.1 2002/11/09 14:34:52 eilers |
30 | * Added VCard Backend. | 33 | * Added VCard Backend. |
31 | * | 34 | * |
32 | */ | 35 | */ |
33 | #include "ocontactaccessbackend_vcard.h" | 36 | #include "ocontactaccessbackend_vcard.h" |
34 | #include "../../library/backend/vobject_p.h" | 37 | #include "../../library/backend/vobject_p.h" |
35 | #include "../../library/backend/qfiledirect_p.h" | 38 | #include "../../library/backend/qfiledirect_p.h" |
36 | 39 | ||
37 | #include <qpe/timeconversion.h> | 40 | #include <qpe/timeconversion.h> |
38 | 41 | ||
39 | #include <qfile.h> | 42 | #include <qfile.h> |
40 | 43 | ||
41 | OContactAccessBackend_VCard::OContactAccessBackend_VCard ( QString , QString filename ): | 44 | OContactAccessBackend_VCard::OContactAccessBackend_VCard ( QString , QString filename ): |
42 | m_dirty( false ), | 45 | m_dirty( false ), |
43 | m_file( filename ) | 46 | m_file( filename ) |
44 | { | 47 | { |
45 | load(); | 48 | load(); |
46 | } | 49 | } |
47 | 50 | ||
48 | 51 | ||
49 | bool OContactAccessBackend_VCard::load () | 52 | bool OContactAccessBackend_VCard::load () |
50 | { | 53 | { |
51 | m_map.clear(); | 54 | m_map.clear(); |
@@ -354,65 +357,65 @@ OContact OContactAccessBackend_VCard::parseVObject( VObject *obj ) | |||
354 | initPropIterator( &nit, o ); | 357 | initPropIterator( &nit, o ); |
355 | while( moreIteration( &nit ) ) { | 358 | while( moreIteration( &nit ) ) { |
356 | VObject *o = nextVObject( &nit ); | 359 | VObject *o = nextVObject( &nit ); |
357 | QCString name = vObjectName( o ); | 360 | QCString name = vObjectName( o ); |
358 | QString value = vObjectStringZValue( o ); | 361 | QString value = vObjectStringZValue( o ); |
359 | if ( name == VCOrgNameProp ) | 362 | if ( name == VCOrgNameProp ) |
360 | c.setCompany( value ); | 363 | c.setCompany( value ); |
361 | else if ( name == VCOrgUnitProp ) | 364 | else if ( name == VCOrgUnitProp ) |
362 | c.setDepartment( value ); | 365 | c.setDepartment( value ); |
363 | else if ( name == VCOrgUnit2Prop ) | 366 | else if ( name == VCOrgUnit2Prop ) |
364 | c.setOffice( value ); | 367 | c.setOffice( value ); |
365 | } | 368 | } |
366 | } | 369 | } |
367 | else if ( name == VCTitleProp ) { | 370 | else if ( name == VCTitleProp ) { |
368 | c.setJobTitle( value ); | 371 | c.setJobTitle( value ); |
369 | } | 372 | } |
370 | else if ( name == "X-Qtopia-Profession" ) { | 373 | else if ( name == "X-Qtopia-Profession" ) { |
371 | c.setProfession( value ); | 374 | c.setProfession( value ); |
372 | } | 375 | } |
373 | else if ( name == "X-Qtopia-Manager" ) { | 376 | else if ( name == "X-Qtopia-Manager" ) { |
374 | c.setManager( value ); | 377 | c.setManager( value ); |
375 | } | 378 | } |
376 | else if ( name == "X-Qtopia-Assistant" ) { | 379 | else if ( name == "X-Qtopia-Assistant" ) { |
377 | c.setAssistant( value ); | 380 | c.setAssistant( value ); |
378 | } | 381 | } |
379 | else if ( name == "X-Qtopia-Spouse" ) { | 382 | else if ( name == "X-Qtopia-Spouse" ) { |
380 | c.setSpouse( value ); | 383 | c.setSpouse( value ); |
381 | } | 384 | } |
382 | else if ( name == "X-Qtopia-Gender" ) { | 385 | else if ( name == "X-Qtopia-Gender" ) { |
383 | c.setGender( value ); | 386 | c.setGender( value ); |
384 | } | 387 | } |
385 | else if ( name == "X-Qtopia-Anniversary" ) { | 388 | else if ( name == "X-Qtopia-Anniversary" ) { |
386 | c.setAnniversary( TimeConversion::fromString( value ) ); | 389 | c.setAnniversary( convVCardDateToDate( value ) ); |
387 | } | 390 | } |
388 | else if ( name == "X-Qtopia-Nickname" ) { | 391 | else if ( name == "X-Qtopia-Nickname" ) { |
389 | c.setNickname( value ); | 392 | c.setNickname( value ); |
390 | } | 393 | } |
391 | else if ( name == "X-Qtopia-Children" ) { | 394 | else if ( name == "X-Qtopia-Children" ) { |
392 | c.setChildren( value ); | 395 | c.setChildren( value ); |
393 | } | 396 | } |
394 | else if ( name == VCBirthDateProp ) { | 397 | else if ( name == VCBirthDateProp ) { |
395 | // Reading Birthdate regarding RFC 2425 (5.8.4) | 398 | // Reading Birthdate regarding RFC 2425 (5.8.4) |
396 | c.setBirthday( convVCardDateToDate( value ) ); | 399 | c.setBirthday( convVCardDateToDate( value ) ); |
397 | 400 | ||
398 | } | 401 | } |
399 | 402 | ||
400 | #if 0 | 403 | #if 0 |
401 | else { | 404 | else { |
402 | printf("Name: %s, value=%s\n", name.data(), vObjectStringZValue( o ) ); | 405 | printf("Name: %s, value=%s\n", name.data(), vObjectStringZValue( o ) ); |
403 | VObjectIterator nit; | 406 | VObjectIterator nit; |
404 | initPropIterator( &nit, o ); | 407 | initPropIterator( &nit, o ); |
405 | while( moreIteration( &nit ) ) { | 408 | while( moreIteration( &nit ) ) { |
406 | VObject *o = nextVObject( &nit ); | 409 | VObject *o = nextVObject( &nit ); |
407 | QCString name = vObjectName( o ); | 410 | QCString name = vObjectName( o ); |
408 | QString value = vObjectStringZValue( o ); | 411 | QString value = vObjectStringZValue( o ); |
409 | printf(" subprop: %s = %s\n", name.data(), value.latin1() ); | 412 | printf(" subprop: %s = %s\n", name.data(), value.latin1() ); |
410 | } | 413 | } |
411 | } | 414 | } |
412 | #endif | 415 | #endif |
413 | } | 416 | } |
414 | c.setFileAs(); | 417 | c.setFileAs(); |
415 | return c; | 418 | return c; |
416 | } | 419 | } |
417 | 420 | ||
418 | 421 | ||
@@ -465,98 +468,106 @@ VObject* OContactAccessBackend_VCard::createVObject( const OContact &c ) | |||
465 | safeAddPropValue( work_adr, VCCountryNameProp, c.businessCountry() ); | 468 | safeAddPropValue( work_adr, VCCountryNameProp, c.businessCountry() ); |
466 | 469 | ||
467 | VObject *work_phone = safeAddPropValue( vcard, VCTelephoneProp, c.businessPhone() ); | 470 | VObject *work_phone = safeAddPropValue( vcard, VCTelephoneProp, c.businessPhone() ); |
468 | safeAddProp( work_phone, VCWorkProp ); | 471 | safeAddProp( work_phone, VCWorkProp ); |
469 | work_phone = safeAddPropValue( vcard, VCTelephoneProp, c.businessMobile() ); | 472 | work_phone = safeAddPropValue( vcard, VCTelephoneProp, c.businessMobile() ); |
470 | safeAddProp( work_phone, VCWorkProp ); | 473 | safeAddProp( work_phone, VCWorkProp ); |
471 | safeAddProp( work_phone, VCCellularProp ); | 474 | safeAddProp( work_phone, VCCellularProp ); |
472 | work_phone = safeAddPropValue( vcard, VCTelephoneProp, c.businessFax() ); | 475 | work_phone = safeAddPropValue( vcard, VCTelephoneProp, c.businessFax() ); |
473 | safeAddProp( work_phone, VCWorkProp ); | 476 | safeAddProp( work_phone, VCWorkProp ); |
474 | safeAddProp( work_phone, VCFaxProp ); | 477 | safeAddProp( work_phone, VCFaxProp ); |
475 | work_phone = safeAddPropValue( vcard, VCTelephoneProp, c.businessPager() ); | 478 | work_phone = safeAddPropValue( vcard, VCTelephoneProp, c.businessPager() ); |
476 | safeAddProp( work_phone, VCWorkProp ); | 479 | safeAddProp( work_phone, VCWorkProp ); |
477 | safeAddProp( work_phone, VCPagerProp ); | 480 | safeAddProp( work_phone, VCPagerProp ); |
478 | 481 | ||
479 | url = safeAddPropValue( vcard, VCURLProp, c.businessWebpage() ); | 482 | url = safeAddPropValue( vcard, VCURLProp, c.businessWebpage() ); |
480 | safeAddProp( url, VCWorkProp ); | 483 | safeAddProp( url, VCWorkProp ); |
481 | 484 | ||
482 | VObject *title = safeAddPropValue( vcard, VCTitleProp, c.jobTitle() ); | 485 | VObject *title = safeAddPropValue( vcard, VCTitleProp, c.jobTitle() ); |
483 | safeAddProp( title, VCWorkProp ); | 486 | safeAddProp( title, VCWorkProp ); |
484 | 487 | ||
485 | 488 | ||
486 | QStringList emails = c.emailList(); | 489 | QStringList emails = c.emailList(); |
487 | emails.prepend( c.defaultEmail() ); | 490 | emails.prepend( c.defaultEmail() ); |
488 | for( QStringList::Iterator it = emails.begin(); it != emails.end(); ++it ) { | 491 | for( QStringList::Iterator it = emails.begin(); it != emails.end(); ++it ) { |
489 | VObject *email = safeAddPropValue( vcard, VCEmailAddressProp, *it ); | 492 | VObject *email = safeAddPropValue( vcard, VCEmailAddressProp, *it ); |
490 | safeAddProp( email, VCInternetProp ); | 493 | safeAddProp( email, VCInternetProp ); |
491 | } | 494 | } |
492 | 495 | ||
493 | safeAddPropValue( vcard, VCNoteProp, c.notes() ); | 496 | safeAddPropValue( vcard, VCNoteProp, c.notes() ); |
494 | 497 | ||
495 | // Exporting Birthday regarding RFC 2425 (5.8.4) | 498 | // Exporting Birthday regarding RFC 2425 (5.8.4) |
496 | if ( c.birthday().isValid() ){ | 499 | if ( c.birthday().isValid() ){ |
497 | QString birthd_rfc2425 = QString("%1-%2-%3") | 500 | qWarning("Exporting birthday as: %s", convDateToVCardDate( c.birthday() ).latin1() ); |
498 | .arg( c.birthday().year() ) | 501 | safeAddPropValue( vcard, VCBirthDateProp, convDateToVCardDate( c.birthday() ) ); |
499 | .arg( c.birthday().month(), 2 ) | ||
500 | .arg( c.birthday().day(), 2 ); | ||
501 | // Now replace spaces with "0"... | ||
502 | int pos = 0; | ||
503 | while ( ( pos = birthd_rfc2425.find (' ') ) > 0 ) | ||
504 | birthd_rfc2425.replace( pos, 1, "0" ); | ||
505 | |||
506 | qWarning("Exporting birthday as: %s", birthd_rfc2425.latin1()); | ||
507 | safeAddPropValue( vcard, VCBirthDateProp, birthd_rfc2425.latin1() ); | ||
508 | } | 502 | } |
509 | 503 | ||
510 | if ( !c.company().isEmpty() || !c.department().isEmpty() || !c.office().isEmpty() ) { | 504 | if ( !c.company().isEmpty() || !c.department().isEmpty() || !c.office().isEmpty() ) { |
511 | VObject *org = safeAddProp( vcard, VCOrgProp ); | 505 | VObject *org = safeAddProp( vcard, VCOrgProp ); |
512 | safeAddPropValue( org, VCOrgNameProp, c.company() ); | 506 | safeAddPropValue( org, VCOrgNameProp, c.company() ); |
513 | safeAddPropValue( org, VCOrgUnitProp, c.department() ); | 507 | safeAddPropValue( org, VCOrgUnitProp, c.department() ); |
514 | safeAddPropValue( org, VCOrgUnit2Prop, c.office() ); | 508 | safeAddPropValue( org, VCOrgUnit2Prop, c.office() ); |
515 | } | 509 | } |
516 | 510 | ||
517 | // some values we have to export as custom fields | 511 | // some values we have to export as custom fields |
518 | safeAddPropValue( vcard, "X-Qtopia-Profession", c.profession() ); | 512 | safeAddPropValue( vcard, "X-Qtopia-Profession", c.profession() ); |
519 | safeAddPropValue( vcard, "X-Qtopia-Manager", c.manager() ); | 513 | safeAddPropValue( vcard, "X-Qtopia-Manager", c.manager() ); |
520 | safeAddPropValue( vcard, "X-Qtopia-Assistant", c.assistant() ); | 514 | safeAddPropValue( vcard, "X-Qtopia-Assistant", c.assistant() ); |
521 | 515 | ||
522 | safeAddPropValue( vcard, "X-Qtopia-Spouse", c.spouse() ); | 516 | safeAddPropValue( vcard, "X-Qtopia-Spouse", c.spouse() ); |
523 | safeAddPropValue( vcard, "X-Qtopia-Gender", c.gender() ); | 517 | safeAddPropValue( vcard, "X-Qtopia-Gender", c.gender() ); |
524 | safeAddPropValue( vcard, "X-Qtopia-Anniversary", TimeConversion::toString( c.anniversary() ) ); | 518 | if ( c.anniversary().isValid() ){ |
519 | qWarning("Exporting anniversary as: %s", convDateToVCardDate( c.anniversary() ).latin1() ); | ||
520 | safeAddPropValue( vcard, "X-Qtopia-Anniversary", convDateToVCardDate( c.anniversary() ) ); | ||
521 | } | ||
525 | safeAddPropValue( vcard, "X-Qtopia-Nickname", c.nickname() ); | 522 | safeAddPropValue( vcard, "X-Qtopia-Nickname", c.nickname() ); |
526 | safeAddPropValue( vcard, "X-Qtopia-Children", c.children() ); | 523 | safeAddPropValue( vcard, "X-Qtopia-Children", c.children() ); |
527 | 524 | ||
528 | return vcard; | 525 | return vcard; |
529 | } | 526 | } |
530 | 527 | ||
528 | QString OContactAccessBackend_VCard::convDateToVCardDate( const QDate& d ) const | ||
529 | { | ||
530 | QString str_rfc2425 = QString("%1-%2-%3") | ||
531 | .arg( d.year() ) | ||
532 | .arg( d.month(), 2 ) | ||
533 | .arg( d.day(), 2 ); | ||
534 | // Now replace spaces with "0"... | ||
535 | int pos = 0; | ||
536 | while ( ( pos = str_rfc2425.find (' ') ) > 0 ) | ||
537 | str_rfc2425.replace( pos, 1, "0" ); | ||
538 | |||
539 | return str_rfc2425; | ||
540 | } | ||
541 | |||
531 | QDate OContactAccessBackend_VCard::convVCardDateToDate( const QString& datestr ) | 542 | QDate OContactAccessBackend_VCard::convVCardDateToDate( const QString& datestr ) |
532 | { | 543 | { |
533 | int monthPos = datestr.find('-'); | 544 | int monthPos = datestr.find('-'); |
534 | int dayPos = datestr.find('-', monthPos+1 ); | 545 | int dayPos = datestr.find('-', monthPos+1 ); |
535 | int sep_ignore = 1; | 546 | int sep_ignore = 1; |
536 | if ( monthPos == -1 || dayPos == -1 ) { | 547 | if ( monthPos == -1 || dayPos == -1 ) { |
537 | qDebug("fromString didn't find - in str = %s; mpos = %d ypos = %d", datestr.latin1(), monthPos, dayPos ); | 548 | qDebug("fromString didn't find - in str = %s; mpos = %d ypos = %d", datestr.latin1(), monthPos, dayPos ); |
538 | // Ok.. No "-" found, therefore we will try to read other format ( YYYYMMDD ) | 549 | // Ok.. No "-" found, therefore we will try to read other format ( YYYYMMDD ) |
539 | if ( datestr.length() == 8 ){ | 550 | if ( datestr.length() == 8 ){ |
540 | monthPos = 4; | 551 | monthPos = 4; |
541 | dayPos = 6; | 552 | dayPos = 6; |
542 | sep_ignore = 0; | 553 | sep_ignore = 0; |
543 | qDebug("Try with follwing positions str = %s; mpos = %d ypos = %d", datestr.latin1(), monthPos, dayPos ); | 554 | qDebug("Try with follwing positions str = %s; mpos = %d ypos = %d", datestr.latin1(), monthPos, dayPos ); |
544 | } else { | 555 | } else { |
545 | return QDate(); | 556 | return QDate(); |
546 | } | 557 | } |
547 | } | 558 | } |
548 | int y = datestr.left( monthPos ).toInt(); | 559 | int y = datestr.left( monthPos ).toInt(); |
549 | int m = datestr.mid( monthPos + sep_ignore, dayPos - monthPos - sep_ignore ).toInt(); | 560 | int m = datestr.mid( monthPos + sep_ignore, dayPos - monthPos - sep_ignore ).toInt(); |
550 | int d = datestr.mid( dayPos + sep_ignore ).toInt(); | 561 | int d = datestr.mid( dayPos + sep_ignore ).toInt(); |
551 | qDebug("TimeConversion::fromString ymd = %s => %d %d %d; mpos = %d ypos = %d", datestr.latin1(), y, m, d, monthPos, dayPos); | 562 | qDebug("TimeConversion::fromString ymd = %s => %d %d %d; mpos = %d ypos = %d", datestr.latin1(), y, m, d, monthPos, dayPos); |
552 | QDate date ( y,m,d ); | 563 | QDate date ( y,m,d ); |
553 | return date; | 564 | return date; |
554 | } | 565 | } |
555 | 566 | ||
556 | VObject* OContactAccessBackend_VCard::safeAddPropValue( VObject *o, const char *prop, const QString &value ) | 567 | VObject* OContactAccessBackend_VCard::safeAddPropValue( VObject *o, const char *prop, const QString &value ) |
557 | { | 568 | { |
558 | VObject *ret = 0; | 569 | VObject *ret = 0; |
559 | if ( o && !value.isEmpty() ) | 570 | if ( o && !value.isEmpty() ) |
560 | ret = addPropValue( o, prop, value.latin1() ); | 571 | ret = addPropValue( o, prop, value.latin1() ); |
561 | return ret; | 572 | return ret; |
562 | } | 573 | } |
diff --git a/libopie/pim/ocontactaccessbackend_vcard.h b/libopie/pim/ocontactaccessbackend_vcard.h index 4437756..236da00 100644 --- a/libopie/pim/ocontactaccessbackend_vcard.h +++ b/libopie/pim/ocontactaccessbackend_vcard.h | |||
@@ -1,74 +1,78 @@ | |||
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.4 2002/12/07 13:26:22 eilers | ||
21 | * Fixing bug in storing anniversary.. | ||
22 | * | ||
20 | * Revision 1.3 2002/11/13 14:14:51 eilers | 23 | * Revision 1.3 2002/11/13 14:14:51 eilers |
21 | * Added sorted for Contacts.. | 24 | * Added sorted for Contacts.. |
22 | * | 25 | * |
23 | * Revision 1.2 2002/11/10 15:41:53 eilers | 26 | * Revision 1.2 2002/11/10 15:41:53 eilers |
24 | * Bugfixes.. | 27 | * Bugfixes.. |
25 | * | 28 | * |
26 | * Revision 1.1 2002/11/09 14:34:52 eilers | 29 | * Revision 1.1 2002/11/09 14:34:52 eilers |
27 | * Added VCard Backend. | 30 | * Added VCard Backend. |
28 | * | 31 | * |
29 | */ | 32 | */ |
30 | #ifndef __OCONTACTACCESSBACKEND_VCARD_H_ | 33 | #ifndef __OCONTACTACCESSBACKEND_VCARD_H_ |
31 | #define __OCONTACTACCESSBACKEND_VCARD_H_ | 34 | #define __OCONTACTACCESSBACKEND_VCARD_H_ |
32 | 35 | ||
33 | #include <opie/ocontact.h> | 36 | #include <opie/ocontact.h> |
34 | 37 | ||
35 | #include "ocontactaccessbackend.h" | 38 | #include "ocontactaccessbackend.h" |
36 | 39 | ||
37 | class VObject; | 40 | class VObject; |
38 | 41 | ||
39 | class OContactAccessBackend_VCard : public OContactAccessBackend { | 42 | class OContactAccessBackend_VCard : public OContactAccessBackend { |
40 | public: | 43 | public: |
41 | OContactAccessBackend_VCard ( QString appname, QString filename = 0l ); | 44 | OContactAccessBackend_VCard ( QString appname, QString filename = 0l ); |
42 | 45 | ||
43 | bool load (); | 46 | bool load (); |
44 | bool reload(); | 47 | bool reload(); |
45 | bool save(); | 48 | bool save(); |
46 | void clear (); | 49 | void clear (); |
47 | 50 | ||
48 | bool add ( const OContact& newcontact ); | 51 | bool add ( const OContact& newcontact ); |
49 | bool remove ( int uid ); | 52 | bool remove ( int uid ); |
50 | bool replace ( const OContact& contact ); | 53 | bool replace ( const OContact& contact ); |
51 | 54 | ||
52 | OContact find ( int uid ) const; | 55 | OContact find ( int uid ) const; |
53 | QArray<int> allRecords() const; | 56 | QArray<int> allRecords() const; |
54 | QArray<int> queryByExample ( const OContact &query, int settings ); | 57 | QArray<int> queryByExample ( const OContact &query, int settings ); |
55 | QArray<int> matchRegexp( const QRegExp &r ) const; | 58 | QArray<int> matchRegexp( const QRegExp &r ) const; |
56 | 59 | ||
57 | const uint querySettings(); | 60 | const uint querySettings(); |
58 | bool hasQuerySettings (uint querySettings) const; | 61 | bool hasQuerySettings (uint querySettings) const; |
59 | QArray<int> sorted( bool ascending, int sortOrder, int sortFilter, int cat ); | 62 | QArray<int> sorted( bool ascending, int sortOrder, int sortFilter, int cat ); |
60 | bool wasChangedExternally(); | 63 | bool wasChangedExternally(); |
61 | 64 | ||
62 | private: | 65 | private: |
63 | OContact parseVObject( VObject* obj ); | 66 | OContact parseVObject( VObject* obj ); |
64 | VObject* createVObject( const OContact& c ); | 67 | VObject* createVObject( const OContact& c ); |
68 | QString convDateToVCardDate( const QDate& c ) const; | ||
65 | QDate convVCardDateToDate( const QString& datestr ); | 69 | QDate convVCardDateToDate( const QString& datestr ); |
66 | VObject *safeAddPropValue( VObject *o, const char* prop, const QString& value ); | 70 | VObject *safeAddPropValue( VObject *o, const char* prop, const QString& value ); |
67 | VObject *safeAddProp( VObject* o, const char* prop); | 71 | VObject *safeAddProp( VObject* o, const char* prop); |
68 | 72 | ||
69 | bool m_dirty : 1; | 73 | bool m_dirty : 1; |
70 | QString m_file; | 74 | QString m_file; |
71 | QMap<int, OContact> m_map; | 75 | QMap<int, OContact> m_map; |
72 | }; | 76 | }; |
73 | 77 | ||
74 | #endif | 78 | #endif |
diff --git a/libopie2/opiepim/backend/ocontactaccessbackend_vcard.cpp b/libopie2/opiepim/backend/ocontactaccessbackend_vcard.cpp index 09ae37b..ca9e410 100644 --- a/libopie2/opiepim/backend/ocontactaccessbackend_vcard.cpp +++ b/libopie2/opiepim/backend/ocontactaccessbackend_vcard.cpp | |||
@@ -1,51 +1,54 @@ | |||
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.5 2002/12/07 13:26:22 eilers | ||
21 | * Fixing bug in storing anniversary.. | ||
22 | * | ||
20 | * Revision 1.4 2002/11/13 14:14:51 eilers | 23 | * Revision 1.4 2002/11/13 14:14:51 eilers |
21 | * Added sorted for Contacts.. | 24 | * Added sorted for Contacts.. |
22 | * | 25 | * |
23 | * Revision 1.3 2002/11/11 16:41:09 kergoth | 26 | * Revision 1.3 2002/11/11 16:41:09 kergoth |
24 | * no default arguments in implementation | 27 | * no default arguments in implementation |
25 | * | 28 | * |
26 | * Revision 1.2 2002/11/10 15:41:53 eilers | 29 | * Revision 1.2 2002/11/10 15:41:53 eilers |
27 | * Bugfixes.. | 30 | * Bugfixes.. |
28 | * | 31 | * |
29 | * Revision 1.1 2002/11/09 14:34:52 eilers | 32 | * Revision 1.1 2002/11/09 14:34:52 eilers |
30 | * Added VCard Backend. | 33 | * Added VCard Backend. |
31 | * | 34 | * |
32 | */ | 35 | */ |
33 | #include "ocontactaccessbackend_vcard.h" | 36 | #include "ocontactaccessbackend_vcard.h" |
34 | #include "../../library/backend/vobject_p.h" | 37 | #include "../../library/backend/vobject_p.h" |
35 | #include "../../library/backend/qfiledirect_p.h" | 38 | #include "../../library/backend/qfiledirect_p.h" |
36 | 39 | ||
37 | #include <qpe/timeconversion.h> | 40 | #include <qpe/timeconversion.h> |
38 | 41 | ||
39 | #include <qfile.h> | 42 | #include <qfile.h> |
40 | 43 | ||
41 | OContactAccessBackend_VCard::OContactAccessBackend_VCard ( QString , QString filename ): | 44 | OContactAccessBackend_VCard::OContactAccessBackend_VCard ( QString , QString filename ): |
42 | m_dirty( false ), | 45 | m_dirty( false ), |
43 | m_file( filename ) | 46 | m_file( filename ) |
44 | { | 47 | { |
45 | load(); | 48 | load(); |
46 | } | 49 | } |
47 | 50 | ||
48 | 51 | ||
49 | bool OContactAccessBackend_VCard::load () | 52 | bool OContactAccessBackend_VCard::load () |
50 | { | 53 | { |
51 | m_map.clear(); | 54 | m_map.clear(); |
@@ -354,65 +357,65 @@ OContact OContactAccessBackend_VCard::parseVObject( VObject *obj ) | |||
354 | initPropIterator( &nit, o ); | 357 | initPropIterator( &nit, o ); |
355 | while( moreIteration( &nit ) ) { | 358 | while( moreIteration( &nit ) ) { |
356 | VObject *o = nextVObject( &nit ); | 359 | VObject *o = nextVObject( &nit ); |
357 | QCString name = vObjectName( o ); | 360 | QCString name = vObjectName( o ); |
358 | QString value = vObjectStringZValue( o ); | 361 | QString value = vObjectStringZValue( o ); |
359 | if ( name == VCOrgNameProp ) | 362 | if ( name == VCOrgNameProp ) |
360 | c.setCompany( value ); | 363 | c.setCompany( value ); |
361 | else if ( name == VCOrgUnitProp ) | 364 | else if ( name == VCOrgUnitProp ) |
362 | c.setDepartment( value ); | 365 | c.setDepartment( value ); |
363 | else if ( name == VCOrgUnit2Prop ) | 366 | else if ( name == VCOrgUnit2Prop ) |
364 | c.setOffice( value ); | 367 | c.setOffice( value ); |
365 | } | 368 | } |
366 | } | 369 | } |
367 | else if ( name == VCTitleProp ) { | 370 | else if ( name == VCTitleProp ) { |
368 | c.setJobTitle( value ); | 371 | c.setJobTitle( value ); |
369 | } | 372 | } |
370 | else if ( name == "X-Qtopia-Profession" ) { | 373 | else if ( name == "X-Qtopia-Profession" ) { |
371 | c.setProfession( value ); | 374 | c.setProfession( value ); |
372 | } | 375 | } |
373 | else if ( name == "X-Qtopia-Manager" ) { | 376 | else if ( name == "X-Qtopia-Manager" ) { |
374 | c.setManager( value ); | 377 | c.setManager( value ); |
375 | } | 378 | } |
376 | else if ( name == "X-Qtopia-Assistant" ) { | 379 | else if ( name == "X-Qtopia-Assistant" ) { |
377 | c.setAssistant( value ); | 380 | c.setAssistant( value ); |
378 | } | 381 | } |
379 | else if ( name == "X-Qtopia-Spouse" ) { | 382 | else if ( name == "X-Qtopia-Spouse" ) { |
380 | c.setSpouse( value ); | 383 | c.setSpouse( value ); |
381 | } | 384 | } |
382 | else if ( name == "X-Qtopia-Gender" ) { | 385 | else if ( name == "X-Qtopia-Gender" ) { |
383 | c.setGender( value ); | 386 | c.setGender( value ); |
384 | } | 387 | } |
385 | else if ( name == "X-Qtopia-Anniversary" ) { | 388 | else if ( name == "X-Qtopia-Anniversary" ) { |
386 | c.setAnniversary( TimeConversion::fromString( value ) ); | 389 | c.setAnniversary( convVCardDateToDate( value ) ); |
387 | } | 390 | } |
388 | else if ( name == "X-Qtopia-Nickname" ) { | 391 | else if ( name == "X-Qtopia-Nickname" ) { |
389 | c.setNickname( value ); | 392 | c.setNickname( value ); |
390 | } | 393 | } |
391 | else if ( name == "X-Qtopia-Children" ) { | 394 | else if ( name == "X-Qtopia-Children" ) { |
392 | c.setChildren( value ); | 395 | c.setChildren( value ); |
393 | } | 396 | } |
394 | else if ( name == VCBirthDateProp ) { | 397 | else if ( name == VCBirthDateProp ) { |
395 | // Reading Birthdate regarding RFC 2425 (5.8.4) | 398 | // Reading Birthdate regarding RFC 2425 (5.8.4) |
396 | c.setBirthday( convVCardDateToDate( value ) ); | 399 | c.setBirthday( convVCardDateToDate( value ) ); |
397 | 400 | ||
398 | } | 401 | } |
399 | 402 | ||
400 | #if 0 | 403 | #if 0 |
401 | else { | 404 | else { |
402 | printf("Name: %s, value=%s\n", name.data(), vObjectStringZValue( o ) ); | 405 | printf("Name: %s, value=%s\n", name.data(), vObjectStringZValue( o ) ); |
403 | VObjectIterator nit; | 406 | VObjectIterator nit; |
404 | initPropIterator( &nit, o ); | 407 | initPropIterator( &nit, o ); |
405 | while( moreIteration( &nit ) ) { | 408 | while( moreIteration( &nit ) ) { |
406 | VObject *o = nextVObject( &nit ); | 409 | VObject *o = nextVObject( &nit ); |
407 | QCString name = vObjectName( o ); | 410 | QCString name = vObjectName( o ); |
408 | QString value = vObjectStringZValue( o ); | 411 | QString value = vObjectStringZValue( o ); |
409 | printf(" subprop: %s = %s\n", name.data(), value.latin1() ); | 412 | printf(" subprop: %s = %s\n", name.data(), value.latin1() ); |
410 | } | 413 | } |
411 | } | 414 | } |
412 | #endif | 415 | #endif |
413 | } | 416 | } |
414 | c.setFileAs(); | 417 | c.setFileAs(); |
415 | return c; | 418 | return c; |
416 | } | 419 | } |
417 | 420 | ||
418 | 421 | ||
@@ -465,98 +468,106 @@ VObject* OContactAccessBackend_VCard::createVObject( const OContact &c ) | |||
465 | safeAddPropValue( work_adr, VCCountryNameProp, c.businessCountry() ); | 468 | safeAddPropValue( work_adr, VCCountryNameProp, c.businessCountry() ); |
466 | 469 | ||
467 | VObject *work_phone = safeAddPropValue( vcard, VCTelephoneProp, c.businessPhone() ); | 470 | VObject *work_phone = safeAddPropValue( vcard, VCTelephoneProp, c.businessPhone() ); |
468 | safeAddProp( work_phone, VCWorkProp ); | 471 | safeAddProp( work_phone, VCWorkProp ); |
469 | work_phone = safeAddPropValue( vcard, VCTelephoneProp, c.businessMobile() ); | 472 | work_phone = safeAddPropValue( vcard, VCTelephoneProp, c.businessMobile() ); |
470 | safeAddProp( work_phone, VCWorkProp ); | 473 | safeAddProp( work_phone, VCWorkProp ); |
471 | safeAddProp( work_phone, VCCellularProp ); | 474 | safeAddProp( work_phone, VCCellularProp ); |
472 | work_phone = safeAddPropValue( vcard, VCTelephoneProp, c.businessFax() ); | 475 | work_phone = safeAddPropValue( vcard, VCTelephoneProp, c.businessFax() ); |
473 | safeAddProp( work_phone, VCWorkProp ); | 476 | safeAddProp( work_phone, VCWorkProp ); |
474 | safeAddProp( work_phone, VCFaxProp ); | 477 | safeAddProp( work_phone, VCFaxProp ); |
475 | work_phone = safeAddPropValue( vcard, VCTelephoneProp, c.businessPager() ); | 478 | work_phone = safeAddPropValue( vcard, VCTelephoneProp, c.businessPager() ); |
476 | safeAddProp( work_phone, VCWorkProp ); | 479 | safeAddProp( work_phone, VCWorkProp ); |
477 | safeAddProp( work_phone, VCPagerProp ); | 480 | safeAddProp( work_phone, VCPagerProp ); |
478 | 481 | ||
479 | url = safeAddPropValue( vcard, VCURLProp, c.businessWebpage() ); | 482 | url = safeAddPropValue( vcard, VCURLProp, c.businessWebpage() ); |
480 | safeAddProp( url, VCWorkProp ); | 483 | safeAddProp( url, VCWorkProp ); |
481 | 484 | ||
482 | VObject *title = safeAddPropValue( vcard, VCTitleProp, c.jobTitle() ); | 485 | VObject *title = safeAddPropValue( vcard, VCTitleProp, c.jobTitle() ); |
483 | safeAddProp( title, VCWorkProp ); | 486 | safeAddProp( title, VCWorkProp ); |
484 | 487 | ||
485 | 488 | ||
486 | QStringList emails = c.emailList(); | 489 | QStringList emails = c.emailList(); |
487 | emails.prepend( c.defaultEmail() ); | 490 | emails.prepend( c.defaultEmail() ); |
488 | for( QStringList::Iterator it = emails.begin(); it != emails.end(); ++it ) { | 491 | for( QStringList::Iterator it = emails.begin(); it != emails.end(); ++it ) { |
489 | VObject *email = safeAddPropValue( vcard, VCEmailAddressProp, *it ); | 492 | VObject *email = safeAddPropValue( vcard, VCEmailAddressProp, *it ); |
490 | safeAddProp( email, VCInternetProp ); | 493 | safeAddProp( email, VCInternetProp ); |
491 | } | 494 | } |
492 | 495 | ||
493 | safeAddPropValue( vcard, VCNoteProp, c.notes() ); | 496 | safeAddPropValue( vcard, VCNoteProp, c.notes() ); |
494 | 497 | ||
495 | // Exporting Birthday regarding RFC 2425 (5.8.4) | 498 | // Exporting Birthday regarding RFC 2425 (5.8.4) |
496 | if ( c.birthday().isValid() ){ | 499 | if ( c.birthday().isValid() ){ |
497 | QString birthd_rfc2425 = QString("%1-%2-%3") | 500 | qWarning("Exporting birthday as: %s", convDateToVCardDate( c.birthday() ).latin1() ); |
498 | .arg( c.birthday().year() ) | 501 | safeAddPropValue( vcard, VCBirthDateProp, convDateToVCardDate( c.birthday() ) ); |
499 | .arg( c.birthday().month(), 2 ) | ||
500 | .arg( c.birthday().day(), 2 ); | ||
501 | // Now replace spaces with "0"... | ||
502 | int pos = 0; | ||
503 | while ( ( pos = birthd_rfc2425.find (' ') ) > 0 ) | ||
504 | birthd_rfc2425.replace( pos, 1, "0" ); | ||
505 | |||
506 | qWarning("Exporting birthday as: %s", birthd_rfc2425.latin1()); | ||
507 | safeAddPropValue( vcard, VCBirthDateProp, birthd_rfc2425.latin1() ); | ||
508 | } | 502 | } |
509 | 503 | ||
510 | if ( !c.company().isEmpty() || !c.department().isEmpty() || !c.office().isEmpty() ) { | 504 | if ( !c.company().isEmpty() || !c.department().isEmpty() || !c.office().isEmpty() ) { |
511 | VObject *org = safeAddProp( vcard, VCOrgProp ); | 505 | VObject *org = safeAddProp( vcard, VCOrgProp ); |
512 | safeAddPropValue( org, VCOrgNameProp, c.company() ); | 506 | safeAddPropValue( org, VCOrgNameProp, c.company() ); |
513 | safeAddPropValue( org, VCOrgUnitProp, c.department() ); | 507 | safeAddPropValue( org, VCOrgUnitProp, c.department() ); |
514 | safeAddPropValue( org, VCOrgUnit2Prop, c.office() ); | 508 | safeAddPropValue( org, VCOrgUnit2Prop, c.office() ); |
515 | } | 509 | } |
516 | 510 | ||
517 | // some values we have to export as custom fields | 511 | // some values we have to export as custom fields |
518 | safeAddPropValue( vcard, "X-Qtopia-Profession", c.profession() ); | 512 | safeAddPropValue( vcard, "X-Qtopia-Profession", c.profession() ); |
519 | safeAddPropValue( vcard, "X-Qtopia-Manager", c.manager() ); | 513 | safeAddPropValue( vcard, "X-Qtopia-Manager", c.manager() ); |
520 | safeAddPropValue( vcard, "X-Qtopia-Assistant", c.assistant() ); | 514 | safeAddPropValue( vcard, "X-Qtopia-Assistant", c.assistant() ); |
521 | 515 | ||
522 | safeAddPropValue( vcard, "X-Qtopia-Spouse", c.spouse() ); | 516 | safeAddPropValue( vcard, "X-Qtopia-Spouse", c.spouse() ); |
523 | safeAddPropValue( vcard, "X-Qtopia-Gender", c.gender() ); | 517 | safeAddPropValue( vcard, "X-Qtopia-Gender", c.gender() ); |
524 | safeAddPropValue( vcard, "X-Qtopia-Anniversary", TimeConversion::toString( c.anniversary() ) ); | 518 | if ( c.anniversary().isValid() ){ |
519 | qWarning("Exporting anniversary as: %s", convDateToVCardDate( c.anniversary() ).latin1() ); | ||
520 | safeAddPropValue( vcard, "X-Qtopia-Anniversary", convDateToVCardDate( c.anniversary() ) ); | ||
521 | } | ||
525 | safeAddPropValue( vcard, "X-Qtopia-Nickname", c.nickname() ); | 522 | safeAddPropValue( vcard, "X-Qtopia-Nickname", c.nickname() ); |
526 | safeAddPropValue( vcard, "X-Qtopia-Children", c.children() ); | 523 | safeAddPropValue( vcard, "X-Qtopia-Children", c.children() ); |
527 | 524 | ||
528 | return vcard; | 525 | return vcard; |
529 | } | 526 | } |
530 | 527 | ||
528 | QString OContactAccessBackend_VCard::convDateToVCardDate( const QDate& d ) const | ||
529 | { | ||
530 | QString str_rfc2425 = QString("%1-%2-%3") | ||
531 | .arg( d.year() ) | ||
532 | .arg( d.month(), 2 ) | ||
533 | .arg( d.day(), 2 ); | ||
534 | // Now replace spaces with "0"... | ||
535 | int pos = 0; | ||
536 | while ( ( pos = str_rfc2425.find (' ') ) > 0 ) | ||
537 | str_rfc2425.replace( pos, 1, "0" ); | ||
538 | |||
539 | return str_rfc2425; | ||
540 | } | ||
541 | |||
531 | QDate OContactAccessBackend_VCard::convVCardDateToDate( const QString& datestr ) | 542 | QDate OContactAccessBackend_VCard::convVCardDateToDate( const QString& datestr ) |
532 | { | 543 | { |
533 | int monthPos = datestr.find('-'); | 544 | int monthPos = datestr.find('-'); |
534 | int dayPos = datestr.find('-', monthPos+1 ); | 545 | int dayPos = datestr.find('-', monthPos+1 ); |
535 | int sep_ignore = 1; | 546 | int sep_ignore = 1; |
536 | if ( monthPos == -1 || dayPos == -1 ) { | 547 | if ( monthPos == -1 || dayPos == -1 ) { |
537 | qDebug("fromString didn't find - in str = %s; mpos = %d ypos = %d", datestr.latin1(), monthPos, dayPos ); | 548 | qDebug("fromString didn't find - in str = %s; mpos = %d ypos = %d", datestr.latin1(), monthPos, dayPos ); |
538 | // Ok.. No "-" found, therefore we will try to read other format ( YYYYMMDD ) | 549 | // Ok.. No "-" found, therefore we will try to read other format ( YYYYMMDD ) |
539 | if ( datestr.length() == 8 ){ | 550 | if ( datestr.length() == 8 ){ |
540 | monthPos = 4; | 551 | monthPos = 4; |
541 | dayPos = 6; | 552 | dayPos = 6; |
542 | sep_ignore = 0; | 553 | sep_ignore = 0; |
543 | qDebug("Try with follwing positions str = %s; mpos = %d ypos = %d", datestr.latin1(), monthPos, dayPos ); | 554 | qDebug("Try with follwing positions str = %s; mpos = %d ypos = %d", datestr.latin1(), monthPos, dayPos ); |
544 | } else { | 555 | } else { |
545 | return QDate(); | 556 | return QDate(); |
546 | } | 557 | } |
547 | } | 558 | } |
548 | int y = datestr.left( monthPos ).toInt(); | 559 | int y = datestr.left( monthPos ).toInt(); |
549 | int m = datestr.mid( monthPos + sep_ignore, dayPos - monthPos - sep_ignore ).toInt(); | 560 | int m = datestr.mid( monthPos + sep_ignore, dayPos - monthPos - sep_ignore ).toInt(); |
550 | int d = datestr.mid( dayPos + sep_ignore ).toInt(); | 561 | int d = datestr.mid( dayPos + sep_ignore ).toInt(); |
551 | qDebug("TimeConversion::fromString ymd = %s => %d %d %d; mpos = %d ypos = %d", datestr.latin1(), y, m, d, monthPos, dayPos); | 562 | qDebug("TimeConversion::fromString ymd = %s => %d %d %d; mpos = %d ypos = %d", datestr.latin1(), y, m, d, monthPos, dayPos); |
552 | QDate date ( y,m,d ); | 563 | QDate date ( y,m,d ); |
553 | return date; | 564 | return date; |
554 | } | 565 | } |
555 | 566 | ||
556 | VObject* OContactAccessBackend_VCard::safeAddPropValue( VObject *o, const char *prop, const QString &value ) | 567 | VObject* OContactAccessBackend_VCard::safeAddPropValue( VObject *o, const char *prop, const QString &value ) |
557 | { | 568 | { |
558 | VObject *ret = 0; | 569 | VObject *ret = 0; |
559 | if ( o && !value.isEmpty() ) | 570 | if ( o && !value.isEmpty() ) |
560 | ret = addPropValue( o, prop, value.latin1() ); | 571 | ret = addPropValue( o, prop, value.latin1() ); |
561 | return ret; | 572 | return ret; |
562 | } | 573 | } |
diff --git a/libopie2/opiepim/backend/ocontactaccessbackend_vcard.h b/libopie2/opiepim/backend/ocontactaccessbackend_vcard.h index 4437756..236da00 100644 --- a/libopie2/opiepim/backend/ocontactaccessbackend_vcard.h +++ b/libopie2/opiepim/backend/ocontactaccessbackend_vcard.h | |||
@@ -1,74 +1,78 @@ | |||
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.4 2002/12/07 13:26:22 eilers | ||
21 | * Fixing bug in storing anniversary.. | ||
22 | * | ||
20 | * Revision 1.3 2002/11/13 14:14:51 eilers | 23 | * Revision 1.3 2002/11/13 14:14:51 eilers |
21 | * Added sorted for Contacts.. | 24 | * Added sorted for Contacts.. |
22 | * | 25 | * |
23 | * Revision 1.2 2002/11/10 15:41:53 eilers | 26 | * Revision 1.2 2002/11/10 15:41:53 eilers |
24 | * Bugfixes.. | 27 | * Bugfixes.. |
25 | * | 28 | * |
26 | * Revision 1.1 2002/11/09 14:34:52 eilers | 29 | * Revision 1.1 2002/11/09 14:34:52 eilers |
27 | * Added VCard Backend. | 30 | * Added VCard Backend. |
28 | * | 31 | * |
29 | */ | 32 | */ |
30 | #ifndef __OCONTACTACCESSBACKEND_VCARD_H_ | 33 | #ifndef __OCONTACTACCESSBACKEND_VCARD_H_ |
31 | #define __OCONTACTACCESSBACKEND_VCARD_H_ | 34 | #define __OCONTACTACCESSBACKEND_VCARD_H_ |
32 | 35 | ||
33 | #include <opie/ocontact.h> | 36 | #include <opie/ocontact.h> |
34 | 37 | ||
35 | #include "ocontactaccessbackend.h" | 38 | #include "ocontactaccessbackend.h" |
36 | 39 | ||
37 | class VObject; | 40 | class VObject; |
38 | 41 | ||
39 | class OContactAccessBackend_VCard : public OContactAccessBackend { | 42 | class OContactAccessBackend_VCard : public OContactAccessBackend { |
40 | public: | 43 | public: |
41 | OContactAccessBackend_VCard ( QString appname, QString filename = 0l ); | 44 | OContactAccessBackend_VCard ( QString appname, QString filename = 0l ); |
42 | 45 | ||
43 | bool load (); | 46 | bool load (); |
44 | bool reload(); | 47 | bool reload(); |
45 | bool save(); | 48 | bool save(); |
46 | void clear (); | 49 | void clear (); |
47 | 50 | ||
48 | bool add ( const OContact& newcontact ); | 51 | bool add ( const OContact& newcontact ); |
49 | bool remove ( int uid ); | 52 | bool remove ( int uid ); |
50 | bool replace ( const OContact& contact ); | 53 | bool replace ( const OContact& contact ); |
51 | 54 | ||
52 | OContact find ( int uid ) const; | 55 | OContact find ( int uid ) const; |
53 | QArray<int> allRecords() const; | 56 | QArray<int> allRecords() const; |
54 | QArray<int> queryByExample ( const OContact &query, int settings ); | 57 | QArray<int> queryByExample ( const OContact &query, int settings ); |
55 | QArray<int> matchRegexp( const QRegExp &r ) const; | 58 | QArray<int> matchRegexp( const QRegExp &r ) const; |
56 | 59 | ||
57 | const uint querySettings(); | 60 | const uint querySettings(); |
58 | bool hasQuerySettings (uint querySettings) const; | 61 | bool hasQuerySettings (uint querySettings) const; |
59 | QArray<int> sorted( bool ascending, int sortOrder, int sortFilter, int cat ); | 62 | QArray<int> sorted( bool ascending, int sortOrder, int sortFilter, int cat ); |
60 | bool wasChangedExternally(); | 63 | bool wasChangedExternally(); |
61 | 64 | ||
62 | private: | 65 | private: |
63 | OContact parseVObject( VObject* obj ); | 66 | OContact parseVObject( VObject* obj ); |
64 | VObject* createVObject( const OContact& c ); | 67 | VObject* createVObject( const OContact& c ); |
68 | QString convDateToVCardDate( const QDate& c ) const; | ||
65 | QDate convVCardDateToDate( const QString& datestr ); | 69 | QDate convVCardDateToDate( const QString& datestr ); |
66 | VObject *safeAddPropValue( VObject *o, const char* prop, const QString& value ); | 70 | VObject *safeAddPropValue( VObject *o, const char* prop, const QString& value ); |
67 | VObject *safeAddProp( VObject* o, const char* prop); | 71 | VObject *safeAddProp( VObject* o, const char* prop); |
68 | 72 | ||
69 | bool m_dirty : 1; | 73 | bool m_dirty : 1; |
70 | QString m_file; | 74 | QString m_file; |
71 | QMap<int, OContact> m_map; | 75 | QMap<int, OContact> m_map; |
72 | }; | 76 | }; |
73 | 77 | ||
74 | #endif | 78 | #endif |