diff options
author | Dirk Hohndel <dirk@hohndel.org> | 2012-12-10 13:16:17 -0800 |
---|---|---|
committer | Dirk Hohndel <dirk@hohndel.org> | 2012-12-10 13:23:55 -0800 |
commit | febcbd6325e42b5b9a6478f7e7d726b98cb5e9bb (patch) | |
tree | 34209785d2cb165c94265508c15c98bcb57f8aaa /info.c | |
parent | 286020a2d16ce3e036b627ccf96fc6dd67dd57a5 (diff) | |
download | subsurface-febcbd6325e42b5b9a6478f7e7d726b98cb5e9bb.tar.gz |
Add the ability to edit the date/time of a dive
This can cause some fun unintended side effects - especially when the dive
is part of a trip and the new date/time moves this into a different trip.
Instead, trips get split and the overall result is consistent, but a bit
unexpected.
But since this is designed to help people right after a dive import in
case the clock on the dive computer was wrong, my guess is this won't ever
be a problem for actual users.
Fixes ticket 18
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
Diffstat (limited to 'info.c')
-rw-r--r-- | info.c | 62 |
1 files changed, 36 insertions, 26 deletions
@@ -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); |