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