2 * Copyright (c) 2009 Apple Inc. All rights reserved.
4 * @APPLE_LICENSE_HEADER_START@
6 * This file contains Original Code and/or Modifications of Original Code
7 * as defined in and that are subject to the Apple Public Source License
8 * Version 2.0 (the 'License'). You may not use this file except in
9 * compliance with the License. Please obtain a copy of the License at
10 * http://www.opensource.apple.com/apsl/ and read it before using this
13 * The Original Code and all software distributed under the License are
14 * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
15 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
16 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
17 * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
18 * Please see the License for the specific language governing rights and
19 * limitations under the License.
21 * @APPLE_LICENSE_HEADER_END@
24 Copyright (c) 1998-2009, Apple Inc. All rights reserved.
27 #if !defined(__COREFOUNDATION_CFPREFERENCES__)
28 #define __COREFOUNDATION_CFPREFERENCES__ 1
30 #include <CoreFoundation/CFBase.h>
31 #include <CoreFoundation/CFArray.h>
32 #include <CoreFoundation/CFString.h>
37 const CFStringRef kCFPreferencesAnyApplication
;
39 const CFStringRef kCFPreferencesCurrentApplication
;
41 const CFStringRef kCFPreferencesAnyHost
;
43 const CFStringRef kCFPreferencesCurrentHost
;
45 const CFStringRef kCFPreferencesAnyUser
;
47 const CFStringRef kCFPreferencesCurrentUser
;
49 /* NOTE: All CFPropertyListRef values returned from
50 CFPreferences API should be assumed to be immutable.
53 /* The "App" functions search the various sources of defaults that
54 apply to the given application, and should never be called with
55 kCFPreferencesAnyApplication - only kCFPreferencesCurrentApplication
56 or an application's ID (its bundle identifier).
59 /* Searches the various sources of application defaults to find the
60 value for the given key. key must not be NULL. If a value is found,
61 it returns it; otherwise returns NULL. Caller must release the
64 CFPropertyListRef
CFPreferencesCopyAppValue(CFStringRef key
, CFStringRef applicationID
);
66 /* Convenience to interpret a preferences value as a boolean directly.
67 Returns false if the key doesn't exist, or has an improper format; under
68 those conditions, keyExistsAndHasValidFormat (if non-NULL) is set to false */
70 Boolean
CFPreferencesGetAppBooleanValue(CFStringRef key
, CFStringRef applicationID
, Boolean
*keyExistsAndHasValidFormat
);
72 /* Convenience to interpret a preferences value as an integer directly.
73 Returns 0 if the key doesn't exist, or has an improper format; under
74 those conditions, keyExistsAndHasValidFormat (if non-NULL) is set to false */
76 CFIndex
CFPreferencesGetAppIntegerValue(CFStringRef key
, CFStringRef applicationID
, Boolean
*keyExistsAndHasValidFormat
);
78 /* Sets the given value for the given key in the "normal" place for
79 application preferences. key must not be NULL. If value is NULL,
80 key is removed instead. */
82 void CFPreferencesSetAppValue(CFStringRef key
, CFPropertyListRef value
, CFStringRef applicationID
);
84 /* Adds the preferences for the given suite to the app preferences for
85 the specified application. To write to the suite domain, use
86 CFPreferencesSetValue(), below, using the suiteName in place
89 void CFPreferencesAddSuitePreferencesToApp(CFStringRef applicationID
, CFStringRef suiteID
);
92 void CFPreferencesRemoveSuitePreferencesFromApp(CFStringRef applicationID
, CFStringRef suiteID
);
94 /* Writes all changes in all sources of application defaults.
95 Returns success or failure. */
97 Boolean
CFPreferencesAppSynchronize(CFStringRef applicationID
);
99 /* The primitive get mechanism; all arguments must be non-NULL
100 (use the constants above for common values). Only the exact
101 location specified by app-user-host is searched. The returned
102 CFType must be released by the caller when it is finished with it. */
104 CFPropertyListRef
CFPreferencesCopyValue(CFStringRef key
, CFStringRef applicationID
, CFStringRef userName
, CFStringRef hostName
);
106 /* Convenience to fetch multiple keys at once. Keys in
107 keysToFetch that are not present in the returned dictionary
108 are not present in the domain. If keysToFetch is NULL, all
111 CFDictionaryRef
CFPreferencesCopyMultiple(CFArrayRef keysToFetch
, CFStringRef applicationID
, CFStringRef userName
, CFStringRef hostName
);
113 /* The primitive set function; all arguments except value must be
114 non-NULL. If value is NULL, the given key is removed */
116 void CFPreferencesSetValue(CFStringRef key
, CFPropertyListRef value
, CFStringRef applicationID
, CFStringRef userName
, CFStringRef hostName
);
118 /* Convenience to set multiple values at once. Behavior is undefined
119 if a key is in both keysToSet and keysToRemove */
121 void CFPreferencesSetMultiple(CFDictionaryRef keysToSet
, CFArrayRef keysToRemove
, CFStringRef applicationID
, CFStringRef userName
, CFStringRef hostName
);
124 Boolean
CFPreferencesSynchronize(CFStringRef applicationID
, CFStringRef userName
, CFStringRef hostName
);
126 /* Constructs and returns the list of the name of all applications
127 which have preferences in the scope of the given user and host.
128 The returned value must be released by the caller; neither argument
131 CFArrayRef
CFPreferencesCopyApplicationList(CFStringRef userName
, CFStringRef hostName
);
133 /* Constructs and returns the list of all keys set in the given
134 location. The returned value must be released by the caller;
135 all arguments must be non-NULL */
137 CFArrayRef
CFPreferencesCopyKeyList(CFStringRef applicationID
, CFStringRef userName
, CFStringRef hostName
);
142 #endif /* ! __COREFOUNDATION_CFPREFERENCES__ */