-rw-r--r-- | library/backend/event.cpp | 34 |
1 files changed, 34 insertions, 0 deletions
diff --git a/library/backend/event.cpp b/library/backend/event.cpp index 7cac314..7ccf16b 100644 --- a/library/backend/event.cpp +++ b/library/backend/event.cpp | |||
@@ -710,614 +710,648 @@ bool Event::operator==( const Event &e ) const | |||
710 | e.note == note ); | 710 | e.note == note ); |
711 | } | 711 | } |
712 | 712 | ||
713 | /*! | 713 | /*! |
714 | \internal | 714 | \internal |
715 | Appends the contact information to \a buf. | 715 | Appends the contact information to \a buf. |
716 | */ | 716 | */ |
717 | void Event::save( QString& buf ) | 717 | void Event::save( QString& buf ) |
718 | { | 718 | { |
719 | buf += " description=\"" + Qtopia::escapeString(descript) + "\""; | 719 | buf += " description=\"" + Qtopia::escapeString(descript) + "\""; |
720 | if ( !locat.isEmpty() ) | 720 | if ( !locat.isEmpty() ) |
721 | buf += " location=\"" + Qtopia::escapeString(locat) + "\""; | 721 | buf += " location=\"" + Qtopia::escapeString(locat) + "\""; |
722 | // save the categoies differently.... | 722 | // save the categoies differently.... |
723 | QString strCats = idsToString( categories() ); | 723 | QString strCats = idsToString( categories() ); |
724 | buf += " categories=\"" + Qtopia::escapeString(strCats) + "\""; | 724 | buf += " categories=\"" + Qtopia::escapeString(strCats) + "\""; |
725 | buf += " uid=\"" + QString::number( uid() ) + "\""; | 725 | buf += " uid=\"" + QString::number( uid() ) + "\""; |
726 | if ( (Type)typ != Normal ) | 726 | if ( (Type)typ != Normal ) |
727 | buf += " type=\"AllDay\""; | 727 | buf += " type=\"AllDay\""; |
728 | if ( hAlarm ) { | 728 | if ( hAlarm ) { |
729 | buf += " alarm=\"" + QString::number( aMinutes ) + "\" sound=\""; | 729 | buf += " alarm=\"" + QString::number( aMinutes ) + "\" sound=\""; |
730 | if ( aSound == Event::Loud ) | 730 | if ( aSound == Event::Loud ) |
731 | buf += "loud"; | 731 | buf += "loud"; |
732 | else | 732 | else |
733 | buf += "silent"; | 733 | buf += "silent"; |
734 | buf += "\""; | 734 | buf += "\""; |
735 | } | 735 | } |
736 | if ( hRepeat ) | 736 | if ( hRepeat ) |
737 | write( buf, pattern ); | 737 | write( buf, pattern ); |
738 | 738 | ||
739 | buf += " start=\"" | 739 | buf += " start=\"" |
740 | + QString::number( startUTC ) | 740 | + QString::number( startUTC ) |
741 | + "\""; | 741 | + "\""; |
742 | 742 | ||
743 | buf += " end=\"" | 743 | buf += " end=\"" |
744 | + QString::number( endUTC ) | 744 | + QString::number( endUTC ) |
745 | + "\""; | 745 | + "\""; |
746 | 746 | ||
747 | if ( !note.isEmpty() ) | 747 | if ( !note.isEmpty() ) |
748 | buf += " note=\"" + Qtopia::escapeString( note ) + "\""; | 748 | buf += " note=\"" + Qtopia::escapeString( note ) + "\""; |
749 | buf += customToXml(); | 749 | buf += customToXml(); |
750 | } | 750 | } |
751 | 751 | ||
752 | /*! | 752 | /*! |
753 | \internal | 753 | \internal |
754 | */ | 754 | */ |
755 | bool Event::RepeatPattern::operator==( const Event::RepeatPattern &right ) const | 755 | bool Event::RepeatPattern::operator==( const Event::RepeatPattern &right ) const |
756 | { | 756 | { |
757 | // *sigh* | 757 | // *sigh* |
758 | return ( type == right.type | 758 | return ( type == right.type |
759 | && frequency == right.frequency | 759 | && frequency == right.frequency |
760 | && position == right.position | 760 | && position == right.position |
761 | && days == right.days | 761 | && days == right.days |
762 | && hasEndDate == right.hasEndDate | 762 | && hasEndDate == right.hasEndDate |
763 | && endDateUTC == right.endDateUTC | 763 | && endDateUTC == right.endDateUTC |
764 | && createTime == right.createTime ); | 764 | && createTime == right.createTime ); |
765 | } | 765 | } |
766 | 766 | ||
767 | /*! | 767 | /*! |
768 | \class EffectiveEvent | 768 | \class EffectiveEvent |
769 | \brief The EffectiveEvent class the data for a single occurance of an event. | 769 | \brief The EffectiveEvent class the data for a single occurance of an event. |
770 | 770 | ||
771 | This class describes the event for a single occurance of it. For example if | 771 | This class describes the event for a single occurance of it. For example if |
772 | an Event occurs every week, the effective event might represent the third | 772 | an Event occurs every week, the effective event might represent the third |
773 | occurance of this Event. | 773 | occurance of this Event. |
774 | 774 | ||
775 | \ingroup qtopiaemb | 775 | \ingroup qtopiaemb |
776 | \ingroup qtopiadesktop | 776 | \ingroup qtopiadesktop |
777 | \warning This class will be phased out in Qtopia 3.x | 777 | \warning This class will be phased out in Qtopia 3.x |
778 | */ | 778 | */ |
779 | 779 | ||
780 | /*! | 780 | /*! |
781 | \enum EffectiveEvent::Position | 781 | \enum EffectiveEvent::Position |
782 | \internal | 782 | \internal |
783 | */ | 783 | */ |
784 | 784 | ||
785 | /*! | 785 | /*! |
786 | \fn EffectiveEvent &EffectiveEvent::operator=(const EffectiveEvent &) | 786 | \fn EffectiveEvent &EffectiveEvent::operator=(const EffectiveEvent &) |
787 | \internal | 787 | \internal |
788 | */ | 788 | */ |
789 | 789 | ||
790 | class EffectiveEventPrivate | 790 | class EffectiveEventPrivate |
791 | { | 791 | { |
792 | public: | 792 | public: |
793 | //currently the existence of the d pointer means multi-day repeating, | 793 | //currently the existence of the d pointer means multi-day repeating, |
794 | //msut be changed if we use the d pointer for anything else. | 794 | //msut be changed if we use the d pointer for anything else. |
795 | QDate startDate; | 795 | QDate startDate; |
796 | QDate endDate; | 796 | QDate endDate; |
797 | }; | 797 | }; |
798 | 798 | ||
799 | /*! | 799 | /*! |
800 | \internal | 800 | \internal |
801 | */ | 801 | */ |
802 | EffectiveEvent::EffectiveEvent() | 802 | EffectiveEvent::EffectiveEvent() |
803 | { | 803 | { |
804 | mDate = QDate::currentDate(); | 804 | mDate = QDate::currentDate(); |
805 | mStart = mEnd = QTime::currentTime(); | 805 | mStart = mEnd = QTime::currentTime(); |
806 | d = 0; | 806 | d = 0; |
807 | } | 807 | } |
808 | 808 | ||
809 | /*! | 809 | /*! |
810 | \internal | 810 | \internal |
811 | */ | 811 | */ |
812 | EffectiveEvent::EffectiveEvent( const Event &e, const QDate &date, Position pos ) | 812 | EffectiveEvent::EffectiveEvent( const Event &e, const QDate &date, Position pos ) |
813 | { | 813 | { |
814 | mEvent = e; | 814 | mEvent = e; |
815 | mDate = date; | 815 | mDate = date; |
816 | if ( pos & Start ) | 816 | if ( pos & Start ) |
817 | mStart = e.start( TRUE ).time(); | 817 | mStart = e.start( TRUE ).time(); |
818 | else | 818 | else |
819 | mStart = QTime( 0, 0, 0 ); | 819 | mStart = QTime( 0, 0, 0 ); |
820 | 820 | ||
821 | if ( pos & End ) | 821 | if ( pos & End ) |
822 | mEnd = e.end( TRUE ).time(); | 822 | mEnd = e.end( TRUE ).time(); |
823 | else | 823 | else |
824 | mEnd = QTime( 23, 59, 59 ); | 824 | mEnd = QTime( 23, 59, 59 ); |
825 | d = 0; | 825 | d = 0; |
826 | } | 826 | } |
827 | 827 | ||
828 | /*! | 828 | /*! |
829 | \internal | 829 | \internal |
830 | */ | 830 | */ |
831 | EffectiveEvent::~EffectiveEvent() | 831 | EffectiveEvent::~EffectiveEvent() |
832 | { | 832 | { |
833 | delete d; | 833 | delete d; |
834 | } | 834 | } |
835 | 835 | ||
836 | /*! | 836 | /*! |
837 | \internal | 837 | \internal |
838 | */ | 838 | */ |
839 | EffectiveEvent::EffectiveEvent( const EffectiveEvent &e ) | 839 | EffectiveEvent::EffectiveEvent( const EffectiveEvent &e ) |
840 | { | 840 | { |
841 | d = 0; | 841 | d = 0; |
842 | *this = e; | 842 | *this = e; |
843 | } | 843 | } |
844 | 844 | ||
845 | EffectiveEvent& EffectiveEvent::operator=( const EffectiveEvent & e ) | 845 | EffectiveEvent& EffectiveEvent::operator=( const EffectiveEvent & e ) |
846 | { | 846 | { |
847 | if ( &e == this ) | 847 | if ( &e == this ) |
848 | return *this; | 848 | return *this; |
849 | delete d; | 849 | delete d; |
850 | if ( e.d ) { | 850 | if ( e.d ) { |
851 | d = new EffectiveEventPrivate; | 851 | d = new EffectiveEventPrivate; |
852 | d->startDate = e.d->startDate; | 852 | d->startDate = e.d->startDate; |
853 | d->endDate = e.d->endDate; | 853 | d->endDate = e.d->endDate; |
854 | } else { | 854 | } else { |
855 | d = 0; | 855 | d = 0; |
856 | } | 856 | } |
857 | mEvent = e.mEvent; | 857 | mEvent = e.mEvent; |
858 | mDate = e.mDate; | 858 | mDate = e.mDate; |
859 | mStart = e.mStart; | 859 | mStart = e.mStart; |
860 | mEnd = e.mEnd; | 860 | mEnd = e.mEnd; |
861 | 861 | ||
862 | return *this; | 862 | return *this; |
863 | 863 | ||
864 | } | 864 | } |
865 | 865 | ||
866 | // QString EffectiveEvent::category() const | 866 | // QString EffectiveEvent::category() const |
867 | // { | 867 | // { |
868 | // return mEvent.category(); | 868 | // return mEvent.category(); |
869 | // } | 869 | // } |
870 | 870 | ||
871 | /*! | 871 | /*! |
872 | Returns the description of the event for this effective event. | 872 | Returns the description of the event for this effective event. |
873 | */ | 873 | */ |
874 | const QString &EffectiveEvent::description( ) const | 874 | const QString &EffectiveEvent::description( ) const |
875 | { | 875 | { |
876 | return mEvent.description(); | 876 | return mEvent.description(); |
877 | } | 877 | } |
878 | 878 | ||
879 | /*! | 879 | /*! |
880 | \internal | 880 | \internal |
881 | */ | 881 | */ |
882 | const QString &EffectiveEvent::location( ) const | 882 | const QString &EffectiveEvent::location( ) const |
883 | { | 883 | { |
884 | return mEvent.location(); | 884 | return mEvent.location(); |
885 | } | 885 | } |
886 | 886 | ||
887 | /*! | 887 | /*! |
888 | \internal | 888 | \internal |
889 | */ | 889 | */ |
890 | const QString &EffectiveEvent::notes() const | 890 | const QString &EffectiveEvent::notes() const |
891 | { | 891 | { |
892 | return mEvent.notes(); | 892 | return mEvent.notes(); |
893 | } | 893 | } |
894 | 894 | ||
895 | /*! | 895 | /*! |
896 | Returns the event associated with this effective event. | 896 | Returns the event associated with this effective event. |
897 | */ | 897 | */ |
898 | const Event &EffectiveEvent::event() const | 898 | const Event &EffectiveEvent::event() const |
899 | { | 899 | { |
900 | return mEvent; | 900 | return mEvent; |
901 | } | 901 | } |
902 | 902 | ||
903 | /*! | 903 | /*! |
904 | \internal | 904 | \internal |
905 | */ | 905 | */ |
906 | const QTime &EffectiveEvent::end() const | 906 | const QTime &EffectiveEvent::end() const |
907 | { | 907 | { |
908 | return mEnd; | 908 | return mEnd; |
909 | } | 909 | } |
910 | 910 | ||
911 | /*! | 911 | /*! |
912 | \internal | 912 | \internal |
913 | */ | 913 | */ |
914 | const QTime &EffectiveEvent::start() const | 914 | const QTime &EffectiveEvent::start() const |
915 | { | 915 | { |
916 | return mStart; | 916 | return mStart; |
917 | } | 917 | } |
918 | 918 | ||
919 | /*! | 919 | /*! |
920 | Returns the date the effective event occurs on. | 920 | Returns the date the effective event occurs on. |
921 | */ | 921 | */ |
922 | const QDate &EffectiveEvent::date() const | 922 | const QDate &EffectiveEvent::date() const |
923 | { | 923 | { |
924 | return mDate; | 924 | return mDate; |
925 | } | 925 | } |
926 | 926 | ||
927 | /*! | 927 | /*! |
928 | \internal | 928 | \internal |
929 | */ | 929 | */ |
930 | int EffectiveEvent::length() const | 930 | int EffectiveEvent::length() const |
931 | { | 931 | { |
932 | return (mEnd.hour() * 60 - mStart.hour() * 60) | 932 | return (mEnd.hour() * 60 - mStart.hour() * 60) |
933 | + QABS(mStart.minute() - mEnd.minute() ); | 933 | + QABS(mStart.minute() - mEnd.minute() ); |
934 | } | 934 | } |
935 | 935 | ||
936 | /*! | 936 | /*! |
937 | \internal | 937 | \internal |
938 | */ | 938 | */ |
939 | void EffectiveEvent::setDate( const QDate &dt ) | 939 | void EffectiveEvent::setDate( const QDate &dt ) |
940 | { | 940 | { |
941 | mDate = dt; | 941 | mDate = dt; |
942 | } | 942 | } |
943 | 943 | ||
944 | /*! | 944 | /*! |
945 | \internal | 945 | \internal |
946 | */ | 946 | */ |
947 | void EffectiveEvent::setStart( const QTime &start ) | 947 | void EffectiveEvent::setStart( const QTime &start ) |
948 | { | 948 | { |
949 | mStart = start; | 949 | mStart = start; |
950 | } | 950 | } |
951 | 951 | ||
952 | /*! | 952 | /*! |
953 | \internal | 953 | \internal |
954 | */ | 954 | */ |
955 | void EffectiveEvent::setEnd( const QTime &end ) | 955 | void EffectiveEvent::setEnd( const QTime &end ) |
956 | { | 956 | { |
957 | mEnd = end; | 957 | mEnd = end; |
958 | } | 958 | } |
959 | 959 | ||
960 | /*! | 960 | /*! |
961 | \internal | 961 | \internal |
962 | */ | 962 | */ |
963 | void EffectiveEvent::setEvent( Event e ) | 963 | void EffectiveEvent::setEvent( Event e ) |
964 | { | 964 | { |
965 | mEvent = e; | 965 | mEvent = e; |
966 | } | 966 | } |
967 | 967 | ||
968 | /*! | 968 | /*! |
969 | \internal | 969 | \internal |
970 | */ | 970 | */ |
971 | bool EffectiveEvent::operator<( const EffectiveEvent &e ) const | 971 | bool EffectiveEvent::operator<( const EffectiveEvent &e ) const |
972 | { | 972 | { |
973 | if ( mDate < e.date() ) | 973 | if ( mDate < e.date() ) |
974 | return TRUE; | 974 | return TRUE; |
975 | if ( mDate == e.date() ) | 975 | if ( mDate == e.date() ) |
976 | return ( mStart < e.start() ); | 976 | return ( mStart < e.start() ); |
977 | else | 977 | else |
978 | return FALSE; | 978 | return FALSE; |
979 | } | 979 | } |
980 | 980 | ||
981 | /*! | 981 | /*! |
982 | \internal | 982 | \internal |
983 | */ | 983 | */ |
984 | bool EffectiveEvent::operator<=( const EffectiveEvent &e ) const | 984 | bool EffectiveEvent::operator<=( const EffectiveEvent &e ) const |
985 | { | 985 | { |
986 | return (mDate <= e.date() ); | 986 | return (mDate <= e.date() ); |
987 | } | 987 | } |
988 | 988 | ||
989 | /*! | 989 | /*! |
990 | \internal | 990 | \internal |
991 | */ | 991 | */ |
992 | bool EffectiveEvent::operator==( const EffectiveEvent &e ) const | 992 | bool EffectiveEvent::operator==( const EffectiveEvent &e ) const |
993 | { | 993 | { |
994 | return ( mDate == e.date() | 994 | return ( mDate == e.date() |
995 | && mStart == e.start() | 995 | && mStart == e.start() |
996 | && mEnd == e.end() | 996 | && mEnd == e.end() |
997 | && mEvent == e.event() ); | 997 | && mEvent == e.event() ); |
998 | } | 998 | } |
999 | 999 | ||
1000 | /*! | 1000 | /*! |
1001 | \internal | 1001 | \internal |
1002 | */ | 1002 | */ |
1003 | bool EffectiveEvent::operator!=( const EffectiveEvent &e ) const | 1003 | bool EffectiveEvent::operator!=( const EffectiveEvent &e ) const |
1004 | { | 1004 | { |
1005 | return !(*this == e); | 1005 | return !(*this == e); |
1006 | } | 1006 | } |
1007 | 1007 | ||
1008 | /*! | 1008 | /*! |
1009 | \internal | 1009 | \internal |
1010 | */ | 1010 | */ |
1011 | bool EffectiveEvent::operator>( const EffectiveEvent &e ) const | 1011 | bool EffectiveEvent::operator>( const EffectiveEvent &e ) const |
1012 | { | 1012 | { |
1013 | return !(*this <= e ); | 1013 | return !(*this <= e ); |
1014 | } | 1014 | } |
1015 | 1015 | ||
1016 | /*! | 1016 | /*! |
1017 | \internal | 1017 | \internal |
1018 | */ | 1018 | */ |
1019 | bool EffectiveEvent::operator>=(const EffectiveEvent &e) const | 1019 | bool EffectiveEvent::operator>=(const EffectiveEvent &e) const |
1020 | { | 1020 | { |
1021 | return !(*this < e); | 1021 | return !(*this < e); |
1022 | } | 1022 | } |
1023 | 1023 | ||
1024 | /*! | 1024 | /*! |
1025 | \internal | 1025 | \internal |
1026 | */ | 1026 | */ |
1027 | void EffectiveEvent::setEffectiveDates( const QDate &from, const QDate &to ) | 1027 | void EffectiveEvent::setEffectiveDates( const QDate &from, const QDate &to ) |
1028 | { | 1028 | { |
1029 | if ( !from.isValid() ) { | 1029 | if ( !from.isValid() ) { |
1030 | delete d; | 1030 | delete d; |
1031 | d = 0; | 1031 | d = 0; |
1032 | return; | 1032 | return; |
1033 | } | 1033 | } |
1034 | if ( !d ) | 1034 | if ( !d ) |
1035 | d = new EffectiveEventPrivate; | 1035 | d = new EffectiveEventPrivate; |
1036 | d->startDate = from; | 1036 | d->startDate = from; |
1037 | d->endDate = to; | 1037 | d->endDate = to; |
1038 | } | 1038 | } |
1039 | 1039 | ||
1040 | /*! | 1040 | /*! |
1041 | \internal | 1041 | \internal |
1042 | */ | 1042 | */ |
1043 | QDate EffectiveEvent::startDate() const | 1043 | QDate EffectiveEvent::startDate() const |
1044 | { | 1044 | { |
1045 | if ( d ) | 1045 | if ( d ) |
1046 | return d->startDate; | 1046 | return d->startDate; |
1047 | else if ( mEvent.hasRepeat() ) | 1047 | else if ( mEvent.hasRepeat() ) |
1048 | return mDate; // single day, since multi-day should have a d pointer | 1048 | return mDate; // single day, since multi-day should have a d pointer |
1049 | else | 1049 | else |
1050 | return mEvent.start().date(); | 1050 | return mEvent.start().date(); |
1051 | } | 1051 | } |
1052 | 1052 | ||
1053 | /*! | 1053 | /*! |
1054 | \internal | 1054 | \internal |
1055 | */ | 1055 | */ |
1056 | QDate EffectiveEvent::endDate() const | 1056 | QDate EffectiveEvent::endDate() const |
1057 | { | 1057 | { |
1058 | if ( d ) | 1058 | if ( d ) |
1059 | return d->endDate; | 1059 | return d->endDate; |
1060 | else if ( mEvent.hasRepeat() ) | 1060 | else if ( mEvent.hasRepeat() ) |
1061 | return mDate; // single day, since multi-day should have a d pointer | 1061 | return mDate; // single day, since multi-day should have a d pointer |
1062 | else | 1062 | else |
1063 | return mEvent.end().date(); | 1063 | return mEvent.end().date(); |
1064 | } | 1064 | } |
1065 | 1065 | ||
1066 | /*! | 1066 | /*! |
1067 | \internal | 1067 | \internal |
1068 | */ | 1068 | */ |
1069 | int EffectiveEvent::size() const | 1069 | int EffectiveEvent::size() const |
1070 | { | 1070 | { |
1071 | return ( mEnd.hour() - mStart.hour() ) * 3600 | 1071 | return ( mEnd.hour() - mStart.hour() ) * 3600 |
1072 | + (mEnd.minute() - mStart.minute() * 60 | 1072 | + (mEnd.minute() - mStart.minute() * 60 |
1073 | + mEnd.second() - mStart.second() ); | 1073 | + mEnd.second() - mStart.second() ); |
1074 | } | 1074 | } |
1075 | 1075 | ||
1076 | 1076 | ||
1077 | // vcal conversion code | 1077 | // vcal conversion code |
1078 | static inline VObject *safeAddPropValue( VObject *o, const char *prop, const QString &value ) | 1078 | static inline VObject *safeAddPropValue( VObject *o, const char *prop, const QString &value ) |
1079 | { | 1079 | { |
1080 | VObject *ret = 0; | 1080 | VObject *ret = 0; |
1081 | if ( o && !value.isEmpty() ) | 1081 | if ( o && !value.isEmpty() ) |
1082 | ret = addPropValue( o, prop, value.latin1() ); | 1082 | ret = addPropValue( o, prop, value.latin1() ); |
1083 | return ret; | 1083 | return ret; |
1084 | } | 1084 | } |
1085 | 1085 | ||
1086 | static inline VObject *safeAddProp( VObject *o, const char *prop) | 1086 | static inline VObject *safeAddProp( VObject *o, const char *prop) |
1087 | { | 1087 | { |
1088 | VObject *ret = 0; | 1088 | VObject *ret = 0; |
1089 | if ( o ) | 1089 | if ( o ) |
1090 | ret = addProp( o, prop ); | 1090 | ret = addProp( o, prop ); |
1091 | return ret; | 1091 | return ret; |
1092 | } | 1092 | } |
1093 | 1093 | ||
1094 | /* | ||
1095 | * Until we support vCal/iCal right | ||
1096 | * we will make DTSTART and other things | ||
1097 | * be floating in the sense of | ||
1098 | * RFC 2445 | ||
1099 | */ | ||
1100 | namespace { | ||
1101 | /* | ||
1102 | * Convert QDateTime to iso8601 but take | ||
1103 | * local time and do not use the Z at the end | ||
1104 | * | ||
1105 | */ | ||
1106 | QCString toISOLocal( const QDateTime& dt ) { | ||
1107 | QCString str; | ||
1108 | /* | ||
1109 | * year month day T Hour Minute Second | ||
1110 | * 4 2 2 2 2 2 digits | ||
1111 | */ | ||
1112 | str.sprintf("%04d%02d%02dT%02d%02d%02d", | ||
1113 | dt.date().year(), | ||
1114 | dt.date().month(), | ||
1115 | dt.date().year(), | ||
1116 | dt.time().hour(), | ||
1117 | dt.time().minute(), | ||
1118 | dt.time().second() ); | ||
1119 | |||
1120 | |||
1121 | |||
1122 | return str; | ||
1123 | } | ||
1124 | |||
1125 | |||
1126 | }; | ||
1127 | |||
1094 | static VObject *createVObject( const Event &e ) | 1128 | static VObject *createVObject( const Event &e ) |
1095 | { | 1129 | { |
1096 | VObject *vcal = newVObject( VCCalProp ); | 1130 | VObject *vcal = newVObject( VCCalProp ); |
1097 | safeAddPropValue( vcal, VCVersionProp, "1.0" ); | 1131 | safeAddPropValue( vcal, VCVersionProp, "1.0" ); |
1098 | VObject *event = safeAddProp( vcal, VCEventProp ); | 1132 | VObject *event = safeAddProp( vcal, VCEventProp ); |
1099 | 1133 | ||
1100 | safeAddPropValue( event, VCDTstartProp, TimeConversion::toISO8601( e.start() ) ); | 1134 | safeAddPropValue( event, VCDTstartProp, TimeConversion::toISO8601( e.start() ) ); |
1101 | safeAddPropValue( event, VCDTendProp, TimeConversion::toISO8601( e.end() ) ); | 1135 | safeAddPropValue( event, VCDTendProp, TimeConversion::toISO8601( e.end() ) ); |
1102 | safeAddPropValue( event, "X-Qtopia-NOTES", e.description() ); | 1136 | safeAddPropValue( event, "X-Qtopia-NOTES", e.description() ); |
1103 | safeAddPropValue( event, VCDescriptionProp, e.description() ); | 1137 | safeAddPropValue( event, VCDescriptionProp, e.description() ); |
1104 | safeAddPropValue( event, VCLocationProp, e.location() ); | 1138 | safeAddPropValue( event, VCLocationProp, e.location() ); |
1105 | 1139 | ||
1106 | if ( e.hasAlarm() ) { | 1140 | if ( e.hasAlarm() ) { |
1107 | VObject *alarm = safeAddProp( event, VCAAlarmProp ); | 1141 | VObject *alarm = safeAddProp( event, VCAAlarmProp ); |
1108 | QDateTime dt = e.start(); | 1142 | QDateTime dt = e.start(); |
1109 | dt = dt.addSecs( -e.alarmTime()*60 ); | 1143 | dt = dt.addSecs( -e.alarmTime()*60 ); |
1110 | safeAddPropValue( alarm, VCRunTimeProp, TimeConversion::toISO8601( dt ) ); | 1144 | safeAddPropValue( alarm, VCRunTimeProp, TimeConversion::toISO8601( dt ) ); |
1111 | safeAddPropValue( alarm, VCAudioContentProp, | 1145 | safeAddPropValue( alarm, VCAudioContentProp, |
1112 | (e.alarmSound() == Event::Silent ? "silent" : "alarm" ) ); | 1146 | (e.alarmSound() == Event::Silent ? "silent" : "alarm" ) ); |
1113 | } | 1147 | } |
1114 | 1148 | ||
1115 | safeAddPropValue( event, "X-Qtopia-TIMEZONE", e.timeZone() ); | 1149 | safeAddPropValue( event, "X-Qtopia-TIMEZONE", e.timeZone() ); |
1116 | 1150 | ||
1117 | if ( e.type() == Event::AllDay ) | 1151 | if ( e.type() == Event::AllDay ) |
1118 | safeAddPropValue( event, "X-Qtopia-AllDay", e.timeZone() ); | 1152 | safeAddPropValue( event, "X-Qtopia-AllDay", e.timeZone() ); |
1119 | 1153 | ||
1120 | // ### repeat missing | 1154 | // ### repeat missing |
1121 | 1155 | ||
1122 | // ### categories missing | 1156 | // ### categories missing |
1123 | 1157 | ||
1124 | return vcal; | 1158 | return vcal; |
1125 | } | 1159 | } |
1126 | 1160 | ||
1127 | 1161 | ||
1128 | static Event parseVObject( VObject *obj ) | 1162 | static Event parseVObject( VObject *obj ) |
1129 | { | 1163 | { |
1130 | Event e; | 1164 | Event e; |
1131 | 1165 | ||
1132 | bool haveAlarm = FALSE; | 1166 | bool haveAlarm = FALSE; |
1133 | bool haveStart = FALSE; | 1167 | bool haveStart = FALSE; |
1134 | bool haveEnd = FALSE; | 1168 | bool haveEnd = FALSE; |
1135 | QDateTime alarmTime; | 1169 | QDateTime alarmTime; |
1136 | Event::SoundTypeChoice soundType = Event::Silent; | 1170 | Event::SoundTypeChoice soundType = Event::Silent; |
1137 | 1171 | ||
1138 | VObjectIterator it; | 1172 | VObjectIterator it; |
1139 | initPropIterator( &it, obj ); | 1173 | initPropIterator( &it, obj ); |
1140 | while( moreIteration( &it ) ) { | 1174 | while( moreIteration( &it ) ) { |
1141 | VObject *o = nextVObject( &it ); | 1175 | VObject *o = nextVObject( &it ); |
1142 | QCString name = vObjectName( o ); | 1176 | QCString name = vObjectName( o ); |
1143 | QCString value = vObjectStringZValue( o ); | 1177 | QCString value = vObjectStringZValue( o ); |
1144 | if ( name == VCDTstartProp ) { | 1178 | if ( name == VCDTstartProp ) { |
1145 | e.setStart( TimeConversion::fromISO8601( value ) ); | 1179 | e.setStart( TimeConversion::fromISO8601( value ) ); |
1146 | haveStart = TRUE; | 1180 | haveStart = TRUE; |
1147 | } | 1181 | } |
1148 | else if ( name == VCDTendProp ) { | 1182 | else if ( name == VCDTendProp ) { |
1149 | e.setEnd( TimeConversion::fromISO8601( value ) ); | 1183 | e.setEnd( TimeConversion::fromISO8601( value ) ); |
1150 | haveEnd = TRUE; | 1184 | haveEnd = TRUE; |
1151 | } | 1185 | } |
1152 | else if ( name == "X-Qtopia-NOTES" ) { | 1186 | else if ( name == "X-Qtopia-NOTES" ) { |
1153 | e.setNotes( value ); | 1187 | e.setNotes( value ); |
1154 | } | 1188 | } |
1155 | else if ( name == VCDescriptionProp ) { | 1189 | else if ( name == VCDescriptionProp ) { |
1156 | e.setDescription( value ); | 1190 | e.setDescription( value ); |
1157 | } | 1191 | } |
1158 | else if ( name == VCLocationProp ) { | 1192 | else if ( name == VCLocationProp ) { |
1159 | e.setLocation( value ); | 1193 | e.setLocation( value ); |
1160 | } | 1194 | } |
1161 | else if ( name == VCAudioContentProp ) { | 1195 | else if ( name == VCAudioContentProp ) { |
1162 | haveAlarm = TRUE; | 1196 | haveAlarm = TRUE; |
1163 | VObjectIterator nit; | 1197 | VObjectIterator nit; |
1164 | initPropIterator( &nit, o ); | 1198 | initPropIterator( &nit, o ); |
1165 | while( moreIteration( &nit ) ) { | 1199 | while( moreIteration( &nit ) ) { |
1166 | VObject *o = nextVObject( &nit ); | 1200 | VObject *o = nextVObject( &nit ); |
1167 | QCString name = vObjectName( o ); | 1201 | QCString name = vObjectName( o ); |
1168 | QCString value = vObjectStringZValue( o ); | 1202 | QCString value = vObjectStringZValue( o ); |
1169 | if ( name == VCRunTimeProp ) | 1203 | if ( name == VCRunTimeProp ) |
1170 | alarmTime = TimeConversion::fromISO8601( value ); | 1204 | alarmTime = TimeConversion::fromISO8601( value ); |
1171 | else if ( name == VCAudioContentProp ) { | 1205 | else if ( name == VCAudioContentProp ) { |
1172 | if ( value == "silent" ) | 1206 | if ( value == "silent" ) |
1173 | soundType = Event::Silent; | 1207 | soundType = Event::Silent; |
1174 | else | 1208 | else |
1175 | soundType = Event::Loud; | 1209 | soundType = Event::Loud; |
1176 | } | 1210 | } |
1177 | } | 1211 | } |
1178 | } | 1212 | } |
1179 | else if ( name == "X-Qtopia-TIMEZONE") { | 1213 | else if ( name == "X-Qtopia-TIMEZONE") { |
1180 | e.setTimeZone( value ); | 1214 | e.setTimeZone( value ); |
1181 | } | 1215 | } |
1182 | else if ( name == "X-Qtopia-AllDay" ) { | 1216 | else if ( name == "X-Qtopia-AllDay" ) { |
1183 | e.setType( Event::AllDay ); | 1217 | e.setType( Event::AllDay ); |
1184 | } | 1218 | } |
1185 | #if 0 | 1219 | #if 0 |
1186 | else { | 1220 | else { |
1187 | printf("Name: %s, value=%s\n", name.data(), vObjectStringZValue( o ) ); | 1221 | printf("Name: %s, value=%s\n", name.data(), vObjectStringZValue( o ) ); |
1188 | VObjectIterator nit; | 1222 | VObjectIterator nit; |
1189 | initPropIterator( &nit, o ); | 1223 | initPropIterator( &nit, o ); |
1190 | while( moreIteration( &nit ) ) { | 1224 | while( moreIteration( &nit ) ) { |
1191 | VObject *o = nextVObject( &nit ); | 1225 | VObject *o = nextVObject( &nit ); |
1192 | QCString name = vObjectName( o ); | 1226 | QCString name = vObjectName( o ); |
1193 | QString value = vObjectStringZValue( o ); | 1227 | QString value = vObjectStringZValue( o ); |
1194 | printf(" subprop: %s = %s\n", name.data(), value.latin1() ); | 1228 | printf(" subprop: %s = %s\n", name.data(), value.latin1() ); |
1195 | } | 1229 | } |
1196 | } | 1230 | } |
1197 | #endif | 1231 | #endif |
1198 | } | 1232 | } |
1199 | 1233 | ||
1200 | if ( !haveStart && !haveEnd ) | 1234 | if ( !haveStart && !haveEnd ) |
1201 | e.setStart( QDateTime::currentDateTime() ); | 1235 | e.setStart( QDateTime::currentDateTime() ); |
1202 | 1236 | ||
1203 | if ( !haveEnd ) { | 1237 | if ( !haveEnd ) { |
1204 | e.setType( Event::AllDay ); | 1238 | e.setType( Event::AllDay ); |
1205 | e.setEnd( e.start() ); | 1239 | e.setEnd( e.start() ); |
1206 | } | 1240 | } |
1207 | 1241 | ||
1208 | if ( haveAlarm ) { | 1242 | if ( haveAlarm ) { |
1209 | int minutes = alarmTime.secsTo( e.start() ) / 60; | 1243 | int minutes = alarmTime.secsTo( e.start() ) / 60; |
1210 | e.setAlarm( TRUE, minutes, soundType ); | 1244 | e.setAlarm( TRUE, minutes, soundType ); |
1211 | } | 1245 | } |
1212 | return e; | 1246 | return e; |
1213 | } | 1247 | } |
1214 | 1248 | ||
1215 | 1249 | ||
1216 | /*! | 1250 | /*! |
1217 | Writes the list of \a events as a set of VCards to the file \a filename. | 1251 | Writes the list of \a events as a set of VCards to the file \a filename. |
1218 | */ | 1252 | */ |
1219 | void Event::writeVCalendar( const QString &filename, const QValueList<Event> &events) | 1253 | void Event::writeVCalendar( const QString &filename, const QValueList<Event> &events) |
1220 | { | 1254 | { |
1221 | 1255 | ||
1222 | QFileDirect f( filename.utf8().data() ); | 1256 | QFileDirect f( filename.utf8().data() ); |
1223 | 1257 | ||
1224 | if ( !f.open( IO_WriteOnly ) ) { | 1258 | if ( !f.open( IO_WriteOnly ) ) { |
1225 | 1259 | ||
1226 | qWarning("Unable to open vcard write"); | 1260 | qWarning("Unable to open vcard write"); |
1227 | 1261 | ||
1228 | return; | 1262 | return; |
1229 | 1263 | ||
1230 | } | 1264 | } |
1231 | 1265 | ||
1232 | 1266 | ||
1233 | QValueList<Event>::ConstIterator it; | 1267 | QValueList<Event>::ConstIterator it; |
1234 | for( it = events.begin(); it != events.end(); ++it ) { | 1268 | for( it = events.begin(); it != events.end(); ++it ) { |
1235 | VObject *obj = createVObject( *it ); | 1269 | VObject *obj = createVObject( *it ); |
1236 | writeVObject( f.directHandle() , obj ); | 1270 | writeVObject( f.directHandle() , obj ); |
1237 | cleanVObject( obj ); | 1271 | cleanVObject( obj ); |
1238 | } | 1272 | } |
1239 | 1273 | ||
1240 | 1274 | ||
1241 | cleanStrTbl(); | 1275 | cleanStrTbl(); |
1242 | } | 1276 | } |
1243 | 1277 | ||
1244 | /*! | 1278 | /*! |
1245 | Writes \a event as a VCard to the file \a filename. | 1279 | Writes \a event as a VCard to the file \a filename. |
1246 | */ | 1280 | */ |
1247 | void Event::writeVCalendar( const QString &filename, const Event &event) | 1281 | void Event::writeVCalendar( const QString &filename, const Event &event) |
1248 | { | 1282 | { |
1249 | 1283 | ||
1250 | QFileDirect f( filename.utf8().data() ); | 1284 | QFileDirect f( filename.utf8().data() ); |
1251 | 1285 | ||
1252 | if ( !f.open( IO_WriteOnly ) ) { | 1286 | if ( !f.open( IO_WriteOnly ) ) { |
1253 | 1287 | ||
1254 | qWarning("Unable to open vcard write"); | 1288 | qWarning("Unable to open vcard write"); |
1255 | 1289 | ||
1256 | return; | 1290 | return; |
1257 | 1291 | ||
1258 | } | 1292 | } |
1259 | 1293 | ||
1260 | 1294 | ||
1261 | VObject *obj = createVObject( event ); | 1295 | VObject *obj = createVObject( event ); |
1262 | writeVObject( f.directHandle() , obj ); | 1296 | writeVObject( f.directHandle() , obj ); |
1263 | cleanVObject( obj ); | 1297 | cleanVObject( obj ); |
1264 | 1298 | ||
1265 | cleanStrTbl(); | 1299 | cleanStrTbl(); |
1266 | } | 1300 | } |
1267 | 1301 | ||
1268 | /*! | 1302 | /*! |
1269 | Returns the set of events read as VCards from the file \a filename. | 1303 | Returns the set of events read as VCards from the file \a filename. |
1270 | */ | 1304 | */ |
1271 | QValueList<Event> Event::readVCalendar( const QString &filename ) | 1305 | QValueList<Event> Event::readVCalendar( const QString &filename ) |
1272 | { | 1306 | { |
1273 | VObject *obj = Parse_MIME_FromFileName( (char *)filename.utf8().data() ); | 1307 | VObject *obj = Parse_MIME_FromFileName( (char *)filename.utf8().data() ); |
1274 | 1308 | ||
1275 | QValueList<Event> events; | 1309 | QValueList<Event> events; |
1276 | 1310 | ||
1277 | while ( obj ) { | 1311 | while ( obj ) { |
1278 | QCString name = vObjectName( obj ); | 1312 | QCString name = vObjectName( obj ); |
1279 | if ( name == VCCalProp ) { | 1313 | if ( name == VCCalProp ) { |
1280 | VObjectIterator nit; | 1314 | VObjectIterator nit; |
1281 | initPropIterator( &nit, obj ); | 1315 | initPropIterator( &nit, obj ); |
1282 | while( moreIteration( &nit ) ) { | 1316 | while( moreIteration( &nit ) ) { |
1283 | VObject *o = nextVObject( &nit ); | 1317 | VObject *o = nextVObject( &nit ); |
1284 | QCString name = vObjectName( o ); | 1318 | QCString name = vObjectName( o ); |
1285 | if ( name == VCEventProp ) | 1319 | if ( name == VCEventProp ) |
1286 | events.append( parseVObject( o ) ); | 1320 | events.append( parseVObject( o ) ); |
1287 | } | 1321 | } |
1288 | } else if ( name == VCEventProp ) { | 1322 | } else if ( name == VCEventProp ) { |
1289 | // shouldn't happen, but just to be sure | 1323 | // shouldn't happen, but just to be sure |
1290 | events.append( parseVObject( obj ) ); | 1324 | events.append( parseVObject( obj ) ); |
1291 | } | 1325 | } |
1292 | VObject *t = obj; | 1326 | VObject *t = obj; |
1293 | obj = nextVObjectInList(obj); | 1327 | obj = nextVObjectInList(obj); |
1294 | cleanVObject( t ); | 1328 | cleanVObject( t ); |
1295 | } | 1329 | } |
1296 | 1330 | ||
1297 | return events; | 1331 | return events; |
1298 | } | 1332 | } |
1299 | 1333 | ||
1300 | bool Event::match( const QRegExp &r ) const | 1334 | bool Event::match( const QRegExp &r ) const |
1301 | { | 1335 | { |
1302 | bool returnMe; | 1336 | bool returnMe; |
1303 | returnMe = false; | 1337 | returnMe = false; |
1304 | 1338 | ||
1305 | if ( descript.find( r ) > -1 ) | 1339 | if ( descript.find( r ) > -1 ) |
1306 | returnMe = true; | 1340 | returnMe = true; |
1307 | else if ( locat.find( r ) > -1 ) | 1341 | else if ( locat.find( r ) > -1 ) |
1308 | returnMe = true; | 1342 | returnMe = true; |
1309 | else if ( TimeConversion::fromUTC( startUTC ).toString().find( r ) > -1 ) | 1343 | else if ( TimeConversion::fromUTC( startUTC ).toString().find( r ) > -1 ) |
1310 | returnMe = true; | 1344 | returnMe = true; |
1311 | else if ( TimeConversion::fromUTC( endUTC ).toString().find( r ) > -1 ) | 1345 | else if ( TimeConversion::fromUTC( endUTC ).toString().find( r ) > -1 ) |
1312 | returnMe = true; | 1346 | returnMe = true; |
1313 | else if ( tz.find( r ) > -1 ) | 1347 | else if ( tz.find( r ) > -1 ) |
1314 | returnMe = true; | 1348 | returnMe = true; |
1315 | else if ( note.find( r ) > -1 ) | 1349 | else if ( note.find( r ) > -1 ) |
1316 | returnMe = true; | 1350 | returnMe = true; |
1317 | else if ( doRepeat() ) { | 1351 | else if ( doRepeat() ) { |
1318 | if ( pattern.hasEndDate ) | 1352 | if ( pattern.hasEndDate ) |
1319 | if ( TimeConversion::fromUTC( pattern.endDateUTC ).toString().find(r) > -1 ) | 1353 | if ( TimeConversion::fromUTC( pattern.endDateUTC ).toString().find(r) > -1 ) |
1320 | returnMe = true; | 1354 | returnMe = true; |
1321 | } | 1355 | } |
1322 | return returnMe; | 1356 | return returnMe; |
1323 | } | 1357 | } |