void FilterDialog::showEvent(QShowEvent *event) { ui->filterTreeWidget->clear(); GList *filter_list; if (filter_type_ == CaptureFilter) { filter_list = get_filter_list_first(CFILTER_LIST); } else { filter_list = get_filter_list_first(DFILTER_LIST); } for (GList *fl_item = filter_list; fl_item; fl_item = g_list_next(fl_item)) { if (!fl_item->data) continue; filter_def *fl_data = (filter_def *) fl_item->data; if (!fl_data->name || !fl_data->strval) continue; addFilter(fl_data->name, fl_data->strval); } if (!new_filter_.isEmpty()) { addFilter(tr("New filter"), new_filter_, true); new_filter_.clear(); } ui->filterTreeWidget->resizeColumnToContents(name_col_); ui->filterTreeWidget->resizeColumnToContents(filter_col_); QDialog::showEvent(event); }
void CaptureFilterEdit::removeFilter() { QAction *ra = qobject_cast<QAction*>(sender()); if (!ra || ra->data().toString().isEmpty()) return; QString remove_filter = ra->data().toString(); for (GList *cf_item = get_filter_list_first(CFILTER_LIST); cf_item; cf_item = g_list_next(cf_item)) { if (!cf_item->data) continue; filter_def *cf_def = (filter_def *) cf_item->data; if (!cf_def->name || !cf_def->strval) continue; if (remove_filter.compare(cf_def->strval) == 0) { remove_from_filter_list(CFILTER_LIST, cf_item); } } char *f_path; int f_save_errno; save_filter_list(CFILTER_LIST, &f_path, &f_save_errno); if (f_path != NULL) { // We had an error saving the filter. QString warning_title = tr("Unable to save capture filter settings."); QString warning_msg = tr("Could not save to your capture filter file\n\"%1\": %2.").arg(f_path).arg(g_strerror(f_save_errno)); QMessageBox::warning(this, warning_title, warning_msg, QMessageBox::Ok); g_free(f_path); } updateBookmarkMenu(); }
void CaptureFilterEdit::updateBookmarkMenu() { if (!bookmark_button_) return; QMenu *bb_menu = bookmark_button_->menu(); bb_menu->clear(); save_action_ = bb_menu->addAction(tr("Save this filter")); connect(save_action_, SIGNAL(triggered(bool)), this, SLOT(saveFilter())); remove_action_ = bb_menu->addAction(tr("Remove this filter")); connect(remove_action_, SIGNAL(triggered(bool)), this, SLOT(removeFilter())); QAction *manage_action = bb_menu->addAction(tr("Manage Capture Filters")); connect(manage_action, SIGNAL(triggered(bool)), this, SLOT(showFilters())); bb_menu->addSeparator(); for (GList *cf_item = get_filter_list_first(CFILTER_LIST); cf_item; cf_item = g_list_next(cf_item)) { if (!cf_item->data) continue; filter_def *cf_def = (filter_def *) cf_item->data; if (!cf_def->name || !cf_def->strval) continue; int one_em = bb_menu->fontMetrics().height(); QString prep_text = QString("%1: %2").arg(cf_def->name).arg(cf_def->strval); prep_text = bb_menu->fontMetrics().elidedText(prep_text, Qt::ElideRight, one_em * 40); QAction *prep_action = bb_menu->addAction(prep_text); prep_action->setData(cf_def->strval); connect(prep_action, SIGNAL(triggered(bool)), this, SLOT(prepareFilter())); } checkFilter(); }
void FilterDialog::on_buttonBox_accepted() { filter_list_type_t fl_type = filter_type_ == CaptureFilter ? CFILTER_LIST : DFILTER_LIST; while (GList *fl_item = get_filter_list_first(fl_type)) { remove_from_filter_list(fl_type, fl_item); } QTreeWidgetItemIterator it(ui->filterTreeWidget); while (*it) { add_to_filter_list(fl_type, (*it)->text(name_col_).toUtf8().constData(), (*it)->text(filter_col_).toUtf8().constData()); ++it; } char *pf_dir_path; char *f_path; int f_save_errno; /* Create the directory that holds personal configuration files, if necessary. */ if (create_persconffile_dir(&pf_dir_path) == -1) { QMessageBox::warning(this, tr("Unable to create profile directory."), tr("Unable to create directory\n\"%1\"\nfor filter files: %2.") .arg(pf_dir_path) .arg(g_strerror(errno)), QMessageBox::Ok); g_free(pf_dir_path); return; } save_filter_list(fl_type, &f_path, &f_save_errno); if (f_path != NULL) { /* We had an error saving the filter. */ QString warning_title; QString warning_msg; if (fl_type == CFILTER_LIST) { warning_title = tr("Unable to save capture filter settings."); warning_msg = tr("Could not save to your capture filter file\n\"%1\": %2.") .arg(f_path).arg(g_strerror(f_save_errno)); } else { warning_title = tr("Unable to save display filter settings."); warning_msg = tr("Could not save to your display filter file\n\"%1\": %2.") .arg(f_path).arg(g_strerror(f_save_errno)); } QMessageBox::warning(this, warning_title, warning_msg, QMessageBox::Ok); g_free(f_path); } if (filter_type_ == CaptureFilter) { wsApp->emitAppSignal(WiresharkApplication::CaptureFilterListChanged); } else { wsApp->emitAppSignal(WiresharkApplication::DisplayFilterListChanged); } }
void CaptureFilterEdit::checkFilter(const QString& filter) { setSyntaxState(Busy); popFilterSyntaxStatus(); bool empty = filter.isEmpty(); setConflict(false); if (bookmark_button_) { bool match = false; for (GList *cf_item = get_filter_list_first(CFILTER_LIST); cf_item; cf_item = g_list_next(cf_item)) { if (!cf_item->data) continue; filter_def *cf_def = (filter_def *) cf_item->data; if (!cf_def->name || !cf_def->strval) continue; if (filter.compare(cf_def->strval) == 0) { match = true; } } if (match) { bookmark_button_->setStockIcon("x-filter-matching-bookmark"); if (remove_action_) { remove_action_->setData(text()); remove_action_->setVisible(true); } } else { bookmark_button_->setStockIcon("x-capture-filter-bookmark"); if (remove_action_) { remove_action_->setVisible(false); } } enable_save_action_ = (!match && !filter.isEmpty()); if (save_action_) { save_action_->setEnabled(false); } } if (apply_button_) { apply_button_->setEnabled(false); } if (clear_button_) { clear_button_->setVisible(!empty); } if (empty) { setFilterSyntaxState(filter, Empty, QString()); } else { syntax_worker_->checkFilter(filter); } }
void CaptureFilterEdit::removeFilter() { QAction *ra = qobject_cast<QAction*>(sender()); if (!ra || ra->data().toString().isEmpty()) return; QString remove_filter = ra->data().toString(); for (GList *cf_item = get_filter_list_first(CFILTER_LIST); cf_item; cf_item = g_list_next(cf_item)) { if (!cf_item->data) continue; filter_def *cf_def = (filter_def *) cf_item->data; if (!cf_def->name || !cf_def->strval) continue; if (remove_filter.compare(cf_def->strval) == 0) { remove_from_filter_list(CFILTER_LIST, cf_item); } } save_filter_list(CFILTER_LIST); updateBookmarkMenu(); }
void CaptureFilterEdit::buildCompletionList(const QString &primitive_word) { if (primitive_word.length() < 1) { completion_model_->setStringList(QStringList()); return; } // Grab matching capture filters from our parent combo and from the // saved capture filters file. Skip ones that look like single fields // and assume they will be added below. QStringList complex_list; QComboBox *cf_combo = qobject_cast<QComboBox *>(parent()); if (cf_combo) { for (int i = 0; i < cf_combo->count() ; i++) { QString recent_filter = cf_combo->itemText(i); if (isComplexFilter(recent_filter)) { complex_list << recent_filter; } } } for (const GList *cf_item = get_filter_list_first(CFILTER_LIST); cf_item; cf_item = g_list_next(cf_item)) { const filter_def *cf_def = (filter_def *) cf_item->data; if (!cf_def || !cf_def->strval) continue; QString saved_filter = cf_def->strval; if (isComplexFilter(saved_filter) && !complex_list.contains(saved_filter)) { complex_list << saved_filter; } } // libpcap has a small number of primitives so we just add the whole list // sans the current word. QStringList primitive_list = libpcap_primitives_; primitive_list.removeAll(primitive_word); completion_model_->setStringList(complex_list + primitive_list); completer()->setCompletionPrefix(primitive_word); }
void DisplayFilterEdit::checkFilter(const QString& filter_text) { if (clear_button_) { clear_button_->setVisible(!filter_text.isEmpty()); } popFilterSyntaxStatus(); checkDisplayFilter(filter_text); switch (syntaxState()) { case Deprecated: { /* * We're being lazy and only printing the first "problem" token. * Would it be better to print all of them? */ QString deprecatedMsg(tr("\"%1\" may have unexpected results (see the User's Guide)") .arg(deprecatedToken())); emit pushFilterSyntaxWarning(deprecatedMsg); break; } case Invalid: { QString invalidMsg(tr("Invalid filter: ")); invalidMsg.append(syntaxErrorMessage()); emit pushFilterSyntaxStatus(invalidMsg); break; } default: break; } if (bookmark_button_) { bool enable_save_action = false; bool match = false; QMenu *bb_menu = bookmark_button_->menu(); bb_menu->clear(); QAction *save_action = bb_menu->addAction(tr("Save this filter")); connect(save_action, SIGNAL(triggered(bool)), this, SLOT(saveFilter())); QAction *manage_action = bb_menu->addAction(tr("Manage Display Filters")); connect(manage_action, SIGNAL(triggered(bool)), this, SLOT(showFilters())); QAction *expr_action = bb_menu->addAction(tr("Manage Filter Expressions")); connect(expr_action, SIGNAL(triggered(bool)), this, SLOT(showExpressionPrefs())); QAction *first_filter = NULL; for (GList *df_item = get_filter_list_first(DFILTER_LIST); df_item; df_item = g_list_next(df_item)) { if (!df_item->data) continue; filter_def *df_def = (filter_def *) df_item->data; if (!df_def->name || !df_def->strval) continue; int one_em = bb_menu->fontMetrics().height(); QString prep_text = QString("%1: %2").arg(df_def->name).arg(df_def->strval); prep_text = bb_menu->fontMetrics().elidedText(prep_text, Qt::ElideRight, one_em * 40); QAction *prep_action = bb_menu->addAction(prep_text); prep_action->setData(df_def->strval); connect(prep_action, SIGNAL(triggered(bool)), this, SLOT(prepareFilter())); if (!first_filter) first_filter = prep_action; if (filter_text.compare(df_def->strval) == 0) { match = true; } } if (first_filter) bb_menu->insertSeparator(first_filter); if (match) { bookmark_button_->setStockIcon("x-filter-matching-bookmark"); QAction *remove_action = new QAction(tr("Remove this filter"), bb_menu); bb_menu->insertAction(manage_action, remove_action); remove_action->setData(filter_text); connect(remove_action, SIGNAL(triggered(bool)), this, SLOT(removeFilter())); } else { bookmark_button_->setStockIcon("x-filter-bookmark"); } if (!match && (syntaxState() == Valid || syntaxState() == Deprecated) && !filter_text.isEmpty()) { enable_save_action = true; } save_action->setEnabled(enable_save_action); }