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