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