From 137e8e7290e61f5b45193f8cfc24eca585dd2c5c Mon Sep 17 00:00:00 2001 From: Francis Lachapelle Date: Wed, 21 Jan 2015 14:46:36 -0500 Subject: [PATCH] Add [iCal(Repeatable)EntityObject attribtues] Those methods are used to get the common attributes of a iCalendar component (vEvent or vTodo). --- .../Appointments/iCalEntityObject+SOGo.h | 2 + .../Appointments/iCalEntityObject+SOGo.m | 141 +++++++++++++++++- .../iCalRepeatableEntityObject+SOGo.h | 2 +- .../iCalRepeatableEntityObject+SOGo.m | 42 +++++- 4 files changed, 184 insertions(+), 3 deletions(-) diff --git a/SoObjects/Appointments/iCalEntityObject+SOGo.h b/SoObjects/Appointments/iCalEntityObject+SOGo.h index 56e982137..9ea2348cf 100644 --- a/SoObjects/Appointments/iCalEntityObject+SOGo.h +++ b/SoObjects/Appointments/iCalEntityObject+SOGo.h @@ -34,6 +34,8 @@ extern NSNumber *iCalDistantFutureNumber; + (void) initializeSOGoExtensions; +- (NSDictionary *) attributes; + - (BOOL) userIsAttendee: (SOGoUser *) user; - (BOOL) userIsOrganizer: (SOGoUser *) user; diff --git a/SoObjects/Appointments/iCalEntityObject+SOGo.m b/SoObjects/Appointments/iCalEntityObject+SOGo.m index 48ba026c3..a150adead 100644 --- a/SoObjects/Appointments/iCalEntityObject+SOGo.m +++ b/SoObjects/Appointments/iCalEntityObject+SOGo.m @@ -1,6 +1,6 @@ /* iCalEntityObject+SOGo.m - this file is part of SOGo * - * Copyright (C) 2007-2014 Inverse inc. + * Copyright (C) 2007-2015 Inverse inc. * * This file is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -20,16 +20,20 @@ #import #import +#import #import #import #import #import +#import #import #import #import #import +#import #import +#import #import #import @@ -63,6 +67,141 @@ NSNumber *iCalDistantFutureNumber = nil; } } +/** + * @see [UIxAppointmentEditor viewAction] + */ +- (NSDictionary *) attributes +{ + NSArray *elements; + NSMutableArray *attendees, *categories; + NSDictionary *organizerData; + NSMutableDictionary *data, *attendeeData, *alarmData; + NSEnumerator *attendeesList; + iCalPerson *organizer, *currentAttendee; + iCalAlarm *alarm; + iCalTrigger *trigger; + id value; + unsigned int i, max; + + data = [NSMutableDictionary dictionaryWithObjectsAndKeys: + [[self tag] lowercaseString], @"component", + [self summary], @"summary", + [self priority], @"priority", + nil]; + + value = [self location]; + if (value) [data setObject: value forKey: @"location"]; + if ([self comment]) [data setObject: [self comment] forKey: @"comment"]; + if ([self attach]) [data setObject: [[self attach] absoluteString] forKey: @"attachUrl"]; + if ([self accessClass]) [data setObject: [self accessClass] forKey: @"classification"]; + if ([self status]) [data setObject: [self status] forKey: @"status"]; + if ([self createdBy]) [data setObject: [self createdBy] forKey: @"createdBy"]; + + // Categories + elements = [self childrenWithTag: @"categories"]; + max = [elements count]; + if (max > 0) + { + categories = [NSMutableArray arrayWithCapacity: max]; + for (i = 0; i < max; i++) + { + [categories addObject: [[elements objectAtIndex: i] flattenedValuesForKey: @""]]; + } + [data setObject: categories forKey: @"categories"]; + } + + // Send appointment notifications + value = [self firstChildWithTag: @"X-SOGo-Send-Appointment-Notifications"]; + [data setObject: [NSNumber numberWithBool: (value? 1:0)] forKey: @"sendAppointmentNotifications"]; + + // Organizer + organizer = [self organizer]; + if (organizer) + { + organizerData = [NSDictionary dictionaryWithObjectsAndKeys: + [organizer rfc822Email], @"email", + [organizer cnWithoutQuotes], @"name", + nil]; + [data setObject: organizerData forKey: @"organizer"]; + } + + + // Attendees + attendees = [NSMutableArray array]; + attendeesList = [[self attendees] objectEnumerator]; + while ((currentAttendee = [attendeesList nextObject])) + { + attendeeData = [NSMutableDictionary dictionaryWithObjectsAndKeys: + [currentAttendee rfc822Email], @"email", + [currentAttendee cnWithoutQuotes], @"name", + nil]; + if ([currentAttendee uid]) [attendeeData setObject: [currentAttendee uid] forKey: @"uid"]; + // TODO: restore support for MS Exchange + // uid = [um getUIDForEmail: [currentAttendee rfc822Email]]; + // if (uid != nil) + // [currentAttendeeData setObject: uid + // forKey: @"uid"]; + // else + // { + // domain = [[context activeUser] domain]; + // contacts = [um fetchContactsMatching: [currentAttendee rfc822Email] inDomain: domain]; + // if ([contacts count] == 1) + // { + // contact = [contacts lastObject]; + // source = [contact objectForKey: @"source"]; + // if ([source conformsToProtocol: @protocol (SOGoDNSource)] && + // [[(NSObject *) source MSExchangeHostname] length]) + // { + // uid = [NSString stringWithFormat: @"%@:%@", [[context activeUser] login], + // [contact valueForKey: @"c_uid"]]; + // [currentAttendeeData setObject: uid forKey: @"uid"]; + // } + // } + // } + [attendeeData setObject: [[currentAttendee partStat] lowercaseString] forKey: @"status"]; + [attendeeData setObject: [[currentAttendee role] lowercaseString] forKey: @"role"]; + if ([[currentAttendee delegatedTo] length]) + [attendeeData setObject: [[currentAttendee delegatedTo] rfc822Email] forKey: @"delegatedTo"]; + if ([[currentAttendee delegatedFrom] length]) + [attendeeData setObject: [[currentAttendee delegatedFrom] rfc822Email] forKey: @"delegatedFrom"]; + + [attendees addObject: attendeeData]; + } + if ([attendees count]) + [data setObject: attendees forKey: @"attendees"]; + + // Alarm + if ([self hasAlarms]) + { + alarm = [self firstSupportedAlarm]; // only consider the first alarm with a supported action + trigger = [alarm trigger]; + if (![[trigger valueType] length] || [[trigger valueType] caseInsensitiveCompare: @"DURATION"] == NSOrderedSame) + { + alarmData = [NSMutableDictionary dictionaryWithObjectsAndKeys: + [[alarm action] lowercaseString], @"action", + nil]; + [alarmData addEntriesFromDictionary: [trigger asDictionary]]; + attendees = [NSMutableArray array]; + attendeesList = [[alarm attendees] objectEnumerator]; + while ((currentAttendee = [attendeesList nextObject])) + { + attendeeData = [NSMutableDictionary dictionaryWithObjectsAndKeys: + [currentAttendee rfc822Email], @"email", + [currentAttendee cnWithoutQuotes], @"name", + nil]; + if ([currentAttendee uid]) [attendeeData setObject: [currentAttendee uid] forKey: @"uid"]; + [attendees addObject: attendeeData]; + } + if ([attendees count]) + [alarmData setObject: attendees forKey: @"attendees"]; + + [data setObject: alarmData forKey: @"alarm"]; + } + } + + return data; +} + - (BOOL) userIsAttendee: (SOGoUser *) user { NSEnumerator *attendees; diff --git a/SoObjects/Appointments/iCalRepeatableEntityObject+SOGo.h b/SoObjects/Appointments/iCalRepeatableEntityObject+SOGo.h index 2a2efd427..32f867414 100644 --- a/SoObjects/Appointments/iCalRepeatableEntityObject+SOGo.h +++ b/SoObjects/Appointments/iCalRepeatableEntityObject+SOGo.h @@ -1,6 +1,6 @@ /* iCalRepeatableEntityObject+SOGo.h - this file is part of SOGo * - * Copyright (C) 2007-2014 Inverse inc. + * Copyright (C) 2007-2015 Inverse inc. * * This file is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by diff --git a/SoObjects/Appointments/iCalRepeatableEntityObject+SOGo.m b/SoObjects/Appointments/iCalRepeatableEntityObject+SOGo.m index c9f66a6b1..69d558bb5 100644 --- a/SoObjects/Appointments/iCalRepeatableEntityObject+SOGo.m +++ b/SoObjects/Appointments/iCalRepeatableEntityObject+SOGo.m @@ -1,6 +1,6 @@ /* iCalRepeatableEntityObject+SOGo.m - this file is part of SOGo * - * Copyright (C) 2007-2014 Inverse inc. + * Copyright (C) 2007-2015 Inverse inc. * * This file is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -25,8 +25,10 @@ #import #import +#import #import #import +#import #import #import #import @@ -69,6 +71,44 @@ return ma; } +/** + * @see [iCalEntityObject+SOGo attributes] + * @see [UIxAppointmentEditor viewAction] + */ +- (NSDictionary *) attributes +{ + NSMutableDictionary *data, *repeat; + NSArray *rules; + NSString *frequency; + iCalRecurrenceRule *rule; + + data = [NSMutableDictionary dictionaryWithDictionary: [super attributes]]; + + rules = [self recurrenceRules]; + if ([rules count] > 0) + { + rule = [rules objectAtIndex: 0]; + frequency = [rule frequencyForValue: [rule frequency]]; + + repeat = [NSMutableDictionary dictionary]; + [repeat setObject: [frequency lowercaseString] forKey: @"frequency"]; + [repeat setObject: [NSNumber numberWithInt: [rule repeatInterval]] forKey: @"interval"]; + if ([rule repeatCount]) + [repeat setObject: [NSNumber numberWithInt: [rule repeatCount]] forKey: @"count"]; + if ([rule untilDate]) + [repeat setObject: [NSNumber numberWithUnsignedInt: [[rule untilDate] timeIntervalSince1970]] forKey: @"until"]; + if ([[rule byDay] length]) + [repeat setObject: [[rule byDayMask] asRuleArray] forKey: @"days"]; + if ([[rule byMonthDay] count]) + [repeat setObject: [rule byMonthDay] forKey: @"monthdays"]; + if ([[rule byMonth] count]) + [repeat setObject: [rule byMonth] forKey: @"months"]; + [data setObject: repeat forKey: @"repeat"]; + } + + return data; +} + - (NSString *) cycleInfo { NSArray *rules;