summaryrefslogtreecommitdiffabout
path: root/libkcal/todo.cpp
Unidiff
Diffstat (limited to 'libkcal/todo.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r--libkcal/todo.cpp5
1 files changed, 3 insertions, 2 deletions
diff --git a/libkcal/todo.cpp b/libkcal/todo.cpp
index 7362bdf..7d04793 100644
--- a/libkcal/todo.cpp
+++ b/libkcal/todo.cpp
@@ -47,333 +47,334 @@ Todo::Todo(const Todo &t) : Incidence(t)
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 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));
164 } 164 }
165 }*/ 165 }*/
166 mDtDue = getEvenTime(dtDue); 166 mDtDue = getEvenTime(dtDue);
167 167
168 //kdDebug(5800) << "setDtDue says date is " << mDtDue.toString() << endl; 168 //kdDebug(5800) << "setDtDue says date is " << mDtDue.toString() << endl;
169 169
170 /*const QPtrList<Alarm>& alarms = alarms(); 170 /*const QPtrList<Alarm>& alarms = alarms();
171 for (Alarm* alarm = alarms.first(); alarm; alarm = alarms.next()) 171 for (Alarm* alarm = alarms.first(); alarm; alarm = alarms.next())
172 alarm->setAlarmStart(mDtDue);*/ 172 alarm->setAlarmStart(mDtDue);*/
173 173
174 updated(); 174 updated();
175} 175}
176 176
177QDateTime Todo::dtDue() const 177QDateTime Todo::dtDue() const
178{ 178{
179 return mDtDue; 179 return mDtDue;
180} 180}
181 181
182QString Todo::dtDueTimeStr() const 182QString Todo::dtDueTimeStr() const
183{ 183{
184 return KGlobal::locale()->formatTime(mDtDue.time()); 184 return KGlobal::locale()->formatTime(mDtDue.time());
185} 185}
186 186
187QString Todo::dtDueDateStr(bool shortfmt) const 187QString Todo::dtDueDateStr(bool shortfmt) const
188{ 188{
189 return KGlobal::locale()->formatDate(mDtDue.date(),shortfmt); 189 return KGlobal::locale()->formatDate(mDtDue.date(),shortfmt);
190} 190}
191 191
192QString Todo::dtDueStr(bool shortfmt) const 192QString Todo::dtDueStr(bool shortfmt) const
193{ 193{
194 return KGlobal::locale()->formatDateTime(mDtDue, shortfmt); 194 return KGlobal::locale()->formatDateTime(mDtDue, shortfmt);
195} 195}
196 196
197bool Todo::hasDueDate() const 197bool Todo::hasDueDate() const
198{ 198{
199 return mHasDueDate; 199 return mHasDueDate;
200} 200}
201 201
202void Todo::setHasDueDate(bool f) 202void Todo::setHasDueDate(bool f)
203{ 203{
204 if (mReadOnly) return; 204 if (mReadOnly) return;
205 mHasDueDate = f; 205 mHasDueDate = f;
206 updated(); 206 updated();
207} 207}
208 208
209 209
210#if 0 210#if 0
211void Todo::setStatus(const QString &statStr) 211void Todo::setStatus(const QString &statStr)
212{ 212{
213 if (mReadOnly) return; 213 if (mReadOnly) return;
214 QString ss(statStr.upper()); 214 QString ss(statStr.upper());
215 215
216 if (ss == "X-ACTION") 216 if (ss == "X-ACTION")
217 mStatus = NEEDS_ACTION; 217 mStatus = NEEDS_ACTION;
218 else if (ss == "NEEDS ACTION") 218 else if (ss == "NEEDS ACTION")
219 mStatus = NEEDS_ACTION; 219 mStatus = NEEDS_ACTION;
220 else if (ss == "ACCEPTED") 220 else if (ss == "ACCEPTED")
221 mStatus = ACCEPTED; 221 mStatus = ACCEPTED;
222 else if (ss == "SENT") 222 else if (ss == "SENT")
223 mStatus = SENT; 223 mStatus = SENT;
224 else if (ss == "TENTATIVE") 224 else if (ss == "TENTATIVE")
225 mStatus = TENTATIVE; 225 mStatus = TENTATIVE;
226 else if (ss == "CONFIRMED") 226 else if (ss == "CONFIRMED")
227 mStatus = CONFIRMED; 227 mStatus = CONFIRMED;
228 else if (ss == "DECLINED") 228 else if (ss == "DECLINED")
229 mStatus = DECLINED; 229 mStatus = DECLINED;
230 else if (ss == "COMPLETED") 230 else if (ss == "COMPLETED")
231 mStatus = COMPLETED; 231 mStatus = COMPLETED;
232 else if (ss == "DELEGATED") 232 else if (ss == "DELEGATED")
233 mStatus = DELEGATED; 233 mStatus = DELEGATED;
234 234
235 updated(); 235 updated();
236} 236}
237 237
238void Todo::setStatus(int status) 238void Todo::setStatus(int status)
239{ 239{
240 if (mReadOnly) return; 240 if (mReadOnly) return;
241 mStatus = status; 241 mStatus = status;
242 updated(); 242 updated();
243} 243}
244 244
245int Todo::status() const 245int Todo::status() const
246{ 246{
247 return mStatus; 247 return mStatus;
248} 248}
249 249
250QString Todo::statusStr() const 250QString Todo::statusStr() const
251{ 251{
252 switch(mStatus) { 252 switch(mStatus) {
253 case NEEDS_ACTION: 253 case NEEDS_ACTION:
254 return QString("NEEDS ACTION"); 254 return QString("NEEDS ACTION");
255 break; 255 break;
256 case ACCEPTED: 256 case ACCEPTED:
257 return QString("ACCEPTED"); 257 return QString("ACCEPTED");
258 break; 258 break;
259 case SENT: 259 case SENT:
260 return QString("SENT"); 260 return QString("SENT");
261 break; 261 break;
262 case TENTATIVE: 262 case TENTATIVE:
263 return QString("TENTATIVE"); 263 return QString("TENTATIVE");
264 break; 264 break;
265 case CONFIRMED: 265 case CONFIRMED:
266 return QString("CONFIRMED"); 266 return QString("CONFIRMED");
267 break; 267 break;
268 case DECLINED: 268 case DECLINED:
269 return QString("DECLINED"); 269 return QString("DECLINED");
270 break; 270 break;
271 case COMPLETED: 271 case COMPLETED:
272 return QString("COMPLETED"); 272 return QString("COMPLETED");
273 break; 273 break;
274 case DELEGATED: 274 case DELEGATED:
275 return QString("DELEGATED"); 275 return QString("DELEGATED");
276 break; 276 break;
277 } 277 }
278 return QString(""); 278 return QString("");
279} 279}
280#endif 280#endif
281 281
282bool Todo::isCompleted() const 282bool Todo::isCompleted() const
283{ 283{
284 if (mPercentComplete == 100) return true; 284 if (mPercentComplete == 100) return true;
285 else return false; 285 else return false;
286} 286}
287 287
288void Todo::setCompleted(bool completed) 288void Todo::setCompleted(bool completed)
289{ 289{
290 if (completed) mPercentComplete = 100; 290 if (completed) mPercentComplete = 100;
291 else { 291 else {
292 mPercentComplete = 0; 292 mPercentComplete = 0;
293 mHasCompletedDate = false; 293 mHasCompletedDate = false;
294 } 294 }
295 updated(); 295 updated();
296} 296}
297 297
298QDateTime Todo::completed() const 298QDateTime Todo::completed() const
299{ 299{
300 return mCompleted; 300 return mCompleted;
301} 301}
302 302
303QString Todo::completedStr() const 303QString Todo::completedStr( bool shortF ) const
304{ 304{
305 return KGlobal::locale()->formatDateTime(mCompleted); 305 return KGlobal::locale()->formatDateTime(mCompleted, shortF);
306} 306}
307 307
308void Todo::setCompleted(const QDateTime &completed) 308void Todo::setCompleted(const QDateTime &completed)
309{ 309{
310 qDebug("Todo::setCompleted ");
310 mHasCompletedDate = true; 311 mHasCompletedDate = true;
311 mPercentComplete = 100; 312 mPercentComplete = 100;
312 mCompleted = getEvenTime(completed); 313 mCompleted = getEvenTime(completed);
313 updated(); 314 updated();
314} 315}
315 316
316bool Todo::hasCompletedDate() const 317bool Todo::hasCompletedDate() const
317{ 318{
318 return mHasCompletedDate; 319 return mHasCompletedDate;
319} 320}
320 321
321int Todo::percentComplete() const 322int Todo::percentComplete() const
322{ 323{
323 return mPercentComplete; 324 return mPercentComplete;
324} 325}
325 326
326void Todo::setPercentComplete(int v) 327void Todo::setPercentComplete(int v)
327{ 328{
328 mPercentComplete = v; 329 mPercentComplete = v;
329 if ( v != 100 ) 330 if ( v != 100 )
330 mHasCompletedDate = false; 331 mHasCompletedDate = false;
331 updated(); 332 updated();
332} 333}
333QDateTime Todo::getNextAlarmDateTime( bool * ok, int * offset ) const 334QDateTime Todo::getNextAlarmDateTime( bool * ok, int * offset ) const
334{ 335{
335 if ( isCompleted() || ! hasDueDate() || cancelled() ) { 336 if ( isCompleted() || ! hasDueDate() || cancelled() ) {
336 *ok = false; 337 *ok = false;
337 return QDateTime (); 338 return QDateTime ();
338 } 339 }
339 QDateTime incidenceStart; 340 QDateTime incidenceStart;
340 incidenceStart = dtDue(); 341 incidenceStart = dtDue();
341 bool enabled = false; 342 bool enabled = false;
342 Alarm* alarm; 343 Alarm* alarm;
343 int off; 344 int off;
344 QDateTime alarmStart = QDateTime::currentDateTime().addDays( 3650 );; 345 QDateTime alarmStart = QDateTime::currentDateTime().addDays( 3650 );;
345 // if ( QDateTime::currentDateTime() > incidenceStart ){ 346 // if ( QDateTime::currentDateTime() > incidenceStart ){
346// *ok = false; 347// *ok = false;
347// return incidenceStart; 348// return incidenceStart;
348// } 349// }
349 for (QPtrListIterator<Alarm> it(mAlarms); (alarm = it.current()) != 0; ++it) { 350 for (QPtrListIterator<Alarm> it(mAlarms); (alarm = it.current()) != 0; ++it) {
350 if (alarm->enabled()) { 351 if (alarm->enabled()) {
351 if ( alarm->hasTime () ) { 352 if ( alarm->hasTime () ) {
352 if ( alarm->time() < alarmStart ) { 353 if ( alarm->time() < alarmStart ) {
353 alarmStart = alarm->time(); 354 alarmStart = alarm->time();
354 enabled = true; 355 enabled = true;
355 off = alarmStart.secsTo( incidenceStart ); 356 off = alarmStart.secsTo( incidenceStart );
356 } 357 }
357 358
358 } else { 359 } else {
359 int secs = alarm->startOffset().asSeconds(); 360 int secs = alarm->startOffset().asSeconds();
360 if ( incidenceStart.addSecs( secs ) < alarmStart ) { 361 if ( incidenceStart.addSecs( secs ) < alarmStart ) {
361 alarmStart = incidenceStart.addSecs( secs ); 362 alarmStart = incidenceStart.addSecs( secs );
362 enabled = true; 363 enabled = true;
363 off = -secs; 364 off = -secs;
364 } 365 }
365 } 366 }
366 } 367 }
367 } 368 }
368 if ( enabled ) { 369 if ( enabled ) {
369 if ( alarmStart > QDateTime::currentDateTime() ) { 370 if ( alarmStart > QDateTime::currentDateTime() ) {
370 *ok = true; 371 *ok = true;
371 * offset = off; 372 * offset = off;
372 return alarmStart; 373 return alarmStart;
373 } 374 }
374 } 375 }
375 *ok = false; 376 *ok = false;
376 return QDateTime (); 377 return QDateTime ();
377 378
378} 379}
379 380