summaryrefslogtreecommitdiffabout
path: root/libkcal/calendarlocal.cpp
Unidiff
Diffstat (limited to 'libkcal/calendarlocal.cpp') (more/less context) (show whitespace changes)
-rw-r--r--libkcal/calendarlocal.cpp6
1 files changed, 3 insertions, 3 deletions
diff --git a/libkcal/calendarlocal.cpp b/libkcal/calendarlocal.cpp
index e75df70..bc76c0b 100644
--- a/libkcal/calendarlocal.cpp
+++ b/libkcal/calendarlocal.cpp
@@ -261,97 +261,97 @@ QPtrList<Event> CalendarLocal::getExternLastSyncEvents()
261 } 261 }
262 262
263 return el; 263 return el;
264 264
265} 265}
266Event *CalendarLocal::event( QString syncProf, QString id ) 266Event *CalendarLocal::event( QString syncProf, QString id )
267{ 267{
268 Event *todo; 268 Event *todo;
269 for ( todo = mEventList.first(); todo; todo = mEventList.next() ) { 269 for ( todo = mEventList.first(); todo; todo = mEventList.next() ) {
270 if ( todo->getID( syncProf ) == id ) return todo; 270 if ( todo->getID( syncProf ) == id ) return todo;
271 } 271 }
272 272
273 return 0; 273 return 0;
274} 274}
275Todo *CalendarLocal::todo( const QString &uid ) 275Todo *CalendarLocal::todo( const QString &uid )
276{ 276{
277 Todo *todo; 277 Todo *todo;
278 for ( todo = mTodoList.first(); todo; todo = mTodoList.next() ) { 278 for ( todo = mTodoList.first(); todo; todo = mTodoList.next() ) {
279 if ( todo->uid() == uid ) return todo; 279 if ( todo->uid() == uid ) return todo;
280 } 280 }
281 281
282 return 0; 282 return 0;
283} 283}
284QString CalendarLocal::nextSummary() const 284QString CalendarLocal::nextSummary() const
285{ 285{
286 return mNextSummary; 286 return mNextSummary;
287} 287}
288QDateTime CalendarLocal::nextAlarmEventDateTime() const 288QDateTime CalendarLocal::nextAlarmEventDateTime() const
289{ 289{
290 return mNextAlarmEventDateTime; 290 return mNextAlarmEventDateTime;
291} 291}
292void CalendarLocal::checkAlarmForIncidence( Incidence * incidence, bool deleted) 292void CalendarLocal::checkAlarmForIncidence( Incidence * incidence, bool deleted)
293{ 293{
294 //mNextAlarmIncidence 294 //mNextAlarmIncidence
295 //mNextAlarmDateTime 295 //mNextAlarmDateTime
296 //return mNextSummary; 296 //return mNextSummary;
297 //return mNextAlarmEventDateTime; 297 //return mNextAlarmEventDateTime;
298 bool newNextAlarm = false; 298 bool newNextAlarm = false;
299 bool computeNextAlarm = false; 299 bool computeNextAlarm = false;
300 bool ok; 300 bool ok;
301 int offset; 301 int offset;
302 QDateTime nextA; 302 QDateTime nextA;
303 // QString nextSum; 303 // QString nextSum;
304 //QDateTime nextEvent; 304 //QDateTime nextEvent;
305 if ( mNextAlarmIncidence == 0 || incidence == 0 ) { 305 if ( mNextAlarmIncidence == 0 || incidence == 0 ) {
306 computeNextAlarm = true; 306 computeNextAlarm = true;
307 } else { 307 } else {
308 if ( ! deleted ) { 308 if ( ! deleted ) {
309 nextA = incidence->getNextAlarmDateTime(& ok, &offset ) ; 309 nextA = incidence->getNextAlarmDateTime(& ok, &offset, QDateTime::currentDateTime() ) ;
310 if ( ok ) { 310 if ( ok ) {
311 if ( nextA < mNextAlarmDateTime ) { 311 if ( nextA < mNextAlarmDateTime ) {
312 deRegisterAlarm(); 312 deRegisterAlarm();
313 mNextAlarmDateTime = nextA; 313 mNextAlarmDateTime = nextA;
314 mNextSummary = incidence->summary(); 314 mNextSummary = incidence->summary();
315 mNextAlarmEventDateTime = nextA.addSecs(offset ) ; 315 mNextAlarmEventDateTime = nextA.addSecs(offset ) ;
316 mNextAlarmEventDateTimeString = KGlobal::locale()->formatDateTime(mNextAlarmEventDateTime); 316 mNextAlarmEventDateTimeString = KGlobal::locale()->formatDateTime(mNextAlarmEventDateTime);
317 newNextAlarm = true; 317 newNextAlarm = true;
318 mNextAlarmIncidence = incidence; 318 mNextAlarmIncidence = incidence;
319 } else { 319 } else {
320 if ( incidence == mNextAlarmIncidence ) { 320 if ( incidence == mNextAlarmIncidence ) {
321 computeNextAlarm = true; 321 computeNextAlarm = true;
322 } 322 }
323 } 323 }
324 } else { 324 } else {
325 if ( mNextAlarmIncidence == incidence ) { 325 if ( mNextAlarmIncidence == incidence ) {
326 computeNextAlarm = true; 326 computeNextAlarm = true;
327 } 327 }
328 } 328 }
329 } else { // deleted 329 } else { // deleted
330 if ( incidence == mNextAlarmIncidence ) { 330 if ( incidence == mNextAlarmIncidence ) {
331 computeNextAlarm = true; 331 computeNextAlarm = true;
332 } 332 }
333 } 333 }
334 } 334 }
335 if ( computeNextAlarm ) { 335 if ( computeNextAlarm ) {
336 deRegisterAlarm(); 336 deRegisterAlarm();
337 nextA = nextAlarm( 1000 ); 337 nextA = nextAlarm( 1000 );
338 if (! mNextAlarmIncidence ) { 338 if (! mNextAlarmIncidence ) {
339 return; 339 return;
340 } 340 }
341 newNextAlarm = true; 341 newNextAlarm = true;
342 } 342 }
343 if ( newNextAlarm ) 343 if ( newNextAlarm )
344 registerAlarm(); 344 registerAlarm();
345} 345}
346QString CalendarLocal:: getAlarmNotification() 346QString CalendarLocal:: getAlarmNotification()
347{ 347{
348 QString ret; 348 QString ret;
349 // this should not happen 349 // this should not happen
350 if (! mNextAlarmIncidence ) 350 if (! mNextAlarmIncidence )
351 return "cal_alarm"+ mNextSummary.left( 25 )+"\n"+mNextAlarmEventDateTimeString; 351 return "cal_alarm"+ mNextSummary.left( 25 )+"\n"+mNextAlarmEventDateTimeString;
352 Alarm* alarm = mNextAlarmIncidence->alarms().first(); 352 Alarm* alarm = mNextAlarmIncidence->alarms().first();
353 if ( alarm->type() == Alarm::Procedure ) { 353 if ( alarm->type() == Alarm::Procedure ) {
354 ret = "proc_alarm" + alarm->programFile()+"+++"; 354 ret = "proc_alarm" + alarm->programFile()+"+++";
355 } else { 355 } else {
356 ret = "audio_alarm" +alarm->audioFile() +"+++"; 356 ret = "audio_alarm" +alarm->audioFile() +"+++";
357 } 357 }
@@ -376,110 +376,110 @@ void CalendarLocal::deRegisterAlarm()
376 return; 376 return;
377 //qDebug("-- deregister Alarm %s ", mLastAlarmNotificationString.latin1() ); 377 //qDebug("-- deregister Alarm %s ", mLastAlarmNotificationString.latin1() );
378 378
379 emit removeAlarm ( mNextAlarmDateTime, mLastAlarmNotificationString ); 379 emit removeAlarm ( mNextAlarmDateTime, mLastAlarmNotificationString );
380 mNextAlarmEventDateTime = QDateTime(); 380 mNextAlarmEventDateTime = QDateTime();
381// #ifndef DESKTOP_VERSION 381// #ifndef DESKTOP_VERSION
382// AlarmServer::deleteAlarm (mNextAlarmDateTime ,"koalarm" ,mLastAlarmNotificationString.latin1() ); 382// AlarmServer::deleteAlarm (mNextAlarmDateTime ,"koalarm" ,mLastAlarmNotificationString.latin1() );
383// #endif 383// #endif
384} 384}
385 385
386QPtrList<Todo> CalendarLocal::todos( const QDate &date ) 386QPtrList<Todo> CalendarLocal::todos( const QDate &date )
387{ 387{
388 QPtrList<Todo> todos; 388 QPtrList<Todo> todos;
389 389
390 Todo *todo; 390 Todo *todo;
391 for ( todo = mTodoList.first(); todo; todo = mTodoList.next() ) { 391 for ( todo = mTodoList.first(); todo; todo = mTodoList.next() ) {
392 if ( todo->hasDueDate() && todo->dtDue().date() == date ) { 392 if ( todo->hasDueDate() && todo->dtDue().date() == date ) {
393 todos.append( todo ); 393 todos.append( todo );
394 } 394 }
395 } 395 }
396 396
397 filter()->apply( &todos ); 397 filter()->apply( &todos );
398 return todos; 398 return todos;
399} 399}
400void CalendarLocal::reInitAlarmSettings() 400void CalendarLocal::reInitAlarmSettings()
401{ 401{
402 if ( !mNextAlarmIncidence ) { 402 if ( !mNextAlarmIncidence ) {
403 nextAlarm( 1000 ); 403 nextAlarm( 1000 );
404 } 404 }
405 deRegisterAlarm(); 405 deRegisterAlarm();
406 mNextAlarmIncidence = 0; 406 mNextAlarmIncidence = 0;
407 checkAlarmForIncidence( 0, false ); 407 checkAlarmForIncidence( 0, false );
408 408
409} 409}
410 410
411 411
412 412
413QDateTime CalendarLocal::nextAlarm( int daysTo ) 413QDateTime CalendarLocal::nextAlarm( int daysTo )
414{ 414{
415 QDateTime nextA = QDateTime::currentDateTime().addDays( daysTo ); 415 QDateTime nextA = QDateTime::currentDateTime().addDays( daysTo );
416 QDateTime start = QDateTime::currentDateTime().addSecs( 30 ); 416 QDateTime start = QDateTime::currentDateTime().addSecs( 30 );
417 QDateTime next; 417 QDateTime next;
418 Event *e; 418 Event *e;
419 bool ok; 419 bool ok;
420 bool found = false; 420 bool found = false;
421 int offset; 421 int offset;
422 mNextAlarmIncidence = 0; 422 mNextAlarmIncidence = 0;
423 for( e = mEventList.first(); e; e = mEventList.next() ) { 423 for( e = mEventList.first(); e; e = mEventList.next() ) {
424 next = e->getNextAlarmDateTime(& ok, &offset ) ; 424 next = e->getNextAlarmDateTime(& ok, &offset, QDateTime::currentDateTime() ) ;
425 if ( ok ) { 425 if ( ok ) {
426 if ( next < nextA ) { 426 if ( next < nextA ) {
427 nextA = next; 427 nextA = next;
428 found = true; 428 found = true;
429 mNextSummary = e->summary(); 429 mNextSummary = e->summary();
430 mNextAlarmEventDateTime = next.addSecs(offset ) ; 430 mNextAlarmEventDateTime = next.addSecs(offset ) ;
431 mNextAlarmIncidence = (Incidence *) e; 431 mNextAlarmIncidence = (Incidence *) e;
432 } 432 }
433 } 433 }
434 } 434 }
435 Todo *t; 435 Todo *t;
436 for( t = mTodoList.first(); t; t = mTodoList.next() ) { 436 for( t = mTodoList.first(); t; t = mTodoList.next() ) {
437 next = t->getNextAlarmDateTime(& ok, &offset ) ; 437 next = t->getNextAlarmDateTime(& ok, &offset, QDateTime::currentDateTime() ) ;
438 if ( ok ) { 438 if ( ok ) {
439 if ( next < nextA ) { 439 if ( next < nextA ) {
440 nextA = next; 440 nextA = next;
441 found = true; 441 found = true;
442 mNextSummary = t->summary(); 442 mNextSummary = t->summary();
443 mNextAlarmEventDateTime = next.addSecs(offset ); 443 mNextAlarmEventDateTime = next.addSecs(offset );
444 mNextAlarmIncidence = (Incidence *) t; 444 mNextAlarmIncidence = (Incidence *) t;
445 } 445 }
446 } 446 }
447 } 447 }
448 if ( mNextAlarmIncidence ) { 448 if ( mNextAlarmIncidence ) {
449 mNextAlarmEventDateTimeString = KGlobal::locale()->formatDateTime(mNextAlarmEventDateTime); 449 mNextAlarmEventDateTimeString = KGlobal::locale()->formatDateTime(mNextAlarmEventDateTime);
450 mNextAlarmDateTime = nextA; 450 mNextAlarmDateTime = nextA;
451 } 451 }
452 return nextA; 452 return nextA;
453} 453}
454Alarm::List CalendarLocal::alarmsTo( const QDateTime &to ) 454Alarm::List CalendarLocal::alarmsTo( const QDateTime &to )
455{ 455{
456 return alarms( QDateTime( QDate( 1900, 1, 1 ) ), to ); 456 return alarms( QDateTime( QDate( 1900, 1, 1 ) ), to );
457} 457}
458 458
459Alarm::List CalendarLocal::alarms( const QDateTime &from, const QDateTime &to ) 459Alarm::List CalendarLocal::alarms( const QDateTime &from, const QDateTime &to )
460{ 460{
461 kdDebug(5800) << "CalendarLocal::alarms(" << from.toString() << " - " 461 kdDebug(5800) << "CalendarLocal::alarms(" << from.toString() << " - "
462 << to.toString() << ")\n"; 462 << to.toString() << ")\n";
463 463
464 Alarm::List alarms; 464 Alarm::List alarms;
465 465
466 Event *e; 466 Event *e;
467 467
468 for( e = mEventList.first(); e; e = mEventList.next() ) { 468 for( e = mEventList.first(); e; e = mEventList.next() ) {
469 if ( e->doesRecur() ) appendRecurringAlarms( alarms, e, from, to ); 469 if ( e->doesRecur() ) appendRecurringAlarms( alarms, e, from, to );
470 else appendAlarms( alarms, e, from, to ); 470 else appendAlarms( alarms, e, from, to );
471 } 471 }
472 472
473 Todo *t; 473 Todo *t;
474 for( t = mTodoList.first(); t; t = mTodoList.next() ) { 474 for( t = mTodoList.first(); t; t = mTodoList.next() ) {
475 appendAlarms( alarms, t, from, to ); 475 appendAlarms( alarms, t, from, to );
476 } 476 }
477 477
478 return alarms; 478 return alarms;
479} 479}
480 480
481void CalendarLocal::appendAlarms( Alarm::List &alarms, Incidence *incidence, 481void CalendarLocal::appendAlarms( Alarm::List &alarms, Incidence *incidence,
482 const QDateTime &from, const QDateTime &to ) 482 const QDateTime &from, const QDateTime &to )
483{ 483{
484 QPtrList<Alarm> alarmList = incidence->alarms(); 484 QPtrList<Alarm> alarmList = incidence->alarms();
485 Alarm *alarm; 485 Alarm *alarm;