Bug 436584 - dolphin --select opens the URLs instead of selecting them
Summary: dolphin --select opens the URLs instead of selecting them
Status: RESOLVED FIXED
Alias: None
Product: dolphin
Classification: Applications
Component: general (show other bugs)
Version: 21.04.0
Platform: Arch Linux Linux
: NOR minor
Target Milestone: ---
Assignee: Dolphin Bug Assignee
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2021-05-04 13:49 UTC by the.betrayer64
Modified: 2021-08-02 16:32 UTC (History)
4 users (show)

See Also:
Latest Commit:
Version Fixed In: 21.08


Attachments
Screenshot of how it looks (239.12 KB, image/png)
2021-05-04 13:49 UTC, the.betrayer64
Details

Note You need to log in before you can comment on or make changes to this bug.
Description the.betrayer64 2021-05-04 13:49:24 UTC
Created attachment 138143 [details]
Screenshot of how it looks

SUMMARY
There is a way to start Dolphin from console, for example.
There is a key "--select" in dolphin command which is supposed to select file paths that are following that command.

Let's say I have a file /home/user/Downloads/picture.jpg
If I type in console "dolphin --select /home/user/Downloads/picture.jpg" AND have a running instance of Dolphin everything is going to work just perfect.
But if I close all instances  of Dolphin on my PC and do the same console launch
the same command - then DOlphin is going to open a file as an empty folder, and, also open that file in gwenview

You might ask "why do you even need to launch Dolphin from console"? My answer is that I'm trying to make a "Reveal in Finder" kind of feature in my program, so I'm launching it from the following code:

QProcess proc;
proc.startDetached("dolphin", QStringList() << "--select" << info.canonicalFilePath());

STEPS TO REPRODUCE
1. Close all Dolphin instances
2. Type in console "dolphin --select ~/.bashrc"

OBSERVED RESULT
Dolphin is going to open .bashrc file as if was an empty folder and also run kate on this file

EXPECTED RESULT
Dolphin would open home folder and select there .bashrc file if it's visible

SOFTWARE/OS VERSIONS
Windows: 
macOS: 
Linux/KDE Plasma: Archlinux
(available in About System)
KDE Plasma Version: 5.21.04
KDE Frameworks Version: 5.81.0
Qt Version: 5.15.2

ADDITIONAL INFORMATION
Comment 1 Nate Graham 2021-05-04 14:12:12 UTC
(In reply to the.betrayer64 from comment #0)
> You might ask "why do you even need to launch Dolphin from console"? My
> answer is that I'm trying to make a "Reveal in Finder" kind of feature in my
> program, so I'm launching it from the following code:
> 
> QProcess proc;
> proc.startDetached("dolphin", QStringList() << "--select" <<
> info.canonicalFilePath());
If you're using KDE Frameworks (specifically, KIO), you can include KIO/OpenFileManagerWindowJob and do:

KIO::highlightInFileManager({QUrl(info.canonicalFilePath())})

Does that suffice?
Comment 2 the.betrayer64 2021-05-04 15:39:04 UTC
I was trying to do a DE agnostic (In reply to Nate Graham from comment #1)
> (In reply to the.betrayer64 from comment #0)
> > You might ask "why do you even need to launch Dolphin from console"? My
> > answer is that I'm trying to make a "Reveal in Finder" kind of feature in my
> > program, so I'm launching it from the following code:
> > 
> > QProcess proc;
> > proc.startDetached("dolphin", QStringList() << "--select" <<
> > info.canonicalFilePath());
> If you're using KDE Frameworks (specifically, KIO), you can include
> KIO/OpenFileManagerWindowJob and do:
> 
> KIO::highlightInFileManager({QUrl(info.canonicalFilePath())})
> 
> Does that suffice?

This works, thank you so much!
But it has a drawback - usually Dolphin, as a really nice app, remembers opened folders in tabs. Once I call "KIO::highlightInFileManager({QUrl(info.canonicalFilePath())})" on closed dolphin - all opened tabs are forgotten. It doesn't bother me personally, but it seems like something fishy.
Comment 3 Nate Graham 2021-05-04 15:42:51 UTC
That is not supposed to happen and I specifically added code to prevent it and cannot reproduce the issue. Sounds like a bug. If it's 100% reproducible with default dolphin settings (just in case you forgot you changed something), please file a new bug report. Thanks!
Comment 4 the.betrayer64 2021-05-04 15:56:00 UTC
It reproduces on my machine: usually it store tabs, but after that call they are clean. I don't remember changing anything in settings about that, and I also might be several days behind the official Archlinux repos, so, if it's something you mended recently - I might not yet have that.
I sure can record a video, but not sure if it hepls, is there something I can check in my versions or settings?

Also, switching the topic, is that "--select" CLI key is something that have chances to be fixed?
Comment 5 Nate Graham 2021-05-04 16:10:12 UTC
Can you file a separate bug about the tab issue?
Comment 6 Nate Graham 2021-05-04 16:18:57 UTC
Anyway, can confirm the original bug.
Comment 7 the.betrayer64 2021-05-04 20:55:06 UTC
Thank you!

Sure, i can open another one! Just lemme test on a fresh update
Comment 8 Arnaud 2021-07-24 20:37:45 UTC
This is still happening in KDE neon Unstable Edition. The difference is that the --select command always opens a new instance, so it always opens a new file as an empty folder and opens the related app.

As an alternative, I can use the following command to do the same:

dbus-send --dest=org.freedesktop.FileManager1 --type=method_call /org/freedesktop/FileManager1 org.freedesktop.FileManager1.ShowItems array:string:"/path/to/file" string:""
Comment 9 Jordan 2021-07-30 20:14:56 UTC
It seems this issue specifically occurs when the session is restored from a previous session. If starting a new session, the files/folders are selected properly.
Comment 10 Bug Janitor Service 2021-08-01 00:55:57 UTC
A possibly relevant merge request was started @ https://invent.kde.org/system/dolphin/-/merge_requests/251
Comment 11 Jordan 2021-08-02 16:30:28 UTC
Git commit f190ae1cf8fc1c1bf0d87899a84f796a3e473032 by Jordan Bucklin.
Committed on 01/08/2021 at 22:54.
Pushed by ngraham into branch 'release/21.08'.

Fix how --select treats files

Previously, when passing file URLs with the --select option,
Dolphin would open the file in its corresponding application, as
well as opening an empty tab in Dolphin as if the file were a
directory. This happens specifically when trying to restore a
session.

This commit prevents Dolphin from opening a file in an application
and from opening an empty tab while passing the --select option,
and selects the URLs instead.

M  +5    -1    src/main.cpp

https://invent.kde.org/system/dolphin/commit/f190ae1cf8fc1c1bf0d87899a84f796a3e473032