Skip to content

Commit

Permalink
(feat) handle alarms for tasks (fixes #3964)
Browse files Browse the repository at this point in the history
  • Loading branch information
extrafu committed Dec 21, 2016
1 parent 4221b6d commit 73309f9
Show file tree
Hide file tree
Showing 2 changed files with 73 additions and 31 deletions.
76 changes: 48 additions & 28 deletions ActiveSync/iCalAlarm+ActiveSync.m
Expand Up @@ -39,6 +39,9 @@
#import <NGCards/iCalAlarm.h>
#import <NGCards/iCalEvent.h>
#import <NGCards/iCalTrigger.h>
#import <NGCards/NSCalendarDate+NGCards.h>

#include "NSDate+ActiveSync.h"

@implementation iCalAlarm (ActiveSync)

Expand All @@ -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: @"<Reminder xmlns=\"Calendar:\">%d</Reminder>", (int)delta];
if ([parent isKindOfClass: [iCalEvent class]])
{
// don't send negative reminder - not supported
if (delta > 0)
[s appendFormat: @"<Reminder xmlns=\"Calendar:\">%d</Reminder>", (int)delta];
}
else
{
[s appendFormat: @"<ReminderTime xmlns=\"Task:\">%@</ReminderTime>", [nextAlarmDate activeSyncRepresentationInContext: context]];
}
}

return s;
Expand All @@ -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
28 changes: 25 additions & 3 deletions ActiveSync/iCalToDo+ActiveSync.m
Expand Up @@ -47,9 +47,12 @@
#import <NGCards/iCalDateTime.h>
#import <NGCards/iCalTimeZone.h>

#import <Appointments/iCalEntityObject+SOGo.h>

#include "NSDate+ActiveSync.h"
#include "NSString+ActiveSync.h"
#include "iCalRecurrenceRule+ActiveSync.h"
#include "iCalAlarm+ActiveSync.h"

@implementation iCalToDo (ActiveSync)

Expand Down Expand Up @@ -99,8 +102,19 @@ - (NSString *) activeSyncRepresentationInContext: (WOContext *) context
v = 1;
[s appendFormat: @"<Importance xmlns=\"Tasks:\">%d</Importance>", v];

// Reminder - FIXME
[s appendFormat: @"<ReminderSet xmlns=\"Tasks:\">%d</ReminderSet>", 0];
// Reminder
if ([self hasAlarms])
{
iCalAlarm *alarm;

alarm = [self firstDisplayOrAudioAlarm];
[s appendFormat: @"<ReminderSet xmlns=\"Tasks:\">%d</ReminderSet>", 1];
[s appendString: [alarm activeSyncRepresentationInContext: context]];
}
else
{
[s appendFormat: @"<ReminderSet xmlns=\"Tasks:\">%d</ReminderSet>", 0];
}

// Sensitivity
if ([[self accessClass] isEqualToString: @"PRIVATE"])
Expand Down Expand Up @@ -149,7 +163,7 @@ - (NSString *) activeSyncRepresentationInContext: (WOContext *) context
[s appendString: @"</Body>"];
}
}

return s;
}

Expand Down Expand Up @@ -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);

}

Expand Down

0 comments on commit 73309f9

Please sign in to comment.