1 /* nautilus-view.h
2  *
3  * Copyright (C) 1999, 2000  Free Software Foundaton
4  * Copyright (C) 2000, 2001  Eazel, Inc.
5  *
6  * This program is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU General Public License as
8  * published by the Free Software Foundation; either version 2 of the
9  * License, or (at your option) any later version.
10  *
11  * This program is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
14  * General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public
17  * License along with this program; if not, see <http://www.gnu.org/licenses/>.
18  *
19  * Authors: Ettore Perazzoli
20  *             Darin Adler <darin@bentspoon.com>
21  *             John Sullivan <sullivan@eazel.com>
22  *          Pavel Cisler <pavel@eazel.com>
23  */
24 
25 #pragma once
26 
27 #include <gtk/gtk.h>
28 #include <gio/gio.h>
29 
30 #include "nautilus-directory.h"
31 #include "nautilus-file.h"
32 
33 #include "nautilus-window.h"
34 #include "nautilus-view.h"
35 #include "nautilus-window-slot.h"
36 
37 G_BEGIN_DECLS
38 
39 #define NAUTILUS_TYPE_FILES_VIEW nautilus_files_view_get_type()
40 
41 G_DECLARE_DERIVABLE_TYPE (NautilusFilesView, nautilus_files_view, NAUTILUS, FILES_VIEW, GtkGrid)
42 
43 struct _NautilusFilesViewClass {
44         GtkGridClass parent_class;
45 
46         /* The 'clear' signal is emitted to empty the view of its contents.
47          * It must be replaced by each subclass.
48          */
49         void         (* clear)                  (NautilusFilesView *view);
50 
51         /* The 'begin_file_changes' signal is emitted before a set of files
52          * are added to the view. It can be replaced by a subclass to do any
53          * necessary preparation for a set of new files. The default
54          * implementation does nothing.
55          */
56         void         (* begin_file_changes)     (NautilusFilesView *view);
57 
58         /* The 'add_files' signal is emitted to add a set of files to the view.
59          * It must be replaced by each subclass.
60          */
61         void    (* add_files)                    (NautilusFilesView *view,
62                                                   GList             *files);
63         void    (* remove_file)                 (NautilusFilesView *view,
64                                                  NautilusFile      *file,
65                                                  NautilusDirectory *directory);
66 
67         /* The 'file_changed' signal is emitted to signal a change in a file,
68          * including the file being removed.
69          * It must be replaced by each subclass.
70          */
71         void         (* file_changed)         (NautilusFilesView *view,
72                                                NautilusFile      *file,
73                                                NautilusDirectory *directory);
74 
75         /* The 'end_file_changes' signal is emitted after a set of files
76          * are added to the view. It can be replaced by a subclass to do any
77          * necessary cleanup (typically, cleanup for code in begin_file_changes).
78          * The default implementation does nothing.
79          */
80         void         (* end_file_changes)    (NautilusFilesView *view);
81 
82         /* The 'begin_loading' signal is emitted before any of the contents
83          * of a directory are added to the view. It can be replaced by a
84          * subclass to do any necessary preparation to start dealing with a
85          * new directory. The default implementation does nothing.
86          */
87         void         (* begin_loading)       (NautilusFilesView *view);
88 
89         /* The 'end_loading' signal is emitted after all of the contents
90          * of a directory are added to the view. It can be replaced by a
91          * subclass to do any necessary clean-up. The default implementation
92          * does nothing.
93          *
94          * If all_files_seen is true, the handler may assume that
95          * no load error ocurred, and all files of the underlying
96          * directory were loaded.
97          *
98          * Otherwise, end_loading was emitted due to cancellation,
99          * which usually means that not all files are available.
100          */
101         void         (* end_loading)          (NautilusFilesView *view,
102                                                gboolean           all_files_seen);
103 
104         /* Function pointers that don't have corresponding signals */
105 
106         /* get_backing uri is a function pointer for subclasses to
107          * override. Subclasses may replace it with a function that
108          * returns the URI for the location where to create new folders,
109          * files, links and paste the clipboard to.
110          */
111 
112         char *        (* get_backing_uri)    (NautilusFilesView *view);
113 
114         /* get_selection is not a signal; it is just a function pointer for
115          * subclasses to replace (override). Subclasses must replace it
116          * with a function that returns a newly-allocated GList of
117          * NautilusFile pointers.
118          */
119         GList *        (* get_selection)     (NautilusFilesView *view);
120 
121         /* get_selection_for_file_transfer  is a function pointer for
122          * subclasses to replace (override). Subclasses must replace it
123          * with a function that returns a newly-allocated GList of
124          * NautilusFile pointers. The difference from get_selection is
125          * that any files in the selection that also has a parent folder
126          * in the selection is not included.
127          */
128         GList *        (* get_selection_for_file_transfer)(NautilusFilesView *view);
129 
130         /* select_all is a function pointer that subclasses must override to
131          * select all of the items in the view */
132         void     (* select_all)              (NautilusFilesView *view);
133 
134         /* select_first is a function pointer that subclasses must override to
135          * select the first item in the view */
136         void     (* select_first)            (NautilusFilesView *view);
137 
138         /* set_selection is a function pointer that subclasses must
139          * override to select the specified items (and unselect all
140          * others). The argument is a list of NautilusFiles. */
141 
142         void     (* set_selection)           (NautilusFilesView *view,
143                                               GList             *selection);
144 
145         /* invert_selection is a function pointer that subclasses must
146          * override to invert selection. */
147 
148         void     (* invert_selection)        (NautilusFilesView *view);
149 
150         /* bump_zoom_level is a function pointer that subclasses must override
151          * to change the zoom level of an object. */
152         void    (* bump_zoom_level)          (NautilusFilesView *view,
153                                               int                zoom_increment);
154 
155         /*
156          * restore_default_zoom_level: restores the zoom level to 100% (or to
157          * whatever is considered the 'standard' zoom level for the view). */
158         void    (* restore_standard_zoom_level) (NautilusFilesView *view);
159 
160         /* can_zoom_in is a function pointer that subclasses must override to
161          * return whether the view is at maximum size (furthest-in zoom level) */
162         gboolean (* can_zoom_in)             (NautilusFilesView *view);
163 
164         /* can_zoom_out is a function pointer that subclasses must override to
165          * return whether the view is at minimum size (furthest-out zoom level) */
166         gboolean (* can_zoom_out)            (NautilusFilesView *view);
167 
168         /* The current zoom level as a percentage of the default. */
169         gfloat   (* get_zoom_level_percentage) (NautilusFilesView *view);
170 
171         gboolean (*is_zoom_level_default)      (NautilusFilesView *view);
172 
173         /* reveal_selection is a function pointer that subclasses may
174          * override to make sure the selected items are sufficiently
175          * apparent to the user (e.g., scrolled into view). By default,
176          * this does nothing.
177          */
178         void     (* reveal_selection)        (NautilusFilesView *view);
179 
180         /* update_menus is a function pointer that subclasses can override to
181          * update the sensitivity or wording of menu items in the menu bar.
182          * It is called (at least) whenever the selection changes. If overridden,
183          * subclasses must call parent class's function.
184          */
185         void    (* update_context_menus)     (NautilusFilesView *view);
186 
187         void    (* update_actions_state)     (NautilusFilesView *view);
188 
189         /* sort_files is a function pointer that subclasses can override
190          * to provide a sorting order to determine which files should be
191          * presented when only a partial list is provided.
192          */
193         int     (* compare_files)            (NautilusFilesView *view,
194                                               NautilusFile      *a,
195                                               NautilusFile      *b);
196 
197         /* is_empty is a function pointer that subclasses must
198          * override to report whether the view contains any items.
199          */
200         gboolean (* is_empty)                (NautilusFilesView *view);
201 
202         /* convert *point from widget's coordinate system to a coordinate
203          * system used for specifying file operation positions, which is view-specific.
204          *
205          * This is used by the the icon view, which converts the screen position to a zoom
206          * level-independent coordinate system.
207          */
208         void (* widget_to_file_operation_position) (NautilusFilesView *view,
209                                                     GdkPoint     *position);
210 
211         /* Preference change callbacks, overridden by icon and list views.
212          * Icon and list views respond by synchronizing to the new preference
213          * values and forcing an update if appropriate.
214          */
215         void        (* click_policy_changed) (NautilusFilesView *view);
216         void        (* sort_directories_first_changed) (NautilusFilesView *view);
217 
218         /* Get the id for this view. Its a guint*/
219         guint        (* get_view_id)       (NautilusFilesView *view);
220 
221         /* Return the uri of the first visible file */
222         char *         (* get_first_visible_file) (NautilusFilesView          *view);
223         /* Scroll the view so that the file specified by the uri is at the top
224            of the view */
225         void           (* scroll_to_file)    (NautilusFilesView *view,
226                                               const char        *uri);
227 
228         NautilusWindow * (*get_window)       (NautilusFilesView *view);
229 
230         GdkRectangle * (* compute_rename_popover_pointing_to) (NautilusFilesView *view);
231 
232         GdkRectangle * (* reveal_for_selection_context_menu) (NautilusFilesView *view);
233 
234         GIcon *        (* get_icon)          (NautilusFilesView *view);
235 
236         /* Use this to show an optional visual feedback when the directory is empty.
237          * By default it shows a widget overlay on top of the view */
238         void           (* check_empty_states)          (NautilusFilesView *view);
239 
240         void           (* preview_selection_event)     (NautilusFilesView *view,
241                                                         GtkDirectionType   direction);
242 };
243 
244 NautilusFilesView *      nautilus_files_view_new                         (guint               id,
245                                                                           NautilusWindowSlot *slot);
246 
247 /* Functions callable from the user interface and elsewhere. */
248 NautilusWindowSlot *nautilus_files_view_get_nautilus_window_slot         (NautilusFilesView *view);
249 char *              nautilus_files_view_get_uri                          (NautilusFilesView *view);
250 
251 void                nautilus_files_view_display_selection_info           (NautilusFilesView *view);
252 
253 /* Wrappers for signal emitters. These are normally called
254  * only by NautilusFilesView itself. They have corresponding signals
255  * that observers might want to connect with.
256  */
257 gboolean            nautilus_files_view_get_loading                      (NautilusFilesView *view);
258 
259 /* Hooks for subclasses to call. These are normally called only by
260  * NautilusFilesView and its subclasses
261  */
262 void                nautilus_files_view_activate_files                   (NautilusFilesView       *view,
263                                                                           GList                   *files,
264                                                                           NautilusWindowOpenFlags  flags,
265                                                                           gboolean                 confirm_multiple);
266 void                nautilus_files_view_activate_file                    (NautilusFilesView       *view,
267                                                                           NautilusFile            *file,
268                                                                           NautilusWindowOpenFlags  flags);
269 void                nautilus_files_view_preview_files                    (NautilusFilesView *view,
270                                                                           GList             *files,
271                                                                           GArray            *locations);
272 void                nautilus_files_view_start_batching_selection_changes (NautilusFilesView *view);
273 void                nautilus_files_view_stop_batching_selection_changes  (NautilusFilesView *view);
274 void                nautilus_files_view_notify_selection_changed         (NautilusFilesView *view);
275 NautilusDirectory  *nautilus_files_view_get_model                        (NautilusFilesView *view);
276 NautilusFile       *nautilus_files_view_get_directory_as_file            (NautilusFilesView *view);
277 void                nautilus_files_view_pop_up_background_context_menu   (NautilusFilesView *view,
278                                                                           const GdkEvent    *event);
279 void                nautilus_files_view_pop_up_selection_context_menu    (NautilusFilesView *view,
280                                                                           const GdkEvent    *event);
281 gboolean            nautilus_files_view_should_show_file                 (NautilusFilesView *view,
282                                                                           NautilusFile      *file);
283 gboolean            nautilus_files_view_should_sort_directories_first    (NautilusFilesView *view);
284 void                nautilus_files_view_ignore_hidden_file_preferences   (NautilusFilesView *view);
285 
286 void                nautilus_files_view_add_subdirectory                (NautilusFilesView *view,
287                                                                          NautilusDirectory *directory);
288 void                nautilus_files_view_remove_subdirectory             (NautilusFilesView *view,
289                                                                          NautilusDirectory *directory);
290 
291 gboolean            nautilus_files_view_is_editable              (NautilusFilesView      *view);
292 NautilusWindow *    nautilus_files_view_get_window               (NautilusFilesView      *view);
293 
294 /* file operations */
295 char *            nautilus_files_view_get_backing_uri            (NautilusFilesView      *view);
296 void              nautilus_files_view_move_copy_items            (NautilusFilesView      *view,
297                                                                   const GList            *item_uris,
298                                                                   const char             *target_uri,
299                                                                   int                     copy_action);
300 void              nautilus_files_view_new_file_with_initial_contents (NautilusFilesView  *view,
301                                                                       const char         *parent_uri,
302                                                                       const char         *filename,
303                                                                       const char         *initial_contents,
304                                                                       int                 length);
305 
306 /* selection handling */
307 void              nautilus_files_view_activate_selection         (NautilusFilesView      *view);
308 void              nautilus_files_view_preview_selection_event    (NautilusFilesView      *view,
309                                                                   GtkDirectionType        direction);
310 void              nautilus_files_view_stop_loading               (NautilusFilesView      *view);
311 
312 char *            nautilus_files_view_get_first_visible_file     (NautilusFilesView      *view);
313 void              nautilus_files_view_scroll_to_file             (NautilusFilesView      *view,
314                                                                   const char             *uri);
315 char *            nautilus_files_view_get_title                  (NautilusFilesView      *view);
316 gboolean          nautilus_files_view_supports_zooming           (NautilusFilesView      *view);
317 void              nautilus_files_view_bump_zoom_level            (NautilusFilesView      *view,
318                                                                   int                     zoom_increment);
319 gboolean          nautilus_files_view_can_zoom_in                (NautilusFilesView      *view);
320 gboolean          nautilus_files_view_can_zoom_out               (NautilusFilesView      *view);
321 
322 void              nautilus_files_view_update_context_menus       (NautilusFilesView      *view);
323 void              nautilus_files_view_update_toolbar_menus       (NautilusFilesView      *view);
324 void              nautilus_files_view_update_actions_state       (NautilusFilesView      *view);
325 
326 void              nautilus_files_view_action_show_hidden_files   (NautilusFilesView      *view,
327                                                                   gboolean                show_hidden);
328 
329 GActionGroup *    nautilus_files_view_get_action_group           (NautilusFilesView      *view);
330 GtkWidget*        nautilus_files_view_get_content_widget         (NautilusFilesView      *view);
331 
332 G_END_DECLS
333