mirror of
https://github.com/subsurface/subsurface.git
synced 2025-02-19 22:16:15 +00:00
Keep conflicting information around when converting v2 to v3 on the fly
When reading a v2 XML or git divelog it can happen that we get multiple names for the same GPS fix or multiple GPS fixes for the same name. We'll still consolidate them to one entry, but we should not throw away the conflicting information - instead we should just add this to the notes. Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
This commit is contained in:
parent
06bbf9f4c8
commit
57d5a40e95
2 changed files with 26 additions and 9 deletions
18
load-git.c
18
load-git.c
|
@ -10,6 +10,8 @@
|
||||||
#include <fcntl.h>
|
#include <fcntl.h>
|
||||||
#include <git2.h>
|
#include <git2.h>
|
||||||
|
|
||||||
|
#include "gettext.h"
|
||||||
|
|
||||||
#include "dive.h"
|
#include "dive.h"
|
||||||
#include "device.h"
|
#include "device.h"
|
||||||
#include "membuffer.h"
|
#include "membuffer.h"
|
||||||
|
@ -138,6 +140,9 @@ static int get_index(const char *line)
|
||||||
static int get_hex(const char *line)
|
static int get_hex(const char *line)
|
||||||
{ return strtoul(line, NULL, 16); }
|
{ return strtoul(line, NULL, 16); }
|
||||||
|
|
||||||
|
/* this is in qthelper.cpp, so including the .h file is a pain */
|
||||||
|
extern const char *printGPSCoords(int lat, int lon);
|
||||||
|
|
||||||
static void parse_dive_gps(char *line, struct membuffer *str, void *_dive)
|
static void parse_dive_gps(char *line, struct membuffer *str, void *_dive)
|
||||||
{
|
{
|
||||||
uint32_t uuid;
|
uint32_t uuid;
|
||||||
|
@ -151,6 +156,12 @@ static void parse_dive_gps(char *line, struct membuffer *str, void *_dive)
|
||||||
uuid = create_dive_site_with_gps("", latitude, longitude);
|
uuid = create_dive_site_with_gps("", latitude, longitude);
|
||||||
dive->dive_site_uuid = uuid;
|
dive->dive_site_uuid = uuid;
|
||||||
} else {
|
} else {
|
||||||
|
if (dive_site_has_gps_location(ds) &&
|
||||||
|
(ds->latitude.udeg != latitude.udeg || ds->longitude.udeg != longitude.udeg)) {
|
||||||
|
// we have a dive site that already has GPS coordinates
|
||||||
|
ds->notes = add_to_string(ds->notes, translate("gettextFromC", "multiple gps locations for this dive site; also %s\n"),
|
||||||
|
printGPSCoords(latitude.udeg, longitude.udeg));
|
||||||
|
}
|
||||||
ds->latitude = latitude;
|
ds->latitude = latitude;
|
||||||
ds->longitude = longitude;
|
ds->longitude = longitude;
|
||||||
}
|
}
|
||||||
|
@ -171,8 +182,15 @@ static void parse_dive_location(char *line, struct membuffer *str, void *_dive)
|
||||||
} else { fprintf(stderr, "found one with uuid %8x\n", uuid); }
|
} else { fprintf(stderr, "found one with uuid %8x\n", uuid); }
|
||||||
dive->dive_site_uuid = uuid;
|
dive->dive_site_uuid = uuid;
|
||||||
} else {
|
} else {
|
||||||
|
// we already had a dive site linked to the dive
|
||||||
fprintf(stderr, "dive had site with uuid %8x and name {%s}\n", ds->uuid, ds->name);
|
fprintf(stderr, "dive had site with uuid %8x and name {%s}\n", ds->uuid, ds->name);
|
||||||
|
if (same_string(ds->name, "")) {
|
||||||
ds->name = name;
|
ds->name = name;
|
||||||
|
} else {
|
||||||
|
// and that dive site had a name. that's weird - if our name is different, add it to the notes
|
||||||
|
if (!same_string(ds->name, name))
|
||||||
|
ds->notes = add_to_string(ds->notes, translate("gettextFromC", "additional name for site: %s\n"), name);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
15
parse-xml.c
15
parse-xml.c
|
@ -1160,6 +1160,9 @@ static void gps_location(char *buffer, struct dive_site *ds)
|
||||||
ds->longitude = parse_degrees(end, &end);
|
ds->longitude = parse_degrees(end, &end);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* this is in qthelper.cpp, so including the .h file is a pain */
|
||||||
|
extern const char *printGPSCoords(int lat, int lon);
|
||||||
|
|
||||||
static void gps_in_dive(char *buffer, struct dive *dive)
|
static void gps_in_dive(char *buffer, struct dive *dive)
|
||||||
{
|
{
|
||||||
char *end;
|
char *end;
|
||||||
|
@ -1187,13 +1190,8 @@ static void gps_in_dive(char *buffer, struct dive *dive)
|
||||||
fprintf(stderr, "dive site uuid in dive, but gps location (%10.6f/%10.6f) different from dive location (%10.6f/%10.6f)\n",
|
fprintf(stderr, "dive site uuid in dive, but gps location (%10.6f/%10.6f) different from dive location (%10.6f/%10.6f)\n",
|
||||||
ds->latitude.udeg / 1000000.0, ds->longitude.udeg / 1000000.0,
|
ds->latitude.udeg / 1000000.0, ds->longitude.udeg / 1000000.0,
|
||||||
latitude.udeg / 1000000.0, longitude.udeg / 1000000.0);
|
latitude.udeg / 1000000.0, longitude.udeg / 1000000.0);
|
||||||
int len = ds->notes ? strlen(ds->notes) : 0;
|
ds->notes = add_to_string(ds->notes, translate("gettextFromC", "multiple gps locations for this dive site; also %s\n"),
|
||||||
len += sizeof("\nalternative coordinates") + 24;
|
printGPSCoords(latitude.udeg, longitude.udeg));
|
||||||
char *notes = malloc(len);
|
|
||||||
snprintf(notes, len, "%s\nalternative coordinates %11.6f/%11.6f",
|
|
||||||
ds->notes ?: "", latitude.udeg / 1000000.0, longitude.udeg / 1000000.0);
|
|
||||||
free(ds->notes);
|
|
||||||
ds->notes = notes;
|
|
||||||
} else {
|
} else {
|
||||||
fprintf(stderr, "let's add the gps coordinates to divesite with uuid %8x and name %s\n", ds->uuid, ds->name ?: "(none)");
|
fprintf(stderr, "let's add the gps coordinates to divesite with uuid %8x and name %s\n", ds->uuid, ds->name ?: "(none)");
|
||||||
ds->latitude = latitude;
|
ds->latitude = latitude;
|
||||||
|
@ -1224,8 +1222,9 @@ static void add_dive_site(char *buffer, struct dive *dive)
|
||||||
fprintf(stderr, "so now add name {%s}\n", buffer);
|
fprintf(stderr, "so now add name {%s}\n", buffer);
|
||||||
ds->name = copy_string(buffer);
|
ds->name = copy_string(buffer);
|
||||||
} else if (!same_string(ds->name, buffer)) {
|
} else if (!same_string(ds->name, buffer)) {
|
||||||
// coin toss, let's just keep the first name we found
|
// coin toss, let's just keep the first name we found and add the new one to the notes
|
||||||
fprintf(stderr, "which means the dive already links to dive site of different name {%s} / {%s}\n", ds->name, buffer);
|
fprintf(stderr, "which means the dive already links to dive site of different name {%s} / {%s}\n", ds->name, buffer);
|
||||||
|
ds->notes = add_to_string(ds->notes, translate("gettextFromC", "additional name for site: %s\n"), buffer);
|
||||||
} else {
|
} else {
|
||||||
// add the existing dive site to the current dive
|
// add the existing dive site to the current dive
|
||||||
fprintf(stderr, "we have an existing location, using {%s}\n", ds->name);
|
fprintf(stderr, "we have an existing location, using {%s}\n", ds->name);
|
||||||
|
|
Loading…
Add table
Reference in a new issue