[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:31:28 UTC 2019


 vcl/inc/qt5/Qt5FilePicker.hxx    |    2 +
 vcl/qt5/Qt5FilePicker.cxx        |   18 +++++++---
 vcl/unx/kde5/KDE5FilePicker.hxx  |    7 ---
 vcl/unx/kde5/KDE5FilePicker2.cxx |   70 ++++++++++++---------------------------
 4 files changed, 37 insertions(+), 60 deletions(-)

New commits:
commit 5e5a50ad52b397d38501102f00a7ced77cbe29a4
Author:     Michael Weghorn <m.weghorn at posteo.de>
AuthorDate: Tue Feb 5 13:43:20 2019 +0100
Commit:     Katarina Behrens <Katarina.Behrens at cib.de>
CommitDate: Tue May 21 21:30:23 2019 +0200

    qt5/kde5: Reuse QFileDialog from Qt5Filepicker in kde5
    
    Drop the '_dialog' member from KDE5FileDialog and use
    the one from Qt5FileDialog instead.
    Move up 'm_bIsFolderPicker' to Qt5FilePicker.
    
    Also, move some of the related functionality from
    the kde5 file picker to the qt5 one, in particular
    take over missing parts from 'KDE5FilePicker::setMultiSelectionMode'
    to 'Qt5FilePicker::setMultiSelectionMode' and drop the
    former (now inherited from the base class).
    
    This e.g. also makes sure that only folders are available
    for selection when using a FolderPicker in qt5
    (e.g. in the dialog to add a JRE in "Tools" -> "Options"
     -> "Advanced"). The functionality had only been implemented
    for kde5 beforehand.
    
    Since the QFileDialog is set to non-native mode in
    Qt5FilePicker constructor, native mode needs to be
    excplicitly enabled again for kde5.
    
    Since Qt's signal/slot mechanism is used to connect
    signals on the object in both constructors
    (Qt5FilePicker/KDE5FilePicker), some events will
    trigger multiple actions. This will be taken care
    of in subsequent commits, along with further
    refactoring.
    
    Change-Id: I245d46c12945acb91c9b52dcff5c83248ac087dd
    Reviewed-on: https://gerrit.libreoffice.org/68042
    Tested-by: Jenkins
    Reviewed-by: Katarina Behrens <Katarina.Behrens at cib.de>
    (cherry picked from commit 0e4963186a6f1bfbde5279c25c62694d073e92a1)
    Reviewed-on: https://gerrit.libreoffice.org/72639

diff --git a/vcl/inc/qt5/Qt5FilePicker.hxx b/vcl/inc/qt5/Qt5FilePicker.hxx
index e40d4c491263..1be97275ceb9 100644
--- a/vcl/inc/qt5/Qt5FilePicker.hxx
+++ b/vcl/inc/qt5/Qt5FilePicker.hxx
@@ -75,6 +75,8 @@ protected:
     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;
+
 public:
     explicit Qt5FilePicker(QFileDialog::FileMode);
     virtual ~Qt5FilePicker() override;
diff --git a/vcl/qt5/Qt5FilePicker.cxx b/vcl/qt5/Qt5FilePicker.cxx
index 6db64b3b0824..5a0abc2b8d48 100644
--- a/vcl/qt5/Qt5FilePicker.cxx
+++ b/vcl/qt5/Qt5FilePicker.cxx
@@ -78,12 +78,19 @@ uno::Sequence<OUString> FilePicker_getSupportedServiceNames()
 
 Qt5FilePicker::Qt5FilePicker(QFileDialog::FileMode eMode)
     : Qt5FilePicker_Base(m_aHelperMutex)
-    , m_pFileDialog(new QFileDialog())
+    , m_pFileDialog(new QFileDialog(nullptr, {}, QDir::homePath()))
+    , m_bIsFolderPicker(eMode == QFileDialog::Directory)
 {
     m_pFileDialog->setOption(QFileDialog::DontUseNativeDialog);
     m_pFileDialog->setFileMode(eMode);
     m_pFileDialog->setWindowModality(Qt::ApplicationModal);
 
+    if (m_bIsFolderPicker)
+    {
+        m_pFileDialog->setOption(QFileDialog::ShowDirsOnly, true);
+        m_pFileDialog->setWindowTitle(toQString(VclResId(STR_FPICKER_FOLDER_DEFAULT_TITLE)));
+    }
+
     m_pExtraControls = new QWidget();
     m_pLayout = dynamic_cast<QGridLayout*>(m_pFileDialog->layout());
 
@@ -232,10 +239,11 @@ void SAL_CALL Qt5FilePicker::setMultiSelectionMode(sal_Bool multiSelect)
         return Q_EMIT setMultiSelectionModeSignal(multiSelect);
     }
 
-    if (multiSelect)
-        m_pFileDialog->setFileMode(QFileDialog::ExistingFiles);
-    else
-        m_pFileDialog->setFileMode(QFileDialog::ExistingFile);
+    if (m_bIsFolderPicker || m_pFileDialog->acceptMode() == QFileDialog::AcceptSave)
+        return;
+
+    m_pFileDialog->setFileMode(multiSelect ? QFileDialog::ExistingFiles
+                                           : QFileDialog::ExistingFile);
 }
 
 void SAL_CALL Qt5FilePicker::setDefaultName(const OUString& name)
diff --git a/vcl/unx/kde5/KDE5FilePicker.hxx b/vcl/unx/kde5/KDE5FilePicker.hxx
index bd9eac8d8939..dcc7367cebab 100644
--- a/vcl/unx/kde5/KDE5FilePicker.hxx
+++ b/vcl/unx/kde5/KDE5FilePicker.hxx
@@ -54,9 +54,6 @@ protected:
     css::uno::Reference<css::ui::dialogs::XFilePickerListener> m_xListener;
     osl::Mutex _helperMutex;
 
-    //the dialog to display
-    QFileDialog* _dialog;
-
     //running filter string to add to dialog
     QStringList _filters;
     // map of filter titles to full filter for selection
@@ -75,7 +72,6 @@ protected:
     QGridLayout* _layout;
 
     bool allowRemoteUrls;
-    bool mbIsFolderPicker;
 
 public:
     explicit KDE5FilePicker(QFileDialog::FileMode);
@@ -92,7 +88,6 @@ public:
     virtual sal_Int16 SAL_CALL execute() override;
 
     // XFilePicker functions
-    virtual void SAL_CALL setMultiSelectionMode(sal_Bool bMode) override;
     virtual void SAL_CALL setDefaultName(const OUString& rName) override;
     virtual void SAL_CALL setDisplayDirectory(const OUString& rDirectory) override;
     virtual OUString SAL_CALL getDisplayDirectory() override;
@@ -185,7 +180,6 @@ Q_SIGNALS:
     OUString getCurrentFilterSignal();
     css::uno::Sequence<OUString> getFilesSignal();
     css::uno::Sequence<OUString> getSelectedFilesSignal();
-    void setMultiSelectionSignal(bool bMulti);
 
 private Q_SLOTS:
     void setTitleSlot(const OUString& rTitle) { return setTitle(rTitle); }
@@ -229,7 +223,6 @@ private Q_SLOTS:
     void setCurrentFilterSlot(const OUString& rFilter) { return setCurrentFilter(rFilter); }
     OUString getCurrentFilterSlot() { return getCurrentFilter(); }
     css::uno::Sequence<OUString> getSelectedFilesSlot() { return getFiles(); }
-    void setMultiSelectionSlot(bool bMulti) { return setMultiSelectionMode(bMulti); }
 };
 
 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/vcl/unx/kde5/KDE5FilePicker2.cxx b/vcl/unx/kde5/KDE5FilePicker2.cxx
index 9661a5a842ab..e8e86f0e5dcf 100644
--- a/vcl/unx/kde5/KDE5FilePicker2.cxx
+++ b/vcl/unx/kde5/KDE5FilePicker2.cxx
@@ -82,13 +82,14 @@ uno::Sequence<OUString> FilePicker_getSupportedServiceNames()
 
 KDE5FilePicker::KDE5FilePicker(QFileDialog::FileMode eMode)
     : Qt5FilePicker(eMode)
-    , _dialog(new QFileDialog(nullptr, {}, QDir::homePath()))
     , _extraControls(new QWidget)
     , _layout(new QGridLayout(_extraControls))
     , allowRemoteUrls(false)
-    , mbIsFolderPicker(eMode == QFileDialog::Directory)
 {
-    _dialog->setSupportedSchemes({
+    // use native dialog
+    m_pFileDialog->setOption(QFileDialog::DontUseNativeDialog, false);
+
+    m_pFileDialog->setSupportedSchemes({
         QStringLiteral("file"),
         QStringLiteral("ftp"),
         QStringLiteral("http"),
@@ -98,16 +99,10 @@ KDE5FilePicker::KDE5FilePicker(QFileDialog::FileMode eMode)
         QStringLiteral("smb"),
     });
 
-    _dialog->setFileMode(eMode);
-
-    if (mbIsFolderPicker)
-    {
-        _dialog->setOption(QFileDialog::ShowDirsOnly, true);
-        _dialog->setWindowTitle(toQString(VclResId(STR_FPICKER_FOLDER_DEFAULT_TITLE)));
-    }
-
-    connect(_dialog, &QFileDialog::filterSelected, this, &KDE5FilePicker::filterChanged);
-    connect(_dialog, &QFileDialog::fileSelected, this, &KDE5FilePicker::selectionChanged);
+    connect(m_pFileDialog.get(), &QFileDialog::filterSelected, this,
+            &KDE5FilePicker::filterChanged);
+    connect(m_pFileDialog.get(), &QFileDialog::fileSelected, this,
+            &KDE5FilePicker::selectionChanged);
     connect(this, &KDE5FilePicker::executeSignal, this, &KDE5FilePicker::execute,
             Qt::BlockingQueuedConnection);
 
@@ -115,8 +110,6 @@ KDE5FilePicker::KDE5FilePicker(QFileDialog::FileMode eMode)
     connect(this, &KDE5FilePicker::setTitleSignal, this, &KDE5FilePicker::setTitleSlot,
             Qt::BlockingQueuedConnection);
     // XFilePicker
-    connect(this, &KDE5FilePicker::setMultiSelectionSignal, this,
-            &KDE5FilePicker::setMultiSelectionSlot, Qt::BlockingQueuedConnection);
     connect(this, &KDE5FilePicker::setDefaultNameSignal, this, &KDE5FilePicker::setDefaultNameSlot,
             Qt::BlockingQueuedConnection);
     connect(this, &KDE5FilePicker::setDisplayDirectorySignal, this,
@@ -157,11 +150,7 @@ KDE5FilePicker::KDE5FilePicker(QFileDialog::FileMode eMode)
     qApp->installEventFilter(this);
 }
 
-KDE5FilePicker::~KDE5FilePicker()
-{
-    delete _extraControls;
-    delete _dialog;
-}
+KDE5FilePicker::~KDE5FilePicker() { delete _extraControls; }
 
 void SAL_CALL
 KDE5FilePicker::addFilePickerListener(const uno::Reference<XFilePickerListener>& xListener)
@@ -185,7 +174,7 @@ void SAL_CALL KDE5FilePicker::setTitle(const OUString& title)
         return Q_EMIT setTitleSignal(title);
     }
 
-    _dialog->setWindowTitle(toQString(title));
+    m_pFileDialog->setWindowTitle(toQString(title));
 }
 
 sal_Int16 SAL_CALL KDE5FilePicker::execute()
@@ -197,28 +186,13 @@ sal_Int16 SAL_CALL KDE5FilePicker::execute()
     }
 
     if (!_filters.isEmpty())
-        _dialog->setNameFilters(_filters);
+        m_pFileDialog->setNameFilters(_filters);
     if (!_currentFilter.isEmpty())
-        _dialog->selectNameFilter(_currentFilter);
+        m_pFileDialog->selectNameFilter(_currentFilter);
 
-    _dialog->show();
+    m_pFileDialog->show();
     //block and wait for user input
-    return _dialog->exec() == QFileDialog::Accepted ? 1 : 0;
-}
-
-// XFilePicker
-void SAL_CALL KDE5FilePicker::setMultiSelectionMode(sal_Bool multiSelect)
-{
-    if (qApp->thread() != QThread::currentThread())
-    {
-        SolarMutexReleaser aReleaser;
-        return Q_EMIT setMultiSelectionSignal(multiSelect);
-    }
-
-    if (mbIsFolderPicker || _dialog->acceptMode() == QFileDialog::AcceptSave)
-        return;
-
-    _dialog->setFileMode(multiSelect ? QFileDialog::ExistingFiles : QFileDialog::ExistingFile);
+    return m_pFileDialog->exec() == QFileDialog::Accepted ? 1 : 0;
 }
 
 void SAL_CALL KDE5FilePicker::setDefaultName(const OUString& name)
@@ -229,7 +203,7 @@ void SAL_CALL KDE5FilePicker::setDefaultName(const OUString& name)
         return Q_EMIT setDefaultNameSignal(name);
     }
 
-    _dialog->selectFile(toQString(name));
+    m_pFileDialog->selectFile(toQString(name));
 }
 
 void SAL_CALL KDE5FilePicker::setDisplayDirectory(const OUString& dir)
@@ -241,7 +215,7 @@ void SAL_CALL KDE5FilePicker::setDisplayDirectory(const OUString& dir)
     }
 
     QString qDir(toQString(dir));
-    _dialog->setDirectoryUrl(QUrl(qDir));
+    m_pFileDialog->setDirectoryUrl(QUrl(qDir));
 }
 
 OUString SAL_CALL KDE5FilePicker::getDisplayDirectory()
@@ -278,7 +252,7 @@ uno::Sequence<OUString> SAL_CALL KDE5FilePicker::getSelectedFiles()
         return Q_EMIT getSelectedFilesSignal();
     }
 
-    QList<QUrl> aURLs = _dialog->selectedUrls();
+    QList<QUrl> aURLs = m_pFileDialog->selectedUrls();
     uno::Sequence<OUString> seq(aURLs.size());
 
     size_t i = 0;
@@ -334,7 +308,7 @@ OUString SAL_CALL KDE5FilePicker::getCurrentFilter()
         return Q_EMIT getCurrentFilterSignal();
     }
 
-    OUString filter = toOUString(_titleToFilters.key(_dialog->selectedNameFilter()));
+    OUString filter = toOUString(_titleToFilters.key(m_pFileDialog->selectedNameFilter()));
 
     //default if not found
     if (filter.isEmpty())
@@ -673,7 +647,7 @@ uno::Any KDE5FilePicker::handleGetListValue(QComboBox* pQComboBox, sal_Int16 nAc
 
 OUString KDE5FilePicker::implGetDirectory()
 {
-    OUString dir = toOUString(_dialog->directoryUrl().url());
+    OUString dir = toOUString(m_pFileDialog->directoryUrl().url());
     return dir;
 }
 
@@ -786,12 +760,12 @@ void SAL_CALL KDE5FilePicker::initialize(const uno::Sequence<uno::Any>& args)
     QFileDialog::AcceptMode operationMode
         = saveDialog ? QFileDialog::AcceptSave : QFileDialog::AcceptOpen;
 
-    _dialog->setAcceptMode(operationMode);
+    m_pFileDialog->setAcceptMode(operationMode);
 
     if (saveDialog)
     {
-        _dialog->setConfirmOverwrite(true);
-        _dialog->setFileMode(QFileDialog::AnyFile);
+        m_pFileDialog->setConfirmOverwrite(true);
+        m_pFileDialog->setFileMode(QFileDialog::AnyFile);
     }
 
     setTitle(VclResId(saveDialog ? STR_FPICKER_SAVE : STR_FPICKER_OPEN));


More information about the Libreoffice-commits mailing list