1 /* UIxCalDayTable.m - this file is part of SOGo
3 * Copyright (C) 2006 Inverse groupe conseil
5 * Author: Wolfgang Sourdeau <wsourdeau@inverse.ca>
7 * This file is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 2, or (at your option)
12 * This file is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
17 * You should have received a copy of the GNU General Public License
18 * along with this program; see the file COPYING. If not, write to
19 * the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
20 * Boston, MA 02111-1307, USA.
23 #import <Foundation/NSArray.h>
24 #import <Foundation/NSCalendarDate.h>
25 #import <Foundation/NSDictionary.h>
26 #import <Foundation/NSKeyValueCoding.h>
27 #import <Foundation/NSString.h>
28 #import <Foundation/NSUserDefaults.h>
30 #import <NGExtensions/NSCalendarDate+misc.h>
31 #import <EOControl/EOQualifier.h>
33 #import <SoObjects/SOGo/SOGoDateFormatter.h>
34 #import <SoObjects/SOGo/SOGoUser.h>
36 #import "UIxCalDayTable.h"
38 @class SOGoAppointment;
40 @implementation UIxCalDayTable
44 if ((self = [super init]))
50 currentTableDay = nil;
51 currentTableHour = nil;
52 weekDays = [[context valueForKey: @"locale"] objectForKey: NSShortWeekDayNameArray];
54 dateFormatter = [[context activeUser] dateFormatterInContext: context];
62 // if (allAppointments)
63 // [allAppointments release];
65 [daysToDisplay release];
66 [hoursToDisplay release];
70 - (void) setNumberOfDays: (NSString *) aNumber
72 numberOfDays = [aNumber intValue];
73 [daysToDisplay release];
77 - (NSString *) numberOfDays
79 return [NSString stringWithFormat: @"%d", numberOfDays];
82 - (void) setStartDate: (NSCalendarDate *) aStartDate
84 startDate = aStartDate;
85 [daysToDisplay release];
89 - (NSCalendarDate *) startDate
92 startDate = [super startDate];
94 return [startDate beginOfDay];
97 - (NSCalendarDate *) endDate
99 NSCalendarDate *endDate;
101 endDate = [[self startDate] dateByAddingYears: 0
103 days: numberOfDays - 1];
105 return [endDate endOfDay];
108 - (NSArray *) hoursToDisplay
110 unsigned int currentHour, lastHour;
114 currentHour = [self dayStartHour];
115 lastHour = [self dayEndHour];
116 hoursToDisplay = [NSMutableArray new];
118 while (currentHour < lastHour)
121 addObject: [NSString stringWithFormat: @"%d", currentHour]];
125 addObject: [NSString stringWithFormat: @"%d", currentHour]];
128 return hoursToDisplay;
131 - (NSArray *) daysToDisplay
133 NSCalendarDate *currentDate;
138 daysToDisplay = [NSMutableArray new];
139 currentDate = [[self startDate] hour: [self dayStartHour]
141 [daysToDisplay addObject: currentDate];
142 for (count = 1; count < numberOfDays; count++)
143 [daysToDisplay addObject: [currentDate dateByAddingYears: 0
149 return daysToDisplay;
152 - (void) setCurrentTableDay: (NSCalendarDate *) aTableDay
154 currentTableDay = aTableDay;
157 - (NSCalendarDate *) currentTableDay
159 return currentTableDay;
162 - (void) setCurrentTableHour: (NSString *) aTableHour
164 currentTableHour = aTableHour;
167 - (NSString *) currentTableHour
169 return currentTableHour;
172 - (NSString *) currentAppointmentHour
174 return [NSString stringWithFormat: @"%.2d00", [currentTableHour intValue]];
177 - (NSString *) labelForDay
179 return [weekDays objectAtIndex: [currentTableDay dayOfWeek]];
182 - (NSString *) labelForDate
184 return [dateFormatter shortFormattedDate: currentTableDay];
187 // - (NSDictionary *) _adjustedAppointment: (NSDictionary *) anAppointment
188 // forStart: (NSCalendarDate *) start
189 // andEnd: (NSCalendarDate *) end
191 // NSMutableDictionary *newMutableAppointment;
192 // NSDictionary *newAppointment;
193 // BOOL startIsEarlier, endIsLater;
196 // = ([[anAppointment objectForKey: @"startDate"] laterDate: start] == start);
198 // = ([[anAppointment objectForKey: @"endDate"] earlierDate: end] == end);
200 // if (startIsEarlier || endIsLater)
202 // newMutableAppointment
203 // = [NSMutableDictionary dictionaryWithDictionary: anAppointment];
205 // if (startIsEarlier)
206 // [newMutableAppointment setObject: start
207 // forKey: @"startDate"];
209 // [newMutableAppointment setObject: end
210 // forKey: @"endDate"];
212 // newAppointment = newMutableAppointment;
215 // newAppointment = anAppointment;
217 // return newAppointment;
220 // - (NSArray *) appointmentsForCurrentDay
222 // NSMutableArray *filteredAppointments;
223 // NSEnumerator *aptsEnumerator;
224 // NSDictionary *currentDayAppointment;
225 // NSCalendarDate *start, *end;
228 // if (!allAppointments)
230 // allAppointments = [self fetchCoreAppointmentsInfos];
231 // [allAppointments retain];
234 // filteredAppointments = [NSMutableArray new];
235 // [filteredAppointments autorelease];
237 // start = [currentTableDay hour: [self dayStartHour] minute: 0];
238 // endHour = [self dayEndHour];
240 // end = [currentTableDay hour: [self dayEndHour] minute: 59];
242 // end = [[currentTableDay tomorrow] hour: 0 minute: 0];
244 // aptsEnumerator = [allAppointments objectEnumerator];
245 // currentDayAppointment = [aptsEnumerator nextObject];
246 // while (currentDayAppointment)
248 // if (([end laterDate: [currentDayAppointment
249 // valueForKey: @"startDate"]] == end)
250 // && ([start earlierDate: [currentDayAppointment
251 // valueForKey: @"endDate"]] == start))
252 // [filteredAppointments
253 // addObject: [self _adjustedAppointment: currentDayAppointment
254 // forStart: start andEnd: end]];
255 // currentDayAppointment = [aptsEnumerator nextObject];
258 // return filteredAppointments;
261 // - (void) setCurrentAppointment: (NSDictionary *) newCurrentAppointment
263 // currentAppointment = newCurrentAppointment;
266 // - (NSDictionary *) currentAppointment
268 // return currentAppointment;
271 - (NSString *) appointmentsClasses
273 return [NSString stringWithFormat: @"appointments appointmentsFor%dDays",
277 - (NSString *) daysViewClasses
279 return [NSString stringWithFormat: @"daysView daysViewFor%dDays", numberOfDays];
282 - (NSString *) dayClasses
284 NSMutableString *classes;
287 classes = [NSMutableString new];
288 [classes autorelease];
289 [classes appendFormat: @"day day%d", [currentTableDay dayOfWeek]];
290 if (numberOfDays > 1)
292 dayOfWeek = [currentTableDay dayOfWeek];
293 if (dayOfWeek == 0 || dayOfWeek == 6)
294 [classes appendString: @" weekEndDay"];
295 if ([currentTableDay isToday])
296 [classes appendString: @" dayOfToday"];
297 if ([[self selectedDate] isDateOnSameDay: currentTableDay])
298 [classes appendString: @" selectedDay"];
304 - (NSString *) clickableHourCellClass
306 return [NSString stringWithFormat: @"clickableHourCell clickableHourCell%@", currentTableHour];