static void
sync_search_directory (NautilusWindowSlot *slot)
{
	NautilusDirectory *directory;
	NautilusQuery *query;
	gchar *text;
	GFile *location;

	g_assert (NAUTILUS_IS_FILE (slot->viewed_file));

	directory = nautilus_directory_get_for_file (slot->viewed_file);
	g_assert (NAUTILUS_IS_SEARCH_DIRECTORY (directory));

	query = nautilus_query_editor_get_query (slot->query_editor);
	text = nautilus_query_get_text (query);

	if (!strlen (text)) {
		location = nautilus_query_editor_get_location (slot->query_editor);
		slot->load_with_search = TRUE;
		nautilus_window_slot_open_location (slot, location, 0);
		g_object_unref (location);
	} else {
		nautilus_search_directory_set_query (NAUTILUS_SEARCH_DIRECTORY (directory),
						     query);
		nautilus_window_slot_reload (slot);
	}

	g_free (text);
	g_object_unref (query);
	nautilus_directory_unref (directory);
}
static void
open_windows (NautilusApplication *application,
	      gboolean force_new,
	      GFile **files,
	      gint n_files,
	      GdkScreen *screen,
	      const char *geometry)
{
	guint i;

	if (files == NULL || files[0] == NULL) {
		/* Open a window pointing at the default location. */
		open_window (application, NULL, screen, geometry);
	} else {
		/* Open windows at each requested location. */
		for (i = 0; i < n_files; ++i) {
			NautilusWindowSlot *slot = NULL;

			if (!force_new)
				slot = get_window_slot_for_location (application, files[i]);

			if (!slot) {
				open_window (application, files[i], screen, geometry);
			} else {
				/* We open the location again to update any possible selection */
				nautilus_window_slot_open_location (slot, files[i], 0);

				NautilusWindow *window = nautilus_window_slot_get_window (slot);
				nautilus_window_set_active_slot (window, slot);
				gtk_window_present (GTK_WINDOW (window));
			}
		}
	}
}
void
nautilus_window_slot_go_home (NautilusWindowSlot *slot,
			      NautilusWindowOpenFlags flags)
{			      
	GFile *home;

	g_return_if_fail (NAUTILUS_IS_WINDOW_SLOT (slot));

	home = g_file_new_for_path (g_get_home_dir ());
	nautilus_window_slot_open_location (slot, home, flags);
	g_object_unref (home);
}
static void
action_go_to_trash_callback (GtkAction *action, 
			     gpointer user_data) 
{
	NautilusWindow *window;
	NautilusWindowSlot *slot;
	GFile *trash;

	window = NAUTILUS_WINDOW (user_data);
	slot = nautilus_window_get_active_slot (window);

	trash = g_file_new_for_uri ("trash:///");
	nautilus_window_slot_open_location (slot, trash,
					    nautilus_event_get_window_open_flags ());
	g_object_unref (trash);
}
static void
action_go_to_network_callback (GtkAction *action, 
				gpointer user_data) 
{
	NautilusWindow *window;
	NautilusWindowSlot *slot;
	GFile *network;

	window = NAUTILUS_WINDOW (user_data);
	slot = nautilus_window_get_active_slot (window);

	network = g_file_new_for_uri (NETWORK_URI);
	nautilus_window_slot_open_location (slot, network,
					    nautilus_event_get_window_open_flags ());
	g_object_unref (network);
}
void
nautilus_window_slot_go_up (NautilusWindowSlot *slot,
			    NautilusWindowOpenFlags flags)
{
	GFile *parent;

	if (slot->location == NULL) {
		return;
	}

	parent = g_file_get_parent (slot->location);
	if (parent == NULL) {
		return;
	}

	nautilus_window_slot_open_location (slot, parent, flags);
	g_object_unref (parent);
}
static void
action_search (GSimpleAction *action,
	       GVariant *parameter,
	       gpointer user_data)
{
	GtkApplication *application = user_data;
	const gchar *string, *uri;
	NautilusQuery *query;
	NautilusDirectory *directory;
	gchar *search_uri;
	NautilusWindow *window;
	GtkWindow *cur_window;
	GFile *location;

	g_variant_get (parameter, "(ss)", &uri, &string);

	if (strlen (string) == 0 ||
	    strlen (uri) == 0) {
		return;
	}

	query = nautilus_query_new ();
	nautilus_query_set_location (query, uri);
	nautilus_query_set_text (query, string);

	search_uri = nautilus_search_directory_generate_new_uri ();
	location = g_file_new_for_uri (search_uri);
	g_free (search_uri);

	directory = nautilus_directory_get (location);
	nautilus_search_directory_set_query (NAUTILUS_SEARCH_DIRECTORY (directory), query);

	cur_window = gtk_application_get_active_window (application);
	window = nautilus_application_create_window (NAUTILUS_APPLICATION (application),
						     cur_window ?
						     gtk_window_get_screen (cur_window) :
						     gdk_screen_get_default ());

	nautilus_window_slot_open_location (nautilus_window_get_active_slot (window), location, 0);

	nautilus_directory_unref (directory);
	g_object_unref (query);
	g_object_unref (location);
}
static void
action_go_to_templates_callback (GtkAction *action,
				 gpointer user_data) 
{
	NautilusWindow *window;
	NautilusWindowSlot *slot;
	char *path;
	GFile *location;

	window = NAUTILUS_WINDOW (user_data);
	slot = nautilus_window_get_active_slot (window);

	path = nautilus_get_templates_directory ();
	location = g_file_new_for_path (path);
	g_free (path);
	nautilus_window_slot_open_location (slot, location,
					    nautilus_event_get_window_open_flags ());
	g_object_unref (location);
}