aboutsummaryrefslogtreecommitdiffstats
path: root/ui
diff options
context:
space:
mode:
authorStig Bjørlykke <stig@bjorlykke.org>2018-09-11 09:47:50 +0200
committerStig Bjørlykke <stig@bjorlykke.org>2018-09-11 09:19:56 +0000
commit4df2fcb0eef156b40bd3ffd37df0da2885293094 (patch)
tree358029e77ffb8640a077387ca8c5349b6ac79af9 /ui
parentf6b8bc39c66c878ff25a4f48fff382f8775a2711 (diff)
Qt: Replace $HOME with ~ in window title %F variable
Replace $HOME with ~ in window title %F variable. Optimize code to check if variable is used before doing replacement. Change-Id: I95ef8505e50379d98fdb1661e09394d1ded7ecca Reviewed-on: https://code.wireshark.org/review/29597 Petri-Dish: Stig Bjørlykke <stig@bjorlykke.org> Tested-by: Petri Dish Buildbot Reviewed-by: Stig Bjørlykke <stig@bjorlykke.org>
Diffstat (limited to 'ui')
-rw-r--r--ui/qt/main_window.cpp45
1 files changed, 30 insertions, 15 deletions
diff --git a/ui/qt/main_window.cpp b/ui/qt/main_window.cpp
index b00fc1d463..d21a53ca85 100644
--- a/ui/qt/main_window.cpp
+++ b/ui/qt/main_window.cpp
@@ -2169,26 +2169,41 @@ QString MainWindow::replaceWindowTitleVariables(QString title)
{
title.replace("%P", get_profile_name());
title.replace("%V", get_ws_vcs_version_info());
- if (capture_file_.capFile()) {
- // get_dirname() will overwrite the argument so make a copy first
- char *filename = g_strdup(capture_file_.capFile()->filename);
- title.replace("%F", get_dirname(filename));
- g_free(filename);
- } else {
- // No file loaded, no folder name
- title.remove("%F");
+
+ if (title.contains("%F")) {
+ // %F is file path of the capture file.
+ if (capture_file_.capFile()) {
+ // get_dirname() will overwrite the argument so make a copy first
+ char *filename = g_strdup(capture_file_.capFile()->filename);
+ QString file(get_dirname(filename));
+ g_free(filename);
+#ifndef _WIN32
+ // Substitute HOME with ~
+ QString homedir(g_getenv("HOME"));
+ if (!homedir.isEmpty()) {
+ homedir.remove(QRegExp("[/]+$"));
+ file.replace(homedir, "~");
+ }
+#endif
+ title.replace("%F", file);
+ } else {
+ // No file loaded, no folder name
+ title.remove("%F");
+ }
}
- // %S is a conditional separator (" - ") that only shows when surrounded by variables
- // with values or static text. Remove repeating, leading and trailing separators.
- title.replace(QRegExp("(%S)+"), "%S");
- title.replace(QRegExp("^%S|%S$"), "");
+ if (title.contains("%S")) {
+ // %S is a conditional separator (" - ") that only shows when surrounded by variables
+ // with values or static text. Remove repeating, leading and trailing separators.
+ title.replace(QRegExp("(%S)+"), "%S");
+ title.remove(QRegExp("^%S|%S$"));
#ifdef __APPLE__
- // On macOS we separate with a unicode em dash
- title.replace("%S", " " UTF8_EM_DASH " ");
+ // On macOS we separate with a unicode em dash
+ title.replace("%S", " " UTF8_EM_DASH " ");
#else
- title.replace("%S", " - ");
+ title.replace("%S", " - ");
#endif
+ }
return title;
}