From 98efa0794aa12eea203216e6f5e7e0bdd336d488 Mon Sep 17 00:00:00 2001 From: Dirk Hohndel Date: Tue, 25 Oct 2011 02:51:16 -0700 Subject: [PATCH] Add menu item and dialog to select which events to display Right now they are displayed in one hbox which doesn't work if you have many events - but the code itself works and correctly toggles the events on and off. Signed-off-by: Dirk Hohndel --- dive.h | 1 + gtk-gui.c | 53 ++++++++++++++++++++++++++++++++++++++++++++++++++++- profile.c | 9 +++++++++ 3 files changed, 62 insertions(+), 1 deletion(-) diff --git a/dive.h b/dive.h index 1008e56..92d358d 100644 --- a/dive.h +++ b/dive.h @@ -263,6 +263,7 @@ extern void add_cylinder_description(cylinder_type_t *); extern void add_people(const char *string); 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 void dive_list_update_dives(void); extern void flush_divelist(struct dive *dive); diff --git a/gtk-gui.c b/gtk-gui.c index 47cab62..a1a129d 100644 --- a/gtk-gui.c +++ b/gtk-gui.c @@ -305,6 +305,13 @@ OPTIONCALLBACK(nitrox_toggle, visible_cols.nitrox) OPTIONCALLBACK(temperature_toggle, visible_cols.temperature) OPTIONCALLBACK(cylinder_toggle, visible_cols.cylinder) +static void event_toggle(GtkWidget *w, gpointer _data) +{ + gboolean *plot_ev = _data; + + *plot_ev = GTK_TOGGLE_BUTTON(w)->active; +} + static void preferences_dialog(GtkWidget *w, gpointer data) { int result; @@ -407,6 +414,45 @@ static void preferences_dialog(GtkWidget *w, gpointer data) gtk_widget_destroy(dialog); } +static void create_toggle(const char* label, int *on, void *_data) +{ + GtkWidget *button, *box = _data; + + button = gtk_check_button_new_with_label(label); + gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(button), *on); + gtk_box_pack_start(GTK_BOX(box), button, FALSE, FALSE, 6); + g_signal_connect(G_OBJECT(button), "toggled", G_CALLBACK(event_toggle), on); +} + +static void selectevents_dialog(GtkWidget *w, gpointer data) +{ + int result; + GtkWidget *dialog, *frame, *vbox, *hbox; + + dialog = gtk_dialog_new_with_buttons("SelectEvents", + GTK_WINDOW(main_window), + GTK_DIALOG_DESTROY_WITH_PARENT, + GTK_STOCK_OK, GTK_RESPONSE_ACCEPT, + GTK_STOCK_CANCEL, GTK_RESPONSE_REJECT, + NULL); + + frame = gtk_frame_new("Enable / Disable Events"); + vbox = gtk_dialog_get_content_area(GTK_DIALOG(dialog)); + gtk_box_pack_start(GTK_BOX(vbox), frame, FALSE, FALSE, 5); + + hbox = gtk_hbox_new(FALSE, 6); + gtk_container_add(GTK_CONTAINER(frame), hbox); + + evn_foreach(&create_toggle, hbox); + + gtk_widget_show_all(dialog); + result = gtk_dialog_run(GTK_DIALOG(dialog)); + if (result == GTK_RESPONSE_ACCEPT) { + repaint_dive(); + } + gtk_widget_destroy(dialog); +} + static void renumber_dialog(GtkWidget *w, gpointer data) { int result; @@ -475,6 +521,7 @@ static void about_dialog(GtkWidget *w, gpointer data) static GtkActionEntry menu_items[] = { { "FileMenuAction", GTK_STOCK_FILE, "File", NULL, NULL, NULL}, { "LogMenuAction", GTK_STOCK_FILE, "Log", NULL, NULL, NULL}, + { "FilterMenuAction", GTK_STOCK_FILE, "Filter", NULL, NULL, NULL}, { "HelpMenuAction", GTK_STOCK_HELP, "Help", NULL, NULL, NULL}, { "OpenFile", GTK_STOCK_OPEN, NULL, "O", NULL, G_CALLBACK(file_open) }, { "SaveFile", GTK_STOCK_SAVE, NULL, "S", NULL, G_CALLBACK(file_save) }, @@ -482,8 +529,9 @@ static GtkActionEntry menu_items[] = { { "Import", NULL, "Import", NULL, NULL, G_CALLBACK(import_dialog) }, { "Preferences", NULL, "Preferences", NULL, NULL, G_CALLBACK(preferences_dialog) }, { "Renumber", NULL, "Renumber", NULL, NULL, G_CALLBACK(renumber_dialog) }, + { "SelectEvents", NULL, "SelectEvents", NULL, NULL, G_CALLBACK(selectevents_dialog) }, { "Quit", GTK_STOCK_QUIT, NULL, "Q", NULL, G_CALLBACK(quit) }, - { "About", GTK_STOCK_ABOUT, NULL, NULL, NULL, G_CALLBACK(about_dialog) }, + { "About", GTK_STOCK_ABOUT, NULL, NULL, NULL, G_CALLBACK(about_dialog) }, }; static gint nmenu_items = sizeof (menu_items) / sizeof (menu_items[0]); @@ -504,6 +552,9 @@ static const gchar* ui_string = " \ \ \ \ + \ + \ + \ \ \ \ diff --git a/profile.c b/profile.c index 810c473..56716f5 100644 --- a/profile.c +++ b/profile.c @@ -174,6 +174,15 @@ static struct ev_select *ev_namelist; static int evn_allocated; static int evn_used; +void evn_foreach(void (*callback)(const char *, int *, void *), void *data) +{ + int i; + + for (i = 0; i < evn_used; i++) { + callback(ev_namelist[i].ev_name, &ev_namelist[i].plot_ev, data); + } +} + void remember_event(const char *eventname) { int i=0, len; -- 2.45.2