]> err.no Git - scalable-opengroupware.org/blob - SOPE/NGCards/iCalCalendar.m
git-svn-id: http://svn.opengroupware.org/SOGo/inverse/trunk@1178 d1b88da0-ebda-0310...
[scalable-opengroupware.org] / SOPE / NGCards / iCalCalendar.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 #import <Foundation/NSArray.h>
23 #import <Foundation/NSString.h>
24
25 #import "iCalEvent.h"
26 #import "iCalToDo.h"
27 #import "iCalJournal.h"
28 #import "iCalFreeBusy.h"
29 #import "iCalEntityObject.h"
30 #import "iCalTimeZone.h"
31
32 #import "iCalCalendar.h"
33
34 @interface iCalCalendar (Privates)
35 - (void) addToEvents: (iCalEvent *) _event;
36 - (void) addToTimezones: (iCalTimeZone *) _tz;
37 - (void) addToTodos: (iCalToDo *) _todo;
38 - (void) addToJournals: (iCalJournal *) _obj;
39 - (void) addToFreeBusys: (iCalFreeBusy *) _obj;
40 @end
41
42 @implementation iCalCalendar
43
44 /* class mapping */
45 - (Class) classForTag: (NSString *) classTag
46 {
47   Class tagClass;
48
49   tagClass = Nil;
50   if ([classTag isEqualToString: @"VEVENT"])
51     tagClass = [iCalEvent class];
52   else if ([classTag isEqualToString: @"VTODO"])
53     tagClass = [iCalToDo class];
54   else if ([classTag isEqualToString: @"VJOURNAL"])
55     tagClass = [iCalJournal class];
56   else if ([classTag isEqualToString: @"VFREEBUSY"])
57     tagClass = [iCalFreeBusy class];
58   else if ([classTag isEqualToString: @"VTIMEZONE"])
59     tagClass = [iCalTimeZone class];
60   else if ([classTag isEqualToString: @"METHOD"]
61            || [classTag isEqualToString: @"PRODID"]
62            || [classTag isEqualToString: @"VERSION"])
63     tagClass = [CardElement class];
64   else
65     tagClass = [super classForTag: classTag];
66
67   return tagClass;
68 }
69
70 /* accessors */
71
72 - (void) setCalscale: (NSString *) _calscale
73 {
74   [[self uniqueChildWithTag: @"calscale"] setValue: 0 to: _calscale];
75 }
76
77 - (NSString *) calscale
78 {
79   return [[self uniqueChildWithTag: @"calscale"] value: 0];
80 }
81
82 - (void) setVersion: (NSString *) _version
83 {
84   [[self uniqueChildWithTag: @"version"] setValue: 0 to: _version];
85 }
86
87 - (NSString *) version
88 {
89   return [[self uniqueChildWithTag: @"version"] value: 0];
90 }
91
92 - (void) setProdID: (NSString *) _value
93 {
94   [[self uniqueChildWithTag: @"prodid"] setValue: 0 to: _value];
95 }
96
97 - (NSString *) prodId
98 {
99   return [[self uniqueChildWithTag: @"prodid"] value: 0];
100 }
101
102 - (void) setMethod: (NSString *) _value
103 {
104   [[self uniqueChildWithTag: @"method"] setValue: 0 to: _value];
105 }
106
107 - (NSString *) method
108 {
109   return [[self uniqueChildWithTag: @"method"] value: 0];
110 }
111
112 - (void) addToEvents: (iCalEvent *) _event
113 {
114   [self addChild: _event];
115 }
116
117 - (NSArray *) events
118 {
119   return [self childrenWithTag: @"vevent"];
120 }
121
122 - (void) addToTimezones: (iCalTimeZone *) _tz
123 {
124   [self addChild: _tz];
125 }
126
127 - (NSArray *) timezones
128 {
129   return [self childrenWithTag: @"vtimezone"];
130 }
131
132 - (void) addToTodos: (iCalToDo *) _todo
133 {
134   [self addChild: _todo];
135 }
136
137 - (NSArray *) todos
138 {
139   return [self childrenWithTag: @"vtodo"];
140 }
141
142 - (void) addToJournals: (iCalJournal *) _todo
143 {
144   [self addChild: _todo];
145 }
146
147 - (NSArray *) journals
148 {
149   return [self childrenWithTag: @"vjournal"];
150 }
151
152 - (void) addToFreeBusys: (iCalFreeBusy *) _fb
153 {
154   [self addChild: _fb];
155 }
156
157 - (NSArray *) freeBusys
158 {
159   return [self childrenWithTag: @"vfreebusy"];
160 }
161
162 - (void) addTimeZone: (iCalTimeZone *) iTZ
163 {
164   iCalTimeZone *possibleTz;
165
166   possibleTz = [self timeZoneWithId: [iTZ tzId]];
167   if (!possibleTz)
168     [self addChild: iTZ];
169 }
170
171 - (iCalTimeZone *) timeZoneWithId: (NSString *) tzId
172 {
173   NSArray *matchingTimeZones;
174   iCalTimeZone *timeZone;
175
176   matchingTimeZones = [self childrenGroupWithTag: @"vtimezone"
177                             withChild: @"tzid"
178                             havingSimpleValue: tzId];
179   if ([matchingTimeZones count])
180     timeZone = [matchingTimeZones objectAtIndex: 0];
181   else
182     timeZone = nil;
183
184   return timeZone;
185 }
186
187 /* collection */
188
189 - (NSArray *) allObjects
190 {
191   NSMutableArray *ma;
192   
193   ma = [NSMutableArray new];
194   [ma addObjectsFromArray: [self events]];
195   [ma addObjectsFromArray: [self todos]];
196   [ma addObjectsFromArray: [self journals]];
197   [ma addObjectsFromArray: [self freeBusys]];
198
199   return ma;
200 }
201
202 /* ical typing */
203
204 - (NSString *) entityName
205 {
206   return @"vcalendar";
207 }
208
209 @end /* iCalCalendar */