summaryrefslogtreecommitdiff
path: root/client/gvfsiconloadable.c
diff options
context:
space:
mode:
Diffstat (limited to 'client/gvfsiconloadable.c')
-rw-r--r--client/gvfsiconloadable.c120
1 files changed, 56 insertions, 64 deletions
diff --git a/client/gvfsiconloadable.c b/client/gvfsiconloadable.c
index a464774f..2de6df89 100644
--- a/client/gvfsiconloadable.c
+++ b/client/gvfsiconloadable.c
@@ -136,20 +136,16 @@ g_vfs_icon_load (GLoadableIcon *icon,
typedef void (*CreateProxyAsyncCallback) (GVfsDBusMount *proxy,
- GSimpleAsyncResult *result,
- GCancellable *cancellable,
- gpointer callback_data);
+ GDBusConnection *connection,
+ GMountInfo *mount_info,
+ GTask *task);
typedef struct {
- GSimpleAsyncResult *result;
- GVfsIcon *vfs_icon;
+ GTask *task;
GMountInfo *mount_info;
GDBusConnection *connection;
GVfsDBusMount *proxy;
- GCancellable *cancellable;
CreateProxyAsyncCallback callback;
- gpointer callback_data;
- gulong cancelled_tag;
} AsyncPathCall;
@@ -159,9 +155,7 @@ async_path_call_free (AsyncPathCall *data)
g_clear_object (&data->connection);
if (data->mount_info)
g_mount_info_unref (data->mount_info);
- g_clear_object (&data->result);
- g_object_unref (data->vfs_icon);
- g_clear_object (&data->cancellable);
+ g_clear_object (&data->task);
g_clear_object (&data->proxy);
g_free (data);
}
@@ -178,8 +172,8 @@ async_proxy_new_cb (GObject *source_object,
proxy = gvfs_dbus_mount_proxy_new_finish (res, &error);
if (proxy == NULL)
{
- _g_simple_async_result_take_error_stripped (data->result, error);
- _g_simple_async_result_complete_with_cancellable (data->result, data->cancellable);
+ g_dbus_error_strip_remote_error (error);
+ g_task_return_error (data->task, error);
async_path_call_free (data);
return;
}
@@ -187,9 +181,11 @@ async_proxy_new_cb (GObject *source_object,
data->proxy = proxy;
data->callback (proxy,
- data->result,
- data->cancellable,
- data->callback_data);
+ data->connection,
+ data->mount_info,
+ g_object_ref (data->task));
+
+ async_path_call_free (data);
}
static void
@@ -202,8 +198,7 @@ async_got_connection_cb (GDBusConnection *connection,
if (connection == NULL)
{
g_dbus_error_strip_remote_error (io_error);
- g_simple_async_result_set_from_error (data->result, io_error);
- _g_simple_async_result_complete_with_cancellable (data->result, data->cancellable);
+ g_task_return_error (data->task, io_error);
async_path_call_free (data);
return;
}
@@ -213,7 +208,7 @@ async_got_connection_cb (GDBusConnection *connection,
G_DBUS_PROXY_FLAGS_DO_NOT_LOAD_PROPERTIES | G_DBUS_PROXY_FLAGS_DO_NOT_CONNECT_SIGNALS,
data->mount_info->dbus_id,
data->mount_info->object_path,
- data->cancellable,
+ g_task_get_cancellable (data->task),
async_proxy_new_cb,
data);
}
@@ -228,8 +223,7 @@ async_got_mount_info (GMountInfo *mount_info,
if (error != NULL)
{
g_dbus_error_strip_remote_error (error);
- g_simple_async_result_set_from_error (data->result, error);
- _g_simple_async_result_complete_with_cancellable (data->result, data->cancellable);
+ g_task_return_error (data->task, error);
async_path_call_free (data);
return;
}
@@ -239,30 +233,19 @@ async_got_mount_info (GMountInfo *mount_info,
_g_dbus_connection_get_for_async (mount_info->dbus_id,
async_got_connection_cb,
data,
- data->cancellable);
+ g_task_get_cancellable (data->task));
}
static void
create_proxy_for_icon_async (GVfsIcon *vfs_icon,
- GCancellable *cancellable,
- GAsyncReadyCallback op_callback,
- gpointer op_callback_data,
- CreateProxyAsyncCallback callback,
- gpointer callback_data)
+ GTask *task,
+ CreateProxyAsyncCallback callback)
{
AsyncPathCall *data;
data = g_new0 (AsyncPathCall, 1);
-
- data->result = g_simple_async_result_new (G_OBJECT (vfs_icon),
- op_callback, op_callback_data,
- NULL);
-
- data->vfs_icon = g_object_ref (vfs_icon);
- if (cancellable)
- data->cancellable = g_object_ref (cancellable);
+ data->task = task;
data->callback = callback;
- data->callback_data = callback_data;
_g_daemon_vfs_get_mount_info_async (vfs_icon->mount_spec,
"/",
@@ -270,12 +253,17 @@ create_proxy_for_icon_async (GVfsIcon *vfs_icon,
data);
}
+typedef struct {
+ gulong cancelled_tag;
+} AsyncCallIconLoad;
+
static void
open_icon_read_cb (GVfsDBusMount *proxy,
GAsyncResult *res,
gpointer user_data)
{
- AsyncPathCall *data = user_data;
+ GTask *task = G_TASK (user_data);
+ AsyncCallIconLoad *data = g_task_get_task_data (task);
GError *error = NULL;
gboolean can_seek;
GUnixFDList *fd_list;
@@ -286,7 +274,8 @@ open_icon_read_cb (GVfsDBusMount *proxy,
if (! gvfs_dbus_mount_call_open_icon_for_read_finish (proxy, &fd_id_val, &can_seek, &fd_list, res, &error))
{
- _g_simple_async_result_take_error_stripped (data->result, error);
+ g_dbus_error_strip_remote_error (error);
+ g_task_return_error (task, error);
goto out;
}
@@ -296,38 +285,39 @@ open_icon_read_cb (GVfsDBusMount *proxy,
if (fd_list == NULL || g_unix_fd_list_get_length (fd_list) != 1 ||
(fd = g_unix_fd_list_get (fd_list, fd_id, NULL)) == -1)
{
- g_simple_async_result_set_error (data->result,
- G_IO_ERROR, G_IO_ERROR_FAILED,
- _("Couldn’t get stream file descriptor"));
+ g_task_return_new_error (task, G_IO_ERROR, G_IO_ERROR_FAILED,
+ _("Couldn’t get stream file descriptor"));
}
else
{
stream = g_daemon_file_input_stream_new (fd, can_seek);
- g_simple_async_result_set_op_res_gpointer (data->result, stream, g_object_unref);
+ g_task_return_pointer (task, stream, g_object_unref);
g_object_unref (fd_list);
}
out:
- _g_simple_async_result_complete_with_cancellable (data->result, data->cancellable);
- _g_dbus_async_unsubscribe_cancellable (data->cancellable, data->cancelled_tag);
- async_path_call_free (data);
+ _g_dbus_async_unsubscribe_cancellable (g_task_get_cancellable (task), data->cancelled_tag);
+ g_object_unref (task);
}
static void
load_async_cb (GVfsDBusMount *proxy,
- GSimpleAsyncResult *result,
- GCancellable *cancellable,
- gpointer callback_data)
+ GDBusConnection *connection,
+ GMountInfo *mount_info,
+ GTask *task)
{
- AsyncPathCall *data = callback_data;
+ AsyncCallIconLoad *data = g_task_get_task_data (task);
+ GVfsIcon *vfs_icon;
+
+ vfs_icon = G_VFS_ICON (g_task_get_source_object (task));
gvfs_dbus_mount_call_open_icon_for_read (proxy,
- data->vfs_icon->icon_id,
+ vfs_icon->icon_id,
NULL,
- cancellable,
+ g_task_get_cancellable (task),
(GAsyncReadyCallback) open_icon_read_cb,
- callback_data);
- data->cancelled_tag = _g_dbus_async_subscribe_cancellable (data->connection, cancellable);
+ task);
+ data->cancelled_tag = _g_dbus_async_subscribe_cancellable (connection, g_task_get_cancellable (task));
}
static void
@@ -337,10 +327,16 @@ g_vfs_icon_load_async (GLoadableIcon *icon,
GAsyncReadyCallback callback,
gpointer user_data)
{
- create_proxy_for_icon_async (G_VFS_ICON (icon),
- cancellable,
- callback, user_data,
- load_async_cb, NULL);
+ AsyncCallIconLoad *data;
+ GTask *task;
+
+ task = g_task_new (icon, cancellable, callback, user_data);
+ g_task_set_source_tag (task, g_vfs_icon_load_async);
+
+ data = g_new0 (AsyncCallIconLoad, 1);
+ g_task_set_task_data (task, data, g_free);
+
+ create_proxy_for_icon_async (G_VFS_ICON (icon), task, load_async_cb);
}
static GInputStream *
@@ -349,14 +345,10 @@ g_vfs_icon_load_finish (GLoadableIcon *icon,
char **type,
GError **error)
{
- GSimpleAsyncResult *simple = G_SIMPLE_ASYNC_RESULT (res);
- gpointer op;
-
- op = g_simple_async_result_get_op_res_gpointer (simple);
- if (op)
- return g_object_ref (op);
+ g_return_val_if_fail (g_task_is_valid (res, icon), NULL);
+ g_return_val_if_fail (g_async_result_is_tagged (res, g_vfs_icon_load_async), NULL);
- return NULL;
+ return g_task_propagate_pointer (G_TASK (res), error);
}
static void