46 #include "CACFPreferences.h"
49 #include "CACFDistributedNotification.h"
50 #include "CADebugMacros.h"
56 CFPropertyListRef CACFPreferences::CopyValue(CFStringRef inKey,
bool inCurrentUser,
bool inCurrentHost)
59 Synchronize(inCurrentUser, inCurrentHost,
false);
61 CFPropertyListRef theAnswer = NULL;
62 CFStringRef theUser = inCurrentUser ? kCFPreferencesCurrentUser : kCFPreferencesAnyUser;
63 CFStringRef theHost = inCurrentHost ? kCFPreferencesCurrentHost : kCFPreferencesAnyHost;
65 theAnswer = CFPreferencesCopyValue(inKey, kCFPreferencesAnyApplication, theUser, theHost);
70 CFStringRef CACFPreferences::CopyStringValue(CFStringRef inKey,
bool inCurrentUser,
bool inCurrentHost)
72 CFStringRef theAnswer = NULL;
75 CFPropertyListRef theRawValue = CopyValue(inKey, inCurrentUser, inCurrentHost);
77 if(theRawValue != NULL)
80 CFTypeID theTypeID = CFGetTypeID(theRawValue);
81 if(theTypeID == CFStringGetTypeID())
84 theAnswer =
static_cast<CFStringRef
>(theRawValue);
88 CFRelease(theRawValue);
89 DebugMessage(
"CACFPreferences::CopyStringValue: not a CFString");
96 CFNumberRef CACFPreferences::CopyNumberValue(CFStringRef inKey,
bool inCurrentUser,
bool inCurrentHost)
98 CFNumberRef theAnswer = NULL;
101 CFPropertyListRef theRawValue = CopyValue(inKey, inCurrentUser, inCurrentHost);
103 if(theRawValue != NULL)
106 CFTypeID theTypeID = CFGetTypeID(theRawValue);
107 if(theTypeID == CFNumberGetTypeID())
110 theAnswer =
static_cast<CFNumberRef
>(theRawValue);
114 CFRelease(theRawValue);
115 DebugMessage(
"CACFPreferences::CopyNumberValue: not a CFNumber");
122 CFArrayRef CACFPreferences::CopyArrayValue(CFStringRef inKey,
bool inCurrentUser,
bool inCurrentHost)
124 CFArrayRef theAnswer = NULL;
127 CFPropertyListRef theRawValue = CopyValue(inKey, inCurrentUser, inCurrentHost);
129 if(theRawValue != NULL)
132 CFTypeID theTypeID = CFGetTypeID(theRawValue);
133 if(theTypeID == CFArrayGetTypeID())
136 theAnswer =
static_cast<CFArrayRef
>(theRawValue);
140 CFRelease(theRawValue);
141 DebugMessage(
"CACFPreferences::CopyArrayValue: not a CFArray");
148 CFDictionaryRef CACFPreferences::CopyDictionaryValue(CFStringRef inKey,
bool inCurrentUser,
bool inCurrentHost)
150 CFDictionaryRef theAnswer = NULL;
153 CFPropertyListRef theRawValue = CopyValue(inKey, inCurrentUser, inCurrentHost);
155 if(theRawValue != NULL)
158 CFTypeID theTypeID = CFGetTypeID(theRawValue);
159 if(theTypeID == CFDictionaryGetTypeID())
162 theAnswer =
static_cast<CFDictionaryRef
>(theRawValue);
166 CFRelease(theRawValue);
167 DebugMessage(
"CACFPreferences::CopyDictionaryValue: not a CFDictionary");
174 void CACFPreferences::SetValue(CFStringRef inKey, CFPropertyListRef inValue,
bool inCurrentUser,
bool inCurrentHost,
bool inSynchronize)
176 CFStringRef theUser = inCurrentUser ? kCFPreferencesCurrentUser : kCFPreferencesAnyUser;
177 CFStringRef theHost = inCurrentHost ? kCFPreferencesCurrentHost : kCFPreferencesAnyHost;
178 CFPreferencesSetValue(inKey, inValue, kCFPreferencesAnyApplication, theUser, theHost);
182 Synchronize(inCurrentUser, inCurrentHost,
true);
186 void CACFPreferences::DeleteValue(CFStringRef inKey,
bool inCurrentUser,
bool inCurrentHost,
bool inSynchronize)
188 CFStringRef theUser = inCurrentUser ? kCFPreferencesCurrentUser : kCFPreferencesAnyUser;
189 CFStringRef theHost = inCurrentHost ? kCFPreferencesCurrentHost : kCFPreferencesAnyHost;
190 CFPreferencesSetValue(inKey, NULL, kCFPreferencesAnyApplication, theUser, theHost);
194 Synchronize(theUser, inCurrentHost,
true);
198 void CACFPreferences::Synchronize(
bool inCurrentUser,
bool inCurrentHost,
bool inForce)
200 if(inForce || ArePrefsOutOfDate(inCurrentUser, inCurrentHost))
202 CFStringRef theUser = inCurrentUser ? kCFPreferencesCurrentUser : kCFPreferencesAnyUser;
203 CFStringRef theHost = inCurrentHost ? kCFPreferencesCurrentHost : kCFPreferencesAnyHost;
204 CFPreferencesSynchronize(kCFPreferencesAnyApplication, theUser, theHost);
205 MarkPrefsClean(inCurrentUser, inCurrentHost);
209 void CACFPreferences::MarkPrefsOutOfDate(
bool inCurrentUser,
bool inCurrentHost)
211 if(!inCurrentUser && !inCurrentHost)
213 sAnyUserAnyHostPrefsOutOfDate =
true;
215 else if(!inCurrentUser && inCurrentHost)
217 sAnyUserCurrentHostPrefsOutOfDate =
true;
219 else if(inCurrentUser && !inCurrentHost)
221 sCurrentUserAnyHostPrefsOutOfDate =
true;
223 else if(inCurrentUser && inCurrentHost)
225 sCurrentUserCurrentHostPrefsOutOfDate =
true;
229 void CACFPreferences::MarkPrefsClean(
bool inCurrentUser,
bool inCurrentHost)
231 if(!inCurrentUser && !inCurrentHost)
233 sAnyUserAnyHostPrefsOutOfDate =
false;
235 else if(!inCurrentUser && inCurrentHost)
237 sAnyUserCurrentHostPrefsOutOfDate =
false;
239 else if(inCurrentUser && !inCurrentHost)
241 sCurrentUserAnyHostPrefsOutOfDate =
false;
243 else if(inCurrentUser && inCurrentHost)
245 sCurrentUserCurrentHostPrefsOutOfDate =
false;
249 void CACFPreferences::SendNotification(CFStringRef inName)
251 CACFDistributedNotification::PostNotification(inName, NULL,
true);
254 bool CACFPreferences::ArePrefsOutOfDate(
bool inCurrentUser,
bool inCurrentHost)
256 bool theAnswer =
false;
258 if(!inCurrentUser && !inCurrentHost)
260 theAnswer = sAnyUserAnyHostPrefsOutOfDate;
262 else if(!inCurrentUser && inCurrentHost)
264 theAnswer = sAnyUserCurrentHostPrefsOutOfDate;
266 else if(inCurrentUser && !inCurrentHost)
268 theAnswer = sCurrentUserAnyHostPrefsOutOfDate;
270 else if(inCurrentUser && inCurrentHost)
272 theAnswer = sCurrentUserCurrentHostPrefsOutOfDate;
278 bool CACFPreferences::sAnyUserAnyHostPrefsOutOfDate =
false;
279 bool CACFPreferences::sAnyUserCurrentHostPrefsOutOfDate =
false;
280 bool CACFPreferences::sCurrentUserAnyHostPrefsOutOfDate =
false;
281 bool CACFPreferences::sCurrentUserCurrentHostPrefsOutOfDate =
false;