added a preference setting, to be able to change the preview timeout in the file open dialog (as requested by Ronnie Sahlberg).

svn path=/trunk/; revision=11859
This commit is contained in:
Ulf Lamping 2004-08-31 09:22:57 +00:00
parent 5a9fc6543f
commit 5e32dc06eb
4 changed files with 63 additions and 13 deletions

View File

@ -113,7 +113,6 @@ static GtkWidget *file_save_as_w;
#endif
#define PREVIEW_STR_MAX 200
#define PREVIEW_TIMEOUT_SECS 3
static double
secs_usecs( guint32 s, guint32 us)
@ -235,7 +234,7 @@ preview_do(GtkWidget *prev, wtap *wth)
if(packets%1000) {
/* do we have a timeout? */
time(&time_current);
if(time_current-time_preview >= PREVIEW_TIMEOUT_SECS) {
if(time_current-time_preview >= (time_t) prefs.gui_fileopen_preview) {
is_breaked = TRUE;
break;
}

View File

@ -52,6 +52,7 @@
static gint fetch_enum_value(gpointer control, const enum_val_t *enumvals);
static gint fileopen_dir_changed_cb(GtkWidget *myentry _U_, GdkEvent *event, gpointer parent_w);
static gint fileopen_preview_changed_cb(GtkWidget *myentry _U_, GdkEvent *event, gpointer parent_w);
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);
@ -73,6 +74,7 @@ static gint recent_files_count_changed_cb(GtkWidget *recent_files_entry _U_,
#define GUI_CONSOLE_OPEN_KEY "console_open"
#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_FILEOPEN_DIR_KEY "fileopen_directory"
#define GUI_ASK_UNSAVED_KEY "ask_unsaved"
@ -167,6 +169,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 Open File preview timeout pref item */
static char open_file_preview_str[128] = "";
#if GTK_MAJOR_VERSION < 2
#define GUI_TABLE_ROWS 10
#else
@ -182,7 +187,8 @@ gui_prefs_show(void)
#ifdef _WIN32
GtkWidget *console_open_om;
#endif
GtkWidget *fileopen_rb, *fileopen_dir_te, *toolbar_style_om;
GtkWidget *fileopen_rb, *fileopen_dir_te, *fileopen_preview_te;
GtkWidget *toolbar_style_om;
GtkWidget *filter_toolbar_placement_om;
GtkWidget *recent_files_count_max_te, *ask_unsaved_cb, *find_wrap_cb;
GtkWidget *webbrowser_te;
@ -308,6 +314,14 @@ gui_prefs_show(void)
SIGNAL_CONNECT(fileopen_dir_te, "focus-out-event",
fileopen_dir_changed_cb, main_vb);
/* File Open dialog preview timeout */
fileopen_preview_te = create_preference_entry(main_tb, pos++,
"\"File Open\" preview timeout:", "Timeout, until preview gives up scanning the capture file content.", open_file_preview_str);
g_snprintf(current_val_str, 128, "%d", prefs.gui_fileopen_preview);
gtk_entry_set_text(GTK_ENTRY(fileopen_preview_te), current_val_str);
OBJECT_SET_DATA(main_vb, GUI_FILEOPEN_PREVIEW_KEY, fileopen_preview_te);
SIGNAL_CONNECT(fileopen_preview_te, "focus_out_event", fileopen_preview_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);
@ -557,6 +571,31 @@ recent_files_count_changed_cb(GtkWidget *recent_files_entry _U_,
return FALSE;
}
static gint
fileopen_preview_changed_cb(GtkWidget *recent_files_entry _U_,
GdkEvent *event _U_, gpointer parent_w)
{
GtkWidget *fileopen_preview_te;
guint newval;
fileopen_preview_te = (GtkWidget *)OBJECT_GET_DATA(parent_w, GUI_FILEOPEN_PREVIEW_KEY);
/*
* Now, just convert the string to a number and store it in the prefs
* filed ...
*/
newval = strtol(gtk_entry_get_text (GTK_ENTRY(fileopen_preview_te)), NULL, 10);
if (newval > 0) {
prefs.gui_fileopen_preview = newval;
}
/* We really should pop up a nasty dialog box if newval <= 0 */
return FALSE;
}
static gint
fileopen_dir_changed_cb(GtkWidget *fileopen_entry _U_, GdkEvent *event _U_, gpointer parent_w)
{

29
prefs.c
View File

@ -1011,6 +1011,7 @@ read_prefs(int *gpf_errno_return, int *gpf_read_errno_return,
prefs.gui_fileopen_style = FO_STYLE_LAST_OPENED;
prefs.gui_recent_files_count_max = 10;
prefs.gui_fileopen_dir = g_strdup("");
prefs.gui_fileopen_preview = 3;
prefs.gui_ask_unsaved = TRUE;
prefs.gui_find_wrap = TRUE;
prefs.gui_webbrowser = g_strdup("mozilla %s");
@ -1315,6 +1316,7 @@ prefs_set_pref(char *prefarg)
#define PRS_GUI_RECENT_COUNT_MAX "gui.recent_files_count.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"
#define PRS_GUI_ASK_UNSAVED "gui.ask_unsaved"
#define PRS_GUI_FIND_WRAP "gui.find_wrap"
#define PRS_GUI_GEOMETRY_SAVE_POSITION "gui.geometry.save.position"
@ -1628,22 +1630,23 @@ set_pref(gchar *pref_name, gchar *value)
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,
FO_STYLE_LAST_OPENED);
} else if (strcmp(pref_name, PRS_GUI_RECENT_COUNT_MAX) == 0) {
prefs.gui_recent_files_count_max = strtoul(value, NULL, 10);
if (prefs.gui_recent_files_count_max == 0) {
/* We really should put up a dialog box here ... */
prefs.gui_recent_files_count_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,
FO_STYLE_LAST_OPENED);
} else if (strcmp(pref_name, PRS_GUI_FILEOPEN_DIR) == 0) {
if (prefs.gui_fileopen_dir != NULL)
g_free(prefs.gui_fileopen_dir);
prefs.gui_fileopen_dir = g_strdup(value);
} else if (strcmp(pref_name, PRS_GUI_FILEOPEN_REMEMBERED_DIR) == 0) { /* deprecated */
} else if (strcmp(pref_name, PRS_GUI_FILEOPEN_PREVIEW) == 0) {
prefs.gui_fileopen_preview = strtoul(value, NULL, 10);
} else if (strcmp(pref_name, PRS_GUI_ASK_UNSAVED) == 0) {
if (strcasecmp(value, "true") == 0) {
prefs.gui_ask_unsaved = TRUE;
@ -2206,20 +2209,27 @@ 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 items in the open recent files list.\n");
fprintf(pf, "# A decimal number.\n");
fprintf(pf, PRS_GUI_RECENT_COUNT_MAX ": %d\n",
prefs.gui_recent_files_count_max);
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",
gui_fileopen_style_text[prefs.gui_fileopen_style]);
fprintf(pf, PRS_GUI_RECENT_COUNT_MAX ": %d\n",
prefs.gui_recent_files_count_max);
if (prefs.gui_fileopen_dir != NULL) {
fprintf(pf, "\n# Directory to start in when opening File Open dialog.\n");
fprintf(pf, PRS_GUI_FILEOPEN_DIR ": %s\n",
prefs.gui_fileopen_dir);
}
fprintf(pf, "\n# The preview timeout in the File Open dialog.\n");
fprintf(pf, "# A decimal number (in seconds).\n");
fprintf(pf, PRS_GUI_FILEOPEN_PREVIEW ": %d\n",
prefs.gui_fileopen_preview);
fprintf(pf, "\n# Ask to save unsaved capture files?\n");
fprintf(pf, "# TRUE or FALSE (case-insensitive).\n");
fprintf(pf, PRS_GUI_ASK_UNSAVED ": %s\n",
@ -2423,6 +2433,7 @@ copy_prefs(e_prefs *dest, e_prefs *src)
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_fileopen_preview = src->gui_fileopen_preview;
dest->gui_ask_unsaved = src->gui_ask_unsaved;
dest->gui_find_wrap = src->gui_find_wrap;
dest->gui_layout_type = src->gui_layout_type;

View File

@ -125,9 +125,10 @@ typedef struct _e_prefs {
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;
guint gui_fileopen_style;
gchar *gui_fileopen_dir;
guint gui_fileopen_preview;
gboolean gui_ask_unsaved;
gboolean gui_find_wrap;
gchar *gui_webbrowser;