2 * Dialog boxes for preferences for printing
6 * Wireshark - Network traffic analyzer
7 * By Gerald Combs <gerald@wireshark.org>
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.
32 #include <epan/prefs.h>
37 #include "gtk/prefs_print.h"
39 #include "gtk/prefs_dlg.h"
40 #include "gtk/gui_utils.h"
41 #include "gtk/file_dlg.h"
42 #include "gtk/capture_file_dlg.h"
43 #include "gtk/stock_icons.h"
44 #include "gtk/gtkglobals.h"
47 static void printer_browse_file_cb(GtkWidget *file_bt, GtkWidget *file_te);
49 #define E_PRINT_FORMAT_KEY "print_format"
50 #define E_PRINT_DESTINATION_KEY "print_destination"
52 static const enum_val_t print_format_vals[] = {
53 { "text", "Plain Text", PR_FMT_TEXT },
54 { "postscript", "Postscript", PR_FMT_PS },
58 static const enum_val_t print_dest_vals[] = {
60 /* "PR_DEST_CMD" means "to printer" on Windows */
61 { "command", "Printer", PR_DEST_CMD },
63 { "command", "Command", PR_DEST_CMD },
65 { "file", "File", PR_DEST_FILE },
69 GtkWidget * printer_prefs_show(void)
71 GtkWidget *main_vb, *main_tb, *button;
75 GtkWidget *file_lb_hb, *file_lb, *file_bt_hb, *file_bt, *file_te;
77 /* Enclosing containers for each row of widgets */
78 main_vb = gtk_vbox_new(FALSE, 5);
79 gtk_container_set_border_width(GTK_CONTAINER(main_vb), 5);
81 main_tb = gtk_table_new(4, 2, FALSE);
82 gtk_box_pack_start(GTK_BOX(main_vb), main_tb, FALSE, FALSE, 0);
83 gtk_table_set_row_spacings(GTK_TABLE(main_tb), 10);
84 gtk_table_set_col_spacings(GTK_TABLE(main_tb), 15);
85 gtk_widget_show(main_tb);
88 button = create_preference_radio_buttons(main_tb, 0, "Format:",
89 NULL, print_format_vals, prefs.pr_format);
90 g_object_set_data(G_OBJECT(main_vb), E_PRINT_FORMAT_KEY, button);
92 /* Output destination */
93 button = create_preference_radio_buttons(main_tb, 1, "Print to:",
94 NULL, print_dest_vals, prefs.pr_dest);
95 g_object_set_data(G_OBJECT(main_vb), E_PRINT_DESTINATION_KEY,
99 /* Command text entry */
100 cmd_te = create_preference_entry(main_tb, 2, "Command:", NULL,
102 g_object_set_data(G_OBJECT(main_vb), PRINT_CMD_TE_KEY, cmd_te);
106 file_lb_hb = gtk_hbox_new(FALSE, 0);
107 gtk_table_attach_defaults(GTK_TABLE(main_tb), file_lb_hb, 0, 1, 3, 4);
108 gtk_widget_show(file_lb_hb);
110 file_lb = gtk_label_new("File:");
111 gtk_box_pack_end(GTK_BOX(file_lb_hb), file_lb, FALSE, FALSE, 0);
112 gtk_widget_show(file_lb);
114 /* File button and text entry */
115 file_bt_hb = gtk_hbox_new(FALSE, 0);
116 gtk_table_attach_defaults(GTK_TABLE(main_tb), file_bt_hb, 1, 2, 3, 4);
117 gtk_widget_show(file_bt_hb);
119 file_bt = gtk_button_new_from_stock(WIRESHARK_STOCK_BROWSE);
120 gtk_box_pack_end(GTK_BOX(file_bt_hb), file_bt, FALSE, FALSE, 0);
121 gtk_widget_show(file_bt);
123 file_te = gtk_entry_new();
124 g_object_set_data(G_OBJECT(main_vb), PRINT_FILE_TE_KEY, file_te);
125 if (prefs.pr_file) gtk_entry_set_text(GTK_ENTRY(file_te), prefs.pr_file);
126 gtk_box_pack_start(GTK_BOX(file_bt_hb), file_te, TRUE, TRUE, 0);
127 gtk_widget_show(file_te);
129 g_signal_connect(file_bt, "clicked", G_CALLBACK(printer_browse_file_cb), file_te);
131 gtk_widget_show(main_vb);
137 printer_browse_file_cb(GtkWidget *file_bt, GtkWidget *file_te)
139 file_selection_browse(file_bt, file_te, "Wireshark: Print to a File",
140 FILE_SELECTION_WRITE_BROWSE);
145 printer_prefs_fetch(GtkWidget *w)
147 prefs.pr_format = fetch_preference_radio_buttons_val(
148 g_object_get_data(G_OBJECT(w), E_PRINT_FORMAT_KEY), print_format_vals);
150 prefs.pr_dest = fetch_preference_radio_buttons_val(
151 g_object_get_data(G_OBJECT(w), E_PRINT_DESTINATION_KEY), print_dest_vals);
154 g_free(prefs.pr_cmd);
155 prefs.pr_cmd = g_strdup(gtk_entry_get_text(
156 GTK_ENTRY(g_object_get_data(G_OBJECT(w), PRINT_CMD_TE_KEY))));
159 g_free(prefs.pr_file);
160 prefs.pr_file = g_strdup(gtk_entry_get_text(
161 GTK_ENTRY(g_object_get_data(G_OBJECT(w), PRINT_FILE_TE_KEY))));
165 printer_prefs_apply(GtkWidget *w _U_)
170 printer_prefs_destroy(GtkWidget *w)
172 GtkWidget *caller = gtk_widget_get_toplevel(w);
175 /* Is there a file selection dialog associated with this
176 Preferences dialog? */
177 fs = g_object_get_data(G_OBJECT(caller), E_FILE_SEL_DIALOG_PTR_KEY);
180 /* Yes. Destroy it. */