From 82f3f1b3d939d1e54f86c032dfa1ad63c624a770 Mon Sep 17 00:00:00 2001 From: Wolfgang Sourdeau Date: Fri, 13 Jul 2012 20:31:41 +0000 Subject: [PATCH] Monotone-Parent: 9475f39d99549bfa74e7f88be7e54d9650beb0d5 Monotone-Revision: d953e1b8cae8bcdf2a3cff4219ea365af8391941 Monotone-Author: wsourdeau@inverse.ca Monotone-Date: 2012-07-13T20:31:41 --- ChangeLog | 8 ++ SoObjects/Appointments/GNUmakefile | 1 + .../Appointments/SOGoAppointmentObject.m | 13 ++- .../Appointments/SOGoCalendarComponent.h | 3 +- .../Appointments/SOGoCalendarComponent.m | 42 +--------- SoObjects/Appointments/SOGoTaskObject.m | 6 ++ SoObjects/Appointments/iCalCalendar+SOGo.h | 39 +++++++++ SoObjects/Appointments/iCalCalendar+SOGo.m | 82 +++++++++++++++++++ 8 files changed, 152 insertions(+), 42 deletions(-) create mode 100644 SoObjects/Appointments/iCalCalendar+SOGo.h create mode 100644 SoObjects/Appointments/iCalCalendar+SOGo.m diff --git a/ChangeLog b/ChangeLog index baa404e10..24061285d 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,5 +1,13 @@ 2012-07-13 Wolfgang Sourdeau + * SoObjects/Appointments/SOGoCalendarComponent.m + (-lookupOccurrence:): now a virtual method forcing the use by + subclasses of the new methods below. + + * SoObjects/Appointments/iCalCalendar+SOGo.m: new category module. + (-eventWithRecurrenceId, -todoWithRecurrenceId): new method that + return as recurrence based on the id passed as parameter. + * Tests/Integration/test-caldav-scheduling.py (CalDAVSchedulingTest.setUp): use the proper password for attendee1_delegate. diff --git a/SoObjects/Appointments/GNUmakefile b/SoObjects/Appointments/GNUmakefile index 46f79d469..c9b03f199 100644 --- a/SoObjects/Appointments/GNUmakefile +++ b/SoObjects/Appointments/GNUmakefile @@ -9,6 +9,7 @@ Appointments_PRINCIPAL_CLASS = SOGoAppointmentsProduct Appointments_OBJC_FILES = \ Product.m \ NSArray+Appointments.m \ + iCalCalendar+SOGo.m \ iCalEntityObject+SOGo.m \ iCalRepeatableEntityObject+SOGo.m \ iCalEvent+SOGo.m \ diff --git a/SoObjects/Appointments/SOGoAppointmentObject.m b/SoObjects/Appointments/SOGoAppointmentObject.m index eaa03b11b..30e4b44f7 100644 --- a/SoObjects/Appointments/SOGoAppointmentObject.m +++ b/SoObjects/Appointments/SOGoAppointmentObject.m @@ -53,6 +53,7 @@ #import #import +#import "iCalCalendar+SOGo.h" #import "iCalEventChanges+SOGo.h" #import "iCalEntityObject+SOGo.h" #import "iCalPerson+SOGo.h" @@ -121,6 +122,12 @@ return newOccurence; } +- (iCalRepeatableEntityObject *) lookupOccurrence: (NSString *) recID + +{ + return [[self calendar: NO secure: NO] eventWithRecurrenceID: recID]; +} + - (SOGoAppointmentObject *) _lookupEvent: (NSString *) eventUID forUID: (NSString *) uid { @@ -839,7 +846,7 @@ inRecurrenceExceptionsForEvent: (iCalEvent *) theEvent // If recurrenceId is defined, find the specified occurence // within the repeating vEvent. recurrenceTime = [NSString stringWithFormat: @"%f", [recurrenceId timeIntervalSince1970]]; - oldEvent = (iCalEvent*)[self lookupOccurence: recurrenceTime]; + oldEvent = (iCalEvent*)[self lookupOccurrence: recurrenceTime]; if (oldEvent == nil) // If no occurence found, create one oldEvent = (iCalEvent *)[self newOccurenceWithID: recurrenceTime]; @@ -906,7 +913,7 @@ inRecurrenceExceptionsForEvent: (iCalEvent *) theEvent // If recurrenceId is defined, find the specified occurence // within the repeating vEvent. recurrenceTime = [NSString stringWithFormat: @"%f", [recurrenceId timeIntervalSince1970]]; - event = [eventObject lookupOccurence: recurrenceTime]; + event = [eventObject lookupOccurrence: recurrenceTime]; if (event == nil) // If no occurence found, create one @@ -1348,7 +1355,7 @@ inRecurrenceExceptionsForEvent: (iCalEvent *) theEvent // If _recurrenceId is defined, find the specified occurence // within the repeating vEvent. recurrenceTime = [NSString stringWithFormat: @"%f", [_recurrenceId timeIntervalSince1970]]; - event = (iCalEvent*)[self lookupOccurence: recurrenceTime]; + event = (iCalEvent*)[self lookupOccurrence: recurrenceTime]; if (event == nil) // If no occurence found, create one diff --git a/SoObjects/Appointments/SOGoCalendarComponent.h b/SoObjects/Appointments/SOGoCalendarComponent.h index d334e7c57..fc111f5a6 100644 --- a/SoObjects/Appointments/SOGoCalendarComponent.h +++ b/SoObjects/Appointments/SOGoCalendarComponent.h @@ -86,7 +86,8 @@ - (NSArray *) getUIDsForICalPersons: (NSArray *) iCalPersons; /* recurrences */ -- (iCalRepeatableEntityObject *) lookupOccurence: (NSString *) recID; +/* same as above, but refers to the existing calendar component */ +- (iCalRepeatableEntityObject *) lookupOccurrence: (NSString *) recID; - (SOGoComponentOccurence *) occurence: (iCalRepeatableEntityObject *) component; - (iCalRepeatableEntityObject *) newOccurenceWithID: (NSString *) recID; diff --git a/SoObjects/Appointments/SOGoCalendarComponent.m b/SoObjects/Appointments/SOGoCalendarComponent.m index 1385cbe9c..eb25f9876 100644 --- a/SoObjects/Appointments/SOGoCalendarComponent.m +++ b/SoObjects/Appointments/SOGoCalendarComponent.m @@ -269,45 +269,11 @@ return iCalString; } -static inline BOOL _occurenceHasID (iCalRepeatableEntityObject *occurence, - NSString *recID) +- (iCalRepeatableEntityObject *) lookupOccurrence: (NSString *) recID { - unsigned int seconds, recSeconds; - - seconds = [recID intValue]; - recSeconds = [[occurence recurrenceId] timeIntervalSince1970]; + [self subclassResponsibility: _cmd]; - return (seconds == recSeconds); -} - -- (iCalRepeatableEntityObject *) lookupOccurence: (NSString *) recID -{ - iCalRepeatableEntityObject *component, *occurence, *currentOccurence; - NSArray *occurences; - unsigned int count, max; - - occurence = nil; - - component = [self component: NO secure: NO]; - if ([component hasRecurrenceRules]) - { - occurences = [[self calendar: NO secure: NO] allObjects]; - max = [occurences count]; - count = 1; // skip master event - while (!occurence && count < max) - { - currentOccurence = [occurences objectAtIndex: count]; - if (_occurenceHasID (currentOccurence, recID)) - occurence = currentOccurence; - else - count++; - } - } - else if (_occurenceHasID (component, recID)) - /* The "master" event could be that occurrence. */ - occurence = component; - - return occurence; + return nil; } - (SOGoComponentOccurence *) occurence: (iCalRepeatableEntityObject *) component @@ -397,7 +363,7 @@ static inline BOOL _occurenceHasID (iCalRepeatableEntityObject *occurence, else if ([lookupName hasPrefix: @"occurence"]) { recID = [lookupName substringFromIndex: 9]; - occurence = [self lookupOccurence: recID]; + occurence = [self lookupOccurrence: recID]; if (occurence) isNewOccurence = NO; else diff --git a/SoObjects/Appointments/SOGoTaskObject.m b/SoObjects/Appointments/SOGoTaskObject.m index 398db5119..5d70dabd0 100644 --- a/SoObjects/Appointments/SOGoTaskObject.m +++ b/SoObjects/Appointments/SOGoTaskObject.m @@ -32,6 +32,7 @@ #import +#import "iCalCalendar+SOGo.h" #import "NSArray+Appointments.h" #import "SOGoAptMailNotification.h" #import "SOGoAppointmentFolder.h" @@ -46,6 +47,11 @@ return @"vtodo"; } +- (iCalRepeatableEntityObject *) lookupOccurrence: (NSString *) recID +{ + return [[self calendar: NO secure: NO] todoWithRecurrenceID: recID]; +} + - (SOGoComponentOccurence *) occurence: (iCalRepeatableEntityObject *) occ { NSArray *allTodos; diff --git a/SoObjects/Appointments/iCalCalendar+SOGo.h b/SoObjects/Appointments/iCalCalendar+SOGo.h new file mode 100644 index 000000000..eae3f8175 --- /dev/null +++ b/SoObjects/Appointments/iCalCalendar+SOGo.h @@ -0,0 +1,39 @@ +/* iCalCalendar+SOGo.h - this file is part of SOGo + * + * Copyright (C) 2012 Inverse inc + * + * Author: Wolfgang Sourdeau + * + * 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 + * the Free Software Foundation; either version 2, or (at your option) + * any later version. + * + * This file is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; see the file COPYING. If not, write to + * the Free Software Foundation, Inc., 59 Temple Place - Suite 330, + * Boston, MA 02111-1307, USA. + */ + +#ifndef ICALCALENDAR_SOGO_H +#define ICALCALENDAR_SOGO_H + +#import + +@class NSString; +@class iCalEvent; +@class iCalToDo; + +@interface iCalCalendar (SOGoExtensions) + +- (iCalEvent *) eventWithRecurrenceID: (NSString *) recID; +- (iCalToDo *) todoWithRecurrenceID: (NSString *) recID; + +@end + +#endif /* ICALCALENDAR_SOGO_H */ diff --git a/SoObjects/Appointments/iCalCalendar+SOGo.m b/SoObjects/Appointments/iCalCalendar+SOGo.m new file mode 100644 index 000000000..d50d30c1d --- /dev/null +++ b/SoObjects/Appointments/iCalCalendar+SOGo.m @@ -0,0 +1,82 @@ +/* iCalCalendar+SOGo.m - this file is part of $PROJECT_NAME_HERE$ + * + * Copyright (C) 2012 Inverse inc + * + * Author: Wolfgang Sourdeau + * + * 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 + * the Free Software Foundation; either version 2, or (at your option) + * any later version. + * + * This file is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; see the file COPYING. If not, write to + * the Free Software Foundation, Inc., 59 Temple Place - Suite 330, + * Boston, MA 02111-1307, USA. + */ + +#import +#import + +#import + +#import "iCalCalendar+SOGo.h" + +@implementation iCalCalendar (SOGoExtensions) + +- (id) _occurrence: (NSString *) recID + inArray: (NSArray *) components +{ + id occurrence; + iCalRepeatableEntityObject *component; + NSUInteger count, max, seconds, recSeconds; + + occurrence = nil; + + seconds = [recID intValue]; + + max = [components count]; + + /* master occurrence */ + component = [components objectAtIndex: 0]; + + if ([component hasRecurrenceRules]) + { + count = 1; // skip master event + while (!occurrence && count < max) + { + component = [components objectAtIndex: count]; + recSeconds = [[component recurrenceId] timeIntervalSince1970]; + if (recSeconds == seconds) + occurrence = component; + else + count++; + } + } + else + { + /* The "master" event could be that occurrence. */ + recSeconds = [[component recurrenceId] timeIntervalSince1970]; + if (recSeconds == seconds) + occurrence = component; + } + + return occurrence; +} + +- (iCalEvent *) eventWithRecurrenceID: (NSString *) recID +{ + return [self _occurrence: recID inArray: [self events]]; +} + +- (iCalToDo *) todoWithRecurrenceID: (NSString *) recID; +{ + return [self _occurrence: recID inArray: [self todos]]; +} + +@end