aboutsummaryrefslogtreecommitdiffstats
path: root/ui/file_dialog.c
diff options
context:
space:
mode:
authorGuy Harris <guy@alum.mit.edu>2018-02-09 11:18:22 -0800
committerGuy Harris <guy@alum.mit.edu>2018-02-09 20:29:08 +0000
commit25d90cb13c6f4296fd0c698ea8b2b67766bfbc88 (patch)
tree18b449c143446b9a70e6b57ffbc3c46780ad8da0 /ui/file_dialog.c
parentbe38102eea170403b66d57d3f8f01ea4d49eaf29 (diff)
Put the preview-generation loop into a common routine.
Don't have all the file open dialogs have their own copies. Change-Id: Icd6f2fd44b081575e6481a134027c90046938c64 Reviewed-on: https://code.wireshark.org/review/25717 Petri-Dish: Guy Harris <guy@alum.mit.edu> Tested-by: Petri Dish Buildbot Reviewed-by: Guy Harris <guy@alum.mit.edu>
Diffstat (limited to 'ui/file_dialog.c')
-rw-r--r--ui/file_dialog.c95
1 files changed, 95 insertions, 0 deletions
diff --git a/ui/file_dialog.c b/ui/file_dialog.c
new file mode 100644
index 0000000000..754d4b6f5c
--- /dev/null
+++ b/ui/file_dialog.c
@@ -0,0 +1,95 @@
+/* file_dialog.c
+ * Common file dialog routines
+ *
+ * Wireshark - Network traffic analyzer
+ * By Gerald Combs <gerald@wireshark.org>
+ * Copyright 2006 Gerald Combs
+ *
+ * SPDX-License-Identifier: GPL-2.0-or-later*/
+
+#include "config.h"
+
+#include <time.h>
+
+#include <glib.h>
+
+#include <wsutil/nstime.h>
+
+#include <wiretap/wtap.h>
+
+#include <epan/prefs.h>
+
+#include "ui/file_dialog.h"
+
+ws_file_preview_times_status
+get_times_for_preview(wtap *wth, ws_file_preview_times *times,
+ guint32 *num_packets, int *err, gchar **err_info)
+{
+ gint64 data_offset;
+ const wtap_rec *rec;
+ guint32 packets;
+ gboolean have_times;
+ gboolean timed_out;
+ time_t time_preview, time_current;
+ double cur_time;
+
+ times->start_time = 0;
+ times->stop_time = 0;
+ packets = 0;
+ have_times = FALSE;
+ timed_out = FALSE;
+ time(&time_preview);
+ while ((wtap_read(wth, err, err_info, &data_offset))) {
+ rec = wtap_get_rec(wth);
+ if (rec->presence_flags & WTAP_HAS_TS) {
+ cur_time = nstime_to_sec(&rec->ts);
+ if (!have_times) {
+ times->start_time = cur_time;
+ times->stop_time = cur_time;
+ have_times = TRUE;
+ }
+ if (cur_time < times->start_time) {
+ times->start_time = cur_time;
+ }
+ if (cur_time > times->stop_time){
+ times->stop_time = cur_time;
+ }
+ }
+
+ packets++;
+ if (packets%1000 == 0) {
+ /* do we have a timeout? */
+ time(&time_current);
+ if (time_current-time_preview >= (time_t) prefs.gui_fileopen_preview) {
+ timed_out = TRUE;
+ break;
+ }
+ }
+ }
+ *num_packets = packets;
+ if (*err != 0) {
+ /* Read error. */
+ return PREVIEW_READ_ERROR;
+ }
+
+ if (have_times) {
+ if (timed_out)
+ return PREVIEW_TIMED_OUT;
+ else
+ return PREVIEW_HAVE_TIMES;
+ } else
+ return PREVIEW_HAVE_NO_TIMES;
+}
+
+/*
+ * Editor modelines
+ *
+ * Local Variables:
+ * c-basic-offset: 4
+ * tab-width: 8
+ * indent-tabs-mode: nil
+ * End:
+ *
+ * ex: set shiftwidth=4 tabstop=8 expandtab:
+ * :indentSize=4:tabSize=8:noTabs=true:
+ */