2006-06-15 21:34:10 +02:00
|
|
|
/*
|
2009-02-24 02:54:59 +01:00
|
|
|
Copyright (C) 2008-2009 Inverse inc.
|
2009-04-21 17:20:52 +02:00
|
|
|
Copyright (C) 2005 SKYRIX Software AG
|
2006-06-15 21:34:10 +02:00
|
|
|
|
2009-02-24 02:54:59 +01:00
|
|
|
This file is part of SOGo.
|
2006-06-15 21:34:10 +02:00
|
|
|
|
2009-02-24 02:54:59 +01:00
|
|
|
SOGo is free software; you can redistribute it and/or modify it under
|
2006-06-15 21:34:10 +02:00
|
|
|
the terms of the GNU Lesser General Public License as published by the
|
|
|
|
Free Software Foundation; either version 2, or (at your option) any
|
|
|
|
later version.
|
|
|
|
|
2009-02-24 02:54:59 +01:00
|
|
|
SOGo is distributed in the hope that it will be useful, but WITHOUT ANY
|
2006-06-15 21:34:10 +02:00
|
|
|
WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
|
|
|
FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
|
|
|
|
License for more details.
|
|
|
|
|
|
|
|
You should have received a copy of the GNU Lesser General Public
|
|
|
|
License along with OGo; see the file COPYING. If not, write to the
|
|
|
|
Free Software Foundation, 59 Temple Place - Suite 330, Boston, MA
|
|
|
|
02111-1307, USA.
|
|
|
|
*/
|
|
|
|
|
2007-11-08 21:35:09 +01:00
|
|
|
#import <Foundation/NSCalendarDate.h>
|
2007-06-18 17:42:26 +02:00
|
|
|
#import <Foundation/NSPropertyList.h>
|
|
|
|
#import <Foundation/NSUserDefaults.h>
|
2007-03-27 20:12:02 +02:00
|
|
|
#import <Foundation/NSValue.h>
|
2007-06-18 17:42:26 +02:00
|
|
|
|
|
|
|
#import <NGExtensions/NSNull+misc.h>
|
|
|
|
#import <NGExtensions/NSObject+Logs.h>
|
|
|
|
|
2007-03-27 20:12:02 +02:00
|
|
|
#import <GDLContentStore/GCSChannelManager.h>
|
|
|
|
#import <GDLContentStore/NSURL+GCS.h>
|
|
|
|
#import <GDLAccess/EOAdaptorChannel.h>
|
|
|
|
#import <GDLAccess/EOAdaptorContext.h>
|
|
|
|
#import <GDLAccess/EOAttribute.h>
|
|
|
|
|
2007-06-19 19:59:09 +02:00
|
|
|
#import "NSObject+Utilities.h"
|
|
|
|
|
2009-10-26 14:39:28 +01:00
|
|
|
#import "NSDictionary+BSJSONAdditions.h"
|
2008-07-25 19:52:49 +02:00
|
|
|
#import "SOGoUserDefaults.h"
|
2009-03-03 20:08:02 +01:00
|
|
|
#import "SOGoCache.h"
|
2006-06-15 21:34:10 +02:00
|
|
|
|
2008-07-25 19:52:49 +02:00
|
|
|
@implementation SOGoUserDefaults
|
2006-06-15 21:34:10 +02:00
|
|
|
|
2007-07-24 20:45:52 +02:00
|
|
|
static NSString *uidColumnName = @"c_uid";
|
2006-06-15 21:34:10 +02:00
|
|
|
|
2009-03-03 20:08:02 +01:00
|
|
|
- (id) initWithTableURL: (NSURL *) theURL
|
|
|
|
uid: (NSString *) theUID
|
|
|
|
fieldName: (NSString *) theFieldName
|
2007-03-27 20:12:02 +02:00
|
|
|
{
|
2009-01-13 21:39:19 +01:00
|
|
|
if ((self = [self init]))
|
2007-03-27 20:12:02 +02:00
|
|
|
{
|
2009-03-03 20:08:02 +01:00
|
|
|
if (theURL && [theUID length] > 0
|
|
|
|
&& [theFieldName length] > 0)
|
2007-03-27 20:12:02 +02:00
|
|
|
{
|
2009-03-03 20:08:02 +01:00
|
|
|
fieldName = [theFieldName copy];
|
|
|
|
url = [theURL copy];
|
|
|
|
uid = [theUID copy];
|
2009-03-22 15:20:50 +01:00
|
|
|
defFlags.ready = YES;
|
2009-10-13 22:17:29 +02:00
|
|
|
defFlags.isNew = YES;
|
2007-03-27 20:12:02 +02:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
[self errorWithFormat: @"missing arguments"];
|
|
|
|
[self release];
|
|
|
|
self = nil;
|
|
|
|
}
|
2006-06-15 21:34:10 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
return self;
|
|
|
|
}
|
2007-03-27 20:12:02 +02:00
|
|
|
|
|
|
|
- (void) dealloc
|
|
|
|
{
|
|
|
|
[values release];
|
|
|
|
[url release];
|
|
|
|
[uid release];
|
|
|
|
[fieldName release];
|
2006-06-15 21:34:10 +02:00
|
|
|
[super dealloc];
|
|
|
|
}
|
|
|
|
|
|
|
|
/* accessors */
|
|
|
|
|
2007-03-27 20:12:02 +02:00
|
|
|
- (NSURL *) tableURL
|
|
|
|
{
|
|
|
|
return url;
|
2006-06-15 21:34:10 +02:00
|
|
|
}
|
|
|
|
|
2007-03-27 20:12:02 +02:00
|
|
|
- (NSString *) uid
|
|
|
|
{
|
|
|
|
return uid;
|
2006-06-15 21:34:10 +02:00
|
|
|
}
|
|
|
|
|
2007-03-27 20:12:02 +02:00
|
|
|
- (NSString *) fieldName
|
|
|
|
{
|
|
|
|
return fieldName;
|
|
|
|
}
|
2006-06-15 21:34:10 +02:00
|
|
|
|
2007-03-27 20:12:02 +02:00
|
|
|
/* operation */
|
|
|
|
|
|
|
|
- (BOOL) primaryFetchProfile
|
|
|
|
{
|
2006-06-15 21:34:10 +02:00
|
|
|
GCSChannelManager *cm;
|
2007-03-27 20:12:02 +02:00
|
|
|
EOAdaptorChannel *channel;
|
2007-05-10 18:15:24 +02:00
|
|
|
NSDictionary *row;
|
2007-03-27 20:12:02 +02:00
|
|
|
NSException *ex;
|
2007-11-01 13:25:21 +01:00
|
|
|
NSString *sql, *value, *error;
|
2007-03-27 20:12:02 +02:00
|
|
|
NSArray *attrs;
|
|
|
|
BOOL rc;
|
2007-05-11 23:22:48 +02:00
|
|
|
NSData *plistData;
|
2007-03-27 20:12:02 +02:00
|
|
|
|
|
|
|
rc = NO;
|
2006-06-15 21:34:10 +02:00
|
|
|
|
|
|
|
cm = [GCSChannelManager defaultChannelManager];
|
2007-03-27 20:12:02 +02:00
|
|
|
channel = [cm acquireOpenChannelForURL: [self tableURL]];
|
|
|
|
if (channel)
|
|
|
|
{
|
|
|
|
/* generate SQL */
|
2009-03-20 23:24:31 +01:00
|
|
|
defFlags.ready = YES;
|
2007-03-27 20:12:02 +02:00
|
|
|
sql = [NSString stringWithFormat: (@"SELECT %@"
|
|
|
|
@" FROM %@"
|
|
|
|
@" WHERE %@ = '%@'"),
|
|
|
|
fieldName, [[self tableURL] gcsTableName],
|
|
|
|
uidColumnName, [self uid]];
|
2007-05-03 17:12:51 +02:00
|
|
|
|
2009-03-03 20:08:02 +01:00
|
|
|
values = [[NSMutableDictionary alloc] init];
|
2007-05-03 17:12:51 +02:00
|
|
|
|
2007-03-27 20:12:02 +02:00
|
|
|
/* run SQL */
|
|
|
|
ex = [channel evaluateExpressionX: sql];
|
|
|
|
if (ex)
|
2007-05-03 17:12:51 +02:00
|
|
|
[self errorWithFormat:@"could not run SQL '%@': %@", sql, ex];
|
2007-03-27 20:12:02 +02:00
|
|
|
else
|
|
|
|
{
|
|
|
|
/* fetch schema */
|
|
|
|
attrs = [channel describeResults: NO /* don't beautify */];
|
|
|
|
|
|
|
|
/* fetch values */
|
|
|
|
row = [channel fetchAttributes: attrs withZone: NULL];
|
2009-10-13 22:17:29 +02:00
|
|
|
defFlags.isNew = !row;
|
2007-03-27 20:12:02 +02:00
|
|
|
[channel cancelFetch];
|
|
|
|
|
|
|
|
/* remember values */
|
2007-05-10 18:15:24 +02:00
|
|
|
value = [row objectForKey: fieldName];
|
|
|
|
if ([value isNotNull])
|
2007-05-11 23:22:48 +02:00
|
|
|
{
|
2009-03-03 20:08:02 +01:00
|
|
|
id v;
|
|
|
|
|
2008-03-27 21:29:33 +01:00
|
|
|
value = [value stringByReplacingString: @"''"
|
|
|
|
withString: @"'"];
|
|
|
|
value = [value stringByReplacingString: @"\\\\"
|
|
|
|
withString: @"\\"];
|
2007-05-11 23:22:48 +02:00
|
|
|
plistData = [value dataUsingEncoding: NSUTF8StringEncoding];
|
2009-03-03 20:08:02 +01:00
|
|
|
v = [NSPropertyListSerialization propertyListFromData: plistData
|
2007-11-01 13:25:21 +01:00
|
|
|
mutabilityOption: NSPropertyListMutableContainers
|
|
|
|
format: NULL
|
|
|
|
errorDescription: &error];
|
2009-03-03 20:08:02 +01:00
|
|
|
if ([v isKindOfClass: [NSMutableDictionary class]])
|
|
|
|
[values addEntriesFromDictionary: v];
|
2007-05-11 23:22:48 +02:00
|
|
|
}
|
2009-03-03 20:08:02 +01:00
|
|
|
|
2007-03-27 20:12:02 +02:00
|
|
|
defFlags.modified = NO;
|
|
|
|
rc = YES;
|
|
|
|
}
|
|
|
|
|
|
|
|
[cm releaseChannel:channel];
|
|
|
|
}
|
|
|
|
else
|
2009-03-20 23:24:31 +01:00
|
|
|
{
|
|
|
|
defFlags.ready = NO;
|
|
|
|
[self errorWithFormat:@"failed to acquire channel for URL: %@",
|
|
|
|
[self tableURL]];
|
|
|
|
}
|
2006-06-15 21:34:10 +02:00
|
|
|
|
2007-03-27 20:12:02 +02:00
|
|
|
return rc;
|
2006-06-15 21:34:10 +02:00
|
|
|
}
|
|
|
|
|
2007-11-01 13:25:21 +01:00
|
|
|
- (NSString *) _serializedDefaults
|
2007-03-27 20:12:02 +02:00
|
|
|
{
|
2007-11-01 13:25:21 +01:00
|
|
|
NSMutableString *serializedDefaults;
|
2007-03-27 20:12:02 +02:00
|
|
|
NSData *serializedDefaultsData;
|
2007-03-29 21:13:27 +02:00
|
|
|
NSString *error;
|
2007-03-27 20:12:02 +02:00
|
|
|
|
2007-06-30 00:10:52 +02:00
|
|
|
error = nil;
|
2007-03-27 20:12:02 +02:00
|
|
|
serializedDefaultsData
|
|
|
|
= [NSPropertyListSerialization dataFromPropertyList: values
|
|
|
|
format: NSPropertyListOpenStepFormat
|
|
|
|
errorDescription: &error];
|
|
|
|
if (error)
|
2007-06-30 00:10:52 +02:00
|
|
|
{
|
2007-11-01 13:25:21 +01:00
|
|
|
[self errorWithFormat: @"serializing the defaults: %@", error];
|
|
|
|
serializedDefaults = nil;
|
2007-06-30 00:10:52 +02:00
|
|
|
[error release];
|
|
|
|
}
|
2007-03-27 20:12:02 +02:00
|
|
|
else
|
|
|
|
{
|
2007-11-01 13:25:21 +01:00
|
|
|
serializedDefaults
|
|
|
|
= [[NSMutableString alloc] initWithData: serializedDefaultsData
|
|
|
|
encoding: NSUTF8StringEncoding];
|
|
|
|
[serializedDefaults autorelease];
|
|
|
|
[serializedDefaults replaceString: @"\\" withString: @"\\\\"];
|
|
|
|
[serializedDefaults replaceString: @"'" withString: @"''"];
|
2007-03-27 20:12:02 +02:00
|
|
|
}
|
2007-11-01 13:25:21 +01:00
|
|
|
|
|
|
|
return serializedDefaults;
|
|
|
|
}
|
|
|
|
|
|
|
|
- (NSString *) generateSQLForInsert
|
|
|
|
{
|
|
|
|
NSString *sql, *serializedDefaults;
|
|
|
|
|
|
|
|
serializedDefaults = [self _serializedDefaults];
|
|
|
|
if (serializedDefaults)
|
|
|
|
sql = [NSString stringWithFormat: (@"INSERT INTO %@"
|
|
|
|
@" (%@, %@)"
|
|
|
|
@" VALUES ('%@', '%@')"),
|
|
|
|
[[self tableURL] gcsTableName], uidColumnName, fieldName,
|
|
|
|
[self uid], serializedDefaults];
|
|
|
|
else
|
|
|
|
sql = nil;
|
2007-03-27 20:12:02 +02:00
|
|
|
|
2006-06-15 21:34:10 +02:00
|
|
|
return sql;
|
|
|
|
}
|
|
|
|
|
2007-03-27 20:12:02 +02:00
|
|
|
- (NSString *) generateSQLForUpdate
|
|
|
|
{
|
2007-11-01 13:25:21 +01:00
|
|
|
NSString *sql, *serializedDefaults;
|
|
|
|
|
|
|
|
serializedDefaults = [self _serializedDefaults];
|
|
|
|
if (serializedDefaults)
|
|
|
|
sql = [NSString stringWithFormat: (@"UPDATE %@"
|
|
|
|
@" SET %@ = '%@'"
|
|
|
|
@" WHERE %@ = '%@'"),
|
|
|
|
[[self tableURL] gcsTableName],
|
|
|
|
fieldName,
|
|
|
|
serializedDefaults,
|
|
|
|
uidColumnName, [self uid]];
|
2007-03-27 20:12:02 +02:00
|
|
|
else
|
2007-11-01 13:25:21 +01:00
|
|
|
sql = nil;
|
2007-03-27 20:12:02 +02:00
|
|
|
|
2006-06-15 21:34:10 +02:00
|
|
|
return sql;
|
|
|
|
}
|
|
|
|
|
2007-03-27 20:12:02 +02:00
|
|
|
- (BOOL) primaryStoreProfile
|
|
|
|
{
|
2006-06-15 21:34:10 +02:00
|
|
|
GCSChannelManager *cm;
|
2007-03-27 20:12:02 +02:00
|
|
|
EOAdaptorChannel *channel;
|
|
|
|
NSException *ex;
|
|
|
|
NSString *sql;
|
|
|
|
BOOL rc;
|
|
|
|
|
|
|
|
rc = NO;
|
2006-06-15 21:34:10 +02:00
|
|
|
|
|
|
|
cm = [GCSChannelManager defaultChannelManager];
|
2007-03-27 20:12:02 +02:00
|
|
|
sql = ((defFlags.isNew)
|
|
|
|
? [self generateSQLForInsert]
|
|
|
|
: [self generateSQLForUpdate]);
|
|
|
|
if (sql)
|
|
|
|
{
|
|
|
|
channel = [cm acquireOpenChannelForURL: [self tableURL]];
|
|
|
|
if (channel)
|
|
|
|
{
|
2009-03-20 23:24:31 +01:00
|
|
|
defFlags.ready = YES;
|
2008-12-02 02:36:53 +01:00
|
|
|
[[channel adaptorContext] beginTransaction];
|
2007-03-27 20:12:02 +02:00
|
|
|
ex = [channel evaluateExpressionX:sql];
|
|
|
|
if (ex)
|
2008-12-02 02:36:53 +01:00
|
|
|
{
|
|
|
|
[self errorWithFormat: @"could not run SQL '%@': %@", sql, ex];
|
|
|
|
[[channel adaptorContext] rollbackTransaction];
|
|
|
|
}
|
2007-03-27 20:12:02 +02:00
|
|
|
else
|
|
|
|
{
|
2008-12-02 02:36:53 +01:00
|
|
|
if ([[channel adaptorContext] commitTransaction])
|
2007-03-27 20:12:02 +02:00
|
|
|
{
|
2008-12-02 02:36:53 +01:00
|
|
|
rc = YES;
|
2007-03-27 20:12:02 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
defFlags.modified = NO;
|
|
|
|
defFlags.isNew = NO;
|
|
|
|
}
|
|
|
|
|
|
|
|
[cm releaseChannel: channel];
|
|
|
|
}
|
|
|
|
else
|
2009-03-20 23:24:31 +01:00
|
|
|
{
|
|
|
|
defFlags.ready = NO;
|
|
|
|
[self errorWithFormat: @"failed to acquire channel for URL: %@",
|
|
|
|
[self tableURL]];
|
|
|
|
}
|
2007-03-27 20:12:02 +02:00
|
|
|
}
|
|
|
|
else
|
|
|
|
[self errorWithFormat: @"failed to generate SQL for storing defaults"];
|
2006-06-15 21:34:10 +02:00
|
|
|
|
2008-12-02 02:36:53 +01:00
|
|
|
if (rc)
|
2009-09-19 22:07:31 +02:00
|
|
|
[[SOGoCache sharedCache] cacheValues: values
|
|
|
|
ofType: ([fieldName isEqualToString: @"c_defaults"] ? @"defaults" : @"settings")
|
|
|
|
forLogin: uid];
|
2008-12-02 02:36:53 +01:00
|
|
|
|
2007-03-27 20:12:02 +02:00
|
|
|
return rc;
|
2006-06-15 21:34:10 +02:00
|
|
|
}
|
|
|
|
|
2007-03-27 20:12:02 +02:00
|
|
|
- (BOOL) fetchProfile
|
|
|
|
{
|
2009-03-22 17:03:21 +01:00
|
|
|
return (values || [self primaryFetchProfile]);
|
2006-06-15 21:34:10 +02:00
|
|
|
}
|
|
|
|
|
2007-06-19 19:59:09 +02:00
|
|
|
- (NSString *) jsonRepresentation
|
|
|
|
{
|
2009-03-20 21:56:29 +01:00
|
|
|
NSString *jsonRep;
|
|
|
|
|
2007-06-19 19:59:09 +02:00
|
|
|
[self fetchProfile];
|
2009-03-20 21:56:29 +01:00
|
|
|
if (values)
|
2009-10-13 22:17:29 +02:00
|
|
|
jsonRep = [values jsonStringValue];
|
2009-03-20 21:56:29 +01:00
|
|
|
else
|
|
|
|
jsonRep = @"{}";
|
2007-06-19 19:59:09 +02:00
|
|
|
|
2009-03-20 21:56:29 +01:00
|
|
|
return jsonRep;
|
2007-06-19 19:59:09 +02:00
|
|
|
}
|
|
|
|
|
2006-06-15 21:34:10 +02:00
|
|
|
/* value access */
|
2008-11-05 22:04:16 +01:00
|
|
|
- (void) setValues: (NSDictionary *) theValues
|
|
|
|
{
|
2009-03-03 20:08:02 +01:00
|
|
|
[values release];
|
|
|
|
|
|
|
|
values = [[NSMutableDictionary alloc] init];
|
2008-11-05 22:04:16 +01:00
|
|
|
[values addEntriesFromDictionary: theValues];
|
2009-02-24 02:54:59 +01:00
|
|
|
defFlags.modified = NO;
|
|
|
|
defFlags.isNew = NO;
|
|
|
|
}
|
|
|
|
|
|
|
|
- (NSDictionary *) values
|
|
|
|
{
|
|
|
|
return values;
|
2008-11-05 22:04:16 +01:00
|
|
|
}
|
2006-06-15 21:34:10 +02:00
|
|
|
|
2007-03-27 20:12:02 +02:00
|
|
|
- (void) setObject: (id) value
|
|
|
|
forKey: (NSString *) key
|
|
|
|
{
|
|
|
|
id old;
|
2006-06-15 21:34:10 +02:00
|
|
|
|
2009-03-22 15:40:50 +01:00
|
|
|
if (!defFlags.ready || ![self fetchProfile])
|
2006-06-15 21:34:10 +02:00
|
|
|
return;
|
|
|
|
|
2007-03-27 20:12:02 +02:00
|
|
|
/* check whether the value is actually modified */
|
|
|
|
if (!defFlags.modified)
|
|
|
|
{
|
|
|
|
old = [values objectForKey: key];
|
|
|
|
if (old == value || [old isEqual: value]) /* value didn't change */
|
|
|
|
return;
|
|
|
|
|
|
|
|
/* we need to this because our typed accessors convert to strings */
|
|
|
|
// TODO: especially problematic with bools
|
|
|
|
if ([value isKindOfClass: [NSString class]]) {
|
|
|
|
if (![old isKindOfClass: [NSString class]])
|
|
|
|
if ([[old description] isEqualToString: value])
|
|
|
|
return;
|
|
|
|
}
|
2006-06-15 21:34:10 +02:00
|
|
|
}
|
2007-03-27 20:12:02 +02:00
|
|
|
|
2006-06-15 21:34:10 +02:00
|
|
|
/* set in hash and mark as modified */
|
2009-05-15 17:52:29 +02:00
|
|
|
if (value)
|
|
|
|
[values setObject: value forKey: key];
|
|
|
|
else
|
|
|
|
[values removeObjectForKey: key];
|
2007-03-27 20:12:02 +02:00
|
|
|
|
|
|
|
defFlags.modified = YES;
|
2006-06-15 21:34:10 +02:00
|
|
|
}
|
|
|
|
|
2007-03-27 20:12:02 +02:00
|
|
|
- (id) objectForKey: (NSString *) key
|
|
|
|
{
|
2006-06-15 21:34:10 +02:00
|
|
|
id value;
|
|
|
|
|
2009-03-20 23:24:31 +01:00
|
|
|
if (!defFlags.ready || ![self fetchProfile])
|
2007-03-27 20:12:02 +02:00
|
|
|
value = nil;
|
|
|
|
else
|
|
|
|
value = [values objectForKey: key];
|
|
|
|
|
|
|
|
return value;
|
2006-06-15 21:34:10 +02:00
|
|
|
}
|
|
|
|
|
2007-03-27 20:12:02 +02:00
|
|
|
- (void) removeObjectForKey: (NSString *) key
|
|
|
|
{
|
|
|
|
[self setObject: nil forKey: key];
|
2006-06-15 21:34:10 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/* saving changes */
|
|
|
|
|
2007-03-27 20:12:02 +02:00
|
|
|
- (BOOL) synchronize
|
|
|
|
{
|
|
|
|
// if (!defFlags.modified) /* was not modified */
|
|
|
|
// return YES;
|
2006-06-15 21:34:10 +02:00
|
|
|
|
|
|
|
/* ensure fetched data (more or less guaranteed by modified!=0) */
|
|
|
|
if (![self fetchProfile])
|
|
|
|
return NO;
|
2007-06-30 00:10:52 +02:00
|
|
|
|
2006-06-15 21:34:10 +02:00
|
|
|
/* store */
|
2007-03-27 20:12:02 +02:00
|
|
|
if (![self primaryStoreProfile])
|
|
|
|
{
|
|
|
|
[self primaryFetchProfile];
|
|
|
|
return NO;
|
|
|
|
}
|
|
|
|
|
2006-06-15 21:34:10 +02:00
|
|
|
/* refetch */
|
|
|
|
return [self primaryFetchProfile];
|
|
|
|
}
|
|
|
|
|
|
|
|
/* typed accessors */
|
|
|
|
|
2007-03-27 20:12:02 +02:00
|
|
|
- (NSArray *) arrayForKey: (NSString *) key
|
|
|
|
{
|
|
|
|
return [self objectForKey: key];
|
2006-06-15 21:34:10 +02:00
|
|
|
}
|
|
|
|
|
2007-03-27 20:12:02 +02:00
|
|
|
- (NSDictionary *) dictionaryForKey: (NSString *) key
|
|
|
|
{
|
|
|
|
return [self objectForKey: key];
|
2006-06-15 21:34:10 +02:00
|
|
|
}
|
|
|
|
|
2007-03-27 20:12:02 +02:00
|
|
|
- (NSData *) dataForKey: (NSString *) key
|
|
|
|
{
|
|
|
|
return [self objectForKey: key];
|
2006-06-15 21:34:10 +02:00
|
|
|
}
|
|
|
|
|
2007-03-27 20:12:02 +02:00
|
|
|
- (NSString *) stringForKey: (NSString *) key
|
|
|
|
{
|
|
|
|
return [self objectForKey: key];
|
2006-06-15 21:34:10 +02:00
|
|
|
}
|
|
|
|
|
2007-03-27 20:12:02 +02:00
|
|
|
- (BOOL) boolForKey: (NSString *) key
|
|
|
|
{
|
|
|
|
return [[self objectForKey: key] boolValue];
|
2006-06-15 21:34:10 +02:00
|
|
|
}
|
|
|
|
|
2007-03-27 20:12:02 +02:00
|
|
|
- (float) floatForKey: (NSString *) key
|
|
|
|
{
|
|
|
|
return [[self objectForKey: key] floatValue];
|
2006-06-15 21:34:10 +02:00
|
|
|
}
|
|
|
|
|
2007-03-27 20:12:02 +02:00
|
|
|
- (int) integerForKey: (NSString *) key
|
|
|
|
{
|
|
|
|
return [[self objectForKey: key] intValue];
|
2006-06-15 21:34:10 +02:00
|
|
|
}
|
|
|
|
|
2007-03-27 20:12:02 +02:00
|
|
|
- (void) setBool: (BOOL) value
|
|
|
|
forKey: (NSString *) key
|
|
|
|
{
|
2006-06-15 21:34:10 +02:00
|
|
|
// TODO: need special support here for int-DB fields
|
2007-03-27 20:12:02 +02:00
|
|
|
[self setObject: [NSNumber numberWithBool: value]
|
|
|
|
forKey: key];
|
2006-06-15 21:34:10 +02:00
|
|
|
}
|
|
|
|
|
2007-03-27 20:12:02 +02:00
|
|
|
- (void) setFloat: (float) value
|
|
|
|
forKey: (NSString *) key
|
|
|
|
{
|
|
|
|
[self setObject: [NSNumber numberWithFloat: value]
|
|
|
|
forKey: key];
|
|
|
|
}
|
2006-06-15 21:34:10 +02:00
|
|
|
|
2007-03-27 20:12:02 +02:00
|
|
|
- (void) setInteger: (int) value
|
|
|
|
forKey: (NSString *) key
|
|
|
|
{
|
|
|
|
[self setObject: [NSNumber numberWithInt: value]
|
|
|
|
forKey: key];
|
2006-06-15 21:34:10 +02:00
|
|
|
}
|
|
|
|
|
2009-03-03 20:08:02 +01:00
|
|
|
- (NSString *) description
|
|
|
|
{
|
|
|
|
return [values description];
|
|
|
|
}
|
|
|
|
|
2008-07-25 19:52:49 +02:00
|
|
|
@end /* SOGoUserDefaults */
|