author | zecke <zecke> | 2002-11-02 12:36:34 (UTC) |
---|---|---|
committer | zecke <zecke> | 2002-11-02 12:36:34 (UTC) |
commit | ffd0a764e4ac7f9bf29edf3b9b4d341e153ecf4a (patch) (unidiff) | |
tree | 601ac645a3768c1fe89fce01243f54a24f08dc15 /libopie2/opiepim/ocontact.cpp | |
parent | 74f49994a9c19bdfdbfdfb57a5cf5e1a1f966b53 (diff) | |
download | opie-ffd0a764e4ac7f9bf29edf3b9b4d341e153ecf4a.zip opie-ffd0a764e4ac7f9bf29edf3b9b4d341e153ecf4a.tar.gz opie-ffd0a764e4ac7f9bf29edf3b9b4d341e153ecf4a.tar.bz2 |
Fix a vCard problem in OContact
cell phones do not set the UId property...
add some more states to otodo
Diffstat (limited to 'libopie2/opiepim/ocontact.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r-- | libopie2/opiepim/ocontact.cpp | 41 |
1 files changed, 25 insertions, 16 deletions
diff --git a/libopie2/opiepim/ocontact.cpp b/libopie2/opiepim/ocontact.cpp index acd65c4..cd238ef 100644 --- a/libopie2/opiepim/ocontact.cpp +++ b/libopie2/opiepim/ocontact.cpp | |||
@@ -1124,20 +1124,20 @@ static VObject *createVObject( const OContact &c ) | |||
1124 | 1124 | ||
1125 | safeAddPropValue( vcard, VCNoteProp, c.notes() ); | 1125 | safeAddPropValue( vcard, VCNoteProp, c.notes() ); |
1126 | 1126 | ||
1127 | // Exporting Birthday regarding RFC 2425 (5.8.4) | 1127 | // Exporting Birthday regarding RFC 2425 (5.8.4) |
1128 | if ( c.birthday().isValid() ){ | 1128 | if ( c.birthday().isValid() ){ |
1129 | QString birthd_rfc2425 = QString("%1-%2-%3") | 1129 | QString birthd_rfc2425 = QString("%1-%2-%3") |
1130 | .arg( c.birthday().year() ) | 1130 | .arg( c.birthday().year() ) |
1131 | .arg( c.birthday().month(), 2 ) | 1131 | .arg( c.birthday().month(), 2 ) |
1132 | .arg( c.birthday().day(), 2 ); | 1132 | .arg( c.birthday().day(), 2 ); |
1133 | // Now replace spaces with "0"... | 1133 | // Now replace spaces with "0"... |
1134 | int pos = 0; | 1134 | int pos = 0; |
1135 | while ( ( pos = birthd_rfc2425.find (' ') ) > 0 ) | 1135 | while ( ( pos = birthd_rfc2425.find (' ') ) > 0 ) |
1136 | birthd_rfc2425.replace( pos, 1, "0" ); | 1136 | birthd_rfc2425.replace( pos, 1, "0" ); |
1137 | 1137 | ||
1138 | qWarning("Exporting birthday as: %s", birthd_rfc2425.latin1()); | 1138 | qWarning("Exporting birthday as: %s", birthd_rfc2425.latin1()); |
1139 | safeAddPropValue( vcard, VCBirthDateProp, birthd_rfc2425.latin1() ); | 1139 | safeAddPropValue( vcard, VCBirthDateProp, birthd_rfc2425.latin1() ); |
1140 | } | 1140 | } |
1141 | 1141 | ||
1142 | if ( !c.company().isEmpty() || !c.department().isEmpty() || !c.office().isEmpty() ) { | 1142 | if ( !c.company().isEmpty() || !c.department().isEmpty() || !c.office().isEmpty() ) { |
1143 | VObject *org = safeAddProp( vcard, VCOrgProp ); | 1143 | VObject *org = safeAddProp( vcard, VCOrgProp ); |
@@ -1385,17 +1385,17 @@ static OContact parseVObject( VObject *obj ) | |||
1385 | } | 1385 | } |
1386 | else if ( name == "X-Qtopia-Nickname" ) { | 1386 | else if ( name == "X-Qtopia-Nickname" ) { |
1387 | c.setNickname( value ); | 1387 | c.setNickname( value ); |
1388 | } | 1388 | } |
1389 | else if ( name == "X-Qtopia-Children" ) { | 1389 | else if ( name == "X-Qtopia-Children" ) { |
1390 | c.setChildren( value ); | 1390 | c.setChildren( value ); |
1391 | } | 1391 | } |
1392 | else if ( name == VCBirthDateProp ) { | 1392 | else if ( name == VCBirthDateProp ) { |
1393 | // Reading Birthdate regarding RFC 2425 (5.8.4) | 1393 | // Reading Birthdate regarding RFC 2425 (5.8.4) |
1394 | c.setBirthday( convVCardDateToDate( value ) ); | 1394 | c.setBirthday( convVCardDateToDate( value ) ); |
1395 | 1395 | ||
1396 | } | 1396 | } |
1397 | 1397 | ||
1398 | #if 0 | 1398 | #if 0 |
1399 | else { | 1399 | else { |
1400 | printf("Name: %s, value=%s\n", name.data(), vObjectStringZValue( o ) ); | 1400 | printf("Name: %s, value=%s\n", name.data(), vObjectStringZValue( o ) ); |
1401 | VObjectIterator nit; | 1401 | VObjectIterator nit; |
@@ -1461,13 +1461,22 @@ QValueList<OContact> OContact::readVCard( const QString &filename ) | |||
1461 | 1461 | ||
1462 | qDebug("vobject = %p", obj ); | 1462 | qDebug("vobject = %p", obj ); |
1463 | 1463 | ||
1464 | QValueList<OContact> contacts; | 1464 | QValueList<OContact> contacts; |
1465 | 1465 | ||
1466 | while ( obj ) { | 1466 | while ( obj ) { |
1467 | contacts.append( parseVObject( obj ) ); | 1467 | OContact con = parseVObject( obj ); |
1468 | /* | ||
1469 | * if uid is 0 assign a new one | ||
1470 | * this at least happens on | ||
1471 | * Nokia6210 | ||
1472 | */ | ||
1473 | if ( con.uid() == 0 ) | ||
1474 | con.setUid( 1 ); | ||
1475 | |||
1476 | contacts.append(con ); | ||
1468 | 1477 | ||
1469 | VObject *t = obj; | 1478 | VObject *t = obj; |
1470 | obj = nextVObjectInList(obj); | 1479 | obj = nextVObjectInList(obj); |
1471 | cleanVObject( t ); | 1480 | cleanVObject( t ); |
1472 | } | 1481 | } |
1473 | 1482 | ||
@@ -1524,23 +1533,23 @@ class QString OContact::recordField( int pos ) const | |||
1524 | { | 1533 | { |
1525 | QStringList SLFIELDS = fields(); // ?? why this ? (se) | 1534 | QStringList SLFIELDS = fields(); // ?? why this ? (se) |
1526 | return SLFIELDS[pos]; | 1535 | return SLFIELDS[pos]; |
1527 | } | 1536 | } |
1528 | 1537 | ||
1529 | // In future releases, we should store birthday and anniversary | 1538 | // In future releases, we should store birthday and anniversary |
1530 | // internally as QDate instead of QString ! | 1539 | // internally as QDate instead of QString ! |
1531 | // QString is always too complicate to interprete (DD.MM.YY, DD/MM/YY, MM/DD/YY, etc..)(se) | 1540 | // QString is always too complicate to interprete (DD.MM.YY, DD/MM/YY, MM/DD/YY, etc..)(se) |
1532 | 1541 | ||
1533 | /*! \fn void OContact::setBirthday( const QDate& date ) | 1542 | /*! \fn void OContact::setBirthday( const QDate& date ) |
1534 | Sets the birthday for the contact to \a date. | 1543 | Sets the birthday for the contact to \a date. |
1535 | */ | 1544 | */ |
1536 | void OContact::setBirthday( const QDate &v ) | 1545 | void OContact::setBirthday( const QDate &v ) |
1537 | { | 1546 | { |
1538 | if ( ( !v.isNull() ) && ( v.isValid() ) ) | 1547 | if ( ( !v.isNull() ) && ( v.isValid() ) ) |
1539 | replace( Qtopia::Birthday, TimeConversion::toString( v ) ); | 1548 | replace( Qtopia::Birthday, TimeConversion::toString( v ) ); |
1540 | 1549 | ||
1541 | } | 1550 | } |
1542 | 1551 | ||
1543 | 1552 | ||
1544 | /*! \fn void OContact::setAnniversary( const QDate &date ) | 1553 | /*! \fn void OContact::setAnniversary( const QDate &date ) |
1545 | Sets the anniversary of the contact to \a date. | 1554 | Sets the anniversary of the contact to \a date. |
1546 | */ | 1555 | */ |
@@ -1550,33 +1559,33 @@ void OContact::setAnniversary( const QDate &v ) | |||
1550 | replace( Qtopia::Anniversary, TimeConversion::toString( v ) ); | 1559 | replace( Qtopia::Anniversary, TimeConversion::toString( v ) ); |
1551 | } | 1560 | } |
1552 | 1561 | ||
1553 | /*! \fn QDate OContact::birthday() const | 1562 | /*! \fn QDate OContact::birthday() const |
1554 | Returns the birthday of the contact. | 1563 | Returns the birthday of the contact. |
1555 | */ | 1564 | */ |
1556 | QDate OContact::birthday() const | 1565 | QDate OContact::birthday() const |
1557 | { | 1566 | { |
1558 | QString str = find( Qtopia::Birthday ); | 1567 | QString str = find( Qtopia::Birthday ); |
1559 | qWarning ("Birthday %s", str.latin1() ); | 1568 | qWarning ("Birthday %s", str.latin1() ); |
1560 | if ( !str.isEmpty() ) | 1569 | if ( !str.isEmpty() ) |
1561 | return TimeConversion::fromString ( str ); | 1570 | return TimeConversion::fromString ( str ); |
1562 | else | 1571 | else |
1563 | return QDate(); | 1572 | return QDate(); |
1564 | } | 1573 | } |
1565 | 1574 | ||
1566 | 1575 | ||
1567 | /*! \fn QDate OContact::anniversary() const | 1576 | /*! \fn QDate OContact::anniversary() const |
1568 | Returns the anniversary of the contact. | 1577 | Returns the anniversary of the contact. |
1569 | */ | 1578 | */ |
1570 | QDate OContact::anniversary() const | 1579 | QDate OContact::anniversary() const |
1571 | { | 1580 | { |
1572 | QDate empty; | 1581 | QDate empty; |
1573 | QString str = find( Qtopia::Anniversary ); | 1582 | QString str = find( Qtopia::Anniversary ); |
1574 | qWarning ("Anniversary %s", str.latin1() ); | 1583 | qWarning ("Anniversary %s", str.latin1() ); |
1575 | if ( !str.isEmpty() ) | 1584 | if ( !str.isEmpty() ) |
1576 | return TimeConversion::fromString ( str ); | 1585 | return TimeConversion::fromString ( str ); |
1577 | else | 1586 | else |
1578 | return empty; | 1587 | return empty; |
1579 | } | 1588 | } |
1580 | 1589 | ||
1581 | 1590 | ||
1582 | void OContact::insertEmail( const QString &v ) | 1591 | void OContact::insertEmail( const QString &v ) |
@@ -1604,13 +1613,13 @@ void OContact::insertEmail( const QString &v ) | |||
1604 | void OContact::removeEmail( const QString &v ) | 1613 | void OContact::removeEmail( const QString &v ) |
1605 | { | 1614 | { |
1606 | QString e = v.simplifyWhiteSpace(); | 1615 | QString e = v.simplifyWhiteSpace(); |
1607 | QString def = defaultEmail(); | 1616 | QString def = defaultEmail(); |
1608 | QString emailsStr = find( Qtopia::Emails ); | 1617 | QString emailsStr = find( Qtopia::Emails ); |
1609 | QStringList emails = emailList(); | 1618 | QStringList emails = emailList(); |
1610 | 1619 | ||
1611 | // otherwise, must first contain it | 1620 | // otherwise, must first contain it |
1612 | if ( !emailsStr.contains( e ) ) | 1621 | if ( !emailsStr.contains( e ) ) |
1613 | return; | 1622 | return; |
1614 | 1623 | ||
1615 | // remove it | 1624 | // remove it |
1616 | //qDebug(" removing email from list %s", e.latin1()); | 1625 | //qDebug(" removing email from list %s", e.latin1()); |
@@ -1637,15 +1646,15 @@ void OContact::setDefaultEmail( const QString &v ) | |||
1637 | { | 1646 | { |
1638 | QString e = v.simplifyWhiteSpace(); | 1647 | QString e = v.simplifyWhiteSpace(); |
1639 | 1648 | ||
1640 | //qDebug("OContact::setDefaultEmail %s", e.latin1()); | 1649 | //qDebug("OContact::setDefaultEmail %s", e.latin1()); |
1641 | replace( Qtopia::DefaultEmail, e ); | 1650 | replace( Qtopia::DefaultEmail, e ); |
1642 | 1651 | ||
1643 | if ( !e.isEmpty() ) | 1652 | if ( !e.isEmpty() ) |
1644 | insertEmail( e ); | 1653 | insertEmail( e ); |
1645 | 1654 | ||
1646 | } | 1655 | } |
1647 | 1656 | ||
1648 | void OContact::insertEmails( const QStringList &v ) | 1657 | void OContact::insertEmails( const QStringList &v ) |
1649 | { | 1658 | { |
1650 | for ( QStringList::ConstIterator it = v.begin(); it != v.end(); ++it ) | 1659 | for ( QStringList::ConstIterator it = v.begin(); it != v.end(); ++it ) |
1651 | insertEmail( *it ); | 1660 | insertEmail( *it ); |