23 #include <QtCore/QList>
24 #include <QtCore/QRegExp>
25 #include <QtCore/QSharedData>
26 #include <QtCore/QUuid>
30 #include <klocalizedstring.h>
32 #include "addresseehelper.h"
34 #ifndef KDEPIM_NO_KRESOURCES
39 #include "addressee.h"
43 static bool matchBinaryPattern(
int value,
int pattern );
46 static bool listEquals(
const QList<L>&,
const QList<L>& );
47 static bool listEquals(
const QStringList&,
const QStringList& );
48 static bool emailsEquals(
const QStringList&,
const QStringList& );
50 class Addressee::Private :
public QSharedData
54 : mUid( QUuid::createUuid().
toString() ),
55 #ifndef KDEPIM_NO_KRESOURCES
58 mEmpty( true ), mChanged( false )
62 Private(
const Private &other )
63 : QSharedData( other )
64 #ifndef KDEPIM_NO_KRESOURCES
70 mFormattedName = other.mFormattedName;
71 mFamilyName = other.mFamilyName;
72 mGivenName = other.mGivenName;
73 mAdditionalName = other.mAdditionalName;
74 mPrefix = other.mPrefix;
75 mSuffix = other.mSuffix;
76 mNickName = other.mNickName;
77 mBirthday = other.mBirthday;
78 mMailer = other.mMailer;
79 mTimeZone = other.mTimeZone;
81 mTitle = other.mTitle;
83 mOrganization = other.mOrganization;
84 mDepartment = other.mDepartment;
86 mProductId = other.mProductId;
87 mRevision = other.mRevision;
88 mSortString = other.mSortString;
90 mSecrecy = other.mSecrecy;
92 mPhoto = other.mPhoto;
93 mSound = other.mSound;
95 mPhoneNumbers = other.mPhoneNumbers;
96 mAddresses = other.mAddresses;
98 mEmails = other.mEmails;
99 mCategories = other.mCategories;
100 mCustomFields = other.mCustomFields;
102 #ifndef KDEPIM_NO_KRESOURCES
103 mResource = other.mResource;
105 mEmpty = other.mEmpty;
106 mChanged = other.mChanged;
115 QString mFormattedName;
118 QString mAdditionalName;
128 QString mOrganization;
144 QStringList mCategories;
145 QMap<QString, QString> mCustomFields;
147 #ifndef KDEPIM_NO_KRESOURCES
175 if (
this != &other )
183 if ( d->mUid != addressee.d->mUid ) {
184 kDebug() <<
"uid differs";
188 if ( d->mName != addressee.d->mName &&
189 !( d->mName.isEmpty() && addressee.d->mName.isEmpty() ) ) {
190 kDebug(5700) <<
"name differs";
194 if ( d->mFormattedName != addressee.d->mFormattedName &&
195 !( d->mFormattedName.isEmpty() && addressee.d->mFormattedName.isEmpty() ) ) {
196 kDebug(5700) <<
"formattedName differs";
200 if ( d->mFamilyName != addressee.d->mFamilyName &&
201 !( d->mFamilyName.isEmpty() && addressee.d->mFamilyName.isEmpty() ) ) {
202 kDebug(5700) <<
"familyName differs";
206 if ( d->mGivenName != addressee.d->mGivenName &&
207 !( d->mGivenName.isEmpty() && addressee.d->mGivenName.isEmpty() ) ) {
208 kDebug(5700) <<
"givenName differs";
212 if ( d->mAdditionalName != addressee.d->mAdditionalName &&
213 !( d->mAdditionalName.isEmpty() && addressee.d->mAdditionalName.isEmpty() ) ) {
214 kDebug(5700) <<
"additionalName differs";
218 if ( d->mPrefix != addressee.d->mPrefix &&
219 !( d->mPrefix.isEmpty() && addressee.d->mPrefix.isEmpty() ) ) {
220 kDebug(5700) <<
"prefix differs";
224 if ( d->mSuffix != addressee.d->mSuffix &&
225 !( d->mSuffix.isEmpty() && addressee.d->mSuffix.isEmpty() ) ) {
226 kDebug(5700) <<
"suffix differs";
230 if ( d->mNickName != addressee.d->mNickName &&
231 !( d->mNickName.isEmpty() && addressee.d->mNickName.isEmpty() ) ) {
232 kDebug(5700) <<
"nickName differs";
236 if ( d->mBirthday != addressee.d->mBirthday ) {
237 kDebug(5700) <<
"birthday differs";
241 if ( d->mMailer != addressee.d->mMailer &&
242 !( d->mMailer.isEmpty() && addressee.d->mMailer.isEmpty() ) ) {
243 kDebug(5700) <<
"mailer differs";
247 if ( d->mTimeZone != addressee.d->mTimeZone ) {
248 kDebug(5700) <<
"timeZone differs";
252 if ( d->mGeo != addressee.d->mGeo ) {
253 kDebug(5700) <<
"geo differs";
257 if ( d->mTitle != addressee.d->mTitle &&
258 !( d->mTitle.isEmpty() && addressee.d->mTitle.isEmpty() ) ) {
259 kDebug(5700) <<
"title differs";
263 if ( d->mRole != addressee.d->mRole &&
264 !( d->mRole.isEmpty() && addressee.d->mRole.isEmpty() ) ) {
265 kDebug(5700) <<
"role differs";
269 if ( d->mOrganization != addressee.d->mOrganization &&
270 !( d->mOrganization.isEmpty() && addressee.d->mOrganization.isEmpty() ) ) {
271 kDebug(5700) <<
"organization differs";
275 if ( d->mDepartment != addressee.d->mDepartment &&
276 !( d->mDepartment.isEmpty() && addressee.d->mDepartment.isEmpty() ) ) {
277 kDebug(5700) <<
"department differs";
281 if ( d->mNote != addressee.d->mNote &&
282 !( d->mNote.isEmpty() && addressee.d->mNote.isEmpty() ) ) {
283 kDebug(5700) <<
"note differs";
287 if ( d->mProductId != addressee.d->mProductId &&
288 !( d->mProductId.isEmpty() && addressee.d->mProductId.isEmpty() ) ) {
289 kDebug(5700) <<
"productId differs";
293 if ( d->mSortString != addressee.d->mSortString &&
294 !( d->mSortString.isEmpty() && addressee.d->mSortString.isEmpty() ) ) {
295 kDebug(5700) <<
"sortString differs";
299 if ( d->mSecrecy != addressee.d->mSecrecy ) {
300 kDebug(5700) <<
"secrecy differs";
304 if ( d->mLogo != addressee.d->mLogo ) {
305 kDebug(5700) <<
"logo differs";
309 if ( d->mPhoto != addressee.d->mPhoto ) {
310 kDebug(5700) <<
"photo differs";
314 if ( d->mSound != addressee.d->mSound ) {
315 kDebug(5700) <<
"sound differs";
319 if ( ( d->mUrl.isValid() || addressee.d->mUrl.isValid() ) &&
320 ( d->mUrl != addressee.d->mUrl ) ) {
321 kDebug() <<
"url differs";
325 if ( !listEquals( d->mPhoneNumbers, addressee.d->mPhoneNumbers ) ) {
326 kDebug() <<
"phoneNumbers differs";
330 if ( !listEquals( d->mAddresses, addressee.d->mAddresses ) ) {
331 kDebug() <<
"addresses differs";
335 if ( !listEquals( d->mKeys, addressee.d->mKeys ) ) {
336 kDebug() <<
"keys differs";
340 if ( !emailsEquals( d->mEmails, addressee.d->mEmails ) ) {
341 kDebug() <<
"emails differs";
345 if ( !listEquals( d->mCategories, addressee.d->mCategories ) ) {
346 kDebug() <<
"categories differs";
350 if ( d->mCustomFields != addressee.d->mCustomFields ) {
351 kDebug() <<
"custom differs";
360 return !( a == *this );
384 return i18n(
"Unique Identifier" );
389 if ( name == d->mName )
403 return i18n(
"Name" );
409 if ( formattedName == d->mFormattedName )
418 return d->mFormattedName;
423 return i18n(
"Formatted Name" );
429 if ( familyName == d->mFamilyName )
438 return d->mFamilyName;
443 return i18n(
"Family Name" );
449 if ( givenName == d->mGivenName )
458 return d->mGivenName;
463 return i18n(
"Given Name" );
469 if ( additionalName == d->mAdditionalName )
478 return d->mAdditionalName;
483 return i18n(
"Additional Names" );
489 if ( prefix == d->mPrefix )
503 return i18n(
"Honorific Prefixes" );
509 if ( suffix == d->mSuffix )
523 return i18n(
"Honorific Suffixes" );
529 if ( nickName == d->mNickName )
543 return i18n(
"Nick Name" );
549 if ( birthday == d->mBirthday )
563 return i18n(
"Birthday" );
569 return i18n(
"Home Address Street" );
575 return i18n(
"Home Address Post Office Box" );
581 return i18n(
"Home Address City" );
587 return i18n(
"Home Address State" );
593 return i18n(
"Home Address Zip Code" );
599 return i18n(
"Home Address Country" );
605 return i18n(
"Home Address Label" );
611 return i18n(
"Business Address Street" );
617 return i18n(
"Business Address Post Office Box" );
623 return i18n(
"Business Address City" );
629 return i18n(
"Business Address State" );
635 return i18n(
"Business Address Zip Code" );
641 return i18n(
"Business Address Country" );
647 return i18n(
"Business Address Label" );
653 return i18n(
"Home Phone" );
659 return i18n(
"Business Phone" );
665 return i18n(
"Mobile Phone" );
671 return i18n(
"Home Fax" );
677 return i18n(
"Business Fax" );
683 return i18n(
"Car Phone" );
689 return i18n(
"ISDN" );
695 return i18n(
"Pager" );
701 return i18n(
"Email Address" );
707 if ( mailer == d->mMailer )
721 return i18n(
"Mail Client" );
727 if ( timeZone == d->mTimeZone )
741 return i18n(
"Time Zone" );
747 if ( geo == d->mGeo )
761 return i18n(
"Geographic Position" );
767 if ( title == d->mTitle )
781 return i18nc(
"a person's title",
"Title" );
787 if ( role == d->mRole )
801 return i18nc(
"of a person in an organization",
"Role" );
807 if ( organization == d->mOrganization )
816 return d->mOrganization;
821 return i18n(
"Organization" );
827 if ( department == d->mDepartment )
836 return d->mDepartment;
841 return i18n(
"Department" );
847 if ( note == d->mNote )
861 return i18n(
"Note" );
867 if ( productId == d->mProductId )
876 return d->mProductId;
881 return i18n(
"Product Identifier" );
887 if ( revision == d->mRevision )
901 return i18n(
"Revision Date" );
907 if ( sortString == d->mSortString )
916 return d->mSortString;
921 return i18n(
"Sort String" );
927 if ( url == d->mUrl )
941 return i18n(
"Homepage" );
947 if ( secrecy == d->mSecrecy )
961 return i18n(
"Security Class" );
967 if ( logo == d->mLogo )
981 return i18n(
"Logo" );
987 if ( photo == d->mPhoto )
1001 return i18n(
"Photo" );
1007 if ( sound == d->mSound )
1021 return i18n(
"Sound" );
1029 if ( str.length() > 1 &&
1030 s[ 0 ] == QLatin1Char(
'"' ) &&
1031 s[ s.length() - 1 ] == QLatin1Char(
'"' ) ) {
1032 str = s.mid( 1, s.length() - 2 );
1045 if ( str.isEmpty() )
1048 static QString spaceStr = QString::fromLatin1(
" " );
1049 static QString emptyStr = QString::fromLatin1(
"" );
1052 int i = str.indexOf( QLatin1Char(
',' ) );
1054 QStringList parts = str.split( spaceStr );
1056 int rightOffset = parts.count() - 1;
1059 while ( rightOffset >= 0 ) {
1061 suffix.prepend( parts[ rightOffset ] + ( suffix.isEmpty() ? emptyStr : spaceStr ) );
1068 if ( rightOffset < 0 )
1071 if ( rightOffset - 1 >= 0 && helper->
containsPrefix( parts[ rightOffset - 1 ].toLower() ) ) {
1072 setFamilyName( parts[ rightOffset - 1 ] + spaceStr + parts[ rightOffset ] );
1082 while ( leftOffset < rightOffset ) {
1084 prefix.append( ( prefix.isEmpty() ? emptyStr : spaceStr ) + parts[ leftOffset ] );
1091 if ( leftOffset < rightOffset ) {
1097 while ( leftOffset < rightOffset ) {
1098 additionalName.append( ( additionalName.isEmpty() ? emptyStr : spaceStr ) + parts[ leftOffset ] );
1103 QString part1 = str.left( i );
1104 QString part2 = str.mid( i + 1 );
1106 QStringList parts = part1.split( spaceStr );
1108 int rightOffset = parts.count() - 1;
1110 if ( parts.count() > 0 ) {
1113 while ( rightOffset >= 0 ) {
1115 suffix.prepend( parts[ rightOffset ] + ( suffix.isEmpty() ? emptyStr : spaceStr ) );
1122 if ( rightOffset - 1 >= 0 && helper->
containsPrefix( parts[ rightOffset - 1 ].toLower() ) ) {
1123 setFamilyName( parts[ rightOffset - 1 ] + spaceStr + parts[ rightOffset ] );
1129 while ( leftOffset < rightOffset ) {
1131 prefix.append( ( prefix.isEmpty() ? emptyStr : spaceStr ) + parts[ leftOffset ] );
1142 parts = part2.split( spaceStr );
1145 rightOffset = parts.count();
1147 if ( parts.count() > 0 ) {
1150 while ( leftOffset < rightOffset ) {
1152 prefix.append( ( prefix.isEmpty() ? emptyStr : spaceStr ) + parts[ leftOffset ] );
1159 if ( leftOffset < rightOffset ) {
1165 while ( leftOffset < rightOffset ) {
1166 additionalName.append( ( additionalName.isEmpty() ? emptyStr : spaceStr ) + parts[ leftOffset ] );
1196 const QString
name =
prefix() + QLatin1Char(
' ' ) +
1202 return name.simplified();
1208 if ( email.isNull() ) {
1213 if ( e.isEmpty() )
return QString();
1219 QRegExp needQuotes( QLatin1String(
"[^ 0-9A-Za-z\\x0080-\\xFFFF]" ) );
1220 if (
realName().indexOf( needQuotes ) != -1 ) {
1222 name.replace( QLatin1String(
"\"" ), QLatin1String(
"\\\"" ) );
1223 text = QLatin1String(
"\"" ) + name + QLatin1String(
"\" <" ) + e + QLatin1Char(
'>' );
1225 text =
realName() + QLatin1String(
" <" ) + e + QLatin1Char(
'>' );
1233 if ( email.simplified().isEmpty() )
1236 if ( d->mEmails.contains( email ) ) {
1237 if ( !preferred || d->mEmails.first() == email )
1240 d->mEmails.removeAll( email );
1241 d->mEmails.prepend( email );
1245 d->mEmails.prepend( email );
1247 d->mEmails.append( email );
1254 if ( d->mEmails.contains( email ) ) {
1255 d->mEmails.removeAll( email );
1261 if ( d->mEmails.count() == 0 )
1264 return d->mEmails.first();
1280 PhoneNumber::List::Iterator it;
1281 for ( it = d->mPhoneNumbers.begin(); it != d->mPhoneNumbers.end(); ++it ) {
1282 if ( ( *it ).id() == phoneNumber.
id() ) {
1287 if ( !phoneNumber.
number().simplified().isEmpty() )
1288 d->mPhoneNumbers.append( phoneNumber );
1293 PhoneNumber::List::Iterator it;
1294 for ( it = d->mPhoneNumbers.begin(); it != d->mPhoneNumbers.end(); ++it ) {
1295 if ( ( *it ).id() == phoneNumber.
id() ) {
1296 d->mPhoneNumbers.erase( it );
1305 PhoneNumber::List::ConstIterator it;
1306 for ( it = d->mPhoneNumbers.constBegin(); it != d->mPhoneNumbers.constEnd(); ++it ) {
1307 if ( matchBinaryPattern( ( *it ).type(), type ) ) {
1310 }
else if ( phoneNumber.
number().isEmpty() ) {
1311 phoneNumber = ( *it );
1321 return d->mPhoneNumbers;
1328 PhoneNumber::List::ConstIterator it;
1329 PhoneNumber::List::ConstIterator end( d->mPhoneNumbers.constEnd() );
1330 for ( it = d->mPhoneNumbers.constBegin(); it != end; ++it ) {
1331 if ( matchBinaryPattern( ( *it ).type(), type ) ) {
1340 PhoneNumber::List::ConstIterator it;
1341 PhoneNumber::List::ConstIterator end( d->mPhoneNumbers.constEnd() );
1342 for ( it = d->mPhoneNumbers.constBegin(); it != end; ++it ) {
1343 if ( ( *it ).id() == id ) {
1354 Key::List::Iterator it;
1355 for ( it = d->mKeys.begin(); it != d->mKeys.end(); ++it ) {
1356 if ( ( *it ).id() == key.
id() ) {
1361 d->mKeys.append( key );
1366 Key::List::Iterator it;
1367 for ( it = d->mKeys.begin(); it != d->mKeys.end(); ++it ) {
1368 if ( ( *it ).id() == key.
id() ) {
1369 d->mKeys.removeAll( key );
1377 Key::List::ConstIterator it;
1378 Key::List::ConstIterator end( d->mKeys.constEnd() );
1379 for ( it = d->mKeys.constBegin(); it != end; ++it ) {
1380 if ( ( *it ).type() == type ) {
1382 if ( customTypeString.isEmpty() ) {
1385 if ( ( *it ).customTypeString() == customTypeString )
1393 return Key( QString(), type );
1410 Key::List::ConstIterator it;
1411 Key::List::ConstIterator end( d->mKeys.constEnd() );
1412 for ( it = d->mKeys.constBegin(); it != end; ++it ) {
1413 if ( ( *it ).type() == type ) {
1415 if ( customTypeString.isEmpty() ) {
1418 if ( ( *it ).customTypeString() == customTypeString )
1431 Key::List::ConstIterator it;
1432 Key::List::ConstIterator end( d->mKeys.constEnd() );
1433 for ( it = d->mKeys.constBegin(); it != end; ++it ) {
1434 if ( ( *it ).id() == id ) {
1445 str += QLatin1String(
"Addressee {\n" );
1446 str += QString::fromLatin1(
" Uid: %1\n" ).arg(
uid() );
1448 str += QString::fromLatin1(
" Name: %1\n" ).arg(
name() );
1449 str += QString::fromLatin1(
" FormattedName: %1\n" ).arg(
formattedName() );
1450 str += QString::fromLatin1(
" FamilyName: %1\n" ).arg(
familyName() );
1451 str += QString::fromLatin1(
" GivenName: %1\n" ).arg(
givenName() );
1452 str += QString::fromLatin1(
" AdditionalName: %1\n" ).arg(
additionalName() );
1453 str += QString::fromLatin1(
" Prefix: %1\n" ).arg(
prefix() );
1454 str += QString::fromLatin1(
" Suffix: %1\n" ).arg(
suffix() );
1455 str += QString::fromLatin1(
" NickName: %1\n" ).arg(
nickName() );
1456 str += QString::fromLatin1(
" Birthday: %1\n" ).arg(
birthday().
toString() );
1457 str += QString::fromLatin1(
" Mailer: %1\n" ).arg(
mailer() );
1458 str += QString::fromLatin1(
" TimeZone: %1\n" ).arg(
timeZone().
toString() );
1459 str += QString::fromLatin1(
" Geo: %1\n" ).arg(
geo().
toString() );
1460 str += QString::fromLatin1(
" Title: %1\n" ).arg(
title() );
1461 str += QString::fromLatin1(
" Role: %1\n" ).arg(
role() );
1462 str += QString::fromLatin1(
" Organization: %1\n" ).arg(
organization() );
1463 str += QString::fromLatin1(
" Department: %1\n" ).arg(
department() );
1464 str += QString::fromLatin1(
" Note: %1\n" ).arg(
note() );
1465 str += QString::fromLatin1(
" ProductId: %1\n" ).arg(
productId() );
1466 str += QString::fromLatin1(
" Revision: %1\n" ).arg(
revision().
toString() );
1467 str += QString::fromLatin1(
" SortString: %1\n" ).arg(
sortString() );
1468 str += QString::fromLatin1(
" Url: %1\n" ).arg(
url().
url() );
1469 str += QString::fromLatin1(
" Secrecy: %1\n" ).arg(
secrecy().
toString() );
1470 str += QString::fromLatin1(
" Logo: %1\n" ).arg(
logo().
toString() );
1471 str += QString::fromLatin1(
" Photo: %1\n" ).arg(
photo().
toString() );
1472 str += QString::fromLatin1(
" Sound: %1\n" ).arg(
sound().
toString() );
1474 str += QLatin1String(
" Emails {\n" );
1475 const QStringList e =
emails();
1476 QStringList::ConstIterator it;
1477 for ( it = e.begin(); it != e.end(); ++it ) {
1478 str += QString::fromLatin1(
" %1\n" ).arg( *it );
1480 str += QLatin1String(
" }\n" );
1482 str += QLatin1String(
" PhoneNumbers {\n" );
1484 PhoneNumber::List::ConstIterator it2;
1485 for ( it2 = p.begin(); it2 != p.end(); ++it2 ) {
1486 str += ( *it2 ).toString();
1488 str += QLatin1String(
" }\n" );
1490 str += QLatin1String(
" Addresses {\n" );
1492 Address::List::ConstIterator it3;
1493 for ( it3 = a.begin(); it3 != a.end(); ++it3 ) {
1494 str += ( *it3 ).toString();
1496 str += QLatin1String(
" }\n" );
1498 str += QLatin1String(
" Keys {\n" );
1500 Key::List::ConstIterator it4;
1501 for ( it4 = k.begin(); it4 != k.end(); ++it4 ) {
1502 str += ( *it4 ).toString();
1504 str += QLatin1String(
" }\n" );
1506 str += QLatin1String(
"}\n" );
1519 Address::List::Iterator it;
1520 for ( it = d->mAddresses.begin(); it != d->mAddresses.end(); ++it ) {
1521 if ( ( *it ).id() == address.
id() ) {
1527 d->mAddresses.append( address );
1532 Address::List::Iterator it;
1533 for ( it = d->mAddresses.begin(); it != d->mAddresses.end(); ++it ) {
1534 if ( ( *it ).id() == address.
id() ) {
1535 d->mAddresses.erase( it );
1544 Address::List::ConstIterator it;
1545 Address::List::ConstIterator end( d->mAddresses.constEnd() );
1546 for ( it = d->mAddresses.constBegin(); it != end; ++it ) {
1547 if ( matchBinaryPattern( ( *it ).type(), type ) ) {
1550 }
else if ( address.
isEmpty() ) {
1561 return d->mAddresses;
1568 Address::List::ConstIterator it;
1569 Address::List::ConstIterator end( d->mAddresses.constEnd() );
1570 for ( it = d->mAddresses.constBegin(); it != end; ++it ) {
1571 if ( matchBinaryPattern( ( *it ).type(), type ) ) {
1581 Address::List::ConstIterator it;
1582 Address::List::ConstIterator end( d->mAddresses.constEnd() );
1583 for ( it = d->mAddresses.constBegin(); it != end; ++it ) {
1584 if ( ( *it ).id() == id ) {
1595 if ( d->mCategories.contains( c ) )
1598 d->mCategories.append( c );
1603 if ( d->mCategories.contains( category ) ) {
1604 d->mCategories.removeAll( category );
1610 return d->mCategories.contains( category );
1622 return d->mCategories;
1626 const QString &value )
1628 if ( value.isEmpty() || name.isEmpty() || app.isEmpty() ) {
1634 const QString qualifiedName = app + QLatin1Char(
'-' ) +
name;
1636 d->mCustomFields.insert( qualifiedName, value );
1641 const QString qualifiedName = app + QLatin1Char(
'-' ) +
name;
1643 d->mCustomFields.remove( qualifiedName );
1648 const QString qualifiedName = app + QLatin1Char(
'-' ) +
name;
1650 return d->mCustomFields.value( qualifiedName );
1657 d->mCustomFields.clear();
1659 foreach (
const QString &
custom, customs ) {
1660 const int index = custom.indexOf( QLatin1Char(
':' ) );
1664 const QString qualifiedName = custom.left( index );
1665 const QString value = custom.mid( index + 1 );
1667 d->mCustomFields.insert( qualifiedName, value );
1675 QMapIterator<QString, QString> it( d->mCustomFields );
1676 while ( it.hasNext() ) {
1678 result << it.key() + QLatin1Char(
':' ) + it.value();
1691 if ( rawEmail.isEmpty() )
1695 QByteArray
address = rawEmail.toUtf8();
1697 QByteArray displayName;
1698 QByteArray addrSpec;
1705 enum { TopLevel, InComment, InAngleAddress } context = TopLevel;
1706 bool inQuotedString =
false;
1707 int commentLevel = 0;
1710 for (
char* p = address.data(); *p && !stop; ++p ) {
1711 switch ( context ) {
1714 case '"' : inQuotedString = !inQuotedString;
1717 case '(' :
if ( !inQuotedString ) {
1718 context = InComment;
1724 case '<' :
if ( !inQuotedString ) {
1725 context = InAngleAddress;
1739 case ',' :
if ( !inQuotedString ) {
1749 default : displayName += *p;
1755 case '(' : ++commentLevel;
1758 case ')' : --commentLevel;
1759 if ( commentLevel == 0 ) {
1775 default : comment += *p;
1779 case InAngleAddress : {
1781 case '"' : inQuotedString = !inQuotedString;
1784 case '>' :
if ( !inQuotedString ) {
1799 default : addrSpec += *p;
1807 displayName = displayName.trimmed();
1808 comment = comment.trimmed();
1809 addrSpec = addrSpec.trimmed();
1811 fullName = QString::fromUtf8( displayName );
1812 email = QString::fromUtf8( addrSpec );
1815 if ( inQuotedString )
1817 if ( context == InComment )
1819 if ( context == InAngleAddress )
1822 if ( addrSpec.isEmpty() ) {
1823 if ( displayName.isEmpty() )
1830 fullName = QString::fromUtf8( comment );
1834 email = email.toLower();
1837 unsigned int len = fullName.length();
1838 if ( fullName[ 0 ] == QLatin1Char(
'"' ) && fullName[ len - 1 ] == QLatin1Char(
'"' ) ) {
1839 fullName = fullName.mid( 1, len - 2 );
1843 #ifndef KDEPIM_NO_KRESOURCES
1851 return d->mResource;
1857 d->mChanged = value;
1867 Private::mSortMode = mode;
1872 if ( !Private::mSortMode )
1875 return Private::mSortMode->lesser( *
this, addr );
1880 return QLatin1String(
"text/directory" );
1883 QDataStream &KABC::operator<<( QDataStream &s,
const Addressee &a )
1888 s << a.d->mFormattedName;
1889 s << a.d->mFamilyName;
1890 s << a.d->mGivenName;
1891 s << a.d->mAdditionalName;
1894 s << a.d->mNickName;
1895 s << a.d->mBirthday;
1897 s << a.d->mTimeZone;
1901 s << a.d->mOrganization;
1902 s << a.d->mDepartment;
1904 s << a.d->mProductId;
1905 s << a.d->mRevision;
1906 s << a.d->mSortString;
1912 s << a.d->mPhoneNumbers;
1913 s << a.d->mAddresses;
1915 s << a.d->mCategories;
1921 QDataStream &KABC::operator>>( QDataStream &s,
Addressee &a )
1926 s >> a.d->mFormattedName;
1927 s >> a.d->mFamilyName;
1928 s >> a.d->mGivenName;
1929 s >> a.d->mAdditionalName;
1932 s >> a.d->mNickName;
1933 s >> a.d->mBirthday;
1935 s >> a.d->mTimeZone;
1939 s >> a.d->mOrganization;
1940 s >> a.d->mDepartment;
1942 s >> a.d->mProductId;
1943 s >> a.d->mRevision;
1944 s >> a.d->mSortString;
1950 s >> a.d->mPhoneNumbers;
1951 s >> a.d->mAddresses;
1953 s >> a.d->mCategories;
1954 QStringList customFields;
1959 a.d->mEmpty =
false;
1964 bool matchBinaryPattern(
int value,
int pattern )
1973 return ( value == 0 );
1975 return ( pattern == ( pattern & value ) );
1979 bool listEquals(
const QList<L> &list,
const QList<L> &pattern )
1981 if ( list.count() != pattern.count() )
1983 const int numberOfElement( list.count() );
1984 for (
int i = 0; i < numberOfElement; ++i ) {
1985 if ( !pattern.contains( list[ i ] ) ) {
1993 bool listEquals(
const QStringList &list,
const QStringList &pattern )
1995 if ( list.count() != pattern.count() )
1998 const int numberOfElement( list.count() );
1999 for (
int i = 0; i < numberOfElement; ++i ) {
2000 if ( !pattern.contains( list[ i ] ) ) {
2008 bool emailsEquals(
const QStringList &list,
const QStringList &pattern )
2010 if ( list.count() != pattern.count() )
2013 if ( list.isEmpty() )
2016 if ( list.first() != pattern.first() )
2019 QStringList::ConstIterator it;
2020 QStringList::ConstIterator end( list.constEnd() );
2021 for ( it = list.constBegin(); it != end; ++it ) {
2022 if ( !pattern.contains( *it ) ) {
Class that holds a Sound clip for a contact.
QStringList customs() const
Return list of all custom entries.
QList< Key > List
List of keys.
static QString homePhoneLabel()
Return translated label for homePhone field.
QString custom(const QString &app, const QString &name) const
Return value of custom entry, identified by app and entry name.
QString department() const
Return department.
Postal address information.
static QString geoLabel()
Return translated label for geo field.
void setNickName(const QString &nickName)
Set nick name.
Picture photo() const
Return photo.
QString name() const
Return name.
static QString pagerLabel()
Return translated label for pager field.
bool operator!=(const Addressee &) const
Not-equal operator.
void insertEmail(const QString &email, bool preferred=false)
Insert an email address.
A class to store a picture of an addressee.
static QString noteLabel()
Return translated label for note field.
void removeEmail(const QString &email)
Remove email address.
bool containsPrefix(const QString &prefix) const
Queries the list of inclusions.
QString title() const
Return title.
void setMailer(const QString &mailer)
Set mail client.
Address findAddress(const QString &id) const
Return address with the given id.
void insertPhoneNumber(const PhoneNumber &phoneNumber)
Insert a phone number.
QString number() const
Returns the phone number.
static QString homeAddressCountryLabel()
Return translated label for homeAddressCountry field.
void setSuffix(const QString &suffix)
Set honorific suffixes.
Addressee()
Construct an empty address book entry.
void setPhoto(const Picture &photo)
Set photo.
Sort method for sorting an addressee list.
static QString homeAddressLocalityLabel()
Return translated label for homeAddressLocality field.
void setResource(Resource *resource)
Set resource where the addressee is from.
void setFormattedName(const QString &formattedName)
Set formatted name.
static QString revisionLabel()
Return translated label for revision field.
A class to store an encryption key.
void setRole(const QString &role)
Set role.
Secrecy secrecy() const
Return security class.
static QString nameLabel()
Return translated label for name field.
static QString organizationLabel()
Return translated label for organization field.
void removeAddress(const Address &address)
Remove address.
QString fullEmail(const QString &email=QString()) const
Return email address including real name.
QString familyName() const
Return family name.
void removeKey(const Key &key)
Remove a key.
This singleton class stores static data, which is shared by all Addressee objects.
Key findKey(const QString &id) const
Return key with the given id.
void setCategories(const QStringList &)
Set categories to given value.
QString prefix() const
Return honorific prefixes.
void setGivenName(const QString &givenName)
Set given name.
PhoneNumber findPhoneNumber(const QString &id) const
Return phone number with the given id.
static QString photoLabel()
Return translated label for photo field.
QString formattedName() const
Return formatted name.
static void setSortMode(KABC::SortMode *mode)
Sets the sort mode implementation.
QString note() const
Return note.
static QString nickNameLabel()
Return translated label for nickName field.
Sound sound() const
Return sound.
static QString homeFaxLabel()
Return translated label for homeFax field.
void setSortString(const QString &sortString)
Set sort string.
void setAdditionalName(const QString &additionalName)
Set additional names.
bool containsSuffix(const QString &suffix) const
Queries the list of honoric suffixes.
static QString uidLabel()
Return translated label for uid field.
void setLogo(const Picture &logo)
Set logo.
void setChanged(bool value)
Mark addressee as changed.
static QString homeAddressStreetLabel()
Return translated label for homeAddressStreet field.
void setFamilyName(const QString &familyName)
Set family name.
Address::List addresses() const
Return list of all addresses.
QString realName() const
Return the name of the addressee.
Custom or IANA conform key.
QDateTime birthday() const
Return birthday.
QString preferredEmail() const
Return preferred email address.
QStringList emails() const
Return list of all email addresses.
QString sortString() const
Return sort string.
void insertCategory(const QString &)
Insert category.
static QString formattedNameLabel()
Return translated label for formattedName field.
void setPrefix(const QString &prefix)
Set honorific prefixes.
void removeCustom(const QString &app, const QString &name)
Remove custom entry.
QString assembledName() const
Return the name that consists of all name parts.
static QString homeAddressPostalCodeLabel()
Return translated label for homeAddressPostalCode field.
static QString suffixLabel()
Return translated label for suffix field.
QString role() const
Return role.
PhoneNumber phoneNumber(PhoneNumber::Type type) const
Return phone number, which matches the given type.
static QString soundLabel()
Return translated label for sound field.
static QString roleLabel()
Return translated label for role field.
bool containsTitle(const QString &title) const
Queries the list of honoric prefixes.
void setTitle(const QString &title)
Set title.
static QString businessAddressLabelLabel()
Return translated label for businessAddressLabel field.
static QString businessAddressPostOfficeBoxLabel()
Return translated label for businessAddressPostOfficeBox field.
void setCustoms(const QStringList &)
Set all custom entries.
bool operator<(const Addressee &addr) const
Return whether this addressee is "less-than" a given one.
QString mailer() const
Return mail client.
void setDepartment(const QString &department)
Set department.
QList< PhoneNumber > List
List of phone numbers.
static QString logoLabel()
Return translated label for logo field.
static QString homeAddressRegionLabel()
Return translated label for homeAddressRegion field.
void setSound(const Sound &sound)
Set sound.
QString additionalName() const
Return additional names.
QString id() const
Returns the unique identifier.
void setUid(const QString &uid)
Set unique identifier.
static QString businessAddressRegionLabel()
Return translated label for businessAddressRegion field.
void insertKey(const Key &key)
Insert a key.
PhoneNumber::List phoneNumbers() const
Return list of all phone numbers.
static QString sortStringLabel()
Return translated label for sortString field.
static AddresseeHelper * self()
Singleton interface to this class.
static QString businessFaxLabel()
Return translated label for businessFax field.
void setOrganization(const QString &organization)
Set organization.
QStringList categories() const
Return list of all set categories.
void setGeo(const Geo &geo)
Set geographic position.
void setUrl(const KUrl &url)
Set homepage.
static QString businessAddressLocalityLabel()
Return translated label for businessAddressLocality field.
QString givenName() const
Return given name.
QList< Address > List
List of addresses.
static QString homeAddressLabelLabel()
Return translated label for homeAddressLabel field.
static QString carPhoneLabel()
Return translated label for carPhone field.
Key key(Key::Type type, QString customTypeString=QString()) const
Return key, which matches the given type.
static void parseEmailAddress(const QString &rawEmail, QString &fullName, QString &email)
Parse full email address.
static QString birthdayLabel()
Return translated label for birthday field.
void setName(const QString &name)
Set name.
bool isEmpty() const
Return, if the address book entry is empty.
static QString businessAddressCountryLabel()
Return translated label for businessAddressCountry field.
void removeCategory(const QString &)
Remove category.
static QString titleLabel()
Return translated label for title field.
TimeZone timeZone() const
Return time zone.
void setNote(const QString ¬e)
Set note.
Addressee & operator=(const Addressee &)
Assignment operator.
static QString mimeType()
Returns the MIME type used for Addressees.
void setNameFromString(const QString &)
Set name fields by parsing the given string and trying to associate the parts of the string with acco...
void insertAddress(const Address &address)
Insert an address.
static QString departmentLabel()
Return translated label for department field.
void insertCustom(const QString &app, const QString &name, const QString &value)
Insert custom entry.
QString organization() const
Return organization.
QString productId() const
Return product identifier.
static QString productIdLabel()
Return translated label for productId field.
static QString emailLabel()
Return translated label for email field.
static QString additionalNameLabel()
Return translated label for additionalName field.
void setEmails(const QStringList &list)
Set the emails to list.
static QString businessPhoneLabel()
Return translated label for businessPhone field.
static QString secrecyLabel()
Return translated label for secrecy field.
Resource * resource() const
Return pointer to resource.
void removePhoneNumber(const PhoneNumber &phoneNumber)
Remove phone number.
bool changed() const
Return whether the addressee is changed.
void setRevision(const QDateTime &revision)
Set revision date.
void setProductId(const QString &productId)
Set product identifier.
QString id() const
Returns the unique identifier.
QString uid() const
Return unique identifier.
static QString urlLabel()
Return translated label for url field.
bool tradeAsFamilyName() const
Returns whether or not a single name component should be interpreted as a family name.
Picture logo() const
Return logo.
~Addressee()
Destroys the address book entry.
void setBirthday(const QDateTime &birthday)
Set birthday.
QString id() const
Returns the unique identifier.
void setTimeZone(const TimeZone &timeZone)
Set time zone.
QString suffix() const
Return honorific suffixes.
static QString timeZoneLabel()
Return translated label for timeZone field.
KUrl url() const
Return homepage.
static QString prefixLabel()
Return translated label for prefix field.
static QString familyNameLabel()
Return translated label for familyName field.
bool isEmpty() const
Returns true, if the address is empty.
QDateTime revision() const
Return revision date.
void setSecrecy(const Secrecy &secrecy)
Set security class.
void setKeys(const Key::List &keys)
Set the list of keys.
Key::List keys() const
Return list of all keys.
static QString givenNameLabel()
Return translated label for givenName field.
static QString homeAddressPostOfficeBoxLabel()
Return translated label for homeAddressPostOfficeBox field.
bool hasCategory(const QString &) const
Return, if addressee has the given category.
static QString mobilePhoneLabel()
Return translated label for mobilePhone field.
bool operator==(const Addressee &) const
Equality operator.
static QString isdnLabel()
Return translated label for isdn field.
QString toString() const
Returns string representation of the addressee.
Address address(Address::Type type) const
Return address, which matches the given type.
static QString businessAddressStreetLabel()
Return translated label for businessAddressStreet field.
QString nickName() const
Return nick name.
Geo geo() const
Return geographic position.
static QString mailerLabel()
Return translated label for mailer field.
static QString businessAddressPostalCodeLabel()
Return translated label for businessAddressPostalCode field.