2006-04-29 23:03:57 +00:00
|
|
|
/* capture_file_dlg.c
|
|
|
|
* Dialog boxes for handling capture files
|
1999-09-09 04:25:49 +00:00
|
|
|
*
|
2004-07-18 00:24:25 +00:00
|
|
|
* $Id$
|
1999-09-09 04:25:49 +00:00
|
|
|
*
|
2006-05-21 05:12:17 +00:00
|
|
|
* Wireshark - Network traffic analyzer
|
|
|
|
* By Gerald Combs <gerald@wireshark.org>
|
1999-09-09 04:25:49 +00:00
|
|
|
* Copyright 1998 Gerald Combs
|
2002-08-28 21:04:11 +00:00
|
|
|
*
|
1999-09-09 04:25:49 +00:00
|
|
|
* This program is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU General Public License
|
|
|
|
* as published by the Free Software Foundation; either version 2
|
|
|
|
* of the License, or (at your option) any later version.
|
2002-08-28 21:04:11 +00:00
|
|
|
*
|
1999-09-09 04:25:49 +00:00
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
2002-08-28 21:04:11 +00:00
|
|
|
*
|
1999-09-09 04:25:49 +00:00
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program; if not, write to the Free Software
|
|
|
|
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
|
|
|
*/
|
|
|
|
|
1999-09-01 03:04:24 +00:00
|
|
|
#ifdef HAVE_CONFIG_H
|
|
|
|
#include "config.h"
|
|
|
|
#endif
|
|
|
|
|
2008-04-13 00:55:59 +00:00
|
|
|
#ifdef HAVE_UNISTD_H
|
|
|
|
#include <unistd.h>
|
|
|
|
#endif
|
|
|
|
|
2004-06-20 07:28:02 +00:00
|
|
|
#include <string.h>
|
|
|
|
|
2002-09-05 18:48:52 +00:00
|
|
|
#include <gtk/gtk.h>
|
2001-10-24 07:18:39 +00:00
|
|
|
|
2004-09-04 20:02:11 +00:00
|
|
|
#include "packet-range.h"
|
On Windows, use the directory in which the binary resides as the
directory in which global data files are stored. If an installed binary
is being run, that's the correct directory for them; if a build-tree
binary is being run, the "manuf" file will be there, and you can put
other data files there as well, if necessary.
Do the same with plugins, except that, if there's no
"plugins\\{version}" subdirectory of that directory, fall back on the
default installation directory, so you at least have a place where you
can put plugins for use by build-tree binaries. (Should we, instead,
have the Windows build procedure create a subdirectory of the "plugins"
source directory, with the plugin version number as its name, and copy
the plugins there, so you'd use the build-tree plugin binaries?)
Move "test_for_directory()" out of "util.c" and into
"epan/filesystem.c", with the other file system access portability
wrappers and convenience routines. Fix "util.h" not to declare it - or
other routines moved to "epan/filesystem.c" a while ago.
svn path=/trunk/; revision=3858
2001-08-21 06:39:18 +00:00
|
|
|
#include <epan/filesystem.h>
|
2004-08-06 19:57:49 +00:00
|
|
|
#include <epan/addr_resolv.h>
|
2004-09-27 22:55:15 +00:00
|
|
|
#include <epan/prefs.h>
|
2008-04-13 00:55:59 +00:00
|
|
|
|
|
|
|
#include "../globals.h"
|
|
|
|
#include "../alert_box.h"
|
|
|
|
#include "../simple_dialog.h"
|
|
|
|
#include "../color.h"
|
2004-01-10 17:29:26 +00:00
|
|
|
#include "../ui_util.h"
|
2008-04-13 00:55:59 +00:00
|
|
|
#include "../color_filters.h"
|
|
|
|
#include "../merge.h"
|
|
|
|
#include "../util.h"
|
2008-05-22 15:46:27 +00:00
|
|
|
#include <wsutil/file_util.h>
|
2004-01-29 23:11:38 +00:00
|
|
|
|
2008-04-13 00:55:59 +00:00
|
|
|
#include "gtk/gtkglobals.h"
|
|
|
|
#include "gtk/keys.h"
|
|
|
|
#include "gtk/filter_dlg.h"
|
|
|
|
#include "gtk/gui_utils.h"
|
|
|
|
#include "gtk/dlg_utils.h"
|
|
|
|
#include "gtk/file_dlg.h"
|
|
|
|
#include "gtk/capture_file_dlg.h"
|
|
|
|
#include "gtk/drag_and_drop.h"
|
|
|
|
#include "gtk/main.h"
|
2009-06-21 19:16:37 +00:00
|
|
|
#include "gtk/menus.h"
|
2008-04-13 00:55:59 +00:00
|
|
|
#include "gtk/recent.h"
|
|
|
|
#include "gtk/color_dlg.h"
|
2009-07-01 09:05:13 +00:00
|
|
|
#ifdef NEW_PACKET_LIST
|
2009-07-02 22:04:22 +00:00
|
|
|
#include "gtk/new_packet_list.h"
|
2009-07-01 09:05:13 +00:00
|
|
|
#endif
|
2008-04-13 00:55:59 +00:00
|
|
|
#ifdef HAVE_LIBPCAP
|
|
|
|
#include "gtk/capture_dlg.h"
|
2004-06-30 07:12:25 +00:00
|
|
|
#endif
|
2008-04-13 00:55:59 +00:00
|
|
|
#include "gtk/stock_icons.h"
|
|
|
|
#include "gtk/range_utils.h"
|
2008-10-19 14:12:58 +00:00
|
|
|
#include "gtk/filter_autocomplete.h"
|
2004-06-30 07:12:25 +00:00
|
|
|
|
2008-04-06 22:25:36 +00:00
|
|
|
#if _WIN32
|
2006-02-13 21:25:43 +00:00
|
|
|
#include <gdk/gdkwin32.h>
|
|
|
|
#include <windows.h>
|
2008-04-13 12:14:57 +00:00
|
|
|
#include "gtk/file_dlg_win32.h"
|
2006-02-13 21:25:43 +00:00
|
|
|
#endif
|
|
|
|
|
2008-04-13 00:55:59 +00:00
|
|
|
|
2004-03-27 11:16:58 +00:00
|
|
|
static void file_open_ok_cb(GtkWidget *w, gpointer fs);
|
Split "filter_dialog_cb()" into "filter_dialog_cb()", which pops up a
"global" dialog box when "Edit:Filters" is selected, so that the list of
filters can be edited, and "filter_browse_cb()", which pops up a dialog
box associated with a "Filter:" button and a text entry widget attached
to that button, so that a filter can be selected or saved (although it
also supports the same editing that the "global" dialog box does).
Have "filter_dialog_cb()" connect the window in which the "Filter:"
button lives and the filter dialog box, so that:
if the window in which the "Filter:" button lives goes away, so
does the filter dialog box (as it no longer has a text widget
into which it can stuff the selected filter);
if the "Filter:" button is clicked when there's already a filter
dialog box open, we just reactivate that existing dialog box
rather than popping up a new one.
Also keep a pointer to the "global" filter dialog box, so that we also
arrange that there's only one of them (by reactivating the existing on
if "Edit:Filters" is selected when there's already a "global" filter
dialog box open).
Keep around pointers to the dialog boxes that contain the "Filter:"
buttons, so that we can arrange that there be only one of them (that was
a side-effect of an earlier attempt at fixing the problems described
above, but it's still useful for keeping multiple competing dialog boxes
from being open - there's more of that to be done).
Make the pointer to the "Open Capture File" dialog box widget static to
"file_dlg.c" - nobody outside of "file_dlg.c cares about it.
svn path=/trunk/; revision=1774
2000-04-01 12:03:42 +00:00
|
|
|
static void file_open_destroy_cb(GtkWidget *win, gpointer user_data);
|
2004-06-17 21:53:26 +00:00
|
|
|
static void file_merge_ok_cb(GtkWidget *w, gpointer fs);
|
|
|
|
static void file_merge_destroy_cb(GtkWidget *win, gpointer user_data);
|
2010-03-21 19:26:32 +00:00
|
|
|
static void file_save_as_select_file_type_cb(GtkWidget *w, gpointer data);
|
2004-03-27 11:16:58 +00:00
|
|
|
static void file_save_as_ok_cb(GtkWidget *w, gpointer fs);
|
2000-04-10 18:40:13 +00:00
|
|
|
static void file_save_as_destroy_cb(GtkWidget *win, gpointer user_data);
|
2006-10-03 18:39:36 +00:00
|
|
|
static void file_color_import_ok_cb(GtkWidget *w, gpointer filter_list);
|
2003-08-18 21:27:11 +00:00
|
|
|
static void file_color_import_destroy_cb(GtkWidget *win, gpointer user_data);
|
2006-10-03 18:39:36 +00:00
|
|
|
static void file_color_export_ok_cb(GtkWidget *w, gpointer filter_list);
|
2003-08-18 21:27:11 +00:00
|
|
|
static void file_color_export_destroy_cb(GtkWidget *win, gpointer user_data);
|
2010-03-21 19:26:32 +00:00
|
|
|
static gint set_file_type_list(GtkWidget *combo_box, int default_file_type);
|
|
|
|
|
|
|
|
#define E_FILE_TYPE_COMBO_BOX_KEY "file_type_combo_box"
|
|
|
|
#define E_COMPRESSED_CB_KEY "compressed_cb"
|
1999-09-01 03:04:24 +00:00
|
|
|
|
2001-05-31 08:36:46 +00:00
|
|
|
#define E_FILE_M_RESOLVE_KEY "file_dlg_mac_resolve_key"
|
|
|
|
#define E_FILE_N_RESOLVE_KEY "file_dlg_network_resolve_key"
|
|
|
|
#define E_FILE_T_RESOLVE_KEY "file_dlg_transport_resolve_key"
|
2000-06-02 03:35:39 +00:00
|
|
|
|
2004-06-17 21:53:26 +00:00
|
|
|
#define E_MERGE_PREPEND_KEY "merge_dlg_prepend_key"
|
|
|
|
#define E_MERGE_CHRONO_KEY "merge_dlg_chrono_key"
|
|
|
|
#define E_MERGE_APPEND_KEY "merge_dlg_append_key"
|
|
|
|
|
2004-06-19 10:48:06 +00:00
|
|
|
|
|
|
|
#define PREVIEW_TABLE_KEY "preview_table_key"
|
|
|
|
#define PREVIEW_FILENAME_KEY "preview_filename_key"
|
|
|
|
#define PREVIEW_FORMAT_KEY "preview_format_key"
|
|
|
|
#define PREVIEW_SIZE_KEY "preview_size_key"
|
|
|
|
#define PREVIEW_ELAPSED_KEY "preview_elapsed_key"
|
|
|
|
#define PREVIEW_PACKETS_KEY "preview_packets_key"
|
|
|
|
#define PREVIEW_FIRST_KEY "preview_first_key"
|
|
|
|
|
|
|
|
|
2003-12-29 20:05:59 +00:00
|
|
|
/*
|
|
|
|
* Keep a static pointer to the current "Save Capture File As" window, if
|
|
|
|
* any, so that if somebody tries to do "File:Save" or "File:Save As"
|
|
|
|
* while there's already a "Save Capture File As" window up, we just pop
|
|
|
|
* up the existing one, rather than creating a new one.
|
|
|
|
*/
|
|
|
|
static GtkWidget *file_save_as_w;
|
|
|
|
|
2004-10-17 02:53:26 +00:00
|
|
|
/* XXX - can we make these not be static? */
|
2010-03-21 19:26:32 +00:00
|
|
|
static packet_range_t range;
|
|
|
|
static gboolean color_selected;
|
|
|
|
static GtkWidget *range_tb;
|
2003-11-30 04:21:55 +00:00
|
|
|
|
2004-06-20 09:35:51 +00:00
|
|
|
#define PREVIEW_STR_MAX 200
|
2004-06-19 10:48:06 +00:00
|
|
|
|
|
|
|
|
|
|
|
/* set a new filename for the preview widget */
|
2004-08-31 08:18:10 +00:00
|
|
|
static wtap *
|
2004-06-19 10:48:06 +00:00
|
|
|
preview_set_filename(GtkWidget *prev, const gchar *cf_name)
|
|
|
|
{
|
|
|
|
GtkWidget *label;
|
|
|
|
wtap *wth;
|
2004-06-20 09:35:51 +00:00
|
|
|
int err = 0;
|
2004-06-19 10:48:06 +00:00
|
|
|
gchar *err_info;
|
2004-06-20 09:35:51 +00:00
|
|
|
gchar string_buff[PREVIEW_STR_MAX];
|
2005-08-19 19:40:00 +00:00
|
|
|
gint64 filesize;
|
2004-06-19 10:48:06 +00:00
|
|
|
|
2004-08-31 08:18:10 +00:00
|
|
|
|
|
|
|
/* init preview labels */
|
2008-04-11 17:14:11 +00:00
|
|
|
label = g_object_get_data(G_OBJECT(prev), PREVIEW_FILENAME_KEY);
|
2004-06-20 18:36:16 +00:00
|
|
|
gtk_label_set_text(GTK_LABEL(label), "-");
|
2008-04-11 17:14:11 +00:00
|
|
|
label = g_object_get_data(G_OBJECT(prev), PREVIEW_FORMAT_KEY);
|
2004-06-19 10:48:06 +00:00
|
|
|
gtk_label_set_text(GTK_LABEL(label), "-");
|
2008-04-11 17:14:11 +00:00
|
|
|
label = g_object_get_data(G_OBJECT(prev), PREVIEW_SIZE_KEY);
|
2004-06-19 10:48:06 +00:00
|
|
|
gtk_label_set_text(GTK_LABEL(label), "-");
|
2008-04-11 17:14:11 +00:00
|
|
|
label = g_object_get_data(G_OBJECT(prev), PREVIEW_ELAPSED_KEY);
|
2004-06-19 10:48:06 +00:00
|
|
|
gtk_label_set_text(GTK_LABEL(label), "-");
|
2008-04-11 17:14:11 +00:00
|
|
|
label = g_object_get_data(G_OBJECT(prev), PREVIEW_PACKETS_KEY);
|
2004-06-19 10:48:06 +00:00
|
|
|
gtk_label_set_text(GTK_LABEL(label), "-");
|
2008-04-11 17:14:11 +00:00
|
|
|
label = g_object_get_data(G_OBJECT(prev), PREVIEW_FIRST_KEY);
|
2004-06-19 10:48:06 +00:00
|
|
|
gtk_label_set_text(GTK_LABEL(label), "-");
|
|
|
|
|
2004-06-20 18:36:16 +00:00
|
|
|
if(!cf_name) {
|
2005-01-01 23:19:11 +00:00
|
|
|
return NULL;
|
2004-06-20 18:36:16 +00:00
|
|
|
}
|
|
|
|
|
2008-04-11 17:14:11 +00:00
|
|
|
label = g_object_get_data(G_OBJECT(prev), PREVIEW_FILENAME_KEY);
|
"gtk_entry_get_text()" returns a "const char *" - assign the result to
one.
"get_basename()" doesn't modify its argument, and its callers don't
modify the substring pointed to by the result, so make it take a "const
char *" as an argument and return a "const char *".
"find_last_pathname_separator()" doesn't modify its argument, so make it
a "const char *" - but some of its callers pass a non-"const" "char *"
and modify the result, so don't make its return value a "const char *".
And, as none of its callers are outside "filesystem.c", make it static.
In "about_folders_page_new()", have separate variables for pathnames
returned as "const char *" (which are cached by the routine that returns
them, so you can't modify them - and can't free them, so get rid of the
commented-out "g_free()" calls for them) and pathnames returned as "char
*" (which are allocated anew for each call, and can be modified, but
have to be freed).
Clean up white space.
svn path=/trunk/; revision=12881
2004-12-31 00:26:36 +00:00
|
|
|
gtk_label_set_text(GTK_LABEL(label), get_basename(cf_name));
|
2004-06-20 18:36:16 +00:00
|
|
|
|
2004-06-19 10:48:06 +00:00
|
|
|
if (test_for_directory(cf_name) == EISDIR) {
|
2008-04-11 17:14:11 +00:00
|
|
|
label = g_object_get_data(G_OBJECT(prev), PREVIEW_FORMAT_KEY);
|
2004-06-19 10:48:06 +00:00
|
|
|
gtk_label_set_text(GTK_LABEL(label), "directory");
|
2005-01-01 23:19:11 +00:00
|
|
|
return NULL;
|
2004-06-19 10:48:06 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
wth = wtap_open_offline(cf_name, &err, &err_info, TRUE);
|
|
|
|
if (wth == NULL) {
|
2008-04-11 17:14:11 +00:00
|
|
|
label = g_object_get_data(G_OBJECT(prev), PREVIEW_FORMAT_KEY);
|
2004-06-19 10:48:06 +00:00
|
|
|
if(err == WTAP_ERR_FILE_UNKNOWN_FORMAT) {
|
|
|
|
gtk_label_set_text(GTK_LABEL(label), "unknown file format");
|
|
|
|
} else {
|
|
|
|
gtk_label_set_text(GTK_LABEL(label), "error opening file");
|
|
|
|
}
|
2005-01-01 23:19:11 +00:00
|
|
|
return NULL;
|
2004-06-19 10:48:06 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Find the size of the file. */
|
2005-08-19 19:40:00 +00:00
|
|
|
filesize = wtap_file_size(wth, &err);
|
|
|
|
if (filesize == -1) {
|
|
|
|
gtk_label_set_text(GTK_LABEL(label), "error getting file size");
|
2004-06-19 10:48:06 +00:00
|
|
|
wtap_close(wth);
|
2005-01-01 23:19:11 +00:00
|
|
|
return NULL;
|
2004-06-19 10:48:06 +00:00
|
|
|
}
|
2007-05-29 18:52:42 +00:00
|
|
|
g_snprintf(string_buff, PREVIEW_STR_MAX, "%" G_GINT64_MODIFIER "d bytes", filesize);
|
2008-04-11 17:14:11 +00:00
|
|
|
label = g_object_get_data(G_OBJECT(prev), PREVIEW_SIZE_KEY);
|
2004-06-19 10:48:06 +00:00
|
|
|
gtk_label_set_text(GTK_LABEL(label), string_buff);
|
|
|
|
|
|
|
|
/* type */
|
2009-03-12 07:56:42 +00:00
|
|
|
g_strlcpy(string_buff, wtap_file_type_string(wtap_file_type(wth)), PREVIEW_STR_MAX);
|
2008-04-11 17:14:11 +00:00
|
|
|
label = g_object_get_data(G_OBJECT(prev), PREVIEW_FORMAT_KEY);
|
2004-06-19 10:48:06 +00:00
|
|
|
gtk_label_set_text(GTK_LABEL(label), string_buff);
|
|
|
|
|
2004-08-31 08:18:10 +00:00
|
|
|
return wth;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/* do a preview run on the currently selected capture file */
|
|
|
|
static void
|
|
|
|
preview_do(GtkWidget *prev, wtap *wth)
|
|
|
|
{
|
|
|
|
GtkWidget *label;
|
|
|
|
unsigned int elapsed_time;
|
|
|
|
time_t time_preview;
|
|
|
|
time_t time_current;
|
|
|
|
int err = 0;
|
|
|
|
gchar *err_info;
|
2006-11-05 22:46:44 +00:00
|
|
|
gint64 data_offset;
|
2004-08-31 08:18:10 +00:00
|
|
|
const struct wtap_pkthdr *phdr;
|
2005-08-24 21:31:56 +00:00
|
|
|
double start_time = 0; /* seconds, with nsec resolution */
|
|
|
|
double stop_time = 0; /* seconds, with nsec resolution */
|
2004-08-31 08:18:10 +00:00
|
|
|
double cur_time;
|
|
|
|
unsigned int packets = 0;
|
|
|
|
gboolean is_breaked = FALSE;
|
|
|
|
gchar string_buff[PREVIEW_STR_MAX];
|
|
|
|
time_t ti_time;
|
|
|
|
struct tm *ti_tm;
|
|
|
|
|
|
|
|
|
2004-06-20 09:35:51 +00:00
|
|
|
time(&time_preview);
|
Make the elapsed time value an "unsigned int" (if the stop time is
before the start time, due to packet time stamp bogosity, neither a
signed value nor an unsigned value will give a sensible answer, and it
doesn't need to be a "long" as the capture's unlikely to span more than
2^32-1 seconds, again modulo packet time stamp bogosity). That
eliminates some format item vs. value warnings.
Make the packet count an "unsigned int" (it can't be negative, and we're
unlikely to have more than 2^32-1 packets - and, if we are, it should be
made a guint64). That eliminates some more format item vs. value
warnings.
Initialize "start_time" and "stop_time" to 0, so that we handle files
with no packets (and so that we don't get uninitialized variable
warnings).
Display the file size with PRIu64, after casting it to "guint64" (that
way we handle file sizes if they're "unsigned int", "unsigned long", or
a 64-bit type on ILP64 platforms (it's 64 bits in BSDs derived from
4.4BSD, even on ILP64 platforms).
Mark the first argument to "file_open_entry_changed()" as unused.
Don't use G_CONST_RETURN, as it's not defined by GLib 1.2[.x].
Get rid of an unused variable.
Clean up white space.
svn path=/trunk/; revision=11189
2004-06-20 03:05:57 +00:00
|
|
|
while ( (wtap_read(wth, &err, &err_info, &data_offset)) ) {
|
2006-02-13 21:25:43 +00:00
|
|
|
phdr = wtap_phdr(wth);
|
2007-04-03 21:17:13 +00:00
|
|
|
cur_time = wtap_nstime_to_sec(&phdr->ts);
|
2004-08-31 08:18:10 +00:00
|
|
|
if(packets == 0) {
|
2004-06-19 10:48:06 +00:00
|
|
|
start_time = cur_time;
|
|
|
|
stop_time = cur_time;
|
|
|
|
}
|
|
|
|
if (cur_time < start_time) {
|
|
|
|
start_time = cur_time;
|
|
|
|
}
|
|
|
|
if (cur_time > stop_time){
|
|
|
|
stop_time = cur_time;
|
|
|
|
}
|
2004-08-31 08:18:10 +00:00
|
|
|
|
|
|
|
packets++;
|
2008-12-24 14:21:03 +00:00
|
|
|
if(packets%1000 == 0) {
|
2004-08-31 08:18:10 +00:00
|
|
|
/* do we have a timeout? */
|
2004-06-20 09:35:51 +00:00
|
|
|
time(&time_current);
|
2004-08-31 09:22:57 +00:00
|
|
|
if(time_current-time_preview >= (time_t) prefs.gui_fileopen_preview) {
|
2004-06-20 09:35:51 +00:00
|
|
|
is_breaked = TRUE;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
Make the elapsed time value an "unsigned int" (if the stop time is
before the start time, due to packet time stamp bogosity, neither a
signed value nor an unsigned value will give a sensible answer, and it
doesn't need to be a "long" as the capture's unlikely to span more than
2^32-1 seconds, again modulo packet time stamp bogosity). That
eliminates some format item vs. value warnings.
Make the packet count an "unsigned int" (it can't be negative, and we're
unlikely to have more than 2^32-1 packets - and, if we are, it should be
made a guint64). That eliminates some more format item vs. value
warnings.
Initialize "start_time" and "stop_time" to 0, so that we handle files
with no packets (and so that we don't get uninitialized variable
warnings).
Display the file size with PRIu64, after casting it to "guint64" (that
way we handle file sizes if they're "unsigned int", "unsigned long", or
a 64-bit type on ILP64 platforms (it's 64 bits in BSDs derived from
4.4BSD, even on ILP64 platforms).
Mark the first argument to "file_open_entry_changed()" as unused.
Don't use G_CONST_RETURN, as it's not defined by GLib 1.2[.x].
Get rid of an unused variable.
Clean up white space.
svn path=/trunk/; revision=11189
2004-06-20 03:05:57 +00:00
|
|
|
}
|
2004-06-19 10:48:06 +00:00
|
|
|
|
|
|
|
if(err != 0) {
|
2004-08-31 08:18:10 +00:00
|
|
|
g_snprintf(string_buff, PREVIEW_STR_MAX, "error after reading %u packets", packets);
|
2008-04-11 17:14:11 +00:00
|
|
|
label = g_object_get_data(G_OBJECT(prev), PREVIEW_PACKETS_KEY);
|
2004-06-19 10:48:06 +00:00
|
|
|
gtk_label_set_text(GTK_LABEL(label), string_buff);
|
|
|
|
wtap_close(wth);
|
2004-08-31 08:18:10 +00:00
|
|
|
return;
|
2004-06-19 10:48:06 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* packet count */
|
2004-06-20 09:35:51 +00:00
|
|
|
if(is_breaked) {
|
2004-08-31 08:18:10 +00:00
|
|
|
g_snprintf(string_buff, PREVIEW_STR_MAX, "more than %u packets (preview timeout)", packets);
|
2004-06-20 09:35:51 +00:00
|
|
|
} else {
|
2004-08-31 08:18:10 +00:00
|
|
|
g_snprintf(string_buff, PREVIEW_STR_MAX, "%u", packets);
|
2004-06-20 09:35:51 +00:00
|
|
|
}
|
2008-04-11 17:14:11 +00:00
|
|
|
label = g_object_get_data(G_OBJECT(prev), PREVIEW_PACKETS_KEY);
|
2004-06-19 10:48:06 +00:00
|
|
|
gtk_label_set_text(GTK_LABEL(label), string_buff);
|
|
|
|
|
|
|
|
/* first packet */
|
|
|
|
ti_time = (long)start_time;
|
|
|
|
ti_tm = localtime( &ti_time );
|
2005-10-26 08:32:21 +00:00
|
|
|
if(ti_tm) {
|
|
|
|
g_snprintf(string_buff, PREVIEW_STR_MAX,
|
|
|
|
"%04d-%02d-%02d %02d:%02d:%02d",
|
|
|
|
ti_tm->tm_year + 1900,
|
|
|
|
ti_tm->tm_mon + 1,
|
|
|
|
ti_tm->tm_mday,
|
|
|
|
ti_tm->tm_hour,
|
|
|
|
ti_tm->tm_min,
|
|
|
|
ti_tm->tm_sec);
|
|
|
|
} else {
|
|
|
|
g_snprintf(string_buff, PREVIEW_STR_MAX, "?");
|
|
|
|
}
|
2008-04-11 17:14:11 +00:00
|
|
|
label = g_object_get_data(G_OBJECT(prev), PREVIEW_FIRST_KEY);
|
2004-06-19 10:48:06 +00:00
|
|
|
gtk_label_set_text(GTK_LABEL(label), string_buff);
|
|
|
|
|
|
|
|
/* elapsed time */
|
Make the elapsed time value an "unsigned int" (if the stop time is
before the start time, due to packet time stamp bogosity, neither a
signed value nor an unsigned value will give a sensible answer, and it
doesn't need to be a "long" as the capture's unlikely to span more than
2^32-1 seconds, again modulo packet time stamp bogosity). That
eliminates some format item vs. value warnings.
Make the packet count an "unsigned int" (it can't be negative, and we're
unlikely to have more than 2^32-1 packets - and, if we are, it should be
made a guint64). That eliminates some more format item vs. value
warnings.
Initialize "start_time" and "stop_time" to 0, so that we handle files
with no packets (and so that we don't get uninitialized variable
warnings).
Display the file size with PRIu64, after casting it to "guint64" (that
way we handle file sizes if they're "unsigned int", "unsigned long", or
a 64-bit type on ILP64 platforms (it's 64 bits in BSDs derived from
4.4BSD, even on ILP64 platforms).
Mark the first argument to "file_open_entry_changed()" as unused.
Don't use G_CONST_RETURN, as it's not defined by GLib 1.2[.x].
Get rid of an unused variable.
Clean up white space.
svn path=/trunk/; revision=11189
2004-06-20 03:05:57 +00:00
|
|
|
elapsed_time = (unsigned int)(stop_time-start_time);
|
2004-06-19 10:48:06 +00:00
|
|
|
if(elapsed_time/86400) {
|
2006-02-13 21:25:43 +00:00
|
|
|
g_snprintf(string_buff, PREVIEW_STR_MAX, "%02u days %02u:%02u:%02u",
|
2004-06-19 10:48:06 +00:00
|
|
|
elapsed_time/86400, elapsed_time%86400/3600, elapsed_time%3600/60, elapsed_time%60);
|
|
|
|
} else {
|
2006-02-13 21:25:43 +00:00
|
|
|
g_snprintf(string_buff, PREVIEW_STR_MAX, "%02u:%02u:%02u",
|
2004-06-19 10:48:06 +00:00
|
|
|
elapsed_time%86400/3600, elapsed_time%3600/60, elapsed_time%60);
|
|
|
|
}
|
2004-06-20 09:35:51 +00:00
|
|
|
if(is_breaked) {
|
|
|
|
g_snprintf(string_buff, PREVIEW_STR_MAX, "unknown");
|
|
|
|
}
|
2008-04-11 17:14:11 +00:00
|
|
|
label = g_object_get_data(G_OBJECT(prev), PREVIEW_ELAPSED_KEY);
|
2004-06-19 10:48:06 +00:00
|
|
|
gtk_label_set_text(GTK_LABEL(label), string_buff);
|
|
|
|
|
|
|
|
wtap_close(wth);
|
|
|
|
}
|
|
|
|
|
|
|
|
#if 0
|
|
|
|
/* as the dialog layout will look very ugly when using the file chooser preview mechanism,
|
2008-04-09 23:06:01 +00:00
|
|
|
simply use the same layout as in GTK2.0 */
|
2004-06-19 10:48:06 +00:00
|
|
|
static void
|
|
|
|
update_preview_cb (GtkFileChooser *file_chooser, gpointer data)
|
|
|
|
{
|
|
|
|
GtkWidget *prev = GTK_WIDGET (data);
|
|
|
|
char *cf_name;
|
|
|
|
gboolean have_preview;
|
|
|
|
|
|
|
|
cf_name = gtk_file_chooser_get_preview_filename (file_chooser);
|
|
|
|
|
|
|
|
have_preview = preview_set_filename(prev, cf_name);
|
|
|
|
|
|
|
|
g_free (cf_name);
|
|
|
|
|
|
|
|
have_preview = TRUE;
|
|
|
|
gtk_file_chooser_set_preview_widget_active (file_chooser, have_preview);
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
2004-08-31 08:18:10 +00:00
|
|
|
/* the filename text entry changed */
|
2004-06-19 10:48:06 +00:00
|
|
|
static void
|
Make the elapsed time value an "unsigned int" (if the stop time is
before the start time, due to packet time stamp bogosity, neither a
signed value nor an unsigned value will give a sensible answer, and it
doesn't need to be a "long" as the capture's unlikely to span more than
2^32-1 seconds, again modulo packet time stamp bogosity). That
eliminates some format item vs. value warnings.
Make the packet count an "unsigned int" (it can't be negative, and we're
unlikely to have more than 2^32-1 packets - and, if we are, it should be
made a guint64). That eliminates some more format item vs. value
warnings.
Initialize "start_time" and "stop_time" to 0, so that we handle files
with no packets (and so that we don't get uninitialized variable
warnings).
Display the file size with PRIu64, after casting it to "guint64" (that
way we handle file sizes if they're "unsigned int", "unsigned long", or
a 64-bit type on ILP64 platforms (it's 64 bits in BSDs derived from
4.4BSD, even on ILP64 platforms).
Mark the first argument to "file_open_entry_changed()" as unused.
Don't use G_CONST_RETURN, as it's not defined by GLib 1.2[.x].
Get rid of an unused variable.
Clean up white space.
svn path=/trunk/; revision=11189
2004-06-20 03:05:57 +00:00
|
|
|
file_open_entry_changed(GtkWidget *w _U_, gpointer file_sel)
|
2004-06-19 10:48:06 +00:00
|
|
|
{
|
2008-04-11 17:14:11 +00:00
|
|
|
GtkWidget *prev = g_object_get_data(G_OBJECT(file_sel), PREVIEW_TABLE_KEY);
|
2009-06-02 20:57:57 +00:00
|
|
|
gchar *cf_name;
|
2004-06-19 10:48:06 +00:00
|
|
|
gboolean have_preview;
|
2004-08-31 08:18:10 +00:00
|
|
|
wtap *wth;
|
2004-06-19 10:48:06 +00:00
|
|
|
|
|
|
|
/* get the filename */
|
|
|
|
cf_name = gtk_file_chooser_get_filename(GTK_FILE_CHOOSER(file_sel));
|
|
|
|
|
|
|
|
/* set the filename to the preview */
|
2004-08-31 08:18:10 +00:00
|
|
|
wth = preview_set_filename(prev, cf_name);
|
2005-01-01 23:19:11 +00:00
|
|
|
have_preview = (wth != NULL);
|
2004-06-19 10:48:06 +00:00
|
|
|
|
2009-06-02 20:57:57 +00:00
|
|
|
g_free(cf_name);
|
|
|
|
|
2004-06-19 10:48:06 +00:00
|
|
|
/* make the preview widget sensitive */
|
|
|
|
gtk_widget_set_sensitive(prev, have_preview);
|
|
|
|
|
2010-05-12 19:44:23 +00:00
|
|
|
/*
|
|
|
|
* XXX - if the Open button isn't sensitive, you can't type into
|
|
|
|
* the location bar and select the file or directory you've typed.
|
|
|
|
* See
|
|
|
|
*
|
|
|
|
* https://bugs.wireshark.org/bugzilla/show_bug.cgi?id=1791
|
|
|
|
*
|
|
|
|
* It's not as if allowing users to click Open when they've
|
|
|
|
* selected a file that's not a valid capture file will cause
|
|
|
|
* anything worse than an error dialog, so we'll leave the Open
|
|
|
|
* button sensitive for now. Perhaps making it sensitive if
|
|
|
|
* cf_name is NULL would also work, although I don't know whether
|
|
|
|
* there are any cases where it would be non-null when you've
|
|
|
|
* typed in the location bar.
|
|
|
|
*
|
|
|
|
* XXX - Bug 1791 also notes that, with the line removed, Bill
|
|
|
|
* Meier "somehow managed to get the file chooser window somewhat
|
|
|
|
* wedged in that neither the cancel or open buttons were responsive".
|
|
|
|
* That seems a bit odd, given that, without this line, we're not
|
|
|
|
* monkeying with the Open button's sensitivity, but...
|
|
|
|
*/
|
|
|
|
#if 0
|
2004-06-19 10:48:06 +00:00
|
|
|
/* make the open/save/... dialog button sensitive */
|
2008-04-27 07:01:58 +00:00
|
|
|
|
2004-06-19 10:48:06 +00:00
|
|
|
gtk_dialog_set_response_sensitive(file_sel, GTK_RESPONSE_ACCEPT, have_preview);
|
2010-05-12 19:44:23 +00:00
|
|
|
#endif
|
2004-08-31 08:18:10 +00:00
|
|
|
|
|
|
|
/* do the actual preview */
|
|
|
|
if(have_preview)
|
|
|
|
preview_do(prev, wth);
|
2004-06-19 10:48:06 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/* copied from summary_dlg.c */
|
|
|
|
static GtkWidget *
|
2005-08-05 20:59:08 +00:00
|
|
|
add_string_to_table_sensitive(GtkWidget *list, guint *row, const gchar *title, const gchar *value, gboolean sensitive)
|
2004-06-19 10:48:06 +00:00
|
|
|
{
|
|
|
|
GtkWidget *label;
|
|
|
|
gchar *indent;
|
|
|
|
|
|
|
|
if(strlen(value) != 0) {
|
|
|
|
indent = g_strdup_printf(" %s", title);
|
|
|
|
} else {
|
|
|
|
indent = g_strdup(title);
|
|
|
|
}
|
|
|
|
label = gtk_label_new(indent);
|
|
|
|
g_free(indent);
|
2009-04-21 16:57:52 +00:00
|
|
|
gtk_misc_set_alignment(GTK_MISC(label), 0.0f, 0.5f);
|
2004-06-19 10:48:06 +00:00
|
|
|
gtk_widget_set_sensitive(label, sensitive);
|
|
|
|
gtk_table_attach_defaults(GTK_TABLE(list), label, 0, 1, *row, *row+1);
|
|
|
|
|
|
|
|
label = gtk_label_new(value);
|
2009-04-21 16:57:52 +00:00
|
|
|
gtk_misc_set_alignment(GTK_MISC(label), 0.0f, 0.5f);
|
2004-06-19 10:48:06 +00:00
|
|
|
gtk_widget_set_sensitive(label, sensitive);
|
|
|
|
gtk_table_attach_defaults(GTK_TABLE(list), label, 1, 2, *row, *row+1);
|
|
|
|
|
|
|
|
*row = *row + 1;
|
|
|
|
|
|
|
|
return label;
|
|
|
|
}
|
|
|
|
|
|
|
|
static GtkWidget *
|
2005-08-05 20:59:08 +00:00
|
|
|
add_string_to_table(GtkWidget *list, guint *row, const gchar *title, const gchar *value)
|
2004-06-19 10:48:06 +00:00
|
|
|
{
|
|
|
|
return add_string_to_table_sensitive(list, row, title, value, TRUE);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
static GtkWidget *
|
|
|
|
preview_new(void)
|
|
|
|
{
|
|
|
|
GtkWidget *table, *label;
|
|
|
|
guint row;
|
|
|
|
|
|
|
|
table = gtk_table_new(1, 2, FALSE);
|
|
|
|
gtk_table_set_col_spacings(GTK_TABLE(table), 6);
|
|
|
|
gtk_table_set_row_spacings(GTK_TABLE(table), 3);
|
|
|
|
row = 0;
|
|
|
|
|
|
|
|
label = add_string_to_table(table, &row, "Filename:", "-");
|
2008-04-11 20:31:05 +00:00
|
|
|
gtk_widget_set_size_request(label, DEF_WIDTH/3, -1);
|
2008-04-11 17:14:11 +00:00
|
|
|
g_object_set_data(G_OBJECT(table), PREVIEW_FILENAME_KEY, label);
|
2004-06-19 10:48:06 +00:00
|
|
|
label = add_string_to_table(table, &row, "Format:", "-");
|
2008-04-11 17:14:11 +00:00
|
|
|
g_object_set_data(G_OBJECT(table), PREVIEW_FORMAT_KEY, label);
|
2004-06-19 10:48:06 +00:00
|
|
|
label = add_string_to_table(table, &row, "Size:", "-");
|
2008-04-11 17:14:11 +00:00
|
|
|
g_object_set_data(G_OBJECT(table), PREVIEW_SIZE_KEY, label);
|
2004-06-19 10:48:06 +00:00
|
|
|
label = add_string_to_table(table, &row, "Packets:", "-");
|
2008-04-11 17:14:11 +00:00
|
|
|
g_object_set_data(G_OBJECT(table), PREVIEW_PACKETS_KEY, label);
|
2004-06-19 10:48:06 +00:00
|
|
|
label = add_string_to_table(table, &row, "First Packet:", "-");
|
2008-04-11 17:14:11 +00:00
|
|
|
g_object_set_data(G_OBJECT(table), PREVIEW_FIRST_KEY, label);
|
2004-06-19 10:48:06 +00:00
|
|
|
label = add_string_to_table(table, &row, "Elapsed time:", "-");
|
2008-04-11 17:14:11 +00:00
|
|
|
g_object_set_data(G_OBJECT(table), PREVIEW_ELAPSED_KEY, label);
|
2004-06-19 10:48:06 +00:00
|
|
|
|
|
|
|
return table;
|
|
|
|
}
|
2003-11-30 04:21:55 +00:00
|
|
|
|
Split "filter_dialog_cb()" into "filter_dialog_cb()", which pops up a
"global" dialog box when "Edit:Filters" is selected, so that the list of
filters can be edited, and "filter_browse_cb()", which pops up a dialog
box associated with a "Filter:" button and a text entry widget attached
to that button, so that a filter can be selected or saved (although it
also supports the same editing that the "global" dialog box does).
Have "filter_dialog_cb()" connect the window in which the "Filter:"
button lives and the filter dialog box, so that:
if the window in which the "Filter:" button lives goes away, so
does the filter dialog box (as it no longer has a text widget
into which it can stuff the selected filter);
if the "Filter:" button is clicked when there's already a filter
dialog box open, we just reactivate that existing dialog box
rather than popping up a new one.
Also keep a pointer to the "global" filter dialog box, so that we also
arrange that there's only one of them (by reactivating the existing on
if "Edit:Filters" is selected when there's already a "global" filter
dialog box open).
Keep around pointers to the dialog boxes that contain the "Filter:"
buttons, so that we can arrange that there be only one of them (that was
a side-effect of an earlier attempt at fixing the problems described
above, but it's still useful for keeping multiple competing dialog boxes
from being open - there's more of that to be done).
Make the pointer to the "Open Capture File" dialog box widget static to
"file_dlg.c" - nobody outside of "file_dlg.c cares about it.
svn path=/trunk/; revision=1774
2000-04-01 12:03:42 +00:00
|
|
|
/*
|
|
|
|
* Keep a static pointer to the current "Open Capture File" window, if
|
|
|
|
* any, so that if somebody tries to do "File:Open" while there's already
|
|
|
|
* an "Open Capture File" window up, we just pop up the existing one,
|
|
|
|
* rather than creating a new one.
|
|
|
|
*/
|
2000-04-10 18:40:13 +00:00
|
|
|
static GtkWidget *file_open_w;
|
Split "filter_dialog_cb()" into "filter_dialog_cb()", which pops up a
"global" dialog box when "Edit:Filters" is selected, so that the list of
filters can be edited, and "filter_browse_cb()", which pops up a dialog
box associated with a "Filter:" button and a text entry widget attached
to that button, so that a filter can be selected or saved (although it
also supports the same editing that the "global" dialog box does).
Have "filter_dialog_cb()" connect the window in which the "Filter:"
button lives and the filter dialog box, so that:
if the window in which the "Filter:" button lives goes away, so
does the filter dialog box (as it no longer has a text widget
into which it can stuff the selected filter);
if the "Filter:" button is clicked when there's already a filter
dialog box open, we just reactivate that existing dialog box
rather than popping up a new one.
Also keep a pointer to the "global" filter dialog box, so that we also
arrange that there's only one of them (by reactivating the existing on
if "Edit:Filters" is selected when there's already a "global" filter
dialog box open).
Keep around pointers to the dialog boxes that contain the "Filter:"
buttons, so that we can arrange that there be only one of them (that was
a side-effect of an earlier attempt at fixing the problems described
above, but it's still useful for keeping multiple competing dialog boxes
from being open - there's more of that to be done).
Make the pointer to the "Open Capture File" dialog box widget static to
"file_dlg.c" - nobody outside of "file_dlg.c cares about it.
svn path=/trunk/; revision=1774
2000-04-01 12:03:42 +00:00
|
|
|
|
1999-09-01 03:04:24 +00:00
|
|
|
/* Open a file */
|
2005-08-02 04:47:15 +00:00
|
|
|
static void
|
2004-01-29 23:11:38 +00:00
|
|
|
file_open_cmd(GtkWidget *w)
|
In the process of destroying a filter editing dialog box, we get a
selection change event on the list of filters. Unfortunately, this can
happen after some other widgets in that dialog box have already been
destroyed - including some of the widgets that such a selection change
event can change.
This sometimes happened when "filter_prefs_delete()" hadn't been called,
so the mechanism we had been using, with a Boolean datum attached to the
dialog box, set in "filter_prefs_delete()" before we actually destroy
the dialog box, wasn't sufficient to keep that from happening.
Attach to the top-level window data items containing pointers to the
widgets changed when a filter is selected from the list, give each of
those widgets their own destroy callbacks, clear the pointer attached to
the top-level widget when the widget is destroyed, and don't do anything
to the widget when a filter is selected from the list if the pointer for
that widget is null, as that means the widget's been destroyed and we
*can't* do anything to it.
Not all filter editing dialogs created on behalf of a "Filter:" button
next to a text entry box should, when you click "OK", activate the text
entry box; if the text entry box is part of a dialog box with multiple
widgets, the user might not have filled in all of the items in that
dialog box, so you shouldn't activate it for them. Add a mechanism by
which, when creating a filter editing dialog box, you can specify
whether the "OK" button should just fill in the text entry box or should
fill it in and also activate it.
svn path=/trunk/; revision=2922
2001-01-21 01:45:07 +00:00
|
|
|
{
|
2008-04-06 22:25:36 +00:00
|
|
|
#if _WIN32
|
2006-02-15 11:01:57 +00:00
|
|
|
win32_open_file(GDK_WINDOW_HWND(top_level->window));
|
2008-04-06 22:25:36 +00:00
|
|
|
#else /* _WIN32 */
|
2004-06-19 10:48:06 +00:00
|
|
|
GtkWidget *main_hb, *main_vb, *filter_hbox, *filter_bt, *filter_te,
|
|
|
|
*m_resolv_cb, *n_resolv_cb, *t_resolv_cb, *prev;
|
2008-03-27 17:26:59 +00:00
|
|
|
GtkTooltips *tooltips = gtk_tooltips_new();
|
In the process of destroying a filter editing dialog box, we get a
selection change event on the list of filters. Unfortunately, this can
happen after some other widgets in that dialog box have already been
destroyed - including some of the widgets that such a selection change
event can change.
This sometimes happened when "filter_prefs_delete()" hadn't been called,
so the mechanism we had been using, with a Boolean datum attached to the
dialog box, set in "filter_prefs_delete()" before we actually destroy
the dialog box, wasn't sufficient to keep that from happening.
Attach to the top-level window data items containing pointers to the
widgets changed when a filter is selected from the list, give each of
those widgets their own destroy callbacks, clear the pointer attached to
the top-level widget when the widget is destroyed, and don't do anything
to the widget when a filter is selected from the list if the pointer for
that widget is null, as that means the widget's been destroyed and we
*can't* do anything to it.
Not all filter editing dialogs created on behalf of a "Filter:" button
next to a text entry box should, when you click "OK", activate the text
entry box; if the text entry box is part of a dialog box with multiple
widgets, the user might not have filled in all of the items in that
dialog box, so you shouldn't activate it for them. Add a mechanism by
which, when creating a filter editing dialog box, you can specify
whether the "OK" button should just fill in the text entry box or should
fill it in and also activate it.
svn path=/trunk/; revision=2922
2001-01-21 01:45:07 +00:00
|
|
|
/* No Apply button, and "OK" just sets our text widget, it doesn't
|
|
|
|
activate it (i.e., it doesn't cause us to try to open the file). */
|
2001-01-21 02:27:24 +00:00
|
|
|
static construct_args_t args = {
|
2006-05-22 07:29:40 +00:00
|
|
|
"Wireshark: Read Filter",
|
2001-01-21 02:27:24 +00:00
|
|
|
FALSE,
|
2005-12-31 17:09:27 +00:00
|
|
|
FALSE,
|
|
|
|
TRUE
|
2001-01-21 02:27:24 +00:00
|
|
|
};
|
1999-09-01 03:04:24 +00:00
|
|
|
|
2000-04-10 18:40:13 +00:00
|
|
|
if (file_open_w != NULL) {
|
Split "filter_dialog_cb()" into "filter_dialog_cb()", which pops up a
"global" dialog box when "Edit:Filters" is selected, so that the list of
filters can be edited, and "filter_browse_cb()", which pops up a dialog
box associated with a "Filter:" button and a text entry widget attached
to that button, so that a filter can be selected or saved (although it
also supports the same editing that the "global" dialog box does).
Have "filter_dialog_cb()" connect the window in which the "Filter:"
button lives and the filter dialog box, so that:
if the window in which the "Filter:" button lives goes away, so
does the filter dialog box (as it no longer has a text widget
into which it can stuff the selected filter);
if the "Filter:" button is clicked when there's already a filter
dialog box open, we just reactivate that existing dialog box
rather than popping up a new one.
Also keep a pointer to the "global" filter dialog box, so that we also
arrange that there's only one of them (by reactivating the existing on
if "Edit:Filters" is selected when there's already a "global" filter
dialog box open).
Keep around pointers to the dialog boxes that contain the "Filter:"
buttons, so that we can arrange that there be only one of them (that was
a side-effect of an earlier attempt at fixing the problems described
above, but it's still useful for keeping multiple competing dialog boxes
from being open - there's more of that to be done).
Make the pointer to the "Open Capture File" dialog box widget static to
"file_dlg.c" - nobody outside of "file_dlg.c cares about it.
svn path=/trunk/; revision=1774
2000-04-01 12:03:42 +00:00
|
|
|
/* There's already an "Open Capture File" dialog box; reactivate it. */
|
2000-04-10 18:40:13 +00:00
|
|
|
reactivate_window(file_open_w);
|
Split "filter_dialog_cb()" into "filter_dialog_cb()", which pops up a
"global" dialog box when "Edit:Filters" is selected, so that the list of
filters can be edited, and "filter_browse_cb()", which pops up a dialog
box associated with a "Filter:" button and a text entry widget attached
to that button, so that a filter can be selected or saved (although it
also supports the same editing that the "global" dialog box does).
Have "filter_dialog_cb()" connect the window in which the "Filter:"
button lives and the filter dialog box, so that:
if the window in which the "Filter:" button lives goes away, so
does the filter dialog box (as it no longer has a text widget
into which it can stuff the selected filter);
if the "Filter:" button is clicked when there's already a filter
dialog box open, we just reactivate that existing dialog box
rather than popping up a new one.
Also keep a pointer to the "global" filter dialog box, so that we also
arrange that there's only one of them (by reactivating the existing on
if "Edit:Filters" is selected when there's already a "global" filter
dialog box open).
Keep around pointers to the dialog boxes that contain the "Filter:"
buttons, so that we can arrange that there be only one of them (that was
a side-effect of an earlier attempt at fixing the problems described
above, but it's still useful for keeping multiple competing dialog boxes
from being open - there's more of that to be done).
Make the pointer to the "Open Capture File" dialog box widget static to
"file_dlg.c" - nobody outside of "file_dlg.c cares about it.
svn path=/trunk/; revision=1774
2000-04-01 12:03:42 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2006-05-22 07:29:40 +00:00
|
|
|
file_open_w = file_selection_new("Wireshark: Open Capture File",
|
2004-03-29 22:40:58 +00:00
|
|
|
FILE_SELECTION_OPEN);
|
2006-02-13 21:25:43 +00:00
|
|
|
/* it's annoying, that the file chooser dialog is already shown here,
|
2004-06-21 05:48:15 +00:00
|
|
|
so we cannot use the correct gtk_window_set_default_size() to resize it */
|
2008-04-11 20:31:05 +00:00
|
|
|
gtk_widget_set_size_request(file_open_w, DEF_WIDTH, DEF_HEIGHT);
|
2000-06-02 03:35:39 +00:00
|
|
|
|
2003-10-14 23:42:19 +00:00
|
|
|
switch (prefs.gui_fileopen_style) {
|
|
|
|
|
|
|
|
case FO_STYLE_LAST_OPENED:
|
|
|
|
/* The user has specified that we should start out in the last directory
|
|
|
|
we looked in. If we've already opened a file, use its containing
|
|
|
|
directory, if we could determine it, as the directory, otherwise
|
|
|
|
use the "last opened" directory saved in the preferences file if
|
|
|
|
there was one. */
|
2004-06-01 17:33:37 +00:00
|
|
|
/* This is now the default behaviour in file_selection_new() */
|
2003-10-14 23:42:19 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case FO_STYLE_SPECIFIED:
|
|
|
|
/* The user has specified that we should always start out in a
|
|
|
|
specified directory; if they've specified that directory,
|
|
|
|
start out by showing the files in that dir. */
|
2004-03-29 22:40:58 +00:00
|
|
|
if (prefs.gui_fileopen_dir[0] != '\0')
|
|
|
|
file_selection_set_current_folder(file_open_w, prefs.gui_fileopen_dir);
|
2003-10-14 23:42:19 +00:00
|
|
|
break;
|
2003-10-14 23:20:17 +00:00
|
|
|
}
|
2004-06-19 10:48:06 +00:00
|
|
|
|
2006-02-13 21:25:43 +00:00
|
|
|
|
2004-06-19 10:48:06 +00:00
|
|
|
main_hb = gtk_hbox_new(FALSE, 3);
|
|
|
|
file_selection_set_extra_widget(file_open_w, main_hb);
|
|
|
|
gtk_widget_show(main_hb);
|
|
|
|
|
2001-05-31 08:36:46 +00:00
|
|
|
/* Container for each row of widgets */
|
|
|
|
main_vb = gtk_vbox_new(FALSE, 3);
|
2008-06-29 15:51:43 +00:00
|
|
|
gtk_container_set_border_width(GTK_CONTAINER(main_vb), 5);
|
2004-06-19 10:48:06 +00:00
|
|
|
gtk_box_pack_start(GTK_BOX(main_hb), main_vb, FALSE, FALSE, 0);
|
2001-05-31 08:36:46 +00:00
|
|
|
gtk_widget_show(main_vb);
|
1999-09-01 03:04:24 +00:00
|
|
|
|
2004-06-19 10:48:06 +00:00
|
|
|
/* filter row */
|
1999-09-01 03:04:24 +00:00
|
|
|
filter_hbox = gtk_hbox_new(FALSE, 1);
|
2008-06-29 15:51:43 +00:00
|
|
|
gtk_container_set_border_width(GTK_CONTAINER(filter_hbox), 0);
|
2001-05-31 08:36:46 +00:00
|
|
|
gtk_box_pack_start(GTK_BOX(main_vb), filter_hbox, FALSE, FALSE, 0);
|
1999-09-01 03:04:24 +00:00
|
|
|
gtk_widget_show(filter_hbox);
|
|
|
|
|
2008-04-11 18:58:19 +00:00
|
|
|
filter_bt = gtk_button_new_from_stock(WIRESHARK_STOCK_DISPLAY_FILTER_ENTRY);
|
2008-04-11 23:00:34 +00:00
|
|
|
g_signal_connect(filter_bt, "clicked",
|
|
|
|
G_CALLBACK(display_filter_construct_cb), &args);
|
|
|
|
g_signal_connect(filter_bt, "destroy",
|
|
|
|
G_CALLBACK(filter_button_destroy_cb), NULL);
|
1999-09-01 03:04:24 +00:00
|
|
|
gtk_box_pack_start(GTK_BOX(filter_hbox), filter_bt, FALSE, TRUE, 0);
|
|
|
|
gtk_widget_show(filter_bt);
|
2008-03-27 17:26:59 +00:00
|
|
|
gtk_tooltips_set_tip(tooltips, filter_bt,
|
|
|
|
"Open the \"Display Filter\" dialog, to edit/apply filters", NULL);
|
2002-08-28 21:04:11 +00:00
|
|
|
|
1999-09-01 03:04:24 +00:00
|
|
|
filter_te = gtk_entry_new();
|
2008-04-11 17:14:11 +00:00
|
|
|
g_object_set_data(G_OBJECT(filter_bt), E_FILT_TE_PTR_KEY, filter_te);
|
1999-09-01 03:04:24 +00:00
|
|
|
gtk_box_pack_start(GTK_BOX(filter_hbox), filter_te, TRUE, TRUE, 3);
|
2008-04-11 23:00:34 +00:00
|
|
|
g_signal_connect(filter_te, "changed",
|
|
|
|
G_CALLBACK(filter_te_syntax_check_cb), NULL);
|
2008-10-19 14:12:58 +00:00
|
|
|
g_object_set_data(G_OBJECT(filter_hbox), E_FILT_AUTOCOMP_PTR_KEY, NULL);
|
|
|
|
g_signal_connect(filter_te, "key-press-event", G_CALLBACK (filter_string_te_key_pressed_cb), NULL);
|
|
|
|
g_signal_connect(file_open_w, "key-press-event", G_CALLBACK (filter_parent_dlg_key_pressed_cb), NULL);
|
2008-10-11 14:32:46 +00:00
|
|
|
colorize_filter_te_as_empty(filter_te);
|
1999-09-01 03:04:24 +00:00
|
|
|
gtk_widget_show(filter_te);
|
2008-03-27 17:26:59 +00:00
|
|
|
gtk_tooltips_set_tip(tooltips, filter_te, "Enter a display filter.", NULL);
|
1999-09-01 03:04:24 +00:00
|
|
|
|
2008-04-11 17:14:11 +00:00
|
|
|
g_object_set_data(G_OBJECT(file_open_w), E_RFILTER_TE_KEY, filter_te);
|
1999-09-01 03:04:24 +00:00
|
|
|
|
2004-06-19 10:48:06 +00:00
|
|
|
/* resolve buttons */
|
2008-04-11 19:04:34 +00:00
|
|
|
m_resolv_cb = gtk_check_button_new_with_mnemonic("Enable _MAC name resolution");
|
2004-01-07 00:10:52 +00:00
|
|
|
gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(m_resolv_cb),
|
2010-10-12 13:15:08 +00:00
|
|
|
gbl_resolv_flags & RESOLV_MAC);
|
2001-05-31 08:36:46 +00:00
|
|
|
gtk_box_pack_start(GTK_BOX(main_vb), m_resolv_cb, FALSE, FALSE, 0);
|
2008-04-11 17:14:11 +00:00
|
|
|
g_object_set_data(G_OBJECT(file_open_w),
|
2004-03-27 11:16:58 +00:00
|
|
|
E_FILE_M_RESOLVE_KEY, m_resolv_cb);
|
|
|
|
gtk_widget_show(m_resolv_cb);
|
2001-05-31 08:36:46 +00:00
|
|
|
|
2008-04-11 19:04:34 +00:00
|
|
|
n_resolv_cb = gtk_check_button_new_with_mnemonic("Enable _network name resolution");
|
2004-01-07 00:10:52 +00:00
|
|
|
gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(n_resolv_cb),
|
2010-10-12 13:15:08 +00:00
|
|
|
gbl_resolv_flags & RESOLV_NETWORK);
|
2001-05-31 08:36:46 +00:00
|
|
|
gtk_box_pack_start(GTK_BOX(main_vb), n_resolv_cb, FALSE, FALSE, 0);
|
|
|
|
gtk_widget_show(n_resolv_cb);
|
2008-04-11 17:14:11 +00:00
|
|
|
g_object_set_data(G_OBJECT(file_open_w), E_FILE_N_RESOLVE_KEY, n_resolv_cb);
|
2008-04-11 19:04:34 +00:00
|
|
|
t_resolv_cb = gtk_check_button_new_with_mnemonic("Enable _transport name resolution");
|
2004-01-07 00:10:52 +00:00
|
|
|
gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(t_resolv_cb),
|
2010-10-12 13:15:08 +00:00
|
|
|
gbl_resolv_flags & RESOLV_TRANSPORT);
|
2001-05-31 08:36:46 +00:00
|
|
|
gtk_box_pack_start(GTK_BOX(main_vb), t_resolv_cb, FALSE, FALSE, 0);
|
|
|
|
gtk_widget_show(t_resolv_cb);
|
2008-04-11 17:14:11 +00:00
|
|
|
g_object_set_data(G_OBJECT(file_open_w), E_FILE_T_RESOLVE_KEY, t_resolv_cb);
|
2004-05-26 03:49:24 +00:00
|
|
|
|
2008-04-11 23:00:34 +00:00
|
|
|
g_signal_connect(file_open_w, "destroy",
|
|
|
|
G_CALLBACK(file_open_destroy_cb), NULL);
|
2004-05-26 03:49:24 +00:00
|
|
|
|
2004-06-19 10:48:06 +00:00
|
|
|
/* preview widget */
|
|
|
|
prev = preview_new();
|
2008-04-11 17:14:11 +00:00
|
|
|
g_object_set_data(G_OBJECT(file_open_w), PREVIEW_TABLE_KEY, prev);
|
2004-06-19 10:48:06 +00:00
|
|
|
gtk_widget_show_all(prev);
|
|
|
|
gtk_box_pack_start(GTK_BOX(main_hb), prev, TRUE, TRUE, 0);
|
|
|
|
|
2008-04-11 21:20:51 +00:00
|
|
|
g_signal_connect(GTK_FILE_CHOOSER(file_open_w), "selection-changed",
|
2008-04-11 23:00:34 +00:00
|
|
|
G_CALLBACK(file_open_entry_changed), file_open_w);
|
2004-06-19 10:48:06 +00:00
|
|
|
file_open_entry_changed(file_open_w, file_open_w);
|
|
|
|
|
2008-04-11 17:14:11 +00:00
|
|
|
g_object_set_data(G_OBJECT(file_open_w), E_DFILTER_TE_KEY,
|
|
|
|
g_object_get_data(G_OBJECT(w), E_DFILTER_TE_KEY));
|
2004-03-27 11:16:58 +00:00
|
|
|
if (gtk_dialog_run(GTK_DIALOG(file_open_w)) == GTK_RESPONSE_ACCEPT)
|
|
|
|
{
|
|
|
|
file_open_ok_cb(file_open_w, file_open_w);
|
|
|
|
}
|
2004-05-26 03:49:24 +00:00
|
|
|
else window_destroy(file_open_w);
|
2008-04-06 22:25:36 +00:00
|
|
|
#endif /* _WIN32 */
|
1999-09-01 03:04:24 +00:00
|
|
|
}
|
|
|
|
|
2008-04-15 20:53:41 +00:00
|
|
|
static void file_open_answered_cb(gpointer dialog _U_, gint btn, gpointer data)
|
2004-01-29 23:11:38 +00:00
|
|
|
{
|
|
|
|
switch(btn) {
|
2004-07-13 07:15:45 +00:00
|
|
|
case(ESD_BTN_SAVE):
|
2004-01-29 23:11:38 +00:00
|
|
|
/* save file first */
|
|
|
|
file_save_as_cmd(after_save_open_dialog, data);
|
|
|
|
break;
|
2004-07-13 07:15:45 +00:00
|
|
|
case(ESD_BTN_DONT_SAVE):
|
2004-02-03 17:59:01 +00:00
|
|
|
cf_close(&cfile);
|
2004-01-29 23:11:38 +00:00
|
|
|
file_open_cmd(data);
|
|
|
|
break;
|
|
|
|
case(ESD_BTN_CANCEL):
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
g_assert_not_reached();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
file_open_cmd_cb(GtkWidget *widget, gpointer data _U_) {
|
|
|
|
gpointer dialog;
|
|
|
|
|
2004-06-20 15:57:11 +00:00
|
|
|
if((cfile.state != FILE_CLOSED) && !cfile.user_saved && prefs.gui_ask_unsaved) {
|
2009-01-04 14:21:54 +00:00
|
|
|
/* user didn't save his current file, ask him */
|
2004-07-13 07:15:45 +00:00
|
|
|
dialog = simple_dialog(ESD_TYPE_CONFIRMATION, ESD_BTNS_SAVE_DONTSAVE_CANCEL,
|
2008-04-12 01:41:53 +00:00
|
|
|
"%sSave capture file before opening a new one?%s\n\n"
|
|
|
|
"If you open a new capture file without saving, your capture data will be discarded.",
|
|
|
|
simple_dialog_primary_start(), simple_dialog_primary_end());
|
2004-01-29 23:11:38 +00:00
|
|
|
simple_dialog_set_cb(dialog, file_open_answered_cb, widget);
|
|
|
|
} else {
|
|
|
|
/* unchanged file, just open a new one */
|
|
|
|
file_open_cmd(widget);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2004-08-31 08:18:10 +00:00
|
|
|
/* user pressed "open" button */
|
1999-09-01 03:04:24 +00:00
|
|
|
static void
|
2004-03-27 11:16:58 +00:00
|
|
|
file_open_ok_cb(GtkWidget *w, gpointer fs) {
|
"gtk_entry_get_text()" returns a "const char *" - assign the result to
one.
"get_basename()" doesn't modify its argument, and its callers don't
modify the substring pointed to by the result, so make it take a "const
char *" as an argument and return a "const char *".
"find_last_pathname_separator()" doesn't modify its argument, so make it
a "const char *" - but some of its callers pass a non-"const" "char *"
and modify the result, so don't make its return value a "const char *".
And, as none of its callers are outside "filesystem.c", make it static.
In "about_folders_page_new()", have separate variables for pathnames
returned as "const char *" (which are cached by the routine that returns
them, so you can't modify them - and can't free them, so get rid of the
commented-out "g_free()" calls for them) and pathnames returned as "char
*" (which are allocated anew for each call, and can be modified, but
have to be freed).
Clean up white space.
svn path=/trunk/; revision=12881
2004-12-31 00:26:36 +00:00
|
|
|
gchar *cf_name, *s;
|
|
|
|
const gchar *rfilter;
|
|
|
|
GtkWidget *filter_te, *m_resolv_cb, *n_resolv_cb, *t_resolv_cb;
|
|
|
|
dfilter_t *rfcode = NULL;
|
|
|
|
int err;
|
1999-09-01 03:04:24 +00:00
|
|
|
|
2009-06-02 20:57:57 +00:00
|
|
|
cf_name = gtk_file_chooser_get_filename(GTK_FILE_CHOOSER(fs));
|
2008-04-11 17:14:11 +00:00
|
|
|
filter_te = g_object_get_data(G_OBJECT(w), E_RFILTER_TE_KEY);
|
"gtk_entry_get_text()" returns a "const char *" - assign the result to
one.
"get_basename()" doesn't modify its argument, and its callers don't
modify the substring pointed to by the result, so make it take a "const
char *" as an argument and return a "const char *".
"find_last_pathname_separator()" doesn't modify its argument, so make it
a "const char *" - but some of its callers pass a non-"const" "char *"
and modify the result, so don't make its return value a "const char *".
And, as none of its callers are outside "filesystem.c", make it static.
In "about_folders_page_new()", have separate variables for pathnames
returned as "const char *" (which are cached by the routine that returns
them, so you can't modify them - and can't free them, so get rid of the
commented-out "g_free()" calls for them) and pathnames returned as "char
*" (which are allocated anew for each call, and can be modified, but
have to be freed).
Clean up white space.
svn path=/trunk/; revision=12881
2004-12-31 00:26:36 +00:00
|
|
|
rfilter = gtk_entry_get_text(GTK_ENTRY(filter_te));
|
2001-02-01 20:21:25 +00:00
|
|
|
if (!dfilter_compile(rfilter, &rfcode)) {
|
2004-02-11 00:55:28 +00:00
|
|
|
bad_dfilter_alert_box(rfilter);
|
2002-09-09 20:39:01 +00:00
|
|
|
g_free(cf_name);
|
1999-10-12 05:01:07 +00:00
|
|
|
return;
|
1999-09-01 03:04:24 +00:00
|
|
|
}
|
|
|
|
|
2000-01-01 04:28:45 +00:00
|
|
|
/* Perhaps the user specified a directory instead of a file.
|
2000-07-31 04:53:40 +00:00
|
|
|
Check whether they did. */
|
|
|
|
if (test_for_directory(cf_name) == EISDIR) {
|
|
|
|
/* It's a directory - set the file selection box to display that
|
|
|
|
directory, don't try to open the directory as a capture file. */
|
2004-06-01 17:33:37 +00:00
|
|
|
set_last_open_dir(cf_name);
|
2002-09-09 20:39:01 +00:00
|
|
|
g_free(cf_name);
|
2004-06-01 17:33:37 +00:00
|
|
|
file_selection_set_current_folder(fs, get_last_open_dir());
|
2000-01-01 04:28:45 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
1999-09-01 03:04:24 +00:00
|
|
|
/* Try to open the capture file. */
|
2005-02-04 18:44:44 +00:00
|
|
|
if (cf_open(&cfile, cf_name, FALSE, &err) != CF_OK) {
|
1999-09-01 03:04:24 +00:00
|
|
|
/* We couldn't open it; don't dismiss the open dialog box,
|
|
|
|
just leave it around so that the user can, after they
|
|
|
|
dismiss the alert box popped up for the open error,
|
|
|
|
try again. */
|
|
|
|
if (rfcode != NULL)
|
2001-02-01 20:21:25 +00:00
|
|
|
dfilter_free(rfcode);
|
2000-01-01 04:28:45 +00:00
|
|
|
g_free(cf_name);
|
2008-04-27 07:01:58 +00:00
|
|
|
|
2008-01-26 16:50:08 +00:00
|
|
|
/* XXX - as we cannot start a new event loop (using gtk_dialog_run()),
|
|
|
|
* as this will prevent the user from closing the now existing error
|
2008-03-27 17:26:59 +00:00
|
|
|
* message, simply close the dialog (this is the best we can do here). */
|
2008-01-26 16:50:08 +00:00
|
|
|
if (file_open_w)
|
|
|
|
window_destroy(file_open_w);
|
2008-04-27 07:01:58 +00:00
|
|
|
|
1999-09-01 03:04:24 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2003-09-15 22:48:42 +00:00
|
|
|
/* Attach the new read filter to "cf" ("cf_open()" succeeded, so
|
1999-09-01 03:04:24 +00:00
|
|
|
it closed the previous capture file, and thus destroyed any
|
|
|
|
previous read filter attached to "cf"). */
|
2000-06-27 04:36:03 +00:00
|
|
|
cfile.rfcode = rfcode;
|
1999-09-01 03:04:24 +00:00
|
|
|
|
2000-06-02 03:35:39 +00:00
|
|
|
/* Set the global resolving variable */
|
2010-10-12 13:15:08 +00:00
|
|
|
gbl_resolv_flags = prefs.name_resolve;
|
2008-04-11 17:14:11 +00:00
|
|
|
m_resolv_cb = g_object_get_data(G_OBJECT(w), E_FILE_M_RESOLVE_KEY);
|
2004-10-22 07:07:08 +00:00
|
|
|
if (gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON (m_resolv_cb)))
|
2010-10-12 13:15:08 +00:00
|
|
|
gbl_resolv_flags |= RESOLV_MAC;
|
2004-10-22 07:07:08 +00:00
|
|
|
else
|
2010-10-12 13:15:08 +00:00
|
|
|
gbl_resolv_flags &= ~RESOLV_MAC;
|
2008-04-11 17:14:11 +00:00
|
|
|
n_resolv_cb = g_object_get_data(G_OBJECT(w), E_FILE_N_RESOLVE_KEY);
|
2004-10-22 07:07:08 +00:00
|
|
|
if (gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON (n_resolv_cb)))
|
2010-10-12 13:15:08 +00:00
|
|
|
gbl_resolv_flags |= RESOLV_NETWORK;
|
2004-10-22 07:07:08 +00:00
|
|
|
else
|
2010-10-12 13:15:08 +00:00
|
|
|
gbl_resolv_flags &= ~RESOLV_NETWORK;
|
2008-04-11 17:14:11 +00:00
|
|
|
t_resolv_cb = g_object_get_data(G_OBJECT(w), E_FILE_T_RESOLVE_KEY);
|
2004-10-22 07:07:08 +00:00
|
|
|
if (gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON (t_resolv_cb)))
|
2010-10-12 13:15:08 +00:00
|
|
|
gbl_resolv_flags |= RESOLV_TRANSPORT;
|
2004-10-22 07:07:08 +00:00
|
|
|
else
|
2010-10-12 13:15:08 +00:00
|
|
|
gbl_resolv_flags &= ~RESOLV_TRANSPORT;
|
2000-06-02 03:35:39 +00:00
|
|
|
|
1999-09-01 03:04:24 +00:00
|
|
|
/* We've crossed the Rubicon; get rid of the file selection box. */
|
2004-05-26 03:49:24 +00:00
|
|
|
window_destroy(GTK_WIDGET (fs));
|
1999-09-01 03:04:24 +00:00
|
|
|
|
2009-12-14 22:05:29 +00:00
|
|
|
switch (cf_read(&cfile, FALSE)) {
|
Add routines to Wiretap to allow a client of Wiretap to get:
a pointer to the "wtap_pkthdr" structure for an open capture
file;
a pointer to the "wtap_pseudo_header" union for an open capture
file;
a pointer to the packet buffer for an open capture file;
so that a program using "wtap_read()" in a loop can get at those items.
Keep, in a "capture_file" structure, an indicator of whether:
no file is open;
a file is open, and being read;
a file is open, and is being read, but the user tried to quit
out of reading the file (e.g., by doing "File/Quit");
a file is open, and has been completely read.
Abort if we try to close a capture that's being read if the user hasn't
tried to quit out of the read.
Have "File/Quit" check if a file is being read; if so, just set the
state indicator to "user tried to quit out of it", so that the code
reading the file can do what's appropriate to clean up, rather than
closing the file out from under that code and causing crashes.
Have "read_cap_file()" read the capture file with a loop using
"wtap_read()", rather than by using "wtap_loop()"; have it check after
reading each packet whether the user tried to abort the read and, if so,
close the capture and return an indication that the read was aborted by
the user. Otherwise, return an indication of whether the read
completely succeeded or failed in the middle (and, if it failed, return
the error code through a pointer).
Have "continue_tail_cap_file()" read the capture file with a loop using
"wtap_read()", rather than by using "wtap_loop()"; have it check after
reading each packet whether the user tried to abort the read and, if so,
quit the loop, and after the loop finishes (even if it read no packets),
return an indication that the read was aborted by the user if that
happened. Otherwise, return an indication of whether the read
completely succeeded or failed in the middle (and, if it failed, return
the error code through a pointer).
Have "finish_tail_cap_file()" read the capture file with a loop using
"wtap_read()", rather than by using "wtap_loop()"; have it check after
reading each packet whether the user tried to abort the read and, if so,
quit the loop, and after the loop finishes (even if it read no packets),
close the capture and return an indication that the read was aborted by
the user if that happened. Otherwise, return an indication of whether
the read completely succeeded or failed in the middle (and, if it
failed, return the error code through a pointer).
Have their callers check whether the read was aborted or not and, if it
was, bail out in the appropriate fashion (exit if it's reading a file
specified by "-r" on the command line; exit the main loop if it's
reading a file specified with File->Open; kill the capture child if it's
"continue_tail_cap_file()"; exit the main loop if it's
"finish_tail_cap_file()".
svn path=/trunk/; revision=2095
2000-06-27 07:13:42 +00:00
|
|
|
|
2005-02-05 12:50:47 +00:00
|
|
|
case CF_READ_OK:
|
|
|
|
case CF_READ_ERROR:
|
Add routines to Wiretap to allow a client of Wiretap to get:
a pointer to the "wtap_pkthdr" structure for an open capture
file;
a pointer to the "wtap_pseudo_header" union for an open capture
file;
a pointer to the packet buffer for an open capture file;
so that a program using "wtap_read()" in a loop can get at those items.
Keep, in a "capture_file" structure, an indicator of whether:
no file is open;
a file is open, and being read;
a file is open, and is being read, but the user tried to quit
out of reading the file (e.g., by doing "File/Quit");
a file is open, and has been completely read.
Abort if we try to close a capture that's being read if the user hasn't
tried to quit out of the read.
Have "File/Quit" check if a file is being read; if so, just set the
state indicator to "user tried to quit out of it", so that the code
reading the file can do what's appropriate to clean up, rather than
closing the file out from under that code and causing crashes.
Have "read_cap_file()" read the capture file with a loop using
"wtap_read()", rather than by using "wtap_loop()"; have it check after
reading each packet whether the user tried to abort the read and, if so,
close the capture and return an indication that the read was aborted by
the user. Otherwise, return an indication of whether the read
completely succeeded or failed in the middle (and, if it failed, return
the error code through a pointer).
Have "continue_tail_cap_file()" read the capture file with a loop using
"wtap_read()", rather than by using "wtap_loop()"; have it check after
reading each packet whether the user tried to abort the read and, if so,
quit the loop, and after the loop finishes (even if it read no packets),
return an indication that the read was aborted by the user if that
happened. Otherwise, return an indication of whether the read
completely succeeded or failed in the middle (and, if it failed, return
the error code through a pointer).
Have "finish_tail_cap_file()" read the capture file with a loop using
"wtap_read()", rather than by using "wtap_loop()"; have it check after
reading each packet whether the user tried to abort the read and, if so,
quit the loop, and after the loop finishes (even if it read no packets),
close the capture and return an indication that the read was aborted by
the user if that happened. Otherwise, return an indication of whether
the read completely succeeded or failed in the middle (and, if it
failed, return the error code through a pointer).
Have their callers check whether the read was aborted or not and, if it
was, bail out in the appropriate fashion (exit if it's reading a file
specified by "-r" on the command line; exit the main loop if it's
reading a file specified with File->Open; kill the capture child if it's
"continue_tail_cap_file()"; exit the main loop if it's
"finish_tail_cap_file()".
svn path=/trunk/; revision=2095
2000-06-27 07:13:42 +00:00
|
|
|
/* Just because we got an error, that doesn't mean we were unable
|
|
|
|
to read any of the file; we handle what we could get from the
|
|
|
|
file. */
|
|
|
|
break;
|
|
|
|
|
2005-02-05 12:50:47 +00:00
|
|
|
case CF_READ_ABORTED:
|
2000-07-03 09:34:27 +00:00
|
|
|
/* The user bailed out of re-reading the capture file; the
|
|
|
|
capture file has been closed - just free the capture file name
|
|
|
|
string and return (without changing the last containing
|
|
|
|
directory). */
|
|
|
|
g_free(cf_name);
|
Add routines to Wiretap to allow a client of Wiretap to get:
a pointer to the "wtap_pkthdr" structure for an open capture
file;
a pointer to the "wtap_pseudo_header" union for an open capture
file;
a pointer to the packet buffer for an open capture file;
so that a program using "wtap_read()" in a loop can get at those items.
Keep, in a "capture_file" structure, an indicator of whether:
no file is open;
a file is open, and being read;
a file is open, and is being read, but the user tried to quit
out of reading the file (e.g., by doing "File/Quit");
a file is open, and has been completely read.
Abort if we try to close a capture that's being read if the user hasn't
tried to quit out of the read.
Have "File/Quit" check if a file is being read; if so, just set the
state indicator to "user tried to quit out of it", so that the code
reading the file can do what's appropriate to clean up, rather than
closing the file out from under that code and causing crashes.
Have "read_cap_file()" read the capture file with a loop using
"wtap_read()", rather than by using "wtap_loop()"; have it check after
reading each packet whether the user tried to abort the read and, if so,
close the capture and return an indication that the read was aborted by
the user. Otherwise, return an indication of whether the read
completely succeeded or failed in the middle (and, if it failed, return
the error code through a pointer).
Have "continue_tail_cap_file()" read the capture file with a loop using
"wtap_read()", rather than by using "wtap_loop()"; have it check after
reading each packet whether the user tried to abort the read and, if so,
quit the loop, and after the loop finishes (even if it read no packets),
return an indication that the read was aborted by the user if that
happened. Otherwise, return an indication of whether the read
completely succeeded or failed in the middle (and, if it failed, return
the error code through a pointer).
Have "finish_tail_cap_file()" read the capture file with a loop using
"wtap_read()", rather than by using "wtap_loop()"; have it check after
reading each packet whether the user tried to abort the read and, if so,
quit the loop, and after the loop finishes (even if it read no packets),
close the capture and return an indication that the read was aborted by
the user if that happened. Otherwise, return an indication of whether
the read completely succeeded or failed in the middle (and, if it
failed, return the error code through a pointer).
Have their callers check whether the read was aborted or not and, if it
was, bail out in the appropriate fashion (exit if it's reading a file
specified by "-r" on the command line; exit the main loop if it's
reading a file specified with File->Open; kill the capture child if it's
"continue_tail_cap_file()"; exit the main loop if it's
"finish_tail_cap_file()".
svn path=/trunk/; revision=2095
2000-06-27 07:13:42 +00:00
|
|
|
return;
|
|
|
|
}
|
2002-08-28 21:04:11 +00:00
|
|
|
|
2000-01-25 05:48:47 +00:00
|
|
|
/* Save the name of the containing directory specified in the path name,
|
|
|
|
if any; we can write over cf_name, which is a good thing, given that
|
|
|
|
"get_dirname()" does write over its argument. */
|
|
|
|
s = get_dirname(cf_name);
|
2001-04-09 22:35:23 +00:00
|
|
|
set_last_open_dir(s);
|
2009-06-30 18:05:04 +00:00
|
|
|
#ifndef NEW_PACKET_LIST
|
2003-07-18 20:55:11 +00:00
|
|
|
gtk_widget_grab_focus(packet_list);
|
2009-06-30 18:05:04 +00:00
|
|
|
#endif
|
2000-06-02 03:35:39 +00:00
|
|
|
|
1999-09-01 03:04:24 +00:00
|
|
|
g_free(cf_name);
|
|
|
|
}
|
|
|
|
|
Split "filter_dialog_cb()" into "filter_dialog_cb()", which pops up a
"global" dialog box when "Edit:Filters" is selected, so that the list of
filters can be edited, and "filter_browse_cb()", which pops up a dialog
box associated with a "Filter:" button and a text entry widget attached
to that button, so that a filter can be selected or saved (although it
also supports the same editing that the "global" dialog box does).
Have "filter_dialog_cb()" connect the window in which the "Filter:"
button lives and the filter dialog box, so that:
if the window in which the "Filter:" button lives goes away, so
does the filter dialog box (as it no longer has a text widget
into which it can stuff the selected filter);
if the "Filter:" button is clicked when there's already a filter
dialog box open, we just reactivate that existing dialog box
rather than popping up a new one.
Also keep a pointer to the "global" filter dialog box, so that we also
arrange that there's only one of them (by reactivating the existing on
if "Edit:Filters" is selected when there's already a "global" filter
dialog box open).
Keep around pointers to the dialog boxes that contain the "Filter:"
buttons, so that we can arrange that there be only one of them (that was
a side-effect of an earlier attempt at fixing the problems described
above, but it's still useful for keeping multiple competing dialog boxes
from being open - there's more of that to be done).
Make the pointer to the "Open Capture File" dialog box widget static to
"file_dlg.c" - nobody outside of "file_dlg.c cares about it.
svn path=/trunk/; revision=1774
2000-04-01 12:03:42 +00:00
|
|
|
static void
|
2003-01-15 05:20:19 +00:00
|
|
|
file_open_destroy_cb(GtkWidget *win _U_, gpointer user_data _U_)
|
Split "filter_dialog_cb()" into "filter_dialog_cb()", which pops up a
"global" dialog box when "Edit:Filters" is selected, so that the list of
filters can be edited, and "filter_browse_cb()", which pops up a dialog
box associated with a "Filter:" button and a text entry widget attached
to that button, so that a filter can be selected or saved (although it
also supports the same editing that the "global" dialog box does).
Have "filter_dialog_cb()" connect the window in which the "Filter:"
button lives and the filter dialog box, so that:
if the window in which the "Filter:" button lives goes away, so
does the filter dialog box (as it no longer has a text widget
into which it can stuff the selected filter);
if the "Filter:" button is clicked when there's already a filter
dialog box open, we just reactivate that existing dialog box
rather than popping up a new one.
Also keep a pointer to the "global" filter dialog box, so that we also
arrange that there's only one of them (by reactivating the existing on
if "Edit:Filters" is selected when there's already a "global" filter
dialog box open).
Keep around pointers to the dialog boxes that contain the "Filter:"
buttons, so that we can arrange that there be only one of them (that was
a side-effect of an earlier attempt at fixing the problems described
above, but it's still useful for keeping multiple competing dialog boxes
from being open - there's more of that to be done).
Make the pointer to the "Open Capture File" dialog box widget static to
"file_dlg.c" - nobody outside of "file_dlg.c cares about it.
svn path=/trunk/; revision=1774
2000-04-01 12:03:42 +00:00
|
|
|
{
|
|
|
|
/* Note that we no longer have a "Open Capture File" dialog box. */
|
2000-04-10 18:40:13 +00:00
|
|
|
file_open_w = NULL;
|
Split "filter_dialog_cb()" into "filter_dialog_cb()", which pops up a
"global" dialog box when "Edit:Filters" is selected, so that the list of
filters can be edited, and "filter_browse_cb()", which pops up a dialog
box associated with a "Filter:" button and a text entry widget attached
to that button, so that a filter can be selected or saved (although it
also supports the same editing that the "global" dialog box does).
Have "filter_dialog_cb()" connect the window in which the "Filter:"
button lives and the filter dialog box, so that:
if the window in which the "Filter:" button lives goes away, so
does the filter dialog box (as it no longer has a text widget
into which it can stuff the selected filter);
if the "Filter:" button is clicked when there's already a filter
dialog box open, we just reactivate that existing dialog box
rather than popping up a new one.
Also keep a pointer to the "global" filter dialog box, so that we also
arrange that there's only one of them (by reactivating the existing on
if "Edit:Filters" is selected when there's already a "global" filter
dialog box open).
Keep around pointers to the dialog boxes that contain the "Filter:"
buttons, so that we can arrange that there be only one of them (that was
a side-effect of an earlier attempt at fixing the problems described
above, but it's still useful for keeping multiple competing dialog boxes
from being open - there's more of that to be done).
Make the pointer to the "Open Capture File" dialog box widget static to
"file_dlg.c" - nobody outside of "file_dlg.c cares about it.
svn path=/trunk/; revision=1774
2000-04-01 12:03:42 +00:00
|
|
|
}
|
|
|
|
|
2004-06-17 21:53:26 +00:00
|
|
|
/*
|
2004-10-17 02:53:26 +00:00
|
|
|
* Keep a static pointer to the current "Merge Capture File" window, if
|
2004-06-17 21:53:26 +00:00
|
|
|
* any, so that if somebody tries to do "File:Merge" while there's already
|
|
|
|
* an "Merge Capture File" window up, we just pop up the existing one,
|
|
|
|
* rather than creating a new one.
|
|
|
|
*/
|
|
|
|
static GtkWidget *file_merge_w;
|
|
|
|
|
|
|
|
/* Merge existing with another file */
|
2005-08-02 04:47:15 +00:00
|
|
|
static void
|
2004-06-17 21:53:26 +00:00
|
|
|
file_merge_cmd(GtkWidget *w)
|
|
|
|
{
|
2008-04-06 22:25:36 +00:00
|
|
|
#if _WIN32
|
2006-02-15 11:01:57 +00:00
|
|
|
win32_merge_file(GDK_WINDOW_HWND(top_level->window));
|
2009-06-30 18:05:04 +00:00
|
|
|
#ifdef NEW_PACKET_LIST
|
|
|
|
new_packet_list_freeze();
|
|
|
|
new_packet_list_thaw();
|
|
|
|
#else
|
2006-02-16 15:53:48 +00:00
|
|
|
packet_list_freeze();
|
|
|
|
packet_list_thaw();
|
2009-06-30 18:05:04 +00:00
|
|
|
#endif /* NEW_PACKET_LIST */
|
2008-04-06 22:25:36 +00:00
|
|
|
#else /* _WIN32 */
|
2010-02-22 18:50:56 +00:00
|
|
|
GtkWidget *main_hb, *main_vb, *ft_hb, *ft_lb, *ft_combo_box, *filter_hbox,
|
2004-10-17 02:53:26 +00:00
|
|
|
*filter_bt, *filter_te, *prepend_rb, *chrono_rb,
|
|
|
|
*append_rb, *prev;
|
2004-06-18 05:58:30 +00:00
|
|
|
GtkTooltips *tooltips = gtk_tooltips_new();
|
2010-03-21 19:26:32 +00:00
|
|
|
int combo_box_item_to_select;
|
2004-06-17 21:53:26 +00:00
|
|
|
/* No Apply button, and "OK" just sets our text widget, it doesn't
|
|
|
|
activate it (i.e., it doesn't cause us to try to open the file). */
|
|
|
|
static construct_args_t args = {
|
2006-05-22 07:29:40 +00:00
|
|
|
"Wireshark: Read Filter",
|
2004-06-17 21:53:26 +00:00
|
|
|
FALSE,
|
2005-12-31 17:09:27 +00:00
|
|
|
FALSE,
|
|
|
|
TRUE
|
2004-06-17 21:53:26 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
if (file_merge_w != NULL) {
|
|
|
|
/* There's already an "Merge Capture File" dialog box; reactivate it. */
|
|
|
|
reactivate_window(file_merge_w);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2004-10-17 03:11:31 +00:00
|
|
|
/* Default to saving all packets, in the file's current format. */
|
|
|
|
|
2006-05-22 07:29:40 +00:00
|
|
|
file_merge_w = file_selection_new("Wireshark: Merge with Capture File",
|
2004-06-17 21:53:26 +00:00
|
|
|
FILE_SELECTION_OPEN);
|
2006-02-13 21:25:43 +00:00
|
|
|
/* it's annoying, that the file chooser dialog is already shown here,
|
2004-06-21 05:48:15 +00:00
|
|
|
so we cannot use the correct gtk_window_set_default_size() to resize it */
|
2008-04-11 20:31:05 +00:00
|
|
|
gtk_widget_set_size_request(file_merge_w, DEF_WIDTH, DEF_HEIGHT);
|
2004-06-17 21:53:26 +00:00
|
|
|
|
|
|
|
switch (prefs.gui_fileopen_style) {
|
|
|
|
|
|
|
|
case FO_STYLE_LAST_OPENED:
|
|
|
|
/* The user has specified that we should start out in the last directory
|
|
|
|
we looked in. If we've already opened a file, use its containing
|
|
|
|
directory, if we could determine it, as the directory, otherwise
|
|
|
|
use the "last opened" directory saved in the preferences file if
|
|
|
|
there was one. */
|
|
|
|
/* This is now the default behaviour in file_selection_new() */
|
|
|
|
break;
|
|
|
|
|
|
|
|
case FO_STYLE_SPECIFIED:
|
|
|
|
/* The user has specified that we should always start out in a
|
|
|
|
specified directory; if they've specified that directory,
|
|
|
|
start out by showing the files in that dir. */
|
|
|
|
if (prefs.gui_fileopen_dir[0] != '\0')
|
|
|
|
file_selection_set_current_folder(file_merge_w, prefs.gui_fileopen_dir);
|
|
|
|
break;
|
|
|
|
}
|
2006-02-13 21:25:43 +00:00
|
|
|
|
2004-06-19 10:48:06 +00:00
|
|
|
main_hb = gtk_hbox_new(FALSE, 3);
|
|
|
|
file_selection_set_extra_widget(file_merge_w, main_hb);
|
|
|
|
gtk_widget_show(main_hb);
|
|
|
|
|
2004-06-17 21:53:26 +00:00
|
|
|
/* Container for each row of widgets */
|
|
|
|
main_vb = gtk_vbox_new(FALSE, 3);
|
2008-06-29 15:51:43 +00:00
|
|
|
gtk_container_set_border_width(GTK_CONTAINER(main_vb), 5);
|
2004-06-19 10:48:06 +00:00
|
|
|
gtk_box_pack_start(GTK_BOX(main_hb), main_vb, FALSE, FALSE, 0);
|
2004-06-17 21:53:26 +00:00
|
|
|
gtk_widget_show(main_vb);
|
|
|
|
|
2004-10-17 02:53:26 +00:00
|
|
|
/* File type row */
|
|
|
|
range_tb = NULL;
|
|
|
|
ft_hb = gtk_hbox_new(FALSE, 3);
|
|
|
|
gtk_container_add(GTK_CONTAINER(main_vb), ft_hb);
|
|
|
|
gtk_widget_show(ft_hb);
|
|
|
|
|
|
|
|
ft_lb = gtk_label_new("Merged output file type:");
|
|
|
|
gtk_box_pack_start(GTK_BOX(ft_hb), ft_lb, FALSE, FALSE, 0);
|
|
|
|
gtk_widget_show(ft_lb);
|
|
|
|
|
2010-02-22 18:50:56 +00:00
|
|
|
ft_combo_box = ws_combo_box_new_text_and_pointer();
|
2004-10-17 02:53:26 +00:00
|
|
|
|
|
|
|
/* Generate the list of file types we can save. */
|
2010-03-21 19:26:32 +00:00
|
|
|
combo_box_item_to_select = set_file_type_list(ft_combo_box, cfile.cd_t);
|
2010-02-22 18:50:56 +00:00
|
|
|
gtk_box_pack_start(GTK_BOX(ft_hb), ft_combo_box, FALSE, FALSE, 0);
|
|
|
|
gtk_widget_show(ft_combo_box);
|
2010-03-21 19:26:32 +00:00
|
|
|
g_object_set_data(G_OBJECT(file_merge_w), E_FILE_TYPE_COMBO_BOX_KEY, ft_combo_box);
|
|
|
|
ws_combo_box_set_active(GTK_COMBO_BOX(ft_combo_box), combo_box_item_to_select); /* No callback */
|
2004-10-17 02:53:26 +00:00
|
|
|
|
2004-06-17 21:53:26 +00:00
|
|
|
filter_hbox = gtk_hbox_new(FALSE, 1);
|
2008-06-29 15:51:43 +00:00
|
|
|
gtk_container_set_border_width(GTK_CONTAINER(filter_hbox), 0);
|
2004-06-17 21:53:26 +00:00
|
|
|
gtk_box_pack_start(GTK_BOX(main_vb), filter_hbox, FALSE, FALSE, 0);
|
|
|
|
gtk_widget_show(filter_hbox);
|
|
|
|
|
2008-04-11 18:58:19 +00:00
|
|
|
filter_bt = gtk_button_new_from_stock(WIRESHARK_STOCK_DISPLAY_FILTER_ENTRY);
|
2008-04-11 23:00:34 +00:00
|
|
|
g_signal_connect(filter_bt, "clicked",
|
|
|
|
G_CALLBACK(display_filter_construct_cb), &args);
|
|
|
|
g_signal_connect(filter_bt, "destroy",
|
|
|
|
G_CALLBACK(filter_button_destroy_cb), NULL);
|
2004-06-17 21:53:26 +00:00
|
|
|
gtk_box_pack_start(GTK_BOX(filter_hbox), filter_bt, FALSE, TRUE, 0);
|
|
|
|
gtk_widget_show(filter_bt);
|
2008-03-27 17:26:59 +00:00
|
|
|
gtk_tooltips_set_tip(tooltips, filter_bt,
|
|
|
|
"Open the \"Display Filter\" dialog, to edit/apply filters", NULL);
|
2004-06-17 21:53:26 +00:00
|
|
|
|
|
|
|
filter_te = gtk_entry_new();
|
2008-04-11 17:14:11 +00:00
|
|
|
g_object_set_data(G_OBJECT(filter_bt), E_FILT_TE_PTR_KEY, filter_te);
|
2004-06-17 21:53:26 +00:00
|
|
|
gtk_box_pack_start(GTK_BOX(filter_hbox), filter_te, TRUE, TRUE, 3);
|
2008-04-11 23:00:34 +00:00
|
|
|
g_signal_connect(filter_te, "changed",
|
|
|
|
G_CALLBACK(filter_te_syntax_check_cb), NULL);
|
2008-10-19 14:12:58 +00:00
|
|
|
g_object_set_data(G_OBJECT(filter_hbox), E_FILT_AUTOCOMP_PTR_KEY, NULL);
|
|
|
|
g_signal_connect(filter_te, "key-press-event", G_CALLBACK (filter_string_te_key_pressed_cb), NULL);
|
|
|
|
g_signal_connect(file_merge_w, "key-press-event", G_CALLBACK (filter_parent_dlg_key_pressed_cb), NULL);
|
2008-10-11 14:32:46 +00:00
|
|
|
colorize_filter_te_as_empty(filter_te);
|
2004-06-17 21:53:26 +00:00
|
|
|
gtk_widget_show(filter_te);
|
2008-03-27 17:26:59 +00:00
|
|
|
gtk_tooltips_set_tip(tooltips, filter_te, "Enter a display filter.", NULL);
|
2004-06-17 21:53:26 +00:00
|
|
|
|
2008-04-11 17:14:11 +00:00
|
|
|
g_object_set_data(G_OBJECT(file_merge_w), E_RFILTER_TE_KEY, filter_te);
|
2004-06-17 21:53:26 +00:00
|
|
|
|
2008-04-11 19:26:22 +00:00
|
|
|
prepend_rb = gtk_radio_button_new_with_mnemonic_from_widget(NULL,
|
|
|
|
"Prepend packets to existing file");
|
2006-02-13 21:25:43 +00:00
|
|
|
gtk_tooltips_set_tip(tooltips, prepend_rb,
|
2004-06-18 05:58:30 +00:00
|
|
|
"The resulting file contains the packets from the selected, followed by the packets from the currently loaded file,"
|
|
|
|
" the packet timestamps will be ignored.", NULL);
|
2004-06-17 21:53:26 +00:00
|
|
|
gtk_box_pack_start(GTK_BOX(main_vb), prepend_rb, FALSE, FALSE, 0);
|
2008-04-11 17:14:11 +00:00
|
|
|
g_object_set_data(G_OBJECT(file_merge_w),
|
2004-06-17 21:53:26 +00:00
|
|
|
E_MERGE_PREPEND_KEY, prepend_rb);
|
|
|
|
gtk_widget_show(prepend_rb);
|
|
|
|
|
2008-04-11 19:26:22 +00:00
|
|
|
chrono_rb = gtk_radio_button_new_with_mnemonic_from_widget(GTK_RADIO_BUTTON(prepend_rb), "Merge packets chronologically");
|
2006-02-13 21:25:43 +00:00
|
|
|
gtk_tooltips_set_tip(tooltips, chrono_rb,
|
2004-06-18 05:58:30 +00:00
|
|
|
"The resulting file contains all the packets from the currently loaded and the selected file,"
|
|
|
|
" sorted by the packet timestamps.", NULL);
|
2004-06-17 21:53:26 +00:00
|
|
|
gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(chrono_rb), TRUE);
|
|
|
|
gtk_box_pack_start(GTK_BOX(main_vb), chrono_rb, FALSE, FALSE, 0);
|
|
|
|
gtk_widget_show(chrono_rb);
|
2008-04-11 17:14:11 +00:00
|
|
|
g_object_set_data(G_OBJECT(file_merge_w), E_MERGE_CHRONO_KEY, chrono_rb);
|
2004-06-17 21:53:26 +00:00
|
|
|
|
2008-04-11 19:26:22 +00:00
|
|
|
append_rb = gtk_radio_button_new_with_mnemonic_from_widget(GTK_RADIO_BUTTON(prepend_rb), "Append packets to existing file");
|
2006-02-13 21:25:43 +00:00
|
|
|
gtk_tooltips_set_tip(tooltips, append_rb,
|
2004-06-18 05:58:30 +00:00
|
|
|
"The resulting file contains the packets from the currently loaded, followed by the packets from the selected file,"
|
|
|
|
" the packet timestamps will be ignored.", NULL);
|
2004-06-17 21:53:26 +00:00
|
|
|
gtk_box_pack_start(GTK_BOX(main_vb), append_rb, FALSE, FALSE, 0);
|
|
|
|
gtk_widget_show(append_rb);
|
2008-04-11 17:14:11 +00:00
|
|
|
g_object_set_data(G_OBJECT(file_merge_w), E_MERGE_APPEND_KEY, append_rb);
|
2004-06-17 21:53:26 +00:00
|
|
|
|
2008-04-11 23:00:34 +00:00
|
|
|
g_signal_connect(file_merge_w, "destroy",
|
|
|
|
G_CALLBACK(file_merge_destroy_cb), NULL);
|
2004-06-17 21:53:26 +00:00
|
|
|
|
2004-06-19 10:48:06 +00:00
|
|
|
/* preview widget */
|
|
|
|
prev = preview_new();
|
2008-04-11 17:14:11 +00:00
|
|
|
g_object_set_data(G_OBJECT(file_merge_w), PREVIEW_TABLE_KEY, prev);
|
2004-06-19 10:48:06 +00:00
|
|
|
gtk_widget_show_all(prev);
|
|
|
|
gtk_box_pack_start(GTK_BOX(main_hb), prev, TRUE, TRUE, 0);
|
|
|
|
|
2008-04-11 21:20:51 +00:00
|
|
|
g_signal_connect(GTK_FILE_CHOOSER(file_merge_w), "selection-changed",
|
2008-04-11 23:00:34 +00:00
|
|
|
G_CALLBACK(file_open_entry_changed), file_merge_w);
|
2004-06-19 10:48:06 +00:00
|
|
|
file_open_entry_changed(file_merge_w, file_merge_w);
|
|
|
|
|
2008-04-11 17:14:11 +00:00
|
|
|
g_object_set_data(G_OBJECT(file_merge_w), E_DFILTER_TE_KEY,
|
|
|
|
g_object_get_data(G_OBJECT(w), E_DFILTER_TE_KEY));
|
2004-06-17 21:53:26 +00:00
|
|
|
if (gtk_dialog_run(GTK_DIALOG(file_merge_w)) == GTK_RESPONSE_ACCEPT)
|
|
|
|
{
|
|
|
|
file_merge_ok_cb(file_merge_w, file_merge_w);
|
|
|
|
}
|
|
|
|
else window_destroy(file_merge_w);
|
2008-04-06 22:25:36 +00:00
|
|
|
#endif /* _WIN32 */
|
2004-06-17 21:53:26 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void file_merge_answered_cb(gpointer dialog _U_, gint btn, gpointer data _U_)
|
|
|
|
{
|
|
|
|
switch(btn) {
|
2004-06-18 07:41:21 +00:00
|
|
|
case(ESD_BTN_OK):
|
2004-06-17 21:53:26 +00:00
|
|
|
/* save file first */
|
|
|
|
file_save_as_cmd(after_save_merge_dialog, data);
|
|
|
|
break;
|
2004-06-18 07:41:21 +00:00
|
|
|
case(ESD_BTN_CANCEL):
|
2004-06-17 21:53:26 +00:00
|
|
|
break;
|
|
|
|
default:
|
|
|
|
g_assert_not_reached();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
file_merge_cmd_cb(GtkWidget *widget, gpointer data _U_) {
|
|
|
|
gpointer dialog;
|
|
|
|
|
2004-06-20 15:57:11 +00:00
|
|
|
if((cfile.state != FILE_CLOSED) && !cfile.user_saved && prefs.gui_ask_unsaved) {
|
2004-06-17 21:53:26 +00:00
|
|
|
/* user didn't saved his current file, ask him */
|
2004-06-18 07:41:21 +00:00
|
|
|
dialog = simple_dialog(ESD_TYPE_CONFIRMATION, ESD_BTNS_OK_CANCEL,
|
2008-04-12 01:41:53 +00:00
|
|
|
"%sSave the capture file before merging to another one?%s\n\n"
|
|
|
|
"A temporary capture file can't be merged.",
|
|
|
|
simple_dialog_primary_start(), simple_dialog_primary_end());
|
2004-06-17 21:53:26 +00:00
|
|
|
simple_dialog_set_cb(dialog, file_merge_answered_cb, widget);
|
|
|
|
} else {
|
|
|
|
/* unchanged file, just start to merge */
|
|
|
|
file_merge_cmd(widget);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
file_merge_ok_cb(GtkWidget *w, gpointer fs) {
|
"gtk_entry_get_text()" returns a "const char *" - assign the result to
one.
"get_basename()" doesn't modify its argument, and its callers don't
modify the substring pointed to by the result, so make it take a "const
char *" as an argument and return a "const char *".
"find_last_pathname_separator()" doesn't modify its argument, so make it
a "const char *" - but some of its callers pass a non-"const" "char *"
and modify the result, so don't make its return value a "const char *".
And, as none of its callers are outside "filesystem.c", make it static.
In "about_folders_page_new()", have separate variables for pathnames
returned as "const char *" (which are cached by the routine that returns
them, so you can't modify them - and can't free them, so get rid of the
commented-out "g_free()" calls for them) and pathnames returned as "char
*" (which are allocated anew for each call, and can be modified, but
have to be freed).
Clean up white space.
svn path=/trunk/; revision=12881
2004-12-31 00:26:36 +00:00
|
|
|
gchar *cf_name, *s;
|
|
|
|
const gchar *rfilter;
|
2010-03-21 19:26:32 +00:00
|
|
|
GtkWidget *ft_combo_box, *filter_te, *rb;
|
"gtk_entry_get_text()" returns a "const char *" - assign the result to
one.
"get_basename()" doesn't modify its argument, and its callers don't
modify the substring pointed to by the result, so make it take a "const
char *" as an argument and return a "const char *".
"find_last_pathname_separator()" doesn't modify its argument, so make it
a "const char *" - but some of its callers pass a non-"const" "char *"
and modify the result, so don't make its return value a "const char *".
And, as none of its callers are outside "filesystem.c", make it static.
In "about_folders_page_new()", have separate variables for pathnames
returned as "const char *" (which are cached by the routine that returns
them, so you can't modify them - and can't free them, so get rid of the
commented-out "g_free()" calls for them) and pathnames returned as "char
*" (which are allocated anew for each call, and can be modified, but
have to be freed).
Clean up white space.
svn path=/trunk/; revision=12881
2004-12-31 00:26:36 +00:00
|
|
|
dfilter_t *rfcode = NULL;
|
|
|
|
int err;
|
2005-02-05 13:44:27 +00:00
|
|
|
cf_status_t merge_status;
|
"gtk_entry_get_text()" returns a "const char *" - assign the result to
one.
"get_basename()" doesn't modify its argument, and its callers don't
modify the substring pointed to by the result, so make it take a "const
char *" as an argument and return a "const char *".
"find_last_pathname_separator()" doesn't modify its argument, so make it
a "const char *" - but some of its callers pass a non-"const" "char *"
and modify the result, so don't make its return value a "const char *".
And, as none of its callers are outside "filesystem.c", make it static.
In "about_folders_page_new()", have separate variables for pathnames
returned as "const char *" (which are cached by the routine that returns
them, so you can't modify them - and can't free them, so get rid of the
commented-out "g_free()" calls for them) and pathnames returned as "char
*" (which are allocated anew for each call, and can be modified, but
have to be freed).
Clean up white space.
svn path=/trunk/; revision=12881
2004-12-31 00:26:36 +00:00
|
|
|
char *in_filenames[2];
|
2005-02-17 03:05:54 +00:00
|
|
|
char *tmpname;
|
2010-03-21 19:26:32 +00:00
|
|
|
gpointer ptr;
|
|
|
|
int file_type;
|
|
|
|
|
2004-06-17 21:53:26 +00:00
|
|
|
|
2009-06-02 20:57:57 +00:00
|
|
|
cf_name = gtk_file_chooser_get_filename(GTK_FILE_CHOOSER(fs));
|
2008-04-11 17:14:11 +00:00
|
|
|
filter_te = g_object_get_data(G_OBJECT(w), E_RFILTER_TE_KEY);
|
"gtk_entry_get_text()" returns a "const char *" - assign the result to
one.
"get_basename()" doesn't modify its argument, and its callers don't
modify the substring pointed to by the result, so make it take a "const
char *" as an argument and return a "const char *".
"find_last_pathname_separator()" doesn't modify its argument, so make it
a "const char *" - but some of its callers pass a non-"const" "char *"
and modify the result, so don't make its return value a "const char *".
And, as none of its callers are outside "filesystem.c", make it static.
In "about_folders_page_new()", have separate variables for pathnames
returned as "const char *" (which are cached by the routine that returns
them, so you can't modify them - and can't free them, so get rid of the
commented-out "g_free()" calls for them) and pathnames returned as "char
*" (which are allocated anew for each call, and can be modified, but
have to be freed).
Clean up white space.
svn path=/trunk/; revision=12881
2004-12-31 00:26:36 +00:00
|
|
|
rfilter = gtk_entry_get_text(GTK_ENTRY(filter_te));
|
2004-06-17 21:53:26 +00:00
|
|
|
if (!dfilter_compile(rfilter, &rfcode)) {
|
|
|
|
bad_dfilter_alert_box(rfilter);
|
|
|
|
g_free(cf_name);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2010-03-21 19:26:32 +00:00
|
|
|
ft_combo_box = g_object_get_data(G_OBJECT(w), E_FILE_TYPE_COMBO_BOX_KEY);
|
|
|
|
if (! ws_combo_box_get_active_pointer(GTK_COMBO_BOX(ft_combo_box), &ptr)) {
|
|
|
|
g_assert_not_reached(); /* Programming error: somehow nothing is active */
|
|
|
|
}
|
|
|
|
file_type = GPOINTER_TO_INT(ptr);
|
|
|
|
|
2004-06-17 21:53:26 +00:00
|
|
|
/* Perhaps the user specified a directory instead of a file.
|
|
|
|
Check whether they did. */
|
|
|
|
if (test_for_directory(cf_name) == EISDIR) {
|
|
|
|
/* It's a directory - set the file selection box to display that
|
|
|
|
directory, don't try to open the directory as a capture file. */
|
|
|
|
set_last_open_dir(cf_name);
|
|
|
|
g_free(cf_name);
|
|
|
|
file_selection_set_current_folder(fs, get_last_open_dir());
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2004-06-18 07:41:21 +00:00
|
|
|
/* merge or append the two files */
|
2008-04-11 17:14:11 +00:00
|
|
|
rb = g_object_get_data(G_OBJECT(w), E_MERGE_CHRONO_KEY);
|
2005-02-17 03:05:54 +00:00
|
|
|
tmpname = NULL;
|
2004-06-17 21:53:26 +00:00
|
|
|
if(gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON (rb))) {
|
2004-10-27 23:28:37 +00:00
|
|
|
/* chronological order */
|
2004-06-21 16:45:07 +00:00
|
|
|
in_filenames[0] = cfile.filename;
|
|
|
|
in_filenames[1] = cf_name;
|
2010-03-21 19:26:32 +00:00
|
|
|
merge_status = cf_merge_files(&tmpname, 2, in_filenames, file_type, FALSE);
|
2004-06-17 21:53:26 +00:00
|
|
|
} else {
|
2008-04-11 17:14:11 +00:00
|
|
|
rb = g_object_get_data(G_OBJECT(w), E_MERGE_PREPEND_KEY);
|
2004-06-17 21:53:26 +00:00
|
|
|
if(gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON (rb))) {
|
|
|
|
/* prepend file */
|
2007-05-16 20:19:30 +00:00
|
|
|
in_filenames[0] = cf_name;
|
|
|
|
in_filenames[1] = cfile.filename;
|
2010-03-21 19:26:32 +00:00
|
|
|
merge_status = cf_merge_files(&tmpname, 2, in_filenames, file_type,
|
2005-02-17 03:05:54 +00:00
|
|
|
TRUE);
|
2004-06-17 21:53:26 +00:00
|
|
|
} else {
|
|
|
|
/* append file */
|
2007-05-16 20:19:30 +00:00
|
|
|
in_filenames[0] = cfile.filename;
|
|
|
|
in_filenames[1] = cf_name;
|
2010-03-21 19:26:32 +00:00
|
|
|
merge_status = cf_merge_files(&tmpname, 2, in_filenames, file_type,
|
2005-02-17 03:05:54 +00:00
|
|
|
TRUE);
|
2004-06-17 21:53:26 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2004-06-18 07:41:21 +00:00
|
|
|
g_free(cf_name);
|
2006-02-13 21:25:43 +00:00
|
|
|
|
2005-02-05 13:44:27 +00:00
|
|
|
if (merge_status != CF_OK) {
|
2004-06-17 21:53:26 +00:00
|
|
|
if (rfcode != NULL)
|
|
|
|
dfilter_free(rfcode);
|
2005-02-17 03:05:54 +00:00
|
|
|
g_free(tmpname);
|
2004-06-17 21:53:26 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2004-06-18 07:41:21 +00:00
|
|
|
cf_close(&cfile);
|
|
|
|
|
|
|
|
/* We've crossed the Rubicon; get rid of the file selection box. */
|
|
|
|
window_destroy(GTK_WIDGET (fs));
|
|
|
|
|
|
|
|
/* Try to open the merged capture file. */
|
2005-02-04 18:44:44 +00:00
|
|
|
if (cf_open(&cfile, tmpname, TRUE /* temporary file */, &err) != CF_OK) {
|
2004-06-17 21:53:26 +00:00
|
|
|
/* We couldn't open it; don't dismiss the open dialog box,
|
|
|
|
just leave it around so that the user can, after they
|
|
|
|
dismiss the alert box popped up for the open error,
|
|
|
|
try again. */
|
|
|
|
if (rfcode != NULL)
|
|
|
|
dfilter_free(rfcode);
|
2005-02-17 03:05:54 +00:00
|
|
|
g_free(tmpname);
|
2008-01-26 16:50:08 +00:00
|
|
|
/* XXX - as we cannot start a new event loop (using gtk_dialog_run()),
|
|
|
|
* as this will prevent the user from closing the now existing error
|
2008-03-27 17:26:59 +00:00
|
|
|
* message, simply close the dialog (this is the best we can do here). */
|
2008-01-26 16:50:08 +00:00
|
|
|
if (file_open_w)
|
|
|
|
window_destroy(file_open_w);
|
2004-06-17 21:53:26 +00:00
|
|
|
return;
|
|
|
|
}
|
2005-02-17 03:05:54 +00:00
|
|
|
g_free(tmpname);
|
2004-06-17 21:53:26 +00:00
|
|
|
|
|
|
|
/* Attach the new read filter to "cf" ("cf_open()" succeeded, so
|
|
|
|
it closed the previous capture file, and thus destroyed any
|
|
|
|
previous read filter attached to "cf"). */
|
|
|
|
cfile.rfcode = rfcode;
|
|
|
|
|
2009-12-14 22:05:29 +00:00
|
|
|
switch (cf_read(&cfile, FALSE)) {
|
2004-06-17 21:53:26 +00:00
|
|
|
|
2005-02-05 12:50:47 +00:00
|
|
|
case CF_READ_OK:
|
|
|
|
case CF_READ_ERROR:
|
2004-06-17 21:53:26 +00:00
|
|
|
/* Just because we got an error, that doesn't mean we were unable
|
|
|
|
to read any of the file; we handle what we could get from the
|
|
|
|
file. */
|
|
|
|
break;
|
|
|
|
|
2005-02-05 12:50:47 +00:00
|
|
|
case CF_READ_ABORTED:
|
2004-06-17 21:53:26 +00:00
|
|
|
/* The user bailed out of re-reading the capture file; the
|
|
|
|
capture file has been closed - just free the capture file name
|
|
|
|
string and return (without changing the last containing
|
|
|
|
directory). */
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Save the name of the containing directory specified in the path name,
|
2004-06-18 07:41:21 +00:00
|
|
|
if any; we can write over cf_merged_name, which is a good thing, given that
|
2004-06-17 21:53:26 +00:00
|
|
|
"get_dirname()" does write over its argument. */
|
2004-06-29 20:59:24 +00:00
|
|
|
s = get_dirname(tmpname);
|
2004-06-17 21:53:26 +00:00
|
|
|
set_last_open_dir(s);
|
2009-06-30 18:05:04 +00:00
|
|
|
#ifndef NEW_PACKET_LIST
|
2004-06-17 21:53:26 +00:00
|
|
|
gtk_widget_grab_focus(packet_list);
|
2009-06-30 18:05:04 +00:00
|
|
|
#endif
|
2004-06-17 21:53:26 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
file_merge_destroy_cb(GtkWidget *win _U_, gpointer user_data _U_)
|
|
|
|
{
|
|
|
|
/* Note that we no longer have a "Merge Capture File" dialog box. */
|
|
|
|
file_merge_w = NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2005-08-02 04:47:15 +00:00
|
|
|
static void file_close_answered_cb(gpointer dialog _U_, gint btn, gpointer data _U_)
|
2004-01-29 23:11:38 +00:00
|
|
|
{
|
|
|
|
switch(btn) {
|
2004-07-13 07:15:45 +00:00
|
|
|
case(ESD_BTN_SAVE):
|
2004-01-29 23:11:38 +00:00
|
|
|
/* save file first */
|
|
|
|
file_save_as_cmd(after_save_close_file, NULL);
|
|
|
|
break;
|
2004-07-13 07:15:45 +00:00
|
|
|
case(ESD_BTN_DONT_SAVE):
|
2004-01-29 23:11:38 +00:00
|
|
|
cf_close(&cfile);
|
|
|
|
break;
|
|
|
|
case(ESD_BTN_CANCEL):
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
g_assert_not_reached();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
1999-09-01 03:04:24 +00:00
|
|
|
/* Close a file */
|
|
|
|
void
|
2002-03-05 11:56:00 +00:00
|
|
|
file_close_cmd_cb(GtkWidget *widget _U_, gpointer data _U_) {
|
2004-01-29 23:11:38 +00:00
|
|
|
gpointer dialog;
|
|
|
|
|
2004-06-20 15:57:11 +00:00
|
|
|
if((cfile.state != FILE_CLOSED) && !cfile.user_saved && prefs.gui_ask_unsaved) {
|
2004-01-29 23:11:38 +00:00
|
|
|
/* user didn't saved his current file, ask him */
|
2004-07-13 07:15:45 +00:00
|
|
|
dialog = simple_dialog(ESD_TYPE_CONFIRMATION, ESD_BTNS_SAVE_DONTSAVE_CANCEL,
|
2008-04-12 01:41:53 +00:00
|
|
|
"%sSave capture file before closing it?%s\n\n"
|
|
|
|
"If you close without saving, your capture data will be discarded.",
|
|
|
|
simple_dialog_primary_start(), simple_dialog_primary_end());
|
2004-01-31 12:13:23 +00:00
|
|
|
|
2004-02-03 17:59:01 +00:00
|
|
|
simple_dialog_set_cb(dialog, file_close_answered_cb, NULL);
|
2004-01-29 23:11:38 +00:00
|
|
|
} else {
|
|
|
|
/* unchanged file, just close it */
|
|
|
|
cf_close(&cfile);
|
|
|
|
}
|
1999-09-01 03:04:24 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
file_save_cmd_cb(GtkWidget *w, gpointer data) {
|
Allow the user to save either all of the current capture, or only the
packets that are currently being displayed from that capture.
Centralize the code to control whether "File:Save" and "File:Save As"
are enabled (and *always* have "File:Save As" enabled if you have a
capture; "File:Save" is enabled only if you have a live capture you've
not yet saved, although it does the same thing as "File:Save As").
Have the "save_file" member of a "capture_file" structure represent
*only* the file currently being *written* to by a capture, and, if there
is no capture currently in progress, have it be NULL; the name of the
file currently being *displayed" is in the "filename" member, and an
"is_tempfile" member indicates whether it's a temporary file for a live
capture or not.
Have "close_cap_file()" delete the current capture file if it's a
temporary capture file that hasn't been saved (in its entirety - saving
selected frames doesn't count). Do the same (if there *is* a current
capture file) when exiting.
The "Ready to load or capture" message is the only statusbar message in
the "main" context; "close_cap_file()" should never pop it, it should
only pop whatever message exists in the "file" context, and thus has no
need to take, as an argument, the context for the message it should pop.
Update the man page to reflect the new behavior of "File:Save" and
"File:Save As", and to reflect recent changes to "Display:Match Selected".
svn path=/trunk/; revision=1170
1999-11-30 20:50:15 +00:00
|
|
|
/* If the file's already been saved, do nothing. */
|
2000-06-27 04:36:03 +00:00
|
|
|
if (cfile.user_saved)
|
Allow the user to save either all of the current capture, or only the
packets that are currently being displayed from that capture.
Centralize the code to control whether "File:Save" and "File:Save As"
are enabled (and *always* have "File:Save As" enabled if you have a
capture; "File:Save" is enabled only if you have a live capture you've
not yet saved, although it does the same thing as "File:Save As").
Have the "save_file" member of a "capture_file" structure represent
*only* the file currently being *written* to by a capture, and, if there
is no capture currently in progress, have it be NULL; the name of the
file currently being *displayed" is in the "filename" member, and an
"is_tempfile" member indicates whether it's a temporary file for a live
capture or not.
Have "close_cap_file()" delete the current capture file if it's a
temporary capture file that hasn't been saved (in its entirety - saving
selected frames doesn't count). Do the same (if there *is* a current
capture file) when exiting.
The "Ready to load or capture" message is the only statusbar message in
the "main" context; "close_cap_file()" should never pop it, it should
only pop whatever message exists in the "file" context, and thus has no
need to take, as an argument, the context for the message it should pop.
Update the man page to reflect the new behavior of "File:Save" and
"File:Save As", and to reflect recent changes to "Display:Match Selected".
svn path=/trunk/; revision=1170
1999-11-30 20:50:15 +00:00
|
|
|
return;
|
1999-09-01 03:04:24 +00:00
|
|
|
|
Allow the user to save either all of the current capture, or only the
packets that are currently being displayed from that capture.
Centralize the code to control whether "File:Save" and "File:Save As"
are enabled (and *always* have "File:Save As" enabled if you have a
capture; "File:Save" is enabled only if you have a live capture you've
not yet saved, although it does the same thing as "File:Save As").
Have the "save_file" member of a "capture_file" structure represent
*only* the file currently being *written* to by a capture, and, if there
is no capture currently in progress, have it be NULL; the name of the
file currently being *displayed" is in the "filename" member, and an
"is_tempfile" member indicates whether it's a temporary file for a live
capture or not.
Have "close_cap_file()" delete the current capture file if it's a
temporary capture file that hasn't been saved (in its entirety - saving
selected frames doesn't count). Do the same (if there *is* a current
capture file) when exiting.
The "Ready to load or capture" message is the only statusbar message in
the "main" context; "close_cap_file()" should never pop it, it should
only pop whatever message exists in the "file" context, and thus has no
need to take, as an argument, the context for the message it should pop.
Update the man page to reflect the new behavior of "File:Save" and
"File:Save As", and to reflect recent changes to "Display:Match Selected".
svn path=/trunk/; revision=1170
1999-11-30 20:50:15 +00:00
|
|
|
/* Do a "Save As". */
|
|
|
|
file_save_as_cmd_cb(w, data);
|
1999-09-01 03:04:24 +00:00
|
|
|
}
|
|
|
|
|
1999-12-06 09:02:48 +00:00
|
|
|
static gboolean
|
|
|
|
can_save_with_wiretap(int ft)
|
|
|
|
{
|
|
|
|
/* To save a file with Wiretap, Wiretap has to handle that format,
|
|
|
|
and its code to handle that format must be able to write a file
|
|
|
|
with this file's encapsulation type. */
|
2000-06-27 04:36:03 +00:00
|
|
|
return wtap_dump_can_open(ft) && wtap_dump_can_write_encap(ft, cfile.lnk_t);
|
1999-12-06 09:02:48 +00:00
|
|
|
}
|
|
|
|
|
2004-01-07 00:10:52 +00:00
|
|
|
|
2010-02-22 18:50:56 +00:00
|
|
|
/* Attach a list of the valid 'save as' file types to a combo_box by
|
|
|
|
checking what Wiretap supports.
|
|
|
|
returns: index of default entry
|
|
|
|
*/
|
|
|
|
static gint
|
2010-03-21 19:26:32 +00:00
|
|
|
set_file_type_list(GtkWidget *combo_box, int default_file_type)
|
1999-12-06 09:02:48 +00:00
|
|
|
{
|
2010-02-22 18:50:56 +00:00
|
|
|
int ft;
|
2010-01-29 16:13:26 +00:00
|
|
|
guint idx;
|
2010-02-22 18:50:56 +00:00
|
|
|
gint item_to_select;
|
1999-12-06 09:02:48 +00:00
|
|
|
|
2010-10-12 13:15:08 +00:00
|
|
|
/* Default to the first supported file type (which should be libpcap)
|
2010-02-22 18:50:56 +00:00
|
|
|
if this file's current type isn't supported */
|
|
|
|
item_to_select = 0;
|
1999-12-06 09:02:48 +00:00
|
|
|
|
|
|
|
/* Check all file types. */
|
2010-01-29 16:13:26 +00:00
|
|
|
idx = 0;
|
1999-12-06 09:02:48 +00:00
|
|
|
for (ft = 0; ft < WTAP_NUM_FILE_TYPES; ft++) {
|
In "Save As", support only file types we can write to; that simplifies
the logic, making it easier to get it right (fewer interactions between
components of the dialog - the file type doesn't affect whether we can
save some but not all packets). It also means we don't offer a file
type for saving, only to take it away if you choose anything other than
saving all packets.
If the capture file is a temporary file from a capture done in the
current Ethereal session, it's libpcap format, which we can write to, so
you would be able to save it.
If it's a saved file we read in, saving the file in its entirety in its
own format is just copying the file, and it's not clear supporting that
adds enough useful functionality to justify the extra complication.
Fix "range_update_dynamics()" to update all the rows of the range
button/count table properly (make the button active iff there's
a non-zero count in the currently-selected column, make a count active
iff the column is selected), to select the "Captured" column if the
count of displayed packets goes to zero, and to select the "Save all
packets" row if the count of packets in the currently-selected row and
column goes to zero. (XXX - we should perhaps do that with the
"user-defined range" counts as well, which would involve updating the
counts on every change to the range field.)
svn path=/trunk/; revision=17251
2006-02-11 11:21:38 +00:00
|
|
|
if (can_save_with_wiretap(ft)) {
|
|
|
|
/* OK, we can write it out in this type. */
|
2010-02-22 18:50:56 +00:00
|
|
|
ws_combo_box_append_text_and_pointer(GTK_COMBO_BOX(combo_box), wtap_file_type_string(ft), GINT_TO_POINTER(ft));
|
2010-03-21 19:26:32 +00:00
|
|
|
if (ft == default_file_type) {
|
In "Save As", support only file types we can write to; that simplifies
the logic, making it easier to get it right (fewer interactions between
components of the dialog - the file type doesn't affect whether we can
save some but not all packets). It also means we don't offer a file
type for saving, only to take it away if you choose anything other than
saving all packets.
If the capture file is a temporary file from a capture done in the
current Ethereal session, it's libpcap format, which we can write to, so
you would be able to save it.
If it's a saved file we read in, saving the file in its entirety in its
own format is just copying the file, and it's not clear supporting that
adds enough useful functionality to justify the extra complication.
Fix "range_update_dynamics()" to update all the rows of the range
button/count table properly (make the button active iff there's
a non-zero count in the currently-selected column, make a count active
iff the column is selected), to select the "Captured" column if the
count of displayed packets goes to zero, and to select the "Save all
packets" row if the count of packets in the currently-selected row and
column goes to zero. (XXX - we should perhaps do that with the
"user-defined range" counts as well, which would involve updating the
counts on every change to the range field.)
svn path=/trunk/; revision=17251
2006-02-11 11:21:38 +00:00
|
|
|
/* Default to the same format as the file, if it's supported. */
|
2010-01-29 16:13:26 +00:00
|
|
|
item_to_select = idx;
|
In "Save As", support only file types we can write to; that simplifies
the logic, making it easier to get it right (fewer interactions between
components of the dialog - the file type doesn't affect whether we can
save some but not all packets). It also means we don't offer a file
type for saving, only to take it away if you choose anything other than
saving all packets.
If the capture file is a temporary file from a capture done in the
current Ethereal session, it's libpcap format, which we can write to, so
you would be able to save it.
If it's a saved file we read in, saving the file in its entirety in its
own format is just copying the file, and it's not clear supporting that
adds enough useful functionality to justify the extra complication.
Fix "range_update_dynamics()" to update all the rows of the range
button/count table properly (make the button active iff there's
a non-zero count in the currently-selected column, make a count active
iff the column is selected), to select the "Captured" column if the
count of displayed packets goes to zero, and to select the "Save all
packets" row if the count of packets in the currently-selected row and
column goes to zero. (XXX - we should perhaps do that with the
"user-defined range" counts as well, which would involve updating the
counts on every change to the range field.)
svn path=/trunk/; revision=17251
2006-02-11 11:21:38 +00:00
|
|
|
}
|
2010-01-29 16:13:26 +00:00
|
|
|
idx++;
|
1999-12-06 09:02:48 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-02-22 18:50:56 +00:00
|
|
|
return item_to_select;
|
1999-12-06 09:02:48 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2010-03-21 19:26:32 +00:00
|
|
|
file_save_as_select_file_type_cb(GtkWidget *w, gpointer data _U_)
|
1999-12-06 09:02:48 +00:00
|
|
|
{
|
2010-03-21 19:26:32 +00:00
|
|
|
int new_file_type;
|
2010-02-22 18:50:56 +00:00
|
|
|
gpointer ptr;
|
2005-09-14 21:57:30 +00:00
|
|
|
GtkWidget *compressed_cb;
|
1999-12-06 09:02:48 +00:00
|
|
|
|
2010-02-22 18:50:56 +00:00
|
|
|
if (! ws_combo_box_get_active_pointer(GTK_COMBO_BOX(w), &ptr)) {
|
|
|
|
g_assert_not_reached(); /* Programming error: somehow nothing is active */
|
|
|
|
}
|
2010-03-21 19:26:32 +00:00
|
|
|
new_file_type = GPOINTER_TO_INT(ptr);
|
2010-02-22 18:50:56 +00:00
|
|
|
|
2010-03-21 19:26:32 +00:00
|
|
|
compressed_cb = g_object_get_data(G_OBJECT(file_save_as_w), E_COMPRESSED_CB_KEY);
|
|
|
|
gtk_widget_set_sensitive(compressed_cb, wtap_dump_can_compress(new_file_type));
|
1999-12-06 09:02:48 +00:00
|
|
|
}
|
|
|
|
|
2004-01-09 18:11:21 +00:00
|
|
|
/*
|
In "Save As", support only file types we can write to; that simplifies
the logic, making it easier to get it right (fewer interactions between
components of the dialog - the file type doesn't affect whether we can
save some but not all packets). It also means we don't offer a file
type for saving, only to take it away if you choose anything other than
saving all packets.
If the capture file is a temporary file from a capture done in the
current Ethereal session, it's libpcap format, which we can write to, so
you would be able to save it.
If it's a saved file we read in, saving the file in its entirety in its
own format is just copying the file, and it's not clear supporting that
adds enough useful functionality to justify the extra complication.
Fix "range_update_dynamics()" to update all the rows of the range
button/count table properly (make the button active iff there's
a non-zero count in the currently-selected column, make a count active
iff the column is selected), to select the "Captured" column if the
count of displayed packets goes to zero, and to select the "Save all
packets" row if the count of packets in the currently-selected row and
column goes to zero. (XXX - we should perhaps do that with the
"user-defined range" counts as well, which would involve updating the
counts on every change to the range field.)
svn path=/trunk/; revision=17251
2006-02-11 11:21:38 +00:00
|
|
|
* Update various dynamic parts of the range controls; called from outside
|
|
|
|
* the file dialog code whenever the packet counts change.
|
2004-01-09 18:11:21 +00:00
|
|
|
*/
|
|
|
|
void
|
In "Save As", support only file types we can write to; that simplifies
the logic, making it easier to get it right (fewer interactions between
components of the dialog - the file type doesn't affect whether we can
save some but not all packets). It also means we don't offer a file
type for saving, only to take it away if you choose anything other than
saving all packets.
If the capture file is a temporary file from a capture done in the
current Ethereal session, it's libpcap format, which we can write to, so
you would be able to save it.
If it's a saved file we read in, saving the file in its entirety in its
own format is just copying the file, and it's not clear supporting that
adds enough useful functionality to justify the extra complication.
Fix "range_update_dynamics()" to update all the rows of the range
button/count table properly (make the button active iff there's
a non-zero count in the currently-selected column, make a count active
iff the column is selected), to select the "Captured" column if the
count of displayed packets goes to zero, and to select the "Save all
packets" row if the count of packets in the currently-selected row and
column goes to zero. (XXX - we should perhaps do that with the
"user-defined range" counts as well, which would involve updating the
counts on every change to the range field.)
svn path=/trunk/; revision=17251
2006-02-11 11:21:38 +00:00
|
|
|
file_save_update_dynamics(void)
|
2004-01-09 18:11:21 +00:00
|
|
|
{
|
|
|
|
if (file_save_as_w == NULL) {
|
|
|
|
/* We don't currently have a "Save As..." dialog box up. */
|
|
|
|
return;
|
|
|
|
}
|
2006-02-13 21:25:43 +00:00
|
|
|
|
In "Save As", support only file types we can write to; that simplifies
the logic, making it easier to get it right (fewer interactions between
components of the dialog - the file type doesn't affect whether we can
save some but not all packets). It also means we don't offer a file
type for saving, only to take it away if you choose anything other than
saving all packets.
If the capture file is a temporary file from a capture done in the
current Ethereal session, it's libpcap format, which we can write to, so
you would be able to save it.
If it's a saved file we read in, saving the file in its entirety in its
own format is just copying the file, and it's not clear supporting that
adds enough useful functionality to justify the extra complication.
Fix "range_update_dynamics()" to update all the rows of the range
button/count table properly (make the button active iff there's
a non-zero count in the currently-selected column, make a count active
iff the column is selected), to select the "Captured" column if the
count of displayed packets goes to zero, and to select the "Save all
packets" row if the count of packets in the currently-selected row and
column goes to zero. (XXX - we should perhaps do that with the
"user-defined range" counts as well, which would involve updating the
counts on every change to the range field.)
svn path=/trunk/; revision=17251
2006-02-11 11:21:38 +00:00
|
|
|
range_update_dynamics(range_tb);
|
2004-01-09 18:11:21 +00:00
|
|
|
}
|
|
|
|
|
2004-04-22 21:31:09 +00:00
|
|
|
|
2004-01-29 23:11:38 +00:00
|
|
|
action_after_save_e action_after_save_g;
|
|
|
|
gpointer action_after_save_data_g;
|
|
|
|
|
|
|
|
|
1999-09-01 03:04:24 +00:00
|
|
|
void
|
2004-01-29 23:11:38 +00:00
|
|
|
file_save_as_cmd(action_after_save_e action_after_save, gpointer action_after_save_data)
|
1999-12-06 09:02:48 +00:00
|
|
|
{
|
2008-04-06 22:25:36 +00:00
|
|
|
#if _WIN32
|
2006-02-15 11:01:57 +00:00
|
|
|
win32_save_as_file(GDK_WINDOW_HWND(top_level->window), action_after_save, action_after_save_data);
|
2008-04-06 22:25:36 +00:00
|
|
|
#else /* _WIN32 */
|
2010-02-22 18:50:56 +00:00
|
|
|
GtkWidget *main_vb, *ft_hb, *ft_lb, *ft_combo_box, *range_fr, *compressed_cb;
|
|
|
|
gint combo_box_item_to_select;
|
2003-12-30 01:19:02 +00:00
|
|
|
|
2000-04-10 18:40:13 +00:00
|
|
|
if (file_save_as_w != NULL) {
|
|
|
|
/* There's already an "Save Capture File As" dialog box; reactivate it. */
|
|
|
|
reactivate_window(file_save_as_w);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
1999-12-06 09:02:48 +00:00
|
|
|
/* Default to saving all packets, in the file's current format. */
|
2003-12-29 20:05:59 +00:00
|
|
|
|
|
|
|
/* init the packet range */
|
|
|
|
packet_range_init(&range);
|
|
|
|
|
2004-01-07 00:10:52 +00:00
|
|
|
/* build the file selection */
|
2006-05-22 07:29:40 +00:00
|
|
|
file_save_as_w = file_selection_new ("Wireshark: Save Capture File As",
|
2004-03-29 22:40:58 +00:00
|
|
|
FILE_SELECTION_SAVE);
|
1999-09-01 03:04:24 +00:00
|
|
|
|
2004-01-29 23:11:38 +00:00
|
|
|
/* as the dialog might already be gone, when using this values, we cannot
|
|
|
|
* set data to the dialog object, but keep global values */
|
|
|
|
action_after_save_g = action_after_save;
|
|
|
|
action_after_save_data_g = action_after_save_data;
|
|
|
|
|
1999-12-06 09:02:48 +00:00
|
|
|
/* Container for each row of widgets */
|
2006-02-13 21:25:43 +00:00
|
|
|
|
2003-12-29 20:05:59 +00:00
|
|
|
main_vb = gtk_vbox_new(FALSE, 5);
|
2008-06-29 15:51:43 +00:00
|
|
|
gtk_container_set_border_width(GTK_CONTAINER(main_vb), 5);
|
2004-03-29 22:55:13 +00:00
|
|
|
file_selection_set_extra_widget(file_save_as_w, main_vb);
|
2006-02-13 21:25:43 +00:00
|
|
|
gtk_widget_show(main_vb);
|
|
|
|
|
2004-01-01 13:10:45 +00:00
|
|
|
/*** Packet Range frame ***/
|
2003-12-30 01:19:02 +00:00
|
|
|
range_fr = gtk_frame_new("Packet Range");
|
2003-12-29 20:05:59 +00:00
|
|
|
gtk_box_pack_start(GTK_BOX(main_vb), range_fr, FALSE, FALSE, 0);
|
|
|
|
gtk_widget_show(range_fr);
|
2006-02-13 21:25:43 +00:00
|
|
|
|
2004-01-07 00:10:52 +00:00
|
|
|
/* range table */
|
2008-04-06 22:25:36 +00:00
|
|
|
range_tb = range_new(&range);
|
2004-01-07 00:10:52 +00:00
|
|
|
gtk_container_add(GTK_CONTAINER(range_fr), range_tb);
|
|
|
|
gtk_widget_show(range_tb);
|
|
|
|
|
1999-12-06 09:02:48 +00:00
|
|
|
/* File type row */
|
|
|
|
ft_hb = gtk_hbox_new(FALSE, 3);
|
|
|
|
gtk_container_add(GTK_CONTAINER(main_vb), ft_hb);
|
|
|
|
gtk_widget_show(ft_hb);
|
2002-08-28 21:04:11 +00:00
|
|
|
|
1999-12-06 09:02:48 +00:00
|
|
|
ft_lb = gtk_label_new("File type:");
|
|
|
|
gtk_box_pack_start(GTK_BOX(ft_hb), ft_lb, FALSE, FALSE, 0);
|
|
|
|
gtk_widget_show(ft_lb);
|
|
|
|
|
2010-02-22 18:50:56 +00:00
|
|
|
ft_combo_box = ws_combo_box_new_text_and_pointer();
|
1999-12-06 09:02:48 +00:00
|
|
|
|
|
|
|
/* Generate the list of file types we can save. */
|
2010-03-21 19:26:32 +00:00
|
|
|
combo_box_item_to_select = set_file_type_list(ft_combo_box, cfile.cd_t);
|
2010-02-22 18:50:56 +00:00
|
|
|
gtk_box_pack_start(GTK_BOX(ft_hb), ft_combo_box, FALSE, FALSE, 0);
|
|
|
|
gtk_widget_show(ft_combo_box);
|
2010-03-21 19:26:32 +00:00
|
|
|
g_object_set_data(G_OBJECT(file_save_as_w), E_FILE_TYPE_COMBO_BOX_KEY, ft_combo_box);
|
1999-09-01 03:04:24 +00:00
|
|
|
|
2004-01-07 00:10:52 +00:00
|
|
|
/* dynamic values in the range frame */
|
2004-04-22 21:31:09 +00:00
|
|
|
range_update_dynamics(range_tb);
|
2004-01-07 00:10:52 +00:00
|
|
|
|
2005-09-14 21:57:30 +00:00
|
|
|
/* compressed */
|
|
|
|
compressed_cb = gtk_check_button_new_with_label("Compress with gzip");
|
|
|
|
gtk_container_add(GTK_CONTAINER(ft_hb), compressed_cb);
|
2006-02-13 21:25:43 +00:00
|
|
|
/* XXX - disable output compression for now, as this doesn't work with the
|
2005-09-23 18:50:07 +00:00
|
|
|
* current optimization to simply copy a capture file if it's using the same
|
|
|
|
* encapsulation ... */
|
|
|
|
/* the rest of the implementation is just working fine :-( */
|
2010-02-22 18:50:56 +00:00
|
|
|
#if 0
|
|
|
|
gtk_widget_show(compressed_cb);
|
|
|
|
#endif
|
2010-03-21 19:26:32 +00:00
|
|
|
g_object_set_data(G_OBJECT(file_save_as_w), E_COMPRESSED_CB_KEY, compressed_cb);
|
|
|
|
/* Ok: now "select" the default filetype which invokes file_save_as_select_file_type_cb */
|
|
|
|
g_signal_connect(ft_combo_box, "changed", G_CALLBACK(file_save_as_select_file_type_cb), NULL);
|
2010-02-22 18:50:56 +00:00
|
|
|
ws_combo_box_set_active(GTK_COMBO_BOX(ft_combo_box), combo_box_item_to_select);
|
2005-09-14 21:57:30 +00:00
|
|
|
|
2008-04-11 23:00:34 +00:00
|
|
|
g_signal_connect(file_save_as_w, "destroy",
|
|
|
|
G_CALLBACK(file_save_as_destroy_cb), NULL);
|
2004-05-26 03:49:24 +00:00
|
|
|
|
|
|
|
if (gtk_dialog_run(GTK_DIALOG(file_save_as_w)) == GTK_RESPONSE_ACCEPT) {
|
2004-03-27 11:16:58 +00:00
|
|
|
file_save_as_ok_cb(file_save_as_w, file_save_as_w);
|
2004-05-26 03:49:24 +00:00
|
|
|
} else {
|
|
|
|
window_destroy(file_save_as_w);
|
2004-03-27 11:16:58 +00:00
|
|
|
}
|
2008-04-06 22:25:36 +00:00
|
|
|
#endif /* _WIN32 */
|
1999-09-01 03:04:24 +00:00
|
|
|
}
|
|
|
|
|
2004-01-29 23:11:38 +00:00
|
|
|
void
|
|
|
|
file_save_as_cmd_cb(GtkWidget *w _U_, gpointer data _U_)
|
|
|
|
{
|
|
|
|
file_save_as_cmd(after_save_no_action, NULL);
|
|
|
|
}
|
|
|
|
|
2005-04-12 21:24:30 +00:00
|
|
|
|
|
|
|
/* all tests ok, we only have to save the file */
|
|
|
|
/* (and probably continue with a pending operation) */
|
1999-09-01 03:04:24 +00:00
|
|
|
static void
|
2005-04-12 21:24:30 +00:00
|
|
|
file_save_as_cb(GtkWidget *w _U_, gpointer fs) {
|
2010-03-21 19:26:32 +00:00
|
|
|
GtkWidget *ft_combo_box;
|
2005-09-14 21:57:30 +00:00
|
|
|
GtkWidget *compressed_cb;
|
2010-03-21 19:26:32 +00:00
|
|
|
gchar *cf_name;
|
|
|
|
gchar *dirname;
|
|
|
|
gpointer ptr;
|
|
|
|
int file_type;
|
2005-04-12 21:24:30 +00:00
|
|
|
|
2009-06-02 20:57:57 +00:00
|
|
|
cf_name = gtk_file_chooser_get_filename(GTK_FILE_CHOOSER(fs));
|
2002-09-09 20:39:01 +00:00
|
|
|
|
2010-03-21 19:26:32 +00:00
|
|
|
compressed_cb = g_object_get_data(G_OBJECT(fs), E_COMPRESSED_CB_KEY);
|
|
|
|
ft_combo_box = g_object_get_data(G_OBJECT(fs), E_FILE_TYPE_COMBO_BOX_KEY);
|
|
|
|
|
|
|
|
if (! ws_combo_box_get_active_pointer(GTK_COMBO_BOX(ft_combo_box), &ptr)) {
|
|
|
|
g_assert_not_reached(); /* Programming error: somehow nothing is active */
|
|
|
|
}
|
|
|
|
file_type = GPOINTER_TO_INT(ptr);
|
2005-09-14 21:57:30 +00:00
|
|
|
|
2006-08-23 21:19:02 +00:00
|
|
|
/* XXX - if the user requests to save to an already existing filename, */
|
|
|
|
/* ask in a dialog if that's intended */
|
|
|
|
/* currently, cf_save() will simply deny it */
|
|
|
|
|
2004-01-02 21:48:24 +00:00
|
|
|
/* Write out the packets (all, or only the ones from the current
|
|
|
|
range) to the file with the specified name. */
|
2010-03-21 19:26:32 +00:00
|
|
|
if (cf_save(&cfile, cf_name, &range, file_type,
|
2005-09-14 21:57:30 +00:00
|
|
|
gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(compressed_cb))) != CF_OK) {
|
2002-09-09 20:39:01 +00:00
|
|
|
/* The write failed; don't dismiss the open dialog box,
|
|
|
|
just leave it around so that the user can, after they
|
|
|
|
dismiss the alert box popped up for the error, try again. */
|
|
|
|
g_free(cf_name);
|
2004-10-16 23:32:24 +00:00
|
|
|
/* XXX - as we cannot start a new event loop (using gtk_dialog_run()),
|
|
|
|
* as this will prevent the user from closing the now existing error
|
|
|
|
* message, simply close the dialog (this is the best we can do here). */
|
2004-09-08 19:26:36 +00:00
|
|
|
if (file_save_as_w)
|
|
|
|
window_destroy(GTK_WIDGET (fs));
|
2002-09-09 20:39:01 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* The write succeeded; get rid of the file selection box. */
|
2005-02-04 18:44:44 +00:00
|
|
|
/* cf_save() might already closed our dialog! */
|
2004-01-29 23:11:38 +00:00
|
|
|
if (file_save_as_w)
|
2004-05-26 03:49:24 +00:00
|
|
|
window_destroy(GTK_WIDGET (fs));
|
2002-09-09 20:39:01 +00:00
|
|
|
|
|
|
|
/* Save the directory name for future file dialogs. */
|
|
|
|
dirname = get_dirname(cf_name); /* Overwrites cf_name */
|
|
|
|
set_last_open_dir(dirname);
|
Allow the user to save either all of the current capture, or only the
packets that are currently being displayed from that capture.
Centralize the code to control whether "File:Save" and "File:Save As"
are enabled (and *always* have "File:Save As" enabled if you have a
capture; "File:Save" is enabled only if you have a live capture you've
not yet saved, although it does the same thing as "File:Save As").
Have the "save_file" member of a "capture_file" structure represent
*only* the file currently being *written* to by a capture, and, if there
is no capture currently in progress, have it be NULL; the name of the
file currently being *displayed" is in the "filename" member, and an
"is_tempfile" member indicates whether it's a temporary file for a live
capture or not.
Have "close_cap_file()" delete the current capture file if it's a
temporary capture file that hasn't been saved (in its entirety - saving
selected frames doesn't count). Do the same (if there *is* a current
capture file) when exiting.
The "Ready to load or capture" message is the only statusbar message in
the "main" context; "close_cap_file()" should never pop it, it should
only pop whatever message exists in the "file" context, and thus has no
need to take, as an argument, the context for the message it should pop.
Update the man page to reflect the new behavior of "File:Save" and
"File:Save As", and to reflect recent changes to "Display:Match Selected".
svn path=/trunk/; revision=1170
1999-11-30 20:50:15 +00:00
|
|
|
g_free(cf_name);
|
2004-01-29 23:11:38 +00:00
|
|
|
|
|
|
|
/* we have finished saving, do we have pending things to do? */
|
|
|
|
switch(action_after_save_g) {
|
|
|
|
case(after_save_no_action):
|
|
|
|
break;
|
|
|
|
case(after_save_open_dialog):
|
|
|
|
file_open_cmd(action_after_save_data_g);
|
|
|
|
break;
|
|
|
|
case(after_save_open_recent_file):
|
|
|
|
menu_open_recent_file_cmd(action_after_save_data_g);
|
|
|
|
break;
|
2004-01-31 18:32:37 +00:00
|
|
|
case(after_save_open_dnd_file):
|
|
|
|
dnd_open_file_cmd(action_after_save_data_g);
|
|
|
|
break;
|
2004-06-17 21:53:26 +00:00
|
|
|
case(after_save_merge_dialog):
|
|
|
|
file_merge_cmd(action_after_save_data_g);
|
|
|
|
break;
|
2004-01-29 23:11:38 +00:00
|
|
|
#ifdef HAVE_LIBPCAP
|
|
|
|
case(after_save_capture_dialog):
|
2005-04-19 21:02:01 +00:00
|
|
|
capture_start_confirmed();
|
2004-01-29 23:11:38 +00:00
|
|
|
break;
|
|
|
|
#endif
|
|
|
|
case(after_save_close_file):
|
|
|
|
cf_close(&cfile);
|
|
|
|
break;
|
|
|
|
case(after_save_exit):
|
|
|
|
main_do_quit();
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
g_assert_not_reached();
|
|
|
|
}
|
|
|
|
|
|
|
|
action_after_save_g = after_save_no_action;
|
1999-09-01 03:04:24 +00:00
|
|
|
}
|
|
|
|
|
2005-04-12 21:24:30 +00:00
|
|
|
|
|
|
|
static void file_save_as_exists_answered_cb(gpointer dialog _U_, gint btn, gpointer data)
|
|
|
|
{
|
|
|
|
gchar *cf_name;
|
|
|
|
|
2009-06-02 20:57:57 +00:00
|
|
|
cf_name = gtk_file_chooser_get_filename(GTK_FILE_CHOOSER(data));
|
2005-04-12 21:24:30 +00:00
|
|
|
|
|
|
|
switch(btn) {
|
|
|
|
case(ESD_BTN_OK):
|
|
|
|
/* save file */
|
2008-05-22 15:46:27 +00:00
|
|
|
ws_unlink(cf_name);
|
2005-04-12 21:24:30 +00:00
|
|
|
file_save_as_cb(NULL, data);
|
|
|
|
break;
|
|
|
|
case(ESD_BTN_CANCEL):
|
2008-01-26 16:45:29 +00:00
|
|
|
/* XXX - as we cannot start a new event loop (using gtk_dialog_run()),
|
|
|
|
* as this will prevent the user from closing the now existing error
|
|
|
|
* message, simply close the dialog (this is the best we can do here). */
|
|
|
|
if (file_save_as_w)
|
|
|
|
window_destroy(file_save_as_w);
|
2005-04-12 21:24:30 +00:00
|
|
|
break;
|
|
|
|
default:
|
|
|
|
g_assert_not_reached();
|
|
|
|
}
|
2009-06-02 20:57:57 +00:00
|
|
|
g_free(cf_name);
|
2005-04-12 21:24:30 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/* user pressed "Save" dialog "Ok" button */
|
|
|
|
static void
|
2010-03-22 15:18:06 +00:00
|
|
|
file_save_as_ok_cb(GtkWidget *w _U_, gpointer fs) {
|
2005-04-12 21:24:30 +00:00
|
|
|
gchar *cf_name;
|
|
|
|
gpointer dialog;
|
2006-02-13 21:25:43 +00:00
|
|
|
|
2009-06-02 20:57:57 +00:00
|
|
|
cf_name = gtk_file_chooser_get_filename(GTK_FILE_CHOOSER(fs));
|
2005-04-12 21:24:30 +00:00
|
|
|
|
|
|
|
/* Perhaps the user specified a directory instead of a file.
|
|
|
|
Check whether they did. */
|
|
|
|
if (test_for_directory(cf_name) == EISDIR) {
|
|
|
|
/* It's a directory - set the file selection box to display that
|
|
|
|
directory, and leave the selection box displayed. */
|
|
|
|
set_last_open_dir(cf_name);
|
|
|
|
g_free(cf_name);
|
|
|
|
file_selection_set_current_folder(fs, get_last_open_dir());
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Check whether the range is valid. */
|
|
|
|
if (!range_check_validity(&range)) {
|
|
|
|
/* The range isn't valid; don't dismiss the open dialog box,
|
|
|
|
just leave it around so that the user can, after they
|
|
|
|
dismiss the alert box popped up for the error, try again. */
|
|
|
|
g_free(cf_name);
|
|
|
|
/* XXX - as we cannot start a new event loop (using gtk_dialog_run()),
|
|
|
|
* as this will prevent the user from closing the now existing error
|
|
|
|
* message, simply close the dialog (this is the best we can do here). */
|
|
|
|
if (file_save_as_w)
|
|
|
|
window_destroy(GTK_WIDGET (fs));
|
2008-04-27 07:01:58 +00:00
|
|
|
|
2005-04-12 21:24:30 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Check that the from file is not the same as to file
|
|
|
|
* We do it here so we catch all cases ...
|
|
|
|
* Unfortunately, the file requester gives us an absolute file
|
|
|
|
* name and the read file name may be relative (if supplied on
|
|
|
|
* the command line). From Joerg Mayer.
|
|
|
|
*/
|
|
|
|
if (files_identical(cfile.filename, cf_name)) {
|
|
|
|
simple_dialog(ESD_TYPE_ERROR, ESD_BTN_OK,
|
|
|
|
"%sCapture file: \"%s\" identical to loaded file!%s\n\n"
|
|
|
|
"Please choose a different filename.",
|
|
|
|
simple_dialog_primary_start(), cf_name, simple_dialog_primary_end());
|
|
|
|
g_free(cf_name);
|
|
|
|
/* XXX - as we cannot start a new event loop (using gtk_dialog_run()),
|
|
|
|
* as this will prevent the user from closing the now existing error
|
|
|
|
* message, simply close the dialog (this is the best we can do here). */
|
|
|
|
if (file_save_as_w)
|
|
|
|
window_destroy(GTK_WIDGET (fs));
|
2008-04-27 07:01:58 +00:00
|
|
|
|
2005-04-12 21:24:30 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* don't show the dialog while saving (or asking) */
|
|
|
|
gtk_widget_hide(GTK_WIDGET (fs));
|
|
|
|
|
|
|
|
/* it the file doesn't exist, simply try to save it */
|
|
|
|
if (!file_exists(cf_name)) {
|
|
|
|
file_save_as_cb(NULL, fs);
|
|
|
|
g_free(cf_name);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* the file exists, ask the user to remove it first */
|
|
|
|
dialog = simple_dialog(ESD_TYPE_CONFIRMATION, ESD_BTNS_OK_CANCEL,
|
2008-04-12 01:41:53 +00:00
|
|
|
"%sA file named \"%s\" already exists.%s\n\n"
|
2008-05-22 15:46:27 +00:00
|
|
|
"Do you want to replace it with the capture you are saving?",
|
2008-04-12 01:41:53 +00:00
|
|
|
simple_dialog_primary_start(), cf_name, simple_dialog_primary_end());
|
2005-04-12 21:24:30 +00:00
|
|
|
simple_dialog_set_cb(dialog, file_save_as_exists_answered_cb, fs);
|
|
|
|
|
|
|
|
g_free(cf_name);
|
|
|
|
}
|
|
|
|
|
2004-01-10 17:29:26 +00:00
|
|
|
void
|
|
|
|
file_save_as_destroy(void)
|
|
|
|
{
|
2004-01-14 14:28:25 +00:00
|
|
|
if (file_save_as_w)
|
2004-05-26 03:49:24 +00:00
|
|
|
window_destroy(file_save_as_w);
|
2004-01-10 17:29:26 +00:00
|
|
|
}
|
|
|
|
|
2000-04-10 18:40:13 +00:00
|
|
|
static void
|
2002-03-05 11:56:00 +00:00
|
|
|
file_save_as_destroy_cb(GtkWidget *win _U_, gpointer user_data _U_)
|
2000-04-10 18:40:13 +00:00
|
|
|
{
|
|
|
|
/* Note that we no longer have a "Save Capture File As" dialog box. */
|
|
|
|
file_save_as_w = NULL;
|
|
|
|
}
|
|
|
|
|
1999-09-01 03:04:24 +00:00
|
|
|
/* Reload a file using the current read and display filters */
|
|
|
|
void
|
2003-10-16 00:45:12 +00:00
|
|
|
file_reload_cmd_cb(GtkWidget *w _U_, gpointer data _U_) {
|
2005-02-04 18:44:44 +00:00
|
|
|
cf_reload(&cfile);
|
Allow the user to save either all of the current capture, or only the
packets that are currently being displayed from that capture.
Centralize the code to control whether "File:Save" and "File:Save As"
are enabled (and *always* have "File:Save As" enabled if you have a
capture; "File:Save" is enabled only if you have a live capture you've
not yet saved, although it does the same thing as "File:Save As").
Have the "save_file" member of a "capture_file" structure represent
*only* the file currently being *written* to by a capture, and, if there
is no capture currently in progress, have it be NULL; the name of the
file currently being *displayed" is in the "filename" member, and an
"is_tempfile" member indicates whether it's a temporary file for a live
capture or not.
Have "close_cap_file()" delete the current capture file if it's a
temporary capture file that hasn't been saved (in its entirety - saving
selected frames doesn't count). Do the same (if there *is* a current
capture file) when exiting.
The "Ready to load or capture" message is the only statusbar message in
the "main" context; "close_cap_file()" should never pop it, it should
only pop whatever message exists in the "file" context, and thus has no
need to take, as an argument, the context for the message it should pop.
Update the man page to reflect the new behavior of "File:Save" and
"File:Save As", and to reflect recent changes to "Display:Match Selected".
svn path=/trunk/; revision=1170
1999-11-30 20:50:15 +00:00
|
|
|
}
|
2003-08-18 21:27:11 +00:00
|
|
|
|
|
|
|
/******************** Color Filters *********************************/
|
|
|
|
/*
|
|
|
|
* Keep a static pointer to the current "Color Export" window, if
|
|
|
|
* any, so that if somebody tries to do "Export"
|
|
|
|
* while there's already a "Color Export" window up, we just pop
|
|
|
|
* up the existing one, rather than creating a new one.
|
|
|
|
*/
|
|
|
|
static GtkWidget *file_color_import_w;
|
|
|
|
|
|
|
|
/* sets the file path to the global color filter file.
|
|
|
|
WARNING: called by both the import and the export dialog.
|
|
|
|
*/
|
|
|
|
static void
|
|
|
|
color_global_cb(GtkWidget *widget _U_, gpointer data)
|
|
|
|
{
|
|
|
|
GtkWidget *fs_widget = data;
|
2004-03-27 11:16:58 +00:00
|
|
|
gchar *path;
|
2003-08-18 21:27:11 +00:00
|
|
|
|
2004-03-27 11:16:58 +00:00
|
|
|
/* decide what file to open (from dfilter code) */
|
|
|
|
path = get_datafile_path("colorfilters");
|
2003-08-18 21:27:11 +00:00
|
|
|
|
2004-03-27 11:16:58 +00:00
|
|
|
gtk_file_chooser_select_filename(GTK_FILE_CHOOSER(fs_widget), path);
|
2008-04-27 07:01:58 +00:00
|
|
|
|
2009-10-27 09:58:57 +00:00
|
|
|
g_free(path);
|
2003-08-18 21:27:11 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Import color filters */
|
|
|
|
void
|
2007-01-22 00:20:33 +00:00
|
|
|
file_color_import_cmd_cb(GtkWidget *color_filters, gpointer filter_list _U_)
|
2003-08-18 21:27:11 +00:00
|
|
|
{
|
2008-04-06 22:25:36 +00:00
|
|
|
#if _WIN32
|
2006-10-03 18:39:36 +00:00
|
|
|
win32_import_color_file(GDK_WINDOW_HWND(top_level->window), color_filters);
|
2008-04-06 22:25:36 +00:00
|
|
|
#else /* _WIN32 */
|
2003-08-18 21:27:11 +00:00
|
|
|
GtkWidget *main_vb, *cfglobal_but;
|
2006-02-13 21:25:43 +00:00
|
|
|
|
2003-08-18 21:27:11 +00:00
|
|
|
/* No Apply button, and "OK" just sets our text widget, it doesn't
|
|
|
|
activate it (i.e., it doesn't cause us to try to open the file). */
|
|
|
|
|
|
|
|
if (file_color_import_w != NULL) {
|
|
|
|
/* There's already an "Import Color Filters" dialog box; reactivate it. */
|
|
|
|
reactivate_window(file_color_import_w);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2006-05-22 07:29:40 +00:00
|
|
|
file_color_import_w = file_selection_new("Wireshark: Import Color Filters",
|
2004-03-29 22:40:58 +00:00
|
|
|
FILE_SELECTION_OPEN);
|
2003-08-18 21:27:11 +00:00
|
|
|
|
|
|
|
/* Container for each row of widgets */
|
|
|
|
main_vb = gtk_vbox_new(FALSE, 3);
|
2008-06-29 15:51:43 +00:00
|
|
|
gtk_container_set_border_width(GTK_CONTAINER(main_vb), 5);
|
2004-03-29 22:55:13 +00:00
|
|
|
file_selection_set_extra_widget(file_color_import_w, main_vb);
|
2003-08-18 21:27:11 +00:00
|
|
|
gtk_widget_show(main_vb);
|
|
|
|
|
|
|
|
|
|
|
|
cfglobal_but = gtk_button_new_with_label("Global Color Filter File");
|
|
|
|
gtk_container_add(GTK_CONTAINER(main_vb), cfglobal_but);
|
2008-04-11 23:00:34 +00:00
|
|
|
g_signal_connect(cfglobal_but, "clicked",
|
|
|
|
G_CALLBACK(color_global_cb), file_color_import_w);
|
2003-08-18 21:27:11 +00:00
|
|
|
gtk_widget_show(cfglobal_but);
|
|
|
|
|
2008-04-11 23:00:34 +00:00
|
|
|
g_signal_connect(file_color_import_w, "destroy",
|
|
|
|
G_CALLBACK(file_color_import_destroy_cb), NULL);
|
2004-05-26 03:49:24 +00:00
|
|
|
|
2004-03-27 11:16:58 +00:00
|
|
|
|
|
|
|
if (gtk_dialog_run(GTK_DIALOG(file_color_import_w)) == GTK_RESPONSE_ACCEPT)
|
|
|
|
{
|
2006-10-03 18:39:36 +00:00
|
|
|
file_color_import_ok_cb(file_color_import_w, color_filters);
|
2004-03-27 11:16:58 +00:00
|
|
|
}
|
2004-05-26 03:49:24 +00:00
|
|
|
else window_destroy(file_color_import_w);
|
2008-04-06 22:25:36 +00:00
|
|
|
#endif /* _WIN32 */
|
2003-08-18 21:27:11 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2006-10-03 18:39:36 +00:00
|
|
|
file_color_import_ok_cb(GtkWidget *w, gpointer color_filters) {
|
2003-08-18 21:27:11 +00:00
|
|
|
gchar *cf_name, *s;
|
2006-10-03 18:39:36 +00:00
|
|
|
GtkWidget *fs = gtk_widget_get_toplevel(w);
|
2003-08-18 21:27:11 +00:00
|
|
|
|
2009-06-02 20:57:57 +00:00
|
|
|
cf_name = gtk_file_chooser_get_filename(GTK_FILE_CHOOSER(fs));
|
2008-04-27 07:01:58 +00:00
|
|
|
|
2003-08-18 21:27:11 +00:00
|
|
|
/* Perhaps the user specified a directory instead of a file.
|
|
|
|
Check whether they did. */
|
|
|
|
if (test_for_directory(cf_name) == EISDIR) {
|
|
|
|
/* It's a directory - set the file selection box to display that
|
2005-03-26 01:09:14 +00:00
|
|
|
directory, don't try to open the directory as a color filter file. */
|
2004-06-01 17:33:37 +00:00
|
|
|
set_last_open_dir(cf_name);
|
2003-08-18 21:27:11 +00:00
|
|
|
g_free(cf_name);
|
2004-06-01 17:33:37 +00:00
|
|
|
file_selection_set_current_folder(fs, get_last_open_dir());
|
2003-08-18 21:27:11 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2005-03-26 01:09:14 +00:00
|
|
|
/* Try to open the color filter file. */
|
2003-08-18 21:27:11 +00:00
|
|
|
|
2006-10-03 20:01:39 +00:00
|
|
|
if (!color_filters_import(cf_name, color_filters)) {
|
2003-08-18 21:27:11 +00:00
|
|
|
/* We couldn't open it; don't dismiss the open dialog box,
|
|
|
|
just leave it around so that the user can, after they
|
|
|
|
dismiss the alert box popped up for the open error,
|
|
|
|
try again. */
|
|
|
|
g_free(cf_name);
|
2008-01-26 17:04:49 +00:00
|
|
|
/* XXX - as we cannot start a new event loop (using gtk_dialog_run()),
|
|
|
|
* as this will prevent the user from closing the now existing error
|
|
|
|
* message, simply close the dialog (this is the best we can do here). */
|
2009-06-10 15:48:20 +00:00
|
|
|
window_destroy(GTK_WIDGET (fs));
|
2008-04-27 07:01:58 +00:00
|
|
|
|
2003-08-18 21:27:11 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* We've crossed the Rubicon; get rid of the file selection box. */
|
2004-05-26 03:49:24 +00:00
|
|
|
window_destroy(GTK_WIDGET (fs));
|
2003-08-18 21:27:11 +00:00
|
|
|
|
|
|
|
/* Save the name of the containing directory specified in the path name,
|
|
|
|
if any; we can write over cf_name, which is a good thing, given that
|
|
|
|
"get_dirname()" does write over its argument. */
|
|
|
|
s = get_dirname(cf_name);
|
|
|
|
set_last_open_dir(s);
|
2009-06-30 18:05:04 +00:00
|
|
|
#ifndef NEW_PACKET_LIST
|
2003-08-18 21:27:11 +00:00
|
|
|
gtk_widget_grab_focus(packet_list);
|
2009-06-30 18:05:04 +00:00
|
|
|
#endif
|
2003-08-18 21:27:11 +00:00
|
|
|
|
|
|
|
g_free(cf_name);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
file_color_import_destroy_cb(GtkWidget *win _U_, gpointer user_data _U_)
|
|
|
|
{
|
|
|
|
/* Note that we no longer have a "Open Capture File" dialog box. */
|
|
|
|
file_color_import_w = NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
static GtkWidget *file_color_export_w;
|
|
|
|
/*
|
2006-10-02 23:11:55 +00:00
|
|
|
* Set the "Export only selected filters" toggle button as appropriate for
|
|
|
|
* the current output file type and count of selected filters.
|
2003-08-18 21:27:11 +00:00
|
|
|
*
|
2006-10-02 23:11:55 +00:00
|
|
|
* Called when the "Export" dialog box is created and when the selected
|
2003-08-18 21:27:11 +00:00
|
|
|
* count changes.
|
|
|
|
*/
|
2005-08-02 04:47:15 +00:00
|
|
|
static void
|
2006-10-02 23:11:55 +00:00
|
|
|
color_set_export_selected_sensitive(GtkWidget * cfselect_cb)
|
2003-08-18 21:27:11 +00:00
|
|
|
{
|
|
|
|
if (file_color_export_w == NULL) {
|
|
|
|
/* We don't currently have an "Export" dialog box up. */
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2006-10-02 23:11:55 +00:00
|
|
|
/* We can request that only the selected filters be saved only if
|
|
|
|
there *are* selected filters. */
|
|
|
|
if (color_selected_count() != 0)
|
|
|
|
gtk_widget_set_sensitive(cfselect_cb, TRUE);
|
2003-08-18 21:27:11 +00:00
|
|
|
else {
|
2006-10-02 23:11:55 +00:00
|
|
|
/* Force the "Export only selected filters" toggle to "false", turn
|
2003-08-18 21:27:11 +00:00
|
|
|
off the flag it controls. */
|
2006-10-02 23:11:55 +00:00
|
|
|
color_selected = FALSE;
|
|
|
|
gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(cfselect_cb), FALSE);
|
|
|
|
gtk_widget_set_sensitive(cfselect_cb, FALSE);
|
2003-08-18 21:27:11 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2006-10-02 23:11:55 +00:00
|
|
|
color_toggle_selected_cb(GtkWidget *widget, gpointer data _U_)
|
2003-08-18 21:27:11 +00:00
|
|
|
{
|
2006-10-02 23:11:55 +00:00
|
|
|
color_selected = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON (widget));
|
2003-08-18 21:27:11 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2006-10-03 18:39:36 +00:00
|
|
|
file_color_export_cmd_cb(GtkWidget *w _U_, gpointer filter_list)
|
2003-08-18 21:27:11 +00:00
|
|
|
{
|
2008-04-06 22:25:36 +00:00
|
|
|
#if _WIN32
|
2006-10-03 18:39:36 +00:00
|
|
|
win32_export_color_file(GDK_WINDOW_HWND(top_level->window), filter_list);
|
2008-04-06 22:25:36 +00:00
|
|
|
#else /* _WIN32 */
|
2006-02-15 11:01:57 +00:00
|
|
|
GtkWidget *main_vb, *cfglobal_but;
|
2009-09-28 17:44:06 +00:00
|
|
|
GtkWidget *cfselect_cb;
|
2006-02-13 21:25:43 +00:00
|
|
|
|
2003-08-18 21:27:11 +00:00
|
|
|
if (file_color_export_w != NULL) {
|
|
|
|
/* There's already an "Color Filter Export" dialog box; reactivate it. */
|
|
|
|
reactivate_window(file_color_export_w);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2006-10-02 23:11:55 +00:00
|
|
|
color_selected = FALSE;
|
2003-08-18 21:27:11 +00:00
|
|
|
|
2006-05-22 07:29:40 +00:00
|
|
|
file_color_export_w = file_selection_new("Wireshark: Export Color Filters",
|
2004-03-29 22:40:58 +00:00
|
|
|
FILE_SELECTION_SAVE);
|
2003-08-18 21:27:11 +00:00
|
|
|
|
|
|
|
/* Container for each row of widgets */
|
|
|
|
main_vb = gtk_vbox_new(FALSE, 3);
|
2008-06-29 15:51:43 +00:00
|
|
|
gtk_container_set_border_width(GTK_CONTAINER(main_vb), 5);
|
2004-03-29 22:55:13 +00:00
|
|
|
file_selection_set_extra_widget(file_color_export_w, main_vb);
|
2003-08-18 21:27:11 +00:00
|
|
|
gtk_widget_show(main_vb);
|
|
|
|
|
2006-10-02 23:11:55 +00:00
|
|
|
cfselect_cb = gtk_check_button_new_with_label("Export only selected filters");
|
|
|
|
gtk_container_add(GTK_CONTAINER(main_vb), cfselect_cb);
|
|
|
|
gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(cfselect_cb), FALSE);
|
2008-04-11 23:00:34 +00:00
|
|
|
g_signal_connect(cfselect_cb, "toggled",
|
|
|
|
G_CALLBACK(color_toggle_selected_cb), NULL);
|
2006-10-02 23:11:55 +00:00
|
|
|
gtk_widget_show(cfselect_cb);
|
|
|
|
color_set_export_selected_sensitive(cfselect_cb);
|
2003-08-18 21:27:11 +00:00
|
|
|
|
|
|
|
cfglobal_but = gtk_button_new_with_label("Global Color Filter File");
|
|
|
|
gtk_container_add(GTK_CONTAINER(main_vb), cfglobal_but);
|
2008-04-11 23:00:34 +00:00
|
|
|
g_signal_connect(cfglobal_but, "clicked",
|
|
|
|
G_CALLBACK(color_global_cb), file_color_export_w);
|
2003-08-18 21:27:11 +00:00
|
|
|
gtk_widget_show(cfglobal_but);
|
|
|
|
|
2008-04-11 23:00:34 +00:00
|
|
|
g_signal_connect(file_color_export_w, "destroy",
|
|
|
|
G_CALLBACK(file_color_export_destroy_cb), NULL);
|
2004-05-26 03:49:24 +00:00
|
|
|
|
2004-03-27 11:16:58 +00:00
|
|
|
if (gtk_dialog_run(GTK_DIALOG(file_color_export_w)) == GTK_RESPONSE_ACCEPT)
|
|
|
|
{
|
2006-10-03 18:39:36 +00:00
|
|
|
file_color_export_ok_cb(file_color_export_w, filter_list);
|
2004-03-27 11:16:58 +00:00
|
|
|
}
|
2004-05-26 03:49:24 +00:00
|
|
|
else window_destroy(file_color_export_w);
|
2008-04-06 22:25:36 +00:00
|
|
|
#endif /* _WIN32 */
|
2003-08-18 21:27:11 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2006-10-03 18:39:36 +00:00
|
|
|
file_color_export_ok_cb(GtkWidget *w, gpointer filter_list) {
|
2003-08-18 21:27:11 +00:00
|
|
|
gchar *cf_name;
|
|
|
|
gchar *dirname;
|
2006-10-03 18:39:36 +00:00
|
|
|
GtkWidget *fs = gtk_widget_get_toplevel(w);
|
2003-08-18 21:27:11 +00:00
|
|
|
|
2009-06-02 20:57:57 +00:00
|
|
|
cf_name = gtk_file_chooser_get_filename(GTK_FILE_CHOOSER(fs));
|
2003-08-18 21:27:11 +00:00
|
|
|
|
|
|
|
/* Perhaps the user specified a directory instead of a file.
|
|
|
|
Check whether they did. */
|
|
|
|
if (test_for_directory(cf_name) == EISDIR) {
|
|
|
|
/* It's a directory - set the file selection box to display that
|
|
|
|
directory, and leave the selection box displayed. */
|
|
|
|
set_last_open_dir(cf_name);
|
|
|
|
g_free(cf_name);
|
2004-06-01 17:33:37 +00:00
|
|
|
file_selection_set_current_folder(fs, get_last_open_dir());
|
2003-08-18 21:27:11 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Write out the filters (all, or only the ones that are currently
|
2006-10-02 23:11:55 +00:00
|
|
|
displayed or selected) to the file with the specified name. */
|
2003-08-18 21:27:11 +00:00
|
|
|
|
2006-10-03 18:39:36 +00:00
|
|
|
if (!color_filters_export(cf_name, filter_list, color_selected))
|
2003-08-18 21:27:11 +00:00
|
|
|
{
|
|
|
|
/* The write failed; don't dismiss the open dialog box,
|
|
|
|
just leave it around so that the user can, after they
|
|
|
|
dismiss the alert box popped up for the error, try again. */
|
|
|
|
g_free(cf_name);
|
2008-04-27 07:01:58 +00:00
|
|
|
|
2008-01-26 17:04:49 +00:00
|
|
|
/* XXX - as we cannot start a new event loop (using gtk_dialog_run()),
|
|
|
|
* as this will prevent the user from closing the now existing error
|
|
|
|
* message, simply close the dialog (this is the best we can do here). */
|
2009-06-10 15:48:20 +00:00
|
|
|
window_destroy(GTK_WIDGET (fs));
|
2008-04-27 07:01:58 +00:00
|
|
|
|
2003-08-18 21:27:11 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* The write succeeded; get rid of the file selection box. */
|
2004-05-26 03:49:24 +00:00
|
|
|
window_destroy(GTK_WIDGET (fs));
|
2003-08-18 21:27:11 +00:00
|
|
|
|
|
|
|
/* Save the directory name for future file dialogs. */
|
|
|
|
dirname = get_dirname(cf_name); /* Overwrites cf_name */
|
|
|
|
set_last_open_dir(dirname);
|
|
|
|
g_free(cf_name);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
file_color_export_destroy_cb(GtkWidget *win _U_, gpointer user_data _U_)
|
|
|
|
{
|
|
|
|
file_color_export_w = NULL;
|
|
|
|
}
|