1 /*
2    nautilus-directory.h: Nautilus directory model.
3 
4    Copyright (C) 1999, 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    Author: Darin Adler <darin@bentspoon.com>
20 */
21 
22 #pragma once
23 
24 #include <gtk/gtk.h>
25 #include <gio/gio.h>
26 
27 #include "nautilus-enums.h"
28 
29 /* NautilusDirectory is a class that manages the model for a directory,
30    real or virtual, for Nautilus, mainly the file-manager component. The directory is
31    responsible for managing both real data and cached metadata. On top of
32    the file system independence provided by gio, the directory
33    object also provides:
34 
35        1) A synchronization framework, which notifies via signals as the
36           set of known files changes.
37        2) An abstract interface for getting attributes and performing
38           operations on files.
39 */
40 
41 #define NAUTILUS_DIRECTORY_PROVIDER_EXTENSION_POINT_NAME "nautilus-directory-provider"
42 
43 #define NAUTILUS_TYPE_DIRECTORY nautilus_directory_get_type()
44 #define NAUTILUS_DIRECTORY(obj) \
45   (G_TYPE_CHECK_INSTANCE_CAST ((obj), NAUTILUS_TYPE_DIRECTORY, NautilusDirectory))
46 #define NAUTILUS_DIRECTORY_CLASS(klass) \
47   (G_TYPE_CHECK_CLASS_CAST ((klass), NAUTILUS_TYPE_DIRECTORY, NautilusDirectoryClass))
48 #define NAUTILUS_IS_DIRECTORY(obj) \
49   (G_TYPE_CHECK_INSTANCE_TYPE ((obj), NAUTILUS_TYPE_DIRECTORY))
50 #define NAUTILUS_IS_DIRECTORY_CLASS(klass) \
51   (G_TYPE_CHECK_CLASS_TYPE ((klass), NAUTILUS_TYPE_DIRECTORY))
52 #define NAUTILUS_DIRECTORY_GET_CLASS(obj) \
53   (G_TYPE_INSTANCE_GET_CLASS ((obj), NAUTILUS_TYPE_DIRECTORY, NautilusDirectoryClass))
54 
55 /* NautilusFile is defined both here and in nautilus-file.h. */
56 #ifndef NAUTILUS_FILE_DEFINED
57 #define NAUTILUS_FILE_DEFINED
58 typedef struct NautilusFile NautilusFile;
59 #endif
60 
61 typedef struct _NautilusDirectory        NautilusDirectory;
62 typedef struct  NautilusDirectoryDetails NautilusDirectoryDetails;
63 
64 struct _NautilusDirectory
65 {
66 	GObject object;
67 	NautilusDirectoryDetails *details;
68 };
69 
70 typedef void (*NautilusDirectoryCallback) (NautilusDirectory *directory,
71 					   GList             *files,
72 					   gpointer           callback_data);
73 
74 typedef struct
75 {
76 	GObjectClass parent_class;
77 
78 	/*** Notification signals for clients to connect to. ***/
79 
80 	/* The files_added signal is emitted as the directory model
81 	 * discovers new files.
82 	 */
83 	void     (* files_added)         (NautilusDirectory          *directory,
84 					  GList                      *added_files);
85 
86 	/* The files_changed signal is emitted as changes occur to
87 	 * existing files that are noticed by the synchronization framework,
88 	 * including when an old file has been deleted. When an old file
89 	 * has been deleted, this is the last chance to forget about these
90 	 * file objects, which are about to be unref'd. Use a call to
91 	 * nautilus_file_is_gone () to test for this case.
92 	 */
93 	void     (* files_changed)       (NautilusDirectory         *directory,
94 					  GList                     *changed_files);
95 
96 	/* The done_loading signal is emitted when a directory load
97 	 * request completes. This is needed because, at least in the
98 	 * case where the directory is empty, the caller will receive
99 	 * no kind of notification at all when a directory load
100 	 * initiated by `nautilus_directory_file_monitor_add' completes.
101 	 */
102 	void     (* done_loading)        (NautilusDirectory         *directory);
103 
104 	void     (* load_error)          (NautilusDirectory         *directory,
105 					  GError                    *error);
106 
107 	/*** Virtual functions for subclasses to override. ***/
108 	gboolean (* contains_file)       (NautilusDirectory         *directory,
109 					  NautilusFile              *file);
110 	void     (* call_when_ready)     (NautilusDirectory         *directory,
111 					  NautilusFileAttributes     file_attributes,
112 					  gboolean                   wait_for_file_list,
113 					  NautilusDirectoryCallback  callback,
114 					  gpointer                   callback_data);
115 	void     (* cancel_callback)     (NautilusDirectory         *directory,
116 					  NautilusDirectoryCallback  callback,
117 					  gpointer                   callback_data);
118 	void     (* file_monitor_add)    (NautilusDirectory          *directory,
119 					  gconstpointer              client,
120 					  gboolean                   monitor_hidden_files,
121 					  NautilusFileAttributes     monitor_attributes,
122 					  NautilusDirectoryCallback  initial_files_callback,
123 					  gpointer                   callback_data);
124 	void     (* file_monitor_remove) (NautilusDirectory         *directory,
125 					  gconstpointer              client);
126 	void     (* force_reload)        (NautilusDirectory         *directory);
127 	gboolean (* are_all_files_seen)  (NautilusDirectory         *directory);
128 	gboolean (* is_not_empty)        (NautilusDirectory         *directory);
129 
130 	/* get_file_list is a function pointer that subclasses may override to
131 	 * customize collecting the list of files in a directory.
132 	 * For example, the NautilusDesktopDirectory overrides this so that it can
133 	 * merge together the list of files in the $HOME/Desktop directory with
134 	 * the list of standard icons (Home, Trash) on the desktop.
135 	 */
136 	GList *	 (* get_file_list)	 (NautilusDirectory *directory);
137 
138 	/* Should return FALSE if the directory is read-only and doesn't
139 	 * allow setting of metadata.
140 	 * An example of this is the search directory.
141 	 */
142 	gboolean (* is_editable)         (NautilusDirectory *directory);
143 
144         /* Subclasses can use this to create custom files when asked by the user
145          * or the nautilus cache. */
146         NautilusFile * (* new_file_from_filename) (NautilusDirectory *directory,
147                                                    const char        *filename,
148                                                    gboolean           self_owned);
149         /* Subclasses can say if they handle the location provided or should the
150          * nautilus file class handle it.
151          */
152         gboolean       (* handles_location)       (GFile             *location);
153 } NautilusDirectoryClass;
154 
155 /* Basic GObject requirements. */
156 GType              nautilus_directory_get_type                 (void);
157 
158 /* Get a directory given a uri.
159  * Creates the appropriate subclass given the uri mappings.
160  * Returns a referenced object, not a floating one. Unref when finished.
161  * If two windows are viewing the same uri, the directory object is shared.
162  */
163 NautilusDirectory *nautilus_directory_get                      (GFile                     *location);
164 NautilusDirectory *nautilus_directory_get_by_uri               (const char                *uri);
165 NautilusDirectory *nautilus_directory_get_for_file             (NautilusFile              *file);
166 
167 /* Covers for g_object_ref and g_object_unref that provide two conveniences:
168  * 1) Using these is type safe.
169  * 2) You are allowed to call these with NULL,
170  */
171 NautilusDirectory *nautilus_directory_ref                      (NautilusDirectory         *directory);
172 void               nautilus_directory_unref                    (NautilusDirectory         *directory);
173 
174 G_DEFINE_AUTOPTR_CLEANUP_FUNC (NautilusDirectory, nautilus_directory_unref)
175 
176 /* Access to a URI. */
177 char *             nautilus_directory_get_uri                  (NautilusDirectory         *directory);
178 GFile *            nautilus_directory_get_location             (NautilusDirectory         *directory);
179 
180 /* Is this file still alive and in this directory? */
181 gboolean           nautilus_directory_contains_file            (NautilusDirectory         *directory,
182 								NautilusFile              *file);
183 
184 NautilusFile*           nautilus_directory_get_file_by_name            (NautilusDirectory *directory,
185                                                                         const gchar       *name);
186 /* Get (and ref) a NautilusFile object for this directory. */
187 NautilusFile *     nautilus_directory_get_corresponding_file   (NautilusDirectory         *directory);
188 
189 /* Waiting for data that's read asynchronously.
190  * The file attribute and metadata keys are for files in the directory.
191  */
192 void               nautilus_directory_call_when_ready          (NautilusDirectory         *directory,
193 								NautilusFileAttributes     file_attributes,
194 								gboolean                   wait_for_all_files,
195 								NautilusDirectoryCallback  callback,
196 								gpointer                   callback_data);
197 void               nautilus_directory_cancel_callback          (NautilusDirectory         *directory,
198 								NautilusDirectoryCallback  callback,
199 								gpointer                   callback_data);
200 
201 
202 /* Monitor the files in a directory. */
203 void               nautilus_directory_file_monitor_add         (NautilusDirectory         *directory,
204 								gconstpointer              client,
205 								gboolean                   monitor_hidden_files,
206 								NautilusFileAttributes     attributes,
207 								NautilusDirectoryCallback  initial_files_callback,
208 								gpointer                   callback_data);
209 void               nautilus_directory_file_monitor_remove      (NautilusDirectory         *directory,
210 								gconstpointer              client);
211 void               nautilus_directory_force_reload             (NautilusDirectory         *directory);
212 
213 /* Get a list of all files currently known in the directory. */
214 GList *            nautilus_directory_get_file_list            (NautilusDirectory         *directory);
215 
216 GList *            nautilus_directory_match_pattern            (NautilusDirectory         *directory,
217 							        const char *glob);
218 
219 
220 /* Return true if the directory has information about all the files.
221  * This will be false until the directory has been read at least once.
222  */
223 gboolean           nautilus_directory_are_all_files_seen       (NautilusDirectory         *directory);
224 
225 gboolean           nautilus_directory_is_local_or_fuse         (NautilusDirectory         *directory);
226 
227 gboolean           nautilus_directory_is_in_trash              (NautilusDirectory         *directory);
228 gboolean           nautilus_directory_is_in_recent             (NautilusDirectory         *directory);
229 gboolean           nautilus_directory_is_in_starred            (NautilusDirectory         *directory);
230 gboolean           nautilus_directory_is_in_admin              (NautilusDirectory         *directory);
231 
232 /* Return false if directory contains anything besides a Nautilus metafile.
233  * Only valid if directory is monitored. Used by the Trash monitor.
234  */
235 gboolean           nautilus_directory_is_not_empty             (NautilusDirectory         *directory);
236 
237 /* Convenience functions for dealing with a list of NautilusDirectory objects that each have a ref.
238  * These are just convenient names for functions that work on lists of GtkObject *.
239  */
240 GList *            nautilus_directory_list_ref                 (GList                     *directory_list);
241 void               nautilus_directory_list_unref               (GList                     *directory_list);
242 void               nautilus_directory_list_free                (GList                     *directory_list);
243 GList *            nautilus_directory_list_copy                (GList                     *directory_list);
244 GList *            nautilus_directory_list_sort_by_uri         (GList                     *directory_list);
245 
246 gboolean           nautilus_directory_is_editable              (NautilusDirectory         *directory);
247 
248 void               nautilus_directory_dump                     (NautilusDirectory         *directory);
249 
250 NautilusFile *     nautilus_directory_new_file_from_filename   (NautilusDirectory *directory,
251                                                                 const char        *filename,
252                                                                 gboolean           self_owned);
253