KCal Library
person.cpp
Go to the documentation of this file.
00001 /* 00002 This file is part of the kcal library. 00003 00004 Copyright (c) 2001 Cornelius Schumacher <schumacher@kde.org> 00005 Copyright (C) 2003-2004 Reinhold Kainhofer <reinhold@kainhofer.com> 00006 00007 This library is free software; you can redistribute it and/or 00008 modify it under the terms of the GNU Library General Public 00009 License as published by the Free Software Foundation; either 00010 version 2 of the License, or (at your option) any later version. 00011 00012 This library is distributed in the hope that it will be useful, 00013 but WITHOUT ANY WARRANTY; without even the implied warranty of 00014 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 00015 Library General Public License for more details. 00016 00017 You should have received a copy of the GNU Library General Public License 00018 along with this library; see the file COPYING.LIB. If not, write to 00019 the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, 00020 Boston, MA 02110-1301, USA. 00021 */ 00034 #include "person.h" 00035 00036 #include "kpimutils/email.h" 00037 00038 #include <QtCore/QRegExp> 00039 00040 #include <kdebug.h> 00041 #include <klocale.h> 00042 00043 using namespace KCal; 00044 00049 //@cond PRIVATE 00050 class KCal::Person::Private 00051 { 00052 public: 00053 QString mName; // person name 00054 QString mEmail; // person email address 00055 }; 00056 //@endcond 00057 00058 Person::Person() : d( new KCal::Person::Private ) 00059 { 00060 } 00061 00062 Person::Person( const QString &fullName ) 00063 : d( new Private ) 00064 { 00065 KPIMUtils::extractEmailAddressAndName( fullName, d->mEmail, d->mName ); 00066 } 00067 00068 Person Person::fromFullName( const QString &fullName ) 00069 { 00070 QString email, name; 00071 KPIMUtils::extractEmailAddressAndName( fullName, email, name ); 00072 return Person( name, email ); 00073 } 00074 00075 Person::Person( const QString &name, const QString &email ) 00076 : d( new KCal::Person::Private ) 00077 { 00078 d->mName = name; 00079 d->mEmail = email; 00080 } 00081 00082 Person::Person( const Person &person ) 00083 : d( new KCal::Person::Private( *person.d ) ) 00084 { 00085 } 00086 00087 Person::~Person() 00088 { 00089 delete d; 00090 } 00091 00092 #if defined(Q_CC_MSVC) 00093 bool KCal::Person::operator==( const Person &person ) const 00094 #else 00095 bool KCal::Person::operator==( const Person &person ) 00096 #endif 00097 { 00098 return 00099 d->mName == person.d->mName && 00100 d->mEmail == person.d->mEmail; 00101 } 00102 00103 Person &KCal::Person::operator=( const Person &person ) 00104 { 00105 // check for self assignment 00106 if ( &person == this ) { 00107 return *this; 00108 } 00109 00110 *d = *person.d; 00111 return *this; 00112 } 00113 00114 QString Person::fullName() const 00115 { 00116 if ( d->mName.isEmpty() ) { 00117 return d->mEmail; 00118 } else { 00119 if ( d->mEmail.isEmpty() ) { 00120 return d->mName; 00121 } else { 00122 // Taken from KABC::Addressee::fullEmail 00123 QString name = d->mName; 00124 QRegExp needQuotes( "[^ 0-9A-Za-z\\x0080-\\xFFFF]" ); 00125 bool weNeedToQuote = name.indexOf( needQuotes ) != -1; 00126 if ( weNeedToQuote ) { 00127 if ( name[0] != '"' ) { 00128 name.prepend( '"' ); 00129 } 00130 if ( name[ name.length()-1 ] != '"' ) { 00131 name.append( '"' ); 00132 } 00133 } 00134 return name + " <" + d->mEmail + '>'; 00135 } 00136 } 00137 } 00138 00139 QString Person::name() const 00140 { 00141 return d->mName; 00142 } 00143 00144 QString Person::email() const 00145 { 00146 return d->mEmail; 00147 } 00148 00149 bool Person::isEmpty() const 00150 { 00151 return d->mEmail.isEmpty() && d->mName.isEmpty(); 00152 } 00153 00154 void Person::setName( const QString &name ) 00155 { 00156 d->mName = name; 00157 } 00158 00159 void Person::setEmail( const QString &email ) 00160 { 00161 if ( email.startsWith( QLatin1String( "mailto:" ), Qt::CaseInsensitive ) ) { 00162 d->mEmail = email.mid( 7 ); 00163 } else { 00164 d->mEmail = email; 00165 } 00166 }
This file is part of the KDE documentation.
Documentation copyright © 1996-2012 The KDE developers.
Generated on Mon May 14 2012 05:05:30 by doxygen 1.7.5 written by Dimitri van Heesch, © 1997-2006
Documentation copyright © 1996-2012 The KDE developers.
Generated on Mon May 14 2012 05:05:30 by doxygen 1.7.5 written by Dimitri van Heesch, © 1997-2006
KDE's Doxygen guidelines are available online.