### Bug Summary

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

### Annotated Source Code

Press '?' to see keyboard shortcuts

Show analyzer invocation
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-04-22-100420-3641-1 -x c++ /builds/wireshark/wireshark/ui/qt/main_application.cpp

Keyboard shortcuts:

- Use 'j/k' keys for keyboard navigation
- Use 'Shift+S' to show/hide relevant lines
- Use '?' to toggle this window

Close
Show only relevant lines Show control flow arrows

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 |
115 | MainApplication *mainApp;
116 |
117 | // XXX - Copied from ui/gtk/file_dlg.c
118 |
119 | static QHash<int, QList<QAction *> > dynamic_menu_groups_;
120 | static QHash<int, QList<QAction *> > added_menu_groups_;
121 | static QHash<int, QList<QAction *> > removed_menu_groups_;
122 |
123 | QString 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
128 | class MimeDatabaseInitThread : public QRunnable
129 | {
130 | private:
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.
140 | class FontDatabaseInitThread : public QRunnable
141 | {
142 | private:
143 | void run()
144 | {
145 | QFontDatabase font_db;
146 | }
147 | };
148 | #endif
149 |
150 | void
151 | topic_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 */
157 | extern "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 |
171 | void 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.
185 | class MsgBoxTextStyle : public QProxyStyle
186 | {
187 | public:
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)
200 | void 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 |
210 | void MainApplication::updateTaps()
211 | {
212 | draw_tap_listeners(false);
213 | }
214 |
215 | QDir MainApplication::openDialogInitialDir() {
216 | return QDir(get_open_dialog_initial_dir());
217 | }
218 |
219 | void 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 |
227 | void 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 |
236 | const QFont MainApplication::monospaceFont(bool zoomed) const
237 | {
238 | if (zoomed) {
239 | return zoomed_font_;
240 | }
241 | return mono_font_;
242 | }
243 |
244 | void 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 |
328 | int MainApplication::monospaceTextSize(const char *str)
329 | {
330 | return QFontMetrics(mono_font_).horizontalAdvance(str);
331 | }
332 |
333 | void 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 |
456 | void 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 |
466 | const QIcon &MainApplication::normalIcon()
467 | {
468 | if (normal_icon_.isNull()) {
469 | initializeIcons();
470 | }
471 | return normal_icon_;
472 | }
473 |
474 | const QIcon &MainApplication::captureIcon()
475 | {
476 | if (capture_icon_.isNull()) {
477 | initializeIcons();
478 | }
479 | return capture_icon_;
480 | }
481 |
482 | const 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 |
493 | void 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.
506 | MainWindow *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 |
517 | void 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 |
529 | bool 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 |
547 | void 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 |
559 | MainApplication::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(this, &MainApplication::appInitialized, [this] { emit aggregationVisiblity(); });
618 | connect(&tap_update_timer_, &QTimer::timeout, this, &MainApplication::updateTaps);
619 |
620 |
621 | // If our window text is lighter than the window background, assume the theme is dark.
622 | prefs_set_gui_theme_is_dark(ColorUtils::themeIsDark());
623 |
624 | #if QT_VERSION((6<<16)|(4<<8)|(2)) >= QT_VERSION_CHECK(6, 5, 0)((6<<16)|(5<<8)|(0)) && defined(Q_OS_WIN)
625 | colorSchemeChanged();
626 | connect(styleHints(), &QStyleHints::colorSchemeChanged, this, &MainApplication::colorSchemeChanged);
627 | #else
628 | setStyle(new MsgBoxTextStyle);
6 | ← | Memory is allocated | →
629 | #endif
630 |
631 | connect(qApp(static_cast<QApplication *>(QCoreApplication::instance ())), &QApplication::aboutToQuit, this, &MainApplication::cleanup);
7 | ← | Potential memory leak
632 | }
633 |
634 | MainApplication::~MainApplication()
635 | {
636 | mainApp = NULL__null;
637 | #ifdef HAVE_LIBPCAP1
638 | free_interface_list(cached_if_list_);
639 | #endif
640 | clearDynamicMenuGroupItems();
641 | }
642 |
643 | void MainApplication::emitAppSignal(AppSignal signal)
644 | {
645 | switch (signal) {
646 | case ColumnsChanged:
647 | emit columnsChanged();
648 | break;
649 | case CaptureFilterListChanged:
650 | emit captureFilterListChanged();
651 | break;
652 | case DisplayFilterListChanged:
653 | emit displayFilterListChanged();
654 | break;
655 | case FilterExpressionsChanged:
656 | emit filterExpressionsChanged();
657 | break;
658 | case LocalInterfacesChanged:
659 | emit localInterfaceListChanged();
660 | break;
661 | case NameResolutionChanged:
662 | emit addressResolutionChanged();
663 | break;
664 | case PreferencesChanged:
665 | tap_update_timer_.setInterval(prefs.tap_update_interval);
666 | setMonospaceFont(prefs.gui_font_name);
667 | emit preferencesChanged();
668 | break;
669 | case PacketDissectionChanged:
670 | emit packetDissectionChanged();
671 | break;
672 | case ProfileChanging:
673 | emit profileChanging();
674 | break;
675 | case RecentPreferencesRead:
676 | emit recentPreferencesRead();
677 | break;
678 | case FieldsChanged:
679 | emit fieldsChanged();
680 | break;
681 | case ColorsChanged:
682 | ColorUtils::setScheme(prefs.gui_color_scheme);
683 | emit colorsChanged();
684 | break;
685 | case FreezePacketList:
686 | emit freezePacketList(false);
687 | break;
688 | case AggregationVisiblity:
689 | emit aggregationVisiblity();
690 | break;
691 | case AggregationChanged:
692 | emit aggregationChanged();
693 | break;
694 | default:
695 | break;
696 | }
697 | }
698 |
699 | // Flush any collected app signals.
700 | //
701 | // On macOS emitting PacketDissectionChanged from a dialog can
702 | // render the application unusable:
703 | // https://gitlab.com/wireshark/wireshark/-/issues/11361
704 | // https://gitlab.com/wireshark/wireshark/-/issues/11448
705 | // Work around the problem by queueing up app signals and emitting them
706 | // after the dialog is closed.
707 | //
708 | // The following bugs might be related although they don't describe the
709 | // exact behavior we're working around here:
710 | // https://bugreports.qt.io/browse/QTBUG-38512
711 | // https://bugreports.qt.io/browse/QTBUG-38600
712 | void MainApplication::flushAppSignals()
713 | {
714 | while (!app_signals_.isEmpty()) {
715 | mainApp->emitAppSignal(app_signals_.takeFirst());
716 | }
717 | }
718 |
719 | void MainApplication::emitStatCommandSignal(const QString &menu_path, const char *arg, void *userdata)
720 | {
721 | emit openStatCommandDialog(menu_path, arg, userdata);
722 | }
723 |
724 | void MainApplication::emitTapParameterSignal(const QString cfg_abbr, const QString arg, void *userdata)
725 | {
726 | emit openTapParameterDialog(cfg_abbr, arg, userdata);
727 | }
728 |
729 | // XXX Combine statistics and funnel routines into addGroupItem + groupItems?
730 | void MainApplication::addDynamicMenuGroupItem(int group, QAction *sg_action)
731 | {
732 | if (!dynamic_menu_groups_.contains(group)) {
733 | dynamic_menu_groups_[group] = QList<QAction *>();
734 | }
735 | dynamic_menu_groups_[group] << sg_action;
736 | }
737 |
738 | void MainApplication::appendDynamicMenuGroupItem(int group, QAction *sg_action)
739 | {
740 | if (!added_menu_groups_.contains(group)) {
741 | added_menu_groups_[group] = QList<QAction *>();
742 | }
743 | added_menu_groups_[group] << sg_action;
744 | addDynamicMenuGroupItem(group, sg_action);
745 | }
746 |
747 | void MainApplication::removeDynamicMenuGroupItem(int group, QAction *sg_action)
748 | {
749 | if (!removed_menu_groups_.contains(group)) {
750 | removed_menu_groups_[group] = QList<QAction *>();
751 | }
752 | removed_menu_groups_[group] << sg_action;
753 | dynamic_menu_groups_[group].removeAll(sg_action);
754 | }
755 |
756 | void MainApplication::clearDynamicMenuGroupItems()
757 | {
758 | foreach (int group, dynamic_menu_groups_.keys())for (auto _container_758 = QtPrivate::qMakeForeachContainer(dynamic_menu_groups_ .keys()); _container_758.i != _container_758.e; ++_container_758 .i) if (int group = *_container_758.i; false) {} else {
759 | dynamic_menu_groups_[group].clear();
760 | }
761 | }
762 |
763 | QList<QAction *> MainApplication::dynamicMenuGroupItems(int group)
764 | {
765 | if (!dynamic_menu_groups_.contains(group)) {
766 | return QList<QAction *>();
767 | }
768 |
769 | QList<QAction *> sgi_list = dynamic_menu_groups_[group];
770 | std::sort(sgi_list.begin(), sgi_list.end(), qActionLessThan);
771 | return sgi_list;
772 | }
773 |
774 | QList<QAction *> MainApplication::addedMenuGroupItems(int group)
775 | {
776 | if (!added_menu_groups_.contains(group)) {
777 | return QList<QAction *>();
778 | }
779 |
780 | QList<QAction *> sgi_list = added_menu_groups_[group];
781 | std::sort(sgi_list.begin(), sgi_list.end(), qActionLessThan);
782 | return sgi_list;
783 | }
784 |
785 | QList<QAction *> MainApplication::removedMenuGroupItems(int group)
786 | {
787 | if (!removed_menu_groups_.contains(group)) {
788 | return QList<QAction *>();
789 | }
790 |
791 | QList<QAction *> sgi_list = removed_menu_groups_[group];
792 | std::sort(sgi_list.begin(), sgi_list.end(), qActionLessThan);
793 | return sgi_list;
794 | }
795 |
796 | void MainApplication::clearAddedMenuGroupItems()
797 | {
798 | foreach (int group, added_menu_groups_.keys())for (auto _container_798 = QtPrivate::qMakeForeachContainer(added_menu_groups_ .keys()); _container_798.i != _container_798.e; ++_container_798 .i) if (int group = *_container_798.i; false) {} else {
799 | added_menu_groups_[group].clear();
800 | }
801 | }
802 |
803 | void MainApplication::clearRemovedMenuGroupItems()
804 | {
805 | foreach (int group, removed_menu_groups_.keys())for (auto _container_805 = QtPrivate::qMakeForeachContainer(removed_menu_groups_ .keys()); _container_805.i != _container_805.e; ++_container_805 .i) if (int group = *_container_805.i; false) {} else {
806 | foreach (QAction *action, removed_menu_groups_[group])for (auto _container_806 = QtPrivate::qMakeForeachContainer(removed_menu_groups_ [group]); _container_806.i != _container_806.e; ++_container_806 .i) if (QAction *action = *_container_806.i; false) {} else {
807 | delete action;
808 | }
809 | removed_menu_groups_[group].clear();
810 | }
811 | }
812 |
813 | #ifdef HAVE_LIBPCAP1
814 |
815 | static void
816 | iface_mon_event_cb(const char *iface, int added, int up)
817 | {
818 | int present = 0;
819 | unsigned ifs, j;
820 | interface_t *device;
821 | interface_options *interface_opts;
822 |
823 | for (ifs = 0; ifs < global_capture_opts.all_ifaces->len; ifs++) {
824 | device = &g_array_index(global_capture_opts.all_ifaces, interface_t, ifs)(((interface_t*) (void *) (global_capture_opts.all_ifaces)-> data) [(ifs)]);
825 | if (strcmp(device->name, iface) == 0) {
826 | present = 1;
827 | if (!up) {
828 | /*
829 | * Interface went down or disappeared; remove all instances
830 | * of it from the current list of interfaces selected
831 | * for capturing.
832 | */
833 | for (j = 0; j < global_capture_opts.ifaces->len; j++) {
834 | interface_opts = &g_array_index(global_capture_opts.ifaces, interface_options, j)(((interface_options*) (void *) (global_capture_opts.ifaces)-> data) [(j)]);
835 | if (strcmp(interface_opts->name, device->name) == 0) {
836 | capture_opts_del_iface(&global_capture_opts, j);
837 | }
838 | }
839 | }
840 | }
841 | }
842 |
843 | mainApp->emitLocalInterfaceEvent(iface, added, up);
844 | if (present != up) {
845 | /*
846 | * We've been told that there's a new interface or that an old
847 | * interface is gone; reload the local interface list.
848 | *
849 | * XXX: We also want to reload the local interface list if [what
850 | * we can retrieve about] the capabilities of the device have changed.
851 | * Ideally we'd update the capabilities of just the one device in
852 | * the cache and signal that the list has been updated, instead of
853 | * freeing the entire cache and scanning again - but some extcaps
854 | * depend on other interfaces being up; e.g. by default androiddump
855 | * tries to connect to the loopback interface to look for adb running,
856 | * so if the loopback interface changes so does the status of
857 | * androiddump.
858 | *
859 | * On Linux, at least, you can't get the capabilities from a down
860 | * interface, but it's still present in all_ifaces - dumpcap returns
861 | * it in the list, and we show it so the user can get a status / error
862 | * message when trying to capture on it instead of it vanishing.
863 | * So if both present and up are true, then we still want to refresh
864 | * to update the capabilities and restart the stats.
865 | *
866 | * We also store the address in all_ifaces and show them to the user,
867 | * so we probably should monitor those events as well and update
868 | * the interface list appropriately when those change.
869 | */
870 | mainApp->refreshLocalInterfaces();
871 | }
872 | }
873 |
874 | #endif
875 |
876 | void MainApplication::ifChangeEventsAvailable()
877 | {
878 | #ifdef HAVE_LIBPCAP1
879 | /*
880 | * Something's readable from the descriptor for interface
881 | * monitoring.
882 | *
883 | * Have the interface-monitoring code Read whatever interface-change
884 | * events are available, and call the callback for them.
885 | */
886 | iface_mon_event();
887 | #endif
888 | }
889 |
890 | void MainApplication::emitLocalInterfaceEvent(const char *ifname, int added, int up)
891 | {
892 | emit localInterfaceEvent(ifname, added, up);
893 | }
894 |
895 | void MainApplication::refreshLocalInterfaces()
896 | {
897 | if (active_captures_ > 0) {
898 | refresh_interfaces_pending_ = true;
899 | return;
900 | }
901 |
902 | refresh_interfaces_pending_ = false;
903 | extcap_clear_interfaces();
904 |
905 | #ifdef HAVE_LIBPCAP1
906 | emit scanLocalInterfaces(nullptr);
907 | #endif
908 | }
909 |
910 | #ifdef HAVE_LIBPCAP1
911 | GList* MainApplication::getInterfaceList() const
912 | {
913 | return interface_list_copy(cached_if_list_);
914 | }
915 |
916 | void MainApplication::setInterfaceList(GList *if_list)
917 | {
918 | free_interface_list(cached_if_list_);
919 | cached_if_list_ = interface_list_copy(if_list);
920 | }
921 | #endif
922 |
923 | void MainApplication::allSystemsGo()
924 | {
925 | QString display_filter = NULL__null;
926 | initialized_ = true;
927 | emit appInitialized();
928 | while (pending_open_files_.length() > 0) {
929 | emit openCaptureFile(pending_open_files_.front(), display_filter, WTAP_TYPE_AUTO0);
930 | pending_open_files_.pop_front();
931 | }
932 |
933 | bool sideBarVisible = recent.gui_welcome_page_sidebar_tips_visible ||
934 | recent.gui_welcome_page_sidebar_learn_visible;
935 | SoftwareUpdate::instance()->init(!sideBarVisible);
936 |
937 | #ifdef HAVE_LIBPCAP1
938 | int err;
939 | err = iface_mon_start(&iface_mon_event_cb);
940 | if (err == 0) {
941 | if_notifier_ = new QSocketNotifier(iface_mon_get_sock(),
942 | QSocketNotifier::Read, this);
943 | connect(if_notifier_, &QSocketNotifier::activated, this, &MainApplication::ifChangeEventsAvailable);
944 | }
945 | #endif
946 | }
947 |
948 | _e_prefs *MainApplication::readConfigurationFiles(bool reset)
949 | {
950 | e_prefs *prefs_p;
951 |
952 | if (reset) {
953 | //
954 | // Reset current preferences and enabled/disabled protocols and
955 | // heuristic dissectors before reading.
956 | // (Needed except when this is called at startup.)
957 | //
958 | prefs_reset(application_configuration_environment_prefix(), application_columns(), application_num_columns());
959 | proto_reenable_all();
960 | }
961 |
962 | /* Load libwireshark settings from the current profile. */
963 | prefs_p = epan_load_settings();
964 |
965 | return prefs_p;
966 | }
967 |
968 | static void switchTranslator(QTranslator& myTranslator, const QString& filename,
969 | const QString& searchPath)
970 | {
971 | mainApp->removeTranslator(&myTranslator);
972 |
973 | if (myTranslator.load(filename, searchPath))
974 | mainApp->installTranslator(&myTranslator);
975 | }
976 |
977 | void MainApplication::loadLanguage(const QString newLanguage)
978 | {
979 | QLocale locale;
980 | QString localeLanguage;
981 | const char* env_prefix = application_configuration_environment_prefix();
982 |
983 | if (newLanguage.isEmpty() || newLanguage == USE_SYSTEM_LANGUAGE"system") {
984 | locale = QLocale::system();
985 | localeLanguage = locale.name();
986 | } else {
987 | localeLanguage = newLanguage;
988 | locale = QLocale(localeLanguage);
989 | }
990 |
991 | QLocale::setDefault(locale);
992 | switchTranslator(mainApp->translator,
993 | QStringLiteral("wireshark_%1.qm")(QString(QtPrivate::qMakeStringPrivate(u"" "wireshark_%1.qm") )).arg(localeLanguage), QStringLiteral(":/i18n/")(QString(QtPrivate::qMakeStringPrivate(u"" ":/i18n/"))));
994 | if (QFile::exists(QStringLiteral("%1/%2/wireshark_%3.qm")(QString(QtPrivate::qMakeStringPrivate(u"" "%1/%2/wireshark_%3.qm" )))
995 | .arg(get_datafile_dir(env_prefix)).arg("languages").arg(localeLanguage)))
996 | switchTranslator(mainApp->translator,
997 | 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)));
998 | if (QFile::exists(QStringLiteral("%1/wireshark_%3.qm")(QString(QtPrivate::qMakeStringPrivate(u"" "%1/wireshark_%3.qm" )))
999 | .arg(gchar_free_to_qstring(get_persconffile_path("languages", false, env_prefix))).arg(localeLanguage)))
1000 | switchTranslator(mainApp->translator,
1001 | QStringLiteral("wireshark_%1.qm")(QString(QtPrivate::qMakeStringPrivate(u"" "wireshark_%1.qm") )).arg(localeLanguage), gchar_free_to_qstring(get_persconffile_path("languages", false, env_prefix)));
1002 | 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))) {
1004 | switchTranslator(mainApp->translatorQt,
1005 | QStringLiteral("qt_%1.qm")(QString(QtPrivate::qMakeStringPrivate(u"" "qt_%1.qm"))).arg(localeLanguage), QString(get_datafile_dir(env_prefix)));
1006 | } else if (QFile::exists(QStringLiteral("%1/qt_%2.qm")(QString(QtPrivate::qMakeStringPrivate(u"" "%1/qt_%2.qm")))
1007 | .arg(get_datafile_dir(env_prefix)).arg(localeLanguage.left(localeLanguage.lastIndexOf('_'))))) {
1008 | switchTranslator(mainApp->translatorQt,
1009 | QStringLiteral("qt_%1.qm")(QString(QtPrivate::qMakeStringPrivate(u"" "qt_%1.qm"))).arg(localeLanguage.left(localeLanguage.lastIndexOf('_'))), QString(get_datafile_dir(env_prefix)));
1010 | } else {
1011 | #if QT_VERSION((6<<16)|(4<<8)|(2)) >= QT_VERSION_CHECK(6, 0, 0)((6<<16)|(0<<8)|(0))
1012 | QString translationPath = QLibraryInfo::path(QLibraryInfo::TranslationsPath);
1013 | #else
1014 | QString translationPath = QLibraryInfo::location(QLibraryInfo::TranslationsPath);
1015 | #endif
1016 | switchTranslator(mainApp->translatorQt, QStringLiteral("qt_%1.qm")(QString(QtPrivate::qMakeStringPrivate(u"" "qt_%1.qm"))).arg(localeLanguage), translationPath);
1017 | }
1018 | }
1019 |
1020 | void MainApplication::doTriggerMenuItem(MainMenuItem menuItem)
1021 | {
1022 | switch (menuItem)
1023 | {
1024 | case FileOpenDialog:
1025 | emit openCaptureFile(QString(), QString(), WTAP_TYPE_AUTO0);
1026 | break;
1027 | case CaptureOptionsDialog:
1028 | emit openCaptureOptions();
1029 | break;
1030 | }
1031 | }
1032 |
1033 | void MainApplication::zoomTextFont(int zoomLevel)
1034 | {
1035 | // Scale by 10%, rounding to nearest half point, minimum 1 point.
1036 | // XXX Small sizes repeat. It might just be easier to create a map of multipliers.
1037 | qreal zoom_size = mono_font_.pointSize() * 2 * qPow(qreal(1.1), zoomLevel);
1038 | zoom_size = qRound(zoom_size) / qreal(2.0);
1039 | zoom_size = qMax(zoom_size, qreal(1.0));
1040 |
1041 | zoomed_font_ = mono_font_;
1042 | zoomed_font_.setPointSizeF(zoom_size);
1043 | emit zoomMonospaceFont(zoomed_font_);
1044 |
1045 | QFont zoomed_application_font = font();
1046 | zoomed_application_font.setPointSizeF(zoom_size);
1047 | emit zoomRegularFont(zoomed_application_font);
1048 | }
1049 |
1050 | void MainApplication::captureEventHandler(CaptureEvent ev)
1051 | {
1052 | switch(ev.captureContext())
1053 | {
1054 | #ifdef HAVE_LIBPCAP1
1055 | case CaptureEvent::Update:
1056 | case CaptureEvent::Fixed:
1057 | switch (ev.eventType())
1058 | {
1059 | case CaptureEvent::Prepared:
1060 | iface_mon_enable(true);
1061 | break;
1062 | case CaptureEvent::Started:
1063 | active_captures_++;
1064 | emit captureActive(active_captures_);
1065 | break;
1066 | case CaptureEvent::Finished:
1067 | active_captures_--;
1068 | emit captureActive(active_captures_);
1069 | if (refresh_interfaces_pending_ && !global_capture_opts.restart) {
1070 | refreshLocalInterfaces();
1071 | }
1072 | break;
1073 | default:
1074 | break;
1075 | }
1076 | break;
1077 | #endif
1078 | case CaptureEvent::File:
1079 | case CaptureEvent::Reload:
1080 | case CaptureEvent::Rescan:
1081 | switch (ev.eventType())
1082 | {
1083 | case CaptureEvent::Started:
1084 | QTimer::singleShot(TAP_UPDATE_DEFAULT_INTERVAL3000 / 5, this, SLOT(updateTaps())qFlagLocation("1" "updateTaps()" "\0" "ui/qt/main_application.cpp" ":" "1084"));
1085 | QTimer::singleShot(TAP_UPDATE_DEFAULT_INTERVAL3000 / 2, this, SLOT(updateTaps())qFlagLocation("1" "updateTaps()" "\0" "ui/qt/main_application.cpp" ":" "1085"));
1086 | break;
1087 | case CaptureEvent::Finished:
1088 | updateTaps();
1089 | break;
1090 | default:
1091 | break;
1092 | }
1093 | break;
1094 | default:
1095 | break;
1096 | }
1097 | }
1098 |
1099 | void MainApplication::pushStatus(StatusInfo status, const QString &message, const QString &messagetip)
1100 | {
1101 | MainWindow * mw = mainWindow();
1102 | if (! mw) {
1103 | return;
1104 | }
1105 |
1106 | MainStatusBar * bar = mw->statusBar();
1107 | if (! bar) {
1108 | return;
1109 | }
1110 |
1111 | switch(status)
1112 | {
1113 | case FilterSyntax:
1114 | bar->pushGenericStatus(MainStatusBar::STATUS_CTX_FILTER, message);
1115 | break;
1116 | case FieldStatus:
1117 | bar->pushGenericStatus(MainStatusBar::STATUS_CTX_FIELD, message);
1118 | break;
1119 | case FileStatus:
1120 | bar->pushGenericStatus(MainStatusBar::STATUS_CTX_FILE, message, messagetip);
1121 | break;
1122 | case ByteStatus:
1123 | bar->pushGenericStatus(MainStatusBar::STATUS_CTX_BYTE, message);
1124 | break;
1125 | case BusyStatus:
1126 | bar->pushGenericStatus(MainStatusBar::STATUS_CTX_PROGRESS, message, messagetip);
1127 | break;
1128 | case TemporaryStatus:
1129 | bar->pushGenericStatus(MainStatusBar::STATUS_CTX_TEMPORARY, message);
1130 | break;
1131 | }
1132 | }
1133 |
1134 | void MainApplication::popStatus(StatusInfo status)
1135 | {
1136 | MainWindow * mw = mainWindow();
1137 | if (! mw) {
1138 | return;
1139 | }
1140 |
1141 | MainStatusBar * bar = mw->statusBar();
1142 | if (! bar) {
1143 | return;
1144 | }
1145 |
1146 | switch(status)
1147 | {
1148 | case FilterSyntax:
1149 | bar->popGenericStatus(MainStatusBar::STATUS_CTX_FILTER);
1150 | break;
1151 | case FieldStatus:
1152 | bar->popGenericStatus(MainStatusBar::STATUS_CTX_FIELD);
1153 | break;
1154 | case FileStatus:
1155 | bar->popGenericStatus(MainStatusBar::STATUS_CTX_FILE);
1156 | break;
1157 | case ByteStatus:
1158 | bar->popGenericStatus(MainStatusBar::STATUS_CTX_BYTE);
1159 | break;
1160 | case BusyStatus:
1161 | bar->popGenericStatus(MainStatusBar::STATUS_CTX_PROGRESS);
1162 | break;
1163 | case TemporaryStatus:
1164 | bar->popGenericStatus(MainStatusBar::STATUS_CTX_TEMPORARY);
1165 | break;
1166 | }
1167 | }
1168 |
1169 | void MainApplication::gotoFrame(int frame)
1170 | {
1171 | MainWindow * mw = mainWindow();
1172 | if (! mw) {
1173 | return;
1174 | }
1175 |
1176 | mw->gotoFrame(frame);
1177 | }
1178 |
1179 | void MainApplication::reloadDisplayFilterMacros()
1180 | {
1181 | dfilter_macro_reload(application_configuration_environment_prefix());
1182 | // The signal is needed when the display filter grammar changes for
1183 | // any reason (not just "fields".)
1184 | mainApp->emitAppSignal(MainApplication::FieldsChanged);
1185 | }