• Skip to content
  • Skip to link menu
KDE 4.0 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 ) : d( new KCal::Person::Private )
00063 {
00064   KPIMUtils::extractEmailAddressAndName( fullName, d->mEmail, d->mName );
00065 }
00066 
00067 Person::Person( const QString &name, const QString &email )
00068   : d( new KCal::Person::Private )
00069 {
00070   d->mName = name;
00071   d->mEmail = email;
00072 }
00073 
00074 Person::Person( const Person &person )
00075   : d( new KCal::Person::Private( *person.d ) )
00076 {
00077 }
00078 
00079 Person::~Person()
00080 {
00081   delete d;
00082 }
00083 
00084 bool KCal::Person::operator==( const Person &person )
00085 {
00086   return
00087     d->mName == person.d->mName &&
00088     d->mEmail == person.d->mEmail;
00089 }
00090 
00091 Person &KCal::Person::operator=( const Person &person )
00092 {
00093   *d = *person.d;
00094   return *this;
00095 }
00096 
00097 QString Person::fullName() const
00098 {
00099   if ( d->mName.isEmpty() ) {
00100     return d->mEmail;
00101   } else {
00102     if ( d->mEmail.isEmpty() ) {
00103       return d->mName;
00104     } else {
00105       // Taken from KABC::Addressee::fullEmail
00106       QString name = d->mName;
00107       QRegExp needQuotes( "[^ 0-9A-Za-z\\x0080-\\xFFFF]" );
00108       bool weNeedToQuote = name.indexOf( needQuotes ) != -1;
00109       if ( weNeedToQuote ) {
00110         if ( name[0] != '"' ) {
00111           name.prepend( '"' );
00112         }
00113         if ( name[ name.length()-1 ] != '"' ) {
00114           name.append( '"' );
00115         }
00116       }
00117       return name + " <" + d->mEmail + '>';
00118     }
00119   }
00120 }
00121 
00122 QString Person::name() const
00123 {
00124   return d->mName;
00125 }
00126 
00127 QString Person::email() const
00128 {
00129   return d->mEmail;
00130 }
00131 
00132 bool Person::isEmpty() const
00133 {
00134   return d->mEmail.isEmpty() && d->mName.isEmpty();
00135 }
00136 
00137 void Person::setName( const QString &name )
00138 {
00139   d->mName = name;
00140 }
00141 
00142 void Person::setEmail( const QString &email )
00143 {
00144   if ( email.startsWith( "mailto:", Qt::CaseInsensitive ) ) {
00145     d->mEmail = email.mid( 7 );
00146   } else {
00147     d->mEmail = email;
00148   }
00149 }

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"
  • 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.5
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