aboutsummaryrefslogtreecommitdiffstats
path: root/ui/qt
diff options
context:
space:
mode:
authorPeter Wu <peter@lekensteyn.nl>2018-04-28 15:53:18 +0200
committerAnders Broman <a.broman58@gmail.com>2018-05-01 10:24:47 +0000
commit4d2844cceca4fdde1e293e3f404f8e820d2385b0 (patch)
tree90ae1b1c7c11875424c5981e2008e2da52267f32 /ui/qt
parent552ef8b1f4bc5ced263c82253ed21793ca8e5d5e (diff)
Qt: do not further modify filename from Save dialog
Let the Save dialog fixup the extension on accepting the dialog. Otherwise it is possible that files are silently overwritten without prompting. Additionally, if a user decides to save a pcapng file as "foo.pcap", do not try to rename it to "foo.pcap.pcapng". This change is limited to macOS and Linux because Windows uses a different file dialog. Tested with both macOS and Linux. Bug: 14600 Change-Id: Ie0bc1f579766a04f0aad96dcd5daba3fffef9764 Reviewed-on: https://code.wireshark.org/review/27188 Petri-Dish: Peter Wu <peter@lekensteyn.nl> Tested-by: Petri Dish Buildbot Reviewed-by: Anders Broman <a.broman58@gmail.com>
Diffstat (limited to 'ui/qt')
-rw-r--r--ui/qt/capture_file_dialog.cpp15
-rw-r--r--ui/qt/capture_file_dialog.h5
-rw-r--r--ui/qt/main_window.cpp8
-rw-r--r--ui/qt/main_window.h2
4 files changed, 29 insertions, 1 deletions
diff --git a/ui/qt/capture_file_dialog.cpp b/ui/qt/capture_file_dialog.cpp
index 90719d6a3e..852b2150a7 100644
--- a/ui/qt/capture_file_dialog.cpp
+++ b/ui/qt/capture_file_dialog.cpp
@@ -217,6 +217,21 @@ check_savability_t CaptureFileDialog::checkSaveAsWithComments(QWidget *
}
+#ifndef Q_OS_WIN
+void CaptureFileDialog::accept()
+{
+ // XXX also useful for Windows, but that uses a different dialog...
+ // Ensure that the filename has a valid extension before performing file
+ // existence checks and before closing the dialog.
+ // HACK: ensure that the filename field does not have the focus, otherwise
+ // selectFile will not change the filename.
+ setFocus();
+ fixFilenameExtension();
+ QFileDialog::accept();
+}
+#endif // ! Q_OS_WIN
+
+
// You have to use open, merge, saveAs, or exportPackets. We should
// probably just make each type a subclass.
int CaptureFileDialog::exec() {
diff --git a/ui/qt/capture_file_dialog.h b/ui/qt/capture_file_dialog.h
index 72c144de03..3ef4f02e51 100644
--- a/ui/qt/capture_file_dialog.h
+++ b/ui/qt/capture_file_dialog.h
@@ -126,7 +126,10 @@ signals:
public slots:
- int exec();
+#ifndef Q_OS_WIN
+ void accept() Q_DECL_OVERRIDE;
+#endif
+ int exec() Q_DECL_OVERRIDE;
int open(QString &file_name, unsigned int &type);
check_savability_t saveAs(QString &file_name, bool must_support_comments);
check_savability_t exportSelectedPackets(QString &file_name, packet_range_t *range);
diff --git a/ui/qt/main_window.cpp b/ui/qt/main_window.cpp
index 93ba8ca6c4..a0d71150b0 100644
--- a/ui/qt/main_window.cpp
+++ b/ui/qt/main_window.cpp
@@ -1464,7 +1464,10 @@ bool MainWindow::saveAsCaptureFile(capture_file *cf, bool must_support_comments,
file_type = save_as_dlg.selectedFileType();
compressed = save_as_dlg.isCompressed();
+#ifdef Q_OS_WIN
+ // the Windows dialog does not fixup extensions, do it manually here.
fileAddExtension(file_name, file_type, compressed);
+#endif // Q_OS_WIN
//#ifndef _WIN32
// /* If the file exists and it's user-immutable or not writable,
@@ -1587,7 +1590,10 @@ void MainWindow::exportSelectedPackets() {
file_type = esp_dlg.selectedFileType();
compressed = esp_dlg.isCompressed();
+#ifdef Q_OS_WIN
+ // the Windows dialog does not fixup extensions, do it manually here.
fileAddExtension(file_name, file_type, compressed);
+#endif // Q_OS_WIN
//#ifndef _WIN32
// /* If the file exists and it's user-immutable or not writable,
@@ -1643,6 +1649,7 @@ void MainWindow::exportDissections(export_type_e export_type) {
ed_dlg.exec();
}
+#ifdef Q_OS_WIN
void MainWindow::fileAddExtension(QString &file_name, int file_type, bool compressed) {
QString file_name_lower;
GSList *extensions_list;
@@ -1697,6 +1704,7 @@ void MainWindow::fileAddExtension(QString &file_name, int file_type, bool compre
}
}
}
+#endif // Q_OS_WIN
bool MainWindow::testCaptureFileClose(QString before_what, FileCloseContext context) {
bool capture_in_progress = false;
diff --git a/ui/qt/main_window.h b/ui/qt/main_window.h
index 427edcef00..163dcb8823 100644
--- a/ui/qt/main_window.h
+++ b/ui/qt/main_window.h
@@ -236,7 +236,9 @@ private:
void exportSelectedPackets();
void exportDissections(export_type_e export_type);
+#ifdef Q_OS_WIN
void fileAddExtension(QString &file_name, int file_type, bool compressed);
+#endif // Q_OS_WIN
bool testCaptureFileClose(QString before_what, FileCloseContext context = Default);
void captureStop();