From 77046c0c2dfb882c24194aa785480cac2d7ddadd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Stig=20Bj=C3=B8rlykke?= Date: Tue, 19 Jan 2016 18:26:41 +0100 Subject: [PATCH] Qt: Add some window title variables MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Add some variables to be used in custom window title. %P = profile name %V = version info Change-Id: I049717432a4d3523b541bb4f6f882c75abc38ddb Reviewed-on: https://code.wireshark.org/review/13419 Reviewed-by: Stig Bjørlykke --- epan/prefs.c | 4 ++-- ui/qt/main_window.cpp | 17 ++++++++++++++--- ui/qt/main_window.h | 1 + 3 files changed, 17 insertions(+), 5 deletions(-) diff --git a/epan/prefs.c b/epan/prefs.c index f1cfffcf25..822befb753 100644 --- a/epan/prefs.c +++ b/epan/prefs.c @@ -2334,11 +2334,11 @@ prefs_register_modules(void) &prefs.gui_update_interval); register_string_like_preference(gui_module, "window_title", "Custom window title", - "Custom window title. (Appended to existing titles.)", + "Custom window title to be appended to the existing title\n%P = profile name\n%V = version info", &prefs.gui_window_title, PREF_STRING, NULL, TRUE); register_string_like_preference(gui_module, "prepend_window_title", "Custom window title prefix", - "Custom window title. (Prepended to existing titles.)", + "Custom window title to be prepended to the existing title\n%P = profile name\n%V = version info", &prefs.gui_prepend_window_title, PREF_STRING, NULL, TRUE); register_string_like_preference(gui_module, "start_title", "Custom start page title", diff --git a/ui/qt/main_window.cpp b/ui/qt/main_window.cpp index 134c0af677..32d165b013 100644 --- a/ui/qt/main_window.cpp +++ b/ui/qt/main_window.cpp @@ -25,6 +25,7 @@ #include #include #include +#include #include #include #include @@ -1934,6 +1935,14 @@ void MainWindow::setTitlebarForCaptureFile() } } +QString MainWindow::replaceWindowTitleVariables(QString title) +{ + title.replace ("%P", get_profile_name()); + title.replace ("%V", get_ws_vcs_version_info()); + + return title; +} + void MainWindow::setWSWindowTitle(QString title) { if (title.isEmpty()) { @@ -1941,15 +1950,17 @@ void MainWindow::setWSWindowTitle(QString title) } if (prefs.gui_prepend_window_title && prefs.gui_prepend_window_title[0]) { - title.prepend(QString("[%1] ").arg(prefs.gui_prepend_window_title)); + QString customTitle = replaceWindowTitleVariables(prefs.gui_prepend_window_title); + title.prepend(QString("[%1] ").arg(customTitle)); } if (prefs.gui_window_title && prefs.gui_window_title[0]) { + QString customTitle = replaceWindowTitleVariables(prefs.gui_window_title); #ifdef __APPLE__ // On OS X we separate the titles with a unicode em dash - title.append(QString(" %1 %2").arg(UTF8_EM_DASH).arg(prefs.gui_window_title)); + title.append(QString(" %1 %2").arg(UTF8_EM_DASH).arg(customTitle)); #else - title.append(QString(" [%1]").arg(prefs.gui_window_title)); + title.append(QString(" [%1]").arg(customTitle)); #endif } diff --git a/ui/qt/main_window.h b/ui/qt/main_window.h index ce2c2df928..a13aa052e2 100644 --- a/ui/qt/main_window.h +++ b/ui/qt/main_window.h @@ -202,6 +202,7 @@ private: void setForCapturedPackets(bool have_captured_packets); void setMenusForFileSet(bool enable_list_files); void setWindowIcon(const QIcon &icon); + QString replaceWindowTitleVariables(QString title); void externalMenuHelper(ext_menu_t * menu, QMenu * subMenu, gint depth);