summaryrefslogtreecommitdiffabout
path: root/libkcal/incidencebase.cpp
authorzautrix <zautrix>2004-06-26 19:01:18 (UTC)
committer zautrix <zautrix>2004-06-26 19:01:18 (UTC)
commitb9aad1f15dc600e4dbe4c62d3fcced6363188ba3 (patch) (unidiff)
tree2c3d4004fb21c72cba65793859f9bcd8ffd3a49c /libkcal/incidencebase.cpp
downloadkdepimpi-b9aad1f15dc600e4dbe4c62d3fcced6363188ba3.zip
kdepimpi-b9aad1f15dc600e4dbe4c62d3fcced6363188ba3.tar.gz
kdepimpi-b9aad1f15dc600e4dbe4c62d3fcced6363188ba3.tar.bz2
Initial revision
Diffstat (limited to 'libkcal/incidencebase.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r--libkcal/incidencebase.cpp393
1 files changed, 393 insertions, 0 deletions
diff --git a/libkcal/incidencebase.cpp b/libkcal/incidencebase.cpp
new file mode 100644
index 0000000..9479048
--- a/dev/null
+++ b/libkcal/incidencebase.cpp
@@ -0,0 +1,393 @@
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 <kglobal.h>
22#include <klocale.h>
23#include <kdebug.h>
24
25#include "calformat.h"
26
27#include "incidencebase.h"
28
29using namespace KCal;
30
31IncidenceBase::IncidenceBase() :
32 mReadOnly(false), mFloats(true), mDuration(0), mHasDuration(false),
33 mPilotId(0), mSyncStatus(SYNCMOD)
34{
35 setUid(CalFormat::createUniqueId());
36 mOrganizer = "";
37 mFloats = false;
38 mDuration = 0;
39 mHasDuration = false;
40 mPilotId = 0;
41 mZaurusId = -1;
42 mZaurusUid = 0;
43 mZaurusStat = 0;
44 mSyncStatus = 0;
45 mAttendees.setAutoDelete( true );
46}
47
48IncidenceBase::IncidenceBase(const IncidenceBase &i) :
49 CustomProperties( i )
50{
51 mReadOnly = i.mReadOnly;
52 mDtStart = i.mDtStart;
53 mDuration = i.mDuration;
54 mHasDuration = i.mHasDuration;
55 mOrganizer = i.mOrganizer;
56 mUid = i.mUid;
57 QPtrList<Attendee> attendees = i.attendees();
58 for( Attendee *a = attendees.first(); a; a = attendees.next() ) {
59 mAttendees.append( new Attendee( *a ) );
60 }
61 mFloats = i.mFloats;
62 mLastModified = i.mLastModified;
63 mPilotId = i.mPilotId;
64 mZaurusId = i.mZaurusId;
65 mZaurusUid = i.mZaurusUid;
66 mZaurusStat = i.mZaurusStat;
67 mSyncStatus = i.mSyncStatus;
68
69 // The copied object is a new one, so it isn't observed by the observer
70 // of the original object.
71 mObservers.clear();
72
73 mAttendees.setAutoDelete( true );
74}
75
76IncidenceBase::~IncidenceBase()
77{
78}
79
80
81bool KCal::operator==( const IncidenceBase& i1, const IncidenceBase& i2 )
82{
83
84 if( i1.attendees().count() != i2.attendees().count() ) {
85 return false; // no need to check further
86 }
87 if ( i1.attendees().count() > 0 ) {
88 Attendee * a1 = i1.attendees().first(), *a2 =i2.attendees().first() ;
89 while ( a1 ) {
90 if ( !( (*a1) == (*a2)) )
91 {
92 //qDebug("Attendee not equal ");
93 return false;
94 }
95 a1 = i1.attendees().next();
96 a2 = i2.attendees().next();
97 }
98 }
99 //if ( i1.dtStart() != i2.dtStart() )
100 // return false;
101#if 0
102 qDebug("1 %d ",i1.doesFloat() == i2.doesFloat() );
103 qDebug("1 %d ",i1.duration() == i2.duration() );
104 qDebug("3 %d ",i1.hasDuration() == i2.hasDuration() );
105 qDebug("1 %d ",i1.pilotId() == i2.pilotId() );
106 qDebug("1 %d %d %d",i1.syncStatus() == i2.syncStatus() , i1.syncStatus(),i2.syncStatus() );
107 qDebug("6 %d ",i1.organizer() == i2.organizer() );
108
109#endif
110 return ( i1.organizer() == i2.organizer() &&
111 // i1.uid() == i2.uid() &&
112 // Don't compare lastModified, otherwise the operator is not
113 // of much use. We are not comparing for identity, after all.
114 i1.doesFloat() == i2.doesFloat() &&
115 i1.duration() == i2.duration() &&
116 i1.hasDuration() == i2.hasDuration() &&
117 i1.pilotId() == i2.pilotId() );// && i1.syncStatus() == i2.syncStatus() );
118 // no need to compare mObserver
119}
120
121
122QDateTime IncidenceBase::getEvenTime( QDateTime dt )
123{
124 QTime t = dt.time();
125 dt.setTime( QTime (t.hour (), t.minute (), t.second () ) );
126 return dt;
127}
128
129
130void IncidenceBase::setUid(const QString &uid)
131{
132 mUid = uid;
133 updated();
134}
135
136QString IncidenceBase::uid() const
137{
138 return mUid;
139}
140
141void IncidenceBase::setLastModified(const QDateTime &lm)
142{
143 // DON'T! updated() because we call this from
144 // Calendar::updateEvent().
145 mLastModified = getEvenTime(lm);
146 //qDebug("IncidenceBase::setLastModified %s ",lm.toString().latin1());
147}
148
149QDateTime IncidenceBase::lastModified() const
150{
151 return mLastModified;
152}
153
154void IncidenceBase::setOrganizer(const QString &o)
155{
156 // we don't check for readonly here, because it is
157 // possible that by setting the organizer we are changing
158 // the event's readonly status...
159 mOrganizer = o;
160 if (mOrganizer.left(7).upper() == "MAILTO:")
161 mOrganizer = mOrganizer.remove(0,7);
162
163 updated();
164}
165
166QString IncidenceBase::organizer() const
167{
168 return mOrganizer;
169}
170
171void IncidenceBase::setReadOnly( bool readOnly )
172{
173 mReadOnly = readOnly;
174}
175
176void IncidenceBase::setDtStart(const QDateTime &dtStart)
177{
178// if (mReadOnly) return;
179 mDtStart = getEvenTime(dtStart);
180 updated();
181}
182
183QDateTime IncidenceBase::dtStart() const
184{
185 return mDtStart;
186}
187
188QString IncidenceBase::dtStartTimeStr() const
189{
190 return KGlobal::locale()->formatTime(dtStart().time());
191}
192
193QString IncidenceBase::dtStartDateStr(bool shortfmt) const
194{
195 return KGlobal::locale()->formatDate(dtStart().date(),shortfmt);
196}
197
198QString IncidenceBase::dtStartStr(bool shortfmt) const
199{
200 return KGlobal::locale()->formatDateTime(dtStart(), shortfmt);
201}
202
203
204bool IncidenceBase::doesFloat() const
205{
206 return mFloats;
207}
208
209void IncidenceBase::setFloats(bool f)
210{
211 if (mReadOnly) return;
212 mFloats = f;
213 updated();
214}
215
216
217void IncidenceBase::addAttendee(Attendee *a, bool doupdate)
218{
219 if (mReadOnly) return;
220 if (a->name().left(7).upper() == "MAILTO:")
221 a->setName(a->name().remove(0,7));
222
223 mAttendees.append(a);
224 if (doupdate) updated();
225}
226
227#if 0
228void IncidenceBase::removeAttendee(Attendee *a)
229{
230 if (mReadOnly) return;
231 mAttendees.removeRef(a);
232 updated();
233}
234
235void IncidenceBase::removeAttendee(const char *n)
236{
237 Attendee *a;
238
239 if (mReadOnly) return;
240 for (a = mAttendees.first(); a; a = mAttendees.next())
241 if (a->getName() == n) {
242 mAttendees.remove();
243 break;
244 }
245}
246#endif
247
248void IncidenceBase::clearAttendees()
249{
250 if (mReadOnly) return;
251 mAttendees.clear();
252}
253
254#if 0
255Attendee *IncidenceBase::getAttendee(const char *n) const
256{
257 QPtrListIterator<Attendee> qli(mAttendees);
258
259 qli.toFirst();
260 while (qli) {
261 if (qli.current()->getName() == n)
262 return qli.current();
263 ++qli;
264 }
265 return 0L;
266}
267#endif
268
269Attendee *IncidenceBase::attendeeByMail(const QString &email)
270{
271 QPtrListIterator<Attendee> qli(mAttendees);
272
273 qli.toFirst();
274 while (qli) {
275 if (qli.current()->email() == email)
276 return qli.current();
277 ++qli;
278 }
279 return 0L;
280}
281
282Attendee *IncidenceBase::attendeeByMails(const QStringList &emails, const QString& email)
283{
284 QPtrListIterator<Attendee> qli(mAttendees);
285
286 QStringList mails = emails;
287 if (!email.isEmpty()) {
288 mails.append(email);
289 }
290 qli.toFirst();
291 while (qli) {
292 for ( QStringList::Iterator it = mails.begin(); it != mails.end(); ++it ) {
293 if (qli.current()->email() == *it)
294 return qli.current();
295 }
296
297 ++qli;
298 }
299 return 0L;
300}
301
302void IncidenceBase::setDuration(int seconds)
303{
304 mDuration = seconds;
305 setHasDuration(true);
306}
307
308int IncidenceBase::duration() const
309{
310 return mDuration;
311}
312
313void IncidenceBase::setHasDuration(bool b)
314{
315 mHasDuration = b;
316}
317
318bool IncidenceBase::hasDuration() const
319{
320 return mHasDuration;
321}
322
323void IncidenceBase::setSyncStatus(int stat)
324{
325 if (mReadOnly) return;
326 mSyncStatus = stat;
327}
328
329int IncidenceBase::syncStatus() const
330{
331 return mSyncStatus;
332}
333
334void IncidenceBase::setPilotId( int id )
335{
336 if (mReadOnly) return;
337 mPilotId = id;
338}
339
340int IncidenceBase::pilotId() const
341{
342 return mPilotId;
343}
344void IncidenceBase::setZaurusId( int id )
345{
346 if (mReadOnly) return;
347 mZaurusId = id;
348}
349
350int IncidenceBase::zaurusId() const
351{
352 return mZaurusId;
353}
354
355int IncidenceBase::zaurusUid() const
356{
357 return mZaurusUid;
358}
359void IncidenceBase::setZaurusUid( int id )
360{
361 if (mReadOnly) return;
362 mZaurusUid = id;
363}
364
365int IncidenceBase::zaurusStat() const
366{
367 return mZaurusStat;
368}
369void IncidenceBase::setZaurusStat( int id )
370{
371 if (mReadOnly) return;
372 mZaurusStat = id;
373}
374
375void IncidenceBase::registerObserver( IncidenceBase::Observer *observer )
376{
377 if( !mObservers.contains(observer) ) mObservers.append( observer );
378}
379
380void IncidenceBase::unRegisterObserver( IncidenceBase::Observer *observer )
381{
382 mObservers.remove( observer );
383}
384
385void IncidenceBase::updated()
386{
387 QPtrListIterator<Observer> it(mObservers);
388 while( it.current() ) {
389 Observer *o = it.current();
390 ++it;
391 o->incidenceUpdated( this );
392 }
393}