1 /* -*- Mode: C; indent-tabs-mode: t; c-basic-offset: 8; tab-width: 8 -*-
2 
3    nemo-file-private.h:
4 
5    Copyright (C) 1999, 2000, 2001 Eazel, Inc.
6 
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.
11 
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.
16 
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., 51 Franklin Street - Suite 500,
20    Boston, MA 02110-1335, USA.
21 
22    Author: Darin Adler <darin@bentspoon.com>
23 */
24 
25 #ifndef NEMO_FILE_PRIVATE_H
26 #define NEMO_FILE_PRIVATE_H
27 
28 #include <libnemo-private/nemo-directory.h>
29 #include <libnemo-private/nemo-file.h>
30 #include <libnemo-private/nemo-monitor.h>
31 #include <libnemo-private/nemo-file-undo-operations.h>
32 #include <eel/eel-glib-extensions.h>
33 #include <eel/eel-string.h>
34 
35 #define NEMO_FILE_DEFAULT_ATTRIBUTES				\
36 	"standard::*,access::*,mountable::*,time::*,unix::*,owner::*,selinux::*,thumbnail::*,id::filesystem,trash::orig-path,trash::deletion-date,metadata::*"
37 
38 /* These are in the typical sort order. Known things come first, then
39  * things where we can't know, finally things where we don't yet know.
40  */
41 typedef enum {
42 	KNOWN,
43 	UNKNOWABLE,
44 	UNKNOWN
45 } Knowledge;
46 
47 typedef enum {
48     FILE_META_STATE_INIT = -1,
49     FILE_META_STATE_FALSE = 0,
50     FILE_META_STATE_TRUE = 1,
51 } NemoFileMetaState;
52 
53 struct NemoFileDetails
54 {
55 	NemoDirectory *directory;
56 
57 	eel_ref_str name;
58 
59 	/* File info: */
60 	GFileType type;
61 
62 	eel_ref_str display_name;
63 	char *display_name_collation_key;
64 	eel_ref_str edit_name;
65 
66 	goffset size; /* -1 is unknown */
67 
68 	int sort_order;
69 
70 	guint32 permissions;
71 	int uid; /* -1 is none */
72 	int gid; /* -1 is none */
73 
74 	eel_ref_str owner;
75 	eel_ref_str owner_real;
76 	eel_ref_str group;
77 
78 	time_t atime; /* 0 is unknown */
79 	time_t mtime; /* 0 is unknown */
80 	time_t ctime; /* 0 is unknown */
81     time_t btime; /* 0 is unknown */
82 
83 	char *symlink_name;
84 
85 	eel_ref_str mime_type;
86 
87 	char *selinux_context;
88 	char *description;
89 
90 	GError *get_info_error;
91 
92 	guint directory_count;
93 
94 	guint deep_directory_count;
95 	guint deep_file_count;
96 	guint deep_unreadable_count;
97     guint deep_hidden_count;
98 	goffset deep_size;
99 
100 	GIcon *icon;
101 
102 	char *thumbnail_path;
103     eel_boolean_bit thumbnail_access_problem : 1;
104 	GdkPixbuf *thumbnail;
105 	time_t thumbnail_mtime;
106     gint thumbnail_throttle_count;
107     time_t last_thumbnail_try_mtime;
108 
109 	GList *mime_list; /* If this is a directory, the list of MIME types in it. */
110 
111 	/* Info you might get from a link (.desktop, .directory or nemo link) */
112 	GIcon *custom_icon;
113 	char *activation_uri;
114 
115 	/* used during DND, for checking whether source and destination are on
116 	 * the same file system.
117 	 */
118 	eel_ref_str filesystem_id;
119 
120 	char *trash_orig_path;
121 
122 	/* The following is for file operations in progress. Since
123 	 * there are normally only a few of these, we can move them to
124 	 * a separate hash table or something if required to keep the
125 	 * file objects small.
126 	 */
127 	GList *operations_in_progress;
128 
129 	/* NemoInfoProviders that need to be run for this file */
130 	GList *pending_info_providers;
131 
132 	/* Emblems provided by extensions */
133 	GList *extension_emblems;
134 	GList *pending_extension_emblems;
135 
136 	/* Attributes provided by extensions */
137 	GHashTable *extension_attributes;
138 	GHashTable *pending_extension_attributes;
139 
140 	GHashTable *metadata;
141 
142 	/* Mount for mountpoint or the references GMount for a "mountable" */
143 	GMount *mount;
144 
145 	/* boolean fields: bitfield to save space, since there can be
146            many NemoFile objects. */
147 
148 	eel_boolean_bit unconfirmed                   : 1;
149 	eel_boolean_bit is_gone                       : 1;
150 	/* Set when emitting files_added on the directory to make sure we
151 	   add a file, and only once */
152 	eel_boolean_bit is_added                      : 1;
153 	/* Set by the NemoDirectory while it's loading the file
154 	 * list so the file knows not to do redundant I/O.
155 	 */
156 	eel_boolean_bit loading_directory             : 1;
157 	eel_boolean_bit got_file_info                 : 1;
158 	eel_boolean_bit get_info_failed               : 1;
159 	eel_boolean_bit file_info_is_up_to_date       : 1;
160 
161     eel_boolean_bit got_btime                     : 1;
162     eel_boolean_bit get_btime_failed              : 1;
163     eel_boolean_bit btime_is_up_to_date           : 1;
164 
165 	eel_boolean_bit got_directory_count           : 1;
166 	eel_boolean_bit directory_count_failed        : 1;
167 	eel_boolean_bit directory_count_is_up_to_date : 1;
168 
169 	eel_boolean_bit deep_counts_status      : 2; /* NemoRequestStatus */
170 	/* no deep_counts_are_up_to_date field; since we expose
171            intermediate values for this attribute, we do actually
172            forget it rather than invalidating. */
173 
174 	eel_boolean_bit got_mime_list                 : 1;
175 	eel_boolean_bit mime_list_failed              : 1;
176 	eel_boolean_bit mime_list_is_up_to_date       : 1;
177 
178 	eel_boolean_bit mount_is_up_to_date           : 1;
179 
180 	eel_boolean_bit got_link_info                 : 1;
181 	eel_boolean_bit link_info_is_up_to_date       : 1;
182 	eel_boolean_bit got_custom_display_name       : 1;
183 	eel_boolean_bit got_custom_activation_uri     : 1;
184 
185 	eel_boolean_bit thumbnail_is_up_to_date       : 1;
186 	eel_boolean_bit thumbnail_wants_original      : 1;
187 	eel_boolean_bit thumbnail_tried_original      : 1;
188 	eel_boolean_bit thumbnailing_failed           : 1;
189 
190 	eel_boolean_bit is_thumbnailing               : 1;
191 
192     eel_boolean_bit is_desktop_orphan             : 1;
193 
194 	/* TRUE if the file is open in a spatial window */
195 	eel_boolean_bit has_open_window               : 1;
196 
197 	eel_boolean_bit is_launcher                   : 1;
198 	eel_boolean_bit is_trusted_link               : 1;
199 	eel_boolean_bit is_foreign_link               : 1;
200 	eel_boolean_bit is_symlink                    : 1;
201 	eel_boolean_bit is_mountpoint                 : 1;
202 	eel_boolean_bit is_hidden                     : 1;
203 
204     eel_boolean_bit favorite_checked              : 1;
205 
206 	eel_boolean_bit has_permissions               : 1;
207 
208 	eel_boolean_bit can_read                      : 1;
209 	eel_boolean_bit can_write                     : 1;
210 	eel_boolean_bit can_execute                   : 1;
211 	eel_boolean_bit can_delete                    : 1;
212 	eel_boolean_bit can_trash                     : 1;
213 	eel_boolean_bit can_rename                    : 1;
214 	eel_boolean_bit can_mount                     : 1;
215 	eel_boolean_bit can_unmount                   : 1;
216 	eel_boolean_bit can_eject                     : 1;
217 	eel_boolean_bit can_start                     : 1;
218 	eel_boolean_bit can_start_degraded            : 1;
219 	eel_boolean_bit can_stop                      : 1;
220 	eel_boolean_bit start_stop_type               : 3; /* GDriveStartStopType */
221 	eel_boolean_bit can_poll_for_media            : 1;
222 	eel_boolean_bit is_media_check_automatic      : 1;
223 
224 	eel_boolean_bit filesystem_readonly           : 1;
225 	eel_boolean_bit filesystem_use_preview        : 2; /* GFilesystemPreviewType */
226     eel_boolean_bit filesystem_info_is_up_to_date : 1;
227 
228     NemoFileLoadDeferredAttrs load_deferred_attrs;
229     NemoFileMetaState pinning;
230     NemoFileMetaState favorite;
231 
232 	time_t trash_time; /* 0 is unknown */
233 
234 	guint64 free_space; /* (guint)-1 for unknown */
235 	time_t free_space_read; /* The time free_space was updated, or 0 for never */
236 
237     gint desktop_monitor;
238     gint cached_position_x;
239     gint cached_position_y;
240 };
241 
242 typedef struct {
243 	NemoFile *file;
244 	GCancellable *cancellable;
245 	NemoFileOperationCallback callback;
246 	gpointer callback_data;
247 	gboolean is_rename;
248 
249 	gpointer data;
250 	GDestroyNotify free_data;
251 	NemoFileUndoInfo *undo_info;
252 } NemoFileOperation;
253 
254 NemoFile *nemo_file_new_from_info                  (NemoDirectory      *directory,
255 							    GFileInfo              *info);
256 void          nemo_file_emit_changed                   (NemoFile           *file);
257 void          nemo_file_mark_gone                      (NemoFile           *file);
258 
259 void          nemo_file_set_directory                  (NemoFile           *file,
260 							    NemoDirectory      *directory);
261 gboolean      nemo_file_get_date                       (NemoFile           *file,
262 							    NemoDateType        date_type,
263 							    time_t                 *date);
264 void          nemo_file_updated_deep_count_in_progress (NemoFile           *file);
265 
266 
267 void          nemo_file_clear_info                     (NemoFile           *file);
268 /* Compare file's state with a fresh file info struct, return FALSE if
269  * no change, update file and return TRUE if the file info contains
270  * new state.  */
271 gboolean      nemo_file_update_info                    (NemoFile           *file,
272 							    GFileInfo              *info);
273 gboolean      nemo_file_update_name                    (NemoFile           *file,
274 							    const char             *name);
275 gboolean      nemo_file_update_metadata_from_info      (NemoFile           *file,
276 							    GFileInfo              *info);
277 
278 gboolean      nemo_file_update_name_and_directory      (NemoFile           *file,
279 							    const char             *name,
280 							    NemoDirectory      *directory);
281 
282 gboolean      nemo_file_set_display_name               (NemoFile           *file,
283 							    const char             *display_name,
284 							    const char             *edit_name,
285 							    gboolean                custom);
286 
287 /* Mark specified attributes for this file out of date without canceling current
288  * I/O or kicking off new I/O.
289  */
290 void                   nemo_file_invalidate_attributes_internal     (NemoFile           *file,
291 									 NemoFileAttributes  file_attributes);
292 NemoFileAttributes nemo_file_get_all_attributes                 (void);
293 gboolean               nemo_file_is_self_owned                      (NemoFile           *file);
294 void                   nemo_file_invalidate_count_and_mime_list     (NemoFile           *file);
295 gboolean               nemo_file_rename_in_progress                 (NemoFile           *file);
296 void                   nemo_file_invalidate_extension_info_internal (NemoFile           *file);
297 void                   nemo_file_info_providers_done                (NemoFile           *file);
298 
299 
300 /* Thumbnailing: */
301 void          nemo_file_set_is_thumbnailing            (NemoFile           *file,
302 							    gboolean                is_thumbnailing);
303 
304 NemoFileOperation *nemo_file_operation_new      (NemoFile                  *file,
305 							 NemoFileOperationCallback  callback,
306 							 gpointer                       callback_data);
307 void                   nemo_file_operation_free     (NemoFileOperation         *op);
308 void                   nemo_file_operation_complete (NemoFileOperation         *op,
309 							 GFile                         *result_location,
310 							 GError                        *error);
311 void                   nemo_file_operation_cancel   (NemoFileOperation         *op);
312 #endif
313