Fix QFileDialog::selectUrl() setting initial directory
ClosedPublic

Authored by muhlenpfordt on Jun 29 2018, 10:41 AM.

Details

Summary

In D4193 setting the initial directory to the given URL when using
QFileDialog::selectUrl() was removed.

  • This causes FileOpen to not start in the current directory but in Gwenviews initial or last set path. In addition, due to adding StripTrailingSlash, D9886 caused the file dialog to select the last subfolder as a file instead of entering it. Both problems can be fixed by using QFileDialog::setDirectoryUrl() instead of QFileDialog::selectUrl().
  • The first problem also occurs in FileSave As. Until this issue is fixed in the libraries an additional QFileDialog::setDirectoryUrl() is added as workaround.

FIXED-IN: 18.04.3

Test Plan
  1. Open Gwenview
  2. Use FileOpen or FileSave As
  3. The file dialog should start in the current directory

Diff Detail

Repository
R260 Gwenview
Lint
Automatic diff as part of commit; lint not applicable.
Unit
Automatic diff as part of commit; unit tests not applicable.
muhlenpfordt requested review of this revision.Jun 29 2018, 10:41 AM
muhlenpfordt created this revision.

The behaviour of QFileDialog::selectUrl() seems to have changed between Qt 5.9.1 and Qt 5.9.5.
On an older Kubuntu 17.10 system the initial path is set by QFileDialog::selectUrl() but not on Kubuntu 18.04.
The changed code also works with the older library version.

rkflx added a subscriber: rkflx.Jun 30 2018, 9:49 PM

Thanks for the patch, which fixes the issue for me. However, I'm not yet sure this is the right approach, as it looks more like a workaround.

Would be interesting to know which commit in Qt broke this. FWIW, I see the same issue with Qt 5.11. Starting here in Qt, I ended up in KDE's Bugzilla. Reverting cc064e81c6ed fixes Save As, but not yet Open. That's odd, but I have to stop for today.

rkflx added a comment.Jul 1 2018, 10:21 PM
This comment was removed by rkflx.
rkflx added a comment.Jul 1 2018, 11:35 PM

This comment was removed by rkflx.

(Sorry for that, used an old Gwenview which gave bogus results.)

rkflx added a comment.Jul 7 2018, 11:08 AM

Now looked more into this. Basically, there are three related changes:

  1. Patch to qfiledialog.cpp, which is in Qt since 5.9.5 and 5.11.0. However, stepping through the code shows that this does not make any difference, as in our case both selectFile and selectUrl in QFileDialogPrivate::init return early, with our explicit calls being handled elsewhere.
  2. D4193, which is in plasma-integration. Reverting fixes Save As in Gwenview, and bisecting shows that this breaks the unit test introduced for D3796 (KFileDialog_UnitTest::testSelectUrl, link to failure).
  3. D9886 in Gwenview, which breaks the Open case due to StripTrailingSlash.

Now, what does this mean for your patch?

  • Please change your commit message so that it differentiates between cases #2 and #3, including pointers to what caused the breakage.
  • The change for Open is absolutely fine (unless we want to add back the slash, but I would not recommend that).
  • I'm not too happy with the change for Save As. I'm willing to give it my thumbs-up as a temporary workaround for 18.04.3 if:
    • An appropriate comment is added to the code.
    • The problems with D4193 are fixed afterwards through patches or by working with the author (Alex) or Friedrich. Possibly this means reverting the original commit (so the test in plasma-integration is fixed, and the workaround in Gwenview can be removed), and solving the original problem in Bug 374913 in another way.

Sorry for not being more helpful or if this sounds harsh, but really that's all I got time for (already took me most of last week to untangle all three issues from above) – I hope you can understand :)

muhlenpfordt edited the summary of this revision. (Show Details)

Added comment for Save As dialog

Thanks for diving that deep into this! Looks like a hard piece of work.
Ok with the commit message / comment? Better suggestions always welcome. ;)

rkflx accepted this revision.Jul 9 2018, 10:19 AM

Thanks! LGTM, only one small correction (which is probably my fault, should've been more precise when writing up my findings):

In D4193 setting the initial directory to the given URL when using QFileDialog::selectUrl() was removed.

  • After adjusting the current directory URL in D9886 this causes FileOpen to not start in the current directory but in Gwenviews initial or last set path. This is fixed by using QFileDialog::setDirectoryUrl() instead of QFileDialog::selectUrl().
  • This causes FileOpen to not start in the current directory but in Gwenviews initial or last set path. In addition, due to adding StripTrailingSlash, D9886 caused the file dialog to select the last subfolder as a file instead of entering it. Both problems can be fixed by using QFileDialog::setDirectoryUrl() instead of QFileDialog::selectUrl().
  • The first problem also occurs in […]
This revision is now accepted and ready to land.Jul 9 2018, 10:19 AM
muhlenpfordt edited the summary of this revision. (Show Details)Jul 9 2018, 11:23 AM
  • This causes FileOpen to not start in the current directory but in Gwenviews initial or last set path. In addition, due to adding StripTrailingSlash, D9886 caused the file dialog to select the last subfolder as a file instead of entering it. Both problems can be fixed by using QFileDialog::setDirectoryUrl() instead of QFileDialog::selectUrl().

Thanks for the clarification, I misinterpreted your explanations.

This revision was automatically updated to reflect the committed changes.