aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRoland Knall <rknall@gmail.com>2019-08-26 17:08:09 +0200
committerRoland Knall <rknall@gmail.com>2019-08-26 20:26:17 +0000
commitb84a8e29e88b88f581e76c29bbcf7e2268651810 (patch)
tree724628e225b926d40f3511b73a3d020b22b24104
parent9bd2eef45ee657f90dff7e2e00354eee3d128e37 (diff)
Qt: Create Apply/Prepare in Packetlist
Create the menu for apply/prepare inside Packetlist. At the same time disabled the "..." methods if no filter has been set yet Move the action list to FilterAction as well Change-Id: Ia18a4021cc95562702ff516a24fb029063096f94 Reviewed-on: https://code.wireshark.org/review/34377 Petri-Dish: Roland Knall <rknall@gmail.com> Tested-by: Petri Dish Buildbot Reviewed-by: Roland Knall <rknall@gmail.com>
-rw-r--r--ui/qt/filter_action.cpp17
-rw-r--r--ui/qt/packet_list.cpp35
2 files changed, 32 insertions, 20 deletions
diff --git a/ui/qt/filter_action.cpp b/ui/qt/filter_action.cpp
index 490350d1df..cef643619d 100644
--- a/ui/qt/filter_action.cpp
+++ b/ui/qt/filter_action.cpp
@@ -182,7 +182,15 @@ const QString FilterAction::actionDirectionName(ActionDirection direction) {
QActionGroup * FilterAction::createFilterGroup(QString filter, bool prepare, bool enabled, QWidget * parent)
{
if ( filter.isEmpty() )
- return Q_NULLPTR;
+ enabled = false;
+
+ bool filterEmpty = false;
+ if ( wsApp )
+ {
+ QWidget * mainWin = wsApp->mainWindow();
+ if ( qobject_cast<MainWindow *>(mainWin) )
+ filterEmpty = qobject_cast<MainWindow *>(mainWin)->getFilter().isEmpty();
+ }
FilterAction * filterAction = new FilterAction(parent, prepare ? FilterAction::ActionPrepare : FilterAction::ActionApply);
@@ -195,14 +203,19 @@ QActionGroup * FilterAction::createFilterGroup(QString filter, bool prepare, boo
action->setProperty("filterType", FilterAction::ActionTypeNot);
action = group->addAction(tr(UTF8_HORIZONTAL_ELLIPSIS "and Selected"));
action->setProperty("filterType", FilterAction::ActionTypeAnd);
+ action->setEnabled(!filterEmpty);
action = group->addAction(tr(UTF8_HORIZONTAL_ELLIPSIS "or Selected"));
action->setProperty("filterType", FilterAction::ActionTypeOr);
+ action->setEnabled(!filterEmpty);
action = group->addAction(tr(UTF8_HORIZONTAL_ELLIPSIS "and not Selected"));
action->setProperty("filterType", FilterAction::ActionTypeAndNot);
+ action->setEnabled(!filterEmpty);
action = group->addAction(tr(UTF8_HORIZONTAL_ELLIPSIS "or not Selected"));
action->setProperty("filterType", FilterAction::ActionTypeOrNot);
+ action->setEnabled(!filterEmpty);
group->setEnabled(enabled);
- connect(group, &QActionGroup::triggered, filterAction, &FilterAction::groupTriggered);
+ if ( ! filter.isEmpty() )
+ connect(group, &QActionGroup::triggered, filterAction, &FilterAction::groupTriggered);
return group;
}
diff --git a/ui/qt/packet_list.cpp b/ui/qt/packet_list.cpp
index ee4ba6d47f..ffbab0f90f 100644
--- a/ui/qt/packet_list.cpp
+++ b/ui/qt/packet_list.cpp
@@ -51,6 +51,7 @@
#include <ui/qt/widgets/packet_list_header.h>
#include <ui/qt/utils/wireshark_mime_data.h>
#include <ui/qt/widgets/drag_label.h>
+#include <ui/qt/filter_action.h>
#include <QAction>
#include <QActionGroup>
@@ -500,28 +501,26 @@ void PacketList::contextMenuEvent(QContextMenuEvent *event)
ctx_menu.addAction(window()->findChild<QAction *>("actionViewEditResolvedName"));
ctx_menu.addSeparator();
- QMenu *main_menu_item = window()->findChild<QMenu *>("menuApplyAsFilter");
- QMenu *submenu = new QMenu(main_menu_item->title(), &ctx_menu);
+ QString selectedfilter = getFilterFromRowAndColumn(currentIndex());
+
+ if ( ! hasFocus() && cap_file_ && cap_file_->finfo_selected) {
+ char *tmp_field = proto_construct_match_selected_string(cap_file_->finfo_selected, cap_file_->edt);
+ selectedfilter = QString(tmp_field);
+ wmem_free(NULL, tmp_field);
+ }
+
+ 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->addAction(window()->findChild<QAction *>("actionAnalyzeAAFSelected"));
- submenu->addAction(window()->findChild<QAction *>("actionAnalyzeAAFNotSelected"));
- submenu->addAction(window()->findChild<QAction *>("actionAnalyzeAAFAndSelected"));
- submenu->addAction(window()->findChild<QAction *>("actionAnalyzeAAFOrSelected"));
- submenu->addAction(window()->findChild<QAction *>("actionAnalyzeAAFAndNotSelected"));
- submenu->addAction(window()->findChild<QAction *>("actionAnalyzeAAFOrNotSelected"));
-
- main_menu_item = window()->findChild<QMenu *>("menuPrepareAFilter");
- submenu = new QMenu(main_menu_item->title(), &ctx_menu);
+ 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);
- submenu->addAction(window()->findChild<QAction *>("actionAnalyzePAFSelected"));
- submenu->addAction(window()->findChild<QAction *>("actionAnalyzePAFNotSelected"));
- submenu->addAction(window()->findChild<QAction *>("actionAnalyzePAFAndSelected"));
- submenu->addAction(window()->findChild<QAction *>("actionAnalyzePAFOrSelected"));
- submenu->addAction(window()->findChild<QAction *>("actionAnalyzePAFAndNotSelected"));
- submenu->addAction(window()->findChild<QAction *>("actionAnalyzePAFOrNotSelected"));
const char *conv_menu_name = "menuConversationFilter";
- main_menu_item = window()->findChild<QMenu *>(conv_menu_name);
+ QMenu * main_menu_item = window()->findChild<QMenu *>(conv_menu_name);
conv_menu_.setTitle(main_menu_item->title());
conv_menu_.setObjectName(conv_menu_name);
ctx_menu.addMenu(&conv_menu_);