]> err.no Git - scalable-opengroupware.org/blob - SOGo/UI/Scheduler/UIxCalWeekListview.m
some code cleanup
[scalable-opengroupware.org] / SOGo / UI / Scheduler / UIxCalWeekListview.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 #include "UIxCalWeekView.h"
24
25 @interface UIxCalWeekListview : UIxCalWeekView
26 {
27   NSArray *uids;
28   id currentUid;
29   int column;
30 }
31
32 - (int)columnsPerDay;
33
34 @end
35
36 #include "common.h"
37 #include <NGExtensions/NGCalendarDateRange.h>
38 #include <SOGo/AgenorUserManager.h>
39 #include <SOGoUI/SOGoAptFormatter.h>
40 #include "SoObjects/Appointments/SOGoAppointmentFolder.h"
41
42 @implementation UIxCalWeekListview
43
44 - (void)dealloc {
45   [self->uids release];
46   [self->currentUid release];
47   [super dealloc];
48 }
49
50 /* fetching */
51
52 /* NOTE: this fetches coreInfos instead of overviewInfos
53  * as is done in the superclass!
54  */
55 - (NSArray *)fetchCoreInfos {
56   if (!self->appointments) {
57     id             folder;
58     NSCalendarDate *sd, *ed;
59     
60     folder             = [self clientObject];
61     sd                 = [self startDate];
62     ed                 = [self endDate];
63     [self setAppointments:[folder fetchCoreInfosFrom:sd to:ed]];
64   }
65   return self->appointments;
66 }
67
68 /* accessors */
69
70 - (NSArray *)uids {
71   if(!self->uids) {
72     self->uids = [[[[self clientObject] calendarUIDs]
73                      sortedArrayUsingSelector:@selector(compareAscending:)]
74                      retain];
75   }
76   return self->uids;
77 }
78
79 - (void)setCurrentUid:(id)_currentUid {
80   ASSIGN(self->currentUid, _currentUid);
81 }
82 - (id)currentUid {
83   return self->currentUid;
84 }
85
86 /* column corresponds to the current day/hour */
87 - (void)setColumn:(int)_column {
88   unsigned dayOfWeek, hour;
89   NSCalendarDate *date;
90
91   dayOfWeek = _column / [self columnsPerDay];
92   hour      = _column % [self columnsPerDay];
93
94   date = [[self startDate] dateByAddingYears:0 months:0 days:dayOfWeek];
95   date = [date hour:hour minute:0];
96   /* let's reuse currentDay, although this isn't named too accurately */
97   [self setCurrentDay:date];
98   self->column = _column;
99 }
100 - (int)column {
101   return self->column;
102 }
103
104 /* columns */
105
106 - (int)columnsPerDay {
107   return 24;
108 }
109
110 - (NSArray *)columns {
111   static NSMutableArray *columns = nil;
112   
113   if(!columns) {
114     unsigned i, count;
115     
116     if([self shouldDisplayWeekend])
117       count = [self columnsPerDay] * 7;
118     else
119       count = [self columnsPerDay] * 5;
120     
121     columns = [[NSMutableArray alloc] initWithCapacity:count];
122     for(i = 0; i < count; i++) {
123       [columns addObject:[NSNumber numberWithInt:i]];
124     }
125   }
126   return columns;
127 }
128
129 /* tests */
130
131 /* row is active, if currentUid is participant of apt */
132 - (BOOL)isRowActive {
133   AgenorUserManager *um;
134   NSString *mailChunk;
135   NSString *currentMail;
136
137   um = [AgenorUserManager sharedUserManager];
138   currentMail = [um getEmailForUID:self->currentUid];
139   mailChunk = [self->appointment valueForKey:@"partmails"];
140   if([mailChunk rangeOfString:currentMail].length > 0)
141     return YES;
142   return NO;
143 }
144
145 /* item is active, if apt's dateRange intersects the range
146    of the current column (currentDay is set to be this date) */
147 - (BOOL)isItemActive {
148   NSCalendarDate *dateStart, *dateEnd, *aptStart, *aptEnd;
149   NGCalendarDateRange *dateRange, *aptRange;
150
151   dateStart = [self currentDay];
152   dateEnd   = [dateStart dateByAddingYears:0 months:0 days:0
153                                      hours:1 minutes:0 seconds:0];
154   dateRange = [NGCalendarDateRange calendarDateRangeWithStartDate:dateStart
155                                                           endDate:dateEnd];
156   aptStart = [self->appointment valueForKey:@"startDate"];
157   aptEnd   = [self->appointment valueForKey:@"endDate"];
158   aptRange = [NGCalendarDateRange calendarDateRangeWithStartDate:aptStart
159                                                          endDate:aptEnd];
160   return [dateRange doesIntersectWithDateRange:aptRange];
161 }
162
163 /* descriptions */
164
165 - (void)configureFormatters {
166   [super configureFormatters];
167   [self->aptFormatter setTitleOnly];
168   [self->privateAptFormatter setPrivateTitleOnly];
169 }
170
171 - (NSString *)cnForCurrentUid {
172   return [[AgenorUserManager sharedUserManager] getCNForUID:self->currentUid];
173 }
174
175 /* style sheet */
176
177 - (NSString *)titleStyle {
178   if([self->currentDay isToday])
179     return @"weekoverview_title_hilite";
180   return @"weekoverview_title";
181 }
182
183 @end /* UIxCalWeekListview */