]> err.no Git - sope/blob - sope-ical/NGiCal/iCalCalendar.m
fixed mapping of 'method' attribute
[sope] / sope-ical / NGiCal / 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 #include "iCalCalendar.h"
23 #include "common.h"
24
25 @implementation iCalCalendar
26
27 - (void)dealloc {
28   [self->version   release];
29   [self->calscale  release];
30   [self->prodId    release];
31   [self->method    release];
32
33   [self->todos     release];
34   [self->events    release];
35   [self->journals  release];
36   [self->freeBusys release];
37   [self->timezones release];
38   [super dealloc];
39 }
40
41 /* accessors */
42
43 - (void)setCalscale:(NSString *)_value {
44   ASSIGNCOPY(self->calscale, _value);
45 }
46 - (NSString *)calscale {
47   return self->calscale;
48 }
49 - (void)setVersion:(NSString *)_value {
50   ASSIGNCOPY(self->version, _value);
51 }
52 - (NSString *)version {
53   return self->version;
54 }
55 - (void)setProdId:(NSString *)_value {
56   ASSIGNCOPY(self->prodId, _value);
57 }
58 - (NSString *)prodId {
59   return self->prodId;
60 }
61 - (void)setMethod:(NSString *)_method {
62   ASSIGNCOPY(self->method, _method);
63 }
64 - (NSString *)method {
65   return self->method;
66 }
67
68 - (void)addToEvents:(iCalEvent *)_event {
69   if (_event == nil) return;
70   if (self->events == nil)
71     self->events = [[NSMutableArray alloc] initWithCapacity:4];
72   [self->events addObject:_event];
73 }
74 - (NSArray *)events {
75   return self->events;
76 }
77
78 - (void)addToTimezones:(id)_tz {
79   NSString *tzid;
80   
81   if (_tz == nil) return;
82   if (self->timezones == nil)
83     self->timezones = [[NSMutableDictionary alloc] initWithCapacity:4];
84   
85   if ((tzid = [_tz valueForKey:@"tzid"]) == nil) {
86     [self logWithFormat:@"ERROR: missing timezone-id in timezone: %@", _tz];
87     return;
88   }
89   [self->timezones setObject:_tz forKey:tzid];
90 }
91 - (NSArray *)timezones {
92   return [self->timezones allValues];
93 }
94
95 - (void)addToTodos:(iCalToDo *)_todo {
96   if (_todo == nil) return;
97   if (self->todos == nil)
98     self->todos = [[NSMutableArray alloc] initWithCapacity:4];
99   [self->todos addObject:_todo];
100 }
101 - (NSArray *)todos {
102   return self->todos;
103 }
104
105 - (void)addToJournals:(iCalJournal *)_obj {
106   if (_obj == nil) return;
107   if (self->journals == nil)
108     self->journals = [[NSMutableArray alloc] initWithCapacity:4];
109   [self->journals addObject:_obj];
110 }
111 - (NSArray *)journals {
112   return self->journals;
113 }
114
115 - (void)addToFreeBusys:(iCalJournal *)_obj {
116   if (_obj == nil) return;
117   if (self->freeBusys == nil)
118     self->freeBusys = [[NSMutableArray alloc] initWithCapacity:4];
119   [self->freeBusys addObject:_obj];
120 }
121 - (NSArray *)freeBusys {
122   return self->freeBusys;
123 }
124
125 /* collection */
126
127 - (NSArray *)allObjects {
128   NSMutableArray *ma;
129   
130   ma = [NSMutableArray arrayWithCapacity:32];
131   if (self->events)    [ma addObjectsFromArray:self->events];
132   if (self->todos)     [ma addObjectsFromArray:self->todos];
133   if (self->freeBusys) [ma addObjectsFromArray:self->freeBusys];
134   if (self->journals)  [ma addObjectsFromArray:self->journals];
135   return ma;
136 }
137 - (NSEnumerator *)objectEnumerator {
138   return [[self allObjects] objectEnumerator];
139 }
140
141 /* ical typing */
142
143 - (NSString *)entityName {
144   return @"vcalendar";
145 }
146
147 /* descriptions */
148
149 - (NSString *)description {
150   NSMutableString *ms;
151
152   ms = [NSMutableString stringWithCapacity:128];
153   [ms appendFormat:@"<0x%08X[%@]:", self, NSStringFromClass([self class])];
154
155   if (self->version)  [ms appendFormat:@" v%@",         self->version];
156   if (self->method)   [ms appendFormat:@" method=%@",   self->method];
157   if (self->prodId)   [ms appendFormat:@" product=%@",  self->prodId];
158   if (self->calscale) [ms appendFormat:@" calscale=%@", self->calscale];
159
160   if ([self->events count] > 0)
161     [ms appendFormat:@" events=%@", self->events];
162   if ([self->todos count] > 0)
163     [ms appendFormat:@" todos=%@", self->todos];
164   if ([self->freeBusys count] > 0)
165     [ms appendFormat:@" fb=%@", self->freeBusys];
166   if ([self->journals count] > 0)
167     [ms appendFormat:@" journals=%@", self->journals];
168
169   if ([self->timezones count] > 0)
170     [ms appendFormat:@" tzs=%@", [self->timezones allKeys]];
171   
172   [ms appendString:@">"];
173   return ms;
174 }
175
176 @end /* iCalCalendar */