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
|
|
|
*
|
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
|
2012-06-28 22:56:06 +00:00
|
|
|
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
1999-09-09 04:25:49 +00:00
|
|
|
*/
|
|
|
|
|
1999-09-01 03:04:24 +00:00
|
|
|
#include "config.h"
|
|
|
|
|
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
|
|
|
|
2013-11-17 02:55:14 +00:00
|
|
|
#include <wsutil/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
|
|
|
|
2012-10-05 18:52:42 +00:00
|
|
|
#include "globals.h"
|
2015-12-22 20:07:00 +00:00
|
|
|
#include <epan/color_filters.h>
|
2012-10-05 18:52:42 +00:00
|
|
|
|
2008-05-22 15:46:27 +00:00
|
|
|
#include <wsutil/file_util.h>
|
2004-01-29 23:11:38 +00:00
|
|
|
|
2013-07-16 02:35:33 +00:00
|
|
|
#include <wiretap/merge.h>
|
|
|
|
|
|
|
|
#include "ui/util.h"
|
2012-01-16 01:07:52 +00:00
|
|
|
#include "ui/alert_box.h"
|
2015-12-22 20:07:00 +00:00
|
|
|
#include "ui/simple_dialog.h"
|
2012-09-24 18:59:44 +00:00
|
|
|
#include "ui/file_dialog.h"
|
2012-01-18 19:38:34 +00:00
|
|
|
#include "ui/recent.h"
|
2012-01-16 01:07:52 +00:00
|
|
|
#include "ui/ui_util.h"
|
|
|
|
|
2012-01-15 21:59:11 +00:00
|
|
|
#include "ui/gtk/gtkglobals.h"
|
2014-02-25 18:08:43 +00:00
|
|
|
#include "ui/gtk/old-gtk-compat.h"
|
2012-01-15 21:59:11 +00:00
|
|
|
#include "ui/gtk/keys.h"
|
|
|
|
#include "ui/gtk/filter_dlg.h"
|
|
|
|
#include "ui/gtk/gui_utils.h"
|
|
|
|
#include "ui/gtk/dlg_utils.h"
|
|
|
|
#include "ui/gtk/file_dlg.h"
|
|
|
|
#include "ui/gtk/capture_file_dlg.h"
|
|
|
|
#include "ui/gtk/drag_and_drop.h"
|
2013-08-21 21:44:48 +00:00
|
|
|
#include "ui/gtk/export_pdu_dlg.h"
|
2012-01-15 21:59:11 +00:00
|
|
|
#include "ui/gtk/main.h"
|
|
|
|
#include "ui/gtk/color_dlg.h"
|
2012-09-04 01:57:36 +00:00
|
|
|
#include "ui/gtk/packet_list.h"
|
2008-04-13 00:55:59 +00:00
|
|
|
#ifdef HAVE_LIBPCAP
|
2012-01-15 21:59:11 +00:00
|
|
|
#include "ui/gtk/capture_dlg.h"
|
2004-06-30 07:12:25 +00:00
|
|
|
#endif
|
2012-01-15 21:59:11 +00:00
|
|
|
#include "ui/gtk/stock_icons.h"
|
|
|
|
#include "ui/gtk/range_utils.h"
|
|
|
|
#include "ui/gtk/filter_autocomplete.h"
|
2004-06-30 07:12:25 +00:00
|
|
|
|
2012-06-21 22:21:02 +00:00
|
|
|
#ifdef _WIN32
|
|
|
|
#define USE_WIN32_FILE_DIALOGS
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifdef USE_WIN32_FILE_DIALOGS
|
2006-02-13 21:25:43 +00:00
|
|
|
#include <gdk/gdkwin32.h>
|
|
|
|
#include <windows.h>
|
2012-01-16 01:29:08 +00:00
|
|
|
#include "ui/win32/file_dlg_win32.h"
|
2006-02-13 21:25:43 +00:00
|
|
|
#endif
|
|
|
|
|
2012-05-25 21:25:55 +00:00
|
|
|
static void do_file_save(capture_file *cf, gboolean dont_reopen);
|
2013-04-01 20:36:42 +00:00
|
|
|
static void file_save_as_cmd(capture_file *cf,
|
|
|
|
gboolean must_support_all_comments,
|
2012-06-20 04:44:14 +00:00
|
|
|
gboolean dont_reopen);
|
2012-06-04 10:27:59 +00:00
|
|
|
static void file_select_file_type_cb(GtkWidget *w, gpointer data);
|
2012-06-25 17:56:29 +00:00
|
|
|
static int set_file_type_list(GtkWidget *combo_box, capture_file *cf,
|
2013-04-01 20:36:42 +00:00
|
|
|
gboolean must_support_all_comments);
|
2012-08-19 21:24:02 +00:00
|
|
|
static gboolean test_file_close(capture_file *cf, gboolean from_quit,
|
|
|
|
const char *before_what);
|
2010-03-21 19:26:32 +00:00
|
|
|
|
|
|
|
#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
|
|
|
|
2004-06-19 10:48:06 +00:00
|
|
|
#define PREVIEW_TABLE_KEY "preview_table_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"
|
|
|
|
|
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 gboolean color_selected;
|
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 */
|
2014-05-09 05:18:49 +00:00
|
|
|
static wtap *
|
2004-06-19 10:48:06 +00:00
|
|
|
preview_set_filename(GtkWidget *prev, const gchar *cf_name)
|
|
|
|
{
|
2013-01-10 03:35:16 +00:00
|
|
|
GtkWidget *label;
|
2014-05-09 05:18:49 +00:00
|
|
|
wtap *wth;
|
2013-01-10 03:35:16 +00:00
|
|
|
int err = 0;
|
|
|
|
gchar *err_info;
|
|
|
|
gchar string_buff[PREVIEW_STR_MAX];
|
|
|
|
gint64 filesize;
|
|
|
|
|
|
|
|
|
|
|
|
/* init preview labels */
|
|
|
|
label = (GtkWidget *)g_object_get_data(G_OBJECT(prev), PREVIEW_FORMAT_KEY);
|
|
|
|
gtk_label_set_text(GTK_LABEL(label), "-");
|
|
|
|
label = (GtkWidget *)g_object_get_data(G_OBJECT(prev), PREVIEW_SIZE_KEY);
|
|
|
|
gtk_label_set_text(GTK_LABEL(label), "-");
|
|
|
|
label = (GtkWidget *)g_object_get_data(G_OBJECT(prev), PREVIEW_ELAPSED_KEY);
|
|
|
|
gtk_label_set_text(GTK_LABEL(label), "-");
|
|
|
|
label = (GtkWidget *)g_object_get_data(G_OBJECT(prev), PREVIEW_PACKETS_KEY);
|
|
|
|
gtk_label_set_text(GTK_LABEL(label), "-");
|
|
|
|
label = (GtkWidget *)g_object_get_data(G_OBJECT(prev), PREVIEW_FIRST_KEY);
|
|
|
|
gtk_label_set_text(GTK_LABEL(label), "-");
|
|
|
|
|
|
|
|
if (!cf_name) {
|
|
|
|
return NULL;
|
|
|
|
}
|
2004-08-31 08:18:10 +00:00
|
|
|
|
2013-01-10 03:35:16 +00:00
|
|
|
if (test_for_directory(cf_name) == EISDIR) {
|
2011-12-01 06:33:14 +00:00
|
|
|
label = (GtkWidget *)g_object_get_data(G_OBJECT(prev), PREVIEW_FORMAT_KEY);
|
2013-01-10 03:35:16 +00:00
|
|
|
gtk_label_set_text(GTK_LABEL(label), "directory");
|
|
|
|
return NULL;
|
|
|
|
}
|
2004-06-20 18:36:16 +00:00
|
|
|
|
2014-01-18 14:20:02 +00:00
|
|
|
wth = wtap_open_offline(cf_name, WTAP_TYPE_AUTO, &err, &err_info, TRUE);
|
2013-01-10 03:35:16 +00:00
|
|
|
if (wth == NULL) {
|
|
|
|
label = (GtkWidget *)g_object_get_data(G_OBJECT(prev), PREVIEW_FORMAT_KEY);
|
|
|
|
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");
|
2004-06-19 10:48:06 +00:00
|
|
|
}
|
2013-01-10 03:35:16 +00:00
|
|
|
return NULL;
|
|
|
|
}
|
2004-06-19 10:48:06 +00:00
|
|
|
|
2013-01-10 03:35:16 +00:00
|
|
|
/* Find the size of the file. */
|
2014-05-09 05:18:49 +00:00
|
|
|
filesize = wtap_file_size(wth, &err);
|
2013-01-10 03:35:16 +00:00
|
|
|
if (filesize == -1) {
|
|
|
|
gtk_label_set_text(GTK_LABEL(label), "error getting file size");
|
|
|
|
wtap_close(wth);
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
g_snprintf(string_buff, PREVIEW_STR_MAX, "%" G_GINT64_MODIFIER "d bytes", filesize);
|
|
|
|
label = (GtkWidget *)g_object_get_data(G_OBJECT(prev), PREVIEW_SIZE_KEY);
|
|
|
|
gtk_label_set_text(GTK_LABEL(label), string_buff);
|
2004-06-19 10:48:06 +00:00
|
|
|
|
2013-01-10 03:35:16 +00:00
|
|
|
/* type */
|
2014-05-09 05:18:49 +00:00
|
|
|
g_strlcpy(string_buff, wtap_file_type_subtype_string(wtap_file_type_subtype(wth)), PREVIEW_STR_MAX);
|
2013-01-10 03:35:16 +00:00
|
|
|
label = (GtkWidget *)g_object_get_data(G_OBJECT(prev), PREVIEW_FORMAT_KEY);
|
|
|
|
gtk_label_set_text(GTK_LABEL(label), string_buff);
|
2004-06-19 10:48:06 +00:00
|
|
|
|
2013-01-10 03:35:16 +00:00
|
|
|
return wth;
|
2004-08-31 08:18:10 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/* do a preview run on the currently selected capture file */
|
|
|
|
static void
|
2014-05-09 05:18:49 +00:00
|
|
|
preview_do(GtkWidget *prev, wtap *wth)
|
2004-08-31 08:18:10 +00:00
|
|
|
{
|
2013-01-10 03:35:16 +00:00
|
|
|
GtkWidget *label;
|
|
|
|
unsigned int elapsed_time;
|
|
|
|
time_t time_preview;
|
|
|
|
time_t time_current;
|
|
|
|
int err = 0;
|
|
|
|
gchar *err_info;
|
|
|
|
gint64 data_offset;
|
|
|
|
double start_time = 0; /* seconds, with nsec resolution */
|
|
|
|
double stop_time = 0; /* seconds, with nsec resolution */
|
|
|
|
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;
|
|
|
|
const struct wtap_pkthdr *phdr;
|
|
|
|
|
|
|
|
|
|
|
|
time(&time_preview);
|
2014-05-23 10:50:02 +00:00
|
|
|
while ( (wtap_read(wth, &err, &err_info, &data_offset)) ) {
|
|
|
|
phdr = wtap_phdr(wth);
|
|
|
|
cur_time = nstime_to_sec(&phdr->ts);
|
|
|
|
if (packets == 0) {
|
|
|
|
start_time = cur_time;
|
|
|
|
stop_time = cur_time;
|
2014-05-23 03:01:31 +00:00
|
|
|
}
|
2014-05-23 10:50:02 +00:00
|
|
|
if (cur_time < start_time) {
|
|
|
|
start_time = cur_time;
|
|
|
|
}
|
|
|
|
if (cur_time > stop_time) {
|
|
|
|
stop_time = cur_time;
|
|
|
|
}
|
|
|
|
|
|
|
|
packets++;
|
|
|
|
if (packets%1000 == 0) {
|
2013-01-10 03:35:16 +00:00
|
|
|
/* do we have a timeout? */
|
|
|
|
time(&time_current);
|
|
|
|
if (time_current-time_preview >= (time_t) prefs.gui_fileopen_preview) {
|
|
|
|
is_breaked = TRUE;
|
|
|
|
break;
|
|
|
|
}
|
2012-06-20 05:48:06 +00:00
|
|
|
}
|
2013-01-10 03:35:16 +00:00
|
|
|
}
|
2004-06-19 10:48:06 +00:00
|
|
|
|
2013-01-10 03:35:16 +00:00
|
|
|
if (err != 0) {
|
|
|
|
g_snprintf(string_buff, PREVIEW_STR_MAX, "error after reading %u packets", packets);
|
|
|
|
label = (GtkWidget *)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);
|
2013-01-10 03:35:16 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* packet count */
|
|
|
|
if (is_breaked) {
|
|
|
|
g_snprintf(string_buff, PREVIEW_STR_MAX, "more than %u packets (preview timeout)", packets);
|
|
|
|
} else {
|
|
|
|
g_snprintf(string_buff, PREVIEW_STR_MAX, "%u", packets);
|
|
|
|
}
|
2013-03-08 07:09:39 +00:00
|
|
|
label = (GtkWidget *)g_object_get_data(G_OBJECT(prev), PREVIEW_PACKETS_KEY);
|
2013-01-10 03:35:16 +00:00
|
|
|
gtk_label_set_text(GTK_LABEL(label), string_buff);
|
|
|
|
|
|
|
|
/* first packet */
|
|
|
|
ti_time = (long)start_time;
|
|
|
|
ti_tm = localtime( &ti_time );
|
|
|
|
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, "?");
|
|
|
|
}
|
2013-03-08 07:09:39 +00:00
|
|
|
label = (GtkWidget *)g_object_get_data(G_OBJECT(prev), PREVIEW_FIRST_KEY);
|
2013-01-10 03:35:16 +00:00
|
|
|
gtk_label_set_text(GTK_LABEL(label), string_buff);
|
|
|
|
|
|
|
|
/* elapsed time */
|
|
|
|
elapsed_time = (unsigned int)(stop_time-start_time);
|
|
|
|
if (elapsed_time/86400) {
|
|
|
|
g_snprintf(string_buff, PREVIEW_STR_MAX, "%02u days %02u:%02u:%02u",
|
|
|
|
elapsed_time/86400, elapsed_time%86400/3600, elapsed_time%3600/60, elapsed_time%60);
|
|
|
|
} else {
|
|
|
|
g_snprintf(string_buff, PREVIEW_STR_MAX, "%02u:%02u:%02u",
|
|
|
|
elapsed_time%86400/3600, elapsed_time%3600/60, elapsed_time%60);
|
|
|
|
}
|
|
|
|
if (is_breaked) {
|
|
|
|
g_snprintf(string_buff, PREVIEW_STR_MAX, "unknown");
|
|
|
|
}
|
|
|
|
label = (GtkWidget *)g_object_get_data(G_OBJECT(prev), PREVIEW_ELAPSED_KEY);
|
|
|
|
gtk_label_set_text(GTK_LABEL(label), string_buff);
|
|
|
|
|
|
|
|
wtap_close(wth);
|
2004-06-19 10:48:06 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#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)
|
|
|
|
{
|
2013-01-10 03:35:16 +00:00
|
|
|
GtkWidget *prev = GTK_WIDGET(data);
|
|
|
|
char *cf_name;
|
|
|
|
gboolean have_preview;
|
2004-06-19 10:48:06 +00:00
|
|
|
|
2013-01-10 03:35:16 +00:00
|
|
|
cf_name = gtk_file_chooser_get_preview_filename(file_chooser);
|
2004-06-19 10:48:06 +00:00
|
|
|
|
2013-01-10 03:35:16 +00:00
|
|
|
have_preview = preview_set_filename(prev, cf_name);
|
2004-06-19 10:48:06 +00:00
|
|
|
|
2013-01-10 03:35:16 +00:00
|
|
|
g_free(cf_name);
|
2004-06-19 10:48:06 +00:00
|
|
|
|
2013-01-10 03:35:16 +00:00
|
|
|
have_preview = TRUE;
|
|
|
|
gtk_file_chooser_set_preview_widget_active(file_chooser, have_preview);
|
2004-06-19 10:48:06 +00:00
|
|
|
}
|
|
|
|
#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
|
|
|
{
|
2013-01-10 03:35:16 +00:00
|
|
|
GtkWidget *prev = (GtkWidget *)g_object_get_data(G_OBJECT(file_sel), PREVIEW_TABLE_KEY);
|
|
|
|
gchar *cf_name;
|
|
|
|
gboolean have_preview;
|
2014-05-09 05:18:49 +00:00
|
|
|
wtap *wth;
|
2013-01-10 03:35:16 +00:00
|
|
|
|
|
|
|
/* get the filename */
|
|
|
|
cf_name = gtk_file_chooser_get_filename(GTK_FILE_CHOOSER(file_sel));
|
|
|
|
|
|
|
|
/* set the filename to the preview */
|
|
|
|
wth = preview_set_filename(prev, cf_name);
|
|
|
|
have_preview = (wth != NULL);
|
|
|
|
|
|
|
|
g_free(cf_name);
|
|
|
|
|
|
|
|
/* make the preview widget sensitive */
|
|
|
|
gtk_widget_set_sensitive(prev, have_preview);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* 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...
|
|
|
|
*/
|
2010-05-12 19:44:23 +00:00
|
|
|
#if 0
|
2013-01-10 03:35:16 +00:00
|
|
|
/* make the open/save/... dialog button sensitive */
|
2008-04-27 07:01:58 +00:00
|
|
|
|
2013-01-10 03:35:16 +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
|
|
|
|
2013-01-10 03:35:16 +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 *
|
2013-01-09 21:04:44 +00:00
|
|
|
add_string_to_grid_sensitive(GtkWidget *grid, guint *row, const gchar *title, const gchar *value, gboolean sensitive)
|
2004-06-19 10:48:06 +00:00
|
|
|
{
|
2013-01-10 03:35:16 +00:00
|
|
|
GtkWidget *label;
|
|
|
|
gchar *indent;
|
2004-06-19 10:48:06 +00:00
|
|
|
|
2013-01-10 03:35:16 +00:00
|
|
|
if (strlen(value) != 0) {
|
|
|
|
indent = g_strdup_printf(" %s", title);
|
|
|
|
} else {
|
|
|
|
indent = g_strdup(title);
|
|
|
|
}
|
|
|
|
label = gtk_label_new(indent);
|
|
|
|
g_free(indent);
|
|
|
|
gtk_misc_set_alignment(GTK_MISC(label), 0.0f, 0.5f);
|
|
|
|
gtk_widget_set_sensitive(label, sensitive);
|
|
|
|
ws_gtk_grid_attach_defaults(GTK_GRID(grid), label, 0, *row, 1, 1);
|
2004-06-19 10:48:06 +00:00
|
|
|
|
2013-01-10 03:35:16 +00:00
|
|
|
label = gtk_label_new(value);
|
|
|
|
gtk_misc_set_alignment(GTK_MISC(label), 0.0f, 0.5f);
|
|
|
|
gtk_widget_set_sensitive(label, sensitive);
|
|
|
|
ws_gtk_grid_attach_defaults(GTK_GRID(grid), label, 1, *row, 1, 1);
|
2004-06-19 10:48:06 +00:00
|
|
|
|
2013-01-10 03:35:16 +00:00
|
|
|
*row = *row + 1;
|
2004-06-19 10:48:06 +00:00
|
|
|
|
2013-01-10 03:35:16 +00:00
|
|
|
return label;
|
2004-06-19 10:48:06 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static GtkWidget *
|
2013-01-09 21:04:44 +00:00
|
|
|
add_string_to_grid(GtkWidget *grid, guint *row, const gchar *title, const gchar *value)
|
2004-06-19 10:48:06 +00:00
|
|
|
{
|
2013-01-10 03:35:16 +00:00
|
|
|
return add_string_to_grid_sensitive(grid, row, title, value, TRUE);
|
2004-06-19 10:48:06 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
static GtkWidget *
|
|
|
|
preview_new(void)
|
|
|
|
{
|
2013-01-10 03:35:16 +00:00
|
|
|
GtkWidget *grid, *label;
|
|
|
|
guint row;
|
|
|
|
|
|
|
|
grid = ws_gtk_grid_new();
|
|
|
|
ws_gtk_grid_set_column_spacing(GTK_GRID(grid), 6);
|
|
|
|
ws_gtk_grid_set_row_spacing(GTK_GRID(grid), 3);
|
|
|
|
row = 0;
|
|
|
|
|
|
|
|
label = add_string_to_grid(grid, &row, "Format:", "-");
|
|
|
|
g_object_set_data(G_OBJECT(grid), PREVIEW_FORMAT_KEY, label);
|
|
|
|
label = add_string_to_grid(grid, &row, "Size:", "-");
|
|
|
|
g_object_set_data(G_OBJECT(grid), PREVIEW_SIZE_KEY, label);
|
|
|
|
label = add_string_to_grid(grid, &row, "Packets:", "-");
|
|
|
|
g_object_set_data(G_OBJECT(grid), PREVIEW_PACKETS_KEY, label);
|
|
|
|
label = add_string_to_grid(grid, &row, "First Packet:", "-");
|
|
|
|
g_object_set_data(G_OBJECT(grid), PREVIEW_FIRST_KEY, label);
|
|
|
|
label = add_string_to_grid(grid, &row, "Elapsed time:", "-");
|
|
|
|
g_object_set_data(G_OBJECT(grid), PREVIEW_ELAPSED_KEY, label);
|
|
|
|
|
|
|
|
return grid;
|
2004-06-19 10:48:06 +00:00
|
|
|
}
|
2003-11-30 04:21:55 +00:00
|
|
|
|
2012-07-16 20:46:13 +00:00
|
|
|
#ifndef USE_WIN32_FILE_DIALOGS
|
2013-01-09 22:03:40 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
------------------------------------------------
|
|
|
|
|top_level win |
|
|
|
|
| ------------------------------------------- |
|
2013-01-10 02:51:36 +00:00
|
|
|
| |file_chooser_dialog [vbox] | |
|
2013-01-09 22:03:40 +00:00
|
|
|
| | -------------------------------------- | |
|
2013-01-10 02:51:36 +00:00
|
|
|
| | |[file_browser] T/T | | |
|
2013-01-09 22:03:40 +00:00
|
|
|
| | | | | |
|
|
|
|
| | | | | |
|
|
|
|
| | | | | |
|
|
|
|
| | -------------------------------------- | |
|
|
|
|
| | | |
|
|
|
|
| | -------------------------------------- | |
|
2013-01-10 02:51:36 +00:00
|
|
|
| | |[alignment] F/F | | |
|
|
|
|
| | | -------------------------------- | | |
|
|
|
|
| | | |main_hb [extra_widget] | | | |
|
|
|
|
| | | | ------------- ---------- | | | |
|
|
|
|
| | | | |main_vb F/F| |grid F/F| | | | |
|
|
|
|
| | | | | item | | row | | | | |
|
|
|
|
| | | | | item | | row | | | | |
|
|
|
|
| | | | | item | | row | | | | |
|
|
|
|
| | | | | item | | row | | | | |
|
|
|
|
| | | | | item | | row | | | | |
|
|
|
|
| | | | ------------- ---------- | | | |
|
|
|
|
| | | -------------------------------- | | |
|
2013-01-09 22:03:40 +00:00
|
|
|
| | -------------------------------------- | |
|
|
|
|
| | | |
|
|
|
|
| | -------------------------------------- | |
|
2013-01-10 02:51:36 +00:00
|
|
|
| | |btn_row F/F | | |
|
2013-01-09 22:03:40 +00:00
|
|
|
| | -------------------------------------- | |
|
|
|
|
| ------------------------------------------- |
|
|
|
|
------------------------------------------------
|
|
|
|
|
2013-01-10 02:51:36 +00:00
|
|
|
Notes:
|
|
|
|
1. T/T & F/F above refer to the
|
|
|
|
gtk_box_pack_start() 'expand'/'fill' args
|
|
|
|
used to pack the widget into the enclosing GtkBox.
|
|
|
|
2. The 'Alignment' widget is actually internal to
|
|
|
|
the GtkFileChooser widget.
|
|
|
|
|
2013-01-09 22:03:40 +00:00
|
|
|
Gtk3: Expand/Fill effect
|
|
|
|
|
|
|
|
Vertical
|
2013-01-10 02:51:36 +00:00
|
|
|
(file_chooser): expand/fills.
|
2013-01-09 22:03:40 +00:00
|
|
|
main_hb does not expand/fill [explicitly set via vexpand = FALSE].
|
|
|
|
btn_row does not expand/fill.
|
|
|
|
So: vertical resize (drog lower edge down).
|
|
|
|
expands (file_chooser) but leaves others as is.
|
|
|
|
Also: grid rows are "vexpand' so grid
|
|
|
|
vertically epands/fills in main_hb.
|
|
|
|
That is: it will be the same height as
|
|
|
|
the main_vb.
|
|
|
|
Since vexpand is "inherited upwards", main_hb vexpand set to FALSE
|
|
|
|
to prevent vertical expansion of same.
|
|
|
|
|
2013-01-10 02:51:36 +00:00
|
|
|
Horizontal
|
|
|
|
(file_chooser) & btn_row: expand/fill.
|
|
|
|
main_vb & grid do not expand.
|
|
|
|
So: horizontal resize (drag right edge to the right)
|
|
|
|
expands all but the "extra widget".
|
2013-01-09 22:03:40 +00:00
|
|
|
*/
|
|
|
|
|
1999-09-01 03:04:24 +00:00
|
|
|
/* Open a file */
|
2012-07-16 20:46:13 +00:00
|
|
|
static gboolean
|
2014-01-18 14:20:02 +00:00
|
|
|
gtk_open_file(GtkWidget *w, GString *file_name, gint *type, GString *display_filter)
|
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
|
|
|
{
|
2013-01-09 21:04:44 +00:00
|
|
|
GtkWidget *file_open_w;
|
|
|
|
GtkWidget *main_hb, *main_vb, *filter_hbox, *filter_bt, *filter_te;
|
|
|
|
GtkWidget *m_resolv_cb, *n_resolv_cb, *t_resolv_cb, *e_resolv_cb, *prev;
|
2014-01-18 14:20:02 +00:00
|
|
|
GtkWidget *format_type_co;
|
|
|
|
GtkCellRenderer *cell;
|
|
|
|
gint i;
|
2013-01-09 21:04:44 +00:00
|
|
|
|
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 = {
|
2012-07-16 20:46:13 +00:00
|
|
|
"Wireshark: Display Filter",
|
2012-06-04 18:41:36 +00:00
|
|
|
FALSE,
|
|
|
|
FALSE,
|
2005-12-31 17:09:27 +00:00
|
|
|
TRUE
|
2001-01-21 02:27:24 +00:00
|
|
|
};
|
2012-07-16 20:46:13 +00:00
|
|
|
gchar *cf_name;
|
|
|
|
|
|
|
|
if (!file_name || !display_filter)
|
|
|
|
return FALSE;
|
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
|
|
|
|
2006-05-22 07:29:40 +00:00
|
|
|
file_open_w = file_selection_new("Wireshark: Open Capture File",
|
2013-05-14 21:53:57 +00:00
|
|
|
GTK_WINDOW(top_level),
|
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
|
|
|
|
2012-07-16 20:46:13 +00:00
|
|
|
if (file_name->len > 0) {
|
2012-07-17 21:44:41 +00:00
|
|
|
gchar *dirname = g_path_get_dirname(file_name->str);
|
|
|
|
|
|
|
|
file_selection_set_current_folder(file_open_w, dirname);
|
|
|
|
g_free(dirname);
|
2012-07-16 20:46:13 +00:00
|
|
|
} else {
|
|
|
|
switch (prefs.gui_fileopen_style) {
|
2012-07-16 21:01:16 +00:00
|
|
|
|
2013-01-10 03:35:16 +00:00
|
|
|
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_open_w, prefs.gui_fileopen_dir);
|
|
|
|
break;
|
2012-07-16 20:46:13 +00:00
|
|
|
}
|
2003-10-14 23:20:17 +00:00
|
|
|
}
|
2004-06-19 10:48:06 +00:00
|
|
|
|
2012-06-02 23:53:04 +00:00
|
|
|
main_hb = ws_gtk_box_new(GTK_ORIENTATION_HORIZONTAL, 3, FALSE);
|
2013-01-09 21:04:44 +00:00
|
|
|
#if GTK_CHECK_VERSION(3,0,0)
|
|
|
|
gtk_widget_set_vexpand(main_hb, FALSE); /* prevents "inheritance" from child VEXPAND */
|
|
|
|
/* so hbox doesn't expand vertically even */
|
|
|
|
/* tho grid rows have VEXPAND. */
|
|
|
|
#endif
|
2004-06-19 10:48:06 +00:00
|
|
|
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 */
|
2012-06-02 23:53:04 +00:00
|
|
|
main_vb = ws_gtk_box_new(GTK_ORIENTATION_VERTICAL, 3, FALSE);
|
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
|
|
|
|
2014-01-18 14:20:02 +00:00
|
|
|
format_type_co = gtk_combo_box_text_new();
|
|
|
|
cell = gtk_cell_renderer_text_new();
|
|
|
|
gtk_cell_layout_pack_start(GTK_CELL_LAYOUT(format_type_co), cell, TRUE);
|
|
|
|
|
|
|
|
gtk_widget_set_tooltip_text(format_type_co, "Format type of capture file");
|
|
|
|
gtk_box_pack_start(GTK_BOX(main_vb), format_type_co, FALSE, FALSE, 0);
|
|
|
|
|
2014-02-25 18:37:58 +00:00
|
|
|
gtk_combo_box_text_append_text(GTK_COMBO_BOX_TEXT(format_type_co), (const gchar *) "Automatic");
|
2014-01-18 14:20:02 +00:00
|
|
|
for (i = 0; open_routines[i].name != NULL; i += 1) {
|
2014-02-25 18:37:58 +00:00
|
|
|
gtk_combo_box_text_append_text(GTK_COMBO_BOX_TEXT(format_type_co), open_routines[i].name);
|
2014-01-18 14:20:02 +00:00
|
|
|
}
|
|
|
|
|
2014-02-25 18:37:58 +00:00
|
|
|
gtk_combo_box_set_active(GTK_COMBO_BOX(format_type_co), 0);
|
2014-01-18 14:20:02 +00:00
|
|
|
gtk_widget_show(format_type_co);
|
|
|
|
|
2012-09-10 21:27:49 +00:00
|
|
|
/* Filter row */
|
2012-06-02 23:53:04 +00:00
|
|
|
filter_hbox = ws_gtk_box_new(GTK_ORIENTATION_HORIZONTAL, 1, FALSE);
|
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);
|
|
|
|
|
2014-02-21 13:09:52 +00:00
|
|
|
filter_bt = ws_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);
|
2013-01-09 21:04:44 +00:00
|
|
|
gtk_box_pack_start(GTK_BOX(filter_hbox), filter_bt, FALSE, FALSE, 0);
|
1999-09-01 03:04:24 +00:00
|
|
|
gtk_widget_show(filter_bt);
|
2012-09-10 21:27:49 +00:00
|
|
|
gtk_widget_set_tooltip_text(filter_bt, "Open the \"Display Filter\" dialog to edit/apply filters");
|
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);
|
2013-01-09 21:04:44 +00:00
|
|
|
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);
|
2012-07-16 21:01:16 +00:00
|
|
|
gtk_entry_set_text(GTK_ENTRY(filter_te), display_filter->str);
|
1999-09-01 03:04:24 +00:00
|
|
|
gtk_widget_show(filter_te);
|
2011-02-12 00:27:47 +00:00
|
|
|
gtk_widget_set_tooltip_text(filter_te, "Enter a display filter.");
|
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
|
|
|
|
2012-09-10 21:27:49 +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),
|
2012-07-06 04:48:36 +00:00
|
|
|
gbl_resolv_flags.mac_name);
|
2001-05-31 08:36:46 +00:00
|
|
|
gtk_box_pack_start(GTK_BOX(main_vb), m_resolv_cb, FALSE, FALSE, 0);
|
2004-03-27 11:16:58 +00:00
|
|
|
gtk_widget_show(m_resolv_cb);
|
2001-05-31 08:36:46 +00:00
|
|
|
|
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),
|
2012-07-06 04:48:36 +00:00
|
|
|
gbl_resolv_flags.transport_name);
|
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);
|
2012-07-10 07:50:34 +00:00
|
|
|
|
|
|
|
n_resolv_cb = gtk_check_button_new_with_mnemonic("Enable _network name resolution");
|
|
|
|
gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(n_resolv_cb),
|
|
|
|
gbl_resolv_flags.network_name);
|
|
|
|
gtk_box_pack_start(GTK_BOX(main_vb), n_resolv_cb, FALSE, FALSE, 0);
|
|
|
|
gtk_widget_show(n_resolv_cb);
|
|
|
|
|
2012-07-09 01:36:54 +00:00
|
|
|
e_resolv_cb = gtk_check_button_new_with_mnemonic("Use _external network name resolver");
|
|
|
|
gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(e_resolv_cb),
|
|
|
|
gbl_resolv_flags.use_external_net_name_resolver);
|
|
|
|
gtk_box_pack_start(GTK_BOX(main_vb), e_resolv_cb, FALSE, FALSE, 0);
|
|
|
|
gtk_widget_show(e_resolv_cb);
|
2004-05-26 03:49:24 +00:00
|
|
|
|
2012-09-10 21:27:49 +00:00
|
|
|
/* Preview widget */
|
2004-06-19 10:48:06 +00:00
|
|
|
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);
|
2013-01-10 02:51:36 +00:00
|
|
|
gtk_box_pack_start(GTK_BOX(main_hb), prev, FALSE, FALSE, 0);
|
2004-06-19 10:48:06 +00:00
|
|
|
|
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));
|
2000-01-01 04:28:45 +00:00
|
|
|
|
2012-07-16 20:46:13 +00:00
|
|
|
cf_name = file_selection_run(file_open_w);
|
2012-09-24 17:04:50 +00:00
|
|
|
|
2012-07-16 20:46:13 +00:00
|
|
|
if (cf_name == NULL) {
|
|
|
|
/* User cancelled or closed the dialog. */
|
|
|
|
return FALSE;
|
|
|
|
}
|
2008-04-27 07:01:58 +00:00
|
|
|
|
2012-07-16 20:46:13 +00:00
|
|
|
g_string_printf(file_name, "%s", cf_name);
|
|
|
|
g_free(cf_name);
|
|
|
|
g_string_printf(display_filter, "%s", gtk_entry_get_text(GTK_ENTRY(filter_te)));
|
|
|
|
|
|
|
|
/* Set the global resolving variable */
|
|
|
|
if (gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(m_resolv_cb)))
|
|
|
|
gbl_resolv_flags.mac_name = TRUE;
|
|
|
|
else
|
|
|
|
gbl_resolv_flags.mac_name = FALSE;
|
|
|
|
if (gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(n_resolv_cb)))
|
|
|
|
gbl_resolv_flags.network_name = TRUE;
|
|
|
|
else
|
|
|
|
gbl_resolv_flags.network_name = FALSE;
|
|
|
|
if (gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(t_resolv_cb)))
|
|
|
|
gbl_resolv_flags.transport_name = TRUE;
|
|
|
|
else
|
|
|
|
gbl_resolv_flags.transport_name = FALSE;
|
|
|
|
if (gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(e_resolv_cb)))
|
|
|
|
gbl_resolv_flags.use_external_net_name_resolver = TRUE;
|
|
|
|
else
|
|
|
|
gbl_resolv_flags.use_external_net_name_resolver = FALSE;
|
|
|
|
|
2014-01-18 14:20:02 +00:00
|
|
|
*type = gtk_combo_box_get_active((GtkComboBox *) format_type_co);
|
|
|
|
|
2012-07-16 20:46:13 +00:00
|
|
|
/* We've crossed the Rubicon; get rid of the file selection box. */
|
|
|
|
window_destroy(GTK_WIDGET(file_open_w));
|
2000-06-02 03:35:39 +00:00
|
|
|
|
2012-07-16 21:01:16 +00:00
|
|
|
return TRUE;
|
2012-07-16 20:46:13 +00:00
|
|
|
}
|
|
|
|
#endif /* USE_WIN32_FILE_DIALOGS */
|
1999-09-01 03:04:24 +00:00
|
|
|
|
2012-07-16 20:46:13 +00:00
|
|
|
/* Open a file */
|
2012-06-04 18:40:45 +00:00
|
|
|
|
2012-07-16 20:46:13 +00:00
|
|
|
/*
|
|
|
|
* <platform/>_open_file routines should upon entry...
|
|
|
|
* Set the path and fill in the filename if the path+filename is provided.
|
|
|
|
* Set the display filter if provided. Filter syntax should be checked.
|
|
|
|
* Set the name resolution check boxes to match the global settings.
|
|
|
|
* ...and upon exit...
|
|
|
|
* Return TRUE on "OK" and "FALSE" on "Cancel".
|
|
|
|
* Set the global name resolution preferences on "OK".
|
|
|
|
* Close the window.
|
|
|
|
*/
|
2012-06-04 18:40:45 +00:00
|
|
|
|
2012-07-16 20:46:13 +00:00
|
|
|
static void
|
2012-08-19 21:24:02 +00:00
|
|
|
file_open_cmd(capture_file *cf, GtkWidget *w _U_)
|
2012-07-16 20:46:13 +00:00
|
|
|
{
|
2013-01-09 21:04:44 +00:00
|
|
|
GString *file_name = g_string_new("");
|
2012-07-16 20:46:13 +00:00
|
|
|
GString *display_filter = g_string_new("");
|
2013-01-09 21:04:44 +00:00
|
|
|
dfilter_t *rfcode = NULL;
|
2015-01-18 10:22:19 +00:00
|
|
|
gchar *err_msg;
|
2012-07-16 20:46:13 +00:00
|
|
|
int err;
|
2014-01-18 14:20:02 +00:00
|
|
|
int type = WTAP_TYPE_AUTO;
|
2012-06-04 18:40:45 +00:00
|
|
|
|
2012-07-16 20:46:13 +00:00
|
|
|
/*
|
|
|
|
* Loop until the user either selects a file or gives up.
|
|
|
|
*/
|
|
|
|
for (;;) {
|
|
|
|
#ifdef USE_WIN32_FILE_DIALOGS
|
2014-02-26 15:27:20 +00:00
|
|
|
if (win32_open_file(GDK_WINDOW_HWND(gtk_widget_get_window(top_level)), file_name, &type, display_filter)) {
|
2012-07-16 20:46:13 +00:00
|
|
|
#else /* USE_WIN32_FILE_DIALOGS */
|
2014-01-18 14:20:02 +00:00
|
|
|
if (gtk_open_file(top_level, file_name, &type, display_filter)) {
|
2012-07-16 20:46:13 +00:00
|
|
|
#endif /* USE_WIN32_FILE_DIALOGS */
|
2012-07-16 21:01:16 +00:00
|
|
|
|
2012-08-19 21:24:02 +00:00
|
|
|
/* Only close the old file now that we know we want to open another one. */
|
|
|
|
cf_close(cf);
|
2012-07-16 20:46:13 +00:00
|
|
|
/* apply our filter */
|
2015-01-18 10:22:19 +00:00
|
|
|
if (dfilter_compile(display_filter->str, &rfcode, &err_msg)) {
|
2012-07-16 20:46:13 +00:00
|
|
|
cf_set_rfcode(&cfile, rfcode);
|
|
|
|
} else {
|
|
|
|
/* Not valid. Tell the user, and go back and run the file
|
|
|
|
selection box again once they dismiss the alert. */
|
2015-01-18 10:22:19 +00:00
|
|
|
bad_dfilter_alert_box(top_level, display_filter->str, err_msg);
|
|
|
|
g_free(err_msg);
|
2012-07-16 20:46:13 +00:00
|
|
|
continue;
|
|
|
|
}
|
2012-06-04 18:40:45 +00:00
|
|
|
|
2014-03-20 16:57:29 +00:00
|
|
|
/* Try to open the capture file. This closes the current file if it succeeds. */
|
2014-01-18 14:20:02 +00:00
|
|
|
if (cf_open(&cfile, file_name->str, type, FALSE, &err) != CF_OK) {
|
2012-07-16 20:46:13 +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. */
|
2015-01-07 17:13:51 +00:00
|
|
|
if (rfcode != NULL){
|
2012-07-16 20:46:13 +00:00
|
|
|
dfilter_free(rfcode);
|
|
|
|
rfcode = NULL;
|
2015-01-07 17:13:51 +00:00
|
|
|
}
|
2012-07-16 20:46:13 +00:00
|
|
|
continue;
|
|
|
|
}
|
2012-06-04 18:40:45 +00:00
|
|
|
|
2012-07-16 20:46:13 +00:00
|
|
|
switch (cf_read(&cfile, FALSE)) {
|
2012-07-16 21:01:16 +00:00
|
|
|
|
2013-01-10 03:35:16 +00:00
|
|
|
case CF_READ_OK:
|
|
|
|
case CF_READ_ERROR:
|
|
|
|
/* 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;
|
|
|
|
|
|
|
|
case CF_READ_ABORTED:
|
|
|
|
/* 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_string_free(file_name, TRUE);
|
|
|
|
g_string_free(display_filter, TRUE);
|
|
|
|
return;
|
2012-07-16 20:46:13 +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. */
|
|
|
|
set_last_open_dir(get_dirname(file_name->str));
|
2012-06-04 18:40:45 +00:00
|
|
|
}
|
2012-07-16 20:46:13 +00:00
|
|
|
g_string_free(file_name, TRUE);
|
|
|
|
g_string_free(display_filter, TRUE);
|
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;
|
|
|
|
}
|
1999-09-01 03:04:24 +00:00
|
|
|
}
|
|
|
|
|
2012-06-04 18:40:45 +00:00
|
|
|
void
|
|
|
|
file_open_cmd_cb(GtkWidget *widget, gpointer data _U_) {
|
|
|
|
/* If there's unsaved data, let the user save it first.
|
|
|
|
If they cancel out of it, don't quit. */
|
2012-08-19 21:24:02 +00:00
|
|
|
if (test_file_close(&cfile, FALSE, " before opening a new capture file"))
|
|
|
|
file_open_cmd(&cfile, widget);
|
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
|
|
|
}
|
|
|
|
|
2012-09-10 21:27:49 +00:00
|
|
|
#ifndef USE_WIN32_FILE_DIALOGS
|
|
|
|
static gboolean
|
|
|
|
gtk_merge_file(GtkWidget *w, GString *file_name, GString *display_filter, int *merge_type)
|
2004-06-17 21:53:26 +00:00
|
|
|
{
|
2013-01-09 21:04:44 +00:00
|
|
|
GtkWidget *file_merge_w;
|
|
|
|
GtkWidget *main_hb, *main_vb, *filter_hbox, *filter_bt, *filter_te;
|
|
|
|
GtkWidget *prepend_rb, *chrono_rb, *append_rb, *prev;
|
2012-01-14 09:16:31 +00:00
|
|
|
|
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 = {
|
2012-09-10 21:27:49 +00:00
|
|
|
"Wireshark: Display Filter",
|
2012-01-14 09:16:31 +00:00
|
|
|
FALSE,
|
|
|
|
FALSE,
|
2005-12-31 17:09:27 +00:00
|
|
|
TRUE
|
2004-06-17 21:53:26 +00:00
|
|
|
};
|
2012-09-10 21:27:49 +00:00
|
|
|
gchar *cf_name;
|
|
|
|
|
|
|
|
if (!file_name || !display_filter || !merge_type)
|
|
|
|
return FALSE;
|
2004-06-17 21:53:26 +00:00
|
|
|
|
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",
|
2013-05-14 21:53:57 +00:00
|
|
|
GTK_WINDOW(top_level),
|
|
|
|
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
|
|
|
|
2012-09-10 21:27:49 +00:00
|
|
|
if (file_name->len > 0) {
|
|
|
|
gchar *dirname = g_path_get_dirname(file_name->str);
|
|
|
|
|
2012-09-10 21:55:55 +00:00
|
|
|
file_selection_set_current_folder(file_merge_w, dirname);
|
2012-09-10 21:27:49 +00:00
|
|
|
g_free(dirname);
|
|
|
|
} else {
|
|
|
|
switch (prefs.gui_fileopen_style) {
|
2012-09-10 21:55:55 +00:00
|
|
|
|
2012-09-10 21:27:49 +00:00
|
|
|
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;
|
2012-09-10 21:55:55 +00:00
|
|
|
|
2012-09-10 21:27:49 +00:00
|
|
|
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;
|
|
|
|
}
|
2004-06-17 21:53:26 +00:00
|
|
|
}
|
2006-02-13 21:25:43 +00:00
|
|
|
|
2012-06-02 23:53:04 +00:00
|
|
|
main_hb = ws_gtk_box_new(GTK_ORIENTATION_HORIZONTAL, 3, FALSE);
|
2013-01-10 02:51:36 +00:00
|
|
|
#if GTK_CHECK_VERSION(3,0,0)
|
|
|
|
gtk_widget_set_vexpand(main_hb, FALSE); /* prevents "inheritance" from child VEXPAND */
|
|
|
|
/* so hbox doesn't expand vertically even */
|
|
|
|
/* tho grid rows have VEXPAND. */
|
|
|
|
#endif
|
2004-06-19 10:48:06 +00:00
|
|
|
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 */
|
2012-06-02 23:53:04 +00:00
|
|
|
main_vb = ws_gtk_box_new(GTK_ORIENTATION_VERTICAL, 3, FALSE);
|
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);
|
|
|
|
|
2012-09-10 21:27:49 +00:00
|
|
|
/* Filter row */
|
2012-06-02 23:53:04 +00:00
|
|
|
filter_hbox = ws_gtk_box_new(GTK_ORIENTATION_HORIZONTAL, 1, FALSE);
|
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);
|
|
|
|
|
2014-02-21 13:09:52 +00:00
|
|
|
filter_bt = ws_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);
|
2012-09-10 21:27:49 +00:00
|
|
|
gtk_widget_set_tooltip_text(filter_bt, "Open the \"Display Filter\" dialog to edit/apply filters");
|
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);
|
2013-01-09 21:04:44 +00:00
|
|
|
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);
|
2012-09-10 21:27:49 +00:00
|
|
|
gtk_entry_set_text(GTK_ENTRY(filter_te), display_filter->str);
|
2004-06-17 21:53:26 +00:00
|
|
|
gtk_widget_show(filter_te);
|
2011-02-16 18:27:00 +00:00
|
|
|
gtk_widget_set_tooltip_text(filter_te, "Enter a display filter.");
|
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
|
|
|
|
2012-09-10 21:27:49 +00:00
|
|
|
/* Merge type */
|
2008-04-11 19:26:22 +00:00
|
|
|
prepend_rb = gtk_radio_button_new_with_mnemonic_from_widget(NULL,
|
2012-09-10 21:27:49 +00:00
|
|
|
"Prepend packets");
|
|
|
|
gtk_widget_set_tooltip_text(prepend_rb, "Insert packets from the selected file before the current file. Packet timestamps will be ignored.");
|
2004-06-17 21:53:26 +00:00
|
|
|
gtk_box_pack_start(GTK_BOX(main_vb), prepend_rb, FALSE, FALSE, 0);
|
|
|
|
gtk_widget_show(prepend_rb);
|
|
|
|
|
2012-09-10 21:27:49 +00:00
|
|
|
chrono_rb = gtk_radio_button_new_with_mnemonic_from_widget(GTK_RADIO_BUTTON(prepend_rb), "Merge chronologically");
|
|
|
|
gtk_widget_set_tooltip_text(chrono_rb, "Insert packets in chronological order.");
|
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);
|
|
|
|
|
2012-09-10 21:27:49 +00:00
|
|
|
append_rb = gtk_radio_button_new_with_mnemonic_from_widget(GTK_RADIO_BUTTON(prepend_rb), "Append packets");
|
|
|
|
gtk_widget_set_tooltip_text(append_rb, "Insert packets from the selected file after the current file. Packet timestamps will be ignored.");
|
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);
|
|
|
|
|
2012-09-10 21:27:49 +00:00
|
|
|
/* Preview widget */
|
2004-06-19 10:48:06 +00:00
|
|
|
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);
|
2013-01-10 02:51:36 +00:00
|
|
|
gtk_box_pack_start(GTK_BOX(main_hb), prev, FALSE, FALSE, 0);
|
2004-06-19 10:48:06 +00:00
|
|
|
|
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));
|
2012-09-10 21:55:55 +00:00
|
|
|
|
2013-05-14 19:06:20 +00:00
|
|
|
cf_name = file_selection_run(file_merge_w);
|
2012-09-10 21:27:49 +00:00
|
|
|
if (cf_name == NULL) {
|
|
|
|
/* User cancelled or closed the dialog. */
|
|
|
|
return FALSE;
|
|
|
|
}
|
2012-06-04 19:04:45 +00:00
|
|
|
|
2012-09-10 21:27:49 +00:00
|
|
|
g_string_printf(file_name, "%s", cf_name);
|
|
|
|
g_free(cf_name);
|
|
|
|
g_string_printf(display_filter, "%s", gtk_entry_get_text(GTK_ENTRY(filter_te)));
|
2012-06-04 19:04:45 +00:00
|
|
|
|
2012-09-10 21:27:49 +00:00
|
|
|
if (gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(chrono_rb))) {
|
|
|
|
*merge_type = 0;
|
|
|
|
} else if (gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(prepend_rb))) {
|
|
|
|
*merge_type = -1;
|
|
|
|
} else {
|
|
|
|
*merge_type = 1;
|
|
|
|
}
|
2012-06-04 19:04:45 +00:00
|
|
|
|
2012-09-10 21:27:49 +00:00
|
|
|
/* We've crossed the Rubicon; get rid of the file selection box. */
|
2012-09-10 21:55:55 +00:00
|
|
|
window_destroy(GTK_WIDGET(file_merge_w));
|
2012-06-04 19:04:45 +00:00
|
|
|
|
2012-09-10 21:27:49 +00:00
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
#endif /* USE_WIN32_FILE_DIALOGS */
|
2012-06-04 19:04:45 +00:00
|
|
|
|
2012-09-10 21:27:49 +00:00
|
|
|
/* Merge existing with another file */
|
2012-06-04 19:04:45 +00:00
|
|
|
|
2012-09-10 21:27:49 +00:00
|
|
|
/*
|
|
|
|
* <platform/>_merge_file routines should upon entry...
|
|
|
|
* Set the path and fill in the filename if the path+filename is provided.
|
|
|
|
* Set the display filter if provided. Filter syntax should be checked.
|
|
|
|
* ...and upon exit...
|
|
|
|
* Return TRUE on "OK" and "FALSE" on "Cancel".
|
|
|
|
* Close the window.
|
|
|
|
*/
|
2012-06-04 19:04:45 +00:00
|
|
|
|
2012-09-10 21:27:49 +00:00
|
|
|
static void
|
|
|
|
file_merge_cmd(GtkWidget *w _U_)
|
|
|
|
{
|
2013-01-09 21:04:44 +00:00
|
|
|
GString *file_name = g_string_new("");
|
2012-09-10 21:27:49 +00:00
|
|
|
GString *display_filter = g_string_new("");
|
|
|
|
int merge_type;
|
2013-01-09 21:04:44 +00:00
|
|
|
dfilter_t *rfcode = NULL;
|
2015-01-18 10:22:19 +00:00
|
|
|
gchar *err_msg;
|
2012-09-10 21:27:49 +00:00
|
|
|
int err;
|
|
|
|
int file_type;
|
|
|
|
cf_status_t merge_status;
|
|
|
|
char *in_filenames[2];
|
2013-01-09 21:04:44 +00:00
|
|
|
char *tmpname = NULL;
|
2012-06-04 19:04:45 +00:00
|
|
|
|
2012-09-10 21:27:49 +00:00
|
|
|
/*
|
|
|
|
* Loop until the user either selects a file or gives up.
|
|
|
|
*/
|
|
|
|
for (;;) {
|
2012-09-19 23:06:39 +00:00
|
|
|
g_string_truncate(file_name, 0);
|
|
|
|
g_string_truncate(display_filter, 0);
|
2012-09-10 21:27:49 +00:00
|
|
|
#ifdef USE_WIN32_FILE_DIALOGS
|
|
|
|
if (win32_merge_file(GDK_WINDOW_HWND(gtk_widget_get_window(top_level)), file_name, display_filter, &merge_type)) {
|
|
|
|
#else /* USE_WIN32_FILE_DIALOGS */
|
2012-09-24 17:04:50 +00:00
|
|
|
if (gtk_merge_file(top_level, file_name, display_filter, &merge_type)) {
|
2012-09-10 21:27:49 +00:00
|
|
|
#endif /* USE_WIN32_FILE_DIALOGS */
|
2012-06-04 19:04:45 +00:00
|
|
|
|
2012-09-10 21:27:49 +00:00
|
|
|
/* Get the specified read filter and try to compile it. */
|
2015-01-18 10:22:19 +00:00
|
|
|
if (!dfilter_compile(display_filter->str, &rfcode, &err_msg)) {
|
2012-09-10 21:27:49 +00:00
|
|
|
/* Not valid. Tell the user, and go back and run the file
|
|
|
|
selection box again once they dismiss the alert. */
|
2015-01-18 10:22:19 +00:00
|
|
|
bad_dfilter_alert_box(top_level, display_filter->str, err_msg);
|
|
|
|
g_free(err_msg);
|
2012-09-10 21:27:49 +00:00
|
|
|
continue;
|
|
|
|
}
|
2012-09-10 21:55:55 +00:00
|
|
|
|
2012-09-10 21:27:49 +00:00
|
|
|
file_type = cfile.cd_t;
|
2012-09-10 21:55:55 +00:00
|
|
|
|
2012-09-10 21:27:49 +00:00
|
|
|
/* Try to merge or append the two files */
|
|
|
|
tmpname = NULL;
|
|
|
|
if (merge_type == 0) {
|
|
|
|
/* chronological order */
|
|
|
|
in_filenames[0] = cfile.filename;
|
|
|
|
in_filenames[1] = file_name->str;
|
|
|
|
merge_status = cf_merge_files(&tmpname, 2, in_filenames, file_type, FALSE);
|
|
|
|
} else if (merge_type < 0) {
|
|
|
|
/* prepend file */
|
|
|
|
in_filenames[0] = file_name->str;
|
|
|
|
in_filenames[1] = cfile.filename;
|
|
|
|
merge_status = cf_merge_files(&tmpname, 2, in_filenames, file_type, TRUE);
|
|
|
|
} else {
|
|
|
|
/* append file */
|
|
|
|
in_filenames[0] = cfile.filename;
|
|
|
|
in_filenames[1] = file_name->str;
|
|
|
|
merge_status = cf_merge_files(&tmpname, 2, in_filenames, file_type, TRUE);
|
|
|
|
}
|
2012-09-10 21:55:55 +00:00
|
|
|
|
2012-09-10 21:27:49 +00:00
|
|
|
if (merge_status != CF_OK) {
|
|
|
|
if (rfcode != NULL)
|
|
|
|
dfilter_free(rfcode);
|
|
|
|
g_free(tmpname);
|
|
|
|
continue;
|
|
|
|
}
|
2012-09-10 21:55:55 +00:00
|
|
|
|
2012-09-10 21:27:49 +00:00
|
|
|
cf_close(&cfile);
|
2012-09-10 21:55:55 +00:00
|
|
|
|
2014-03-20 16:57:29 +00:00
|
|
|
/* Try to open the merged capture file. This closes the current file if it succeeds. */
|
2014-01-18 14:20:02 +00:00
|
|
|
if (cf_open(&cfile, tmpname, WTAP_TYPE_AUTO, TRUE /* temporary file */, &err) != CF_OK) {
|
2012-09-10 21:27:49 +00:00
|
|
|
/* We couldn't open it; fail. */
|
|
|
|
if (rfcode != NULL)
|
|
|
|
dfilter_free(rfcode);
|
|
|
|
g_free(tmpname);
|
|
|
|
g_string_free(file_name, TRUE);
|
|
|
|
g_string_free(display_filter, TRUE);
|
|
|
|
return;
|
|
|
|
}
|
2012-09-10 21:55:55 +00:00
|
|
|
|
2012-09-10 21:27:49 +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"). */
|
2015-11-17 00:27:34 +00:00
|
|
|
cf_set_rfcode(&cfile, rfcode);
|
2012-09-10 21:55:55 +00:00
|
|
|
|
2012-09-10 21:27:49 +00:00
|
|
|
switch (cf_read(&cfile, FALSE)) {
|
2012-09-10 21:55:55 +00:00
|
|
|
|
2012-09-10 21:27:49 +00:00
|
|
|
case CF_READ_OK:
|
|
|
|
case CF_READ_ERROR:
|
|
|
|
/* 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;
|
2012-09-10 21:55:55 +00:00
|
|
|
|
2012-09-10 21:27:49 +00:00
|
|
|
case CF_READ_ABORTED:
|
|
|
|
/* 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(tmpname);
|
|
|
|
g_string_free(file_name, TRUE);
|
|
|
|
g_string_free(display_filter, TRUE);
|
|
|
|
return;
|
|
|
|
}
|
2012-06-04 19:04:45 +00:00
|
|
|
}
|
2012-09-10 21:55:55 +00:00
|
|
|
|
2012-06-04 19:04:45 +00:00
|
|
|
/* Save the name of the containing directory specified in the path name,
|
|
|
|
if any; we can write over cf_merged_name, which is a good thing, given that
|
|
|
|
"get_dirname()" does write over its argument. */
|
2012-09-19 23:06:39 +00:00
|
|
|
if (tmpname) {
|
|
|
|
set_last_open_dir(get_dirname(tmpname));
|
|
|
|
g_free(tmpname);
|
|
|
|
}
|
2012-09-10 21:27:49 +00:00
|
|
|
g_string_free(file_name, TRUE);
|
|
|
|
g_string_free(display_filter, TRUE);
|
2012-06-04 19:04:45 +00:00
|
|
|
return;
|
2004-06-17 21:53:26 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
file_merge_cmd_cb(GtkWidget *widget, gpointer data _U_) {
|
2012-05-25 21:25:55 +00:00
|
|
|
/* If there's unsaved data, let the user save it first.
|
|
|
|
If they cancel out of it, don't merge. */
|
|
|
|
GtkWidget *msg_dialog;
|
2012-06-02 18:13:12 +00:00
|
|
|
gchar *display_basename;
|
2012-05-25 21:25:55 +00:00
|
|
|
gint response;
|
|
|
|
|
|
|
|
if (prefs.gui_ask_unsaved) {
|
2013-04-02 20:35:46 +00:00
|
|
|
if (cf_has_unsaved_data(&cfile)) {
|
2013-04-01 23:44:29 +00:00
|
|
|
/* This file has unsaved data; ask the user whether to save the
|
|
|
|
capture. */
|
2012-05-25 21:25:55 +00:00
|
|
|
if (cfile.is_tempfile) {
|
|
|
|
msg_dialog = gtk_message_dialog_new(GTK_WINDOW(top_level),
|
2013-03-21 02:29:09 +00:00
|
|
|
(GtkDialogFlags)(GTK_DIALOG_MODAL|GTK_DIALOG_DESTROY_WITH_PARENT),
|
2012-05-25 21:25:55 +00:00
|
|
|
GTK_MESSAGE_QUESTION,
|
|
|
|
GTK_BUTTONS_NONE,
|
|
|
|
"Do you want to save the captured packets before merging another capture file into it?");
|
|
|
|
|
|
|
|
gtk_message_dialog_format_secondary_text(GTK_MESSAGE_DIALOG(msg_dialog),
|
|
|
|
"A temporary capture file can't be merged.");
|
|
|
|
} else {
|
|
|
|
/*
|
|
|
|
* Format the message.
|
|
|
|
*/
|
2012-06-02 18:13:12 +00:00
|
|
|
display_basename = g_filename_display_basename(cfile.filename);
|
2012-05-25 21:25:55 +00:00
|
|
|
msg_dialog = gtk_message_dialog_new(GTK_WINDOW(top_level),
|
2013-03-21 02:29:09 +00:00
|
|
|
(GtkDialogFlags)(GTK_DIALOG_MODAL|GTK_DIALOG_DESTROY_WITH_PARENT),
|
2012-05-25 21:25:55 +00:00
|
|
|
GTK_MESSAGE_QUESTION,
|
|
|
|
GTK_BUTTONS_NONE,
|
2012-06-02 18:13:12 +00:00
|
|
|
"Do you want to save the changes you've made "
|
|
|
|
"to the capture file \"%s\" before merging another capture file into it?",
|
|
|
|
display_basename);
|
|
|
|
g_free(display_basename);
|
2012-05-25 21:25:55 +00:00
|
|
|
gtk_message_dialog_format_secondary_text(GTK_MESSAGE_DIALOG(msg_dialog),
|
|
|
|
"The changes must be saved before the files are merged.");
|
|
|
|
}
|
|
|
|
|
|
|
|
gtk_dialog_add_button(GTK_DIALOG(msg_dialog),
|
|
|
|
GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL);
|
|
|
|
gtk_dialog_add_button(GTK_DIALOG(msg_dialog),
|
2012-12-22 17:41:40 +00:00
|
|
|
WIRESHARK_STOCK_SAVE, GTK_RESPONSE_ACCEPT);
|
2013-05-14 02:46:17 +00:00
|
|
|
gtk_dialog_set_alternative_button_order(GTK_DIALOG(msg_dialog),
|
|
|
|
GTK_RESPONSE_ACCEPT,
|
|
|
|
GTK_RESPONSE_CANCEL,
|
|
|
|
-1);
|
|
|
|
gtk_dialog_set_default_response(GTK_DIALOG(msg_dialog),
|
|
|
|
GTK_RESPONSE_ACCEPT);
|
2012-05-25 21:25:55 +00:00
|
|
|
|
|
|
|
response = gtk_dialog_run(GTK_DIALOG(msg_dialog));
|
|
|
|
gtk_widget_destroy(msg_dialog);
|
|
|
|
|
|
|
|
switch (response) {
|
|
|
|
|
|
|
|
case GTK_RESPONSE_ACCEPT:
|
|
|
|
/* Save the file but don't close it */
|
|
|
|
do_file_save(&cfile, FALSE);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case GTK_RESPONSE_CANCEL:
|
|
|
|
case GTK_RESPONSE_NONE:
|
|
|
|
case GTK_RESPONSE_DELETE_EVENT:
|
|
|
|
default:
|
|
|
|
/* Don't do the merge. */
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
2004-06-17 21:53:26 +00:00
|
|
|
}
|
2012-05-25 21:25:55 +00:00
|
|
|
|
|
|
|
/* Do the merge. */
|
|
|
|
file_merge_cmd(widget);
|
2004-06-17 21:53:26 +00:00
|
|
|
}
|
|
|
|
|
2012-06-14 02:11:34 +00:00
|
|
|
#ifdef HAVE_LIBPCAP
|
2012-06-14 01:34:52 +00:00
|
|
|
static void
|
|
|
|
do_capture_stop(capture_file *cf)
|
|
|
|
{
|
|
|
|
/* Stop the capture (complete with UI updates). */
|
|
|
|
capture_stop_cb(NULL, NULL);
|
|
|
|
|
|
|
|
/* Now run the main loop until the capture stops and we finish
|
|
|
|
reading it; we need to run the main loop so we respond to
|
|
|
|
messages on the sync pipe and the sync pipe being closed. */
|
|
|
|
while (cf->state == FILE_READ_IN_PROGRESS)
|
|
|
|
gtk_main_iteration();
|
|
|
|
}
|
2012-06-14 02:11:34 +00:00
|
|
|
#endif
|
2012-06-14 01:34:52 +00:00
|
|
|
|
2012-08-19 21:24:02 +00:00
|
|
|
/* Returns true if the current file has been saved or if the user has chosen
|
|
|
|
* to discard it, ie if it is safe to continue with the call to close, and
|
|
|
|
* false otherwise. */
|
2012-05-25 21:25:55 +00:00
|
|
|
gboolean
|
2012-08-19 21:24:02 +00:00
|
|
|
test_file_close(capture_file *cf, gboolean from_quit, const char *before_what)
|
2004-01-29 23:11:38 +00:00
|
|
|
{
|
2012-05-25 21:25:55 +00:00
|
|
|
GtkWidget *msg_dialog;
|
2012-06-02 18:13:12 +00:00
|
|
|
gchar *display_basename;
|
2012-05-25 21:25:55 +00:00
|
|
|
gint response;
|
2012-06-03 20:39:45 +00:00
|
|
|
gboolean capture_in_progress;
|
2012-05-25 21:25:55 +00:00
|
|
|
|
|
|
|
if (cf->state == FILE_CLOSED)
|
|
|
|
return TRUE; /* already closed, nothing to do */
|
|
|
|
|
2012-06-03 20:39:45 +00:00
|
|
|
#ifdef HAVE_LIBPCAP
|
|
|
|
if (cf->state == FILE_READ_IN_PROGRESS) {
|
|
|
|
/* This is true if we're reading a capture file *or* if we're doing
|
|
|
|
a live capture. If we're reading a capture file, the main loop
|
|
|
|
is busy reading packets, and only accepting input from the
|
|
|
|
progress dialog, so we can't get here, so this means we're
|
|
|
|
doing a capture. */
|
|
|
|
capture_in_progress = TRUE;
|
|
|
|
} else
|
|
|
|
#endif
|
|
|
|
capture_in_progress = FALSE;
|
2012-07-16 21:01:16 +00:00
|
|
|
|
2012-05-25 21:25:55 +00:00
|
|
|
if (prefs.gui_ask_unsaved) {
|
2013-04-02 20:35:46 +00:00
|
|
|
if (cf_has_unsaved_data(cf) || capture_in_progress) {
|
2013-04-01 23:44:29 +00:00
|
|
|
/* This file has unsaved data or there's a capture in progress;
|
|
|
|
ask the user whether to save the data. */
|
2012-05-25 21:25:55 +00:00
|
|
|
if (cf->is_tempfile) {
|
|
|
|
msg_dialog = gtk_message_dialog_new(GTK_WINDOW(top_level),
|
2013-03-21 02:29:09 +00:00
|
|
|
(GtkDialogFlags)(GTK_DIALOG_MODAL|GTK_DIALOG_DESTROY_WITH_PARENT),
|
2012-05-25 21:25:55 +00:00
|
|
|
GTK_MESSAGE_QUESTION,
|
|
|
|
GTK_BUTTONS_NONE,
|
2012-07-16 21:01:16 +00:00
|
|
|
capture_in_progress ?
|
2012-06-03 20:39:45 +00:00
|
|
|
"Do you want to stop the capture and save the captured packets%s?" :
|
|
|
|
"Do you want to save the captured packets%s?",
|
2012-05-25 21:25:55 +00:00
|
|
|
before_what);
|
|
|
|
|
|
|
|
gtk_message_dialog_format_secondary_text(GTK_MESSAGE_DIALOG(msg_dialog),
|
|
|
|
"Your captured packets will be lost if you don't save them.");
|
|
|
|
} else {
|
|
|
|
/*
|
|
|
|
* Format the message.
|
|
|
|
*/
|
2012-06-02 18:13:12 +00:00
|
|
|
display_basename = g_filename_display_basename(cf->filename);
|
2012-06-03 20:39:45 +00:00
|
|
|
if (capture_in_progress) {
|
|
|
|
msg_dialog = gtk_message_dialog_new(GTK_WINDOW(top_level),
|
2013-03-21 02:29:09 +00:00
|
|
|
(GtkDialogFlags)(GTK_DIALOG_MODAL|GTK_DIALOG_DESTROY_WITH_PARENT),
|
2012-06-03 20:39:45 +00:00
|
|
|
GTK_MESSAGE_QUESTION,
|
|
|
|
GTK_BUTTONS_NONE,
|
|
|
|
"Do you want to stop the capture and save the captured packets%s?",
|
|
|
|
before_what);
|
|
|
|
} else {
|
|
|
|
msg_dialog = gtk_message_dialog_new(GTK_WINDOW(top_level),
|
2013-03-21 02:29:09 +00:00
|
|
|
(GtkDialogFlags)(GTK_DIALOG_MODAL|GTK_DIALOG_DESTROY_WITH_PARENT),
|
2012-06-03 20:39:45 +00:00
|
|
|
GTK_MESSAGE_QUESTION,
|
|
|
|
GTK_BUTTONS_NONE,
|
|
|
|
"Do you want to save the changes you've made "
|
|
|
|
"to the capture file \"%s\"%s?",
|
|
|
|
display_basename, before_what);
|
|
|
|
}
|
2012-06-02 18:13:12 +00:00
|
|
|
g_free(display_basename);
|
2012-05-25 21:25:55 +00:00
|
|
|
gtk_message_dialog_format_secondary_text(GTK_MESSAGE_DIALOG(msg_dialog),
|
2012-06-03 20:39:45 +00:00
|
|
|
capture_in_progress ?
|
|
|
|
"Your captured packets will be lost if you don't save them." :
|
2012-05-25 21:25:55 +00:00
|
|
|
"Your changes will be lost if you don't save them.");
|
|
|
|
}
|
|
|
|
|
|
|
|
/* If this is from a Quit operation, use "quit and don't save"
|
|
|
|
rather than just "don't save". */
|
|
|
|
gtk_dialog_add_button(GTK_DIALOG(msg_dialog),
|
2012-06-03 20:39:45 +00:00
|
|
|
(from_quit ?
|
|
|
|
(cf->state == FILE_READ_IN_PROGRESS ?
|
|
|
|
WIRESHARK_STOCK_STOP_QUIT_DONT_SAVE :
|
|
|
|
WIRESHARK_STOCK_QUIT_DONT_SAVE) :
|
|
|
|
(capture_in_progress ?
|
|
|
|
WIRESHARK_STOCK_STOP_DONT_SAVE :
|
|
|
|
WIRESHARK_STOCK_DONT_SAVE)),
|
2012-05-25 21:25:55 +00:00
|
|
|
GTK_RESPONSE_REJECT);
|
|
|
|
gtk_dialog_add_button(GTK_DIALOG(msg_dialog),
|
|
|
|
GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL);
|
2012-06-03 20:39:45 +00:00
|
|
|
gtk_dialog_add_button(GTK_DIALOG(msg_dialog),
|
|
|
|
(capture_in_progress ?
|
|
|
|
WIRESHARK_STOCK_STOP_SAVE :
|
2012-12-22 17:41:40 +00:00
|
|
|
WIRESHARK_STOCK_SAVE),
|
2012-06-03 20:39:45 +00:00
|
|
|
GTK_RESPONSE_ACCEPT);
|
2013-05-14 02:46:17 +00:00
|
|
|
gtk_dialog_set_alternative_button_order(GTK_DIALOG(msg_dialog),
|
|
|
|
GTK_RESPONSE_ACCEPT,
|
|
|
|
GTK_RESPONSE_CANCEL,
|
|
|
|
GTK_RESPONSE_REJECT,
|
|
|
|
-1);
|
|
|
|
gtk_dialog_set_default_response(GTK_DIALOG(msg_dialog),
|
|
|
|
GTK_RESPONSE_ACCEPT);
|
2012-05-25 21:25:55 +00:00
|
|
|
|
|
|
|
response = gtk_dialog_run(GTK_DIALOG(msg_dialog));
|
|
|
|
gtk_widget_destroy(msg_dialog);
|
|
|
|
|
|
|
|
switch (response) {
|
|
|
|
|
|
|
|
case GTK_RESPONSE_ACCEPT:
|
2012-06-03 20:39:45 +00:00
|
|
|
#ifdef HAVE_LIBPCAP
|
|
|
|
/* If there's a capture in progress, we have to stop the capture
|
|
|
|
and then do the save. */
|
|
|
|
if (capture_in_progress)
|
2012-06-14 01:34:52 +00:00
|
|
|
do_capture_stop(cf);
|
2012-06-03 20:39:45 +00:00
|
|
|
#endif
|
2012-05-25 21:25:55 +00:00
|
|
|
/* Save the file and close it */
|
|
|
|
do_file_save(cf, TRUE);
|
2004-01-29 23:11:38 +00:00
|
|
|
break;
|
2012-05-25 21:25:55 +00:00
|
|
|
|
|
|
|
case GTK_RESPONSE_REJECT:
|
2012-06-03 20:39:45 +00:00
|
|
|
#ifdef HAVE_LIBPCAP
|
|
|
|
/* If there's a capture in progress; we have to stop the capture
|
|
|
|
and then do the close. */
|
|
|
|
if (capture_in_progress)
|
2012-06-14 01:34:52 +00:00
|
|
|
do_capture_stop(cf);
|
2012-06-03 20:39:45 +00:00
|
|
|
#endif
|
2004-01-29 23:11:38 +00:00
|
|
|
break;
|
2012-05-25 21:25:55 +00:00
|
|
|
|
|
|
|
case GTK_RESPONSE_CANCEL:
|
|
|
|
case GTK_RESPONSE_NONE:
|
|
|
|
case GTK_RESPONSE_DELETE_EVENT:
|
|
|
|
default:
|
2012-06-03 20:39:45 +00:00
|
|
|
/* Don't close the file (and don't stop any capture in progress). */
|
2012-05-25 21:25:55 +00:00
|
|
|
return FALSE; /* file not closed */
|
|
|
|
}
|
|
|
|
} else {
|
2012-08-19 21:24:02 +00:00
|
|
|
/* unchanged file, safe to close */
|
|
|
|
return TRUE;
|
2004-01-29 23:11:38 +00:00
|
|
|
}
|
2012-05-25 21:25:55 +00:00
|
|
|
} else {
|
2012-06-03 20:39:45 +00:00
|
|
|
/* User asked not to be bothered by those prompts, just close it.
|
|
|
|
XXX - should that apply only to saving temporary files? */
|
|
|
|
#ifdef HAVE_LIBPCAP
|
|
|
|
/* If there's a capture in progress, we have to stop the capture
|
|
|
|
and then do the close. */
|
|
|
|
if (capture_in_progress)
|
2012-06-14 01:34:52 +00:00
|
|
|
do_capture_stop(cf);
|
2012-06-03 20:39:45 +00:00
|
|
|
#endif
|
2012-08-19 21:24:02 +00:00
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
return TRUE; /* shouldn't get here? */
|
|
|
|
}
|
|
|
|
|
|
|
|
gboolean
|
|
|
|
do_file_close(capture_file *cf, gboolean from_quit, const char *before_what)
|
|
|
|
{
|
|
|
|
if (test_file_close(cf, from_quit, before_what)) {
|
2012-05-25 21:25:55 +00:00
|
|
|
cf_close(cf);
|
2012-08-19 21:24:02 +00:00
|
|
|
return TRUE;
|
2012-05-25 21:25:55 +00:00
|
|
|
}
|
2012-08-19 21:24:02 +00:00
|
|
|
return FALSE;
|
2004-01-29 23:11:38 +00:00
|
|
|
}
|
|
|
|
|
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_) {
|
2012-05-25 21:25:55 +00:00
|
|
|
do_file_close(&cfile, FALSE, "");
|
1999-09-01 03:04:24 +00:00
|
|
|
}
|
|
|
|
|
2012-06-20 04:44:14 +00:00
|
|
|
#define RESPONSE_DISCARD_COMMENTS_AND_SAVE 1
|
|
|
|
#define RESPONSE_SAVE_IN_ANOTHER_FORMAT 2
|
|
|
|
|
|
|
|
static check_savability_t
|
|
|
|
check_save_with_comments(capture_file *cf)
|
|
|
|
{
|
2013-04-01 20:36:42 +00:00
|
|
|
guint32 comment_types;
|
2013-01-09 21:04:44 +00:00
|
|
|
GtkWidget *msg_dialog;
|
|
|
|
gint response;
|
2012-06-20 04:44:14 +00:00
|
|
|
|
2013-04-01 20:36:42 +00:00
|
|
|
/* What types of comments do we have? */
|
|
|
|
comment_types = cf_comment_types(cf);
|
2012-06-20 04:44:14 +00:00
|
|
|
|
2013-04-01 20:36:42 +00:00
|
|
|
/* Does the file's format support all the comments we have? */
|
|
|
|
if (wtap_dump_supports_comment_types(cf->cd_t, comment_types)) {
|
|
|
|
/* Yes. Let the save happen; we can save all the comments, so
|
|
|
|
there's no need to delete them. */
|
2012-06-20 04:44:14 +00:00
|
|
|
return SAVE;
|
|
|
|
}
|
|
|
|
|
2013-04-01 20:36:42 +00:00
|
|
|
/* No. Are there formats in which we can write this file that
|
|
|
|
supports all the comments in this file? */
|
2013-04-01 21:17:50 +00:00
|
|
|
if (wtap_dump_can_write(cf->linktypes, comment_types)) {
|
2013-04-01 20:36:42 +00:00
|
|
|
/* Yes. Offer the user a choice of "Save in a format that
|
2012-06-20 04:44:14 +00:00
|
|
|
supports comments", "Discard comments and save in the
|
|
|
|
file's own format", or "Cancel", meaning "don't bother
|
|
|
|
saving the file at all". */
|
|
|
|
msg_dialog = gtk_message_dialog_new(GTK_WINDOW(top_level),
|
|
|
|
GTK_DIALOG_DESTROY_WITH_PARENT,
|
|
|
|
GTK_MESSAGE_QUESTION,
|
|
|
|
GTK_BUTTONS_NONE,
|
|
|
|
"The capture has comments, but the file's format "
|
|
|
|
"doesn't support comments. Do you want to save the capture "
|
|
|
|
"in a format that supports comments, or discard the comments "
|
|
|
|
"and save in the file's format?");
|
|
|
|
gtk_dialog_add_buttons(GTK_DIALOG(msg_dialog),
|
|
|
|
"Discard comments and save",
|
|
|
|
RESPONSE_DISCARD_COMMENTS_AND_SAVE,
|
|
|
|
GTK_STOCK_CANCEL,
|
|
|
|
GTK_RESPONSE_CANCEL,
|
|
|
|
"Save in another format",
|
|
|
|
RESPONSE_SAVE_IN_ANOTHER_FORMAT,
|
|
|
|
NULL);
|
2013-05-14 02:46:17 +00:00
|
|
|
gtk_dialog_set_alternative_button_order(GTK_DIALOG(msg_dialog),
|
|
|
|
RESPONSE_SAVE_IN_ANOTHER_FORMAT,
|
|
|
|
GTK_RESPONSE_CANCEL,
|
|
|
|
RESPONSE_DISCARD_COMMENTS_AND_SAVE,
|
|
|
|
-1);
|
2012-06-20 04:44:14 +00:00
|
|
|
gtk_dialog_set_default_response(GTK_DIALOG(msg_dialog),
|
|
|
|
RESPONSE_SAVE_IN_ANOTHER_FORMAT);
|
|
|
|
} else {
|
|
|
|
/* No. Offer the user a choice of "Discard comments and
|
|
|
|
save in the file's format" or "Cancel". */
|
|
|
|
msg_dialog = gtk_message_dialog_new(GTK_WINDOW(top_level),
|
|
|
|
GTK_DIALOG_DESTROY_WITH_PARENT,
|
|
|
|
GTK_MESSAGE_QUESTION,
|
|
|
|
GTK_BUTTONS_NONE,
|
|
|
|
"The capture has comments, but no file format in which it "
|
|
|
|
"can be saved supports comments. Do you want to discard "
|
|
|
|
"the comments and save in the file's format?");
|
|
|
|
gtk_dialog_add_buttons(GTK_DIALOG(msg_dialog),
|
|
|
|
GTK_STOCK_CANCEL,
|
|
|
|
GTK_RESPONSE_CANCEL,
|
|
|
|
"Discard comments and save",
|
|
|
|
RESPONSE_DISCARD_COMMENTS_AND_SAVE,
|
|
|
|
NULL);
|
2013-05-14 02:46:17 +00:00
|
|
|
gtk_dialog_set_alternative_button_order(GTK_DIALOG(msg_dialog),
|
|
|
|
RESPONSE_DISCARD_COMMENTS_AND_SAVE,
|
|
|
|
GTK_RESPONSE_CANCEL,
|
|
|
|
-1);
|
2012-06-20 04:44:14 +00:00
|
|
|
gtk_dialog_set_default_response(GTK_DIALOG(msg_dialog),
|
|
|
|
GTK_RESPONSE_CANCEL);
|
|
|
|
}
|
|
|
|
|
|
|
|
response = gtk_dialog_run(GTK_DIALOG(msg_dialog));
|
|
|
|
gtk_widget_destroy(msg_dialog);
|
|
|
|
|
|
|
|
switch (response) {
|
|
|
|
|
|
|
|
case RESPONSE_SAVE_IN_ANOTHER_FORMAT:
|
|
|
|
/* Let the user select another format. */
|
|
|
|
return SAVE_IN_ANOTHER_FORMAT;
|
|
|
|
|
|
|
|
case RESPONSE_DISCARD_COMMENTS_AND_SAVE:
|
|
|
|
/* Save without the comments and, if that succeeds, delete the
|
|
|
|
comments. */
|
|
|
|
return SAVE_WITHOUT_COMMENTS;
|
|
|
|
|
|
|
|
case GTK_RESPONSE_CANCEL:
|
|
|
|
case GTK_RESPONSE_NONE:
|
|
|
|
case GTK_RESPONSE_DELETE_EVENT:
|
|
|
|
default:
|
|
|
|
/* Just give up. */
|
|
|
|
return CANCELLED;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-05-25 21:25:55 +00:00
|
|
|
/*
|
|
|
|
* Save the capture file in question, prompting the user for a file
|
|
|
|
* name to save to if necessary.
|
|
|
|
*/
|
|
|
|
static void
|
|
|
|
do_file_save(capture_file *cf, gboolean dont_reopen)
|
|
|
|
{
|
2013-01-09 21:04:44 +00:00
|
|
|
char *fname;
|
|
|
|
gboolean discard_comments;
|
2012-06-20 04:44:14 +00:00
|
|
|
cf_write_status_t status;
|
2012-05-25 21:25:55 +00:00
|
|
|
|
|
|
|
if (cf->is_tempfile) {
|
We're an editor now, as we let you add, delete, and edit frame comments,
so "Save" should, for non-temporary files, mean "save the current state
of the capture file on top of the existing file" without prompting for a
file name.
That means we have to do a "safe save" - i.e, write the capture out to a
new file and, if that succeeds, rename the new file on top of the old
file - as the actual packet data to write out is in the file we're
overwriting, not in memory. (We'd want to do that anyway, of
course....)
Update some comments.
Clean up indentation slightly, and get rid of an unnecessary variable
(in all the cases where we use it, we assign it the same value, and that
value isn't modified out from under us before we use it).
Note that after a "Save", or a "Save As" that writes out all captured
packets, we shouldn't have to close the current file and open the new
file and reread it - we should be able to open the new file and update
the frame offsets in the frame_data structures.
Note that we need to do some a better job of reporting rename failures.
svn path=/trunk/; revision=42777
2012-05-22 10:36:40 +00:00
|
|
|
/* This is a temporary capture file, so saving it means saving
|
2012-05-25 21:25:55 +00:00
|
|
|
it to a permanent file. Prompt the user for a location
|
2012-06-20 04:44:14 +00:00
|
|
|
to which to save it. Don't require that the file format
|
|
|
|
support comments - if it's a temporary capture file, it's
|
|
|
|
probably pcap-ng, which supports comments and, if it's
|
|
|
|
not pcap-ng, let the user decide what they want to do
|
|
|
|
if they've added comments. */
|
2012-09-24 17:04:50 +00:00
|
|
|
file_save_as_cmd(cf, FALSE, dont_reopen);
|
We're an editor now, as we let you add, delete, and edit frame comments,
so "Save" should, for non-temporary files, mean "save the current state
of the capture file on top of the existing file" without prompting for a
file name.
That means we have to do a "safe save" - i.e, write the capture out to a
new file and, if that succeeds, rename the new file on top of the old
file - as the actual packet data to write out is in the file we're
overwriting, not in memory. (We'd want to do that anyway, of
course....)
Update some comments.
Clean up indentation slightly, and get rid of an unnecessary variable
(in all the cases where we use it, we assign it the same value, and that
value isn't modified out from under us before we use it).
Note that after a "Save", or a "Save As" that writes out all captured
packets, we shouldn't have to close the current file and open the new
file and reread it - we should be able to open the new file and update
the frame offsets in the frame_data structures.
Note that we need to do some a better job of reporting rename failures.
svn path=/trunk/; revision=42777
2012-05-22 10:36:40 +00:00
|
|
|
} else {
|
2012-05-25 21:25:55 +00:00
|
|
|
if (cf->unsaved_changes) {
|
We're an editor now, as we let you add, delete, and edit frame comments,
so "Save" should, for non-temporary files, mean "save the current state
of the capture file on top of the existing file" without prompting for a
file name.
That means we have to do a "safe save" - i.e, write the capture out to a
new file and, if that succeeds, rename the new file on top of the old
file - as the actual packet data to write out is in the file we're
overwriting, not in memory. (We'd want to do that anyway, of
course....)
Update some comments.
Clean up indentation slightly, and get rid of an unnecessary variable
(in all the cases where we use it, we assign it the same value, and that
value isn't modified out from under us before we use it).
Note that after a "Save", or a "Save As" that writes out all captured
packets, we shouldn't have to close the current file and open the new
file and reread it - we should be able to open the new file and update
the frame offsets in the frame_data structures.
Note that we need to do some a better job of reporting rename failures.
svn path=/trunk/; revision=42777
2012-05-22 10:36:40 +00:00
|
|
|
/* This is not a temporary capture file, but it has unsaved
|
|
|
|
changes, so saving it means doing a "safe save" on top
|
2012-06-20 04:44:14 +00:00
|
|
|
of the existing file, in the same format - no UI needed
|
|
|
|
unless the file has comments and the file's format doesn't
|
|
|
|
support them.
|
|
|
|
|
|
|
|
If the file has comments, does the file's format support them?
|
|
|
|
If not, ask the user whether they want to discard the comments
|
|
|
|
or choose a different format. */
|
|
|
|
switch (check_save_with_comments(cf)) {
|
|
|
|
|
|
|
|
case SAVE:
|
|
|
|
/* The file can be saved in the specified format as is;
|
|
|
|
just drive on and save in the format they selected. */
|
|
|
|
discard_comments = FALSE;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case SAVE_WITHOUT_COMMENTS:
|
|
|
|
/* The file can't be saved in the specified format as is,
|
|
|
|
but it can be saved without the comments, and the user
|
|
|
|
said "OK, discard the comments", so save it in the
|
|
|
|
format they specified without the comments. */
|
|
|
|
discard_comments = TRUE;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case SAVE_IN_ANOTHER_FORMAT:
|
|
|
|
/* There are file formats in which we can save this that
|
|
|
|
support comments, and the user said not to delete the
|
|
|
|
comments. Do a "Save As" so the user can select
|
|
|
|
one of those formats and choose a file name. */
|
2012-09-24 17:04:50 +00:00
|
|
|
file_save_as_cmd(cf, TRUE, dont_reopen);
|
2012-06-20 04:44:14 +00:00
|
|
|
return;
|
|
|
|
|
|
|
|
case CANCELLED:
|
|
|
|
/* The user said "forget it". Just return. */
|
|
|
|
return;
|
|
|
|
|
|
|
|
default:
|
|
|
|
/* Squelch warnings that discard_comments is being used
|
|
|
|
uninitialized. */
|
|
|
|
g_assert_not_reached();
|
|
|
|
return;
|
2012-07-16 21:01:16 +00:00
|
|
|
}
|
2012-06-20 04:44:14 +00:00
|
|
|
|
2012-05-25 21:25:55 +00:00
|
|
|
/* XXX - cf->filename might get freed out from under us, because
|
2014-05-24 18:28:30 +00:00
|
|
|
the code path through which cf_save_records() goes currently
|
2012-06-20 05:48:06 +00:00
|
|
|
closes the current file and then opens and reloads the saved file,
|
|
|
|
so make a copy and free it later. */
|
2012-05-25 21:25:55 +00:00
|
|
|
fname = g_strdup(cf->filename);
|
2014-05-24 18:28:30 +00:00
|
|
|
status = cf_save_records(cf, fname, cf->cd_t, cf->iscompressed,
|
2012-06-20 04:44:14 +00:00
|
|
|
discard_comments, dont_reopen);
|
|
|
|
switch (status) {
|
|
|
|
|
|
|
|
case CF_WRITE_OK:
|
|
|
|
/* The save succeeded; we're done.
|
|
|
|
If we discarded comments, redraw the packet list to reflect
|
|
|
|
any packets that no longer have comments. */
|
|
|
|
if (discard_comments)
|
2012-09-04 02:35:25 +00:00
|
|
|
packet_list_queue_draw();
|
2012-06-20 04:44:14 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case CF_WRITE_ERROR:
|
|
|
|
/* The write failed.
|
|
|
|
XXX - OK, what do we do now? Let them try a
|
|
|
|
"Save As", in case they want to try to save to a
|
|
|
|
different directory r file system? */
|
|
|
|
break;
|
|
|
|
|
|
|
|
case CF_WRITE_ABORTED:
|
|
|
|
/* The write was aborted; just drive on. */
|
|
|
|
break;
|
|
|
|
}
|
2012-05-25 21:25:55 +00:00
|
|
|
g_free(fname);
|
We're an editor now, as we let you add, delete, and edit frame comments,
so "Save" should, for non-temporary files, mean "save the current state
of the capture file on top of the existing file" without prompting for a
file name.
That means we have to do a "safe save" - i.e, write the capture out to a
new file and, if that succeeds, rename the new file on top of the old
file - as the actual packet data to write out is in the file we're
overwriting, not in memory. (We'd want to do that anyway, of
course....)
Update some comments.
Clean up indentation slightly, and get rid of an unnecessary variable
(in all the cases where we use it, we assign it the same value, and that
value isn't modified out from under us before we use it).
Note that after a "Save", or a "Save As" that writes out all captured
packets, we shouldn't have to close the current file and open the new
file and reread it - we should be able to open the new file and update
the frame offsets in the frame_data structures.
Note that we need to do some a better job of reporting rename failures.
svn path=/trunk/; revision=42777
2012-05-22 10:36:40 +00:00
|
|
|
}
|
2012-05-25 21:25:55 +00:00
|
|
|
/* Otherwise just do nothing. */
|
We're an editor now, as we let you add, delete, and edit frame comments,
so "Save" should, for non-temporary files, mean "save the current state
of the capture file on top of the existing file" without prompting for a
file name.
That means we have to do a "safe save" - i.e, write the capture out to a
new file and, if that succeeds, rename the new file on top of the old
file - as the actual packet data to write out is in the file we're
overwriting, not in memory. (We'd want to do that anyway, of
course....)
Update some comments.
Clean up indentation slightly, and get rid of an unnecessary variable
(in all the cases where we use it, we assign it the same value, and that
value isn't modified out from under us before we use it).
Note that after a "Save", or a "Save As" that writes out all captured
packets, we shouldn't have to close the current file and open the new
file and reread it - we should be able to open the new file and update
the frame offsets in the frame_data structures.
Note that we need to do some a better job of reporting rename failures.
svn path=/trunk/; revision=42777
2012-05-22 10:36:40 +00:00
|
|
|
}
|
1999-09-01 03:04:24 +00:00
|
|
|
}
|
|
|
|
|
2012-05-25 21:25:55 +00:00
|
|
|
void
|
|
|
|
file_save_cmd_cb(GtkWidget *w _U_, gpointer data _U_) {
|
|
|
|
do_file_save(&cfile, FALSE);
|
|
|
|
}
|
|
|
|
|
2010-02-22 18:50:56 +00:00
|
|
|
/* Attach a list of the valid 'save as' file types to a combo_box by
|
2012-01-14 09:16:31 +00:00
|
|
|
checking what Wiretap supports. Make the default type the first
|
2012-06-20 04:44:14 +00:00
|
|
|
in the list. If must_supprt_comments is true, restrict the list
|
|
|
|
to those formats that support comments (currently, just pcap-ng).
|
2012-06-25 17:56:29 +00:00
|
|
|
|
|
|
|
Returns the default file type. */
|
|
|
|
static int
|
2012-06-20 04:44:14 +00:00
|
|
|
set_file_type_list(GtkWidget *combo_box, capture_file *cf,
|
2013-04-01 20:36:42 +00:00
|
|
|
gboolean must_support_all_comments)
|
1999-12-06 09:02:48 +00:00
|
|
|
{
|
2013-04-01 20:36:42 +00:00
|
|
|
guint32 required_comment_types;
|
2013-11-08 09:53:01 +00:00
|
|
|
GArray *savable_file_types_subtypes;
|
2013-01-09 21:04:44 +00:00
|
|
|
guint i;
|
|
|
|
int ft;
|
|
|
|
int default_ft = -1;
|
2012-01-24 04:33:23 +00:00
|
|
|
|
2013-04-01 20:36:42 +00:00
|
|
|
/* What types of comments do we have to support? */
|
|
|
|
if (must_support_all_comments)
|
|
|
|
required_comment_types = cf_comment_types(cf); /* all the ones the file has */
|
|
|
|
else
|
|
|
|
required_comment_types = 0; /* none of them */
|
|
|
|
|
|
|
|
/* What types of file can we save this file as? */
|
2013-11-08 09:53:01 +00:00
|
|
|
savable_file_types_subtypes = wtap_get_savable_file_types_subtypes(cf->cd_t,
|
|
|
|
cf->linktypes,
|
|
|
|
required_comment_types);
|
2012-01-24 04:33:23 +00:00
|
|
|
|
2013-11-08 09:53:01 +00:00
|
|
|
if (savable_file_types_subtypes != NULL) {
|
2012-01-24 04:33:23 +00:00
|
|
|
/* OK, we have at least one file type we can save this file as.
|
|
|
|
(If we didn't, we shouldn't have gotten here in the first
|
|
|
|
place.) Add them all to the combo box. */
|
2013-11-08 09:53:01 +00:00
|
|
|
for (i = 0; i < savable_file_types_subtypes->len; i++) {
|
|
|
|
ft = g_array_index(savable_file_types_subtypes, int, i);
|
2012-06-25 17:56:29 +00:00
|
|
|
if (default_ft == -1)
|
|
|
|
default_ft = ft; /* first file type is the default */
|
2012-01-24 04:33:23 +00:00
|
|
|
ws_combo_box_append_text_and_pointer(GTK_COMBO_BOX(combo_box),
|
2013-11-08 09:53:01 +00:00
|
|
|
wtap_file_type_subtype_string(ft),
|
2012-01-24 04:33:23 +00:00
|
|
|
GINT_TO_POINTER(ft));
|
1999-12-06 09:02:48 +00:00
|
|
|
}
|
2013-11-08 09:53:01 +00:00
|
|
|
g_array_free(savable_file_types_subtypes, TRUE);
|
1999-12-06 09:02:48 +00:00
|
|
|
}
|
2012-06-25 17:56:29 +00:00
|
|
|
|
|
|
|
return default_ft;
|
1999-12-06 09:02:48 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2012-06-04 10:27:59 +00:00
|
|
|
file_select_file_type_cb(GtkWidget *w, gpointer parent_arg)
|
1999-12-06 09:02:48 +00:00
|
|
|
{
|
2013-03-08 07:09:39 +00:00
|
|
|
GtkWidget *parent = (GtkWidget *)parent_arg;
|
2013-01-09 21:04:44 +00:00
|
|
|
int new_file_type;
|
|
|
|
gpointer ptr;
|
2005-09-14 21:57:30 +00:00
|
|
|
GtkWidget *compressed_cb;
|
1999-12-06 09:02:48 +00:00
|
|
|
|
2012-06-20 01:11:01 +00:00
|
|
|
compressed_cb = (GtkWidget *)g_object_get_data(G_OBJECT(parent), E_COMPRESSED_CB_KEY);
|
2010-02-22 18:50:56 +00:00
|
|
|
if (! ws_combo_box_get_active_pointer(GTK_COMBO_BOX(w), &ptr)) {
|
2012-06-20 01:11:01 +00:00
|
|
|
/* XXX - this can happen when we clear the list of file types
|
|
|
|
and then reconstruct it. */
|
|
|
|
gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(compressed_cb), FALSE);
|
|
|
|
gtk_widget_set_sensitive(compressed_cb, FALSE);
|
|
|
|
return;
|
2010-02-22 18:50:56 +00:00
|
|
|
}
|
2010-03-21 19:26:32 +00:00
|
|
|
new_file_type = GPOINTER_TO_INT(ptr);
|
2010-02-22 18:50:56 +00:00
|
|
|
|
2012-05-24 07:51:39 +00:00
|
|
|
if (!wtap_dump_can_compress(new_file_type)) {
|
|
|
|
/* Can't compress this file type; turn off compression and make
|
|
|
|
the compression checkbox insensitive. */
|
|
|
|
gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(compressed_cb), FALSE);
|
|
|
|
gtk_widget_set_sensitive(compressed_cb, FALSE);
|
|
|
|
} else
|
|
|
|
gtk_widget_set_sensitive(compressed_cb, TRUE);
|
1999-12-06 09:02:48 +00:00
|
|
|
}
|
|
|
|
|
2012-06-20 01:11:01 +00:00
|
|
|
static check_savability_t
|
2012-09-24 17:04:50 +00:00
|
|
|
gtk_check_save_as_with_comments(GtkWidget *w, capture_file *cf, int file_type)
|
2012-06-20 01:11:01 +00:00
|
|
|
{
|
2013-04-01 20:36:42 +00:00
|
|
|
guint32 comment_types;
|
2013-01-09 21:04:44 +00:00
|
|
|
GtkWidget *msg_dialog;
|
|
|
|
gint response;
|
2012-06-20 01:11:01 +00:00
|
|
|
|
2013-04-01 20:36:42 +00:00
|
|
|
/* What types of comments do we have? */
|
|
|
|
comment_types = cf_comment_types(cf);
|
2012-06-20 01:11:01 +00:00
|
|
|
|
2013-04-01 20:36:42 +00:00
|
|
|
/* Does the file's format support all the comments we have? */
|
|
|
|
if (wtap_dump_supports_comment_types(file_type, comment_types)) {
|
|
|
|
/* Yes. Let the save happen; we can save all the comments, so
|
|
|
|
there's no need to delete them. */
|
2012-06-20 01:11:01 +00:00
|
|
|
return SAVE;
|
|
|
|
}
|
2013-04-01 20:36:42 +00:00
|
|
|
|
|
|
|
/* No. Are there formats in which we can write this file that
|
|
|
|
supports all the comments in this file? */
|
2013-04-01 21:17:50 +00:00
|
|
|
if (wtap_dump_can_write(cf->linktypes, comment_types)) {
|
2012-06-20 01:11:01 +00:00
|
|
|
/* Yes. Offer the user a choice of "Save in a format that
|
|
|
|
supports comments", "Discard comments and save in the
|
|
|
|
format you selected", or "Cancel", meaning "don't bother
|
|
|
|
saving the file at all". */
|
2012-09-24 17:04:50 +00:00
|
|
|
msg_dialog = gtk_message_dialog_new(GTK_WINDOW(w),
|
2012-06-20 01:11:01 +00:00
|
|
|
GTK_DIALOG_DESTROY_WITH_PARENT,
|
|
|
|
GTK_MESSAGE_QUESTION,
|
|
|
|
GTK_BUTTONS_NONE,
|
|
|
|
"The capture has comments, but the file format you chose "
|
|
|
|
"doesn't support comments. Do you want to save the capture "
|
|
|
|
"in a format that supports comments, or discard the comments "
|
|
|
|
"and save in the format you chose?");
|
|
|
|
gtk_dialog_add_buttons(GTK_DIALOG(msg_dialog),
|
|
|
|
"Discard comments and save",
|
|
|
|
RESPONSE_DISCARD_COMMENTS_AND_SAVE,
|
|
|
|
GTK_STOCK_CANCEL,
|
|
|
|
GTK_RESPONSE_CANCEL,
|
|
|
|
"Save in another format",
|
|
|
|
RESPONSE_SAVE_IN_ANOTHER_FORMAT,
|
|
|
|
NULL);
|
2013-05-14 02:46:17 +00:00
|
|
|
gtk_dialog_set_alternative_button_order(GTK_DIALOG(msg_dialog),
|
|
|
|
RESPONSE_SAVE_IN_ANOTHER_FORMAT,
|
|
|
|
GTK_RESPONSE_CANCEL,
|
|
|
|
RESPONSE_DISCARD_COMMENTS_AND_SAVE,
|
|
|
|
-1);
|
2012-06-20 01:11:01 +00:00
|
|
|
gtk_dialog_set_default_response(GTK_DIALOG(msg_dialog),
|
|
|
|
RESPONSE_SAVE_IN_ANOTHER_FORMAT);
|
|
|
|
} else {
|
|
|
|
/* No. Offer the user a choice of "Discard comments and
|
|
|
|
save in the format you selected" or "Cancel". */
|
2012-09-24 17:04:50 +00:00
|
|
|
msg_dialog = gtk_message_dialog_new(GTK_WINDOW(w),
|
2012-06-20 01:11:01 +00:00
|
|
|
GTK_DIALOG_DESTROY_WITH_PARENT,
|
|
|
|
GTK_MESSAGE_QUESTION,
|
|
|
|
GTK_BUTTONS_NONE,
|
|
|
|
"The capture has comments, but no file format in which it "
|
|
|
|
"can be saved supports comments. Do you want to discard "
|
|
|
|
"the comments and save in the format you chose?");
|
|
|
|
gtk_dialog_add_buttons(GTK_DIALOG(msg_dialog),
|
|
|
|
GTK_STOCK_CANCEL,
|
|
|
|
GTK_RESPONSE_CANCEL,
|
|
|
|
"Discard comments and save",
|
|
|
|
RESPONSE_DISCARD_COMMENTS_AND_SAVE,
|
|
|
|
NULL);
|
2013-05-14 02:46:17 +00:00
|
|
|
gtk_dialog_set_alternative_button_order(GTK_DIALOG(msg_dialog),
|
|
|
|
RESPONSE_DISCARD_COMMENTS_AND_SAVE,
|
|
|
|
GTK_RESPONSE_CANCEL,
|
|
|
|
-1);
|
2012-06-20 01:11:01 +00:00
|
|
|
gtk_dialog_set_default_response(GTK_DIALOG(msg_dialog),
|
|
|
|
GTK_RESPONSE_CANCEL);
|
|
|
|
}
|
|
|
|
|
|
|
|
response = gtk_dialog_run(GTK_DIALOG(msg_dialog));
|
|
|
|
gtk_widget_destroy(msg_dialog);
|
|
|
|
|
|
|
|
switch (response) {
|
|
|
|
|
|
|
|
case RESPONSE_SAVE_IN_ANOTHER_FORMAT:
|
|
|
|
/* OK, the only other format we support is pcap-ng. Make that
|
|
|
|
the one and only format in the combo box, and return to
|
|
|
|
let the user continue with the dialog.
|
|
|
|
|
|
|
|
XXX - removing all the formats from the combo box will clear
|
|
|
|
the compressed checkbox; get the current value and restore
|
|
|
|
it.
|
|
|
|
|
|
|
|
XXX - we know pcap-ng can be compressed; if we ever end up
|
|
|
|
supporting saving comments in a format that *can't* be
|
|
|
|
compressed, such as NetMon format, we must check this. */
|
2012-09-24 17:04:50 +00:00
|
|
|
/* XXX - need a compressed checkbox here! */
|
2012-06-20 01:11:01 +00:00
|
|
|
return SAVE_IN_ANOTHER_FORMAT;
|
|
|
|
|
|
|
|
case RESPONSE_DISCARD_COMMENTS_AND_SAVE:
|
|
|
|
/* Save without the comments and, if that succeeds, delete the
|
|
|
|
comments. */
|
|
|
|
return SAVE_WITHOUT_COMMENTS;
|
|
|
|
|
|
|
|
case GTK_RESPONSE_CANCEL:
|
|
|
|
case GTK_RESPONSE_NONE:
|
|
|
|
case GTK_RESPONSE_DELETE_EVENT:
|
|
|
|
default:
|
|
|
|
/* Just give up. */
|
|
|
|
return CANCELLED;
|
|
|
|
}
|
|
|
|
}
|
2004-04-22 21:31:09 +00:00
|
|
|
|
2012-09-24 17:04:50 +00:00
|
|
|
#ifndef USE_WIN32_FILE_DIALOGS
|
|
|
|
/* "Save as" */
|
|
|
|
static gboolean
|
|
|
|
gtk_save_as_file(GtkWidget *w _U_, capture_file *cf, GString *file_name, int *file_type,
|
2013-04-01 20:36:42 +00:00
|
|
|
gboolean *compressed, gboolean must_support_all_comments)
|
1999-12-06 09:02:48 +00:00
|
|
|
{
|
2013-01-09 21:04:44 +00:00
|
|
|
GtkWidget *file_save_as_w;
|
|
|
|
GtkWidget *main_vb, *ft_hb, *ft_lb, *ft_combo_box, *compressed_cb;
|
|
|
|
int default_ft;
|
|
|
|
char *cf_name;
|
|
|
|
gpointer ptr;
|
2012-09-24 17:04:50 +00:00
|
|
|
|
|
|
|
if (!file_name || !file_type || !compressed)
|
|
|
|
return FALSE;
|
2000-04-10 18:40:13 +00:00
|
|
|
|
"Save As" always saves everything and, when the save is done, makes the
new file the current file, as is the case in most if not all other GUI
applications.
A new "Export Specified Packets" menu option allows you to specify which
packets to write out, with the default being the displayed packets (and
those on which the displayed packets depend for, e.g. reassembly), and
never makes the resulting file the current file.
The two operations are conceptually distinct. Lumping them into one
menu item, with the default for "Save As" being "displayed packets only"
and thus making it behave like the latter operation, was causing some
confusion; see, for example, bug 6640.
Make the dialog popped up if you try to "Save As" or "Export Specified
Packets" on top of an existing file ask the "do you want to do this?"
question in the main part of the message, and note in the secondary text
that doing that will overwrite what's in the file; that matches what
TextEdit on OS X and the GNOME text editor say.
svn path=/trunk/; revision=42792
2012-05-22 22:17:57 +00:00
|
|
|
/* Default to saving in the file's current format. */
|
2003-12-29 20:05:59 +00:00
|
|
|
|
2004-01-07 00:10:52 +00:00
|
|
|
/* build the file selection */
|
2012-06-19 19:20:47 +00:00
|
|
|
file_save_as_w = file_selection_new("Wireshark: Save Capture File As",
|
2013-05-14 21:53:57 +00:00
|
|
|
GTK_WINDOW(top_level),
|
2012-06-19 19:20:47 +00:00
|
|
|
FILE_SELECTION_SAVE);
|
1999-09-01 03:04:24 +00:00
|
|
|
|
1999-12-06 09:02:48 +00:00
|
|
|
/* Container for each row of widgets */
|
2006-02-13 21:25:43 +00:00
|
|
|
|
2012-06-02 23:53:04 +00:00
|
|
|
main_vb = ws_gtk_box_new(GTK_ORIENTATION_VERTICAL, 5, FALSE);
|
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);
|
|
|
|
|
1999-12-06 09:02:48 +00:00
|
|
|
/* File type row */
|
2012-06-02 23:53:04 +00:00
|
|
|
ft_hb = ws_gtk_box_new(GTK_ORIENTATION_HORIZONTAL, 3, FALSE);
|
2013-03-11 16:28:11 +00:00
|
|
|
gtk_box_pack_start(GTK_BOX(main_vb), ft_hb, FALSE, FALSE, 0);
|
1999-12-06 09:02:48 +00:00
|
|
|
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. */
|
2013-04-01 20:36:42 +00:00
|
|
|
default_ft = set_file_type_list(ft_combo_box, cf, must_support_all_comments);
|
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
|
|
|
|
2012-06-25 17:56:29 +00:00
|
|
|
/* compressed - if the file is currently compressed, and the default
|
|
|
|
file type supports compression, turn the checkbox on */
|
2005-09-14 21:57:30 +00:00
|
|
|
compressed_cb = gtk_check_button_new_with_label("Compress with gzip");
|
2013-03-11 16:28:11 +00:00
|
|
|
gtk_box_pack_start(GTK_BOX(ft_hb), compressed_cb, FALSE, FALSE, 0);
|
2012-06-25 17:56:29 +00:00
|
|
|
if (cf->iscompressed && wtap_dump_can_compress(default_ft))
|
|
|
|
gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(compressed_cb), TRUE);
|
2010-02-22 18:50:56 +00:00
|
|
|
gtk_widget_show(compressed_cb);
|
2010-03-21 19:26:32 +00:00
|
|
|
g_object_set_data(G_OBJECT(file_save_as_w), E_COMPRESSED_CB_KEY, compressed_cb);
|
2012-06-20 01:11:01 +00:00
|
|
|
|
2012-06-04 10:27:59 +00:00
|
|
|
/* Ok: now "select" the default filetype which invokes file_select_file_type_cb */
|
|
|
|
g_signal_connect(ft_combo_box, "changed", G_CALLBACK(file_select_file_type_cb), file_save_as_w);
|
2012-01-14 09:16:31 +00:00
|
|
|
ws_combo_box_set_active(GTK_COMBO_BOX(ft_combo_box), 0);
|
2005-09-14 21:57:30 +00:00
|
|
|
|
2012-09-24 17:04:50 +00:00
|
|
|
cf_name = file_selection_run(file_save_as_w);
|
|
|
|
|
|
|
|
if (cf_name == NULL) {
|
|
|
|
/* User cancelled or closed the dialog. */
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
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);
|
|
|
|
*compressed = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(compressed_cb));
|
|
|
|
|
|
|
|
/* We've crossed the Rubicon; get rid of the file selection box. */
|
|
|
|
window_destroy(GTK_WIDGET(file_save_as_w));
|
|
|
|
|
|
|
|
g_string_printf(file_name, "%s", cf_name);
|
|
|
|
g_free(cf_name);
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
#endif /* USE_WIN32_FILE_DIALOGS */
|
|
|
|
|
2012-10-03 19:24:14 +00:00
|
|
|
static void
|
|
|
|
file_add_extension(GString *file_name, int file_type, gboolean compressed) {
|
2013-01-09 21:04:44 +00:00
|
|
|
gchar *file_name_lower;
|
|
|
|
GString *file_suffix;
|
|
|
|
GSList *extensions_list, *extension;
|
|
|
|
gboolean add_extension;
|
2012-10-03 19:24:14 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Append the default file extension if there's none given by
|
|
|
|
* the user or if they gave one that's not one of the valid
|
|
|
|
* extensions for the file type.
|
|
|
|
*/
|
|
|
|
file_name_lower = g_utf8_strdown(file_name->str, -1);
|
2013-01-09 21:04:44 +00:00
|
|
|
file_suffix = g_string_new("");
|
2012-10-03 19:24:14 +00:00
|
|
|
extensions_list = wtap_get_file_extensions_list(file_type, FALSE);
|
|
|
|
if (extensions_list != NULL) {
|
|
|
|
/* We have one or more extensions for this file type.
|
|
|
|
Start out assuming we need to add the default one. */
|
|
|
|
add_extension = TRUE;
|
|
|
|
|
|
|
|
/* OK, see if the file has one of those extensions. */
|
|
|
|
for (extension = extensions_list; extension != NULL;
|
|
|
|
extension = g_slist_next(extension)) {
|
|
|
|
g_string_printf(file_suffix, ".%s", (char *)extension->data);
|
|
|
|
if (g_str_has_suffix(file_name_lower, file_suffix->str)) {
|
|
|
|
/*
|
|
|
|
* The file name has one of the extensions for
|
|
|
|
* this file type.
|
|
|
|
*/
|
|
|
|
add_extension = FALSE;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
g_string_append(file_suffix, ".gz");
|
|
|
|
if (g_str_has_suffix(file_name_lower, file_suffix->str)) {
|
|
|
|
/*
|
|
|
|
* The file name has one of the extensions for
|
|
|
|
* this file type.
|
|
|
|
*/
|
|
|
|
add_extension = FALSE;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
/* We have no extensions for this file type. Don't add one. */
|
|
|
|
add_extension = FALSE;
|
|
|
|
}
|
|
|
|
g_free(file_name_lower);
|
|
|
|
g_string_free(file_suffix, TRUE);
|
|
|
|
if (add_extension) {
|
|
|
|
if (wtap_default_file_extension(file_type) != NULL) {
|
|
|
|
g_string_append_printf(file_name, ".%s",
|
|
|
|
wtap_default_file_extension(file_type));
|
|
|
|
if (compressed) {
|
|
|
|
g_string_append(file_name, ".gz");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-09-24 17:04:50 +00:00
|
|
|
/* Save a file with a user-specified name */
|
|
|
|
|
|
|
|
/*
|
|
|
|
* <platform/>_save_as_file routines should upon entry...
|
|
|
|
* Set the path and fill in the filename if the path+filename is provided.
|
|
|
|
* ...and upon exit...
|
|
|
|
* Return TRUE on "OK" and "FALSE" on "Cancel".
|
|
|
|
* Close the window.
|
|
|
|
*/
|
|
|
|
|
|
|
|
static void
|
2013-04-01 20:36:42 +00:00
|
|
|
file_save_as_cmd(capture_file *cf, gboolean must_support_all_comments,
|
2012-09-24 17:04:50 +00:00
|
|
|
gboolean dont_reopen)
|
|
|
|
{
|
2013-01-09 21:04:44 +00:00
|
|
|
GString *file_name = g_string_new("");
|
|
|
|
int file_type;
|
|
|
|
gboolean compressed;
|
|
|
|
gchar *dirname;
|
|
|
|
gboolean discard_comments = FALSE;
|
2012-09-24 17:04:50 +00:00
|
|
|
cf_write_status_t status;
|
|
|
|
|
2012-09-26 19:52:53 +00:00
|
|
|
/*
|
2012-05-25 21:25:55 +00:00
|
|
|
* Loop until the user either selects a file or gives up.
|
|
|
|
*/
|
|
|
|
for (;;) {
|
2012-09-24 17:04:50 +00:00
|
|
|
#ifdef USE_WIN32_FILE_DIALOGS
|
2012-09-24 17:44:11 +00:00
|
|
|
if (win32_save_as_file(GDK_WINDOW_HWND(gtk_widget_get_window(top_level)), cf,
|
2013-04-01 20:36:42 +00:00
|
|
|
file_name, &file_type, &compressed, must_support_all_comments)) {
|
2012-09-24 17:04:50 +00:00
|
|
|
/* They discarded comments, so redraw the packet details window
|
|
|
|
to reflect any packets that no longer have comments. */
|
|
|
|
packet_list_queue_draw();
|
|
|
|
#else /* USE_WIN32_FILE_DIALOGS */
|
2013-04-01 20:36:42 +00:00
|
|
|
if (gtk_save_as_file(top_level, cf, file_name, &file_type, &compressed, must_support_all_comments)) {
|
2012-09-24 17:04:50 +00:00
|
|
|
#endif /* USE_WIN32_FILE_DIALOGS */
|
2012-05-25 21:25:55 +00:00
|
|
|
|
2012-09-24 17:04:50 +00:00
|
|
|
/* If the file has comments, does the format the user selected
|
|
|
|
support them? If not, ask the user whether they want to
|
|
|
|
discard the comments or choose a different format. */
|
|
|
|
#ifdef USE_WIN32_FILE_DIALOGS
|
2012-09-24 17:44:11 +00:00
|
|
|
switch (win32_check_save_as_with_comments(GDK_WINDOW_HWND(gtk_widget_get_window(top_level)), cf, file_type)) {
|
2012-09-24 17:04:50 +00:00
|
|
|
#else /* USE_WIN32_FILE_DIALOGS */
|
|
|
|
switch (gtk_check_save_as_with_comments(top_level, cf, file_type)) {
|
|
|
|
#endif /* USE_WIN32_FILE_DIALOGS */
|
2012-06-20 01:11:01 +00:00
|
|
|
|
2012-09-24 17:04:50 +00:00
|
|
|
case SAVE:
|
|
|
|
/* The file can be saved in the specified format as is;
|
|
|
|
just drive on and save in the format they selected. */
|
|
|
|
discard_comments = FALSE;
|
|
|
|
break;
|
2012-06-20 01:11:01 +00:00
|
|
|
|
2012-09-24 17:04:50 +00:00
|
|
|
case SAVE_WITHOUT_COMMENTS:
|
|
|
|
/* The file can't be saved in the specified format as is,
|
|
|
|
but it can be saved without the comments, and the user
|
|
|
|
said "OK, discard the comments", so save it in the
|
|
|
|
format they specified without the comments. */
|
|
|
|
discard_comments = TRUE;
|
|
|
|
break;
|
2012-06-20 01:11:01 +00:00
|
|
|
|
2012-09-24 17:04:50 +00:00
|
|
|
case SAVE_IN_ANOTHER_FORMAT:
|
|
|
|
/* There are file formats in which we can save this that
|
|
|
|
support comments, and the user said not to delete the
|
|
|
|
comments. The combo box of file formats has had the
|
|
|
|
formats that don't support comments trimmed from it,
|
|
|
|
so run the dialog again, to let the user decide
|
|
|
|
whether to save in one of those formats or give up. */
|
2013-04-01 20:36:42 +00:00
|
|
|
must_support_all_comments = TRUE;
|
2012-09-24 17:04:50 +00:00
|
|
|
continue;
|
|
|
|
|
|
|
|
case CANCELLED:
|
|
|
|
/* The user said "forget it". Just get rid of the dialog box
|
|
|
|
and return. */
|
|
|
|
g_string_free(file_name, TRUE);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2012-10-03 19:24:14 +00:00
|
|
|
file_add_extension(file_name, file_type, compressed);
|
2012-06-20 01:11:01 +00:00
|
|
|
|
2012-06-21 22:21:02 +00:00
|
|
|
#ifndef _WIN32
|
2012-09-24 17:04:50 +00:00
|
|
|
/* If the file exists and it's user-immutable or not writable,
|
|
|
|
ask the user whether they want to override that. */
|
|
|
|
if (!file_target_unwritable_ui(top_level, file_name->str)) {
|
|
|
|
/* They don't. Let them try another file name or cancel. */
|
|
|
|
continue;
|
|
|
|
}
|
2012-06-21 22:21:02 +00:00
|
|
|
#endif
|
2012-05-25 21:25:55 +00:00
|
|
|
|
2012-09-24 17:04:50 +00:00
|
|
|
/* Attempt to save the file */
|
2014-05-24 18:28:30 +00:00
|
|
|
status = cf_save_records(&cfile, file_name->str, file_type, compressed,
|
2012-09-24 17:04:50 +00:00
|
|
|
discard_comments, dont_reopen);
|
|
|
|
switch (status) {
|
|
|
|
|
|
|
|
case CF_WRITE_OK:
|
|
|
|
/* The save succeeded; we're done. */
|
|
|
|
/* Save the directory name for future file dialogs. */
|
2012-10-03 19:24:14 +00:00
|
|
|
dirname = get_dirname(file_name->str); /* Overwrites file_name->str */
|
2012-09-24 17:04:50 +00:00
|
|
|
set_last_open_dir(dirname);
|
|
|
|
/* If we discarded comments, redraw the packet list to reflect
|
|
|
|
any packets that no longer have comments. */
|
|
|
|
if (discard_comments)
|
|
|
|
packet_list_queue_draw();
|
|
|
|
break;
|
|
|
|
|
|
|
|
case CF_WRITE_ERROR:
|
|
|
|
/* The save failed; let the user try again. */
|
|
|
|
continue;
|
|
|
|
|
|
|
|
case CF_WRITE_ABORTED:
|
|
|
|
/* The user aborted the save; just return. */
|
|
|
|
g_string_free(file_name, TRUE);
|
|
|
|
return;
|
|
|
|
}
|
Distinguish between "failed" and "user stopped it" for "save as" and
"export specified packets". For "failed", let the user try again with a
different file, in case it failed due to, for example, running out of
space or quota (probably the most likely failure mode for writing, and
trying to a different volume might be the best workaround). For "user
stopped it", presumably they don't want to try again (the most likely
reason is "it was taking too damn long").
Put "Exporting to: ...", not "Saving: ..." in the statusbar if we're
doing "export specified packets".
In process_specified_packets(), allow a null range pointer to be
specified, meaning "save 'em all"; that avoids the possibly-expensive
(with a large capture) operation of initializing the range.
If a "safe save" atop an existing file fails or is stopped, get rid of
the temporary file we created.
svn path=/trunk/; revision=43095
2012-06-05 02:46:54 +00:00
|
|
|
}
|
2012-09-24 17:04:50 +00:00
|
|
|
g_string_free(file_name, TRUE);
|
|
|
|
return;
|
2004-03-27 11:16:58 +00:00
|
|
|
}
|
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_)
|
|
|
|
{
|
2012-09-24 17:04:50 +00:00
|
|
|
file_save_as_cmd(&cfile, FALSE, FALSE);
|
2005-04-12 21:24:30 +00:00
|
|
|
}
|
|
|
|
|
2012-10-03 19:24:14 +00:00
|
|
|
#ifndef USE_WIN32_FILE_DIALOGS
|
|
|
|
static gboolean
|
|
|
|
gtk_export_specified_packets_file(GtkWidget *w _U_, GString *file_name, int *file_type,
|
|
|
|
gboolean *compressed, packet_range_t *range)
|
"Save As" always saves everything and, when the save is done, makes the
new file the current file, as is the case in most if not all other GUI
applications.
A new "Export Specified Packets" menu option allows you to specify which
packets to write out, with the default being the displayed packets (and
those on which the displayed packets depend for, e.g. reassembly), and
never makes the resulting file the current file.
The two operations are conceptually distinct. Lumping them into one
menu item, with the default for "Save As" being "displayed packets only"
and thus making it behave like the latter operation, was causing some
confusion; see, for example, bug 6640.
Make the dialog popped up if you try to "Save As" or "Export Specified
Packets" on top of an existing file ask the "do you want to do this?"
question in the main part of the message, and note in the secondary text
that doing that will overwrite what's in the file; that matches what
TextEdit on OS X and the GNOME text editor say.
svn path=/trunk/; revision=42792
2012-05-22 22:17:57 +00:00
|
|
|
{
|
2013-01-09 21:04:44 +00:00
|
|
|
GtkWidget *file_export_specified_packets_w;
|
|
|
|
GtkWidget *main_vb, *ft_hb, *ft_lb, *ft_combo_box, *range_fr, *range_grid,
|
2012-06-04 10:27:59 +00:00
|
|
|
*compressed_cb;
|
2013-01-09 21:04:44 +00:00
|
|
|
char *cf_name;
|
|
|
|
gpointer ptr;
|
"Save As" always saves everything and, when the save is done, makes the
new file the current file, as is the case in most if not all other GUI
applications.
A new "Export Specified Packets" menu option allows you to specify which
packets to write out, with the default being the displayed packets (and
those on which the displayed packets depend for, e.g. reassembly), and
never makes the resulting file the current file.
The two operations are conceptually distinct. Lumping them into one
menu item, with the default for "Save As" being "displayed packets only"
and thus making it behave like the latter operation, was causing some
confusion; see, for example, bug 6640.
Make the dialog popped up if you try to "Save As" or "Export Specified
Packets" on top of an existing file ask the "do you want to do this?"
question in the main part of the message, and note in the secondary text
that doing that will overwrite what's in the file; that matches what
TextEdit on OS X and the GNOME text editor say.
svn path=/trunk/; revision=42792
2012-05-22 22:17:57 +00:00
|
|
|
|
2012-10-03 19:24:14 +00:00
|
|
|
if (!file_name || !file_type || !compressed || !range)
|
|
|
|
return FALSE;
|
"Save As" always saves everything and, when the save is done, makes the
new file the current file, as is the case in most if not all other GUI
applications.
A new "Export Specified Packets" menu option allows you to specify which
packets to write out, with the default being the displayed packets (and
those on which the displayed packets depend for, e.g. reassembly), and
never makes the resulting file the current file.
The two operations are conceptually distinct. Lumping them into one
menu item, with the default for "Save As" being "displayed packets only"
and thus making it behave like the latter operation, was causing some
confusion; see, for example, bug 6640.
Make the dialog popped up if you try to "Save As" or "Export Specified
Packets" on top of an existing file ask the "do you want to do this?"
question in the main part of the message, and note in the secondary text
that doing that will overwrite what's in the file; that matches what
TextEdit on OS X and the GNOME text editor say.
svn path=/trunk/; revision=42792
2012-05-22 22:17:57 +00:00
|
|
|
|
2012-10-03 19:24:14 +00:00
|
|
|
/* Default to writing out all displayed packets, in the file's current format. */
|
"Save As" always saves everything and, when the save is done, makes the
new file the current file, as is the case in most if not all other GUI
applications.
A new "Export Specified Packets" menu option allows you to specify which
packets to write out, with the default being the displayed packets (and
those on which the displayed packets depend for, e.g. reassembly), and
never makes the resulting file the current file.
The two operations are conceptually distinct. Lumping them into one
menu item, with the default for "Save As" being "displayed packets only"
and thus making it behave like the latter operation, was causing some
confusion; see, for example, bug 6640.
Make the dialog popped up if you try to "Save As" or "Export Specified
Packets" on top of an existing file ask the "do you want to do this?"
question in the main part of the message, and note in the secondary text
that doing that will overwrite what's in the file; that matches what
TextEdit on OS X and the GNOME text editor say.
svn path=/trunk/; revision=42792
2012-05-22 22:17:57 +00:00
|
|
|
|
|
|
|
/* build the file selection */
|
2012-06-19 19:20:47 +00:00
|
|
|
file_export_specified_packets_w = file_selection_new("Wireshark: Export Specified Packets",
|
2013-05-14 21:53:57 +00:00
|
|
|
GTK_WINDOW(top_level),
|
2012-06-19 19:20:47 +00:00
|
|
|
FILE_SELECTION_SAVE);
|
"Save As" always saves everything and, when the save is done, makes the
new file the current file, as is the case in most if not all other GUI
applications.
A new "Export Specified Packets" menu option allows you to specify which
packets to write out, with the default being the displayed packets (and
those on which the displayed packets depend for, e.g. reassembly), and
never makes the resulting file the current file.
The two operations are conceptually distinct. Lumping them into one
menu item, with the default for "Save As" being "displayed packets only"
and thus making it behave like the latter operation, was causing some
confusion; see, for example, bug 6640.
Make the dialog popped up if you try to "Save As" or "Export Specified
Packets" on top of an existing file ask the "do you want to do this?"
question in the main part of the message, and note in the secondary text
that doing that will overwrite what's in the file; that matches what
TextEdit on OS X and the GNOME text editor say.
svn path=/trunk/; revision=42792
2012-05-22 22:17:57 +00:00
|
|
|
|
|
|
|
/* Container for each row of widgets */
|
|
|
|
|
2012-06-02 23:53:04 +00:00
|
|
|
main_vb = ws_gtk_box_new(GTK_ORIENTATION_VERTICAL, 5, FALSE);
|
"Save As" always saves everything and, when the save is done, makes the
new file the current file, as is the case in most if not all other GUI
applications.
A new "Export Specified Packets" menu option allows you to specify which
packets to write out, with the default being the displayed packets (and
those on which the displayed packets depend for, e.g. reassembly), and
never makes the resulting file the current file.
The two operations are conceptually distinct. Lumping them into one
menu item, with the default for "Save As" being "displayed packets only"
and thus making it behave like the latter operation, was causing some
confusion; see, for example, bug 6640.
Make the dialog popped up if you try to "Save As" or "Export Specified
Packets" on top of an existing file ask the "do you want to do this?"
question in the main part of the message, and note in the secondary text
that doing that will overwrite what's in the file; that matches what
TextEdit on OS X and the GNOME text editor say.
svn path=/trunk/; revision=42792
2012-05-22 22:17:57 +00:00
|
|
|
gtk_container_set_border_width(GTK_CONTAINER(main_vb), 5);
|
|
|
|
file_selection_set_extra_widget(file_export_specified_packets_w, main_vb);
|
|
|
|
gtk_widget_show(main_vb);
|
|
|
|
|
|
|
|
/*** Packet Range frame ***/
|
|
|
|
range_fr = gtk_frame_new("Packet Range");
|
|
|
|
gtk_box_pack_start(GTK_BOX(main_vb), range_fr, FALSE, FALSE, 0);
|
|
|
|
gtk_widget_show(range_fr);
|
|
|
|
|
2013-01-09 21:04:44 +00:00
|
|
|
/* grid table */
|
|
|
|
range_grid = range_new(range, TRUE);
|
|
|
|
gtk_container_add(GTK_CONTAINER(range_fr), range_grid);
|
|
|
|
gtk_widget_show(range_grid);
|
"Save As" always saves everything and, when the save is done, makes the
new file the current file, as is the case in most if not all other GUI
applications.
A new "Export Specified Packets" menu option allows you to specify which
packets to write out, with the default being the displayed packets (and
those on which the displayed packets depend for, e.g. reassembly), and
never makes the resulting file the current file.
The two operations are conceptually distinct. Lumping them into one
menu item, with the default for "Save As" being "displayed packets only"
and thus making it behave like the latter operation, was causing some
confusion; see, for example, bug 6640.
Make the dialog popped up if you try to "Save As" or "Export Specified
Packets" on top of an existing file ask the "do you want to do this?"
question in the main part of the message, and note in the secondary text
that doing that will overwrite what's in the file; that matches what
TextEdit on OS X and the GNOME text editor say.
svn path=/trunk/; revision=42792
2012-05-22 22:17:57 +00:00
|
|
|
|
|
|
|
/* File type row */
|
2012-06-02 23:53:04 +00:00
|
|
|
ft_hb = ws_gtk_box_new(GTK_ORIENTATION_HORIZONTAL, 3, FALSE);
|
2013-03-11 16:28:11 +00:00
|
|
|
gtk_box_pack_start(GTK_BOX(main_vb), ft_hb, FALSE, FALSE, 0);
|
2012-07-19 13:06:04 +00:00
|
|
|
|
"Save As" always saves everything and, when the save is done, makes the
new file the current file, as is the case in most if not all other GUI
applications.
A new "Export Specified Packets" menu option allows you to specify which
packets to write out, with the default being the displayed packets (and
those on which the displayed packets depend for, e.g. reassembly), and
never makes the resulting file the current file.
The two operations are conceptually distinct. Lumping them into one
menu item, with the default for "Save As" being "displayed packets only"
and thus making it behave like the latter operation, was causing some
confusion; see, for example, bug 6640.
Make the dialog popped up if you try to "Save As" or "Export Specified
Packets" on top of an existing file ask the "do you want to do this?"
question in the main part of the message, and note in the secondary text
that doing that will overwrite what's in the file; that matches what
TextEdit on OS X and the GNOME text editor say.
svn path=/trunk/; revision=42792
2012-05-22 22:17:57 +00:00
|
|
|
gtk_widget_show(ft_hb);
|
|
|
|
|
|
|
|
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);
|
|
|
|
|
|
|
|
ft_combo_box = ws_combo_box_new_text_and_pointer();
|
|
|
|
|
|
|
|
/* Generate the list of file types we can save. */
|
2012-06-20 04:44:14 +00:00
|
|
|
set_file_type_list(ft_combo_box, &cfile, FALSE);
|
"Save As" always saves everything and, when the save is done, makes the
new file the current file, as is the case in most if not all other GUI
applications.
A new "Export Specified Packets" menu option allows you to specify which
packets to write out, with the default being the displayed packets (and
those on which the displayed packets depend for, e.g. reassembly), and
never makes the resulting file the current file.
The two operations are conceptually distinct. Lumping them into one
menu item, with the default for "Save As" being "displayed packets only"
and thus making it behave like the latter operation, was causing some
confusion; see, for example, bug 6640.
Make the dialog popped up if you try to "Save As" or "Export Specified
Packets" on top of an existing file ask the "do you want to do this?"
question in the main part of the message, and note in the secondary text
that doing that will overwrite what's in the file; that matches what
TextEdit on OS X and the GNOME text editor say.
svn path=/trunk/; revision=42792
2012-05-22 22:17:57 +00:00
|
|
|
gtk_box_pack_start(GTK_BOX(ft_hb), ft_combo_box, FALSE, FALSE, 0);
|
|
|
|
gtk_widget_show(ft_combo_box);
|
|
|
|
g_object_set_data(G_OBJECT(file_export_specified_packets_w), E_FILE_TYPE_COMBO_BOX_KEY, ft_combo_box);
|
|
|
|
|
|
|
|
/* dynamic values in the range frame */
|
2013-01-09 21:04:44 +00:00
|
|
|
range_update_dynamics(range_grid);
|
"Save As" always saves everything and, when the save is done, makes the
new file the current file, as is the case in most if not all other GUI
applications.
A new "Export Specified Packets" menu option allows you to specify which
packets to write out, with the default being the displayed packets (and
those on which the displayed packets depend for, e.g. reassembly), and
never makes the resulting file the current file.
The two operations are conceptually distinct. Lumping them into one
menu item, with the default for "Save As" being "displayed packets only"
and thus making it behave like the latter operation, was causing some
confusion; see, for example, bug 6640.
Make the dialog popped up if you try to "Save As" or "Export Specified
Packets" on top of an existing file ask the "do you want to do this?"
question in the main part of the message, and note in the secondary text
that doing that will overwrite what's in the file; that matches what
TextEdit on OS X and the GNOME text editor say.
svn path=/trunk/; revision=42792
2012-05-22 22:17:57 +00:00
|
|
|
|
|
|
|
/* compressed */
|
|
|
|
compressed_cb = gtk_check_button_new_with_label("Compress with gzip");
|
2013-03-11 16:28:11 +00:00
|
|
|
gtk_box_pack_start(GTK_BOX(ft_hb), compressed_cb, FALSE, FALSE, 0);
|
"Save As" always saves everything and, when the save is done, makes the
new file the current file, as is the case in most if not all other GUI
applications.
A new "Export Specified Packets" menu option allows you to specify which
packets to write out, with the default being the displayed packets (and
those on which the displayed packets depend for, e.g. reassembly), and
never makes the resulting file the current file.
The two operations are conceptually distinct. Lumping them into one
menu item, with the default for "Save As" being "displayed packets only"
and thus making it behave like the latter operation, was causing some
confusion; see, for example, bug 6640.
Make the dialog popped up if you try to "Save As" or "Export Specified
Packets" on top of an existing file ask the "do you want to do this?"
question in the main part of the message, and note in the secondary text
that doing that will overwrite what's in the file; that matches what
TextEdit on OS X and the GNOME text editor say.
svn path=/trunk/; revision=42792
2012-05-22 22:17:57 +00:00
|
|
|
gtk_widget_show(compressed_cb);
|
|
|
|
g_object_set_data(G_OBJECT(file_export_specified_packets_w), E_COMPRESSED_CB_KEY, compressed_cb);
|
2012-05-22 22:57:37 +00:00
|
|
|
|
2012-06-04 10:27:59 +00:00
|
|
|
/* Ok: now "select" the default filetype which invokes file_select_file_type_cb */
|
|
|
|
g_signal_connect(ft_combo_box, "changed", G_CALLBACK(file_select_file_type_cb), file_export_specified_packets_w);
|
"Save As" always saves everything and, when the save is done, makes the
new file the current file, as is the case in most if not all other GUI
applications.
A new "Export Specified Packets" menu option allows you to specify which
packets to write out, with the default being the displayed packets (and
those on which the displayed packets depend for, e.g. reassembly), and
never makes the resulting file the current file.
The two operations are conceptually distinct. Lumping them into one
menu item, with the default for "Save As" being "displayed packets only"
and thus making it behave like the latter operation, was causing some
confusion; see, for example, bug 6640.
Make the dialog popped up if you try to "Save As" or "Export Specified
Packets" on top of an existing file ask the "do you want to do this?"
question in the main part of the message, and note in the secondary text
that doing that will overwrite what's in the file; that matches what
TextEdit on OS X and the GNOME text editor say.
svn path=/trunk/; revision=42792
2012-05-22 22:17:57 +00:00
|
|
|
ws_combo_box_set_active(GTK_COMBO_BOX(ft_combo_box), 0);
|
|
|
|
|
2012-10-03 19:24:14 +00:00
|
|
|
cf_name = file_selection_run(file_export_specified_packets_w);
|
|
|
|
if (cf_name == NULL) {
|
|
|
|
/* User cancelled or closed the dialog. */
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
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);
|
|
|
|
*compressed = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(compressed_cb));
|
|
|
|
|
|
|
|
/* We've crossed the Rubicon; get rid of the file export box. */
|
|
|
|
window_destroy(GTK_WIDGET(file_export_specified_packets_w));
|
|
|
|
|
|
|
|
g_string_printf(file_name, "%s", cf_name);
|
|
|
|
g_free(cf_name);
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
#endif /* USE_WIN32_FILE_DIALOGS */
|
|
|
|
|
|
|
|
/*
|
|
|
|
* <platform/>_export_specified_packets_file routines should upon entry...
|
|
|
|
* Set the path and fill in the filename if the path+filename is provided.
|
|
|
|
* ...and upon exit...
|
2012-10-05 18:52:42 +00:00
|
|
|
* Not initialize range.
|
2012-10-03 19:24:14 +00:00
|
|
|
* Return TRUE on "OK" and "FALSE" on "Cancel".
|
|
|
|
* Close the window.
|
|
|
|
*/
|
|
|
|
|
|
|
|
void
|
|
|
|
file_export_specified_packets_cmd_cb(GtkWidget *w _U_, gpointer data _U_) {
|
2013-01-09 21:04:44 +00:00
|
|
|
GString *file_name = g_string_new("");
|
|
|
|
int file_type;
|
|
|
|
gboolean compressed;
|
|
|
|
packet_range_t range;
|
|
|
|
cf_write_status_t status;
|
|
|
|
gchar *dirname;
|
|
|
|
gchar *display_basename;
|
|
|
|
GtkWidget *msg_dialog;
|
2012-10-03 19:24:14 +00:00
|
|
|
|
|
|
|
/* init the packet range */
|
2012-10-05 18:52:42 +00:00
|
|
|
packet_range_init(&range, &cfile);
|
2013-01-09 21:04:44 +00:00
|
|
|
range.process_filtered = TRUE;
|
2012-10-03 19:24:14 +00:00
|
|
|
range.include_dependents = TRUE;
|
|
|
|
|
2012-06-04 10:27:59 +00:00
|
|
|
/*
|
|
|
|
* Loop until the user either selects a file or gives up.
|
|
|
|
*/
|
|
|
|
for (;;) {
|
2012-10-03 19:24:14 +00:00
|
|
|
#ifdef USE_WIN32_FILE_DIALOGS
|
|
|
|
if (win32_export_specified_packets_file(GDK_WINDOW_HWND(gtk_widget_get_window(top_level)),
|
2013-10-11 17:20:50 +00:00
|
|
|
&cfile, file_name, &file_type, &compressed, &range)) {
|
2012-10-03 19:24:14 +00:00
|
|
|
#else /* USE_WIN32_FILE_DIALOGS */
|
|
|
|
if (gtk_export_specified_packets_file(w, file_name, &file_type, &compressed, &range)) {
|
|
|
|
#endif /* USE_WIN32_FILE_DIALOGS */
|
"Save As" always saves everything and, when the save is done, makes the
new file the current file, as is the case in most if not all other GUI
applications.
A new "Export Specified Packets" menu option allows you to specify which
packets to write out, with the default being the displayed packets (and
those on which the displayed packets depend for, e.g. reassembly), and
never makes the resulting file the current file.
The two operations are conceptually distinct. Lumping them into one
menu item, with the default for "Save As" being "displayed packets only"
and thus making it behave like the latter operation, was causing some
confusion; see, for example, bug 6640.
Make the dialog popped up if you try to "Save As" or "Export Specified
Packets" on top of an existing file ask the "do you want to do this?"
question in the main part of the message, and note in the secondary text
that doing that will overwrite what's in the file; that matches what
TextEdit on OS X and the GNOME text editor say.
svn path=/trunk/; revision=42792
2012-05-22 22:17:57 +00:00
|
|
|
|
2012-10-03 19:24:14 +00:00
|
|
|
/* Check whether the range is valid. */
|
|
|
|
if (!range_check_validity_modal(top_level, &range)) {
|
|
|
|
/* The range isn't valid; the user was told that, and dismissed
|
|
|
|
the dialog telling them that, so let them fix the range
|
|
|
|
and try again, or cancel. */
|
|
|
|
continue;
|
|
|
|
}
|
2005-04-12 21:24:30 +00:00
|
|
|
|
2012-10-03 19:24:14 +00:00
|
|
|
/* XXX - Check for comments? */
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Check that we're not going to save on top of the current
|
|
|
|
* capture 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, file_name->str)) {
|
|
|
|
display_basename = g_filename_display_basename(file_name->str);
|
|
|
|
msg_dialog = gtk_message_dialog_new(GTK_WINDOW(top_level),
|
|
|
|
GTK_DIALOG_DESTROY_WITH_PARENT,
|
|
|
|
GTK_MESSAGE_ERROR,
|
|
|
|
GTK_BUTTONS_OK,
|
|
|
|
"The file \"%s\" is the capture file from which you're exporting the packets.",
|
|
|
|
display_basename);
|
|
|
|
g_free(display_basename);
|
|
|
|
gtk_message_dialog_format_secondary_text(GTK_MESSAGE_DIALOG(msg_dialog),
|
|
|
|
"You cannot export packets on top of the current capture file.");
|
|
|
|
gtk_dialog_run(GTK_DIALOG(msg_dialog));
|
|
|
|
gtk_widget_destroy(msg_dialog);
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
file_add_extension(file_name, file_type, compressed);
|
2008-04-27 07:01:58 +00:00
|
|
|
|
2012-06-21 22:21:02 +00:00
|
|
|
#ifndef _WIN32
|
2012-10-03 19:24:14 +00:00
|
|
|
/* If the file exists and it's user-immutable or not writable,
|
|
|
|
ask the user whether they want to override that. */
|
|
|
|
if (!file_target_unwritable_ui(top_level, file_name->str)) {
|
|
|
|
/* They don't. Let them try another file name or cancel. */
|
|
|
|
continue;
|
|
|
|
}
|
2012-06-21 22:21:02 +00:00
|
|
|
#endif
|
2005-04-12 21:24:30 +00:00
|
|
|
|
2012-10-03 19:24:14 +00:00
|
|
|
/* Attempt to export the file */
|
|
|
|
status = cf_export_specified_packets(&cfile, file_name->str, &range, file_type,
|
|
|
|
compressed);
|
|
|
|
switch (status) {
|
Distinguish between "failed" and "user stopped it" for "save as" and
"export specified packets". For "failed", let the user try again with a
different file, in case it failed due to, for example, running out of
space or quota (probably the most likely failure mode for writing, and
trying to a different volume might be the best workaround). For "user
stopped it", presumably they don't want to try again (the most likely
reason is "it was taking too damn long").
Put "Exporting to: ...", not "Saving: ..." in the statusbar if we're
doing "export specified packets".
In process_specified_packets(), allow a null range pointer to be
specified, meaning "save 'em all"; that avoids the possibly-expensive
(with a large capture) operation of initializing the range.
If a "safe save" atop an existing file fails or is stopped, get rid of
the temporary file we created.
svn path=/trunk/; revision=43095
2012-06-05 02:46:54 +00:00
|
|
|
|
2012-10-03 19:24:14 +00:00
|
|
|
case CF_WRITE_OK:
|
|
|
|
/* The write succeeded; get rid of the file selection box. */
|
|
|
|
/* cf_export_specified_packets() might already closed our dialog! */
|
Distinguish between "failed" and "user stopped it" for "save as" and
"export specified packets". For "failed", let the user try again with a
different file, in case it failed due to, for example, running out of
space or quota (probably the most likely failure mode for writing, and
trying to a different volume might be the best workaround). For "user
stopped it", presumably they don't want to try again (the most likely
reason is "it was taking too damn long").
Put "Exporting to: ...", not "Saving: ..." in the statusbar if we're
doing "export specified packets".
In process_specified_packets(), allow a null range pointer to be
specified, meaning "save 'em all"; that avoids the possibly-expensive
(with a large capture) operation of initializing the range.
If a "safe save" atop an existing file fails or is stopped, get rid of
the temporary file we created.
svn path=/trunk/; revision=43095
2012-06-05 02:46:54 +00:00
|
|
|
|
2012-10-03 19:24:14 +00:00
|
|
|
/* Save the directory name for future file dialogs.
|
|
|
|
XXX - should there be separate ones for "Save As" and
|
|
|
|
"Export Specified Packets"? */
|
|
|
|
dirname = get_dirname(file_name->str); /* Overwrites file_name->str */
|
|
|
|
set_last_open_dir(dirname);
|
|
|
|
break;
|
Distinguish between "failed" and "user stopped it" for "save as" and
"export specified packets". For "failed", let the user try again with a
different file, in case it failed due to, for example, running out of
space or quota (probably the most likely failure mode for writing, and
trying to a different volume might be the best workaround). For "user
stopped it", presumably they don't want to try again (the most likely
reason is "it was taking too damn long").
Put "Exporting to: ...", not "Saving: ..." in the statusbar if we're
doing "export specified packets".
In process_specified_packets(), allow a null range pointer to be
specified, meaning "save 'em all"; that avoids the possibly-expensive
(with a large capture) operation of initializing the range.
If a "safe save" atop an existing file fails or is stopped, get rid of
the temporary file we created.
svn path=/trunk/; revision=43095
2012-06-05 02:46:54 +00:00
|
|
|
|
2012-10-03 19:24:14 +00:00
|
|
|
case CF_WRITE_ERROR:
|
|
|
|
/* The save failed; let the user try again. */
|
|
|
|
continue;
|
|
|
|
|
|
|
|
case CF_WRITE_ABORTED:
|
|
|
|
/* The user aborted the save; just return. */
|
|
|
|
g_string_free(file_name, TRUE);
|
|
|
|
return;
|
|
|
|
}
|
Distinguish between "failed" and "user stopped it" for "save as" and
"export specified packets". For "failed", let the user try again with a
different file, in case it failed due to, for example, running out of
space or quota (probably the most likely failure mode for writing, and
trying to a different volume might be the best workaround). For "user
stopped it", presumably they don't want to try again (the most likely
reason is "it was taking too damn long").
Put "Exporting to: ...", not "Saving: ..." in the statusbar if we're
doing "export specified packets".
In process_specified_packets(), allow a null range pointer to be
specified, meaning "save 'em all"; that avoids the possibly-expensive
(with a large capture) operation of initializing the range.
If a "safe save" atop an existing file fails or is stopped, get rid of
the temporary file we created.
svn path=/trunk/; revision=43095
2012-06-05 02:46:54 +00:00
|
|
|
}
|
2012-10-03 19:24:14 +00:00
|
|
|
g_string_free(file_name, TRUE);
|
|
|
|
return;
|
2005-04-12 21:24:30 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
"Save As" always saves everything and, when the save is done, makes the
new file the current file, as is the case in most if not all other GUI
applications.
A new "Export Specified Packets" menu option allows you to specify which
packets to write out, with the default being the displayed packets (and
those on which the displayed packets depend for, e.g. reassembly), and
never makes the resulting file the current file.
The two operations are conceptually distinct. Lumping them into one
menu item, with the default for "Save As" being "displayed packets only"
and thus making it behave like the latter operation, was causing some
confusion; see, for example, bug 6640.
Make the dialog popped up if you try to "Save As" or "Export Specified
Packets" on top of an existing file ask the "do you want to do this?"
question in the main part of the message, and note in the secondary text
that doing that will overwrite what's in the file; that matches what
TextEdit on OS X and the GNOME text editor say.
svn path=/trunk/; revision=42792
2012-05-22 22:17:57 +00:00
|
|
|
|
2013-08-21 21:44:48 +00:00
|
|
|
void
|
|
|
|
file_export_pdu_ok_cb(GtkWidget *widget _U_, gpointer data)
|
|
|
|
{
|
|
|
|
GtkWidget *msg_dialog;
|
|
|
|
gchar *display_basename;
|
|
|
|
gint response;
|
|
|
|
|
|
|
|
if (prefs.gui_ask_unsaved && cf_has_unsaved_data(&cfile)) {
|
|
|
|
if (cfile.is_tempfile) {
|
|
|
|
msg_dialog = gtk_message_dialog_new(GTK_WINDOW(top_level),
|
|
|
|
(GtkDialogFlags)(GTK_DIALOG_MODAL|GTK_DIALOG_DESTROY_WITH_PARENT),
|
|
|
|
GTK_MESSAGE_QUESTION, GTK_BUTTONS_NONE,
|
|
|
|
"Do you want to save the captured packets before exporting PDUs?");
|
|
|
|
|
|
|
|
gtk_message_dialog_format_secondary_text(GTK_MESSAGE_DIALOG(msg_dialog),
|
|
|
|
"After the export, the captured packets will no longer be accessible.");
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
display_basename = g_filename_display_basename(cfile.filename);
|
|
|
|
msg_dialog = gtk_message_dialog_new(GTK_WINDOW(top_level),
|
|
|
|
(GtkDialogFlags)(GTK_DIALOG_MODAL|GTK_DIALOG_DESTROY_WITH_PARENT),
|
|
|
|
GTK_MESSAGE_QUESTION, GTK_BUTTONS_NONE,
|
|
|
|
"Do you want to save the changes you've made "
|
|
|
|
"to the capture file \"%s\" before exporting PDUs from it?",
|
|
|
|
display_basename);
|
|
|
|
g_free(display_basename);
|
|
|
|
gtk_message_dialog_format_secondary_text(GTK_MESSAGE_DIALOG(msg_dialog),
|
|
|
|
"Unsaved changes will be discarded when PDUs are exported.");
|
|
|
|
}
|
|
|
|
|
|
|
|
gtk_dialog_add_button(GTK_DIALOG(msg_dialog),
|
|
|
|
WIRESHARK_STOCK_DONT_SAVE, GTK_RESPONSE_CLOSE);
|
|
|
|
gtk_dialog_add_button(GTK_DIALOG(msg_dialog),
|
|
|
|
GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL);
|
|
|
|
gtk_dialog_add_button(GTK_DIALOG(msg_dialog),
|
|
|
|
WIRESHARK_STOCK_SAVE, GTK_RESPONSE_ACCEPT);
|
|
|
|
gtk_dialog_set_alternative_button_order(GTK_DIALOG(msg_dialog),
|
|
|
|
GTK_RESPONSE_ACCEPT,
|
|
|
|
GTK_RESPONSE_CANCEL,
|
|
|
|
GTK_RESPONSE_CLOSE,
|
|
|
|
-1);
|
|
|
|
gtk_dialog_set_default_response(GTK_DIALOG(msg_dialog), GTK_RESPONSE_ACCEPT);
|
|
|
|
|
|
|
|
response = gtk_dialog_run(GTK_DIALOG(msg_dialog));
|
|
|
|
gtk_widget_destroy(msg_dialog);
|
|
|
|
|
|
|
|
switch (response) {
|
|
|
|
case GTK_RESPONSE_CLOSE:
|
|
|
|
/* nothing to do, user chose to discard the unsaved data */
|
|
|
|
break;
|
|
|
|
|
|
|
|
case GTK_RESPONSE_ACCEPT:
|
|
|
|
/* save the file but don't close it */
|
|
|
|
do_file_save(&cfile, FALSE);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case GTK_RESPONSE_CANCEL:
|
|
|
|
case GTK_RESPONSE_NONE:
|
|
|
|
case GTK_RESPONSE_DELETE_EVENT:
|
|
|
|
default:
|
|
|
|
/* don't do the export. */
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-01-20 05:51:10 +00:00
|
|
|
export_pdu_action(data);
|
2013-08-21 21:44:48 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
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)
|
|
|
|
{
|
2011-12-01 06:33:14 +00:00
|
|
|
GtkWidget *fs_widget = (GtkWidget *)data;
|
2013-01-09 21:04:44 +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
|
|
|
{
|
2012-06-21 22:21:02 +00:00
|
|
|
#ifdef USE_WIN32_FILE_DIALOGS
|
2011-07-29 10:11:24 +00:00
|
|
|
win32_import_color_file(GDK_WINDOW_HWND(gtk_widget_get_window(top_level)), color_filters);
|
2012-06-21 22:21:02 +00:00
|
|
|
#else /* USE_WIN32_FILE_DIALOGS */
|
2013-01-09 21:04:44 +00:00
|
|
|
GtkWidget *main_vb, *cfglobal_but;
|
2015-12-22 20:07:00 +00:00
|
|
|
gchar *cf_name, *s, *err_msg = NULL;
|
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). */
|
|
|
|
|
2006-05-22 07:29:40 +00:00
|
|
|
file_color_import_w = file_selection_new("Wireshark: Import Color Filters",
|
2013-05-14 21:53:57 +00:00
|
|
|
GTK_WINDOW(top_level),
|
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 */
|
2012-06-02 23:53:04 +00:00
|
|
|
main_vb = ws_gtk_box_new(GTK_ORIENTATION_VERTICAL, 3, FALSE);
|
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");
|
2013-03-11 16:28:11 +00:00
|
|
|
gtk_box_pack_start(GTK_BOX(main_vb), cfglobal_but, FALSE, FALSE, 0);
|
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);
|
|
|
|
|
2012-06-04 19:37:04 +00:00
|
|
|
/*
|
|
|
|
* Loop until the user either selects a file or gives up.
|
|
|
|
*/
|
|
|
|
for (;;) {
|
2012-06-21 22:21:02 +00:00
|
|
|
cf_name = file_selection_run(file_color_import_w);
|
|
|
|
if (cf_name == NULL) {
|
|
|
|
/* User cancelled or closed the dialog. */
|
2012-06-04 19:37:04 +00:00
|
|
|
return;
|
|
|
|
}
|
2004-03-27 11:16:58 +00:00
|
|
|
|
2012-06-04 19:37:04 +00:00
|
|
|
/* Try to open the color filter file. */
|
2016-01-01 04:14:08 +00:00
|
|
|
if (!color_filters_import(cf_name, color_filters, &err_msg, color_filter_add_cb)) {
|
2012-06-04 19:37:04 +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. */
|
2015-12-22 20:07:00 +00:00
|
|
|
simple_dialog(ESD_TYPE_ERROR, ESD_BTN_OK, "%s", err_msg);
|
|
|
|
g_free(err_msg);
|
2012-06-04 19:37:04 +00:00
|
|
|
g_free(cf_name);
|
|
|
|
continue;
|
|
|
|
}
|
2008-04-27 07:01:58 +00:00
|
|
|
|
2012-06-04 19:37:04 +00:00
|
|
|
/* We've crossed the Rubicon; get rid of the file selection box. */
|
|
|
|
window_destroy(GTK_WIDGET(file_color_import_w));
|
2003-08-18 21:27:11 +00:00
|
|
|
|
2012-06-04 19:37:04 +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);
|
2003-08-18 21:27:11 +00:00
|
|
|
|
|
|
|
g_free(cf_name);
|
|
|
|
return;
|
|
|
|
}
|
2012-06-21 22:21:02 +00:00
|
|
|
#endif /* USE_WIN32_FILE_DIALOGS */
|
2003-08-18 21:27:11 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
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
|
|
|
{
|
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
|
|
|
{
|
2013-01-09 21:04:44 +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
|
|
|
{
|
2012-06-22 08:22:11 +00:00
|
|
|
#ifdef USE_WIN32_FILE_DIALOGS
|
2013-10-11 17:20:50 +00:00
|
|
|
win32_export_color_file(GDK_WINDOW_HWND(gtk_widget_get_window(top_level)), &cfile, filter_list);
|
2012-06-21 22:21:02 +00:00
|
|
|
#else /* USE_WIN32_FILE_DIALOGS */
|
2012-06-04 19:37:04 +00:00
|
|
|
GtkWidget *file_color_export_w;
|
2006-02-15 11:01:57 +00:00
|
|
|
GtkWidget *main_vb, *cfglobal_but;
|
2009-09-28 17:44:06 +00:00
|
|
|
GtkWidget *cfselect_cb;
|
2012-06-04 19:37:04 +00:00
|
|
|
gchar *cf_name;
|
|
|
|
gchar *dirname;
|
2015-12-22 20:07:00 +00:00
|
|
|
gchar *err_msg = NULL;
|
2003-08-18 21:27:11 +00:00
|
|
|
|
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",
|
2013-05-14 21:53:57 +00:00
|
|
|
GTK_WINDOW(top_level),
|
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 */
|
2012-06-02 23:53:04 +00:00
|
|
|
main_vb = ws_gtk_box_new(GTK_ORIENTATION_VERTICAL, 3, FALSE);
|
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");
|
2013-03-11 16:18:41 +00:00
|
|
|
gtk_box_pack_start(GTK_BOX(main_vb), cfselect_cb, FALSE, FALSE, 0);
|
2006-10-02 23:11:55 +00:00
|
|
|
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");
|
2013-03-11 16:28:11 +00:00
|
|
|
gtk_box_pack_start(GTK_BOX(main_vb), cfglobal_but, FALSE, FALSE, 0);
|
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);
|
|
|
|
|
2012-06-04 19:37:04 +00:00
|
|
|
/*
|
|
|
|
* Loop until the user either selects a file or gives up.
|
|
|
|
*/
|
|
|
|
for (;;) {
|
2012-06-21 22:21:02 +00:00
|
|
|
cf_name = file_selection_run(file_color_export_w);
|
|
|
|
if (cf_name == NULL) {
|
|
|
|
/* User cancelled or closed the dialog. */
|
2012-06-04 19:37:04 +00:00
|
|
|
return;
|
|
|
|
}
|
2003-08-18 21:27:11 +00:00
|
|
|
|
2012-06-21 22:21:02 +00:00
|
|
|
#ifndef _WIN32
|
2012-06-19 19:20:47 +00:00
|
|
|
/* If the file exists and it's user-immutable or not writable,
|
|
|
|
ask the user whether they want to override that. */
|
|
|
|
if (!file_target_unwritable_ui(file_color_export_w, cf_name)) {
|
2012-06-04 19:37:04 +00:00
|
|
|
/* They don't. Let them try another file name or cancel. */
|
|
|
|
g_free(cf_name);
|
|
|
|
continue;
|
|
|
|
}
|
2012-06-21 22:21:02 +00:00
|
|
|
#endif
|
2003-08-18 21:27:11 +00:00
|
|
|
|
2012-06-04 19:37:04 +00:00
|
|
|
/* Write out the filters (all, or only the ones that are currently
|
|
|
|
displayed or selected) to the file with the specified name. */
|
2015-12-22 20:07:00 +00:00
|
|
|
if (!color_filters_export(cf_name, (GSList *)filter_list, color_selected, &err_msg)) {
|
2012-06-04 19:37:04 +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. */
|
2015-12-22 20:07:00 +00:00
|
|
|
simple_dialog(ESD_TYPE_ERROR, ESD_BTN_OK, "%s", err_msg);
|
|
|
|
g_free(err_msg);
|
2012-06-04 19:37:04 +00:00
|
|
|
g_free(cf_name);
|
|
|
|
continue;
|
|
|
|
}
|
2003-08-18 21:27:11 +00:00
|
|
|
|
2012-06-04 19:37:04 +00:00
|
|
|
/* The write succeeded; get rid of the file selection box. */
|
|
|
|
window_destroy(GTK_WIDGET(file_color_export_w));
|
2003-08-18 21:27:11 +00:00
|
|
|
|
2012-06-04 19:37:04 +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);
|
|
|
|
}
|
2012-06-21 22:21:02 +00:00
|
|
|
#endif /* USE_WIN32_FILE_DIALOGS */
|
2003-08-18 21:27:11 +00:00
|
|
|
}
|
2012-07-16 20:46:13 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Editor modelines
|
|
|
|
*
|
|
|
|
* Local Variables:
|
|
|
|
* c-basic-offset: 2
|
|
|
|
* tab-width: 8
|
|
|
|
* indent-tabs-mode: nil
|
|
|
|
* End:
|
|
|
|
*
|
|
|
|
* ex: set shiftwidth=2 tabstop=8 expandtab:
|
|
|
|
* :indentSize=2:tabSize=8:noTabs=true:
|
|
|
|
*/
|