1 /* -*- Mode: C; indent-tabs-mode: t; c-basic-offset: 8; tab-width: 8 -*-
2 
3    caja-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 St, Fifth Floor,
20    Boston, MA 02110-1301, USA.
21 
22    Author: Darin Adler <darin@bentspoon.com>
23 */
24 
25 #ifndef CAJA_FILE_PRIVATE_H
26 #define CAJA_FILE_PRIVATE_H
27 
28 #include <eel/eel-glib-extensions.h>
29 #include <eel/eel-string.h>
30 
31 #include "caja-directory.h"
32 #include "caja-file.h"
33 #include "caja-monitor.h"
34 #include "caja-undostack-manager.h"
35 
36 #define CAJA_FILE_LARGE_TOP_LEFT_TEXT_MAXIMUM_CHARACTERS_PER_LINE 80
37 #define CAJA_FILE_LARGE_TOP_LEFT_TEXT_MAXIMUM_LINES               24
38 #define CAJA_FILE_LARGE_TOP_LEFT_TEXT_MAXIMUM_BYTES               10000
39 
40 #define CAJA_FILE_TOP_LEFT_TEXT_MAXIMUM_CHARACTERS_PER_LINE 10
41 #define CAJA_FILE_TOP_LEFT_TEXT_MAXIMUM_LINES               5
42 #define CAJA_FILE_TOP_LEFT_TEXT_MAXIMUM_BYTES               1024
43 
44 #define CAJA_FILE_DEFAULT_ATTRIBUTES				\
45 	"standard::*,access::*,mountable::*,time::*,unix::*,owner::*,selinux::*,thumbnail::*,id::filesystem,trash::orig-path,trash::deletion-date,metadata::*"
46 
47 /* These are in the typical sort order. Known things come first, then
48  * things where we can't know, finally things where we don't yet know.
49  */
50 typedef enum
51 {
52     KNOWN,
53     UNKNOWABLE,
54     UNKNOWN
55 } Knowledge;
56 
57 typedef struct
58 {
59     char emblem_keywords[1];
60 } CajaFileSortByEmblemCache;
61 
62 struct _CajaFilePrivate
63 {
64     CajaDirectory *directory;
65 
66     GRefString *name;
67 
68     /* File info: */
69     GFileType type;
70 
71     GRefString *display_name;
72     char *display_name_collation_key;
73     GRefString *edit_name;
74 
75     goffset size; /* -1 is unknown */
76     goffset size_on_disk; /* -1 is unknown */
77 
78     int sort_order;
79 
80     guint32 permissions;
81     int uid; /* -1 is none */
82     int gid; /* -1 is none */
83 
84     GRefString *owner;
85     GRefString *owner_real;
86     GRefString *group;
87 
88     time_t atime; /* 0 is unknown */
89     time_t mtime; /* 0 is unknown */
90     time_t ctime; /* 0 is unknown */
91     time_t btime; /* 0 is unknown */
92 
93     char *symlink_name;
94 
95     GRefString *mime_type;
96 
97     char *selinux_context;
98     char *description;
99 
100     GError *get_info_error;
101 
102     guint directory_count;
103 
104     guint deep_directory_count;
105     guint deep_file_count;
106     guint deep_unreadable_count;
107     goffset deep_size;
108     goffset deep_size_on_disk;
109 
110     GIcon *icon;
111 
112     char *thumbnail_path;
113     GdkPixbuf *thumbnail;
114     time_t thumbnail_mtime;
115 
116     GList *mime_list; /* If this is a directory, the list of MIME types in it. */
117     char *top_left_text;
118 
119     /* Info you might get from a link (.desktop, .directory or caja link) */
120     char *custom_icon;
121     char *activation_uri;
122 
123     /* used during DND, for checking whether source and destination are on
124      * the same file system.
125      */
126     GRefString *filesystem_id;
127 
128     char *trash_orig_path;
129 
130     /* The following is for file operations in progress. Since
131      * there are normally only a few of these, we can move them to
132      * a separate hash table or something if required to keep the
133      * file objects small.
134      */
135     GList *operations_in_progress;
136 
137     /* We use this to cache automatic emblems and emblem keywords
138        to speed up compare_by_emblems. */
139     CajaFileSortByEmblemCache *compare_by_emblem_cache;
140 
141     /* CajaInfoProviders that need to be run for this file */
142     GList *pending_info_providers;
143 
144     /* Emblems provided by extensions */
145     GList *extension_emblems;
146     GList *pending_extension_emblems;
147 
148     /* Attributes provided by extensions */
149     GHashTable *extension_attributes;
150     GHashTable *pending_extension_attributes;
151 
152     GHashTable *metadata;
153 
154     /* Mount for mountpoint or the references GMount for a "mountable" */
155     GMount *mount;
156 
157     /* boolean fields: bitfield to save space, since there can be
158            many CajaFile objects. */
159 
160     eel_boolean_bit unconfirmed                   : 1;
161     eel_boolean_bit is_gone                       : 1;
162     /* Set when emitting files_added on the directory to make sure we
163        add a file, and only once */
164     eel_boolean_bit is_added                      : 1;
165     /* Set by the CajaDirectory while it's loading the file
166      * list so the file knows not to do redundant I/O.
167      */
168     eel_boolean_bit loading_directory             : 1;
169     eel_boolean_bit got_file_info                 : 1;
170     eel_boolean_bit get_info_failed               : 1;
171     eel_boolean_bit file_info_is_up_to_date       : 1;
172 
173     eel_boolean_bit got_directory_count           : 1;
174     eel_boolean_bit directory_count_failed        : 1;
175     eel_boolean_bit directory_count_is_up_to_date : 1;
176 
177     eel_boolean_bit deep_counts_status      : 2; /* CajaRequestStatus */
178     /* no deep_counts_are_up_to_date field; since we expose
179            intermediate values for this attribute, we do actually
180            forget it rather than invalidating. */
181 
182     eel_boolean_bit got_mime_list                 : 1;
183     eel_boolean_bit mime_list_failed              : 1;
184     eel_boolean_bit mime_list_is_up_to_date       : 1;
185 
186     eel_boolean_bit mount_is_up_to_date           : 1;
187 
188     eel_boolean_bit got_top_left_text             : 1;
189     eel_boolean_bit got_large_top_left_text       : 1;
190     eel_boolean_bit top_left_text_is_up_to_date   : 1;
191 
192     eel_boolean_bit got_link_info                 : 1;
193     eel_boolean_bit link_info_is_up_to_date       : 1;
194     eel_boolean_bit got_custom_display_name       : 1;
195     eel_boolean_bit got_custom_activation_uri     : 1;
196 
197     eel_boolean_bit thumbnail_is_up_to_date       : 1;
198     eel_boolean_bit thumbnail_wants_original      : 1;
199     eel_boolean_bit thumbnail_tried_original      : 1;
200     eel_boolean_bit thumbnailing_failed           : 1;
201 
202     eel_boolean_bit is_thumbnailing               : 1;
203 
204     /* TRUE if the file is open in a spatial window */
205     eel_boolean_bit has_open_window               : 1;
206 
207     eel_boolean_bit is_launcher                   : 1;
208     eel_boolean_bit is_trusted_link               : 1;
209     eel_boolean_bit is_foreign_link               : 1;
210     eel_boolean_bit is_symlink                    : 1;
211     eel_boolean_bit is_mountpoint                 : 1;
212     eel_boolean_bit is_hidden                     : 1;
213     eel_boolean_bit is_backup                     : 1;
214     eel_boolean_bit has_permissions               : 1;
215 
216     eel_boolean_bit can_read                      : 1;
217     eel_boolean_bit can_write                     : 1;
218     eel_boolean_bit can_execute                   : 1;
219     eel_boolean_bit can_delete                    : 1;
220     eel_boolean_bit can_trash                     : 1;
221     eel_boolean_bit can_rename                    : 1;
222     eel_boolean_bit can_mount                     : 1;
223     eel_boolean_bit can_unmount                   : 1;
224     eel_boolean_bit can_eject                     : 1;
225     eel_boolean_bit can_start                     : 1;
226     eel_boolean_bit can_start_degraded            : 1;
227     eel_boolean_bit can_stop                      : 1;
228     eel_boolean_bit start_stop_type               : 3; /* GDriveStartStopType */
229     eel_boolean_bit can_poll_for_media            : 1;
230     eel_boolean_bit is_media_check_automatic      : 1;
231 
232     eel_boolean_bit filesystem_readonly           : 1;
233     eel_boolean_bit filesystem_use_preview        : 2; /* GFilesystemPreviewType */
234     eel_boolean_bit filesystem_info_is_up_to_date : 1;
235 
236     time_t trash_time; /* 0 is unknown */
237 };
238 
239 typedef struct
240 {
241     CajaFile *file;
242     GCancellable *cancellable;
243     CajaFileOperationCallback callback;
244     gpointer callback_data;
245     gboolean is_rename;
246 
247     gpointer data;
248     GDestroyNotify free_data;
249     CajaUndoStackActionData* undo_redo_data;
250 } CajaFileOperation;
251 
252 
253 CajaFile *caja_file_new_from_info                  (CajaDirectory      *directory,
254         GFileInfo              *info);
255 void          caja_file_emit_changed                   (CajaFile           *file);
256 void          caja_file_mark_gone                      (CajaFile           *file);
257 char *        caja_extract_top_left_text               (const char             *text,
258         gboolean                large,
259         int                     length);
260 void          caja_file_set_directory                  (CajaFile           *file,
261         CajaDirectory      *directory);
262 gboolean      caja_file_get_date                       (CajaFile           *file,
263         CajaDateType        date_type,
264         time_t                 *date);
265 void          caja_file_updated_deep_count_in_progress (CajaFile           *file);
266 
267 
268 void          caja_file_clear_info                     (CajaFile           *file);
269 /* Compare file's state with a fresh file info struct, return FALSE if
270  * no change, update file and return TRUE if the file info contains
271  * new state.  */
272 gboolean      caja_file_update_info                    (CajaFile           *file,
273         GFileInfo              *info);
274 gboolean      caja_file_update_name                    (CajaFile           *file,
275         const char             *name);
276 gboolean      caja_file_update_metadata_from_info      (CajaFile           *file,
277         GFileInfo              *info);
278 
279 gboolean      caja_file_update_name_and_directory      (CajaFile           *file,
280         const char             *name,
281         CajaDirectory      *directory);
282 
283 gboolean      caja_file_set_display_name               (CajaFile           *file,
284         const char             *display_name,
285         const char             *edit_name,
286         gboolean                custom);
287 void          caja_file_set_mount                      (CajaFile           *file,
288         GMount                 *mount);
289 
290 /* Return true if the top lefts of files in this directory should be
291  * fetched, according to the preference settings.
292  */
293 gboolean      caja_file_should_get_top_left_text       (CajaFile           *file);
294 
295 /* Mark specified attributes for this file out of date without canceling current
296  * I/O or kicking off new I/O.
297  */
298 void                   caja_file_invalidate_attributes_internal     (CajaFile           *file,
299         CajaFileAttributes  file_attributes);
300 CajaFileAttributes caja_file_get_all_attributes                 (void);
301 gboolean               caja_file_is_self_owned                      (CajaFile           *file);
302 void                   caja_file_invalidate_count_and_mime_list     (CajaFile           *file);
303 gboolean               caja_file_rename_in_progress                 (CajaFile           *file);
304 void                   caja_file_invalidate_extension_info_internal (CajaFile           *file);
305 void                   caja_file_info_providers_done                (CajaFile           *file);
306 
307 
308 /* Thumbnailing: */
309 void          caja_file_set_is_thumbnailing            (CajaFile           *file,
310         gboolean                is_thumbnailing);
311 
312 CajaFileOperation *caja_file_operation_new      (CajaFile                  *file,
313         CajaFileOperationCallback  callback,
314         gpointer                       callback_data);
315 void                   caja_file_operation_free     (CajaFileOperation         *op);
316 void                   caja_file_operation_complete (CajaFileOperation         *op,
317         GFile                         *result_location,
318         GError                        *error);
319 void                   caja_file_operation_cancel   (CajaFileOperation         *op);
320 
321 #endif
322