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 /pref.h | |
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 'pref.h')
-rw-r--r-- | pref.h | 14 |
1 files changed, 4 insertions, 10 deletions
@@ -36,18 +36,12 @@ extern struct preferences prefs, default_prefs; #define PP_GRAPHS_ENABLED (prefs.pp_graphs.po2 || prefs.pp_graphs.pn2 || prefs.pp_graphs.phe) -typedef enum { - PREF_BOOL, - PREF_STRING -} pref_type_t; - -#define BOOL_TO_PTR(_cond) ((_cond) ? (void *)1 : NULL) -#define PTR_TO_BOOL(_ptr) ((_ptr) != NULL) - extern void subsurface_open_conf(void); -extern void subsurface_set_conf(char *name, pref_type_t type, const void *value); +extern void subsurface_set_conf(char *name, const char *value); +extern void subsurface_set_conf_bool(char *name, gboolean value); extern void subsurface_unset_conf(char *name); -extern const void *subsurface_get_conf(char *name, pref_type_t type); +extern const void *subsurface_get_conf(char *name); +extern int subsurface_get_conf_bool(char *name); extern void subsurface_flush_conf(void); extern void subsurface_close_conf(void); |