summaryrefslogtreecommitdiff
path: root/src/caja-navigation-window-slot.c
blob: 4bf2844715551a1362439fcf3fd01c7ccbe33869 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
/* -*- Mode: C; indent-tabs-mode: t; c-basic-offset: 8; tab-width: 8 -*-

   caja-navigation-window-slot.c: Caja navigation window slot

   Copyright (C) 2008 Free Software Foundation, Inc.

   This program is free software; you can redistribute it and/or
   modify it under the terms of the GNU General Public License as
   published by the Free Software Foundation; either version 2 of the
   License, or (at your option) any later version.

   This program is distributed in the hope that it will be useful,
   but WITHOUT ANY WARRANTY; without even the implied warranty of
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
   General Public License for more details.

   You should have received a copy of the GNU General Public
   License along with this program; if not, write to the
   Free Software Foundation, Inc., 59 Temple Place - Suite 330,
   Boston, MA 02111-1307, USA.

   Author: Christian Neumair <cneumair@gnome.org>
*/

#include "caja-window-slot.h"
#include "caja-navigation-window-slot.h"
#include "caja-window-private.h"
#include "caja-search-bar.h"
#include "caja-navigation-window-pane.h"
#include <libcaja-private/caja-window-slot-info.h>
#include <libcaja-private/caja-file.h>
#include <eel/eel-gtk-macros.h>

static void caja_navigation_window_slot_init       (CajaNavigationWindowSlot *slot);
static void caja_navigation_window_slot_class_init (CajaNavigationWindowSlotClass *class);

G_DEFINE_TYPE (CajaNavigationWindowSlot, caja_navigation_window_slot, CAJA_TYPE_WINDOW_SLOT)
#define parent_class caja_navigation_window_slot_parent_class

gboolean
caja_navigation_window_slot_should_close_with_mount (CajaNavigationWindowSlot *slot,
        GMount *mount)
{
    CajaBookmark *bookmark;
    GFile *mount_location, *bookmark_location;
    GList *l;
    gboolean close_with_mount;

    if (slot->parent.pane->window->details->initiated_unmount)
    {
        return FALSE;
    }

    mount_location = g_mount_get_root (mount);

    close_with_mount = TRUE;

    for (l = slot->back_list; l != NULL; l = l->next)
    {
        bookmark = CAJA_BOOKMARK (l->data);

        bookmark_location = caja_bookmark_get_location (bookmark);
        close_with_mount &= g_file_has_prefix (bookmark_location, mount_location) ||
                            g_file_equal (bookmark_location, mount_location);
        g_object_unref (bookmark_location);

        if (!close_with_mount)
        {
            break;
        }
    }

    close_with_mount &= g_file_has_prefix (CAJA_WINDOW_SLOT (slot)->location, mount_location) ||
                        g_file_equal (CAJA_WINDOW_SLOT (slot)->location, mount_location);

    /* we could also consider the forward list here, but since the “go home” request
     * in caja-window-manager-views.c:mount_removed_callback() would discard those
     * anyway, we don't consider them.
     */

    g_object_unref (mount_location);

    return close_with_mount;
}

void
caja_navigation_window_slot_clear_forward_list (CajaNavigationWindowSlot *slot)
{
    g_assert (CAJA_IS_NAVIGATION_WINDOW_SLOT (slot));

    eel_g_object_list_free (slot->forward_list);
    slot->forward_list = NULL;
}

void
caja_navigation_window_slot_clear_back_list (CajaNavigationWindowSlot *slot)
{
    g_assert (CAJA_IS_NAVIGATION_WINDOW_SLOT (slot));

    eel_g_object_list_free (slot->back_list);
    slot->back_list = NULL;
}

static void
query_editor_changed_callback (CajaSearchBar *bar,
                               CajaQuery *query,
                               gboolean reload,
                               CajaWindowSlot *slot)
{
    CajaDirectory *directory;

    g_assert (CAJA_IS_FILE (slot->viewed_file));

    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
caja_navigation_window_slot_update_query_editor (CajaWindowSlot *slot)
{
    CajaDirectory *directory;
    CajaSearchDirectory *search_directory;
    CajaQuery *query;
    CajaNavigationWindow *navigation_window;
    GtkWidget *query_editor;

    g_assert (slot->pane->window != NULL);
    navigation_window = CAJA_NAVIGATION_WINDOW (slot->pane->window);

    query_editor = NULL;

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

        if (caja_search_directory_is_saved_search (search_directory))
        {
            query_editor = caja_query_editor_new (TRUE,
                                                  caja_search_directory_is_indexed (search_directory));
        }
        else
        {
            query_editor = caja_query_editor_new_with_bar (FALSE,
                           caja_search_directory_is_indexed (search_directory),
                           slot->pane->window->details->active_pane->active_slot == slot,
                           CAJA_SEARCH_BAR (CAJA_NAVIGATION_WINDOW_PANE (slot->pane)->search_bar),
                           slot);
        }
    }

    slot->query_editor = CAJA_QUERY_EDITOR (query_editor);

    if (query_editor != NULL)
    {
        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_window_slot_add_extra_location_widget (slot, query_editor);
        gtk_widget_show (query_editor);
        caja_query_editor_grab_focus (CAJA_QUERY_EDITOR (query_editor));
    }

    caja_directory_unref (directory);
}

static void
caja_navigation_window_slot_active (CajaWindowSlot *slot)
{
    CajaNavigationWindow *window;
    CajaNavigationWindowSlot *navigation_slot;
    CajaNavigationWindowPane *pane;
    int page_num;

    navigation_slot = CAJA_NAVIGATION_WINDOW_SLOT (slot);
    pane = CAJA_NAVIGATION_WINDOW_PANE (slot->pane);
    window = CAJA_NAVIGATION_WINDOW (slot->pane->window);

    page_num = gtk_notebook_page_num (GTK_NOTEBOOK (pane->notebook),
                                      slot->content_box);
    g_assert (page_num >= 0);

    gtk_notebook_set_current_page (GTK_NOTEBOOK (pane->notebook), page_num);

    EEL_CALL_PARENT (CAJA_WINDOW_SLOT_CLASS, active, (slot));

    if (slot->viewed_file != NULL)
    {
        caja_navigation_window_load_extension_toolbar_items (window);
    }
}

static void
caja_navigation_window_slot_dispose (GObject *object)
{
    CajaNavigationWindowSlot *slot;

    slot = CAJA_NAVIGATION_WINDOW_SLOT (object);

    caja_navigation_window_slot_clear_forward_list (slot);
    caja_navigation_window_slot_clear_back_list (slot);

    G_OBJECT_CLASS (parent_class)->dispose (object);
}

static void
caja_navigation_window_slot_init (CajaNavigationWindowSlot *slot)
{
}

static void
caja_navigation_window_slot_class_init (CajaNavigationWindowSlotClass *class)
{
    CAJA_WINDOW_SLOT_CLASS (class)->active = caja_navigation_window_slot_active;
    CAJA_WINDOW_SLOT_CLASS (class)->update_query_editor = caja_navigation_window_slot_update_query_editor;

    G_OBJECT_CLASS (class)->dispose = caja_navigation_window_slot_dispose;
}