diff options
Diffstat (limited to 'ui/gtk/main_welcome.c')
-rw-r--r-- | ui/gtk/main_welcome.c | 61 |
1 files changed, 47 insertions, 14 deletions
diff --git a/ui/gtk/main_welcome.c b/ui/gtk/main_welcome.c index 4bd3b90569..33557a8bea 100644 --- a/ui/gtk/main_welcome.c +++ b/ui/gtk/main_welcome.c @@ -102,8 +102,8 @@ static GdkColor topic_item_entered_bg = { 0, 0xd3d3, 0xd8d8, 0xdada }; #endif static GtkWidget *welcome_file_panel_vb = NULL; #ifdef HAVE_LIBPCAP -static GtkWidget *if_view = NULL; -static GtkWidget *swindow; +static GtkWidget *if_view = NULL; /* contains a view (list) of all the interfaces */ +static GtkWidget *if_scrolled_window; /* a scrolled window that contains the if_view */ #endif static GSList *status_messages = NULL; @@ -834,7 +834,7 @@ select_ifaces(void) GtkTreeModel *model; GtkTreeSelection *entry; - if (global_capture_opts.num_selected > 0 && swindow) { + if (global_capture_opts.num_selected > 0 && if_scrolled_window) { view = g_object_get_data(G_OBJECT(welcome_hb), TREE_VIEW_INTERFACES); model = gtk_tree_view_get_model(GTK_TREE_VIEW(view)); entry = gtk_tree_view_get_selection(GTK_TREE_VIEW(view)); @@ -922,13 +922,42 @@ clear_capture_box(void) if (item_hb) { gtk_widget_destroy(item_hb); } - if (swindow) { - gtk_widget_destroy(swindow); - swindow = NULL; + if (if_scrolled_window) { + gtk_widget_destroy(if_scrolled_window); + if_scrolled_window = NULL; if_view = NULL; } } +static void update_interface_scrolled_window_height(void) +{ + /* set the height of the scroll window that shows the interfaces + * based on the number of visible interfaces - up to a maximum of 10 interfaces */ + guint i; + interface_t device; + int visible_interface_count=0; + + if(if_scrolled_window==NULL){ + return; + } + + 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) { + visible_interface_count++; + } + } + if(visible_interface_count>10){ + /* up to 10 interfaces will be visible at one time */ + visible_interface_count=10; + } + if(visible_interface_count<2){ + /* minimum space for two interfaces */ + visible_interface_count=2; + } + gtk_widget_set_size_request(if_scrolled_window, FALSE, visible_interface_count*21+4); +} + static void update_capture_box(void) { @@ -943,7 +972,7 @@ update_capture_box(void) 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_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); @@ -955,6 +984,7 @@ update_capture_box(void) } } } + update_interface_scrolled_window_height(); changed = TRUE; gtk_tree_selection_set_select_function(GTK_TREE_SELECTION(entry), on_selection_changed, (gpointer)&changed, NULL); } @@ -993,10 +1023,10 @@ static void fill_capture_box(void) "Same as Capture/Interfaces menu or toolbar item", welcome_button_callback_helper, capture_if_cb); gtk_box_pack_start(GTK_BOX(box_to_fill), item_hb_interface_list, FALSE, FALSE, 5); - swindow = gtk_scrolled_window_new (NULL, NULL); - gtk_widget_set_size_request(swindow, FALSE, 100); - gtk_scrolled_window_set_shadow_type(GTK_SCROLLED_WINDOW(swindow), GTK_SHADOW_IN); - gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(swindow), GTK_POLICY_AUTOMATIC, GTK_POLICY_AUTOMATIC); + if_scrolled_window = gtk_scrolled_window_new (NULL, NULL); + update_interface_scrolled_window_height(); + gtk_scrolled_window_set_shadow_type(GTK_SCROLLED_WINDOW(if_scrolled_window), GTK_SHADOW_IN); + gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(if_scrolled_window), GTK_POLICY_AUTOMATIC, GTK_POLICY_AUTOMATIC); g_object_set_data(G_OBJECT(welcome_hb), CAPTURE_HB_BOX_INTERFACE_LIST, item_hb_interface_list); if_view = gtk_tree_view_new (); @@ -1028,8 +1058,8 @@ static void fill_capture_box(void) (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); update_capture_box(); - gtk_container_add (GTK_CONTAINER (swindow), if_view); - gtk_container_add(GTK_CONTAINER(box_to_fill), swindow); + gtk_container_add (GTK_CONTAINER (if_scrolled_window), if_view); + gtk_container_add(GTK_CONTAINER(box_to_fill), if_scrolled_window); g_object_set_data(G_OBJECT(welcome_hb), CAPTURE_HB_BOX_START, item_hb_start); item_hb_capture = welcome_button(WIRESHARK_STOCK_CAPTURE_OPTIONS, @@ -1057,6 +1087,9 @@ static void fill_capture_box(void) if (if_view) { clear_capture_box(); } + + /* run capture_interface_list(), not to get the interfaces, but to detect + * any errors, if there is an error, display an appropriate message in the gui */ capture_interface_list(&error, &err_str); switch (error) { @@ -1148,7 +1181,7 @@ welcome_if_panel_reload(void) 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) { + if (if_view && if_scrolled_window && global_capture_opts.all_ifaces->len > 0) { update_capture_box(); } else { GtkWidget *item_hb; |