Qt: List all protocols in PacketList "Protocol Preferences"

Show all protocols which has preferences in the packet list context
menu "Protocol Preferences".

Change-Id: I72e2ed95db36cc6d817ca44db214782f075d55d6
Reviewed-on: https://code.wireshark.org/review/37666
Petri-Dish: Stig Bjørlykke <stig@bjorlykke.org>
Tested-by: Petri Dish Buildbot
Reviewed-by: Stig Bjørlykke <stig@bjorlykke.org>
This commit is contained in:
Stig Bjørlykke 2020-07-02 10:20:14 +02:00
parent 7bf8a87429
commit a6d8a2c118
4 changed files with 33 additions and 17 deletions

View File

@ -239,6 +239,8 @@ PacketList::PacketList(QWidget *parent) :
setUniformRowHeights(true);
setAccessibleName("Packet list");
proto_prefs_menus_.setTitle(tr("Protocol Preferences"));
packet_list_header_ = new PacketListHeader(header()->orientation(), cap_file_);
connect(packet_list_header_, &PacketListHeader::resetColumnWidth, this, &PacketList::setRecentColumnWidth);
connect(packet_list_header_, &PacketListHeader::updatePackets, this, &PacketList::updatePackets);
@ -279,11 +281,6 @@ PacketList::PacketList(QWidget *parent) :
this, SLOT(sectionMoved(int,int,int)));
connect(verticalScrollBar(), SIGNAL(actionTriggered(int)), this, SLOT(vScrollBarActionTriggered(int)));
connect(&proto_prefs_menu_, SIGNAL(showProtocolPreferences(QString)),
this, SIGNAL(showProtocolPreferences(QString)));
connect(&proto_prefs_menu_, SIGNAL(editProtocolPreference(preference*,pref_module*)),
this, SIGNAL(editProtocolPreference(preference*,pref_module*)));
}
void PacketList::colorsChanged()
@ -591,29 +588,41 @@ void PacketList::selectionChanged (const QItemSelection & selected, const QItemS
void PacketList::contextMenuEvent(QContextMenuEvent *event)
{
const char *module_name = NULL;
if (cap_file_ && cap_file_->edt && cap_file_->edt->tree) {
GPtrArray *finfo_array = proto_all_finfos(cap_file_->edt->tree);
for (guint i = finfo_array->len - 1; i > 0 ; i --) {
proto_prefs_menus_.clear();
if (cap_file_ && cap_file_->edt && cap_file_->edt->tree) {
GPtrArray *finfo_array = proto_all_finfos(cap_file_->edt->tree);
QList<QString> added_proto_prefs;
for (guint i = 0; i < finfo_array->len; i++) {
field_info *fi = (field_info *)g_ptr_array_index (finfo_array, i);
header_field_info *hfinfo = fi->hfinfo;
if (!g_str_has_prefix(hfinfo->abbrev, "text") &&
!g_str_has_prefix(hfinfo->abbrev, "_ws.expert") &&
!g_str_has_prefix(hfinfo->abbrev, "_ws.lua") &&
!g_str_has_prefix(hfinfo->abbrev, "_ws.malformed")) {
if (prefs_is_registered_protocol(hfinfo->abbrev)) {
if (hfinfo->parent == -1) {
module_name = hfinfo->abbrev;
} else {
module_name = proto_registrar_get_abbrev(hfinfo->parent);
}
break;
if (added_proto_prefs.contains(module_name)) {
continue;
}
ProtocolPreferencesMenu *proto_prefs_menu = new ProtocolPreferencesMenu(hfinfo->name, module_name, &proto_prefs_menus_);
connect(proto_prefs_menu, SIGNAL(showProtocolPreferences(QString)),
this, SIGNAL(showProtocolPreferences(QString)));
connect(proto_prefs_menu, SIGNAL(editProtocolPreference(preference*,pref_module*)),
this, SIGNAL(editProtocolPreference(preference*,pref_module*)));
proto_prefs_menus_.addMenu(proto_prefs_menu);
added_proto_prefs << module_name;
}
}
g_ptr_array_free(finfo_array, TRUE);
}
proto_prefs_menu_.setModule(module_name);
QModelIndex ctxIndex = indexAt(event->pos());
@ -705,7 +714,7 @@ void PacketList::contextMenuEvent(QContextMenuEvent *event)
frameData->setParent(submenu);
ctx_menu->addSeparator();
ctx_menu->addMenu(&proto_prefs_menu_);
ctx_menu->addMenu(&proto_prefs_menus_);
action = ctx_menu->addAction(tr("Decode As" UTF8_HORIZONTAL_ELLIPSIS));
action->setProperty("create_new", QVariant(true));
connect(action, &QAction::triggered, this, &PacketList::ctxDecodeAsDialog);

View File

@ -114,7 +114,7 @@ private:
capture_file *cap_file_;
QMenu conv_menu_;
QMenu colorize_menu_;
ProtocolPreferencesMenu proto_prefs_menu_;
QMenu proto_prefs_menus_;
int ctx_column_;
QByteArray column_state_;
OverlayScrollBar *overlay_sb_;

View File

@ -136,6 +136,12 @@ ProtocolPreferencesMenu::ProtocolPreferencesMenu()
setModule(NULL);
}
ProtocolPreferencesMenu::ProtocolPreferencesMenu(const QString &title, const QString &module_name, QWidget *parent) :
QMenu(title, parent)
{
setModule(module_name);
}
void ProtocolPreferencesMenu::setModule(const QString module_name)
{
QAction *action;

View File

@ -22,6 +22,7 @@ class ProtocolPreferencesMenu : public QMenu
public:
ProtocolPreferencesMenu();
ProtocolPreferencesMenu(const QString &title, const QString &module_name, QWidget *parent = nullptr);
void setModule(const QString module_name);
void addMenuItem(struct preference *pref);