Windows: Make sure more native dialogs handle HiDPI.

Add a WiresharkFileDialog class, which is a thin wrapper around a few
QFileDialog functions that sets per-monitor v2 DPI awareness before
showing native dialogs and resets the awareness context afterward.
Use it where we call QFileDialog::getXXX.

Change-Id: Ib711a70aa94b693a2515804a729f666ea7fbd673
Reviewed-on: https://code.wireshark.org/review/27568
Reviewed-by: Gerald Combs <gerald@wireshark.org>
Petri-Dish: Gerald Combs <gerald@wireshark.org>
Tested-by: Petri Dish Buildbot
Reviewed-by: Anders Broman <a.broman58@gmail.com>
This commit is contained in:
Gerald Combs 2018-05-15 17:02:26 -07:00 committed by Anders Broman
parent d3427b8a65
commit 62999cc677
32 changed files with 199 additions and 64 deletions

View File

@ -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

View File

@ -21,11 +21,12 @@
#include "ui/simple_dialog.h"
#include "ui/qt/widgets/wireshark_file_dialog.h"
#include <QClipboard>
#include <QContextMenuEvent>
#include <QPushButton>
#include <QTreeWidget>
#include <QFileDialog>
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)"));

View File

@ -23,12 +23,12 @@
#include "ui/simple_dialog.h"
#include <ui/qt/utils/variant_pointer.h>
#include "ui/qt/widgets/wireshark_file_dialog.h"
#include <QClipboard>
#include <QContextMenuEvent>
#include <QPushButton>
#include <QTreeWidget>
#include <QFileDialog>
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)"));

View File

@ -25,12 +25,12 @@
#include <ui/qt/utils/variant_pointer.h>
#include "ui/simple_dialog.h"
#include "ui/qt/widgets/wireshark_file_dialog.h"
#include <QClipboard>
#include <QContextMenuEvent>
#include <QPushButton>
#include <QTreeWidget>
#include <QFileDialog>
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)"));

View File

@ -26,12 +26,12 @@
#include <ui/qt/utils/variant_pointer.h>
#include "ui/simple_dialog.h"
#include "ui/qt/widgets/wireshark_file_dialog.h"
#include <QClipboard>
#include <QContextMenuEvent>
#include <QPushButton>
#include <QTreeWidget>
#include <QFileDialog>
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)"));

View File

@ -22,7 +22,6 @@
#ifdef HAVE_LIBPCAP
#include <QAbstractItemModel>
#include <QFileDialog>
#include <QMessageBox>
#include <QTimer>
@ -47,6 +46,7 @@
#include <ui/qt/utils/qt_ui_utils.h>
#include <ui/qt/models/sparkline_delegate.h>
#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);
}

View File

@ -20,9 +20,9 @@
#include "wsutil/filesystem.h"
#include "wireshark_application.h"
#include "ui/qt/widgets/wireshark_file_dialog.h"
#include <QColorDialog>
#include <QFileDialog>
#include <QMessageBox>
#include <QPushButton>
@ -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)) {

View File

@ -14,9 +14,9 @@
#include <wsutil/utf8_entities.h>
#include "wireshark_application.h"
#include "ui/qt/widgets/wireshark_file_dialog.h"
#include <QDialogButtonBox>
#include <QFileDialog>
#include <QMessageBox>
#include <QPushButton>
@ -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);

View File

@ -12,13 +12,14 @@
#include <wsutil/utf8_entities.h>
#include "ui/qt/widgets/wireshark_file_dialog.h"
#include <QObject>
#include <QWidget>
#include <QLabel>
#include <QLineEdit>
#include <QBoxLayout>
#include <QPushButton>
#include <QFileDialog>
#include <QDir>
#include <QFileInfo>
#include <QVariant>
@ -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);

View File

@ -23,9 +23,9 @@
#include "wsutil/utf8_entities.h"
#include "wireshark_application.h"
#include "ui/qt/widgets/wireshark_file_dialog.h"
#include <QClipboard>
#include <QFileDialog>
#include <QMessageBox>
#include <QPushButton>
#include <QTextCursor>
@ -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 ")")

View File

@ -33,9 +33,11 @@
#include "ws_symbol_export.h"
#include <ui/qt/utils/color_utils.h>
#include <ui/qt/utils/qt_ui_utils.h>
#include "progress_frame.h"
#include <ui/qt/utils/qt_ui_utils.h>
#include "ui/qt/widgets/wireshark_file_dialog.h"
#include <QElapsedTimer>
#include <QKeyEvent>
@ -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_);

View File

@ -29,7 +29,6 @@
#include <wsutil/g711.h>
#include <wsutil/pint.h>
#include <QFileDialog>
#include <QMessageBox>
#include <QPushButton>
#include <QTemporaryFile>
@ -38,6 +37,7 @@
#include <ui/qt/utils/qt_ui_utils.h>
#include <ui/qt/utils/stock_icon.h>
#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)"));

View File

@ -30,8 +30,8 @@
#include <ui_import_text_dialog.h>
#include "wireshark_application.h"
#include <ui/qt/utils/qt_ui_utils.h>
#include "ui/qt/widgets/wireshark_file_dialog.h"
#include <QFileDialog>
#include <QDebug>
#include <QFile>
@ -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);
}

View File

@ -29,9 +29,9 @@
#include <wsutil/report_message.h>
#include <ui/qt/utils/tango_colors.h> //provides some default colors
#include "ui/qt/widgets/wireshark_file_dialog.h"
#include <QClipboard>
#include <QFileDialog>
#include <QFontMetrics>
#include <QFrame>
#include <QHBoxLayout>
@ -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) {

View File

@ -21,7 +21,6 @@
#include <ui/qt/utils/tango_colors.h>
#include <QFileDialog>
#include <QMenu>
#include <QRubberBand>
@ -29,6 +28,7 @@
#include <ui/qt/utils/qt_ui_utils.h>
#include "wireshark_application.h"
#include "simple_dialog.h"
#include "ui/qt/widgets/wireshark_file_dialog.h"
#include <epan/dissectors/packet-rlc-lte.h>
@ -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) {

View File

@ -17,8 +17,8 @@
#include <epan/prefs-int.h>
#include <ui/qt/models/pref_models.h>
#include <wsutil/filesystem.h>
#include "ui/qt/widgets/wireshark_file_dialog.h"
#include <QFileDialog>
#include <QDebug>
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;

View File

@ -77,6 +77,7 @@ DIAG_ON(frame-larger-than=)
#include <ui/qt/utils/variant_pointer.h>
#include <ui/qt/widgets/drag_drop_toolbar.h>
#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 ")")

View File

@ -40,7 +40,6 @@
#include <ui/qt/models/path_chooser_delegate.h>
#include <QCheckBox>
#include <QFileDialog>
#include <QHBoxLayout>
#include <QLineEdit>
#include <QStandardItemModel>

View File

@ -15,11 +15,11 @@
#include <ui/qt/manager/wireshark_preference.h>
#include <ui/qt/manager/preference_manager.h>
#include <ui/qt/widgets/range_syntax_lineedit.h>
#include "ui/qt/widgets/wireshark_file_dialog.h"
#include <ui/qt/wireshark_application.h>
#include <ui/qt/uat_dialog.h>
#include <QDir>
#include <QFileDialog>
#include <QLineEdit>
#include <QComboBox>
#include <QColorDialog>
@ -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);

View File

@ -14,10 +14,10 @@
#include "ui/last_open_dir.h"
#include <ui/qt/models/path_chooser_delegate.h>
#include "ui/qt/widgets/wireshark_file_dialog.h"
#include <QHBoxLayout>
#include <QPushButton>
#include <QFileDialog>
#include <QWidget>
#include <QLineEdit>
@ -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();

View File

@ -10,6 +10,7 @@
#include "module_preferences_scroll_area.h"
#include <ui_module_preferences_scroll_area.h>
#include <ui/qt/widgets/syntax_line_edit.h>
#include "ui/qt/widgets/wireshark_file_dialog.h"
#include <ui/qt/utils/qt_ui_utils.h>
#include "uat_dialog.h"
#include "wireshark_application.h"
@ -24,7 +25,6 @@
#include <QButtonGroup>
#include <QCheckBox>
#include <QComboBox>
#include <QFileDialog>
#include <QHBoxLayout>
#include <QLabel>
#include <QLineEdit>
@ -487,7 +487,7 @@ void ModulePreferencesScrollArea::saveFilenamePushButtonPressed()
pref_t *pref = VariantPointer<pref_t>::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<pref_t>::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<pref_t>::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()) {

View File

@ -26,7 +26,6 @@
#include <wsutil/g711.h>
#include <wsutil/pint.h>
#include <QFileDialog>
#include <QMessageBox>
#include <QPushButton>
#include <QTemporaryFile>
@ -36,6 +35,7 @@
#include "rtp_player_dialog.h"
#include <ui/qt/utils/stock_icon.h>
#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)"));

View File

@ -20,10 +20,10 @@
#include <ui/qt/utils/qt_ui_utils.h>
#include "rtp_analysis_dialog.h"
#include "wireshark_application.h"
#include "ui/qt/widgets/wireshark_file_dialog.h"
#include <QAction>
#include <QClipboard>
#include <QFileDialog>
#include <QKeyEvent>
#include <QPushButton>
#include <QTextStream>
@ -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) {

View File

@ -18,7 +18,6 @@
#include <QWidget>
#include <QDir>
#include <QFileDialog>
#include <QPushButton>
//#include <QDebug>

View File

@ -20,10 +20,10 @@
#include "ui/tap-sctp-analysis.h"
#include <QFileDialog>
#include <QMessageBox>
#include <ui/qt/widgets/qcustomplot.h>
#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) {

View File

@ -26,9 +26,9 @@
#include "wireshark_application.h"
#include <ui/qt/utils/variant_pointer.h>
#include <ui/alert_box.h>
#include "ui/qt/widgets/wireshark_file_dialog.h"
#include <QDir>
#include <QFileDialog>
#include <QFontMetrics>
#include <QPoint>
@ -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) {

View File

@ -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;

View File

@ -28,6 +28,12 @@
#include "epan/stat_tap_ui.h"
#ifdef Q_OS_WIN
#include <windows.h>
#include "ui/packet_range.h"
#include "ui/win32/file_dlg_win32.h"
#endif // Q_OS_WIN
#include "ui/last_open_dir.h"
#include <wsutil/utf8_entities.h>
@ -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();

View File

@ -24,10 +24,10 @@
#include <ui/qt/utils/qt_ui_utils.h>
#include "progress_frame.h"
#include "wireshark_application.h"
#include "ui/qt/widgets/wireshark_file_dialog.h"
#include <QCursor>
#include <QDir>
#include <QFileDialog>
#include <QIcon>
#include <QPushButton>
@ -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) {

View File

@ -10,6 +10,7 @@
*/
#include <ui/qt/widgets/editor_file_dialog.h>
#include <ui/qt/widgets/wireshark_file_dialog.h>
#include <QKeyEvent>
#include <QStyle>
@ -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())

View File

@ -0,0 +1,65 @@
/* wireshark_file_dialog.cpp
*
* Wireshark - Network traffic analyzer
* By Gerald Combs <gerald@wireshark.org>
* Copyright 1998 Gerald Combs
*
* SPDX-License-Identifier: GPL-2.0-or-later
*/
#include "wireshark_file_dialog.h"
#ifdef Q_OS_WIN
#include <windows.h>
#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:
*/

View File

@ -0,0 +1,50 @@
/* wireshark_file_dialog.h
*
* Wireshark - Network traffic analyzer
* By Gerald Combs <gerald@wireshark.org>
* Copyright 1998 Gerald Combs
*
* SPDX-License-Identifier: GPL-2.0-or-later
*/
#ifndef WIRESHARK_FILE_DIALOG_H
#define WIRESHARK_FILE_DIALOG_H
#include <QFileDialog>
/**
* @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:
*/