author | hakan <hakan> | 2002-03-29 16:32:49 (UTC) |
---|---|---|
committer | hakan <hakan> | 2002-03-29 16:32:49 (UTC) |
commit | d31e0363e905aae78034626896b0d6620ffbc8fc (patch) (unidiff) | |
tree | e6a98e06b0a76008c1ca8b12a095ce2ab2cabd34 | |
parent | 6e194663130b9548c4a31afd2798d9ca1dd30be5 (diff) | |
download | opie-d31e0363e905aae78034626896b0d6620ffbc8fc.zip opie-d31e0363e905aae78034626896b0d6620ffbc8fc.tar.gz opie-d31e0363e905aae78034626896b0d6620ffbc8fc.tar.bz2 |
Added getEvent(uid) and a fix reassigning uids to events whos uids have been cleared
-rw-r--r-- | library/datebookdb.cpp | 25 | ||||
-rw-r--r-- | library/datebookdb.h | 3 |
2 files changed, 27 insertions, 1 deletions
diff --git a/library/datebookdb.cpp b/library/datebookdb.cpp index bf7fd94..da5a797 100644 --- a/library/datebookdb.cpp +++ b/library/datebookdb.cpp | |||
@@ -336,431 +336,454 @@ bool nextOccurance(const Event &e, const QDate &from, QDateTime &next) | |||
336 | } | 336 | } |
337 | } | 337 | } |
338 | 338 | ||
339 | static bool nextAlarm( const Event &ev, QDateTime& when, int& warn) | 339 | static bool nextAlarm( const Event &ev, QDateTime& when, int& warn) |
340 | { | 340 | { |
341 | QDateTime now = QDateTime::currentDateTime(); | 341 | QDateTime now = QDateTime::currentDateTime(); |
342 | if ( ev.hasRepeat() ) { | 342 | if ( ev.hasRepeat() ) { |
343 | QDateTime ralarm; | 343 | QDateTime ralarm; |
344 | if (nextOccurance(ev, now.date(), ralarm)) { | 344 | if (nextOccurance(ev, now.date(), ralarm)) { |
345 | ralarm = ralarm.addSecs(-ev.alarmTime()*60); | 345 | ralarm = ralarm.addSecs(-ev.alarmTime()*60); |
346 | if ( ralarm > now ) { | 346 | if ( ralarm > now ) { |
347 | when = ralarm; | 347 | when = ralarm; |
348 | warn = ev.alarmTime(); | 348 | warn = ev.alarmTime(); |
349 | } else if ( nextOccurance(ev, now.date().addDays(1), ralarm) ) { | 349 | } else if ( nextOccurance(ev, now.date().addDays(1), ralarm) ) { |
350 | ralarm = ralarm.addSecs( -ev.alarmTime()*60 ); | 350 | ralarm = ralarm.addSecs( -ev.alarmTime()*60 ); |
351 | if ( ralarm > now ) { | 351 | if ( ralarm > now ) { |
352 | when = ralarm; | 352 | when = ralarm; |
353 | warn = ev.alarmTime(); | 353 | warn = ev.alarmTime(); |
354 | } | 354 | } |
355 | } | 355 | } |
356 | } | 356 | } |
357 | } else { | 357 | } else { |
358 | warn = ev.alarmTime(); | 358 | warn = ev.alarmTime(); |
359 | when = ev.start().addSecs( -ev.alarmTime()*60 ); | 359 | when = ev.start().addSecs( -ev.alarmTime()*60 ); |
360 | } | 360 | } |
361 | return when > now; | 361 | return when > now; |
362 | } | 362 | } |
363 | 363 | ||
364 | static void addEventAlarm( const Event &ev ) | 364 | static void addEventAlarm( const Event &ev ) |
365 | { | 365 | { |
366 | QDateTime when; | 366 | QDateTime when; |
367 | int warn; | 367 | int warn; |
368 | if ( nextAlarm(ev,when,warn) ) | 368 | if ( nextAlarm(ev,when,warn) ) |
369 | AlarmServer::addAlarm( when, | 369 | AlarmServer::addAlarm( when, |
370 | "QPE/Application/datebook", | 370 | "QPE/Application/datebook", |
371 | "alarm(QDateTime,int)", warn ); | 371 | "alarm(QDateTime,int)", warn ); |
372 | } | 372 | } |
373 | 373 | ||
374 | static void delEventAlarm( const Event &ev ) | 374 | static void delEventAlarm( const Event &ev ) |
375 | { | 375 | { |
376 | QDateTime when; | 376 | QDateTime when; |
377 | int warn; | 377 | int warn; |
378 | if ( nextAlarm(ev,when,warn) ) | 378 | if ( nextAlarm(ev,when,warn) ) |
379 | AlarmServer::deleteAlarm( when, | 379 | AlarmServer::deleteAlarm( when, |
380 | "QPE/Application/datebook", | 380 | "QPE/Application/datebook", |
381 | "alarm(QDateTime,int)", warn ); | 381 | "alarm(QDateTime,int)", warn ); |
382 | } | 382 | } |
383 | 383 | ||
384 | 384 | ||
385 | DateBookDB::DateBookDB() | 385 | DateBookDB::DateBookDB() |
386 | { | 386 | { |
387 | init(); | 387 | init(); |
388 | } | 388 | } |
389 | 389 | ||
390 | DateBookDB::~DateBookDB() | 390 | DateBookDB::~DateBookDB() |
391 | { | 391 | { |
392 | save(); | 392 | save(); |
393 | eventList.clear(); | 393 | eventList.clear(); |
394 | repeatEvents.clear(); | 394 | repeatEvents.clear(); |
395 | } | 395 | } |
396 | 396 | ||
397 | 397 | ||
398 | //#### Why is this code duplicated in getEffectiveEvents ????? | 398 | //#### Why is this code duplicated in getEffectiveEvents ????? |
399 | //#### Addendum. Don't use this function, lets faze it out if we can. | 399 | //#### Addendum. Don't use this function, lets faze it out if we can. |
400 | QValueList<Event> DateBookDB::getEvents( const QDate &from, const QDate &to ) | 400 | QValueList<Event> DateBookDB::getEvents( const QDate &from, const QDate &to ) |
401 | { | 401 | { |
402 | QValueList<Event> tmpList; | 402 | QValueList<Event> tmpList; |
403 | tmpList = getNonRepeatingEvents( from, to ); | 403 | tmpList = getNonRepeatingEvents( from, to ); |
404 | 404 | ||
405 | // check for repeating events... | 405 | // check for repeating events... |
406 | for (QValueList<Event>::ConstIterator it = repeatEvents.begin(); | 406 | for (QValueList<Event>::ConstIterator it = repeatEvents.begin(); |
407 | it != repeatEvents.end(); ++it) { | 407 | it != repeatEvents.end(); ++it) { |
408 | QDate itDate = from; | 408 | QDate itDate = from; |
409 | QDateTime due; | 409 | QDateTime due; |
410 | 410 | ||
411 | /* create a false end date, to short circuit on hard | 411 | /* create a false end date, to short circuit on hard |
412 | MonthlyDay recurences */ | 412 | MonthlyDay recurences */ |
413 | Event dummy_event = *it; | 413 | Event dummy_event = *it; |
414 | Event::RepeatPattern r = dummy_event.repeatPattern(); | 414 | Event::RepeatPattern r = dummy_event.repeatPattern(); |
415 | if ( !r.hasEndDate || r.endDate() > to ) { | 415 | if ( !r.hasEndDate || r.endDate() > to ) { |
416 | r.setEndDate( to ); | 416 | r.setEndDate( to ); |
417 | r.hasEndDate = TRUE; | 417 | r.hasEndDate = TRUE; |
418 | } | 418 | } |
419 | dummy_event.setRepeat(TRUE, r); | 419 | dummy_event.setRepeat(TRUE, r); |
420 | 420 | ||
421 | while (nextOccurance(dummy_event, itDate, due)) { | 421 | while (nextOccurance(dummy_event, itDate, due)) { |
422 | if (due.date() > to) | 422 | if (due.date() > to) |
423 | break; | 423 | break; |
424 | Event newEvent = *it; | 424 | Event newEvent = *it; |
425 | newEvent.setStart(due); | 425 | newEvent.setStart(due); |
426 | newEvent.setEnd(due.addSecs((*it).start().secsTo((*it).end()))); | 426 | newEvent.setEnd(due.addSecs((*it).start().secsTo((*it).end()))); |
427 | 427 | ||
428 | tmpList.append(newEvent); | 428 | tmpList.append(newEvent); |
429 | itDate = due.date().addDays(1); /* the next event */ | 429 | itDate = due.date().addDays(1); /* the next event */ |
430 | } | 430 | } |
431 | } | 431 | } |
432 | qHeapSort(tmpList); | 432 | qHeapSort(tmpList); |
433 | return tmpList; | 433 | return tmpList; |
434 | } | 434 | } |
435 | 435 | ||
436 | QValueList<Event> DateBookDB::getEvents( const QDateTime &start ) | 436 | QValueList<Event> DateBookDB::getEvents( const QDateTime &start ) |
437 | { | 437 | { |
438 | QValueList<Event> day = getEvents(start.date(),start.date()); | 438 | QValueList<Event> day = getEvents(start.date(),start.date()); |
439 | 439 | ||
440 | QValueListConstIterator<Event> it; | 440 | QValueListConstIterator<Event> it; |
441 | QDateTime dtTmp; | 441 | QDateTime dtTmp; |
442 | QValueList<Event> tmpList; | 442 | QValueList<Event> tmpList; |
443 | for (it = day.begin(); it != day.end(); ++it ) { | 443 | for (it = day.begin(); it != day.end(); ++it ) { |
444 | dtTmp = (*it).start(TRUE); | 444 | dtTmp = (*it).start(TRUE); |
445 | if ( dtTmp == start ) | 445 | if ( dtTmp == start ) |
446 | tmpList.append( *it ); | 446 | tmpList.append( *it ); |
447 | } | 447 | } |
448 | return tmpList; | 448 | return tmpList; |
449 | } | 449 | } |
450 | 450 | ||
451 | //#### Why is this code duplicated in getEvents ????? | 451 | //#### Why is this code duplicated in getEvents ????? |
452 | 452 | ||
453 | QValueList<EffectiveEvent> DateBookDB::getEffectiveEvents( const QDate &from, | 453 | QValueList<EffectiveEvent> DateBookDB::getEffectiveEvents( const QDate &from, |
454 | const QDate &to ) | 454 | const QDate &to ) |
455 | { | 455 | { |
456 | QValueList<EffectiveEvent> tmpList; | 456 | QValueList<EffectiveEvent> tmpList; |
457 | QValueListIterator<Event> it; | 457 | QValueListIterator<Event> it; |
458 | 458 | ||
459 | EffectiveEvent effEv; | 459 | EffectiveEvent effEv; |
460 | QDateTime dtTmp, | 460 | QDateTime dtTmp, |
461 | dtEnd; | 461 | dtEnd; |
462 | 462 | ||
463 | for (it = eventList.begin(); it != eventList.end(); ++it ) { | 463 | for (it = eventList.begin(); it != eventList.end(); ++it ) { |
464 | if (!(*it).isValidUid()) | ||
465 | (*it).assignUid(); // FIXME: Hack to restore cleared uids | ||
466 | |||
464 | dtTmp = (*it).start(TRUE); | 467 | dtTmp = (*it).start(TRUE); |
465 | dtEnd = (*it).end(TRUE); | 468 | dtEnd = (*it).end(TRUE); |
466 | 469 | ||
467 | if ( dtTmp.date() >= from && dtTmp.date() <= to ) { | 470 | if ( dtTmp.date() >= from && dtTmp.date() <= to ) { |
468 | Event tmpEv = *it; | 471 | Event tmpEv = *it; |
469 | effEv.setEvent(tmpEv); | 472 | effEv.setEvent(tmpEv); |
470 | effEv.setDate( dtTmp.date() ); | 473 | effEv.setDate( dtTmp.date() ); |
471 | effEv.setStart( dtTmp.time() ); | 474 | effEv.setStart( dtTmp.time() ); |
472 | if ( dtTmp.date() != dtEnd.date() ) | 475 | if ( dtTmp.date() != dtEnd.date() ) |
473 | effEv.setEnd( QTime(23, 59, 0) ); | 476 | effEv.setEnd( QTime(23, 59, 0) ); |
474 | else | 477 | else |
475 | effEv.setEnd( dtEnd.time() ); | 478 | effEv.setEnd( dtEnd.time() ); |
476 | tmpList.append( effEv ); | 479 | tmpList.append( effEv ); |
477 | } | 480 | } |
478 | // we must also check for end date information... | 481 | // we must also check for end date information... |
479 | if ( dtEnd.date() != dtTmp.date() && dtEnd.date() >= from ) { | 482 | if ( dtEnd.date() != dtTmp.date() && dtEnd.date() >= from ) { |
480 | QDateTime dt = dtTmp.addDays( 1 ); | 483 | QDateTime dt = dtTmp.addDays( 1 ); |
481 | dt.setTime( QTime(0, 0, 0) ); | 484 | dt.setTime( QTime(0, 0, 0) ); |
482 | QDateTime dtStop; | 485 | QDateTime dtStop; |
483 | if ( dtEnd > to ) { | 486 | if ( dtEnd > to ) { |
484 | dtStop = to; | 487 | dtStop = to; |
485 | } else | 488 | } else |
486 | dtStop = dtEnd; | 489 | dtStop = dtEnd; |
487 | while ( dt <= dtStop ) { | 490 | while ( dt <= dtStop ) { |
488 | Event tmpEv = *it; | 491 | Event tmpEv = *it; |
489 | effEv.setEvent( tmpEv ); | 492 | effEv.setEvent( tmpEv ); |
490 | effEv.setDate( dt.date() ); | 493 | effEv.setDate( dt.date() ); |
491 | if ( dt >= from ) { | 494 | if ( dt >= from ) { |
492 | effEv.setStart( QTime(0, 0, 0) ); | 495 | effEv.setStart( QTime(0, 0, 0) ); |
493 | if ( dt.date() == dtEnd.date() ) | 496 | if ( dt.date() == dtEnd.date() ) |
494 | effEv.setEnd( dtEnd.time() ); | 497 | effEv.setEnd( dtEnd.time() ); |
495 | else | 498 | else |
496 | effEv.setEnd( QTime(23, 59, 59) ); | 499 | effEv.setEnd( QTime(23, 59, 59) ); |
497 | tmpList.append( effEv ); | 500 | tmpList.append( effEv ); |
498 | } | 501 | } |
499 | dt = dt.addDays( 1 ); | 502 | dt = dt.addDays( 1 ); |
500 | } | 503 | } |
501 | } | 504 | } |
502 | } | 505 | } |
503 | // check for repeating events... | 506 | // check for repeating events... |
504 | QDateTime repeat; | 507 | QDateTime repeat; |
505 | for ( it = repeatEvents.begin(); it != repeatEvents.end(); ++it ) { | 508 | for ( it = repeatEvents.begin(); it != repeatEvents.end(); ++it ) { |
509 | if (!(*it).isValidUid()) | ||
510 | (*it).assignUid(); // FIXME: Hack to restore cleared uids | ||
506 | 511 | ||
507 | /* create a false end date, to short circuit on hard | 512 | /* create a false end date, to short circuit on hard |
508 | MonthlyDay recurences */ | 513 | MonthlyDay recurences */ |
509 | Event dummy_event = *it; | 514 | Event dummy_event = *it; |
510 | int duration = (*it).start().date().daysTo( (*it).end().date() ); | 515 | int duration = (*it).start().date().daysTo( (*it).end().date() ); |
511 | QDate itDate = from.addDays(-duration); | 516 | QDate itDate = from.addDays(-duration); |
512 | 517 | ||
513 | Event::RepeatPattern r = dummy_event.repeatPattern(); | 518 | Event::RepeatPattern r = dummy_event.repeatPattern(); |
514 | if ( !r.hasEndDate || r.endDate() > to ) { | 519 | if ( !r.hasEndDate || r.endDate() > to ) { |
515 | r.setEndDate( to ); | 520 | r.setEndDate( to ); |
516 | r.hasEndDate = TRUE; | 521 | r.hasEndDate = TRUE; |
517 | } | 522 | } |
518 | dummy_event.setRepeat(TRUE, r); | 523 | dummy_event.setRepeat(TRUE, r); |
519 | 524 | ||
520 | while (nextOccurance(dummy_event, itDate, repeat)) { | 525 | while (nextOccurance(dummy_event, itDate, repeat)) { |
521 | if(repeat.date() > to) | 526 | if(repeat.date() > to) |
522 | break; | 527 | break; |
523 | effEv.setDate( repeat.date() ); | 528 | effEv.setDate( repeat.date() ); |
524 | if ((*it).type() == Event::AllDay) { | 529 | if ((*it).type() == Event::AllDay) { |
525 | effEv.setStart( QTime(0,0,0) ); | 530 | effEv.setStart( QTime(0,0,0) ); |
526 | effEv.setEnd( QTime(23,59,59) ); | 531 | effEv.setEnd( QTime(23,59,59) ); |
527 | } else { | 532 | } else { |
528 | /* we only occur by days, not hours/minutes/seconds. Hence | 533 | /* we only occur by days, not hours/minutes/seconds. Hence |
529 | the actual end and start times will be the same for | 534 | the actual end and start times will be the same for |
530 | every repeated event. For multi day events this is | 535 | every repeated event. For multi day events this is |
531 | fixed up later if on wronge day span */ | 536 | fixed up later if on wronge day span */ |
532 | effEv.setStart( (*it).start().time() ); | 537 | effEv.setStart( (*it).start().time() ); |
533 | effEv.setEnd( (*it).end().time() ); | 538 | effEv.setEnd( (*it).end().time() ); |
534 | } | 539 | } |
535 | if ( duration != 0 ) { | 540 | if ( duration != 0 ) { |
536 | // multi-day repeating events | 541 | // multi-day repeating events |
537 | QDate sub_it = QMAX( repeat.date(), from ); | 542 | QDate sub_it = QMAX( repeat.date(), from ); |
538 | QDate startDate = repeat.date(); | 543 | QDate startDate = repeat.date(); |
539 | QDate endDate = startDate.addDays( duration ); | 544 | QDate endDate = startDate.addDays( duration ); |
540 | 545 | ||
541 | while ( sub_it <= endDate && sub_it <= to ) { | 546 | while ( sub_it <= endDate && sub_it <= to ) { |
542 | EffectiveEvent tmpEffEv = effEv; | 547 | EffectiveEvent tmpEffEv = effEv; |
543 | Event tmpEv = *it; | 548 | Event tmpEv = *it; |
544 | tmpEffEv.setEvent( tmpEv ); | 549 | tmpEffEv.setEvent( tmpEv ); |
545 | 550 | ||
546 | if ( sub_it != startDate ) | 551 | if ( sub_it != startDate ) |
547 | tmpEffEv.setStart( QTime(0,0,0) ); | 552 | tmpEffEv.setStart( QTime(0,0,0) ); |
548 | if ( sub_it != endDate ) | 553 | if ( sub_it != endDate ) |
549 | tmpEffEv.setEnd( QTime(23,59,59) ); | 554 | tmpEffEv.setEnd( QTime(23,59,59) ); |
550 | tmpEffEv.setDate( sub_it ); | 555 | tmpEffEv.setDate( sub_it ); |
551 | tmpEffEv.setEffectiveDates( startDate, endDate ); | 556 | tmpEffEv.setEffectiveDates( startDate, endDate ); |
552 | tmpList.append( tmpEffEv ); | 557 | tmpList.append( tmpEffEv ); |
553 | sub_it = sub_it.addDays( 1 ); | 558 | sub_it = sub_it.addDays( 1 ); |
554 | } | 559 | } |
555 | itDate = endDate; | 560 | itDate = endDate; |
556 | } else { | 561 | } else { |
557 | Event tmpEv = *it; | 562 | Event tmpEv = *it; |
558 | effEv.setEvent( tmpEv ); | 563 | effEv.setEvent( tmpEv ); |
559 | tmpList.append( effEv ); | 564 | tmpList.append( effEv ); |
560 | itDate = repeat.date().addDays( 1 ); | 565 | itDate = repeat.date().addDays( 1 ); |
561 | } | 566 | } |
562 | } | 567 | } |
563 | } | 568 | } |
564 | 569 | ||
565 | qHeapSort( tmpList ); | 570 | qHeapSort( tmpList ); |
566 | return tmpList; | 571 | return tmpList; |
567 | } | 572 | } |
568 | 573 | ||
569 | QValueList<EffectiveEvent> DateBookDB::getEffectiveEvents( const QDateTime &dt) | 574 | QValueList<EffectiveEvent> DateBookDB::getEffectiveEvents( const QDateTime &dt) |
570 | { | 575 | { |
571 | QValueList<EffectiveEvent> day = getEffectiveEvents(dt.date(), dt.date()); | 576 | QValueList<EffectiveEvent> day = getEffectiveEvents(dt.date(), dt.date()); |
572 | QValueListConstIterator<EffectiveEvent> it; | 577 | QValueListConstIterator<EffectiveEvent> it; |
573 | QValueList<EffectiveEvent> tmpList; | 578 | QValueList<EffectiveEvent> tmpList; |
574 | QDateTime dtTmp; | 579 | QDateTime dtTmp; |
575 | 580 | ||
576 | for (it = day.begin(); it != day.end(); ++it ) { | 581 | for (it = day.begin(); it != day.end(); ++it ) { |
577 | dtTmp = QDateTime( (*it).date(), (*it).start() ); | 582 | dtTmp = QDateTime( (*it).date(), (*it).start() ); |
578 | // at the moment we don't have second granularity, be nice about that.. | 583 | // at the moment we don't have second granularity, be nice about that.. |
579 | if ( QABS(dt.secsTo(dtTmp)) < 60 ) | 584 | if ( QABS(dt.secsTo(dtTmp)) < 60 ) |
580 | tmpList.append( *it ); | 585 | tmpList.append( *it ); |
581 | } | 586 | } |
582 | return tmpList; | 587 | return tmpList; |
583 | } | 588 | } |
584 | 589 | ||
590 | Event DateBookDB::getEvent( int uid ) { | ||
591 | QValueList<Event>::ConstIterator it; | ||
592 | |||
593 | for (it = eventList.begin(); it != eventList.end(); it++) { | ||
594 | if ((*it).uid() == uid) return *it; | ||
595 | } | ||
596 | for (it = repeatEvents.begin(); it != repeatEvents.end(); it++) { | ||
597 | if ((*it).uid() == uid) return *it; | ||
598 | } | ||
599 | |||
600 | qDebug("Event not found: uid=%d\n", uid); | ||
601 | } | ||
602 | |||
585 | 603 | ||
586 | void DateBookDB::addEvent( const Event &ev, bool doalarm ) | 604 | void DateBookDB::addEvent( const Event &ev, bool doalarm ) |
587 | { | 605 | { |
588 | // write to the journal... | 606 | // write to the journal... |
589 | saveJournalEntry( ev, ACTION_ADD, -1, false ); | 607 | saveJournalEntry( ev, ACTION_ADD, -1, false ); |
590 | addJFEvent( ev, doalarm ); | 608 | addJFEvent( ev, doalarm ); |
591 | d->clean = false; | 609 | d->clean = false; |
592 | } | 610 | } |
593 | 611 | ||
594 | void DateBookDB::addJFEvent( const Event &ev, bool doalarm ) | 612 | void DateBookDB::addJFEvent( const Event &ev, bool doalarm ) |
595 | { | 613 | { |
596 | if ( doalarm && ev.hasAlarm() ) | 614 | if ( doalarm && ev.hasAlarm() ) |
597 | addEventAlarm( ev ); | 615 | addEventAlarm( ev ); |
598 | if ( ev.hasRepeat() ) | 616 | if ( ev.hasRepeat() ) |
599 | repeatEvents.append( ev ); | 617 | repeatEvents.append( ev ); |
600 | else | 618 | else |
601 | eventList.append( ev ); | 619 | eventList.append( ev ); |
602 | } | 620 | } |
603 | 621 | ||
604 | void DateBookDB::editEvent( const Event &old, Event &editedEv ) | 622 | void DateBookDB::editEvent( const Event &old, Event &editedEv ) |
605 | { | 623 | { |
606 | int oldIndex=0; | 624 | int oldIndex=0; |
607 | bool oldHadRepeat = old.hasRepeat(); | 625 | bool oldHadRepeat = old.hasRepeat(); |
608 | Event orig; | 626 | Event orig; |
609 | 627 | ||
610 | // write to the journal... | 628 | // write to the journal... |
611 | if ( oldHadRepeat ) { | 629 | if ( oldHadRepeat ) { |
612 | if ( origRepeat( old, orig ) ) // should work always... | 630 | if ( origRepeat( old, orig ) ) // should work always... |
613 | oldIndex = repeatEvents.findIndex( orig ); | 631 | oldIndex = repeatEvents.findIndex( orig ); |
614 | } else | 632 | } else |
615 | oldIndex = eventList.findIndex( old ); | 633 | oldIndex = eventList.findIndex( old ); |
616 | saveJournalEntry( editedEv, ACTION_REPLACE, oldIndex, oldHadRepeat ); | 634 | saveJournalEntry( editedEv, ACTION_REPLACE, oldIndex, oldHadRepeat ); |
617 | 635 | ||
636 | // Delete old event | ||
618 | if ( old.hasAlarm() ) | 637 | if ( old.hasAlarm() ) |
619 | delEventAlarm( old ); | 638 | delEventAlarm( old ); |
620 | if ( oldHadRepeat ) { | 639 | if ( oldHadRepeat ) { |
621 | if ( oldHadRepeat && editedEv.hasRepeat() ) { | 640 | if ( editedEv.hasRepeat() ) { // This mean that origRepeat was run above and |
641 | // orig is initialized | ||
622 | // assumption, when someone edits a repeating event, they | 642 | // assumption, when someone edits a repeating event, they |
623 | // want to change them all, maybe not perfect, but it works | 643 | // want to change them all, maybe not perfect, but it works |
624 | // for the moment... | 644 | // for the moment... |
625 | repeatEvents.remove( orig ); | 645 | repeatEvents.remove( orig ); |
626 | } else | 646 | } else |
627 | removeRepeat( old ); | 647 | removeRepeat( old ); |
628 | } else { | 648 | } else { |
629 | QValueList<Event>::Iterator it = eventList.find( old ); | 649 | QValueList<Event>::Iterator it = eventList.find( old ); |
630 | if ( it != eventList.end() ) | 650 | if ( it != eventList.end() ) |
631 | eventList.remove( it ); | 651 | eventList.remove( it ); |
632 | } | 652 | } |
653 | |||
654 | // Add new event | ||
633 | if ( editedEv.hasAlarm() ) | 655 | if ( editedEv.hasAlarm() ) |
634 | addEventAlarm( editedEv ); | 656 | addEventAlarm( editedEv ); |
635 | if ( editedEv.hasRepeat() ) | 657 | if ( editedEv.hasRepeat() ) |
636 | repeatEvents.append( editedEv ); | 658 | repeatEvents.append( editedEv ); |
637 | else | 659 | else |
638 | eventList.append( editedEv ); | 660 | eventList.append( editedEv ); |
661 | |||
639 | d->clean = false; | 662 | d->clean = false; |
640 | } | 663 | } |
641 | 664 | ||
642 | void DateBookDB::removeEvent( const Event &ev ) | 665 | void DateBookDB::removeEvent( const Event &ev ) |
643 | { | 666 | { |
644 | // write to the journal... | 667 | // write to the journal... |
645 | saveJournalEntry( ev, ACTION_REMOVE, -1, false ); | 668 | saveJournalEntry( ev, ACTION_REMOVE, -1, false ); |
646 | removeJFEvent( ev ); | 669 | removeJFEvent( ev ); |
647 | d->clean = false; | 670 | d->clean = false; |
648 | } | 671 | } |
649 | 672 | ||
650 | void DateBookDB::removeJFEvent( const Event&ev ) | 673 | void DateBookDB::removeJFEvent( const Event&ev ) |
651 | { | 674 | { |
652 | if ( ev.hasAlarm() ) | 675 | if ( ev.hasAlarm() ) |
653 | delEventAlarm( ev ); | 676 | delEventAlarm( ev ); |
654 | if ( ev.hasRepeat() ) { | 677 | if ( ev.hasRepeat() ) { |
655 | removeRepeat( ev ); | 678 | removeRepeat( ev ); |
656 | } else { | 679 | } else { |
657 | QValueList<Event>::Iterator it = eventList.find( ev ); | 680 | QValueList<Event>::Iterator it = eventList.find( ev ); |
658 | if ( it != eventList.end() ) | 681 | if ( it != eventList.end() ) |
659 | eventList.remove( it ); | 682 | eventList.remove( it ); |
660 | } | 683 | } |
661 | } | 684 | } |
662 | 685 | ||
663 | // also handles journaling... | 686 | // also handles journaling... |
664 | void DateBookDB::loadFile( const QString &strFile ) | 687 | void DateBookDB::loadFile( const QString &strFile ) |
665 | { | 688 | { |
666 | 689 | ||
667 | QFile f( strFile ); | 690 | QFile f( strFile ); |
668 | if ( !f.open( IO_ReadOnly ) ) | 691 | if ( !f.open( IO_ReadOnly ) ) |
669 | return; | 692 | return; |
670 | 693 | ||
671 | enum Attribute { | 694 | enum Attribute { |
672 | FDescription = 0, | 695 | FDescription = 0, |
673 | FLocation, | 696 | FLocation, |
674 | FCategories, | 697 | FCategories, |
675 | FUid, | 698 | FUid, |
676 | FType, | 699 | FType, |
677 | FAlarm, | 700 | FAlarm, |
678 | FSound, | 701 | FSound, |
679 | FRType, | 702 | FRType, |
680 | FRWeekdays, | 703 | FRWeekdays, |
681 | FRPosition, | 704 | FRPosition, |
682 | FRFreq, | 705 | FRFreq, |
683 | FRHasEndDate, | 706 | FRHasEndDate, |
684 | FREndDate, | 707 | FREndDate, |
685 | FRStart, | 708 | FRStart, |
686 | FREnd, | 709 | FREnd, |
687 | FNote, | 710 | FNote, |
688 | FCreated, | 711 | FCreated, |
689 | FAction, | 712 | FAction, |
690 | FActionKey, | 713 | FActionKey, |
691 | FJournalOrigHadRepeat | 714 | FJournalOrigHadRepeat |
692 | }; | 715 | }; |
693 | 716 | ||
694 | QAsciiDict<int> dict( 97 ); | 717 | QAsciiDict<int> dict( 97 ); |
695 | dict.setAutoDelete( TRUE ); | 718 | dict.setAutoDelete( TRUE ); |
696 | dict.insert( "description", new int(FDescription) ); | 719 | dict.insert( "description", new int(FDescription) ); |
697 | dict.insert( "location", new int(FLocation) ); | 720 | dict.insert( "location", new int(FLocation) ); |
698 | dict.insert( "categories", new int(FCategories) ); | 721 | dict.insert( "categories", new int(FCategories) ); |
699 | dict.insert( "uid", new int(FUid) ); | 722 | dict.insert( "uid", new int(FUid) ); |
700 | dict.insert( "type", new int(FType) ); | 723 | dict.insert( "type", new int(FType) ); |
701 | dict.insert( "alarm", new int(FAlarm) ); | 724 | dict.insert( "alarm", new int(FAlarm) ); |
702 | dict.insert( "sound", new int(FSound) ); | 725 | dict.insert( "sound", new int(FSound) ); |
703 | dict.insert( "rtype", new int(FRType) ); | 726 | dict.insert( "rtype", new int(FRType) ); |
704 | dict.insert( "rweekdays", new int(FRWeekdays) ); | 727 | dict.insert( "rweekdays", new int(FRWeekdays) ); |
705 | dict.insert( "rposition", new int(FRPosition) ); | 728 | dict.insert( "rposition", new int(FRPosition) ); |
706 | dict.insert( "rfreq", new int(FRFreq) ); | 729 | dict.insert( "rfreq", new int(FRFreq) ); |
707 | dict.insert( "rhasenddate", new int(FRHasEndDate) ); | 730 | dict.insert( "rhasenddate", new int(FRHasEndDate) ); |
708 | dict.insert( "enddt", new int(FREndDate) ); | 731 | dict.insert( "enddt", new int(FREndDate) ); |
709 | dict.insert( "start", new int(FRStart) ); | 732 | dict.insert( "start", new int(FRStart) ); |
710 | dict.insert( "end", new int(FREnd) ); | 733 | dict.insert( "end", new int(FREnd) ); |
711 | dict.insert( "note", new int(FNote) ); | 734 | dict.insert( "note", new int(FNote) ); |
712 | dict.insert( "created", new int(FCreated) ); | 735 | dict.insert( "created", new int(FCreated) ); |
713 | dict.insert( "action", new int(FAction) ); | 736 | dict.insert( "action", new int(FAction) ); |
714 | dict.insert( "actionkey", new int(FActionKey) ); | 737 | dict.insert( "actionkey", new int(FActionKey) ); |
715 | dict.insert( "actionorig", new int (FJournalOrigHadRepeat) ); | 738 | dict.insert( "actionorig", new int (FJournalOrigHadRepeat) ); |
716 | 739 | ||
717 | 740 | ||
718 | QByteArray ba = f.readAll(); | 741 | QByteArray ba = f.readAll(); |
719 | char* dt = ba.data(); | 742 | char* dt = ba.data(); |
720 | int len = ba.size(); | 743 | int len = ba.size(); |
721 | int currentAction, | 744 | int currentAction, |
722 | journalKey, | 745 | journalKey, |
723 | origHadRepeat; // should be bool, but we need tri-state(not being used) | 746 | origHadRepeat; // should be bool, but we need tri-state(not being used) |
724 | 747 | ||
725 | int i = 0; | 748 | int i = 0; |
726 | char *point; | 749 | char *point; |
727 | while ( ( point = strstr( dt+i, "<event " ) ) != 0 ) { | 750 | while ( ( point = strstr( dt+i, "<event " ) ) != 0 ) { |
728 | i = point - dt; | 751 | i = point - dt; |
729 | // if we are reading in events in the general case, | 752 | // if we are reading in events in the general case, |
730 | // we are just adding them, so let the actions represent that... | 753 | // we are just adding them, so let the actions represent that... |
731 | currentAction = ACTION_ADD; | 754 | currentAction = ACTION_ADD; |
732 | journalKey = -1; | 755 | journalKey = -1; |
733 | origHadRepeat = -1; | 756 | origHadRepeat = -1; |
734 | // some temporary variables for dates and times ... | 757 | // some temporary variables for dates and times ... |
735 | //int startY = 0, startM = 0, startD = 0, starth = 0, startm = 0, starts = 0; | 758 | //int startY = 0, startM = 0, startD = 0, starth = 0, startm = 0, starts = 0; |
736 | //int endY = 0, endM = 0, endD = 0, endh = 0, endm = 0, ends = 0; | 759 | //int endY = 0, endM = 0, endD = 0, endh = 0, endm = 0, ends = 0; |
737 | //int enddtY = 0, enddtM = 0, enddtD = 0; | 760 | //int enddtY = 0, enddtM = 0, enddtD = 0; |
738 | 761 | ||
739 | // ... for the alarm settings ... | 762 | // ... for the alarm settings ... |
740 | int alarmTime = -1; Event::SoundTypeChoice alarmSound = Event::Silent; | 763 | int alarmTime = -1; Event::SoundTypeChoice alarmSound = Event::Silent; |
741 | // ... and for the recurrence | 764 | // ... and for the recurrence |
742 | Event::RepeatPattern rp; | 765 | Event::RepeatPattern rp; |
743 | Event e; | 766 | Event e; |
744 | 767 | ||
745 | i += 7; | 768 | i += 7; |
746 | 769 | ||
747 | while( 1 ) { | 770 | while( 1 ) { |
748 | while ( i < len && (dt[i] == ' ' || dt[i] == '\n' || dt[i] == '\r') ) | 771 | while ( i < len && (dt[i] == ' ' || dt[i] == '\n' || dt[i] == '\r') ) |
749 | ++i; | 772 | ++i; |
750 | if ( i >= len-2 || (dt[i] == '/' && dt[i+1] == '>') ) | 773 | if ( i >= len-2 || (dt[i] == '/' && dt[i+1] == '>') ) |
751 | break; | 774 | break; |
752 | // we have another attribute, read it. | 775 | // we have another attribute, read it. |
753 | int j = i; | 776 | int j = i; |
754 | while ( j < len && dt[j] != '=' ) | 777 | while ( j < len && dt[j] != '=' ) |
755 | ++j; | 778 | ++j; |
756 | char *attr = dt+i; | 779 | char *attr = dt+i; |
757 | dt[j] = '\0'; | 780 | dt[j] = '\0'; |
758 | i = ++j; // skip = | 781 | i = ++j; // skip = |
759 | while ( i < len && dt[i] != '"' ) | 782 | while ( i < len && dt[i] != '"' ) |
760 | ++i; | 783 | ++i; |
761 | j = ++i; | 784 | j = ++i; |
762 | bool haveAmp = FALSE; | 785 | bool haveAmp = FALSE; |
763 | bool haveUtf = FALSE; | 786 | bool haveUtf = FALSE; |
764 | while ( j < len && dt[j] != '"' ) { | 787 | while ( j < len && dt[j] != '"' ) { |
765 | if ( dt[j] == '&' ) | 788 | if ( dt[j] == '&' ) |
766 | haveAmp = TRUE; | 789 | haveAmp = TRUE; |
diff --git a/library/datebookdb.h b/library/datebookdb.h index aadb397..e4c251c 100644 --- a/library/datebookdb.h +++ b/library/datebookdb.h | |||
@@ -1,85 +1,88 @@ | |||
1 | /********************************************************************** | 1 | /********************************************************************** |
2 | ** Copyright (C) 2000 Trolltech AS. All rights reserved. | 2 | ** Copyright (C) 2000 Trolltech AS. All rights reserved. |
3 | ** | 3 | ** |
4 | ** This file is part of Qtopia Environment. | 4 | ** This file is part of Qtopia Environment. |
5 | ** | 5 | ** |
6 | ** This file may be distributed and/or modified under the terms of the | 6 | ** This file may be distributed and/or modified under the terms of the |
7 | ** GNU General Public License version 2 as published by the Free Software | 7 | ** GNU General Public License version 2 as published by the Free Software |
8 | ** Foundation and appearing in the file LICENSE.GPL included in the | 8 | ** Foundation and appearing in the file LICENSE.GPL included in the |
9 | ** packaging of this file. | 9 | ** packaging of this file. |
10 | ** | 10 | ** |
11 | ** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE | 11 | ** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE |
12 | ** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. | 12 | ** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. |
13 | ** | 13 | ** |
14 | ** See http://www.trolltech.com/gpl/ for GPL licensing information. | 14 | ** See http://www.trolltech.com/gpl/ for GPL licensing information. |
15 | ** | 15 | ** |
16 | ** Contact info@trolltech.com if any conditions of this licensing are | 16 | ** Contact info@trolltech.com if any conditions of this licensing are |
17 | ** not clear to you. | 17 | ** not clear to you. |
18 | ** | 18 | ** |
19 | **********************************************************************/ | 19 | **********************************************************************/ |
20 | 20 | ||
21 | #ifndef DATEBOOKDB_H | 21 | #ifndef DATEBOOKDB_H |
22 | #define DATEBOOKDB_H | 22 | #define DATEBOOKDB_H |
23 | 23 | ||
24 | #include <qdatetime.h> | 24 | #include <qdatetime.h> |
25 | #include <qfile.h> | 25 | #include <qfile.h> |
26 | #include <qvaluelist.h> | 26 | #include <qvaluelist.h> |
27 | #include <qpe/event.h> | 27 | #include <qpe/event.h> |
28 | 28 | ||
29 | // journal actions... | 29 | // journal actions... |
30 | enum journal_action { ACTION_ADD, ACTION_REMOVE, ACTION_REPLACE }; | 30 | enum journal_action { ACTION_ADD, ACTION_REMOVE, ACTION_REPLACE }; |
31 | 31 | ||
32 | class DateBookDBPrivate; | 32 | class DateBookDBPrivate; |
33 | class DateBookDB | 33 | class DateBookDB |
34 | { | 34 | { |
35 | public: | 35 | public: |
36 | DateBookDB(); | 36 | DateBookDB(); |
37 | ~DateBookDB(); | 37 | ~DateBookDB(); |
38 | 38 | ||
39 | // very depreciated now!!! | 39 | // very depreciated now!!! |
40 | QValueList<Event> getEvents( const QDate &from, const QDate &to ); | 40 | QValueList<Event> getEvents( const QDate &from, const QDate &to ); |
41 | QValueList<Event> getEvents( const QDateTime &start ); | 41 | QValueList<Event> getEvents( const QDateTime &start ); |
42 | 42 | ||
43 | // USE THESE!!! | 43 | // USE THESE!!! |
44 | QValueList<EffectiveEvent> getEffectiveEvents( const QDate &from, | 44 | QValueList<EffectiveEvent> getEffectiveEvents( const QDate &from, |
45 | const QDate &to ); | 45 | const QDate &to ); |
46 | QValueList<EffectiveEvent> getEffectiveEvents( const QDateTime &start ); | 46 | QValueList<EffectiveEvent> getEffectiveEvents( const QDateTime &start ); |
47 | Event getEvent( int uid ); | ||
47 | 48 | ||
48 | QValueList<Event> getRawRepeats() const; | 49 | QValueList<Event> getRawRepeats() const; |
49 | QValueList<Event> getNonRepeatingEvents( const QDate &from, | 50 | QValueList<Event> getNonRepeatingEvents( const QDate &from, |
50 | const QDate &to ) const; | 51 | const QDate &to ) const; |
51 | 52 | ||
52 | // Use these when dealing with adding removing events... | 53 | // Use these when dealing with adding removing events... |
53 | void addEvent( const Event &ev, bool doalarm=TRUE ); | 54 | void addEvent( const Event &ev, bool doalarm=TRUE ); |
54 | void removeEvent( const Event &ev ); | 55 | void removeEvent( const Event &ev ); |
55 | void editEvent( const Event &old, Event &ev ); | 56 | void editEvent( const Event &old, Event &ev ); |
56 | // add/remove event without journaling ( these ended up in public by accident, never | 57 | // add/remove event without journaling ( these ended up in public by accident, never |
57 | // use them unless you know what you are doing...), | 58 | // use them unless you know what you are doing...), |
58 | // please put them in private if we ever can change the class... | 59 | // please put them in private if we ever can change the class... |
59 | void addJFEvent( const Event &ev, bool doalarm=TRUE ); | 60 | void addJFEvent( const Event &ev, bool doalarm=TRUE ); |
60 | void removeJFEvent( const Event &ev ); | 61 | void removeJFEvent( const Event &ev ); |
61 | 62 | ||
62 | bool save(); | 63 | bool save(); |
63 | void reload(); | 64 | void reload(); |
64 | private: | 65 | private: |
65 | //find the real repeat... | 66 | //find the real repeat... |
66 | bool origRepeat( const Event &ev, Event &orig ) const; | 67 | bool origRepeat( const Event &ev, Event &orig ) const; |
67 | bool removeRepeat( const Event &ev ); | 68 | bool removeRepeat( const Event &ev ); |
68 | void init(); | 69 | void init(); |
69 | void loadFile( const QString &strFile ); | 70 | void loadFile( const QString &strFile ); |
70 | // depreciated... | 71 | // depreciated... |
71 | void saveJournalEntry( const Event &ev, journal_action action ); | 72 | void saveJournalEntry( const Event &ev, journal_action action ); |
72 | // new version, uncomment the "= -1" when we remove the above | 73 | // new version, uncomment the "= -1" when we remove the above |
73 | // function.. | 74 | // function.. |
74 | bool saveJournalEntry( const Event &ev, journal_action action, | 75 | bool saveJournalEntry( const Event &ev, journal_action action, |
75 | int key/* = -1*/, bool origHadRepeat = false ); | 76 | int key/* = -1*/, bool origHadRepeat = false ); |
76 | 77 | ||
77 | QValueList<Event> eventList; // non-repeating events... | 78 | QValueList<Event> eventList; // non-repeating events... |
78 | QValueList<Event> repeatEvents; // the repeating events... | 79 | QValueList<Event> repeatEvents; // the repeating events... |
79 | DateBookDBPrivate *d; | 80 | DateBookDBPrivate *d; |
80 | QFile journalFile; | 81 | QFile journalFile; |
82 | |||
83 | intrecordIdMax; // ADDITION | ||
81 | }; | 84 | }; |
82 | 85 | ||
83 | /* helper functions, also useful to other apps. */ | 86 | /* helper functions, also useful to other apps. */ |
84 | bool nextOccurance( const Event &e, const QDate &from, QDateTime &next); | 87 | bool nextOccurance( const Event &e, const QDate &from, QDateTime &next); |
85 | #endif | 88 | #endif |