diff options
author | David Perry <boolean263@protonmail.com> | 2021-08-11 08:57:45 -0400 |
---|---|---|
committer | Wireshark GitLab Utility <gerald+gitlab-utility@wireshark.org> | 2021-09-10 20:47:12 +0000 |
commit | 389a603fdbd6df785ba4080f72abf57df006117a (patch) | |
tree | f5aa886fb2293383a689a15af0689dc129e4d07d /ui/qt | |
parent | 059c7906c08962b10b7905959800089269fbd74b (diff) |
Allow adding comments to all selected packets
Allow the user to select multiple packets, and
* add the same comment to all selected packets
* remove all comments from selected packets
A new comment is added to each packet, now that we support multiple
comments per packet.
This is one potential way to address #8713.
Diffstat (limited to 'ui/qt')
-rw-r--r-- | ui/qt/main_window.h | 1 | ||||
-rw-r--r-- | ui/qt/main_window_slots.cpp | 26 | ||||
-rw-r--r-- | ui/qt/packet_comment_dialog.cpp | 7 | ||||
-rw-r--r-- | ui/qt/packet_comment_dialog.h | 2 | ||||
-rw-r--r-- | ui/qt/packet_list.cpp | 44 | ||||
-rw-r--r-- | ui/qt/packet_list.h | 1 |
6 files changed, 61 insertions, 20 deletions
diff --git a/ui/qt/main_window.h b/ui/qt/main_window.h index 698557f152..617de26b9b 100644 --- a/ui/qt/main_window.h +++ b/ui/qt/main_window.h @@ -397,6 +397,7 @@ private slots: void actionAddPacketComment(); void actionEditPacketComment(); void actionDeletePacketComment(); + void actionDeleteCommentsFromPackets(); QString commentToMenuText(QString text, int max_len = 40); void setEditCommentsMenu(); void setMenusForSelectedPacket(); diff --git a/ui/qt/main_window_slots.cpp b/ui/qt/main_window_slots.cpp index 1fd311413d..e1a6878f02 100644 --- a/ui/qt/main_window_slots.cpp +++ b/ui/qt/main_window_slots.cpp @@ -1158,9 +1158,15 @@ void MainWindow::setEditCommentsMenu() this, SLOT(actionDeletePacketComment())); aPtr->setData(i); } + main_ui_->menuPacketComment->addSeparator(); + main_ui_->menuPacketComment->addAction(tr("Delete packet comments"), this, SLOT(actionDeleteCommentsFromPackets())); } wtap_block_unref(pkt_block); } + if (selectedRows().count() > 1) { + main_ui_->menuPacketComment->addSeparator(); + main_ui_->menuPacketComment->addAction(tr("Delete comments from %n packet(s)", nullptr, selectedRows().count()), this, SLOT(actionDeleteCommentsFromPackets())); + } } void MainWindow::setMenusForSelectedPacket() @@ -1262,8 +1268,8 @@ void MainWindow::setMenusForSelectedPacket() if (capture_file_.capFile() && capture_file_.capFile()->linktypes) linkTypes = capture_file_.capFile()->linktypes; - bool enableEditComments = frame_selected && linkTypes && wtap_dump_can_write(capture_file_.capFile()->linktypes, WTAP_COMMENT_PER_PACKET); - main_ui_->menuPacketComment->setEnabled(enableEditComments); + bool enableEditComments = linkTypes && wtap_dump_can_write(capture_file_.capFile()->linktypes, WTAP_COMMENT_PER_PACKET); + main_ui_->menuPacketComment->setEnabled(enableEditComments && selectedRows().count() > 0); main_ui_->actionDeleteAllPacketComments->setEnabled(enableEditComments); main_ui_->actionEditIgnorePacket->setEnabled(frame_selected || multi_selection); @@ -2210,7 +2216,7 @@ void MainWindow::editTimeShiftFinished(int) void MainWindow::actionAddPacketComment() { QList<int> rows = selectedRows(); - if (rows.count() != 1) + if (rows.count() == 0) return; frame_data * fdata = frameDataForRow(rows.at(0)); @@ -2218,7 +2224,7 @@ void MainWindow::actionAddPacketComment() return; PacketCommentDialog* pc_dialog; - pc_dialog = new PacketCommentDialog(fdata->num, this, NULL); + pc_dialog = new PacketCommentDialog(false, this, NULL); connect(pc_dialog, &QDialog::finished, std::bind(&MainWindow::addPacketCommentFinished, this, pc_dialog, std::placeholders::_1)); pc_dialog->setWindowModality(Qt::ApplicationModal); pc_dialog->setAttribute(Qt::WA_DeleteOnClose); @@ -2239,14 +2245,10 @@ void MainWindow::actionEditPacketComment() if (rows.count() != 1) return; - frame_data * fdata = frameDataForRow(rows.at(0)); - if (! fdata) - return; - QAction *ra = qobject_cast<QAction*>(sender()); guint nComment = ra->data().toUInt(); PacketCommentDialog* pc_dialog; - pc_dialog = new PacketCommentDialog(fdata->num, this, packet_list_->getPacketComment(nComment)); + pc_dialog = new PacketCommentDialog(true, this, packet_list_->getPacketComment(nComment)); connect(pc_dialog, &QDialog::finished, std::bind(&MainWindow::editPacketCommentFinished, this, pc_dialog, std::placeholders::_1, nComment)); pc_dialog->setWindowModality(Qt::ApplicationModal); pc_dialog->setAttribute(Qt::WA_DeleteOnClose); @@ -2269,6 +2271,12 @@ void MainWindow::actionDeletePacketComment() updateForUnsavedChanges(); } +void MainWindow::actionDeleteCommentsFromPackets() +{ + packet_list_->deleteCommentsFromPackets(); + updateForUnsavedChanges(); +} + void MainWindow::on_actionDeleteAllPacketComments_triggered() { QMessageBox *msg_dialog = new QMessageBox(); diff --git a/ui/qt/packet_comment_dialog.cpp b/ui/qt/packet_comment_dialog.cpp index a45c6ea2b2..b74bfc7c5b 100644 --- a/ui/qt/packet_comment_dialog.cpp +++ b/ui/qt/packet_comment_dialog.cpp @@ -12,13 +12,14 @@ #include "wireshark_application.h" -PacketCommentDialog::PacketCommentDialog(guint32 frame, QWidget *parent, QString comment) : +PacketCommentDialog::PacketCommentDialog(bool isEdit, QWidget *parent, QString comment) : GeometryStateDialog(parent), pc_ui_(new Ui::PacketCommentDialog) { - QString title = QString(tr("Packet %1 Comment")) - .arg(frame); + QString title = isEdit + ? tr("Edit Packet Comment") + : tr("Add Packet Comment"); pc_ui_->setupUi(this); loadGeometry(); diff --git a/ui/qt/packet_comment_dialog.h b/ui/qt/packet_comment_dialog.h index 147e3a09b2..c87a7a63d7 100644 --- a/ui/qt/packet_comment_dialog.h +++ b/ui/qt/packet_comment_dialog.h @@ -23,7 +23,7 @@ class PacketCommentDialog : public GeometryStateDialog Q_OBJECT public: - explicit PacketCommentDialog(guint32 frame, QWidget *parent = 0, QString comment = QString()); + explicit PacketCommentDialog(bool isEdit, QWidget *parent = 0, QString comment = QString()); ~PacketCommentDialog(); QString text(); diff --git a/ui/qt/packet_list.cpp b/ui/qt/packet_list.cpp index c1489952d1..b038f195fb 100644 --- a/ui/qt/packet_list.cpp +++ b/ui/qt/packet_list.cpp @@ -1400,22 +1400,26 @@ QString PacketList::getPacketComment(guint c_number) void PacketList::addPacketComment(QString new_comment) { - int row = currentIndex().row(); frame_data *fdata; if (!cap_file_ || !packet_list_model_) return; if (new_comment.isEmpty()) return; - fdata = packet_list_model_->getRowFdata(row); + QByteArray ba = new_comment.toLocal8Bit(); - if (!fdata) return; + for (int i = 0; i < selectedRows().size(); i++) { + int row = selectedRows().at(i); - wtap_block_t pkt_block = cf_get_packet_block(cap_file_, fdata); + fdata = packet_list_model_->getRowFdata(row); - QByteArray ba = new_comment.toLocal8Bit(); - wtap_block_add_string_option(pkt_block, OPT_COMMENT, ba.data(), ba.size()); + if (!fdata) continue; - cf_set_modified_block(cap_file_, fdata, pkt_block); + wtap_block_t pkt_block = cf_get_packet_block(cap_file_, fdata); + + wtap_block_add_string_option(pkt_block, OPT_COMMENT, ba.data(), ba.size()); + + cf_set_modified_block(cap_file_, fdata, pkt_block); + } redrawVisiblePackets(); } @@ -1477,6 +1481,32 @@ QString PacketList::allPacketComments() return buf_str; } +void PacketList::deleteCommentsFromPackets() +{ + frame_data *fdata; + + if (!cap_file_ || !packet_list_model_) return; + + for (int i = 0; i < selectedRows().size(); i++) { + int row = selectedRows().at(i); + + fdata = packet_list_model_->getRowFdata(row); + + if (!fdata) continue; + + wtap_block_t pkt_block = cf_get_packet_block(cap_file_, fdata); + guint n_comments = wtap_block_count_option(pkt_block, OPT_COMMENT); + + for (guint j = 0; j < n_comments; j++) { + wtap_block_remove_nth_option_instance(pkt_block, OPT_COMMENT, 0); + } + + cf_set_modified_block(cap_file_, fdata, pkt_block); + } + + redrawVisiblePackets(); +} + void PacketList::deleteAllPacketComments() { guint32 framenum; diff --git a/ui/qt/packet_list.h b/ui/qt/packet_list.h index a9fc5bfb94..35f0fab9ca 100644 --- a/ui/qt/packet_list.h +++ b/ui/qt/packet_list.h @@ -75,6 +75,7 @@ public: void addPacketComment(QString new_comment); void setPacketComment(guint c_number, QString new_comment); QString allPacketComments(); + void deleteCommentsFromPackets(); void deleteAllPacketComments(); void setVerticalAutoScroll(bool enabled = true); void setCaptureInProgress(bool in_progress = false) { capture_in_progress_ = in_progress; tail_at_end_ = in_progress; } |