name change
[obnox/wireshark/wip.git] / gtk / print_prefs.c
1 /* print_prefs.c
2  * Dialog boxes for preferences for printing
3  *
4  * $Id$
5  *
6  * Wireshark - Network traffic analyzer
7  * By Gerald Combs <gerald@wireshark.org>
8  * Copyright 1998 Gerald Combs
9  *
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.
14  *
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.
19  *
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.
23  */
24
25 #ifdef HAVE_CONFIG_H
26 #include "config.h"
27 #endif
28
29 #include <errno.h>
30 #include <gtk/gtk.h>
31
32 #include "globals.h"
33 #include "print_prefs.h"
34 #include "keys.h"
35 #include "print.h"
36 #include <epan/prefs.h>
37 #include "prefs_dlg.h"
38 #include "util.h"
39 #include "gui_utils.h"
40 #if 0
41 #include "dlg_utils.h"
42 #endif
43 #include "file_dlg.h"
44 #include "capture_file_dlg.h"
45 #include "compat_macros.h"
46 #include "gtkglobals.h"
47
48 static void printer_browse_file_cb(GtkWidget *file_bt, GtkWidget *file_te);
49
50 #define E_PRINT_FORMAT_KEY        "print_format"
51 #define E_PRINT_DESTINATION_KEY   "print_destination"
52
53 static const enum_val_t print_format_vals[] = {
54         { "text",       "Plain Text", PR_FMT_TEXT },
55         { "postscript", "Postscript", PR_FMT_PS },
56         { NULL,         NULL,         0 }
57 };
58
59 static const enum_val_t print_dest_vals[] = {
60 #ifdef _WIN32
61         /* "PR_DEST_CMD" means "to printer" on Windows */
62         { "command", "Printer", PR_DEST_CMD },
63 #else
64         { "command", "Command", PR_DEST_CMD },
65 #endif
66         { "file",    "File",    PR_DEST_FILE },
67         { NULL,      NULL,      0 }
68 };
69
70 GtkWidget * printer_prefs_show(void)
71 {
72         GtkWidget       *main_vb, *main_tb, *button;
73 #ifndef _WIN32
74         GtkWidget       *cmd_te;
75 #endif
76         GtkWidget       *file_lb_hb, *file_lb, *file_bt_hb, *file_bt, *file_te;
77
78         /* Enclosing containers for each row of widgets */
79         main_vb = gtk_vbox_new(FALSE, 5);
80         gtk_container_border_width(GTK_CONTAINER(main_vb), 5);
81
82         main_tb = gtk_table_new(4, 2, FALSE);
83         gtk_box_pack_start(GTK_BOX(main_vb), main_tb, FALSE, FALSE, 0);
84         gtk_table_set_row_spacings(GTK_TABLE(main_tb), 10);
85         gtk_table_set_col_spacings(GTK_TABLE(main_tb), 15);
86         gtk_widget_show(main_tb);
87
88         /* Output format */
89         button = create_preference_radio_buttons(main_tb, 0, "Format:",
90            NULL, print_format_vals, prefs.pr_format);
91         OBJECT_SET_DATA(main_vb, E_PRINT_FORMAT_KEY, button);
92
93         /* Output destination */
94         button = create_preference_radio_buttons(main_tb, 1, "Print to:",
95            NULL, print_dest_vals, prefs.pr_dest);
96         OBJECT_SET_DATA(main_vb, E_PRINT_DESTINATION_KEY,
97            button);
98
99 #ifndef _WIN32
100         /* Command text entry */
101         cmd_te = create_preference_entry(main_tb, 2, "Command:", NULL,
102           prefs.pr_cmd);
103         OBJECT_SET_DATA(main_vb, PRINT_CMD_TE_KEY, cmd_te);
104 #endif
105
106
107         file_lb_hb = gtk_hbox_new(FALSE, 0);
108         gtk_table_attach_defaults(GTK_TABLE(main_tb), file_lb_hb, 0, 1, 3, 4);
109         gtk_widget_show(file_lb_hb);
110
111     file_lb = gtk_label_new("File:");
112         gtk_box_pack_end(GTK_BOX(file_lb_hb), file_lb, FALSE, FALSE, 0);
113         gtk_widget_show(file_lb);
114
115         /* File button and text entry */
116         file_bt_hb = gtk_hbox_new(FALSE, 0);
117         gtk_table_attach_defaults(GTK_TABLE(main_tb), file_bt_hb, 1, 2, 3, 4);
118         gtk_widget_show(file_bt_hb);
119
120     file_bt = BUTTON_NEW_FROM_STOCK(ETHEREAL_STOCK_BROWSE);
121         gtk_box_pack_end(GTK_BOX(file_bt_hb), file_bt, FALSE, FALSE, 0);
122         gtk_widget_show(file_bt);
123
124         file_te = gtk_entry_new();
125         OBJECT_SET_DATA(main_vb, PRINT_FILE_TE_KEY, file_te);
126         if (prefs.pr_file) gtk_entry_set_text(GTK_ENTRY(file_te), prefs.pr_file);
127         gtk_box_pack_start(GTK_BOX(file_bt_hb), file_te, TRUE, TRUE, 0);
128         gtk_widget_show(file_te);
129
130         SIGNAL_CONNECT(file_bt, "clicked", printer_browse_file_cb, file_te);
131
132         gtk_widget_show(main_vb);
133         return(main_vb);
134 }
135
136
137 static void
138 printer_browse_file_cb(GtkWidget *file_bt, GtkWidget *file_te)
139 {
140     file_selection_browse(file_bt, file_te, "Ethereal: Print to a File",
141                           FILE_SELECTION_WRITE_BROWSE);
142 }
143
144
145 void
146 printer_prefs_fetch(GtkWidget *w)
147 {
148   prefs.pr_format = fetch_preference_radio_buttons_val(
149         OBJECT_GET_DATA(w, E_PRINT_FORMAT_KEY), print_format_vals);
150
151   prefs.pr_dest = fetch_preference_radio_buttons_val(
152         OBJECT_GET_DATA(w, E_PRINT_DESTINATION_KEY), print_dest_vals);
153
154 #ifndef _WIN32
155   if (prefs.pr_cmd)
156     g_free(prefs.pr_cmd);
157   prefs.pr_cmd = g_strdup(gtk_entry_get_text(
158                           GTK_ENTRY(OBJECT_GET_DATA(w, PRINT_CMD_TE_KEY))));
159 #endif
160
161   if (prefs.pr_file)
162     g_free(prefs.pr_file);
163   prefs.pr_file = g_strdup(gtk_entry_get_text(
164                            GTK_ENTRY(OBJECT_GET_DATA(w, PRINT_FILE_TE_KEY))));
165 }
166
167 void
168 printer_prefs_apply(GtkWidget *w _U_)
169 {
170 }
171
172 void
173 printer_prefs_destroy(GtkWidget *w)
174 {
175   GtkWidget *caller = gtk_widget_get_toplevel(w);
176   GtkWidget *fs;
177
178   /* Is there a file selection dialog associated with this
179      Preferences dialog? */
180   fs = OBJECT_GET_DATA(caller, E_FILE_SEL_DIALOG_PTR_KEY);
181
182   if (fs != NULL) {
183     /* Yes.  Destroy it. */
184     window_destroy(fs);
185   }
186 }