Let Qt lay out and size elements in FollowStreamDialog. Make it
authorGerald Combs <gerald@wireshark.org>
Mon, 14 Oct 2013 21:17:38 +0000 (21:17 -0000)
committerGerald Combs <gerald@wireshark.org>
Mon, 14 Oct 2013 21:17:38 +0000 (21:17 -0000)
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
ui/qt/follow_stream_dialog.h
ui/qt/follow_stream_dialog.ui
ui/qt/main_window_slots.cpp

index 1c3264520bf9a84d009fab1a65976a3cefe96700..d919662f2d5d35524cda7294123ec19cec76cf97 100644 (file)
@@ -44,6 +44,7 @@
 #include "ws_symbol_export.h"
 
 #include "qt_ui_utils.h"
+#include "wireshark_application.h"
 
 #include "globals.h"
 #include "file.h"
 #include <zlib.h>
 #endif
 
-#include <QInputDialog>
+#include <QKeyEvent>
 #include <QMessageBox>
 #include <QPrintDialog>
 #include <QPrinter>
+#include <QTextEdit>
 #include <QTextStream>
 
 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<QKeyEvent*>(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,
index fdd943134a0a2692444b9077374fa58dd429eb6b..5f8ec7471404f5b1d72b12a382f359a8a84a9b67 100644 (file)
@@ -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);
index bf9b1205ed7bbb8ea3d6aaa8f8ddc487eb738344..43c7042c2fab8856c8fdc6dd3619138e2d682c91 100644 (file)
@@ -7,7 +7,7 @@
     <x>0</x>
     <y>0</y>
     <width>667</width>
-    <height>426</height>
+    <height>639</height>
    </rect>
   </property>
   <property name="sizePolicy">
    </sizepolicy>
   </property>
   <property name="windowTitle">
-   <string>Dialog</string>
+   <string>Follow Stream</string>
   </property>
-  <widget class="QGroupBox" name="groupBox">
-   <property name="geometry">
-    <rect>
-     <x>10</x>
-     <y>0</y>
-     <width>651</width>
-     <height>381</height>
-    </rect>
-   </property>
-   <property name="title">
-    <string>Stream contents</string>
-   </property>
-   <widget class="QComboBox" name="cbDirections">
-    <property name="geometry">
-     <rect>
-      <x>11</x>
-      <y>352</y>
-      <width>461</width>
-      <height>27</height>
-     </rect>
-    </property>
-   </widget>
-   <widget class="QTextEdit" name="teStreamContent">
-    <property name="geometry">
-     <rect>
-      <x>10</x>
-      <y>20</y>
-      <width>631</width>
-      <height>321</height>
-     </rect>
-    </property>
-    <property name="readOnly">
-     <bool>true</bool>
-    </property>
-   </widget>
-   <widget class="QWidget" name="layoutWidget">
-    <property name="geometry">
-     <rect>
-      <x>480</x>
-      <y>350</y>
-      <width>158</width>
-      <height>29</height>
-     </rect>
-    </property>
+  <property name="sizeGripEnabled">
+   <bool>true</bool>
+  </property>
+  <layout class="QVBoxLayout" name="verticalLayout">
+   <item>
+    <widget class="QTextEdit" name="teStreamContent">
+     <property name="readOnly">
+      <bool>true</bool>
+     </property>
+    </widget>
+   </item>
+   <item>
     <layout class="QHBoxLayout" name="horizontalLayout">
+     <item>
+      <widget class="QComboBox" name="cbDirections"/>
+     </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>
      <item>
       <widget class="QLabel" name="label">
        <property name="text">
       </widget>
      </item>
     </layout>
-   </widget>
-  </widget>
-  <widget class="QDialogButtonBox" name="buttonBox">
-   <property name="geometry">
-    <rect>
-     <x>20</x>
-     <y>390</y>
-     <width>631</width>
-     <height>27</height>
-    </rect>
-   </property>
-   <property name="standardButtons">
-    <set>QDialogButtonBox::Help</set>
-   </property>
-  </widget>
+   </item>
+   <item>
+    <layout class="QHBoxLayout" name="horizontalLayout_2" stretch="0,1,0">
+     <item>
+      <widget class="QLabel" name="label_2">
+       <property name="text">
+        <string>Find:</string>
+       </property>
+      </widget>
+     </item>
+     <item>
+      <widget class="QLineEdit" name="leFind"/>
+     </item>
+     <item>
+      <widget class="QPushButton" name="bFind">
+       <property name="text">
+        <string>&amp;Next</string>
+       </property>
+      </widget>
+     </item>
+    </layout>
+   </item>
+   <item>
+    <widget class="QDialogButtonBox" name="buttonBox">
+     <property name="standardButtons">
+      <set>QDialogButtonBox::Cancel|QDialogButtonBox::Help</set>
+     </property>
+    </widget>
+   </item>
+  </layout>
  </widget>
  <resources/>
  <connections/>
index c19763fb5b5318f0c0dc0ec04978f6b57c2d5ff7..de435c56e1e2345fd542d3adce4d4a8aaa145b98 100644 (file)
@@ -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)