[gnome-control-center] background: Replace deprecated GSimpleAsyncResult with GTask



commit 122f997493b8d4ed8ccfbfa0fdfbff8d92b41842
Author: Robert Ancell <robert ancell canonical com>
Date:   Fri Jun 1 14:26:57 2018 +1200

    background: Replace deprecated GSimpleAsyncResult with GTask

 panels/background/bg-wallpapers-source.c |  4 ++-
 panels/background/cc-background-xml.c    | 45 +++++++++++++++-----------------
 panels/background/cc-background-xml.h    | 22 +++++++++-------
 3 files changed, 36 insertions(+), 35 deletions(-)
---
diff --git a/panels/background/bg-wallpapers-source.c b/panels/background/bg-wallpapers-source.c
index 50f40b369..a1fb460c2 100644
--- a/panels/background/bg-wallpapers-source.c
+++ b/panels/background/bg-wallpapers-source.c
@@ -81,7 +81,9 @@ list_load_cb (GObject *source_object,
              GAsyncResult *res,
              gpointer user_data)
 {
-  cc_background_xml_load_list_finish (res);
+  g_autoptr(GError) error = NULL;
+  if (!cc_background_xml_load_list_finish (CC_BACKGROUND_XML (source_object), res, &error))
+    g_warning ("Failed to load background list: %s", error->message);
 }
 
 static void
diff --git a/panels/background/cc-background-xml.c b/panels/background/cc-background-xml.c
index 4cb774e44..10823afb8 100644
--- a/panels/background/cc-background-xml.c
+++ b/panels/background/cc-background-xml.c
@@ -431,42 +431,39 @@ cc_background_xml_load_list (CcBackgroundXml *data,
   }
 }
 
-const GHashTable *
-cc_background_xml_load_list_finish (GAsyncResult  *async_result)
+gboolean
+cc_background_xml_load_list_finish (CcBackgroundXml *xml,
+                                   GAsyncResult    *result,
+                                   GError         **error)
 {
-       GSimpleAsyncResult *result = G_SIMPLE_ASYNC_RESULT (async_result);
-       CcBackgroundXml *data;
-
-       g_return_val_if_fail (G_IS_ASYNC_RESULT (async_result), NULL);
-       g_warn_if_fail (g_simple_async_result_get_source_tag (result) == cc_background_xml_load_list_async);
-
-       data = CC_BACKGROUND_XML (g_simple_async_result_get_op_res_gpointer (result));
-       return data->wp_hash;
+       g_return_val_if_fail (g_task_is_valid (result, xml), FALSE);
+       g_return_val_if_fail (error == NULL || *error == NULL, FALSE);
+       return g_task_propagate_boolean (G_TASK (result), error);
 }
 
 static void
-load_list_thread (GSimpleAsyncResult *res,
-                 GObject *object,
+load_list_thread (GTask *task,
+                 gpointer source_object,
+                 gpointer task_data,
                  GCancellable *cancellable)
 {
-       CcBackgroundXml *data;
-
-       data = g_simple_async_result_get_op_res_gpointer (res);
-       cc_background_xml_load_list (data, TRUE);
+       CcBackgroundXml *xml = CC_BACKGROUND_XML (source_object);
+       cc_background_xml_load_list (xml, TRUE);
+       g_task_return_boolean (task, TRUE);
 }
 
-void cc_background_xml_load_list_async (CcBackgroundXml *xml,
-                                       GCancellable *cancellable,
-                                       GAsyncReadyCallback callback,
-                                       gpointer user_data)
+void
+cc_background_xml_load_list_async (CcBackgroundXml *xml,
+                                  GCancellable *cancellable,
+                                  GAsyncReadyCallback callback,
+                                  gpointer user_data)
 {
-       g_autoptr(GSimpleAsyncResult) result = NULL;
+       g_autoptr(GTask) task = NULL;
 
        g_return_if_fail (CC_IS_BACKGROUND_XML (xml));
 
-       result = g_simple_async_result_new (G_OBJECT (xml), callback, user_data, 
cc_background_xml_load_list_async);
-       g_simple_async_result_set_op_res_gpointer (result, xml, NULL);
-       g_simple_async_result_run_in_thread (result, (GSimpleAsyncThreadFunc) load_list_thread, 
G_PRIORITY_LOW, cancellable);
+       task = g_task_new (xml, cancellable, callback, user_data);
+       g_task_run_in_thread (task, load_list_thread);
 }
 
 gboolean
diff --git a/panels/background/cc-background-xml.h b/panels/background/cc-background-xml.h
index bf0687f78..809f6f1c7 100644
--- a/panels/background/cc-background-xml.h
+++ b/panels/background/cc-background-xml.h
@@ -31,17 +31,19 @@ G_DECLARE_FINAL_TYPE (CcBackgroundXml, cc_background_xml, CC, BACKGROUND_XML, GO
 
 CcBackgroundXml *cc_background_xml_new (void);
 
-void cc_background_xml_save                          (CcBackgroundItem *item,
-                                                     const char       *filename);
-
-CcBackgroundItem *cc_background_xml_get_item         (const char      *filename);
-gboolean cc_background_xml_load_xml                  (CcBackgroundXml *data,
-                                                     const char      *filename);
-void cc_background_xml_load_list_async               (CcBackgroundXml *data,
-                                                     GCancellable *cancellable,
+void cc_background_xml_save                          (CcBackgroundItem   *item,
+                                                     const char         *filename);
+
+CcBackgroundItem *cc_background_xml_get_item         (const char         *filename);
+gboolean cc_background_xml_load_xml                  (CcBackgroundXml    *data,
+                                                     const char         *filename);
+void cc_background_xml_load_list_async               (CcBackgroundXml    *xml,
+                                                     GCancellable       *cancellable,
                                                      GAsyncReadyCallback callback,
-                                                     gpointer user_data);
-const GHashTable *cc_background_xml_load_list_finish (GAsyncResult  *async_result);
+                                                     gpointer            user_data);
+gboolean cc_background_xml_load_list_finish          (CcBackgroundXml    *xml,
+                                                     GAsyncResult       *result,
+                                                     GError            **error);
 
 G_END_DECLS
 


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