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
22 #import <Foundation/NSArray.h>
23 #import <Foundation/NSString.h>
25 #import "iCalEventChanges.h"
27 #import "iCalPerson.h"
29 @interface iCalEventChanges (PrivateAPI)
30 - (void)_trackAttendeeChanges:(iCalEvent *)_from :(iCalEvent *)_to;
31 - (void)_trackAlarmChanges:(iCalEvent *)_from :(iCalEvent *)_to;
32 - (void)_trackPropertyChanges:(iCalEvent *)_from :(iCalEvent *)_to;
35 @implementation iCalEventChanges
37 + (id)changesFromEvent:(iCalEvent *)_from toEvent:(iCalEvent *)_to {
38 return [[[self alloc] initWithFromEvent:_from toEvent:_to] autorelease];
41 - (id)initWithFromEvent:(iCalEvent *)_from toEvent:(iCalEvent *)_to {
44 self->insertedAttendees = [[NSMutableArray alloc] init];
45 self->deletedAttendees = [[NSMutableArray alloc] init];
46 self->updatedAttendees = [[NSMutableArray alloc] init];
47 self->insertedAlarms = [[NSMutableArray alloc] init];
48 self->deletedAlarms = [[NSMutableArray alloc] init];
49 self->updatedAlarms = [[NSMutableArray alloc] init];
50 self->updatedProperties = [[NSMutableArray alloc] init];
51 [self _trackAttendeeChanges:_from :_to];
52 [self _trackPropertyChanges:_from :_to];
58 [self->insertedAttendees release];
59 [self->deletedAttendees release];
60 [self->updatedAttendees release];
61 [self->insertedAlarms release];
62 [self->deletedAlarms release];
63 [self->updatedAlarms release];
64 [self->updatedProperties release];
68 - (void)_trackAttendeeChanges:(iCalEvent *)_from :(iCalEvent *)_to {
69 unsigned f, t, fcount, tcount;
70 NSArray *fromAttendees, *toAttendees;
72 fromAttendees = [_from attendees];
73 fcount = [fromAttendees count];
74 toAttendees = [_to attendees];
75 tcount = [toAttendees count];
76 for(f = 0; f < fcount; f++) {
80 fp = [fromAttendees objectAtIndex:f];
82 for(t = 0; t < tcount; t++) {
85 tp = [toAttendees objectAtIndex:t];
86 if([fp hasSameEmailAddress:tp]) {
88 if(![fp isEqualToPerson:tp]) {
89 [self->updatedAttendees addObject:tp];
95 [self->deletedAttendees addObject:fp];
98 for(t = 0; t < tcount; t++) {
102 tp = [toAttendees objectAtIndex:t];
103 for(f = 0; f < fcount; f++) {
106 fp = [fromAttendees objectAtIndex:f];
107 if([tp hasSameEmailAddress:fp]) {
113 [self->insertedAttendees addObject:tp];
117 - (void)_trackAlarmChanges:(iCalEvent *)_from :(iCalEvent *)_to {
120 - (void)_trackPropertyChanges:(iCalEvent *)_from :(iCalEvent *)_to {
121 if(!IS_EQUAL([_from startDate], [_to startDate], isEqualToDate:))
122 [self->updatedProperties addObject:@"startDate"];
123 if(!IS_EQUAL([_from endDate], [_to endDate], isEqualToDate:))
124 [self->updatedProperties addObject:@"endDate"];
125 if(!IS_EQUAL([_from created], [_to created], isEqualToDate:))
126 [self->updatedProperties addObject:@"created"];
127 if(!IS_EQUAL([_from lastModified], [_to lastModified], isEqualToDate:))
128 [self->updatedProperties addObject:@"lastModified"];
129 if(![_from durationAsTimeInterval] == [_to durationAsTimeInterval])
130 [self->updatedProperties addObject:@"duration"];
131 if(!IS_EQUAL([_from summary], [_to summary], isEqualToString:))
132 [self->updatedProperties addObject:@"summary"];
133 if(!IS_EQUAL([_from location], [_to location], isEqualToString:))
134 [self->updatedProperties addObject:@"location"];
135 if(!IS_EQUAL([_from comment], [_to comment], isEqualToString:))
136 [self->updatedProperties addObject:@"comment"];
137 if(!IS_EQUAL([_from priority], [_to priority], isEqualToString:))
138 [self->updatedProperties addObject:@"priority"];
139 if(!IS_EQUAL([_from status], [_to status], isEqualToString:))
140 [self->updatedProperties addObject:@"status"];
141 if(!IS_EQUAL([_from accessClass], [_to accessClass], isEqualToString:))
142 [self->updatedProperties addObject:@"accessClass"];
143 if(!IS_EQUAL([_from sequence], [_to sequence], isEqualToNumber:))
144 [self->updatedProperties addObject:@"sequence"];
145 if(!IS_EQUAL([_from organizer], [_to organizer], isEqual:))
146 [self->updatedProperties addObject:@"organizer"];
150 return [self hasAttendeeChanges] ||
151 [self hasAlarmChanges] ||
152 [self hasPropertyChanges];
155 - (BOOL)hasAttendeeChanges {
156 return [[self insertedAttendees] count] > 0 ||
157 [[self deletedAttendees] count] > 0 ||
158 [[self updatedAttendees] count] > 0;
161 - (BOOL)hasAlarmChanges {
162 return [[self insertedAlarms] count] > 0 ||
163 [[self deletedAlarms] count] > 0 ||
164 [[self updatedAlarms] count] > 0;
167 - (BOOL)hasPropertyChanges {
168 return [[self updatedProperties] count] > 0;
171 - (NSArray *)insertedAttendees {
172 return self->insertedAttendees;
174 - (NSArray *)deletedAttendees {
175 return self->deletedAttendees;
177 - (NSArray *)updatedAttendees {
178 return self->updatedAttendees;
181 - (NSArray *)insertedAlarms {
182 return self->insertedAlarms;
184 - (NSArray *)deletedAlarms {
185 return self->deletedAlarms;
187 - (NSArray *)updatedAlarms {
188 return self->updatedAlarms;
191 - (NSArray *)updatedProperties {
192 return self->updatedProperties;
197 - (NSString *)description {
200 ms = [NSMutableString stringWithCapacity:128];
201 [ms appendFormat:@"<0x%p[%@]:", self, NSStringFromClass([self class])];
203 [ms appendFormat:@" updatedProperties=%@", self->updatedProperties];
204 [ms appendFormat:@" insertedAttendees=%@", self->insertedAttendees];
205 [ms appendFormat:@" deletedAttendees=%@", self->deletedAttendees];
206 [ms appendFormat:@" updatedAttendees=%@", self->updatedAttendees];
208 [ms appendString:@">"];