summaryrefslogtreecommitdiffabout
path: root/libkcal/incidencebase.cpp
Unidiff
Diffstat (limited to 'libkcal/incidencebase.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r--libkcal/incidencebase.cpp2
1 files changed, 2 insertions, 0 deletions
diff --git a/libkcal/incidencebase.cpp b/libkcal/incidencebase.cpp
index 2ddbb01..96039df 100644
--- a/libkcal/incidencebase.cpp
+++ b/libkcal/incidencebase.cpp
@@ -1,399 +1,401 @@
1/* 1/*
2 This file is part of libkcal. 2 This file is part of libkcal.
3 Copyright (c) 2001 Cornelius Schumacher <schumacher@kde.org> 3 Copyright (c) 2001 Cornelius Schumacher <schumacher@kde.org>
4 4
5 This library is free software; you can redistribute it and/or 5 This library is free software; you can redistribute it and/or
6 modify it under the terms of the GNU Library General Public 6 modify it under the terms of the GNU Library General Public
7 License as published by the Free Software Foundation; either 7 License as published by the Free Software Foundation; either
8 version 2 of the License, or (at your option) any later version. 8 version 2 of the License, or (at your option) any later version.
9 9
10 This library is distributed in the hope that it will be useful, 10 This library is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of 11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Library General Public License for more details. 13 Library General Public License for more details.
14 14
15 You should have received a copy of the GNU Library General Public License 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 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, 17 the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
18 Boston, MA 02111-1307, USA. 18 Boston, MA 02111-1307, USA.
19*/ 19*/
20 20
21#include <kglobal.h> 21#include <kglobal.h>
22#include <klocale.h> 22#include <klocale.h>
23#include <kdebug.h> 23#include <kdebug.h>
24#include <kidmanager.h> 24#include <kidmanager.h>
25 25
26#include "calformat.h" 26#include "calformat.h"
27#include "syncdefines.h" 27#include "syncdefines.h"
28 28
29#include "incidencebase.h" 29#include "incidencebase.h"
30 30
31using namespace KCal; 31using namespace KCal;
32 32
33IncidenceBase::IncidenceBase() : 33IncidenceBase::IncidenceBase() :
34 mReadOnly(false), mFloats(true), mDuration(0), mHasDuration(false), 34 mReadOnly(false), mFloats(true), mDuration(0), mHasDuration(false),
35 mPilotId(0), mSyncStatus(SYNCMOD) 35 mPilotId(0), mSyncStatus(SYNCMOD)
36{ 36{
37 setUid(CalFormat::createUniqueId()); 37 setUid(CalFormat::createUniqueId());
38 mOrganizer = ""; 38 mOrganizer = "";
39 mFloats = false; 39 mFloats = false;
40 mDuration = 0; 40 mDuration = 0;
41 mHasDuration = false; 41 mHasDuration = false;
42 mPilotId = 0; 42 mPilotId = 0;
43 mExternalId = ":"; 43 mExternalId = ":";
44 mTempSyncStat = SYNC_TEMPSTATE_INITIAL; 44 mTempSyncStat = SYNC_TEMPSTATE_INITIAL;
45 mSyncStatus = 0; 45 mSyncStatus = 0;
46 mAttendees.setAutoDelete( true ); 46 mAttendees.setAutoDelete( true );
47 mCalEnabled = true; 47 mCalEnabled = true;
48 mAlarmEnabled = true; 48 mAlarmEnabled = true;
49 mCalID = 0; 49 mCalID = 0;
50} 50}
51 51
52IncidenceBase::IncidenceBase(const IncidenceBase &i) : 52IncidenceBase::IncidenceBase(const IncidenceBase &i) :
53 CustomProperties( i ) 53 CustomProperties( i )
54{ 54{
55 55
56 mReadOnly = i.mReadOnly; 56 mReadOnly = i.mReadOnly;
57 mDtStart = i.mDtStart; 57 mDtStart = i.mDtStart;
58 mDuration = i.mDuration; 58 mDuration = i.mDuration;
59 mHasDuration = i.mHasDuration; 59 mHasDuration = i.mHasDuration;
60 mOrganizer = i.mOrganizer; 60 mOrganizer = i.mOrganizer;
61 mUid = i.mUid; 61 mUid = i.mUid;
62 mCalEnabled = i.mCalEnabled; 62 mCalEnabled = i.mCalEnabled;
63 mAlarmEnabled = i.mAlarmEnabled; 63 mAlarmEnabled = i.mAlarmEnabled;
64 mCalID = i.mCalID; 64 mCalID = i.mCalID;
65 QPtrList<Attendee> attendees = i.attendees(); 65 QPtrList<Attendee> attendees = i.attendees();
66 for( Attendee *a = attendees.first(); a; a = attendees.next() ) { 66 for( Attendee *a = attendees.first(); a; a = attendees.next() ) {
67 mAttendees.append( new Attendee( *a ) ); 67 mAttendees.append( new Attendee( *a ) );
68 } 68 }
69 mFloats = i.mFloats; 69 mFloats = i.mFloats;
70 mLastModified = i.mLastModified; 70 mLastModified = i.mLastModified;
71 mPilotId = i.mPilotId; 71 mPilotId = i.mPilotId;
72 mTempSyncStat = i.mTempSyncStat; 72 mTempSyncStat = i.mTempSyncStat;
73 mSyncStatus = i.mSyncStatus; 73 mSyncStatus = i.mSyncStatus;
74 mExternalId = i.mExternalId; 74 mExternalId = i.mExternalId;
75 // The copied object is a new one, so it isn't observed by the observer 75 // The copied object is a new one, so it isn't observed by the observer
76 // of the original object. 76 // of the original object.
77 mObservers.clear(); 77 mObservers.clear();
78 78
79 mAttendees.setAutoDelete( true ); 79 mAttendees.setAutoDelete( true );
80} 80}
81 81
82IncidenceBase::~IncidenceBase() 82IncidenceBase::~IncidenceBase()
83{ 83{
84} 84}
85 85
86 86
87bool KCal::operator==( const IncidenceBase& i1, const IncidenceBase& i2 ) 87bool KCal::operator==( const IncidenceBase& i1, const IncidenceBase& i2 )
88{ 88{
89 // do not compare mSyncStatus and mExternalId 89 // do not compare mSyncStatus and mExternalId
90 if( i1.attendees().count() != i2.attendees().count() ) { 90 if( i1.attendees().count() != i2.attendees().count() ) {
91 return false; // no need to check further 91 return false; // no need to check further
92 } 92 }
93 if ( i1.attendees().count() > 0 ) { 93 if ( i1.attendees().count() > 0 ) {
94 Attendee * a1 = i1.attendees().first(), *a2 =i2.attendees().first() ; 94 Attendee * a1 = i1.attendees().first(), *a2 =i2.attendees().first() ;
95 while ( a1 ) { 95 while ( a1 ) {
96 if ( !( (*a1) == (*a2)) ) 96 if ( !( (*a1) == (*a2)) )
97 { 97 {
98 //qDebug("Attendee not equal "); 98 //qDebug("Attendee not equal ");
99 return false; 99 return false;
100 } 100 }
101 a1 = i1.attendees().next(); 101 a1 = i1.attendees().next();
102 a2 = i2.attendees().next(); 102 a2 = i2.attendees().next();
103 } 103 }
104 } 104 }
105 //if ( i1.dtStart() != i2.dtStart() ) 105 //if ( i1.dtStart() != i2.dtStart() )
106 // return false; 106 // return false;
107#if 0 107#if 0
108 qDebug("1 %d ",i1.doesFloat() == i2.doesFloat() ); 108 qDebug("1 %d ",i1.doesFloat() == i2.doesFloat() );
109 qDebug("1 %d ",i1.duration() == i2.duration() ); 109 qDebug("1 %d ",i1.duration() == i2.duration() );
110 qDebug("3 %d ",i1.hasDuration() == i2.hasDuration() ); 110 qDebug("3 %d ",i1.hasDuration() == i2.hasDuration() );
111 qDebug("1 %d ",i1.pilotId() == i2.pilotId() ); 111 qDebug("1 %d ",i1.pilotId() == i2.pilotId() );
112 qDebug("1 %d %d %d",i1.syncStatus() == i2.syncStatus() , i1.syncStatus(),i2.syncStatus() ); 112 qDebug("1 %d %d %d",i1.syncStatus() == i2.syncStatus() , i1.syncStatus(),i2.syncStatus() );
113 qDebug("6 %d ",i1.organizer() == i2.organizer() ); 113 qDebug("6 %d ",i1.organizer() == i2.organizer() );
114 114
115#endif 115#endif
116 if ( i1.hasDuration() == i2.hasDuration() ) { 116 if ( i1.hasDuration() == i2.hasDuration() ) {
117 if ( i1.hasDuration() ) { 117 if ( i1.hasDuration() ) {
118 if ( i1.duration() != i2.duration() ) 118 if ( i1.duration() != i2.duration() )
119 return false; 119 return false;
120 } 120 }
121 } else { 121 } else {
122 return false; 122 return false;
123 } 123 }
124 124
125 return ( i1.organizer() == i2.organizer() && 125 return ( i1.organizer() == i2.organizer() &&
126 // i1.uid() == i2.uid() && 126 // i1.uid() == i2.uid() &&
127 // Don't compare lastModified, otherwise the operator is not 127 // Don't compare lastModified, otherwise the operator is not
128 // of much use. We are not comparing for identity, after all. 128 // of much use. We are not comparing for identity, after all.
129 i1.doesFloat() == i2.doesFloat() && 129 i1.doesFloat() == i2.doesFloat() &&
130 i1.pilotId() == i2.pilotId() );// && i1.syncStatus() == i2.syncStatus() ); 130 i1.pilotId() == i2.pilotId() );// && i1.syncStatus() == i2.syncStatus() );
131 // no need to compare mObserver 131 // no need to compare mObserver
132} 132}
133 133
134 134
135QDateTime IncidenceBase::getEvenTime( QDateTime dt ) 135QDateTime IncidenceBase::getEvenTime( QDateTime dt )
136{ 136{
137 QTime t = dt.time(); 137 QTime t = dt.time();
138 dt.setTime( QTime (t.hour (), t.minute (), t.second () ) ); 138 dt.setTime( QTime (t.hour (), t.minute (), t.second () ) );
139 return dt; 139 return dt;
140} 140}
141 141
142void IncidenceBase::setCalID( int id ) 142void IncidenceBase::setCalID( int id )
143{ 143{
144 if ( mCalID > 0 )
145 updated();
144 mCalID = id; 146 mCalID = id;
145} 147}
146int IncidenceBase::calID() const 148int IncidenceBase::calID() const
147{ 149{
148 return mCalID; 150 return mCalID;
149} 151}
150void IncidenceBase::setCalEnabled( bool b ) 152void IncidenceBase::setCalEnabled( bool b )
151{ 153{
152 mCalEnabled = b; 154 mCalEnabled = b;
153} 155}
154bool IncidenceBase::calEnabled() const 156bool IncidenceBase::calEnabled() const
155{ 157{
156 return mCalEnabled; 158 return mCalEnabled;
157} 159}
158 160
159void IncidenceBase::setAlarmEnabled( bool b ) 161void IncidenceBase::setAlarmEnabled( bool b )
160{ 162{
161 mAlarmEnabled = b; 163 mAlarmEnabled = b;
162} 164}
163bool IncidenceBase::alarmEnabled() const 165bool IncidenceBase::alarmEnabled() const
164{ 166{
165 return mAlarmEnabled; 167 return mAlarmEnabled;
166} 168}
167 169
168 170
169void IncidenceBase::setUid(const QString &uid) 171void IncidenceBase::setUid(const QString &uid)
170{ 172{
171 mUid = uid; 173 mUid = uid;
172 updated(); 174 updated();
173} 175}
174 176
175QString IncidenceBase::uid() const 177QString IncidenceBase::uid() const
176{ 178{
177 return mUid; 179 return mUid;
178} 180}
179 181
180void IncidenceBase::setLastModified(const QDateTime &lm) 182void IncidenceBase::setLastModified(const QDateTime &lm)
181{ 183{
182 // DON'T! updated() because we call this from 184 // DON'T! updated() because we call this from
183 // Calendar::updateEvent(). 185 // Calendar::updateEvent().
184 mLastModified = getEvenTime(lm); 186 mLastModified = getEvenTime(lm);
185 //qDebug("IncidenceBase::setLastModified %s ",lm.toString().latin1()); 187 //qDebug("IncidenceBase::setLastModified %s ",lm.toString().latin1());
186} 188}
187 189
188QDateTime IncidenceBase::lastModified() const 190QDateTime IncidenceBase::lastModified() const
189{ 191{
190 return mLastModified; 192 return mLastModified;
191} 193}
192 194
193void IncidenceBase::setOrganizer(const QString &o) 195void IncidenceBase::setOrganizer(const QString &o)
194{ 196{
195 // we don't check for readonly here, because it is 197 // we don't check for readonly here, because it is
196 // possible that by setting the organizer we are changing 198 // possible that by setting the organizer we are changing
197 // the event's readonly status... 199 // the event's readonly status...
198 mOrganizer = o; 200 mOrganizer = o;
199 if (mOrganizer.left(7).upper() == "MAILTO:") 201 if (mOrganizer.left(7).upper() == "MAILTO:")
200 mOrganizer = mOrganizer.remove(0,7); 202 mOrganizer = mOrganizer.remove(0,7);
201 203
202 updated(); 204 updated();
203} 205}
204 206
205QString IncidenceBase::organizer() const 207QString IncidenceBase::organizer() const
206{ 208{
207 return mOrganizer; 209 return mOrganizer;
208} 210}
209 211
210void IncidenceBase::setReadOnly( bool readOnly ) 212void IncidenceBase::setReadOnly( bool readOnly )
211{ 213{
212 mReadOnly = readOnly; 214 mReadOnly = readOnly;
213} 215}
214 216
215void IncidenceBase::setDtStart(const QDateTime &dtStart) 217void IncidenceBase::setDtStart(const QDateTime &dtStart)
216{ 218{
217// if (mReadOnly) return; 219// if (mReadOnly) return;
218 mDtStart = getEvenTime(dtStart); 220 mDtStart = getEvenTime(dtStart);
219 updated(); 221 updated();
220} 222}
221 223
222 224
223QDateTime IncidenceBase::dtStart() const 225QDateTime IncidenceBase::dtStart() const
224{ 226{
225 return mDtStart; 227 return mDtStart;
226} 228}
227 229
228QString IncidenceBase::dtStartTimeStr() const 230QString IncidenceBase::dtStartTimeStr() const
229{ 231{
230 return KGlobal::locale()->formatTime(dtStart().time()); 232 return KGlobal::locale()->formatTime(dtStart().time());
231} 233}
232 234
233QString IncidenceBase::dtStartDateStr(bool shortfmt) const 235QString IncidenceBase::dtStartDateStr(bool shortfmt) const
234{ 236{
235 return KGlobal::locale()->formatDate(dtStart().date(),shortfmt); 237 return KGlobal::locale()->formatDate(dtStart().date(),shortfmt);
236} 238}
237 239
238QString IncidenceBase::dtStartStr(bool shortfmt) const 240QString IncidenceBase::dtStartStr(bool shortfmt) const
239{ 241{
240 if ( doesFloat() ) 242 if ( doesFloat() )
241 return KGlobal::locale()->formatDate(dtStart().date(),shortfmt); 243 return KGlobal::locale()->formatDate(dtStart().date(),shortfmt);
242 return KGlobal::locale()->formatDateTime(dtStart(), shortfmt); 244 return KGlobal::locale()->formatDateTime(dtStart(), shortfmt);
243} 245}
244 246
245 247
246bool IncidenceBase::doesFloat() const 248bool IncidenceBase::doesFloat() const
247{ 249{
248 return mFloats; 250 return mFloats;
249} 251}
250 252
251void IncidenceBase::setFloats(bool f) 253void IncidenceBase::setFloats(bool f)
252{ 254{
253 if (mReadOnly) return; 255 if (mReadOnly) return;
254 mFloats = f; 256 mFloats = f;
255 updated(); 257 updated();
256} 258}
257 259
258 260
259bool IncidenceBase::addAttendee(Attendee *a, bool doupdate) 261bool IncidenceBase::addAttendee(Attendee *a, bool doupdate)
260{ 262{
261 if (mReadOnly) return false; 263 if (mReadOnly) return false;
262 if (a->name().left(7).upper() == "MAILTO:") 264 if (a->name().left(7).upper() == "MAILTO:")
263 a->setName(a->name().remove(0,7)); 265 a->setName(a->name().remove(0,7));
264 266
265 QPtrListIterator<Attendee> qli(mAttendees); 267 QPtrListIterator<Attendee> qli(mAttendees);
266 268
267 qli.toFirst(); 269 qli.toFirst();
268 while (qli) { 270 while (qli) {
269 if (*qli.current() == *a) 271 if (*qli.current() == *a)
270 return false; 272 return false;
271 ++qli; 273 ++qli;
272 } 274 }
273 mAttendees.append(a); 275 mAttendees.append(a);
274 if (doupdate) updated(); 276 if (doupdate) updated();
275 return true; 277 return true;
276} 278}
277 279
278#if 0 280#if 0
279void IncidenceBase::removeAttendee(Attendee *a) 281void IncidenceBase::removeAttendee(Attendee *a)
280{ 282{
281 if (mReadOnly) return; 283 if (mReadOnly) return;
282 mAttendees.removeRef(a); 284 mAttendees.removeRef(a);
283 updated(); 285 updated();
284} 286}
285 287
286void IncidenceBase::removeAttendee(const char *n) 288void IncidenceBase::removeAttendee(const char *n)
287{ 289{
288 Attendee *a; 290 Attendee *a;
289 291
290 if (mReadOnly) return; 292 if (mReadOnly) return;
291 for (a = mAttendees.first(); a; a = mAttendees.next()) 293 for (a = mAttendees.first(); a; a = mAttendees.next())
292 if (a->getName() == n) { 294 if (a->getName() == n) {
293 mAttendees.remove(); 295 mAttendees.remove();
294 break; 296 break;
295 } 297 }
296} 298}
297#endif 299#endif
298 300
299void IncidenceBase::clearAttendees() 301void IncidenceBase::clearAttendees()
300{ 302{
301 if (mReadOnly) return; 303 if (mReadOnly) return;
302 mAttendees.clear(); 304 mAttendees.clear();
303} 305}
304 306
305#if 0 307#if 0
306Attendee *IncidenceBase::getAttendee(const char *n) const 308Attendee *IncidenceBase::getAttendee(const char *n) const
307{ 309{
308 QPtrListIterator<Attendee> qli(mAttendees); 310 QPtrListIterator<Attendee> qli(mAttendees);
309 311
310 qli.toFirst(); 312 qli.toFirst();
311 while (qli) { 313 while (qli) {
312 if (qli.current()->getName() == n) 314 if (qli.current()->getName() == n)
313 return qli.current(); 315 return qli.current();
314 ++qli; 316 ++qli;
315 } 317 }
316 return 0L; 318 return 0L;
317} 319}
318#endif 320#endif
319 321
320Attendee *IncidenceBase::attendeeByMail(const QString &email) 322Attendee *IncidenceBase::attendeeByMail(const QString &email)
321{ 323{
322 QPtrListIterator<Attendee> qli(mAttendees); 324 QPtrListIterator<Attendee> qli(mAttendees);
323 325
324 qli.toFirst(); 326 qli.toFirst();
325 while (qli) { 327 while (qli) {
326 if (qli.current()->email().lower() == email.lower()) 328 if (qli.current()->email().lower() == email.lower())
327 return qli.current(); 329 return qli.current();
328 ++qli; 330 ++qli;
329 } 331 }
330 return 0L; 332 return 0L;
331} 333}
332 334
333Attendee *IncidenceBase::attendeeByMails(const QStringList &emails, const QString& email) 335Attendee *IncidenceBase::attendeeByMails(const QStringList &emails, const QString& email)
334{ 336{
335 QPtrListIterator<Attendee> qli(mAttendees); 337 QPtrListIterator<Attendee> qli(mAttendees);
336 338
337 QStringList mails = emails; 339 QStringList mails = emails;
338 if (!email.isEmpty()) { 340 if (!email.isEmpty()) {
339 mails.append(email); 341 mails.append(email);
340 } 342 }
341 qli.toFirst(); 343 qli.toFirst();
342 while (qli) { 344 while (qli) {
343 for ( QStringList::Iterator it = mails.begin(); it != mails.end(); ++it ) { 345 for ( QStringList::Iterator it = mails.begin(); it != mails.end(); ++it ) {
344 if (qli.current()->email().lower() == (*it).lower()) 346 if (qli.current()->email().lower() == (*it).lower())
345 return qli.current(); 347 return qli.current();
346 } 348 }
347 349
348 ++qli; 350 ++qli;
349 } 351 }
350 return 0L; 352 return 0L;
351} 353}
352 354
353void IncidenceBase::setDuration(int seconds) 355void IncidenceBase::setDuration(int seconds)
354{ 356{
355 mDuration = seconds; 357 mDuration = seconds;
356 setHasDuration(true); 358 setHasDuration(true);
357} 359}
358 360
359int IncidenceBase::duration() const 361int IncidenceBase::duration() const
360{ 362{
361 return mDuration; 363 return mDuration;
362} 364}
363 365
364void IncidenceBase::setHasDuration(bool b) 366void IncidenceBase::setHasDuration(bool b)
365{ 367{
366 mHasDuration = b; 368 mHasDuration = b;
367} 369}
368 370
369bool IncidenceBase::hasDuration() const 371bool IncidenceBase::hasDuration() const
370{ 372{
371 return mHasDuration; 373 return mHasDuration;
372} 374}
373 375
374void IncidenceBase::setSyncStatus(int stat) 376void IncidenceBase::setSyncStatus(int stat)
375{ 377{
376 if (mReadOnly) return; 378 if (mReadOnly) return;
377 mSyncStatus = stat; 379 mSyncStatus = stat;
378} 380}
379 381
380int IncidenceBase::syncStatus() const 382int IncidenceBase::syncStatus() const
381{ 383{
382 return mSyncStatus; 384 return mSyncStatus;
383} 385}
384 386
385void IncidenceBase::setPilotId( int id ) 387void IncidenceBase::setPilotId( int id )
386{ 388{
387 if (mReadOnly) return; 389 if (mReadOnly) return;
388 mPilotId = id; 390 mPilotId = id;
389} 391}
390 392
391int IncidenceBase::pilotId() const 393int IncidenceBase::pilotId() const
392{ 394{
393 return mPilotId; 395 return mPilotId;
394} 396}
395 397
396int IncidenceBase::tempSyncStat() const 398int IncidenceBase::tempSyncStat() const
397{ 399{
398 return mTempSyncStat; 400 return mTempSyncStat;
399} 401}