static void
search_callback_add_pending_file_callbacks (SearchCallback *callback)
{
	callback->file_list = nemo_file_list_copy (callback->search_directory->details->files);
	callback->non_ready_hash = file_list_to_hash_table (callback->search_directory->details->files);

	search_callback_add_file_callbacks (callback);
}
static GList *
search_get_file_list (NemoDirectory *directory)
{
	NemoSearchDirectory *search;

	search = NEMO_SEARCH_DIRECTORY (directory);

	return nemo_file_list_copy (search->details->files);
}
Example #3
0
static GList *
nemo_directory_moved_internal (GFile *old_location,
				   GFile *new_location)
{
	CollectData collection;
	NemoDirectory *directory;
	GList *node, *affected_files;
	GFile *new_directory_location;
	char *relative_path;

	collection.container = old_location;
	collection.directories = NULL;

	g_hash_table_foreach (directories,
			      collect_directories_by_container,
			      &collection);

	affected_files = NULL;

	for (node = collection.directories; node != NULL; node = node->next) {
		directory = NEMO_DIRECTORY (node->data);
		new_directory_location = NULL;

		if (g_file_equal (directory->details->location, old_location)) {
			new_directory_location = g_object_ref (new_location);
		} else {
			relative_path = g_file_get_relative_path (old_location,
								  directory->details->location);
			if (relative_path != NULL) {
				new_directory_location = g_file_resolve_relative_path (new_location, relative_path);
				g_free (relative_path);
				
			}
		}
		
		if (new_directory_location) {
			change_directory_location (directory, new_directory_location);
			g_object_unref (new_directory_location);
		
			/* Collect affected files. */
			if (directory->details->as_file != NULL) {
				affected_files = g_list_prepend
					(affected_files,
					 nemo_file_ref (directory->details->as_file));
			}
			affected_files = g_list_concat
				(affected_files,
				 nemo_file_list_copy (directory->details->file_list));
		}
		
		nemo_directory_unref (directory);
	}

	g_list_free (collection.directories);

	return affected_files;
}
static void
desktop_call_when_ready (NemoDirectory *directory,
			 NemoFileAttributes file_attributes,
			 gboolean wait_for_file_list,
			 NemoDirectoryCallback callback,
			 gpointer callback_data)
{
	NemoDesktopDirectory *desktop;
	MergedCallback search_key, *merged_callback;

	desktop = NEMO_DESKTOP_DIRECTORY (directory);

	/* Check to be sure we aren't overwriting. */
	search_key.callback = callback;
	search_key.callback_data = callback_data;
	if (g_hash_table_lookup (desktop->details->callbacks, &search_key) != NULL) {
		g_warning ("tried to add a new callback while an old one was pending");
		return;
	}

	/* Create a merged_callback record. */
	merged_callback = g_new0 (MergedCallback, 1);
	merged_callback->desktop_dir = desktop;
	merged_callback->callback = callback;
	merged_callback->callback_data = callback_data;
	merged_callback->wait_for_attributes = file_attributes;
	merged_callback->wait_for_file_list = wait_for_file_list;
	merged_callback->non_ready_directories = g_list_prepend
			(merged_callback->non_ready_directories, directory);
	merged_callback->non_ready_directories = g_list_prepend
			(merged_callback->non_ready_directories, desktop->details->real_directory);


	merged_callback->merged_file_list = g_list_concat (NULL,
							   nemo_file_list_copy (directory->details->file_list));

	/* Put it in the hash table. */
	g_hash_table_insert (desktop->details->callbacks,
			     merged_callback, merged_callback);

	/* Now tell all the directories about it. */
	nemo_directory_call_when_ready
		(desktop->details->real_directory,
		 merged_callback->wait_for_attributes,
		 merged_callback->wait_for_file_list,
		 directory_ready_callback, merged_callback);
	nemo_directory_call_when_ready_internal
		(directory,
		 NULL,
		 merged_callback->wait_for_attributes,
		 merged_callback->wait_for_file_list,
		 directory_ready_callback,
		 NULL,
		 merged_callback);
	
}
static void
build_merged_callback_list (NemoDirectory *directory,
			    GList *file_list,
			    gpointer callback_data)
{
	GList **merged_list;

	merged_list = callback_data;
	*merged_list = g_list_concat (*merged_list,
				      nemo_file_list_copy (file_list));
}
static void
search_call_when_ready (NemoDirectory *directory,
			NemoFileAttributes file_attributes,
			gboolean wait_for_file_list,
			NemoDirectoryCallback callback,
			gpointer callback_data)
{
	NemoSearchDirectory *search;
	SearchCallback *search_callback;

	search = NEMO_SEARCH_DIRECTORY (directory);

	search_callback = search_callback_find (search, callback, callback_data);
	if (search_callback == NULL) {
		search_callback = search_callback_find_pending (search, callback, callback_data);
	}
	
	if (search_callback) {
		g_warning ("tried to add a new callback while an old one was pending");
		return;
	}

	search_callback = g_new0 (SearchCallback, 1);
	search_callback->search_directory = search;
	search_callback->callback = callback;
	search_callback->callback_data = callback_data;
	search_callback->wait_for_attributes = file_attributes;
	search_callback->wait_for_file_list = wait_for_file_list;

	if (wait_for_file_list && !search->details->search_finished) {
		/* Add it to the pending callback list, which will be
		 * processed when the directory has finished loading
		 */
		search->details->pending_callback_list = 
			g_list_prepend (search->details->pending_callback_list, search_callback);

		/* We might need to start the search engine */
		start_or_stop_search_engine (search, TRUE);
	} else {
		search_callback->file_list = nemo_file_list_copy (search->details->files);
		search_callback->non_ready_hash = file_list_to_hash_table (search->details->files);

		if (!search_callback->non_ready_hash) {
			/* If there are no ready files, we invoke the callback
			   with an empty list.
			*/
			search_callback_invoke_and_destroy (search_callback);
		} else {
			search->details->callback_list = g_list_prepend (search->details->callback_list, search_callback);
			search_callback_add_file_callbacks (search_callback);
		}
	}
}
static void
desktop_monitor_add (NemoDirectory *directory,
		    gconstpointer client,
		    gboolean monitor_hidden_files,
		    NemoFileAttributes file_attributes,
		    NemoDirectoryCallback callback,
		    gpointer callback_data)
{
	NemoDesktopDirectory *desktop;
	MergedMonitor *monitor;
	GList *merged_callback_list;

	desktop = NEMO_DESKTOP_DIRECTORY (directory);

	/* Map the client to a unique value so this doesn't interfere
	 * with direct monitoring of the directory by the same client.
	 */
	monitor = g_hash_table_lookup (desktop->details->monitors, client);
	if (monitor != NULL) {
		g_assert (monitor->desktop_dir == desktop);
	} else {
		monitor = g_new0 (MergedMonitor, 1);
		monitor->desktop_dir = desktop;
		g_hash_table_insert (desktop->details->monitors,
				     (gpointer) client, monitor);
	}
	monitor->monitor_hidden_files = monitor_hidden_files;
	monitor->monitor_attributes = file_attributes;
	
	/* Call through to the real directory add calls. */
	merged_callback_list = NULL;

	/* Call up to real dir */
	nemo_directory_file_monitor_add
		(desktop->details->real_directory, monitor,
		 monitor_hidden_files,
		 file_attributes,
		 build_merged_callback_list, &merged_callback_list);
	
	/* Handle the desktop part */
	merged_callback_list = g_list_concat (merged_callback_list,
					      nemo_file_list_copy (directory->details->file_list));

	
	if (callback != NULL) {
		(* callback) (directory, merged_callback_list, callback_data);
	}
	nemo_file_list_free (merged_callback_list);
}
static void
directory_ready_callback (NemoDirectory *directory,
			  GList *files,
			  gpointer callback_data)
{
	MergedCallback *merged_callback;

	g_assert (NEMO_IS_DIRECTORY (directory));
	g_assert (callback_data != NULL);

	merged_callback = callback_data;
	g_assert (g_list_find (merged_callback->non_ready_directories, directory) != NULL);

	/* Update based on this call. */
	merged_callback->merged_file_list = g_list_concat
		(merged_callback->merged_file_list,
		 nemo_file_list_copy (files));

	/* Check if we are ready. */
	merged_callback_remove_directory (merged_callback, directory);
}
Example #9
0
void
fm_tree_model_set_highlight_for_files (FMTreeModel *model,
                                       GList *files)
{
	GList *old_files;

	if (model->details->highlighted_files != NULL) {
		old_files = model->details->highlighted_files;
		model->details->highlighted_files = NULL;

		g_list_foreach (old_files,
		                (GFunc) do_update_node, model);

		nemo_file_list_free (old_files);
	}

	if (files != NULL) {
		model->details->highlighted_files = 
			nemo_file_list_copy (files);
		g_list_foreach (model->details->highlighted_files,
		                (GFunc) do_update_node, model);
	}
}