From 0efe942aab7e985c825422e3f7a0d2e5aee9a5b9 Mon Sep 17 00:00:00 2001 From: Gerald Combs Date: Mon, 14 Oct 2013 21:17:38 +0000 Subject: Let Qt lay out and size elements in FollowStreamDialog. Make it resizable. Get rid of the group box -- the OS X and Windows HIGs discourage its use and I'm not sure if it fits the GNOME HIG in this case either. Make the stream contents monospace. Set the cursor to the beginning of the text when we follow a stream. Continue the War On Unnecessary Dialogs. Move "Find"ing from a pop-up window to the main Follow dialog. Wrap back to the beginning as needed. Add a "Cancel" button. Make sure it and the escape key work as expected. svn path=/trunk/; revision=52607 --- ui/qt/follow_stream_dialog.cpp | 98 ++++++++++++++++++++++++++++----- ui/qt/follow_stream_dialog.h | 13 ++++- ui/qt/follow_stream_dialog.ui | 121 ++++++++++++++++++++--------------------- ui/qt/main_window_slots.cpp | 3 + 4 files changed, 157 insertions(+), 78 deletions(-) diff --git a/ui/qt/follow_stream_dialog.cpp b/ui/qt/follow_stream_dialog.cpp index 1c3264520b..d919662f2d 100644 --- a/ui/qt/follow_stream_dialog.cpp +++ b/ui/qt/follow_stream_dialog.cpp @@ -44,6 +44,7 @@ #include "ws_symbol_export.h" #include "qt_ui_utils.h" +#include "wireshark_application.h" #include "globals.h" #include "file.h" @@ -56,10 +57,11 @@ #include #endif -#include +#include #include #include #include +#include #include FollowStreamDialog::FollowStreamDialog(QWidget *parent) : @@ -69,16 +71,16 @@ FollowStreamDialog::FollowStreamDialog(QWidget *parent) : follow_info = NULL; ui->setupUi(this); - this->setFixedSize(this->size()); + ui->teStreamContent->setFont(wsApp->monospaceFont()); + ui->teStreamContent->installEventFilter(this); connect(ui->buttonBox, SIGNAL(helpRequested()), this, SLOT(HelpButton())); - bFilterOut = ui->buttonBox->addButton(tr("Filter out this stream"), QDialogButtonBox::ActionRole); + bFilterOut = ui->buttonBox->addButton(tr("Hide this stream"), QDialogButtonBox::ActionRole); connect(bFilterOut, SIGNAL(clicked()), this, SLOT(FilterOut())); - - bFind = ui->buttonBox->addButton(tr("Find"), QDialogButtonBox::ActionRole); - connect(bFind, SIGNAL(clicked()), this, SLOT(FindText())); +// bFind = ui->buttonBox->addButton(tr("Find"), QDialogButtonBox::ActionRole); +// connect(bFind, SIGNAL(clicked()), this, SLOT(FindText())); bPrint = ui->buttonBox->addButton(tr("Print"), QDialogButtonBox::ActionRole); connect(bPrint, SIGNAL(clicked()), this, SLOT(Print())); @@ -99,16 +101,17 @@ void FollowStreamDialog::Print() #endif } -void FollowStreamDialog::FindText() +void FollowStreamDialog::FindText(bool go_back) { - bool ok; - QString text = QInputDialog::getText(this, tr("Wireshark: Find text"), - tr("Find text:"), QLineEdit::Normal, - " ", &ok); - if (ok && !text.isEmpty()) - { + if (ui->leFind->text().isEmpty()) return; + + bool found = ui->teStreamContent->find(ui->leFind->text()); + + if (found) { + ui->teStreamContent->setFocus(); + } else if (go_back) { ui->teStreamContent->moveCursor(QTextCursor::Start); - ui->teStreamContent->find(text); + FindText(false); } } @@ -201,6 +204,21 @@ void FollowStreamDialog::on_cbCharset_currentIndexChanged(int index) follow_read_stream(); } +void FollowStreamDialog::on_bFind_clicked() +{ + FindText(); +} + +void FollowStreamDialog::on_leFind_returnPressed() +{ + FindText(); +} + +void FollowStreamDialog::on_buttonBox_rejected() +{ + hide(); +} + frs_return_t FollowStreamDialog::follow_read_stream() { @@ -392,6 +410,7 @@ FollowStreamDialog::follow_stream() follow_info->is_ipv6 = stats.is_ipv6; follow_read_stream(); + ui->teStreamContent->moveCursor(QTextCursor::Start); } @@ -463,6 +482,57 @@ void FollowStreamDialog::add_text(char *buffer, size_t nchars, gboolean is_from_ } } +// The following keyboard shortcuts should work (although +// they may not work consistently depending on focus): +// / (slash), Ctrl-F - Focus and highlight the search box +// Ctrl-G, Ctrl-N, F3 - Find next +// Should we make it so that typing any text starts searching? +bool FollowStreamDialog::eventFilter(QObject *obj, QEvent *event) +{ + Q_UNUSED(obj) + if (ui->teStreamContent->hasFocus() && event->type() == QEvent::KeyPress) { + ui->leFind->setFocus(); + QKeyEvent *keyEvent = static_cast(event); + if (keyEvent->matches(QKeySequence::Find)) { + return true; + } else if (keyEvent->matches(QKeySequence::FindNext)) { + FindText(); + return true; + } + } + + return false; +} + +void FollowStreamDialog::keyPressEvent(QKeyEvent *event) +{ + if (ui->leFind->hasFocus()) { + if (event->key() == Qt::Key_Enter || event->key() == Qt::Key_Return) { + FindText(); + return; + } + } else { + if (event->key() == Qt::Key_Slash || event->matches(QKeySequence::Find)) { + ui->leFind->setFocus(); + ui->leFind->selectAll(); + } + return; + } + + if (event->key() == Qt::Key_F3 || event->key() == Qt::Key_N && event->modifiers() & Qt::ControlModifier) { + FindText(); + return; + } + + QDialog::keyPressEvent(event); +} + +void FollowStreamDialog::closeEvent(QCloseEvent *event) +{ + Q_UNUSED(event) + hide(); +} + frs_return_t FollowStreamDialog::follow_show(char *buffer, size_t nchars, gboolean is_from_server, diff --git a/ui/qt/follow_stream_dialog.h b/ui/qt/follow_stream_dialog.h index fdd943134a..5f8ec74714 100644 --- a/ui/qt/follow_stream_dialog.h +++ b/ui/qt/follow_stream_dialog.h @@ -93,16 +93,23 @@ public: void add_text(char *buffer, size_t nchars, gboolean is_from_server); +protected: + bool eventFilter(QObject *obj, QEvent *event); + void keyPressEvent(QKeyEvent *event); + void closeEvent (QCloseEvent *event); + private slots: void on_cbCharset_currentIndexChanged(int index); void on_cbDirections_currentIndexChanged(int index); + void on_bFind_clicked(); + void on_leFind_returnPressed(); + void on_buttonBox_rejected(); + void HelpButton(); void FilterOut(); - void FindText(); + void FindText(bool go_back = true); void SaveAs(); void Print(); -// void on_bNext_clicked(); -// void on_bPrevious_clicked(); signals: void updateFilter(QString &filter, bool force); diff --git a/ui/qt/follow_stream_dialog.ui b/ui/qt/follow_stream_dialog.ui index bf9b1205ed..43c7042c2f 100644 --- a/ui/qt/follow_stream_dialog.ui +++ b/ui/qt/follow_stream_dialog.ui @@ -7,7 +7,7 @@ 0 0 667 - 426 + 639 @@ -17,53 +17,37 @@ - Dialog + Follow Stream - - - - 10 - 0 - 651 - 381 - - - - Stream contents - - - - - 11 - 352 - 461 - 27 - - - - - - - 10 - 20 - 631 - 321 - - - - true - - - - - - 480 - 350 - 158 - 29 - - + + true + + + + + + true + + + + + + + + + + + Qt::Horizontal + + + + 40 + 20 + + + + @@ -104,21 +88,36 @@ - - - - - - 20 - 390 - 631 - 27 - - - - QDialogButtonBox::Help - - + + + + + + + Find: + + + + + + + + + + &Next + + + + + + + + + QDialogButtonBox::Cancel|QDialogButtonBox::Help + + + + diff --git a/ui/qt/main_window_slots.cpp b/ui/qt/main_window_slots.cpp index c19763fb5b..de435c56e1 100644 --- a/ui/qt/main_window_slots.cpp +++ b/ui/qt/main_window_slots.cpp @@ -1703,6 +1703,9 @@ void MainWindow::on_actionAnalyzePAFOrNotSelected_triggered() void MainWindow::on_actionAnalyzeFollowTCPStream_triggered() { + // XXX Keeping a window or dialog in memory is common in the GTK+ + // code but not in the Qt code. Should we just create a new + // dialog and exec() it instead? follow_stream_dialog_.Follow(getFilter(), FOLLOW_TCP); if (follow_stream_dialog_.isMinimized() == true) -- cgit v1.2.3