From 1d01ebc84867af00825512a3a3cfd9d0fa15eea9 Mon Sep 17 00:00:00 2001 From: Michael Weghorn Date: Thu, 7 Feb 2019 16:58:29 +0100 Subject: Make 'setDefaultName()' work again for kde5 fpicker Add an option to Qt5FilePicker constructor to say whether the QFileDialog should be a native one or not, since 'QFileDialog::selectFile' does not preselect the correct name in the native dialog any more if the 'QFileDialog::DontUseNativeDialog' option has ever been set, i.e. QFileDialog fileDialog; fileDialog.setOption(QFileDialog::DontUseNativeDialog); fileDialog.setOption(QFileDialog::DontUseNativeDialog, false); fileDialog.selectFile("test.txt"); will not properly set the name in the native file dialog, which broke 'setDefaultName' for the KDE5FilePicker. This makes it work again, even though I think that the underlying issue is a Qt bug (s. https://bugreports.qt.io/browse/QTBUG-73682 ). Change-Id: I99a1e7c97d594925d600fa8eaf3303f9013551c2 Reviewed-on: https://gerrit.libreoffice.org/68058 Tested-by: Jenkins Reviewed-by: Katarina Behrens --- vcl/inc/qt5/Qt5FilePicker.hxx | 5 ++++- vcl/qt5/Qt5FilePicker.cxx | 7 +++++-- vcl/unx/kde5/KDE5FilePicker2.cxx | 2 +- 3 files changed, 10 insertions(+), 4 deletions(-) (limited to 'vcl') diff --git a/vcl/inc/qt5/Qt5FilePicker.hxx b/vcl/inc/qt5/Qt5FilePicker.hxx index 8b8055efab9d..1bb6974ab83e 100644 --- a/vcl/inc/qt5/Qt5FilePicker.hxx +++ b/vcl/inc/qt5/Qt5FilePicker.hxx @@ -86,7 +86,10 @@ protected: bool m_bIsFolderPicker; public: - explicit Qt5FilePicker(QFileDialog::FileMode, bool bShowFileExtensionInFilterTitle = false); + // use non-native file dialog by default; there's no easy way to add custom widgets + // in a generic way in the native one + explicit Qt5FilePicker(QFileDialog::FileMode, bool bShowFileExtensionInFilterTitle = false, + bool bUseNativeDialog = false); virtual ~Qt5FilePicker() override; // XFilePickerNotifier diff --git a/vcl/qt5/Qt5FilePicker.cxx b/vcl/qt5/Qt5FilePicker.cxx index 0d2025cec55b..dcfcc68f0888 100644 --- a/vcl/qt5/Qt5FilePicker.cxx +++ b/vcl/qt5/Qt5FilePicker.cxx @@ -76,13 +76,16 @@ uno::Sequence FilePicker_getSupportedServiceNames() } } -Qt5FilePicker::Qt5FilePicker(QFileDialog::FileMode eMode, bool bShowFileExtensionInFilterTitle) +Qt5FilePicker::Qt5FilePicker(QFileDialog::FileMode eMode, bool bShowFileExtensionInFilterTitle, + bool bUseNativeDialog) : Qt5FilePicker_Base(m_aHelperMutex) , m_bShowFileExtensionInFilterTitle(bShowFileExtensionInFilterTitle) , m_pFileDialog(new QFileDialog(nullptr, {}, QDir::homePath())) , m_bIsFolderPicker(eMode == QFileDialog::Directory) { - m_pFileDialog->setOption(QFileDialog::DontUseNativeDialog); + if (!bUseNativeDialog) + m_pFileDialog->setOption(QFileDialog::DontUseNativeDialog); + m_pFileDialog->setFileMode(eMode); m_pFileDialog->setWindowModality(Qt::ApplicationModal); diff --git a/vcl/unx/kde5/KDE5FilePicker2.cxx b/vcl/unx/kde5/KDE5FilePicker2.cxx index 3f4f61575185..2e855bac7c6b 100644 --- a/vcl/unx/kde5/KDE5FilePicker2.cxx +++ b/vcl/unx/kde5/KDE5FilePicker2.cxx @@ -82,7 +82,7 @@ uno::Sequence FilePicker_getSupportedServiceNames() KDE5FilePicker::KDE5FilePicker(QFileDialog::FileMode eMode) // Native kde5 filepicker does not add file extension automatically - : Qt5FilePicker(eMode, true) + : Qt5FilePicker(eMode, true, true) , _layout(new QGridLayout(m_pExtraControls)) , allowRemoteUrls(false) { -- cgit