Kaydet (Commit) fee0bf03 authored tarafından Michael Weghorn's avatar Michael Weghorn Kaydeden (comit) Katarina Behrens

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: 's avatarKatarina Behrens <Katarina.Behrens@cib.de>
üst 3035db41
...@@ -56,6 +56,13 @@ class VCLPLUG_QT5_PUBLIC Qt5FilePicker : public QObject, public Qt5FilePicker_Ba ...@@ -56,6 +56,13 @@ class VCLPLUG_QT5_PUBLIC Qt5FilePicker : public QObject, public Qt5FilePicker_Ba
{ {
Q_OBJECT 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: protected:
css::uno::Reference<css::ui::dialogs::XFilePickerListener> m_xListener; css::uno::Reference<css::ui::dialogs::XFilePickerListener> m_xListener;
...@@ -78,7 +85,7 @@ protected: ...@@ -78,7 +85,7 @@ protected:
bool m_bIsFolderPicker; bool m_bIsFolderPicker;
public: public:
explicit Qt5FilePicker(QFileDialog::FileMode); explicit Qt5FilePicker(QFileDialog::FileMode, bool bShowFileExtensionInFilterTitle = false);
virtual ~Qt5FilePicker() override; virtual ~Qt5FilePicker() override;
// XFilePickerNotifier // XFilePickerNotifier
......
...@@ -76,8 +76,9 @@ uno::Sequence<OUString> FilePicker_getSupportedServiceNames() ...@@ -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) : Qt5FilePicker_Base(m_aHelperMutex)
, m_bShowFileExtensionInFilterTitle(bShowFileExtensionInFilterTitle)
, m_pFileDialog(new QFileDialog(nullptr, {}, QDir::homePath())) , m_pFileDialog(new QFileDialog(nullptr, {}, QDir::homePath()))
, m_bIsFolderPicker(eMode == QFileDialog::Directory) , m_bIsFolderPicker(eMode == QFileDialog::Directory)
{ {
...@@ -320,14 +321,17 @@ void SAL_CALL Qt5FilePicker::appendFilter(const OUString& title, const OUString& ...@@ -320,14 +321,17 @@ void SAL_CALL Qt5FilePicker::appendFilter(const OUString& title, const OUString&
QString t = toQString(title).replace("/", "\\/"); QString t = toQString(title).replace("/", "\\/");
QString n = t; QString n = t;
// strip duplicated type if (!m_bShowFileExtensionInFilterTitle)
int pos = n.indexOf(" ("); {
if (pos >= 0) // strip file extension from filter title
n.truncate(pos); int pos = n.indexOf(" (");
if (pos >= 0)
n.truncate(pos);
}
QString f = toQString(filter); 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(";", " "); f.replace(";", " ");
// make sure "*.*" is not used as "all files" // make sure "*.*" is not used as "all files"
......
...@@ -50,13 +50,6 @@ class KDE5FilePicker : public Qt5FilePicker ...@@ -50,13 +50,6 @@ class KDE5FilePicker : public Qt5FilePicker
{ {
Q_OBJECT Q_OBJECT
protected: 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 //mapping of SAL control ID's to created custom controls
QHash<sal_Int16, QWidget*> _customWidgets; QHash<sal_Int16, QWidget*> _customWidgets;
QHash<sal_Int16, QWidget*> _customListboxes; QHash<sal_Int16, QWidget*> _customListboxes;
...@@ -76,16 +69,6 @@ public: ...@@ -76,16 +69,6 @@ public:
// XExecutableDialog functions // XExecutableDialog functions
virtual sal_Int16 SAL_CALL execute() override; 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 // XFilePickerControlAccess functions
virtual void SAL_CALL setValue(sal_Int16 nControlId, sal_Int16 nControlAction, virtual void SAL_CALL setValue(sal_Int16 nControlId, sal_Int16 nControlAction,
const css::uno::Any& rValue) override; const css::uno::Any& rValue) override;
...@@ -135,11 +118,6 @@ Q_SIGNALS: ...@@ -135,11 +118,6 @@ Q_SIGNALS:
void enableControlSignal(sal_Int16 nControlId, bool bEnable); void enableControlSignal(sal_Int16 nControlId, bool bEnable);
void setLabelSignal(sal_Int16 nControlId, const OUString& rLabel); void setLabelSignal(sal_Int16 nControlId, const OUString& rLabel);
OUString getLabelSignal(sal_Int16 nControlId); 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: private Q_SLOTS:
void setValueSlot(sal_Int16 nControlId, sal_Int16 nControlAction, const css::uno::Any& rValue) void setValueSlot(sal_Int16 nControlId, sal_Int16 nControlAction, const css::uno::Any& rValue)
...@@ -163,20 +141,6 @@ private Q_SLOTS: ...@@ -163,20 +141,6 @@ private Q_SLOTS:
} }
OUString getLabelSlot(sal_Int16 nControlId) { return getLabel(nControlId); } 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: */ /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
...@@ -81,7 +81,8 @@ uno::Sequence<OUString> FilePicker_getSupportedServiceNames() ...@@ -81,7 +81,8 @@ uno::Sequence<OUString> FilePicker_getSupportedServiceNames()
// KDE5FilePicker // KDE5FilePicker
KDE5FilePicker::KDE5FilePicker(QFileDialog::FileMode eMode) KDE5FilePicker::KDE5FilePicker(QFileDialog::FileMode eMode)
: Qt5FilePicker(eMode) // Native kde5 filepicker does not add file extension automatically
: Qt5FilePicker(eMode, true)
, _extraControls(new QWidget) , _extraControls(new QWidget)
, _layout(new QGridLayout(_extraControls)) , _layout(new QGridLayout(_extraControls))
, allowRemoteUrls(false) , allowRemoteUrls(false)
...@@ -102,16 +103,6 @@ KDE5FilePicker::KDE5FilePicker(QFileDialog::FileMode eMode) ...@@ -102,16 +103,6 @@ KDE5FilePicker::KDE5FilePicker(QFileDialog::FileMode eMode)
connect(this, &KDE5FilePicker::executeSignal, this, &KDE5FilePicker::execute, connect(this, &KDE5FilePicker::executeSignal, this, &KDE5FilePicker::execute,
Qt::BlockingQueuedConnection); 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 // XFilePickerControlAccess
connect(this, &KDE5FilePicker::setValueSignal, this, &KDE5FilePicker::setValueSlot, connect(this, &KDE5FilePicker::setValueSignal, this, &KDE5FilePicker::setValueSlot,
Qt::BlockingQueuedConnection); Qt::BlockingQueuedConnection);
...@@ -138,87 +129,16 @@ sal_Int16 SAL_CALL KDE5FilePicker::execute() ...@@ -138,87 +129,16 @@ sal_Int16 SAL_CALL KDE5FilePicker::execute()
return Q_EMIT executeSignal(); return Q_EMIT executeSignal();
} }
if (!_filters.isEmpty()) if (!m_aNamedFilterList.isEmpty())
m_pFileDialog->setNameFilters(_filters); m_pFileDialog->setNameFilters(m_aNamedFilterList);
if (!_currentFilter.isEmpty()) if (!m_aCurrentFilter.isEmpty())
m_pFileDialog->selectNameFilter(_currentFilter); m_pFileDialog->selectNameFilter(m_aCurrentFilter);
m_pFileDialog->show(); m_pFileDialog->show();
//block and wait for user input //block and wait for user input
return m_pFileDialog->exec() == QFileDialog::Accepted ? 1 : 0; 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 // XFilePickerControlAccess
void SAL_CALL KDE5FilePicker::setValue(sal_Int16 controlId, sal_Int16 nControlAction, void SAL_CALL KDE5FilePicker::setValue(sal_Int16 controlId, sal_Int16 nControlAction,
const uno::Any& value) const uno::Any& value)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment