filebrowser: don't use deprecated GIOScheduler

2d1eb80d3d
This commit is contained in:
JosephMcc 2017-02-13 20:24:42 -08:00
parent 9637840886
commit 87238194c3
1 changed files with 106 additions and 100 deletions

View File

@ -195,6 +195,8 @@ static void model_check_dummy (XedFileBrowserStore
static void next_files_async (GFileEnumerator *enumerator, static void next_files_async (GFileEnumerator *enumerator,
AsyncNode *async); AsyncNode *async);
static void delete_files (AsyncData *data);
G_DEFINE_DYNAMIC_TYPE_EXTENDED (XedFileBrowserStore, xed_file_browser_store, G_DEFINE_DYNAMIC_TYPE_EXTENDED (XedFileBrowserStore, xed_file_browser_store,
G_TYPE_OBJECT, G_TYPE_OBJECT,
0, 0,
@ -3655,93 +3657,101 @@ emit_no_trash (AsyncData *data)
return ret; return ret;
} }
typedef struct static void
delete_file_finished (GFile *file,
GAsyncResult *res,
AsyncData *data)
{ {
XedFileBrowserStore *model; GError *error = NULL;
GFile *file; gboolean ok;
} IdleDelete;
static gboolean if (data->trash)
file_deleted (IdleDelete *data)
{ {
FileBrowserNode *node; ok = g_file_trash_finish (file, res, &error);
node = model_find_node (data->model, NULL, data->file); }
else
{
ok = g_file_delete_finish (file, res, &error);
}
if (ok)
{
/* Remove the file from the model */
FileBrowserNode *node = model_find_node (data->model, NULL, file);
if (node != NULL) if (node != NULL)
{ {
model_remove_node (data->model, node, NULL, TRUE); model_remove_node (data->model, node, NULL, TRUE);
} }
return FALSE; /* Process the next file */
data->iter = data->iter->next;
} }
else if (!ok && error != NULL)
static gboolean
delete_files (GIOSchedulerJob *job,
GCancellable *cancellable,
AsyncData *data)
{ {
GFile *file; gint code = error->code;
GError *error = NULL;
gboolean ret;
gint code;
IdleDelete delete;
/* Check if our job is done */
if (!data->iter)
{
return FALSE;
}
/* Move a file to the trash */
file = G_FILE (data->iter->data);
if (data->trash)
{
ret = g_file_trash (file, cancellable, &error);
}
else
{
ret = g_file_delete (file, cancellable, &error);
}
if (ret)
{
delete.model = data->model;
delete.file = file;
/* Remove the file from the model in the main loop */
g_io_scheduler_job_send_to_mainloop (job, (GSourceFunc)file_deleted, &delete, NULL);
}
else if (!ret && error)
{
code = error->code;
g_error_free (error); g_error_free (error);
if (data->trash && code == G_IO_ERROR_NOT_SUPPORTED) if (data->trash && code == G_IO_ERROR_NOT_SUPPORTED)
{ {
/* Trash is not supported on this system ... */ /* Trash is not supported on this system. Ask the user
if (g_io_scheduler_job_send_to_mainloop (job, (GSourceFunc)emit_no_trash, data, NULL)) * if he wants to delete completely the files instead.
*/
if (emit_no_trash (data))
{ {
/* Changes this into a delete job */ /* Changes this into a delete job */
data->trash = FALSE; data->trash = FALSE;
data->iter = data->files; data->iter = data->files;
return TRUE;
} }
else
{
/* End the job */ /* End the job */
return FALSE; async_data_free (data);
return;
}
} }
else if (code == G_IO_ERROR_CANCELLED) else if (code == G_IO_ERROR_CANCELLED)
{ {
/* Job has been cancelled, just let the job end */ /* Job has been cancelled, end the job */
return FALSE; async_data_free (data);
return;
} }
} }
/* Process the next item */ /* Continue the job */
data->iter = data->iter->next; delete_files (data);
return TRUE; }
static void
delete_files (AsyncData *data)
{
GFile *file;
/* Check if our job is done */
if (data->iter == NULL)
{
async_data_free (data);
return;
}
file = G_FILE (data->iter->data);
if (data->trash)
{
g_file_trash_async (file,
G_PRIORITY_DEFAULT,
data->cancellable,
(GAsyncReadyCallback)delete_file_finished,
data);
}
else
{
g_file_delete_async (file,
G_PRIORITY_DEFAULT,
data->cancellable,
(GAsyncReadyCallback)delete_file_finished,
data);
}
} }
XedFileBrowserStoreResult XedFileBrowserStoreResult
@ -3801,11 +3811,7 @@ xed_file_browser_store_delete_all (XedFileBrowserStore *model,
model->priv->async_handles = g_slist_prepend (model->priv->async_handles, data); model->priv->async_handles = g_slist_prepend (model->priv->async_handles, data);
g_io_scheduler_push_job ((GIOSchedulerJobFunc)delete_files, delete_files (data);
data,
(GDestroyNotify)async_data_free,
G_PRIORITY_DEFAULT,
data->cancellable);
g_list_free (rows); g_list_free (rows);
return XED_FILE_BROWSER_STORE_RESULT_OK; return XED_FILE_BROWSER_STORE_RESULT_OK;