]> err.no Git - scalable-opengroupware.org/blob - UI/Scheduler/UIxCalMulticolumnDayView.m
Install libs to /usr/lib
[scalable-opengroupware.org] / UI / Scheduler / UIxCalMulticolumnDayView.m
1 /* UIxCalMulticolumnDayView.h - this file is part of SOGo
2  *
3  * Copyright (C) 2006 Inverse groupe conseil
4  *
5  * Author: Wolfgang Sourdeau <wsourdeau@inverse.ca>
6  *
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)
10  * any later version.
11  *
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.
16  *
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.
21  */
22
23 #import <Foundation/NSArray.h>
24 #import <Foundation/NSDictionary.h>
25 #import <Foundation/NSString.h>
26 #import <Foundation/NSUserDefaults.h>
27 #import <Foundation/NSValue.h>
28
29 #import <NGExtensions/NSCalendarDate+misc.h>
30
31 #import <SoObjects/SOGo/SOGoUser.h>
32 #import <SoObjects/SOGo/SOGoDateFormatter.h>
33
34 #import "UIxCalMulticolumnDayView.h"
35
36 @implementation UIxCalMulticolumnDayView : UIxCalDayView
37
38 - (id) init
39 {
40   if ((self = [super init]))
41     {
42 //       allAppointments = nil;
43       subscriptionUsers = nil;
44       hoursToDisplay = nil;
45       currentTableUser = nil;
46       currentTableHour = nil;
47 //       dateFormatter = [[SOGoDateFormatter alloc]
48 //                         initWithLocale: [self locale]];
49     }
50
51   return self;
52 }
53
54 - (void) dealloc
55 {
56 //   [allAppointments release];
57   [subscriptionUsers release];
58   [hoursToDisplay release];
59 //   [dateFormatter release];
60   [super dealloc];
61 }
62
63 - (void) setCSSClass: (NSString *) aCssClass
64 {
65   cssClass = aCssClass;
66 }
67
68 - (NSString *) cssClass
69 {
70   return cssClass;
71 }
72
73 - (void) setCSSId: (NSString *) aCssId
74 {
75   cssId = aCssId;
76 }
77
78 - (NSString *) cssId
79 {
80   return cssId;
81 }
82
83 - (NSArray *) hoursToDisplay
84 {
85   unsigned int currentHour, lastHour;
86
87   if (!hoursToDisplay)
88     {
89       currentHour = [self dayStartHour];
90       lastHour = [self dayEndHour];
91       hoursToDisplay = [NSMutableArray new];
92
93       while (currentHour < lastHour)
94         {
95           [hoursToDisplay
96             addObject: [NSString stringWithFormat: @"%d", currentHour]];
97           currentHour++;
98         }
99       [hoursToDisplay
100         addObject: [NSString stringWithFormat: @"%d", currentHour]];
101     }
102
103   return hoursToDisplay;
104 }
105
106 - (NSArray *) subscriptionUsers
107 {
108   SOGoUser *activeUser;
109   NSString *userList, *currentUserLogin;
110   NSEnumerator *users;
111
112   if (!subscriptionUsers)
113     {
114       subscriptionUsers = [NSMutableArray new];
115       activeUser = [context activeUser];
116       userList = [[activeUser userDefaults] objectForKey: @"calendaruids"];
117       users = [[userList componentsSeparatedByString: @","] objectEnumerator];
118       currentUserLogin = [users nextObject];
119       while (currentUserLogin)
120         {
121           if (![currentUserLogin hasPrefix: @"-"])
122             [subscriptionUsers addObject: currentUserLogin];
123           currentUserLogin = [users nextObject];
124         }
125     }
126
127   return subscriptionUsers;
128 }
129
130 - (void) setCurrentTableUser: (NSString *) aTableUser;
131 {
132   currentTableUser = aTableUser;
133 }
134
135 - (NSString *) currentTableUser;
136 {
137   return currentTableUser;
138 }
139
140 - (void) setCurrentTableHour: (NSString *) aTableHour
141 {
142   currentTableHour = aTableHour;
143 }
144
145 - (NSString *) currentTableHour
146 {
147   return currentTableHour;
148 }
149
150 - (NSString *) currentAppointmentHour
151 {
152   return [NSString stringWithFormat: @"%.2d00", [currentTableHour intValue]];
153 }
154
155 - (NSDictionary *) _adjustedAppointment: (NSDictionary *) anAppointment
156                                forStart: (NSCalendarDate *) start
157                                  andEnd: (NSCalendarDate *) end
158 {
159   NSMutableDictionary *newMutableAppointment;
160   NSDictionary *newAppointment;
161   BOOL startIsEarlier, endIsLater;
162
163   startIsEarlier
164     = ([[anAppointment objectForKey: @"startDate"] laterDate: start] == start);
165   endIsLater
166     = ([[anAppointment objectForKey: @"endDate"] earlierDate: end] == end);
167
168   if (startIsEarlier || endIsLater)
169     {
170       newMutableAppointment
171         = [NSMutableDictionary dictionaryWithDictionary: anAppointment];
172       
173       if (startIsEarlier)
174         [newMutableAppointment setObject: start
175                                forKey: @"startDate"];
176       if (endIsLater)
177         [newMutableAppointment setObject: end
178                                forKey: @"endDate"];
179
180       newAppointment = newMutableAppointment;
181     }
182   else
183     newAppointment = anAppointment;
184
185   return newAppointment;
186 }
187
188 /* fetching */
189
190 // - (NSCalendarDate *) startDate
191 // {
192 //   return [[self selectedDate] beginOfDay];
193 // }
194
195 // - (NSCalendarDate *) endDate
196 // {
197 //   return [[self selectedDate] endOfDay];
198 // }
199
200 // - (NSArray *) appointmentsForCurrentUser
201 // {
202 //   NSMutableArray *filteredAppointments;
203 //   NSEnumerator *aptsEnumerator;
204 //   NSDictionary *userAppointment;
205 //   NSCalendarDate *start, *end;
206 //   int endHour;
207
208 //   if (!allAppointments)
209 //     {
210 //       allAppointments = [self fetchCoreAppointmentsInfos];
211 //       [allAppointments retain];
212 //     }
213
214 //   start = [[self selectedDate] hour: [self dayStartHour] minute: 0];
215 //   endHour = [self dayEndHour];
216 //   if (endHour < 24)
217 //     end = [[self selectedDate] hour: [self dayEndHour] minute: 59];
218 //   else
219 //     end = [[[self selectedDate] tomorrow] hour: 0 minute: 0];
220
221 //   filteredAppointments = [NSMutableArray new];
222 //   [filteredAppointments autorelease];
223
224 //   aptsEnumerator = [allAppointments objectEnumerator];
225 //   userAppointment = [aptsEnumerator nextObject];
226 //   while (userAppointment)
227 //     {
228 //       if ([[userAppointment objectForKey: @"owner"]
229 //             isEqualToString: currentTableUser])
230 //         [filteredAppointments
231 //           addObject: [self _adjustedAppointment: userAppointment
232 //                            forStart: start andEnd: end]];
233 //       userAppointment = [aptsEnumerator nextObject];
234 //     }
235
236 //   return filteredAppointments;
237 // }
238
239 // - (void) setCurrentAppointment: (NSDictionary *) newCurrentAppointment
240 // {
241 //   currentAppointment = newCurrentAppointment;
242 // }
243
244 // - (NSDictionary *) currentAppointment
245 // {
246 //   return currentAppointment;
247 // }
248
249 // - (NSString *) appointmentsClasses
250 // {
251 //   return @"appointments appointmentsFor1Days";
252 // }
253
254 - (NSString *) currentUserClasses
255 {
256   NSArray *users;
257   NSString *lastDayUser;
258
259   users = [self subscriptionUsers];
260
261   if (currentTableUser == [users lastObject])
262     lastDayUser = @" lastDayUser";
263   else
264     lastDayUser = @"";
265     
266   return [NSString stringWithFormat: @"day appointmentsOf%@%@",
267                    currentTableUser, lastDayUser];
268 }
269
270 - (NSString *) clickableHourCellClass
271 {
272   return [NSString stringWithFormat: @"clickableHourCell clickableHourCell%@", currentTableHour];
273 }
274
275 - (NSNumber *) dayWidthPercentage
276 {
277   NSArray *users;
278
279   users = [self subscriptionUsers];
280
281   return [NSNumber numberWithFloat: (100.0 / [users count])];
282 }
283
284 - (NSNumber *) currentTableUserDayLeftPercentage
285 {
286   NSArray *users;
287
288   users = [self subscriptionUsers];
289
290   return [NSNumber numberWithFloat: ([users indexOfObject: currentTableUser]
291                                      * (100.0 / [users count]))];
292 }
293
294 @end