summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--display-gtk.h2
-rw-r--r--divelist.c49
-rw-r--r--info.c62
3 files changed, 87 insertions, 26 deletions
diff --git a/display-gtk.h b/display-gtk.h
index 36895b7c8..b48c87eed 100644
--- a/display-gtk.h
+++ b/display-gtk.h
@@ -85,6 +85,8 @@ extern int process_ui_events(void);
extern void update_progressbar(progressbar_t *progress, double value);
extern void update_progressbar_text(progressbar_t *progress, const char *text);
+extern GtkWidget *create_date_time_widget(struct tm *time, GtkWidget **cal, GtkWidget **h, GtkWidget **m);
+
extern GtkWidget *dive_profile_widget(void);
extern GtkWidget *dive_info_frame(void);
extern GtkWidget *extended_dive_info_widget(void);
diff --git a/divelist.c b/divelist.c
index 03517d360..676ba62ae 100644
--- a/divelist.c
+++ b/divelist.c
@@ -1384,6 +1384,48 @@ void edit_dive_from_path_cb(GtkWidget *menuitem, GtkTreePath *path)
edit_multi_dive_info(dive);
}
+void edit_dive_when_cb(GtkWidget *menuitem, struct dive *dive)
+{
+ GtkWidget *dialog, *cal, *h, *m;
+ timestamp_t when;
+
+ guint yval, mval, dval;
+ int success;
+ struct tm tm;
+
+ if (!dive)
+ return;
+
+ when = dive->when;
+ utc_mkdate(when, &tm);
+ dialog = create_date_time_widget(&tm, &cal, &h, &m);
+
+ gtk_widget_show_all(dialog);
+ success = gtk_dialog_run(GTK_DIALOG(dialog)) == GTK_RESPONSE_ACCEPT;
+ if (!success) {
+ gtk_widget_destroy(dialog);
+ return;
+ }
+ memset(&tm, 0, sizeof(tm));
+ gtk_calendar_get_date(GTK_CALENDAR(cal), &yval, &mval, &dval);
+ tm.tm_year = yval;
+ tm.tm_mon = mval;
+ tm.tm_mday = dval;
+ tm.tm_hour = gtk_spin_button_get_value(GTK_SPIN_BUTTON(h));
+ tm.tm_min = gtk_spin_button_get_value(GTK_SPIN_BUTTON(m));
+
+ gtk_widget_destroy(dialog);
+ when = utc_mktime(&tm);
+ if (dive->when != when) {
+ dive->when = when;
+ mark_divelist_changed(TRUE);
+ remember_tree_state();
+ report_dives(FALSE, FALSE);
+ dive_list_update_dives();
+ restore_tree_state();
+ }
+}
+
static void expand_all_cb(GtkWidget *menuitem, GtkTreeView *tree_view)
{
gtk_tree_view_expand_all(tree_view);
@@ -2141,6 +2183,9 @@ static void popup_divelist_menu(GtkTreeView *tree_view, GtkTreeModel *model, int
if (amount_selected == 1) {
deletelabel = _(deletesinglelabel);
editlabel = _(editsinglelabel);
+ menuitem = gtk_menu_item_new_with_label(_("Edit dive date/time"));
+ g_signal_connect(menuitem, "activate", G_CALLBACK(edit_dive_when_cb), dive);
+ gtk_menu_shell_append(GTK_MENU_SHELL(menu), menuitem);
} else {
deletelabel = _(deleteplurallabel);
editlabel = _(editplurallabel);
@@ -2157,6 +2202,10 @@ static void popup_divelist_menu(GtkTreeView *tree_view, GtkTreeModel *model, int
if (amount_selected == 2)
add_dive_merge_label(idx, GTK_MENU_SHELL(menu));
} else {
+ menuitem = gtk_menu_item_new_with_label(_("Edit dive date/time"));
+ g_signal_connect(menuitem, "activate", G_CALLBACK(edit_dive_when_cb), dive);
+ gtk_menu_shell_append(GTK_MENU_SHELL(menu), menuitem);
+
deletelabel = _(deletesinglelabel);
menuitem = gtk_menu_item_new_with_label(deletelabel);
g_signal_connect(menuitem, "activate", G_CALLBACK(delete_dive_cb), path);
diff --git a/info.c b/info.c
index c61fd7588..97f015155 100644
--- a/info.c
+++ b/info.c
@@ -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);