2008-07-17 23:12:43 +02:00
|
|
|
/* SOGoComponentOccurence.m - this file is part of SOGo
|
|
|
|
*
|
2008-09-27 03:13:41 +02:00
|
|
|
* Copyright (C) 2008 Inverse inc.
|
2008-07-17 23:12:43 +02:00
|
|
|
*
|
|
|
|
* Author: Wolfgang Sourdeau <wsourdeau@inverse.ca>
|
|
|
|
*
|
|
|
|
* 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 <Foundation/NSArray.h>
|
2008-08-11 21:21:56 +02:00
|
|
|
#import <Foundation/NSCalendarDate.h>
|
2008-07-17 23:12:43 +02:00
|
|
|
#import <Foundation/NSString.h>
|
|
|
|
|
|
|
|
#import <NGCards/iCalCalendar.h>
|
|
|
|
#import <NGCards/iCalRepeatableEntityObject.h>
|
|
|
|
|
2008-11-22 08:20:22 +01:00
|
|
|
#import "SOGoAppointmentObject.h"
|
|
|
|
#import "SOGoCalendarComponent.h"
|
|
|
|
|
2008-07-17 23:12:43 +02:00
|
|
|
#import "SOGoComponentOccurence.h"
|
|
|
|
|
|
|
|
@interface SOGoCalendarComponent (OccurenceExtensions)
|
|
|
|
|
|
|
|
- (void) prepareDeleteOccurence: (iCalRepeatableEntityObject *) component;
|
|
|
|
|
|
|
|
@end
|
|
|
|
|
|
|
|
@implementation SOGoComponentOccurence
|
|
|
|
|
|
|
|
+ (id) occurenceWithComponent: (iCalRepeatableEntityObject *) newComponent
|
|
|
|
withMasterComponent: (iCalRepeatableEntityObject *) newMaster
|
|
|
|
inContainer: (SOGoCalendarComponent *) newContainer
|
|
|
|
{
|
|
|
|
SOGoComponentOccurence *occurence;
|
2008-08-11 21:21:56 +02:00
|
|
|
NSTimeInterval seconds;
|
2008-07-17 23:12:43 +02:00
|
|
|
NSString *newName;
|
|
|
|
|
|
|
|
if (newComponent == newMaster)
|
|
|
|
newName = @"master";
|
|
|
|
else
|
|
|
|
{
|
|
|
|
seconds = [[newComponent recurrenceId] timeIntervalSince1970];
|
2008-08-11 21:21:56 +02:00
|
|
|
newName = [NSString stringWithFormat: @"occurence%d", (int) seconds];
|
|
|
|
}
|
2008-07-17 23:12:43 +02:00
|
|
|
occurence = [self objectWithName: newName inContainer: newContainer];
|
|
|
|
[occurence setComponent: newComponent];
|
|
|
|
[occurence setMasterComponent: newMaster];
|
|
|
|
|
|
|
|
return occurence;
|
|
|
|
}
|
|
|
|
|
|
|
|
- (id) init
|
|
|
|
{
|
|
|
|
if ((self = [super init]))
|
|
|
|
{
|
2009-03-02 22:47:47 +01:00
|
|
|
parentCalendar = nil;
|
2008-07-17 23:12:43 +02:00
|
|
|
component = nil;
|
|
|
|
master = nil;
|
|
|
|
isNew = NO;
|
|
|
|
}
|
|
|
|
|
|
|
|
return self;
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void) setIsNew: (BOOL) newIsNew
|
|
|
|
{
|
|
|
|
isNew = newIsNew;
|
|
|
|
}
|
|
|
|
|
|
|
|
- (BOOL) isNew
|
|
|
|
{
|
|
|
|
return isNew;
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void) dealloc
|
|
|
|
{
|
2009-03-02 22:47:47 +01:00
|
|
|
[parentCalendar release];
|
2008-07-17 23:12:43 +02:00
|
|
|
[super dealloc];
|
|
|
|
}
|
|
|
|
|
|
|
|
/* SOGoObject overrides */
|
|
|
|
|
|
|
|
- (BOOL) isFolderish
|
|
|
|
{
|
|
|
|
return NO;
|
|
|
|
}
|
|
|
|
|
|
|
|
- (NSString *) contentAsString
|
|
|
|
{
|
|
|
|
return [component versitString];
|
|
|
|
}
|
|
|
|
|
|
|
|
- (NSString *) davContentLength
|
|
|
|
{
|
|
|
|
unsigned int length;
|
|
|
|
|
|
|
|
length = [[self contentAsString]
|
|
|
|
lengthOfBytesUsingEncoding: NSUTF8StringEncoding];
|
|
|
|
|
|
|
|
return [NSString stringWithFormat: @"%u", length];
|
|
|
|
}
|
|
|
|
|
|
|
|
/* /SOGoObject overrides */
|
|
|
|
|
|
|
|
- (void) setComponent: (iCalRepeatableEntityObject *) newComponent
|
|
|
|
{
|
2009-03-02 22:47:47 +01:00
|
|
|
component = newComponent;
|
|
|
|
ASSIGN (parentCalendar, [component parent]);
|
2008-07-17 23:12:43 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
- (void) setMasterComponent: (iCalRepeatableEntityObject *) newMaster
|
|
|
|
{
|
2009-03-02 22:47:47 +01:00
|
|
|
master = newMaster;
|
2008-07-17 23:12:43 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
- (NSArray *) aclsForUser: (NSString *) uid
|
|
|
|
{
|
|
|
|
return [container aclsForUser: uid];
|
|
|
|
}
|
|
|
|
|
|
|
|
/* SOGoComponentOccurence protocol */
|
|
|
|
|
|
|
|
- (iCalRepeatableEntityObject *) occurence
|
|
|
|
{
|
|
|
|
return component;
|
|
|
|
}
|
|
|
|
|
2008-11-22 08:20:22 +01:00
|
|
|
- (NSException *) prepareDelete;
|
2008-07-17 23:12:43 +02:00
|
|
|
{
|
2008-12-05 17:11:41 +01:00
|
|
|
NSMutableArray *occurences;
|
|
|
|
NSCalendarDate *recurrenceId, *currentId;
|
2008-07-17 23:12:43 +02:00
|
|
|
NSException *error;
|
2008-12-05 17:11:41 +01:00
|
|
|
NSString *newContent;
|
|
|
|
iCalCalendar *calendar;
|
|
|
|
iCalEntityObject *currentOccurence;
|
|
|
|
int max, count;
|
2008-07-17 23:12:43 +02:00
|
|
|
|
|
|
|
if (component == master)
|
|
|
|
error = [container delete];
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if ([container respondsToSelector: @selector (prepareDeleteOccurence:)])
|
|
|
|
[container prepareDeleteOccurence: component];
|
2008-12-04 00:08:37 +01:00
|
|
|
|
2008-12-05 17:11:41 +01:00
|
|
|
// Add an date exception
|
|
|
|
recurrenceId = [component recurrenceId];
|
|
|
|
[master addToExceptionDates: recurrenceId];
|
|
|
|
[master increaseSequence];
|
|
|
|
|
|
|
|
// Remove the specified occurence within the repeating vEvent.
|
|
|
|
calendar = [master parent];
|
|
|
|
occurences = [calendar events];
|
|
|
|
max = [occurences count];
|
|
|
|
count = 1;
|
|
|
|
while (count < max)
|
|
|
|
{
|
|
|
|
currentOccurence = [occurences objectAtIndex: count];
|
|
|
|
currentId = [currentOccurence recurrenceId];
|
|
|
|
if ([currentId compare: recurrenceId] == NSOrderedSame)
|
|
|
|
{
|
|
|
|
[[calendar children] removeObject: currentOccurence];
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
count++;
|
|
|
|
}
|
2008-11-22 08:20:22 +01:00
|
|
|
|
2008-12-05 17:11:41 +01:00
|
|
|
// We generate the updated iCalendar file and we save it
|
|
|
|
// in the database.
|
|
|
|
newContent = [calendar versitString];
|
|
|
|
error = [container saveContentString: newContent];
|
2008-07-17 23:12:43 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
return error;
|
|
|
|
}
|
|
|
|
|
2008-08-11 21:21:56 +02:00
|
|
|
- (void) saveComponent: (iCalRepeatableEntityObject *) newEvent
|
2008-07-17 23:12:43 +02:00
|
|
|
{
|
|
|
|
[container saveComponent: newEvent];
|
|
|
|
}
|
|
|
|
|
2008-08-09 17:21:19 +02:00
|
|
|
#warning most of SOGoCalendarComponent and SOGoComponentOccurence share the same external interface... \
|
|
|
|
they should be siblings or SOGoComponentOccurence the parent class of SOGoCalendarComponent...
|
2008-11-22 08:20:22 +01:00
|
|
|
- (NSException *) changeParticipationStatus: (NSString *) newStatus
|
2008-08-09 17:21:19 +02:00
|
|
|
{
|
2008-11-22 08:20:22 +01:00
|
|
|
NSCalendarDate *date;
|
|
|
|
|
|
|
|
date = [component recurrenceId];
|
|
|
|
|
|
|
|
return [container changeParticipationStatus: newStatus forRecurrenceId: date];
|
2008-08-09 17:21:19 +02:00
|
|
|
}
|
|
|
|
|
2008-07-17 23:12:43 +02:00
|
|
|
@end
|