diff --git a/ChangeLog b/ChangeLog index db1477330..876745853 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,12 @@ +2006-09-08 Wolfgang Sourdeau + + * SoObjects/SOGo/SOGoObject.m ([SOGoObject -serverTimeZone]): new + centralized method returing the timezone configured in the + userdefaults db or "Canada/Eastern" if missing. + ([SOGoObject -userTimeZone]): new centralized method returing the + timezone of the current user or the server timezone if missing + from the user configuration table. + 2006-09-07 Wolfgang Sourdeau * UI/WebServerResources/SchedulerUI.js: implemented caching of diff --git a/SoObjects/SOGo/SOGoObject.h b/SoObjects/SOGo/SOGoObject.h index bbf922220..ee0fd9111 100644 --- a/SoObjects/SOGo/SOGoObject.h +++ b/SoObjects/SOGo/SOGoObject.h @@ -34,7 +34,7 @@ lookup. */ -@class NSString, NSArray, NSMutableString, NSException; +@class NSString, NSArray, NSMutableString, NSException, NSTimeZone; @class GCSFolderManager, GCSFolder; @class SOGoUserFolder, SOGoGroupsFolder; @@ -42,6 +42,7 @@ { NSString *nameInContainer; id container; + NSTimeZone *userTimeZone; } + (id) objectWithName: (NSString *)_name inContainer:(id)_container; @@ -53,6 +54,9 @@ - (NSString *)nameInContainer; - (id)container; +- (NSTimeZone *) serverTimeZone; +- (NSTimeZone *) userTimeZone; + /* ownership */ - (NSString *)ownerInContext:(id)_ctx; diff --git a/SoObjects/SOGo/SOGoObject.m b/SoObjects/SOGo/SOGoObject.m index 835c37930..1cde0f91d 100644 --- a/SoObjects/SOGo/SOGoObject.m +++ b/SoObjects/SOGo/SOGoObject.m @@ -19,11 +19,12 @@ 02111-1307, USA. */ -#include "SOGoObject.h" -#include "SOGoUserFolder.h" -#include -#include -#include "common.h" +#import "SOGoUser.h" +#import "SOGoObject.h" +#import "SOGoUserFolder.h" +#import +#import +#import "common.h" @interface SOGoObject(Content) - (NSString *)contentAsString; @@ -32,12 +33,16 @@ @implementation SOGoObject static BOOL kontactGroupDAV = YES; +static NSTimeZone *serverTimeZone = nil; + (int)version { return 0; } -+ (void)initialize { ++ (void) initialize +{ + NSString *tzName; + NSUserDefaults *ud = [NSUserDefaults standardUserDefaults]; kontactGroupDAV = @@ -56,6 +61,15 @@ static BOOL kontactGroupDAV = YES; asDefaultForPermission:SoPerm_View]; [[self soClassSecurityInfo] declareRole:SoRole_Authenticated asDefaultForPermission:SoPerm_WebDAVAccess]; + + if (!serverTimeZone) + { + tzName = [ud stringForKey: @"SOGoServerTimeZone"]; + if (!tzName) + tzName = @"Canada/Eastern"; + serverTimeZone = [NSTimeZone timeZoneWithName: tzName]; + [serverTimeZone retain]; + } } /* containment */ @@ -76,9 +90,10 @@ static BOOL kontactGroupDAV = YES; - (id)initWithName:(NSString *)_name inContainer:(id)_container { if ((self = [super init])) { - self->nameInContainer = [_name copy]; - self->container = + nameInContainer = [_name copy]; + container = [self doesRetainContainer] ? [_container retain] : _container; + userTimeZone = nil; } return self; } @@ -89,18 +104,20 @@ static BOOL kontactGroupDAV = YES; - (void)dealloc { if ([self doesRetainContainer]) - [self->container release]; - [self->nameInContainer release]; + [container release]; + if (userTimeZone) + [userTimeZone release]; + [nameInContainer release]; [super dealloc]; } /* accessors */ - (NSString *)nameInContainer { - return self->nameInContainer; + return nameInContainer; } - (id)container { - return self->container; + return container; } /* ownership */ @@ -139,10 +156,10 @@ static BOOL kontactGroupDAV = YES; /* looking up shared objects */ - (SOGoUserFolder *)lookupUserFolder { - if (![self->container respondsToSelector:_cmd]) + if (![container respondsToSelector:_cmd]) return nil; - return [self->container lookupUserFolder]; + return [container lookupUserFolder]; } - (SOGoGroupsFolder *)lookupGroupsFolder { return [[self lookupUserFolder] lookupGroupsFolder]; @@ -150,8 +167,8 @@ static BOOL kontactGroupDAV = YES; - (void)sleep { if ([self doesRetainContainer]) - [self->container release]; - self->container = nil; + [container release]; + container = nil; } /* operations */ @@ -369,15 +386,39 @@ static BOOL kontactGroupDAV = YES; return nil; } +- (NSTimeZone *) serverTimeZone +{ + return serverTimeZone; +} + +- (NSTimeZone *) userTimeZone +{ + NSUserDefaults *userPrefs; + WOContext *context; + + if (!userTimeZone) + { + context = [[WOApplication application] context]; + userPrefs = [[context activeUser] userDefaults]; + userTimeZone = [NSTimeZone + timeZoneWithName: [userPrefs stringForKey: @"timezonename"]]; + if (userTimeZone) + [userTimeZone retain]; + else + userTimeZone = [self serverTimeZone]; + } + + return userTimeZone; +} + /* description */ - (void)appendAttributesToDescription:(NSMutableString *)_ms { - if (self->nameInContainer != nil) - [_ms appendFormat:@" name=%@", self->nameInContainer]; - if (self->container != nil) { + if (nameInContainer) + [_ms appendFormat:@" name=%@", nameInContainer]; + if (container) [_ms appendFormat:@" container=0x%08X/%@", - self->container, [self->container valueForKey:@"nameInContainer"]]; - } + container, [container valueForKey:@"nameInContainer"]]; } - (NSString *)description { @@ -387,6 +428,7 @@ static BOOL kontactGroupDAV = YES; [ms appendFormat:@"<0x%08X[%@]:", self, NSStringFromClass([self class])]; [self appendAttributesToDescription:ms]; [ms appendString:@">"]; + return ms; }