recent-manager: Add RecentInfo.create_app_info()

A simple wrapper that makes it possible to create a GAppInfo from a
GtkRecentInfo blob.
This commit is contained in:
Emmanuele Bassi 2010-10-22 11:42:39 +01:00
parent 06758f1ab5
commit 03fc0dd5ca
4 changed files with 72 additions and 1 deletions

View File

@ -2620,9 +2620,10 @@ gtk_recent_info_get_private_hint
gtk_recent_info_get_application_info
gtk_recent_info_get_applications
gtk_recent_info_last_application
gtk_recent_info_has_application
gtk_recent_info_create_app_info
gtk_recent_info_get_groups
gtk_recent_info_has_group
gtk_recent_info_has_application
gtk_recent_info_get_icon
gtk_recent_info_get_short_name
gtk_recent_info_get_uri_display

View File

@ -2793,6 +2793,7 @@ gtk_recent_info_get_application_info
gtk_recent_info_get_applications G_GNUC_MALLOC
gtk_recent_info_last_application G_GNUC_MALLOC
gtk_recent_info_has_application
gtk_recent_info_create_app_info
gtk_recent_info_get_groups G_GNUC_MALLOC
gtk_recent_info_has_group
gtk_recent_info_get_icon

View File

@ -2316,6 +2316,72 @@ gtk_recent_info_has_group (GtkRecentInfo *info,
return FALSE;
}
/**
* gtk_recent_info_create_app_info:
* @info: a #GtkRecentInfo
* @app_name: (allow-none): 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
* @error: (allow-none): return location for a #GError, or %NULL
*
* Creates a #GAppInfo for the specified #GtkRecentInfo
*
* Return value: (transfer full): the newly created #GAppInfo, or %NULL.
* In case of error, @error will be set either with a
* %GTK_RECENT_MANAGER_ERROR or a %G_IO_ERROR
*/
GAppInfo *
gtk_recent_info_create_app_info (GtkRecentInfo *info,
const gchar *app_name,
GError **error)
{
RecentAppInfo *ai;
GAppInfo *app_info;
GError *internal_error = NULL;
g_return_val_if_fail (info != NULL, NULL);
if (app_name == NULL || *app_name == '\0')
{
char *content_type;
if (info->mime_type == NULL)
return NULL;
content_type = g_content_type_from_mime_type (info->mime_type);
if (content_type == NULL)
return NULL;
app_info = g_app_info_get_default_for_type (content_type, TRUE);
g_free (content_type);
return app_info;
}
ai = g_hash_table_lookup (info->apps_lookup, app_name);
if (ai == NULL)
{
g_set_error (error, GTK_RECENT_MANAGER_ERROR,
GTK_RECENT_MANAGER_ERROR_NOT_REGISTERED,
_("No registered application with name '%s' for item with URI '%s' found"),
app_name,
info->uri);
return NULL;
}
internal_error = NULL;
app_info = g_app_info_create_from_commandline (ai->exec, ai->name,
G_APP_INFO_CREATE_NONE,
&internal_error);
if (internal_error != NULL)
{
g_propagate_error (error, internal_error);
return NULL;
}
return app_info;
}
/*
* _gtk_recent_manager_sync:
*

View File

@ -204,6 +204,9 @@ gboolean gtk_recent_info_get_application_info (GtkRecentInfo *info
const gchar **app_exec,
guint *count,
time_t *time_);
GAppInfo * gtk_recent_info_create_app_info (GtkRecentInfo *info,
const gchar *app_name,
GError **error);
gchar ** gtk_recent_info_get_applications (GtkRecentInfo *info,
gsize *length) G_GNUC_MALLOC;
gchar * gtk_recent_info_last_application (GtkRecentInfo *info) G_GNUC_MALLOC;