From ff4b5478b520856d0b9d2b423627050a1672418d Mon Sep 17 00:00:00 2001 From: Dirk Hohndel Date: Tue, 16 Jun 2015 20:28:42 -0700 Subject: 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 --- save-git.c | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) (limited to 'save-git.c') 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"); } -- cgit v1.2.3-70-g09d2