diff --git a/ChangeLog b/ChangeLog index c9933b59e..258528bc3 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,18 @@ +2011-09-27 Francis Lachapelle + + * SoObjects/SOGo/SOGoUserDefaults.m (-setBusyOffHours): new setter + for the new defaults SOGoBusyOffHours, which defines if periods + outside business hours should be opaque (busy). + (-busyOffHours): getter corollary to the new method above. + + * UI/PreferencesUI/UIxPreferences.m (-setBusyOffHours:): new + setter for the new defaults SOGoBusyOffHours. + (-busyOffHours): getter corollary to the new method above. + + * SoObjects/Appointments/SOGoFreeBusyObject.m + (-fetchFreeBusyInfosFrom:to:): add off-hours if defaults + SOGoBusyOffHours is true. + 2011-09-26 Wolfgang Sourdeau * OpenChange/MAPIStoreFolder.m diff --git a/SoObjects/Appointments/SOGoFreeBusyObject.m b/SoObjects/Appointments/SOGoFreeBusyObject.m index 28e76b15c..f66d00c58 100644 --- a/SoObjects/Appointments/SOGoFreeBusyObject.m +++ b/SoObjects/Appointments/SOGoFreeBusyObject.m @@ -244,9 +244,11 @@ to: (NSCalendarDate *) endDate { SOGoAppointmentFolder *calFolder; -// SoSecurityManager *sm; + SOGoUser *user; + SOGoUserDefaults *ud; NSArray *folders; NSMutableArray *infos; + NSString *login; unsigned int count, max; infos = [NSMutableArray array]; @@ -263,6 +265,75 @@ to: endDate]]; } + login = [container ownerInContext: context]; + user = [SOGoUser userWithLogin: login]; + ud = [user userDefaults]; + + if ([ud busyOffHours]) + { + NSCalendarDate *currentStartDate, *currentEndDate, *weekendStartDate, *weekendEndDate; + NSTimeZone *timeZone; + unsigned int dayStartHour, dayEndHour, intervalHours; + BOOL firstRange; + + dayStartHour = [ud dayStartHour]; + dayEndHour = [ud dayEndHour]; + intervalHours = dayStartHour + 24 - dayEndHour; + timeZone = [ud timeZone]; + firstRange = YES; + + currentStartDate = [NSCalendarDate dateWithYear: [startDate yearOfCommonEra] + month: [startDate monthOfYear] + day: [startDate dayOfMonth] + hour: 0 + minute: 0 + second: 0 + timeZone: timeZone]; + currentEndDate = [NSCalendarDate dateWithYear: [startDate yearOfCommonEra] + month: [startDate monthOfYear] + day: [startDate dayOfMonth] + hour: dayStartHour + minute: 0 + second: 0 + timeZone: timeZone]; + + while ([currentStartDate compare: endDate] == NSOrderedAscending || + [currentStartDate compare: endDate] == NSOrderedSame) + { + if ([endDate compare: currentEndDate] == NSOrderedAscending) + currentEndDate = endDate; + + [infos addObject: [NSDictionary dictionaryWithObjectsAndKeys: + [NSNumber numberWithBool: YES], @"c_isopaque", + ([currentStartDate compare: startDate] == NSOrderedAscending)? startDate : currentStartDate, @"startDate", + currentEndDate, @"endDate", nil]]; + + if (!firstRange + && currentEndDate != endDate + && ([currentEndDate dayOfWeek] == 6 || [currentEndDate dayOfWeek] == 0)) + { + // Fill weekend days + weekendStartDate = currentEndDate; + weekendEndDate = [weekendStartDate addYear:0 month:0 day:0 hour:(-[weekendStartDate hourOfDay] + dayEndHour) minute:0 second:0]; + [infos addObject: [NSDictionary dictionaryWithObjectsAndKeys: [NSNumber numberWithBool: YES], @"c_isopaque", + weekendStartDate, @"startDate", + weekendEndDate, @"endDate", nil]]; + } + + // Compute next range + if (firstRange) + { + currentStartDate = [currentStartDate addYear:0 month:0 day:0 hour:dayEndHour minute:0 second:0]; + firstRange = NO; + } + else + { + currentStartDate = [currentStartDate addYear:0 month:0 day:1 hour:0 minute:0 second:0]; + } + currentEndDate = [currentStartDate addYear:0 month:0 day:0 hour:intervalHours minute:0 second:0]; + } + } + return infos; } diff --git a/SoObjects/SOGo/SOGoUserDefaults.h b/SoObjects/SOGo/SOGoUserDefaults.h index 3b5901ead..3ea311eaf 100644 --- a/SoObjects/SOGo/SOGoUserDefaults.h +++ b/SoObjects/SOGo/SOGoUserDefaults.h @@ -72,6 +72,9 @@ extern NSString *SOGoWeekStartFirstFullWeek; - (NSString *) dayEndTime; - (unsigned int) dayEndHour; +- (void) setBusyOffHours: (BOOL) busyOffHours; +- (BOOL) busyOffHours; + - (void) setTimeZoneName: (NSString *) newValue; - (NSString *) timeZoneName; diff --git a/SoObjects/SOGo/SOGoUserDefaults.m b/SoObjects/SOGo/SOGoUserDefaults.m index e280089fb..f51353972 100644 --- a/SoObjects/SOGo/SOGoUserDefaults.m +++ b/SoObjects/SOGo/SOGoUserDefaults.m @@ -283,6 +283,16 @@ NSString *SOGoWeekStartFirstFullWeek = @"FirstFullWeek"; return [[self dayEndTime] timeValue]; } +- (void) setBusyOffHours: (BOOL) newValue +{ + [self setBool: newValue forKey: @"SOGoBusyOffHours"]; +} + +- (BOOL) busyOffHours +{ + return [self boolForKey: @"SOGoBusyOffHours"]; +} + - (void) setTimeZoneName: (NSString *) newValue { [self setObject: newValue forKey: @"SOGoTimeZone"]; diff --git a/UI/PreferencesUI/UIxPreferences.m b/UI/PreferencesUI/UIxPreferences.m index 4efed6639..5548a97c4 100644 --- a/UI/PreferencesUI/UIxPreferences.m +++ b/UI/PreferencesUI/UIxPreferences.m @@ -483,6 +483,16 @@ [userDefaults setDayEndTime: newTime]; } +- (void) setBusyOffHours: (BOOL) busyOffHours +{ + [userDefaults setBusyOffHours: busyOffHours]; +} + +- (BOOL) busyOffHours +{ + return [userDefaults busyOffHours]; +} + - (NSArray *) firstWeekList { return [NSArray arrayWithObjects: diff --git a/UI/Templates/PreferencesUI/UIxPreferences.wox b/UI/Templates/PreferencesUI/UIxPreferences.wox index cd808145e..e12d1db71 100644 --- a/UI/Templates/PreferencesUI/UIxPreferences.wox +++ b/UI/Templates/PreferencesUI/UIxPreferences.wox @@ -97,6 +97,11 @@ const:id="dayEndTime" string="item" selection="userDayEndTime" />
+