File: | builds/wireshark/wireshark/ui/qt/packet_list.cpp |
Warning: | line 953, column 20 Potential leak of memory pointed to by 'content' |
Press '?' to see keyboard shortcuts
Keyboard shortcuts:
1 | /* packet_list.cpp | |||
2 | * | |||
3 | * Wireshark - Network traffic analyzer | |||
4 | * By Gerald Combs <[email protected]> | |||
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 "config.h" | |||
13 | ||||
14 | #include "file.h" | |||
15 | ||||
16 | #include <epan/epan.h> | |||
17 | #include <epan/epan_dissect.h> | |||
18 | ||||
19 | #include <epan/column.h> | |||
20 | #include <epan/expert.h> | |||
21 | #include <epan/ipproto.h> | |||
22 | #include <epan/packet.h> | |||
23 | #include <epan/prefs.h> | |||
24 | #include <epan/proto.h> | |||
25 | ||||
26 | #include "ui/main_statusbar.h" | |||
27 | #include "ui/packet_list_utils.h" | |||
28 | #include "ui/preference_utils.h" | |||
29 | #include "ui/recent.h" | |||
30 | #include "ui/recent_utils.h" | |||
31 | #include "ui/ws_ui_util.h" | |||
32 | #include "ui/simple_dialog.h" | |||
33 | #include <wsutil/utf8_entities.h> | |||
34 | #include "ui/util.h" | |||
35 | ||||
36 | #include "wiretap/wtap_opttypes.h" | |||
37 | #include "wsutil/application_flavor.h" | |||
38 | #include "wsutil/str_util.h" | |||
39 | #include <wsutil/wslog.h> | |||
40 | ||||
41 | #include <epan/color_filters.h> | |||
42 | ||||
43 | #include <ui/qt/utils/color_utils.h> | |||
44 | #include <ui/qt/widgets/overlay_scroll_bar.h> | |||
45 | #include "proto_tree.h" | |||
46 | #include <ui/qt/utils/qt_ui_utils.h> | |||
47 | #include "main_application.h" | |||
48 | #include <ui/qt/utils/data_printer.h> | |||
49 | #include <ui/qt/utils/frame_information.h> | |||
50 | #include <ui/qt/utils/profile_switcher.h> | |||
51 | #include <ui/qt/utils/variant_pointer.h> | |||
52 | #include <ui/qt/models/pref_models.h> | |||
53 | #include <ui/qt/widgets/packet_list_header.h> | |||
54 | #include <ui/qt/utils/wireshark_mime_data.h> | |||
55 | #include <ui/qt/widgets/drag_label.h> | |||
56 | #include <ui/qt/filter_action.h> | |||
57 | #include <ui/qt/follow_stream_action.h> | |||
58 | #include <ui/qt/decode_as_dialog.h> | |||
59 | #include <ui/qt/wireshark_main_window.h> | |||
60 | ||||
61 | #include <QAction> | |||
62 | #include <QActionGroup> | |||
63 | #include <QClipboard> | |||
64 | #include <QContextMenuEvent> | |||
65 | #include <QtCore/qmath.h> | |||
66 | #include <QElapsedTimer> | |||
67 | #include <QFontMetrics> | |||
68 | #include <QHeaderView> | |||
69 | #include <QMessageBox> | |||
70 | #include <QPainter> | |||
71 | #include <QScreen> | |||
72 | #include <QScrollBar> | |||
73 | #include <QTabWidget> | |||
74 | #include <QTextEdit> | |||
75 | #include <QTimerEvent> | |||
76 | #include <QTreeWidget> | |||
77 | #include <QWindow> | |||
78 | #include <QJsonObject> | |||
79 | #include <QJsonDocument> | |||
80 | ||||
81 | #ifdef Q_OS_WIN | |||
82 | #include "wsutil/file_util.h" | |||
83 | #include <QSysInfo> | |||
84 | #include <uxtheme.h> | |||
85 | #endif | |||
86 | ||||
87 | // To do: | |||
88 | // - Fix "apply as filter" behavior. | |||
89 | // - Add colorize conversation. | |||
90 | // - Use a timer to trigger automatic scrolling. | |||
91 | ||||
92 | // If we ever add the ability to open multiple capture files we might be | |||
93 | // able to use something like QMap<capture_file *, PacketList *> to match | |||
94 | // capture files against packet lists and models. | |||
95 | static PacketList *gbl_cur_packet_list; | |||
96 | ||||
97 | const int max_comments_to_fetch_ = 20000000; // Arbitrary | |||
98 | const int overlay_update_interval_ = 100; // 250; // Milliseconds. | |||
99 | ||||
100 | ||||
101 | /* | |||
102 | * Given a frame_data structure, scroll to and select the row in the | |||
103 | * packet list corresponding to that frame. If there is no such | |||
104 | * row, return false, otherwise return true. | |||
105 | */ | |||
106 | bool | |||
107 | packet_list_select_row_from_data(frame_data *fdata_needle) | |||
108 | { | |||
109 | if (! gbl_cur_packet_list || ! gbl_cur_packet_list->model()) | |||
110 | return false; | |||
111 | ||||
112 | PacketListModel * model = qobject_cast<PacketListModel *>(gbl_cur_packet_list->model()); | |||
113 | ||||
114 | if (! model) | |||
115 | return false; | |||
116 | ||||
117 | model->flushVisibleRows(); | |||
118 | int row = -1; | |||
119 | if (!fdata_needle) | |||
120 | row = 0; | |||
121 | else | |||
122 | row = model->visibleIndexOf(fdata_needle); | |||
123 | ||||
124 | if (row >= 0) { | |||
125 | /* Calling ClearAndSelect with setCurrentIndex clears the "current" | |||
126 | * item, but doesn't clear the "selected" item. We want to clear | |||
127 | * the "selected" item as well so that selectionChanged() will be | |||
128 | * emitted in order to force an update of the packet details and | |||
129 | * packet bytes after a search. | |||
130 | */ | |||
131 | gbl_cur_packet_list->selectionModel()->clearSelection(); | |||
132 | gbl_cur_packet_list->selectionModel()->setCurrentIndex(model->index(row, 0), QItemSelectionModel::ClearAndSelect | QItemSelectionModel::Rows); | |||
133 | gbl_cur_packet_list->scrollTo(gbl_cur_packet_list->currentIndex(), PacketList::PositionAtCenter); | |||
134 | return true; | |||
135 | } | |||
136 | ||||
137 | return false; | |||
138 | } | |||
139 | ||||
140 | /* | |||
141 | * Given a field_info, select the field (which will scroll to it in | |||
142 | * the main ProtoTree, etc.) This is kind of an odd place for it, | |||
143 | * but we call this when performing Find Packet in lieu of changing the | |||
144 | * selected frame (the function above), because we found a match in the | |||
145 | * same frame as the currently selected one. | |||
146 | */ | |||
147 | bool | |||
148 | packet_list_select_finfo(field_info *fi) | |||
149 | { | |||
150 | if (! gbl_cur_packet_list || ! gbl_cur_packet_list->model()) | |||
151 | return false; | |||
152 | ||||
153 | if (fi) { | |||
154 | FieldInformation finfo(fi, gbl_cur_packet_list); | |||
155 | emit gbl_cur_packet_list->fieldSelected(&finfo); | |||
156 | } else { | |||
157 | emit gbl_cur_packet_list->fieldSelected(0); | |||
158 | } | |||
159 | return true; | |||
160 | } | |||
161 | ||||
162 | void | |||
163 | packet_list_clear(void) | |||
164 | { | |||
165 | if (gbl_cur_packet_list) { | |||
166 | gbl_cur_packet_list->clear(); | |||
167 | } | |||
168 | } | |||
169 | ||||
170 | void | |||
171 | packet_list_freeze(void) | |||
172 | { | |||
173 | if (gbl_cur_packet_list) { | |||
174 | gbl_cur_packet_list->freeze(); | |||
175 | } | |||
176 | } | |||
177 | ||||
178 | void | |||
179 | packet_list_thaw(void) | |||
180 | { | |||
181 | if (gbl_cur_packet_list) { | |||
182 | gbl_cur_packet_list->thaw(); | |||
183 | } | |||
184 | ||||
185 | packets_bar_update(); | |||
186 | } | |||
187 | ||||
188 | /* Redraw the packet list *and* currently-selected detail */ | |||
189 | void | |||
190 | packet_list_queue_draw(void) | |||
191 | { | |||
192 | if (gbl_cur_packet_list) | |||
193 | gbl_cur_packet_list->redrawVisiblePackets(); | |||
194 | } | |||
195 | ||||
196 | void | |||
197 | packet_list_recent_write_all(FILE *rf) { | |||
198 | if (!gbl_cur_packet_list) | |||
199 | return; | |||
200 | ||||
201 | gbl_cur_packet_list->writeRecent(rf); | |||
202 | } | |||
203 | ||||
204 | bool | |||
205 | packet_list_multi_select_active(void) | |||
206 | { | |||
207 | if (gbl_cur_packet_list) { | |||
208 | return gbl_cur_packet_list->multiSelectActive(); | |||
209 | } | |||
210 | return false; | |||
211 | } | |||
212 | ||||
213 | #define MIN_COL_WIDTH_STR"MMMMMM" "MMMMMM" | |||
214 | ||||
215 | PacketList::PacketList(QWidget *parent) : | |||
216 | QTreeView(parent), | |||
217 | proto_tree_(nullptr), | |||
218 | cap_file_(nullptr), | |||
219 | ctx_column_(-1), | |||
220 | overlay_timer_id_(0), | |||
221 | create_near_overlay_(true), | |||
222 | create_far_overlay_(true), | |||
223 | mouse_pressed_at_(QModelIndex()), | |||
224 | capture_in_progress_(false), | |||
225 | tail_at_end_(0), | |||
226 | columns_changed_(false), | |||
227 | set_column_visibility_(false), | |||
228 | set_style_sheet_(false), | |||
229 | frozen_current_row_(QModelIndex()), | |||
230 | frozen_selected_rows_(QModelIndexList()), | |||
231 | cur_history_(-1), | |||
232 | in_history_(false), | |||
233 | finfo_array(nullptr), | |||
234 | profile_switcher_(nullptr) | |||
235 | { | |||
236 | setItemsExpandable(false); | |||
237 | setRootIsDecorated(false); | |||
238 | setSortingEnabled(prefs.gui_packet_list_sortable); | |||
239 | setUniformRowHeights(true); | |||
240 | setAccessibleName("Packet list"); | |||
241 | ||||
242 | packet_list_header_ = new PacketListHeader(header()->orientation()); | |||
243 | connect(packet_list_header_, &PacketListHeader::resetColumnWidth, this, &PacketList::setRecentColumnWidth); | |||
244 | connect(packet_list_header_, &PacketListHeader::updatePackets, this, &PacketList::updatePackets); | |||
245 | connect(packet_list_header_, &PacketListHeader::showColumnPreferences, this, &PacketList::showProtocolPreferences); | |||
246 | connect(packet_list_header_, &PacketListHeader::editColumn, this, &PacketList::editColumn); | |||
247 | connect(packet_list_header_, &PacketListHeader::columnsChanged, this, &PacketList::columnsChanged); | |||
248 | setHeader(packet_list_header_); | |||
249 | ||||
250 | header()->setFirstSectionMovable(true); | |||
251 | ||||
252 | setSelectionMode(QAbstractItemView::ExtendedSelection); | |||
253 | ||||
254 | // Shrink down to a small but nonzero size in the main splitter. | |||
255 | int one_em = fontMetrics().height(); | |||
256 | setMinimumSize(one_em, one_em); | |||
257 | ||||
258 | overlay_sb_ = new OverlayScrollBar(Qt::Vertical, this); | |||
259 | setVerticalScrollBar(overlay_sb_); | |||
260 | ||||
261 | header()->setSortIndicator(-1, Qt::AscendingOrder); | |||
262 | ||||
263 | packet_list_model_ = new PacketListModel(this, cap_file_); | |||
264 | setModel(packet_list_model_); | |||
265 | ||||
266 | 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" , 266)); | |||
267 | gbl_cur_packet_list = this; | |||
268 | ||||
269 | connect(packet_list_model_, SIGNAL(goToPacket(int))qFlagLocation("2" "goToPacket(int)" "\0" "ui/qt/packet_list.cpp" ":" "269"), this, SLOT(goToPacket(int))qFlagLocation("1" "goToPacket(int)" "\0" "ui/qt/packet_list.cpp" ":" "269")); | |||
270 | connect(packet_list_model_, SIGNAL(itemHeightChanged(const QModelIndex&))qFlagLocation("2" "itemHeightChanged(const QModelIndex&)" "\0" "ui/qt/packet_list.cpp" ":" "270"), this, SLOT(updateRowHeights(const QModelIndex&))qFlagLocation("1" "updateRowHeights(const QModelIndex&)" "\0" "ui/qt/packet_list.cpp" ":" "270")); | |||
271 | connect(mainApp, SIGNAL(addressResolutionChanged())qFlagLocation("2" "addressResolutionChanged()" "\0" "ui/qt/packet_list.cpp" ":" "271"), this, SLOT(redrawVisiblePacketsDontSelectCurrent())qFlagLocation("1" "redrawVisiblePacketsDontSelectCurrent()" "\0" "ui/qt/packet_list.cpp" ":" "271")); | |||
272 | connect(mainApp, SIGNAL(columnDataChanged())qFlagLocation("2" "columnDataChanged()" "\0" "ui/qt/packet_list.cpp" ":" "272"), this, SLOT(redrawVisiblePacketsDontSelectCurrent())qFlagLocation("1" "redrawVisiblePacketsDontSelectCurrent()" "\0" "ui/qt/packet_list.cpp" ":" "272")); | |||
273 | connect(mainApp, &MainApplication::preferencesChanged, this, [=]() { | |||
274 | /* The pref is a uint but QCache maxCost is a signed int (/ | |||
275 | * qsizetype in Qt 6). Note that QAbstractItemModel row numbers | |||
276 | * are ints, not unsigned ints, so we're limited to INT_MAX | |||
277 | * rows anyway. | |||
278 | */ | |||
279 | PacketListRecord::setMaxCache(prefs.gui_packet_list_cached_rows_max > INT_MAX2147483647 ? INT_MAX2147483647 : prefs.gui_packet_list_cached_rows_max); | |||
280 | if ((bool) (prefs.gui_packet_list_sortable) != isSortingEnabled()) { | |||
281 | setSortingEnabled(prefs.gui_packet_list_sortable); | |||
282 | } | |||
283 | }); | |||
284 | ||||
285 | connect(header(), SIGNAL(sectionResized(int,int,int))qFlagLocation("2" "sectionResized(int,int,int)" "\0" "ui/qt/packet_list.cpp" ":" "285"), | |||
286 | this, SLOT(sectionResized(int,int,int))qFlagLocation("1" "sectionResized(int,int,int)" "\0" "ui/qt/packet_list.cpp" ":" "286")); | |||
287 | connect(header(), SIGNAL(sectionMoved(int,int,int))qFlagLocation("2" "sectionMoved(int,int,int)" "\0" "ui/qt/packet_list.cpp" ":" "287"), | |||
288 | this, SLOT(sectionMoved(int,int,int))qFlagLocation("1" "sectionMoved(int,int,int)" "\0" "ui/qt/packet_list.cpp" ":" "288")); | |||
289 | ||||
290 | connect(verticalScrollBar(), SIGNAL(actionTriggered(int))qFlagLocation("2" "actionTriggered(int)" "\0" "ui/qt/packet_list.cpp" ":" "290"), this, SLOT(vScrollBarActionTriggered(int))qFlagLocation("1" "vScrollBarActionTriggered(int)" "\0" "ui/qt/packet_list.cpp" ":" "290")); | |||
291 | } | |||
292 | ||||
293 | PacketList::~PacketList() | |||
294 | { | |||
295 | if (finfo_array) | |||
296 | { | |||
297 | g_ptr_array_free(finfo_array, true); | |||
298 | } | |||
299 | } | |||
300 | ||||
301 | void PacketList::scrollTo(const QModelIndex &index, QAbstractItemView::ScrollHint hint) | |||
302 | { | |||
303 | /* QAbstractItemView doesn't have a way to indicate "auto scroll, but | |||
304 | * only vertically." So just restore the horizontal scroll value whenever | |||
305 | * it scrolls. | |||
306 | */ | |||
307 | setUpdatesEnabled(false); | |||
308 | int horizVal = horizontalScrollBar()->value(); | |||
309 | QTreeView::scrollTo(index, hint); | |||
310 | horizontalScrollBar()->setValue(horizVal); | |||
311 | setUpdatesEnabled(true); | |||
312 | } | |||
313 | ||||
314 | void PacketList::colorsChanged() | |||
315 | { | |||
316 | const QString c_active = "active"; | |||
317 | const QString c_inactive = "!active"; | |||
318 | ||||
319 | QString flat_style_format = | |||
320 | "QTreeView::item:selected:%1 {" | |||
321 | " color: %2;" | |||
322 | " background-color: %3;" | |||
323 | "}"; | |||
324 | ||||
325 | QString gradient_style_format = | |||
326 | "QTreeView::item:selected:%1 {" | |||
327 | " color: %2;" | |||
328 | " background-color: qlineargradient(x1:0, y1:0, x2:0, y2:1 stop: 0 %4, stop: 0.5 %3, stop: 1 %4);" | |||
329 | "}"; | |||
330 | ||||
331 | QString hover_style; | |||
332 | #if !defined(Q_OS_WIN) | |||
333 | hover_style = QStringLiteral((QString(QtPrivate::qMakeStringPrivate(u"" "QTreeView:item:hover {" " background-color: %1;" " color: palette(text);" "}"))) | |||
334 | "QTreeView:item:hover {"(QString(QtPrivate::qMakeStringPrivate(u"" "QTreeView:item:hover {" " background-color: %1;" " color: palette(text);" "}"))) | |||
335 | " background-color: %1;"(QString(QtPrivate::qMakeStringPrivate(u"" "QTreeView:item:hover {" " background-color: %1;" " color: palette(text);" "}"))) | |||
336 | " color: palette(text);"(QString(QtPrivate::qMakeStringPrivate(u"" "QTreeView:item:hover {" " background-color: %1;" " color: palette(text);" "}"))) | |||
337 | "}")(QString(QtPrivate::qMakeStringPrivate(u"" "QTreeView:item:hover {" " background-color: %1;" " color: palette(text);" "}"))).arg(ColorUtils::hoverBackground().name(QColor::HexArgb)); | |||
338 | #endif | |||
339 | ||||
340 | QString active_style = QString(); | |||
341 | QString inactive_style = QString(); | |||
342 | ||||
343 | if (prefs.gui_active_style == COLOR_STYLE_DEFAULT0) { | |||
344 | // ACTIVE = Default | |||
345 | } else if (prefs.gui_active_style == COLOR_STYLE_FLAT1) { | |||
346 | // ACTIVE = Flat | |||
347 | QColor foreground = ColorUtils::fromColorT(prefs.gui_active_fg); | |||
348 | QColor background = ColorUtils::fromColorT(prefs.gui_active_bg); | |||
349 | ||||
350 | active_style = flat_style_format.arg( | |||
351 | c_active, | |||
352 | foreground.name(), | |||
353 | background.name()); | |||
354 | } else if (prefs.gui_active_style == COLOR_STYLE_GRADIENT2) { | |||
355 | // ACTIVE = Gradient | |||
356 | QColor foreground = ColorUtils::fromColorT(prefs.gui_active_fg); | |||
357 | QColor background1 = ColorUtils::fromColorT(prefs.gui_active_bg); | |||
358 | QColor background2 = QColor::fromRgb(ColorUtils::alphaBlend(foreground, background1, COLOR_STYLE_ALPHA0.25)); | |||
359 | ||||
360 | active_style = gradient_style_format.arg( | |||
361 | c_active, | |||
362 | foreground.name(), | |||
363 | background1.name(), | |||
364 | background2.name()); | |||
365 | } | |||
366 | ||||
367 | // INACTIVE style sheet settings | |||
368 | if (prefs.gui_inactive_style == COLOR_STYLE_DEFAULT0) { | |||
369 | // INACTIVE = Default | |||
370 | } else if (prefs.gui_inactive_style == COLOR_STYLE_FLAT1) { | |||
371 | // INACTIVE = Flat | |||
372 | QColor foreground = ColorUtils::fromColorT(prefs.gui_inactive_fg); | |||
373 | QColor background = ColorUtils::fromColorT(prefs.gui_inactive_bg); | |||
374 | ||||
375 | inactive_style = flat_style_format.arg( | |||
376 | c_inactive, | |||
377 | foreground.name(), | |||
378 | background.name()); | |||
379 | } else if (prefs.gui_inactive_style == COLOR_STYLE_GRADIENT2) { | |||
380 | // INACTIVE = Gradient | |||
381 | QColor foreground = ColorUtils::fromColorT(prefs.gui_inactive_fg); | |||
382 | QColor background1 = ColorUtils::fromColorT(prefs.gui_inactive_bg); | |||
383 | QColor background2 = QColor::fromRgb(ColorUtils::alphaBlend(foreground, background1, COLOR_STYLE_ALPHA0.25)); | |||
384 | ||||
385 | inactive_style = gradient_style_format.arg( | |||
386 | c_inactive, | |||
387 | foreground.name(), | |||
388 | background1.name(), | |||
389 | background2.name()); | |||
390 | } | |||
391 | ||||
392 | // Set the style sheet | |||
393 | set_style_sheet_ = true; | |||
394 | if(prefs.gui_packet_list_hover_style) { | |||
395 | setStyleSheet(active_style + inactive_style + hover_style); | |||
396 | } else { | |||
397 | setStyleSheet(active_style + inactive_style); | |||
398 | } | |||
399 | set_style_sheet_ = false; | |||
400 | #if \ | |||
401 | ( \ | |||
402 | (QT_VERSION((6<<16)|(4<<8)|(2)) >= QT_VERSION_CHECK(6, 5, 4)((6<<16)|(5<<8)|(4)) && QT_VERSION((6<<16)|(4<<8)|(2)) < QT_VERSION_CHECK(6, 6, 0)((6<<16)|(6<<8)|(0))) \ | |||
403 | || (QT_VERSION((6<<16)|(4<<8)|(2)) >= QT_VERSION_CHECK(6, 6, 1)((6<<16)|(6<<8)|(1))) \ | |||
404 | ) | |||
405 | // https://bugreports.qt.io/browse/QTBUG-122109 | |||
406 | // Affects Qt 6.5.4 and later, 6.6.1 and later. | |||
407 | // When setting the style sheet, all visible sections are set | |||
408 | // to the new minimum DefaultSectionSize (even if it hasn't | |||
409 | // changed.) So make sure the new widths aren't saved to recent | |||
410 | // and then restore from recent. | |||
411 | applyRecentColumnWidths(); | |||
412 | setColumnVisibility(); | |||
413 | #endif | |||
414 | } | |||
415 | ||||
416 | QString PacketList::joinSummaryRow(QStringList col_parts, int row, SummaryCopyType type) | |||
417 | { | |||
418 | QString copy_text; | |||
419 | switch (type) { | |||
420 | case CopyAsCSV: | |||
421 | copy_text = "\""; | |||
422 | copy_text += col_parts.join("\",\""); | |||
423 | copy_text += "\""; | |||
424 | break; | |||
425 | case CopyAsYAML: | |||
426 | copy_text = "----\n"; | |||
427 | copy_text += QStringLiteral("# Packet %1 from %2\n")(QString(QtPrivate::qMakeStringPrivate(u"" "# Packet %1 from %2\n" ))).arg(row).arg(cap_file_->filename); | |||
428 | copy_text += "- "; | |||
429 | copy_text += col_parts.join("\n- "); | |||
430 | copy_text += "\n"; | |||
431 | break; | |||
432 | case CopyAsText: | |||
433 | default: | |||
434 | copy_text = col_parts.join("\t"); | |||
435 | } | |||
436 | ||||
437 | return copy_text; | |||
438 | } | |||
439 | ||||
440 | void PacketList::drawRow (QPainter *painter, const QStyleOptionViewItem &option, const QModelIndex &index) const | |||
441 | { | |||
442 | QTreeView::drawRow(painter, option, index); | |||
443 | ||||
444 | if (prefs.gui_packet_list_separator) { | |||
445 | QRect rect = visualRect(index); | |||
446 | ||||
447 | painter->setPen(QColor(Qt::white)); | |||
448 | painter->drawLine(0, rect.y() + rect.height() - 1, width(), rect.y() + rect.height() - 1); | |||
449 | } | |||
450 | } | |||
451 | ||||
452 | void PacketList::setProtoTree (ProtoTree *proto_tree) { | |||
453 | proto_tree_ = proto_tree; | |||
454 | ||||
455 | connect(proto_tree_, SIGNAL(goToPacket(int))qFlagLocation("2" "goToPacket(int)" "\0" "ui/qt/packet_list.cpp" ":" "455"), this, SLOT(goToPacket(int))qFlagLocation("1" "goToPacket(int)" "\0" "ui/qt/packet_list.cpp" ":" "455")); | |||
456 | connect(proto_tree_, SIGNAL(relatedFrame(int,ft_framenum_type_t))qFlagLocation("2" "relatedFrame(int,ft_framenum_type_t)" "\0" "ui/qt/packet_list.cpp" ":" "456"), | |||
457 | &related_packet_delegate_, SLOT(addRelatedFrame(int,ft_framenum_type_t))qFlagLocation("1" "addRelatedFrame(int,ft_framenum_type_t)" "\0" "ui/qt/packet_list.cpp" ":" "457")); | |||
458 | } | |||
459 | ||||
460 | bool PacketList::uniqueSelectActive() | |||
461 | { | |||
462 | return selectionModel()->selectedRows(0).count() == 1 ? true : false; | |||
463 | } | |||
464 | ||||
465 | bool PacketList::multiSelectActive() | |||
466 | { | |||
467 | return selectionModel()->selectedRows(0).count() > 1 ? true : false; | |||
468 | } | |||
469 | ||||
470 | QList<int> PacketList::selectedRows(bool useFrameNum) | |||
471 | { | |||
472 | QList<int> rows; | |||
473 | if (selectionModel() && selectionModel()->hasSelection()) | |||
474 | { | |||
475 | foreach (QModelIndex idx, selectionModel()->selectedRows(0))for (auto _container_475 = QtPrivate::qMakeForeachContainer(selectionModel ()->selectedRows(0)); _container_475.i != _container_475.e ; ++_container_475.i) if (QModelIndex idx = *_container_475.i ; false) {} else | |||
476 | { | |||
477 | if (idx.isValid()) | |||
478 | { | |||
479 | if (! useFrameNum) | |||
480 | rows << idx.row(); | |||
481 | else if (useFrameNum) | |||
482 | { | |||
483 | frame_data * frame = getFDataForRow(idx.row()); | |||
484 | if (frame) | |||
485 | rows << frame->num; | |||
486 | } | |||
487 | } | |||
488 | } | |||
489 | } | |||
490 | else if (currentIndex().isValid()) | |||
491 | { | |||
492 | // | |||
493 | // XXX - will we ever have a current index but not a selection | |||
494 | // model? | |||
495 | // | |||
496 | if (! useFrameNum) | |||
497 | rows << currentIndex().row(); | |||
498 | else | |||
499 | { | |||
500 | frame_data *frame = getFDataForRow(currentIndex().row()); | |||
501 | if (frame) | |||
502 | rows << frame->num; | |||
503 | } | |||
504 | } | |||
505 | ||||
506 | return rows; | |||
507 | } | |||
508 | ||||
509 | void PacketList::selectionChanged (const QItemSelection & selected, const QItemSelection & deselected) | |||
510 | { | |||
511 | QTreeView::selectionChanged(selected, deselected); | |||
512 | ||||
513 | if (!cap_file_) return; | |||
514 | ||||
515 | int row = -1; | |||
516 | static bool multiSelect = false; | |||
517 | ||||
518 | if (selectionModel()) | |||
519 | { | |||
520 | QModelIndexList selRows = selectionModel()->selectedRows(0); | |||
521 | if (selRows.count() > 1) | |||
522 | { | |||
523 | QList<int> rows; | |||
524 | foreach (QModelIndex idx, selRows)for (auto _container_524 = QtPrivate::qMakeForeachContainer(selRows ); _container_524.i != _container_524.e; ++_container_524.i) if (QModelIndex idx = *_container_524.i; false) {} else | |||
525 | { | |||
526 | if (idx.isValid()) | |||
527 | rows << idx.row(); | |||
528 | } | |||
529 | ||||
530 | emit framesSelected(rows); | |||
531 | emit fieldSelected(0); | |||
532 | cf_unselect_packet(cap_file_); | |||
533 | ||||
534 | /* We have to repaint the content while changing state, as some delegates react to multi-select */ | |||
535 | if (! multiSelect) | |||
536 | { | |||
537 | related_packet_delegate_.clear(); | |||
538 | viewport()->update(); | |||
539 | } | |||
540 | ||||
541 | multiSelect = true; | |||
542 | ||||
543 | return; | |||
544 | } | |||
545 | else if (selRows.count() > 0 && selRows.at(0).isValid()) | |||
546 | { | |||
547 | multiSelect = false; | |||
548 | row = selRows.at(0).row(); | |||
549 | } | |||
550 | ||||
551 | /* Handling empty selection */ | |||
552 | if (selRows.count() <= 0) | |||
553 | { | |||
554 | /* Nothing selected, but multiSelect is still active */ | |||
555 | if (multiSelect) | |||
556 | { | |||
557 | multiSelect = false; | |||
558 | if (currentIndex().isValid()) | |||
559 | { | |||
560 | selectionModel()->select(currentIndex(), QItemSelectionModel::ClearAndSelect | QItemSelectionModel::Rows ); | |||
561 | return; | |||
562 | } | |||
563 | } | |||
564 | /* Nothing selected, so in WS <= 3.0 nothing was indicated as well */ | |||
565 | else if (currentIndex().isValid()) | |||
566 | { | |||
567 | setCurrentIndex(QModelIndex()); | |||
568 | } | |||
569 | } | |||
570 | } | |||
571 | ||||
572 | if (row < 0 || !packet_list_model_) | |||
573 | cf_unselect_packet(cap_file_); | |||
574 | else { | |||
575 | frame_data * fdata = packet_list_model_->getRowFdata(row); | |||
576 | cf_select_packet(cap_file_, fdata); | |||
577 | } | |||
578 | ||||
579 | if (!in_history_ && cap_file_->current_frame) { | |||
580 | cur_history_++; | |||
581 | selection_history_.resize(cur_history_); | |||
582 | selection_history_.append(cap_file_->current_frame->num); | |||
583 | } | |||
584 | ||||
585 | related_packet_delegate_.clear(); | |||
586 | ||||
587 | // The previous dissection state has been invalidated by cf_select_packet | |||
588 | // above, receivers must clear the previous state and apply the updated one. | |||
589 | emit framesSelected(QList<int>() << row); | |||
590 | ||||
591 | if (!cap_file_->edt) { | |||
592 | viewport()->update(); | |||
593 | emit fieldSelected(0); | |||
594 | return; | |||
595 | } | |||
596 | ||||
597 | if (cap_file_->edt->tree) { | |||
598 | packet_info *pi = &cap_file_->edt->pi; | |||
599 | related_packet_delegate_.setCurrentFrame(pi->num); | |||
600 | conversation_t *conv = find_conversation_pinfo_ro(pi, 0); | |||
601 | if (conv) { | |||
602 | related_packet_delegate_.setConversation(conv); | |||
603 | } | |||
604 | viewport()->update(); | |||
605 | } | |||
606 | ||||
607 | if (cap_file_->search_in_progress) { | |||
608 | field_info *fi = NULL__null; | |||
609 | ||||
610 | if (cap_file_->string && cap_file_->decode_data) { | |||
611 | // The tree where the target string matched one of the labels was discarded in | |||
612 | // match_protocol_tree() so we have to search again in the latest tree. | |||
613 | fi = cf_find_string_protocol_tree(cap_file_, cap_file_->edt->tree); | |||
614 | } else if (cap_file_->search_len != 0) { | |||
615 | // Find the finfo that corresponds to our byte. | |||
616 | // The match can span multiple fields (and a single byte can | |||
617 | // match more than one field.) Our behavior is to find the last | |||
618 | // field in the tree (so hopefully spanning fewer bytes) that | |||
619 | // matches the last byte in the search match. | |||
620 | // (regex search can find a zero length match not at the | |||
621 | // start of the frame if lookbehind is used, but | |||
622 | // proto_find_field_from_offset doesn't match such a field | |||
623 | // and it's not clear which field we would want to match.) | |||
624 | fi = proto_find_field_from_offset(cap_file_->edt->tree, cap_file_->search_pos + cap_file_->search_len - 1, | |||
625 | cap_file_->edt->tvb); | |||
626 | } | |||
627 | ||||
628 | if (fi) { | |||
629 | FieldInformation finfo(fi, this); | |||
630 | emit fieldSelected(&finfo); | |||
631 | } else { | |||
632 | emit fieldSelected(0); | |||
633 | } | |||
634 | } else if (proto_tree_) { | |||
635 | proto_tree_->restoreSelectedField(); | |||
636 | } | |||
637 | } | |||
638 | ||||
639 | void PacketList::contextMenuEvent(QContextMenuEvent *event) | |||
640 | { | |||
641 | const char *module_name = NULL__null; | |||
642 | ||||
643 | if (finfo_array) | |||
644 | { | |||
645 | g_ptr_array_free(finfo_array, true); | |||
646 | finfo_array = NULL__null; | |||
647 | } | |||
648 | ||||
649 | QModelIndex ctxIndex = indexAt(event->pos()); | |||
650 | ||||
651 | if (selectionModel() && selectionModel()->selectedRows(0).count() > 1) | |||
652 | selectionModel()->select(ctxIndex, QItemSelectionModel::ClearAndSelect | QItemSelectionModel::Rows); | |||
653 | ||||
654 | // frameData will be owned by one of the submenus, see below. | |||
655 | FrameInformation * frameData = | |||
656 | new FrameInformation(new CaptureFile(this, cap_file_), packet_list_model_->getRowFdata(ctxIndex.row())); | |||
657 | ||||
658 | QMenu * ctx_menu = new QMenu(this); | |||
659 | ctx_menu->setAttribute(Qt::WA_DeleteOnClose); | |||
660 | // XXX We might want to reimplement setParent() and fill in the context | |||
661 | // menu there. | |||
662 | ctx_menu->addAction(window()->findChild<QAction *>("actionEditMarkSelected")); | |||
663 | ctx_menu->addAction(window()->findChild<QAction *>("actionEditIgnoreSelected")); | |||
664 | ctx_menu->addAction(window()->findChild<QAction *>("actionEditSetTimeReference")); | |||
665 | ctx_menu->addAction(window()->findChild<QAction *>("actionEditTimeShift")); | |||
666 | ctx_menu->addMenu(window()->findChild<QMenu *>("menuPacketComment")); | |||
667 | ||||
668 | ctx_menu->addSeparator(); | |||
669 | ||||
670 | // Code for custom context menus from Lua's register_packet_menu() | |||
671 | MainWindow * mainWindow = qobject_cast<MainWindow *>(mainApp->mainWindow()); | |||
672 | // N.B., will only call for a single frame selection, | |||
673 | if (cap_file_ && cap_file_->edt && cap_file_->edt->tree) { | |||
674 | finfo_array = proto_all_finfos(cap_file_->edt->tree); | |||
675 | if (mainWindow) { | |||
676 | bool insertedPacketMenu = mainWindow->addPacketMenus(ctx_menu, finfo_array); | |||
677 | if (insertedPacketMenu) { | |||
678 | ctx_menu->addSeparator(); | |||
679 | } | |||
680 | } | |||
681 | } | |||
682 | ||||
683 | ctx_menu->addAction(window()->findChild<QAction *>("actionViewEditResolvedName")); | |||
684 | ctx_menu->addSeparator(); | |||
685 | ||||
686 | QString selectedfilter = getFilterFromRowAndColumn(currentIndex()); | |||
687 | ||||
688 | if (! hasFocus() && cap_file_ && cap_file_->finfo_selected) { | |||
689 | char *tmp_field = proto_construct_match_selected_string(cap_file_->finfo_selected, cap_file_->edt); | |||
690 | selectedfilter = QString(tmp_field); | |||
691 | wmem_free(NULL__null, tmp_field); | |||
692 | } | |||
693 | ||||
694 | bool have_filter_expr = !selectedfilter.isEmpty(); | |||
695 | ctx_menu->addMenu(FilterAction::createFilterMenu(FilterAction::ActionApply, selectedfilter, have_filter_expr, ctx_menu)); | |||
696 | ctx_menu->addMenu(FilterAction::createFilterMenu(FilterAction::ActionPrepare, selectedfilter, have_filter_expr, ctx_menu)); | |||
697 | ||||
698 | const char *conv_menu_name = "menuConversationFilter"; | |||
699 | QMenu * main_menu_item = window()->findChild<QMenu *>(conv_menu_name); | |||
700 | conv_menu_.setTitle(main_menu_item->title()); | |||
701 | conv_menu_.setObjectName(conv_menu_name); | |||
702 | ctx_menu->addMenu(&conv_menu_); | |||
703 | ||||
704 | const char *colorize_menu_name = "menuColorizeConversation"; | |||
705 | main_menu_item = window()->findChild<QMenu *>(colorize_menu_name); | |||
706 | colorize_menu_.setTitle(main_menu_item->title()); | |||
707 | colorize_menu_.setObjectName(colorize_menu_name); | |||
708 | ctx_menu->addMenu(&colorize_menu_); | |||
709 | ||||
710 | QMenu * submenu; | |||
711 | main_menu_item = window()->findChild<QMenu *>("menuSCTP"); | |||
712 | if (main_menu_item) { | |||
713 | submenu = new QMenu(main_menu_item->title(), ctx_menu); | |||
714 | ctx_menu->addMenu(submenu); | |||
715 | submenu->addAction(window()->findChild<QAction *>("actionSCTPAnalyseThisAssociation")); | |||
716 | submenu->addAction(window()->findChild<QAction *>("actionSCTPShowAllAssociations")); | |||
717 | submenu->addAction(window()->findChild<QAction *>("actionSCTPFilterThisAssociation")); | |||
718 | } | |||
719 | ||||
720 | main_menu_item = window()->findChild<QMenu *>("menuFollow"); | |||
721 | if (main_menu_item) { | |||
722 | submenu = new QMenu(main_menu_item->title(), ctx_menu); | |||
723 | ctx_menu->addMenu(submenu); | |||
724 | foreach (FollowStreamAction *follow_action, main_menu_item->findChildren<FollowStreamAction *>())for (auto _container_724 = QtPrivate::qMakeForeachContainer(main_menu_item ->findChildren<FollowStreamAction *>()); _container_724 .i != _container_724.e; ++_container_724.i) if (FollowStreamAction *follow_action = *_container_724.i; false) {} else { | |||
725 | /* XXX: We could, like the prefs above, walk the protocols/layers | |||
726 | * and add the follow actions in the order they appear in the packet. | |||
727 | */ | |||
728 | if (follow_action->isEnabled()) { | |||
729 | submenu->addAction(follow_action); | |||
730 | } | |||
731 | } | |||
732 | } | |||
733 | ||||
734 | ctx_menu->addSeparator(); | |||
735 | ||||
736 | main_menu_item = window()->findChild<QMenu *>("menuEditCopy"); | |||
737 | submenu = new QMenu(main_menu_item->title(), ctx_menu); | |||
738 | submenu->setToolTipsVisible(true); | |||
739 | ctx_menu->addMenu(submenu); | |||
740 | ||||
741 | QAction * action = submenu->addAction(tr("Summary as Text")); | |||
742 | action->setData(CopyAsText); | |||
743 | connect(action, SIGNAL(triggered())qFlagLocation("2" "triggered()" "\0" "ui/qt/packet_list.cpp" ":" "743"), this, SLOT(copySummary())qFlagLocation("1" "copySummary()" "\0" "ui/qt/packet_list.cpp" ":" "743")); | |||
744 | action = submenu->addAction(tr("…as CSV")); | |||
745 | action->setData(CopyAsCSV); | |||
746 | connect(action, SIGNAL(triggered())qFlagLocation("2" "triggered()" "\0" "ui/qt/packet_list.cpp" ":" "746"), this, SLOT(copySummary())qFlagLocation("1" "copySummary()" "\0" "ui/qt/packet_list.cpp" ":" "746")); | |||
747 | action = submenu->addAction(tr("…as YAML")); | |||
748 | action->setData(CopyAsYAML); | |||
749 | connect(action, SIGNAL(triggered())qFlagLocation("2" "triggered()" "\0" "ui/qt/packet_list.cpp" ":" "749"), this, SLOT(copySummary())qFlagLocation("1" "copySummary()" "\0" "ui/qt/packet_list.cpp" ":" "749")); | |||
750 | action = submenu->addAction(tr("…as HTML")); | |||
751 | action->setData(CopyAsHTML); | |||
752 | connect(action, SIGNAL(triggered())qFlagLocation("2" "triggered()" "\0" "ui/qt/packet_list.cpp" ":" "752"), this, SLOT(copySummary())qFlagLocation("1" "copySummary()" "\0" "ui/qt/packet_list.cpp" ":" "752")); | |||
753 | submenu->addSeparator(); | |||
754 | ||||
755 | submenu->addAction(window()->findChild<QAction *>("actionEditCopyAsFilter")); | |||
756 | submenu->addSeparator(); | |||
757 | ||||
758 | QActionGroup * copyEntries = DataPrinter::copyActions(this, frameData); | |||
759 | submenu->addActions(copyEntries->actions()); | |||
760 | copyEntries->setParent(submenu); | |||
761 | frameData->setParent(submenu); | |||
762 | ||||
763 | if (application_flavor_is_wireshark()) { | |||
764 | /* i.e., Wireshark only */ | |||
765 | ctx_menu->addSeparator(); | |||
766 | QMenu *proto_prefs_menus = new QMenu(ProtocolPreferencesMenu::tr("Protocol Preferences"), ctx_menu); | |||
767 | ||||
768 | if (cap_file_ && cap_file_->edt && cap_file_->edt->tree) { | |||
769 | QList<QString> added_proto_prefs; | |||
770 | // N.B. finfo_array will be assigned above | |||
771 | for (unsigned i = 0; i < finfo_array->len; i++) { | |||
772 | field_info *fi = (field_info *)g_ptr_array_index (finfo_array, i)((finfo_array)->pdata)[i]; | |||
773 | const header_field_info *hfinfo = fi->hfinfo; | |||
774 | ||||
775 | if (prefs_is_registered_protocol(hfinfo->abbrev)) { | |||
776 | if (hfinfo->parent == -1) { | |||
777 | module_name = hfinfo->abbrev; | |||
778 | } else { | |||
779 | module_name = proto_registrar_get_abbrev(hfinfo->parent); | |||
780 | } | |||
781 | ||||
782 | if (added_proto_prefs.contains(module_name)) { | |||
783 | continue; | |||
784 | } | |||
785 | ||||
786 | ProtocolPreferencesMenu *proto_prefs_menu = new ProtocolPreferencesMenu(hfinfo->name, module_name, proto_prefs_menus); | |||
787 | ||||
788 | connect(proto_prefs_menu, SIGNAL(showProtocolPreferences(QString))qFlagLocation("2" "showProtocolPreferences(QString)" "\0" "ui/qt/packet_list.cpp" ":" "788"), | |||
789 | this, SIGNAL(showProtocolPreferences(QString))qFlagLocation("2" "showProtocolPreferences(QString)" "\0" "ui/qt/packet_list.cpp" ":" "789")); | |||
790 | connect(proto_prefs_menu, SIGNAL(editProtocolPreference(pref_t*,module_t*))qFlagLocation("2" "editProtocolPreference(pref_t*,module_t*)" "\0" "ui/qt/packet_list.cpp" ":" "790"), | |||
791 | this, SIGNAL(editProtocolPreference(pref_t*,module_t*))qFlagLocation("2" "editProtocolPreference(pref_t*,module_t*)" "\0" "ui/qt/packet_list.cpp" ":" "791")); | |||
792 | ||||
793 | proto_prefs_menus->addMenu(proto_prefs_menu); | |||
794 | added_proto_prefs << module_name; | |||
795 | } | |||
796 | } | |||
797 | } | |||
798 | ctx_menu->addMenu(proto_prefs_menus); | |||
799 | action = ctx_menu->addAction(tr("Decode As…")); | |||
800 | action->setProperty("create_new", QVariant(true)); | |||
801 | connect(action, &QAction::triggered, this, &PacketList::ctxDecodeAsDialog); | |||
802 | // "Print" not ported intentionally | |||
803 | action = window()->findChild<QAction *>("actionViewShowPacketInNewWindow"); | |||
804 | ctx_menu->addAction(action); | |||
805 | } | |||
806 | ||||
807 | // Set menu sensitivity for the current column and set action data. | |||
808 | if (frameData) | |||
809 | emit framesSelected(QList<int>() << frameData->frameNum()); | |||
810 | else | |||
811 | emit framesSelected(QList<int>()); | |||
812 | ||||
813 | ctx_menu->popup(event->globalPos()); | |||
814 | } | |||
815 | ||||
816 | void PacketList::ctxDecodeAsDialog() | |||
817 | { | |||
818 | QAction *da_action = qobject_cast<QAction*>(sender()); | |||
819 | if (! da_action) | |||
820 | return; | |||
821 | bool create_new = da_action->property("create_new").toBool(); | |||
822 | ||||
823 | DecodeAsDialog *da_dialog = new DecodeAsDialog(this, cap_file_, create_new); | |||
824 | connect(da_dialog, SIGNAL(destroyed(QObject*))qFlagLocation("2" "destroyed(QObject*)" "\0" "ui/qt/packet_list.cpp" ":" "824"), mainApp, SLOT(flushAppSignals())qFlagLocation("1" "flushAppSignals()" "\0" "ui/qt/packet_list.cpp" ":" "824")); | |||
825 | da_dialog->setWindowModality(Qt::ApplicationModal); | |||
826 | da_dialog->setAttribute(Qt::WA_DeleteOnClose); | |||
827 | da_dialog->show(); | |||
828 | } | |||
829 | ||||
830 | void PacketList::timerEvent(QTimerEvent *event) | |||
831 | { | |||
832 | if (event->timerId() == overlay_timer_id_) { | |||
833 | if (!capture_in_progress_) { | |||
834 | if (create_near_overlay_) drawNearOverlay(); | |||
835 | if (create_far_overlay_) drawFarOverlay(); | |||
836 | } | |||
837 | } else { | |||
838 | QTreeView::timerEvent(event); | |||
839 | } | |||
840 | } | |||
841 | ||||
842 | void PacketList::paintEvent(QPaintEvent *event) | |||
843 | { | |||
844 | // XXX This is overkill, but there are quite a few events that | |||
845 | // require a new overlay, e.g. page up/down, scrolling, column | |||
846 | // resizing, etc. | |||
847 | create_near_overlay_ = true; | |||
848 | QTreeView::paintEvent(event); | |||
849 | } | |||
850 | ||||
851 | void PacketList::mousePressEvent (QMouseEvent *event) | |||
852 | { | |||
853 | QTreeView::mousePressEvent(event); | |||
854 | ||||
855 | QModelIndex curIndex = indexAt(event->pos()); | |||
856 | mouse_pressed_at_ = curIndex; | |||
857 | ||||
858 | bool midButton = (event->buttons() & Qt::MiddleButton) == Qt::MiddleButton; | |||
859 | if (midButton && cap_file_ && packet_list_model_) | |||
860 | { | |||
861 | packet_list_model_->toggleFrameMark(QModelIndexList() << curIndex); | |||
862 | ||||
863 | // Make sure the packet list's frame.marked related field text is updated. | |||
864 | redrawVisiblePackets(); | |||
865 | ||||
866 | create_far_overlay_ = true; | |||
867 | packets_bar_update(); | |||
868 | } | |||
869 | } | |||
870 | ||||
871 | void PacketList::mouseReleaseEvent(QMouseEvent *event) { | |||
872 | QTreeView::mouseReleaseEvent(event); | |||
873 | ||||
874 | mouse_pressed_at_ = QModelIndex(); | |||
875 | } | |||
876 | ||||
877 | void PacketList::mouseMoveEvent (QMouseEvent *event) | |||
878 | { | |||
879 | QModelIndex curIndex = indexAt(event->pos()); | |||
880 | if (event->buttons() & Qt::LeftButton && curIndex.isValid() && curIndex == mouse_pressed_at_) | |||
| ||||
881 | { | |||
882 | ctx_column_ = curIndex.column(); | |||
883 | QMimeData * mimeData = new QMimeData(); | |||
884 | QWidget * content = nullptr; | |||
885 | ||||
886 | QString filter = getFilterFromRowAndColumn(curIndex); | |||
887 | QList<int> rows = selectedRows(); | |||
888 | if (rows.count() > 1) | |||
889 | { | |||
890 | QStringList content; | |||
891 | foreach (int row, rows)for (auto _container_891 = QtPrivate::qMakeForeachContainer(rows ); _container_891.i != _container_891.e; ++_container_891.i) if (int row = *_container_891.i; false) {} else | |||
892 | { | |||
893 | QModelIndex idx = model()->index(row, 0); | |||
894 | if (! idx.isValid()) | |||
895 | continue; | |||
896 | ||||
897 | QString entry = createSummaryText(idx, CopyAsText); | |||
898 | content << entry; | |||
899 | } | |||
900 | ||||
901 | if (content.count() > 0) | |||
902 | mimeData->setText(content.join("\n")); | |||
903 | } | |||
904 | else if (! filter.isEmpty()) | |||
905 | { | |||
906 | QString abbrev; | |||
907 | QString name = model()->headerData(curIndex.column(), header()->orientation()).toString(); | |||
908 | ||||
909 | if (! filter.isEmpty()) | |||
910 | { | |||
911 | abbrev = filter.left(filter.indexOf(' ')); | |||
912 | } | |||
913 | else | |||
914 | { | |||
915 | filter = model()->data(curIndex).toString().toLower(); | |||
916 | abbrev = filter; | |||
917 | } | |||
918 | ||||
919 | mimeData->setText(filter); | |||
920 | ||||
921 | QJsonObject filterData; | |||
922 | filterData["filter"] = filter; | |||
923 | filterData["name"] = abbrev; | |||
924 | filterData["description"] = name; | |||
925 | ||||
926 | mimeData->setData(WiresharkMimeData::DisplayFilterMimeType, QJsonDocument(filterData).toJson()); | |||
927 | content = new DragLabel(QStringLiteral("%1\n%2")(QString(QtPrivate::qMakeStringPrivate(u"" "%1\n%2"))).arg(name, abbrev), this); | |||
928 | } | |||
929 | else | |||
930 | { | |||
931 | QString text = model()->data(curIndex).toString(); | |||
932 | if (! text.isEmpty()) | |||
933 | mimeData->setText(text); | |||
934 | } | |||
935 | ||||
936 | if (mimeData->hasText() || mimeData->hasFormat(WiresharkMimeData::DisplayFilterMimeType)) | |||
937 | { | |||
938 | QDrag * drag = new QDrag(this); | |||
939 | drag->setMimeData(mimeData); | |||
940 | if (content) | |||
941 | { | |||
942 | qreal dpr = window()->windowHandle()->devicePixelRatio(); | |||
943 | QPixmap pixmap= QPixmap(content->size() * dpr); | |||
944 | pixmap.setDevicePixelRatio(dpr); | |||
945 | content->render(&pixmap); | |||
946 | drag->setPixmap(pixmap); | |||
947 | } | |||
948 | ||||
949 | drag->exec(Qt::CopyAction); | |||
950 | } | |||
951 | else | |||
952 | { | |||
953 | delete mimeData; | |||
| ||||
954 | } | |||
955 | } | |||
956 | } | |||
957 | ||||
958 | void PacketList::keyPressEvent(QKeyEvent *event) | |||
959 | { | |||
960 | QTreeView::keyPressEvent(event); | |||
961 | ||||
962 | if (event->matches(QKeySequence::Copy)) | |||
963 | { | |||
964 | QStringList content, htmlContent; | |||
965 | if (model() && selectionModel() && selectionModel()->hasSelection()) | |||
966 | { | |||
967 | QList<int> rows; | |||
968 | QModelIndexList selRows = selectionModel()->selectedRows(0); | |||
969 | foreach(QModelIndex row, selRows)for (auto _container_969 = QtPrivate::qMakeForeachContainer(selRows ); _container_969.i != _container_969.e; ++_container_969.i) if (QModelIndex row = *_container_969.i; false) {} else | |||
970 | rows.append(row.row()); | |||
971 | ||||
972 | QStringList hdr_parts; | |||
973 | QList<int> align_parts, size_parts; | |||
974 | ||||
975 | switch (prefs.gui_packet_list_copy_format_options_for_keyboard_shortcut) { | |||
976 | case COPY_FORMAT_TEXT: | |||
977 | case COPY_FORMAT_HTML: | |||
978 | if (prefs.gui_packet_list_copy_text_with_aligned_columns) { | |||
979 | hdr_parts = createHeaderPartsForAligned(); | |||
980 | align_parts = createAlignmentPartsForAligned(); | |||
981 | size_parts = createSizePartsForAligned(false, hdr_parts, rows); | |||
982 | } | |||
983 | if (prefs.gui_packet_list_copy_format_options_for_keyboard_shortcut == COPY_FORMAT_HTML) { | |||
984 | htmlContent << createDefaultStyleForHtml(); | |||
985 | htmlContent << createOpeningTagForHtml(); | |||
986 | } | |||
987 | break; | |||
988 | case COPY_FORMAT_CSV: | |||
989 | case COPY_FORMAT_YAML: | |||
990 | break; | |||
991 | } | |||
992 | ||||
993 | QList<QStringList> entries; | |||
994 | foreach(int row, rows)for (auto _container_994 = QtPrivate::qMakeForeachContainer(rows ); _container_994.i != _container_994.e; ++_container_994.i) if (int row = *_container_994.i; false) {} else | |||
995 | { | |||
996 | QModelIndex idx = model()->index(row, 0); | |||
997 | if (! idx.isValid()) | |||
998 | continue; | |||
999 | ||||
1000 | switch (prefs.gui_packet_list_copy_format_options_for_keyboard_shortcut) { | |||
1001 | case COPY_FORMAT_TEXT: | |||
1002 | case COPY_FORMAT_HTML: | |||
1003 | if (prefs.gui_packet_list_copy_text_with_aligned_columns) | |||
1004 | content << createSummaryForAligned(idx, align_parts, size_parts); | |||
1005 | else | |||
1006 | content << createSummaryText(idx, CopyAsText); | |||
1007 | if (prefs.gui_packet_list_copy_format_options_for_keyboard_shortcut == COPY_FORMAT_HTML) | |||
1008 | htmlContent << createSummaryForHtml(idx); | |||
1009 | break; | |||
1010 | case COPY_FORMAT_CSV: | |||
1011 | content << createSummaryText(idx, CopyAsCSV); | |||
1012 | break; | |||
1013 | case COPY_FORMAT_YAML: | |||
1014 | content << createSummaryText(idx, CopyAsYAML); | |||
1015 | break; | |||
1016 | } | |||
1017 | } | |||
1018 | } | |||
1019 | ||||
1020 | if (prefs.gui_packet_list_copy_format_options_for_keyboard_shortcut == COPY_FORMAT_HTML) { | |||
1021 | // htmlContent will never be empty as they will always have style and table tags | |||
1022 | QMimeData *mimeData = new QMimeData; | |||
1023 | htmlContent << createClosingTagForHtml(); | |||
1024 | mimeData->setHtml(htmlContent.join('\n')); | |||
1025 | mimeData->setText(content.join('\n').append("\n")); | |||
1026 | mainApp->clipboard()->setMimeData(mimeData, QClipboard::Clipboard); | |||
1027 | } | |||
1028 | else { | |||
1029 | if (content.count() > 0) { | |||
1030 | QString copy_text; | |||
1031 | if (prefs.gui_packet_list_copy_format_options_for_keyboard_shortcut == COPY_FORMAT_YAML) { | |||
1032 | copy_text = content.join(""); | |||
1033 | } | |||
1034 | else { | |||
1035 | copy_text = content.join("\n"); | |||
1036 | copy_text += "\n"; | |||
1037 | } | |||
1038 | mainApp->clipboard()->setText(copy_text); | |||
1039 | } | |||
1040 | } | |||
1041 | } | |||
1042 | } | |||
1043 | ||||
1044 | void PacketList::resizeEvent(QResizeEvent *event) | |||
1045 | { | |||
1046 | create_near_overlay_ = true; | |||
1047 | create_far_overlay_ = true; | |||
1048 | QTreeView::resizeEvent(event); | |||
1049 | } | |||
1050 | ||||
1051 | void PacketList::setColumnVisibility() | |||
1052 | { | |||
1053 | set_column_visibility_ = true; | |||
1054 | for (int i = 0; i < prefs.num_cols; i++) { | |||
1055 | setColumnHidden(i, get_column_visible(i) ? false : true); | |||
1056 | } | |||
1057 | set_column_visibility_ = false; | |||
1058 | } | |||
1059 | ||||
1060 | int PacketList::sizeHintForColumn(int column) const | |||
1061 | { | |||
1062 | int size_hint = 0; | |||
1063 | ||||
1064 | // This is a bit hacky but Qt does a fine job of column sizing and | |||
1065 | // reimplementing QTreeView::sizeHintForColumn seems like a worse idea. | |||
1066 | if (itemDelegateForColumn(column)) { | |||
1067 | QStyleOptionViewItem option; | |||
1068 | #if QT_VERSION((6<<16)|(4<<8)|(2)) >= QT_VERSION_CHECK(6, 0, 0)((6<<16)|(0<<8)|(0)) | |||
1069 | initViewItemOption(&option); | |||
1070 | #else | |||
1071 | option = viewOptions(); | |||
1072 | #endif | |||
1073 | // In my (gcc) testing this results in correct behavior on Windows but adds extra space | |||
1074 | // on macOS and Linux. We might want to add Q_OS_... #ifdefs accordingly. | |||
1075 | size_hint = itemDelegateForColumn(column)->sizeHint(option, QModelIndex()).width(); | |||
1076 | } | |||
1077 | size_hint += QTreeView::sizeHintForColumn(column); // Decoration padding | |||
1078 | return size_hint; | |||
1079 | } | |||
1080 | ||||
1081 | void PacketList::setRecentColumnWidth(int col) | |||
1082 | { | |||
1083 | int col_width = recent_get_column_width(col); | |||
1084 | ||||
1085 | if (col_width < 1) { | |||
1086 | int fmt = get_column_format(col); | |||
1087 | const char *long_str = get_column_width_string(fmt, col); | |||
1088 | ||||
1089 | QFontMetrics fm = QFontMetrics(mainApp->monospaceFont()); | |||
1090 | if (long_str) { | |||
1091 | col_width = fm.horizontalAdvance(long_str); | |||
1092 | } else { | |||
1093 | col_width = fm.horizontalAdvance(MIN_COL_WIDTH_STR"MMMMMM"); | |||
1094 | } | |||
1095 | // Custom delegate padding | |||
1096 | if (itemDelegateForColumn(col)) { | |||
1097 | QStyleOptionViewItem option; | |||
1098 | #if QT_VERSION((6<<16)|(4<<8)|(2)) >= QT_VERSION_CHECK(6, 0, 0)((6<<16)|(0<<8)|(0)) | |||
1099 | initViewItemOption(&option); | |||
1100 | #else | |||
1101 | option = viewOptions(); | |||
1102 | #endif | |||
1103 | col_width += itemDelegateForColumn(col)->sizeHint(option, QModelIndex()).width(); | |||
1104 | } | |||
1105 | } | |||
1106 | ||||
1107 | setColumnWidth(col, col_width); | |||
1108 | } | |||
1109 | ||||
1110 | void PacketList::drawCurrentPacket() | |||
1111 | { | |||
1112 | // XXX - Update for multi-select? If more than one packet is Selected, | |||
1113 | // this changes it so that only the Current packet is Selected. | |||
1114 | QModelIndex current_index = currentIndex(); | |||
1115 | if (selectionModel() && current_index.isValid()) { | |||
1116 | selectionModel()->clearSelection(); | |||
1117 | selectionModel()->setCurrentIndex(current_index, QItemSelectionModel::SelectCurrent | QItemSelectionModel::Rows); | |||
1118 | } | |||
1119 | } | |||
1120 | ||||
1121 | // Redraw the packet list and detail. Re-selects the current packet (causes | |||
1122 | // the UI to scroll to that packet). | |||
1123 | // Called from many places. | |||
1124 | void PacketList::redrawVisiblePackets() { | |||
1125 | redrawVisiblePacketsDontSelectCurrent(); | |||
1126 | drawCurrentPacket(); | |||
1127 | } | |||
1128 | ||||
1129 | // Redraw the packet list and detail. | |||
1130 | // Does not scroll back to the selected packet. | |||
1131 | void PacketList::redrawVisiblePacketsDontSelectCurrent() { | |||
1132 | packet_list_model_->invalidateAllColumnStrings(); | |||
1133 | } | |||
1134 | ||||
1135 | void PacketList::resetColumns() | |||
1136 | { | |||
1137 | packet_list_model_->resetColumns(); | |||
1138 | } | |||
1139 | ||||
1140 | // Return true if we have a visible packet further along in the history. | |||
1141 | bool PacketList::haveNextHistory(bool update_cur) | |||
1142 | { | |||
1143 | if (selection_history_.size() < 1 || cur_history_ >= selection_history_.size() - 1) { | |||
1144 | return false; | |||
1145 | } | |||
1146 | ||||
1147 | for (int i = cur_history_ + 1; i < selection_history_.size(); i++) { | |||
1148 | if (packet_list_model_->packetNumberToRow(selection_history_.at(i)) >= 0) { | |||
1149 | if (update_cur) { | |||
1150 | cur_history_ = i; | |||
1151 | } | |||
1152 | return true; | |||
1153 | } | |||
1154 | } | |||
1155 | return false; | |||
1156 | } | |||
1157 | ||||
1158 | // Return true if we have a visible packet back in the history. | |||
1159 | bool PacketList::havePreviousHistory(bool update_cur) | |||
1160 | { | |||
1161 | if (selection_history_.size() < 1 || cur_history_ < 1) { | |||
1162 | return false; | |||
1163 | } | |||
1164 | ||||
1165 | for (int i = cur_history_ - 1; i >= 0; i--) { | |||
1166 | if (packet_list_model_->packetNumberToRow(selection_history_.at(i)) >= 0) { | |||
1167 | if (update_cur) { | |||
1168 | cur_history_ = i; | |||
1169 | } | |||
1170 | return true; | |||
1171 | } | |||
1172 | } | |||
1173 | return false; | |||
1174 | } | |||
1175 | ||||
1176 | void PacketList::setProfileSwitcher(ProfileSwitcher *profile_switcher) | |||
1177 | { | |||
1178 | profile_switcher_ = profile_switcher; | |||
1179 | if (profile_switcher) { | |||
1180 | connect(packet_list_model_, &PacketListModel::packetAppended, profile_switcher_, &ProfileSwitcher::checkPacket); | |||
1181 | } | |||
1182 | } | |||
1183 | ||||
1184 | frame_data *PacketList::getFDataForRow(int row) const | |||
1185 | { | |||
1186 | return packet_list_model_->getRowFdata(row); | |||
1187 | } | |||
1188 | ||||
1189 | // prefs.col_list has changed. | |||
1190 | void PacketList::columnsChanged() | |||
1191 | { | |||
1192 | columns_changed_ = true; | |||
1193 | column_register_fields(); | |||
1194 | mainApp->emitAppSignal(MainApplication::FieldsChanged); | |||
1195 | if (!cap_file_) { | |||
1196 | // Keep columns_changed_ = true until we load a capture file. | |||
1197 | return; | |||
1198 | } | |||
1199 | ||||
1200 | prefs.num_cols = g_list_length(prefs.col_list); | |||
1201 | col_cleanup(&cap_file_->cinfo); | |||
1202 | build_column_format_array(&cap_file_->cinfo, prefs.num_cols, false); | |||
1203 | create_far_overlay_ = true; | |||
1204 | resetColumns(); | |||
1205 | applyRecentColumnWidths(); | |||
1206 | setColumnVisibility(); | |||
1207 | columns_changed_ = false; | |||
1208 | } | |||
1209 | ||||
1210 | // Fields have changed, update custom columns | |||
1211 | void PacketList::fieldsChanged(capture_file *cf) | |||
1212 | { | |||
1213 | prefs.num_cols = g_list_length(prefs.col_list); | |||
1214 | col_cleanup(&cf->cinfo); | |||
1215 | build_column_format_array(&cf->cinfo, prefs.num_cols, false); | |||
1216 | resetColumns(); | |||
1217 | } | |||
1218 | ||||
1219 | // Column widths should | |||
1220 | // - Load from recent when we load a new profile (including at starting up). | |||
1221 | // - Reapply when changing columns. | |||
1222 | // - Persist across freezes and thaws. | |||
1223 | // - Persist across file closing and opening. | |||
1224 | // - Save to recent when we save our profile (including shutting down). | |||
1225 | // - Not be affected by the behavior of stretchLastSection. (XXX: We | |||
1226 | // still save the stretched value to recent, sectionResized doesn't | |||
1227 | // distinguish between a resize from being stretched and a manual change.) | |||
1228 | void PacketList::applyRecentColumnWidths() | |||
1229 | { | |||
1230 | // Either we've just started up or a profile has changed. Read | |||
1231 | // the recent settings, apply them, and save the header state. | |||
1232 | ||||
1233 | for (int col = 0; col < prefs.num_cols; col++) { | |||
1234 | // The column must be shown before setting column width. | |||
1235 | // Visibility will be updated in setColumnVisibility(). | |||
1236 | setColumnHidden(col, false); | |||
1237 | setRecentColumnWidth(col); | |||
1238 | } | |||
1239 | ||||
1240 | column_state_ = header()->saveState(); | |||
1241 | } | |||
1242 | ||||
1243 | void PacketList::preferencesChanged() | |||
1244 | { | |||
1245 | // Related packet delegate | |||
1246 | if (prefs.gui_packet_list_show_related) { | |||
1247 | setItemDelegateForColumn(0, &related_packet_delegate_); | |||
1248 | } else { | |||
1249 | setItemDelegateForColumn(0, 0); | |||
1250 | } | |||
1251 | ||||
1252 | // Intelligent scroll bar (minimap) | |||
1253 | if (prefs.gui_packet_list_show_minimap) { | |||
1254 | if (overlay_timer_id_ == 0) { | |||
1255 | overlay_timer_id_ = startTimer(overlay_update_interval_); | |||
1256 | } | |||
1257 | } else { | |||
1258 | if (overlay_timer_id_ != 0) { | |||
1259 | killTimer(overlay_timer_id_); | |||
1260 | overlay_timer_id_ = 0; | |||
1261 | } | |||
1262 | } | |||
1263 | ||||
1264 | // Elide mode. | |||
1265 | // This sets the mode for the entire view. If we want to make this setting | |||
1266 | // per-column we'll either have to generalize RelatedPacketDelegate so that | |||
1267 | // we can set it for entire rows or create another delegate. | |||
1268 | Qt::TextElideMode elide_mode = Qt::ElideRight; | |||
1269 | switch (prefs.gui_packet_list_elide_mode) { | |||
1270 | case ELIDE_LEFT: | |||
1271 | elide_mode = Qt::ElideLeft; | |||
1272 | break; | |||
1273 | case ELIDE_MIDDLE: | |||
1274 | elide_mode = Qt::ElideMiddle; | |||
1275 | break; | |||
1276 | case ELIDE_NONE: | |||
1277 | elide_mode = Qt::ElideNone; | |||
1278 | break; | |||
1279 | default: | |||
1280 | break; | |||
1281 | } | |||
1282 | setTextElideMode(elide_mode); | |||
1283 | } | |||
1284 | ||||
1285 | void PacketList::freezePacketList(bool changing_profile) | |||
1286 | { | |||
1287 | changing_profile_ = changing_profile; | |||
1288 | freeze(true); | |||
1289 | } | |||
1290 | ||||
1291 | void PacketList::recolorPackets() | |||
1292 | { | |||
1293 | packet_list_model_->resetColorized(); | |||
1294 | redrawVisiblePackets(); | |||
1295 | } | |||
1296 | ||||
1297 | // Enable autoscroll. | |||
1298 | void PacketList::setVerticalAutoScroll(bool enabled) | |||
1299 | { | |||
1300 | tail_at_end_ = enabled; | |||
1301 | if (enabled && capture_in_progress_) { | |||
1302 | scrollToBottom(); | |||
1303 | } | |||
1304 | } | |||
1305 | ||||
1306 | // Called when we finish reading, reloading, rescanning, and retapping | |||
1307 | // packets. | |||
1308 | void PacketList::captureFileReadFinished() | |||
1309 | { | |||
1310 | packet_list_model_->flushVisibleRows(); | |||
1311 | packet_list_model_->dissectIdle(true); | |||
1312 | // Invalidating the column strings picks up and request/response | |||
1313 | // tracking changes. We might just want to call it from flushVisibleRows. | |||
1314 | packet_list_model_->invalidateAllColumnStrings(); | |||
1315 | // Sort *after* invalidating the column strings | |||
1316 | if (isSortingEnabled()) { | |||
1317 | sortByColumn(header()->sortIndicatorSection(), header()->sortIndicatorOrder()); | |||
1318 | } | |||
1319 | } | |||
1320 | ||||
1321 | bool PacketList::freeze(bool keep_current_frame) | |||
1322 | { | |||
1323 | if (!cap_file_ || model() == Q_NULLPTRnullptr) { | |||
1324 | // No capture file or already frozen | |||
1325 | return false; | |||
1326 | } | |||
1327 | ||||
1328 | frame_data *current_frame = cap_file_->current_frame; | |||
1329 | column_state_ = header()->saveState(); | |||
1330 | setHeaderHidden(true); | |||
1331 | frozen_current_row_ = currentIndex(); | |||
1332 | frozen_selected_rows_ = selectionModel()->selectedRows(); | |||
1333 | selectionModel()->clear(); | |||
1334 | setModel(Q_NULLPTRnullptr); | |||
1335 | // It looks like GTK+ sends a cursor-changed signal at this point but Qt doesn't | |||
1336 | // call selectionChanged. | |||
1337 | related_packet_delegate_.clear(); | |||
1338 | ||||
1339 | if (keep_current_frame) { | |||
1340 | cap_file_->current_frame = current_frame; | |||
1341 | } | |||
1342 | ||||
1343 | /* Clears packet list as well as byteview */ | |||
1344 | emit framesSelected(QList<int>()); | |||
1345 | ||||
1346 | return true; | |||
1347 | } | |||
1348 | ||||
1349 | bool PacketList::thaw(bool restore_selection) | |||
1350 | { | |||
1351 | if (!cap_file_ || model() != Q_NULLPTRnullptr) { | |||
1352 | // No capture file or not frozen | |||
1353 | return false; | |||
1354 | } | |||
1355 | ||||
1356 | setHeaderHidden(false); | |||
1357 | // Note that if we have a current sort status set in the header, | |||
1358 | // this will automatically try to sort the model (we don't want | |||
1359 | // that to happen if we're in the middle of reading the file). | |||
1360 | setModel(packet_list_model_); | |||
1361 | ||||
1362 | if (changing_profile_) { | |||
1363 | // When changing profile the new recent settings must be applied to the columns. | |||
1364 | applyRecentColumnWidths(); | |||
1365 | setColumnVisibility(); | |||
1366 | changing_profile_ = false; | |||
1367 | } else { | |||
1368 | // Resetting the model resets our column widths so we restore them here. | |||
1369 | // We don't reapply the recent settings because the user could have | |||
1370 | // resized the columns manually since they were initially loaded. | |||
1371 | header()->restoreState(column_state_); | |||
1372 | } | |||
1373 | ||||
1374 | if (restore_selection && frozen_selected_rows_.length() > 0 && selectionModel()) { | |||
1375 | /* This updates our selection, which redissects the current packet, | |||
1376 | * which is needed when we're called from MainWindow::layoutPanes. | |||
1377 | * Also, this resets all ProtoTree and ByteView data */ | |||
1378 | clearSelection(); | |||
1379 | setCurrentIndex(frozen_current_row_); | |||
1380 | foreach (QModelIndex idx, frozen_selected_rows_)for (auto _container_1380 = QtPrivate::qMakeForeachContainer( frozen_selected_rows_); _container_1380.i != _container_1380. e; ++_container_1380.i) if (QModelIndex idx = *_container_1380 .i; false) {} else { | |||
1381 | selectionModel()->select(idx, QItemSelectionModel::Select | QItemSelectionModel::Rows); | |||
1382 | } | |||
1383 | scrollTo(currentIndex(), PositionAtCenter); | |||
1384 | } | |||
1385 | frozen_current_row_ = QModelIndex(); | |||
1386 | frozen_selected_rows_ = QModelIndexList(); | |||
1387 | ||||
1388 | return true; | |||
1389 | } | |||
1390 | ||||
1391 | void PacketList::clear() { | |||
1392 | related_packet_delegate_.clear(); | |||
1393 | selectionModel()->clear(); | |||
1394 | packet_list_model_->clear(); | |||
1395 | proto_tree_->clear(); | |||
1396 | selection_history_.clear(); | |||
1397 | cur_history_ = -1; | |||
1398 | in_history_ = false; | |||
1399 | ||||
1400 | QImage overlay; | |||
1401 | overlay_sb_->setNearOverlayImage(overlay); | |||
1402 | overlay_sb_->setMarkedPacketImage(overlay); | |||
1403 | create_near_overlay_ = true; | |||
1404 | create_far_overlay_ = true; | |||
1405 | } | |||
1406 | ||||
1407 | void PacketList::writeRecent(FILE *rf) { | |||
1408 | int col, width, col_fmt; | |||
1409 | char xalign; | |||
1410 | ||||
1411 | fprintf (rf, "%s:\n", RECENT_KEY_COL_WIDTH"column.width"); | |||
1412 | for (col = 0; col < prefs.num_cols; col++) { | |||
1413 | if (col > 0) { | |||
1414 | fprintf (rf, ",\n"); | |||
1415 | } | |||
1416 | col_fmt = get_column_format(col); | |||
1417 | if (col_fmt == COL_CUSTOM) { | |||
1418 | fprintf (rf, " \"%%Cus:%s\",", get_column_custom_fields(col)); | |||
1419 | } else { | |||
1420 | fprintf (rf, " %s,", col_format_to_string(col_fmt)); | |||
1421 | } | |||
1422 | width = recent_get_column_width (col); | |||
1423 | xalign = recent_get_column_xalign (col); | |||
1424 | fprintf (rf, " %d", width); | |||
1425 | if (xalign != COLUMN_XALIGN_DEFAULT0) { | |||
1426 | fprintf (rf, ":%c", xalign); | |||
1427 | } | |||
1428 | } | |||
1429 | fprintf (rf, "\n"); | |||
1430 | } | |||
1431 | ||||
1432 | bool PacketList::contextMenuActive() | |||
1433 | { | |||
1434 | return ctx_column_ >= 0 ? true : false; | |||
1435 | } | |||
1436 | ||||
1437 | QString PacketList::getFilterFromRowAndColumn(QModelIndex idx) | |||
1438 | { | |||
1439 | frame_data *fdata; | |||
1440 | QString filter; | |||
1441 | ||||
1442 | if (! idx.isValid()) | |||
1443 | return filter; | |||
1444 | ||||
1445 | int row = idx.row(); | |||
1446 | int column = idx.column(); | |||
1447 | ||||
1448 | if (!cap_file_ || !packet_list_model_ || column < 0 || column >= cap_file_->cinfo.num_cols) | |||
1449 | return filter; | |||
1450 | ||||
1451 | fdata = packet_list_model_->getRowFdata(row); | |||
1452 | ||||
1453 | if (fdata != NULL__null) { | |||
1454 | epan_dissect_t edt; | |||
1455 | wtap_rec rec; /* Record metadata */ | |||
1456 | Buffer buf; /* Record data */ | |||
1457 | ||||
1458 | wtap_rec_init(&rec); | |||
1459 | ws_buffer_init(&buf, 1514); | |||
1460 | if (!cf_read_record(cap_file_, fdata, &rec, &buf)) { | |||
1461 | wtap_rec_cleanup(&rec); | |||
1462 | ws_buffer_free(&buf); | |||
1463 | return filter; /* error reading the record */ | |||
1464 | } | |||
1465 | /* proto tree, visible. We need a proto tree if there's custom columns */ | |||
1466 | epan_dissect_init(&edt, cap_file_->epan, have_custom_cols(&cap_file_->cinfo), false); | |||
1467 | col_custom_prime_edt(&edt, &cap_file_->cinfo); | |||
1468 | ||||
1469 | epan_dissect_run(&edt, cap_file_->cd_t, &rec, | |||
1470 | ws_buffer_start_ptr(&buf)((&buf)->data + (&buf)->start), | |||
1471 | fdata, &cap_file_->cinfo); | |||
1472 | ||||
1473 | if (cap_file_->cinfo.columns[column].col_fmt == COL_CUSTOM) { | |||
1474 | filter.append(gchar_free_to_qstring(col_custom_get_filter(&edt, &cap_file_->cinfo, column))); | |||
1475 | } else { | |||
1476 | /* We don't need to fill in the custom columns, as we get their | |||
1477 | * filters above. | |||
1478 | */ | |||
1479 | col_fill_in(&edt.pi, true, true); | |||
1480 | if (strlen(cap_file_->cinfo.col_expr.col_expr[column]) != 0 && | |||
1481 | strlen(cap_file_->cinfo.col_expr.col_expr_val[column]) != 0) { | |||
1482 | bool is_string_value = false; | |||
1483 | header_field_info *hfi = proto_registrar_get_byname(cap_file_->cinfo.col_expr.col_expr[column]); | |||
1484 | 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 )) { | |||
1485 | /* Could be an address type such as usb.src which must be quoted. */ | |||
1486 | is_string_value = true; | |||
1487 | } | |||
1488 | ||||
1489 | if (filter.isEmpty()) { | |||
1490 | if (is_string_value) { | |||
1491 | filter.append(QStringLiteral("%1 == \"%2\"")(QString(QtPrivate::qMakeStringPrivate(u"" "%1 == \"%2\""))) | |||
1492 | .arg(cap_file_->cinfo.col_expr.col_expr[column]) | |||
1493 | .arg(cap_file_->cinfo.col_expr.col_expr_val[column])); | |||
1494 | } else { | |||
1495 | filter.append(QStringLiteral("%1 == %2")(QString(QtPrivate::qMakeStringPrivate(u"" "%1 == %2"))) | |||
1496 | .arg(cap_file_->cinfo.col_expr.col_expr[column]) | |||
1497 | .arg(cap_file_->cinfo.col_expr.col_expr_val[column])); | |||
1498 | } | |||
1499 | } | |||
1500 | } | |||
1501 | } | |||
1502 | ||||
1503 | epan_dissect_cleanup(&edt); | |||
1504 | wtap_rec_cleanup(&rec); | |||
1505 | ws_buffer_free(&buf); | |||
1506 | } | |||
1507 | ||||
1508 | return filter; | |||
1509 | } | |||
1510 | ||||
1511 | void PacketList::resetColorized() | |||
1512 | { | |||
1513 | packet_list_model_->resetColorized(); | |||
1514 | update(); | |||
1515 | } | |||
1516 | ||||
1517 | QString PacketList::getPacketComment(unsigned c_number) | |||
1518 | { | |||
1519 | int row = currentIndex().row(); | |||
1520 | const frame_data *fdata; | |||
1521 | char *pkt_comment; | |||
1522 | wtap_opttype_return_val result; | |||
1523 | QString ret_val = NULL__null; | |||
1524 | ||||
1525 | if (!cap_file_ || !packet_list_model_) return NULL__null; | |||
1526 | ||||
1527 | fdata = packet_list_model_->getRowFdata(row); | |||
1528 | ||||
1529 | if (!fdata) return NULL__null; | |||
1530 | ||||
1531 | wtap_block_t pkt_block = cf_get_packet_block(cap_file_, fdata); | |||
1532 | result = wtap_block_get_nth_string_option_value(pkt_block, OPT_COMMENT1, c_number, &pkt_comment); | |||
1533 | if (result == WTAP_OPTTYPE_SUCCESS) { | |||
1534 | ret_val = QString(pkt_comment); | |||
1535 | } | |||
1536 | wtap_block_unref(pkt_block); | |||
1537 | return ret_val; | |||
1538 | } | |||
1539 | ||||
1540 | void PacketList::addPacketComment(QString new_comment) | |||
1541 | { | |||
1542 | if (!cap_file_ || !packet_list_model_) return; | |||
1543 | if (new_comment.isEmpty()) return; | |||
1544 | ||||
1545 | QByteArray ba = new_comment.toUtf8(); | |||
1546 | ||||
1547 | /* | |||
1548 | * Make sure this would fit in a pcapng option. | |||
1549 | * | |||
1550 | * XXX - 65535 is the maximum size for an option in pcapng; | |||
1551 | * what if another capture file format supports larger | |||
1552 | * comments? | |||
1553 | */ | |||
1554 | if (ba.size() > 65535) { | |||
1555 | simple_dialog(ESD_TYPE_ERROR, ESD_BTN_OK0x01, | |||
1556 | "That comment is too large to save in a capture file."); | |||
1557 | return; | |||
1558 | } | |||
1559 | ||||
1560 | if (selectionModel() && selectionModel()->hasSelection()) { | |||
1561 | packet_list_model_->addFrameComment(selectionModel()->selectedRows(), ba); | |||
1562 | drawCurrentPacket(); | |||
1563 | } | |||
1564 | } | |||
1565 | ||||
1566 | void PacketList::setPacketComment(unsigned c_number, QString new_comment) | |||
1567 | { | |||
1568 | QModelIndex curIndex = currentIndex(); | |||
1569 | ||||
1570 | if (!cap_file_ || !packet_list_model_) return; | |||
1571 | ||||
1572 | QByteArray ba = new_comment.toUtf8(); | |||
1573 | /* | |||
1574 | * Make sure this would fit in a pcapng option. | |||
1575 | * | |||
1576 | * XXX - 65535 is the maximum size for an option in pcapng; | |||
1577 | * what if another capture file format supports larger | |||
1578 | * comments? | |||
1579 | */ | |||
1580 | if (ba.size() > 65535) { | |||
1581 | simple_dialog(ESD_TYPE_ERROR, ESD_BTN_OK0x01, | |||
1582 | "That comment is too large to save in a capture file."); | |||
1583 | return; | |||
1584 | } | |||
1585 | ||||
1586 | packet_list_model_->setFrameComment(curIndex, ba, c_number); | |||
1587 | drawCurrentPacket(); | |||
1588 | } | |||
1589 | ||||
1590 | QString PacketList::allPacketComments() | |||
1591 | { | |||
1592 | uint32_t framenum; | |||
1593 | frame_data *fdata; | |||
1594 | QString buf_str; | |||
1595 | ||||
1596 | if (!cap_file_) return buf_str; | |||
1597 | ||||
1598 | for (framenum = 1; framenum <= cap_file_->count ; framenum++) { | |||
1599 | fdata = frame_data_sequence_find(cap_file_->provider.frames, framenum); | |||
1600 | ||||
1601 | wtap_block_t pkt_block = cf_get_packet_block(cap_file_, fdata); | |||
1602 | ||||
1603 | if (pkt_block) { | |||
1604 | unsigned n_comments = wtap_block_count_option(pkt_block, OPT_COMMENT1); | |||
1605 | for (unsigned i = 0; i < n_comments; i++) { | |||
1606 | char *comment_text; | |||
1607 | if (WTAP_OPTTYPE_SUCCESS == wtap_block_get_nth_string_option_value(pkt_block, OPT_COMMENT1, i, &comment_text)) { | |||
1608 | buf_str.append(tr("Frame %1: %2\n\n").arg(framenum).arg(comment_text)); | |||
1609 | if (buf_str.length() > max_comments_to_fetch_) { | |||
1610 | buf_str.append(tr("[ Comment text exceeds %1. Stopping. ]") | |||
1611 | .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)))); | |||
1612 | return buf_str; | |||
1613 | } | |||
1614 | } | |||
1615 | } | |||
1616 | } | |||
1617 | } | |||
1618 | return buf_str; | |||
1619 | } | |||
1620 | ||||
1621 | void PacketList::deleteCommentsFromPackets() | |||
1622 | { | |||
1623 | if (!cap_file_ || !packet_list_model_) return; | |||
1624 | ||||
1625 | if (selectionModel() && selectionModel()->hasSelection()) { | |||
1626 | packet_list_model_->deleteFrameComments(selectionModel()->selectedRows()); | |||
1627 | drawCurrentPacket(); | |||
1628 | } | |||
1629 | } | |||
1630 | ||||
1631 | void PacketList::deleteAllPacketComments() | |||
1632 | { | |||
1633 | if (!cap_file_ || !packet_list_model_) return; | |||
1634 | ||||
1635 | packet_list_model_->deleteAllFrameComments(); | |||
1636 | drawCurrentPacket(); | |||
1637 | } | |||
1638 | ||||
1639 | ||||
1640 | // Slots | |||
1641 | ||||
1642 | void PacketList::setCaptureFile(capture_file *cf) | |||
1643 | { | |||
1644 | cap_file_ = cf; | |||
1645 | packet_list_model_->setCaptureFile(cf); | |||
1646 | if (cf) { | |||
1647 | if (columns_changed_) { | |||
1648 | columnsChanged(); | |||
1649 | } else { | |||
1650 | // Restore columns widths and visibility. | |||
1651 | header()->restoreState(column_state_); | |||
1652 | setColumnVisibility(); | |||
1653 | } | |||
1654 | } | |||
1655 | create_near_overlay_ = true; | |||
1656 | changing_profile_ = false; | |||
1657 | sortByColumn(-1, Qt::AscendingOrder); | |||
1658 | } | |||
1659 | ||||
1660 | void PacketList::setMonospaceFont(const QFont &mono_font) | |||
1661 | { | |||
1662 | setFont(mono_font); | |||
1663 | } | |||
1664 | ||||
1665 | void PacketList::setRegularFont(const QFont ®ular_font) | |||
1666 | { | |||
1667 | header()->setFont(regular_font); | |||
1668 | header()->viewport()->setFont(regular_font); | |||
1669 | } | |||
1670 | ||||
1671 | void PacketList::goNextPacket(void) | |||
1672 | { | |||
1673 | if (QApplication::keyboardModifiers() & Qt::AltModifier) { | |||
1674 | // Alt+toolbar | |||
1675 | goNextHistoryPacket(); | |||
1676 | return; | |||
1677 | } | |||
1678 | ||||
1679 | if (selectionModel()->hasSelection()) { | |||
1680 | selectionModel()->setCurrentIndex(moveCursor(MoveDown, Qt::NoModifier), QItemSelectionModel::ClearAndSelect | QItemSelectionModel::Rows); | |||
1681 | } else { | |||
1682 | // First visible packet. | |||
1683 | selectionModel()->setCurrentIndex(indexAt(viewport()->rect().topLeft()), QItemSelectionModel::ClearAndSelect | QItemSelectionModel::Rows); | |||
1684 | } | |||
1685 | ||||
1686 | scrollViewChanged(false); | |||
1687 | } | |||
1688 | ||||
1689 | void PacketList::goPreviousPacket(void) | |||
1690 | { | |||
1691 | if (QApplication::keyboardModifiers() & Qt::AltModifier) { | |||
1692 | // Alt+toolbar | |||
1693 | goPreviousHistoryPacket(); | |||
1694 | return; | |||
1695 | } | |||
1696 | ||||
1697 | if (selectionModel()->hasSelection()) { | |||
1698 | selectionModel()->setCurrentIndex(moveCursor(MoveUp, Qt::NoModifier), QItemSelectionModel::ClearAndSelect | QItemSelectionModel::Rows); | |||
1699 | } else { | |||
1700 | // Last visible packet. | |||
1701 | QModelIndex last_idx = indexAt(viewport()->rect().bottomLeft()); | |||
1702 | if (last_idx.isValid()) { | |||
1703 | selectionModel()->setCurrentIndex(last_idx, QItemSelectionModel::ClearAndSelect | QItemSelectionModel::Rows); | |||
1704 | } else { | |||
1705 | goLastPacket(); | |||
1706 | } | |||
1707 | } | |||
1708 | ||||
1709 | scrollViewChanged(false); | |||
1710 | } | |||
1711 | ||||
1712 | void PacketList::goFirstPacket(void) { | |||
1713 | if (packet_list_model_->rowCount() < 1) return; | |||
1714 | selectionModel()->setCurrentIndex(packet_list_model_->index(0, 0), QItemSelectionModel::ClearAndSelect | QItemSelectionModel::Rows); | |||
1715 | scrollTo(currentIndex()); | |||
1716 | ||||
1717 | scrollViewChanged(false); | |||
1718 | } | |||
1719 | ||||
1720 | void PacketList::goLastPacket(void) { | |||
1721 | if (packet_list_model_->rowCount() < 1) return; | |||
1722 | selectionModel()->setCurrentIndex(packet_list_model_->index(packet_list_model_->rowCount() - 1, 0), QItemSelectionModel::ClearAndSelect | QItemSelectionModel::Rows); | |||
1723 | scrollTo(currentIndex()); | |||
1724 | ||||
1725 | scrollViewChanged(false); | |||
1726 | } | |||
1727 | ||||
1728 | void PacketList::goToPacket(int packet, int hf_id) | |||
1729 | { | |||
1730 | if (!cf_goto_frame(cap_file_, packet, false)) | |||
1731 | return; | |||
1732 | ||||
1733 | // cf_goto_frame only returns true if packet_list_select_row_from_data | |||
1734 | // succeeds, the latter has already selected and scrolled to the frame. | |||
1735 | if (hf_id > 0) { | |||
1736 | proto_tree_->goToHfid(hf_id); | |||
1737 | } | |||
1738 | ||||
1739 | scrollViewChanged(false); | |||
1740 | } | |||
1741 | ||||
1742 | void PacketList::goNextHistoryPacket() | |||
1743 | { | |||
1744 | if (haveNextHistory(true)) { | |||
1745 | in_history_ = true; | |||
1746 | goToPacket(selection_history_.at(cur_history_)); | |||
1747 | in_history_ = false; | |||
1748 | } | |||
1749 | } | |||
1750 | ||||
1751 | void PacketList::goPreviousHistoryPacket() | |||
1752 | { | |||
1753 | if (havePreviousHistory(true)) { | |||
1754 | in_history_ = true; | |||
1755 | goToPacket(selection_history_.at(cur_history_)); | |||
1756 | in_history_ = false; | |||
1757 | } | |||
1758 | } | |||
1759 | ||||
1760 | void PacketList::markFrame() | |||
1761 | { | |||
1762 | if (!cap_file_ || !packet_list_model_) return; | |||
1763 | ||||
1764 | QModelIndexList frames; | |||
1765 | ||||
1766 | if (selectionModel() && selectionModel()->hasSelection()) | |||
1767 | { | |||
1768 | QModelIndexList selRows = selectionModel()->selectedRows(0); | |||
1769 | foreach (QModelIndex idx, selRows)for (auto _container_1769 = QtPrivate::qMakeForeachContainer( selRows); _container_1769.i != _container_1769.e; ++_container_1769 .i) if (QModelIndex idx = *_container_1769.i; false) {} else | |||
1770 | { | |||
1771 | if (idx.isValid()) | |||
1772 | { | |||
1773 | frames << idx; | |||
1774 | } | |||
1775 | } | |||
1776 | } | |||
1777 | else | |||
1778 | frames << currentIndex(); | |||
1779 | ||||
1780 | packet_list_model_->toggleFrameMark(frames); | |||
1781 | ||||
1782 | // Make sure the packet list's frame.marked related field text is updated. | |||
1783 | redrawVisiblePackets(); | |||
1784 | ||||
1785 | create_far_overlay_ = true; | |||
1786 | packets_bar_update(); | |||
1787 | } | |||
1788 | ||||
1789 | void PacketList::markAllDisplayedFrames(bool set) | |||
1790 | { | |||
1791 | if (!cap_file_ || !packet_list_model_) return; | |||
1792 | ||||
1793 | packet_list_model_->setDisplayedFrameMark(set); | |||
1794 | ||||
1795 | // Make sure the packet list's frame.marked related field text is updated. | |||
1796 | redrawVisiblePackets(); | |||
1797 | ||||
1798 | create_far_overlay_ = true; | |||
1799 | packets_bar_update(); | |||
1800 | } | |||
1801 | ||||
1802 | void PacketList::ignoreFrame() | |||
1803 | { | |||
1804 | if (!cap_file_ || !packet_list_model_) return; | |||
1805 | ||||
1806 | QModelIndexList frames; | |||
1807 | ||||
1808 | if (selectionModel() && selectionModel()->hasSelection()) | |||
1809 | { | |||
1810 | foreach (QModelIndex idx, selectionModel()->selectedRows(0))for (auto _container_1810 = QtPrivate::qMakeForeachContainer( selectionModel()->selectedRows(0)); _container_1810.i != _container_1810 .e; ++_container_1810.i) if (QModelIndex idx = *_container_1810 .i; false) {} else | |||
1811 | { | |||
1812 | if (idx.isValid()) | |||
1813 | { | |||
1814 | frames << idx; | |||
1815 | } | |||
1816 | } | |||
1817 | } | |||
1818 | else | |||
1819 | frames << currentIndex(); | |||
1820 | ||||
1821 | ||||
1822 | packet_list_model_->toggleFrameIgnore(frames); | |||
1823 | create_far_overlay_ = true; | |||
1824 | int sb_val = verticalScrollBar()->value(); // Surely there's a better way to keep our position? | |||
1825 | setUpdatesEnabled(false); | |||
1826 | emit packetDissectionChanged(); | |||
1827 | setUpdatesEnabled(true); | |||
1828 | verticalScrollBar()->setValue(sb_val); | |||
1829 | } | |||
1830 | ||||
1831 | void PacketList::ignoreAllDisplayedFrames(bool set) | |||
1832 | { | |||
1833 | if (!cap_file_ || !packet_list_model_) return; | |||
1834 | ||||
1835 | packet_list_model_->setDisplayedFrameIgnore(set); | |||
1836 | create_far_overlay_ = true; | |||
1837 | emit packetDissectionChanged(); | |||
1838 | } | |||
1839 | ||||
1840 | void PacketList::setTimeReference() | |||
1841 | { | |||
1842 | if (!cap_file_ || !packet_list_model_) return; | |||
1843 | packet_list_model_->toggleFrameRefTime(currentIndex()); | |||
1844 | create_far_overlay_ = true; | |||
1845 | } | |||
1846 | ||||
1847 | void PacketList::unsetAllTimeReferences() | |||
1848 | { | |||
1849 | if (!cap_file_ || !packet_list_model_) return; | |||
1850 | packet_list_model_->unsetAllFrameRefTime(); | |||
1851 | create_far_overlay_ = true; | |||
1852 | } | |||
1853 | ||||
1854 | void PacketList::applyTimeShift() | |||
1855 | { | |||
1856 | packet_list_model_->resetColumns(); | |||
1857 | redrawVisiblePackets(); | |||
1858 | emit packetDissectionChanged(); | |||
1859 | } | |||
1860 | ||||
1861 | void PacketList::updatePackets(bool redraw) | |||
1862 | { | |||
1863 | if (redraw) { | |||
1864 | packet_list_model_->resetColumns(); | |||
1865 | redrawVisiblePackets(); | |||
1866 | } else { | |||
1867 | update(); | |||
1868 | } | |||
1869 | } | |||
1870 | ||||
1871 | void PacketList::columnVisibilityTriggered() | |||
1872 | { | |||
1873 | QAction *ha = qobject_cast<QAction*>(sender()); | |||
1874 | if (!ha) return; | |||
1875 | ||||
1876 | int col = ha->data().toInt(); | |||
1877 | set_column_visible(col, ha->isChecked()); | |||
1878 | setColumnVisibility(); | |||
1879 | if (ha->isChecked()) { | |||
1880 | setRecentColumnWidth(col); | |||
1881 | } | |||
1882 | prefs_main_write(); | |||
1883 | } | |||
1884 | ||||
1885 | void PacketList::sectionResized(int col, int, int new_width) | |||
1886 | { | |||
1887 | if (isVisible() && !columns_changed_ && !set_column_visibility_ && !set_style_sheet_ && new_width > 0) { | |||
1888 | // Column 1 gets an invalid value (32 on macOS) when we're not yet | |||
1889 | // visible. | |||
1890 | // | |||
1891 | // Don't set column width when columns changed or setting column | |||
1892 | // visibility because we may get a sectionResized() from QTreeView | |||
1893 | // with values from a old columns layout. | |||
1894 | // | |||
1895 | // Don't set column width when hiding a column. | |||
1896 | ||||
1897 | recent_set_column_width(col, new_width); | |||
1898 | } | |||
1899 | } | |||
1900 | ||||
1901 | // The user moved a column. Make sure prefs.col_list, the column format | |||
1902 | // array, and the header's visual and logical indices all agree. | |||
1903 | // gtk/packet_list.c:column_dnd_changed_cb | |||
1904 | void PacketList::sectionMoved(int logicalIndex, int oldVisualIndex, int newVisualIndex) | |||
1905 | { | |||
1906 | GList *new_col_list = NULL__null; | |||
1907 | GList *new_recent_col_list = NULL__null; | |||
1908 | QList<int> saved_sizes; | |||
1909 | int sort_idx; | |||
1910 | ||||
1911 | // Since we undo the move below, these should always stay in sync. | |||
1912 | // Otherwise the order of columns can be unexpected after drag and drop. | |||
1913 | if (logicalIndex != oldVisualIndex) { | |||
1914 | 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" , 1915, __func__, "Column moved from an unexpected state (%d, %d, %d)" , logicalIndex, oldVisualIndex, newVisualIndex); } } while (0 ) | |||
1915 | logicalIndex, oldVisualIndex, newVisualIndex)do { if (true) { ws_log_full("", LOG_LEVEL_WARNING, "ui/qt/packet_list.cpp" , 1915, __func__, "Column moved from an unexpected state (%d, %d, %d)" , logicalIndex, oldVisualIndex, newVisualIndex); } } while (0 ); | |||
1916 | } | |||
1917 | ||||
1918 | // Remember which column should be sorted. Use the visual index since this | |||
1919 | // points to the current GUI state rather than the outdated column order | |||
1920 | // (indicated by the logical index). | |||
1921 | sort_idx = header()->sortIndicatorSection(); | |||
1922 | if (sort_idx != -1) { | |||
1923 | sort_idx = header()->visualIndex(sort_idx); | |||
1924 | } | |||
1925 | ||||
1926 | // Build a new column list based on the header's logical order. | |||
1927 | for (int vis_idx = 0; vis_idx < header()->count(); vis_idx++) { | |||
1928 | int log_idx = header()->logicalIndex(vis_idx); | |||
1929 | saved_sizes << header()->sectionSize(log_idx); | |||
1930 | ||||
1931 | void *pref_data = g_list_nth_data(prefs.col_list, log_idx); | |||
1932 | if (pref_data) { | |||
1933 | new_col_list = g_list_append(new_col_list, pref_data); | |||
1934 | } | |||
1935 | ||||
1936 | pref_data = g_list_nth_data(recent.col_width_list, log_idx); | |||
1937 | if (pref_data) { | |||
1938 | new_recent_col_list = g_list_append(new_recent_col_list, pref_data); | |||
1939 | } | |||
1940 | } | |||
1941 | ||||
1942 | // Undo move to ensure that the logical indices map to the visual indices, | |||
1943 | // otherwise the column order is changed twice (once via the modified | |||
1944 | // col_list, once because of the visual/logical index mismatch). | |||
1945 | disconnect(header(), SIGNAL(sectionMoved(int,int,int))qFlagLocation("2" "sectionMoved(int,int,int)" "\0" "ui/qt/packet_list.cpp" ":" "1945"), | |||
1946 | this, SLOT(sectionMoved(int,int,int))qFlagLocation("1" "sectionMoved(int,int,int)" "\0" "ui/qt/packet_list.cpp" ":" "1946")); | |||
1947 | header()->moveSection(newVisualIndex, oldVisualIndex); | |||
1948 | connect(header(), SIGNAL(sectionMoved(int,int,int))qFlagLocation("2" "sectionMoved(int,int,int)" "\0" "ui/qt/packet_list.cpp" ":" "1948"), | |||
1949 | this, SLOT(sectionMoved(int,int,int))qFlagLocation("1" "sectionMoved(int,int,int)" "\0" "ui/qt/packet_list.cpp" ":" "1949")); | |||
1950 | ||||
1951 | // Clear and rebuild our (and the header's) model. There doesn't appear | |||
1952 | // to be another way to reset the logical index. | |||
1953 | freeze(); | |||
1954 | ||||
1955 | g_list_free(prefs.col_list); | |||
1956 | prefs.col_list = new_col_list; | |||
1957 | g_list_free(recent.col_width_list); | |||
1958 | recent.col_width_list = new_recent_col_list; | |||
1959 | ||||
1960 | thaw(true); | |||
1961 | ||||
1962 | for (int i = 0; i < saved_sizes.length(); i++) { | |||
1963 | if (saved_sizes[i] < 1) continue; | |||
1964 | header()->resizeSection(i, saved_sizes[i]); | |||
1965 | } | |||
1966 | ||||
1967 | prefs_main_write(); | |||
1968 | ||||
1969 | mainApp->emitAppSignal(MainApplication::ColumnsChanged); | |||
1970 | ||||
1971 | // If the column with the sort indicator got shifted, mark the new column | |||
1972 | // after updating the columns contents (via ColumnsChanged) to ensure that | |||
1973 | // the columns are sorted using the intended column contents. | |||
1974 | int left_col = MIN(oldVisualIndex, newVisualIndex)(((oldVisualIndex) < (newVisualIndex)) ? (oldVisualIndex) : (newVisualIndex)); | |||
1975 | int right_col = MAX(oldVisualIndex, newVisualIndex)(((oldVisualIndex) > (newVisualIndex)) ? (oldVisualIndex) : (newVisualIndex)); | |||
1976 | if (left_col <= sort_idx && sort_idx <= right_col) { | |||
1977 | header()->setSortIndicator(sort_idx, header()->sortIndicatorOrder()); | |||
1978 | } | |||
1979 | } | |||
1980 | ||||
1981 | void PacketList::updateRowHeights(const QModelIndex &ih_index) | |||
1982 | { | |||
1983 | QStyleOptionViewItem option; | |||
1984 | #if QT_VERSION((6<<16)|(4<<8)|(2)) >= QT_VERSION_CHECK(6, 0, 0)((6<<16)|(0<<8)|(0)) | |||
1985 | initViewItemOption(&option); | |||
1986 | #else | |||
1987 | option = viewOptions(); | |||
1988 | #endif | |||
1989 | int max_height = 0; | |||
1990 | ||||
1991 | // One of our columns increased the maximum row height. Find out which one. | |||
1992 | for (int col = 0; col < packet_list_model_->columnCount(); col++) { | |||
1993 | QSize size_hint = itemDelegate()->sizeHint(option, packet_list_model_->index(ih_index.row(), col)); | |||
1994 | max_height = qMax(max_height, size_hint.height()); | |||
1995 | } | |||
1996 | ||||
1997 | if (max_height > 0) { | |||
1998 | packet_list_model_->setMaximumRowHeight(max_height); | |||
1999 | } | |||
2000 | } | |||
2001 | ||||
2002 | QString PacketList::createSummaryText(QModelIndex idx, SummaryCopyType type) | |||
2003 | { | |||
2004 | if (! idx.isValid()) | |||
2005 | return ""; | |||
2006 | ||||
2007 | QStringList col_parts; | |||
2008 | int row = idx.row(); | |||
2009 | for (int col = 0; col < packet_list_model_->columnCount(); col++) { | |||
2010 | if (get_column_visible(col)) { | |||
2011 | col_parts << packet_list_model_->data(packet_list_model_->index(row, col), Qt::DisplayRole).toString(); | |||
2012 | } | |||
2013 | } | |||
2014 | return joinSummaryRow(col_parts, row, type); | |||
2015 | } | |||
2016 | ||||
2017 | QString PacketList::createHeaderSummaryText(SummaryCopyType type) | |||
2018 | { | |||
2019 | QStringList col_parts; | |||
2020 | for (int col = 0; col < packet_list_model_->columnCount(); ++col) { | |||
2021 | if (get_column_visible(col)) { | |||
2022 | col_parts << packet_list_model_->headerData(col, Qt::Orientation::Horizontal, Qt::DisplayRole).toString(); | |||
2023 | } | |||
2024 | } | |||
2025 | return joinSummaryRow(col_parts, 0, type); | |||
2026 | } | |||
2027 | ||||
2028 | QStringList PacketList::createHeaderPartsForAligned() | |||
2029 | { | |||
2030 | QStringList hdr_parts; | |||
2031 | for (int col = 0; col < packet_list_model_->columnCount(); ++col) { | |||
2032 | if (get_column_visible(col)) { | |||
2033 | hdr_parts << packet_list_model_->headerData(col, Qt::Orientation::Horizontal, Qt::DisplayRole).toString(); | |||
2034 | } | |||
2035 | } | |||
2036 | return hdr_parts; | |||
2037 | } | |||
2038 | ||||
2039 | QList<int> PacketList::createAlignmentPartsForAligned() | |||
2040 | { | |||
2041 | QList<int> align_parts; | |||
2042 | for (int col = 0; col < packet_list_model_->columnCount(); col++) { | |||
2043 | if (get_column_visible(col)) { | |||
2044 | align_parts << packet_list_model_->data(packet_list_model_->index(0, col), Qt::TextAlignmentRole).toInt(); | |||
2045 | } | |||
2046 | } | |||
2047 | return align_parts; | |||
2048 | } | |||
2049 | ||||
2050 | QList<int> PacketList::createSizePartsForAligned(bool useHeader, QStringList hdr_parts, QList<int> rows) | |||
2051 | { | |||
2052 | QList<int> size_parts; | |||
2053 | ||||
2054 | for (int i = 0; i < hdr_parts.size(); ++i) { | |||
2055 | if (useHeader) | |||
2056 | size_parts << static_cast<int>(hdr_parts.at(i).size()); | |||
2057 | else | |||
2058 | size_parts << 0; | |||
2059 | } | |||
2060 | ||||
2061 | foreach(int row, rows)for (auto _container_2061 = QtPrivate::qMakeForeachContainer( rows); _container_2061.i != _container_2061.e; ++_container_2061 .i) if (int row = *_container_2061.i; false) {} else | |||
2062 | { | |||
2063 | QModelIndex idx = model()->index(row, 0); | |||
2064 | if (! idx.isValid()) | |||
2065 | continue; | |||
2066 | ||||
2067 | QStringList col_parts; | |||
2068 | for (int col = 0; col < packet_list_model_->columnCount(); col++) { | |||
2069 | if (get_column_visible(col)) { | |||
2070 | col_parts << (packet_list_model_->data(packet_list_model_->index(row, col), Qt::DisplayRole).toString()); | |||
2071 | } | |||
2072 | } | |||
2073 | ||||
2074 | for (int i = 0; i < col_parts.size(); ++i) { | |||
2075 | if (col_parts.at(i).size() > size_parts.at(i)) { | |||
2076 | size_parts[i] = static_cast<int>(col_parts.at(i).size()); | |||
2077 | } | |||
2078 | } | |||
2079 | col_parts.clear(); | |||
2080 | } | |||
2081 | ||||
2082 | return size_parts; | |||
2083 | } | |||
2084 | ||||
2085 | QString PacketList::createHeaderSummaryForAligned(QStringList hdr_parts, QList<int> align_parts, QList<int> size_parts) | |||
2086 | { | |||
2087 | QString hdr_text; | |||
2088 | for (int i = 0; i < hdr_parts.size(); ++i) { | |||
2089 | if (align_parts.at(i) == Qt::AlignLeft) { | |||
2090 | hdr_text += hdr_parts[i].leftJustified(size_parts.at(i), ' ') + " "; | |||
2091 | } | |||
2092 | else if (align_parts.at(i) == Qt::AlignRight) { | |||
2093 | hdr_text += hdr_parts[i].rightJustified(size_parts.at(i), ' ') + " "; | |||
2094 | } | |||
2095 | } | |||
2096 | return QStringLiteral("-%1")(QString(QtPrivate::qMakeStringPrivate(u"" "-%1"))).arg(hdr_text).trimmed().mid(1); | |||
2097 | } | |||
2098 | ||||
2099 | QString PacketList::createSummaryForAligned(QModelIndex idx, QList<int> align_parts, QList<int> size_parts) | |||
2100 | { | |||
2101 | if (! idx.isValid()) | |||
2102 | return ""; | |||
2103 | ||||
2104 | QStringList col_parts; | |||
2105 | int row = idx.row(); | |||
2106 | for (int col = 0; col < packet_list_model_->columnCount(); col++) { | |||
2107 | if (get_column_visible(col)) { | |||
2108 | col_parts << packet_list_model_->data(packet_list_model_->index(row, col), Qt::DisplayRole).toString(); | |||
2109 | } | |||
2110 | } | |||
2111 | ||||
2112 | QString col_text; | |||
2113 | for (int i = 0; i < col_parts.size(); ++i) { | |||
2114 | if (align_parts.at(i) == Qt::AlignLeft) { | |||
2115 | col_text += col_parts[i].leftJustified(size_parts.at(i), ' ') + " "; | |||
2116 | } | |||
2117 | else if (align_parts.at(i) == Qt::AlignRight) { | |||
2118 | col_text += col_parts[i].rightJustified(size_parts.at(i), ' ') + " "; | |||
2119 | } | |||
2120 | } | |||
2121 | ||||
2122 | return QStringLiteral("-%1")(QString(QtPrivate::qMakeStringPrivate(u"" "-%1"))).arg(col_text).trimmed().mid(1); | |||
2123 | } | |||
2124 | ||||
2125 | QString PacketList::createDefaultStyleForHtml() | |||
2126 | { | |||
2127 | QString style_text; | |||
2128 | style_text = "<style>"; | |||
2129 | QString fontFamily = QString(prefs.gui_font_name).split(",")[0]; | |||
2130 | QString fontSize = QString(prefs.gui_font_name).split(",")[1]; | |||
2131 | style_text += "table{font-family:" + fontFamily + ";font-size:" + fontSize + "pt;}"; | |||
2132 | style_text += "th{background-color:#000000;color:#ffffff;text-align:left;}"; | |||
2133 | style_text += "th,td{padding:" + QString::number(fontSize.toInt() / 2) + "pt}"; | |||
2134 | style_text += "</style>"; | |||
2135 | return style_text; | |||
2136 | } | |||
2137 | ||||
2138 | QString PacketList::createOpeningTagForHtml() | |||
2139 | { | |||
2140 | return "<table>"; | |||
2141 | } | |||
2142 | ||||
2143 | QString PacketList::createHeaderSummaryForHtml() | |||
2144 | { | |||
2145 | QString hdr_text; | |||
2146 | hdr_text += "<tr>"; | |||
2147 | for (int col = 0; col < packet_list_model_->columnCount(); ++col) { | |||
2148 | if (get_column_visible(col)) { | |||
2149 | hdr_text += "<th>"; | |||
2150 | hdr_text += packet_list_model_->headerData(col, Qt::Orientation::Horizontal, Qt::DisplayRole).toString(); | |||
2151 | hdr_text += "</th>"; | |||
2152 | } | |||
2153 | } | |||
2154 | hdr_text += "</tr>"; | |||
2155 | return hdr_text; | |||
2156 | } | |||
2157 | ||||
2158 | QString PacketList::createSummaryForHtml(QModelIndex idx) | |||
2159 | { | |||
2160 | if (! idx.isValid()) | |||
2161 | return ""; | |||
2162 | ||||
2163 | int row = idx.row(); | |||
2164 | QString col_text; | |||
2165 | ||||
2166 | QString bg_color = packet_list_model_->data(packet_list_model_->index(row, 0), Qt::BackgroundRole).toString(); | |||
2167 | QString fg_color = packet_list_model_->data(packet_list_model_->index(row, 0), Qt::ForegroundRole).toString(); | |||
2168 | col_text += "<tr style=\"background-color:" + bg_color + ";color:" + fg_color + ";\">"; | |||
2169 | ||||
2170 | QString alignment[] = {"left", "right", "center", "justify"}; | |||
2171 | ||||
2172 | for (int col = 0; col < packet_list_model_->columnCount(); col++) { | |||
2173 | if (get_column_visible(col)) { | |||
2174 | col_text += "<td style=\"text-align:" + alignment[packet_list_model_->data(packet_list_model_->index(row, col), Qt::TextAlignmentRole).toInt() / 2] + ";\">"; | |||
2175 | col_text += packet_list_model_->data(packet_list_model_->index(row, col), Qt::DisplayRole).toString(); | |||
2176 | col_text += "</td>"; | |||
2177 | } | |||
2178 | } | |||
2179 | ||||
2180 | col_text += "</tr>"; | |||
2181 | return col_text; | |||
2182 | } | |||
2183 | ||||
2184 | QString PacketList::createClosingTagForHtml() | |||
2185 | { | |||
2186 | return "</table>"; | |||
2187 | } | |||
2188 | ||||
2189 | void PacketList::copySummary() | |||
2190 | { | |||
2191 | if (!currentIndex().isValid()) return; | |||
2192 | ||||
2193 | QAction *ca = qobject_cast<QAction*>(sender()); | |||
2194 | if (!ca) return; | |||
2195 | ||||
2196 | QVariant type = ca->data(); | |||
2197 | if (! type.canConvert<SummaryCopyType>()) | |||
2198 | return; | |||
2199 | SummaryCopyType copy_type = type.value<SummaryCopyType>(); | |||
2200 | ||||
2201 | QString copy_text; | |||
2202 | if (type == CopyAsText || type == CopyAsHTML) { | |||
2203 | if (prefs.gui_packet_list_copy_text_with_aligned_columns) { | |||
2204 | QList<int> rows; | |||
2205 | rows << currentIndex().row(); | |||
2206 | QStringList hdr_parts; | |||
2207 | QList<int> align_parts, size_parts; | |||
2208 | hdr_parts = createHeaderPartsForAligned(); | |||
2209 | align_parts = createAlignmentPartsForAligned(); | |||
2210 | size_parts = createSizePartsForAligned(false, hdr_parts, rows); | |||
2211 | copy_text = createSummaryForAligned(currentIndex(), align_parts, size_parts); | |||
2212 | } | |||
2213 | else { | |||
2214 | copy_text = createSummaryText(currentIndex(), CopyAsText); | |||
2215 | } | |||
2216 | copy_text += "\n"; | |||
2217 | if (type == CopyAsHTML) { | |||
2218 | QStringList htmlContent; | |||
2219 | htmlContent << createDefaultStyleForHtml(); | |||
2220 | htmlContent << createOpeningTagForHtml(); | |||
2221 | htmlContent << createSummaryForHtml(currentIndex()); | |||
2222 | htmlContent << createClosingTagForHtml(); | |||
2223 | // htmlContent will never be empty as they will always have | |||
2224 | // style and table tags | |||
2225 | QMimeData *mimeData = new QMimeData; | |||
2226 | mimeData->setHtml(htmlContent.join('\n')); | |||
2227 | mimeData->setText(copy_text); | |||
2228 | mainApp->clipboard()->setMimeData(mimeData, QClipboard::Clipboard); | |||
2229 | } | |||
2230 | else { | |||
2231 | mainApp->clipboard()->setText(copy_text); | |||
2232 | } | |||
2233 | } | |||
2234 | else { | |||
2235 | copy_text = createSummaryText(currentIndex(), copy_type); | |||
2236 | if (type != CopyAsYAML) | |||
2237 | copy_text += "\n"; | |||
2238 | mainApp->clipboard()->setText(copy_text); | |||
2239 | } | |||
2240 | } | |||
2241 | ||||
2242 | // We need to tell when the user has scrolled the packet list, either to | |||
2243 | // the end or anywhere other than the end. | |||
2244 | void PacketList::vScrollBarActionTriggered(int) | |||
2245 | { | |||
2246 | // If we're scrolling with a mouse wheel or trackpad sliderPosition can end up | |||
2247 | // past the end. | |||
2248 | tail_at_end_ = (overlay_sb_->sliderPosition() >= overlay_sb_->maximum()); | |||
2249 | ||||
2250 | scrollViewChanged(tail_at_end_); | |||
2251 | } | |||
2252 | ||||
2253 | void PacketList::scrollViewChanged(bool at_end) | |||
2254 | { | |||
2255 | if (capture_in_progress_) { | |||
2256 | // We want to start auto scrolling when the user scrolls to (or past) | |||
2257 | // the end only if recent.capture_auto_scroll is set. | |||
2258 | // We want to stop autoscrolling if the user scrolls up or uses | |||
2259 | // Go to Packet regardless of the preference setting. | |||
2260 | if (recent.capture_auto_scroll || !at_end) { | |||
2261 | emit packetListScrolled(at_end); | |||
2262 | } | |||
2263 | } | |||
2264 | } | |||
2265 | ||||
2266 | // Goal: Overlay the packet list scroll bar with the colors of all of the | |||
2267 | // packets. | |||
2268 | // Try 1: Average packet colors in each scroll bar raster line. This has | |||
2269 | // two problems: It's easy to wash out colors and we dissect every packet. | |||
2270 | // Try 2: Color across a 5000 or 10000 packet window. We still end up washing | |||
2271 | // out colors. | |||
2272 | // Try 3: One packet per vertical scroll bar pixel. This seems to work best | |||
2273 | // but has the smallest window. | |||
2274 | // Try 4: Use a multiple of the scroll bar height and scale the image down | |||
2275 | // using Qt::SmoothTransformation. This gives us more packets per raster | |||
2276 | // line. | |||
2277 | ||||
2278 | // Odd (prime?) numbers resulted in fewer scaling artifacts. A multiplier | |||
2279 | // of 9 washed out colors a little too much. | |||
2280 | //const int height_multiplier_ = 7; | |||
2281 | void PacketList::drawNearOverlay() | |||
2282 | { | |||
2283 | if (create_near_overlay_) { | |||
2284 | create_near_overlay_ = false; | |||
2285 | } | |||
2286 | ||||
2287 | if (!cap_file_ || cap_file_->state != FILE_READ_DONE) return; | |||
2288 | ||||
2289 | if (!prefs.gui_packet_list_show_minimap) return; | |||
2290 | ||||
2291 | qreal dp_ratio = overlay_sb_->devicePixelRatio(); | |||
2292 | int o_height = overlay_sb_->height() * dp_ratio; | |||
2293 | int o_rows = qMin(packet_list_model_->rowCount(), o_height); | |||
2294 | QFontMetricsF fmf(mainApp->font()); | |||
2295 | int o_width = ((static_cast<int>(fmf.height())) * 2 * dp_ratio) + 2; // 2ems + 1-pixel border on either side. | |||
2296 | ||||
2297 | if (recent.packet_list_colorize && o_rows > 0) { | |||
2298 | QImage overlay(o_width, o_height, QImage::Format_ARGB32_Premultiplied); | |||
2299 | ||||
2300 | QPainter painter(&overlay); | |||
2301 | ||||
2302 | overlay.fill(Qt::transparent); | |||
2303 | ||||
2304 | int cur_line = 0; | |||
2305 | int start = 0; | |||
2306 | ||||
2307 | if (packet_list_model_->rowCount() > o_height && overlay_sb_->maximum() > 0) { | |||
2308 | start += ((double) overlay_sb_->value() / overlay_sb_->maximum()) * (packet_list_model_->rowCount() - o_rows); | |||
2309 | } | |||
2310 | int end = start + o_rows; | |||
2311 | for (int row = start; row < end; row++) { | |||
2312 | packet_list_model_->ensureRowColorized(row); | |||
2313 | ||||
2314 | frame_data *fdata = packet_list_model_->getRowFdata(row); | |||
2315 | const color_t *bgcolor = NULL__null; | |||
2316 | if (fdata->color_filter) { | |||
2317 | const color_filter_t *color_filter = (const color_filter_t *) fdata->color_filter; | |||
2318 | bgcolor = &color_filter->bg_color; | |||
2319 | } | |||
2320 | ||||
2321 | int next_line = (row - start + 1) * o_height / o_rows; | |||
2322 | if (bgcolor) { | |||
2323 | QColor color(ColorUtils::fromColorT(bgcolor)); | |||
2324 | painter.fillRect(0, cur_line, o_width, next_line - cur_line, color); | |||
2325 | } | |||
2326 | cur_line = next_line; | |||
2327 | } | |||
2328 | ||||
2329 | // If the selected packet is in the overlay set selected_pos | |||
2330 | // accordingly. Otherwise, pin it to either the top or bottom. | |||
2331 | QList<int> positions; | |||
2332 | if (selectionModel()->hasSelection()) { | |||
2333 | ||||
2334 | QModelIndexList selRows = selectionModel()->selectedRows(0); | |||
2335 | int last_row = -1; | |||
2336 | int last_pos = -1; | |||
2337 | foreach (QModelIndex idx, selRows)for (auto _container_2337 = QtPrivate::qMakeForeachContainer( selRows); _container_2337.i != _container_2337.e; ++_container_2337 .i) if (QModelIndex idx = *_container_2337.i; false) {} else | |||
2338 | { | |||
2339 | int selected_pos = -1; | |||
2340 | int sel_row = idx.row(); | |||
2341 | if (sel_row < start) { | |||
2342 | selected_pos = 0; | |||
2343 | } else if (sel_row >= end) { | |||
2344 | selected_pos = overlay.height() - 1; | |||
2345 | } else { | |||
2346 | selected_pos = (sel_row - start) * o_height / o_rows; | |||
2347 | } | |||
2348 | ||||
2349 | /* Due to the difference in the display height, we sometimes get empty positions | |||
2350 | * inbetween consecutive valid rows. If those are detected, they are signaled as | |||
2351 | * being selected as well */ | |||
2352 | if (last_pos >= 0 && selected_pos > (last_pos + 1) && (last_row + 1) == sel_row) | |||
2353 | { | |||
2354 | for (int pos = (last_pos + 1); pos < selected_pos; pos++) | |||
2355 | { | |||
2356 | if (! positions.contains(pos)) | |||
2357 | positions << pos; | |||
2358 | } | |||
2359 | } | |||
2360 | else if (selected_pos != -1 && ! positions.contains(selected_pos)) | |||
2361 | positions << selected_pos; | |||
2362 | ||||
2363 | last_row = sel_row; | |||
2364 | last_pos = selected_pos; | |||
2365 | } | |||
2366 | } | |||
2367 | ||||
2368 | overlay_sb_->setNearOverlayImage(overlay, packet_list_model_->rowCount(), start, end, positions, (o_height / o_rows)); | |||
2369 | } else { | |||
2370 | QImage overlay; | |||
2371 | overlay_sb_->setNearOverlayImage(overlay); | |||
2372 | } | |||
2373 | } | |||
2374 | ||||
2375 | void PacketList::drawFarOverlay() | |||
2376 | { | |||
2377 | if (create_far_overlay_) { | |||
2378 | create_far_overlay_ = false; | |||
2379 | } | |||
2380 | ||||
2381 | if (!cap_file_ || cap_file_->state != FILE_READ_DONE) return; | |||
2382 | ||||
2383 | if (!prefs.gui_packet_list_show_minimap) return; | |||
2384 | ||||
2385 | QSize groove_size = overlay_sb_->grooveRect().size(); | |||
2386 | qreal dp_ratio = overlay_sb_->devicePixelRatio(); | |||
2387 | groove_size *= dp_ratio; | |||
2388 | int o_width = groove_size.width(); | |||
2389 | int o_height = groove_size.height(); | |||
2390 | int pl_rows = packet_list_model_->rowCount(); | |||
2391 | QImage overlay(o_width, o_height, QImage::Format_ARGB32_Premultiplied); | |||
2392 | bool have_marked_image = false; | |||
2393 | ||||
2394 | // If only there were references from popular culture about getting into | |||
2395 | // some sort of groove. | |||
2396 | if (!overlay.isNull() && recent.packet_list_colorize && pl_rows > 0) { | |||
2397 | ||||
2398 | QPainter painter(&overlay); | |||
2399 | ||||
2400 | // Draw text-colored tick marks on a transparent background. | |||
2401 | // Hopefully no themes use the text color for the groove color. | |||
2402 | overlay.fill(Qt::transparent); | |||
2403 | ||||
2404 | QColor tick_color = palette().text().color(); | |||
2405 | tick_color.setAlphaF(0.3f); | |||
2406 | painter.setPen(tick_color); | |||
2407 | ||||
2408 | for (int row = 0; row < pl_rows; row++) { | |||
2409 | ||||
2410 | frame_data *fdata = packet_list_model_->getRowFdata(row); | |||
2411 | if (fdata->marked || fdata->ref_time || fdata->ignored) { | |||
2412 | int new_line = row * o_height / pl_rows; | |||
2413 | int tick_width = o_width / 3; | |||
2414 | // Marked or ignored: left side, time refs: right side. | |||
2415 | // XXX Draw ignored ticks in the middle? | |||
2416 | int x1 = fdata->ref_time ? o_width - tick_width : 1; | |||
2417 | int x2 = fdata->ref_time ? o_width - 1 : tick_width; | |||
2418 | ||||
2419 | painter.drawLine(x1, new_line, x2, new_line); | |||
2420 | have_marked_image = true; | |||
2421 | } | |||
2422 | } | |||
2423 | ||||
2424 | if (have_marked_image) { | |||
2425 | overlay_sb_->setMarkedPacketImage(overlay); | |||
2426 | return; | |||
2427 | } | |||
2428 | } | |||
2429 | ||||
2430 | if (!have_marked_image) { | |||
2431 | QImage null_overlay; | |||
2432 | overlay_sb_->setMarkedPacketImage(null_overlay); | |||
2433 | } | |||
2434 | } | |||
2435 | ||||
2436 | // Auto scroll if: | |||
2437 | // - We are capturing | |||
2438 | // - actionGoAutoScroll in the main UI is checked. | |||
2439 | ||||
2440 | // actionGoAutoScroll in the main UI: | |||
2441 | // - Is set to the value of recent.capture_auto_scroll when beginning a capture | |||
2442 | // - Can be triggered manually by the user | |||
2443 | // - Is turned on if the last user-set vertical scrollbar position is at the | |||
2444 | // end and recent.capture_auto_scroll is enabled | |||
2445 | // - Is turned off if the last user-set vertical scrollbar is not at the end, | |||
2446 | // or if one of the Go to Packet actions is used (XXX: Should keyboard | |||
2447 | // navigation in keyPressEvent turn it off for similar reasons?) | |||
2448 | void PacketList::rowsInserted(const QModelIndex &parent, int start, int end) | |||
2449 | { | |||
2450 | QTreeView::rowsInserted(parent, start, end); | |||
2451 | if (capture_in_progress_ && tail_at_end_) { | |||
2452 | scrollToBottom(); | |||
2453 | } | |||
2454 | } | |||
2455 | ||||
2456 | void PacketList::resizeAllColumns(bool onlyTimeFormatted) | |||
2457 | { | |||
2458 | if (!cap_file_ || cap_file_->state == FILE_CLOSED || cap_file_->state == FILE_READ_PENDING) | |||
2459 | return; | |||
2460 | ||||
2461 | for (int col = 0; col < cap_file_->cinfo.num_cols; col++) { | |||
2462 | if (! onlyTimeFormatted || col_has_time_fmt(&cap_file_->cinfo, col)) { | |||
2463 | resizeColumnToContents(col); | |||
2464 | } | |||
2465 | } | |||
2466 | } |