[glib: 23/24] gfile: Make g_query_default_handler_async really Async




commit 5b04d23fc43782af2ebb59f151b4b981747850d2
Author: Marco Trevisan (TreviƱo) <mail 3v1n0 net>
Date:   Thu Jun 2 00:47:43 2022 +0200

    gfile: Make g_query_default_handler_async really Async
    
    Despite the name, the call was still doing blocking operations when
    looking for app handlers via GAppInfo. Now it's possible to use fully
    async calls.
    
    Together with previous commit, the API is now fully async.

 gio/gfile.c | 48 +++++++++++++++++++++++++++++++++++-------------
 1 file changed, 35 insertions(+), 13 deletions(-)
---
diff --git a/gio/gfile.c b/gio/gfile.c
index 93a2ab6349..e78b5e1857 100644
--- a/gio/gfile.c
+++ b/gio/gfile.c
@@ -7603,6 +7603,34 @@ query_default_handler_query_info_cb (GObject      *object,
   g_clear_object (&task);
 }
 
+static void
+on_query_default_handler_for_uri_cb (GObject      *object,
+                                     GAsyncResult *result,
+                                     gpointer      user_data)
+{
+  GTask *task = user_data;
+  GAppInfo *app_info;
+
+  app_info = g_app_info_get_default_for_uri_scheme_finish (result, NULL);
+
+  if (app_info)
+    {
+      g_task_return_pointer (task, g_steal_pointer (&app_info), g_object_unref);
+      g_object_unref (task);
+    }
+  else
+    {
+      g_file_query_info_async (g_task_get_source_object (task),
+                               G_FILE_ATTRIBUTE_STANDARD_CONTENT_TYPE ","
+                               G_FILE_ATTRIBUTE_STANDARD_FAST_CONTENT_TYPE,
+                               0,
+                               g_task_get_priority (task),
+                               g_task_get_cancellable (task),
+                               query_default_handler_query_info_cb,
+                               task);
+    }
+}
+
 /**
  * g_file_query_default_handler_async:
  * @file: a #GFile to open
@@ -7631,21 +7659,13 @@ g_file_query_default_handler_async (GFile              *file,
   uri_scheme = g_file_get_uri_scheme (file);
   if (uri_scheme && uri_scheme[0] != '\0')
     {
-      GAppInfo *appinfo;
-
-      /* FIXME: The following still uses blocking calls. */
-      appinfo = g_app_info_get_default_for_uri_scheme (uri_scheme);
+      g_app_info_get_default_for_uri_scheme_async (uri_scheme,
+                                                   cancellable,
+                                                   on_query_default_handler_for_uri_cb,
+                                                   g_steal_pointer (&task));
       g_free (uri_scheme);
-
-      if (appinfo != NULL)
-        {
-          g_task_return_pointer (task, g_steal_pointer (&appinfo), g_object_unref);
-          g_object_unref (task);
-          return;
-        }
+      return;
     }
-  else
-    g_free (uri_scheme);
 
   g_file_query_info_async (file,
                            G_FILE_ATTRIBUTE_STANDARD_CONTENT_TYPE ","
@@ -7655,6 +7675,8 @@ g_file_query_default_handler_async (GFile              *file,
                            cancellable,
                            query_default_handler_query_info_cb,
                            g_steal_pointer (&task));
+
+  g_free (uri_scheme);
 }
 
 /**


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]