diff --git a/ActiveSync/iCalAlarm+ActiveSync.m b/ActiveSync/iCalAlarm+ActiveSync.m index 62a3ad146b..bb843ce63b 100644 --- a/ActiveSync/iCalAlarm+ActiveSync.m +++ b/ActiveSync/iCalAlarm+ActiveSync.m @@ -39,6 +39,9 @@ #import #import #import +#import + +#include "NSDate+ActiveSync.h" @implementation iCalAlarm (ActiveSync) @@ -56,9 +59,16 @@ - (NSString *) activeSyncRepresentationInContext: (WOContext *) context nextAlarmDate = [self nextAlarmDate]; delta = (int)(([[(iCalEvent *)parent startDate] timeIntervalSince1970] - [nextAlarmDate timeIntervalSince1970])/60); - // don't send negative reminder - not supported - if (delta > 0) - [s appendFormat: @"%d", (int)delta]; + if ([parent isKindOfClass: [iCalEvent class]]) + { + // don't send negative reminder - not supported + if (delta > 0) + [s appendFormat: @"%d", (int)delta]; + } + else + { + [s appendFormat: @"%@", [nextAlarmDate activeSyncRepresentationInContext: context]]; + } } return s; @@ -70,37 +80,47 @@ - (void) takeActiveSyncValues: (NSDictionary *) theValues iCalTrigger *trigger; id o; - o = [theValues objectForKey: @"Reminder"]; - - // Outlook: if reminder is set to 0 minutes before start save it as 1 minute since -> 0 minutes in not accepted by SOGo - if ([o isEqualToString: @"0"]) - o = @"1"; - - trigger = [iCalTrigger elementWithTag: @"TRIGGER"]; - [trigger setValueType: @"DURATION"]; - [self setTrigger: trigger]; - [self setAction: @"DISPLAY"]; - - // SOGo web ui only supports 1w but not 2w (custom reminder only supports min/hours/days) - // 1week = -P1W - // 2weeks > -PxD - // xdays > -PxD - // xhours -> -PTxH - // xmin -> -PTxM - if ([o intValue] == 10080) - [trigger setSingleValue: [NSString stringWithFormat: @"-P1W" ] forKey: @""]; - else + if ((o = [theValues objectForKey: @"Reminder"])) { - if (([o intValue] % 1440) == 0) - [trigger setSingleValue: [NSString stringWithFormat: @"-P%dD", ([o intValue] / 1440)] forKey: @""]; + // Outlook: if reminder is set to 0 minutes before starttime, save it as 1 minute since -> 0 minutes in not accepted by SOGo + if ([o isEqualToString: @"0"]) + o = @"1"; + + trigger = [iCalTrigger elementWithTag: @"TRIGGER"]; + [trigger setValueType: @"DURATION"]; + [self setTrigger: trigger]; + [self setAction: @"DISPLAY"]; + + // SOGo web ui only supports 1w but not 2w (custom reminder only supports min/hours/days) + // 1week = -P1W + // 2weeks > -PxD + // xdays > -PxD + // xhours -> -PTxH + // xmin -> -PTxM + if ([o intValue] == 10080) + [trigger setSingleValue: [NSString stringWithFormat: @"-P1W" ] forKey: @""]; else { - if (([o intValue] % 60) == 0) - [trigger setSingleValue: [NSString stringWithFormat: @"-PT%dH", ([o intValue] / 60)] forKey: @""]; + if (([o intValue] % 1440) == 0) + [trigger setSingleValue: [NSString stringWithFormat: @"-P%dD", ([o intValue] / 1440)] forKey: @""]; else - [trigger setSingleValue: [NSString stringWithFormat: @"-PT%@M", o] forKey: @""]; + { + if (([o intValue] % 60) == 0) + [trigger setSingleValue: [NSString stringWithFormat: @"-PT%dH", ([o intValue] / 60)] forKey: @""]; + else + [trigger setSingleValue: [NSString stringWithFormat: @"-PT%@M", o] forKey: @""]; + } } } + else if ((o = [theValues objectForKey: @"ReminderTime"])) + { + o = [o calendarDate]; + trigger = [iCalTrigger elementWithTag: @"TRIGGER"]; + [trigger setValueType: @"DATE-TIME"]; + [trigger setSingleValue: [NSString stringWithFormat: @"%@Z", [o iCalFormattedDateTimeString]] forKey: @""]; + [self setTrigger: trigger]; + [self setAction: @"DISPLAY"]; + } } @end diff --git a/ActiveSync/iCalToDo+ActiveSync.m b/ActiveSync/iCalToDo+ActiveSync.m index bff24c48a7..6c550fec99 100644 --- a/ActiveSync/iCalToDo+ActiveSync.m +++ b/ActiveSync/iCalToDo+ActiveSync.m @@ -47,9 +47,12 @@ #import #import +#import + #include "NSDate+ActiveSync.h" #include "NSString+ActiveSync.h" #include "iCalRecurrenceRule+ActiveSync.h" +#include "iCalAlarm+ActiveSync.h" @implementation iCalToDo (ActiveSync) @@ -99,8 +102,19 @@ - (NSString *) activeSyncRepresentationInContext: (WOContext *) context v = 1; [s appendFormat: @"%d", v]; - // Reminder - FIXME - [s appendFormat: @"%d", 0]; + // Reminder + if ([self hasAlarms]) + { + iCalAlarm *alarm; + + alarm = [self firstDisplayOrAudioAlarm]; + [s appendFormat: @"%d", 1]; + [s appendString: [alarm activeSyncRepresentationInContext: context]]; + } + else + { + [s appendFormat: @"%d", 0]; + } // Sensitivity if ([[self accessClass] isEqualToString: @"PRIVATE"]) @@ -149,7 +163,7 @@ - (NSString *) activeSyncRepresentationInContext: (WOContext *) context [s appendString: @""]; } } - + return s; } @@ -253,6 +267,14 @@ - (void) takeActiveSyncValues: (NSDictionary *) theValues if ((o = [theValues objectForKey: @"ReminderTime"])) { + iCalAlarm *alarm; + + alarm = [[iCalAlarm alloc] init]; + [alarm takeActiveSyncValues: theValues inContext: context]; + + [self removeAllAlarms]; + [self addToAlarms: alarm]; + RELEASE(alarm); }