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