aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGuy Harris <guy@alum.mit.edu>2018-07-04 10:45:00 -0700
committerGuy Harris <guy@alum.mit.edu>2018-07-04 17:45:47 +0000
commit1c6dc6d31f147d1ea7b8694204e81cf5d827de23 (patch)
treedbbcec262aa62b42526f1f64cc7ab2e553e78c20
parent018025e3bc112821130a99e3ec94a53c35bc5878 (diff)
Some fixes.
For filePath() and fileName(), just return a null string if we can't convert from the native encoding to UTF-8 - those aren't used for displaying, those are used for setting the main window's file name and for generating names of files to save based on the capture file name. Have fileDisplayName() just return the display name, without "[closing]"/"[closed]" decoration or a special case for no file being open (just return a null string if there's no file open), and have fileTitle() return the decorated display name. Change-Id: I244f318d5444dcf58527e5d38c4d073c28b73810 Reviewed-on: https://code.wireshark.org/review/28594 Reviewed-by: Guy Harris <guy@alum.mit.edu>
-rw-r--r--ui/qt/capture_file.cpp25
-rw-r--r--ui/qt/capture_file.h40
-rw-r--r--ui/qt/wireshark_dialog.cpp2
3 files changed, 48 insertions, 19 deletions
diff --git a/ui/qt/capture_file.cpp b/ui/qt/capture_file.cpp
index af578729d2..019657f3cc 100644
--- a/ui/qt/capture_file.cpp
+++ b/ui/qt/capture_file.cpp
@@ -135,7 +135,7 @@ const QString CaptureFile::filePath()
g_free(utf8_filename);
} else {
// So what the heck else can we do here?
- path = tr("(File name can't be mapped to UTF-8)");
+ path = QString();
}
} else {
path = QString();
@@ -145,10 +145,11 @@ const QString CaptureFile::filePath()
const QString CaptureFile::fileName()
{
- QString name;
+ QString path, name;
- if (isValid()) {
- QFileInfo cfi(filePath());
+ path = filePath();
+ if (!path.isEmpty()) {
+ QFileInfo cfi(path);
name = cfi.fileName();
} else {
name = QString();
@@ -159,13 +160,25 @@ const QString CaptureFile::fileName()
const QString CaptureFile::fileDisplayName()
{
- QString title;
+ QString displayName;
if (isValid()) {
char *display_name = cf_get_display_name(cap_file_);
- title = display_name + file_state_;
+ displayName = display_name;
g_free(display_name);
} else {
+ displayName = QString();
+ }
+ return displayName;
+}
+
+const QString CaptureFile::fileTitle()
+{
+ QString title;
+
+ if (isValid()) {
+ title = fileDisplayName() + file_state_;
+ } else {
title = no_capture_file_;
}
return title;
diff --git a/ui/qt/capture_file.h b/ui/qt/capture_file.h
index 7cf9e6ec36..160644ed4a 100644
--- a/ui/qt/capture_file.h
+++ b/ui/qt/capture_file.h
@@ -45,37 +45,53 @@ public:
/** Return the full pathname.
*
- * @return The entire pathname.
+ * @return The entire pathname, converted from the native OS's encoding
+ * to Unicode if necessary, or a null string if the conversion can't
+ * be done.
*/
const QString filePath();
/** Return the plain filename.
*
- * @return The last component of the pathname; this includes the
- * extension.
+ * @return The last component of the pathname, including the extension,
+ * converted from the native OS's encoding to Unicode if necessary, or
+ * a null string if the conversion can't be done.
*/
const QString fileName();
- /** Return a string representing the file suitable for use in a
- * window title.
+ /** Return a string representing the file suitable for use for
+ * display in the UI in places such as a main window title.
*
* @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, converted
+ * from the native OS's encoding to Unicode if necessary (and
+ * with REPLACEMENT CHARACTER inserted if the string can't
+ * be converted).
*
- * the last component of the capture file's name, followed
- * by [closing], if it's a permanent file and is being closed;
+ * a null string, if there is no capture file.
+ */
+ const QString fileDisplayName();
+
+ /** Return a string representing the file suitable for use in an
+ * auxiliary window title.
+ *
+ * @return One of:
+ *
+ * the result of fileDisplayName(), if the file is open;
*
- * the last component of the capture file's name, followed
- * by [closed], if it's a permanent file and has been closed;
+ * the result of fileDisplayName() followed by [closing], if
+ * the file is being closed;
+ *
+ * the result of fileDisplayName() followed by [closed], if
+ * the file has been closed;
*
* [no capture file], if there is no capture file.
*/
- const QString fileDisplayName();
+ const QString fileTitle();
/** Return the current packet information.
*
diff --git a/ui/qt/wireshark_dialog.cpp b/ui/qt/wireshark_dialog.cpp
index 15931e3d41..4a219c42f2 100644
--- a/ui/qt/wireshark_dialog.cpp
+++ b/ui/qt/wireshark_dialog.cpp
@@ -75,7 +75,7 @@ void WiresharkDialog::setWindowSubtitle(const QString &subtitle)
void WiresharkDialog::setWindowTitleFromSubtitle()
{
- QString title = wsApp->windowTitleString(QStringList() << subtitle_ << cap_file_.fileDisplayName());
+ QString title = wsApp->windowTitleString(QStringList() << subtitle_ << cap_file_.fileTitle());
QDialog::setWindowTitle(title);
}