summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGravatar Dirk Hohndel <dirk@hohndel.org>2012-12-15 20:40:16 -1000
committerGravatar Dirk Hohndel <dirk@hohndel.org>2012-12-15 21:01:29 -1000
commit2f9960f20b292a2fa8c01da4a0c4600c71f4fc3a (patch)
tree7940972608a6c0fdc825e57a45451ccd5efe23a9
parentbe9d924cf833fd4f4de478cbc5dccbb3775acc3d (diff)
downloadsubsurface-2f9960f20b292a2fa8c01da4a0c4600c71f4fc3a.tar.gz
Deal with some trip issues when editing dive timestamps
The idea behind editing timestamps had of course been the typical "oops, I forgot to set my time correctly" which shifts a dive (or a few of them) by a few hours but keeps the overall order of dives the same). But reasonable people might argue that they can envision a scenario where more dramatic changes are being made. And we need to deal with the impact this has on dive trips. Here we handle a couple of simple cases: - this is the only dive in a trip; just update the trip (this can still cause problems if the new time is in the middle of an existing trip). - this dives moves before the start of the trip it is in; let's remove it from that trip (this response is a bit simplistic - but as I tried to say, I don't expect this to be a common use case; and removing it at least doesn't lead to entirely unexpected behavior). - this dive moves past the end of this trip into the range of a different trip (in this case we remove the dive from the current trip and allow it to interrupt the trip it is moving into). Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
-rw-r--r--divelist.c8
1 files changed, 8 insertions, 0 deletions
diff --git a/divelist.c b/divelist.c
index a917889c4..19ee031c6 100644
--- a/divelist.c
+++ b/divelist.c
@@ -1441,6 +1441,14 @@ void edit_dive_when_cb(GtkWidget *menuitem, struct dive *dive)
gtk_widget_destroy(dialog);
when = utc_mktime(&tm);
if (dive->when != when) {
+ /* if this is the only dive in the trip, just change the trip time */
+ if (dive->divetrip && dive->divetrip->nrdives == 1)
+ dive->divetrip->when = when;
+ /* if this is suddenly before the start of the trip, remove it from the trip */
+ else if (dive->divetrip && dive->divetrip->when > when)
+ remove_dive_from_trip(dive);
+ else if (find_matching_trip(when) != dive->divetrip)
+ remove_dive_from_trip(dive);
dive->when = when;
mark_divelist_changed(TRUE);
remember_tree_state();