diff options
author | Linus Torvalds <torvalds@linux-foundation.org> | 2013-01-10 19:33:53 -0800 |
---|---|---|
committer | Dirk Hohndel <dirk@hohndel.org> | 2013-01-10 20:30:54 -0800 |
commit | 8dea49ffe29c602efc52fbaaf89fd3456c19add7 (patch) | |
tree | a2c5a45d043da40ae969e895c0c26c2eaed6eddd /macos.c | |
parent | 21f38190d3bf3f59ea70fe71bc109f438b49ab4c (diff) | |
download | subsurface-8dea49ffe29c602efc52fbaaf89fd3456c19add7.tar.gz |
Clean up preference saving code
The old code (on purpose) didn't try to differentiate "nonexisting
boolean configuration" with "existing boolean configuration set to
false", which is problematic if we optimize the saving to not save
default preferences at all.
Which this does.
So in addition to the logic to know about default preferences, this has
to change the interfaces for the PREF_BOOL reading code so that you can
tell the difference between "no value" and "false".
And since the previous calling convention was an abomination of doing
pointer casting and having case-statements for the config types, change
that while at it. Both from a usage perspective *and* from a back-end
perspective it is actually much simpler to just have different functions
for the string vs boolean config read/write versions. The OSX versions
in particular end up being one-liners.
(The GConf library is a nightmare, and doesn't seem to have any way to
know whether a boolean value exists or not, so you have to read it as a
GConfVal and then turn it into a gboolean rather than just get the "oh,
it didn't exist" as an error value).
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
Diffstat (limited to 'macos.c')
-rw-r--r-- | macos.c | 52 |
1 files changed, 25 insertions, 27 deletions
@@ -31,38 +31,36 @@ void subsurface_unset_conf(char *name) CFPreferencesSetAppValue(CFSTR_VAR(name), NULL, SUBSURFACE_PREFERENCES); } -void subsurface_set_conf(char *name, pref_type_t type, const void *value) -{ - switch (type) { - case PREF_BOOL: - CFPreferencesSetAppValue(CFSTR_VAR(name), - value == NULL ? kCFBooleanFalse : kCFBooleanTrue, SUBSURFACE_PREFERENCES); - break; - case PREF_STRING: - CFPreferencesSetAppValue(CFSTR_VAR(name), CFSTR_VAR(value), SUBSURFACE_PREFERENCES); - } +void subsurface_set_conf(char *name, const void *value) +{ + CFPreferencesSetAppValue(CFSTR_VAR(name), CFSTR_VAR(value), SUBSURFACE_PREFERENCES); +} + +void subsurface_set_conf(char *name, int value) +{ + CFPreferencesSetAppValue(CFSTR_VAR(name), + value ? kCFBooleanTrue : kCFBooleanFalse, SUBSURFACE_PREFERENCES); } -const void *subsurface_get_conf(char *name, pref_type_t type) +const void *subsurface_get_conf(char *name) { - Boolean boolpref; CFPropertyListRef strpref; - switch (type) { - case PREF_BOOL: - boolpref = CFPreferencesGetAppBooleanValue(CFSTR_VAR(name), SUBSURFACE_PREFERENCES, FALSE); - if (boolpref) - return (void *) 1; - else - return NULL; - case PREF_STRING: - strpref = CFPreferencesCopyAppValue(CFSTR_VAR(name), SUBSURFACE_PREFERENCES); - if (!strpref) - return NULL; - return strdup(CFStringGetCStringPtr(strpref, kCFStringEncodingMacRoman)); - } - /* we shouldn't get here, but having this line makes the compiler happy */ - return NULL; + strpref = CFPreferencesCopyAppValue(CFSTR_VAR(name), SUBSURFACE_PREFERENCES); + if (!strpref) + return NULL; + return strdup(CFStringGetCStringPtr(strpref, kCFStringEncodingMacRoman)); +} + +int subsurface_get_conf_bool(char *name) +{ + Boolean boolpref, exists; + CFPropertyListRef strpref; + + boolpref = CFPreferencesGetAppBooleanValue(CFSTR_VAR(name), SUBSURFACE_PREFERENCES, &exists); + if (!exists) + return -1; + return boolpref; } void subsurface_flush_conf(void) |