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