37 #include <QtCore/QRegExp>
39 using namespace KCalCore;
46 class KCalCore::Person::Private
49 Private() : mCount( 0 ) {}
61 : d( new KCalCore::
Person::Private )
68 : d( new KCalCore::
Person::Private( *person.d ) )
80 d->mName == person.d->mName &&
81 d->mEmail == person.d->mEmail;
86 return !( *
this == person );
92 if ( &person ==
this ) {
102 if ( d->mName.isEmpty() ) {
105 if ( d->mEmail.isEmpty() ) {
109 QString
name = d->mName;
110 QRegExp needQuotes(
"[^ 0-9A-Za-z\\x0080-\\xFFFF]" );
111 bool weNeedToQuote = name.indexOf( needQuotes ) != -1;
112 if ( weNeedToQuote ) {
113 if ( name[0] !=
'"' ) {
116 if ( name[ name.length()-1 ] !=
'"' ) {
120 return name +
" <" + d->mEmail +
'>';
137 return d->mEmail.isEmpty() && d->mName.isEmpty();
147 if ( email.startsWith( QLatin1String(
"mailto:" ), Qt::CaseInsensitive ) ) {
148 d->mEmail = email.mid( 7 );
157 int pos = email.lastIndexOf(
"@" );
158 return ( pos > 0 ) && ( email.lastIndexOf(
"." ) > pos ) && ( ( email.length() - pos ) > 4 );
178 return stream << person->d->mName
180 << person->d->mCount;
188 stream >> name >> email >> count;
191 person_tmp->setCount( count );
192 person.swap( person_tmp );
199 static bool extractEmailAddressAndName(
const QString &aStr, QString &mail, QString &name )
204 const int len = aStr.length();
205 const char cQuotes =
'"';
207 bool bInComment =
false;
208 bool bInQuotesOutsideOfEmail =
false;
209 int i=0, iAd=0, iMailStart=0, iMailEnd=0;
211 unsigned int commentstack = 0;
223 bInComment = commentstack != 0;
224 if (
'"' == c && !bInComment ) {
225 bInQuotesOutsideOfEmail = !bInQuotesOutsideOfEmail;
228 if( !bInComment && !bInQuotesOutsideOfEmail ) {
241 for ( i = 0; len > i; ++i ) {
249 mail = aStr.mid( i + 1 );
250 if ( mail.endsWith(
'>' ) ) {
251 mail.truncate( mail.length() - 1 );
259 bInQuotesOutsideOfEmail =
false;
260 for ( i = iAd-1; 0 <= i; --i ) {
264 if ( !name.isEmpty() ) {
271 }
else if ( bInQuotesOutsideOfEmail ) {
272 if ( cQuotes == c ) {
273 bInQuotesOutsideOfEmail =
false;
274 }
else if ( c !=
'\\' ) {
284 if ( cQuotes == c ) {
285 bInQuotesOutsideOfEmail =
true;
290 switch ( c.toLatin1() ) {
295 if ( !name.isEmpty() ) {
309 name = name.simplified();
310 mail = mail.simplified();
312 if ( mail.isEmpty() ) {
322 bInQuotesOutsideOfEmail =
false;
323 int parenthesesNesting = 0;
324 for ( i = iAd+1; len > i; ++i ) {
328 if ( --parenthesesNesting == 0 ) {
330 if ( !name.isEmpty() ) {
340 ++parenthesesNesting;
344 }
else if ( bInQuotesOutsideOfEmail ) {
345 if ( cQuotes == c ) {
346 bInQuotesOutsideOfEmail =
false;
347 }
else if ( c !=
'\\' ) {
357 if ( cQuotes == c ) {
358 bInQuotesOutsideOfEmail =
true;
363 switch ( c.toLatin1() ) {
368 if ( !name.isEmpty() ) {
371 if ( ++parenthesesNesting > 0 ) {
385 name = name.simplified();
386 mail = mail.simplified();
388 return ! ( name.isEmpty() || mail.isEmpty() );
395 extractEmailAddressAndName( fullName, email, name );
Person & operator=(const Person &person)
Sets this person equal to person.
Represents a person, by name and email address.
void setEmail(const QString &email)
Sets the email address for this person to email.
QString name() const
Returns the person name string.
virtual ~Person()
Destroys a person.
QString fullName() const
Returns the full name of this person.
This file is part of the API for handling calendar data and defines the Person class.
void setName(const QString &name)
Sets the name of the person to name.
bool operator!=(const Person &person) const
Compares this with person for non-equality.
bool operator==(const Person &person) const
Compares this with person for equality.
void setCount(int count)
Sets the number of references for this person.
Person()
Constructs a blank person.
bool isEmpty() const
Returns true if the person name and email address are empty.
QString email() const
Returns the email address for this person.
int count() const
Returns the number of references or zero if it is not initialized.
static Person::Ptr fromFullName(const QString &fullName)
Constructs a person with name and email address taken from fullName.
QSharedPointer< Person > Ptr
A shared pointer to a Person object.
KCALCORE_EXPORT QDataStream & operator<<(QDataStream &stream, const KCalCore::Attendee::Ptr &attendee)
Serializes an Attendee object into a data stream.
uint qHash(const KCalCore::Period &key)
Return a hash value for a Period argument.
static bool isValidEmail(const QString &email)
Returns true if person's email address is valid.
KCALCORE_EXPORT QDataStream & operator>>(QDataStream &stream, KCalCore::Attendee::Ptr &attendee)
Initializes an Attendee object from a data stream.