[Libreoffice-commits] core.git: Branch 'libreoffice-6-2' - vcl/inc vcl/qt5 vcl/unx
Michael Weghorn (via logerrit)
logerrit at kemper.freedesktop.org
Tue May 21 19:40:10 UTC 2019
vcl/inc/qt5/Qt5FilePicker.hxx | 9 +++
vcl/qt5/Qt5FilePicker.cxx | 16 ++++--
vcl/unx/kde5/KDE5FilePicker.hxx | 36 ---------------
vcl/unx/kde5/KDE5FilePicker2.cxx | 92 ++-------------------------------------
4 files changed, 24 insertions(+), 129 deletions(-)
New commits:
commit 34458461bca54ccb14dd2617ad4638cf687b04c0
Author: Michael Weghorn <m.weghorn at posteo.de>
AuthorDate: Wed Feb 6 14:40:45 2019 +0100
Commit: Katarina Behrens <Katarina.Behrens at cib.de>
CommitDate: Tue May 21 21:39:10 2019 +0200
KDE5FilePicker: Reuse XFilter{,Group}Manager methods from qt5
The non-native QFileDialog automatically adds the file extension
for the selected filter in the listbox, therefore it was stripped
from the filter title in 'Qt5FilePicker::appendFilter'.
Since the native Plasma/kde5 file dialog does not add it automatically,
introduce a new member 'm_bShowFileExtensionInFilterTitle' to specify
whether or not to strip the extension and set it accordingly in
KDE5FilePicker (so that it continues to show e.g.
"ODF Text Document (.odt)" instead of just "ODF Text Document").
This allows for KDE5FilePicker to reuse the base class implementation
and thus to drop all related own members and methods.
Change-Id: Icfb77d065160d3f655e3e89ad69de4195781373a
Reviewed-on: https://gerrit.libreoffice.org/68052
Tested-by: Jenkins
Reviewed-by: Katarina Behrens <Katarina.Behrens at cib.de>
(cherry picked from commit fee0bf03f4ca19c454fb727156887e45ceeb364a)
Reviewed-on: https://gerrit.libreoffice.org/72649
diff --git a/vcl/inc/qt5/Qt5FilePicker.hxx b/vcl/inc/qt5/Qt5FilePicker.hxx
index 1be97275ceb9..74fb25f57e20 100644
--- a/vcl/inc/qt5/Qt5FilePicker.hxx
+++ b/vcl/inc/qt5/Qt5FilePicker.hxx
@@ -56,6 +56,13 @@ class VCLPLUG_QT5_PUBLIC Qt5FilePicker : public QObject, public Qt5FilePicker_Ba
{
Q_OBJECT
+private:
+ // 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;
@@ -78,7 +85,7 @@ protected:
bool m_bIsFolderPicker;
public:
- explicit Qt5FilePicker(QFileDialog::FileMode);
+ explicit Qt5FilePicker(QFileDialog::FileMode, bool bShowFileExtensionInFilterTitle = false);
virtual ~Qt5FilePicker() override;
// XFilePickerNotifier
diff --git a/vcl/qt5/Qt5FilePicker.cxx b/vcl/qt5/Qt5FilePicker.cxx
index 37790a7d0349..6390f0d1474e 100644
--- a/vcl/qt5/Qt5FilePicker.cxx
+++ b/vcl/qt5/Qt5FilePicker.cxx
@@ -76,8 +76,9 @@ uno::Sequence<OUString> FilePicker_getSupportedServiceNames()
}
}
-Qt5FilePicker::Qt5FilePicker(QFileDialog::FileMode eMode)
+Qt5FilePicker::Qt5FilePicker(QFileDialog::FileMode eMode, bool bShowFileExtensionInFilterTitle)
: Qt5FilePicker_Base(m_aHelperMutex)
+ , m_bShowFileExtensionInFilterTitle(bShowFileExtensionInFilterTitle)
, m_pFileDialog(new QFileDialog(nullptr, {}, QDir::homePath()))
, m_bIsFolderPicker(eMode == QFileDialog::Directory)
{
@@ -320,14 +321,17 @@ void SAL_CALL Qt5FilePicker::appendFilter(const OUString& title, const OUString&
QString t = toQString(title).replace("/", "\\/");
QString n = t;
- // strip duplicated type
- int pos = n.indexOf(" (");
- if (pos >= 0)
- n.truncate(pos);
+ if (!m_bShowFileExtensionInFilterTitle)
+ {
+ // strip file extension from filter title
+ int pos = n.indexOf(" (");
+ if (pos >= 0)
+ n.truncate(pos);
+ }
QString f = toQString(filter);
- // openoffice gives us filters separated by ';' qt dialogs just want space separated
+ // LibreOffice gives us filters separated by ';' qt dialogs just want space separated
f.replace(";", " ");
// make sure "*.*" is not used as "all files"
diff --git a/vcl/unx/kde5/KDE5FilePicker.hxx b/vcl/unx/kde5/KDE5FilePicker.hxx
index 05a8f138350d..37bb748eed83 100644
--- a/vcl/unx/kde5/KDE5FilePicker.hxx
+++ b/vcl/unx/kde5/KDE5FilePicker.hxx
@@ -50,13 +50,6 @@ class KDE5FilePicker : public Qt5FilePicker
{
Q_OBJECT
protected:
- //running filter string to add to dialog
- QStringList _filters;
- // map of filter titles to full filter for selection
- QHash<QString, QString> _titleToFilters;
- // string to set the current filter
- QString _currentFilter;
-
//mapping of SAL control ID's to created custom controls
QHash<sal_Int16, QWidget*> _customWidgets;
QHash<sal_Int16, QWidget*> _customListboxes;
@@ -76,16 +69,6 @@ public:
// XExecutableDialog functions
virtual sal_Int16 SAL_CALL execute() override;
- // XFilterManager functions
- virtual void SAL_CALL appendFilter(const OUString& rTitle, const OUString& rFilter) override;
- virtual void SAL_CALL setCurrentFilter(const OUString& rTitle) override;
- virtual OUString SAL_CALL getCurrentFilter() override;
-
- // XFilterGroupManager functions
- virtual void SAL_CALL
- appendFilterGroup(const OUString& rGroupTitle,
- const css::uno::Sequence<css::beans::StringPair>& rFilters) override;
-
// XFilePickerControlAccess functions
virtual void SAL_CALL setValue(sal_Int16 nControlId, sal_Int16 nControlAction,
const css::uno::Any& rValue) override;
@@ -134,11 +117,6 @@ Q_SIGNALS:
void enableControlSignal(sal_Int16 nControlId, bool bEnable);
void setLabelSignal(sal_Int16 nControlId, const OUString& rLabel);
OUString getLabelSignal(sal_Int16 nControlId);
- void appendFilterSignal(const OUString& rTitle, const OUString& rFilter);
- void appendFilterGroupSignal(const OUString& rTitle,
- const css::uno::Sequence<css::beans::StringPair>& rFilters);
- void setCurrentFilterSignal(const OUString& rFilter);
- OUString getCurrentFilterSignal();
private Q_SLOTS:
void setValueSlot(sal_Int16 nControlId, sal_Int16 nControlAction, const css::uno::Any& rValue)
@@ -162,20 +140,6 @@ private Q_SLOTS:
}
OUString getLabelSlot(sal_Int16 nControlId) { return getLabel(nControlId); }
-
- void appendFilterSlot(const OUString& rTitle, const OUString& rFilter)
- {
- return appendFilter(rTitle, rFilter);
- }
-
- void appendFilterGroupSlot(const OUString& rTitle,
- const css::uno::Sequence<css::beans::StringPair>& rFilters)
- {
- return appendFilterGroup(rTitle, rFilters);
- }
-
- void setCurrentFilterSlot(const OUString& rFilter) { return setCurrentFilter(rFilter); }
- OUString getCurrentFilterSlot() { return getCurrentFilter(); }
};
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/vcl/unx/kde5/KDE5FilePicker2.cxx b/vcl/unx/kde5/KDE5FilePicker2.cxx
index f146870a4713..ac43149437d8 100644
--- a/vcl/unx/kde5/KDE5FilePicker2.cxx
+++ b/vcl/unx/kde5/KDE5FilePicker2.cxx
@@ -80,7 +80,8 @@ uno::Sequence<OUString> FilePicker_getSupportedServiceNames()
// KDE5FilePicker
KDE5FilePicker::KDE5FilePicker(QFileDialog::FileMode eMode)
- : Qt5FilePicker(eMode)
+ // Native kde5 filepicker does not add file extension automatically
+ : Qt5FilePicker(eMode, true)
, _extraControls(new QWidget)
, _layout(new QGridLayout(_extraControls))
, allowRemoteUrls(false)
@@ -101,16 +102,6 @@ KDE5FilePicker::KDE5FilePicker(QFileDialog::FileMode eMode)
connect(this, &KDE5FilePicker::executeSignal, this, &KDE5FilePicker::execute,
Qt::BlockingQueuedConnection);
- // XFilterManager
- connect(this, &KDE5FilePicker::appendFilterSignal, this, &KDE5FilePicker::appendFilterSlot,
- Qt::BlockingQueuedConnection);
- connect(this, &KDE5FilePicker::setCurrentFilterSignal, this,
- &KDE5FilePicker::setCurrentFilterSlot, Qt::BlockingQueuedConnection);
- connect(this, &KDE5FilePicker::getCurrentFilterSignal, this,
- &KDE5FilePicker::getCurrentFilterSlot, Qt::BlockingQueuedConnection);
- // XFilterGroupManager
- connect(this, &KDE5FilePicker::appendFilterGroupSignal, this,
- &KDE5FilePicker::appendFilterGroupSlot, Qt::BlockingQueuedConnection);
// XFilePickerControlAccess
connect(this, &KDE5FilePicker::setValueSignal, this, &KDE5FilePicker::setValueSlot,
Qt::BlockingQueuedConnection);
@@ -137,87 +128,16 @@ sal_Int16 SAL_CALL KDE5FilePicker::execute()
return Q_EMIT executeSignal();
}
- if (!_filters.isEmpty())
- m_pFileDialog->setNameFilters(_filters);
- if (!_currentFilter.isEmpty())
- m_pFileDialog->selectNameFilter(_currentFilter);
+ if (!m_aNamedFilterList.isEmpty())
+ m_pFileDialog->setNameFilters(m_aNamedFilterList);
+ if (!m_aCurrentFilter.isEmpty())
+ m_pFileDialog->selectNameFilter(m_aCurrentFilter);
m_pFileDialog->show();
//block and wait for user input
return m_pFileDialog->exec() == QFileDialog::Accepted ? 1 : 0;
}
-// XFilterManager
-void SAL_CALL KDE5FilePicker::appendFilter(const OUString& title, const OUString& filter)
-{
- if (qApp->thread() != QThread::currentThread())
- {
- SolarMutexReleaser aReleaser;
- return Q_EMIT appendFilterSignal(title, filter);
- }
-
- QString t(toQString(title));
- QString f(toQString(filter));
- // '/' need to be escaped else they are assumed to be mime types by kfiledialog
- //see the docs
- t.replace("/", "\\/");
-
- // libreoffice separates by filters by ';' qt dialogs by space
- f.replace(";", " ");
-
- // make sure "*.*" is not used as "all files"
- f.replace("*.*", "*");
-
- _filters << QStringLiteral("%1 (%2)").arg(t, f);
- _titleToFilters[t] = _filters.constLast();
-}
-
-void SAL_CALL KDE5FilePicker::setCurrentFilter(const OUString& title)
-{
- if (qApp->thread() != QThread::currentThread())
- {
- SolarMutexReleaser aReleaser;
- return Q_EMIT setCurrentFilterSignal(title);
- }
-
- _currentFilter = _titleToFilters.value(toQString(title));
-}
-
-OUString SAL_CALL KDE5FilePicker::getCurrentFilter()
-{
- if (qApp->thread() != QThread::currentThread())
- {
- SolarMutexReleaser aReleaser;
- return Q_EMIT getCurrentFilterSignal();
- }
-
- OUString filter = toOUString(_titleToFilters.key(m_pFileDialog->selectedNameFilter()));
-
- //default if not found
- if (filter.isEmpty())
- filter = "ODF Text Document (.odt)";
-
- return filter;
-}
-
-// XFilterGroupManager
-void SAL_CALL KDE5FilePicker::appendFilterGroup(const OUString& rGroupTitle,
- const uno::Sequence<beans::StringPair>& filters)
-{
- if (qApp->thread() != QThread::currentThread())
- {
- SolarMutexReleaser aReleaser;
- return Q_EMIT appendFilterGroupSignal(rGroupTitle, filters);
- }
-
- const sal_uInt16 length = filters.getLength();
- for (sal_uInt16 i = 0; i < length; ++i)
- {
- beans::StringPair aPair = filters[i];
- appendFilter(aPair.First, aPair.Second);
- }
-}
-
// XFilePickerControlAccess
void SAL_CALL KDE5FilePicker::setValue(sal_Int16 controlId, sal_Int16 nControlAction,
const uno::Any& value)
More information about the Libreoffice-commits
mailing list