aboutsummaryrefslogtreecommitdiffstats
path: root/smtk-import/smartrak.c
diff options
context:
space:
mode:
authorGravatar Salvador Cuñat <salvador.cunat@gmail.com>2017-04-02 23:42:36 +0200
committerGravatar Dirk Hohndel <dirk@hohndel.org>2017-04-04 10:54:55 -0700
commite4086dc74648c5f5ed7b72f1dc35e16e3bee8041 (patch)
treed96f24c69f778dbd68643d46fcd7de3baa93b0d1 /smtk-import/smartrak.c
parent4864ea56cbaa694ed237e854de2cfa1407fc18c4 (diff)
downloadsubsurface-e4086dc74648c5f5ed7b72f1dc35e16e3bee8041.tar.gz
smtk-import Avoid duplicities in bookmarks
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 <salvador.cunat@gmail.com>
Diffstat (limited to 'smtk-import/smartrak.c')
-rw-r--r--smtk-import/smartrak.c28
1 files changed, 25 insertions, 3 deletions
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
@@ -645,6 +645,22 @@ static void smtk_parse_relations(MdbHandle *mdb, struct dive *dive, char *dive_i
}
/*
+ * 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
* Type may be one of 1 = Text; 2 = DC; 3 = Tissue Data; 4 = Photo (0 most of time??)
@@ -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);