summaryrefslogtreecommitdiffstats
path: root/divelist.c
diff options
context:
space:
mode:
authorGravatar Dirk Hohndel <dirk@hohndel.org>2012-12-10 13:16:17 -0800
committerGravatar Dirk Hohndel <dirk@hohndel.org>2012-12-10 13:23:55 -0800
commitfebcbd6325e42b5b9a6478f7e7d726b98cb5e9bb (patch)
tree34209785d2cb165c94265508c15c98bcb57f8aaa /divelist.c
parent286020a2d16ce3e036b627ccf96fc6dd67dd57a5 (diff)
downloadsubsurface-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 'divelist.c')
-rw-r--r--divelist.c49
1 files changed, 49 insertions, 0 deletions
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);