aboutsummaryrefslogtreecommitdiffstats
path: root/file.c
diff options
context:
space:
mode:
authorGuy Harris <guy@alum.mit.edu>2013-04-01 23:44:29 +0000
committerGuy Harris <guy@alum.mit.edu>2013-04-01 23:44:29 +0000
commitd94275940164f0b40d12d1caa709b113360491c2 (patch)
treec2db98b41c1d80160f286af62b5d94f6959359c7 /file.c
parentf8965b7b2cddad13ca785b283dc05d59c3af2438 (diff)
Add routines to file.c to indicate whether:
a save can be done ("can" in the sense of "there's something to save" and in the sense of "we can write that something out"); a "save as" can be done (in the sense of "we can write what we have out"); there's unsaved data to save (which might be unsaved changes or might be a temporary file full of packets); and use them as appropriate. This means that the "unsaved data" indicator in the UI will be turned on for temporary files full of packets as well as for files with unsaved changes; that's what we want. svn path=/trunk/; revision=48693
Diffstat (limited to 'file.c')
-rw-r--r--file.c98
1 files changed, 93 insertions, 5 deletions
diff --git a/file.c b/file.c
index eea204e2d9..b9d62a3c65 100644
--- a/file.c
+++ b/file.c
@@ -3973,15 +3973,103 @@ cf_can_write_with_wiretap(capture_file *cf)
{
/* We don't care whether we support the comments in this file or not;
if we can't, we'll offer the user the option of discarding the
- comments.
-
- XXX - we shouldn't offer the option of adding or editing comments
- of a particular type if we don't support that particular type of
- comment in any file format. */
+ comments. */
return wtap_dump_can_write(cf->linktypes, 0);
}
/*
+ * Should we let the user do a save?
+ *
+ * We should if:
+ *
+ * the file has unsaved changes, and we can save it in some
+ * format through Wiretap
+ *
+ * or
+ *
+ * the file is a temporary file and has no unsaved changes (so
+ * that "saving" it just means copying it).
+ *
+ * XXX - we shouldn't allow files to be edited if they can't be saved,
+ * so cf->unsaved_changes should be true only if the file can be saved.
+ *
+ * We don't care whether we support the comments in this file or not;
+ * if we can't, we'll offer the user the option of discarding the
+ * comments.
+ */
+gboolean
+cf_can_save(capture_file *cf)
+{
+ if (cf->unsaved_changes && wtap_dump_can_write(cf->linktypes, 0)) {
+ /* Saved changes, and we can write it out with Wiretap. */
+ return TRUE;
+ }
+
+ if (cf->is_tempfile && !cf->unsaved_changes) {
+ /*
+ * Temporary file with no unsaved changes, so we can just do a
+ * raw binary copy.
+ */
+ return TRUE;
+ }
+
+ /* Nothing to save. */
+ return FALSE;
+}
+
+/*
+ * Should we let the user do a "save as"?
+ *
+ * That's true if:
+ *
+ * we can save it in some format through Wiretap
+ *
+ * or
+ *
+ * the file is a temporary file and has no unsaved changes (so
+ * that "saving" it just means copying it).
+ *
+ * XXX - we shouldn't allow files to be edited if they can't be saved,
+ * so cf->unsaved_changes should be true only if the file can be saved.
+ *
+ * We don't care whether we support the comments in this file or not;
+ * if we can't, we'll offer the user the option of discarding the
+ * comments.
+ */
+gboolean
+cf_can_save_as(capture_file *cf)
+{
+ if (wtap_dump_can_write(cf->linktypes, 0)) {
+ /* We can write it out with Wiretap. */
+ return TRUE;
+ }
+
+ if (cf->is_tempfile && !cf->unsaved_changes) {
+ /*
+ * Temporary file with no unsaved changes, so we can just do a
+ * raw binary copy.
+ */
+ return TRUE;
+ }
+
+ /* Nothing to save. */
+ return FALSE;
+}
+
+/*
+ * Does this file have unsaved data?
+ */
+gboolean
+cf_not_saved(capture_file *cf)
+{
+ /*
+ * If this is a temporary file, or a file with unsaved changes, it
+ * has unsaved data.
+ */
+ return cf->is_tempfile || cf->unsaved_changes;
+}
+
+/*
* Quick scan to find packet offsets.
*/
static cf_read_status_t