RFC: Official way to Move to Trash

Hi

While working on adding a “Move to Trash” feature to DiskUsage contextual menu, I’m started to wonder what’s the official way for third party apps to implement a “Move to Trash” feature of files and/or directories?

Should they do themselves, locating the trash folder for the volume on which these entry_ref are located and move them there, adding the “_trk/original_path” attribute so Tracker could support its “Restore” feature ?

Or should it be by sending a Ttrs message to Tracker, to delegate this task to Tracker?

I think it’ll better if Haiku have an official way to do that, so every apps will do the same way and won’t have to bother if they forgot something that Tracker will needs etc.

In a way, the same could also be about deleting files/directories.

Could it be part of libtracker.so API ? Or did I miss it, as it’s already there?

4 Likes

Trash should probably be interacted with via BMessage to Tracker or an API call to a system library, rather than apps rolling their own ways to do it.

Of the two, having a library function seems best to me.

3 Likes

I would rather have an api/call that talks with the roster, than with tracker. But other than this it makes sense. (I consider deskbar and tracker to be user replaceable, so I don’t want to fit too much crucial apis into tracker)

1 Like

BFilePanel and others are already crucial APIs in libtracker.so. Functionally any replacement for Tracker will have to replace various public APIs it provides. I don’t think there’s a problem with this, really, and I don’t think it’s a reason to shy away from having more public APIs in Tracker when it makes sense.

However, in this case, I don’t think it makes sense, and this should probably be a function of the Storage Kit, if anything.

I don’t know of anything in the public API, however we do have a trash CLI tool that can do this at least.

It looks like MediaPlayer also implements its own “move to trash” functionality, so there’s another instance of something that should be consolidated once we add a public API.

I guess Move To Trash could be added to Storage Kit indeed. It’s quite immediate as actually it’s juts moving node from a volume into a volume local “Trash” folder at root of that volume and write one attribute.

But for a Delete (actual delete), in particular directories and their content, then it’s far less immediate, and in such case it will make sense that the end user will see that the deletion task is currently in progress, something that Tracker does, while the storage kit has no UI, it’s the job of libtracker.so

So maybe the front API for both MoveToTrash() and DeleteDirectory() should be moved to libtracker.so to respect that separation between non-UI storage kit and the UI, which depends on the current Files Manager app is running, and if ever it’s an alternative to Tracker, it already have to support libtracker.so current API for BFilePanel anyway.

libtracker.so is defacto the API between apps and “File Manager” app.

1 Like

Indeed. These are already things that should be moved out of tracker imo. I recognize some apis can’t be moved out because of backwards compat, but there should be new replacements that simply work differently. For example we should add a filepanel like android or iOS has, the calling app never gets any file descriptors until the user picks one, only then it gets one. This can be used to then make most apps not need permission to acces “the entire disk”. I think even while providing backwards compat we can mark some ELF files as “uses new security apis” and reject loading some stuff or granting access to files implicitly.

1 Like

The “official” way to move files to Trash is to send a ‘Ttrs’ message to Tracker using the private API defined in tracker_private.h. That’s how Media Player used to Trash playlist files but we got rid of that ability in Media Player. I also added a constant for ‘Tres’ to tracker_private.h for if you’d like to restore the trashed file.

But why? What would the point be?

Sure, but that doesn’t mean it can’t also be part of libtracker. Or any other library for that matter. This sounds like an unrelated new feature.

It looks to me like it still has code to do this and it just does it directly without sending messages?

When I implemented command-less shortcuts and plain old delete to remove a playlist item from Media Player I had initially preserved the Move to Trash shortcut as well. However I was told we didn’t need that one, just the remove playlist item shortcut, so the Move to Trash shortcut is now gone from Media Player. But when the shortcut did exist it used the tracker_private.h constant to Trash the file. So that’s the closest we have to an official method to Trash a file that we have.

Considering the case of “small ipc” stuff, these dialogs would actually be opened by a server (if wanted by utilizing libtracker.so)
but the clients of that server should not use or need libtracker directly, they would instead get a very small ipc-based api/lib for this. (would make more sense in libbe or so, to me. unless we want to make libraries smaller)