void nautilus_directory_notify_files_added_by_uri (GList *uris) { GList *files; files = nautilus_file_list_from_uris (uris); nautilus_directory_notify_files_added (files); g_list_free_full (files, g_object_unref); }
void nautilus_directory_notify_files_moved (GList *file_pairs) { GList *p, *affected_files, *node; GFilePair *pair; NautilusFile *file; NautilusDirectory *old_directory, *new_directory; GHashTable *parent_directories; GList *new_files_list, *unref_list; GHashTable *added_lists, *changed_lists; char *name; NautilusFileAttributes cancel_attributes; GFile *to_location, *from_location; /* Make a list of added and changed files in each directory. */ new_files_list = NULL; added_lists = g_hash_table_new (NULL, NULL); changed_lists = g_hash_table_new (NULL, NULL); unref_list = NULL; /* Make a list of parent directories that will need their counts updated. */ parent_directories = g_hash_table_new (NULL, NULL); cancel_attributes = nautilus_file_get_all_attributes (); for (p = file_pairs; p != NULL; p = p->next) { pair = p->data; from_location = pair->from; to_location = pair->to; /* Handle overwriting a file. */ file = nautilus_file_get_existing (to_location); if (file != NULL) { /* Mark it gone and prepare to send the changed signal. */ nautilus_file_mark_gone (file); new_directory = file->details->directory; hash_table_list_prepend (changed_lists, new_directory, file); collect_parent_directories (parent_directories, new_directory); } /* Update any directory objects that are affected. */ affected_files = nautilus_directory_moved_internal (from_location, to_location); for (node = affected_files; node != NULL; node = node->next) { file = NAUTILUS_FILE (node->data); hash_table_list_prepend (changed_lists, file->details->directory, file); } unref_list = g_list_concat (unref_list, affected_files); /* Move an existing file. */ file = nautilus_file_get_existing (from_location); if (file == NULL) { /* Handle this as if it was a new file. */ new_files_list = g_list_prepend (new_files_list, to_location); } else { /* Handle notification in the old directory. */ old_directory = file->details->directory; collect_parent_directories (parent_directories, old_directory); /* Cancel loading of attributes in the old directory */ nautilus_directory_cancel_loading_file_attributes (old_directory, file, cancel_attributes); /* Locate the new directory. */ new_directory = get_parent_directory (to_location); collect_parent_directories (parent_directories, new_directory); /* We can unref now -- new_directory is in the * parent directories list so it will be * around until the end of this function * anyway. */ nautilus_directory_unref (new_directory); /* Update the file's name and directory. */ name = g_file_get_basename (to_location); nautilus_file_update_name_and_directory (file, name, new_directory); g_free (name); /* Update file attributes */ nautilus_file_invalidate_attributes (file, NAUTILUS_FILE_ATTRIBUTE_INFO); hash_table_list_prepend (changed_lists, old_directory, file); if (old_directory != new_directory) { hash_table_list_prepend (added_lists, new_directory, file); } /* Unref each file once to balance out nautilus_file_get_by_uri. */ unref_list = g_list_prepend (unref_list, file); } } /* Now send out the changed and added signals for existing file objects. */ g_hash_table_foreach (changed_lists, call_files_changed_free_list, NULL); g_hash_table_destroy (changed_lists); g_hash_table_foreach (added_lists, call_files_added_free_list, NULL); g_hash_table_destroy (added_lists); /* Let the file objects go. */ nautilus_file_list_free (unref_list); /* Invalidate count for each parent directory. */ g_hash_table_foreach (parent_directories, invalidate_count_and_unref, NULL); g_hash_table_destroy (parent_directories); /* Separate handling for brand new file objects. */ nautilus_directory_notify_files_added (new_files_list); g_list_free (new_files_list); }
/* go through changes in the change queue, send ones with the same kind * in a list to the different nautilus_directory_notify calls */ void nautilus_file_changes_consume_changes (gboolean consume_all) { NautilusFileChange *change; GList *additions, *changes, *deletions, *moves; GList *metadata_copy_requests, *metadata_move_requests, *metadata_remove_requests; GList *position_set_requests; GFilePair *pair; NautilusFileChangesQueuePosition *position_set; guint chunk_count; NautilusFileChangesQueue *queue; gboolean flush_needed; additions = NULL; changes = NULL; deletions = NULL; moves = NULL; metadata_copy_requests = NULL; metadata_move_requests = NULL; metadata_remove_requests = NULL; position_set_requests = NULL; queue = nautilus_file_changes_queue_get(); /* Consume changes from the queue, stuffing them into one of three lists, * keep doing it while the changes are of the same kind, then send them off. * This is to ensure that the changes get sent off in the same order that they * arrived. */ for (chunk_count = 0; ; chunk_count++) { change = nautilus_file_changes_queue_get_change (queue); /* figure out if we need to flush the pending changes that we collected sofar */ if (change == NULL) { flush_needed = TRUE; /* no changes left, flush everything */ } else { flush_needed = additions != NULL && change->kind != CHANGE_FILE_ADDED && change->kind != CHANGE_METADATA_COPIED && change->kind != CHANGE_POSITION_SET && change->kind != CHANGE_POSITION_REMOVE; flush_needed |= changes != NULL && change->kind != CHANGE_FILE_CHANGED; flush_needed |= moves != NULL && change->kind != CHANGE_FILE_MOVED && change->kind != CHANGE_METADATA_MOVED && change->kind != CHANGE_POSITION_SET && change->kind != CHANGE_POSITION_REMOVE; flush_needed |= deletions != NULL && change->kind != CHANGE_FILE_REMOVED && change->kind != CHANGE_METADATA_REMOVED; flush_needed |= metadata_copy_requests != NULL && change->kind != CHANGE_FILE_ADDED && change->kind != CHANGE_METADATA_COPIED && change->kind != CHANGE_POSITION_SET && change->kind != CHANGE_POSITION_REMOVE; flush_needed |= metadata_move_requests != NULL && change->kind != CHANGE_FILE_MOVED && change->kind != CHANGE_METADATA_MOVED && change->kind != CHANGE_POSITION_SET && change->kind != CHANGE_POSITION_REMOVE; flush_needed |= metadata_remove_requests != NULL && change->kind != CHANGE_FILE_REMOVED && change->kind != CHANGE_METADATA_REMOVED; flush_needed |= position_set_requests != NULL && change->kind != CHANGE_POSITION_SET && change->kind != CHANGE_POSITION_REMOVE && change->kind != CHANGE_FILE_ADDED && change->kind != CHANGE_FILE_MOVED && change->kind != CHANGE_METADATA_COPIED && change->kind != CHANGE_METADATA_MOVED; flush_needed |= !consume_all && chunk_count >= CONSUME_CHANGES_MAX_CHUNK; /* we have reached the chunk maximum */ } if (flush_needed) { /* Send changes we collected off. * At one time we may only have one of the lists * contain changes. */ if (deletions != NULL) { deletions = g_list_reverse (deletions); nautilus_directory_notify_files_removed (deletions); eel_g_object_list_free (deletions); deletions = NULL; } if (moves != NULL) { moves = g_list_reverse (moves); nautilus_directory_notify_files_moved (moves); pairs_list_free (moves); moves = NULL; } if (additions != NULL) { additions = g_list_reverse (additions); nautilus_directory_notify_files_added (additions); eel_g_object_list_free (additions); additions = NULL; } if (changes != NULL) { changes = g_list_reverse (changes); nautilus_directory_notify_files_changed (changes); eel_g_object_list_free (changes); changes = NULL; } if (metadata_copy_requests != NULL) { metadata_copy_requests = g_list_reverse (metadata_copy_requests); nautilus_directory_schedule_metadata_copy (metadata_copy_requests); pairs_list_free (metadata_copy_requests); metadata_copy_requests = NULL; } if (metadata_move_requests != NULL) { metadata_move_requests = g_list_reverse (metadata_move_requests); nautilus_directory_schedule_metadata_move (metadata_move_requests); pairs_list_free (metadata_move_requests); metadata_move_requests = NULL; } if (metadata_remove_requests != NULL) { metadata_remove_requests = g_list_reverse (metadata_remove_requests); nautilus_directory_schedule_metadata_remove (metadata_remove_requests); eel_g_object_list_free (metadata_remove_requests); metadata_remove_requests = NULL; } if (position_set_requests != NULL) { position_set_requests = g_list_reverse (position_set_requests); nautilus_directory_schedule_position_set (position_set_requests); position_set_list_free (position_set_requests); position_set_requests = NULL; } } if (change == NULL) { /* we are done */ return; } /* add the new change to the list */ switch (change->kind) { case CHANGE_FILE_ADDED: additions = g_list_prepend (additions, change->from); break; case CHANGE_FILE_CHANGED: changes = g_list_prepend (changes, change->from); break; case CHANGE_FILE_REMOVED: deletions = g_list_prepend (deletions, change->from); break; case CHANGE_FILE_MOVED: pair = g_new (GFilePair, 1); pair->from = change->from; pair->to = change->to; moves = g_list_prepend (moves, pair); break; case CHANGE_METADATA_COPIED: pair = g_new (GFilePair, 1); pair->from = change->from; pair->to = change->to; metadata_copy_requests = g_list_prepend (metadata_copy_requests, pair); break; case CHANGE_METADATA_MOVED: pair = g_new (GFilePair, 1); pair->from = change->from; pair->to = change->to; metadata_move_requests = g_list_prepend (metadata_move_requests, pair); break; case CHANGE_METADATA_REMOVED: metadata_remove_requests = g_list_prepend (metadata_remove_requests, change->from); break; case CHANGE_POSITION_SET: position_set = g_new (NautilusFileChangesQueuePosition, 1); position_set->location = change->from; position_set->set = TRUE; position_set->point = change->point; position_set->screen = change->screen; position_set_requests = g_list_prepend (position_set_requests, position_set); break; case CHANGE_POSITION_REMOVE: position_set = g_new (NautilusFileChangesQueuePosition, 1); position_set->location = change->from; position_set->set = FALSE; position_set_requests = g_list_prepend (position_set_requests, position_set); break; default: g_assert_not_reached (); break; } g_free (change); } }