From 85ed689dc0d6ab07386153151f6ac232adb91a8f Mon Sep 17 00:00:00 2001 From: Dirk Hohndel Date: Mon, 7 Jan 2013 08:13:23 -0800 Subject: Support relative times in diveplanner input "on the fly" mode This had gotten lost when updating the profile on the fly. Signed-off-by: Dirk Hohndel --- dive.h | 2 +- gtk-gui.c | 2 +- planner.c | 8 ++++++-- 3 files changed, 8 insertions(+), 4 deletions(-) diff --git a/dive.h b/dive.h index 697ab8512..43010ffaf 100644 --- a/dive.h +++ b/dive.h @@ -597,7 +597,7 @@ struct diveplan { extern void test_planner(void); void plan(struct diveplan *diveplan, char **cache_datap, struct dive **divep); void plan_add_segment(struct diveplan *diveplan, int duration, int depth, int o2, int he); -void add_duration_to_nth_dp(struct diveplan *diveplan, int idx, int duration); +void add_duration_to_nth_dp(struct diveplan *diveplan, int idx, int duration, gboolean is_rel); void add_depth_to_nth_dp(struct diveplan *diveplan, int idx, int depth); void add_gas_to_nth_dp(struct diveplan *diveplan, int idx, int o2, int he); void free_dps(struct divedatapoint *dp); diff --git a/gtk-gui.c b/gtk-gui.c index 70be30120..6c39d25fe 100644 --- a/gtk-gui.c +++ b/gtk-gui.c @@ -1395,7 +1395,7 @@ static gboolean duration_focus_out_cb(GtkWidget *entry, GdkEvent * event, gpoint durationtext = strdup(gtk_entry_get_text(GTK_ENTRY(entry))); if (validate_time(durationtext, &duration, &is_rel)) { - add_duration_to_nth_dp(&diveplan, idx, duration); + add_duration_to_nth_dp(&diveplan, idx, duration, is_rel); show_planned_dive(); } else { /* we need to instead change the color of the input field or something */ diff --git a/planner.c b/planner.c index 13a36e62b..fab5996ce 100644 --- a/planner.c +++ b/planner.c @@ -179,9 +179,13 @@ struct divedatapoint *get_nth_dp(struct diveplan *diveplan, int idx) return dp; } -void add_duration_to_nth_dp(struct diveplan *diveplan, int idx, int duration) +void add_duration_to_nth_dp(struct diveplan *diveplan, int idx, int duration, gboolean is_rel) { - struct divedatapoint *dp = get_nth_dp(diveplan, idx); + struct divedatapoint *pdp, *dp = get_nth_dp(diveplan, idx); + if (idx > 0 && is_rel) { + pdp = get_nth_dp(diveplan, idx - 1); + duration += pdp->time; + } dp->time = duration; } -- cgit v1.2.3-70-g09d2