2001-03-22 23:54:47 +00:00
/* proto_hier_stats_dlg.c
*
2004-07-18 00:24:25 +00:00
* $ Id $
2001-03-22 23:54:47 +00:00
*
2006-05-21 05:12:17 +00:00
* Wireshark - Network traffic analyzer
* By Gerald Combs < gerald @ wireshark . org >
2001-03-22 23:54:47 +00:00
* Copyright 1998 Gerald Combs
*
* This program is free software ; you can redistribute it and / or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation ; either version 2
* of the License , or ( at your option ) any later version .
*
* This program is distributed in the hope that it will be useful ,
* but WITHOUT ANY WARRANTY ; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE . See the
* GNU General Public License for more details .
*
* You should have received a copy of the GNU General Public License
* along with this program ; if not , write to the Free Software
2012-06-28 22:56:06 +00:00
* Foundation , Inc . , 51 Franklin Street , Fifth Floor , Boston , MA 02110 - 1301 USA .
2001-03-22 23:54:47 +00:00
*/
# ifdef HAVE_CONFIG_H
# include "config.h"
# endif
2010-08-30 23:58:19 +00:00
# include <stdio.h>
2007-12-06 18:10:35 +00:00
# include <string.h>
2001-03-22 23:54:47 +00:00
# include <gtk/gtk.h>
2008-04-13 03:32:24 +00:00
# include "../proto_hier_stats.h"
2012-01-16 01:07:52 +00:00
# include "ui/simple_dialog.h"
2008-04-13 03:32:24 +00:00
2012-01-15 21:59:11 +00:00
# include "ui/gtk/proto_hier_stats_dlg.h"
# include "ui/gtk/dlg_utils.h"
# include "ui/gtk/gui_utils.h"
# include "ui/gtk/filter_utils.h"
# include "ui/gtk/gtkglobals.h"
# include "ui/gtk/help_dlg.h"
# include "ui/gtk/utf8_entities.h"
2008-04-13 03:32:24 +00:00
2001-03-22 23:54:47 +00:00
2002-11-03 17:38:45 +00:00
enum {
PROTOCOL_COLUMN ,
PRCT_PKTS_COLUMN ,
PKTS_COLUMN ,
2010-03-03 23:04:06 +00:00
PRCT_BYTES_COLUMN ,
2002-11-03 17:38:45 +00:00
BYTES_COLUMN ,
2004-03-17 21:48:15 +00:00
BANDWIDTH_COLUMN ,
2002-11-03 17:38:45 +00:00
END_PKTS_COLUMN ,
END_BYTES_COLUMN ,
2004-03-17 21:48:15 +00:00
END_BANDWIDTH_COLUMN ,
2007-12-06 18:10:35 +00:00
FILTER_NAME ,
2008-05-18 19:49:12 +00:00
PRCT_PKTS_VALUE_COLUMN ,
2010-03-03 23:04:06 +00:00
PRCT_BYTES_VALUE_COLUMN ,
2002-11-03 17:38:45 +00:00
NUM_STAT_COLUMNS /* must be the last */
} ;
2001-03-22 23:54:47 +00:00
typedef struct {
2009-03-19 17:47:00 +00:00
GtkTreeView * tree_view ;
GtkTreeIter * iter ;
ph_stats_t * ps ;
2001-03-22 23:54:47 +00:00
} draw_info_t ;
2007-12-06 18:10:35 +00:00
static GtkWidget * tree ;
2001-03-22 23:54:47 +00:00
# define PCT(x,y) (100.0 * (float)(x) / (float)(y))
2010-03-03 23:04:06 +00:00
# define BANDWIDTH(bytes,secs) ((bytes) * 8.0 / ((secs) * 1000.0 * 1000.0))
2001-03-22 23:54:47 +00:00
2007-12-06 18:10:35 +00:00
static void
proto_hier_select_filter_cb ( GtkWidget * widget _U_ , gpointer callback_data _U_ , guint callback_action )
{
2012-06-01 07:02:04 +00:00
gchar * str = NULL ;
gchar * strtmp = NULL ;
2009-03-19 17:47:00 +00:00
const char * filter = NULL ;
GtkTreeSelection * sel ;
GtkTreeModel * model ;
GtkTreeIter iter ;
2012-06-01 07:02:04 +00:00
GtkTreePath * path ;
2009-03-19 17:47:00 +00:00
sel = gtk_tree_view_get_selection ( GTK_TREE_VIEW ( tree ) ) ;
gtk_tree_selection_get_selected ( sel , & model , & iter ) ;
2012-06-01 07:02:04 +00:00
path = gtk_tree_model_get_path ( model , & iter ) ;
2009-03-19 17:47:00 +00:00
gtk_tree_model_get ( model , & iter , FILTER_NAME , & filter , - 1 ) ;
2012-06-01 07:02:04 +00:00
if ( filter & & strlen ( filter ) > 0 ) {
2009-03-19 17:47:00 +00:00
str = g_strdup_printf ( " %s " , filter ) ;
} else {
simple_dialog ( ESD_TYPE_ERROR , ESD_BTN_OK , " Could not acquire information to build a filter! \n Try expanding or choosing another item. " ) ;
return ;
}
2012-06-01 07:02:04 +00:00
while ( gtk_tree_path_up ( path ) & & gtk_tree_path_get_depth ( path ) > 0 )
{
strtmp = g_strdup_printf ( " %s " , str ) ;
g_free ( str ) ;
gtk_tree_model_get_iter ( model , & iter , path ) ;
gtk_tree_model_get ( model , & iter , FILTER_NAME , & filter , - 1 ) ;
if ( filter & & strlen ( filter ) > 0 ) {
str = g_strdup_printf ( " %s and %s " , strtmp , filter ) ;
} else {
simple_dialog ( ESD_TYPE_ERROR , ESD_BTN_OK , " Could not acquire information to build a filter! \n Try expanding or choosing another item. " ) ;
return ;
}
g_free ( strtmp ) ;
}
2009-03-19 17:47:00 +00:00
2012-06-01 07:02:04 +00:00
apply_selected_filter ( callback_action , str ) ;
gtk_tree_path_free ( path ) ;
2009-03-19 17:47:00 +00:00
g_free ( str ) ;
2007-12-06 18:10:35 +00:00
}
2010-09-02 15:38:04 +00:00
/* Action callbacks */
2010-08-30 19:49:57 +00:00
static void
apply_as_selected_cb ( GtkWidget * widget , gpointer user_data )
{
2011-09-21 18:55:03 +00:00
proto_hier_select_filter_cb ( widget , user_data , CALLBACK_MATCH ( ACTYPE_SELECTED , 0 ) ) ;
2010-08-30 19:49:57 +00:00
}
static void
apply_as_not_selected_cb ( GtkWidget * widget , gpointer user_data )
{
2011-09-21 18:55:03 +00:00
proto_hier_select_filter_cb ( widget , user_data , CALLBACK_MATCH ( ACTYPE_NOT_SELECTED , 0 ) ) ;
2010-08-30 19:49:57 +00:00
}
static void
apply_as_and_selected_cb ( GtkWidget * widget , gpointer user_data )
{
2011-09-21 18:55:03 +00:00
proto_hier_select_filter_cb ( widget , user_data , CALLBACK_MATCH ( ACTYPE_AND_SELECTED , 0 ) ) ;
2010-08-30 19:49:57 +00:00
}
static void
apply_as_or_selected_cb ( GtkWidget * widget , gpointer user_data )
{
2011-09-21 18:55:03 +00:00
proto_hier_select_filter_cb ( widget , user_data , CALLBACK_MATCH ( ACTYPE_OR_SELECTED , 0 ) ) ;
2010-08-30 19:49:57 +00:00
}
static void
apply_as_and_not_selected_cb ( GtkWidget * widget , gpointer user_data )
{
2011-09-21 18:55:03 +00:00
proto_hier_select_filter_cb ( widget , user_data , CALLBACK_MATCH ( ACTYPE_AND_NOT_SELECTED , 0 ) ) ;
2010-08-30 19:49:57 +00:00
}
static void
apply_as_or_not_selected_cb ( GtkWidget * widget , gpointer user_data )
{
2011-09-21 18:55:03 +00:00
proto_hier_select_filter_cb ( widget , user_data , CALLBACK_MATCH ( ACTYPE_OR_NOT_SELECTED , 0 ) ) ;
2010-08-30 19:49:57 +00:00
}
static void
prep_as_selected_cb ( GtkWidget * widget , gpointer user_data )
{
2011-09-21 18:55:03 +00:00
proto_hier_select_filter_cb ( widget , user_data , CALLBACK_PREPARE ( ACTYPE_SELECTED , 0 ) ) ;
2010-08-30 19:49:57 +00:00
}
static void
prep_as_not_selected_cb ( GtkWidget * widget , gpointer user_data )
{
2011-09-21 18:55:03 +00:00
proto_hier_select_filter_cb ( widget , user_data , CALLBACK_PREPARE ( ACTYPE_NOT_SELECTED , 0 ) ) ;
2010-08-30 19:49:57 +00:00
}
static void
prep_as_and_selected_cb ( GtkWidget * widget , gpointer user_data )
{
2011-09-21 18:55:03 +00:00
proto_hier_select_filter_cb ( widget , user_data , CALLBACK_PREPARE ( ACTYPE_AND_SELECTED , 0 ) ) ;
2010-08-30 19:49:57 +00:00
}
static void
prep_as_or_selected_cb ( GtkWidget * widget , gpointer user_data )
{
2011-09-21 18:55:03 +00:00
proto_hier_select_filter_cb ( widget , user_data , CALLBACK_PREPARE ( ACTYPE_OR_SELECTED , 0 ) ) ;
2010-08-30 19:49:57 +00:00
}
static void
prep_as_and_not_selected_cb ( GtkWidget * widget , gpointer user_data )
{
2011-09-21 18:55:03 +00:00
proto_hier_select_filter_cb ( widget , user_data , CALLBACK_PREPARE ( ACTYPE_AND_NOT_SELECTED , 0 ) ) ;
2010-08-30 19:49:57 +00:00
}
static void
prep_as_or_not_selected_cb ( GtkWidget * widget , gpointer user_data )
{
2011-09-21 18:55:03 +00:00
proto_hier_select_filter_cb ( widget , user_data , CALLBACK_PREPARE ( ACTYPE_OR_NOT_SELECTED , 0 ) ) ;
2010-08-30 19:49:57 +00:00
}
static void
find_selected_cb ( GtkWidget * widget , gpointer user_data )
{
2011-09-21 18:55:03 +00:00
proto_hier_select_filter_cb ( widget , user_data , CALLBACK_FIND_FRAME ( ACTYPE_SELECTED , 0 ) ) ;
2010-08-30 19:49:57 +00:00
}
static void
find_not_selected_cb ( GtkWidget * widget , gpointer user_data )
{
2011-09-21 18:55:03 +00:00
proto_hier_select_filter_cb ( widget , user_data , CALLBACK_FIND_FRAME ( ACTYPE_NOT_SELECTED , 0 ) ) ;
2010-08-30 19:49:57 +00:00
}
static void
find_prev_selected_cb ( GtkWidget * widget , gpointer user_data )
{
2011-09-21 18:55:03 +00:00
proto_hier_select_filter_cb ( widget , user_data , CALLBACK_FIND_PREVIOUS ( ACTYPE_SELECTED , 0 ) ) ;
2010-08-30 19:49:57 +00:00
}
static void
find_prev_not_selected_cb ( GtkWidget * widget , gpointer user_data )
{
2011-09-21 18:55:03 +00:00
proto_hier_select_filter_cb ( widget , user_data , CALLBACK_FIND_PREVIOUS ( ACTYPE_NOT_SELECTED , 0 ) ) ;
2010-08-30 19:49:57 +00:00
}
static void
find_next_selected_cb ( GtkWidget * widget , gpointer user_data )
{
2011-09-21 18:55:03 +00:00
proto_hier_select_filter_cb ( widget , user_data , CALLBACK_FIND_NEXT ( ACTYPE_SELECTED , 0 ) ) ;
2010-08-30 19:49:57 +00:00
}
static void
find_next_not_selected_cb ( GtkWidget * widget , gpointer user_data )
{
2011-09-21 18:55:03 +00:00
proto_hier_select_filter_cb ( widget , user_data , CALLBACK_FIND_NEXT ( ACTYPE_NOT_SELECTED , 0 ) ) ;
2010-08-30 19:49:57 +00:00
}
static void
color_selected_cb ( GtkWidget * widget , gpointer user_data )
{
2011-09-21 18:55:03 +00:00
proto_hier_select_filter_cb ( widget , user_data , CALLBACK_COLORIZE ( ACTYPE_SELECTED , 0 ) ) ;
2010-08-30 19:49:57 +00:00
}
static const char * ui_desc_proto_hier_stats_filter_popup =
" <ui> \n "
" <popup name='ProtoHierStatsFilterPopup'> \n "
" <menu action='/Apply as Filter'> \n "
" <menuitem action='/Apply as Filter/Selected'/> \n "
2010-10-03 15:10:29 +00:00
" <menuitem action='/Apply as Filter/Not Selected'/> \n "
2010-10-03 16:09:25 +00:00
" <menuitem action='/Apply as Filter/ " UTF8_HORIZONTAL_ELLIPSIS " and Selected'/> \n "
" <menuitem action='/Apply as Filter/ " UTF8_HORIZONTAL_ELLIPSIS " or Selected'/> \n "
" <menuitem action='/Apply as Filter/ " UTF8_HORIZONTAL_ELLIPSIS " and not Selected'/> \n "
" <menuitem action='/Apply as Filter/ " UTF8_HORIZONTAL_ELLIPSIS " or not Selected'/> \n "
2010-08-30 19:49:57 +00:00
" </menu> \n "
" <menu action='/Prepare a Filter'> \n "
" <menuitem action='/Prepare a Filter/Selected'/> \n "
2010-10-03 15:10:29 +00:00
" <menuitem action='/Prepare a Filter/Not Selected'/> \n "
2010-10-03 16:09:25 +00:00
" <menuitem action='/Prepare a Filter/ " UTF8_HORIZONTAL_ELLIPSIS " and Selected'/> \n "
" <menuitem action='/Prepare a Filter/ " UTF8_HORIZONTAL_ELLIPSIS " or Selected'/> \n "
" <menuitem action='/Prepare a Filter/ " UTF8_HORIZONTAL_ELLIPSIS " and not Selected'/> \n "
" <menuitem action='/Prepare a Filter/ " UTF8_HORIZONTAL_ELLIPSIS " or not Selected'/> \n "
2010-08-30 19:49:57 +00:00
" </menu> \n "
" <menu action='/Find Frame'> \n "
" <menu action='/Find Frame/Find Frame'> \n "
" <menuitem action='/Find Frame/Selected'/> \n "
" <menuitem action='/Find Frame/Not Selected'/> \n "
" </menu> \n "
" <menu action='/Find Frame/Find Next'> \n "
" <menuitem action='/Find Next/Selected'/> \n "
" <menuitem action='/Find Next/Not Selected'/> \n "
" </menu> \n "
" <menu action='/Find Frame/Find Previous'> \n "
" <menuitem action='/Find Previous/Selected'/> \n "
" <menuitem action='/Find Previous/Not Selected'/> \n "
" </menu> \n "
" </menu> \n "
" <menu action='/Colorize Procedure'> \n "
" <menuitem action='/Colorize Procedure/Colorize Protocol'/> \n "
" </menu> \n "
" </popup> \n "
" </ui> \n " ;
/*
* GtkActionEntry
* typedef struct {
* const gchar * name ;
* const gchar * stock_id ;
* const gchar * label ;
* const gchar * accelerator ;
* const gchar * tooltip ;
* GCallback callback ;
* } GtkActionEntry ;
2011-09-21 18:55:03 +00:00
* const gchar * name ; The name of the action .
* const gchar * stock_id ; The stock id for the action , or the name of an icon from the icon theme .
* const gchar * label ; The label for the action . This field should typically be marked for translation ,
2010-08-30 19:49:57 +00:00
* see gtk_action_group_set_translation_domain ( ) .
2011-09-21 18:55:03 +00:00
* If label is NULL , the label of the stock item with id stock_id is used .
* const gchar * accelerator ; The accelerator for the action , in the format understood by gtk_accelerator_parse ( ) .
* const gchar * tooltip ; The tooltip for the action . This field should typically be marked for translation ,
* see gtk_action_group_set_translation_domain ( ) .
* GCallback callback ; The function to call when the action is activated .
2010-08-30 19:49:57 +00:00
*
*/
static const GtkActionEntry proto_hier_stats_popup_entries [ ] = {
2011-09-21 18:55:03 +00:00
{ " /Apply as Filter " , NULL , " Apply as Filter " , NULL , NULL , NULL } ,
{ " /Prepare a Filter " , NULL , " Prepare a Filter " , NULL , NULL , NULL } ,
{ " /Find Frame " , NULL , " Find Frame " , NULL , NULL , NULL } ,
{ " /Find Frame/Find Frame " , NULL , " Find Frame " , NULL , NULL , NULL } ,
{ " /Find Frame/Find Next " , NULL , " Find Next " , NULL , NULL , NULL } ,
{ " /Find Frame/Find Previous " , NULL , " Find Previous " , NULL , NULL , NULL } ,
{ " /Colorize Procedure " , NULL , " Colorize Procedure " , NULL , NULL , NULL } ,
{ " /Apply as Filter/Selected " , NULL , " Selected " , NULL , " Selected " , G_CALLBACK ( apply_as_selected_cb ) } ,
{ " /Apply as Filter/Not Selected " , NULL , " Not Selected " , NULL , " Not Selected " , G_CALLBACK ( apply_as_not_selected_cb ) } ,
{ " /Apply as Filter/ " UTF8_HORIZONTAL_ELLIPSIS " and Selected " , NULL , UTF8_HORIZONTAL_ELLIPSIS " and Selected " , NULL , UTF8_HORIZONTAL_ELLIPSIS " and Selected " , G_CALLBACK ( apply_as_and_selected_cb ) } ,
{ " /Apply as Filter/ " UTF8_HORIZONTAL_ELLIPSIS " or Selected " , NULL , UTF8_HORIZONTAL_ELLIPSIS " or Selected " , NULL , UTF8_HORIZONTAL_ELLIPSIS " or Selected " , G_CALLBACK ( apply_as_or_selected_cb ) } ,
{ " /Apply as Filter/ " UTF8_HORIZONTAL_ELLIPSIS " and not Selected " , NULL , UTF8_HORIZONTAL_ELLIPSIS " and not Selected " , NULL , UTF8_HORIZONTAL_ELLIPSIS " and not Selected " , G_CALLBACK ( apply_as_and_not_selected_cb ) } ,
{ " /Apply as Filter/ " UTF8_HORIZONTAL_ELLIPSIS " or not Selected " , NULL , UTF8_HORIZONTAL_ELLIPSIS " or not Selected " , NULL , UTF8_HORIZONTAL_ELLIPSIS " or not Selected " , G_CALLBACK ( apply_as_or_not_selected_cb ) } ,
{ " /Prepare a Filter/Selected " , NULL , " Selected " , NULL , " selcted " , G_CALLBACK ( prep_as_selected_cb ) } ,
{ " /Prepare a Filter/Not Selected " , NULL , " Not Selected " , NULL , " Not Selected " , G_CALLBACK ( prep_as_not_selected_cb ) } ,
{ " /Prepare a Filter/ " UTF8_HORIZONTAL_ELLIPSIS " and Selected " , NULL , UTF8_HORIZONTAL_ELLIPSIS " and Selected " , NULL , UTF8_HORIZONTAL_ELLIPSIS " and Selected " , G_CALLBACK ( prep_as_and_selected_cb ) } ,
{ " /Prepare a Filter/ " UTF8_HORIZONTAL_ELLIPSIS " or Selected " , NULL , UTF8_HORIZONTAL_ELLIPSIS " or Selected " , NULL , UTF8_HORIZONTAL_ELLIPSIS " or Selected " , G_CALLBACK ( prep_as_or_selected_cb ) } ,
{ " /Prepare a Filter/ " UTF8_HORIZONTAL_ELLIPSIS " and not Selected " , NULL , UTF8_HORIZONTAL_ELLIPSIS " and not Selected " , NULL , UTF8_HORIZONTAL_ELLIPSIS " and not Selected " , G_CALLBACK ( prep_as_and_not_selected_cb ) } ,
{ " /Prepare a Filter/ " UTF8_HORIZONTAL_ELLIPSIS " or not Selected " , NULL , UTF8_HORIZONTAL_ELLIPSIS " or not Selected " , NULL , UTF8_HORIZONTAL_ELLIPSIS " or not Selected " , G_CALLBACK ( prep_as_or_not_selected_cb ) } ,
{ " /Find Frame/Selected " , NULL , " Selected " , NULL , " Selected " , G_CALLBACK ( find_selected_cb ) } ,
{ " /Find Frame/Not Selected " , NULL , " Not Selected " , NULL , " Not Selected " , G_CALLBACK ( find_not_selected_cb ) } ,
{ " /Find Previous/Selected " , NULL , " Selected " , NULL , " Selected " , G_CALLBACK ( find_prev_selected_cb ) } ,
{ " /Find Previous/Not Selected " , NULL , " Not Selected " , NULL , " Not Selected " , G_CALLBACK ( find_prev_not_selected_cb ) } ,
{ " /Find Next/Selected " , NULL , " Selected " , NULL , " Selected " , G_CALLBACK ( find_next_selected_cb ) } ,
{ " /Find Next/Not Selected " , NULL , " Not Selected " , NULL , " Not Selected " , G_CALLBACK ( find_next_not_selected_cb ) } ,
{ " /Colorize Procedure/Colorize Protocol " , NULL , " Colorize Protocol " , NULL , " Colorize Protocol " , G_CALLBACK ( color_selected_cb ) } ,
2010-08-30 19:49:57 +00:00
} ;
2007-12-06 18:10:35 +00:00
2001-03-22 23:54:47 +00:00
static void
2002-11-03 17:38:45 +00:00
fill_in_tree_node ( GNode * node , gpointer data )
2001-03-22 23:54:47 +00:00
{
2002-11-03 17:38:45 +00:00
ph_stats_node_t * stats = node - > data ;
draw_info_t * di = data ;
2004-03-17 21:48:15 +00:00
ph_stats_t * ps = di - > ps ;
draw_info_t child_di ;
2005-08-10 19:49:45 +00:00
double seconds ;
gchar * text [ NUM_STAT_COLUMNS ] ;
2010-03-03 23:04:06 +00:00
float percent_packets , percent_bytes ;
2002-11-03 17:38:45 +00:00
GtkTreeView * tree_view = di - > tree_view ;
GtkTreeIter * iter = di - > iter ;
GtkTreeStore * store ;
GtkTreeIter new_iter ;
2004-03-17 21:48:15 +00:00
seconds = ps - > last_time - ps - > first_time ;
2010-03-03 23:04:06 +00:00
percent_packets = ( float ) PCT ( stats - > num_pkts_total , ps - > tot_packets ) ;
percent_bytes = ( float ) PCT ( stats - > num_bytes_total , ps - > tot_bytes ) ;
text [ PROTOCOL_COLUMN ] = ( gchar * ) ( stats - > hfinfo - > name ) ;
text [ PRCT_PKTS_COLUMN ] = g_strdup_printf ( " %.2f %% " , percent_packets ) ;
text [ PKTS_COLUMN ] = g_strdup_printf ( " %u " , stats - > num_pkts_total ) ;
text [ PRCT_BYTES_COLUMN ] = g_strdup_printf ( " %.2f %% " , percent_bytes ) ;
text [ BYTES_COLUMN ] = g_strdup_printf ( " %u " , stats - > num_bytes_total ) ;
2004-03-17 21:48:15 +00:00
if ( seconds > 0.0 ) {
2010-03-03 23:04:06 +00:00
text [ BANDWIDTH_COLUMN ] = g_strdup_printf ( " %.3f " ,
BANDWIDTH ( stats - > num_bytes_total , seconds ) ) ;
2004-03-17 21:48:15 +00:00
} else {
2010-03-03 23:04:06 +00:00
text [ BANDWIDTH_COLUMN ] = " n.c. " ;
2004-03-17 21:48:15 +00:00
}
2010-03-03 23:04:06 +00:00
text [ END_PKTS_COLUMN ] = g_strdup_printf ( " %u " , stats - > num_pkts_last ) ;
text [ END_BYTES_COLUMN ] = g_strdup_printf ( " %u " , stats - > num_bytes_last ) ;
2004-03-17 21:48:15 +00:00
if ( seconds > 0.0 ) {
2010-03-03 23:04:06 +00:00
text [ END_BANDWIDTH_COLUMN ] = g_strdup_printf ( " %.3f " ,
BANDWIDTH ( stats - > num_bytes_last , seconds ) ) ;
2004-03-17 21:48:15 +00:00
} else {
2010-03-03 23:04:06 +00:00
text [ END_BANDWIDTH_COLUMN ] = " n.c. " ;
2004-03-17 21:48:15 +00:00
}
2002-11-03 17:38:45 +00:00
store = GTK_TREE_STORE ( gtk_tree_view_get_model ( tree_view ) ) ;
gtk_tree_store_append ( store , & new_iter , iter ) ;
gtk_tree_store_set ( store , & new_iter ,
2010-03-03 23:04:06 +00:00
PROTOCOL_COLUMN , text [ PROTOCOL_COLUMN ] ,
PRCT_PKTS_COLUMN , text [ PRCT_PKTS_COLUMN ] ,
PKTS_COLUMN , text [ PKTS_COLUMN ] ,
PRCT_BYTES_COLUMN , text [ PRCT_BYTES_COLUMN ] ,
BYTES_COLUMN , text [ BYTES_COLUMN ] ,
BANDWIDTH_COLUMN , text [ BANDWIDTH_COLUMN ] ,
END_PKTS_COLUMN , text [ END_PKTS_COLUMN ] ,
END_BYTES_COLUMN , text [ END_BYTES_COLUMN ] ,
END_BANDWIDTH_COLUMN , text [ END_BANDWIDTH_COLUMN ] ,
FILTER_NAME , stats - > hfinfo - > abbrev ,
PRCT_PKTS_VALUE_COLUMN , percent_packets ,
PRCT_BYTES_VALUE_COLUMN , percent_bytes ,
2002-11-03 17:38:45 +00:00
- 1 ) ;
2001-03-22 23:54:47 +00:00
2010-03-03 23:04:06 +00:00
g_free ( text [ PRCT_PKTS_COLUMN ] ) ;
g_free ( text [ PKTS_COLUMN ] ) ;
g_free ( text [ PRCT_BYTES_COLUMN ] ) ;
g_free ( text [ BYTES_COLUMN ] ) ;
if ( seconds > 0.0 ) g_free ( text [ BANDWIDTH_COLUMN ] ) ;
g_free ( text [ END_PKTS_COLUMN ] ) ;
g_free ( text [ END_BYTES_COLUMN ] ) ;
if ( seconds > 0.0 ) g_free ( text [ END_BANDWIDTH_COLUMN ] ) ;
2002-11-03 17:38:45 +00:00
child_di . tree_view = tree_view ;
child_di . iter = & new_iter ;
child_di . ps = ps ;
2001-03-22 23:54:47 +00:00
2002-11-03 17:38:45 +00:00
g_node_children_foreach ( node , G_TRAVERSE_ALL ,
fill_in_tree_node , & child_di ) ;
2001-03-22 23:54:47 +00:00
}
static void
2010-01-29 19:09:01 +00:00
fill_in_tree ( GtkWidget * tree_lcl , ph_stats_t * ps )
2001-03-22 23:54:47 +00:00
{
2010-03-03 23:04:06 +00:00
draw_info_t di ;
2001-03-22 23:54:47 +00:00
2010-01-29 19:09:01 +00:00
di . tree_view = GTK_TREE_VIEW ( tree_lcl ) ;
2009-03-19 17:47:00 +00:00
di . iter = NULL ;
di . ps = ps ;
2001-03-22 23:54:47 +00:00
2009-03-19 17:47:00 +00:00
g_node_children_foreach ( ps - > stats_tree , G_TRAVERSE_ALL ,
fill_in_tree_node , & di ) ;
2001-03-22 23:54:47 +00:00
}
2007-12-08 22:45:30 +00:00
2010-07-30 12:41:56 +00:00
static gboolean
2010-08-30 19:49:57 +00:00
proto_hier_show_popup_menu_cb ( GtkWidget * widget _U_ , GdkEvent * event , GtkWidget * popup_menu_object )
2007-12-08 22:45:30 +00:00
{
GdkEventButton * bevent = ( GdkEventButton * ) event ;
2010-03-03 23:04:06 +00:00
if ( event - > type = = GDK_BUTTON_PRESS & & bevent - > button = = 3 ) {
2007-12-08 22:45:30 +00:00
/* If this is a right click on one of our columns, popup the context menu */
2010-03-03 23:04:06 +00:00
gtk_menu_popup ( GTK_MENU ( popup_menu_object ) , NULL , NULL , NULL , NULL , bevent - > button , bevent - > time ) ;
2007-12-08 22:45:30 +00:00
}
return FALSE ;
}
2007-12-06 18:10:35 +00:00
static void
proto_hier_create_popup_menu ( void )
{
2011-09-21 18:55:03 +00:00
GtkUIManager * ui_manager ;
GtkActionGroup * action_group ;
GError * error = NULL ;
GtkWidget * popup_menu_object ;
action_group = gtk_action_group_new ( " ProtoHierStatsTFilterPopupActionGroup " ) ;
gtk_action_group_add_actions ( action_group , /* the action group */
( gpointer ) proto_hier_stats_popup_entries , /* an array of action descriptions */
G_N_ELEMENTS ( proto_hier_stats_popup_entries ) , /* the number of entries */
NULL ) ; /* data to pass to the action callbacks */
ui_manager = gtk_ui_manager_new ( ) ;
gtk_ui_manager_insert_action_group ( ui_manager ,
action_group ,
0 ) ; /* the position at which the group will be inserted */
gtk_ui_manager_add_ui_from_string ( ui_manager , ui_desc_proto_hier_stats_filter_popup , - 1 , & error ) ;
if ( error ! = NULL )
2010-08-30 19:49:57 +00:00
{
fprintf ( stderr , " Warning: building proto hier ststs filter popup failed: %s \n " ,
error - > message ) ;
g_error_free ( error ) ;
error = NULL ;
}
2011-09-21 18:55:03 +00:00
popup_menu_object = gtk_ui_manager_get_widget ( ui_manager , " /ProtoHierStatsFilterPopup " ) ;
g_signal_connect ( tree , " button_press_event " , G_CALLBACK ( proto_hier_show_popup_menu_cb ) , popup_menu_object ) ;
2010-09-02 15:38:04 +00:00
2007-12-06 18:10:35 +00:00
}
2001-12-31 20:40:34 +00:00
# define MAX_DLG_HEIGHT 450
2004-03-17 21:48:15 +00:00
# define DEF_DLG_WIDTH 700
2001-03-22 23:54:47 +00:00
static void
2001-03-24 02:07:22 +00:00
create_tree ( GtkWidget * container , ph_stats_t * ps )
2001-03-22 23:54:47 +00:00
{
2011-09-21 18:55:03 +00:00
GtkWidget * sw ;
2002-11-03 17:38:45 +00:00
GtkTreeView * tree_view ;
GtkTreeStore * store ;
GtkCellRenderer * renderer ;
GtkTreeViewColumn * column ;
2001-03-22 23:54:47 +00:00
2002-11-03 17:38:45 +00:00
/* Scrolled Window */
2004-02-06 19:19:12 +00:00
sw = scrolled_window_new ( NULL , NULL ) ;
2011-07-11 18:18:35 +00:00
gtk_scrolled_window_set_shadow_type ( GTK_SCROLLED_WINDOW ( sw ) ,
2009-03-19 17:47:00 +00:00
GTK_SHADOW_IN ) ;
2002-11-03 17:38:45 +00:00
gtk_container_add ( GTK_CONTAINER ( container ) , sw ) ;
2010-03-03 23:04:06 +00:00
store = gtk_tree_store_new ( NUM_STAT_COLUMNS , G_TYPE_STRING , G_TYPE_STRING ,
2008-05-18 19:49:12 +00:00
G_TYPE_STRING , G_TYPE_STRING , G_TYPE_STRING ,
2011-07-11 18:18:35 +00:00
G_TYPE_STRING , G_TYPE_STRING , G_TYPE_STRING ,
2010-03-03 23:04:06 +00:00
G_TYPE_STRING , G_TYPE_POINTER , G_TYPE_FLOAT ,
G_TYPE_FLOAT ) ;
2002-11-03 17:38:45 +00:00
tree = tree_view_new ( GTK_TREE_MODEL ( store ) ) ;
2008-01-31 16:37:56 +00:00
g_object_unref ( G_OBJECT ( store ) ) ;
2002-11-03 17:38:45 +00:00
tree_view = GTK_TREE_VIEW ( tree ) ;
gtk_tree_view_set_headers_visible ( tree_view , TRUE ) ;
gtk_tree_view_set_headers_clickable ( tree_view , FALSE ) ;
renderer = gtk_cell_renderer_text_new ( ) ;
column = gtk_tree_view_column_new_with_attributes ( " Protocol " , renderer ,
" text " , PROTOCOL_COLUMN ,
NULL ) ;
gtk_tree_view_column_set_sizing ( column , GTK_TREE_VIEW_COLUMN_AUTOSIZE ) ;
gtk_tree_view_append_column ( tree_view , column ) ;
2008-05-17 22:57:53 +00:00
renderer = gtk_cell_renderer_progress_new ( ) ;
2002-11-03 17:38:45 +00:00
column = gtk_tree_view_column_new_with_attributes ( " % Packets " , renderer ,
2008-05-18 19:49:12 +00:00
" text " , PRCT_PKTS_COLUMN ,
2010-03-03 23:04:06 +00:00
" value " , PRCT_PKTS_VALUE_COLUMN ,
2002-11-03 17:38:45 +00:00
NULL ) ;
2010-03-03 23:04:06 +00:00
gtk_tree_view_column_set_expand ( column , TRUE ) ;
2002-11-03 17:38:45 +00:00
gtk_tree_view_column_set_sizing ( column , GTK_TREE_VIEW_COLUMN_AUTOSIZE ) ;
gtk_tree_view_append_column ( tree_view , column ) ;
renderer = gtk_cell_renderer_text_new ( ) ;
column = gtk_tree_view_column_new_with_attributes ( " Packets " , renderer ,
" text " , PKTS_COLUMN ,
NULL ) ;
g_object_set ( G_OBJECT ( renderer ) , " xalign " , 1.0 , NULL ) ;
gtk_tree_view_column_set_sizing ( column , GTK_TREE_VIEW_COLUMN_AUTOSIZE ) ;
gtk_tree_view_append_column ( tree_view , column ) ;
2010-03-03 23:04:06 +00:00
renderer = gtk_cell_renderer_progress_new ( ) ;
column = gtk_tree_view_column_new_with_attributes ( " % Bytes " , renderer ,
" text " , PRCT_BYTES_COLUMN ,
" value " , PRCT_BYTES_VALUE_COLUMN ,
NULL ) ;
gtk_tree_view_column_set_expand ( column , TRUE ) ;
gtk_tree_view_column_set_sizing ( column , GTK_TREE_VIEW_COLUMN_AUTOSIZE ) ;
gtk_tree_view_append_column ( tree_view , column ) ;
2002-11-03 17:38:45 +00:00
renderer = gtk_cell_renderer_text_new ( ) ;
column = gtk_tree_view_column_new_with_attributes ( " Bytes " , renderer ,
" text " , BYTES_COLUMN ,
NULL ) ;
g_object_set ( G_OBJECT ( renderer ) , " xalign " , 1.0 , NULL ) ;
gtk_tree_view_column_set_sizing ( column , GTK_TREE_VIEW_COLUMN_AUTOSIZE ) ;
gtk_tree_view_append_column ( tree_view , column ) ;
renderer = gtk_cell_renderer_text_new ( ) ;
2004-03-17 21:48:15 +00:00
column = gtk_tree_view_column_new_with_attributes ( " Mbit/s " , renderer ,
2010-03-03 23:04:06 +00:00
" text " , BANDWIDTH_COLUMN ,
2004-03-17 21:48:15 +00:00
NULL ) ;
g_object_set ( G_OBJECT ( renderer ) , " xalign " , 1.0 , NULL ) ;
gtk_tree_view_column_set_sizing ( column , GTK_TREE_VIEW_COLUMN_AUTOSIZE ) ;
gtk_tree_view_append_column ( tree_view , column ) ;
renderer = gtk_cell_renderer_text_new ( ) ;
2010-03-03 23:04:06 +00:00
column = gtk_tree_view_column_new_with_attributes ( " End Packets " , renderer ,
" text " , END_PKTS_COLUMN ,
NULL ) ;
2002-11-03 17:38:45 +00:00
g_object_set ( G_OBJECT ( renderer ) , " xalign " , 1.0 , NULL ) ;
gtk_tree_view_column_set_sizing ( column , GTK_TREE_VIEW_COLUMN_AUTOSIZE ) ;
gtk_tree_view_append_column ( tree_view , column ) ;
renderer = gtk_cell_renderer_text_new ( ) ;
column = gtk_tree_view_column_new_with_attributes ( " End Bytes " , renderer ,
" text " , END_BYTES_COLUMN ,
NULL ) ;
g_object_set ( G_OBJECT ( renderer ) , " xalign " , 1.0 , NULL ) ;
gtk_tree_view_column_set_sizing ( column , GTK_TREE_VIEW_COLUMN_AUTOSIZE ) ;
gtk_tree_view_append_column ( tree_view , column ) ;
2004-03-17 21:48:15 +00:00
renderer = gtk_cell_renderer_text_new ( ) ;
column = gtk_tree_view_column_new_with_attributes ( " End Mbit/s " , renderer ,
2010-03-03 23:04:06 +00:00
" text " , END_BANDWIDTH_COLUMN ,
2004-03-17 21:48:15 +00:00
NULL ) ;
g_object_set ( G_OBJECT ( renderer ) , " xalign " , 1.0 , NULL ) ;
gtk_tree_view_column_set_sizing ( column , GTK_TREE_VIEW_COLUMN_AUTOSIZE ) ;
gtk_tree_view_append_column ( tree_view , column ) ;
2001-03-22 23:54:47 +00:00
2002-11-03 17:38:45 +00:00
/* Fill in the data. */
fill_in_tree ( tree , ps ) ;
2001-03-22 23:54:47 +00:00
2008-04-11 20:31:05 +00:00
gtk_widget_set_size_request ( tree , DEF_DLG_WIDTH , MAX_DLG_HEIGHT ) ;
2004-05-01 18:40:20 +00:00
gtk_tree_view_expand_all ( tree_view ) ;
2001-03-22 23:54:47 +00:00
2007-12-06 18:10:35 +00:00
proto_hier_create_popup_menu ( ) ;
2002-11-03 17:38:45 +00:00
gtk_container_add ( GTK_CONTAINER ( sw ) , tree ) ;
2001-03-22 23:54:47 +00:00
}
2005-08-20 14:08:53 +00:00
void
2002-03-05 11:56:00 +00:00
proto_hier_stats_cb ( GtkWidget * w _U_ , gpointer d _U_ )
2001-03-22 23:54:47 +00:00
{
2010-03-03 23:04:06 +00:00
ph_stats_t * ps ;
GtkWidget * dlg , * close_bt , * help_bt , * vbox , * bbox ;
GtkWidget * label ;
char title [ 256 ] ;
const char * current_filter ;
2009-03-19 17:47:00 +00:00
/* Get the statistics. */
ps = ph_stats_new ( ) ;
if ( ps = = NULL ) {
/* The user gave up before we finished; don't pop up
a statistics window . */
return ;
}
2001-03-24 02:07:22 +00:00
2009-03-19 17:47:00 +00:00
dlg = window_new ( GTK_WINDOW_TOPLEVEL , " Wireshark: Protocol Hierarchy Statistics " ) ;
2001-03-22 23:54:47 +00:00
2012-04-21 17:06:30 +00:00
vbox = ws_gtk_box_new ( GTK_ORIENTATION_VERTICAL , 5 , FALSE ) ;
2009-03-19 17:47:00 +00:00
gtk_container_set_border_width ( GTK_CONTAINER ( vbox ) , 5 ) ;
gtk_container_add ( GTK_CONTAINER ( dlg ) , vbox ) ;
2001-03-22 23:54:47 +00:00
2009-03-19 17:47:00 +00:00
current_filter = gtk_entry_get_text ( GTK_ENTRY ( main_display_filter_widget ) ) ;
2007-12-06 18:10:35 +00:00
2009-03-19 17:47:00 +00:00
if ( current_filter & & strlen ( current_filter ) ! = 0 ) {
g_snprintf ( title , sizeof ( title ) , " Display filter: %s " , current_filter ) ;
} else {
g_strlcpy ( title , " Display filter: none " , sizeof ( title ) ) ;
}
label = gtk_label_new ( title ) ;
gtk_box_pack_start ( GTK_BOX ( vbox ) , label , FALSE , FALSE , 0 ) ;
2007-11-30 15:37:21 +00:00
2009-03-19 17:47:00 +00:00
/* Data section */
create_tree ( vbox , ps ) ;
2004-01-21 21:19:34 +00:00
2009-03-19 17:47:00 +00:00
ph_stats_free ( ps ) ;
2004-03-17 21:48:15 +00:00
2009-03-19 17:47:00 +00:00
/* Button row. */
bbox = dlg_button_row_new ( GTK_STOCK_CLOSE , GTK_STOCK_HELP , NULL ) ;
gtk_box_pack_end ( GTK_BOX ( vbox ) , bbox , FALSE , FALSE , 0 ) ;
gtk_widget_show ( bbox ) ;
2001-03-22 23:54:47 +00:00
2009-03-19 17:47:00 +00:00
close_bt = g_object_get_data ( G_OBJECT ( bbox ) , GTK_STOCK_CLOSE ) ;
window_set_cancel_button ( dlg , close_bt , window_cancel_button_cb ) ;
2001-03-22 23:54:47 +00:00
2009-03-19 17:47:00 +00:00
help_bt = g_object_get_data ( G_OBJECT ( bbox ) , GTK_STOCK_HELP ) ;
g_signal_connect ( help_bt , " clicked " , G_CALLBACK ( topic_cb ) , ( gpointer ) HELP_STATS_PROTO_HIERARCHY_DIALOG ) ;
2005-01-20 23:17:23 +00:00
2009-03-19 17:47:00 +00:00
g_signal_connect ( dlg , " delete_event " , G_CALLBACK ( window_delete_event_cb ) , NULL ) ;
2001-03-22 23:54:47 +00:00
2009-03-19 17:47:00 +00:00
gtk_widget_show_all ( dlg ) ;
window_present ( dlg ) ;
2001-03-22 23:54:47 +00:00
}
2009-03-19 17:47:00 +00:00
/*
* Editor modelines
*
* Local Variables :
* c - basic - offset : 4
* tab - width : 8
* indent - tabs - mode : nil
* End :
*
2011-09-21 17:49:11 +00:00
* ex : set shiftwidth = 4 tabstop = 8 expandtab :
2009-03-19 17:47:00 +00:00
* : indentSize = 4 : tabSize = 8 : noTabs = true :
*/