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 <gerald@wireshark.org>
Tested-by: Petri Dish Buildbot <buildbot-no-reply@wireshark.org>
Reviewed-by: Gerald Combs <gerald@wireshark.org>
This commit is contained in:
Gerald Combs 2015-10-28 14:41:59 -07:00
parent bd4f414593
commit f449dcd8a5
13 changed files with 399 additions and 17 deletions

View File

@ -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) {

View File

@ -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) */

View File

@ -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

View File

@ -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

View File

@ -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 \

View File

@ -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 \

View File

@ -0,0 +1,112 @@
/* filter_expression_frame.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 "filter_expression_frame.h"
#include "ui_filter_expression_frame.h"
#include <epan/filter_expressions.h>
// 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:
*/

View File

@ -0,0 +1,73 @@
/* filter_expression_frame.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 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:
*/

View File

@ -0,0 +1,151 @@
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>FilterExpressionFrame</class>
<widget class="QFrame" name="FilterExpressionFrame">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>745</width>
<height>22</height>
</rect>
</property>
<property name="windowTitle">
<string>Frame</string>
</property>
<property name="frameShape">
<enum>QFrame::NoFrame</enum>
</property>
<property name="frameShadow">
<enum>QFrame::Plain</enum>
</property>
<layout class="QHBoxLayout" name="horizontalLayout" stretch="0,1,0,0,0,0,1,0,0,0">
<property name="topMargin">
<number>0</number>
</property>
<property name="bottomMargin">
<number>0</number>
</property>
<item>
<widget class="QToolButton" name="filterExpressionPreferencesToolButton">
<property name="text">
<string>Filter Expression Preferences…</string>
</property>
</widget>
</item>
<item>
<spacer name="horizontalSpacer_3">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>88</width>
<height>5</height>
</size>
</property>
</spacer>
</item>
<item>
<widget class="QLabel" name="labelLabel">
<property name="text">
<string>Label:</string>
</property>
</widget>
</item>
<item>
<widget class="SyntaxLineEdit" name="labelLineEdit">
<property name="sizePolicy">
<sizepolicy hsizetype="Expanding" vsizetype="Fixed">
<horstretch>1</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="minimumSize">
<size>
<width>80</width>
<height>0</height>
</size>
</property>
</widget>
</item>
<item>
<spacer name="horizontalSpacer_2">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>20</width>
<height>5</height>
</size>
</property>
</spacer>
</item>
<item>
<widget class="QLabel" name="filterLabel">
<property name="text">
<string>Filter:</string>
</property>
</widget>
</item>
<item>
<widget class="DisplayFilterEdit" name="displayFilterLineEdit">
<property name="sizePolicy">
<sizepolicy hsizetype="Expanding" vsizetype="Fixed">
<horstretch>1</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="minimumSize">
<size>
<width>80</width>
<height>0</height>
</size>
</property>
</widget>
</item>
<item>
<spacer name="horizontalSpacer">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>20</width>
<height>5</height>
</size>
</property>
</spacer>
</item>
<item>
<widget class="QToolButton" name="okButton">
<property name="text">
<string>OK</string>
</property>
</widget>
</item>
<item>
<widget class="QToolButton" name="cancelButton">
<property name="text">
<string>Cancel</string>
</property>
</widget>
</item>
</layout>
</widget>
<customwidgets>
<customwidget>
<class>SyntaxLineEdit</class>
<extends>QLineEdit</extends>
<header>syntax_line_edit.h</header>
</customwidget>
<customwidget>
<class>DisplayFilterEdit</class>
<extends>QLineEdit</extends>
<header>display_filter_edit.h</header>
</customwidget>
</customwidgets>
<resources/>
<connections/>
</ui>

View File

@ -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*)));

View File

@ -285,6 +285,7 @@ private slots:
void setFeaturesEnabled(bool enabled = true);
void on_actionDisplayFilterExpression_triggered();
void on_actionNewDisplayFilterExpression_triggered();
void displayFilterButtonClicked();
// Handle FilterAction signals

View File

@ -100,6 +100,9 @@
<item>
<widget class="PreferenceEditorFrame" name="preferenceEditorFrame"/>
</item>
<item>
<widget class="FilterExpressionFrame" name="filterExpressionFrame"/>
</item>
<item>
<widget class="QStackedWidget" name="mainStack">
<property name="enabled">
@ -698,6 +701,12 @@
<property name="movable">
<bool>false</bool>
</property>
<property name="iconSize">
<size>
<width>14</width>
<height>14</height>
</size>
</property>
<attribute name="toolBarArea">
<enum>TopToolBarArea</enum>
</attribute>
@ -705,6 +714,8 @@
<bool>true</bool>
</attribute>
<addaction name="actionDisplayFilterExpression"/>
<addaction name="separator"/>
<addaction name="actionNewDisplayFilterExpression"/>
</widget>
<widget class="QToolBar" name="wirelessToolBar">
<property name="windowTitle">
@ -1240,12 +1251,12 @@
<property name="text">
<string>As Filter</string>
</property>
<property name="shortcut">
<string>Ctrl+Shift+C</string>
</property>
<property name="toolTip">
<string>Copy this item as a display filter</string>
</property>
<property name="shortcut">
<string>Ctrl+Shift+C</string>
</property>
</action>
<action name="actionAnalyzeAAFSelected">
<property name="text">
@ -2806,6 +2817,21 @@
<string>Show IEEE 802.11 wireless LAN statistics.</string>
</property>
</action>
<action name="actionNewDisplayFilterExpression">
<property name="icon">
<iconset resource="../../image/toolbar.qrc">
<normaloff>:/stock/plus-8.png</normaloff>:/stock/plus-8.png</iconset>
</property>
<property name="text">
<string>Add a filter button</string>
</property>
<property name="iconText">
<string>Expression…</string>
</property>
<property name="toolTip">
<string>Add a display filter button.</string>
</property>
</action>
</widget>
<layoutdefault spacing="6" margin="11"/>
<customwidgets>
@ -2849,6 +2875,12 @@
<header>address_editor_frame.h</header>
<container>1</container>
</customwidget>
<customwidget>
<class>FilterExpressionFrame</class>
<extends>QFrame</extends>
<header>filter_expression_frame.h</header>
<container>1</container>
</customwidget>
</customwidgets>
<resources>
<include location="../../image/toolbar.qrc"/>

View File

@ -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.