[gnome-shell] hotplug-sniffer: Port to GTask
- From: Florian Müllner <fmuellner src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-shell] hotplug-sniffer: Port to GTask
- Date: Thu, 15 Oct 2015 21:10:58 +0000 (UTC)
commit bf0be6ef12d602852923e6752333ee950a3379a8
Author: Florian Müllner <fmuellner gnome org>
Date: Fri Sep 25 19:25:36 2015 +0200
hotplug-sniffer: Port to GTask
GSimpleAsyncResult is deprecated.
src/hotplug-sniffer/shell-mime-sniffer.c | 48 +++++++++---------------------
1 files changed, 14 insertions(+), 34 deletions(-)
---
diff --git a/src/hotplug-sniffer/shell-mime-sniffer.c b/src/hotplug-sniffer/shell-mime-sniffer.c
index b5be402..0792ab7 100644
--- a/src/hotplug-sniffer/shell-mime-sniffer.c
+++ b/src/hotplug-sniffer/shell-mime-sniffer.c
@@ -85,8 +85,7 @@ struct _ShellMimeSnifferPrivate {
GCancellable *cancellable;
guint watchdog_id;
- GSimpleAsyncResult *async_result;
- gchar **sniffed_mime;
+ GTask *task;
};
G_DEFINE_TYPE_WITH_PRIVATE (ShellMimeSniffer, shell_mime_sniffer, G_TYPE_OBJECT);
@@ -188,6 +187,7 @@ prepare_async_result (DeepCountState *state)
GArray *results;
GPtrArray *sniffed_mime;
SniffedResult result;
+ char **mimes;
sniffed_mime = g_ptr_array_new ();
results = g_array_new (TRUE, TRUE, sizeof (SniffedResult));
@@ -229,10 +229,10 @@ prepare_async_result (DeepCountState *state)
out:
g_ptr_array_add (sniffed_mime, NULL);
- self->priv->sniffed_mime = (gchar **) g_ptr_array_free (sniffed_mime, FALSE);
+ mimes = (gchar **) g_ptr_array_free (sniffed_mime, FALSE);
g_array_free (results, TRUE);
- g_simple_async_result_complete_in_idle (self->priv->async_result);
+ g_task_return_pointer (self->priv->task, mimes, (GDestroyNotify)g_strfreev);
}
/* adapted from nautilus/libnautilus-private/nautilus-directory-async.c */
@@ -425,20 +425,17 @@ query_info_async_ready_cb (GObject *source,
if (error != NULL)
{
- g_simple_async_result_take_error (self->priv->async_result,
- error);
- g_simple_async_result_complete_in_idle (self->priv->async_result);
+ g_task_return_error (self->priv->task, error);
return;
}
if (g_file_info_get_file_type (info) != G_FILE_TYPE_DIRECTORY)
{
- g_simple_async_result_set_error (self->priv->async_result,
- G_IO_ERROR,
- G_IO_ERROR_NOT_DIRECTORY,
- "Not a directory");
- g_simple_async_result_complete_in_idle (self->priv->async_result);
+ g_task_return_new_error (self->priv->task,
+ G_IO_ERROR,
+ G_IO_ERROR_NOT_DIRECTORY,
+ "Not a directory");
return;
}
@@ -484,7 +481,7 @@ shell_mime_sniffer_dispose (GObject *object)
g_clear_object (&self->priv->file);
g_clear_object (&self->priv->cancellable);
- g_clear_object (&self->priv->async_result);
+ g_clear_object (&self->priv->task);
if (self->priv->watchdog_id != 0)
{
@@ -496,16 +493,6 @@ shell_mime_sniffer_dispose (GObject *object)
}
static void
-shell_mime_sniffer_finalize (GObject *object)
-{
- ShellMimeSniffer *self = SHELL_MIME_SNIFFER (object);
-
- g_strfreev (self->priv->sniffed_mime);
-
- G_OBJECT_CLASS (shell_mime_sniffer_parent_class)->finalize (object);
-}
-
-static void
shell_mime_sniffer_get_property (GObject *object,
guint prop_id,
GValue *value,
@@ -548,7 +535,6 @@ shell_mime_sniffer_class_init (ShellMimeSnifferClass *klass)
oclass = G_OBJECT_CLASS (klass);
oclass->dispose = shell_mime_sniffer_dispose;
- oclass->finalize = shell_mime_sniffer_finalize;
oclass->get_property = shell_mime_sniffer_get_property;
oclass->set_property = shell_mime_sniffer_set_property;
@@ -583,14 +569,11 @@ shell_mime_sniffer_sniff_async (ShellMimeSniffer *self,
gpointer user_data)
{
g_assert (self->priv->watchdog_id == 0);
- g_assert (self->priv->async_result == NULL);
+ g_assert (self->priv->task == NULL);
- self->priv->async_result =
- g_simple_async_result_new (G_OBJECT (self),
- callback, user_data,
- shell_mime_sniffer_sniff_finish);
-
self->priv->cancellable = g_cancellable_new ();
+ self->priv->task = g_task_new (self, self->priv->cancellable,
+ callback, user_data);
self->priv->watchdog_id =
g_timeout_add (WATCHDOG_TIMEOUT,
@@ -605,8 +588,5 @@ shell_mime_sniffer_sniff_finish (ShellMimeSniffer *self,
GAsyncResult *res,
GError **error)
{
- if (g_simple_async_result_propagate_error (self->priv->async_result, error))
- return NULL;
-
- return g_strdupv (self->priv->sniffed_mime);
+ return g_task_propagate_pointer (self->priv->task, error);
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]