-rw-r--r-- | library/datebookdb.cpp | 14 | ||||
-rw-r--r-- | library/datebookdb.h | 1 |
2 files changed, 0 insertions, 15 deletions
diff --git a/library/datebookdb.cpp b/library/datebookdb.cpp index da5a797..2ac9a0c 100644 --- a/library/datebookdb.cpp +++ b/library/datebookdb.cpp | |||
@@ -398,398 +398,384 @@ DateBookDB::~DateBookDB() | |||
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()) | 464 | if (!(*it).isValidUid()) |
465 | (*it).assignUid(); // FIXME: Hack to restore cleared uids | 465 | (*it).assignUid(); // FIXME: Hack to restore cleared uids |
466 | 466 | ||
467 | dtTmp = (*it).start(TRUE); | 467 | dtTmp = (*it).start(TRUE); |
468 | dtEnd = (*it).end(TRUE); | 468 | dtEnd = (*it).end(TRUE); |
469 | 469 | ||
470 | if ( dtTmp.date() >= from && dtTmp.date() <= to ) { | 470 | if ( dtTmp.date() >= from && dtTmp.date() <= to ) { |
471 | Event tmpEv = *it; | 471 | Event tmpEv = *it; |
472 | effEv.setEvent(tmpEv); | 472 | effEv.setEvent(tmpEv); |
473 | effEv.setDate( dtTmp.date() ); | 473 | effEv.setDate( dtTmp.date() ); |
474 | effEv.setStart( dtTmp.time() ); | 474 | effEv.setStart( dtTmp.time() ); |
475 | if ( dtTmp.date() != dtEnd.date() ) | 475 | if ( dtTmp.date() != dtEnd.date() ) |
476 | effEv.setEnd( QTime(23, 59, 0) ); | 476 | effEv.setEnd( QTime(23, 59, 0) ); |
477 | else | 477 | else |
478 | effEv.setEnd( dtEnd.time() ); | 478 | effEv.setEnd( dtEnd.time() ); |
479 | tmpList.append( effEv ); | 479 | tmpList.append( effEv ); |
480 | } | 480 | } |
481 | // we must also check for end date information... | 481 | // we must also check for end date information... |
482 | if ( dtEnd.date() != dtTmp.date() && dtEnd.date() >= from ) { | 482 | if ( dtEnd.date() != dtTmp.date() && dtEnd.date() >= from ) { |
483 | QDateTime dt = dtTmp.addDays( 1 ); | 483 | QDateTime dt = dtTmp.addDays( 1 ); |
484 | dt.setTime( QTime(0, 0, 0) ); | 484 | dt.setTime( QTime(0, 0, 0) ); |
485 | QDateTime dtStop; | 485 | QDateTime dtStop; |
486 | if ( dtEnd > to ) { | 486 | if ( dtEnd > to ) { |
487 | dtStop = to; | 487 | dtStop = to; |
488 | } else | 488 | } else |
489 | dtStop = dtEnd; | 489 | dtStop = dtEnd; |
490 | while ( dt <= dtStop ) { | 490 | while ( dt <= dtStop ) { |
491 | Event tmpEv = *it; | 491 | Event tmpEv = *it; |
492 | effEv.setEvent( tmpEv ); | 492 | effEv.setEvent( tmpEv ); |
493 | effEv.setDate( dt.date() ); | 493 | effEv.setDate( dt.date() ); |
494 | if ( dt >= from ) { | 494 | if ( dt >= from ) { |
495 | effEv.setStart( QTime(0, 0, 0) ); | 495 | effEv.setStart( QTime(0, 0, 0) ); |
496 | if ( dt.date() == dtEnd.date() ) | 496 | if ( dt.date() == dtEnd.date() ) |
497 | effEv.setEnd( dtEnd.time() ); | 497 | effEv.setEnd( dtEnd.time() ); |
498 | else | 498 | else |
499 | effEv.setEnd( QTime(23, 59, 59) ); | 499 | effEv.setEnd( QTime(23, 59, 59) ); |
500 | tmpList.append( effEv ); | 500 | tmpList.append( effEv ); |
501 | } | 501 | } |
502 | dt = dt.addDays( 1 ); | 502 | dt = dt.addDays( 1 ); |
503 | } | 503 | } |
504 | } | 504 | } |
505 | } | 505 | } |
506 | // check for repeating events... | 506 | // check for repeating events... |
507 | QDateTime repeat; | 507 | QDateTime repeat; |
508 | for ( it = repeatEvents.begin(); it != repeatEvents.end(); ++it ) { | 508 | for ( it = repeatEvents.begin(); it != repeatEvents.end(); ++it ) { |
509 | if (!(*it).isValidUid()) | 509 | if (!(*it).isValidUid()) |
510 | (*it).assignUid(); // FIXME: Hack to restore cleared uids | 510 | (*it).assignUid(); // FIXME: Hack to restore cleared uids |
511 | 511 | ||
512 | /* create a false end date, to short circuit on hard | 512 | /* create a false end date, to short circuit on hard |
513 | MonthlyDay recurences */ | 513 | MonthlyDay recurences */ |
514 | Event dummy_event = *it; | 514 | Event dummy_event = *it; |
515 | int duration = (*it).start().date().daysTo( (*it).end().date() ); | 515 | int duration = (*it).start().date().daysTo( (*it).end().date() ); |
516 | QDate itDate = from.addDays(-duration); | 516 | QDate itDate = from.addDays(-duration); |
517 | 517 | ||
518 | Event::RepeatPattern r = dummy_event.repeatPattern(); | 518 | Event::RepeatPattern r = dummy_event.repeatPattern(); |
519 | if ( !r.hasEndDate || r.endDate() > to ) { | 519 | if ( !r.hasEndDate || r.endDate() > to ) { |
520 | r.setEndDate( to ); | 520 | r.setEndDate( to ); |
521 | r.hasEndDate = TRUE; | 521 | r.hasEndDate = TRUE; |
522 | } | 522 | } |
523 | dummy_event.setRepeat(TRUE, r); | 523 | dummy_event.setRepeat(TRUE, r); |
524 | 524 | ||
525 | while (nextOccurance(dummy_event, itDate, repeat)) { | 525 | while (nextOccurance(dummy_event, itDate, repeat)) { |
526 | if(repeat.date() > to) | 526 | if(repeat.date() > to) |
527 | break; | 527 | break; |
528 | effEv.setDate( repeat.date() ); | 528 | effEv.setDate( repeat.date() ); |
529 | if ((*it).type() == Event::AllDay) { | 529 | if ((*it).type() == Event::AllDay) { |
530 | effEv.setStart( QTime(0,0,0) ); | 530 | effEv.setStart( QTime(0,0,0) ); |
531 | effEv.setEnd( QTime(23,59,59) ); | 531 | effEv.setEnd( QTime(23,59,59) ); |
532 | } else { | 532 | } else { |
533 | /* we only occur by days, not hours/minutes/seconds. Hence | 533 | /* we only occur by days, not hours/minutes/seconds. Hence |
534 | the actual end and start times will be the same for | 534 | the actual end and start times will be the same for |
535 | every repeated event. For multi day events this is | 535 | every repeated event. For multi day events this is |
536 | fixed up later if on wronge day span */ | 536 | fixed up later if on wronge day span */ |
537 | effEv.setStart( (*it).start().time() ); | 537 | effEv.setStart( (*it).start().time() ); |
538 | effEv.setEnd( (*it).end().time() ); | 538 | effEv.setEnd( (*it).end().time() ); |
539 | } | 539 | } |
540 | if ( duration != 0 ) { | 540 | if ( duration != 0 ) { |
541 | // multi-day repeating events | 541 | // multi-day repeating events |
542 | QDate sub_it = QMAX( repeat.date(), from ); | 542 | QDate sub_it = QMAX( repeat.date(), from ); |
543 | QDate startDate = repeat.date(); | 543 | QDate startDate = repeat.date(); |
544 | QDate endDate = startDate.addDays( duration ); | 544 | QDate endDate = startDate.addDays( duration ); |
545 | 545 | ||
546 | while ( sub_it <= endDate && sub_it <= to ) { | 546 | while ( sub_it <= endDate && sub_it <= to ) { |
547 | EffectiveEvent tmpEffEv = effEv; | 547 | EffectiveEvent tmpEffEv = effEv; |
548 | Event tmpEv = *it; | 548 | Event tmpEv = *it; |
549 | tmpEffEv.setEvent( tmpEv ); | 549 | tmpEffEv.setEvent( tmpEv ); |
550 | 550 | ||
551 | if ( sub_it != startDate ) | 551 | if ( sub_it != startDate ) |
552 | tmpEffEv.setStart( QTime(0,0,0) ); | 552 | tmpEffEv.setStart( QTime(0,0,0) ); |
553 | if ( sub_it != endDate ) | 553 | if ( sub_it != endDate ) |
554 | tmpEffEv.setEnd( QTime(23,59,59) ); | 554 | tmpEffEv.setEnd( QTime(23,59,59) ); |
555 | tmpEffEv.setDate( sub_it ); | 555 | tmpEffEv.setDate( sub_it ); |
556 | tmpEffEv.setEffectiveDates( startDate, endDate ); | 556 | tmpEffEv.setEffectiveDates( startDate, endDate ); |
557 | tmpList.append( tmpEffEv ); | 557 | tmpList.append( tmpEffEv ); |
558 | sub_it = sub_it.addDays( 1 ); | 558 | sub_it = sub_it.addDays( 1 ); |
559 | } | 559 | } |
560 | itDate = endDate; | 560 | itDate = endDate; |
561 | } else { | 561 | } else { |
562 | Event tmpEv = *it; | 562 | Event tmpEv = *it; |
563 | effEv.setEvent( tmpEv ); | 563 | effEv.setEvent( tmpEv ); |
564 | tmpList.append( effEv ); | 564 | tmpList.append( effEv ); |
565 | itDate = repeat.date().addDays( 1 ); | 565 | itDate = repeat.date().addDays( 1 ); |
566 | } | 566 | } |
567 | } | 567 | } |
568 | } | 568 | } |
569 | 569 | ||
570 | qHeapSort( tmpList ); | 570 | qHeapSort( tmpList ); |
571 | return tmpList; | 571 | return tmpList; |
572 | } | 572 | } |
573 | 573 | ||
574 | QValueList<EffectiveEvent> DateBookDB::getEffectiveEvents( const QDateTime &dt) | 574 | QValueList<EffectiveEvent> DateBookDB::getEffectiveEvents( const QDateTime &dt) |
575 | { | 575 | { |
576 | QValueList<EffectiveEvent> day = getEffectiveEvents(dt.date(), dt.date()); | 576 | QValueList<EffectiveEvent> day = getEffectiveEvents(dt.date(), dt.date()); |
577 | QValueListConstIterator<EffectiveEvent> it; | 577 | QValueListConstIterator<EffectiveEvent> it; |
578 | QValueList<EffectiveEvent> tmpList; | 578 | QValueList<EffectiveEvent> tmpList; |
579 | QDateTime dtTmp; | 579 | QDateTime dtTmp; |
580 | 580 | ||
581 | for (it = day.begin(); it != day.end(); ++it ) { | 581 | for (it = day.begin(); it != day.end(); ++it ) { |
582 | dtTmp = QDateTime( (*it).date(), (*it).start() ); | 582 | dtTmp = QDateTime( (*it).date(), (*it).start() ); |
583 | // 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.. |
584 | if ( QABS(dt.secsTo(dtTmp)) < 60 ) | 584 | if ( QABS(dt.secsTo(dtTmp)) < 60 ) |
585 | tmpList.append( *it ); | 585 | tmpList.append( *it ); |
586 | } | 586 | } |
587 | return tmpList; | 587 | return tmpList; |
588 | } | 588 | } |
589 | 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 | |||
603 | |||
604 | void DateBookDB::addEvent( const Event &ev, bool doalarm ) | 590 | void DateBookDB::addEvent( const Event &ev, bool doalarm ) |
605 | { | 591 | { |
606 | // write to the journal... | 592 | // write to the journal... |
607 | saveJournalEntry( ev, ACTION_ADD, -1, false ); | 593 | saveJournalEntry( ev, ACTION_ADD, -1, false ); |
608 | addJFEvent( ev, doalarm ); | 594 | addJFEvent( ev, doalarm ); |
609 | d->clean = false; | 595 | d->clean = false; |
610 | } | 596 | } |
611 | 597 | ||
612 | void DateBookDB::addJFEvent( const Event &ev, bool doalarm ) | 598 | void DateBookDB::addJFEvent( const Event &ev, bool doalarm ) |
613 | { | 599 | { |
614 | if ( doalarm && ev.hasAlarm() ) | 600 | if ( doalarm && ev.hasAlarm() ) |
615 | addEventAlarm( ev ); | 601 | addEventAlarm( ev ); |
616 | if ( ev.hasRepeat() ) | 602 | if ( ev.hasRepeat() ) |
617 | repeatEvents.append( ev ); | 603 | repeatEvents.append( ev ); |
618 | else | 604 | else |
619 | eventList.append( ev ); | 605 | eventList.append( ev ); |
620 | } | 606 | } |
621 | 607 | ||
622 | void DateBookDB::editEvent( const Event &old, Event &editedEv ) | 608 | void DateBookDB::editEvent( const Event &old, Event &editedEv ) |
623 | { | 609 | { |
624 | int oldIndex=0; | 610 | int oldIndex=0; |
625 | bool oldHadRepeat = old.hasRepeat(); | 611 | bool oldHadRepeat = old.hasRepeat(); |
626 | Event orig; | 612 | Event orig; |
627 | 613 | ||
628 | // write to the journal... | 614 | // write to the journal... |
629 | if ( oldHadRepeat ) { | 615 | if ( oldHadRepeat ) { |
630 | if ( origRepeat( old, orig ) ) // should work always... | 616 | if ( origRepeat( old, orig ) ) // should work always... |
631 | oldIndex = repeatEvents.findIndex( orig ); | 617 | oldIndex = repeatEvents.findIndex( orig ); |
632 | } else | 618 | } else |
633 | oldIndex = eventList.findIndex( old ); | 619 | oldIndex = eventList.findIndex( old ); |
634 | saveJournalEntry( editedEv, ACTION_REPLACE, oldIndex, oldHadRepeat ); | 620 | saveJournalEntry( editedEv, ACTION_REPLACE, oldIndex, oldHadRepeat ); |
635 | 621 | ||
636 | // Delete old event | 622 | // Delete old event |
637 | if ( old.hasAlarm() ) | 623 | if ( old.hasAlarm() ) |
638 | delEventAlarm( old ); | 624 | delEventAlarm( old ); |
639 | if ( oldHadRepeat ) { | 625 | if ( oldHadRepeat ) { |
640 | if ( editedEv.hasRepeat() ) { // This mean that origRepeat was run above and | 626 | if ( editedEv.hasRepeat() ) { // This mean that origRepeat was run above and |
641 | // orig is initialized | 627 | // orig is initialized |
642 | // assumption, when someone edits a repeating event, they | 628 | // assumption, when someone edits a repeating event, they |
643 | // want to change them all, maybe not perfect, but it works | 629 | // want to change them all, maybe not perfect, but it works |
644 | // for the moment... | 630 | // for the moment... |
645 | repeatEvents.remove( orig ); | 631 | repeatEvents.remove( orig ); |
646 | } else | 632 | } else |
647 | removeRepeat( old ); | 633 | removeRepeat( old ); |
648 | } else { | 634 | } else { |
649 | QValueList<Event>::Iterator it = eventList.find( old ); | 635 | QValueList<Event>::Iterator it = eventList.find( old ); |
650 | if ( it != eventList.end() ) | 636 | if ( it != eventList.end() ) |
651 | eventList.remove( it ); | 637 | eventList.remove( it ); |
652 | } | 638 | } |
653 | 639 | ||
654 | // Add new event | 640 | // Add new event |
655 | if ( editedEv.hasAlarm() ) | 641 | if ( editedEv.hasAlarm() ) |
656 | addEventAlarm( editedEv ); | 642 | addEventAlarm( editedEv ); |
657 | if ( editedEv.hasRepeat() ) | 643 | if ( editedEv.hasRepeat() ) |
658 | repeatEvents.append( editedEv ); | 644 | repeatEvents.append( editedEv ); |
659 | else | 645 | else |
660 | eventList.append( editedEv ); | 646 | eventList.append( editedEv ); |
661 | 647 | ||
662 | d->clean = false; | 648 | d->clean = false; |
663 | } | 649 | } |
664 | 650 | ||
665 | void DateBookDB::removeEvent( const Event &ev ) | 651 | void DateBookDB::removeEvent( const Event &ev ) |
666 | { | 652 | { |
667 | // write to the journal... | 653 | // write to the journal... |
668 | saveJournalEntry( ev, ACTION_REMOVE, -1, false ); | 654 | saveJournalEntry( ev, ACTION_REMOVE, -1, false ); |
669 | removeJFEvent( ev ); | 655 | removeJFEvent( ev ); |
670 | d->clean = false; | 656 | d->clean = false; |
671 | } | 657 | } |
672 | 658 | ||
673 | void DateBookDB::removeJFEvent( const Event&ev ) | 659 | void DateBookDB::removeJFEvent( const Event&ev ) |
674 | { | 660 | { |
675 | if ( ev.hasAlarm() ) | 661 | if ( ev.hasAlarm() ) |
676 | delEventAlarm( ev ); | 662 | delEventAlarm( ev ); |
677 | if ( ev.hasRepeat() ) { | 663 | if ( ev.hasRepeat() ) { |
678 | removeRepeat( ev ); | 664 | removeRepeat( ev ); |
679 | } else { | 665 | } else { |
680 | QValueList<Event>::Iterator it = eventList.find( ev ); | 666 | QValueList<Event>::Iterator it = eventList.find( ev ); |
681 | if ( it != eventList.end() ) | 667 | if ( it != eventList.end() ) |
682 | eventList.remove( it ); | 668 | eventList.remove( it ); |
683 | } | 669 | } |
684 | } | 670 | } |
685 | 671 | ||
686 | // also handles journaling... | 672 | // also handles journaling... |
687 | void DateBookDB::loadFile( const QString &strFile ) | 673 | void DateBookDB::loadFile( const QString &strFile ) |
688 | { | 674 | { |
689 | 675 | ||
690 | QFile f( strFile ); | 676 | QFile f( strFile ); |
691 | if ( !f.open( IO_ReadOnly ) ) | 677 | if ( !f.open( IO_ReadOnly ) ) |
692 | return; | 678 | return; |
693 | 679 | ||
694 | enum Attribute { | 680 | enum Attribute { |
695 | FDescription = 0, | 681 | FDescription = 0, |
696 | FLocation, | 682 | FLocation, |
697 | FCategories, | 683 | FCategories, |
698 | FUid, | 684 | FUid, |
699 | FType, | 685 | FType, |
700 | FAlarm, | 686 | FAlarm, |
701 | FSound, | 687 | FSound, |
702 | FRType, | 688 | FRType, |
703 | FRWeekdays, | 689 | FRWeekdays, |
704 | FRPosition, | 690 | FRPosition, |
705 | FRFreq, | 691 | FRFreq, |
706 | FRHasEndDate, | 692 | FRHasEndDate, |
707 | FREndDate, | 693 | FREndDate, |
708 | FRStart, | 694 | FRStart, |
709 | FREnd, | 695 | FREnd, |
710 | FNote, | 696 | FNote, |
711 | FCreated, | 697 | FCreated, |
712 | FAction, | 698 | FAction, |
713 | FActionKey, | 699 | FActionKey, |
714 | FJournalOrigHadRepeat | 700 | FJournalOrigHadRepeat |
715 | }; | 701 | }; |
716 | 702 | ||
717 | QAsciiDict<int> dict( 97 ); | 703 | QAsciiDict<int> dict( 97 ); |
718 | dict.setAutoDelete( TRUE ); | 704 | dict.setAutoDelete( TRUE ); |
719 | dict.insert( "description", new int(FDescription) ); | 705 | dict.insert( "description", new int(FDescription) ); |
720 | dict.insert( "location", new int(FLocation) ); | 706 | dict.insert( "location", new int(FLocation) ); |
721 | dict.insert( "categories", new int(FCategories) ); | 707 | dict.insert( "categories", new int(FCategories) ); |
722 | dict.insert( "uid", new int(FUid) ); | 708 | dict.insert( "uid", new int(FUid) ); |
723 | dict.insert( "type", new int(FType) ); | 709 | dict.insert( "type", new int(FType) ); |
724 | dict.insert( "alarm", new int(FAlarm) ); | 710 | dict.insert( "alarm", new int(FAlarm) ); |
725 | dict.insert( "sound", new int(FSound) ); | 711 | dict.insert( "sound", new int(FSound) ); |
726 | dict.insert( "rtype", new int(FRType) ); | 712 | dict.insert( "rtype", new int(FRType) ); |
727 | dict.insert( "rweekdays", new int(FRWeekdays) ); | 713 | dict.insert( "rweekdays", new int(FRWeekdays) ); |
728 | dict.insert( "rposition", new int(FRPosition) ); | 714 | dict.insert( "rposition", new int(FRPosition) ); |
729 | dict.insert( "rfreq", new int(FRFreq) ); | 715 | dict.insert( "rfreq", new int(FRFreq) ); |
730 | dict.insert( "rhasenddate", new int(FRHasEndDate) ); | 716 | dict.insert( "rhasenddate", new int(FRHasEndDate) ); |
731 | dict.insert( "enddt", new int(FREndDate) ); | 717 | dict.insert( "enddt", new int(FREndDate) ); |
732 | dict.insert( "start", new int(FRStart) ); | 718 | dict.insert( "start", new int(FRStart) ); |
733 | dict.insert( "end", new int(FREnd) ); | 719 | dict.insert( "end", new int(FREnd) ); |
734 | dict.insert( "note", new int(FNote) ); | 720 | dict.insert( "note", new int(FNote) ); |
735 | dict.insert( "created", new int(FCreated) ); | 721 | dict.insert( "created", new int(FCreated) ); |
736 | dict.insert( "action", new int(FAction) ); | 722 | dict.insert( "action", new int(FAction) ); |
737 | dict.insert( "actionkey", new int(FActionKey) ); | 723 | dict.insert( "actionkey", new int(FActionKey) ); |
738 | dict.insert( "actionorig", new int (FJournalOrigHadRepeat) ); | 724 | dict.insert( "actionorig", new int (FJournalOrigHadRepeat) ); |
739 | 725 | ||
740 | 726 | ||
741 | QByteArray ba = f.readAll(); | 727 | QByteArray ba = f.readAll(); |
742 | char* dt = ba.data(); | 728 | char* dt = ba.data(); |
743 | int len = ba.size(); | 729 | int len = ba.size(); |
744 | int currentAction, | 730 | int currentAction, |
745 | journalKey, | 731 | journalKey, |
746 | origHadRepeat; // should be bool, but we need tri-state(not being used) | 732 | origHadRepeat; // should be bool, but we need tri-state(not being used) |
747 | 733 | ||
748 | int i = 0; | 734 | int i = 0; |
749 | char *point; | 735 | char *point; |
750 | while ( ( point = strstr( dt+i, "<event " ) ) != 0 ) { | 736 | while ( ( point = strstr( dt+i, "<event " ) ) != 0 ) { |
751 | i = point - dt; | 737 | i = point - dt; |
752 | // if we are reading in events in the general case, | 738 | // if we are reading in events in the general case, |
753 | // we are just adding them, so let the actions represent that... | 739 | // we are just adding them, so let the actions represent that... |
754 | currentAction = ACTION_ADD; | 740 | currentAction = ACTION_ADD; |
755 | journalKey = -1; | 741 | journalKey = -1; |
756 | origHadRepeat = -1; | 742 | origHadRepeat = -1; |
757 | // some temporary variables for dates and times ... | 743 | // some temporary variables for dates and times ... |
758 | //int startY = 0, startM = 0, startD = 0, starth = 0, startm = 0, starts = 0; | 744 | //int startY = 0, startM = 0, startD = 0, starth = 0, startm = 0, starts = 0; |
759 | //int endY = 0, endM = 0, endD = 0, endh = 0, endm = 0, ends = 0; | 745 | //int endY = 0, endM = 0, endD = 0, endh = 0, endm = 0, ends = 0; |
760 | //int enddtY = 0, enddtM = 0, enddtD = 0; | 746 | //int enddtY = 0, enddtM = 0, enddtD = 0; |
761 | 747 | ||
762 | // ... for the alarm settings ... | 748 | // ... for the alarm settings ... |
763 | int alarmTime = -1; Event::SoundTypeChoice alarmSound = Event::Silent; | 749 | int alarmTime = -1; Event::SoundTypeChoice alarmSound = Event::Silent; |
764 | // ... and for the recurrence | 750 | // ... and for the recurrence |
765 | Event::RepeatPattern rp; | 751 | Event::RepeatPattern rp; |
766 | Event e; | 752 | Event e; |
767 | 753 | ||
768 | i += 7; | 754 | i += 7; |
769 | 755 | ||
770 | while( 1 ) { | 756 | while( 1 ) { |
771 | while ( i < len && (dt[i] == ' ' || dt[i] == '\n' || dt[i] == '\r') ) | 757 | while ( i < len && (dt[i] == ' ' || dt[i] == '\n' || dt[i] == '\r') ) |
772 | ++i; | 758 | ++i; |
773 | if ( i >= len-2 || (dt[i] == '/' && dt[i+1] == '>') ) | 759 | if ( i >= len-2 || (dt[i] == '/' && dt[i+1] == '>') ) |
774 | break; | 760 | break; |
775 | // we have another attribute, read it. | 761 | // we have another attribute, read it. |
776 | int j = i; | 762 | int j = i; |
777 | while ( j < len && dt[j] != '=' ) | 763 | while ( j < len && dt[j] != '=' ) |
778 | ++j; | 764 | ++j; |
779 | char *attr = dt+i; | 765 | char *attr = dt+i; |
780 | dt[j] = '\0'; | 766 | dt[j] = '\0'; |
781 | i = ++j; // skip = | 767 | i = ++j; // skip = |
782 | while ( i < len && dt[i] != '"' ) | 768 | while ( i < len && dt[i] != '"' ) |
783 | ++i; | 769 | ++i; |
784 | j = ++i; | 770 | j = ++i; |
785 | bool haveAmp = FALSE; | 771 | bool haveAmp = FALSE; |
786 | bool haveUtf = FALSE; | 772 | bool haveUtf = FALSE; |
787 | while ( j < len && dt[j] != '"' ) { | 773 | while ( j < len && dt[j] != '"' ) { |
788 | if ( dt[j] == '&' ) | 774 | if ( dt[j] == '&' ) |
789 | haveAmp = TRUE; | 775 | haveAmp = TRUE; |
790 | if ( ((unsigned char)dt[j]) > 0x7f ) | 776 | if ( ((unsigned char)dt[j]) > 0x7f ) |
791 | haveUtf = TRUE; | 777 | haveUtf = TRUE; |
792 | ++j; | 778 | ++j; |
793 | } | 779 | } |
794 | 780 | ||
795 | if ( i == j ) { | 781 | if ( i == j ) { |
diff --git a/library/datebookdb.h b/library/datebookdb.h index e4c251c..0add028 100644 --- a/library/datebookdb.h +++ b/library/datebookdb.h | |||
@@ -1,88 +1,87 @@ | |||
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 ); | ||
48 | 47 | ||
49 | QValueList<Event> getRawRepeats() const; | 48 | QValueList<Event> getRawRepeats() const; |
50 | QValueList<Event> getNonRepeatingEvents( const QDate &from, | 49 | QValueList<Event> getNonRepeatingEvents( const QDate &from, |
51 | const QDate &to ) const; | 50 | const QDate &to ) const; |
52 | 51 | ||
53 | // Use these when dealing with adding removing events... | 52 | // Use these when dealing with adding removing events... |
54 | void addEvent( const Event &ev, bool doalarm=TRUE ); | 53 | void addEvent( const Event &ev, bool doalarm=TRUE ); |
55 | void removeEvent( const Event &ev ); | 54 | void removeEvent( const Event &ev ); |
56 | void editEvent( const Event &old, Event &ev ); | 55 | void editEvent( const Event &old, Event &ev ); |
57 | // add/remove event without journaling ( these ended up in public by accident, never | 56 | // add/remove event without journaling ( these ended up in public by accident, never |
58 | // use them unless you know what you are doing...), | 57 | // use them unless you know what you are doing...), |
59 | // please put them in private if we ever can change the class... | 58 | // please put them in private if we ever can change the class... |
60 | void addJFEvent( const Event &ev, bool doalarm=TRUE ); | 59 | void addJFEvent( const Event &ev, bool doalarm=TRUE ); |
61 | void removeJFEvent( const Event &ev ); | 60 | void removeJFEvent( const Event &ev ); |
62 | 61 | ||
63 | bool save(); | 62 | bool save(); |
64 | void reload(); | 63 | void reload(); |
65 | private: | 64 | private: |
66 | //find the real repeat... | 65 | //find the real repeat... |
67 | bool origRepeat( const Event &ev, Event &orig ) const; | 66 | bool origRepeat( const Event &ev, Event &orig ) const; |
68 | bool removeRepeat( const Event &ev ); | 67 | bool removeRepeat( const Event &ev ); |
69 | void init(); | 68 | void init(); |
70 | void loadFile( const QString &strFile ); | 69 | void loadFile( const QString &strFile ); |
71 | // depreciated... | 70 | // depreciated... |
72 | void saveJournalEntry( const Event &ev, journal_action action ); | 71 | void saveJournalEntry( const Event &ev, journal_action action ); |
73 | // new version, uncomment the "= -1" when we remove the above | 72 | // new version, uncomment the "= -1" when we remove the above |
74 | // function.. | 73 | // function.. |
75 | bool saveJournalEntry( const Event &ev, journal_action action, | 74 | bool saveJournalEntry( const Event &ev, journal_action action, |
76 | int key/* = -1*/, bool origHadRepeat = false ); | 75 | int key/* = -1*/, bool origHadRepeat = false ); |
77 | 76 | ||
78 | QValueList<Event> eventList; // non-repeating events... | 77 | QValueList<Event> eventList; // non-repeating events... |
79 | QValueList<Event> repeatEvents; // the repeating events... | 78 | QValueList<Event> repeatEvents; // the repeating events... |
80 | DateBookDBPrivate *d; | 79 | DateBookDBPrivate *d; |
81 | QFile journalFile; | 80 | QFile journalFile; |
82 | 81 | ||
83 | intrecordIdMax; // ADDITION | 82 | intrecordIdMax; // ADDITION |
84 | }; | 83 | }; |
85 | 84 | ||
86 | /* helper functions, also useful to other apps. */ | 85 | /* helper functions, also useful to other apps. */ |
87 | bool nextOccurance( const Event &e, const QDate &from, QDateTime &next); | 86 | bool nextOccurance( const Event &e, const QDate &from, QDateTime &next); |
88 | #endif | 87 | #endif |