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 /linux.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 'linux.c')
-rw-r--r-- | linux.c | 41 |
1 files changed, 23 insertions, 18 deletions
@@ -28,27 +28,32 @@ void subsurface_unset_conf(char *name) gconf_client_unset(gconf, gconf_name(name), NULL); } -void subsurface_set_conf(char *name, pref_type_t type, const void *value) -{ - switch (type) { - case PREF_BOOL: - gconf_client_set_bool(gconf, gconf_name(name), value != NULL, NULL); - break; - case PREF_STRING: - gconf_client_set_string(gconf, gconf_name(name), value, NULL); - } +void subsurface_set_conf(char *name, const char *value) +{ + gconf_client_set_string(gconf, gconf_name(name), value, NULL); } -const void *subsurface_get_conf(char *name, pref_type_t type) +void subsurface_set_conf_bool(char *name, int value) { - switch (type) { - case PREF_BOOL: - return gconf_client_get_bool(gconf, gconf_name(name), NULL) ? (void *) 1 : NULL; - case PREF_STRING: - return gconf_client_get_string(gconf, gconf_name(name), NULL); - } - /* we shouldn't get here */ - return NULL; + gconf_client_set_bool(gconf, gconf_name(name), value > 0, NULL); +} + +const void *subsurface_get_conf(char *name) +{ + return gconf_client_get_string(gconf, gconf_name(name), NULL); +} + +int subsurface_get_conf_bool(char *name) +{ + GConfValue *val; + gboolean ret; + + val = gconf_client_get(gconf, gconf_name(name), NULL); + if (!val) + return -1; + ret = gconf_value_get_bool(val); + gconf_value_free(val); + return ret; } void subsurface_flush_conf(void) |