]> err.no Git - sope/blob - sope-appserver/samples/iCalPortal/iCalView.m
generate RSS from display group
[sope] / sope-appserver / samples / iCalPortal / iCalView.m
1 /*
2   Copyright (C) 2000-2005 SKYRIX Software AG
3
4   This file is part of SOPE.
5
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
9   later version.
10
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.
15
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
19   02111-1307, USA.
20 */
21
22 #include "iCalView.h"
23 #include "iCalPortalUser.h"
24 #include <NGExtensions/EOCacheDataSource.h>
25 #include "common.h"
26
27 @interface iCalPortalDateFormatter : NSFormatter
28 {
29   iCalView *component;
30 }
31
32 - (id)initWithComponent:(iCalView *)_comp;
33
34 @end
35
36 @implementation iCalView
37
38 + (int)version {
39   return [super version] + 0 /* v2 */;
40 }
41 + (void)initialize {
42   NSAssert2([super version] == 2,
43             @"invalid superclass (%@) version %i !",
44             NSStringFromClass([self superclass]), [super version]);
45 }
46
47 - (void)dealloc {
48   [self->dateFormatter release];
49   [self->dataSource    release];
50   [self->item          release];
51   [self->calendarName  release];
52   [self->today         release];
53   [super dealloc];
54 }
55
56 /* accessors */
57
58 - (void)setCalendarName:(NSString *)_name {
59   ASSIGN(self->calendarName, _name);
60 }
61 - (NSString *)calendarName {
62   return self->calendarName;
63 }
64
65 - (void)setItem:(id)_item {
66   ASSIGN(self->item, _item);
67 }
68 - (id)item {
69   return self->item;
70 }
71
72 - (NSTimeZone *)viewTimeZone {
73   if ([self hasSession])
74     return [[self session] viewTimeZone];
75   
76   return [NSTimeZone timeZoneWithName:@"Europe/Berlin"];
77 }
78
79 /* datasource */
80
81 - (NSString *)entityName {
82   return nil;
83 }
84
85 - (EOQualifier *)qualifier {
86   return nil;
87 }
88
89 - (EOFetchSpecification *)fetchSpecification {
90   EOFetchSpecification *fs;
91
92   fs = [[EOFetchSpecification alloc] init];
93   [fs setEntityName:[self entityName]];
94   [fs setQualifier:[self qualifier]];
95   return [fs autorelease];
96 }
97
98 - (EODataSource *)dataSource {
99   EODataSource *ds;
100   EOFetchSpecification *fspec;
101   
102   if (self->dataSource)
103     return self->dataSource;
104   
105   if ((ds = [[self user] dataSourceAtPath:self->calendarName]) == nil)
106     return nil;
107   
108   if ((fspec = [self fetchSpecification]))
109     [ds setFetchSpecification:fspec];
110   
111   if ((ds = [[EOCacheDataSource alloc] initWithDataSource:ds]) == nil)
112     return nil;
113   
114   self->dataSource = ds;
115   
116   return ds;
117 }
118
119 - (NSFormatter *)dateFormatter {
120   if (self->dateFormatter == nil) {
121     self->dateFormatter =
122       [[iCalPortalDateFormatter alloc] initWithComponent:self];
123   }
124   return self->dateFormatter;
125 }
126
127 - (NSCalendarDate *)today {
128   if (self->today == nil) {
129     self->today = [[NSCalendarDate alloc] init];
130     [self->today setTimeZone:[self viewTimeZone]];
131   }
132   return self->today;
133 }
134
135 /* notifications */
136
137 - (void)sleep {
138   [super sleep];
139   [self setItem:nil];
140   [self->dataSource    release]; self->dataSource    = nil;
141   [self->dateFormatter release]; self->dateFormatter = nil;
142 }
143
144 /* labels */
145
146 - (NSString *)localizedTitle {
147   NSString *s, *calType;
148   NSString *pe;
149   
150   s  = [self calendarName];
151   pe = [s pathExtension];
152   s  = [s stringByDeletingPathExtension];
153
154   if ([pe isEqualToString:@"ics"] || [pe length] == 0)
155     calType = @"iCalTypeName";
156   else if ([pe isEqualToString:@"vfb"] || [pe isEqualToString:@"ifb"])
157     calType = @"freeBusyTypeName";
158   else
159     calType = @"unknownTypeName";
160   
161   calType = [self stringForKey:calType];
162   
163   s = [NSString stringWithFormat:@"%@ on %@: %@", 
164                   [super localizedTitle], calType, s];
165   return s;
166 }
167
168 /* actions */
169
170 - (id)run {
171   if ([self hasSession]) {
172     WORequest *rq;
173     id tmp;
174   
175     rq = [[self context] request];
176     
177     if ((tmp = [rq formValueForKey:@"calendarName"])) {
178       [self setCalendarName:tmp];
179     }
180     else {
181       /* choose default cal ... */
182     }
183   }  
184   return [super run];
185 }
186
187 @end /* iCalView */
188
189 @implementation iCalPortalDateFormatter
190
191 - (id)initWithComponent:(iCalView *)_comp {
192   self->component = _comp;
193   return self;
194 }
195
196 - (NSString *)stringForObjectValue:(id)_object {
197   static Class NSCalendarDateClass = Nil;
198
199   if (_object == nil) return nil;
200   
201   if (NSCalendarDateClass == Nil) 
202     NSCalendarDateClass = [NSCalendarDateClass class];
203
204   NSLog(@"string for object: %@", _object);
205   
206   if (![_object isKindOfClass:NSCalendarDateClass])
207     return [_object stringValue];
208   
209   [_object setTimeZone:[self->component viewTimeZone]];
210   return [_object descriptionWithCalendarFormat:@"%H:%M"];
211 }
212
213 @end /* iCalPortalDateFormatter */