static void
search_engine_hits_added (NautilusSearchEngine *engine, GList *hits, 
			  NautilusSearchDirectory *search)
{
	GList *hit_list;
	GList *file_list;
	NautilusFile *file;
	SearchMonitor *monitor;
	GList *monitor_list;

	file_list = NULL;

	for (hit_list = hits; hit_list != NULL; hit_list = hit_list->next) {
		NautilusSearchHit *hit = hit_list->data;
		const char *uri;

		uri = nautilus_search_hit_get_uri (hit);
		if (g_str_has_suffix (uri, NAUTILUS_SAVED_SEARCH_EXTENSION)) {
			/* Never return saved searches themselves as hits */
			continue;
		}

		nautilus_search_hit_compute_scores (hit, search->details->query);

		file = nautilus_file_get_by_uri (uri);
		nautilus_file_set_search_relevance (file, nautilus_search_hit_get_relevance (hit));

		for (monitor_list = search->details->monitor_list; monitor_list; monitor_list = monitor_list->next) {
			monitor = monitor_list->data;

			/* Add monitors */
			nautilus_file_monitor_add (file, monitor, monitor->monitor_attributes);
		}

		g_signal_connect (file, "changed", G_CALLBACK (file_changed), search),

		file_list = g_list_prepend (file_list, file);
		g_hash_table_add (search->details->files_hash, file);
	}
	
	search->details->files = g_list_concat (search->details->files, file_list);

	nautilus_directory_emit_files_added (NAUTILUS_DIRECTORY (search), file_list);

	file = nautilus_directory_get_corresponding_file (NAUTILUS_DIRECTORY (search));
	nautilus_file_emit_changed (file);
	nautilus_file_unref (file);

        search_directory_add_pending_files_callbacks (search);
}
static void
forward_files_changed_cover (NautilusDirectory *real_directory,
			     GList *files,
			     gpointer callback_data)
{
	nautilus_directory_emit_files_changed (NAUTILUS_DIRECTORY (callback_data), files);
}
static void
desktop_finalize (GObject *object)
{
	NautilusDesktopDirectoryFile *desktop_file;
	NautilusDesktopDirectory *desktop_directory;

	desktop_file = NAUTILUS_DESKTOP_DIRECTORY_FILE (object);
	desktop_directory = desktop_file->details->desktop_directory;

	/* Todo: ghash now safe? */
	eel_g_hash_table_safe_for_each
		(desktop_file->details->callbacks,
		 desktop_callback_remove_file_cover,
		 desktop_file->details->real_dir_file);
	
	if (g_hash_table_size (desktop_file->details->callbacks) != 0) {
		g_warning ("call_when_ready still pending when desktop virtual file is destroyed");
	}

	g_hash_table_destroy (desktop_file->details->callbacks);
	g_hash_table_destroy (desktop_file->details->monitors);

	nautilus_file_unref (desktop_file->details->real_dir_file);
	nautilus_directory_unref (NAUTILUS_DIRECTORY (desktop_directory));

	G_OBJECT_CLASS (nautilus_desktop_directory_file_parent_class)->finalize (object);
}
Example #4
0
static GList *
nautilus_directory_moved_internal (GFile *old_location,
				   GFile *new_location)
{
	CollectData collection;
	NautilusDirectory *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 = NAUTILUS_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,
					 nautilus_file_ref (directory->details->as_file));
			}
			affected_files = g_list_concat
				(affected_files,
				 nautilus_file_list_copy (directory->details->file_list));
		}
		
		nautilus_directory_unref (directory);
	}

	g_list_free (collection.directories);

	return affected_files;
}
Example #5
0
static void
call_files_changed_unref_free_list (gpointer key, gpointer value, gpointer user_data)
{
	g_assert (value != NULL);
	g_assert (user_data == NULL);

	call_files_changed_common (NAUTILUS_DIRECTORY (key), value);
	nautilus_file_list_free (value);
}
static void
file_changed (NautilusFile *file, NautilusSearchDirectory *search)
{
	GList list;

	list.data = file;
	list.next = NULL;

	nautilus_directory_emit_files_changed (NAUTILUS_DIRECTORY (search), &list);
}
static void
search_engine_error (NautilusSearchEngine *engine, const char *error_message, NautilusSearchDirectory *search)
{
	GError *error;

	error = g_error_new_literal (G_IO_ERROR, G_IO_ERROR_FAILED,
				     error_message);
	nautilus_directory_emit_load_error (NAUTILUS_DIRECTORY (search),
					    error);
	g_error_free (error);
}
Example #8
0
static void
collect_all_directories (gpointer key, gpointer value, gpointer callback_data)
{
	NautilusDirectory *directory;
	GList **dirs;

	directory = NAUTILUS_DIRECTORY (value);
	dirs = callback_data;

	*dirs = g_list_prepend (*dirs, nautilus_directory_ref (directory));
}
static void
search_callback_invoke_and_destroy (SearchCallback *search_callback)
{
	search_callback->callback (NAUTILUS_DIRECTORY (search_callback->search_directory),
				   search_callback->file_list,
				   search_callback->callback_data);

	search_callback->search_directory->details->callback_list = 
		g_list_remove (search_callback->search_directory->details->callback_list, search_callback);

	search_callback_destroy (search_callback);
}
Example #10
0
static void
invalidate_one_count (gpointer key, gpointer value, gpointer user_data)
{
	NautilusDirectory *directory;

	g_assert (key != NULL);
	g_assert (NAUTILUS_IS_DIRECTORY (value));
	g_assert (user_data == NULL);

	directory = NAUTILUS_DIRECTORY (value);
	
	nautilus_directory_invalidate_count_and_mime_list (directory);
}
Example #11
0
static void
nautilus_directory_finalize (GObject *object)
{
	NautilusDirectory *directory;

	directory = NAUTILUS_DIRECTORY (object);

	g_hash_table_remove (directories, directory->details->location);

	nautilus_directory_cancel (directory);
	g_assert (directory->details->count_in_progress == NULL);
	g_assert (directory->details->top_left_read_state == NULL);

	if (directory->details->monitor_list != NULL) {
		g_warning ("destroying a NautilusDirectory while it's being monitored");
		g_list_free_full (directory->details->monitor_list, g_free);
	}

	if (directory->details->monitor != NULL) {
		nautilus_monitor_cancel (directory->details->monitor);
	}

	if (directory->details->dequeue_pending_idle_id != 0) {
		g_source_remove (directory->details->dequeue_pending_idle_id);
	}

	if (directory->details->call_ready_idle_id != 0) {
		g_source_remove (directory->details->call_ready_idle_id);
	}

	if (directory->details->location) {
		g_object_unref (directory->details->location);
	}

	g_assert (directory->details->file_list == NULL);
	g_hash_table_destroy (directory->details->file_hash);

	if (directory->details->hidden_file_hash) {
		g_hash_table_destroy (directory->details->hidden_file_hash);
	}
	
	nautilus_file_queue_destroy (directory->details->high_priority_queue);
	nautilus_file_queue_destroy (directory->details->low_priority_queue);
	nautilus_file_queue_destroy (directory->details->extension_queue);
	g_assert (directory->details->directory_load_in_progress == NULL);
	g_assert (directory->details->count_in_progress == NULL);
	g_assert (directory->details->dequeue_pending_idle_id == 0);
	g_list_free_full (directory->details->pending_file_info, g_object_unref);

	EEL_CALL_PARENT (G_OBJECT_CLASS, finalize, (object));
}
Example #12
0
static void
nautilus_directory_init (gpointer object, gpointer klass)
{
	NautilusDirectory *directory;

	directory = NAUTILUS_DIRECTORY(object);

	directory->details = G_TYPE_INSTANCE_GET_PRIVATE ((directory), NAUTILUS_TYPE_DIRECTORY, NautilusDirectoryDetails);
	directory->details->file_hash = g_hash_table_new (g_str_hash, g_str_equal);
	directory->details->high_priority_queue = nautilus_file_queue_new ();
	directory->details->low_priority_queue = nautilus_file_queue_new ();
	directory->details->extension_queue = nautilus_file_queue_new ();
	directory->details->free_space = (guint64)-1;
}
Example #13
0
static void
async_state_changed_one (gpointer key, gpointer value, gpointer user_data)
{
	NautilusDirectory *directory;

	g_assert (key != NULL);
	g_assert (NAUTILUS_IS_DIRECTORY (value));
	g_assert (user_data == NULL);

	directory = NAUTILUS_DIRECTORY (value);
	
	nautilus_directory_async_state_changed (directory);
	emit_change_signals_for_all_files (directory);
}
static void
merged_monitor_destroy (MergedMonitor *monitor)
{
	NautilusDesktopDirectory *desktop;

	desktop = monitor->desktop_dir;
	
	/* Call through to the real directory remove calls. */
	nautilus_directory_file_monitor_remove (desktop->details->real_directory, monitor);

	nautilus_directory_monitor_remove_internal (NAUTILUS_DIRECTORY (desktop), NULL, monitor);
	
	g_free (monitor);
}
Example #15
0
static NautilusDirectory *
nautilus_directory_new (GFile *location)
{
	NautilusDirectory *directory;
	char *uri;

	uri = g_file_get_uri (location);
	
	if (eel_uri_is_desktop (uri)) {
		directory = NAUTILUS_DIRECTORY (g_object_new (NAUTILUS_TYPE_DESKTOP_DIRECTORY, NULL));
	} else if (eel_uri_is_search (uri)) {
		directory = NAUTILUS_DIRECTORY (g_object_new (NAUTILUS_TYPE_SEARCH_DIRECTORY, NULL));
	} else if (g_str_has_suffix (uri, NAUTILUS_SAVED_SEARCH_EXTENSION)) {
		directory = NAUTILUS_DIRECTORY (nautilus_search_directory_new_from_saved_search (uri));
	} else {
		directory = NAUTILUS_DIRECTORY (g_object_new (NAUTILUS_TYPE_VFS_DIRECTORY, NULL));
	}

	set_directory_location (directory, location);

	g_free (uri);
	
	return directory;
}
Example #16
0
static void
nautilus_directory_get_property (GObject *object,
				 guint property_id,
				 GValue *value,
				 GParamSpec *pspec)
{
	NautilusDirectory *directory = NAUTILUS_DIRECTORY (object);

	switch (property_id) {
	case PROP_LOCATION:
		g_value_set_object (value, directory->details->location);
		break;
	default:
		G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
		break;
	}
}
Example #17
0
static void
collect_directories_by_container (gpointer key, gpointer value, gpointer callback_data)
{
	NautilusDirectory *directory;
	CollectData *collect_data;
	GFile *location;

	location = (GFile *) key;
	directory = NAUTILUS_DIRECTORY (value);
	collect_data = (CollectData *) callback_data;

	if (g_file_has_prefix (location, collect_data->container) ||
	    g_file_equal (collect_data->container, location)) {
		nautilus_directory_ref (directory);
		collect_data->directories =
			g_list_prepend (collect_data->directories,
					directory);
	}
}
static void
search_directory_ensure_loaded (NautilusSearchDirectory *search)
{
	if (search->details->search_loaded) {
		return;
	}

	search->details->search_loaded = TRUE;
	nautilus_directory_emit_done_loading (NAUTILUS_DIRECTORY (search));

	/* Add all file callbacks */
	g_list_foreach (search->details->pending_callback_list,
			(GFunc)search_callback_add_pending_file_callbacks, NULL);
	search->details->callback_list = g_list_concat (search->details->callback_list,
							search->details->pending_callback_list);

	g_list_free (search->details->pending_callback_list);
	search->details->pending_callback_list = NULL;
}
static void
merged_callback_check_done (MergedCallback *merged_callback)
{
	/* Check if we are ready. */
	if (merged_callback->non_ready_directories != NULL) {
		return;
	}

	/* Remove from the hash table before sending it. */
	g_hash_table_steal (merged_callback->desktop_dir->details->callbacks, merged_callback);

	/* We are ready, so do the real callback. */
	(* merged_callback->callback) (NAUTILUS_DIRECTORY (merged_callback->desktop_dir),
				       merged_callback->merged_file_list,
				       merged_callback->callback_data);

	/* And we are done. */
	merged_callback_destroy (merged_callback);
}
Example #20
0
void
emit_change_signals_for_all_files_in_all_directories (void)
{
	GList *dirs, *l;
	NautilusDirectory *directory;

	dirs = NULL;
	g_hash_table_foreach (directories,
			      collect_all_directories,
			      &dirs);

	for (l = dirs; l != NULL; l = l->next) {
		directory = NAUTILUS_DIRECTORY (l->data);
		emit_change_signals_for_all_files (directory);
		nautilus_directory_unref (directory);
	}

	g_list_free (dirs);
}
Example #21
0
static void
filtering_changed_callback (gpointer callback_data)
{
	GList *dirs, *l;
	NautilusDirectory *directory;

	g_assert (callback_data == NULL);

	dirs = NULL;
	g_hash_table_foreach (directories, collect_all_directories, &dirs);

	/* Preference about which items to show has changed, so we
	 * can't trust any of our precomputed directory counts.
	 */
	for (l = dirs; l != NULL; l = l->next) {
		directory = NAUTILUS_DIRECTORY (l->data);
		nautilus_directory_invalidate_count_and_mime_list (directory);
	}

	nautilus_directory_list_unref (dirs);
}
static void
search_engine_finished (NautilusSearchEngine         *engine,
                        NautilusSearchProviderStatus  status,
                        NautilusSearchDirectory      *search)
{
        /* If the search engine is going to restart means it finished an old search
         * that was stopped or cancelled.
         * Don't emit the done loading signal in this case, since this means the search
         * directory tried to start a new search before all the search providers were finished
         * in the search engine.
         * If we emit the done-loading signal in this situation the client will think
         * that it finished the current search, not an old one like it's actually
         * happening. */
        if (status == NAUTILUS_SEARCH_PROVIDER_STATUS_NORMAL) {
                on_search_directory_search_ready_and_valid (search);
	        nautilus_directory_emit_done_loading (NAUTILUS_DIRECTORY (search));
        } else if (status == NAUTILUS_SEARCH_PROVIDER_STATUS_RESTARTING) {
                /* Remove file monitors of the files from an old search that just
                 * actually finished */
                reset_file_list (search);
        }
}
static void
done_loading_callback (NautilusDirectory *real_directory,
		       NautilusDesktopDirectory *desktop)
{
     nautilus_directory_emit_done_loading (NAUTILUS_DIRECTORY (desktop));
}
static void
desktop_directory_changed_callback (gpointer data)
{
	update_desktop_directory (NAUTILUS_DESKTOP_DIRECTORY (data));
	nautilus_directory_force_reload (NAUTILUS_DIRECTORY (data));
}
Example #25
0
static int
compare_by_uri_cover (gconstpointer a, gconstpointer b)
{
	return compare_by_uri (NAUTILUS_DIRECTORY (a), NAUTILUS_DIRECTORY (b));
}