Bug Summary

File:builds/wireshark/wireshark/ui/qt/packet_list.cpp
Warning:line 1398, column 20
Potential leak of memory pointed to by 'drag_label'

Annotated Source Code

Press '?' to see keyboard shortcuts

clang -cc1 -cc1 -triple x86_64-pc-linux-gnu -analyze -disable-free -clear-ast-before-backend -disable-llvm-verifier -discard-value-names -main-file-name packet_list.cpp -analyzer-checker=core -analyzer-checker=apiModeling -analyzer-checker=unix -analyzer-checker=deadcode -analyzer-checker=cplusplus -analyzer-checker=security.insecureAPI.UncheckedReturn -analyzer-checker=security.insecureAPI.getpw -analyzer-checker=security.insecureAPI.gets -analyzer-checker=security.insecureAPI.mktemp -analyzer-checker=security.insecureAPI.mkstemp -analyzer-checker=security.insecureAPI.vfork -analyzer-checker=nullability.NullPassedToNonnull -analyzer-checker=nullability.NullReturnedFromNonnull -analyzer-output plist -w -setup-static-analyzer -mrelocation-model pic -pic-level 2 -fhalf-no-semantic-interposition -fno-delete-null-pointer-checks -mframe-pointer=all -relaxed-aliasing -fmath-errno -ffp-contract=on -fno-rounding-math -ffloat16-excess-precision=fast -fbfloat16-excess-precision=fast -mconstructor-aliases -funwind-tables=2 -target-cpu x86-64 -tune-cpu generic -debugger-tuning=gdb -fdebug-compilation-dir=/builds/wireshark/wireshark/build -fcoverage-compilation-dir=/builds/wireshark/wireshark/build -resource-dir /usr/lib/llvm-22/lib/clang/22 -isystem /usr/include/glib-2.0 -isystem /usr/lib/x86_64-linux-gnu/glib-2.0/include -isystem /builds/wireshark/wireshark/build/ui/qt -isystem /builds/wireshark/wireshark/ui/qt -isystem /builds/wireshark/wireshark/ui/qt/lua_debugger -isystem /usr/include/x86_64-linux-gnu/qt6/QtConcurrent -isystem /usr/include/x86_64-linux-gnu/qt6 -isystem /usr/include/x86_64-linux-gnu/qt6/QtCore -isystem /usr/lib/x86_64-linux-gnu/qt6/mkspecs/linux-g++ -isystem /usr/include/x86_64-linux-gnu/qt6/QtNetwork -isystem /usr/include/x86_64-linux-gnu/qt6/QtPrintSupport -isystem /usr/include/x86_64-linux-gnu/qt6/QtGui -isystem /usr/include/x86_64-linux-gnu/qt6/QtWidgets -isystem /usr/include/x86_64-linux-gnu/qt6/QtSvg -isystem /usr/include/x86_64-linux-gnu/qt6/QtMultimedia -isystem /usr/include/x86_64-linux-gnu/qt6/QtDBus -D CARES_NO_DEPRECATED -D G_DISABLE_DEPRECATED -D G_DISABLE_SINGLE_INCLUDES -D QT_CONCURRENT_LIB -D QT_CORE_LIB -D QT_DBUS_LIB -D QT_GUI_LIB -D QT_MULTIMEDIA_LIB -D QT_NETWORK_LIB -D QT_PRINTSUPPORT_LIB -D QT_SVG_LIB -D QT_WIDGETS_LIB -D WS_DEBUG -D WS_DEBUG_UTF_8 -I /builds/wireshark/wireshark/build/ui/qt/qtui_autogen/include -I /builds/wireshark/wireshark/build -I /builds/wireshark/wireshark -I /builds/wireshark/wireshark/include -D _GLIBCXX_ASSERTIONS -internal-isystem /usr/lib/gcc/x86_64-linux-gnu/16/../../../../include/c++/16 -internal-isystem /usr/lib/gcc/x86_64-linux-gnu/16/../../../../include/x86_64-linux-gnu/c++/16 -internal-isystem /usr/lib/gcc/x86_64-linux-gnu/16/../../../../include/c++/16/backward -internal-isystem /usr/lib/llvm-22/lib/clang/22/include -internal-isystem /usr/local/include -internal-isystem /usr/lib/gcc/x86_64-linux-gnu/16/../../../../x86_64-linux-gnu/include -internal-externc-isystem /usr/include/x86_64-linux-gnu -internal-externc-isystem /include -internal-externc-isystem /usr/include -fmacro-prefix-map=/builds/wireshark/wireshark/= -fmacro-prefix-map=/builds/wireshark/wireshark/build/= -fmacro-prefix-map=../= -Wno-format-nonliteral -std=c++17 -fdeprecated-macro -ferror-limit 19 -fwrapv -fwrapv-pointer -fstrict-flex-arrays=3 -stack-protector 2 -fstack-clash-protection -fcf-protection=full -fgnuc-version=4.2.1 -fskip-odr-check-in-gmf -fcxx-exceptions -fexceptions -fcolor-diagnostics -analyzer-output=html -faddrsig -fdwarf2-cfi-asm -o /builds/wireshark/wireshark/sbout/2026-09-28-100419-3662-1 -x c++ /builds/wireshark/wireshark/ui/qt/packet_list.cpp
1/* packet_list.cpp
2 *
3 * Wireshark - Network traffic analyzer
4 * By Gerald Combs <gerald@wireshark.org>
5 * Copyright 1998 Gerald Combs
6 *
7 * SPDX-License-Identifier: GPL-2.0-or-later
8 */
9
10#include <ui/qt/packet_list.h>
11
12#include "file.h"
13
14#include <epan/epan.h>
15#include <epan/epan_dissect.h>
16
17#include <epan/column.h>
18#include <epan/expert.h>
19#include <epan/packet.h>
20#include <epan/prefs.h>
21#include <epan/proto.h>
22
23#include "ui/main_statusbar.h"
24#include "ui/packet_list_utils.h"
25#include "ui/preference_utils.h"
26#include "ui/recent.h"
27#include "ui/simple_dialog.h"
28#include <wsutil/utf8_entities.h>
29
30#include "wiretap/wtap_opttypes.h"
31#include "app/application_flavor.h"
32#include "wsutil/str_util.h"
33#include <wsutil/wslog.h>
34
35#include <epan/color_filters.h>
36
37#include <ui/qt/utils/color_utils.h>
38#include <ui/qt/utils/theme_manager.h>
39#include <ui/qt/utils/font_manager.h>
40#include <ui/qt/widgets/overlay_scroll_bar.h>
41#include "proto_tree.h"
42#include <ui/qt/utils/qt_ui_utils.h>
43#include "main_application.h"
44#include <ui/qt/utils/data_printer.h>
45#include <ui/qt/utils/frame_information.h>
46#include <ui/qt/utils/profile_switcher.h>
47#include <ui/qt/utils/variant_pointer.h>
48#include <ui/qt/models/pref_models.h>
49#include <ui/qt/widgets/packet_list_header.h>
50#include <ui/qt/utils/wireshark_mime_data.h>
51#include <ui/qt/widgets/drag_label.h>
52#include <ui/qt/filter_action.h>
53#include <ui/qt/follow_stream_action.h>
54#include <ui/qt/decode_as_dialog.h>
55#include <ui/qt/wireshark_main_window.h>
56
57#include <QAction>
58#include <QActionGroup>
59#include <QApplication>
60#include <QClipboard>
61#include <QContextMenuEvent>
62#include <QtCore/qmath.h>
63#include <QElapsedTimer>
64#include <QFontMetrics>
65#include <QHeaderView>
66#include <QKeyEvent>
67#include <QMessageBox>
68#include <QPainter>
69#include <QScreen>
70#include <QScrollBar>
71#include <QWheelEvent>
72#include <QTabWidget>
73#include <QTextEdit>
74#include <QTimerEvent>
75#include <QTreeWidget>
76#include <QWindow>
77#include <QJsonObject>
78#include <QJsonDocument>
79
80#ifdef Q_OS_WIN
81#include "wsutil/file_util.h"
82#include <QSysInfo>
83#include <uxtheme.h>
84#endif
85
86// To do:
87// - Fix "apply as filter" behavior.
88// - Add colorize conversation.
89// - Use a timer to trigger automatic scrolling.
90
91// If we ever add the ability to open multiple capture files we might be
92// able to use something like QMap<capture_file *, PacketList *> to match
93// capture files against packet lists and models.
94static PacketList *gbl_cur_packet_list;
95
96const int max_comments_to_fetch_ = 20000000; // Arbitrary
97const int overlay_update_interval_ = 100; // 250; // Milliseconds.
98// Turbo mode: If the user holds down the down or up key longer than the
99// activation delay, switch from the operating system's autorepeat rate to
100// our own, faster rate.
101const int turbo_activation_delay_ = 1500; // Milliseconds, somewhat arbitrary.
102// Our goal is to move to the next or previous packet as fast as possible
103// while still allowing the user to recognize changes in the hex view.
104// According to this paper on Rapid Serial Visual Presentation (RSVP), humans
105// can recognize images presented as fast as 13ms.
106// https://web.archive.org/web/20250216195443/https://mollylab-1.mit.edu/sites/default/files/documents/FastDetect2014withFigures.pdf
107// Hopefully 15ms is plenty.
108const int turbo_nav_interval_ = 15; // Milliseconds
109
110
111/*
112 * Given a frame_data structure, scroll to and select the row in the
113 * packet list corresponding to that frame. If there is no such
114 * row, return false, otherwise return true.
115 */
116bool
117packet_list_select_row_from_data(frame_data *fdata_needle)
118{
119 if (! gbl_cur_packet_list || ! gbl_cur_packet_list->model())
120 return false;
121
122 PacketListModel* model = qobject_cast<PacketListModel*>(gbl_cur_packet_list->model());
123
124 if (!model)
125 return false;
126
127 model->flushVisibleRows();
128 int row = -1;
129 if (!fdata_needle)
130 row = 0;
131 else
132 row = model->visibleIndexOf(fdata_needle);
133
134 if (row >= 0) {
135 /* Calling ClearAndSelect with setCurrentIndex clears the "current"
136 * item, but doesn't clear the "selected" item. We want to clear
137 * the "selected" item as well so that selectionChanged() will be
138 * emitted in order to force an update of the packet details and
139 * packet bytes after a search.
140 */
141 gbl_cur_packet_list->selectionModel()->clearSelection();
142 gbl_cur_packet_list->selectionModel()->setCurrentIndex(model->index(row, 0), QItemSelectionModel::ClearAndSelect | QItemSelectionModel::Rows);
143 gbl_cur_packet_list->scrollTo(gbl_cur_packet_list->currentIndex(), PacketList::PositionAtCenter);
144 return true;
145 }
146
147 return false;
148}
149
150/*
151 * Given a field_info, select the field (which will scroll to it in
152 * the main ProtoTree, etc.) This is kind of an odd place for it,
153 * but we call this when performing Find Packet in lieu of changing the
154 * selected frame (the function above), because we found a match in the
155 * same frame as the currently selected one.
156 */
157bool
158packet_list_select_finfo(field_info *fi)
159{
160 if (! gbl_cur_packet_list || ! gbl_cur_packet_list->model())
161 return false;
162
163 if (fi) {
164 FieldInformation finfo(fi, gbl_cur_packet_list);
165 emit gbl_cur_packet_list->fieldSelected(&finfo);
166 } else {
167 emit gbl_cur_packet_list->fieldSelected(0);
168 }
169 return true;
170}
171
172void
173packet_list_clear(void)
174{
175 if (gbl_cur_packet_list) {
176 gbl_cur_packet_list->clear();
177 }
178}
179
180void
181packet_list_freeze(void)
182{
183 if (gbl_cur_packet_list) {
184 gbl_cur_packet_list->freeze();
185 }
186}
187
188void
189packet_list_thaw(void)
190{
191 if (gbl_cur_packet_list) {
192 gbl_cur_packet_list->thaw();
193 }
194
195 packets_bar_update();
196}
197
198/* Redraw the packet list *and* currently-selected detail */
199void
200packet_list_queue_draw(void)
201{
202 if (gbl_cur_packet_list)
203 gbl_cur_packet_list->redrawVisiblePackets();
204}
205
206void
207packet_list_recent_write_all(FILE *rf) {
208 if (!gbl_cur_packet_list)
209 return;
210
211 gbl_cur_packet_list->writeRecent(rf);
212}
213
214bool
215packet_list_multi_select_active(void)
216{
217 if (gbl_cur_packet_list) {
218 return gbl_cur_packet_list->multiSelectActive();
219 }
220 return false;
221}
222
223#define MIN_COL_WIDTH_STR"MMMMMM" "MMMMMM"
224
225PacketList::PacketList(QWidget *parent) :
226 QTreeView(parent),
227 proto_tree_(nullptr),
228 cap_file_(nullptr),
229 ctx_column_(-1),
230 ctx_from_pinned_row_strip_(false),
231 overlay_timer_id_(0),
232 turbo_timer_id_(0),
233 turbo_key_(Qt::Key(0)),
234 held_key_(Qt::Key(0)),
235 create_near_overlay_(true),
236 create_far_overlay_(true),
237 mouse_pressed_at_(QModelIndex()),
238 capture_in_progress_(false),
239 tail_at_end_(0),
240 columns_changed_(false),
241 set_column_visibility_(false),
242 set_style_sheet_(false),
243 frozen_current_row_(QModelIndex()),
244 frozen_selected_rows_(QModelIndexList()),
245 pinned_rows_model_(nullptr),
246 pinned_column_boundary_(0),
247 pinned_column_view_(nullptr),
248 pinned_row_view_(nullptr),
249 pinned_row_corner_view_(nullptr),
250 hovered_frame_num_(-1),
251 cur_history_(-1),
252 in_history_(false),
253 finfo_array(nullptr),
254 profile_switcher_(nullptr)
255{
256 setItemsExpandable(false);
257 setRootIsDecorated(false);
258 setSortingEnabled(prefs.gui_packet_list_sortable);
259 setUniformRowHeights(true);
260 setFocusPolicy(Qt::StrongFocus);
261 // Needed so mouseMoveEvent() fires on a plain hover (no button held),
262 // to track hovered_frame_num_ for the cross-pane hover highlight.
263 setMouseTracking(true);
264
265#ifdef Q_OS_MAC
266 setAttribute(Qt::WA_MacShowFocusRect, true);
267#endif
268
269 verticalScrollBar()->setFocusPolicy(Qt::NoFocus);
270 horizontalScrollBar()->setFocusPolicy(Qt::NoFocus);
271
272 packet_list_header_ = new PacketListHeader(header()->orientation());
273 connect(packet_list_header_, &PacketListHeader::resetColumnWidth, this, &PacketList::setRecentColumnWidth);
274 connect(packet_list_header_, &PacketListHeader::updatePackets, this, &PacketList::updatePackets);
275 connect(packet_list_header_, &PacketListHeader::showColumnPreferences, this, &PacketList::showProtocolPreferences);
276 connect(packet_list_header_, &PacketListHeader::editColumn, this, &PacketList::editColumn);
277 connect(packet_list_header_, &PacketListHeader::columnsChanged, this, &PacketList::columnsChanged);
278 setHeader(packet_list_header_);
279
280 header()->setFirstSectionMovable(true);
281
282 setSelectionMode(QAbstractItemView::ExtendedSelection);
283
284 // Shrink down to a small but nonzero size in the main splitter.
285 int one_em = fontMetrics().height();
286 setMinimumSize(one_em, one_em);
287
288 overlay_sb_ = new OverlayScrollBar(Qt::Vertical, this);
289 setVerticalScrollBar(overlay_sb_);
290
291 header()->setSortIndicator(-1, Qt::AscendingOrder);
292
293 packet_list_model_ = new PacketListModel(this, cap_file_);
294 setModel(packet_list_model_);
295
296 Q_ASSERT(gbl_cur_packet_list == Q_NULLPTR)((gbl_cur_packet_list == nullptr) ? static_cast<void>(0
) : ::qt_assert("gbl_cur_packet_list == Q_NULLPTR", "ui/qt/packet_list.cpp"
, 296))
;
297 gbl_cur_packet_list = this;
298
299 connect(packet_list_model_, &PacketListModel::goToPacket, this, [=](int packet) { goToPacket(packet); });
300 connect(mainApp, &MainApplication::addressResolutionChanged, this, &PacketList::redrawVisiblePacketsDontSelectCurrent);
301 connect(mainApp, &MainApplication::columnDataChanged, this, &PacketList::redrawVisiblePacketsDontSelectCurrent);
302 connect(mainApp, &MainApplication::preferencesChanged, this, [=]() {
303 /* The pref is a uint but QCache maxCost is a signed int (/
304 * qsizetype in Qt 6). Note that QAbstractItemModel row numbers
305 * are ints, not unsigned ints, so we're limited to INT_MAX
306 * rows anyway.
307 */
308 PacketListRecord::setMaxCache(prefs.gui_packet_list_cached_rows_max > INT_MAX2147483647 ? INT_MAX2147483647 : prefs.gui_packet_list_cached_rows_max);
309 if ((bool) (prefs.gui_packet_list_sortable) != isSortingEnabled()) {
310 setSortingEnabled(prefs.gui_packet_list_sortable);
311 }
312 });
313
314 connect(header(), &QHeaderView::sectionResized, this, &PacketList::sectionResized);
315 connect(header(), &QHeaderView::sectionMoved, this, &PacketList::sectionMoved);
316 // The frozen column view's own header is a separate QHeaderView and
317 // doesn't automatically follow this one's sort indicator (the arrow
318 // icon), so keep it mirrored whenever a click on the real header (not
319 // just sortByColumnFromOverlay()) changes it.
320 connect(header(), &QHeaderView::sortIndicatorChanged, this, [this](int column, Qt::SortOrder order) {
321 if (pinned_column_view_) {
322 pinned_column_view_->mirrorSortIndicator(column, order);
323 }
324 });
325
326 connect(verticalScrollBar(), &QScrollBar::actionTriggered, this, &PacketList::vScrollBarActionTriggered);
327
328 connect(packet_list_header_, &PacketListHeader::freezeColumnsToHere, this, &PacketList::setPinnedColumnBoundary);
329 connect(packet_list_header_, &PacketListHeader::unfreezeColumns, this, [this]() { setPinnedColumnBoundary(0); });
330
331 pinned_rows_model_ = new PinnedRowsModel(this);
332 pinned_rows_model_->setSourceModel(packet_list_model_);
333 // Filtering (modelReset) and sorting (layoutChanged) on the source
334 // model both need the pinned set re-resolved/re-ordered to match.
335 connect(packet_list_model_, &QAbstractItemModel::modelReset, this, &PacketList::updatePinnedRowVisibility);
336 connect(packet_list_model_, &QAbstractItemModel::layoutChanged, this, &PacketList::updatePinnedRowVisibility);
337
338 pinned_column_view_ = new PinnedColumnView(this, this);
339 pinned_column_view_->setModel(packet_list_model_);
340 pinned_column_view_->setSelectionModel(selectionModel());
341
342 connect(verticalScrollBar(), &QScrollBar::valueChanged, pinned_column_view_, &PinnedColumnView::setVerticalScrollValue);
343
344 // Own the font: seed it now and follow the FontManager for later changes.
345 connect(FontManager::instance(), &FontManager::monospaceFontChanged, this, &PacketList::setMonospaceFont);
346 connect(FontManager::instance(), &FontManager::applicationFontChanged, this, &PacketList::setRegularFont);
347 setMonospaceFont(FontManager::zoomedMonospaceFont());
348 setRegularFont(FontManager::zoomedFont());
349
350 // isActiveWindow()/QEvent::ActivationChange can lag behind the actual
351 // activation state on some platforms until the next event loop
352 // iteration, so also track focus moving to/from the application
353 // entirely to keep the pinned overlay views' selection color synced.
354 connect(qApp(static_cast<QApplication *>(QCoreApplication::instance
()))
, &QApplication::focusChanged, this, &PacketList::applicationFocusChanged);
355}
356
357void PacketList::setPinnedRowViews(PinnedRowView *row_view, PinnedRowView *corner_view)
358{
359 pinned_row_view_ = row_view;
360 pinned_row_corner_view_ = corner_view;
361
362 if (pinned_row_view_) {
363 pinned_row_view_->setModel(pinned_rows_model_);
364 connect(horizontalScrollBar(), &QScrollBar::valueChanged, pinned_row_view_, &PinnedRowView::setHorizontalScrollValue);
365 }
366 if (pinned_row_corner_view_) {
367 pinned_row_corner_view_->setModel(pinned_rows_model_);
368 }
369}
370
371QList<QTreeView *> PacketList::pinnedOverlayViews() const
372{
373 QList<QTreeView *> views;
374 if (pinned_column_view_) {
375 views << pinned_column_view_;
376 }
377 if (pinned_row_view_) {
378 views << pinned_row_view_;
379 }
380 if (pinned_row_corner_view_) {
381 views << pinned_row_corner_view_;
382 }
383 return views;
384}
385
386void PacketList::repaintPinnedOverlays()
387{
388 for (QTreeView *view : pinnedOverlayViews()) {
389 view->viewport()->update();
390 }
391}
392
393void PacketList::mirrorSectionWidthToOverlays(int column, int width)
394{
395 if (pinned_column_view_) {
396 pinned_column_view_->mirrorSectionWidth(column, width);
397 }
398 if (pinned_row_view_) {
399 pinned_row_view_->mirrorSectionWidth(column, width);
400 }
401 if (pinned_row_corner_view_) {
402 pinned_row_corner_view_->mirrorSectionWidth(column, width);
403 }
404}
405
406PacketList::~PacketList()
407{
408 if (finfo_array)
409 {
410 g_ptr_array_free(finfo_array, true);
411 }
412}
413
414void PacketList::scrollTo(const QModelIndex &index, QAbstractItemView::ScrollHint hint)
415{
416 /* QAbstractItemView doesn't have a way to indicate "auto scroll, but
417 * only vertically." So just restore the horizontal scroll value whenever
418 * it scrolls.
419 */
420 setUpdatesEnabled(false);
421 int horizVal = horizontalScrollBar()->value();
422 QTreeView::scrollTo(index, hint);
423 horizontalScrollBar()->setValue(horizVal);
424 setUpdatesEnabled(true);
425}
426
427void PacketList::colorsChanged()
428{
429 const QString c_active = "active";
430 const QString c_inactive = "!active";
431
432 const QString flat_style_format =
433 "QTreeView::item:selected:%1 {"
434 " color: %2;"
435 " background-color: %3;"
436 "}";
437
438 // Same as flat_style_format but with no :active/:!active selector at
439 // all, for the overlay panes (see applyOverlayActiveState()).
440 const QString plain_style_format =
441 "QTreeView::item:selected {"
442 " color: %1;"
443 " background-color: %2;"
444 "}";
445
446 ThemeManager *tm = ThemeManager::instance();
447 QColor active_bg = tm->color(ThemeManager::PacketsSelection);
448 QColor inactive_bg = tm->color(ThemeManager::PacketsInactive);
449 QColor active_fg = tm->color(ThemeManager::PacketsSelectionText);
450 QColor inactive_fg = tm->color(ThemeManager::PacketsInactiveText);
451
452 QString active_style = flat_style_format.arg(
453 c_active,
454 active_fg.name(),
455 active_bg.name());
456 QString inactive_style = flat_style_format.arg(
457 c_inactive,
458 inactive_fg.name(),
459 inactive_bg.name());
460
461 // Hover highlighting is painted manually in drawRow() (driven by
462 // hovered_frame_num_) rather than through a :hover stylesheet
463 // selector, since the mouse hovering a pinned overlay view needs to
464 // highlight the corresponding row in every pane, not just the one
465 // widget Qt considers "hovered".
466 QString full_style = active_style + inactive_style;
467
468 // Cache the plain flat colors (no :active/:!active selector -- see
469 // applyOverlayActiveState()) so window-activation changes can pick the
470 // right one without recomputing from ThemeManager every time.
471 overlay_active_flat_style_ = plain_style_format.arg(active_fg.name(), active_bg.name());
472 overlay_inactive_flat_style_ = plain_style_format.arg(inactive_fg.name(), inactive_bg.name());
473
474 set_style_sheet_ = true;
475 setStyleSheet(full_style);
476 set_style_sheet_ = false;
477
478 applyOverlayActiveState();
479#if \
480 ( \
481 (QT_VERSION((6<<16)|(10<<8)|(2)) >= QT_VERSION_CHECK(6, 5, 4)((6<<16)|(5<<8)|(4)) && QT_VERSION((6<<16)|(10<<8)|(2)) < QT_VERSION_CHECK(6, 6, 0)((6<<16)|(6<<8)|(0))) \
482 || (QT_VERSION((6<<16)|(10<<8)|(2)) >= QT_VERSION_CHECK(6, 6, 1)((6<<16)|(6<<8)|(1))) \
483 )
484 // https://bugreports.qt.io/browse/QTBUG-122109
485 // Affects Qt 6.5.4 and later, 6.6.1 and later.
486 // When setting the style sheet, all visible sections are set
487 // to the new minimum DefaultSectionSize (even if it hasn't
488 // changed.) So make sure the new widths aren't saved to recent
489 // and then restore from recent.
490 applyRecentColumnWidths();
491 setColumnVisibility();
492#endif
493}
494
495void PacketList::applyOverlayActiveState()
496{
497 // Match the plain flat_style_format(":active"/:!active") selectors
498 // applied to this view itself, which are keyed to whether THIS widget
499 // has focus (not just whether the window is active) -- Qt's
500 // :active/:!active tracks the same thing per-widget. Clicking into the
501 // packet details/bytes pane keeps the window active but moves focus
502 // away from PacketList, and the overlay panes should dim along with
503 // it, not stay "focused" on their own.
504 const QString &style = (hasFocus() && isActiveWindow()) ? overlay_active_flat_style_ : overlay_inactive_flat_style_;
505 if (pinned_column_view_) {
506 pinned_column_view_->setStyleSheet(style);
507 }
508 if (pinned_row_view_) {
509 pinned_row_view_->setStyleSheet(style);
510 }
511 if (pinned_row_corner_view_) {
512 pinned_row_corner_view_->setStyleSheet(style);
513 }
514}
515
516void PacketList::changeEvent(QEvent *event)
517{
518 QTreeView::changeEvent(event);
519
520 if (event->type() == QEvent::ActivationChange) {
521 applyOverlayActiveState();
522 }
523}
524
525void PacketList::applicationFocusChanged(QWidget *, QWidget *)
526{
527 applyOverlayActiveState();
528}
529
530QString PacketList::joinSummaryRow(QStringList col_parts, int row, SummaryCopyType type)
531{
532 QString copy_text;
533 switch (type) {
534 case CopyAsCSV:
535 copy_text = "\"";
536 copy_text += col_parts.join("\",\"");
537 copy_text += "\"";
538 break;
539 case CopyAsYAML:
540 copy_text = "----\n";
541 copy_text += QStringLiteral("# Packet %1 from %2\n")(QString(QtPrivate::qMakeStringPrivate(u"" "# Packet %1 from %2\n"
)))
.arg(row).arg(cap_file_->filename);
542 copy_text += "- ";
543 copy_text += col_parts.join("\n- ");
544 copy_text += "\n";
545 break;
546 case CopyAsText:
547 default:
548 copy_text = col_parts.join("\t");
549 }
550
551 return copy_text;
552}
553
554void PacketList::drawRow (QPainter *painter, const QStyleOptionViewItem &option, const QModelIndex &index) const
555{
556 QTreeView::drawRow(painter, option, index);
557
558 // The hover highlight is driven by hovered_frame_num_ rather than Qt's
559 // native per-widget hover state, since the mouse hovering a pinned
560 // overlay view needs to highlight this row here too -- native :hover
561 // styling only ever reacts to the mouse being over this specific
562 // widget. Painted even on a selected row so hover wins over selection,
563 // matching the pre-ThemeManager behavior (see the old :selected:hover
564 // stylesheet rule this replaced -- "background-color: ...;
565 // color: palette(text);"). Uses ColorUtils::paintFlatCell() rather
566 // than re-invoking each column's delegate with overridden palette
567 // roles -- QStyledItemDelegate::paint() calls initStyleOption(),
568 // which re-fetches Qt::BackgroundRole from the model and clobbers any
569 // backgroundBrush/palette override made beforehand, so a colored,
570 // marked, or ignored row's own background always won that fight and
571 // showed through instead of the flat hover color.
572 if (prefs.gui_packet_list_hover_style && index.isValid()) {
573 frame_data *fdata = getFDataForRow(index.row());
574 if (fdata && (int)fdata->num == hovered_frame_num_) {
575 QColor hover_bg = ColorUtils::hoverBackground();
576 QColor text_color = palette().color(QPalette::Text);
577
578 for (int visual_col = 0; visual_col < header()->count(); visual_col++) {
579 int logical_col = header()->logicalIndex(visual_col);
580 if (isColumnHidden(logical_col)) {
581 continue;
582 }
583 QModelIndex col_index = index.siblingAtColumn(logical_col);
584 QStyleOptionViewItem col_option = option;
585 col_option.rect = visualRect(col_index);
586 ColorUtils::paintFlatCell(painter, this, col_option, col_index, hover_bg, text_color);
587 }
588 }
589 }
590
591 if (prefs.gui_packet_list_separator) {
592 QRect rect = visualRect(index);
593
594 painter->setPen(QColor(Qt::white));
595 painter->drawLine(0, rect.y() + rect.height() - 1, width(), rect.y() + rect.height() - 1);
596 }
597}
598
599void PacketList::setProtoTree (ProtoTree *proto_tree) {
600 proto_tree_ = proto_tree;
601
602 connect(proto_tree_, &ProtoTree::goToPacket, this, [=](int packet) { goToPacket(packet); });
603 connect(proto_tree_, &ProtoTree::relatedFrame,
604 &related_packet_delegate_, &RelatedPacketDelegate::addRelatedFrame);
605}
606
607bool PacketList::uniqueSelectActive()
608{
609 return selectionModel()->selectedRows(0).count() == 1 ? true : false;
610}
611
612bool PacketList::multiSelectActive()
613{
614 return selectionModel()->selectedRows(0).count() > 1 ? true : false;
615}
616
617QList<int> PacketList::selectedRows(bool useFrameNum)
618{
619 QList<int> rows;
620 if (selectionModel() && selectionModel()->hasSelection())
621 {
622 foreach (QModelIndex idx, selectionModel()->selectedRows(0))for (auto _container_622 = QtPrivate::qMakeForeachContainer(selectionModel
()->selectedRows(0)); _container_622.i != _container_622.e
; ++_container_622.i) if (QModelIndex idx = *_container_622.i
; false) {} else
623 {
624 if (idx.isValid())
625 {
626 if (! useFrameNum)
627 rows << idx.row();
628 else if (useFrameNum)
629 {
630 frame_data * frame = getFDataForRow(idx.row());
631 if (frame)
632 rows << frame->num;
633 }
634 }
635 }
636 }
637 else if (currentIndex().isValid())
638 {
639 //
640 // XXX - will we ever have a current index but not a selection
641 // model?
642 //
643 if (! useFrameNum)
644 rows << currentIndex().row();
645 else
646 {
647 frame_data *frame = getFDataForRow(currentIndex().row());
648 if (frame)
649 rows << frame->num;
650 }
651 }
652
653 return rows;
654}
655
656int PacketList::currentFrameNum() const
657{
658 if (!cap_file_ || !cap_file_->current_frame) {
659 return -1;
660 }
661 return (int)cap_file_->current_frame->num;
662}
663
664void PacketList::selectionChanged (const QItemSelection & selected, const QItemSelection & deselected)
665{
666 QTreeView::selectionChanged(selected, deselected);
667
668 // The pinned overlay views share this view's selection model, but each
669 // is a separate QAbstractItemView with its own viewport; force a
670 // repaint there too so the highlight always shows on both sides of a
671 // freeze boundary, regardless of which view the selection change
672 // originated from.
673 repaintPinnedOverlays();
674
675 // We shouldn't need to scroll because QTreeView already does that if
676 // a single packet is newly selected. If we have a single selected packet
677 // because we just deselected the second to last packet, we probably don't
678 // want to scroll to the remaining frame.
679 drawCurrentPacket(false);
680}
681
682void PacketList::contextMenuEvent(QContextMenuEvent *event)
683{
684 const char *module_name = NULL__null;
685
686 if (finfo_array)
687 {
688 g_ptr_array_free(finfo_array, true);
689 finfo_array = NULL__null;
690 }
691
692 QModelIndex ctxIndex = indexAt(event->pos());
693
694 if (selectionModel() && selectionModel()->selectedRows(0).count() > 1)
695 selectionModel()->select(ctxIndex, QItemSelectionModel::ClearAndSelect | QItemSelectionModel::Rows);
696
697 // ctxIndex is invalid when this is called via showContextMenuForFrame()
698 // for a pinned packet that's been filtered out of this view entirely
699 // (no row here to resolve via indexAt()/getRowFdata()) -- fall back to
700 // whatever frame was actually selected (by selectFrameFromOverlay(),
701 // just before this runs), which for that case is exactly the pinned
702 // packet's own frame, resolved independently of any row here.
703 frame_data *ctx_row_fdata = ctxIndex.isValid() ?
704 packet_list_model_->getRowFdata(ctxIndex.row()) :
705 (cap_file_ ? cap_file_->current_frame : nullptr);
706
707 // frameData will be owned by one of the submenus, see below.
708 FrameInformation * frameData =
709 new FrameInformation(new CaptureFile(this, cap_file_), ctx_row_fdata);
710
711 QMenu * ctx_menu = new QMenu(this);
712 ctx_menu->setAttribute(Qt::WA_DeleteOnClose);
713 // XXX We might want to reimplement setParent() and fill in the context
714 // menu there.
715 ctx_menu->addAction(window()->findChild<QAction *>("actionEditMarkSelected"));
716 ctx_menu->addAction(window()->findChild<QAction *>("actionEditIgnoreSelected"));
717 ctx_menu->addAction(window()->findChild<QAction *>("actionEditSetTimeReference"));
718 ctx_menu->addAction(window()->findChild<QAction *>("actionEditTimeShift"));
719 ctx_menu->addMenu(window()->findChild<QMenu *>("menuPacketComment"));
720
721 ctx_menu->addSeparator();
722
723 // Code for custom context menus from Lua's register_packet_menu()
724 MainWindow * mainWindow = mainApp->mainWindow();
725 // N.B., will only call for a single frame selection,
726 if (cap_file_ && cap_file_->edt && cap_file_->edt->tree) {
727 finfo_array = proto_all_finfos(cap_file_->edt->tree);
728 if (mainWindow) {
729 bool insertedPacketMenu = mainWindow->addPacketMenus(ctx_menu, finfo_array);
730 if (insertedPacketMenu) {
731 ctx_menu->addSeparator();
732 }
733 }
734 }
735
736 ctx_menu->addAction(window()->findChild<QAction *>("actionViewEditResolvedName"));
737
738 frame_data *ctx_fdata = ctx_row_fdata;
739 if (ctx_fdata) {
740 bool rowPinned = pinned_rows_model_->isPinned((int)ctx_fdata->num);
741 bool maxReached = !rowPinned && pinned_rows_model_->pinnedCount() >= PinnedRowsModel::kMaxPinnedRows;
742 QString pin_label = rowPinned ? tr("Unpin Row")
743 : maxReached ? tr("Pin Row to Top (max %1 reached)").arg(PinnedRowsModel::kMaxPinnedRows)
744 : tr("Pin Row to Top");
745 QAction *pin_action = ctx_menu->addAction(pin_label);
746 pin_action->setEnabled(!maxReached);
747 connect(pin_action, &QAction::triggered, this, [this, rowPinned]() {
748 if (rowPinned) {
749 unpinSelectedRows();
750 } else {
751 pinSelectedRows();
752 }
753 });
754 }
755
756 // Shown only for a context menu request that actually originated from
757 // the pinned-row strip (PinnedRowView) itself -- not the frozen-column
758 // overlay or a direct right-click on the primary view -- since
759 // scrolling the main view to a packet already visible there (or
760 // clearing every pinned row) doesn't make sense as an action offered
761 // from either of those.
762 if (ctx_from_pinned_row_strip_ && ctx_fdata) {
763 int ctx_frame_num = ctx_fdata->num;
764 QAction *goto_action = ctx_menu->addAction(tr("Go to Packet"));
765 connect(goto_action, &QAction::triggered, this, [this, ctx_frame_num]() {
766 goToPacket(ctx_frame_num);
767 });
768 }
769 if (ctx_from_pinned_row_strip_ && pinned_rows_model_->pinnedCount() > 0) {
770 QAction *unpin_all_action = ctx_menu->addAction(tr("Unpin All Rows"));
771 connect(unpin_all_action, &QAction::triggered, this, &PacketList::unpinAllRows);
772 }
773 // Reset for the next context menu request: showContextMenuForRow()/
774 // showContextMenuForFrame() set this immediately before calling here,
775 // but a direct right-click on the primary view calls this override
776 // straight from Qt's own event dispatch, bypassing both wrappers
777 // entirely -- so it can't be reset at entry the way ctx_column_ is,
778 // only after this one use.
779 ctx_from_pinned_row_strip_ = false;
780
781 ctx_menu->addSeparator();
782
783 QString selectedfilter = getFilterFromRowAndColumn(currentIndex());
784
785 if (! hasFocus() && cap_file_ && cap_file_->finfo_selected) {
786 char *tmp_field = proto_construct_match_selected_string(cap_file_->finfo_selected, cap_file_->edt);
787 selectedfilter = QString(tmp_field);
788 wmem_free(NULL__null, tmp_field);
789 }
790
791 bool have_filter_expr = !selectedfilter.isEmpty();
792 ctx_menu->addMenu(FilterAction::createFilterMenu(FilterAction::ActionApply, selectedfilter, have_filter_expr, ctx_menu));
793 ctx_menu->addMenu(FilterAction::createFilterMenu(FilterAction::ActionPrepare, selectedfilter, have_filter_expr, ctx_menu));
794
795 const char *conv_menu_name = "menuConversationFilter";
796 QMenu * main_menu_item = window()->findChild<QMenu *>(conv_menu_name);
797 conv_menu_.setTitle(main_menu_item->title());
798 conv_menu_.setObjectName(conv_menu_name);
799 ctx_menu->addMenu(&conv_menu_);
800
801 const char *colorize_menu_name = "menuColorizeConversation";
802 main_menu_item = window()->findChild<QMenu *>(colorize_menu_name);
803 colorize_menu_.setTitle(main_menu_item->title());
804 colorize_menu_.setObjectName(colorize_menu_name);
805 ctx_menu->addMenu(&colorize_menu_);
806
807 QMenu * submenu;
808 main_menu_item = window()->findChild<QMenu *>("menuSCTP");
809 if (main_menu_item) {
810 submenu = new QMenu(main_menu_item->title(), ctx_menu);
811 ctx_menu->addMenu(submenu);
812 submenu->addAction(window()->findChild<QAction *>("actionSCTPAnalyseThisAssociation"));
813 submenu->addAction(window()->findChild<QAction *>("actionSCTPShowAllAssociations"));
814 submenu->addAction(window()->findChild<QAction *>("actionSCTPFilterThisAssociation"));
815 }
816
817 main_menu_item = window()->findChild<QMenu *>("menuFollow");
818 if (main_menu_item) {
819 submenu = new QMenu(main_menu_item->title(), ctx_menu);
820 ctx_menu->addMenu(submenu);
821 foreach (FollowStreamAction *follow_action, main_menu_item->findChildren<FollowStreamAction *>())for (auto _container_821 = QtPrivate::qMakeForeachContainer(main_menu_item
->findChildren<FollowStreamAction *>()); _container_821
.i != _container_821.e; ++_container_821.i) if (FollowStreamAction
*follow_action = *_container_821.i; false) {} else
{
822 /* XXX: We could, like the prefs above, walk the protocols/layers
823 * and add the follow actions in the order they appear in the packet.
824 */
825 if (follow_action->isEnabled()) {
826 submenu->addAction(follow_action);
827 }
828 }
829 }
830
831 ctx_menu->addSeparator();
832
833 main_menu_item = window()->findChild<QMenu *>("menuEditCopy");
834 submenu = new QMenu(main_menu_item->title(), ctx_menu);
835 submenu->setToolTipsVisible(true);
836 ctx_menu->addMenu(submenu);
837
838 QAction * action = submenu->addAction(tr("Summary as Text"));
839 action->setData(CopyAsText);
840 connect(action, &QAction::triggered, this, &PacketList::copySummary);
841 action = submenu->addAction(tr("…as CSV"));
842 action->setData(CopyAsCSV);
843 connect(action, &QAction::triggered, this, &PacketList::copySummary);
844 action = submenu->addAction(tr("…as YAML"));
845 action->setData(CopyAsYAML);
846 connect(action, &QAction::triggered, this, &PacketList::copySummary);
847 action = submenu->addAction(tr("…as HTML"));
848 action->setData(CopyAsHTML);
849 connect(action, &QAction::triggered, this, &PacketList::copySummary);
850 submenu->addSeparator();
851
852 submenu->addAction(window()->findChild<QAction *>("actionEditCopyAsFilter"));
853 submenu->addSeparator();
854
855 QActionGroup * copyEntries = DataPrinter::copyActions(this, frameData);
856 submenu->addActions(copyEntries->actions());
857 copyEntries->setParent(submenu);
858 frameData->setParent(submenu);
859
860 if (application_flavor_is_wireshark()) {
861 /* i.e., Wireshark only */
862 ctx_menu->addSeparator();
863 QMenu *proto_prefs_menus = new QMenu(ProtocolPreferencesMenu::tr("Protocol Preferences"), ctx_menu);
864
865 if (cap_file_ && cap_file_->edt && cap_file_->edt->tree) {
866 QList<QString> added_proto_prefs;
867 // N.B. finfo_array will be assigned above
868 for (unsigned i = 0; i < finfo_array->len; i++) {
869 field_info *fi = (field_info *)g_ptr_array_index (finfo_array, i)((finfo_array)->pdata)[i];
870 const header_field_info *hfinfo = fi->hfinfo;
871
872 if (prefs_is_registered_protocol(hfinfo->abbrev)) {
873 if (hfinfo->parent == -1) {
874 module_name = hfinfo->abbrev;
875 } else {
876 module_name = proto_registrar_get_abbrev(hfinfo->parent);
877 }
878
879 if (added_proto_prefs.contains(module_name)) {
880 continue;
881 }
882
883 ProtocolPreferencesMenu *proto_prefs_menu = new ProtocolPreferencesMenu(hfinfo->name, module_name, proto_prefs_menus);
884
885 connect(proto_prefs_menu, &ProtocolPreferencesMenu::showProtocolPreferences,
886 this, &PacketList::showProtocolPreferences);
887 connect(proto_prefs_menu, SIGNAL(editProtocolPreference(pref_t*,module_t*))qFlagLocation("2" "editProtocolPreference(pref_t*,module_t*)"
"\0" "ui/qt/packet_list.cpp" ":" "887")
,
888 this, SIGNAL(editProtocolPreference(pref_t*,module_t*))qFlagLocation("2" "editProtocolPreference(pref_t*,module_t*)"
"\0" "ui/qt/packet_list.cpp" ":" "888")
);
889
890 proto_prefs_menus->addMenu(proto_prefs_menu);
891 added_proto_prefs << module_name;
892 }
893 }
894 }
895 ctx_menu->addMenu(proto_prefs_menus);
896 action = ctx_menu->addAction(tr("Decode As…"));
897 action->setProperty("create_new", QVariant(true));
898 connect(action, &QAction::triggered, this, &PacketList::ctxDecodeAsDialog);
899 // "Print" not ported intentionally
900 action = window()->findChild<QAction *>("actionViewShowPacketInNewWindow");
901 ctx_menu->addAction(action);
902 }
903
904 // Set menu sensitivity for the current column and set action data.
905 if (frameData)
906 emit framesSelected(QList<int>() << frameData->frameNum());
907 else
908 emit framesSelected(QList<int>());
909
910 ctx_menu->popup(event->globalPos());
911}
912
913void PacketList::ctxDecodeAsDialog()
914{
915 QAction *da_action = qobject_cast<QAction*>(sender());
916 if (! da_action)
917 return;
918 bool create_new = da_action->property("create_new").toBool();
919
920 DecodeAsDialog *da_dialog = new DecodeAsDialog(this, cap_file_, create_new);
921 connect(da_dialog, &DecodeAsDialog::destroyed, mainApp, &MainApplication::flushAppSignals);
922 da_dialog->setWindowModality(Qt::ApplicationModal);
923 da_dialog->setAttribute(Qt::WA_DeleteOnClose);
924 da_dialog->show();
925}
926
927void PacketList::timerEvent(QTimerEvent *event)
928{
929 if (event->timerId() == overlay_timer_id_) {
930 if (!capture_in_progress_ && model() != nullptr) {
931 if (create_near_overlay_) drawNearOverlay();
932 if (create_far_overlay_) drawFarOverlay();
933 }
934 } else if (event->timerId() == turbo_timer_id_) {
935 QKeyEvent turbo_step(QEvent::KeyPress, turbo_key_, Qt::NoModifier, QString(), true);
936 QTreeView::keyPressEvent(&turbo_step);
937 } else {
938 QTreeView::timerEvent(event);
939 }
940}
941
942void PacketList::paintEvent(QPaintEvent *event)
943{
944 // XXX This is overkill, but there are quite a few events that
945 // require a new overlay, e.g. page up/down, scrolling, column
946 // resizing, etc.
947 create_near_overlay_ = true;
948 QTreeView::paintEvent(event);
949}
950
951void PacketList::mousePressEvent(QMouseEvent *event)
952{
953 QTreeView::mousePressEvent(event);
954
955 QModelIndex curIndex = indexAt(event->pos());
956 mouse_pressed_at_ = curIndex;
957
958 bool midButton = (event->buttons() & Qt::MiddleButton) == Qt::MiddleButton;
959 if (midButton && cap_file_ && packet_list_model_)
960 {
961 packet_list_model_->toggleFrameMark(QModelIndexList() << curIndex);
962
963 // Make sure the packet list's frame.marked related field text is updated.
964 redrawVisiblePackets();
965
966 create_far_overlay_ = true;
967 packets_bar_update();
968 }
969}
970
971void PacketList::mouseReleaseEvent(QMouseEvent *event) {
972 QTreeView::mouseReleaseEvent(event);
973
974 mouse_pressed_at_ = QModelIndex();
975}
976
977// The pinned overlay views (PinnedColumnView/PinnedRowView) are separate
978// QTreeViews that only ever show a slice of the real content, laid out
979// independently of the primary view. Translating pixel coordinates from an
980// overlay's click into this view's coordinate space is unreliable -- their
981// row geometry can drift by a row even when the two appear visually
982// aligned (e.g. differing sub-pixel scroll remainders). Instead, the
983// overlay resolves the row itself via its own (always-correct, since it's
984// local) indexAt(), and these entry points act on that row/index directly
985// within this view, exactly as a real click here would.
986void PacketList::selectRowFromOverlay(int row, int column, Qt::MouseButtons buttons,
987 Qt::KeyboardModifiers modifiers)
988{
989 QModelIndex index = model()->index(row, column);
990 if (!index.isValid()) {
991 return;
992 }
993
994 // Selecting a pinned packet (the whole point of pinning it) shouldn't
995 // yank the primary view's scroll position to wherever that packet
996 // happens to be -- setCurrentIndex() below scrolls to make the new
997 // current index visible (QAbstractItemView's normal behavior for
998 // e.g. arrow-key navigation), which is exactly what a click in the
999 // pinned strip should NOT do. Save and restore the vertical scroll
1000 // position around it, the same way scrollTo() already does for the
1001 // horizontal one.
1002 int vert_scroll_value = verticalScrollBar()->value();
1003
1004 mouse_pressed_at_ = index;
1005
1006 // Mirrors the same three cases native ExtendedSelection handles for a
1007 // plain click (no modifier/Ctrl/Shift) -- this view's own
1008 // mousePressEvent() can't be relied on here since the click actually
1009 // landed in a different, overlay widget (PinnedRowView/
1010 // PinnedColumnView), which forwards here instead of letting
1011 // QAbstractItemView's native handling run.
1012 //
1013 // setCurrentIndex(QModelIndex) (the view-level convenience method) always
1014 // re-applies its own ClearAndSelect internally, which would immediately
1015 // clobber the Toggle/Select calls below -- moving "current" without
1016 // touching the selection just made requires going through
1017 // QItemSelectionModel::setCurrentIndex() directly with an explicit
1018 // NoUpdate flag instead.
1019 if (modifiers & Qt::ShiftModifier) {
1020 QModelIndex from = currentIndex().isValid() ? currentIndex() : index;
1021 selectionModel()->select(QItemSelection(from, index),
1022 QItemSelectionModel::Select | QItemSelectionModel::Rows);
1023 selectionModel()->setCurrentIndex(index, QItemSelectionModel::NoUpdate | QItemSelectionModel::Current);
1024 } else if (modifiers & Qt::ControlModifier) {
1025 selectionModel()->select(index, QItemSelectionModel::Toggle | QItemSelectionModel::Rows);
1026 selectionModel()->setCurrentIndex(index, QItemSelectionModel::NoUpdate | QItemSelectionModel::Current);
1027 } else {
1028 setCurrentIndex(index);
1029 selectionModel()->select(index, QItemSelectionModel::ClearAndSelect | QItemSelectionModel::Rows);
1030 }
1031
1032 verticalScrollBar()->setValue(vert_scroll_value);
1033 // Keep keyboard focus on the primary view so the selection highlight
1034 // always renders in its "active" color, regardless of which pane the
1035 // click that produced this selection landed in.
1036 setFocus();
1037
1038 // The pinned-row views draw their own selection highlight by reading
1039 // currentFrameNum()/selectedRows() directly (see PinnedRowView::drawRow()),
1040 // rather than sharing this view's QItemSelectionModel, so updating that
1041 // state above doesn't itself trigger a repaint there -- request one
1042 // explicitly, the same way setHoveredFrameNum() already does for hover.
1043 repaintPinnedOverlays();
1044
1045 if (buttons & Qt::MiddleButton) {
1046 packet_list_model_->toggleFrameMark(QModelIndexList() << index);
1047 redrawVisiblePackets();
1048 create_far_overlay_ = true;
1049 packets_bar_update();
1050 }
1051}
1052
1053void PacketList::selectFramesFromOverlay(const QList<int> &frame_nums)
1054{
1055 if (!packet_list_model_) {
1056 return;
1057 }
1058
1059 // Builds one QItemSelection out of each frame's own (single-row)
1060 // selection range rather than one spanning QItemSelection(first, last):
1061 // a single range only ever expresses a contiguous rectangle in one
1062 // model's row space, so there's no way to ask it for "just these
1063 // sparse primary-view rows" directly -- each frame number (already
1064 // resolved by the caller to just the pinned rows actually within a
1065 // strip-scoped Shift-click range, see
1066 // PinnedRowView::mousePressEvent()) is resolved to its own primary-view
1067 // row here, which naturally excludes any unpinned row that happens to
1068 // sit between them there. Accumulated into one QItemSelection and
1069 // applied via a single select() call (rather than clearSelection() +
1070 // one select() per frame) so selectionChanged() -- which does real
1071 // work per call, e.g. rebuilding and emitting framesSelected() -- only
1072 // fires once for the whole batch, not once per frame.
1073 QItemSelection combined;
1074 QModelIndex last_valid_index;
1075 for (int frame_num : frame_nums) {
1076 int row = packet_list_model_->packetNumberToRow(frame_num);
1077 if (row < 0) {
1078 // Filtered out of the primary view -- no row here to add to
1079 // the shared QItemSelectionModel for it, same documented
1080 // limitation selectFrameFromOverlay() already carries for a
1081 // single filtered-out pinned row.
1082 continue;
1083 }
1084 QModelIndex row_index = model()->index(row, 0);
1085 combined.select(row_index, row_index);
1086 last_valid_index = row_index;
1087 }
1088
1089 // Matches selectRowFromOverlay()/selectFrameFromOverlay(), which both
1090 // update or clear this: stale drag-select state left over from an
1091 // earlier real click on this view itself shouldn't be mistaken for a
1092 // drag matching whatever row a later mouseMoveEvent() lands on (see
1093 // mouse_pressed_at_'s own comment and its use at line ~1431).
1094 mouse_pressed_at_ = QModelIndex();
1095 selectionModel()->select(combined, QItemSelectionModel::ClearAndSelect | QItemSelectionModel::Rows);
1096
1097 if (last_valid_index.isValid()) {
1098 selectionModel()->setCurrentIndex(last_valid_index,
1099 QItemSelectionModel::NoUpdate | QItemSelectionModel::Current);
1100 }
1101 setFocus();
1102
1103 // The pinned-row views draw their own selection highlight by reading
1104 // currentFrameNum()/selectedRows() directly (see PinnedRowView::drawRow()),
1105 // rather than sharing this view's QItemSelectionModel, so updating that
1106 // state above doesn't itself trigger a repaint there -- request one
1107 // explicitly, the same way setHoveredFrameNum() already does for hover.
1108 repaintPinnedOverlays();
1109}
1110
1111void PacketList::selectFrameFromOverlay(int frame_num, Qt::KeyboardModifiers /* modifiers */)
1112{
1113 if (!cap_file_ || !packet_list_model_) {
1114 return;
1115 }
1116
1117 PacketListRecord *record = packet_list_model_->physicalRecordForFrameNum(frame_num);
1118 frame_data *fdata = record ? record->frameData() : nullptr;
1119 if (!fdata) {
1120 return;
1121 }
1122
1123 // Clear any real selection in this view's own model: the frame being
1124 // selected may not even have a row here (it can be filtered out), so
1125 // there's no index to select instead. Mirrors the "nothing selected"
1126 // path selectionChanged() takes for row < 0.
1127 selectionModel()->clearSelection();
1128 setCurrentIndex(QModelIndex());
1129 mouse_pressed_at_ = QModelIndex();
1130 setFocus();
1131
1132 // The pinned-row views draw their own selection highlight by reading
1133 // currentFrameNum()/selectedRows() directly (see PinnedRowView::drawRow()),
1134 // rather than sharing this view's QItemSelectionModel, so updating that
1135 // state above doesn't itself trigger a repaint there -- request one
1136 // explicitly, the same way setHoveredFrameNum() already does for hover.
1137 repaintPinnedOverlays();
1138
1139 // cf_select_packet() works directly against the capture file's own
1140 // frame array and is independent of the display filter/QModelIndex
1141 // entirely -- unlike selectionChanged()'s row-based path, which can
1142 // only ever resolve a frame that currently has a row in this view.
1143 cf_select_packet(cap_file_, fdata);
1144
1145 // This adds a frame to the history even if it's filtered out and not in
1146 // the main view. Such a frame will be skipped by have[Next|Previous]History
1147 // and thus go[Next|Previous]HistoryPacket, but is preserved in the history
1148 // for when the filter changes. To make goToHistory work for frames which
1149 // are filtered out but still pinned would take more work.
1150 if (cap_file_->current_frame) {
1151 updateHistory(cap_file_->current_frame->num);
1152 }
1153
1154 related_packet_delegate_.clear();
1155
1156 // The previous dissection state has been invalidated by
1157 // cf_select_packet() above; receivers must clear the previous state
1158 // and apply the updated one.
1159 emit framesSelected(QList<int>() << frame_num);
1160
1161 if (!cap_file_->edt) {
1162 viewport()->update();
1163 emit fieldSelected(0);
1164 return;
1165 }
1166
1167 if (cap_file_->edt->tree) {
1168 packet_info *pi = &cap_file_->edt->pi;
1169 related_packet_delegate_.setCurrentFrame(pi->num);
1170 conversation_t *conv = find_conversation_pinfo_ro(pi, 0);
1171 if (conv) {
1172 related_packet_delegate_.setConversation(conv);
1173 }
1174 viewport()->update();
1175 }
1176
1177 if (proto_tree_) {
1178 proto_tree_->restoreSelectedField();
1179 } else {
1180 emit fieldSelected(0);
1181 }
1182}
1183
1184void PacketList::showContextMenuForRow(int row, const QPoint &global_pos, bool from_pinned_row_strip)
1185{
1186 QModelIndex index = model()->index(row, 0);
1187 if (!index.isValid()) {
1188 return;
1189 }
1190
1191 ctx_from_pinned_row_strip_ = from_pinned_row_strip;
1192
1193 // visualRect() is this view's own geometry query, so it can't drift
1194 // the way a translated cross-view pixel position could; it guarantees
1195 // contextMenuEvent()'s own indexAt() resolves back to this exact row.
1196 QPoint local_pos = visualRect(index).center();
1197 QContextMenuEvent translated(QContextMenuEvent::Mouse, local_pos, global_pos);
1198 contextMenuEvent(&translated);
1199}
1200
1201void PacketList::showContextMenuForFrame(int frame_num, const QPoint &global_pos, bool from_pinned_row_strip)
1202{
1203 ctx_from_pinned_row_strip_ = from_pinned_row_strip;
1204
1205 // Select the frame first so cap_file_->current_frame/edt reflect it --
1206 // contextMenuEvent() falls back to cap_file_->current_frame whenever
1207 // indexAt() resolves to an invalid index (see below), which is
1208 // exactly what happens for a pinned packet with no row in this view
1209 // at all (i.e. filtered out).
1210 selectFrameFromOverlay(frame_num);
1211
1212 // A position guaranteed to resolve to an invalid index via
1213 // indexAt(), same idea as showContextMenuForRow() using a real row's
1214 // visualRect() to guarantee the opposite. contextMenuEvent() then
1215 // uses the ctx_row_fdata fallback to cap_file_->current_frame set by
1216 // selectFrameFromOverlay() above instead of a row-based lookup.
1217 QPoint local_pos(-1, -1);
1218 QContextMenuEvent translated(QContextMenuEvent::Mouse, local_pos, global_pos);
1219 contextMenuEvent(&translated);
1220}
1221
1222// header_pos must already be in packet_list_header_'s (the real, primary
1223// header's) own coordinate space by the time it reaches each forwarder
1224// below -- every caller (PinnedColumnHeader, and PacketListPane's
1225// duplicate_header_corner_/duplicate_header_main_ event filter) is
1226// responsible for translating its own local position into that space
1227// first, since each has a different relationship to it (PinnedColumnHeader
1228// and duplicate_header_corner_ both start at the frozen boundary the same
1229// way packet_list_header_'s own unscrolled columns [0, boundary) do;
1230// duplicate_header_main_ instead starts at the boundary itself and must
1231// add its own width). See PacketList::frozenHeaderPosToReal() for the
1232// shared translation helper used by PinnedColumnHeader.
1233QPoint PacketList::frozenHeaderPosToReal(const QPoint &frozen_pos) const
1234{
1235 int logical_index = pinned_column_view_->header()->logicalIndexAt(frozen_pos);
1236 if (logical_index < 0) {
1237 return frozen_pos;
1238 }
1239 int real_x = packet_list_header_->sectionViewportPosition(logical_index)
1240 + (frozen_pos.x() - pinned_column_view_->header()->sectionViewportPosition(logical_index));
1241 return QPoint(real_x, frozen_pos.y());
1242}
1243
1244void PacketList::forwardHeaderContextMenu(QContextMenuEvent *event, const QPoint &header_pos)
1245{
1246 // event->globalPos() (from the original click, wherever it actually
1247 // happened on screen) rather than packet_list_header_->mapToGlobal(
1248 // header_pos): the latter assumes the real header is on-screen at its
1249 // usual position, which isn't true when this request originated from
1250 // duplicate_header_ (PacketListPane's stand-in header shown above the
1251 // pinned-rows strip while the real one is hidden) -- that would pop
1252 // the menu up at the real header's location instead of where the user
1253 // actually right-clicked.
1254 QContextMenuEvent translated(event->reason(), header_pos, event->globalPos(), event->modifiers());
1255 packet_list_header_->showContextMenuAt(&translated);
1256}
1257
1258void PacketList::forwardHeaderMousePress(QMouseEvent *event, const QPoint &header_pos)
1259{
1260 // Temporarily disable click-to-sort on the real header: forwarding
1261 // press/release here is only meant to drive its resize-drag state
1262 // machine (needed so a frozen column's resize actually changes the
1263 // shared column width). QHeaderView's mouseReleaseEvent does its own
1264 // native click-to-sort detection as a side effect of the same event,
1265 // which would otherwise double up with the explicit
1266 // sortByColumnFromOverlay() call and cancel it out.
1267 packet_list_header_->setSectionsClickable(false);
1268 QMouseEvent translated(event->type(), header_pos, packet_list_header_->mapToGlobal(header_pos),
1269 event->button(), event->buttons(), event->modifiers());
1270 packet_list_header_->forwardMousePressEvent(&translated);
1271}
1272
1273void PacketList::forwardHeaderMouseMove(QMouseEvent *event, const QPoint &header_pos)
1274{
1275 QMouseEvent translated(event->type(), header_pos, packet_list_header_->mapToGlobal(header_pos),
1276 event->button(), event->buttons(), event->modifiers());
1277 packet_list_header_->forwardMouseMoveEvent(&translated);
1278}
1279
1280void PacketList::forwardHeaderMouseRelease(QMouseEvent *event, const QPoint &header_pos)
1281{
1282 QMouseEvent translated(event->type(), header_pos, packet_list_header_->mapToGlobal(header_pos),
1283 event->button(), event->buttons(), event->modifiers());
1284 packet_list_header_->forwardMouseReleaseEvent(&translated);
1285 packet_list_header_->setSectionsClickable(true);
1286}
1287
1288void PacketList::forwardWheelEvent(QWheelEvent *event)
1289{
1290 QTreeView::wheelEvent(event);
1291}
1292
1293void PacketList::sortByColumnFromOverlay(int column)
1294{
1295 if (!isSortingEnabled()) {
1296 return;
1297 }
1298
1299 Qt::SortOrder order = Qt::AscendingOrder;
1300 if (header()->sortIndicatorSection() == column) {
1301 order = (header()->sortIndicatorOrder() == Qt::AscendingOrder) ? Qt::DescendingOrder : Qt::AscendingOrder;
1302 }
1303 header()->setSortIndicator(column, order);
1304
1305 // The frozen column view's own header is a separate QHeaderView, so it
1306 // needs its sort indicator (the arrow icon) set explicitly to match --
1307 // it doesn't automatically follow the primary header's indicator.
1308 if (pinned_column_view_) {
1309 pinned_column_view_->mirrorSortIndicator(column, order);
1310 }
1311}
1312
1313void PacketList::mouseMoveEvent (QMouseEvent *event)
1314{
1315 QModelIndex curIndex = indexAt(event->pos());
1316 frame_data *hovered_fdata = curIndex.isValid() ? getFDataForRow(curIndex.row()) : nullptr;
1
'?' condition is true
1317 int new_hovered_frame_num = hovered_fdata ? (int)hovered_fdata->num : -1;
2
Assuming 'hovered_fdata' is null
3
'?' condition is false
1318 if (new_hovered_frame_num != hovered_frame_num_) {
4
Assuming 'new_hovered_frame_num' is equal to field 'hovered_frame_num_'
1319 hovered_frame_num_ = new_hovered_frame_num;
1320 viewport()->update();
1321 repaintPinnedOverlays();
1322 }
1323
1324 if (event->buttons() & Qt::LeftButton && curIndex.isValid() && curIndex == mouse_pressed_at_)
5
Assuming the condition is true
6
Taking true branch
1325 {
1326 ctx_column_ = curIndex.column();
1327 QMimeData * mimeData = new QMimeData();
1328 DragLabel * drag_label = nullptr;
1329
1330 QString filter = getFilterFromRowAndColumn(curIndex);
1331 QList<int> rows = selectedRows();
1332 if (rows.count() > 1)
7
Assuming the condition is false
8
Taking false branch
1333 {
1334 QStringList entries;
1335 foreach (int row, rows)for (auto _container_1335 = QtPrivate::qMakeForeachContainer(
rows); _container_1335.i != _container_1335.e; ++_container_1335
.i) if (int row = *_container_1335.i; false) {} else
1336 {
1337 QModelIndex idx = model()->index(row, 0);
1338 if (! idx.isValid())
1339 continue;
1340
1341 QString entry = createSummaryText(idx, CopyAsText);
1342 entries << entry;
1343 }
1344
1345 if (entries.count() > 0)
1346 mimeData->setText(entries.join("\n"));
1347 }
1348 else if (! filter.isEmpty())
9
Assuming the condition is true
10
Taking true branch
1349 {
1350 QString abbrev;
1351 QString name = model()->headerData(curIndex.column(), header()->orientation()).toString();
1352
1353 if (! filter.isEmpty())
11
Assuming the condition is false
12
Taking false branch
1354 {
1355 abbrev = filter.left(filter.indexOf(' '));
1356 }
1357 else
1358 {
1359 filter = model()->data(curIndex).toString().toLower();
1360 abbrev = filter;
1361 }
1362
1363 mimeData->setText(filter);
1364
1365 QJsonObject filterData;
1366 filterData["filter"] = filter;
1367 filterData["name"] = abbrev;
1368 filterData["description"] = name;
1369
1370 mimeData->setData(WiresharkMimeData::DisplayFilterMimeType, QJsonDocument(filterData).toJson());
1371 drag_label = new DragLabel(QStringLiteral("%1\n%2")(QString(QtPrivate::qMakeStringPrivate(u"" "%1\n%2"))).arg(name, abbrev), this);
13
Memory is allocated
1372 }
1373 else
1374 {
1375 QString text = model()->data(curIndex).toString();
1376 if (! text.isEmpty())
1377 mimeData->setText(text);
1378 }
1379
1380 if (mimeData->hasText() || mimeData->hasFormat(WiresharkMimeData::DisplayFilterMimeType))
14
Assuming the condition is false
15
Assuming the condition is false
16
Taking false branch
1381 {
1382 QDrag * drag = new QDrag(this);
1383 drag->setMimeData(mimeData);
1384 if (drag_label)
1385 {
1386 qreal dpr = window()->windowHandle()->devicePixelRatio();
1387 QPixmap pixmap= QPixmap(drag_label->size() * dpr);
1388 pixmap.setDevicePixelRatio(dpr);
1389 drag_label->render(&pixmap);
1390 drag->setPixmap(pixmap);
1391 delete drag_label;
1392 }
1393
1394 drag->exec(Qt::CopyAction);
1395 }
1396 else
1397 {
1398 delete mimeData;
17
Potential leak of memory pointed to by 'drag_label'
1399 }
1400 }
1401}
1402
1403void PacketList::leaveEvent(QEvent *event)
1404{
1405 QTreeView::leaveEvent(event);
1406
1407 if (hovered_frame_num_ != -1) {
1408 hovered_frame_num_ = -1;
1409 viewport()->update();
1410 repaintPinnedOverlays();
1411 }
1412}
1413
1414void PacketList::setHoveredRowFromOverlay(int row)
1415{
1416 frame_data *fdata = (row >= 0) ? getFDataForRow(row) : nullptr;
1417 setHoveredFrameNum(fdata ? (int)fdata->num : -1);
1418}
1419
1420void PacketList::setHoveredFrameNum(int frame_num)
1421{
1422 if (frame_num == hovered_frame_num_) {
1423 return;
1424 }
1425
1426 hovered_frame_num_ = frame_num;
1427 viewport()->update();
1428 repaintPinnedOverlays();
1429}
1430
1431void PacketList::keyPressEvent(QKeyEvent *event)
1432{
1433 // XXX Add support for Qt::Key_F7 and Qt::Key_F8
1434 bool nav_key = (event->key() == Qt::Key_Up || event->key() == Qt::Key_Down);
1435
1436 if (nav_key && event->isAutoRepeat()) {
1437 Qt::Key key = static_cast<Qt::Key>(event->key());
1438
1439 if (turbo_timer_id_ != 0 && key == turbo_key_) {
1440 // We're handling autorepeat ourselves.
1441 event->accept();
1442 return;
1443 }
1444
1445 if (turbo_timer_id_ == 0 && key == held_key_ && key_hold_elapsed_.isValid() &&
1446 key_hold_elapsed_.hasExpired(turbo_activation_delay_)) {
1447 turbo_key_ = key;
1448 turbo_timer_id_ = startTimer(turbo_nav_interval_);
1449 event->accept();
1450 return;
1451 }
1452 }
1453
1454 QTreeView::keyPressEvent(event);
1455
1456 if (nav_key && !event->isAutoRepeat()) {
1457 held_key_ = static_cast<Qt::Key>(event->key());
1458 key_hold_elapsed_.start();
1459 }
1460
1461 if (event->matches(QKeySequence::Copy))
1462 {
1463 QStringList content, htmlContent;
1464 if (model() && selectionModel() && selectionModel()->hasSelection())
1465 {
1466 QList<int> rows;
1467 QModelIndexList selRows = selectionModel()->selectedRows(0);
1468 foreach(QModelIndex row, selRows)for (auto _container_1468 = QtPrivate::qMakeForeachContainer(
selRows); _container_1468.i != _container_1468.e; ++_container_1468
.i) if (QModelIndex row = *_container_1468.i; false) {} else
1469 rows.append(row.row());
1470
1471 QStringList hdr_parts;
1472 QList<int> align_parts, size_parts;
1473
1474 switch (prefs.gui_packet_list_copy_format_options_for_keyboard_shortcut) {
1475 case COPY_FORMAT_TEXT:
1476 case COPY_FORMAT_HTML:
1477 if (prefs.gui_packet_list_copy_text_with_aligned_columns) {
1478 hdr_parts = createHeaderPartsForAligned();
1479 align_parts = createAlignmentPartsForAligned();
1480 size_parts = createSizePartsForAligned(false, hdr_parts, rows);
1481 }
1482 if (prefs.gui_packet_list_copy_format_options_for_keyboard_shortcut == COPY_FORMAT_HTML) {
1483 htmlContent << createDefaultStyleForHtml();
1484 htmlContent << createOpeningTagForHtml();
1485 }
1486 break;
1487 case COPY_FORMAT_CSV:
1488 case COPY_FORMAT_YAML:
1489 break;
1490 }
1491
1492 QList<QStringList> entries;
1493 foreach(int row, rows)for (auto _container_1493 = QtPrivate::qMakeForeachContainer(
rows); _container_1493.i != _container_1493.e; ++_container_1493
.i) if (int row = *_container_1493.i; false) {} else
1494 {
1495 QModelIndex idx = model()->index(row, 0);
1496 if (! idx.isValid())
1497 continue;
1498
1499 switch (prefs.gui_packet_list_copy_format_options_for_keyboard_shortcut) {
1500 case COPY_FORMAT_TEXT:
1501 case COPY_FORMAT_HTML:
1502 if (prefs.gui_packet_list_copy_text_with_aligned_columns)
1503 content << createSummaryForAligned(idx, align_parts, size_parts);
1504 else
1505 content << createSummaryText(idx, CopyAsText);
1506 if (prefs.gui_packet_list_copy_format_options_for_keyboard_shortcut == COPY_FORMAT_HTML)
1507 htmlContent << createSummaryForHtml(idx);
1508 break;
1509 case COPY_FORMAT_CSV:
1510 content << createSummaryText(idx, CopyAsCSV);
1511 break;
1512 case COPY_FORMAT_YAML:
1513 content << createSummaryText(idx, CopyAsYAML);
1514 break;
1515 }
1516 }
1517 }
1518
1519 if (prefs.gui_packet_list_copy_format_options_for_keyboard_shortcut == COPY_FORMAT_HTML) {
1520 // htmlContent will never be empty as they will always have style and table tags
1521 QMimeData *mimeData = new QMimeData;
1522 htmlContent << createClosingTagForHtml();
1523 mimeData->setHtml(htmlContent.join('\n'));
1524 mimeData->setText(content.join('\n').append("\n"));
1525 mainApp->clipboard()->setMimeData(mimeData, QClipboard::Clipboard);
1526 }
1527 else {
1528 if (content.count() > 0) {
1529 QString copy_text;
1530 if (prefs.gui_packet_list_copy_format_options_for_keyboard_shortcut == COPY_FORMAT_YAML) {
1531 copy_text = content.join("");
1532 }
1533 else {
1534 copy_text = content.join("\n");
1535 copy_text += "\n";
1536 }
1537 mainApp->clipboard()->setText(copy_text);
1538 }
1539 }
1540 }
1541}
1542
1543void PacketList::keyReleaseEvent(QKeyEvent *event)
1544{
1545 if (!event->isAutoRepeat() && event->key() == held_key_) {
1546 if (turbo_timer_id_ != 0 && event->key() == turbo_key_) {
1547 killTimer(turbo_timer_id_);
1548 turbo_timer_id_ = 0;
1549 }
1550 held_key_ = Qt::Key(0);
1551 key_hold_elapsed_.invalidate();
1552 }
1553
1554 QTreeView::keyReleaseEvent(event);
1555}
1556
1557void PacketList::focusInEvent(QFocusEvent *event)
1558{
1559 QTreeView::focusInEvent(event);
1560
1561 if (event->reason() == Qt::TabFocusReason || event->reason() == Qt::BacktabFocusReason) {
1562 if (model() && model()->rowCount() > 0 && selectionModel()) {
1563 if (!selectionModel()->hasSelection()) {
1564 QModelIndex first = model()->index(0, 0);
1565 if (first.isValid()) {
1566 selectionModel()->setCurrentIndex(first, QItemSelectionModel::ClearAndSelect | QItemSelectionModel::Rows);
1567 setCurrentIndex(first);
1568 }
1569 }
1570
1571 // ALWAYS scroll to the current index if we have one
1572 if (currentIndex().isValid()) {
1573 scrollTo(currentIndex());
1574 }
1575 }
1576 }
1577}
1578
1579void PacketList::focusOutEvent(QFocusEvent *event)
1580{
1581 if (turbo_timer_id_ != 0) {
1582 killTimer(turbo_timer_id_);
1583 turbo_timer_id_ = 0;
1584 }
1585 held_key_ = Qt::Key(0);
1586 key_hold_elapsed_.invalidate();
1587
1588 QTreeView::focusOutEvent(event);
1589}
1590
1591void PacketList::resizeEvent(QResizeEvent *event)
1592{
1593 create_near_overlay_ = true;
1594 create_far_overlay_ = true;
1595 QTreeView::resizeEvent(event);
1596 layoutPinnedOverlays();
1597}
1598
1599void PacketList::setColumnVisibility()
1600{
1601 set_column_visibility_ = true;
1602 for (unsigned i = 0; i < prefs.num_cols; i++) {
1603 bool hidden = get_column_visible(i) ? false : true;
1604 bool frozen = isColumnFrozen((int)i, pinned_column_boundary_);
1605 setColumnHidden(i, hidden);
1606 if (pinned_column_view_) {
1607 pinned_column_view_->setColumnHidden(i, hidden || !frozen);
1608 }
1609 if (pinned_row_view_) {
1610 pinned_row_view_->setColumnHidden(i, hidden || frozen);
1611 }
1612 if (pinned_row_corner_view_) {
1613 pinned_row_corner_view_->setColumnHidden(i, hidden || !frozen);
1614 }
1615 emit columnHiddenChanged(i, hidden);
1616 }
1617 setColumnDelegate();
1618 set_column_visibility_ = false;
1619}
1620
1621void PacketList::setColumnDelegate()
1622{
1623 for (unsigned i = 0; i < prefs.num_cols; i++) {
1624 setItemDelegateForColumn(i, nullptr); // Reset all delegates
1625 }
1626
1627 // Multi-color delegate takes precedence over related packet delegate (row stripes only, not scrollbar-only mode)
1628 if (prefs.gui_packet_list_multi_color_mode == PACKET_LIST_MULTI_COLOR_MODE_FULL ||
1629 prefs.gui_packet_list_multi_color_mode == PACKET_LIST_MULTI_COLOR_MODE_SHIFT_RIGHT) {
1630 for (unsigned i = 0; i < prefs.num_cols; i++) {
1631 if (get_column_visible(i)) {
1632 setItemDelegateForColumn(i, &multi_color_delegate_);
1633 }
1634 }
1635 }
1636 else if (prefs.gui_packet_list_show_related) {
1637 for (unsigned i = 0; i < prefs.num_cols; i++) {
1638 if (get_column_visible(i)) {
1639 setItemDelegateForColumn(i, &related_packet_delegate_);
1640 break; // Set the delegate only on the first visible column
1641 }
1642 }
1643 }
1644
1645 for (unsigned i = 0; i < prefs.num_cols; i++) {
1646 QAbstractItemDelegate *col_delegate = itemDelegateForColumn(i);
1647 if (!col_delegate) {
1648 continue;
1649 }
1650 for (QTreeView *view : pinnedOverlayViews()) {
1651 view->setItemDelegateForColumn(i, col_delegate);
1652 }
1653 }
1654}
1655
1656void PacketList::setRecentColumnWidth(int col)
1657{
1658 int col_width = recent_get_column_width(col);
1659
1660 if (col_width < 1) {
1661 int fmt = get_column_format(col);
1662 const char *long_str = get_column_width_string(fmt, col);
1663
1664 // TODO: a column's natural width is model data, not a view concern.
1665 // PacketListModel should hint it instead of the view measuring against
1666 // the font here.
1667 QFontMetrics fm = QFontMetrics(FontManager::monospaceFont());
1668 if (long_str) {
1669 col_width = fm.horizontalAdvance(long_str);
1670 } else {
1671 col_width = fm.horizontalAdvance(MIN_COL_WIDTH_STR"MMMMMM");
1672 }
1673 // Custom delegate padding
1674 if (itemDelegateForColumn(col)) {
1675 QStyleOptionViewItem option;
1676 initViewItemOption(&option);
1677 // This is adding "how much width hinted for an empty index, plus
1678 // the decoration, plus any padding between the decoration and
1679 // normal display?" Many styles however have a non zero hint for
1680 // an empty index, so this isn't quite right. What we really want
1681 // is a size hint for an index whose data is the string above, and
1682 // to just use that for the width.
1683 col_width += itemDelegateForColumn(col)->sizeHint(option, QModelIndex()).width();
1684 }
1685 }
1686
1687 setColumnWidth(col, col_width);
1688}
1689
1690void PacketList::drawCurrentPacket(bool scroll)
1691{
1692 // Update the dissection details for the current frame.
1693 //
1694 // It might make sense to call this from dataChanged if a single frame
1695 // is selected and its index is among those changed, instead of, e.g.,
1696 // markFrame() having to call this directly. Note however that
1697 // PacketListModel calls layoutChanged instead of dataChanged due
1698 // to a Qt 6 bug (that appears to have been mitigated in Qt 6.9),
1699 // so we perhaps have to listen to LayoutChanged as well.
1700 if (!cap_file_) return;
1701
1702 int row = -1;
1703 static bool multiSelect = false;
1704 QList<int> selectedFrames;
1705
1706 if (selectionModel())
1707 {
1708 QModelIndexList selRows = selectionModel()->selectedRows(0);
1709 if (selRows.count() > 1)
1710 {
1711 if (packet_list_model_) {
1712 foreach (QModelIndex idx, selRows)for (auto _container_1712 = QtPrivate::qMakeForeachContainer(
selRows); _container_1712.i != _container_1712.e; ++_container_1712
.i) if (QModelIndex idx = *_container_1712.i; false) {} else
1713 {
1714 frame_data * fdata = packet_list_model_->getRowFdata(idx);
1715 if (fdata)
1716 selectedFrames << fdata->num;
1717 }
1718 }
1719
1720 emit framesSelected(selectedFrames);
1721 emit fieldSelected(0);
1722 cf_unselect_packet(cap_file_);
1723
1724 /* We have to repaint the content while changing state, as some delegates react to multi-select */
1725 if (! multiSelect)
1726 {
1727 related_packet_delegate_.clear();
1728 viewport()->update();
1729 }
1730
1731 multiSelect = true;
1732
1733 return;
1734 }
1735 else if (selRows.count() > 0 && selRows.at(0).isValid())
1736 {
1737 /* One row selected. Note this is *not* necessarily the row of the
1738 * currentIndex, if two rows were selected and one was deselected
1739 * via Ctrl-Click. Then the currentIndex is the deselected row. */
1740 multiSelect = false;
1741 row = selRows.at(0).row();
1742 if (scroll) {
1743 if (currentIndex().siblingAtColumn(0) != selRows.at(0)) {
1744 // Not the currentIndex. Set the current index, which will
1745 // scroll to it. Use NoUpdate to not change the selection
1746 // and possibly create a loop.
1747 selectionModel()->setCurrentIndex(selRows.at(0), QItemSelectionModel::NoUpdate);
1748 } else {
1749 // The currentIndex. Scroll to it if necessary.
1750 scrollTo(currentIndex());
1751 }
1752 }
1753 }
1754
1755 /* Handling empty selection */
1756 if (selRows.count() <= 0)
1757 {
1758 /* Nothing selected, but multiSelect is still active */
1759 if (multiSelect)
1760 {
1761 multiSelect = false;
1762 if (currentIndex().isValid())
1763 {
1764 selectionModel()->select(currentIndex(), QItemSelectionModel::ClearAndSelect | QItemSelectionModel::Rows );
1765 return;
1766 }
1767 }
1768 /* Nothing selected, so in WS <= 3.0 nothing was indicated as well */
1769 else if (currentIndex().isValid())
1770 {
1771 setCurrentIndex(QModelIndex());
1772 }
1773 }
1774 }
1775
1776 if (row < 0 || !packet_list_model_)
1777 cf_unselect_packet(cap_file_);
1778 else {
1779 frame_data * fdata = packet_list_model_->getRowFdata(row);
1780 cf_select_packet(cap_file_, fdata);
1781 if (fdata)
1782 selectedFrames << fdata->num;
1783 }
1784
1785 if (cap_file_->current_frame) {
1786 // Add this to the end of the history if it's not already
1787 updateHistory(cap_file_->current_frame->num);
1788 }
1789
1790 related_packet_delegate_.clear();
1791
1792 // The previous dissection state has been invalidated by cf_select_packet
1793 // above, receivers must clear the previous state and apply the updated one.
1794 emit framesSelected(selectedFrames);
1795
1796 if (!cap_file_->edt) {
1797 viewport()->update();
1798 emit fieldSelected(0);
1799 return;
1800 }
1801
1802 if (cap_file_->edt->tree) {
1803 packet_info *pi = &cap_file_->edt->pi;
1804 related_packet_delegate_.setCurrentFrame(pi->num);
1805 conversation_t *conv = find_conversation_pinfo_ro(pi, 0);
1806 if (conv) {
1807 related_packet_delegate_.setConversation(conv);
1808 }
1809 viewport()->update();
1810 }
1811
1812 // Figure out what field should be selected.
1813 // XXX - All this should be done in ProtoTree in response to framesSelected
1814 if (cap_file_->search_in_progress) {
1815 field_info *fi = NULL__null;
1816
1817 if (cap_file_->string && cap_file_->decode_data) {
1818 // The tree where the target string matched one of the labels was discarded in
1819 // match_protocol_tree() so we have to search again in the latest tree.
1820 fi = cf_find_string_protocol_tree(cap_file_, cap_file_->edt->tree);
1821 } else if (cap_file_->search_len != 0) {
1822 // Find the finfo that corresponds to our byte.
1823 // The match can span multiple fields (and a single byte can
1824 // match more than one field.) Our behavior is to find the last
1825 // field in the tree (so hopefully spanning fewer bytes) that
1826 // matches the last byte in the search match.
1827 // (regex search can find a zero length match not at the
1828 // start of the frame if lookbehind is used, but
1829 // proto_find_field_from_offset doesn't match such a field
1830 // and it's not clear which field we would want to match.)
1831 fi = proto_find_field_from_offset(cap_file_->edt->tree, cap_file_->search_pos + cap_file_->search_len - 1,
1832 cap_file_->edt->tvb);
1833 }
1834
1835 if (fi) {
1836 FieldInformation finfo(fi, this);
1837 emit fieldSelected(&finfo);
1838 } else {
1839 emit fieldSelected(0);
1840 }
1841 } else if (proto_tree_) {
1842 proto_tree_->restoreSelectedField();
1843 }
1844}
1845
1846// Redraw the packet list and detail.
1847// Causes the UI to scroll to the current packet.
1848// Called from many places.
1849void PacketList::redrawVisiblePackets() {
1850 packet_list_model_->invalidateAllColumnStrings();
1851 drawCurrentPacket();
1852}
1853
1854// Redraw the packet list and detail.
1855// Does not scroll back to the selected packet.
1856void PacketList::redrawVisiblePacketsDontSelectCurrent() {
1857 packet_list_model_->invalidateAllColumnStrings();
1858 drawCurrentPacket(false);
1859}
1860
1861void PacketList::resetColumns()
1862{
1863 packet_list_model_->resetColumns();
1864}
1865
1866// Return true if we have a visible packet further along in the history.
1867bool PacketList::haveNextHistory(bool update_cur)
1868{
1869 if (selection_history_.size() < 1 || cur_history_ >= selection_history_.size() - 1) {
1870 return false;
1871 }
1872
1873 for (int i = cur_history_ + 1; i < selection_history_.size(); i++) {
1874 if (packet_list_model_->packetNumberToRow(selection_history_.at(i)) >= 0) {
1875 if (update_cur) {
1876 cur_history_ = i;
1877 }
1878 return true;
1879 }
1880 }
1881 return false;
1882}
1883
1884// Return true if we have a visible packet back in the history.
1885bool PacketList::havePreviousHistory(bool update_cur)
1886{
1887 if (selection_history_.size() < 1 || cur_history_ < 1) {
1888 return false;
1889 }
1890
1891 for (int i = cur_history_ - 1; i >= 0; i--) {
1892 if (packet_list_model_->packetNumberToRow(selection_history_.at(i)) >= 0) {
1893 if (update_cur) {
1894 cur_history_ = i;
1895 }
1896 return true;
1897 }
1898 }
1899 return false;
1900}
1901
1902void PacketList::updateHistory(int frame_num)
1903{
1904 // We want to call this whenever cap_file_->current_frame changes.
1905 // (We don't keep a history of frames that were selected as part of
1906 // multiselect.) That is not the same thing as the currentIndex. First,
1907 // because the pinned rows can set a frame as the current frame that
1908 // isn't in the main view (and thus never becomes the currentIndex.)
1909 // Secondly, because with ExtendedSelection an index can become the
1910 // currentIndex by being in a multi-selection and then *deselected*
1911 // with Ctrl-Click. (Also, if two frames were selected, the remaining
1912 // frame then becomes cap_file_->current_frame but not CurrentIndex.)
1913 if (in_history_)
1914 return;
1915
1916 if (!selection_history_.isEmpty()) {
1917 if (frame_num == selection_history_.constLast()) {
1918 return;
1919 }
1920 }
1921
1922 cur_history_++;
1923 selection_history_.append(frame_num);
1924}
1925
1926void PacketList::setProfileSwitcher(ProfileSwitcher *profile_switcher)
1927{
1928 profile_switcher_ = profile_switcher;
1929 if (profile_switcher) {
1930 connect(packet_list_model_, &PacketListModel::packetAppended, profile_switcher_, &ProfileSwitcher::checkPacket);
1931 }
1932}
1933
1934frame_data *PacketList::getFDataForRow(int row) const
1935{
1936 return packet_list_model_->getRowFdata(row);
1937}
1938
1939// prefs.col_list has changed.
1940void PacketList::columnsChanged()
1941{
1942 columns_changed_ = true;
1943 column_register_fields();
1944 mainApp->emitAppSignal(MainApplication::FieldsChanged);
1945 if (!cap_file_) {
1946 // Keep columns_changed_ = true until we load a capture file.
1947 return;
1948 }
1949
1950 prefs.num_cols = g_list_length(prefs.col_list);
1951 col_cleanup(&cap_file_->cinfo);
1952 build_column_format_array(&cap_file_->cinfo, prefs.num_cols, false);
1953 create_far_overlay_ = true;
1954 resetColumns();
1955 applyRecentColumnWidths();
1956 setColumnVisibility();
1957 // Freezing is defined purely positionally ("the first N columns"), and
1958 // this signal doesn't say which column(s) actually changed -- a
1959 // removal, addition, or reorder can each change which logical columns
1960 // now sit at positions [0, pinned_column_boundary_), so there's no way
1961 // to tell from here whether the frozen set still means what the user
1962 // last chose. Unfreezing unconditionally is conservative (it also
1963 // clears a freeze that a change elsewhere in the column list didn't
1964 // actually affect), but guarantees the frozen set is never silently
1965 // wrong. setPinnedColumnBoundary() also re-syncs the pinned overlays
1966 // and duplicate header pair to match.
1967 if (pinned_column_boundary_ > 0) {
1968 setPinnedColumnBoundary(0);
1969 }
1970 columns_changed_ = false;
1971}
1972
1973// Fields have changed, update custom columns
1974void PacketList::fieldsChanged(capture_file *cf)
1975{
1976 // hfids used by custom columns or by the _ws.col fields may have changed,
1977 // so recreate the columns. We shouldn't need to if prefs.col_list is NULL,
1978 // since that doesn't register and deregister _ws.col fields.
1979 // If the column pref changes to or from NULL, that triggers columnsChanged
1980 // above, so we don't need to do it twice.
1981 //
1982 // XXX - If we knew exactly which fields changed, we could rebuild the
1983 // columns only if a field used by the columns changed.
1984 if (prefs.col_list) {
1985 prefs.num_cols = g_list_length(prefs.col_list);
1986 col_cleanup(&cf->cinfo);
1987 build_column_format_array(&cf->cinfo, prefs.num_cols, false);
1988 resetColumns();
1989 }
1990}
1991
1992// Column widths should
1993// - Load from recent when we load a new profile (including at starting up).
1994// - Reapply when changing columns.
1995// - Persist across freezes and thaws.
1996// - Persist across file closing and opening.
1997// - Save to recent when we save our profile (including shutting down).
1998// - Not be affected by the behavior of stretchLastSection. (XXX: We
1999// still save the stretched value to recent, sectionResized doesn't
2000// distinguish between a resize from being stretched and a manual change.)
2001void PacketList::applyRecentColumnWidths()
2002{
2003 // Either we've just started up or a profile has changed. Read
2004 // the recent settings, apply them, and save the header state.
2005
2006 for (unsigned col = 0; col < prefs.num_cols; col++) {
2007 // The column must be shown before setting column width.
2008 // Visibility will be updated in setColumnVisibility().
2009 setColumnHidden(col, false);
2010 setRecentColumnWidth(col);
2011 }
2012}
2013
2014void PacketList::preferencesChanged()
2015{
2016 // Previously driven by the separate MainApplication::colorsChanged
2017 // signal, which has been removed — every colorsChanged emit was
2018 // paired with a preferencesChanged emit anyway. Rebuilding the
2019 // selection stylesheet on every pref change is cheap (single
2020 // setStyleSheet call) and idempotent.
2021 colorsChanged();
2022
2023 // Intelligent scroll bar (minimap)
2024 if (prefs.gui_packet_list_show_minimap) {
2025 if (overlay_timer_id_ == 0) {
2026 overlay_timer_id_ = startTimer(overlay_update_interval_);
2027 }
2028 } else {
2029 if (overlay_timer_id_ != 0) {
2030 killTimer(overlay_timer_id_);
2031 overlay_timer_id_ = 0;
2032 }
2033 }
2034
2035 // Elide mode.
2036 // This sets the mode for the entire view. If we want to make this setting
2037 // per-column we'll either have to generalize RelatedPacketDelegate so that
2038 // we can set it for entire rows or create another delegate.
2039 Qt::TextElideMode elide_mode = Qt::ElideRight;
2040 switch (prefs.gui_packet_list_elide_mode) {
2041 case ELIDE_LEFT:
2042 elide_mode = Qt::ElideLeft;
2043 break;
2044 case ELIDE_MIDDLE:
2045 elide_mode = Qt::ElideMiddle;
2046 break;
2047 case ELIDE_NONE:
2048 elide_mode = Qt::ElideNone;
2049 break;
2050 default:
2051 break;
2052 }
2053 setTextElideMode(elide_mode);
2054}
2055
2056void PacketList::freezePacketList(bool changing_profile)
2057{
2058 changing_profile_ = changing_profile;
2059 freeze(true);
2060}
2061
2062void PacketList::recolorPackets()
2063{
2064 packet_list_model_->resetColorized();
2065 redrawVisiblePackets();
2066}
2067
2068// Enable autoscroll.
2069void PacketList::setVerticalAutoScroll(bool enabled)
2070{
2071 tail_at_end_ = enabled;
2072 if (enabled && capture_in_progress_) {
2073 scrollToBottom();
2074 }
2075}
2076
2077// Called when we finish reading, reloading, rescanning, and retapping
2078// packets.
2079void PacketList::captureFileReadFinished()
2080{
2081 packet_list_model_->flushVisibleRows();
2082 packet_list_model_->dissectIdle(true);
2083 // Invalidating the column strings picks up and request/response
2084 // tracking changes. We might just want to call it from flushVisibleRows.
2085 packet_list_model_->invalidateAllColumnStrings();
2086 // Sort *after* invalidating the column strings
2087 if (isSortingEnabled()) {
2088 sortByColumn(header()->sortIndicatorSection(), header()->sortIndicatorOrder());
2089 }
2090}
2091
2092bool PacketList::freeze(bool keep_current_frame)
2093{
2094 if (!cap_file_ || model() == Q_NULLPTRnullptr) {
2095 // No capture file or already frozen
2096 return false;
2097 }
2098
2099 frame_data *current_frame = cap_file_->current_frame;
2100 column_state_ = header()->saveState();
2101 setHeaderHidden(true);
2102 frozen_current_row_ = currentIndex();
2103 frozen_selected_rows_ = selectionModel()->selectedRows();
2104 selectionModel()->clear();
2105 setModel(Q_NULLPTRnullptr);
2106 // It looks like GTK+ sends a cursor-changed signal at this point but Qt doesn't
2107 // call selectionChanged.
2108 related_packet_delegate_.clear();
2109
2110 if (keep_current_frame) {
2111 cap_file_->current_frame = current_frame;
2112 }
2113
2114 /* Clears packet list as well as byteview */
2115 emit framesSelected(QList<int>());
2116
2117 return true;
2118}
2119
2120bool PacketList::thaw(bool restore_selection)
2121{
2122 if (!cap_file_ || model() != Q_NULLPTRnullptr) {
2123 // No capture file or not frozen
2124 return false;
2125 }
2126
2127 setHeaderHidden(false);
2128 // Note that if we have a current sort status set in the header,
2129 // this will automatically try to sort the model (we don't want
2130 // that to happen if we're in the middle of reading the file).
2131 setModel(packet_list_model_);
2132
2133 // setModel() always creates a brand-new default selection model, even
2134 // when passed the same model pointer, discarding the one we'd shared
2135 // with pinned_column_view_ back in the constructor. Re-share it so its
2136 // selection highlighting doesn't silently go stale. (The pinned-row
2137 // overlays use a separate proxy model -- PinnedRowsModel -- and so
2138 // never shared this selection model to begin with.)
2139 if (pinned_column_view_) {
2140 pinned_column_view_->setSelectionModel(selectionModel());
2141 }
2142
2143 if (changing_profile_) {
2144 // When changing profile the new recent settings must be applied to the columns.
2145 applyRecentColumnWidths();
2146 setColumnVisibility();
2147 changing_profile_ = false;
2148 } else {
2149 // Resetting the model resets our column widths so we restore them here.
2150 // We don't reapply the recent settings because the user could have
2151 // resized the columns manually since they were initially loaded.
2152 header()->restoreState(column_state_);
2153 }
2154
2155 if (restore_selection && frozen_selected_rows_.length() > 0 && selectionModel()) {
2156 /* This updates our selection, which redissects the current packet,
2157 * which is needed when we're called from MainWindow::layoutPanes.
2158 * Also, this resets all ProtoTree and ByteView data */
2159 clearSelection();
2160 setCurrentIndex(frozen_current_row_);
2161 foreach (QModelIndex idx, frozen_selected_rows_)for (auto _container_2161 = QtPrivate::qMakeForeachContainer(
frozen_selected_rows_); _container_2161.i != _container_2161.
e; ++_container_2161.i) if (QModelIndex idx = *_container_2161
.i; false) {} else
{
2162 selectionModel()->select(idx, QItemSelectionModel::Select | QItemSelectionModel::Rows);
2163 }
2164 scrollTo(currentIndex(), PositionAtCenter);
2165 }
2166 frozen_current_row_ = QModelIndex();
2167 frozen_selected_rows_ = QModelIndexList();
2168
2169 return true;
2170}
2171
2172void PacketList::clear() {
2173 // Cleared before packet_list_model_ below: that call emits modelReset,
2174 // which updatePinnedRowVisibility() (connected to it) reacts to by
2175 // calling pinned_rows_model_->refresh() -- resolving pinned frame
2176 // numbers against packet_list_model_ while it's already been cleared,
2177 // if pinned_rows_model_ itself hadn't been cleared first. Every
2178 // consumer of that resolution currently null-checks defensively, so
2179 // this ordering wasn't otherwise observably wrong, but doing the
2180 // pinned-state clear first removes the transient window entirely
2181 // rather than relying on those checks to mask it.
2182 pinned_rows_model_->clear();
2183 setPinnedColumnBoundary(0);
2184
2185 related_packet_delegate_.clear();
2186 selectionModel()->clear();
2187 packet_list_model_->clear();
2188 proto_tree_->clear();
2189 selection_history_.clear();
2190 cur_history_ = -1;
2191 in_history_ = false;
2192
2193 QImage overlay;
2194 overlay_sb_->setNearOverlayImage(overlay);
2195 overlay_sb_->setMarkedPacketImage(overlay);
2196 create_near_overlay_ = true;
2197 create_far_overlay_ = true;
2198
2199 updatePinnedRowVisibility();
2200}
2201
2202void PacketList::writeRecent(FILE *rf) {
2203 int width, col_fmt;
2204 char xalign;
2205
2206 fprintf (rf, "%s:\n", RECENT_KEY_COL_WIDTH"column.width");
2207 for (unsigned col = 0; col < prefs.num_cols; col++) {
2208 if (col > 0) {
2209 fprintf (rf, ",\n");
2210 }
2211 col_fmt = get_column_format(col);
2212 if (col_fmt == COL_CUSTOM) {
2213 fprintf (rf, " \"%%Cus:%s\",", get_column_custom_fields(col));
2214 } else {
2215 fprintf (rf, " %s,", col_format_to_string(col_fmt));
2216 }
2217 width = recent_get_column_width (col);
2218 xalign = recent_get_column_xalign (col);
2219 fprintf (rf, " %d", width);
2220 if (xalign != COLUMN_XALIGN_DEFAULT0) {
2221 fprintf (rf, ":%c", xalign);
2222 }
2223 }
2224 fprintf (rf, "\n");
2225}
2226
2227bool PacketList::contextMenuActive()
2228{
2229 return ctx_column_ >= 0 ? true : false;
2230}
2231
2232QString PacketList::getFilterFromRowAndColumn(QModelIndex idx)
2233{
2234 frame_data *fdata;
2235 QString filter;
2236
2237 if (! idx.isValid())
2238 return filter;
2239
2240 int row = idx.row();
2241 int column = idx.column();
2242
2243 if (!cap_file_ || !packet_list_model_ || column < 0 || (unsigned)column >= cap_file_->cinfo.num_cols)
2244 return filter;
2245
2246 fdata = packet_list_model_->getRowFdata(row);
2247
2248 if (fdata != NULL__null) {
2249 epan_dissect_t edt;
2250 wtap_rec rec; /* Record information */
2251
2252 wtap_rec_init(&rec, DEFAULT_INIT_BUFFER_SIZE_2048(2 * 1024));
2253 if (!cf_read_record(cap_file_, fdata, &rec)) {
2254 wtap_rec_cleanup(&rec);
2255 return filter; /* error reading the record */
2256 }
2257 /* proto tree, visible. We need a proto tree if there's custom columns */
2258 epan_dissect_init(&edt, cap_file_->epan, have_custom_cols(&cap_file_->cinfo), false);
2259 col_custom_prime_edt(&edt, &cap_file_->cinfo);
2260
2261 epan_dissect_run(&edt, cap_file_->cd_t, &rec, fdata, &cap_file_->cinfo);
2262
2263 if (cap_file_->cinfo.columns[column].col_fmt == COL_CUSTOM) {
2264 filter.append(gchar_free_to_qstring(col_custom_get_filter(&edt, &cap_file_->cinfo, (unsigned)column)));
2265 } else {
2266 /* We don't need to fill in the custom columns, as we get their
2267 * filters above.
2268 */
2269 col_fill_in(&edt.pi, true, true);
2270 if (strlen(cap_file_->cinfo.col_expr.col_expr[column]) != 0 &&
2271 strlen(cap_file_->cinfo.col_expr.col_expr_val[column]) != 0) {
2272 bool is_string_value = false;
2273 header_field_info *hfi = proto_registrar_get_byname(cap_file_->cinfo.col_expr.col_expr[column]);
2274 if (hfi && FT_IS_STRING(hfi->type)((hfi->type) == FT_STRING || (hfi->type) == FT_STRINGZ ||
(hfi->type) == FT_STRINGZPAD || (hfi->type) == FT_STRINGZTRUNC
|| (hfi->type) == FT_UINT_STRING || (hfi->type) == FT_AX25
)
) {
2275 /* Could be an address type such as usb.src which must be quoted. */
2276 is_string_value = true;
2277 }
2278
2279 if (filter.isEmpty()) {
2280 if (is_string_value) {
2281 filter.append(QStringLiteral("%1 == \"%2\"")(QString(QtPrivate::qMakeStringPrivate(u"" "%1 == \"%2\"")))
2282 .arg(cap_file_->cinfo.col_expr.col_expr[column])
2283 .arg(cap_file_->cinfo.col_expr.col_expr_val[column]));
2284 } else {
2285 filter.append(QStringLiteral("%1 == %2")(QString(QtPrivate::qMakeStringPrivate(u"" "%1 == %2")))
2286 .arg(cap_file_->cinfo.col_expr.col_expr[column])
2287 .arg(cap_file_->cinfo.col_expr.col_expr_val[column]));
2288 }
2289 }
2290 }
2291 }
2292
2293 epan_dissect_cleanup(&edt);
2294 wtap_rec_cleanup(&rec);
2295 }
2296
2297 return filter;
2298}
2299
2300void PacketList::resetColorized()
2301{
2302 packet_list_model_->resetColorized();
2303 update();
2304}
2305
2306QString PacketList::getPacketComment(unsigned c_number)
2307{
2308 int row = currentIndex().row();
2309 const frame_data *fdata;
2310 char *pkt_comment;
2311 wtap_opttype_return_val result;
2312 QString ret_val = NULL__null;
2313
2314 if (!cap_file_ || !packet_list_model_) return NULL__null;
2315
2316 fdata = packet_list_model_->getRowFdata(row);
2317
2318 if (!fdata) return NULL__null;
2319
2320 wtap_block_t pkt_block = cf_get_packet_block(cap_file_, fdata);
2321 result = wtap_block_get_nth_string_option_value(pkt_block, OPT_COMMENT1, c_number, &pkt_comment);
2322 if (result == WTAP_OPTTYPE_SUCCESS) {
2323 ret_val = QString(pkt_comment);
2324 }
2325 wtap_block_unref(pkt_block);
2326 return ret_val;
2327}
2328
2329void PacketList::addPacketComment(QString new_comment)
2330{
2331 if (!cap_file_ || !packet_list_model_) return;
2332 if (new_comment.isEmpty()) return;
2333
2334 QByteArray ba = new_comment.toUtf8();
2335
2336 /*
2337 * Make sure this would fit in a pcapng option.
2338 *
2339 * XXX - 65535 is the maximum size for an option in pcapng;
2340 * what if another capture file format supports larger
2341 * comments?
2342 */
2343 if (ba.size() > 65535) {
2344 simple_dialog(ESD_TYPE_ERROR, ESD_BTN_OK0x01,
2345 "That comment is too large to save in a capture file.");
2346 return;
2347 }
2348
2349 if (selectionModel() && selectionModel()->hasSelection()) {
2350 packet_list_model_->addFrameComment(selectionModel()->selectedRows(), ba);
2351 drawCurrentPacket();
2352 }
2353}
2354
2355void PacketList::setPacketComment(unsigned c_number, QString new_comment)
2356{
2357 QModelIndex curIndex = currentIndex();
2358
2359 if (!cap_file_ || !packet_list_model_) return;
2360
2361 QByteArray ba = new_comment.toUtf8();
2362 /*
2363 * Make sure this would fit in a pcapng option.
2364 *
2365 * XXX - 65535 is the maximum size for an option in pcapng;
2366 * what if another capture file format supports larger
2367 * comments?
2368 */
2369 if (ba.size() > 65535) {
2370 simple_dialog(ESD_TYPE_ERROR, ESD_BTN_OK0x01,
2371 "That comment is too large to save in a capture file.");
2372 return;
2373 }
2374
2375 packet_list_model_->setFrameComment(curIndex, ba, c_number);
2376 drawCurrentPacket();
2377}
2378
2379QString PacketList::allPacketComments()
2380{
2381 uint32_t framenum;
2382 frame_data *fdata;
2383 QString buf_str;
2384
2385 if (!cap_file_) return buf_str;
2386
2387 for (framenum = 1; framenum <= cap_file_->count ; framenum++) {
2388 fdata = frame_data_sequence_find(cap_file_->provider.frames, framenum);
2389
2390 wtap_block_t pkt_block = cf_get_packet_block(cap_file_, fdata);
2391
2392 if (pkt_block) {
2393 unsigned n_comments = wtap_block_count_option(pkt_block, OPT_COMMENT1);
2394 for (unsigned i = 0; i < n_comments; i++) {
2395 char *comment_text;
2396 if (WTAP_OPTTYPE_SUCCESS == wtap_block_get_nth_string_option_value(pkt_block, OPT_COMMENT1, i, &comment_text)) {
2397 buf_str.append(tr("Frame %1: %2\n\n").arg(framenum).arg(comment_text));
2398 if (buf_str.length() > max_comments_to_fetch_) {
2399 buf_str.append(tr("[ Comment text exceeds %1. Stopping. ]")
2400 .arg(format_size(max_comments_to_fetch_, FORMAT_SIZE_UNIT_BYTES, FORMAT_SIZE_PREFIX_SI)format_size_wmem(__null, max_comments_to_fetch_, FORMAT_SIZE_UNIT_BYTES
, (1 << 0))
));
2401 return buf_str;
2402 }
2403 }
2404 }
2405 }
2406 }
2407 return buf_str;
2408}
2409
2410void PacketList::deleteCommentsFromPackets()
2411{
2412 if (!cap_file_ || !packet_list_model_) return;
2413
2414 if (selectionModel() && selectionModel()->hasSelection()) {
2415 packet_list_model_->deleteFrameComments(selectionModel()->selectedRows());
2416 drawCurrentPacket();
2417 }
2418}
2419
2420void PacketList::deleteAllPacketComments()
2421{
2422 if (!cap_file_ || !packet_list_model_) return;
2423
2424 packet_list_model_->deleteAllFrameComments();
2425 drawCurrentPacket();
2426}
2427
2428
2429// Slots
2430
2431void PacketList::setCaptureFile(capture_file *cf)
2432{
2433 cap_file_ = cf;
2434 packet_list_model_->setCaptureFile(cf);
2435 if (cap_file_ && columns_changed_) {
2436 columnsChanged();
2437 }
2438 create_near_overlay_ = true;
2439 changing_profile_ = false;
2440 sortByColumn(-1, Qt::AscendingOrder);
2441}
2442
2443void PacketList::setMonospaceFont(const QFont &mono_font)
2444{
2445 setFont(mono_font);
2446 for (QTreeView *view : pinnedOverlayViews()) {
2447 view->setFont(mono_font);
2448 }
2449 layoutPinnedOverlays();
2450}
2451
2452void PacketList::setRegularFont(const QFont &regular_font)
2453{
2454 header()->setFont(regular_font);
2455 header()->viewport()->setFont(regular_font);
2456 // pinned_column_view_'s own header isn't covered by setMonospaceFont()
2457 // looping over pinnedOverlayViews() (that sets the *view's* font, for
2458 // cell content -- QHeaderView doesn't automatically inherit a
2459 // different font set on its own separately-headed QTreeView the way
2460 // the primary view's header is explicitly given the regular font
2461 // above), so without this it silently kept whatever font QHeaderView
2462 // fell back to, differing from the primary header's.
2463 if (pinned_column_view_) {
2464 pinned_column_view_->header()->setFont(regular_font);
2465 }
2466}
2467
2468void PacketList::goNextPacket(void)
2469{
2470 if (QApplication::keyboardModifiers() & Qt::AltModifier) {
2471 // Alt+toolbar
2472 goNextHistoryPacket();
2473 return;
2474 }
2475
2476 if (selectionModel()->hasSelection()) {
2477 selectionModel()->setCurrentIndex(moveCursor(MoveDown, Qt::NoModifier), QItemSelectionModel::ClearAndSelect | QItemSelectionModel::Rows);
2478 } else {
2479 // First visible packet.
2480 selectionModel()->setCurrentIndex(indexAt(viewport()->rect().topLeft()), QItemSelectionModel::ClearAndSelect | QItemSelectionModel::Rows);
2481 }
2482
2483 scrollViewChanged(false);
2484}
2485
2486void PacketList::goPreviousPacket(void)
2487{
2488 if (QApplication::keyboardModifiers() & Qt::AltModifier) {
2489 // Alt+toolbar
2490 goPreviousHistoryPacket();
2491 return;
2492 }
2493
2494 if (selectionModel()->hasSelection()) {
2495 selectionModel()->setCurrentIndex(moveCursor(MoveUp, Qt::NoModifier), QItemSelectionModel::ClearAndSelect | QItemSelectionModel::Rows);
2496 } else {
2497 // Last visible packet.
2498 QModelIndex last_idx = indexAt(viewport()->rect().bottomLeft());
2499 if (last_idx.isValid()) {
2500 selectionModel()->setCurrentIndex(last_idx, QItemSelectionModel::ClearAndSelect | QItemSelectionModel::Rows);
2501 } else {
2502 goLastPacket();
2503 }
2504 }
2505
2506 scrollViewChanged(false);
2507}
2508
2509void PacketList::goFirstPacket(void) {
2510 if (packet_list_model_->rowCount() < 1) return;
2511 selectionModel()->setCurrentIndex(packet_list_model_->index(0, 0), QItemSelectionModel::ClearAndSelect | QItemSelectionModel::Rows);
2512 scrollTo(currentIndex());
2513
2514 scrollViewChanged(false);
2515}
2516
2517void PacketList::goLastPacket(void) {
2518 if (packet_list_model_->rowCount() < 1) return;
2519 selectionModel()->setCurrentIndex(packet_list_model_->index(packet_list_model_->rowCount() - 1, 0), QItemSelectionModel::ClearAndSelect | QItemSelectionModel::Rows);
2520 scrollTo(currentIndex());
2521
2522 scrollViewChanged(false);
2523}
2524
2525void PacketList::goToPacket(int packet, int hf_id)
2526{
2527 if (!cf_goto_frame(cap_file_, packet, false))
2528 return;
2529
2530 // cf_goto_frame only returns true if packet_list_select_row_from_data
2531 // succeeds, the latter has already selected and scrolled to the frame.
2532 if (hf_id > 0) {
2533 proto_tree_->goToHfid(hf_id);
2534 }
2535
2536 scrollViewChanged(false);
2537}
2538
2539void PacketList::goNextHistoryPacket()
2540{
2541 if (haveNextHistory(true)) {
2542 in_history_ = true;
2543 goToPacket(selection_history_.at(cur_history_));
2544 in_history_ = false;
2545 }
2546}
2547
2548void PacketList::goPreviousHistoryPacket()
2549{
2550 if (havePreviousHistory(true)) {
2551 in_history_ = true;
2552 goToPacket(selection_history_.at(cur_history_));
2553 in_history_ = false;
2554 }
2555}
2556
2557void PacketList::markFrame()
2558{
2559 if (!cap_file_ || !packet_list_model_) return;
2560
2561 QModelIndexList frames;
2562
2563 if (selectionModel() && selectionModel()->hasSelection())
2564 {
2565 QModelIndexList selRows = selectionModel()->selectedRows(0);
2566 foreach (QModelIndex idx, selRows)for (auto _container_2566 = QtPrivate::qMakeForeachContainer(
selRows); _container_2566.i != _container_2566.e; ++_container_2566
.i) if (QModelIndex idx = *_container_2566.i; false) {} else
2567 {
2568 if (idx.isValid())
2569 {
2570 frames << idx;
2571 }
2572 }
2573 }
2574 else
2575 frames << currentIndex();
2576
2577 packet_list_model_->toggleFrameMark(frames);
2578
2579 // Make sure the packet list's frame.marked related field text is updated.
2580 redrawVisiblePackets();
2581
2582 create_far_overlay_ = true;
2583 packets_bar_update();
2584}
2585
2586void PacketList::markAllDisplayedFrames(bool set)
2587{
2588 if (!cap_file_ || !packet_list_model_) return;
2589
2590 packet_list_model_->setDisplayedFrameMark(set);
2591
2592 // Make sure the packet list's frame.marked related field text is updated.
2593 redrawVisiblePackets();
2594
2595 create_far_overlay_ = true;
2596 packets_bar_update();
2597}
2598
2599void PacketList::ignoreFrame()
2600{
2601 if (!cap_file_ || !packet_list_model_) return;
2602
2603 QModelIndexList frames;
2604
2605 if (selectionModel() && selectionModel()->hasSelection())
2606 {
2607 foreach (QModelIndex idx, selectionModel()->selectedRows(0))for (auto _container_2607 = QtPrivate::qMakeForeachContainer(
selectionModel()->selectedRows(0)); _container_2607.i != _container_2607
.e; ++_container_2607.i) if (QModelIndex idx = *_container_2607
.i; false) {} else
2608 {
2609 if (idx.isValid())
2610 {
2611 frames << idx;
2612 }
2613 }
2614 }
2615 else
2616 frames << currentIndex();
2617
2618
2619 packet_list_model_->toggleFrameIgnore(frames);
2620 create_far_overlay_ = true;
2621 int sb_val = verticalScrollBar()->value(); // Surely there's a better way to keep our position?
2622 setUpdatesEnabled(false);
2623 emit packetDissectionChanged();
2624 setUpdatesEnabled(true);
2625 verticalScrollBar()->setValue(sb_val);
2626}
2627
2628void PacketList::ignoreAllDisplayedFrames(bool set)
2629{
2630 if (!cap_file_ || !packet_list_model_) return;
2631
2632 packet_list_model_->setDisplayedFrameIgnore(set);
2633 create_far_overlay_ = true;
2634 emit packetDissectionChanged();
2635}
2636
2637void PacketList::setTimeReference()
2638{
2639 if (!cap_file_ || !packet_list_model_) return;
2640
2641 QModelIndexList frames;
2642
2643 if (selectionModel() && selectionModel()->hasSelection())
2644 {
2645 foreach (QModelIndex idx, selectionModel()->selectedRows(0))for (auto _container_2645 = QtPrivate::qMakeForeachContainer(
selectionModel()->selectedRows(0)); _container_2645.i != _container_2645
.e; ++_container_2645.i) if (QModelIndex idx = *_container_2645
.i; false) {} else
2646 {
2647 if (idx.isValid())
2648 {
2649 frames << idx;
2650 }
2651 }
2652 }
2653 else
2654 frames << currentIndex();
2655
2656 packet_list_model_->toggleFrameRefTime(frames);
2657 create_far_overlay_ = true;
2658}
2659
2660void PacketList::unsetAllTimeReferences()
2661{
2662 if (!cap_file_ || !packet_list_model_) return;
2663 packet_list_model_->unsetAllFrameRefTime();
2664 create_far_overlay_ = true;
2665}
2666
2667void PacketList::applyTimeShift()
2668{
2669 packet_list_model_->resetColumns();
2670 redrawVisiblePackets();
2671 emit packetDissectionChanged();
2672}
2673
2674void PacketList::updatePackets(bool redraw)
2675{
2676 if (redraw) {
2677 packet_list_model_->resetColumns();
2678 redrawVisiblePackets();
2679 } else {
2680 update();
2681 }
2682}
2683
2684void PacketList::columnVisibilityTriggered()
2685{
2686 QAction *ha = qobject_cast<QAction*>(sender());
2687 if (!ha) return;
2688
2689 int col = ha->data().toInt();
2690 set_column_visible(col, ha->isChecked());
2691 setColumnVisibility();
2692 if (ha->isChecked()) {
2693 setRecentColumnWidth(col);
2694 }
2695 prefs_main_write();
2696}
2697
2698void PacketList::sectionResized(int col, int, int new_width)
2699{
2700 if (isVisible() && !columns_changed_ && !set_column_visibility_ && !set_style_sheet_ && new_width > 0) {
2701 // Column 1 gets an invalid value (32 on macOS) when we're not yet
2702 // visible.
2703 //
2704 // Don't set column width when columns changed or setting column
2705 // visibility because we may get a sectionResized() from QTreeView
2706 // with values from a old columns layout.
2707 //
2708 // Don't set column width when hiding a column.
2709
2710 recent_set_column_width(col, new_width);
2711 }
2712
2713 mirrorSectionWidthToOverlays(col, new_width);
2714 layoutPinnedOverlays();
2715}
2716
2717// The user moved a column. Make sure prefs.col_list, the column format
2718// array, and the header's visual and logical indices all agree.
2719// gtk/packet_list.c:column_dnd_changed_cb
2720void PacketList::sectionMoved(int logicalIndex, int oldVisualIndex, int newVisualIndex)
2721{
2722 GList *new_col_list = NULL__null;
2723 GList *new_recent_col_list = NULL__null;
2724 QList<int> saved_sizes;
2725 int sort_idx;
2726
2727 // Since we undo the move below, these should always stay in sync.
2728 // Otherwise the order of columns can be unexpected after drag and drop.
2729 if (logicalIndex != oldVisualIndex) {
2730 ws_warning("Column moved from an unexpected state (%d, %d, %d)",do { if (true) { ws_log_full("", LOG_LEVEL_WARNING, "ui/qt/packet_list.cpp"
, 2731, __func__, "Column moved from an unexpected state (%d, %d, %d)"
, logicalIndex, oldVisualIndex, newVisualIndex); } } while (0
)
2731 logicalIndex, oldVisualIndex, newVisualIndex)do { if (true) { ws_log_full("", LOG_LEVEL_WARNING, "ui/qt/packet_list.cpp"
, 2731, __func__, "Column moved from an unexpected state (%d, %d, %d)"
, logicalIndex, oldVisualIndex, newVisualIndex); } } while (0
)
;
2732 }
2733
2734 // Remember which column should be sorted. Use the visual index since this
2735 // points to the current GUI state rather than the outdated column order
2736 // (indicated by the logical index).
2737 sort_idx = header()->sortIndicatorSection();
2738 if (sort_idx != -1) {
2739 sort_idx = header()->visualIndex(sort_idx);
2740 }
2741
2742 // Build a new column list based on the header's logical order.
2743 for (int vis_idx = 0; vis_idx < header()->count(); vis_idx++) {
2744 int log_idx = header()->logicalIndex(vis_idx);
2745 saved_sizes << header()->sectionSize(log_idx);
2746
2747 void *pref_data = g_list_nth_data(prefs.col_list, log_idx);
2748 if (pref_data) {
2749 new_col_list = g_list_append(new_col_list, pref_data);
2750 }
2751
2752 pref_data = g_list_nth_data(recent.col_width_list, log_idx);
2753 if (pref_data) {
2754 new_recent_col_list = g_list_append(new_recent_col_list, pref_data);
2755 }
2756 }
2757
2758 // Undo move to ensure that the logical indices map to the visual indices,
2759 // otherwise the column order is changed twice (once via the modified
2760 // col_list, once because of the visual/logical index mismatch).
2761 disconnect(header(), &QHeaderView::sectionMoved, this, &PacketList::sectionMoved);
2762 header()->moveSection(newVisualIndex, oldVisualIndex);
2763 connect(header(), &QHeaderView::sectionMoved, this, &PacketList::sectionMoved);
2764
2765 // Clear and rebuild our (and the header's) model. There doesn't appear
2766 // to be another way to reset the logical index.
2767 freeze();
2768
2769 g_list_free(prefs.col_list);
2770 prefs.col_list = new_col_list;
2771 g_list_free(recent.col_width_list);
2772 recent.col_width_list = new_recent_col_list;
2773
2774 thaw(true);
2775
2776 for (int i = 0; i < saved_sizes.length(); i++) {
2777 if (saved_sizes[i] < 1) continue;
2778 header()->resizeSection(i, saved_sizes[i]);
2779 }
2780
2781 prefs_main_write();
2782
2783 mainApp->emitAppSignal(MainApplication::ColumnsChanged);
2784
2785 // If the column with the sort indicator got shifted, mark the new column
2786 // after updating the columns contents (via ColumnsChanged) to ensure that
2787 // the columns are sorted using the intended column contents.
2788 int left_col = MIN(oldVisualIndex, newVisualIndex)(((oldVisualIndex) < (newVisualIndex)) ? (oldVisualIndex) :
(newVisualIndex))
;
2789 int right_col = MAX(oldVisualIndex, newVisualIndex)(((oldVisualIndex) > (newVisualIndex)) ? (oldVisualIndex) :
(newVisualIndex))
;
2790 if (left_col <= sort_idx && sort_idx <= right_col) {
2791 header()->setSortIndicator(sort_idx, header()->sortIndicatorOrder());
2792 }
2793
2794 layoutPinnedOverlays();
2795}
2796
2797void PacketList::pinSelectedRows()
2798{
2799 if (!pinned_rows_model_ || !packet_list_model_) return;
2800
2801 QModelIndexList frames;
2802 if (selectionModel() && selectionModel()->hasSelection()) {
2803 foreach (QModelIndex idx, selectionModel()->selectedRows(0))for (auto _container_2803 = QtPrivate::qMakeForeachContainer(
selectionModel()->selectedRows(0)); _container_2803.i != _container_2803
.e; ++_container_2803.i) if (QModelIndex idx = *_container_2803
.i; false) {} else
{
2804 if (idx.isValid()) frames << idx;
2805 }
2806 } else {
2807 frames << currentIndex();
2808 }
2809
2810 foreach (QModelIndex idx, frames)for (auto _container_2810 = QtPrivate::qMakeForeachContainer(
frames); _container_2810.i != _container_2810.e; ++_container_2810
.i) if (QModelIndex idx = *_container_2810.i; false) {} else
{
2811 frame_data *fdata = packet_list_model_->getRowFdata(idx.row());
2812 if (fdata) {
2813 pinned_rows_model_->pinFrame((int)fdata->num);
2814 }
2815 }
2816 updatePinnedRowVisibility();
2817}
2818
2819void PacketList::unpinSelectedRows()
2820{
2821 if (!pinned_rows_model_ || !packet_list_model_) return;
2822
2823 QModelIndexList frames;
2824 if (selectionModel() && selectionModel()->hasSelection()) {
2825 foreach (QModelIndex idx, selectionModel()->selectedRows(0))for (auto _container_2825 = QtPrivate::qMakeForeachContainer(
selectionModel()->selectedRows(0)); _container_2825.i != _container_2825
.e; ++_container_2825.i) if (QModelIndex idx = *_container_2825
.i; false) {} else
{
2826 if (idx.isValid()) frames << idx;
2827 }
2828 } else {
2829 frames << currentIndex();
2830 }
2831
2832 foreach (QModelIndex idx, frames)for (auto _container_2832 = QtPrivate::qMakeForeachContainer(
frames); _container_2832.i != _container_2832.e; ++_container_2832
.i) if (QModelIndex idx = *_container_2832.i; false) {} else
{
2833 frame_data *fdata = packet_list_model_->getRowFdata(idx.row());
2834 if (fdata) {
2835 pinned_rows_model_->unpinFrame((int)fdata->num);
2836 }
2837 }
2838 updatePinnedRowVisibility();
2839}
2840
2841void PacketList::unpinAllRows()
2842{
2843 pinned_rows_model_->clear();
2844 updatePinnedRowVisibility();
2845}
2846
2847int PacketList::pinnedRowHeight() const
2848{
2849 int row_height = sizeHintForRow(0);
2850 if (row_height > 0) {
2851 return row_height;
2852 }
2853 // No rows laid out yet (e.g. empty capture); fall back to font-based
2854 // spacing so the strip still sizes sensibly rather than to 0.
2855 return fontMetrics().height() + 2;
2856}
2857
2858void PacketList::setPinnedColumnBoundary(int column_count)
2859{
2860 pinned_column_boundary_ = column_count;
2861 emit pinnedColumnBoundaryChanged(pinned_column_boundary_);
2862
2863 // Seed widths for the newly-pinned range; afterward sectionResized()
2864 // keeps these in sync as the user resizes columns.
2865 for (int i = 0; i < pinned_column_boundary_; i++) {
2866 int width = header()->sectionSize(i);
2867 if (pinned_column_view_) {
2868 pinned_column_view_->mirrorSectionWidth(i, width);
2869 }
2870 if (pinned_row_corner_view_) {
2871 pinned_row_corner_view_->mirrorSectionWidth(i, width);
2872 }
2873 }
2874
2875 if (pinned_column_view_) {
2876 pinned_column_view_->setFrozenColumnCount(pinned_column_boundary_);
2877 }
2878 if (packet_list_header_) {
2879 packet_list_header_->setFrozenColumnCount(pinned_column_boundary_);
2880 }
2881
2882 updatePinnedRowVisibility();
2883 layoutPinnedOverlays();
2884}
2885
2886void PacketList::updatePinnedRowVisibility()
2887{
2888 pinned_rows_model_->refresh();
2889
2890 bool have_pinned_rows = pinned_rows_model_->pinnedCount() > 0;
2891
2892 for (unsigned i = 0; i < prefs.num_cols; i++) {
2893 int width = header()->sectionSize(i);
2894 if (pinned_row_view_) {
2895 pinned_row_view_->mirrorSectionWidth(i, width);
2896 }
2897 if (pinned_row_corner_view_) {
2898 pinned_row_corner_view_->mirrorSectionWidth(i, width);
2899 }
2900 }
2901
2902 if (pinned_row_view_) {
2903 pinned_row_view_->setColumnRange(pinned_column_boundary_, -1);
2904 pinned_row_view_->setVisible(have_pinned_rows);
2905 pinned_row_view_->updateGeometry();
2906 }
2907 if (pinned_row_corner_view_) {
2908 bool show_corner = have_pinned_rows && pinned_column_boundary_ > 0;
2909 if (show_corner) {
2910 pinned_row_corner_view_->setColumnRange(0, pinned_column_boundary_ - 1);
2911 }
2912 pinned_row_corner_view_->setVisible(show_corner);
2913 pinned_row_corner_view_->updateGeometry();
2914 }
2915
2916 layoutPinnedOverlays();
2917}
2918
2919void PacketList::layoutPinnedOverlays()
2920{
2921 // Width of the frozen-column portion, shared between the column-freeze
2922 // overlay below and the pinned-row strip's "corner" widget (whose
2923 // sizing PacketListPane keeps in sync via pinnedRowsCornerWidthChanged()).
2924 int corner_width = 0;
2925 for (int i = 0; i < pinned_column_boundary_; i++) {
2926 corner_width += header()->sectionSize(i);
2927 }
2928 bool have_pinned_rows = pinned_rows_model_ && pinned_rows_model_->pinnedCount() > 0;
2929 emit pinnedRowsCornerWidthChanged(corner_width, have_pinned_rows);
2930
2931 if (!pinned_column_view_) {
2932 return;
2933 }
2934
2935 // Derive the real on-screen offsets from the primary view's own child
2936 // widgets rather than assuming (0, 0): QTreeView's default frame
2937 // border/margin means header()/viewport() do not actually start flush
2938 // with PacketList's own top-left corner.
2939 int left_offset = header()->pos().x();
2940 int top_offset = header()->pos().y();
2941 int header_height = header()->height();
2942
2943 if (pinned_column_boundary_ > 0) {
2944 pinned_column_view_->mirrorHeaderHeight(header_height);
2945 // Span from the header's own top offset (not the viewport's) so
2946 // this view's own header covers the primary header's frozen-column
2947 // titles, which would otherwise scroll horizontally with the rest
2948 // of the header.
2949 QSize new_size(corner_width, header_height + viewport()->height());
2950 pinned_column_view_->setGeometry(left_offset, top_offset,
2951 new_size.width(), new_size.height());
2952 pinned_column_view_->setVisible(true);
2953 pinned_column_view_->raise();
2954 // refreshLayout() forces a full row-geometry recompute
2955 // (doItemsLayout()), which must run after setGeometry() since
2956 // QTreeView computes its vertical scroll range from the current
2957 // viewport size -- but only the height actually affects that
2958 // range, so skip the recompute when only corner_width (the
2959 // column-resize-driven part of new_size) changed. Without this,
2960 // dragging a column resize handle while frozen columns are active
2961 // re-runs a full O(rows) layout on every mouse-move tick.
2962 if (new_size.height() != pinned_column_view_size_.height()) {
2963 pinned_column_view_->refreshLayout();
2964 }
2965 pinned_column_view_size_ = new_size;
2966 pinned_column_view_->setVerticalScrollValue(verticalScrollBar()->value());
2967 } else {
2968 pinned_column_view_->setVisible(false);
2969 }
2970}
2971
2972QString PacketList::createSummaryText(QModelIndex idx, SummaryCopyType type)
2973{
2974 if (! idx.isValid())
2975 return "";
2976
2977 QStringList col_parts;
2978 int row = idx.row();
2979 for (int col = 0; col < packet_list_model_->columnCount(); col++) {
2980 if (get_column_visible(col)) {
2981 col_parts << packet_list_model_->data(packet_list_model_->index(row, col), Qt::DisplayRole).toString();
2982 }
2983 }
2984 return joinSummaryRow(col_parts, row, type);
2985}
2986
2987QString PacketList::createHeaderSummaryText(SummaryCopyType type)
2988{
2989 QStringList col_parts;
2990 for (int col = 0; col < packet_list_model_->columnCount(); ++col) {
2991 if (get_column_visible(col)) {
2992 col_parts << packet_list_model_->headerData(col, Qt::Orientation::Horizontal, Qt::DisplayRole).toString();
2993 }
2994 }
2995 return joinSummaryRow(col_parts, 0, type);
2996}
2997
2998QStringList PacketList::createHeaderPartsForAligned()
2999{
3000 QStringList hdr_parts;
3001 for (int col = 0; col < packet_list_model_->columnCount(); ++col) {
3002 if (get_column_visible(col)) {
3003 hdr_parts << packet_list_model_->headerData(col, Qt::Orientation::Horizontal, Qt::DisplayRole).toString();
3004 }
3005 }
3006 return hdr_parts;
3007}
3008
3009QList<int> PacketList::createAlignmentPartsForAligned()
3010{
3011 QList<int> align_parts;
3012 for (int col = 0; col < packet_list_model_->columnCount(); col++) {
3013 if (get_column_visible(col)) {
3014 align_parts << packet_list_model_->data(packet_list_model_->index(0, col), Qt::TextAlignmentRole).toInt();
3015 }
3016 }
3017 return align_parts;
3018}
3019
3020QList<int> PacketList::createSizePartsForAligned(bool useHeader, QStringList hdr_parts, QList<int> rows)
3021{
3022 QList<int> size_parts;
3023
3024 for (int i = 0; i < hdr_parts.size(); ++i) {
3025 if (useHeader)
3026 size_parts << static_cast<int>(hdr_parts.at(i).size());
3027 else
3028 size_parts << 0;
3029 }
3030
3031 foreach(int row, rows)for (auto _container_3031 = QtPrivate::qMakeForeachContainer(
rows); _container_3031.i != _container_3031.e; ++_container_3031
.i) if (int row = *_container_3031.i; false) {} else
3032 {
3033 QModelIndex idx = model()->index(row, 0);
3034 if (! idx.isValid())
3035 continue;
3036
3037 QStringList col_parts;
3038 for (int col = 0; col < packet_list_model_->columnCount(); col++) {
3039 if (get_column_visible(col)) {
3040 col_parts << (packet_list_model_->data(packet_list_model_->index(row, col), Qt::DisplayRole).toString());
3041 }
3042 }
3043
3044 for (int i = 0; i < col_parts.size(); ++i) {
3045 if (col_parts.at(i).size() > size_parts.at(i)) {
3046 size_parts[i] = static_cast<int>(col_parts.at(i).size());
3047 }
3048 }
3049 col_parts.clear();
3050 }
3051
3052 return size_parts;
3053}
3054
3055QString PacketList::createHeaderSummaryForAligned(QStringList hdr_parts, QList<int> align_parts, QList<int> size_parts)
3056{
3057 QString hdr_text;
3058 for (int i = 0; i < hdr_parts.size(); ++i) {
3059 if (align_parts.at(i) == Qt::AlignLeft) {
3060 hdr_text += hdr_parts[i].leftJustified(size_parts.at(i), ' ') + " ";
3061 }
3062 else if (align_parts.at(i) == Qt::AlignRight) {
3063 hdr_text += hdr_parts[i].rightJustified(size_parts.at(i), ' ') + " ";
3064 }
3065 }
3066 return QStringLiteral("-%1")(QString(QtPrivate::qMakeStringPrivate(u"" "-%1"))).arg(hdr_text).trimmed().mid(1);
3067}
3068
3069QString PacketList::createSummaryForAligned(QModelIndex idx, QList<int> align_parts, QList<int> size_parts)
3070{
3071 if (! idx.isValid())
3072 return "";
3073
3074 QStringList col_parts;
3075 int row = idx.row();
3076 for (int col = 0; col < packet_list_model_->columnCount(); col++) {
3077 if (get_column_visible(col)) {
3078 col_parts << packet_list_model_->data(packet_list_model_->index(row, col), Qt::DisplayRole).toString();
3079 }
3080 }
3081
3082 QString col_text;
3083 for (int i = 0; i < col_parts.size(); ++i) {
3084 if (align_parts.at(i) == Qt::AlignLeft) {
3085 col_text += col_parts[i].leftJustified(size_parts.at(i), ' ') + " ";
3086 }
3087 else if (align_parts.at(i) == Qt::AlignRight) {
3088 col_text += col_parts[i].rightJustified(size_parts.at(i), ' ') + " ";
3089 }
3090 }
3091
3092 return QStringLiteral("-%1")(QString(QtPrivate::qMakeStringPrivate(u"" "-%1"))).arg(col_text).trimmed().mid(1);
3093}
3094
3095QString PacketList::createDefaultStyleForHtml()
3096{
3097 QString fontFamily = QString(prefs.gui_font_name).split(",")[0];
3098 QString fontSize = QString(prefs.gui_font_name).split(",")[1];
3099
3100 return QStringLiteral("<style>"(QString(QtPrivate::qMakeStringPrivate(u"" "<style>" "table{font-family:%1;font-size:%2pt;}"
"th{background-color:#000000;color:#ffffff;text-align:left;}"
"th,td{padding:%3pt}" "</style>")))
3101 "table{font-family:%1;font-size:%2pt;}"(QString(QtPrivate::qMakeStringPrivate(u"" "<style>" "table{font-family:%1;font-size:%2pt;}"
"th{background-color:#000000;color:#ffffff;text-align:left;}"
"th,td{padding:%3pt}" "</style>")))
3102 "th{background-color:#000000;color:#ffffff;text-align:left;}"(QString(QtPrivate::qMakeStringPrivate(u"" "<style>" "table{font-family:%1;font-size:%2pt;}"
"th{background-color:#000000;color:#ffffff;text-align:left;}"
"th,td{padding:%3pt}" "</style>")))
3103 "th,td{padding:%3pt}"(QString(QtPrivate::qMakeStringPrivate(u"" "<style>" "table{font-family:%1;font-size:%2pt;}"
"th{background-color:#000000;color:#ffffff;text-align:left;}"
"th,td{padding:%3pt}" "</style>")))
3104 "</style>")(QString(QtPrivate::qMakeStringPrivate(u"" "<style>" "table{font-family:%1;font-size:%2pt;}"
"th{background-color:#000000;color:#ffffff;text-align:left;}"
"th,td{padding:%3pt}" "</style>")))
.arg(fontFamily, fontSize).arg(fontSize.toInt() / 2);
3105}
3106
3107QString PacketList::createOpeningTagForHtml()
3108{
3109 return "<table>";
3110}
3111
3112QString PacketList::createHeaderSummaryForHtml()
3113{
3114 QString hdr_text;
3115 hdr_text += "<tr>";
3116 for (int col = 0; col < packet_list_model_->columnCount(); ++col) {
3117 if (get_column_visible(col)) {
3118 hdr_text += "<th>";
3119 hdr_text += packet_list_model_->headerData(col, Qt::Orientation::Horizontal, Qt::DisplayRole).toString();
3120 hdr_text += "</th>";
3121 }
3122 }
3123 hdr_text += "</tr>";
3124 return hdr_text;
3125}
3126
3127QString PacketList::createSummaryForHtml(QModelIndex idx)
3128{
3129 if (! idx.isValid())
3130 return "";
3131
3132 int row = idx.row();
3133 QString col_text;
3134
3135 QString bg_color = packet_list_model_->data(packet_list_model_->index(row, 0), Qt::BackgroundRole).toString();
3136 QString fg_color = packet_list_model_->data(packet_list_model_->index(row, 0), Qt::ForegroundRole).toString();
3137 col_text += "<tr style=\"background-color:" + bg_color + ";color:" + fg_color + ";\">";
3138
3139 QString alignment[] = {"left", "right", "center", "justify"};
3140
3141 for (int col = 0; col < packet_list_model_->columnCount(); col++) {
3142 if (get_column_visible(col)) {
3143 col_text += "<td style=\"text-align:" + alignment[packet_list_model_->data(packet_list_model_->index(row, col), Qt::TextAlignmentRole).toInt() / 2] + ";\">";
3144 col_text += packet_list_model_->data(packet_list_model_->index(row, col), Qt::DisplayRole).toString();
3145 col_text += "</td>";
3146 }
3147 }
3148
3149 col_text += "</tr>";
3150 return col_text;
3151}
3152
3153QString PacketList::createClosingTagForHtml()
3154{
3155 return "</table>";
3156}
3157
3158void PacketList::copySummary()
3159{
3160 if (!currentIndex().isValid()) return;
3161
3162 QAction *ca = qobject_cast<QAction*>(sender());
3163 if (!ca) return;
3164
3165 QVariant type = ca->data();
3166 if (! type.canConvert<SummaryCopyType>())
3167 return;
3168 SummaryCopyType copy_type = type.value<SummaryCopyType>();
3169
3170 QString copy_text;
3171 if (type == CopyAsText || type == CopyAsHTML) {
3172 if (prefs.gui_packet_list_copy_text_with_aligned_columns) {
3173 QList<int> rows;
3174 rows << currentIndex().row();
3175 QStringList hdr_parts;
3176 QList<int> align_parts, size_parts;
3177 hdr_parts = createHeaderPartsForAligned();
3178 align_parts = createAlignmentPartsForAligned();
3179 size_parts = createSizePartsForAligned(false, hdr_parts, rows);
3180 copy_text = createSummaryForAligned(currentIndex(), align_parts, size_parts);
3181 }
3182 else {
3183 copy_text = createSummaryText(currentIndex(), CopyAsText);
3184 }
3185 copy_text += "\n";
3186 if (type == CopyAsHTML) {
3187 QStringList htmlContent;
3188 htmlContent << createDefaultStyleForHtml();
3189 htmlContent << createOpeningTagForHtml();
3190 htmlContent << createSummaryForHtml(currentIndex());
3191 htmlContent << createClosingTagForHtml();
3192 // htmlContent will never be empty as they will always have
3193 // style and table tags
3194 QMimeData *mimeData = new QMimeData;
3195 mimeData->setHtml(htmlContent.join('\n'));
3196 mimeData->setText(copy_text);
3197 mainApp->clipboard()->setMimeData(mimeData, QClipboard::Clipboard);
3198 }
3199 else {
3200 mainApp->clipboard()->setText(copy_text);
3201 }
3202 }
3203 else {
3204 copy_text = createSummaryText(currentIndex(), copy_type);
3205 if (type != CopyAsYAML)
3206 copy_text += "\n";
3207 mainApp->clipboard()->setText(copy_text);
3208 }
3209}
3210
3211// We need to tell when the user has scrolled the packet list, either to
3212// the end or anywhere other than the end.
3213void PacketList::vScrollBarActionTriggered(int)
3214{
3215 // If we're scrolling with a mouse wheel or trackpad sliderPosition can end up
3216 // past the end.
3217 tail_at_end_ = (overlay_sb_->sliderPosition() >= overlay_sb_->maximum());
3218
3219 scrollViewChanged(tail_at_end_);
3220}
3221
3222void PacketList::scrollViewChanged(bool at_end)
3223{
3224 if (capture_in_progress_) {
3225 // We want to start auto scrolling when the user scrolls to (or past)
3226 // the end only if recent.capture_auto_scroll is set.
3227 // We want to stop autoscrolling if the user scrolls up or uses
3228 // Go to Packet regardless of the preference setting.
3229 if (recent.capture_auto_scroll || !at_end) {
3230 emit packetListScrolled(at_end);
3231 }
3232 }
3233}
3234
3235// Goal: Overlay the packet list scroll bar with the colors of all of the
3236// packets.
3237// Try 1: Average packet colors in each scroll bar raster line. This has
3238// two problems: It's easy to wash out colors and we dissect every packet.
3239// Try 2: Color across a 5000 or 10000 packet window. We still end up washing
3240// out colors.
3241// Try 3: One packet per vertical scroll bar pixel. This seems to work best
3242// but has the smallest window.
3243// Try 4: Use a multiple of the scroll bar height and scale the image down
3244// using Qt::SmoothTransformation. This gives us more packets per raster
3245// line.
3246
3247// Odd (prime?) numbers resulted in fewer scaling artifacts. A multiplier
3248// of 9 washed out colors a little too much.
3249//const int height_multiplier_ = 7;
3250void PacketList::drawNearOverlay()
3251{
3252 if (create_near_overlay_) {
3253 create_near_overlay_ = false;
3254 }
3255
3256 if (!cap_file_ || cap_file_->state != FILE_READ_DONE) return;
3257
3258 if (!prefs.gui_packet_list_show_minimap) return;
3259
3260 qreal dp_ratio = overlay_sb_->devicePixelRatio();
3261 int o_height = overlay_sb_->height() * dp_ratio;
3262 int o_rows = qMin(packet_list_model_->rowCount(), o_height);
3263 QFontMetricsF fmf(mainApp->font());
3264 int o_width = ((static_cast<int>(fmf.height())) * 2 * dp_ratio) + 2; // 2ems + 1-pixel border on either side.
3265
3266 if (recent.packet_list_colorize && o_rows > 0) {
3267 QImage overlay(o_width, o_height, QImage::Format_ARGB32_Premultiplied);
3268
3269 QPainter painter(&overlay);
3270
3271 overlay.fill(Qt::transparent);
3272
3273 int cur_line = 0;
3274 int start = 0;
3275
3276 if (packet_list_model_->rowCount() > o_height && overlay_sb_->maximum() > 0) {
3277 start += ((double) overlay_sb_->value() / overlay_sb_->maximum()) * (packet_list_model_->rowCount() - o_rows);
3278 }
3279 int end = start + o_rows;
3280 for (int row = start; row < end; row++) {
3281 packet_list_model_->ensureRowColorized(row);
3282
3283 frame_data *fdata = packet_list_model_->getRowFdata(row);
3284 int next_line = (row - start + 1) * o_height / o_rows;
3285 int row_height = next_line - cur_line;
3286
3287 // Multi-color support in minimap (enabled for all non-Off modes)
3288 if (prefs.gui_packet_list_multi_color_mode != PACKET_LIST_MULTI_COLOR_MODE_OFF) {
3289 QModelIndex idx = packet_list_model_->index(row, 0);
3290 PacketListRecord *record = static_cast<PacketListRecord*>(idx.internalPointer());
3291 // Conversation color filters take full precedence — skip multi-color stripe rendering
3292 bool is_conversation_color = fdata->color_filter &&
3293 strncmp(((const color_filter_t *)fdata->color_filter)->filter_name,
3294 CONVERSATION_COLOR_PREFIX"___conversation_color_filter___", strlen(CONVERSATION_COLOR_PREFIX"___conversation_color_filter___")) == 0;
3295 if (record && record->hasMultipleColors() && !is_conversation_color) {
3296 // Draw vertical stripes for multiple colors (skip paused filters)
3297 const GSList *filters = record->matchingColorFilters();
3298
3299 // Count non-paused filters
3300 int num_active_colors = 0;
3301 for (const GSList *item = filters; item != NULL__null; item = g_slist_next(item)((item) ? (((GSList *)(item))->next) : __null)) {
3302 const color_filter_t *colorf = (const color_filter_t *)item->data;
3303 if (!color_filter_is_session_disabled(colorf->filter_name)) {
3304 num_active_colors++;
3305 }
3306 }
3307
3308 if (num_active_colors > 0) {
3309 int stripe_width = o_width / num_active_colors;
3310 int x_pos = 0;
3311 int stripe_idx = 0;
3312
3313 for (const GSList *item = filters; item != NULL__null; item = g_slist_next(item)((item) ? (((GSList *)(item))->next) : __null)) {
3314 const color_filter_t *colorf = (const color_filter_t *)item->data;
3315 // Skip paused filters
3316 if (!color_filter_is_session_disabled(colorf->filter_name)) {
3317 QColor color(ColorUtils::fromColorT(&colorf->bg_color));
3318 int width = (stripe_idx == num_active_colors - 1) ? (o_width - x_pos) : stripe_width;
3319 painter.fillRect(x_pos, cur_line, width, row_height, color);
3320 x_pos += stripe_width;
3321 stripe_idx++;
3322 }
3323 }
3324 } else {
3325 // All filters paused, draw no color
3326 painter.fillRect(0, cur_line, o_width, row_height, QColor(Qt::white));
3327 }
3328 } else if (fdata->color_filter) {
3329 // Single color fallback
3330 const color_filter_t *color_filter = (const color_filter_t *) fdata->color_filter;
3331 QColor color(ColorUtils::fromColorT(&color_filter->bg_color));
3332 painter.fillRect(0, cur_line, o_width, row_height, color);
3333 }
3334 } else {
3335 // Original single-color behavior
3336 const color_t *bgcolor = NULL__null;
3337 if (fdata->color_filter) {
3338 const color_filter_t *color_filter = (const color_filter_t *) fdata->color_filter;
3339 bgcolor = &color_filter->bg_color;
3340 }
3341
3342 if (bgcolor) {
3343 QColor color(ColorUtils::fromColorT(bgcolor));
3344 painter.fillRect(0, cur_line, o_width, row_height, color);
3345 }
3346 }
3347
3348 cur_line = next_line;
3349 }
3350
3351 // If the selected packet is in the overlay set selected_pos
3352 // accordingly. Otherwise, pin it to either the top or bottom.
3353 QList<int> positions;
3354 if (selectionModel()->hasSelection()) {
3355
3356 QModelIndexList selRows = selectionModel()->selectedRows(0);
3357 int last_row = -1;
3358 int last_pos = -1;
3359 foreach (QModelIndex idx, selRows)for (auto _container_3359 = QtPrivate::qMakeForeachContainer(
selRows); _container_3359.i != _container_3359.e; ++_container_3359
.i) if (QModelIndex idx = *_container_3359.i; false) {} else
3360 {
3361 int selected_pos = -1;
3362 int sel_row = idx.row();
3363 if (sel_row < start) {
3364 selected_pos = 0;
3365 } else if (sel_row >= end) {
3366 selected_pos = overlay.height() - 1;
3367 } else {
3368 selected_pos = (sel_row - start) * o_height / o_rows;
3369 }
3370
3371 /* Due to the difference in the display height, we sometimes get empty positions
3372 * inbetween consecutive valid rows. If those are detected, they are signaled as
3373 * being selected as well */
3374 if (last_pos >= 0 && selected_pos > (last_pos + 1) && (last_row + 1) == sel_row)
3375 {
3376 for (int pos = (last_pos + 1); pos < selected_pos; pos++)
3377 {
3378 if (! positions.contains(pos))
3379 positions << pos;
3380 }
3381 }
3382 else if (selected_pos != -1 && ! positions.contains(selected_pos))
3383 positions << selected_pos;
3384
3385 last_row = sel_row;
3386 last_pos = selected_pos;
3387 }
3388 }
3389
3390 overlay_sb_->setNearOverlayImage(overlay, packet_list_model_->rowCount(), start, end, positions, (o_height / o_rows));
3391 } else {
3392 QImage overlay;
3393 overlay_sb_->setNearOverlayImage(overlay);
3394 }
3395}
3396
3397void PacketList::drawFarOverlay()
3398{
3399 if (create_far_overlay_) {
3400 create_far_overlay_ = false;
3401 }
3402
3403 if (!cap_file_ || cap_file_->state != FILE_READ_DONE) return;
3404
3405 if (!prefs.gui_packet_list_show_minimap) return;
3406
3407 QSize groove_size = overlay_sb_->grooveRect().size();
3408 qreal dp_ratio = overlay_sb_->devicePixelRatio();
3409 groove_size *= dp_ratio;
3410 int o_width = groove_size.width();
3411 int o_height = groove_size.height();
3412 int pl_rows = packet_list_model_->rowCount();
3413 QImage overlay(o_width, o_height, QImage::Format_ARGB32_Premultiplied);
3414 bool have_marked_image = false;
3415
3416 // If only there were references from popular culture about getting into
3417 // some sort of groove.
3418 if (!overlay.isNull() && recent.packet_list_colorize && pl_rows > 0) {
3419
3420 QPainter painter(&overlay);
3421
3422 // Draw text-colored tick marks on a transparent background.
3423 // Hopefully no themes use the text color for the groove color.
3424 overlay.fill(Qt::transparent);
3425
3426 QColor tick_color = palette().text().color();
3427 tick_color.setAlphaF(0.3f);
3428 painter.setPen(tick_color);
3429
3430 for (int row = 0; row < pl_rows; row++) {
3431
3432 frame_data *fdata = packet_list_model_->getRowFdata(row);
3433 if (fdata->marked || fdata->ref_time || fdata->ignored) {
3434 int new_line = row * o_height / pl_rows;
3435 int tick_width = o_width / 3;
3436 // Marked or ignored: left side, time refs: right side.
3437 // XXX Draw ignored ticks in the middle?
3438 int x1 = fdata->ref_time ? o_width - tick_width : 1;
3439 int x2 = fdata->ref_time ? o_width - 1 : tick_width;
3440
3441 painter.drawLine(x1, new_line, x2, new_line);
3442 have_marked_image = true;
3443 }
3444 }
3445
3446 if (have_marked_image) {
3447 overlay_sb_->setMarkedPacketImage(overlay);
3448 return;
3449 }
3450 }
3451
3452 if (!have_marked_image) {
3453 QImage null_overlay;
3454 overlay_sb_->setMarkedPacketImage(null_overlay);
3455 }
3456}
3457
3458// Auto scroll if:
3459// - We are capturing
3460// - actionGoAutoScroll in the main UI is checked.
3461
3462// actionGoAutoScroll in the main UI:
3463// - Is set to the value of recent.capture_auto_scroll when beginning a capture
3464// - Can be triggered manually by the user
3465// - Is turned on if the last user-set vertical scrollbar position is at the
3466// end and recent.capture_auto_scroll is enabled
3467// - Is turned off if the last user-set vertical scrollbar is not at the end,
3468// or if one of the Go to Packet actions is used (XXX: Should keyboard
3469// navigation in keyPressEvent turn it off for similar reasons?)
3470void PacketList::rowsInserted(const QModelIndex &parent, int start, int end)
3471{
3472 QTreeView::rowsInserted(parent, start, end);
3473 bool aggregation_mode = recent.aggregation_view && prefs.aggregation_fields_num > 0;
3474 if (aggregation_mode) {
3475 // In Aggregation mode, we might have replaced the currently selected
3476 // packets with new ones matching the aggregation fields, so we need
3477 // to redissect the details if a single frame is selected.
3478 drawCurrentPacket(false);
3479 }
3480 if (capture_in_progress_ && tail_at_end_) {
3481 scrollToBottom();
3482 }
3483}
3484
3485void PacketList::resizeAllColumns(bool onlyTimeFormatted)
3486{
3487 if (!cap_file_ || cap_file_->state == FILE_CLOSED || cap_file_->state == FILE_READ_PENDING)
3488 return;
3489
3490 for (unsigned col = 0; col < cap_file_->cinfo.num_cols; col++) {
3491 if (! onlyTimeFormatted || col_has_time_fmt(&cap_file_->cinfo, col)) {
3492 resizeColumnToContents(col);
3493 }
3494 }
3495}