Mercurial > geeqie.yaz
annotate src/filedata.c @ 784:16b3a5c8aedc
new notification system (used only in vflist for now)
author | nadvornik |
---|---|
date | Wed, 04 Jun 2008 21:12:47 +0000 |
parents | d6a7fb4b8e7c |
children | 548b193c084c |
rev | line source |
---|---|
586 | 1 /* |
2 * Geeqie | |
3 * (C) 2006 John Ellis | |
4 * Copyright (C) 2008 The Geeqie Team | |
5 * | |
6 * Author: John Ellis | |
7 * | |
8 * This software is released under the GNU General Public License (GNU GPL). | |
9 * Please read the included file COPYING for more information. | |
10 * This software comes with no warranty of any kind, use at your own risk! | |
11 */ | |
12 | |
13 | |
14 #include "main.h" | |
15 #include "filedata.h" | |
16 | |
17 #include "filefilter.h" | |
18 #include "cache.h" | |
19 #include "rcfile.h" | |
20 #include "secure_save.h" | |
21 #include "thumb_standard.h" | |
22 #include "ui_fileops.h" | |
23 | |
24 | |
25 static gint sidecar_file_priority(const gchar *path); | |
26 | |
27 | |
28 /* | |
29 *----------------------------------------------------------------------------- | |
30 * text conversion utils | |
31 *----------------------------------------------------------------------------- | |
32 */ | |
33 | |
34 gchar *text_from_size(gint64 size) | |
35 { | |
36 gchar *a, *b; | |
37 gchar *s, *d; | |
38 gint l, n, i; | |
39 | |
40 /* what I would like to use is printf("%'d", size) | |
41 * BUT: not supported on every libc :( | |
42 */ | |
43 if (size > G_MAXUINT) | |
44 { | |
45 /* the %lld conversion is not valid in all libcs, so use a simple work-around */ | |
46 a = g_strdup_printf("%d%09d", (guint)(size / 1000000000), (guint)(size % 1000000000)); | |
47 } | |
48 else | |
49 { | |
50 a = g_strdup_printf("%d", (guint)size); | |
51 } | |
52 l = strlen(a); | |
53 n = (l - 1)/ 3; | |
54 if (n < 1) return a; | |
55 | |
56 b = g_new(gchar, l + n + 1); | |
57 | |
58 s = a; | |
59 d = b; | |
60 i = l - n * 3; | |
61 while (*s != '\0') | |
62 { | |
63 if (i < 1) | |
64 { | |
65 i = 3; | |
66 *d = ','; | |
67 d++; | |
68 } | |
69 | |
70 *d = *s; | |
71 s++; | |
72 d++; | |
73 i--; | |
74 } | |
75 *d = '\0'; | |
76 | |
77 g_free(a); | |
78 return b; | |
79 } | |
80 | |
81 gchar *text_from_size_abrev(gint64 size) | |
82 { | |
83 if (size < (gint64)1024) | |
84 { | |
85 return g_strdup_printf(_("%d bytes"), (gint)size); | |
86 } | |
87 if (size < (gint64)1048576) | |
88 { | |
89 return g_strdup_printf(_("%.1f K"), (double)size / 1024.0); | |
90 } | |
91 if (size < (gint64)1073741824) | |
92 { | |
93 return g_strdup_printf(_("%.1f MB"), (double)size / 1048576.0); | |
94 } | |
95 | |
96 /* to avoid overflowing the double, do division in two steps */ | |
97 size /= 1048576; | |
98 return g_strdup_printf(_("%.1f GB"), (double)size / 1024.0); | |
99 } | |
100 | |
101 /* note: returned string is valid until next call to text_from_time() */ | |
102 const gchar *text_from_time(time_t t) | |
103 { | |
104 static gchar *ret = NULL; | |
105 gchar buf[128]; | |
106 gint buflen; | |
107 struct tm *btime; | |
108 GError *error = NULL; | |
109 | |
110 btime = localtime(&t); | |
111 | |
112 /* the %x warning about 2 digit years is not an error */ | |
113 buflen = strftime(buf, sizeof(buf), "%x %H:%M", btime); | |
114 if (buflen < 1) return ""; | |
115 | |
116 g_free(ret); | |
117 ret = g_locale_to_utf8(buf, buflen, NULL, NULL, &error); | |
118 if (error) | |
119 { | |
673
fbebf5cf4a55
Do not use printf() directly but use new wrapper function log_printf() instead.
zas_
parents:
671
diff
changeset
|
120 log_printf("Error converting locale strftime to UTF-8: %s\n", error->message); |
586 | 121 g_error_free(error); |
122 return ""; | |
123 } | |
124 | |
125 return ret; | |
126 } | |
127 | |
128 /* | |
129 *----------------------------------------------------------------------------- | |
130 * file info struct | |
131 *----------------------------------------------------------------------------- | |
132 */ | |
133 | |
134 FileData *file_data_merge_sidecar_files(FileData *target, FileData *source); | |
135 static void file_data_check_sidecars(FileData *fd); | |
136 FileData *file_data_disconnect_sidecar_file(FileData *target, FileData *sfd); | |
137 | |
138 | |
763
81f9e8dbb4bf
improved infrastructure for tracing changes, optimized vflist_populate_view
nadvornik
parents:
753
diff
changeset
|
139 void file_data_increment_version(FileData *fd) |
81f9e8dbb4bf
improved infrastructure for tracing changes, optimized vflist_populate_view
nadvornik
parents:
753
diff
changeset
|
140 { |
81f9e8dbb4bf
improved infrastructure for tracing changes, optimized vflist_populate_view
nadvornik
parents:
753
diff
changeset
|
141 fd->version++; |
81f9e8dbb4bf
improved infrastructure for tracing changes, optimized vflist_populate_view
nadvornik
parents:
753
diff
changeset
|
142 if (fd->parent) fd->parent->version++; |
784
16b3a5c8aedc
new notification system (used only in vflist for now)
nadvornik
parents:
783
diff
changeset
|
143 |
16b3a5c8aedc
new notification system (used only in vflist for now)
nadvornik
parents:
783
diff
changeset
|
144 file_data_send_notification(fd); /* FIXME there are probably situations when we don't want to call this */ |
763
81f9e8dbb4bf
improved infrastructure for tracing changes, optimized vflist_populate_view
nadvornik
parents:
753
diff
changeset
|
145 } |
81f9e8dbb4bf
improved infrastructure for tracing changes, optimized vflist_populate_view
nadvornik
parents:
753
diff
changeset
|
146 |
81f9e8dbb4bf
improved infrastructure for tracing changes, optimized vflist_populate_view
nadvornik
parents:
753
diff
changeset
|
147 |
586 | 148 static void file_data_set_path(FileData *fd, const gchar *path) |
149 { | |
150 | |
725 | 151 if (strcmp(path, G_DIR_SEPARATOR_S) == 0) |
586 | 152 { |
153 fd->path = g_strdup(path); | |
154 fd->name = fd->path; | |
155 fd->extension = fd->name + 1; | |
156 return; | |
157 } | |
158 | |
159 fd->path = g_strdup(path); | |
160 fd->name = filename_from_path(fd->path); | |
161 | |
162 if (strcmp(fd->name, "..") == 0) | |
163 { | |
164 gchar *dir = remove_level_from_path(path); | |
165 g_free(fd->path); | |
166 fd->path = remove_level_from_path(dir); | |
167 g_free(dir); | |
168 fd->name = ".."; | |
169 fd->extension = fd->name + 2; | |
170 return; | |
171 } | |
172 else if (strcmp(fd->name, ".") == 0) | |
173 { | |
174 g_free(fd->path); | |
175 fd->path = remove_level_from_path(path); | |
176 fd->name = "."; | |
177 fd->extension = fd->name + 1; | |
178 return; | |
179 } | |
180 | |
181 fd->extension = extension_from_path(fd->path); | |
182 if (fd->extension == NULL) | |
183 fd->extension = fd->name + strlen(fd->name); | |
184 } | |
185 | |
186 static void file_data_check_changed_files(FileData *fd, struct stat *st) | |
187 { | |
188 GList *work; | |
189 if (fd->size != st->st_size || | |
190 fd->date != st->st_mtime) | |
191 { | |
192 fd->size = st->st_size; | |
193 fd->date = st->st_mtime; | |
194 if (fd->pixbuf) g_object_unref(fd->pixbuf); | |
195 fd->pixbuf = NULL; | |
763
81f9e8dbb4bf
improved infrastructure for tracing changes, optimized vflist_populate_view
nadvornik
parents:
753
diff
changeset
|
196 file_data_increment_version(fd); |
586 | 197 } |
198 | |
199 work = fd->sidecar_files; | |
200 while (work) | |
201 { | |
202 FileData *sfd = work->data; | |
203 struct stat st; | |
204 | |
205 if (!stat_utf8(sfd->path, &st)) | |
206 { | |
207 file_data_disconnect_sidecar_file(fd, sfd); | |
208 } | |
209 | |
210 file_data_check_changed_files(sfd, &st); | |
211 work = work->next; | |
212 } | |
213 } | |
214 | |
215 static GHashTable *file_data_pool = NULL; | |
216 | |
217 static FileData *file_data_new(const gchar *path_utf8, struct stat *st, gboolean check_sidecars) | |
218 { | |
219 FileData *fd; | |
220 | |
221 DEBUG_2("file_data_new: '%s' %d", path_utf8, check_sidecars); | |
222 | |
223 if (!file_data_pool) | |
224 file_data_pool = g_hash_table_new(g_str_hash, g_str_equal); | |
225 | |
226 fd = g_hash_table_lookup(file_data_pool, path_utf8); | |
227 if (fd) | |
228 { | |
229 file_data_check_changed_files(fd, st); | |
230 DEBUG_2("file_data_pool hit: '%s'", fd->path); | |
231 return file_data_ref(fd); | |
232 } | |
233 | |
234 fd = g_new0(FileData, 1); | |
235 | |
236 file_data_set_path(fd, path_utf8); | |
237 | |
238 fd->original_path = g_strdup(path_utf8); | |
239 fd->size = st->st_size; | |
240 fd->date = st->st_mtime; | |
241 fd->pixbuf = NULL; | |
242 fd->sidecar_files = NULL; | |
243 fd->ref = 1; | |
244 fd->magick = 0x12345678; | |
245 | |
246 g_hash_table_insert(file_data_pool, fd->original_path, fd); | |
247 | |
248 if (check_sidecars && sidecar_file_priority(fd->extension)) | |
249 file_data_check_sidecars(fd); | |
250 return fd; | |
251 } | |
252 | |
253 static void file_data_check_sidecars(FileData *fd) | |
254 { | |
255 int base_len = fd->extension - fd->path; | |
256 GString *fname = g_string_new_len(fd->path, base_len); | |
257 FileData *parent_fd = NULL; | |
258 GList *work = sidecar_ext_get_list(); | |
259 while (work) | |
260 { | |
261 /* check for possible sidecar files; | |
262 the sidecar files created here are referenced only via fd->sidecar_files or fd->parent, | |
263 they have fd->ref set to 0 and file_data unref must chack and free them all together | |
264 (using fd->ref would cause loops and leaks) | |
265 */ | |
266 | |
267 FileData *new_fd; | |
268 | |
269 gchar *ext = work->data; | |
270 work = work->next; | |
271 | |
272 if (strcmp(ext, fd->extension) == 0) | |
273 { | |
274 new_fd = fd; /* processing the original file */ | |
275 } | |
276 else | |
277 { | |
278 struct stat nst; | |
279 g_string_truncate(fname, base_len); | |
280 g_string_append(fname, ext); | |
281 | |
282 if (!stat_utf8(fname->str, &nst)) | |
283 continue; | |
284 | |
285 new_fd = file_data_new(fname->str, &nst, FALSE); | |
286 new_fd->ref--; /* do not use ref here */ | |
287 } | |
288 | |
289 if (!parent_fd) | |
290 parent_fd = new_fd; /* parent is the one with the highest prio, found first */ | |
291 else | |
292 file_data_merge_sidecar_files(parent_fd, new_fd); | |
293 } | |
294 g_string_free(fname, TRUE); | |
295 } | |
296 | |
297 | |
298 static FileData *file_data_new_local(const gchar *path, struct stat *st, gboolean check_sidecars) | |
299 { | |
300 gchar *path_utf8 = path_to_utf8(path); | |
301 FileData *ret = file_data_new(path_utf8, st, check_sidecars); | |
302 g_free(path_utf8); | |
303 return ret; | |
304 } | |
305 | |
306 FileData *file_data_new_simple(const gchar *path_utf8) | |
307 { | |
308 struct stat st; | |
309 | |
310 if (!stat_utf8(path_utf8, &st)) | |
311 { | |
312 st.st_size = 0; | |
313 st.st_mtime = 0; | |
314 } | |
315 | |
316 return file_data_new(path_utf8, &st, TRUE); | |
317 } | |
318 | |
319 FileData *file_data_add_sidecar_file(FileData *target, FileData *sfd) | |
320 { | |
321 sfd->parent = target; | |
322 if(!g_list_find(target->sidecar_files, sfd)) | |
323 target->sidecar_files = g_list_prepend(target->sidecar_files, sfd); | |
324 return target; | |
325 } | |
326 | |
327 | |
328 FileData *file_data_merge_sidecar_files(FileData *target, FileData *source) | |
329 { | |
330 GList *work; | |
331 file_data_add_sidecar_file(target, source); | |
332 | |
333 work = source->sidecar_files; | |
334 while (work) | |
335 { | |
336 FileData *sfd = work->data; | |
337 file_data_add_sidecar_file(target, sfd); | |
338 work = work->next; | |
339 } | |
340 | |
341 g_list_free(source->sidecar_files); | |
342 source->sidecar_files = NULL; | |
343 | |
344 target->sidecar_files = filelist_sort(target->sidecar_files, SORT_NAME, TRUE); | |
345 return target; | |
346 } | |
347 | |
348 | |
349 | |
350 FileData *file_data_ref(FileData *fd) | |
351 { | |
352 if (fd == NULL) return NULL; | |
353 | |
354 // return g_memdup(fd, sizeof(FileData)); | |
355 g_assert(fd->magick == 0x12345678); | |
356 fd->ref++; | |
357 return fd; | |
358 } | |
359 | |
360 static void file_data_free(FileData *fd) | |
361 { | |
362 g_assert(fd->magick == 0x12345678); | |
363 g_assert(fd->ref == 0); | |
364 | |
365 g_hash_table_remove(file_data_pool, fd->original_path); | |
366 | |
367 g_free(fd->path); | |
368 g_free(fd->original_path); | |
369 if (fd->pixbuf) g_object_unref(fd->pixbuf); | |
370 | |
371 | |
372 g_assert(fd->sidecar_files == NULL); /* sidecar files must be freed before calling this */ | |
373 | |
374 file_data_change_info_free(NULL, fd); | |
375 g_free(fd); | |
376 } | |
377 | |
378 void file_data_unref(FileData *fd) | |
379 { | |
380 if (fd == NULL) return; | |
381 g_assert(fd->magick == 0x12345678); | |
382 | |
383 fd->ref--; | |
384 DEBUG_2("file_data_unref (%d): '%s'", fd->ref, fd->path); | |
385 | |
386 if (fd->ref == 0) | |
387 { | |
388 FileData *parent = fd->parent ? fd->parent : fd; | |
389 | |
390 GList *work; | |
391 | |
392 if (parent->ref > 0) | |
393 return; | |
394 | |
395 work = parent->sidecar_files; | |
396 while (work) | |
397 { | |
398 FileData *sfd = work->data; | |
399 if (sfd->ref > 0) | |
400 return; | |
401 work = work->next; | |
402 } | |
403 | |
404 /* none of parent/children is referenced, we can free everything */ | |
405 | |
406 DEBUG_2("file_data_unref: deleting '%s', parent '%s'", fd->path, parent->path); | |
407 | |
408 work = parent->sidecar_files; | |
409 while (work) | |
410 { | |
411 FileData *sfd = work->data; | |
412 file_data_free(sfd); | |
413 work = work->next; | |
414 } | |
415 | |
416 g_list_free(parent->sidecar_files); | |
417 parent->sidecar_files = NULL; | |
418 | |
419 file_data_free(parent); | |
420 | |
421 } | |
422 } | |
423 | |
424 FileData *file_data_disconnect_sidecar_file(FileData *target, FileData *sfd) | |
425 { | |
426 sfd->parent = target; | |
427 g_assert(g_list_find(target->sidecar_files, sfd)); | |
428 | |
429 target->sidecar_files = g_list_remove(target->sidecar_files, sfd); | |
430 sfd->parent = NULL; | |
431 | |
432 if (sfd->ref == 0) { | |
433 file_data_free(sfd); | |
434 return NULL; | |
435 } | |
436 | |
437 return sfd; | |
438 } | |
439 | |
440 /* compare name without extension */ | |
441 gint file_data_compare_name_without_ext(FileData *fd1, FileData *fd2) | |
442 { | |
443 size_t len1 = fd1->extension - fd1->name; | |
444 size_t len2 = fd2->extension - fd2->name; | |
445 | |
446 if (len1 < len2) return -1; | |
447 if (len1 > len2) return 1; | |
448 | |
449 return strncmp(fd1->name, fd2->name, len1); | |
450 } | |
451 | |
452 gboolean file_data_add_change_info(FileData *fd, FileDataChangeType type, const gchar *src, const gchar *dest) | |
453 { | |
454 | |
455 FileDataChangeInfo *fdci; | |
456 | |
457 if (fd->change) return FALSE; | |
458 | |
459 fdci = g_new0(FileDataChangeInfo, 1); | |
460 | |
461 fdci->type = type; | |
462 | |
463 if (src) | |
464 fdci->source = g_strdup(src); | |
465 else | |
466 fdci->source = g_strdup(fd->path); | |
467 | |
468 if (dest) | |
469 fdci->dest = g_strdup(dest); | |
470 | |
471 fd->change = fdci; | |
472 return TRUE; | |
473 } | |
474 | |
475 void file_data_change_info_free(FileDataChangeInfo *fdci, FileData *fd) | |
476 { | |
477 if (!fdci && fd) | |
478 fdci = fd->change; | |
479 | |
480 if (!fdci) | |
481 return; | |
482 | |
483 g_free(fdci->source); | |
484 g_free(fdci->dest); | |
485 | |
486 g_free(fdci); | |
487 | |
488 if (fd) | |
489 fd->change = NULL; | |
490 } | |
491 | |
492 | |
493 | |
494 | |
495 /* | |
496 *----------------------------------------------------------------------------- | |
497 * sidecar file info struct | |
498 *----------------------------------------------------------------------------- | |
499 */ | |
500 | |
501 | |
502 | |
503 static gint sidecar_file_priority(const gchar *path) | |
504 { | |
505 const char *extension = extension_from_path(path); | |
506 int i = 1; | |
507 GList *work; | |
508 if (extension == NULL) | |
509 return 0; | |
510 | |
511 work = sidecar_ext_get_list(); | |
512 | |
513 while (work) { | |
514 gchar *ext = work->data; | |
515 work = work->next; | |
516 if (strcmp(extension, ext) == 0) return i; | |
517 i++; | |
518 } | |
519 return 0; | |
520 } | |
521 | |
522 | |
523 /* | |
524 *----------------------------------------------------------------------------- | |
525 * load file list | |
526 *----------------------------------------------------------------------------- | |
527 */ | |
528 | |
529 static SortType filelist_sort_method = SORT_NONE; | |
530 static gint filelist_sort_ascend = TRUE; | |
531 | |
532 | |
533 gint filelist_sort_compare_filedata(FileData *fa, FileData *fb) | |
534 { | |
535 if (!filelist_sort_ascend) | |
536 { | |
537 FileData *tmp = fa; | |
538 fa = fb; | |
539 fb = tmp; | |
540 } | |
541 | |
542 switch (filelist_sort_method) | |
543 { | |
544 case SORT_SIZE: | |
545 if (fa->size < fb->size) return -1; | |
546 if (fa->size > fb->size) return 1; | |
547 return CASE_SORT(fa->name, fb->name); /* fall back to name */ | |
548 break; | |
549 case SORT_TIME: | |
550 if (fa->date < fb->date) return -1; | |
551 if (fa->date > fb->date) return 1; | |
552 return CASE_SORT(fa->name, fb->name); /* fall back to name */ | |
553 break; | |
554 #ifdef HAVE_STRVERSCMP | |
555 case SORT_NUMBER: | |
556 return strverscmp(fa->name, fb->name); | |
557 break; | |
558 #endif | |
559 case SORT_NAME: | |
560 default: | |
561 return CASE_SORT(fa->name, fb->name); | |
562 break; | |
563 } | |
564 } | |
565 | |
566 gint filelist_sort_compare_filedata_full(FileData *fa, FileData *fb, SortType method, gint ascend) | |
567 { | |
568 filelist_sort_method = method; | |
569 filelist_sort_ascend = ascend; | |
570 return filelist_sort_compare_filedata(fa, fb); | |
571 } | |
572 | |
573 static gint filelist_sort_file_cb(void *a, void *b) | |
574 { | |
575 return filelist_sort_compare_filedata(a, b); | |
576 } | |
577 | |
578 GList *filelist_sort_full(GList *list, SortType method, gint ascend, GCompareFunc cb) | |
579 { | |
580 filelist_sort_method = method; | |
581 filelist_sort_ascend = ascend; | |
582 return g_list_sort(list, cb); | |
583 } | |
584 | |
585 GList *filelist_insert_sort_full(GList *list, void *data, SortType method, gint ascend, GCompareFunc cb) | |
586 { | |
587 filelist_sort_method = method; | |
588 filelist_sort_ascend = ascend; | |
589 return g_list_insert_sorted(list, data, cb); | |
590 } | |
591 | |
592 GList *filelist_sort(GList *list, SortType method, gint ascend) | |
593 { | |
594 return filelist_sort_full(list, method, ascend, (GCompareFunc) filelist_sort_file_cb); | |
595 } | |
596 | |
597 GList *filelist_insert_sort(GList *list, FileData *fd, SortType method, gint ascend) | |
598 { | |
599 return filelist_insert_sort_full(list, fd, method, ascend, (GCompareFunc) filelist_sort_file_cb); | |
600 } | |
601 | |
602 | |
603 static GList *filelist_filter_out_sidecars(GList *flist) | |
604 { | |
605 GList *work = flist; | |
606 GList *flist_filtered = NULL; | |
607 | |
608 while (work) | |
609 { | |
610 FileData *fd = work->data; | |
611 work = work->next; | |
612 if (fd->parent) /* remove fd's that are children */ | |
613 file_data_unref(fd); | |
614 else | |
615 flist_filtered = g_list_prepend(flist_filtered, fd); | |
616 } | |
617 g_list_free(flist); | |
618 return flist_filtered; | |
619 } | |
620 | |
783 | 621 static gint filelist_read_real(FileData *dir_fd, GList **files, GList **dirs, gint follow_symlinks) |
586 | 622 { |
623 DIR *dp; | |
624 struct dirent *dir; | |
625 gchar *pathl; | |
779 | 626 GList *dlist = NULL; |
627 GList *flist = NULL; | |
628 int (*stat_func)(const char *path, struct stat *buf); | |
586 | 629 |
779 | 630 g_assert(files || dirs); |
631 | |
632 if (files) *files = NULL; | |
633 if (dirs) *dirs = NULL; | |
586 | 634 |
783 | 635 pathl = path_from_utf8(dir_fd->path); |
779 | 636 if (!pathl) return FALSE; |
637 | |
638 dp = opendir(pathl); | |
639 if (dp == NULL) | |
586 | 640 { |
641 g_free(pathl); | |
642 return FALSE; | |
643 } | |
644 | |
779 | 645 if (follow_symlinks) |
646 stat_func = stat; | |
647 else | |
648 stat_func = lstat; | |
649 | |
586 | 650 while ((dir = readdir(dp)) != NULL) |
651 { | |
779 | 652 struct stat ent_sbuf; |
653 const gchar *name = dir->d_name; | |
654 gchar *filepath; | |
655 | |
656 if (!options->file_filter.show_hidden_files && ishidden(name)) | |
657 continue; | |
658 | |
659 filepath = g_build_filename(pathl, name, NULL); | |
660 if (stat_func(filepath, &ent_sbuf) >= 0) | |
586 | 661 { |
779 | 662 if (S_ISDIR(ent_sbuf.st_mode)) |
586 | 663 { |
779 | 664 /* we ignore the .thumbnails dir for cleanliness */ |
665 if (dirs && | |
666 !(name[0] == '.' && (name[1] == '\0' || (name[1] == '.' && name[2] == '\0'))) && | |
667 strcmp(name, GQ_CACHE_LOCAL_THUMB) != 0 && | |
668 strcmp(name, GQ_CACHE_LOCAL_METADATA) != 0 && | |
669 strcmp(name, THUMB_FOLDER_LOCAL) != 0) | |
586 | 670 { |
779 | 671 dlist = g_list_prepend(dlist, file_data_new_local(filepath, &ent_sbuf, FALSE)); |
586 | 672 } |
673 } | |
779 | 674 else |
675 { | |
676 if (files && filter_name_exists(name)) | |
677 { | |
678 flist = g_list_prepend(flist, file_data_new_local(filepath, &ent_sbuf, TRUE)); | |
679 } | |
680 } | |
586 | 681 } |
779 | 682 g_free(filepath); |
586 | 683 } |
684 | |
685 closedir(dp); | |
779 | 686 |
586 | 687 g_free(pathl); |
688 | |
689 if (dirs) *dirs = dlist; | |
779 | 690 if (files) *files = filelist_filter_out_sidecars(flist); |
586 | 691 |
692 return TRUE; | |
693 } | |
694 | |
783 | 695 gint filelist_read(FileData *dir_fd, GList **files, GList **dirs) |
586 | 696 { |
783 | 697 return filelist_read_real(dir_fd, files, dirs, TRUE); |
586 | 698 } |
699 | |
783 | 700 gint filelist_read_lstat(FileData *dir_fd, GList **files, GList **dirs) |
586 | 701 { |
783 | 702 return filelist_read_real(dir_fd, files, dirs, FALSE); |
586 | 703 } |
704 | |
705 void filelist_free(GList *list) | |
706 { | |
707 GList *work; | |
708 | |
709 work = list; | |
710 while (work) | |
711 { | |
712 file_data_unref((FileData *)work->data); | |
713 work = work->next; | |
714 } | |
715 | |
716 g_list_free(list); | |
717 } | |
718 | |
719 | |
720 GList *filelist_copy(GList *list) | |
721 { | |
722 GList *new_list = NULL; | |
723 GList *work; | |
724 | |
725 work = list; | |
726 while (work) | |
727 { | |
728 FileData *fd; | |
729 | |
730 fd = work->data; | |
731 work = work->next; | |
732 | |
733 new_list = g_list_prepend(new_list, file_data_ref(fd)); | |
734 } | |
735 | |
736 return g_list_reverse(new_list); | |
737 } | |
738 | |
739 GList *filelist_from_path_list(GList *list) | |
740 { | |
741 GList *new_list = NULL; | |
742 GList *work; | |
743 | |
744 work = list; | |
745 while (work) | |
746 { | |
747 gchar *path; | |
748 | |
749 path = work->data; | |
750 work = work->next; | |
751 | |
752 new_list = g_list_prepend(new_list, file_data_new_simple(path)); | |
753 } | |
754 | |
755 return g_list_reverse(new_list); | |
756 } | |
757 | |
758 GList *filelist_to_path_list(GList *list) | |
759 { | |
760 GList *new_list = NULL; | |
761 GList *work; | |
762 | |
763 work = list; | |
764 while (work) | |
765 { | |
766 FileData *fd; | |
767 | |
768 fd = work->data; | |
769 work = work->next; | |
770 | |
771 new_list = g_list_prepend(new_list, g_strdup(fd->path)); | |
772 } | |
773 | |
774 return g_list_reverse(new_list); | |
775 } | |
776 | |
777 GList *filelist_filter(GList *list, gint is_dir_list) | |
778 { | |
779 GList *work; | |
780 | |
781 if (!is_dir_list && options->file_filter.disable && options->file_filter.show_hidden_files) return list; | |
782 | |
783 work = list; | |
784 while (work) | |
785 { | |
786 FileData *fd = (FileData *)(work->data); | |
787 const gchar *name = fd->name; | |
788 | |
789 if ((!options->file_filter.show_hidden_files && ishidden(name)) || | |
790 (!is_dir_list && !filter_name_exists(name)) || | |
791 (is_dir_list && name[0] == '.' && (strcmp(name, GQ_CACHE_LOCAL_THUMB) == 0 || | |
792 strcmp(name, GQ_CACHE_LOCAL_METADATA) == 0)) ) | |
793 { | |
794 GList *link = work; | |
795 work = work->next; | |
796 list = g_list_remove_link(list, link); | |
797 file_data_unref(fd); | |
798 g_list_free(link); | |
799 } | |
800 else | |
801 { | |
802 work = work->next; | |
803 } | |
804 } | |
805 | |
806 return list; | |
807 } | |
808 | |
809 /* | |
810 *----------------------------------------------------------------------------- | |
811 * filelist recursive | |
812 *----------------------------------------------------------------------------- | |
813 */ | |
814 | |
815 static gint filelist_sort_path_cb(gconstpointer a, gconstpointer b) | |
816 { | |
817 return CASE_SORT(((FileData *)a)->path, ((FileData *)b)->path); | |
818 } | |
819 | |
820 GList *filelist_sort_path(GList *list) | |
821 { | |
822 return g_list_sort(list, filelist_sort_path_cb); | |
823 } | |
824 | |
825 static void filelist_recursive_append(GList **list, GList *dirs) | |
826 { | |
827 GList *work; | |
828 | |
829 work = dirs; | |
830 while (work) | |
831 { | |
832 FileData *fd = (FileData *)(work->data); | |
780
44128da39e13
Drop initialization to NULL since filelist_read() will take care of it.
zas_
parents:
779
diff
changeset
|
833 GList *f; |
44128da39e13
Drop initialization to NULL since filelist_read() will take care of it.
zas_
parents:
779
diff
changeset
|
834 GList *d; |
586 | 835 |
783 | 836 if (filelist_read(fd, &f, &d)) |
586 | 837 { |
838 f = filelist_filter(f, FALSE); | |
839 f = filelist_sort_path(f); | |
840 *list = g_list_concat(*list, f); | |
841 | |
842 d = filelist_filter(d, TRUE); | |
843 d = filelist_sort_path(d); | |
844 filelist_recursive_append(list, d); | |
845 filelist_free(d); | |
846 } | |
847 | |
848 work = work->next; | |
849 } | |
850 } | |
851 | |
783 | 852 GList *filelist_recursive(FileData *dir_fd) |
586 | 853 { |
780
44128da39e13
Drop initialization to NULL since filelist_read() will take care of it.
zas_
parents:
779
diff
changeset
|
854 GList *list; |
44128da39e13
Drop initialization to NULL since filelist_read() will take care of it.
zas_
parents:
779
diff
changeset
|
855 GList *d; |
586 | 856 |
783 | 857 if (!filelist_read(dir_fd, &list, &d)) return NULL; |
586 | 858 list = filelist_filter(list, FALSE); |
859 list = filelist_sort_path(list); | |
860 | |
861 d = filelist_filter(d, TRUE); | |
862 d = filelist_sort_path(d); | |
863 filelist_recursive_append(&list, d); | |
864 filelist_free(d); | |
865 | |
866 return list; | |
867 } | |
590 | 868 |
869 | |
870 | |
871 /* | |
872 * file_data - operates on the given fd | |
873 * file_data_sc - operates on the given fd + sidecars - all fds linked via fd->sidecar_files or fd->parent | |
874 */ | |
875 | |
876 | |
877 /* return list of sidecar file extensions in a string */ | |
596 | 878 gchar *file_data_sc_list_to_string(FileData *fd) |
879 { | |
880 GList *work; | |
881 GString *result = g_string_new(""); | |
882 | |
883 work = fd->sidecar_files; | |
884 while (work) | |
885 { | |
886 FileData *sfd = work->data; | |
887 result = g_string_append(result, "+ "); | |
888 result = g_string_append(result, sfd->extension); | |
889 work = work->next; | |
890 if (work) result = g_string_append_c(result, ' '); | |
891 } | |
892 | |
893 return g_string_free(result, FALSE); | |
894 } | |
590 | 895 |
896 | |
897 /* disables / enables grouping for particular file, sends UPDATE notification */ | |
898 void file_data_disable_grouping(FileData *fd); // now file_data_disconnect_sidecar_file, broken | |
899 void file_data_disable_grouping(FileData *fd); | |
900 | |
901 /* runs stat on a file and sends UPDATE notification if it has been changed */ | |
902 void file_data_sc_update(FileData *fd); | |
903 | |
904 | |
905 | |
906 | |
907 /* | |
908 * add FileDataChangeInfo (see typedefs.h) for the given operation | |
909 * uses file_data_add_change_info | |
910 * | |
911 * fails if the fd->change already exists - change operations can't run in parallel | |
912 * fd->change_info works as a lock | |
913 * | |
914 * dest can be NULL - in this case the current name is used for now, it will | |
915 * be changed later | |
916 */ | |
917 | |
918 /* | |
919 FileDataChangeInfo types: | |
920 COPY | |
921 MOVE - patch is changed, name may be changed too | |
922 RENAME - path remains unchanged, name is changed | |
923 extension should remain (FIXME should we allow editing extension? it will make problems wth grouping) | |
924 sidecar names are changed too, extensions are not changed | |
925 DELETE | |
926 UPDATE - file size, date or grouping has been changed | |
927 */ | |
928 | |
929 gboolean file_data_add_ci(FileData *fd, FileDataChangeType type, const gchar *src, const gchar *dest) | |
930 { | |
931 | |
932 FileDataChangeInfo *fdci; | |
933 | |
934 if (fd->change) return FALSE; | |
935 | |
936 fdci = g_new0(FileDataChangeInfo, 1); | |
937 | |
938 fdci->type = type; | |
939 | |
940 if (src) | |
941 fdci->source = g_strdup(src); | |
942 else | |
943 fdci->source = g_strdup(fd->path); | |
944 | |
945 if (dest) | |
946 fdci->dest = g_strdup(dest); | |
947 | |
948 fd->change = fdci; | |
949 | |
950 return TRUE; | |
951 } | |
952 | |
953 void file_data_free_ci(FileData *fd) | |
954 { | |
955 FileDataChangeInfo *fdci = fd->change; | |
956 | |
957 if (!fdci) | |
958 return; | |
959 | |
960 g_free(fdci->source); | |
961 g_free(fdci->dest); | |
962 | |
963 g_free(fdci); | |
964 | |
965 fd->change = NULL; | |
966 } | |
967 | |
968 | |
969 static gboolean file_data_sc_add_ci(FileData *fd, FileDataChangeType type) | |
970 { | |
971 GList *work; | |
972 if (fd->parent) fd = fd->parent; | |
973 | |
974 if (fd->change) return FALSE; | |
975 work = fd->sidecar_files; | |
976 while (work) | |
977 { | |
978 FileData *sfd = work->data; | |
979 if (sfd->change) return FALSE; | |
980 work = work->next; | |
981 } | |
982 | |
983 file_data_add_ci(fd, type, NULL, NULL); | |
984 | |
985 work = fd->sidecar_files; | |
986 while (work) | |
987 { | |
988 FileData *sfd = work->data; | |
989 file_data_add_ci(sfd, type, NULL, NULL); | |
990 work = work->next; | |
991 } | |
992 | |
993 return TRUE; | |
994 } | |
995 | |
996 static gboolean file_data_sc_check_ci(FileData *fd, FileDataChangeType type) | |
997 { | |
998 GList *work; | |
999 if (fd->parent) fd = fd->parent; | |
1000 | |
1001 if (!fd->change) return FALSE; | |
1002 if (fd->change->type != type) return FALSE; | |
1003 work = fd->sidecar_files; | |
1004 while (work) | |
1005 { | |
1006 FileData *sfd = work->data; | |
1007 if (!sfd->change) return FALSE; | |
1008 if (sfd->change->type != type) return FALSE; | |
1009 work = work->next; | |
1010 } | |
1011 return TRUE; | |
1012 } | |
1013 | |
1014 | |
751 | 1015 gboolean file_data_sc_add_ci_copy(FileData *fd, const gchar *dest_path) |
590 | 1016 { |
1017 if (!file_data_sc_add_ci(fd, FILEDATA_CHANGE_COPY)) return FALSE; | |
1018 file_data_sc_update_ci_copy(fd, dest_path); | |
1019 return TRUE; | |
1020 } | |
1021 | |
751 | 1022 gboolean file_data_sc_add_ci_move(FileData *fd, const gchar *dest_path) |
590 | 1023 { |
1024 if (!file_data_sc_add_ci(fd, FILEDATA_CHANGE_MOVE)) return FALSE; | |
1025 file_data_sc_update_ci_move(fd, dest_path); | |
1026 return TRUE; | |
1027 } | |
1028 | |
751 | 1029 gboolean file_data_sc_add_ci_rename(FileData *fd, const gchar *dest_path) |
590 | 1030 { |
1031 if (!file_data_sc_add_ci(fd, FILEDATA_CHANGE_RENAME)) return FALSE; | |
1032 file_data_sc_update_ci_rename(fd, dest_path); | |
1033 return TRUE; | |
1034 } | |
1035 | |
1036 gboolean file_data_sc_add_ci_delete(FileData *fd) | |
1037 { | |
1038 return file_data_sc_add_ci(fd, FILEDATA_CHANGE_DELETE); | |
1039 } | |
1040 | |
753 | 1041 gboolean file_data_sc_add_ci_unspecified(FileData *fd, const gchar *dest_path) |
590 | 1042 { |
753 | 1043 if (!file_data_sc_add_ci(fd, FILEDATA_CHANGE_UNSPECIFIED)) return FALSE; |
1044 file_data_sc_update_ci_unspecified(fd, dest_path); | |
1045 return TRUE; | |
590 | 1046 } |
1047 | |
1048 void file_data_sc_free_ci(FileData *fd) | |
1049 { | |
1050 GList *work; | |
1051 if (fd->parent) fd = fd->parent; | |
1052 | |
1053 file_data_free_ci(fd); | |
1054 | |
1055 work = fd->sidecar_files; | |
1056 while (work) | |
1057 { | |
1058 FileData *sfd = work->data; | |
1059 file_data_free_ci(sfd); | |
1060 work = work->next; | |
1061 } | |
1062 } | |
1063 | |
751 | 1064 gboolean file_data_sc_add_ci_delete_list(GList *fd_list) |
1065 { | |
1066 GList *work; | |
1067 gboolean ret = TRUE; | |
1068 work = fd_list; | |
1069 while (work) | |
1070 { | |
1071 FileData *fd = work->data; | |
1072 if (!file_data_sc_add_ci_delete(fd)) ret = FALSE; | |
1073 work = work->next; | |
1074 } | |
1075 return ret; | |
1076 } | |
1077 | |
1078 gboolean file_data_sc_add_ci_copy_list(GList *fd_list, const gchar *dest) | |
1079 { | |
1080 GList *work; | |
1081 gboolean ret = TRUE; | |
1082 work = fd_list; | |
1083 while (work) | |
1084 { | |
1085 FileData *fd = work->data; | |
1086 if (!file_data_sc_add_ci_copy(fd, dest)) ret = FALSE; | |
1087 work = work->next; | |
1088 } | |
1089 return ret; | |
1090 } | |
1091 | |
1092 gboolean file_data_sc_add_ci_move_list(GList *fd_list, const gchar *dest) | |
1093 { | |
1094 GList *work; | |
1095 gboolean ret = TRUE; | |
1096 work = fd_list; | |
1097 while (work) | |
1098 { | |
1099 FileData *fd = work->data; | |
1100 if (!file_data_sc_add_ci_move(fd, dest)) ret = FALSE; | |
1101 work = work->next; | |
1102 } | |
1103 return ret; | |
1104 } | |
1105 | |
1106 gboolean file_data_sc_add_ci_rename_list(GList *fd_list, const gchar *dest) | |
1107 { | |
1108 GList *work; | |
1109 gboolean ret = TRUE; | |
1110 work = fd_list; | |
1111 while (work) | |
1112 { | |
1113 FileData *fd = work->data; | |
1114 if (!file_data_sc_add_ci_rename(fd, dest)) ret = FALSE; | |
1115 work = work->next; | |
1116 } | |
1117 return ret; | |
1118 } | |
1119 | |
753 | 1120 gboolean file_data_sc_add_ci_unspecified_list(GList *fd_list, const gchar *dest) |
1121 { | |
1122 GList *work; | |
1123 gboolean ret = TRUE; | |
1124 work = fd_list; | |
1125 while (work) | |
1126 { | |
1127 FileData *fd = work->data; | |
1128 if (!file_data_sc_add_ci_unspecified(fd, dest)) ret = FALSE; | |
1129 work = work->next; | |
1130 } | |
1131 return ret; | |
1132 } | |
1133 | |
751 | 1134 void file_data_sc_free_ci_list(GList *fd_list) |
1135 { | |
1136 GList *work; | |
1137 work = fd_list; | |
1138 while (work) | |
1139 { | |
1140 FileData *fd = work->data; | |
1141 file_data_sc_free_ci(fd); | |
1142 work = work->next; | |
1143 } | |
1144 } | |
590 | 1145 |
1146 /* | |
1147 * update existing fd->change, it will be used from dialog callbacks for interactive editing | |
1148 * fails if fd->change does not exist or the change type does not match | |
1149 */ | |
1150 | |
751 | 1151 static void file_data_update_ci_dest(FileData *fd, const gchar *dest_path) |
590 | 1152 { |
1153 g_free(fd->change->dest); | |
1154 fd->change->dest = g_strdup(dest_path); | |
1155 } | |
1156 | |
751 | 1157 static void file_data_update_ci_dest_preserve_ext(FileData *fd, const gchar *dest_path) |
590 | 1158 { |
1159 const char *extension = extension_from_path(fd->change->source); | |
751 | 1160 gchar *base = remove_extension_from_path(dest_path); |
590 | 1161 g_free(fd->change->dest); |
751 | 1162 fd->change->dest = g_strdup_printf("%s%s", base, extension); |
1163 g_free(base); | |
590 | 1164 } |
1165 | |
751 | 1166 static void file_data_sc_update_ci(FileData *fd, const gchar *dest_path) |
590 | 1167 { |
1168 GList *work; | |
751 | 1169 gchar *dest_path_full = NULL; |
590 | 1170 if (fd->parent) fd = fd->parent; |
1171 | |
751 | 1172 if (!dest_path) dest_path = fd->path; |
1173 | |
1174 if (!strchr(dest_path, G_DIR_SEPARATOR)) /* we got only filename, not a full path */ | |
1175 { | |
1176 gchar *dir = remove_level_from_path(fd->path); | |
1177 dest_path_full = g_build_filename(dir, dest_path, NULL); | |
1178 g_free(dir); | |
1179 dest_path = dest_path_full; | |
1180 } | |
1181 | |
1182 if (isdir(dest_path)) | |
1183 { | |
1184 dest_path_full = g_build_filename(dest_path, fd->name, NULL); | |
1185 dest_path = dest_path_full; | |
1186 } | |
1187 | |
1188 | |
590 | 1189 file_data_update_ci_dest(fd, dest_path); |
1190 work = fd->sidecar_files; | |
1191 while (work) | |
1192 { | |
1193 FileData *sfd = work->data; | |
1194 file_data_update_ci_dest_preserve_ext(sfd, dest_path); | |
1195 work = work->next; | |
1196 } | |
751 | 1197 g_free(dest_path_full); |
590 | 1198 } |
1199 | |
751 | 1200 gint file_data_sc_update_ci_copy(FileData *fd, const gchar *dest_path) |
590 | 1201 { |
1202 if (!file_data_sc_check_ci(fd, FILEDATA_CHANGE_COPY)) return FALSE; | |
1203 file_data_sc_update_ci(fd, dest_path); | |
1204 return TRUE; | |
1205 } | |
1206 | |
751 | 1207 gint file_data_sc_update_ci_move(FileData *fd, const gchar *dest_path) |
590 | 1208 { |
1209 if (!file_data_sc_check_ci(fd, FILEDATA_CHANGE_MOVE)) return FALSE; | |
1210 file_data_sc_update_ci(fd, dest_path); | |
1211 return TRUE; | |
1212 } | |
1213 | |
751 | 1214 gint file_data_sc_update_ci_rename(FileData *fd, const gchar *dest_path) |
590 | 1215 { |
1216 if (!file_data_sc_check_ci(fd, FILEDATA_CHANGE_RENAME)) return FALSE; | |
1217 file_data_sc_update_ci(fd, dest_path); | |
1218 return TRUE; | |
1219 } | |
1220 | |
753 | 1221 gint file_data_sc_update_ci_unspecified(FileData *fd, const gchar *dest_path) |
1222 { | |
1223 if (!file_data_sc_check_ci(fd, FILEDATA_CHANGE_UNSPECIFIED)) return FALSE; | |
1224 file_data_sc_update_ci(fd, dest_path); | |
1225 return TRUE; | |
1226 } | |
1227 | |
590 | 1228 |
751 | 1229 gboolean file_data_sc_update_ci_move_list(GList *fd_list, const gchar *dest) |
1230 { | |
1231 GList *work; | |
1232 gboolean ret = TRUE; | |
1233 work = fd_list; | |
1234 while (work) | |
1235 { | |
1236 FileData *fd = work->data; | |
1237 if (!file_data_sc_update_ci_move(fd, dest)) ret = FALSE; | |
1238 work = work->next; | |
1239 } | |
1240 return ret; | |
1241 } | |
1242 | |
1243 gboolean file_data_sc_update_ci_copy_list(GList *fd_list, const gchar *dest) | |
1244 { | |
1245 GList *work; | |
1246 gboolean ret = TRUE; | |
1247 work = fd_list; | |
1248 while (work) | |
1249 { | |
1250 FileData *fd = work->data; | |
1251 if (!file_data_sc_update_ci_copy(fd, dest)) ret = FALSE; | |
1252 work = work->next; | |
1253 } | |
1254 return ret; | |
1255 } | |
1256 | |
753 | 1257 gboolean file_data_sc_update_ci_unspecified_list(GList *fd_list, const gchar *dest) |
1258 { | |
1259 GList *work; | |
1260 gboolean ret = TRUE; | |
1261 work = fd_list; | |
1262 while (work) | |
1263 { | |
1264 FileData *fd = work->data; | |
1265 if (!file_data_sc_update_ci_unspecified(fd, dest)) ret = FALSE; | |
1266 work = work->next; | |
1267 } | |
1268 return ret; | |
1269 } | |
1270 | |
590 | 1271 |
1272 /* | |
1273 * check dest paths - dest image exists, etc. | |
1274 * returns FIXME | |
1275 * it should detect all possible problems with the planned operation | |
1276 */ | |
1277 | |
1278 gint file_data_sc_check_ci_dest(FileData *fd) | |
1279 { | |
1280 } | |
1281 | |
1282 | |
1283 | |
1284 | |
1285 /* | |
1286 * perform the change described by FileFataChangeInfo | |
1287 * it is used for internal operations, | |
1288 * this function actually operates with files on the filesystem | |
1289 * it should implement safe delete | |
1290 */ | |
1291 | |
1292 static gboolean file_data_perform_move(FileData *fd) | |
1293 { | |
1294 g_assert(!strcmp(fd->change->source, fd->path)); | |
1295 return move_file(fd->change->source, fd->change->dest); | |
1296 } | |
1297 | |
1298 static gboolean file_data_perform_copy(FileData *fd) | |
1299 { | |
1300 g_assert(!strcmp(fd->change->source, fd->path)); | |
1301 return copy_file(fd->change->source, fd->change->dest); | |
1302 } | |
1303 | |
1304 static gboolean file_data_perform_delete(FileData *fd) | |
1305 { | |
1306 return unlink_file(fd->path); | |
1307 } | |
1308 | |
1309 static gboolean file_data_perform_ci(FileData *fd) | |
1310 { | |
1311 FileDataChangeType type = fd->change->type; | |
1312 switch (type) | |
1313 { | |
1314 case FILEDATA_CHANGE_MOVE: | |
1315 return file_data_perform_move(fd); | |
1316 case FILEDATA_CHANGE_COPY: | |
1317 return file_data_perform_copy(fd); | |
1318 case FILEDATA_CHANGE_RENAME: | |
1319 return file_data_perform_move(fd); /* the same as move */ | |
1320 case FILEDATA_CHANGE_DELETE: | |
1321 return file_data_perform_delete(fd); | |
753 | 1322 case FILEDATA_CHANGE_UNSPECIFIED: |
596 | 1323 /* nothing to do here */ |
590 | 1324 break; |
1325 } | |
1326 return TRUE; | |
1327 } | |
1328 | |
1329 | |
1330 | |
1331 gboolean file_data_sc_perform_ci(FileData *fd) | |
1332 { | |
1333 GList *work; | |
1334 gboolean ret = TRUE; | |
1335 FileDataChangeType type = fd->change->type; | |
1336 if (!file_data_sc_check_ci(fd, type)) return FALSE; | |
1337 | |
1338 work = fd->sidecar_files; | |
1339 while (work) | |
1340 { | |
1341 FileData *sfd = work->data; | |
1342 if (!file_data_perform_ci(sfd)) ret = FALSE; | |
1343 work = work->next; | |
1344 } | |
1345 if (!file_data_perform_ci(fd)) ret = FALSE; | |
1346 return ret; | |
1347 } | |
1348 | |
1349 /* | |
1350 * updates FileData structure according to FileDataChangeInfo | |
1351 */ | |
1352 | |
1353 static void file_data_apply_ci(FileData *fd) | |
1354 { | |
1355 FileDataChangeType type = fd->change->type; | |
1356 /* FIXME delete ?*/ | |
773 | 1357 if (type == FILEDATA_CHANGE_MOVE || type == FILEDATA_CHANGE_RENAME) |
590 | 1358 { |
1359 g_free(fd->path); | |
1360 g_hash_table_remove(file_data_pool, fd->original_path); | |
1361 g_free(fd->original_path); | |
1362 file_data_set_path(fd, fd->change->dest); | |
1363 fd->original_path = g_strdup(fd->change->dest); | |
1364 g_hash_table_insert(file_data_pool, fd->original_path, fd); | |
1365 } | |
763
81f9e8dbb4bf
improved infrastructure for tracing changes, optimized vflist_populate_view
nadvornik
parents:
753
diff
changeset
|
1366 file_data_increment_version(fd); |
590 | 1367 } |
1368 | |
596 | 1369 gint file_data_sc_apply_ci(FileData *fd) |
590 | 1370 { |
1371 GList *work; | |
1372 FileDataChangeType type = fd->change->type; | |
1373 if (!file_data_sc_check_ci(fd, type)) return FALSE; | |
1374 | |
1375 work = fd->sidecar_files; | |
1376 while (work) | |
1377 { | |
1378 FileData *sfd = work->data; | |
1379 file_data_apply_ci(sfd); | |
1380 work = work->next; | |
1381 } | |
1382 file_data_apply_ci(fd); | |
1383 return TRUE; | |
1384 } | |
1385 | |
1386 | |
1387 /* | |
1388 * notify other modules about the change described by FileFataChangeInfo | |
1389 */ | |
1390 | |
1391 /* might use file_maint_ functions for now, later it should be changed to a system of callbacks | |
1392 FIXME do we need the ignore_list? It looks like a workaround for ineffective | |
1393 implementation in view_file_list.c */ | |
1394 | |
784
16b3a5c8aedc
new notification system (used only in vflist for now)
nadvornik
parents:
783
diff
changeset
|
1395 |
16b3a5c8aedc
new notification system (used only in vflist for now)
nadvornik
parents:
783
diff
changeset
|
1396 |
16b3a5c8aedc
new notification system (used only in vflist for now)
nadvornik
parents:
783
diff
changeset
|
1397 |
16b3a5c8aedc
new notification system (used only in vflist for now)
nadvornik
parents:
783
diff
changeset
|
1398 typedef struct _NotifyData NotifyData; |
16b3a5c8aedc
new notification system (used only in vflist for now)
nadvornik
parents:
783
diff
changeset
|
1399 |
16b3a5c8aedc
new notification system (used only in vflist for now)
nadvornik
parents:
783
diff
changeset
|
1400 struct _NotifyData { |
16b3a5c8aedc
new notification system (used only in vflist for now)
nadvornik
parents:
783
diff
changeset
|
1401 FileDataNotifyFunc func; |
16b3a5c8aedc
new notification system (used only in vflist for now)
nadvornik
parents:
783
diff
changeset
|
1402 gpointer data; |
16b3a5c8aedc
new notification system (used only in vflist for now)
nadvornik
parents:
783
diff
changeset
|
1403 }; |
16b3a5c8aedc
new notification system (used only in vflist for now)
nadvornik
parents:
783
diff
changeset
|
1404 |
16b3a5c8aedc
new notification system (used only in vflist for now)
nadvornik
parents:
783
diff
changeset
|
1405 static GList *notify_func_list = NULL; |
16b3a5c8aedc
new notification system (used only in vflist for now)
nadvornik
parents:
783
diff
changeset
|
1406 |
16b3a5c8aedc
new notification system (used only in vflist for now)
nadvornik
parents:
783
diff
changeset
|
1407 gint file_data_register_notify_func(FileDataNotifyFunc func, gpointer data) |
16b3a5c8aedc
new notification system (used only in vflist for now)
nadvornik
parents:
783
diff
changeset
|
1408 { |
16b3a5c8aedc
new notification system (used only in vflist for now)
nadvornik
parents:
783
diff
changeset
|
1409 NotifyData *nd = g_new(NotifyData, 1); |
16b3a5c8aedc
new notification system (used only in vflist for now)
nadvornik
parents:
783
diff
changeset
|
1410 nd->func = func; |
16b3a5c8aedc
new notification system (used only in vflist for now)
nadvornik
parents:
783
diff
changeset
|
1411 nd->data = data; |
16b3a5c8aedc
new notification system (used only in vflist for now)
nadvornik
parents:
783
diff
changeset
|
1412 notify_func_list = g_list_prepend(notify_func_list, nd); |
16b3a5c8aedc
new notification system (used only in vflist for now)
nadvornik
parents:
783
diff
changeset
|
1413 DEBUG_1("Notify func registered: %p\n", nd); |
16b3a5c8aedc
new notification system (used only in vflist for now)
nadvornik
parents:
783
diff
changeset
|
1414 return TRUE; |
16b3a5c8aedc
new notification system (used only in vflist for now)
nadvornik
parents:
783
diff
changeset
|
1415 } |
16b3a5c8aedc
new notification system (used only in vflist for now)
nadvornik
parents:
783
diff
changeset
|
1416 |
16b3a5c8aedc
new notification system (used only in vflist for now)
nadvornik
parents:
783
diff
changeset
|
1417 gint file_data_unregister_notify_func(FileDataNotifyFunc func, gpointer data) |
16b3a5c8aedc
new notification system (used only in vflist for now)
nadvornik
parents:
783
diff
changeset
|
1418 { |
16b3a5c8aedc
new notification system (used only in vflist for now)
nadvornik
parents:
783
diff
changeset
|
1419 GList *work = notify_func_list; |
16b3a5c8aedc
new notification system (used only in vflist for now)
nadvornik
parents:
783
diff
changeset
|
1420 |
16b3a5c8aedc
new notification system (used only in vflist for now)
nadvornik
parents:
783
diff
changeset
|
1421 while(work) |
16b3a5c8aedc
new notification system (used only in vflist for now)
nadvornik
parents:
783
diff
changeset
|
1422 { |
16b3a5c8aedc
new notification system (used only in vflist for now)
nadvornik
parents:
783
diff
changeset
|
1423 NotifyData *nd = (NotifyData *)work->data; |
16b3a5c8aedc
new notification system (used only in vflist for now)
nadvornik
parents:
783
diff
changeset
|
1424 if (nd->func == func && nd->data == data) |
16b3a5c8aedc
new notification system (used only in vflist for now)
nadvornik
parents:
783
diff
changeset
|
1425 { |
16b3a5c8aedc
new notification system (used only in vflist for now)
nadvornik
parents:
783
diff
changeset
|
1426 notify_func_list = g_list_delete_link(notify_func_list, work); |
16b3a5c8aedc
new notification system (used only in vflist for now)
nadvornik
parents:
783
diff
changeset
|
1427 g_free(nd); |
16b3a5c8aedc
new notification system (used only in vflist for now)
nadvornik
parents:
783
diff
changeset
|
1428 DEBUG_1("Notify func unregistered: %p\n", nd); |
16b3a5c8aedc
new notification system (used only in vflist for now)
nadvornik
parents:
783
diff
changeset
|
1429 return TRUE; |
16b3a5c8aedc
new notification system (used only in vflist for now)
nadvornik
parents:
783
diff
changeset
|
1430 } |
16b3a5c8aedc
new notification system (used only in vflist for now)
nadvornik
parents:
783
diff
changeset
|
1431 work = work->next; |
16b3a5c8aedc
new notification system (used only in vflist for now)
nadvornik
parents:
783
diff
changeset
|
1432 } |
16b3a5c8aedc
new notification system (used only in vflist for now)
nadvornik
parents:
783
diff
changeset
|
1433 return FALSE; |
16b3a5c8aedc
new notification system (used only in vflist for now)
nadvornik
parents:
783
diff
changeset
|
1434 } |
16b3a5c8aedc
new notification system (used only in vflist for now)
nadvornik
parents:
783
diff
changeset
|
1435 |
16b3a5c8aedc
new notification system (used only in vflist for now)
nadvornik
parents:
783
diff
changeset
|
1436 |
16b3a5c8aedc
new notification system (used only in vflist for now)
nadvornik
parents:
783
diff
changeset
|
1437 void file_data_send_notification(FileData *fd) |
16b3a5c8aedc
new notification system (used only in vflist for now)
nadvornik
parents:
783
diff
changeset
|
1438 { |
16b3a5c8aedc
new notification system (used only in vflist for now)
nadvornik
parents:
783
diff
changeset
|
1439 GList *work = notify_func_list; |
16b3a5c8aedc
new notification system (used only in vflist for now)
nadvornik
parents:
783
diff
changeset
|
1440 while(work) |
16b3a5c8aedc
new notification system (used only in vflist for now)
nadvornik
parents:
783
diff
changeset
|
1441 { |
16b3a5c8aedc
new notification system (used only in vflist for now)
nadvornik
parents:
783
diff
changeset
|
1442 NotifyData *nd = (NotifyData *)work->data; |
16b3a5c8aedc
new notification system (used only in vflist for now)
nadvornik
parents:
783
diff
changeset
|
1443 DEBUG_1("Notify func calling: %p %s\n", nd, fd->path); |
16b3a5c8aedc
new notification system (used only in vflist for now)
nadvornik
parents:
783
diff
changeset
|
1444 nd->func(fd, nd->data); |
16b3a5c8aedc
new notification system (used only in vflist for now)
nadvornik
parents:
783
diff
changeset
|
1445 work = work->next; |
16b3a5c8aedc
new notification system (used only in vflist for now)
nadvornik
parents:
783
diff
changeset
|
1446 } |
16b3a5c8aedc
new notification system (used only in vflist for now)
nadvornik
parents:
783
diff
changeset
|
1447 } |
16b3a5c8aedc
new notification system (used only in vflist for now)
nadvornik
parents:
783
diff
changeset
|
1448 |
590 | 1449 void file_data_sc_send_notification(FileData *fd) |
1450 { | |
1451 } | |
1452 | |
1453 | |
784
16b3a5c8aedc
new notification system (used only in vflist for now)
nadvornik
parents:
783
diff
changeset
|
1454 |
16b3a5c8aedc
new notification system (used only in vflist for now)
nadvornik
parents:
783
diff
changeset
|
1455 |
16b3a5c8aedc
new notification system (used only in vflist for now)
nadvornik
parents:
783
diff
changeset
|
1456 |
16b3a5c8aedc
new notification system (used only in vflist for now)
nadvornik
parents:
783
diff
changeset
|
1457 |
16b3a5c8aedc
new notification system (used only in vflist for now)
nadvornik
parents:
783
diff
changeset
|
1458 |
16b3a5c8aedc
new notification system (used only in vflist for now)
nadvornik
parents:
783
diff
changeset
|
1459 |
16b3a5c8aedc
new notification system (used only in vflist for now)
nadvornik
parents:
783
diff
changeset
|
1460 |