summaryrefslogtreecommitdiff
path: root/libopie2/opiepim/backend/ocontactaccessbackend_vcard.cpp
Unidiff
Diffstat (limited to 'libopie2/opiepim/backend/ocontactaccessbackend_vcard.cpp') (more/less context) (show whitespace changes)
-rw-r--r--libopie2/opiepim/backend/ocontactaccessbackend_vcard.cpp18
1 files changed, 10 insertions, 8 deletions
diff --git a/libopie2/opiepim/backend/ocontactaccessbackend_vcard.cpp b/libopie2/opiepim/backend/ocontactaccessbackend_vcard.cpp
index ffa6a7d..b6ea461 100644
--- a/libopie2/opiepim/backend/ocontactaccessbackend_vcard.cpp
+++ b/libopie2/opiepim/backend/ocontactaccessbackend_vcard.cpp
@@ -26,24 +26,26 @@
26 Inc., 59 Temple Place - Suite 330, 26 Inc., 59 Temple Place - Suite 330,
27 Boston, MA 02111-1307, USA. 27 Boston, MA 02111-1307, USA.
28*/ 28*/
29/* 29/*
30 * VCard Backend for the OPIE-Contact Database. 30 * VCard Backend for the OPIE-Contact Database.
31 */ 31 */
32 32
33 33
34#include "vobject_p.h" 34#include "vobject_p.h"
35 35
36/* OPIE */ 36/* OPIE */
37#include <opie2/ocontactaccessbackend_vcard.h> 37#include <opie2/ocontactaccessbackend_vcard.h>
38#include <opie2/odebug.h>
39
38#include <qpe/timeconversion.h> 40#include <qpe/timeconversion.h>
39 41
40//FIXME: Hack to allow direct access to FILE* fh. Rewrite this! 42//FIXME: Hack to allow direct access to FILE* fh. Rewrite this!
41#define protected public 43#define protected public
42#include <qfile.h> 44#include <qfile.h>
43#undef protected 45#undef protected
44 46
45namespace Opie { 47namespace Opie {
46 48
47OPimContactAccessBackend_VCard::OPimContactAccessBackend_VCard ( const QString& , const QString& filename ): 49OPimContactAccessBackend_VCard::OPimContactAccessBackend_VCard ( const QString& , const QString& filename ):
48 m_dirty( false ), 50 m_dirty( false ),
49 m_file( filename ) 51 m_file( filename )
@@ -55,38 +57,38 @@ OPimContactAccessBackend_VCard::OPimContactAccessBackend_VCard ( const QString&
55bool OPimContactAccessBackend_VCard::load () 57bool OPimContactAccessBackend_VCard::load ()
56{ 58{
57 m_map.clear(); 59 m_map.clear();
58 m_dirty = false; 60 m_dirty = false;
59 61
60 VObject* obj = 0l; 62 VObject* obj = 0l;
61 63
62 if ( QFile::exists(m_file) ){ 64 if ( QFile::exists(m_file) ){
63 obj = Parse_MIME_FromFileName( QFile::encodeName(m_file).data() ); 65 obj = Parse_MIME_FromFileName( QFile::encodeName(m_file).data() );
64 if ( !obj ) 66 if ( !obj )
65 return false; 67 return false;
66 }else{ 68 }else{
67 qWarning("File \"%s\" not found !", m_file.latin1() ); 69 owarn << "File \"" << m_file << "\" not found !" << oendl;
68 return false; 70 return false;
69 } 71 }
70 72
71 while ( obj ) { 73 while ( obj ) {
72 OPimContact con = parseVObject( obj ); 74 OPimContact con = parseVObject( obj );
73 /* 75 /*
74 * if uid is 0 assign a new one 76 * if uid is 0 assign a new one
75 * this at least happens on 77 * this at least happens on
76 * Nokia6210 78 * Nokia6210
77 */ 79 */
78 if ( con.uid() == 0 ){ 80 if ( con.uid() == 0 ){
79 con.setUid( 1 ); 81 con.setUid( 1 );
80 qWarning("assigned new uid %d",con.uid() ); 82 owarn << "assigned new uid " << con.uid() << "" << oendl;
81 } 83 }
82 84
83 m_map.insert( con.uid(), con ); 85 m_map.insert( con.uid(), con );
84 86
85 VObject *t = obj; 87 VObject *t = obj;
86 obj = nextVObjectInList(obj); 88 obj = nextVObjectInList(obj);
87 cleanVObject( t ); 89 cleanVObject( t );
88 } 90 }
89 91
90 return true; 92 return true;
91 93
92} 94}
@@ -307,25 +309,25 @@ OPimContact OPimContactAccessBackend_VCard::parseVObject( VObject *obj )
307 type |= PAGER; 309 type |= PAGER;
308 else if ( name == VCPreferredProp ) 310 else if ( name == VCPreferredProp )
309 ; 311 ;
310 else 312 else
311 type |= UNKNOWN; 313 type |= UNKNOWN;
312 } 314 }
313 if ( (type & UNKNOWN) != UNKNOWN ) { 315 if ( (type & UNKNOWN) != UNKNOWN ) {
314 if ( ( type & (HOME|WORK) ) == 0 ) // default 316 if ( ( type & (HOME|WORK) ) == 0 ) // default
315 type |= HOME; 317 type |= HOME;
316 if ( ( type & (VOICE|CELL|FAX|PAGER) ) == 0 ) // default 318 if ( ( type & (VOICE|CELL|FAX|PAGER) ) == 0 ) // default
317 type |= VOICE; 319 type |= VOICE;
318 320
319 qWarning("value %s %d", value.data(), type ); 321 owarn << "value " << value.data() << " " << type << "" << oendl;
320 if ( (type & (VOICE|HOME) ) == (VOICE|HOME) && (type & (CELL|HOME) ) != (CELL|HOME) ) 322 if ( (type & (VOICE|HOME) ) == (VOICE|HOME) && (type & (CELL|HOME) ) != (CELL|HOME) )
321 c.setHomePhone( value ); 323 c.setHomePhone( value );
322 if ( ( type & (FAX|HOME) ) == (FAX|HOME) ) 324 if ( ( type & (FAX|HOME) ) == (FAX|HOME) )
323 c.setHomeFax( value ); 325 c.setHomeFax( value );
324 if ( ( type & (CELL|HOME) ) == (CELL|HOME) ) 326 if ( ( type & (CELL|HOME) ) == (CELL|HOME) )
325 c.setHomeMobile( value ); 327 c.setHomeMobile( value );
326 if ( ( type & (VOICE|WORK) ) == (VOICE|WORK) && (type & (CELL|WORK) ) != (CELL|WORK) ) 328 if ( ( type & (VOICE|WORK) ) == (VOICE|WORK) && (type & (CELL|WORK) ) != (CELL|WORK) )
327 c.setBusinessPhone( value ); 329 c.setBusinessPhone( value );
328 if ( ( type & (FAX|WORK) ) == (FAX|WORK) ) 330 if ( ( type & (FAX|WORK) ) == (FAX|WORK) )
329 c.setBusinessFax( value ); 331 c.setBusinessFax( value );
330 if ( ( type & (CELL|WORK) ) == (CELL|WORK) ) 332 if ( ( type & (CELL|WORK) ) == (CELL|WORK) )
331 c.setBusinessMobile( value ); 333 c.setBusinessMobile( value );
@@ -501,44 +503,44 @@ VObject* OPimContactAccessBackend_VCard::createVObject( const OPimContact &c )
501 503
502 QStringList emails = c.emailList(); 504 QStringList emails = c.emailList();
503 // emails.prepend( c.defaultEmail() ); Fix for bugreport #1045 505 // emails.prepend( c.defaultEmail() ); Fix for bugreport #1045
504 for( QStringList::Iterator it = emails.begin(); it != emails.end(); ++it ) { 506 for( QStringList::Iterator it = emails.begin(); it != emails.end(); ++it ) {
505 VObject *email = safeAddPropValue( vcard, VCEmailAddressProp, *it ); 507 VObject *email = safeAddPropValue( vcard, VCEmailAddressProp, *it );
506 safeAddProp( email, VCInternetProp ); 508 safeAddProp( email, VCInternetProp );
507 } 509 }
508 510
509 safeAddPropValue( vcard, VCNoteProp, c.notes() ); 511 safeAddPropValue( vcard, VCNoteProp, c.notes() );
510 512
511 // Exporting Birthday regarding RFC 2425 (5.8.4) 513 // Exporting Birthday regarding RFC 2425 (5.8.4)
512 if ( c.birthday().isValid() ){ 514 if ( c.birthday().isValid() ){
513 qWarning("Exporting birthday as: %s", convDateToVCardDate( c.birthday() ).latin1() ); 515 owarn << "Exporting birthday as: " << convDateToVCardDate( c.birthday() ) << "" << oendl;
514 safeAddPropValue( vcard, VCBirthDateProp, convDateToVCardDate( c.birthday() ) ); 516 safeAddPropValue( vcard, VCBirthDateProp, convDateToVCardDate( c.birthday() ) );
515 } 517 }
516 518
517 if ( !c.company().isEmpty() || !c.department().isEmpty() || !c.office().isEmpty() ) { 519 if ( !c.company().isEmpty() || !c.department().isEmpty() || !c.office().isEmpty() ) {
518 VObject *org = safeAddProp( vcard, VCOrgProp ); 520 VObject *org = safeAddProp( vcard, VCOrgProp );
519 safeAddPropValue( org, VCOrgNameProp, c.company() ); 521 safeAddPropValue( org, VCOrgNameProp, c.company() );
520 safeAddPropValue( org, VCOrgUnitProp, c.department() ); 522 safeAddPropValue( org, VCOrgUnitProp, c.department() );
521 safeAddPropValue( org, VCOrgUnit2Prop, c.office() ); 523 safeAddPropValue( org, VCOrgUnit2Prop, c.office() );
522 } 524 }
523 525
524 // some values we have to export as custom fields 526 // some values we have to export as custom fields
525 safeAddPropValue( vcard, "X-Qtopia-Profession", c.profession() ); 527 safeAddPropValue( vcard, "X-Qtopia-Profession", c.profession() );
526 safeAddPropValue( vcard, "X-Qtopia-Manager", c.manager() ); 528 safeAddPropValue( vcard, "X-Qtopia-Manager", c.manager() );
527 safeAddPropValue( vcard, "X-Qtopia-Assistant", c.assistant() ); 529 safeAddPropValue( vcard, "X-Qtopia-Assistant", c.assistant() );
528 530
529 safeAddPropValue( vcard, "X-Qtopia-Spouse", c.spouse() ); 531 safeAddPropValue( vcard, "X-Qtopia-Spouse", c.spouse() );
530 safeAddPropValue( vcard, "X-Qtopia-Gender", c.gender() ); 532 safeAddPropValue( vcard, "X-Qtopia-Gender", c.gender() );
531 if ( c.anniversary().isValid() ){ 533 if ( c.anniversary().isValid() ){
532 qWarning("Exporting anniversary as: %s", convDateToVCardDate( c.anniversary() ).latin1() ); 534 owarn << "Exporting anniversary as: " << convDateToVCardDate( c.anniversary() ) << "" << oendl;
533 safeAddPropValue( vcard, "X-Qtopia-Anniversary", convDateToVCardDate( c.anniversary() ) ); 535 safeAddPropValue( vcard, "X-Qtopia-Anniversary", convDateToVCardDate( c.anniversary() ) );
534 } 536 }
535 safeAddPropValue( vcard, "X-Qtopia-Nickname", c.nickname() ); 537 safeAddPropValue( vcard, "X-Qtopia-Nickname", c.nickname() );
536 safeAddPropValue( vcard, "X-Qtopia-Children", c.children() ); 538 safeAddPropValue( vcard, "X-Qtopia-Children", c.children() );
537 539
538 return vcard; 540 return vcard;
539} 541}
540 542
541QString OPimContactAccessBackend_VCard::convDateToVCardDate( const QDate& d ) const 543QString OPimContactAccessBackend_VCard::convDateToVCardDate( const QDate& d ) const
542{ 544{
543 QString str_rfc2425 = QString("%1-%2-%3") 545 QString str_rfc2425 = QString("%1-%2-%3")
544 .arg( d.year() ) 546 .arg( d.year() )
@@ -549,39 +551,39 @@ QString OPimContactAccessBackend_VCard::convDateToVCardDate( const QDate& d ) co
549 while ( ( pos = str_rfc2425.find (' ') ) > 0 ) 551 while ( ( pos = str_rfc2425.find (' ') ) > 0 )
550 str_rfc2425.replace( pos, 1, "0" ); 552 str_rfc2425.replace( pos, 1, "0" );
551 553
552 return str_rfc2425; 554 return str_rfc2425;
553} 555}
554 556
555QDate OPimContactAccessBackend_VCard::convVCardDateToDate( const QString& datestr ) 557QDate OPimContactAccessBackend_VCard::convVCardDateToDate( const QString& datestr )
556{ 558{
557 int monthPos = datestr.find('-'); 559 int monthPos = datestr.find('-');
558 int dayPos = datestr.find('-', monthPos+1 ); 560 int dayPos = datestr.find('-', monthPos+1 );
559 int sep_ignore = 1; 561 int sep_ignore = 1;
560 if ( monthPos == -1 || dayPos == -1 ) { 562 if ( monthPos == -1 || dayPos == -1 ) {
561 qDebug("fromString didn't find - in str = %s; mpos = %d ypos = %d", datestr.latin1(), monthPos, dayPos ); 563 odebug << "fromString didn't find - in str = " << datestr << "; mpos = " << monthPos << " ypos = " << dayPos << "" << oendl;
562 // Ok.. No "-" found, therefore we will try to read other format ( YYYYMMDD ) 564 // Ok.. No "-" found, therefore we will try to read other format ( YYYYMMDD )
563 if ( datestr.length() == 8 ){ 565 if ( datestr.length() == 8 ){
564 monthPos = 4; 566 monthPos = 4;
565 dayPos = 6; 567 dayPos = 6;
566 sep_ignore = 0; 568 sep_ignore = 0;
567 qDebug("Try with follwing positions str = %s; mpos = %d ypos = %d", datestr.latin1(), monthPos, dayPos ); 569 odebug << "Try with follwing positions str = " << datestr << "; mpos = " << monthPos << " ypos = " << dayPos << "" << oendl;
568 } else { 570 } else {
569 return QDate(); 571 return QDate();
570 } 572 }
571 } 573 }
572 int y = datestr.left( monthPos ).toInt(); 574 int y = datestr.left( monthPos ).toInt();
573 int m = datestr.mid( monthPos + sep_ignore, dayPos - monthPos - sep_ignore ).toInt(); 575 int m = datestr.mid( monthPos + sep_ignore, dayPos - monthPos - sep_ignore ).toInt();
574 int d = datestr.mid( dayPos + sep_ignore ).toInt(); 576 int d = datestr.mid( dayPos + sep_ignore ).toInt();
575 qDebug("TimeConversion::fromString ymd = %s => %d %d %d; mpos = %d ypos = %d", datestr.latin1(), y, m, d, monthPos, dayPos); 577 odebug << "TimeConversion::fromString ymd = " << datestr << " => " << y << " " << m << " " << d << "; mpos = " << monthPos << " ypos = " << dayPos << "" << oendl;
576 QDate date ( y,m,d ); 578 QDate date ( y,m,d );
577 return date; 579 return date;
578} 580}
579 581
580VObject* OPimContactAccessBackend_VCard::safeAddPropValue( VObject *o, const char *prop, const QString &value ) 582VObject* OPimContactAccessBackend_VCard::safeAddPropValue( VObject *o, const char *prop, const QString &value )
581{ 583{
582 VObject *ret = 0; 584 VObject *ret = 0;
583 if ( o && !value.isEmpty() ) 585 if ( o && !value.isEmpty() )
584 ret = addPropValue( o, prop, value.latin1() ); 586 ret = addPropValue( o, prop, value.latin1() );
585 return ret; 587 return ret;
586} 588}
587 589