Monotone-Parent: afb2242cf07ec3d3c9cbe25bb4a43d4e15d1ec70

Monotone-Revision: 3ea0b7cf5da4f19b50ca8ef28a18b5479c38c7a5

Monotone-Author: wsourdeau@inverse.ca
Monotone-Date: 2009-12-01T14:29:56
Monotone-Branch: ca.inverse.sogo
maint-2.0.2
Wolfgang Sourdeau 2009-12-01 14:29:56 +00:00
parent e8dc2e31c5
commit f092e394c1
7 changed files with 170 additions and 43 deletions

View File

@ -1,3 +1,10 @@
2009-12-01 Wolfgang Sourdeau <wsourdeau@inverse.ca>
* SoObjects/SOGo/SOGoDefaultsSource.m (-boolForKey:)
(-floatForKey:, -integerForKey:, -dataForKey:, -stringForKey:)
(-dictionaryForKey:, -arrayForKey:, -stringArrayForKey:): added
type checking and warnings.
2009-11-30 Wolfgang Sourdeau <wsourdeau@inverse.ca> 2009-11-30 Wolfgang Sourdeau <wsourdeau@inverse.ca>
* SoObjects/SOGo/SOGoDefaultsSource.m (-setBool:forKey:): we * SoObjects/SOGo/SOGoDefaultsSource.m (-setBool:forKey:): we
@ -6,7 +13,7 @@
code. code.
* UI/WebServerResources/SchedulerUI.js (initCalendars): the * UI/WebServerResources/SchedulerUI.js (initCalendars): the
"ShowCompletedTasks" parameter is in the UserSettings dictionary. "ShowCompletedTasks" parameter is in the UserSettings dictionary.
* SoObjects/SOGo/SOGoDefaultsSource.m * SoObjects/SOGo/SOGoDefaultsSource.m
(-migrateOldDefaultsWithDictionary:): when migrating between two (-migrateOldDefaultsWithDictionary:): when migrating between two

View File

@ -74,7 +74,7 @@ extern NSString *SOGoDefaultsSourceUnmutableSource;
- (void) setInteger: (int) value forKey: (NSString *) key; - (void) setInteger: (int) value forKey: (NSString *) key;
- (int) integerForKey: (NSString *) key; - (int) integerForKey: (NSString *) key;
- (id) dictionaryForKey: (NSString *) key; - (NSDictionary *) dictionaryForKey: (NSString *) key;
- (NSData *) dataForKey: (NSString *) key; - (NSData *) dataForKey: (NSString *) key;
- (NSString *) stringForKey: (NSString *) key; - (NSString *) stringForKey: (NSString *) key;

View File

@ -34,8 +34,25 @@
NSString *SOGoDefaultsSourceInvalidSource = @"SOGoDefaultsSourceInvalidSource"; NSString *SOGoDefaultsSourceInvalidSource = @"SOGoDefaultsSourceInvalidSource";
NSString *SOGoDefaultsSourceUnmutableSource = @"SOGoDefaultsSourceUnmutableSource"; NSString *SOGoDefaultsSourceUnmutableSource = @"SOGoDefaultsSourceUnmutableSource";
static Class NSArrayKlass = Nil;
static Class NSDataKlass = Nil;
static Class NSDictionaryKlass = Nil;
static Class NSStringKlass = Nil;
@implementation SOGoDefaultsSource @implementation SOGoDefaultsSource
+ (void) initialize
{
if (!NSArrayKlass)
NSArrayKlass = [NSArray class];
if (!NSDataKlass)
NSDataKlass = [NSData class];
if (!NSDictionaryKlass)
NSDictionaryKlass = [NSDictionary class];
if (!NSStringKlass)
NSStringKlass = [NSString class];
}
+ (id) defaultsSourceWithSource: (id) newSource + (id) defaultsSourceWithSource: (id) newSource
andParentSource: (SOGoDefaultsSource *) newParentSource andParentSource: (SOGoDefaultsSource *) newParentSource
{ {
@ -128,7 +145,25 @@ NSString *SOGoDefaultsSourceUnmutableSource = @"SOGoDefaultsSourceUnmutableSourc
- (BOOL) boolForKey: (NSString *) key - (BOOL) boolForKey: (NSString *) key
{ {
return [[self objectForKey: key] boolValue]; id boolForKey;
BOOL value;
boolForKey = [self objectForKey: key];
if (boolForKey)
{
if ([boolForKey respondsToSelector: @selector (boolValue)])
value = [boolForKey boolValue];
else
{
[self warnWithFormat: @"expected a boolean for '%@' (ignored)",
key];
value = NO;
}
}
else
value = NO;
return value;
} }
- (void) setFloat: (float) value - (void) setFloat: (float) value
@ -140,7 +175,25 @@ NSString *SOGoDefaultsSourceUnmutableSource = @"SOGoDefaultsSourceUnmutableSourc
- (float) floatForKey: (NSString *) key - (float) floatForKey: (NSString *) key
{ {
return [[self objectForKey: key] floatValue]; id floatForKey;
float value;
floatForKey = [self objectForKey: key];
if (floatForKey)
{
if ([floatForKey respondsToSelector: @selector (floatValue)])
value = [floatForKey floatValue];
else
{
[self warnWithFormat: @"expected a float for '%@' (ignored)",
key];
value = 0.0;
}
}
else
value = 0.0;
return value;
} }
- (void) setInteger: (int) value - (void) setInteger: (int) value
@ -152,39 +205,107 @@ NSString *SOGoDefaultsSourceUnmutableSource = @"SOGoDefaultsSourceUnmutableSourc
- (int) integerForKey: (NSString *) key - (int) integerForKey: (NSString *) key
{ {
return [[self objectForKey: key] intValue]; id intForKey;
} int value;
#warning TODO: type checking intForKey = [self objectForKey: key];
- (NSArray *) arrayForKey: (NSString *) key if (intForKey)
{ {
return [self objectForKey: key]; if ([intForKey respondsToSelector: @selector (intValue)])
} value = [intForKey intValue];
else
{
[self warnWithFormat: @"expected an integer for '%@' (ignored)",
key];
value = 0;
}
}
else
value = 0;
- (NSArray *) stringArrayForKey: (NSString *) key return value;
{
return [self objectForKey: key];
} }
- (NSData *) dataForKey: (NSString *) key - (NSData *) dataForKey: (NSString *) key
{ {
return [self objectForKey: key]; NSData *dataForKey;
dataForKey = [self objectForKey: key];
if (dataForKey && ![dataForKey isKindOfClass: NSDataKlass])
{
[self warnWithFormat: @"expected an NSData for '%@' (ignored)",
key];
dataForKey = nil;
}
return dataForKey;
} }
- (NSString *) stringForKey: (NSString *) key - (NSString *) stringForKey: (NSString *) key
{ {
return [self objectForKey: key]; NSString *stringForKey;
stringForKey = [self objectForKey: key];
if (stringForKey && ![stringForKey isKindOfClass: NSStringKlass])
{
[self warnWithFormat: @"expected an NSString for '%@' (ignored)",
key];
stringForKey = nil;
}
return stringForKey;
} }
/* Dictionaries are a special case for which we don't allow searches in the - (NSDictionary *) dictionaryForKey: (NSString *) key
parent source. Each level can thus have its own set of dictionary values. */
- (id) dictionaryForKey: (NSString *) objectKey
{ {
id objectForKey; NSDictionary *dictionaryForKey;
objectForKey = [source objectForKey: objectKey]; /* Dictionaries are a special case for which we don't allow searches in the
parent source. Each level can thus have its own set of dictionary
values. */
dictionaryForKey = [source objectForKey: key];
if (dictionaryForKey
&& ![dictionaryForKey isKindOfClass: NSDictionaryKlass])
{
[self warnWithFormat: @"expected an NSDictionary for '%@' (ignored)",
key];
dictionaryForKey = nil;
}
return objectForKey; return dictionaryForKey;
}
- (NSArray *) arrayForKey: (NSString *) key
{
NSArray *arrayForKey;
arrayForKey = [self objectForKey: key];
if (arrayForKey && ![arrayForKey isKindOfClass: NSArrayKlass])
{
[self warnWithFormat: @"expected an NSArray for '%@' (ignored)",
key];
arrayForKey = nil;
}
return arrayForKey;
}
- (NSArray *) stringArrayForKey: (NSString *) key
{
NSArray *stringArray;
int count, max;
stringArray = [self arrayForKey: key];
for (count = 0; stringArray && count < max; count++)
if (![[stringArray objectAtIndex: count] isKindOfClass: NSStringKlass])
{
[self warnWithFormat: @"expected string value in array for '%@'"
@", value %d is not a string (ignored)",
key, count];
stringArray = nil;
}
return stringArray;
} }
- (BOOL) migrate - (BOOL) migrate

View File

@ -26,7 +26,7 @@
#import <SOGo/SOGoDefaultsSource.h> #import <SOGo/SOGoDefaultsSource.h>
@class NSArray; @class NSArray;
@class NSMutableDictionary; @class NSDictionary;
@class NSString; @class NSString;
@class NSTimeZone; @class NSTimeZone;
@ -140,11 +140,11 @@ extern NSString *SOGoWeekStartFirstFullWeek;
- (void) setRemindWithASound: (BOOL) newValue; - (void) setRemindWithASound: (BOOL) newValue;
- (BOOL) remindWithASound; - (BOOL) remindWithASound;
- (void) setVacationOptions: (NSMutableDictionary *) newValue; - (void) setVacationOptions: (NSDictionary *) newValue;
- (NSMutableDictionary *) vacationOptions; - (NSDictionary *) vacationOptions;
- (void) setForwardOptions: (NSMutableDictionary *) newValue; - (void) setForwardOptions: (NSDictionary *) newValue;
- (NSMutableDictionary *) forwardOptions; - (NSDictionary *) forwardOptions;
@end @end

View File

@ -540,22 +540,22 @@ NSString *SOGoWeekStartFirstFullWeek = @"FirstFullWeek";
return [self boolForKey: @"SOGoRemindWithASound"]; return [self boolForKey: @"SOGoRemindWithASound"];
} }
- (void) setVacationOptions: (NSMutableDictionary *) newValue - (void) setVacationOptions: (NSDictionary *) newValue
{ {
[self setObject: newValue forKey: @"Vacation"]; [self setObject: newValue forKey: @"Vacation"];
} }
- (NSMutableDictionary *) vacationOptions - (NSDictionary *) vacationOptions
{ {
return [self dictionaryForKey: @"Vacation"]; return [self dictionaryForKey: @"Vacation"];
} }
- (void) setForwardOptions: (NSMutableDictionary *) newValue - (void) setForwardOptions: (NSDictionary *) newValue
{ {
[self setObject: newValue forKey: @"Forward"]; [self setObject: newValue forKey: @"Forward"];
} }
- (NSMutableDictionary *) forwardOptions - (NSDictionary *) forwardOptions
{ {
return [self dictionaryForKey: @"Forward"]; return [self dictionaryForKey: @"Forward"];
} }

View File

@ -32,12 +32,13 @@
#import <NGImap4/NGImap4Connection.h> #import <NGImap4/NGImap4Connection.h>
#import <NGImap4/NGImap4Client.h> #import <NGImap4/NGImap4Client.h>
#import <SoObjects/Mailer/SOGoMailFolder.h> #import <Mailer/SOGoMailFolder.h>
#import <SoObjects/Mailer/SOGoTrashFolder.h> #import <Mailer/SOGoTrashFolder.h>
#import <SoObjects/Mailer/SOGoMailAccount.h> #import <Mailer/SOGoMailAccount.h>
#import <SoObjects/Mailer/SOGoMailObject.h> #import <Mailer/SOGoMailObject.h>
#import <SoObjects/SOGo/NSObject+Utilities.h> #import <SOGo/NSObject+Utilities.h>
#import <SoObjects/SOGo/SOGoUser.h> #import <SOGo/SOGoUser.h>
#import <SOGo/SOGoUserSettings.h>
#import <UI/Common/WODirectAction+SOGo.h> #import <UI/Common/WODirectAction+SOGo.h>

View File

@ -79,24 +79,22 @@
dd = [user domainDefaults]; dd = [user domainDefaults];
if ([dd vacationEnabled]) if ([dd vacationEnabled])
{ {
vacationOptions = [userDefaults vacationOptions]; vacationOptions = [[userDefaults vacationOptions] mutableCopy];
if (!vacationOptions) if (!vacationOptions)
{ {
vacationOptions = [NSMutableDictionary dictionary]; vacationOptions = [NSMutableDictionary new];
[userDefaults setVacationOptions: vacationOptions]; [userDefaults setVacationOptions: vacationOptions];
} }
[vacationOptions retain];
} }
if ([dd forwardEnabled]) if ([dd forwardEnabled])
{ {
forwardOptions = [userDefaults forwardOptions]; forwardOptions = [[userDefaults forwardOptions] mutableCopy];
if (!forwardOptions) if (!forwardOptions)
{ {
forwardOptions = [NSMutableDictionary dictionary]; forwardOptions = [NSMutableDictionary new];
[userDefaults setForwardOptions: forwardOptions]; [userDefaults setForwardOptions: forwardOptions];
} }
[forwardOptions retain];
} }
} }