Qt: Move Apply/Prepare to general QMenu handler
Also clarify the method by which the filter can be selected. From the main menu only selected filters from a ProtoTree can be selected, therefore the code for PacketList handling has been removed. Change-Id: I5e5827d763ab3b25db14a384581f283238f96d28 Reviewed-on: https://code.wireshark.org/review/34384 Petri-Dish: Roland Knall <rknall@gmail.com> Tested-by: Petri Dish Buildbot Reviewed-by: Gerald Combs <gerald@wireshark.org> Reviewed-by: Roland Knall <rknall@gmail.com>
This commit is contained in:
parent
92ac2f5099
commit
cd8f720251
|
@ -12,6 +12,8 @@
|
|||
#include <ui/qt/wireshark_application.h>
|
||||
#include <ui/qt/main_window.h>
|
||||
|
||||
#include <QMenu>
|
||||
|
||||
FilterAction::FilterAction(QObject *parent, FilterAction::Action action, FilterAction::ActionType type, FilterAction::ActionDirection direction) :
|
||||
QAction(parent),
|
||||
action_(action),
|
||||
|
@ -220,6 +222,18 @@ QActionGroup * FilterAction::createFilterGroup(QString filter, bool prepare, boo
|
|||
return group;
|
||||
}
|
||||
|
||||
QMenu * FilterAction::createFilterMenu(FilterAction::Action act, QString filter, bool enabled, QWidget * par)
|
||||
{
|
||||
QString title = ( act == FilterAction::ActionApply) ? QObject::tr("Apply as Filter") : QObject::tr("Prepare as Filter");
|
||||
bool prepare = ( act == FilterAction::ActionApply) ? false : true;
|
||||
|
||||
QMenu * submenu = new QMenu(title, par);
|
||||
QActionGroup * group = FilterAction::createFilterGroup(filter, prepare, enabled, par);
|
||||
submenu->addActions(group->actions());
|
||||
|
||||
return submenu;
|
||||
}
|
||||
|
||||
void FilterAction::groupTriggered(QAction * action)
|
||||
{
|
||||
if ( action && wsApp )
|
||||
|
|
|
@ -73,6 +73,7 @@ public:
|
|||
static const QString actionDirectionName(ActionDirection direction);
|
||||
|
||||
static QActionGroup * createFilterGroup(QString filter, bool prepare, bool enabled, QWidget * parent);
|
||||
static QMenu * createFilterMenu(FilterAction::Action act, QString filter, bool enabled, QWidget * parent);
|
||||
|
||||
signals:
|
||||
|
||||
|
|
|
@ -651,6 +651,11 @@ MainWindow::MainWindow(QWidget *parent) :
|
|||
connect(main_ui_->statusBar, SIGNAL(editCaptureComment()),
|
||||
this, SLOT(on_actionStatisticsCaptureFileProperties_triggered()));
|
||||
|
||||
connect(main_ui_->menuApplyAsFilter, &QMenu::aboutToShow,
|
||||
this, &MainWindow::filterMenuAboutToShow);
|
||||
connect(main_ui_->menuPrepareAFilter, &QMenu::aboutToShow,
|
||||
this, &MainWindow::filterMenuAboutToShow);
|
||||
|
||||
#ifdef HAVE_LIBPCAP
|
||||
QTreeWidget *iface_tree = findChild<QTreeWidget *>("interfaceTree");
|
||||
if (iface_tree) {
|
||||
|
|
|
@ -533,18 +533,8 @@ private slots:
|
|||
void on_actionAnalyzeDisplayFilterMacros_triggered();
|
||||
void matchFieldFilter(FilterAction::Action action, FilterAction::ActionType filter_type);
|
||||
void on_actionAnalyzeCreateAColumn_triggered();
|
||||
void on_actionAnalyzeAAFSelected_triggered();
|
||||
void on_actionAnalyzeAAFNotSelected_triggered();
|
||||
void on_actionAnalyzeAAFAndSelected_triggered();
|
||||
void on_actionAnalyzeAAFOrSelected_triggered();
|
||||
void on_actionAnalyzeAAFAndNotSelected_triggered();
|
||||
void on_actionAnalyzeAAFOrNotSelected_triggered();
|
||||
void on_actionAnalyzePAFSelected_triggered();
|
||||
void on_actionAnalyzePAFNotSelected_triggered();
|
||||
void on_actionAnalyzePAFAndSelected_triggered();
|
||||
void on_actionAnalyzePAFOrSelected_triggered();
|
||||
void on_actionAnalyzePAFAndNotSelected_triggered();
|
||||
void on_actionAnalyzePAFOrNotSelected_triggered();
|
||||
|
||||
void filterMenuAboutToShow();
|
||||
|
||||
void applyConversationFilter();
|
||||
void applyExportObject();
|
||||
|
|
|
@ -394,23 +394,11 @@
|
|||
<property name="title">
|
||||
<string>Apply as Filter</string>
|
||||
</property>
|
||||
<addaction name="actionAnalyzeAAFSelected"/>
|
||||
<addaction name="actionAnalyzeAAFNotSelected"/>
|
||||
<addaction name="actionAnalyzeAAFAndSelected"/>
|
||||
<addaction name="actionAnalyzeAAFOrSelected"/>
|
||||
<addaction name="actionAnalyzeAAFAndNotSelected"/>
|
||||
<addaction name="actionAnalyzeAAFOrNotSelected"/>
|
||||
</widget>
|
||||
<widget class="QMenu" name="menuPrepareAFilter">
|
||||
<property name="title">
|
||||
<string>Prepare a Filter</string>
|
||||
</property>
|
||||
<addaction name="actionAnalyzePAFSelected"/>
|
||||
<addaction name="actionAnalyzePAFNotSelected"/>
|
||||
<addaction name="actionAnalyzePAFAndSelected"/>
|
||||
<addaction name="actionAnalyzePAFOrSelected"/>
|
||||
<addaction name="actionAnalyzePAFAndNotSelected"/>
|
||||
<addaction name="actionAnalyzePAFOrNotSelected"/>
|
||||
</widget>
|
||||
<widget class="QMenu" name="menuSCTP">
|
||||
<property name="title">
|
||||
|
@ -1362,96 +1350,6 @@
|
|||
<string notr="true">Ctrl+Shift+C</string>
|
||||
</property>
|
||||
</action>
|
||||
<action name="actionAnalyzeAAFSelected">
|
||||
<property name="text">
|
||||
<string>&Selected</string>
|
||||
</property>
|
||||
</action>
|
||||
<action name="actionAnalyzeAAFNotSelected">
|
||||
<property name="text">
|
||||
<string>&Not Selected</string>
|
||||
</property>
|
||||
<property name="toolTip">
|
||||
<string>Not Selected</string>
|
||||
</property>
|
||||
</action>
|
||||
<action name="actionAnalyzeAAFAndSelected">
|
||||
<property name="text">
|
||||
<string>…&and Selected</string>
|
||||
</property>
|
||||
<property name="toolTip">
|
||||
<string>…and Selected</string>
|
||||
</property>
|
||||
</action>
|
||||
<action name="actionAnalyzeAAFOrSelected">
|
||||
<property name="text">
|
||||
<string>…&or Selected</string>
|
||||
</property>
|
||||
<property name="toolTip">
|
||||
<string>…or Selected</string>
|
||||
</property>
|
||||
</action>
|
||||
<action name="actionAnalyzeAAFAndNotSelected">
|
||||
<property name="text">
|
||||
<string>…a&nd not Selected</string>
|
||||
</property>
|
||||
<property name="toolTip">
|
||||
<string>…and not Selected</string>
|
||||
</property>
|
||||
</action>
|
||||
<action name="actionAnalyzeAAFOrNotSelected">
|
||||
<property name="text">
|
||||
<string>…o&r not Selected</string>
|
||||
</property>
|
||||
<property name="toolTip">
|
||||
<string>…or not Selected</string>
|
||||
</property>
|
||||
</action>
|
||||
<action name="actionAnalyzePAFSelected">
|
||||
<property name="text">
|
||||
<string>&Selected</string>
|
||||
</property>
|
||||
</action>
|
||||
<action name="actionAnalyzePAFNotSelected">
|
||||
<property name="text">
|
||||
<string>&Not Selected</string>
|
||||
</property>
|
||||
<property name="toolTip">
|
||||
<string>Not Selected</string>
|
||||
</property>
|
||||
</action>
|
||||
<action name="actionAnalyzePAFAndSelected">
|
||||
<property name="text">
|
||||
<string>…&and Selected</string>
|
||||
</property>
|
||||
<property name="toolTip">
|
||||
<string>…and Selected</string>
|
||||
</property>
|
||||
</action>
|
||||
<action name="actionAnalyzePAFOrSelected">
|
||||
<property name="text">
|
||||
<string>…&or Selected</string>
|
||||
</property>
|
||||
<property name="toolTip">
|
||||
<string>…or Selected</string>
|
||||
</property>
|
||||
</action>
|
||||
<action name="actionAnalyzePAFAndNotSelected">
|
||||
<property name="text">
|
||||
<string>…a&nd not Selected</string>
|
||||
</property>
|
||||
<property name="toolTip">
|
||||
<string>…and not Selected</string>
|
||||
</property>
|
||||
</action>
|
||||
<action name="actionAnalyzePAFOrNotSelected">
|
||||
<property name="text">
|
||||
<string>…o&r not Selected</string>
|
||||
</property>
|
||||
<property name="toolTip">
|
||||
<string>…or not Selected</string>
|
||||
</property>
|
||||
</action>
|
||||
<action name="actionAnalyzeDisplayFilters">
|
||||
<property name="text">
|
||||
<string>Display &Filters…</string>
|
||||
|
|
|
@ -1145,8 +1145,6 @@ void MainWindow::setMenusForSelectedPacket()
|
|||
than one time reference frame or the current frame isn't a
|
||||
time reference frame). (XXX - why check frame_selected?) */
|
||||
bool another_is_time_ref = false;
|
||||
/* We have a valid filter expression */
|
||||
bool have_filter_expr = false;
|
||||
|
||||
QList<QAction *> cc_actions = QList<QAction *>()
|
||||
<< main_ui_->actionViewColorizeConversation1 << main_ui_->actionViewColorizeConversation2
|
||||
|
@ -1178,8 +1176,6 @@ void MainWindow::setMenusForSelectedPacket()
|
|||
}
|
||||
}
|
||||
|
||||
have_filter_expr = !packet_list_->getFilterFromRowAndColumn(packet_list_->currentIndex()).isEmpty();
|
||||
|
||||
main_ui_->actionEditMarkPacket->setEnabled(frame_selected);
|
||||
main_ui_->actionEditMarkAllDisplayed->setEnabled(have_frames);
|
||||
/* Unlike un-ignore, do not allow unmark of all frames when no frames are displayed */
|
||||
|
@ -1205,20 +1201,6 @@ void MainWindow::setMenusForSelectedPacket()
|
|||
main_ui_->actionGoNextHistoryPacket->setEnabled(next_selection_history);
|
||||
main_ui_->actionGoPreviousHistoryPacket->setEnabled(previous_selection_history);
|
||||
|
||||
main_ui_->actionAnalyzeAAFSelected->setEnabled(have_filter_expr);
|
||||
main_ui_->actionAnalyzeAAFNotSelected->setEnabled(have_filter_expr);
|
||||
main_ui_->actionAnalyzeAAFAndSelected->setEnabled(have_filter_expr);
|
||||
main_ui_->actionAnalyzeAAFOrSelected->setEnabled(have_filter_expr);
|
||||
main_ui_->actionAnalyzeAAFAndNotSelected->setEnabled(have_filter_expr);
|
||||
main_ui_->actionAnalyzeAAFOrNotSelected->setEnabled(have_filter_expr);
|
||||
|
||||
main_ui_->actionAnalyzePAFSelected->setEnabled(have_filter_expr);
|
||||
main_ui_->actionAnalyzePAFNotSelected->setEnabled(have_filter_expr);
|
||||
main_ui_->actionAnalyzePAFAndSelected->setEnabled(have_filter_expr);
|
||||
main_ui_->actionAnalyzePAFOrSelected->setEnabled(have_filter_expr);
|
||||
main_ui_->actionAnalyzePAFAndNotSelected->setEnabled(have_filter_expr);
|
||||
main_ui_->actionAnalyzePAFOrNotSelected->setEnabled(have_filter_expr);
|
||||
|
||||
main_ui_->actionAnalyzeFollowTCPStream->setEnabled(is_tcp);
|
||||
main_ui_->actionAnalyzeFollowUDPStream->setEnabled(is_udp);
|
||||
main_ui_->actionAnalyzeFollowTLSStream->setEnabled(is_tls);
|
||||
|
@ -1356,19 +1338,6 @@ void MainWindow::setMenusForSelectedTreeRow(FieldInformation *finfo) {
|
|||
// frame_selected && (gbl_resolv_flags.mac_name || gbl_resolv_flags.network_name ||
|
||||
// gbl_resolv_flags.transport_name));
|
||||
|
||||
main_ui_->actionAnalyzeAAFSelected->setEnabled(can_match_selected);
|
||||
main_ui_->actionAnalyzeAAFNotSelected->setEnabled(can_match_selected);
|
||||
main_ui_->actionAnalyzeAAFAndSelected->setEnabled(can_match_selected);
|
||||
main_ui_->actionAnalyzeAAFOrSelected->setEnabled(can_match_selected);
|
||||
main_ui_->actionAnalyzeAAFAndNotSelected->setEnabled(can_match_selected);
|
||||
main_ui_->actionAnalyzeAAFOrNotSelected->setEnabled(can_match_selected);
|
||||
|
||||
main_ui_->actionAnalyzePAFSelected->setEnabled(can_match_selected);
|
||||
main_ui_->actionAnalyzePAFNotSelected->setEnabled(can_match_selected);
|
||||
main_ui_->actionAnalyzePAFAndSelected->setEnabled(can_match_selected);
|
||||
main_ui_->actionAnalyzePAFOrSelected->setEnabled(can_match_selected);
|
||||
main_ui_->actionAnalyzePAFAndNotSelected->setEnabled(can_match_selected);
|
||||
main_ui_->actionAnalyzePAFOrNotSelected->setEnabled(can_match_selected);
|
||||
}
|
||||
|
||||
void MainWindow::interfaceSelectionChanged()
|
||||
|
@ -2587,6 +2556,25 @@ void MainWindow::on_actionViewReload_as_File_Format_or_Capture_triggered()
|
|||
|
||||
// Analyze Menu
|
||||
|
||||
void MainWindow::filterMenuAboutToShow()
|
||||
{
|
||||
QMenu * menu = qobject_cast<QMenu *>(sender());
|
||||
QString field_filter;
|
||||
|
||||
if (capture_file_.capFile() && capture_file_.capFile()->finfo_selected) {
|
||||
char *tmp_field = proto_construct_match_selected_string(capture_file_.capFile()->finfo_selected,
|
||||
capture_file_.capFile()->edt);
|
||||
field_filter = QString(tmp_field);
|
||||
wmem_free(NULL, tmp_field);
|
||||
}
|
||||
bool enable = ! field_filter.isEmpty();
|
||||
bool prepare = menu->objectName().compare("menuPrepareAFilter") == 0;
|
||||
|
||||
menu->clear();
|
||||
QActionGroup * group = FilterAction::createFilterGroup(field_filter, prepare, enable, menu);
|
||||
menu->addActions(group->actions());
|
||||
}
|
||||
|
||||
void MainWindow::matchFieldFilter(FilterAction::Action action, FilterAction::ActionType filter_type)
|
||||
{
|
||||
QString field_filter;
|
||||
|
@ -2678,69 +2666,6 @@ void MainWindow::applyExportObject()
|
|||
|
||||
}
|
||||
|
||||
// XXX We could probably create the analyze and prepare actions
|
||||
// dynamically using FilterActions and consolidate the methods
|
||||
// below into one callback.
|
||||
void MainWindow::on_actionAnalyzeAAFSelected_triggered()
|
||||
{
|
||||
matchFieldFilter(FilterAction::ActionApply, FilterAction::ActionTypePlain);
|
||||
}
|
||||
|
||||
void MainWindow::on_actionAnalyzeAAFNotSelected_triggered()
|
||||
{
|
||||
matchFieldFilter(FilterAction::ActionApply, FilterAction::ActionTypeNot);
|
||||
}
|
||||
|
||||
void MainWindow::on_actionAnalyzeAAFAndSelected_triggered()
|
||||
{
|
||||
matchFieldFilter(FilterAction::ActionApply, FilterAction::ActionTypeAnd);
|
||||
}
|
||||
|
||||
void MainWindow::on_actionAnalyzeAAFOrSelected_triggered()
|
||||
{
|
||||
matchFieldFilter(FilterAction::ActionApply, FilterAction::ActionTypeOr);
|
||||
}
|
||||
|
||||
void MainWindow::on_actionAnalyzeAAFAndNotSelected_triggered()
|
||||
{
|
||||
matchFieldFilter(FilterAction::ActionApply, FilterAction::ActionTypeAndNot);
|
||||
}
|
||||
|
||||
void MainWindow::on_actionAnalyzeAAFOrNotSelected_triggered()
|
||||
{
|
||||
matchFieldFilter(FilterAction::ActionApply, FilterAction::ActionTypeOrNot);
|
||||
}
|
||||
|
||||
void MainWindow::on_actionAnalyzePAFSelected_triggered()
|
||||
{
|
||||
matchFieldFilter(FilterAction::ActionPrepare, FilterAction::ActionTypePlain);
|
||||
}
|
||||
|
||||
void MainWindow::on_actionAnalyzePAFNotSelected_triggered()
|
||||
{
|
||||
matchFieldFilter(FilterAction::ActionPrepare, FilterAction::ActionTypeNot);
|
||||
}
|
||||
|
||||
void MainWindow::on_actionAnalyzePAFAndSelected_triggered()
|
||||
{
|
||||
matchFieldFilter(FilterAction::ActionPrepare, FilterAction::ActionTypeAnd);
|
||||
}
|
||||
|
||||
void MainWindow::on_actionAnalyzePAFOrSelected_triggered()
|
||||
{
|
||||
matchFieldFilter(FilterAction::ActionPrepare, FilterAction::ActionTypeOr);
|
||||
}
|
||||
|
||||
void MainWindow::on_actionAnalyzePAFAndNotSelected_triggered()
|
||||
{
|
||||
matchFieldFilter(FilterAction::ActionPrepare, FilterAction::ActionTypeAndNot);
|
||||
}
|
||||
|
||||
void MainWindow::on_actionAnalyzePAFOrNotSelected_triggered()
|
||||
{
|
||||
matchFieldFilter(FilterAction::ActionPrepare, FilterAction::ActionTypeOrNot);
|
||||
}
|
||||
|
||||
void MainWindow::on_actionAnalyzeEnabledProtocols_triggered()
|
||||
{
|
||||
EnabledProtocolsDialog enable_proto_dialog(this);
|
||||
|
|
|
@ -510,14 +510,8 @@ void PacketList::contextMenuEvent(QContextMenuEvent *event)
|
|||
}
|
||||
|
||||
bool have_filter_expr = !selectedfilter.isEmpty();
|
||||
QMenu * submenu = new QMenu(tr("Apply as Filter"), &ctx_menu);
|
||||
QActionGroup * group = FilterAction::createFilterGroup(selectedfilter, false, have_filter_expr, &ctx_menu);
|
||||
submenu->addActions(group->actions());
|
||||
ctx_menu.addMenu(submenu);
|
||||
submenu = new QMenu(tr("Prepare as Filter"), &ctx_menu);
|
||||
group = FilterAction::createFilterGroup(selectedfilter, true, have_filter_expr, &ctx_menu);
|
||||
submenu->addActions(group->actions());
|
||||
ctx_menu.addMenu(submenu);
|
||||
ctx_menu.addMenu(FilterAction::createFilterMenu(FilterAction::ActionApply, selectedfilter, have_filter_expr, &ctx_menu));
|
||||
ctx_menu.addMenu(FilterAction::createFilterMenu(FilterAction::ActionPrepare, selectedfilter, have_filter_expr, &ctx_menu));
|
||||
|
||||
const char *conv_menu_name = "menuConversationFilter";
|
||||
QMenu * main_menu_item = window()->findChild<QMenu *>(conv_menu_name);
|
||||
|
@ -532,7 +526,7 @@ void PacketList::contextMenuEvent(QContextMenuEvent *event)
|
|||
ctx_menu.addMenu(&colorize_menu_);
|
||||
|
||||
main_menu_item = window()->findChild<QMenu *>("menuSCTP");
|
||||
submenu = new QMenu(main_menu_item->title(), &ctx_menu);
|
||||
QMenu * submenu = new QMenu(main_menu_item->title(), &ctx_menu);
|
||||
ctx_menu.addMenu(submenu);
|
||||
submenu->addAction(window()->findChild<QAction *>("actionSCTPAnalyseThisAssociation"));
|
||||
submenu->addAction(window()->findChild<QAction *>("actionSCTPShowAllAssociations"));
|
||||
|
|
|
@ -152,14 +152,9 @@ void ProtoTree::protoTreeContextMenu(QContextMenuEvent * event)
|
|||
{
|
||||
char * selectedfilter = proto_construct_match_selected_string(fi, edt);
|
||||
bool can_match_selected = proto_can_match_selected(fi, edt);
|
||||
QMenu * main_menu_item = new QMenu(tr("Apply as Filter"), &ctxMenu);
|
||||
QActionGroup * group = FilterAction::createFilterGroup(selectedfilter, false, can_match_selected, &ctxMenu);
|
||||
main_menu_item->addActions(group->actions());
|
||||
ctxMenu.addMenu(main_menu_item);
|
||||
main_menu_item = new QMenu(tr("Prepare as Filter"), &ctxMenu);
|
||||
group = FilterAction::createFilterGroup(selectedfilter, true, can_match_selected, &ctxMenu);
|
||||
main_menu_item->addActions(group->actions());
|
||||
ctxMenu.addMenu(main_menu_item);
|
||||
ctxMenu.addMenu(FilterAction::createFilterMenu(FilterAction::ActionApply, selectedfilter, can_match_selected, &ctxMenu));
|
||||
ctxMenu.addMenu(FilterAction::createFilterMenu(FilterAction::ActionPrepare, selectedfilter, can_match_selected, &ctxMenu));
|
||||
|
||||
if ( selectedfilter )
|
||||
wmem_free(Q_NULLPTR, selectedfilter);
|
||||
ctxMenu.addSeparator();
|
||||
|
@ -341,14 +336,8 @@ void ProtoTree::contextMenuEvent(QContextMenuEvent *event)
|
|||
epan_dissect_t *edt = cap_file_ ? cap_file_->edt : edt_;
|
||||
char * selectedfilter = proto_construct_match_selected_string(finfo.fieldInfo(), edt);
|
||||
bool can_match_selected = proto_can_match_selected(finfo.fieldInfo(), edt);
|
||||
main_menu_item = new QMenu(tr("Apply as Filter"), &ctx_menu);
|
||||
QActionGroup * group = FilterAction::createFilterGroup(selectedfilter, false, can_match_selected, &ctx_menu);
|
||||
main_menu_item->addActions(group->actions());
|
||||
ctx_menu.addMenu(main_menu_item);
|
||||
main_menu_item = new QMenu(tr("Prepare as Filter"), &ctx_menu);
|
||||
group = FilterAction::createFilterGroup(selectedfilter, true, can_match_selected, &ctx_menu);
|
||||
main_menu_item->addActions(group->actions());
|
||||
ctx_menu.addMenu(main_menu_item);
|
||||
ctx_menu.addMenu(FilterAction::createFilterMenu(FilterAction::ActionApply, selectedfilter, can_match_selected, &ctx_menu));
|
||||
ctx_menu.addMenu(FilterAction::createFilterMenu(FilterAction::ActionPrepare, selectedfilter, can_match_selected, &ctx_menu));
|
||||
if ( selectedfilter )
|
||||
wmem_free(Q_NULLPTR, selectedfilter);
|
||||
|
||||
|
|
Loading…
Reference in New Issue