aboutsummaryrefslogtreecommitdiffstats
path: root/ui
diff options
context:
space:
mode:
authorGuy Harris <guy@alum.mit.edu>2018-07-03 15:14:50 -0700
committerGuy Harris <guy@alum.mit.edu>2018-07-03 22:17:15 +0000
commit670377f491dd11bfe2b59738e9dfb329dbc826d4 (patch)
treef738a1b3e0b98e4d6bd603e9d61d861d29793303 /ui
parent03200d951d75ef7467cd2e4fd17769fab2e6518b (diff)
Don't show temporary file names in title bars.
For dialogs and auxiliary windows, if we have a live capture that hasn't yet been saved to a permanent location, there's no good reason to show the temporary file name in the title bar, as: it's a random string that doesn't indicate where the capture was done and that could confuse people (see, for example, the confusion in bug 14929, in which somebody referred to the "Follow TCP Stream" window as the ".pcap dialog" because its title had ".pcap" at the end, due to the capture file being a temporary file and its name showing up in the title bar of that window); it differs from what the main window title bar shows. While we're at it, don't assume that the file name in the capture_file structure is a UTF-8 string - some UN*Xes might not use UTF-8 for file names. Change-Id: I0d3dfd5d7f896ea37533daf7089b688710dbabf0 Reviewed-on: https://code.wireshark.org/review/28581 Reviewed-by: Guy Harris <guy@alum.mit.edu>
Diffstat (limited to 'ui')
-rw-r--r--ui/qt/capture_file.cpp36
-rw-r--r--ui/qt/capture_file.h22
2 files changed, 52 insertions, 6 deletions
diff --git a/ui/qt/capture_file.cpp b/ui/qt/capture_file.cpp
index d6e9fe6b98..fc4ae6c907 100644
--- a/ui/qt/capture_file.cpp
+++ b/ui/qt/capture_file.cpp
@@ -115,11 +115,43 @@ int CaptureFile::currentRow()
return -1;
}
+const QString CaptureFile::fileTitle()
+{
+ if (isValid() && cap_file_->is_tempfile) {
+ //
+ // For a temporary file, put the source of the data
+ // in the window title, not whatever random pile
+ // of characters is the last component of the path
+ // name.
+ //
+ return cf_get_tempfile_source(cap_file_) + file_state_;
+ } else {
+ return fileName() + file_state_;
+ }
+}
+
const QString CaptureFile::fileName()
{
if (isValid()) {
- QFileInfo cfi(QString::fromUtf8(cap_file_->filename));
- file_name_ = cfi.fileName();
+ //
+ // Sadly, some UN*Xes don't necessarily use UTF-8
+ // for their file names, so we have to map the
+ // file path to UTF-8. If that fails, we're somewhat
+ // stuck.
+ //
+ char *utf8_filename = g_filename_to_utf8(cap_file_->filename,
+ -1,
+ NULL,
+ NULL,
+ NULL);
+ if (utf8_filename) {
+ QFileInfo cfi(QString::fromUtf8(utf8_filename));
+ file_name_ = cfi.fileName();
+ g_free(utf8_filename);
+ } else {
+ // So what the heck else can we do here?
+ file_name_ = tr("(File name can't be mapped to UTF-8)");
+ }
}
return file_name_;
diff --git a/ui/qt/capture_file.h b/ui/qt/capture_file.h
index 90ae6d175c..f5f3ad948f 100644
--- a/ui/qt/capture_file.h
+++ b/ui/qt/capture_file.h
@@ -43,12 +43,26 @@ public:
*/
int currentRow();
- /** Return a filename suitable for use in a window title.
+ /** Return a string representing the file suitable for use in a
+ * window title.
*
- * @return One of: the basename of the capture file without an extension,
- * the basename followed by "[closing]", "[closed]", or "[no capture file]".
+ * @return One of:
+ *
+ * the devices on which the capture was done, if the file is a
+ * temporary file for a capture;
+ *
+ * the last component of the capture file's name, if it's a
+ * permanent file and isn't being closed;
+ *
+ * the last component of the capture file's name, followed
+ * by [closing], if it's a permanent file and is being closed;
+ *
+ * the last component of the capture file's name, followed
+ * by [closed], if it's a permanent file and has been closed;
+ *
+ * [no capture file], if there is no capture file.
*/
- const QString fileTitle() { return fileName() + file_state_; }
+ const QString fileTitle();
/** Return the plain filename.
*