diff --git a/ui/qt/CMakeLists.txt b/ui/qt/CMakeLists.txt index 5b23e8d7a3..adc875ba72 100644 --- a/ui/qt/CMakeLists.txt +++ b/ui/qt/CMakeLists.txt @@ -38,6 +38,7 @@ set(WIRESHARK_WIDGET_HEADERS widgets/stock_icon_tool_button.h widgets/syntax_line_edit.h widgets/tabnav_tree_view.h + widgets/wireshark_file_dialog.h ) set(WIRESHARK_MANAGER_HEADERS @@ -266,6 +267,7 @@ set(WIRESHARK_WIDGET_SRCS widgets/stock_icon_tool_button.cpp widgets/syntax_line_edit.cpp widgets/tabnav_tree_view.cpp + widgets/wireshark_file_dialog.cpp ) set(WIRESHARK_MANAGER_SRCS diff --git a/ui/qt/bluetooth_att_server_attributes_dialog.cpp b/ui/qt/bluetooth_att_server_attributes_dialog.cpp index 721068593a..973c09d5ee 100644 --- a/ui/qt/bluetooth_att_server_attributes_dialog.cpp +++ b/ui/qt/bluetooth_att_server_attributes_dialog.cpp @@ -21,11 +21,12 @@ #include "ui/simple_dialog.h" +#include "ui/qt/widgets/wireshark_file_dialog.h" + #include #include #include #include -#include static const int column_number_handle = 0; static const int column_number_uuid = 1; @@ -356,7 +357,7 @@ void BluetoothAttServerAttributesDialog::on_actionSave_as_image_triggered() { QPixmap image; - QString fileName = QFileDialog::getSaveFileName(this, tr("Save Table Image"), + QString fileName = WiresharkFileDialog::getSaveFileName(this, tr("Save Table Image"), "att_server_attributes_table.png", tr("PNG Image (*.png)")); diff --git a/ui/qt/bluetooth_device_dialog.cpp b/ui/qt/bluetooth_device_dialog.cpp index e05013b19c..5c7b3b002c 100644 --- a/ui/qt/bluetooth_device_dialog.cpp +++ b/ui/qt/bluetooth_device_dialog.cpp @@ -23,12 +23,12 @@ #include "ui/simple_dialog.h" #include +#include "ui/qt/widgets/wireshark_file_dialog.h" #include #include #include #include -#include static const int column_number_value = 0; static const int column_number_changes = 1; @@ -647,7 +647,7 @@ void BluetoothDeviceDialog::on_actionSave_as_image_triggered() { QPixmap image; - QString fileName = QFileDialog::getSaveFileName(this, + QString fileName = WiresharkFileDialog::getSaveFileName(this, tr("Save Table Image"), "bluetooth_device_table.png", tr("PNG Image (*.png)")); diff --git a/ui/qt/bluetooth_devices_dialog.cpp b/ui/qt/bluetooth_devices_dialog.cpp index 3337229c8e..242edd424c 100644 --- a/ui/qt/bluetooth_devices_dialog.cpp +++ b/ui/qt/bluetooth_devices_dialog.cpp @@ -25,12 +25,12 @@ #include #include "ui/simple_dialog.h" +#include "ui/qt/widgets/wireshark_file_dialog.h" #include #include #include #include -#include static const int column_number_bd_addr = 0; static const int column_number_bd_addr_oui = 1; @@ -436,7 +436,7 @@ void BluetoothDevicesDialog::on_actionSave_as_image_triggered() { QPixmap image; - QString fileName = QFileDialog::getSaveFileName(this, + QString fileName = WiresharkFileDialog::getSaveFileName(this, tr("Save Table Image"), "bluetooth_devices_table.png", tr("PNG Image (*.png)")); diff --git a/ui/qt/bluetooth_hci_summary_dialog.cpp b/ui/qt/bluetooth_hci_summary_dialog.cpp index 493fe43cf4..1e594c07b8 100644 --- a/ui/qt/bluetooth_hci_summary_dialog.cpp +++ b/ui/qt/bluetooth_hci_summary_dialog.cpp @@ -26,12 +26,12 @@ #include #include "ui/simple_dialog.h" +#include "ui/qt/widgets/wireshark_file_dialog.h" #include #include #include #include -#include static const int column_number_name = 0; static const int column_number_ogf = 1; @@ -863,7 +863,7 @@ void BluetoothHciSummaryDialog::on_actionSave_as_image_triggered() { QPixmap image; - QString fileName = QFileDialog::getSaveFileName(this, + QString fileName = WiresharkFileDialog::getSaveFileName(this, tr("Save Table Image"), "bluetooth_hci_summary.png", tr("PNG Image (*.png)")); diff --git a/ui/qt/capture_interfaces_dialog.cpp b/ui/qt/capture_interfaces_dialog.cpp index 645f1d61e5..5f705465cc 100644 --- a/ui/qt/capture_interfaces_dialog.cpp +++ b/ui/qt/capture_interfaces_dialog.cpp @@ -22,7 +22,6 @@ #ifdef HAVE_LIBPCAP #include -#include #include #include @@ -47,6 +46,7 @@ #include #include +#include "ui/qt/widgets/wireshark_file_dialog.h" // To do: // - Set a size hint for item delegates. @@ -362,7 +362,7 @@ void CaptureInterfacesDialog::browseButtonClicked() open_dir = prefs.gui_fileopen_dir; break; } - QString file_name = QFileDialog::getSaveFileName(this, tr("Specify a Capture File"), open_dir); + QString file_name = WiresharkFileDialog::getSaveFileName(this, tr("Specify a Capture File"), open_dir); ui->filenameLineEdit->setText(file_name); } diff --git a/ui/qt/coloring_rules_dialog.cpp b/ui/qt/coloring_rules_dialog.cpp index 0c35aa8c80..616a8dbfc1 100644 --- a/ui/qt/coloring_rules_dialog.cpp +++ b/ui/qt/coloring_rules_dialog.cpp @@ -20,9 +20,9 @@ #include "wsutil/filesystem.h" #include "wireshark_application.h" +#include "ui/qt/widgets/wireshark_file_dialog.h" #include -#include #include #include @@ -279,7 +279,7 @@ void ColoringRulesDialog::on_buttonBox_clicked(QAbstractButton *button) QString err; if (button == import_button_) { - QString file_name = QFileDialog::getOpenFileName(this, wsApp->windowTitleString(tr("Import Coloring Rules")), + QString file_name = WiresharkFileDialog::getOpenFileName(this, wsApp->windowTitleString(tr("Import Coloring Rules")), wsApp->lastOpenDir().path()); if (!file_name.isEmpty()) { if (!colorRuleModel_.importColors(file_name, err)) { @@ -297,7 +297,7 @@ void ColoringRulesDialog::on_buttonBox_clicked(QAbstractButton *button) return; QString caption = wsApp->windowTitleString(tr("Export %1 Coloring Rules").arg(num_items)); - QString file_name = QFileDialog::getSaveFileName(this, caption, + QString file_name = WiresharkFileDialog::getSaveFileName(this, caption, wsApp->lastOpenDir().path()); if (!file_name.isEmpty()) { if (!colorRuleModel_.exportColors(file_name, err)) { diff --git a/ui/qt/export_object_dialog.cpp b/ui/qt/export_object_dialog.cpp index 872bd95535..e6a562c1aa 100644 --- a/ui/qt/export_object_dialog.cpp +++ b/ui/qt/export_object_dialog.cpp @@ -14,9 +14,9 @@ #include #include "wireshark_application.h" +#include "ui/qt/widgets/wireshark_file_dialog.h" #include -#include #include #include @@ -154,7 +154,7 @@ void ExportObjectDialog::saveCurrentEntry() return; GString *safe_filename = eo_massage_str(entry_filename.toUtf8().constData(), EXPORT_OBJECT_MAXFILELEN-path.canonicalPath().length(), 0); - QString file_name = QFileDialog::getSaveFileName(this, wsApp->windowTitleString(tr("Save Object As" UTF8_HORIZONTAL_ELLIPSIS)), + QString file_name = WiresharkFileDialog::getSaveFileName(this, wsApp->windowTitleString(tr("Save Object As" UTF8_HORIZONTAL_ELLIPSIS)), safe_filename->str); g_string_free(safe_filename, TRUE); @@ -176,7 +176,7 @@ void ExportObjectDialog::saveAllEntries() // as the native dialog is used, and it supports that; does // that also work on Windows and with Qt's own dialog? // - save_in_path = QFileDialog::getExistingDirectory(this, wsApp->windowTitleString(tr("Save All Objects In" UTF8_HORIZONTAL_ELLIPSIS)), + save_in_path = WiresharkFileDialog::getExistingDirectory(this, wsApp->windowTitleString(tr("Save All Objects In" UTF8_HORIZONTAL_ELLIPSIS)), save_in_dir.canonicalPath(), QFileDialog::ShowDirsOnly); diff --git a/ui/qt/extcap_argument_file.cpp b/ui/qt/extcap_argument_file.cpp index 02690e5abf..b0eb2d5b32 100644 --- a/ui/qt/extcap_argument_file.cpp +++ b/ui/qt/extcap_argument_file.cpp @@ -12,13 +12,14 @@ #include +#include "ui/qt/widgets/wireshark_file_dialog.h" + #include #include #include #include #include #include -#include #include #include #include @@ -106,7 +107,7 @@ void ExtcapArgumentFileSelection::openFileDialog() fileExt.prepend(";;").prepend(givenExt); } - filename = QFileDialog::getOpenFileName((QWidget *)(textBox->parent()), + filename = WiresharkFileDialog::getOpenFileName((QWidget *)(textBox->parent()), QString().fromUtf8(_argument->display) + " " + tr("Open File"), workingDir.absolutePath(), fileExt); diff --git a/ui/qt/firewall_rules_dialog.cpp b/ui/qt/firewall_rules_dialog.cpp index 49781df2b3..f7c6a9d35e 100644 --- a/ui/qt/firewall_rules_dialog.cpp +++ b/ui/qt/firewall_rules_dialog.cpp @@ -23,9 +23,9 @@ #include "wsutil/utf8_entities.h" #include "wireshark_application.h" +#include "ui/qt/widgets/wireshark_file_dialog.h" #include -#include #include #include #include @@ -170,7 +170,7 @@ void FirewallRulesDialog::on_buttonBox_clicked(QAbstractButton *button) if (button == ui->buttonBox->button(QDialogButtonBox::Save)) { QString save_title = QString("Save %1 rules as" UTF8_HORIZONTAL_ELLIPSIS) .arg(firewall_product_name(prod_)); - QByteArray file_name = QFileDialog::getSaveFileName(this, + QByteArray file_name = WiresharkFileDialog::getSaveFileName(this, save_title, wsApp->lastOpenDir().canonicalPath(), tr("Text file (*.txt);;All Files (" ALL_FILES_WILDCARD ")") diff --git a/ui/qt/follow_stream_dialog.cpp b/ui/qt/follow_stream_dialog.cpp index 9a988486fb..a43b382725 100644 --- a/ui/qt/follow_stream_dialog.cpp +++ b/ui/qt/follow_stream_dialog.cpp @@ -33,9 +33,11 @@ #include "ws_symbol_export.h" #include +#include #include "progress_frame.h" -#include + +#include "ui/qt/widgets/wireshark_file_dialog.h" #include #include @@ -264,7 +266,7 @@ void FollowStreamDialog::findText(bool go_back) void FollowStreamDialog::saveAs() { - QString file_name = QFileDialog::getSaveFileName(this, wsApp->windowTitleString(tr("Save Stream Content As" UTF8_HORIZONTAL_ELLIPSIS))); + QString file_name = WiresharkFileDialog::getSaveFileName(this, wsApp->windowTitleString(tr("Save Stream Content As" UTF8_HORIZONTAL_ELLIPSIS))); if (!file_name.isEmpty()) { QTextStream out(&file_); diff --git a/ui/qt/iax2_analysis_dialog.cpp b/ui/qt/iax2_analysis_dialog.cpp index 1603fb2c43..e7acdcab32 100644 --- a/ui/qt/iax2_analysis_dialog.cpp +++ b/ui/qt/iax2_analysis_dialog.cpp @@ -29,7 +29,6 @@ #include #include -#include #include #include #include @@ -38,6 +37,7 @@ #include #include #include "wireshark_application.h" +#include "ui/qt/widgets/wireshark_file_dialog.h" /* * @file RTP stream analysis dialog @@ -584,7 +584,7 @@ void Iax2AnalysisDialog::on_actionSaveGraph_triggered() if (!file_closed_) { save_file += QString("/%1").arg(cap_file_.fileTitle()); } - file_name = QFileDialog::getSaveFileName(this, wsApp->windowTitleString(tr("Save Graph As" UTF8_HORIZONTAL_ELLIPSIS)), + file_name = WiresharkFileDialog::getSaveFileName(this, wsApp->windowTitleString(tr("Save Graph As" UTF8_HORIZONTAL_ELLIPSIS)), save_file, filter, &extension); if (!file_name.isEmpty()) { @@ -894,7 +894,7 @@ void Iax2AnalysisDialog::saveAudio(Iax2AnalysisDialog::StreamDirection direction ext_filter.append(tr(";;Raw (*.raw)")); } QString sel_filter; - QString file_path = QFileDialog::getSaveFileName( + QString file_path = WiresharkFileDialog::getSaveFileName( this, caption, wsApp->lastOpenDir().absoluteFilePath("Saved RTP Audio.au"), ext_filter, &sel_filter); @@ -1160,7 +1160,7 @@ void Iax2AnalysisDialog::saveCsv(Iax2AnalysisDialog::StreamDirection direction) break; } - QString file_path = QFileDialog::getSaveFileName( + QString file_path = WiresharkFileDialog::getSaveFileName( this, caption, wsApp->lastOpenDir().absoluteFilePath("RTP Packet Data.csv"), tr("Comma-separated values (*.csv)")); diff --git a/ui/qt/import_text_dialog.cpp b/ui/qt/import_text_dialog.cpp index 72011abdfd..b48dc7f50c 100644 --- a/ui/qt/import_text_dialog.cpp +++ b/ui/qt/import_text_dialog.cpp @@ -30,8 +30,8 @@ #include #include "wireshark_application.h" #include +#include "ui/qt/widgets/wireshark_file_dialog.h" -#include #include #include @@ -276,7 +276,7 @@ void ImportTextDialog::on_textFileBrowseButton_clicked() break; } - QString file_name = QFileDialog::getOpenFileName(this, wsApp->windowTitleString(tr("Import Text File")), open_dir); + QString file_name = WiresharkFileDialog::getOpenFileName(this, wsApp->windowTitleString(tr("Import Text File")), open_dir); ti_ui_->textFileLineEdit->setText(file_name); } diff --git a/ui/qt/io_graph_dialog.cpp b/ui/qt/io_graph_dialog.cpp index 16ee07a107..b0e3380ea4 100644 --- a/ui/qt/io_graph_dialog.cpp +++ b/ui/qt/io_graph_dialog.cpp @@ -29,9 +29,9 @@ #include #include //provides some default colors +#include "ui/qt/widgets/wireshark_file_dialog.h" #include -#include #include #include #include @@ -1404,7 +1404,7 @@ void IOGraphDialog::on_buttonBox_accepted() if (!file_closed_) { save_file += QString("/%1").arg(cap_file_.fileTitle()); } - file_name = QFileDialog::getSaveFileName(this, wsApp->windowTitleString(tr("Save Graph As" UTF8_HORIZONTAL_ELLIPSIS)), + file_name = WiresharkFileDialog::getSaveFileName(this, wsApp->windowTitleString(tr("Save Graph As" UTF8_HORIZONTAL_ELLIPSIS)), save_file, filter, &extension); if (file_name.length() > 0) { diff --git a/ui/qt/lte_rlc_graph_dialog.cpp b/ui/qt/lte_rlc_graph_dialog.cpp index 1313f866ed..4188dbe3c2 100644 --- a/ui/qt/lte_rlc_graph_dialog.cpp +++ b/ui/qt/lte_rlc_graph_dialog.cpp @@ -21,7 +21,6 @@ #include -#include #include #include @@ -29,6 +28,7 @@ #include #include "wireshark_application.h" #include "simple_dialog.h" +#include "ui/qt/widgets/wireshark_file_dialog.h" #include @@ -856,7 +856,7 @@ void LteRlcGraphDialog::on_buttonBox_accepted() .arg(bmp_filter) .arg(jpeg_filter); - file_name = QFileDialog::getSaveFileName(this, wsApp->windowTitleString(tr("Save Graph As" UTF8_HORIZONTAL_ELLIPSIS)), + file_name = WiresharkFileDialog::getSaveFileName(this, wsApp->windowTitleString(tr("Save Graph As" UTF8_HORIZONTAL_ELLIPSIS)), path.canonicalPath(), filter, &extension); if (file_name.length() > 0) { diff --git a/ui/qt/main_window_preferences_frame.cpp b/ui/qt/main_window_preferences_frame.cpp index 5b99023a44..bb1c8e3a4b 100644 --- a/ui/qt/main_window_preferences_frame.cpp +++ b/ui/qt/main_window_preferences_frame.cpp @@ -17,8 +17,8 @@ #include #include #include +#include "ui/qt/widgets/wireshark_file_dialog.h" -#include #include MainWindowPreferencesFrame::MainWindowPreferencesFrame(QWidget *parent) : @@ -164,7 +164,7 @@ void MainWindowPreferencesFrame::on_foStyleSpecifiedLineEdit_textEdited(const QS void MainWindowPreferencesFrame::on_foStyleSpecifiedPushButton_clicked() { - QString specified_dir = QFileDialog::getExistingDirectory(this, tr("Open Files In")); + QString specified_dir = WiresharkFileDialog::getExistingDirectory(this, tr("Open Files In")); if (specified_dir.isEmpty()) return; diff --git a/ui/qt/main_window_slots.cpp b/ui/qt/main_window_slots.cpp index 95bf8707f3..6d6ec5ae13 100644 --- a/ui/qt/main_window_slots.cpp +++ b/ui/qt/main_window_slots.cpp @@ -77,6 +77,7 @@ DIAG_ON(frame-larger-than=) #include #include +#include "ui/qt/widgets/wireshark_file_dialog.h" #ifdef HAVE_SOFTWARE_UPDATE #include "ui/software_update.h" @@ -1987,7 +1988,7 @@ void MainWindow::on_actionFileExportPacketBytes_triggered() if (!capture_file_.capFile() || !capture_file_.capFile()->finfo_selected) return; - file_name = QFileDialog::getSaveFileName(this, + file_name = WiresharkFileDialog::getSaveFileName(this, wsApp->windowTitleString(tr("Export Selected Packet Bytes")), wsApp->lastOpenDir().canonicalPath(), tr("Raw data (*.bin *.dat *.raw);;All Files (" ALL_FILES_WILDCARD ")") @@ -2062,7 +2063,7 @@ void MainWindow::on_actionFileExportSSLSessionKeys_triggered() } save_title.append(wsApp->windowTitleString(tr("Export SSL Session Keys (%Ln key(s))", "", keylist_len))); - file_name = QFileDialog::getSaveFileName(this, + file_name = WiresharkFileDialog::getSaveFileName(this, save_title, wsApp->lastOpenDir().canonicalPath(), tr("SSL Session Keys (*.keys *.txt);;All Files (" ALL_FILES_WILDCARD ")") diff --git a/ui/qt/manage_interfaces_dialog.cpp b/ui/qt/manage_interfaces_dialog.cpp index 4db4bbafdb..514444d311 100644 --- a/ui/qt/manage_interfaces_dialog.cpp +++ b/ui/qt/manage_interfaces_dialog.cpp @@ -40,7 +40,6 @@ #include #include -#include #include #include #include diff --git a/ui/qt/manager/wireshark_preference.cpp b/ui/qt/manager/wireshark_preference.cpp index 9774d7d0ed..451c9685ed 100644 --- a/ui/qt/manager/wireshark_preference.cpp +++ b/ui/qt/manager/wireshark_preference.cpp @@ -15,11 +15,11 @@ #include #include #include +#include "ui/qt/widgets/wireshark_file_dialog.h" #include #include #include -#include #include #include #include @@ -169,7 +169,7 @@ public: SaveFilePreference(QObject * parent = Q_NULLPTR) : WiresharkPreference(parent) {} virtual QWidget * editor(QWidget * parent, const QStyleOptionViewItem &option, const QModelIndex &index) { - QString filename = QFileDialog::getSaveFileName(parent, wsApp->windowTitleString(prefs_get_title(prefsItem()->getPref())), + QString filename = WiresharkFileDialog::getSaveFileName(parent, wsApp->windowTitleString(prefs_get_title(prefsItem()->getPref())), index.model()->data(index, Qt::DisplayRole).toString()); if (!filename.isEmpty()) { ((QAbstractItemModel*)index.model())->setData(index, QDir::toNativeSeparators(filename), Qt::EditRole); @@ -185,7 +185,7 @@ public: OpenFilePreference(QObject * parent = Q_NULLPTR) : WiresharkPreference(parent) {} virtual QWidget * editor(QWidget * parent, const QStyleOptionViewItem &option, const QModelIndex &index) { - QString filename = QFileDialog::getOpenFileName(parent, wsApp->windowTitleString(prefs_get_title(prefsItem()->getPref())), + QString filename = WiresharkFileDialog::getOpenFileName(parent, wsApp->windowTitleString(prefs_get_title(prefsItem()->getPref())), index.model()->data(index, Qt::DisplayRole).toString()); if (!filename.isEmpty()) { ((QAbstractItemModel*)index.model())->setData(index, QDir::toNativeSeparators(filename), Qt::EditRole); @@ -201,7 +201,7 @@ public: DirNamePreference(QObject * parent = Q_NULLPTR) : WiresharkPreference(parent) {} virtual QWidget * editor(QWidget * parent, const QStyleOptionViewItem &option, const QModelIndex &index) { - QString filename = QFileDialog::getExistingDirectory(parent, wsApp->windowTitleString(prefs_get_title(prefsItem()->getPref())), + QString filename = WiresharkFileDialog::getExistingDirectory(parent, wsApp->windowTitleString(prefs_get_title(prefsItem()->getPref())), index.model()->data(index, Qt::DisplayRole).toString()); if (!filename.isEmpty()) { ((QAbstractItemModel*)index.model())->setData(index, QDir::toNativeSeparators(filename), Qt::EditRole); diff --git a/ui/qt/models/path_chooser_delegate.cpp b/ui/qt/models/path_chooser_delegate.cpp index 9312b493e6..6e159a9905 100644 --- a/ui/qt/models/path_chooser_delegate.cpp +++ b/ui/qt/models/path_chooser_delegate.cpp @@ -14,10 +14,10 @@ #include "ui/last_open_dir.h" #include +#include "ui/qt/widgets/wireshark_file_dialog.h" #include #include -#include #include #include @@ -82,7 +82,7 @@ void PathChooserDelegate::browse_button_clicked() } QWidget * qw = new QWidget(); - QString file_name = QFileDialog::getOpenFileName(qw, tr("Open Pipe"), open_dir); + QString file_name = WiresharkFileDialog::getOpenFileName(qw, tr("Open Pipe"), open_dir); if ( !file_name.isEmpty() ) { QWidget * parent = ((QPushButton *)sender())->parentWidget(); diff --git a/ui/qt/module_preferences_scroll_area.cpp b/ui/qt/module_preferences_scroll_area.cpp index 6f900ac707..5de7f1f678 100644 --- a/ui/qt/module_preferences_scroll_area.cpp +++ b/ui/qt/module_preferences_scroll_area.cpp @@ -10,6 +10,7 @@ #include "module_preferences_scroll_area.h" #include #include +#include "ui/qt/widgets/wireshark_file_dialog.h" #include #include "uat_dialog.h" #include "wireshark_application.h" @@ -24,7 +25,6 @@ #include #include #include -#include #include #include #include @@ -487,7 +487,7 @@ void ModulePreferencesScrollArea::saveFilenamePushButtonPressed() pref_t *pref = VariantPointer::asPtr(filename_pb->property(pref_prop_)); if (!pref) return; - QString filename = QFileDialog::getSaveFileName(this, wsApp->windowTitleString(prefs_get_title(pref)), + QString filename = WiresharkFileDialog::getSaveFileName(this, wsApp->windowTitleString(prefs_get_title(pref)), prefs_get_string_value(pref, pref_stashed)); if (!filename.isEmpty()) { @@ -504,7 +504,7 @@ void ModulePreferencesScrollArea::openFilenamePushButtonPressed() pref_t *pref = VariantPointer::asPtr(filename_pb->property(pref_prop_)); if (!pref) return; - QString filename = QFileDialog::getOpenFileName(this, wsApp->windowTitleString(prefs_get_title(pref)), + QString filename = WiresharkFileDialog::getOpenFileName(this, wsApp->windowTitleString(prefs_get_title(pref)), prefs_get_string_value(pref, pref_stashed)); if (!filename.isEmpty()) { prefs_set_string_value(pref, QDir::toNativeSeparators(filename).toStdString().c_str(), pref_stashed); @@ -520,7 +520,7 @@ void ModulePreferencesScrollArea::dirnamePushButtonPressed() pref_t *pref = VariantPointer::asPtr(dirname_pb->property(pref_prop_)); if (!pref) return; - QString dirname = QFileDialog::getExistingDirectory(this, wsApp->windowTitleString(prefs_get_title(pref)), + QString dirname = WiresharkFileDialog::getExistingDirectory(this, wsApp->windowTitleString(prefs_get_title(pref)), prefs_get_string_value(pref, pref_stashed)); if (!dirname.isEmpty()) { diff --git a/ui/qt/rtp_analysis_dialog.cpp b/ui/qt/rtp_analysis_dialog.cpp index ace5d00303..e911169c33 100644 --- a/ui/qt/rtp_analysis_dialog.cpp +++ b/ui/qt/rtp_analysis_dialog.cpp @@ -26,7 +26,6 @@ #include #include -#include #include #include #include @@ -36,6 +35,7 @@ #include "rtp_player_dialog.h" #include #include "wireshark_application.h" +#include "ui/qt/widgets/wireshark_file_dialog.h" /* * @file RTP stream analysis dialog @@ -637,7 +637,7 @@ void RtpAnalysisDialog::on_actionSaveGraph_triggered() if (!file_closed_) { save_file += QString("/%1").arg(cap_file_.fileTitle()); } - file_name = QFileDialog::getSaveFileName(this, wsApp->windowTitleString(tr("Save Graph As" UTF8_HORIZONTAL_ELLIPSIS)), + file_name = WiresharkFileDialog::getSaveFileName(this, wsApp->windowTitleString(tr("Save Graph As" UTF8_HORIZONTAL_ELLIPSIS)), save_file, filter, &extension); if (!file_name.isEmpty()) { @@ -1411,7 +1411,7 @@ void RtpAnalysisDialog::saveAudio(RtpAnalysisDialog::StreamDirection direction, ext_filter.append(ext_filter_raw); } QString sel_filter; - QString file_path = QFileDialog::getSaveFileName( + QString file_path = WiresharkFileDialog::getSaveFileName( this, caption, wsApp->lastOpenDir().absoluteFilePath("Saved RTP Audio.au"), ext_filter, &sel_filter); @@ -1484,7 +1484,7 @@ void RtpAnalysisDialog::saveCsv(RtpAnalysisDialog::StreamDirection direction) break; } - QString file_path = QFileDialog::getSaveFileName( + QString file_path = WiresharkFileDialog::getSaveFileName( this, caption, wsApp->lastOpenDir().absoluteFilePath("RTP Packet Data.csv"), tr("Comma-separated values (*.csv)")); diff --git a/ui/qt/rtp_stream_dialog.cpp b/ui/qt/rtp_stream_dialog.cpp index 3a20fbfa69..0cc50ec168 100644 --- a/ui/qt/rtp_stream_dialog.cpp +++ b/ui/qt/rtp_stream_dialog.cpp @@ -20,10 +20,10 @@ #include #include "rtp_analysis_dialog.h" #include "wireshark_application.h" +#include "ui/qt/widgets/wireshark_file_dialog.h" #include #include -#include #include #include #include @@ -508,7 +508,7 @@ void RtpStreamDialog::on_actionExportAsRtpDump_triggered() QDir path(wsApp->lastOpenDir()); QString save_file = path.canonicalPath() + "/" + cap_file_.fileTitle(); QString extension; - file_name = QFileDialog::getSaveFileName(this, wsApp->windowTitleString(tr("Save RTPDump As" UTF8_HORIZONTAL_ELLIPSIS)), + file_name = WiresharkFileDialog::getSaveFileName(this, wsApp->windowTitleString(tr("Save RTPDump As" UTF8_HORIZONTAL_ELLIPSIS)), save_file, "RTPDump Format (*.rtpdump)", &extension); if (file_name.length() > 0) { diff --git a/ui/qt/sctp_all_assocs_dialog.cpp b/ui/qt/sctp_all_assocs_dialog.cpp index 9d224ac777..39d6d7dfd8 100644 --- a/ui/qt/sctp_all_assocs_dialog.cpp +++ b/ui/qt/sctp_all_assocs_dialog.cpp @@ -18,7 +18,6 @@ #include #include -#include #include //#include diff --git a/ui/qt/sctp_graph_dialog.cpp b/ui/qt/sctp_graph_dialog.cpp index dff5fac56d..f3546e5330 100644 --- a/ui/qt/sctp_graph_dialog.cpp +++ b/ui/qt/sctp_graph_dialog.cpp @@ -20,10 +20,10 @@ #include "ui/tap-sctp-analysis.h" -#include #include #include +#include "ui/qt/widgets/wireshark_file_dialog.h" #include "wireshark_application.h" SCTPGraphDialog::SCTPGraphDialog(QWidget *parent, sctp_assoc_info_t *assoc, capture_file *cf, int dir) : @@ -436,7 +436,7 @@ void SCTPGraphDialog::save_graph(QDialog *dlg, QCustomPlot *plot) .arg(bmp_filter) .arg(jpeg_filter); - file_name = QFileDialog::getSaveFileName(dlg, wsApp->windowTitleString(tr("Save Graph As" UTF8_HORIZONTAL_ELLIPSIS)), + file_name = WiresharkFileDialog::getSaveFileName(dlg, wsApp->windowTitleString(tr("Save Graph As" UTF8_HORIZONTAL_ELLIPSIS)), path.canonicalPath(), filter, &extension); if (file_name.length() > 0) { diff --git a/ui/qt/sequence_dialog.cpp b/ui/qt/sequence_dialog.cpp index 8c4f0cb4c3..73991608c7 100644 --- a/ui/qt/sequence_dialog.cpp +++ b/ui/qt/sequence_dialog.cpp @@ -26,9 +26,9 @@ #include "wireshark_application.h" #include #include +#include "ui/qt/widgets/wireshark_file_dialog.h" #include -#include #include #include @@ -375,7 +375,7 @@ void SequenceDialog::on_buttonBox_accepted() filter.append(QString(";;%5").arg(ascii_filter)); } - file_name = QFileDialog::getSaveFileName(this, wsApp->windowTitleString(tr("Save Graph As" UTF8_HORIZONTAL_ELLIPSIS)), + file_name = WiresharkFileDialog::getSaveFileName(this, wsApp->windowTitleString(tr("Save Graph As" UTF8_HORIZONTAL_ELLIPSIS)), path.canonicalPath(), filter, &extension); if (file_name.length() > 0) { diff --git a/ui/qt/show_packet_bytes_dialog.cpp b/ui/qt/show_packet_bytes_dialog.cpp index ef9aea5f25..5b94528f7a 100644 --- a/ui/qt/show_packet_bytes_dialog.cpp +++ b/ui/qt/show_packet_bytes_dialog.cpp @@ -12,6 +12,7 @@ #include "main_window.h" #include "wireshark_application.h" +#include "ui/qt/widgets/wireshark_file_dialog.h" #include "epan/charsets.h" @@ -292,7 +293,7 @@ void ShowPacketBytesDialog::copyBytes() void ShowPacketBytesDialog::saveAs() { - QString file_name = QFileDialog::getSaveFileName(this, wsApp->windowTitleString(tr("Save Selected Packet Bytes As" UTF8_HORIZONTAL_ELLIPSIS))); + QString file_name = WiresharkFileDialog::getSaveFileName(this, wsApp->windowTitleString(tr("Save Selected Packet Bytes As" UTF8_HORIZONTAL_ELLIPSIS))); if (file_name.isEmpty()) return; diff --git a/ui/qt/tap_parameter_dialog.cpp b/ui/qt/tap_parameter_dialog.cpp index 104baf573a..ddfae13445 100644 --- a/ui/qt/tap_parameter_dialog.cpp +++ b/ui/qt/tap_parameter_dialog.cpp @@ -28,6 +28,12 @@ #include "epan/stat_tap_ui.h" +#ifdef Q_OS_WIN +#include +#include "ui/packet_range.h" +#include "ui/win32/file_dlg_win32.h" +#endif // Q_OS_WIN + #include "ui/last_open_dir.h" #include @@ -519,6 +525,9 @@ void TapParameterDialog::on_actionSaveAs_triggered() bool success = false; int last_errno; +#ifdef Q_OS_WIN + HANDLE da_ctx = set_thread_per_monitor_v2_awareness(); +#endif QFileDialog SaveAsDialog(this, wsApp->windowTitleString(tr("Save Statistics As" UTF8_HORIZONTAL_ELLIPSIS)), get_last_open_dir()); SaveAsDialog.setNameFilter(tr("Plain text file (*.txt);;" @@ -527,7 +536,11 @@ void TapParameterDialog::on_actionSaveAs_triggered() "YAML document (*.yaml)")); SaveAsDialog.selectNameFilter(tr("Plain text file (*.txt)")); SaveAsDialog.setAcceptMode(QFileDialog::AcceptSave); - if (!SaveAsDialog.exec()) { + int result = SaveAsDialog.exec(); +#ifdef Q_OS_WIN + revert_thread_per_monitor_v2_awareness(da_ctx); +#endif + if (!result) { return; } selectedFilter= SaveAsDialog.selectedNameFilter(); diff --git a/ui/qt/tcp_stream_dialog.cpp b/ui/qt/tcp_stream_dialog.cpp index 6c63cec191..2350fd124c 100644 --- a/ui/qt/tcp_stream_dialog.cpp +++ b/ui/qt/tcp_stream_dialog.cpp @@ -24,10 +24,10 @@ #include #include "progress_frame.h" #include "wireshark_application.h" +#include "ui/qt/widgets/wireshark_file_dialog.h" #include #include -#include #include #include @@ -1807,7 +1807,7 @@ void TCPStreamDialog::on_buttonBox_accepted() .arg(bmp_filter) .arg(jpeg_filter); - file_name = QFileDialog::getSaveFileName(this, wsApp->windowTitleString(tr("Save Graph As" UTF8_HORIZONTAL_ELLIPSIS)), + file_name = WiresharkFileDialog::getSaveFileName(this, wsApp->windowTitleString(tr("Save Graph As" UTF8_HORIZONTAL_ELLIPSIS)), path.canonicalPath(), filter, &extension); if (file_name.length() > 0) { diff --git a/ui/qt/widgets/editor_file_dialog.cpp b/ui/qt/widgets/editor_file_dialog.cpp index dc99117477..73802a2c6c 100644 --- a/ui/qt/widgets/editor_file_dialog.cpp +++ b/ui/qt/widgets/editor_file_dialog.cpp @@ -10,6 +10,7 @@ */ #include +#include #include #include @@ -93,11 +94,11 @@ void EditorFileDialog::applyFilename() if (mode_ == Directory) { - file = QFileDialog::getExistingDirectory(this, caption_, directory_, options_); + file = WiresharkFileDialog::getExistingDirectory(this, caption_, directory_, options_); } else { - file = QFileDialog::getOpenFileName(this, caption_, directory_, filter_, NULL, options_); + file = WiresharkFileDialog::getOpenFileName(this, caption_, directory_, filter_, NULL, options_); } if (!file.isEmpty()) diff --git a/ui/qt/widgets/wireshark_file_dialog.cpp b/ui/qt/widgets/wireshark_file_dialog.cpp new file mode 100644 index 0000000000..41defb905e --- /dev/null +++ b/ui/qt/widgets/wireshark_file_dialog.cpp @@ -0,0 +1,65 @@ +/* wireshark_file_dialog.cpp + * + * Wireshark - Network traffic analyzer + * By Gerald Combs + * Copyright 1998 Gerald Combs + * + * SPDX-License-Identifier: GPL-2.0-or-later + */ + +#include "wireshark_file_dialog.h" + +#ifdef Q_OS_WIN +#include +#include "ui/packet_range.h" +#include "ui/win32/file_dlg_win32.h" +#endif // Q_OS_WIN + +QString WiresharkFileDialog::getExistingDirectory(QWidget *parent, const QString &caption, const QString &dir, Options options) +{ +#ifdef Q_OS_WIN + HANDLE da_ctx = set_thread_per_monitor_v2_awareness(); +#endif + QString ed = QFileDialog::getExistingDirectory(parent, caption, dir, options); +#ifdef Q_OS_WIN + revert_thread_per_monitor_v2_awareness(da_ctx); +#endif + return ed; +} + +QString WiresharkFileDialog::getOpenFileName(QWidget *parent, const QString &caption, const QString &dir, const QString &filter, QString *selectedFilter, Options options) +{ +#ifdef Q_OS_WIN + HANDLE da_ctx = set_thread_per_monitor_v2_awareness(); +#endif + QString ofn = QFileDialog::getOpenFileName(parent, caption, dir, filter, selectedFilter, options); +#ifdef Q_OS_WIN + revert_thread_per_monitor_v2_awareness(da_ctx); +#endif + return ofn; +} + +QString WiresharkFileDialog::getSaveFileName(QWidget *parent, const QString &caption, const QString &dir, const QString &filter, QString *selectedFilter, Options options) +{ +#ifdef Q_OS_WIN + HANDLE da_ctx = set_thread_per_monitor_v2_awareness(); +#endif + QString sfn = QFileDialog::getSaveFileName(parent, caption, dir, filter, selectedFilter, options); +#ifdef Q_OS_WIN + revert_thread_per_monitor_v2_awareness(da_ctx); +#endif + return sfn; +} + +/* + * Editor modelines + * + * Local Variables: + * c-basic-offset: 4 + * tab-width: 8 + * indent-tabs-mode: nil + * End: + * + * ex: set shiftwidth=4 tabstop=8 expandtab: + * :indentSize=4:tabSize=8:noTabs=true: + */ diff --git a/ui/qt/widgets/wireshark_file_dialog.h b/ui/qt/widgets/wireshark_file_dialog.h new file mode 100644 index 0000000000..de7797080e --- /dev/null +++ b/ui/qt/widgets/wireshark_file_dialog.h @@ -0,0 +1,50 @@ +/* wireshark_file_dialog.h + * + * Wireshark - Network traffic analyzer + * By Gerald Combs + * Copyright 1998 Gerald Combs + * + * SPDX-License-Identifier: GPL-2.0-or-later + */ + +#ifndef WIRESHARK_FILE_DIALOG_H +#define WIRESHARK_FILE_DIALOG_H + +#include + +/** + * @brief The WiresharkFileDialog class + * + * Qt <= 5.9 supports setting old (Windows 8.1) per-monitor DPI awareness + * via Qt:AA_EnableHighDpiScaling. We do this in wireshark-qt.cpp. In order + * for native dialogs to be rendered correctly we need to to set per-monitor + * *v2* awareness prior to creating the dialog. + * Qt doesn't render correctly when per-monitor v2 awareness is enabled, so + * we need to revert our thread context when we're done. + * The class functions below are simple wrappers around their QFileDialog + * equivalents that set PMv2 awareness before showing native dialogs on + * Windows and resets it afterward. + */ + +class WiresharkFileDialog : public QFileDialog +{ +public: + static QString getExistingDirectory(QWidget *parent = Q_NULLPTR, const QString &caption = QString(), const QString &dir = QString(), Options options = ShowDirsOnly); + static QString getOpenFileName(QWidget *parent = Q_NULLPTR, const QString &caption = QString(), const QString &dir = QString(), const QString &filter = QString(), QString *selectedFilter = Q_NULLPTR, Options options = Options()); + static QString getSaveFileName(QWidget *parent = Q_NULLPTR, const QString &caption = QString(), const QString &dir = QString(), const QString &filter = QString(), QString *selectedFilter = Q_NULLPTR, Options options = Options()); +}; + +#endif // WIRESHARK_FILE_DIALOG_H + +/* + * Editor modelines + * + * Local Variables: + * c-basic-offset: 4 + * tab-width: 8 + * indent-tabs-mode: nil + * End: + * + * ex: set shiftwidth=4 tabstop=8 expandtab: + * :indentSize=4:tabSize=8:noTabs=true: + */