Gtk.RecentManager


Gtk.RecentManager — Managing recently used files

Object Hierarchy:

    GObject
    ╰── Gtk.RecentManager

Functions:

Description:

Gtk.RecentManager provides a facility for adding, removing and looking 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.

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

Adding a new recently used file is as simple as:

manager = Gtk.RecentManager()
manager.add_item(file_uri)

The Gtk.RecentManager 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 Gtk.RecentManager::lookup_item():

    manager = Gtk.RecentManager()    
    info = manager.lookup_item(file_uri)

In order to retrieve the list of recently used files, you can use Gtk.RecentManager::get_items(), which returns a list of GtkRecentInfo-structs.

manager = Gtk.RecentManager()    
for item in manager.get_items():
    print(item)

A Gtk.RecentManager is the model used to populate the contents of one, or more Gtk.RecentChooser implementations.

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

Recently used files are supported since GTK+ 2.10.


Function Details:

new()

new () -> Gtk.RecentManager

Creates a new recent manager object. Recent manager objects are used tohandle the list of recently used resources. A Gtk.RecentManager objectmonitors the recently used resources list, and emits the “changed” signaleach time something inside the list changes. Gtk.RecentManager objects are expensive: be sure to create them only whenneeded. You should use Gtk.RecentManager:get_default() instead.

  • Returns: A newly created Gtk.RecentManager object

  • Since: 2.10


get_default()

get_default () -> Gtk.RecentManager

Gets a unique instance of Gtk.RecentManager, that you can sharein your application without caring about memory management.

  • Returns: A unique Gtk.RecentManager. Do not ref orunref it.

  • Since: 2.10


add_item()

add_item (self, uri:str) -> bool

Adds a new resource, pointed by uri, into the recently usedresources list. This function automatically retrieves some of the neededmetadata and setting other metadata to common default values;it then feeds the data to Gtk.RecentManager:add_full(). See Gtk.RecentManager:add_full() if you want to explicitlydefine the metadata for the resource pointed by uri.

  • Returns: True if the new item was successfully addedto the recently used resources list

  • Since: 2.10


add_full()

add_full (self, uri:str, recent_data:Gtk.RecentData) -> bool

Adds a new resource, pointed by uri, into the recently usedresources list, using the metadata specified inside theGtk.RecentData passed in recent_data. The passed URI will be used to identify this resource inside thelist. In order to register the new recently used resource, metadata aboutthe resource must be passed as well as the URI; the metadata isstored in a Gtk.RecentData, which must contain the MIMEtype of the resource pointed by the URI; the name of the applicationthat is registering the item, and a command line to be used whenlaunching the item. Optionally, a Gtk.RecentData might contain a UTF-8 stringto be used when viewing the item instead of the last component ofthe URI; a short description of the item; whether the item shouldbe considered private - that is, should be displayed only by theapplications that have registered it.

  • Returns: True if the new item was successfully added to therecently used resources list, FALSE otherwise

  • Since: 2.10


remove_item()

remove_item (self, uri:str) -> bool

Removes a resource pointed by uri from the recently used resourceslist handled by a recent manager.

  • Returns: True if the item pointed by urihas been successfullyremoved by the recently used resources list, and FALSE otherwise

  • Since: 2.10


lookup_item()

lookup_item (self, uri:str) -> Gtk.RecentInfo

Searches for a URI inside the recently used resources list, andreturns a Gtk.RecentInfo containing informations about the resourcelike its MIME type, or its display name.

  • Returns: a Gtk.RecentInfo containing informationabout the resource pointed by uri, or None if the URI wasnot registered in the recently used resources list. Free with`Gtk.RecentInfo:unref()`.

  • Since: 2.10


has_item()

has_item (self, uri:str) -> bool

Checks whether there is a recently used resource registeredwith uri inside the recent manager.

  • Returns: True if the resource was found, FALSE otherwise

  • Since: 2.10


move_item()

move_item (self, uri:str, new_uri:str=None) -> bool

Changes the location of a recently used resource from uri to new_uri. Please note that this function will not affect the resource pointedby the URIs, but only the URI used in the recently used resources list.

  • Returns: True on success

  • Since: 2.10


get_items()

get_items (self) -> list

Gets the list of recently used resources.

  • Returns: a list ofnewly allocated Gtk.RecentInfo objects. Use`Gtk.RecentInfo:unref()on each item inside the list, and thenfree the list itself usingg_list_free()`.

  • Since: 2.10


purge_items()

purge_items (self) -> int

Purges every item from the recently used resources list.

  • Returns: the number of items that have been removed from therecently used resources list

  • Since: 2.10


results matching ""

    No results matching ""