diff --git a/kcal/person.cpp b/kcal/person.cpp index b07eb4161..de1c35849 100644 --- a/kcal/person.cpp +++ b/kcal/person.cpp @@ -1,171 +1,176 @@ /* - This file is part of the kcal library. + This file is part of the kcal library. - Copyright (c) 2001 Cornelius Schumacher - Copyright (C) 2003-2004 Reinhold Kainhofer + Copyright (c) 2001 Cornelius Schumacher + Copyright (C) 2003-2004 Reinhold Kainhofer - This library is free software; you can redistribute it and/or - modify it under the terms of the GNU Library General Public - License as published by the Free Software Foundation; either - version 2 of the License, or (at your option) any later version. + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Library General Public + License as published by the Free Software Foundation; either + version 2 of the License, or (at your option) any later version. - This library is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - Library General Public License for more details. + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Library General Public License for more details. - You should have received a copy of the GNU Library General Public License - along with this library; see the file COPYING.LIB. If not, write to - the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, - Boston, MA 02110-1301, USA. + You should have received a copy of the GNU Library General Public License + along with this library; see the file COPYING.LIB. If not, write to + the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + Boston, MA 02110-1301, USA. */ /** @file This file is part of the API for handling calendar data and defines the Person class. @brief Represents a person, by name and email address. @author Cornelius Schumacher \ @author Reinhold Kainhofer \ */ #include "person.h" #include "kpimutils/email.h" #include #include #include using namespace KCal; /** Private class that helps to provide binary compatibility between releases. @internal */ //@cond PRIVATE class KCal::Person::Private { public: QString mName; // person name QString mEmail; // person email address }; //@endcond Person::Person() : d( new KCal::Person::Private ) { } Person::Person( const QString &fullName ) : d( new Private ) { KPIMUtils::extractEmailAddressAndName( fullName, d->mEmail, d->mName ); } Person Person::fromFullName( const QString &fullName ) { QString email, name; KPIMUtils::extractEmailAddressAndName( fullName, email, name ); return Person( name, email ); } Person::Person( const QString &name, const QString &email ) : d( new KCal::Person::Private ) { d->mName = name; d->mEmail = email; } Person::Person( const Person &person ) : d( new KCal::Person::Private( *person.d ) ) { } Person::~Person() { delete d; } #if defined(Q_CC_MSVC) bool KCal::Person::operator==( const Person &person ) const #else bool KCal::Person::operator==( const Person &person ) #endif { return d->mName == person.d->mName && d->mEmail == person.d->mEmail; } Person &KCal::Person::operator=( const Person &person ) { // check for self assignment if ( &person == this ) { return *this; } *d = *person.d; return *this; } QString Person::fullName() const { if ( d->mName.isEmpty() ) { return d->mEmail; } else { if ( d->mEmail.isEmpty() ) { return d->mName; } else { // Taken from KABC::Addressee::fullEmail QString name = d->mName; QRegExp needQuotes( "[^ 0-9A-Za-z\\x0080-\\xFFFF]" ); bool weNeedToQuote = name.indexOf( needQuotes ) != -1; if ( weNeedToQuote ) { if ( name[0] != '"' ) { name.prepend( '"' ); } if ( name[ name.length()-1 ] != '"' ) { name.append( '"' ); } } return name + " <" + d->mEmail + '>'; } } } QString Person::name() const { return d->mName; } QString Person::email() const { return d->mEmail; } bool Person::isEmpty() const { return d->mEmail.isEmpty() && d->mName.isEmpty(); } void Person::setName( const QString &name ) { d->mName = name; } void Person::setEmail( const QString &email ) { if ( email.startsWith( QLatin1String( "mailto:" ), Qt::CaseInsensitive ) ) { d->mEmail = email.mid( 7 ); } else { d->mEmail = email; } } + +/* + Return a hash value for a Person argument. + @param key is a Person. +*/ static inline uint qHash( const Person &key ) { return qHash( key.fullName() ); } diff --git a/kcal/person.h b/kcal/person.h index aaea8c4a6..ecee07426 100644 --- a/kcal/person.h +++ b/kcal/person.h @@ -1,159 +1,163 @@ /* - This file is part of the kcal library. + This file is part of the kcal library. - Copyright (c) 2001-2003 Cornelius Schumacher - Copyright (C) 2003-2004 Reinhold Kainhofer + Copyright (c) 2001-2003 Cornelius Schumacher + Copyright (C) 2003-2004 Reinhold Kainhofer - This library is free software; you can redistribute it and/or - modify it under the terms of the GNU Library General Public - License as published by the Free Software Foundation; either - version 2 of the License, or (at your option) any later version. + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Library General Public + License as published by the Free Software Foundation; either + version 2 of the License, or (at your option) any later version. - This library is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - Library General Public License for more details. + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Library General Public License for more details. - You should have received a copy of the GNU Library General Public License - along with this library; see the file COPYING.LIB. If not, write to - the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, - Boston, MA 02110-1301, USA. + You should have received a copy of the GNU Library General Public License + along with this library; see the file COPYING.LIB. If not, write to + the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + Boston, MA 02110-1301, USA. */ /** @file This file is part of the API for handling calendar data and defines the Person class. - @brief - Represents a person, by name ane email address. - @author Cornelius Schumacher \ @author Reinhold Kainhofer \ */ #ifndef KCAL_PERSON_H #define KCAL_PERSON_H #include #include #include "kcal_export.h" namespace KCal { /** + @brief + Represents a person, by name ane email address. + This class represents a person, with a name and an email address. - It supports the "FirstName LastName " format. + It supports the "FirstName LastName\ " format. */ class KCAL_EXPORT Person { public: /** Constructs a blank person. */ Person(); /** Constructs a person with name and email address taken from @p fullName. @param fullName is the name and email of the person in - the form FirstName LastName \. + the form "FirstName LastName \". */ static Person fromFullName( const QString &fullName ); /** - \deprecated - Use fromFullName() instead. + Constructs a person with name and email address taken from @p fullName. + + @param fullName is the name and email of the person in + the form "FirstName LastName \". + + @deprecated use fromFullName() instead. */ KDE_CONSTRUCTOR_DEPRECATED explicit Person( const QString &fullName ); /** Constructs a person with the name @p name and email address @p email. @param name is the name of this person. @param email is the email address of this person. */ Person( const QString &name, const QString &email ); /** Constructs a person as a copy of another person object. @param person is the person to copy. */ Person( const Person &person ); /** Destroys a person. */ ~Person(); /** Returns true if the person name and email address are empty. */ bool isEmpty() const; /** Returns the full name of this person. */ QString fullName( ) const; /** Sets the name of the person to @p name. @param name is the name of this person. @see name() */ void setName( const QString &name ); /** Returns the person name string. @see setName() */ QString name() const; /** Sets the email address for this person to @p email. @param email is the email address for this person. @see email() */ void setEmail( const QString &email ); /** Returns the email address for this person. @see setEmail() */ QString email() const; /** Compares this with @p person for equality. @param person is the person to compare. */ //KDE5: make const for all #if defined(Q_CC_MSVC) bool operator==( const Person &person ) const; #else bool operator==( const Person &person ); //krazy:exclude=operators #endif /** Sets this person equal to @p person. @param person is the person to copy. */ Person &operator=( const Person &person ); private: //@cond PRIVATE class Private; Private *const d; //@endcond }; } #endif