diff options
author | Guy Harris <guy@alum.mit.edu> | 2001-12-06 02:21:26 +0000 |
---|---|---|
committer | Guy Harris <guy@alum.mit.edu> | 2001-12-06 02:21:26 +0000 |
commit | a936b559df71128d0d40de3647248464aa60b534 (patch) | |
tree | aa6e4bbf6f48a2c8e17b6ddb772bf9b1b925fe85 | |
parent | fcdb3784172eb64a6a7c6a79793b6541f54c7189 (diff) |
Make the "Save only marked frames" button in the "Save As..." dialog box
sensitive only if there *are* marked frames.
svn path=/trunk/; revision=4341
-rw-r--r-- | file.c | 23 | ||||
-rw-r--r-- | file.h | 15 | ||||
-rw-r--r-- | gtk/file_dlg.c | 46 | ||||
-rw-r--r-- | gtk/file_dlg.h | 13 | ||||
-rw-r--r-- | gtk/main.c | 11 |
5 files changed, 91 insertions, 17 deletions
@@ -1,7 +1,7 @@ /* file.c * File I/O routines * - * $Id: file.c,v 1.249 2001/12/04 23:38:53 guy Exp $ + * $Id: file.c,v 1.250 2001/12/06 02:21:24 guy Exp $ * * Ethereal - Network traffic analyzer * By Gerald Combs <gerald@ethereal.com> @@ -175,6 +175,7 @@ open_cap_file(char *fname, gboolean is_tempfile, capture_file *cf) cf->cd_t = wtap_file_type(cf->wth); cf->count = 0; + cf->marked_count = 0; cf->drops_known = FALSE; cf->drops = 0; cf->esec = 0; @@ -1642,6 +1643,26 @@ unselect_field(void) set_menus_for_selected_tree_row(FALSE); } +/* + * Mark a particular frame. + */ +void +mark_frame(capture_file *cf, frame_data *frame) +{ + frame->flags.marked = TRUE; + cf->marked_count++; +} + +/* + * Unmark a particular frame. + */ +void +unmark_frame(capture_file *cf, frame_data *frame) +{ + frame->flags.marked = FALSE; + cf->marked_count--; +} + static void freeze_clist(capture_file *cf) { @@ -1,7 +1,7 @@ /* file.h * Definitions for file structures and routines * - * $Id: file.h,v 1.86 2001/12/04 08:25:55 guy Exp $ + * $Id: file.h,v 1.87 2001/12/06 02:21:25 guy Exp $ * * Ethereal - Network traffic analyzer * By Gerald Combs <gerald@ethereal.com> @@ -53,7 +53,8 @@ typedef struct _capture_file { guint16 cd_t; /* File type of capture file */ int lnk_t; /* Link-layer type with which to save capture */ guint32 vers; /* Version. For tcpdump minor is appended to major */ - int count; /* Packet count */ + int count; /* Total number of frames */ + int marked_count; /* Number of marked frames */ gboolean drops_known; /* TRUE if we know how many packets were dropped */ guint32 drops; /* Dropped packets */ guint32 esec; /* Elapsed seconds */ @@ -130,6 +131,16 @@ void unselect_packet(capture_file *); void unselect_field(void); +/* + * Mark a particular frame in a particular capture. + */ +void mark_frame(capture_file *, frame_data *); + +/* + * Unmark a particular frame in a particular capture. + */ +void unmark_frame(capture_file *, frame_data *); + /* Moves or copies a file. Returns 0 on failure, 1 on success */ int file_mv(char *from, char *to); diff --git a/gtk/file_dlg.c b/gtk/file_dlg.c index 8a769f1da6..dfefc25025 100644 --- a/gtk/file_dlg.c +++ b/gtk/file_dlg.c @@ -1,7 +1,7 @@ /* file_dlg.c * Dialog boxes for handling files * - * $Id: file_dlg.c,v 1.44 2001/11/09 00:08:30 guy Exp $ + * $Id: file_dlg.c,v 1.45 2001/12/06 02:21:26 guy Exp $ * * Ethereal - Network traffic analyzer * By Gerald Combs <gerald@ethereal.com> @@ -378,8 +378,8 @@ select_file_type_cb(GtkWidget *w, gpointer data) /* We can select only the filtered or marked packets to be saved if we can use Wiretap to save the file. */ gtk_widget_set_sensitive(filter_cb, can_save_with_wiretap(new_filetype)); - gtk_widget_set_sensitive(mark_cb, can_save_with_wiretap(new_filetype)); filetype = new_filetype; + file_set_save_marked_sensitive(); } } @@ -472,17 +472,15 @@ file_save_as_cmd_cb(GtkWidget *w, gpointer data) gtk_widget_show(filter_cb); /* - * XXX - should this be sensitive only if at least one packet is - * marked, so that there are marked packets to save, and if not - * all packets are marked, so that "only marked packets" is different - * from "all packets"? + * XXX - if the number of marked frames changes to or from 0, we + * should change whether this is sensitive or not. */ mark_cb = gtk_check_button_new_with_label("Save only marked packets"); gtk_container_add(GTK_CONTAINER(main_vb), mark_cb); + marked = FALSE; gtk_toggle_button_set_state(GTK_TOGGLE_BUTTON(mark_cb), FALSE); gtk_signal_connect(GTK_OBJECT(mark_cb), "toggled", GTK_SIGNAL_FUNC(toggle_marked_cb), NULL); - gtk_widget_set_sensitive(mark_cb, can_save_with_wiretap(filetype)); gtk_widget_show(mark_cb); /* File type row */ @@ -501,6 +499,15 @@ file_save_as_cmd_cb(GtkWidget *w, gpointer data) gtk_box_pack_start(GTK_BOX(ft_hb), ft_om, FALSE, FALSE, 0); gtk_widget_show(ft_om); + /* + * Make the "Save only marked packets" toggle sensitive if there are + * marked frames; make it insensitive, turn it off, and set the + * file type option menu appropriately, if there aren't. + * + * This has to be done after we create the file type menu option. + */ + file_set_save_marked_sensitive(); + /* Connect the cancel_button to destroy the widget */ gtk_signal_connect_object(GTK_OBJECT (GTK_FILE_SELECTION (file_save_as_w)->cancel_button), "clicked", (GtkSignalFunc) @@ -512,9 +519,34 @@ file_save_as_cmd_cb(GtkWidget *w, gpointer data) dlg_set_cancel(file_save_as_w, GTK_FILE_SELECTION(file_save_as_w)->cancel_button); gtk_file_selection_set_filename(GTK_FILE_SELECTION(file_save_as_w), ""); + gtk_widget_show(file_save_as_w); } +/* + * Set the "Save only marked packets" toggle button as appropriate for + * the current output file type and count of marked packets. + * Called when the "Save As..." dialog box is created and when either + * the file type or the marked count changes. + */ +void +file_set_save_marked_sensitive(void) +{ + /* We can request that only the marked packets be saved only if we + can use Wiretap to save the file and if there *are* marked packets. */ + if (can_save_with_wiretap(filetype) && cfile.marked_count != 0) + gtk_widget_set_sensitive(mark_cb, TRUE); + else { + /* Force the "Save only marked packets" toggle to "false", turn + off the flag it controls, and update the list of types we can + save the file as. */ + marked = FALSE; + gtk_toggle_button_set_state(GTK_TOGGLE_BUTTON(mark_cb), FALSE); + set_file_type_list(ft_om); + gtk_widget_set_sensitive(mark_cb, FALSE); + } +} + static void file_save_as_ok_cb(GtkWidget *w, GtkFileSelection *fs) { gchar *cf_name; diff --git a/gtk/file_dlg.h b/gtk/file_dlg.h index 6076d1f28b..b7e5a7084a 100644 --- a/gtk/file_dlg.h +++ b/gtk/file_dlg.h @@ -1,12 +1,11 @@ /* file_dlg.h * Definitions for dialog boxes for handling files * - * $Id: file_dlg.h,v 1.1 2000/02/12 06:58:41 guy Exp $ + * $Id: file_dlg.h,v 1.2 2001/12/06 02:21:26 guy Exp $ * * Ethereal - Network traffic analyzer - * By Gerald Combs <gerald@zing.org> + * By Gerald Combs <gerald@ethereal.com> * Copyright 1998 Gerald Combs - * * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License @@ -32,4 +31,12 @@ void file_save_as_cmd_cb(GtkWidget *, gpointer); void file_close_cmd_cb(GtkWidget *, gpointer); void file_reload_cmd_cb(GtkWidget *, gpointer); +/* + * Set the "Save only marked packets" toggle button as appropriate for + * the current output file type and count of marked packets. + * Called when the "Save As..." dialog box is created and when either + * the file type or the marked count changes. + */ +void file_set_save_marked_sensitive(void); + #endif /* file_dlg.h */ diff --git a/gtk/main.c b/gtk/main.c index 13ba0b6854..a73acfcc94 100644 --- a/gtk/main.c +++ b/gtk/main.c @@ -1,6 +1,6 @@ /* main.c * - * $Id: main.c,v 1.215 2001/12/04 08:25:59 guy Exp $ + * $Id: main.c,v 1.216 2001/12/06 02:21:26 guy Exp $ * * Ethereal - Network traffic analyzer * By Gerald Combs <gerald@ethereal.com> @@ -127,6 +127,7 @@ #include "color_utils.h" #include "filter_prefs.h" #include "prefs_dlg.h" +#include "file_dlg.h" #include "column.h" #include "print.h" #include "resolv.h" @@ -371,15 +372,18 @@ static void set_frame_mark(gboolean set, frame_data *frame, gint row) { GdkColor fg, bg; - if (frame == NULL || row == -1) return; - frame->flags.marked = set; + if (row == -1) + return; if (set) { + mark_frame(&cfile, frame); color_t_to_gdkcolor(&fg, &prefs.gui_marked_fg); color_t_to_gdkcolor(&bg, &prefs.gui_marked_bg); } else { + unmark_frame(&cfile, frame); fg = BLACK; bg = WHITE; } + file_set_save_marked_sensitive(); gtk_clist_set_background(GTK_CLIST(packet_list), row, &bg); gtk_clist_set_foreground(GTK_CLIST(packet_list), row, &fg); } @@ -413,7 +417,6 @@ void mark_frame_cb(GtkWidget *w, gpointer data) { static void mark_all_frames(gboolean set) { frame_data *fdata; - if (cfile.plist == NULL) return; for (fdata = cfile.plist; fdata != NULL; fdata = fdata->next) { set_frame_mark(set, fdata, |