1 /* proto_hier_stats_dlg.c
3 * $Id: proto_hier_stats_dlg.c,v 1.10 2002/08/28 21:03:49 jmayer Exp $
5 * Ethereal - Network traffic analyzer
6 * By Gerald Combs <gerald@ethereal.com>
7 * Copyright 1998 Gerald Combs
9 * This program is free software; you can redistribute it and/or
10 * modify it under the terms of the GNU General Public License
11 * as published by the Free Software Foundation; either version 2
12 * of the License, or (at your option) any later version.
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
19 * You should have received a copy of the GNU General Public License
20 * along with this program; if not, write to the Free Software
21 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
31 #include "proto_hier_stats.h"
32 #include "dlg_utils.h"
36 #define NUM_STAT_COLUMNS 6
47 #define PCT(x,y) (100.0 * (float)(x) / (float)(y))
50 fill_in_ctree_node(GNode *node, gpointer data)
52 ph_stats_node_t *stats = node->data;
53 draw_info_t *di = data;
55 GtkCTree *tree = di->tree;
56 GtkCTreeNode *parent = di->parent;
57 ph_stats_t *ps = di->ps;
59 gchar *text[NUM_STAT_COLUMNS];
61 GtkCTreeNode *new_node;
65 if (g_node_n_children(node) > 0) {
72 text[0] = stats->hfinfo->name;
73 text[1] = g_strdup_printf("%6.2f%%",
74 PCT(stats->num_pkts_total, ps->tot_packets));
75 text[2] = g_strdup_printf("%u", stats->num_pkts_total);
76 text[3] = g_strdup_printf("%u", stats->num_bytes_total);
77 text[4] = g_strdup_printf("%u", stats->num_pkts_last);
78 text[5] = g_strdup_printf("%u", stats->num_bytes_last);
80 new_node = gtk_ctree_insert_node(tree, parent, NULL, text,
81 5, NULL, NULL, NULL, NULL,
92 child_di.parent = new_node;
95 g_node_children_foreach(node, G_TRAVERSE_ALL,
96 fill_in_ctree_node, &child_di);
103 fill_in_ctree(GtkWidget *tree, ph_stats_t *ps)
107 di.tree = GTK_CTREE(tree);
111 g_node_children_foreach(ps->stats_tree, G_TRAVERSE_ALL,
112 fill_in_ctree_node, &di);
115 #define MAX_DLG_HEIGHT 450
116 #define DEF_DLG_WIDTH 600
118 create_tree(GtkWidget *container, ph_stats_t *ps)
120 GtkWidget *sw, *tree;
122 gchar *column_titles[NUM_STAT_COLUMNS] = {
131 /* Scrolled Window */
132 sw = gtk_scrolled_window_new(NULL, NULL);
133 gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(sw),
134 GTK_POLICY_AUTOMATIC,
135 GTK_POLICY_AUTOMATIC);
136 gtk_container_add(GTK_CONTAINER(container), sw);
138 tree = ctree_new_with_titles(NUM_STAT_COLUMNS, 0, column_titles);
140 /* XXX - get 'pos' to set vertical scroll-bar placement. */
142 /* The title bars do nothing. */
143 gtk_clist_column_titles_passive(GTK_CLIST(tree));
145 /* Auto Resize all columns */
146 for (i = 0; i < NUM_STAT_COLUMNS; i++) {
147 gtk_clist_set_column_auto_resize(GTK_CLIST(tree), i, TRUE);
151 /* Right justify numeric columns */
152 for (i = 1; i <= 5; i++) {
153 gtk_clist_set_column_justification(GTK_CLIST(tree), i,
157 /* Fill in the data. */
158 fill_in_ctree(tree, ps);
160 height = GTK_CLIST(tree)->rows * (GTK_CLIST(tree)->row_height + 5);
161 height = MIN(height, MAX_DLG_HEIGHT);
162 gtk_widget_set_usize(tree, DEF_DLG_WIDTH, height);
165 gtk_container_add(GTK_CONTAINER(sw), tree);
169 #define WNAME "Protocol Hierarchy Statistics"
172 proto_hier_stats_cb(GtkWidget *w _U_, gpointer d _U_)
175 GtkWidget *dlg, *bt, *vbox, *frame, *bbox;
177 /* Get the statistics. */
180 /* The user gave up before we finished; don't pop up
181 a statistics window. */
185 dlg = gtk_window_new(GTK_WINDOW_TOPLEVEL);
186 gtk_window_set_title(GTK_WINDOW(dlg), "Ethereal: " WNAME);
187 gtk_signal_connect (GTK_OBJECT (dlg), "realize",
188 GTK_SIGNAL_FUNC (window_icon_realize_cb), NULL);
190 vbox = gtk_vbox_new(FALSE, 5);
191 gtk_container_border_width(GTK_CONTAINER(vbox), 5);
192 gtk_container_add(GTK_CONTAINER(dlg), vbox);
194 frame = gtk_frame_new(WNAME);
195 /*gtk_container_add(GTK_CONTAINER(vbox), frame);*/
196 gtk_box_pack_start(GTK_BOX(vbox), frame, TRUE, TRUE, 0);
200 create_tree(frame, ps);
202 /* Button row. We put it in an HButtonBox to
203 * keep it from expanding to the width of the window. */
204 bbox = gtk_hbutton_box_new();
205 gtk_button_box_set_spacing(GTK_BUTTON_BOX(bbox), 5);
206 /*gtk_container_add(GTK_CONTAINER(vbox), bbox);*/
207 gtk_box_pack_start(GTK_BOX(vbox), bbox, FALSE, FALSE, 0);
210 bt = gtk_button_new_with_label("Close");
211 gtk_signal_connect_object(GTK_OBJECT(bt), "clicked",
212 GTK_SIGNAL_FUNC(gtk_widget_destroy),
214 gtk_container_add(GTK_CONTAINER(bbox), bt);
215 GTK_WIDGET_SET_FLAGS(bt, GTK_CAN_DEFAULT);
216 gtk_widget_grab_default(bt);
217 dlg_set_cancel(dlg, bt);
219 gtk_widget_show_all(dlg);