forked from osmocom/wireshark
Added "Apply as filter"/"Prepare a filter"/"Find frame"/"Colorize Protocol"
menu. Simplified getting the Display filter. svn path=/trunk/; revision=23786
This commit is contained in:
parent
b0998315f9
commit
4783f12c08
|
@ -26,16 +26,25 @@
|
|||
# include "config.h"
|
||||
#endif
|
||||
|
||||
#include <string.h>
|
||||
|
||||
#include <gtk/gtk.h>
|
||||
|
||||
#include "proto_hier_stats.h"
|
||||
#include "proto_hier_stats_dlg.h"
|
||||
#include "compat_macros.h"
|
||||
#include "dlg_utils.h"
|
||||
#include "gui_utils.h"
|
||||
#include "find_dlg.h"
|
||||
#include "color_dlg.h"
|
||||
#include "gtkglobals.h"
|
||||
#include "main.h"
|
||||
#include "compat_macros.h"
|
||||
#include "simple_dialog.h"
|
||||
#include "help_dlg.h"
|
||||
|
||||
#define GTK_MENU_FUNC(a) ((GtkItemFactoryCallback)(a))
|
||||
|
||||
#if GTK_MAJOR_VERSION < 2
|
||||
#define NUM_STAT_COLUMNS 8
|
||||
#else
|
||||
|
@ -48,6 +57,7 @@ enum {
|
|||
END_PKTS_COLUMN,
|
||||
END_BYTES_COLUMN,
|
||||
END_BANDWIDTH_COLUMN,
|
||||
FILTER_NAME,
|
||||
NUM_STAT_COLUMNS /* must be the last */
|
||||
};
|
||||
#endif
|
||||
|
@ -63,10 +73,190 @@ typedef struct {
|
|||
ph_stats_t *ps;
|
||||
} draw_info_t;
|
||||
|
||||
static GtkWidget *popup_menu_object;
|
||||
static GtkWidget *tree;
|
||||
|
||||
#define PCT(x,y) (100.0 * (float)(x) / (float)(y))
|
||||
#define BANDWITDH(bytes,secs) ((bytes) * 8.0 / ((secs) * 1000.0 * 1000.0))
|
||||
|
||||
/* action is encoded as
|
||||
filter_action*256+filter_type
|
||||
|
||||
filter_action:
|
||||
0: Match
|
||||
1: Prepare
|
||||
2: Find Frame
|
||||
3: Find Next
|
||||
4: Find Previous
|
||||
5: Colorize Host Traffic
|
||||
filter_type:
|
||||
0: Selected
|
||||
1: Not Selected
|
||||
2: And Selected
|
||||
3: Or Selected
|
||||
4: And Not Selected
|
||||
5: Or Not Selected
|
||||
*/
|
||||
static void
|
||||
proto_hier_select_filter_cb(GtkWidget *widget _U_, gpointer callback_data _U_, guint callback_action)
|
||||
{
|
||||
int action, type;
|
||||
char dirstr[128];
|
||||
char str[256];
|
||||
const char *current_filter;
|
||||
const char *filter = NULL;
|
||||
#if GTK_MAJOR_VERSION >= 2
|
||||
GtkTreeSelection *sel;
|
||||
GtkTreeModel *model;
|
||||
GtkTreeIter iter;
|
||||
#endif
|
||||
|
||||
action = (callback_action>>8)&0xff;
|
||||
type = callback_action&0xff;
|
||||
|
||||
#if GTK_MAJOR_VERSION >= 2
|
||||
sel = gtk_tree_view_get_selection (GTK_TREE_VIEW(tree));
|
||||
gtk_tree_selection_get_selected (sel, &model, &iter);
|
||||
gtk_tree_model_get (model, &iter, FILTER_NAME, &filter, -1);
|
||||
#endif
|
||||
if (filter && 0 != strlen(filter)) {
|
||||
g_snprintf(dirstr, 127, "%s", filter);
|
||||
} else {
|
||||
simple_dialog(ESD_TYPE_ERROR, ESD_BTN_OK, "Could not acquire information to build a filter!\nTry expanding or choosing another item.");
|
||||
return;
|
||||
}
|
||||
|
||||
current_filter=gtk_entry_get_text(GTK_ENTRY(main_display_filter_widget));
|
||||
switch(type){
|
||||
case 0:
|
||||
/* selected */
|
||||
g_snprintf(str, 255, "%s", dirstr);
|
||||
break;
|
||||
case 1:
|
||||
/* not selected */
|
||||
g_snprintf(str, 255, "!(%s)", dirstr);
|
||||
break;
|
||||
case 2:
|
||||
/* and selected */
|
||||
if ((!current_filter) || (0 == strlen(current_filter)))
|
||||
g_snprintf(str, 255, "%s", dirstr);
|
||||
else
|
||||
g_snprintf(str, 255, "(%s) && (%s)", current_filter, dirstr);
|
||||
break;
|
||||
case 3:
|
||||
/* or selected */
|
||||
if ((!current_filter) || (0 == strlen(current_filter)))
|
||||
g_snprintf(str, 255, "%s", dirstr);
|
||||
else
|
||||
g_snprintf(str, 255, "(%s) || (%s)", current_filter, dirstr);
|
||||
break;
|
||||
case 4:
|
||||
/* and not selected */
|
||||
if ((!current_filter) || (0 == strlen(current_filter)))
|
||||
g_snprintf(str, 255, "!(%s)", dirstr);
|
||||
else
|
||||
g_snprintf(str, 255, "(%s) && !(%s)", current_filter, dirstr);
|
||||
break;
|
||||
case 5:
|
||||
/* or not selected */
|
||||
if ((!current_filter) || (0 == strlen(current_filter)))
|
||||
g_snprintf(str, 255, "!(%s)", dirstr);
|
||||
else
|
||||
g_snprintf(str, 255, "(%s) || !(%s)", current_filter, dirstr);
|
||||
break;
|
||||
}
|
||||
|
||||
switch(action){
|
||||
case 0:
|
||||
/* match */
|
||||
gtk_entry_set_text(GTK_ENTRY(main_display_filter_widget), str);
|
||||
main_filter_packets(&cfile, str, FALSE);
|
||||
gdk_window_raise(top_level->window);
|
||||
break;
|
||||
case 1:
|
||||
/* prepare */
|
||||
gtk_entry_set_text(GTK_ENTRY(main_display_filter_widget), str);
|
||||
break;
|
||||
case 2:
|
||||
/* find frame */
|
||||
find_frame_with_filter(str);
|
||||
break;
|
||||
case 3:
|
||||
/* find next */
|
||||
find_previous_next_frame_with_filter(str, FALSE);
|
||||
break;
|
||||
case 4:
|
||||
/* find previous */
|
||||
find_previous_next_frame_with_filter(str, TRUE);
|
||||
break;
|
||||
case 5:
|
||||
/* colorize host traffic */
|
||||
color_display_with_filter(str);
|
||||
break;
|
||||
}
|
||||
}
|
||||
static gint
|
||||
proto_hier_show_popup_menu_cb(GtkWidget *widget _U_, GdkEvent *event, gpointer data _U_)
|
||||
{
|
||||
GdkEventButton *bevent = (GdkEventButton *)event;
|
||||
|
||||
if(event->type==GDK_BUTTON_PRESS && bevent->button==3){
|
||||
/* If this is a right click on one of our columns, popup the context menu */
|
||||
gtk_menu_popup(GTK_MENU(popup_menu_object), NULL, NULL, NULL, NULL,
|
||||
bevent->button, bevent->time);
|
||||
}
|
||||
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
static GtkItemFactoryEntry proto_hier_list_menu_items[] =
|
||||
{
|
||||
/* Match */
|
||||
ITEM_FACTORY_ENTRY("/Apply as Filter", NULL, NULL, 0, "<Branch>", NULL),
|
||||
ITEM_FACTORY_ENTRY("/Apply as Filter/Selected", NULL,
|
||||
proto_hier_select_filter_cb, 0*256+0, NULL, NULL),
|
||||
ITEM_FACTORY_ENTRY("/Apply as Filter/Not Selected", NULL,
|
||||
proto_hier_select_filter_cb, 0*256+1, NULL, NULL),
|
||||
ITEM_FACTORY_ENTRY("/Apply as Filter/... and Selected", NULL,
|
||||
proto_hier_select_filter_cb, 0*256+2, NULL, NULL),
|
||||
ITEM_FACTORY_ENTRY("/Apply as Filter/... or Selected", NULL,
|
||||
proto_hier_select_filter_cb, 0*256+3, NULL, NULL),
|
||||
ITEM_FACTORY_ENTRY("/Apply as Filter/... and not Selected", NULL,
|
||||
proto_hier_select_filter_cb, 0*256+4, NULL, NULL),
|
||||
ITEM_FACTORY_ENTRY("/Apply as Filter/... or not Selected", NULL,
|
||||
proto_hier_select_filter_cb, 0*256+5, NULL, NULL),
|
||||
|
||||
/* Prepare */
|
||||
ITEM_FACTORY_ENTRY("/Prepare a Filter", NULL, NULL, 0, "<Branch>", NULL),
|
||||
ITEM_FACTORY_ENTRY("/Prepare a Filter/Selected", NULL,
|
||||
proto_hier_select_filter_cb, 1*256+0, NULL, NULL),
|
||||
ITEM_FACTORY_ENTRY("/Prepare a Filter/Not Selected", NULL,
|
||||
proto_hier_select_filter_cb, 1*256+1, NULL, NULL),
|
||||
ITEM_FACTORY_ENTRY("/Prepare a Filter/... and Selected", NULL,
|
||||
proto_hier_select_filter_cb, 1*256+2, NULL, NULL),
|
||||
ITEM_FACTORY_ENTRY("/Prepare a Filter/... or Selected", NULL,
|
||||
proto_hier_select_filter_cb, 1*256+3, NULL, NULL),
|
||||
ITEM_FACTORY_ENTRY("/Prepare a Filter/... and not Selected", NULL,
|
||||
proto_hier_select_filter_cb, 1*256+4, NULL, NULL),
|
||||
ITEM_FACTORY_ENTRY("/Prepare a Filter/... or not Selected", NULL,
|
||||
proto_hier_select_filter_cb, 1*256+5, NULL, NULL),
|
||||
|
||||
/* Find Frame */
|
||||
ITEM_FACTORY_ENTRY("/Find Frame", NULL, NULL, 0, "<Branch>", NULL),
|
||||
ITEM_FACTORY_ENTRY("/Find Frame/Find Frame", NULL,
|
||||
proto_hier_select_filter_cb, 2*256+0, NULL, NULL),
|
||||
/* Find Next */
|
||||
ITEM_FACTORY_ENTRY("/Find Frame/Find Next", NULL,
|
||||
proto_hier_select_filter_cb, 3*256+0, NULL, NULL),
|
||||
/* Find Previous */
|
||||
ITEM_FACTORY_ENTRY("/Find Frame/Find Previous", NULL,
|
||||
proto_hier_select_filter_cb, 4*256+0, NULL, NULL),
|
||||
/* Colorize Protocol */
|
||||
ITEM_FACTORY_ENTRY("/Colorize Protocol", NULL,
|
||||
proto_hier_select_filter_cb, 5*256+0, NULL, NULL),
|
||||
|
||||
};
|
||||
|
||||
static void
|
||||
fill_in_tree_node(GNode *node, gpointer data)
|
||||
{
|
||||
|
@ -133,6 +323,7 @@ fill_in_tree_node(GNode *node, gpointer data)
|
|||
END_PKTS_COLUMN, text[5],
|
||||
END_BYTES_COLUMN, text[6],
|
||||
END_BANDWIDTH_COLUMN, text[7],
|
||||
FILTER_NAME, stats->hfinfo->abbrev,
|
||||
-1);
|
||||
#endif
|
||||
|
||||
|
@ -175,12 +366,23 @@ fill_in_tree(GtkWidget *tree, ph_stats_t *ps)
|
|||
fill_in_tree_node, &di);
|
||||
}
|
||||
|
||||
static void
|
||||
proto_hier_create_popup_menu(void)
|
||||
{
|
||||
GtkItemFactory *item_factory;
|
||||
|
||||
item_factory = gtk_item_factory_new(GTK_TYPE_MENU, "<main>", NULL);
|
||||
gtk_item_factory_create_items_ac(item_factory, sizeof(proto_hier_list_menu_items)/sizeof(proto_hier_list_menu_items[0]), proto_hier_list_menu_items, NULL, 2);
|
||||
popup_menu_object = gtk_item_factory_get_widget (item_factory, "<main>");
|
||||
SIGNAL_CONNECT(tree, "button_press_event", proto_hier_show_popup_menu_cb, NULL);
|
||||
}
|
||||
|
||||
#define MAX_DLG_HEIGHT 450
|
||||
#define DEF_DLG_WIDTH 700
|
||||
static void
|
||||
create_tree(GtkWidget *container, ph_stats_t *ps)
|
||||
{
|
||||
GtkWidget *sw, *tree;
|
||||
GtkWidget *sw;
|
||||
#if GTK_MAJOR_VERSION < 2
|
||||
int i, height;
|
||||
const gchar *column_titles[NUM_STAT_COLUMNS] = {
|
||||
|
@ -231,7 +433,7 @@ create_tree(GtkWidget *container, ph_stats_t *ps)
|
|||
store = gtk_tree_store_new(NUM_STAT_COLUMNS, G_TYPE_STRING,
|
||||
G_TYPE_STRING, G_TYPE_STRING, G_TYPE_STRING,
|
||||
G_TYPE_STRING, G_TYPE_STRING, G_TYPE_STRING,
|
||||
G_TYPE_STRING);
|
||||
G_TYPE_STRING, G_TYPE_POINTER);
|
||||
tree = tree_view_new(GTK_TREE_MODEL(store));
|
||||
tree_view = GTK_TREE_VIEW(tree);
|
||||
gtk_tree_view_set_headers_visible(tree_view, TRUE);
|
||||
|
@ -307,6 +509,10 @@ create_tree(GtkWidget *container, ph_stats_t *ps)
|
|||
gtk_tree_view_expand_all(tree_view);
|
||||
#endif
|
||||
|
||||
#if GTK_MAJOR_VERSION >= 2
|
||||
proto_hier_create_popup_menu ();
|
||||
#endif
|
||||
|
||||
gtk_container_add(GTK_CONTAINER(sw), tree);
|
||||
}
|
||||
|
||||
|
@ -317,6 +523,7 @@ proto_hier_stats_cb(GtkWidget *w _U_, gpointer d _U_)
|
|||
GtkWidget *dlg, *close_bt, *help_bt, *vbox, *bbox;
|
||||
GtkWidget *label;
|
||||
char title[256];
|
||||
const char *current_filter;
|
||||
|
||||
/* Get the statistics. */
|
||||
ps = ph_stats_new();
|
||||
|
@ -332,8 +539,10 @@ proto_hier_stats_cb(GtkWidget *w _U_, gpointer d _U_)
|
|||
gtk_container_border_width(GTK_CONTAINER(vbox), 5);
|
||||
gtk_container_add(GTK_CONTAINER(dlg), vbox);
|
||||
|
||||
if (ps->dfilter) {
|
||||
g_snprintf(title, 255, "Display filter: %s", ps->dfilter);
|
||||
current_filter=gtk_entry_get_text(GTK_ENTRY(main_display_filter_widget));
|
||||
|
||||
if (current_filter && strlen(current_filter) != 0) {
|
||||
g_snprintf(title, 255, "Display filter: %s", current_filter);
|
||||
} else {
|
||||
g_snprintf(title, 255, "Display filter: none");
|
||||
}
|
||||
|
|
|
@ -197,7 +197,6 @@ ph_stats_new(void)
|
|||
ps->stats_tree = g_node_new(NULL);
|
||||
ps->first_time = 0.0;
|
||||
ps->last_time = 0.0;
|
||||
ps->dfilter = cfile.dfilter;
|
||||
|
||||
/* Update the progress bar when it gets to this value. */
|
||||
progbar_nextstep = 0;
|
||||
|
|
|
@ -41,7 +41,6 @@ typedef struct {
|
|||
GNode *stats_tree;
|
||||
double first_time; /* seconds (msec resolution) of first packet */
|
||||
double last_time; /* seconds (msec resolution) of last packet */
|
||||
const char *dfilter; /* display filter */
|
||||
} ph_stats_t;
|
||||
|
||||
|
||||
|
|
Loading…
Reference in New Issue