aboutsummaryrefslogtreecommitdiffstats
path: root/save-xml.c
diff options
context:
space:
mode:
authorGravatar Dirk Hohndel <dirk@hohndel.org>2015-02-13 23:52:41 -0800
committerGravatar Dirk Hohndel <dirk@hohndel.org>2015-02-13 23:52:41 -0800
commit56de6b73f67d5ddeec74153303a27866e39279c7 (patch)
tree45040e1fb23c26e12b3002e9381f13717a9eb78d /save-xml.c
parent2843dc38c9e64e87ac1ee84e2cb0147f630ab117 (diff)
parentf81e2c111d9c563a78e62c3bae64bec07c052ec0 (diff)
downloadsubsurface-56de6b73f67d5ddeec74153303a27866e39279c7.tar.gz
Merge branch 'divesites'
This brings in the dive site infrastructure and initial UI work
Diffstat (limited to 'save-xml.c')
-rw-r--r--save-xml.c75
1 files changed, 40 insertions, 35 deletions
diff --git a/save-xml.c b/save-xml.c
index 053b8fc96..c09b90812 100644
--- a/save-xml.c
+++ b/save-xml.c
@@ -110,38 +110,8 @@ static void save_salinity(struct membuffer *b, struct divecomputer *dc)
put_string(b, " />\n");
}
-static void show_location(struct membuffer *b, struct dive *dive)
-{
- degrees_t latitude = dive->latitude;
- degrees_t longitude = dive->longitude;
-
- /* Should we write a location tag at all? */
- if (!(latitude.udeg || longitude.udeg) && !dive->location)
- return;
-
- put_string(b, " <location");
-
- /*
- * Ok, theoretically I guess you could dive at
- * exactly 0,0. But we don't support that. So
- * if you do, just fudge it a bit, and say that
- * you dove a few meters away.
- */
- if (latitude.udeg || longitude.udeg) {
- put_degrees(b, latitude, " gps='", " ");
- put_degrees(b, longitude, "", "'");
- }
-
- /* Do we have a location name or should we write a empty tag? */
- if (dive->location && dive->location[0] != '\0')
- show_utf8(b, dive->location, ">", "</location>\n", 0);
- else
- put_string(b, "/>\n");
-}
-
static void save_overview(struct membuffer *b, struct dive *dive)
{
- show_location(b, dive);
show_utf8(b, dive->divemaster, " <divemaster>", "</divemaster>\n", 0);
show_utf8(b, dive->buddy, " <buddy>", "</buddy>\n", 0);
show_utf8(b, dive->notes, " <notes>", "</notes>\n", 0);
@@ -424,7 +394,8 @@ void save_one_dive(struct membuffer *b, struct dive *dive)
if (dive->visibility)
put_format(b, " visibility='%d'", dive->visibility);
save_tags(b, dive->tag_list);
-
+ if (dive->dive_site_uuid)
+ put_format(b, " divesiteid='%8x'", dive->dive_site_uuid);
show_date(b, dive->when);
put_format(b, " duration='%u:%02u min'>\n",
FRACTION(dive->dc.duration.seconds, 60));
@@ -507,7 +478,7 @@ static void save_one_device(void *_f, const char *model, uint32_t deviceid,
put_format(b, "/>\n");
}
-#define VERSION 2
+#define VERSION 3
int save_dives(const char *filename)
{
@@ -529,8 +500,34 @@ void save_dives_buffer(struct membuffer *b, const bool select_only)
call_for_each_dc(b, save_one_device);
if (autogroup)
put_format(b, " <autogroup state='1' />\n");
- put_format(b, "</settings>\n<dives>\n");
-
+ put_format(b, "</settings>\n");
+
+ /* save the dive sites */
+ put_format(b, "<divesites>\n");
+ for (i = 0; i < dive_site_table.nr; i++) {
+ struct dive_site *ds = get_dive_site(i);
+ if (dive_site_is_empty(ds)) {
+ int j;
+ struct dive *d;
+ for_each_dive(j, d) {
+ if (d->dive_site_uuid == ds->uuid)
+ d->dive_site_uuid = 0;
+ }
+ delete_dive_site(get_dive_site(i)->uuid);
+ i--; // since we just deleted that one
+ continue;
+ }
+ put_format(b, "<site uuid='%8x' ", ds->uuid);
+ show_utf8(b, ds->name, " name='", "'", 1);
+ if (ds->latitude.udeg || ds->longitude.udeg) {
+ put_degrees(b, ds->latitude, " gps='", " ");
+ put_degrees(b, ds->longitude, "", "'");
+ }
+ show_utf8(b, ds->description, " description='", "'", 1);
+ show_utf8(b, ds->notes, " notes='", "'", 1);
+ put_format(b, "/>\n");
+ }
+ put_format(b, "</divesites>\n<dives>\n");
for (trip = dive_trip_list; trip != NULL; trip = trip->next)
trip->index = 0;
@@ -605,7 +602,15 @@ static void try_to_backup(const char *filename)
while (extension[i][0] != '\0') {
int elen = strlen(extension[i]);
if (strcasecmp(filename + flen - elen, extension[i]) == 0) {
- save_backup(filename, extension[i], "bak");
+ if (last_xml_version < VERSION) {
+ int se_len = strlen(extension[i]) + 5;
+ char *special_ext = malloc(se_len);
+ snprintf(special_ext, se_len, "%s.v%d", extension[i], last_xml_version);
+ save_backup(filename, extension[i], special_ext);
+ free(special_ext);
+ } else {
+ save_backup(filename, extension[i], "bak");
+ }
break;
}
i++;