hotplug-sniffer: Port to GTask

GSimpleAsyncResult is deprecated.
This commit is contained in:
Florian Müllner 2015-09-25 19:25:36 +02:00
parent 294702d3f1
commit bf0be6ef12

View File

@ -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)
{
@ -495,16 +492,6 @@ shell_mime_sniffer_dispose (GObject *object)
G_OBJECT_CLASS (shell_mime_sniffer_parent_class)->dispose (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,
@ -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);
}