2007-12-11 A. Walton <awalton@svn.gnome.org>
[nautilus.git] / libnautilus-private / nautilus-file.h
blobb2c94481df6a5194cc4cf6444909c8e0f3cf50aa
1 /* -*- Mode: C; indent-tabs-mode: t; c-basic-offset: 8; tab-width: 8 -*-
3 nautilus-file.h: Nautilus file model.
5 Copyright (C) 1999, 2000, 2001 Eazel, Inc.
7 This program is free software; you can redistribute it and/or
8 modify it under the terms of the GNU General Public License as
9 published by the Free Software Foundation; either version 2 of the
10 License, or (at your option) any later version.
12 This program is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 General Public License for more details.
17 You should have received a copy of the GNU General Public
18 License along with this program; if not, write to the
19 Free Software Foundation, Inc., 59 Temple Place - Suite 330,
20 Boston, MA 02111-1307, USA.
22 Author: Darin Adler <darin@bentspoon.com>
25 #ifndef NAUTILUS_FILE_H
26 #define NAUTILUS_FILE_H
28 #include <gtk/gtkobject.h>
29 #include <gio/gfileinfo.h>
30 #include <gio/gfile.h>
31 #include <gio/gioerror.h>
32 #include <libnautilus-private/nautilus-file-attributes.h>
33 #include <libnautilus-private/nautilus-icon-info.h>
35 /* NautilusFile is an object used to represent a single element of a
36 * NautilusDirectory. It's lightweight and relies on NautilusDirectory
37 * to do most of the work.
40 /* NautilusFile is defined both here and in nautilus-directory.h. */
41 #ifndef NAUTILUS_FILE_DEFINED
42 #define NAUTILUS_FILE_DEFINED
43 typedef struct NautilusFile NautilusFile;
44 #endif
46 #define NAUTILUS_TYPE_FILE \
47 (nautilus_file_get_type ())
48 #define NAUTILUS_FILE(obj) \
49 (GTK_CHECK_CAST ((obj), NAUTILUS_TYPE_FILE, NautilusFile))
50 #define NAUTILUS_FILE_CLASS(klass) \
51 (GTK_CHECK_CLASS_CAST ((klass), NAUTILUS_TYPE_FILE, NautilusFileClass))
52 #define NAUTILUS_IS_FILE(obj) \
53 (GTK_CHECK_TYPE ((obj), NAUTILUS_TYPE_FILE))
54 #define NAUTILUS_IS_FILE_CLASS(klass) \
55 (GTK_CHECK_CLASS_TYPE ((klass), NAUTILUS_TYPE_FILE))
56 #define NAUTILUS_FILE_GET_CLASS(obj) \
57 (G_TYPE_INSTANCE_GET_CLASS ((obj), NAUTILUS_TYPE_FILE, NautilusFileClass))
59 typedef enum {
60 NAUTILUS_FILE_SORT_NONE,
61 NAUTILUS_FILE_SORT_BY_DISPLAY_NAME,
62 NAUTILUS_FILE_SORT_BY_DIRECTORY,
63 NAUTILUS_FILE_SORT_BY_SIZE,
64 NAUTILUS_FILE_SORT_BY_TYPE,
65 NAUTILUS_FILE_SORT_BY_MTIME,
66 NAUTILUS_FILE_SORT_BY_ATIME,
67 NAUTILUS_FILE_SORT_BY_EMBLEMS
68 } NautilusFileSortType;
70 typedef enum {
71 NAUTILUS_REQUEST_NOT_STARTED,
72 NAUTILUS_REQUEST_IN_PROGRESS,
73 NAUTILUS_REQUEST_DONE
74 } NautilusRequestStatus;
76 typedef enum {
77 NAUTILUS_FILE_ICON_FLAGS_NONE = 0,
78 NAUTILUS_FILE_ICON_FLAGS_USE_THUMBNAILS = (1<<0),
79 NAUTILUS_FILE_ICON_FLAGS_IGNORE_VISITING = (1<<1),
80 NAUTILUS_FILE_ICON_FLAGS_EMBEDDING_TEXT = (1<<2),
81 NAUTILUS_FILE_ICON_FLAGS_FOR_DRAG_ACCEPT = (1<<3),
82 NAUTILUS_FILE_ICON_FLAGS_FOR_OPEN_FOLDER = (1<<4)
83 } NautilusFileIconFlags;
85 /* Emblems sometimes displayed for NautilusFiles. Do not localize. */
86 #define NAUTILUS_FILE_EMBLEM_NAME_SYMBOLIC_LINK "symbolic-link"
87 #define NAUTILUS_FILE_EMBLEM_NAME_CANT_READ "noread"
88 #define NAUTILUS_FILE_EMBLEM_NAME_CANT_WRITE "nowrite"
89 #define NAUTILUS_FILE_EMBLEM_NAME_TRASH "trash"
90 #define NAUTILUS_FILE_EMBLEM_NAME_NOTE "note"
91 #define NAUTILUS_FILE_EMBLEM_NAME_DESKTOP "desktop"
93 typedef void (*NautilusFileCallback) (NautilusFile *file,
94 gpointer callback_data);
95 typedef void (*NautilusFileListCallback) (GList *file_list,
96 gpointer callback_data);
97 typedef void (*NautilusFileOperationCallback) (NautilusFile *file,
98 GFile *result_location,
99 GError *error,
100 gpointer callback_data);
101 typedef int (*NautilusWidthMeasureCallback) (const char *string,
102 void *context);
103 typedef char * (*NautilusTruncateCallback) (const char *string,
104 int width,
105 void *context);
108 #define NAUTILUS_FILE_ATTRIBUTES_FOR_ICON (NAUTILUS_FILE_ATTRIBUTE_INFO | NAUTILUS_FILE_ATTRIBUTE_LINK_INFO |NAUTILUS_FILE_ATTRIBUTE_METADATA | NAUTILUS_FILE_ATTRIBUTE_THUMBNAIL)
110 typedef void NautilusFileListHandle;
112 /* GObject requirements. */
113 GType nautilus_file_get_type (void);
115 /* Getting at a single file. */
116 NautilusFile * nautilus_file_get (GFile *location);
117 NautilusFile * nautilus_file_get_by_uri (const char *uri);
119 /* Get a file only if the nautilus version already exists */
120 NautilusFile * nautilus_file_get_existing (GFile *location);
121 NautilusFile * nautilus_file_get_existing_by_uri (const char *uri);
123 /* Covers for gtk_object_ref and gtk_object_unref that provide two conveniences:
124 * 1) You don't have to cast to GtkObject *, so using these is type safe.
125 * 2) You are allowed to call these with NULL,
127 NautilusFile * nautilus_file_ref (NautilusFile *file);
128 void nautilus_file_unref (NautilusFile *file);
130 /* Monitor the file. */
131 void nautilus_file_monitor_add (NautilusFile *file,
132 gconstpointer client,
133 NautilusFileAttributes attributes);
134 void nautilus_file_monitor_remove (NautilusFile *file,
135 gconstpointer client);
137 /* Waiting for data that's read asynchronously.
138 * This interface currently works only for metadata, but could be expanded
139 * to other attributes as well.
141 void nautilus_file_call_when_ready (NautilusFile *file,
142 NautilusFileAttributes attributes,
143 NautilusFileCallback callback,
144 gpointer callback_data);
145 void nautilus_file_cancel_call_when_ready (NautilusFile *file,
146 NautilusFileCallback callback,
147 gpointer callback_data);
148 gboolean nautilus_file_check_if_ready (NautilusFile *file,
149 NautilusFileAttributes attributes);
150 void nautilus_file_invalidate_attributes (NautilusFile *file,
151 NautilusFileAttributes attributes);
152 void nautilus_file_invalidate_all_attributes (NautilusFile *file);
154 /* Basic attributes for file objects. */
155 gboolean nautilus_file_contains_text (NautilusFile *file);
156 char * nautilus_file_get_display_name (NautilusFile *file);
157 char * nautilus_file_get_edit_name (NautilusFile *file);
158 char * nautilus_file_get_name (NautilusFile *file);
159 GFile * nautilus_file_get_location (NautilusFile *file);
160 char * nautilus_file_get_uri (NautilusFile *file);
161 char * nautilus_file_get_uri_scheme (NautilusFile *file);
162 NautilusFile * nautilus_file_get_parent (NautilusFile *file);
163 GFile * nautilus_file_get_parent_location (NautilusFile *file);
164 char * nautilus_file_get_parent_uri (NautilusFile *file);
165 char * nautilus_file_get_parent_uri_for_display (NautilusFile *file);
166 gboolean nautilus_file_can_get_size (NautilusFile *file);
167 goffset nautilus_file_get_size (NautilusFile *file);
168 time_t nautilus_file_get_mtime (NautilusFile *file);
169 GFileType nautilus_file_get_file_type (NautilusFile *file);
170 char * nautilus_file_get_mime_type (NautilusFile *file);
171 gboolean nautilus_file_is_mime_type (NautilusFile *file,
172 const char *mime_type);
173 gboolean nautilus_file_is_launchable (NautilusFile *file);
174 gboolean nautilus_file_is_symbolic_link (NautilusFile *file);
175 gboolean nautilus_file_is_mountpoint (NautilusFile *file);
176 char * nautilus_file_get_volume_free_space (NautilusFile *file);
177 char * nautilus_file_get_volume_name (NautilusFile *file);
178 char * nautilus_file_get_symbolic_link_target_path (NautilusFile *file);
179 char * nautilus_file_get_symbolic_link_target_uri (NautilusFile *file);
180 gboolean nautilus_file_is_broken_symbolic_link (NautilusFile *file);
181 gboolean nautilus_file_is_nautilus_link (NautilusFile *file);
182 gboolean nautilus_file_is_executable (NautilusFile *file);
183 gboolean nautilus_file_is_directory (NautilusFile *file);
184 gboolean nautilus_file_is_in_trash (NautilusFile *file);
185 gboolean nautilus_file_is_in_desktop (NautilusFile *file);
186 gboolean nautilus_file_is_home (NautilusFile *file);
187 gboolean nautilus_file_is_desktop_directory (NautilusFile *file);
188 GError * nautilus_file_get_file_info_error (NautilusFile *file);
189 gboolean nautilus_file_get_directory_item_count (NautilusFile *file,
190 guint *count,
191 gboolean *count_unreadable);
192 void nautilus_file_recompute_deep_counts (NautilusFile *file);
193 NautilusRequestStatus nautilus_file_get_deep_counts (NautilusFile *file,
194 guint *directory_count,
195 guint *file_count,
196 guint *unreadable_directory_count,
197 goffset *total_size,
198 gboolean force);
199 gboolean nautilus_file_should_show_thumbnail (NautilusFile *file);
200 gboolean nautilus_file_should_show_directory_item_count (NautilusFile *file);
201 gboolean nautilus_file_should_show_type (NautilusFile *file);
202 GList * nautilus_file_get_keywords (NautilusFile *file);
203 void nautilus_file_set_keywords (NautilusFile *file,
204 GList *keywords);
205 GList * nautilus_file_get_emblem_icons (NautilusFile *file,
206 char **exclude);
207 GList * nautilus_file_get_emblem_pixbufs (NautilusFile *file,
208 int size,
209 gboolean force_size,
210 char **exclude);
211 char * nautilus_file_get_top_left_text (NautilusFile *file);
212 char * nautilus_file_peek_top_left_text (NautilusFile *file,
213 gboolean need_large_text,
214 gboolean *got_top_left_text);
215 gboolean nautilus_file_get_directory_item_mime_types (NautilusFile *file,
216 GList **mime_list);
218 void nautilus_file_set_attributes (NautilusFile *file,
219 GFileInfo *attributes,
220 NautilusFileOperationCallback callback,
221 gpointer callback_data);
223 /* Permissions. */
224 gboolean nautilus_file_can_get_permissions (NautilusFile *file);
225 gboolean nautilus_file_can_set_permissions (NautilusFile *file);
226 guint nautilus_file_get_permissions (NautilusFile *file);
227 gboolean nautilus_file_can_get_owner (NautilusFile *file);
228 gboolean nautilus_file_can_set_owner (NautilusFile *file);
229 gboolean nautilus_file_can_get_group (NautilusFile *file);
230 gboolean nautilus_file_can_set_group (NautilusFile *file);
231 char * nautilus_file_get_owner_name (NautilusFile *file);
232 char * nautilus_file_get_group_name (NautilusFile *file);
233 GList * nautilus_get_user_names (void);
234 GList * nautilus_get_all_group_names (void);
235 GList * nautilus_file_get_settable_group_names (NautilusFile *file);
236 gboolean nautilus_file_can_get_selinux_context (NautilusFile *file);
237 char * nautilus_file_get_selinux_context (NautilusFile *file);
239 /* "Capabilities". */
240 gboolean nautilus_file_can_read (NautilusFile *file);
241 gboolean nautilus_file_can_write (NautilusFile *file);
242 gboolean nautilus_file_can_execute (NautilusFile *file);
243 gboolean nautilus_file_can_rename (NautilusFile *file);
244 gboolean nautilus_file_can_delete (NautilusFile *file);
245 gboolean nautilus_file_can_trash (NautilusFile *file);
247 gboolean nautilus_file_can_mount (NautilusFile *file);
248 gboolean nautilus_file_can_unmount (NautilusFile *file);
249 gboolean nautilus_file_can_eject (NautilusFile *file);
251 void nautilus_file_mount (NautilusFile *file,
252 GMountOperation *mount_op,
253 GCancellable *cancellable,
254 NautilusFileOperationCallback callback,
255 gpointer callback_data);
256 void nautilus_file_unmount (NautilusFile *file,
257 NautilusFileOperationCallback callback,
258 gpointer callback_data);
259 void nautilus_file_eject (NautilusFile *file,
260 NautilusFileOperationCallback callback,
261 gpointer callback_data);
263 /* Basic operations for file objects. */
264 void nautilus_file_set_owner (NautilusFile *file,
265 const char *user_name_or_id,
266 NautilusFileOperationCallback callback,
267 gpointer callback_data);
268 void nautilus_file_set_group (NautilusFile *file,
269 const char *group_name_or_id,
270 NautilusFileOperationCallback callback,
271 gpointer callback_data);
272 void nautilus_file_set_permissions (NautilusFile *file,
273 guint32 permissions,
274 NautilusFileOperationCallback callback,
275 gpointer callback_data);
276 void nautilus_file_rename (NautilusFile *file,
277 const char *new_name,
278 NautilusFileOperationCallback callback,
279 gpointer callback_data);
280 void nautilus_file_cancel (NautilusFile *file,
281 NautilusFileOperationCallback callback,
282 gpointer callback_data);
284 /* Return true if this file has already been deleted.
285 * This object will be unref'd after sending the files_removed signal,
286 * but it could hang around longer if someone ref'd it.
288 gboolean nautilus_file_is_gone (NautilusFile *file);
290 /* Return true if this file is not confirmed to have ever really
291 * existed. This is true when the NautilusFile object has been created, but no I/O
292 * has yet confirmed the existence of a file by that name.
294 gboolean nautilus_file_is_not_yet_confirmed (NautilusFile *file);
296 /* Simple getting and setting top-level metadata. */
297 char * nautilus_file_get_metadata (NautilusFile *file,
298 const char *key,
299 const char *default_metadata);
300 GList * nautilus_file_get_metadata_list (NautilusFile *file,
301 const char *list_key,
302 const char *list_subkey);
303 void nautilus_file_set_metadata (NautilusFile *file,
304 const char *key,
305 const char *default_metadata,
306 const char *metadata);
307 void nautilus_file_set_metadata_list (NautilusFile *file,
308 const char *list_key,
309 const char *list_subkey,
310 GList *list);
312 /* Covers for common data types. */
313 gboolean nautilus_file_get_boolean_metadata (NautilusFile *file,
314 const char *key,
315 gboolean default_metadata);
316 void nautilus_file_set_boolean_metadata (NautilusFile *file,
317 const char *key,
318 gboolean default_metadata,
319 gboolean metadata);
320 int nautilus_file_get_integer_metadata (NautilusFile *file,
321 const char *key,
322 int default_metadata);
323 void nautilus_file_set_integer_metadata (NautilusFile *file,
324 const char *key,
325 int default_metadata,
326 int metadata);
329 /* Attributes for file objects as user-displayable strings. */
330 char * nautilus_file_get_string_attribute (NautilusFile *file,
331 const char *attribute_name);
332 char * nautilus_file_get_string_attribute_with_default (NautilusFile *file,
333 const char *attribute_name);
334 char * nautilus_file_fit_modified_date_as_string (NautilusFile *file,
335 int width,
336 NautilusWidthMeasureCallback measure_callback,
337 NautilusTruncateCallback truncate_callback,
338 void *measure_truncate_context);
340 /* Matching with another URI. */
341 gboolean nautilus_file_matches_uri (NautilusFile *file,
342 const char *uri);
344 /* Is the file local? */
345 gboolean nautilus_file_is_local (NautilusFile *file);
347 /* Comparing two file objects for sorting */
348 int nautilus_file_compare_for_sort (NautilusFile *file_1,
349 NautilusFile *file_2,
350 NautilusFileSortType sort_type,
351 gboolean directories_first,
352 gboolean reversed);
353 int nautilus_file_compare_for_sort_by_attribute (NautilusFile *file_1,
354 NautilusFile *file_2,
355 const char *attribute,
356 gboolean directories_first,
357 gboolean reversed);
358 int nautilus_file_compare_display_name (NautilusFile *file_1,
359 const char *pattern);
361 /* filtering functions for use by various directory views */
362 gboolean nautilus_file_is_hidden_file (NautilusFile *file);
363 gboolean nautilus_file_is_backup_file (NautilusFile *file);
364 gboolean nautilus_file_should_show (NautilusFile *file,
365 gboolean show_hidden,
366 gboolean show_backup);
367 GList *nautilus_file_list_filter_hidden_and_backup (GList *files,
368 gboolean show_hidden,
369 gboolean show_backup);
372 /* Get the URI that's used when activating the file.
373 * Getting this can require reading the contents of the file.
375 char * nautilus_file_get_activation_uri (NautilusFile *file);
377 char * nautilus_file_get_drop_target_uri (NautilusFile *file);
379 /* Get custom icon (if specified by metadata or link contents) */
380 char * nautilus_file_get_custom_icon (NautilusFile *file);
383 GIcon * nautilus_file_get_gicon (NautilusFile *file,
384 NautilusFileIconFlags flags);
385 NautilusIconInfo * nautilus_file_get_icon (NautilusFile *file,
386 int size,
387 NautilusFileIconFlags flags);
388 GdkPixbuf * nautilus_file_get_icon_pixbuf (NautilusFile *file,
389 int size,
390 gboolean force_size,
391 NautilusFileIconFlags flags);
393 gboolean nautilus_file_has_open_window (NautilusFile *file);
394 void nautilus_file_set_has_open_window (NautilusFile *file,
395 gboolean has_open_window);
397 /* Thumbnailing handling */
398 gboolean nautilus_file_is_thumbnailing (NautilusFile *file);
400 /* Convenience functions for dealing with a list of NautilusFile objects that each have a ref.
401 * These are just convenient names for functions that work on lists of GtkObject *.
403 GList * nautilus_file_list_ref (GList *file_list);
404 void nautilus_file_list_unref (GList *file_list);
405 void nautilus_file_list_free (GList *file_list);
406 GList * nautilus_file_list_copy (GList *file_list);
407 GList * nautilus_file_list_sort_by_display_name (GList *file_list);
408 void nautilus_file_list_call_when_ready (GList *file_list,
409 NautilusFileAttributes attributes,
410 NautilusFileListHandle **handle,
411 NautilusFileListCallback callback,
412 gpointer callback_data);
413 void nautilus_file_list_cancel_call_when_ready (NautilusFileListHandle *handle);
415 /* Debugging */
416 void nautilus_file_dump (NautilusFile *file);
418 typedef struct NautilusFileDetails NautilusFileDetails;
420 struct NautilusFile {
421 GObject parent_slot;
422 NautilusFileDetails *details;
425 /* This is actually a "protected" type, but it must be here so we can
426 * compile the get_date function pointer declaration below.
428 typedef enum {
429 NAUTILUS_DATE_TYPE_MODIFIED,
430 NAUTILUS_DATE_TYPE_CHANGED,
431 NAUTILUS_DATE_TYPE_ACCESSED,
432 NAUTILUS_DATE_TYPE_PERMISSIONS_CHANGED
433 } NautilusDateType;
435 typedef struct {
436 GObjectClass parent_slot;
438 /* Subclasses can set this to something other than G_FILE_TYPE_UNKNOWN and
439 it will be used as the default file type. This is useful when creating
440 a "virtual" NautilusFile subclass that you can't actually get real
441 information about. For exaple NautilusDesktopDirectoryFile. */
442 GFileType default_file_type;
444 /* Called when the file notices any change. */
445 void (* changed) (NautilusFile *file);
447 /* Called periodically while directory deep count is being computed. */
448 void (* updated_deep_count_in_progress) (NautilusFile *file);
450 /* Virtual functions (mainly used for trash directory). */
451 void (* monitor_add) (NautilusFile *file,
452 gconstpointer client,
453 NautilusFileAttributes attributes);
454 void (* monitor_remove) (NautilusFile *file,
455 gconstpointer client);
456 void (* call_when_ready) (NautilusFile *file,
457 NautilusFileAttributes attributes,
458 NautilusFileCallback callback,
459 gpointer callback_data);
460 void (* cancel_call_when_ready) (NautilusFile *file,
461 NautilusFileCallback callback,
462 gpointer callback_data);
463 gboolean (* check_if_ready) (NautilusFile *file,
464 NautilusFileAttributes attributes);
465 gboolean (* get_item_count) (NautilusFile *file,
466 guint *count,
467 gboolean *count_unreadable);
468 NautilusRequestStatus (* get_deep_counts) (NautilusFile *file,
469 guint *directory_count,
470 guint *file_count,
471 guint *unreadable_directory_count,
472 goffset *total_size);
473 gboolean (* get_date) (NautilusFile *file,
474 NautilusDateType type,
475 time_t *date);
476 char * (* get_where_string) (NautilusFile *file);
478 void (* mount) (NautilusFile *file,
479 GMountOperation *mount_op,
480 GCancellable *cancellable,
481 NautilusFileOperationCallback callback,
482 gpointer callback_data);
483 void (* unmount) (NautilusFile *file,
484 NautilusFileOperationCallback callback,
485 gpointer callback_data);
486 void (* eject) (NautilusFile *file,
487 NautilusFileOperationCallback callback,
488 gpointer callback_data);
489 } NautilusFileClass;
491 #endif /* NAUTILUS_FILE_H */