Add a custom column from the packet details popup menu.

This fixes bug 4246.

svn path=/trunk/; revision=31020
This commit is contained in:
Stig Bjørlykke 2009-11-19 18:22:26 +00:00
parent 2d2a1ef1cf
commit 9a7d0994d8
5 changed files with 61 additions and 8 deletions

View File

@ -154,6 +154,7 @@
#include "gtk/capture_dlg.h"
#include "gtk/capture_if_dlg.h"
#include "gtk/tap_dfilter_dlg.h"
#include "gtk/prefs_column.h"
#ifdef HAVE_LIBPCAP
#include "../image/wsicon16.xpm"
@ -797,6 +798,19 @@ void expand_all_cb(GtkWidget *widget _U_, gpointer data _U_) {
expand_all_tree(cfile.edt->tree, tree_view);
}
void apply_as_custom_column_cb (GtkWidget *widget _U_, gpointer data _U_)
{
if (cfile.finfo_selected) {
column_prefs_add_custom(COL_CUSTOM, cfile.finfo_selected->hfinfo->name,
cfile.finfo_selected->hfinfo->abbrev);
#ifndef NEW_PACKET_LIST
/* Recreate the packet list according to new preferences */
packet_list_recreate ();
cfile.cinfo.columns_changed = FALSE; /* Reset value */
#endif
}
}
void expand_tree_cb(GtkWidget *widget _U_, gpointer data _U_) {
GtkTreePath *path;

View File

@ -241,6 +241,13 @@ extern void expand_tree_cb(GtkWidget *widget, gpointer data);
*/
extern void expand_all_cb(GtkWidget *widget, gpointer data);
/** User requested "Apply as a custom column" by menu.
*
* @param widget parent widget (unused)
* @param data unused
*/
extern void apply_as_custom_column_cb(GtkWidget *widget, gpointer data);
/** User requested "Collapse All" by menu.
*
* @param widget parent widget (unused)

View File

@ -388,7 +388,7 @@ colorize_conversation_cb(GtkWidget * w _U_, gpointer data _U_, int action)
if( (action>>8) == 255 ) {
color_filters_reset_tmp();
#ifdef NEW_PACKET_LIST
new_packet_list_colorize_packets();
new_packet_list_colorize_packets();
#else
cf_colorize_packets(&cfile);
#endif
@ -678,6 +678,9 @@ static GtkItemFactoryEntry menu_items[] =
0, "<StockItem>", WIRESHARK_STOCK_DISPLAY_FILTER,},
{"/Analyze/Display Filter _Macros...", NULL, GTK_MENU_FUNC(macros_dialog_cb), 0, NULL, NULL,},
{"/Analyze/<separator>", NULL, NULL, 0, "<Separator>", NULL,},
#ifndef NEW_PACKET_LIST
{"/Analyze/Apply as Column", NULL, GTK_MENU_FUNC(apply_as_custom_column_cb), 0, NULL, NULL},
#endif
{"/Analyze/Appl_y as Filter", NULL, NULL, 0, "<Branch>", NULL,},
{"/Analyze/Apply as Filter/_Selected", NULL, GTK_MENU_FUNC(match_selected_ptree_cb),
MATCH_SELECTED_REPLACE|MATCH_SELECTED_APPLY_NOW, NULL, NULL,},
@ -987,6 +990,12 @@ static GtkItemFactoryEntry tree_view_menu_items[] =
{"/<separator>", NULL, NULL, 0, "<Separator>", NULL,},
#ifndef NEW_PACKET_LIST
{"/Apply as Column", NULL, GTK_MENU_FUNC(apply_as_custom_column_cb), 0, NULL, NULL},
{"/<separator>", NULL, NULL, 0, "<Separator>", NULL,},
#endif
{"/Apply as Filter", NULL, NULL, 0, "<Branch>", NULL,},
{"/Apply as Filter/_Selected", NULL, GTK_MENU_FUNC(match_selected_ptree_cb),
MATCH_SELECTED_REPLACE|MATCH_SELECTED_APPLY_NOW, NULL, NULL,},
@ -3173,8 +3182,12 @@ set_menus_for_selected_tree_row(capture_file *cf)
TRUE);
set_menu_sensitivity(tree_view_menu_factory, "/Copy/As Filter",
proto_can_match_selected(cf->finfo_selected, cf->edt));
set_menu_sensitivity(main_menu_factory, "/Analyze/Apply as Column",
hfinfo->type != FT_NONE);
set_menu_sensitivity(main_menu_factory, "/Analyze/Apply as Filter",
proto_can_match_selected(cf->finfo_selected, cf->edt));
set_menu_sensitivity(tree_view_menu_factory, "/Apply as Column",
hfinfo->type != FT_NONE);
set_menu_sensitivity(tree_view_menu_factory, "/Apply as Filter",
proto_can_match_selected(cf->finfo_selected, cf->edt));
set_menu_sensitivity(main_menu_factory, "/Analyze/Prepare a Filter",
@ -3215,6 +3228,8 @@ set_menus_for_selected_tree_row(capture_file *cf)
set_menu_sensitivity(main_menu_factory, "/Edit/Copy/Value", FALSE);
set_menu_sensitivity(main_menu_factory, "/Edit/Copy/As Filter", FALSE);
set_menu_sensitivity(tree_view_menu_factory, "/Copy", FALSE);
set_menu_sensitivity(main_menu_factory, "/Analyze/Apply as Column", FALSE);
set_menu_sensitivity(tree_view_menu_factory, "/Apply as Column", FALSE);
set_menu_sensitivity(main_menu_factory, "/Analyze/Apply as Filter", FALSE);
set_menu_sensitivity(tree_view_menu_factory, "/Apply as Filter", FALSE);
set_menu_sensitivity(main_menu_factory, "/Analyze/Prepare a Filter", FALSE);

View File

@ -259,11 +259,23 @@ column_prefs_show(GtkWidget *prefs_window) {
}
void
column_prefs_add_custom(gint fmt, const gchar *title, const gchar *custom_field)
{
fmt_data *cfmt;
cfmt = (fmt_data *) g_malloc(sizeof(fmt_data));
cfmt->title = g_strdup(title);
cfmt->fmt = g_strdup(col_format_to_string(fmt));
cfmt->custom_field = g_strdup(custom_field);
prefs.col_list = g_list_append(prefs.col_list, cfmt);
}
/* To do: add input checking to each of these callbacks */
static void
column_list_new_cb(GtkWidget *w _U_, gpointer data) {
fmt_data *cfmt;
gint cur_fmt;
const gchar *title = "New Column";
GtkTreeView *column_l = GTK_TREE_VIEW(data);
@ -272,12 +284,8 @@ column_list_new_cb(GtkWidget *w _U_, gpointer data) {
GtkTreePath *path;
GtkTreeViewColumn *title_column;
cur_fmt = COL_NUMBER; /* Set the default new column type */
cfmt = (fmt_data *) g_malloc(sizeof(fmt_data));
cfmt->title = g_strdup(title);
cfmt->fmt = g_strdup(col_format_to_string(cur_fmt));
cfmt->custom_field = NULL;
prefs.col_list = g_list_append(prefs.col_list, cfmt);
cur_fmt = COL_NUMBER; /* Set the default new column type */
column_prefs_add_custom (cur_fmt, title, NULL);
model = gtk_tree_view_get_model(column_l);
gtk_list_store_append(GTK_LIST_STORE(model), &iter);

View File

@ -55,4 +55,13 @@ void column_prefs_apply(GtkWidget *widget);
*/
void column_prefs_destroy(GtkWidget *widget);
/** Add a custom column.
*
* @param fmt column format
* @param title column title
* @param custom_field column custom field
*/
void column_prefs_add_custom(gint fmt, const gchar *title,
const gchar *custom_field);
#endif