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