From 874c978bbce62a7ed43934249057c4937d299627 Mon Sep 17 00:00:00 2001 From: Guy Harris Date: Thu, 5 Jul 2018 17:31:02 -0700 Subject: [PATCH] Use the file *base* name for statistics graphs etc.. For example, if the file is foo.pcap, make the default name for a saved PDF of some graph be foo.pdf, as it was prior to 2.6, not foo.pcap.pdf. Change-Id: Ide99c9c7fa1f3d16f829e731f968a209fbb52b8d Reviewed-on: https://code.wireshark.org/review/28624 Reviewed-by: Guy Harris --- ui/qt/capture_file.cpp | 15 +++++++++++++++ ui/qt/capture_file.h | 8 ++++++++ ui/qt/iax2_analysis_dialog.cpp | 2 +- ui/qt/io_graph_dialog.cpp | 2 +- ui/qt/rtp_analysis_dialog.cpp | 2 +- ui/qt/rtp_stream_dialog.cpp | 2 +- 6 files changed, 27 insertions(+), 4 deletions(-) diff --git a/ui/qt/capture_file.cpp b/ui/qt/capture_file.cpp index 019657f3cc..3aee4f557c 100644 --- a/ui/qt/capture_file.cpp +++ b/ui/qt/capture_file.cpp @@ -158,6 +158,21 @@ const QString CaptureFile::fileName() return name; } +const QString CaptureFile::fileBaseName() +{ + QString path, baseName; + + path = filePath(); + if (!path.isEmpty()) { + QFileInfo cfi(path); + baseName = cfi.baseName(); + } else { + baseName = QString(); + } + + return baseName; +} + const QString CaptureFile::fileDisplayName() { QString displayName; diff --git a/ui/qt/capture_file.h b/ui/qt/capture_file.h index 160644ed4a..8fd8ce680d 100644 --- a/ui/qt/capture_file.h +++ b/ui/qt/capture_file.h @@ -59,6 +59,14 @@ public: */ const QString fileName(); + /** Return the plain filename without an extension. + * + * @return The last component of the pathname, without 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 fileBaseName(); + /** Return a string representing the file suitable for use for * display in the UI in places such as a main window title. * diff --git a/ui/qt/iax2_analysis_dialog.cpp b/ui/qt/iax2_analysis_dialog.cpp index ec92272a65..00472f1ef5 100644 --- a/ui/qt/iax2_analysis_dialog.cpp +++ b/ui/qt/iax2_analysis_dialog.cpp @@ -571,7 +571,7 @@ void Iax2AnalysisDialog::on_actionSaveGraph_triggered() QString save_file = path.canonicalPath(); if (!file_closed_) { - save_file += QString("/%1").arg(cap_file_.fileName()); + save_file += QString("/%1").arg(cap_file_.fileBaseName()); } file_name = WiresharkFileDialog::getSaveFileName(this, wsApp->windowTitleString(tr("Save Graph As" UTF8_HORIZONTAL_ELLIPSIS)), save_file, filter, &extension); diff --git a/ui/qt/io_graph_dialog.cpp b/ui/qt/io_graph_dialog.cpp index ed654febb7..7965f11c7a 100644 --- a/ui/qt/io_graph_dialog.cpp +++ b/ui/qt/io_graph_dialog.cpp @@ -1402,7 +1402,7 @@ void IOGraphDialog::on_buttonBox_accepted() QString save_file = path.canonicalPath(); if (!file_closed_) { - save_file += QString("/%1").arg(cap_file_.fileName()); + save_file += QString("/%1").arg(cap_file_.fileBaseName()); } file_name = WiresharkFileDialog::getSaveFileName(this, wsApp->windowTitleString(tr("Save Graph As" UTF8_HORIZONTAL_ELLIPSIS)), save_file, filter, &extension); diff --git a/ui/qt/rtp_analysis_dialog.cpp b/ui/qt/rtp_analysis_dialog.cpp index 5867123bfb..86bd9ca4fd 100644 --- a/ui/qt/rtp_analysis_dialog.cpp +++ b/ui/qt/rtp_analysis_dialog.cpp @@ -609,7 +609,7 @@ void RtpAnalysisDialog::on_actionSaveGraph_triggered() QString save_file = path.canonicalPath(); if (!file_closed_) { - save_file += QString("/%1").arg(cap_file_.fileName()); + save_file += QString("/%1").arg(cap_file_.fileBaseName()); } file_name = WiresharkFileDialog::getSaveFileName(this, wsApp->windowTitleString(tr("Save Graph As" UTF8_HORIZONTAL_ELLIPSIS)), save_file, filter, &extension); diff --git a/ui/qt/rtp_stream_dialog.cpp b/ui/qt/rtp_stream_dialog.cpp index 280af9fc27..9d14788cae 100644 --- a/ui/qt/rtp_stream_dialog.cpp +++ b/ui/qt/rtp_stream_dialog.cpp @@ -497,7 +497,7 @@ void RtpStreamDialog::on_actionExportAsRtpDump_triggered() if (stream_info) { QString file_name; QDir path(wsApp->lastOpenDir()); - QString save_file = path.canonicalPath() + "/" + cap_file_.fileName(); + QString save_file = path.canonicalPath() + "/" + cap_file_.fileBaseName(); QString extension; file_name = WiresharkFileDialog::getSaveFileName(this, wsApp->windowTitleString(tr("Save RTPDump As" UTF8_HORIZONTAL_ELLIPSIS)), save_file, "RTPDump Format (*.rtpdump)", &extension);