summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGravatar Linus Torvalds <torvalds@linux-foundation.org>2012-06-27 13:11:54 -0700
committerGravatar Linus Torvalds <torvalds@linux-foundation.org>2012-06-27 13:11:54 -0700
commite3bdfc2dc357e362a695632a3e0ee24095bb5b5a (patch)
tree26f91dd877b4f766e772e3ca47f8705d0a6aedc9
parentd4b0ce1c86d420a308770a598a07c3815778dc57 (diff)
downloadsubsurface-e3bdfc2dc357e362a695632a3e0ee24095bb5b5a.tar.gz
Rough "Add new dive" infrastructure in the divelist
Do a right-click to get a menu with the "Add dive" entry. Should do delete too, but that's for later. What's also apparently for later is to make this *useful*. It's the butt-ugliest time entry field ever, and there's no way to set depth for the dive either. So this is more of a RFC than anything truly useful. Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
-rw-r--r--dive.h1
-rw-r--r--divelist.c45
-rw-r--r--info.c84
3 files changed, 130 insertions, 0 deletions
diff --git a/dive.h b/dive.h
index 6b5c77816..a25fafb39 100644
--- a/dive.h
+++ b/dive.h
@@ -343,6 +343,7 @@ extern void add_location(const char *string);
extern void remember_event(const char *eventname);
extern void evn_foreach(void (*callback)(const char *, int *, void *), void *data);
+extern int add_new_dive(struct dive *dive);
extern int edit_dive_info(struct dive *dive);
extern void dive_list_update_dives(void);
extern void flush_divelist(struct dive *dive);
diff --git a/divelist.c b/divelist.c
index 2054ca017..c67e42a4f 100644
--- a/divelist.c
+++ b/divelist.c
@@ -687,6 +687,49 @@ static void row_activated_cb(GtkTreeView *tree_view,
edit_dive_info(get_dive(index));
}
+static void add_dive_cb(GtkWidget *menuitem, GtkTreeModel *model)
+{
+ struct dive *dive;
+
+ dive = alloc_dive();
+ if (add_new_dive(dive)) {
+ record_dive(dive);
+ report_dives(TRUE);
+ return;
+ }
+ free(dive);
+}
+
+static void popup_divelist_menu(GtkTreeView *tree_view, GtkTreeModel *model, int button)
+{
+ GtkWidget *menu, *menuitem;
+
+ menu = gtk_menu_new();
+ menuitem = gtk_menu_item_new_with_label("Add dive");
+ g_signal_connect(menuitem, "activate", G_CALLBACK(add_dive_cb), model);
+ gtk_menu_shell_append(GTK_MENU_SHELL(menu), menuitem);
+ gtk_widget_show_all(menu);
+
+ gtk_menu_popup(GTK_MENU(menu), NULL, NULL, NULL, NULL,
+ button, gtk_get_current_event_time());
+}
+
+static void popup_menu_cb(GtkTreeView *tree_view,
+ GtkTreeModel *model)
+{
+ popup_divelist_menu(tree_view, model, 0);
+}
+
+static gboolean button_press_cb(GtkWidget *treeview, GdkEventButton *event, GtkTreeModel *model)
+{
+ /* Right-click? Bring up the menu */
+ if (event->type == GDK_BUTTON_PRESS && event->button == 3) {
+ popup_divelist_menu(GTK_TREE_VIEW(treeview), model, 3);
+ return TRUE;
+ }
+ return FALSE;
+}
+
GtkWidget *dive_list_create(void)
{
GtkTreeSelection *selection;
@@ -734,6 +777,8 @@ GtkWidget *dive_list_create(void)
g_signal_connect_after(dive_list.tree_view, "realize", G_CALLBACK(realize_cb), NULL);
g_signal_connect(dive_list.tree_view, "row-activated", G_CALLBACK(row_activated_cb), dive_list.model);
+ g_signal_connect(dive_list.tree_view, "button-press-event", G_CALLBACK(button_press_cb), dive_list.model);
+ g_signal_connect(dive_list.tree_view, "popup-menu", G_CALLBACK(popup_menu_cb), dive_list.model);
g_signal_connect(selection, "changed", G_CALLBACK(selection_cb), dive_list.model);
dive_list.container_widget = gtk_scrolled_window_new(NULL, NULL);
diff --git a/info.c b/info.c
index 813d58adc..10a31f558 100644
--- a/info.c
+++ b/info.c
@@ -420,6 +420,90 @@ int edit_dive_info(struct dive *dive)
return success;
}
+/* Fixme - should do at least depths too - a dive without a depth is kind of pointless */
+static time_t dive_time_widget(struct dive *dive)
+{
+ GtkWidget *dialog;
+ GtkWidget *cal, *hbox, *vbox;
+ GtkWidget *h, *m;
+ GtkWidget *duration;
+ GtkWidget *label;
+ guint yval, mval, dval;
+ struct tm tm;
+ int success;
+
+ dialog = gtk_dialog_new_with_buttons("Date and Time",
+ GTK_WINDOW(main_window),
+ GTK_DIALOG_DESTROY_WITH_PARENT,
+ GTK_STOCK_OK, GTK_RESPONSE_ACCEPT,
+ GTK_STOCK_CANCEL, GTK_RESPONSE_REJECT,
+ NULL);
+
+ vbox = gtk_dialog_get_content_area(GTK_DIALOG(dialog));
+
+ /* Calendar hbox */
+ hbox = gtk_hbox_new(0, 3);
+ gtk_box_pack_start(GTK_BOX(vbox), hbox, FALSE, TRUE, 0);
+
+ cal = gtk_calendar_new();
+ gtk_box_pack_start(GTK_BOX(hbox), cal, FALSE, TRUE, 0);
+
+ /* Time/duration hbox */
+ hbox = gtk_hbox_new(0, 3);
+ gtk_box_pack_start(GTK_BOX(vbox), hbox, FALSE, TRUE, 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_spin_button_set_wrap(GTK_SPIN_BUTTON(h), TRUE);
+ gtk_spin_button_set_wrap(GTK_SPIN_BUTTON(m), TRUE);
+
+ duration = gtk_spin_button_new_with_range (0.0, 1000.0, 1.0);
+
+ gtk_box_pack_start(GTK_BOX(hbox), h, FALSE, FALSE, 0);
+ label = gtk_label_new(":");
+ gtk_box_pack_start(GTK_BOX(hbox), label, FALSE, FALSE, 0);
+ gtk_box_pack_start(GTK_BOX(hbox), m, FALSE, FALSE, 0);
+
+ label = gtk_label_new(" Duration:");
+ gtk_box_pack_start(GTK_BOX(hbox), label, FALSE, FALSE, 0);
+ gtk_box_pack_start(GTK_BOX(hbox), duration, FALSE, FALSE, 0);
+
+ gtk_widget_show_all(dialog);
+ success = gtk_dialog_run(GTK_DIALOG(dialog)) == GTK_RESPONSE_ACCEPT;
+ if (!success) {
+ gtk_widget_destroy(dialog);
+ return 0;
+ }
+
+ 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));
+
+ dive->duration.seconds = gtk_spin_button_get_value(GTK_SPIN_BUTTON(duration))*60;
+
+ gtk_widget_destroy(dialog);
+ dive->when = utc_mktime(&tm);
+
+ return 1;
+}
+
+int add_new_dive(struct dive *dive)
+{
+ if (!dive)
+ return 0;
+
+ if (!dive_time_widget(dive))
+ return 0;
+
+ return edit_dive_info(dive);
+}
+
GtkWidget *extended_dive_info_widget(void)
{
GtkWidget *vbox, *hbox;