2 Copyright (C) 2000-2004 SKYRIX Software AG
4 This file is part of OGo
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
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.
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
25 #import <Foundation/NSDictionary.h>
27 #import <NGExtensions/NSNull+misc.h>
28 #import <NGExtensions/NSCalendarDate+misc.h>
29 #import <NGObjWeb/WOContext+SoObjects.h>
31 #import <NGCards/iCalEntityObject.h>
32 #import <SOGo/SOGoAuthenticator.h>
33 #import <SOGo/SOGoUser.h>
34 #import <SOGoUI/SOGoAptFormatter.h>
36 #import "UIxCalInlineAptView.h"
38 @implementation UIxCalInlineAptView
42 if ((self = [super init]))
54 [appointment release];
56 [tooltipFormatter release];
59 [queryDictionary release];
60 [referenceDate release];
64 - (void) setAppointment: (NSDictionary *) _appointment
66 ASSIGN(appointment, _appointment);
69 - (NSDictionary *) appointment
74 - (void) setDayStartHour: (unsigned int) anHour
76 dayStartHour = anHour;
79 - (void) setDayEndHour: (unsigned int) anHour
84 - (void) setFormatter: (id) _formatter
86 ASSIGN(formatter, _formatter);
94 - (void) setTooltipFormatter: (id) _tooltipFormatter
96 ASSIGN(tooltipFormatter, _tooltipFormatter);
99 - (id) tooltipFormatter
101 return tooltipFormatter;
104 - (void) setUrl: (id) _url
114 - (void) setStyle: (id) _style
122 ms = [NSMutableString stringWithString: _style];
124 ms = (NSMutableString *)[NSMutableString string];
126 if ((prio = [appointment valueForKey:@"priority"])) {
127 [ms appendFormat:@" apt_prio%@", prio];
129 email = [[[self context] activeUser] email];
130 s = [appointment valueForKey:@"orgmail"];
133 if ([s rangeOfString: email].length > 0)
134 [ms appendString:@" apt_organizer"];
136 [ms appendString:@" apt_other"];
138 s = [appointment valueForKey:@"partmails"];
141 if ([s rangeOfString:email].length > 0)
142 [ms appendString:@" apt_participant"];
144 [ms appendString:@" apt_nonparticipant"];
146 ASSIGNCOPY(style, ms);
153 - (void) setQueryDictionary: (id) _queryDictionary
155 ASSIGN(queryDictionary, _queryDictionary);
158 - (id) queryDictionary
160 return queryDictionary;
163 - (void) setReferenceDate: (id) _referenceDate
165 ASSIGN(referenceDate, _referenceDate);
170 return referenceDate;
173 - (void) setCanAccess: (BOOL) _canAccess
175 canAccess = _canAccess;
183 - (NSString *) displayClasses
185 NSTimeInterval secondsStart, secondsEnd, delta;
186 NSCalendarDate *startDate;
187 int deltaStart, deltaLength;
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)
197 deltaStart = (([startDate hourOfDay] * 60 + [startDate minuteOfHour]
198 - dayStartHour * 60) / 15);
200 return [NSString stringWithFormat: @"appointment starts%d lasts%d",
201 deltaStart, deltaLength, [startDate dayOfWeek]];
204 - (NSString *) innerDisplayClasses
206 return [NSString stringWithFormat: @"appointmentInside ownerIs%@",
207 [appointment objectForKey: @"owner"]];
210 - (NSString *) displayStyle
212 NSCalendarDate *startDate, *endDate, *dayStart, *dayEnd;
213 int sSeconds, eSeconds, deltaMinutes;
217 uTZ = [referenceDate timeZone];
218 dayStart = [referenceDate beginOfDay];
219 dayEnd = [referenceDate endOfDay];
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)
232 deltaMinutes = (([endDate hourOfDay] - [startDate hourOfDay]) * 60
233 + [endDate minuteOfHour] - [startDate minuteOfHour]);
234 height = ceil(deltaMinutes / 15) * 25;
236 return [NSString stringWithFormat: @"height: %d%%;", height];
241 - (NSString *) startHour
243 NSCalendarDate *start;
245 start = [appointment objectForKey: @"startDate"];
247 return [NSString stringWithFormat: @"%.2d:%.2d",
248 [start hourOfDay], [start minuteOfHour]];
253 return [formatter stringForObjectValue: appointment
254 referenceDate: [self referenceDate]];
257 - (NSString *) tooltip
259 return [tooltipFormatter stringForObjectValue: appointment
260 referenceDate: [self referenceDate]];
263 - (BOOL) _userIsInTheCard: (NSString *) email
265 NSString *orgMailString, *partMailsString;
267 BOOL userIsInTheCard;
269 orgMailString = [appointment objectForKey: @"orgmail"];
270 if ([orgMailString isNotNull] && [orgMailString isEqualToString: email])
271 userIsInTheCard = YES;
274 partMailsString = [appointment objectForKey: @"partmails"];
275 if ([partMailsString isNotNull])
277 partMails = [partMailsString componentsSeparatedByString: @"\n"];
278 userIsInTheCard = [partMails containsObject: email];
281 userIsInTheCard = NO;
284 return userIsInTheCard;
287 - (BOOL) titleShouldBeHidden
291 SOGoAuthenticator *sAuth;
293 sAuth = [SOGoAuthenticator sharedSOGoAuthenticator];
294 user = [sAuth userInContext: context];
296 if ([[appointment objectForKey: @"owner"] isEqualToString: [user login]]
297 || ([[appointment objectForKey: @"classification"] intValue]
298 != iCalAccessConfidential))
301 shouldBeHidden = ![self _userIsInTheCard: [user email]];
303 return shouldBeHidden;