mirror of
https://gitlab.gnome.org/GNOME/glib.git
synced 2025-09-07 00:18:44 +02:00
Add g_file_query_default_handler utility to easily look up the GAppInfo
2008-01-29 Alexander Larsson <alexl@redhat.com> * gfile.[ch]: Add g_file_query_default_handler utility to easily look up the GAppInfo that handles a file. * gdesktopappinfo.[ch]: * giomodule.c: Set up an extension point for g_app_info_get_default_for_uri_scheme() * gvfs.c: Remove unused function svn path=/trunk/; revision=6409
This commit is contained in:
committed by
Alexander Larsson
parent
1b0fce2dca
commit
431fef8617
51
gio/gfile.c
51
gio/gfile.c
@@ -4572,6 +4572,57 @@ g_file_mount_enclosing_volume_finish (GFile *location,
|
||||
* Utility functions *
|
||||
********************************************/
|
||||
|
||||
GAppInfo *
|
||||
g_file_query_default_handler (GFile *file,
|
||||
GCancellable *cancellable,
|
||||
GError **error)
|
||||
{
|
||||
char *uri_scheme;
|
||||
const char *content_type;
|
||||
GAppInfo *appinfo;
|
||||
GFileInfo *info;
|
||||
char *path;
|
||||
|
||||
uri_scheme = g_file_get_uri_scheme (file);
|
||||
appinfo = g_app_info_get_default_for_uri_scheme (uri_scheme);
|
||||
g_free (uri_scheme);
|
||||
|
||||
if (appinfo != NULL)
|
||||
return appinfo;
|
||||
|
||||
info = g_file_query_info (file,
|
||||
G_FILE_ATTRIBUTE_STANDARD_CONTENT_TYPE,
|
||||
0,
|
||||
cancellable,
|
||||
error);
|
||||
if (info == NULL)
|
||||
return NULL;
|
||||
|
||||
appinfo = NULL;
|
||||
|
||||
content_type = g_file_info_get_content_type (info);
|
||||
if (content_type)
|
||||
{
|
||||
/* Don't use is_native(), as we want to support fuse paths if availible */
|
||||
path = g_file_get_path (file);
|
||||
appinfo = g_app_info_get_default_for_type (content_type,
|
||||
path == NULL);
|
||||
g_free (path);
|
||||
}
|
||||
|
||||
g_object_unref (info);
|
||||
|
||||
if (appinfo != NULL)
|
||||
return appinfo;
|
||||
|
||||
g_set_error (error, G_IO_ERROR,
|
||||
G_IO_ERROR_NOT_SUPPORTED,
|
||||
_("No application is registered as handling this file"));
|
||||
return NULL;
|
||||
|
||||
}
|
||||
|
||||
|
||||
#define GET_CONTENT_BLOCK_SIZE 8192
|
||||
|
||||
/**
|
||||
|
Reference in New Issue
Block a user