]> err.no Git - scalable-opengroupware.org/blob - UI/Scheduler/UIxCalInlineAptView.m
a0bc0d8226cbe82fae0538db3dcbfaae26ecaabf
[scalable-opengroupware.org] / UI / Scheduler / UIxCalInlineAptView.m
1 /*
2  Copyright (C) 2000-2004 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 #import <math.h>
24
25 #import <Foundation/NSDictionary.h>
26
27 #import <NGExtensions/NSNull+misc.h>
28 #import <NGExtensions/NSCalendarDate+misc.h>
29 #import <NGObjWeb/WOContext+SoObjects.h>
30
31 #import <NGCards/iCalEntityObject.h>
32 #import <SOGo/SOGoAuthenticator.h>
33 #import <SOGo/SOGoUser.h>
34 #import <SOGoUI/SOGoAptFormatter.h>
35
36 #import "UIxCalInlineAptView.h"
37
38 @implementation UIxCalInlineAptView
39
40 - (id) init
41 {
42   if ((self = [super init]))
43     {
44       dayStartHour = 0;
45       dayEndHour = 24;
46       appointment = nil;
47     }
48
49   return self;
50 }
51
52 - (void) dealloc
53 {
54   [appointment release];
55   [formatter release];
56   [tooltipFormatter release];
57   [url release];
58   [style release];
59   [queryDictionary release];
60   [referenceDate release];
61   [super dealloc];
62 }
63
64 - (void) setAppointment: (NSDictionary *) _appointment
65 {
66   ASSIGN(appointment, _appointment);
67 }
68
69 - (NSDictionary *) appointment
70 {
71   return appointment;
72 }
73
74 - (void) setDayStartHour: (unsigned int) anHour
75 {
76   dayStartHour = anHour;
77 }
78
79 - (void) setDayEndHour: (unsigned int) anHour
80 {
81   dayEndHour = anHour;
82 }
83
84 - (void) setFormatter: (id) _formatter
85 {
86   ASSIGN(formatter, _formatter);
87 }
88
89 - (id) formatter
90 {
91   return formatter;
92 }
93
94 - (void) setTooltipFormatter: (id) _tooltipFormatter
95 {
96   ASSIGN(tooltipFormatter, _tooltipFormatter);
97 }
98
99 - (id) tooltipFormatter
100 {
101   return tooltipFormatter;
102 }
103
104 - (void) setUrl: (id) _url
105 {
106   ASSIGN(url, _url);
107 }
108
109 - (id) url
110 {
111   return url;
112 }
113
114 - (void) setStyle: (id) _style 
115 {
116   NSMutableString *ms;
117   NSNumber *prio;
118   NSString *s;
119   NSString *email;
120
121   if (_style)
122     ms = [NSMutableString stringWithString: _style];
123   else
124     ms = (NSMutableString *)[NSMutableString string];
125
126   if ((prio = [appointment valueForKey:@"priority"])) {
127     [ms appendFormat:@" apt_prio%@", prio];
128   }
129   email = [[[self context] activeUser] email];
130   s = [appointment valueForKey:@"orgmail"];
131   if ([s isNotNull])
132     {
133       if ([s rangeOfString: email].length > 0)
134         [ms appendString:@" apt_organizer"];
135       else
136         [ms appendString:@" apt_other"];
137     }
138   s = [appointment valueForKey:@"partmails"];
139   if ([s isNotNull])
140     {
141       if ([s rangeOfString:email].length > 0)
142         [ms appendString:@" apt_participant"];
143       else
144         [ms appendString:@" apt_nonparticipant"];
145     }
146   ASSIGNCOPY(style, ms);
147 }
148
149 - (id)style {
150   return style;
151 }
152
153 - (void) setQueryDictionary: (id) _queryDictionary
154 {
155   ASSIGN(queryDictionary, _queryDictionary);
156 }
157
158 - (id) queryDictionary
159 {
160   return queryDictionary;
161 }
162
163 - (void) setReferenceDate: (id) _referenceDate
164 {
165   ASSIGN(referenceDate, _referenceDate);
166 }
167
168 - (id) referenceDate
169 {
170   return referenceDate;
171 }
172
173 - (void) setCanAccess: (BOOL) _canAccess
174 {
175   canAccess = _canAccess;
176 }
177
178 - (BOOL) canAccess
179 {
180   return canAccess;
181 }
182
183 - (NSString *) displayClasses
184 {
185   NSTimeInterval secondsStart, secondsEnd, delta;
186   NSCalendarDate *startDate;
187   int deltaStart, deltaLength;
188
189   startDate = [appointment objectForKey: @"startDate"];
190   secondsStart = [startDate timeIntervalSince1970];
191   secondsEnd = [[appointment objectForKey: @"endDate"] timeIntervalSince1970];
192   delta = (secondsEnd - [startDate timeIntervalSince1970]) / 60;
193   deltaLength = delta / 15;
194   if (((int) delta % 15) > 0)
195     deltaLength += 1;
196
197   deltaStart = (([startDate hourOfDay] * 60 + [startDate minuteOfHour]
198                  - dayStartHour * 60) / 15);
199
200   return [NSString stringWithFormat: @"appointment starts%d lasts%d",
201                    deltaStart, deltaLength, [startDate dayOfWeek]];
202 }
203
204 - (NSString *) innerDisplayClasses
205 {
206   return [NSString stringWithFormat: @"appointmentInside ownerIs%@",
207                    [appointment objectForKey: @"owner"]];
208 }
209
210 - (NSString *) displayStyle
211 {
212   NSCalendarDate *startDate, *endDate, *dayStart, *dayEnd;
213   int sSeconds, eSeconds, deltaMinutes;
214   unsigned int height;
215   NSTimeZone *uTZ;
216
217   uTZ = [referenceDate timeZone];
218   dayStart = [referenceDate beginOfDay];
219   dayEnd = [referenceDate endOfDay];
220
221   sSeconds = [[appointment objectForKey: @"startdate"] intValue];
222   eSeconds = [[appointment objectForKey: @"enddate"] intValue];
223   startDate = [NSCalendarDate dateWithTimeIntervalSince1970: sSeconds];
224   [startDate setTimeZone: uTZ];
225   if ([startDate earlierDate: dayStart] == startDate)
226     startDate = dayStart;
227   endDate = [NSCalendarDate dateWithTimeIntervalSince1970: eSeconds];
228   [endDate setTimeZone: uTZ];
229   if ([endDate earlierDate: dayEnd] == dayEnd)
230     endDate = dayEnd;
231
232   deltaMinutes = (([endDate hourOfDay] - [startDate hourOfDay]) * 60
233                   + [endDate minuteOfHour] - [startDate minuteOfHour]);
234   height = ceil(deltaMinutes / 15) * 25;
235
236   return [NSString stringWithFormat: @"height: %d%%;", height];
237 }
238
239 /* helpers */
240
241 - (NSString *) startHour
242 {
243   NSCalendarDate *start;
244
245   start = [appointment objectForKey: @"startDate"];
246
247   return [NSString stringWithFormat: @"%.2d:%.2d",
248                    [start hourOfDay], [start minuteOfHour]];
249 }
250
251 - (NSString *) title
252 {
253   return [formatter stringForObjectValue: appointment
254                     referenceDate: [self referenceDate]];
255 }
256
257 - (NSString *) tooltip
258 {
259   return [tooltipFormatter stringForObjectValue: appointment
260                            referenceDate: [self referenceDate]];
261 }
262
263 - (BOOL) _userIsInTheCard: (NSString *) email
264 {
265   NSString *orgMailString, *partMailsString;
266   NSArray *partMails;
267   BOOL userIsInTheCard;
268
269   orgMailString = [appointment objectForKey: @"orgmail"];
270   if ([orgMailString isNotNull] && [orgMailString isEqualToString: email])
271     userIsInTheCard = YES;
272   else
273     {
274       partMailsString = [appointment objectForKey: @"partmails"];
275       if ([partMailsString isNotNull])
276         {
277           partMails = [partMailsString componentsSeparatedByString: @"\n"];
278           userIsInTheCard = [partMails containsObject: email];
279         }
280       else
281         userIsInTheCard = NO;
282     }
283
284   return userIsInTheCard;
285 }
286
287 @end