24 #include <QtCore/QList>
25 #include <QtCore/QRegExp>
26 #include <QtCore/QSharedData>
30 #include <klocalizedstring.h>
33 #include "addresseehelper.h"
35 #ifndef KDEPIM_NO_KRESOURCES
40 #include "addressee.h"
44 static bool matchBinaryPattern(
int value,
int pattern );
47 static bool listEquals(
const QList<L>&,
const QList<L>& );
48 static bool listEquals(
const QStringList&,
const QStringList& );
49 static bool emailsEquals(
const QStringList&,
const QStringList& );
51 class Addressee::Private :
public QSharedData
55 : mUid( KRandom::randomString( 10 ) ),
56 #ifndef KDEPIM_NO_KRESOURCES
59 mEmpty( true ), mChanged( false )
63 Private(
const Private &other )
64 : QSharedData( other )
65 #ifndef KDEPIM_NO_KRESOURCES
71 mFormattedName = other.mFormattedName;
72 mFamilyName = other.mFamilyName;
73 mGivenName = other.mGivenName;
74 mAdditionalName = other.mAdditionalName;
75 mPrefix = other.mPrefix;
76 mSuffix = other.mSuffix;
77 mNickName = other.mNickName;
78 mBirthday = other.mBirthday;
79 mMailer = other.mMailer;
80 mTimeZone = other.mTimeZone;
82 mTitle = other.mTitle;
84 mOrganization = other.mOrganization;
85 mDepartment = other.mDepartment;
87 mProductId = other.mProductId;
88 mRevision = other.mRevision;
89 mSortString = other.mSortString;
91 mSecrecy = other.mSecrecy;
93 mPhoto = other.mPhoto;
94 mSound = other.mSound;
96 mPhoneNumbers = other.mPhoneNumbers;
97 mAddresses = other.mAddresses;
99 mEmails = other.mEmails;
100 mCategories = other.mCategories;
101 mCustomFields = other.mCustomFields;
103 #ifndef KDEPIM_NO_KRESOURCES
104 mResource = other.mResource;
106 mEmpty = other.mEmpty;
107 mChanged = other.mChanged;
116 QString mFormattedName;
119 QString mAdditionalName;
129 QString mOrganization;
145 QStringList mCategories;
146 QMap<QString, QString> mCustomFields;
148 #ifndef KDEPIM_NO_KRESOURCES
176 if (
this != &other )
184 if ( d->mUid != addressee.d->mUid ) {
185 kDebug() <<
"uid differs";
189 if ( d->mName != addressee.d->mName &&
190 !( d->mName.isEmpty() && addressee.d->mName.isEmpty() ) ) {
191 kDebug(5700) <<
"name differs";
195 if ( d->mFormattedName != addressee.d->mFormattedName &&
196 !( d->mFormattedName.isEmpty() && addressee.d->mFormattedName.isEmpty() ) ) {
197 kDebug(5700) <<
"formattedName differs";
201 if ( d->mFamilyName != addressee.d->mFamilyName &&
202 !( d->mFamilyName.isEmpty() && addressee.d->mFamilyName.isEmpty() ) ) {
203 kDebug(5700) <<
"familyName differs";
207 if ( d->mGivenName != addressee.d->mGivenName &&
208 !( d->mGivenName.isEmpty() && addressee.d->mGivenName.isEmpty() ) ) {
209 kDebug(5700) <<
"givenName differs";
213 if ( d->mAdditionalName != addressee.d->mAdditionalName &&
214 !( d->mAdditionalName.isEmpty() && addressee.d->mAdditionalName.isEmpty() ) ) {
215 kDebug(5700) <<
"additionalName differs";
219 if ( d->mPrefix != addressee.d->mPrefix &&
220 !( d->mPrefix.isEmpty() && addressee.d->mPrefix.isEmpty() ) ) {
221 kDebug(5700) <<
"prefix differs";
225 if ( d->mSuffix != addressee.d->mSuffix &&
226 !( d->mSuffix.isEmpty() && addressee.d->mSuffix.isEmpty() ) ) {
227 kDebug(5700) <<
"suffix differs";
231 if ( d->mNickName != addressee.d->mNickName &&
232 !( d->mNickName.isEmpty() && addressee.d->mNickName.isEmpty() ) ) {
233 kDebug(5700) <<
"nickName differs";
237 if ( d->mBirthday != addressee.d->mBirthday ) {
238 kDebug(5700) <<
"birthday differs";
242 if ( d->mMailer != addressee.d->mMailer &&
243 !( d->mMailer.isEmpty() && addressee.d->mMailer.isEmpty() ) ) {
244 kDebug(5700) <<
"mailer differs";
248 if ( d->mTimeZone != addressee.d->mTimeZone ) {
249 kDebug(5700) <<
"timeZone differs";
253 if ( d->mGeo != addressee.d->mGeo ) {
254 kDebug(5700) <<
"geo differs";
258 if ( d->mTitle != addressee.d->mTitle &&
259 !( d->mTitle.isEmpty() && addressee.d->mTitle.isEmpty() ) ) {
260 kDebug(5700) <<
"title differs";
264 if ( d->mRole != addressee.d->mRole &&
265 !( d->mRole.isEmpty() && addressee.d->mRole.isEmpty() ) ) {
266 kDebug(5700) <<
"role differs";
270 if ( d->mOrganization != addressee.d->mOrganization &&
271 !( d->mOrganization.isEmpty() && addressee.d->mOrganization.isEmpty() ) ) {
272 kDebug(5700) <<
"organization differs";
276 if ( d->mDepartment != addressee.d->mDepartment &&
277 !( d->mDepartment.isEmpty() && addressee.d->mDepartment.isEmpty() ) ) {
278 kDebug(5700) <<
"department differs";
282 if ( d->mNote != addressee.d->mNote &&
283 !( d->mNote.isEmpty() && addressee.d->mNote.isEmpty() ) ) {
284 kDebug(5700) <<
"note differs";
288 if ( d->mProductId != addressee.d->mProductId &&
289 !( d->mProductId.isEmpty() && addressee.d->mProductId.isEmpty() ) ) {
290 kDebug(5700) <<
"productId differs";
294 if ( d->mSortString != addressee.d->mSortString &&
295 !( d->mSortString.isEmpty() && addressee.d->mSortString.isEmpty() ) ) {
296 kDebug(5700) <<
"sortString differs";
300 if ( d->mSecrecy != addressee.d->mSecrecy ) {
301 kDebug(5700) <<
"secrecy differs";
305 if ( d->mLogo != addressee.d->mLogo ) {
306 kDebug(5700) <<
"logo differs";
310 if ( d->mPhoto != addressee.d->mPhoto ) {
311 kDebug(5700) <<
"photo differs";
315 if ( d->mSound != addressee.d->mSound ) {
316 kDebug(5700) <<
"sound differs";
320 if ( ( d->mUrl.isValid() || addressee.d->mUrl.isValid() ) &&
321 ( d->mUrl != addressee.d->mUrl ) ) {
322 kDebug() <<
"url differs";
326 if ( !listEquals( d->mPhoneNumbers, addressee.d->mPhoneNumbers ) ) {
327 kDebug() <<
"phoneNumbers differs";
331 if ( !listEquals( d->mAddresses, addressee.d->mAddresses ) ) {
332 kDebug() <<
"addresses differs";
336 if ( !listEquals( d->mKeys, addressee.d->mKeys ) ) {
337 kDebug() <<
"keys differs";
341 if ( !emailsEquals( d->mEmails, addressee.d->mEmails ) ) {
342 kDebug() <<
"emails differs";
346 if ( !listEquals( d->mCategories, addressee.d->mCategories ) ) {
347 kDebug() <<
"categories differs";
351 if ( d->mCustomFields != addressee.d->mCustomFields ) {
352 kDebug() <<
"custom differs";
361 return !( a == *this );
385 return i18n(
"Unique Identifier" );
390 if ( name == d->mName )
404 return i18n(
"Name" );
410 if ( formattedName == d->mFormattedName )
419 return d->mFormattedName;
424 return i18n(
"Formatted Name" );
430 if ( familyName == d->mFamilyName )
439 return d->mFamilyName;
444 return i18n(
"Family Name" );
450 if ( givenName == d->mGivenName )
459 return d->mGivenName;
464 return i18n(
"Given Name" );
470 if ( additionalName == d->mAdditionalName )
479 return d->mAdditionalName;
484 return i18n(
"Additional Names" );
490 if ( prefix == d->mPrefix )
504 return i18n(
"Honorific Prefixes" );
510 if ( suffix == d->mSuffix )
524 return i18n(
"Honorific Suffixes" );
530 if ( nickName == d->mNickName )
544 return i18n(
"Nick Name" );
550 if ( birthday == d->mBirthday )
564 return i18n(
"Birthday" );
570 return i18n(
"Home Address Street" );
576 return i18n(
"Home Address Post Office Box" );
582 return i18n(
"Home Address City" );
588 return i18n(
"Home Address State" );
594 return i18n(
"Home Address Zip Code" );
600 return i18n(
"Home Address Country" );
606 return i18n(
"Home Address Label" );
612 return i18n(
"Business Address Street" );
618 return i18n(
"Business Address Post Office Box" );
624 return i18n(
"Business Address City" );
630 return i18n(
"Business Address State" );
636 return i18n(
"Business Address Zip Code" );
642 return i18n(
"Business Address Country" );
648 return i18n(
"Business Address Label" );
654 return i18n(
"Home Phone" );
660 return i18n(
"Business Phone" );
666 return i18n(
"Mobile Phone" );
672 return i18n(
"Home Fax" );
678 return i18n(
"Business Fax" );
684 return i18n(
"Car Phone" );
690 return i18n(
"ISDN" );
696 return i18n(
"Pager" );
702 return i18n(
"Email Address" );
708 if ( mailer == d->mMailer )
722 return i18n(
"Mail Client" );
728 if ( timeZone == d->mTimeZone )
742 return i18n(
"Time Zone" );
748 if ( geo == d->mGeo )
762 return i18n(
"Geographic Position" );
768 if ( title == d->mTitle )
782 return i18nc(
"a person's title",
"Title" );
788 if ( role == d->mRole )
802 return i18nc(
"of a person in an organization",
"Role" );
808 if ( organization == d->mOrganization )
817 return d->mOrganization;
822 return i18n(
"Organization" );
828 if ( department == d->mDepartment )
837 return d->mDepartment;
842 return i18n(
"Department" );
848 if ( note == d->mNote )
862 return i18n(
"Note" );
868 if ( productId == d->mProductId )
877 return d->mProductId;
882 return i18n(
"Product Identifier" );
888 if ( revision == d->mRevision )
902 return i18n(
"Revision Date" );
908 if ( sortString == d->mSortString )
917 return d->mSortString;
922 return i18n(
"Sort String" );
928 if ( url == d->mUrl )
942 return i18n(
"Homepage" );
948 if ( secrecy == d->mSecrecy )
962 return i18n(
"Security Class" );
968 if ( logo == d->mLogo )
982 return i18n(
"Logo" );
988 if ( photo == d->mPhoto )
1002 return i18n(
"Photo" );
1008 if ( sound == d->mSound )
1022 return i18n(
"Sound" );
1030 if ( str.length() > 1 &&
1031 s[ 0 ] == QLatin1Char(
'"' ) &&
1032 s[ s.length() - 1 ] == QLatin1Char(
'"' ) ) {
1033 str = s.mid( 1, s.length() - 2 );
1046 if ( str.isEmpty() )
1049 static QString spaceStr = QString::fromLatin1(
" " );
1050 static QString emptyStr = QString::fromLatin1(
"" );
1053 int i = str.indexOf( QLatin1Char(
',' ) );
1055 QStringList parts = str.split( spaceStr );
1057 int rightOffset = parts.count() - 1;
1060 while ( rightOffset >= 0 ) {
1062 suffix.prepend( parts[ rightOffset ] + ( suffix.isEmpty() ? emptyStr : spaceStr ) );
1069 if ( rightOffset < 0 )
1072 if ( rightOffset - 1 >= 0 && helper->
containsPrefix( parts[ rightOffset - 1 ].toLower() ) ) {
1073 setFamilyName( parts[ rightOffset - 1 ] + spaceStr + parts[ rightOffset ] );
1083 while ( leftOffset < rightOffset ) {
1085 prefix.append( ( prefix.isEmpty() ? emptyStr : spaceStr ) + parts[ leftOffset ] );
1092 if ( leftOffset < rightOffset ) {
1098 while ( leftOffset < rightOffset ) {
1099 additionalName.append( ( additionalName.isEmpty() ? emptyStr : spaceStr ) + parts[ leftOffset ] );
1104 QString part1 = str.left( i );
1105 QString part2 = str.mid( i + 1 );
1107 QStringList parts = part1.split( spaceStr );
1109 int rightOffset = parts.count() - 1;
1111 if ( parts.count() > 0 ) {
1114 while ( rightOffset >= 0 ) {
1116 suffix.prepend( parts[ rightOffset ] + ( suffix.isEmpty() ? emptyStr : spaceStr ) );
1123 if ( rightOffset - 1 >= 0 && helper->
containsPrefix( parts[ rightOffset - 1 ].toLower() ) ) {
1124 setFamilyName( parts[ rightOffset - 1 ] + spaceStr + parts[ rightOffset ] );
1130 while ( leftOffset < rightOffset ) {
1132 prefix.append( ( prefix.isEmpty() ? emptyStr : spaceStr ) + parts[ leftOffset ] );
1143 parts = part2.split( spaceStr );
1146 rightOffset = parts.count();
1148 if ( parts.count() > 0 ) {
1151 while ( leftOffset < rightOffset ) {
1153 prefix.append( ( prefix.isEmpty() ? emptyStr : spaceStr ) + parts[ leftOffset ] );
1160 if ( leftOffset < rightOffset ) {
1166 while ( leftOffset < rightOffset ) {
1167 additionalName.append( ( additionalName.isEmpty() ? emptyStr : spaceStr ) + parts[ leftOffset ] );
1197 const QString
name =
prefix() + QLatin1Char(
' ' ) +
1203 return name.simplified();
1209 if ( email.isNull() ) {
1214 if ( e.isEmpty() )
return QString();
1220 QRegExp needQuotes( QLatin1String(
"[^ 0-9A-Za-z\\x0080-\\xFFFF]" ) );
1221 if (
realName().indexOf( needQuotes ) != -1 ) {
1223 name.replace( QLatin1String(
"\"" ), QLatin1String(
"\\\"" ) );
1224 text = QLatin1String(
"\"" ) + name + QLatin1String(
"\" <" ) + e + QLatin1Char(
'>' );
1226 text =
realName() + QLatin1String(
" <" ) + e + QLatin1Char(
'>' );
1234 if ( email.simplified().isEmpty() )
1237 if ( d->mEmails.contains( email ) ) {
1238 if ( !preferred || d->mEmails.first() == email )
1241 d->mEmails.removeAll( email );
1242 d->mEmails.prepend( email );
1246 d->mEmails.prepend( email );
1248 d->mEmails.append( email );
1255 if ( d->mEmails.contains( email ) ) {
1256 d->mEmails.removeAll( email );
1262 if ( d->mEmails.count() == 0 )
1265 return d->mEmails.first();
1281 PhoneNumber::List::Iterator it;
1282 for ( it = d->mPhoneNumbers.begin(); it != d->mPhoneNumbers.end(); ++it ) {
1283 if ( ( *it ).id() == phoneNumber.
id() ) {
1288 if ( !phoneNumber.
number().simplified().isEmpty() )
1289 d->mPhoneNumbers.append( phoneNumber );
1294 PhoneNumber::List::Iterator it;
1295 for ( it = d->mPhoneNumbers.begin(); it != d->mPhoneNumbers.end(); ++it ) {
1296 if ( ( *it ).id() == phoneNumber.
id() ) {
1297 d->mPhoneNumbers.erase( it );
1306 PhoneNumber::List::ConstIterator it;
1307 for ( it = d->mPhoneNumbers.constBegin(); it != d->mPhoneNumbers.constEnd(); ++it ) {
1308 if ( matchBinaryPattern( ( *it ).type(), type ) ) {
1311 }
else if ( phoneNumber.
number().isEmpty() ) {
1312 phoneNumber = ( *it );
1322 return d->mPhoneNumbers;
1329 PhoneNumber::List::ConstIterator it;
1330 PhoneNumber::List::ConstIterator end( d->mPhoneNumbers.constEnd() );
1331 for ( it = d->mPhoneNumbers.constBegin(); it != end; ++it ) {
1332 if ( matchBinaryPattern( ( *it ).type(), type ) ) {
1341 PhoneNumber::List::ConstIterator it;
1342 PhoneNumber::List::ConstIterator end( d->mPhoneNumbers.constEnd() );
1343 for ( it = d->mPhoneNumbers.constBegin(); it != end; ++it ) {
1344 if ( ( *it ).id() == id ) {
1355 Key::List::Iterator it;
1356 for ( it = d->mKeys.begin(); it != d->mKeys.end(); ++it ) {
1357 if ( ( *it ).id() == key.
id() ) {
1362 d->mKeys.append( key );
1367 Key::List::Iterator it;
1368 for ( it = d->mKeys.begin(); it != d->mKeys.end(); ++it ) {
1369 if ( ( *it ).id() == key.
id() ) {
1370 d->mKeys.removeAll( key );
1378 Key::List::ConstIterator it;
1379 Key::List::ConstIterator end( d->mKeys.constEnd() );
1380 for ( it = d->mKeys.constBegin(); it != end; ++it ) {
1381 if ( ( *it ).type() == type ) {
1383 if ( customTypeString.isEmpty() ) {
1386 if ( ( *it ).customTypeString() == customTypeString )
1394 return Key( QString(), type );
1411 Key::List::ConstIterator it;
1412 Key::List::ConstIterator end( d->mKeys.constEnd() );
1413 for ( it = d->mKeys.constBegin(); it != end; ++it ) {
1414 if ( ( *it ).type() == type ) {
1416 if ( customTypeString.isEmpty() ) {
1419 if ( ( *it ).customTypeString() == customTypeString )
1432 Key::List::ConstIterator it;
1433 Key::List::ConstIterator end( d->mKeys.constEnd() );
1434 for ( it = d->mKeys.constBegin(); it != end; ++it ) {
1435 if ( ( *it ).id() == id ) {
1446 str += QLatin1String(
"Addressee {\n" );
1447 str += QString::fromLatin1(
" Uid: %1\n" ).arg(
uid() );
1449 str += QString::fromLatin1(
" Name: %1\n" ).arg(
name() );
1450 str += QString::fromLatin1(
" FormattedName: %1\n" ).arg(
formattedName() );
1451 str += QString::fromLatin1(
" FamilyName: %1\n" ).arg(
familyName() );
1452 str += QString::fromLatin1(
" GivenName: %1\n" ).arg(
givenName() );
1453 str += QString::fromLatin1(
" AdditionalName: %1\n" ).arg(
additionalName() );
1454 str += QString::fromLatin1(
" Prefix: %1\n" ).arg(
prefix() );
1455 str += QString::fromLatin1(
" Suffix: %1\n" ).arg(
suffix() );
1456 str += QString::fromLatin1(
" NickName: %1\n" ).arg(
nickName() );
1457 str += QString::fromLatin1(
" Birthday: %1\n" ).arg(
birthday().
toString() );
1458 str += QString::fromLatin1(
" Mailer: %1\n" ).arg(
mailer() );
1459 str += QString::fromLatin1(
" TimeZone: %1\n" ).arg(
timeZone().
toString() );
1460 str += QString::fromLatin1(
" Geo: %1\n" ).arg(
geo().
toString() );
1461 str += QString::fromLatin1(
" Title: %1\n" ).arg(
title() );
1462 str += QString::fromLatin1(
" Role: %1\n" ).arg(
role() );
1463 str += QString::fromLatin1(
" Organization: %1\n" ).arg(
organization() );
1464 str += QString::fromLatin1(
" Department: %1\n" ).arg(
department() );
1465 str += QString::fromLatin1(
" Note: %1\n" ).arg(
note() );
1466 str += QString::fromLatin1(
" ProductId: %1\n" ).arg(
productId() );
1467 str += QString::fromLatin1(
" Revision: %1\n" ).arg(
revision().
toString() );
1468 str += QString::fromLatin1(
" SortString: %1\n" ).arg(
sortString() );
1469 str += QString::fromLatin1(
" Url: %1\n" ).arg(
url().
url() );
1470 str += QString::fromLatin1(
" Secrecy: %1\n" ).arg(
secrecy().
toString() );
1471 str += QString::fromLatin1(
" Logo: %1\n" ).arg(
logo().
toString() );
1472 str += QString::fromLatin1(
" Photo: %1\n" ).arg(
photo().
toString() );
1473 str += QString::fromLatin1(
" Sound: %1\n" ).arg(
sound().
toString() );
1475 str += QLatin1String(
" Emails {\n" );
1476 const QStringList e =
emails();
1477 QStringList::ConstIterator it;
1478 for ( it = e.begin(); it != e.end(); ++it ) {
1479 str += QString::fromLatin1(
" %1\n" ).arg( *it );
1481 str += QLatin1String(
" }\n" );
1483 str += QLatin1String(
" PhoneNumbers {\n" );
1485 PhoneNumber::List::ConstIterator it2;
1486 for ( it2 = p.begin(); it2 != p.end(); ++it2 ) {
1487 str += ( *it2 ).toString();
1489 str += QLatin1String(
" }\n" );
1491 str += QLatin1String(
" Addresses {\n" );
1493 Address::List::ConstIterator it3;
1494 for ( it3 = a.begin(); it3 != a.end(); ++it3 ) {
1495 str += ( *it3 ).toString();
1497 str += QLatin1String(
" }\n" );
1499 str += QLatin1String(
" Keys {\n" );
1501 Key::List::ConstIterator it4;
1502 for ( it4 = k.begin(); it4 != k.end(); ++it4 ) {
1503 str += ( *it4 ).toString();
1505 str += QLatin1String(
" }\n" );
1507 str += QLatin1String(
"}\n" );
1520 Address::List::Iterator it;
1521 for ( it = d->mAddresses.begin(); it != d->mAddresses.end(); ++it ) {
1522 if ( ( *it ).id() == address.
id() ) {
1528 d->mAddresses.append( address );
1533 Address::List::Iterator it;
1534 for ( it = d->mAddresses.begin(); it != d->mAddresses.end(); ++it ) {
1535 if ( ( *it ).id() == address.
id() ) {
1536 d->mAddresses.erase( it );
1545 Address::List::ConstIterator it;
1546 Address::List::ConstIterator end( d->mAddresses.constEnd() );
1547 for ( it = d->mAddresses.constBegin(); it != end; ++it ) {
1548 if ( matchBinaryPattern( ( *it ).type(), type ) ) {
1551 }
else if ( address.
isEmpty() ) {
1562 return d->mAddresses;
1569 Address::List::ConstIterator it;
1570 Address::List::ConstIterator end( d->mAddresses.constEnd() );
1571 for ( it = d->mAddresses.constBegin(); it != end; ++it ) {
1572 if ( matchBinaryPattern( ( *it ).type(), type ) ) {
1582 Address::List::ConstIterator it;
1583 Address::List::ConstIterator end( d->mAddresses.constEnd() );
1584 for ( it = d->mAddresses.constBegin(); it != end; ++it ) {
1585 if ( ( *it ).id() == id ) {
1596 if ( d->mCategories.contains( c ) )
1599 d->mCategories.append( c );
1604 if ( d->mCategories.contains( category ) ) {
1605 d->mCategories.removeAll( category );
1611 return d->mCategories.contains( category );
1623 return d->mCategories;
1627 const QString &value )
1629 if ( value.isEmpty() || name.isEmpty() || app.isEmpty() ) {
1635 const QString qualifiedName = app + QLatin1Char(
'-' ) +
name;
1637 d->mCustomFields.insert( qualifiedName, value );
1642 const QString qualifiedName = app + QLatin1Char(
'-' ) +
name;
1644 d->mCustomFields.remove( qualifiedName );
1649 const QString qualifiedName = app + QLatin1Char(
'-' ) +
name;
1651 return d->mCustomFields.value( qualifiedName );
1658 d->mCustomFields.clear();
1660 foreach (
const QString &
custom, customs ) {
1661 const int index = custom.indexOf( QLatin1Char(
':' ) );
1665 const QString qualifiedName = custom.left( index );
1666 const QString value = custom.mid( index + 1 );
1668 d->mCustomFields.insert( qualifiedName, value );
1676 QMapIterator<QString, QString> it( d->mCustomFields );
1677 while ( it.hasNext() ) {
1679 result << it.key() + QLatin1Char(
':' ) + it.value();
1692 if ( rawEmail.isEmpty() )
1696 QByteArray
address = rawEmail.toUtf8();
1698 QByteArray displayName;
1699 QByteArray addrSpec;
1706 enum { TopLevel, InComment, InAngleAddress } context = TopLevel;
1707 bool inQuotedString =
false;
1708 int commentLevel = 0;
1711 for (
char* p = address.data(); *p && !stop; ++p ) {
1712 switch ( context ) {
1715 case '"' : inQuotedString = !inQuotedString;
1718 case '(' :
if ( !inQuotedString ) {
1719 context = InComment;
1725 case '<' :
if ( !inQuotedString ) {
1726 context = InAngleAddress;
1740 case ',' :
if ( !inQuotedString ) {
1750 default : displayName += *p;
1756 case '(' : ++commentLevel;
1759 case ')' : --commentLevel;
1760 if ( commentLevel == 0 ) {
1776 default : comment += *p;
1780 case InAngleAddress : {
1782 case '"' : inQuotedString = !inQuotedString;
1785 case '>' :
if ( !inQuotedString ) {
1800 default : addrSpec += *p;
1808 displayName = displayName.trimmed();
1809 comment = comment.trimmed();
1810 addrSpec = addrSpec.trimmed();
1812 fullName = QString::fromUtf8( displayName );
1813 email = QString::fromUtf8( addrSpec );
1816 if ( inQuotedString )
1818 if ( context == InComment )
1820 if ( context == InAngleAddress )
1823 if ( addrSpec.isEmpty() ) {
1824 if ( displayName.isEmpty() )
1831 fullName = QString::fromUtf8( comment );
1835 email = email.toLower();
1838 unsigned int len = fullName.length();
1839 if ( fullName[ 0 ] == QLatin1Char(
'"' ) && fullName[ len - 1 ] == QLatin1Char(
'"' ) ) {
1840 fullName = fullName.mid( 1, len - 2 );
1844 #ifndef KDEPIM_NO_KRESOURCES
1852 return d->mResource;
1858 d->mChanged = value;
1868 Private::mSortMode = mode;
1873 if ( !Private::mSortMode )
1876 return Private::mSortMode->lesser( *
this, addr );
1881 return QLatin1String(
"text/directory" );
1884 QDataStream &KABC::operator<<( QDataStream &s,
const Addressee &a )
1889 s << a.d->mFormattedName;
1890 s << a.d->mFamilyName;
1891 s << a.d->mGivenName;
1892 s << a.d->mAdditionalName;
1895 s << a.d->mNickName;
1896 s << a.d->mBirthday;
1898 s << a.d->mTimeZone;
1902 s << a.d->mOrganization;
1903 s << a.d->mDepartment;
1905 s << a.d->mProductId;
1906 s << a.d->mRevision;
1907 s << a.d->mSortString;
1913 s << a.d->mPhoneNumbers;
1914 s << a.d->mAddresses;
1916 s << a.d->mCategories;
1922 QDataStream &KABC::operator>>( QDataStream &s,
Addressee &a )
1927 s >> a.d->mFormattedName;
1928 s >> a.d->mFamilyName;
1929 s >> a.d->mGivenName;
1930 s >> a.d->mAdditionalName;
1933 s >> a.d->mNickName;
1934 s >> a.d->mBirthday;
1936 s >> a.d->mTimeZone;
1940 s >> a.d->mOrganization;
1941 s >> a.d->mDepartment;
1943 s >> a.d->mProductId;
1944 s >> a.d->mRevision;
1945 s >> a.d->mSortString;
1951 s >> a.d->mPhoneNumbers;
1952 s >> a.d->mAddresses;
1954 s >> a.d->mCategories;
1955 QStringList customFields;
1960 a.d->mEmpty =
false;
1965 bool matchBinaryPattern(
int value,
int pattern )
1974 return ( value == 0 );
1976 return ( pattern == ( pattern & value ) );
1980 bool listEquals(
const QList<L> &list,
const QList<L> &pattern )
1982 if ( list.count() != pattern.count() )
1984 const int numberOfElement( list.count() );
1985 for (
int i = 0; i < numberOfElement; ++i ) {
1986 if ( !pattern.contains( list[ i ] ) ) {
1994 bool listEquals(
const QStringList &list,
const QStringList &pattern )
1996 if ( list.count() != pattern.count() )
1999 const int numberOfElement( list.count() );
2000 for (
int i = 0; i < numberOfElement; ++i ) {
2001 if ( !pattern.contains( list[ i ] ) ) {
2009 bool emailsEquals(
const QStringList &list,
const QStringList &pattern )
2011 if ( list.count() != pattern.count() )
2014 if ( list.isEmpty() )
2017 if ( list.first() != pattern.first() )
2020 QStringList::ConstIterator it;
2021 QStringList::ConstIterator end( list.constEnd() );
2022 for ( it = list.constBegin(); it != end; ++it ) {
2023 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.