FIRST_PROTO_PREFS_PAGE needs to be incremented by 2 in order for
[obnox/wireshark/wip.git] / gtk / summary_dlg.c
1 /* summary_dlg.c
2  * Routines for capture file summary window
3  *
4  * $Id: summary_dlg.c,v 1.11 2002/02/08 10:07:38 guy Exp $
5  *
6  * Ethereal - Network traffic analyzer
7  * By Gerald Combs <gerald@zing.org>
8  * Copyright 1998 Gerald Combs
9  *
10  *
11  * This program is free software; you can redistribute it and/or
12  * modify it under the terms of the GNU General Public License
13  * as published by the Free Software Foundation; either version 2
14  * of the License, or (at your option) any later version.
15  *
16  * This program is distributed in the hope that it will be useful,
17  * but WITHOUT ANY WARRANTY; without even the implied warranty of
18  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
19  * GNU General Public License for more details.
20  *
21  * You should have received a copy of the GNU General Public License
22  * along with this program; if not, write to the Free Software
23  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
24  */
25
26
27 #ifdef HAVE_CONFIG_H
28 # include "config.h"
29 #endif
30
31 #include <gtk/gtk.h>
32
33 #include <stdio.h>
34 #include <string.h>
35 #include <wtap.h>
36
37 #ifdef NEED_SNPRINTF_H
38 # include "snprintf.h"
39 #endif
40
41 #include "summary.h"
42 #include "summary_dlg.h"
43 #include "dlg_utils.h"
44 #include "ui_util.h"
45
46 #define SUM_STR_MAX 1024
47
48
49 static void
50 add_string_to_box(gchar *str, GtkWidget *box)
51 {
52   GtkWidget *lb;
53   lb = gtk_label_new(str);
54   gtk_misc_set_alignment(GTK_MISC(lb), 0.0, 0.5);
55   gtk_box_pack_start(GTK_BOX(box), lb,FALSE,FALSE, 0);
56   gtk_widget_show(lb);
57 }
58
59
60 void
61 summary_open_cb(GtkWidget *w, gpointer d)
62 {
63   summary_tally summary;
64   GtkWidget     *sum_open_w,
65                 *main_vb, *file_fr, *data_fr, *capture_fr, *file_box, 
66                 *data_box, *capture_box, *bbox, *close_bt;
67
68   gchar          string_buff[SUM_STR_MAX];
69
70   double         seconds;
71
72  /* initialize the tally */
73   summary_fill_in(&summary);
74
75   /* initial compututations */
76   seconds = summary.stop_time - summary.start_time;
77   sum_open_w = gtk_window_new(GTK_WINDOW_TOPLEVEL);
78   gtk_window_set_title(GTK_WINDOW(sum_open_w), "Ethereal: Summary");
79   gtk_signal_connect (GTK_OBJECT (sum_open_w), "realize",
80     GTK_SIGNAL_FUNC (window_icon_realize_cb), NULL);
81
82   /* Container for each row of widgets */
83   main_vb = gtk_vbox_new(FALSE, 3);
84   gtk_container_border_width(GTK_CONTAINER(main_vb), 5);
85   gtk_container_add(GTK_CONTAINER(sum_open_w), main_vb);
86   gtk_widget_show(main_vb);
87
88   /* File frame */
89   file_fr = gtk_frame_new("File");
90   gtk_container_add(GTK_CONTAINER(main_vb), file_fr);
91   gtk_widget_show(file_fr);
92
93   file_box = gtk_vbox_new(FALSE, 3);
94   gtk_container_add(GTK_CONTAINER(file_fr), file_box);
95   gtk_widget_show(file_box);
96
97   /* filename */
98   snprintf(string_buff, SUM_STR_MAX, "Name: %s", summary.filename);
99   add_string_to_box(string_buff, file_box);
100
101   /* length */
102   snprintf(string_buff, SUM_STR_MAX, "Length: %lu", summary.file_length);
103   add_string_to_box(string_buff, file_box);
104
105   /* format */
106   snprintf(string_buff, SUM_STR_MAX, "Format: %s", wtap_file_type_string(summary.encap_type));
107   add_string_to_box(string_buff, file_box);
108
109   if (summary.has_snap) {
110     /* snapshot length */
111     snprintf(string_buff, SUM_STR_MAX, "Snapshot length: %u", summary.snap);
112     add_string_to_box(string_buff, file_box);
113   }
114
115   /* Data frame */
116   data_fr = gtk_frame_new("Data");
117   gtk_container_add(GTK_CONTAINER(main_vb), data_fr);
118   gtk_widget_show(data_fr);
119
120   data_box = gtk_vbox_new(FALSE, 3);
121   gtk_container_add(GTK_CONTAINER(data_fr), data_box);
122   gtk_widget_show(data_box);
123
124   /* seconds */
125   snprintf(string_buff, SUM_STR_MAX, "Elapsed time: %.3f seconds", summary.elapsed_time);
126   add_string_to_box(string_buff, data_box);
127
128   snprintf(string_buff, SUM_STR_MAX, "Between first and last packet: %.3f seconds", seconds);
129   add_string_to_box(string_buff, data_box);
130
131   /* Packet count */
132   snprintf(string_buff, SUM_STR_MAX, "Packet count: %i", summary.packet_count);
133   add_string_to_box(string_buff, data_box);
134
135   /* Filtered Packet count */
136   snprintf(string_buff, SUM_STR_MAX, "Filtered packet count: %i", summary.filtered_count);
137   add_string_to_box(string_buff, data_box);
138
139   /* Marked Packet count */
140   snprintf(string_buff, SUM_STR_MAX, "Marked packet count: %i", summary.marked_count);
141   add_string_to_box(string_buff, data_box);
142
143   /* Packets per second */
144   if (seconds > 0){
145     snprintf(string_buff, SUM_STR_MAX, "Avg. packets/sec: %.3f", summary.packet_count/seconds);
146     add_string_to_box(string_buff, data_box);
147   }
148
149   /* Dropped count */
150   if (summary.drops_known) {
151     snprintf(string_buff, SUM_STR_MAX, "Dropped packets: %u", summary.drops);
152     add_string_to_box(string_buff, data_box);
153   }
154
155   /* Byte count */
156   snprintf(string_buff, SUM_STR_MAX, "Bytes of traffic: %d", summary.bytes);
157   add_string_to_box(string_buff, data_box);
158
159   /* Bytes per second */
160   if (seconds > 0){
161     snprintf(string_buff, SUM_STR_MAX, "Avg. bytes/sec: %.3f", summary.bytes/seconds);
162     add_string_to_box(string_buff, data_box);
163
164     /* MBit per second */
165     snprintf(string_buff, SUM_STR_MAX, "Avg. Mbit/sec: %.3f", summary.bytes*8/(seconds*1000*1000));
166     add_string_to_box(string_buff, data_box);
167   }
168
169   /* Capture frame */
170   capture_fr = gtk_frame_new("Capture");
171   gtk_container_add(GTK_CONTAINER(main_vb), capture_fr);
172   gtk_widget_show(capture_fr);
173
174   capture_box = gtk_vbox_new(FALSE, 3);
175   gtk_container_add(GTK_CONTAINER(capture_fr), capture_box);
176   gtk_widget_show(capture_box);
177
178
179   /* interface */
180   if (summary.iface) {
181     snprintf(string_buff, SUM_STR_MAX, "Interface: %s", summary.iface);
182   } else {
183     sprintf(string_buff, "Interface: unknown");
184   }
185   add_string_to_box(string_buff, capture_box);
186
187   /* Display filter */
188   if (summary.dfilter) {
189     snprintf(string_buff, SUM_STR_MAX, "Display filter: %s", summary.dfilter);
190   } else {
191     sprintf(string_buff, "Display filter: none");
192   }
193   add_string_to_box(string_buff, capture_box);
194
195 #ifdef HAVE_LIBPCAP
196   /* Capture filter */
197   if (summary.cfilter && summary.cfilter[0] != '\0') {
198     snprintf(string_buff, SUM_STR_MAX, "Capture filter: %s", summary.cfilter);
199   } else {
200     sprintf(string_buff, "Capture filter: none");
201   }
202   add_string_to_box(string_buff, capture_box);
203 #endif
204
205   /* Button row: close button.
206      (We put it in an HButtonBox, even though there's only one of them,
207      so that it doesn't expand to the width of the window.  */
208   bbox = gtk_hbutton_box_new();
209   gtk_button_box_set_spacing(GTK_BUTTON_BOX(bbox), 5);
210   gtk_container_add(GTK_CONTAINER(main_vb), bbox);
211   gtk_widget_show(bbox);
212
213   /* Create Close Button */
214   close_bt = gtk_button_new_with_label("Close");
215   gtk_signal_connect_object(GTK_OBJECT(close_bt), "clicked",
216     GTK_SIGNAL_FUNC(gtk_widget_destroy),
217     GTK_OBJECT(sum_open_w));
218   GTK_WIDGET_SET_FLAGS(close_bt, GTK_CAN_DEFAULT);
219   gtk_box_pack_start(GTK_BOX(bbox), close_bt, FALSE,FALSE, 0);
220   gtk_widget_grab_default(close_bt);
221   gtk_widget_show(close_bt);
222
223   /* Catch the "key_press_event" signal in the window, so that we can catch
224      the ESC key being pressed and act as if the "Close" button had
225      been selected. */
226   dlg_set_cancel(sum_open_w, close_bt);
227
228   gtk_window_set_position(GTK_WINDOW(sum_open_w), GTK_WIN_POS_MOUSE);
229   gtk_widget_show(sum_open_w);
230 }