From f449dcd8a590416aa33e5314f3db2bfc00134e9c Mon Sep 17 00:00:00 2001 From: Gerald Combs Date: Wed, 28 Oct 2015 14:41:59 -0700 Subject: [PATCH] Qt: Add the ability to add filter expressions. Add a "+" icon to the display filter toolbar which allows the addition of a new filter expression button. (Hopefully this will be the last main window UI change before 2.0.) Change-Id: I52bf56bf699dddb7b387b9f4de1bf8b35eb3c4ce Reviewed-on: https://code.wireshark.org/review/11375 Petri-Dish: Gerald Combs Tested-by: Petri Dish Buildbot Reviewed-by: Gerald Combs --- epan/filter_expressions.c | 8 +- epan/filter_expressions.h | 2 +- ui/qt/CMakeLists.txt | 3 + ui/qt/Makefile.am | 2 + ui/qt/Makefile.common | 4 + ui/qt/Wireshark.pro | 3 + ui/qt/filter_expression_frame.cpp | 112 ++++++++++++++++++++++ ui/qt/filter_expression_frame.h | 73 +++++++++++++++ ui/qt/filter_expression_frame.ui | 151 ++++++++++++++++++++++++++++++ ui/qt/main_window.cpp | 5 + ui/qt/main_window.h | 1 + ui/qt/main_window.ui | 38 +++++++- ui/qt/main_window_slots.cpp | 14 +-- 13 files changed, 399 insertions(+), 17 deletions(-) create mode 100644 ui/qt/filter_expression_frame.cpp create mode 100644 ui/qt/filter_expression_frame.h create mode 100644 ui/qt/filter_expression_frame.ui diff --git a/epan/filter_expressions.c b/epan/filter_expressions.c index 936fca96c7..1b6d3069e6 100644 --- a/epan/filter_expressions.c +++ b/epan/filter_expressions.c @@ -44,16 +44,10 @@ filter_expression_new(const gchar *label, const gchar *expr, struct filter_expression *expression; struct filter_expression *prev; - expression = (struct filter_expression *)g_malloc(sizeof(struct filter_expression)); - memset(expression, '\0', sizeof(struct filter_expression)); - expression->button = NULL; + expression = (struct filter_expression *)g_malloc0(sizeof(struct filter_expression)); expression->label = g_strdup(label); expression->expression = g_strdup(expr); expression->enabled = enabled; - expression->deleted = FALSE; - expression->index = 0; - - expression->next = NULL; /* Add it at the end so the button order is always the same*/ if (*pfilter_expression_head == NULL) { diff --git a/epan/filter_expressions.h b/epan/filter_expressions.h index fa2ec7790d..20c0667270 100644 --- a/epan/filter_expressions.h +++ b/epan/filter_expressions.h @@ -38,7 +38,7 @@ struct filter_expression { gchar *label; gchar *expression; - gint index; + gint index; gboolean enabled; /* Can be set to FALSE by Preferences Dialog */ gboolean deleted; /* Can be set to TRUE by Preferences Dialog (GTK+ only) */ diff --git a/ui/qt/CMakeLists.txt b/ui/qt/CMakeLists.txt index d39be1ca97..84783a3d3f 100644 --- a/ui/qt/CMakeLists.txt +++ b/ui/qt/CMakeLists.txt @@ -63,6 +63,7 @@ set(WIRESHARK_QT_HEADERS filter_action.h filter_dialog.h filter_dialog.h + filter_expression_frame.h filter_expressions_preferences_frame.h follow_stream_dialog.h follow_stream_text.h @@ -210,6 +211,7 @@ set(WIRESHARK_QT_SRC file_set_dialog.cpp filter_action.cpp filter_dialog.cpp + filter_expression_frame.cpp filter_expressions_preferences_frame.cpp follow_stream_dialog.cpp follow_stream_text.cpp @@ -353,6 +355,7 @@ set(WIRESHARK_QT_UI export_pdu_dialog.ui file_set_dialog.ui filter_dialog.ui + filter_expression_frame.ui filter_expressions_preferences_frame.ui follow_stream_dialog.ui font_color_preferences_frame.ui diff --git a/ui/qt/Makefile.am b/ui/qt/Makefile.am index fb7f2f592f..237f7f5bbd 100644 --- a/ui/qt/Makefile.am +++ b/ui/qt/Makefile.am @@ -174,6 +174,8 @@ file_set_dialog.$(OBJEXT): ui_file_set_dialog.h filter_dialog.$(OBJEXT): ui_filter_dialog.h +filter_expression_frame.$(OBJEXT): ui_filter_expression_frame.h + filter_expressions_preferences_frame.$(OBJEXT): ui_filter_expressions_preferences_frame.h follow_stream_dialog.$(OBJEXT): ui_follow_stream_dialog.h diff --git a/ui/qt/Makefile.common b/ui/qt/Makefile.common index eb3bba2290..0c1d09cde1 100644 --- a/ui/qt/Makefile.common +++ b/ui/qt/Makefile.common @@ -52,6 +52,7 @@ NODIST_GENERATED_HEADER_FILES = \ ui_extcap_options_dialog.h \ ui_file_set_dialog.h \ ui_filter_dialog.h \ + ui_filter_expression_frame.h \ ui_filter_expressions_preferences_frame.h \ ui_follow_stream_dialog.h \ ui_font_color_preferences_frame.h \ @@ -184,6 +185,7 @@ MOC_HDRS = \ file_set_dialog.h \ filter_action.h \ filter_dialog.h \ + filter_expression_frame.h \ filter_expressions_preferences_frame.h \ follow_stream_dialog.h \ follow_stream_text.h \ @@ -298,6 +300,7 @@ UI_FILES = \ extcap_options_dialog.ui \ file_set_dialog.ui \ filter_dialog.ui \ + filter_expression_frame.ui \ filter_expressions_preferences_frame.ui \ follow_stream_dialog.ui \ font_color_preferences_frame.ui \ @@ -442,6 +445,7 @@ WIRESHARK_QT_SRC = \ file_set_dialog.cpp \ filter_action.cpp \ filter_dialog.cpp \ + filter_expression_frame.cpp \ filter_expressions_preferences_frame.cpp \ follow_stream_dialog.cpp \ follow_stream_text.cpp \ diff --git a/ui/qt/Wireshark.pro b/ui/qt/Wireshark.pro index 9892177d6b..eeeccea6f8 100644 --- a/ui/qt/Wireshark.pro +++ b/ui/qt/Wireshark.pro @@ -231,6 +231,7 @@ FORMS += \ extcap_options_dialog.ui \ file_set_dialog.ui \ filter_dialog.ui \ + filter_expression_frame.ui \ filter_expressions_preferences_frame.ui \ follow_stream_dialog.ui \ font_color_preferences_frame.ui \ @@ -316,6 +317,7 @@ HEADERS += $$HEADERS_WS_C \ extcap_argument_file.h \ extcap_options_dialog.h \ filter_action.h \ + filter_expression_frame.h \ filter_expressions_preferences_frame.h \ follow_stream_dialog.h \ follow_stream_text.h \ @@ -704,6 +706,7 @@ SOURCES += \ file_set_dialog.cpp \ filter_action.cpp \ filter_dialog.cpp \ + filter_expression_frame.cpp \ filter_expressions_preferences_frame.cpp \ follow_stream_dialog.cpp \ follow_stream_text.cpp \ diff --git a/ui/qt/filter_expression_frame.cpp b/ui/qt/filter_expression_frame.cpp new file mode 100644 index 0000000000..d0ccb2677b --- /dev/null +++ b/ui/qt/filter_expression_frame.cpp @@ -0,0 +1,112 @@ +/* filter_expression_frame.cpp + * + * Wireshark - Network traffic analyzer + * By Gerald Combs + * 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 "filter_expression_frame.h" +#include "ui_filter_expression_frame.h" + +#include + +// To do: +// - Add the ability to edit current expressions. + +FilterExpressionFrame::FilterExpressionFrame(QWidget *parent) : + AccordionFrame(parent), + ui(new Ui::FilterExpressionFrame) +{ + ui->setupUi(this); +} + +FilterExpressionFrame::~FilterExpressionFrame() +{ + delete ui; +} + +void FilterExpressionFrame::addExpression(const QString filter_text) +{ + if (isVisible()) { + on_cancelButton_clicked(); + return; + } + + ui->labelLineEdit->setText(tr("Apply this filter")); + ui->displayFilterLineEdit->setText(filter_text); +} + +void FilterExpressionFrame::showEvent(QShowEvent *event) +{ + ui->labelLineEdit->setFocus(); + ui->labelLineEdit->selectAll(); + + AccordionFrame::showEvent(event); +} + +void FilterExpressionFrame::updateWidgets() +{ + bool ok_enable = false; + + if (!ui->labelLineEdit->text().isEmpty()) { + ok_enable = true; + } + + ui->okButton->setEnabled(ok_enable); +} + +void FilterExpressionFrame::on_filterExpressionPreferencesToolButton_clicked() +{ + on_cancelButton_clicked(); + emit showPreferencesDialog(PreferencesDialog::ppFilterExpressions); +} + +void FilterExpressionFrame::on_labelLineEdit_textChanged(const QString) +{ + updateWidgets(); +} + +void FilterExpressionFrame::on_okButton_clicked() +{ + QByteArray label_ba = ui->labelLineEdit->text().toUtf8(); + QByteArray expr_ba = ui->displayFilterLineEdit->text().toUtf8(); + + filter_expression_new(label_ba.constData(), expr_ba.constData(), TRUE); + + on_cancelButton_clicked(); + emit filterExpressionsChanged(); +} + +void FilterExpressionFrame::on_cancelButton_clicked() +{ + ui->labelLineEdit->clear(); + ui->displayFilterLineEdit->clear(); + animatedHide(); +} + +/* + * 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/filter_expression_frame.h b/ui/qt/filter_expression_frame.h new file mode 100644 index 0000000000..3e289919f5 --- /dev/null +++ b/ui/qt/filter_expression_frame.h @@ -0,0 +1,73 @@ +/* filter_expression_frame.h + * + * Wireshark - Network traffic analyzer + * By Gerald Combs + * 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 FILTER_EXPRESSION_FRAME_H +#define FILTER_EXPRESSION_FRAME_H + +#include "accordion_frame.h" +#include "preferences_dialog.h" + +namespace Ui { +class FilterExpressionFrame; +} + +class FilterExpressionFrame : public AccordionFrame +{ + Q_OBJECT + +public: + explicit FilterExpressionFrame(QWidget *parent = 0); + ~FilterExpressionFrame(); + + void addExpression(const QString filter_text); + +signals: + void showPreferencesDialog(PreferencesDialog::PreferencesPane start_pane); + void filterExpressionsChanged(); + +protected: + virtual void showEvent(QShowEvent *event); + +private: + Ui::FilterExpressionFrame *ui; + +private slots: + void updateWidgets(); + void on_filterExpressionPreferencesToolButton_clicked(); + void on_labelLineEdit_textChanged(const QString); + void on_okButton_clicked(); + void on_cancelButton_clicked(); +}; + +#endif // FILTER_EXPRESSION_FRAME_H + +/* + * 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/filter_expression_frame.ui b/ui/qt/filter_expression_frame.ui new file mode 100644 index 0000000000..7a2a33f67d --- /dev/null +++ b/ui/qt/filter_expression_frame.ui @@ -0,0 +1,151 @@ + + + FilterExpressionFrame + + + + 0 + 0 + 745 + 22 + + + + Frame + + + QFrame::NoFrame + + + QFrame::Plain + + + + 0 + + + 0 + + + + + Filter Expression Preferences… + + + + + + + Qt::Horizontal + + + + 88 + 5 + + + + + + + + Label: + + + + + + + + 1 + 0 + + + + + 80 + 0 + + + + + + + + Qt::Horizontal + + + + 20 + 5 + + + + + + + + Filter: + + + + + + + + 1 + 0 + + + + + 80 + 0 + + + + + + + + Qt::Horizontal + + + + 20 + 5 + + + + + + + + OK + + + + + + + Cancel + + + + + + + + SyntaxLineEdit + QLineEdit +
syntax_line_edit.h
+
+ + DisplayFilterEdit + QLineEdit +
display_filter_edit.h
+
+
+ + +
diff --git a/ui/qt/main_window.cpp b/ui/qt/main_window.cpp index ba2087a981..2b47f866c0 100644 --- a/ui/qt/main_window.cpp +++ b/ui/qt/main_window.cpp @@ -323,6 +323,7 @@ MainWindow::MainWindow(QWidget *parent) : main_ui_->addressEditorFrame->hide(); main_ui_->columnEditorFrame->hide(); main_ui_->preferenceEditorFrame->hide(); + main_ui_->filterExpressionFrame->hide(); #ifndef HAVE_LIBPCAP main_ui_->menuCapture->setEnabled(false); @@ -481,6 +482,10 @@ MainWindow::MainWindow(QWidget *parent) : this, SLOT(showPreferencesDialog(QString))); connect(main_ui_->preferenceEditorFrame, SIGNAL(showProtocolPreferences(QString)), this, SLOT(showPreferencesDialog(QString))); + connect(main_ui_->filterExpressionFrame, SIGNAL(showPreferencesDialog(PreferencesDialog::PreferencesPane)), + this, SLOT(showPreferencesDialog(PreferencesDialog::PreferencesPane))); + connect(main_ui_->filterExpressionFrame, SIGNAL(filterExpressionsChanged()), + this, SLOT(filterExpressionsChanged())); connect(this, SIGNAL(setCaptureFile(capture_file*)), main_ui_->searchFrame, SLOT(setCaptureFile(capture_file*))); diff --git a/ui/qt/main_window.h b/ui/qt/main_window.h index be314ed24e..40c52e7b9a 100644 --- a/ui/qt/main_window.h +++ b/ui/qt/main_window.h @@ -285,6 +285,7 @@ private slots: void setFeaturesEnabled(bool enabled = true); void on_actionDisplayFilterExpression_triggered(); + void on_actionNewDisplayFilterExpression_triggered(); void displayFilterButtonClicked(); // Handle FilterAction signals diff --git a/ui/qt/main_window.ui b/ui/qt/main_window.ui index 761f160cb1..3ee4ffadbd 100644 --- a/ui/qt/main_window.ui +++ b/ui/qt/main_window.ui @@ -100,6 +100,9 @@ + + + @@ -698,6 +701,12 @@ false + + + 14 + 14 + + TopToolBarArea @@ -705,6 +714,8 @@ true + + @@ -1240,12 +1251,12 @@ As Filter - - Ctrl+Shift+C - Copy this item as a display filter + + Ctrl+Shift+C + @@ -2806,6 +2817,21 @@ Show IEEE 802.11 wireless LAN statistics. + + + + :/stock/plus-8.png:/stock/plus-8.png + + + Add a filter button + + + Expression… + + + Add a display filter button. + + @@ -2849,6 +2875,12 @@
address_editor_frame.h
1 + + FilterExpressionFrame + QFrame +
filter_expression_frame.h
+ 1 +
diff --git a/ui/qt/main_window_slots.cpp b/ui/qt/main_window_slots.cpp index a51c293e9d..ace6fe50dd 100644 --- a/ui/qt/main_window_slots.cpp +++ b/ui/qt/main_window_slots.cpp @@ -760,13 +760,13 @@ void MainWindow::filterExpressionsChanged() // Recreate filter buttons foreach (QAction *act, main_ui_->displayFilterToolBar->actions()) { // Permanent actions shouldn't have data - if (act->property(dfe_property_).isValid() || act->isSeparator()) { + if (act->property(dfe_property_).isValid()) { main_ui_->displayFilterToolBar->removeAction(act); delete act; } } - bool first = true; + // XXX Add a context menu for removing and changing buttons. for (struct filter_expression *fe = *pfilter_expression_head; fe != NULL; fe = fe->next) { if (!fe->enabled) continue; QAction *dfb_action = new QAction(fe->label, main_ui_->displayFilterToolBar); @@ -775,10 +775,6 @@ void MainWindow::filterExpressionsChanged() dfb_action->setProperty(dfe_property_, true); main_ui_->displayFilterToolBar->addAction(dfb_action); connect(dfb_action, SIGNAL(triggered()), this, SLOT(displayFilterButtonClicked())); - if (first) { - first = false; - main_ui_->displayFilterToolBar->insertSeparator(dfb_action); - } } } @@ -1507,6 +1503,12 @@ void MainWindow::on_actionDisplayFilterExpression_triggered() dfe_dialog->show(); } +void MainWindow::on_actionNewDisplayFilterExpression_triggered() +{ + main_ui_->filterExpressionFrame->addExpression(df_combo_box_->lineEdit()->text()); + showAccordionFrame(main_ui_->filterExpressionFrame); +} + // On Qt4 + OS X with unifiedTitleAndToolBarOnMac set it's possible to make // the main window obnoxiously wide.