08e0cbb9b276b1b98b16c34a9138102cad7e85bb
[metze/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.8 2000/08/21 18:20:19 deniel 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
45 #define SUM_STR_MAX 1024
46
47
48 static void
49 add_string_to_box(gchar *str, GtkWidget *box)
50 {
51   GtkWidget *lb;
52   lb = gtk_label_new(str);
53   gtk_misc_set_alignment(GTK_MISC(lb), 0.0, 0.5);
54   gtk_box_pack_start(GTK_BOX(box), lb,FALSE,FALSE, 0);
55   gtk_widget_show(lb);
56 }
57
58
59 void
60 summary_open_cb(GtkWidget *w, gpointer d)
61 {
62   summary_tally summary;
63   GtkWidget     *sum_open_w,
64                 *main_vb, *file_fr, *data_fr, *capture_fr, *file_box, 
65                 *data_box, *capture_box, *bbox, *close_bt;
66
67   gchar          string_buff[SUM_STR_MAX];
68
69   double         seconds;
70
71  /* initialize the tally */
72   summary_fill_in(&summary);
73
74   /* initial compututations */
75   seconds = summary.stop_time - summary.start_time;
76   sum_open_w = gtk_window_new(GTK_WINDOW_TOPLEVEL);
77   gtk_window_set_title(GTK_WINDOW(sum_open_w), "Ethereal: Summary");
78
79   /* Container for each row of widgets */
80   main_vb = gtk_vbox_new(FALSE, 3);
81   gtk_container_border_width(GTK_CONTAINER(main_vb), 5);
82   gtk_container_add(GTK_CONTAINER(sum_open_w), main_vb);
83   gtk_widget_show(main_vb);
84
85   /* File frame */
86   file_fr = gtk_frame_new("File");
87   gtk_container_add(GTK_CONTAINER(main_vb), file_fr);
88   gtk_widget_show(file_fr);
89
90   file_box = gtk_vbox_new(FALSE, 3);
91   gtk_container_add(GTK_CONTAINER(file_fr), file_box);
92   gtk_widget_show(file_box);
93
94   /* filename */
95   snprintf(string_buff, SUM_STR_MAX, "Name: %s", summary.filename);
96   add_string_to_box(string_buff, file_box);
97
98   /* length */
99   snprintf(string_buff, SUM_STR_MAX, "Length: %lu", summary.file_length);
100   add_string_to_box(string_buff, file_box);
101
102   /* format */
103   snprintf(string_buff, SUM_STR_MAX, "Format: %s", wtap_file_type_string(summary.encap_type));
104   add_string_to_box(string_buff, file_box);
105
106   /* snapshot length */
107   snprintf(string_buff, SUM_STR_MAX, "Snapshot length: %u", summary.snap);
108   add_string_to_box(string_buff, file_box);
109
110   /* Data frame */
111   data_fr = gtk_frame_new("Data");
112   gtk_container_add(GTK_CONTAINER(main_vb), data_fr);
113   gtk_widget_show(data_fr);
114
115   data_box = gtk_vbox_new(FALSE, 3);
116   gtk_container_add(GTK_CONTAINER(data_fr), data_box);
117   gtk_widget_show(data_box);
118
119   /* seconds */
120   snprintf(string_buff, SUM_STR_MAX, "Elapsed time: %.3f seconds", summary.elapsed_time);
121   add_string_to_box(string_buff, data_box);
122
123   snprintf(string_buff, SUM_STR_MAX, "Between first and last packet: %.3f seconds", seconds);
124   add_string_to_box(string_buff, data_box);
125
126   /* Packet count */
127   snprintf(string_buff, SUM_STR_MAX, "Packet count: %i", summary.packet_count);
128   add_string_to_box(string_buff, data_box);
129
130   /* Filtered Packet count */
131   snprintf(string_buff, SUM_STR_MAX, "Filtered packet count: %i", summary.filtered_count);
132   add_string_to_box(string_buff, data_box);
133
134   /* Marked Packet count */
135   snprintf(string_buff, SUM_STR_MAX, "Marked packet count: %i", summary.marked_count);
136   add_string_to_box(string_buff, data_box);
137
138   /* Packets per second */
139   if (seconds > 0){
140     snprintf(string_buff, SUM_STR_MAX, "Avg. packets/sec: %.3f", summary.packet_count/seconds);
141     add_string_to_box(string_buff, data_box);
142   }
143
144   /* Dropped count */
145   snprintf(string_buff, SUM_STR_MAX, "Dropped packets: %i", summary.drops);
146   add_string_to_box(string_buff, data_box);
147
148   /* Byte count */
149   snprintf(string_buff, SUM_STR_MAX, "Bytes of traffic: %d", summary.bytes);
150   add_string_to_box(string_buff, data_box);
151
152   /* Bytes per second */
153   if (seconds > 0){
154     snprintf(string_buff, SUM_STR_MAX, "Avg. bytes/sec: %.3f", summary.bytes/seconds);
155     add_string_to_box(string_buff, data_box);
156
157     /* MBit per second */
158     snprintf(string_buff, SUM_STR_MAX, "Avg. Mbit/sec: %.3f", summary.bytes*8/(seconds*1000*1000));
159     add_string_to_box(string_buff, data_box);
160   }
161
162   /* Capture frame */
163   capture_fr = gtk_frame_new("Capture");
164   gtk_container_add(GTK_CONTAINER(main_vb), capture_fr);
165   gtk_widget_show(capture_fr);
166
167   capture_box = gtk_vbox_new(FALSE, 3);
168   gtk_container_add(GTK_CONTAINER(capture_fr), capture_box);
169   gtk_widget_show(capture_box);
170
171
172   /* interface */
173   if (summary.iface) {
174     snprintf(string_buff, SUM_STR_MAX, "Interface: %s", summary.iface);
175   } else {
176     sprintf(string_buff, "Interface: unknown");
177   }
178   add_string_to_box(string_buff, capture_box);
179
180   /* Display filter */
181   if (summary.dfilter) {
182     snprintf(string_buff, SUM_STR_MAX, "Display filter: %s", summary.dfilter);
183   } else {
184     sprintf(string_buff, "Display filter: none");
185   }
186   add_string_to_box(string_buff, capture_box);
187
188 #ifdef HAVE_LIBPCAP
189   /* Capture filter */
190   if (summary.cfilter && summary.cfilter[0] != '\0') {
191     snprintf(string_buff, SUM_STR_MAX, "Capture filter: %s", summary.cfilter);
192   } else {
193     sprintf(string_buff, "Capture filter: none");
194   }
195   add_string_to_box(string_buff, capture_box);
196 #endif
197
198   /* Button row: close button.
199      (We put it in an HButtonBox, even though there's only one of them,
200      so that it doesn't expand to the width of the window.  */
201   bbox = gtk_hbutton_box_new();
202   gtk_button_box_set_spacing(GTK_BUTTON_BOX(bbox), 5);
203   gtk_container_add(GTK_CONTAINER(main_vb), bbox);
204   gtk_widget_show(bbox);
205
206   /* Create Close Button */
207   close_bt = gtk_button_new_with_label("Close");
208   gtk_signal_connect_object(GTK_OBJECT(close_bt), "clicked",
209     GTK_SIGNAL_FUNC(gtk_widget_destroy),
210     GTK_OBJECT(sum_open_w));
211   GTK_WIDGET_SET_FLAGS(close_bt, GTK_CAN_DEFAULT);
212   gtk_box_pack_start(GTK_BOX(bbox), close_bt, FALSE,FALSE, 0);
213   gtk_widget_grab_default(close_bt);
214   gtk_widget_show(close_bt);
215
216   /* Catch the "key_press_event" signal in the window, so that we can catch
217      the ESC key being pressed and act as if the "Close" button had
218      been selected. */
219   dlg_set_cancel(sum_open_w, close_bt);
220
221   gtk_window_set_position(GTK_WINDOW(sum_open_w), GTK_WIN_POS_MOUSE);
222   gtk_widget_show(sum_open_w);
223 }