• Skip to content
  • Skip to link menu
KDE API Reference
  • KDE API Reference
  • kdepimlibs API Reference
  • KDE Home
  • Contact Us
 

KCal Library

  • sources
  • kde-4.12
  • kdepimlibs
  • kcal
person.cpp
Go to the documentation of this file.
1 /*
2  This file is part of the kcal library.
3 
4  Copyright (c) 2001 Cornelius Schumacher <schumacher@kde.org>
5  Copyright (C) 2003-2004 Reinhold Kainhofer <reinhold@kainhofer.com>
6 
7  This library is free software; you can redistribute it and/or
8  modify it under the terms of the GNU Library General Public
9  License as published by the Free Software Foundation; either
10  version 2 of the License, or (at your option) any later version.
11 
12  This library is distributed in the hope that it will be useful,
13  but WITHOUT ANY WARRANTY; without even the implied warranty of
14  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15  Library General Public License for more details.
16 
17  You should have received a copy of the GNU Library General Public License
18  along with this library; see the file COPYING.LIB. If not, write to
19  the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
20  Boston, MA 02110-1301, USA.
21 */
34 #include "person.h"
35 
36 #include "kpimutils/email.h"
37 
38 #include <QtCore/QRegExp>
39 
40 #include <kdebug.h>
41 #include <klocalizedstring.h>
42 
43 using namespace KCal;
44 
49 //@cond PRIVATE
50 class KCal::Person::Private
51 {
52  public:
53  QString mName; // person name
54  QString mEmail; // person email address
55 };
56 //@endcond
57 
58 Person::Person() : d( new KCal::Person::Private )
59 {
60 }
61 
62 Person::Person( const QString &fullName )
63  : d( new Private )
64 {
65  KPIMUtils::extractEmailAddressAndName( fullName, d->mEmail, d->mName );
66 }
67 
68 Person Person::fromFullName( const QString &fullName )
69 {
70  QString email, name;
71  KPIMUtils::extractEmailAddressAndName( fullName, email, name );
72  return Person( name, email );
73 }
74 
75 Person::Person( const QString &name, const QString &email )
76  : d( new KCal::Person::Private )
77 {
78  d->mName = name;
79  d->mEmail = email;
80 }
81 
82 Person::Person( const Person &person )
83  : d( new KCal::Person::Private( *person.d ) )
84 {
85 }
86 
87 Person::~Person()
88 {
89  delete d;
90 }
91 
92 #if defined(Q_CC_MSVC)
93 bool KCal::Person::operator==( const Person &person ) const
94 #else
95 bool KCal::Person::operator==( const Person &person )
96 #endif
97 {
98  return
99  d->mName == person.d->mName &&
100  d->mEmail == person.d->mEmail;
101 }
102 
103 Person &KCal::Person::operator=( const Person &person )
104 {
105  // check for self assignment
106  if ( &person == this ) {
107  return *this;
108  }
109 
110  *d = *person.d;
111  return *this;
112 }
113 
114 QString Person::fullName() const
115 {
116  if ( d->mName.isEmpty() ) {
117  return d->mEmail;
118  } else {
119  if ( d->mEmail.isEmpty() ) {
120  return d->mName;
121  } else {
122  // Taken from KABC::Addressee::fullEmail
123  QString name = d->mName;
124  QRegExp needQuotes( "[^ 0-9A-Za-z\\x0080-\\xFFFF]" );
125  bool weNeedToQuote = name.indexOf( needQuotes ) != -1;
126  if ( weNeedToQuote ) {
127  if ( name[0] != '"' ) {
128  name.prepend( '"' );
129  }
130  if ( name[ name.length()-1 ] != '"' ) {
131  name.append( '"' );
132  }
133  }
134  return name + " <" + d->mEmail + '>';
135  }
136  }
137 }
138 
139 QString Person::name() const
140 {
141  return d->mName;
142 }
143 
144 QString Person::email() const
145 {
146  return d->mEmail;
147 }
148 
149 bool Person::isEmpty() const
150 {
151  return d->mEmail.isEmpty() && d->mName.isEmpty();
152 }
153 
154 void Person::setName( const QString &name )
155 {
156  d->mName = name;
157 }
158 
159 void Person::setEmail( const QString &email )
160 {
161  if ( email.startsWith( QLatin1String( "mailto:" ), Qt::CaseInsensitive ) ) {
162  d->mEmail = email.mid( 7 );
163  } else {
164  d->mEmail = email;
165  }
166 }
KCal::Person::email
QString email() const
Returns the email address for this person.
Definition: person.cpp:144
KCal::Person::fromFullName
static Person fromFullName(const QString &fullName)
Constructs a person with name and email address taken from fullName.
Definition: person.cpp:68
KCal::Person::~Person
~Person()
Destroys a person.
Definition: person.cpp:87
person.h
This file is part of the API for handling calendar data and defines the Person class.
KCal::Person::isEmpty
bool isEmpty() const
Returns true if the person name and email address are empty.
Definition: person.cpp:149
KCal::Person::setEmail
void setEmail(const QString &email)
Sets the email address for this person to email.
Definition: person.cpp:159
KCal::Person
Represents a person, by name ane email address.
Definition: person.h:48
KCal::Person::operator==
bool operator==(const Person &person)
Compares this with person for equality.
Definition: person.cpp:95
KCal::Person::name
QString name() const
Returns the person name string.
Definition: person.cpp:139
KCal::Person::setName
void setName(const QString &name)
Sets the name of the person to name.
Definition: person.cpp:154
KCal::Person::operator=
Person & operator=(const Person &person)
Sets this person equal to person.
Definition: person.cpp:103
KCal::Person::fullName
QString fullName() const
Returns the full name of this person.
Definition: person.cpp:114
KCal::Person::Person
Person()
Constructs a blank person.
Definition: person.cpp:58
This file is part of the KDE documentation.
Documentation copyright © 1996-2014 The KDE developers.
Generated on Tue Oct 14 2014 23:00:58 by doxygen 1.8.7 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.

KCal Library

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

kdepimlibs API Reference

Skip menu "kdepimlibs API Reference"
  • akonadi
  •   contact
  •   kmime
  •   socialutils
  • kabc
  • kalarmcal
  • kblog
  • kcal
  • kcalcore
  • kcalutils
  • kholidays
  • kimap
  • kldap
  • kmbox
  • kmime
  • kpimidentities
  • kpimtextedit
  • kresources
  • ktnef
  • kxmlrpcclient
  • microblog

Search



Report problems with this website to our bug tracking system.
Contact the specific authors with questions and comments about the page contents.

KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal