]> err.no Git - scalable-opengroupware.org/blob - SOPE/NGCards/iCalFreeBusy.m
git-svn-id: http://svn.opengroupware.org/SOGo/inverse/trunk@1178 d1b88da0-ebda-0310...
[scalable-opengroupware.org] / SOPE / NGCards / iCalFreeBusy.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 #import <Foundation/NSTimeZone.h>
25
26 #import "iCalDateTime.h"
27 #import "NSCalendarDate+NGCards.h"
28
29 #import "iCalFreeBusy.h"
30
31 @implementation iCalFreeBusy
32
33 - (Class) classForTag: (NSString *) classTag
34 {
35   Class tagClass;
36
37   if ([classTag isEqualToString: @"DTEND"])
38     tagClass = [iCalDateTime class];
39   else if ([classTag isEqualToString: @"FREEBUSY"])
40     tagClass = [CardElement class];
41   else
42     tagClass = [super classForTag: classTag];
43
44   return tagClass;
45 }
46
47 /* accessors */
48 - (void) setEndDate: (NSCalendarDate *) newEndDate
49 {
50   [(iCalDateTime *) [self uniqueChildWithTag: @"dtend"]
51                     setDateTime: newEndDate];
52 }
53
54 - (NSCalendarDate *) endDate
55 {
56   return [(iCalDateTime *) [self uniqueChildWithTag: @"dtend"]
57                            dateTime];
58 }
59
60 - (BOOL) hasEndDate
61 {
62   return ([[self childrenWithTag: @"dtend"] count] > 0);
63 }
64
65 - (NSString *) _freeBusyTypeString: (iCalFreeBusyType) type
66 {
67   NSString *typeString;
68
69   switch (type)
70     {
71     case iCalFBBusy:
72       typeString = @"BUSY";
73       break;
74     case iCalFBFree:
75       typeString = @"FREE";
76       break;
77     case iCalFBBusyUnavailable:
78       typeString = @"BUSY-UNAVAILABLE";
79       break;
80     default:
81       typeString = @"BUSY-TENTATIVE";
82     }
83
84   return typeString;
85 }
86
87 - (void) addFreeBusyFrom: (NSCalendarDate *) start
88                       to: (NSCalendarDate *) end
89                     type: (iCalFreeBusyType) type
90 {
91   CardElement *freeBusyElement;
92   NSString *value;
93   NSCalendarDate *utcStart, *utcEnd;
94   NSTimeZone *uTZ;
95
96   uTZ = [NSTimeZone timeZoneWithAbbreviation: @"GMT"];
97   utcStart = [start copy];
98   utcEnd = [end copy];
99   [utcStart setTimeZone: uTZ];
100   [utcEnd setTimeZone: uTZ];
101
102   value = [NSString stringWithFormat: @"%@Z/%@Z",
103                     [utcStart iCalFormattedDateTimeString],
104                     [utcEnd iCalFormattedDateTimeString]];
105   freeBusyElement = [CardElement simpleElementWithTag: @"freebusy"
106                                  value: value];
107   [freeBusyElement addAttribute: @"fbtype"
108                    value: [self _freeBusyTypeString: type]];
109   [self addChild: freeBusyElement];
110
111   [utcStart release];
112   [utcEnd release];
113 }
114
115 /* ical typing */
116
117 - (NSString *) entityName
118 {
119   return @"vfreebusy";
120 }
121
122 @end /* iCalFreeBusy */