source: trunk/ICeCoffEE/ICeCoffEE/CFPreferencesWrapper.m@ 66

Last change on this file since 66 was 66, checked in by Nicholas Riley, 22 years ago

Initial import.

File size: 4.5 KB
Line 
1
2#import <Carbon/Carbon.h>
3#import "CFPreferencesWrapper.h"
4
5
6@implementation CFPreferencesWrapper_ICeCoffEE
7
8- initWithApplication:(NSString*)appIdentifier
9{
10 self = [super init];
11
12 if( !self || !appIdentifier )
13 {
14 [self release];
15 return nil;
16 }
17
18 identifier = [appIdentifier retain];
19
20 return self;
21}
22
23- (void)dealloc
24{
25 [identifier release];
26
27 [super dealloc];
28}
29
30+ preferencesWithApplication:(NSString*)appIdentifier
31{
32 return [[[self alloc] initWithApplication:appIdentifier] autorelease];
33}
34
35
36- (NSArray*)arrayForKey:(NSString*)key
37{
38 id object;
39
40 object = (id) CFPreferencesCopyAppValue( (CFStringRef) key, (CFStringRef) identifier);
41
42 if( object && (CFGetTypeID( object) == CFArrayGetTypeID()) )
43 return [object autorelease];
44 else
45 {
46 [object release];
47 return nil;
48 }
49}
50
51- (BOOL)boolForKey:(NSString*)key
52{
53 Boolean dummy;
54
55 return CFPreferencesGetAppBooleanValue( (CFStringRef) key, (CFStringRef) identifier, &dummy);
56}
57
58- (NSData*)dataForKey:(NSString*)key
59{
60 id object;
61
62 object = (id) CFPreferencesCopyAppValue( (CFStringRef) key, (CFStringRef) identifier);
63
64 if( object && (CFGetTypeID( object) == CFDataGetTypeID()) )
65 return [object autorelease];
66 else
67 {
68 [object release];
69 return nil;
70 }
71}
72
73- (NSDictionary*)dictionaryForKey:(NSString*)key
74{
75 id object;
76
77 object = (id) CFPreferencesCopyAppValue( (CFStringRef) key, (CFStringRef) identifier);
78
79 if( object && (CFGetTypeID( object) == CFDictionaryGetTypeID()) )
80 return [object autorelease];
81 else
82 {
83 [object release];
84 return nil;
85 }
86}
87
88- (float)floatForKey:(NSString*)key
89{
90 id object;
91 float retVal;
92
93 object = (id) CFPreferencesCopyAppValue( (CFStringRef) key, (CFStringRef) identifier);
94
95 if( object && (CFGetTypeID( object) == CFNumberGetTypeID()) )
96 {
97 retVal = [object floatValue];
98 [object release];
99 return retVal;
100 }
101 else
102 {
103 [object release];
104 return 0;
105 }
106}
107
108- (int)integerForKey:(NSString*)key
109{
110 Boolean dummy;
111
112 return CFPreferencesGetAppIntegerValue( (CFStringRef) key, (CFStringRef) identifier, &dummy);
113}
114
115- (id)objectForKey:(NSString*)key
116{
117 return [(id) CFPreferencesCopyAppValue( (CFStringRef) key, (CFStringRef) identifier) autorelease];
118}
119
120- (NSArray*)stringArrayForKey:(NSString*)key
121{
122 id object;
123
124 object = (id) CFPreferencesCopyAppValue( (CFStringRef) key, (CFStringRef) identifier);
125
126 if( object && (CFGetTypeID( object) == CFArrayGetTypeID()) )
127 {
128 NSEnumerator *enumerator = [object objectEnumerator];
129 id element;
130
131 while( (element = [enumerator nextObject]) )
132 {
133 if( CFGetTypeID( element) != CFStringGetTypeID() )
134 {
135 [object release];
136 return nil;
137 }
138 }
139
140 return [object autorelease];
141 }
142 else
143 {
144 [object release];
145 return nil;
146 }
147}
148
149- (NSString*)stringForKey:(NSString*)key
150{
151 id object;
152
153 object = (id) CFPreferencesCopyAppValue( (CFStringRef) key, (CFStringRef) identifier);
154
155 if( object && (CFGetTypeID( object) == CFStringGetTypeID()) )
156 return [object autorelease];
157 else
158 {
159 [object release];
160 return nil;
161 }
162}
163
164
165- (void)removeObjectForKey:(NSString*)key
166{
167 CFPreferencesSetAppValue( (CFStringRef) key, (CFPropertyListRef) NULL, (CFStringRef) identifier);
168}
169
170- (void)setBool:(BOOL)value forKey:(NSString*)key
171{
172 CFPreferencesSetAppValue( (CFStringRef) key, (CFPropertyListRef) (value ? kCFBooleanTrue : kCFBooleanFalse), (CFStringRef) identifier);
173}
174
175- (void)setFloat:(float)value forKey:(NSString*)key
176{
177 CFPreferencesSetAppValue( (CFStringRef) key, (CFPropertyListRef) [NSNumber numberWithFloat:value], (CFStringRef) identifier);
178}
179
180- (void)setInteger:(int)value forKey:(NSString*)key
181{
182 CFPreferencesSetAppValue( (CFStringRef) key, (CFPropertyListRef) [NSNumber numberWithInt:value], (CFStringRef) identifier);
183}
184
185- (void)setObject:(id)value forKey:(NSString*)key
186{
187 CFPreferencesSetAppValue( (CFStringRef) key, (CFPropertyListRef) value, (CFStringRef) identifier);
188}
189
190- (BOOL)keyExist:(NSString*)key
191{
192 BOOL exist = NO;
193
194 CFPropertyListRef value = CFPreferencesCopyAppValue((CFStringRef)key, (CFStringRef)identifier);
195 if (value)
196 {
197 exist = YES;
198 CFRelease(value);
199 }
200
201 return exist;
202}
203
204- (BOOL)synchronize
205{
206 return CFPreferencesAppSynchronize( (CFStringRef) identifier);
207}
208
209@end
Note: See TracBrowser for help on using the repository browser.