-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 @@ -1121,9 +1121,14 @@ static VObject *createVObject( const OContact &c ) } 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() ); @@ -1148,8 +1153,24 @@ static VObject *createVObject( const OContact &c ) /*! \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; @@ -1347,11 +1368,15 @@ static OContact parseVObject( VObject *obj ) 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; @@ -1606,4 +1631,5 @@ 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 @@ -212,9 +212,9 @@ public: 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 ); } @@ -223,9 +223,8 @@ private: 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; @@ -235,8 +234,10 @@ private: const QString &zip, const QString &country ) const; Qtopia::UidGen &uidGen() { return sUidGen; } + + static Qtopia::UidGen sUidGen; QMap<int, QString> mMap; ContactPrivate *d; }; 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 @@ -1121,9 +1121,14 @@ static VObject *createVObject( const OContact &c ) } 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() ); @@ -1148,8 +1153,24 @@ static VObject *createVObject( const OContact &c ) /*! \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; @@ -1347,11 +1368,15 @@ static OContact parseVObject( VObject *obj ) 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; @@ -1606,4 +1631,5 @@ 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 @@ -212,9 +212,9 @@ public: 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 ); } @@ -223,9 +223,8 @@ private: 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; @@ -235,8 +234,10 @@ private: const QString &zip, const QString &country ) const; Qtopia::UidGen &uidGen() { return sUidGen; } + + static Qtopia::UidGen sUidGen; QMap<int, QString> mMap; ContactPrivate *d; }; |