summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGravatar Dirk Hohndel <dirk@hohndel.org>2012-11-21 15:34:04 -0800
committerGravatar Dirk Hohndel <dirk@hohndel.org>2012-11-21 15:34:04 -0800
commit10ce60e2120419282ff7694e8deda60e94832aa1 (patch)
tree6ea6a96da0b4209879e20b429672ae73b79a8ebb
parentd872a5c8aab858fa7a06b6f91f2dda57a43a6306 (diff)
downloadsubsurface-10ce60e2120419282ff7694e8deda60e94832aa1.tar.gz
Fix "prefer download" behavior
When this was first implemented the assumption was that a downloaded dive that is to be merged with an existing dive would have the same time stamp. But as Linus pointed out even back then, this does fail if a dive has been merged with a download from a different dive computer before (think: download from computer a, then download same dive from b, then improve something in the parsing from computer a and try to redownload; the time stamp could have changed). This commit also fixes a silly omission in the merge_dives() function (which ended up ALWAYS prefering the downloaded dive) and finally implements the necessary changes to mark dives downloaded from a Uemis SDA as well. Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
-rw-r--r--dive.c12
-rw-r--r--dive.h2
-rw-r--r--file.c4
-rw-r--r--gtk-gui.c2
-rw-r--r--parse-xml.c5
5 files changed, 14 insertions, 11 deletions
diff --git a/dive.c b/dive.c
index ae9ecde00..c76b71056 100644
--- a/dive.c
+++ b/dive.c
@@ -1077,8 +1077,6 @@ struct dive *try_to_merge(struct dive *a, struct dive *b, gboolean prefer_downlo
*/
if ((a->when >= b->when + 60) || (a->when <= b->when - 60))
return NULL;
- if (prefer_downloaded && a->when != b->when)
- return NULL;
if (!prefer_downloaded) {
/* Dive 'a' is 'offset' seconds before dive 'b' */
offset = find_sample_offset(a, b);
@@ -1093,10 +1091,12 @@ struct dive *merge_dives(struct dive *a, struct dive *b, int offset, gboolean pr
struct dive *res = alloc_dive();
struct dive *dl = NULL;
- if (a->downloaded)
- dl = a;
- else if (b->downloaded)
- dl = b;
+ if (prefer_downloaded) {
+ if (a->downloaded)
+ dl = a;
+ else if (b->downloaded)
+ dl = b;
+ }
res->when = a->when;
res->selected = a->selected || b->selected;
merge_trip(res, a, b);
diff --git a/dive.h b/dive.h
index 7131b3eaf..d4e2d3eaf 100644
--- a/dive.h
+++ b/dive.h
@@ -392,7 +392,7 @@ static inline struct dive *get_dive(int nr)
for ((_i) = 0; ((_x) = get_dive(_i)) != NULL; (_i)++)
extern void parse_xml_init(void);
-extern void parse_xml_buffer(const char *url, const char *buf, int size, GError **error);
+extern void parse_xml_buffer(const char *url, const char *buf, int size, gboolean downloaded, GError **error);
extern void parse_xml_exit(void);
extern void set_filename(const char *filename, gboolean force);
diff --git a/file.c b/file.c
index db72b5f66..31f5d882c 100644
--- a/file.c
+++ b/file.c
@@ -72,7 +72,7 @@ static void suunto_read(struct zip_file *file, GError **error)
size = read * 3 / 2;
mem = realloc(mem, size);
}
- parse_xml_buffer(_("SDE file"), mem, read, error);
+ parse_xml_buffer(_("SDE file"), mem, read, FALSE, error);
free(mem);
}
#endif
@@ -246,7 +246,7 @@ static void parse_file_buffer(const char *filename, struct memblock *mem, GError
if (fmt && open_by_filename(filename, fmt+1, mem, error))
return;
- parse_xml_buffer(filename, mem->buffer, mem->size, error);
+ parse_xml_buffer(filename, mem->buffer, mem->size, FALSE, error);
}
void parse_file(const char *filename, GError **error, gboolean possible_default_filename)
diff --git a/gtk-gui.c b/gtk-gui.c
index 292a3c77d..dca239bf2 100644
--- a/gtk-gui.c
+++ b/gtk-gui.c
@@ -1685,7 +1685,7 @@ static GError *setup_uemis_import(device_data_t *data)
#if UEMIS_DEBUG > 3
fprintf(debugfile, "xml buffer \"%s\"\n\n", buf);
#endif
- parse_xml_buffer("Uemis Download", buf, strlen(buf), &error);
+ parse_xml_buffer("Uemis Download", buf, strlen(buf), TRUE, &error);
set_uemis_last_dive(uemis_max_dive_data);
#if UEMIS_DEBUG > 2
fprintf(debugfile, "uemis_max_dive_data: %s\n", uemis_max_dive_data);
diff --git a/parse-xml.c b/parse-xml.c
index 15138f43e..04d39643b 100644
--- a/parse-xml.c
+++ b/parse-xml.c
@@ -168,6 +168,7 @@ static struct {
} cur_event;
static struct tm cur_tm;
static int cur_cylinder_index, cur_ws_index;
+static gboolean from_download;
static enum import_source {
UNKNOWN,
@@ -1219,6 +1220,7 @@ static void dive_start(void)
add_dive_to_trip(cur_dive, cur_trip);
cur_dive->tripflag = IN_TRIP;
}
+ cur_dive->downloaded = from_download;
}
static void dive_end(void)
@@ -1499,9 +1501,10 @@ static void reset_all(void)
import_source = UNKNOWN;
}
-void parse_xml_buffer(const char *url, const char *buffer, int size, GError **error)
+void parse_xml_buffer(const char *url, const char *buffer, int size, gboolean downloaded, GError **error)
{
xmlDoc *doc;
+ from_download = downloaded;
doc = xmlReadMemory(buffer, size, url, NULL, 0);
if (!doc) {