2 Copyright (C) 2004 SKYRIX Software AG
4 This file is part of OpenGroupware.org.
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
24 #import "UIxCalDayView.h"
26 #include <EOControl/EOControl.h>
27 #include <NGExtensions/NGCalendarDateRange.h>
30 @interface UIxCalDayView (PrivateAPI)
31 - (BOOL)isCurrentDateInApt:(id)_apt;
32 - (NSArray *)_getDatesFrom:(NSCalendarDate *)_from to:(NSCalendarDate *)_to;
35 @implementation UIxCalDayView
38 [self->currentDate release];
42 - (void)setCurrentDate:(NSCalendarDate *)_date {
43 ASSIGN(self->currentDate, _date);
45 - (NSCalendarDate *)currentDate {
46 return self->currentDate;
49 - (BOOL)isCurrentDateInApt {
50 return [self isCurrentDateInApt:[self appointment]];
53 - (BOOL)isCurrentDateInApt:(id)_apt {
54 NSCalendarDate *dateStart, *dateEnd, *aptStart, *aptEnd;
55 NGCalendarDateRange *dateRange, *aptRange;
57 dateStart = self->currentDate;
58 dateEnd = [dateStart dateByAddingYears:0 months:0 days:0
59 hours:1 minutes:0 seconds:0];
60 dateRange = [NGCalendarDateRange calendarDateRangeWithStartDate:dateStart
62 aptStart = [self->appointment valueForKey:@"startDate"];
63 aptEnd = [self->appointment valueForKey:@"endDate"];
64 aptRange = [NGCalendarDateRange calendarDateRangeWithStartDate:aptStart
66 return [dateRange doesIntersectWithDateRange:aptRange];
69 - (NSArray *)dateRange {
70 /* default range is from dayStartHour to dayEndHour. Any values before
71 or after are also fine */
73 NSCalendarDate *min, *max;
74 NSArray *aptDateRanges;
76 min = [[self startDate] hour:[self dayStartHour] minute:0];
77 max = [[self startDate] hour:[self dayEndHour] minute:0];
79 aptDateRanges = [[self appointments] valueForKey:@"startDate"];
80 if([aptDateRanges count] != 0) {
83 aptDateRanges = [aptDateRanges sortedArrayUsingSelector:@selector(compareAscending:)];
84 d = [aptDateRanges objectAtIndex:0];
85 if ([d isDateOnSameDay:min])
86 min = (NSCalendarDate *)[d earlierDate:min];
87 d = [aptDateRanges objectAtIndex:[aptDateRanges count] - 1];
88 if ([d isDateOnSameDay:max])
89 max = (NSCalendarDate *)[d laterDate:max];
92 return [self _getDatesFrom:min to:max];
95 - (NSArray *)_getDatesFrom:(NSCalendarDate *)_from to:(NSCalendarDate *)_to {
96 NSMutableArray *dates;
97 unsigned i, count, offset;
99 offset = [_from hourOfDay];
100 count = ([_to hourOfDay] + 1) - offset;
101 dates = [[NSMutableArray alloc] initWithCapacity:count];
102 for(i = 0; i < count; i++) {
103 NSCalendarDate *date;
105 date = [_from hour:offset + i minute:0];
106 [dates addObject:date];
108 return [dates autorelease];
114 - (NSDictionary *)prevDayQueryParameters {
115 NSCalendarDate *date;
117 date = [[self startDate] dateByAddingYears:0 months:0 days:-1
118 hours:0 minutes:0 seconds:0];
119 return [self queryParametersBySettingSelectedDate:date];
122 - (NSDictionary *)nextDayQueryParameters {
123 NSCalendarDate *date;
125 date = [[self startDate] dateByAddingYears:0 months:0 days:1
126 hours:0 minutes:0 seconds:0];
127 return [self queryParametersBySettingSelectedDate:date];
130 - (NSDictionary *)currentDateQueryParameters {
131 NSMutableDictionary *qp;
133 NSCalendarDate *date;
135 date = [self currentDate];
136 hmString = [NSString stringWithFormat:@"%02d%02d",
137 [date hourOfDay], [date minuteOfHour]];
138 qp = [[self queryParameters] mutableCopy];
139 [self setSelectedDateQueryParameter:date inDictionary:qp];
140 [qp setObject:hmString forKey:@"hm"];
141 return [qp autorelease];
147 - (NSCalendarDate *)startDate {
148 return [[self selectedDate] beginOfDay];
150 - (NSCalendarDate *)endDate {
151 return [[self startDate] endOfDay];
157 - (NSArray *)appointments {
158 return [self fetchCoreInfos];
161 - (NSArray *)aptsForCurrentDate {
163 NSMutableArray *filtered;
165 NSCalendarDate *start, *end;
167 start = self->currentDate;
168 end = [start dateByAddingYears:0
175 apts = [self appointments];
176 filtered = [[NSMutableArray alloc] initWithCapacity:1];
177 count = [apts count];
178 for(i = 0; i < count; i++) {
180 NSCalendarDate *aptStartDate;
182 /* NOTE: appointments are totally opaque objects, we don't know much
183 about them. The reason for this is that they are backend-dependent
184 and we'd like to use UIx for SOGo *and* ZideStore also.
185 We have to accept the fact that we know just a little bit
186 of their API which is completely KVC driven.
189 apt = [apts objectAtIndex:i];
190 aptStartDate = [apt valueForKey:@"startDate"];
191 if([aptStartDate isGreaterThanOrEqualTo:start] &&
192 [aptStartDate isLessThan:end])
194 [filtered addObject:apt];
197 /* multiple day range? */
198 NSCalendarDate *aptEndDate;
200 if ((aptEndDate = [apt valueForKey:@"endDate"])) {
201 if ([aptEndDate isLessThanOrEqualTo:end] ||
202 ([aptStartDate isLessThan:start] &&
203 [aptEndDate isGreaterThan:end]))
205 [filtered addObject:apt];
211 return [filtered autorelease];
214 - (BOOL)hasAptsForCurrentDate {
215 return [[self aptsForCurrentDate] count] != 0;