Move third-party sources to separate sub-directory
[geeqie.git] / src / filedata.h
1 /*
2  * Copyright (C) 2004 John Ellis
3  * Copyright (C) 2008 - 2016 The Geeqie Team
4  *
5  * Author: John Ellis
6  *
7  * This program is free software; you can redistribute it and/or modify
8  * it under the terms of the GNU General Public License as published by
9  * the Free Software Foundation; either version 2 of the License, or
10  * (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
15  * GNU General Public License for more details.
16  *
17  * You should have received a copy of the GNU General Public License along
18  * with this program; if not, write to the Free Software Foundation, Inc.,
19  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
20  */
21
22 #ifndef FILEDATA_H
23 #define FILEDATA_H
24
25 #include <sys/types.h>
26
27 #include <gdk-pixbuf/gdk-pixbuf.h>
28 #include <glib.h>
29
30 #include <config.h>
31
32 #include "typedefs.h"
33
34 struct ExifData;
35 struct HistMap;
36
37 #ifdef DEBUG
38 #define DEBUG_FILEDATA
39 #endif
40
41 #define FD_MAGICK 0x12345678u
42
43 gchar *text_from_size(gint64 size);
44 gchar *text_from_size_abrev(gint64 size);
45 const gchar *text_from_time(time_t t);
46
47 enum FileDataChangeType {
48         FILEDATA_CHANGE_DELETE,
49         FILEDATA_CHANGE_MOVE,
50         FILEDATA_CHANGE_RENAME,
51         FILEDATA_CHANGE_COPY,
52         FILEDATA_CHANGE_UNSPECIFIED,
53         FILEDATA_CHANGE_WRITE_METADATA
54 };
55
56 enum NotifyPriority {
57         NOTIFY_PRIORITY_HIGH = 0,
58         NOTIFY_PRIORITY_MEDIUM,
59         NOTIFY_PRIORITY_LOW
60 };
61
62 enum SelectionType {
63         SELECTION_NONE          = 0,
64         SELECTION_SELECTED      = 1 << 0,
65         SELECTION_PRELIGHT      = 1 << 1,
66         SELECTION_FOCUS         = 1 << 2
67 };
68
69 struct FileDataChangeInfo {
70         FileDataChangeType type;
71         gchar *source;
72         gchar *dest;
73         gint error;
74         gboolean regroup_when_finished;
75 };
76
77 struct FileData {
78         guint magick;
79         gint type;
80         gchar *original_path; /**< key to file_data_pool hash table */
81         gchar *path;
82         const gchar *name;
83         const gchar *extension;
84         gchar *extended_extension;
85         FileFormatClass format_class;
86         gchar *format_name; /**< set by the image loader */
87         gchar *collate_key_name;
88         gchar *collate_key_name_nocase;
89         gchar *collate_key_name_natural;
90         gchar *collate_key_name_nocase_natural;
91         gint64 size;
92         time_t date;
93         time_t cdate;
94         mode_t mode; /**< this is needed at least for notification in view_dir because it is preserved after the file/directory is deleted */
95         gint sidecar_priority;
96
97         guint marks; /**< each bit represents one mark */
98         guint valid_marks; /**< zero bit means that the corresponding mark needs to be reread */
99
100
101         GList *sidecar_files;
102         FileData *parent; /**< parent file if this is a sidecar file, NULL otherwise */
103         FileDataChangeInfo *change; /**< for rename, move ... */
104         GdkPixbuf *thumb_pixbuf;
105
106         GdkPixbuf *pixbuf; /**< full-size image, only complete images, NULL during loading
107                               all FileData with non-NULL pixbuf are referenced by image_cache */
108
109         HistMap *histmap;
110
111         gboolean locked;
112         gint ref;
113         gint version; /**< increased when any field in this structure is changed */
114         gboolean disable_grouping;
115
116         gint user_orientation;
117         gint exif_orientation;
118
119         ExifData *exif;
120         time_t exifdate;
121         time_t exifdate_digitized;
122         GHashTable *modified_xmp; /**< hash table which contains unwritten xmp metadata in format: key->list of string values */
123         GList *cached_metadata;
124         gint rating;
125         gboolean metadata_in_idle_loaded;
126
127         gchar *owner;
128         gchar *group;
129         gchar *sym_link;
130
131         SelectionType selected;  /**< Used by view-file-icon. */
132
133         gint page_num;
134         gint page_total;
135 };
136
137 /**
138  * @headerfile file_data_new_group
139  * scan for sidecar files - expensive
140  */
141 FileData *file_data_new_group(const gchar *path_utf8);
142
143 /**
144  * @headerfile file_data_new_no_grouping
145  * should be used on helper files which can't have sidecars
146  */
147 FileData *file_data_new_no_grouping(const gchar *path_utf8);
148
149 /**
150  * @headerfile file_data_new_dir
151  * should be used on dirs
152  */
153 FileData *file_data_new_dir(const gchar *path_utf8);
154
155 FileData *file_data_new_simple(const gchar *path_utf8);
156
157 #ifdef DEBUG_FILEDATA
158 FileData *file_data_ref_debug(const gchar *file, gint line, FileData *fd);
159 void file_data_unref_debug(const gchar *file, gint line, FileData *fd);
160 #define file_data_ref(fd) file_data_ref_debug(__FILE__, __LINE__, fd)
161 #define file_data_unref(fd) file_data_unref_debug(__FILE__, __LINE__, fd)
162 #else
163 FileData *file_data_ref(FileData *fd);
164 void file_data_unref(FileData *fd);
165 #endif
166
167 void file_data_lock(FileData *fd);
168 void file_data_unlock(FileData *fd);
169 void file_data_lock_list(GList *list);
170 void file_data_unlock_list(GList *list);
171
172 gboolean file_data_check_changed_files(FileData *fd);
173
174 void file_data_increment_version(FileData *fd);
175
176 gboolean file_data_add_change_info(FileData *fd, FileDataChangeType type, const gchar *src, const gchar *dest);
177 void file_data_change_info_free(FileDataChangeInfo *fdci, FileData *fd);
178
179 void file_data_disable_grouping(FileData *fd, gboolean disable);
180 void file_data_disable_grouping_list(GList *fd_list, gboolean disable);
181
182 gint filelist_sort_compare_filedata(FileData *fa, FileData *fb);
183 gint filelist_sort_compare_filedata_full(FileData *fa, FileData *fb, SortType method, gboolean ascend);
184 GList *filelist_sort(GList *list, SortType method, gboolean ascend, gboolean case_sensitive);
185 GList *filelist_sort_full(GList *list, SortType method, gboolean ascend, gboolean case_sensitive, GCompareFunc cb);
186 GList *filelist_insert_sort_full(GList *list, gpointer data, SortType method, gboolean ascend, gboolean case_sensitive, GCompareFunc cb);
187
188 gboolean filelist_read(FileData *dir_fd, GList **files, GList **dirs);
189 gboolean filelist_read_lstat(FileData *dir_fd, GList **files, GList **dirs);
190 void filelist_free(GList *list);
191 GList *filelist_copy(GList *list);
192 GList *filelist_from_path_list(GList *list);
193 GList *filelist_to_path_list(GList *list);
194
195 GList *filelist_filter(GList *list, gboolean is_dir_list);
196
197 GList *filelist_sort_path(GList *list);
198 GList *filelist_recursive(FileData *dir_fd);
199 GList *filelist_recursive_full(FileData *dir_fd, SortType method, gboolean ascend, gboolean case_sensitive);
200
201 using FileDataGetMarkFunc = gboolean (*)(FileData *, gint, gpointer);
202 using FileDataSetMarkFunc = gboolean (*)(FileData *, gint, gboolean, gpointer);
203 gboolean file_data_register_mark_func(gint n, FileDataGetMarkFunc get_mark_func, FileDataSetMarkFunc set_mark_func, gpointer data, GDestroyNotify notify);
204 void file_data_get_registered_mark_func(gint n, FileDataGetMarkFunc *get_mark_func, FileDataSetMarkFunc *set_mark_func, gpointer *data);
205
206
207 gboolean file_data_get_mark(FileData *fd, gint n);
208 guint file_data_get_marks(FileData *fd);
209 void file_data_set_mark(FileData *fd, gint n, gboolean value);
210 gboolean file_data_filter_marks(FileData *fd, guint filter);
211 GList *file_data_filter_marks_list(GList *list, guint filter);
212
213 gboolean file_data_filter_file_filter(FileData *fd, GRegex *filter);
214 GList *file_data_filter_file_filter_list(GList *list, GRegex *filter);
215
216 GList *file_data_filter_class_list(GList *list, guint filter);
217
218 gchar *file_data_sc_list_to_string(FileData *fd);
219
220 gchar *file_data_get_sidecar_path(FileData *fd, gboolean existing_only);
221
222
223 gboolean file_data_add_ci(FileData *fd, FileDataChangeType type, const gchar *src, const gchar *dest);
224 gboolean file_data_sc_add_ci_copy(FileData *fd, const gchar *dest_path);
225 gboolean file_data_sc_add_ci_move(FileData *fd, const gchar *dest_path);
226 gboolean file_data_sc_add_ci_rename(FileData *fd, const gchar *dest_path);
227 gboolean file_data_sc_add_ci_delete(FileData *fd);
228 gboolean file_data_sc_add_ci_unspecified(FileData *fd, const gchar *dest_path);
229
230 gboolean file_data_sc_add_ci_delete_list(GList *fd_list);
231 gboolean file_data_sc_add_ci_copy_list(GList *fd_list, const gchar *dest);
232 gboolean file_data_sc_add_ci_move_list(GList *fd_list, const gchar *dest);
233 gboolean file_data_sc_add_ci_rename_list(GList *fd_list, const gchar *dest);
234 gboolean file_data_sc_add_ci_unspecified_list(GList *fd_list, const gchar *dest);
235 gboolean file_data_add_ci_write_metadata_list(GList *fd_list);
236
237 gboolean file_data_sc_update_ci_copy_list(GList *fd_list, const gchar *dest);
238 gboolean file_data_sc_update_ci_move_list(GList *fd_list, const gchar *dest);
239 gboolean file_data_sc_update_ci_unspecified_list(GList *fd_list, const gchar *dest);
240
241
242 gboolean file_data_sc_update_ci_copy(FileData *fd, const gchar *dest_path);
243 gboolean file_data_sc_update_ci_move(FileData *fd, const gchar *dest_path);
244 gboolean file_data_sc_update_ci_rename(FileData *fd, const gchar *dest_path);
245 gboolean file_data_sc_update_ci_unspecified(FileData *fd, const gchar *dest_path);
246
247 gchar *file_data_get_error_string(gint error);
248
249 gint file_data_verify_ci(FileData *fd, GList *list);
250 gint file_data_verify_ci_list(GList *list, gchar **desc, gboolean with_sidecars);
251
252 gboolean file_data_perform_ci(FileData *fd);
253 gboolean file_data_apply_ci(FileData *fd);
254 void file_data_free_ci(FileData *fd);
255 void file_data_free_ci_list(GList *fd_list);
256
257 void file_data_set_regroup_when_finished(FileData *fd, gboolean enable);
258
259 gint file_data_sc_verify_ci(FileData *fd, GList *list);
260
261 gboolean file_data_sc_perform_ci(FileData *fd);
262 gboolean file_data_sc_apply_ci(FileData *fd);
263 void file_data_sc_free_ci(FileData *fd);
264 void file_data_sc_free_ci_list(GList *fd_list);
265
266 GList *file_data_process_groups_in_selection(GList *list, gboolean ungroup, GList **ungrouped);
267
268
269 using FileDataNotifyFunc = void (*)(FileData *, NotifyType, gpointer);
270 gboolean file_data_register_notify_func(FileDataNotifyFunc func, gpointer data, NotifyPriority priority);
271 gboolean file_data_unregister_notify_func(FileDataNotifyFunc func, gpointer data);
272 void file_data_send_notification(FileData *fd, NotifyType type);
273
274 gboolean file_data_register_real_time_monitor(FileData *fd);
275 gboolean file_data_unregister_real_time_monitor(FileData *fd);
276
277 void read_exif_time_data(FileData *file);
278 void read_exif_time_digitized_data(FileData *file);
279
280 gboolean marks_list_save(gchar *path, gboolean save);
281 gboolean marks_list_load(const gchar *path);
282 void marks_clear_all();
283 void read_rating_data(FileData *file);
284
285 void file_data_inc_page_num(FileData *fd);
286 void file_data_dec_page_num(FileData *fd);
287 void file_data_set_page_total(FileData *fd, gint page_total);
288 void file_data_set_page_num(FileData *fd, gint page_num);
289
290 void file_data_dump();
291 #endif
292 /* vim: set shiftwidth=8 softtabstop=0 cindent cinoptions={1s: */