diff options
author | Gerald Combs <gerald@wireshark.org> | 2016-02-23 10:04:16 -0800 |
---|---|---|
committer | Gerald Combs <gerald@wireshark.org> | 2016-02-26 17:28:04 +0000 |
commit | 070fc33e8501168debf879b9068da5da8e6445d6 (patch) | |
tree | b502f9c492f44ffe73f386dfdf9ea584f1178729 /ui/qt/capture_interfaces_dialog.cpp | |
parent | 10358a2f14a69fbbf0e3042429399e4934a79674 (diff) |
Qt: Update selected interface filter behavior.
Change the selected interface behavior in the main window and the
capture interfaces dialog to better handle multiple selections. Attempt
to document this at the top of interface_tree.cpp.
Move the default capture filter code from CaptureFilterEdit to
MainWelcome. Add a "conflicting filter" check to CaptureEdit which
updates the placeholder text.
Handle conflicting filters in the main welcome screen and the capture
interfaces dialog. Propagate interface selections and filter updates in
the capture interfaces dialog to the main welcome screen.
Consolidate some of the interface handling code in InterfaceTree and
CaptureInterfacesDialog.
Make sure CaptureInterfacesDialog manages the global capture options by
device name instead numeric index.
Start deprecating prefs.capture_devices_filter and
capture_dev_user_cfilter_find.
Change some member function names so that they're hopefully more clear
and consistent.
Ping-Bug: 11886
Change-Id: I63b06dbae29c2c45ee9252092ad54bdcbacae6e6
Reviewed-on: https://code.wireshark.org/review/14129
Petri-Dish: Gerald Combs <gerald@wireshark.org>
Reviewed-by: Stig Bjørlykke <stig@bjorlykke.org>
Tested-by: Petri Dish Buildbot <buildbot-no-reply@wireshark.org>
Reviewed-by: Gerald Combs <gerald@wireshark.org>
Diffstat (limited to 'ui/qt/capture_interfaces_dialog.cpp')
-rw-r--r-- | ui/qt/capture_interfaces_dialog.cpp | 189 |
1 files changed, 85 insertions, 104 deletions
diff --git a/ui/qt/capture_interfaces_dialog.cpp b/ui/qt/capture_interfaces_dialog.cpp index 82acc44131..d0c6e5a570 100644 --- a/ui/qt/capture_interfaces_dialog.cpp +++ b/ui/qt/capture_interfaces_dialog.cpp @@ -152,16 +152,19 @@ CaptureInterfacesDialog::CaptureInterfacesDialog(QWidget *parent) : ui->filenameLineEdit->setPlaceholderText(tr("Leave blank to use a temporary file")); #endif - connect(ui->interfaceTree,SIGNAL(itemClicked(QTreeWidgetItem*,int)),this,SLOT(interfaceClicked(QTreeWidgetItem*,int))); - connect(ui->interfaceTree, SIGNAL(itemSelectionChanged()), this, SLOT(interfaceSelected())); + // Changes in interface selections or capture filters should be propagated + // to the main welcome screen where they will be applied to the global + // capture options. + connect(this, SIGNAL(interfacesChanged()), ui->captureFilterComboBox, SIGNAL(interfacesChanged())); connect(ui->captureFilterComboBox, SIGNAL(captureFilterSyntaxChanged(bool)), this, SLOT(updateWidgets())); connect(ui->captureFilterComboBox->lineEdit(), SIGNAL(textEdited(QString)), this, SLOT(filterEdited())); - connect(ui->captureFilterComboBox, SIGNAL(activated(QString)), - this, SLOT(filterEdited())); + connect(ui->captureFilterComboBox->lineEdit(), SIGNAL(textEdited(QString)), + this, SIGNAL(captureFilterTextEdited(QString))); connect(&interface_item_delegate_, SIGNAL(filterChanged(QString)), ui->captureFilterComboBox->lineEdit(), SLOT(setText(QString))); - connect(this, SIGNAL(interfacesChanged()), ui->captureFilterComboBox, SIGNAL(interfacesChanged())); + connect(&interface_item_delegate_, SIGNAL(filterChanged(QString)), + this, SIGNAL(captureFilterTextEdited(QString))); connect(this, SIGNAL(ifsChanged()), this, SLOT(refreshInterfaceList())); connect(wsApp, SIGNAL(localInterfaceListChanged()), this, SLOT(updateLocalInterfaces())); connect(ui->browseButton, SIGNAL(clicked()), this, SLOT(browseButtonClicked())); @@ -169,29 +172,20 @@ CaptureInterfacesDialog::CaptureInterfacesDialog(QWidget *parent) : void CaptureInterfacesDialog::interfaceSelected() { - interface_t *device; + InterfaceTree::updateGlobalDeviceSelections(ui->interfaceTree, col_interface_); + + start_bt_->setEnabled((global_capture_opts.num_selected > 0) ? true: false); + + emit interfacesChanged(); + + updateSelectedFilter(); - if (ui->interfaceTree->selectedItems().isEmpty()) { - for (guint i = 0; i < global_capture_opts.all_ifaces->len; i++) { - device = &g_array_index(global_capture_opts.all_ifaces, interface_t, i); - device->selected = false; - device->locked = true; - } - global_capture_opts.num_selected = 0; - start_bt_->setEnabled(false); - emit setSelectedInterfaces(); - for (guint i = 0; i < global_capture_opts.all_ifaces->len; i++) { - device = &g_array_index(global_capture_opts.all_ifaces, interface_t, i); - device->locked = false; - } - } updateWidgets(); } void CaptureInterfacesDialog::filterEdited() { QList<QTreeWidgetItem*> si = ui->interfaceTree->selectedItems(); - if (si.isEmpty()) return; foreach (QTreeWidgetItem *ti, si) { ti->setText(col_filter_, ui->captureFilterComboBox->lineEdit()->text()); @@ -218,41 +212,6 @@ void CaptureInterfacesDialog::updateWidgets() start_bt_->setEnabled(can_capture); } -void CaptureInterfacesDialog::interfaceClicked(QTreeWidgetItem *, int) -{ - guint i; - QString filter = ui->captureFilterComboBox->currentText(); - - global_capture_opts.num_selected = 0; - for (i = 0; i < global_capture_opts.all_ifaces->len; i++) { - interface_t *device = &g_array_index(global_capture_opts.all_ifaces, interface_t, i); - device->selected = FALSE; - } - - foreach (QTreeWidgetItem *ti, ui->interfaceTree->selectedItems()) - { - QString interface_name = ti->text(col_interface_); - - for (i = 0; i < global_capture_opts.all_ifaces->len; i++) { - interface_t *device = &g_array_index(global_capture_opts.all_ifaces, interface_t, i); - if (interface_name.compare(device->display_name)) { - continue; - } else { - device->selected = TRUE; - global_capture_opts.num_selected++; - break; - } - } - - start_bt_->setEnabled((global_capture_opts.num_selected > 0) ? true: false); - - if (filter.compare(QString(""))) { - emit interfacesChanged(); - } - emit setSelectedInterfaces(); - } -} - CaptureInterfacesDialog::~CaptureInterfacesDialog() { delete ui; @@ -269,8 +228,9 @@ void CaptureInterfacesDialog::on_capturePromModeCheckBox_toggled(bool checked) prefs.capture_prom_mode = checked; for (int row = 0; row < ui->interfaceTree->topLevelItemCount(); row++) { QTreeWidgetItem *ti = ui->interfaceTree->topLevelItem(row); - int device_idx = ti->data(col_interface_, Qt::UserRole).toUInt(); - device = &g_array_index(global_capture_opts.all_ifaces, interface_t, device_idx); + QString device_name = ti->data(col_interface_, Qt::UserRole).toString(); + device = getDeviceByName(device_name); + if (!device) continue; // QString device_name = ui->interfaceTree->topLevelItem(row)->text(col_interface_); device->pmode = checked; ti->setText(col_pmode_, checked? tr("enabled"):tr("disabled")); @@ -460,6 +420,8 @@ void CaptureInterfacesDialog::updateInterfaces() ui->cbResolveNetworkNames->setChecked(gbl_resolv_flags.network_name); ui->cbResolveTransportNames->setChecked(gbl_resolv_flags.transport_name); + // Rebuild the interface list without disturbing the main welcome screen. + disconnect(ui->interfaceTree, SIGNAL(itemSelectionChanged()), this, SLOT(interfaceSelected())); ui->interfaceTree->clear(); GList *list; @@ -469,6 +431,7 @@ void CaptureInterfacesDialog::updateInterfaces() #endif gint snaplen; gboolean hassnap, pmode; + QList<QTreeWidgetItem *> selected_interfaces; if (global_capture_opts.all_ifaces->len > 0) { interface_t *device; @@ -484,7 +447,7 @@ void CaptureInterfacesDialog::updateInterfaces() // Traffic sparklines InterfaceTreeWidgetItem *ti = new InterfaceTreeWidgetItem(ui->interfaceTree); ti->setFlags(ti->flags() | Qt::ItemIsEditable); - ti->setData(col_interface_, Qt::UserRole, qVariantFromValue(device_idx)); + ti->setData(col_interface_, Qt::UserRole, QString(device->name)); ti->setData(col_traffic_, Qt::UserRole, qVariantFromValue(&ti->points)); ti->setText(col_interface_, device->display_name); @@ -562,34 +525,20 @@ void CaptureInterfacesDialog::updateInterfaces() #ifdef HAVE_EXTCAP } #endif - // If the capture filter column has text, assume that the user - // has filled it in via selectedIfaceCaptureFilterComboBox. - if (ti->text(col_filter_).isEmpty()) { - gchar* user_cfilter = capture_dev_user_cfilter_find(device->name); - if (user_cfilter) { - g_free(device->cfilter); - device->cfilter = user_cfilter; - } - ti->setText(col_filter_, device->cfilter); - } + ti->setText(col_filter_, device->cfilter); - if (prefs.capture_device && strstr(prefs.capture_device, device->name) != NULL) { - device->selected = TRUE; - global_capture_opts.num_selected++; + if (device->selected) { + selected_interfaces << ti; } - ti->setSelected(device->selected); } } - // col_interface_ = 0, - // col_traffic_, - // col_link_, - // col_pmode_, - // col_snaplen_, - // col_buffer_, - // col_monitor_, - // col_filter_, - // col_num_columns_ + foreach (QTreeWidgetItem *ti, selected_interfaces) { + ti->setSelected(true); + } + connect(ui->interfaceTree, SIGNAL(itemSelectionChanged()), this, SLOT(interfaceSelected())); + updateSelectedFilter(); + // Manually or automatically size some columns as needed. int one_em = fontMetrics().height(); for (int col = 0; col < ui->interfaceTree->topLevelItemCount(); col++) { @@ -622,6 +571,11 @@ void CaptureInterfacesDialog::updateInterfaces() } } +void CaptureInterfacesDialog::showEvent(QShowEvent *) +{ + updateInterfaces(); +} + void CaptureInterfacesDialog::refreshInterfaceList() { updateInterfaces(); @@ -802,12 +756,6 @@ bool CaptureInterfacesDialog::saveOptionsToPreferences() interface_t *device; - // Close the editor if it's open. - QTreeWidgetItem *ti = ui->interfaceTree->currentItem(); - if (ti) { - ui->interfaceTree->setCurrentItem(ti, col_interface_); - } - for (int col = col_link_; col <= col_filter_; col++) { if (ui->interfaceTree->isColumnHidden(col)) { continue; @@ -821,9 +769,9 @@ bool CaptureInterfacesDialog::saveOptionsToPreferences() for (int row = 0; row < ui->interfaceTree->topLevelItemCount(); row++) { QTreeWidgetItem *ti = ui->interfaceTree->topLevelItem(row); - guint device_idx = ti->data(col_interface_, Qt::UserRole).toUInt(); - device = &g_array_index(global_capture_opts.all_ifaces, interface_t, device_idx); - if (device->active_dlt == -1) { + QString device_name = ti->data(col_interface_, Qt::UserRole).toString(); + device = getDeviceByName(device_name); + if (!device || device->active_dlt == -1) { continue; } link_list << QString("%1(%2)").arg(device->name).arg(device->active_dlt); @@ -839,9 +787,9 @@ bool CaptureInterfacesDialog::saveOptionsToPreferences() for (int row = 0; row < ui->interfaceTree->topLevelItemCount(); row++) { QTreeWidgetItem *ti = ui->interfaceTree->topLevelItem(row); - guint device_idx = ti->data(col_interface_, Qt::UserRole).toUInt(); - device = &g_array_index(global_capture_opts.all_ifaces, interface_t, device_idx); - if (device->buffer == -1) { + QString device_name = ti->data(col_interface_, Qt::UserRole).toString(); + device = getDeviceByName(device_name); + if (!device || device->buffer == -1) { continue; } buffer_size_list << QString("%1(%2)").arg(device->name).arg(device->buffer); @@ -857,8 +805,9 @@ bool CaptureInterfacesDialog::saveOptionsToPreferences() for (int row = 0; row < ui->interfaceTree->topLevelItemCount(); row++) { QTreeWidgetItem *ti = ui->interfaceTree->topLevelItem(row); - guint device_idx = ti->data(col_interface_, Qt::UserRole).toUInt(); - device = &g_array_index(global_capture_opts.all_ifaces, interface_t, device_idx); + QString device_name = ti->data(col_interface_, Qt::UserRole).toString(); + device = getDeviceByName(device_name); + if (!device) continue; snaplen_list << QString("%1:%2(%3)") .arg(device->name) .arg(device->has_snaplen) @@ -874,9 +823,9 @@ bool CaptureInterfacesDialog::saveOptionsToPreferences() for (int row = 0; row < ui->interfaceTree->topLevelItemCount(); row++) { QTreeWidgetItem *ti = ui->interfaceTree->topLevelItem(row); - guint device_idx = ti->data(col_interface_, Qt::UserRole).toUInt(); - device = &g_array_index(global_capture_opts.all_ifaces, interface_t, device_idx); - if (device->pmode == -1) { + QString device_name = ti->data(col_interface_, Qt::UserRole).toString(); + device = getDeviceByName(device_name); + if (!device || device->pmode == -1) { continue; } pmode_list << QString("%1(%2)").arg(device->name).arg(device->pmode); @@ -892,9 +841,9 @@ bool CaptureInterfacesDialog::saveOptionsToPreferences() for (int row = 0; row < ui->interfaceTree->topLevelItemCount(); row++) { QTreeWidgetItem *ti = ui->interfaceTree->topLevelItem(row); - guint device_idx = ti->data(col_interface_, Qt::UserRole).toUInt(); - device = &g_array_index(global_capture_opts.all_ifaces, interface_t, device_idx); - if (!device->monitor_mode_supported || (device->monitor_mode_supported && !device->monitor_mode_enabled)) { + QString device_name = ti->data(col_interface_, Qt::UserRole).toString(); + device = getDeviceByName(device_name); + if (!device || !device->monitor_mode_supported || (device->monitor_mode_supported && !device->monitor_mode_enabled)) { continue; } monitor_list << device->name; @@ -904,13 +853,18 @@ bool CaptureInterfacesDialog::saveOptionsToPreferences() break; } #endif // HAVE_MONITOR_SETTING + +#if 0 + // The device cfilter should have been applied at this point. + // We shouldn't change it here. case col_filter_: { // XXX Update selected interfaces only? for (int row = 0; row < ui->interfaceTree->topLevelItemCount(); row++) { QTreeWidgetItem *ti = ui->interfaceTree->topLevelItem(row); - guint device_idx = ti->data(col_interface_, Qt::UserRole).toUInt(); - device = &g_array_index(global_capture_opts.all_ifaces, interface_t, device_idx); + QString device_name = ti->data(col_interface_, Qt::UserRole).toString(); + device = getDeviceByName(device_name); + if (!device) continue; g_free(device->cfilter); if (ti->text(col_filter_).isEmpty()) { device->cfilter = NULL; @@ -919,6 +873,7 @@ bool CaptureInterfacesDialog::saveOptionsToPreferences() } } } +#endif } } if (!prefs.gui_use_pref_save) { @@ -927,6 +882,21 @@ bool CaptureInterfacesDialog::saveOptionsToPreferences() return true; } +void CaptureInterfacesDialog::updateSelectedFilter() +{ + // Should match MainWelcome::interfaceSelected. + QPair <const QString, bool> sf_pair = CaptureFilterEdit::getSelectedFilter(); + const QString user_filter = sf_pair.first; + bool conflict = sf_pair.second; + + if (conflict) { + ui->captureFilterComboBox->lineEdit()->clear(); + ui->captureFilterComboBox->setConflict(true); + } else { + ui->captureFilterComboBox->lineEdit()->setText(user_filter); + } +} + void CaptureInterfacesDialog::on_manage_clicked() { if (saveOptionsToPreferences()) { @@ -951,6 +921,17 @@ void CaptureInterfacesDialog::changeEvent(QEvent* event) QDialog::changeEvent(event); } +interface_t *CaptureInterfacesDialog::getDeviceByName(const QString device_name) +{ + for (guint i = 0; i < global_capture_opts.all_ifaces->len; i++) { + interface_t *device = &g_array_index(global_capture_opts.all_ifaces, interface_t, i); + if (device_name.compare(QString().fromUtf8(device->name)) == 0) { + return device; + } + } + return NULL; +} + // // InterfaceTreeItem // |