2 * Routines for handling preferences
4 * $Id: prefs_dlg.c,v 1.11 2000/05/08 07:58:20 guy Exp $
6 * Ethereal - Network traffic analyzer
7 * By Gerald Combs <gerald@zing.org>
8 * Copyright 1998 Gerald Combs
11 * This program is free software; you can redistribute it and/or
12 * modify it under the terms of the GNU General Public License
13 * as published by the Free Software Foundation; either version 2
14 * of the License, or (at your option) any later version.
16 * This program is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 * GNU General Public License for more details.
21 * You should have received a copy of the GNU General Public License
22 * along with this program; if not, write to the Free Software
23 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
30 #ifdef HAVE_SYS_TYPES_H
31 #include <sys/types.h>
51 #include "column_prefs.h"
53 #include "prefs_dlg.h"
54 #include "print_prefs.h"
55 #include "stream_prefs.h"
56 #include "gui_prefs.h"
59 #include "dlg_utils.h"
60 #include "simple_dialog.h"
62 static void prefs_main_ok_cb(GtkWidget *, gpointer);
63 static void prefs_main_save_cb(GtkWidget *, gpointer);
64 static void prefs_main_cancel_cb(GtkWidget *, gpointer);
65 static gboolean prefs_main_delete_cb(GtkWidget *, gpointer);
66 static void prefs_main_destroy_cb(GtkWidget *, gpointer);
68 #define E_PRINT_PAGE_KEY "printer_options_page"
69 #define E_COLUMN_PAGE_KEY "column_options_page"
70 #define E_STREAM_PAGE_KEY "tcp_stream_options_page"
71 #define E_GUI_PAGE_KEY "gui_options_page"
74 * Keep a static pointer to the current "Preferences" window, if any, so that
75 * if somebody tries to do "Edit:Preferences" while there's already a
76 * "Preferences" window up, we just pop up the existing one, rather than
79 static GtkWidget *prefs_w;
82 prefs_cb(GtkWidget *w, gpointer sp) {
83 GtkWidget *main_vb, *top_hb, *bbox, *prefs_nb,
84 *ok_bt, *save_bt, *cancel_bt;
85 GtkWidget *print_pg, *column_pg, *stream_pg, *gui_pg, *label;
87 gint start_page = (gint) sp;
89 if (prefs_w != NULL) {
90 /* There's already a "Preferences" dialog box; reactivate it. */
91 reactivate_window(prefs_w);
95 prefs_w = gtk_window_new(GTK_WINDOW_TOPLEVEL);
96 gtk_window_set_title(GTK_WINDOW(prefs_w), "Ethereal: Preferences");
97 gtk_signal_connect(GTK_OBJECT(prefs_w), "delete-event",
98 GTK_SIGNAL_FUNC(prefs_main_delete_cb), NULL);
99 gtk_signal_connect(GTK_OBJECT(prefs_w), "destroy",
100 GTK_SIGNAL_FUNC(prefs_main_destroy_cb), NULL);
102 /* Container for each row of widgets */
103 main_vb = gtk_vbox_new(FALSE, 5);
104 gtk_container_border_width(GTK_CONTAINER(main_vb), 5);
105 gtk_container_add(GTK_CONTAINER(prefs_w), main_vb);
106 gtk_widget_show(main_vb);
108 /* Top row: Preferences notebook */
109 top_hb = gtk_hbox_new(FALSE, 1);
110 gtk_container_add(GTK_CONTAINER(main_vb), top_hb);
111 gtk_widget_show(top_hb);
113 prefs_nb = gtk_notebook_new();
114 gtk_container_add(GTK_CONTAINER(main_vb), prefs_nb);
115 gtk_widget_show(prefs_nb);
118 print_pg = printer_prefs_show();
119 gtk_object_set_data(GTK_OBJECT(prefs_w), E_PRINT_PAGE_KEY, print_pg);
120 label = gtk_label_new ("Printing");
121 gtk_notebook_append_page (GTK_NOTEBOOK(prefs_nb), print_pg, label);
124 column_pg = column_prefs_show();
125 gtk_object_set_data(GTK_OBJECT(prefs_w), E_COLUMN_PAGE_KEY, column_pg);
126 label = gtk_label_new ("Columns");
127 gtk_notebook_append_page (GTK_NOTEBOOK(prefs_nb), column_pg, label);
129 /* TCP Streams prefs */
130 stream_pg = stream_prefs_show();
131 gtk_object_set_data(GTK_OBJECT(prefs_w), E_STREAM_PAGE_KEY, stream_pg);
132 label = gtk_label_new ("TCP Streams");
133 gtk_notebook_append_page (GTK_NOTEBOOK(prefs_nb), stream_pg, label);
136 gui_pg = gui_prefs_show();
137 gtk_object_set_data(GTK_OBJECT(prefs_w), E_GUI_PAGE_KEY, gui_pg);
138 label = gtk_label_new ("GUI");
139 gtk_notebook_append_page (GTK_NOTEBOOK(prefs_nb), gui_pg, label);
141 /* Jump to the specified page, if it was supplied */
142 if (start_page > E_PR_PG_NONE)
143 gtk_notebook_set_page(GTK_NOTEBOOK(prefs_nb), start_page);
145 /* Button row: OK and cancel buttons */
146 bbox = gtk_hbutton_box_new();
147 gtk_button_box_set_layout (GTK_BUTTON_BOX (bbox), GTK_BUTTONBOX_END);
148 gtk_button_box_set_spacing(GTK_BUTTON_BOX(bbox), 5);
149 gtk_container_add(GTK_CONTAINER(main_vb), bbox);
150 gtk_widget_show(bbox);
152 ok_bt = gtk_button_new_with_label ("OK");
153 gtk_signal_connect(GTK_OBJECT(ok_bt), "clicked",
154 GTK_SIGNAL_FUNC(prefs_main_ok_cb), GTK_OBJECT(prefs_w));
155 GTK_WIDGET_SET_FLAGS(ok_bt, GTK_CAN_DEFAULT);
156 gtk_box_pack_start (GTK_BOX (bbox), ok_bt, TRUE, TRUE, 0);
157 gtk_widget_grab_default(ok_bt);
158 gtk_widget_show(ok_bt);
160 save_bt = gtk_button_new_with_label ("Save");
161 gtk_signal_connect(GTK_OBJECT(save_bt), "clicked",
162 GTK_SIGNAL_FUNC(prefs_main_save_cb), GTK_OBJECT(prefs_w));
163 GTK_WIDGET_SET_FLAGS(save_bt, GTK_CAN_DEFAULT);
164 gtk_box_pack_start (GTK_BOX (bbox), save_bt, TRUE, TRUE, 0);
165 gtk_widget_show(save_bt);
167 cancel_bt = gtk_button_new_with_label ("Cancel");
168 gtk_signal_connect(GTK_OBJECT(cancel_bt), "clicked",
169 GTK_SIGNAL_FUNC(prefs_main_cancel_cb), GTK_OBJECT(prefs_w));
170 GTK_WIDGET_SET_FLAGS(cancel_bt, GTK_CAN_DEFAULT);
171 gtk_box_pack_start (GTK_BOX (bbox), cancel_bt, TRUE, TRUE, 0);
172 gtk_widget_show(cancel_bt);
174 /* Catch the "key_press_event" signal in the window, so that we can catch
175 the ESC key being pressed and act as if the "Cancel" button had
177 dlg_set_cancel(prefs_w, cancel_bt);
179 gtk_widget_show(prefs_w);
183 prefs_main_ok_cb(GtkWidget *ok_bt, gpointer parent_w)
185 printer_prefs_ok(gtk_object_get_data(GTK_OBJECT(parent_w), E_PRINT_PAGE_KEY));
186 column_prefs_ok(gtk_object_get_data(GTK_OBJECT(parent_w), E_COLUMN_PAGE_KEY));
187 stream_prefs_ok(gtk_object_get_data(GTK_OBJECT(parent_w), E_STREAM_PAGE_KEY));
188 gui_prefs_ok(gtk_object_get_data(GTK_OBJECT(parent_w), E_GUI_PAGE_KEY));
189 gtk_widget_destroy(GTK_WIDGET(parent_w));
193 prefs_main_save_cb(GtkWidget *save_bt, gpointer parent_w)
198 printer_prefs_save(gtk_object_get_data(GTK_OBJECT(parent_w), E_PRINT_PAGE_KEY));
199 column_prefs_save(gtk_object_get_data(GTK_OBJECT(parent_w), E_COLUMN_PAGE_KEY));
200 stream_prefs_save(gtk_object_get_data(GTK_OBJECT(parent_w), E_STREAM_PAGE_KEY));
201 gui_prefs_save(gtk_object_get_data(GTK_OBJECT(parent_w), E_GUI_PAGE_KEY));
202 err = write_prefs(&pf_path);
204 simple_dialog(ESD_TYPE_WARN, NULL,
205 "Can't open preferences file\n\"%s\": %s.", pf_path,
211 prefs_main_cancel_cb(GtkWidget *cancel_bt, gpointer parent_w)
213 printer_prefs_cancel(gtk_object_get_data(GTK_OBJECT(parent_w), E_PRINT_PAGE_KEY));
214 column_prefs_cancel(gtk_object_get_data(GTK_OBJECT(parent_w), E_COLUMN_PAGE_KEY));
215 stream_prefs_cancel(gtk_object_get_data(GTK_OBJECT(parent_w), E_STREAM_PAGE_KEY));
216 gui_prefs_cancel(gtk_object_get_data(GTK_OBJECT(parent_w), E_GUI_PAGE_KEY));
217 gtk_widget_destroy(GTK_WIDGET(parent_w));
221 prefs_main_delete_cb(GtkWidget *prefs_w, gpointer dummy)
223 printer_prefs_delete(gtk_object_get_data(GTK_OBJECT(prefs_w), E_PRINT_PAGE_KEY));
224 column_prefs_delete(gtk_object_get_data(GTK_OBJECT(prefs_w), E_COLUMN_PAGE_KEY));
225 stream_prefs_delete(gtk_object_get_data(GTK_OBJECT(prefs_w), E_STREAM_PAGE_KEY));
226 gui_prefs_delete(gtk_object_get_data(GTK_OBJECT(prefs_w), E_GUI_PAGE_KEY));
231 prefs_main_destroy_cb(GtkWidget *win, gpointer user_data)
233 /* XXX - call the delete callback? Or move its stuff here and
236 /* Note that we no longer have a "Preferences" dialog box. */