Class RecentManager

All Implemented Interfaces:
Proxy

@Generated("org.javagi.JavaGI") public class RecentManager extends GObject

Manages and looks up recently used files.

Each recently used file is identified by its URI, and has meta-data associated to it, like the names and command lines of the applications that have registered it, the number of time each application has registered the same file, the mime type of the file and whether the file should be displayed only by the applications that have registered it.

The recently used files list is per user.

GtkRecentManager acts like a database of all the recently used files. You can create new GtkRecentManager objects, but it is more efficient to use the default manager created by GTK.

Adding a new recently used file is as simple as:

GtkRecentManager *manager;

manager = gtk_recent_manager_get_default ();
gtk_recent_manager_add_item (manager, file_uri);

The GtkRecentManager will try to gather all the needed information from the file itself through GIO.

Looking up the meta-data associated with a recently used file given its URI requires calling lookupItem(String):

GtkRecentManager *manager;
GtkRecentInfo *info;
GError *error = NULL;

manager = gtk_recent_manager_get_default ();
info = gtk_recent_manager_lookup_item (manager, file_uri, &error);
if (error)
  {
    g_warning ("Could not find the file: %s", error->message);
    g_error_free (error);
  }
else
 {
   // Use the info object
   gtk_recent_info_unref (info);
 }

In order to retrieve the list of recently used files, you can use getItems(), which returns a list of Gtk.RecentInfo.

Note that the maximum age of the recently used files list is controllable through the Gtk.Settings:gtk-recent-files-max-age property.

  • Constructor Details

    • RecentManager

      public RecentManager(MemorySegment address)
      Create a RecentManager instance for the provided memory address.
      Parameters:
      address - the memory address of the native object
    • RecentManager

      public RecentManager()
      Create a new RecentManager.
  • Method Details

    • getType

      public static @Nullable Type getType()
      Get the GType of the RecentManager class.
      Returns:
      the GType
    • getMemoryLayout

      public static MemoryLayout getMemoryLayout()
      The memory layout of the native struct.
      Returns:
      the memory layout
    • asParent

      protected RecentManager asParent()
      Return this instance as if it were its parent type. Comparable to the Java super keyword, but ensures the parent typeclass is also used in native code.
      Overrides:
      asParent in class GObject
      Returns:
      the instance as if it were its parent type
    • getDefault

      public static RecentManager getDefault()
      Gets a unique instance of GtkRecentManager that you can share in your application without caring about memory management.
      Returns:
      A unique GtkRecentManager. Do not ref or unref it.
    • addFull

      public boolean addFull(String uri, RecentData recentData)

      Adds a new resource, pointed by uri, into the recently used resources list, using the metadata specified inside the GtkRecentData passed in recentData.

      The passed URI will be used to identify this resource inside the list.

      In order to register the new recently used resource, metadata about the resource must be passed as well as the URI; the metadata is stored in a GtkRecentData, which must contain the MIME type of the resource pointed by the URI; the name of the application that is registering the item, and a command line to be used when launching the item.

      Optionally, a GtkRecentData might contain a UTF-8 string to be used when viewing the item instead of the last component of the URI; a short description of the item; whether the item should be considered private - that is, should be displayed only by the applications that have registered it.

      Parameters:
      uri - a valid URI
      recentData - metadata of the resource
      Returns:
      true if the new item was successfully added to the recently used resources list, false otherwise
    • addItem

      public boolean addItem(String uri)

      Adds a new resource, pointed by uri, into the recently used resources list.

      This function automatically retrieves some of the needed metadata and setting other metadata to common default values; it then feeds the data to addFull(String, RecentData).

      See addFull(String, RecentData) if you want to explicitly define the metadata for the resource pointed by uri.

      Parameters:
      uri - a valid URI
      Returns:
      true if the new item was successfully added to the recently used resources list
    • getItems

      public List<RecentInfo> getItems()
      Gets the list of recently used resources.
      Returns:
      a list of newly allocated GtkRecentInfo objects. Use RecentInfo.unref() on each item inside the list, and then free the list itself using g_list_free().
    • hasItem

      public boolean hasItem(String uri)
      Checks whether there is a recently used resource registered with uri inside the recent manager.
      Parameters:
      uri - a URI
      Returns:
      true if the resource was found, false otherwise
    • lookupItem

      public @Nullable RecentInfo lookupItem(String uri) throws GErrorException
      Searches for a URI inside the recently used resources list, and returns a GtkRecentInfo containing information about the resource like its MIME type, or its display name.
      Parameters:
      uri - a URI
      Returns:
      a GtkRecentInfo containing information about the resource pointed by uri, or null if the URI was not registered in the recently used resources list. Free with RecentInfo.unref().
      Throws:
      GErrorException - see GError
    • moveItem

      public boolean moveItem(String uri, @Nullable String newUri) throws GErrorException

      Changes the location of a recently used resource from uri to newUri.

      Please note that this function will not affect the resource pointed by the URIs, but only the URI used in the recently used resources list.

      Parameters:
      uri - the URI of a recently used resource
      newUri - the new URI of the recently used resource, or null to remove the item pointed by uri in the list
      Returns:
      true on success
      Throws:
      GErrorException - see GError
    • purgeItems

      public int purgeItems() throws GErrorException
      Purges every item from the recently used resources list.
      Returns:
      the number of items that have been removed from the recently used resources list
      Throws:
      GErrorException - see GError
    • removeItem

      public boolean removeItem(String uri) throws GErrorException
      Removes a resource pointed by uri from the recently used resources list handled by a recent manager.
      Parameters:
      uri - the URI of the item you wish to remove
      Returns:
      true if the item pointed by uri has been successfully removed by the recently used resources list, and false otherwise
      Throws:
      GErrorException - see GError
    • changed

      protected void changed()
    • onChanged

      Emitted when the current recently used resources manager changes its contents.

      This can happen either by calling addItem(String) or by another application.

      Parameters:
      handler - the signal handler
      Returns:
      a signal handler ID to keep track of the signal connection
      See Also:
    • emitChanged

      public void emitChanged()
      Emits the "changed" signal. See onChanged(RecentManager.ChangedCallback).
    • builder

      public static RecentManager.Builder<? extends RecentManager.Builder> builder()
      A RecentManager.Builder object constructs a RecentManager with the specified properties. Use the various set...() methods to set properties, and finish construction with RecentManager.Builder.build().
      Returns:
      the builder object