From 5c0229466e35faab0d3abce7e134baf1c06cb070 Mon Sep 17 00:00:00 2001 From: Ludovic Marcotte Date: Wed, 21 Dec 2016 08:49:05 -0500 Subject: [PATCH] (feat) handle alarms for tasks (fixes #3964) --- ActiveSync/iCalAlarm+ActiveSync.m | 76 +++++++++++++++++++------------ ActiveSync/iCalToDo+ActiveSync.m | 28 ++++++++++-- 2 files changed, 73 insertions(+), 31 deletions(-) diff --git a/ActiveSync/iCalAlarm+ActiveSync.m b/ActiveSync/iCalAlarm+ActiveSync.m index aac4be116..f50ec5572 100644 --- a/ActiveSync/iCalAlarm+ActiveSync.m +++ b/ActiveSync/iCalAlarm+ActiveSync.m @@ -36,6 +36,9 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. #import #import #import +#import + +#include "NSDate+ActiveSync.h" @implementation iCalAlarm (ActiveSync) @@ -53,9 +56,16 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 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; @@ -67,37 +77,47 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 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 41269802d..44e9b6263 100644 --- a/ActiveSync/iCalToDo+ActiveSync.m +++ b/ActiveSync/iCalToDo+ActiveSync.m @@ -43,9 +43,12 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. #import #import +#import + #include "NSDate+ActiveSync.h" #include "NSString+ActiveSync.h" #include "iCalRecurrenceRule+ActiveSync.h" +#include "iCalAlarm+ActiveSync.h" @implementation iCalToDo (ActiveSync) @@ -95,8 +98,19 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 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"]) @@ -145,7 +159,7 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. [s appendString: @""]; } } - + return s; } @@ -249,6 +263,14 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. if ((o = [theValues objectForKey: @"ReminderTime"])) { + iCalAlarm *alarm; + + alarm = [[iCalAlarm alloc] init]; + [alarm takeActiveSyncValues: theValues inContext: context]; + + [self removeAllAlarms]; + [self addToAlarms: alarm]; + RELEASE(alarm); }