libkcal

person.cpp
1/*
2 This file is part of libkcal.
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*/
22
23#include "person.h"
24
25#include <kdebug.h>
26#include <tdelocale.h>
27
28#include <libemailfunctions/email.h>
29
30#include <tqregexp.h>
31
32using namespace KCal;
33
34Person::Person( const TQString &fullName )
35{
36 TQString name, email;
37 KPIM::getNameAndMail( fullName, name, email );
38 setName( name );
39 setEmail( email );
40}
41
42Person::Person( const TQString &name, const TQString &email )
43{
44 setName( name );
45 setEmail( email );
46}
47
48
49bool KCal::operator==( const Person& p1, const Person& p2 )
50{
51 return ( p1.name() == p2.name() &&
52 p1.email() == p2.email() );
53}
54
55
56TQString Person::fullName() const
57{
58 if( mName.isEmpty() ) {
59 return mEmail;
60 } else {
61 if( mEmail.isEmpty() )
62 return mName;
63 else {
64 // Taken from TDEABC::Addressee::fullEmail
65 TQString name = mName;
66 TQRegExp needQuotes( "[^ 0-9A-Za-z\\x0080-\\xFFFF]" );
67 bool weNeedToQuote = name.find( needQuotes ) != -1;
68 if ( weNeedToQuote ) {
69 if ( name[0] != '"' )
70 name.prepend( '"' );
71 if ( name[ name.length()-1 ] != '"' )
72 name.append( '"' );
73 }
74 return name + " <" + mEmail + ">";
75 }
76 }
77}
78
79bool Person::isEmpty() const
80{
81 return mEmail.isEmpty() && mName.isEmpty();
82}
83
84void Person::setName(const TQString &name)
85{
86 mName = name;
87}
88
89void Person::setEmail(const TQString &email)
90{
91 if ( email.startsWith( "mailto:", false ) ) {
92 mEmail = email.mid(7);
93 } else {
94 mEmail = email;
95 }
96}
This class represents a person.
Definition: person.h:35
Namespace KCal is for global classes, objects and/or functions in libkcal.
Definition: alarm.h:38