-rw-r--r-- | kabc/addressee.cpp | 3 |
1 files changed, 2 insertions, 1 deletions
diff --git a/kabc/addressee.cpp b/kabc/addressee.cpp index 18b4d58..39d14bb 100644 --- a/kabc/addressee.cpp +++ b/kabc/addressee.cpp | |||
@@ -1434,129 +1434,130 @@ void Addressee::setNameFromString( const QString &str ) | |||
1434 | int rightOffset = parts.count() - 1; | 1434 | int rightOffset = parts.count() - 1; |
1435 | 1435 | ||
1436 | QString suffix; | 1436 | QString suffix; |
1437 | while ( rightOffset >= 0 ) { | 1437 | while ( rightOffset >= 0 ) { |
1438 | if ( suffixes.contains( parts[ rightOffset ] ) ) { | 1438 | if ( suffixes.contains( parts[ rightOffset ] ) ) { |
1439 | suffix.prepend(parts[ rightOffset ] + (suffix.isEmpty() ? "" : " ")); | 1439 | suffix.prepend(parts[ rightOffset ] + (suffix.isEmpty() ? "" : " ")); |
1440 | rightOffset--; | 1440 | rightOffset--; |
1441 | } else | 1441 | } else |
1442 | break; | 1442 | break; |
1443 | } | 1443 | } |
1444 | setSuffix( suffix ); | 1444 | setSuffix( suffix ); |
1445 | 1445 | ||
1446 | if ( rightOffset - 1 >= 0 && prefixes.contains( parts[ rightOffset - 1 ].lower() ) ) { | 1446 | if ( rightOffset - 1 >= 0 && prefixes.contains( parts[ rightOffset - 1 ].lower() ) ) { |
1447 | setFamilyName( parts[ rightOffset - 1 ] + " " + parts[ rightOffset ] ); | 1447 | setFamilyName( parts[ rightOffset - 1 ] + " " + parts[ rightOffset ] ); |
1448 | rightOffset--; | 1448 | rightOffset--; |
1449 | } else | 1449 | } else |
1450 | setFamilyName( parts[ rightOffset ] ); | 1450 | setFamilyName( parts[ rightOffset ] ); |
1451 | 1451 | ||
1452 | QString prefix; | 1452 | QString prefix; |
1453 | while ( leftOffset < rightOffset ) { | 1453 | while ( leftOffset < rightOffset ) { |
1454 | if ( titles.contains( parts[ leftOffset ] ) ) { | 1454 | if ( titles.contains( parts[ leftOffset ] ) ) { |
1455 | prefix.append( ( prefix.isEmpty() ? "" : " ") + parts[ leftOffset ] ); | 1455 | prefix.append( ( prefix.isEmpty() ? "" : " ") + parts[ leftOffset ] ); |
1456 | leftOffset++; | 1456 | leftOffset++; |
1457 | } else | 1457 | } else |
1458 | break; | 1458 | break; |
1459 | } | 1459 | } |
1460 | 1460 | ||
1461 | parts = QStringList::split( " ", part2 ); | 1461 | parts = QStringList::split( " ", part2 ); |
1462 | 1462 | ||
1463 | leftOffset = 0; | 1463 | leftOffset = 0; |
1464 | rightOffset = parts.count(); | 1464 | rightOffset = parts.count(); |
1465 | 1465 | ||
1466 | while ( leftOffset < rightOffset ) { | 1466 | while ( leftOffset < rightOffset ) { |
1467 | if ( titles.contains( parts[ leftOffset ] ) ) { | 1467 | if ( titles.contains( parts[ leftOffset ] ) ) { |
1468 | prefix.append( ( prefix.isEmpty() ? "" : " ") + parts[ leftOffset ] ); | 1468 | prefix.append( ( prefix.isEmpty() ? "" : " ") + parts[ leftOffset ] ); |
1469 | leftOffset++; | 1469 | leftOffset++; |
1470 | } else | 1470 | } else |
1471 | break; | 1471 | break; |
1472 | } | 1472 | } |
1473 | setPrefix( prefix ); | 1473 | setPrefix( prefix ); |
1474 | 1474 | ||
1475 | if ( leftOffset < rightOffset ) { | 1475 | if ( leftOffset < rightOffset ) { |
1476 | setGivenName( parts[ leftOffset ] ); | 1476 | setGivenName( parts[ leftOffset ] ); |
1477 | leftOffset++; | 1477 | leftOffset++; |
1478 | } | 1478 | } |
1479 | 1479 | ||
1480 | QString additionalName; | 1480 | QString additionalName; |
1481 | while ( leftOffset < rightOffset ) { | 1481 | while ( leftOffset < rightOffset ) { |
1482 | additionalName.append( ( additionalName.isEmpty() ? "" : " ") + parts[ leftOffset ] ); | 1482 | additionalName.append( ( additionalName.isEmpty() ? "" : " ") + parts[ leftOffset ] ); |
1483 | leftOffset++; | 1483 | leftOffset++; |
1484 | } | 1484 | } |
1485 | setAdditionalName( additionalName ); | 1485 | setAdditionalName( additionalName ); |
1486 | } | 1486 | } |
1487 | } | 1487 | } |
1488 | 1488 | ||
1489 | QString Addressee::realName() const | 1489 | QString Addressee::realName() const |
1490 | { | 1490 | { |
1491 | if ( !formattedName().isEmpty() ) | 1491 | if ( !formattedName().isEmpty() ) |
1492 | return formattedName(); | 1492 | return formattedName(); |
1493 | 1493 | ||
1494 | QString n = assembledName(); | 1494 | QString n = assembledName(); |
1495 | 1495 | ||
1496 | if ( n.isEmpty() ) | 1496 | if ( n.isEmpty() ) |
1497 | n = name(); | 1497 | n = name(); |
1498 | 1498 | if ( n.isEmpty() ) | |
1499 | n = organization(); | ||
1499 | return n; | 1500 | return n; |
1500 | } | 1501 | } |
1501 | 1502 | ||
1502 | QString Addressee::assembledName() const | 1503 | QString Addressee::assembledName() const |
1503 | { | 1504 | { |
1504 | QString name = prefix() + " " + givenName() + " " + additionalName() + " " + | 1505 | QString name = prefix() + " " + givenName() + " " + additionalName() + " " + |
1505 | familyName() + " " + suffix(); | 1506 | familyName() + " " + suffix(); |
1506 | 1507 | ||
1507 | return name.simplifyWhiteSpace(); | 1508 | return name.simplifyWhiteSpace(); |
1508 | } | 1509 | } |
1509 | 1510 | ||
1510 | QString Addressee::fullEmail( const QString &email ) const | 1511 | QString Addressee::fullEmail( const QString &email ) const |
1511 | { | 1512 | { |
1512 | QString e; | 1513 | QString e; |
1513 | if ( email.isNull() ) { | 1514 | if ( email.isNull() ) { |
1514 | e = preferredEmail(); | 1515 | e = preferredEmail(); |
1515 | } else { | 1516 | } else { |
1516 | e = email; | 1517 | e = email; |
1517 | } | 1518 | } |
1518 | if ( e.isEmpty() ) return QString::null; | 1519 | if ( e.isEmpty() ) return QString::null; |
1519 | 1520 | ||
1520 | QString text; | 1521 | QString text; |
1521 | if ( realName().isEmpty() ) | 1522 | if ( realName().isEmpty() ) |
1522 | text = e; | 1523 | text = e; |
1523 | else | 1524 | else |
1524 | text = assembledName() + " <" + e + ">"; | 1525 | text = assembledName() + " <" + e + ">"; |
1525 | 1526 | ||
1526 | return text; | 1527 | return text; |
1527 | } | 1528 | } |
1528 | 1529 | ||
1529 | void Addressee::insertEmail( const QString &email, bool preferred ) | 1530 | void Addressee::insertEmail( const QString &email, bool preferred ) |
1530 | { | 1531 | { |
1531 | detach(); | 1532 | detach(); |
1532 | 1533 | ||
1533 | QStringList::Iterator it = mData->emails.find( email ); | 1534 | QStringList::Iterator it = mData->emails.find( email ); |
1534 | 1535 | ||
1535 | if ( it != mData->emails.end() ) { | 1536 | if ( it != mData->emails.end() ) { |
1536 | if ( !preferred || it == mData->emails.begin() ) return; | 1537 | if ( !preferred || it == mData->emails.begin() ) return; |
1537 | mData->emails.remove( it ); | 1538 | mData->emails.remove( it ); |
1538 | mData->emails.prepend( email ); | 1539 | mData->emails.prepend( email ); |
1539 | } else { | 1540 | } else { |
1540 | if ( preferred ) { | 1541 | if ( preferred ) { |
1541 | mData->emails.prepend( email ); | 1542 | mData->emails.prepend( email ); |
1542 | } else { | 1543 | } else { |
1543 | mData->emails.append( email ); | 1544 | mData->emails.append( email ); |
1544 | } | 1545 | } |
1545 | } | 1546 | } |
1546 | } | 1547 | } |
1547 | 1548 | ||
1548 | void Addressee::removeEmail( const QString &email ) | 1549 | void Addressee::removeEmail( const QString &email ) |
1549 | { | 1550 | { |
1550 | detach(); | 1551 | detach(); |
1551 | 1552 | ||
1552 | QStringList::Iterator it = mData->emails.find( email ); | 1553 | QStringList::Iterator it = mData->emails.find( email ); |
1553 | if ( it == mData->emails.end() ) return; | 1554 | if ( it == mData->emails.end() ) return; |
1554 | 1555 | ||
1555 | mData->emails.remove( it ); | 1556 | mData->emails.remove( it ); |
1556 | } | 1557 | } |
1557 | 1558 | ||
1558 | QString Addressee::preferredEmail() const | 1559 | QString Addressee::preferredEmail() const |
1559 | { | 1560 | { |
1560 | if ( mData->emails.count() == 0 ) return QString::null; | 1561 | if ( mData->emails.count() == 0 ) return QString::null; |
1561 | else return mData->emails.first(); | 1562 | else return mData->emails.first(); |
1562 | } | 1563 | } |