Fix Plasma-QPA filedialog to show wrong directory with QFileDialog::selectUrl()
ClosedPublic

Authored by kossebau on Dec 22 2016, 7:09 PM.

Details

Summary

QFileDialog does not set the initialDirectory option in codepaths from
QFileDialog::selectUrl or QFileDialog::selectFile when passing the task
on to the native widget. So KDEPlatformFileDialogHelper has to make sure
itself that info is kept.
Because KDEPlatformFileDialogHelper::initializeDialog() calls
setDirectory(options()->initialDirectory()); as intended, usually during
the show event (and thus resets any otherwise wanted state of the filewidget
it has from previous setup calls via QFileDialog), to whatever value the
initialDirectory option had before, usually the working directory as set
during initialization.

Test Plan

New unit test kfiledialog_unittest testSelectUrl no longer fails with added
code, also behaves now as expected with code e.g. from KUrlRequester.

Diff Detail

Repository
R135 Integration for Qt applications in Plasma
Branch
fixFileDialogDirectoryWithSelectUrl
Lint
No Linters Available
Unit
No Unit Test Coverage
kossebau updated this revision to Diff 9301.Dec 22 2016, 7:09 PM
kossebau retitled this revision from to Fix Plasma-QPA filedialog to show wrong directory with QFileDialog::selectUrl().
kossebau updated this object.
kossebau edited the test plan for this revision. (Show Details)
kossebau added reviewers: Plasma, Frameworks, dfaure.
Restricted Application added a project: Plasma. · View Herald TranscriptDec 22 2016, 7:09 PM
Restricted Application added a subscriber: plasma-devel. · View Herald Transcript
graesslin accepted this revision.Dec 22 2016, 7:20 PM
graesslin added a reviewer: graesslin.
This revision is now accepted and ready to land.Dec 22 2016, 7:20 PM
dfaure accepted this revision.Dec 22 2016, 8:53 PM
dfaure edited edge metadata.
dfaure added inline comments.
src/platformtheme/kdeplatformfiledialoghelper.cpp
365

Should say 5.8.0, the autotest fails for me (without the fix) with current Qt 5.8 git.

kossebau closed this revision.Dec 23 2016, 12:25 AM
kossebau marked an inline comment as done.
dfaure added inline comments.Dec 23 2016, 1:59 PM
src/platformtheme/kdeplatformfiledialoghelper.cpp
368

This does NOT build for me.

qplatformdialoghelper.h:295:5: error: ‘QFileDialogOptions::QFileDialogOptions(const QFileDialogOptions&)’ is private
kdeplatformfiledialoghelper.cpp:368:77: error: within this context
kdeplatformfiledialoghelper.cpp:368:77: error: use of deleted function ‘QFileDialogOptions::QFileDialogOptions(const QFileDialogOptions&)’

Qt 5.8 git, gcc 4.8.

I am not sure why Q_DISABLE_COPY(QFileDialogOptions) is used, sounds like the right fix is to add support for copying and moving to these classes in Qt; but short term this might mean doing the copy by hand (calling 20 setters, sucks). It is curious however that it built for you?

kossebau added inline comments.Dec 23 2016, 2:32 PM
src/platformtheme/kdeplatformfiledialoghelper.cpp
368

Seems the code needs to be adapted to have a variant for the changes introduced by this commit:
http://code.qt.io/cgit/qt/qtbase.git/commit/src/gui/kernel/qplatformdialoghelper.h?id=1a421248396e4b2bdc9ff3ebb63b1edf41c93474
so be for that version

QSharedPointer<QFileDialogOptions> opt = options()->clone();

Could you give that a try? I only have Qt from my distro packages, which is Qt 5.7.0

I am not used to browsing of Qt branches and sadly cannot spot from http://code.qt.io/cgit/qt/qtbase.git/log/src/gui/kernel/qplatformdialoghelper.h at which version this is added.

git log says this is qtbase commit 1a42124, from before v5.8.0-alpha1.
So I'll check for 5.8 and use clone, thanks for the information.

Okay, thanks for fixing for Qt 5.8. Cherry-picked your commit also for the Plasma/5.8 branch now for upcoming Plasma 5.8.4 release, given Plasma 5.9.0 will only appear after Qt 5.8.0 (by schedules at least), so chances are people will want to run 5.8 with 5.8 :)