aboutsummaryrefslogtreecommitdiffstats
path: root/gtk
diff options
context:
space:
mode:
authorGuy Harris <guy@alum.mit.edu>2004-03-29 22:40:58 +0000
committerGuy Harris <guy@alum.mit.edu>2004-03-29 22:40:58 +0000
commit29c644691b49c655372aa355f51b4e33eaef7d99 (patch)
tree6719c44647f45c9072ae42483e919cad6d7f6046 /gtk
parent08c04ec97398e122efff4fb3c5145716ed110525 (diff)
Make "file_selection_new()" take as its second argument an
Ethereal-defined indication of the action (open vs. save), regardless of whether we're building for GTK+ >= 2.4 or not; we just ignore the argument in pre-2.4 GTK+. Use "file_selection_new()" rather than #if'ed code to use it or "gtk_file_chooser_dialog_new()" for GTK+ >= 2.4 and "gtk_file_selection_new()" or it for pre-2.4 GTK+. Add a "file_selection_set_current_folder()" routine that does the appropriate thing depending on whether we're GTK+ >= 2.4 or not, and use that rather than #if'ed code to use "gtk_file_chooser_set_current_folder()" or "gtk_file_selection_set_filename()". svn path=/trunk/; revision=10511
Diffstat (limited to 'gtk')
-rw-r--r--gtk/capture_dlg.c19
-rw-r--r--gtk/dlg_utils.c49
-rw-r--r--gtk/dlg_utils.h15
-rw-r--r--gtk/file_dlg.c84
-rw-r--r--gtk/follow_dlg.c33
-rw-r--r--gtk/print_prefs.c10
6 files changed, 80 insertions, 130 deletions
diff --git a/gtk/capture_dlg.c b/gtk/capture_dlg.c
index 44b4f3ded8..c373199f38 100644
--- a/gtk/capture_dlg.c
+++ b/gtk/capture_dlg.c
@@ -1,7 +1,7 @@
/* capture_dlg.c
* Routines for packet capture windows
*
- * $Id: capture_dlg.c,v 1.123 2004/03/27 12:18:40 ulfl Exp $
+ * $Id: capture_dlg.c,v 1.124 2004/03/29 22:40:57 guy Exp $
*
* Ethereal - Network traffic analyzer
* By Gerald Combs <gerald@ethereal.com>
@@ -1043,25 +1043,12 @@ capture_prep_file_cb(GtkWidget *w, gpointer file_te)
return;
}
-#if (GTK_MAJOR_VERSION == 2 && GTK_MINOR_VERSION >= 4) || GTK_MAJOR_VERSION > 2
- fs = gtk_file_chooser_dialog_new("Ethereal: Capture File",
- GTK_WINDOW(top_level),
- GTK_FILE_CHOOSER_ACTION_SAVE,
- GTK_STOCK_OPEN, GTK_RESPONSE_ACCEPT,
- GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL,
- NULL);
-#else
- fs = file_selection_new ("Ethereal: Capture File");
-#endif
+ fs = file_selection_new("Ethereal: Capture File", FILE_SELECTION_SAVE);
/* If we've opened a file, start out by showing the files in the directory
in which that file resided. */
if (last_open_dir)
-#if (GTK_MAJOR_VERSION == 2 && GTK_MINOR_VERSION >= 4) || GTK_MAJOR_VERSION > 2
- gtk_file_chooser_set_current_folder(GTK_FILE_CHOOSER(fs), last_open_dir);
-#else
- gtk_file_selection_set_filename(GTK_FILE_SELECTION(fs), last_open_dir);
-#endif
+ file_selection_set_current_folder(fs, last_open_dir);
OBJECT_SET_DATA(fs, E_CAP_FILE_TE_KEY, file_te);
diff --git a/gtk/dlg_utils.c b/gtk/dlg_utils.c
index 3b3856089d..0c6014f58d 100644
--- a/gtk/dlg_utils.c
+++ b/gtk/dlg_utils.c
@@ -1,7 +1,7 @@
/* dlg_utils.c
* Utilities to use when constructing dialogs
*
- * $Id: dlg_utils.c,v 1.22 2004/03/27 11:16:58 oabad Exp $
+ * $Id: dlg_utils.c,v 1.23 2004/03/29 22:40:57 guy Exp $
*
* Ethereal - Network traffic analyzer
* By Gerald Combs <gerald@ethereal.com>
@@ -31,6 +31,7 @@
#include "gtkglobals.h"
#include "ui_util.h"
+#include "dlg_utils.h"
#include "compat_macros.h"
#include <string.h>
@@ -323,29 +324,59 @@ dlg_window_new(const gchar *title)
main window. */
#if (GTK_MAJOR_VERSION == 2 && GTK_MINOR_VERSION >= 4) || GTK_MAJOR_VERSION > 2
GtkWidget *
-file_selection_new(const gchar *title, GtkFileChooserAction action)
-#else
-GtkWidget *
-file_selection_new(const gchar *title)
-#endif
+file_selection_new(const gchar *title, file_selection_action_t action)
{
GtkWidget *win;
+ GtkFileChooserAction gtk_action;
-#if (GTK_MAJOR_VERSION == 2 && GTK_MINOR_VERSION >= 4) || GTK_MAJOR_VERSION > 2
- win = gtk_file_chooser_dialog_new(title, GTK_WINDOW(top_level), action,
+ switch (action) {
+
+ case FILE_SELECTION_OPEN:
+ gtk_action = GTK_FILE_CHOOSER_ACTION_OPEN;
+ break;
+
+ case FILE_SELECTION_SAVE:
+ gtk_action = GTK_FILE_CHOOSER_ACTION_SAVE;
+ break;
+
+ default:
+ g_assert_not_reached();
+ gtk_action = -1;
+ break;
+ }
+ win = gtk_file_chooser_dialog_new(title, GTK_WINDOW(top_level), gtk_action,
GTK_STOCK_OPEN, GTK_RESPONSE_ACCEPT,
GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL,
NULL);
gtk_window_set_position(GTK_WINDOW(win), GTK_WIN_POS_CENTER_ON_PARENT);
+ return win;
+}
#else
+GtkWidget *
+file_selection_new(const gchar *title, file_selection_action_t action _U_)
+{
+ GtkWidget *win;
+
win = gtk_file_selection_new(title);
#if GTK_MAJOR_VERSION >= 2
gtk_window_set_position(GTK_WINDOW(win), GTK_WIN_POS_CENTER_ON_PARENT);
#endif
gtk_window_set_transient_for(GTK_WINDOW(win), GTK_WINDOW(top_level));
-#endif
return win;
}
+#endif
+
+/* Set the current folder for a file selection dialog. */
+gboolean
+file_selection_set_current_folder(GtkWidget *fs, const gchar *filename)
+{
+#if (GTK_MAJOR_VERSION == 2 && GTK_MINOR_VERSION >= 4) || GTK_MAJOR_VERSION > 2
+ return gtk_file_chooser_set_current_folder(GTK_FILE_CHOOSER(fs), filename);
+#else
+ gtk_file_selection_set_filename(GTK_FILE_SELECTION(fs), filename);
+ return TRUE;
+#endif
+}
/* Set the "activate" signal for a widget to call a routine to
activate the "OK" button for a dialog box.
diff --git a/gtk/dlg_utils.h b/gtk/dlg_utils.h
index ed7edc2299..32e77b0c21 100644
--- a/gtk/dlg_utils.h
+++ b/gtk/dlg_utils.h
@@ -1,7 +1,7 @@
/* dlg_utils.h
* Declarations of utilities to use when constructing dialogs
*
- * $Id: dlg_utils.h,v 1.10 2004/03/27 11:16:58 oabad Exp $
+ * $Id: dlg_utils.h,v 1.11 2004/03/29 22:40:57 guy Exp $
*
* Ethereal - Network traffic analyzer
* By Gerald Combs <gerald@ethereal.com>
@@ -30,11 +30,14 @@ extern GtkWidget *dlg_window_new(const gchar *);
/* Create a file selection dialog box window that belongs to Ethereal's
main window. */
-#if (GTK_MAJOR_VERSION == 2 && GTK_MINOR_VERSION >= 4) || GTK_MAJOR_VERSION > 2
-extern GtkWidget *file_selection_new(const gchar *, GtkFileChooserAction);
-#else
-extern GtkWidget *file_selection_new(const gchar *);
-#endif
+typedef enum {
+ FILE_SELECTION_OPEN,
+ FILE_SELECTION_SAVE
+} file_selection_action_t;
+extern GtkWidget *file_selection_new(const gchar *, file_selection_action_t);
+
+/* Set the current folder for a file selection dialog. */
+extern gboolean file_selection_set_current_folder(GtkWidget *, const gchar *);
/* Create a button row for a dialog */
/* the button widgets will be available by OBJECT_GET_DATA(stock_id) */
diff --git a/gtk/file_dlg.c b/gtk/file_dlg.c
index 6a8e901dec..93abe2a78f 100644
--- a/gtk/file_dlg.c
+++ b/gtk/file_dlg.c
@@ -1,7 +1,7 @@
/* file_dlg.c
* Dialog boxes for handling files
*
- * $Id: file_dlg.c,v 1.100 2004/03/27 12:18:40 ulfl Exp $
+ * $Id: file_dlg.c,v 1.101 2004/03/29 22:40:58 guy Exp $
*
* Ethereal - Network traffic analyzer
* By Gerald Combs <gerald@ethereal.com>
@@ -112,20 +112,12 @@ select_file_cb(GtkWidget *file_bt, const char *label)
return;
}
-#if (GTK_MAJOR_VERSION == 2 && GTK_MINOR_VERSION >= 4) || GTK_MAJOR_VERSION > 2
- fs = file_selection_new(label, GTK_FILE_CHOOSER_ACTION_SAVE);
-#else
- fs = file_selection_new(label);
-#endif
+ fs = file_selection_new(label, FILE_SELECTION_SAVE);
/* If we've opened a file, start out by showing the files in the directory
in which that file resided. */
if (last_open_dir)
-#if (GTK_MAJOR_VERSION == 2 && GTK_MINOR_VERSION >= 4) || GTK_MAJOR_VERSION > 2
- gtk_file_chooser_set_current_folder(GTK_FILE_CHOOSER(fs), last_open_dir);
-#else
- gtk_file_selection_set_filename(GTK_FILE_SELECTION(fs), last_open_dir);
-#endif
+ file_selection_set_current_folder(fs, last_open_dir);
OBJECT_SET_DATA(fs, PRINT_FILE_TE_KEY, file_te);
@@ -251,12 +243,8 @@ file_open_cmd(GtkWidget *w)
return;
}
-#if (GTK_MAJOR_VERSION == 2 && GTK_MINOR_VERSION >= 4) || GTK_MAJOR_VERSION > 2
file_open_w = file_selection_new("Ethereal: Open Capture File",
- GTK_FILE_CHOOSER_ACTION_OPEN);
-#else
- file_open_w = file_selection_new("Ethereal: Open Capture File");
-#endif
+ FILE_SELECTION_OPEN);
SIGNAL_CONNECT(file_open_w, "destroy", file_open_destroy_cb, NULL);
#if GTK_MAJOR_VERSION < 2
@@ -275,30 +263,16 @@ file_open_cmd(GtkWidget *w)
directory, if we could determine it, as the directory, otherwise
use the "last opened" directory saved in the preferences file if
there was one. */
- if (last_open_dir) {
-#if (GTK_MAJOR_VERSION == 2 && GTK_MINOR_VERSION >= 4) || GTK_MAJOR_VERSION > 2
- gtk_file_chooser_set_current_folder(GTK_FILE_CHOOSER(file_open_w),
- last_open_dir);
-#else
- gtk_file_selection_set_filename(GTK_FILE_SELECTION(file_open_w),
- last_open_dir);
-#endif
- }
+ if (last_open_dir)
+ file_selection_set_current_folder(file_open_w, last_open_dir);
break;
case FO_STYLE_SPECIFIED:
/* The user has specified that we should always start out in a
specified directory; if they've specified that directory,
start out by showing the files in that dir. */
- if (prefs.gui_fileopen_dir[0] != '\0') {
-#if (GTK_MAJOR_VERSION == 2 && GTK_MINOR_VERSION >= 4) || GTK_MAJOR_VERSION > 2
- gtk_file_chooser_set_current_folder(GTK_FILE_CHOOSER(file_open_w),
- prefs.gui_fileopen_dir);
-#else
- gtk_file_selection_set_filename(GTK_FILE_SELECTION(file_open_w),
- prefs.gui_fileopen_dir);
-#endif
- }
+ if (prefs.gui_fileopen_dir[0] != '\0')
+ file_selection_set_current_folder(file_open_w, prefs.gui_fileopen_dir);
break;
}
@@ -907,12 +881,8 @@ file_save_as_cmd(action_after_save_e action_after_save, gpointer action_after_sa
tooltips = gtk_tooltips_new();
/* build the file selection */
-#if (GTK_MAJOR_VERSION == 2 && GTK_MINOR_VERSION >= 4) || GTK_MAJOR_VERSION > 2
file_save_as_w = file_selection_new ("Ethereal: Save Capture File As",
- GTK_FILE_CHOOSER_ACTION_SAVE);
-#else
- file_save_as_w = file_selection_new ("Ethereal: Save Capture File As");
-#endif
+ FILE_SELECTION_SAVE);
SIGNAL_CONNECT(file_save_as_w, "destroy", file_save_as_destroy_cb, NULL);
/* as the dialog might already be gone, when using this values, we cannot
@@ -928,13 +898,7 @@ file_save_as_cmd(action_after_save_e action_after_save, gpointer action_after_sa
/* If we've opened a file, start out by showing the files in the directory
in which that file resided. */
if (last_open_dir)
-#if (GTK_MAJOR_VERSION == 2 && GTK_MINOR_VERSION >= 4) || GTK_MAJOR_VERSION > 2
- gtk_file_chooser_set_current_folder(GTK_FILE_CHOOSER(file_save_as_w),
- last_open_dir);
-#else
- gtk_file_selection_set_filename(GTK_FILE_SELECTION(file_save_as_w),
- last_open_dir);
-#endif
+ file_selection_set_current_folder(file_save_as_w, last_open_dir);
/* Container for each row of widgets */
@@ -1313,12 +1277,8 @@ file_color_import_cmd_cb(GtkWidget *w _U_, gpointer data)
return;
}
-#if (GTK_MAJOR_VERSION == 2 && GTK_MINOR_VERSION >= 4) || GTK_MAJOR_VERSION > 2
file_color_import_w = file_selection_new("Ethereal: Import Color Filters",
- GTK_FILE_CHOOSER_ACTION_OPEN);
-#else
- file_color_import_w = gtk_file_selection_new("Ethereal: Import Color Filters");
-#endif
+ FILE_SELECTION_OPEN);
SIGNAL_CONNECT(file_color_import_w, "destroy", file_color_import_destroy_cb, NULL);
#if GTK_MAJOR_VERSION < 2
@@ -1332,13 +1292,7 @@ file_color_import_cmd_cb(GtkWidget *w _U_, gpointer data)
/* If we've opened a file, start out by showing the files in the directory
in which that file resided. */
if (last_open_dir)
-#if (GTK_MAJOR_VERSION == 2 && GTK_MINOR_VERSION >= 4) || GTK_MAJOR_VERSION > 2
- gtk_file_chooser_set_current_folder(GTK_FILE_CHOOSER(file_color_import_w),
- last_open_dir);
-#else
- gtk_file_selection_set_filename(GTK_FILE_SELECTION(file_color_import_w),
- last_open_dir);
-#endif
+ file_selection_set_current_folder(file_color_import_w, last_open_dir);
/* Container for each row of widgets */
main_vb = gtk_vbox_new(FALSE, 3);
@@ -1494,25 +1448,15 @@ file_color_export_cmd_cb(GtkWidget *w _U_, gpointer data _U_)
color_marked = FALSE;
filetype = cfile.cd_t;
-#if (GTK_MAJOR_VERSION == 2 && GTK_MINOR_VERSION >= 4) || GTK_MAJOR_VERSION > 2
file_color_export_w = file_selection_new("Ethereal: Export Color Filters",
- GTK_FILE_CHOOSER_ACTION_SAVE);
-#else
- file_color_export_w = gtk_file_selection_new("Ethereal: Export Color Filters");
-#endif
+ FILE_SELECTION_SAVE);
SIGNAL_CONNECT(file_color_export_w, "destroy", file_color_export_destroy_cb, NULL);
/* If we've opened a file, start out by showing the files in the directory
in which that file resided. */
if (last_open_dir)
-#if (GTK_MAJOR_VERSION == 2 && GTK_MINOR_VERSION >= 4) || GTK_MAJOR_VERSION > 2
- gtk_file_chooser_set_current_folder(GTK_FILE_CHOOSER(file_color_export_w),
- last_open_dir);
-#else
- gtk_file_selection_set_filename(GTK_FILE_SELECTION(file_color_export_w),
- last_open_dir);
+ file_selection_set_current_folder(file_color_export_w, last_open_dir);
-#endif
/* Container for each row of widgets */
main_vb = gtk_vbox_new(FALSE, 3);
gtk_container_border_width(GTK_CONTAINER(main_vb), 5);
diff --git a/gtk/follow_dlg.c b/gtk/follow_dlg.c
index 8a9455a907..9df2de190e 100644
--- a/gtk/follow_dlg.c
+++ b/gtk/follow_dlg.c
@@ -1,6 +1,6 @@
/* follow_dlg.c
*
- * $Id: follow_dlg.c,v 1.54 2004/03/27 11:16:58 oabad Exp $
+ * $Id: follow_dlg.c,v 1.55 2004/03/29 22:40:58 guy Exp $
*
* Ethereal - Network traffic analyzer
* By Gerald Combs <gerald@ethereal.com>
@@ -934,7 +934,10 @@ follow_load_text(follow_info_t *follow_info)
static void
follow_save_as_cmd_cb(GtkWidget *w _U_, gpointer data)
{
- GtkWidget *ok_bt, *new_win;
+#if GTK_MAJOR_VERSION < 2 || (GTK_MAJOR_VERSION == 2 && GTK_MINOR_VERSION < 4)
+ GtkWidget *ok_bt;
+#endif
+ GtkWidget *new_win;
follow_info_t *follow_info = data;
if (follow_info->follow_save_as_w != NULL) {
@@ -943,36 +946,26 @@ follow_save_as_cmd_cb(GtkWidget *w _U_, gpointer data)
return;
}
-#if (GTK_MAJOR_VERSION == 2 && GTK_MINOR_VERSION >= 4) || GTK_MAJOR_VERSION > 2
new_win = file_selection_new("Ethereal: Save TCP Follow Stream As",
- GTK_FILE_CHOOSER_ACTION_SAVE);
-#else
- new_win = gtk_file_selection_new("Ethereal: Save TCP Follow Stream As");
-#endif
+ FILE_SELECTION_SAVE);
follow_info->follow_save_as_w = new_win;
SIGNAL_CONNECT(new_win, "destroy", follow_save_as_destroy_cb, follow_info);
/* Tuck away the follow_info object into the window */
OBJECT_SET_DATA(new_win, E_FOLLOW_INFO_KEY, follow_info);
-#if (GTK_MAJOR_VERSION == 2 && GTK_MINOR_VERSION >= 4) || GTK_MAJOR_VERSION > 2
/* If we've opened a file, start out by showing the files in the directory
in which that file resided. */
if (last_open_dir)
- gtk_file_chooser_set_current_folder(GTK_FILE_CHOOSER(new_win),
- last_open_dir);
+ file_selection_set_current_folder(new_win, last_open_dir);
+
+#if (GTK_MAJOR_VERSION == 2 && GTK_MINOR_VERSION >= 4) || GTK_MAJOR_VERSION > 2
if (gtk_dialog_run(GTK_DIALOG(new_win)) == GTK_RESPONSE_ACCEPT)
{
follow_save_as_ok_cb(new_win, new_win);
}
else gtk_widget_destroy(new_win);
#else
- /* If we've opened a file, start out by showing the files in the directory
- in which that file resided. */
- if (last_open_dir)
- gtk_file_selection_set_filename(GTK_FILE_SELECTION(new_win),
- last_open_dir);
-
/* Connect the ok_button to file_save_as_ok_cb function and pass along a
pointer to the file selection box widget */
ok_bt = GTK_FILE_SELECTION(new_win)->ok_button;
@@ -1015,13 +1008,7 @@ follow_save_as_ok_cb(GtkWidget * w _U_, gpointer fs)
directory, and leave the selection box displayed. */
set_last_open_dir(to_name);
g_free(to_name);
-#if (GTK_MAJOR_VERSION == 2 && GTK_MINOR_VERSION >= 4) || GTK_MAJOR_VERSION > 2
- gtk_file_chooser_set_current_folder(GTK_FILE_CHOOSER(fs),
- last_open_dir);
-#else
- gtk_file_selection_set_filename(GTK_FILE_SELECTION(fs),
- last_open_dir);
-#endif
+ file_selection_set_current_folder(fs, last_open_dir);
return;
}
diff --git a/gtk/print_prefs.c b/gtk/print_prefs.c
index 93658bd6b1..4875b1123f 100644
--- a/gtk/print_prefs.c
+++ b/gtk/print_prefs.c
@@ -1,7 +1,7 @@
/* print_prefs.c
* Dialog boxes for preferences for printing
*
- * $Id: print_prefs.c,v 1.18 2004/03/27 11:16:58 oabad Exp $
+ * $Id: print_prefs.c,v 1.19 2004/03/29 22:40:58 guy Exp $
*
* Ethereal - Network traffic analyzer
* By Gerald Combs <gerald@ethereal.com>
@@ -152,12 +152,10 @@ printer_opts_file_cb(GtkWidget *file_bt, gpointer file_te) {
return;
}
-#if (GTK_MAJOR_VERSION == 2 && GTK_MINOR_VERSION >= 4) || GTK_MAJOR_VERSION > 2
fs = file_selection_new("Ethereal: Print to a File",
- GTK_FILE_CHOOSER_ACTION_SAVE);
-#else
- fs = gtk_file_selection_new ("Ethereal: Print to a File");
- OBJECT_SET_DATA(fs, PRINT_FILE_TE_KEY, file_te);
+ FILE_SELECTION_SAVE);
+#if GTK_MAJOR_VERSION < 2 || (GTK_MAJOR_VERSION == 2 && GTK_MINOR_VERSION < 4)
+ OBJECT_SET_DATA(fs, PRINT_FILE_TE_KEY, file_te);
#endif
/* Set the E_FS_CALLER_PTR_KEY for the new dialog to point to our caller. */