2013-08-08 00:26:57 +00:00
|
|
|
/* capture_filter_combo.cpp
|
|
|
|
*
|
|
|
|
* Wireshark - Network traffic analyzer
|
|
|
|
* By Gerald Combs <gerald@wireshark.org>
|
|
|
|
* Copyright 1998 Gerald Combs
|
|
|
|
*
|
2018-04-30 07:47:58 +00:00
|
|
|
* SPDX-License-Identifier: GPL-2.0-or-later
|
|
|
|
*/
|
2013-08-08 00:26:57 +00:00
|
|
|
|
|
|
|
#include <stdio.h>
|
|
|
|
|
2017-07-25 14:15:18 +00:00
|
|
|
#include <ui/qt/utils/qt_ui_utils.h>
|
2013-08-08 00:26:57 +00:00
|
|
|
#include "ui/recent_utils.h"
|
|
|
|
#include "ui/recent.h"
|
|
|
|
|
|
|
|
#include <epan/prefs.h>
|
|
|
|
|
2017-07-25 14:15:18 +00:00
|
|
|
#include <ui/qt/widgets/capture_filter_combo.h>
|
2019-06-21 22:06:33 +00:00
|
|
|
#include <ui/qt/utils/color_utils.h>
|
2013-08-08 00:26:57 +00:00
|
|
|
#include "wireshark_application.h"
|
|
|
|
|
2016-01-29 06:55:03 +00:00
|
|
|
CaptureFilterCombo::CaptureFilterCombo(QWidget *parent, bool plain) :
|
2013-08-08 00:26:57 +00:00
|
|
|
QComboBox(parent),
|
|
|
|
cf_edit_(NULL)
|
|
|
|
{
|
2016-01-29 06:55:03 +00:00
|
|
|
cf_edit_ = new CaptureFilterEdit(this, plain);
|
2013-08-08 00:26:57 +00:00
|
|
|
|
|
|
|
setEditable(true);
|
2015-05-19 17:18:54 +00:00
|
|
|
// Enabling autocompletion here gives us two simultaneous completions:
|
|
|
|
// Inline (highlighted text) for entire filters, handled here and popup
|
|
|
|
// completion for fields handled by CaptureFilterEdit.
|
|
|
|
setAutoCompletion(false);
|
2013-08-08 00:26:57 +00:00
|
|
|
setLineEdit(cf_edit_);
|
2018-05-21 22:47:21 +00:00
|
|
|
// Default is Preferred.
|
|
|
|
setSizePolicy(QSizePolicy::MinimumExpanding, sizePolicy().verticalPolicy());
|
2013-08-08 00:26:57 +00:00
|
|
|
setInsertPolicy(QComboBox::NoInsert);
|
|
|
|
setAccessibleName(tr("Capture filter selector"));
|
2019-06-21 22:06:33 +00:00
|
|
|
updateStyleSheet();
|
2013-08-08 00:26:57 +00:00
|
|
|
|
2018-12-24 17:11:20 +00:00
|
|
|
connect(this, &CaptureFilterCombo::interfacesChanged, cf_edit_,
|
|
|
|
static_cast<void (CaptureFilterEdit::*)()>(&CaptureFilterEdit::checkFilter));
|
|
|
|
connect(cf_edit_, &CaptureFilterEdit::pushFilterSyntaxStatus,
|
|
|
|
this, &CaptureFilterCombo::pushFilterSyntaxStatus);
|
|
|
|
connect(cf_edit_, &CaptureFilterEdit::popFilterSyntaxStatus,
|
|
|
|
this, &CaptureFilterCombo::popFilterSyntaxStatus);
|
|
|
|
connect(cf_edit_, &CaptureFilterEdit::captureFilterSyntaxChanged,
|
|
|
|
this, &CaptureFilterCombo::captureFilterSyntaxChanged);
|
|
|
|
connect(cf_edit_, &CaptureFilterEdit::startCapture, this, &CaptureFilterCombo::startCapture);
|
|
|
|
connect(cf_edit_, &CaptureFilterEdit::startCapture, this, &CaptureFilterCombo::saveAndRebuildFilterList);
|
|
|
|
connect(wsApp, &WiresharkApplication::appInitialized, this, &CaptureFilterCombo::rebuildFilterList);
|
|
|
|
connect(wsApp, &WiresharkApplication::preferencesChanged, this, &CaptureFilterCombo::rebuildFilterList);
|
2013-08-08 00:26:57 +00:00
|
|
|
|
2016-06-12 22:10:02 +00:00
|
|
|
rebuildFilterList();
|
2013-08-08 00:26:57 +00:00
|
|
|
clearEditText();
|
|
|
|
}
|
|
|
|
|
2016-09-02 12:10:31 +00:00
|
|
|
void CaptureFilterCombo::writeRecent(FILE *rf)
|
|
|
|
{
|
2013-08-08 00:26:57 +00:00
|
|
|
int i;
|
|
|
|
|
|
|
|
for (i = 0; i < count(); i++) {
|
2014-11-29 18:29:26 +00:00
|
|
|
const QByteArray& filter = itemText(i).toUtf8();
|
|
|
|
if (!filter.isEmpty()) {
|
|
|
|
fprintf(rf, RECENT_KEY_DISPLAY_FILTER ": %s\n", filter.constData());
|
2013-08-08 00:26:57 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-06-21 22:06:33 +00:00
|
|
|
bool CaptureFilterCombo::event(QEvent *event)
|
|
|
|
{
|
|
|
|
switch (event->type()) {
|
|
|
|
case QEvent::PaletteChange:
|
|
|
|
updateStyleSheet();
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
return QComboBox::event(event);
|
|
|
|
}
|
|
|
|
|
|
|
|
void CaptureFilterCombo::updateStyleSheet()
|
|
|
|
{
|
|
|
|
const char *display_mode = ColorUtils::themeIsDark() ? "dark" : "light";
|
|
|
|
|
|
|
|
QString ss = QString(
|
|
|
|
"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(:/stock_icons/14x14/x-filter-dropdown.%1.png);"
|
|
|
|
" }"
|
|
|
|
|
|
|
|
"QComboBox::down-arrow:on { /* shift the arrow when popup is open */"
|
|
|
|
" top: 1px;"
|
|
|
|
" left: 1px;"
|
|
|
|
"}"
|
|
|
|
).arg(display_mode);
|
|
|
|
setStyleSheet(ss);
|
|
|
|
}
|
|
|
|
|
2016-03-31 21:20:26 +00:00
|
|
|
void CaptureFilterCombo::saveAndRebuildFilterList()
|
2013-08-08 00:26:57 +00:00
|
|
|
{
|
2016-03-31 21:20:26 +00:00
|
|
|
if (!currentText().isEmpty()) {
|
2013-08-08 00:26:57 +00:00
|
|
|
recent_add_cfilter(NULL, currentText().toUtf8().constData());
|
|
|
|
}
|
2016-03-31 21:20:26 +00:00
|
|
|
rebuildFilterList();
|
|
|
|
}
|
2016-09-02 12:10:31 +00:00
|
|
|
|
2016-03-31 21:20:26 +00:00
|
|
|
void CaptureFilterCombo::rebuildFilterList()
|
|
|
|
{
|
2014-09-26 15:30:44 +00:00
|
|
|
lineEdit()->blockSignals(true);
|
2016-03-31 21:20:26 +00:00
|
|
|
GList *cfilter_list = recent_get_cfilter_list(NULL);
|
2016-09-02 12:10:31 +00:00
|
|
|
QString cur_filter = currentText();
|
2013-08-08 00:26:57 +00:00
|
|
|
clear();
|
|
|
|
for (GList *li = g_list_first(cfilter_list); li != NULL; li = g_list_next(li)) {
|
|
|
|
insertItem(0, (const gchar *) li->data);
|
|
|
|
}
|
2016-09-02 12:10:31 +00:00
|
|
|
lineEdit()->setText(cur_filter);
|
2014-09-26 15:30:44 +00:00
|
|
|
lineEdit()->blockSignals(false);
|
2013-08-08 00:26:57 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* 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:
|
|
|
|
*/
|