summaryrefslogtreecommitdiffabout
path: root/libkcal/todo.cpp
Unidiff
Diffstat (limited to 'libkcal/todo.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r--libkcal/todo.cpp4
1 files changed, 2 insertions, 2 deletions
diff --git a/libkcal/todo.cpp b/libkcal/todo.cpp
index d81a68f..9c04a7e 100644
--- a/libkcal/todo.cpp
+++ b/libkcal/todo.cpp
@@ -35,129 +35,129 @@ Todo::Todo(): Incidence()
35 mCompleted = getEvenTime(QDateTime::currentDateTime()); 35 mCompleted = getEvenTime(QDateTime::currentDateTime());
36 mHasCompletedDate = false; 36 mHasCompletedDate = false;
37 mPercentComplete = 0; 37 mPercentComplete = 0;
38} 38}
39 39
40Todo::Todo(const Todo &t) : Incidence(t) 40Todo::Todo(const Todo &t) : Incidence(t)
41{ 41{
42 mDtDue = t.mDtDue; 42 mDtDue = t.mDtDue;
43 mHasDueDate = t.mHasDueDate; 43 mHasDueDate = t.mHasDueDate;
44 mCompleted = t.mCompleted; 44 mCompleted = t.mCompleted;
45 mHasCompletedDate = t.mHasCompletedDate; 45 mHasCompletedDate = t.mHasCompletedDate;
46 mPercentComplete = t.mPercentComplete; 46 mPercentComplete = t.mPercentComplete;
47} 47}
48 48
49Todo::~Todo() 49Todo::~Todo()
50{ 50{
51 51
52} 52}
53 53
54Incidence *Todo::clone() 54Incidence *Todo::clone()
55{ 55{
56 return new Todo(*this); 56 return new Todo(*this);
57} 57}
58 58
59bool Todo::contains ( Todo* from ) 59bool Todo::contains ( Todo* from )
60{ 60{
61 61
62 if ( !from->summary().isEmpty() ) 62 if ( !from->summary().isEmpty() )
63 if ( !summary().startsWith( from->summary() )) 63 if ( !summary().startsWith( from->summary() ))
64 return false; 64 return false;
65 if ( from->hasStartDate() ) { 65 if ( from->hasStartDate() ) {
66 if ( !hasStartDate() ) 66 if ( !hasStartDate() )
67 return false; 67 return false;
68 if ( from->dtStart() != dtStart()) 68 if ( from->dtStart() != dtStart())
69 return false; 69 return false;
70 } 70 }
71 if ( from->hasDueDate() ){ 71 if ( from->hasDueDate() ){
72 if ( !hasDueDate() ) 72 if ( !hasDueDate() )
73 return false; 73 return false;
74 if ( from->dtDue() != dtDue()) 74 if ( from->dtDue() != dtDue())
75 return false; 75 return false;
76 } 76 }
77 if ( !from->location().isEmpty() ) 77 if ( !from->location().isEmpty() )
78 if ( !location().startsWith( from->location() ) ) 78 if ( !location().startsWith( from->location() ) )
79 return false; 79 return false;
80 if ( !from->description().isEmpty() ) 80 if ( !from->description().isEmpty() )
81 if ( !description().startsWith( from->description() )) 81 if ( !description().startsWith( from->description() ))
82 return false; 82 return false;
83 if ( from->alarms().count() ) { 83 if ( from->alarms().count() ) {
84 Alarm *a = from->alarms().first(); 84 Alarm *a = from->alarms().first();
85 if ( a->enabled() ){ 85 if ( a->enabled() ){
86 if ( !alarms().count() ) 86 if ( !alarms().count() )
87 return false; 87 return false;
88 Alarm *b = alarms().first(); 88 Alarm *b = alarms().first();
89 if( ! b->enabled() ) 89 if( ! b->enabled() )
90 return false; 90 return false;
91 if ( ! (a->offset() == b->offset() )) 91 if ( ! (a->offset() == b->offset() ))
92 return false; 92 return false;
93 } 93 }
94 } 94 }
95 95
96 QStringList cat = categories(); 96 QStringList cat = categories();
97 QStringList catFrom = from->categories(); 97 QStringList catFrom = from->categories();
98 QString nCat; 98 QString nCat;
99 int iii; 99 unsigned int iii;
100 for ( iii = 0; iii < catFrom.count();++iii ) { 100 for ( iii = 0; iii < catFrom.count();++iii ) {
101 nCat = catFrom[iii]; 101 nCat = catFrom[iii];
102 if ( !nCat.isEmpty() ) 102 if ( !nCat.isEmpty() )
103 if ( !cat.contains( nCat )) { 103 if ( !cat.contains( nCat )) {
104 return false; 104 return false;
105 } 105 }
106 } 106 }
107 if ( from->isCompleted() ) { 107 if ( from->isCompleted() ) {
108 if ( !isCompleted() ) 108 if ( !isCompleted() )
109 return false; 109 return false;
110 } 110 }
111 if( priority() != from->priority() ) 111 if( priority() != from->priority() )
112 return false; 112 return false;
113 113
114 114
115 return true; 115 return true;
116 116
117} 117}
118bool KCal::operator==( const Todo& t1, const Todo& t2 ) 118bool KCal::operator==( const Todo& t1, const Todo& t2 )
119{ 119{
120 120
121 bool ret = operator==( (const Incidence&)t1, (const Incidence&)t2 ); 121 bool ret = operator==( (const Incidence&)t1, (const Incidence&)t2 );
122 if ( ! ret ) 122 if ( ! ret )
123 return false; 123 return false;
124 if ( t1.hasDueDate() == t2.hasDueDate() ) { 124 if ( t1.hasDueDate() == t2.hasDueDate() ) {
125 if ( t1.hasDueDate() ) { 125 if ( t1.hasDueDate() ) {
126 if ( t1.doesFloat() == t2.doesFloat() ) { 126 if ( t1.doesFloat() == t2.doesFloat() ) {
127 if ( t1.doesFloat() ) { 127 if ( t1.doesFloat() ) {
128 if ( t1.dtDue().date() != t2.dtDue().date() ) 128 if ( t1.dtDue().date() != t2.dtDue().date() )
129 return false; 129 return false;
130 } else 130 } else
131 if ( t1.dtDue() != t2.dtDue() ) 131 if ( t1.dtDue() != t2.dtDue() )
132 return false; 132 return false;
133 } else 133 } else
134 return false;// float != 134 return false;// float !=
135 } 135 }
136 136
137 } else 137 } else
138 return false; 138 return false;
139 if ( t1.percentComplete() != t2.percentComplete() ) 139 if ( t1.percentComplete() != t2.percentComplete() )
140 return false; 140 return false;
141 if ( t1.isCompleted() ) { 141 if ( t1.isCompleted() ) {
142 if ( t1.hasCompletedDate() == t2.hasCompletedDate() ) { 142 if ( t1.hasCompletedDate() == t2.hasCompletedDate() ) {
143 if ( t1.hasCompletedDate() ) { 143 if ( t1.hasCompletedDate() ) {
144 if ( t1.completed() != t2.completed() ) 144 if ( t1.completed() != t2.completed() )
145 return false; 145 return false;
146 } 146 }
147 147
148 } else 148 } else
149 return false; 149 return false;
150 } 150 }
151 return true; 151 return true;
152 152
153} 153}
154 154
155void Todo::setDtDue(const QDateTime &dtDue) 155void Todo::setDtDue(const QDateTime &dtDue)
156{ 156{
157 //int diffsecs = mDtDue.secsTo(dtDue); 157 //int diffsecs = mDtDue.secsTo(dtDue);
158 158
159 /*if (mReadOnly) return; 159 /*if (mReadOnly) return;
160 const QPtrList<Alarm>& alarms = alarms(); 160 const QPtrList<Alarm>& alarms = alarms();
161 for (Alarm* alarm = alarms.first(); alarm; alarm = alarms.next()) { 161 for (Alarm* alarm = alarms.first(); alarm; alarm = alarms.next()) {
162 if (alarm->enabled()) { 162 if (alarm->enabled()) {
163 alarm->setTime(alarm->time().addSecs(diffsecs)); 163 alarm->setTime(alarm->time().addSecs(diffsecs));
@@ -314,101 +314,101 @@ bool Todo::isCompleted() const
314 if (mPercentComplete == 100) return true; 314 if (mPercentComplete == 100) return true;
315 else return false; 315 else return false;
316} 316}
317 317
318void Todo::setCompleted(bool completed) 318void Todo::setCompleted(bool completed)
319{ 319{
320 if (completed) mPercentComplete = 100; 320 if (completed) mPercentComplete = 100;
321 else { 321 else {
322 mPercentComplete = 0; 322 mPercentComplete = 0;
323 mHasCompletedDate = false; 323 mHasCompletedDate = false;
324 } 324 }
325 updated(); 325 updated();
326} 326}
327 327
328QDateTime Todo::completed() const 328QDateTime Todo::completed() const
329{ 329{
330 return mCompleted; 330 return mCompleted;
331} 331}
332 332
333QString Todo::completedStr( bool shortF ) const 333QString Todo::completedStr( bool shortF ) const
334{ 334{
335 return KGlobal::locale()->formatDateTime(mCompleted, shortF); 335 return KGlobal::locale()->formatDateTime(mCompleted, shortF);
336} 336}
337 337
338void Todo::setCompleted(const QDateTime &completed) 338void Todo::setCompleted(const QDateTime &completed)
339{ 339{
340 //qDebug("Todo::setCompleted "); 340 //qDebug("Todo::setCompleted ");
341 if ( mHasCompletedDate ) { 341 if ( mHasCompletedDate ) {
342 // qDebug("has completed data - return "); 342 // qDebug("has completed data - return ");
343 return; 343 return;
344 } 344 }
345 mHasCompletedDate = true; 345 mHasCompletedDate = true;
346 mPercentComplete = 100; 346 mPercentComplete = 100;
347 mCompleted = getEvenTime(completed); 347 mCompleted = getEvenTime(completed);
348 updated(); 348 updated();
349} 349}
350 350
351bool Todo::hasCompletedDate() const 351bool Todo::hasCompletedDate() const
352{ 352{
353 return mHasCompletedDate; 353 return mHasCompletedDate;
354} 354}
355 355
356int Todo::percentComplete() const 356int Todo::percentComplete() const
357{ 357{
358 return mPercentComplete; 358 return mPercentComplete;
359} 359}
360 360
361void Todo::setPercentComplete(int v) 361void Todo::setPercentComplete(int v)
362{ 362{
363 mPercentComplete = v; 363 mPercentComplete = v;
364 if ( v != 100 ) 364 if ( v != 100 )
365 mHasCompletedDate = false; 365 mHasCompletedDate = false;
366 updated(); 366 updated();
367} 367}
368QDateTime Todo::getNextAlarmDateTime( bool * ok, int * offset ) const 368QDateTime Todo::getNextAlarmDateTime( bool * ok, int * offset ) const
369{ 369{
370 if ( isCompleted() || ! hasDueDate() || cancelled() ) { 370 if ( isCompleted() || ! hasDueDate() || cancelled() ) {
371 *ok = false; 371 *ok = false;
372 return QDateTime (); 372 return QDateTime ();
373 } 373 }
374 QDateTime incidenceStart; 374 QDateTime incidenceStart;
375 incidenceStart = dtDue(); 375 incidenceStart = dtDue();
376 bool enabled = false; 376 bool enabled = false;
377 Alarm* alarm; 377 Alarm* alarm;
378 int off; 378 int off = 0;
379 QDateTime alarmStart = QDateTime::currentDateTime().addDays( 3650 );; 379 QDateTime alarmStart = QDateTime::currentDateTime().addDays( 3650 );;
380 // if ( QDateTime::currentDateTime() > incidenceStart ){ 380 // if ( QDateTime::currentDateTime() > incidenceStart ){
381// *ok = false; 381// *ok = false;
382// return incidenceStart; 382// return incidenceStart;
383// } 383// }
384 for (QPtrListIterator<Alarm> it(mAlarms); (alarm = it.current()) != 0; ++it) { 384 for (QPtrListIterator<Alarm> it(mAlarms); (alarm = it.current()) != 0; ++it) {
385 if (alarm->enabled()) { 385 if (alarm->enabled()) {
386 if ( alarm->hasTime () ) { 386 if ( alarm->hasTime () ) {
387 if ( alarm->time() < alarmStart ) { 387 if ( alarm->time() < alarmStart ) {
388 alarmStart = alarm->time(); 388 alarmStart = alarm->time();
389 enabled = true; 389 enabled = true;
390 off = alarmStart.secsTo( incidenceStart ); 390 off = alarmStart.secsTo( incidenceStart );
391 } 391 }
392 392
393 } else { 393 } else {
394 int secs = alarm->startOffset().asSeconds(); 394 int secs = alarm->startOffset().asSeconds();
395 if ( incidenceStart.addSecs( secs ) < alarmStart ) { 395 if ( incidenceStart.addSecs( secs ) < alarmStart ) {
396 alarmStart = incidenceStart.addSecs( secs ); 396 alarmStart = incidenceStart.addSecs( secs );
397 enabled = true; 397 enabled = true;
398 off = -secs; 398 off = -secs;
399 } 399 }
400 } 400 }
401 } 401 }
402 } 402 }
403 if ( enabled ) { 403 if ( enabled ) {
404 if ( alarmStart > QDateTime::currentDateTime() ) { 404 if ( alarmStart > QDateTime::currentDateTime() ) {
405 *ok = true; 405 *ok = true;
406 * offset = off; 406 * offset = off;
407 return alarmStart; 407 return alarmStart;
408 } 408 }
409 } 409 }
410 *ok = false; 410 *ok = false;
411 return QDateTime (); 411 return QDateTime ();
412 412
413} 413}
414 414