Add a text import dialog. Use libui.

svn path=/trunk/; revision=44956
This commit is contained in:
Gerald Combs 2012-09-17 23:40:53 +00:00
parent 06499e6dd0
commit 3069f22bd1
12 changed files with 1127 additions and 56 deletions

View File

@ -134,9 +134,6 @@ win32:INCLUDEPATH += \
# We have to manually trigger relinking each time one of these is modified.
# Is there any way to do this automatically?
SOURCES_WS_C = \
../alert_box.c \
../iface_lists.c \
../util.c \
../../airpcap_loader.c \
../../capture-pcap-util.c \
../../capture.c \
@ -239,7 +236,8 @@ HEADERS_QT_CPP = \
wireshark_application.h
FORMS += main_window.ui \
main_welcome.ui
main_welcome.ui \
import_text_dialog.ui
win32 { ## These should be in config.pri ??
!isEmpty(PORTAUDIO_DIR) {
@ -285,7 +283,7 @@ macx:QMAKE_LFLAGS += \
-framework CoreServices \
-framework ApplicationServices -framework CoreFoundation -framework CoreServices
unix:LIBS += -L../../lib -Wl,-rpath ../../lib -lwireshark -lwiretap -lwsutil \
unix:LIBS += -L../../lib -Wl,-rpath ../../lib -lwireshark -lwiretap -lwsutil -lui \
-lpcap
macx:LIBS += -Wl,-macosx_version_min,10.5 -liconv
@ -318,6 +316,7 @@ win32 {
LIBS += \
wsock32.lib user32.lib shell32.lib comctl32.lib comdlg32.lib \
-L../../epan -llibwireshark -L../../wsutil -llibwsutil -L../../wiretap -lwiretap-$${WTAP_VERSION} \
-L.. -llibui \
-L$${GLIB_DIR}/lib -lglib-2.0 -lgmodule-2.0
!isEmpty(MSVCR_DLL) {
@ -366,7 +365,6 @@ win32 {
#QMAKE_POST_LINK +=$$quote(cd $$replace(PLUGINS_IN_PWD, /, \\)\\..\\..\\plugins$$escape_expand(\\n\\t))
#QMAKE_POST_LINK +=$$quote(nmake -f Makefile.nmake INSTALL_DIR=$$replace(PLUGINS_OUT_PWD, /, \\)\\$(DESTDIR)$$escape_expand(\\n\\t))
#QMAKE_POST_LINK +=$$quote(cd $$replace(PLUGINS_IN_PWD, /, \\)$$escape_expand(\\n\\t))
}
RESOURCES += \
@ -385,3 +383,9 @@ ICON = ../../packaging/macosx/Resources/Wireshark.icns
RC_FILE = qtshark.rc
win32: QMAKE_CLEAN += *.pdb
HEADERS += \
import_text_dialog.h
SOURCES += \
import_text_dialog.cpp

View File

@ -0,0 +1,446 @@
/* import_text_dialog.cpp
*
* $Id: capture_file_dialog.cpp 44864 2012-09-10 23:03:22Z gerald $
*
* Wireshark - Network traffic analyzer
* By Gerald Combs <gerald@wireshark.org>
* 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
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
*
* 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.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*/
#ifdef HAVE_CONFIG_H
#include "config.h"
#endif
#include <time.h>
#include <import_text_dialog.h>
#include "wiretap/wtap.h"
#include "wiretap/pcap-encap.h"
#include <epan/prefs.h>
#include "ui/text_import_scanner.h"
#include "ui/last_open_dir.h"
#include "ui/alert_box.h"
#include "file.h"
#include "wsutil/file_util.h"
#include "tempfile.h"
#include <ui_import_text_dialog.h>
#include <wireshark_application.h>
#include <QFileDialog>
#include <QDebug>
#include <QFile>
#include <QMessageBox>
ImportTextDialog::ImportTextDialog(QWidget *parent) :
QDialog(parent),
ui(new Ui::ImportTextDialog),
import_info_()
{
int encap;
int i;
ui->setupUi(this);
memset(&import_info_, 0, sizeof(import_info_));
ok_button_ = ui->buttonBox->button(QDialogButtonBox::Ok);
ok_button_->setEnabled(false);
#ifdef Q_WS_MAC
// The grid layout squishes each line edit otherwise.
int le_height = ui->textFileLineEdit->sizeHint().height();
ui->ethertypeLineEdit->setMinimumHeight(le_height);
ui->protocolLineEdit->setMinimumHeight(le_height);
ui->sourcePortLineEdit->setMinimumHeight(le_height);
ui->destinationPortLineEdit->setMinimumHeight(le_height);
ui->tagLineEdit->setMinimumHeight(le_height);
ui->ppiLineEdit->setMinimumHeight(le_height);
#endif
on_dateTimeLineEdit_textChanged(ui->dateTimeLineEdit->text());
for (i = 0; i < ui->headerGridLayout->count(); i++) {
QRadioButton *rb = qobject_cast<QRadioButton *>(ui->headerGridLayout->itemAt(i)->widget());
if (rb) encap_buttons_.append(rb);
}
/* Scan all Wiretap encapsulation types */
import_info_.encapsulation = WTAP_ENCAP_ETHERNET;
for (encap = import_info_.encapsulation; encap < wtap_get_num_encap_types(); encap++)
{
/* Check if we can write to a PCAP file
*
* Exclude wtap encapsulations that require a pseudo header,
* because we won't setup one from the text we import and
* wiretap doesn't allow us to write 'raw' frames
*/
if ((wtap_wtap_encap_to_pcap_encap(encap) > 0) && !wtap_encap_requires_phdr(encap)) {
const char *name;
/* If it has got a name */
if ((name = wtap_encap_string(encap)))
{
ui->encapComboBox->addItem(name, QVariant(encap));
}
}
}
}
ImportTextDialog::~ImportTextDialog()
{
delete ui;
}
QString &ImportTextDialog::capfileName() {
return capfile_name_;
}
void ImportTextDialog::convertTextFile() {
int import_file_fd;
char *tmpname;
int err;
capfile_name_.clear();
/* Choose a random name for the temporary import buffer */
import_file_fd = create_tempfile(&tmpname, "import");
capfile_name_.append(tmpname);
import_info_.wdh = wtap_dump_fdopen(import_file_fd, WTAP_FILE_PCAP, import_info_.encapsulation, import_info_.max_frame_length, FALSE, &err);
qDebug() << capfile_name_ << ":" << import_info_.wdh << import_info_.encapsulation << import_info_.max_frame_length;
if (import_info_.wdh == NULL) {
open_failure_alert_box(capfile_name_.toUtf8().constData(), err, TRUE);
fclose(import_info_.import_text_file);
setResult(QDialog::Rejected);
return;
}
text_import_setup(&import_info_);
text_importin = import_info_.import_text_file;
text_importlex();
text_import_cleanup();
if (fclose(import_info_.import_text_file))
{
read_failure_alert_box(import_info_.import_text_filename, errno);
}
if (!wtap_dump_close(import_info_.wdh, &err))
{
write_failure_alert_box(capfile_name_.toUtf8().constData(), err);
}
}
void ImportTextDialog::enableHeaderWidgets(bool enable_buttons) {
bool ethertype = false;
bool ipv4_proto = false;
bool port = false;
bool sctp_tag = false;
bool sctp_ppi = false;
if (enable_buttons) {
if (ui->ethernetButton->isChecked()) {
ethertype = true;
on_ethertypeLineEdit_textChanged(ui->ethertypeLabel->text());
} else if (ui->ipv4Button->isChecked()) {
ipv4_proto = true;
on_protocolLineEdit_textChanged(ui->protocolLineEdit->text());
} else if (ui->udpButton->isChecked() || ui->tcpButton->isChecked()) {
port = true;
on_sourcePortLineEdit_textChanged(ui->sourcePortLineEdit->text());
on_destinationPortLineEdit_textChanged(ui->destinationPortLineEdit->text());
} else if (ui->sctpButton->isChecked()) {
port = true;
sctp_tag = true;
on_sourcePortLineEdit_textChanged(ui->sourcePortLineEdit->text());
on_destinationPortLineEdit_textChanged(ui->destinationPortLineEdit->text());
on_tagLineEdit_textChanged(ui->tagLineEdit->text());
}
if (ui->sctpDataButton->isChecked()) {
port = true;
sctp_ppi = true;
on_sourcePortLineEdit_textChanged(ui->sourcePortLineEdit->text());
on_destinationPortLineEdit_textChanged(ui->destinationPortLineEdit->text());
on_ppiLineEdit_textChanged(ui->ppiLineEdit->text());
}
}
foreach (QRadioButton *rb, encap_buttons_) {
rb->setEnabled(enable_buttons);
}
ui->ethertypeLabel->setEnabled(ethertype);
ui->ethertypeLineEdit->setEnabled(ethertype);
ui->protocolLabel->setEnabled(ipv4_proto);
ui->protocolLineEdit->setEnabled(ipv4_proto);
ui->sourcePortLabel->setEnabled(port);
ui->sourcePortLineEdit->setEnabled(port);
ui->destinationPortLabel->setEnabled(port);
ui->destinationPortLineEdit->setEnabled(port);
ui->tagLabel->setEnabled(sctp_tag);
ui->tagLineEdit->setEnabled(sctp_tag);
ui->ppiLabel->setEnabled(sctp_ppi);
ui->ppiLineEdit->setEnabled(sctp_ppi);
}
void ImportTextDialog::exec() {
QVariant encap_val;
QDialog::exec();
if (result() != QDialog::Accepted) {
return;
}
import_info_.import_text_filename = ui->textFileLineEdit->text().toUtf8().data();
import_info_.import_text_file = ws_fopen(import_info_.import_text_filename, "rb");
if (!import_info_.import_text_file) {
open_failure_alert_box(import_info_.import_text_filename, errno, FALSE);
setResult(QDialog::Rejected);
return;
}
import_info_.offset_type =
ui->hexOffsetButton->isChecked() ? OFFSET_HEX :
ui->decimalOffsetButton->isChecked() ? OFFSET_DEC :
ui->octalOffsetButton->isChecked() ? OFFSET_OCT :
OFFSET_NONE;
import_info_.date_timestamp = ui->dateTimeLineEdit->text().length() > 0;
import_info_.date_timestamp_format = ui->dateTimeLineEdit->text().toUtf8().data();
encap_val = ui->encapComboBox->itemData(ui->encapComboBox->currentIndex());
import_info_.dummy_header_type = HEADER_NONE;
if (encap_val.isValid() && encap_val.toUInt() == WTAP_ENCAP_ETHERNET && !ui->noDummyButton->isChecked()) {
// Inputs were validated in the on_xxx_textChanged slots.
if (ui->ethernetButton->isChecked()) {
import_info_.dummy_header_type = HEADER_ETH;
} else if (ui->ipv4Button->isChecked()) {
import_info_.dummy_header_type = HEADER_IPV4;
} else if(ui->udpButton->isChecked()) {
import_info_.dummy_header_type = HEADER_UDP;
} else if(ui->tcpButton->isChecked()) {
import_info_.dummy_header_type = HEADER_TCP;
} else if(ui->sctpButton->isChecked()) {
import_info_.dummy_header_type = HEADER_SCTP;
} else if(ui->sctpDataButton->isChecked()) {
import_info_.dummy_header_type = HEADER_SCTP_DATA;
}
}
if (import_info_.max_frame_length == 0) {
import_info_.max_frame_length = IMPORT_MAX_PACKET;
}
convertTextFile();
}
void ImportTextDialog::on_textFileBrowseButton_clicked()
{
char *open_dir = NULL;
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. */
/* This is now the default behaviour in file_selection_new() */
open_dir = get_last_open_dir();
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')
open_dir = prefs.gui_fileopen_dir;
break;
}
QString file_name = QFileDialog::getOpenFileName(this, "Wireshark: Import text file", open_dir);
ui->textFileLineEdit->setText(file_name);
}
void ImportTextDialog::on_textFileLineEdit_textChanged(const QString &file_name)
{
QFile *text_file;
text_file = new QFile(file_name);
if (text_file->open(QIODevice::ReadOnly)) {
ok_button_->setEnabled(true);
text_file->close();
} else {
ok_button_->setEnabled(false);
}
}
void ImportTextDialog::on_encapComboBox_currentIndexChanged(int index)
{
QVariant val = ui->encapComboBox->itemData(index);
bool enabled = false;
if (val != QVariant::Invalid) {
import_info_.encapsulation = val.toUInt();
if (import_info_.encapsulation == WTAP_ENCAP_ETHERNET) enabled = true;
}
enableHeaderWidgets(enabled);
}
void ImportTextDialog::on_dateTimeLineEdit_textChanged(const QString &time_format)
{
if (time_format.length() > 0) {
time_t cur_time;
struct tm *cur_tm;
char time_str[100];
time(&cur_time);
cur_tm = localtime(&cur_time);
strftime(time_str, 100, ui->dateTimeLineEdit->text().toUtf8().constData(), cur_tm);
ui->timestampExampleLabel->setText(QString("Example: %1").arg(time_str));
} else {
ui->timestampExampleLabel->setText("<i>(No format will be applied)</i>");
}
}
void ImportTextDialog::on_noDummyButton_toggled(bool checked)
{
if (checked) enableHeaderWidgets();
}
void ImportTextDialog::on_ethernetButton_toggled(bool checked)
{
on_noDummyButton_toggled(checked);
}
void ImportTextDialog::on_ipv4Button_toggled(bool checked)
{
on_noDummyButton_toggled(checked);
}
void ImportTextDialog::on_udpButton_toggled(bool checked)
{
on_noDummyButton_toggled(checked);
}
void ImportTextDialog::on_tcpButton_toggled(bool checked)
{
on_noDummyButton_toggled(checked);
}
void ImportTextDialog::on_sctpButton_toggled(bool checked)
{
on_noDummyButton_toggled(checked);
}
void ImportTextDialog::on_sctpDataButton_toggled(bool checked)
{
on_noDummyButton_toggled(checked);
}
void ImportTextDialog::on_ethertypeLineEdit_textChanged(const QString &ethertype_str)
{
bool conv_ok;
import_info_.pid = ethertype_str.toUShort(&conv_ok, 16);
if (conv_ok && import_info_.pid <= 0xffff) {
ok_button_->setEnabled(true);
} else {
ok_button_->setEnabled(false);
}
}
void ImportTextDialog::on_protocolLineEdit_textChanged(const QString &protocol_str)
{
bool conv_ok;
import_info_.protocol = protocol_str.toUShort(&conv_ok, 10);
if (conv_ok && import_info_.protocol <= 0xff) {
ok_button_->setEnabled(true);
} else {
ok_button_->setEnabled(false);
}
}
void ImportTextDialog::on_sourcePortLineEdit_textChanged(const QString &source_port_str)
{
bool conv_ok;
import_info_.src_port = source_port_str.toUShort(&conv_ok, 10);
if (conv_ok && import_info_.src_port <= 0xffff) {
ok_button_->setEnabled(true);
} else {
ok_button_->setEnabled(false);
}
}
void ImportTextDialog::on_destinationPortLineEdit_textChanged(const QString &destination_port_str)
{
bool conv_ok;
import_info_.dst_port = destination_port_str.toUShort(&conv_ok, 10);
if (conv_ok && import_info_.dst_port <= 0xffff) {
ok_button_->setEnabled(true);
} else {
ok_button_->setEnabled(false);
}
}
void ImportTextDialog::on_tagLineEdit_textChanged(const QString &tag_str)
{
bool conv_ok;
import_info_.tag = tag_str.toULong(&conv_ok, 10);
if (conv_ok && import_info_.tag <= 0xffffffff) {
ok_button_->setEnabled(true);
} else {
ok_button_->setEnabled(false);
}
}
void ImportTextDialog::on_ppiLineEdit_textChanged(const QString &ppi_str)
{
bool conv_ok;
import_info_.ppi = ppi_str.toULong(&conv_ok, 10);
if (conv_ok && import_info_.ppi <= 0xffffffff) {
ok_button_->setEnabled(true);
} else {
ok_button_->setEnabled(false);
}
}
void ImportTextDialog::on_maxLengthLineEdit_textChanged(const QString &max_frame_len_str)
{
bool conv_ok;
import_info_.max_frame_length = max_frame_len_str.toUShort(&conv_ok, 10);
if (conv_ok && import_info_.max_frame_length <= IMPORT_MAX_PACKET) {
ok_button_->setEnabled(true);
} else {
ok_button_->setEnabled(false);
}
}

View File

@ -0,0 +1,90 @@
/* import_text_dialog.h
*
* $Id: capture_file_dialog.cpp 44864 2012-09-10 23:03:22Z gerald $
*
* Wireshark - Network traffic analyzer
* By Gerald Combs <gerald@wireshark.org>
* 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
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
*
* 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.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*/
#ifndef IMPORT_TEXT_DIALOG_H
#define IMPORT_TEXT_DIALOG_H
#ifdef HAVE_CONFIG_H
# include "config.h"
#endif
#include <stdio.h>
#include <glib.h>
#include "ui/text_import.h"
#include <QDialog>
#include <QPushButton>
#include <QRadioButton>
namespace Ui {
class ImportTextDialog;
}
class ImportTextDialog : public QDialog
{
Q_OBJECT
public:
explicit ImportTextDialog(QWidget *parent = 0);
~ImportTextDialog();
QString &capfileName();
private:
void convertTextFile();
void enableHeaderWidgets(bool enable_buttons = true);
Ui::ImportTextDialog *ui;
QPushButton *ok_button_;
QList<QRadioButton *>encap_buttons_;
text_import_info_t import_info_;
QString capfile_name_;
public slots:
void exec();
private slots:
void on_textFileBrowseButton_clicked();
void on_textFileLineEdit_textChanged(const QString &arg1);
void on_encapComboBox_currentIndexChanged(int index);
void on_dateTimeLineEdit_textChanged(const QString &arg1);
void on_noDummyButton_toggled(bool checked);
void on_ethernetButton_toggled(bool checked);
void on_ipv4Button_toggled(bool checked);
void on_udpButton_toggled(bool checked);
void on_tcpButton_toggled(bool checked);
void on_sctpButton_toggled(bool checked);
void on_sctpDataButton_toggled(bool checked);
void on_ethertypeLineEdit_textChanged(const QString &ethertype_str);
void on_protocolLineEdit_textChanged(const QString &protocol_str);
void on_sourcePortLineEdit_textChanged(const QString &source_port_str);
void on_destinationPortLineEdit_textChanged(const QString &destination_port_str);
void on_tagLineEdit_textChanged(const QString &tag_str);
void on_ppiLineEdit_textChanged(const QString &ppi_str);
void on_maxLengthLineEdit_textChanged(const QString &max_frame_len_str);
};
#endif // IMPORT_TEXT_DIALOG_H

461
ui/qt/import_text_dialog.ui Normal file
View File

@ -0,0 +1,461 @@
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>ImportTextDialog</class>
<widget class="QDialog" name="ImportTextDialog">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>472</width>
<height>600</height>
</rect>
</property>
<property name="sizePolicy">
<sizepolicy hsizetype="Preferred" vsizetype="Fixed">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="windowTitle">
<string>Wireshark: Import from Text</string>
</property>
<property name="sizeGripEnabled">
<bool>true</bool>
</property>
<property name="modal">
<bool>true</bool>
</property>
<layout class="QFormLayout" name="formLayout_3">
<property name="fieldGrowthPolicy">
<enum>QFormLayout::FieldsStayAtSizeHint</enum>
</property>
<item row="0" column="0" colspan="2">
<widget class="QGroupBox" name="groupBox">
<property name="title">
<string>Import From</string>
</property>
<layout class="QFormLayout" name="formLayout_2">
<item row="1" column="0" colspan="2">
<layout class="QHBoxLayout" name="horizontalLayout_2">
<item>
<widget class="QLabel" name="label">
<property name="text">
<string>File:</string>
</property>
</widget>
</item>
<item>
<widget class="QLineEdit" name="textFileLineEdit">
<property name="sizePolicy">
<sizepolicy hsizetype="MinimumExpanding" vsizetype="Fixed">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="toolTip">
<string>Set name of text file to import</string>
</property>
</widget>
</item>
<item>
<widget class="QPushButton" name="textFileBrowseButton">
<property name="toolTip">
<string>Browse for text file to import</string>
</property>
<property name="text">
<string>Browse...</string>
</property>
</widget>
</item>
</layout>
</item>
<item row="2" column="0" colspan="2">
<layout class="QGridLayout" name="gridLayout_2">
<item row="2" column="1">
<widget class="QRadioButton" name="octalOffsetButton">
<property name="toolTip">
<string>Offsets in the text file are in octal notation</string>
</property>
<property name="text">
<string>Octal</string>
</property>
</widget>
</item>
<item row="0" column="0">
<widget class="QLabel" name="label_2">
<property name="text">
<string>Offsets:</string>
</property>
</widget>
</item>
<item row="0" column="1">
<widget class="QRadioButton" name="hexOffsetButton">
<property name="toolTip">
<string>Offsets in the text file are in hexadecimal notation</string>
</property>
<property name="text">
<string>Hexadecimal</string>
</property>
<property name="checked">
<bool>true</bool>
</property>
</widget>
</item>
<item row="1" column="1">
<widget class="QRadioButton" name="decimalOffsetButton">
<property name="toolTip">
<string>Offsets in the text file are in decimal notation</string>
</property>
<property name="text">
<string>Decimal</string>
</property>
</widget>
</item>
<item row="0" column="2" rowspan="3">
<spacer name="horizontalSpacer_2">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>40</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
</layout>
</item>
<item row="4" column="0" colspan="2">
<layout class="QHBoxLayout" name="horizontalLayout_3">
<item>
<widget class="QLabel" name="label_3">
<property name="toolTip">
<string>The format in which to parse timestamps in the text file (eg. %H:%M:%S.). Format specifiers are based on strptime(3)</string>
</property>
<property name="text">
<string>Timestamp format:</string>
</property>
</widget>
</item>
<item>
<widget class="QLineEdit" name="dateTimeLineEdit">
<property name="toolTip">
<string>The format in which to parse timestamps in the text file (eg. %H:%M:%S.). Format specifiers are based on strptime(3)</string>
</property>
</widget>
</item>
<item>
<widget class="QLabel" name="timestampExampleLabel">
<property name="text">
<string/>
</property>
</widget>
</item>
<item>
<spacer name="horizontalSpacer">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>40</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
</layout>
</item>
</layout>
</widget>
</item>
<item row="1" column="0" colspan="2">
<widget class="QGroupBox" name="groupBox_2">
<property name="title">
<string>Encapsulation</string>
</property>
<layout class="QFormLayout" name="formLayout">
<property name="fieldGrowthPolicy">
<enum>QFormLayout::FieldsStayAtSizeHint</enum>
</property>
<item row="0" column="0" colspan="2">
<layout class="QHBoxLayout" name="horizontalLayout">
<item>
<widget class="QLabel" name="label_4">
<property name="text">
<string>Encapsulation Type:</string>
</property>
</widget>
</item>
<item>
<widget class="QComboBox" name="encapComboBox">
<property name="toolTip">
<string>Encapsulation type of the frames in the import capture file</string>
</property>
</widget>
</item>
<item>
<spacer name="horizontalSpacer_3">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>40</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
</layout>
</item>
<item row="1" column="0" colspan="2">
<layout class="QGridLayout" name="headerGridLayout">
<item row="3" column="2">
<widget class="QLineEdit" name="sourcePortLineEdit">
<property name="toolTip">
<string>The UDP, TCP or SCTP source port for each frame</string>
</property>
</widget>
</item>
<item row="6" column="2">
<widget class="QLineEdit" name="ppiLineEdit">
<property name="toolTip">
<string>The SCTP DATA payload protocol identifier for each frame</string>
</property>
</widget>
</item>
<item row="4" column="2">
<widget class="QLineEdit" name="destinationPortLineEdit">
<property name="toolTip">
<string>The UDP, TCP or SCTP destination port for each frame</string>
</property>
</widget>
</item>
<item row="1" column="0">
<widget class="QRadioButton" name="ethernetButton">
<property name="toolTip">
<string>Prefix each frame with an Ethernet header</string>
</property>
<property name="text">
<string>Ethernet</string>
</property>
</widget>
</item>
<item row="5" column="0">
<widget class="QRadioButton" name="sctpButton">
<property name="toolTip">
<string>Prefix each frame with an Ethernet, IPv4 and SCTP header</string>
</property>
<property name="text">
<string>SCTP</string>
</property>
</widget>
</item>
<item row="6" column="1">
<widget class="QLabel" name="ppiLabel">
<property name="text">
<string>PPI:</string>
</property>
</widget>
</item>
<item row="2" column="1">
<widget class="QLabel" name="protocolLabel">
<property name="text">
<string>Protocol (dec):</string>
</property>
</widget>
</item>
<item row="0" column="0" colspan="3">
<widget class="QRadioButton" name="noDummyButton">
<property name="toolTip">
<string>Leave frames unchanged</string>
</property>
<property name="text">
<string>No dummy header</string>
</property>
<property name="checked">
<bool>true</bool>
</property>
</widget>
</item>
<item row="0" column="3" rowspan="7">
<spacer name="horizontalSpacer_4">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>40</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
<item row="5" column="1">
<widget class="QLabel" name="tagLabel">
<property name="text">
<string>Tag:</string>
</property>
</widget>
</item>
<item row="3" column="0">
<widget class="QRadioButton" name="udpButton">
<property name="toolTip">
<string>Prefix each frame with an Ethernet, IPv4 and UDP header</string>
</property>
<property name="text">
<string>UDP</string>
</property>
</widget>
</item>
<item row="3" column="1">
<widget class="QLabel" name="sourcePortLabel">
<property name="text">
<string>Source port:</string>
</property>
</widget>
</item>
<item row="1" column="2">
<widget class="QLineEdit" name="ethertypeLineEdit">
<property name="toolTip">
<string>The Ethertype value of each frame</string>
</property>
<property name="cursorPosition">
<number>0</number>
</property>
</widget>
</item>
<item row="4" column="0">
<widget class="QRadioButton" name="tcpButton">
<property name="toolTip">
<string>Prefix each frame with an Ethernet, IPv4 and TCP header</string>
</property>
<property name="text">
<string>TCP</string>
</property>
</widget>
</item>
<item row="5" column="2">
<widget class="QLineEdit" name="tagLineEdit">
<property name="toolTip">
<string>The SCTP verification tag for each frame</string>
</property>
</widget>
</item>
<item row="4" column="1">
<widget class="QLabel" name="destinationPortLabel">
<property name="text">
<string>Destination port:</string>
</property>
</widget>
</item>
<item row="1" column="1">
<widget class="QLabel" name="ethertypeLabel">
<property name="text">
<string>Ethertype (hex):</string>
</property>
</widget>
</item>
<item row="2" column="2">
<widget class="QLineEdit" name="protocolLineEdit">
<property name="toolTip">
<string>The IPv4 protocol ID for each frame</string>
</property>
</widget>
</item>
<item row="6" column="0">
<widget class="QRadioButton" name="sctpDataButton">
<property name="toolTip">
<string>Prefix each frame with an Ethernet, IPv4 and SCTP (DATA) header</string>
</property>
<property name="text">
<string>SCTP (Data)</string>
</property>
</widget>
</item>
<item row="2" column="0">
<widget class="QRadioButton" name="ipv4Button">
<property name="toolTip">
<string>Prefix each frame with an Ethernet and IPv4 header</string>
</property>
<property name="text">
<string>IPv4</string>
</property>
</widget>
</item>
</layout>
</item>
</layout>
</widget>
</item>
<item row="3" column="0" colspan="2">
<widget class="QDialogButtonBox" name="buttonBox">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="standardButtons">
<set>QDialogButtonBox::Cancel|QDialogButtonBox::Help|QDialogButtonBox::Ok</set>
</property>
</widget>
</item>
<item row="2" column="1">
<layout class="QHBoxLayout" name="horizontalLayout_4">
<item>
<widget class="QLabel" name="label_11">
<property name="text">
<string>Maximum frame length:</string>
</property>
</widget>
</item>
<item>
<widget class="QLineEdit" name="maxLengthLineEdit">
<property name="toolTip">
<string>The maximum size of the frames to write to the import capture file (max 64000)</string>
</property>
<property name="inputMask">
<string>90000; </string>
</property>
</widget>
</item>
</layout>
</item>
</layout>
</widget>
<resources/>
<connections>
<connection>
<sender>buttonBox</sender>
<signal>accepted()</signal>
<receiver>ImportTextDialog</receiver>
<slot>accept()</slot>
<hints>
<hint type="sourcelabel">
<x>248</x>
<y>254</y>
</hint>
<hint type="destinationlabel">
<x>157</x>
<y>274</y>
</hint>
</hints>
</connection>
<connection>
<sender>buttonBox</sender>
<signal>rejected()</signal>
<receiver>ImportTextDialog</receiver>
<slot>reject()</slot>
<hints>
<hint type="sourcelabel">
<x>316</x>
<y>260</y>
</hint>
<hint type="destinationlabel">
<x>286</x>
<y>274</y>
</hint>
</hints>
</connection>
</connections>
</ui>

View File

@ -760,13 +760,12 @@ int main(int argc, char *argv[])
/* Read the profile independent recent file. We have to do this here so we can */
/* set the profile before it can be set from the command line parameterts */
// xxx qtshark
//recent_read_static(&rf_path, &rf_open_errno);
//if (rf_path != NULL && rf_open_errno != 0) {
// simple_dialog(ESD_TYPE_WARN, ESD_BTN_OK,
// "Could not open common recent file\n\"%s\": %s.",
// rf_path, strerror(rf_open_errno));
//}
recent_read_static(&rf_path, &rf_open_errno);
if (rf_path != NULL && rf_open_errno != 0) {
simple_dialog(ESD_TYPE_WARN, ESD_BTN_OK,
"Could not open common recent file\n\"%s\": %s.",
rf_path, strerror(rf_open_errno));
}
/* "pre-scan" the command line parameters, if we have "console only"
parameters. We do this so we don't start GTK+ if we're only showing
@ -849,6 +848,27 @@ int main(int argc, char *argv[])
}
}
/* Init the "Open file" dialog directory */
/* (do this after the path settings are processed) */
/* Read the profile dependent (static part) of the recent file. */
/* Only the static part of it will be read, as we don't have the gui now to fill the */
/* recent lists which is done in the dynamic part. */
/* We have to do this already here, so command line parameters can overwrite these values. */
recent_read_profile_static(&rf_path, &rf_open_errno);
if (rf_path != NULL && rf_open_errno != 0) {
simple_dialog(ESD_TYPE_WARN, ESD_BTN_OK,
"Could not open recent file\n\"%s\": %s.",
rf_path, g_strerror(rf_open_errno));
}
if (recent.gui_fileopen_remembered_dir &&
test_for_directory(recent.gui_fileopen_remembered_dir) == EISDIR) {
wsApp->setLastOpenDir(recent.gui_fileopen_remembered_dir);
} else {
wsApp->setLastOpenDir(get_persdatafile_dir());
}
#ifdef HAVE_LIBPCAP
capture_callback_add(main_capture_callback, NULL);
#endif

View File

@ -51,6 +51,7 @@
#include "byte_view_tab.h"
#include "capture_file_dialog.h"
#include "display_filter_edit.h"
#include "import_text_dialog.h"
#include "qt_ui_utils.h"
@ -407,7 +408,7 @@ void MainWindow::openCaptureFile(QString &cf_path)
break;
}
// get_dirname overwrites its path. Hopefully this isn't a problem.
set_last_open_dir(get_dirname(cf_path.toUtf8().data()));
wsApp->setLastOpenDir(get_dirname(cf_path.toUtf8().data()));
df_combo_box_->setEditText(display_filter);
main_ui_->statusBar->showExpert();
@ -576,7 +577,7 @@ void MainWindow::mergeCaptureFile()
/* 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. */
set_last_open_dir(get_dirname(tmpname));
wsApp->setLastOpenDir(get_dirname(tmpname));
g_free(tmpname);
df_combo_box_->setEditText(display_filter);
main_ui_->statusBar->showExpert();
@ -585,6 +586,21 @@ void MainWindow::mergeCaptureFile()
}
void MainWindow::importCaptureFile() {
ImportTextDialog import_dlg;
if (!testCaptureFileClose(cap_file_, FALSE, *new QString(" before importing a new capture")))
return;
import_dlg.exec();
if (import_dlg.result() != QDialog::Accepted) {
return;
}
openCaptureFile(import_dlg.capfileName());
}
void MainWindow::saveCapture(capture_file *cf, bool close_capture) {
Q_UNUSED(cf);
Q_UNUSED(close_capture);
@ -594,7 +610,7 @@ void MainWindow::saveCapture(capture_file *cf, bool close_capture) {
bool MainWindow::testCaptureFileClose(capture_file *cf, bool from_quit, QString &before_what) {
bool capture_in_progress = FALSE;
if (cf->state == FILE_CLOSED)
if (!cf || cf->state == FILE_CLOSED)
return true; /* Already closed, nothing to do */
#ifdef HAVE_LIBPCAP
@ -964,7 +980,7 @@ void MainWindow::captureFileReadFinished(const capture_file *cf) {
// /* Remember folder for next Open dialog and save it in recent */
// dir_path = get_dirname(g_strdup(cf->filename));
// set_last_open_dir(dir_path);
// wsApp->setLastOpenDir(dir_path);
// g_free(dir_path);
// }
// set_display_filename(cf);
@ -1208,6 +1224,11 @@ void MainWindow::on_actionFileMerge_triggered()
mergeCaptureFile();
}
void MainWindow::on_actionFileImport_triggered()
{
importCaptureFile();
}
void MainWindow::on_actionFileClose_triggered() {
testCaptureFileClose(&cfile);

View File

@ -96,6 +96,7 @@ private:
void openCaptureFile(QString& cf_path = *new QString());
void mergeCaptureFile();
void importCaptureFile();
void saveCapture(capture_file *cf, bool close_capture);
bool testCaptureFileClose(capture_file *cf, bool from_quit = false, QString& before_what = *new QString());
void captureStop(capture_file *cf);
@ -140,7 +141,9 @@ private slots:
void on_actionFileOpen_triggered();
void on_actionFileMerge_triggered();
void on_actionFileImport_triggered();
void on_actionFileClose_triggered();
void on_actionGoGoToPacket_triggered();
void resetPreviousFocus();

View File

@ -66,7 +66,6 @@ struct remote_host_t {
};
// Referenced from ui/win32/file_dlg_win32.c and implemented in wireshark_application.cpp
extern void set_last_open_dir(const char *dirname);
extern gboolean main_do_quit(void);
#ifdef __cplusplus

View File

@ -48,36 +48,6 @@ static char *last_open_dir = NULL;
static bool updated_last_open_dir = FALSE;
static QList<recent_item_status *> recent_items;
void
set_last_open_dir(const char *dirname)
{
qint64 len;
gchar *new_last_open_dir;
if (dirname) {
len = strlen(dirname);
if (dirname[len-1] == G_DIR_SEPARATOR) {
new_last_open_dir = g_strconcat(dirname, NULL);
}
else {
new_last_open_dir = g_strconcat(dirname,
G_DIR_SEPARATOR_S, NULL);
}
if (last_open_dir == NULL ||
strcmp(last_open_dir, new_last_open_dir) != 0)
updated_last_open_dir = TRUE;
}
else {
new_last_open_dir = NULL;
if (last_open_dir != NULL)
updated_last_open_dir = TRUE;
}
g_free(last_open_dir);
last_open_dir = new_last_open_dir;
}
extern "C" char *
get_last_open_dir(void)
{
@ -282,6 +252,43 @@ void WiresharkApplication::captureFileCallback(int event, void * data)
}
}
QDir WiresharkApplication::lastOpenDir() {
return QDir(last_open_dir);
}
void WiresharkApplication::setLastOpenDir(QString *dir_str) {
setLastOpenDir(dir_str->toUtf8().constData());
}
void WiresharkApplication::setLastOpenDir(const char *dir_name)
{
qint64 len;
gchar *new_last_open_dir;
if (dir_name) {
len = strlen(dir_name);
if (dir_name[len-1] == G_DIR_SEPARATOR) {
new_last_open_dir = g_strconcat(dir_name, NULL);
}
else {
new_last_open_dir = g_strconcat(dir_name,
G_DIR_SEPARATOR_S, NULL);
}
if (last_open_dir == NULL ||
strcmp(last_open_dir, new_last_open_dir) != 0)
updated_last_open_dir = TRUE;
}
else {
new_last_open_dir = NULL;
if (last_open_dir != NULL)
updated_last_open_dir = TRUE;
}
g_free(last_open_dir);
last_open_dir = new_last_open_dir;
}
void WiresharkApplication::clearRecentItems() {
recent_item_status *ri;

View File

@ -60,6 +60,9 @@ public:
void captureCallback(int event, capture_options * capture_opts);
#endif
void captureFileCallback(int event, void * data);
QDir lastOpenDir();
void setLastOpenDir(const char *dir_name);
void setLastOpenDir(QString *dir_str);
private:
QTimer *recent_timer_;

View File

@ -28,18 +28,23 @@
*******************************************************************************/
#ifndef TEXT_IMPORT_H
#define TEXT_IMPORT_H
#ifndef __TEXT_IMPORT_H__
#define __TEXT_IMPORT_H__
#include <glib.h>
#include "wtap.h"
#ifdef __cplusplus
extern "C" {
#endif /* __cplusplus */
#define IMPORT_MAX_PACKET 64000
/* The parameter interface */
enum offset_type
{
OFFSET_NONE = 0,
OFFSET_HEX,
OFFSET_OCT,
OFFSET_DEC
@ -59,11 +64,11 @@ enum dummy_header_type
typedef struct
{
/* Input info */
guchar *import_text_filename;
char *import_text_filename;
FILE *import_text_file;
enum offset_type offset_type;
gboolean date_timestamp;
guchar *date_timestamp_format;
char *date_timestamp_format;
/* Import info */
guint encapsulation;
@ -84,4 +89,8 @@ typedef struct
void text_import_setup(text_import_info_t *info);
void text_import_cleanup(void);
#endif
#ifdef __cplusplus
}
#endif /* __cplusplus */
#endif /* __TEXT_IMPORT_H__ */

View File

@ -28,8 +28,12 @@
*******************************************************************************/
#ifndef TEXT_IMPORT_SCANNER_H
#define TEXT_IMPORT_SCANNER_H
#ifndef __TEXT_IMPORT_SCANNER_H__
#define __TEXT_IMPORT_SCANNER_H__
#ifdef __cplusplus
extern "C" {
#endif /* __cplusplus */
typedef enum {
T_BYTE = 1,
@ -47,4 +51,8 @@ extern FILE *text_importin;
int text_importlex(void);
#endif
#ifdef __cplusplus
}
#endif /* __cplusplus */
#endif /* __TEXT_IMPORT_SCANNER_H__ */