1 /* proto_hier_stats_dlg.c
3 * $Id: proto_hier_stats_dlg.c,v 1.1 2001/03/22 23:54:47 gram Exp $
5 * Ethereal - Network traffic analyzer
6 * By Gerald Combs <gerald@zing.org>
7 * Copyright 1998 Gerald Combs
10 * This program is free software; you can redistribute it and/or
11 * modify it under the terms of the GNU General Public License
12 * as published by the Free Software Foundation; either version 2
13 * of the License, or (at your option) any later version.
15 * This program is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU General Public License for more details.
20 * You should have received a copy of the GNU General Public License
21 * along with this program; if not, write to the Free Software
22 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
32 #include "proto_hier_stats.h"
33 #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);
116 create_tree(GtkWidget *container)
118 GtkWidget *sw, *tree;
121 gchar *column_titles[NUM_STAT_COLUMNS] = {
123 "Percentage Packets",
126 "Last-Protocol Packets",
127 "Last-Protocol Bytes",
132 /* Scrolled Window */
133 sw = gtk_scrolled_window_new(NULL, NULL);
134 gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(sw),
135 GTK_POLICY_AUTOMATIC,
136 GTK_POLICY_AUTOMATIC);
137 gtk_container_add(GTK_CONTAINER(container), sw);
139 tree = gtk_ctree_new_with_titles(NUM_STAT_COLUMNS, 0, column_titles);
141 /* XXX - get 'pos' to set vertical scroll-bar placement. */
142 /* XXX - set line style from preferences ???. */
144 /* The titel bars do nothing. */
145 gtk_clist_column_titles_passive(GTK_CLIST(tree));
147 /* Auto Resize all columns */
148 for (i = 0; i < NUM_STAT_COLUMNS; i++) {
149 gtk_clist_set_column_auto_resize(GTK_CLIST(tree), i, TRUE);
153 /* Right justify numeric columns */
154 for (i = 1; i <= 5; i++) {
155 gtk_clist_set_column_justification(GTK_CLIST(tree), i,
159 /* Fill in the data. */
160 fill_in_ctree(tree, ps);
162 /* Try to size the CTree to a good initial size.
163 * 5 is a magic number that I pulled out off my hat.
164 * Using DEF_WIDTH is pretty bogus, too. */
165 height = GTK_CLIST(tree)->rows * (GTK_CLIST(tree)->row_height + 5);
166 gtk_widget_set_usize(tree, DEF_WIDTH, height);
169 gtk_container_add(GTK_CONTAINER(sw), tree);
174 proto_hier_stats_cb(GtkWidget *w, gpointer d)
176 GtkWidget *dlg, *bt, *vbox, *frame, *bbox;
177 const gchar *wname = "Protocol Hierarchy Statistics";
179 dlg = dlg_window_new(wname);
181 vbox = gtk_vbox_new(FALSE, 5);
182 gtk_container_border_width(GTK_CONTAINER(vbox), 5);
183 gtk_container_add(GTK_CONTAINER(dlg), vbox);
185 frame = gtk_frame_new(wname);
186 /*gtk_container_add(GTK_CONTAINER(vbox), frame);*/
187 gtk_box_pack_start(GTK_BOX(vbox), frame, TRUE, TRUE, 0);
193 /* Button row. We put it in an HButtonBox to
194 * keep it from expanding to the width of the window. */
195 bbox = gtk_hbutton_box_new();
196 gtk_button_box_set_spacing(GTK_BUTTON_BOX(bbox), 5);
197 /*gtk_container_add(GTK_CONTAINER(vbox), bbox);*/
198 gtk_box_pack_start(GTK_BOX(vbox), bbox, FALSE, FALSE, 0);
201 bt = gtk_button_new_with_label("Close");
202 gtk_signal_connect_object(GTK_OBJECT(bt), "clicked",
203 GTK_SIGNAL_FUNC(gtk_widget_destroy),
205 gtk_container_add(GTK_CONTAINER(bbox), bt);
206 GTK_WIDGET_SET_FLAGS(bt, GTK_CAN_DEFAULT);
207 gtk_widget_grab_default(bt);
208 dlg_set_cancel(dlg, bt);
210 gtk_widget_show_all(dlg);