Qt: Add some window title variables
authorStig Bjørlykke <stig@bjorlykke.org>
Tue, 19 Jan 2016 17:26:41 +0000 (18:26 +0100)
committerStig Bjørlykke <stig@bjorlykke.org>
Thu, 21 Jan 2016 18:22:05 +0000 (18:22 +0000)
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 <stig@bjorlykke.org>
epan/prefs.c
ui/qt/main_window.cpp
ui/qt/main_window.h

index f1cfffcf2575954dd15a5b4a3caa3e103ecff40e..822befb753be9155b9cc3250782397d597404e74 100644 (file)
@@ -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",
index 134c0af67775191a7d43a9295e755ba752c59e4b..32d165b013930442e9a355b878fe4d07878741a6 100644 (file)
@@ -25,6 +25,7 @@
 #include <epan/addr_resolv.h>
 #include <epan/epan_dissect.h>
 #include <wsutil/filesystem.h>
+#include <wsutil/ws_version_info.h>
 #include <epan/prefs.h>
 #include <epan/stats_tree_priv.h>
 #include <epan/plugin_if.h>
@@ -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
     }
 
index ce2c2df928d9f0a4ec573f082a1283f4f1e911cd..a13aa052e214073c014fb10a94f0898762c3db21 100644 (file)
@@ -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);