diff --git a/ChangeLog b/ChangeLog index fb4fe6601..8ed4b02a3 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,8 @@ +2009-03-03 Ludovic Marcotte + + * Fixed various small issues with the SOGo + cache subsystem. + 2009-03-03 Wolfgang Sourdeau * UI/Scheduler/UIxCalDayTable.m ([UIxCalDayTable -dayClasses]): diff --git a/SoObjects/SOGo/SOGoCache.h b/SoObjects/SOGo/SOGoCache.h index c95016dfc..7531eef8c 100644 --- a/SoObjects/SOGo/SOGoCache.h +++ b/SoObjects/SOGo/SOGoCache.h @@ -60,6 +60,10 @@ - (SOGoUserDefaults *) userDefaultsForLogin: (NSString *) theLogin; - (SOGoUserDefaults *) userSettingsForLogin: (NSString *) theLogin; +- (void) setDefaults: (SOGoUserDefaults *) theDefaults + forLogin: (NSString *) theLogin + key: (NSString *) theKey; + @end #endif /* SOGOCACHE_H */ diff --git a/SoObjects/SOGo/SOGoCache.m b/SoObjects/SOGo/SOGoCache.m index faeb8d61f..af3a7f305 100644 --- a/SoObjects/SOGo/SOGoCache.m +++ b/SoObjects/SOGo/SOGoCache.m @@ -316,6 +316,23 @@ static NSLock *lock; return [[users objectForKey: theLogin] objectForKey: @"settings"]; } +// +// +// +- (void) setDefaults: (SOGoUserDefaults *) theDefaults + forLogin: (NSString *) theLogin + key: (NSString *) theKey +{ + if (![users objectForKey: theLogin]) + [users setObject: [NSMutableDictionary dictionary] forKey: theLogin]; + + [[users objectForKey: theLogin] setObject: theDefaults forKey: theKey]; + [[users objectForKey: theLogin] setObject: [[NSDate date] addTimeInterval: [SOGoCache cleanupInterval]] + forKey: @"cleanupDate"]; + + //NSLog(@"Set %@ to %@", theKey, [users objectForKey: theLogin]); +} + // // Notification callbacks. // @@ -336,21 +353,17 @@ static NSLock *lock; uid: theLogin fieldName: [NSString stringWithFormat: @"c_%@", theKey]] autorelease]; - - if (![users objectForKey: theLogin]) - [users setObject: [NSMutableDictionary dictionary] forKey: theLogin]; + [defaults setValues: theValues]; + [self setDefaults: defaults forLogin: theLogin key: theKey]; - [[users objectForKey: theLogin] setObject: defaults forKey: theKey]; - [[users objectForKey: theLogin] setObject: [[NSDate date] addTimeInterval: [SOGoCache cleanupInterval]] - forKey: @"cleanupDate"]; - - //NSLog(@"\n\n\nCached user %@ for UID: %@\nvalues: %@\n\n", theKey, theLogin, theValues); - #if defined(THREADSAFE) [lock unlock]; #endif } +// +// +// - (void) _userAttributesHaveLoaded: (NSNotification *) theNotification { NSString *uid; @@ -380,6 +393,9 @@ static NSLock *lock; } } +// +// +// - (void) _userDefaultsHaveLoaded: (NSNotification *) theNotification { NSString *uid; @@ -395,11 +411,14 @@ static NSLock *lock; } } +// +// +// - (void) _userDefaultsHaveChanged: (NSNotification *) theNotification { SOGoUserDefaults *defaults; NSString *uid; - + uid = [[theNotification userInfo] objectForKey: @"uid"]; //NSLog(@"Updating user defaults for UID: %@", uid); defaults = (SOGoUserDefaults *)[self userDefaultsForLogin: uid]; @@ -424,6 +443,9 @@ static NSLock *lock; } } +// +// +// - (void) _userSettingsHaveLoaded: (NSNotification *) theNotification { NSString *uid; @@ -439,6 +461,9 @@ static NSLock *lock; } } +// +// +// - (void) _userSettingsHaveChanged: (NSNotification *) theNotification { SOGoUserDefaults *settings; @@ -468,6 +493,9 @@ static NSLock *lock; } } +// +// +// - (void) _cleanupSources { NSDictionary *currentEntry; diff --git a/SoObjects/SOGo/SOGoUser.h b/SoObjects/SOGo/SOGoUser.h index 8f4685be5..442578760 100644 --- a/SoObjects/SOGo/SOGoUser.h +++ b/SoObjects/SOGo/SOGoUser.h @@ -64,14 +64,11 @@ extern NSString *SOGoWeekStartFirstFullWeek; @interface SOGoUser : SoUser { - NSArray *allEmails; - NSString *language; - NSString *currentPassword; - SOGoDateFormatter *dateFormatter; - SOGoUserFolder *homeFolder; - NSString *cn; - NSTimeZone *userTimeZone; NSMutableArray *mailAccounts; + SOGoUserFolder *homeFolder; + NSString *currentPassword; + NSArray *allEmails; + NSString *cn; } + (NSString *) language; diff --git a/SoObjects/SOGo/SOGoUser.m b/SoObjects/SOGo/SOGoUser.m index 32010cb20..9ff25be4a 100644 --- a/SoObjects/SOGo/SOGoUser.m +++ b/SoObjects/SOGo/SOGoUser.m @@ -262,12 +262,9 @@ _timeValue (NSString *key) if ((self = [super initWithLogin: realUID roles: newRoles])) { allEmails = nil; - language = nil; currentPassword = nil; - dateFormatter = nil; homeFolder = nil; cn = nil; - userTimeZone = nil; mailAccounts = nil; } } @@ -283,24 +280,21 @@ _timeValue (NSString *key) - (void) dealloc { [allEmails release]; - [language release]; [currentPassword release]; - [dateFormatter release]; [homeFolder release]; [cn release]; - [userTimeZone release]; [mailAccounts release]; [super dealloc]; } - (void) setPrimaryRoles: (NSArray *) newRoles { - ASSIGN (roles, newRoles); + ASSIGN(roles, newRoles); } - (void) setCurrentPassword: (NSString *) newPassword { - ASSIGN (currentPassword, newPassword); + ASSIGN(currentPassword, newPassword); } - (NSString *) currentPassword @@ -410,25 +404,25 @@ _timeValue (NSString *key) - (SOGoDateFormatter *) dateFormatterInContext: (WOContext *) context { + SOGoDateFormatter *dateFormatter; NSString *format; NSUserDefaults *ud; - if (!dateFormatter) - { - dateFormatter = [SOGoDateFormatter new]; - [dateFormatter setLocale: [[WOApplication application] localeForLanguageNamed: [self language]]]; - ud = [self userDefaults]; - format = [ud stringForKey: @"ShortDateFormat"]; - if (format) - [dateFormatter setShortDateFormat: format]; - format = [ud stringForKey: @"LongDateFormat"]; - if (format) - [dateFormatter setLongDateFormat: format]; - format = [ud stringForKey: @"TimeFormat"]; - if (format) - [dateFormatter setTimeFormat: format]; - } + dateFormatter = [SOGoDateFormatter new]; + [dateFormatter autorelease]; + [dateFormatter setLocale: [[WOApplication application] localeForLanguageNamed: [self language]]]; + ud = [self userDefaults]; + format = [ud stringForKey: @"ShortDateFormat"]; + if (format) + [dateFormatter setShortDateFormat: format]; + format = [ud stringForKey: @"LongDateFormat"]; + if (format) + [dateFormatter setLongDateFormat: format]; + format = [ud stringForKey: @"TimeFormat"]; + if (format) + [dateFormatter setTimeFormat: format]; + return dateFormatter; } @@ -486,6 +480,8 @@ _timeValue (NSString *key) [d setObject: login forKey: @"uid"]; [d setObject: [SOGoProfileURL absoluteString] forKey: @"url"]; + [[SOGoCache sharedCache] setDefaults: defaults forLogin: login key: @"defaults"]; + [[NSDistributedNotificationCenter defaultCenter] postNotificationName: @"SOGoUserDefaultsHaveLoaded" object: nil @@ -518,6 +514,8 @@ _timeValue (NSString *key) [d setObject: login forKey: @"uid"]; [d setObject: [SOGoProfileURL absoluteString] forKey: @"url"]; + [[SOGoCache sharedCache] setDefaults: settings forLogin: login key: @"settings"]; + [[NSDistributedNotificationCenter defaultCenter] postNotificationName: @"SOGoUserSettingsHaveLoaded" object: nil @@ -532,31 +530,28 @@ _timeValue (NSString *key) - (NSString *) language { - if (!language) - { - language = [[self userDefaults] stringForKey: @"Language"]; - if (![language length]) - language = [SOGoUser language]; - [language retain]; - } + NSString *language; + + language = [[self userDefaults] stringForKey: @"Language"]; + if (![language length]) + language = [SOGoUser language]; return language; } - (NSTimeZone *) timeZone { + NSTimeZone *userTimeZone; NSString *timeZoneName; + + timeZoneName = [[self userDefaults] stringForKey: @"TimeZone"]; + userTimeZone = nil; + if ([timeZoneName length] > 0) + userTimeZone = [NSTimeZone timeZoneWithName: timeZoneName]; if (!userTimeZone) - { - timeZoneName = [[self userDefaults] stringForKey: @"TimeZone"]; - if ([timeZoneName length] > 0) - userTimeZone = [NSTimeZone timeZoneWithName: timeZoneName]; - if (!userTimeZone) - userTimeZone = serverTimeZone; - [userTimeZone retain]; - } - + userTimeZone = serverTimeZone; + return userTimeZone; } @@ -840,32 +835,17 @@ _timeValue (NSString *key) - (NSString *) replyPlacement { - NSString *replyPlacement; - - replyPlacement - = [[self userDefaults] stringForKey: @"ReplyPlacement"]; - - return replyPlacement; + return [[self userDefaults] stringForKey: @"ReplyPlacement"]; } - (NSString *) signaturePlacement { - NSString *signaturePlacement; - - signaturePlacement - = [[self userDefaults] stringForKey: @"SignaturePlacement"]; - - return signaturePlacement; + return [[self userDefaults] stringForKey: @"SignaturePlacement"]; } - (NSString *) messageForwarding { - NSString *messageForwarding; - - messageForwarding - = [[self userDefaults] stringForKey: @"MessageForwarding"]; - - return messageForwarding; + return [[self userDefaults] stringForKey: @"MessageForwarding"]; } /* folders */ diff --git a/SoObjects/SOGo/SOGoUserDefaults.h b/SoObjects/SOGo/SOGoUserDefaults.h index 16f477a4a..04559bbef 100644 --- a/SoObjects/SOGo/SOGoUserDefaults.h +++ b/SoObjects/SOGo/SOGoUserDefaults.h @@ -30,18 +30,21 @@ An object with the same API like NSUserDefaults which retrieves profile information for users in the database. + + It does NOT store values internally but rather uses an external + mutable dictionary for this (generally coming from SOGoCache) */ -@class NSString, NSURL, NSUserDefaults, NSArray, NSDictionary, NSData; -@class NSCalendarDate, NSMutableDictionary; +@class NSString, NSURL, NSUserDefaults, NSArray, NSDictionary; +@class NSData, NSCalendarDate, NSMutableDictionary; @interface SOGoUserDefaults : NSObject { NSURL *url; NSString *uid; NSString *fieldName; - NSMutableDictionary *values; NSCalendarDate *lastFetch; + NSMutableDictionary *values; struct { @@ -50,9 +53,9 @@ } defFlags; } -- (id) initWithTableURL: (NSURL *) url - uid: (NSString *) uid - fieldName: (NSString *) fieldName; +- (id) initWithTableURL: (NSURL *) theURL + uid: (NSString *) theUID + fieldName: (NSString *) theFieldName; /* value access */ - (void) setValues: (NSDictionary *) theValues; diff --git a/SoObjects/SOGo/SOGoUserDefaults.m b/SoObjects/SOGo/SOGoUserDefaults.m index ea9350b5c..7691f2a86 100644 --- a/SoObjects/SOGo/SOGoUserDefaults.m +++ b/SoObjects/SOGo/SOGoUserDefaults.m @@ -38,23 +38,24 @@ #import "NSObject+Utilities.h" #import "SOGoUserDefaults.h" +#import "SOGoCache.h" @implementation SOGoUserDefaults static NSString *uidColumnName = @"c_uid"; -- (id) initWithTableURL: (NSURL *) tableURL - uid: (NSString *) userID - fieldName: (NSString *) defaultsFieldName +- (id) initWithTableURL: (NSURL *) theURL + uid: (NSString *) theUID + fieldName: (NSString *) theFieldName { if ((self = [self init])) { - if (tableURL && [userID length] > 0 - && [defaultsFieldName length] > 0) + if (theURL && [theUID length] > 0 + && [theFieldName length] > 0) { - fieldName = [defaultsFieldName copy]; - url = [tableURL copy]; - uid = [userID copy]; + fieldName = [theFieldName copy]; + url = [theURL copy]; + uid = [theUID copy]; } else { @@ -120,10 +121,9 @@ static NSString *uidColumnName = @"c_uid"; fieldName, [[self tableURL] gcsTableName], uidColumnName, [self uid]]; - [values release]; + values = [[NSMutableDictionary alloc] init]; /* run SQL */ - ex = [channel evaluateExpressionX: sql]; if (ex) [self errorWithFormat:@"could not run SQL '%@': %@", sql, ex]; @@ -141,24 +141,21 @@ static NSString *uidColumnName = @"c_uid"; value = [row objectForKey: fieldName]; if ([value isNotNull]) { + id v; + value = [value stringByReplacingString: @"''" withString: @"'"]; value = [value stringByReplacingString: @"\\\\" withString: @"\\"]; plistData = [value dataUsingEncoding: NSUTF8StringEncoding]; - values - = [NSPropertyListSerialization propertyListFromData: plistData + v = [NSPropertyListSerialization propertyListFromData: plistData mutabilityOption: NSPropertyListMutableContainers format: NULL errorDescription: &error]; - if ([values isKindOfClass: [NSMutableDictionary class]]) - [values retain]; - else - values = [NSMutableDictionary new]; + if ([v isKindOfClass: [NSMutableDictionary class]]) + [values addEntriesFromDictionary: v]; } - else - values = [NSMutableDictionary new]; - + ASSIGN(lastFetch, [NSCalendarDate date]); defFlags.modified = NO; rc = YES; @@ -294,6 +291,10 @@ static NSString *uidColumnName = @"c_uid"; [d setObject: uid forKey: @"uid"]; [d setObject: [url absoluteString] forKey: @"url"]; + [[SOGoCache sharedCache] setDefaults: self + forLogin: uid + key: ([fieldName isEqualToString: @"c_defaults"] ? @"defaults" : @"settings")]; + [[NSDistributedNotificationCenter defaultCenter] postNotificationName: ([fieldName isEqualToString: @"c_defaults"] ? @"SOGoUserDefaultsHaveChanged" @@ -308,7 +309,7 @@ static NSString *uidColumnName = @"c_uid"; - (BOOL) fetchProfile { - return (values || [self primaryFetchProfile]); + return (values || [self primaryFetchProfile]); } - (NSString *) jsonRepresentation @@ -321,7 +322,9 @@ static NSString *uidColumnName = @"c_uid"; /* value access */ - (void) setValues: (NSDictionary *) theValues { - [values removeAllObjects]; + [values release]; + + values = [[NSMutableDictionary alloc] init]; [values addEntriesFromDictionary: theValues]; ASSIGN(lastFetch, [NSCalendarDate date]); defFlags.modified = NO; @@ -404,9 +407,8 @@ static NSString *uidColumnName = @"c_uid"; - (void) flush { - [values release]; + [values removeAllObjects]; [lastFetch release]; - values = nil; lastFetch = nil; defFlags.modified = NO; defFlags.isNew = NO; @@ -471,4 +473,9 @@ static NSString *uidColumnName = @"c_uid"; forKey: key]; } +- (NSString *) description +{ + return [values description]; +} + @end /* SOGoUserDefaults */ diff --git a/UI/Scheduler/UIxCalDayTable.m b/UI/Scheduler/UIxCalDayTable.m index 3c6e1e8fa..097182540 100644 --- a/UI/Scheduler/UIxCalDayTable.m +++ b/UI/Scheduler/UIxCalDayTable.m @@ -1,6 +1,6 @@ /* UIxCalDayTable.m - this file is part of SOGo * - * Copyright (C) 2006 Inverse inc. + * Copyright (C) 2006-2009 Inverse inc. * * Author: Wolfgang Sourdeau * @@ -59,6 +59,7 @@ weekDays = [locale objectForKey: NSShortWeekDayNameArray]; [weekDays retain]; dateFormatter = [[context activeUser] dateFormatterInContext: context]; + [dateFormatter retain]; } return self; @@ -71,6 +72,7 @@ [weekDays release]; [daysToDisplay release]; [hoursToDisplay release]; + [dateFormatter release]; [super dealloc]; }