Add text import capability, like text2pcap, directly into the GUI.
[obnox/wireshark/wip.git] / gtk / summary_dlg.c
index 1a765a8aba320e56e346017f34ee5895c40506c1..192ef3e58a0bb31b05490980085045bfd11f6894 100644 (file)
 # include "config.h"
 #endif
 
+#ifdef HAVE_SYS_TYPES_H
+#include <sys/types.h>
+#endif
 #include <string.h>
+#include <time.h>
 
 #include <gtk/gtk.h>
 
-#include <wtap.h>
-#include <time.h>
+#include <epan/strutil.h>
 
-#include "globals.h"
-#include "file.h"
+#include <wiretap/wtap.h>
+
+#include "../globals.h"
+#include "../file.h"
+#include "../summary.h"
 #ifdef HAVE_LIBPCAP
-#include "capture.h"
-#include "main.h"
+#include "../capture.h"
+#include "gtk/main.h"
+#include "gtk/capture_globals.h"
 #endif
-#include "summary.h"
-#include "summary_dlg.h"
-#include "dlg_utils.h"
-#include "gui_utils.h"
-#include "compat_macros.h"
-#include "help_dlg.h"
+
+#include "gtk/summary_dlg.h"
+#include "gtk/dlg_utils.h"
+#include "gtk/gui_utils.h"
+#include "gtk/help_dlg.h"
+
 
 #define SUM_STR_MAX     1024
 #define FILTER_SNIP_LEN 50
@@ -62,13 +69,18 @@ add_string_to_table_sensitive(GtkWidget *list, guint *row, const gchar *title, c
         indent = g_strdup(title);
     }
     label = gtk_label_new(indent);
+    if (strlen(value) == 0) {
+      gchar *message = g_strdup_printf("<span weight=\"bold\">%s</span>", title);
+      gtk_label_set_markup(GTK_LABEL(label), message);
+      g_free (message);
+    }
     g_free(indent);
-    gtk_misc_set_alignment(GTK_MISC(label), 0.0, 0.5);
+    gtk_misc_set_alignment(GTK_MISC(label), 0.0f, 0.5f);
     gtk_widget_set_sensitive(label, sensitive);
     gtk_table_attach_defaults(GTK_TABLE(list), label, 0, 1, *row, *row+1);
 
     label = gtk_label_new(value);
-    gtk_misc_set_alignment(GTK_MISC(label), 0.0, 0.5);
+    gtk_misc_set_alignment(GTK_MISC(label), 0.0f, 0.5f);
     gtk_widget_set_sensitive(label, sensitive);
     gtk_table_attach_defaults(GTK_TABLE(list), label, 1, 2, *row, *row+1);
 
@@ -83,9 +95,9 @@ add_string_to_table(GtkWidget *list, guint *row, gchar *title, gchar *value)
 
 
 static void
-add_string_to_list(GtkWidget *list, gchar *title, gchar *captured, gchar *displayed)
+add_string_to_list(GtkWidget *list, gchar *title, gchar *captured, gchar *displayed, gchar *marked)
 {
-    simple_list_append(list, 0, title, 1, captured, 2, displayed, -1);
+    simple_list_append(list, 0, title, 1, captured, 2, displayed, 3, marked, -1);
 }
 
 void
@@ -96,13 +108,15 @@ summary_open_cb(GtkWidget *w _U_, gpointer d _U_)
                 *main_vb, *bbox, *close_bt, *help_bt;
   GtkWidget     *table;
   GtkWidget     *list;
-  static const char *titles[] = { "Traffic", "Captured", "Displayed" };
+  static const char *titles[] = { "Traffic", "Captured", "Displayed", "Marked" };
 
   gchar         string_buff[SUM_STR_MAX];
   gchar         string_buff2[SUM_STR_MAX];
+  gchar         string_buff3[SUM_STR_MAX];
 
   double        seconds;
   double        disp_seconds;
+  double        marked_seconds;
   guint         offset;
   guint         snip;
   guint         row;
@@ -116,16 +130,17 @@ summary_open_cb(GtkWidget *w _U_, gpointer d _U_)
   /* initial computations */
   summary_fill_in(&cfile, &summary);
 #ifdef HAVE_LIBPCAP
-  summary_fill_in_capture(capture_opts, &summary);
+  summary_fill_in_capture(&global_capture_opts, &summary);
 #endif
   seconds = summary.stop_time - summary.start_time;
   disp_seconds = summary.filtered_stop - summary.filtered_start;
+  marked_seconds = summary.marked_stop - summary.marked_start;
 
   sum_open_w = window_new(GTK_WINDOW_TOPLEVEL, "Wireshark: Summary");
 
   /* Container for each row of widgets */
   main_vb = gtk_vbox_new(FALSE, 12);
-  gtk_container_border_width(GTK_CONTAINER(main_vb), 12);
+  gtk_container_set_border_width(GTK_CONTAINER(main_vb), 12);
   gtk_container_add(GTK_CONTAINER(sum_open_w), main_vb);
 
   /* table */
@@ -144,13 +159,17 @@ summary_open_cb(GtkWidget *w _U_, gpointer d _U_)
   add_string_to_table(table, &row, "Name:", string_buff);
 
   /* length */
-  g_snprintf(string_buff, SUM_STR_MAX, "%lld bytes", (long long) summary.file_length);
+  g_snprintf(string_buff, SUM_STR_MAX, "%" G_GINT64_MODIFIER "d bytes", summary.file_length);
   add_string_to_table(table, &row, "Length:", string_buff);
 
   /* format */
-  g_snprintf(string_buff, SUM_STR_MAX, "%s", wtap_file_type_string(summary.encap_type));
+  g_snprintf(string_buff, SUM_STR_MAX, "%s", wtap_file_type_string(summary.file_type));
   add_string_to_table(table, &row, "Format:", string_buff);
 
+  /* encapsulation */
+  g_snprintf(string_buff, SUM_STR_MAX, "%s", wtap_encap_string(summary.encap_type));
+  add_string_to_table(table, &row, "Encapsulation:", string_buff);
+
   if (summary.has_snap) {
     /* snapshot length */
     g_snprintf(string_buff, SUM_STR_MAX, "%u bytes", summary.snap);
@@ -191,10 +210,10 @@ summary_open_cb(GtkWidget *w _U_, gpointer d _U_)
   /* elapsed seconds */
   elapsed_time = (unsigned int)summary.elapsed_time;
   if(elapsed_time/86400) {
-      g_snprintf(string_buff, SUM_STR_MAX, "%02u days %02u:%02u:%02u", 
+      g_snprintf(string_buff, SUM_STR_MAX, "%02u days %02u:%02u:%02u",
         elapsed_time/86400, elapsed_time%86400/3600, elapsed_time%3600/60, elapsed_time%60);
   } else {
-      g_snprintf(string_buff, SUM_STR_MAX, "%02u:%02u:%02u", 
+      g_snprintf(string_buff, SUM_STR_MAX, "%02u:%02u:%02u",
         elapsed_time%86400/3600, elapsed_time%3600/60, elapsed_time%60);
   }
   add_string_to_table(table, &row, "Elapsed:", string_buff);
@@ -214,7 +233,7 @@ summary_open_cb(GtkWidget *w _U_, gpointer d _U_)
 
   /* Dropped count */
   if (summary.drops_known) {
-    g_snprintf(string_buff, SUM_STR_MAX, "%" PRIu64, summary.drops);
+    g_snprintf(string_buff, SUM_STR_MAX, "%" G_GINT64_MODIFIER "u", summary.drops);
   } else {
     g_snprintf(string_buff, SUM_STR_MAX, "unknown");
   }
@@ -254,7 +273,7 @@ summary_open_cb(GtkWidget *w _U_, gpointer d _U_)
         str_work = g_strdup(&str_dup[offset]);
         snip++;
     }
-    
+
     add_string_to_table(table, &row, (snip == 0) ? "Display filter:" : "", str_work);
     g_free(str_work);
     g_free(str_dup);
@@ -263,122 +282,157 @@ summary_open_cb(GtkWidget *w _U_, gpointer d _U_)
     add_string_to_table(table, &row, "Display filter:", "none");
   }
 
-  /* Marked Packet count */
-  g_snprintf(string_buff, SUM_STR_MAX, "%i", summary.marked_count);
-  add_string_to_table(table, &row, "Marked packets:", string_buff);
-
+  /* Ignored packet count */
+  g_snprintf(string_buff, SUM_STR_MAX, "%i", summary.ignored_count);
+  add_string_to_table(table, &row, "Ignored packets:", string_buff);
 
   /* Traffic */
-  list = simple_list_new(3, titles);
+  list = simple_list_new(4, titles);
   gtk_container_add(GTK_CONTAINER(main_vb), list);
 
-  g_snprintf(string_buff, SUM_STR_MAX, "%.3f sec", seconds);
-  if(summary.dfilter) {
-    g_snprintf(string_buff2, SUM_STR_MAX, "%.3f sec", disp_seconds);
-  } else {
-    strcpy(string_buff2, "");
-  }
-  add_string_to_list(list, "Between first and last packet", string_buff, string_buff2);
-
   /* Packet count */
   g_snprintf(string_buff, SUM_STR_MAX, "%i", summary.packet_count);
-  if(summary.dfilter) {
+  if (summary.dfilter) {
     g_snprintf(string_buff2, SUM_STR_MAX, "%i", summary.filtered_count);
   } else {
-    strcpy(string_buff2, "");
+    g_strlcpy(string_buff2, string_buff, SUM_STR_MAX);
   }
-  add_string_to_list(list, "Packets", string_buff, string_buff2);
+  g_snprintf(string_buff3, SUM_STR_MAX, "%i", summary.marked_count);
+  add_string_to_list(list, "Packets", string_buff, string_buff2, string_buff3);
+
+  /* Time between first and last */
+  if (seconds > 0) {
+    g_snprintf(string_buff, SUM_STR_MAX, "%.3f sec", seconds);
+  } else {
+    string_buff[0] = '\0';
+  }
+  if (summary.dfilter && disp_seconds > 0) {
+    g_snprintf(string_buff2, SUM_STR_MAX, "%.3f sec", disp_seconds);
+  } else {
+    string_buff2[0] = '\0';
+  }
+  if (summary.marked_count && marked_seconds > 0) {
+    g_snprintf(string_buff3, SUM_STR_MAX, "%.3f sec", marked_seconds);
+  } else {
+    string_buff3[0] = '\0';
+  }
+  add_string_to_list(list, "Between first and last packet", string_buff, string_buff2, string_buff3);
 
   /* Packets per second */
-  if (seconds > 0){
+  if (seconds > 0) {
     g_snprintf(string_buff, SUM_STR_MAX, "%.3f", summary.packet_count/seconds);
   } else {
-    strcpy(string_buff, "");
+    string_buff[0] = '\0';
   }
-  if(summary.dfilter && disp_seconds > 0){
+  if(summary.dfilter && disp_seconds > 0) {
     g_snprintf(string_buff2, SUM_STR_MAX, "%.3f", summary.filtered_count/disp_seconds);
   } else {
-    strcpy(string_buff2, "");
+    string_buff2[0] = '\0';
+  }
+  if(summary.marked_count && marked_seconds > 0) {
+    g_snprintf(string_buff3, SUM_STR_MAX, "%.3f", summary.marked_count/marked_seconds);
+  } else {
+    string_buff3[0] = '\0';
   }
-  add_string_to_list(list, "Avg. packets/sec", string_buff, string_buff2);
+  add_string_to_list(list, "Avg. packets/sec", string_buff, string_buff2, string_buff3);
 
   /* Packet size */
-  if (summary.packet_count > 0){
+  if (summary.packet_count > 1) {
     g_snprintf(string_buff, SUM_STR_MAX, "%.3f bytes",
-      /* MSVC cannot convert from unsigned __int64 to float, so first convert to signed __int64 */
-      (float) (gint64) (summary.bytes/summary.packet_count) );
+              /* MSVC cannot convert from unsigned __int64 to float, so first convert to signed __int64 */
+              (float) ((gint64) summary.bytes)/summary.packet_count);
   } else {
-    strcpy(string_buff, "");
+    string_buff[0] = '\0';
   }
-  if (summary.dfilter && summary.filtered_count > 0){
+  if (summary.dfilter && summary.filtered_count > 1) {
     g_snprintf(string_buff2, SUM_STR_MAX, "%.3f bytes",
-          /* MSVC cannot convert from unsigned __int64 to float, so first convert to signed __int64 */
-          (float) (gint64) summary.filtered_bytes/summary.filtered_count);
+              /* MSVC cannot convert from unsigned __int64 to float, so first convert to signed __int64 */
+              (float) ((gint64) summary.filtered_bytes)/summary.filtered_count);
   } else {
-    strcpy(string_buff2, "");
+    string_buff2[0] = '\0';
   }
-  add_string_to_list(list, "Avg. packet size", string_buff, string_buff2);
+  if (summary.marked_count > 1) {
+    g_snprintf(string_buff3, SUM_STR_MAX, "%.3f bytes",
+              /* MSVC cannot convert from unsigned __int64 to float, so first convert to signed __int64 */
+              (float) ((gint64) summary.marked_bytes)/summary.marked_count);
+  } else {
+    string_buff3[0] = '\0';
+  }
+  add_string_to_list(list, "Avg. packet size", string_buff, string_buff2, string_buff3);
 
   /* Byte count */
-  g_snprintf(string_buff, SUM_STR_MAX, "%" PRIu64, summary.bytes);
-  if (summary.dfilter && summary.filtered_count > 0){
-    g_snprintf(string_buff2, SUM_STR_MAX, "%" PRIu64, summary.filtered_bytes);
+  g_snprintf(string_buff, SUM_STR_MAX, "%" G_GINT64_MODIFIER "u", summary.bytes);
+  if (summary.dfilter && summary.filtered_count > 0) {
+    g_snprintf(string_buff2, SUM_STR_MAX, "%" G_GINT64_MODIFIER "u", summary.filtered_bytes);
   } else {
-    strcpy(string_buff2, "");
+    string_buff2[0] = '\0';
   }
-  add_string_to_list(list, "Bytes", string_buff, string_buff2);
+  if (summary.marked_count) {
+    g_snprintf(string_buff3, SUM_STR_MAX, "%" G_GINT64_MODIFIER "u", summary.marked_bytes);
+  } else {
+    string_buff3[0] = '\0';
+  }
+  add_string_to_list(list, "Bytes", string_buff, string_buff2, string_buff3);
 
   /* Bytes per second */
   if (seconds > 0){
     /* MSVC cannot convert from unsigned __int64 to float, so first convert to signed __int64 */
-    g_snprintf(string_buff, SUM_STR_MAX, "%.3f", ((gint64) summary.bytes)/seconds );
+    g_snprintf(string_buff, SUM_STR_MAX, "%.3f", ((gint64) summary.bytes)/seconds);
+  } else {
+    string_buff[0] = '\0';
+  }
+  if (summary.dfilter && disp_seconds > 0) {
+    /* MSVC cannot convert from unsigned __int64 to float, so first convert to signed __int64 */
+    g_snprintf(string_buff2, SUM_STR_MAX, "%.3f", ((gint64) summary.filtered_bytes)/disp_seconds);
   } else {
-    strcpy(string_buff, "");
+    string_buff2[0] = '\0';
   }
-  if (summary.dfilter && disp_seconds > 0){
+  if (summary.marked_count && marked_seconds > 0) {
     /* MSVC cannot convert from unsigned __int64 to float, so first convert to signed __int64 */
-    g_snprintf(string_buff2, SUM_STR_MAX, "%.3f", ((gint64) summary.filtered_bytes)/disp_seconds );
+    g_snprintf(string_buff3, SUM_STR_MAX, "%.3f", ((gint64) summary.marked_bytes)/marked_seconds);
   } else {
-    strcpy(string_buff2, "");
+    string_buff3[0] = '\0';
   }
-  add_string_to_list(list, "Avg. bytes/sec", string_buff, string_buff2);
+  add_string_to_list(list, "Avg. bytes/sec", string_buff, string_buff2, string_buff3);
 
   /* MBit per second */
-  if (seconds > 0){
-    /* MSVC cannot convert from unsigned __int64 to float, so first convert to signed __int64 */
-    g_snprintf(string_buff, SUM_STR_MAX, "%.3f", ((gint64) summary.bytes) * 8.0 / (seconds * 1000.0 * 1000.0));
+  if (seconds > 0) {
+    g_snprintf(string_buff, SUM_STR_MAX, "%.3f",
+              /* MSVC cannot convert from unsigned __int64 to float, so first convert to signed __int64 */
+              ((gint64) summary.bytes) * 8.0 / (seconds * 1000.0 * 1000.0));
   } else {
-    strcpy(string_buff, "");
+    string_buff[0] = '\0';
   }
-  if (summary.dfilter && disp_seconds > 0){
-    g_snprintf(string_buff2, SUM_STR_MAX, "%.3f", 
-          /* MSVC cannot convert from unsigned __int64 to float, so first convert to signed __int64 */
-          ((gint64) summary.filtered_bytes) * 8.0 / (disp_seconds * 1000.0 * 1000.0));
+  if (summary.dfilter && disp_seconds > 0) {
+    g_snprintf(string_buff2, SUM_STR_MAX, "%.3f",
+              /* MSVC cannot convert from unsigned __int64 to float, so first convert to signed __int64 */
+              ((gint64) summary.filtered_bytes) * 8.0 / (disp_seconds * 1000.0 * 1000.0));
   } else {
-    strcpy(string_buff2, "");
+    string_buff2[0] = '\0';
   }
-  add_string_to_list(list, "Avg. MBit/sec", string_buff, string_buff2);
-
-  
-  /* Button row. */
-  if(topic_available(HELP_STATS_SUMMARY_DIALOG)) {
-    bbox = dlg_button_row_new(GTK_STOCK_CLOSE, GTK_STOCK_HELP, NULL);
+  if (summary.marked_count && marked_seconds > 0) {
+    g_snprintf(string_buff3, SUM_STR_MAX, "%.3f",
+              /* MSVC cannot convert from unsigned __int64 to float, so first convert to signed __int64 */
+              ((gint64) summary.marked_bytes) * 8.0 / (marked_seconds * 1000.0 * 1000.0));
   } else {
-    bbox = dlg_button_row_new(GTK_STOCK_CLOSE, NULL);
+    string_buff3[0] = '\0';
   }
+  add_string_to_list(list, "Avg. MBit/sec", string_buff, string_buff2, string_buff3);
+
+
+  /* Button row. */
+  bbox = dlg_button_row_new(GTK_STOCK_CLOSE, GTK_STOCK_HELP, NULL);
   gtk_container_add(GTK_CONTAINER(main_vb), bbox);
 
-  close_bt = OBJECT_GET_DATA(bbox, GTK_STOCK_CLOSE);
+  close_bt = g_object_get_data(G_OBJECT(bbox), GTK_STOCK_CLOSE);
   window_set_cancel_button(sum_open_w, close_bt, window_cancel_button_cb);
 
-  if(topic_available(HELP_STATS_SUMMARY_DIALOG)) {
-    help_bt = OBJECT_GET_DATA(bbox, GTK_STOCK_HELP);
-    SIGNAL_CONNECT(help_bt, "clicked", topic_cb, HELP_STATS_SUMMARY_DIALOG);
-  }
+  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_SUMMARY_DIALOG);
 
   gtk_widget_grab_focus(close_bt);
 
-  SIGNAL_CONNECT(sum_open_w, "delete_event", window_delete_event_cb, NULL);
+  g_signal_connect(sum_open_w, "delete_event", G_CALLBACK(window_delete_event_cb), NULL);
 
   gtk_widget_show_all(sum_open_w);
   window_present(sum_open_w);