helloSystem / Filer

A file manager that can also render the desktop
GNU General Public License v2.0
32 stars 8 forks source link

Support "show in file manager" operations #15

Open probonopd opened 4 years ago

probonopd commented 4 years ago

User story: When I select "show in folder" for a download in a browser, then not only the Downloads folder should open but also the downloaded file should be selected.

Looks like GNOME and KDE use https://www.freedesktop.org/wiki/Specifications/file-manager-interface/, org.freedesktop.FileManager1 DBus name and the /org/freedesktop/FileManager1 object path.

And e.g., Chromium implements it: https://chromium.googlesource.com/chromium/src/+/master/chrome/browser/platform_util_linux.cc

Reference: https://github.com/probonopd/go-appimage/issues/12

This was also requested upstream.

probonopd commented 4 years ago

https://github.com/linuxdeepin/dde-file-manager/search?q=dbusfilemanager1 seems to be relatively straightforward.

probonopd commented 4 years ago

Nautilus implements it, XFCE file manager doesn't.

image

grahamperrin commented 3 years ago

… also (for example) this Open folder button in multimedia/simplescreenrecorder:

image

Other non-browser apps affected by this issue include:

probonopd commented 3 years ago

SSR is using https://doc.qt.io/qt-5/qdesktopservices.html#openUrl

https://github.com/MaartenBaert/ssr/blob/5f50ceff93cbdc1eab8ad09af880f5b8ffb28702/src/GUI/PageDone.cpp#L54-L57

[static]bool QDesktopServices::openUrl(const QUrl &url) Opens the given url in the appropriate Web browser for the user's desktop environment, and returns true if successful; otherwise returns false.

If the URL is a reference to a local file (i.e., the URL scheme is "file") then it will be opened with a suitable application instead of a Web browser.

I think this is not about "show in file manager", and is not using /org/freedesktop/FileManager1 -- "show in file manager" highlights the file in question in the file manager.

grahamperrin commented 3 years ago

Thanks … with KDE Plasma on FreeBSD 14.0-CURRENT, the Open folder button opens the folder that contains the screen recording in a new tab in Dolphin.

Do you need a separate issue for applications that should show the folder but not select the file?

probonopd commented 3 years ago

the Open folder button opens the folder that contains the screen recording in a new tab in Dolphin.

Yes, but this ticket is about applications being able to not only open the folder but also select the file in the file manager. Filer does not implement the protocol needed for this yet.

Do you need a separate issue for applications that should show the folder but not select the file?

Not yet. This stuff is expected to work only once we have a proper "open with" database/implementation.

probonopd commented 3 years ago

Looks like @Ashish-Bansal had sent a patch for KDE Dolphin that implements this.

https://phabricator.kde.org/source/dolphin/browse/master/src/dbusinterface.cpp

Can we port this to Filer? Possibly somewhere around

https://github.com/helloSystem/Filer/blob/7824dea7916a27a0f6d87616178292e0847d930c/src/application.cpp#L88

probonopd commented 3 years ago

Did I ever mention that I find D-Bus way too complicated? ;-)

Added https://github.com/helloSystem/Filer/commit/4c1f261220f9d0993b219c32f57a929aec753b80

But the wrong methods get exported to D-Bus under the org.freedesktop.FileManager1 service as shown by QDBusViewer below:

All these things we were already exporting under the D-Bus org.filer.Filer Service. But under the org.freedesktop.FileManager1 we want to export the methods needed by the File Manager DBus Interface:

image

In my personal opinion, D-Bus being too complicated starts right with the fact that there is org.freedesktop.FileManager1 and /org/freedesktop/FileManager1 and that the two are not one and the same. As we can see, this complicates things immensely because now one needs to ensure (how?) that /org/freedesktop/FileManager1 (and only it) actually gets published under org.freedesktop.FileManager1. Why?

probonopd commented 3 years ago

What I seem to be missing entirely is how to tell Qt "publish the Qt method DBusInterface::ShowFolders(const QStringList& uriList, const QString& startUpId) as the D-Bus method ShowFolders under /org/freedesktop/FileManager1 under org.freedesktop.FileManager1. Exactly there and only there.

probonopd commented 3 years ago

Thanks @zyga for the following explanation:

I don't know Qt but it's fairly simple if you think about it the following way.

Maybe if I meditate long enough over it, then one day I will understand and appreciate the concepts behind D-Bus ;-)

probonopd commented 3 years ago

This works:

gdbus call --session --dest org.freedesktop.FileManager1 --object-path /org/freedesktop/FileManager1 --method org.freedesktop.FileManager1.ShowItems '["file:///Applications"]' ""

It will open a Filer window at / and highlight the Applications folder therein.

Thanks @mszoek.

probonopd commented 1 year ago

Looks like ShowFolders is not implemented here yet.

https://github.com/helloSystem/Filer/blob/5fc509ad04ba7f51e3af9c16deeaac9fe24f3844/src/application.cpp#L692-L694

Causes:

It is implemented correctly in https://github.com/probonopd/Filer