/* either called due to slot change, or due to location change in the current slot. */
static void
real_sync_search_widgets (CajaWindowPane *window_pane)
{
    CajaWindowSlot *slot;
    CajaDirectory *directory;
    CajaSearchDirectory *search_directory;
    CajaNavigationWindowPane *pane;

    pane = CAJA_NAVIGATION_WINDOW_PANE (window_pane);
    slot = window_pane->active_slot;
    search_directory = NULL;

    directory = caja_directory_get (slot->location);
    if (CAJA_IS_SEARCH_DIRECTORY (directory))
    {
        search_directory = CAJA_SEARCH_DIRECTORY (directory);
    }

    if (search_directory != NULL &&
            !caja_search_directory_is_saved_search (search_directory))
    {
        caja_navigation_window_pane_show_location_bar_temporarily (pane);
        caja_navigation_window_pane_set_bar_mode (pane, CAJA_BAR_SEARCH);
        pane->temporary_search_bar = FALSE;
    }
    else
    {
        pane->temporary_search_bar = TRUE;
        caja_navigation_window_pane_hide_temporary_bars (pane);
    }
    caja_directory_unref (directory);
}
static void
query_editor_changed_callback (CajaSearchBar *bar,
                               CajaQuery *query,
                               gboolean reload,
                               CajaWindowSlot *slot)
{
    CajaDirectory *directory;

    directory = caja_directory_get_for_file (slot->viewed_file);
    g_assert (CAJA_IS_SEARCH_DIRECTORY (directory));

    caja_search_directory_set_query (CAJA_SEARCH_DIRECTORY (directory),
                                     query);
    if (reload)
    {
        caja_window_slot_reload (slot);
    }

    caja_directory_unref (directory);
}
static void
real_update_query_editor (CajaWindowSlot *slot)
{
    GtkWidget *query_editor;
    CajaQuery *query;
    CajaDirectory *directory;
    CajaSearchDirectory *search_directory;

    directory = caja_directory_get (slot->location);

    if (CAJA_IS_SEARCH_DIRECTORY (directory))
    {
        search_directory = CAJA_SEARCH_DIRECTORY (directory);

        query_editor = caja_query_editor_new (caja_search_directory_is_saved_search (search_directory),
                                              caja_search_directory_is_indexed (search_directory));

        slot->query_editor = CAJA_QUERY_EDITOR (query_editor);

        caja_window_slot_add_extra_location_widget (slot, query_editor);
        gtk_widget_show (query_editor);
        g_signal_connect_object (query_editor, "changed",
                                 G_CALLBACK (query_editor_changed_callback), slot, 0);

        query = caja_search_directory_get_query (search_directory);
        if (query != NULL)
        {
            caja_query_editor_set_query (CAJA_QUERY_EDITOR (query_editor),
                                         query);
            g_object_unref (query);
        }
        else
        {
            caja_query_editor_set_default_query (CAJA_QUERY_EDITOR (query_editor));
        }
    }

    caja_directory_unref (directory);
}
static void
search_bar_activate_callback (CajaSearchBar *bar,
                              CajaNavigationWindowPane *pane)
{
    char *uri, *current_uri;
    CajaDirectory *directory;
    CajaSearchDirectory *search_directory;
    CajaQuery *query;
    GFile *location;

    uri = caja_search_directory_generate_new_uri ();
    location = g_file_new_for_uri (uri);
    g_free (uri);

    directory = caja_directory_get (location);

    g_assert (CAJA_IS_SEARCH_DIRECTORY (directory));

    search_directory = CAJA_SEARCH_DIRECTORY (directory);

    query = caja_search_bar_get_query (CAJA_SEARCH_BAR (pane->search_bar));
    if (query != NULL)
    {
        CajaWindowSlot *slot = CAJA_WINDOW_PANE (pane)->active_slot;
        if (!caja_search_directory_is_indexed (search_directory))
        {
            current_uri = caja_window_slot_get_location_uri (slot);
            caja_query_set_location (query, current_uri);
            g_free (current_uri);
        }
        caja_search_directory_set_query (search_directory, query);
        g_object_unref (query);
    }

    caja_window_slot_go_to (CAJA_WINDOW_PANE (pane)->active_slot, location, FALSE);

    caja_directory_unref (directory);
    g_object_unref (location);
}
gboolean
caja_navigation_window_pane_hide_temporary_bars (CajaNavigationWindowPane *pane)
{
    CajaWindowSlot *slot;
    CajaDirectory *directory;
    gboolean success;

    g_assert (CAJA_IS_NAVIGATION_WINDOW_PANE (pane));

    slot = CAJA_WINDOW_PANE(pane)->active_slot;
    success = FALSE;

    if (pane->temporary_location_bar)
    {
        if (caja_navigation_window_pane_location_bar_showing (pane))
        {
            caja_navigation_window_pane_hide_location_bar (pane, FALSE);
        }
        pane->temporary_location_bar = FALSE;
        success = TRUE;
    }
    if (pane->temporary_navigation_bar)
    {
        directory = caja_directory_get (slot->location);

        if (CAJA_IS_SEARCH_DIRECTORY (directory))
        {
            caja_navigation_window_pane_set_bar_mode (pane, CAJA_BAR_SEARCH);
        }
        else
        {
            if (!g_settings_get_boolean (caja_preferences, CAJA_PREFERENCES_ALWAYS_USE_LOCATION_ENTRY))
            {
                caja_navigation_window_pane_set_bar_mode (pane, CAJA_BAR_PATH);
            }
        }
        pane->temporary_navigation_bar = FALSE;
        success = TRUE;

        caja_directory_unref (directory);
    }
    if (pane->temporary_search_bar)
    {
        CajaNavigationWindow *window;

        if (!g_settings_get_boolean (caja_preferences, CAJA_PREFERENCES_ALWAYS_USE_LOCATION_ENTRY))
        {
            caja_navigation_window_pane_set_bar_mode (pane, CAJA_BAR_PATH);
        }
        else
        {
            caja_navigation_window_pane_set_bar_mode (pane, CAJA_BAR_NAVIGATION);
        }
        window = CAJA_NAVIGATION_WINDOW (CAJA_WINDOW_PANE (pane)->window);
        caja_navigation_window_set_search_button (window, FALSE);
        pane->temporary_search_bar = FALSE;
        success = TRUE;
    }

    return success;
}