Adding files to "Recents" using GTK and Vala

Hi, everyone! I’ve been trying to contribute with GNOME Boxes by adding the screenshots that are taken via its UI to the “Recents” section of the file explorer. I looked it up and found RecentManager in the Vala documentation, as well as a few examples of it being used in other projects. Following these examples, I wrote the code below:

Gtk.RecentManager.get_default ().add_item (
    GLib.Filename.to_uri(get_screenshot_filename ())
);

It returns true signalling success, but the file doesn’t actually appear under “Recent”. Does anyone know what’s missing?

Context: the issue I’m trying to solve is #895, and you can checkout my fork of Boxes with the changes I mentioned here.

Context: the issue I’m trying to solve is #895, and you can checkout my fork of Boxes with the changes I mentioned here .

get_screenshot_filename returns a new name for a screenshot file every time you call it.
So the filenname you pass to add_item is not the file just saved, but something else and it doesn’t exist. add_item tries to add some fileinfo to its argument before actually registering it, but fails. This is done asynchronously, hence add_item always returns true.
The solution is to pass the same filename passed to pixbuf.save also to add_item.

1 Like

get_screenshot_filename returns a new name for a screenshot file every time you call it.

Oh, :man_facepalming: :man_facepalming: :man_facepalming:

Good call, thank you! I updated my fork with your suggestion (storing and using the same output of get_screenshot_filename for the same screenshot), but it is still not working. I wonder if this has something to do with flatpak and GNOME Builder sandboxing.

This topic was automatically closed 45 days after the last reply. New replies are no longer allowed.