author | zautrix <zautrix> | 2005-01-31 16:29:05 (UTC) |
---|---|---|
committer | zautrix <zautrix> | 2005-01-31 16:29:05 (UTC) |
commit | ec037c4616342c1b3976c55db98b775f48e0d455 (patch) (unidiff) | |
tree | 9d568c8f6ad6005f822c12644596b7a553837c7f /libkcal | |
parent | 5d52c81be9b43887c13f8534a04164d3b44b821f (diff) | |
download | kdepimpi-ec037c4616342c1b3976c55db98b775f48e0d455.zip kdepimpi-ec037c4616342c1b3976c55db98b775f48e0d455.tar.gz kdepimpi-ec037c4616342c1b3976c55db98b775f48e0d455.tar.bz2 |
fix
-rw-r--r-- | libkcal/calendarlocal.cpp | 1 | ||||
-rw-r--r-- | libkcal/incidence.cpp | 3 |
2 files changed, 2 insertions, 2 deletions
diff --git a/libkcal/calendarlocal.cpp b/libkcal/calendarlocal.cpp index 0eba6a9..e75154b 100644 --- a/libkcal/calendarlocal.cpp +++ b/libkcal/calendarlocal.cpp | |||
@@ -206,519 +206,520 @@ void CalendarLocal::deleteTodo( Todo *todo ) | |||
206 | mUndoIncidence = todo->clone(); | 206 | mUndoIncidence = todo->clone(); |
207 | 207 | ||
208 | if ( mTodoList.removeRef( todo ) ) { | 208 | if ( mTodoList.removeRef( todo ) ) { |
209 | setModified( true ); | 209 | setModified( true ); |
210 | } | 210 | } |
211 | } | 211 | } |
212 | 212 | ||
213 | QPtrList<Todo> CalendarLocal::rawTodos() | 213 | QPtrList<Todo> CalendarLocal::rawTodos() |
214 | { | 214 | { |
215 | return mTodoList; | 215 | return mTodoList; |
216 | } | 216 | } |
217 | Todo *CalendarLocal::todo( QString syncProf, QString id ) | 217 | Todo *CalendarLocal::todo( QString syncProf, QString id ) |
218 | { | 218 | { |
219 | Todo *todo; | 219 | Todo *todo; |
220 | for ( todo = mTodoList.first(); todo; todo = mTodoList.next() ) { | 220 | for ( todo = mTodoList.first(); todo; todo = mTodoList.next() ) { |
221 | if ( todo->getID( syncProf ) == id ) return todo; | 221 | if ( todo->getID( syncProf ) == id ) return todo; |
222 | } | 222 | } |
223 | 223 | ||
224 | return 0; | 224 | return 0; |
225 | } | 225 | } |
226 | void CalendarLocal::removeSyncInfo( QString syncProfile) | 226 | void CalendarLocal::removeSyncInfo( QString syncProfile) |
227 | { | 227 | { |
228 | QPtrList<Incidence> all = rawIncidences() ; | 228 | QPtrList<Incidence> all = rawIncidences() ; |
229 | Incidence *inc; | 229 | Incidence *inc; |
230 | for ( inc = all.first(); inc; inc = all.next() ) { | 230 | for ( inc = all.first(); inc; inc = all.next() ) { |
231 | inc->removeID( syncProfile ); | 231 | inc->removeID( syncProfile ); |
232 | } | 232 | } |
233 | if ( syncProfile.isEmpty() ) { | 233 | if ( syncProfile.isEmpty() ) { |
234 | QPtrList<Event> el; | 234 | QPtrList<Event> el; |
235 | Event *todo; | 235 | Event *todo; |
236 | for ( todo = mEventList.first(); todo; todo = mEventList.next() ) { | 236 | for ( todo = mEventList.first(); todo; todo = mEventList.next() ) { |
237 | if ( todo->uid().left( 15 ) == QString("last-syncEvent-") ) | 237 | if ( todo->uid().left( 15 ) == QString("last-syncEvent-") ) |
238 | el.append( todo ); | 238 | el.append( todo ); |
239 | } | 239 | } |
240 | for ( todo = el.first(); todo; todo = el.next() ) { | 240 | for ( todo = el.first(); todo; todo = el.next() ) { |
241 | deleteIncidence ( todo ); | 241 | deleteIncidence ( todo ); |
242 | } | 242 | } |
243 | } else { | 243 | } else { |
244 | Event *lse = event( "last-syncEvent-"+ syncProfile); | 244 | Event *lse = event( "last-syncEvent-"+ syncProfile); |
245 | deleteIncidence ( lse ); | 245 | deleteIncidence ( lse ); |
246 | } | 246 | } |
247 | } | 247 | } |
248 | QPtrList<Event> CalendarLocal::getExternLastSyncEvents() | 248 | QPtrList<Event> CalendarLocal::getExternLastSyncEvents() |
249 | { | 249 | { |
250 | QPtrList<Event> el; | 250 | QPtrList<Event> el; |
251 | Event *todo; | 251 | Event *todo; |
252 | for ( todo = mEventList.first(); todo; todo = mEventList.next() ) { | 252 | for ( todo = mEventList.first(); todo; todo = mEventList.next() ) { |
253 | if ( todo->uid().left( 15 ) == QString("last-syncEvent-") ) | 253 | if ( todo->uid().left( 15 ) == QString("last-syncEvent-") ) |
254 | if ( todo->summary().left(3) == "E: " ) | 254 | if ( todo->summary().left(3) == "E: " ) |
255 | el.append( todo ); | 255 | el.append( todo ); |
256 | } | 256 | } |
257 | 257 | ||
258 | return el; | 258 | return el; |
259 | 259 | ||
260 | } | 260 | } |
261 | Event *CalendarLocal::event( QString syncProf, QString id ) | 261 | Event *CalendarLocal::event( QString syncProf, QString id ) |
262 | { | 262 | { |
263 | Event *todo; | 263 | Event *todo; |
264 | for ( todo = mEventList.first(); todo; todo = mEventList.next() ) { | 264 | for ( todo = mEventList.first(); todo; todo = mEventList.next() ) { |
265 | if ( todo->getID( syncProf ) == id ) return todo; | 265 | if ( todo->getID( syncProf ) == id ) return todo; |
266 | } | 266 | } |
267 | 267 | ||
268 | return 0; | 268 | return 0; |
269 | } | 269 | } |
270 | Todo *CalendarLocal::todo( const QString &uid ) | 270 | Todo *CalendarLocal::todo( const QString &uid ) |
271 | { | 271 | { |
272 | Todo *todo; | 272 | Todo *todo; |
273 | for ( todo = mTodoList.first(); todo; todo = mTodoList.next() ) { | 273 | for ( todo = mTodoList.first(); todo; todo = mTodoList.next() ) { |
274 | if ( todo->uid() == uid ) return todo; | 274 | if ( todo->uid() == uid ) return todo; |
275 | } | 275 | } |
276 | 276 | ||
277 | return 0; | 277 | return 0; |
278 | } | 278 | } |
279 | QString CalendarLocal::nextSummary() const | 279 | QString CalendarLocal::nextSummary() const |
280 | { | 280 | { |
281 | return mNextSummary; | 281 | return mNextSummary; |
282 | } | 282 | } |
283 | QDateTime CalendarLocal::nextAlarmEventDateTime() const | 283 | QDateTime CalendarLocal::nextAlarmEventDateTime() const |
284 | { | 284 | { |
285 | return mNextAlarmEventDateTime; | 285 | return mNextAlarmEventDateTime; |
286 | } | 286 | } |
287 | void CalendarLocal::checkAlarmForIncidence( Incidence * incidence, bool deleted) | 287 | void CalendarLocal::checkAlarmForIncidence( Incidence * incidence, bool deleted) |
288 | { | 288 | { |
289 | //mNextAlarmIncidence | 289 | //mNextAlarmIncidence |
290 | //mNextAlarmDateTime | 290 | //mNextAlarmDateTime |
291 | //return mNextSummary; | 291 | //return mNextSummary; |
292 | //return mNextAlarmEventDateTime; | 292 | //return mNextAlarmEventDateTime; |
293 | bool newNextAlarm = false; | 293 | bool newNextAlarm = false; |
294 | bool computeNextAlarm = false; | 294 | bool computeNextAlarm = false; |
295 | bool ok; | 295 | bool ok; |
296 | int offset; | 296 | int offset; |
297 | QDateTime nextA; | 297 | QDateTime nextA; |
298 | // QString nextSum; | 298 | // QString nextSum; |
299 | //QDateTime nextEvent; | 299 | //QDateTime nextEvent; |
300 | if ( mNextAlarmIncidence == 0 || incidence == 0 ) { | 300 | if ( mNextAlarmIncidence == 0 || incidence == 0 ) { |
301 | computeNextAlarm = true; | 301 | computeNextAlarm = true; |
302 | } else { | 302 | } else { |
303 | if ( ! deleted ) { | 303 | if ( ! deleted ) { |
304 | nextA = incidence->getNextAlarmDateTime(& ok, &offset ) ; | 304 | nextA = incidence->getNextAlarmDateTime(& ok, &offset ) ; |
305 | if ( ok ) { | 305 | if ( ok ) { |
306 | if ( nextA < mNextAlarmDateTime ) { | 306 | if ( nextA < mNextAlarmDateTime ) { |
307 | deRegisterAlarm(); | 307 | deRegisterAlarm(); |
308 | mNextAlarmDateTime = nextA; | 308 | mNextAlarmDateTime = nextA; |
309 | mNextSummary = incidence->summary(); | 309 | mNextSummary = incidence->summary(); |
310 | mNextAlarmEventDateTime = nextA.addSecs(offset ) ; | 310 | mNextAlarmEventDateTime = nextA.addSecs(offset ) ; |
311 | mNextAlarmEventDateTimeString = KGlobal::locale()->formatDateTime(mNextAlarmEventDateTime); | 311 | mNextAlarmEventDateTimeString = KGlobal::locale()->formatDateTime(mNextAlarmEventDateTime); |
312 | newNextAlarm = true; | 312 | newNextAlarm = true; |
313 | mNextAlarmIncidence = incidence; | 313 | mNextAlarmIncidence = incidence; |
314 | } else { | 314 | } else { |
315 | if ( incidence == mNextAlarmIncidence ) { | 315 | if ( incidence == mNextAlarmIncidence ) { |
316 | computeNextAlarm = true; | 316 | computeNextAlarm = true; |
317 | } | 317 | } |
318 | } | 318 | } |
319 | } else { | 319 | } else { |
320 | if ( mNextAlarmIncidence == incidence ) { | 320 | if ( mNextAlarmIncidence == incidence ) { |
321 | computeNextAlarm = true; | 321 | computeNextAlarm = true; |
322 | } | 322 | } |
323 | } | 323 | } |
324 | } else { // deleted | 324 | } else { // deleted |
325 | if ( incidence == mNextAlarmIncidence ) { | 325 | if ( incidence == mNextAlarmIncidence ) { |
326 | computeNextAlarm = true; | 326 | computeNextAlarm = true; |
327 | } | 327 | } |
328 | } | 328 | } |
329 | } | 329 | } |
330 | if ( computeNextAlarm ) { | 330 | if ( computeNextAlarm ) { |
331 | deRegisterAlarm(); | 331 | deRegisterAlarm(); |
332 | nextA = nextAlarm( 1000 ); | 332 | nextA = nextAlarm( 1000 ); |
333 | if (! mNextAlarmIncidence ) { | 333 | if (! mNextAlarmIncidence ) { |
334 | return; | 334 | return; |
335 | } | 335 | } |
336 | newNextAlarm = true; | 336 | newNextAlarm = true; |
337 | } | 337 | } |
338 | if ( newNextAlarm ) | 338 | if ( newNextAlarm ) |
339 | registerAlarm(); | 339 | registerAlarm(); |
340 | } | 340 | } |
341 | QString CalendarLocal:: getAlarmNotification() | 341 | QString CalendarLocal:: getAlarmNotification() |
342 | { | 342 | { |
343 | QString ret; | 343 | QString ret; |
344 | // this should not happen | 344 | // this should not happen |
345 | if (! mNextAlarmIncidence ) | 345 | if (! mNextAlarmIncidence ) |
346 | return "cal_alarm"+ mNextSummary.left( 25 )+"\n"+mNextAlarmEventDateTimeString; | 346 | return "cal_alarm"+ mNextSummary.left( 25 )+"\n"+mNextAlarmEventDateTimeString; |
347 | Alarm* alarm = mNextAlarmIncidence->alarms().first(); | 347 | Alarm* alarm = mNextAlarmIncidence->alarms().first(); |
348 | if ( alarm->type() == Alarm::Procedure ) { | 348 | if ( alarm->type() == Alarm::Procedure ) { |
349 | ret = "proc_alarm" + alarm->programFile()+"+++"; | 349 | ret = "proc_alarm" + alarm->programFile()+"+++"; |
350 | } else { | 350 | } else { |
351 | ret = "audio_alarm" +alarm->audioFile() +"+++"; | 351 | ret = "audio_alarm" +alarm->audioFile() +"+++"; |
352 | } | 352 | } |
353 | ret += "cal_alarm"+ mNextSummary.left( 25 ); | 353 | ret += "cal_alarm"+ mNextSummary.left( 25 ); |
354 | if ( mNextSummary.length() > 25 ) | 354 | if ( mNextSummary.length() > 25 ) |
355 | ret += "\n" + mNextSummary.mid(25, 25 ); | 355 | ret += "\n" + mNextSummary.mid(25, 25 ); |
356 | ret+= "\n"+mNextAlarmEventDateTimeString; | 356 | ret+= "\n"+mNextAlarmEventDateTimeString; |
357 | return ret; | 357 | return ret; |
358 | } | 358 | } |
359 | void CalendarLocal::registerAlarm() | 359 | void CalendarLocal::registerAlarm() |
360 | { | 360 | { |
361 | mLastAlarmNotificationString = getAlarmNotification(); | 361 | mLastAlarmNotificationString = getAlarmNotification(); |
362 | // qDebug("++ register Alarm %s %s",mNextAlarmDateTime.toString().latin1(), mLastAlarmNotificationString.latin1() ); | 362 | // qDebug("++ register Alarm %s %s",mNextAlarmDateTime.toString().latin1(), mLastAlarmNotificationString.latin1() ); |
363 | emit addAlarm ( mNextAlarmDateTime, mLastAlarmNotificationString ); | 363 | emit addAlarm ( mNextAlarmDateTime, mLastAlarmNotificationString ); |
364 | // #ifndef DESKTOP_VERSION | 364 | // #ifndef DESKTOP_VERSION |
365 | // AlarmServer::addAlarm ( mNextAlarmDateTime,"koalarm", mLastAlarmNotificationString.latin1() ); | 365 | // AlarmServer::addAlarm ( mNextAlarmDateTime,"koalarm", mLastAlarmNotificationString.latin1() ); |
366 | // #endif | 366 | // #endif |
367 | } | 367 | } |
368 | void CalendarLocal::deRegisterAlarm() | 368 | void CalendarLocal::deRegisterAlarm() |
369 | { | 369 | { |
370 | if ( mLastAlarmNotificationString.isNull() ) | 370 | if ( mLastAlarmNotificationString.isNull() ) |
371 | return; | 371 | return; |
372 | //qDebug("-- deregister Alarm %s ", mLastAlarmNotificationString.latin1() ); | 372 | //qDebug("-- deregister Alarm %s ", mLastAlarmNotificationString.latin1() ); |
373 | 373 | ||
374 | emit removeAlarm ( mNextAlarmDateTime, mLastAlarmNotificationString ); | 374 | emit removeAlarm ( mNextAlarmDateTime, mLastAlarmNotificationString ); |
375 | // #ifndef DESKTOP_VERSION | 375 | // #ifndef DESKTOP_VERSION |
376 | // AlarmServer::deleteAlarm (mNextAlarmDateTime ,"koalarm" ,mLastAlarmNotificationString.latin1() ); | 376 | // AlarmServer::deleteAlarm (mNextAlarmDateTime ,"koalarm" ,mLastAlarmNotificationString.latin1() ); |
377 | // #endif | 377 | // #endif |
378 | } | 378 | } |
379 | 379 | ||
380 | QPtrList<Todo> CalendarLocal::todos( const QDate &date ) | 380 | QPtrList<Todo> CalendarLocal::todos( const QDate &date ) |
381 | { | 381 | { |
382 | QPtrList<Todo> todos; | 382 | QPtrList<Todo> todos; |
383 | 383 | ||
384 | Todo *todo; | 384 | Todo *todo; |
385 | for ( todo = mTodoList.first(); todo; todo = mTodoList.next() ) { | 385 | for ( todo = mTodoList.first(); todo; todo = mTodoList.next() ) { |
386 | if ( todo->hasDueDate() && todo->dtDue().date() == date ) { | 386 | if ( todo->hasDueDate() && todo->dtDue().date() == date ) { |
387 | todos.append( todo ); | 387 | todos.append( todo ); |
388 | } | 388 | } |
389 | } | 389 | } |
390 | 390 | ||
391 | filter()->apply( &todos ); | 391 | filter()->apply( &todos ); |
392 | return todos; | 392 | return todos; |
393 | } | 393 | } |
394 | void CalendarLocal::reInitAlarmSettings() | 394 | void CalendarLocal::reInitAlarmSettings() |
395 | { | 395 | { |
396 | if ( !mNextAlarmIncidence ) { | 396 | if ( !mNextAlarmIncidence ) { |
397 | nextAlarm( 1000 ); | 397 | nextAlarm( 1000 ); |
398 | } | 398 | } |
399 | deRegisterAlarm(); | 399 | deRegisterAlarm(); |
400 | mNextAlarmIncidence = 0; | 400 | mNextAlarmIncidence = 0; |
401 | checkAlarmForIncidence( 0, false ); | 401 | checkAlarmForIncidence( 0, false ); |
402 | 402 | ||
403 | } | 403 | } |
404 | 404 | ||
405 | 405 | ||
406 | 406 | ||
407 | QDateTime CalendarLocal::nextAlarm( int daysTo ) | 407 | QDateTime CalendarLocal::nextAlarm( int daysTo ) |
408 | { | 408 | { |
409 | QDateTime nextA = QDateTime::currentDateTime().addDays( daysTo ); | 409 | QDateTime nextA = QDateTime::currentDateTime().addDays( daysTo ); |
410 | QDateTime start = QDateTime::currentDateTime().addSecs( 30 ); | 410 | QDateTime start = QDateTime::currentDateTime().addSecs( 30 ); |
411 | QDateTime next; | 411 | QDateTime next; |
412 | Event *e; | 412 | Event *e; |
413 | bool ok; | 413 | bool ok; |
414 | bool found = false; | 414 | bool found = false; |
415 | int offset; | 415 | int offset; |
416 | mNextAlarmIncidence = 0; | 416 | mNextAlarmIncidence = 0; |
417 | for( e = mEventList.first(); e; e = mEventList.next() ) { | 417 | for( e = mEventList.first(); e; e = mEventList.next() ) { |
418 | next = e->getNextAlarmDateTime(& ok, &offset ) ; | 418 | next = e->getNextAlarmDateTime(& ok, &offset ) ; |
419 | if ( ok ) { | 419 | if ( ok ) { |
420 | if ( next < nextA ) { | 420 | if ( next < nextA ) { |
421 | nextA = next; | 421 | nextA = next; |
422 | found = true; | 422 | found = true; |
423 | mNextSummary = e->summary(); | 423 | mNextSummary = e->summary(); |
424 | mNextAlarmEventDateTime = next.addSecs(offset ) ; | 424 | mNextAlarmEventDateTime = next.addSecs(offset ) ; |
425 | mNextAlarmIncidence = (Incidence *) e; | 425 | mNextAlarmIncidence = (Incidence *) e; |
426 | } | 426 | } |
427 | } | 427 | } |
428 | } | 428 | } |
429 | Todo *t; | 429 | Todo *t; |
430 | for( t = mTodoList.first(); t; t = mTodoList.next() ) { | 430 | for( t = mTodoList.first(); t; t = mTodoList.next() ) { |
431 | next = t->getNextAlarmDateTime(& ok, &offset ) ; | 431 | next = t->getNextAlarmDateTime(& ok, &offset ) ; |
432 | if ( ok ) { | 432 | if ( ok ) { |
433 | if ( next < nextA ) { | 433 | if ( next < nextA ) { |
434 | nextA = next; | 434 | nextA = next; |
435 | found = true; | 435 | found = true; |
436 | mNextSummary = t->summary(); | 436 | mNextSummary = t->summary(); |
437 | mNextAlarmEventDateTime = next.addSecs(offset ); | 437 | mNextAlarmEventDateTime = next.addSecs(offset ); |
438 | mNextAlarmIncidence = (Incidence *) t; | 438 | mNextAlarmIncidence = (Incidence *) t; |
439 | } | 439 | } |
440 | } | 440 | } |
441 | } | 441 | } |
442 | if ( mNextAlarmIncidence ) { | 442 | if ( mNextAlarmIncidence ) { |
443 | mNextAlarmEventDateTimeString = KGlobal::locale()->formatDateTime(mNextAlarmEventDateTime); | 443 | mNextAlarmEventDateTimeString = KGlobal::locale()->formatDateTime(mNextAlarmEventDateTime); |
444 | mNextAlarmDateTime = nextA; | 444 | mNextAlarmDateTime = nextA; |
445 | } | 445 | } |
446 | return nextA; | 446 | return nextA; |
447 | } | 447 | } |
448 | Alarm::List CalendarLocal::alarmsTo( const QDateTime &to ) | 448 | Alarm::List CalendarLocal::alarmsTo( const QDateTime &to ) |
449 | { | 449 | { |
450 | return alarms( QDateTime( QDate( 1900, 1, 1 ) ), to ); | 450 | return alarms( QDateTime( QDate( 1900, 1, 1 ) ), to ); |
451 | } | 451 | } |
452 | 452 | ||
453 | Alarm::List CalendarLocal::alarms( const QDateTime &from, const QDateTime &to ) | 453 | Alarm::List CalendarLocal::alarms( const QDateTime &from, const QDateTime &to ) |
454 | { | 454 | { |
455 | kdDebug(5800) << "CalendarLocal::alarms(" << from.toString() << " - " | 455 | kdDebug(5800) << "CalendarLocal::alarms(" << from.toString() << " - " |
456 | << to.toString() << ")\n"; | 456 | << to.toString() << ")\n"; |
457 | 457 | ||
458 | Alarm::List alarms; | 458 | Alarm::List alarms; |
459 | 459 | ||
460 | Event *e; | 460 | Event *e; |
461 | 461 | ||
462 | for( e = mEventList.first(); e; e = mEventList.next() ) { | 462 | for( e = mEventList.first(); e; e = mEventList.next() ) { |
463 | if ( e->doesRecur() ) appendRecurringAlarms( alarms, e, from, to ); | 463 | if ( e->doesRecur() ) appendRecurringAlarms( alarms, e, from, to ); |
464 | else appendAlarms( alarms, e, from, to ); | 464 | else appendAlarms( alarms, e, from, to ); |
465 | } | 465 | } |
466 | 466 | ||
467 | Todo *t; | 467 | Todo *t; |
468 | for( t = mTodoList.first(); t; t = mTodoList.next() ) { | 468 | for( t = mTodoList.first(); t; t = mTodoList.next() ) { |
469 | appendAlarms( alarms, t, from, to ); | 469 | appendAlarms( alarms, t, from, to ); |
470 | } | 470 | } |
471 | 471 | ||
472 | return alarms; | 472 | return alarms; |
473 | } | 473 | } |
474 | 474 | ||
475 | void CalendarLocal::appendAlarms( Alarm::List &alarms, Incidence *incidence, | 475 | void CalendarLocal::appendAlarms( Alarm::List &alarms, Incidence *incidence, |
476 | const QDateTime &from, const QDateTime &to ) | 476 | const QDateTime &from, const QDateTime &to ) |
477 | { | 477 | { |
478 | QPtrList<Alarm> alarmList = incidence->alarms(); | 478 | QPtrList<Alarm> alarmList = incidence->alarms(); |
479 | Alarm *alarm; | 479 | Alarm *alarm; |
480 | for( alarm = alarmList.first(); alarm; alarm = alarmList.next() ) { | 480 | for( alarm = alarmList.first(); alarm; alarm = alarmList.next() ) { |
481 | // kdDebug(5800) << "CalendarLocal::appendAlarms() '" << alarm->text() | 481 | // kdDebug(5800) << "CalendarLocal::appendAlarms() '" << alarm->text() |
482 | // << "': " << alarm->time().toString() << " - " << alarm->enabled() << endl; | 482 | // << "': " << alarm->time().toString() << " - " << alarm->enabled() << endl; |
483 | if ( alarm->enabled() ) { | 483 | if ( alarm->enabled() ) { |
484 | if ( alarm->time() >= from && alarm->time() <= to ) { | 484 | if ( alarm->time() >= from && alarm->time() <= to ) { |
485 | kdDebug(5800) << "CalendarLocal::appendAlarms() '" << incidence->summary() | 485 | kdDebug(5800) << "CalendarLocal::appendAlarms() '" << incidence->summary() |
486 | << "': " << alarm->time().toString() << endl; | 486 | << "': " << alarm->time().toString() << endl; |
487 | alarms.append( alarm ); | 487 | alarms.append( alarm ); |
488 | } | 488 | } |
489 | } | 489 | } |
490 | } | 490 | } |
491 | } | 491 | } |
492 | 492 | ||
493 | void CalendarLocal::appendRecurringAlarms( Alarm::List &alarms, | 493 | void CalendarLocal::appendRecurringAlarms( Alarm::List &alarms, |
494 | Incidence *incidence, | 494 | Incidence *incidence, |
495 | const QDateTime &from, | 495 | const QDateTime &from, |
496 | const QDateTime &to ) | 496 | const QDateTime &to ) |
497 | { | 497 | { |
498 | 498 | ||
499 | QPtrList<Alarm> alarmList = incidence->alarms(); | 499 | QPtrList<Alarm> alarmList = incidence->alarms(); |
500 | Alarm *alarm; | 500 | Alarm *alarm; |
501 | QDateTime qdt; | 501 | QDateTime qdt; |
502 | for( alarm = alarmList.first(); alarm; alarm = alarmList.next() ) { | 502 | for( alarm = alarmList.first(); alarm; alarm = alarmList.next() ) { |
503 | if (incidence->recursOn(from.date())) { | 503 | if (incidence->recursOn(from.date())) { |
504 | qdt.setTime(alarm->time().time()); | 504 | qdt.setTime(alarm->time().time()); |
505 | qdt.setDate(from.date()); | 505 | qdt.setDate(from.date()); |
506 | } | 506 | } |
507 | else qdt = alarm->time(); | 507 | else qdt = alarm->time(); |
508 | // qDebug("1 %s %s %s", qdt.toString().latin1(), from.toString().latin1(), to.toString().latin1()); | 508 | // qDebug("1 %s %s %s", qdt.toString().latin1(), from.toString().latin1(), to.toString().latin1()); |
509 | if ( alarm->enabled() ) { | 509 | if ( alarm->enabled() ) { |
510 | if ( qdt >= from && qdt <= to ) { | 510 | if ( qdt >= from && qdt <= to ) { |
511 | alarms.append( alarm ); | 511 | alarms.append( alarm ); |
512 | } | 512 | } |
513 | } | 513 | } |
514 | } | 514 | } |
515 | } | 515 | } |
516 | 516 | ||
517 | 517 | ||
518 | /****************************** PROTECTED METHODS ****************************/ | 518 | /****************************** PROTECTED METHODS ****************************/ |
519 | 519 | ||
520 | // after changes are made to an event, this should be called. | 520 | // after changes are made to an event, this should be called. |
521 | void CalendarLocal::update( IncidenceBase *incidence ) | 521 | void CalendarLocal::update( IncidenceBase *incidence ) |
522 | { | 522 | { |
523 | incidence->setSyncStatus( Event::SYNCMOD ); | 523 | incidence->setSyncStatus( Event::SYNCMOD ); |
524 | incidence->setLastModified( QDateTime::currentDateTime() ); | 524 | incidence->setLastModified( QDateTime::currentDateTime() ); |
525 | // we should probably update the revision number here, | 525 | // we should probably update the revision number here, |
526 | // or internally in the Event itself when certain things change. | 526 | // or internally in the Event itself when certain things change. |
527 | // need to verify with ical documentation. | 527 | // need to verify with ical documentation. |
528 | 528 | ||
529 | setModified( true ); | 529 | setModified( true ); |
530 | } | 530 | } |
531 | 531 | ||
532 | void CalendarLocal::insertEvent( Event *event ) | 532 | void CalendarLocal::insertEvent( Event *event ) |
533 | { | 533 | { |
534 | if ( mEventList.findRef( event ) < 0 ) mEventList.append( event ); | 534 | if ( mEventList.findRef( event ) < 0 ) mEventList.append( event ); |
535 | } | 535 | } |
536 | 536 | ||
537 | 537 | ||
538 | QPtrList<Event> CalendarLocal::rawEventsForDate( const QDate &qd, bool sorted ) | 538 | QPtrList<Event> CalendarLocal::rawEventsForDate( const QDate &qd, bool sorted ) |
539 | { | 539 | { |
540 | QPtrList<Event> eventList; | 540 | QPtrList<Event> eventList; |
541 | 541 | ||
542 | Event *event; | 542 | Event *event; |
543 | for( event = mEventList.first(); event; event = mEventList.next() ) { | 543 | for( event = mEventList.first(); event; event = mEventList.next() ) { |
544 | if ( event->doesRecur() ) { | 544 | if ( event->doesRecur() ) { |
545 | if ( event->isMultiDay() ) { | 545 | if ( event->isMultiDay() ) { |
546 | int extraDays = event->dtStart().date().daysTo( event->dtEnd().date() ); | 546 | int extraDays = event->dtStart().date().daysTo( event->dtEnd().date() ); |
547 | int i; | 547 | int i; |
548 | for ( i = 0; i <= extraDays; i++ ) { | 548 | for ( i = 0; i <= extraDays; i++ ) { |
549 | if ( event->recursOn( qd.addDays( -i ) ) ) { | 549 | if ( event->recursOn( qd.addDays( -i ) ) ) { |
550 | eventList.append( event ); | 550 | eventList.append( event ); |
551 | break; | 551 | break; |
552 | } | 552 | } |
553 | } | 553 | } |
554 | } else { | 554 | } else { |
555 | if ( event->recursOn( qd ) ) | 555 | if ( event->recursOn( qd ) ) |
556 | eventList.append( event ); | 556 | eventList.append( event ); |
557 | } | 557 | } |
558 | } else { | 558 | } else { |
559 | if ( event->dtStart().date() <= qd && event->dtEnd().date() >= qd ) { | 559 | if ( event->dtStart().date() <= qd && event->dtEnd().date() >= qd ) { |
560 | eventList.append( event ); | 560 | eventList.append( event ); |
561 | } | 561 | } |
562 | } | 562 | } |
563 | } | 563 | } |
564 | 564 | ||
565 | if ( !sorted ) { | 565 | if ( !sorted ) { |
566 | return eventList; | 566 | return eventList; |
567 | } | 567 | } |
568 | 568 | ||
569 | // kdDebug(5800) << "Sorting events for date\n" << endl; | 569 | // kdDebug(5800) << "Sorting events for date\n" << endl; |
570 | // now, we have to sort it based on dtStart.time() | 570 | // now, we have to sort it based on dtStart.time() |
571 | QPtrList<Event> eventListSorted; | 571 | QPtrList<Event> eventListSorted; |
572 | Event *sortEvent; | 572 | Event *sortEvent; |
573 | for ( event = eventList.first(); event; event = eventList.next() ) { | 573 | for ( event = eventList.first(); event; event = eventList.next() ) { |
574 | sortEvent = eventListSorted.first(); | 574 | sortEvent = eventListSorted.first(); |
575 | int i = 0; | 575 | int i = 0; |
576 | while ( sortEvent && event->dtStart().time()>=sortEvent->dtStart().time() ) | 576 | while ( sortEvent && event->dtStart().time()>=sortEvent->dtStart().time() ) |
577 | { | 577 | { |
578 | i++; | 578 | i++; |
579 | sortEvent = eventListSorted.next(); | 579 | sortEvent = eventListSorted.next(); |
580 | } | 580 | } |
581 | eventListSorted.insert( i, event ); | 581 | eventListSorted.insert( i, event ); |
582 | } | 582 | } |
583 | return eventListSorted; | 583 | return eventListSorted; |
584 | } | 584 | } |
585 | 585 | ||
586 | 586 | ||
587 | QPtrList<Event> CalendarLocal::rawEvents( const QDate &start, const QDate &end, | 587 | QPtrList<Event> CalendarLocal::rawEvents( const QDate &start, const QDate &end, |
588 | bool inclusive ) | 588 | bool inclusive ) |
589 | { | 589 | { |
590 | qDebug("CalendarLocal::rawEvents called "); | ||
590 | Event *event = 0; | 591 | Event *event = 0; |
591 | 592 | ||
592 | QPtrList<Event> eventList; | 593 | QPtrList<Event> eventList; |
593 | 594 | ||
594 | // Get non-recurring events | 595 | // Get non-recurring events |
595 | for( event = mEventList.first(); event; event = mEventList.next() ) { | 596 | for( event = mEventList.first(); event; event = mEventList.next() ) { |
596 | if ( event->doesRecur() ) { | 597 | if ( event->doesRecur() ) { |
597 | QDate rStart = event->dtStart().date(); | 598 | QDate rStart = event->dtStart().date(); |
598 | bool found = false; | 599 | bool found = false; |
599 | if ( inclusive ) { | 600 | if ( inclusive ) { |
600 | if ( rStart >= start && rStart <= end ) { | 601 | if ( rStart >= start && rStart <= end ) { |
601 | // Start date of event is in range. Now check for end date. | 602 | // Start date of event is in range. Now check for end date. |
602 | // if duration is negative, event recurs forever, so do not include it. | 603 | // if duration is negative, event recurs forever, so do not include it. |
603 | if ( event->recurrence()->duration() == 0 ) { // End date set | 604 | if ( event->recurrence()->duration() == 0 ) { // End date set |
604 | QDate rEnd = event->recurrence()->endDate(); | 605 | QDate rEnd = event->recurrence()->endDate(); |
605 | if ( rEnd >= start && rEnd <= end ) { // End date within range | 606 | if ( rEnd >= start && rEnd <= end ) { // End date within range |
606 | found = true; | 607 | found = true; |
607 | } | 608 | } |
608 | } else if ( event->recurrence()->duration() > 0 ) { // Duration set | 609 | } else if ( event->recurrence()->duration() > 0 ) { // Duration set |
609 | // TODO: Calculate end date from duration. Should be done in Event | 610 | // TODO: Calculate end date from duration. Should be done in Event |
610 | // For now exclude all events with a duration. | 611 | // For now exclude all events with a duration. |
611 | } | 612 | } |
612 | } | 613 | } |
613 | } else { | 614 | } else { |
614 | bool founOne; | 615 | bool founOne; |
615 | QDate next = event->getNextOccurence( start, &founOne ).date(); | 616 | QDate next = event->getNextOccurence( start, &founOne ).date(); |
616 | if ( founOne ) { | 617 | if ( founOne ) { |
617 | if ( next <= end ) { | 618 | if ( next <= end ) { |
618 | found = true; | 619 | found = true; |
619 | } | 620 | } |
620 | } | 621 | } |
621 | 622 | ||
622 | /* | 623 | /* |
623 | // crap !!! | 624 | // crap !!! |
624 | if ( rStart <= end ) { // Start date not after range | 625 | if ( rStart <= end ) { // Start date not after range |
625 | if ( rStart >= start ) { // Start date within range | 626 | if ( rStart >= start ) { // Start date within range |
626 | found = true; | 627 | found = true; |
627 | } else if ( event->recurrence()->duration() == -1 ) { // Recurs forever | 628 | } else if ( event->recurrence()->duration() == -1 ) { // Recurs forever |
628 | found = true; | 629 | found = true; |
629 | } else if ( event->recurrence()->duration() == 0 ) { // End date set | 630 | } else if ( event->recurrence()->duration() == 0 ) { // End date set |
630 | QDate rEnd = event->recurrence()->endDate(); | 631 | QDate rEnd = event->recurrence()->endDate(); |
631 | if ( rEnd >= start && rEnd <= end ) { // End date within range | 632 | if ( rEnd >= start && rEnd <= end ) { // End date within range |
632 | found = true; | 633 | found = true; |
633 | } | 634 | } |
634 | } else { // Duration set | 635 | } else { // Duration set |
635 | // TODO: Calculate end date from duration. Should be done in Event | 636 | // TODO: Calculate end date from duration. Should be done in Event |
636 | // For now include all events with a duration. | 637 | // For now include all events with a duration. |
637 | found = true; | 638 | found = true; |
638 | } | 639 | } |
639 | } | 640 | } |
640 | */ | 641 | */ |
641 | 642 | ||
642 | } | 643 | } |
643 | 644 | ||
644 | if ( found ) eventList.append( event ); | 645 | if ( found ) eventList.append( event ); |
645 | } else { | 646 | } else { |
646 | QDate s = event->dtStart().date(); | 647 | QDate s = event->dtStart().date(); |
647 | QDate e = event->dtEnd().date(); | 648 | QDate e = event->dtEnd().date(); |
648 | 649 | ||
649 | if ( inclusive ) { | 650 | if ( inclusive ) { |
650 | if ( s >= start && e <= end ) { | 651 | if ( s >= start && e <= end ) { |
651 | eventList.append( event ); | 652 | eventList.append( event ); |
652 | } | 653 | } |
653 | } else { | 654 | } else { |
654 | if ( ( s >= start && s <= end ) || ( e >= start && e <= end ) ) { | 655 | if ( ( s >= start && s <= end ) || ( e >= start && e <= end ) ) { |
655 | eventList.append( event ); | 656 | eventList.append( event ); |
656 | } | 657 | } |
657 | } | 658 | } |
658 | } | 659 | } |
659 | } | 660 | } |
660 | 661 | ||
661 | return eventList; | 662 | return eventList; |
662 | } | 663 | } |
663 | 664 | ||
664 | QPtrList<Event> CalendarLocal::rawEventsForDate( const QDateTime &qdt ) | 665 | QPtrList<Event> CalendarLocal::rawEventsForDate( const QDateTime &qdt ) |
665 | { | 666 | { |
666 | return rawEventsForDate( qdt.date() ); | 667 | return rawEventsForDate( qdt.date() ); |
667 | } | 668 | } |
668 | 669 | ||
669 | QPtrList<Event> CalendarLocal::rawEvents() | 670 | QPtrList<Event> CalendarLocal::rawEvents() |
670 | { | 671 | { |
671 | return mEventList; | 672 | return mEventList; |
672 | } | 673 | } |
673 | 674 | ||
674 | bool CalendarLocal::addJournal(Journal *journal) | 675 | bool CalendarLocal::addJournal(Journal *journal) |
675 | { | 676 | { |
676 | if ( journal->dtStart().isValid()) | 677 | if ( journal->dtStart().isValid()) |
677 | kdDebug(5800) << "Adding Journal on " << journal->dtStart().toString() << endl; | 678 | kdDebug(5800) << "Adding Journal on " << journal->dtStart().toString() << endl; |
678 | else | 679 | else |
679 | kdDebug(5800) << "Adding Journal without a DTSTART" << endl; | 680 | kdDebug(5800) << "Adding Journal without a DTSTART" << endl; |
680 | 681 | ||
681 | mJournalList.append(journal); | 682 | mJournalList.append(journal); |
682 | 683 | ||
683 | journal->registerObserver( this ); | 684 | journal->registerObserver( this ); |
684 | 685 | ||
685 | setModified( true ); | 686 | setModified( true ); |
686 | 687 | ||
687 | return true; | 688 | return true; |
688 | } | 689 | } |
689 | 690 | ||
690 | void CalendarLocal::deleteJournal( Journal *journal ) | 691 | void CalendarLocal::deleteJournal( Journal *journal ) |
691 | { | 692 | { |
692 | if ( mUndoIncidence ) delete mUndoIncidence; | 693 | if ( mUndoIncidence ) delete mUndoIncidence; |
693 | mUndoIncidence = journal->clone(); | 694 | mUndoIncidence = journal->clone(); |
694 | mUndoIncidence->setSummary( mUndoIncidence->description().left(25)); | 695 | mUndoIncidence->setSummary( mUndoIncidence->description().left(25)); |
695 | if ( mJournalList.removeRef(journal) ) { | 696 | if ( mJournalList.removeRef(journal) ) { |
696 | setModified( true ); | 697 | setModified( true ); |
697 | } | 698 | } |
698 | } | 699 | } |
699 | 700 | ||
700 | Journal *CalendarLocal::journal( const QDate &date ) | 701 | Journal *CalendarLocal::journal( const QDate &date ) |
701 | { | 702 | { |
702 | // kdDebug(5800) << "CalendarLocal::journal() " << date.toString() << endl; | 703 | // kdDebug(5800) << "CalendarLocal::journal() " << date.toString() << endl; |
703 | 704 | ||
704 | for ( Journal *it = mJournalList.first(); it; it = mJournalList.next() ) | 705 | for ( Journal *it = mJournalList.first(); it; it = mJournalList.next() ) |
705 | if ( it->dtStart().date() == date ) | 706 | if ( it->dtStart().date() == date ) |
706 | return it; | 707 | return it; |
707 | 708 | ||
708 | return 0; | 709 | return 0; |
709 | } | 710 | } |
710 | 711 | ||
711 | Journal *CalendarLocal::journal( const QString &uid ) | 712 | Journal *CalendarLocal::journal( const QString &uid ) |
712 | { | 713 | { |
713 | for ( Journal *it = mJournalList.first(); it; it = mJournalList.next() ) | 714 | for ( Journal *it = mJournalList.first(); it; it = mJournalList.next() ) |
714 | if ( it->uid() == uid ) | 715 | if ( it->uid() == uid ) |
715 | return it; | 716 | return it; |
716 | 717 | ||
717 | return 0; | 718 | return 0; |
718 | } | 719 | } |
719 | 720 | ||
720 | QPtrList<Journal> CalendarLocal::journals() | 721 | QPtrList<Journal> CalendarLocal::journals() |
721 | { | 722 | { |
722 | return mJournalList; | 723 | return mJournalList; |
723 | } | 724 | } |
724 | 725 | ||
diff --git a/libkcal/incidence.cpp b/libkcal/incidence.cpp index 28402ae..f9e1e9e 100644 --- a/libkcal/incidence.cpp +++ b/libkcal/incidence.cpp | |||
@@ -211,407 +211,406 @@ void Incidence::setCreated(QDateTime created) | |||
211 | mCreated = getEvenTime(created); | 211 | mCreated = getEvenTime(created); |
212 | } | 212 | } |
213 | 213 | ||
214 | QDateTime Incidence::created() const | 214 | QDateTime Incidence::created() const |
215 | { | 215 | { |
216 | return mCreated; | 216 | return mCreated; |
217 | } | 217 | } |
218 | 218 | ||
219 | void Incidence::setRevision(int rev) | 219 | void Incidence::setRevision(int rev) |
220 | { | 220 | { |
221 | if (mReadOnly) return; | 221 | if (mReadOnly) return; |
222 | mRevision = rev; | 222 | mRevision = rev; |
223 | 223 | ||
224 | updated(); | 224 | updated(); |
225 | } | 225 | } |
226 | 226 | ||
227 | int Incidence::revision() const | 227 | int Incidence::revision() const |
228 | { | 228 | { |
229 | return mRevision; | 229 | return mRevision; |
230 | } | 230 | } |
231 | 231 | ||
232 | void Incidence::setDtStart(const QDateTime &dtStart) | 232 | void Incidence::setDtStart(const QDateTime &dtStart) |
233 | { | 233 | { |
234 | 234 | ||
235 | QDateTime dt = getEvenTime(dtStart); | 235 | QDateTime dt = getEvenTime(dtStart); |
236 | recurrence()->setRecurStart( dt); | 236 | recurrence()->setRecurStart( dt); |
237 | IncidenceBase::setDtStart( dt ); | 237 | IncidenceBase::setDtStart( dt ); |
238 | } | 238 | } |
239 | 239 | ||
240 | void Incidence::setDescription(const QString &description) | 240 | void Incidence::setDescription(const QString &description) |
241 | { | 241 | { |
242 | if (mReadOnly) return; | 242 | if (mReadOnly) return; |
243 | mDescription = description; | 243 | mDescription = description; |
244 | updated(); | 244 | updated(); |
245 | } | 245 | } |
246 | 246 | ||
247 | QString Incidence::description() const | 247 | QString Incidence::description() const |
248 | { | 248 | { |
249 | return mDescription; | 249 | return mDescription; |
250 | } | 250 | } |
251 | 251 | ||
252 | 252 | ||
253 | void Incidence::setSummary(const QString &summary) | 253 | void Incidence::setSummary(const QString &summary) |
254 | { | 254 | { |
255 | if (mReadOnly) return; | 255 | if (mReadOnly) return; |
256 | mSummary = summary; | 256 | mSummary = summary; |
257 | updated(); | 257 | updated(); |
258 | } | 258 | } |
259 | 259 | ||
260 | QString Incidence::summary() const | 260 | QString Incidence::summary() const |
261 | { | 261 | { |
262 | return mSummary; | 262 | return mSummary; |
263 | } | 263 | } |
264 | 264 | ||
265 | void Incidence::setCategories(const QStringList &categories) | 265 | void Incidence::setCategories(const QStringList &categories) |
266 | { | 266 | { |
267 | if (mReadOnly) return; | 267 | if (mReadOnly) return; |
268 | mCategories = categories; | 268 | mCategories = categories; |
269 | updated(); | 269 | updated(); |
270 | } | 270 | } |
271 | 271 | ||
272 | // TODO: remove setCategories(QString) function | 272 | // TODO: remove setCategories(QString) function |
273 | void Incidence::setCategories(const QString &catStr) | 273 | void Incidence::setCategories(const QString &catStr) |
274 | { | 274 | { |
275 | if (mReadOnly) return; | 275 | if (mReadOnly) return; |
276 | mCategories.clear(); | 276 | mCategories.clear(); |
277 | 277 | ||
278 | if (catStr.isEmpty()) return; | 278 | if (catStr.isEmpty()) return; |
279 | 279 | ||
280 | mCategories = QStringList::split(",",catStr); | 280 | mCategories = QStringList::split(",",catStr); |
281 | 281 | ||
282 | QStringList::Iterator it; | 282 | QStringList::Iterator it; |
283 | for(it = mCategories.begin();it != mCategories.end(); ++it) { | 283 | for(it = mCategories.begin();it != mCategories.end(); ++it) { |
284 | *it = (*it).stripWhiteSpace(); | 284 | *it = (*it).stripWhiteSpace(); |
285 | } | 285 | } |
286 | 286 | ||
287 | updated(); | 287 | updated(); |
288 | } | 288 | } |
289 | 289 | ||
290 | QStringList Incidence::categories() const | 290 | QStringList Incidence::categories() const |
291 | { | 291 | { |
292 | return mCategories; | 292 | return mCategories; |
293 | } | 293 | } |
294 | 294 | ||
295 | QString Incidence::categoriesStr() | 295 | QString Incidence::categoriesStr() |
296 | { | 296 | { |
297 | return mCategories.join(","); | 297 | return mCategories.join(","); |
298 | } | 298 | } |
299 | 299 | ||
300 | void Incidence::setRelatedToUid(const QString &relatedToUid) | 300 | void Incidence::setRelatedToUid(const QString &relatedToUid) |
301 | { | 301 | { |
302 | if (mReadOnly) return; | 302 | if (mReadOnly) return; |
303 | mRelatedToUid = relatedToUid; | 303 | mRelatedToUid = relatedToUid; |
304 | } | 304 | } |
305 | 305 | ||
306 | QString Incidence::relatedToUid() const | 306 | QString Incidence::relatedToUid() const |
307 | { | 307 | { |
308 | return mRelatedToUid; | 308 | return mRelatedToUid; |
309 | } | 309 | } |
310 | 310 | ||
311 | void Incidence::setRelatedTo(Incidence *relatedTo) | 311 | void Incidence::setRelatedTo(Incidence *relatedTo) |
312 | { | 312 | { |
313 | //qDebug("Incidence::setRelatedTo %d ", relatedTo); | 313 | //qDebug("Incidence::setRelatedTo %d ", relatedTo); |
314 | //qDebug("setRelatedTo(Incidence *relatedTo) %s %s", summary().latin1(), relatedTo->summary().latin1() ); | 314 | //qDebug("setRelatedTo(Incidence *relatedTo) %s %s", summary().latin1(), relatedTo->summary().latin1() ); |
315 | if (mReadOnly || mRelatedTo == relatedTo) return; | 315 | if (mReadOnly || mRelatedTo == relatedTo) return; |
316 | if(mRelatedTo) { | 316 | if(mRelatedTo) { |
317 | // updated(); | 317 | // updated(); |
318 | mRelatedTo->removeRelation(this); | 318 | mRelatedTo->removeRelation(this); |
319 | } | 319 | } |
320 | mRelatedTo = relatedTo; | 320 | mRelatedTo = relatedTo; |
321 | if (mRelatedTo) mRelatedTo->addRelation(this); | 321 | if (mRelatedTo) mRelatedTo->addRelation(this); |
322 | } | 322 | } |
323 | 323 | ||
324 | Incidence *Incidence::relatedTo() const | 324 | Incidence *Incidence::relatedTo() const |
325 | { | 325 | { |
326 | return mRelatedTo; | 326 | return mRelatedTo; |
327 | } | 327 | } |
328 | 328 | ||
329 | QPtrList<Incidence> Incidence::relations() const | 329 | QPtrList<Incidence> Incidence::relations() const |
330 | { | 330 | { |
331 | return mRelations; | 331 | return mRelations; |
332 | } | 332 | } |
333 | 333 | ||
334 | void Incidence::addRelation(Incidence *event) | 334 | void Incidence::addRelation(Incidence *event) |
335 | { | 335 | { |
336 | if( mRelations.findRef( event ) == -1 ) { | 336 | if( mRelations.findRef( event ) == -1 ) { |
337 | mRelations.append(event); | 337 | mRelations.append(event); |
338 | //updated(); | 338 | //updated(); |
339 | } | 339 | } |
340 | } | 340 | } |
341 | 341 | ||
342 | void Incidence::removeRelation(Incidence *event) | 342 | void Incidence::removeRelation(Incidence *event) |
343 | { | 343 | { |
344 | 344 | ||
345 | mRelations.removeRef(event); | 345 | mRelations.removeRef(event); |
346 | 346 | ||
347 | // if (event->getRelatedTo() == this) event->setRelatedTo(0); | 347 | // if (event->getRelatedTo() == this) event->setRelatedTo(0); |
348 | } | 348 | } |
349 | 349 | ||
350 | bool Incidence::recursOn(const QDate &qd) const | 350 | bool Incidence::recursOn(const QDate &qd) const |
351 | { | 351 | { |
352 | if (recurrence()->recursOnPure(qd) && !isException(qd)) return true; | 352 | if (recurrence()->recursOnPure(qd) && !isException(qd)) return true; |
353 | else return false; | 353 | else return false; |
354 | } | 354 | } |
355 | 355 | ||
356 | void Incidence::setExDates(const DateList &exDates) | 356 | void Incidence::setExDates(const DateList &exDates) |
357 | { | 357 | { |
358 | if (mReadOnly) return; | 358 | if (mReadOnly) return; |
359 | mExDates = exDates; | 359 | mExDates = exDates; |
360 | 360 | ||
361 | recurrence()->setRecurExDatesCount(mExDates.count()); | 361 | recurrence()->setRecurExDatesCount(mExDates.count()); |
362 | 362 | ||
363 | updated(); | 363 | updated(); |
364 | } | 364 | } |
365 | 365 | ||
366 | void Incidence::addExDate(const QDate &date) | 366 | void Incidence::addExDate(const QDate &date) |
367 | { | 367 | { |
368 | if (mReadOnly) return; | 368 | if (mReadOnly) return; |
369 | mExDates.append(date); | 369 | mExDates.append(date); |
370 | 370 | ||
371 | recurrence()->setRecurExDatesCount(mExDates.count()); | 371 | recurrence()->setRecurExDatesCount(mExDates.count()); |
372 | 372 | ||
373 | updated(); | 373 | updated(); |
374 | } | 374 | } |
375 | 375 | ||
376 | DateList Incidence::exDates() const | 376 | DateList Incidence::exDates() const |
377 | { | 377 | { |
378 | return mExDates; | 378 | return mExDates; |
379 | } | 379 | } |
380 | 380 | ||
381 | bool Incidence::isException(const QDate &date) const | 381 | bool Incidence::isException(const QDate &date) const |
382 | { | 382 | { |
383 | DateList::ConstIterator it; | 383 | DateList::ConstIterator it; |
384 | for( it = mExDates.begin(); it != mExDates.end(); ++it ) { | 384 | for( it = mExDates.begin(); it != mExDates.end(); ++it ) { |
385 | if ( (*it) == date ) { | 385 | if ( (*it) == date ) { |
386 | return true; | 386 | return true; |
387 | } | 387 | } |
388 | } | 388 | } |
389 | 389 | ||
390 | return false; | 390 | return false; |
391 | } | 391 | } |
392 | 392 | ||
393 | void Incidence::addAttachment(Attachment *attachment) | 393 | void Incidence::addAttachment(Attachment *attachment) |
394 | { | 394 | { |
395 | if (mReadOnly || !attachment) return; | 395 | if (mReadOnly || !attachment) return; |
396 | mAttachments.append(attachment); | 396 | mAttachments.append(attachment); |
397 | updated(); | 397 | updated(); |
398 | } | 398 | } |
399 | 399 | ||
400 | void Incidence::deleteAttachment(Attachment *attachment) | 400 | void Incidence::deleteAttachment(Attachment *attachment) |
401 | { | 401 | { |
402 | mAttachments.removeRef(attachment); | 402 | mAttachments.removeRef(attachment); |
403 | } | 403 | } |
404 | 404 | ||
405 | void Incidence::deleteAttachments(const QString& mime) | 405 | void Incidence::deleteAttachments(const QString& mime) |
406 | { | 406 | { |
407 | Attachment *at = mAttachments.first(); | 407 | Attachment *at = mAttachments.first(); |
408 | while (at) { | 408 | while (at) { |
409 | if (at->mimeType() == mime) | 409 | if (at->mimeType() == mime) |
410 | mAttachments.remove(); | 410 | mAttachments.remove(); |
411 | else | 411 | else |
412 | at = mAttachments.next(); | 412 | at = mAttachments.next(); |
413 | } | 413 | } |
414 | } | 414 | } |
415 | 415 | ||
416 | QPtrList<Attachment> Incidence::attachments() const | 416 | QPtrList<Attachment> Incidence::attachments() const |
417 | { | 417 | { |
418 | return mAttachments; | 418 | return mAttachments; |
419 | } | 419 | } |
420 | 420 | ||
421 | QPtrList<Attachment> Incidence::attachments(const QString& mime) const | 421 | QPtrList<Attachment> Incidence::attachments(const QString& mime) const |
422 | { | 422 | { |
423 | QPtrList<Attachment> attachments; | 423 | QPtrList<Attachment> attachments; |
424 | QPtrListIterator<Attachment> it( mAttachments ); | 424 | QPtrListIterator<Attachment> it( mAttachments ); |
425 | Attachment *at; | 425 | Attachment *at; |
426 | while ( (at = it.current()) ) { | 426 | while ( (at = it.current()) ) { |
427 | if (at->mimeType() == mime) | 427 | if (at->mimeType() == mime) |
428 | attachments.append(at); | 428 | attachments.append(at); |
429 | ++it; | 429 | ++it; |
430 | } | 430 | } |
431 | 431 | ||
432 | return attachments; | 432 | return attachments; |
433 | } | 433 | } |
434 | 434 | ||
435 | void Incidence::setResources(const QStringList &resources) | 435 | void Incidence::setResources(const QStringList &resources) |
436 | { | 436 | { |
437 | if (mReadOnly) return; | 437 | if (mReadOnly) return; |
438 | mResources = resources; | 438 | mResources = resources; |
439 | updated(); | 439 | updated(); |
440 | } | 440 | } |
441 | 441 | ||
442 | QStringList Incidence::resources() const | 442 | QStringList Incidence::resources() const |
443 | { | 443 | { |
444 | return mResources; | 444 | return mResources; |
445 | } | 445 | } |
446 | 446 | ||
447 | 447 | ||
448 | void Incidence::setPriority(int priority) | 448 | void Incidence::setPriority(int priority) |
449 | { | 449 | { |
450 | if (mReadOnly) return; | 450 | if (mReadOnly) return; |
451 | mPriority = priority; | 451 | mPriority = priority; |
452 | updated(); | 452 | updated(); |
453 | } | 453 | } |
454 | 454 | ||
455 | int Incidence::priority() const | 455 | int Incidence::priority() const |
456 | { | 456 | { |
457 | return mPriority; | 457 | return mPriority; |
458 | } | 458 | } |
459 | 459 | ||
460 | void Incidence::setSecrecy(int sec) | 460 | void Incidence::setSecrecy(int sec) |
461 | { | 461 | { |
462 | if (mReadOnly) return; | 462 | if (mReadOnly) return; |
463 | mSecrecy = sec; | 463 | mSecrecy = sec; |
464 | updated(); | 464 | updated(); |
465 | } | 465 | } |
466 | 466 | ||
467 | int Incidence::secrecy() const | 467 | int Incidence::secrecy() const |
468 | { | 468 | { |
469 | return mSecrecy; | 469 | return mSecrecy; |
470 | } | 470 | } |
471 | 471 | ||
472 | QString Incidence::secrecyStr() const | 472 | QString Incidence::secrecyStr() const |
473 | { | 473 | { |
474 | return secrecyName(mSecrecy); | 474 | return secrecyName(mSecrecy); |
475 | } | 475 | } |
476 | 476 | ||
477 | QString Incidence::secrecyName(int secrecy) | 477 | QString Incidence::secrecyName(int secrecy) |
478 | { | 478 | { |
479 | switch (secrecy) { | 479 | switch (secrecy) { |
480 | case SecrecyPublic: | 480 | case SecrecyPublic: |
481 | return i18n("Public"); | 481 | return i18n("Public"); |
482 | break; | 482 | break; |
483 | case SecrecyPrivate: | 483 | case SecrecyPrivate: |
484 | return i18n("Private"); | 484 | return i18n("Private"); |
485 | break; | 485 | break; |
486 | case SecrecyConfidential: | 486 | case SecrecyConfidential: |
487 | return i18n("Confidential"); | 487 | return i18n("Confidential"); |
488 | break; | 488 | break; |
489 | default: | 489 | default: |
490 | return i18n("Undefined"); | 490 | return i18n("Undefined"); |
491 | break; | 491 | break; |
492 | } | 492 | } |
493 | } | 493 | } |
494 | 494 | ||
495 | QStringList Incidence::secrecyList() | 495 | QStringList Incidence::secrecyList() |
496 | { | 496 | { |
497 | QStringList list; | 497 | QStringList list; |
498 | list << secrecyName(SecrecyPublic); | 498 | list << secrecyName(SecrecyPublic); |
499 | list << secrecyName(SecrecyPrivate); | 499 | list << secrecyName(SecrecyPrivate); |
500 | list << secrecyName(SecrecyConfidential); | 500 | list << secrecyName(SecrecyConfidential); |
501 | 501 | ||
502 | return list; | 502 | return list; |
503 | } | 503 | } |
504 | 504 | ||
505 | 505 | ||
506 | QPtrList<Alarm> Incidence::alarms() const | 506 | QPtrList<Alarm> Incidence::alarms() const |
507 | { | 507 | { |
508 | return mAlarms; | 508 | return mAlarms; |
509 | } | 509 | } |
510 | 510 | ||
511 | Alarm* Incidence::newAlarm() | 511 | Alarm* Incidence::newAlarm() |
512 | { | 512 | { |
513 | Alarm* alarm = new Alarm(this); | 513 | Alarm* alarm = new Alarm(this); |
514 | mAlarms.append(alarm); | 514 | mAlarms.append(alarm); |
515 | // updated(); | 515 | // updated(); |
516 | return alarm; | 516 | return alarm; |
517 | } | 517 | } |
518 | 518 | ||
519 | void Incidence::addAlarm(Alarm *alarm) | 519 | void Incidence::addAlarm(Alarm *alarm) |
520 | { | 520 | { |
521 | mAlarms.append(alarm); | 521 | mAlarms.append(alarm); |
522 | updated(); | 522 | updated(); |
523 | } | 523 | } |
524 | 524 | ||
525 | void Incidence::removeAlarm(Alarm *alarm) | 525 | void Incidence::removeAlarm(Alarm *alarm) |
526 | { | 526 | { |
527 | mAlarms.removeRef(alarm); | 527 | mAlarms.removeRef(alarm); |
528 | updated(); | 528 | updated(); |
529 | } | 529 | } |
530 | 530 | ||
531 | void Incidence::clearAlarms() | 531 | void Incidence::clearAlarms() |
532 | { | 532 | { |
533 | mAlarms.clear(); | 533 | mAlarms.clear(); |
534 | updated(); | 534 | updated(); |
535 | } | 535 | } |
536 | 536 | ||
537 | bool Incidence::isAlarmEnabled() const | 537 | bool Incidence::isAlarmEnabled() const |
538 | { | 538 | { |
539 | Alarm* alarm; | 539 | Alarm* alarm; |
540 | for (QPtrListIterator<Alarm> it(mAlarms); (alarm = it.current()) != 0; ++it) { | 540 | for (QPtrListIterator<Alarm> it(mAlarms); (alarm = it.current()) != 0; ++it) { |
541 | if (alarm->enabled()) | 541 | if (alarm->enabled()) |
542 | return true; | 542 | return true; |
543 | } | 543 | } |
544 | return false; | 544 | return false; |
545 | } | 545 | } |
546 | 546 | ||
547 | Recurrence *Incidence::recurrence() const | 547 | Recurrence *Incidence::recurrence() const |
548 | { | 548 | { |
549 | return mRecurrence; | 549 | return mRecurrence; |
550 | } | 550 | } |
551 | void Incidence::setRecurrence( Recurrence * r) | 551 | void Incidence::setRecurrence( Recurrence * r) |
552 | { | 552 | { |
553 | delete mRecurrence; | 553 | delete mRecurrence; |
554 | mRecurrence = r; | 554 | mRecurrence = r; |
555 | } | 555 | } |
556 | 556 | ||
557 | void Incidence::setLocation(const QString &location) | 557 | void Incidence::setLocation(const QString &location) |
558 | { | 558 | { |
559 | if (mReadOnly) return; | 559 | if (mReadOnly) return; |
560 | mLocation = location; | 560 | mLocation = location; |
561 | updated(); | 561 | updated(); |
562 | } | 562 | } |
563 | 563 | ||
564 | QString Incidence::location() const | 564 | QString Incidence::location() const |
565 | { | 565 | { |
566 | return mLocation; | 566 | return mLocation; |
567 | } | 567 | } |
568 | 568 | ||
569 | ushort Incidence::doesRecur() const | 569 | ushort Incidence::doesRecur() const |
570 | { | 570 | { |
571 | if ( mRecurrence ) return mRecurrence->doesRecur(); | 571 | if ( mRecurrence ) return mRecurrence->doesRecur(); |
572 | else return Recurrence::rNone; | 572 | else return Recurrence::rNone; |
573 | } | 573 | } |
574 | 574 | ||
575 | QDateTime Incidence::getNextOccurence( const QDateTime& dt, bool* ok ) const | 575 | QDateTime Incidence::getNextOccurence( const QDateTime& dt, bool* ok ) const |
576 | { | 576 | { |
577 | QDateTime incidenceStart = dt; | 577 | QDateTime incidenceStart = dt; |
578 | *ok = false; | 578 | *ok = false; |
579 | if ( doesRecur() ) { | 579 | if ( doesRecur() ) { |
580 | bool last; | 580 | bool last; |
581 | recurrence()->getPreviousDateTime( incidenceStart , &last ); | 581 | recurrence()->getPreviousDateTime( incidenceStart , &last ); |
582 | int count = 0; | 582 | int count = 0; |
583 | if ( !last ) { | 583 | if ( !last ) { |
584 | while ( !last ) { | 584 | while ( !last ) { |
585 | ++count; | 585 | ++count; |
586 | incidenceStart = recurrence()->getNextDateTime( incidenceStart, &last ); | 586 | incidenceStart = recurrence()->getNextDateTime( incidenceStart, &last ); |
587 | if ( recursOn( incidenceStart.date() ) ) { | 587 | if ( recursOn( incidenceStart.date() ) ) { |
588 | last = true; // exit while llop | 588 | last = true; // exit while llop |
589 | } else { | 589 | } else { |
590 | if ( last ) { // no alarm on last recurrence | 590 | if ( last ) { // no alarm on last recurrence |
591 | return QDateTime (); | 591 | return QDateTime (); |
592 | } | 592 | } |
593 | int year = incidenceStart.date().year(); | 593 | int year = incidenceStart.date().year(); |
594 | // workaround for bug in recurrence | 594 | // workaround for bug in recurrence |
595 | if ( count == 100 || year < 1980 || year > 5000 ) { | 595 | if ( count == 100 || year < 1000 || year > 5000 ) { |
596 | return QDateTime (); | 596 | return QDateTime (); |
597 | } | 597 | } |
598 | incidenceStart = incidenceStart.addSecs( 1 ); | 598 | incidenceStart = incidenceStart.addSecs( 1 ); |
599 | } | 599 | } |
600 | } | 600 | } |
601 | } else { | 601 | } else { |
602 | return QDateTime (); | 602 | return QDateTime (); |
603 | } | 603 | } |
604 | } else { | 604 | } else { |
605 | if ( hasStartDate () ) { | 605 | if ( hasStartDate () ) { |
606 | incidenceStart = dtStart(); | 606 | incidenceStart = dtStart(); |
607 | } | 607 | } |
608 | if ( type() =="Todo" ) { | 608 | if ( type() =="Todo" ) { |
609 | if ( ((Todo*)this)->hasDueDate() ) | 609 | if ( ((Todo*)this)->hasDueDate() ) |
610 | incidenceStart = ((Todo*)this)->dtDue(); | 610 | incidenceStart = ((Todo*)this)->dtDue(); |
611 | |||
612 | } | 611 | } |
613 | } | 612 | } |
614 | if ( incidenceStart > dt ) | 613 | if ( incidenceStart > dt ) |
615 | *ok = true; | 614 | *ok = true; |
616 | return incidenceStart; | 615 | return incidenceStart; |
617 | } | 616 | } |