diff options
author | Dirk Hohndel <dirk@hohndel.org> | 2015-06-16 20:28:42 -0700 |
---|---|---|
committer | Dirk Hohndel <dirk@hohndel.org> | 2015-06-17 09:48:10 -0700 |
commit | ff4b5478b520856d0b9d2b423627050a1672418d (patch) | |
tree | ad37deb6f680863d172e91f2cf8dcd86779fb492 | |
parent | 7cf3ebc2f7b65f6cb422b063e614cda6bfb472ac (diff) | |
download | subsurface-ff4b5478b520856d0b9d2b423627050a1672418d.tar.gz |
Store the user's unit preferences in git storage
Save and load a usually unused copy of the preferences with the units that
were active the last time the dive list was saved to git storage (this
isn't used in XML files); storing the unit preferences in the data file is
usually pointless (that's a setting of the software, not a property of the
data), but it's a great hint of what the user might expect to see when
creating a backend service that visualizes the dive list without
Subsurface running - so this is basically a functionality for the core
library that Subsurface itself doesn't use but that another consumer of
the library (like an HTML exporter) will need.
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
-rw-r--r-- | dive.c | 47 | ||||
-rw-r--r-- | dive.h | 1 | ||||
-rw-r--r-- | load-git.c | 8 | ||||
-rw-r--r-- | pref.h | 2 | ||||
-rw-r--r-- | save-git.c | 18 | ||||
-rw-r--r-- | subsurfacestartup.c | 2 |
6 files changed, 75 insertions, 3 deletions
@@ -2860,6 +2860,53 @@ void set_userid(char *rUserId) prefs.userid[30]='\0'; } +/* this sets a usually unused copy of the preferences with the units + * that were active the last time the dive list was saved to git storage + * (this isn't used in XML files); storing the unit preferences in the + * data file is usually pointless (that's a setting of the software, + * not a property of the data), but it's a great hint of what the user + * might expect to see when creating a backend service that visualizes + * the dive list without Subsurface running - so this is basically a + * functionality for the core library that Subsurface itself doesn't + * use but that another consumer of the library (like an HTML exporter) + * will need */ +void set_informational_units(char *units) +{ + if (strstr(units, "METRIC")) { + informational_prefs.unit_system = METRIC; + } else if (strstr(units, "IMPERIAL")) { + informational_prefs.unit_system = IMPERIAL; + } else if (strstr(units, "PERSONALIZE")) { + informational_prefs.unit_system = PERSONALIZE; + if (strstr(units, "METERS")) + informational_prefs.units.length = METERS; + if (strstr(units, "FEET")) + informational_prefs.units.length = FEET; + if (strstr(units, "LITER")) + informational_prefs.units.volume = LITER; + if (strstr(units, "CUFT")) + informational_prefs.units.volume = CUFT; + if (strstr(units, "BAR")) + informational_prefs.units.pressure = BAR; + if (strstr(units, "PSI")) + informational_prefs.units.pressure = PSI; + if (strstr(units, "PASCAL")) + informational_prefs.units.pressure = PASCAL; + if (strstr(units, "CELSIUS")) + informational_prefs.units.temperature = CELSIUS; + if (strstr(units, "FAHRENHEIT")) + informational_prefs.units.temperature = FAHRENHEIT; + if (strstr(units, "KG")) + informational_prefs.units.weight = KG; + if (strstr(units, "LBS")) + informational_prefs.units.weight = LBS; + if (strstr(units, "SECONDS")) + informational_prefs.units.vertical_speed_time = SECONDS; + if (strstr(units, "MINUTES")) + informational_prefs.units.vertical_speed_time = MINUTES; + } +} + void average_max_depth(struct diveplan *dive, int *avg_depth, int *max_depth) { int integral = 0; @@ -858,6 +858,7 @@ extern double strtod_flags(const char *str, const char **ptr, unsigned int flags extern void set_save_userid_local(short value); extern void set_userid(char *user_id); +extern void set_informational_units(char *units); extern const char *get_dive_date_c_string(timestamp_t when); extern void update_setpoint_events(struct divecomputer *dc); diff --git a/load-git.c b/load-git.c index 59bb8adc6..08eef085d 100644 --- a/load-git.c +++ b/load-git.c @@ -727,6 +727,12 @@ static void parse_trip_notes(char *line, struct membuffer *str, void *_trip) static void parse_settings_autogroup(char *line, struct membuffer *str, void *_unused) { set_autogroup(1); } +static void parse_settings_units(char *line, struct membuffer *str, void *unused) +{ + if (line) + set_informational_units(line); +} + static void parse_settings_userid(char *line, struct membuffer *str, void *_unused) { if (line) { @@ -895,7 +901,7 @@ static void trip_parser(char *line, struct membuffer *str, void *_trip) static struct keyword_action settings_action[] = { #undef D #define D(x) { #x, parse_settings_ ## x } - D(autogroup), D(divecomputerid), D(subsurface), D(userid), D(version), + D(autogroup), D(divecomputerid), D(subsurface), D(units), D(userid), D(version), }; static void settings_parser(char *line, struct membuffer *str, void *_unused) @@ -120,7 +120,7 @@ enum cloud_status { CS_VERIFIED }; -extern struct preferences prefs, default_prefs; +extern struct preferences prefs, default_prefs, informational_prefs; #define PP_GRAPHS_ENABLED (prefs.pp_graphs.po2 || prefs.pp_graphs.pn2 || prefs.pp_graphs.phe) diff --git a/save-git.c b/save-git.c index f76029f11..3f540eab9 100644 --- a/save-git.c +++ b/save-git.c @@ -786,6 +786,23 @@ static int save_one_trip(git_repository *repo, struct dir *tree, dive_trip_t *tr return 0; } +static void save_units(void *_b) +{ + struct membuffer *b =_b; + if (prefs.unit_system == METRIC) + put_string(b, "units METRIC\n"); + else if (prefs.unit_system == IMPERIAL) + put_string(b, "units IMPERIAL\n"); + else + put_format(b, "units PERSONALIZE %s %s %s %s %s %s", + prefs.units.length == METERS ? "METERS" : "FEET", + prefs.units.volume == LITER ? "LITER" : "CUFT", + prefs.units.pressure == BAR ? "BAR" : prefs.units.pressure == PSI ? "PSI" : "PASCAL", + prefs.units.temperature == CELSIUS ? "CELSIUS" : prefs.units.temperature == FAHRENHEIT ? "FAHRENHEIT" : "KELVIN", + prefs.units.weight == KG ? "KG" : "LBS", + prefs.units.vertical_speed_time == SECONDS ? "SECONDS" : "MINUTES"); +} + static void save_userid(void *_b) { struct membuffer *b = _b; @@ -824,6 +841,7 @@ static void save_settings(git_repository *repo, struct dir *tree) save_userid(&b); call_for_each_dc(&b, save_one_device, false); cond_put_format(autogroup, &b, "autogroup\n"); + save_units(&b); blob_insert(repo, tree, &b, "00-Subsurface"); } diff --git a/subsurfacestartup.c b/subsurfacestartup.c index ab4af7035..a64c8175d 100644 --- a/subsurfacestartup.c +++ b/subsurfacestartup.c @@ -3,7 +3,7 @@ #include <stdbool.h> #include <string.h> #include "gettext.h" -struct preferences prefs; +struct preferences prefs, informational_prefs; struct preferences default_prefs = { .cloud_base_url = "https://cloud.subsurface-divelog.org/", .units = SI_UNITS, |