comparison src/filedata.c @ 806:8620e6934cfb

Tidy up: add/remove white lines, minor code changes.
author zas_
date Sun, 08 Jun 2008 23:42:51 +0000
parents 9b676bb76a2e
children 06929cbcd796
comparison
equal deleted inserted replaced
805:5a3fc27147ab 806:8620e6934cfb
222 222
223 static gboolean file_data_check_changed_files_recursive(FileData *fd, struct stat *st) 223 static gboolean file_data_check_changed_files_recursive(FileData *fd, struct stat *st)
224 { 224 {
225 gboolean ret = FALSE; 225 gboolean ret = FALSE;
226 GList *work; 226 GList *work;
227
227 if (fd->size != st->st_size || 228 if (fd->size != st->st_size ||
228 fd->date != st->st_mtime) 229 fd->date != st->st_mtime)
229 { 230 {
230 fd->size = st->st_size; 231 fd->size = st->st_size;
231 fd->date = st->st_mtime; 232 fd->date = st->st_mtime;
260 261
261 static gboolean file_data_check_changed_files(FileData *fd) 262 static gboolean file_data_check_changed_files(FileData *fd)
262 { 263 {
263 gboolean ret = FALSE; 264 gboolean ret = FALSE;
264 struct stat st; 265 struct stat st;
266
265 if (fd->parent) fd = fd->parent; 267 if (fd->parent) fd = fd->parent;
266 268
267 if (!stat_utf8(fd->path, &st)) 269 if (!stat_utf8(fd->path, &st))
268 { 270 {
271 GList *work;
272 FileData *sfd = NULL;
273
269 /* parent is missing, we have to rebuild whole group */ 274 /* parent is missing, we have to rebuild whole group */
270 ret = TRUE; 275 ret = TRUE;
271 fd->size = 0; 276 fd->size = 0;
272 fd->date = 0; 277 fd->date = 0;
273 GList *work = fd->sidecar_files; 278
274 FileData *sfd = NULL; 279 work = fd->sidecar_files;
275 while (work) 280 while (work)
276 { 281 {
277 sfd = work->data; 282 sfd = work->data;
278 work = work->next; 283 work = work->next;
279 284
280 file_data_disconnect_sidecar_file(fd, sfd); 285 file_data_disconnect_sidecar_file(fd, sfd);
281 } 286 }
282 if (sfd) file_data_check_sidecars(sfd); /* this will group the sidecars back together */ 287 if (sfd) file_data_check_sidecars(sfd); /* this will group the sidecars back together */
283 file_data_send_notification(fd, NOTIFY_TYPE_REREAD); 288 file_data_send_notification(fd, NOTIFY_TYPE_REREAD);
284 } 289 }
285 else 290 else
291 {
286 ret |= file_data_check_changed_files_recursive(fd, &st); 292 ret |= file_data_check_changed_files_recursive(fd, &st);
293 }
294
287 return ret; 295 return ret;
288 } 296 }
289 297
290 static FileData *file_data_new(const gchar *path_utf8, struct stat *st, gboolean check_sidecars) 298 static FileData *file_data_new(const gchar *path_utf8, struct stat *st, gboolean check_sidecars)
291 { 299 {
298 306
299 fd = g_hash_table_lookup(file_data_pool, path_utf8); 307 fd = g_hash_table_lookup(file_data_pool, path_utf8);
300 if (fd) 308 if (fd)
301 { 309 {
302 gboolean changed; 310 gboolean changed;
311
303 if (fd->parent) 312 if (fd->parent)
304 changed = file_data_check_changed_files(fd); 313 changed = file_data_check_changed_files(fd);
305 else 314 else
306 changed = file_data_check_changed_files_recursive(fd, st); 315 changed = file_data_check_changed_files_recursive(fd, st);
307 if (changed && check_sidecars && sidecar_file_priority(fd->extension)) 316 if (changed && check_sidecars && sidecar_file_priority(fd->extension))
308 file_data_check_sidecars(fd); 317 file_data_check_sidecars(fd);
309 DEBUG_2("file_data_pool hit: '%s' %s", fd->path, changed ? "(changed)" : ""); 318 DEBUG_2("file_data_pool hit: '%s' %s", fd->path, changed ? "(changed)" : "");
319
310 return file_data_ref(fd); 320 return file_data_ref(fd);
311 } 321 }
312 322
313 fd = g_new0(FileData, 1); 323 fd = g_new0(FileData, 1);
314 324
337 { 347 {
338 int base_len = fd->extension - fd->path; 348 int base_len = fd->extension - fd->path;
339 GString *fname = g_string_new_len(fd->path, base_len); 349 GString *fname = g_string_new_len(fd->path, base_len);
340 FileData *parent_fd = NULL; 350 FileData *parent_fd = NULL;
341 GList *work = sidecar_ext_get_list(); 351 GList *work = sidecar_ext_get_list();
352
342 while (work) 353 while (work)
343 { 354 {
344 /* check for possible sidecar files; 355 /* check for possible sidecar files;
345 the sidecar files created here are referenced only via fd->sidecar_files or fd->parent, 356 the sidecar files created here are referenced only via fd->sidecar_files or fd->parent,
346 they have fd->ref set to 0 and file_data unref must chack and free them all together 357 they have fd->ref set to 0 and file_data unref must chack and free them all together
347 (using fd->ref would cause loops and leaks) 358 (using fd->ref would cause loops and leaks)
348 */ 359 */
349 360
350 FileData *new_fd; 361 FileData *new_fd;
351
352 gchar *ext = work->data; 362 gchar *ext = work->data;
363
353 work = work->next; 364 work = work->next;
354 365
355 if (strcmp(ext, fd->extension) == 0) 366 if (strcmp(ext, fd->extension) == 0)
356 { 367 {
357 new_fd = fd; /* processing the original file */ 368 new_fd = fd; /* processing the original file */
380 391
381 static FileData *file_data_new_local(const gchar *path, struct stat *st, gboolean check_sidecars) 392 static FileData *file_data_new_local(const gchar *path, struct stat *st, gboolean check_sidecars)
382 { 393 {
383 gchar *path_utf8 = path_to_utf8(path); 394 gchar *path_utf8 = path_to_utf8(path);
384 FileData *ret = file_data_new(path_utf8, st, check_sidecars); 395 FileData *ret = file_data_new(path_utf8, st, check_sidecars);
396
385 g_free(path_utf8); 397 g_free(path_utf8);
386 return ret; 398 return ret;
387 } 399 }
388 400
389 FileData *file_data_new_simple(const gchar *path_utf8) 401 FileData *file_data_new_simple(const gchar *path_utf8)
410 422
411 423
412 FileData *file_data_merge_sidecar_files(FileData *target, FileData *source) 424 FileData *file_data_merge_sidecar_files(FileData *target, FileData *source)
413 { 425 {
414 GList *work; 426 GList *work;
427
415 file_data_add_sidecar_file(target, source); 428 file_data_add_sidecar_file(target, source);
416 429
417 work = source->sidecar_files; 430 work = source->sidecar_files;
418 while (work) 431 while (work)
419 { 432 {
424 437
425 g_list_free(source->sidecar_files); 438 g_list_free(source->sidecar_files);
426 source->sidecar_files = NULL; 439 source->sidecar_files = NULL;
427 440
428 target->sidecar_files = filelist_sort(target->sidecar_files, SORT_NAME, TRUE); 441 target->sidecar_files = filelist_sort(target->sidecar_files, SORT_NAME, TRUE);
442
429 return target; 443 return target;
430 } 444 }
431
432 445
433 446
434 FileData *file_data_ref(FileData *fd) 447 FileData *file_data_ref(FileData *fd)
435 { 448 {
436 if (fd == NULL) return NULL; 449 if (fd == NULL) return NULL;
452 g_free(fd->original_path); 465 g_free(fd->original_path);
453 g_free(fd->collate_key_name); 466 g_free(fd->collate_key_name);
454 g_free(fd->collate_key_name_nocase); 467 g_free(fd->collate_key_name_nocase);
455 if (fd->pixbuf) g_object_unref(fd->pixbuf); 468 if (fd->pixbuf) g_object_unref(fd->pixbuf);
456 469
457
458 g_assert(fd->sidecar_files == NULL); /* sidecar files must be freed before calling this */ 470 g_assert(fd->sidecar_files == NULL); /* sidecar files must be freed before calling this */
459 471
460 file_data_change_info_free(NULL, fd); 472 file_data_change_info_free(NULL, fd);
461 g_free(fd); 473 g_free(fd);
462 } 474 }
469 fd->ref--; 481 fd->ref--;
470 DEBUG_2("file_data_unref (%d): '%s'", fd->ref, fd->path); 482 DEBUG_2("file_data_unref (%d): '%s'", fd->ref, fd->path);
471 483
472 if (fd->ref == 0) 484 if (fd->ref == 0)
473 { 485 {
486 GList *work;
474 FileData *parent = fd->parent ? fd->parent : fd; 487 FileData *parent = fd->parent ? fd->parent : fd;
475 488
476 GList *work;
477
478 if (parent->ref > 0) 489 if (parent->ref > 0)
479 return; 490 return;
480 491
481 work = parent->sidecar_files; 492 work = parent->sidecar_files;
482 while (work) 493 while (work)
501 512
502 g_list_free(parent->sidecar_files); 513 g_list_free(parent->sidecar_files);
503 parent->sidecar_files = NULL; 514 parent->sidecar_files = NULL;
504 515
505 file_data_free(parent); 516 file_data_free(parent);
506
507 } 517 }
508 } 518 }
509 519
510 FileData *file_data_disconnect_sidecar_file(FileData *target, FileData *sfd) 520 FileData *file_data_disconnect_sidecar_file(FileData *target, FileData *sfd)
511 { 521 {
515 file_data_increment_version(sfd); /* increments both sfd and target */ 525 file_data_increment_version(sfd); /* increments both sfd and target */
516 526
517 target->sidecar_files = g_list_remove(target->sidecar_files, sfd); 527 target->sidecar_files = g_list_remove(target->sidecar_files, sfd);
518 sfd->parent = NULL; 528 sfd->parent = NULL;
519 529
520 if (sfd->ref == 0) { 530 if (sfd->ref == 0)
531 {
521 file_data_free(sfd); 532 file_data_free(sfd);
522 return NULL; 533 return NULL;
523 } 534 }
524 535
525 return sfd; 536 return sfd;
526 } 537 }
527 538
528 /* compare name without extension */ 539 /* compare name without extension */
537 return strncmp(fd1->name, fd2->name, len1); /* FIXME: utf8 */ 548 return strncmp(fd1->name, fd2->name, len1); /* FIXME: utf8 */
538 } 549 }
539 550
540 gboolean file_data_add_change_info(FileData *fd, FileDataChangeType type, const gchar *src, const gchar *dest) 551 gboolean file_data_add_change_info(FileData *fd, FileDataChangeType type, const gchar *src, const gchar *dest)
541 { 552 {
542
543 FileDataChangeInfo *fdci; 553 FileDataChangeInfo *fdci;
544 554
545 if (fd->change) return FALSE; 555 if (fd->change) return FALSE;
546 556
547 fdci = g_new0(FileDataChangeInfo, 1); 557 fdci = g_new0(FileDataChangeInfo, 1);
548
549 fdci->type = type; 558 fdci->type = type;
550 559
551 if (src) 560 if (src)
552 fdci->source = g_strdup(src); 561 fdci->source = g_strdup(src);
553 else 562 else
555 564
556 if (dest) 565 if (dest)
557 fdci->dest = g_strdup(dest); 566 fdci->dest = g_strdup(dest);
558 567
559 fd->change = fdci; 568 fd->change = fdci;
569
560 return TRUE; 570 return TRUE;
561 } 571 }
562 572
563 void file_data_change_info_free(FileDataChangeInfo *fdci, FileData *fd) 573 void file_data_change_info_free(FileDataChangeInfo *fdci, FileData *fd)
564 { 574 {
591 static gint sidecar_file_priority(const gchar *path) 601 static gint sidecar_file_priority(const gchar *path)
592 { 602 {
593 const char *extension = extension_from_path(path); 603 const char *extension = extension_from_path(path);
594 int i = 1; 604 int i = 1;
595 GList *work; 605 GList *work;
606
596 if (extension == NULL) 607 if (extension == NULL)
597 return 0; 608 return 0;
598 609
599 work = sidecar_ext_get_list(); 610 work = sidecar_ext_get_list();
600 611
601 while (work) { 612 while (work) {
602 gchar *ext = work->data; 613 gchar *ext = work->data;
614
603 work = work->next; 615 work = work->next;
604 if (strcmp(extension, ext) == 0) return i; 616 if (strcmp(extension, ext) == 0) return i;
605 i++; 617 i++;
606 } 618 }
607 return 0; 619 return 0;
699 GList *flist_filtered = NULL; 711 GList *flist_filtered = NULL;
700 712
701 while (work) 713 while (work)
702 { 714 {
703 FileData *fd = work->data; 715 FileData *fd = work->data;
716
704 work = work->next; 717 work = work->next;
705 if (fd->parent) /* remove fd's that are children */ 718 if (fd->parent) /* remove fd's that are children */
706 file_data_unref(fd); 719 file_data_unref(fd);
707 else 720 else
708 flist_filtered = g_list_prepend(flist_filtered, fd); 721 flist_filtered = g_list_prepend(flist_filtered, fd);
709 } 722 }
710 g_list_free(flist); 723 g_list_free(flist);
724
711 return flist_filtered; 725 return flist_filtered;
712 } 726 }
713 727
714 static gint filelist_read_real(FileData *dir_fd, GList **files, GList **dirs, gint follow_symlinks) 728 static gint filelist_read_real(FileData *dir_fd, GList **files, GList **dirs, gint follow_symlinks)
715 { 729 {
883 (!is_dir_list && !filter_name_exists(name)) || 897 (!is_dir_list && !filter_name_exists(name)) ||
884 (is_dir_list && name[0] == '.' && (strcmp(name, GQ_CACHE_LOCAL_THUMB) == 0 || 898 (is_dir_list && name[0] == '.' && (strcmp(name, GQ_CACHE_LOCAL_THUMB) == 0 ||
885 strcmp(name, GQ_CACHE_LOCAL_METADATA) == 0)) ) 899 strcmp(name, GQ_CACHE_LOCAL_METADATA) == 0)) )
886 { 900 {
887 GList *link = work; 901 GList *link = work;
888 work = work->next; 902
889 list = g_list_remove_link(list, link); 903 list = g_list_remove_link(list, link);
890 file_data_unref(fd); 904 file_data_unref(fd);
891 g_list_free(link); 905 g_list_free(link);
892 } 906 }
893 else 907
894 { 908 work = work->next;
895 work = work->next;
896 }
897 } 909 }
898 910
899 return list; 911 return list;
900 } 912 }
901 913
975 if (!value == !(fd->marks & (1 << n))) return; 987 if (!value == !(fd->marks & (1 << n))) return;
976 988
977 fd->marks = fd->marks ^ (1 << n); 989 fd->marks = fd->marks ^ (1 << n);
978 file_data_increment_version(fd); 990 file_data_increment_version(fd);
979 file_data_send_notification(fd, NOTIFY_TYPE_INTERNAL); 991 file_data_send_notification(fd, NOTIFY_TYPE_INTERNAL);
980
981 } 992 }
982 993
983 gint file_data_get_user_orientation(FileData *fd) 994 gint file_data_get_user_orientation(FileData *fd)
984 { 995 {
985 return fd->user_orientation; 996 return fd->user_orientation;
1010 1021
1011 work = fd->sidecar_files; 1022 work = fd->sidecar_files;
1012 while (work) 1023 while (work)
1013 { 1024 {
1014 FileData *sfd = work->data; 1025 FileData *sfd = work->data;
1026
1015 result = g_string_append(result, "+ "); 1027 result = g_string_append(result, "+ ");
1016 result = g_string_append(result, sfd->extension); 1028 result = g_string_append(result, sfd->extension);
1017 work = work->next; 1029 work = work->next;
1018 if (work) result = g_string_append_c(result, ' '); 1030 if (work) result = g_string_append_c(result, ' ');
1019 } 1031 }
1054 UPDATE - file size, date or grouping has been changed 1066 UPDATE - file size, date or grouping has been changed
1055 */ 1067 */
1056 1068
1057 gboolean file_data_add_ci(FileData *fd, FileDataChangeType type, const gchar *src, const gchar *dest) 1069 gboolean file_data_add_ci(FileData *fd, FileDataChangeType type, const gchar *src, const gchar *dest)
1058 { 1070 {
1059
1060 FileDataChangeInfo *fdci; 1071 FileDataChangeInfo *fdci;
1061 1072
1062 if (fd->change) return FALSE; 1073 if (fd->change) return FALSE;
1063 1074
1064 fdci = g_new0(FileDataChangeInfo, 1); 1075 fdci = g_new0(FileDataChangeInfo, 1);
1095 1106
1096 1107
1097 static gboolean file_data_sc_add_ci(FileData *fd, FileDataChangeType type) 1108 static gboolean file_data_sc_add_ci(FileData *fd, FileDataChangeType type)
1098 { 1109 {
1099 GList *work; 1110 GList *work;
1111
1100 if (fd->parent) fd = fd->parent; 1112 if (fd->parent) fd = fd->parent;
1101 1113
1102 if (fd->change) return FALSE; 1114 if (fd->change) return FALSE;
1115
1103 work = fd->sidecar_files; 1116 work = fd->sidecar_files;
1104 while (work) 1117 while (work)
1105 { 1118 {
1106 FileData *sfd = work->data; 1119 FileData *sfd = work->data;
1120
1107 if (sfd->change) return FALSE; 1121 if (sfd->change) return FALSE;
1108 work = work->next; 1122 work = work->next;
1109 } 1123 }
1110 1124
1111 file_data_add_ci(fd, type, NULL, NULL); 1125 file_data_add_ci(fd, type, NULL, NULL);
1112 1126
1113 work = fd->sidecar_files; 1127 work = fd->sidecar_files;
1114 while (work) 1128 while (work)
1115 { 1129 {
1116 FileData *sfd = work->data; 1130 FileData *sfd = work->data;
1131
1117 file_data_add_ci(sfd, type, NULL, NULL); 1132 file_data_add_ci(sfd, type, NULL, NULL);
1118 work = work->next; 1133 work = work->next;
1119 } 1134 }
1120 1135
1121 return TRUE; 1136 return TRUE;
1122 } 1137 }
1123 1138
1124 static gboolean file_data_sc_check_ci(FileData *fd, FileDataChangeType type) 1139 static gboolean file_data_sc_check_ci(FileData *fd, FileDataChangeType type)
1125 { 1140 {
1126 GList *work; 1141 GList *work;
1142
1127 if (fd->parent) fd = fd->parent; 1143 if (fd->parent) fd = fd->parent;
1128 1144
1129 if (!fd->change) return FALSE; 1145 if (!fd->change || fd->change->type != type) return FALSE;
1130 if (fd->change->type != type) return FALSE; 1146
1131 work = fd->sidecar_files; 1147 work = fd->sidecar_files;
1132 while (work) 1148 while (work)
1133 { 1149 {
1134 FileData *sfd = work->data; 1150 FileData *sfd = work->data;
1135 if (!sfd->change) return FALSE; 1151
1136 if (sfd->change->type != type) return FALSE; 1152 if (!sfd->change || sfd->change->type != type) return FALSE;
1137 work = work->next; 1153 work = work->next;
1138 } 1154 }
1155
1139 return TRUE; 1156 return TRUE;
1140 } 1157 }
1141 1158
1142 1159
1143 gboolean file_data_sc_add_ci_copy(FileData *fd, const gchar *dest_path) 1160 gboolean file_data_sc_add_ci_copy(FileData *fd, const gchar *dest_path)
1174 } 1191 }
1175 1192
1176 void file_data_sc_free_ci(FileData *fd) 1193 void file_data_sc_free_ci(FileData *fd)
1177 { 1194 {
1178 GList *work; 1195 GList *work;
1196
1179 if (fd->parent) fd = fd->parent; 1197 if (fd->parent) fd = fd->parent;
1180 1198
1181 file_data_free_ci(fd); 1199 file_data_free_ci(fd);
1182 1200
1183 work = fd->sidecar_files; 1201 work = fd->sidecar_files;
1184 while (work) 1202 while (work)
1185 { 1203 {
1186 FileData *sfd = work->data; 1204 FileData *sfd = work->data;
1205
1187 file_data_free_ci(sfd); 1206 file_data_free_ci(sfd);
1188 work = work->next; 1207 work = work->next;
1189 } 1208 }
1190 } 1209 }
1191 1210
1192 gboolean file_data_sc_add_ci_delete_list(GList *fd_list) 1211 gboolean file_data_sc_add_ci_delete_list(GList *fd_list)
1193 { 1212 {
1194 GList *work; 1213 GList *work;
1195 gboolean ret = TRUE; 1214 gboolean ret = TRUE;
1215
1196 work = fd_list; 1216 work = fd_list;
1197 while (work) 1217 while (work)
1198 { 1218 {
1199 FileData *fd = work->data; 1219 FileData *fd = work->data;
1220
1200 if (!file_data_sc_add_ci_delete(fd)) ret = FALSE; 1221 if (!file_data_sc_add_ci_delete(fd)) ret = FALSE;
1201 work = work->next; 1222 work = work->next;
1202 } 1223 }
1224
1203 return ret; 1225 return ret;
1204 } 1226 }
1205 1227
1206 gboolean file_data_sc_add_ci_copy_list(GList *fd_list, const gchar *dest) 1228 gboolean file_data_sc_add_ci_copy_list(GList *fd_list, const gchar *dest)
1207 { 1229 {
1208 GList *work; 1230 GList *work;
1209 gboolean ret = TRUE; 1231 gboolean ret = TRUE;
1232
1210 work = fd_list; 1233 work = fd_list;
1211 while (work) 1234 while (work)
1212 { 1235 {
1213 FileData *fd = work->data; 1236 FileData *fd = work->data;
1237
1214 if (!file_data_sc_add_ci_copy(fd, dest)) ret = FALSE; 1238 if (!file_data_sc_add_ci_copy(fd, dest)) ret = FALSE;
1215 work = work->next; 1239 work = work->next;
1216 } 1240 }
1241
1217 return ret; 1242 return ret;
1218 } 1243 }
1219 1244
1220 gboolean file_data_sc_add_ci_move_list(GList *fd_list, const gchar *dest) 1245 gboolean file_data_sc_add_ci_move_list(GList *fd_list, const gchar *dest)
1221 { 1246 {
1222 GList *work; 1247 GList *work;
1223 gboolean ret = TRUE; 1248 gboolean ret = TRUE;
1249
1224 work = fd_list; 1250 work = fd_list;
1225 while (work) 1251 while (work)
1226 { 1252 {
1227 FileData *fd = work->data; 1253 FileData *fd = work->data;
1254
1228 if (!file_data_sc_add_ci_move(fd, dest)) ret = FALSE; 1255 if (!file_data_sc_add_ci_move(fd, dest)) ret = FALSE;
1229 work = work->next; 1256 work = work->next;
1230 } 1257 }
1258
1231 return ret; 1259 return ret;
1232 } 1260 }
1233 1261
1234 gboolean file_data_sc_add_ci_rename_list(GList *fd_list, const gchar *dest) 1262 gboolean file_data_sc_add_ci_rename_list(GList *fd_list, const gchar *dest)
1235 { 1263 {
1236 GList *work; 1264 GList *work;
1237 gboolean ret = TRUE; 1265 gboolean ret = TRUE;
1266
1238 work = fd_list; 1267 work = fd_list;
1239 while (work) 1268 while (work)
1240 { 1269 {
1241 FileData *fd = work->data; 1270 FileData *fd = work->data;
1271
1242 if (!file_data_sc_add_ci_rename(fd, dest)) ret = FALSE; 1272 if (!file_data_sc_add_ci_rename(fd, dest)) ret = FALSE;
1243 work = work->next; 1273 work = work->next;
1244 } 1274 }
1275
1245 return ret; 1276 return ret;
1246 } 1277 }
1247 1278
1248 gboolean file_data_sc_add_ci_unspecified_list(GList *fd_list, const gchar *dest) 1279 gboolean file_data_sc_add_ci_unspecified_list(GList *fd_list, const gchar *dest)
1249 { 1280 {
1250 GList *work; 1281 GList *work;
1251 gboolean ret = TRUE; 1282 gboolean ret = TRUE;
1283
1252 work = fd_list; 1284 work = fd_list;
1253 while (work) 1285 while (work)
1254 { 1286 {
1255 FileData *fd = work->data; 1287 FileData *fd = work->data;
1288
1256 if (!file_data_sc_add_ci_unspecified(fd, dest)) ret = FALSE; 1289 if (!file_data_sc_add_ci_unspecified(fd, dest)) ret = FALSE;
1257 work = work->next; 1290 work = work->next;
1258 } 1291 }
1292
1259 return ret; 1293 return ret;
1260 } 1294 }
1261 1295
1262 void file_data_sc_free_ci_list(GList *fd_list) 1296 void file_data_sc_free_ci_list(GList *fd_list)
1263 { 1297 {
1264 GList *work; 1298 GList *work;
1299
1265 work = fd_list; 1300 work = fd_list;
1266 while (work) 1301 while (work)
1267 { 1302 {
1268 FileData *fd = work->data; 1303 FileData *fd = work->data;
1304
1269 file_data_sc_free_ci(fd); 1305 file_data_sc_free_ci(fd);
1270 work = work->next; 1306 work = work->next;
1271 } 1307 }
1272 } 1308 }
1273 1309
1284 1320
1285 static void file_data_update_ci_dest_preserve_ext(FileData *fd, const gchar *dest_path) 1321 static void file_data_update_ci_dest_preserve_ext(FileData *fd, const gchar *dest_path)
1286 { 1322 {
1287 const char *extension = extension_from_path(fd->change->source); 1323 const char *extension = extension_from_path(fd->change->source);
1288 gchar *base = remove_extension_from_path(dest_path); 1324 gchar *base = remove_extension_from_path(dest_path);
1325
1289 g_free(fd->change->dest); 1326 g_free(fd->change->dest);
1290 fd->change->dest = g_strdup_printf("%s%s", base, extension); 1327 fd->change->dest = g_strdup_printf("%s%s", base, extension);
1328
1291 g_free(base); 1329 g_free(base);
1292 } 1330 }
1293 1331
1294 static void file_data_sc_update_ci(FileData *fd, const gchar *dest_path) 1332 static void file_data_sc_update_ci(FileData *fd, const gchar *dest_path)
1295 { 1333 {
1296 GList *work; 1334 GList *work;
1297 gchar *dest_path_full = NULL; 1335 gchar *dest_path_full = NULL;
1336
1298 if (fd->parent) fd = fd->parent; 1337 if (fd->parent) fd = fd->parent;
1299 1338
1300 if (!dest_path) dest_path = fd->path; 1339 if (!dest_path) dest_path = fd->path;
1301 1340
1302 if (!strchr(dest_path, G_DIR_SEPARATOR)) /* we got only filename, not a full path */ 1341 if (!strchr(dest_path, G_DIR_SEPARATOR)) /* we got only filename, not a full path */
1303 { 1342 {
1304 gchar *dir = remove_level_from_path(fd->path); 1343 gchar *dir = remove_level_from_path(fd->path);
1344
1305 dest_path_full = g_build_filename(dir, dest_path, NULL); 1345 dest_path_full = g_build_filename(dir, dest_path, NULL);
1306 g_free(dir); 1346 g_free(dir);
1307 dest_path = dest_path_full; 1347 dest_path = dest_path_full;
1308 } 1348 }
1309 1349
1310 if (isdir(dest_path)) 1350 if (isdir(dest_path))
1311 { 1351 {
1312 dest_path_full = g_build_filename(dest_path, fd->name, NULL); 1352 dest_path_full = g_build_filename(dest_path, fd->name, NULL);
1313 dest_path = dest_path_full; 1353 dest_path = dest_path_full;
1314 } 1354 }
1315 1355
1316
1317 file_data_update_ci_dest(fd, dest_path); 1356 file_data_update_ci_dest(fd, dest_path);
1357
1318 work = fd->sidecar_files; 1358 work = fd->sidecar_files;
1319 while (work) 1359 while (work)
1320 { 1360 {
1321 FileData *sfd = work->data; 1361 FileData *sfd = work->data;
1362
1322 file_data_update_ci_dest_preserve_ext(sfd, dest_path); 1363 file_data_update_ci_dest_preserve_ext(sfd, dest_path);
1323 work = work->next; 1364 work = work->next;
1324 } 1365 }
1366
1325 g_free(dest_path_full); 1367 g_free(dest_path_full);
1326 } 1368 }
1327 1369
1328 gint file_data_sc_update_ci_copy(FileData *fd, const gchar *dest_path) 1370 gint file_data_sc_update_ci_copy(FileData *fd, const gchar *dest_path)
1329 { 1371 {
1356 1398
1357 gboolean file_data_sc_update_ci_move_list(GList *fd_list, const gchar *dest) 1399 gboolean file_data_sc_update_ci_move_list(GList *fd_list, const gchar *dest)
1358 { 1400 {
1359 GList *work; 1401 GList *work;
1360 gboolean ret = TRUE; 1402 gboolean ret = TRUE;
1403
1361 work = fd_list; 1404 work = fd_list;
1362 while (work) 1405 while (work)
1363 { 1406 {
1364 FileData *fd = work->data; 1407 FileData *fd = work->data;
1408
1365 if (!file_data_sc_update_ci_move(fd, dest)) ret = FALSE; 1409 if (!file_data_sc_update_ci_move(fd, dest)) ret = FALSE;
1366 work = work->next; 1410 work = work->next;
1367 } 1411 }
1412
1368 return ret; 1413 return ret;
1369 } 1414 }
1370 1415
1371 gboolean file_data_sc_update_ci_copy_list(GList *fd_list, const gchar *dest) 1416 gboolean file_data_sc_update_ci_copy_list(GList *fd_list, const gchar *dest)
1372 { 1417 {
1373 GList *work; 1418 GList *work;
1374 gboolean ret = TRUE; 1419 gboolean ret = TRUE;
1420
1375 work = fd_list; 1421 work = fd_list;
1376 while (work) 1422 while (work)
1377 { 1423 {
1378 FileData *fd = work->data; 1424 FileData *fd = work->data;
1425
1379 if (!file_data_sc_update_ci_copy(fd, dest)) ret = FALSE; 1426 if (!file_data_sc_update_ci_copy(fd, dest)) ret = FALSE;
1380 work = work->next; 1427 work = work->next;
1381 } 1428 }
1429
1382 return ret; 1430 return ret;
1383 } 1431 }
1384 1432
1385 gboolean file_data_sc_update_ci_unspecified_list(GList *fd_list, const gchar *dest) 1433 gboolean file_data_sc_update_ci_unspecified_list(GList *fd_list, const gchar *dest)
1386 { 1434 {
1387 GList *work; 1435 GList *work;
1388 gboolean ret = TRUE; 1436 gboolean ret = TRUE;
1437
1389 work = fd_list; 1438 work = fd_list;
1390 while (work) 1439 while (work)
1391 { 1440 {
1392 FileData *fd = work->data; 1441 FileData *fd = work->data;
1442
1393 if (!file_data_sc_update_ci_unspecified(fd, dest)) ret = FALSE; 1443 if (!file_data_sc_update_ci_unspecified(fd, dest)) ret = FALSE;
1394 work = work->next; 1444 work = work->next;
1395 } 1445 }
1446
1396 return ret; 1447 return ret;
1397 } 1448 }
1398 1449
1399 1450
1400 /* 1451 /*
1459 gboolean file_data_sc_perform_ci(FileData *fd) 1510 gboolean file_data_sc_perform_ci(FileData *fd)
1460 { 1511 {
1461 GList *work; 1512 GList *work;
1462 gboolean ret = TRUE; 1513 gboolean ret = TRUE;
1463 FileDataChangeType type = fd->change->type; 1514 FileDataChangeType type = fd->change->type;
1515
1464 if (!file_data_sc_check_ci(fd, type)) return FALSE; 1516 if (!file_data_sc_check_ci(fd, type)) return FALSE;
1465 1517
1466 work = fd->sidecar_files; 1518 work = fd->sidecar_files;
1467 while (work) 1519 while (work)
1468 { 1520 {
1469 FileData *sfd = work->data; 1521 FileData *sfd = work->data;
1522
1470 if (!file_data_perform_ci(sfd)) ret = FALSE; 1523 if (!file_data_perform_ci(sfd)) ret = FALSE;
1471 work = work->next; 1524 work = work->next;
1472 } 1525 }
1526
1473 if (!file_data_perform_ci(fd)) ret = FALSE; 1527 if (!file_data_perform_ci(fd)) ret = FALSE;
1528
1474 return ret; 1529 return ret;
1475 } 1530 }
1476 1531
1477 /* 1532 /*
1478 * updates FileData structure according to FileDataChangeInfo 1533 * updates FileData structure according to FileDataChangeInfo
1479 */ 1534 */
1480 1535
1481 static void file_data_apply_ci(FileData *fd) 1536 static void file_data_apply_ci(FileData *fd)
1482 { 1537 {
1483 FileDataChangeType type = fd->change->type; 1538 FileDataChangeType type = fd->change->type;
1539
1484 /* FIXME delete ?*/ 1540 /* FIXME delete ?*/
1485 if (type == FILEDATA_CHANGE_MOVE || type == FILEDATA_CHANGE_RENAME) 1541 if (type == FILEDATA_CHANGE_MOVE || type == FILEDATA_CHANGE_RENAME)
1486 { 1542 {
1487 file_data_set_path(fd, fd->change->dest); 1543 file_data_set_path(fd, fd->change->dest);
1488 } 1544 }
1492 1548
1493 gint file_data_sc_apply_ci(FileData *fd) 1549 gint file_data_sc_apply_ci(FileData *fd)
1494 { 1550 {
1495 GList *work; 1551 GList *work;
1496 FileDataChangeType type = fd->change->type; 1552 FileDataChangeType type = fd->change->type;
1553
1497 if (!file_data_sc_check_ci(fd, type)) return FALSE; 1554 if (!file_data_sc_check_ci(fd, type)) return FALSE;
1498 1555
1499 work = fd->sidecar_files; 1556 work = fd->sidecar_files;
1500 while (work) 1557 while (work)
1501 { 1558 {
1502 FileData *sfd = work->data; 1559 FileData *sfd = work->data;
1560
1503 file_data_apply_ci(sfd); 1561 file_data_apply_ci(sfd);
1504 work = work->next; 1562 work = work->next;
1505 } 1563 }
1564
1506 file_data_apply_ci(fd); 1565 file_data_apply_ci(fd);
1566
1507 return TRUE; 1567 return TRUE;
1508 } 1568 }
1509 1569
1510 1570
1511 /* 1571 /*
1531 1591
1532 static gint file_data_notify_sort(gconstpointer a, gconstpointer b) 1592 static gint file_data_notify_sort(gconstpointer a, gconstpointer b)
1533 { 1593 {
1534 NotifyData *nda = (NotifyData *)a; 1594 NotifyData *nda = (NotifyData *)a;
1535 NotifyData *ndb = (NotifyData *)b; 1595 NotifyData *ndb = (NotifyData *)b;
1596
1536 if (nda->priority < ndb->priority) return -1; 1597 if (nda->priority < ndb->priority) return -1;
1537 if (nda->priority > ndb->priority) return 1; 1598 if (nda->priority > ndb->priority) return 1;
1538 return 0; 1599 return 0;
1539 } 1600 }
1540 1601
1541 gint file_data_register_notify_func(FileDataNotifyFunc func, gpointer data, NotifyPriority priority) 1602 gint file_data_register_notify_func(FileDataNotifyFunc func, gpointer data, NotifyPriority priority)
1542 { 1603 {
1543 NotifyData *nd = g_new(NotifyData, 1); 1604 NotifyData *nd;
1605
1606 nd = g_new(NotifyData, 1);
1544 nd->func = func; 1607 nd->func = func;
1545 nd->data = data; 1608 nd->data = data;
1546 nd->priority = priority; 1609 nd->priority = priority;
1610
1547 notify_func_list = g_list_insert_sorted(notify_func_list, nd, file_data_notify_sort); 1611 notify_func_list = g_list_insert_sorted(notify_func_list, nd, file_data_notify_sort);
1548 DEBUG_1("Notify func registered: %p", nd); 1612 DEBUG_1("Notify func registered: %p", nd);
1613
1549 return TRUE; 1614 return TRUE;
1550 } 1615 }
1551 1616
1552 gint file_data_unregister_notify_func(FileDataNotifyFunc func, gpointer data) 1617 gint file_data_unregister_notify_func(FileDataNotifyFunc func, gpointer data)
1553 { 1618 {
1554 GList *work = notify_func_list; 1619 GList *work = notify_func_list;
1555 1620
1556 while(work) 1621 while (work)
1557 { 1622 {
1558 NotifyData *nd = (NotifyData *)work->data; 1623 NotifyData *nd = (NotifyData *)work->data;
1624
1559 if (nd->func == func && nd->data == data) 1625 if (nd->func == func && nd->data == data)
1560 { 1626 {
1561 notify_func_list = g_list_delete_link(notify_func_list, work); 1627 notify_func_list = g_list_delete_link(notify_func_list, work);
1562 g_free(nd); 1628 g_free(nd);
1563 DEBUG_1("Notify func unregistered: %p", nd); 1629 DEBUG_1("Notify func unregistered: %p", nd);
1564 return TRUE; 1630 return TRUE;
1565 } 1631 }
1566 work = work->next; 1632 work = work->next;
1567 } 1633 }
1634
1568 return FALSE; 1635 return FALSE;
1569 } 1636 }
1570 1637
1571 1638
1572 void file_data_send_notification(FileData *fd, NotifyType type) 1639 void file_data_send_notification(FileData *fd, NotifyType type)
1573 { 1640 {
1574 GList *work = notify_func_list; 1641 GList *work = notify_func_list;
1575 while(work) 1642
1643 while (work)
1576 { 1644 {
1577 NotifyData *nd = (NotifyData *)work->data; 1645 NotifyData *nd = (NotifyData *)work->data;
1646
1578 DEBUG_1("Notify func calling: %p %s", nd, fd->path); 1647 DEBUG_1("Notify func calling: %p %s", nd, fd->path);
1579 nd->func(fd, type, nd->data); 1648 nd->func(fd, type, nd->data);
1580 work = work->next; 1649 work = work->next;
1581 } 1650 }
1582 } 1651 }
1617 1686
1618 if (realtime_monitor_id == -1) 1687 if (realtime_monitor_id == -1)
1619 { 1688 {
1620 realtime_monitor_id = g_timeout_add(5000, realtime_monitor_cb, NULL); 1689 realtime_monitor_id = g_timeout_add(5000, realtime_monitor_cb, NULL);
1621 } 1690 }
1691
1622 return TRUE; 1692 return TRUE;
1623 } 1693 }
1624 1694
1625 gint file_data_unregister_real_time_monitor(FileData *fd) 1695 gint file_data_unregister_real_time_monitor(FileData *fd)
1626 { 1696 {
1627 gint count; 1697 gint count;
1698
1628 g_assert(file_data_monitor_pool); 1699 g_assert(file_data_monitor_pool);
1629 1700
1630 count = GPOINTER_TO_INT(g_hash_table_lookup(file_data_monitor_pool, fd)); 1701 count = GPOINTER_TO_INT(g_hash_table_lookup(file_data_monitor_pool, fd));
1631 1702
1632 DEBUG_1("Unregister realtime %d %s", count, fd->path); 1703 DEBUG_1("Unregister realtime %d %s", count, fd->path);
1646 { 1717 {
1647 g_source_remove(realtime_monitor_id); 1718 g_source_remove(realtime_monitor_id);
1648 realtime_monitor_id = -1; 1719 realtime_monitor_id = -1;
1649 return FALSE; 1720 return FALSE;
1650 } 1721 }
1722
1651 return TRUE; 1723 return TRUE;
1652 } 1724 }
1653
1654
1655
1656
1657
1658
1659