diff --git a/thunar/thunar-io-jobs.c b/thunar/thunar-io-jobs.c index 859bdef..7784dc0 100644 --- a/thunar/thunar-io-jobs.c +++ b/thunar/thunar-io-jobs.c @@ -197,7 +197,12 @@ again: } } else - g_object_unref (stream); + { + g_object_unref (stream); + + /* register new file */ + thunar_job_add_new_file (job, lp->data); + } } /* check if we have failed */ @@ -211,9 +216,6 @@ again: if (exo_job_is_cancelled (EXO_JOB (job))) return FALSE; - /* emit the "new-files" signal with the given file list */ - thunar_job_new_files (THUNAR_JOB (job), file_list); - return TRUE; } @@ -334,6 +336,11 @@ again: goto again; } } + else + { + /* register new file */ + thunar_job_add_new_file (job, lp->data); + } } /* check if we have failed */ @@ -346,9 +353,6 @@ again: /* check if the job was cancelled */ if (exo_job_is_cancelled (EXO_JOB (job))) return FALSE; - - /* emit the "new-files" signal with the given file list */ - thunar_job_new_files (THUNAR_JOB (job), file_list); return TRUE; } @@ -429,6 +433,9 @@ again: /* notify the thumbnail cache that the corresponding thumbnail can also * be deleted now */ thunar_thumbnail_cache_delete_file (thumbnail_cache, lp->data); + + /* notify file changed */ + thunar_job_changed_file (job, lp->data); } else { @@ -668,7 +675,6 @@ _thunar_io_jobs_link (ThunarJob *job, ThunarApplication *application; GError *err = NULL; GFile *real_target_file; - GList *new_files_list = NULL; GList *source_file_list; GList *sp; GList *target_file_list; @@ -708,8 +714,8 @@ _thunar_io_jobs_link (ThunarJob *job, /* queue the file for the folder update unless it was skipped */ if (sp->data != real_target_file) { - new_files_list = thunar_g_file_list_prepend (new_files_list, - real_target_file); + /* register new file */ + thunar_job_add_new_file (job, real_target_file); /* notify the thumbnail cache that we need to copy the original * thumbnail for the symlink to have one too */ @@ -728,14 +734,11 @@ _thunar_io_jobs_link (ThunarJob *job, if (err != NULL) { - thunar_g_file_list_free (new_files_list); g_propagate_error (error, err); return FALSE; } else { - thunar_job_new_files (THUNAR_JOB (job), new_files_list); - thunar_g_file_list_free (new_files_list); return TRUE; } } @@ -792,6 +795,9 @@ _thunar_io_jobs_trash (ThunarJob *job, /* update the thumbnail cache */ thunar_thumbnail_cache_cleanup_file (thumbnail_cache, lp->data); + + /* notify file changed */ + thunar_job_changed_file (job, lp->data); } /* release the thumbnail cache */ diff --git a/thunar/thunar-job.c b/thunar/thunar-job.c index 0cd0389..18bb9c4 100644 --- a/thunar/thunar-job.c +++ b/thunar/thunar-job.c @@ -35,6 +35,7 @@ #include #include #include +#include @@ -49,6 +50,7 @@ enum ASK_REPLACE, FILES_READY, NEW_FILES, + RELOAD_FOLDER, LAST_SIGNAL, }; @@ -61,6 +63,9 @@ static ThunarJobResponse thunar_job_real_ask (ThunarJob *job static ThunarJobResponse thunar_job_real_ask_replace (ThunarJob *job, ThunarFile *source_file, ThunarFile *target_file); +static void thunar_job_reload_folder (ThunarJob *job, + GFile *path, + void *user_data); @@ -70,6 +75,7 @@ struct _ThunarJobPrivate ThunarJobResponse earlier_ask_overwrite_response; ThunarJobResponse earlier_ask_skip_response; GList *total_files; + GList *new_files; }; @@ -202,6 +208,21 @@ thunar_job_class_init (ThunarJobClass *klass) G_SIGNAL_NO_HOOKS, 0, NULL, NULL, g_cclosure_marshal_VOID__POINTER, G_TYPE_NONE, 1, G_TYPE_POINTER); + + /** + * ThunarJob::reload-folder: + * @job : a #ThunarJob. + * @path : a #GFile that was added/removed/changed + * + * This is an internal signal emitted by the job as it modifies the filesystem. + * Its handler initiates a reload of the parent #ThunarFolder of @path. + **/ + job_signals[RELOAD_FOLDER] = + g_signal_new (I_("reload-folder"), + G_TYPE_FROM_CLASS (klass), + G_SIGNAL_NO_HOOKS, 0, NULL, NULL, + g_cclosure_marshal_VOID__POINTER, + G_TYPE_NONE, 1, G_TYPE_POINTER); } @@ -213,6 +234,9 @@ thunar_job_init (ThunarJob *job) job->priv->earlier_ask_create_response = 0; job->priv->earlier_ask_overwrite_response = 0; job->priv->earlier_ask_skip_response = 0; + job->priv->new_files = NULL; + + g_signal_connect (G_OBJECT (job), "reload-folder", G_CALLBACK (thunar_job_reload_folder), NULL); } @@ -220,6 +244,8 @@ thunar_job_init (ThunarJob *job) static void thunar_job_finalize (GObject *object) { + thunar_g_file_list_free (THUNAR_JOB (object)->priv->new_files); + (*G_OBJECT_CLASS (thunar_job_parent_class)->finalize) (object); } @@ -533,22 +559,37 @@ thunar_job_files_ready (ThunarJob *job, void -thunar_job_new_files (ThunarJob *job, - const GList *file_list) +thunar_job_new_files (ThunarJob *job) { _thunar_return_if_fail (THUNAR_IS_JOB (job)); /* check if we have any files */ - if (G_LIKELY (file_list != NULL)) + if (G_LIKELY (job->priv->new_files != NULL)) { /* emit the "new-files" signal */ - exo_job_emit (EXO_JOB (job), job_signals[NEW_FILES], 0, file_list); + exo_job_emit (EXO_JOB (job), job_signals[NEW_FILES], 0, job->priv->new_files); } } void +thunar_job_add_new_file (ThunarJob *job, + GFile *file) +{ + _thunar_return_if_fail (THUNAR_IS_JOB (job)); + _thunar_return_if_fail (G_IS_FILE (file)); + + /* remember new file */ + job->priv->new_files = thunar_g_file_list_prepend (job->priv->new_files, file); + + /* consider changed */ + thunar_job_changed_file (job, file); +} + + + +void thunar_job_set_total_files (ThunarJob *job, GList *total_files) { @@ -599,3 +640,52 @@ thunar_job_processing_file (ThunarJob *job, } } } + + + +void +thunar_job_changed_file (ThunarJob *job, + GFile *path) +{ + _thunar_return_if_fail (THUNAR_IS_JOB (job)); + _thunar_return_if_fail (G_IS_FILE (path)); + + /* emit the "reload-folder" signal to be caught by our closure in the main loop */ + exo_job_emit (EXO_JOB (job), job_signals[RELOAD_FOLDER], 0, path); +} + + + +static void +thunar_job_reload_folder (ThunarJob *job, GFile *path, void *user_data) +{ + GFile *parent_path; + ThunarFile *file; + ThunarFolder *folder; + + _thunar_return_if_fail (THUNAR_IS_JOB (job)); + _thunar_return_if_fail (G_IS_FILE (path)); + + /* get parent path */ + if ((parent_path = g_file_get_parent (path)) == NULL) + goto fail0; + + /* get a ThunarFile for the parent */ + if ((file = thunar_file_cache_lookup (parent_path)) == NULL) + goto fail1; + + /* get a ThunarFolder */ + if ((folder = thunar_folder_get_for_file (file)) == NULL) + goto fail2; + + /* reload the folder */ + thunar_folder_reload (folder); + + g_object_unref (folder); +fail2: + g_object_unref (file); +fail1: + g_object_unref (parent_path); +fail0: + return; +} diff --git a/thunar/thunar-job.h b/thunar/thunar-job.h index 8ed8a8b..c53d741 100644 --- a/thunar/thunar-job.h +++ b/thunar/thunar-job.h @@ -86,8 +86,11 @@ ThunarJobResponse thunar_job_ask_skip (ThunarJob *job, ...); gboolean thunar_job_files_ready (ThunarJob *job, GList *file_list); -void thunar_job_new_files (ThunarJob *job, - const GList *file_list); +void thunar_job_new_files (ThunarJob *job); +void thunar_job_add_new_file (ThunarJob *job, + GFile *file); +void thunar_job_changed_file (ThunarJob *job, + GFile *path); G_END_DECLS diff --git a/thunar/thunar-simple-job.c b/thunar/thunar-simple-job.c index e311ba7..f455750 100644 --- a/thunar/thunar-simple-job.c +++ b/thunar/thunar-simple-job.c @@ -133,7 +133,10 @@ thunar_simple_job_execute (ExoJob *job, return FALSE; } else - return TRUE; + { + thunar_job_new_files (THUNAR_JOB (job)); + return TRUE; + } } diff --git a/thunar/thunar-transfer-job.c b/thunar/thunar-transfer-job.c index c38cf85..0fb17f0 100644 --- a/thunar/thunar-transfer-job.c +++ b/thunar/thunar-transfer-job.c @@ -480,7 +480,7 @@ thunar_transfer_job_copy_node (ThunarTransferJob *job, ThunarTransferNode *node, GFile *target_file, GFile *target_parent_file, - GList **target_file_list_return, + gboolean add_new_files, GError **error) { ThunarThumbnailCache *thumbnail_cache; @@ -554,7 +554,7 @@ retry_copy: if (node->children != NULL) { /* copy all children of this node */ - thunar_transfer_job_copy_node (job, node->children, NULL, real_target_file, NULL, &err); + thunar_transfer_job_copy_node (job, node->children, NULL, real_target_file, FALSE, &err); /* free resources allocted for the children */ thunar_transfer_node_free (node->children); @@ -570,12 +570,10 @@ retry_copy: break; } - /* add the real target file to the return list */ - if (G_LIKELY (target_file_list_return != NULL)) + /* register new file */ + if (G_LIKELY (add_new_files)) { - *target_file_list_return = - thunar_g_file_list_prepend (*target_file_list_return, - real_target_file); + thunar_job_add_new_file (THUNAR_JOB (job), real_target_file); } retry_remove: @@ -654,7 +652,6 @@ thunar_transfer_job_execute (ExoJob *job, GFileInfo *info; gboolean parent_exists; GError *err = NULL; - GList *new_files_list = NULL; GList *snext; GList *sp; GList *tnext; @@ -786,8 +783,8 @@ thunar_transfer_job_execute (ExoJob *job, node->source_file, tp->data); - /* add the target file to the new files list */ - new_files_list = thunar_g_file_list_prepend (new_files_list, tp->data); + /* register new file */ + thunar_job_add_new_file (THUNAR_JOB (job), tp->data); /* release source and target files */ thunar_transfer_node_free (node); @@ -834,8 +831,7 @@ thunar_transfer_job_execute (ExoJob *job, sp != NULL && tp != NULL && err == NULL; sp = sp->next, tp = tp->next) { - thunar_transfer_job_copy_node (transfer_job, sp->data, tp->data, NULL, - &new_files_list, &err); + thunar_transfer_job_copy_node (transfer_job, sp->data, tp->data, NULL, TRUE, &err); } } @@ -847,8 +843,7 @@ thunar_transfer_job_execute (ExoJob *job, } else { - thunar_job_new_files (THUNAR_JOB (job), new_files_list); - thunar_g_file_list_free (new_files_list); + thunar_job_new_files (THUNAR_JOB (job)); return TRUE; } }