summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGravatar Dirk Hohndel <dirk@hohndel.org>2013-02-27 14:44:28 -0800
committerGravatar Dirk Hohndel <dirk@hohndel.org>2013-02-27 14:46:47 -0800
commit9e8aaad133736dfc35d8a5163befd7e7196a3b19 (patch)
tree873b2c2eb5a18ccb3e6c2b6f17d9f34230e42d99
parent4c04fe531636dbb21efaa267283aef07248c7ccd (diff)
downloadsubsurface-9e8aaad133736dfc35d8a5163befd7e7196a3b19.tar.gz
When manually adding a dive allow user to set avg depth as well
So far we only allowed setting the max depth. This changes the layout of the entry widget and makes our helper function create_date_time_widget return the hbox in which it positions the time entry. I plan to reuse this later when allowing to edit the duration as well as the start date and time under certain circumstances. This is a small part of a feature request; see #75 Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
-rw-r--r--display-gtk.h2
-rw-r--r--divelist.c4
-rw-r--r--info.c56
3 files changed, 42 insertions, 20 deletions
diff --git a/display-gtk.h b/display-gtk.h
index 335cf4962..fb7eaf254 100644
--- a/display-gtk.h
+++ b/display-gtk.h
@@ -52,7 +52,7 @@ enum {
MATCH_AFTER
} found_string_entry;
-extern GtkWidget *create_date_time_widget(struct tm *time, GtkWidget **cal, GtkWidget **h, GtkWidget **m);
+extern GtkWidget *create_date_time_widget(struct tm *time, GtkWidget **cal, GtkWidget **h, GtkWidget **m, GtkWidget **timehbox);
extern void add_string_list_entry(const char *string, GtkListStore *list);
extern int match_list(GtkListStore *list, const char *string);
diff --git a/divelist.c b/divelist.c
index 1c020afe4..4fa817d0a 100644
--- a/divelist.c
+++ b/divelist.c
@@ -1537,7 +1537,7 @@ static void edit_dive_from_path_cb(GtkWidget *menuitem, GtkTreePath *path)
static void edit_dive_when_cb(GtkWidget *menuitem, struct dive *dive)
{
- GtkWidget *dialog, *cal, *h, *m;
+ GtkWidget *dialog, *cal, *h, *m, *timehbox;
timestamp_t when;
guint yval, mval, dval;
@@ -1549,7 +1549,7 @@ static void edit_dive_when_cb(GtkWidget *menuitem, struct dive *dive)
when = dive->when;
utc_mkdate(when, &tm);
- dialog = create_date_time_widget(&tm, &cal, &h, &m);
+ dialog = create_date_time_widget(&tm, &cal, &h, &m, &timehbox);
gtk_widget_show_all(dialog);
success = gtk_dialog_run(GTK_DIALOG(dialog)) == GTK_RESPONSE_ACCEPT;
diff --git a/info.c b/info.c
index 5f979eb3e..9a5c3a1a2 100644
--- a/info.c
+++ b/info.c
@@ -1095,7 +1095,11 @@ static GtkWidget *frame_box(GtkWidget *vbox, const char *fmt, ...)
return hbox;
}
-GtkWidget *create_date_time_widget(struct tm *time, GtkWidget **cal, GtkWidget **h, GtkWidget **m)
+/* returns the dialog plus pointers to the calendar, hour and minute widget
+ * plus the hbox that holds the time entry (in case the caller wants to put
+ * a duration entry widget next to the time entry widget */
+GtkWidget *create_date_time_widget(struct tm *time, GtkWidget **cal, GtkWidget **h,
+ GtkWidget **m, GtkWidget **timehbox)
{
GtkWidget *dialog;
GtkWidget *hbox, *vbox;
@@ -1116,12 +1120,13 @@ GtkWidget *create_date_time_widget(struct tm *time, GtkWidget **cal, GtkWidget *
gtk_box_pack_start(GTK_BOX(hbox), *cal, FALSE, TRUE, 0);
/* Time hbox */
- hbox = frame_box(vbox, _("Time"));
+ *timehbox = gtk_hbox_new(TRUE, 3);
+ gtk_box_pack_start(GTK_BOX(vbox), *timehbox, FALSE, FALSE, 0);
+ hbox = frame_box(*timehbox, _("Time"));
*h = gtk_spin_button_new_with_range (0.0, 23.0, 1.0);
*m = gtk_spin_button_new_with_range (0.0, 59.0, 1.0);
-
gtk_calendar_select_month(GTK_CALENDAR(*cal), time->tm_mon, time->tm_year + 1900);
gtk_calendar_select_day(GTK_CALENDAR(*cal), time->tm_mday);
gtk_spin_button_set_value(GTK_SPIN_BUTTON(*h), time->tm_hour);
@@ -1138,16 +1143,28 @@ GtkWidget *create_date_time_widget(struct tm *time, GtkWidget **cal, GtkWidget *
return dialog;
}
+static int mm_from_spinbutton(GtkWidget *depth)
+{
+ int result;
+ double val = gtk_spin_button_get_value(GTK_SPIN_BUTTON(depth));
+ if (prefs.units.length == FEET) {
+ result = feet_to_mm(val);
+ } else {
+ result = val * 1000 + 0.5;
+ }
+ return result;
+}
+
static timestamp_t dive_time_widget(struct dive *dive)
{
GtkWidget *dialog;
GtkWidget *cal, *vbox, *hbox, *box;
GtkWidget *h, *m;
- GtkWidget *duration, *depth;
+ GtkWidget *duration, *depth, *avgdepth;
guint yval, mval, dval;
struct tm tm, *time;
int success;
- double depthinterval, val;
+ double depthinterval;
/*
* If we have a dive selected, 'add dive' will default
@@ -1167,18 +1184,19 @@ static timestamp_t dive_time_widget(struct dive *dive)
now = tv.tv_sec;
time = localtime(&now);
}
- dialog = create_date_time_widget(time, &cal, &h, &m);
+ dialog = create_date_time_widget(time, &cal, &h, &m, &hbox);
vbox = gtk_dialog_get_content_area(GTK_DIALOG(dialog));
- hbox = gtk_hbox_new(TRUE, 3);
- gtk_box_pack_start(GTK_BOX(vbox), hbox, FALSE, FALSE, 0);
- /* Duration hbox */
+ /* Duration box */
box = frame_box(hbox, _("Duration (min)"));
duration = gtk_spin_button_new_with_range (0.0, 1000.0, 1.0);
gtk_box_pack_end(GTK_BOX(box), duration, FALSE, FALSE, 0);
+ hbox = gtk_hbox_new(TRUE, 3);
+ gtk_box_pack_start(GTK_BOX(vbox), hbox, FALSE, FALSE, 0);
+
/* Depth box */
- box = frame_box(hbox, _("Depth (%s):"), prefs.units.length == FEET ? _("ft") : _("m"));
+ box = frame_box(hbox, _("Max Depth (%s):"), prefs.units.length == FEET ? _("ft") : _("m"));
if (prefs.units.length == FEET) {
depthinterval = 1.0;
} else {
@@ -1187,6 +1205,15 @@ static timestamp_t dive_time_widget(struct dive *dive)
depth = gtk_spin_button_new_with_range (0.0, 1000.0, depthinterval);
gtk_box_pack_end(GTK_BOX(box), depth, FALSE, FALSE, 0);
+ box = frame_box(hbox, _("Avg Depth (%s):"), prefs.units.length == FEET ? _("ft") : _("m"));
+ if (prefs.units.length == FEET) {
+ depthinterval = 1.0;
+ } else {
+ depthinterval = 0.1;
+ }
+ avgdepth = gtk_spin_button_new_with_range (0.0, 1000.0, depthinterval);
+ gtk_box_pack_end(GTK_BOX(box), avgdepth, FALSE, FALSE, 0);
+
/* All done, show it and wait for editing */
gtk_widget_show_all(dialog);
success = gtk_dialog_run(GTK_DIALOG(dialog)) == GTK_RESPONSE_ACCEPT;
@@ -1204,13 +1231,8 @@ static timestamp_t dive_time_widget(struct dive *dive)
tm.tm_hour = gtk_spin_button_get_value(GTK_SPIN_BUTTON(h));
tm.tm_min = gtk_spin_button_get_value(GTK_SPIN_BUTTON(m));
- val = gtk_spin_button_get_value(GTK_SPIN_BUTTON(depth));
- if (prefs.units.length == FEET) {
- dive->dc.maxdepth.mm = feet_to_mm(val);
- } else {
- dive->dc.maxdepth.mm = val * 1000 + 0.5;
- }
-
+ dive->dc.maxdepth.mm = mm_from_spinbutton(depth);
+ dive->dc.meandepth.mm = mm_from_spinbutton(avgdepth);
dive->dc.duration.seconds = gtk_spin_button_get_value(GTK_SPIN_BUTTON(duration))*60;
gtk_widget_destroy(dialog);