print system enhanced, more print ranges and expanded states
authorulfl <ulfl@f5534014-38df-0310-8fa8-9805f1628bb7>
Tue, 9 Dec 2003 22:27:28 +0000 (22:27 +0000)
committerulfl <ulfl@f5534014-38df-0310-8fa8-9805f1628bb7>
Tue, 9 Dec 2003 22:27:28 +0000 (22:27 +0000)
git-svn-id: http://anonsvn.wireshark.org/wireshark/trunk@9222 f5534014-38df-0310-8fa8-9805f1628bb7

gtk/print_dlg.c
print.c
print.h
tethereal.c

index cf5b27b1e41d395d28ee6ca4c3864a9164b4a801..4153c17e1ac722d182ec7ef453bf4e3c55356f9b 100644 (file)
@@ -1,7 +1,7 @@
 /* print_dlg.c
  * Dialog boxes for printing
  *
- * $Id: print_dlg.c,v 1.48 2003/12/01 02:01:56 guy Exp $
+ * $Id: print_dlg.c,v 1.49 2003/12/09 22:24:14 ulfl Exp $
  *
  * Ethereal - Network traffic analyzer
  * By Gerald Combs <gerald@ethereal.com>
@@ -87,7 +87,10 @@ static gchar * print_cmd;
 #define PRINT_COLLAPSE_ALL_RB_KEY "printer_collapse_all_radio_button"
 #define PRINT_AS_DISPLAYED_RB_KEY "printer_as_displayed_radio_button"
 #define PRINT_EXPAND_ALL_RB_KEY   "printer_expand_all_radio_button"
-#define PRINT_PRINT_ONLY_MARKED_RB_KEY "printer_print_only_marked_radio_button"
+
+#define PRINT_ONLY_SELECTED_RB_KEY    "printer_print_only_selected_radio_button"
+#define PRINT_ONLY_MARKED_RB_KEY      "printer_print_only_marked_radio_button"
+#define PRINT_ONLY_DISPLAYED_RB_KEY   "printer_print_only_displayed_radio_button"
 
 /*
  * Keep a static pointer to the current "Print" window, if any, so that if
@@ -127,6 +130,7 @@ file_print_cmd_cb(GtkWidget *widget _U_, gpointer data _U_)
   GtkTooltips   *tooltips;
   gchar         label_text[100];
   frame_data    *packet;
+  guint32       captured_count;
   guint32       displayed_count;
 
   if (print_w != NULL) {
@@ -135,11 +139,13 @@ file_print_cmd_cb(GtkWidget *widget _U_, gpointer data _U_)
     return;
   }
 
-  /* count displayed packets */
-  /* XXX: there should be a displayed_count in cfile, so we don't have to do this here */
+  /* count packets */
+  /* XXX: this counters should be a in cfile, so we don't have to do this here */
+  captured_count = 0;
   displayed_count = 0;
   packet = cfile.plist;
   while(packet != NULL) {
+    captured_count++;
     if (packet->flags.passed_dfilter) {
       displayed_count++;
     }
@@ -295,75 +301,79 @@ file_print_cmd_cb(GtkWidget *widget _U_, gpointer data _U_)
   gtk_widget_show(range_vb);
 
 
-  /* "All packets captured" */
-  /* "All packets displayed" */
   /* "Selected packet only" */
   /* "Marked packets only" */
+  /* "All packets displayed" */
+  /* "All packets captured" */
   /* "Packets from x to y" */
 
-  g_snprintf(label_text, sizeof(label_text), "XXX: All packets _captured, XXX%u packet(s)", 0);
+  g_snprintf(label_text, sizeof(label_text), "_Selected packet only, 1 packet");
 #if GTK_MAJOR_VERSION < 2
-  all_captured_rb = dlg_radio_button_new_with_label_with_mnemonic(NULL,
+  selected_rb = dlg_radio_button_new_with_label_with_mnemonic(
+                NULL,
                                label_text, accel_group);
 #else
-  all_captured_rb = gtk_radio_button_new_with_mnemonic(NULL, label_text);
+  selected_rb = gtk_radio_button_new_with_mnemonic(
+                    NULL, label_text);
 #endif
-  gtk_toggle_button_set_state(GTK_TOGGLE_BUTTON(all_captured_rb), TRUE);
-  gtk_tooltips_set_tip (tooltips, all_captured_rb, 
-      ("Print all packets captured"), NULL);
-  gtk_container_add(GTK_CONTAINER(range_vb), all_captured_rb);
-  /*gtk_widget_show(all_captured_rb);*/
+  gtk_toggle_button_set_state(GTK_TOGGLE_BUTTON(selected_rb), TRUE);
+  gtk_tooltips_set_tip (tooltips, selected_rb, ("Print the currently selected packet only"), NULL);
+  gtk_container_add(GTK_CONTAINER(range_vb), selected_rb);
+  gtk_widget_show(selected_rb);
+
+  g_snprintf(label_text, sizeof(label_text), "_Marked packets only, %u packet(s)", cfile.marked_count);
+#if GTK_MAJOR_VERSION < 2
+  marked_rb = dlg_radio_button_new_with_label_with_mnemonic(
+                gtk_radio_button_group(GTK_RADIO_BUTTON(selected_rb)),
+                               label_text, accel_group);
+#else
+  marked_rb = gtk_radio_button_new_with_mnemonic_from_widget(
+                    GTK_RADIO_BUTTON(selected_rb), label_text);
+#endif
+  gtk_toggle_button_set_state(GTK_TOGGLE_BUTTON(marked_rb), FALSE);
+  gtk_tooltips_set_tip (tooltips, marked_rb, ("Print marked packets only"), NULL);
+  gtk_container_add(GTK_CONTAINER(range_vb), marked_rb);
+  gtk_widget_set_sensitive(marked_rb, cfile.marked_count);
+  gtk_widget_show(marked_rb);
 
   g_snprintf(label_text, sizeof(label_text), "All packets _displayed, %u packet(s)", displayed_count);
 #if GTK_MAJOR_VERSION < 2
   all_displayed_rb = dlg_radio_button_new_with_label_with_mnemonic(
-                gtk_radio_button_group(GTK_RADIO_BUTTON(all_captured_rb)),
+                gtk_radio_button_group(GTK_RADIO_BUTTON(selected_rb)),
                                label_text, accel_group);
 #else
   all_displayed_rb = gtk_radio_button_new_with_mnemonic_from_widget(
-                    GTK_RADIO_BUTTON(all_captured_rb), label_text);
+                    GTK_RADIO_BUTTON(selected_rb), label_text);
 #endif
-  gtk_toggle_button_set_state(GTK_TOGGLE_BUTTON(all_displayed_rb), TRUE);
+  gtk_toggle_button_set_state(GTK_TOGGLE_BUTTON(all_displayed_rb), FALSE);
   gtk_tooltips_set_tip (tooltips, all_displayed_rb, 
       ("Print all packets currently displayed"), NULL);
   gtk_container_add(GTK_CONTAINER(range_vb), all_displayed_rb);
+  gtk_widget_set_sensitive(all_displayed_rb, displayed_count != captured_count);
   gtk_widget_show(all_displayed_rb);
 
+  g_snprintf(label_text, sizeof(label_text), "All packets _captured, %u packet(s)", captured_count);
 #if GTK_MAJOR_VERSION < 2
-  selected_rb = dlg_radio_button_new_with_label_with_mnemonic(
-                gtk_radio_button_group(GTK_RADIO_BUTTON(all_captured_rb)),
-                               "XXX: _Selected packet only", accel_group);
-#else
-  selected_rb = gtk_radio_button_new_with_mnemonic_from_widget(
-                    GTK_RADIO_BUTTON(all_captured_rb), "XXX: _Selected packet only");
-#endif
-  gtk_toggle_button_set_state(GTK_TOGGLE_BUTTON(selected_rb), FALSE);
-  gtk_tooltips_set_tip (tooltips, selected_rb, ("Print the currently selected packet only"), NULL);
-  gtk_container_add(GTK_CONTAINER(range_vb), selected_rb);
-  /*gtk_widget_show(selected_rb);*/
-
-  g_snprintf(label_text, sizeof(label_text), "_Marked packets only, %u packet(s)", cfile.marked_count);
-#if GTK_MAJOR_VERSION < 2
-  marked_rb = dlg_radio_button_new_with_label_with_mnemonic(
-                gtk_radio_button_group(GTK_RADIO_BUTTON(all_captured_rb)),
+  all_captured_rb = dlg_radio_button_new_with_label_with_mnemonic(
+                gtk_radio_button_group(GTK_RADIO_BUTTON(selected_rb)),
                                label_text, accel_group);
 #else
-  marked_rb = gtk_radio_button_new_with_mnemonic_from_widget(
-                    GTK_RADIO_BUTTON(all_captured_rb), label_text);
+  all_captured_rb = gtk_radio_button_new_with_mnemonic_from_widget(
+                    GTK_RADIO_BUTTON(selected_rb), label_text);
 #endif
-  gtk_toggle_button_set_state(GTK_TOGGLE_BUTTON(marked_rb), FALSE);
-  gtk_tooltips_set_tip (tooltips, marked_rb, ("Print marked packets only"), NULL);
-  gtk_container_add(GTK_CONTAINER(range_vb), marked_rb);
-  gtk_widget_set_sensitive(marked_rb, cfile.marked_count);
-  gtk_widget_show(marked_rb);
+  gtk_toggle_button_set_state(GTK_TOGGLE_BUTTON(all_captured_rb), FALSE);
+  gtk_tooltips_set_tip (tooltips, all_captured_rb, 
+      ("Print all packets captured"), NULL);
+  gtk_container_add(GTK_CONTAINER(range_vb), all_captured_rb);
+  gtk_widget_show(all_captured_rb);
 
 #if GTK_MAJOR_VERSION < 2
   range_rb = dlg_radio_button_new_with_label_with_mnemonic(
-                gtk_radio_button_group(GTK_RADIO_BUTTON(all_captured_rb)),
+                gtk_radio_button_group(GTK_RADIO_BUTTON(selected_rb)),
                                "XXX: Packets f_rom X to Y", accel_group);
 #else
   range_rb = gtk_radio_button_new_with_mnemonic_from_widget(
-                    GTK_RADIO_BUTTON(all_captured_rb), "XXX: Packets f_rom X to Y");
+                    GTK_RADIO_BUTTON(selected_rb), "XXX: Packets f_rom X to Y");
 #endif
   gtk_toggle_button_set_state(GTK_TOGGLE_BUTTON(range_rb), FALSE);
   gtk_tooltips_set_tip (tooltips, range_rb, ("Print packets from number X to Y only"), NULL);
@@ -406,18 +416,18 @@ file_print_cmd_cb(GtkWidget *widget _U_, gpointer data _U_)
   gtk_container_add(GTK_CONTAINER(details_fr), details_vb);
   gtk_widget_show(details_vb);
 
-  /* "As displayed"/"All Expanded" radio buttons */
+  /* "All collapsed"/"As displayed"/"All Expanded" radio buttons */
 #if GTK_MAJOR_VERSION < 2
   collapse_all_rb = dlg_radio_button_new_with_label_with_mnemonic(NULL,
-                                   "XXX: All dissections co_llapsed", accel_group);
+                                   "All dissections co_llapsed", accel_group);
 #else
   collapse_all_rb = gtk_radio_button_new_with_mnemonic(
-                    NULL, "XXX: All dissections co_llapsed");
+                    NULL, "All dissections co_llapsed");
 #endif
   gtk_toggle_button_set_state(GTK_TOGGLE_BUTTON(collapse_all_rb), FALSE);
   gtk_tooltips_set_tip (tooltips, collapse_all_rb, ("Print packet details tree \"collapsed\""), NULL);
   gtk_container_add(GTK_CONTAINER(details_vb), collapse_all_rb);
-  /*gtk_widget_show(collapse_all_rb);*/
+  gtk_widget_show(collapse_all_rb);
 
 #if GTK_MAJOR_VERSION < 2
   as_displayed_rb = dlg_radio_button_new_with_label_with_mnemonic(
@@ -427,7 +437,7 @@ file_print_cmd_cb(GtkWidget *widget _U_, gpointer data _U_)
   as_displayed_rb = gtk_radio_button_new_with_mnemonic_from_widget(
                     GTK_RADIO_BUTTON(collapse_all_rb), "Dissections as displa_yed");
 #endif
-  gtk_toggle_button_set_state(GTK_TOGGLE_BUTTON(as_displayed_rb), FALSE);
+  gtk_toggle_button_set_state(GTK_TOGGLE_BUTTON(as_displayed_rb), TRUE);
   gtk_tooltips_set_tip (tooltips, as_displayed_rb, ("Print packet details tree \"as displayed\""), NULL);
   gtk_container_add(GTK_CONTAINER(details_vb), as_displayed_rb);
   gtk_widget_show(as_displayed_rb);
@@ -440,7 +450,7 @@ file_print_cmd_cb(GtkWidget *widget _U_, gpointer data _U_)
   expand_all_rb = gtk_radio_button_new_with_mnemonic_from_widget(
                     GTK_RADIO_BUTTON(collapse_all_rb), "All dissections e_xpanded");
 #endif
-  gtk_toggle_button_set_state(GTK_TOGGLE_BUTTON(expand_all_rb), TRUE);
+  gtk_toggle_button_set_state(GTK_TOGGLE_BUTTON(expand_all_rb), FALSE);
   gtk_tooltips_set_tip (tooltips, expand_all_rb, ("Print packet details tree \"expanded\""), NULL);
   gtk_container_add(GTK_CONTAINER(details_vb), expand_all_rb);
   gtk_widget_show(expand_all_rb);
@@ -488,8 +498,11 @@ file_print_cmd_cb(GtkWidget *widget _U_, gpointer data _U_)
   OBJECT_SET_DATA(ok_bt, PRINT_FILE_TE_KEY, file_te);
   OBJECT_SET_DATA(ok_bt, PRINT_DETAILS_CB_KEY, details_cb);
   OBJECT_SET_DATA(ok_bt, PRINT_HEX_CB_KEY, hex_cb);
+  OBJECT_SET_DATA(ok_bt, PRINT_AS_DISPLAYED_RB_KEY, as_displayed_rb);
   OBJECT_SET_DATA(ok_bt, PRINT_EXPAND_ALL_RB_KEY, expand_all_rb);
-  OBJECT_SET_DATA(ok_bt, PRINT_PRINT_ONLY_MARKED_RB_KEY, marked_rb);
+  OBJECT_SET_DATA(ok_bt, PRINT_ONLY_SELECTED_RB_KEY, selected_rb);
+  OBJECT_SET_DATA(ok_bt, PRINT_ONLY_MARKED_RB_KEY, marked_rb);
+  OBJECT_SET_DATA(ok_bt, PRINT_ONLY_DISPLAYED_RB_KEY, all_displayed_rb);
   SIGNAL_CONNECT(ok_bt, "clicked", print_ok_cb, print_w);
   GTK_WIDGET_SET_FLAGS(ok_bt, GTK_CAN_DEFAULT);
   gtk_tooltips_set_tip (tooltips, ok_bt, ("Perform printing"), NULL);
@@ -653,11 +666,31 @@ print_ok_cb(GtkWidget *ok_bt, gpointer parent_w)
   button = (GtkWidget *)OBJECT_GET_DATA(ok_bt, PRINT_HEX_CB_KEY);
   print_args.print_hex = GTK_TOGGLE_BUTTON (button)->active;
 
+  print_args.print_dissections = print_dissections_collapsed;
+
+  button = (GtkWidget *)OBJECT_GET_DATA(ok_bt, PRINT_AS_DISPLAYED_RB_KEY);
+  if (GTK_TOGGLE_BUTTON (button)->active) {
+    print_args.print_dissections = print_dissections_as_displayed;
+  }
   button = (GtkWidget *)OBJECT_GET_DATA(ok_bt, PRINT_EXPAND_ALL_RB_KEY);
-  print_args.expand_all = GTK_TOGGLE_BUTTON (button)->active;
+  if (GTK_TOGGLE_BUTTON (button)->active) {
+    print_args.print_dissections = print_dissections_expanded;
+  }
 
-  button = (GtkWidget *)OBJECT_GET_DATA(ok_bt, PRINT_PRINT_ONLY_MARKED_RB_KEY);
-  print_args.print_only_marked = GTK_TOGGLE_BUTTON (button)->active;
+  print_args.print_range = print_range_all_captured;
+
+  button = (GtkWidget *)OBJECT_GET_DATA(ok_bt, PRINT_ONLY_SELECTED_RB_KEY);
+  if (GTK_TOGGLE_BUTTON (button)->active) {
+    print_args.print_range = print_range_selected_only;
+  }
+  button = (GtkWidget *)OBJECT_GET_DATA(ok_bt, PRINT_ONLY_MARKED_RB_KEY);
+  if (GTK_TOGGLE_BUTTON (button)->active) {
+    print_args.print_range = print_range_marked_only;
+  }
+  button = (GtkWidget *)OBJECT_GET_DATA(ok_bt, PRINT_ONLY_DISPLAYED_RB_KEY);
+  if (GTK_TOGGLE_BUTTON (button)->active) {
+    print_args.print_range = print_range_all_displayed;
+  }
 
   gtk_widget_destroy(GTK_WIDGET(parent_w));
 
@@ -708,81 +741,6 @@ print_destroy_cb(GtkWidget *win, gpointer user_data _U_)
   print_w = NULL;
 }
 
-/* Print a packet */
-void
-file_print_packet_cmd_cb(GtkWidget *widget _U_, gpointer data _U_)
-{
-  FILE *fh;
-  print_args_t print_args;
-#ifdef _WIN32
-  int win_printer_flag = FALSE;
-#endif
-
-  switch (prefs.pr_dest) {
-
-  case PR_DEST_CMD:
-#ifdef _WIN32
-    /* "PR_DEST_CMD" means "to printer" on Windows */
-    win_printer_flag = TRUE;
-    setup_mswin_print(&print_args);
-    fh = fopen(print_args.dest, "w");
-    print_args.to_file = TRUE;
-    break;
-#else
-    fh = popen(prefs.pr_cmd, "w");
-    print_args.to_file = FALSE;
-    print_args.dest = prefs.pr_cmd;
-    break;
-#endif
-
-  case PR_DEST_FILE:
-    fh = fopen(prefs.pr_file, "w");
-    print_args.to_file = TRUE;
-    print_args.dest = prefs.pr_file;
-    break;
-
-  default:
-    fh = NULL; /* XXX - "can't happen" */
-    break;
-  }
-  if (fh == NULL) {
-    switch (prefs.pr_dest) {
-
-    case PR_DEST_CMD:
-      simple_dialog(ESD_TYPE_WARN, NULL, "Couldn't run print command %s.",
-        prefs.pr_cmd);
-      break;
-
-    case PR_DEST_FILE:
-      simple_dialog(ESD_TYPE_WARN, NULL, file_write_error_message(errno),
-        prefs.pr_file);
-      break;
-    }
-    return;
-  }
-
-  print_preamble(fh, prefs.pr_format);
-  print_args.format = prefs.pr_format;
-  print_args.print_summary = FALSE;
-  print_args.print_hex = FALSE;
-  print_args.expand_all = TRUE;
-  print_args.print_only_marked = FALSE;
-  proto_tree_print(&print_args, cfile.edt, fh);
-  print_finale(fh, prefs.pr_format);
-  close_print_dest(print_args.to_file, fh);
-
-#ifdef _WIN32
-  if (win_printer_flag) {
-    print_mswin(print_args.dest);
-
-    /* trash temp file */
-    remove(print_args.dest);
-    g_free(print_args.dest);
-  }
-#endif
-}
-
-
 
 
 
diff --git a/print.c b/print.c
index e016b4a20bb47986afb6872ffd45d9b9ac12c390..1494e5118100d0be5a9dacae3fb0fab20ab31894 100644 (file)
--- a/print.c
+++ b/print.c
@@ -1,7 +1,7 @@
 /* print.c
  * Routines for printing packet analysis trees.
  *
- * $Id: print.c,v 1.65 2003/12/08 21:57:25 guy Exp $
+ * $Id: print.c,v 1.66 2003/12/09 22:27:28 ulfl Exp $
  *
  * Gilbert Ramirez <gram@alumni.rice.edu>
  *
@@ -52,14 +52,14 @@ static void ps_clean_string(unsigned char *out, const unsigned char *in,
                        int outbuf_size);
 
 typedef struct {
-       int             level;
-       FILE            *fh;
-       GSList          *src_list;
-       gboolean        print_all_levels;
-       gboolean        print_hex_for_data;
-       char_enc        encoding;
-       gint            format;
-       epan_dissect_t  *edt;
+       int                         level;
+       FILE                    *fh;
+       GSList                  *src_list;
+       print_dissections_e print_dissections;
+       gboolean                print_hex_for_data;
+       char_enc                encoding;
+       gint                    format;
+       epan_dissect_t      *edt;
 } print_data;
 
 static void print_pdml_geninfo(proto_tree *tree, print_data *pdata);
@@ -98,7 +98,7 @@ proto_tree_print(print_args_t *print_args, epan_dissect_t *edt,
        data.fh = fh;
        data.src_list = edt->pi.data_src;
        data.encoding = edt->pi.fd->flags.encoding;
-       data.print_all_levels = print_args->expand_all;
+       data.print_dissections = print_args->print_dissections;
        data.print_hex_for_data = !print_args->print_hex;
            /* If we're printing the entire packet in hex, don't
               print uninterpreted data fields in hex as well. */
@@ -184,14 +184,15 @@ void proto_tree_print_node(proto_node *node, gpointer data)
                pd = get_field_data(pdata->src_list, fi);
                print_hex_data_buffer(pdata->fh, pd, fi->length,
                    pdata->encoding, pdata->format);
-       }
+    }
 
        /* If we're printing all levels, or if this node is one with a
           subtree and its subtree is expanded, recurse into the subtree,
           if it exists. */
        g_assert(fi->tree_type >= -1 && fi->tree_type < num_tree_types);
-       if (pdata->print_all_levels ||
-           (fi->tree_type >= 0 && tree_is_expanded[fi->tree_type])) {
+       if (pdata->print_dissections == print_dissections_expanded ||
+           (pdata->print_dissections == print_dissections_as_displayed &&
+        fi->tree_type >= 0 && tree_is_expanded[fi->tree_type])) {
                if (node->first_child != NULL) {
                        pdata->level++;
                        proto_tree_children_foreach(node,
diff --git a/print.h b/print.h
index ab88590360c4df158adbd612de9a58c496919db2..89603b903a964517d6d9f4131cce275cd0e8eaf0 100644 (file)
--- a/print.h
+++ b/print.h
@@ -1,7 +1,7 @@
 /* print.h
  * Definitions for printing packet analysis trees.
  *
- * $Id: print.h,v 1.32 2003/12/09 22:04:57 ulfl Exp $
+ * $Id: print.h,v 1.33 2003/12/09 22:21:24 ulfl Exp $
  *
  * Gilbert Ramirez <gram@alumni.rice.edu>
  *
@@ -59,8 +59,6 @@ typedef struct {
 
   gboolean     print_summary;  /* TRUE if we should just print summary;
                                   FALSE if we should print protocol tree. */
-  gboolean     expand_all;     /* TRUE if we should expand all levels;
-                                  FALSE if we should expand as displayed. */
   print_dissections_e   print_dissections;
   gboolean     print_hex;      /* TRUE if we should also print hex data;
                                   FALSE if we should print only if not dissected. */
index cbe7b2cb94db00453d586641edaae8fa2369e542..7b8196573e107b45760ab7d376bbadf3ed2b51b2 100644 (file)
@@ -1,6 +1,6 @@
 /* tethereal.c
  *
- * $Id: tethereal.c,v 1.208 2003/12/09 05:56:30 gram Exp $
+ * $Id: tethereal.c,v 1.209 2003/12/09 22:22:52 ulfl Exp $
  *
  * Ethereal - Network traffic analyzer
  * By Gerald Combs <gerald@ethereal.com>
@@ -2543,8 +2543,8 @@ wtap_dispatch_cb_print(guchar *user, const struct wtap_pkthdr *phdr,
       print_args.format = print_format;
       print_args.print_summary = FALSE;
       print_args.print_hex = print_hex;
-      print_args.expand_all = TRUE;
-      print_args.print_only_marked = FALSE;
+      print_args.print_dissections = print_dissections_expanded;
+      print_args.print_range = print_range_all_captured;
       proto_tree_print(&print_args, edt, stdout);
       if (!print_hex) {
         /* "print_hex_data()" will put out a leading blank line, as well