From: tuexen Date: Wed, 20 Jul 2011 12:51:57 +0000 (+0000) Subject: Synchronize the selection of interfaces between the main welcome X-Git-Url: http://git.samba.org/samba.git/?p=obnox%2Fwireshark%2Fwip.git;a=commitdiff_plain;h=1c8f4c4a6482dc1e7eed0e5704735a04fc20cb0a Synchronize the selection of interfaces between the main welcome window, the capture/interface dialog box and the capture / start menu item. Obtained from Irene Ruengeler. git-svn-id: http://anonsvn.wireshark.org/wireshark/trunk@38133 f5534014-38df-0310-8fa8-9805f1628bb7 --- diff --git a/gtk/capture_dlg.c b/gtk/capture_dlg.c index f57bc9834b..bc679ec46b 100644 --- a/gtk/capture_dlg.c +++ b/gtk/capture_dlg.c @@ -2689,7 +2689,7 @@ capture_start_cb(GtkWidget *w _U_, gpointer d _U_) #endif if (get_interfaces_dialog_window()) { - window_destroy(get_interfaces_dialog_window()); + window_destroy(GTK_WIDGET(get_interfaces_dialog_window())); } if (cap_open_w) { diff --git a/gtk/capture_if_dlg.c b/gtk/capture_if_dlg.c index 68aff3513c..067f27460d 100644 --- a/gtk/capture_if_dlg.c +++ b/gtk/capture_if_dlg.c @@ -66,6 +66,7 @@ #include "gtk/webbrowser.h" #include "gtk/capture_globals.h" #include "gtk/network_icons.h" +#include "gtk/main_welcome.h" #ifdef HAVE_AIRPCAP #include "../image/toolbar/capture_airpcap_16.xpm" @@ -136,8 +137,29 @@ typedef struct if_dlg_data_s { static gboolean gbl_capture_in_progress = FALSE; +void +update_selected_interface(gchar *name, gboolean activate) +{ + guint ifs; + GList *curr; + if_dlg_data_t *temp; + + for (ifs = 0; ifs < g_list_length(if_data_list); ifs++) { + curr = g_list_nth(if_data_list, ifs); + temp = (if_dlg_data_t *)(curr->data); + if (strcmp(name, temp->if_info.name) == 0) { + if (activate) { + gtk_toggle_button_set_active((GtkToggleButton *)temp->choose_bt, TRUE); + } else { + gtk_toggle_button_set_active((GtkToggleButton *)temp->choose_bt, FALSE); + } + break; + } + } +} + static void -store_selected(GtkWidget *choose_bt _U_, gpointer if_data) +store_selected(GtkWidget *choose_bt, gpointer if_data) { if_dlg_data_t *if_dlg_data = if_data, *temp; GList *curr; @@ -161,6 +183,9 @@ store_selected(GtkWidget *choose_bt _U_, gpointer if_data) if (!temp->selected) { interface_opts = g_array_index(global_capture_opts.ifaces, interface_options, i); global_capture_opts.ifaces = g_array_remove_index(global_capture_opts.ifaces, i); + if (gtk_widget_is_focus(choose_bt) && get_welcome_window()) { + change_interface_selection(interface_opts.name, FALSE); + } g_free(interface_opts.name); g_free(interface_opts.descr); g_free(interface_opts.cfilter); @@ -203,6 +228,9 @@ store_selected(GtkWidget *choose_bt _U_, gpointer if_data) interface_opts.sampling_param = global_capture_opts.default_options.sampling_param; #endif g_array_append_val(global_capture_opts.ifaces, interface_opts); + if (gtk_widget_is_focus(choose_bt) && get_welcome_window() != NULL) { + change_interface_selection(g_strdup(temp->if_info.name), TRUE); + } } if (temp->selected) diff --git a/gtk/capture_if_dlg.h b/gtk/capture_if_dlg.h index 12f5509eef..5ffc747a2d 100644 --- a/gtk/capture_if_dlg.h +++ b/gtk/capture_if_dlg.h @@ -50,6 +50,9 @@ capture_if_cb(GtkWidget *widget, gpointer data); GtkWidget * capture_get_if_icon(const if_info_t* if_info); +void +update_selected_interface(gchar *name, gboolean activate); + GtkWidget * get_interfaces_dialog_window(void); diff --git a/gtk/main_welcome.c b/gtk/main_welcome.c index 7b181cecaa..a47ae9e203 100644 --- a/gtk/main_welcome.c +++ b/gtk/main_welcome.c @@ -676,7 +676,7 @@ main_welcome_add_recent_capture_file(const char *widget_cf_name, GObject *menu_i #ifdef HAVE_LIBPCAP static gboolean select_current_ifaces(GtkTreeModel *model, - GtkTreePath *path _U_, + GtkTreePath *path, GtkTreeIter *iter, gpointer userdata) { @@ -688,7 +688,9 @@ static gboolean select_current_ifaces(GtkTreeModel *model, gtk_tree_model_get (model, iter, IFACE_NAME, &if_name, -1); for (i = 0; i < global_capture_opts.ifaces->len; i++) { if (strcmp(g_array_index(global_capture_opts.ifaces, interface_options, i).name, if_name) == 0) { - gtk_tree_selection_select_iter(selection, iter); + if (!gtk_tree_selection_path_is_selected(selection, path)) { + gtk_tree_selection_select_iter(selection, iter); + } found = TRUE; break; } @@ -711,7 +713,7 @@ gboolean on_selection_changed(GtkTreeSelection *selection _U_, guint i; cap_settings_t cap_settings; gboolean found = FALSE; - + gtk_tree_model_get_iter (model, &iter, path); gtk_tree_model_get (model, &iter, IFACE_NAME, &if_name, -1); for (i = 0; i < global_capture_opts.ifaces->len; i++) { @@ -720,6 +722,9 @@ gboolean on_selection_changed(GtkTreeSelection *selection _U_, if (path_currently_selected) { interface_opts = g_array_index(global_capture_opts.ifaces, interface_options, i); global_capture_opts.ifaces = g_array_remove_index(global_capture_opts.ifaces, i); + if (gtk_widget_is_focus(g_object_get_data(G_OBJECT(welcome_hb), TREE_VIEW_INTERFACES)) && get_interfaces_dialog_window()) { + update_selected_interface(strdup(interface_opts.name), FALSE); + } g_free(interface_opts.name); g_free(interface_opts.descr); g_free(interface_opts.cfilter); @@ -762,8 +767,48 @@ gboolean on_selection_changed(GtkTreeSelection *selection _U_, interface_opts.sampling_param = global_capture_opts.default_options.sampling_param; #endif g_array_append_val(global_capture_opts.ifaces, interface_opts); + if (gtk_widget_is_focus(g_object_get_data(G_OBJECT(welcome_hb), TREE_VIEW_INTERFACES)) && get_interfaces_dialog_window()) { + update_selected_interface(strdup(interface_opts.name), TRUE); + } + } + return TRUE; +} + +static gboolean activate_ifaces(GtkTreeModel *model, + GtkTreePath *path _U_, + GtkTreeIter *iter, + gpointer userdata) +{ + gchar *if_name; + GtkWidget *view; + GtkTreeSelection *selection; + selected_name_t *entry = (selected_name_t *)userdata; + + view = g_object_get_data(G_OBJECT(welcome_hb), TREE_VIEW_INTERFACES); + selection = gtk_tree_view_get_selection(GTK_TREE_VIEW(view)); + gtk_tree_model_get (model, iter, IFACE_NAME, &if_name, -1); + if (strcmp(if_name, entry->name) == 0) { + if (entry->activate) { + gtk_tree_selection_select_iter(selection, iter); + } else { + gtk_tree_selection_unselect_iter(selection, iter); } return TRUE; + } + return FALSE; +} + +void change_interface_selection(gchar* name, gboolean activate) +{ + GtkWidget *view; + GtkTreeModel *model; + selected_name_t entry; + + view = g_object_get_data(G_OBJECT(welcome_hb), TREE_VIEW_INTERFACES); + model = gtk_tree_view_get_model(GTK_TREE_VIEW(view)); + entry.name = strdup(name); + entry.activate = activate; + gtk_tree_model_foreach(GTK_TREE_MODEL(model), (GtkTreeModelForeachFunc)(activate_ifaces), (gpointer) &entry); } #endif @@ -869,7 +914,6 @@ welcome_if_panel_reload(void) GList* child_list; GList* child_list_item; - if(welcome_if_panel_vb) { child_box = scroll_box_dynamic_reset(welcome_if_panel_vb); child_list = gtk_container_get_children(GTK_CONTAINER(child_box)); @@ -1223,3 +1267,9 @@ welcome_new(void) return welcome_scrollw; } + +GtkWidget* get_welcome_window(void) +{ + return welcome_hb; +} + diff --git a/gtk/main_welcome.h b/gtk/main_welcome.h index daec47cb30..b7da8adff4 100644 --- a/gtk/main_welcome.h +++ b/gtk/main_welcome.h @@ -33,6 +33,10 @@ enum NUMCOLUMNS }; +typedef struct selected_name_s { + gchar *name; + gboolean activate; +} selected_name_t; GtkWidget *welcome_new(void); /* reset the list of recently used files */ @@ -63,4 +67,8 @@ void welcome_header_pop_msg(void); void select_ifaces(void); +GtkWidget* get_welcome_window(void); + +void change_interface_selection(gchar* name, gboolean activate); + #endif /* __MAIN_WELCOME_H__ */