[gnome-control-center] printers: Replace deprecated GSimpleAsyncResult with GTask
- From: Marek Kašík <mkasik src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-control-center] printers: Replace deprecated GSimpleAsyncResult with GTask
- Date: Wed, 28 Nov 2018 11:56:16 +0000 (UTC)
commit 323fee6d3bddc82f755c3a243079555041bb82d3
Author: Robert Ancell <robert ancell canonical com>
Date: Fri Jun 1 15:22:58 2018 +1200
printers: Replace deprecated GSimpleAsyncResult with GTask
panels/printers/pp-host.c | 92 ++++++++++++++--------------------------
panels/printers/pp-new-printer.c | 60 ++++++++------------------
panels/printers/pp-samba.c | 47 ++++++++------------
3 files changed, 67 insertions(+), 132 deletions(-)
---
diff --git a/panels/printers/pp-host.c b/panels/printers/pp-host.c
index 70b447c8c..1d4d35b9f 100644
--- a/panels/printers/pp-host.c
+++ b/panels/printers/pp-host.c
@@ -247,11 +247,12 @@ line_split (gchar *line)
}
static void
-_pp_host_get_snmp_devices_thread (GSimpleAsyncResult *res,
- GObject *object,
- GCancellable *cancellable)
+_pp_host_get_snmp_devices_thread (GTask *task,
+ gpointer source_object,
+ gpointer task_data,
+ GCancellable *cancellable)
{
- PpHost *host = (PpHost *) object;
+ PpHost *host = (PpHost *) source_object;
PpHostPrivate *priv = host->priv;
PpPrintDevice *device;
gboolean is_network_device;
@@ -262,7 +263,8 @@ _pp_host_get_snmp_devices_thread (GSimpleAsyncResult *res,
gchar *stderr_string = NULL;
gint exit_status;
- data = g_simple_async_result_get_op_res_gpointer (res);
+ data = g_task_get_task_data (task);
+
data->devices = g_new0 (PpDevicesList, 1);
data->devices->devices = NULL;
@@ -324,6 +326,8 @@ _pp_host_get_snmp_devices_thread (GSimpleAsyncResult *res,
g_strfreev (printer_informations);
g_free (stdout_string);
}
+
+ g_task_return_pointer (task, g_steal_pointer (&data->devices), (GDestroyNotify) pp_devices_list_free);
}
static void
@@ -342,18 +346,10 @@ pp_host_get_snmp_devices_async (PpHost *host,
GAsyncReadyCallback callback,
gpointer user_data)
{
- GSimpleAsyncResult *res;
- GSDData *data;
+ g_autoptr(GTask) task = NULL;
- res = g_simple_async_result_new (G_OBJECT (host), callback, user_data, pp_host_get_snmp_devices_async);
- data = g_new0 (GSDData, 1);
- data->devices = NULL;
-
- g_simple_async_result_set_check_cancellable (res, cancellable);
- g_simple_async_result_set_op_res_gpointer (res, data, (GDestroyNotify) gsd_data_free);
- g_simple_async_result_run_in_thread (res, _pp_host_get_snmp_devices_thread, 0, cancellable);
-
- g_object_unref (res);
+ task = g_task_new (host, cancellable, callback, user_data);
+ g_task_run_in_thread (task, _pp_host_get_snmp_devices_thread);
}
PpDevicesList *
@@ -361,32 +357,22 @@ pp_host_get_snmp_devices_finish (PpHost *host,
GAsyncResult *res,
GError **error)
{
- GSimpleAsyncResult *simple = G_SIMPLE_ASYNC_RESULT (res);
- GSDData *data;
- PpDevicesList *result;
-
- g_warn_if_fail (g_simple_async_result_get_source_tag (simple) == pp_host_get_snmp_devices_async);
-
- if (g_simple_async_result_propagate_error (simple, error))
- return NULL;
-
- data = g_simple_async_result_get_op_res_gpointer (simple);
- result = data->devices;
- data->devices = NULL;
-
- return result;
+ g_return_val_if_fail (g_task_is_valid (res, host), NULL);
+ g_return_val_if_fail (error == NULL || *error == NULL, NULL);
+ return g_task_propagate_pointer (G_TASK (res), error);
}
static void
-_pp_host_get_remote_cups_devices_thread (GSimpleAsyncResult *res,
- GObject *object,
- GCancellable *cancellable)
+_pp_host_get_remote_cups_devices_thread (GTask *task,
+ gpointer source_object,
+ gpointer task_data,
+ GCancellable *cancellable)
{
cups_dest_t *dests = NULL;
- GSDData *data;
- PpHost *host = (PpHost *) object;
+ PpHost *host = (PpHost *) source_object;
PpHostPrivate *priv = host->priv;
PpPrintDevice *device;
+ GSDData *data;
const char *device_location;
http_t *http;
gchar *device_uri;
@@ -394,7 +380,8 @@ _pp_host_get_remote_cups_devices_thread (GSimpleAsyncResult *res,
gint port;
gint i;
- data = g_simple_async_result_get_op_res_gpointer (res);
+ data = g_task_get_task_data (task);
+
data->devices = g_new0 (PpDevicesList, 1);
data->devices->devices = NULL;
@@ -439,6 +426,8 @@ _pp_host_get_remote_cups_devices_thread (GSimpleAsyncResult *res,
httpClose (http);
}
+
+ g_task_return_pointer (task, g_steal_pointer (&data->devices), (GDestroyNotify) pp_devices_list_free);
}
void
@@ -447,18 +436,10 @@ pp_host_get_remote_cups_devices_async (PpHost *host,
GAsyncReadyCallback callback,
gpointer user_data)
{
- GSimpleAsyncResult *res;
- GSDData *data;
+ g_autoptr(GTask) task = NULL;
- res = g_simple_async_result_new (G_OBJECT (host), callback, user_data,
pp_host_get_remote_cups_devices_async);
- data = g_new0 (GSDData, 1);
- data->devices = NULL;
-
- g_simple_async_result_set_check_cancellable (res, cancellable);
- g_simple_async_result_set_op_res_gpointer (res, data, (GDestroyNotify) gsd_data_free);
- g_simple_async_result_run_in_thread (res, _pp_host_get_remote_cups_devices_thread, 0, cancellable);
-
- g_object_unref (res);
+ task = g_task_new (host, cancellable, callback, user_data);
+ g_task_run_in_thread (task, _pp_host_get_remote_cups_devices_thread);
}
PpDevicesList *
@@ -466,20 +447,9 @@ pp_host_get_remote_cups_devices_finish (PpHost *host,
GAsyncResult *res,
GError **error)
{
- GSimpleAsyncResult *simple = G_SIMPLE_ASYNC_RESULT (res);
- GSDData *data;
- PpDevicesList *result;
-
- g_warn_if_fail (g_simple_async_result_get_source_tag (simple) == pp_host_get_remote_cups_devices_async);
-
- if (g_simple_async_result_propagate_error (simple, error))
- return NULL;
-
- data = g_simple_async_result_get_op_res_gpointer (simple);
- result = data->devices;
- data->devices = NULL;
-
- return result;
+ g_return_val_if_fail (g_task_is_valid (res, host), NULL);
+ g_return_val_if_fail (error == NULL || *error == NULL, NULL);
+ return g_task_propagate_pointer (G_TASK (res), error);
}
typedef struct
diff --git a/panels/printers/pp-new-printer.c b/panels/printers/pp-new-printer.c
index 0c2177743..ffb131ee8 100644
--- a/panels/printers/pp-new-printer.c
+++ b/panels/printers/pp-new-printer.c
@@ -59,7 +59,7 @@ struct _PpNewPrinterPrivate
guint window_id;
gboolean unlink_ppd_file;
- GSimpleAsyncResult *res;
+ GTask *task;
GCancellable *cancellable;
};
@@ -102,10 +102,7 @@ pp_new_printer_finalize (GObject *object)
g_clear_pointer (&priv->location, g_free);
g_clear_pointer (&priv->make_and_model, g_free);
g_clear_pointer (&priv->host_name, g_free);
-
- if (priv->res)
- g_object_unref (priv->res);
-
+ g_clear_object (&priv->task);
if (priv->cancellable)
g_object_unref (priv->cancellable);
@@ -351,7 +348,6 @@ pp_new_printer_init (PpNewPrinter *printer)
printer->priv->unlink_ppd_file = FALSE;
printer->priv->cancellable = NULL;
- printer->priv->res = NULL;
}
PpNewPrinter *
@@ -370,14 +366,14 @@ _pp_new_printer_add_async_cb (gboolean success,
if (!success)
{
- g_simple_async_result_set_error (priv->res,
- G_IO_ERROR,
- G_IO_ERROR_FAILED,
- "Installation of the new printer failed.");
+ g_task_return_new_error (priv->task,
+ G_IO_ERROR,
+ G_IO_ERROR_FAILED,
+ "Installation of the new printer failed.");
+ return;
}
- g_simple_async_result_set_op_res_gboolean (priv->res, success);
- g_simple_async_result_complete_in_idle (priv->res);
+ g_task_return_boolean (priv->task, success);
}
static void
@@ -1323,15 +1319,16 @@ printer_configure_async (PpNewPrinter *new_printer)
ime_data);
}
-static void
-_pp_new_printer_add_async (GSimpleAsyncResult *res,
- GObject *object,
- GCancellable *cancellable)
+void
+pp_new_printer_add_async (PpNewPrinter *printer,
+ GCancellable *cancellable,
+ GAsyncReadyCallback callback,
+ gpointer user_data)
{
- PpNewPrinter *printer = PP_NEW_PRINTER (object);
PpNewPrinterPrivate *priv = printer->priv;
+ g_autoptr(GTask) task = NULL;
- priv->res = g_object_ref (res);
+ priv->task = g_task_new (printer, cancellable, callback, user_data);
priv->cancellable = g_object_ref (cancellable);
if (priv->ppd_name || priv->ppd_file_name)
@@ -1385,33 +1382,12 @@ _pp_new_printer_add_async (GSimpleAsyncResult *res,
}
}
-void
-pp_new_printer_add_async (PpNewPrinter *printer,
- GCancellable *cancellable,
- GAsyncReadyCallback callback,
- gpointer user_data)
-{
- GSimpleAsyncResult *res;
-
- res = g_simple_async_result_new (G_OBJECT (printer), callback, user_data, pp_new_printer_add_async);
-
- g_simple_async_result_set_check_cancellable (res, cancellable);
- _pp_new_printer_add_async (res, G_OBJECT (printer), cancellable);
-
- g_object_unref (res);
-}
-
gboolean
pp_new_printer_add_finish (PpNewPrinter *printer,
GAsyncResult *res,
GError **error)
{
- GSimpleAsyncResult *simple = G_SIMPLE_ASYNC_RESULT (res);
-
- g_warn_if_fail (g_simple_async_result_get_source_tag (simple) == pp_new_printer_add_async);
-
- if (g_simple_async_result_propagate_error (simple, error))
- return FALSE;
-
- return g_simple_async_result_get_op_res_gboolean (simple);
+ g_return_val_if_fail (g_task_is_valid (res, printer), FALSE);
+ g_return_val_if_fail (error == NULL || *error == NULL, FALSE);
+ return g_task_propagate_boolean (G_TASK (res), error);
}
diff --git a/panels/printers/pp-samba.c b/panels/printers/pp-samba.c
index 04db2d8ab..502cc7827 100644
--- a/panels/printers/pp-samba.c
+++ b/panels/printers/pp-samba.c
@@ -354,21 +354,21 @@ list_dir (SMBCCTX *smb_context,
}
static void
-_pp_samba_get_devices_thread (GSimpleAsyncResult *res,
- GObject *object,
- GCancellable *cancellable)
+_pp_samba_get_devices_thread (GTask *task,
+ gpointer source_object,
+ gpointer task_data,
+ GCancellable *cancellable)
{
static GMutex mutex;
- SMBData *data;
+ SMBData *data = (SMBData *) task_data;
SMBCCTX *smb_context;
gchar *dirname;
gchar *path;
gchar *hostname = NULL;
- data = g_simple_async_result_get_op_res_gpointer (res);
data->devices = g_new0 (PpDevicesList, 1);
data->devices->devices = NULL;
- data->samba = PP_SAMBA (object);
+ data->samba = PP_SAMBA (source_object);
g_mutex_lock (&mutex);
@@ -379,7 +379,7 @@ _pp_samba_get_devices_thread (GSimpleAsyncResult *res,
{
smbc_setOptionUserData (smb_context, data);
- g_object_get (object, "hostname", &hostname, NULL);
+ g_object_get (source_object, "hostname", &hostname, NULL);
if (hostname != NULL)
{
dirname = g_strdup_printf ("smb://%s", hostname);
@@ -404,6 +404,8 @@ _pp_samba_get_devices_thread (GSimpleAsyncResult *res,
}
g_mutex_unlock (&mutex);
+
+ g_task_return_pointer (task, g_steal_pointer (&data->devices), (GDestroyNotify) pp_devices_list_free);
}
void
@@ -413,25 +415,23 @@ pp_samba_get_devices_async (PpSamba *samba,
GAsyncReadyCallback callback,
gpointer user_data)
{
- GSimpleAsyncResult *res;
- SMBData *data;
- gchar *hostname = NULL;
+ g_autoptr(GTask) task = NULL;
+ SMBData *data;
+ gchar *hostname = NULL;
g_object_get (G_OBJECT (samba), "hostname", &hostname, NULL);
- res = g_simple_async_result_new (G_OBJECT (samba), callback, user_data, pp_samba_get_devices_async);
+ task = g_task_new (samba, cancellable, callback, user_data);
data = g_new0 (SMBData, 1);
data->devices = NULL;
data->context = g_main_context_default ();
data->hostname_set = hostname != NULL;
data->auth_if_needed = auth_if_needed;
- g_simple_async_result_set_check_cancellable (res, cancellable);
- g_simple_async_result_set_op_res_gpointer (res, data, (GDestroyNotify) smb_data_free);
- g_simple_async_result_run_in_thread (res, _pp_samba_get_devices_thread, 0, cancellable);
+ g_task_set_task_data (task, data, (GDestroyNotify) smb_data_free);
+ g_task_run_in_thread (task, _pp_samba_get_devices_thread);
g_free (hostname);
- g_object_unref (res);
}
PpDevicesList *
@@ -439,18 +439,7 @@ pp_samba_get_devices_finish (PpSamba *samba,
GAsyncResult *res,
GError **error)
{
- GSimpleAsyncResult *simple = G_SIMPLE_ASYNC_RESULT (res);
- SMBData *data;
- PpDevicesList *result;
-
- g_warn_if_fail (g_simple_async_result_get_source_tag (simple) == pp_samba_get_devices_async);
-
- if (g_simple_async_result_propagate_error (simple, error))
- return NULL;
-
- data = g_simple_async_result_get_op_res_gpointer (simple);
- result = data->devices;
- data->devices = NULL;
-
- return result;
+ g_return_val_if_fail (g_task_is_valid (res, samba), NULL);
+ g_return_val_if_fail (error == NULL || *error == NULL, NULL);
+ return g_task_propagate_pointer (G_TASK (res), error);
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]