1/*
2 This file is part of the kcal library.
3
4 Copyright (c) 2001 Cornelius Schumacher <schumacher@kde.org>
5
6 This library is free software; you can redistribute it and/or
7 modify it under the terms of the GNU Library General Public
8 License as published by the Free Software Foundation; either
9 version 2 of the License, or (at your option) any later version.
10
11 This library is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 Library General Public License for more details.
15
16 You should have received a copy of the GNU Library General Public License
17 along with this library; see the file COPYING.LIB. If not, write to
18 the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
19 Boston, MA 02110-1301, USA.
20*/
21/**
22 @file
23 This file is part of the API for handling calendar data and
24 defines the Attendee class.
25
26 @brief
27 Represents information related to an attendee of an Calendar Incidence.
28
29 @author Cornelius Schumacher \<schumacher@kde.org\>
30*/
31
32#include "attendee.h"
33
34#include <kdebug.h>
35#include <klocalizedstring.h>
36#include <kglobal.h>
37
38#include <QtCore/QStringList>
39
40static const KCatalogLoader loader("libkcal");
41
42using namespace KCal;
43
44/**
45 Private class that helps to provide binary compatibility between releases.
46 @internal
47*/
48//@cond PRIVATE
49class KCal::Attendee::Private
50{
51 public:
52 bool mRSVP;
53 Role mRole;
54 PartStat mStatus;
55 QString mUid;
56 QString mDelegate;
57 QString mDelegator;
58 CustomProperties mCustomProperties;
59};
60//@endcond
61
62Attendee::Attendee( const QString &name, const QString &email, bool rsvp,
63 Attendee::PartStat status, Attendee::Role role, const QString &uid )
64 : d( new Attendee::Private )
65{
66 setName( name );
67 setEmail( email );
68 d->mRSVP = rsvp;
69 d->mStatus = status;
70 d->mRole = role;
71 d->mUid = uid;
72}
73
74Attendee::Attendee( const Attendee &attendee )
75 : Person( attendee ),
76 d( new Attendee::Private( *attendee.d ) )
77{
78}
79
80Attendee::~Attendee()
81{
82 delete d;
83}
84
85bool KCal::Attendee::operator==( const Attendee &attendee )
86{
87 return
88 ( Person & )*this == ( const Person & )attendee &&
89 d->mRSVP == attendee.d->mRSVP &&
90 d->mRole == attendee.d->mRole &&
91 d->mStatus == attendee.d->mStatus &&
92 d->mUid == attendee.d->mUid &&
93 d->mDelegate == attendee.d->mDelegate &&
94 d->mDelegator == attendee.d->mDelegator;
95}
96
97Attendee &KCal::Attendee::operator=( const Attendee &attendee )
98{
99 // check for self assignment
100 if ( &attendee == this ) {
101 return *this;
102 }
103
104 *d = *attendee.d;
105 setName( attendee.name() );
106 setEmail( attendee.email() );
107 return *this;
108}
109
110void Attendee::setRSVP( bool r )
111{
112 d->mRSVP = r;
113}
114
115bool Attendee::RSVP() const
116{
117 return d->mRSVP;
118}
119
120void Attendee::setStatus( Attendee::PartStat status )
121{
122 d->mStatus = status;
123}
124
125Attendee::PartStat Attendee::status() const
126{
127 return d->mStatus;
128}
129
130QString Attendee::statusStr() const
131{
132 return statusName( d->mStatus );
133}
134
135QString Attendee::statusName( Attendee::PartStat status )
136{
137 switch ( status ) {
138 default:
139 case NeedsAction:
140 return i18nc( "@item event, to-do or journal needs action", "Needs Action" );
141 break;
142 case Accepted:
143 return i18nc( "@item event, to-do or journal accepted", "Accepted" );
144 break;
145 case Declined:
146 return i18nc( "@item event, to-do or journal declined", "Declined" );
147 break;
148 case Tentative:
149 return i18nc( "@item event or to-do tentatively accepted", "Tentative" );
150 break;
151 case Delegated:
152 return i18nc( "@item event or to-do delegated", "Delegated" );
153 break;
154 case Completed:
155 return i18nc( "@item to-do completed", "Completed" );
156 break;
157 case InProcess:
158 return i18nc( "@item to-do in process of being completed", "In Process" );
159 break;
160 case None:
161 return i18nc( "@item event or to-do status unknown", "Unknown" );
162 break;
163 }
164}
165
166QStringList Attendee::statusList()
167{
168 QStringList list;
169 list << statusName( NeedsAction );
170 list << statusName( Accepted );
171 list << statusName( Declined );
172 list << statusName( Tentative );
173 list << statusName( Delegated );
174 list << statusName( Completed );
175 list << statusName( InProcess );
176
177 return list;
178}
179
180void Attendee::setRole( Attendee::Role role )
181{
182 d->mRole = role;
183}
184
185Attendee::Role Attendee::role() const
186{
187 return d->mRole;
188}
189
190QString Attendee::roleStr() const
191{
192 return roleName( d->mRole );
193}
194
195void Attendee::setUid( const QString &uid )
196{
197 d->mUid = uid;
198}
199
200QString Attendee::uid() const
201{
202 return d->mUid;
203}
204
205QString Attendee::roleName( Attendee::Role role )
206{
207 switch ( role ) {
208 case Chair:
209 return i18nc( "@item chairperson", "Chair" );
210 break;
211 default:
212 case ReqParticipant:
213 return i18nc( "@item participation is required", "Participant" );
214 break;
215 case OptParticipant:
216 return i18nc( "@item participation is optional", "Optional Participant" );
217 break;
218 case NonParticipant:
219 return i18nc( "@item non-participant copied for information", "Observer" );
220 break;
221 }
222}
223
224QStringList Attendee::roleList()
225{
226 QStringList list;
227 list << roleName( ReqParticipant );
228 list << roleName( OptParticipant );
229 list << roleName( NonParticipant );
230 list << roleName( Chair );
231
232 return list;
233}
234
235void Attendee::setDelegate( const QString &delegate )
236{
237 d->mDelegate = delegate;
238}
239
240QString Attendee::delegate() const
241{
242 return d->mDelegate;
243}
244
245void Attendee::setDelegator( const QString &delegator )
246{
247 d->mDelegator = delegator;
248}
249
250QString Attendee::delegator() const
251{
252 return d->mDelegator;
253}
254
255void Attendee::setCustomProperty( const QByteArray &xname, const QString &xvalue )
256{
257 d->mCustomProperties.setNonKDECustomProperty( xname, xvalue );
258}
259
260CustomProperties &Attendee::customProperties()
261{
262 return d->mCustomProperties;
263}
264
265const CustomProperties &Attendee::customProperties() const
266{
267 return d->mCustomProperties;
268}
269