Add default filename and divelist font to prefs structure

.. and add the usual logic to not save the default values.

This also simplifies the initial system-specific setup of both of these:
since we have defaults for all the preferences that get set up at
startup, we can just initialize those defaults to the system-specific
fonts then and there.

Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
This commit is contained in:
Linus Torvalds 2013-01-11 17:07:22 -08:00 committed by Dirk Hohndel
parent 954290c70b
commit 6a10700ca5
11 changed files with 84 additions and 89 deletions

26
prefs.c
View file

@ -1,3 +1,5 @@
#include <string.h>
#include "dive.h"
static void set_bool_conf(char *name, gboolean value, gboolean def)
@ -13,6 +15,16 @@ static void set_bool_conf(char *name, gboolean value, gboolean def)
#define SAVE_UNIT(name, field, value) __SAVE_BOOLEAN(name, units.field, value)
#define SAVE_BOOL(name, field) __SAVE_BOOLEAN(name, field, TRUE)
static void set_string_conf(char *name, const char *value, const char *def)
{
if (!strcmp(value, def)) {
subsurface_unset_conf(name);
return;
}
subsurface_set_conf(name, value);
}
#define SAVE_STRING(name, field) set_string_conf(name, prefs.field, default_prefs.field)
/* We don't really save doubles */
static void save_double_conf(char *name, double _val, double _def)
{
@ -63,7 +75,7 @@ void save_preferences(void)
SAVE_BOOL("OTU", visible_cols.otu);
SAVE_BOOL("MAXCNS", visible_cols.maxcns);
subsurface_set_conf("divelist_font", divelist_font);
SAVE_STRING("divelist_font", divelist_font);
SAVE_BOOL("po2graph", pp_graphs.po2);
SAVE_BOOL("pn2graph", pp_graphs.pn2);
@ -80,7 +92,7 @@ void save_preferences(void)
SAVE_PERCENT("gflow", gflow);
SAVE_PERCENT("gfhigh", gfhigh);
subsurface_set_conf("default_filename", default_filename);
SAVE_STRING("default_filename", default_filename);
/* Flush the changes out to the system */
subsurface_flush_conf();
@ -153,7 +165,13 @@ void load_preferences(void)
free((void *)conf_value);
}
set_gf(prefs.gflow, prefs.gfhigh);
divelist_font = subsurface_get_conf("divelist_font");
default_filename = subsurface_get_conf("default_filename");
conf_value = subsurface_get_conf("divelist_font");
if (conf_value)
prefs.divelist_font = conf_value;
conf_value = subsurface_get_conf("default_filename");
if (conf_value)
prefs.default_filename = conf_value;
}