aboutsummaryrefslogtreecommitdiffstats
path: root/ui
diff options
context:
space:
mode:
authorGuy Harris <guy@alum.mit.edu>2012-06-28 08:13:21 +0000
committerGuy Harris <guy@alum.mit.edu>2012-06-28 08:13:21 +0000
commit5e7ca579ceeb21b355831bd2c5de6742e8e9a14b (patch)
tree29f58015c96ff0d14b989ca24a3771795d2737dc /ui
parent234628c616e21b5f0d45984cd67016e976491290 (diff)
Detangle the code that manages the interface list on the welcome screen:
fill_capture_box(): if there are interfaces on which to capture, constructs the interface list, otherwise destroys the interface list and puts up a message. update_capture_box(): updates the interface list to reflect current reality. welcome_if_panel_reload(): if there is an interface list, and if there are interfaces on which to capture (so that we still want that list), updates the list by calling update_capture_box(), otherwise creates or destroys it by calling fill_capture_box() (as either it doesn't exist but now needs to or does exist but needs to go away). Have refresh_local_interface_lists(), which re-fetches the list of local interfaces and updates every interface list that includes local interfaces, and refresh_non_local_interface_lists(), which only updates interface lists that (also) include interfaces other than local interfaces (such as pipes and remote interfaces). Call them in the apprpriate places (if we know the list of local interfaces has been updated, call refresh_local_interface_lists(), otherwise, if we know interfaces other than local interfaces have been added or removed, call refresh_non_local_interface_lists()). Don't have any routine that updates the interface list for one widget update the interface list for any other widget; leave the global updating of interface lists up to refresh_local_interface_lists() and refresh_non_local_interface_lists() - only call one of them if any interface lists are to be updated. svn path=/trunk/; revision=43517
Diffstat (limited to 'ui')
-rw-r--r--ui/gtk/capture_dlg.c87
-rw-r--r--ui/gtk/capture_dlg.h3
-rw-r--r--ui/gtk/capture_if_dlg.c2
-rw-r--r--ui/gtk/main.c57
-rw-r--r--ui/gtk/main.h17
-rw-r--r--ui/gtk/main_menubar.c2
-rw-r--r--ui/gtk/main_welcome.c91
-rw-r--r--ui/gtk/prefs_capture.c5
8 files changed, 132 insertions, 132 deletions
diff --git a/ui/gtk/capture_dlg.c b/ui/gtk/capture_dlg.c
index 65d7c639a8..7f0db36e35 100644
--- a/ui/gtk/capture_dlg.c
+++ b/ui/gtk/capture_dlg.c
@@ -1059,9 +1059,7 @@ update_interface_list(void)
} else if (iftype == CAPTURE_IFREMOTE) {
/* New remote interface */
insert_new_rows(if_list);
- if (interfaces_dialog_window_present()) {
- refresh_if_window();
- }
+ refresh_non_local_interface_lists();
}
}
@@ -1780,16 +1778,6 @@ update_options_table(gint index)
}
-void
-update_all_rows(void)
-{
- GtkTreeView *view;
-
- view = (GtkTreeView *) g_object_get_data(G_OBJECT(cap_open_w), E_CAP_IFACE_KEY);
- create_and_fill_model(GTK_TREE_VIEW(view));
-}
-
-
static void
save_options_cb(GtkWidget *win _U_, gpointer user_data _U_)
{
@@ -2612,12 +2600,7 @@ static void change_pipe_name_cb(gpointer dialog _U_, gint btn, gpointer data)
} else {
gtk_widget_set_sensitive(ok_bt, FALSE);
}
- if (interfaces_dialog_window_present()) {
- refresh_if_window();
- }
- if (get_welcome_window() != NULL) {
- change_interface_name(oldname, i);
- }
+ refresh_non_local_interface_lists();
break;
}
}
@@ -2737,12 +2720,12 @@ add_pipe_cb(gpointer w _U_)
} else {
gtk_widget_set_sensitive(ok_bt, FALSE);
}
- if (interfaces_dialog_window_present()) {
- refresh_if_window();
- }
- if (get_welcome_window() != NULL) {
- welcome_if_panel_reload ();
- }
+
+ /* Refresh all places that are displaying an interface list
+ that includes interfaces other than local interfaces
+ (such as pipes). */
+ refresh_non_local_interface_lists();
+
g_free(name);
}
}
@@ -2819,9 +2802,10 @@ pipe_del_bt_clicked_cb(GtkWidget *w _U_, gpointer data _U_)
gtk_widget_set_sensitive(name_te, FALSE);
}
- if (get_welcome_window() != NULL) {
- welcome_if_panel_reload();
- }
+ /* Refresh all places that are displaying an interface list
+ that includes interfaces other than local interfaces
+ (such as pipes). */
+ refresh_non_local_interface_lists();
}
static void
@@ -2983,33 +2967,30 @@ apply_local_cb(GtkWidget *win _U_, gpointer *data _U_)
prefs.capture_devices_hide = NULL;
}
hide_interface(g_strdup(new_hide));
- update_all_rows();
- if (interfaces_dialog_window_present()) {
- refresh_if_window();
- }
- if (get_welcome_window() != NULL) {
- welcome_if_panel_reload ();
- }
+
+ /* Refresh all places that are displaying an interface list
+ that includes local interfaces. */
+ refresh_local_interface_lists();
}
}
void
capture_dlg_refresh_if(void)
{
+ GtkTreeView *view;
+
fill_local_list();
- update_all_rows();
- if (interfaces_dialog_window_present()) {
- refresh_if_window();
- }
- if (get_welcome_window() != NULL) {
- welcome_if_panel_reload ();
- }
+
+ view = (GtkTreeView *) g_object_get_data(G_OBJECT(cap_open_w), E_CAP_IFACE_KEY);
+ create_and_fill_model(GTK_TREE_VIEW(view));
}
static void
rescan_local_cb(GtkWidget *button _U_, gpointer *data _U_)
{
- refresh_interfaces_cb();
+ /* Refresh all places that are displaying an interface list
+ that includes local interfaces. */
+ refresh_local_interface_lists();
}
#if defined(HAVE_PCAP_REMOTE)
@@ -3123,13 +3104,9 @@ ok_remote_cb(GtkWidget *win _U_, gpointer *data _U_)
g_free(name);
}
hide_interface(g_strdup(new_hide));
- update_all_rows();
- if (interfaces_dialog_window_present()) {
- refresh_if_window();
- }
- if (get_welcome_window() != NULL) {
- welcome_if_panel_reload ();
- }
+
+ /* Refresh all places that are displaying an interface list. */
+ refresh_interfaces_cb();
}
static gboolean
@@ -3186,13 +3163,9 @@ remove_remote_host(GtkWidget *w _U_, gpointer data _U_)
}
}
}
- update_all_rows();
- if (interfaces_dialog_window_present()) {
- refresh_if_window();
- }
- if (get_welcome_window() != NULL) {
- welcome_if_panel_reload ();
- }
+
+ /* Refresh all places that are displaying an interface list. */
+ refresh_interfaces_cb();
}
}
#endif
diff --git a/ui/gtk/capture_dlg.h b/ui/gtk/capture_dlg.h
index da6f7de0d5..ecd3365611 100644
--- a/ui/gtk/capture_dlg.h
+++ b/ui/gtk/capture_dlg.h
@@ -129,9 +129,6 @@ void
options_interface_cb(GtkTreeView *view, GtkTreePath *path, GtkTreeViewColumn *column _U_, gpointer userdata);
void
-update_all_rows(void);
-
-void
capture_dlg_refresh_if(void);
#endif /* capture_dlg.h */
diff --git a/ui/gtk/capture_if_dlg.c b/ui/gtk/capture_if_dlg.c
index fcc976d787..e319bbde7f 100644
--- a/ui/gtk/capture_if_dlg.c
+++ b/ui/gtk/capture_if_dlg.c
@@ -137,6 +137,7 @@ typedef struct if_dlg_data_s {
static gboolean gbl_capture_in_progress = FALSE;
+#if 0
void
add_interface(void)
{
@@ -155,6 +156,7 @@ add_interface(void)
g_array_append_val(if_array, data);
refresh_if_window();
}
+#endif
void
update_selected_interface(gchar *name)
diff --git a/ui/gtk/main.c b/ui/gtk/main.c
index ff5fd6f212..ff4b09e2f4 100644
--- a/ui/gtk/main.c
+++ b/ui/gtk/main.c
@@ -1134,25 +1134,41 @@ file_quit_cmd_cb(GtkWidget *widget _U_, gpointer data _U_)
#ifdef HAVE_LIBPCAP
/*
- * Refresh everything visible that shows an interface list.
+ * Refresh everything visible that shows an interface list that
+ * includes local interfaces.
*/
void
-refresh_interfaces_cb(void)
+refresh_local_interface_lists(void)
{
- /* Reload the interface list. */
+ /* Reload the local interface list. */
scan_local_interfaces(&global_capture_opts);
/* If there's an interfaces dialog up, refresh it. */
if (interfaces_dialog_window_present())
refresh_if_window();
- /* If there's a capture options dialog up, refresh it; doing
- so will also update the welcome screen, if it's up.
- Otherwise, if the welcome screen is up, refresh it. */
+ /* If there's a capture options dialog up, refresh it. */
if (capture_dlg_window_present())
- /* Will also update welcome panel */
capture_dlg_refresh_if();
- else if(get_welcome_window() != NULL)
+
+ /* If the welcome screen is up, refresh its interface list. */
+ if (get_welcome_window() != NULL)
+ welcome_if_panel_reload();
+}
+
+/*
+ * Refresh everything visible that shows an interface list that
+ * includes non-local interfaces.
+ */
+void
+refresh_non_local_interface_lists(void)
+{
+ /* If there's a capture options dialog up, refresh it. */
+ if (capture_dlg_window_present())
+ capture_dlg_refresh_if();
+
+ /* If the welcome screen is up, refresh its interface list. */
+ if (get_welcome_window() != NULL)
welcome_if_panel_reload();
}
#endif
@@ -2615,9 +2631,7 @@ main(int argc, char *argv[])
prefs_to_capture_opts();
/*#ifdef HAVE_LIBPCAP
- if (global_capture_opts.all_ifaces->len == 0) {
- scan_local_interfaces(&global_capture_opts);
- }
+ fill_in_local_interfaces(&global_capture_opts);
#endif*/
/* Now get our args */
while ((opt = getopt(argc, argv, optstring)) != -1) {
@@ -2861,11 +2875,7 @@ main(int argc, char *argv[])
}
#ifdef HAVE_LIBPCAP
- if (global_capture_opts.all_ifaces->len == 0) {
- scan_local_interfaces(&global_capture_opts);
- }
-#endif
-#ifdef HAVE_LIBPCAP
+ fill_in_local_interfaces(&global_capture_opts);
if (start_capture && list_link_layer_types) {
/* Specifying *both* is bogus. */
cmdarg_err("You can't specify both -L and a live capture.");
@@ -4378,6 +4388,21 @@ scan_local_interfaces(capture_options* capture_opts)
}
}
+/*
+ * Get the global interface list. Generate it if we haven't
+ * done so already.
+ */
+void
+fill_in_local_interfaces(capture_options* capture_opts)
+{
+ static gboolean initialized = FALSE;
+
+ if (!initialized) {
+ scan_local_interfaces(capture_opts);
+ initialized = TRUE;
+ }
+}
+
void hide_interface(gchar* new_hide)
{
gchar *tok;
diff --git a/ui/gtk/main.h b/ui/gtk/main.h
index c8f6f4630e..cf45bb73c6 100644
--- a/ui/gtk/main.h
+++ b/ui/gtk/main.h
@@ -376,9 +376,16 @@ extern GtkWidget *pkt_scrollw;
#ifdef HAVE_LIBPCAP
/*
- * Refresh everything visible that shows an interface list.
+ * Refresh everything visible that shows an interface list that
+ * includes local interfaces.
*/
-extern void refresh_interfaces_cb(void);
+extern void refresh_local_interface_lists(void);
+
+/*
+ * Refresh everything visible that shows an interface list that
+ * includes non-local interfaces.
+ */
+extern void refresh_non_local_interface_lists(void);
#endif
void hide_interface(gchar* new_hide);
@@ -391,4 +398,10 @@ void hide_interface(gchar* new_hide);
*/
extern void scan_local_interfaces(capture_options* capture_opts);
+/*
+ * Get the global interface list. Generate it if we haven't
+ * done so already.
+ */
+extern void fill_in_local_interfaces(capture_options* capture_opts);
+
#endif /* __MAIN_H__ */
diff --git a/ui/gtk/main_menubar.c b/ui/gtk/main_menubar.c
index c5f1438d2a..2488ccf2d5 100644
--- a/ui/gtk/main_menubar.c
+++ b/ui/gtk/main_menubar.c
@@ -885,7 +885,7 @@ capture_cb(GtkAction *action _U_, gpointer user_data _U_)
cfilter_dialog_cb(NULL /* GtkWidget *w _U_ */);
return;
}else if(strcmp(name, "RefreshInterfaces") == 0){
- refresh_interfaces_cb();
+ refresh_local_interface_lists();
return;
}
diff --git a/ui/gtk/main_welcome.c b/ui/gtk/main_welcome.c
index 326662ab63..8ea1ed32a2 100644
--- a/ui/gtk/main_welcome.c
+++ b/ui/gtk/main_welcome.c
@@ -113,7 +113,6 @@ static void capture_if_start(GtkWidget *w _U_, gpointer data _U_);
#if GTK_CHECK_VERSION(2,18,0)
static gboolean activate_link_cb(GtkLabel *label _U_, gchar *uri, gpointer user_data _U_);
#endif
-static void welcome_if_tree_load(void);
#endif
/* The "scroll box dynamic" is a (complicated) pseudo widget to */
@@ -927,6 +926,36 @@ clear_capture_box(void)
}
}
+static void
+update_capture_box(void)
+{
+ guint i;
+ GtkListStore *store = NULL;
+ GtkTreeIter iter;
+ GtkTreeSelection *entry;
+ interface_t device;
+ gboolean changed = FALSE;
+
+ entry = gtk_tree_view_get_selection(GTK_TREE_VIEW(if_view));
+ gtk_tree_selection_unselect_all(GTK_TREE_SELECTION(entry));
+ store = gtk_list_store_new(NUMCOLUMNS, GDK_TYPE_PIXBUF, G_TYPE_STRING, G_TYPE_STRING);
+
+ gtk_list_store_clear(store);
+ gtk_tree_view_set_model(GTK_TREE_VIEW(if_view), GTK_TREE_MODEL (store));
+ for (i = 0; i < global_capture_opts.all_ifaces->len; i++) {
+ device = g_array_index(global_capture_opts.all_ifaces, interface_t, i);
+ if (!device.hidden) {
+ gtk_list_store_append (store, &iter);
+ gtk_list_store_set (store, &iter, ICON, gtk_image_get_pixbuf(GTK_IMAGE(capture_get_if_icon(&device))), IFACE_DESCR, device.display_name, IFACE_NAME, device.name, -1);
+ if (device.selected) {
+ gtk_tree_selection_select_iter(entry, &iter);
+ }
+ }
+ }
+ changed = TRUE;
+ gtk_tree_selection_set_select_function(GTK_TREE_SELECTION(entry), on_selection_changed, (gpointer)&changed, NULL);
+}
+
static void fill_capture_box(void)
{
GtkWidget *box_to_fill;
@@ -991,7 +1020,7 @@ static void fill_capture_box(void)
"Same as Capture/Interfaces with default options",
(welcome_button_callback_t)capture_if_start, (gpointer)if_view);
gtk_box_pack_start(GTK_BOX(box_to_fill), item_hb_start, FALSE, FALSE, 5);
- welcome_if_tree_load();
+ update_capture_box();
gtk_container_add (GTK_CONTAINER (swindow), if_view);
gtk_container_add(GTK_CONTAINER(box_to_fill), swindow);
g_object_set_data(G_OBJECT(welcome_hb), CAPTURE_HB_BOX_START, item_hb_start);
@@ -1090,54 +1119,6 @@ static void fill_capture_box(void)
g_object_set_data(G_OBJECT(welcome_hb), CAPTURE_LABEL, w);
}
}
-#endif
-
-#ifdef HAVE_LIBPCAP
-/* list the interfaces */
-static void
-welcome_if_tree_load(void)
-{
- guint i;
- GtkListStore *store = NULL;
- GtkTreeIter iter;
- GtkTreeSelection *entry;
- interface_t device;
- gboolean changed = FALSE;
-
- if (if_view && swindow) {
- entry = gtk_tree_view_get_selection(GTK_TREE_VIEW(if_view));
- gtk_tree_selection_unselect_all(GTK_TREE_SELECTION(entry));
- store = gtk_list_store_new(NUMCOLUMNS, GDK_TYPE_PIXBUF, G_TYPE_STRING, G_TYPE_STRING);
-
- gtk_list_store_clear(store);
- gtk_tree_view_set_model(GTK_TREE_VIEW(if_view), GTK_TREE_MODEL (store));
- /* LOAD THE INTERFACES */
- if (global_capture_opts.all_ifaces->len == 0) {
- scan_local_interfaces(&global_capture_opts);
- if (global_capture_opts.all_ifaces->len == 0) {
- fill_capture_box();
- }
- } else {
- for (i = 0; i < global_capture_opts.all_ifaces->len; i++) {
- device = g_array_index(global_capture_opts.all_ifaces, interface_t, i);
- if (!device.hidden) {
- gtk_list_store_append (store, &iter);
- gtk_list_store_set (store, &iter, ICON, gtk_image_get_pixbuf(GTK_IMAGE(capture_get_if_icon(&device))), IFACE_DESCR, device.display_name, IFACE_NAME, device.name, -1);
- if (device.selected) {
- gtk_tree_selection_select_iter(entry, &iter);
- }
- }
- }
- changed = TRUE;
- gtk_tree_selection_set_select_function(GTK_TREE_SELECTION(entry), on_selection_changed, (gpointer)&changed, NULL);
- if (gtk_widget_is_focus(GTK_WIDGET(if_view)) && capture_dlg_window_present()) {
- update_all_rows();
- }
- }
- } else {
- fill_capture_box();
- }
-}
#endif /* HAVE_LIBPCAP */
@@ -1147,7 +1128,15 @@ welcome_if_panel_reload(void)
{
#ifdef HAVE_LIBPCAP
if (welcome_hb) {
- welcome_if_tree_load();
+ /* If we have a list of interfaces, and if the current interface
+ list is non-empty, just update the interface list. Otherwise,
+ create it (as we didn't have it) or destroy it (as we won't
+ have it). */
+ if (if_view && swindow && global_capture_opts.all_ifaces->len > 0) {
+ update_capture_box();
+ } else {
+ fill_capture_box();
+ }
gtk_widget_show_all(welcome_hb);
}
#endif /* HAVE_LIBPCAP */
diff --git a/ui/gtk/prefs_capture.c b/ui/gtk/prefs_capture.c
index e300e2f653..1dda51c06e 100644
--- a/ui/gtk/prefs_capture.c
+++ b/ui/gtk/prefs_capture.c
@@ -620,8 +620,9 @@ ifopts_edit_ok_cb(GtkWidget *w _U_, gpointer parent_w)
ifopts_write_new_hide();
}
- /* Update welcome page */
- welcome_if_panel_reload ();
+ /* Update everything that shows an interface list that includes
+ local interfaces. */
+ refresh_local_interface_lists();
/* Now nuke this window. */
gtk_grab_remove(GTK_WIDGET(parent_w));