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 <NGObjWeb/NGObjWeb.h>
29 @interface UIxCalInlineAptView : WOComponent
31 NSDictionary *appointment;
46 #include <SOGoUI/SOGoAptFormatter.h>
47 #include <SOGo/SOGoUser.h>
48 #include <NGObjWeb/WOContext+SoObjects.h>
50 @implementation UIxCalInlineAptView
54 if ((self = [super init]))
66 [appointment release];
68 [tooltipFormatter release];
71 [queryDictionary release];
72 [referenceDate release];
76 - (void) setAppointment: (NSDictionary *) _appointment
78 ASSIGN(appointment, _appointment);
81 - (NSDictionary *) appointment
86 - (void) setDayStartHour: (unsigned int) anHour
88 dayStartHour = anHour;
91 - (void) setDayEndHour: (unsigned int) anHour
96 - (void) setFormatter: (id) _formatter
98 ASSIGN(formatter, _formatter);
106 - (void) setTooltipFormatter: (id) _tooltipFormatter
108 ASSIGN(tooltipFormatter, _tooltipFormatter);
111 - (id) tooltipFormatter
113 return tooltipFormatter;
116 - (void) setUrl: (id) _url
126 - (void) setStyle: (id) _style
134 ms = [NSMutableString stringWithString: _style];
136 ms = (NSMutableString *)[NSMutableString string];
138 if ((prio = [appointment valueForKey:@"priority"])) {
139 [ms appendFormat:@" apt_prio%@", prio];
141 email = [[[self context] activeUser] email];
142 if ((s = [appointment valueForKey:@"orgmail"])) {
143 if ([s rangeOfString:email].length > 0) {
144 [ms appendString:@" apt_organizer"];
147 [ms appendString:@" apt_other"];
150 if ((s = [appointment valueForKey:@"partmails"])) {
151 if ([s rangeOfString:email].length > 0) {
152 [ms appendString:@" apt_participant"];
155 [ms appendString:@" apt_nonparticipant"];
158 ASSIGNCOPY(style, ms);
165 - (void) setQueryDictionary: (id) _queryDictionary
167 ASSIGN(queryDictionary, _queryDictionary);
170 - (id) queryDictionary
172 return queryDictionary;
175 - (void) setReferenceDate: (id) _referenceDate
177 ASSIGN(referenceDate, _referenceDate);
182 return referenceDate;
185 - (void) setCanAccess: (BOOL) _canAccess
187 canAccess = _canAccess;
195 - (NSString *) displayClasses
197 NSTimeInterval secondsStart, secondsEnd, delta;
198 NSCalendarDate *startDate;
199 int deltaStart, deltaLength;
201 startDate = [appointment objectForKey: @"startDate"];
202 secondsStart = [startDate timeIntervalSince1970];
203 secondsEnd = [[appointment objectForKey: @"endDate"] timeIntervalSince1970];
204 delta = (secondsEnd - [startDate timeIntervalSince1970]) / 60;
205 deltaLength = delta / 15;
206 if (((int) delta % 15) > 0)
209 deltaStart = (([startDate hourOfDay] * 60 + [startDate minuteOfHour]
210 - dayStartHour * 60) / 15);
212 return [NSString stringWithFormat: @"appointment ownerIs%@ starts%d lasts%d",
213 [appointment objectForKey: @"owner"],
214 deltaStart, deltaLength, [startDate dayOfWeek]];
217 - (NSString *) innerDisplayClasses
219 return [NSString stringWithFormat: @"appointmentInside ownerIs%@",
220 [appointment objectForKey: @"owner"]];
223 - (NSString *) displayStyle
225 NSCalendarDate *startDate, *endDate, *dayStart, *dayEnd;
226 int sSeconds, eSeconds, deltaMinutes;
230 uTZ = [referenceDate timeZone];
231 dayStart = [referenceDate beginOfDay];
232 dayEnd = [referenceDate endOfDay];
234 sSeconds = [[appointment objectForKey: @"startdate"] intValue];
235 eSeconds = [[appointment objectForKey: @"enddate"] intValue];
236 startDate = [NSCalendarDate dateWithTimeIntervalSince1970: sSeconds];
237 [startDate setTimeZone: uTZ];
238 if ([startDate earlierDate: dayStart] == startDate)
239 startDate = dayStart;
240 endDate = [NSCalendarDate dateWithTimeIntervalSince1970: eSeconds];
241 [endDate setTimeZone: uTZ];
242 if ([endDate earlierDate: dayEnd] == dayEnd)
245 deltaMinutes = (([endDate hourOfDay] - [startDate hourOfDay]) * 60
246 + [endDate minuteOfHour] - [startDate minuteOfHour]);
247 height = ceil(deltaMinutes / 15) * 25;
249 return [NSString stringWithFormat: @"height: %d%%;", height];
256 return [formatter stringForObjectValue: appointment
257 referenceDate: [self referenceDate]];
260 - (NSString *) tooltip
262 return [tooltipFormatter stringForObjectValue: appointment
263 referenceDate: [self referenceDate]];