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>
This commit is contained in:
Dirk Hohndel 2015-06-16 20:28:42 -07:00
parent 7cf3ebc2f7
commit ff4b5478b5
6 changed files with 75 additions and 3 deletions

View file

@ -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");
}