2 Copyright (C) 2000-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 "iCalPortalUser.h"
24 #include <NGExtensions/EOCacheDataSource.h>
27 @interface iCalPortalDateFormatter : NSFormatter
32 - (id)initWithComponent:(iCalView *)_comp;
36 @implementation iCalView
39 return [super version] + 0 /* v2 */;
42 NSAssert2([super version] == 2,
43 @"invalid superclass (%@) version %i !",
44 NSStringFromClass([self superclass]), [super version]);
48 [self->dateFormatter release];
49 [self->dataSource release];
51 [self->calendarName release];
52 [self->today release];
58 - (void)setCalendarName:(NSString *)_name {
59 ASSIGN(self->calendarName, _name);
61 - (NSString *)calendarName {
62 return self->calendarName;
65 - (void)setItem:(id)_item {
66 ASSIGN(self->item, _item);
72 - (NSTimeZone *)viewTimeZone {
73 if ([self hasSession])
74 return [[self session] viewTimeZone];
76 return [NSTimeZone timeZoneWithName:@"Europe/Berlin"];
81 - (NSString *)entityName {
85 - (EOQualifier *)qualifier {
89 - (EOFetchSpecification *)fetchSpecification {
90 EOFetchSpecification *fs;
92 fs = [[EOFetchSpecification alloc] init];
93 [fs setEntityName:[self entityName]];
94 [fs setQualifier:[self qualifier]];
95 return [fs autorelease];
98 - (EODataSource *)dataSource {
100 EOFetchSpecification *fspec;
102 if (self->dataSource)
103 return self->dataSource;
105 if ((ds = [[self user] dataSourceAtPath:self->calendarName]) == nil)
108 if ((fspec = [self fetchSpecification]))
109 [ds setFetchSpecification:fspec];
111 if ((ds = [[EOCacheDataSource alloc] initWithDataSource:ds]) == nil)
114 self->dataSource = ds;
119 - (NSFormatter *)dateFormatter {
120 if (self->dateFormatter == nil) {
121 self->dateFormatter =
122 [[iCalPortalDateFormatter alloc] initWithComponent:self];
124 return self->dateFormatter;
127 - (NSCalendarDate *)today {
128 if (self->today == nil) {
129 self->today = [[NSCalendarDate alloc] init];
130 [self->today setTimeZone:[self viewTimeZone]];
140 [self->dataSource release]; self->dataSource = nil;
141 [self->dateFormatter release]; self->dateFormatter = nil;
146 - (NSString *)localizedTitle {
147 NSString *s, *calType;
150 s = [self calendarName];
151 pe = [s pathExtension];
152 s = [s stringByDeletingPathExtension];
154 if ([pe isEqualToString:@"ics"] || [pe length] == 0)
155 calType = @"iCalTypeName";
156 else if ([pe isEqualToString:@"vfb"] || [pe isEqualToString:@"ifb"])
157 calType = @"freeBusyTypeName";
159 calType = @"unknownTypeName";
161 calType = [self stringForKey:calType];
163 s = [NSString stringWithFormat:@"%@ on %@: %@",
164 [super localizedTitle], calType, s];
171 if ([self hasSession]) {
175 rq = [[self context] request];
177 if ((tmp = [rq formValueForKey:@"calendarName"])) {
178 [self setCalendarName:tmp];
181 /* choose default cal ... */
189 @implementation iCalPortalDateFormatter
191 - (id)initWithComponent:(iCalView *)_comp {
192 self->component = _comp;
196 - (NSString *)stringForObjectValue:(id)_object {
197 static Class NSCalendarDateClass = Nil;
199 if (_object == nil) return nil;
201 if (NSCalendarDateClass == Nil)
202 NSCalendarDateClass = [NSCalendarDateClass class];
204 NSLog(@"string for object: %@", _object);
206 if (![_object isKindOfClass:NSCalendarDateClass])
207 return [_object stringValue];
209 [_object setTimeZone:[self->component viewTimeZone]];
210 return [_object descriptionWithCalendarFormat:@"%H:%M"];
213 @end /* iCalPortalDateFormatter */