From e4086dc74648c5f5ed7b72f1dc35e16e3bee8041 Mon Sep 17 00:00:00 2001 From: Salvador Cuñat Date: Sun, 2 Apr 2017 23:42:36 +0200 Subject: smtk-import Avoid duplicities in bookmarks MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit SmartTrak's bookmarks work in the same fashion Subsurface's do. The user may set a bookmark while underwater or set it just on the divelog software. At this time we are parsing those set in the DC twice, as we get one from libdivecomputer and another from smarttrak's database. This patch just checks if we have a bookmark event downloaded by libdivecomputer which has the same time that the one parsed from the .slg file. If so, merge the names taking the one from smarttrak. Text from smarttrak is preferred because the user may have entered some interesting note there and libdivecomputer's name is just "bookmark". Signed-off-by: Salvador Cuñat --- smtk-import/smartrak.c | 28 +++++++++++++++++++++++++--- 1 file changed, 25 insertions(+), 3 deletions(-) (limited to 'smtk-import') diff --git a/smtk-import/smartrak.c b/smtk-import/smartrak.c index 36eabed0b..6b8a1f60c 100644 --- a/smtk-import/smartrak.c +++ b/smtk-import/smartrak.c @@ -644,6 +644,22 @@ static void smtk_parse_relations(MdbHandle *mdb, struct dive *dive, char *dive_i mdb_free_tabledef(table); } +/* + * Returns a pointer to a bookmark event in an event list if it exists for + * a given time. Return NULL otherwise. + */ +static struct event *find_bookmark(struct event *orig, unsigned int t) +{ + struct event *ev = orig; + + while (ev) { + if ((ev->time.seconds == t) && (ev->type == SAMPLE_EVENT_BOOKMARK)) + return ev; + ev = ev->next; + } + return NULL; +} + /* * Marker table is a mix between Type tables and Relations tables. Its format is * | Dive Idx | Idx | Text | Type | XPos | YPos | XConnect | YConnect @@ -659,6 +675,7 @@ static void smtk_parse_bookmarks(MdbHandle *mdb, struct dive *d, char *dive_idx) MdbColumn *col[MDB_MAX_COLS]; char *bound_values[MDB_MAX_COLS], *tmp = NULL; unsigned int time; + struct event *ev; table = smtk_open_table(mdb, "Marker", col, bound_values); if (!table) @@ -667,9 +684,14 @@ static void smtk_parse_bookmarks(MdbHandle *mdb, struct dive *d, char *dive_idx) if (same_string(col[0]->bind_ptr, dive_idx)) { time = lrint(strtod(col[4]->bind_ptr, NULL) * 60); tmp = strdup(col[2]->bind_ptr); - if (!add_event(&d->dc, time, SAMPLE_EVENT_BOOKMARK, 0, 0, tmp)) - report_error("[smtk-import] Error - Couldn't add bookmark, dive %d, Name = %s", - d->number, tmp); + ev = find_bookmark(d->dc.events, time); + if (ev != NULL) { + memset(&ev->name, 0, strlen(tmp) + 1); + memcpy(ev->name, tmp, strlen(tmp)); + } else + if (!add_event(&d->dc, time, SAMPLE_EVENT_BOOKMARK, 0, 0, tmp)) + report_error("[smtk-import] Error - Couldn't add bookmark, dive %d, Name = %s", + d->number, tmp); } } smtk_free(bound_values, table->num_cols); -- cgit v1.2.3-70-g09d2