summaryrefslogtreecommitdiffstats
path: root/save-git.c
diff options
context:
space:
mode:
authorGravatar Dirk Hohndel <dirk@hohndel.org>2015-06-16 20:28:42 -0700
committerGravatar Dirk Hohndel <dirk@hohndel.org>2015-06-17 09:48:10 -0700
commitff4b5478b520856d0b9d2b423627050a1672418d (patch)
treead37deb6f680863d172e91f2cf8dcd86779fb492 /save-git.c
parent7cf3ebc2f7b65f6cb422b063e614cda6bfb472ac (diff)
downloadsubsurface-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>
Diffstat (limited to 'save-git.c')
-rw-r--r--save-git.c18
1 files changed, 18 insertions, 0 deletions
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");
}