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>
This commit is contained in:
Dirk Hohndel 2012-12-15 20:40:16 -10:00
parent be9d924cf8
commit 2f9960f20b

View file

@ -1441,6 +1441,14 @@ void edit_dive_when_cb(GtkWidget *menuitem, struct dive *dive)
gtk_widget_destroy(dialog); gtk_widget_destroy(dialog);
when = utc_mktime(&tm); when = utc_mktime(&tm);
if (dive->when != when) { 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; dive->when = when;
mark_divelist_changed(TRUE); mark_divelist_changed(TRUE);
remember_tree_state(); remember_tree_state();