summaryrefslogtreecommitdiffabout
path: root/libkcal/person.cpp
Unidiff
Diffstat (limited to 'libkcal/person.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r--libkcal/person.cpp77
1 files changed, 77 insertions, 0 deletions
diff --git a/libkcal/person.cpp b/libkcal/person.cpp
new file mode 100644
index 0000000..aca28c2
--- a/dev/null
+++ b/libkcal/person.cpp
@@ -0,0 +1,77 @@
1/*
2 This file is part of libkcal.
3 Copyright (c) 2001 Cornelius Schumacher <schumacher@kde.org>
4
5 This library is free software; you can redistribute it and/or
6 modify it under the terms of the GNU Library General Public
7 License as published by the Free Software Foundation; either
8 version 2 of the License, or (at your option) any later version.
9
10 This library is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Library General Public License for more details.
14
15 You should have received a copy of the GNU Library General Public License
16 along with this library; see the file COPYING.LIB. If not, write to
17 the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
18 Boston, MA 02111-1307, USA.
19*/
20
21#include <kdebug.h>
22#include <klocale.h>
23
24#include "person.h"
25
26using namespace KCal;
27
28Person::Person( const QString &fullName )
29{
30 int emailPos = fullName.find( '<' );
31 if ( emailPos < 0 ) {
32 setEmail(fullName);
33 } else {
34 setEmail(fullName.mid( emailPos + 1, fullName.length() - 1 ));
35 setName(fullName.left( emailPos - 2 ));
36 }
37}
38
39Person::Person( const QString &name, const QString &email )
40{
41 setName(name);
42 setEmail(email);
43}
44
45
46bool KCal::operator==( const Person& p1, const Person& p2 )
47{
48 return ( p1.name() == p2.name() &&
49 p1.email() == p2.email() );
50}
51
52
53QString Person::fullName() const
54{
55 if( mName.isEmpty() ) {
56 return mEmail;
57 } else {
58 if( mEmail.isEmpty() )
59 return mName;
60 else
61 return mName + " <" + mEmail + ">";
62 }
63}
64
65void Person::setName(const QString &name)
66{
67 mName = name;
68}
69
70void Person::setEmail(const QString &email)
71{
72 if (email.left(7).lower() == "mailto:") {
73 mEmail = email.mid(7);
74 } else {
75 mEmail = email;
76 }
77}