Add support for multiple interface to the main welcome screen.

This patch is from Irene Ruengeler.

svn path=/trunk/; revision=37913
This commit is contained in:
Michael Tüxen 2011-07-06 09:17:06 +00:00
parent 859aadfd5f
commit 48683778a0
3 changed files with 191 additions and 199 deletions

View File

@ -3457,6 +3457,7 @@ main_widgets_show_or_hide(void)
if (!have_capture_file) {
if(welcome_pane) {
gtk_widget_show(welcome_pane);
welcome_if_tree_load();
}
} else {
gtk_widget_hide(welcome_pane);

View File

@ -90,6 +90,7 @@ static GdkColor topic_item_entered_bg = { 0, 0xd3d3, 0xd8d8, 0xdada };
static GtkWidget *welcome_file_panel_vb = NULL;
#ifdef HAVE_LIBPCAP
static GtkWidget *welcome_if_panel_vb = NULL;
static GtkWidget *if_view = NULL;
#endif
static GSList *status_messages = NULL;
@ -105,10 +106,10 @@ static GSList *status_messages = NULL;
#define SCROLL_BOX_MAX_CHILDS "ScrollBoxDynamic_MaxChilds"
#define SCROLL_BOX_SCROLLW_Y_SIZE "ScrollBoxDynamic_Scrollw_Y_Size"
#define SCROLL_BOX_SCROLLW "ScrollBoxDynamic_Scrollw"
#define TREE_VIEW_INTERFACES "TreeViewInterfaces"
static GtkWidget *
scroll_box_dynamic_new(GtkBox *child_box, guint max_childs, guint scrollw_y_size) {
scroll_box_dynamic_new(GtkWidget *child_box, guint max_childs, guint scrollw_y_size) {
GtkWidget * parent_box;
@ -331,7 +332,6 @@ welcome_header_new(void)
header_lb = gtk_label_new(NULL);
welcome_header_set_message(NULL);
gtk_label_set_selectable (GTK_LABEL(header_lb),TRUE);
gtk_misc_set_alignment (GTK_MISC(header_lb), 0.0f, 0.5f);
gtk_box_pack_start(GTK_BOX(item_hb), header_lb, TRUE, TRUE, 5);
@ -565,131 +565,19 @@ main_welcome_add_recent_capture_files(const char *widget_cf_name)
#ifdef HAVE_LIBPCAP
/* user clicked on an interface button */
static gboolean
welcome_if_press_cb(GtkWidget *widget _U_, GdkEventButton *event _U_, gpointer data)
/* list the interfaces */
void
welcome_if_tree_load(void)
{
cap_settings_t cap_settings;
interface_options interface_opts;
while (global_capture_opts.ifaces->len > 0) {
interface_opts = g_array_index(global_capture_opts.ifaces, interface_options, 0);
global_capture_opts.ifaces = g_array_remove_index(global_capture_opts.ifaces, 0);
g_free(interface_opts.name);
g_free(interface_opts.descr);
g_free(interface_opts.cfilter);
#ifdef HAVE_PCAP_REMOTE
g_free(interface_opts.remote_host);
g_free(interface_opts.remote_port);
g_free(interface_opts.auth_username);
g_free(interface_opts.auth_password);
#endif
}
/* XXX - fix this */
/*global_capture_opts.iface_descr = get_interface_descriptive_name(global_capture_opts.iface);*/
interface_opts.name = g_strdup(data);
interface_opts.descr = NULL;
cap_settings = capture_get_cap_settings(interface_opts.name);
interface_opts.monitor_mode = cap_settings.monitor_mode;
interface_opts.linktype = cap_settings.linktype;
interface_opts.cfilter = g_strdup(global_capture_opts.default_options.cfilter);
interface_opts.snaplen = global_capture_opts.default_options.snaplen;
interface_opts.has_snaplen = global_capture_opts.default_options.has_snaplen;
interface_opts.promisc_mode = global_capture_opts.default_options.promisc_mode;
#if defined(_WIN32) || defined(HAVE_PCAP_CREATE)
interface_opts.buffer_size = global_capture_opts.default_options.buffer_size;
#endif
#ifdef HAVE_PCAP_REMOTE
interface_opts.src_type = global_capture_opts.default_options.src_type;
interface_opts.remote_host = g_strdup(global_capture_opts.default_options.remote_host);
interface_opts.remote_port = g_strdup(global_capture_opts.default_options.remote_port);
interface_opts.auth_type = global_capture_opts.default_options.auth_type;
interface_opts.auth_username = g_strdup(global_capture_opts.default_options.auth_username);
interface_opts.auth_password = g_strdup(global_capture_opts.default_options.auth_password);
interface_opts.datatx_udp = global_capture_opts.default_options.datatx_udp;
interface_opts.nocap_rpcap = global_capture_opts.default_options.nocap_rpcap;
interface_opts.nocap_local = global_capture_opts.default_options.nocap_local;
#endif
#ifdef HAVE_PCAP_SETSAMPLING
interface_opts.sampling_method = global_capture_opts.default_options.sampling_method;
interface_opts.sampling_param = global_capture_opts.default_options.sampling_param;
#endif
/* XXX - remove this? */
if (global_capture_opts.save_file) {
g_free(global_capture_opts.save_file);
global_capture_opts.save_file = NULL;
}
#ifdef HAVE_AIRPCAP
airpcap_if_active = get_airpcap_if_from_name(airpcap_if_list, interface_opts.name);
airpcap_if_selected = airpcap_if_active;
airpcap_set_toolbar_start_capture(airpcap_if_active);
#endif
g_array_append_val(global_capture_opts.ifaces, interface_opts);
capture_start_cb(NULL, NULL);
return FALSE;
}
/* create a single interface entry */
static GtkWidget *
welcome_if_new(const if_info_t *if_info, const gchar *user_descr, GdkColor *topic_bg _U_, gpointer interf)
{
GtkWidget *interface_hb;
GtkWidget *w;
GString *message;
GtkWidget *eb;
/* event box */
eb = gtk_event_box_new();
gtk_widget_modify_bg(eb, GTK_STATE_NORMAL, &topic_item_idle_bg);
g_signal_connect(eb, "enter-notify-event", G_CALLBACK(welcome_item_enter_cb), NULL);
g_signal_connect(eb, "leave-notify-event", G_CALLBACK(welcome_item_leave_cb), NULL);
g_signal_connect(eb, "button-press-event", G_CALLBACK(welcome_if_press_cb), interf);
interface_hb = gtk_hbox_new(FALSE, 5);
gtk_container_add(GTK_CONTAINER(eb), interface_hb);
/* icon */
w = capture_get_if_icon(if_info);
gtk_box_pack_start(GTK_BOX(interface_hb), w, FALSE, FALSE, 5);
if (user_descr != NULL)
message = g_string_new(user_descr);
else if (if_info->description != NULL)
message = g_string_new(if_info->description);
else
message = g_string_new(if_info->name);
/* truncate string if it's too long */
/* (the number of chars is a bit arbitrary, though) */
if(message->len > 48) {
g_string_truncate(message, 45);
g_string_append (message, " ...");
}
g_string_prepend(message, "<span foreground='blue'>");
g_string_append (message, "</span>");
w = gtk_label_new(message->str);
gtk_label_set_markup(GTK_LABEL(w), message->str);
g_string_free(message, TRUE);
gtk_misc_set_alignment (GTK_MISC(w), 0.0f, 0.0f);
gtk_box_pack_start(GTK_BOX(interface_hb), w, FALSE, FALSE, 0);
return eb;
}
/* load the sorted list of interfaces */
static GList *
welcome_if_panel_get_if_list(void)
{
GList *if_list;
if_info_t *if_info;
GList *if_list;
int err;
gchar *err_str = NULL;
gchar *err_str = NULL;
int ifs;
GList *curr;
gchar *user_descr;
GtkListStore *store;
GtkTreeIter iter;
/* LOAD THE INTERFACES */
if_list = capture_interface_list(&err, &err_str);
@ -697,51 +585,38 @@ welcome_if_panel_get_if_list(void)
if (if_list == NULL && err == CANT_GET_INTERFACE_LIST) {
simple_dialog(ESD_TYPE_ERROR, ESD_BTN_OK, "%s", err_str);
g_free(err_str);
return;
} else if (err_str) {
g_free(err_str);
}
return if_list;
}
if (g_list_length(if_list) > 0) {
store = gtk_list_store_new(1, G_TYPE_STRING);
/* List the interfaces */
for(ifs = 0; (curr = g_list_nth(if_list, ifs)); ifs++) {
/*g_string_assign(if_tool_str, "");*/
if_info = curr->data;
gtk_list_store_append (store, &iter);
/* Continue if capture device is hidden */
if (prefs_is_capture_device_hidden(if_info->name)) {
continue;
}
/* list the interfaces */
static void
welcome_if_panel_list(GList *if_list)
{
GtkWidget *child_box;
GtkWidget *interface_hb;
if_info_t *if_info;
int ifs;
GList *curr;
gchar *user_descr;
/* List the interfaces */
for(ifs = 0; (curr = g_list_nth(if_list, ifs)); ifs++) {
/*g_string_assign(if_tool_str, "");*/
if_info = curr->data;
/* Continue if capture device is hidden */
if (prefs_is_capture_device_hidden(if_info->name)) {
continue;
}
user_descr = capture_dev_user_descr_find(if_info->name);
if (user_descr) {
user_descr = capture_dev_user_descr_find(if_info->name);
if (user_descr) {
#ifndef _WIN32
gchar *comment = user_descr;
user_descr = g_strdup_printf("%s (%s)", comment, if_info->name);
g_free (comment);
gchar *comment = user_descr;
user_descr = g_strdup_printf("%s (%s)", comment, if_info->name);
g_free (comment);
#endif
interface_hb = welcome_if_new(if_info, user_descr, &topic_content_bg, g_strdup(if_info->name));
g_free (user_descr);
} else {
interface_hb = welcome_if_new(if_info, NULL, &topic_content_bg, g_strdup(if_info->name));
gtk_list_store_set(store, &iter, 0, if_info->name, -1);
g_free (user_descr);
} else {
gtk_list_store_set (store, &iter, 0, if_info->name, -1);
}
}
child_box = scroll_box_dynamic_add(welcome_if_panel_vb);
gtk_box_pack_start(GTK_BOX(child_box), interface_hb, FALSE, FALSE, 1);
gtk_tree_view_set_model(GTK_TREE_VIEW(if_view), GTK_TREE_MODEL (store));
}
free_interface_list(if_list);
}
#endif /* HAVE_LIBPCAP */
@ -757,7 +632,6 @@ welcome_if_panel_reload(void)
if(welcome_if_panel_vb) {
GList *if_list;
child_box = scroll_box_dynamic_reset(welcome_if_panel_vb);
child_list = gtk_container_get_children(GTK_CONTAINER(child_box));
child_list_item = child_list;
@ -768,16 +642,116 @@ welcome_if_panel_reload(void)
}
g_list_free(child_list);
if_list = welcome_if_panel_get_if_list();
welcome_if_panel_list(if_list);
free_interface_list(if_list);
welcome_if_tree_load();
gtk_widget_show_all(welcome_if_panel_vb);
}
#endif /* HAVE_LIBPCAP */
}
static void make_selections_array(GtkTreeModel *model,
GtkTreePath *path _U_,
GtkTreeIter *iter,
gpointer userdata _U_)
{
gchar *if_name;
interface_options interface_opts;
cap_settings_t cap_settings;
gtk_tree_model_get (model, iter, 0, &if_name, -1);
interface_opts.name = g_strdup(if_name);
interface_opts.descr = get_interface_descriptive_name(interface_opts.name);
interface_opts.linktype = capture_dev_user_linktype_find(interface_opts.name);
interface_opts.cfilter = g_strdup(global_capture_opts.default_options.cfilter);
interface_opts.has_snaplen = global_capture_opts.default_options.has_snaplen;
interface_opts.snaplen = global_capture_opts.default_options.snaplen;
cap_settings = capture_get_cap_settings (interface_opts.name);;
interface_opts.promisc_mode = global_capture_opts.default_options.promisc_mode;
interface_opts.buffer_size = global_capture_opts.default_options.buffer_size;
interface_opts.monitor_mode = cap_settings.monitor_mode;
#ifdef HAVE_PCAP_REMOTE
interface_opts.src_type = global_capture_opts.default_options.src_type;
interface_opts.remote_host = g_strdup(global_capture_opts.default_options.remote_host);
interface_opts.remote_port = g_strdup(global_capture_opts.default_options.remote_port);
interface_opts.auth_type = global_capture_opts.default_options.auth_type;
interface_opts.auth_username = g_strdup(global_capture_opts.default_options.auth_username);
interface_opts.auth_password = g_strdup(global_capture_opts.default_options.auth_password);
interface_opts.datatx_udp = global_capture_opts.default_options.datatx_udp;
interface_opts.nocap_rpcap = global_capture_opts.default_options.nocap_rpcap;
interface_opts.nocap_local = global_capture_opts.default_options.nocap_local;
#endif
#ifdef HAVE_PCAP_SETSAMPLING
interface_opts.sampling_method = global_capture_opts.default_options.sampling_method;
interface_opts.sampling_param = global_capture_opts.default_options.sampling_param;
#endif
g_array_append_val(global_capture_opts.ifaces, interface_opts);
}
static void capture_if_start(GtkWidget *w _U_, gpointer data _U_)
{
GtkTreeSelection *entry;
GtkWidget* view;
gint len;
interface_options interface_opts;
view = g_object_get_data(G_OBJECT(welcome_hb), TREE_VIEW_INTERFACES);
entry = gtk_tree_view_get_selection(GTK_TREE_VIEW(view));
len = gtk_tree_selection_count_selected_rows(entry);
if (!entry || len==0) {
simple_dialog(ESD_TYPE_ERROR, ESD_BTN_OK,
"You didn't specify an interface on which to capture packets.");
return;
}
while (global_capture_opts.ifaces->len > 0) {
interface_opts = g_array_index(global_capture_opts.ifaces, interface_options, 0);
global_capture_opts.ifaces = g_array_remove_index(global_capture_opts.ifaces, 0);
g_free(interface_opts.name);
g_free(interface_opts.descr);
g_free(interface_opts.cfilter);
#ifdef HAVE_PCAP_REMOTE
g_free(interface_opts.remote_host);
g_free(interface_opts.remote_port);
g_free(interface_opts.auth_username);
g_free(interface_opts.auth_password);
#endif
}
gtk_tree_selection_selected_foreach(entry, make_selections_array, NULL);
/* XXX - remove this? */
if (global_capture_opts.save_file) {
g_free(global_capture_opts.save_file);
global_capture_opts.save_file = NULL;
}
#ifdef HAVE_AIRPCAP
airpcap_if_active = get_airpcap_if_from_name(airpcap_if_list, interface_opts.name);
airpcap_if_selected = airpcap_if_active;
airpcap_set_toolbar_start_capture(airpcap_if_active);
#endif
capture_start_cb(NULL, NULL);
}
void capture_if_cb_prep(GtkWidget *w _U_, gpointer d _U_)
{
GtkTreeSelection *entry;
GtkWidget* view;
view = g_object_get_data(G_OBJECT(welcome_hb), TREE_VIEW_INTERFACES);
entry = gtk_tree_view_get_selection(GTK_TREE_VIEW(view));
if (entry) {
/* global_capture_opts.number_of_ifaces = gtk_tree_selection_count_selected_rows(entry);*/
gtk_tree_selection_selected_foreach(entry, make_selections_array, NULL);
}
capture_if_cb(NULL, NULL);
}
void capture_opts_cb_prep(GtkWidget *w _U_, gpointer d _U_)
{
GtkTreeSelection *entry;
GtkWidget* view;
view = g_object_get_data(G_OBJECT(welcome_hb), TREE_VIEW_INTERFACES);
entry = gtk_tree_view_get_selection(GTK_TREE_VIEW(view));
if (entry) {
gtk_tree_selection_selected_foreach(entry, make_selections_array, NULL);
}
capture_prep_cb(NULL, NULL);
}
/* create the welcome page */
GtkWidget *
@ -792,10 +766,6 @@ welcome_new(void)
GtkWidget *header;
GtkWidget *topic_vb;
GtkWidget *topic_to_fill;
#ifdef HAVE_LIBPCAP
GtkWidget *if_child_box;
GList *if_list;
#endif /* HAVE_LIBPCAP */
GtkWidget *file_child_box;
gchar *label_text;
#ifdef _WIN32
@ -803,6 +773,13 @@ welcome_new(void)
DWORD chimney_enabled = 0;
DWORD ce_size = sizeof(chimney_enabled);
#endif
GtkWidget *swindow;
GtkTreeSelection *selection;
GtkCellRenderer *renderer;
GtkTreeViewColumn *column;
GList *if_list;
int err;
gchar *err_str = NULL;
/* prepare colors */
@ -851,35 +828,47 @@ welcome_new(void)
gtk_box_pack_start(GTK_BOX(column_vb), topic_vb, TRUE, TRUE, 0);
#ifdef HAVE_LIBPCAP
if_list = welcome_if_panel_get_if_list();
if_list = capture_interface_list(&err, &err_str);
if (g_list_length(if_list) > 0) {
item_hb = welcome_button(WIRESHARK_STOCK_CAPTURE_INTERFACES,
"Interface List",
"Live list of the capture interfaces\n(counts incoming packets)",
"Same as Capture/Interfaces menu or toolbar item",
welcome_button_callback_helper, capture_if_cb);
welcome_button_callback_helper, capture_if_cb_prep);
gtk_box_pack_start(GTK_BOX(topic_to_fill), item_hb, FALSE, FALSE, 5);
label_text = g_strdup("<span foreground=\"black\">Start capture on interface:</span>");
w = gtk_label_new(label_text);
gtk_label_set_markup(GTK_LABEL(w), label_text);
g_free (label_text);
gtk_misc_set_alignment (GTK_MISC(w), 0.0f, 0.0f);
gtk_box_pack_start(GTK_BOX(topic_to_fill), w, FALSE, FALSE, 5);
if_child_box = gtk_vbox_new(FALSE, 0);
/* 8 capture interfaces or 150 pixels height is about the size */
/* that still fits on a screen of about 1000*700 */
welcome_if_panel_vb = scroll_box_dynamic_new(GTK_BOX(if_child_box), 8, 150);
gtk_box_pack_start(GTK_BOX(topic_to_fill), welcome_if_panel_vb, FALSE, FALSE, 0);
welcome_if_panel_list(if_list);
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_view = gtk_tree_view_new ();
gtk_object_set(GTK_OBJECT(if_view), "headers-visible", FALSE, NULL);
g_object_set_data(G_OBJECT(welcome_hb), TREE_VIEW_INTERFACES, if_view);
renderer = gtk_cell_renderer_text_new();
column = gtk_tree_view_column_new_with_attributes ("",
GTK_CELL_RENDERER(renderer),
"text", 0,
NULL);
gtk_tree_view_append_column(GTK_TREE_VIEW(if_view), column);
gtk_tree_view_column_set_resizable(gtk_tree_view_get_column(GTK_TREE_VIEW (if_view),0), TRUE );
selection = gtk_tree_view_get_selection(GTK_TREE_VIEW(if_view));
gtk_tree_selection_set_mode(selection, GTK_SELECTION_MULTIPLE);
item_hb = welcome_button(WIRESHARK_STOCK_CAPTURE_START,
"Start",
"Choose one or more interfaces to capture from, then <b>Start</b>",
"Same as Capture/Interfaces with default options",
(welcome_button_callback_t)capture_if_start, (gpointer)if_view);
gtk_box_pack_start(GTK_BOX(topic_to_fill), item_hb, FALSE, FALSE, 5);
welcome_if_tree_load();
gtk_container_add (GTK_CONTAINER (swindow), if_view);
gtk_container_add(GTK_CONTAINER(topic_to_fill), swindow);
item_hb = welcome_button(WIRESHARK_STOCK_CAPTURE_OPTIONS,
"Capture Options",
"Start a capture with detailed options",
"Same as Capture/Options menu or toolbar item",
welcome_button_callback_helper, capture_prep_cb);
"Capture Options",
"Start a capture with detailed options",
"Same as Capture/Options menu or toolbar item",
welcome_button_callback_helper, capture_prep_cb);
gtk_box_pack_start(GTK_BOX(topic_to_fill), item_hb, FALSE, FALSE, 5);
#ifdef _WIN32
/* Check for chimney offloading */
@ -888,10 +877,10 @@ welcome_new(void)
NULL, NULL, (LPBYTE) &chimney_enabled, &ce_size);
if (reg_ret == ERROR_SUCCESS && chimney_enabled) {
item_hb = welcome_button(WIRESHARK_STOCK_WIKI,
"Offloading Detected",
"TCP Chimney offloading is enabled. You \nmight not capture much data.",
topic_online_url(ONLINEPAGE_CHIMNEY),
topic_menu_cb, GINT_TO_POINTER(ONLINEPAGE_CHIMNEY));
"Offloading Detected",
"TCP Chimney offloading is enabled. You \nmight not capture much data.",
topic_online_url(ONLINEPAGE_CHIMNEY),
topic_menu_cb, GINT_TO_POINTER(ONLINEPAGE_CHIMNEY));
gtk_box_pack_start(GTK_BOX(topic_to_fill), item_hb, FALSE, FALSE, 5);
}
#endif /* _WIN32 */
@ -961,7 +950,7 @@ welcome_new(void)
file_child_box = gtk_vbox_new(FALSE, 1);
/* 17 file items or 300 pixels height is about the size */
/* that still fits on a screen of about 1000*700 */
welcome_file_panel_vb = scroll_box_dynamic_new(GTK_BOX(file_child_box), 17, 300);
welcome_file_panel_vb = scroll_box_dynamic_new(GTK_WIDGET(file_child_box), 17, 300);
gtk_box_pack_start(GTK_BOX(topic_to_fill), welcome_file_panel_vb, FALSE, FALSE, 0);
item_hb = welcome_button(WIRESHARK_STOCK_WIKI,

View File

@ -54,4 +54,6 @@ void welcome_header_set_message(gchar *msg);
*/
void welcome_header_pop_msg(void);
void welcome_if_tree_load(void);
#endif /* __MAIN_WELCOME_H__ */