Bug Summary

File:builds/wireshark/wireshark/ui/qt/main_application.cpp
Warning:line 626, column 13
Potential memory leak

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_application.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-21/lib/clang/21 -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 /usr/include/x86_64-linux-gnu/qt6/QtWidgets -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/QtGui -isystem /usr/include/x86_64-linux-gnu/qt6/QtCore5Compat -isystem /usr/include/x86_64-linux-gnu/qt6/QtConcurrent -isystem /usr/include/x86_64-linux-gnu/qt6/QtPrintSupport -isystem /usr/include/x86_64-linux-gnu/qt6/QtNetwork -isystem /usr/include/x86_64-linux-gnu/qt6/QtMultimedia -isystem /usr/include/x86_64-linux-gnu/qt6/QtDBus -D G_DISABLE_DEPRECATED -D G_DISABLE_SINGLE_INCLUDES -D QT_CONCURRENT_LIB -D QT_CORE5COMPAT_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_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/14/../../../../include/c++/14 -internal-isystem /usr/lib/gcc/x86_64-linux-gnu/14/../../../../include/x86_64-linux-gnu/c++/14 -internal-isystem /usr/lib/gcc/x86_64-linux-gnu/14/../../../../include/c++/14/backward -internal-isystem /usr/lib/llvm-21/lib/clang/21/include -internal-isystem /usr/local/include -internal-isystem /usr/lib/gcc/x86_64-linux-gnu/14/../../../../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 -D__GCC_HAVE_DWARF2_CFI_ASM=1 -o /builds/wireshark/wireshark/sbout/2026-04-11-100403-3641-1 -x c++ /builds/wireshark/wireshark/ui/qt/main_application.cpp
1/* main_application.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// warning C4267: 'argument' : conversion from 'size_t' to 'int', possible loss of data
11#ifdef _MSC_VER
12#pragma warning(push)
13#pragma warning(disable : 4267)
14#endif
15
16#define WS_LOG_DOMAIN"Main" LOG_DOMAIN_MAIN"Main"
17
18#include "main_application.h"
19
20#include <algorithm>
21#include <errno(*__errno_location ()).h>
22
23#include "wsutil/filesystem.h"
24#include "app/application_flavor.h"
25
26#include "epan/addr_resolv.h"
27#include "epan/column-utils.h"
28#include "epan/disabled_protos.h"
29#include "epan/ftypes/ftypes.h"
30#include "epan/prefs.h"
31#include "epan/proto.h"
32#include "epan/tap.h"
33#include "epan/timestamp.h"
34#include "epan/decode_as.h"
35#include "epan/dfilter/dfilter-macro.h"
36
37#include "ui/commandline.h"
38#include "ui/decode_as_utils.h"
39#include "ui/preference_utils.h"
40#include "ui/iface_lists.h"
41#include "ui/language.h"
42#include "ui/recent.h"
43#include "ui/simple_dialog.h"
44#include "ui/util.h"
45
46#include <ui/qt/utils/qt_ui_utils.h>
47#include <ui/qt/utils/color_utils.h>
48#include <ui/qt/utils/software_update.h>
49#include "coloring_rules_dialog.h"
50
51#include "epan/color_filters.h"
52
53#include "extcap.h"
54#ifdef HAVE_LIBPCAP1
55#include <capture/iface_monitor.h>
56#endif
57
58#include "wsutil/filter_files.h"
59#include "ui/capture_globals.h"
60#include "ui/file_dialog.h"
61#include "ui/recent_utils.h"
62
63#ifdef HAVE_LIBPCAP1
64#include "ui/capture.h"
65#endif
66
67#include "wsutil/utf8_entities.h"
68
69#ifdef _WIN32
70# include "wsutil/file_util.h"
71# include <QMessageBox>
72# include <QSettings>
73#endif /* _WIN32 */
74
75#include <ui/qt/capture_file.h>
76
77#include <ui/qt/main_window.h>
78#include <ui/qt/main_status_bar.h>
79#include <ui/qt/utils/workspace_state.h>
80
81#include <QAction>
82#include <QApplication>
83#include <QColorDialog>
84#include <QDesktopServices>
85#include <QDir>
86#include <QEvent>
87#include <QFileOpenEvent>
88#include <QFontInfo>
89#include <QFontMetrics>
90#include <QLibraryInfo>
91#include <QLocale>
92#include <QMainWindow>
93#include <QMutableListIterator>
94#include <QProxyStyle>
95#include <QSocketNotifier>
96#include <QThreadPool>
97#include <QUrl>
98#include <qmath.h>
99
100#if (QT_VERSION((6<<16)|(4<<8)|(2)) < QT_VERSION_CHECK(6, 0, 0)((6<<16)|(0<<8)|(0)))
101#include <QFontDatabase>
102#endif
103#include <QMimeDatabase>
104
105#include <QStyleHints>
106
107#if QT_VERSION((6<<16)|(4<<8)|(2)) >= QT_VERSION_CHECK(6, 5, 0)((6<<16)|(5<<8)|(0)) && defined(Q_OS_WIN)
108#include <QStyleFactory>
109#endif
110
111#ifdef _MSC_VER
112#pragma warning(pop)
113#endif
114
115MainApplication *mainApp;
116
117// XXX - Copied from ui/gtk/file_dlg.c
118
119static QHash<int, QList<QAction *> > dynamic_menu_groups_;
120static QHash<int, QList<QAction *> > added_menu_groups_;
121static QHash<int, QList<QAction *> > removed_menu_groups_;
122
123QString MainApplication::window_title_separator_ = QString::fromUtf8(" " UTF8_MIDDLE_DOT"\u00b7" " ");
124
125// QMimeDatabase parses a large-ish XML file and can be slow to initialize.
126// Do so in a worker thread as early as possible.
127// https://github.com/lxde/pcmanfm-qt/issues/415
128class MimeDatabaseInitThread : public QRunnable
129{
130private:
131 void run()
132 {
133 QMimeDatabase mime_db;
134 mime_db.mimeTypeForData(QByteArray());
135 }
136};
137
138#if (QT_VERSION((6<<16)|(4<<8)|(2)) < QT_VERSION_CHECK(6, 0, 0)((6<<16)|(0<<8)|(0)))
139// Populating the font database can be slow as well.
140class FontDatabaseInitThread : public QRunnable
141{
142private:
143 void run()
144 {
145 QFontDatabase font_db;
146 }
147};
148#endif
149
150void
151topic_action(topic_action_e action)
152{
153 if (mainApp) mainApp->helpTopicAction(action);
154}
155
156/* write all capture filenames of the menu to the user's recent file */
157extern "C" void menu_recent_file_write_all(FILE *rf) {
158
159 const QList<RecentFileInfo>& recentFiles = WorkspaceState::instance()->recentCaptureFiles();
160 int rFSize = static_cast<int>(recentFiles.size());
161 for (int i = 0; i < rFSize; i++) {
162 const RecentFileInfo& rfi = recentFiles.at(i);
163
164 QString cf_name = rfi.filename;
165 if (!cf_name.isNull()) {
166 fprintf (rf, RECENT_KEY_CAPTURE_FILE"recent.capture_file" ": %s\n", qUtf8Printable(cf_name)QtPrivate::asString(cf_name).toUtf8().constData());
167 }
168 }
169}
170
171void MainApplication::refreshPacketData()
172{
173 if (host_name_lookup_process()) {
174 emit addressResolutionChanged();
175 } else if (col_data_changed()) {
176 emit columnDataChanged();
177 }
178}
179
180// The Fusion style, and the Mac style, allow QMessageBox text to be
181// selectable by the mouse. The various Windows styles do not. On
182// Windows we switch between the Fusion style and Windows style depending
183// on dark mode, so to make things consistent on Windows (and between
184// Windows and other platforms) alllow it on all styles.
185class MsgBoxTextStyle : public QProxyStyle
186{
187public:
188 MsgBoxTextStyle(QStyle *style = nullptr) : QProxyStyle(style) {}
189 MsgBoxTextStyle(const QString &key) : QProxyStyle(key) {}
190 int styleHint(StyleHint hint, const QStyleOption *option = nullptr,
191 const QWidget *widget = nullptr, QStyleHintReturn *returnData = nullptr) const override
192 {
193 if (hint == QStyle::SH_MessageBox_TextInteractionFlags)
194 return QProxyStyle::styleHint(hint, option, widget, returnData) | Qt::TextSelectableByMouse;
195 return QProxyStyle::styleHint(hint, option, widget, returnData);
196 }
197};
198
199#if QT_VERSION((6<<16)|(4<<8)|(2)) >= QT_VERSION_CHECK(6, 5, 0)((6<<16)|(5<<8)|(0)) && defined(Q_OS_WIN)
200void MainApplication::colorSchemeChanged() {
201 // TODO - Supposedly the windows11 style handles dark mode better.
202 if (ColorUtils::themeIsDark()) {
203 setStyle(QStyleFactory::create("fusion"));
204 } else {
205 setStyle(new MsgBoxTextStyle("windowsvista"));
206 }
207}
208#endif
209
210void MainApplication::updateTaps()
211{
212 draw_tap_listeners(false);
213}
214
215QDir MainApplication::openDialogInitialDir() {
216 return QDir(get_open_dialog_initial_dir());
217}
218
219void MainApplication::setLastOpenDirFromFilename(const QString file_name)
220{
221 /* XXX - Use canonicalPath() instead of absolutePath()? */
222 QString directory = QDir::toNativeSeparators(QFileInfo(file_name).absolutePath());
223 /* XXX - printable? */
224 set_last_open_dir(qUtf8Printable(directory)QtPrivate::asString(directory).toUtf8().constData());
225}
226
227void MainApplication::helpTopicAction(topic_action_e action)
228{
229 QString url = gchar_free_to_qstring(topic_action_url(action));
230
231 if (!url.isEmpty()) {
232 QDesktopServices::openUrl(QUrl(QDir::fromNativeSeparators(url)));
233 }
234}
235
236const QFont MainApplication::monospaceFont(bool zoomed) const
237{
238 if (zoomed) {
239 return zoomed_font_;
240 }
241 return mono_font_;
242}
243
244void MainApplication::setMonospaceFont(const char *font_string) {
245
246 if (font_string && strlen(font_string) > 0) {
247#if (QT_VERSION((6<<16)|(4<<8)|(2)) < QT_VERSION_CHECK(6, 0, 0)((6<<16)|(0<<8)|(0)))
248 // Qt 6's QFont::toString returns a value with 16 or 17 fields, e.g.
249 // Consolas,11,-1,5,400,0,0,0,0,0,0,0,0,0,0,1
250 // Corbel,10,-1,5,400,0,0,0,0,0,0,0,0,0,0,1,Regular
251 // Qt 5's QFont::fromString expects a value with 10 or 11 fields, e.g.
252 // Consolas,10,-1,5,50,0,0,0,0,0
253 // Corbel,10,-1,5,50,0,0,0,0,0,Regular
254 // It looks like Qt6's QFont::fromString can read both forms:
255 // https://github.com/qt/qtbase/blob/6.0/src/gui/text/qfont.cpp#L2146
256 // but Qt5's cannot:
257 // https://github.com/qt/qtbase/blob/5.15/src/gui/text/qfont.cpp#L2151
258 const char *fs_ptr = font_string;
259 int field_count = 1;
260 while ((fs_ptr = strchr(fs_ptr, ',')) != NULL__null) {
261 fs_ptr++;
262 field_count++;
263 }
264 if (field_count <= 11) {
265#endif
266 mono_font_.fromString(font_string);
267
268 // Only accept the font name if it actually exists.
269 if (mono_font_.family() == QFontInfo(mono_font_).family()) {
270 return;
271 } else {
272 ws_warning("Monospace font family %s differs from its fontinfo: %s",do { if (true) { ws_log_full("Main", LOG_LEVEL_WARNING, "ui/qt/main_application.cpp"
, 273, __func__, "Monospace font family %s differs from its fontinfo: %s"
, QtPrivate::asString(mono_font_.family()).toUtf8().constData
(), QtPrivate::asString(QFontInfo(mono_font_).family()).toUtf8
().constData()); } } while (0)
273 qUtf8Printable(mono_font_.family()), qUtf8Printable(QFontInfo(mono_font_).family()))do { if (true) { ws_log_full("Main", LOG_LEVEL_WARNING, "ui/qt/main_application.cpp"
, 273, __func__, "Monospace font family %s differs from its fontinfo: %s"
, QtPrivate::asString(mono_font_.family()).toUtf8().constData
(), QtPrivate::asString(QFontInfo(mono_font_).family()).toUtf8
().constData()); } } while (0)
;
274 }
275#if (QT_VERSION((6<<16)|(4<<8)|(2)) < QT_VERSION_CHECK(6, 0, 0)((6<<16)|(0<<8)|(0)))
276 } else {
277 ws_warning("Monospace font %s appears to be from Qt6 and we're running Qt5.", font_string)do { if (true) { ws_log_full("Main", LOG_LEVEL_WARNING, "ui/qt/main_application.cpp"
, 277, __func__, "Monospace font %s appears to be from Qt6 and we're running Qt5."
, font_string); } } while (0)
;
278 }
279#endif
280 }
281
282 // https://en.wikipedia.org/wiki/Category:Monospaced_typefaces
283 const char *win_default_font = "Consolas";
284 const char *win_alt_font = "Lucida Console";
285 // SF Mono might be a system font someday. Right now (Oct 2016) it appears
286 // to be limited to Xcode and Terminal.
287 // http://www.openradar.me/26790072
288 // http://www.openradar.me/26862220
289 const char *osx_default_font = "SF Mono";
290 const QStringList osx_alt_fonts = QStringList() << "Menlo" << "Monaco";
291 // XXX Detect Ubuntu systems (e.g. via /etc/os-release and/or
292 // /etc/lsb_release) and add "Ubuntu Mono Regular" there.
293 // https://design.ubuntu.com/font/
294 const char *x11_default_font = "Liberation Mono";
295 const QStringList x11_alt_fonts = QStringList() << "DejaVu Sans Mono" << "Bitstream Vera Sans Mono";
296 const QStringList fallback_fonts = QStringList() << "Lucida Sans Typewriter" << "Inconsolata" << "Droid Sans Mono" << "Andale Mono" << "Courier New" << "monospace";
297 QStringList substitutes;
298 int font_size_adjust = 0;
299
300 // Try to pick the latest, shiniest fixed-width font for our OS.
301#if defined(Q_OS_WIN)
302 const char *default_font = win_default_font;
303 substitutes << win_alt_font << osx_default_font << osx_alt_fonts << x11_default_font << x11_alt_fonts << fallback_fonts;
304# if (QT_VERSION((6<<16)|(4<<8)|(2)) >= QT_VERSION_CHECK(6, 0, 0)((6<<16)|(0<<8)|(0)))
305 font_size_adjust = 1;
306# else // QT_VERSION
307 font_size_adjust = 2;
308# endif // QT_VERSION
309#elif defined(Q_OS_MAC)
310 const char *default_font = osx_default_font;
311 substitutes << osx_alt_fonts << win_default_font << win_alt_font << x11_default_font << x11_alt_fonts << fallback_fonts;
312#else // Q_OS
313 const char *default_font = x11_default_font;
314 substitutes << x11_alt_fonts << win_default_font << win_alt_font << osx_default_font << osx_alt_fonts << fallback_fonts;
315#endif // Q_OS
316
317 mono_font_ = QFont(default_font, mainApp->font().pointSize() + font_size_adjust);
318 mono_font_.insertSubstitutions(default_font, substitutes);
319 mono_font_.setBold(false);
320
321 // Retrieve the effective font and apply it.
322 mono_font_.setFamily(QFontInfo(mono_font_).family());
323
324 wmem_free(wmem_epan_scope(), prefs.gui_font_name);
325 prefs.gui_font_name = wmem_strdup(wmem_epan_scope(), mono_font_.toString().toUtf8().constData());
326}
327
328int MainApplication::monospaceTextSize(const char *str)
329{
330 return QFontMetrics(mono_font_).horizontalAdvance(str);
331}
332
333void MainApplication::setConfigurationProfile(const char *profile_name, bool write_recent_file)
334{
335 char *rf_path;
336 int rf_open_errno;
337 char *err_msg = NULL__null;
338 const char* env_prefix = application_configuration_environment_prefix();
339
340 bool prev_capture_no_interface_load;
341 bool prev_capture_no_extcap;
342
343 /* First check if profile exists */
344 if (!profile_exists(env_prefix, profile_name, false)) {
345 if (profile_exists(env_prefix, profile_name, true)) {
346 char *pf_dir_path, *pf_dir_path2, *pf_filename;
347 /* Copy from global profile */
348 if (create_persconffile_profile(env_prefix, profile_name, &pf_dir_path) == -1) {
349 simple_dialog(ESD_TYPE_ERROR, ESD_BTN_OK0x01,
350 "Can't create directory\n\"%s\":\n%s.",
351 pf_dir_path, g_strerror(errno(*__errno_location ())));
352
353 g_free(pf_dir_path);
354 }
355
356 if (copy_persconffile_profile(env_prefix, profile_name, profile_name, true, &pf_filename,
357 &pf_dir_path, &pf_dir_path2) == -1) {
358 simple_dialog(ESD_TYPE_ERROR, ESD_BTN_OK0x01,
359 "Can't copy file \"%s\" in directory\n\"%s\" to\n\"%s\":\n%s.",
360 pf_filename, pf_dir_path2, pf_dir_path, g_strerror(errno(*__errno_location ())));
361
362 g_free(pf_filename);
363 g_free(pf_dir_path);
364 g_free(pf_dir_path2);
365 }
366 } else {
367 /* No personal and no global profile exists */
368 return;
369 }
370 }
371
372 /* Then check if changing to another profile */
373 if (profile_name && strcmp (profile_name, get_profile_name()) == 0) {
374 return;
375 }
376
377 prev_capture_no_interface_load = prefs.capture_no_interface_load;
378 prev_capture_no_extcap = prefs.capture_no_extcap;
379
380 /* Get the current geometry, before writing it to disk */
381 emit profileChanging();
382
383 if (write_recent_file && profile_exists(env_prefix, get_profile_name(), false))
384 {
385 /* Write recent file for profile we are leaving, if it still exists */
386 write_profile_recent();
387 }
388
389 // Freeze the packet list early to avoid updating column data before doing a
390 // full redissection. The packet list will be thawed when redissection is done.
391 emit freezePacketList(true);
392
393 /* Set profile name and update the status bar */
394 set_profile_name (profile_name);
395 emit profileNameChanged(profile_name);
396
397 /* Apply new preferences */
398 readConfigurationFiles(true);
399
400 /* Apply command-line preferences */
401 commandline_options_reapply();
402 extcap_register_preferences(NULL__null, NULL__null);
403
404 /* Switching profile requires reloading the macro list. */
405 reloadDisplayFilterMacros();
406
407 if (!recent_read_profile_static(&rf_path, &rf_open_errno)) {
408 simple_dialog(ESD_TYPE_WARN, ESD_BTN_OK0x01,
409 "Could not open common recent file\n\"%s\": %s.",
410 rf_path, g_strerror(rf_open_errno));
411 g_free(rf_path);
412 }
413 if (recent.gui_fileopen_remembered_dir &&
414 test_for_directory(recent.gui_fileopen_remembered_dir) == EISDIR21) {
415 set_last_open_dir(recent.gui_fileopen_remembered_dir);
416 }
417 timestamp_set_type(recent.gui_time_format);
418 timestamp_set_precision(recent.gui_time_precision);
419 timestamp_set_seconds_type (recent.gui_seconds_format);
420
421 prefs_to_capture_opts(&global_capture_opts);
422 prefs_apply_all();
423#ifdef HAVE_LIBPCAP1
424 update_local_interfaces(&global_capture_opts);
425#endif
426
427 emit columnsChanged();
428 emit colorsChanged();
429 emit preferencesChanged();
430 emit recentPreferencesRead();
431 emit filterExpressionsChanged();
432 emit checkDisplayFilter();
433 emit captureFilterListChanged();
434 emit displayFilterListChanged();
435
436 /* Reload color filters */
437 if (!color_filters_reload(&err_msg, color_filter_add_cb, application_configuration_environment_prefix())) {
438 simple_dialog(ESD_TYPE_ERROR, ESD_BTN_OK0x01, "%s", err_msg);
439 g_free(err_msg);
440 }
441
442 /* Load interfaces if settings have changed */
443 if (!prefs.capture_no_interface_load &&
444 ((prefs.capture_no_interface_load != prev_capture_no_interface_load) ||
445 (prefs.capture_no_extcap != prev_capture_no_extcap))) {
446 refreshLocalInterfaces();
447 }
448
449 emit localInterfaceListChanged();
450 emit packetDissectionChanged();
451
452 /* Write recent_common file to ensure last used profile setting is stored. */
453 write_recent();
454}
455
456void MainApplication::reloadLuaPluginsDelayed()
457{
458 QTimer::singleShot(0, this, &MainApplication::reloadLuaPlugins);
459}
460
461const QIcon &MainApplication::normalIcon()
462{
463 if (normal_icon_.isNull()) {
464 initializeIcons();
465 }
466 return normal_icon_;
467}
468
469const QIcon &MainApplication::captureIcon()
470{
471 if (capture_icon_.isNull()) {
472 initializeIcons();
473 }
474 return capture_icon_;
475}
476
477const QString MainApplication::windowTitleString(QStringList title_parts)
478{
479 QMutableStringListIterator tii(title_parts);
480 while (tii.hasNext()) {
481 QString ti = tii.next();
482 if (ti.isEmpty()) tii.remove();
483 }
484 title_parts.prepend(applicationName());
485 return title_parts.join(window_title_separator_);
486}
487
488void MainApplication::applyCustomColorsFromRecent()
489{
490 int i = 0;
491 bool ok;
492 for (GList *custom_color = recent.custom_colors; custom_color; custom_color = custom_color->next) {
493 QRgb rgb = QString((const char *)custom_color->data).toUInt(&ok, 16);
494 if (ok) {
495 QColorDialog::setCustomColor(i++, QColor(rgb));
496 }
497 }
498}
499
500// Return the first top-level MainWindow.
501MainWindow *MainApplication::mainWindow()
502{
503 foreach (QWidget *tlw, topLevelWidgets())for (auto _container_503 = QtPrivate::qMakeForeachContainer(topLevelWidgets
()); _container_503.i != _container_503.e; ++_container_503.i
) if (QWidget *tlw = *_container_503.i; false) {} else
{
504 MainWindow *tlmw = qobject_cast<MainWindow *>(tlw);
505 if (tlmw && tlmw->isVisible()) {
506 return tlmw;
507 }
508 }
509 return nullptr;
510}
511
512void MainApplication::storeCustomColorsInRecent()
513{
514 if (QColorDialog::customCount()) {
515 prefs_clear_string_list(recent.custom_colors);
516 recent.custom_colors = NULL__null;
517 for (int i = 0; i < QColorDialog::customCount(); i++) {
518 QRgb rgb = QColorDialog::customColor(i).rgb();
519 recent.custom_colors = g_list_append(recent.custom_colors, ws_strdup_printf("%08x", rgb)wmem_strdup_printf(__null, "%08x", rgb));
520 }
521 }
522}
523
524bool MainApplication::event(QEvent *event)
525{
526 QString display_filter = NULL__null;
527 if (event->type() == QEvent::FileOpen) {
528 QFileOpenEvent *foe = static_cast<QFileOpenEvent *>(event);
529 if (foe && foe->file().length() > 0) {
530 QString cf_path(foe->file());
531 if (initialized_) {
532 emit openCaptureFile(cf_path, display_filter, WTAP_TYPE_AUTO0);
533 } else {
534 pending_open_files_.append(cf_path);
535 }
536 }
537 return true;
538 }
539 return QApplication::event(event);
540}
541
542void MainApplication::cleanup()
543{
544 SoftwareUpdate::instance()->cleanup();
545 storeCustomColorsInRecent();
546 // Write the user's recent file(s) to disk.
547 write_profile_recent();
548 write_recent();
549
550 // We might end up here via exit_application.
551 QThreadPool::globalInstance()->waitForDone();
552}
553
554MainApplication::MainApplication(int &argc, char **argv) :
555 QApplication(argc, argv),
556 initialized_(false),
557 is_reloading_lua_(false),
558 if_notifier_(NULL__null),
559 active_captures_(0),
560 refresh_interfaces_pending_(false)
561#if defined(Q_OS_MAC) || defined(Q_OS_WIN)
562 , normal_icon_(windowIcon())
563#endif
564#ifdef HAVE_LIBPCAP1
565 , cached_if_list_(NULL__null)
566#endif
567{
568 mainApp = this;
569
570 MimeDatabaseInitThread *mime_db_init_thread = new(MimeDatabaseInitThread);
571 QThreadPool::globalInstance()->start(mime_db_init_thread);
572#if (QT_VERSION((6<<16)|(4<<8)|(2)) < QT_VERSION_CHECK(6, 0, 0)((6<<16)|(0<<8)|(0)))
573 FontDatabaseInitThread *font_db_init_thread = new (FontDatabaseInitThread);
574 QThreadPool::globalInstance()->start(font_db_init_thread);
575#endif
576
577 Q_INIT_RESOURCE(about)do { extern int qInitResources_about (); qInitResources_about
(); } while (false)
;
1
Loop condition is false. Exiting loop
578 Q_INIT_RESOURCE(i18n)do { extern int qInitResources_i18n (); qInitResources_i18n (
); } while (false)
;
2
Loop condition is false. Exiting loop
579 Q_INIT_RESOURCE(layout)do { extern int qInitResources_layout (); qInitResources_layout
(); } while (false)
;
3
Loop condition is false. Exiting loop
580 Q_INIT_RESOURCE(stock_icons)do { extern int qInitResources_stock_icons (); qInitResources_stock_icons
(); } while (false)
;
4
Loop condition is false. Exiting loop
581 Q_INIT_RESOURCE(languages)do { extern int qInitResources_languages (); qInitResources_languages
(); } while (false)
;
5
Loop condition is false. Exiting loop
582
583#ifdef Q_OS_WIN
584 /* RichEd20.DLL is needed for native file dialog filter entries. */
585 ws_load_library("riched20.dll");
586#endif // Q_OS_WIN
587
588#if (QT_VERSION((6<<16)|(4<<8)|(2)) < QT_VERSION_CHECK(6, 0, 0)((6<<16)|(0<<8)|(0)))
589 setAttribute(Qt::AA_UseHighDpiPixmaps);
590#endif
591
592#if QT_VERSION((6<<16)|(4<<8)|(2)) < QT_VERSION_CHECK(6, 0, 0)((6<<16)|(0<<8)|(0))
593 setAttribute(Qt::AA_DisableWindowContextHelpButton);
594#endif
595
596 // We use a lot of style sheets that base their colors on the main
597 // application palette, so this works better.
598 setAttribute(Qt::AA_UseStyleSheetPropagationInWidgetStyles, true);
599
600 // Throw various settings at the wall with the hope that one of them will
601 // enable context menu shortcuts QTBUG-69452, QTBUG-109590
602 setAttribute(Qt::AA_DontShowShortcutsInContextMenus, false);
603 styleHints()->setShowShortcutsInContextMenus(true);
604
605 packet_data_timer_.setParent(this);
606 connect(&packet_data_timer_, &QTimer::timeout, this, &MainApplication::refreshPacketData);
607 packet_data_timer_.start(1000);
608
609 tap_update_timer_.setParent(this);
610 // tap_update_timer interval is set when preferences are set before init
611 connect(this, &MainApplication::appInitialized, &tap_update_timer_, [&]() { tap_update_timer_.start(); });
612 connect(this, &MainApplication::appInitialized, [this] { emit aggregationVisiblity(); });
613 connect(&tap_update_timer_, &QTimer::timeout, this, &MainApplication::updateTaps);
614
615
616 // If our window text is lighter than the window background, assume the theme is dark.
617 prefs_set_gui_theme_is_dark(ColorUtils::themeIsDark());
618
619#if QT_VERSION((6<<16)|(4<<8)|(2)) >= QT_VERSION_CHECK(6, 5, 0)((6<<16)|(5<<8)|(0)) && defined(Q_OS_WIN)
620 colorSchemeChanged();
621 connect(styleHints(), &QStyleHints::colorSchemeChanged, this, &MainApplication::colorSchemeChanged);
622#else
623 setStyle(new MsgBoxTextStyle);
6
Memory is allocated
624#endif
625
626 connect(qApp(static_cast<QApplication *>(QCoreApplication::instance
()))
, &QApplication::aboutToQuit, this, &MainApplication::cleanup);
7
Potential memory leak
627}
628
629MainApplication::~MainApplication()
630{
631 mainApp = NULL__null;
632#ifdef HAVE_LIBPCAP1
633 free_interface_list(cached_if_list_);
634#endif
635 clearDynamicMenuGroupItems();
636}
637
638void MainApplication::emitAppSignal(AppSignal signal)
639{
640 switch (signal) {
641 case ColumnsChanged:
642 emit columnsChanged();
643 break;
644 case CaptureFilterListChanged:
645 emit captureFilterListChanged();
646 break;
647 case DisplayFilterListChanged:
648 emit displayFilterListChanged();
649 break;
650 case FilterExpressionsChanged:
651 emit filterExpressionsChanged();
652 break;
653 case LocalInterfacesChanged:
654 emit localInterfaceListChanged();
655 break;
656 case NameResolutionChanged:
657 emit addressResolutionChanged();
658 break;
659 case PreferencesChanged:
660 tap_update_timer_.setInterval(prefs.tap_update_interval);
661 setMonospaceFont(prefs.gui_font_name);
662 emit preferencesChanged();
663 break;
664 case PacketDissectionChanged:
665 emit packetDissectionChanged();
666 break;
667 case ProfileChanging:
668 emit profileChanging();
669 break;
670 case RecentPreferencesRead:
671 emit recentPreferencesRead();
672 break;
673 case FieldsChanged:
674 emit fieldsChanged();
675 break;
676 case ColorsChanged:
677 ColorUtils::setScheme(prefs.gui_color_scheme);
678 emit colorsChanged();
679 break;
680 case FreezePacketList:
681 emit freezePacketList(false);
682 break;
683 case AggregationVisiblity:
684 emit aggregationVisiblity();
685 break;
686 case AggregationChanged:
687 emit aggregationChanged();
688 break;
689 default:
690 break;
691 }
692}
693
694// Flush any collected app signals.
695//
696// On macOS emitting PacketDissectionChanged from a dialog can
697// render the application unusable:
698// https://gitlab.com/wireshark/wireshark/-/issues/11361
699// https://gitlab.com/wireshark/wireshark/-/issues/11448
700// Work around the problem by queueing up app signals and emitting them
701// after the dialog is closed.
702//
703// The following bugs might be related although they don't describe the
704// exact behavior we're working around here:
705// https://bugreports.qt.io/browse/QTBUG-38512
706// https://bugreports.qt.io/browse/QTBUG-38600
707void MainApplication::flushAppSignals()
708{
709 while (!app_signals_.isEmpty()) {
710 mainApp->emitAppSignal(app_signals_.takeFirst());
711 }
712}
713
714void MainApplication::emitStatCommandSignal(const QString &menu_path, const char *arg, void *userdata)
715{
716 emit openStatCommandDialog(menu_path, arg, userdata);
717}
718
719void MainApplication::emitTapParameterSignal(const QString cfg_abbr, const QString arg, void *userdata)
720{
721 emit openTapParameterDialog(cfg_abbr, arg, userdata);
722}
723
724// XXX Combine statistics and funnel routines into addGroupItem + groupItems?
725void MainApplication::addDynamicMenuGroupItem(int group, QAction *sg_action)
726{
727 if (!dynamic_menu_groups_.contains(group)) {
728 dynamic_menu_groups_[group] = QList<QAction *>();
729 }
730 dynamic_menu_groups_[group] << sg_action;
731}
732
733void MainApplication::appendDynamicMenuGroupItem(int group, QAction *sg_action)
734{
735 if (!added_menu_groups_.contains(group)) {
736 added_menu_groups_[group] = QList<QAction *>();
737 }
738 added_menu_groups_[group] << sg_action;
739 addDynamicMenuGroupItem(group, sg_action);
740}
741
742void MainApplication::removeDynamicMenuGroupItem(int group, QAction *sg_action)
743{
744 if (!removed_menu_groups_.contains(group)) {
745 removed_menu_groups_[group] = QList<QAction *>();
746 }
747 removed_menu_groups_[group] << sg_action;
748 dynamic_menu_groups_[group].removeAll(sg_action);
749}
750
751void MainApplication::clearDynamicMenuGroupItems()
752{
753 foreach (int group, dynamic_menu_groups_.keys())for (auto _container_753 = QtPrivate::qMakeForeachContainer(dynamic_menu_groups_
.keys()); _container_753.i != _container_753.e; ++_container_753
.i) if (int group = *_container_753.i; false) {} else
{
754 dynamic_menu_groups_[group].clear();
755 }
756}
757
758QList<QAction *> MainApplication::dynamicMenuGroupItems(int group)
759{
760 if (!dynamic_menu_groups_.contains(group)) {
761 return QList<QAction *>();
762 }
763
764 QList<QAction *> sgi_list = dynamic_menu_groups_[group];
765 std::sort(sgi_list.begin(), sgi_list.end(), qActionLessThan);
766 return sgi_list;
767}
768
769QList<QAction *> MainApplication::addedMenuGroupItems(int group)
770{
771 if (!added_menu_groups_.contains(group)) {
772 return QList<QAction *>();
773 }
774
775 QList<QAction *> sgi_list = added_menu_groups_[group];
776 std::sort(sgi_list.begin(), sgi_list.end(), qActionLessThan);
777 return sgi_list;
778}
779
780QList<QAction *> MainApplication::removedMenuGroupItems(int group)
781{
782 if (!removed_menu_groups_.contains(group)) {
783 return QList<QAction *>();
784 }
785
786 QList<QAction *> sgi_list = removed_menu_groups_[group];
787 std::sort(sgi_list.begin(), sgi_list.end(), qActionLessThan);
788 return sgi_list;
789}
790
791void MainApplication::clearAddedMenuGroupItems()
792{
793 foreach (int group, added_menu_groups_.keys())for (auto _container_793 = QtPrivate::qMakeForeachContainer(added_menu_groups_
.keys()); _container_793.i != _container_793.e; ++_container_793
.i) if (int group = *_container_793.i; false) {} else
{
794 added_menu_groups_[group].clear();
795 }
796}
797
798void MainApplication::clearRemovedMenuGroupItems()
799{
800 foreach (int group, removed_menu_groups_.keys())for (auto _container_800 = QtPrivate::qMakeForeachContainer(removed_menu_groups_
.keys()); _container_800.i != _container_800.e; ++_container_800
.i) if (int group = *_container_800.i; false) {} else
{
801 foreach (QAction *action, removed_menu_groups_[group])for (auto _container_801 = QtPrivate::qMakeForeachContainer(removed_menu_groups_
[group]); _container_801.i != _container_801.e; ++_container_801
.i) if (QAction *action = *_container_801.i; false) {} else
{
802 delete action;
803 }
804 removed_menu_groups_[group].clear();
805 }
806}
807
808#ifdef HAVE_LIBPCAP1
809
810static void
811iface_mon_event_cb(const char *iface, int added, int up)
812{
813 int present = 0;
814 unsigned ifs, j;
815 interface_t *device;
816 interface_options *interface_opts;
817
818 for (ifs = 0; ifs < global_capture_opts.all_ifaces->len; ifs++) {
819 device = &g_array_index(global_capture_opts.all_ifaces, interface_t, ifs)(((interface_t*) (void *) (global_capture_opts.all_ifaces)->
data) [(ifs)])
;
820 if (strcmp(device->name, iface) == 0) {
821 present = 1;
822 if (!up) {
823 /*
824 * Interface went down or disappeared; remove all instances
825 * of it from the current list of interfaces selected
826 * for capturing.
827 */
828 for (j = 0; j < global_capture_opts.ifaces->len; j++) {
829 interface_opts = &g_array_index(global_capture_opts.ifaces, interface_options, j)(((interface_options*) (void *) (global_capture_opts.ifaces)->
data) [(j)])
;
830 if (strcmp(interface_opts->name, device->name) == 0) {
831 capture_opts_del_iface(&global_capture_opts, j);
832 }
833 }
834 }
835 }
836 }
837
838 mainApp->emitLocalInterfaceEvent(iface, added, up);
839 if (present != up) {
840 /*
841 * We've been told that there's a new interface or that an old
842 * interface is gone; reload the local interface list.
843 *
844 * XXX: We also want to reload the local interface list if [what
845 * we can retrieve about] the capabilities of the device have changed.
846 * Ideally we'd update the capabilities of just the one device in
847 * the cache and signal that the list has been updated, instead of
848 * freeing the entire cache and scanning again - but some extcaps
849 * depend on other interfaces being up; e.g. by default androiddump
850 * tries to connect to the loopback interface to look for adb running,
851 * so if the loopback interface changes so does the status of
852 * androiddump.
853 *
854 * On Linux, at least, you can't get the capabilities from a down
855 * interface, but it's still present in all_ifaces - dumpcap returns
856 * it in the list, and we show it so the user can get a status / error
857 * message when trying to capture on it instead of it vanishing.
858 * So if both present and up are true, then we still want to refresh
859 * to update the capabilities and restart the stats.
860 *
861 * We also store the address in all_ifaces and show them to the user,
862 * so we probably should monitor those events as well and update
863 * the interface list appropriately when those change.
864 */
865 mainApp->refreshLocalInterfaces();
866 }
867}
868
869#endif
870
871void MainApplication::ifChangeEventsAvailable()
872{
873#ifdef HAVE_LIBPCAP1
874 /*
875 * Something's readable from the descriptor for interface
876 * monitoring.
877 *
878 * Have the interface-monitoring code Read whatever interface-change
879 * events are available, and call the callback for them.
880 */
881 iface_mon_event();
882#endif
883}
884
885void MainApplication::emitLocalInterfaceEvent(const char *ifname, int added, int up)
886{
887 emit localInterfaceEvent(ifname, added, up);
888}
889
890void MainApplication::refreshLocalInterfaces()
891{
892 if (active_captures_ > 0) {
893 refresh_interfaces_pending_ = true;
894 return;
895 }
896
897 refresh_interfaces_pending_ = false;
898 extcap_clear_interfaces();
899
900#ifdef HAVE_LIBPCAP1
901 emit scanLocalInterfaces(nullptr);
902#endif
903}
904
905#ifdef HAVE_LIBPCAP1
906GList* MainApplication::getInterfaceList() const
907{
908 return interface_list_copy(cached_if_list_);
909}
910
911void MainApplication::setInterfaceList(GList *if_list)
912{
913 free_interface_list(cached_if_list_);
914 cached_if_list_ = interface_list_copy(if_list);
915}
916#endif
917
918void MainApplication::allSystemsGo()
919{
920 QString display_filter = NULL__null;
921 initialized_ = true;
922 emit appInitialized();
923 while (pending_open_files_.length() > 0) {
924 emit openCaptureFile(pending_open_files_.front(), display_filter, WTAP_TYPE_AUTO0);
925 pending_open_files_.pop_front();
926 }
927
928 bool sideBarVisible = recent.gui_welcome_page_sidebar_tips_visible ||
929 recent.gui_welcome_page_sidebar_learn_visible;
930 SoftwareUpdate::instance()->init(!sideBarVisible);
931
932#ifdef HAVE_LIBPCAP1
933 int err;
934 err = iface_mon_start(&iface_mon_event_cb);
935 if (err == 0) {
936 if_notifier_ = new QSocketNotifier(iface_mon_get_sock(),
937 QSocketNotifier::Read, this);
938 connect(if_notifier_, &QSocketNotifier::activated, this, &MainApplication::ifChangeEventsAvailable);
939 }
940#endif
941}
942
943_e_prefs *MainApplication::readConfigurationFiles(bool reset)
944{
945 e_prefs *prefs_p;
946
947 if (reset) {
948 //
949 // Reset current preferences and enabled/disabled protocols and
950 // heuristic dissectors before reading.
951 // (Needed except when this is called at startup.)
952 //
953 prefs_reset(application_configuration_environment_prefix(), application_columns(), application_num_columns());
954 proto_reenable_all();
955 }
956
957 /* Load libwireshark settings from the current profile. */
958 prefs_p = epan_load_settings();
959
960 return prefs_p;
961}
962
963static void switchTranslator(QTranslator& myTranslator, const QString& filename,
964 const QString& searchPath)
965{
966 mainApp->removeTranslator(&myTranslator);
967
968 if (myTranslator.load(filename, searchPath))
969 mainApp->installTranslator(&myTranslator);
970}
971
972void MainApplication::loadLanguage(const QString newLanguage)
973{
974 QLocale locale;
975 QString localeLanguage;
976 const char* env_prefix = application_configuration_environment_prefix();
977
978 if (newLanguage.isEmpty() || newLanguage == USE_SYSTEM_LANGUAGE"system") {
979 locale = QLocale::system();
980 localeLanguage = locale.name();
981 } else {
982 localeLanguage = newLanguage;
983 locale = QLocale(localeLanguage);
984 }
985
986 QLocale::setDefault(locale);
987 switchTranslator(mainApp->translator,
988 QStringLiteral("wireshark_%1.qm")(QString(QtPrivate::qMakeStringPrivate(u"" "wireshark_%1.qm")
))
.arg(localeLanguage), QStringLiteral(":/i18n/")(QString(QtPrivate::qMakeStringPrivate(u"" ":/i18n/"))));
989 if (QFile::exists(QStringLiteral("%1/%2/wireshark_%3.qm")(QString(QtPrivate::qMakeStringPrivate(u"" "%1/%2/wireshark_%3.qm"
)))
990 .arg(get_datafile_dir(env_prefix)).arg("languages").arg(localeLanguage)))
991 switchTranslator(mainApp->translator,
992 QStringLiteral("wireshark_%1.qm")(QString(QtPrivate::qMakeStringPrivate(u"" "wireshark_%1.qm")
))
.arg(localeLanguage), QStringLiteral("%1/languages")(QString(QtPrivate::qMakeStringPrivate(u"" "%1/languages"))).arg(get_datafile_dir(env_prefix)));
993 if (QFile::exists(QStringLiteral("%1/wireshark_%3.qm")(QString(QtPrivate::qMakeStringPrivate(u"" "%1/wireshark_%3.qm"
)))
994 .arg(gchar_free_to_qstring(get_persconffile_path("languages", false, env_prefix))).arg(localeLanguage)))
995 switchTranslator(mainApp->translator,
996 QStringLiteral("wireshark_%1.qm")(QString(QtPrivate::qMakeStringPrivate(u"" "wireshark_%1.qm")
))
.arg(localeLanguage), gchar_free_to_qstring(get_persconffile_path("languages", false, env_prefix)));
997 if (QFile::exists(QStringLiteral("%1/qt_%2.qm")(QString(QtPrivate::qMakeStringPrivate(u"" "%1/qt_%2.qm")))
998 .arg(get_datafile_dir(env_prefix)).arg(localeLanguage))) {
999 switchTranslator(mainApp->translatorQt,
1000 QStringLiteral("qt_%1.qm")(QString(QtPrivate::qMakeStringPrivate(u"" "qt_%1.qm"))).arg(localeLanguage), QString(get_datafile_dir(env_prefix)));
1001 } else if (QFile::exists(QStringLiteral("%1/qt_%2.qm")(QString(QtPrivate::qMakeStringPrivate(u"" "%1/qt_%2.qm")))
1002 .arg(get_datafile_dir(env_prefix)).arg(localeLanguage.left(localeLanguage.lastIndexOf('_'))))) {
1003 switchTranslator(mainApp->translatorQt,
1004 QStringLiteral("qt_%1.qm")(QString(QtPrivate::qMakeStringPrivate(u"" "qt_%1.qm"))).arg(localeLanguage.left(localeLanguage.lastIndexOf('_'))), QString(get_datafile_dir(env_prefix)));
1005 } else {
1006#if QT_VERSION((6<<16)|(4<<8)|(2)) >= QT_VERSION_CHECK(6, 0, 0)((6<<16)|(0<<8)|(0))
1007 QString translationPath = QLibraryInfo::path(QLibraryInfo::TranslationsPath);
1008#else
1009 QString translationPath = QLibraryInfo::location(QLibraryInfo::TranslationsPath);
1010#endif
1011 switchTranslator(mainApp->translatorQt, QStringLiteral("qt_%1.qm")(QString(QtPrivate::qMakeStringPrivate(u"" "qt_%1.qm"))).arg(localeLanguage), translationPath);
1012 }
1013}
1014
1015void MainApplication::doTriggerMenuItem(MainMenuItem menuItem)
1016{
1017 switch (menuItem)
1018 {
1019 case FileOpenDialog:
1020 emit openCaptureFile(QString(), QString(), WTAP_TYPE_AUTO0);
1021 break;
1022 case CaptureOptionsDialog:
1023 emit openCaptureOptions();
1024 break;
1025 }
1026}
1027
1028void MainApplication::zoomTextFont(int zoomLevel)
1029{
1030 // Scale by 10%, rounding to nearest half point, minimum 1 point.
1031 // XXX Small sizes repeat. It might just be easier to create a map of multipliers.
1032 qreal zoom_size = mono_font_.pointSize() * 2 * qPow(qreal(1.1), zoomLevel);
1033 zoom_size = qRound(zoom_size) / qreal(2.0);
1034 zoom_size = qMax(zoom_size, qreal(1.0));
1035
1036 zoomed_font_ = mono_font_;
1037 zoomed_font_.setPointSizeF(zoom_size);
1038 emit zoomMonospaceFont(zoomed_font_);
1039
1040 QFont zoomed_application_font = font();
1041 zoomed_application_font.setPointSizeF(zoom_size);
1042 emit zoomRegularFont(zoomed_application_font);
1043}
1044
1045void MainApplication::captureEventHandler(CaptureEvent ev)
1046{
1047 switch(ev.captureContext())
1048 {
1049#ifdef HAVE_LIBPCAP1
1050 case CaptureEvent::Update:
1051 case CaptureEvent::Fixed:
1052 switch (ev.eventType())
1053 {
1054 case CaptureEvent::Prepared:
1055 iface_mon_enable(true);
1056 break;
1057 case CaptureEvent::Started:
1058 active_captures_++;
1059 emit captureActive(active_captures_);
1060 break;
1061 case CaptureEvent::Finished:
1062 active_captures_--;
1063 emit captureActive(active_captures_);
1064 if (refresh_interfaces_pending_ && !global_capture_opts.restart) {
1065 refreshLocalInterfaces();
1066 }
1067 break;
1068 default:
1069 break;
1070 }
1071 break;
1072#endif
1073 case CaptureEvent::File:
1074 case CaptureEvent::Reload:
1075 case CaptureEvent::Rescan:
1076 switch (ev.eventType())
1077 {
1078 case CaptureEvent::Started:
1079 QTimer::singleShot(TAP_UPDATE_DEFAULT_INTERVAL3000 / 5, this, SLOT(updateTaps())qFlagLocation("1" "updateTaps()" "\0" "ui/qt/main_application.cpp"
":" "1079")
);
1080 QTimer::singleShot(TAP_UPDATE_DEFAULT_INTERVAL3000 / 2, this, SLOT(updateTaps())qFlagLocation("1" "updateTaps()" "\0" "ui/qt/main_application.cpp"
":" "1080")
);
1081 break;
1082 case CaptureEvent::Finished:
1083 updateTaps();
1084 break;
1085 default:
1086 break;
1087 }
1088 break;
1089 default:
1090 break;
1091 }
1092}
1093
1094void MainApplication::pushStatus(StatusInfo status, const QString &message, const QString &messagetip)
1095{
1096 MainWindow * mw = mainWindow();
1097 if (! mw) {
1098 return;
1099 }
1100
1101 MainStatusBar * bar = mw->statusBar();
1102 if (! bar) {
1103 return;
1104 }
1105
1106 switch(status)
1107 {
1108 case FilterSyntax:
1109 bar->pushGenericStatus(MainStatusBar::STATUS_CTX_FILTER, message);
1110 break;
1111 case FieldStatus:
1112 bar->pushGenericStatus(MainStatusBar::STATUS_CTX_FIELD, message);
1113 break;
1114 case FileStatus:
1115 bar->pushGenericStatus(MainStatusBar::STATUS_CTX_FILE, message, messagetip);
1116 break;
1117 case ByteStatus:
1118 bar->pushGenericStatus(MainStatusBar::STATUS_CTX_BYTE, message);
1119 break;
1120 case BusyStatus:
1121 bar->pushGenericStatus(MainStatusBar::STATUS_CTX_PROGRESS, message, messagetip);
1122 break;
1123 case TemporaryStatus:
1124 bar->pushGenericStatus(MainStatusBar::STATUS_CTX_TEMPORARY, message);
1125 break;
1126 }
1127}
1128
1129void MainApplication::popStatus(StatusInfo status)
1130{
1131 MainWindow * mw = mainWindow();
1132 if (! mw) {
1133 return;
1134 }
1135
1136 MainStatusBar * bar = mw->statusBar();
1137 if (! bar) {
1138 return;
1139 }
1140
1141 switch(status)
1142 {
1143 case FilterSyntax:
1144 bar->popGenericStatus(MainStatusBar::STATUS_CTX_FILTER);
1145 break;
1146 case FieldStatus:
1147 bar->popGenericStatus(MainStatusBar::STATUS_CTX_FIELD);
1148 break;
1149 case FileStatus:
1150 bar->popGenericStatus(MainStatusBar::STATUS_CTX_FILE);
1151 break;
1152 case ByteStatus:
1153 bar->popGenericStatus(MainStatusBar::STATUS_CTX_BYTE);
1154 break;
1155 case BusyStatus:
1156 bar->popGenericStatus(MainStatusBar::STATUS_CTX_PROGRESS);
1157 break;
1158 case TemporaryStatus:
1159 bar->popGenericStatus(MainStatusBar::STATUS_CTX_TEMPORARY);
1160 break;
1161 }
1162}
1163
1164void MainApplication::gotoFrame(int frame)
1165{
1166 MainWindow * mw = mainWindow();
1167 if (! mw) {
1168 return;
1169 }
1170
1171 mw->gotoFrame(frame);
1172}
1173
1174void MainApplication::reloadDisplayFilterMacros()
1175{
1176 dfilter_macro_reload(application_configuration_environment_prefix());
1177 // The signal is needed when the display filter grammar changes for
1178 // any reason (not just "fields".)
1179 mainApp->emitAppSignal(MainApplication::FieldsChanged);
1180}