some more : try to make read/write not break the build if the return value is not...
[obnox/wireshark/wip.git] / gtk / capture_file_dlg.c
index 6c9232e20a47d7c8c8d20eb9036b991b4300c375..c707a6be73bad6e061bf4dbcec5534139acd99ea 100644 (file)
@@ -3,8 +3,8 @@
  *
  * $Id$
  *
- * Ethereal - Network traffic analyzer
- * By Gerald Combs <gerald@ethereal.com>
+ * Wireshark - Network traffic analyzer
+ * By Gerald Combs <gerald@wireshark.org>
  * Copyright 1998 Gerald Combs
  *
  * This program is free software; you can redistribute it and/or
@@ -43,6 +43,7 @@
 #include "simple_dialog.h"
 #include "menu.h"
 #include "dlg_utils.h"
+#include "file_dlg.h"
 #include "capture_file_dlg.h"
 #include "main.h"
 #include "compat_macros.h"
@@ -76,9 +77,9 @@ static void file_merge_destroy_cb(GtkWidget *win, gpointer user_data);
 static void select_file_type_cb(GtkWidget *w, gpointer data);
 static void file_save_as_ok_cb(GtkWidget *w, gpointer fs);
 static void file_save_as_destroy_cb(GtkWidget *win, gpointer user_data);
-static void file_color_import_ok_cb(GtkWidget *w, gpointer fs);
+static void file_color_import_ok_cb(GtkWidget *w, gpointer filter_list);
 static void file_color_import_destroy_cb(GtkWidget *win, gpointer user_data);
-static void file_color_export_ok_cb(GtkWidget *w, gpointer fs);
+static void file_color_export_ok_cb(GtkWidget *w, gpointer filter_list);
 static void file_color_export_destroy_cb(GtkWidget *win, gpointer user_data);
 static void set_file_type_list(GtkWidget *option_menu);
 
@@ -90,8 +91,6 @@ static void set_file_type_list(GtkWidget *option_menu);
 #define E_MERGE_CHRONO_KEY           "merge_dlg_chrono_key"
 #define E_MERGE_APPEND_KEY           "merge_dlg_append_key"
 
-#define ARGUMENT_CL "argument_cl"
-
 
 #define PREVIEW_TABLE_KEY       "preview_table_key"
 #define PREVIEW_FILENAME_KEY    "preview_filename_key"
@@ -112,9 +111,9 @@ static GtkWidget *file_save_as_w;
 
 /* XXX - can we make these not be static? */
 static packet_range_t range;
-static gboolean color_marked;
+static gboolean color_selected;
 static int filetype;
-static GtkWidget *cfmark_cb;
+static GtkWidget *cfselect_cb;
 static GtkWidget *ft_om;
 static GtkWidget *range_tb;
 
@@ -201,7 +200,7 @@ preview_do(GtkWidget *prev, wtap *wth)
     time_t      time_current;
     int         err = 0;
     gchar      *err_info;
-    long        data_offset;
+    gint64      data_offset;
     const struct wtap_pkthdr *phdr;
     double      start_time = 0;        /* seconds, with nsec resolution */
     double      stop_time = 0; /* seconds, with nsec resolution */
@@ -216,7 +215,7 @@ preview_do(GtkWidget *prev, wtap *wth)
     time(&time_preview);
     while ( (wtap_read(wth, &err, &err_info, &data_offset)) ) {
         phdr = wtap_phdr(wth);
-        cur_time = nstime_to_sec( (const nstime_t *) &phdr->ts );
+        cur_time = wtap_nstime_to_sec(&phdr->ts);
         if(packets == 0) {
             start_time         = cur_time;
             stop_time = cur_time;
@@ -439,7 +438,7 @@ file_open_cmd(GtkWidget *w)
   /* No Apply button, and "OK" just sets our text widget, it doesn't
      activate it (i.e., it doesn't cause us to try to open the file). */
   static construct_args_t args = {
-       "Ethereal: Read Filter",
+       "Wireshark: Read Filter",
        FALSE,
        FALSE,
     TRUE
@@ -451,7 +450,7 @@ file_open_cmd(GtkWidget *w)
     return;
   }
 
-  file_open_w = file_selection_new("Ethereal: Open Capture File",
+  file_open_w = file_selection_new("Wireshark: Open Capture File",
                                    FILE_SELECTION_OPEN);
 #if (GTK_MAJOR_VERSION == 2 && GTK_MINOR_VERSION >= 4) || GTK_MAJOR_VERSION > 2
   /* it's annoying, that the file chooser dialog is already shown here,
@@ -506,7 +505,7 @@ file_open_cmd(GtkWidget *w)
   gtk_box_pack_start(GTK_BOX(main_vb), filter_hbox, FALSE, FALSE, 0);
   gtk_widget_show(filter_hbox);
 
-  filter_bt = BUTTON_NEW_FROM_STOCK(ETHEREAL_STOCK_DISPLAY_FILTER_ENTRY);
+  filter_bt = BUTTON_NEW_FROM_STOCK(WIRESHARK_STOCK_DISPLAY_FILTER_ENTRY);
   SIGNAL_CONNECT(filter_bt, "clicked", display_filter_construct_cb, &args);
   SIGNAL_CONNECT(filter_bt, "destroy", filter_button_destroy_cb, NULL);
   gtk_box_pack_start(GTK_BOX(filter_hbox), filter_bt, FALSE, TRUE, 0);
@@ -775,7 +774,7 @@ file_merge_cmd(GtkWidget *w)
   /* No Apply button, and "OK" just sets our text widget, it doesn't
      activate it (i.e., it doesn't cause us to try to open the file). */
   static construct_args_t args = {
-       "Ethereal: Read Filter",
+       "Wireshark: Read Filter",
        FALSE,
        FALSE,
     TRUE
@@ -790,7 +789,7 @@ file_merge_cmd(GtkWidget *w)
   /* Default to saving all packets, in the file's current format. */
   filetype = cfile.cd_t;
 
-  file_merge_w = file_selection_new("Ethereal: Merge with Capture File",
+  file_merge_w = file_selection_new("Wireshark: Merge with Capture File",
                                    FILE_SELECTION_OPEN);
 #if (GTK_MAJOR_VERSION == 2 && GTK_MINOR_VERSION >= 4) || GTK_MAJOR_VERSION > 2
   /* it's annoying, that the file chooser dialog is already shown here,
@@ -860,7 +859,7 @@ file_merge_cmd(GtkWidget *w)
   gtk_box_pack_start(GTK_BOX(main_vb), filter_hbox, FALSE, FALSE, 0);
   gtk_widget_show(filter_hbox);
 
-  filter_bt = BUTTON_NEW_FROM_STOCK(ETHEREAL_STOCK_DISPLAY_FILTER_ENTRY);
+  filter_bt = BUTTON_NEW_FROM_STOCK(WIRESHARK_STOCK_DISPLAY_FILTER_ENTRY);
   SIGNAL_CONNECT(filter_bt, "clicked", display_filter_construct_cb, &args);
   SIGNAL_CONNECT(filter_bt, "destroy", filter_button_destroy_cb, NULL);
   gtk_box_pack_start(GTK_BOX(filter_hbox), filter_bt, FALSE, TRUE, 0);
@@ -1279,7 +1278,7 @@ file_save_as_cmd(action_after_save_e action_after_save, gpointer action_after_sa
   tooltips = gtk_tooltips_new();
 
   /* build the file selection */
-  file_save_as_w = file_selection_new ("Ethereal: Save Capture File As",
+  file_save_as_w = file_selection_new ("Wireshark: Save Capture File As",
                                        FILE_SELECTION_SAVE);
 
   /* as the dialog might already be gone, when using this values, we cannot
@@ -1392,6 +1391,10 @@ file_save_as_cb(GtkWidget *w _U_, gpointer fs) {
 
   compressed_cb = OBJECT_GET_DATA(file_save_as_w, "compressed");
 
+  /* XXX - if the user requests to save to an already existing filename, */
+  /* ask in a dialog if that's intended */
+  /* currently, cf_save() will simply deny it */
+
   /* Write out the packets (all, or only the ones from the current
      range) to the file with the specified name. */
   if (cf_save(&cfile, cf_name, &range, filetype,
@@ -1618,10 +1621,10 @@ color_global_cb(GtkWidget *widget _U_, gpointer data)
 
 /* Import color filters */
 void
-file_color_import_cmd_cb(GtkWidget *w _U_, gpointer data)
+file_color_import_cmd_cb(GtkWidget *color_filters, gpointer filter_list _U_)
 {
 #if GTK_MAJOR_VERSION >= 2 && _WIN32
-  win32_import_color_file(GDK_WINDOW_HWND(top_level->window));
+  win32_import_color_file(GDK_WINDOW_HWND(top_level->window), color_filters);
 #else /* GTK_MAJOR_VERSION >= 2 && _WIN32 */
   GtkWidget    *main_vb, *cfglobal_but;
 #if GTK_MAJOR_VERSION < 2
@@ -1637,7 +1640,7 @@ file_color_import_cmd_cb(GtkWidget *w _U_, gpointer data)
     return;
   }
 
-  file_color_import_w = file_selection_new("Ethereal: Import Color Filters",
+  file_color_import_w = file_selection_new("Wireshark: Import Color Filters",
                                            FILE_SELECTION_OPEN);
 
 #if GTK_MAJOR_VERSION < 2
@@ -1663,21 +1666,17 @@ file_color_import_cmd_cb(GtkWidget *w _U_, gpointer data)
   SIGNAL_CONNECT(file_color_import_w, "destroy", file_color_import_destroy_cb, NULL);
 
 #if (GTK_MAJOR_VERSION == 2 && GTK_MINOR_VERSION >= 4) || GTK_MAJOR_VERSION > 2
-  OBJECT_SET_DATA(file_color_import_w, ARGUMENT_CL, data);
 
   if (gtk_dialog_run(GTK_DIALOG(file_color_import_w)) == GTK_RESPONSE_ACCEPT)
   {
-      file_color_import_ok_cb(file_color_import_w, file_color_import_w);
+      file_color_import_ok_cb(file_color_import_w, color_filters);
   }
   else window_destroy(file_color_import_w);
 #else /* (GTK_MAJOR_VERSION == 2 && GTK_MINOR_VERSION >= 4) || GTK_MAJOR_VERSION > 2 */
   /* Connect the ok_button to file_open_ok_cb function and pass along a
      pointer to the file selection box widget */
   SIGNAL_CONNECT(GTK_FILE_SELECTION(file_color_import_w)->ok_button, "clicked",
-                 file_color_import_ok_cb, file_color_import_w);
-
-  OBJECT_SET_DATA(GTK_FILE_SELECTION(file_color_import_w)->ok_button,
-                  ARGUMENT_CL, data);
+                 file_color_import_ok_cb, color_filters);
 
   window_set_cancel_button(file_color_import_w,
       GTK_FILE_SELECTION(file_color_import_w)->cancel_button, window_cancel_button_cb);
@@ -1692,11 +1691,9 @@ file_color_import_cmd_cb(GtkWidget *w _U_, gpointer data)
 }
 
 static void
-file_color_import_ok_cb(GtkWidget *w, gpointer fs) {
+file_color_import_ok_cb(GtkWidget *w, gpointer color_filters) {
   gchar     *cf_name, *s;
-  gpointer  argument;
-
-  argument = OBJECT_GET_DATA(w, ARGUMENT_CL);     /* to be passed back into color_filters_import */
+  GtkWidget *fs = gtk_widget_get_toplevel(w);
 
 #if (GTK_MAJOR_VERSION == 2 && GTK_MINOR_VERSION >= 4) || GTK_MAJOR_VERSION > 2
   cf_name = g_strdup(gtk_file_chooser_get_filename(GTK_FILE_CHOOSER(fs)));
@@ -1716,7 +1713,7 @@ file_color_import_ok_cb(GtkWidget *w, gpointer fs) {
 
   /* Try to open the color filter file. */
 
-  if (!color_filters_import(cf_name, argument)) {
+  if (!color_filters_import(cf_name, color_filters)) {
     /* We couldn't open it; don't dismiss the open dialog box,
        just leave it around so that the user can, after they
        dismiss the alert box popped up for the open error,
@@ -1747,44 +1744,44 @@ file_color_import_destroy_cb(GtkWidget *win _U_, gpointer user_data _U_)
 
 static GtkWidget *file_color_export_w;
 /*
- * Set the "Export only marked filters" toggle button as appropriate for
- * the current output file type and count of marked filters.
+ * Set the "Export only selected filters" toggle button as appropriate for
+ * the current output file type and count of selected filters.
  *
- * Called when the "Export" dialog box is created and when the marked
+ * Called when the "Export" dialog box is created and when the selected
  * count changes.
  */
 static void
-color_set_export_marked_sensitive(GtkWidget * cfmark_cb)
+color_set_export_selected_sensitive(GtkWidget * cfselect_cb)
 {
   if (file_color_export_w == NULL) {
     /* We don't currently have an "Export" dialog box up. */
     return;
   }
 
-  /* We can request that only the marked filters be saved only if
-        there *are* marked filters. */
-  if (color_marked_count() != 0)
-    gtk_widget_set_sensitive(cfmark_cb, TRUE);
+  /* We can request that only the selected filters be saved only if
+        there *are* selected filters. */
+  if (color_selected_count() != 0)
+    gtk_widget_set_sensitive(cfselect_cb, TRUE);
   else {
-    /* Force the "Export only marked filters" toggle to "false", turn
+    /* Force the "Export only selected filters" toggle to "false", turn
        off the flag it controls. */
-    color_marked = FALSE;
-    gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(cfmark_cb), FALSE);
-    gtk_widget_set_sensitive(cfmark_cb, FALSE);
+    color_selected = FALSE;
+    gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(cfselect_cb), FALSE);
+    gtk_widget_set_sensitive(cfselect_cb, FALSE);
   }
 }
 
 static void
-color_toggle_marked_cb(GtkWidget *widget, gpointer data _U_)
+color_toggle_selected_cb(GtkWidget *widget, gpointer data _U_)
 {
-  color_marked = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON (widget));
+  color_selected = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON (widget));
 }
 
 void
-file_color_export_cmd_cb(GtkWidget *w _U_, gpointer data _U_)
+file_color_export_cmd_cb(GtkWidget *w _U_, gpointer filter_list)
 {
 #if GTK_MAJOR_VERSION >= 2 && _WIN32
-  win32_export_color_file(GDK_WINDOW_HWND(top_level->window));
+  win32_export_color_file(GDK_WINDOW_HWND(top_level->window), filter_list);
 #else /* GTK_MAJOR_VERSION >= 2 && _WIN32 */
   GtkWidget *main_vb, *cfglobal_but;
 
@@ -1795,10 +1792,10 @@ file_color_export_cmd_cb(GtkWidget *w _U_, gpointer data _U_)
   }
 
   /* Default to saving all packets, in the file's current format. */
-  color_marked   = FALSE;
+  color_selected   = FALSE;
   filetype = cfile.cd_t;
 
-  file_color_export_w = file_selection_new("Ethereal: Export Color Filters",
+  file_color_export_w = file_selection_new("Wireshark: Export Color Filters",
                                            FILE_SELECTION_SAVE);
 
   /* Container for each row of widgets */
@@ -1807,12 +1804,12 @@ file_color_export_cmd_cb(GtkWidget *w _U_, gpointer data _U_)
   file_selection_set_extra_widget(file_color_export_w, main_vb);
   gtk_widget_show(main_vb);
 
-  cfmark_cb = gtk_check_button_new_with_label("Export only marked filters");
-  gtk_container_add(GTK_CONTAINER(main_vb), cfmark_cb);
-  gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(cfmark_cb), FALSE);
-  SIGNAL_CONNECT(cfmark_cb, "toggled", color_toggle_marked_cb, NULL);
-  gtk_widget_show(cfmark_cb);
-  color_set_export_marked_sensitive(cfmark_cb);
+  cfselect_cb = gtk_check_button_new_with_label("Export only selected filters");
+  gtk_container_add(GTK_CONTAINER(main_vb), cfselect_cb);
+  gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(cfselect_cb), FALSE);
+  SIGNAL_CONNECT(cfselect_cb, "toggled", color_toggle_selected_cb, NULL);
+  gtk_widget_show(cfselect_cb);
+  color_set_export_selected_sensitive(cfselect_cb);
 
   cfglobal_but = gtk_button_new_with_label("Global Color Filter File");
   gtk_container_add(GTK_CONTAINER(main_vb), cfglobal_but);
@@ -1824,14 +1821,14 @@ file_color_export_cmd_cb(GtkWidget *w _U_, gpointer data _U_)
 #if (GTK_MAJOR_VERSION == 2 && GTK_MINOR_VERSION >= 4) || GTK_MAJOR_VERSION > 2
   if (gtk_dialog_run(GTK_DIALOG(file_color_export_w)) == GTK_RESPONSE_ACCEPT)
   {
-      file_color_export_ok_cb(file_color_export_w, file_color_export_w);
+      file_color_export_ok_cb(file_color_export_w, filter_list);
   }
   else window_destroy(file_color_export_w);
 #else /* (GTK_MAJOR_VERSION == 2 && GTK_MINOR_VERSION >= 4) || GTK_MAJOR_VERSION > 2 */
   /* Connect the ok_button to file_export_ok_cb function and pass along a
      pointer to the file selection box widget */
   SIGNAL_CONNECT(GTK_FILE_SELECTION (file_color_export_w)->ok_button, "clicked",
-                 file_color_export_ok_cb, file_color_export_w);
+                 file_color_export_ok_cb, filter_list);
 
   window_set_cancel_button(file_color_export_w,
       GTK_FILE_SELECTION(file_color_export_w)->cancel_button, window_cancel_button_cb);
@@ -1848,9 +1845,10 @@ file_color_export_cmd_cb(GtkWidget *w _U_, gpointer data _U_)
 }
 
 static void
-file_color_export_ok_cb(GtkWidget *w _U_, gpointer fs) {
+file_color_export_ok_cb(GtkWidget *w, gpointer filter_list) {
   gchar        *cf_name;
   gchar        *dirname;
+  GtkWidget *fs = gtk_widget_get_toplevel(w);
 
 #if (GTK_MAJOR_VERSION == 2 && GTK_MINOR_VERSION >= 4) || GTK_MAJOR_VERSION > 2
   cf_name = g_strdup(gtk_file_chooser_get_filename(GTK_FILE_CHOOSER(fs)));
@@ -1870,9 +1868,9 @@ file_color_export_ok_cb(GtkWidget *w _U_, gpointer fs) {
   }
 
   /* Write out the filters (all, or only the ones that are currently
-     displayed or marked) to the file with the specified name. */
+     displayed or selected) to the file with the specified name. */
 
-   if (!color_filters_export(cf_name, color_marked))
+   if (!color_filters_export(cf_name, filter_list, color_selected))
    {
     /* The write failed; don't dismiss the open dialog box,
        just leave it around so that the user can, after they