mirror of
https://gitlab.gnome.org/GNOME/glib.git
synced 2025-02-04 10:16:17 +01:00
gio: port file/vfs-related classes from GSimpleAsyncResult to GTask
https://bugzilla.gnome.org/show_bug.cgi?id=661767
This commit is contained in:
parent
669505e354
commit
ed5accf16c
30
gio/gdrive.c
30
gio/gdrive.c
@ -23,7 +23,7 @@
|
|||||||
|
|
||||||
#include "config.h"
|
#include "config.h"
|
||||||
#include "gdrive.h"
|
#include "gdrive.h"
|
||||||
#include "gsimpleasyncresult.h"
|
#include "gtask.h"
|
||||||
#include "gthemedicon.h"
|
#include "gthemedicon.h"
|
||||||
#include "gasyncresult.h"
|
#include "gasyncresult.h"
|
||||||
#include "gioerror.h"
|
#include "gioerror.h"
|
||||||
@ -388,10 +388,10 @@ g_drive_eject (GDrive *drive,
|
|||||||
|
|
||||||
if (iface->eject == NULL)
|
if (iface->eject == NULL)
|
||||||
{
|
{
|
||||||
g_simple_async_report_error_in_idle (G_OBJECT (drive), callback, user_data,
|
g_task_report_new_error (drive, callback, user_data,
|
||||||
|
g_drive_eject_with_operation,
|
||||||
G_IO_ERROR, G_IO_ERROR_NOT_SUPPORTED,
|
G_IO_ERROR, G_IO_ERROR_NOT_SUPPORTED,
|
||||||
_("drive doesn't implement eject"));
|
_("drive doesn't implement eject"));
|
||||||
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -423,6 +423,8 @@ g_drive_eject_finish (GDrive *drive,
|
|||||||
|
|
||||||
if (g_async_result_legacy_propagate_error (result, error))
|
if (g_async_result_legacy_propagate_error (result, error))
|
||||||
return FALSE;
|
return FALSE;
|
||||||
|
else if (g_async_result_is_tagged (result, g_drive_eject_with_operation))
|
||||||
|
return g_task_propagate_boolean (G_TASK (result), error);
|
||||||
|
|
||||||
iface = G_DRIVE_GET_IFACE (drive);
|
iface = G_DRIVE_GET_IFACE (drive);
|
||||||
|
|
||||||
@ -461,8 +463,8 @@ g_drive_eject_with_operation (GDrive *drive,
|
|||||||
|
|
||||||
if (iface->eject == NULL && iface->eject_with_operation == NULL)
|
if (iface->eject == NULL && iface->eject_with_operation == NULL)
|
||||||
{
|
{
|
||||||
g_simple_async_report_error_in_idle (G_OBJECT (drive),
|
g_task_report_new_error (drive, callback, user_data,
|
||||||
callback, user_data,
|
g_drive_eject_with_operation,
|
||||||
G_IO_ERROR, G_IO_ERROR_NOT_SUPPORTED,
|
G_IO_ERROR, G_IO_ERROR_NOT_SUPPORTED,
|
||||||
/* Translators: This is an error
|
/* Translators: This is an error
|
||||||
* message for drive objects that
|
* message for drive objects that
|
||||||
@ -503,6 +505,8 @@ g_drive_eject_with_operation_finish (GDrive *drive,
|
|||||||
|
|
||||||
if (g_async_result_legacy_propagate_error (result, error))
|
if (g_async_result_legacy_propagate_error (result, error))
|
||||||
return FALSE;
|
return FALSE;
|
||||||
|
else if (g_async_result_is_tagged (result, g_drive_eject_with_operation))
|
||||||
|
return g_task_propagate_boolean (G_TASK (result), error);
|
||||||
|
|
||||||
iface = G_DRIVE_GET_IFACE (drive);
|
iface = G_DRIVE_GET_IFACE (drive);
|
||||||
if (iface->eject_with_operation_finish != NULL)
|
if (iface->eject_with_operation_finish != NULL)
|
||||||
@ -538,10 +542,10 @@ g_drive_poll_for_media (GDrive *drive,
|
|||||||
|
|
||||||
if (iface->poll_for_media == NULL)
|
if (iface->poll_for_media == NULL)
|
||||||
{
|
{
|
||||||
g_simple_async_report_error_in_idle (G_OBJECT (drive), callback, user_data,
|
g_task_report_new_error (drive, callback, user_data,
|
||||||
|
g_drive_poll_for_media,
|
||||||
G_IO_ERROR, G_IO_ERROR_NOT_SUPPORTED,
|
G_IO_ERROR, G_IO_ERROR_NOT_SUPPORTED,
|
||||||
_("drive doesn't implement polling for media"));
|
_("drive doesn't implement polling for media"));
|
||||||
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -571,6 +575,8 @@ g_drive_poll_for_media_finish (GDrive *drive,
|
|||||||
|
|
||||||
if (g_async_result_legacy_propagate_error (result, error))
|
if (g_async_result_legacy_propagate_error (result, error))
|
||||||
return FALSE;
|
return FALSE;
|
||||||
|
else if (g_async_result_is_tagged (result, g_drive_poll_for_media))
|
||||||
|
return g_task_propagate_boolean (G_TASK (result), error);
|
||||||
|
|
||||||
iface = G_DRIVE_GET_IFACE (drive);
|
iface = G_DRIVE_GET_IFACE (drive);
|
||||||
|
|
||||||
@ -741,7 +747,8 @@ g_drive_start (GDrive *drive,
|
|||||||
|
|
||||||
if (iface->start == NULL)
|
if (iface->start == NULL)
|
||||||
{
|
{
|
||||||
g_simple_async_report_error_in_idle (G_OBJECT (drive), callback, user_data,
|
g_task_report_new_error (drive, callback, user_data,
|
||||||
|
g_drive_start,
|
||||||
G_IO_ERROR, G_IO_ERROR_NOT_SUPPORTED,
|
G_IO_ERROR, G_IO_ERROR_NOT_SUPPORTED,
|
||||||
_("drive doesn't implement start"));
|
_("drive doesn't implement start"));
|
||||||
return;
|
return;
|
||||||
@ -775,6 +782,8 @@ g_drive_start_finish (GDrive *drive,
|
|||||||
|
|
||||||
if (g_async_result_legacy_propagate_error (result, error))
|
if (g_async_result_legacy_propagate_error (result, error))
|
||||||
return FALSE;
|
return FALSE;
|
||||||
|
else if (g_async_result_is_tagged (result, g_drive_start))
|
||||||
|
return g_task_propagate_boolean (G_TASK (result), error);
|
||||||
|
|
||||||
iface = G_DRIVE_GET_IFACE (drive);
|
iface = G_DRIVE_GET_IFACE (drive);
|
||||||
|
|
||||||
@ -840,7 +849,8 @@ g_drive_stop (GDrive *drive,
|
|||||||
|
|
||||||
if (iface->stop == NULL)
|
if (iface->stop == NULL)
|
||||||
{
|
{
|
||||||
g_simple_async_report_error_in_idle (G_OBJECT (drive), callback, user_data,
|
g_task_report_new_error (drive, callback, user_data,
|
||||||
|
g_drive_start,
|
||||||
G_IO_ERROR, G_IO_ERROR_NOT_SUPPORTED,
|
G_IO_ERROR, G_IO_ERROR_NOT_SUPPORTED,
|
||||||
_("drive doesn't implement stop"));
|
_("drive doesn't implement stop"));
|
||||||
return;
|
return;
|
||||||
@ -874,6 +884,8 @@ g_drive_stop_finish (GDrive *drive,
|
|||||||
|
|
||||||
if (g_async_result_legacy_propagate_error (result, error))
|
if (g_async_result_legacy_propagate_error (result, error))
|
||||||
return FALSE;
|
return FALSE;
|
||||||
|
else if (g_async_result_is_tagged (result, g_drive_start))
|
||||||
|
return g_task_propagate_boolean (G_TASK (result), error);
|
||||||
|
|
||||||
iface = G_DRIVE_GET_IFACE (drive);
|
iface = G_DRIVE_GET_IFACE (drive);
|
||||||
|
|
||||||
|
865
gio/gfile.c
865
gio/gfile.c
File diff suppressed because it is too large
Load Diff
@ -26,7 +26,6 @@
|
|||||||
#include "gioscheduler.h"
|
#include "gioscheduler.h"
|
||||||
#include "gasyncresult.h"
|
#include "gasyncresult.h"
|
||||||
#include "gasynchelper.h"
|
#include "gasynchelper.h"
|
||||||
#include "gsimpleasyncresult.h"
|
|
||||||
#include "gioerror.h"
|
#include "gioerror.h"
|
||||||
#include "glibintl.h"
|
#include "glibintl.h"
|
||||||
|
|
||||||
@ -335,7 +334,6 @@ g_file_enumerator_next_files_async (GFileEnumerator *enumerator,
|
|||||||
gpointer user_data)
|
gpointer user_data)
|
||||||
{
|
{
|
||||||
GFileEnumeratorClass *class;
|
GFileEnumeratorClass *class;
|
||||||
GSimpleAsyncResult *simple;
|
|
||||||
|
|
||||||
g_return_if_fail (G_IS_FILE_ENUMERATOR (enumerator));
|
g_return_if_fail (G_IS_FILE_ENUMERATOR (enumerator));
|
||||||
g_return_if_fail (enumerator != NULL);
|
g_return_if_fail (enumerator != NULL);
|
||||||
@ -343,20 +341,19 @@ g_file_enumerator_next_files_async (GFileEnumerator *enumerator,
|
|||||||
|
|
||||||
if (num_files == 0)
|
if (num_files == 0)
|
||||||
{
|
{
|
||||||
simple = g_simple_async_result_new (G_OBJECT (enumerator),
|
GTask *task;
|
||||||
callback,
|
|
||||||
user_data,
|
task = g_task_new (enumerator, cancellable, callback, user_data);
|
||||||
g_file_enumerator_next_files_async);
|
g_task_set_source_tag (task, g_file_enumerator_next_files_async);
|
||||||
g_simple_async_result_complete_in_idle (simple);
|
g_task_return_pointer (task, NULL, NULL);
|
||||||
g_object_unref (simple);
|
g_object_unref (task);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (enumerator->priv->closed)
|
if (enumerator->priv->closed)
|
||||||
{
|
{
|
||||||
g_simple_async_report_error_in_idle (G_OBJECT (enumerator),
|
g_task_report_new_error (enumerator, callback, user_data,
|
||||||
callback,
|
g_file_enumerator_next_files_async,
|
||||||
user_data,
|
|
||||||
G_IO_ERROR, G_IO_ERROR_CLOSED,
|
G_IO_ERROR, G_IO_ERROR_CLOSED,
|
||||||
_("File enumerator is already closed"));
|
_("File enumerator is already closed"));
|
||||||
return;
|
return;
|
||||||
@ -364,9 +361,8 @@ g_file_enumerator_next_files_async (GFileEnumerator *enumerator,
|
|||||||
|
|
||||||
if (enumerator->priv->pending)
|
if (enumerator->priv->pending)
|
||||||
{
|
{
|
||||||
g_simple_async_report_error_in_idle (G_OBJECT (enumerator),
|
g_task_report_new_error (enumerator, callback, user_data,
|
||||||
callback,
|
g_file_enumerator_next_files_async,
|
||||||
user_data,
|
|
||||||
G_IO_ERROR, G_IO_ERROR_PENDING,
|
G_IO_ERROR, G_IO_ERROR_PENDING,
|
||||||
_("File enumerator has outstanding operation"));
|
_("File enumerator has outstanding operation"));
|
||||||
return;
|
return;
|
||||||
@ -407,10 +403,7 @@ g_file_enumerator_next_files_finish (GFileEnumerator *enumerator,
|
|||||||
if (g_async_result_legacy_propagate_error (result, error))
|
if (g_async_result_legacy_propagate_error (result, error))
|
||||||
return NULL;
|
return NULL;
|
||||||
else if (g_async_result_is_tagged (result, g_file_enumerator_next_files_async))
|
else if (g_async_result_is_tagged (result, g_file_enumerator_next_files_async))
|
||||||
{
|
return g_task_propagate_pointer (G_TASK (result), error);
|
||||||
/* Special case read of 0 files */
|
|
||||||
return NULL;
|
|
||||||
}
|
|
||||||
|
|
||||||
class = G_FILE_ENUMERATOR_GET_CLASS (enumerator);
|
class = G_FILE_ENUMERATOR_GET_CLASS (enumerator);
|
||||||
return class->next_files_finish (enumerator, result, error);
|
return class->next_files_finish (enumerator, result, error);
|
||||||
@ -459,9 +452,8 @@ g_file_enumerator_close_async (GFileEnumerator *enumerator,
|
|||||||
|
|
||||||
if (enumerator->priv->closed)
|
if (enumerator->priv->closed)
|
||||||
{
|
{
|
||||||
g_simple_async_report_error_in_idle (G_OBJECT (enumerator),
|
g_task_report_new_error (enumerator, callback, user_data,
|
||||||
callback,
|
g_file_enumerator_close_async,
|
||||||
user_data,
|
|
||||||
G_IO_ERROR, G_IO_ERROR_CLOSED,
|
G_IO_ERROR, G_IO_ERROR_CLOSED,
|
||||||
_("File enumerator is already closed"));
|
_("File enumerator is already closed"));
|
||||||
return;
|
return;
|
||||||
@ -469,9 +461,8 @@ g_file_enumerator_close_async (GFileEnumerator *enumerator,
|
|||||||
|
|
||||||
if (enumerator->priv->pending)
|
if (enumerator->priv->pending)
|
||||||
{
|
{
|
||||||
g_simple_async_report_error_in_idle (G_OBJECT (enumerator),
|
g_task_report_new_error (enumerator, callback, user_data,
|
||||||
callback,
|
g_file_enumerator_close_async,
|
||||||
user_data,
|
|
||||||
G_IO_ERROR, G_IO_ERROR_PENDING,
|
G_IO_ERROR, G_IO_ERROR_PENDING,
|
||||||
_("File enumerator has outstanding operation"));
|
_("File enumerator has outstanding operation"));
|
||||||
return;
|
return;
|
||||||
@ -518,6 +509,8 @@ g_file_enumerator_close_finish (GFileEnumerator *enumerator,
|
|||||||
|
|
||||||
if (g_async_result_legacy_propagate_error (result, error))
|
if (g_async_result_legacy_propagate_error (result, error))
|
||||||
return FALSE;
|
return FALSE;
|
||||||
|
else if (g_async_result_is_tagged (result, g_file_enumerator_close_async))
|
||||||
|
return g_task_propagate_boolean (G_TASK (result), error);
|
||||||
|
|
||||||
class = G_FILE_ENUMERATOR_GET_CLASS (enumerator);
|
class = G_FILE_ENUMERATOR_GET_CLASS (enumerator);
|
||||||
return class->close_finish (enumerator, result, error);
|
return class->close_finish (enumerator, result, error);
|
||||||
@ -620,40 +613,29 @@ g_file_enumerator_get_child (GFileEnumerator *enumerator,
|
|||||||
g_file_info_get_name (info));
|
g_file_info_get_name (info));
|
||||||
}
|
}
|
||||||
|
|
||||||
typedef struct {
|
|
||||||
int num_files;
|
|
||||||
GList *files;
|
|
||||||
} NextAsyncOp;
|
|
||||||
|
|
||||||
static void
|
static void
|
||||||
next_async_op_free (NextAsyncOp *op)
|
next_async_op_free (GList *files)
|
||||||
{
|
{
|
||||||
/* Free the list, if finish wasn't called */
|
g_list_free_full (files, g_object_unref);
|
||||||
g_list_free_full (op->files, g_object_unref);
|
|
||||||
|
|
||||||
g_free (op);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
static void
|
static void
|
||||||
next_files_thread (GSimpleAsyncResult *res,
|
next_files_thread (GTask *task,
|
||||||
GObject *object,
|
gpointer source_object,
|
||||||
|
gpointer task_data,
|
||||||
GCancellable *cancellable)
|
GCancellable *cancellable)
|
||||||
{
|
{
|
||||||
NextAsyncOp *op;
|
GFileEnumerator *enumerator = source_object;
|
||||||
|
int num_files = GPOINTER_TO_INT (task_data);
|
||||||
GFileEnumeratorClass *class;
|
GFileEnumeratorClass *class;
|
||||||
|
GList *files = NULL;
|
||||||
GError *error = NULL;
|
GError *error = NULL;
|
||||||
GFileInfo *info;
|
GFileInfo *info;
|
||||||
GFileEnumerator *enumerator;
|
|
||||||
int i;
|
int i;
|
||||||
|
|
||||||
enumerator = G_FILE_ENUMERATOR (object);
|
class = G_FILE_ENUMERATOR_GET_CLASS (enumerator);
|
||||||
op = g_simple_async_result_get_op_res_gpointer (res);
|
|
||||||
|
|
||||||
class = G_FILE_ENUMERATOR_GET_CLASS (object);
|
for (i = 0; i < num_files; i++)
|
||||||
|
|
||||||
for (i = 0; i < op->num_files; i++)
|
|
||||||
{
|
{
|
||||||
if (g_cancellable_set_error_if_cancelled (cancellable, &error))
|
if (g_cancellable_set_error_if_cancelled (cancellable, &error))
|
||||||
info = NULL;
|
info = NULL;
|
||||||
@ -665,8 +647,7 @@ next_files_thread (GSimpleAsyncResult *res,
|
|||||||
/* If we get an error after first file, return that on next operation */
|
/* If we get an error after first file, return that on next operation */
|
||||||
if (error != NULL && i > 0)
|
if (error != NULL && i > 0)
|
||||||
{
|
{
|
||||||
if (error->domain == G_IO_ERROR &&
|
if (g_error_matches (error, G_IO_ERROR, G_IO_ERROR_CANCELLED))
|
||||||
error->code == G_IO_ERROR_CANCELLED)
|
|
||||||
g_error_free (error); /* Never propagate cancel errors to other call */
|
g_error_free (error); /* Never propagate cancel errors to other call */
|
||||||
else
|
else
|
||||||
enumerator->priv->outstanding_error = error;
|
enumerator->priv->outstanding_error = error;
|
||||||
@ -676,8 +657,13 @@ next_files_thread (GSimpleAsyncResult *res,
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
op->files = g_list_prepend (op->files, info);
|
files = g_list_prepend (files, info);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (error)
|
||||||
|
g_task_return_error (task, error);
|
||||||
|
else
|
||||||
|
g_task_return_pointer (task, files, (GDestroyNotify)next_async_op_free);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
@ -688,19 +674,14 @@ g_file_enumerator_real_next_files_async (GFileEnumerator *enumerator,
|
|||||||
GAsyncReadyCallback callback,
|
GAsyncReadyCallback callback,
|
||||||
gpointer user_data)
|
gpointer user_data)
|
||||||
{
|
{
|
||||||
GSimpleAsyncResult *res;
|
GTask *task;
|
||||||
NextAsyncOp *op;
|
|
||||||
|
|
||||||
op = g_new0 (NextAsyncOp, 1);
|
task = g_task_new (enumerator, cancellable, callback, user_data);
|
||||||
|
g_task_set_task_data (task, GINT_TO_POINTER (num_files), NULL);
|
||||||
|
g_task_set_priority (task, io_priority);
|
||||||
|
|
||||||
op->num_files = num_files;
|
g_task_run_in_thread (task, next_files_thread);
|
||||||
op->files = NULL;
|
g_object_unref (task);
|
||||||
|
|
||||||
res = g_simple_async_result_new (G_OBJECT (enumerator), callback, user_data, g_file_enumerator_real_next_files_async);
|
|
||||||
g_simple_async_result_set_op_res_gpointer (res, op, (GDestroyNotify) next_async_op_free);
|
|
||||||
|
|
||||||
g_simple_async_result_run_in_thread (res, next_files_thread, io_priority, cancellable);
|
|
||||||
g_object_unref (res);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static GList *
|
static GList *
|
||||||
@ -708,44 +689,30 @@ g_file_enumerator_real_next_files_finish (GFileEnumerator *enumer
|
|||||||
GAsyncResult *result,
|
GAsyncResult *result,
|
||||||
GError **error)
|
GError **error)
|
||||||
{
|
{
|
||||||
GSimpleAsyncResult *simple = G_SIMPLE_ASYNC_RESULT (result);
|
g_return_val_if_fail (g_task_is_valid (result, enumerator), NULL);
|
||||||
NextAsyncOp *op;
|
|
||||||
GList *res;
|
|
||||||
|
|
||||||
g_warn_if_fail (g_simple_async_result_get_source_tag (simple) ==
|
return g_task_propagate_pointer (G_TASK (result), error);
|
||||||
g_file_enumerator_real_next_files_async);
|
|
||||||
|
|
||||||
if (g_simple_async_result_propagate_error (simple, error))
|
|
||||||
return NULL;
|
|
||||||
|
|
||||||
op = g_simple_async_result_get_op_res_gpointer (simple);
|
|
||||||
|
|
||||||
res = op->files;
|
|
||||||
op->files = NULL;
|
|
||||||
return res;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
close_async_thread (GSimpleAsyncResult *res,
|
close_async_thread (GTask *task,
|
||||||
GObject *object,
|
gpointer source_object,
|
||||||
|
gpointer task_data,
|
||||||
GCancellable *cancellable)
|
GCancellable *cancellable)
|
||||||
{
|
{
|
||||||
|
GFileEnumerator *enumerator = source_object;
|
||||||
GFileEnumeratorClass *class;
|
GFileEnumeratorClass *class;
|
||||||
GError *error = NULL;
|
GError *error = NULL;
|
||||||
gboolean result;
|
gboolean result;
|
||||||
|
|
||||||
/* Auto handling of cancelation disabled, and ignore
|
class = G_FILE_ENUMERATOR_GET_CLASS (enumerator);
|
||||||
cancellation, since we want to close things anyway, although
|
result = class->close_fn (enumerator, cancellable, &error);
|
||||||
possibly in a quick-n-dirty way. At least we never want to leak
|
if (result)
|
||||||
open handles */
|
g_task_return_boolean (task, TRUE);
|
||||||
|
else
|
||||||
class = G_FILE_ENUMERATOR_GET_CLASS (object);
|
g_task_return_error (task, error);
|
||||||
result = class->close_fn (G_FILE_ENUMERATOR (object), cancellable, &error);
|
|
||||||
if (!result)
|
|
||||||
g_simple_async_result_take_error (res, error);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
static void
|
static void
|
||||||
g_file_enumerator_real_close_async (GFileEnumerator *enumerator,
|
g_file_enumerator_real_close_async (GFileEnumerator *enumerator,
|
||||||
int io_priority,
|
int io_priority,
|
||||||
@ -753,20 +720,13 @@ g_file_enumerator_real_close_async (GFileEnumerator *enumerator,
|
|||||||
GAsyncReadyCallback callback,
|
GAsyncReadyCallback callback,
|
||||||
gpointer user_data)
|
gpointer user_data)
|
||||||
{
|
{
|
||||||
GSimpleAsyncResult *res;
|
GTask *task;
|
||||||
|
|
||||||
res = g_simple_async_result_new (G_OBJECT (enumerator),
|
task = g_task_new (enumerator, cancellable, callback, user_data);
|
||||||
callback,
|
g_task_set_priority (task, io_priority);
|
||||||
user_data,
|
|
||||||
g_file_enumerator_real_close_async);
|
|
||||||
|
|
||||||
g_simple_async_result_set_handle_cancellation (res, FALSE);
|
g_task_run_in_thread (task, close_async_thread);
|
||||||
|
g_object_unref (task);
|
||||||
g_simple_async_result_run_in_thread (res,
|
|
||||||
close_async_thread,
|
|
||||||
io_priority,
|
|
||||||
cancellable);
|
|
||||||
g_object_unref (res);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static gboolean
|
static gboolean
|
||||||
@ -774,13 +734,7 @@ g_file_enumerator_real_close_finish (GFileEnumerator *enumerator,
|
|||||||
GAsyncResult *result,
|
GAsyncResult *result,
|
||||||
GError **error)
|
GError **error)
|
||||||
{
|
{
|
||||||
GSimpleAsyncResult *simple = G_SIMPLE_ASYNC_RESULT (result);
|
g_return_val_if_fail (g_task_is_valid (result, enumerator), FALSE);
|
||||||
|
|
||||||
g_warn_if_fail (g_simple_async_result_get_source_tag (simple) ==
|
return g_task_propagate_boolean (G_TASK (result), error);
|
||||||
g_file_enumerator_real_close_async);
|
|
||||||
|
|
||||||
if (g_simple_async_result_propagate_error (simple, error))
|
|
||||||
return FALSE;
|
|
||||||
|
|
||||||
return TRUE;
|
|
||||||
}
|
}
|
||||||
|
@ -28,7 +28,7 @@
|
|||||||
#include "glibintl.h"
|
#include "glibintl.h"
|
||||||
#include "gloadableicon.h"
|
#include "gloadableicon.h"
|
||||||
#include "ginputstream.h"
|
#include "ginputstream.h"
|
||||||
#include "gsimpleasyncresult.h"
|
#include "gtask.h"
|
||||||
#include "gioerror.h"
|
#include "gioerror.h"
|
||||||
|
|
||||||
|
|
||||||
@ -283,19 +283,6 @@ g_file_icon_load (GLoadableIcon *icon,
|
|||||||
return G_INPUT_STREAM (stream);
|
return G_INPUT_STREAM (stream);
|
||||||
}
|
}
|
||||||
|
|
||||||
typedef struct {
|
|
||||||
GLoadableIcon *icon;
|
|
||||||
GAsyncReadyCallback callback;
|
|
||||||
gpointer user_data;
|
|
||||||
} LoadData;
|
|
||||||
|
|
||||||
static void
|
|
||||||
load_data_free (LoadData *data)
|
|
||||||
{
|
|
||||||
g_object_unref (data->icon);
|
|
||||||
g_free (data);
|
|
||||||
}
|
|
||||||
|
|
||||||
static void
|
static void
|
||||||
load_async_callback (GObject *source_object,
|
load_async_callback (GObject *source_object,
|
||||||
GAsyncResult *res,
|
GAsyncResult *res,
|
||||||
@ -303,35 +290,14 @@ load_async_callback (GObject *source_object,
|
|||||||
{
|
{
|
||||||
GFileInputStream *stream;
|
GFileInputStream *stream;
|
||||||
GError *error = NULL;
|
GError *error = NULL;
|
||||||
GSimpleAsyncResult *simple;
|
GTask *task = user_data;
|
||||||
LoadData *data = user_data;
|
|
||||||
|
|
||||||
stream = g_file_read_finish (G_FILE (source_object), res, &error);
|
stream = g_file_read_finish (G_FILE (source_object), res, &error);
|
||||||
|
|
||||||
if (stream == NULL)
|
if (stream == NULL)
|
||||||
{
|
g_task_return_error (task, error);
|
||||||
simple = g_simple_async_result_new_take_error (G_OBJECT (data->icon),
|
|
||||||
data->callback,
|
|
||||||
data->user_data,
|
|
||||||
error);
|
|
||||||
}
|
|
||||||
else
|
else
|
||||||
{
|
g_task_return_pointer (task, stream, g_object_unref);
|
||||||
simple = g_simple_async_result_new (G_OBJECT (data->icon),
|
g_object_unref (task);
|
||||||
data->callback,
|
|
||||||
data->user_data,
|
|
||||||
g_file_icon_load_async);
|
|
||||||
|
|
||||||
g_simple_async_result_set_op_res_gpointer (simple,
|
|
||||||
stream,
|
|
||||||
g_object_unref);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
g_simple_async_result_complete (simple);
|
|
||||||
|
|
||||||
load_data_free (data);
|
|
||||||
g_object_unref (simple);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
@ -342,17 +308,13 @@ g_file_icon_load_async (GLoadableIcon *icon,
|
|||||||
gpointer user_data)
|
gpointer user_data)
|
||||||
{
|
{
|
||||||
GFileIcon *file_icon = G_FILE_ICON (icon);
|
GFileIcon *file_icon = G_FILE_ICON (icon);
|
||||||
LoadData *data;
|
GTask *task;
|
||||||
|
|
||||||
data = g_new0 (LoadData, 1);
|
task = g_task_new (icon, cancellable, callback, user_data);
|
||||||
data->icon = g_object_ref (icon);
|
|
||||||
data->callback = callback;
|
|
||||||
data->user_data = user_data;
|
|
||||||
|
|
||||||
g_file_read_async (file_icon->file, 0,
|
g_file_read_async (file_icon->file, 0,
|
||||||
cancellable,
|
cancellable,
|
||||||
load_async_callback, data);
|
load_async_callback, task);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static GInputStream *
|
static GInputStream *
|
||||||
@ -361,19 +323,12 @@ g_file_icon_load_finish (GLoadableIcon *icon,
|
|||||||
char **type,
|
char **type,
|
||||||
GError **error)
|
GError **error)
|
||||||
{
|
{
|
||||||
GSimpleAsyncResult *simple = G_SIMPLE_ASYNC_RESULT (res);
|
g_return_val_if_fail (g_task_is_valid (res, icon), NULL);
|
||||||
gpointer op;
|
|
||||||
|
|
||||||
g_warn_if_fail (g_simple_async_result_get_source_tag (simple) == g_file_icon_load_async);
|
|
||||||
|
|
||||||
if (type)
|
if (type)
|
||||||
*type = NULL;
|
*type = NULL;
|
||||||
|
|
||||||
op = g_simple_async_result_get_op_res_gpointer (simple);
|
return g_task_propagate_pointer (G_TASK (res), error);
|
||||||
if (op)
|
|
||||||
return g_object_ref (op);
|
|
||||||
|
|
||||||
return NULL;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
|
@ -25,9 +25,9 @@
|
|||||||
#include <glib.h>
|
#include <glib.h>
|
||||||
#include <gfileinputstream.h>
|
#include <gfileinputstream.h>
|
||||||
#include <gseekable.h>
|
#include <gseekable.h>
|
||||||
#include "gsimpleasyncresult.h"
|
|
||||||
#include "gcancellable.h"
|
#include "gcancellable.h"
|
||||||
#include "gasyncresult.h"
|
#include "gasyncresult.h"
|
||||||
|
#include "gtask.h"
|
||||||
#include "gioerror.h"
|
#include "gioerror.h"
|
||||||
#include "glibintl.h"
|
#include "glibintl.h"
|
||||||
|
|
||||||
@ -215,9 +215,8 @@ g_file_input_stream_query_info_async (GFileInputStream *stream,
|
|||||||
|
|
||||||
if (!g_input_stream_set_pending (input_stream, &error))
|
if (!g_input_stream_set_pending (input_stream, &error))
|
||||||
{
|
{
|
||||||
g_simple_async_report_take_gerror_in_idle (G_OBJECT (stream),
|
g_task_report_error (stream, callback, user_data,
|
||||||
callback,
|
g_file_input_stream_query_info_async,
|
||||||
user_data,
|
|
||||||
error);
|
error);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@ -253,6 +252,8 @@ g_file_input_stream_query_info_finish (GFileInputStream *stream,
|
|||||||
|
|
||||||
if (g_async_result_legacy_propagate_error (result, error))
|
if (g_async_result_legacy_propagate_error (result, error))
|
||||||
return NULL;
|
return NULL;
|
||||||
|
else if (g_async_result_is_tagged (result, g_file_input_stream_query_info_async))
|
||||||
|
return g_task_propagate_pointer (G_TASK (result), error);
|
||||||
|
|
||||||
class = G_FILE_INPUT_STREAM_GET_CLASS (stream);
|
class = G_FILE_INPUT_STREAM_GET_CLASS (stream);
|
||||||
return class->query_info_finish (stream, result, error);
|
return class->query_info_finish (stream, result, error);
|
||||||
@ -379,45 +380,29 @@ g_file_input_stream_seekable_truncate (GSeekable *seekable,
|
|||||||
* Default implementation of async ops *
|
* Default implementation of async ops *
|
||||||
********************************************/
|
********************************************/
|
||||||
|
|
||||||
typedef struct {
|
|
||||||
char *attributes;
|
|
||||||
GFileInfo *info;
|
|
||||||
} QueryInfoAsyncData;
|
|
||||||
|
|
||||||
static void
|
static void
|
||||||
query_info_data_free (QueryInfoAsyncData *data)
|
query_info_async_thread (GTask *task,
|
||||||
{
|
gpointer source_object,
|
||||||
if (data->info)
|
gpointer task_data,
|
||||||
g_object_unref (data->info);
|
|
||||||
g_free (data->attributes);
|
|
||||||
g_free (data);
|
|
||||||
}
|
|
||||||
|
|
||||||
static void
|
|
||||||
query_info_async_thread (GSimpleAsyncResult *res,
|
|
||||||
GObject *object,
|
|
||||||
GCancellable *cancellable)
|
GCancellable *cancellable)
|
||||||
{
|
{
|
||||||
|
GFileInputStream *stream = source_object;
|
||||||
|
const char *attributes = task_data;
|
||||||
GFileInputStreamClass *class;
|
GFileInputStreamClass *class;
|
||||||
GError *error = NULL;
|
GError *error = NULL;
|
||||||
QueryInfoAsyncData *data;
|
GFileInfo *info = NULL;
|
||||||
GFileInfo *info;
|
|
||||||
|
|
||||||
data = g_simple_async_result_get_op_res_gpointer (res);
|
class = G_FILE_INPUT_STREAM_GET_CLASS (stream);
|
||||||
|
|
||||||
info = NULL;
|
|
||||||
|
|
||||||
class = G_FILE_INPUT_STREAM_GET_CLASS (object);
|
|
||||||
if (class->query_info)
|
if (class->query_info)
|
||||||
info = class->query_info (G_FILE_INPUT_STREAM (object), data->attributes, cancellable, &error);
|
info = class->query_info (stream, attributes, cancellable, &error);
|
||||||
else
|
else
|
||||||
g_set_error_literal (&error, G_IO_ERROR, G_IO_ERROR_NOT_SUPPORTED,
|
g_set_error_literal (&error, G_IO_ERROR, G_IO_ERROR_NOT_SUPPORTED,
|
||||||
_("Stream doesn't support query_info"));
|
_("Stream doesn't support query_info"));
|
||||||
|
|
||||||
if (info == NULL)
|
if (info == NULL)
|
||||||
g_simple_async_result_take_error (res, error);
|
g_task_return_error (task, error);
|
||||||
else
|
else
|
||||||
data->info = info;
|
g_task_return_pointer (task, info, g_object_unref);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
@ -428,17 +413,14 @@ g_file_input_stream_real_query_info_async (GFileInputStream *stream,
|
|||||||
GAsyncReadyCallback callback,
|
GAsyncReadyCallback callback,
|
||||||
gpointer user_data)
|
gpointer user_data)
|
||||||
{
|
{
|
||||||
GSimpleAsyncResult *res;
|
GTask *task;
|
||||||
QueryInfoAsyncData *data;
|
|
||||||
|
|
||||||
data = g_new0 (QueryInfoAsyncData, 1);
|
task = g_task_new (stream, cancellable, callback, user_data);
|
||||||
data->attributes = g_strdup (attributes);
|
g_task_set_task_data (task, g_strdup (attributes), g_free);
|
||||||
|
g_task_set_priority (task, io_priority);
|
||||||
|
|
||||||
res = g_simple_async_result_new (G_OBJECT (stream), callback, user_data, g_file_input_stream_real_query_info_async);
|
g_task_run_in_thread (task, query_info_async_thread);
|
||||||
g_simple_async_result_set_op_res_gpointer (res, data, (GDestroyNotify)query_info_data_free);
|
g_object_unref (task);
|
||||||
|
|
||||||
g_simple_async_result_run_in_thread (res, query_info_async_thread, io_priority, cancellable);
|
|
||||||
g_object_unref (res);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static GFileInfo *
|
static GFileInfo *
|
||||||
@ -446,17 +428,7 @@ g_file_input_stream_real_query_info_finish (GFileInputStream *stream,
|
|||||||
GAsyncResult *res,
|
GAsyncResult *res,
|
||||||
GError **error)
|
GError **error)
|
||||||
{
|
{
|
||||||
GSimpleAsyncResult *simple = G_SIMPLE_ASYNC_RESULT (res);
|
g_return_val_if_fail (g_task_is_valid (res, stream), NULL);
|
||||||
QueryInfoAsyncData *data;
|
|
||||||
|
|
||||||
g_warn_if_fail (g_simple_async_result_get_source_tag (simple) == g_file_input_stream_real_query_info_async);
|
return g_task_propagate_pointer (G_TASK (res), error);
|
||||||
|
|
||||||
if (g_simple_async_result_propagate_error (simple, error))
|
|
||||||
return NULL;
|
|
||||||
|
|
||||||
data = g_simple_async_result_get_op_res_gpointer (simple);
|
|
||||||
if (data->info)
|
|
||||||
return g_object_ref (data->info);
|
|
||||||
|
|
||||||
return NULL;
|
|
||||||
}
|
}
|
||||||
|
@ -25,8 +25,8 @@
|
|||||||
#include <glib.h>
|
#include <glib.h>
|
||||||
#include <gfileiostream.h>
|
#include <gfileiostream.h>
|
||||||
#include <gseekable.h>
|
#include <gseekable.h>
|
||||||
#include "gsimpleasyncresult.h"
|
|
||||||
#include "gasyncresult.h"
|
#include "gasyncresult.h"
|
||||||
|
#include "gtask.h"
|
||||||
#include "gcancellable.h"
|
#include "gcancellable.h"
|
||||||
#include "gioerror.h"
|
#include "gioerror.h"
|
||||||
#include "gfileoutputstream.h"
|
#include "gfileoutputstream.h"
|
||||||
@ -227,9 +227,8 @@ g_file_io_stream_query_info_async (GFileIOStream *stream,
|
|||||||
|
|
||||||
if (!g_io_stream_set_pending (io_stream, &error))
|
if (!g_io_stream_set_pending (io_stream, &error))
|
||||||
{
|
{
|
||||||
g_simple_async_report_take_gerror_in_idle (G_OBJECT (stream),
|
g_task_report_error (stream, callback, user_data,
|
||||||
callback,
|
g_file_io_stream_query_info_async,
|
||||||
user_data,
|
|
||||||
error);
|
error);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@ -267,6 +266,8 @@ g_file_io_stream_query_info_finish (GFileIOStream *stream,
|
|||||||
|
|
||||||
if (g_async_result_legacy_propagate_error (result, error))
|
if (g_async_result_legacy_propagate_error (result, error))
|
||||||
return NULL;
|
return NULL;
|
||||||
|
else if (g_async_result_is_tagged (result, g_file_io_stream_query_info_async))
|
||||||
|
return g_task_propagate_pointer (G_TASK (result), error);
|
||||||
|
|
||||||
class = G_FILE_IO_STREAM_GET_CLASS (stream);
|
class = G_FILE_IO_STREAM_GET_CLASS (stream);
|
||||||
return class->query_info_finish (stream, result, error);
|
return class->query_info_finish (stream, result, error);
|
||||||
|
@ -25,8 +25,8 @@
|
|||||||
#include <glib.h>
|
#include <glib.h>
|
||||||
#include <gfileoutputstream.h>
|
#include <gfileoutputstream.h>
|
||||||
#include <gseekable.h>
|
#include <gseekable.h>
|
||||||
#include "gsimpleasyncresult.h"
|
|
||||||
#include "gasyncresult.h"
|
#include "gasyncresult.h"
|
||||||
|
#include "gtask.h"
|
||||||
#include "gcancellable.h"
|
#include "gcancellable.h"
|
||||||
#include "gioerror.h"
|
#include "gioerror.h"
|
||||||
#include "glibintl.h"
|
#include "glibintl.h"
|
||||||
@ -225,9 +225,8 @@ g_file_output_stream_query_info_async (GFileOutputStream *stream,
|
|||||||
|
|
||||||
if (!g_output_stream_set_pending (output_stream, &error))
|
if (!g_output_stream_set_pending (output_stream, &error))
|
||||||
{
|
{
|
||||||
g_simple_async_report_take_gerror_in_idle (G_OBJECT (stream),
|
g_task_report_error (stream, callback, user_data,
|
||||||
callback,
|
g_file_output_stream_query_info_async,
|
||||||
user_data,
|
|
||||||
error);
|
error);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@ -263,6 +262,8 @@ g_file_output_stream_query_info_finish (GFileOutputStream *stream,
|
|||||||
|
|
||||||
if (g_async_result_legacy_propagate_error (result, error))
|
if (g_async_result_legacy_propagate_error (result, error))
|
||||||
return NULL;
|
return NULL;
|
||||||
|
else if (g_async_result_is_tagged (result, g_file_output_stream_query_info_async))
|
||||||
|
return g_task_propagate_pointer (G_TASK (result), error);
|
||||||
|
|
||||||
class = G_FILE_OUTPUT_STREAM_GET_CLASS (stream);
|
class = G_FILE_OUTPUT_STREAM_GET_CLASS (stream);
|
||||||
return class->query_info_finish (stream, result, error);
|
return class->query_info_finish (stream, result, error);
|
||||||
@ -482,45 +483,29 @@ g_file_output_stream_seekable_truncate (GSeekable *seekable,
|
|||||||
* Default implementation of async ops *
|
* Default implementation of async ops *
|
||||||
********************************************/
|
********************************************/
|
||||||
|
|
||||||
typedef struct {
|
|
||||||
char *attributes;
|
|
||||||
GFileInfo *info;
|
|
||||||
} QueryInfoAsyncData;
|
|
||||||
|
|
||||||
static void
|
static void
|
||||||
query_info_data_free (QueryInfoAsyncData *data)
|
query_info_async_thread (GTask *task,
|
||||||
{
|
gpointer source_object,
|
||||||
if (data->info)
|
gpointer task_data,
|
||||||
g_object_unref (data->info);
|
|
||||||
g_free (data->attributes);
|
|
||||||
g_free (data);
|
|
||||||
}
|
|
||||||
|
|
||||||
static void
|
|
||||||
query_info_async_thread (GSimpleAsyncResult *res,
|
|
||||||
GObject *object,
|
|
||||||
GCancellable *cancellable)
|
GCancellable *cancellable)
|
||||||
{
|
{
|
||||||
|
GFileOutputStream *stream = source_object;
|
||||||
|
const char *attributes = task_data;
|
||||||
GFileOutputStreamClass *class;
|
GFileOutputStreamClass *class;
|
||||||
GError *error = NULL;
|
GError *error = NULL;
|
||||||
QueryInfoAsyncData *data;
|
GFileInfo *info = NULL;
|
||||||
GFileInfo *info;
|
|
||||||
|
|
||||||
data = g_simple_async_result_get_op_res_gpointer (res);
|
class = G_FILE_OUTPUT_STREAM_GET_CLASS (stream);
|
||||||
|
|
||||||
info = NULL;
|
|
||||||
|
|
||||||
class = G_FILE_OUTPUT_STREAM_GET_CLASS (object);
|
|
||||||
if (class->query_info)
|
if (class->query_info)
|
||||||
info = class->query_info (G_FILE_OUTPUT_STREAM (object), data->attributes, cancellable, &error);
|
info = class->query_info (stream, attributes, cancellable, &error);
|
||||||
else
|
else
|
||||||
g_set_error_literal (&error, G_IO_ERROR, G_IO_ERROR_NOT_SUPPORTED,
|
g_set_error_literal (&error, G_IO_ERROR, G_IO_ERROR_NOT_SUPPORTED,
|
||||||
_("Stream doesn't support query_info"));
|
_("Stream doesn't support query_info"));
|
||||||
|
|
||||||
if (info == NULL)
|
if (info == NULL)
|
||||||
g_simple_async_result_take_error (res, error);
|
g_task_return_error (task, error);
|
||||||
else
|
else
|
||||||
data->info = info;
|
g_task_return_pointer (task, info, g_object_unref);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
@ -531,17 +516,14 @@ g_file_output_stream_real_query_info_async (GFileOutputStream *stream,
|
|||||||
GAsyncReadyCallback callback,
|
GAsyncReadyCallback callback,
|
||||||
gpointer user_data)
|
gpointer user_data)
|
||||||
{
|
{
|
||||||
GSimpleAsyncResult *res;
|
GTask *task;
|
||||||
QueryInfoAsyncData *data;
|
|
||||||
|
|
||||||
data = g_new0 (QueryInfoAsyncData, 1);
|
task = g_task_new (stream, cancellable, callback, user_data);
|
||||||
data->attributes = g_strdup (attributes);
|
g_task_set_task_data (task, g_strdup (attributes), g_free);
|
||||||
|
g_task_set_priority (task, io_priority);
|
||||||
|
|
||||||
res = g_simple_async_result_new (G_OBJECT (stream), callback, user_data, g_file_output_stream_real_query_info_async);
|
g_task_run_in_thread (task, query_info_async_thread);
|
||||||
g_simple_async_result_set_op_res_gpointer (res, data, (GDestroyNotify)query_info_data_free);
|
g_object_unref (task);
|
||||||
|
|
||||||
g_simple_async_result_run_in_thread (res, query_info_async_thread, io_priority, cancellable);
|
|
||||||
g_object_unref (res);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static GFileInfo *
|
static GFileInfo *
|
||||||
@ -549,17 +531,7 @@ g_file_output_stream_real_query_info_finish (GFileOutputStream *stream,
|
|||||||
GAsyncResult *res,
|
GAsyncResult *res,
|
||||||
GError **error)
|
GError **error)
|
||||||
{
|
{
|
||||||
GSimpleAsyncResult *simple = G_SIMPLE_ASYNC_RESULT (res);
|
g_return_val_if_fail (g_task_is_valid (res, stream), NULL);
|
||||||
QueryInfoAsyncData *data;
|
|
||||||
|
|
||||||
g_warn_if_fail (g_simple_async_result_get_source_tag (simple) == g_file_output_stream_real_query_info_async);
|
return g_task_propagate_pointer (G_TASK (res), error);
|
||||||
|
|
||||||
if (g_simple_async_result_propagate_error (simple, error))
|
|
||||||
return NULL;
|
|
||||||
|
|
||||||
data = g_simple_async_result_get_op_res_gpointer (simple);
|
|
||||||
if (data->info)
|
|
||||||
return g_object_ref (data->info);
|
|
||||||
|
|
||||||
return NULL;
|
|
||||||
}
|
}
|
||||||
|
@ -21,10 +21,10 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
#include "config.h"
|
#include "config.h"
|
||||||
#include "gasyncresult.h"
|
|
||||||
#include "gsimpleasyncresult.h"
|
|
||||||
#include "gicon.h"
|
#include "gicon.h"
|
||||||
#include "gloadableicon.h"
|
#include "gloadableicon.h"
|
||||||
|
#include "gasyncresult.h"
|
||||||
|
#include "gtask.h"
|
||||||
#include "glibintl.h"
|
#include "glibintl.h"
|
||||||
|
|
||||||
|
|
||||||
@ -156,43 +156,35 @@ g_loadable_icon_load_finish (GLoadableIcon *icon,
|
|||||||
typedef struct {
|
typedef struct {
|
||||||
int size;
|
int size;
|
||||||
char *type;
|
char *type;
|
||||||
GInputStream *stream;
|
|
||||||
} LoadData;
|
} LoadData;
|
||||||
|
|
||||||
static void
|
static void
|
||||||
load_data_free (LoadData *data)
|
load_data_free (LoadData *data)
|
||||||
{
|
{
|
||||||
if (data->stream)
|
|
||||||
g_object_unref (data->stream);
|
|
||||||
g_free (data->type);
|
g_free (data->type);
|
||||||
g_free (data);
|
g_free (data);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
load_async_thread (GSimpleAsyncResult *res,
|
load_async_thread (GTask *task,
|
||||||
GObject *object,
|
gpointer source_object,
|
||||||
|
gpointer task_data,
|
||||||
GCancellable *cancellable)
|
GCancellable *cancellable)
|
||||||
{
|
{
|
||||||
|
GLoadableIcon *icon = source_object;
|
||||||
|
LoadData *data = task_data;
|
||||||
GLoadableIconIface *iface;
|
GLoadableIconIface *iface;
|
||||||
GInputStream *stream;
|
GInputStream *stream;
|
||||||
LoadData *data;
|
|
||||||
GError *error = NULL;
|
GError *error = NULL;
|
||||||
char *type = NULL;
|
|
||||||
|
|
||||||
data = g_simple_async_result_get_op_res_gpointer (res);
|
iface = G_LOADABLE_ICON_GET_IFACE (icon);
|
||||||
|
stream = iface->load (icon, data->size, &data->type,
|
||||||
|
cancellable, &error);
|
||||||
|
|
||||||
iface = G_LOADABLE_ICON_GET_IFACE (object);
|
if (stream)
|
||||||
stream = iface->load (G_LOADABLE_ICON (object), data->size, &type, cancellable, &error);
|
g_task_return_pointer (task, stream, g_object_unref);
|
||||||
|
|
||||||
if (stream == NULL)
|
|
||||||
{
|
|
||||||
g_simple_async_result_take_error (res, error);
|
|
||||||
}
|
|
||||||
else
|
else
|
||||||
{
|
g_task_return_error (task, error);
|
||||||
data->stream = stream;
|
|
||||||
data->type = type;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -204,14 +196,14 @@ g_loadable_icon_real_load_async (GLoadableIcon *icon,
|
|||||||
GAsyncReadyCallback callback,
|
GAsyncReadyCallback callback,
|
||||||
gpointer user_data)
|
gpointer user_data)
|
||||||
{
|
{
|
||||||
GSimpleAsyncResult *res;
|
GTask *task;
|
||||||
LoadData *data;
|
LoadData *data;
|
||||||
|
|
||||||
res = g_simple_async_result_new (G_OBJECT (icon), callback, user_data, g_loadable_icon_real_load_async);
|
task = g_task_new (icon, cancellable, callback, user_data);
|
||||||
data = g_new0 (LoadData, 1);
|
data = g_new0 (LoadData, 1);
|
||||||
g_simple_async_result_set_op_res_gpointer (res, data, (GDestroyNotify) load_data_free);
|
g_task_set_task_data (task, data, (GDestroyNotify) load_data_free);
|
||||||
g_simple_async_result_run_in_thread (res, load_async_thread, 0, cancellable);
|
g_task_run_in_thread (task, load_async_thread);
|
||||||
g_object_unref (res);
|
g_object_unref (task);
|
||||||
}
|
}
|
||||||
|
|
||||||
static GInputStream *
|
static GInputStream *
|
||||||
@ -220,21 +212,21 @@ g_loadable_icon_real_load_finish (GLoadableIcon *icon,
|
|||||||
char **type,
|
char **type,
|
||||||
GError **error)
|
GError **error)
|
||||||
{
|
{
|
||||||
GSimpleAsyncResult *simple = G_SIMPLE_ASYNC_RESULT (res);
|
GTask *task;
|
||||||
LoadData *data;
|
LoadData *data;
|
||||||
|
GInputStream *stream;
|
||||||
|
|
||||||
g_warn_if_fail (g_simple_async_result_get_source_tag (simple) == g_loadable_icon_real_load_async);
|
g_return_val_if_fail (g_task_is_valid (res, icon), NULL);
|
||||||
|
|
||||||
if (g_simple_async_result_propagate_error (simple, error))
|
task = G_TASK (res);
|
||||||
return NULL;
|
data = g_task_get_task_data (task);
|
||||||
|
|
||||||
data = g_simple_async_result_get_op_res_gpointer (simple);
|
stream = g_task_propagate_pointer (task, error);
|
||||||
|
if (stream && type)
|
||||||
if (type)
|
|
||||||
{
|
{
|
||||||
*type = data->type;
|
*type = data->type;
|
||||||
data->type = NULL;
|
data->type = NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
return g_object_ref (data->stream);
|
return stream;
|
||||||
}
|
}
|
||||||
|
45
gio/gmount.c
45
gio/gmount.c
@ -31,7 +31,7 @@
|
|||||||
#include "gmountprivate.h"
|
#include "gmountprivate.h"
|
||||||
#include "gthemedicon.h"
|
#include "gthemedicon.h"
|
||||||
#include "gasyncresult.h"
|
#include "gasyncresult.h"
|
||||||
#include "gsimpleasyncresult.h"
|
#include "gtask.h"
|
||||||
#include "gioerror.h"
|
#include "gioerror.h"
|
||||||
#include "glibintl.h"
|
#include "glibintl.h"
|
||||||
|
|
||||||
@ -52,7 +52,7 @@
|
|||||||
*
|
*
|
||||||
* Unmounting a #GMount instance is an asynchronous operation. For
|
* Unmounting a #GMount instance is an asynchronous operation. For
|
||||||
* more information about asynchronous operations, see #GAsyncResult
|
* more information about asynchronous operations, see #GAsyncResult
|
||||||
* and #GSimpleAsyncResult. To unmount a #GMount instance, first call
|
* and #GTask. To unmount a #GMount instance, first call
|
||||||
* g_mount_unmount_with_operation() with (at least) the #GMount instance and a
|
* g_mount_unmount_with_operation() with (at least) the #GMount instance and a
|
||||||
* #GAsyncReadyCallback. The callback will be fired when the
|
* #GAsyncReadyCallback. The callback will be fired when the
|
||||||
* operation has resolved (either with success or failure), and a
|
* operation has resolved (either with success or failure), and a
|
||||||
@ -386,14 +386,13 @@ g_mount_unmount (GMount *mount,
|
|||||||
|
|
||||||
if (iface->unmount == NULL)
|
if (iface->unmount == NULL)
|
||||||
{
|
{
|
||||||
g_simple_async_report_error_in_idle (G_OBJECT (mount),
|
g_task_report_new_error (mount, callback, user_data,
|
||||||
callback, user_data,
|
g_mount_unmount_with_operation,
|
||||||
G_IO_ERROR, G_IO_ERROR_NOT_SUPPORTED,
|
G_IO_ERROR, G_IO_ERROR_NOT_SUPPORTED,
|
||||||
/* Translators: This is an error
|
/* Translators: This is an error
|
||||||
* message for mount objects that
|
* message for mount objects that
|
||||||
* don't implement unmount. */
|
* don't implement unmount. */
|
||||||
_("mount doesn't implement \"unmount\""));
|
_("mount doesn't implement \"unmount\""));
|
||||||
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -426,6 +425,8 @@ g_mount_unmount_finish (GMount *mount,
|
|||||||
|
|
||||||
if (g_async_result_legacy_propagate_error (result, error))
|
if (g_async_result_legacy_propagate_error (result, error))
|
||||||
return FALSE;
|
return FALSE;
|
||||||
|
else if (g_async_result_is_tagged (result, g_mount_unmount_with_operation))
|
||||||
|
return g_task_propagate_boolean (G_TASK (result), error);
|
||||||
|
|
||||||
iface = G_MOUNT_GET_IFACE (mount);
|
iface = G_MOUNT_GET_IFACE (mount);
|
||||||
return (* iface->unmount_finish) (mount, result, error);
|
return (* iface->unmount_finish) (mount, result, error);
|
||||||
@ -461,14 +462,13 @@ g_mount_eject (GMount *mount,
|
|||||||
|
|
||||||
if (iface->eject == NULL)
|
if (iface->eject == NULL)
|
||||||
{
|
{
|
||||||
g_simple_async_report_error_in_idle (G_OBJECT (mount),
|
g_task_report_new_error (mount, callback, user_data,
|
||||||
callback, user_data,
|
g_mount_eject_with_operation,
|
||||||
G_IO_ERROR, G_IO_ERROR_NOT_SUPPORTED,
|
G_IO_ERROR, G_IO_ERROR_NOT_SUPPORTED,
|
||||||
/* Translators: This is an error
|
/* Translators: This is an error
|
||||||
* message for mount objects that
|
* message for mount objects that
|
||||||
* don't implement eject. */
|
* don't implement eject. */
|
||||||
_("mount doesn't implement \"eject\""));
|
_("mount doesn't implement \"eject\""));
|
||||||
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -501,6 +501,8 @@ g_mount_eject_finish (GMount *mount,
|
|||||||
|
|
||||||
if (g_async_result_legacy_propagate_error (result, error))
|
if (g_async_result_legacy_propagate_error (result, error))
|
||||||
return FALSE;
|
return FALSE;
|
||||||
|
else if (g_async_result_is_tagged (result, g_mount_eject_with_operation))
|
||||||
|
return g_task_propagate_boolean (G_TASK (result), error);
|
||||||
|
|
||||||
iface = G_MOUNT_GET_IFACE (mount);
|
iface = G_MOUNT_GET_IFACE (mount);
|
||||||
return (* iface->eject_finish) (mount, result, error);
|
return (* iface->eject_finish) (mount, result, error);
|
||||||
@ -538,14 +540,13 @@ g_mount_unmount_with_operation (GMount *mount,
|
|||||||
|
|
||||||
if (iface->unmount == NULL && iface->unmount_with_operation == NULL)
|
if (iface->unmount == NULL && iface->unmount_with_operation == NULL)
|
||||||
{
|
{
|
||||||
g_simple_async_report_error_in_idle (G_OBJECT (mount),
|
g_task_report_new_error (mount, callback, user_data,
|
||||||
callback, user_data,
|
g_mount_unmount_with_operation,
|
||||||
G_IO_ERROR, G_IO_ERROR_NOT_SUPPORTED,
|
G_IO_ERROR, G_IO_ERROR_NOT_SUPPORTED,
|
||||||
/* Translators: This is an error
|
/* Translators: This is an error
|
||||||
* message for mount objects that
|
* message for mount objects that
|
||||||
* don't implement any of unmount or unmount_with_operation. */
|
* don't implement any of unmount or unmount_with_operation. */
|
||||||
_("mount doesn't implement \"unmount\" or \"unmount_with_operation\""));
|
_("mount doesn't implement \"unmount\" or \"unmount_with_operation\""));
|
||||||
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -581,6 +582,8 @@ g_mount_unmount_with_operation_finish (GMount *mount,
|
|||||||
|
|
||||||
if (g_async_result_legacy_propagate_error (result, error))
|
if (g_async_result_legacy_propagate_error (result, error))
|
||||||
return FALSE;
|
return FALSE;
|
||||||
|
else if (g_async_result_is_tagged (result, g_mount_unmount_with_operation))
|
||||||
|
return g_task_propagate_boolean (G_TASK (result), error);
|
||||||
|
|
||||||
iface = G_MOUNT_GET_IFACE (mount);
|
iface = G_MOUNT_GET_IFACE (mount);
|
||||||
if (iface->unmount_with_operation_finish != NULL)
|
if (iface->unmount_with_operation_finish != NULL)
|
||||||
@ -622,8 +625,8 @@ g_mount_eject_with_operation (GMount *mount,
|
|||||||
|
|
||||||
if (iface->eject == NULL && iface->eject_with_operation == NULL)
|
if (iface->eject == NULL && iface->eject_with_operation == NULL)
|
||||||
{
|
{
|
||||||
g_simple_async_report_error_in_idle (G_OBJECT (mount),
|
g_task_report_new_error (mount, callback, user_data,
|
||||||
callback, user_data,
|
g_mount_eject_with_operation,
|
||||||
G_IO_ERROR, G_IO_ERROR_NOT_SUPPORTED,
|
G_IO_ERROR, G_IO_ERROR_NOT_SUPPORTED,
|
||||||
/* Translators: This is an error
|
/* Translators: This is an error
|
||||||
* message for mount objects that
|
* message for mount objects that
|
||||||
@ -664,6 +667,8 @@ g_mount_eject_with_operation_finish (GMount *mount,
|
|||||||
|
|
||||||
if (g_async_result_legacy_propagate_error (result, error))
|
if (g_async_result_legacy_propagate_error (result, error))
|
||||||
return FALSE;
|
return FALSE;
|
||||||
|
else if (g_async_result_is_tagged (result, g_mount_eject_with_operation))
|
||||||
|
return g_task_propagate_boolean (G_TASK (result), error);
|
||||||
|
|
||||||
iface = G_MOUNT_GET_IFACE (mount);
|
iface = G_MOUNT_GET_IFACE (mount);
|
||||||
if (iface->eject_with_operation_finish != NULL)
|
if (iface->eject_with_operation_finish != NULL)
|
||||||
@ -708,14 +713,13 @@ g_mount_remount (GMount *mount,
|
|||||||
|
|
||||||
if (iface->remount == NULL)
|
if (iface->remount == NULL)
|
||||||
{
|
{
|
||||||
g_simple_async_report_error_in_idle (G_OBJECT (mount),
|
g_task_report_new_error (mount, callback, user_data,
|
||||||
callback, user_data,
|
g_mount_remount,
|
||||||
G_IO_ERROR, G_IO_ERROR_NOT_SUPPORTED,
|
G_IO_ERROR, G_IO_ERROR_NOT_SUPPORTED,
|
||||||
/* Translators: This is an error
|
/* Translators: This is an error
|
||||||
* message for mount objects that
|
* message for mount objects that
|
||||||
* don't implement remount. */
|
* don't implement remount. */
|
||||||
_("mount doesn't implement \"remount\""));
|
_("mount doesn't implement \"remount\""));
|
||||||
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -746,6 +750,8 @@ g_mount_remount_finish (GMount *mount,
|
|||||||
|
|
||||||
if (g_async_result_legacy_propagate_error (result, error))
|
if (g_async_result_legacy_propagate_error (result, error))
|
||||||
return FALSE;
|
return FALSE;
|
||||||
|
else if (g_async_result_is_tagged (result, g_mount_remount))
|
||||||
|
return g_task_propagate_boolean (G_TASK (result), error);
|
||||||
|
|
||||||
iface = G_MOUNT_GET_IFACE (mount);
|
iface = G_MOUNT_GET_IFACE (mount);
|
||||||
return (* iface->remount_finish) (mount, result, error);
|
return (* iface->remount_finish) (mount, result, error);
|
||||||
@ -788,14 +794,13 @@ g_mount_guess_content_type (GMount *mount,
|
|||||||
|
|
||||||
if (iface->guess_content_type == NULL)
|
if (iface->guess_content_type == NULL)
|
||||||
{
|
{
|
||||||
g_simple_async_report_error_in_idle (G_OBJECT (mount),
|
g_task_report_new_error (mount, callback, user_data,
|
||||||
callback, user_data,
|
g_mount_guess_content_type,
|
||||||
G_IO_ERROR, G_IO_ERROR_NOT_SUPPORTED,
|
G_IO_ERROR, G_IO_ERROR_NOT_SUPPORTED,
|
||||||
/* Translators: This is an error
|
/* Translators: This is an error
|
||||||
* message for mount objects that
|
* message for mount objects that
|
||||||
* don't implement content type guessing. */
|
* don't implement content type guessing. */
|
||||||
_("mount doesn't implement content type guessing"));
|
_("mount doesn't implement content type guessing"));
|
||||||
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -832,6 +837,8 @@ g_mount_guess_content_type_finish (GMount *mount,
|
|||||||
|
|
||||||
if (g_async_result_legacy_propagate_error (result, error))
|
if (g_async_result_legacy_propagate_error (result, error))
|
||||||
return NULL;
|
return NULL;
|
||||||
|
else if (g_async_result_is_tagged (result, g_mount_guess_content_type))
|
||||||
|
return g_task_propagate_pointer (G_TASK (result), error);
|
||||||
|
|
||||||
iface = G_MOUNT_GET_IFACE (mount);
|
iface = G_MOUNT_GET_IFACE (mount);
|
||||||
return (* iface->guess_content_type_finish) (mount, result, error);
|
return (* iface->guess_content_type_finish) (mount, result, error);
|
||||||
|
113
gio/gunixmount.c
113
gio/gunixmount.c
@ -245,9 +245,6 @@ g_unix_mount_can_eject (GMount *mount)
|
|||||||
|
|
||||||
typedef struct {
|
typedef struct {
|
||||||
GUnixMount *unix_mount;
|
GUnixMount *unix_mount;
|
||||||
GAsyncReadyCallback callback;
|
|
||||||
gpointer user_data;
|
|
||||||
GCancellable *cancellable;
|
|
||||||
int error_fd;
|
int error_fd;
|
||||||
GIOChannel *error_channel;
|
GIOChannel *error_channel;
|
||||||
GSource *error_channel_source;
|
GSource *error_channel_source;
|
||||||
@ -256,34 +253,8 @@ typedef struct {
|
|||||||
} UnmountEjectOp;
|
} UnmountEjectOp;
|
||||||
|
|
||||||
static void
|
static void
|
||||||
eject_unmount_cb (GPid pid, gint status, gpointer user_data)
|
unmount_eject_op_free (UnmountEjectOp *data)
|
||||||
{
|
{
|
||||||
UnmountEjectOp *data = user_data;
|
|
||||||
GSimpleAsyncResult *simple;
|
|
||||||
|
|
||||||
if (WEXITSTATUS (status) != 0)
|
|
||||||
{
|
|
||||||
GError *error;
|
|
||||||
error = g_error_new_literal (G_IO_ERROR,
|
|
||||||
G_IO_ERROR_FAILED,
|
|
||||||
data->error_string->str);
|
|
||||||
simple = g_simple_async_result_new_from_error (G_OBJECT (data->unix_mount),
|
|
||||||
data->callback,
|
|
||||||
data->user_data,
|
|
||||||
error);
|
|
||||||
g_error_free (error);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
simple = g_simple_async_result_new (G_OBJECT (data->unix_mount),
|
|
||||||
data->callback,
|
|
||||||
data->user_data,
|
|
||||||
NULL);
|
|
||||||
}
|
|
||||||
|
|
||||||
g_simple_async_result_complete (simple);
|
|
||||||
g_object_unref (simple);
|
|
||||||
|
|
||||||
if (data->error_channel_source)
|
if (data->error_channel_source)
|
||||||
{
|
{
|
||||||
g_source_destroy (data->error_channel_source);
|
g_source_destroy (data->error_channel_source);
|
||||||
@ -293,21 +264,46 @@ eject_unmount_cb (GPid pid, gint status, gpointer user_data)
|
|||||||
g_string_free (data->error_string, TRUE);
|
g_string_free (data->error_string, TRUE);
|
||||||
g_strfreev (data->argv);
|
g_strfreev (data->argv);
|
||||||
close (data->error_fd);
|
close (data->error_fd);
|
||||||
g_spawn_close_pid (pid);
|
|
||||||
g_free (data);
|
g_free (data);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void
|
||||||
|
eject_unmount_cb (GPid pid, gint status, gpointer user_data)
|
||||||
|
{
|
||||||
|
GTask *task = user_data;
|
||||||
|
UnmountEjectOp *data = g_task_get_task_data (task);
|
||||||
|
|
||||||
|
if (g_task_return_error_if_cancelled (task))
|
||||||
|
return;
|
||||||
|
|
||||||
|
g_spawn_close_pid (pid);
|
||||||
|
|
||||||
|
if (WEXITSTATUS (status) != 0)
|
||||||
|
{
|
||||||
|
g_task_return_new_error (task, G_IO_ERROR, G_IO_ERROR_FAILED,
|
||||||
|
"%s", data->error_string->str);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
g_task_return_boolean (task, TRUE);
|
||||||
|
|
||||||
|
g_object_unref (task);
|
||||||
|
}
|
||||||
|
|
||||||
static gboolean
|
static gboolean
|
||||||
eject_unmount_read_error (GIOChannel *channel,
|
eject_unmount_read_error (GIOChannel *channel,
|
||||||
GIOCondition condition,
|
GIOCondition condition,
|
||||||
gpointer user_data)
|
gpointer user_data)
|
||||||
{
|
{
|
||||||
UnmountEjectOp *data = user_data;
|
GTask *task = user_data;
|
||||||
|
UnmountEjectOp *data = g_task_get_task_data (task);
|
||||||
char buf[BUFSIZ];
|
char buf[BUFSIZ];
|
||||||
gsize bytes_read;
|
gsize bytes_read;
|
||||||
GError *error;
|
GError *error;
|
||||||
GIOStatus status;
|
GIOStatus status;
|
||||||
|
|
||||||
|
if (g_task_return_error_if_cancelled (task))
|
||||||
|
return FALSE;
|
||||||
|
|
||||||
error = NULL;
|
error = NULL;
|
||||||
read:
|
read:
|
||||||
status = g_io_channel_read_chars (channel, buf, sizeof (buf), &bytes_read, &error);
|
status = g_io_channel_read_chars (channel, buf, sizeof (buf), &bytes_read, &error);
|
||||||
@ -341,11 +337,15 @@ read:
|
|||||||
static gboolean
|
static gboolean
|
||||||
eject_unmount_do_cb (gpointer user_data)
|
eject_unmount_do_cb (gpointer user_data)
|
||||||
{
|
{
|
||||||
UnmountEjectOp *data = (UnmountEjectOp *) user_data;
|
GTask *task = user_data;
|
||||||
|
UnmountEjectOp *data = g_task_get_task_data (task);
|
||||||
GPid child_pid;
|
GPid child_pid;
|
||||||
GSource *child_watch;
|
GSource *child_watch;
|
||||||
GError *error = NULL;
|
GError *error = NULL;
|
||||||
|
|
||||||
|
if (g_task_return_error_if_cancelled (task))
|
||||||
|
return G_SOURCE_REMOVE;
|
||||||
|
|
||||||
if (!g_spawn_async_with_pipes (NULL, /* working dir */
|
if (!g_spawn_async_with_pipes (NULL, /* working dir */
|
||||||
data->argv,
|
data->argv,
|
||||||
NULL, /* envp */
|
NULL, /* envp */
|
||||||
@ -369,33 +369,19 @@ eject_unmount_do_cb (gpointer user_data)
|
|||||||
goto handle_error;
|
goto handle_error;
|
||||||
|
|
||||||
data->error_channel_source = g_io_create_watch (data->error_channel, G_IO_IN);
|
data->error_channel_source = g_io_create_watch (data->error_channel, G_IO_IN);
|
||||||
g_source_set_callback (data->error_channel_source,
|
g_task_attach_source (task, data->error_channel_source,
|
||||||
(GSourceFunc) eject_unmount_read_error, data, NULL);
|
(GSourceFunc) eject_unmount_read_error);
|
||||||
g_source_attach (data->error_channel_source, g_main_context_get_thread_default ());
|
|
||||||
|
|
||||||
child_watch = g_child_watch_source_new (child_pid);
|
child_watch = g_child_watch_source_new (child_pid);
|
||||||
g_source_set_callback (child_watch, (GSourceFunc) eject_unmount_cb, data, NULL);
|
g_task_attach_source (task, data->error_channel_source,
|
||||||
g_source_attach (child_watch, g_main_context_get_thread_default ());
|
(GSourceFunc) eject_unmount_cb);
|
||||||
g_source_unref (child_watch);
|
g_source_unref (child_watch);
|
||||||
|
|
||||||
handle_error:
|
handle_error:
|
||||||
if (error != NULL) {
|
if (error != NULL)
|
||||||
GSimpleAsyncResult *simple;
|
{
|
||||||
simple = g_simple_async_result_new_take_error (G_OBJECT (data->unix_mount),
|
g_task_return_error (task, error);
|
||||||
data->callback,
|
g_object_unref (task);
|
||||||
data->user_data,
|
|
||||||
error);
|
|
||||||
g_simple_async_result_complete (simple);
|
|
||||||
g_object_unref (simple);
|
|
||||||
|
|
||||||
if (data->error_string != NULL)
|
|
||||||
g_string_free (data->error_string, TRUE);
|
|
||||||
|
|
||||||
if (data->error_channel != NULL)
|
|
||||||
g_io_channel_unref (data->error_channel);
|
|
||||||
|
|
||||||
g_strfreev (data->argv);
|
|
||||||
g_free (data);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return G_SOURCE_REMOVE;
|
return G_SOURCE_REMOVE;
|
||||||
@ -410,20 +396,23 @@ eject_unmount_do (GMount *mount,
|
|||||||
{
|
{
|
||||||
GUnixMount *unix_mount = G_UNIX_MOUNT (mount);
|
GUnixMount *unix_mount = G_UNIX_MOUNT (mount);
|
||||||
UnmountEjectOp *data;
|
UnmountEjectOp *data;
|
||||||
|
GTask *task;
|
||||||
|
GSource *timeout;
|
||||||
|
|
||||||
data = g_new0 (UnmountEjectOp, 1);
|
data = g_new0 (UnmountEjectOp, 1);
|
||||||
data->unix_mount = unix_mount;
|
|
||||||
data->callback = callback;
|
|
||||||
data->user_data = user_data;
|
|
||||||
data->cancellable = cancellable;
|
|
||||||
data->argv = g_strdupv (argv);
|
data->argv = g_strdupv (argv);
|
||||||
|
|
||||||
|
task = g_task_new (mount, cancellable, callback, user_data);
|
||||||
|
g_task_set_task_data (task, data, (GDestroyNotify)unmount_eject_op_free);
|
||||||
|
|
||||||
if (unix_mount->volume_monitor != NULL)
|
if (unix_mount->volume_monitor != NULL)
|
||||||
g_signal_emit_by_name (unix_mount->volume_monitor, "mount-pre-unmount", mount);
|
g_signal_emit_by_name (unix_mount->volume_monitor, "mount-pre-unmount", mount);
|
||||||
|
|
||||||
g_signal_emit_by_name (mount, "pre-unmount", 0);
|
g_signal_emit_by_name (mount, "pre-unmount", 0);
|
||||||
|
|
||||||
g_timeout_add (500, (GSourceFunc) eject_unmount_do_cb, data);
|
timeout = g_timeout_source_new (500);
|
||||||
|
g_task_attach_source (task, timeout, (GSourceFunc) eject_unmount_do_cb);
|
||||||
|
g_source_unref (timeout);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
@ -449,7 +438,7 @@ g_unix_mount_unmount_finish (GMount *mount,
|
|||||||
GAsyncResult *result,
|
GAsyncResult *result,
|
||||||
GError **error)
|
GError **error)
|
||||||
{
|
{
|
||||||
return TRUE;
|
return g_task_propagate_boolean (G_TASK (result), error);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
@ -475,7 +464,7 @@ g_unix_mount_eject_finish (GMount *mount,
|
|||||||
GAsyncResult *result,
|
GAsyncResult *result,
|
||||||
GError **error)
|
GError **error)
|
||||||
{
|
{
|
||||||
return TRUE;
|
return g_task_propagate_boolean (G_TASK (result), error);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
|
@ -36,7 +36,7 @@
|
|||||||
#include "gthemedicon.h"
|
#include "gthemedicon.h"
|
||||||
#include "gvolume.h"
|
#include "gvolume.h"
|
||||||
#include "gvolumemonitor.h"
|
#include "gvolumemonitor.h"
|
||||||
#include "gsimpleasyncresult.h"
|
#include "gtask.h"
|
||||||
#include "gioerror.h"
|
#include "gioerror.h"
|
||||||
#include "glibintl.h"
|
#include "glibintl.h"
|
||||||
/* for BUFSIZ */
|
/* for BUFSIZ */
|
||||||
@ -270,9 +270,6 @@ _g_unix_volume_has_mount_path (GUnixVolume *volume,
|
|||||||
|
|
||||||
typedef struct {
|
typedef struct {
|
||||||
GUnixVolume *unix_volume;
|
GUnixVolume *unix_volume;
|
||||||
GAsyncReadyCallback callback;
|
|
||||||
gpointer user_data;
|
|
||||||
GCancellable *cancellable;
|
|
||||||
int error_fd;
|
int error_fd;
|
||||||
GIOChannel *error_channel;
|
GIOChannel *error_channel;
|
||||||
GSource *error_channel_source;
|
GSource *error_channel_source;
|
||||||
@ -280,54 +277,53 @@ typedef struct {
|
|||||||
} EjectMountOp;
|
} EjectMountOp;
|
||||||
|
|
||||||
static void
|
static void
|
||||||
eject_mount_cb (GPid pid,
|
eject_mount_op_free (EjectMountOp *data)
|
||||||
gint status,
|
|
||||||
gpointer user_data)
|
|
||||||
{
|
{
|
||||||
EjectMountOp *data = user_data;
|
if (data->error_string != NULL)
|
||||||
GSimpleAsyncResult *simple;
|
g_string_free (data->error_string, TRUE);
|
||||||
|
|
||||||
if (WEXITSTATUS (status) != 0)
|
if (data->error_channel != NULL)
|
||||||
{
|
g_io_channel_unref (data->error_channel);
|
||||||
GError *error;
|
|
||||||
error = g_error_new_literal (G_IO_ERROR,
|
|
||||||
G_IO_ERROR_FAILED,
|
|
||||||
data->error_string->str);
|
|
||||||
simple = g_simple_async_result_new_from_error (G_OBJECT (data->unix_volume),
|
|
||||||
data->callback,
|
|
||||||
data->user_data,
|
|
||||||
error);
|
|
||||||
g_error_free (error);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
simple = g_simple_async_result_new (G_OBJECT (data->unix_volume),
|
|
||||||
data->callback,
|
|
||||||
data->user_data,
|
|
||||||
NULL);
|
|
||||||
}
|
|
||||||
|
|
||||||
g_simple_async_result_complete (simple);
|
|
||||||
g_object_unref (simple);
|
|
||||||
|
|
||||||
if (data->error_channel_source)
|
if (data->error_channel_source)
|
||||||
{
|
{
|
||||||
g_source_destroy (data->error_channel_source);
|
g_source_destroy (data->error_channel_source);
|
||||||
g_source_unref (data->error_channel_source);
|
g_source_unref (data->error_channel_source);
|
||||||
}
|
}
|
||||||
g_io_channel_unref (data->error_channel);
|
|
||||||
g_string_free (data->error_string, TRUE);
|
if (data->error_fd != -1)
|
||||||
close (data->error_fd);
|
close (data->error_fd);
|
||||||
g_spawn_close_pid (pid);
|
|
||||||
g_free (data);
|
g_free (data);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void
|
||||||
|
eject_mount_cb (GPid pid,
|
||||||
|
gint status,
|
||||||
|
gpointer user_data)
|
||||||
|
{
|
||||||
|
GTask *task = user_data;
|
||||||
|
EjectMountOp *data = g_task_get_task_data (task);
|
||||||
|
|
||||||
|
if (WEXITSTATUS (status) != 0)
|
||||||
|
{
|
||||||
|
g_task_return_new_error (task,
|
||||||
|
G_IO_ERROR,
|
||||||
|
G_IO_ERROR_FAILED,
|
||||||
|
data->error_string->str);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
g_task_return_boolean (task, TRUE);
|
||||||
|
g_object_unref (task);
|
||||||
|
}
|
||||||
|
|
||||||
static gboolean
|
static gboolean
|
||||||
eject_mount_read_error (GIOChannel *channel,
|
eject_mount_read_error (GIOChannel *channel,
|
||||||
GIOCondition condition,
|
GIOCondition condition,
|
||||||
gpointer user_data)
|
gpointer user_data)
|
||||||
{
|
{
|
||||||
EjectMountOp *data = user_data;
|
GTask *task = user_data;
|
||||||
|
EjectMountOp *data = g_task_get_task_data (task);
|
||||||
char buf[BUFSIZ];
|
char buf[BUFSIZ];
|
||||||
gsize bytes_read;
|
gsize bytes_read;
|
||||||
GError *error;
|
GError *error;
|
||||||
@ -371,6 +367,7 @@ eject_mount_do (GVolume *volume,
|
|||||||
char **argv)
|
char **argv)
|
||||||
{
|
{
|
||||||
GUnixVolume *unix_volume = G_UNIX_VOLUME (volume);
|
GUnixVolume *unix_volume = G_UNIX_VOLUME (volume);
|
||||||
|
GTask *task;
|
||||||
EjectMountOp *data;
|
EjectMountOp *data;
|
||||||
GPid child_pid;
|
GPid child_pid;
|
||||||
GSource *child_watch;
|
GSource *child_watch;
|
||||||
@ -378,9 +375,10 @@ eject_mount_do (GVolume *volume,
|
|||||||
|
|
||||||
data = g_new0 (EjectMountOp, 1);
|
data = g_new0 (EjectMountOp, 1);
|
||||||
data->unix_volume = unix_volume;
|
data->unix_volume = unix_volume;
|
||||||
data->callback = callback;
|
data->error_fd = -1;
|
||||||
data->user_data = user_data;
|
|
||||||
data->cancellable = cancellable;
|
task = g_task_new (unix_volume, cancellable, callback, user_data);
|
||||||
|
g_task_set_task_data (task, data, (GDestroyNotify) eject_mount_op_free);
|
||||||
|
|
||||||
error = NULL;
|
error = NULL;
|
||||||
if (!g_spawn_async_with_pipes (NULL, /* working dir */
|
if (!g_spawn_async_with_pipes (NULL, /* working dir */
|
||||||
@ -407,33 +405,18 @@ eject_mount_do (GVolume *volume,
|
|||||||
goto handle_error;
|
goto handle_error;
|
||||||
|
|
||||||
data->error_channel_source = g_io_create_watch (data->error_channel, G_IO_IN);
|
data->error_channel_source = g_io_create_watch (data->error_channel, G_IO_IN);
|
||||||
g_source_set_callback (data->error_channel_source,
|
g_task_attach_source (task, data->error_channel_source,
|
||||||
(GSourceFunc) eject_mount_read_error, data, NULL);
|
(GSourceFunc) eject_mount_read_error);
|
||||||
g_source_attach (data->error_channel_source, g_main_context_get_thread_default ());
|
|
||||||
|
|
||||||
child_watch = g_child_watch_source_new (child_pid);
|
child_watch = g_child_watch_source_new (child_pid);
|
||||||
g_source_set_callback (child_watch, (GSourceFunc) eject_mount_cb, data, NULL);
|
g_task_attach_source (task, child_watch, (GSourceFunc) eject_mount_cb);
|
||||||
g_source_attach (child_watch, g_main_context_get_thread_default ());
|
|
||||||
g_source_unref (child_watch);
|
g_source_unref (child_watch);
|
||||||
|
|
||||||
handle_error:
|
handle_error:
|
||||||
if (error != NULL)
|
if (error != NULL)
|
||||||
{
|
{
|
||||||
GSimpleAsyncResult *simple;
|
g_task_return_error (task, error);
|
||||||
simple = g_simple_async_result_new_take_error (G_OBJECT (data->unix_volume),
|
g_object_unref (task);
|
||||||
data->callback,
|
|
||||||
data->user_data,
|
|
||||||
error);
|
|
||||||
g_simple_async_result_complete (simple);
|
|
||||||
g_object_unref (simple);
|
|
||||||
|
|
||||||
if (data->error_string != NULL)
|
|
||||||
g_string_free (data->error_string, TRUE);
|
|
||||||
|
|
||||||
if (data->error_channel != NULL)
|
|
||||||
g_io_channel_unref (data->error_channel);
|
|
||||||
|
|
||||||
g_free (data);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -26,7 +26,7 @@
|
|||||||
#include "gvolume.h"
|
#include "gvolume.h"
|
||||||
#include "gthemedicon.h"
|
#include "gthemedicon.h"
|
||||||
#include "gasyncresult.h"
|
#include "gasyncresult.h"
|
||||||
#include "gsimpleasyncresult.h"
|
#include "gtask.h"
|
||||||
#include "gioerror.h"
|
#include "gioerror.h"
|
||||||
#include "glibintl.h"
|
#include "glibintl.h"
|
||||||
|
|
||||||
@ -42,9 +42,9 @@
|
|||||||
*
|
*
|
||||||
* Mounting a #GVolume instance is an asynchronous operation. For more
|
* Mounting a #GVolume instance is an asynchronous operation. For more
|
||||||
* information about asynchronous operations, see #GAsyncResult and
|
* information about asynchronous operations, see #GAsyncResult and
|
||||||
* #GSimpleAsyncResult. To mount a #GVolume, first call
|
* #GTask. To mount a #GVolume, first call g_volume_mount() with (at
|
||||||
* g_volume_mount() with (at least) the #GVolume instance, optionally
|
* least) the #GVolume instance, optionally a #GMountOperation object
|
||||||
* a #GMountOperation object and a #GAsyncReadyCallback.
|
* and a #GAsyncReadyCallback.
|
||||||
*
|
*
|
||||||
* Typically, one will only want to pass %NULL for the
|
* Typically, one will only want to pass %NULL for the
|
||||||
* #GMountOperation if automounting all volumes when a desktop session
|
* #GMountOperation if automounting all volumes when a desktop session
|
||||||
@ -359,10 +359,10 @@ g_volume_mount (GVolume *volume,
|
|||||||
|
|
||||||
if (iface->mount_fn == NULL)
|
if (iface->mount_fn == NULL)
|
||||||
{
|
{
|
||||||
g_simple_async_report_error_in_idle (G_OBJECT (volume), callback, user_data,
|
g_task_report_new_error (volume, callback, user_data,
|
||||||
|
g_volume_mount,
|
||||||
G_IO_ERROR, G_IO_ERROR_NOT_SUPPORTED,
|
G_IO_ERROR, G_IO_ERROR_NOT_SUPPORTED,
|
||||||
_("volume doesn't implement mount"));
|
_("volume doesn't implement mount"));
|
||||||
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -397,6 +397,8 @@ g_volume_mount_finish (GVolume *volume,
|
|||||||
|
|
||||||
if (g_async_result_legacy_propagate_error (result, error))
|
if (g_async_result_legacy_propagate_error (result, error))
|
||||||
return FALSE;
|
return FALSE;
|
||||||
|
else if (g_async_result_is_tagged (result, g_volume_mount))
|
||||||
|
return g_task_propagate_boolean (G_TASK (result), error);
|
||||||
|
|
||||||
iface = G_VOLUME_GET_IFACE (volume);
|
iface = G_VOLUME_GET_IFACE (volume);
|
||||||
return (* iface->mount_finish) (volume, result, error);
|
return (* iface->mount_finish) (volume, result, error);
|
||||||
@ -431,10 +433,10 @@ g_volume_eject (GVolume *volume,
|
|||||||
|
|
||||||
if (iface->eject == NULL)
|
if (iface->eject == NULL)
|
||||||
{
|
{
|
||||||
g_simple_async_report_error_in_idle (G_OBJECT (volume), callback, user_data,
|
g_task_report_new_error (volume, callback, user_data,
|
||||||
|
g_volume_eject_with_operation,
|
||||||
G_IO_ERROR, G_IO_ERROR_NOT_SUPPORTED,
|
G_IO_ERROR, G_IO_ERROR_NOT_SUPPORTED,
|
||||||
_("volume doesn't implement eject"));
|
_("volume doesn't implement eject"));
|
||||||
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -466,6 +468,8 @@ g_volume_eject_finish (GVolume *volume,
|
|||||||
|
|
||||||
if (g_async_result_legacy_propagate_error (result, error))
|
if (g_async_result_legacy_propagate_error (result, error))
|
||||||
return FALSE;
|
return FALSE;
|
||||||
|
if (g_async_result_is_tagged (result, g_volume_eject_with_operation))
|
||||||
|
return g_task_propagate_boolean (G_TASK (result), error);
|
||||||
|
|
||||||
iface = G_VOLUME_GET_IFACE (volume);
|
iface = G_VOLUME_GET_IFACE (volume);
|
||||||
return (* iface->eject_finish) (volume, result, error);
|
return (* iface->eject_finish) (volume, result, error);
|
||||||
@ -503,8 +507,8 @@ g_volume_eject_with_operation (GVolume *volume,
|
|||||||
|
|
||||||
if (iface->eject == NULL && iface->eject_with_operation == NULL)
|
if (iface->eject == NULL && iface->eject_with_operation == NULL)
|
||||||
{
|
{
|
||||||
g_simple_async_report_error_in_idle (G_OBJECT (volume),
|
g_task_report_new_error (volume, callback, user_data,
|
||||||
callback, user_data,
|
g_volume_eject_with_operation,
|
||||||
G_IO_ERROR, G_IO_ERROR_NOT_SUPPORTED,
|
G_IO_ERROR, G_IO_ERROR_NOT_SUPPORTED,
|
||||||
/* Translators: This is an error
|
/* Translators: This is an error
|
||||||
* message for volume objects that
|
* message for volume objects that
|
||||||
@ -545,6 +549,8 @@ g_volume_eject_with_operation_finish (GVolume *volume,
|
|||||||
|
|
||||||
if (g_async_result_legacy_propagate_error (result, error))
|
if (g_async_result_legacy_propagate_error (result, error))
|
||||||
return FALSE;
|
return FALSE;
|
||||||
|
else if (g_async_result_is_tagged (result, g_volume_eject_with_operation))
|
||||||
|
return g_task_propagate_boolean (G_TASK (result), error);
|
||||||
|
|
||||||
iface = G_VOLUME_GET_IFACE (volume);
|
iface = G_VOLUME_GET_IFACE (volume);
|
||||||
if (iface->eject_with_operation_finish != NULL)
|
if (iface->eject_with_operation_finish != NULL)
|
||||||
|
Loading…
Reference in New Issue
Block a user