summaryrefslogtreecommitdiff
path: root/gio/gfile.c
diff options
context:
space:
mode:
authorMarco Trevisan (Treviño) <mail@3v1n0.net>2022-06-02 04:33:00 +0200
committerMarco Trevisan (Treviño) <mail@3v1n0.net>2022-06-22 20:07:30 +0200
commitc87602451c43a5ed5285311e9e85aa6815cb1239 (patch)
tree6a3ce13d831c51033e229d7bb7b7804f462a8f18 /gio/gfile.c
parent44dbd4317083dcb0f989d8e03e36a4694eacef5b (diff)
downloadglib-c87602451c43a5ed5285311e9e85aa6815cb1239.tar.gz
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.
Diffstat (limited to 'gio/gfile.c')
-rw-r--r--gio/gfile.c58
1 files changed, 45 insertions, 13 deletions
diff --git a/gio/gfile.c b/gio/gfile.c
index a4d6d11cf..93a2ab634 100644
--- a/gio/gfile.c
+++ b/gio/gfile.c
@@ -7524,6 +7524,36 @@ g_file_query_default_handler (GFile *file,
}
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
query_default_handler_query_info_cb (GObject *object,
GAsyncResult *result,
gpointer user_data)
@@ -7533,7 +7563,6 @@ query_default_handler_query_info_cb (GObject *object,
GError *error = NULL;
GFileInfo *info;
const char *content_type;
- GAppInfo *appinfo = NULL;
info = g_file_query_info_finish (file, result, &error);
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);
if (content_type)
{
+ GCancellable *cancellable = g_task_get_cancellable (task);
char *path;
/* Don't use is_native(), as we want to support fuse paths if available */
path = g_file_get_path (file);
- /* FIXME: The following still uses blocking calls. */
- appinfo = g_app_info_get_default_for_type (content_type,
- path == NULL);
+ g_app_info_get_default_for_type_async (content_type,
+ path == NULL,
+ cancellable,
+ query_default_handler_query_app_info_for_type_cb,
+ g_steal_pointer (&task));
+
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);
-
- 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);
+ g_clear_object (&task);
}
/**