Bug Summary

File:builds/wireshark/wireshark/ui/qt/main_status_bar.cpp
Warning:line 720, column 9
Potential leak of memory pointed to by 'placer'

Annotated Source Code

Press '?' to see keyboard shortcuts

clang -cc1 -cc1 -triple x86_64-pc-linux-gnu -analyze -disable-free -clear-ast-before-backend -disable-llvm-verifier -discard-value-names -main-file-name main_status_bar.cpp -analyzer-checker=core -analyzer-checker=apiModeling -analyzer-checker=unix -analyzer-checker=deadcode -analyzer-checker=cplusplus -analyzer-checker=security.insecureAPI.UncheckedReturn -analyzer-checker=security.insecureAPI.getpw -analyzer-checker=security.insecureAPI.gets -analyzer-checker=security.insecureAPI.mktemp -analyzer-checker=security.insecureAPI.mkstemp -analyzer-checker=security.insecureAPI.vfork -analyzer-checker=nullability.NullPassedToNonnull -analyzer-checker=nullability.NullReturnedFromNonnull -analyzer-output plist -w -setup-static-analyzer -mrelocation-model pic -pic-level 2 -fhalf-no-semantic-interposition -fno-delete-null-pointer-checks -mframe-pointer=all -relaxed-aliasing -fmath-errno -ffp-contract=on -fno-rounding-math -ffloat16-excess-precision=fast -fbfloat16-excess-precision=fast -mconstructor-aliases -funwind-tables=2 -target-cpu x86-64 -tune-cpu generic -debugger-tuning=gdb -fdebug-compilation-dir=/builds/wireshark/wireshark/build -fcoverage-compilation-dir=/builds/wireshark/wireshark/build -resource-dir /usr/lib/llvm-22/lib/clang/22 -isystem /usr/include/glib-2.0 -isystem /usr/lib/x86_64-linux-gnu/glib-2.0/include -isystem /builds/wireshark/wireshark/build/ui/qt -isystem /builds/wireshark/wireshark/ui/qt -isystem /builds/wireshark/wireshark/ui/qt/lua_debugger -isystem /usr/include/x86_64-linux-gnu/qt6/QtConcurrent -isystem /usr/include/x86_64-linux-gnu/qt6 -isystem /usr/include/x86_64-linux-gnu/qt6/QtCore -isystem /usr/lib/x86_64-linux-gnu/qt6/mkspecs/linux-g++ -isystem /usr/include/x86_64-linux-gnu/qt6/QtNetwork -isystem /usr/include/x86_64-linux-gnu/qt6/QtPrintSupport -isystem /usr/include/x86_64-linux-gnu/qt6/QtGui -isystem /usr/include/x86_64-linux-gnu/qt6/QtWidgets -isystem /usr/include/x86_64-linux-gnu/qt6/QtSvg -isystem /usr/include/x86_64-linux-gnu/qt6/QtMultimedia -isystem /usr/include/x86_64-linux-gnu/qt6/QtDBus -D CARES_NO_DEPRECATED -D G_DISABLE_DEPRECATED -D G_DISABLE_SINGLE_INCLUDES -D QT_CONCURRENT_LIB -D QT_CORE_LIB -D QT_DBUS_LIB -D QT_GUI_LIB -D QT_MULTIMEDIA_LIB -D QT_NETWORK_LIB -D QT_PRINTSUPPORT_LIB -D QT_SVG_LIB -D QT_WIDGETS_LIB -D WS_DEBUG -D WS_DEBUG_UTF_8 -I /builds/wireshark/wireshark/build/ui/qt/qtui_autogen/include -I /builds/wireshark/wireshark/build -I /builds/wireshark/wireshark -I /builds/wireshark/wireshark/include -D _GLIBCXX_ASSERTIONS -internal-isystem /usr/lib/gcc/x86_64-linux-gnu/16/../../../../include/c++/16 -internal-isystem /usr/lib/gcc/x86_64-linux-gnu/16/../../../../include/x86_64-linux-gnu/c++/16 -internal-isystem /usr/lib/gcc/x86_64-linux-gnu/16/../../../../include/c++/16/backward -internal-isystem /usr/lib/llvm-22/lib/clang/22/include -internal-isystem /usr/local/include -internal-isystem /usr/lib/gcc/x86_64-linux-gnu/16/../../../../x86_64-linux-gnu/include -internal-externc-isystem /usr/include/x86_64-linux-gnu -internal-externc-isystem /include -internal-externc-isystem /usr/include -fmacro-prefix-map=/builds/wireshark/wireshark/= -fmacro-prefix-map=/builds/wireshark/wireshark/build/= -fmacro-prefix-map=../= -Wno-format-nonliteral -std=c++17 -fdeprecated-macro -ferror-limit 19 -fwrapv -fwrapv-pointer -fstrict-flex-arrays=3 -stack-protector 2 -fstack-clash-protection -fcf-protection=full -fgnuc-version=4.2.1 -fskip-odr-check-in-gmf -fcxx-exceptions -fexceptions -fcolor-diagnostics -analyzer-output=html -faddrsig -fdwarf2-cfi-asm -o /builds/wireshark/wireshark/sbout/2026-11-18-100343-3661-1 -x c++ /builds/wireshark/wireshark/ui/qt/main_status_bar.cpp
1/* main_status_bar.cpp
2 *
3 * Wireshark - Network traffic analyzer
4 * By Gerald Combs <[email protected]>
5 * Copyright 1998 Gerald Combs
6 *
7 * SPDX-License-Identifier: GPL-2.0-or-later
8 */
9
10#include "config.h"
11
12#include "file.h"
13
14#include <epan/expert.h>
15#include <epan/prefs.h>
16#include <epan/tag_rules.h>
17
18#include <wsutil/filesystem.h>
19#include <wsutil/utf8_entities.h>
20
21#include "ui/main_statusbar.h"
22#include <ui/qt/utils/qt_ui_utils.h>
23#include <ui/qt/main_window.h>
24
25#include "capture_file.h"
26#include "main_status_bar.h"
27#include "profile_dialog.h"
28#include <ui/qt/utils/color_utils.h>
29#include <ui/qt/utils/font_manager.h>
30#include <ui/qt/utils/zoom_scaling.h>
31#include <ui/qt/utils/themes/contrast_adapt_icon.h>
32#include <ui/qt/utils/themes/themed_icon.h>
33#include <ui/qt/capture_file.h>
34#include <ui/qt/widgets/clickable_label.h>
35#include <ui/recent.h>
36
37#include <QAction>
38#include <QHBoxLayout>
39#include <QMenu>
40#include <QScreen>
41#include <QSplitter>
42#include <QToolButton>
43#include <QLatin1Char>
44
45#include <functional>
46
47// To do:
48// - Use the CaptureFile class.
49
50// XXX - The GTK+ code assigns priorities to these and pushes/pops accordingly.
51
52Q_DECLARE_METATYPE(ProfileDialog::ProfileAction)template <> struct QMetaTypeId< ProfileDialog::ProfileAction
> { enum { Defined = 1 }; static_assert(QtPrivate::checkTypeIsSuitableForMetaType
<ProfileDialog::ProfileAction>()); static int qt_metatype_id
() { [[clang::require_constant_initialization]] static QBasicAtomicInt
metatype_id = { 0 }; if (const int id = metatype_id.loadAcquire
()) return id; constexpr auto arr = QtPrivate::typenameHelper
<ProfileDialog::ProfileAction>(); auto name = arr.data(
); if (QByteArrayView(name) == ("ProfileDialog::ProfileAction"
)) { const int id = qRegisterNormalizedMetaType<ProfileDialog
::ProfileAction>(name); metatype_id.storeRelease(id); return
id; } const int newId = qRegisterMetaType< ProfileDialog::
ProfileAction >("ProfileDialog::ProfileAction"); metatype_id
.storeRelease(newId); return newId; } };
53
54// The profile menu opens near the right edge of the screen. Without room on
55// the right, Qt opens a submenu on the left, but its submenus on the right
56// again, on top of the menus they were opened from. Once a submenu has been
57// opened on the left, keep opening its submenus on the left.
58class SubMenuPlacer : public QObject
59{
60public:
61 explicit SubMenuPlacer(QObject *parent) : QObject(parent) {}
62
63protected:
64 bool eventFilter(QObject *obj, QEvent *event) override
65 {
66 QMenu *menu = qobject_cast<QMenu *>(obj);
67 if (event->type() != QEvent::Show || !menu)
68 return false;
69
70 QMenu *parentMenu = qobject_cast<QMenu *>(menu->parentWidget());
71 QMenu *grandMenu = parentMenu ? qobject_cast<QMenu *>(parentMenu->parentWidget()) : Q_NULLPTRnullptr;
72 if (!grandMenu || parentMenu->x() >= grandMenu->x() || menu->x() < parentMenu->x())
73 return false;
74
75 QPoint pos(parentMenu->x() - menu->width(), menu->y());
76 if (menu->screen() && pos.x() >= menu->screen()->availableGeometry().left())
77 menu->move(pos);
78 return false;
79 }
80};
81
82// If we ever add support for multiple windows this will need to be replaced.
83// See also: main_window.cpp
84static MainStatusBar *cur_main_status_bar_;
85
86/*
87 * Push a formatted temporary message onto the statusbar.
88 */
89void
90statusbar_push_temporary_msg(const char *msg_format, ...)
91{
92 va_list ap;
93 QString push_msg;
94
95 if (!cur_main_status_bar_) return;
96
97 va_start(ap, msg_format)__builtin_va_start(ap, msg_format);
98 push_msg = QString::vasprintf(msg_format, ap);
99 va_end(ap)__builtin_va_end(ap);
100
101 mainApp->pushStatus(WiresharkApplication::TemporaryStatus, push_msg);
102}
103
104/*
105 * Update the packets statusbar to the current values
106 */
107void
108packets_bar_update(void)
109{
110 if (!cur_main_status_bar_) return;
111
112 cur_main_status_bar_->updateCaptureStatistics(NULL__null);
113}
114
115MainStatusBar::MainStatusBar(QWidget *parent) :
116 QStatusBar(parent),
117 cap_file_(NULL__null),
118 cs_fixed_(false),
119 cs_count_(0)
120{
121 QSplitter *splitter = new QSplitter(this);
122 QWidget *info_progress = new QWidget(this);
123 info_progress_hb_ = new QHBoxLayout(info_progress);
124
125#if defined(Q_OS_WIN)
126 // Handles are the same color as widgets, at least on Windows 7.
127 splitter->setHandleWidth(3);
128 splitter->setStyleSheet(QStringLiteral((QString(QtPrivate::qMakeStringPrivate(u"" "QSplitter::handle {"
" border-left: 1px solid palette(mid);" " border-right: 1px solid palette(mid);"
"}")))
129 "QSplitter::handle {"(QString(QtPrivate::qMakeStringPrivate(u"" "QSplitter::handle {"
" border-left: 1px solid palette(mid);" " border-right: 1px solid palette(mid);"
"}")))
130 " border-left: 1px solid palette(mid);"(QString(QtPrivate::qMakeStringPrivate(u"" "QSplitter::handle {"
" border-left: 1px solid palette(mid);" " border-right: 1px solid palette(mid);"
"}")))
131 " border-right: 1px solid palette(mid);"(QString(QtPrivate::qMakeStringPrivate(u"" "QSplitter::handle {"
" border-left: 1px solid palette(mid);" " border-right: 1px solid palette(mid);"
"}")))
132 "}"(QString(QtPrivate::qMakeStringPrivate(u"" "QSplitter::handle {"
" border-left: 1px solid palette(mid);" " border-right: 1px solid palette(mid);"
"}")))
133 )(QString(QtPrivate::qMakeStringPrivate(u"" "QSplitter::handle {"
" border-left: 1px solid palette(mid);" " border-right: 1px solid palette(mid);"
"}")))
);
134#endif
135
136#ifdef Q_OS_MACOS
137 profile_status_.setAttribute(Qt::WA_MacSmallSize, true);
138#endif
139
140 QString button_ss =
141 "QToolButton {"
142 " border: none;"
143 " background: transparent;" // Disables platform style on Windows.
144 " padding: 0px;"
145 " margin: 0px;"
146 "}";
147
148 QString label_ss =
149 "QLabel {"
150 " margin-left: 0.5em;"
151 "}";
152
153 expert_button_ = new QToolButton(this);
154 expert_button_->setStyleSheet(button_ss);
155 expert_button_->setAccessibleName(tr("Expert information"));
156 expert_button_->setAccessibleDescription(tr("Opens the expert information dialog, showing errors, warnings, and other relevant information about the capture."));
157 expert_button_->hide();
158
159 // We just want a clickable image. Using a QPushButton or QToolButton would require
160 // a lot of adjustment.
161 ThemedIcon comment_icon(QStringLiteral(":/svg_icons/capture-comment.svg")(QString(QtPrivate::qMakeStringPrivate(u"" ":/svg_icons/capture-comment.svg"
)))
, ThemeManager::PaletteText);
162 comment_button_ = new QToolButton(this);
163 comment_button_->setIcon(comment_icon);
164 comment_button_->setStyleSheet(button_ss);
165 comment_button_->setAccessibleName(tr("Capture comment"));
166 comment_button_->setAccessibleDescription(tr("Opens the Capture File Properties dialog to view or edit capture-level comments."));
167
168 comment_button_->setToolTip(tr("Open the Capture File Properties dialog"));
169 comment_button_->setEnabled(false);
170 connect(expert_button_, &QToolButton::clicked, this, &MainStatusBar::showExpertInfo);
171 connect(comment_button_, &QToolButton::clicked, this, &MainStatusBar::editCaptureComment);
172
173 applyIconSizes();
174 connect(FontManager::instance(), &FontManager::zoomChanged, this, &MainStatusBar::applyIconSizes);
175
176 info_status_.setTemporaryContext(STATUS_CTX_TEMPORARY);
177 info_status_.setShrinkable(true);
178 info_status_.setAccessibleName(tr("Information"));
179 info_status_.setAccessibleDescription(tr("Displays general information, status messages, and expert severity details."));
180
181 info_progress_hb_->addWidget(expert_button_);
182 info_progress_hb_->addWidget(comment_button_);
183 info_progress_hb_->addWidget(&info_status_);
184 info_progress_hb_->addWidget(&progress_frame_);
185 info_progress_hb_->addStretch(10);
186
187 // LabelStack does setStyleSheet for QLabel but ClickableLabel does not
188 packet_status_.setAccessibleName(tr("Packet statistics"));
189 packet_status_.setAccessibleDescription(tr("Shows the number of captured, displayed, and selected packets."));
190 profile_status_.setStyleSheet(label_ss);
191 profile_status_.setAccessibleName(tr("Configuration profile"));
192 profile_status_.setAccessibleDescription(tr("Displays the current configuration profile and allows switching between profiles."));
193
194 splitter->addWidget(info_progress);
195 splitter->addWidget(&packet_status_);
196 splitter->addWidget(&profile_status_);
197
198 splitter->setStretchFactor(0, 3);
199 splitter->setStretchFactor(1, 3);
200 splitter->setStretchFactor(2, 1);
201
202 addWidget(splitter, 1);
203
204 cur_main_status_bar_ = this;
205
206 splitter->hide();
207 setReadyMsg();
208 packets_bar_update();
209
210#ifdef QWINTASKBARPROGRESS_H
211 progress_frame_.enableTaskbarUpdates(true);
212#endif
213
214 mainApp->whenInitialized(splitter, [splitter]() { splitter->show(); });
215 mainApp->whenInitialized(this, [this]() { appInitialized(); });
216 connect(&info_status_, &LabelStack::toggleTemporaryFlash, this, &MainStatusBar::toggleBackground);
217 connect(mainApp, &MainApplication::profileNameChanged, this, &MainStatusBar::setProfileName);
218 connect(&profile_status_, &ClickableLabel::clickedAt, this, &MainStatusBar::showProfileMenu);
219
220 connect(&progress_frame_, &ProgressFrame::stopLoading, this, &MainStatusBar::stopLoading);
221}
222
223MainStatusBar::~MainStatusBar()
224{
225
226}
227
228
229void MainStatusBar::showExpert() {
230 expertUpdate();
231}
232
233void MainStatusBar::captureFileClosing() {
234 expert_button_->hide();
235 progress_frame_.captureFileClosing();
236 field_status_supplement_.clear();
237 field_status_include_base_ = true;
238 field_status_base_.clear();
239 popGenericStatus(STATUS_CTX_FIELD);
240}
241
242void MainStatusBar::expertUpdate() {
243 // <img> won't load @2x versions in Qt versions earlier than 5.4.
244 // https://bugreports.qt.io/browse/QTBUG-36383
245 // We might have to switch to a QPushButton.
246 QString stock_name = "expert-";
247 QString tt_text = tr(" is the highest expert information level");
248
249 switch(expert_get_highest_severity()) {
250 case(PI_ERROR0x00800000):
251 stock_name.append("error");
252 tt_text.prepend(tr("ERROR"));
253 break;
254 case(PI_WARN0x00600000):
255 stock_name.append("warn");
256 tt_text.prepend(tr("WARNING"));
257 break;
258 case(PI_NOTE0x00400000):
259 stock_name.append("note");
260 tt_text.prepend(tr("NOTE"));
261 break;
262 case(PI_CHAT0x00200000):
263 stock_name.append("chat");
264 tt_text.prepend(tr("CHAT"));
265 break;
266 default:
267 stock_name.append("none");
268 tt_text = tr("No expert information");
269 break;
270 }
271
272 ContrastAdaptIcon expert_icon(QStringLiteral(":/svg_icons/")(QString(QtPrivate::qMakeStringPrivate(u"" ":/svg_icons/"))) + stock_name.toLatin1() + QStringLiteral(".svg")(QString(QtPrivate::qMakeStringPrivate(u"" ".svg"))),
273 QPalette::Window);
274 applyIconSizes();
275 expert_button_->setIcon(expert_icon);
276 expert_button_->setToolTip(tt_text);
277 expert_button_->show();
278}
279
280// ui/gtk/main_statusbar.c
281void MainStatusBar::setFileName(CaptureFile &cf)
282{
283 if (cf.isValid()) {
284 popGenericStatus(STATUS_CTX_FILE);
285 QString msgtip = QStringLiteral("%1 (%2)")(QString(QtPrivate::qMakeStringPrivate(u"" "%1 (%2)")))
286 .arg(cf.capFile()->filename, file_size_to_qstring(cf.capFile()->f_datalen));
287 pushGenericStatus(STATUS_CTX_FILE, cf.fileName(), msgtip);
288 }
289}
290
291void MainStatusBar::setReadyMsg()
292{
293#ifdef HAVE_LIBPCAP1
294 QString ready_msg(tr("Ready to load or capture"));
295#else
296 QString ready_msg(tr("Ready to load file"));
297#endif
298 info_status_.pushText(std::move(ready_msg), STATUS_CTX_MAIN);
299}
300
301void MainStatusBar::applyIconSizes()
302{
303 // Both indicators match the display filter toolbar icons. They are not
304 // sized from the status text, whose font is smaller on macOS.
305 const int side = ZoomScaling::barIconSize();
306 expert_button_->setIconSize(QSize(side, side));
307 comment_button_->setIconSize(QSize(side, side));
308 info_progress_hb_->setContentsMargins(side / 2, 0, 0, 0);
309}
310
311void MainStatusBar::changeEvent(QEvent *event)
312{
313 if (event->type() == QEvent::LanguageChange) {
314 info_status_.popText(STATUS_CTX_MAIN);
315 setReadyMsg();
316 setStatusbarForCaptureFile();
317 showCaptureStatistics();
318 setProfileName();
319 }
320 if (event->type() == QEvent::FontChange || event->type() == QEvent::ApplicationFontChange) {
321 applyIconSizes();
322 }
323 QStatusBar::changeEvent(event);
324}
325
326void MainStatusBar::setCaptureFile(capture_file *cf)
327{
328 cap_file_ = cf;
329 comment_button_->setEnabled(cap_file_ != NULL__null);
330}
331
332void MainStatusBar::setStatusbarForCaptureFile()
333{
334 if (cap_file_ && cap_file_->filename && (cap_file_->state != FILE_CLOSED)) {
335 popGenericStatus(STATUS_CTX_FILE);
336 QString msgtip = QStringLiteral("%1 (%2)")(QString(QtPrivate::qMakeStringPrivate(u"" "%1 (%2)")))
337 .arg(cap_file_->filename, file_size_to_qstring(cap_file_->f_datalen));
338 pushGenericStatus(STATUS_CTX_FILE,
339 gchar_free_to_qstring(cf_get_display_name(cap_file_)), msgtip);
340 }
341}
342
343void MainStatusBar::setFieldStatusSupplement(const QString &supplement, bool include_selected_field)
344{
345 field_status_supplement_ = supplement;
346 field_status_include_base_ = include_selected_field;
347 refreshFieldStatus();
348}
349
350void MainStatusBar::refreshFieldStatus()
351{
352 QString display;
353 if (!field_status_supplement_.isEmpty()) {
354 display = field_status_supplement_;
355 if (field_status_include_base_ && !field_status_base_.isEmpty()) {
356 display += QLatin1Char(' ') + field_status_base_;
357 }
358 } else {
359 display = field_status_base_;
360 }
361 pushGenericStatus(STATUS_CTX_FIELD, display);
362}
363
364void MainStatusBar::selectedFieldChanged(FieldInformation * finfo)
365{
366 QString item_info;
367
368 if (! finfo) {
369 field_status_base_.clear();
370 refreshFieldStatus();
371 return;
372 }
373
374 FieldInformation::HeaderInfo hInfo = finfo->headerInfo();
375
376 if (hInfo.isValid)
377 {
378 /* For frame.tag items, show the rule's comment in the status bar instead of the blurb. */
379 if (hInfo.abbreviation == "frame.tag") {
380 field_info *fi = finfo->fieldInfo();
381 const char *rule_name = fi ? fvalue_get_string(fi->value) : nullptr;
382 QString comment_str;
383 if (rule_name) {
384 for (const GSList *r = tag_rules_get_list(); r; r = g_slist_next(r)((r) ? (((GSList *)(r))->next) : __null)) {
385 const tag_rule_t *rule = (const tag_rule_t *)r->data;
386 if (strcmp(rule->rule_name, rule_name) == 0) {
387 if (rule->comment && rule->comment[0])
388 comment_str = QString::fromUtf8(rule->comment);
389 break;
390 }
391 }
392 }
393 item_info.append(comment_str.isEmpty() ? hInfo.description : comment_str);
394 } else if (hInfo.description.length() > 0) {
395 item_info.append(hInfo.description);
396 } else {
397 item_info.append(hInfo.name);
398 }
399 }
400
401 if (!item_info.isEmpty()) {
402 int finfo_length;
403 if (hInfo.isValid)
404 item_info.append(" (" + hInfo.abbreviation + ")");
405
406 finfo_length = finfo->position().length + finfo->appendix().length;
407 if (finfo_length > 0) {
408 int finfo_bits = FI_GET_BITS_SIZE(finfo->fieldInfo())(((finfo->fieldInfo()) ? ((finfo->fieldInfo())->flags
& ((((63) & 63) << 12))) : 0) >> 12)
;
409 if (finfo_bits % 8 == 0) {
410 item_info.append(", " + tr("%Ln byte(s)", "", finfo_length));
411 } else {
412 item_info.append(", " + tr("%Ln bit(s)", "", finfo_bits));
413 }
414 }
415 }
416
417 field_status_base_ = item_info;
418 refreshFieldStatus();
419}
420
421void MainStatusBar::highlightedFieldChanged(FieldInformation * finfo)
422{
423 QString hint;
424
425 if (finfo)
426 {
427 FieldInformation::Position pos = finfo->position();
428
429 if (pos.length < 2) {
430 hint = tr("Byte %1").arg(pos.start);
431 } else {
432 hint = tr("Bytes %1-%2").arg(pos.start).arg(pos.start + pos.length - 1);
433 }
434 hint += QStringLiteral(": %1 (%2)")(QString(QtPrivate::qMakeStringPrivate(u"" ": %1 (%2)")))
435 .arg(finfo->headerInfo().name, finfo->headerInfo().abbreviation);
436 }
437
438 pushGenericStatus(STATUS_CTX_BYTE, hint);
439}
440
441void MainStatusBar::pushGenericStatus(StatusContext status, const QString &message, const QString &messagetip)
442{
443 LabelStack * stack = &info_status_;
444
445 if (status == STATUS_CTX_MAIN)
446 stack = &packet_status_;
447
448 if (message.isEmpty() && status != STATUS_CTX_FILE && status != STATUS_CTX_TEMPORARY && status != STATUS_CTX_PROGRESS)
449 popGenericStatus(status);
450 else
451 stack->pushText(message, status, messagetip);
452
453 if (status == STATUS_CTX_FILTER || status == STATUS_CTX_FILE)
454 expertUpdate();
455}
456
457void MainStatusBar::popGenericStatus(StatusContext status)
458{
459 LabelStack * stack = &info_status_;
460
461 if (status == STATUS_CTX_MAIN)
462 stack = &packet_status_;
463
464 stack->popText(status);
465}
466
467void MainStatusBar::setProfileName()
468{
469 profile_status_.setText(tr("Profile: %1").arg(get_profile_name()));
470}
471
472void MainStatusBar::appInitialized()
473{
474 setProfileName();
475 connect(mainApp->mainWindow(), &MainWindow::framesSelected, this, &MainStatusBar::selectedFrameChanged);
476}
477
478void MainStatusBar::selectedFrameChanged(QList<int>)
479{
480 showCaptureStatistics();
481}
482
483void MainStatusBar::showCaptureStatistics()
484{
485 QString packets_str;
486
487 QList<int> rows;
488 MainWindow * mw = mainApp->mainWindow();
489 // Only a single selected packet is shown, so don't build the
490 // list of a large selection.
491 if (mw && !mw->hasSelection()) {
492 rows = mw->selectedRows(true);
493 }
494
495#ifdef HAVE_LIBPCAP1
496 if (cap_file_) {
497 /* Do we have any packets? */
498 if (!cs_fixed_) {
499 cs_count_ = cap_file_->count;
500 }
501 if (cs_count_ > 0) {
502 if (prefs.gui_show_selected_packet && rows.count() == 1) {
503 packets_str.append(tr("Selected Packet: %1 %2 ")
504 .arg(rows.at(0))
505 .arg(UTF8_MIDDLE_DOT"\u00b7"));
506 }
507 packets_str.append(tr("Packets: %1").arg(cs_count_));
508
509 if (cap_file_->dfilter) {
510 packets_str.append(tr(" %1 Displayed: %2 (%3%)")
511 .arg(UTF8_MIDDLE_DOT"\u00b7")
512 .arg(cap_file_->displayed_count)
513 .arg((100.0*cap_file_->displayed_count)/cs_count_, 0, 'f', 1));
514 }
515 if (recent.aggregation_view) {
516 packets_str.append(tr(" %1 Aggregated: %2")
517 .arg(UTF8_MIDDLE_DOT"\u00b7")
518 .arg(cap_file_->aggregation_count));
519 }
520 if (rows.count() > 1) {
521 packets_str.append(tr(" %1 Selected: %2 (%3%)")
522 .arg(UTF8_MIDDLE_DOT"\u00b7")
523 .arg(rows.count())
524 .arg((100.0*rows.count())/cs_count_, 0, 'f', 1));
525 }
526 if (cap_file_->marked_count > 0) {
527 packets_str.append(tr(" %1 Marked: %2 (%3%)")
528 .arg(UTF8_MIDDLE_DOT"\u00b7")
529 .arg(cap_file_->marked_count)
530 .arg((100.0*cap_file_->marked_count)/cs_count_, 0, 'f', 1));
531 }
532 if (cap_file_->drops_known) {
533 packets_str.append(tr(" %1 Dropped: %2 (%3%)")
534 .arg(UTF8_MIDDLE_DOT"\u00b7")
535 .arg(cap_file_->drops)
536 .arg((100.0*cap_file_->drops)/(cs_count_ + cap_file_->drops), 0, 'f', 1));
537 }
538 if (cap_file_->ignored_count > 0) {
539 packets_str.append(tr(" %1 Ignored: %2 (%3%)")
540 .arg(UTF8_MIDDLE_DOT"\u00b7")
541 .arg(cap_file_->ignored_count)
542 .arg((100.0*cap_file_->ignored_count)/cs_count_, 0, 'f', 1));
543 }
544 if (cap_file_->packet_comment_count > 0) {
545 packets_str.append(tr(" %1 Comments: %2")
546 .arg(UTF8_MIDDLE_DOT"\u00b7")
547 .arg(cap_file_->packet_comment_count));
548 }
549 if (prefs.gui_show_file_load_time && !cap_file_->is_tempfile) {
550 /* Loading an existing file */
551 unsigned long computed_elapsed = cf_get_computed_elapsed(cap_file_);
552 packets_str.append(tr(" %1 Load time: %2:%3.%4")
553 .arg(UTF8_MIDDLE_DOT"\u00b7")
554 .arg(computed_elapsed/60000, 2, 10, QLatin1Char('0'))
555 .arg(computed_elapsed%60000/1000, 2, 10, QLatin1Char('0'))
556 .arg(computed_elapsed%1000, 3, 10, QLatin1Char('0')));
557 }
558 }
559 } else if (cs_fixed_ && cs_count_ > 0) {
560 /* There shouldn't be any rows without a cap_file_ but this is benign */
561 if (prefs.gui_show_selected_packet && rows.count() == 1) {
562 packets_str.append(tr("Selected Packet: %1 %2 ")
563 .arg(rows.at(0))
564 .arg(UTF8_MIDDLE_DOT"\u00b7"));
565 }
566 packets_str.append(tr("Packets: %1")
567 .arg(cs_count_));
568 }
569#endif // HAVE_LIBPCAP
570
571 if (packets_str.isEmpty()) {
572 packets_str = tr("No Packets");
573 }
574
575 popGenericStatus(STATUS_CTX_MAIN);
576 pushGenericStatus(STATUS_CTX_MAIN, packets_str);
577}
578
579// These two counts are different in multiple file mode. cap_session->count
580// is the total number in the session across all files; cap_file_->count is
581// count in the current file. Perhaps we could display both in both cases?
582
583void MainStatusBar::updateCaptureStatistics(capture_session *cap_session)
584{
585 cs_fixed_ = false;
586
587#ifndef HAVE_LIBPCAP1
588 Q_UNUSED(cap_session)(void)cap_session;
589#else
590 if ((!cap_session || cap_session->cf == cap_file_) && cap_file_ && cap_file_->count) {
591 cs_count_ = cap_file_->count;
592 } else {
593 cs_count_ = 0;
594 }
595#endif // HAVE_LIBPCAP
596
597 showCaptureStatistics();
598}
599
600void MainStatusBar::updateCaptureFixedStatistics(capture_session *cap_session)
601{
602 cs_fixed_ = true;
603
604#ifndef HAVE_LIBPCAP1
605 Q_UNUSED(cap_session)(void)cap_session;
606#else
607 if (cap_session && cap_session->count) {
608 cs_count_ = cap_session->count;
609 } else {
610 cs_count_ = 0;
611 }
612#endif // HAVE_LIBPCAP
613
614 showCaptureStatistics();
615}
616
617void MainStatusBar::showProfileMenu(const QPoint &global_pos, Qt::MouseButton button)
618{
619 //Use the model object to pull the profile information
620 ProfileModel model;
621 ProfileSortModel sortModel;
622 sortModel.setSourceModel(&model);
623 sortModel.sort(0, Qt::DescendingOrder);
624
625 QMenu * ctx_menu_;
626 QMenu * profile_menu;
627 if (button == Qt::LeftButton) {
1
Assuming 'button' is equal to LeftButton
2
Taking true branch
628 ctx_menu_ = nullptr;
629 profile_menu = new QMenu(this);
630 profile_menu->setAttribute(Qt::WA_DeleteOnClose);
631 } else {
632 ctx_menu_ = new QMenu(this);
633 ctx_menu_->setAttribute(Qt::WA_DeleteOnClose);
634 profile_menu = new QMenu(ctx_menu_);
635 }
636
637 const ProfileItem* currentProfile = model.getCurrentProfile();
638
639 // Add the profiles of one scope, using a submenu for profiles with children
640 std::function<void(QMenu *, const QModelIndex &, bool)> addProfiles;
641 // NOLINTNEXTLINE(misc-no-recursion)
642 addProfiles = [&](QMenu * menu, const QModelIndex &parent, bool global) {
643 for (int i = 0; i < sortModel.rowCount(parent); ++i)
644 {
645 //Go through the proxy model to get the profile information in the right order
646 QModelIndex proxyIndex = sortModel.index(i, 0, parent);
647 const ProfileItem* profile = model.getProfile(sortModel.mapToSource(proxyIndex));
648 if (profile == Q_NULLPTRnullptr || profile->isGlobal() != global)
649 continue;
650
651 /* Check if this profile does not exist as user */
652 bool hidden = global && model.getPersonalProfile(profile->getName()) != Q_NULLPTRnullptr;
653 bool hasChildren = sortModel.rowCount(proxyIndex) > 0;
654 if (hidden && !hasChildren)
655 continue;
656
657 // An ampersand in the menu item's text sets Alt+F as a shortcut for this menu.
658 // Use "&&" to get a real ampersand in the menu bar.
659 QString name = profile->getLeafName();
660 name.replace('&', "&&");
661
662 QMenu * subMenu = hasChildren ? menu->addMenu(name) : menu;
663
664 if (hasChildren)
665 {
666 QFont subMenuFont = subMenu->menuAction()->font();
667 subMenuFont.setItalic(profile->isGlobal());
668 // Show the path to the current profile in bold, including the current profile itself
669 if ((currentProfile != Q_NULLPTRnullptr) &&
670 (currentProfile->getName().compare(profile->getName()) == 0 ||
671 currentProfile->getName().startsWith(profile->getName() + "/")) &&
672 profile->isGlobal() == currentProfile->isGlobal())
673 subMenuFont.setBold(true);
674 subMenu->menuAction()->setFont(subMenuFont);
675 }
676 if (!hidden)
677 {
678 QAction * pa = subMenu->addAction(name);
679 QFont profileFont;
680 pa->setCheckable(true);
681 if ((currentProfile != Q_NULLPTRnullptr) &&
682 (profile->getName().compare(currentProfile->getName()) == 0) &&
683 profile->isGlobal() == currentProfile->isGlobal())
684 {
685 profileFont.setBold(true);
686 pa->setChecked(true);
687 }
688
689 if (profile->isGlobal())
690 profileFont.setItalic(true);
691
692 pa->setFont(profileFont);
693 pa->setProperty("profile_name", profile->getName());
694 pa->setProperty("profile_is_global", profile->isGlobal());
695
696 connect(pa, &QAction::triggered, this, &MainStatusBar::switchToProfile);
697 }
698
699 if (hasChildren)
700 {
701 subMenu->addSeparator();
702 addProfiles(subMenu, proxyIndex, global);
703
704 // Remove a submenu with only the separator, when the profile and all its children are hidden
705 if (subMenu->actions().count() <= 1)
706 delete subMenu;
707 }
708 }
709 };
710
711 addProfiles(profile_menu, QModelIndex(), false);
712 profile_menu->addSeparator();
713 addProfiles(profile_menu, QModelIndex(), true);
714
715 SubMenuPlacer *placer = new SubMenuPlacer(profile_menu);
3
Memory is allocated
716 for (QMenu *subMenu : profile_menu->findChildren<QMenu *>())
717 subMenu->installEventFilter(placer);
718
719 if (button
3.1
'button' is equal to LeftButton
== Qt::LeftButton) {
4
Taking true branch
720 profile_menu->popup(global_pos);
5
Potential leak of memory pointed to by 'placer'
721 } else {
722
723 bool enable_edit = false;
724
725 if ((currentProfile != Q_NULLPTRnullptr) && !currentProfile->isDefault() && !currentProfile->isGlobal())
726 enable_edit = true;
727
728 profile_menu->setTitle(tr("Switch to"));
729 QAction * action = ctx_menu_->addAction(tr("Manage Profiles…"), this, SLOT(manageProfile())qFlagLocation("1" "manageProfile()" "\0" "ui/qt/main_status_bar.cpp"
":" "729")
);
730 action->setProperty("dialog_action_", (int)ProfileDialog::ShowProfiles);
731
732 ctx_menu_->addSeparator();
733 action = ctx_menu_->addAction(tr("New…"), this, SLOT(manageProfile())qFlagLocation("1" "manageProfile()" "\0" "ui/qt/main_status_bar.cpp"
":" "733")
);
734 action->setProperty("dialog_action_", (int)ProfileDialog::NewProfile);
735 action = ctx_menu_->addAction(tr("Edit…"), this, SLOT(manageProfile())qFlagLocation("1" "manageProfile()" "\0" "ui/qt/main_status_bar.cpp"
":" "735")
);
736 action->setProperty("dialog_action_", (int)ProfileDialog::EditCurrentProfile);
737 action->setEnabled(enable_edit);
738 action = ctx_menu_->addAction(tr("Delete"), this, SLOT(manageProfile())qFlagLocation("1" "manageProfile()" "\0" "ui/qt/main_status_bar.cpp"
":" "738")
);
739 action->setProperty("dialog_action_", (int)ProfileDialog::DeleteCurrentProfile);
740 action->setEnabled(enable_edit);
741 ctx_menu_->addSeparator();
742
743#if defined(HAVE_MINIZIP1) || defined(HAVE_MINIZIPNG)
744 QMenu * importMenu = new QMenu(tr("Import"), ctx_menu_);
745 action = importMenu->addAction(tr("From Zip File…"), this, SLOT(manageProfile())qFlagLocation("1" "manageProfile()" "\0" "ui/qt/main_status_bar.cpp"
":" "745")
);
746 action->setProperty("dialog_action_", (int)ProfileDialog::ImportZipProfile);
747 action = importMenu->addAction(tr("From Directory…"), this, SLOT(manageProfile())qFlagLocation("1" "manageProfile()" "\0" "ui/qt/main_status_bar.cpp"
":" "747")
);
748 action->setProperty("dialog_action_", (int)ProfileDialog::ImportDirProfile);
749 ctx_menu_->addMenu(importMenu);
750
751 if (model.userProfilesExist())
752 {
753 QMenu * exportMenu = new QMenu(tr("Export"), ctx_menu_);
754 if (enable_edit)
755 {
756 action = exportMenu->addAction(tr("Selected Personal Profile…"), this, SLOT(manageProfile())qFlagLocation("1" "manageProfile()" "\0" "ui/qt/main_status_bar.cpp"
":" "756")
);
757 action->setProperty("dialog_action_", (int)ProfileDialog::ExportSingleProfile);
758 action->setEnabled(enable_edit);
759
760 qsizetype count = model.withChildren({model.findByName(currentProfile->getName())}).count();
761 if (count > 1)
762 {
763 action = exportMenu->addAction(tr("%Ln Personal Profile(s) (including sub-profiles)…", "", static_cast<int>(count)), this, SLOT(manageProfile())qFlagLocation("1" "manageProfile()" "\0" "ui/qt/main_status_bar.cpp"
":" "763")
);
764 action->setProperty("dialog_action_", (int)ProfileDialog::ExportSingleProfileWithChildren);
765 }
766 }
767 action = exportMenu->addAction(tr("All Personal Profiles…"), this, SLOT(manageProfile())qFlagLocation("1" "manageProfile()" "\0" "ui/qt/main_status_bar.cpp"
":" "767")
);
768 action->setProperty("dialog_action_", (int)ProfileDialog::ExportAllProfiles);
769 ctx_menu_->addMenu(exportMenu);
770 }
771
772#else
773 action = ctx_menu_->addAction(tr("Import"), this, SLOT(manageProfile())qFlagLocation("1" "manageProfile()" "\0" "ui/qt/main_status_bar.cpp"
":" "773")
);
774 action->setProperty("dialog_action_", (int)ProfileDialog::ImportDirProfile);
775#endif
776 ctx_menu_->addSeparator();
777
778 ctx_menu_->addMenu(profile_menu);
779 ctx_menu_->popup(global_pos);
780 }
781}
782
783void MainStatusBar::toggleBackground(bool enabled)
784{
785 if (enabled) {
786 setStyleSheet(QStringLiteral((QString(QtPrivate::qMakeStringPrivate(u"" "QStatusBar {" " background-color: %2;"
"}")))
787 "QStatusBar {"(QString(QtPrivate::qMakeStringPrivate(u"" "QStatusBar {" " background-color: %2;"
"}")))
788 " background-color: %2;"(QString(QtPrivate::qMakeStringPrivate(u"" "QStatusBar {" " background-color: %2;"
"}")))
789 "}"(QString(QtPrivate::qMakeStringPrivate(u"" "QStatusBar {" " background-color: %2;"
"}")))
790 )(QString(QtPrivate::qMakeStringPrivate(u"" "QStatusBar {" " background-color: %2;"
"}")))
791 .arg(ColorUtils::warningBackground().name()));
792 } else {
793 setStyleSheet(QString());
794 }
795}
796
797void MainStatusBar::switchToProfile()
798{
799 QAction *pa = qobject_cast<QAction*>(sender());
800
801 if (pa && pa->property("profile_name").isValid()) {
802 QString profile = pa->property("profile_name").toString();
803 mainApp->setConfigurationProfile(profile.toUtf8().constData());
804 }
805}
806
807void MainStatusBar::manageProfile()
808{
809 QAction *pa = qobject_cast<QAction*>(sender());
810
811 if (pa) {
812 ProfileDialog * cp_dialog = new ProfileDialog(this);
813 cp_dialog->setAttribute(Qt::WA_DeleteOnClose);
814
815 int profileAction = pa->property("dialog_action_").toInt();
816 cp_dialog->execAction(static_cast<ProfileDialog::ProfileAction>(profileAction));
817 }
818}
819
820void MainStatusBar::captureEventHandler(CaptureEvent ev)
821{
822 switch(ev.captureContext())
823 {
824#ifdef HAVE_LIBPCAP1
825 case CaptureEvent::Update:
826 switch (ev.eventType())
827 {
828 case CaptureEvent::Continued:
829 updateCaptureStatistics(ev.capSession());
830 break;
831 case CaptureEvent::Finished:
832 updateCaptureStatistics(ev.capSession());
833 break;
834 default:
835 break;
836 }
837 break;
838 case CaptureEvent::Fixed:
839 switch (ev.eventType())
840 {
841 case CaptureEvent::Continued:
842 updateCaptureFixedStatistics(ev.capSession());
843 break;
844 default:
845 break;
846 }
847 break;
848#endif
849 case CaptureEvent::Save:
850 switch (ev.eventType())
851 {
852 case CaptureEvent::Finished:
853 case CaptureEvent::Failed:
854 case CaptureEvent::Stopped:
855 popGenericStatus(STATUS_CTX_FILE);
856 break;
857 default:
858 break;
859 }
860 break;
861 default:
862 break;
863 }
864}