2012-01-04 22:13:01 +00:00
|
|
|
/* capture_file_dialog.cpp
|
|
|
|
*
|
|
|
|
* Wireshark - Network traffic analyzer
|
|
|
|
* By Gerald Combs <gerald@wireshark.org>
|
|
|
|
* Copyright 1998 Gerald Combs
|
|
|
|
*
|
2018-04-30 07:47:58 +00:00
|
|
|
* SPDX-License-Identifier: GPL-2.0-or-later
|
|
|
|
*/
|
2012-01-04 22:13:01 +00:00
|
|
|
|
2021-11-12 17:23:04 +00:00
|
|
|
#include "config.h"
|
|
|
|
|
2019-12-09 22:36:28 +00:00
|
|
|
#include "file.h"
|
|
|
|
|
2012-07-19 23:07:17 +00:00
|
|
|
#include <wiretap/wtap.h>
|
|
|
|
|
2012-10-08 20:01:59 +00:00
|
|
|
#include "packet_range_group_box.h"
|
2012-01-04 22:13:01 +00:00
|
|
|
#include "capture_file_dialog.h"
|
|
|
|
|
2019-12-09 22:36:28 +00:00
|
|
|
|
2013-04-24 11:07:25 +00:00
|
|
|
#ifdef Q_OS_WIN
|
2012-07-12 00:04:53 +00:00
|
|
|
#include <windows.h>
|
2017-04-23 23:48:17 +00:00
|
|
|
#include "ui/packet_range.h"
|
2012-07-12 00:04:53 +00:00
|
|
|
#include "ui/win32/file_dlg_win32.h"
|
2013-04-24 11:07:25 +00:00
|
|
|
#else // Q_OS_WIN
|
2012-09-06 23:41:34 +00:00
|
|
|
|
2012-07-27 21:43:02 +00:00
|
|
|
#include <errno.h>
|
2016-03-22 01:39:17 +00:00
|
|
|
#include "wsutil/filesystem.h"
|
|
|
|
#include "wsutil/nstime.h"
|
2016-09-08 21:31:03 +00:00
|
|
|
#include "wsutil/str_util.h"
|
|
|
|
#include "wsutil/utf8_entities.h"
|
|
|
|
|
2016-02-29 21:29:19 +00:00
|
|
|
#include "ui/all_files_wildcard.h"
|
2012-10-16 19:47:43 +00:00
|
|
|
|
2016-09-13 19:47:22 +00:00
|
|
|
#include <QCheckBox>
|
|
|
|
#include <QFileInfo>
|
2012-07-21 01:21:41 +00:00
|
|
|
#include <QGridLayout>
|
|
|
|
#include <QHBoxLayout>
|
|
|
|
#include <QLabel>
|
|
|
|
#include <QLineEdit>
|
2016-09-13 19:47:22 +00:00
|
|
|
#include <QSortFilterProxyModel>
|
2012-10-08 20:01:59 +00:00
|
|
|
#include <QSpacerItem>
|
2016-09-13 19:47:22 +00:00
|
|
|
#include <QVBoxLayout>
|
|
|
|
#endif // ! Q_OS_WIN
|
2012-07-12 00:04:53 +00:00
|
|
|
|
2012-12-05 20:33:40 +00:00
|
|
|
#include <QPushButton>
|
2019-12-09 22:36:28 +00:00
|
|
|
#include <QMessageBox>
|
|
|
|
|
2016-03-22 01:39:17 +00:00
|
|
|
#include "epan/prefs.h"
|
2017-07-25 14:15:18 +00:00
|
|
|
#include <ui/qt/utils/qt_ui_utils.h>
|
2016-03-22 01:39:17 +00:00
|
|
|
#include <wireshark_application.h>
|
2012-12-05 20:33:40 +00:00
|
|
|
|
2012-10-08 20:01:59 +00:00
|
|
|
CaptureFileDialog::CaptureFileDialog(QWidget *parent, capture_file *cf, QString &display_filter) :
|
2019-11-24 23:32:06 +00:00
|
|
|
WiresharkFileDialog(parent),
|
2012-10-08 20:01:59 +00:00
|
|
|
cap_file_(cf),
|
2012-10-13 00:21:25 +00:00
|
|
|
display_filter_(display_filter),
|
2013-04-24 11:07:25 +00:00
|
|
|
#if !defined(Q_OS_WIN)
|
2016-07-03 20:50:47 +00:00
|
|
|
display_filter_edit_(NULL),
|
2012-10-08 20:01:59 +00:00
|
|
|
default_ft_(-1),
|
2012-10-15 18:32:51 +00:00
|
|
|
save_bt_(NULL),
|
|
|
|
help_topic_(TOPIC_ACTION_NONE)
|
2012-09-26 19:52:53 +00:00
|
|
|
#else
|
2012-10-08 20:01:59 +00:00
|
|
|
file_type_(-1)
|
2012-09-26 19:52:53 +00:00
|
|
|
#endif
|
2012-01-04 22:13:01 +00:00
|
|
|
{
|
2016-03-22 01:39:17 +00:00
|
|
|
switch (prefs.gui_fileopen_style) {
|
|
|
|
case FO_STYLE_LAST_OPENED:
|
|
|
|
/* The user has specified that we should start out in the last directory
|
|
|
|
* we looked in. If we've already opened a file, use its containing
|
|
|
|
* directory, if we could determine it, as the directory, otherwise
|
|
|
|
* use the "last opened" directory saved in the preferences file if
|
|
|
|
* there was one.
|
|
|
|
*/
|
|
|
|
setDirectory(wsApp->lastOpenDir());
|
|
|
|
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')
|
|
|
|
setDirectory(prefs.gui_fileopen_dir);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2013-04-24 11:07:25 +00:00
|
|
|
#if !defined(Q_OS_WIN)
|
2012-07-21 01:21:41 +00:00
|
|
|
// Add extra widgets
|
2015-05-15 18:08:18 +00:00
|
|
|
// https://wiki.qt.io/Qt_project_org_faq#How_can_I_add_widgets_to_my_QFileDialog_instance.3F
|
2012-07-21 01:21:41 +00:00
|
|
|
setOption(QFileDialog::DontUseNativeDialog, true);
|
2016-09-13 19:47:22 +00:00
|
|
|
setOption(QFileDialog::HideNameFilterDetails, true);
|
2012-09-06 22:58:39 +00:00
|
|
|
QGridLayout *fd_grid = qobject_cast<QGridLayout*>(layout());
|
|
|
|
QHBoxLayout *h_box = new QHBoxLayout();
|
2012-07-21 01:21:41 +00:00
|
|
|
|
2012-10-08 20:01:59 +00:00
|
|
|
last_row_ = fd_grid->rowCount();
|
2012-07-21 01:21:41 +00:00
|
|
|
|
2012-10-08 20:01:59 +00:00
|
|
|
fd_grid->addItem(new QSpacerItem(1, 1), last_row_, 0);
|
2016-09-08 21:31:03 +00:00
|
|
|
fd_grid->addLayout(h_box, last_row_, 0, 1, 2);
|
2012-10-08 20:01:59 +00:00
|
|
|
last_row_++;
|
2012-07-21 01:21:41 +00:00
|
|
|
|
2012-09-06 22:58:39 +00:00
|
|
|
// Left and right boxes for controls and preview
|
|
|
|
h_box->addLayout(&left_v_box_);
|
|
|
|
h_box->addLayout(&right_v_box_);
|
2012-10-12 23:40:29 +00:00
|
|
|
|
2013-04-24 11:07:25 +00:00
|
|
|
#else // Q_OS_WIN
|
2012-09-10 23:03:22 +00:00
|
|
|
merge_type_ = 0;
|
2013-04-24 11:07:25 +00:00
|
|
|
#endif // Q_OS_WIN
|
2012-09-06 22:58:39 +00:00
|
|
|
}
|
2012-07-30 21:22:53 +00:00
|
|
|
|
2019-12-09 22:36:28 +00:00
|
|
|
check_savability_t CaptureFileDialog::checkSaveAsWithComments(QWidget *parent, capture_file *cf, int file_type) {
|
2013-04-01 20:36:42 +00:00
|
|
|
guint32 comment_types;
|
wiretap: have file handlers advertise blocks and options supported.
Instead of a "supports name resolution" Boolean and bitflags for types of
comments supported, provide a list of block types that the file
type/subtype supports, with each block type having a list of options
supported. Indicate whether "supported" means "one instance" or
"multiple instances".
"Supports" doesn't just mean "can be written", it also means "could be
read".
Rename WTAP_BLOCK_IF_DESCRIPTION to WTAP_BLOCK_IF_ID_AND_INFO, to
indicate that it provides, in addition to information about the
interface, an ID (implicitly, in pcapng files, by its ordinal number)
that is associated with every packet in the file. Emphasize that in
comments - just because your capture file format can list the interfaces
on which a capture was done, that doesn't mean it supports this; it
doesn't do so if the file doesn't indicate, for every packet, on which
of those interfaces it was captured (I'm looking at *you*, Microsoft
Network Monitor...).
Use APIs to query that information to do what the "does this file
type/subtype support name resolution information", "does this file
type/subtype support all of these comment types", and "does this file
type/subtype support - and require - interface IDs" APIs did.
Provide backwards compatibility for Lua.
This allows us to eliminate the WTAP_FILE_TYPE_SUBTYPE_ values for IBM's
iptrace; do so.
2021-02-21 22:18:04 +00:00
|
|
|
bool all_comment_types_supported = true;
|
2012-09-26 19:52:53 +00:00
|
|
|
|
2013-04-01 20:36:42 +00:00
|
|
|
/* What types of comments do we have? */
|
|
|
|
comment_types = cf_comment_types(cf);
|
2012-09-26 19:52:53 +00:00
|
|
|
|
2013-04-01 20:36:42 +00:00
|
|
|
/* Does the file's format support all the comments we have? */
|
wiretap: have file handlers advertise blocks and options supported.
Instead of a "supports name resolution" Boolean and bitflags for types of
comments supported, provide a list of block types that the file
type/subtype supports, with each block type having a list of options
supported. Indicate whether "supported" means "one instance" or
"multiple instances".
"Supports" doesn't just mean "can be written", it also means "could be
read".
Rename WTAP_BLOCK_IF_DESCRIPTION to WTAP_BLOCK_IF_ID_AND_INFO, to
indicate that it provides, in addition to information about the
interface, an ID (implicitly, in pcapng files, by its ordinal number)
that is associated with every packet in the file. Emphasize that in
comments - just because your capture file format can list the interfaces
on which a capture was done, that doesn't mean it supports this; it
doesn't do so if the file doesn't indicate, for every packet, on which
of those interfaces it was captured (I'm looking at *you*, Microsoft
Network Monitor...).
Use APIs to query that information to do what the "does this file
type/subtype support name resolution information", "does this file
type/subtype support all of these comment types", and "does this file
type/subtype support - and require - interface IDs" APIs did.
Provide backwards compatibility for Lua.
This allows us to eliminate the WTAP_FILE_TYPE_SUBTYPE_ values for IBM's
iptrace; do so.
2021-02-21 22:18:04 +00:00
|
|
|
if (comment_types & WTAP_COMMENT_PER_SECTION) {
|
|
|
|
if (wtap_file_type_subtype_supports_option(file_type,
|
|
|
|
WTAP_BLOCK_SECTION,
|
|
|
|
OPT_COMMENT) == OPTION_NOT_SUPPORTED)
|
|
|
|
all_comment_types_supported = false;
|
|
|
|
}
|
|
|
|
if (comment_types & WTAP_COMMENT_PER_INTERFACE) {
|
|
|
|
if (wtap_file_type_subtype_supports_option(file_type,
|
|
|
|
WTAP_BLOCK_IF_ID_AND_INFO,
|
|
|
|
OPT_COMMENT) == OPTION_NOT_SUPPORTED)
|
|
|
|
all_comment_types_supported = false;
|
|
|
|
}
|
|
|
|
if (comment_types & WTAP_COMMENT_PER_PACKET) {
|
|
|
|
if (wtap_file_type_subtype_supports_option(file_type,
|
|
|
|
WTAP_BLOCK_PACKET,
|
|
|
|
OPT_COMMENT) == OPTION_NOT_SUPPORTED)
|
|
|
|
all_comment_types_supported = false;
|
|
|
|
}
|
|
|
|
if (all_comment_types_supported) {
|
2013-04-01 20:36:42 +00:00
|
|
|
/* Yes. Let the save happen; we can save all the comments, so
|
|
|
|
there's no need to delete them. */
|
2012-09-26 19:52:53 +00:00
|
|
|
return SAVE;
|
|
|
|
}
|
2013-04-01 20:36:42 +00:00
|
|
|
|
2021-01-12 00:11:52 +00:00
|
|
|
QMessageBox msg_dialog(parent);
|
2016-01-25 10:26:57 +00:00
|
|
|
QPushButton *save_button;
|
|
|
|
QPushButton *discard_button;
|
|
|
|
|
|
|
|
msg_dialog.setIcon(QMessageBox::Question);
|
|
|
|
msg_dialog.setText(tr("This capture file contains comments."));
|
|
|
|
msg_dialog.setStandardButtons(QMessageBox::Cancel);
|
|
|
|
|
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-09-26 19:52:53 +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-10-24 15:51:50 +00:00
|
|
|
msg_dialog.setInformativeText(tr("The file format you chose doesn't support comments. "
|
2016-01-25 10:26:57 +00:00
|
|
|
"Do you want to save the capture in a format that supports comments "
|
|
|
|
"or discard the comments and save in the format you chose?"));
|
2012-09-26 19:52:53 +00:00
|
|
|
// The predefined roles don't really match the tasks at hand...
|
2016-01-25 10:26:57 +00:00
|
|
|
discard_button = msg_dialog.addButton(tr("Discard comments and save"), QMessageBox::DestructiveRole);
|
|
|
|
save_button = msg_dialog.addButton(tr("Save in another format"), QMessageBox::AcceptRole);
|
|
|
|
msg_dialog.setDefaultButton(save_button);
|
2012-09-26 19:52:53 +00:00
|
|
|
} else {
|
|
|
|
/* No. Offer the user a choice of "Discard comments and
|
|
|
|
save in the format you selected" or "Cancel". */
|
2012-10-24 15:51:50 +00:00
|
|
|
msg_dialog.setInformativeText(tr("No file format in which it can be saved supports comments. "
|
2016-01-25 10:26:57 +00:00
|
|
|
"Do you want to discard the comments and save in the format you chose?"));
|
|
|
|
save_button = NULL;
|
|
|
|
discard_button = msg_dialog.addButton(tr("Discard comments and save"), QMessageBox::DestructiveRole);
|
2012-09-26 19:52:53 +00:00
|
|
|
msg_dialog.setDefaultButton(QMessageBox::Cancel);
|
|
|
|
}
|
|
|
|
|
2018-03-16 20:04:34 +00:00
|
|
|
#if defined(Q_OS_MAC)
|
2018-03-25 02:15:14 +00:00
|
|
|
/*
|
|
|
|
* In macOS, the "default button" is not necessarily the button that
|
|
|
|
* has the input focus; Enter/Return activates the default button, and
|
|
|
|
* the spacebar activates the button that has the input focus, and
|
|
|
|
* they might be different buttons.
|
|
|
|
*
|
|
|
|
* In a "do you want to save" dialog, for example, the "save" button
|
|
|
|
* is the default button, and the "don't save" button has the input
|
|
|
|
* focus, so you can press Enter/Return to save or space not to save
|
|
|
|
* (or Escape to dismiss the dialog).
|
|
|
|
*
|
|
|
|
* In Qt terms, this means "no auto-default", as auto-default makes the
|
|
|
|
* button with the input focus the default button, so that Enter/Return
|
|
|
|
* will activate it.
|
|
|
|
*/
|
|
|
|
QList<QAbstractButton *> buttons = msg_dialog.buttons();
|
|
|
|
for (int i = 0; i < buttons.size(); ++i) {
|
|
|
|
QPushButton *button = static_cast<QPushButton *>(buttons.at(i));;
|
|
|
|
button->setAutoDefault(false);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* It also means that the "don't save" button should be the one
|
|
|
|
* initially given the focus.
|
|
|
|
*/
|
2017-03-10 12:03:02 +00:00
|
|
|
discard_button->setFocus();
|
2018-03-16 20:04:34 +00:00
|
|
|
#endif
|
2017-03-10 12:03:02 +00:00
|
|
|
|
2016-01-25 10:26:57 +00:00
|
|
|
msg_dialog.exec();
|
|
|
|
/* According to the Qt doc:
|
|
|
|
* when using QMessageBox with custom buttons, exec() function returns an opaque value.
|
|
|
|
*
|
|
|
|
* Therefore we should use clickedButton() to determine which button was clicked. */
|
2012-09-26 19:52:53 +00:00
|
|
|
|
2016-01-25 10:26:57 +00:00
|
|
|
if (msg_dialog.clickedButton() == save_button) {
|
2018-01-09 00:38:10 +00:00
|
|
|
/* OK, the only other format we support is pcapng. Make that
|
2012-09-26 19:52:53 +00:00
|
|
|
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.
|
|
|
|
|
2018-01-09 00:38:10 +00:00
|
|
|
XXX - we know pcapng can be compressed; if we ever end up
|
2012-09-26 19:52:53 +00:00
|
|
|
supporting saving comments in a format that *can't* be
|
|
|
|
compressed, such as NetMon format, we must check this. */
|
|
|
|
/* XXX - need a compressed checkbox here! */
|
|
|
|
return SAVE_IN_ANOTHER_FORMAT;
|
|
|
|
|
2016-01-25 10:26:57 +00:00
|
|
|
} else if (msg_dialog.clickedButton() == discard_button) {
|
2012-09-26 19:52:53 +00:00
|
|
|
/* Save without the comments and, if that succeeds, delete the
|
|
|
|
comments. */
|
|
|
|
return SAVE_WITHOUT_COMMENTS;
|
|
|
|
}
|
2016-01-25 10:26:57 +00:00
|
|
|
|
|
|
|
/* Just give up. */
|
2012-09-26 19:52:53 +00:00
|
|
|
return CANCELLED;
|
2012-09-26 21:16:59 +00:00
|
|
|
}
|
2012-09-26 19:52:53 +00:00
|
|
|
|
2012-09-06 22:58:39 +00:00
|
|
|
|
2018-04-28 13:53:18 +00:00
|
|
|
#ifndef Q_OS_WIN
|
|
|
|
void CaptureFileDialog::accept()
|
|
|
|
{
|
2018-11-19 22:28:05 +00:00
|
|
|
//
|
|
|
|
// If this is a dialog for writing files, we want to ensure that
|
|
|
|
// the filename has a valid extension before performing file
|
2018-04-28 13:53:18 +00:00
|
|
|
// existence checks and before closing the dialog.
|
2018-11-19 22:28:05 +00:00
|
|
|
// This isn't necessary for dialogs for reading files; the name
|
|
|
|
// has to exactly match the name of the file you want to open,
|
|
|
|
// and doesn't need to be, and shouldn't be, modified.
|
|
|
|
//
|
|
|
|
// XXX also useful for Windows, but that uses a different dialog...
|
|
|
|
//
|
|
|
|
if (acceptMode() == QFileDialog::AcceptSave) {
|
|
|
|
// HACK: ensure that the filename field does not have the focus,
|
|
|
|
// otherwise selectFile will not change the filename.
|
|
|
|
setFocus();
|
|
|
|
fixFilenameExtension();
|
|
|
|
}
|
2019-11-24 23:32:06 +00:00
|
|
|
WiresharkFileDialog::accept();
|
2018-04-28 13:53:18 +00:00
|
|
|
}
|
|
|
|
#endif // ! Q_OS_WIN
|
|
|
|
|
|
|
|
|
2012-10-13 00:18:46 +00:00
|
|
|
// You have to use open, merge, saveAs, or exportPackets. We should
|
|
|
|
// probably just make each type a subclass.
|
|
|
|
int CaptureFileDialog::exec() {
|
|
|
|
return QDialog::Rejected;
|
|
|
|
}
|
2012-09-06 22:58:39 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
2012-10-13 00:18:46 +00:00
|
|
|
// Windows
|
2016-02-29 02:14:01 +00:00
|
|
|
// We use native file dialogs here, rather than the Qt dialog
|
2013-04-24 11:07:25 +00:00
|
|
|
#ifdef Q_OS_WIN
|
2012-10-13 00:18:46 +00:00
|
|
|
int CaptureFileDialog::selectedFileType() {
|
|
|
|
return file_type_;
|
|
|
|
}
|
2012-09-06 22:58:39 +00:00
|
|
|
|
2018-11-16 04:06:36 +00:00
|
|
|
wtap_compression_type CaptureFileDialog::compressionType() {
|
|
|
|
return compression_type_;
|
2012-10-13 00:18:46 +00:00
|
|
|
}
|
2012-09-06 22:58:39 +00:00
|
|
|
|
2014-01-18 14:20:02 +00:00
|
|
|
int CaptureFileDialog::open(QString &file_name, unsigned int &type) {
|
2019-12-09 23:18:06 +00:00
|
|
|
QString title_str = wsApp->windowTitleString(tr("Open Capture File"));
|
2012-10-13 00:18:46 +00:00
|
|
|
GString *fname = g_string_new(file_name.toUtf8().constData());
|
|
|
|
GString *dfilter = g_string_new(display_filter_.toUtf8().constData());
|
|
|
|
gboolean wof_status;
|
2012-09-06 22:58:39 +00:00
|
|
|
|
2013-08-29 22:15:40 +00:00
|
|
|
// XXX Add a widget->HWND routine to qt_ui_utils and use it instead.
|
2019-12-09 23:18:06 +00:00
|
|
|
wof_status = win32_open_file((HWND)parentWidget()->effectiveWinId(), title_str.toStdWString().c_str(), fname, &type, dfilter);
|
2012-10-13 00:18:46 +00:00
|
|
|
file_name = fname->str;
|
|
|
|
display_filter_ = dfilter->str;
|
2012-09-06 22:58:39 +00:00
|
|
|
|
2012-10-13 00:18:46 +00:00
|
|
|
g_string_free(fname, TRUE);
|
|
|
|
g_string_free(dfilter, TRUE);
|
2012-09-06 22:58:39 +00:00
|
|
|
|
2012-10-13 00:18:46 +00:00
|
|
|
return (int) wof_status;
|
2012-09-06 22:58:39 +00:00
|
|
|
}
|
|
|
|
|
2013-04-01 20:36:42 +00:00
|
|
|
check_savability_t CaptureFileDialog::saveAs(QString &file_name, bool must_support_all_comments) {
|
2019-12-09 23:18:06 +00:00
|
|
|
QString title_str = wsApp->windowTitleString(tr("Save Capture File As"));
|
2012-10-13 00:18:46 +00:00
|
|
|
GString *fname = g_string_new(file_name.toUtf8().constData());
|
|
|
|
gboolean wsf_status;
|
2012-09-06 23:41:34 +00:00
|
|
|
|
2019-12-09 23:18:06 +00:00
|
|
|
wsf_status = win32_save_as_file((HWND)parentWidget()->effectiveWinId(), title_str.toStdWString().c_str(), cap_file_, fname, &file_type_, &compression_type_, must_support_all_comments);
|
2012-10-13 00:18:46 +00:00
|
|
|
file_name = fname->str;
|
2012-09-06 23:41:34 +00:00
|
|
|
|
2012-10-13 00:18:46 +00:00
|
|
|
g_string_free(fname, TRUE);
|
2012-09-06 23:41:34 +00:00
|
|
|
|
2012-10-13 00:18:46 +00:00
|
|
|
if (wsf_status) {
|
2019-12-09 22:36:28 +00:00
|
|
|
return checkSaveAsWithComments(parentWidget(), cap_file_, file_type_);
|
2012-10-13 00:18:46 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return CANCELLED;
|
2012-09-06 23:41:34 +00:00
|
|
|
}
|
2012-09-06 22:58:39 +00:00
|
|
|
|
2019-11-12 15:39:19 +00:00
|
|
|
check_savability_t CaptureFileDialog::exportSelectedPackets(QString &file_name, packet_range_t *range, QString selRange) {
|
2019-12-09 23:18:06 +00:00
|
|
|
QString title_str = wsApp->windowTitleString(tr("Export Specified Packets"));
|
2012-10-13 00:18:46 +00:00
|
|
|
GString *fname = g_string_new(file_name.toUtf8().constData());
|
|
|
|
gboolean wespf_status;
|
|
|
|
|
2019-11-17 19:02:20 +00:00
|
|
|
if (selRange.length() > 0)
|
2019-11-12 15:39:19 +00:00
|
|
|
{
|
|
|
|
packet_range_convert_selection_str(range, selRange.toUtf8().constData());
|
|
|
|
}
|
|
|
|
|
2019-12-09 23:18:06 +00:00
|
|
|
wespf_status = win32_export_specified_packets_file((HWND)parentWidget()->effectiveWinId(), title_str.toStdWString().c_str(), cap_file_, fname, &file_type_, &compression_type_, range);
|
2012-10-13 00:18:46 +00:00
|
|
|
file_name = fname->str;
|
|
|
|
|
|
|
|
g_string_free(fname, TRUE);
|
|
|
|
|
|
|
|
if (wespf_status) {
|
2019-12-09 22:36:28 +00:00
|
|
|
return checkSaveAsWithComments(parentWidget(), cap_file_, file_type_);
|
2012-10-13 00:18:46 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return CANCELLED;
|
2012-09-06 22:58:39 +00:00
|
|
|
}
|
|
|
|
|
2012-10-13 00:18:46 +00:00
|
|
|
int CaptureFileDialog::merge(QString &file_name) {
|
2019-12-09 23:18:06 +00:00
|
|
|
QString title_str = wsApp->windowTitleString(tr("Merge Capture File"));
|
2012-10-13 00:18:46 +00:00
|
|
|
GString *fname = g_string_new(file_name.toUtf8().constData());
|
|
|
|
GString *dfilter = g_string_new(display_filter_.toUtf8().constData());
|
|
|
|
gboolean wmf_status;
|
|
|
|
|
2019-12-09 23:18:06 +00:00
|
|
|
|
|
|
|
wmf_status = win32_merge_file((HWND)parentWidget()->effectiveWinId(), title_str.toStdWString().c_str(), fname, dfilter, &merge_type_);
|
2012-10-13 00:18:46 +00:00
|
|
|
file_name = fname->str;
|
|
|
|
display_filter_ = dfilter->str;
|
|
|
|
|
|
|
|
g_string_free(fname, TRUE);
|
|
|
|
g_string_free(dfilter, TRUE);
|
|
|
|
|
|
|
|
return (int) wmf_status;
|
|
|
|
}
|
|
|
|
|
|
|
|
int CaptureFileDialog::mergeType() {
|
|
|
|
return merge_type_;
|
|
|
|
}
|
|
|
|
|
2018-04-28 11:15:36 +00:00
|
|
|
#else // ! Q_OS_WIN
|
2016-02-29 02:14:01 +00:00
|
|
|
// Not Windows
|
|
|
|
// We use the Qt dialogs here
|
2013-11-08 01:08:42 +00:00
|
|
|
QString CaptureFileDialog::fileExtensionType(int et, bool extension_globs)
|
|
|
|
{
|
2016-09-13 19:47:22 +00:00
|
|
|
QString extension_type_name;
|
|
|
|
QStringList all_wildcards;
|
2018-11-20 04:12:27 +00:00
|
|
|
QStringList no_compression_suffix_wildcards;
|
2013-11-08 01:08:42 +00:00
|
|
|
GSList *extensions_list;
|
|
|
|
GSList *extension;
|
|
|
|
|
2016-09-13 19:47:22 +00:00
|
|
|
extension_type_name = wtap_get_file_extension_type_name(et);
|
2013-11-08 01:08:42 +00:00
|
|
|
|
|
|
|
if (!extension_globs) {
|
2016-09-13 19:47:22 +00:00
|
|
|
return extension_type_name;
|
2013-11-08 01:08:42 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
extensions_list = wtap_get_file_extension_type_extensions(et);
|
|
|
|
|
2018-11-20 04:12:27 +00:00
|
|
|
// Get the list of compression-type extensions.
|
|
|
|
GSList *compression_type_extensions = wtap_get_all_compression_type_extensions_list();
|
|
|
|
|
2013-11-08 01:08:42 +00:00
|
|
|
/* Construct the list of patterns. */
|
|
|
|
for (extension = extensions_list; extension != NULL;
|
|
|
|
extension = g_slist_next(extension)) {
|
2016-09-13 19:47:22 +00:00
|
|
|
QString bare_wc = QString("*.%1").arg((char *)extension->data);
|
|
|
|
all_wildcards << bare_wc;
|
2018-11-20 04:12:27 +00:00
|
|
|
|
|
|
|
// Does this end with a compression suffix?
|
|
|
|
bool ends_with_compression_suffix = false;
|
|
|
|
for (GSList *compression_type_extension = compression_type_extensions;
|
|
|
|
compression_type_extension != NULL;
|
|
|
|
compression_type_extension = g_slist_next(compression_type_extension)) {
|
|
|
|
QString suffix = QString(".") + (char *)compression_type_extension->data;
|
|
|
|
if (bare_wc.endsWith(suffix)) {
|
|
|
|
ends_with_compression_suffix = true;
|
|
|
|
break;
|
|
|
|
}
|
2016-09-13 19:47:22 +00:00
|
|
|
}
|
2018-11-20 04:12:27 +00:00
|
|
|
|
|
|
|
// If it doesn't, add it to the list of wildcards-without-
|
|
|
|
// compression-suffixes.
|
|
|
|
if (!ends_with_compression_suffix)
|
|
|
|
no_compression_suffix_wildcards << bare_wc;
|
2013-11-08 01:08:42 +00:00
|
|
|
}
|
2018-11-20 04:12:27 +00:00
|
|
|
g_slist_free(compression_type_extensions);
|
2013-11-08 01:08:42 +00:00
|
|
|
wtap_free_extensions_list(extensions_list);
|
2016-09-13 19:47:22 +00:00
|
|
|
|
|
|
|
// We set HideNameFilterDetails so that "All Files" and "All Capture
|
|
|
|
// Files" don't show a wildcard list. We want to show the associated
|
|
|
|
// wildcards for individual file types so we add them twice.
|
|
|
|
return QString("%1 (%2) (%3)")
|
|
|
|
.arg(extension_type_name)
|
2018-11-20 04:12:27 +00:00
|
|
|
.arg(no_compression_suffix_wildcards.join(" "))
|
2016-09-13 19:47:22 +00:00
|
|
|
.arg(all_wildcards.join(" "));
|
2013-11-08 01:08:42 +00:00
|
|
|
}
|
|
|
|
|
2018-04-28 11:15:36 +00:00
|
|
|
// Returns " (...)", containing the suffix list suitable for setNameFilters.
|
|
|
|
// All extensions ("pcap", "pcap.gz", etc.) are also returned in "suffixes".
|
|
|
|
QString CaptureFileDialog::fileType(int ft, QStringList &suffixes)
|
2012-07-19 23:07:17 +00:00
|
|
|
{
|
|
|
|
QString filter;
|
2012-10-13 01:29:29 +00:00
|
|
|
GSList *extensions_list;
|
2012-07-19 23:07:17 +00:00
|
|
|
|
2018-04-28 11:15:36 +00:00
|
|
|
filter = " (";
|
2012-09-06 22:58:39 +00:00
|
|
|
|
2012-07-19 23:07:17 +00:00
|
|
|
extensions_list = wtap_get_file_extensions_list(ft, TRUE);
|
|
|
|
if (extensions_list == NULL) {
|
|
|
|
/* This file type doesn't have any particular extension
|
2016-02-29 21:29:19 +00:00
|
|
|
conventionally used for it, so we'll just use a
|
|
|
|
wildcard that matches all file names - even those
|
|
|
|
with no extension, so we don't need to worry about
|
|
|
|
compressed file extensions. */
|
|
|
|
filter += ALL_FILES_WILDCARD;
|
2012-07-19 23:07:17 +00:00
|
|
|
} else {
|
2018-04-28 11:15:36 +00:00
|
|
|
// HACK: at least for Qt 5.10 and before, if the first extension is
|
|
|
|
// empty ("."), it will prevent the default (broken) extension
|
|
|
|
// replacement from being applied in the non-native Save file dialog.
|
|
|
|
filter += '.';
|
|
|
|
|
2012-07-19 23:07:17 +00:00
|
|
|
/* Construct the list of patterns. */
|
2018-04-28 11:15:36 +00:00
|
|
|
for (GSList *extension = extensions_list; extension != NULL;
|
2012-07-19 23:07:17 +00:00
|
|
|
extension = g_slist_next(extension)) {
|
2018-04-28 11:15:36 +00:00
|
|
|
QString suffix((char *)extension->data);
|
|
|
|
filter += " *." + suffix;;
|
|
|
|
suffixes << suffix;
|
2012-07-19 23:07:17 +00:00
|
|
|
}
|
2013-11-08 01:08:42 +00:00
|
|
|
wtap_free_extensions_list(extensions_list);
|
2012-07-19 23:07:17 +00:00
|
|
|
}
|
|
|
|
filter += ')';
|
2012-09-06 22:58:39 +00:00
|
|
|
return filter;
|
2012-07-19 23:07:17 +00:00
|
|
|
}
|
|
|
|
|
2012-09-06 22:58:39 +00:00
|
|
|
QStringList CaptureFileDialog::buildFileOpenTypeList() {
|
|
|
|
QStringList filters;
|
2013-11-08 01:08:42 +00:00
|
|
|
QString filter, sep;
|
|
|
|
GSList *extensions_list;
|
|
|
|
GSList *extension;
|
|
|
|
int et;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Microsoft's UI guidelines say, of the file filters in open and
|
|
|
|
* save dialogs:
|
|
|
|
*
|
|
|
|
* For meta-filters, remove the file extension list to eliminate
|
|
|
|
* clutter. Examples: "All files," "All pictures," "All music,"
|
|
|
|
* and "All videos."
|
|
|
|
*
|
|
|
|
* On both Windows XP and Windows 7, Wordpad doesn't do that, but
|
|
|
|
* Paint does.
|
|
|
|
*
|
|
|
|
* XXX - on Windows, does Qt do that here? For "All Capture Files",
|
|
|
|
* the filter will be a bit long, so it *really* shouldn't be shown.
|
|
|
|
* What about other platforms?
|
|
|
|
*/
|
2016-02-29 21:29:19 +00:00
|
|
|
filters << QString(tr("All Files (" ALL_FILES_WILDCARD ")"));
|
2012-07-19 23:07:17 +00:00
|
|
|
|
2013-11-08 01:08:42 +00:00
|
|
|
/*
|
2016-09-10 06:44:25 +00:00
|
|
|
* Add an "All Capture Files" entry, with all the capture file
|
|
|
|
* extensions we know about.
|
2013-11-08 01:08:42 +00:00
|
|
|
*/
|
2015-10-05 15:03:30 +00:00
|
|
|
filter = tr("All Capture Files");
|
2013-11-08 01:08:42 +00:00
|
|
|
|
|
|
|
/*
|
2016-09-10 06:44:25 +00:00
|
|
|
* Construct its list of patterns.
|
2013-11-08 01:08:42 +00:00
|
|
|
*/
|
2016-09-10 06:44:25 +00:00
|
|
|
extensions_list = wtap_get_all_capture_file_extensions_list();
|
2013-11-08 01:08:42 +00:00
|
|
|
sep = " (";
|
|
|
|
for (extension = extensions_list; extension != NULL;
|
|
|
|
extension = g_slist_next(extension)) {
|
|
|
|
filter += sep;
|
|
|
|
filter += "*.";
|
|
|
|
filter += (char *)extension->data;
|
|
|
|
sep = " ";
|
|
|
|
}
|
2016-09-11 20:19:31 +00:00
|
|
|
wtap_free_extensions_list(extensions_list);
|
2013-11-08 01:08:42 +00:00
|
|
|
filter += ")";
|
|
|
|
filters << filter;
|
2012-07-19 23:07:17 +00:00
|
|
|
|
2013-11-08 01:08:42 +00:00
|
|
|
/* Include all the file types Wireshark supports. */
|
|
|
|
for (et = 0; et < wtap_get_num_file_type_extensions(); et++) {
|
|
|
|
filters << fileExtensionType(et);
|
2012-09-06 22:58:39 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return filters;
|
|
|
|
}
|
|
|
|
|
2018-11-19 22:30:37 +00:00
|
|
|
// Replaces or appends an extension based on the current file filter
|
|
|
|
// and compression setting.
|
2018-11-19 22:28:05 +00:00
|
|
|
// Used in dialogs that select a file to write.
|
2018-04-28 11:15:36 +00:00
|
|
|
void CaptureFileDialog::fixFilenameExtension()
|
|
|
|
{
|
|
|
|
QFileInfo fi(selectedFiles()[0]);
|
|
|
|
QString filename = fi.fileName();
|
|
|
|
if (fi.isDir() || filename.isEmpty()) {
|
|
|
|
// no file selected, or a directory was selected. Ignore.
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
QString old_suffix;
|
|
|
|
QString new_suffix(wtap_default_file_extension(selectedFileType()));
|
|
|
|
QStringList valid_extensions = type_suffixes_.value(selectedNameFilter());
|
|
|
|
// Find suffixes such as "pcap" or "pcap.gz" if any
|
|
|
|
if (!fi.suffix().isEmpty()) {
|
|
|
|
QStringList current_suffixes(fi.suffix());
|
|
|
|
int pos = filename.lastIndexOf('.', -2 - current_suffixes.at(0).size());
|
|
|
|
if (pos > 0) {
|
|
|
|
current_suffixes.prepend(filename.right(filename.size() - (pos + 1)));
|
|
|
|
}
|
|
|
|
|
|
|
|
// If the current suffix is valid for the current file type, try to
|
|
|
|
// preserve it. Otherwise use the default file extension (if available).
|
|
|
|
foreach (const QString ¤t_suffix, current_suffixes) {
|
|
|
|
if (valid_extensions.contains(current_suffix)) {
|
|
|
|
old_suffix = current_suffix;
|
|
|
|
new_suffix = current_suffix;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (old_suffix.isEmpty()) {
|
|
|
|
foreach (const QString ¤t_suffix, current_suffixes) {
|
|
|
|
foreach (const QStringList &suffixes, type_suffixes_.values()) {
|
|
|
|
if (suffixes.contains(current_suffix)) {
|
|
|
|
old_suffix = current_suffix;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (!old_suffix.isEmpty()) {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-11-20 04:12:27 +00:00
|
|
|
// Fixup the new suffix based on whether we're compressing or not.
|
|
|
|
if (compressionType() == WTAP_UNCOMPRESSED) {
|
|
|
|
// Not compressing; strip off any compression suffix
|
|
|
|
GSList *compression_type_extensions = wtap_get_all_compression_type_extensions_list();
|
|
|
|
for (GSList *compression_type_extension = compression_type_extensions;
|
|
|
|
compression_type_extension != NULL;
|
|
|
|
compression_type_extension = g_slist_next(compression_type_extension)) {
|
|
|
|
QString suffix = QString(".") + (char *)compression_type_extension->data;
|
|
|
|
if (new_suffix.endsWith(suffix)) {
|
|
|
|
//
|
|
|
|
// It ends with this compression suffix; chop it off.
|
|
|
|
//
|
|
|
|
new_suffix.chop(suffix.size());
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
g_slist_free(compression_type_extensions);
|
|
|
|
} else {
|
|
|
|
// Compressing; append the appropriate compression suffix.
|
|
|
|
QString compressed_file_extension = QString(".") + wtap_compression_type_extension(compressionType());
|
|
|
|
if (valid_extensions.contains(new_suffix + compressed_file_extension)) {
|
|
|
|
new_suffix += compressed_file_extension;
|
|
|
|
}
|
2018-04-28 11:15:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (!new_suffix.isEmpty() && old_suffix != new_suffix) {
|
|
|
|
filename.chop(old_suffix.size());
|
|
|
|
if (old_suffix.isEmpty()) {
|
|
|
|
filename += '.';
|
|
|
|
}
|
|
|
|
filename += new_suffix;
|
|
|
|
selectFile(filename);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-10-13 00:18:46 +00:00
|
|
|
void CaptureFileDialog::addPreview(QVBoxLayout &v_box) {
|
|
|
|
QGridLayout *preview_grid = new QGridLayout();
|
|
|
|
QLabel *lbl;
|
2012-09-06 23:41:34 +00:00
|
|
|
|
2012-10-13 00:18:46 +00:00
|
|
|
preview_labels_.clear();
|
|
|
|
v_box.addLayout(preview_grid);
|
2012-09-26 19:52:53 +00:00
|
|
|
|
2012-10-13 00:18:46 +00:00
|
|
|
preview_grid->setColumnStretch(0, 0);
|
|
|
|
preview_grid->setColumnStretch(1, 10);
|
2012-09-26 19:52:53 +00:00
|
|
|
|
2012-10-13 00:18:46 +00:00
|
|
|
lbl = new QLabel(tr("Format:"));
|
|
|
|
preview_grid->addWidget(lbl, 0, 0);
|
|
|
|
preview_grid->addWidget(&preview_format_, 0, 1);
|
|
|
|
preview_labels_ << lbl << &preview_format_;
|
2012-10-08 20:01:59 +00:00
|
|
|
|
2012-10-13 00:18:46 +00:00
|
|
|
lbl = new QLabel(tr("Size:"));
|
|
|
|
preview_grid->addWidget(lbl, 1, 0);
|
|
|
|
preview_grid->addWidget(&preview_size_, 1, 1);
|
|
|
|
preview_labels_ << lbl << &preview_size_;
|
2012-10-08 20:01:59 +00:00
|
|
|
|
2016-09-08 21:31:03 +00:00
|
|
|
lbl = new QLabel(tr("Start / elapsed:"));
|
2012-10-13 00:18:46 +00:00
|
|
|
preview_grid->addWidget(lbl, 3, 0);
|
2016-09-08 21:31:03 +00:00
|
|
|
preview_grid->addWidget(&preview_first_elapsed_, 3, 1);
|
|
|
|
preview_labels_ << lbl << &preview_first_elapsed_;
|
2012-10-08 20:01:59 +00:00
|
|
|
|
2021-10-10 23:05:57 +00:00
|
|
|
connect(this, &CaptureFileDialog::currentChanged, this, &CaptureFileDialog::preview);
|
2012-09-26 19:52:53 +00:00
|
|
|
|
2012-10-13 00:18:46 +00:00
|
|
|
preview("");
|
2012-09-26 19:52:53 +00:00
|
|
|
}
|
|
|
|
|
2012-10-13 00:18:46 +00:00
|
|
|
void CaptureFileDialog::addMergeControls(QVBoxLayout &v_box) {
|
2012-09-10 23:03:22 +00:00
|
|
|
|
2012-10-24 15:51:50 +00:00
|
|
|
merge_prepend_.setText(tr("Prepend packets"));
|
|
|
|
merge_prepend_.setToolTip(tr("Insert packets from the selected file before the current file. Packet timestamps will be ignored."));
|
2012-10-13 00:18:46 +00:00
|
|
|
v_box.addWidget(&merge_prepend_, 0, Qt::AlignTop);
|
2012-09-10 23:03:22 +00:00
|
|
|
|
2012-10-24 15:51:50 +00:00
|
|
|
merge_chrono_.setText(tr("Merge chronologically"));
|
|
|
|
merge_chrono_.setToolTip(tr("Insert packets in chronological order."));
|
2012-10-13 00:18:46 +00:00
|
|
|
merge_chrono_.setChecked(true);
|
|
|
|
v_box.addWidget(&merge_chrono_, 0, Qt::AlignTop);
|
2012-09-10 23:03:22 +00:00
|
|
|
|
2012-10-24 15:51:50 +00:00
|
|
|
merge_append_.setText(tr("Append packets"));
|
|
|
|
merge_append_.setToolTip(tr("Insert packets from the selected file after the current file. Packet timestamps will be ignored."));
|
2012-10-13 00:18:46 +00:00
|
|
|
v_box.addWidget(&merge_append_, 0, Qt::AlignTop);
|
2012-09-10 23:03:22 +00:00
|
|
|
}
|
|
|
|
|
2012-09-06 23:41:34 +00:00
|
|
|
int CaptureFileDialog::selectedFileType() {
|
2021-02-27 22:25:55 +00:00
|
|
|
return type_hash_.value(selectedNameFilter(), WTAP_FILE_TYPE_SUBTYPE_UNKNOWN);
|
2012-09-06 23:41:34 +00:00
|
|
|
}
|
|
|
|
|
2018-11-16 04:06:36 +00:00
|
|
|
wtap_compression_type CaptureFileDialog::compressionType() {
|
|
|
|
return compress_.isChecked() ? WTAP_GZIP_COMPRESSED : WTAP_UNCOMPRESSED;
|
2012-09-26 19:52:53 +00:00
|
|
|
}
|
|
|
|
|
2012-09-06 23:41:34 +00:00
|
|
|
void CaptureFileDialog::addDisplayFilterEdit() {
|
2012-09-26 19:52:53 +00:00
|
|
|
QGridLayout *fd_grid = qobject_cast<QGridLayout*>(layout());
|
|
|
|
|
2015-11-16 19:00:32 +00:00
|
|
|
fd_grid->addWidget(new QLabel(tr("Read filter:")), last_row_, 0);
|
2012-09-26 19:52:53 +00:00
|
|
|
|
2015-11-16 19:00:32 +00:00
|
|
|
display_filter_edit_ = new DisplayFilterEdit(this, ReadFilterToApply);
|
2012-09-26 19:52:53 +00:00
|
|
|
display_filter_edit_->setText(display_filter_);
|
2012-10-08 20:01:59 +00:00
|
|
|
fd_grid->addWidget(display_filter_edit_, last_row_, 1);
|
|
|
|
last_row_++;
|
2012-09-06 23:41:34 +00:00
|
|
|
}
|
|
|
|
|
2014-01-18 14:20:02 +00:00
|
|
|
void CaptureFileDialog::addFormatTypeSelector(QVBoxLayout &v_box) {
|
2020-07-06 20:41:07 +00:00
|
|
|
int i;
|
|
|
|
/* Put Auto, as well as pcap and pcapng (which are the first two entries in
|
|
|
|
open_routines), at the top of the file type list. */
|
2016-09-08 21:31:03 +00:00
|
|
|
format_type_.addItem(tr("Automatically detect file type"));
|
2020-07-06 20:41:07 +00:00
|
|
|
for (i = 0; i < 2; i += 1) {
|
2014-01-18 14:20:02 +00:00
|
|
|
format_type_.addItem(open_routines[i].name);
|
|
|
|
}
|
2020-07-06 20:41:07 +00:00
|
|
|
/* Generate a sorted list of the remaining file types. */
|
|
|
|
QStringList routine_names;
|
|
|
|
for ( /* keep using i */ ; open_routines[i].name != NULL; i += 1) {
|
|
|
|
routine_names += QString(open_routines[i].name);
|
|
|
|
}
|
|
|
|
routine_names.sort(Qt::CaseInsensitive);
|
|
|
|
for (i = 0; i < routine_names.size(); i += 1) {
|
|
|
|
format_type_.addItem(routine_names.at(i));
|
|
|
|
}
|
2014-01-18 14:20:02 +00:00
|
|
|
|
|
|
|
v_box.addWidget(&format_type_, 0, Qt::AlignTop);
|
|
|
|
}
|
|
|
|
|
2012-10-08 20:01:59 +00:00
|
|
|
void CaptureFileDialog::addGzipControls(QVBoxLayout &v_box) {
|
2012-09-26 19:52:53 +00:00
|
|
|
compress_.setText(tr("Compress with g&zip"));
|
2018-11-16 04:06:36 +00:00
|
|
|
if (cap_file_->compression_type == WTAP_GZIP_COMPRESSED &&
|
|
|
|
wtap_dump_can_compress(default_ft_)) {
|
2012-09-26 19:52:53 +00:00
|
|
|
compress_.setChecked(true);
|
|
|
|
} else {
|
|
|
|
compress_.setChecked(false);
|
|
|
|
}
|
2012-10-12 23:40:29 +00:00
|
|
|
v_box.addWidget(&compress_, 0, Qt::AlignTop);
|
2018-04-28 11:15:36 +00:00
|
|
|
connect(&compress_, &QCheckBox::stateChanged, this, &CaptureFileDialog::fixFilenameExtension);
|
2012-09-26 19:52:53 +00:00
|
|
|
|
|
|
|
}
|
|
|
|
|
2019-11-12 15:39:19 +00:00
|
|
|
void CaptureFileDialog::addRangeControls(QVBoxLayout &v_box, packet_range_t *range, QString selRange) {
|
|
|
|
packet_range_group_box_.initRange(range, selRange);
|
2012-10-12 23:40:29 +00:00
|
|
|
v_box.addWidget(&packet_range_group_box_, 0, Qt::AlignTop);
|
2012-10-08 20:01:59 +00:00
|
|
|
}
|
|
|
|
|
2012-10-15 18:32:51 +00:00
|
|
|
QDialogButtonBox *CaptureFileDialog::addHelpButton(topic_action_e help_topic)
|
|
|
|
{
|
|
|
|
// This doesn't appear to be documented anywhere but it seems pretty obvious
|
|
|
|
// and it works.
|
|
|
|
QDialogButtonBox *button_box = findChild<QDialogButtonBox *>();
|
|
|
|
|
|
|
|
help_topic_ = help_topic;
|
|
|
|
|
|
|
|
if (button_box) {
|
|
|
|
button_box->addButton(QDialogButtonBox::Help);
|
2021-10-10 23:05:57 +00:00
|
|
|
connect(button_box, &QDialogButtonBox::helpRequested, this, &CaptureFileDialog::on_buttonBox_helpRequested);
|
2012-10-15 18:32:51 +00:00
|
|
|
}
|
|
|
|
return button_box;
|
|
|
|
}
|
|
|
|
|
2014-01-18 14:20:02 +00:00
|
|
|
int CaptureFileDialog::open(QString &file_name, unsigned int &type) {
|
2014-12-29 23:15:59 +00:00
|
|
|
setWindowTitle(wsApp->windowTitleString(tr("Open Capture File")));
|
2012-09-06 23:41:34 +00:00
|
|
|
setNameFilters(buildFileOpenTypeList());
|
|
|
|
setFileMode(QFileDialog::ExistingFile);
|
|
|
|
|
2014-01-18 14:20:02 +00:00
|
|
|
addFormatTypeSelector(left_v_box_);
|
2012-09-26 19:52:53 +00:00
|
|
|
addDisplayFilterEdit();
|
2012-09-06 23:41:34 +00:00
|
|
|
addPreview(right_v_box_);
|
2012-10-15 18:32:51 +00:00
|
|
|
addHelpButton(HELP_OPEN_DIALOG);
|
2012-09-06 23:41:34 +00:00
|
|
|
|
|
|
|
// Grow the dialog to account for the extra widgets.
|
|
|
|
resize(width(), height() + left_v_box_.minimumSize().height() + display_filter_edit_->minimumSize().height());
|
|
|
|
|
2012-09-26 19:52:53 +00:00
|
|
|
display_filter_.clear();
|
|
|
|
|
2012-09-06 23:41:34 +00:00
|
|
|
if (!file_name.isEmpty()) {
|
|
|
|
selectFile(file_name);
|
|
|
|
}
|
|
|
|
|
2019-11-24 23:32:06 +00:00
|
|
|
if (WiresharkFileDialog::exec() && selectedFiles().length() > 0) {
|
2012-09-26 19:52:53 +00:00
|
|
|
file_name = selectedFiles()[0];
|
2020-07-06 20:41:07 +00:00
|
|
|
type = open_info_name_to_type(qPrintable(format_type_.currentText()));
|
2012-09-06 23:41:34 +00:00
|
|
|
display_filter_.append(display_filter_edit_->text());
|
|
|
|
|
|
|
|
return QDialog::Accepted;
|
|
|
|
} else {
|
|
|
|
return QDialog::Rejected;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-04-01 20:36:42 +00:00
|
|
|
check_savability_t CaptureFileDialog::saveAs(QString &file_name, bool must_support_all_comments) {
|
2014-12-29 23:15:59 +00:00
|
|
|
setWindowTitle(wsApp->windowTitleString(tr("Save Capture File As")));
|
2012-09-26 19:52:53 +00:00
|
|
|
// XXX There doesn't appear to be a way to use setNameFilters without restricting
|
|
|
|
// what the user can select. We might want to use our own combobox instead and
|
|
|
|
// let the user select anything.
|
2013-04-01 20:36:42 +00:00
|
|
|
setNameFilters(buildFileSaveAsTypeList(must_support_all_comments));
|
2012-09-26 19:52:53 +00:00
|
|
|
setAcceptMode(QFileDialog::AcceptSave);
|
2012-10-24 15:51:50 +00:00
|
|
|
setLabelText(FileType, tr("Save as:"));
|
2012-09-26 19:52:53 +00:00
|
|
|
|
2012-10-08 20:01:59 +00:00
|
|
|
addGzipControls(left_v_box_);
|
2012-10-15 18:32:51 +00:00
|
|
|
addHelpButton(HELP_SAVE_DIALOG);
|
2012-09-26 19:52:53 +00:00
|
|
|
|
|
|
|
// Grow the dialog to account for the extra widgets.
|
|
|
|
resize(width(), height() + left_v_box_.minimumSize().height());
|
|
|
|
|
|
|
|
if (!file_name.isEmpty()) {
|
|
|
|
selectFile(file_name);
|
|
|
|
}
|
2018-04-28 11:15:36 +00:00
|
|
|
connect(this, &QFileDialog::filterSelected, this, &CaptureFileDialog::fixFilenameExtension);
|
2012-09-26 19:52:53 +00:00
|
|
|
|
2019-11-24 23:32:06 +00:00
|
|
|
if (WiresharkFileDialog::exec() && selectedFiles().length() > 0) {
|
2021-02-27 22:25:55 +00:00
|
|
|
int file_type;
|
|
|
|
|
2012-09-26 19:52:53 +00:00
|
|
|
file_name = selectedFiles()[0];
|
2021-02-27 22:25:55 +00:00
|
|
|
file_type = selectedFileType();
|
|
|
|
/* Is the file type bogus? */
|
|
|
|
if (file_type == WTAP_FILE_TYPE_SUBTYPE_UNKNOWN) {
|
|
|
|
/* This "should not happen". */
|
|
|
|
QMessageBox msg_dialog;
|
|
|
|
|
|
|
|
msg_dialog.setIcon(QMessageBox::Critical);
|
|
|
|
msg_dialog.setText(tr("Unknown file type returned by save as dialog."));
|
|
|
|
msg_dialog.setInformativeText(tr("Please report this as a Wireshark issue at https://gitlab.com/wireshark/wireshark/-/issues."));
|
|
|
|
msg_dialog.exec();
|
|
|
|
return CANCELLED;
|
|
|
|
}
|
|
|
|
return checkSaveAsWithComments(this, cap_file_, file_type);
|
2012-10-08 20:01:59 +00:00
|
|
|
}
|
|
|
|
return CANCELLED;
|
|
|
|
}
|
|
|
|
|
2019-11-12 15:39:19 +00:00
|
|
|
check_savability_t CaptureFileDialog::exportSelectedPackets(QString &file_name, packet_range_t *range, QString selRange) {
|
2012-10-15 18:32:51 +00:00
|
|
|
QDialogButtonBox *button_box;
|
2012-10-08 20:01:59 +00:00
|
|
|
|
2014-12-29 23:15:59 +00:00
|
|
|
setWindowTitle(wsApp->windowTitleString(tr("Export Specified Packets")));
|
2012-10-08 20:01:59 +00:00
|
|
|
// XXX See comment in ::saveAs regarding setNameFilters
|
|
|
|
setNameFilters(buildFileSaveAsTypeList(false));
|
|
|
|
setAcceptMode(QFileDialog::AcceptSave);
|
2012-10-11 21:45:05 +00:00
|
|
|
setLabelText(FileType, tr("Export as:"));
|
2012-10-08 20:01:59 +00:00
|
|
|
|
2019-11-12 15:39:19 +00:00
|
|
|
addRangeControls(left_v_box_, range, selRange);
|
2012-10-12 23:40:29 +00:00
|
|
|
addGzipControls(right_v_box_);
|
2012-10-15 18:32:51 +00:00
|
|
|
button_box = addHelpButton(HELP_EXPORT_FILE_DIALOG);
|
2012-10-08 20:01:59 +00:00
|
|
|
|
|
|
|
if (button_box) {
|
|
|
|
save_bt_ = button_box->button(QDialogButtonBox::Save);
|
2012-10-12 23:40:29 +00:00
|
|
|
if (save_bt_) {
|
2021-10-10 23:05:57 +00:00
|
|
|
connect(&packet_range_group_box_, &PacketRangeGroupBox::validityChanged,
|
|
|
|
save_bt_, &QPushButton::setEnabled);
|
2012-10-12 23:40:29 +00:00
|
|
|
}
|
2012-10-08 20:01:59 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Grow the dialog to account for the extra widgets.
|
2012-10-12 23:40:29 +00:00
|
|
|
resize(width(), height() + (packet_range_group_box_.height() * 2 / 3));
|
2012-10-08 20:01:59 +00:00
|
|
|
|
|
|
|
if (!file_name.isEmpty()) {
|
|
|
|
selectFile(file_name);
|
|
|
|
}
|
2018-04-28 11:15:36 +00:00
|
|
|
connect(this, &QFileDialog::filterSelected, this, &CaptureFileDialog::fixFilenameExtension);
|
2012-10-08 20:01:59 +00:00
|
|
|
|
2019-11-24 23:32:06 +00:00
|
|
|
if (WiresharkFileDialog::exec() && selectedFiles().length() > 0) {
|
2021-02-27 22:25:55 +00:00
|
|
|
int file_type;
|
|
|
|
|
2012-10-08 20:01:59 +00:00
|
|
|
file_name = selectedFiles()[0];
|
2021-02-27 22:25:55 +00:00
|
|
|
file_type = selectedFileType();
|
|
|
|
/* Is the file type bogus? */
|
|
|
|
if (file_type == WTAP_FILE_TYPE_SUBTYPE_UNKNOWN) {
|
|
|
|
/* This "should not happen". */
|
|
|
|
QMessageBox msg_dialog;
|
|
|
|
|
|
|
|
msg_dialog.setIcon(QMessageBox::Critical);
|
|
|
|
msg_dialog.setText(tr("Unknown file type returned by save as dialog."));
|
|
|
|
msg_dialog.setInformativeText(tr("Please report this as a Wireshark issue at https://gitlab.com/wireshark/wireshark/-/issues."));
|
|
|
|
msg_dialog.exec();
|
|
|
|
return CANCELLED;
|
|
|
|
}
|
|
|
|
return checkSaveAsWithComments(this, cap_file_, file_type);
|
2012-09-26 19:52:53 +00:00
|
|
|
}
|
|
|
|
return CANCELLED;
|
|
|
|
}
|
|
|
|
|
2012-09-10 23:03:22 +00:00
|
|
|
int CaptureFileDialog::merge(QString &file_name) {
|
2014-12-29 23:15:59 +00:00
|
|
|
setWindowTitle(wsApp->windowTitleString(tr("Merge Capture File")));
|
2012-09-10 23:03:22 +00:00
|
|
|
setNameFilters(buildFileOpenTypeList());
|
|
|
|
setFileMode(QFileDialog::ExistingFile);
|
|
|
|
|
2012-09-26 19:52:53 +00:00
|
|
|
addDisplayFilterEdit();
|
2012-09-10 23:03:22 +00:00
|
|
|
addMergeControls(left_v_box_);
|
|
|
|
addPreview(right_v_box_);
|
2012-10-15 18:32:51 +00:00
|
|
|
addHelpButton(HELP_MERGE_DIALOG);
|
2012-09-10 23:03:22 +00:00
|
|
|
|
2012-09-26 19:52:53 +00:00
|
|
|
file_name.clear();
|
|
|
|
display_filter_.clear();
|
|
|
|
|
2012-09-10 23:03:22 +00:00
|
|
|
// Grow the dialog to account for the extra widgets.
|
|
|
|
resize(width(), height() + right_v_box_.minimumSize().height() + display_filter_edit_->minimumSize().height());
|
|
|
|
|
2019-11-24 23:32:06 +00:00
|
|
|
if (WiresharkFileDialog::exec() && selectedFiles().length() > 0) {
|
2012-09-10 23:03:22 +00:00
|
|
|
file_name.append(selectedFiles()[0]);
|
|
|
|
display_filter_.append(display_filter_edit_->text());
|
|
|
|
|
|
|
|
return QDialog::Accepted;
|
|
|
|
} else {
|
|
|
|
return QDialog::Rejected;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-04-01 20:36:42 +00:00
|
|
|
QStringList CaptureFileDialog::buildFileSaveAsTypeList(bool must_support_all_comments) {
|
2012-09-06 22:58:39 +00:00
|
|
|
QStringList filters;
|
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;
|
2012-09-06 22:58:39 +00:00
|
|
|
guint i;
|
|
|
|
|
|
|
|
type_hash_.clear();
|
2018-04-28 11:15:36 +00:00
|
|
|
type_suffixes_.clear();
|
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(cap_file_); /* all the ones the file has */
|
|
|
|
else
|
|
|
|
required_comment_types = 0; /* none of them */
|
|
|
|
|
|
|
|
/* What types of file can we save this file as? */
|
wiretap: more work on file type/subtypes.
Provide a wiretap routine to get an array of all savable file
type/subtypes, sorted with pcap and pcapng at the top, followed by the
other types, sorted either by the name or the description.
Use that routine to list options for the -F flag for various commands
Rename wtap_get_savable_file_types_subtypes() to
wtap_get_savable_file_types_subtypes_for_file(), to indicate that it
provides an array of all file type/subtypes in which a given file can be
saved. Have it sort all types, other than the default type/subtype and,
if there is one, the "other" type (both of which are put at the top), by
the name or the description.
Don't allow wtap_register_file_type_subtypes() to override any existing
registrations; have them always register a new type. In that routine,
if there are any emply slots in the table, due to an entry being
unregistered, use it rather than allocating a new slot.
Don't allow unregistration of built-in types.
Rename the "dump open table" to the "file type/subtype table", as it has
entries for all types/subtypes, even if we can't write them.
Initialize that table in a routine that pre-allocates the GArray before
filling it with built-in types/subtypes, so it doesn't keep getting
reallocated.
Get rid of wtap_num_file_types_subtypes - it's just a copy of the size
of the GArray.
Don't have wtap_file_type_subtype_description() crash if handed an
file type/subtype that isn't a valid array index - just return NULL, as
we do with wtap_file_type_subtype_name().
In wtap_name_to_file_type_subtype(), don't use WTAP_FILE_TYPE_SUBTYPE_
names for the backwards-compatibility names - map those names to the
current names, and then look them up. This reduces the number of
uses of hardwired WTAP_FILE_TYPE_SUBTYPE_ values.
Clean up the type of wtap_module_count - it has no need to be a gulong.
Have built-in wiretap file handlers register names to be used for their
file type/subtypes, rather than building the table in init.lua.
Add a new Lua C function get_wtap_filetypes() to construct the
wtap_filetypes table, based on the registered names, and use it in
init.lua.
Add a #define WSLUA_INTERNAL_FUNCTION to register functions intended
only for internal use in init.lua, so they can be made available from
Lua without being documented.
Get rid of WTAP_NUM_FILE_TYPES_SUBTYPES - most code has no need to use
it, as it can just request arrays of types, and the space of
type/subtype codes can be sparse due to registration in any case, so
code has to be careful using it.
wtap_get_num_file_types_subtypes() is no longer used, so remove it. It
returns the number of elements in the file type/subtype array, which is
not necessarily the name of known file type/subtypes, as there may have
been some deregistered types, and those types do *not* get removed from
the array, they just get cleared so that they're available for future
allocation (we don't want the indices of any registered types to changes
if another type is deregistered, as those indicates are the type/subtype
values, so we can't shrink the array).
Clean up white space and remove some comments that shouldn't have been
added.
2021-02-17 06:24:47 +00:00
|
|
|
savable_file_types_subtypes = wtap_get_savable_file_types_subtypes_for_file(cap_file_->cd_t,
|
2013-11-08 09:53:01 +00:00
|
|
|
cap_file_->linktypes,
|
wiretap: more work on file type/subtypes.
Provide a wiretap routine to get an array of all savable file
type/subtypes, sorted with pcap and pcapng at the top, followed by the
other types, sorted either by the name or the description.
Use that routine to list options for the -F flag for various commands
Rename wtap_get_savable_file_types_subtypes() to
wtap_get_savable_file_types_subtypes_for_file(), to indicate that it
provides an array of all file type/subtypes in which a given file can be
saved. Have it sort all types, other than the default type/subtype and,
if there is one, the "other" type (both of which are put at the top), by
the name or the description.
Don't allow wtap_register_file_type_subtypes() to override any existing
registrations; have them always register a new type. In that routine,
if there are any emply slots in the table, due to an entry being
unregistered, use it rather than allocating a new slot.
Don't allow unregistration of built-in types.
Rename the "dump open table" to the "file type/subtype table", as it has
entries for all types/subtypes, even if we can't write them.
Initialize that table in a routine that pre-allocates the GArray before
filling it with built-in types/subtypes, so it doesn't keep getting
reallocated.
Get rid of wtap_num_file_types_subtypes - it's just a copy of the size
of the GArray.
Don't have wtap_file_type_subtype_description() crash if handed an
file type/subtype that isn't a valid array index - just return NULL, as
we do with wtap_file_type_subtype_name().
In wtap_name_to_file_type_subtype(), don't use WTAP_FILE_TYPE_SUBTYPE_
names for the backwards-compatibility names - map those names to the
current names, and then look them up. This reduces the number of
uses of hardwired WTAP_FILE_TYPE_SUBTYPE_ values.
Clean up the type of wtap_module_count - it has no need to be a gulong.
Have built-in wiretap file handlers register names to be used for their
file type/subtypes, rather than building the table in init.lua.
Add a new Lua C function get_wtap_filetypes() to construct the
wtap_filetypes table, based on the registered names, and use it in
init.lua.
Add a #define WSLUA_INTERNAL_FUNCTION to register functions intended
only for internal use in init.lua, so they can be made available from
Lua without being documented.
Get rid of WTAP_NUM_FILE_TYPES_SUBTYPES - most code has no need to use
it, as it can just request arrays of types, and the space of
type/subtype codes can be sparse due to registration in any case, so
code has to be careful using it.
wtap_get_num_file_types_subtypes() is no longer used, so remove it. It
returns the number of elements in the file type/subtype array, which is
not necessarily the name of known file type/subtypes, as there may have
been some deregistered types, and those types do *not* get removed from
the array, they just get cleared so that they're available for future
allocation (we don't want the indices of any registered types to changes
if another type is deregistered, as those indicates are the type/subtype
values, so we can't shrink the array).
Clean up white space and remove some comments that shouldn't have been
added.
2021-02-17 06:24:47 +00:00
|
|
|
required_comment_types,
|
|
|
|
FT_SORT_BY_DESCRIPTION);
|
2012-09-06 22:58:39 +00:00
|
|
|
|
2013-11-08 09:53:01 +00:00
|
|
|
if (savable_file_types_subtypes != NULL) {
|
2012-10-13 01:29:29 +00:00
|
|
|
int ft;
|
2012-09-06 22:58:39 +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-09-26 19:52:53 +00:00
|
|
|
if (default_ft_ < 1)
|
|
|
|
default_ft_ = ft; /* first file type is the default */
|
2021-02-13 08:03:51 +00:00
|
|
|
QString type_name(wtap_file_type_subtype_description(ft));
|
2018-04-28 11:15:36 +00:00
|
|
|
filters << type_name + fileType(ft, type_suffixes_[type_name]);
|
|
|
|
type_hash_[type_name] = ft;
|
2012-09-06 22:58:39 +00:00
|
|
|
}
|
2013-11-08 09:53:01 +00:00
|
|
|
g_array_free(savable_file_types_subtypes, TRUE);
|
2012-07-19 23:07:17 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return filters;
|
|
|
|
}
|
2012-07-27 21:43:02 +00:00
|
|
|
|
2012-09-07 00:29:32 +00:00
|
|
|
int CaptureFileDialog::mergeType() {
|
|
|
|
if (merge_prepend_.isChecked())
|
|
|
|
return -1;
|
|
|
|
else if (merge_append_.isChecked())
|
|
|
|
return 1;
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
2012-10-08 20:01:59 +00:00
|
|
|
|
2012-10-09 15:34:40 +00:00
|
|
|
// Slots
|
|
|
|
|
2012-10-08 20:01:59 +00:00
|
|
|
|
2012-09-07 00:29:32 +00:00
|
|
|
|
2012-07-27 21:43:02 +00:00
|
|
|
/* do a preview run on the currently selected capture file */
|
|
|
|
void CaptureFileDialog::preview(const QString & path)
|
|
|
|
{
|
|
|
|
wtap *wth;
|
2018-02-09 19:18:22 +00:00
|
|
|
int err;
|
2012-07-27 21:43:02 +00:00
|
|
|
gchar *err_info;
|
2018-02-10 02:45:14 +00:00
|
|
|
ws_file_preview_stats stats;
|
|
|
|
ws_file_preview_stats_status status;
|
2012-07-27 21:43:02 +00:00
|
|
|
time_t ti_time;
|
|
|
|
struct tm *ti_tm;
|
|
|
|
unsigned int elapsed_time;
|
|
|
|
|
2012-09-06 22:58:39 +00:00
|
|
|
foreach (QLabel *lbl, preview_labels_) {
|
2012-07-27 21:43:02 +00:00
|
|
|
lbl->setEnabled(false);
|
|
|
|
}
|
|
|
|
|
2016-09-08 21:31:03 +00:00
|
|
|
preview_format_.setText(tr(UTF8_EM_DASH));
|
|
|
|
preview_size_.setText(tr(UTF8_EM_DASH));
|
|
|
|
preview_first_elapsed_.setText(tr(UTF8_EM_DASH));
|
2012-07-27 21:43:02 +00:00
|
|
|
|
|
|
|
if (path.length() < 1) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (test_for_directory(path.toUtf8().data()) == EISDIR) {
|
2012-09-06 22:58:39 +00:00
|
|
|
preview_format_.setText(tr("directory"));
|
2012-07-27 21:43:02 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2014-01-18 14:20:02 +00:00
|
|
|
wth = wtap_open_offline(path.toUtf8().data(), WTAP_TYPE_AUTO, &err, &err_info, TRUE);
|
2012-07-27 21:43:02 +00:00
|
|
|
if (wth == NULL) {
|
2019-11-17 19:02:20 +00:00
|
|
|
if (err == WTAP_ERR_FILE_UNKNOWN_FORMAT) {
|
2012-09-06 22:58:39 +00:00
|
|
|
preview_format_.setText(tr("unknown file format"));
|
2012-07-27 21:43:02 +00:00
|
|
|
} else {
|
2012-09-06 22:58:39 +00:00
|
|
|
preview_format_.setText(tr("error opening file"));
|
2012-07-27 21:43:02 +00:00
|
|
|
}
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Success!
|
2012-09-06 22:58:39 +00:00
|
|
|
foreach (QLabel *lbl, preview_labels_) {
|
2012-07-27 21:43:02 +00:00
|
|
|
lbl->setEnabled(true);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Format
|
2021-02-13 08:03:51 +00:00
|
|
|
preview_format_.setText(QString::fromUtf8(wtap_file_type_subtype_description(wtap_file_type_subtype(wth))));
|
2012-07-27 21:43:02 +00:00
|
|
|
|
|
|
|
// Size
|
2016-09-08 21:31:03 +00:00
|
|
|
gint64 filesize = wtap_file_size(wth, &err);
|
|
|
|
// Finder and Windows Explorer use IEC. What do the various Linux file managers use?
|
2016-09-11 20:19:31 +00:00
|
|
|
QString size_str(gchar_free_to_qstring(format_size(filesize, format_size_unit_bytes|format_size_prefix_iec)));
|
2012-07-27 21:43:02 +00:00
|
|
|
|
2018-02-10 02:45:14 +00:00
|
|
|
status = get_stats_for_preview(wth, &stats, &err, &err_info);
|
2012-07-27 21:43:02 +00:00
|
|
|
|
2019-11-17 19:02:20 +00:00
|
|
|
if (status == PREVIEW_READ_ERROR) {
|
2018-02-09 19:18:22 +00:00
|
|
|
// XXX - give error details?
|
2018-02-09 20:35:33 +00:00
|
|
|
g_free(err_info);
|
2018-05-09 07:08:02 +00:00
|
|
|
preview_size_.setText(tr("%1, error after %Ln data record(s)", "", stats.records)
|
2017-04-05 07:13:38 +00:00
|
|
|
.arg(size_str));
|
2012-07-27 21:43:02 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Packet count
|
2019-11-17 19:02:20 +00:00
|
|
|
if (status == PREVIEW_TIMED_OUT) {
|
2018-02-10 02:45:14 +00:00
|
|
|
preview_size_.setText(tr("%1, timed out at %Ln data record(s)", "", stats.data_records)
|
2017-04-05 07:13:38 +00:00
|
|
|
.arg(size_str));
|
2012-07-27 21:43:02 +00:00
|
|
|
} else {
|
2018-02-10 02:45:14 +00:00
|
|
|
preview_size_.setText(tr("%1, %Ln data record(s)", "", stats.data_records)
|
2017-04-05 07:13:38 +00:00
|
|
|
.arg(size_str));
|
2012-07-27 21:43:02 +00:00
|
|
|
}
|
|
|
|
|
2016-09-08 21:31:03 +00:00
|
|
|
// First packet + elapsed time
|
2018-02-06 04:24:33 +00:00
|
|
|
QString first_elapsed;
|
2019-11-17 19:02:20 +00:00
|
|
|
if (stats.have_times) {
|
2018-02-10 02:45:14 +00:00
|
|
|
//
|
|
|
|
// We saw at least one record with a time stamp, so we can give
|
|
|
|
// a start time (if we have a mix of records with and without
|
|
|
|
// time stamps, and there were records without time stamps
|
|
|
|
// before the first one with a time stamp, this may be inaccurate).
|
|
|
|
//
|
|
|
|
ti_time = (long)stats.start_time;
|
2018-02-06 04:24:33 +00:00
|
|
|
ti_tm = localtime(&ti_time);
|
|
|
|
first_elapsed = "?";
|
2019-11-17 19:02:20 +00:00
|
|
|
if (ti_tm) {
|
2019-12-20 05:57:04 +00:00
|
|
|
first_elapsed = QString("%1-%2-%3 %4:%5:%6")
|
Fix formatting of the start time and elapsed time.
There's no
QString arg(uint a, int fieldWidth = 0, QChar fillChar = QLatin1Char(' '))
const
version of the arg method of QString, there's only
QString arg(uint a, int fieldWidth = 0, int base = 10,
QChar fillChar = Latin1Char(' ')) const
so if you don't pass the base argument, it turns the QChar into an int
(presumably using the unicode method, so that ends up being 0x20 or 32),
passes it as the base argument (so it does the conversion base-32 -
that's <= 36, so it's a valid value for the base argument), and defaults
the fillChar argument to space.
Add 10 as the base argument, so it behaves correctly.
Bug: 16429
Change-Id: If4872d6d55aa5d9a7489219622d4190827e65d34
Reviewed-on: https://code.wireshark.org/review/36337
Petri-Dish: Guy Harris <guy@alum.mit.edu>
Tested-by: Petri Dish Buildbot
Reviewed-by: Guy Harris <guy@alum.mit.edu>
2020-03-08 18:39:02 +00:00
|
|
|
.arg(ti_tm->tm_year + 1900, 4, 10, QChar('0'))
|
|
|
|
.arg(ti_tm->tm_mon + 1, 2, 10, QChar('0'))
|
|
|
|
.arg(ti_tm->tm_mday, 2, 10, QChar('0'))
|
|
|
|
.arg(ti_tm->tm_hour, 2, 10, QChar('0'))
|
|
|
|
.arg(ti_tm->tm_min, 2, 10, QChar('0'))
|
|
|
|
.arg(ti_tm->tm_sec, 2, 10, QChar('0'));
|
2018-02-06 04:24:33 +00:00
|
|
|
}
|
2018-02-10 02:45:14 +00:00
|
|
|
} else {
|
|
|
|
first_elapsed = tr("unknown");
|
2012-07-27 21:43:02 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Elapsed time
|
2016-09-08 21:31:03 +00:00
|
|
|
first_elapsed += " / ";
|
2019-11-17 19:02:20 +00:00
|
|
|
if (status == PREVIEW_SUCCEEDED && stats.have_times) {
|
2018-02-10 02:45:14 +00:00
|
|
|
//
|
|
|
|
// We didn't time out, so we looked at all packets, and we got
|
|
|
|
// at least one packet with a time stamp, so we can calculate
|
|
|
|
// an elapsed time from the time stamp of the last packet with
|
|
|
|
// with a time stamp (if we have a mix of records with and without
|
|
|
|
// time stamps, and there were records without time stamps after
|
|
|
|
// the last one with a time stamp, this may be inaccurate).
|
|
|
|
//
|
|
|
|
elapsed_time = (unsigned int)(stats.stop_time-stats.start_time);
|
2019-11-17 19:02:20 +00:00
|
|
|
if (elapsed_time/86400) {
|
Fix formatting of the start time and elapsed time.
There's no
QString arg(uint a, int fieldWidth = 0, QChar fillChar = QLatin1Char(' '))
const
version of the arg method of QString, there's only
QString arg(uint a, int fieldWidth = 0, int base = 10,
QChar fillChar = Latin1Char(' ')) const
so if you don't pass the base argument, it turns the QChar into an int
(presumably using the unicode method, so that ends up being 0x20 or 32),
passes it as the base argument (so it does the conversion base-32 -
that's <= 36, so it's a valid value for the base argument), and defaults
the fillChar argument to space.
Add 10 as the base argument, so it behaves correctly.
Bug: 16429
Change-Id: If4872d6d55aa5d9a7489219622d4190827e65d34
Reviewed-on: https://code.wireshark.org/review/36337
Petri-Dish: Guy Harris <guy@alum.mit.edu>
Tested-by: Petri Dish Buildbot
Reviewed-by: Guy Harris <guy@alum.mit.edu>
2020-03-08 18:39:02 +00:00
|
|
|
first_elapsed += QString("%1 days ").arg(elapsed_time/86400, 2, 10, QChar('0'));
|
2019-12-20 05:57:04 +00:00
|
|
|
elapsed_time = elapsed_time % 86400;
|
2018-02-06 04:24:33 +00:00
|
|
|
}
|
2019-12-20 05:57:04 +00:00
|
|
|
first_elapsed += QString("%2:%3:%4")
|
Fix formatting of the start time and elapsed time.
There's no
QString arg(uint a, int fieldWidth = 0, QChar fillChar = QLatin1Char(' '))
const
version of the arg method of QString, there's only
QString arg(uint a, int fieldWidth = 0, int base = 10,
QChar fillChar = Latin1Char(' ')) const
so if you don't pass the base argument, it turns the QChar into an int
(presumably using the unicode method, so that ends up being 0x20 or 32),
passes it as the base argument (so it does the conversion base-32 -
that's <= 36, so it's a valid value for the base argument), and defaults
the fillChar argument to space.
Add 10 as the base argument, so it behaves correctly.
Bug: 16429
Change-Id: If4872d6d55aa5d9a7489219622d4190827e65d34
Reviewed-on: https://code.wireshark.org/review/36337
Petri-Dish: Guy Harris <guy@alum.mit.edu>
Tested-by: Petri Dish Buildbot
Reviewed-by: Guy Harris <guy@alum.mit.edu>
2020-03-08 18:39:02 +00:00
|
|
|
.arg(elapsed_time%86400/3600, 2, 10, QChar('0'))
|
|
|
|
.arg(elapsed_time%3600/60, 2, 10, QChar('0'))
|
|
|
|
.arg(elapsed_time%60, 2, 10, QChar('0'));
|
2018-02-10 02:45:14 +00:00
|
|
|
} else {
|
|
|
|
first_elapsed += tr("unknown");
|
2012-07-27 21:43:02 +00:00
|
|
|
}
|
2016-09-08 21:31:03 +00:00
|
|
|
preview_first_elapsed_.setText(first_elapsed);
|
2012-07-27 21:43:02 +00:00
|
|
|
|
|
|
|
wtap_close(wth);
|
|
|
|
}
|
|
|
|
|
2012-10-15 18:32:51 +00:00
|
|
|
void CaptureFileDialog::on_buttonBox_helpRequested()
|
|
|
|
{
|
2012-10-16 19:47:43 +00:00
|
|
|
if (help_topic_ != TOPIC_ACTION_NONE) wsApp->helpTopicAction(help_topic_);
|
2012-10-15 18:32:51 +00:00
|
|
|
}
|
|
|
|
|
2018-04-28 11:15:36 +00:00
|
|
|
#endif // ! Q_OS_WIN
|