2 * Dialog boxes for printing
4 * $Id: print_dlg.c,v 1.73 2004/04/25 12:04:08 ulfl Exp $
6 * Ethereal - Network traffic analyzer
7 * By Gerald Combs <gerald@ethereal.com>
8 * Copyright 1998 Gerald Combs
10 * This program is free software; you can redistribute it and/or
11 * modify it under the terms of the GNU General Public License
12 * as published by the Free Software Foundation; either version 2
13 * of the License, or (at your option) any later version.
15 * This program is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU General Public License for more details.
20 * You should have received a copy of the GNU General Public License
21 * along with this program; if not, write to the Free Software
22 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
37 #include "alert_box.h"
38 #include "simple_dialog.h"
41 #include "dlg_utils.h"
43 #include <epan/epan_dissect.h>
44 #include <epan/filesystem.h>
47 #include "print_mswin.h"
49 #include "compat_macros.h"
50 #include "range_utils.h"
53 /* On Win32, a GUI application apparently can't use "popen()" (it
54 "returns an invalid file handle, if used in a Windows program,
55 that will cause the program to hang indefinitely"), so we can't
56 use a pipe to a print command to print to a printer.
58 Eventually, we should try to use the native Win32 printing API
59 for this (and also use various UNIX printing APIs, when present?).
62 static void print_cmd_toggle_dest(GtkWidget *widget, gpointer data);
63 static void print_cmd_toggle_detail(GtkWidget *widget, gpointer data);
64 static void print_ok_cb(GtkWidget *ok_bt, gpointer parent_w);
65 static void print_close_cb(GtkWidget *close_bt, gpointer parent_w);
66 static void print_destroy_cb(GtkWidget *win, gpointer user_data);
70 #define PRINT_ARGS_KEY "printer_args"
72 #define PRINT_PS_RB_KEY "printer_ps_radio_button"
73 #define PRINT_PDML_RB_KEY "printer_pdml_radio_button"
74 #define PRINT_PSML_RB_KEY "printer_psml_radio_button"
75 #define PRINT_DEST_CB_KEY "printer_destination_check_button"
77 #define PRINT_SUMMARY_CB_KEY "printer_summary_check_button"
78 #define PRINT_DETAILS_CB_KEY "printer_details_check_button"
79 #define PRINT_COLLAPSE_ALL_RB_KEY "printer_collapse_all_radio_button"
80 #define PRINT_AS_DISPLAYED_RB_KEY "printer_as_displayed_radio_button"
81 #define PRINT_EXPAND_ALL_RB_KEY "printer_expand_all_radio_button"
82 #define PRINT_HEX_CB_KEY "printer_hex_check_button"
83 #define PRINT_FORMFEED_CB_KEY "printer_formfeed_check_button"
85 #define PRINT_BT_KEY "printer_button"
88 * Keep a static pointer to the current "Print" window, if any, so that if
89 * somebody tries to do "File:Print" while there's already a "Print" window
90 * up, we just pop up the existing one, rather than creating a new one.
92 static GtkWidget *print_w = NULL;
94 static print_args_t print_args;
96 static gboolean print_prefs_init = FALSE;
99 /* Open the print dialog */
101 file_print_cmd_cb(GtkWidget *widget _U_, gpointer data _U_)
103 #if GTK_MAJOR_VERSION < 2
104 GtkAccelGroup *accel_group;
109 GtkWidget *printer_fr, *printer_vb;
110 GtkWidget *text_rb, *ps_rb, *pdml_rb, *psml_rb;
111 GtkWidget *printer_tb, *dest_cb;
113 GtkWidget *cmd_lb, *cmd_te;
115 GtkWidget *file_bt, *file_te;
117 GtkWidget *range_fr, *range_tb;
119 GtkWidget *packet_hb;
121 GtkWidget *format_fr, *format_vb;
122 GtkWidget *summary_cb;
124 GtkWidget *details_cb;
125 GtkWidget *details_hb, *details_vb;
126 GtkWidget *collapse_all_rb, *as_displayed_rb, *expand_all_rb;
128 GtkWidget *sep, *formfeed_cb;
130 GtkWidget *bbox, *ok_bt, *cancel_bt;
132 GtkTooltips *tooltips;
134 print_args_t *args = &print_args;
136 if (print_w != NULL) {
137 /* There's already a "Print" dialog box; reactivate it. */
138 reactivate_window(print_w);
142 /* get settings from preferences (and other initial values) only once */
143 if(print_prefs_init == FALSE) {
144 print_prefs_init = TRUE;
145 args->format = prefs.pr_format;
146 args->to_file = prefs.pr_dest;
147 args->file = g_strdup(prefs.pr_file);
148 args->cmd = g_strdup(prefs.pr_cmd);
149 args->print_summary = TRUE;
150 args->print_dissections = print_dissections_as_displayed;
151 args->print_hex = FALSE;
152 args->print_formfeed = FALSE;
154 /* init the printing range */
155 packet_range_init(&args->range);
158 /* Enable tooltips */
159 tooltips = gtk_tooltips_new();
162 print_w = dlg_window_new("Ethereal: Print");
163 SIGNAL_CONNECT(print_w, "destroy", print_destroy_cb, NULL);
165 #if GTK_MAJOR_VERSION < 2
166 /* Accelerator group for the accelerators (or, as they're called in
167 Windows and, I think, in Motif, "mnemonics"; Alt+<key> is a mnemonic,
168 Ctrl+<key> is an accelerator). */
169 accel_group = gtk_accel_group_new();
170 gtk_window_add_accel_group(GTK_WINDOW(print_w), accel_group);
173 /* Vertical enclosing container for each row of widgets */
174 main_vb = gtk_vbox_new(FALSE, 5);
175 gtk_container_border_width(GTK_CONTAINER(main_vb), 5);
176 gtk_container_add(GTK_CONTAINER(print_w), main_vb);
177 gtk_widget_show(main_vb);
179 /*****************************************************/
181 /*** printer frame ***/
182 printer_fr = gtk_frame_new("Printer");
183 gtk_box_pack_start(GTK_BOX(main_vb), printer_fr, FALSE, FALSE, 0);
184 gtk_widget_show(printer_fr);
185 printer_vb = gtk_vbox_new(FALSE, 5);
186 gtk_container_border_width(GTK_CONTAINER(printer_vb), 5);
187 gtk_container_add(GTK_CONTAINER(printer_fr), printer_vb);
188 gtk_widget_show(printer_vb);
190 /* "Plain text" / "Postscript" / "PDML", ... radio buttons */
191 text_rb = RADIO_BUTTON_NEW_WITH_MNEMONIC(NULL, "Plain _text", accel_group);
192 if (args->format == PR_FMT_TEXT)
193 gtk_toggle_button_set_state(GTK_TOGGLE_BUTTON(text_rb), TRUE);
194 gtk_tooltips_set_tip (tooltips, text_rb, ("Print output in ascii \"plain text\" format. If you're unsure, use this format."), NULL);
195 gtk_box_pack_start(GTK_BOX(printer_vb), text_rb, FALSE, FALSE, 0);
196 gtk_widget_show(text_rb);
198 ps_rb = RADIO_BUTTON_NEW_WITH_MNEMONIC(text_rb, "_PostScript", accel_group);
199 if (args->format == PR_FMT_PS)
200 gtk_toggle_button_set_state(GTK_TOGGLE_BUTTON(ps_rb), TRUE);
201 gtk_tooltips_set_tip (tooltips, ps_rb, ("Print output in \"postscript\" format, for postscript capable printers or print servers."), NULL);
202 gtk_box_pack_start(GTK_BOX(printer_vb), ps_rb, FALSE, FALSE, 0);
203 gtk_widget_show(ps_rb);
205 pdml_rb = RADIO_BUTTON_NEW_WITH_MNEMONIC(text_rb, "PDM_L (XML: Packet Details Markup Language)", accel_group);
206 if (args->format == PR_FMT_PDML)
207 gtk_toggle_button_set_state(GTK_TOGGLE_BUTTON(pdml_rb), TRUE);
208 gtk_tooltips_set_tip (tooltips, pdml_rb, (
209 "Print output in \"PDML\" (Packet Details Markup Language), "
210 "an XML based packet data interchange format. "
211 "Usually used in combination with the \"Output to file\" option to export packet data into an XML file."), NULL);
212 gtk_box_pack_start(GTK_BOX(printer_vb), pdml_rb, FALSE, FALSE, 0);
213 gtk_widget_show(pdml_rb);
215 psml_rb = RADIO_BUTTON_NEW_WITH_MNEMONIC(text_rb, "PSML (XML: Packet Summary Markup Language)", accel_group);
216 if (args->format == PR_FMT_PSML)
217 gtk_toggle_button_set_state(GTK_TOGGLE_BUTTON(psml_rb), TRUE);
218 gtk_tooltips_set_tip (tooltips, psml_rb, (
219 "Print output in \"PSML\" (Packet Summary Markup Language), "
220 "an XML based packet summary interchange format. "
221 "Usually used in combination with the \"Output to file\" option to export packet data into an XML file."), NULL);
222 gtk_box_pack_start(GTK_BOX(printer_vb), psml_rb, FALSE, FALSE, 0);
223 gtk_widget_show(psml_rb);
227 printer_tb = gtk_table_new(2, 3, FALSE);
229 printer_tb = gtk_table_new(2, 2, FALSE);
231 gtk_box_pack_start(GTK_BOX(printer_vb), printer_tb, FALSE, FALSE, 0);
232 gtk_table_set_row_spacings(GTK_TABLE(printer_tb), 5);
233 gtk_table_set_col_spacings(GTK_TABLE(printer_tb), 5);
234 gtk_widget_show(printer_tb);
237 /* Output to file button */
238 dest_cb = CHECK_BUTTON_NEW_WITH_MNEMONIC("Output to _file:", accel_group);
240 gtk_toggle_button_set_state(GTK_TOGGLE_BUTTON(dest_cb), TRUE);
241 gtk_tooltips_set_tip (tooltips, dest_cb, ("Output to file instead of printer"), NULL);
242 gtk_table_attach_defaults(GTK_TABLE(printer_tb), dest_cb, 0, 1, 0, 1);
243 gtk_widget_show(dest_cb);
245 /* File text entry and "Browse" button */
246 file_te = gtk_entry_new();
247 OBJECT_SET_DATA(dest_cb, PRINT_FILE_TE_KEY, file_te);
248 gtk_tooltips_set_tip (tooltips, file_te, ("Enter Output filename"), NULL);
249 gtk_entry_set_text(GTK_ENTRY(file_te), args->file);
250 gtk_table_attach_defaults(GTK_TABLE(printer_tb), file_te, 1, 2, 0, 1);
251 gtk_widget_set_sensitive(file_te, args->to_file);
252 gtk_widget_show(file_te);
254 gtk_widget_grab_focus(file_te);
256 file_bt = BUTTON_NEW_FROM_STOCK(ETHEREAL_STOCK_BROWSE);
257 OBJECT_SET_DATA(dest_cb, PRINT_FILE_BT_KEY, file_bt);
258 OBJECT_SET_DATA(file_bt, E_FILE_TE_PTR_KEY, file_te);
259 gtk_tooltips_set_tip (tooltips, file_bt, ("Browse output filename in filesystem"), NULL);
260 gtk_table_attach_defaults(GTK_TABLE(printer_tb), file_bt, 2, 3, 0, 1);
261 gtk_widget_set_sensitive(file_bt, args->to_file);
262 gtk_widget_show(file_bt);
264 /* Command label and text entry */
266 cmd_lb = gtk_label_new("Print command:");
267 OBJECT_SET_DATA(dest_cb, PRINT_CMD_LB_KEY, cmd_lb);
268 gtk_misc_set_alignment(GTK_MISC(cmd_lb), 1.0, 0.5);
269 gtk_table_attach_defaults(GTK_TABLE(printer_tb), cmd_lb, 0, 1, 1, 2);
270 gtk_widget_set_sensitive(cmd_lb, !args->to_file);
271 gtk_widget_show(cmd_lb);
273 cmd_te = gtk_entry_new();
274 OBJECT_SET_DATA(dest_cb, PRINT_CMD_TE_KEY, cmd_te);
275 gtk_tooltips_set_tip (tooltips, cmd_te, ("Enter print command"), NULL);
276 gtk_entry_set_text(GTK_ENTRY(cmd_te), args->cmd);
277 gtk_table_attach_defaults(GTK_TABLE(printer_tb), cmd_te, 1, 2, 1, 2);
278 gtk_widget_set_sensitive(cmd_te, !args->to_file);
279 gtk_widget_show(cmd_te);
282 SIGNAL_CONNECT(dest_cb, "toggled", print_cmd_toggle_dest, NULL);
283 SIGNAL_CONNECT(file_bt, "clicked", select_file_cb, "Ethereal: Print to File");
286 /*****************************************************/
288 /*** hor box for range and format frames ***/
289 packet_hb = gtk_hbox_new(FALSE, 5);
290 gtk_container_add(GTK_CONTAINER(main_vb), packet_hb);
291 gtk_widget_show(packet_hb);
293 /*** packet range frame ***/
294 range_fr = gtk_frame_new("Packet Range");
295 gtk_box_pack_start(GTK_BOX(packet_hb), range_fr, FALSE, FALSE, 0);
296 gtk_widget_show(range_fr);
298 range_tb = range_new(&args->range
299 #if GTK_MAJOR_VERSION < 2
303 gtk_container_add(GTK_CONTAINER(range_fr), range_tb);
304 gtk_widget_show(range_tb);
306 /*****************************************************/
308 /*** packet format frame ***/
309 format_fr = gtk_frame_new("Packet Format");
310 gtk_box_pack_start(GTK_BOX(packet_hb), format_fr, TRUE, TRUE, 0);
311 gtk_widget_show(format_fr);
312 format_vb = gtk_vbox_new(FALSE, 5);
313 gtk_container_border_width(GTK_CONTAINER(format_vb), 5);
314 gtk_container_add(GTK_CONTAINER(format_fr), format_vb);
315 gtk_widget_show(format_vb);
317 /* "Print summary line" check button */
318 summary_cb = CHECK_BUTTON_NEW_WITH_MNEMONIC("Packet summary line", accel_group);
319 gtk_toggle_button_set_state(GTK_TOGGLE_BUTTON(summary_cb), args->print_summary);
320 SIGNAL_CONNECT(summary_cb, "clicked", print_cmd_toggle_detail, print_w);
321 gtk_tooltips_set_tip (tooltips, summary_cb, ("Output of a packet summary line, like in the packet list"), NULL);
322 gtk_container_add(GTK_CONTAINER(format_vb), summary_cb);
323 gtk_widget_show(summary_cb);
326 /* "Details" check button */
327 details_cb = CHECK_BUTTON_NEW_WITH_MNEMONIC("Packet details:", accel_group);
328 gtk_toggle_button_set_state(GTK_TOGGLE_BUTTON(details_cb), args->print_dissections != print_dissections_none);
329 SIGNAL_CONNECT(details_cb, "clicked", print_cmd_toggle_detail, print_w);
330 gtk_tooltips_set_tip (tooltips, details_cb, ("Output format of the selected packet details (protocol tree)."), NULL);
331 gtk_container_add(GTK_CONTAINER(format_vb), details_cb);
332 gtk_widget_show(details_cb);
334 /*** packet details ***/
335 details_hb = gtk_hbox_new(FALSE, 6);
336 gtk_container_border_width(GTK_CONTAINER(details_hb), 0);
337 gtk_container_add(GTK_CONTAINER(format_vb), details_hb);
338 gtk_widget_show(details_hb);
340 details_vb = gtk_vbox_new(FALSE, 6);
341 gtk_container_border_width(GTK_CONTAINER(details_vb), 0);
342 gtk_container_add(GTK_CONTAINER(details_hb), details_vb);
343 gtk_widget_show(details_vb);
345 details_vb = gtk_vbox_new(FALSE, 6);
346 gtk_container_border_width(GTK_CONTAINER(details_vb), 0);
347 gtk_container_add(GTK_CONTAINER(details_hb), details_vb);
348 gtk_widget_show(details_vb);
350 /* "All collapsed"/"As displayed"/"All Expanded" radio buttons */
351 collapse_all_rb = RADIO_BUTTON_NEW_WITH_MNEMONIC(NULL, "All co_llapsed", accel_group);
352 gtk_toggle_button_set_state(GTK_TOGGLE_BUTTON(collapse_all_rb), args->print_dissections == print_dissections_collapsed);
353 gtk_tooltips_set_tip (tooltips, collapse_all_rb, ("Output of the packet details tree \"collapsed\""), NULL);
354 gtk_container_add(GTK_CONTAINER(details_vb), collapse_all_rb);
355 gtk_widget_show(collapse_all_rb);
357 as_displayed_rb = RADIO_BUTTON_NEW_WITH_MNEMONIC(collapse_all_rb, "As displa_yed", accel_group);
358 gtk_toggle_button_set_state(GTK_TOGGLE_BUTTON(as_displayed_rb), args->print_dissections == print_dissections_as_displayed);
359 gtk_tooltips_set_tip (tooltips, as_displayed_rb, ("Output of the packet details tree \"as displayed\""), NULL);
360 gtk_container_add(GTK_CONTAINER(details_vb), as_displayed_rb);
361 gtk_widget_show(as_displayed_rb);
363 expand_all_rb = RADIO_BUTTON_NEW_WITH_MNEMONIC(collapse_all_rb, "All e_xpanded", accel_group);
364 gtk_toggle_button_set_state(GTK_TOGGLE_BUTTON(expand_all_rb), args->print_dissections == print_dissections_expanded);
365 gtk_tooltips_set_tip (tooltips, expand_all_rb, ("Output of the packet details tree \"expanded\""), NULL);
366 gtk_container_add(GTK_CONTAINER(details_vb), expand_all_rb);
367 gtk_widget_show(expand_all_rb);
369 /* "Print hex" check button. */
370 hex_cb = CHECK_BUTTON_NEW_WITH_MNEMONIC("Packet bytes", accel_group);
371 gtk_toggle_button_set_state(GTK_TOGGLE_BUTTON(hex_cb), args->print_hex);
372 SIGNAL_CONNECT(hex_cb, "clicked", print_cmd_toggle_detail, print_w);
373 gtk_tooltips_set_tip (tooltips, hex_cb, ("Add a hexdump of the packet data"), NULL);
374 gtk_container_add(GTK_CONTAINER(format_vb), hex_cb);
375 gtk_widget_show(hex_cb);
378 sep = gtk_hseparator_new();
379 gtk_container_add(GTK_CONTAINER(format_vb), sep);
380 gtk_widget_show(sep);
382 /* "Each packet on a new page" check button. */
383 formfeed_cb = CHECK_BUTTON_NEW_WITH_MNEMONIC("Each packet on a new page", accel_group);
384 gtk_toggle_button_set_state(GTK_TOGGLE_BUTTON(formfeed_cb), args->print_formfeed);
385 gtk_tooltips_set_tip (tooltips, formfeed_cb, ("When checked, a new page will be used for each packet. "
386 "This is done by adding a formfeed (or similar) between the packet outputs."), NULL);
387 gtk_container_add(GTK_CONTAINER(format_vb), formfeed_cb);
388 gtk_widget_show(formfeed_cb);
391 OBJECT_SET_DATA(print_w, PRINT_ARGS_KEY, args);
392 OBJECT_SET_DATA(print_w, PRINT_SUMMARY_CB_KEY, summary_cb);
393 OBJECT_SET_DATA(print_w, PRINT_DETAILS_CB_KEY, details_cb);
394 OBJECT_SET_DATA(print_w, PRINT_COLLAPSE_ALL_RB_KEY, collapse_all_rb);
395 OBJECT_SET_DATA(print_w, PRINT_AS_DISPLAYED_RB_KEY, as_displayed_rb);
396 OBJECT_SET_DATA(print_w, PRINT_EXPAND_ALL_RB_KEY, expand_all_rb);
397 OBJECT_SET_DATA(print_w, PRINT_HEX_CB_KEY, hex_cb);
399 /*****************************************************/
403 bbox = dlg_button_row_new(GTK_STOCK_PRINT, GTK_STOCK_CANCEL, NULL);
404 gtk_box_pack_start(GTK_BOX(main_vb), bbox, FALSE, FALSE, 0);
405 gtk_widget_show(bbox);
407 ok_bt = OBJECT_GET_DATA(bbox, GTK_STOCK_PRINT);
409 OBJECT_SET_DATA(print_w, PRINT_BT_KEY, ok_bt);
411 OBJECT_SET_DATA(ok_bt, PRINT_PS_RB_KEY, ps_rb);
412 OBJECT_SET_DATA(ok_bt, PRINT_PDML_RB_KEY, pdml_rb);
413 OBJECT_SET_DATA(ok_bt, PRINT_PSML_RB_KEY, psml_rb);
414 OBJECT_SET_DATA(ok_bt, PRINT_DEST_CB_KEY, dest_cb);
416 OBJECT_SET_DATA(ok_bt, PRINT_CMD_TE_KEY, cmd_te);
419 OBJECT_SET_DATA(ok_bt, PRINT_ARGS_KEY, args);
420 OBJECT_SET_DATA(ok_bt, PRINT_FILE_TE_KEY, file_te);
421 OBJECT_SET_DATA(ok_bt, PRINT_SUMMARY_CB_KEY, summary_cb);
422 OBJECT_SET_DATA(ok_bt, PRINT_DETAILS_CB_KEY, details_cb);
423 OBJECT_SET_DATA(ok_bt, PRINT_COLLAPSE_ALL_RB_KEY, collapse_all_rb);
424 OBJECT_SET_DATA(ok_bt, PRINT_AS_DISPLAYED_RB_KEY, as_displayed_rb);
425 OBJECT_SET_DATA(ok_bt, PRINT_EXPAND_ALL_RB_KEY, expand_all_rb);
426 OBJECT_SET_DATA(ok_bt, PRINT_HEX_CB_KEY, hex_cb);
427 OBJECT_SET_DATA(ok_bt, PRINT_FORMFEED_CB_KEY, formfeed_cb);
428 SIGNAL_CONNECT(ok_bt, "clicked", print_ok_cb, print_w);
429 gtk_tooltips_set_tip (tooltips, ok_bt, ("Start printing"), NULL);
430 gtk_widget_grab_default(ok_bt);
432 cancel_bt = OBJECT_GET_DATA(bbox, GTK_STOCK_CANCEL);
433 SIGNAL_CONNECT(cancel_bt, "clicked", print_close_cb, print_w);
434 gtk_tooltips_set_tip (tooltips, cancel_bt, ("Cancel print and exit dialog"), NULL);
436 /* Catch the "activate" signal on the "Command" and "File" text entries,
437 so that if the user types Return there, we act as if the "OK" button
438 had been selected, as happens if Return is typed if some widget
439 that *doesn't* handle the Return key has the input focus. */
442 dlg_set_activate(cmd_te, ok_bt);
444 dlg_set_activate(file_te, ok_bt);
446 /* Catch the "key_press_event" signal in the window, so that we can catch
447 the ESC key being pressed and act as if the "Cancel" button had
449 dlg_set_cancel(print_w, cancel_bt);
451 gtk_widget_show(print_w);
455 /* user changed "print to" destination */
457 print_cmd_toggle_dest(GtkWidget *widget, gpointer data _U_)
460 GtkWidget *cmd_lb, *cmd_te;
462 GtkWidget *file_bt, *file_te;
466 cmd_lb = GTK_WIDGET(OBJECT_GET_DATA(widget, PRINT_CMD_LB_KEY));
467 cmd_te = GTK_WIDGET(OBJECT_GET_DATA(widget, PRINT_CMD_TE_KEY));
469 file_bt = GTK_WIDGET(OBJECT_GET_DATA(widget, PRINT_FILE_BT_KEY));
470 file_te = GTK_WIDGET(OBJECT_GET_DATA(widget, PRINT_FILE_TE_KEY));
472 to_file = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON (widget));
474 gtk_widget_set_sensitive(cmd_lb, !to_file);
475 gtk_widget_set_sensitive(cmd_te, !to_file);
477 gtk_widget_set_sensitive(file_bt, to_file);
478 gtk_widget_set_sensitive(file_te, to_file);
482 /* user changed "packet details" */
484 print_cmd_toggle_detail(GtkWidget *widget _U_, gpointer data)
486 GtkWidget *print_bt, *summary_cb, *details_cb, *collapse_all_rb, *expand_all_rb, *as_displayed_rb, *hex_cb;
487 gboolean print_detail;
490 print_bt = GTK_WIDGET(OBJECT_GET_DATA(data, PRINT_BT_KEY));
491 summary_cb = GTK_WIDGET(OBJECT_GET_DATA(data, PRINT_SUMMARY_CB_KEY));
492 details_cb = GTK_WIDGET(OBJECT_GET_DATA(data, PRINT_DETAILS_CB_KEY));
493 collapse_all_rb = GTK_WIDGET(OBJECT_GET_DATA(data, PRINT_COLLAPSE_ALL_RB_KEY));
494 as_displayed_rb = GTK_WIDGET(OBJECT_GET_DATA(data, PRINT_AS_DISPLAYED_RB_KEY));
495 expand_all_rb = GTK_WIDGET(OBJECT_GET_DATA(data, PRINT_EXPAND_ALL_RB_KEY));
496 hex_cb = GTK_WIDGET(OBJECT_GET_DATA(data, PRINT_HEX_CB_KEY));
498 /* is user disabled details, disable the corresponding buttons */
499 print_detail = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON (details_cb));
500 gtk_widget_set_sensitive(collapse_all_rb, print_detail);
501 gtk_widget_set_sensitive(as_displayed_rb, print_detail);
502 gtk_widget_set_sensitive(expand_all_rb, print_detail);
504 /* if user selected nothing to print at all, disable the "ok" button */
505 gtk_widget_set_sensitive(print_bt,
506 gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON (summary_cb)) ||
507 gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON (details_cb)) ||
508 gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON (hex_cb)));
513 print_ok_cb(GtkWidget *ok_bt, gpointer parent_w)
521 int win_printer_flag = FALSE;
524 args = (print_args_t *)OBJECT_GET_DATA(ok_bt, PRINT_ARGS_KEY);
526 button = (GtkWidget *)OBJECT_GET_DATA(ok_bt, PRINT_DEST_CB_KEY);
527 args->to_file = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON (button));
530 g_dest = gtk_entry_get_text(GTK_ENTRY(OBJECT_GET_DATA(ok_bt,
531 PRINT_FILE_TE_KEY)));
533 simple_dialog(ESD_TYPE_ERROR, ESD_BTN_OK,
534 "Printing to file, but no file specified.");
538 args->file = g_strdup(g_dest);
539 /* Save the directory name for future file dialogs. */
540 f_name = g_strdup(g_dest);
541 dirname = get_dirname(f_name); /* Overwrites f_name */
542 set_last_open_dir(dirname);
546 win_printer_flag = TRUE;
547 /*XXX should use temp file stuff in util routines */
549 args->file = g_strdup(tmpnam(NULL));
550 args->to_file = TRUE;
553 args->cmd = g_strdup(gtk_entry_get_text(GTK_ENTRY(OBJECT_GET_DATA(ok_bt,
554 PRINT_CMD_TE_KEY))));
558 args->format = PR_FMT_TEXT;
559 button = (GtkWidget *)OBJECT_GET_DATA(ok_bt, PRINT_PS_RB_KEY);
560 if (gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON (button)))
561 args->format = PR_FMT_PS;
562 button = (GtkWidget *)OBJECT_GET_DATA(ok_bt, PRINT_PDML_RB_KEY);
563 if (gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON (button)))
564 args->format = PR_FMT_PDML;
565 button = (GtkWidget *)OBJECT_GET_DATA(ok_bt, PRINT_PSML_RB_KEY);
566 if (gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON (button)))
567 args->format = PR_FMT_PSML;
569 button = (GtkWidget *)OBJECT_GET_DATA(ok_bt, PRINT_SUMMARY_CB_KEY);
570 args->print_summary = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON (button));
572 button = (GtkWidget *)OBJECT_GET_DATA(ok_bt, PRINT_COLLAPSE_ALL_RB_KEY);
573 if (gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON (button))) {
574 args->print_dissections = print_dissections_collapsed;
576 button = (GtkWidget *)OBJECT_GET_DATA(ok_bt, PRINT_AS_DISPLAYED_RB_KEY);
577 if (gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON (button))) {
578 args->print_dissections = print_dissections_as_displayed;
580 button = (GtkWidget *)OBJECT_GET_DATA(ok_bt, PRINT_EXPAND_ALL_RB_KEY);
581 if (gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON (button))) {
582 args->print_dissections = print_dissections_expanded;
585 /* the details setting has priority over the radio buttons */
586 button = (GtkWidget *)OBJECT_GET_DATA(ok_bt, PRINT_DETAILS_CB_KEY);
587 if (!gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON (button))) {
588 args->print_dissections = print_dissections_none;
591 button = (GtkWidget *)OBJECT_GET_DATA(ok_bt, PRINT_HEX_CB_KEY);
592 args->print_hex = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON (button));
594 button = (GtkWidget *)OBJECT_GET_DATA(ok_bt, PRINT_FORMFEED_CB_KEY);
595 args->print_formfeed = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON (button));
598 gtk_widget_destroy(GTK_WIDGET(parent_w));
600 /* Now print the packets */
601 switch (print_packets(&cfile, args)) {
608 open_failure_alert_box(args->file, errno, TRUE);
610 simple_dialog(ESD_TYPE_ERROR, ESD_BTN_OK, "Couldn't run print command %s.",
616 write_failure_alert_box(args->file, errno);
618 simple_dialog(ESD_TYPE_ERROR, ESD_BTN_OK,
619 "Error writing to print command: %s", strerror(errno));
624 if (win_printer_flag) {
625 print_mswin(args->file);
627 /* trash temp file */
634 print_close_cb(GtkWidget *close_bt _U_, gpointer parent_w)
636 gtk_grab_remove(GTK_WIDGET(parent_w));
637 gtk_widget_destroy(GTK_WIDGET(parent_w));
641 print_destroy_cb(GtkWidget *win, gpointer user_data _U_)
645 /* Is there a file selection dialog associated with this
646 Print File dialog? */
647 fs = OBJECT_GET_DATA(win, E_FILE_SEL_DIALOG_PTR_KEY);
650 /* Yes. Destroy it. */
651 gtk_widget_destroy(fs);
654 /* Note that we no longer have a "Print" dialog box. */