aboutsummaryrefslogtreecommitdiffstats
path: root/ui/qt
diff options
context:
space:
mode:
authorStig Bjørlykke <stig@bjorlykke.org>2016-02-14 19:34:11 +0100
committerStig Bjørlykke <stig@bjorlykke.org>2016-02-15 19:44:27 +0000
commit44f74e7b2657fb8691e59aa86910f818ece31c4d (patch)
treecc711f6bde30ab95fe2778a7a2d36d15f25d1fa0 /ui/qt
parent8e1ade8516ef74b8bcc64e783400c2d0939250ef (diff)
Qt: Add FindLineEdit with regex search option
Add settings to the QLineEdit context menu to use textual or regular expression search. Use this in Follow Stream and Show Packet Bytes. Change-Id: I3a9f5a923f616629aa40a334921871f98b518f30 Reviewed-on: https://code.wireshark.org/review/13942 Petri-Dish: Stig Bjørlykke <stig@bjorlykke.org> Tested-by: Petri Dish Buildbot <buildbot-no-reply@wireshark.org> Reviewed-by: Stig Bjørlykke <stig@bjorlykke.org>
Diffstat (limited to 'ui/qt')
-rw-r--r--ui/qt/CMakeLists.txt2
-rw-r--r--ui/qt/Makefile.common2
-rw-r--r--ui/qt/Wireshark.pro2
-rw-r--r--ui/qt/find_line_edit.cpp75
-rw-r--r--ui/qt/find_line_edit.h64
-rw-r--r--ui/qt/follow_stream_dialog.cpp24
-rw-r--r--ui/qt/follow_stream_dialog.h2
-rw-r--r--ui/qt/follow_stream_dialog.ui9
-rw-r--r--ui/qt/show_packet_bytes_dialog.cpp24
-rw-r--r--ui/qt/show_packet_bytes_dialog.h2
-rw-r--r--ui/qt/show_packet_bytes_dialog.ui11
11 files changed, 211 insertions, 6 deletions
diff --git a/ui/qt/CMakeLists.txt b/ui/qt/CMakeLists.txt
index dbfa3ec02e..ecaf198a68 100644
--- a/ui/qt/CMakeLists.txt
+++ b/ui/qt/CMakeLists.txt
@@ -65,6 +65,7 @@ set(WIRESHARK_QT_HEADERS
filter_dialog.h
filter_expression_frame.h
filter_expressions_preferences_frame.h
+ find_line_edit.h
follow_stream_dialog.h
follow_stream_text.h
font_color_preferences_frame.h
@@ -215,6 +216,7 @@ set(WIRESHARK_QT_SRC
filter_dialog.cpp
filter_expression_frame.cpp
filter_expressions_preferences_frame.cpp
+ find_line_edit.cpp
follow_stream_dialog.cpp
follow_stream_text.cpp
font_color_preferences_frame.cpp
diff --git a/ui/qt/Makefile.common b/ui/qt/Makefile.common
index 32dbdeba5a..aa7212d044 100644
--- a/ui/qt/Makefile.common
+++ b/ui/qt/Makefile.common
@@ -189,6 +189,7 @@ MOC_HDRS = \
filter_dialog.h \
filter_expression_frame.h \
filter_expressions_preferences_frame.h \
+ find_line_edit.h \
follow_stream_dialog.h \
follow_stream_text.h \
font_color_preferences_frame.h \
@@ -452,6 +453,7 @@ WIRESHARK_QT_SRC = \
filter_dialog.cpp \
filter_expression_frame.cpp \
filter_expressions_preferences_frame.cpp \
+ find_line_edit.cpp \
follow_stream_dialog.cpp \
follow_stream_text.cpp \
font_color_preferences_frame.cpp \
diff --git a/ui/qt/Wireshark.pro b/ui/qt/Wireshark.pro
index d4eae29a58..68023b565c 100644
--- a/ui/qt/Wireshark.pro
+++ b/ui/qt/Wireshark.pro
@@ -321,6 +321,7 @@ HEADERS += $$HEADERS_WS_C \
filter_action.h \
filter_expression_frame.h \
filter_expressions_preferences_frame.h \
+ find_line_edit.h \
follow_stream_dialog.h \
follow_stream_text.h \
font_color_preferences_frame.h \
@@ -713,6 +714,7 @@ SOURCES += \
filter_dialog.cpp \
filter_expression_frame.cpp \
filter_expressions_preferences_frame.cpp \
+ find_line_edit.cpp \
follow_stream_dialog.cpp \
follow_stream_text.cpp \
font_color_preferences_frame.cpp \
diff --git a/ui/qt/find_line_edit.cpp b/ui/qt/find_line_edit.cpp
new file mode 100644
index 0000000000..94d351033b
--- /dev/null
+++ b/ui/qt/find_line_edit.cpp
@@ -0,0 +1,75 @@
+/* find_line_edit.cpp
+ *
+ * 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.
+ */
+
+#include "find_line_edit.h"
+
+#include <QAction>
+#include <QKeyEvent>
+#include <QMenu>
+
+void FindLineEdit::contextMenuEvent(QContextMenuEvent *event)
+{
+ QMenu *menu = createStandardContextMenu();
+
+#if (QT_VERSION >= QT_VERSION_CHECK(5, 3, 0))
+ QAction *action;
+
+ menu->addSeparator();
+
+ action = menu->addAction(tr("Textual Find"));
+ action->setCheckable(true);
+ action->setChecked(!use_regex_);
+ connect(action, SIGNAL(triggered()), this, SLOT(setUseTextual()));
+
+ action = menu->addAction(tr("Regular Expression Find"));
+ action->setCheckable(true);
+ action->setChecked(use_regex_);
+ connect(action, SIGNAL(triggered()), this, SLOT(setUseRegex()));
+#endif
+
+ menu->exec(event->globalPos());
+ delete menu;
+}
+
+void FindLineEdit::setUseTextual()
+{
+ use_regex_ = false;
+ emit useRegexFind(use_regex_);
+}
+
+void FindLineEdit::setUseRegex()
+{
+ use_regex_ = true;
+ emit useRegexFind(use_regex_);
+}
+
+/*
+ * Editor modelines
+ *
+ * Local Variables:
+ * c-basic-offset: 4
+ * tab-width: 8
+ * indent-tabs-mode: nil
+ * End:
+ *
+ * ex: set shiftwidth=4 tabstop=8 expandtab:
+ * :indentSize=4:tabSize=8:noTabs=true:
+ */
diff --git a/ui/qt/find_line_edit.h b/ui/qt/find_line_edit.h
new file mode 100644
index 0000000000..03996323ea
--- /dev/null
+++ b/ui/qt/find_line_edit.h
@@ -0,0 +1,64 @@
+/* find_line_edit.h
+ *
+ * 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 FIND_LINE_EDIT_H
+#define FIND_LINE_EDIT_H
+
+#include <QLineEdit>
+
+namespace Ui {
+class FindLineEdit;
+}
+
+class FindLineEdit : public QLineEdit
+{
+ Q_OBJECT
+
+public:
+ explicit FindLineEdit(QWidget *parent = 0) : QLineEdit(parent), use_regex_(false) { }
+ ~FindLineEdit() { }
+
+signals:
+ void useRegexFind(bool);
+
+private slots:
+ void contextMenuEvent(QContextMenuEvent *event);
+ void setUseTextual();
+ void setUseRegex();
+
+private:
+ bool use_regex_;
+};
+
+#endif // FIND_LINE_EDIT_H
+
+/*
+ * Editor modelines - http://www.wireshark.org/tools/modelines.html
+ *
+ * Local variables:
+ * c-basic-offset: 4
+ * tab-width: 8
+ * indent-tabs-mode: nil
+ * End:
+ *
+ * vi: set shiftwidth=4 tabstop=8 expandtab:
+ * :indentSize=4:tabSize=8:noTabs=true:
+ */
diff --git a/ui/qt/follow_stream_dialog.cpp b/ui/qt/follow_stream_dialog.cpp
index 2af7717cc4..40a8afeb1b 100644
--- a/ui/qt/follow_stream_dialog.cpp
+++ b/ui/qt/follow_stream_dialog.cpp
@@ -72,7 +72,8 @@ FollowStreamDialog::FollowStreamDialog(QWidget &parent, CaptureFile &cf, follow_
follower_(NULL),
show_type_(SHOW_ASCII),
truncated_(false),
- save_as_(false)
+ save_as_(false),
+ use_regex_find_(false)
{
ui->setupUi(this);
@@ -99,6 +100,8 @@ FollowStreamDialog::FollowStreamDialog(QWidget &parent, CaptureFile &cf, follow_
ui->teStreamContent->installEventFilter(this);
+ connect(ui->leFind, SIGNAL(useRegexFind(bool)), this, SLOT(useRegexFind(bool)));
+
// XXX Use recent settings instead
resize(parent.width() * 2 / 3, parent.height());
@@ -220,11 +223,30 @@ void FollowStreamDialog::updateWidgets(bool follow_in_progress)
WiresharkDialog::updateWidgets();
}
+void FollowStreamDialog::useRegexFind(bool use_regex)
+{
+ use_regex_find_ = use_regex;
+ if (use_regex_find_)
+ ui->lFind->setText("Regex Find:");
+ else
+ ui->lFind->setText("Find:");
+}
+
void FollowStreamDialog::findText(bool go_back)
{
if (ui->leFind->text().isEmpty()) return;
+#if (QT_VERSION >= QT_VERSION_CHECK(5, 3, 0))
+ bool found;
+ if (use_regex_find_) {
+ QRegExp regex(ui->leFind->text());
+ found = ui->teStreamContent->find(regex);
+ } else {
+ found = ui->teStreamContent->find(ui->leFind->text());
+ }
+#else
bool found = ui->teStreamContent->find(ui->leFind->text());
+#endif
if (found) {
ui->teStreamContent->setFocus();
diff --git a/ui/qt/follow_stream_dialog.h b/ui/qt/follow_stream_dialog.h
index 8508034fe8..e4389aed94 100644
--- a/ui/qt/follow_stream_dialog.h
+++ b/ui/qt/follow_stream_dialog.h
@@ -71,6 +71,7 @@ private slots:
void helpButton();
void filterOut();
+ void useRegexFind(bool use_regex);
void findText(bool go_back = true);
void saveAs();
void printStream();
@@ -126,6 +127,7 @@ private:
QMap<int,guint32> text_pos_to_packet_;
bool save_as_;
+ bool use_regex_find_;
QFile file_;
};
diff --git a/ui/qt/follow_stream_dialog.ui b/ui/qt/follow_stream_dialog.ui
index cbb66cde70..c2b1877f04 100644
--- a/ui/qt/follow_stream_dialog.ui
+++ b/ui/qt/follow_stream_dialog.ui
@@ -104,14 +104,14 @@
<item>
<layout class="QHBoxLayout" name="horizontalLayout_2" stretch="0,1,0">
<item>
- <widget class="QLabel" name="label_2">
+ <widget class="QLabel" name="lFind">
<property name="text">
<string>Find:</string>
</property>
</widget>
</item>
<item>
- <widget class="QLineEdit" name="leFind"/>
+ <widget class="FindLineEdit" name="leFind"/>
</item>
<item>
<widget class="QPushButton" name="bFind">
@@ -137,6 +137,11 @@
<extends>QTextEdit</extends>
<header>follow_stream_text.h</header>
</customwidget>
+ <customwidget>
+ <class>FindLineEdit</class>
+ <extends>QLineEdit</extends>
+ <header>find_line_edit.h</header>
+ </customwidget>
</customwidgets>
<resources/>
<connections/>
diff --git a/ui/qt/show_packet_bytes_dialog.cpp b/ui/qt/show_packet_bytes_dialog.cpp
index e0c1c2767a..93539399cc 100644
--- a/ui/qt/show_packet_bytes_dialog.cpp
+++ b/ui/qt/show_packet_bytes_dialog.cpp
@@ -44,7 +44,8 @@
ShowPacketBytesDialog::ShowPacketBytesDialog(QWidget &parent, CaptureFile &cf) :
WiresharkDialog(parent, cf),
ui(new Ui::ShowPacketBytesDialog),
- show_as_(ShowAsASCII)
+ show_as_(ShowAsASCII),
+ use_regex_find_(false)
{
ui->setupUi(this);
@@ -69,6 +70,8 @@ ShowPacketBytesDialog::ShowPacketBytesDialog(QWidget &parent, CaptureFile &cf) :
ui->tePacketBytes->installEventFilter(this);
+ connect(ui->leFind, SIGNAL(useRegexFind(bool)), this, SLOT(useRegexFind(bool)));
+
// XXX Use recent settings instead
resize(parent.width() * 2 / 3, parent.height());
@@ -126,11 +129,30 @@ void ShowPacketBytesDialog::on_cbShowAs_currentIndexChanged(int idx)
updatePacketBytes();
}
+void ShowPacketBytesDialog::useRegexFind(bool use_regex)
+{
+ use_regex_find_ = use_regex;
+ if (use_regex_find_)
+ ui->lFind->setText("Regex Find:");
+ else
+ ui->lFind->setText("Find:");
+}
+
void ShowPacketBytesDialog::findText(bool go_back)
{
if (ui->leFind->text().isEmpty()) return;
+#if (QT_VERSION >= QT_VERSION_CHECK(5, 3, 0))
+ bool found;
+ if (use_regex_find_) {
+ QRegExp regex(ui->leFind->text());
+ found = ui->tePacketBytes->find(regex);
+ } else {
+ found = ui->tePacketBytes->find(ui->leFind->text());
+ }
+#else
bool found = ui->tePacketBytes->find(ui->leFind->text());
+#endif
if (found) {
ui->tePacketBytes->setFocus();
diff --git a/ui/qt/show_packet_bytes_dialog.h b/ui/qt/show_packet_bytes_dialog.h
index af9e88efd3..9161b97ee5 100644
--- a/ui/qt/show_packet_bytes_dialog.h
+++ b/ui/qt/show_packet_bytes_dialog.h
@@ -60,6 +60,7 @@ private slots:
void on_bFind_clicked();
void on_buttonBox_rejected();
+ void useRegexFind(bool use_regex);
void findText(bool go_back = true);
void helpButton();
void printBytes();
@@ -90,6 +91,7 @@ private:
QPushButton *copy_button_;
QPushButton *save_as_button_;
ShowAsType show_as_;
+ bool use_regex_find_;
QImage image_;
};
diff --git a/ui/qt/show_packet_bytes_dialog.ui b/ui/qt/show_packet_bytes_dialog.ui
index b0c00aa11c..441a19fcf9 100644
--- a/ui/qt/show_packet_bytes_dialog.ui
+++ b/ui/qt/show_packet_bytes_dialog.ui
@@ -41,7 +41,7 @@
</widget>
</item>
<item>
- <layout class="QHBoxLayout" name="horizontalLayout_1" stretch="0,0,0,0,1,0,0">
+ <layout class="QHBoxLayout" name="horizontalLayout_1" stretch="0,0,0">
<item>
<widget class="QLabel" name="lShowAs">
<property name="text">
@@ -81,7 +81,7 @@
</widget>
</item>
<item>
- <widget class="QLineEdit" name="leFind"/>
+ <widget class="FindLineEdit" name="leFind"/>
</item>
<item>
<widget class="QPushButton" name="bFind">
@@ -101,6 +101,13 @@
</item>
</layout>
</widget>
+ <customwidgets>
+ <customwidget>
+ <class>FindLineEdit</class>
+ <extends>QLineEdit</extends>
+ <header>find_line_edit.h</header>
+ </customwidget>
+ </customwidgets>
<resources/>
<connections/>
</ui>