diff --git a/ChangeLog b/ChangeLog index 937a9dcfd..e01ae2b88 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,9 @@ +2006-08-24 Wolfgang Sourdeau + + * UI/Scheduler/UIxCalDayTable.[hm]: new class module/component + used by UIxCalDayView and UIxCalWeekView to display the events + occuring in one or more days. + 2006-08-22 Wolfgang Sourdeau * UI/Scheduler/UIxCalMainView.m: extended class to populate the diff --git a/UI/Scheduler/UIxCalDayTable.h b/UI/Scheduler/UIxCalDayTable.h new file mode 100644 index 000000000..bd4a32b3a --- /dev/null +++ b/UI/Scheduler/UIxCalDayTable.h @@ -0,0 +1,65 @@ +/* UIxCalDayTable.h - this file is part of $PROJECT_NAME_HERE$ + * + * Copyright (C) 2006 Inverse groupe conseil + * + * Author: Wolfgang Sourdeau + * + * This file is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2, or (at your option) + * any later version. + * + * This file is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; see the file COPYING. If not, write to + * the Free Software Foundation, Inc., 59 Temple Place - Suite 330, + * Boston, MA 02111-1307, USA. + */ + +#ifndef UIXCALDAYTABLE_H +#define UIXCALDAYTABLE_H + +#import "UIxCalView.h" + +@class NSArray; +@class NSCalendarDay; +@class NSString; +@class SOGoDateFormatter; + +@interface UIxCalDayTable : UIxCalView +{ + int numberOfDays; + NSCalendarDate *startDate; + NSCalendarDate *currentTableDay; + NSString *currentTableHour; + NSArray *daysToDisplay; + NSMutableArray *hoursToDisplay; + SOGoDateFormatter *dateFormatter; + + NSString *cssClass; + NSString *cssId; +} + +- (void) setCSSClass: (NSString *) aCssClass; +- (NSString *) cssClass; + +- (void) setCSSId: (NSString *) aCssId; +- (NSString *) cssId; + +- (void) setNumberOfDays: (NSString *) aNumber; + +- (void) setStartDate: (NSCalendarDate *) aStartDate; +- (NSCalendarDate *) startDate; +- (NSCalendarDate *) endDate; + +- (NSArray *) daysToDisplay; +- (void) setCurrentTableDay: (NSCalendarDate *) aTableDay; +- (NSCalendarDate *) currentTableDay; + +@end + +#endif /* UIXCALDAYTABLE_H */ diff --git a/UI/Scheduler/UIxCalDayTable.m b/UI/Scheduler/UIxCalDayTable.m new file mode 100644 index 000000000..1cb03e360 --- /dev/null +++ b/UI/Scheduler/UIxCalDayTable.m @@ -0,0 +1,211 @@ +/* UIxCalDayTable.m - this file is part of SOGo + * + * Copyright (C) 2006 Inverse groupe conseil + * + * Author: Wolfgang Sourdeau + * + * This file is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2, or (at your option) + * any later version. + * + * This file is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; see the file COPYING. If not, write to + * the Free Software Foundation, Inc., 59 Temple Place - Suite 330, + * Boston, MA 02111-1307, USA. + */ + +#import +#import +#import +#import + +#import + +#import +#import + +#import "UIxCalDayTable.h" + +@class SOGoAppointment; + +@implementation UIxCalDayTable + +- (id) init +{ + if ((self = [super init])) + { + daysToDisplay = nil; + hoursToDisplay = nil; + numberOfDays = 1; + startDate = nil; + currentTableDay = nil; + currentTableHour = nil; + dateFormatter = [[SOGoDateFormatter alloc] + initWithLocale: [self locale]]; + } + + return self; +} + +- (void) dealloc +{ + [dateFormatter release]; + [super dealloc]; +} + +- (void) setCSSClass: (NSString *) aCssClass +{ + cssClass = aCssClass; +} + +- (NSString *) cssClass +{ + return cssClass; +} + +- (void) setCSSId: (NSString *) aCssId +{ + cssId = aCssId; +} + +- (NSString *) cssId +{ + return cssId; +} + +- (void) setNumberOfDays: (NSString *) aNumber +{ + numberOfDays = [aNumber intValue]; +} + +- (void) setStartDate: (NSCalendarDate *) aStartDate +{ + startDate = aStartDate; +} + +- (NSCalendarDate *) startDate +{ + if (!startDate) + startDate = [super startDate]; + + return [startDate beginOfDay]; +} + +- (NSCalendarDate *) endDate +{ + NSCalendarDate *endDate; + + endDate = [[self startDate] dateByAddingYears: 0 + months: 0 + days: numberOfDays - 1]; + + return [endDate endOfDay]; +} + +- (NSArray *) hoursToDisplay +{ + unsigned int currentHour, lastHour; + + if (!hoursToDisplay) + { + currentHour = [self dayStartHour]; + lastHour = [self dayEndHour]; + hoursToDisplay + = [NSMutableArray arrayWithCapacity: (lastHour - currentHour)]; + + while (currentHour < lastHour) + { + [hoursToDisplay + addObject: [NSString stringWithFormat: @"%d", currentHour]]; + currentHour++; + } + } + + return hoursToDisplay; +} + +- (NSArray *) daysToDisplay +{ + NSMutableArray *days; + NSCalendarDate *currentDate; + int count; + + days = [NSMutableArray arrayWithCapacity: numberOfDays]; + currentDate = [[self startDate] hour: [currentTableHour intValue] + minute: 0]; + [days addObject: currentDate]; + for (count = 1; count < numberOfDays; count++) + { + currentDate = [currentDate dateByAddingYears: 0 + months: 0 + days: 1]; + [days addObject: currentDate]; + } + + return days; +} + +- (void) setCurrentTableDay: (NSCalendarDate *) aTableDay +{ + currentTableDay = aTableDay; +} + +- (NSCalendarDate *) currentTableDay +{ + return currentTableDay; +} + +- (void) setCurrentTableHour: (NSString *) aTableHour +{ + currentTableHour = aTableHour; +} + +- (NSString *) currentTableHour +{ + return currentTableHour; +} + +- (NSString *) labelForDay +{ + return [NSString stringWithFormat: @"%@ %@", + [dateFormatter shortDayOfWeek: [currentTableDay dayOfWeek]], + [dateFormatter stringForObjectValue: currentTableDay]]; +} + +- (NSArray *) aptsForCurrentDate +{ + NSArray *apts; + NSMutableArray *filtered; + unsigned i, count; + NSCalendarDate *start, *end; + SOGoAppointment *apt; + NSCalendarDate *aptStartDate; + + start = currentTableDay; + end = [start dateByAddingYears: 0 months: 0 days: 0 + hours: 0 minutes: 59 seconds: 59]; + + apts = [self fetchCoreInfos]; + filtered = [NSMutableArray new]; + [filtered autorelease]; + + count = [apts count]; + for (i = 0; i < count; i++) + { + apt = [apts objectAtIndex:i]; + aptStartDate = [apt valueForKey:@"startDate"]; + if([aptStartDate isGreaterThanOrEqualTo: start] + && [aptStartDate isLessThan: end]) + [filtered addObject:apt]; + } + + return filtered; +} + +@end