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