From fc461d1592f35f25e30a68bcbab936a66dc853c8 Mon Sep 17 00:00:00 2001 From: Gerald Combs Date: Sun, 25 Sep 2022 13:31:59 -0700 Subject: [PATCH] Qt: Manually connect our "Go" menu actions. --- ui/logray/logray_main_window.cpp | 23 +-- ui/logray/logray_main_window.h | 7 +- ui/logray/logray_main_window_slots.cpp | 187 ++++++++++++++----------- ui/qt/wireshark_main_window.cpp | 23 +-- ui/qt/wireshark_main_window.h | 7 +- ui/qt/wireshark_main_window_slots.cpp | 187 ++++++++++++++----------- 6 files changed, 218 insertions(+), 216 deletions(-) diff --git a/ui/logray/logray_main_window.cpp b/ui/logray/logray_main_window.cpp index e7181e73b3..725cf34563 100644 --- a/ui/logray/logray_main_window.cpp +++ b/ui/logray/logray_main_window.cpp @@ -601,28 +601,7 @@ main_ui_->goToLineEdit->setValidator(goToLineQiv); connectFileMenuActions(); connectEditMenuActions(); connectViewMenuActions(); - - connect(main_ui_->actionGoNextPacket, SIGNAL(triggered()), - packet_list_, SLOT(goNextPacket())); - connect(main_ui_->actionGoPreviousPacket, SIGNAL(triggered()), - packet_list_, SLOT(goPreviousPacket())); - connect(main_ui_->actionGoFirstPacket, SIGNAL(triggered()), - packet_list_, SLOT(goFirstPacket())); - connect(main_ui_->actionGoLastPacket, SIGNAL(triggered()), - packet_list_, SLOT(goLastPacket())); - connect(main_ui_->actionGoNextHistoryPacket, SIGNAL(triggered()), - packet_list_, SLOT(goNextHistoryPacket())); - connect(main_ui_->actionGoPreviousHistoryPacket, SIGNAL(triggered()), - packet_list_, SLOT(goPreviousHistoryPacket())); - - connect(main_ui_->actionViewExpandSubtrees, SIGNAL(triggered()), - proto_tree_, SLOT(expandSubtrees())); - connect(main_ui_->actionViewCollapseSubtrees, SIGNAL(triggered()), - proto_tree_, SLOT(collapseSubtrees())); - connect(main_ui_->actionViewExpandAll, SIGNAL(triggered()), - proto_tree_, SLOT(expandAll())); - connect(main_ui_->actionViewCollapseAll, SIGNAL(triggered()), - proto_tree_, SLOT(collapseAll())); + connectGoMenuActions(); connect(packet_list_, SIGNAL(packetDissectionChanged()), this, SLOT(redissectPackets())); diff --git a/ui/logray/logray_main_window.h b/ui/logray/logray_main_window.h index e77cafdda6..005efab83c 100644 --- a/ui/logray/logray_main_window.h +++ b/ui/logray/logray_main_window.h @@ -418,11 +418,8 @@ private slots: void reloadCaptureFileAsFormatOrCapture(); void reloadCaptureFile(); - void on_actionGoGoToPacket_triggered(); - void on_actionGoGoToLinkedPacket_triggered(); - void on_actionGoNextConversationPacket_triggered(); - void on_actionGoPreviousConversationPacket_triggered(); - void on_actionGoAutoScroll_toggled(bool checked); + void connectGoMenuActions(); + void resetPreviousFocus(); void on_actionCaptureOptions_triggered(); diff --git a/ui/logray/logray_main_window_slots.cpp b/ui/logray/logray_main_window_slots.cpp index f423ee17c7..8c1765626c 100644 --- a/ui/logray/logray_main_window_slots.cpp +++ b/ui/logray/logray_main_window_slots.cpp @@ -2224,6 +2224,18 @@ void LograyMainWindow::connectViewMenuActions() zoomText(); }); + connect(main_ui_->actionViewExpandSubtrees, &QAction::triggered, + proto_tree_, &ProtoTree::expandSubtrees); + + connect(main_ui_->actionViewCollapseSubtrees, &QAction::triggered, + proto_tree_, &ProtoTree::collapseSubtrees); + + connect(main_ui_->actionViewExpandAll, &QAction::triggered, + proto_tree_, &ProtoTree::expandAll); + + connect(main_ui_->actionViewCollapseAll, &QAction::triggered, + proto_tree_, &ProtoTree::collapseAll); + connect(main_ui_->actionViewColorizePacketList, &QAction::triggered, this, [this](bool checked) { recent.packet_list_colorize = checked; packet_list_->recolorPackets(); @@ -2597,6 +2609,100 @@ void LograyMainWindow::reloadCaptureFile() // Go Menu +void LograyMainWindow::connectGoMenuActions() +{ + connect(main_ui_->actionGoGoToPacket, &QAction::triggered, this, [this]() { + if (! packet_list_->model() || packet_list_->model()->rowCount() < 1) { + return; + } + previous_focus_ = mainApp->focusWidget(); + connect(previous_focus_, SIGNAL(destroyed()), this, SLOT(resetPreviousFocus())); + + showAccordionFrame(main_ui_->goToFrame, true); + if (main_ui_->goToFrame->isVisible()) { + main_ui_->goToLineEdit->clear(); + main_ui_->goToLineEdit->setFocus(); + } + }); + + connect(main_ui_->actionGoGoToLinkedPacket, &QAction::triggered, this, [this]() { + QAction *gta = qobject_cast(sender()); + if (!gta) return; + + bool ok = false; + int packet_num = gta->data().toInt(&ok); + if (!ok) return; + + packet_list_->goToPacket(packet_num); + }); + + connect(main_ui_->actionGoNextPacket, &QAction::triggered, + packet_list_, &PacketList::goNextPacket); + + connect(main_ui_->actionGoPreviousPacket, &QAction::triggered, + packet_list_, &PacketList::goPreviousPacket); + + connect(main_ui_->actionGoFirstPacket, &QAction::triggered, + packet_list_, &PacketList::goFirstPacket); + + connect(main_ui_->actionGoLastPacket, &QAction::triggered, + packet_list_, &PacketList::goLastPacket); + + connect(main_ui_->actionGoNextConversationPacket, &QAction::triggered, this, + [this]() { goToConversationFrame(true); }); + + connect(main_ui_->actionGoPreviousConversationPacket, &QAction::triggered, this, + [this]() { goToConversationFrame(false); }); + + connect(main_ui_->actionGoNextHistoryPacket, &QAction::triggered, + packet_list_, &PacketList::goNextHistoryPacket); + + connect(main_ui_->actionGoPreviousHistoryPacket, &QAction::triggered, + packet_list_, &PacketList::goPreviousHistoryPacket); + + connect(main_ui_->actionGoAutoScroll, &QAction::triggered, this, + [this](bool checked) { packet_list_->setVerticalAutoScroll(checked); }); +} + +void LograyMainWindow::goToConversationFrame(bool go_next) { + gchar *filter = NULL; + dfilter_t *dfcode = NULL; + gboolean found_packet = FALSE; + packet_info *pi = capture_file_.packetInfo(); + + if (!pi) { + // No packet was selected, or multiple packets were selected. + return; + } + + /* Try to build a conversation + * filter in the order TCP, UDP, IP, Ethernet and apply the + * coloring */ + filter = conversation_filter_from_log(pi); + if (filter == NULL) { + mainApp->pushStatus(WiresharkApplication::TemporaryStatus, tr("Unable to build conversation filter.")); + g_free(filter); + return; + } + + if (!dfilter_compile(filter, &dfcode, NULL)) { + /* The attempt failed; report an error. */ + mainApp->pushStatus(WiresharkApplication::TemporaryStatus, tr("Error compiling filter for this conversation.")); + g_free(filter); + return; + } + + found_packet = cf_find_packet_dfilter(capture_file_.capFile(), dfcode, go_next ? SD_FORWARD : SD_BACKWARD); + + if (!found_packet) { + /* We didn't find a packet */ + mainApp->pushStatus(WiresharkApplication::TemporaryStatus, tr("No previous/next packet in conversation.")); + } + + dfilter_free(dfcode); + g_free(filter); +} + // Analyze Menu void LograyMainWindow::filterMenuAboutToShow() @@ -2954,87 +3060,6 @@ void LograyMainWindow::on_actionHelpAbout_triggered() about_dialog->activateWindow(); } -void LograyMainWindow::on_actionGoGoToPacket_triggered() { - if (! packet_list_->model() || packet_list_->model()->rowCount() < 1) { - return; - } - previous_focus_ = mainApp->focusWidget(); - connect(previous_focus_, SIGNAL(destroyed()), this, SLOT(resetPreviousFocus())); - - showAccordionFrame(main_ui_->goToFrame, true); - if (main_ui_->goToFrame->isVisible()) { - main_ui_->goToLineEdit->clear(); - main_ui_->goToLineEdit->setFocus(); - } -} - -void LograyMainWindow::on_actionGoGoToLinkedPacket_triggered() -{ - QAction *gta = qobject_cast(sender()); - if (!gta) return; - - bool ok = false; - int packet_num = gta->data().toInt(&ok); - if (!ok) return; - - packet_list_->goToPacket(packet_num); -} - -// gtk/main_menubar.c:goto_conversation_frame -void LograyMainWindow::goToConversationFrame(bool go_next) { - gchar *filter = NULL; - dfilter_t *dfcode = NULL; - gboolean found_packet = FALSE; - packet_info *pi = capture_file_.packetInfo(); - - if (!pi) { - // No packet was selected, or multiple packets were selected. - return; - } - - /* Try to build a conversation - * filter in the order TCP, UDP, IP, Ethernet and apply the - * coloring */ - filter = conversation_filter_from_log(pi); - if (filter == NULL) { - mainApp->pushStatus(WiresharkApplication::TemporaryStatus, tr("Unable to build conversation filter.")); - g_free(filter); - return; - } - - if (!dfilter_compile(filter, &dfcode, NULL)) { - /* The attempt failed; report an error. */ - mainApp->pushStatus(WiresharkApplication::TemporaryStatus, tr("Error compiling filter for this conversation.")); - g_free(filter); - return; - } - - found_packet = cf_find_packet_dfilter(capture_file_.capFile(), dfcode, go_next ? SD_FORWARD : SD_BACKWARD); - - if (!found_packet) { - /* We didn't find a packet */ - mainApp->pushStatus(WiresharkApplication::TemporaryStatus, tr("No previous/next packet in conversation.")); - } - - dfilter_free(dfcode); - g_free(filter); -} - -void LograyMainWindow::on_actionGoNextConversationPacket_triggered() -{ - goToConversationFrame(true); -} - -void LograyMainWindow::on_actionGoPreviousConversationPacket_triggered() -{ - goToConversationFrame(false); -} - -void LograyMainWindow::on_actionGoAutoScroll_toggled(bool checked) -{ - packet_list_->setVerticalAutoScroll(checked); -} - void LograyMainWindow::resetPreviousFocus() { previous_focus_ = NULL; } diff --git a/ui/qt/wireshark_main_window.cpp b/ui/qt/wireshark_main_window.cpp index 525b5e76eb..eab8b1445c 100644 --- a/ui/qt/wireshark_main_window.cpp +++ b/ui/qt/wireshark_main_window.cpp @@ -629,6 +629,7 @@ main_ui_->goToLineEdit->setValidator(goToLineQiv); connectFileMenuActions(); connectEditMenuActions(); connectViewMenuActions(); + connectGoMenuActions(); connect(main_ui_->actionAnalyzeFollowTCPStream, &QAction::triggered, this, [this]() { this->openFollowStreamDialogForType(FOLLOW_TCP); }, @@ -655,28 +656,6 @@ main_ui_->goToLineEdit->setValidator(goToLineQiv); [this]() { this->openFollowStreamDialogForType(FOLLOW_SIP); }, Qt::QueuedConnection); - connect(main_ui_->actionGoNextPacket, SIGNAL(triggered()), - packet_list_, SLOT(goNextPacket())); - connect(main_ui_->actionGoPreviousPacket, SIGNAL(triggered()), - packet_list_, SLOT(goPreviousPacket())); - connect(main_ui_->actionGoFirstPacket, SIGNAL(triggered()), - packet_list_, SLOT(goFirstPacket())); - connect(main_ui_->actionGoLastPacket, SIGNAL(triggered()), - packet_list_, SLOT(goLastPacket())); - connect(main_ui_->actionGoNextHistoryPacket, SIGNAL(triggered()), - packet_list_, SLOT(goNextHistoryPacket())); - connect(main_ui_->actionGoPreviousHistoryPacket, SIGNAL(triggered()), - packet_list_, SLOT(goPreviousHistoryPacket())); - - connect(main_ui_->actionViewExpandSubtrees, SIGNAL(triggered()), - proto_tree_, SLOT(expandSubtrees())); - connect(main_ui_->actionViewCollapseSubtrees, SIGNAL(triggered()), - proto_tree_, SLOT(collapseSubtrees())); - connect(main_ui_->actionViewExpandAll, SIGNAL(triggered()), - proto_tree_, SLOT(expandAll())); - connect(main_ui_->actionViewCollapseAll, SIGNAL(triggered()), - proto_tree_, SLOT(collapseAll())); - connect(packet_list_, SIGNAL(packetDissectionChanged()), this, SLOT(redissectPackets())); connect(packet_list_, SIGNAL(showColumnPreferences(QString)), diff --git a/ui/qt/wireshark_main_window.h b/ui/qt/wireshark_main_window.h index 455a7ee17e..3d520ca72c 100644 --- a/ui/qt/wireshark_main_window.h +++ b/ui/qt/wireshark_main_window.h @@ -443,11 +443,8 @@ private slots: void reloadCaptureFileAsFormatOrCapture(); void reloadCaptureFile(); - void on_actionGoGoToPacket_triggered(); - void on_actionGoGoToLinkedPacket_triggered(); - void on_actionGoNextConversationPacket_triggered(); - void on_actionGoPreviousConversationPacket_triggered(); - void on_actionGoAutoScroll_toggled(bool checked); + void connectGoMenuActions(); + void resetPreviousFocus(); void on_actionCaptureOptions_triggered(); diff --git a/ui/qt/wireshark_main_window_slots.cpp b/ui/qt/wireshark_main_window_slots.cpp index 92884ba0c2..18159155f4 100644 --- a/ui/qt/wireshark_main_window_slots.cpp +++ b/ui/qt/wireshark_main_window_slots.cpp @@ -2391,6 +2391,18 @@ void WiresharkMainWindow::connectViewMenuActions() zoomText(); }); + connect(main_ui_->actionViewExpandSubtrees, &QAction::triggered, + proto_tree_, &ProtoTree::expandSubtrees); + + connect(main_ui_->actionViewCollapseSubtrees, &QAction::triggered, + proto_tree_, &ProtoTree::collapseSubtrees); + + connect(main_ui_->actionViewExpandAll, &QAction::triggered, + proto_tree_, &ProtoTree::expandAll); + + connect(main_ui_->actionViewCollapseAll, &QAction::triggered, + proto_tree_, &ProtoTree::collapseAll); + connect(main_ui_->actionViewColorizePacketList, &QAction::triggered, this, [this](bool checked) { recent.packet_list_colorize = checked; packet_list_->recolorPackets(); @@ -2769,6 +2781,100 @@ void WiresharkMainWindow::reloadCaptureFile() // Go Menu +void WiresharkMainWindow::connectGoMenuActions() +{ + connect(main_ui_->actionGoGoToPacket, &QAction::triggered, this, [this]() { + if (! packet_list_->model() || packet_list_->model()->rowCount() < 1) { + return; + } + previous_focus_ = mainApp->focusWidget(); + connect(previous_focus_, SIGNAL(destroyed()), this, SLOT(resetPreviousFocus())); + + showAccordionFrame(main_ui_->goToFrame, true); + if (main_ui_->goToFrame->isVisible()) { + main_ui_->goToLineEdit->clear(); + main_ui_->goToLineEdit->setFocus(); + } + }); + + connect(main_ui_->actionGoGoToLinkedPacket, &QAction::triggered, this, [this]() { + QAction *gta = qobject_cast(sender()); + if (!gta) return; + + bool ok = false; + int packet_num = gta->data().toInt(&ok); + if (!ok) return; + + packet_list_->goToPacket(packet_num); + }); + + connect(main_ui_->actionGoNextPacket, &QAction::triggered, + packet_list_, &PacketList::goNextPacket); + + connect(main_ui_->actionGoPreviousPacket, &QAction::triggered, + packet_list_, &PacketList::goPreviousPacket); + + connect(main_ui_->actionGoFirstPacket, &QAction::triggered, + packet_list_, &PacketList::goFirstPacket); + + connect(main_ui_->actionGoLastPacket, &QAction::triggered, + packet_list_, &PacketList::goLastPacket); + + connect(main_ui_->actionGoNextConversationPacket, &QAction::triggered, this, + [this]() { goToConversationFrame(true); }); + + connect(main_ui_->actionGoPreviousConversationPacket, &QAction::triggered, this, + [this]() { goToConversationFrame(false); }); + + connect(main_ui_->actionGoNextHistoryPacket, &QAction::triggered, + packet_list_, &PacketList::goNextHistoryPacket); + + connect(main_ui_->actionGoPreviousHistoryPacket, &QAction::triggered, + packet_list_, &PacketList::goPreviousHistoryPacket); + + connect(main_ui_->actionGoAutoScroll, &QAction::triggered, this, + [this](bool checked) { packet_list_->setVerticalAutoScroll(checked); }); +} + +void WiresharkMainWindow::goToConversationFrame(bool go_next) { + gchar *filter = NULL; + dfilter_t *dfcode = NULL; + gboolean found_packet = FALSE; + packet_info *pi = capture_file_.packetInfo(); + + if (!pi) { + // No packet was selected, or multiple packets were selected. + return; + } + + /* Try to build a conversation + * filter in the order TCP, UDP, IP, Ethernet and apply the + * coloring */ + filter = conversation_filter_from_packet(pi); + if (filter == NULL) { + mainApp->pushStatus(WiresharkApplication::TemporaryStatus, tr("Unable to build conversation filter.")); + g_free(filter); + return; + } + + if (!dfilter_compile(filter, &dfcode, NULL)) { + /* The attempt failed; report an error. */ + mainApp->pushStatus(WiresharkApplication::TemporaryStatus, tr("Error compiling filter for this conversation.")); + g_free(filter); + return; + } + + found_packet = cf_find_packet_dfilter(capture_file_.capFile(), dfcode, go_next ? SD_FORWARD : SD_BACKWARD); + + if (!found_packet) { + /* We didn't find a packet */ + mainApp->pushStatus(WiresharkApplication::TemporaryStatus, tr("No previous/next packet in conversation.")); + } + + dfilter_free(dfcode); + g_free(filter); +} + // Analyze Menu void WiresharkMainWindow::filterMenuAboutToShow() @@ -3692,87 +3798,6 @@ void WiresharkMainWindow::on_actionHelpAbout_triggered() about_dialog->activateWindow(); } -void WiresharkMainWindow::on_actionGoGoToPacket_triggered() { - if (! packet_list_->model() || packet_list_->model()->rowCount() < 1) { - return; - } - previous_focus_ = mainApp->focusWidget(); - connect(previous_focus_, SIGNAL(destroyed()), this, SLOT(resetPreviousFocus())); - - showAccordionFrame(main_ui_->goToFrame, true); - if (main_ui_->goToFrame->isVisible()) { - main_ui_->goToLineEdit->clear(); - main_ui_->goToLineEdit->setFocus(); - } -} - -void WiresharkMainWindow::on_actionGoGoToLinkedPacket_triggered() -{ - QAction *gta = qobject_cast(sender()); - if (!gta) return; - - bool ok = false; - int packet_num = gta->data().toInt(&ok); - if (!ok) return; - - packet_list_->goToPacket(packet_num); -} - -// gtk/main_menubar.c:goto_conversation_frame -void WiresharkMainWindow::goToConversationFrame(bool go_next) { - gchar *filter = NULL; - dfilter_t *dfcode = NULL; - gboolean found_packet = FALSE; - packet_info *pi = capture_file_.packetInfo(); - - if (!pi) { - // No packet was selected, or multiple packets were selected. - return; - } - - /* Try to build a conversation - * filter in the order TCP, UDP, IP, Ethernet and apply the - * coloring */ - filter = conversation_filter_from_packet(pi); - if (filter == NULL) { - mainApp->pushStatus(WiresharkApplication::TemporaryStatus, tr("Unable to build conversation filter.")); - g_free(filter); - return; - } - - if (!dfilter_compile(filter, &dfcode, NULL)) { - /* The attempt failed; report an error. */ - mainApp->pushStatus(WiresharkApplication::TemporaryStatus, tr("Error compiling filter for this conversation.")); - g_free(filter); - return; - } - - found_packet = cf_find_packet_dfilter(capture_file_.capFile(), dfcode, go_next ? SD_FORWARD : SD_BACKWARD); - - if (!found_packet) { - /* We didn't find a packet */ - mainApp->pushStatus(WiresharkApplication::TemporaryStatus, tr("No previous/next packet in conversation.")); - } - - dfilter_free(dfcode); - g_free(filter); -} - -void WiresharkMainWindow::on_actionGoNextConversationPacket_triggered() -{ - goToConversationFrame(true); -} - -void WiresharkMainWindow::on_actionGoPreviousConversationPacket_triggered() -{ - goToConversationFrame(false); -} - -void WiresharkMainWindow::on_actionGoAutoScroll_toggled(bool checked) -{ - packet_list_->setVerticalAutoScroll(checked); -} - void WiresharkMainWindow::resetPreviousFocus() { previous_focus_ = NULL; }