Fix desktop link to file or directory
ClosedPublic

Authored by hoffmannrobert on Apr 2 2019, 9:43 AM.

Details

Summary

KUrlRequester: Show a popup to select between File and Directory before displaying the file dialog.

Test Plan

Right click onto desktop, select 'Create new' and then
'Basic link to file or directory' or 'Link to Location (URL)'.
Click the file selection icon. A popup is displayed.

If 'File' is selected, a file dialog is displayed, showing files and directories, allowing the selection of a file.
If 'Directory' is selected, a file dialog is displayed, showing only directories, allowing the selection of a directory.

Without the patch, no popup is displayed, only directories are shown in the file dialog and only a directory can be selected.

BUG: 357171
FIXED-IN: 5.59

Diff Detail

Repository
R241 KIO
Lint
Automatic diff as part of commit; lint not applicable.
Unit
Automatic diff as part of commit; unit tests not applicable.
hoffmannrobert created this revision.Apr 2 2019, 9:43 AM
Restricted Application added a project: Frameworks. · View Herald TranscriptApr 2 2019, 9:43 AM
Restricted Application added a subscriber: kde-frameworks-devel. · View Herald Transcript
hoffmannrobert requested review of this revision.Apr 2 2019, 9:43 AM
ngraham requested changes to this revision.Apr 2 2019, 4:05 PM
ngraham added a subscriber: ngraham.

This doesn't work. Try creating a symlink to a directory. In the file picker dialog, the Open button doesn't work.

See https://bugs.kde.org/show_bug.cgi?id=357171 for more context.

This revision now requires changes to proceed.Apr 2 2019, 4:05 PM
  • Add file/directory selection
hoffmannrobert retitled this revision from Fix desktop link filter to Fix desktop link to file or directory.Apr 4 2019, 10:32 AM
hoffmannrobert edited the summary of this revision. (Show Details)
hoffmannrobert edited the test plan for this revision. (Show Details)

This doesn't work. Try creating a symlink to a directory. In the file picker dialog, the Open button doesn't work.

See https://bugs.kde.org/show_bug.cgi?id=357171 for more context.

Yes, sorry. But this works.

Interesting solution. However the directory use case still doesn't work. If I use the directory chooser to choose /home/nate/Pictures, the path fiels says /home/nate/ and the file name field says file:///home/nate/

You need to double click the directory, so you enter the directory, then click Open.

Hmm, that's confusing. I would recommend using the decided directory chooser rather than rolling your own.

Is there a different decided directory chooser than QFileDialog?

It's the way QFileDialog handles directories. If you click a directory, it not added to the selection, other than a file, which is. So, if QFileDialog::selectedUrls() is called, nothing is in the selection and the current path is returned.

  • Set option QFileDialog::ShowDirsOnly after setting file mode

Thanks, I've learned that QFileDialog only creates a well behaving directory chooser, if the QFileDialog::ShowDirsOnly option is set to true _after_ having set the fileMode to QFileDialog::Directory. If you do it the other way around, it doesn't add directories to the selection.

Now it's necessary to delete an already created file dialog and make a new one, if you change your mind and choose the file chooser after having selected a directory chooser, or vice versa. Otherwise it would crash.

Thanks, this works well now. The UI and behavior seem sane, and I've just got a few code changes requested:

src/widgets/kurlrequester.cpp
470

This should probably be folder-new for visual consistency with the file icon you've chosen

474

This feels overly clever and fragile. The more typical approach would be to connect the actions' triggered signals to lambda functions that execute the code that you currently have in the if/else blocks below.

dfaure requested changes to this revision.Apr 6 2019, 5:05 PM
dfaure added inline comments.
src/widgets/kurlrequester.cpp
291

I don't understand what this variable means. What's a DirFile? ;)
Reading the rest I guess this means DirOrFile, ok, but what else is there?

481

coding style: join with previous line

486

coding style: join with previous line

This revision now requires changes to proceed.Apr 6 2019, 5:05 PM
  • Use lambdas and helper
hoffmannrobert marked 5 inline comments as done.Apr 7 2019, 8:05 AM
hoffmannrobert added inline comments.
src/widgets/kurlrequester.cpp
291

Ok, renamed. This variable is there to remember that the mode initially was set to 'KFile::File | KFile::Directory'. Without, you couldn't change your mind and select 'Directory' after selecting 'File' or vice versa.

dfaure added a comment.Apr 7 2019, 8:09 AM

Ah! So "DirOrFile" means the user can see and choose both directories and files? Maybe call this ModeWasDirAndFile. I kept reading this was "mode was dirs or mode was files" (which made me say "what else is there?"), while now I think I understand it means "mode was (both dir+files)", right?

Won't this additional popup be annoying for other applications using KUrlRequester? I'm afraid that one use case where it makes sense, pollutes other use cases.
Can you confirm it only shows up when saving, and when the mode is "dir+files"?

src/widgets/kurlrequester.cpp
255

I'd call this createFileDialog()

hoffmannrobert marked an inline comment as done.
  • Renames

Ah! So "DirOrFile" means the user can see and choose both directories and files? Maybe call this ModeWasDirAndFile. I kept reading this was "mode was dirs or mode was files" (which made me say "what else is there?"), while now I think I understand it means "mode was (both dir+files)", right?

Yes. In KDE4, with KFileDialog, this used to work, KFileDialog can select both dirs and files, but QFileDialog can't.

Won't this additional popup be annoying for other applications using KUrlRequester? I'm afraid that one use case where it makes sense, pollutes other use cases.
Can you confirm it only shows up when saving, and when the mode is "dir+files"?

This popup only shows up if

((fileDialogMode & KFile::Directory) && (fileDialogMode & KFile::File))

or ModeWasDirAndFile, which can only be set to true if mode previously was

((fileDialogMode & KFile::Directory) && (fileDialogMode & KFile::File))

In this case there always needs to be a decision between File and Directory before the QFileDialog is created, because QFileDialog cannot be set up to be a chooser for both at the same time.

All use cases which want to get an url from KUrlRequester and set the mode to both KFile::Directory and KFile::File must get the user's decision before the QFileDialog is shown.

AcceptMode is independent from this, it can be both AcceptOpen and AcceptSave.

dfaure accepted this revision.Apr 7 2019, 11:02 AM

OK. So a likely fallback of this patch is that some applications which are (possibly erroneously) setting Dir+File as mode (in order to select just a file, for instance), will now bother the user with a popup. If that happens, the applications will need to be fixed to pass just File.

I just tagged 5.57.0-rc1, so this can go in, it will give us one month to test it.

Thanks, I've learned that QFileDialog only creates a well behaving directory chooser, if the QFileDialog::ShowDirsOnly option is set to true _after_ having set the fileMode to QFileDialog::Directory. If you do it the other way around, it doesn't add directories to the selection.

As a side note (not directly related to the change being discussed here): I think this is a bug in kio/plasma-integration, since the way this needs to be done with the native Plasma file dialog is inconsistent with what the non-native Qt dialog does, s. https://bugs.kde.org/show_bug.cgi?id=406464 .

ngraham accepted this revision.May 22 2019, 4:14 PM

Oops, sorry I lost track of this. LGTM now. Let's get it in.

This revision is now accepted and ready to land.May 22 2019, 4:14 PM

Because it has new strings though, I'm afraid this is 5.60 material because we're past the 5.59 string freeze. Making a note on my calendar so it doesn't get lost again...

bruns added a subscriber: bruns.May 22 2019, 10:44 PM

I think this can go in now, as the i18n strings are not actually new - grep src/widgets/fileundomanager.cpp for i18n("File") and i18n("Directory").

Ah, that's true.

ngraham edited the test plan for this revision. (Show Details)May 24 2019, 4:46 AM
This revision was automatically updated to reflect the committed changes.