Bug Summary

File:builds/wireshark/wireshark/ui/qt/main_application.cpp
Warning:line 630, 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 /builds/wireshark/wireshark/ui/qt/lua_debugger -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-05-19-100354-3659-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 <gerald@wireshark.org>
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, [this]() {
459 /* Clear the reloading flag so the re-triggered reload
460 * is not blocked by the isReloadingLua() guard. */
461 setReloadingLua(false);
462 emit reloadLuaPlugins();
463 });
464}
465
466const QIcon &MainApplication::normalIcon()
467{
468 if (normal_icon_.isNull()) {
469 initializeIcons();
470 }
471 return normal_icon_;
472}
473
474const QIcon &MainApplication::captureIcon()
475{
476 if (capture_icon_.isNull()) {
477 initializeIcons();
478 }
479 return capture_icon_;
480}
481
482const QString MainApplication::windowTitleString(QStringList title_parts)
483{
484 QMutableStringListIterator tii(title_parts);
485 while (tii.hasNext()) {
486 QString ti = tii.next();
487 if (ti.isEmpty()) tii.remove();
488 }
489 title_parts.prepend(applicationName());
490 return title_parts.join(window_title_separator_);
491}
492
493void MainApplication::applyCustomColorsFromRecent()
494{
495 int i = 0;
496 bool ok;
497 for (GList *custom_color = recent.custom_colors; custom_color; custom_color = custom_color->next) {
498 QRgb rgb = QString((const char *)custom_color->data).toUInt(&ok, 16);
499 if (ok) {
500 QColorDialog::setCustomColor(i++, QColor(rgb));
501 }
502 }
503}
504
505// Return the first top-level MainWindow.
506MainWindow *MainApplication::mainWindow()
507{
508 foreach (QWidget *tlw, topLevelWidgets())for (auto _container_508 = QtPrivate::qMakeForeachContainer(topLevelWidgets
()); _container_508.i != _container_508.e; ++_container_508.i
) if (QWidget *tlw = *_container_508.i; false) {} else
{
509 MainWindow *tlmw = qobject_cast<MainWindow *>(tlw);
510 if (tlmw && tlmw->isVisible()) {
511 return tlmw;
512 }
513 }
514 return nullptr;
515}
516
517void MainApplication::storeCustomColorsInRecent()
518{
519 if (QColorDialog::customCount()) {
520 prefs_clear_string_list(recent.custom_colors);
521 recent.custom_colors = NULL__null;
522 for (int i = 0; i < QColorDialog::customCount(); i++) {
523 QRgb rgb = QColorDialog::customColor(i).rgb();
524 recent.custom_colors = g_list_append(recent.custom_colors, ws_strdup_printf("%08x", rgb)wmem_strdup_printf(__null, "%08x", rgb));
525 }
526 }
527}
528
529bool MainApplication::event(QEvent *event)
530{
531 QString display_filter = NULL__null;
532 if (event->type() == QEvent::FileOpen) {
533 QFileOpenEvent *foe = static_cast<QFileOpenEvent *>(event);
534 if (foe && foe->file().length() > 0) {
535 QString cf_path(foe->file());
536 if (initialized_) {
537 emit openCaptureFile(cf_path, display_filter, WTAP_TYPE_AUTO0);
538 } else {
539 pending_open_files_.append(cf_path);
540 }
541 }
542 return true;
543 }
544 return QApplication::event(event);
545}
546
547void MainApplication::cleanup()
548{
549 SoftwareUpdate::instance()->cleanup();
550 storeCustomColorsInRecent();
551 // Write the user's recent file(s) to disk.
552 write_profile_recent();
553 write_recent();
554
555 // We might end up here via exit_application.
556 QThreadPool::globalInstance()->waitForDone();
557}
558
559MainApplication::MainApplication(int &argc, char **argv) :
560 QApplication(argc, argv),
561 initialized_(false),
562 is_reloading_lua_(false),
563 if_notifier_(NULL__null),
564 active_captures_(0),
565 refresh_interfaces_pending_(false)
566#if defined(Q_OS_MAC) || defined(Q_OS_WIN)
567 , normal_icon_(windowIcon())
568#endif
569#ifdef HAVE_LIBPCAP1
570 , cached_if_list_(NULL__null)
571#endif
572{
573 mainApp = this;
574
575 MimeDatabaseInitThread *mime_db_init_thread = new(MimeDatabaseInitThread);
576 QThreadPool::globalInstance()->start(mime_db_init_thread);
577#if (QT_VERSION((6<<16)|(4<<8)|(2)) < QT_VERSION_CHECK(6, 0, 0)((6<<16)|(0<<8)|(0)))
578 FontDatabaseInitThread *font_db_init_thread = new (FontDatabaseInitThread);
579 QThreadPool::globalInstance()->start(font_db_init_thread);
580#endif
581
582 Q_INIT_RESOURCE(about)do { extern int qInitResources_about (); qInitResources_about
(); } while (false)
;
1
Loop condition is false. Exiting loop
583 Q_INIT_RESOURCE(i18n)do { extern int qInitResources_i18n (); qInitResources_i18n (
); } while (false)
;
2
Loop condition is false. Exiting loop
584 Q_INIT_RESOURCE(layout)do { extern int qInitResources_layout (); qInitResources_layout
(); } while (false)
;
3
Loop condition is false. Exiting loop
585 Q_INIT_RESOURCE(stock_icons)do { extern int qInitResources_stock_icons (); qInitResources_stock_icons
(); } while (false)
;
4
Loop condition is false. Exiting loop
586 Q_INIT_RESOURCE(languages)do { extern int qInitResources_languages (); qInitResources_languages
(); } while (false)
;
5
Loop condition is false. Exiting loop
587
588#ifdef Q_OS_WIN
589 /* RichEd20.DLL is needed for native file dialog filter entries. */
590 ws_load_library("riched20.dll");
591#endif // Q_OS_WIN
592
593#if (QT_VERSION((6<<16)|(4<<8)|(2)) < QT_VERSION_CHECK(6, 0, 0)((6<<16)|(0<<8)|(0)))
594 setAttribute(Qt::AA_UseHighDpiPixmaps);
595#endif
596
597#if QT_VERSION((6<<16)|(4<<8)|(2)) < QT_VERSION_CHECK(6, 0, 0)((6<<16)|(0<<8)|(0))
598 setAttribute(Qt::AA_DisableWindowContextHelpButton);
599#endif
600
601 // We use a lot of style sheets that base their colors on the main
602 // application palette, so this works better.
603 setAttribute(Qt::AA_UseStyleSheetPropagationInWidgetStyles, true);
604
605 // Throw various settings at the wall with the hope that one of them will
606 // enable context menu shortcuts QTBUG-69452, QTBUG-109590
607 setAttribute(Qt::AA_DontShowShortcutsInContextMenus, false);
608 styleHints()->setShowShortcutsInContextMenus(true);
609
610 packet_data_timer_.setParent(this);
611 connect(&packet_data_timer_, &QTimer::timeout, this, &MainApplication::refreshPacketData);
612 packet_data_timer_.start(1000);
613
614 tap_update_timer_.setParent(this);
615 // tap_update_timer interval is set when preferences are set before init
616 connect(this, &MainApplication::appInitialized, &tap_update_timer_, [&]() { tap_update_timer_.start(); });
617 connect(&tap_update_timer_, &QTimer::timeout, this, &MainApplication::updateTaps);
618
619
620 // If our window text is lighter than the window background, assume the theme is dark.
621 prefs_set_gui_theme_is_dark(ColorUtils::themeIsDark());
622
623#if QT_VERSION((6<<16)|(4<<8)|(2)) >= QT_VERSION_CHECK(6, 5, 0)((6<<16)|(5<<8)|(0)) && defined(Q_OS_WIN)
624 colorSchemeChanged();
625 connect(styleHints(), &QStyleHints::colorSchemeChanged, this, &MainApplication::colorSchemeChanged);
626#else
627 setStyle(new MsgBoxTextStyle);
6
Memory is allocated
628#endif
629
630 connect(qApp(static_cast<QApplication *>(QCoreApplication::instance
()))
, &QApplication::aboutToQuit, this, &MainApplication::cleanup);
7
Potential memory leak
631}
632
633MainApplication::~MainApplication()
634{
635 mainApp = NULL__null;
636#ifdef HAVE_LIBPCAP1
637 free_interface_list(cached_if_list_);
638#endif
639 clearDynamicMenuGroupItems();
640}
641
642void MainApplication::emitAppSignal(AppSignal signal)
643{
644 switch (signal) {
645 case ColumnsChanged:
646 emit columnsChanged();
647 break;
648 case CaptureFilterListChanged:
649 emit captureFilterListChanged();
650 break;
651 case DisplayFilterListChanged:
652 emit displayFilterListChanged();
653 break;
654 case FilterExpressionsChanged:
655 emit filterExpressionsChanged();
656 break;
657 case LocalInterfacesChanged:
658 emit localInterfaceListChanged();
659 break;
660 case NameResolutionChanged:
661 emit addressResolutionChanged();
662 break;
663 case PreferencesChanged:
664 tap_update_timer_.setInterval(prefs.tap_update_interval);
665 setMonospaceFont(prefs.gui_font_name);
666 emit preferencesChanged();
667 break;
668 case PacketDissectionChanged:
669 emit packetDissectionChanged();
670 break;
671 case ProfileChanging:
672 emit profileChanging();
673 break;
674 case RecentPreferencesRead:
675 emit recentPreferencesRead();
676 break;
677 case FieldsChanged:
678 emit fieldsChanged();
679 break;
680 case ColorsChanged:
681 ColorUtils::setScheme(prefs.gui_color_scheme);
682 emit colorsChanged();
683 break;
684 case FreezePacketList:
685 emit freezePacketList(false);
686 break;
687 case AggregationChanged:
688 emit aggregationChanged();
689 break;
690 default:
691 break;
692 }
693}
694
695// Flush any collected app signals.
696//
697// On macOS emitting PacketDissectionChanged from a dialog can
698// render the application unusable:
699// https://gitlab.com/wireshark/wireshark/-/issues/11361
700// https://gitlab.com/wireshark/wireshark/-/issues/11448
701// Work around the problem by queueing up app signals and emitting them
702// after the dialog is closed.
703//
704// The following bugs might be related although they don't describe the
705// exact behavior we're working around here:
706// https://bugreports.qt.io/browse/QTBUG-38512
707// https://bugreports.qt.io/browse/QTBUG-38600
708void MainApplication::flushAppSignals()
709{
710 while (!app_signals_.isEmpty()) {
711 mainApp->emitAppSignal(app_signals_.takeFirst());
712 }
713}
714
715void MainApplication::emitStatCommandSignal(const QString &menu_path, const char *arg, void *userdata)
716{
717 emit openStatCommandDialog(menu_path, arg, userdata);
718}
719
720void MainApplication::emitTapParameterSignal(const QString cfg_abbr, const QString arg, void *userdata)
721{
722 emit openTapParameterDialog(cfg_abbr, arg, userdata);
723}
724
725// XXX Combine statistics and funnel routines into addGroupItem + groupItems?
726void MainApplication::addDynamicMenuGroupItem(int group, QAction *sg_action)
727{
728 if (!dynamic_menu_groups_.contains(group)) {
729 dynamic_menu_groups_[group] = QList<QAction *>();
730 }
731 dynamic_menu_groups_[group] << sg_action;
732}
733
734void MainApplication::appendDynamicMenuGroupItem(int group, QAction *sg_action)
735{
736 if (!added_menu_groups_.contains(group)) {
737 added_menu_groups_[group] = QList<QAction *>();
738 }
739 added_menu_groups_[group] << sg_action;
740 addDynamicMenuGroupItem(group, sg_action);
741}
742
743void MainApplication::removeDynamicMenuGroupItem(int group, QAction *sg_action)
744{
745 if (!removed_menu_groups_.contains(group)) {
746 removed_menu_groups_[group] = QList<QAction *>();
747 }
748 removed_menu_groups_[group] << sg_action;
749 dynamic_menu_groups_[group].removeAll(sg_action);
750}
751
752void MainApplication::clearDynamicMenuGroupItems()
753{
754 foreach (int group, dynamic_menu_groups_.keys())for (auto _container_754 = QtPrivate::qMakeForeachContainer(dynamic_menu_groups_
.keys()); _container_754.i != _container_754.e; ++_container_754
.i) if (int group = *_container_754.i; false) {} else
{
755 dynamic_menu_groups_[group].clear();
756 }
757}
758
759QList<QAction *> MainApplication::dynamicMenuGroupItems(int group)
760{
761 if (!dynamic_menu_groups_.contains(group)) {
762 return QList<QAction *>();
763 }
764
765 QList<QAction *> sgi_list = dynamic_menu_groups_[group];
766 std::sort(sgi_list.begin(), sgi_list.end(), qActionLessThan);
767 return sgi_list;
768}
769
770QList<QAction *> MainApplication::addedMenuGroupItems(int group)
771{
772 if (!added_menu_groups_.contains(group)) {
773 return QList<QAction *>();
774 }
775
776 QList<QAction *> sgi_list = added_menu_groups_[group];
777 std::sort(sgi_list.begin(), sgi_list.end(), qActionLessThan);
778 return sgi_list;
779}
780
781QList<QAction *> MainApplication::removedMenuGroupItems(int group)
782{
783 if (!removed_menu_groups_.contains(group)) {
784 return QList<QAction *>();
785 }
786
787 QList<QAction *> sgi_list = removed_menu_groups_[group];
788 std::sort(sgi_list.begin(), sgi_list.end(), qActionLessThan);
789 return sgi_list;
790}
791
792void MainApplication::clearAddedMenuGroupItems()
793{
794 foreach (int group, added_menu_groups_.keys())for (auto _container_794 = QtPrivate::qMakeForeachContainer(added_menu_groups_
.keys()); _container_794.i != _container_794.e; ++_container_794
.i) if (int group = *_container_794.i; false) {} else
{
795 added_menu_groups_[group].clear();
796 }
797}
798
799void MainApplication::clearRemovedMenuGroupItems()
800{
801 foreach (int group, removed_menu_groups_.keys())for (auto _container_801 = QtPrivate::qMakeForeachContainer(removed_menu_groups_
.keys()); _container_801.i != _container_801.e; ++_container_801
.i) if (int group = *_container_801.i; false) {} else
{
802 foreach (QAction *action, removed_menu_groups_[group])for (auto _container_802 = QtPrivate::qMakeForeachContainer(removed_menu_groups_
[group]); _container_802.i != _container_802.e; ++_container_802
.i) if (QAction *action = *_container_802.i; false) {} else
{
803 delete action;
804 }
805 removed_menu_groups_[group].clear();
806 }
807}
808
809#ifdef HAVE_LIBPCAP1
810
811static void
812iface_mon_event_cb(const char *iface, int added, int up)
813{
814 int present = 0;
815 unsigned ifs, j;
816 interface_t *device;
817 interface_options *interface_opts;
818
819 for (ifs = 0; ifs < global_capture_opts.all_ifaces->len; ifs++) {
820 device = &g_array_index(global_capture_opts.all_ifaces, interface_t, ifs)(((interface_t*) (void *) (global_capture_opts.all_ifaces)->
data) [(ifs)])
;
821 if (strcmp(device->name, iface) == 0) {
822 present = 1;
823 if (!up) {
824 /*
825 * Interface went down or disappeared; remove all instances
826 * of it from the current list of interfaces selected
827 * for capturing.
828 */
829 for (j = 0; j < global_capture_opts.ifaces->len; j++) {
830 interface_opts = &g_array_index(global_capture_opts.ifaces, interface_options, j)(((interface_options*) (void *) (global_capture_opts.ifaces)->
data) [(j)])
;
831 if (strcmp(interface_opts->name, device->name) == 0) {
832 capture_opts_del_iface(&global_capture_opts, j);
833 }
834 }
835 }
836 }
837 }
838
839 mainApp->emitLocalInterfaceEvent(iface, added, up);
840 if (present != up) {
841 /*
842 * We've been told that there's a new interface or that an old
843 * interface is gone; reload the local interface list.
844 *
845 * XXX: We also want to reload the local interface list if [what
846 * we can retrieve about] the capabilities of the device have changed.
847 * Ideally we'd update the capabilities of just the one device in
848 * the cache and signal that the list has been updated, instead of
849 * freeing the entire cache and scanning again - but some extcaps
850 * depend on other interfaces being up; e.g. by default androiddump
851 * tries to connect to the loopback interface to look for adb running,
852 * so if the loopback interface changes so does the status of
853 * androiddump.
854 *
855 * On Linux, at least, you can't get the capabilities from a down
856 * interface, but it's still present in all_ifaces - dumpcap returns
857 * it in the list, and we show it so the user can get a status / error
858 * message when trying to capture on it instead of it vanishing.
859 * So if both present and up are true, then we still want to refresh
860 * to update the capabilities and restart the stats.
861 *
862 * We also store the address in all_ifaces and show them to the user,
863 * so we probably should monitor those events as well and update
864 * the interface list appropriately when those change.
865 */
866 mainApp->refreshLocalInterfaces();
867 }
868}
869
870#endif
871
872void MainApplication::ifChangeEventsAvailable()
873{
874#ifdef HAVE_LIBPCAP1
875 /*
876 * Something's readable from the descriptor for interface
877 * monitoring.
878 *
879 * Have the interface-monitoring code Read whatever interface-change
880 * events are available, and call the callback for them.
881 */
882 iface_mon_event();
883#endif
884}
885
886void MainApplication::emitLocalInterfaceEvent(const char *ifname, int added, int up)
887{
888 emit localInterfaceEvent(ifname, added, up);
889}
890
891void MainApplication::refreshLocalInterfaces()
892{
893 if (active_captures_ > 0) {
894 refresh_interfaces_pending_ = true;
895 return;
896 }
897
898 refresh_interfaces_pending_ = false;
899 extcap_clear_interfaces();
900
901#ifdef HAVE_LIBPCAP1
902 emit scanLocalInterfaces(nullptr);
903#endif
904}
905
906#ifdef HAVE_LIBPCAP1
907GList* MainApplication::getInterfaceList() const
908{
909 return interface_list_copy(cached_if_list_);
910}
911
912void MainApplication::setInterfaceList(GList *if_list)
913{
914 free_interface_list(cached_if_list_);
915 cached_if_list_ = interface_list_copy(if_list);
916}
917#endif
918
919void MainApplication::allSystemsGo()
920{
921 QString display_filter = NULL__null;
922 initialized_ = true;
923 emit appInitialized();
924 while (pending_open_files_.length() > 0) {
925 emit openCaptureFile(pending_open_files_.front(), display_filter, WTAP_TYPE_AUTO0);
926 pending_open_files_.pop_front();
927 }
928
929 bool sideBarVisible = recent.gui_welcome_page_sidebar_tips_visible ||
930 recent.gui_welcome_page_sidebar_learn_visible;
931 SoftwareUpdate::instance()->init(!sideBarVisible);
932
933#ifdef HAVE_LIBPCAP1
934 int err;
935 err = iface_mon_start(&iface_mon_event_cb);
936 if (err == 0) {
937 if_notifier_ = new QSocketNotifier(iface_mon_get_sock(),
938 QSocketNotifier::Read, this);
939 connect(if_notifier_, &QSocketNotifier::activated, this, &MainApplication::ifChangeEventsAvailable);
940 }
941#endif
942}
943
944_e_prefs *MainApplication::readConfigurationFiles(bool reset)
945{
946 e_prefs *prefs_p;
947
948 if (reset) {
949 //
950 // Reset current preferences and enabled/disabled protocols and
951 // heuristic dissectors before reading.
952 // (Needed except when this is called at startup.)
953 //
954 prefs_reset(application_configuration_environment_prefix(), application_columns(), application_num_columns());
955 proto_reenable_all();
956 }
957
958 /* Load libwireshark settings from the current profile. */
959 prefs_p = epan_load_settings();
960
961 return prefs_p;
962}
963
964static void switchTranslator(QTranslator& myTranslator, const QString& filename,
965 const QString& searchPath)
966{
967 mainApp->removeTranslator(&myTranslator);
968
969 if (myTranslator.load(filename, searchPath))
970 mainApp->installTranslator(&myTranslator);
971}
972
973void MainApplication::loadLanguage(const QString newLanguage)
974{
975 QLocale locale;
976 QString localeLanguage;
977 const char* env_prefix = application_configuration_environment_prefix();
978
979 if (newLanguage.isEmpty() || newLanguage == USE_SYSTEM_LANGUAGE"system") {
980 locale = QLocale::system();
981 localeLanguage = locale.name();
982 } else {
983 localeLanguage = newLanguage;
984 locale = QLocale(localeLanguage);
985 }
986
987 QLocale::setDefault(locale);
988 switchTranslator(mainApp->translator,
989 QStringLiteral("wireshark_%1.qm")(QString(QtPrivate::qMakeStringPrivate(u"" "wireshark_%1.qm")
))
.arg(localeLanguage), QStringLiteral(":/i18n/")(QString(QtPrivate::qMakeStringPrivate(u"" ":/i18n/"))));
990 if (QFile::exists(QStringLiteral("%1/%2/wireshark_%3.qm")(QString(QtPrivate::qMakeStringPrivate(u"" "%1/%2/wireshark_%3.qm"
)))
991 .arg(get_datafile_dir(env_prefix)).arg("languages").arg(localeLanguage)))
992 switchTranslator(mainApp->translator,
993 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)));
994 if (QFile::exists(QStringLiteral("%1/wireshark_%3.qm")(QString(QtPrivate::qMakeStringPrivate(u"" "%1/wireshark_%3.qm"
)))
995 .arg(gchar_free_to_qstring(get_persconffile_path("languages", false, env_prefix))).arg(localeLanguage)))
996 switchTranslator(mainApp->translator,
997 QStringLiteral("wireshark_%1.qm")(QString(QtPrivate::qMakeStringPrivate(u"" "wireshark_%1.qm")
))
.arg(localeLanguage), gchar_free_to_qstring(get_persconffile_path("languages", false, env_prefix)));
998 if (QFile::exists(QStringLiteral("%1/qt_%2.qm")(QString(QtPrivate::qMakeStringPrivate(u"" "%1/qt_%2.qm")))
999 .arg(get_datafile_dir(env_prefix)).arg(localeLanguage))) {
1000 switchTranslator(mainApp->translatorQt,
1001 QStringLiteral("qt_%1.qm")(QString(QtPrivate::qMakeStringPrivate(u"" "qt_%1.qm"))).arg(localeLanguage), QString(get_datafile_dir(env_prefix)));
1002 } else if (QFile::exists(QStringLiteral("%1/qt_%2.qm")(QString(QtPrivate::qMakeStringPrivate(u"" "%1/qt_%2.qm")))
1003 .arg(get_datafile_dir(env_prefix)).arg(localeLanguage.left(localeLanguage.lastIndexOf('_'))))) {
1004 switchTranslator(mainApp->translatorQt,
1005 QStringLiteral("qt_%1.qm")(QString(QtPrivate::qMakeStringPrivate(u"" "qt_%1.qm"))).arg(localeLanguage.left(localeLanguage.lastIndexOf('_'))), QString(get_datafile_dir(env_prefix)));
1006 } else {
1007#if QT_VERSION((6<<16)|(4<<8)|(2)) >= QT_VERSION_CHECK(6, 0, 0)((6<<16)|(0<<8)|(0))
1008 QString translationPath = QLibraryInfo::path(QLibraryInfo::TranslationsPath);
1009#else
1010 QString translationPath = QLibraryInfo::location(QLibraryInfo::TranslationsPath);
1011#endif
1012 switchTranslator(mainApp->translatorQt, QStringLiteral("qt_%1.qm")(QString(QtPrivate::qMakeStringPrivate(u"" "qt_%1.qm"))).arg(localeLanguage), translationPath);
1013 }
1014}
1015
1016void MainApplication::doTriggerMenuItem(MainMenuItem menuItem)
1017{
1018 switch (menuItem)
1019 {
1020 case FileOpenDialog:
1021 emit openCaptureFile(QString(), QString(), WTAP_TYPE_AUTO0);
1022 break;
1023 case CaptureOptionsDialog:
1024 emit openCaptureOptions();
1025 break;
1026 }
1027}
1028
1029void MainApplication::zoomTextFont(int zoomLevel)
1030{
1031 // Scale by 10%, rounding to nearest half point, minimum 1 point.
1032 // XXX Small sizes repeat. It might just be easier to create a map of multipliers.
1033 qreal zoom_size = mono_font_.pointSize() * 2 * qPow(qreal(1.1), zoomLevel);
1034 zoom_size = qRound(zoom_size) / qreal(2.0);
1035 zoom_size = qMax(zoom_size, qreal(1.0));
1036
1037 zoomed_font_ = mono_font_;
1038 zoomed_font_.setPointSizeF(zoom_size);
1039 emit zoomMonospaceFont(zoomed_font_);
1040
1041 QFont zoomed_application_font = font();
1042 zoomed_application_font.setPointSizeF(zoom_size);
1043 emit zoomRegularFont(zoomed_application_font);
1044}
1045
1046void MainApplication::captureEventHandler(CaptureEvent ev)
1047{
1048 switch(ev.captureContext())
1049 {
1050#ifdef HAVE_LIBPCAP1
1051 case CaptureEvent::Update:
1052 case CaptureEvent::Fixed:
1053 switch (ev.eventType())
1054 {
1055 case CaptureEvent::Prepared:
1056 iface_mon_enable(true);
1057 break;
1058 case CaptureEvent::Started:
1059 active_captures_++;
1060 emit captureActive(active_captures_);
1061 break;
1062 case CaptureEvent::Finished:
1063 active_captures_--;
1064 emit captureActive(active_captures_);
1065 if (refresh_interfaces_pending_ && !global_capture_opts.restart) {
1066 refreshLocalInterfaces();
1067 }
1068 break;
1069 default:
1070 break;
1071 }
1072 break;
1073#endif
1074 case CaptureEvent::File:
1075 case CaptureEvent::Reload:
1076 case CaptureEvent::Rescan:
1077 switch (ev.eventType())
1078 {
1079 case CaptureEvent::Started:
1080 QTimer::singleShot(TAP_UPDATE_DEFAULT_INTERVAL3000 / 5, this, SLOT(updateTaps())qFlagLocation("1" "updateTaps()" "\0" "ui/qt/main_application.cpp"
":" "1080")
);
1081 QTimer::singleShot(TAP_UPDATE_DEFAULT_INTERVAL3000 / 2, this, SLOT(updateTaps())qFlagLocation("1" "updateTaps()" "\0" "ui/qt/main_application.cpp"
":" "1081")
);
1082 break;
1083 case CaptureEvent::Finished:
1084 updateTaps();
1085 break;
1086 default:
1087 break;
1088 }
1089 break;
1090 default:
1091 break;
1092 }
1093}
1094
1095void MainApplication::pushStatus(StatusInfo status, const QString &message, const QString &messagetip)
1096{
1097 MainWindow * mw = mainWindow();
1098 if (! mw) {
1099 return;
1100 }
1101
1102 MainStatusBar * bar = mw->statusBar();
1103 if (! bar) {
1104 return;
1105 }
1106
1107 switch(status)
1108 {
1109 case FilterSyntax:
1110 bar->pushGenericStatus(MainStatusBar::STATUS_CTX_FILTER, message);
1111 break;
1112 case FieldStatus:
1113 bar->pushGenericStatus(MainStatusBar::STATUS_CTX_FIELD, message);
1114 break;
1115 case FileStatus:
1116 bar->pushGenericStatus(MainStatusBar::STATUS_CTX_FILE, message, messagetip);
1117 break;
1118 case ByteStatus:
1119 bar->pushGenericStatus(MainStatusBar::STATUS_CTX_BYTE, message);
1120 break;
1121 case BusyStatus:
1122 bar->pushGenericStatus(MainStatusBar::STATUS_CTX_PROGRESS, message, messagetip);
1123 break;
1124 case TemporaryStatus:
1125 bar->pushGenericStatus(MainStatusBar::STATUS_CTX_TEMPORARY, message);
1126 break;
1127 }
1128}
1129
1130void MainApplication::popStatus(StatusInfo status)
1131{
1132 MainWindow * mw = mainWindow();
1133 if (! mw) {
1134 return;
1135 }
1136
1137 MainStatusBar * bar = mw->statusBar();
1138 if (! bar) {
1139 return;
1140 }
1141
1142 switch(status)
1143 {
1144 case FilterSyntax:
1145 bar->popGenericStatus(MainStatusBar::STATUS_CTX_FILTER);
1146 break;
1147 case FieldStatus:
1148 bar->popGenericStatus(MainStatusBar::STATUS_CTX_FIELD);
1149 break;
1150 case FileStatus:
1151 bar->popGenericStatus(MainStatusBar::STATUS_CTX_FILE);
1152 break;
1153 case ByteStatus:
1154 bar->popGenericStatus(MainStatusBar::STATUS_CTX_BYTE);
1155 break;
1156 case BusyStatus:
1157 bar->popGenericStatus(MainStatusBar::STATUS_CTX_PROGRESS);
1158 break;
1159 case TemporaryStatus:
1160 bar->popGenericStatus(MainStatusBar::STATUS_CTX_TEMPORARY);
1161 break;
1162 }
1163}
1164
1165void MainApplication::gotoFrame(int frame)
1166{
1167 MainWindow * mw = mainWindow();
1168 if (! mw) {
1169 return;
1170 }
1171
1172 mw->gotoFrame(frame);
1173}
1174
1175void MainApplication::reloadDisplayFilterMacros()
1176{
1177 dfilter_macro_reload(application_configuration_environment_prefix());
1178 // The signal is needed when the display filter grammar changes for
1179 // any reason (not just "fields".)
1180 mainApp->emitAppSignal(MainApplication::FieldsChanged);
1181}