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 | |||
@@ -1118,32 +1118,32 @@ static VObject *createVObject( const OContact &c ) | |||
1118 | QStringList emails = c.emailList(); | 1118 | QStringList emails = c.emailList(); |
1119 | emails.prepend( c.defaultEmail() ); | 1119 | emails.prepend( c.defaultEmail() ); |
1120 | for( QStringList::Iterator it = emails.begin(); it != emails.end(); ++it ) { | 1120 | for( QStringList::Iterator it = emails.begin(); it != emails.end(); ++it ) { |
1121 | VObject *email = safeAddPropValue( vcard, VCEmailAddressProp, *it ); | 1121 | VObject *email = safeAddPropValue( vcard, VCEmailAddressProp, *it ); |
1122 | safeAddProp( email, VCInternetProp ); | 1122 | safeAddProp( email, VCInternetProp ); |
1123 | } | 1123 | } |
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 ); |
1144 | safeAddPropValue( org, VCOrgNameProp, c.company() ); | 1144 | safeAddPropValue( org, VCOrgNameProp, c.company() ); |
1145 | safeAddPropValue( org, VCOrgUnitProp, c.department() ); | 1145 | safeAddPropValue( org, VCOrgUnitProp, c.department() ); |
1146 | safeAddPropValue( org, VCOrgUnit2Prop, c.office() ); | 1146 | safeAddPropValue( org, VCOrgUnit2Prop, c.office() ); |
1147 | } | 1147 | } |
1148 | 1148 | ||
1149 | // some values we have to export as custom fields | 1149 | // some values we have to export as custom fields |
@@ -1379,29 +1379,29 @@ static OContact parseVObject( VObject *obj ) | |||
1379 | } | 1379 | } |
1380 | else if ( name == "X-Qtopia-Gender" ) { | 1380 | else if ( name == "X-Qtopia-Gender" ) { |
1381 | c.setGender( value ); | 1381 | c.setGender( value ); |
1382 | } | 1382 | } |
1383 | else if ( name == "X-Qtopia-Anniversary" ) { | 1383 | else if ( name == "X-Qtopia-Anniversary" ) { |
1384 | c.setAnniversary( TimeConversion::fromString( value ) ); | 1384 | c.setAnniversary( TimeConversion::fromString( value ) ); |
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; |
1402 | initPropIterator( &nit, o ); | 1402 | initPropIterator( &nit, o ); |
1403 | while( moreIteration( &nit ) ) { | 1403 | while( moreIteration( &nit ) ) { |
1404 | VObject *o = nextVObject( &nit ); | 1404 | VObject *o = nextVObject( &nit ); |
1405 | QCString name = vObjectName( o ); | 1405 | QCString name = vObjectName( o ); |
1406 | QString value = vObjectStringZValue( o ); | 1406 | QString value = vObjectStringZValue( o ); |
1407 | printf(" subprop: %s = %s\n", name.data(), value.latin1() ); | 1407 | printf(" subprop: %s = %s\n", name.data(), value.latin1() ); |
@@ -1455,25 +1455,34 @@ void OContact::writeVCard( const QString &filename, const OContact &contact) | |||
1455 | Returns the set of contacts read as VCards from the file \a filename. | 1455 | Returns the set of contacts read as VCards from the file \a filename. |
1456 | */ | 1456 | */ |
1457 | QValueList<OContact> OContact::readVCard( const QString &filename ) | 1457 | QValueList<OContact> OContact::readVCard( const QString &filename ) |
1458 | { | 1458 | { |
1459 | qDebug("trying to open %s, exists=%d", filename.utf8().data(), QFileInfo( filename.utf8().data() ).size() ); | 1459 | qDebug("trying to open %s, exists=%d", filename.utf8().data(), QFileInfo( filename.utf8().data() ).size() ); |
1460 | VObject *obj = Parse_MIME_FromFileName( (char *)filename.utf8().data() ); | 1460 | VObject *obj = Parse_MIME_FromFileName( (char *)filename.utf8().data() ); |
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 | ||
1474 | return contacts; | 1483 | return contacts; |
1475 | } | 1484 | } |
1476 | 1485 | ||
1477 | /*! | 1486 | /*! |
1478 | Returns TRUE if the contact matches the regular expression \a regexp. | 1487 | Returns TRUE if the contact matches the regular expression \a regexp. |
1479 | Otherwise returns FALSE. | 1488 | Otherwise returns FALSE. |
@@ -1518,71 +1527,71 @@ QMap<QString,QString> OContact::toExtraMap() const | |||
1518 | qWarning ("Function not implemented: OContact::toExtraMap()"); | 1527 | qWarning ("Function not implemented: OContact::toExtraMap()"); |
1519 | QMap <QString,QString> useless; | 1528 | QMap <QString,QString> useless; |
1520 | return useless; | 1529 | return useless; |
1521 | } | 1530 | } |
1522 | 1531 | ||
1523 | class QString OContact::recordField( int pos ) const | 1532 | 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 | */ |
1547 | void OContact::setAnniversary( const QDate &v ) | 1556 | void OContact::setAnniversary( const QDate &v ) |
1548 | { | 1557 | { |
1549 | if ( ( !v.isNull() ) && ( v.isValid() ) ) | 1558 | if ( ( !v.isNull() ) && ( v.isValid() ) ) |
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 ) |
1583 | { | 1592 | { |
1584 | //qDebug("insertEmail %s", v.latin1()); | 1593 | //qDebug("insertEmail %s", v.latin1()); |
1585 | QString e = v.simplifyWhiteSpace(); | 1594 | QString e = v.simplifyWhiteSpace(); |
1586 | QString def = defaultEmail(); | 1595 | QString def = defaultEmail(); |
1587 | 1596 | ||
1588 | // if no default, set it as the default email and don't insert | 1597 | // if no default, set it as the default email and don't insert |
@@ -1598,25 +1607,25 @@ void OContact::insertEmail( const QString &v ) | |||
1598 | if ( !emailsStr.isEmpty() ) | 1607 | if ( !emailsStr.isEmpty() ) |
1599 | emailsStr += emailSeparator(); | 1608 | emailsStr += emailSeparator(); |
1600 | emailsStr += e; | 1609 | emailsStr += e; |
1601 | replace( Qtopia::Emails, emailsStr ); | 1610 | replace( Qtopia::Emails, emailsStr ); |
1602 | } | 1611 | } |
1603 | 1612 | ||
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()); |
1617 | emails.remove( e ); | 1626 | emails.remove( e ); |
1618 | // reset the string | 1627 | // reset the string |
1619 | emailsStr = emails.join(emailSeparator()); // Sharp's brain dead separator | 1628 | emailsStr = emails.join(emailSeparator()); // Sharp's brain dead separator |
1620 | replace( Qtopia::Emails, emailsStr ); | 1629 | replace( Qtopia::Emails, emailsStr ); |
1621 | 1630 | ||
1622 | // if default, then replace the default email with the first one | 1631 | // if default, then replace the default email with the first one |
@@ -1631,23 +1640,23 @@ void OContact::removeEmail( const QString &v ) | |||
1631 | void OContact::clearEmails() | 1640 | void OContact::clearEmails() |
1632 | { | 1641 | { |
1633 | mMap.remove( Qtopia::DefaultEmail ); | 1642 | mMap.remove( Qtopia::DefaultEmail ); |
1634 | mMap.remove( Qtopia::Emails ); | 1643 | mMap.remove( Qtopia::Emails ); |
1635 | } | 1644 | } |
1636 | void OContact::setDefaultEmail( const QString &v ) | 1645 | 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 ); |
1652 | } | 1661 | } |
1653 | 1662 | ||