diff options
author | Emmanuele Bassi <ebassi@linux.intel.com> | 2010-10-22 11:42:39 +0100 |
---|---|---|
committer | Emmanuele Bassi <ebassi@linux.intel.com> | 2010-10-22 11:54:53 +0100 |
commit | 03fc0dd5caf6e88f02574be4af34c9c79b6940aa (patch) | |
tree | e6ca06d81ba72efbc579c51368967024ac245e25 /gtk/gtkrecentmanager.c | |
parent | 06758f1ab5e7a6fd97c6bff6041aca96743a13b6 (diff) | |
download | gtk+-03fc0dd5caf6e88f02574be4af34c9c79b6940aa.tar.gz |
recent-manager: Add RecentInfo.create_app_info()
A simple wrapper that makes it possible to create a GAppInfo from a
GtkRecentInfo blob.
Diffstat (limited to 'gtk/gtkrecentmanager.c')
-rw-r--r-- | gtk/gtkrecentmanager.c | 66 |
1 files changed, 66 insertions, 0 deletions
diff --git a/gtk/gtkrecentmanager.c b/gtk/gtkrecentmanager.c index 7e3aff0c9b..a53b1b8092 100644 --- a/gtk/gtkrecentmanager.c +++ b/gtk/gtkrecentmanager.c @@ -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: * |