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