author | eilers <eilers> | 2002-10-28 13:41:31 (UTC) |
---|---|---|
committer | eilers <eilers> | 2002-10-28 13:41:31 (UTC) |
commit | d033fbaff92f1e8e89a96c69dadda068cf3177cd (patch) (side-by-side diff) | |
tree | d23b6ee600ef7ac095a2ae191ac63436386351f6 | |
parent | 54b9d51694242a1f2e0c1898b05c56114827ca10 (diff) | |
download | opie-d033fbaff92f1e8e89a96c69dadda068cf3177cd.zip opie-d033fbaff92f1e8e89a96c69dadda068cf3177cd.tar.gz opie-d033fbaff92f1e8e89a96c69dadda068cf3177cd.tar.bz2 |
Vcard now exports date in correct format (Regarding RFC 2425).
Vcard now imports birthday..
-rw-r--r-- | libopie/pim/ocontact.cpp | 30 | ||||
-rw-r--r-- | libopie/pim/ocontact.h | 5 | ||||
-rw-r--r-- | libopie2/opiepim/ocontact.cpp | 30 | ||||
-rw-r--r-- | libopie2/opiepim/ocontact.h | 5 |
4 files changed, 62 insertions, 8 deletions
diff --git a/libopie/pim/ocontact.cpp b/libopie/pim/ocontact.cpp index 21fc088..734f5a2 100644 --- a/libopie/pim/ocontact.cpp +++ b/libopie/pim/ocontact.cpp @@ -1093,91 +1093,112 @@ static VObject *createVObject( const OContact &c ) safeAddPropValue( work_adr, VCRegionProp, c.businessState() ); safeAddPropValue( work_adr, VCPostalCodeProp, c.businessZip() ); safeAddPropValue( work_adr, VCCountryNameProp, c.businessCountry() ); VObject *work_phone = safeAddPropValue( vcard, VCTelephoneProp, c.businessPhone() ); safeAddProp( work_phone, VCWorkProp ); work_phone = safeAddPropValue( vcard, VCTelephoneProp, c.businessMobile() ); safeAddProp( work_phone, VCWorkProp ); safeAddProp( work_phone, VCCellularProp ); work_phone = safeAddPropValue( vcard, VCTelephoneProp, c.businessFax() ); safeAddProp( work_phone, VCWorkProp ); safeAddProp( work_phone, VCFaxProp ); work_phone = safeAddPropValue( vcard, VCTelephoneProp, c.businessPager() ); safeAddProp( work_phone, VCWorkProp ); safeAddProp( work_phone, VCPagerProp ); url = safeAddPropValue( vcard, VCURLProp, c.businessWebpage() ); safeAddProp( url, VCWorkProp ); VObject *title = safeAddPropValue( vcard, VCTitleProp, c.jobTitle() ); safeAddProp( title, VCWorkProp ); QStringList emails = c.emailList(); emails.prepend( c.defaultEmail() ); for( QStringList::Iterator it = emails.begin(); it != emails.end(); ++it ) { VObject *email = safeAddPropValue( vcard, VCEmailAddressProp, *it ); safeAddProp( email, VCInternetProp ); } safeAddPropValue( vcard, VCNoteProp, c.notes() ); - safeAddPropValue( vcard, VCBirthDateProp, TimeConversion::toString( c.birthday() ) ); + // Exporting Birthday regarding RFC 2425 (5.8.4) + if ( !c.birthday().isNull() ){ + QString birthd_rfc2425 = c.birthday().year() + QString( "-" ) + c.birthday().month() + QString( "-" ) + c.birthday().day(); + qWarning("Exporting birthday as: %s", birthd_rfc2425.latin1()); + safeAddPropValue( vcard, VCBirthDateProp, birthd_rfc2425.latin1() ); + } if ( !c.company().isEmpty() || !c.department().isEmpty() || !c.office().isEmpty() ) { VObject *org = safeAddProp( vcard, VCOrgProp ); safeAddPropValue( org, VCOrgNameProp, c.company() ); safeAddPropValue( org, VCOrgUnitProp, c.department() ); safeAddPropValue( org, VCOrgUnit2Prop, c.office() ); } // some values we have to export as custom fields safeAddPropValue( vcard, "X-Qtopia-Profession", c.profession() ); safeAddPropValue( vcard, "X-Qtopia-Manager", c.manager() ); safeAddPropValue( vcard, "X-Qtopia-Assistant", c.assistant() ); safeAddPropValue( vcard, "X-Qtopia-Spouse", c.spouse() ); safeAddPropValue( vcard, "X-Qtopia-Gender", c.gender() ); safeAddPropValue( vcard, "X-Qtopia-Anniversary", TimeConversion::toString( c.anniversary() ) ); safeAddPropValue( vcard, "X-Qtopia-Nickname", c.nickname() ); safeAddPropValue( vcard, "X-Qtopia-Children", c.children() ); return vcard; } /*! \internal */ +static QDate convVCardDateToDate( const QString& datestr ) +{ + int monthPos = datestr.find('-'); + int dayPos = datestr.find('-', monthPos+1 ); + if ( monthPos == -1 || dayPos == -1 ) { + qDebug("fromString didn't find - in str = %s; mpos = %d ypos = %d", datestr.latin1(), monthPos, dayPos ); + return QDate(); + } + int y = datestr.left( monthPos ).toInt(); + int m = datestr.mid( monthPos+1, dayPos - monthPos - 1 ).toInt(); + int d = datestr.mid( dayPos+1 ).toInt(); + QDate date ( y,m,d ); + qDebug("TimeConversion::fromString ymd = %s => %d %d %d; mpos = %d ypos = %d", datestr.latin1(), y, m, d, monthPos, dayPos); + return date; +} + static OContact parseVObject( VObject *obj ) { OContact c; VObjectIterator it; initPropIterator( &it, obj ); while( moreIteration( &it ) ) { VObject *o = nextVObject( &it ); QCString name = vObjectName( o ); QCString value = vObjectStringZValue( o ); if ( name == VCNameProp ) { VObjectIterator nit; initPropIterator( &nit, o ); while( moreIteration( &nit ) ) { VObject *o = nextVObject( &nit ); QCString name = vObjectTypeInfo( o ); QString value = vObjectStringZValue( o ); if ( name == VCNamePrefixesProp ) c.setTitle( value ); else if ( name == VCNameSuffixesProp ) c.setSuffix( value ); else if ( name == VCFamilyNameProp ) c.setLastName( value ); else if ( name == VCGivenNameProp ) c.setFirstName( value ); else if ( name == VCAdditionalNamesProp ) c.setMiddleName( value ); } } else if ( name == VCAdrProp ) { bool work = TRUE; // default address is work address QString street; @@ -1319,67 +1340,71 @@ static OContact parseVObject( VObject *obj ) else if ( name == VCOrgUnitProp ) c.setDepartment( value ); else if ( name == VCOrgUnit2Prop ) c.setOffice( value ); } } else if ( name == VCTitleProp ) { c.setJobTitle( value ); } else if ( name == "X-Qtopia-Profession" ) { c.setProfession( value ); } else if ( name == "X-Qtopia-Manager" ) { c.setManager( value ); } else if ( name == "X-Qtopia-Assistant" ) { c.setAssistant( value ); } else if ( name == "X-Qtopia-Spouse" ) { c.setSpouse( value ); } else if ( name == "X-Qtopia-Gender" ) { c.setGender( value ); } else if ( name == "X-Qtopia-Anniversary" ) { c.setAnniversary( TimeConversion::fromString( value ) ); } else if ( name == "X-Qtopia-Nickname" ) { c.setNickname( value ); } else if ( name == "X-Qtopia-Children" ) { c.setChildren( value ); + } + else if ( name == VCBirthDateProp ) { + // Reading Birthdate regarding RFC 2425 (5.8.4) + c.setBirthday( convVCardDateToDate( value ) ); + } - #if 0 else { printf("Name: %s, value=%s\n", name.data(), vObjectStringZValue( o ) ); VObjectIterator nit; initPropIterator( &nit, o ); while( moreIteration( &nit ) ) { VObject *o = nextVObject( &nit ); QCString name = vObjectName( o ); QString value = vObjectStringZValue( o ); printf(" subprop: %s = %s\n", name.data(), value.latin1() ); } } #endif } c.setFileAs(); return c; } /*! Writes the list of \a contacts as a set of VCards to the file \a filename. */ void OContact::writeVCard( const QString &filename, const QValueList<OContact> &contacts) { QFileDirect f( filename.utf8().data() ); if ( !f.open( IO_WriteOnly ) ) { qWarning("Unable to open vcard write"); return; } QValueList<OContact>::ConstIterator it; for( it = contacts.begin(); it != contacts.end(); ++it ) { VObject *obj = createVObject( *it ); @@ -1578,32 +1603,33 @@ void OContact::removeEmail( const QString &v ) // if default, then replace the default email with the first one if ( def == e ) { //qDebug("removeEmail is default; setting new default"); if ( !emails.count() ) clearEmails(); else // setDefaultEmail will remove e from the list setDefaultEmail( emails.first() ); } } void OContact::clearEmails() { mMap.remove( Qtopia::DefaultEmail ); mMap.remove( Qtopia::Emails ); } void OContact::setDefaultEmail( const QString &v ) { QString e = v.simplifyWhiteSpace(); //qDebug("OContact::setDefaultEmail %s", e.latin1()); replace( Qtopia::DefaultEmail, e ); if ( !e.isEmpty() ) insertEmail( e ); } void OContact::insertEmails( const QStringList &v ) { for ( QStringList::ConstIterator it = v.begin(); it != v.end(); ++it ) insertEmail( *it ); } + diff --git a/libopie/pim/ocontact.h b/libopie/pim/ocontact.h index 9e83150..382ab94 100644 --- a/libopie/pim/ocontact.h +++ b/libopie/pim/ocontact.h @@ -184,62 +184,63 @@ public: // other QString notes() const { return find( Qtopia::Notes ); } QString groups() const { return find( Qtopia::Groups ); } QStringList groupList() const; // // custom // const QString &customField( const QString &key ) // { return find( Custom- + key ); } static QStringList fields(); static QStringList trfields(); static QStringList untrfields(); QString toRichText() const; QMap<int, QString> toMap() const; QString field( int key ) const { return find( key ); } // journaling... void saveJournal( journal_action action, const QString &key = QString::null ); void save( QString &buf ) const; void setUid( int i ) { Record::setUid(i); replace( Qtopia::AddressUid , QString::number(i)); } QString toShortText()const; QString OContact::type()const; QMap<QString,QString> OContact::toExtraMap() const; class QString OContact::recordField(int) const; // Why private ? (eilers,se) QString emailSeparator() const { return " "; } - // the emails should be seperated by a comma + // the emails should be seperated by a comma void setEmails( const QString &v ); QString emails() const { return find( Qtopia::Emails ); } private: friend class AbEditor; friend class AbTable; friend class AddressBookAccessPrivate; friend class XMLIO; - void insert( int key, const QString &value ); void replace( int key, const QString &value ); QString find( int key ) const; QString displayAddress( const QString &street, const QString &city, const QString &state, const QString &zip, const QString &country ) const; Qtopia::UidGen &uidGen() { return sUidGen; } + + static Qtopia::UidGen sUidGen; QMap<int, QString> mMap; ContactPrivate *d; }; #endif diff --git a/libopie2/opiepim/ocontact.cpp b/libopie2/opiepim/ocontact.cpp index 21fc088..734f5a2 100644 --- a/libopie2/opiepim/ocontact.cpp +++ b/libopie2/opiepim/ocontact.cpp @@ -1093,91 +1093,112 @@ static VObject *createVObject( const OContact &c ) safeAddPropValue( work_adr, VCRegionProp, c.businessState() ); safeAddPropValue( work_adr, VCPostalCodeProp, c.businessZip() ); safeAddPropValue( work_adr, VCCountryNameProp, c.businessCountry() ); VObject *work_phone = safeAddPropValue( vcard, VCTelephoneProp, c.businessPhone() ); safeAddProp( work_phone, VCWorkProp ); work_phone = safeAddPropValue( vcard, VCTelephoneProp, c.businessMobile() ); safeAddProp( work_phone, VCWorkProp ); safeAddProp( work_phone, VCCellularProp ); work_phone = safeAddPropValue( vcard, VCTelephoneProp, c.businessFax() ); safeAddProp( work_phone, VCWorkProp ); safeAddProp( work_phone, VCFaxProp ); work_phone = safeAddPropValue( vcard, VCTelephoneProp, c.businessPager() ); safeAddProp( work_phone, VCWorkProp ); safeAddProp( work_phone, VCPagerProp ); url = safeAddPropValue( vcard, VCURLProp, c.businessWebpage() ); safeAddProp( url, VCWorkProp ); VObject *title = safeAddPropValue( vcard, VCTitleProp, c.jobTitle() ); safeAddProp( title, VCWorkProp ); QStringList emails = c.emailList(); emails.prepend( c.defaultEmail() ); for( QStringList::Iterator it = emails.begin(); it != emails.end(); ++it ) { VObject *email = safeAddPropValue( vcard, VCEmailAddressProp, *it ); safeAddProp( email, VCInternetProp ); } safeAddPropValue( vcard, VCNoteProp, c.notes() ); - safeAddPropValue( vcard, VCBirthDateProp, TimeConversion::toString( c.birthday() ) ); + // Exporting Birthday regarding RFC 2425 (5.8.4) + if ( !c.birthday().isNull() ){ + QString birthd_rfc2425 = c.birthday().year() + QString( "-" ) + c.birthday().month() + QString( "-" ) + c.birthday().day(); + qWarning("Exporting birthday as: %s", birthd_rfc2425.latin1()); + safeAddPropValue( vcard, VCBirthDateProp, birthd_rfc2425.latin1() ); + } if ( !c.company().isEmpty() || !c.department().isEmpty() || !c.office().isEmpty() ) { VObject *org = safeAddProp( vcard, VCOrgProp ); safeAddPropValue( org, VCOrgNameProp, c.company() ); safeAddPropValue( org, VCOrgUnitProp, c.department() ); safeAddPropValue( org, VCOrgUnit2Prop, c.office() ); } // some values we have to export as custom fields safeAddPropValue( vcard, "X-Qtopia-Profession", c.profession() ); safeAddPropValue( vcard, "X-Qtopia-Manager", c.manager() ); safeAddPropValue( vcard, "X-Qtopia-Assistant", c.assistant() ); safeAddPropValue( vcard, "X-Qtopia-Spouse", c.spouse() ); safeAddPropValue( vcard, "X-Qtopia-Gender", c.gender() ); safeAddPropValue( vcard, "X-Qtopia-Anniversary", TimeConversion::toString( c.anniversary() ) ); safeAddPropValue( vcard, "X-Qtopia-Nickname", c.nickname() ); safeAddPropValue( vcard, "X-Qtopia-Children", c.children() ); return vcard; } /*! \internal */ +static QDate convVCardDateToDate( const QString& datestr ) +{ + int monthPos = datestr.find('-'); + int dayPos = datestr.find('-', monthPos+1 ); + if ( monthPos == -1 || dayPos == -1 ) { + qDebug("fromString didn't find - in str = %s; mpos = %d ypos = %d", datestr.latin1(), monthPos, dayPos ); + return QDate(); + } + int y = datestr.left( monthPos ).toInt(); + int m = datestr.mid( monthPos+1, dayPos - monthPos - 1 ).toInt(); + int d = datestr.mid( dayPos+1 ).toInt(); + QDate date ( y,m,d ); + qDebug("TimeConversion::fromString ymd = %s => %d %d %d; mpos = %d ypos = %d", datestr.latin1(), y, m, d, monthPos, dayPos); + return date; +} + static OContact parseVObject( VObject *obj ) { OContact c; VObjectIterator it; initPropIterator( &it, obj ); while( moreIteration( &it ) ) { VObject *o = nextVObject( &it ); QCString name = vObjectName( o ); QCString value = vObjectStringZValue( o ); if ( name == VCNameProp ) { VObjectIterator nit; initPropIterator( &nit, o ); while( moreIteration( &nit ) ) { VObject *o = nextVObject( &nit ); QCString name = vObjectTypeInfo( o ); QString value = vObjectStringZValue( o ); if ( name == VCNamePrefixesProp ) c.setTitle( value ); else if ( name == VCNameSuffixesProp ) c.setSuffix( value ); else if ( name == VCFamilyNameProp ) c.setLastName( value ); else if ( name == VCGivenNameProp ) c.setFirstName( value ); else if ( name == VCAdditionalNamesProp ) c.setMiddleName( value ); } } else if ( name == VCAdrProp ) { bool work = TRUE; // default address is work address QString street; @@ -1319,67 +1340,71 @@ static OContact parseVObject( VObject *obj ) else if ( name == VCOrgUnitProp ) c.setDepartment( value ); else if ( name == VCOrgUnit2Prop ) c.setOffice( value ); } } else if ( name == VCTitleProp ) { c.setJobTitle( value ); } else if ( name == "X-Qtopia-Profession" ) { c.setProfession( value ); } else if ( name == "X-Qtopia-Manager" ) { c.setManager( value ); } else if ( name == "X-Qtopia-Assistant" ) { c.setAssistant( value ); } else if ( name == "X-Qtopia-Spouse" ) { c.setSpouse( value ); } else if ( name == "X-Qtopia-Gender" ) { c.setGender( value ); } else if ( name == "X-Qtopia-Anniversary" ) { c.setAnniversary( TimeConversion::fromString( value ) ); } else if ( name == "X-Qtopia-Nickname" ) { c.setNickname( value ); } else if ( name == "X-Qtopia-Children" ) { c.setChildren( value ); + } + else if ( name == VCBirthDateProp ) { + // Reading Birthdate regarding RFC 2425 (5.8.4) + c.setBirthday( convVCardDateToDate( value ) ); + } - #if 0 else { printf("Name: %s, value=%s\n", name.data(), vObjectStringZValue( o ) ); VObjectIterator nit; initPropIterator( &nit, o ); while( moreIteration( &nit ) ) { VObject *o = nextVObject( &nit ); QCString name = vObjectName( o ); QString value = vObjectStringZValue( o ); printf(" subprop: %s = %s\n", name.data(), value.latin1() ); } } #endif } c.setFileAs(); return c; } /*! Writes the list of \a contacts as a set of VCards to the file \a filename. */ void OContact::writeVCard( const QString &filename, const QValueList<OContact> &contacts) { QFileDirect f( filename.utf8().data() ); if ( !f.open( IO_WriteOnly ) ) { qWarning("Unable to open vcard write"); return; } QValueList<OContact>::ConstIterator it; for( it = contacts.begin(); it != contacts.end(); ++it ) { VObject *obj = createVObject( *it ); @@ -1578,32 +1603,33 @@ void OContact::removeEmail( const QString &v ) // if default, then replace the default email with the first one if ( def == e ) { //qDebug("removeEmail is default; setting new default"); if ( !emails.count() ) clearEmails(); else // setDefaultEmail will remove e from the list setDefaultEmail( emails.first() ); } } void OContact::clearEmails() { mMap.remove( Qtopia::DefaultEmail ); mMap.remove( Qtopia::Emails ); } void OContact::setDefaultEmail( const QString &v ) { QString e = v.simplifyWhiteSpace(); //qDebug("OContact::setDefaultEmail %s", e.latin1()); replace( Qtopia::DefaultEmail, e ); if ( !e.isEmpty() ) insertEmail( e ); } void OContact::insertEmails( const QStringList &v ) { for ( QStringList::ConstIterator it = v.begin(); it != v.end(); ++it ) insertEmail( *it ); } + diff --git a/libopie2/opiepim/ocontact.h b/libopie2/opiepim/ocontact.h index 9e83150..382ab94 100644 --- a/libopie2/opiepim/ocontact.h +++ b/libopie2/opiepim/ocontact.h @@ -184,62 +184,63 @@ public: // other QString notes() const { return find( Qtopia::Notes ); } QString groups() const { return find( Qtopia::Groups ); } QStringList groupList() const; // // custom // const QString &customField( const QString &key ) // { return find( Custom- + key ); } static QStringList fields(); static QStringList trfields(); static QStringList untrfields(); QString toRichText() const; QMap<int, QString> toMap() const; QString field( int key ) const { return find( key ); } // journaling... void saveJournal( journal_action action, const QString &key = QString::null ); void save( QString &buf ) const; void setUid( int i ) { Record::setUid(i); replace( Qtopia::AddressUid , QString::number(i)); } QString toShortText()const; QString OContact::type()const; QMap<QString,QString> OContact::toExtraMap() const; class QString OContact::recordField(int) const; // Why private ? (eilers,se) QString emailSeparator() const { return " "; } - // the emails should be seperated by a comma + // the emails should be seperated by a comma void setEmails( const QString &v ); QString emails() const { return find( Qtopia::Emails ); } private: friend class AbEditor; friend class AbTable; friend class AddressBookAccessPrivate; friend class XMLIO; - void insert( int key, const QString &value ); void replace( int key, const QString &value ); QString find( int key ) const; QString displayAddress( const QString &street, const QString &city, const QString &state, const QString &zip, const QString &country ) const; Qtopia::UidGen &uidGen() { return sUidGen; } + + static Qtopia::UidGen sUidGen; QMap<int, QString> mMap; ContactPrivate *d; }; #endif |