-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 | |||
@@ -1046,96 +1046,130 @@ QDate EffectiveEvent::startDate() const | |||
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 ); |