diff options
-rw-r--r-- | vcl/inc/qt5/Qt5FilePicker.hxx | 32 | ||||
-rw-r--r-- | vcl/qt5/Qt5FilePicker.cxx | 36 | ||||
-rw-r--r-- | vcl/unx/kf5/KF5FilePicker.cxx | 5 | ||||
-rw-r--r-- | vcl/unx/kf5/KF5FilePicker.hxx | 6 |
4 files changed, 32 insertions, 47 deletions
diff --git a/vcl/inc/qt5/Qt5FilePicker.hxx b/vcl/inc/qt5/Qt5FilePicker.hxx index 35ca687f8dcb..6fb116875dd4 100644 --- a/vcl/inc/qt5/Qt5FilePicker.hxx +++ b/vcl/inc/qt5/Qt5FilePicker.hxx @@ -60,39 +60,31 @@ class VCLPLUG_QT5_PUBLIC Qt5FilePicker : public QObject, public Qt5FilePicker_Ba private: css::uno::Reference<css::uno::XComponentContext> m_context; - // whether to show (i.e. not remove) the file extension in the filter title, - // e.g. whether to use "ODF Text Document (*.odt)" or just - // "ODF Text Document" as filter title - // (non-native QFileDialog e.g. adds that information by itself anyway) - bool m_bShowFileExtensionInFilterTitle; - -protected: css::uno::Reference<css::ui::dialogs::XFilePickerListener> m_xListener; - std::unique_ptr<QFileDialog> m_pFileDialog; ///< the non-native file picker dialog - osl::Mutex m_aHelperMutex; ///< mutex used by the WeakComponentImplHelper - QStringList m_aNamedFilterList; ///< to keep the original sequence QHash<QString, QString> m_aTitleToFilterMap; // to retrieve the filename extension for a given filter QHash<QString, QString> m_aNamedFilterToExtensionMap; - QString m_aCurrentFilter; - QWidget* m_pExtraControls; ///< widget to contain extra custom controls QGridLayout* m_pLayout; ///< layout for extra custom controls - QLabel* m_pFilenameLabel; ///< label to display the filename - QLabel* m_pFilterLabel; ///< label to display the filter QHash<sal_Int16, QWidget*> m_aCustomWidgetsMap; ///< map of SAL control ID's to widget - bool m_bIsFolderPicker; + const bool m_bIsFolderPicker; + +protected: + QStringList m_aNamedFilterList; ///< to keep the original sequence + QString m_aCurrentFilter; + + std::unique_ptr<QFileDialog> m_pFileDialog; ///< the file picker dialog + QWidget* m_pExtraControls; ///< widget to contain extra custom controls public: // 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(css::uno::Reference<css::uno::XComponentContext> const& context, - QFileDialog::FileMode, bool bShowFileExtensionInFilterTitle = false, - bool bUseNativeDialog = false); + QFileDialog::FileMode, bool bUseNative = false); virtual ~Qt5FilePicker() override; // XFilePickerNotifier @@ -155,9 +147,6 @@ public: virtual void SAL_CALL setDescription(const OUString& rDescription) override; protected: - static css::uno::Any handleGetListValue(const QComboBox* pWidget, sal_Int16 nControlAction); - static void handleSetListValue(QComboBox* pQComboBox, sal_Int16 nAction, - const css::uno::Any& rValue); virtual void addCustomControl(sal_Int16 controlId); void setCustomControlWidgetLayout(QGridLayout* pLayout) { m_pLayout = pLayout; } @@ -166,6 +155,9 @@ private: Qt5FilePicker& operator=(const Qt5FilePicker&) = delete; static QString getResString(const char* pRedId); + static css::uno::Any handleGetListValue(const QComboBox* pWidget, sal_Int16 nControlAction); + static void handleSetListValue(QComboBox* pQComboBox, sal_Int16 nAction, + const css::uno::Any& rValue); private Q_SLOTS: // emit XFilePickerListener controlStateChanged event diff --git a/vcl/qt5/Qt5FilePicker.cxx b/vcl/qt5/Qt5FilePicker.cxx index 730d7f142df0..10c25052fd8a 100644 --- a/vcl/qt5/Qt5FilePicker.cxx +++ b/vcl/qt5/Qt5FilePicker.cxx @@ -76,16 +76,14 @@ uno::Sequence<OUString> FilePicker_getSupportedServiceNames() } Qt5FilePicker::Qt5FilePicker(css::uno::Reference<css::uno::XComponentContext> const& context, - QFileDialog::FileMode eMode, bool bShowFileExtensionInFilterTitle, - bool bUseNativeDialog) + QFileDialog::FileMode eMode, bool bUseNative) : Qt5FilePicker_Base(m_aHelperMutex) , m_context(context) - , m_bShowFileExtensionInFilterTitle(bShowFileExtensionInFilterTitle) - , m_pFileDialog(new QFileDialog(nullptr, {}, QDir::homePath())) , m_bIsFolderPicker(eMode == QFileDialog::Directory) + , m_pFileDialog(new QFileDialog(nullptr, {}, QDir::homePath())) + , m_pExtraControls(new QWidget()) { - if (!bUseNativeDialog) - m_pFileDialog->setOption(QFileDialog::DontUseNativeDialog); + m_pFileDialog->setOption(QFileDialog::DontUseNativeDialog, !bUseNative); m_pFileDialog->setFileMode(eMode); m_pFileDialog->setWindowModality(Qt::ApplicationModal); @@ -96,7 +94,6 @@ Qt5FilePicker::Qt5FilePicker(css::uno::Reference<css::uno::XComponentContext> co m_pFileDialog->setWindowTitle(toQString(VclResId(STR_FPICKER_FOLDER_DEFAULT_TITLE))); } - m_pExtraControls = new QWidget(); m_pLayout = dynamic_cast<QGridLayout*>(m_pFileDialog->layout()); setMultiSelectionMode(false); @@ -293,28 +290,28 @@ void SAL_CALL Qt5FilePicker::appendFilter(const OUString& title, const OUString& } // '/' need to be escaped else they are assumed to be mime types - QString t = toQString(title).replace("/", "\\/"); + QString sTitle = toQString(title).replace("/", "\\/"); - QString n = t; - if (!m_bShowFileExtensionInFilterTitle) + QString sFilterName = sTitle; + // the Qt5 non-native file picker adds the extensions to the filter title, so strip them + if (m_pFileDialog->testOption(QFileDialog::DontUseNativeDialog)) { - // strip file extension from filter title - int pos = n.indexOf(" ("); + int pos = sFilterName.indexOf(" ("); if (pos >= 0) - n.truncate(pos); + sFilterName.truncate(pos); } - QString f = toQString(filter); + QString sGlobFilter = toQString(filter); // LibreOffice gives us filters separated by ';' qt dialogs just want space separated - f.replace(";", " "); + sGlobFilter.replace(";", " "); // make sure "*.*" is not used as "all files" - f.replace("*.*", "*"); + sGlobFilter.replace("*.*", "*"); - m_aNamedFilterList << QStringLiteral("%1 (%2)").arg(n, f); - m_aTitleToFilterMap[t] = m_aNamedFilterList.constLast(); - m_aNamedFilterToExtensionMap[m_aNamedFilterList.constLast()] = f; + m_aNamedFilterList << QStringLiteral("%1 (%2)").arg(sFilterName, sGlobFilter); + m_aTitleToFilterMap[sTitle] = m_aNamedFilterList.constLast(); + m_aNamedFilterToExtensionMap[m_aNamedFilterList.constLast()] = sGlobFilter; } void SAL_CALL Qt5FilePicker::setCurrentFilter(const OUString& title) @@ -704,6 +701,7 @@ void SAL_CALL Qt5FilePicker::initialize(const uno::Sequence<uno::Any>& args) return; } + m_aNamedFilterToExtensionMap.clear(); m_aNamedFilterList.clear(); m_aTitleToFilterMap.clear(); m_aCurrentFilter.clear(); diff --git a/vcl/unx/kf5/KF5FilePicker.cxx b/vcl/unx/kf5/KF5FilePicker.cxx index b269c893c60f..a7ecd938ccca 100644 --- a/vcl/unx/kf5/KF5FilePicker.cxx +++ b/vcl/unx/kf5/KF5FilePicker.cxx @@ -48,12 +48,9 @@ uno::Sequence<OUString> FilePicker_getSupportedServiceNames() KF5FilePicker::KF5FilePicker(css::uno::Reference<css::uno::XComponentContext> const& context, QFileDialog::FileMode eMode) // Native kf5 filepicker does not add file extension automatically - : Qt5FilePicker(context, eMode, true, true) + : Qt5FilePicker(context, eMode, true) , _layout(new QGridLayout(m_pExtraControls)) { - // use native dialog - m_pFileDialog->setOption(QFileDialog::DontUseNativeDialog, false); - // only columns 0 and 1 are used by controls (s. Qt5FilePicker::addCustomControl); // set stretch for (unused) column 2 in order for the controls to only take the space // they actually need and avoid empty space in between diff --git a/vcl/unx/kf5/KF5FilePicker.hxx b/vcl/unx/kf5/KF5FilePicker.hxx index 4325e782d0f4..ee731a36a425 100644 --- a/vcl/unx/kf5/KF5FilePicker.hxx +++ b/vcl/unx/kf5/KF5FilePicker.hxx @@ -23,11 +23,11 @@ class QGridLayout; -class KF5FilePicker : public Qt5FilePicker +class KF5FilePicker final : public Qt5FilePicker { Q_OBJECT -protected: +private: //layout for extra custom controls QGridLayout* _layout; @@ -55,8 +55,6 @@ public: private: //add a custom control widget to the file dialog void addCustomControl(sal_Int16 controlId) override; - -protected: bool eventFilter(QObject* watched, QEvent* event) override; }; |