Bug 443253

Summary: FTP folder ignores default application to open file
Product: [Applications] dolphin Reporter: Max <maximtsyba>
Component: generalAssignee: Dolphin Bug Assignee <dolphin-bugs-null>
Status: RESOLVED FIXED    
Severity: normal CC: a.samirh78, faure, kde, kfm-devel, linus.kardell, mike, nate, nicolas.fella
Priority: NOR    
Version: 21.08.1   
Target Milestone: ---   
Platform: Other   
OS: Linux   
Latest Commit: Version Fixed In: 21.12.3

Description Max 2021-10-03 11:31:36 UTC
SUMMARY
In network folder (FTP), when I click on files Dolphin always tries to open them in web browser, instead of system default application for this filetype.

STEPS TO REPRODUCE
1. Add FTP folder
2. Try to open file from FTP folder by double clicking on it

OBSERVED RESULT
File is getting open in web browser. Not even the system default one, just random web browser from the installed

EXPECTED RESULT
File should be open in default application for such filetype, configurable in system settings

SOFTWARE/OS VERSIONS
Linux/KDE Plasma: KDE NEON
KDE Plasma Version: 5.22.5
KDE Frameworks Version: 5.86.0
Qt Version: 5.15.3
Dolphin version: 21.08.1
Comment 1 Nicolas Fella 2021-12-06 21:25:53 UTC
*** Bug 446550 has been marked as a duplicate of this bug. ***
Comment 2 Nicolas Fella 2021-12-06 21:28:53 UTC
It looks like it chooses the default app for ftp:// links over the default app for that file type
Comment 3 Nicolas Fella 2021-12-06 21:35:20 UTC
Reproducible using "kioclient5 exec ftp://ftp.slackware.com/debian/README"
Comment 4 Nicolas Fella 2021-12-06 22:05:43 UTC
The problem is somewhat obvious, the best solution isn't.

The relevant Dolphin code is in https://invent.kde.org/system/dolphin/-/blob/master/src/dolphinviewcontainer.cpp#L658

KIO::OpenUrlJob first looks whether the scheme (ftp) is handles by any app and only when that isn't given tries to determine the MIME type.

I see a couple possible options:
1) Dolphin already knows the MIME type. We could resolve the preferred app and use KIO::ApplicationLauncherJob instead. That's probably what the context menu entry does anyway
2) Change OpenUrlJob to prefer determining the mime type over the scheme handler
3) Add API to pass the MIME type from Dolphin to OpenUrlJob and make it use that

David, Ahmad, Kai: thoughts?
Comment 5 Kai Uwe Broulik 2021-12-06 22:15:55 UTC
> 2) Change OpenUrlJob to prefer determining the mime type over the scheme handler

Wouldn't that end us back at the "examining..." situation where we try to figure out how to open the app so it takes a while to open a file?

Maybe it really depends on the type of scheme... for a "browsable" protocol I would expect it to behave like a local folder. Maybe "if (supportslisting) { determine mimetype } else { open with handler }"?

3) Add API to pass the MIME type from Dolphin to OpenUrlJob and make it use that

But yeah, if the mimetype is known and we could save a stat, that would be nice either way.
Comment 6 Nicolas Fella 2021-12-07 18:34:37 UTC
(In reply to Kai Uwe Broulik from comment #5)
> > 2) Change OpenUrlJob to prefer determining the mime type over the scheme handler
> 
> Wouldn't that end us back at the "examining..." situation where we try to
> figure out how to open the app so it takes a while to open a file?
yeah, probably
 
> Maybe it really depends on the type of scheme... for a "browsable" protocol
> I would expect it to behave like a local folder. Maybe "if (supportslisting)
> { determine mimetype } else { open with handler }"?
hmm, interesting idea

> 3) Add API to pass the MIME type from Dolphin to OpenUrlJob and make it use
> that
> 
> But yeah, if the mimetype is known and we could save a stat, that would be
> nice either way.
My concern is that it's a bit magic to have the behavior change this way depending on whether you pass a mimetype or not

I tried implementing option 1), but that breaks running executable scripts (it always opens them in an editor)
Comment 7 Bug Janitor Service 2022-02-03 23:18:38 UTC
A possibly relevant merge request was started @ https://invent.kde.org/system/dolphin/-/merge_requests/343
Comment 8 Nicolas Fella 2022-02-04 11:56:33 UTC
Git commit 3b4676b3871cad5cd0e4695b211581f8db8accd0 by Nicolas Fella.
Committed on 03/02/2022 at 23:18.
Pushed by nicolasfella into branch 'release/21.12'.

Fix opening FTP files in their preferred app

When passing an URL like ftp://foo/bar.txt OpenUrlJob opens it in the default handler for ftp urls, not the one for txt files, which would be more appropriate here

By passing along the mimetype we can change that behavior to what we want

M  +1    -1    src/dolphinviewcontainer.cpp

https://invent.kde.org/system/dolphin/commit/3b4676b3871cad5cd0e4695b211581f8db8accd0
Comment 9 Mike Lothian 2022-02-07 12:48:47 UTC
Would you mind checking if you're seeing the same thing for smb:// files

If I run smplayer smb://path/to/video it works fine, however if I launch from Dolphin - which is just smplayer %U kioexec starts to copy the file rather than streaming
Comment 10 Nicolas Fella 2022-02-07 12:54:58 UTC
(In reply to Mike Lothian from comment #9)
> Would you mind checking if you're seeing the same thing for smb:// files

The problem/fix isn't specific to FTP, in principle it applies to smb too

> If I run smplayer smb://path/to/video it works fine, however if I launch
> from Dolphin - which is just smplayer %U kioexec starts to copy the file
> rather than streaming#
But it does open in smplayer when opening from Dolphin?
Comment 11 Mike Lothian 2022-02-07 13:02:01 UTC
Yes, once it finishes downloading, it does open in smplayer

I'll raise a new bug for this