diff options
author | Guy Harris <guy@alum.mit.edu> | 2000-01-03 06:29:39 +0000 |
---|---|---|
committer | Guy Harris <guy@alum.mit.edu> | 2000-01-03 06:29:39 +0000 |
commit | 302c1164834d14e5b239f17b04e41c503c07605b (patch) | |
tree | e4574fea9d9f020a19787b715c774abd43b31570 | |
parent | 77e59876a7a34e094731791cbd95e07a637179c4 (diff) | |
download | wireshark-302c1164834d14e5b239f17b04e41c503c07605b.tar.gz wireshark-302c1164834d14e5b239f17b04e41c503c07605b.tar.bz2 wireshark-302c1164834d14e5b239f17b04e41c503c07605b.zip |
Don't have "write_prefs()" display a dialog box if the attempt to open
the preferences file fails, have it return an error indication and the
path of the preferences file, and have its caller display the dialog
box. That way you don't have to drag in the dialog box code if you're
going to use the preferences code in, say, a "line-mode" Ethereal.
svn path=/trunk/; revision=1413
-rw-r--r-- | gtk/prefs_dlg.c | 14 | ||||
-rw-r--r-- | prefs.c | 20 | ||||
-rw-r--r-- | prefs.h | 4 |
3 files changed, 26 insertions, 12 deletions
diff --git a/gtk/prefs_dlg.c b/gtk/prefs_dlg.c index 66495b0276..9f610d1705 100644 --- a/gtk/prefs_dlg.c +++ b/gtk/prefs_dlg.c @@ -1,7 +1,7 @@ /* prefs_dlg.c * Routines for handling preferences * - * $Id: prefs_dlg.c,v 1.6 1999/12/29 05:53:48 guy Exp $ + * $Id: prefs_dlg.c,v 1.7 2000/01/03 06:29:39 guy Exp $ * * Ethereal - Network traffic analyzer * By Gerald Combs <gerald@zing.org> @@ -34,6 +34,7 @@ #include <gtk/gtk.h> #include <stdlib.h> +#include <string.h> #include <ctype.h> #include <errno.h> @@ -54,6 +55,7 @@ #include "stream_prefs.h" #include "gui_prefs.h" #include "util.h" +#include "ui_util.h" static void prefs_main_ok_cb(GtkWidget *, gpointer); static void prefs_main_save_cb(GtkWidget *, gpointer); @@ -168,11 +170,19 @@ prefs_main_ok_cb(GtkWidget *ok_bt, gpointer parent_w) static void prefs_main_save_cb(GtkWidget *save_bt, gpointer parent_w) { + int err; + char *pf_path; + printer_prefs_save(gtk_object_get_data(GTK_OBJECT(parent_w), E_PRINT_PAGE_KEY)); column_prefs_save(gtk_object_get_data(GTK_OBJECT(parent_w), E_COLUMN_PAGE_KEY)); stream_prefs_save(gtk_object_get_data(GTK_OBJECT(parent_w), E_STREAM_PAGE_KEY)); gui_prefs_save(gtk_object_get_data(GTK_OBJECT(parent_w), E_GUI_PAGE_KEY)); - write_prefs(); + err = write_prefs(&pf_path); + if (err != 0) { + simple_dialog(ESD_TYPE_WARN, NULL, + "Can't open preferences file\n\"%s\": %s.", pf_path, + strerror(err)); + } } static void @@ -1,7 +1,7 @@ /* prefs.c * Routines for handling preferences * - * $Id: prefs.c,v 1.28 1999/12/30 23:02:38 gram Exp $ + * $Id: prefs.c,v 1.29 2000/01/03 06:29:32 guy Exp $ * * Ethereal - Network traffic analyzer * By Gerald Combs <gerald@zing.org> @@ -51,7 +51,6 @@ #include "prefs.h" #include "column.h" #include "print.h" -#include "ui_util.h" /* Internal functions */ static int set_pref(gchar*, gchar*); @@ -454,8 +453,8 @@ set_pref(gchar *pref, gchar *value) { return 1; } -void -write_prefs(void) { +int +write_prefs(char **pf_path_return) { FILE *pf; struct stat s_buf; @@ -480,10 +479,9 @@ write_prefs(void) { sprintf(pf_path, "%s/%s/%s", getenv("HOME"), PF_DIR, PF_NAME); if ((pf = fopen(pf_path, "w")) == NULL) { - simple_dialog(ESD_TYPE_WARN, NULL, - "Can't open preferences file\n\"%s\".", pf_path); - return; - } + *pf_path_return = pf_path; + return errno; + } fputs("# Configuration file for Ethereal " VERSION ".\n" "#\n" @@ -551,4 +549,10 @@ write_prefs(void) { gui_ptree_expander_style_text[prefs.gui_ptree_expander_style]); fclose(pf); + + /* XXX - catch I/O errors (e.g. "ran out of disk space") and return + an error indication, or maybe write to a new preferences file and + rename that file on top of the old one only if there are not I/O + errors. */ + return 0; } @@ -1,7 +1,7 @@ /* prefs.h * Definitions for preference handling routines * - * $Id: prefs.h,v 1.13 1999/12/30 23:02:39 gram Exp $ + * $Id: prefs.h,v 1.14 2000/01/03 06:29:33 guy Exp $ * * Ethereal - Network traffic analyzer * By Gerald Combs <gerald@zing.org> @@ -54,6 +54,6 @@ typedef struct _e_prefs { extern e_prefs prefs; e_prefs* read_prefs(char **); -void write_prefs(void); +int write_prefs(char **); #endif /* prefs.h */ |