• Skip to content
  • Skip to link menu
KDE 4.1 API Reference
  • KDE API Reference
  • KDE-PIM Libraries
  • Sitemap
  • Contact Us
 

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 bool KCal::Person::operator==( const Person &person )
00093 {
00094   return
00095     d->mName == person.d->mName &&
00096     d->mEmail == person.d->mEmail;
00097 }
00098 
00099 Person &KCal::Person::operator=( const Person &person )
00100 {
00101   *d = *person.d;
00102   return *this;
00103 }
00104 
00105 QString Person::fullName() const
00106 {
00107   if ( d->mName.isEmpty() ) {
00108     return d->mEmail;
00109   } else {
00110     if ( d->mEmail.isEmpty() ) {
00111       return d->mName;
00112     } else {
00113       // Taken from KABC::Addressee::fullEmail
00114       QString name = d->mName;
00115       QRegExp needQuotes( "[^ 0-9A-Za-z\\x0080-\\xFFFF]" );
00116       bool weNeedToQuote = name.indexOf( needQuotes ) != -1;
00117       if ( weNeedToQuote ) {
00118         if ( name[0] != '"' ) {
00119           name.prepend( '"' );
00120         }
00121         if ( name[ name.length()-1 ] != '"' ) {
00122           name.append( '"' );
00123         }
00124       }
00125       return name + " <" + d->mEmail + '>';
00126     }
00127   }
00128 }
00129 
00130 QString Person::name() const
00131 {
00132   return d->mName;
00133 }
00134 
00135 QString Person::email() const
00136 {
00137   return d->mEmail;
00138 }
00139 
00140 bool Person::isEmpty() const
00141 {
00142   return d->mEmail.isEmpty() && d->mName.isEmpty();
00143 }
00144 
00145 void Person::setName( const QString &name )
00146 {
00147   d->mName = name;
00148 }
00149 
00150 void Person::setEmail( const QString &email )
00151 {
00152   if ( email.startsWith( "mailto:", Qt::CaseInsensitive ) ) {
00153     d->mEmail = email.mid( 7 );
00154   } else {
00155     d->mEmail = email;
00156   }
00157 }

KCal Library

Skip menu "KCal Library"
  • Main Page
  • Namespace List
  • Class Hierarchy
  • Alphabetical List
  • Class List
  • File List
  • Namespace Members
  • Class Members
  • Related Pages

KDE-PIM Libraries

Skip menu "KDE-PIM Libraries"
  • akonadi
  • kabc
  • kblog
  • kcal
  • kimap
  • kioslave
  •   imap4
  •   mbox
  • kldap
  • kmime
  • kpimidentities
  • kpimutils
  • kresources
  • ktnef
  • kxmlrpcclient
  • mailtransport
  • qgpgme
  • syndication
  •   atom
  •   rdf
  •   rss2
Generated for KDE-PIM Libraries by doxygen 1.5.4
This website is maintained by Adriaan de Groot and Allen Winter.
KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal