Commit 733bf962 authored by Sébastien Wilmet's avatar Sébastien Wilmet

Add async version of g_file_trash()

https://bugzilla.gnome.org/show_bug.cgi?id=548353
parent c35b73a9
......@@ -131,6 +131,8 @@ g_file_delete
g_file_delete_async
g_file_delete_finish
g_file_trash
g_file_trash_async
g_file_trash_finish
g_file_copy
g_file_copy_async
g_file_copy_finish
......
......@@ -225,6 +225,14 @@ static void g_file_real_delete_async (GFile
static gboolean g_file_real_delete_finish (GFile *file,
GAsyncResult *res,
GError **error);
static void g_file_real_trash_async (GFile *file,
int io_priority,
GCancellable *cancellable,
GAsyncReadyCallback callback,
gpointer user_data);
static gboolean g_file_real_trash_finish (GFile *file,
GAsyncResult *res,
GError **error);
static void g_file_real_open_readwrite_async (GFile *file,
int io_priority,
GCancellable *cancellable,
......@@ -325,6 +333,8 @@ g_file_default_init (GFileIface *iface)
iface->replace_finish = g_file_real_replace_finish;
iface->delete_file_async = g_file_real_delete_async;
iface->delete_file_finish = g_file_real_delete_finish;
iface->trash_async = g_file_real_trash_async;
iface->trash_finish = g_file_real_trash_finish;
iface->open_readwrite_async = g_file_real_open_readwrite_async;
iface->open_readwrite_finish = g_file_real_open_readwrite_finish;
iface->create_readwrite_async = g_file_real_create_readwrite_async;
......@@ -3826,6 +3836,68 @@ g_file_trash (GFile *file,
return (* iface->trash) (file, cancellable, error);
}
/**
* g_file_trash_async:
* @file: input #GFile
* @io_priority: the <link linkend="io-priority">I/O priority</link>
* of the request
* @cancellable: (allow-none): optional #GCancellable object,
* %NULL to ignore
* @callback: a #GAsyncReadyCallback to call
* when the request is satisfied
* @user_data: the data to pass to callback function
*
* Asynchronously sends @file to the Trash location, if possible.
*
* Virtual: trash_async
* Since: 2.38
*/
void
g_file_trash_async (GFile *file,
int io_priority,
GCancellable *cancellable,
GAsyncReadyCallback callback,
gpointer user_data)
{
GFileIface *iface;
g_return_if_fail (G_IS_FILE (file));
iface = G_FILE_GET_IFACE (file);
(* iface->trash_async) (file,
io_priority,
cancellable,
callback,
user_data);
}
/**
* g_file_trash_finish:
* @file: input #GFile
* @result: a #GAsyncResult
* @error: a #GError, or %NULL
*
* Finishes an asynchronous file trashing operation, started with
* g_file_trash_async().
*
* Virtual: trash_finish
* Returns: %TRUE on successful trash, %FALSE otherwise.
* Since: 2.38
*/
gboolean
g_file_trash_finish (GFile *file,
GAsyncResult *result,
GError **error)
{
GFileIface *iface;
g_return_val_if_fail (G_IS_FILE (file), FALSE);
g_return_val_if_fail (G_IS_ASYNC_RESULT (result), FALSE);
iface = G_FILE_GET_IFACE (file);
return (* iface->trash_finish) (file, result, error);
}
/**
* g_file_set_display_name:
* @file: input #GFile
......@@ -5521,6 +5593,45 @@ g_file_real_delete_finish (GFile *file,
return g_task_propagate_boolean (G_TASK (res), error);
}
static void
trash_async_thread (GTask *task,
gpointer object,
gpointer task_data,
GCancellable *cancellable)
{
GError *error = NULL;
if (g_file_trash (G_FILE (object), cancellable, &error))
g_task_return_boolean (task, TRUE);
else
g_task_return_error (task, error);
}
static void
g_file_real_trash_async (GFile *file,
int io_priority,
GCancellable *cancellable,
GAsyncReadyCallback callback,
gpointer user_data)
{
GTask *task;
task = g_task_new (file, cancellable, callback, user_data);
g_task_set_priority (task, io_priority);
g_task_run_in_thread (task, trash_async_thread);
g_object_unref (task);
}
static gboolean
g_file_real_trash_finish (GFile *file,
GAsyncResult *res,
GError **error)
{
g_return_val_if_fail (g_task_is_valid (res, file), FALSE);
return g_task_propagate_boolean (G_TASK (res), error);
}
static void
open_readwrite_async_thread (GTask *task,
gpointer object,
......
......@@ -108,8 +108,8 @@ typedef struct _GFileIface GFileIface;
* @delete_file_async: Asynchronously deletes a file.
* @delete_file_finish: Finishes an asynchronous delete.
* @trash: Sends a #GFile to the Trash location.
* @_trash_async: Asynchronously sends a #GFile to the Trash location.
* @_trash_finish: Finishes an asynchronous file trashing operation.
* @trash_async: Asynchronously sends a #GFile to the Trash location.
* @trash_finish: Finishes an asynchronous file trashing operation.
* @make_directory: Makes a directory.
* @_make_directory_async: Asynchronously makes a directory.
* @_make_directory_finish: Finishes making a directory asynchronously.
......@@ -365,8 +365,14 @@ struct _GFileIface
gboolean (* trash) (GFile *file,
GCancellable *cancellable,
GError **error);
void (* _trash_async) (void);
void (* _trash_finish) (void);
void (* trash_async) (GFile *file,
int io_priority,
GCancellable *cancellable,
GAsyncReadyCallback callback,
gpointer user_data);
gboolean (* trash_finish) (GFile *file,
GAsyncResult *result,
GError **error);
gboolean (* make_directory) (GFile *file,
GCancellable *cancellable,
......@@ -838,6 +844,19 @@ GLIB_AVAILABLE_IN_ALL
gboolean g_file_trash (GFile *file,
GCancellable *cancellable,
GError **error);
GLIB_AVAILABLE_IN_2_38
void g_file_trash_async (GFile *file,
int io_priority,
GCancellable *cancellable,
GAsyncReadyCallback callback,
gpointer user_data);
GLIB_AVAILABLE_IN_2_38
gboolean g_file_trash_finish (GFile *file,
GAsyncResult *result,
GError **error);
GLIB_AVAILABLE_IN_ALL
gboolean g_file_copy (GFile *source,
GFile *destination,
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment