author | zautrix <zautrix> | 2005-04-04 18:24:25 (UTC) |
---|---|---|
committer | zautrix <zautrix> | 2005-04-04 18:24:25 (UTC) |
commit | ff205358654ed8741f0008eabd64a0e8b0476b61 (patch) (unidiff) | |
tree | 52844c5c14286c463fc11b132b6d92cd6d72c96c /libkcal/calendarlocal.cpp | |
parent | 13fa1e5e1d5e4663bbbc79e0c68caf725ad2e31b (diff) | |
download | kdepimpi-ff205358654ed8741f0008eabd64a0e8b0476b61.zip kdepimpi-ff205358654ed8741f0008eabd64a0e8b0476b61.tar.gz kdepimpi-ff205358654ed8741f0008eabd64a0e8b0476b61.tar.bz2 |
fix
-rw-r--r-- | libkcal/calendarlocal.cpp | 2 |
1 files changed, 1 insertions, 1 deletions
diff --git a/libkcal/calendarlocal.cpp b/libkcal/calendarlocal.cpp index 5c889c3..00a43e5 100644 --- a/libkcal/calendarlocal.cpp +++ b/libkcal/calendarlocal.cpp | |||
@@ -205,268 +205,268 @@ void CalendarLocal::deleteTodo( Todo *todo ) | |||
205 | removeRelations( todo ); | 205 | removeRelations( 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 | if ( lse ) | 245 | if ( lse ) |
246 | deleteIncidence ( lse ); | 246 | deleteIncidence ( lse ); |
247 | } | 247 | } |
248 | } | 248 | } |
249 | QPtrList<Event> CalendarLocal::getExternLastSyncEvents() | 249 | QPtrList<Event> CalendarLocal::getExternLastSyncEvents() |
250 | { | 250 | { |
251 | QPtrList<Event> el; | 251 | QPtrList<Event> el; |
252 | Event *todo; | 252 | Event *todo; |
253 | for ( todo = mEventList.first(); todo; todo = mEventList.next() ) { | 253 | for ( todo = mEventList.first(); todo; todo = mEventList.next() ) { |
254 | if ( todo->uid().left( 15 ) == QString("last-syncEvent-") ) | 254 | if ( todo->uid().left( 15 ) == QString("last-syncEvent-") ) |
255 | if ( todo->summary().left(3) == "E: " ) | 255 | if ( todo->summary().left(3) == "E: " ) |
256 | el.append( todo ); | 256 | el.append( todo ); |
257 | } | 257 | } |
258 | 258 | ||
259 | return el; | 259 | return el; |
260 | 260 | ||
261 | } | 261 | } |
262 | Event *CalendarLocal::event( QString syncProf, QString id ) | 262 | Event *CalendarLocal::event( QString syncProf, QString id ) |
263 | { | 263 | { |
264 | Event *todo; | 264 | Event *todo; |
265 | for ( todo = mEventList.first(); todo; todo = mEventList.next() ) { | 265 | for ( todo = mEventList.first(); todo; todo = mEventList.next() ) { |
266 | if ( todo->getID( syncProf ) == id ) return todo; | 266 | if ( todo->getID( syncProf ) == id ) return todo; |
267 | } | 267 | } |
268 | 268 | ||
269 | return 0; | 269 | return 0; |
270 | } | 270 | } |
271 | Todo *CalendarLocal::todo( const QString &uid ) | 271 | Todo *CalendarLocal::todo( const QString &uid ) |
272 | { | 272 | { |
273 | Todo *todo; | 273 | Todo *todo; |
274 | for ( todo = mTodoList.first(); todo; todo = mTodoList.next() ) { | 274 | for ( todo = mTodoList.first(); todo; todo = mTodoList.next() ) { |
275 | if ( todo->uid() == uid ) return todo; | 275 | if ( todo->uid() == uid ) return todo; |
276 | } | 276 | } |
277 | 277 | ||
278 | return 0; | 278 | return 0; |
279 | } | 279 | } |
280 | QString CalendarLocal::nextSummary() const | 280 | QString CalendarLocal::nextSummary() const |
281 | { | 281 | { |
282 | return mNextSummary; | 282 | return mNextSummary; |
283 | } | 283 | } |
284 | QDateTime CalendarLocal::nextAlarmEventDateTime() const | 284 | QDateTime CalendarLocal::nextAlarmEventDateTime() const |
285 | { | 285 | { |
286 | return mNextAlarmEventDateTime; | 286 | return mNextAlarmEventDateTime; |
287 | } | 287 | } |
288 | void CalendarLocal::checkAlarmForIncidence( Incidence * incidence, bool deleted) | 288 | void CalendarLocal::checkAlarmForIncidence( Incidence * incidence, bool deleted) |
289 | { | 289 | { |
290 | //mNextAlarmIncidence | 290 | //mNextAlarmIncidence |
291 | //mNextAlarmDateTime | 291 | //mNextAlarmDateTime |
292 | //return mNextSummary; | 292 | //return mNextSummary; |
293 | //return mNextAlarmEventDateTime; | 293 | //return mNextAlarmEventDateTime; |
294 | bool newNextAlarm = false; | 294 | bool newNextAlarm = false; |
295 | bool computeNextAlarm = false; | 295 | bool computeNextAlarm = false; |
296 | bool ok; | 296 | bool ok; |
297 | int offset; | 297 | int offset; |
298 | QDateTime nextA; | 298 | QDateTime nextA; |
299 | // QString nextSum; | 299 | // QString nextSum; |
300 | //QDateTime nextEvent; | 300 | //QDateTime nextEvent; |
301 | mNextAlarmEventDateTime = QDateTime(); | ||
302 | if ( mNextAlarmIncidence == 0 || incidence == 0 ) { | 301 | if ( mNextAlarmIncidence == 0 || incidence == 0 ) { |
303 | computeNextAlarm = true; | 302 | computeNextAlarm = true; |
304 | } else { | 303 | } else { |
305 | if ( ! deleted ) { | 304 | if ( ! deleted ) { |
306 | nextA = incidence->getNextAlarmDateTime(& ok, &offset ) ; | 305 | nextA = incidence->getNextAlarmDateTime(& ok, &offset ) ; |
307 | if ( ok ) { | 306 | if ( ok ) { |
308 | if ( nextA < mNextAlarmDateTime ) { | 307 | if ( nextA < mNextAlarmDateTime ) { |
309 | deRegisterAlarm(); | 308 | deRegisterAlarm(); |
310 | mNextAlarmDateTime = nextA; | 309 | mNextAlarmDateTime = nextA; |
311 | mNextSummary = incidence->summary(); | 310 | mNextSummary = incidence->summary(); |
312 | mNextAlarmEventDateTime = nextA.addSecs(offset ) ; | 311 | mNextAlarmEventDateTime = nextA.addSecs(offset ) ; |
313 | mNextAlarmEventDateTimeString = KGlobal::locale()->formatDateTime(mNextAlarmEventDateTime); | 312 | mNextAlarmEventDateTimeString = KGlobal::locale()->formatDateTime(mNextAlarmEventDateTime); |
314 | newNextAlarm = true; | 313 | newNextAlarm = true; |
315 | mNextAlarmIncidence = incidence; | 314 | mNextAlarmIncidence = incidence; |
316 | } else { | 315 | } else { |
317 | if ( incidence == mNextAlarmIncidence ) { | 316 | if ( incidence == mNextAlarmIncidence ) { |
318 | computeNextAlarm = true; | 317 | computeNextAlarm = true; |
319 | } | 318 | } |
320 | } | 319 | } |
321 | } else { | 320 | } else { |
322 | if ( mNextAlarmIncidence == incidence ) { | 321 | if ( mNextAlarmIncidence == incidence ) { |
323 | computeNextAlarm = true; | 322 | computeNextAlarm = true; |
324 | } | 323 | } |
325 | } | 324 | } |
326 | } else { // deleted | 325 | } else { // deleted |
327 | if ( incidence == mNextAlarmIncidence ) { | 326 | if ( incidence == mNextAlarmIncidence ) { |
328 | computeNextAlarm = true; | 327 | computeNextAlarm = true; |
329 | } | 328 | } |
330 | } | 329 | } |
331 | } | 330 | } |
332 | if ( computeNextAlarm ) { | 331 | if ( computeNextAlarm ) { |
333 | deRegisterAlarm(); | 332 | deRegisterAlarm(); |
334 | nextA = nextAlarm( 1000 ); | 333 | nextA = nextAlarm( 1000 ); |
335 | if (! mNextAlarmIncidence ) { | 334 | if (! mNextAlarmIncidence ) { |
336 | return; | 335 | return; |
337 | } | 336 | } |
338 | newNextAlarm = true; | 337 | newNextAlarm = true; |
339 | } | 338 | } |
340 | if ( newNextAlarm ) | 339 | if ( newNextAlarm ) |
341 | registerAlarm(); | 340 | registerAlarm(); |
342 | } | 341 | } |
343 | QString CalendarLocal:: getAlarmNotification() | 342 | QString CalendarLocal:: getAlarmNotification() |
344 | { | 343 | { |
345 | QString ret; | 344 | QString ret; |
346 | // this should not happen | 345 | // this should not happen |
347 | if (! mNextAlarmIncidence ) | 346 | if (! mNextAlarmIncidence ) |
348 | return "cal_alarm"+ mNextSummary.left( 25 )+"\n"+mNextAlarmEventDateTimeString; | 347 | return "cal_alarm"+ mNextSummary.left( 25 )+"\n"+mNextAlarmEventDateTimeString; |
349 | Alarm* alarm = mNextAlarmIncidence->alarms().first(); | 348 | Alarm* alarm = mNextAlarmIncidence->alarms().first(); |
350 | if ( alarm->type() == Alarm::Procedure ) { | 349 | if ( alarm->type() == Alarm::Procedure ) { |
351 | ret = "proc_alarm" + alarm->programFile()+"+++"; | 350 | ret = "proc_alarm" + alarm->programFile()+"+++"; |
352 | } else { | 351 | } else { |
353 | ret = "audio_alarm" +alarm->audioFile() +"+++"; | 352 | ret = "audio_alarm" +alarm->audioFile() +"+++"; |
354 | } | 353 | } |
355 | ret += "cal_alarm"+ mNextSummary.left( 25 ); | 354 | ret += "cal_alarm"+ mNextSummary.left( 25 ); |
356 | if ( mNextSummary.length() > 25 ) | 355 | if ( mNextSummary.length() > 25 ) |
357 | ret += "\n" + mNextSummary.mid(25, 25 ); | 356 | ret += "\n" + mNextSummary.mid(25, 25 ); |
358 | ret+= "\n"+mNextAlarmEventDateTimeString; | 357 | ret+= "\n"+mNextAlarmEventDateTimeString; |
359 | return ret; | 358 | return ret; |
360 | } | 359 | } |
361 | void CalendarLocal::registerAlarm() | 360 | void CalendarLocal::registerAlarm() |
362 | { | 361 | { |
363 | mLastAlarmNotificationString = getAlarmNotification(); | 362 | mLastAlarmNotificationString = getAlarmNotification(); |
364 | // qDebug("++ register Alarm %s %s",mNextAlarmDateTime.toString().latin1(), mLastAlarmNotificationString.latin1() ); | 363 | // qDebug("++ register Alarm %s %s",mNextAlarmDateTime.toString().latin1(), mLastAlarmNotificationString.latin1() ); |
365 | emit addAlarm ( mNextAlarmDateTime, mLastAlarmNotificationString ); | 364 | emit addAlarm ( mNextAlarmDateTime, mLastAlarmNotificationString ); |
366 | // #ifndef DESKTOP_VERSION | 365 | // #ifndef DESKTOP_VERSION |
367 | // AlarmServer::addAlarm ( mNextAlarmDateTime,"koalarm", mLastAlarmNotificationString.latin1() ); | 366 | // AlarmServer::addAlarm ( mNextAlarmDateTime,"koalarm", mLastAlarmNotificationString.latin1() ); |
368 | // #endif | 367 | // #endif |
369 | } | 368 | } |
370 | void CalendarLocal::deRegisterAlarm() | 369 | void CalendarLocal::deRegisterAlarm() |
371 | { | 370 | { |
372 | if ( mLastAlarmNotificationString.isNull() ) | 371 | if ( mLastAlarmNotificationString.isNull() ) |
373 | return; | 372 | return; |
374 | //qDebug("-- deregister Alarm %s ", mLastAlarmNotificationString.latin1() ); | 373 | //qDebug("-- deregister Alarm %s ", mLastAlarmNotificationString.latin1() ); |
375 | 374 | ||
376 | emit removeAlarm ( mNextAlarmDateTime, mLastAlarmNotificationString ); | 375 | emit removeAlarm ( mNextAlarmDateTime, mLastAlarmNotificationString ); |
376 | mNextAlarmEventDateTime = QDateTime(); | ||
377 | // #ifndef DESKTOP_VERSION | 377 | // #ifndef DESKTOP_VERSION |
378 | // AlarmServer::deleteAlarm (mNextAlarmDateTime ,"koalarm" ,mLastAlarmNotificationString.latin1() ); | 378 | // AlarmServer::deleteAlarm (mNextAlarmDateTime ,"koalarm" ,mLastAlarmNotificationString.latin1() ); |
379 | // #endif | 379 | // #endif |
380 | } | 380 | } |
381 | 381 | ||
382 | QPtrList<Todo> CalendarLocal::todos( const QDate &date ) | 382 | QPtrList<Todo> CalendarLocal::todos( const QDate &date ) |
383 | { | 383 | { |
384 | QPtrList<Todo> todos; | 384 | QPtrList<Todo> todos; |
385 | 385 | ||
386 | Todo *todo; | 386 | Todo *todo; |
387 | for ( todo = mTodoList.first(); todo; todo = mTodoList.next() ) { | 387 | for ( todo = mTodoList.first(); todo; todo = mTodoList.next() ) { |
388 | if ( todo->hasDueDate() && todo->dtDue().date() == date ) { | 388 | if ( todo->hasDueDate() && todo->dtDue().date() == date ) { |
389 | todos.append( todo ); | 389 | todos.append( todo ); |
390 | } | 390 | } |
391 | } | 391 | } |
392 | 392 | ||
393 | filter()->apply( &todos ); | 393 | filter()->apply( &todos ); |
394 | return todos; | 394 | return todos; |
395 | } | 395 | } |
396 | void CalendarLocal::reInitAlarmSettings() | 396 | void CalendarLocal::reInitAlarmSettings() |
397 | { | 397 | { |
398 | if ( !mNextAlarmIncidence ) { | 398 | if ( !mNextAlarmIncidence ) { |
399 | nextAlarm( 1000 ); | 399 | nextAlarm( 1000 ); |
400 | } | 400 | } |
401 | deRegisterAlarm(); | 401 | deRegisterAlarm(); |
402 | mNextAlarmIncidence = 0; | 402 | mNextAlarmIncidence = 0; |
403 | checkAlarmForIncidence( 0, false ); | 403 | checkAlarmForIncidence( 0, false ); |
404 | 404 | ||
405 | } | 405 | } |
406 | 406 | ||
407 | 407 | ||
408 | 408 | ||
409 | QDateTime CalendarLocal::nextAlarm( int daysTo ) | 409 | QDateTime CalendarLocal::nextAlarm( int daysTo ) |
410 | { | 410 | { |
411 | QDateTime nextA = QDateTime::currentDateTime().addDays( daysTo ); | 411 | QDateTime nextA = QDateTime::currentDateTime().addDays( daysTo ); |
412 | QDateTime start = QDateTime::currentDateTime().addSecs( 30 ); | 412 | QDateTime start = QDateTime::currentDateTime().addSecs( 30 ); |
413 | QDateTime next; | 413 | QDateTime next; |
414 | Event *e; | 414 | Event *e; |
415 | bool ok; | 415 | bool ok; |
416 | bool found = false; | 416 | bool found = false; |
417 | int offset; | 417 | int offset; |
418 | mNextAlarmIncidence = 0; | 418 | mNextAlarmIncidence = 0; |
419 | for( e = mEventList.first(); e; e = mEventList.next() ) { | 419 | for( e = mEventList.first(); e; e = mEventList.next() ) { |
420 | next = e->getNextAlarmDateTime(& ok, &offset ) ; | 420 | next = e->getNextAlarmDateTime(& ok, &offset ) ; |
421 | if ( ok ) { | 421 | if ( ok ) { |
422 | if ( next < nextA ) { | 422 | if ( next < nextA ) { |
423 | nextA = next; | 423 | nextA = next; |
424 | found = true; | 424 | found = true; |
425 | mNextSummary = e->summary(); | 425 | mNextSummary = e->summary(); |
426 | mNextAlarmEventDateTime = next.addSecs(offset ) ; | 426 | mNextAlarmEventDateTime = next.addSecs(offset ) ; |
427 | mNextAlarmIncidence = (Incidence *) e; | 427 | mNextAlarmIncidence = (Incidence *) e; |
428 | } | 428 | } |
429 | } | 429 | } |
430 | } | 430 | } |
431 | Todo *t; | 431 | Todo *t; |
432 | for( t = mTodoList.first(); t; t = mTodoList.next() ) { | 432 | for( t = mTodoList.first(); t; t = mTodoList.next() ) { |
433 | next = t->getNextAlarmDateTime(& ok, &offset ) ; | 433 | next = t->getNextAlarmDateTime(& ok, &offset ) ; |
434 | if ( ok ) { | 434 | if ( ok ) { |
435 | if ( next < nextA ) { | 435 | if ( next < nextA ) { |
436 | nextA = next; | 436 | nextA = next; |
437 | found = true; | 437 | found = true; |
438 | mNextSummary = t->summary(); | 438 | mNextSummary = t->summary(); |
439 | mNextAlarmEventDateTime = next.addSecs(offset ); | 439 | mNextAlarmEventDateTime = next.addSecs(offset ); |
440 | mNextAlarmIncidence = (Incidence *) t; | 440 | mNextAlarmIncidence = (Incidence *) t; |
441 | } | 441 | } |
442 | } | 442 | } |
443 | } | 443 | } |
444 | if ( mNextAlarmIncidence ) { | 444 | if ( mNextAlarmIncidence ) { |
445 | mNextAlarmEventDateTimeString = KGlobal::locale()->formatDateTime(mNextAlarmEventDateTime); | 445 | mNextAlarmEventDateTimeString = KGlobal::locale()->formatDateTime(mNextAlarmEventDateTime); |
446 | mNextAlarmDateTime = nextA; | 446 | mNextAlarmDateTime = nextA; |
447 | } | 447 | } |
448 | return nextA; | 448 | return nextA; |
449 | } | 449 | } |
450 | Alarm::List CalendarLocal::alarmsTo( const QDateTime &to ) | 450 | Alarm::List CalendarLocal::alarmsTo( const QDateTime &to ) |
451 | { | 451 | { |
452 | return alarms( QDateTime( QDate( 1900, 1, 1 ) ), to ); | 452 | return alarms( QDateTime( QDate( 1900, 1, 1 ) ), to ); |
453 | } | 453 | } |
454 | 454 | ||
455 | Alarm::List CalendarLocal::alarms( const QDateTime &from, const QDateTime &to ) | 455 | Alarm::List CalendarLocal::alarms( const QDateTime &from, const QDateTime &to ) |
456 | { | 456 | { |
457 | kdDebug(5800) << "CalendarLocal::alarms(" << from.toString() << " - " | 457 | kdDebug(5800) << "CalendarLocal::alarms(" << from.toString() << " - " |
458 | << to.toString() << ")\n"; | 458 | << to.toString() << ")\n"; |
459 | 459 | ||
460 | Alarm::List alarms; | 460 | Alarm::List alarms; |
461 | 461 | ||
462 | Event *e; | 462 | Event *e; |
463 | 463 | ||
464 | for( e = mEventList.first(); e; e = mEventList.next() ) { | 464 | for( e = mEventList.first(); e; e = mEventList.next() ) { |
465 | if ( e->doesRecur() ) appendRecurringAlarms( alarms, e, from, to ); | 465 | if ( e->doesRecur() ) appendRecurringAlarms( alarms, e, from, to ); |
466 | else appendAlarms( alarms, e, from, to ); | 466 | else appendAlarms( alarms, e, from, to ); |
467 | } | 467 | } |
468 | 468 | ||
469 | Todo *t; | 469 | Todo *t; |
470 | for( t = mTodoList.first(); t; t = mTodoList.next() ) { | 470 | for( t = mTodoList.first(); t; t = mTodoList.next() ) { |
471 | appendAlarms( alarms, t, from, to ); | 471 | appendAlarms( alarms, t, from, to ); |
472 | } | 472 | } |