]> err.no Git - scalable-opengroupware.org/blob - UI/Scheduler/UIxCalDayOverview.m
moved SOGo files up
[scalable-opengroupware.org] / UI / Scheduler / UIxCalDayOverview.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 // $Id$
22
23
24 #include "UIxCalDayOverview.h"
25 #include "common.h"
26 #include <SOGoUI/SOGoAptFormatter.h>
27
28 @implementation UIxCalDayOverview
29
30 - (void)dealloc {
31     [self->currentApts release];
32     [super dealloc];
33 }
34
35 - (void)setCurrentApts:(NSArray *)_apts {
36     ASSIGN(self->currentApts, _apts);
37 }
38 - (NSArray *)currentApts {
39     return self->currentApts;
40 }
41
42 - (int)minRequiredRowSpan {
43     unsigned count = [[self aptsForCurrentDate] count];
44     return count == 0 ? 1 : count;
45 }
46
47 /* overriding */
48
49 - (void)configureFormatters {
50   [super configureFormatters];
51
52   [self->aptFormatter setSingleLineFullDetails];
53   [self->aptTooltipFormatter setTooltip];
54 }
55
56 - (NSArray *)aptsForCurrentDate {
57   NSArray        *apts;
58   NSMutableArray *filtered;
59   unsigned       i, count;
60   NSCalendarDate *start, *end;
61   
62   start = self->currentDate;
63   end   = [start dateByAddingYears:0
64                             months:0
65                               days:0
66                              hours:0
67                            minutes:59
68                            seconds:59];
69   
70   apts     = [self appointments];
71   filtered = [[NSMutableArray alloc] initWithCapacity:1];
72   count    = [apts count];
73   for (i = 0; i < count; i++) {
74     id apt;
75     NSCalendarDate *aptStartDate;
76     
77     apt = [apts objectAtIndex:i];
78     aptStartDate = [apt valueForKey:@"startDate"];
79     if([aptStartDate isGreaterThanOrEqualTo:start] &&
80        [aptStartDate isLessThan:end])
81     {
82       [filtered addObject:apt];
83     }
84   }
85   
86   return [filtered autorelease];
87 }
88
89 - (NSArray *)allDayApts {
90   NSCalendarDate *start;
91   NSArray        *apts;
92   NSMutableArray *filtered;
93   unsigned       i, count;
94   
95   if (self->allDayApts)
96     return self->allDayApts;
97
98   start    = [self startDate];
99   apts     = [self appointments];
100   filtered = [[NSMutableArray alloc] initWithCapacity:1];
101   count    = [apts count];
102   for (i = 0; i < count; i++) {
103     id       apt;
104     NSNumber *bv;
105     
106     apt = [apts objectAtIndex:i];
107     bv  = [apt valueForKey:@"isallday"];
108     if ([bv boolValue]) {
109       [filtered addObject:apt];
110     }
111     else {
112       NSCalendarDate *aptStartDate;
113
114       aptStartDate = [apt valueForKey:@"startDate"];
115       if([aptStartDate isLessThan:start]) {
116         [filtered addObject:apt];
117       }
118     }
119   }
120   
121   ASSIGN(self->allDayApts, filtered);
122   [filtered release];
123   return self->allDayApts;
124 }
125
126 @end