summaryrefslogtreecommitdiffabout
path: root/libkcal/incidence.cpp
Unidiff
Diffstat (limited to 'libkcal/incidence.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r--libkcal/incidence.cpp2
1 files changed, 1 insertions, 1 deletions
diff --git a/libkcal/incidence.cpp b/libkcal/incidence.cpp
index 55ac6d4..5a9ef0e 100644
--- a/libkcal/incidence.cpp
+++ b/libkcal/incidence.cpp
@@ -1,376 +1,376 @@
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 24
25#include "calformat.h" 25#include "calformat.h"
26 26
27#include "incidence.h" 27#include "incidence.h"
28#include "todo.h" 28#include "todo.h"
29 29
30using namespace KCal; 30using namespace KCal;
31 31
32Incidence::Incidence() : 32Incidence::Incidence() :
33 IncidenceBase(), 33 IncidenceBase(),
34 mRelatedTo(0), mSecrecy(SecrecyPublic), mPriority(3) 34 mRelatedTo(0), mSecrecy(SecrecyPublic), mPriority(3)
35{ 35{
36 mRecurrence = new Recurrence(this); 36 mRecurrence = new Recurrence(this);
37 mCancelled = false; 37 mCancelled = false;
38 recreate(); 38 recreate();
39 mHasStartDate = true; 39 mHasStartDate = true;
40 mAlarms.setAutoDelete(true); 40 mAlarms.setAutoDelete(true);
41 mAttachments.setAutoDelete(true); 41 mAttachments.setAutoDelete(true);
42} 42}
43 43
44Incidence::Incidence( const Incidence &i ) : IncidenceBase( i ) 44Incidence::Incidence( const Incidence &i ) : IncidenceBase( i )
45{ 45{
46// TODO: reenable attributes currently commented out. 46// TODO: reenable attributes currently commented out.
47 mRevision = i.mRevision; 47 mRevision = i.mRevision;
48 mCreated = i.mCreated; 48 mCreated = i.mCreated;
49 mDescription = i.mDescription; 49 mDescription = i.mDescription;
50 mSummary = i.mSummary; 50 mSummary = i.mSummary;
51 mCategories = i.mCategories; 51 mCategories = i.mCategories;
52// Incidence *mRelatedTo; Incidence *mRelatedTo; 52// Incidence *mRelatedTo; Incidence *mRelatedTo;
53 mRelatedTo = 0; 53 mRelatedTo = 0;
54 mRelatedToUid = i.mRelatedToUid; 54 mRelatedToUid = i.mRelatedToUid;
55// QPtrList<Incidence> mRelations; QPtrList<Incidence> mRelations; 55// QPtrList<Incidence> mRelations; QPtrList<Incidence> mRelations;
56 mExDates = i.mExDates; 56 mExDates = i.mExDates;
57 mAttachments = i.mAttachments; 57 mAttachments = i.mAttachments;
58 mResources = i.mResources; 58 mResources = i.mResources;
59 mSecrecy = i.mSecrecy; 59 mSecrecy = i.mSecrecy;
60 mPriority = i.mPriority; 60 mPriority = i.mPriority;
61 mLocation = i.mLocation; 61 mLocation = i.mLocation;
62 mCancelled = i.mCancelled; 62 mCancelled = i.mCancelled;
63 mHasStartDate = i.mHasStartDate; 63 mHasStartDate = i.mHasStartDate;
64 QPtrListIterator<Alarm> it( i.mAlarms ); 64 QPtrListIterator<Alarm> it( i.mAlarms );
65 const Alarm *a; 65 const Alarm *a;
66 while( (a = it.current()) ) { 66 while( (a = it.current()) ) {
67 Alarm *b = new Alarm( *a ); 67 Alarm *b = new Alarm( *a );
68 b->setParent( this ); 68 b->setParent( this );
69 mAlarms.append( b ); 69 mAlarms.append( b );
70 70
71 ++it; 71 ++it;
72 } 72 }
73 mAlarms.setAutoDelete(true); 73 mAlarms.setAutoDelete(true);
74 74
75 mRecurrence = new Recurrence( *(i.mRecurrence), this ); 75 mRecurrence = new Recurrence( *(i.mRecurrence), this );
76} 76}
77 77
78Incidence::~Incidence() 78Incidence::~Incidence()
79{ 79{
80 80
81 Incidence *ev; 81 Incidence *ev;
82 QPtrList<Incidence> Relations = relations(); 82 QPtrList<Incidence> Relations = relations();
83 for (ev=Relations.first();ev;ev=Relations.next()) { 83 for (ev=Relations.first();ev;ev=Relations.next()) {
84 if (ev->relatedTo() == this) ev->setRelatedTo(0); 84 if (ev->relatedTo() == this) ev->setRelatedTo(0);
85 } 85 }
86 if (relatedTo()) relatedTo()->removeRelation(this); 86 if (relatedTo()) relatedTo()->removeRelation(this);
87 delete mRecurrence; 87 delete mRecurrence;
88 88
89} 89}
90 90
91bool Incidence::cancelled() const 91bool Incidence::cancelled() const
92{ 92{
93 return mCancelled; 93 return mCancelled;
94} 94}
95void Incidence::setCancelled( bool b ) 95void Incidence::setCancelled( bool b )
96{ 96{
97 mCancelled = b; 97 mCancelled = b;
98 updated(); 98 updated();
99} 99}
100bool Incidence::hasStartDate() const 100bool Incidence::hasStartDate() const
101{ 101{
102 return mHasStartDate; 102 return mHasStartDate;
103} 103}
104 104
105void Incidence::setHasStartDate(bool f) 105void Incidence::setHasStartDate(bool f)
106{ 106{
107 if (mReadOnly) return; 107 if (mReadOnly) return;
108 mHasStartDate = f; 108 mHasStartDate = f;
109 updated(); 109 updated();
110} 110}
111 111
112// A string comparison that considers that null and empty are the same 112// A string comparison that considers that null and empty are the same
113static bool stringCompare( const QString& s1, const QString& s2 ) 113static bool stringCompare( const QString& s1, const QString& s2 )
114{ 114{
115 if ( s1.isEmpty() && s2.isEmpty() ) 115 if ( s1.isEmpty() && s2.isEmpty() )
116 return true; 116 return true;
117 return s1 == s2; 117 return s1 == s2;
118} 118}
119 119
120bool KCal::operator==( const Incidence& i1, const Incidence& i2 ) 120bool KCal::operator==( const Incidence& i1, const Incidence& i2 )
121{ 121{
122 122
123 if( i1.alarms().count() != i2.alarms().count() ) { 123 if( i1.alarms().count() != i2.alarms().count() ) {
124 return false; // no need to check further 124 return false; // no need to check further
125 } 125 }
126 if ( i1.alarms().count() > 0 ) { 126 if ( i1.alarms().count() > 0 ) {
127 if ( !( *(i1.alarms().first()) == *(i2.alarms().first())) ) 127 if ( !( *(i1.alarms().first()) == *(i2.alarms().first())) )
128 { 128 {
129 qDebug("alarm not equal "); 129 qDebug("alarm not equal ");
130 return false; 130 return false;
131 } 131 }
132 } 132 }
133#if 0 133#if 0
134 QPtrListIterator<Alarm> a1( i1.alarms() ); 134 QPtrListIterator<Alarm> a1( i1.alarms() );
135 QPtrListIterator<Alarm> a2( i2.alarms() ); 135 QPtrListIterator<Alarm> a2( i2.alarms() );
136 for( ; a1.current() && a2.current(); ++a1, ++a2 ) { 136 for( ; a1.current() && a2.current(); ++a1, ++a2 ) {
137 if( *a1.current() == *a2.current() ) { 137 if( *a1.current() == *a2.current() ) {
138 continue; 138 continue;
139 } 139 }
140 else { 140 else {
141 return false; 141 return false;
142 } 142 }
143 } 143 }
144#endif 144#endif
145 145
146 if ( ! operator==( (const IncidenceBase&)i1, (const IncidenceBase&)i2 ) ) 146 if ( ! operator==( (const IncidenceBase&)i1, (const IncidenceBase&)i2 ) )
147 return false; 147 return false;
148 if ( i1.hasStartDate() == i2.hasStartDate() ) { 148 if ( i1.hasStartDate() == i2.hasStartDate() ) {
149 if ( i1.hasStartDate() ) { 149 if ( i1.hasStartDate() ) {
150 if ( i1.dtStart() != i2.dtStart() ) 150 if ( i1.dtStart() != i2.dtStart() )
151 return false; 151 return false;
152 } 152 }
153 } else { 153 } else {
154 return false; 154 return false;
155 } 155 }
156 if (!( *i1.recurrence() == *i2.recurrence()) ) { 156 if (!( *i1.recurrence() == *i2.recurrence()) ) {
157 qDebug("recurrence is NOT equal "); 157 qDebug("recurrence is NOT equal ");
158 return false; 158 return false;
159 } 159 }
160 return 160 return
161 // i1.created() == i2.created() && 161 // i1.created() == i2.created() &&
162 stringCompare( i1.description(), i2.description() ) && 162 stringCompare( i1.description(), i2.description() ) &&
163 stringCompare( i1.summary(), i2.summary() ) && 163 stringCompare( i1.summary(), i2.summary() ) &&
164 i1.categories() == i2.categories() && 164 i1.categories() == i2.categories() &&
165 // no need to compare mRelatedTo 165 // no need to compare mRelatedTo
166 stringCompare( i1.relatedToUid(), i2.relatedToUid() ) && 166 stringCompare( i1.relatedToUid(), i2.relatedToUid() ) &&
167 // i1.relations() == i2.relations() && 167 // i1.relations() == i2.relations() &&
168 i1.exDates() == i2.exDates() && 168 i1.exDates() == i2.exDates() &&
169 i1.attachments() == i2.attachments() && 169 i1.attachments() == i2.attachments() &&
170 i1.resources() == i2.resources() && 170 i1.resources() == i2.resources() &&
171 i1.secrecy() == i2.secrecy() && 171 i1.secrecy() == i2.secrecy() &&
172 i1.priority() == i2.priority() && 172 i1.priority() == i2.priority() &&
173 stringCompare( i1.location(), i2.location() ); 173 stringCompare( i1.location(), i2.location() );
174} 174}
175 175
176 176
177void Incidence::recreate() 177void Incidence::recreate()
178{ 178{
179 setCreated(QDateTime::currentDateTime()); 179 setCreated(QDateTime::currentDateTime());
180 180
181 setUid(CalFormat::createUniqueId()); 181 setUid(CalFormat::createUniqueId());
182 182
183 setRevision(0); 183 setRevision(0);
184 184 setIDStr( ":" );
185 setLastModified(QDateTime::currentDateTime()); 185 setLastModified(QDateTime::currentDateTime());
186} 186}
187 187
188void Incidence::setReadOnly( bool readOnly ) 188void Incidence::setReadOnly( bool readOnly )
189{ 189{
190 IncidenceBase::setReadOnly( readOnly ); 190 IncidenceBase::setReadOnly( readOnly );
191 recurrence()->setRecurReadOnly( readOnly); 191 recurrence()->setRecurReadOnly( readOnly);
192} 192}
193 193
194void Incidence::setCreated(QDateTime created) 194void Incidence::setCreated(QDateTime created)
195{ 195{
196 if (mReadOnly) return; 196 if (mReadOnly) return;
197 mCreated = getEvenTime(created); 197 mCreated = getEvenTime(created);
198} 198}
199 199
200QDateTime Incidence::created() const 200QDateTime Incidence::created() const
201{ 201{
202 return mCreated; 202 return mCreated;
203} 203}
204 204
205void Incidence::setRevision(int rev) 205void Incidence::setRevision(int rev)
206{ 206{
207 if (mReadOnly) return; 207 if (mReadOnly) return;
208 mRevision = rev; 208 mRevision = rev;
209 209
210 updated(); 210 updated();
211} 211}
212 212
213int Incidence::revision() const 213int Incidence::revision() const
214{ 214{
215 return mRevision; 215 return mRevision;
216} 216}
217 217
218void Incidence::setDtStart(const QDateTime &dtStart) 218void Incidence::setDtStart(const QDateTime &dtStart)
219{ 219{
220 220
221 QDateTime dt = getEvenTime(dtStart); 221 QDateTime dt = getEvenTime(dtStart);
222 recurrence()->setRecurStart( dt); 222 recurrence()->setRecurStart( dt);
223 IncidenceBase::setDtStart( dt ); 223 IncidenceBase::setDtStart( dt );
224} 224}
225 225
226void Incidence::setDescription(const QString &description) 226void Incidence::setDescription(const QString &description)
227{ 227{
228 if (mReadOnly) return; 228 if (mReadOnly) return;
229 mDescription = description; 229 mDescription = description;
230 updated(); 230 updated();
231} 231}
232 232
233QString Incidence::description() const 233QString Incidence::description() const
234{ 234{
235 return mDescription; 235 return mDescription;
236} 236}
237 237
238 238
239void Incidence::setSummary(const QString &summary) 239void Incidence::setSummary(const QString &summary)
240{ 240{
241 if (mReadOnly) return; 241 if (mReadOnly) return;
242 mSummary = summary; 242 mSummary = summary;
243 updated(); 243 updated();
244} 244}
245 245
246QString Incidence::summary() const 246QString Incidence::summary() const
247{ 247{
248 return mSummary; 248 return mSummary;
249} 249}
250 250
251void Incidence::setCategories(const QStringList &categories) 251void Incidence::setCategories(const QStringList &categories)
252{ 252{
253 if (mReadOnly) return; 253 if (mReadOnly) return;
254 mCategories = categories; 254 mCategories = categories;
255 updated(); 255 updated();
256} 256}
257 257
258// TODO: remove setCategories(QString) function 258// TODO: remove setCategories(QString) function
259void Incidence::setCategories(const QString &catStr) 259void Incidence::setCategories(const QString &catStr)
260{ 260{
261 if (mReadOnly) return; 261 if (mReadOnly) return;
262 mCategories.clear(); 262 mCategories.clear();
263 263
264 if (catStr.isEmpty()) return; 264 if (catStr.isEmpty()) return;
265 265
266 mCategories = QStringList::split(",",catStr); 266 mCategories = QStringList::split(",",catStr);
267 267
268 QStringList::Iterator it; 268 QStringList::Iterator it;
269 for(it = mCategories.begin();it != mCategories.end(); ++it) { 269 for(it = mCategories.begin();it != mCategories.end(); ++it) {
270 *it = (*it).stripWhiteSpace(); 270 *it = (*it).stripWhiteSpace();
271 } 271 }
272 272
273 updated(); 273 updated();
274} 274}
275 275
276QStringList Incidence::categories() const 276QStringList Incidence::categories() const
277{ 277{
278 return mCategories; 278 return mCategories;
279} 279}
280 280
281QString Incidence::categoriesStr() 281QString Incidence::categoriesStr()
282{ 282{
283 return mCategories.join(","); 283 return mCategories.join(",");
284} 284}
285 285
286void Incidence::setRelatedToUid(const QString &relatedToUid) 286void Incidence::setRelatedToUid(const QString &relatedToUid)
287{ 287{
288 if (mReadOnly) return; 288 if (mReadOnly) return;
289 mRelatedToUid = relatedToUid; 289 mRelatedToUid = relatedToUid;
290} 290}
291 291
292QString Incidence::relatedToUid() const 292QString Incidence::relatedToUid() const
293{ 293{
294 return mRelatedToUid; 294 return mRelatedToUid;
295} 295}
296 296
297void Incidence::setRelatedTo(Incidence *relatedTo) 297void Incidence::setRelatedTo(Incidence *relatedTo)
298{ 298{
299 //qDebug("Incidence::setRelatedTo %d ", relatedTo); 299 //qDebug("Incidence::setRelatedTo %d ", relatedTo);
300 //qDebug("setRelatedTo(Incidence *relatedTo) %s %s", summary().latin1(), relatedTo->summary().latin1() ); 300 //qDebug("setRelatedTo(Incidence *relatedTo) %s %s", summary().latin1(), relatedTo->summary().latin1() );
301 if (mReadOnly || mRelatedTo == relatedTo) return; 301 if (mReadOnly || mRelatedTo == relatedTo) return;
302 if(mRelatedTo) { 302 if(mRelatedTo) {
303 // updated(); 303 // updated();
304 mRelatedTo->removeRelation(this); 304 mRelatedTo->removeRelation(this);
305 } 305 }
306 mRelatedTo = relatedTo; 306 mRelatedTo = relatedTo;
307 if (mRelatedTo) mRelatedTo->addRelation(this); 307 if (mRelatedTo) mRelatedTo->addRelation(this);
308} 308}
309 309
310Incidence *Incidence::relatedTo() const 310Incidence *Incidence::relatedTo() const
311{ 311{
312 return mRelatedTo; 312 return mRelatedTo;
313} 313}
314 314
315QPtrList<Incidence> Incidence::relations() const 315QPtrList<Incidence> Incidence::relations() const
316{ 316{
317 return mRelations; 317 return mRelations;
318} 318}
319 319
320void Incidence::addRelation(Incidence *event) 320void Incidence::addRelation(Incidence *event)
321{ 321{
322 if( mRelations.findRef( event ) == -1 ) { 322 if( mRelations.findRef( event ) == -1 ) {
323 mRelations.append(event); 323 mRelations.append(event);
324 //updated(); 324 //updated();
325 } 325 }
326} 326}
327 327
328void Incidence::removeRelation(Incidence *event) 328void Incidence::removeRelation(Incidence *event)
329{ 329{
330 330
331 mRelations.removeRef(event); 331 mRelations.removeRef(event);
332 332
333// if (event->getRelatedTo() == this) event->setRelatedTo(0); 333// if (event->getRelatedTo() == this) event->setRelatedTo(0);
334} 334}
335 335
336bool Incidence::recursOn(const QDate &qd) const 336bool Incidence::recursOn(const QDate &qd) const
337{ 337{
338 if (recurrence()->recursOnPure(qd) && !isException(qd)) return true; 338 if (recurrence()->recursOnPure(qd) && !isException(qd)) return true;
339 else return false; 339 else return false;
340} 340}
341 341
342void Incidence::setExDates(const DateList &exDates) 342void Incidence::setExDates(const DateList &exDates)
343{ 343{
344 if (mReadOnly) return; 344 if (mReadOnly) return;
345 mExDates = exDates; 345 mExDates = exDates;
346 346
347 recurrence()->setRecurExDatesCount(mExDates.count()); 347 recurrence()->setRecurExDatesCount(mExDates.count());
348 348
349 updated(); 349 updated();
350} 350}
351 351
352void Incidence::addExDate(const QDate &date) 352void Incidence::addExDate(const QDate &date)
353{ 353{
354 if (mReadOnly) return; 354 if (mReadOnly) return;
355 mExDates.append(date); 355 mExDates.append(date);
356 356
357 recurrence()->setRecurExDatesCount(mExDates.count()); 357 recurrence()->setRecurExDatesCount(mExDates.count());
358 358
359 updated(); 359 updated();
360} 360}
361 361
362DateList Incidence::exDates() const 362DateList Incidence::exDates() const
363{ 363{
364 return mExDates; 364 return mExDates;
365} 365}
366 366
367bool Incidence::isException(const QDate &date) const 367bool Incidence::isException(const QDate &date) const
368{ 368{
369 DateList::ConstIterator it; 369 DateList::ConstIterator it;
370 for( it = mExDates.begin(); it != mExDates.end(); ++it ) { 370 for( it = mExDates.begin(); it != mExDates.end(); ++it ) {
371 if ( (*it) == date ) { 371 if ( (*it) == date ) {
372 return true; 372 return true;
373 } 373 }
374 } 374 }
375 375
376 return false; 376 return false;