mirror of
https://gitlab.gnome.org/GNOME/glib.git
synced 2025-01-26 05:56:14 +01:00
gfile: Use async API to get the default GAppInfo for type
In both callbacks of g_file_query_default_handler_async() we were actually using I/O blocking APIs making it not fully async. Now that such API is provided, we can use it.
This commit is contained in:
parent
44dbd43170
commit
c87602451c
58
gio/gfile.c
58
gio/gfile.c
@ -7523,6 +7523,36 @@ g_file_query_default_handler (GFile *file,
|
|||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void
|
||||||
|
query_default_handler_query_app_info_for_type_cb (GObject *object,
|
||||||
|
GAsyncResult *result,
|
||||||
|
gpointer user_data)
|
||||||
|
{
|
||||||
|
GTask *task = G_TASK (user_data);
|
||||||
|
GAppInfo *appinfo;
|
||||||
|
GError *error = NULL;
|
||||||
|
|
||||||
|
appinfo = g_app_info_get_default_for_type_finish (result, &error);
|
||||||
|
|
||||||
|
if (appinfo != NULL)
|
||||||
|
{
|
||||||
|
g_task_return_pointer (task, g_steal_pointer (&appinfo), g_object_unref);
|
||||||
|
}
|
||||||
|
else if (g_error_matches (error, G_IO_ERROR, G_IO_ERROR_NOT_FOUND))
|
||||||
|
{
|
||||||
|
g_task_return_new_error (task,
|
||||||
|
G_IO_ERROR, G_IO_ERROR_NOT_SUPPORTED,
|
||||||
|
"%s", error->message);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
g_task_return_error (task, g_steal_pointer (&error));
|
||||||
|
}
|
||||||
|
|
||||||
|
g_clear_error (&error);
|
||||||
|
g_object_unref (task);
|
||||||
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
query_default_handler_query_info_cb (GObject *object,
|
query_default_handler_query_info_cb (GObject *object,
|
||||||
GAsyncResult *result,
|
GAsyncResult *result,
|
||||||
@ -7533,7 +7563,6 @@ query_default_handler_query_info_cb (GObject *object,
|
|||||||
GError *error = NULL;
|
GError *error = NULL;
|
||||||
GFileInfo *info;
|
GFileInfo *info;
|
||||||
const char *content_type;
|
const char *content_type;
|
||||||
GAppInfo *appinfo = NULL;
|
|
||||||
|
|
||||||
info = g_file_query_info_finish (file, result, &error);
|
info = g_file_query_info_finish (file, result, &error);
|
||||||
if (info == NULL)
|
if (info == NULL)
|
||||||
@ -7548,27 +7577,30 @@ query_default_handler_query_info_cb (GObject *object,
|
|||||||
content_type = g_file_info_get_attribute_string (info, G_FILE_ATTRIBUTE_STANDARD_FAST_CONTENT_TYPE);
|
content_type = g_file_info_get_attribute_string (info, G_FILE_ATTRIBUTE_STANDARD_FAST_CONTENT_TYPE);
|
||||||
if (content_type)
|
if (content_type)
|
||||||
{
|
{
|
||||||
|
GCancellable *cancellable = g_task_get_cancellable (task);
|
||||||
char *path;
|
char *path;
|
||||||
|
|
||||||
/* Don't use is_native(), as we want to support fuse paths if available */
|
/* Don't use is_native(), as we want to support fuse paths if available */
|
||||||
path = g_file_get_path (file);
|
path = g_file_get_path (file);
|
||||||
|
|
||||||
/* FIXME: The following still uses blocking calls. */
|
g_app_info_get_default_for_type_async (content_type,
|
||||||
appinfo = g_app_info_get_default_for_type (content_type,
|
path == NULL,
|
||||||
path == NULL);
|
cancellable,
|
||||||
|
query_default_handler_query_app_info_for_type_cb,
|
||||||
|
g_steal_pointer (&task));
|
||||||
|
|
||||||
g_free (path);
|
g_free (path);
|
||||||
}
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
g_task_return_new_error (task,
|
||||||
|
G_IO_ERROR,
|
||||||
|
G_IO_ERROR_NOT_SUPPORTED,
|
||||||
|
_("No application is registered as handling this file"));
|
||||||
|
}
|
||||||
|
|
||||||
g_object_unref (info);
|
g_object_unref (info);
|
||||||
|
g_clear_object (&task);
|
||||||
if (appinfo != NULL)
|
|
||||||
g_task_return_pointer (task, g_steal_pointer (&appinfo), g_object_unref);
|
|
||||||
else
|
|
||||||
g_task_return_new_error (task,
|
|
||||||
G_IO_ERROR,
|
|
||||||
G_IO_ERROR_NOT_SUPPORTED,
|
|
||||||
_("No application is registered as handling this file"));
|
|
||||||
g_object_unref (task);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
Loading…
Reference in New Issue
Block a user