-rw-r--r-- | library/datebookdb.cpp | 3 |
1 files changed, 2 insertions, 1 deletions
diff --git a/library/datebookdb.cpp b/library/datebookdb.cpp index 2ac9a0c..a26fe8f 100644 --- a/library/datebookdb.cpp +++ b/library/datebookdb.cpp | |||
@@ -640,193 +640,194 @@ void DateBookDB::editEvent( const Event &old, Event &editedEv ) | |||
640 | // Add new event | 640 | // Add new event |
641 | if ( editedEv.hasAlarm() ) | 641 | if ( editedEv.hasAlarm() ) |
642 | addEventAlarm( editedEv ); | 642 | addEventAlarm( editedEv ); |
643 | if ( editedEv.hasRepeat() ) | 643 | if ( editedEv.hasRepeat() ) |
644 | repeatEvents.append( editedEv ); | 644 | repeatEvents.append( editedEv ); |
645 | else | 645 | else |
646 | eventList.append( editedEv ); | 646 | eventList.append( editedEv ); |
647 | 647 | ||
648 | d->clean = false; | 648 | d->clean = false; |
649 | } | 649 | } |
650 | 650 | ||
651 | void DateBookDB::removeEvent( const Event &ev ) | 651 | void DateBookDB::removeEvent( const Event &ev ) |
652 | { | 652 | { |
653 | // write to the journal... | 653 | // write to the journal... |
654 | saveJournalEntry( ev, ACTION_REMOVE, -1, false ); | 654 | saveJournalEntry( ev, ACTION_REMOVE, -1, false ); |
655 | removeJFEvent( ev ); | 655 | removeJFEvent( ev ); |
656 | d->clean = false; | 656 | d->clean = false; |
657 | } | 657 | } |
658 | 658 | ||
659 | void DateBookDB::removeJFEvent( const Event&ev ) | 659 | void DateBookDB::removeJFEvent( const Event&ev ) |
660 | { | 660 | { |
661 | if ( ev.hasAlarm() ) | 661 | if ( ev.hasAlarm() ) |
662 | delEventAlarm( ev ); | 662 | delEventAlarm( ev ); |
663 | if ( ev.hasRepeat() ) { | 663 | if ( ev.hasRepeat() ) { |
664 | removeRepeat( ev ); | 664 | removeRepeat( ev ); |
665 | } else { | 665 | } else { |
666 | QValueList<Event>::Iterator it = eventList.find( ev ); | 666 | QValueList<Event>::Iterator it = eventList.find( ev ); |
667 | if ( it != eventList.end() ) | 667 | if ( it != eventList.end() ) |
668 | eventList.remove( it ); | 668 | eventList.remove( it ); |
669 | } | 669 | } |
670 | } | 670 | } |
671 | 671 | ||
672 | // also handles journaling... | 672 | // also handles journaling... |
673 | void DateBookDB::loadFile( const QString &strFile ) | 673 | void DateBookDB::loadFile( const QString &strFile ) |
674 | { | 674 | { |
675 | 675 | ||
676 | QFile f( strFile ); | 676 | QFile f( strFile ); |
677 | if ( !f.open( IO_ReadOnly ) ) | 677 | if ( !f.open( IO_ReadOnly ) ) |
678 | return; | 678 | return; |
679 | 679 | ||
680 | enum Attribute { | 680 | enum Attribute { |
681 | FDescription = 0, | 681 | FDescription = 0, |
682 | FLocation, | 682 | FLocation, |
683 | FCategories, | 683 | FCategories, |
684 | FUid, | 684 | FUid, |
685 | FType, | 685 | FType, |
686 | FAlarm, | 686 | FAlarm, |
687 | FSound, | 687 | FSound, |
688 | FRType, | 688 | FRType, |
689 | FRWeekdays, | 689 | FRWeekdays, |
690 | FRPosition, | 690 | FRPosition, |
691 | FRFreq, | 691 | FRFreq, |
692 | FRHasEndDate, | 692 | FRHasEndDate, |
693 | FREndDate, | 693 | FREndDate, |
694 | FRStart, | 694 | FRStart, |
695 | FREnd, | 695 | FREnd, |
696 | FNote, | 696 | FNote, |
697 | FCreated, | 697 | FCreated, |
698 | FAction, | 698 | FAction, |
699 | FActionKey, | 699 | FActionKey, |
700 | FJournalOrigHadRepeat | 700 | FJournalOrigHadRepeat |
701 | }; | 701 | }; |
702 | 702 | ||
703 | QAsciiDict<int> dict( 97 ); | 703 | QAsciiDict<int> dict( 97 ); |
704 | dict.setAutoDelete( TRUE ); | 704 | dict.setAutoDelete( TRUE ); |
705 | dict.insert( "description", new int(FDescription) ); | 705 | dict.insert( "description", new int(FDescription) ); |
706 | dict.insert( "location", new int(FLocation) ); | 706 | dict.insert( "location", new int(FLocation) ); |
707 | dict.insert( "categories", new int(FCategories) ); | 707 | dict.insert( "categories", new int(FCategories) ); |
708 | dict.insert( "uid", new int(FUid) ); | 708 | dict.insert( "uid", new int(FUid) ); |
709 | dict.insert( "type", new int(FType) ); | 709 | dict.insert( "type", new int(FType) ); |
710 | dict.insert( "alarm", new int(FAlarm) ); | 710 | dict.insert( "alarm", new int(FAlarm) ); |
711 | dict.insert( "sound", new int(FSound) ); | 711 | dict.insert( "sound", new int(FSound) ); |
712 | dict.insert( "rtype", new int(FRType) ); | 712 | dict.insert( "rtype", new int(FRType) ); |
713 | dict.insert( "rweekdays", new int(FRWeekdays) ); | 713 | dict.insert( "rweekdays", new int(FRWeekdays) ); |
714 | dict.insert( "rposition", new int(FRPosition) ); | 714 | dict.insert( "rposition", new int(FRPosition) ); |
715 | dict.insert( "rfreq", new int(FRFreq) ); | 715 | dict.insert( "rfreq", new int(FRFreq) ); |
716 | dict.insert( "rhasenddate", new int(FRHasEndDate) ); | 716 | dict.insert( "rhasenddate", new int(FRHasEndDate) ); |
717 | dict.insert( "enddt", new int(FREndDate) ); | 717 | dict.insert( "enddt", new int(FREndDate) ); |
718 | dict.insert( "start", new int(FRStart) ); | 718 | dict.insert( "start", new int(FRStart) ); |
719 | dict.insert( "end", new int(FREnd) ); | 719 | dict.insert( "end", new int(FREnd) ); |
720 | dict.insert( "note", new int(FNote) ); | 720 | dict.insert( "note", new int(FNote) ); |
721 | dict.insert( "created", new int(FCreated) ); | 721 | dict.insert( "created", new int(FCreated) ); |
722 | dict.insert( "action", new int(FAction) ); | 722 | dict.insert( "action", new int(FAction) ); |
723 | dict.insert( "actionkey", new int(FActionKey) ); | 723 | dict.insert( "actionkey", new int(FActionKey) ); |
724 | dict.insert( "actionorig", new int (FJournalOrigHadRepeat) ); | 724 | dict.insert( "actionorig", new int (FJournalOrigHadRepeat) ); |
725 | 725 | ||
726 | 726 | ||
727 | QByteArray ba = f.readAll(); | 727 | QByteArray ba = f.readAll(); |
728 | char* dt = ba.data(); | 728 | char* dt = ba.data(); |
729 | int len = ba.size(); | 729 | int len = ba.size(); |
730 | int currentAction, | 730 | int currentAction, |
731 | journalKey, | 731 | journalKey, |
732 | 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) |
733 | 733 | ||
734 | int i = 0; | 734 | int i = 0; |
735 | char *point; | 735 | char *point; |
736 | while ( ( point = strstr( dt+i, "<event " ) ) != 0 ) { | 736 | // hack to get rid of segfaults after reading </DATEBOOK> |
737 | while ( (dt+i != 0) && (( point = strstr( dt+i, "<event " ) ) != 0 )) { | ||
737 | i = point - dt; | 738 | i = point - dt; |
738 | // if we are reading in events in the general case, | 739 | // if we are reading in events in the general case, |
739 | // we are just adding them, so let the actions represent that... | 740 | // we are just adding them, so let the actions represent that... |
740 | currentAction = ACTION_ADD; | 741 | currentAction = ACTION_ADD; |
741 | journalKey = -1; | 742 | journalKey = -1; |
742 | origHadRepeat = -1; | 743 | origHadRepeat = -1; |
743 | // some temporary variables for dates and times ... | 744 | // some temporary variables for dates and times ... |
744 | //int startY = 0, startM = 0, startD = 0, starth = 0, startm = 0, starts = 0; | 745 | //int startY = 0, startM = 0, startD = 0, starth = 0, startm = 0, starts = 0; |
745 | //int endY = 0, endM = 0, endD = 0, endh = 0, endm = 0, ends = 0; | 746 | //int endY = 0, endM = 0, endD = 0, endh = 0, endm = 0, ends = 0; |
746 | //int enddtY = 0, enddtM = 0, enddtD = 0; | 747 | //int enddtY = 0, enddtM = 0, enddtD = 0; |
747 | 748 | ||
748 | // ... for the alarm settings ... | 749 | // ... for the alarm settings ... |
749 | int alarmTime = -1; Event::SoundTypeChoice alarmSound = Event::Silent; | 750 | int alarmTime = -1; Event::SoundTypeChoice alarmSound = Event::Silent; |
750 | // ... and for the recurrence | 751 | // ... and for the recurrence |
751 | Event::RepeatPattern rp; | 752 | Event::RepeatPattern rp; |
752 | Event e; | 753 | Event e; |
753 | 754 | ||
754 | i += 7; | 755 | i += 7; |
755 | 756 | ||
756 | while( 1 ) { | 757 | while( 1 ) { |
757 | while ( i < len && (dt[i] == ' ' || dt[i] == '\n' || dt[i] == '\r') ) | 758 | while ( i < len && (dt[i] == ' ' || dt[i] == '\n' || dt[i] == '\r') ) |
758 | ++i; | 759 | ++i; |
759 | if ( i >= len-2 || (dt[i] == '/' && dt[i+1] == '>') ) | 760 | if ( i >= len-2 || (dt[i] == '/' && dt[i+1] == '>') ) |
760 | break; | 761 | break; |
761 | // we have another attribute, read it. | 762 | // we have another attribute, read it. |
762 | int j = i; | 763 | int j = i; |
763 | while ( j < len && dt[j] != '=' ) | 764 | while ( j < len && dt[j] != '=' ) |
764 | ++j; | 765 | ++j; |
765 | char *attr = dt+i; | 766 | char *attr = dt+i; |
766 | dt[j] = '\0'; | 767 | dt[j] = '\0'; |
767 | i = ++j; // skip = | 768 | i = ++j; // skip = |
768 | while ( i < len && dt[i] != '"' ) | 769 | while ( i < len && dt[i] != '"' ) |
769 | ++i; | 770 | ++i; |
770 | j = ++i; | 771 | j = ++i; |
771 | bool haveAmp = FALSE; | 772 | bool haveAmp = FALSE; |
772 | bool haveUtf = FALSE; | 773 | bool haveUtf = FALSE; |
773 | while ( j < len && dt[j] != '"' ) { | 774 | while ( j < len && dt[j] != '"' ) { |
774 | if ( dt[j] == '&' ) | 775 | if ( dt[j] == '&' ) |
775 | haveAmp = TRUE; | 776 | haveAmp = TRUE; |
776 | if ( ((unsigned char)dt[j]) > 0x7f ) | 777 | if ( ((unsigned char)dt[j]) > 0x7f ) |
777 | haveUtf = TRUE; | 778 | haveUtf = TRUE; |
778 | ++j; | 779 | ++j; |
779 | } | 780 | } |
780 | 781 | ||
781 | if ( i == j ) { | 782 | if ( i == j ) { |
782 | // leave out empty attributes | 783 | // leave out empty attributes |
783 | i = j + 1; | 784 | i = j + 1; |
784 | continue; | 785 | continue; |
785 | } | 786 | } |
786 | 787 | ||
787 | QString value = haveUtf ? QString::fromUtf8( dt+i, j-i ) | 788 | QString value = haveUtf ? QString::fromUtf8( dt+i, j-i ) |
788 | : QString::fromLatin1( dt+i, j-i ); | 789 | : QString::fromLatin1( dt+i, j-i ); |
789 | if ( haveAmp ) | 790 | if ( haveAmp ) |
790 | value = Qtopia::plainString( value ); | 791 | value = Qtopia::plainString( value ); |
791 | i = j + 1; | 792 | i = j + 1; |
792 | 793 | ||
793 | //qDebug("attr='%s' value='%s'", attr.data(), value.latin1() ); | 794 | //qDebug("attr='%s' value='%s'", attr.data(), value.latin1() ); |
794 | int * find = dict[ attr ]; | 795 | int * find = dict[ attr ]; |
795 | #if 1 | 796 | #if 1 |
796 | if ( !find ) { | 797 | if ( !find ) { |
797 | // custom field | 798 | // custom field |
798 | e.setCustomField(attr, value); | 799 | e.setCustomField(attr, value); |
799 | continue; | 800 | continue; |
800 | } | 801 | } |
801 | 802 | ||
802 | switch( *find ) { | 803 | switch( *find ) { |
803 | case FDescription: | 804 | case FDescription: |
804 | e.setDescription( value ); | 805 | e.setDescription( value ); |
805 | break; | 806 | break; |
806 | case FLocation: | 807 | case FLocation: |
807 | e.setLocation( value ); | 808 | e.setLocation( value ); |
808 | break; | 809 | break; |
809 | case FCategories: | 810 | case FCategories: |
810 | e.setCategories( Qtopia::Record::idsFromString( value ) ); | 811 | e.setCategories( Qtopia::Record::idsFromString( value ) ); |
811 | break; | 812 | break; |
812 | case FUid: | 813 | case FUid: |
813 | e.setUid( value.toInt() ); | 814 | e.setUid( value.toInt() ); |
814 | break; | 815 | break; |
815 | case FType: | 816 | case FType: |
816 | if ( value == "AllDay" ) | 817 | if ( value == "AllDay" ) |
817 | e.setType( Event::AllDay ); | 818 | e.setType( Event::AllDay ); |
818 | else | 819 | else |
819 | e.setType( Event::Normal ); | 820 | e.setType( Event::Normal ); |
820 | break; | 821 | break; |
821 | case FAlarm: | 822 | case FAlarm: |
822 | alarmTime = value.toInt(); | 823 | alarmTime = value.toInt(); |
823 | break; | 824 | break; |
824 | case FSound: | 825 | case FSound: |
825 | alarmSound = value == "loud" ? Event::Loud : Event::Silent; | 826 | alarmSound = value == "loud" ? Event::Loud : Event::Silent; |
826 | break; | 827 | break; |
827 | // recurrence stuff | 828 | // recurrence stuff |
828 | case FRType: | 829 | case FRType: |
829 | if ( value == "Daily" ) | 830 | if ( value == "Daily" ) |
830 | rp.type = Event::Daily; | 831 | rp.type = Event::Daily; |
831 | else if ( value == "Weekly" ) | 832 | else if ( value == "Weekly" ) |
832 | rp.type = Event::Weekly; | 833 | rp.type = Event::Weekly; |