]> err.no Git - scalable-opengroupware.org/blob - UI/Scheduler/UIxCalDayView.m
git-svn-id: http://svn.opengroupware.org/SOGo/inverse/trunk@1089 d1b88da0-ebda-0310...
[scalable-opengroupware.org] / UI / Scheduler / UIxCalDayView.m
1 /*
2   Copyright (C) 2004 SKYRIX Software AG
3
4   This file is part of OpenGroupware.org.
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
22 #import <Foundation/NSArray.h>
23 #import <Foundation/NSCalendarDate.h>
24 #import <Foundation/NSDictionary.h>
25 #import <Foundation/NSKeyValueCoding.h>
26 #import <Foundation/NSString.h>
27 #import <Foundation/NSValue.h>
28
29 #import <EOControl/EOQualifier.h>
30
31 #import <NGExtensions/NSCalendarDate+misc.h>
32 #import <NGExtensions/NGCalendarDateRange.h>
33
34 #import <SoObjects/SOGo/SOGoDateFormatter.h>
35
36 #import "UIxCalDayView.h"
37
38 // @interface UIxCalDayView (PrivateAPI)
39 // - (BOOL)isCurrentDateInApt:(id)_apt;
40 // - (NSArray *)_getDatesFrom:(NSCalendarDate *)_from to:(NSCalendarDate *)_to;
41 // @end
42
43 @implementation UIxCalDayView
44
45 // - (void) dealloc
46 // {
47 //   [self->currentDate release];
48 //   [super dealloc];
49 // }
50
51 // - (void) setCurrentDate: (NSCalendarDate *) _date
52 // {
53 //   ASSIGN(self->currentDate, _date);
54 // }
55
56 // - (NSCalendarDate *) currentDate
57 // {
58 //   return self->currentDate;
59 // }
60
61 // - (BOOL) isCurrentDateInApt
62 // {
63 //   return [self isCurrentDateInApt: [self appointment]];
64 // }
65
66 // - (BOOL) isCurrentDateInApt: (id) _apt
67 // {
68 //   NSCalendarDate *dateStart, *dateEnd, *aptStart, *aptEnd;
69 //   NGCalendarDateRange *dateRange, *aptRange;
70     
71 //   dateStart = self->currentDate;
72 //   dateEnd   = [dateStart dateByAddingYears:0 months:0 days:0
73 //                          hours:1 minutes:0 seconds:0];
74 //   dateRange = [NGCalendarDateRange calendarDateRangeWithStartDate:dateStart
75 //                                    endDate:dateEnd];
76 //   aptStart = [self->appointment valueForKey:@"startDate"];
77 //   aptEnd   = [self->appointment valueForKey:@"endDate"];
78 //   aptRange = [NGCalendarDateRange calendarDateRangeWithStartDate:aptStart
79 //                                   endDate:aptEnd];
80
81 //   return [dateRange doesIntersectWithDateRange:aptRange];
82 // }
83
84 // - (NSArray *) dateRange
85 // {
86 //   /* default range is from dayStartHour to dayEndHour. Any values before
87 //      or after are also fine */
88
89 //   NSCalendarDate *min, *max;
90 //   NSArray        *aptDateRanges;
91
92 //   min = [[self startDate] hour:[self dayStartHour] minute:0];
93 //   max = [[self startDate] hour:[self dayEndHour]   minute:0];
94
95 //   aptDateRanges = [[self appointments] valueForKey: @"startDate"];
96 //   if([aptDateRanges count] != 0) {
97 //     NSCalendarDate *d;
98
99 //     aptDateRanges
100 //       = [aptDateRanges sortedArrayUsingSelector: @selector(compareAscending:)];
101 //     d   = [aptDateRanges objectAtIndex:0];
102 //     if ([d isDateOnSameDay:min])
103 //       min = (NSCalendarDate *)[d earlierDate:min];
104 //     d   = [aptDateRanges objectAtIndex:[aptDateRanges count] - 1];
105 //     if ([d isDateOnSameDay:max])
106 //       max = (NSCalendarDate *)[d laterDate:max];
107 //   }
108   
109 //   return [self _getDatesFrom:min to:max];
110 // }
111
112 // - (NSArray *) _getDatesFrom: (NSCalendarDate *) _from
113 //                          to: (NSCalendarDate *) _to
114 // {
115 //   NSMutableArray *dates;
116 //   unsigned       i, count, offset;
117
118 //   offset = [_from hourOfDay];
119 //   count  = ([_to hourOfDay] + 1) - offset;
120 //   dates  = [[NSMutableArray alloc] initWithCapacity:count];
121 //   for(i = 0; i < count; i++) {
122 //     NSCalendarDate *date;
123         
124 //     date = [_from hour:offset + i minute:0];
125 //     [dates addObject:date];
126 //   }
127 //   return [dates autorelease];
128 // }
129
130 /* URLs */
131
132 - (NSDictionary *) dayBeforePrevDayQueryParameters
133 {
134   return [self _dateQueryParametersWithOffset: -2];
135 }
136
137 - (NSDictionary *) prevDayQueryParameters
138 {
139   return [self _dateQueryParametersWithOffset: -1];
140 }
141
142 - (NSDictionary *) nextDayQueryParameters
143 {
144   return [self _dateQueryParametersWithOffset: 1];
145 }
146
147 - (NSDictionary *) dayAfterNextDayQueryParameters
148 {
149   return [self _dateQueryParametersWithOffset: 2];
150 }
151
152 - (NSDictionary *) currentDateQueryParameters
153 {
154   NSMutableDictionary *qp;
155   NSString *hmString;
156   NSCalendarDate *date;
157     
158   date = [self selectedDate];
159   hmString = [NSString stringWithFormat:@"%.2d%.2d",
160                        [date hourOfDay], [date minuteOfHour]];
161   qp = [[self queryParameters] mutableCopy];
162   [self setSelectedDateQueryParameter:date inDictionary:qp];
163   [qp setObject: hmString forKey:@"hm"];
164   return [qp autorelease];
165 }
166
167 /* fetching */
168
169 - (NSCalendarDate *) startDate
170 {
171   return [[self selectedDate] beginOfDay];
172 }
173
174 /* appointments */
175
176 // - (NSArray *)allDayApts {
177 //   NSCalendarDate *start;
178 //   NSArray        *apts;
179 //   NSMutableArray *filtered;
180 //   unsigned       i, count;
181   
182 //   if (self->allDayApts)
183 //     return self->allDayApts;
184
185 //   start    = [self startDate];
186 //   apts     = [self appointments];
187 //   filtered = [[NSMutableArray alloc] initWithCapacity:1];
188 //   count    = [apts count];
189 //   for (i = 0; i < count; i++) {
190 //     id       apt;
191 //     NSNumber *bv;
192     
193 //     apt = [apts objectAtIndex:i];
194 //     bv  = [apt valueForKey:@"isallday"];
195 //     if ([bv boolValue]) {
196 //       [filtered addObject:apt];
197 //     }
198 //     else {
199 //       NSCalendarDate *aptStartDate;
200
201 //       aptStartDate = [apt valueForKey:@"startDate"];
202 //       if([aptStartDate isLessThan:start]) {
203 //         [filtered addObject:apt];
204 //       }
205 //     }
206 //   }
207   
208 //   ASSIGN(self->allDayApts, filtered);
209 //   [filtered release];
210 //   return self->allDayApts;
211 // }
212
213 // - (BOOL) hasAptsForCurrentDate
214 // {
215 //   return [[self aptsForCurrentDate] count] != 0;
216 // }
217
218 - (NSString *) _dayNameWithOffsetFromToday: (int) offset
219 {
220   NSCalendarDate *date;
221
222   date = [[self selectedDate] dateByAddingYears: 0
223                               months: 0
224                               days: offset];
225
226   return [self localizedNameForDayOfWeek: [date dayOfWeek]];
227 }
228
229 - (NSString *) dayBeforeYesterdayName
230 {
231   return [self _dayNameWithOffsetFromToday: -2];
232 }
233
234 - (NSString *) yesterdayName
235 {
236   return [self _dayNameWithOffsetFromToday: -1];
237 }
238
239 - (NSString *) currentDayName
240 {
241   return [self _dayNameWithOffsetFromToday: 0];
242 }
243
244 - (NSString *) tomorrowName
245 {
246   return [self _dayNameWithOffsetFromToday: 1];
247 }
248
249 - (NSString *) dayAfterTomorrowName
250 {
251   return [self _dayNameWithOffsetFromToday: 2];
252 }
253
254 @end