2 Copyright (C) 2004-2005 SKYRIX Software AG
4 This file is part of SOPE.
6 SOPE is free software; you can redistribute it and/or modify it under
7 the terms of the GNU Lesser General Public License as published by the
8 Free Software Foundation; either version 2, or (at your option) any
11 SOPE is distributed in the hope that it will be useful, but WITHOUT ANY
12 WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
14 License for more details.
16 You should have received a copy of the GNU Lesser General Public
17 License along with SOPE; see the file COPYING. If not, write to the
18 Free Software Foundation, 59 Temple Place - Suite 330, Boston, MA
23 #include "iCalEventChanges.h"
24 #include "iCalEvent.h"
25 #include "iCalPerson.h"
28 @interface iCalEventChanges (PrivateAPI)
29 - (void)_trackAttendeeChanges:(iCalEvent *)_from :(iCalEvent *)_to;
30 - (void)_trackAlarmChanges:(iCalEvent *)_from :(iCalEvent *)_to;
31 - (void)_trackPropertyChanges:(iCalEvent *)_from :(iCalEvent *)_to;
34 @implementation iCalEventChanges
36 + (id)changesFromEvent:(iCalEvent *)_from toEvent:(iCalEvent *)_to {
37 return [[[self alloc] initWithFromEvent:_from toEvent:_to] autorelease];
40 - (id)initWithFromEvent:(iCalEvent *)_from toEvent:(iCalEvent *)_to {
43 self->insertedAttendees = [[NSMutableArray alloc] init];
44 self->deletedAttendees = [[NSMutableArray alloc] init];
45 self->updatedAttendees = [[NSMutableArray alloc] init];
46 self->insertedAlarms = [[NSMutableArray alloc] init];
47 self->deletedAlarms = [[NSMutableArray alloc] init];
48 self->updatedAlarms = [[NSMutableArray alloc] init];
49 self->updatedProperties = [[NSMutableArray alloc] init];
50 [self _trackAttendeeChanges:_from :_to];
51 [self _trackPropertyChanges:_from :_to];
57 [self->insertedAttendees release];
58 [self->deletedAttendees release];
59 [self->updatedAttendees release];
60 [self->insertedAlarms release];
61 [self->deletedAlarms release];
62 [self->updatedAlarms release];
63 [self->updatedProperties release];
67 - (void)_trackAttendeeChanges:(iCalEvent *)_from :(iCalEvent *)_to {
68 unsigned f, t, fcount, tcount;
69 NSArray *fromAttendees, *toAttendees;
71 fromAttendees = [_from attendees];
72 fcount = [fromAttendees count];
73 toAttendees = [_to attendees];
74 tcount = [toAttendees count];
75 for(f = 0; f < fcount; f++) {
79 fp = [fromAttendees objectAtIndex:f];
81 for(t = 0; t < tcount; t++) {
84 tp = [toAttendees objectAtIndex:t];
85 if([fp hasSameEmailAddress:tp]) {
87 if(![fp isEqualToPerson:tp]) {
88 [self->updatedAttendees addObject:tp];
94 [self->deletedAttendees addObject:fp];
97 for(t = 0; t < tcount; t++) {
101 tp = [toAttendees objectAtIndex:t];
102 for(f = 0; f < fcount; f++) {
105 fp = [fromAttendees objectAtIndex:f];
106 if([tp hasSameEmailAddress:fp]) {
112 [self->insertedAttendees addObject:tp];
116 - (void)_trackAlarmChanges:(iCalEvent *)_from :(iCalEvent *)_to {
119 - (void)_trackPropertyChanges:(iCalEvent *)_from :(iCalEvent *)_to {
120 if(!IS_EQUAL([_from startDate], [_to startDate], isEqualToDate:))
121 [self->updatedProperties addObject:@"startDate"];
122 if(!IS_EQUAL([_from endDate], [_to endDate], isEqualToDate:))
123 [self->updatedProperties addObject:@"endDate"];
124 if(!IS_EQUAL([_from created], [_to created], isEqualToDate:))
125 [self->updatedProperties addObject:@"created"];
126 if(!IS_EQUAL([_from lastModified], [_to lastModified], isEqualToDate:))
127 [self->updatedProperties addObject:@"lastModified"];
128 if(![_from durationAsTimeInterval] == [_to durationAsTimeInterval])
129 [self->updatedProperties addObject:@"duration"];
130 if(!IS_EQUAL([_from summary], [_to summary], isEqualToString:))
131 [self->updatedProperties addObject:@"summary"];
132 if(!IS_EQUAL([_from location], [_to location], isEqualToString:))
133 [self->updatedProperties addObject:@"location"];
134 if(!IS_EQUAL([_from comment], [_to comment], isEqualToString:))
135 [self->updatedProperties addObject:@"comment"];
136 if(!IS_EQUAL([_from priority], [_to priority], isEqualToString:))
137 [self->updatedProperties addObject:@"priority"];
138 if(!IS_EQUAL([_from status], [_to status], isEqualToString:))
139 [self->updatedProperties addObject:@"status"];
140 if(!IS_EQUAL([_from accessClass], [_to accessClass], isEqualToString:))
141 [self->updatedProperties addObject:@"accessClass"];
142 if(!IS_EQUAL([_from sequence], [_to sequence], isEqualToNumber:))
143 [self->updatedProperties addObject:@"sequence"];
144 if(!IS_EQUAL([_from organizer], [_to organizer], isEqual:))
145 [self->updatedProperties addObject:@"organizer"];
149 return [self hasAttendeeChanges] ||
150 [self hasAlarmChanges] ||
151 [self hasPropertyChanges];
154 - (BOOL)hasAttendeeChanges {
155 return [[self insertedAttendees] count] > 0 ||
156 [[self deletedAttendees] count] > 0 ||
157 [[self updatedAttendees] count] > 0;
160 - (BOOL)hasAlarmChanges {
161 return [[self insertedAlarms] count] > 0 ||
162 [[self deletedAlarms] count] > 0 ||
163 [[self updatedAlarms] count] > 0;
166 - (BOOL)hasPropertyChanges {
167 return [[self updatedProperties] count] > 0;
170 - (NSArray *)insertedAttendees {
171 return self->insertedAttendees;
173 - (NSArray *)deletedAttendees {
174 return self->deletedAttendees;
176 - (NSArray *)updatedAttendees {
177 return self->updatedAttendees;
180 - (NSArray *)insertedAlarms {
181 return self->insertedAlarms;
183 - (NSArray *)deletedAlarms {
184 return self->deletedAlarms;
186 - (NSArray *)updatedAlarms {
187 return self->updatedAlarms;
190 - (NSArray *)updatedProperties {
191 return self->updatedProperties;
196 - (NSString *)description {
199 ms = [NSMutableString stringWithCapacity:128];
200 [ms appendFormat:@"<0x%08X[%@]:", self, NSStringFromClass([self class])];
202 [ms appendFormat:@" updatedProperties=%@", self->updatedProperties];
203 [ms appendFormat:@" insertedAttendees=%@", self->insertedAttendees];
204 [ms appendFormat:@" deletedAttendees=%@", self->deletedAttendees];
205 [ms appendFormat:@" updatedAttendees=%@", self->updatedAttendees];
207 [ms appendString:@">"];