1999-09-09 04:25:49 +00:00
|
|
|
/* print_prefs.c
|
|
|
|
* Dialog boxes for preferences for printing
|
|
|
|
*
|
2004-07-18 00:24:25 +00:00
|
|
|
* $Id$
|
1999-09-09 04:25:49 +00:00
|
|
|
*
|
|
|
|
* Ethereal - Network traffic analyzer
|
2002-01-11 07:40:32 +00:00
|
|
|
* By Gerald Combs <gerald@ethereal.com>
|
1999-09-09 04:25:49 +00:00
|
|
|
* Copyright 1998 Gerald Combs
|
2002-08-28 21:04:11 +00:00
|
|
|
*
|
1999-09-09 04:25:49 +00:00
|
|
|
* This program is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU General Public License
|
|
|
|
* as published by the Free Software Foundation; either version 2
|
|
|
|
* of the License, or (at your option) any later version.
|
2002-08-28 21:04:11 +00:00
|
|
|
*
|
1999-09-09 04:25:49 +00:00
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
2002-08-28 21:04:11 +00:00
|
|
|
*
|
1999-09-09 04:25:49 +00:00
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program; if not, write to the Free Software
|
|
|
|
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
|
|
|
*/
|
1999-09-01 03:04:24 +00:00
|
|
|
|
|
|
|
#ifdef HAVE_CONFIG_H
|
|
|
|
#include "config.h"
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#include <errno.h>
|
2000-10-20 04:26:40 +00:00
|
|
|
#include <gtk/gtk.h>
|
1999-09-01 03:04:24 +00:00
|
|
|
|
|
|
|
#include "globals.h"
|
We need to catch a "window delete" event for the preferences dialog box
- that event happens if, say, you nuke the dialog box from a window
manager - and call "delete" routines for each of the preferences tabs,
so that, for preferences tabs that include list widgets, we can set a
flag on the preferences tab widget telling the selection callback for
the list widget that the buttons it would normally set the sensitivity
of, based on whether any row in the list is selected or not, have Joined
the Choir Invisible, and therefore that we shouldn't change their
sensitivity because GTK+ will whine at us if we do, just as is the case
if we press the "OK" or "Cancel" button (which also cause the window to
go away).
Can we just do this in the "window delete" handler? I.e., does that get
called if we explicitly destroy the widget? Or should we catch a
"destroy" event instead?
(There must be a better way to do this....)
svn path=/trunk/; revision=647
1999-09-10 06:53:32 +00:00
|
|
|
#include "print_prefs.h"
|
1999-09-01 03:04:24 +00:00
|
|
|
#include "keys.h"
|
|
|
|
#include "print.h"
|
2004-09-27 22:55:15 +00:00
|
|
|
#include <epan/prefs.h>
|
2002-01-13 20:35:12 +00:00
|
|
|
#include "prefs_dlg.h"
|
1999-09-01 03:04:24 +00:00
|
|
|
#include "util.h"
|
2000-05-08 07:54:54 +00:00
|
|
|
#include "ui_util.h"
|
|
|
|
#include "dlg_utils.h"
|
2004-05-26 03:49:24 +00:00
|
|
|
#include "file_dlg.h"
|
2002-11-11 15:39:06 +00:00
|
|
|
#include "compat_macros.h"
|
2004-03-27 11:16:58 +00:00
|
|
|
#include "gtkglobals.h"
|
2000-05-08 07:54:54 +00:00
|
|
|
|
2004-05-26 04:21:49 +00:00
|
|
|
static void printer_browse_file_cb(GtkWidget *file_bt, GtkWidget *file_te);
|
1999-09-01 03:04:24 +00:00
|
|
|
|
2002-01-13 20:35:12 +00:00
|
|
|
#define E_PRINT_FORMAT_KEY "print_format"
|
|
|
|
#define E_PRINT_DESTINATION_KEY "print_destination"
|
|
|
|
|
|
|
|
static const enum_val_t print_format_vals[] = {
|
2004-05-24 02:25:21 +00:00
|
|
|
{ "text", "Plain Text", PR_FMT_TEXT },
|
|
|
|
{ "postscript", "Postscript", PR_FMT_PS },
|
|
|
|
{ NULL, NULL, 0 }
|
2002-01-13 20:35:12 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
static const enum_val_t print_dest_vals[] = {
|
2002-08-13 07:54:37 +00:00
|
|
|
#ifdef _WIN32
|
|
|
|
/* "PR_DEST_CMD" means "to printer" on Windows */
|
2004-05-24 02:25:21 +00:00
|
|
|
{ "command", "Printer", PR_DEST_CMD },
|
2002-08-13 07:54:37 +00:00
|
|
|
#else
|
2004-05-24 02:25:21 +00:00
|
|
|
{ "command", "Command", PR_DEST_CMD },
|
2002-08-13 07:54:37 +00:00
|
|
|
#endif
|
2004-05-24 02:25:21 +00:00
|
|
|
{ "file", "File", PR_DEST_FILE },
|
|
|
|
{ NULL, NULL, 0 }
|
2002-01-13 20:35:12 +00:00
|
|
|
};
|
1999-09-01 03:04:24 +00:00
|
|
|
|
2002-01-11 07:40:32 +00:00
|
|
|
GtkWidget * printer_prefs_show(void)
|
1999-09-01 03:04:24 +00:00
|
|
|
{
|
|
|
|
GtkWidget *main_vb, *main_tb, *button;
|
2002-08-13 07:54:37 +00:00
|
|
|
#ifndef _WIN32
|
2002-01-13 20:35:12 +00:00
|
|
|
GtkWidget *cmd_te;
|
2002-08-13 07:54:37 +00:00
|
|
|
#endif
|
2004-01-21 03:54:32 +00:00
|
|
|
GtkWidget *file_lb_hb, *file_lb, *file_bt_hb, *file_bt, *file_te;
|
1999-09-01 03:04:24 +00:00
|
|
|
|
|
|
|
/* Enclosing containers for each row of widgets */
|
2002-01-11 07:40:32 +00:00
|
|
|
main_vb = gtk_vbox_new(FALSE, 5);
|
|
|
|
gtk_container_border_width(GTK_CONTAINER(main_vb), 5);
|
1999-09-01 03:04:24 +00:00
|
|
|
|
|
|
|
main_tb = gtk_table_new(4, 2, FALSE);
|
|
|
|
gtk_box_pack_start(GTK_BOX(main_vb), main_tb, FALSE, FALSE, 0);
|
2002-01-11 07:40:32 +00:00
|
|
|
gtk_table_set_row_spacings(GTK_TABLE(main_tb), 10);
|
|
|
|
gtk_table_set_col_spacings(GTK_TABLE(main_tb), 15);
|
|
|
|
gtk_widget_show(main_tb);
|
1999-09-01 03:04:24 +00:00
|
|
|
|
|
|
|
/* Output format */
|
2002-01-13 20:35:12 +00:00
|
|
|
button = create_preference_radio_buttons(main_tb, 0, "Format:",
|
2002-01-20 20:05:18 +00:00
|
|
|
NULL, print_format_vals, prefs.pr_format);
|
2002-11-11 15:39:06 +00:00
|
|
|
OBJECT_SET_DATA(main_vb, E_PRINT_FORMAT_KEY, button);
|
1999-09-01 03:04:24 +00:00
|
|
|
|
|
|
|
/* Output destination */
|
2002-01-13 20:35:12 +00:00
|
|
|
button = create_preference_radio_buttons(main_tb, 1, "Print to:",
|
2002-01-20 20:05:18 +00:00
|
|
|
NULL, print_dest_vals, prefs.pr_dest);
|
2002-11-11 15:39:06 +00:00
|
|
|
OBJECT_SET_DATA(main_vb, E_PRINT_DESTINATION_KEY,
|
2002-01-13 20:35:12 +00:00
|
|
|
button);
|
1999-09-01 03:04:24 +00:00
|
|
|
|
2002-08-13 07:54:37 +00:00
|
|
|
#ifndef _WIN32
|
1999-09-01 03:04:24 +00:00
|
|
|
/* Command text entry */
|
2002-01-20 20:05:18 +00:00
|
|
|
cmd_te = create_preference_entry(main_tb, 2, "Command:", NULL,
|
|
|
|
prefs.pr_cmd);
|
2002-11-11 15:39:06 +00:00
|
|
|
OBJECT_SET_DATA(main_vb, PRINT_CMD_TE_KEY, cmd_te);
|
2002-08-13 07:54:37 +00:00
|
|
|
#endif
|
1999-09-01 03:04:24 +00:00
|
|
|
|
2004-01-21 03:54:32 +00:00
|
|
|
|
|
|
|
file_lb_hb = gtk_hbox_new(FALSE, 0);
|
|
|
|
gtk_table_attach_defaults(GTK_TABLE(main_tb), file_lb_hb, 0, 1, 3, 4);
|
|
|
|
gtk_widget_show(file_lb_hb);
|
|
|
|
|
|
|
|
file_lb = gtk_label_new("File:");
|
|
|
|
gtk_box_pack_end(GTK_BOX(file_lb_hb), file_lb, FALSE, FALSE, 0);
|
|
|
|
gtk_widget_show(file_lb);
|
|
|
|
|
1999-09-01 03:04:24 +00:00
|
|
|
/* File button and text entry */
|
|
|
|
file_bt_hb = gtk_hbox_new(FALSE, 0);
|
2004-01-21 03:54:32 +00:00
|
|
|
gtk_table_attach_defaults(GTK_TABLE(main_tb), file_bt_hb, 1, 2, 3, 4);
|
1999-09-01 03:04:24 +00:00
|
|
|
gtk_widget_show(file_bt_hb);
|
|
|
|
|
2004-01-21 03:54:32 +00:00
|
|
|
file_bt = BUTTON_NEW_FROM_STOCK(ETHEREAL_STOCK_BROWSE);
|
1999-09-01 03:04:24 +00:00
|
|
|
gtk_box_pack_end(GTK_BOX(file_bt_hb), file_bt, FALSE, FALSE, 0);
|
|
|
|
gtk_widget_show(file_bt);
|
|
|
|
|
|
|
|
file_te = gtk_entry_new();
|
2002-11-11 15:39:06 +00:00
|
|
|
OBJECT_SET_DATA(main_vb, PRINT_FILE_TE_KEY, file_te);
|
1999-09-01 03:04:24 +00:00
|
|
|
if (prefs.pr_file) gtk_entry_set_text(GTK_ENTRY(file_te), prefs.pr_file);
|
2004-01-21 03:54:32 +00:00
|
|
|
gtk_box_pack_start(GTK_BOX(file_bt_hb), file_te, TRUE, TRUE, 0);
|
1999-09-01 03:04:24 +00:00
|
|
|
gtk_widget_show(file_te);
|
|
|
|
|
2004-05-26 03:49:24 +00:00
|
|
|
SIGNAL_CONNECT(file_bt, "clicked", printer_browse_file_cb, file_te);
|
1999-09-01 03:04:24 +00:00
|
|
|
|
|
|
|
gtk_widget_show(main_vb);
|
|
|
|
return(main_vb);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static void
|
2004-05-26 03:49:24 +00:00
|
|
|
printer_browse_file_cb(GtkWidget *file_bt, GtkWidget *file_te)
|
2000-05-08 07:54:54 +00:00
|
|
|
{
|
2004-05-26 03:49:24 +00:00
|
|
|
file_selection_browse(file_bt, file_te, "Ethereal: Print to a File", FILE_SELECTION_SAVE);
|
2000-05-08 07:54:54 +00:00
|
|
|
}
|
|
|
|
|
2004-05-26 03:49:24 +00:00
|
|
|
|
1999-09-01 03:04:24 +00:00
|
|
|
void
|
Instead of each set of built-in preferences having "ok", "save",
"cancel", and "delete" methods, give them:
"fetch" - fetch from the notebook tab any values not already
stored in "prefs", and store them there, but doesn't apply them;
"apply" - apply the settings in "prefs";
"destroy" - clean up any windows created from the tab.
As we no longer have "cancel" methods, we don't have per-preference code
to revert preference values; instead, we have the common preference
dialog box code make a copy of all the current preferences, and, when
the "Cancel" button is clicked, free the current preferences and copy
the saved preferences to it, and apply the preferences.
Add an "Apply" button to the preference dialog box, which applies the
current preferences without closing the dialog box.
Treat a request to delete the preferences dialog box as equivalent to
clicking "Cancel".
Have a "remember_ptree_widget()" routine to remember all protocol tree
widgets, and use the list of those widgets when we set GUI preferences
for the protocol tree widgets, rather than setting the main protocol
tree widget and then using the list of packet windows. Move that code
out of "main.c" to "proto_draw.c", as it's not used by anything in
"main.c", but is used by stuff in "proto_draw.c".
Make the font one of the preferences we can set on the fly for protocol
tree widgets. Also make it something we can set on the fly for the
packet list widget.
svn path=/trunk/; revision=2316
2000-08-21 08:09:17 +00:00
|
|
|
printer_prefs_fetch(GtkWidget *w)
|
1999-09-01 03:04:24 +00:00
|
|
|
{
|
2002-01-13 20:35:12 +00:00
|
|
|
prefs.pr_format = fetch_preference_radio_buttons_val(
|
2002-11-11 15:39:06 +00:00
|
|
|
OBJECT_GET_DATA(w, E_PRINT_FORMAT_KEY), print_format_vals);
|
2002-01-13 20:35:12 +00:00
|
|
|
|
|
|
|
prefs.pr_dest = fetch_preference_radio_buttons_val(
|
2002-11-11 15:39:06 +00:00
|
|
|
OBJECT_GET_DATA(w, E_PRINT_DESTINATION_KEY), print_dest_vals);
|
2002-01-13 20:35:12 +00:00
|
|
|
|
2002-08-13 07:54:37 +00:00
|
|
|
#ifndef _WIN32
|
2002-01-13 20:35:12 +00:00
|
|
|
if (prefs.pr_cmd)
|
|
|
|
g_free(prefs.pr_cmd);
|
|
|
|
prefs.pr_cmd = g_strdup(gtk_entry_get_text(
|
2002-11-11 15:39:06 +00:00
|
|
|
GTK_ENTRY(OBJECT_GET_DATA(w, PRINT_CMD_TE_KEY))));
|
2002-08-13 07:54:37 +00:00
|
|
|
#endif
|
2002-01-13 20:35:12 +00:00
|
|
|
|
|
|
|
if (prefs.pr_file)
|
|
|
|
g_free(prefs.pr_file);
|
|
|
|
prefs.pr_file = g_strdup(gtk_entry_get_text(
|
2002-11-11 15:39:06 +00:00
|
|
|
GTK_ENTRY(OBJECT_GET_DATA(w, PRINT_FILE_TE_KEY))));
|
1999-09-01 03:04:24 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2002-03-05 11:56:00 +00:00
|
|
|
printer_prefs_apply(GtkWidget *w _U_)
|
We need to catch a "window delete" event for the preferences dialog box
- that event happens if, say, you nuke the dialog box from a window
manager - and call "delete" routines for each of the preferences tabs,
so that, for preferences tabs that include list widgets, we can set a
flag on the preferences tab widget telling the selection callback for
the list widget that the buttons it would normally set the sensitivity
of, based on whether any row in the list is selected or not, have Joined
the Choir Invisible, and therefore that we shouldn't change their
sensitivity because GTK+ will whine at us if we do, just as is the case
if we press the "OK" or "Cancel" button (which also cause the window to
go away).
Can we just do this in the "window delete" handler? I.e., does that get
called if we explicitly destroy the widget? Or should we catch a
"destroy" event instead?
(There must be a better way to do this....)
svn path=/trunk/; revision=647
1999-09-10 06:53:32 +00:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
Instead of each set of built-in preferences having "ok", "save",
"cancel", and "delete" methods, give them:
"fetch" - fetch from the notebook tab any values not already
stored in "prefs", and store them there, but doesn't apply them;
"apply" - apply the settings in "prefs";
"destroy" - clean up any windows created from the tab.
As we no longer have "cancel" methods, we don't have per-preference code
to revert preference values; instead, we have the common preference
dialog box code make a copy of all the current preferences, and, when
the "Cancel" button is clicked, free the current preferences and copy
the saved preferences to it, and apply the preferences.
Add an "Apply" button to the preference dialog box, which applies the
current preferences without closing the dialog box.
Treat a request to delete the preferences dialog box as equivalent to
clicking "Cancel".
Have a "remember_ptree_widget()" routine to remember all protocol tree
widgets, and use the list of those widgets when we set GUI preferences
for the protocol tree widgets, rather than setting the main protocol
tree widget and then using the list of packet windows. Move that code
out of "main.c" to "proto_draw.c", as it's not used by anything in
"main.c", but is used by stuff in "proto_draw.c".
Make the font one of the preferences we can set on the fly for protocol
tree widgets. Also make it something we can set on the fly for the
packet list widget.
svn path=/trunk/; revision=2316
2000-08-21 08:09:17 +00:00
|
|
|
printer_prefs_destroy(GtkWidget *w)
|
1999-09-01 03:04:24 +00:00
|
|
|
{
|
2000-05-08 07:54:54 +00:00
|
|
|
GtkWidget *caller = gtk_widget_get_toplevel(w);
|
|
|
|
GtkWidget *fs;
|
|
|
|
|
|
|
|
/* Is there a file selection dialog associated with this
|
|
|
|
Preferences dialog? */
|
2002-11-11 15:39:06 +00:00
|
|
|
fs = OBJECT_GET_DATA(caller, E_FILE_SEL_DIALOG_PTR_KEY);
|
2000-05-08 07:54:54 +00:00
|
|
|
|
|
|
|
if (fs != NULL) {
|
|
|
|
/* Yes. Destroy it. */
|
2004-05-26 03:49:24 +00:00
|
|
|
window_destroy(fs);
|
2000-05-08 07:54:54 +00:00
|
|
|
}
|
1999-09-01 03:04:24 +00:00
|
|
|
}
|