ANNOUNCEMENT: Live Wireshark University & Allegro Packets online APAC Wireshark Training Session
July 17th, 2024 | 10:00am-11:55am SGT (UTC+8) | Online

Ethereal-dev: [Ethereal-dev] GTK GUI patch to make save capture dialogs a preference setting

Note: This archive is from the project's previous web site, ethereal.com. This list is no longer active.

From: David Brower <David.Brower@xxxxxxxxxx>
Date: Thu, 10 Mar 2005 16:03:43 -0800
In my usagem I never ever save a capture file, and I'm bothered
enough by Ethereal's questioning me I've done something about it.

The following patch adds a gui preferences item called
"Save Capture dialogs", whose "Nag" value may be
either "Safe" or "Silent".     The default behaviour is
"safe".

When set to "Silent", the questioning boxes never appear,
and you can X out the window and it goes away; similarly
you can start a new capture without a "save" nag.

I hope this is of use to someone.

thanks,
-dB

-------------------------- cut here ------------------
diff -Naur ethereal-0.10.3-clean/gtk/capture_dlg.c
dbrower-nonag/gtk/capture_dlg.c
--- ethereal-0.10.3-clean/gtk/capture_dlg.c    2004-03-17
20:05:34.000000000 -0800
+++ dbrower-nonag/gtk/capture_dlg.c    2005-03-10 15:46:45.168658017 -0800
@@ -998,7 +998,7 @@
 {
   gpointer  dialog;
 
-  if((cfile.state != FILE_CLOSED) && !cfile.user_saved) {
+  if((cfile.state != FILE_CLOSED) && !cfile.user_saved &&
prefs.gui_save_capture_nag) {
     /* user didn't saved his current file, ask him */
     dialog = simple_dialog(ESD_TYPE_CONFIRMATION, ESD_BTNS_YES_NO_CANCEL,
                 PRIMARY_TEXT_START "Save capture file before starting a
new capture?" PRIMARY_TEXT_END "\n\n"
diff -Naur ethereal-0.10.3-clean/gtk/file_dlg.c dbrower-nonag/gtk/file_dlg.c
--- ethereal-0.10.3-clean/gtk/file_dlg.c    2004-02-28
10:06:40.000000000 -0800
+++ dbrower-nonag/gtk/file_dlg.c    2005-03-10 15:46:45.142659745 -0800
@@ -357,7 +357,7 @@
 file_open_cmd_cb(GtkWidget *widget, gpointer data _U_) {
   gpointer  dialog;
 
-  if((cfile.state != FILE_CLOSED) && !cfile.user_saved) {
+  if((cfile.state != FILE_CLOSED) && !cfile.user_saved &&
prefs.gui_save_capture_nag) {
     /* user didn't saved his current file, ask him */
     dialog = simple_dialog(ESD_TYPE_CONFIRMATION, ESD_BTNS_YES_NO_CANCEL,
                 PRIMARY_TEXT_START "Save capture file before opening a
new one?" PRIMARY_TEXT_END "\n\n"
@@ -483,7 +483,7 @@
 file_close_cmd_cb(GtkWidget *widget _U_, gpointer data _U_) {
   gpointer  dialog;
 
-  if((cfile.state != FILE_CLOSED) && !cfile.user_saved) {
+  if((cfile.state != FILE_CLOSED) && !cfile.user_saved &&
prefs.gui_save_capture_nag) {
     /* user didn't saved his current file, ask him */
     dialog = simple_dialog(ESD_TYPE_CONFIRMATION, ESD_BTNS_YES_NO_CANCEL,
                 PRIMARY_TEXT_START "Save capture file before closing
it?" PRIMARY_TEXT_END "\n\n"
diff -Naur ethereal-0.10.3-clean/gtk/gui_prefs.c
dbrower-nonag/gtk/gui_prefs.c
--- ethereal-0.10.3-clean/gtk/gui_prefs.c    2004-03-17
20:05:35.000000000 -0800
+++ dbrower-nonag/gtk/gui_prefs.c    2005-03-10 15:46:45.139659944 -0800
@@ -63,6 +63,7 @@
 #define ALTERN_COLORS_KEY               "altern_colors"
 #endif
 #define HEX_DUMP_HIGHLIGHT_STYLE_KEY    "hex_dump_highlight_style"
+#define SAVE_CAPTURE_NAG_KEY        "save_capture_nag"
 #define GEOMETRY_POSITION_KEY        "geometry_position"
 #define GEOMETRY_SIZE_KEY        "geometry_size"
 #define GEOMETRY_MAXIMIZED_KEY        "geometry_maximized"
@@ -115,6 +116,12 @@
     { NULL,       0 }
 };
 
+static const enum_val_t save_capture_nag_vals[] = {
+      { "Safe",     TRUE },
+      { "Silent",   FALSE },
+    { NULL,       0 }
+};
+
 static const enum_val_t toolbar_style_vals[] = {
       { "Icons only",     TB_STYLE_ICONS },
       { "Text only",      TB_STYLE_TEXT },
@@ -128,6 +135,8 @@
     { NULL,    0 }
 };
 
+
+
 /* Set to FALSE initially; set to TRUE if the user ever hits "OK" on
    the "Font..." dialog, so that we know that they (probably) changed
    the font, and therefore that the "apply" function needs to take care
@@ -155,6 +164,7 @@
     GtkWidget *main_tb, *main_vb, *hbox;
     GtkWidget *scrollbar_om, *plist_browse_om;
     GtkWidget *ptree_browse_om, *highlight_style_om;
+    GtkWidget *save_capture_nag_om;
     GtkWidget *fileopen_rb, *fileopen_dir_te, *toolbar_style_om;
     GtkWidget *recent_files_count_max_te;
     GtkWidget *save_position_cb, *save_size_cb, *save_maximized_cb;
@@ -230,6 +240,13 @@
     OBJECT_SET_DATA(main_vb, HEX_DUMP_HIGHLIGHT_STYLE_KEY,
         highlight_style_om);
 
+    /* Save Capture Dialog */
+    save_capture_nag_om = create_preference_option_menu(main_tb, pos++,
+        "Save Capture preferences:", NULL, save_capture_nag_vals,
+        prefs.gui_save_capture_nag);
+    OBJECT_SET_DATA(main_vb, SAVE_CAPTURE_NAG_KEY,
+        save_capture_nag_om);
+
     /* Toolbar prefs */
     toolbar_style_om = create_preference_option_menu(main_tb, pos++,
         "Toolbar style:", NULL, toolbar_style_vals,
@@ -425,6 +442,11 @@
     prefs.gui_hex_dump_highlight_style = fetch_enum_value(
         OBJECT_GET_DATA(w, HEX_DUMP_HIGHLIGHT_STYLE_KEY),
         highlight_style_vals);
+
+    prefs.gui_save_capture_nag = fetch_enum_value(
+        OBJECT_GET_DATA(w, SAVE_CAPTURE_NAG_KEY),
+        save_capture_nag_vals);
+
     prefs.gui_toolbar_main_style = fetch_enum_value(
         OBJECT_GET_DATA(w, GUI_TOOLBAR_STYLE_KEY),
         toolbar_style_vals);   
diff -Naur ethereal-0.10.3-clean/gtk/main.c dbrower-nonag/gtk/main.c
--- ethereal-0.10.3-clean/gtk/main.c    2004-03-25 14:21:18.000000000 -0800
+++ dbrower-nonag/gtk/main.c    2005-03-10 15:46:45.156658814 -0800
@@ -1243,7 +1243,7 @@
 {
   gpointer dialog;
 
-  if((cfile.state != FILE_CLOSED) && !cfile.user_saved) {
+  if((cfile.state != FILE_CLOSED) && !cfile.user_saved &&
prefs.gui_save_capture_nag) {
     /* user didn't saved his current file, ask him */
     dialog = simple_dialog(ESD_TYPE_CONFIRMATION, ESD_BTNS_YES_NO_CANCEL,
                 PRIMARY_TEXT_START "Save capture file before program
quit?" PRIMARY_TEXT_END "\n\n"
@@ -1364,7 +1364,7 @@
 {
   gpointer dialog;
 
-  if((cfile.state != FILE_CLOSED) && !cfile.user_saved) {
+  if((cfile.state != FILE_CLOSED) && !cfile.user_saved &&
prefs.gui_save_capture_nag) {
     /* user didn't saved his current file, ask him */
     dialog = simple_dialog(ESD_TYPE_CONFIRMATION, ESD_BTNS_YES_NO_CANCEL,
                 PRIMARY_TEXT_START "Save capture file before program
quit?" PRIMARY_TEXT_END "\n\n"
@@ -1802,7 +1802,7 @@
         g_free(cf_name_ori);
 
         /* ask the user to save it's current capture file first */
-        if((cfile.state != FILE_CLOSED) && !cfile.user_saved) {
+        if((cfile.state != FILE_CLOSED) && !cfile.user_saved &&
prefs.gui_save_capture_nag) {
             /* user didn't saved his current file, ask him */
             dialog = simple_dialog(ESD_TYPE_CONFIRMATION,
                         ESD_BTNS_YES_NO_CANCEL,
diff -Naur ethereal-0.10.3-clean/gtk/menu.c dbrower-nonag/gtk/menu.c
--- ethereal-0.10.3-clean/gtk/menu.c    2004-03-25 14:21:18.000000000 -0800
+++ dbrower-nonag/gtk/menu.c    2005-03-10 15:46:45.158658681 -0800
@@ -962,7 +962,7 @@
   gpointer  dialog;
 
 
-  if((cfile.state != FILE_CLOSED) && !cfile.user_saved) {
+  if((cfile.state != FILE_CLOSED) && !cfile.user_saved &&
prefs.gui_save_capture_nag) {
     /* user didn't saved his current file, ask him */
     dialog = simple_dialog(ESD_TYPE_CONFIRMATION, ESD_BTNS_YES_NO_CANCEL,
                 PRIMARY_TEXT_START "Save capture file before opening a
new one?" PRIMARY_TEXT_END "\n\n"
diff -Naur ethereal-0.10.3-clean/prefs.c dbrower-nonag/prefs.c
--- ethereal-0.10.3-clean/prefs.c    2004-02-28 10:06:38.000000000 -0800
+++ dbrower-nonag/prefs.c    2005-03-10 15:46:45.846612955 -0800
@@ -87,6 +87,9 @@
 static gchar    *gui_hex_dump_highlight_style_text[] =
     { "BOLD", "INVERSE", NULL };
 
+static gchar    *gui_save_capture_nag_text[] =
+    { "SAFE", "SILENT", NULL };
+
 static gchar    *gui_fileopen_style_text[] =
     { "LAST_OPENED", "SPECIFIED", NULL };
 
@@ -921,6 +924,7 @@
     prefs.gui_ptree_line_style = 0;
     prefs.gui_ptree_expander_style = 1;
     prefs.gui_hex_dump_highlight_style = 1;
+    prefs.gui_save_capture_nag = 1;
     prefs.gui_toolbar_main_style = TB_STYLE_ICONS;
 #ifdef WIN32
     prefs.gui_font_name1 = g_strdup("-*-lucida
console-medium-r-*-*-*-100-*-*-*-*-*-*");
@@ -1274,6 +1278,7 @@
 #define PRS_GUI_PTREE_LINE_STYLE         "gui.protocol_tree_line_style"
 #define PRS_GUI_PTREE_EXPANDER_STYLE     "gui.protocol_tree_expander_style"
 #define PRS_GUI_HEX_DUMP_HIGHLIGHT_STYLE "gui.hex_dump_highlight_style"
+#define PRS_GUI_SAVE_CAPTURE_NAG     "gui.save_capture_nag"
 #define PRS_GUI_FONT_NAME_1              "gui.font_name"
 #define PRS_GUI_FONT_NAME_2              "gui.gtk2.font_name"
 #define PRS_GUI_MARKED_FG                "gui.marked_frame.fg"
@@ -1524,6 +1529,9 @@
   } else if (strcmp(pref_name, PRS_GUI_HEX_DUMP_HIGHLIGHT_STYLE) == 0) {
     prefs.gui_hex_dump_highlight_style =
     find_index_from_string_array(value,
gui_hex_dump_highlight_style_text, 1);
+  } else if (strcmp(pref_name, PRS_GUI_SAVE_CAPTURE_NAG) == 0) {
+    prefs.gui_save_capture_nag =
+    find_index_from_string_array(value, gui_save_capture_nag_text, 1);
   } else if (strcmp(pref_name, PRS_GUI_TOOLBAR_MAIN_SHOW) == 0) {
     /* obsoleted by recent setting */
   } else if (strcmp(pref_name, PRS_GUI_TOOLBAR_MAIN_STYLE) == 0) {
@@ -2125,6 +2133,11 @@
   fprintf(pf, PRS_GUI_HEX_DUMP_HIGHLIGHT_STYLE ": %s\n",
          
gui_hex_dump_highlight_style_text[prefs.gui_hex_dump_highlight_style]);
 
+  fprintf(pf, "\n# Save Capture dialogs\n");
+  fprintf(pf, "# One of: SAFE, SILENT\n");
+  fprintf(pf, PRS_GUI_SAVE_CAPTURE_NAG ": %s\n",
+          gui_save_capture_nag_text[prefs.gui_save_capture_nag]);
+
   fprintf(pf, "\n# Main Toolbar style.\n");
   fprintf(pf, "# One of: ICONS, TEXT, BOTH\n");
   fprintf(pf, PRS_GUI_TOOLBAR_MAIN_STYLE ": %s\n",
@@ -2265,6 +2278,7 @@
   dest->gui_ptree_line_style = src->gui_ptree_line_style;
   dest->gui_ptree_expander_style = src->gui_ptree_expander_style;
   dest->gui_hex_dump_highlight_style = src->gui_hex_dump_highlight_style;
+  dest->gui_save_capture_nag = src->gui_save_capture_nag;
   dest->gui_toolbar_main_style = src->gui_toolbar_main_style;
   dest->gui_fileopen_dir = g_strdup(src->gui_fileopen_dir);
   dest->gui_fileopen_style = src->gui_fileopen_style;
diff -Naur ethereal-0.10.3-clean/prefs.h dbrower-nonag/prefs.h
--- ethereal-0.10.3-clean/prefs.h    2004-02-08 18:18:32.000000000 -0800
+++ dbrower-nonag/prefs.h    2005-03-10 15:46:45.846612955 -0800
@@ -81,6 +81,7 @@
   gint     gui_ptree_line_style;
   gint     gui_ptree_expander_style;
   gboolean gui_hex_dump_highlight_style;
+  gboolean gui_save_capture_nag;
   gint     gui_toolbar_main_style;
   gchar   *gui_font_name1;
   gchar   *gui_font_name2;
---------------------------------------------- cut here
--------------------------------------