From a00c11f08ac2516dcf0c6ffab13aaacc0b14ec71 Mon Sep 17 00:00:00 2001 From: Alexander Larsson Date: Fri, 1 Feb 2008 11:21:37 +0000 Subject: [PATCH] Add g_app_info_launch_default_for_uri utility function. (#513256) 2008-02-01 Alexander Larsson * gappinfo.[ch]: * gio.symbols: Add g_app_info_launch_default_for_uri utility function. (#513256) svn path=/trunk/; revision=6437 --- gio/ChangeLog | 7 +++++++ gio/gappinfo.c | 41 +++++++++++++++++++++++++++++++++++++++++ gio/gappinfo.h | 4 ++++ gio/gio.symbols | 1 + 4 files changed, 53 insertions(+) diff --git a/gio/ChangeLog b/gio/ChangeLog index f89164137..bfd581115 100644 --- a/gio/ChangeLog +++ b/gio/ChangeLog @@ -1,3 +1,10 @@ +2008-02-01 Alexander Larsson + + * gappinfo.[ch]: + * gio.symbols: + Add g_app_info_launch_default_for_uri utility + function. (#513256) + 2008-02-01 Cosimo Cecchi * gdesktopappinfo.c: diff --git a/gio/gappinfo.c b/gio/gappinfo.c index 9f2fe01a4..ff53c517d 100644 --- a/gio/gappinfo.c +++ b/gio/gappinfo.c @@ -528,6 +528,47 @@ g_app_info_should_show (GAppInfo *appinfo) return (* iface->should_show) (appinfo); } +/** + * g_app_info_launch_default_for_uri: + * @uri: the uri to show + * @context: an optional #GAppLaunchContext. + * @error: a #GError. + * + * Utility function that launches the default application + * registered to handle the specified uri. Synchronous I/O + * is done on the uri to detext the type of the file if + * required. + * + * Returns: %TRUE on success, %FALSE on error. + **/ +gboolean +g_app_info_launch_default_for_uri (const char *uri, + GAppLaunchContext *launch_context, + GError *error) +{ + GAppInfo *app_info; + GFile *file; + GList l; + gboolean res; + + file = g_file_new_for_uri (uri); + app_info = g_file_query_default_handler (file, NULL, error); + g_object_unref (file); + if (app_info == NULL) + return FALSE; + + /* Use the uri, not the GFile, as the GFile roundtrip may + * affect the uri which we don't want (for instance for a + * mailto: uri). + */ + l.data = uri; + l.next = l.prev = NULL; + res = g_app_info_launch_uris (app_info, &l, + launch_context, error); + return res; +} + + G_DEFINE_TYPE (GAppLaunchContext, g_app_launch_context, G_TYPE_OBJECT); /** diff --git a/gio/gappinfo.h b/gio/gappinfo.h index 0f51dc5db..04ee9ebb8 100644 --- a/gio/gappinfo.h +++ b/gio/gappinfo.h @@ -186,6 +186,10 @@ GAppInfo *g_app_info_get_default_for_type (const char *content_type, gboolean must_support_uris); GAppInfo *g_app_info_get_default_for_uri_scheme (const char *uri_scheme); +gboolean g_app_info_launch_default_for_uri (const char *uri, + GAppLaunchContext *launch_context, + GError *error); + /** * GAppLaunchContext: * @parent_instance: The parent instance. diff --git a/gio/gio.symbols b/gio/gio.symbols index 8b64e5fe2..482844989 100644 --- a/gio/gio.symbols +++ b/gio/gio.symbols @@ -46,6 +46,7 @@ g_app_info_set_as_default_for_extension g_app_info_add_supports_type g_app_info_can_remove_supports_type g_app_info_remove_supports_type +g_app_info_launch_default_for_uri g_app_launch_context_new g_app_launch_context_get_display g_app_launch_context_get_startup_notify_id