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