mirror of
https://github.com/subsurface/subsurface.git
synced 2025-01-31 20:33:24 +00:00
Make the default preferences explicit
This makes it explicit what the default preferences are, so that we can more easily avoid unnecessarily saving default settings. It also makes imperial metrics the default for the US (Burma and Liberia always get forgotten!) Right now we tend to be somewhat confused about defaults. We do have them, but then even if something has a default value, we tend to write it out to the config file. Which is not just unnecessary, but makes it really hard to see after-the-fact whether the user actually wanted that *specific* value, or whether they just wanted the default behavior. So this prepares for having explicit configuration for when we want something different than the defaults. Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org> Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
This commit is contained in:
parent
868a2cc090
commit
21f38190d3
2 changed files with 51 additions and 9 deletions
|
@ -35,13 +35,6 @@ const char *existing_filename;
|
|||
const char *divelist_font;
|
||||
const char *default_filename;
|
||||
|
||||
struct preferences prefs = {
|
||||
SI_UNITS,
|
||||
{ TRUE, FALSE, },
|
||||
{ FALSE, FALSE, FALSE, 1.6, 4.0, 13.0},
|
||||
FALSE, FALSE, FALSE, 0.30, 0.75
|
||||
};
|
||||
|
||||
char *nicknamestring;
|
||||
|
||||
static GtkWidget *dive_profile;
|
||||
|
|
53
main.c
53
main.c
|
@ -15,7 +15,24 @@ char *debugfilename;
|
|||
FILE *debugfile;
|
||||
#endif
|
||||
|
||||
struct units units;
|
||||
struct preferences prefs;
|
||||
struct preferences default_prefs = {
|
||||
.units = SI_UNITS,
|
||||
.visible_cols = { TRUE, FALSE, },
|
||||
.pp_graphs = {
|
||||
.po2 = FALSE,
|
||||
.pn2 = FALSE,
|
||||
.phe = FALSE,
|
||||
.po2_threshold = 1.6,
|
||||
.pn2_threshold = 4.0,
|
||||
.phe_threshold = 13.0,
|
||||
},
|
||||
.profile_red_ceiling = FALSE,
|
||||
.profile_calc_ceiling = FALSE,
|
||||
.calc_ceiling_3m_incr = FALSE,
|
||||
.gflow = 0.30,
|
||||
.gfhigh = 0.75,
|
||||
};
|
||||
|
||||
/* random helper functions, used here or elsewhere */
|
||||
static int sortfn(const void *_a, const void *_b)
|
||||
|
@ -239,6 +256,36 @@ void renumber_dives(int nr)
|
|||
mark_divelist_changed(TRUE);
|
||||
}
|
||||
|
||||
/*
|
||||
* Under a POSIX setup, the locale string should have a format
|
||||
* like [language[_territory][.codeset][@modifier]].
|
||||
*
|
||||
* So search for the underscore, and see if the "territory" is
|
||||
* US, and turn on imperial units by default.
|
||||
*
|
||||
* I guess Burma and Liberia should trigger this too. I'm too
|
||||
* lazy to look up the territory names, though.
|
||||
*/
|
||||
static void setup_system_prefs(void)
|
||||
{
|
||||
const char *env = getenv("LC_MEASUREMENT");
|
||||
|
||||
if (!env)
|
||||
env = getenv("LC_ALL");
|
||||
if (!env)
|
||||
env = getenv("LANG");
|
||||
if (!env)
|
||||
return;
|
||||
env = strchr(env, '_');
|
||||
if (!env)
|
||||
return;
|
||||
env++;
|
||||
if (strncmp(env, "US", 2))
|
||||
return;
|
||||
|
||||
default_prefs.units = IMPERIAL_units;
|
||||
}
|
||||
|
||||
int main(int argc, char **argv)
|
||||
{
|
||||
int i;
|
||||
|
@ -253,7 +300,9 @@ int main(int argc, char **argv)
|
|||
bindtextdomain("subsurface", path);
|
||||
bind_textdomain_codeset("subsurface", "utf-8");
|
||||
textdomain("subsurface");
|
||||
units = SI_units;
|
||||
|
||||
setup_system_prefs();
|
||||
prefs = default_prefs;
|
||||
|
||||
#if DEBUGFILE > 1
|
||||
debugfile = stderr;
|
||||
|
|
Loading…
Add table
Reference in a new issue