From b304562fa89aa67fd5639d6c14c6e12472287515 Mon Sep 17 00:00:00 2001 From: Linus Torvalds Date: Sun, 11 Nov 2012 15:02:50 +0100 Subject: [PATCH] Be stricter about when we allow merging of dives If the surface interval between two dives is more than half an hour, don't try to call it a single dive. Just the dive profile will be looking ridiculous. Things like tank refills etc could also be a good thing to check (again, the dive profile would look ridiculous), but the cylinder pressure going up a small amount is actually normal (ie cylinder warming up in warmer water on the surface). So I don't know what the proper limit for that would be. Signed-off-by: Linus Torvalds Signed-off-by: Dirk Hohndel --- divelist.c | 19 ++++++++++++++----- 1 file changed, 14 insertions(+), 5 deletions(-) diff --git a/divelist.c b/divelist.c index 10c1ce4b3..3e48d2fb9 100644 --- a/divelist.c +++ b/divelist.c @@ -2118,16 +2118,25 @@ static void merge_dives_cb(GtkWidget *menuitem, void *unused) /* Called if there are exactly two selected dives and the dive at idx is one of them */ static void add_dive_merge_label(int idx, GtkMenuShell *menu) { - struct dive *d; + struct dive *a, *b; GtkWidget *menuitem; /* The other selected dive must be next to it.. */ - if (!((d = get_dive(idx-1)) && d->selected) && - !((d = get_dive(idx+1)) && d->selected)) - return; + a = get_dive(idx); + b = get_dive(idx+1); + if (!b || !b->selected) { + b = a; + a = get_dive(idx-1); + if (!a || !a->selected) + return; + } /* .. and they had better be in the same dive trip */ - if (d->divetrip != get_dive(idx)->divetrip) + if (a->divetrip != b->divetrip) + return; + + /* .. and if the surface interval is excessive, you must be kidding us */ + if (b->when > a->when + a->duration.seconds + 30*60) return; /* If so, we can add a "merge dive" menu entry */