diff options
author | Gerald Combs <gerald@wireshark.org> | 2013-08-08 00:26:57 +0000 |
---|---|---|
committer | Gerald Combs <gerald@wireshark.org> | 2013-08-08 00:26:57 +0000 |
commit | 79454ef9fad4f80b059b77c1ad3cca82bf7f7a43 (patch) | |
tree | add3245672d29123a94400221066a154ca5d7124 /ui | |
parent | 786adc8522ab074a092ad4c61fbd19d8e728e101 (diff) |
Add initial capture filter support.
Add CaptureFilterCombo and CaptureFilterEdit classes, similar to their
display filter counterparts. Add a CaptureFilterSyntaxWorker class which
runs a syntax check in a background thread similar to the threaded code
in capture_dlg.c. Add a bunch of related signal and slot plumbing. Other
minor fixups.
svn path=/trunk/; revision=51200
Diffstat (limited to 'ui')
-rw-r--r-- | ui/gtk/capture_dlg.c | 2 | ||||
-rw-r--r-- | ui/qt/CMakeLists.txt | 6 | ||||
-rw-r--r-- | ui/qt/Makefile.common | 6 | ||||
-rw-r--r-- | ui/qt/QtShark.pro | 8 | ||||
-rw-r--r-- | ui/qt/capture_filter_combo.cpp | 134 | ||||
-rw-r--r-- | ui/qt/capture_filter_combo.h | 69 | ||||
-rw-r--r-- | ui/qt/capture_filter_edit.cpp | 354 | ||||
-rw-r--r-- | ui/qt/capture_filter_edit.h | 84 | ||||
-rw-r--r-- | ui/qt/capture_filter_syntax_worker.cpp | 141 | ||||
-rw-r--r-- | ui/qt/capture_filter_syntax_worker.h | 64 | ||||
-rw-r--r-- | ui/qt/label_stack.cpp | 2 | ||||
-rw-r--r-- | ui/qt/label_stack.h | 2 | ||||
-rw-r--r-- | ui/qt/main_welcome.cpp | 10 | ||||
-rw-r--r-- | ui/qt/main_welcome.h | 3 | ||||
-rw-r--r-- | ui/qt/main_welcome.ui | 112 | ||||
-rw-r--r-- | ui/qt/main_window.cpp | 11 | ||||
-rw-r--r-- | ui/qt/main_window.h | 2 | ||||
-rw-r--r-- | ui/qt/main_window_slots.cpp | 19 | ||||
-rw-r--r-- | ui/qt/recent_file_status.cpp | 14 | ||||
-rw-r--r-- | ui/qt/recent_file_status.h | 11 | ||||
-rw-r--r-- | ui/qt/wireshark_application.cpp | 1 |
21 files changed, 1010 insertions, 45 deletions
diff --git a/ui/gtk/capture_dlg.c b/ui/gtk/capture_dlg.c index c444d58804..c5d0974e93 100644 --- a/ui/gtk/capture_dlg.c +++ b/ui/gtk/capture_dlg.c @@ -596,7 +596,7 @@ typedef struct capture_filter_check { */ /* We could make this smarter by caching results */ -capture_filter_check_t cfc_data; +static capture_filter_check_t cfc_data; static GMutex *pcap_compile_mtx; static GCond *cfc_data_cond; diff --git a/ui/qt/CMakeLists.txt b/ui/qt/CMakeLists.txt index b722a6d981..48712a32a5 100644 --- a/ui/qt/CMakeLists.txt +++ b/ui/qt/CMakeLists.txt @@ -28,6 +28,9 @@ set(QTSHARK_H_SRC byte_view_tab.h byte_view_text.h capture_file_dialog.h + capture_filter_combo.h + capture_filter_edit.h + capture_filter_syntax_worker.h capture_info_dialog.h capture_interface_dialog.h capture_preferences_frame.h @@ -83,6 +86,9 @@ set(CLEAN_FILES byte_view_tab.cpp byte_view_text.cpp capture_file_dialog.cpp + capture_filter_combo.cpp + capture_filter_edit.cpp + capture_filter_syntax_worker.cpp capture_info_dialog.cpp capture_interface_dialog.cpp color_dialog.cpp diff --git a/ui/qt/Makefile.common b/ui/qt/Makefile.common index 02d93e34ea..526a12756a 100644 --- a/ui/qt/Makefile.common +++ b/ui/qt/Makefile.common @@ -92,6 +92,9 @@ MOC_HDRS = \ byte_view_tab.h \ byte_view_text.h \ capture_file_dialog.h \ + capture_filter_combo.h \ + capture_filter_edit.h \ + capture_filter_syntax_worker.h \ capture_info_dialog.h \ capture_interface_dialog.h \ color_dialog.h \ @@ -214,6 +217,9 @@ WIRESHARK_QT_SRC = \ byte_view_tab.cpp \ byte_view_text.cpp \ capture_file_dialog.cpp \ + capture_filter_combo.cpp \ + capture_filter_edit.cpp \ + capture_filter_syntax_worker.cpp \ capture_info_dialog.cpp \ capture_interface_dialog.cpp \ color_dialog.cpp \ diff --git a/ui/qt/QtShark.pro b/ui/qt/QtShark.pro index 052f49fc3d..a648629677 100644 --- a/ui/qt/QtShark.pro +++ b/ui/qt/QtShark.pro @@ -25,6 +25,8 @@ # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. # +cache() + isEqual(QT_MAJOR_VERSION, 4) { QT += core gui } else { @@ -449,6 +451,9 @@ HEADERS += \ byte_view_tab.h \ byte_view_text.h \ capture_file_dialog.h \ + capture_filter_combo.h \ + capture_filter_edit.h \ + capture_filter_syntax_worker.h \ capture_info_dialog.h \ capture_interface_dialog.h \ color_dialog.h \ @@ -484,6 +489,9 @@ SOURCES += \ byte_view_tab.cpp \ byte_view_text.cpp \ capture_file_dialog.cpp \ + capture_filter_combo.cpp \ + capture_filter_edit.cpp \ + capture_filter_syntax_worker.cpp \ capture_info_dialog.cpp \ capture_interface_dialog.cpp \ capture_preferences_frame.cpp \ diff --git a/ui/qt/capture_filter_combo.cpp b/ui/qt/capture_filter_combo.cpp new file mode 100644 index 0000000000..c83b06494d --- /dev/null +++ b/ui/qt/capture_filter_combo.cpp @@ -0,0 +1,134 @@ +/* capture_filter_combo.cpp + * + * $Id$ + * + * 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 <stdio.h> + +#include "qt_ui_utils.h" +#include "ui/recent_utils.h" +#include "ui/recent.h" + +#include <epan/prefs.h> + +#include "capture_filter_combo.h" +#include "wireshark_application.h" + +#include <QCompleter> + +CaptureFilterCombo::CaptureFilterCombo(QWidget *parent) : + QComboBox(parent), + cf_edit_(NULL) +{ + cf_edit_ = new CaptureFilterEdit(); + + setEditable(true); + setLineEdit(cf_edit_); + setSizePolicy(QSizePolicy::MinimumExpanding, QSizePolicy::Fixed); + setInsertPolicy(QComboBox::NoInsert); + setAccessibleName(tr("Capture filter selector")); + setStyleSheet( + "QComboBox {" +#ifdef Q_OS_MAC + " border: 1px solid gray;" +#else + " border: 1px solid palette(shadow);" +#endif + " border-radius: 3px;" + " padding: 0px 0px 0px 0px;" + " margin-left: 0px;" + " min-width: 20em;" + " }" + + "QComboBox::drop-down {" + " subcontrol-origin: padding;" + " subcontrol-position: top right;" + " width: 16px;" + " border-left-width: 0px;" + " }" + + "QComboBox::down-arrow {" + " image: url(:/dfilter/dfilter_dropdown.png);" + " }" + + "QComboBox::down-arrow:on { /* shift the arrow when popup is open */" + " top: 1px;" + " left: 1px;" + "}" + ); + completer()->setCompletionMode(QCompleter::PopupCompletion); + + connect(this, SIGNAL(interfacesChanged()), cf_edit_, SLOT(checkFilter())); + connect(cf_edit_, SIGNAL(pushFilterSyntaxStatus(QString&)), + this, SIGNAL(pushFilterSyntaxStatus(QString&))); + connect(cf_edit_, SIGNAL(popFilterSyntaxStatus()), + this, SIGNAL(popFilterSyntaxStatus())); + connect(cf_edit_, SIGNAL(captureFilterSyntaxChanged(bool)), + this, SIGNAL(captureFilterSyntaxChanged(bool))); + connect(cf_edit_, SIGNAL(startCapture()), this, SIGNAL(startCapture())); + connect(cf_edit_, SIGNAL(startCapture()), this, SLOT(rebuildFilterList())); + connect(wsApp, SIGNAL(appInitialized()), this, SLOT(rebuildFilterList())); + connect(wsApp, SIGNAL(preferencesChanged()), this, SLOT(rebuildFilterList())); + + rebuildFilterList(false); + clearEditText(); +} + +void CaptureFilterCombo::writeRecent(FILE *rf) { + int i; + const char *filter_str; + + for (i = 0; i < count(); i++) { + filter_str = itemText(i).toUtf8().constData(); + if(filter_str && strlen(filter_str) > 0) { + fprintf(rf, RECENT_KEY_DISPLAY_FILTER ": %s\n", filter_str); + } + } +} + +void CaptureFilterCombo::rebuildFilterList(bool insert_edit_text) +{ + GList *cfilter_list = recent_get_cfilter_list(NULL); + QString cur_filter = currentText(); + + if (insert_edit_text && !currentText().isEmpty()) { + recent_add_cfilter(NULL, currentText().toUtf8().constData()); + } + + clear(); + for (GList *li = g_list_first(cfilter_list); li != NULL; li = g_list_next(li)) { + insertItem(0, (const gchar *) li->data); + } + setCurrentText(cur_filter); +} + +/* + * 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/capture_filter_combo.h b/ui/qt/capture_filter_combo.h new file mode 100644 index 0000000000..1cfbe223ba --- /dev/null +++ b/ui/qt/capture_filter_combo.h @@ -0,0 +1,69 @@ +/* capture_filter_combo.h + * + * $Id$ + * + * 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 CAPTURE_FILTER_COMBO_H +#define CAPTURE_FILTER_COMBO_H + +#include "capture_filter_edit.h" + +#include <QComboBox> +#include <QList> + +class CaptureFilterCombo : public QComboBox +{ + Q_OBJECT +public: + explicit CaptureFilterCombo(QWidget *parent = 0); + bool addRecentCapture(const char *filter); + void writeRecent(FILE *rf); + +signals: + void interfacesChanged(); + void pushFilterSyntaxStatus(QString&); + void popFilterSyntaxStatus(); + void captureFilterSyntaxChanged(bool valid); + void startCapture(); + +public slots: + +private: + CaptureFilterEdit *cf_edit_; + +private slots: + void rebuildFilterList(bool insert_edit_text = true); +}; + +#endif // CAPTURE_FILTER_COMBO_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/capture_filter_edit.cpp b/ui/qt/capture_filter_edit.cpp new file mode 100644 index 0000000000..2f1973434a --- /dev/null +++ b/ui/qt/capture_filter_edit.cpp @@ -0,0 +1,354 @@ +/* capture_filter_edit.cpp + * + * $Id$ + * + * 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 "config.h" + +#include <glib.h> + +#include <epan/proto.h> + +#include "capture_opts.h" +#include "ui/capture_globals.h" + +#include "capture_filter_edit.h" + +#include <QPainter> +#include <QStyleOptionFrame> + +#include "ui/utf8_entities.h" +#include "qt_ui_utils.h" + +#if defined(Q_OS_MAC) && 0 +// http://developer.apple.com/library/mac/#documentation/Cocoa/Reference/ApplicationKit/Classes/NSImage_Class/Reference/Reference.html +// http://www.virtualbox.org/svn/vbox/trunk/src/VBox/Frontends/VirtualBox/src/platform/darwin/UICocoaSpecialControls.mm + +class UIMiniCancelButton: public QAbstractButton +{ + Q_OBJECT; + +public: + UIMiniCancelButton(QWidget *pParent = 0); + + void setText(const QString &strText) { m_pButton->setText(strText); } + void setToolTip(const QString &strTip) { m_pButton->setToolTip(strTip); } + void removeBorder() {} + +protected: + void paintEvent(QPaintEvent * /* pEvent */) {} + void resizeEvent(QResizeEvent *pEvent); + +private: + UICocoaButton *m_pButton; +}; + +UIMiniCancelButton::UIMiniCancelButton(QWidget *pParent /* = 0 */) + : QAbstractButton(pParent) +{ + setShortcut(QKeySequence(Qt::Key_Escape)); + m_pButton = new UICocoaButton(UICocoaButton::CancelButton, this); + connect(m_pButton, SIGNAL(clicked()), + this, SIGNAL(clicked())); + setFixedSize(m_pButton->size()); +} + +#endif + + +// XXX - We need simplified (button- and dropdown-free) versions for use in dialogs and field-only checking. + +CaptureFilterEdit::CaptureFilterEdit(QWidget *parent, bool plain) : + SyntaxLineEdit(parent), + plain_(plain), + field_name_only_(false), + apply_button_(NULL) +{ + setAccessibleName(tr("Capture filter entry")); + + empty_filter_message_ = QString(tr("Enter a capture filter %1")).arg(UTF8_HORIZONTAL_ELLIPSIS); + + // DFCombo + // Bookmark (star) + // DispalyFilterEdit + // Clear button + // Apply (right arrow) + Cancel (x) + Reload (arrowed circle) + // Combo drop-down + + // XXX - Move bookmark and apply buttons to the toolbar a la Firefox, Chrome & Safari? + // XXX - Use native buttons on OS X? + + bookmark_button_ = new QToolButton(this); + bookmark_button_->setCursor(Qt::ArrowCursor); + bookmark_button_->setStyleSheet(QString( + "QToolButton { /* all types of tool button */" + " border 0 0 0 0;" +#ifdef Q_OS_MAC + " border-right: %1px solid gray;" +#else + " border-right: %1px solid palette(shadow);" +#endif + " border-top-left-radius: 3px;" + " border-bottom-left-radius: 3px;" + " padding-left: 1px;" + " image: url(:/dfilter/dfilter_bookmark_normal.png) center;" + "}" + + "QToolButton:hover {" + " image: url(:/dfilter/dfilter_bookmark_hover.png) center;" + "}" + "QToolButton:pressed {" + " image: url(:/dfilter/dfilter_bookmark_pressed.png) center;" + "}" + "QToolButton:disabled {" + " image: url(:/dfilter/dfilter_bookmark_disabled.png) center;" + "}" + + + ).arg(plain_ ? 0 : 1) + ); + connect(bookmark_button_, SIGNAL(clicked()), this, SLOT(bookmarkClicked())); + + clear_button_ = new QToolButton(this); + clear_button_->setCursor(Qt::ArrowCursor); + clear_button_->setStyleSheet( + "QToolButton {" + " image: url(:/dfilter/dfilter_erase_normal.png) center;" + " border: none;" + " width: 16px;" + "}" + "QToolButton:hover {" + " image: url(:/dfilter/dfilter_erase_active.png) center;" + "}" + "QToolButton:pressed {" + " image: url(:/dfilter/dfilter_erase_selected.png) center;" + "}" + ); + clear_button_->hide(); + connect(clear_button_, SIGNAL(clicked()), this, SLOT(clear())); + connect(this, SIGNAL(textChanged(const QString&)), this, SLOT(checkFilter(const QString&))); + + if (!plain_) { + apply_button_ = new QToolButton(this); + apply_button_->setCursor(Qt::ArrowCursor); + apply_button_->setEnabled(false); + apply_button_->setStyleSheet( + "QToolButton { /* all types of tool button */" + " border 0 0 0 0;" + " border-top-right-radius: 3px;" + " border-bottom-right-radius: 3px;" + " padding-right: 1px;" + " image: url(:/dfilter/dfilter_apply_normal.png) center;" + "}" + + "QToolButton:hover {" + " image: url(:/dfilter/dfilter_apply_hover.png) center;" + "}" + "QToolButton:pressed {" + " image: url(:/dfilter/dfilter_apply_pressed.png) center;" + "}" + "QToolButton:disabled {" + " image: url(:/dfilter/dfilter_apply_disabled.png) center;" + "}" + ); + connect(apply_button_, SIGNAL(clicked()), this, SLOT(applyCaptureFilter())); + connect(this, SIGNAL(returnPressed()), this, SLOT(applyCaptureFilter())); + } + + int frameWidth = style()->pixelMetric(QStyle::PM_DefaultFrameWidth); + QSize bksz = bookmark_button_->sizeHint(); + QSize cbsz = clear_button_->sizeHint(); + QSize apsz; + if (apply_button_) { + apsz = apply_button_->sizeHint(); + } else { + apsz.setHeight(0); apsz.setWidth(0); + } + setStyleSheet(QString( + "CaptureFilterEdit {" + " padding-left: %1px;" + " margin-left: %2px;" + " margin-right: %3px;" + "}" + ) + .arg(frameWidth + 1) + .arg(bksz.width()) + .arg(cbsz.width() + apsz.width() + frameWidth + 1) + ); + + QThread *syntax_thread = new QThread; + syntax_worker_ = new CaptureFilterSyntaxWorker; + syntax_worker_->moveToThread(syntax_thread); + connect(syntax_thread, SIGNAL(started()), syntax_worker_, SLOT(start())); + connect(syntax_thread, SIGNAL(started()), this, SLOT(checkFilter())); + connect(syntax_worker_, SIGNAL(syntaxResult(QString,bool,QString)), + this, SLOT(setFilterSyntaxState(QString,bool,QString))); + connect(syntax_thread, SIGNAL(finished()), syntax_worker_, SLOT(deleteLater())); + syntax_thread->start(); + + setText(global_capture_opts.default_options.cfilter); +} + +void CaptureFilterEdit::paintEvent(QPaintEvent *evt) { + SyntaxLineEdit::paintEvent(evt); + + // http://wiki.forum.nokia.com/index.php/Custom_QLineEdit + if (text().isEmpty() && ! this->hasFocus()) { + QPainter p(this); + QFont f = font(); + f.setItalic(true); + p.setFont(f); + + QColor color(palette().color(foregroundRole())); + color.setAlphaF(0.5); + p.setPen(color); + + QStyleOptionFrame opt; + initStyleOption(&opt); + QRect cr = style()->subElementRect(QStyle::SE_LineEditContents, &opt, this); + cr.setLeft(cr.left() + 2); + cr.setRight(cr.right() - 2); + + p.drawText(cr, Qt::AlignLeft|Qt::AlignVCenter, empty_filter_message_); + } + // else check filter syntax and set the background accordingly + // XXX - Should we add little warning/error icons as well? +} + +void CaptureFilterEdit::resizeEvent(QResizeEvent *) +{ + QSize cbsz = clear_button_->sizeHint(); + QSize apsz; + if (apply_button_) { + apsz = apply_button_->sizeHint(); + } else { + apsz.setHeight(0); apsz.setWidth(0); + } + int frameWidth = style()->pixelMetric(QStyle::PM_DefaultFrameWidth); + clear_button_->move(contentsRect().right() - frameWidth - cbsz.width() - apsz.width(), + contentsRect().top()); + clear_button_->setMaximumHeight(contentsRect().height()); + if (apply_button_) { + apply_button_->move(contentsRect().right() - frameWidth - apsz.width(), + contentsRect().top()); + apply_button_->setMaximumHeight(contentsRect().height()); + } + bookmark_button_->setMaximumHeight(contentsRect().height()); +} + +void CaptureFilterEdit::checkFilter(const QString& text) +{ + setSyntaxState(Empty); + popFilterSyntaxStatus(); + bool empty = text.isEmpty(); + + bookmark_button_->setEnabled(false); + if (apply_button_) { + apply_button_->setEnabled(false); + } + + if (empty) { + clear_button_->setVisible(false); + setFilterSyntaxState(text, true, QString()); + } else { + clear_button_->setVisible(true); + syntax_worker_->checkFilter(text); + } +} + +void CaptureFilterEdit::checkFilter() +{ + checkFilter(text()); +} + +void CaptureFilterEdit::setFilterSyntaxState(QString filter, bool valid, QString err_msg) +{ + if (filter.compare(text()) == 0) { // The user hasn't changed the filter + if (valid) { + setSyntaxState(text().isEmpty() ? Empty : Valid); + } else { + setSyntaxState(Invalid); + emit pushFilterSyntaxStatus(err_msg); + } + } + + if (syntaxState() != Invalid) { + bookmark_button_->setEnabled(true); + if (apply_button_) { + apply_button_->setEnabled(true); + } + valid = true; + g_free(global_capture_opts.default_options.cfilter); + if (filter.isEmpty()) { + global_capture_opts.default_options.cfilter = NULL; + } else { + global_capture_opts.default_options.cfilter = qstring_strdup(filter); + } + + if (global_capture_opts.num_selected > 0) { + interface_t device; + + for (guint i = 0; i < global_capture_opts.all_ifaces->len; i++) { + device = g_array_index(global_capture_opts.all_ifaces, interface_t, i); + if (!device.selected) { + continue; + } +// if (device.active_dlt == -1) { +// simple_dialog(ESD_TYPE_ERROR, ESD_BTN_OK, "The link type of interface %s was not specified.", device.name); +// continue; /* Programming error: somehow managed to select an "unsupported" entry */ +// } + g_array_remove_index(global_capture_opts.all_ifaces, i); + device.cfilter = qstring_strdup(filter); + g_array_insert_val(global_capture_opts.all_ifaces, i, device); +// update_filter_string(device.name, filter_text); + } + } + } + + emit captureFilterSyntaxChanged(valid); +} + +void CaptureFilterEdit::bookmarkClicked() +{ + emit addBookmark(text()); +} + +void CaptureFilterEdit::applyCaptureFilter() +{ + if (syntaxState() == Invalid) { + return; + } + + emit startCapture(); +} + +/* + * 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/capture_filter_edit.h b/ui/qt/capture_filter_edit.h new file mode 100644 index 0000000000..c402393704 --- /dev/null +++ b/ui/qt/capture_filter_edit.h @@ -0,0 +1,84 @@ +/* capture_filter_edit.h + * + * $Id$ + * + * 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 CAPTURE_FILTER_EDIT_H +#define CAPTURE_FILTER_EDIT_H + +#include <QThread> +#include <QToolButton> +#include "syntax_line_edit.h" +#include "capture_filter_syntax_worker.h" + +class CaptureFilterEdit : public SyntaxLineEdit +{ + Q_OBJECT +public: + explicit CaptureFilterEdit(QWidget *parent = 0, bool plain = false); + +protected: + void paintEvent(QPaintEvent *evt); + void resizeEvent(QResizeEvent *); +// void focusInEvent(QFocusEvent *evt); +// void focusOutEvent(QFocusEvent *evt); + +public slots: + void checkFilter(); + +private slots: + void applyCaptureFilter(); + void checkFilter(const QString &text); + void setFilterSyntaxState(QString filter, bool valid, QString err_msg); + void bookmarkClicked(); + +private: + bool plain_; + bool field_name_only_; + QString empty_filter_message_; + QToolButton *bookmark_button_; + QToolButton *clear_button_; + QToolButton *apply_button_; + CaptureFilterSyntaxWorker *syntax_worker_; + +signals: + void pushFilterSyntaxStatus(QString&); + void popFilterSyntaxStatus(); + void captureFilterSyntaxChanged(bool valid); + void startCapture(); + void addBookmark(QString filter); + +}; + +#endif // CAPTURE_FILTER_EDIT_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/capture_filter_syntax_worker.cpp b/ui/qt/capture_filter_syntax_worker.cpp new file mode 100644 index 0000000000..a0ff63ca22 --- /dev/null +++ b/ui/qt/capture_filter_syntax_worker.cpp @@ -0,0 +1,141 @@ +/* capture_filter_syntax_worker.cpp + * + * $Id$ + * + * 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 "config.h" + +#ifdef HAVE_LIBPCAP +#include <glib.h> +#include <pcap.h> +#include "capture_opts.h" +#include "ui/capture_globals.h" +#endif + +#include "capture_filter_syntax_worker.h" + +#include <QMutexLocker> +#include <QSet> + +// Must be global +static QMutex pcap_compile_mtx_; + +#if 0 +#include <QDebug> +#include <QThread> +#define DEBUG_SYNTAX_CHECK(state1, state2) qDebug() << "CF state" << QThread::currentThreadId() << state1 << "->" << state2 << ":" << filter_text_ << ":" << filter +#else +#define DEBUG_SYNTAX_CHECK(state1, state2) +#endif + +#define DUMMY_SNAPLENGTH 65535 +#define DUMMY_NETMASK 0xFF000000 + +void CaptureFilterSyntaxWorker::start() { +#ifdef HAVE_LIBPCAP + forever { + QString filter; + QSet<gint> active_dlts; + struct bpf_program fcode; + pcap_t *pd; + int pc_err; + bool ok = true; + QString err_str; + + data_mtx_.lock(); + while (filter_text_.isEmpty()) { + data_cond_.wait(&data_mtx_); + } + + DEBUG_SYNTAX_CHECK("pending", "unknown"); + filter = filter_text_; + filter_text_ = QString(); + data_mtx_.unlock(); + + if (global_capture_opts.all_ifaces->len < 1) { + emit syntaxResult(filter, false, QString("No interfaces selected")); + DEBUG_SYNTAX_CHECK("unknown", "no interfaces"); + continue; + } + + for (guint if_idx = 0; if_idx < global_capture_opts.all_ifaces->len; if_idx++) { + interface_t device; + + device = g_array_index(global_capture_opts.all_ifaces, interface_t, if_idx); + if (!device.locked && device.selected) { + active_dlts.insert(device.active_dlt); + } + } + + foreach (gint dlt, active_dlts.toList()) { + pcap_compile_mtx_.lock(); + pd = pcap_open_dead(dlt, DUMMY_SNAPLENGTH); +#ifdef PCAP_NETMASK_UNKNOWN + pc_err = pcap_compile(pd, &fcode, filter.toUtf8().constData(), 1 /* Do optimize */, PCAP_NETMASK_UNKNOWN); +#else + pc_err = pcap_compile(pd, &fcode, filter.toUtf8().constData(), 1 /* Do optimize */, 0); +#endif + + if (pc_err) { + DEBUG_SYNTAX_CHECK("unknown", "known bad"); + ok = false; + err_str = pcap_geterr(pd); + } else { + DEBUG_SYNTAX_CHECK("unknown", "known good"); + } + pcap_close(pd); + + pcap_compile_mtx_.unlock(); + + if (!ok) break; + } + emit syntaxResult(filter, ok, err_str); + + DEBUG_SYNTAX_CHECK("known", "idle"); + } +#endif // HAVE_LIBPCAP +} + +void CaptureFilterSyntaxWorker::checkFilter(const QString &filter) +{ +#ifdef HAVE_LIBPCAP + QMutexLocker ml(&data_mtx_); + /* Ruthlessly clobber the current state. */ + filter_text_ = filter; + DEBUG_SYNTAX_CHECK("received", "?"); + data_cond_.wakeOne(); +#else + emit syntaxResult(filter, true, QString("Syntax checking unavailable")); +#endif // HAVE_LIBPCAP +} + +/* + * 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/capture_filter_syntax_worker.h b/ui/qt/capture_filter_syntax_worker.h new file mode 100644 index 0000000000..58e7646ba4 --- /dev/null +++ b/ui/qt/capture_filter_syntax_worker.h @@ -0,0 +1,64 @@ +/* capture_filter_syntax_worker.h + * + * $Id$ + * + * 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 CAPTURE_FILTER_SYNTAX_WORKER_H +#define CAPTURE_FILTER_SYNTAX_WORKER_H + +#include <QMutex> +#include <QObject> +#include <QWaitCondition> + +class CaptureFilterSyntaxWorker : public QObject +{ + Q_OBJECT + +public: + CaptureFilterSyntaxWorker(QObject *parent = 0) : QObject(parent) {} + void checkFilter(const QString &filter); + +public slots: + void start(); + +private: + QMutex data_mtx_; + QWaitCondition data_cond_; + QString filter_text_; + +signals: + void syntaxResult(QString filter, bool valid, QString err_msg); +}; + +#endif // CAPTURE_FILTER_SYNTAX_WORKER_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/label_stack.cpp b/ui/qt/label_stack.cpp index edb5c1460a..adc87da118 100644 --- a/ui/qt/label_stack.cpp +++ b/ui/qt/label_stack.cpp @@ -45,7 +45,7 @@ LabelStack::LabelStack(QWidget *parent) : connect(&temporary_timer_, SIGNAL(timeout()), this, SLOT(updateTemporaryStatus())); } -void LabelStack::setTemporaryContext(int ctx) { +void LabelStack::setTemporaryContext(const int ctx) { temporary_ctx_ = ctx; } diff --git a/ui/qt/label_stack.h b/ui/qt/label_stack.h index c0c1ade21c..bc2f754e8d 100644 --- a/ui/qt/label_stack.h +++ b/ui/qt/label_stack.h @@ -34,7 +34,7 @@ class LabelStack : public QLabel Q_OBJECT public: explicit LabelStack(QWidget *parent = 0); - void setTemporaryContext(int ctx); + void setTemporaryContext(const int ctx); void pushText(QString &text, int ctx); protected: diff --git a/ui/qt/main_welcome.cpp b/ui/qt/main_welcome.cpp index 04fa37a4e8..60ae7d4191 100644 --- a/ui/qt/main_welcome.cpp +++ b/ui/qt/main_welcome.cpp @@ -140,6 +140,16 @@ MainWelcome::MainWelcome(QWidget *parent) : connect(task_list_, SIGNAL(itemSelectionChanged()), this, SLOT(showTask())); connect(welcome_ui_->interfaceTree, SIGNAL(itemDoubleClicked(QTreeWidgetItem*,int)), this, SLOT(interfaceDoubleClicked(QTreeWidgetItem*,int))); + connect(welcome_ui_->interfaceTree, SIGNAL(interfaceUpdated(const char*,bool)), + welcome_ui_->captureFilterComboBox, SIGNAL(interfacesChanged())); + connect(welcome_ui_->captureFilterComboBox, SIGNAL(pushFilterSyntaxStatus(QString&)), + this, SIGNAL(pushFilterSyntaxStatus(QString&))); + connect(welcome_ui_->captureFilterComboBox, SIGNAL(popFilterSyntaxStatus()), + this, SIGNAL(popFilterSyntaxStatus())); + connect(welcome_ui_->captureFilterComboBox, SIGNAL(captureFilterSyntaxChanged(bool)), + this, SIGNAL(captureFilterSyntaxChanged(bool))); + connect(welcome_ui_->captureFilterComboBox, SIGNAL(startCapture()), + this, SIGNAL(startCapture())); connect(recent_files_, SIGNAL(itemActivated(QListWidgetItem *)), this, SLOT(openRecentItem(QListWidgetItem *))); updateRecentFiles(); diff --git a/ui/qt/main_welcome.h b/ui/qt/main_welcome.h index 9fe7f07c8d..4e0851ee08 100644 --- a/ui/qt/main_welcome.h +++ b/ui/qt/main_welcome.h @@ -57,6 +57,9 @@ private: signals: void startCapture(); void recentFileActivated(QString& cfile); + void pushFilterSyntaxStatus(QString&); + void popFilterSyntaxStatus(); + void captureFilterSyntaxChanged(bool valid); private slots: void destroySplashOverlay(); diff --git a/ui/qt/main_welcome.ui b/ui/qt/main_welcome.ui index 284d4bcb5c..c9044a8dc6 100644 --- a/ui/qt/main_welcome.ui +++ b/ui/qt/main_welcome.ui @@ -36,35 +36,88 @@ <property name="currentIndex"> <number>0</number> </property> - <widget class="InterfaceTree" name="interfaceTree"> - <property name="sizePolicy"> - <sizepolicy hsizetype="MinimumExpanding" vsizetype="Expanding"> - <horstretch>0</horstretch> - <verstretch>0</verstretch> - </sizepolicy> - </property> - <property name="horizontalScrollBarPolicy"> - <enum>Qt::ScrollBarAlwaysOff</enum> - </property> - <property name="uniformRowHeights"> - <bool>true</bool> - </property> - <property name="columnCount"> - <number>2</number> - </property> - <attribute name="headerVisible"> - <bool>false</bool> - </attribute> - <column> - <property name="text"> - <string notr="true">1</string> + <widget class="QWidget" name="captureContainer"> + <layout class="QVBoxLayout" name="verticalLayout_3"> + <property name="leftMargin"> + <number>0</number> + </property> + <property name="topMargin"> + <number>0</number> </property> - </column> - <column> - <property name="text"> - <string notr="true">2</string> + <property name="rightMargin"> + <number>0</number> </property> - </column> + <property name="bottomMargin"> + <number>0</number> + </property> + <item> + <widget class="QWidget" name="captureFilterLayout" native="true"> + <layout class="QHBoxLayout" name="horizontalLayout" stretch="0,0"> + <property name="leftMargin"> + <number>0</number> + </property> + <property name="topMargin"> + <number>0</number> + </property> + <property name="rightMargin"> + <number>0</number> + </property> + <item> + <widget class="QLabel" name="label"> + <property name="text"> + <string>Capture filter:</string> + </property> + </widget> + </item> + <item> + <widget class="CaptureFilterCombo" name="captureFilterComboBox"> + <property name="sizePolicy"> + <sizepolicy hsizetype="MinimumExpanding" vsizetype="Fixed"> + <horstretch>0</horstretch> + <verstretch>0</verstretch> + </sizepolicy> + </property> + <property name="editable"> + <bool>true</bool> + </property> + </widget> + </item> + </layout> + </widget> + </item> + <item> + <widget class="InterfaceTree" name="interfaceTree"> + <property name="sizePolicy"> + <sizepolicy hsizetype="MinimumExpanding" vsizetype="Expanding"> + <horstretch>0</horstretch> + <verstretch>0</verstretch> + </sizepolicy> + </property> + <property name="horizontalScrollBarPolicy"> + <enum>Qt::ScrollBarAlwaysOff</enum> + </property> + <property name="uniformRowHeights"> + <bool>true</bool> + </property> + <property name="columnCount"> + <number>2</number> + </property> + <attribute name="headerVisible"> + <bool>false</bool> + </attribute> + <column> + <property name="text"> + <string notr="true">1</string> + </property> + </column> + <column> + <property name="text"> + <string notr="true">2</string> + </property> + </column> + </widget> + </item> + </layout> </widget> <widget class="QListWidget" name="recentList"> <property name="sizePolicy"> @@ -153,6 +206,11 @@ more about Wireshark</string> <extends>QTreeWidget</extends> <header>interface_tree.h</header> </customwidget> + <customwidget> + <class>CaptureFilterCombo</class> + <extends>QComboBox</extends> + <header>capture_filter_combo.h</header> + </customwidget> </customwidgets> <resources/> <connections/> diff --git a/ui/qt/main_window.cpp b/ui/qt/main_window.cpp index 119f77a7f9..a06c2b4367 100644 --- a/ui/qt/main_window.cpp +++ b/ui/qt/main_window.cpp @@ -82,6 +82,7 @@ MainWindow::MainWindow(QWidget *parent) : cap_file_(NULL), previous_focus_(NULL), capture_stopping_(false), + capture_filter_valid_(false), #ifdef _WIN32 pipe_timer_(NULL) #else @@ -112,7 +113,8 @@ MainWindow::MainWindow(QWidget *parent) : const DisplayFilterEdit *df_edit = dynamic_cast<DisplayFilterEdit *>(df_combo_box_->lineEdit()); connect(df_edit, SIGNAL(pushFilterSyntaxStatus(QString&)), main_ui_->statusBar, SLOT(pushFilterStatus(QString&))); connect(df_edit, SIGNAL(popFilterSyntaxStatus()), main_ui_->statusBar, SLOT(popFilterStatus())); - connect(df_edit, SIGNAL(pushFilterSyntaxWarning(QString&)), main_ui_->statusBar, SLOT(pushTemporaryStatus(QString&))); + connect(df_edit, SIGNAL(pushFilterSyntaxWarning(QString&)), + main_ui_->statusBar, SLOT(pushTemporaryStatus(QString&))); connect(df_edit, SIGNAL(filterPackets(QString&,bool)), this, SLOT(filterPackets(QString&,bool))); connect(df_edit, SIGNAL(addBookmark(QString)), this, SLOT(addDisplayFilterButton(QString))); connect(this, SIGNAL(displayFilterSuccess(bool)), df_edit, SLOT(displayFilterSuccess(bool))); @@ -231,6 +233,10 @@ MainWindow::MainWindow(QWidget *parent) : this, SLOT(startCapture())); connect(main_welcome_, SIGNAL(recentFileActivated(QString&)), this, SLOT(openCaptureFile(QString&))); + connect(main_welcome_, SIGNAL(pushFilterSyntaxStatus(QString&)), + main_ui_->statusBar, SLOT(pushFilterStatus(QString&))); + connect(main_welcome_, SIGNAL(popFilterSyntaxStatus()), + main_ui_->statusBar, SLOT(popFilterStatus())); connect(this, SIGNAL(setCaptureFile(capture_file*)), main_ui_->searchFrame, SLOT(setCaptureFile(capture_file*))); @@ -276,6 +282,9 @@ MainWindow::MainWindow(QWidget *parent) : connect(iface_tree, SIGNAL(itemSelectionChanged()), this, SLOT(interfaceSelectionChanged())); } + connect(main_ui_->welcomePage, SIGNAL(captureFilterSyntaxChanged(bool)), + this, SLOT(captureFilterSyntaxChanged(bool))); + main_ui_->mainStack->setCurrentWidget(main_welcome_); } diff --git a/ui/qt/main_window.h b/ui/qt/main_window.h index 75a96a9a85..efce801bff 100644 --- a/ui/qt/main_window.h +++ b/ui/qt/main_window.h @@ -104,6 +104,7 @@ private: FileSetDialog file_set_dialog_; SummaryDialog summary_dialog_; bool capture_stopping_; + bool capture_filter_valid_; // Pipe input gint pipe_source_; @@ -181,6 +182,7 @@ private slots: void setMenusForSelectedPacket(); void setMenusForSelectedTreeRow(field_info *fi = NULL); void interfaceSelectionChanged(); + void captureFilterSyntaxChanged(bool valid); void redissectPackets(); void recreatePacketList(); diff --git a/ui/qt/main_window_slots.cpp b/ui/qt/main_window_slots.cpp index cf4d2881dc..11e3bcdf19 100644 --- a/ui/qt/main_window_slots.cpp +++ b/ui/qt/main_window_slots.cpp @@ -422,6 +422,15 @@ void MainWindow::startCapture() { return; } + // Ideally we should have disabled the start capture + // toolbar buttons and menu items. This may not be the + // case, e.g. with QtMacExtras. + if(!capture_filter_valid_) { + QString msg = QString("Invalid capture filter"); + main_ui_->statusBar->pushTemporaryStatus(msg); + return; + } + /* XXX - we might need to init other pref data as well... */ // main_auto_scroll_live_changed(auto_scroll_live); @@ -949,13 +958,21 @@ void MainWindow::setMenusForSelectedTreeRow(field_info *fi) { void MainWindow::interfaceSelectionChanged() { - if (global_capture_opts.num_selected > 0) { + // XXX This doesn't disable the toolbar button when using + // QtMacExtras. + if (global_capture_opts.num_selected > 0 && capture_filter_valid_) { main_ui_->actionStartCapture->setEnabled(true); } else { main_ui_->actionStartCapture->setEnabled(false); } } +void MainWindow::captureFilterSyntaxChanged(bool valid) +{ + capture_filter_valid_ = valid; + interfaceSelectionChanged(); +} + void MainWindow::redissectPackets() { if (cap_file_) diff --git a/ui/qt/recent_file_status.cpp b/ui/qt/recent_file_status.cpp index 0da8c23340..28ba973dd5 100644 --- a/ui/qt/recent_file_status.cpp +++ b/ui/qt/recent_file_status.cpp @@ -27,20 +27,20 @@ // Sigh. The Qt 4 documentation says we should subclass QThread here. Other sources // insist that we should subclass QObject, then move it to a newly created QThread. -RecentFileStatus::RecentFileStatus(const QString &filename, QObject *parent) : - QObject(parent), m_filename(filename), m_size(0) -{ -} +//RecentFileStatus::RecentFileStatus(const QString &filename, QObject *parent) : +// QObject(parent), filename_(filename), size_(0) +//{ +//} void RecentFileStatus::start(void) { QFileInfo fi; - fi.setFile(m_filename); + fi.setFile(filename_); if (fi.isFile() && fi.isReadable()) { - emit statusFound(m_filename, fi.size(), true); + emit statusFound(filename_, fi.size(), true); } else { - emit statusFound(m_filename, 0, false); + emit statusFound(filename_, 0, false); } } diff --git a/ui/qt/recent_file_status.h b/ui/qt/recent_file_status.h index 6483cfa198..c284ea56ba 100644 --- a/ui/qt/recent_file_status.h +++ b/ui/qt/recent_file_status.h @@ -30,15 +30,16 @@ class RecentFileStatus : public QObject { Q_OBJECT public: - RecentFileStatus(const QString &filename, QObject *parent = 0); + RecentFileStatus(const QString &filename, QObject *parent = 0) : + QObject(parent), filename_(filename), size_(0) {} - QString getFilename() const { return (m_filename); } - size_t getSize() const { return (m_size); } + QString getFilename() const { return (filename_); } + size_t getSize() const { return (size_); } void quit() { emit finished(); } private: - QString m_filename; - size_t m_size; + QString filename_; + size_t size_; signals: void statusFound(const QString &filename = *new QString(), qint64 size = 0, bool accessible = false); diff --git a/ui/qt/wireshark_application.cpp b/ui/qt/wireshark_application.cpp index 4f3f8ef018..66a8b762d1 100644 --- a/ui/qt/wireshark_application.cpp +++ b/ui/qt/wireshark_application.cpp @@ -181,7 +181,6 @@ void WiresharkApplication::refreshRecentFiles(void) { connect(rf_status, SIGNAL(statusFound(QString, qint64, bool)), this, SLOT(itemStatusFinished(QString, qint64, bool))); connect(rf_status, SIGNAL(finished()), rf_thread, SLOT(quit())); connect(rf_status, SIGNAL(finished()), rf_status, SLOT(deleteLater())); -// connect(rf_status, SIGNAL(finished()), rf_thread, SLOT(deleteLater())); rf_thread->start(); } |