2010-06-04 22:54:07 +02:00
|
|
|
/* SOGoAppointmentFolderObject.m - this file is part of SOGo
|
|
|
|
*
|
|
|
|
* Copyright (C) 2010 Inverse inc.
|
|
|
|
*
|
|
|
|
* 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>
|
2010-06-09 14:49:57 +02:00
|
|
|
#import <Foundation/NSCalendarDate.h>
|
2010-06-04 22:54:07 +02:00
|
|
|
#import <Foundation/NSDictionary.h>
|
|
|
|
#import <Foundation/NSString.h>
|
|
|
|
|
2010-06-09 14:49:57 +02:00
|
|
|
#import <NGObjWeb/WOContext+SoObjects.h>
|
2010-06-04 22:54:07 +02:00
|
|
|
#import <NGObjWeb/WOResponse.h>
|
2010-06-09 14:49:57 +02:00
|
|
|
#import <NGExtensions/NSObject+Logs.h>
|
2010-06-04 22:54:07 +02:00
|
|
|
|
|
|
|
#import <NGCards/iCalCalendar.h>
|
|
|
|
#import <NGCards/iCalTimeZone.h>
|
|
|
|
|
2011-03-30 17:01:55 +02:00
|
|
|
#import <SOGo/SOGoBuild.h>
|
2010-06-09 14:49:57 +02:00
|
|
|
#import <SOGo/SOGoDomainDefaults.h>
|
|
|
|
#import <SOGo/SOGoUser.h>
|
|
|
|
|
2010-06-04 22:54:07 +02:00
|
|
|
#import "SOGoAppointmentFolder.h"
|
|
|
|
#import "SOGoCalendarComponent.h"
|
|
|
|
|
|
|
|
#import "SOGoAppointmentFolderObject.h"
|
|
|
|
|
2010-06-09 14:49:57 +02:00
|
|
|
static NSArray *contentFields = nil;
|
|
|
|
|
2010-06-04 22:54:07 +02:00
|
|
|
@implementation SOGoAppointmentFolderObject
|
|
|
|
|
2010-06-09 14:49:57 +02:00
|
|
|
+ (void) initialize
|
|
|
|
{
|
|
|
|
if (!contentFields)
|
|
|
|
contentFields = [[NSArray alloc] initWithObjects: @"c_name", @"c_version",
|
|
|
|
@"c_lastmodified", @"c_creationdate",
|
|
|
|
@"c_component", nil];
|
|
|
|
}
|
|
|
|
|
2010-06-04 22:54:07 +02:00
|
|
|
- (id) init
|
|
|
|
{
|
2010-06-09 14:49:57 +02:00
|
|
|
int davCalendarStartTimeLimit;
|
|
|
|
SOGoUser *user;
|
|
|
|
|
2010-06-04 22:54:07 +02:00
|
|
|
if ((self = [super init]))
|
|
|
|
{
|
|
|
|
folder = nil;
|
2010-06-09 14:49:57 +02:00
|
|
|
|
|
|
|
user = [context activeUser];
|
|
|
|
davCalendarStartTimeLimit
|
|
|
|
= [[user domainDefaults] davCalendarStartTimeLimit];
|
|
|
|
/* 43200 = 60 * 60 * 24 / 2 */
|
|
|
|
davTimeHalfLimitSeconds = davCalendarStartTimeLimit * 43200;
|
2010-06-04 22:54:07 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
return self;
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void) dealloc
|
|
|
|
{
|
|
|
|
[folder release];
|
|
|
|
[super dealloc];
|
|
|
|
}
|
|
|
|
|
|
|
|
- (BOOL) isFolderish
|
|
|
|
{
|
|
|
|
return NO;
|
|
|
|
}
|
|
|
|
|
|
|
|
- (SOGoAppointmentFolder *) _folder
|
|
|
|
{
|
|
|
|
NSString *folderName;
|
|
|
|
int length;
|
|
|
|
|
|
|
|
if (!folder)
|
|
|
|
{
|
|
|
|
length = [nameInContainer length];
|
|
|
|
if (length > 3)
|
|
|
|
{
|
|
|
|
folderName = [nameInContainer substringToIndex: length - 4];
|
|
|
|
folder = [container lookupName: folderName
|
|
|
|
inContext: context
|
|
|
|
acquire: NO];
|
|
|
|
[folder retain];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return folder;
|
|
|
|
}
|
|
|
|
|
|
|
|
- (NSArray *) aclsForUser: (NSString *) login
|
|
|
|
{
|
|
|
|
return [[self _folder] aclsForUser: login];
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void) _extractTimeZones: (NSArray *) timeZones
|
|
|
|
intoDictionary: (NSMutableDictionary *) tzDict
|
|
|
|
{
|
|
|
|
int count, max;
|
|
|
|
iCalTimeZone *timeZone;
|
|
|
|
NSString *tzId;
|
|
|
|
|
|
|
|
max = [timeZones count];
|
|
|
|
for (count = 0; count < max; count++)
|
|
|
|
{
|
|
|
|
timeZone = [timeZones objectAtIndex: count];
|
|
|
|
tzId = [timeZone tzId];
|
|
|
|
if (![tzDict objectForKey: tzId])
|
|
|
|
[tzDict setObject: timeZone forKey: tzId];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void) _extractCalendarsData: (NSArray *) calendars
|
|
|
|
intoTimeZones: (NSMutableDictionary *) timeZones
|
|
|
|
andComponents: (NSMutableArray *) components
|
|
|
|
{
|
|
|
|
int count, max;
|
|
|
|
iCalCalendar *calendar;
|
|
|
|
|
|
|
|
max = [calendars count];
|
|
|
|
for (count = 0; count < max; count++)
|
|
|
|
{
|
|
|
|
calendar = [calendars objectAtIndex: count];
|
|
|
|
[self _extractTimeZones: [calendar timezones]
|
|
|
|
intoDictionary: timeZones];
|
|
|
|
[components addObjectsFromArray: [calendar allObjects]];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-06-09 14:49:57 +02:00
|
|
|
- (NSArray *) _fetchFolderRecords
|
|
|
|
{
|
|
|
|
NSCalendarDate *start, *end;
|
|
|
|
|
|
|
|
if (davTimeHalfLimitSeconds)
|
|
|
|
{
|
|
|
|
start = [[NSCalendarDate date] addYear: 0
|
|
|
|
month: 0
|
|
|
|
day: 0
|
|
|
|
hour: 0
|
|
|
|
minute: 0
|
|
|
|
second: -davTimeHalfLimitSeconds];
|
|
|
|
end = [start addYear: 0
|
|
|
|
month: 0
|
|
|
|
day: 0
|
|
|
|
hour: 0
|
|
|
|
minute: 0
|
|
|
|
second: (2 * davTimeHalfLimitSeconds)];
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
start = nil;
|
|
|
|
end = nil;
|
|
|
|
}
|
|
|
|
|
|
|
|
return [[self _folder] bareFetchFields: contentFields
|
|
|
|
from: start
|
|
|
|
to: end
|
|
|
|
title: nil
|
|
|
|
component: nil
|
|
|
|
additionalFilters: nil];
|
|
|
|
}
|
|
|
|
|
2010-06-04 22:54:07 +02:00
|
|
|
- (NSArray *) _folderCalendars
|
|
|
|
{
|
2010-06-09 14:49:57 +02:00
|
|
|
NSArray *records;
|
2010-06-04 22:54:07 +02:00
|
|
|
NSMutableArray *calendars;
|
2010-06-09 14:49:57 +02:00
|
|
|
SOGoCalendarComponent *component;
|
|
|
|
int count, max;
|
|
|
|
iCalCalendar *calendar;
|
|
|
|
NSString *name;
|
2010-06-04 22:54:07 +02:00
|
|
|
|
2010-06-09 14:49:57 +02:00
|
|
|
records = [self _fetchFolderRecords];
|
|
|
|
max = [records count];
|
2010-06-04 22:54:07 +02:00
|
|
|
calendars = [NSMutableArray arrayWithCapacity: max];
|
|
|
|
for (count = 0; count < max; count++)
|
|
|
|
{
|
2010-06-09 14:49:57 +02:00
|
|
|
name = [[records objectAtIndex: count] objectForKey: @"c_name"];
|
|
|
|
component = [folder lookupName: name
|
2010-06-04 22:54:07 +02:00
|
|
|
inContext: context
|
|
|
|
acquire: NO];
|
2010-06-09 14:49:57 +02:00
|
|
|
calendar = [component calendar: NO secure: !activeUserIsOwner];
|
|
|
|
if (calendar)
|
|
|
|
[calendars addObject: calendar];
|
|
|
|
else
|
|
|
|
[self errorWithFormat: @"record with c_name '%@' should obviously not"
|
|
|
|
@" be listed here", name];
|
2010-06-04 22:54:07 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
return calendars;
|
|
|
|
}
|
|
|
|
|
|
|
|
- (iCalCalendar *) contentCalendar
|
|
|
|
{
|
|
|
|
NSArray *calendars;
|
|
|
|
iCalCalendar *calendar;
|
|
|
|
NSMutableDictionary *timeZones;
|
|
|
|
NSMutableArray *components;
|
|
|
|
|
|
|
|
calendars = [self _folderCalendars];
|
|
|
|
timeZones = [NSMutableDictionary dictionaryWithCapacity: 16];
|
|
|
|
components = [NSMutableArray arrayWithCapacity: [calendars count] * 2];
|
|
|
|
[self _extractCalendarsData: calendars
|
|
|
|
intoTimeZones: timeZones andComponents: components];
|
|
|
|
|
|
|
|
calendar = [iCalCalendar groupWithTag: @"vcalendar"];
|
|
|
|
[calendar setMethod: @"PUBLISH"];
|
|
|
|
[calendar setVersion: @"2.0"];
|
2011-03-30 17:01:55 +02:00
|
|
|
[calendar setProdID: [NSString stringWithFormat:
|
|
|
|
@"-//Inverse inc./SOGo %@//EN",
|
|
|
|
SOGoVersion]];
|
2010-06-04 22:54:07 +02:00
|
|
|
[calendar addChildren: [timeZones allValues]];
|
|
|
|
[calendar addChildren: components];
|
|
|
|
|
|
|
|
return calendar;
|
|
|
|
}
|
|
|
|
|
|
|
|
- (id) davEntityTag
|
|
|
|
{
|
|
|
|
return [[self _folder] davCollectionTag];
|
|
|
|
}
|
|
|
|
|
|
|
|
- (NSString *) contentAsString
|
|
|
|
{
|
|
|
|
[self subclassResponsibility: _cmd];
|
|
|
|
|
|
|
|
return nil;
|
|
|
|
}
|
|
|
|
|
|
|
|
- (NSString *) davContentType
|
|
|
|
{
|
|
|
|
[self subclassResponsibility: _cmd];
|
|
|
|
|
|
|
|
return nil;
|
|
|
|
}
|
|
|
|
|
2010-06-08 15:35:25 +02:00
|
|
|
- (NSString *) displayName
|
|
|
|
{
|
|
|
|
return [[self _folder] displayName];
|
|
|
|
}
|
|
|
|
|
|
|
|
- (NSString *) davDisplayName
|
|
|
|
{
|
|
|
|
return [self displayName];
|
|
|
|
}
|
|
|
|
|
2010-06-04 22:54:07 +02:00
|
|
|
@end
|