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 | 28 | ||||
-rw-r--r-- | libopie/pim/ocontact.h | 3 | ||||
-rw-r--r-- | libopie2/opiepim/ocontact.cpp | 28 | ||||
-rw-r--r-- | libopie2/opiepim/ocontact.h | 3 |
4 files changed, 58 insertions, 4 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 @@ -1123,5 +1123,10 @@ 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() ) { @@ -1150,4 +1155,20 @@ 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 ) { @@ -1350,5 +1371,9 @@ static OContact parseVObject( VObject *obj ) c.setChildren( value ); } + else if ( name == VCBirthDateProp ) { + // Reading Birthdate regarding RFC 2425 (5.8.4) + c.setBirthday( convVCardDateToDate( value ) ); + } #if 0 @@ -1608,2 +1633,3 @@ void OContact::insertEmails( const QStringList &v ) 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 @@ -225,5 +225,4 @@ private: friend class XMLIO; - void insert( int key, const QString &value ); void replace( int key, const QString &value ); @@ -237,4 +236,6 @@ private: Qtopia::UidGen &uidGen() { return sUidGen; } + + static Qtopia::UidGen sUidGen; QMap<int, QString> mMap; 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 @@ -1123,5 +1123,10 @@ 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() ) { @@ -1150,4 +1155,20 @@ 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 ) { @@ -1350,5 +1371,9 @@ static OContact parseVObject( VObject *obj ) c.setChildren( value ); } + else if ( name == VCBirthDateProp ) { + // Reading Birthdate regarding RFC 2425 (5.8.4) + c.setBirthday( convVCardDateToDate( value ) ); + } #if 0 @@ -1608,2 +1633,3 @@ void OContact::insertEmails( const QStringList &v ) 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 @@ -225,5 +225,4 @@ private: friend class XMLIO; - void insert( int key, const QString &value ); void replace( int key, const QString &value ); @@ -237,4 +236,6 @@ private: Qtopia::UidGen &uidGen() { return sUidGen; } + + static Qtopia::UidGen sUidGen; QMap<int, QString> mMap; |