CtkRecentManager

CtkRecentManager — Managing recently used files

Functions

CtkRecentManager * ctk_recent_manager_new ()
CtkRecentManager * ctk_recent_manager_get_default ()
gboolean ctk_recent_manager_add_item ()
gboolean ctk_recent_manager_add_full ()
gboolean ctk_recent_manager_remove_item ()
CtkRecentInfo * ctk_recent_manager_lookup_item ()
gboolean ctk_recent_manager_has_item ()
gboolean ctk_recent_manager_move_item ()
GList * ctk_recent_manager_get_items ()
gint ctk_recent_manager_purge_items ()
CtkRecentInfo * ctk_recent_info_ref ()
void ctk_recent_info_unref ()
const gchar * ctk_recent_info_get_uri ()
const gchar * ctk_recent_info_get_display_name ()
const gchar * ctk_recent_info_get_description ()
const gchar * ctk_recent_info_get_mime_type ()
GDateTime * ctk_recent_info_get_added ()
GDateTime * ctk_recent_info_get_modified ()
GDateTime * ctk_recent_info_get_visited ()
gboolean ctk_recent_info_get_private_hint ()
gboolean ctk_recent_info_get_application_info ()
gchar ** ctk_recent_info_get_applications ()
gchar * ctk_recent_info_last_application ()
gboolean ctk_recent_info_has_application ()
GAppInfo * ctk_recent_info_create_app_info ()
gchar ** ctk_recent_info_get_groups ()
gboolean ctk_recent_info_has_group ()
GdkPixbuf * ctk_recent_info_get_icon ()
GIcon * ctk_recent_info_get_gicon ()
gchar * ctk_recent_info_get_short_name ()
gchar * ctk_recent_info_get_uri_display ()
gint ctk_recent_info_get_age ()
gboolean ctk_recent_info_is_local ()
gboolean ctk_recent_info_exists ()
gboolean ctk_recent_info_match ()

Properties

char * filename Read / Write / Construct Only
int size Read

Signals

void changed Run First

Types and Values

Object Hierarchy

    GObject
    ╰── CtkRecentManager

Includes

#include <ctk/ctk.h>

Description

CtkRecentManager 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 CtkRecentManager acts like a database of all the recently used files. You can create new CtkRecentManager objects, but it is more efficient to use the default manager created by CTK+.

Adding a new recently used file is as simple as:

1
2
3
4
CtkRecentManager *manager;

manager = ctk_recent_manager_get_default ();
ctk_recent_manager_add_item (manager, file_uri);

The CtkRecentManager 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 ctk_recent_manager_lookup_item():

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
CtkRecentManager *manager;
CtkRecentInfo *info;
GError *error = NULL;

manager = ctk_recent_manager_get_default ();
info = ctk_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
   ctk_recent_info_unref (info);
 }

In order to retrieve the list of recently used files, you can use ctk_recent_manager_get_items(), which returns a list of CtkRecentInfo-structs.

A CtkRecentManager is the model used to populate the contents of one, or more CtkRecentChooser implementations.

Note that the maximum age of the recently used files list is controllable through the “ctk-recent-files-max-age” property.

Recently used files are supported since CTK+ 2.10.

Functions

ctk_recent_manager_new ()

CtkRecentManager *
ctk_recent_manager_new (void);

Creates a new recent manager object. Recent manager objects are used to handle the list of recently used resources. A CtkRecentManager object monitors the recently used resources list, and emits the “changed” signal each time something inside the list changes.

CtkRecentManager objects are expensive: be sure to create them only when needed. You should use ctk_recent_manager_get_default() instead.

Returns

A newly created CtkRecentManager object

Since: 2.10


ctk_recent_manager_get_default ()

CtkRecentManager *
ctk_recent_manager_get_default (void);

Gets a unique instance of CtkRecentManager, that you can share in your application without caring about memory management.

Returns

A unique CtkRecentManager. Do not ref or unref it.

[transfer none]

Since: 2.10


ctk_recent_manager_add_item ()

gboolean
ctk_recent_manager_add_item (CtkRecentManager *manager,
                             const gchar *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 ctk_recent_manager_add_full().

See ctk_recent_manager_add_full() if you want to explicitly define the metadata for the resource pointed by uri .

Parameters

manager

a CtkRecentManager

 

uri

a valid URI

 

Returns

TRUE if the new item was successfully added to the recently used resources list

Since: 2.10


ctk_recent_manager_add_full ()

gboolean
ctk_recent_manager_add_full (CtkRecentManager *manager,
                             const gchar *uri,
                             const CtkRecentData *recent_data);

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

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 CtkRecentData, 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 CtkRecentData 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

manager

a CtkRecentManager

 

uri

a valid URI

 

recent_data

metadata of the resource

 

Returns

TRUE if the new item was successfully added to the recently used resources list, FALSE otherwise

Since: 2.10


ctk_recent_manager_remove_item ()

gboolean
ctk_recent_manager_remove_item (CtkRecentManager *manager,
                                const gchar *uri,
                                GError **error);

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

Parameters

manager

a CtkRecentManager

 

uri

the URI of the item you wish to remove

 

error

return location for a GError, or NULL.

[allow-none]

Returns

TRUE if the item pointed by uri has been successfully removed by the recently used resources list, and FALSE otherwise

Since: 2.10


ctk_recent_manager_lookup_item ()

CtkRecentInfo *
ctk_recent_manager_lookup_item (CtkRecentManager *manager,
                                const gchar *uri,
                                GError **error);

Searches for a URI inside the recently used resources list, and returns a CtkRecentInfo containing informations about the resource like its MIME type, or its display name.

Parameters

manager

a CtkRecentManager

 

uri

a URI

 

error

a return location for a GError, or NULL.

[allow-none]

Returns

a CtkRecentInfo containing information about the resource pointed by uri , or NULL if the URI was not registered in the recently used resources list. Free with ctk_recent_info_unref().

[nullable]

Since: 2.10


ctk_recent_manager_has_item ()

gboolean
ctk_recent_manager_has_item (CtkRecentManager *manager,
                             const gchar *uri);

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

Parameters

manager

a CtkRecentManager

 

uri

a URI

 

Returns

TRUE if the resource was found, FALSE otherwise

Since: 2.10


ctk_recent_manager_move_item ()

gboolean
ctk_recent_manager_move_item (CtkRecentManager *manager,
                              const gchar *uri,
                              const gchar *new_uri,
                              GError **error);

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

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

manager

a CtkRecentManager

 

uri

the URI of a recently used resource

 

new_uri

the new URI of the recently used resource, or NULL to remove the item pointed by uri in the list.

[allow-none]

error

a return location for a GError, or NULL.

[allow-none]

Returns

TRUE on success

Since: 2.10


ctk_recent_manager_get_items ()

GList *
ctk_recent_manager_get_items (CtkRecentManager *manager);

Gets the list of recently used resources.

Parameters

manager

a CtkRecentManager

 

Returns

a list of newly allocated CtkRecentInfo objects. Use ctk_recent_info_unref() on each item inside the list, and then free the list itself using g_list_free().

[element-type CtkRecentInfo][transfer full]

Since: 2.10


ctk_recent_manager_purge_items ()

gint
ctk_recent_manager_purge_items (CtkRecentManager *manager,
                                GError **error);

Purges every item from the recently used resources list.

Parameters

manager

a CtkRecentManager

 

error

a return location for a GError, or NULL.

[allow-none]

Returns

the number of items that have been removed from the recently used resources list

Since: 2.10


ctk_recent_info_ref ()

CtkRecentInfo *
ctk_recent_info_ref (CtkRecentInfo *info);

Increases the reference count of recent_info by one.

Parameters

info

a CtkRecentInfo

 

Returns

the recent info object with its reference count increased by one

Since: 2.10


ctk_recent_info_unref ()

void
ctk_recent_info_unref (CtkRecentInfo *info);

Decreases the reference count of info by one. If the reference count reaches zero, info is deallocated, and the memory freed.

Parameters

info

a CtkRecentInfo

 

Since: 2.10


ctk_recent_info_get_uri ()

const gchar *
ctk_recent_info_get_uri (CtkRecentInfo *info);

Gets the URI of the resource.

Parameters

info

a CtkRecentInfo

 

Returns

the URI of the resource. The returned string is owned by the recent manager, and should not be freed.

Since: 2.10


ctk_recent_info_get_display_name ()

const gchar *
ctk_recent_info_get_display_name (CtkRecentInfo *info);

Gets the name of the resource. If none has been defined, the basename of the resource is obtained.

Parameters

info

a CtkRecentInfo

 

Returns

the display name of the resource. The returned string is owned by the recent manager, and should not be freed.

Since: 2.10


ctk_recent_info_get_description ()

const gchar *
ctk_recent_info_get_description (CtkRecentInfo *info);

Gets the (short) description of the resource.

Parameters

info

a CtkRecentInfo

 

Returns

the description of the resource. The returned string is owned by the recent manager, and should not be freed.

Since: 2.10


ctk_recent_info_get_mime_type ()

const gchar *
ctk_recent_info_get_mime_type (CtkRecentInfo *info);

Gets the MIME type of the resource.

Parameters

info

a CtkRecentInfo

 

Returns

the MIME type of the resource. The returned string is owned by the recent manager, and should not be freed.

Since: 2.10


ctk_recent_info_get_added ()

GDateTime *
ctk_recent_info_get_added (CtkRecentInfo *info);

Gets the the time when the resource was added to the recently used resources list.

Parameters

info

a CtkRecentInfo

 

Returns

a GDateTime for the time when the resource was added.

[transfer none]

Since: 2.10


ctk_recent_info_get_modified ()

GDateTime *
ctk_recent_info_get_modified (CtkRecentInfo *info);

Gets the time when the meta-data for the resource was last modified.

Parameters

info

a CtkRecentInfo

 

Returns

a GDateTime for the time when the resource was last modified.

[transfer none]

Since: 2.10


ctk_recent_info_get_visited ()

GDateTime *
ctk_recent_info_get_visited (CtkRecentInfo *info);

Gets the time when the meta-data for the resource was last visited.

Parameters

info

a CtkRecentInfo

 

Returns

a GDateTime for the time when the resource was last visited.

[transfer none]

Since: 2.10


ctk_recent_info_get_private_hint ()

gboolean
ctk_recent_info_get_private_hint (CtkRecentInfo *info);

Gets the value of the “private” flag. Resources in the recently used list that have this flag set to TRUE should only be displayed by the applications that have registered them.

Parameters

info

a CtkRecentInfo

 

Returns

TRUE if the private flag was found, FALSE otherwise

Since: 2.10


ctk_recent_info_get_application_info ()

gboolean
ctk_recent_info_get_application_info (CtkRecentInfo *info,
                                      const char *app_name,
                                      const char **app_exec,
                                      guint *count,
                                      GDateTime **stamp);

Gets the data regarding the application that has registered the resource pointed by info .

If the command line contains any escape characters defined inside the storage specification, they will be expanded.

Parameters

info

a CtkRecentInfo

 

app_name

the name of the application that has registered this item

 

app_exec

return location for the string containing the command line.

[transfer none][out]

count

return location for the number of times this item was registered.

[out]

stamp

return location for the time this item was last registered for this application.

[out][transfer none]

Returns

TRUE if an application with app_name has registered this resource inside the recently used list, or FALSE otherwise. The app_exec string is owned by the CtkRecentInfo and should not be modified or freed

Since: 2.10


ctk_recent_info_get_applications ()

gchar **
ctk_recent_info_get_applications (CtkRecentInfo *info,
                                  gsize *length);

Retrieves the list of applications that have registered this resource.

Parameters

info

a CtkRecentInfo

 

length

return location for the length of the returned list.

[out][allow-none]

Returns

a newly allocated NULL-terminated array of strings. Use g_strfreev() to free it.

[array length=length zero-terminated=1][transfer full]

Since: 2.10


ctk_recent_info_last_application ()

gchar *
ctk_recent_info_last_application (CtkRecentInfo *info);

Gets the name of the last application that have registered the recently used resource represented by info .

Parameters

info

a CtkRecentInfo

 

Returns

an application name. Use g_free() to free it.

Since: 2.10


ctk_recent_info_has_application ()

gboolean
ctk_recent_info_has_application (CtkRecentInfo *info,
                                 const gchar *app_name);

Checks whether an application registered this resource using app_name .

Parameters

info

a CtkRecentInfo

 

app_name

a string containing an application name

 

Returns

TRUE if an application with name app_name was found, FALSE otherwise

Since: 2.10


ctk_recent_info_create_app_info ()

GAppInfo *
ctk_recent_info_create_app_info (CtkRecentInfo *info,
                                 const gchar *app_name,
                                 GError **error);

Creates a GAppInfo for the specified CtkRecentInfo

Parameters

info

a CtkRecentInfo

 

app_name

the name of the application that should be mapped to a GAppInfo; if NULL is used then the default application for the MIME type is used.

[allow-none]

error

return location for a GError, or NULL.

[allow-none]

Returns

the newly created GAppInfo, or NULL. In case of error, error will be set either with a CTK_RECENT_MANAGER_ERROR or a G_IO_ERROR.

[nullable][transfer full]


ctk_recent_info_get_groups ()

gchar **
ctk_recent_info_get_groups (CtkRecentInfo *info,
                            gsize *length);

Returns all groups registered for the recently used item info . The array of returned group names will be NULL terminated, so length might optionally be NULL.

Parameters

info

a CtkRecentInfo

 

length

return location for the number of groups returned.

[out][allow-none]

Returns

a newly allocated NULL terminated array of strings. Use g_strfreev() to free it.

[array length=length zero-terminated=1][transfer full]

Since: 2.10


ctk_recent_info_has_group ()

gboolean
ctk_recent_info_has_group (CtkRecentInfo *info,
                           const gchar *group_name);

Checks whether group_name appears inside the groups registered for the recently used item info .

Parameters

info

a CtkRecentInfo

 

group_name

name of a group

 

Returns

TRUE if the group was found

Since: 2.10


ctk_recent_info_get_icon ()

GdkPixbuf *
ctk_recent_info_get_icon (CtkRecentInfo *info,
                          gint size);

Retrieves the icon of size size associated to the resource MIME type.

Parameters

info

a CtkRecentInfo

 

size

the size of the icon in pixels

 

Returns

a GdkPixbuf containing the icon, or NULL. Use g_object_unref() when finished using the icon.

[nullable][transfer full]

Since: 2.10


ctk_recent_info_get_gicon ()

GIcon *
ctk_recent_info_get_gicon (CtkRecentInfo *info);

Retrieves the icon associated to the resource MIME type.

Parameters

info

a CtkRecentInfo

 

Returns

a GIcon containing the icon, or NULL. Use g_object_unref() when finished using the icon.

[nullable][transfer full]

Since: 2.22


ctk_recent_info_get_short_name ()

gchar *
ctk_recent_info_get_short_name (CtkRecentInfo *info);

Computes a valid UTF-8 string that can be used as the name of the item in a menu or list. For example, calling this function on an item that refers to “file:///foo/bar.txt” will yield “bar.txt”.

Parameters

info

an CtkRecentInfo

 

Returns

A newly-allocated string in UTF-8 encoding free it with g_free()

Since: 2.10


ctk_recent_info_get_uri_display ()

gchar *
ctk_recent_info_get_uri_display (CtkRecentInfo *info);

Gets a displayable version of the resource’s URI. If the resource is local, it returns a local path; if the resource is not local, it returns the UTF-8 encoded content of ctk_recent_info_get_uri().

Parameters

info

a CtkRecentInfo

 

Returns

a newly allocated UTF-8 string containing the resource’s URI or NULL. Use g_free() when done using it.

[nullable]

Since: 2.10


ctk_recent_info_get_age ()

gint
ctk_recent_info_get_age (CtkRecentInfo *info);

Gets the number of days elapsed since the last update of the resource pointed by info .

Parameters

info

a CtkRecentInfo

 

Returns

a positive integer containing the number of days elapsed since the time this resource was last modified

Since: 2.10


ctk_recent_info_is_local ()

gboolean
ctk_recent_info_is_local (CtkRecentInfo *info);

Checks whether the resource is local or not by looking at the scheme of its URI.

Parameters

info

a CtkRecentInfo

 

Returns

TRUE if the resource is local

Since: 2.10


ctk_recent_info_exists ()

gboolean
ctk_recent_info_exists (CtkRecentInfo *info);

Checks whether the resource pointed by info still exists. At the moment this check is done only on resources pointing to local files.

Parameters

info

a CtkRecentInfo

 

Returns

TRUE if the resource exists

Since: 2.10


ctk_recent_info_match ()

gboolean
ctk_recent_info_match (CtkRecentInfo *info_a,
                       CtkRecentInfo *info_b);

Checks whether two CtkRecentInfo point to the same resource.

Parameters

info_a

a CtkRecentInfo

 

info_b

a CtkRecentInfo

 

Returns

TRUE if both CtkRecentInfo point to the same resource, FALSE otherwise

Since: 2.10

Types and Values

struct CtkRecentManager

struct CtkRecentManager;

CtkRecentManager contains only private data and should be accessed using the provided API.

Since: 2.10


CtkRecentInfo

typedef struct _CtkRecentInfo CtkRecentInfo;

CtkRecentInfo contains private data only, and should be accessed using the provided API.

CtkRecentInfo constains all the meta-data associated with an entry in the recently used files list.

Since: 2.10


struct CtkRecentData

struct CtkRecentData {
  gchar *display_name;
  gchar *description;

  gchar *mime_type;

  gchar *app_name;
  gchar *app_exec;

  gchar **groups;

  gboolean is_private;
};

Meta-data to be passed to ctk_recent_manager_add_full() when registering a recently used resource.

Members

gchar *display_name;

a UTF-8 encoded string, containing the name of the recently used resource to be displayed, or NULL;

 

gchar *description;

a UTF-8 encoded string, containing a short description of the resource, or NULL;

 

gchar *mime_type;

the MIME type of the resource;

 

gchar *app_name;

the name of the application that is registering this recently used resource;

 

gchar *app_exec;

command line used to launch this resource; may contain the “%f” and “%u” escape characters which will be expanded to the resource file path and URI respectively when the command line is retrieved;

 

gchar **groups;

a vector of strings containing groups names;.

[array zero-terminated=1]

gboolean is_private;

whether this resource should be displayed only by the applications that have registered it or not.

 

CTK_RECENT_MANAGER_ERROR

#define CTK_RECENT_MANAGER_ERROR (ctk_recent_manager_error_quark ())

The GError domain for CtkRecentManager errors.

Since: 2.10


enum CtkRecentManagerError

Error codes for CtkRecentManager operations

Members

CTK_RECENT_MANAGER_ERROR_NOT_FOUND

the URI specified does not exists in the recently used resources list.

 

CTK_RECENT_MANAGER_ERROR_INVALID_URI

the URI specified is not valid.

 

CTK_RECENT_MANAGER_ERROR_INVALID_ENCODING

the supplied string is not UTF-8 encoded.

 

CTK_RECENT_MANAGER_ERROR_NOT_REGISTERED

no application has registered the specified item.

 

CTK_RECENT_MANAGER_ERROR_READ

failure while reading the recently used resources file.

 

CTK_RECENT_MANAGER_ERROR_WRITE

failure while writing the recently used resources file.

 

CTK_RECENT_MANAGER_ERROR_UNKNOWN

unspecified error.

 

Since: 2.10

Property Details

The “filename” property

  “filename”                 char *

The full path to the file to be used to store and read the recently used resources list

Owner: CtkRecentManager

Flags: Read / Write / Construct Only

Default value: NULL

Since: 2.10


The “size” property

  “size”                     int

The size of the recently used resources list.

Owner: CtkRecentManager

Flags: Read

Allowed values: >= -1

Default value: 0

Since: 2.10

Signal Details

The “changed” signal

void
user_function (CtkRecentManager *recent_manager,
               gpointer          user_data)

Emitted when the current recently used resources manager changes its contents, either by calling ctk_recent_manager_add_item() or by another application.

Parameters

recent_manager

the recent manager

 

user_data

user data set when the signal handler was connected.

 

Flags: Run First

Since: 2.10

See Also

GBookmarkFile, CtkSettings, CtkRecentChooser