From Kovarththanan Rajaratnam (Bug 2660):

Make display filter max recent entries a preference

(From me: fixed an off by one bug in saving to the recent file)


svn path=/trunk/; revision=25960
This commit is contained in:
Sake Blok 2008-08-08 19:41:35 +00:00
parent 3cba46070c
commit 643d1baa53
4 changed files with 57 additions and 6 deletions

View File

@ -1161,6 +1161,7 @@ init_prefs(void) {
prefs.gui_geometry_save_column_width = FALSE;
prefs.gui_console_open = console_open_never;
prefs.gui_fileopen_style = FO_STYLE_LAST_OPENED;
prefs.gui_recent_df_entries_max = 10;
prefs.gui_recent_files_count_max = 10;
prefs.gui_fileopen_dir = g_strdup(get_persdatafile_dir());
prefs.gui_fileopen_preview = 3;
@ -1627,6 +1628,7 @@ prefs_is_capture_device_hidden(const char *name)
#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_RECENT_DF_ENTRIES_MAX "gui.recent_display_filter_entries.max"
#define PRS_GUI_FILEOPEN_DIR "gui.fileopen.dir"
#define PRS_GUI_FILEOPEN_REMEMBERED_DIR "gui.fileopen.remembered_dir"
#define PRS_GUI_FILEOPEN_PREVIEW "gui.fileopen.preview"
@ -1985,6 +1987,12 @@ set_pref(gchar *pref_name, gchar *value, void *private_data _U_)
/* We really should put up a dialog box here ... */
prefs.gui_recent_files_count_max = 10;
}
} else if (strcmp(pref_name, PRS_GUI_RECENT_DF_ENTRIES_MAX) == 0) {
prefs.gui_recent_df_entries_max = strtoul(value, NULL, 10);
if (prefs.gui_recent_df_entries_max == 0) {
/* We really should put up a dialog box here ... */
prefs.gui_recent_df_entries_max = 10;
}
} else if (strcmp(pref_name, PRS_GUI_FILEOPEN_STYLE) == 0) {
prefs.gui_fileopen_style =
find_index_from_string_array(value, gui_fileopen_style_text,
@ -2709,6 +2717,11 @@ write_prefs(char **pf_path_return)
fprintf(pf, PRS_GUI_CONSOLE_OPEN ": %s\n",
gui_console_open_text[prefs.gui_console_open]);
fprintf(pf, "\n# The max. number of entries in the display filter list.\n");
fprintf(pf, "# A decimal number.\n");
fprintf(pf, PRS_GUI_RECENT_DF_ENTRIES_MAX ": %d\n",
prefs.gui_recent_df_entries_max);
fprintf(pf, "\n# The max. number of items in the open recent files list.\n");
fprintf(pf, "# A decimal number.\n");
fprintf(pf, PRS_GUI_RECENT_COUNT_MAX ": %d\n",

View File

@ -125,6 +125,7 @@ typedef struct _e_prefs {
gboolean gui_geometry_save_maximized;
gboolean gui_geometry_save_column_width;
console_open_e gui_console_open;
guint gui_recent_df_entries_max;
guint gui_recent_files_count_max;
guint gui_fileopen_style;
gchar *gui_fileopen_dir;

View File

@ -37,6 +37,8 @@
#include "filter_dlg.h"
#include "filter_autocomplete.h"
#include "epan/prefs.h"
#include "keys.h"
#include "gtkglobals.h"
#include "stock_icons.h"
@ -218,9 +220,6 @@ GtkWidget *filter_toolbar_new()
return filter_tb;
}
/* XXX: use a preference for this setting! */
static guint dfilter_combo_max_recent = 10;
/* add a display filter to the combo box */
/* Note: a new filter string will replace an old identical one */
static gboolean
@ -264,7 +263,7 @@ dfilter_recent_combo_write_all(FILE *rf) {
/* write all non empty display filter strings to the recent file (until max count) */
li = g_list_first(dfilter_list);
while ( li && (max_count++ <= dfilter_combo_max_recent) ) {
while ( li && (max_count++ < prefs.gui_recent_df_entries_max) ) {
if (strlen(li->data)) {
fprintf (rf, RECENT_KEY_DISPLAY_FILTER ": %s\n", (char *)li->data);
}
@ -327,7 +326,7 @@ main_filter_packets(capture_file *cf, const gchar *dftext, gboolean force)
if (add_filter) {
/* trim list size first */
while (g_list_length(dfilter_list) >= dfilter_combo_max_recent) {
while (g_list_length(dfilter_list) >= prefs.gui_recent_df_entries_max) {
dfilter_list = g_list_remove(dfilter_list, g_list_first(dfilter_list)->data);
}

View File

@ -56,6 +56,8 @@ static gint fileopen_preview_changed_cb(GtkWidget *myentry _U_, GdkEvent *event,
static void fileopen_selected_cb(GtkWidget *mybutton_rb _U_, gpointer parent_w);
static gint recent_files_count_changed_cb(GtkWidget *recent_files_entry _U_,
GdkEvent *event _U_, gpointer parent_w);
static gint recent_df_entries_changed_cb(GtkWidget *recent_df_entry _U_,
GdkEvent *event _U_, gpointer parent_w);
#define PLIST_SEL_BROWSE_KEY "plist_sel_browse"
#define PTREE_SEL_BROWSE_KEY "ptree_sel_browse"
#define GEOMETRY_POSITION_KEY "geometry_position"
@ -67,6 +69,7 @@ static gint recent_files_count_changed_cb(GtkWidget *recent_files_entry _U_,
#define GUI_FILEOPEN_KEY "fileopen_behavior"
#define GUI_FILEOPEN_PREVIEW_KEY "fileopen_preview_timeout"
#define GUI_RECENT_FILES_COUNT_KEY "recent_files_count"
#define GUI_RECENT_DF_ENTRIES_KEY "recent_display_filter_entries"
#define GUI_FILEOPEN_DIR_KEY "fileopen_directory"
#define GUI_ASK_UNSAVED_KEY "ask_unsaved"
#define GUI_WEBBROWSER_KEY "webbrowser"
@ -141,6 +144,9 @@ static GtkWidget *font_browse_w;
/* Used to contain the string from the Recent Files Count Max pref item */
static char recent_files_count_max_str[128] = "";
/* Used to contain the string from the Recent Display Filter Max Entries pref item */
static char recent_df_entries_max_str[128] = "";
/* Used to contain the string from the Open File preview timeout pref item */
static char open_file_preview_str[128] = "";
@ -156,7 +162,7 @@ gui_prefs_show(void)
GtkWidget *console_open_om;
#endif
GtkWidget *fileopen_rb, *fileopen_dir_te, *fileopen_preview_te;
GtkWidget *recent_files_count_max_te, *ask_unsaved_cb, *find_wrap_cb;
GtkWidget *recent_files_count_max_te, *recent_df_entries_max_te, *ask_unsaved_cb, *find_wrap_cb;
GtkWidget *use_pref_save_cb;
GtkWidget *webbrowser_te;
GtkWidget *save_position_cb, *save_size_cb, *save_maximized_cb, *save_column_width_cb;
@ -261,6 +267,14 @@ gui_prefs_show(void)
g_object_set_data(G_OBJECT(main_vb), GUI_FILEOPEN_PREVIEW_KEY, fileopen_preview_te);
g_signal_connect(fileopen_preview_te, "focus_out_event", G_CALLBACK(fileopen_preview_changed_cb), main_vb);
/* Number of recent entries in the display filter list ... */
recent_df_entries_max_te = create_preference_entry(main_tb, pos++,
"Filter display max. list entries:", "Maximum number of recent entries in filter display list", recent_df_entries_max_str);
g_snprintf(current_val_str, 128, "%d", prefs.gui_recent_df_entries_max);
gtk_entry_set_text(GTK_ENTRY(recent_df_entries_max_te), current_val_str);
g_object_set_data(G_OBJECT(main_vb), GUI_RECENT_DF_ENTRIES_KEY, recent_df_entries_max_te);
g_signal_connect(recent_df_entries_max_te, "focus_out_event", G_CALLBACK(recent_df_entries_changed_cb), main_vb);
/* Number of entries in the recent_files list ... */
recent_files_count_max_te = create_preference_entry(main_tb, pos++,
"\"Open Recent\" max. list entries:", "Maximum number of recent files", recent_files_count_max_str);
@ -481,6 +495,30 @@ gui_prefs_destroy(GtkWidget *w _U_)
}
}
static gint
recent_df_entries_changed_cb(GtkWidget *recent_df_entry _U_,
GdkEvent *event _U_, gpointer parent_w)
{
GtkWidget *recent_df_entries_count_te;
guint newval;
recent_df_entries_count_te = (GtkWidget *)g_object_get_data(G_OBJECT(parent_w), GUI_RECENT_DF_ENTRIES_KEY);
/*
* Now, just convert the string to a number and store it in the prefs
* filed ...
*/
newval = strtol(gtk_entry_get_text (GTK_ENTRY(recent_df_entries_count_te)), NULL, 10);
if (newval > 0) {
prefs.gui_recent_df_entries_max = newval;
}
/* We really should pop up a nasty dialog box if newval <= 0 */
return FALSE;
}
static gint
recent_files_count_changed_cb(GtkWidget *recent_files_entry _U_,