From f6534b8a972a87d52d6422e87bda92b82f174243 Mon Sep 17 00:00:00 2001 From: Roland Knall Date: Thu, 29 Aug 2019 14:30:45 +0200 Subject: Qt: ProtoTree combine menus The menu for a prototree when opened from a packetdialog was different than the one opened underneath packetlist. Those two are now the same. Change-Id: I57572287daa5a3b1de1f5bc8e95b382d5869af6e Reviewed-on: https://code.wireshark.org/review/34395 Petri-Dish: Roland Knall Tested-by: Petri Dish Buildbot Reviewed-by: Roland Knall --- ui/qt/proto_tree.cpp | 255 +++++++++++++++++++-------------------------------- ui/qt/proto_tree.h | 1 - 2 files changed, 94 insertions(+), 162 deletions(-) diff --git a/ui/qt/proto_tree.cpp b/ui/qt/proto_tree.cpp index d9e49a63cf..6441b1b3ee 100644 --- a/ui/qt/proto_tree.cpp +++ b/ui/qt/proto_tree.cpp @@ -101,104 +101,6 @@ void ProtoTree::clear() { updateContentWidth(); } -void ProtoTree::protoTreeContextMenu(QContextMenuEvent * event) -{ - QMenu ctxMenu(this); - QAction * action; - - bool have_subtree = false; -#if 0 - bool have_packet_bytes = false; -#endif - - QModelIndex index = indexAt(event->pos()); - field_info * fi = Q_NULLPTR; - if ( index.isValid() ) - { - FieldInformation finfo(proto_tree_model_->protoNodeFromIndex(index).protoNode()); - fi = finfo.fieldInfo(); - - bool is_selected = false; - - if (cap_file_ && cap_file_->finfo_selected == fi) - is_selected = true; - else if (! window()->findChild("actionViewExpandSubtrees")) - is_selected = true; - - if ( is_selected ) - { - if (fi && fi->tree_type != -1) { - have_subtree = true; - } -#if 0 - if (fi && fi->ds_tvb) { - have_packet_bytes = true; - } -#endif - } - } - - - action = ctxMenu.addAction(tr("Expand Subtrees"), this, SLOT(expandSubtrees())); - action->setEnabled(have_subtree); - action = ctxMenu.addAction(tr("Collapse Subtrees"), this, SLOT(collapseSubtrees())); - action->setEnabled(have_subtree); - ctxMenu.addAction(tr("Expand All"), this, SLOT(expandAll())); - ctxMenu.addAction(tr("Collapse All"), this, SLOT(collapseAll())); - ctxMenu.addSeparator(); - - epan_dissect_t *edt = cap_file_ ? cap_file_->edt : edt_; - if ( fi && edt ) - { - char * selectedfilter = proto_construct_match_selected_string(fi, edt); - bool can_match_selected = proto_can_match_selected(fi, edt); - 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(); - } - - QMenu *submenu = ctxMenu.addMenu(tr("Copy")); - submenu->addAction(tr("All Visible Items"), this, SLOT(ctxCopyVisibleItems())); - action = submenu->addAction(tr("All Visible Selected Tree Items"), this, SLOT(ctxCopyVisibleItems())); - action->setProperty("selected_tree", qVariantFromValue(true)); - action = submenu->addAction(tr("Desription"), this, SLOT(ctxCopySelectedInfo())); - action->setProperty("field_type", ProtoTree::Description); - action = submenu->addAction(tr("Field Name"), this, SLOT(ctxCopySelectedInfo())); - action->setProperty("field_type", ProtoTree::Name); - action = submenu->addAction(tr("Value"), this, SLOT(ctxCopySelectedInfo())); - action->setProperty("field_type", ProtoTree::Value); - submenu->addSeparator(); - submenu->addAction(tr("As Filter"), this, SLOT(ctxCopyAsFilter())); - - ctxMenu.addSeparator(); - - ctxMenu.addAction(tr("Wiki Protocol Page"), this, SLOT(ctxOpenUrlWiki())); - action = ctxMenu.addAction(tr("Filter Field Reference"), this, SLOT(ctxOpenUrlWiki())); - action->setProperty("field_reference", qVariantFromValue(true)); - ctxMenu.addMenu(&proto_prefs_menu_); - - QModelIndex idx = indexAt(event->pos()); - FieldInformation finfo(proto_tree_model_->protoNodeFromIndex(idx).protoNode()); - QActionGroup * copyEntries = DataPrinter::copyActions(this, &finfo); - submenu->addActions(copyEntries->actions()); - - - // The "text only" header field will not give preferences for the selected protocol. - // Use parent in this case. - proto_node *node = proto_tree_model_->protoNodeFromIndex(idx).protoNode(); - while (node && node->finfo && node->finfo->hfinfo && node->finfo->hfinfo->id == hf_text_only) - node = node->parent; - - FieldInformation pref_finfo(node); - proto_prefs_menu_.setModule(pref_finfo.moduleName()); - - - ctxMenu.exec(event->globalPos()); -} - void ProtoTree::ctxCopyVisibleItems() { bool selected_tree = false; @@ -308,32 +210,53 @@ void ProtoTree::ctxOpenUrlWiki() void ProtoTree::contextMenuEvent(QContextMenuEvent *event) { + QModelIndex index = indexAt(event->pos()); + if ( ! index.isValid() ) + return; + // We're in a PacketDialog + bool buildForDialog = false; if (! window()->findChild("actionViewExpandSubtrees")) - { - protoTreeContextMenu(event); - return; - } + buildForDialog = true; QMenu ctx_menu(this); QMenu *main_menu_item, *submenu; QAction *action; - ctx_menu.addAction(window()->findChild("actionViewExpandSubtrees")); - ctx_menu.addAction(window()->findChild("actionViewCollapseSubtrees")); - ctx_menu.addAction(window()->findChild("actionViewExpandAll")); - ctx_menu.addAction(window()->findChild("actionViewCollapseAll")); - ctx_menu.addSeparator(); + bool have_subtree = false; + FieldInformation finfo(proto_tree_model_->protoNodeFromIndex(index).protoNode()); + field_info * fi = finfo.fieldInfo(); + bool is_selected = false; + epan_dissect_t *edt = cap_file_ ? cap_file_->edt : edt_; + + if (cap_file_ && cap_file_->finfo_selected == fi) + is_selected = true; + else if (! window()->findChild("actionViewExpandSubtrees")) + is_selected = true; + + if ( is_selected ) + { + if (fi && fi->tree_type != -1) { + have_subtree = true; + } + } - action = window()->findChild("actionAnalyzeCreateAColumn"); - ctx_menu.addAction(action); + action = ctx_menu.addAction(tr("Expand Subtrees"), this, SLOT(expandSubtrees())); + action->setEnabled(have_subtree); + action = ctx_menu.addAction(tr("Collapse Subtrees"), this, SLOT(collapseSubtrees())); + action->setEnabled(have_subtree); + ctx_menu.addAction(tr("Expand All"), this, SLOT(expandAll())); + ctx_menu.addAction(tr("Collapse All"), this, SLOT(collapseAll())); ctx_menu.addSeparator(); - QModelIndex index = indexAt(event->pos()); - FieldInformation finfo(proto_tree_model_->protoNodeFromIndex(index).protoNode()); + if ( ! buildForDialog ) + { + action = window()->findChild("actionAnalyzeCreateAColumn"); + ctx_menu.addAction(action); + ctx_menu.addSeparator(); + } - 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); ctx_menu.addMenu(FilterAction::createFilterMenu(FilterAction::ActionApply, selectedfilter, can_match_selected, &ctx_menu)); @@ -341,75 +264,85 @@ void ProtoTree::contextMenuEvent(QContextMenuEvent *event) if ( selectedfilter ) wmem_free(Q_NULLPTR, selectedfilter); - QMenu *main_conv_menu = window()->findChild("menuConversationFilter"); - conv_menu_.setTitle(main_conv_menu->title()); - conv_menu_.clear(); - foreach (QAction *action, main_conv_menu->actions()) { - conv_menu_.addAction(action); - } - - ctx_menu.addMenu(&conv_menu_); + if ( ! buildForDialog ) + { + QMenu *main_conv_menu = window()->findChild("menuConversationFilter"); + conv_menu_.setTitle(main_conv_menu->title()); + conv_menu_.clear(); + foreach (QAction *action, main_conv_menu->actions()) { + conv_menu_.addAction(action); + } - colorize_menu_.setTitle(tr("Colorize with Filter")); - ctx_menu.addMenu(&colorize_menu_); + ctx_menu.addMenu(&conv_menu_); - main_menu_item = window()->findChild("menuFollow"); - submenu = new QMenu(main_menu_item->title(), &ctx_menu); - ctx_menu.addMenu(submenu); - submenu->addAction(window()->findChild("actionAnalyzeFollowTCPStream")); - submenu->addAction(window()->findChild("actionAnalyzeFollowUDPStream")); - submenu->addAction(window()->findChild("actionAnalyzeFollowTLSStream")); - submenu->addAction(window()->findChild("actionAnalyzeFollowHTTPStream")); - ctx_menu.addSeparator(); + colorize_menu_.setTitle(tr("Colorize with Filter")); + ctx_menu.addMenu(&colorize_menu_); - main_menu_item = window()->findChild("menuEditCopy"); - submenu = new QMenu(main_menu_item->title(), &ctx_menu); - ctx_menu.addMenu(submenu); - submenu->addAction(window()->findChild("actionCopyAllVisibleItems")); - submenu->addAction(window()->findChild("actionCopyAllVisibleSelectedTreeItems")); - submenu->addAction(window()->findChild("actionEditCopyDescription")); - submenu->addAction(window()->findChild("actionEditCopyFieldName")); - submenu->addAction(window()->findChild("actionEditCopyValue")); - submenu->addSeparator(); + main_menu_item = window()->findChild("menuFollow"); + submenu = new QMenu(main_menu_item->title(), &ctx_menu); + ctx_menu.addMenu(submenu); + submenu->addAction(window()->findChild("actionAnalyzeFollowTCPStream")); + submenu->addAction(window()->findChild("actionAnalyzeFollowUDPStream")); + submenu->addAction(window()->findChild("actionAnalyzeFollowTLSStream")); + submenu->addAction(window()->findChild("actionAnalyzeFollowHTTPStream")); + ctx_menu.addSeparator(); + } - submenu->addAction(window()->findChild("actionEditCopyAsFilter")); + submenu = ctx_menu.addMenu(tr("Copy")); + submenu->addAction(tr("All Visible Items"), this, SLOT(ctxCopyVisibleItems())); + action = submenu->addAction(tr("All Visible Selected Tree Items"), this, SLOT(ctxCopyVisibleItems())); + action->setProperty("selected_tree", qVariantFromValue(true)); + action = submenu->addAction(tr("Desription"), this, SLOT(ctxCopySelectedInfo())); + action->setProperty("field_type", ProtoTree::Description); + action = submenu->addAction(tr("Field Name"), this, SLOT(ctxCopySelectedInfo())); + action->setProperty("field_type", ProtoTree::Name); + action = submenu->addAction(tr("Value"), this, SLOT(ctxCopySelectedInfo())); + action->setProperty("field_type", ProtoTree::Value); submenu->addSeparator(); - + submenu->addAction(tr("As Filter"), this, SLOT(ctxCopyAsFilter())); QActionGroup * copyEntries = DataPrinter::copyActions(this, &finfo); submenu->addActions(copyEntries->actions()); + ctx_menu.addSeparator(); - action = window()->findChild("actionAnalyzeShowPacketBytes"); - ctx_menu.addAction(action); - action = window()->findChild("actionFileExportPacketBytes"); - ctx_menu.addAction(action); + if ( ! buildForDialog ) + { + action = window()->findChild("actionAnalyzeShowPacketBytes"); + ctx_menu.addAction(action); + action = window()->findChild("actionFileExportPacketBytes"); + ctx_menu.addAction(action); - ctx_menu.addSeparator(); + ctx_menu.addSeparator(); + } - action = window()->findChild("actionContextWikiProtocolPage"); - ctx_menu.addAction(action); - action = window()->findChild("actionContextFilterFieldReference"); - ctx_menu.addAction(action); + ctx_menu.addAction(tr("Wiki Protocol Page"), this, SLOT(ctxOpenUrlWiki())); + action = ctx_menu.addAction(tr("Filter Field Reference"), this, SLOT(ctxOpenUrlWiki())); + action->setProperty("field_reference", qVariantFromValue(true)); ctx_menu.addMenu(&proto_prefs_menu_); ctx_menu.addSeparator(); decode_as_ = window()->findChild("actionAnalyzeDecodeAs"); ctx_menu.addAction(decode_as_); - ctx_menu.addAction(window()->findChild("actionGoGoToLinkedPacket")); - ctx_menu.addAction(window()->findChild("actionContextShowLinkedPacketInNewWindow")); + if ( ! buildForDialog ) + { + ctx_menu.addAction(window()->findChild("actionGoGoToLinkedPacket")); + ctx_menu.addAction(window()->findChild("actionContextShowLinkedPacketInNewWindow")); - // The "text only" header field will not give preferences for the selected protocol. - // Use parent in this case. - proto_node *node = proto_tree_model_->protoNodeFromIndex(index).protoNode(); - while (node && node->finfo && node->finfo->hfinfo && node->finfo->hfinfo->id == hf_text_only) - node = node->parent; + // The "text only" header field will not give preferences for the selected protocol. + // Use parent in this case. + proto_node *node = proto_tree_model_->protoNodeFromIndex(index).protoNode(); + while (node && node->finfo && node->finfo->hfinfo && node->finfo->hfinfo->id == hf_text_only) + node = node->parent; - FieldInformation pref_finfo(node); - proto_prefs_menu_.setModule(pref_finfo.moduleName()); + FieldInformation pref_finfo(node); + proto_prefs_menu_.setModule(pref_finfo.moduleName()); - decode_as_->setData(QVariant::fromValue(true)); + decode_as_->setData(QVariant::fromValue(true)); + } ctx_menu.exec(event->globalPos()); - decode_as_->setData(QVariant()); + + if ( ! buildForDialog ) + decode_as_->setData(QVariant()); } void ProtoTree::timerEvent(QTimerEvent *event) diff --git a/ui/qt/proto_tree.h b/ui/qt/proto_tree.h index e4794796d8..36ee3bdc16 100644 --- a/ui/qt/proto_tree.h +++ b/ui/qt/proto_tree.h @@ -48,7 +48,6 @@ protected: } CopyInfos; virtual void contextMenuEvent(QContextMenuEvent *event); - void protoTreeContextMenu(QContextMenuEvent * event); virtual void timerEvent(QTimerEvent *event); virtual void keyReleaseEvent(QKeyEvent *event); virtual bool eventFilter(QObject * obj, QEvent * ev); -- cgit v1.2.3