Instead of using private #defines for the last argument to
[obnox/wireshark/wip.git] / gtk / recent.c
index 28da76e9ec560b0465f66ccd72d6b21dd6847972..54509e3ef4f9418edb3c79422637a0c25fda4312 100644 (file)
 
 #include "gtk/recent.h"
 #include "gtk/main.h"
-#include "gtk/main_menu.h"
+#include "gtk/menus.h"
 #include "gtk/gui_utils.h"
+#ifdef NEW_PACKET_LIST
+#include "gtk/new_packet_list.h"
+#else
 #include "gtk/main_packet_list.h"
+#endif /*NEW_PACKET_LIST */
 #include "gtk/file_dlg.h"
 #include "gtk/cfilter_combo_utils.h"
 #include "gtk/u3.h"
 
+#ifdef HAVE_PCAP_REMOTE
+#include "gtk/capture_dlg.h"
+#endif
 
 #define RECENT_KEY_MAIN_TOOLBAR_SHOW        "gui.toolbar_main_show"
 #define RECENT_KEY_FILTER_TOOLBAR_SHOW      "gui.filter_toolbar_show"
@@ -63,7 +70,9 @@
 #define RECENT_KEY_PACKET_LIST_COLORIZE     "gui.packet_list_colorize"
 #define RECENT_GUI_TIME_FORMAT              "gui.time_format"
 #define RECENT_GUI_TIME_PRECISION           "gui.time_precision"
+#define RECENT_GUI_SECONDS_FORMAT           "gui.seconds_format"
 #define RECENT_GUI_ZOOM_LEVEL               "gui.zoom_level"
+#define RECENT_GUI_BYTES_VIEW               "gui.bytes_view"
 #define RECENT_GUI_GEOMETRY_MAIN_X          "gui.geometry_main_x"
 #define RECENT_GUI_GEOMETRY_MAIN_Y          "gui.geometry_main_y"
 #define RECENT_GUI_GEOMETRY_MAIN_WIDTH      "gui.geometry_main_width"
 #define RECENT_GUI_GEOMETRY_STATUS_PANE_LEFT  "gui.geometry_status_pane"
 #define RECENT_GUI_GEOMETRY_STATUS_PANE_RIGHT "gui.geometry_status_pane_right"
 #define RECENT_GUI_GEOMETRY_WLAN_STATS_PANE "gui.geometry_status_wlan_stats_pane"
+#define RECENT_LAST_USED_PROFILE            "gui.last_used_profile"
 #define RECENT_GUI_FILEOPEN_REMEMBERED_DIR  "gui.fileopen_remembered_dir"
 #define RECENT_GUI_GEOMETRY                 "gui.geom."
 #define RECENT_KEY_PRIVS_WARN_IF_ELEVATED   "privs.warn_if_elevated"
 #define RECENT_KEY_PRIVS_WARN_IF_NO_NPF     "privs.warn_if_no_npf"
-#define RECENT_KEY_HAS_RECENT_COMMON        "recent.has_recent_common"
 
 #define RECENT_FILE_NAME "recent"
 #define RECENT_COMMON_FILE_NAME "recent_common"
@@ -91,6 +100,9 @@ static const char *ts_type_text[] =
 static const char *ts_precision_text[] =
        { "AUTO", "SEC", "DSEC", "CSEC", "MSEC", "USEC", "NSEC", NULL };
 
+static const char *ts_seconds_text[] =
+  { "SECONDS", "HOUR_MIN_SEC", NULL };
+
 /* Takes an string and a pointer to an array of strings, and a default int value.
  * The array must be terminated by a NULL string. If the string is found in the array
  * of strings, the index of that string in the array is returned. Otherwise, the
@@ -117,9 +129,7 @@ free_col_width_info(recent_settings_t *rs)
 
   while (rs->col_width_list != NULL) {
     cfmt = rs->col_width_list->data;
-    if (cfmt->cfield) {
-      g_free(cfmt->cfield);
-    }
+    g_free(cfmt->cfield);
     g_free(cfmt);
     rs->col_width_list = g_list_remove_link(rs->col_width_list, rs->col_width_list);
   }
@@ -127,7 +137,7 @@ free_col_width_info(recent_settings_t *rs)
   rs->col_width_list = NULL;
 }
 
-/* Attempt to Write out "recent" to the user's recent file.
+/* Attempt to Write out "recent common" to the user's recent common file.
    If we got an error report it with a dialog box and return FALSE,
    otherwise return TRUE. */
 gboolean
@@ -184,6 +194,15 @@ write_recent(void)
     "\n", rf);
 
   dfilter_recent_combo_write_all(rf);
+
+#ifdef HAVE_PCAP_REMOTE
+  fputs("\n"
+    "######## Recent remote hosts, cannot be altered through command line ########\n"
+    "\n", rf);
+       
+  capture_remote_combo_recent_write_all(rf);
+#endif
+
   fprintf(rf, "\n# Main window geometry.\n");
   fprintf(rf, "# Decimal numbers.\n");
   fprintf(rf, RECENT_GUI_GEOMETRY_MAIN_X ": %d\n", recent.gui_geometry_main_x);
@@ -211,6 +230,9 @@ write_recent(void)
                  recent.gui_geometry_status_pane_right);
   }
 
+  fprintf(rf, "\n# Last used Configuration Profile.\n");
+  fprintf(rf, RECENT_LAST_USED_PROFILE ": %s\n", get_profile_name());
+
   fprintf(rf, "\n# WLAN statistics upper pane size.\n");
   fprintf(rf, "# Decimal number.\n");
   fprintf(rf, RECENT_GUI_GEOMETRY_WLAN_STATS_PANE ": %d\n",
@@ -238,7 +260,7 @@ write_recent(void)
 }
 
 
-/* Attempt to Write out profile "recent" to the user's recent file.
+/* Attempt to Write out profile "recent" to the user's profile recent file.
    If we got an error report it with a dialog box and return FALSE,
    otherwise return TRUE. */
 gboolean
@@ -340,11 +362,21 @@ write_profile_recent(void)
   fprintf(rf, RECENT_GUI_TIME_PRECISION ": %s\n",
           ts_precision_text[recent.gui_time_precision]);
 
+  fprintf(rf, "\n# Seconds display format.\n");
+  fprintf(rf, "# One of: SECONDS, HOUR_MIN_SEC\n");
+  fprintf(rf, RECENT_GUI_SECONDS_FORMAT ": %s\n",
+          ts_seconds_text[recent.gui_seconds_format]);
+
   fprintf(rf, "\n# Zoom level.\n");
   fprintf(rf, "# A decimal number.\n");
   fprintf(rf, RECENT_GUI_ZOOM_LEVEL ": %d\n",
                  recent.gui_zoom_level);
 
+  fprintf(rf, "\n# Bytes view.\n");
+  fprintf(rf, "# A decimal number.\n");
+  fprintf(rf, RECENT_GUI_BYTES_VIEW ": %d\n",
+                 recent.gui_bytes_view);
+
   fprintf(rf, "\n# Main window upper (or leftmost) pane size.\n");
   fprintf(rf, "# Decimal number.\n");
   if (recent.gui_geometry_main_upper_pane != 0) {
@@ -358,13 +390,13 @@ write_profile_recent(void)
                  recent.gui_geometry_main_lower_pane);
   }
 
-  fprintf(rf, "\n# This configuration has a recent_common file.\n");
-  fprintf(rf, "# TRUE or FALSE (case-insensitive).\n");
-  fprintf(rf, RECENT_KEY_HAS_RECENT_COMMON ": TRUE\n");
-
   fprintf(rf, "\n# Packet list column pixel widths.\n");
   fprintf(rf, "# Each pair of strings consists of a column format and its pixel width.\n");
+#ifdef NEW_PACKET_LIST
+  new_packet_list_recent_write_all(rf);
+#else
   packet_list_recent_write_all(rf);
+#endif
 
   if (get_last_open_dir() != NULL) {
     fprintf(rf, "\n# Last directory navigated to in File Open dialog.\n");
@@ -461,6 +493,10 @@ read_set_recent_common_pair_static(gchar *key, gchar *value, void *private_data
       return PREFS_SET_SYNTAX_ERR;     /* number must be positive */
     recent.gui_geometry_status_pane_left = num;
     recent.has_gui_geometry_status_pane = TRUE;
+  } else if (strcmp(key, RECENT_LAST_USED_PROFILE) == 0) {
+    if ((strcmp(value, DEFAULT_PROFILE) != 0) && profile_exists (value)) {
+      set_profile_name (value);
+    }
   } else if (strcmp(key, RECENT_GUI_GEOMETRY_WLAN_STATS_PANE) == 0) {
     num = strtol(value, &p, 0);
     if (p == value || *p != '\0')
@@ -505,7 +541,7 @@ read_set_recent_pair_static(gchar *key, gchar *value, void *private_data _U_)
   GList *col_l, *col_l_elt;
   col_width_data *cfmt;
   const gchar *cust_format = col_format_to_string(COL_CUSTOM);
-  int cust_format_len = strlen(cust_format);
+  int cust_format_len = (int) strlen(cust_format);
 
   if (strcmp(key, RECENT_KEY_MAIN_TOOLBAR_SHOW) == 0) {
     if (g_ascii_strcasecmp(value, "true") == 0) {
@@ -576,11 +612,19 @@ read_set_recent_pair_static(gchar *key, gchar *value, void *private_data _U_)
   } else if (strcmp(key, RECENT_GUI_TIME_PRECISION) == 0) {
     recent.gui_time_precision =
        find_index_from_string_array(value, ts_precision_text, TS_PREC_AUTO);
+  } else if (strcmp(key, RECENT_GUI_SECONDS_FORMAT) == 0) {
+    recent.gui_seconds_format =
+       find_index_from_string_array(value, ts_seconds_text, TS_SECONDS_DEFAULT);
   } else if (strcmp(key, RECENT_GUI_ZOOM_LEVEL) == 0) {
     num = strtol(value, &p, 0);
     if (p == value || *p != '\0')
       return PREFS_SET_SYNTAX_ERR;     /* number was bad */
     recent.gui_zoom_level = num;
+  } else if (strcmp(key, RECENT_GUI_BYTES_VIEW) == 0) {
+    num = strtol(value, &p, 0);
+    if (p == value || *p != '\0')
+      return PREFS_SET_SYNTAX_ERR;     /* number was bad */
+    recent.gui_bytes_view = num;
   } else if (strcmp(key, RECENT_GUI_GEOMETRY_MAIN_MAXIMIZED) == 0) {
     if (g_ascii_strcasecmp(value, "true") == 0) {
         recent.gui_geometry_main_maximized = TRUE;
@@ -605,14 +649,8 @@ read_set_recent_pair_static(gchar *key, gchar *value, void *private_data _U_)
       return PREFS_SET_SYNTAX_ERR;     /* number must be positive */
     recent.gui_geometry_main_lower_pane = num;
     recent.has_gui_geometry_main_lower_pane = TRUE;
-  } else if (strcmp(key, RECENT_KEY_HAS_RECENT_COMMON) == 0) {
-    if (g_ascii_strcasecmp(value, "true") == 0) {
-        recent.has_recent_common = TRUE;
-    }
-    else {
-        recent.has_recent_common = FALSE;
-    }
-  } else if (strcmp(key, RECENT_KEY_COL_WIDTH) == 0) {
+  }
+  else if (strcmp(key, RECENT_KEY_COL_WIDTH) == 0) {
     col_l = prefs_get_string_list(value);
     if (col_l == NULL)
       return PREFS_SET_SYNTAX_ERR;
@@ -660,13 +698,25 @@ read_set_recent_pair_static(gchar *key, gchar *value, void *private_data _U_)
        cfmt->cfield = g_strdup(&fmt[cust_format_len+1]);  /* add 1 for ':' */
       }
       g_free (fmt);
-      if (cfmt->cfmt == -1)
+      if (cfmt->cfmt == -1) {
+        g_free(cfmt->cfield);
+       g_free(cfmt);
        return PREFS_SET_SYNTAX_ERR;   /* string was bad */
+      }
 
       col_l_elt      = col_l_elt->next;
       cfmt->width    = strtol(col_l_elt->data, &p, 0);
-      if (p == col_l_elt->data || *p != '\0')
+      if (p == col_l_elt->data || (*p != '\0' && *p != ':')) {
+       g_free(cfmt->cfield);
+       g_free(cfmt);
        return PREFS_SET_SYNTAX_ERR;    /* number was bad */
+      }
+
+      if (*p == ':') {
+        cfmt->xalign = *(++p);
+      } else {
+        cfmt->xalign = COLUMN_XALIGN_DEFAULT;
+      }
 
       col_l_elt      = col_l_elt->next;
       recent.col_width_list = g_list_append(recent.col_width_list, cfmt);
@@ -691,6 +741,10 @@ read_set_recent_pair_dynamic(gchar *key, gchar *value, void *private_data _U_)
        dfilter_combo_add_recent(value);
   } else if (strcmp(key, RECENT_KEY_CAPTURE_FILTER) == 0) {
        cfilter_combo_add_recent(value);
+#ifdef HAVE_PCAP_REMOTE
+  } else if (strcmp(key, RECENT_KEY_REMOTE_HOST) == 0) {
+       capture_remote_combo_add_recent(value);
+#endif
   }
 
   return PREFS_SET_OK;
@@ -739,7 +793,7 @@ recent_set_arg(char *prefarg)
 }
 
 
-/* opens the user's recent file and read the first part */
+/* opens the user's recent common file and read the first part */
 void
 recent_read_static(char **rf_path_return, int *rf_errno_return)
 {
@@ -759,14 +813,13 @@ recent_read_static(char **rf_path_return, int *rf_errno_return)
 
   recent.privs_warn_if_elevated = TRUE;
   recent.privs_warn_if_no_npf = TRUE;
-  recent.has_recent_common = FALSE;
 
   recent.col_width_list = NULL;
 
-  /* Construct the pathname of the user's recent file. */
+  /* Construct the pathname of the user's recent common file. */
   rf_path = get_persconffile_path(RECENT_COMMON_FILE_NAME, FALSE, FALSE);
 
-  /* Read the user's recent file, if it exists. */
+  /* Read the user's recent common file, if it exists. */
   *rf_path_return = NULL;
   if ((rf = ws_fopen(rf_path, "r")) != NULL) {
     /* We succeeded in opening it; read it. */
@@ -792,7 +845,7 @@ recent_read_static(char **rf_path_return, int *rf_errno_return)
 void
 recent_read_profile_static(char **rf_path_return, int *rf_errno_return)
 {
-  char       *rf_path;
+  char       *rf_path, *rf_common_path;
   FILE       *rf;
 
   /* set defaults */
@@ -807,7 +860,9 @@ recent_read_profile_static(char **rf_path_return, int *rf_errno_return)
   recent.packet_list_colorize   = TRUE;
   recent.gui_time_format        = TS_RELATIVE;
   recent.gui_time_precision     = TS_PREC_AUTO;
+  recent.gui_seconds_format     = TS_SECONDS_DEFAULT;
   recent.gui_zoom_level         = 0;
+  recent.gui_bytes_view         = 0;
 
   /* pane size of zero will autodetect */
   recent.gui_geometry_main_upper_pane   = 0;
@@ -821,7 +876,7 @@ recent_read_profile_static(char **rf_path_return, int *rf_errno_return)
     free_col_width_info(&recent);
   }
 
-  /* Construct the pathname of the user's recent file. */
+  /* Construct the pathname of the user's profile recent file. */
   rf_path = get_persconffile_path(RECENT_FILE_NAME, TRUE, FALSE);
 
   /* Read the user's recent file, if it exists. */
@@ -830,12 +885,23 @@ recent_read_profile_static(char **rf_path_return, int *rf_errno_return)
     /* We succeeded in opening it; read it. */
     read_prefs_file(rf_path, rf, read_set_recent_pair_static, NULL);
     fclose(rf);
-    if (!recent.has_recent_common) {
+
+    /* XXX: The following code doesn't actually do anything since
+     *  the "recent common file" always exists. Presumably the 
+     *  "if (!file_exists())" should actually be "if (file_exists())".
+     *  However, I've left the code as is because this 
+     *  behaviour has existed for quite some time and I don't
+     *  know what's supposed to happen at this point.
+     *  ToDo: Determine if the "recent common file" should be read at this point
+     */
+    rf_common_path = get_persconffile_path(RECENT_COMMON_FILE_NAME, FALSE, FALSE);
+    if (!file_exists(rf_common_path)) {
       /* Read older common settings from recent file */
       rf = ws_fopen(rf_path, "r");
       read_prefs_file(rf_path, rf, read_set_recent_common_pair_static, NULL);
       fclose(rf);
     }
+    g_free(rf_common_path);
     g_free(rf_path);
     rf_path = NULL;
   } else {
@@ -857,10 +923,11 @@ recent_read_dynamic(char **rf_path_return, int *rf_errno_return)
   FILE       *rf;
 
 
-  /* Construct the pathname of the user's recent file. */
-  if (recent.has_recent_common) {
-    rf_path = get_persconffile_path(RECENT_COMMON_FILE_NAME, FALSE, FALSE);
-  } else {
+  /* Construct the pathname of the user's recent common file. */
+  rf_path = get_persconffile_path(RECENT_COMMON_FILE_NAME, FALSE, FALSE);
+  if (!file_exists (rf_path)) {
+    /* Recent common file does not exist, read from default recent */
+    g_free (rf_path);
     rf_path = get_persconffile_path(RECENT_FILE_NAME, FALSE, FALSE);
   }
 
@@ -948,6 +1015,76 @@ recent_set_column_width(gint col, gint width)
       col_w->cfield = NULL;
     }
     col_w->width = width;
+    col_w->xalign = COLUMN_XALIGN_DEFAULT;
     recent.col_width_list = g_list_append(recent.col_width_list, col_w);
   }
 }
+
+gchar
+recent_get_column_xalign(gint col)
+{
+  GList *col_l;
+  col_width_data *col_w;
+  gint cfmt;
+  const gchar *cfield = NULL;
+
+  cfmt = get_column_format(col);
+  if (cfmt == COL_CUSTOM) {
+    cfield = get_column_custom_field(col);
+  }
+
+  col_l = g_list_first(recent.col_width_list);
+  while (col_l) {
+    col_w = (col_width_data *) col_l->data;
+    if (col_w->cfmt == cfmt) {
+      if (cfmt != COL_CUSTOM || strcmp (cfield, col_w->cfield) == 0) {
+        return col_w->xalign;
+      }
+    }
+    col_l = col_l->next;
+  }
+
+  return 0;
+}
+
+void
+recent_set_column_xalign(gint col, gchar xalign)
+{
+  GList *col_l;
+  col_width_data *col_w;
+  gint cfmt;
+  const gchar *cfield = NULL;
+  gboolean found = FALSE;
+
+  cfmt = get_column_format(col);
+  if (cfmt == COL_CUSTOM) {
+    cfield = get_column_custom_field(col);
+  }
+
+  col_l = g_list_first(recent.col_width_list);
+  while (col_l) {
+    col_w = (col_width_data *) col_l->data;
+    if (col_w->cfmt == cfmt) {
+      if (cfmt != COL_CUSTOM || strcmp (cfield, col_w->cfield) == 0) {
+        col_w->xalign = xalign;
+        found = TRUE;
+        break;
+      }
+    }
+    col_l = col_l->next;
+  }
+
+  if (!found) {
+    col_w = (col_width_data *) g_malloc(sizeof(col_width_data));
+    col_w->cfmt = cfmt;
+    if (cfield) {
+      col_w->cfield = g_strdup(cfield);
+    } else {
+      col_w->cfield = NULL;
+    }
+    col_w->width = 40;
+    col_w->xalign = xalign;
+    recent.col_width_list = g_list_append(recent.col_width_list, col_w);
+  }
+}
+