Win32 only: Preference setting to open a console window, one of:
authorUlf Lamping <ulf.lamping@web.de>
Thu, 13 May 2004 15:28:02 +0000 (15:28 -0000)
committerUlf Lamping <ulf.lamping@web.de>
Thu, 13 May 2004 15:28:02 +0000 (15:28 -0000)
never (default), automatic (like before), always

svn path=/trunk/; revision=10870

gtk/gui_prefs.c
gtk/main.c
gtk/main.h
prefs.c
prefs.h

index aa6d8eed3d60a1b3bb0eece50e76f0a5ef34915f..e3d8900ba9907b2942263081d027bfc13f95c79c 100644 (file)
@@ -1,7 +1,7 @@
 /* gui_prefs.c
  * Dialog box for GUI preferences
  *
- * $Id: gui_prefs.c,v 1.68 2004/04/29 16:35:15 ulfl Exp $
+ * $Id: gui_prefs.c,v 1.69 2004/05/13 15:28:02 ulfl Exp $
  *
  * Ethereal - Network traffic analyzer
  * By Gerald Combs <gerald@ethereal.com>
@@ -68,6 +68,7 @@ static gint recent_files_count_changed_cb(GtkWidget *recent_files_entry _U_,
 #define GEOMETRY_SIZE_KEY              "geometry_size"
 #define GEOMETRY_MAXIMIZED_KEY         "geometry_maximized"
 
+#define GUI_CONSOLE_OPEN_KEY "console_open"
 #define GUI_FILEOPEN_KEY       "fileopen_behavior"
 #define GUI_RECENT_FILES_COUNT_KEY "recent_files_count"
 #define GUI_FILEOPEN_DIR_KEY   "fileopen_directory"
@@ -129,6 +130,15 @@ static const enum_val_t toolbar_style_vals[] = {
        { NULL,             0 }
 };
 
+#ifdef _WIN32
+static const enum_val_t gui_console_open_vals[] = {
+       { "Never",                      console_open_never },
+       { "Automatic (advanced user)",  console_open_auto },
+       { "Always (debugging)",         console_open_always },
+       { NULL,                         0 }
+};
+#endif
+
 static const enum_val_t gui_fileopen_vals[] = {
        { "Remember last directory", FO_STYLE_LAST_OPENED },
        { "Always start in:", FO_STYLE_SPECIFIED },
@@ -162,6 +172,9 @@ gui_prefs_show(void)
        GtkWidget *main_tb, *main_vb, *hbox;
        GtkWidget *scrollbar_om, *plist_browse_om;
        GtkWidget *ptree_browse_om, *highlight_style_om;
+#ifdef _WIN32
+       GtkWidget *console_open_om;
+#endif
        GtkWidget *fileopen_rb, *fileopen_dir_te, *toolbar_style_om;
     GtkWidget *filter_toolbar_placement_om;
        GtkWidget *recent_files_count_max_te;
@@ -264,6 +277,14 @@ gui_prefs_show(void)
            "Save maximized state:", NULL, prefs.gui_geometry_save_maximized);
        OBJECT_SET_DATA(main_vb, GEOMETRY_MAXIMIZED_KEY, save_maximized_cb);
 
+#ifdef _WIN32
+       /* How the console window should be opened */
+    console_open_om = create_preference_option_menu(main_tb, pos++,
+       "Open a console window", NULL,
+       gui_console_open_vals, prefs.gui_console_open);
+       OBJECT_SET_DATA(main_vb, GUI_CONSOLE_OPEN_KEY, console_open_om);
+#endif
+
        /* Allow user to select where they want the File Open dialog to open to
         * by default */
        fileopen_rb = create_preference_radio_buttons(main_tb, pos++,
@@ -451,6 +472,10 @@ gui_prefs_fetch(GtkWidget *w)
            gtk_toggle_button_get_active(OBJECT_GET_DATA(w, GEOMETRY_SIZE_KEY));
        prefs.gui_geometry_save_maximized =
            gtk_toggle_button_get_active(OBJECT_GET_DATA(w, GEOMETRY_MAXIMIZED_KEY));
+#ifdef _WIN32
+       prefs.gui_console_open = fetch_enum_value(
+           OBJECT_GET_DATA(w, GUI_CONSOLE_OPEN_KEY), gui_console_open_vals);
+#endif
        prefs.gui_fileopen_style = fetch_preference_radio_buttons_val(
            OBJECT_GET_DATA(w, GUI_FILEOPEN_KEY), gui_fileopen_vals);
            
@@ -481,6 +506,12 @@ void
 gui_prefs_apply(GtkWidget *w _U_)
 {
 
+#ifdef _WIN32
+    if (prefs.gui_console_open == console_open_always) {
+        create_console();
+    }
+#endif
+
        if (font_changed) {
                /* This redraws the hex dump windows. */
                switch (font_apply()) {
index a5682666cc6e286d1671f870796a291b9a392c87..df1832329ba875a6c2708b630a605a524b42afad 100644 (file)
@@ -1,6 +1,6 @@
 /* main.c
  *
- * $Id: main.c,v 1.433 2004/05/07 12:15:24 ulfl Exp $
+ * $Id: main.c,v 1.434 2004/05/13 15:28:02 ulfl Exp $
  *
  * Ethereal - Network traffic analyzer
  * By Gerald Combs <gerald@ethereal.com>
@@ -157,9 +157,8 @@ GtkStyle *item_style;
 #endif
 
 #ifdef WIN32
-static gboolean has_no_console;        /* TRUE if app has no console */
-static gboolean console_was_created; /* TRUE if console was created */
-static void create_console(void);
+static gboolean has_console;   /* TRUE if app has console */
+/*static void create_console(void);*/
 static void destroy_console(void);
 static void console_log_handler(const char *log_domain,
     GLogLevelFlags log_level, const char *message, gpointer user_data);
@@ -2064,6 +2063,12 @@ main(int argc, char *argv[])
     pf_path = NULL;
   }
 
+#ifdef _WIN32
+  if (prefs->gui_console_open == console_open_always) {
+    create_console();
+  }
+#endif
+
 #ifdef HAVE_LIBPCAP
   capture_opts.has_snaplen = FALSE;
   capture_opts.snaplen = MIN_PACKET_SIZE;
@@ -2374,8 +2379,7 @@ main(int argc, char *argv[])
       case 'v':        /* Show version and exit */
         show_version();
 #ifdef WIN32
-        if (console_was_created)
-          destroy_console();
+        destroy_console();
 #endif
         exit(0);
         break;
@@ -2946,8 +2950,7 @@ main(int argc, char *argv[])
   /* For some unknown reason, the "atexit()" call in "create_console()"
      doesn't arrange that "destroy_console()" be called when we exit,
      so we call it here if a console was created. */
-  if (console_was_created)
-    destroy_console();
+  destroy_console();
 #endif
 
   gtk_exit(0);
@@ -2976,7 +2979,7 @@ WinMain (struct HINSTANCE__ *hInstance,
         char               *lpszCmdLine,
         int                 nCmdShow)
 {
-  has_no_console = TRUE;
+  has_console = FALSE;
   return main (__argc, __argv);
 }
 
@@ -2984,10 +2987,10 @@ WinMain (struct HINSTANCE__ *hInstance,
  * If this application has no console window to which its standard output
  * would go, create one.
  */
-static void
+void
 create_console(void)
 {
-  if (has_no_console) {
+  if (!has_console && prefs.gui_console_open != console_open_never) {
     /* We have no console to which to print the version string, so
        create one and make it the standard input, output, and error. */
     if (!AllocConsole())
@@ -2997,8 +3000,7 @@ create_console(void)
     freopen("CONOUT$", "w", stderr);
 
     /* Well, we have a console now. */
-    has_no_console = FALSE;
-    console_was_created = TRUE;
+    has_console = TRUE;
 
     /* Now register "destroy_console()" as a routine to be called just
        before the application exits, so that we can destroy the console
@@ -3012,9 +3014,11 @@ create_console(void)
 static void
 destroy_console(void)
 {
-  printf("\n\nPress any key to exit\n");
-  _getch();
-  FreeConsole();
+  if (has_console) {
+    printf("\n\nPress any key to exit\n");
+    _getch();
+    FreeConsole();
+  }
 }
 
 /* This routine should not be necessary, at least as I read the GLib
@@ -3032,7 +3036,7 @@ console_log_handler(const char *log_domain, GLogLevelFlags log_level,
                    const char *message, gpointer user_data)
 {
   create_console();
-  if (console_was_created) {
+  if (has_console) {
     /* For some unknown reason, the above doesn't appear to actually cause
        anything to be sent to the standard output, so we'll just splat the
        message out directly, just to make sure it gets out. */
index 75fc0a60cf76b80c62cd1c0829128c55e15b0ab1..11e8f0d49f69acf735b6c9cc2707deb37eb480c9 100644 (file)
@@ -1,7 +1,7 @@
 /* main.h
  * Global defines, etc.
  *
- * $Id: main.h,v 1.46 2004/05/04 20:49:33 guy Exp $
+ * $Id: main.h,v 1.47 2004/05/13 15:28:02 ulfl Exp $
  *
  * Ethereal - Network traffic analyzer
  * By Gerald Combs <gerald@ethereal.com>
@@ -118,6 +118,9 @@ extern gboolean main_filter_packets(capture_file *cf, const gchar *dftext,
 extern void dnd_open_file_cmd(gpointer cf_name);
 extern void packets_bar_update(void);
 
+#ifdef _WIN32
+extern void create_console(void);
+#endif
 
 typedef enum {
        FA_SUCCESS,
diff --git a/prefs.c b/prefs.c
index 55136474e41251b83efc87b5283d93403bff4362..cc2d00c632c1572387358bbf00db98746b40e5fa 100644 (file)
--- a/prefs.c
+++ b/prefs.c
@@ -1,7 +1,7 @@
 /* prefs.c
  * Routines for handling preferences
  *
- * $Id: prefs.c,v 1.131 2004/05/05 07:31:05 guy Exp $
+ * $Id: prefs.c,v 1.132 2004/05/13 15:28:01 ulfl Exp $
  *
  * Ethereal - Network traffic analyzer
  * By Gerald Combs <gerald@ethereal.com>
@@ -87,6 +87,9 @@ static gchar  *gui_ptree_expander_style_text[] =
 static gchar   *gui_hex_dump_highlight_style_text[] =
        { "BOLD", "INVERSE", NULL };
 
+static gchar   *gui_console_open_text[] =
+       { "NEVER", "AUTOMATIC", "ALWAYS", NULL };
+
 static gchar   *gui_fileopen_style_text[] =
        { "LAST_OPENED", "SPECIFIED", NULL };
 
@@ -990,6 +993,7 @@ read_prefs(int *gpf_errno_return, int *gpf_read_errno_return,
     prefs.gui_geometry_save_position =         0;
     prefs.gui_geometry_save_size     =         1;
     prefs.gui_geometry_save_maximized=         1;
+    prefs.gui_console_open           = console_open_never;
     prefs.gui_fileopen_style         = FO_STYLE_LAST_OPENED;
     prefs.gui_recent_files_count_max = 10;
     prefs.gui_fileopen_dir           = g_strdup("");
@@ -1287,6 +1291,7 @@ prefs_set_pref(char *prefarg)
 #define PRS_GUI_FONT_NAME_2              "gui.gtk2.font_name"
 #define PRS_GUI_MARKED_FG                "gui.marked_frame.fg"
 #define PRS_GUI_MARKED_BG                "gui.marked_frame.bg"
+#define PRS_GUI_CONSOLE_OPEN             "gui.console_open"
 #define PRS_GUI_FILEOPEN_STYLE           "gui.fileopen.style"
 #define PRS_GUI_RECENT_COUNT_MAX         "gui.recent_files_count.max"
 #define PRS_GUI_FILEOPEN_DIR             "gui.fileopen.dir"
@@ -1596,6 +1601,10 @@ set_pref(gchar *pref_name, gchar *value)
   } else if (strcmp(pref_name, PRS_GUI_GEOMETRY_MAIN_Y) == 0) {         /* deprecated */
   } else if (strcmp(pref_name, PRS_GUI_GEOMETRY_MAIN_WIDTH) == 0) {     /* deprecated */
   } else if (strcmp(pref_name, PRS_GUI_GEOMETRY_MAIN_HEIGHT) == 0) {    /* deprecated */
+  } else if (strcmp(pref_name, PRS_GUI_CONSOLE_OPEN) == 0) {
+    prefs.gui_console_open =
+       find_index_from_string_array(value, gui_console_open_text,
+                                    console_open_never);
   } else if (strcmp(pref_name, PRS_GUI_FILEOPEN_STYLE) == 0) {
     prefs.gui_fileopen_style =
        find_index_from_string_array(value, gui_fileopen_style_text,
@@ -2200,6 +2209,11 @@ write_prefs(char **pf_path_return)
   fprintf(pf, PRS_GUI_GEOMETRY_SAVE_MAXIMIZED ": %s\n",
                  prefs.gui_geometry_save_maximized == TRUE ? "TRUE" : "FALSE");
                   
+  fprintf(pf, "\n# Open a console window (WIN32 only)?\n");
+  fprintf(pf, "# One of: NEVER, AUTOMATIC, ALWAYS\n");
+  fprintf(pf, PRS_GUI_CONSOLE_OPEN ": %s\n",
+                 gui_console_open_text[prefs.gui_console_open]);
+
   fprintf(pf, "\n# Where to start the File Open dialog box.\n");
   fprintf(pf, "# One of: LAST_OPENED, SPECIFIED\n");
   fprintf(pf, PRS_GUI_FILEOPEN_STYLE ": %s\n",
@@ -2319,6 +2333,7 @@ copy_prefs(e_prefs *dest, e_prefs *src)
   dest->gui_hex_dump_highlight_style = src->gui_hex_dump_highlight_style;
   dest->gui_toolbar_main_style = src->gui_toolbar_main_style;
   dest->gui_fileopen_dir = g_strdup(src->gui_fileopen_dir);
+  dest->gui_console_open = src->gui_console_open;
   dest->gui_fileopen_style = src->gui_fileopen_style;
   dest->gui_layout_type = src->gui_layout_type;
   dest->gui_layout_content_1 = src->gui_layout_content_1;
diff --git a/prefs.h b/prefs.h
index 7e788f013323e8ccc1be0e97e6e88c8fff851a6b..ffc264e3f6f0fe78b279662197f63e9f41e0f04d 100644 (file)
--- a/prefs.h
+++ b/prefs.h
@@ -1,7 +1,7 @@
 /* prefs.h
  * Definitions for preference handling routines
  *
- * $Id: prefs.h,v 1.61 2004/05/09 10:03:37 guy Exp $
+ * $Id: prefs.h,v 1.62 2004/05/13 15:28:01 ulfl Exp $
  *
  * Ethereal - Network traffic analyzer
  * By Gerald Combs <gerald@ethereal.com>
@@ -90,6 +90,15 @@ typedef enum {
     layout_pane_content_pbytes
 } layout_pane_content_e;
 
+/*
+ * open console behaviour (win32 only)
+ */
+typedef enum {
+    console_open_never,
+    console_open_auto,
+    console_open_always,
+} console_open_e;
+
 
 typedef struct _e_prefs {
   gint     pr_format;
@@ -115,6 +124,7 @@ typedef struct _e_prefs {
   gboolean gui_geometry_save_position;
   gboolean gui_geometry_save_size;
   gboolean gui_geometry_save_maximized;
+  console_open_e gui_console_open;
   guint    gui_fileopen_style;
   guint    gui_recent_files_count_max;
   gchar           *gui_fileopen_dir;