summaryrefslogtreecommitdiffstats
path: root/info.c
diff options
context:
space:
mode:
Diffstat (limited to 'info.c')
-rw-r--r--info.c70
1 files changed, 40 insertions, 30 deletions
diff --git a/info.c b/info.c
index ee27c4535..97f015155 100644
--- a/info.c
+++ b/info.c
@@ -455,7 +455,7 @@ static void save_dive_info_changes(struct dive *dive, struct dive *master, struc
new_text = (char *)gtk_entry_get_text(info->airtemp);
if(sscanf(new_text, "%lf", &newtemp) == 1) {
unsigned long mkelvin;
- switch (output_units.temperature) {
+ switch (prefs.output_units.temperature) {
case CELSIUS:
mkelvin = C_to_mkelvin(newtemp);
break;
@@ -817,18 +817,11 @@ static GtkWidget *frame_box(GtkWidget *vbox, const char *fmt, ...)
return hbox;
}
-/* Fixme - should do at least depths too - a dive without a depth is kind of pointless */
-static timestamp_t dive_time_widget(struct dive *dive)
+GtkWidget *create_date_time_widget(struct tm *time, GtkWidget **cal, GtkWidget **h, GtkWidget **m)
{
GtkWidget *dialog;
- GtkWidget *cal, *hbox, *vbox, *box;
- GtkWidget *h, *m;
- GtkWidget *duration, *depth;
+ GtkWidget *hbox, *vbox;
GtkWidget *label;
- guint yval, mval, dval;
- struct tm tm, *time;
- int success;
- double depthinterval, val;
dialog = gtk_dialog_new_with_buttons(_("Date and Time"),
GTK_WINDOW(main_window),
@@ -841,14 +834,42 @@ static timestamp_t dive_time_widget(struct dive *dive)
/* Calendar hbox */
hbox = frame_box(vbox, _("Date:"));
- cal = gtk_calendar_new();
- gtk_box_pack_start(GTK_BOX(hbox), cal, FALSE, TRUE, 0);
+ *cal = gtk_calendar_new();
+ gtk_box_pack_start(GTK_BOX(hbox), *cal, FALSE, TRUE, 0);
/* Time hbox */
hbox = frame_box(vbox, _("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);
+ *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);
+ gtk_spin_button_set_value(GTK_SPIN_BUTTON(*m), (time->tm_min / 5)*5);
+
+ gtk_spin_button_set_wrap(GTK_SPIN_BUTTON(*h), TRUE);
+ gtk_spin_button_set_wrap(GTK_SPIN_BUTTON(*m), TRUE);
+
+ gtk_box_pack_end(GTK_BOX(hbox), *m, FALSE, FALSE, 0);
+ label = gtk_label_new(":");
+ gtk_box_pack_end(GTK_BOX(hbox), label, FALSE, FALSE, 0);
+ gtk_box_pack_end(GTK_BOX(hbox), *h, FALSE, FALSE, 0);
+
+ return dialog;
+}
+
+static timestamp_t dive_time_widget(struct dive *dive)
+{
+ GtkWidget *dialog;
+ GtkWidget *cal, *vbox, *hbox, *box;
+ GtkWidget *h, *m;
+ GtkWidget *duration, *depth;
+ guint yval, mval, dval;
+ struct tm tm, *time;
+ int success;
+ double depthinterval, val;
/*
* If we have a dive selected, 'add dive' will default
@@ -868,19 +889,8 @@ static timestamp_t dive_time_widget(struct dive *dive)
now = tv.tv_sec;
time = localtime(&now);
}
- 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);
- gtk_spin_button_set_value(GTK_SPIN_BUTTON(m), (time->tm_min / 5)*5);
-
- gtk_spin_button_set_wrap(GTK_SPIN_BUTTON(h), TRUE);
- gtk_spin_button_set_wrap(GTK_SPIN_BUTTON(m), TRUE);
-
- gtk_box_pack_end(GTK_BOX(hbox), m, FALSE, FALSE, 0);
- label = gtk_label_new(":");
- gtk_box_pack_end(GTK_BOX(hbox), label, FALSE, FALSE, 0);
- gtk_box_pack_end(GTK_BOX(hbox), h, FALSE, FALSE, 0);
-
+ dialog = create_date_time_widget(time, &cal, &h, &m);
+ 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);
@@ -890,8 +900,8 @@ static timestamp_t dive_time_widget(struct dive *dive)
gtk_box_pack_end(GTK_BOX(box), duration, FALSE, FALSE, 0);
/* Depth box */
- box = frame_box(hbox, _("Depth (%s):"), output_units.length == FEET ? _("ft") : _("m"));
- if (output_units.length == FEET) {
+ box = frame_box(hbox, _("Depth (%s):"), prefs.output_units.length == FEET ? _("ft") : _("m"));
+ if (prefs.output_units.length == FEET) {
depthinterval = 1.0;
} else {
depthinterval = 0.1;
@@ -917,7 +927,7 @@ static timestamp_t dive_time_widget(struct dive *dive)
tm.tm_min = gtk_spin_button_get_value(GTK_SPIN_BUTTON(m));
val = gtk_spin_button_get_value(GTK_SPIN_BUTTON(depth));
- if (output_units.length == FEET) {
+ if (prefs.output_units.length == FEET) {
dive->maxdepth.mm = feet_to_mm(val);
} else {
dive->maxdepth.mm = val * 1000 + 0.5;