### Bug Summary

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