comparison src/filedata.c @ 1422:91bed0d66cf2

gint -> gboolean and tidy up.
author zas_
date Thu, 12 Mar 2009 22:35:45 +0000
parents fe4da037be21
children 6933974f0885
comparison
equal deleted inserted replaced
1421:130054d9dd8a 1422:91bed0d66cf2
220 return; 220 return;
221 } 221 }
222 222
223 fd->extension = extension_from_path(fd->path); 223 fd->extension = extension_from_path(fd->path);
224 if (fd->extension == NULL) 224 if (fd->extension == NULL)
225 {
225 fd->extension = fd->name + strlen(fd->name); 226 fd->extension = fd->name + strlen(fd->name);
227 }
226 228
227 file_data_set_collate_keys(fd); 229 file_data_set_collate_keys(fd);
228 } 230 }
229 231
230 static gboolean file_data_check_changed_files_recursive(FileData *fd, struct stat *st) 232 static gboolean file_data_check_changed_files_recursive(FileData *fd, struct stat *st)
529 g_assert(fd->magick == 0x12345678); 531 g_assert(fd->magick == 0x12345678);
530 532
531 fd->ref--; 533 fd->ref--;
532 #ifdef DEBUG_FILEDATA 534 #ifdef DEBUG_FILEDATA
533 DEBUG_2("file_data_unref (%d): '%s' @ %s:%d", fd->ref, fd->path, file, line); 535 DEBUG_2("file_data_unref (%d): '%s' @ %s:%d", fd->ref, fd->path, file, line);
534
535 #else 536 #else
536 DEBUG_2("file_data_unref (%d): '%s'", fd->ref, fd->path); 537 DEBUG_2("file_data_unref (%d): '%s'", fd->ref, fd->path);
537 #endif 538 #endif
538 if (fd->ref == 0) 539 if (fd->ref == 0)
539 { 540 {
540 GList *work; 541 GList *work;
541 FileData *parent = fd->parent ? fd->parent : fd; 542 FileData *parent = fd->parent ? fd->parent : fd;
542 543
543 if (parent->ref > 0) 544 if (parent->ref > 0) return;
544 return;
545 545
546 work = parent->sidecar_files; 546 work = parent->sidecar_files;
547 while (work) 547 while (work)
548 { 548 {
549 FileData *sfd = work->data; 549 FileData *sfd = work->data;
550 if (sfd->ref > 0) 550 if (sfd->ref > 0) return;
551 return;
552 work = work->next; 551 work = work->next;
553 } 552 }
554 553
555 /* none of parent/children is referenced, we can free everything */ 554 /* none of parent/children is referenced, we can free everything */
556 555
641 return strncmp(fd1->name, fd2->name, len1); /* FIXME: utf8 */ 640 return strncmp(fd1->name, fd2->name, len1); /* FIXME: utf8 */
642 } 641 }
643 642
644 void file_data_change_info_free(FileDataChangeInfo *fdci, FileData *fd) 643 void file_data_change_info_free(FileDataChangeInfo *fdci, FileData *fd)
645 { 644 {
646 if (!fdci && fd) 645 if (!fdci && fd) fdci = fd->change;
647 fdci = fd->change; 646
648 647 if (!fdci) return;
649 if (!fdci)
650 return;
651 648
652 g_free(fdci->source); 649 g_free(fdci->source);
653 g_free(fdci->dest); 650 g_free(fdci->dest);
654 651
655 g_free(fdci); 652 g_free(fdci);
656 653
657 if (fd) 654 if (fd) fd->change = NULL;
658 fd->change = NULL;
659 } 655 }
660 656
661 static gboolean file_data_can_write_directly(FileData *fd) 657 static gboolean file_data_can_write_directly(FileData *fd)
662 { 658 {
663 return filter_name_is_writable(fd->extension); 659 return filter_name_is_writable(fd->extension);
670 666
671 gchar *file_data_get_sidecar_path(FileData *fd, gboolean existing_only) 667 gchar *file_data_get_sidecar_path(FileData *fd, gboolean existing_only)
672 { 668 {
673 gchar *sidecar_path = NULL; 669 gchar *sidecar_path = NULL;
674 GList *work; 670 GList *work;
671
675 if (!file_data_can_write_sidecar(fd)) return NULL; 672 if (!file_data_can_write_sidecar(fd)) return NULL;
676 673
677 work = fd->parent ? fd->parent->sidecar_files : fd->sidecar_files; 674 work = fd->parent ? fd->parent->sidecar_files : fd->sidecar_files;
678 while (work) 675 while (work)
679 { 676 {
732 * load file list 729 * load file list
733 *----------------------------------------------------------------------------- 730 *-----------------------------------------------------------------------------
734 */ 731 */
735 732
736 static SortType filelist_sort_method = SORT_NONE; 733 static SortType filelist_sort_method = SORT_NONE;
737 static gint filelist_sort_ascend = TRUE; 734 static gboolean filelist_sort_ascend = TRUE;
738 735
739 736
740 gint filelist_sort_compare_filedata(FileData *fa, FileData *fb) 737 gint filelist_sort_compare_filedata(FileData *fa, FileData *fb)
741 { 738 {
742 if (!filelist_sort_ascend) 739 if (!filelist_sort_ascend)
773 return strcmp(fa->collate_key_name, fb->collate_key_name); 770 return strcmp(fa->collate_key_name, fb->collate_key_name);
774 else 771 else
775 return strcmp(fa->collate_key_name_nocase, fb->collate_key_name_nocase); 772 return strcmp(fa->collate_key_name_nocase, fb->collate_key_name_nocase);
776 } 773 }
777 774
778 gint filelist_sort_compare_filedata_full(FileData *fa, FileData *fb, SortType method, gint ascend) 775 gint filelist_sort_compare_filedata_full(FileData *fa, FileData *fb, SortType method, gboolean ascend)
779 { 776 {
780 filelist_sort_method = method; 777 filelist_sort_method = method;
781 filelist_sort_ascend = ascend; 778 filelist_sort_ascend = ascend;
782 return filelist_sort_compare_filedata(fa, fb); 779 return filelist_sort_compare_filedata(fa, fb);
783 } 780 }
785 static gint filelist_sort_file_cb(gpointer a, gpointer b) 782 static gint filelist_sort_file_cb(gpointer a, gpointer b)
786 { 783 {
787 return filelist_sort_compare_filedata(a, b); 784 return filelist_sort_compare_filedata(a, b);
788 } 785 }
789 786
790 GList *filelist_sort_full(GList *list, SortType method, gint ascend, GCompareFunc cb) 787 GList *filelist_sort_full(GList *list, SortType method, gboolean ascend, GCompareFunc cb)
791 { 788 {
792 filelist_sort_method = method; 789 filelist_sort_method = method;
793 filelist_sort_ascend = ascend; 790 filelist_sort_ascend = ascend;
794 return g_list_sort(list, cb); 791 return g_list_sort(list, cb);
795 } 792 }
796 793
797 GList *filelist_insert_sort_full(GList *list, gpointer data, SortType method, gint ascend, GCompareFunc cb) 794 GList *filelist_insert_sort_full(GList *list, gpointer data, SortType method, gboolean ascend, GCompareFunc cb)
798 { 795 {
799 filelist_sort_method = method; 796 filelist_sort_method = method;
800 filelist_sort_ascend = ascend; 797 filelist_sort_ascend = ascend;
801 return g_list_insert_sorted(list, data, cb); 798 return g_list_insert_sorted(list, data, cb);
802 } 799 }
803 800
804 GList *filelist_sort(GList *list, SortType method, gint ascend) 801 GList *filelist_sort(GList *list, SortType method, gboolean ascend)
805 { 802 {
806 return filelist_sort_full(list, method, ascend, (GCompareFunc) filelist_sort_file_cb); 803 return filelist_sort_full(list, method, ascend, (GCompareFunc) filelist_sort_file_cb);
807 } 804 }
808 805
809 GList *filelist_insert_sort(GList *list, FileData *fd, SortType method, gint ascend) 806 GList *filelist_insert_sort(GList *list, FileData *fd, SortType method, gboolean ascend)
810 { 807 {
811 return filelist_insert_sort_full(list, fd, method, ascend, (GCompareFunc) filelist_sort_file_cb); 808 return filelist_insert_sort_full(list, fd, method, ascend, (GCompareFunc) filelist_sort_file_cb);
812 } 809 }
813 810
814 811
830 g_list_free(flist); 827 g_list_free(flist);
831 828
832 return flist_filtered; 829 return flist_filtered;
833 } 830 }
834 831
835 static gint filelist_read_real(FileData *dir_fd, GList **files, GList **dirs, gint follow_symlinks) 832 static gboolean filelist_read_real(FileData *dir_fd, GList **files, GList **dirs, gboolean follow_symlinks)
836 { 833 {
837 DIR *dp; 834 DIR *dp;
838 struct dirent *dir; 835 struct dirent *dir;
839 gchar *pathl; 836 gchar *pathl;
840 GList *dlist = NULL; 837 GList *dlist = NULL;
904 if (files) *files = filelist_filter_out_sidecars(flist); 901 if (files) *files = filelist_filter_out_sidecars(flist);
905 902
906 return TRUE; 903 return TRUE;
907 } 904 }
908 905
909 gint filelist_read(FileData *dir_fd, GList **files, GList **dirs) 906 gboolean filelist_read(FileData *dir_fd, GList **files, GList **dirs)
910 { 907 {
911 return filelist_read_real(dir_fd, files, dirs, TRUE); 908 return filelist_read_real(dir_fd, files, dirs, TRUE);
912 } 909 }
913 910
914 gint filelist_read_lstat(FileData *dir_fd, GList **files, GList **dirs) 911 gboolean filelist_read_lstat(FileData *dir_fd, GList **files, GList **dirs)
915 { 912 {
916 return filelist_read_real(dir_fd, files, dirs, FALSE); 913 return filelist_read_real(dir_fd, files, dirs, FALSE);
917 } 914 }
918 915
919 void filelist_free(GList *list) 916 void filelist_free(GList *list)
986 } 983 }
987 984
988 return g_list_reverse(new_list); 985 return g_list_reverse(new_list);
989 } 986 }
990 987
991 GList *filelist_filter(GList *list, gint is_dir_list) 988 GList *filelist_filter(GList *list, gboolean is_dir_list)
992 { 989 {
993 GList *work; 990 GList *work;
994 991
995 if (!is_dir_list && options->file_filter.disable && options->file_filter.show_hidden_files) return list; 992 if (!is_dir_list && options->file_filter.disable && options->file_filter.show_hidden_files) return list;
996 993
1088 static gpointer file_data_mark_func_data[FILEDATA_MARKS_SIZE]; 1085 static gpointer file_data_mark_func_data[FILEDATA_MARKS_SIZE];
1089 1086
1090 gboolean file_data_get_mark(FileData *fd, gint n) 1087 gboolean file_data_get_mark(FileData *fd, gint n)
1091 { 1088 {
1092 gboolean valid = (fd->valid_marks & (1 << n)); 1089 gboolean valid = (fd->valid_marks & (1 << n));
1090
1093 if (file_data_get_mark_func[n] && !valid) 1091 if (file_data_get_mark_func[n] && !valid)
1094 { 1092 {
1095 guint old = fd->marks; 1093 guint old = fd->marks;
1096 gboolean value = (file_data_get_mark_func[n])(fd, n, file_data_mark_func_data[n]); 1094 gboolean value = (file_data_get_mark_func[n])(fd, n, file_data_mark_func_data[n]);
1095
1097 if (!value != !(fd->marks & (1 << n))) 1096 if (!value != !(fd->marks & (1 << n)))
1098 { 1097 {
1099 fd->marks = fd->marks ^ (1 << n); 1098 fd->marks = fd->marks ^ (1 << n);
1100 } 1099 }
1100
1101 fd->valid_marks |= (1 << n); 1101 fd->valid_marks |= (1 << n);
1102 if (old && !fd->marks) /* keep files with non-zero marks in memory */ 1102 if (old && !fd->marks) /* keep files with non-zero marks in memory */
1103 { 1103 {
1104 file_data_unref(fd); 1104 file_data_unref(fd);
1105 } 1105 }
1317 1317
1318 void file_data_free_ci(FileData *fd) 1318 void file_data_free_ci(FileData *fd)
1319 { 1319 {
1320 FileDataChangeInfo *fdci = fd->change; 1320 FileDataChangeInfo *fdci = fd->change;
1321 1321
1322 if (!fdci) 1322 if (!fdci) return;
1323 return;
1324 1323
1325 file_data_planned_change_remove(fd); 1324 file_data_planned_change_remove(fd);
1326 1325
1327 g_free(fdci->source); 1326 g_free(fdci->source);
1328 g_free(fdci->dest); 1327 g_free(fdci->dest);
1656 } 1655 }
1657 1656
1658 g_free(dest_path_full); 1657 g_free(dest_path_full);
1659 } 1658 }
1660 1659
1661 static gint file_data_sc_check_update_ci(FileData *fd, const gchar *dest_path, FileDataChangeType type) 1660 static gboolean file_data_sc_check_update_ci(FileData *fd, const gchar *dest_path, FileDataChangeType type)
1662 { 1661 {
1663 if (!file_data_sc_check_ci(fd, type)) return FALSE; 1662 if (!file_data_sc_check_ci(fd, type)) return FALSE;
1664 file_data_sc_update_ci(fd, dest_path); 1663 file_data_sc_update_ci(fd, dest_path);
1665 return TRUE; 1664 return TRUE;
1666 } 1665 }
1667 1666
1668 gint file_data_sc_update_ci_copy(FileData *fd, const gchar *dest_path) 1667 gboolean file_data_sc_update_ci_copy(FileData *fd, const gchar *dest_path)
1669 { 1668 {
1670 return file_data_sc_check_update_ci(fd, dest_path, FILEDATA_CHANGE_COPY); 1669 return file_data_sc_check_update_ci(fd, dest_path, FILEDATA_CHANGE_COPY);
1671 } 1670 }
1672 1671
1673 gint file_data_sc_update_ci_move(FileData *fd, const gchar *dest_path) 1672 gboolean file_data_sc_update_ci_move(FileData *fd, const gchar *dest_path)
1674 { 1673 {
1675 return file_data_sc_check_update_ci(fd, dest_path, FILEDATA_CHANGE_MOVE); 1674 return file_data_sc_check_update_ci(fd, dest_path, FILEDATA_CHANGE_MOVE);
1676 } 1675 }
1677 1676
1678 gint file_data_sc_update_ci_rename(FileData *fd, const gchar *dest_path) 1677 gboolean file_data_sc_update_ci_rename(FileData *fd, const gchar *dest_path)
1679 { 1678 {
1680 return file_data_sc_check_update_ci(fd, dest_path, FILEDATA_CHANGE_RENAME); 1679 return file_data_sc_check_update_ci(fd, dest_path, FILEDATA_CHANGE_RENAME);
1681 } 1680 }
1682 1681
1683 gint file_data_sc_update_ci_unspecified(FileData *fd, const gchar *dest_path) 1682 gboolean file_data_sc_update_ci_unspecified(FileData *fd, const gchar *dest_path)
1684 { 1683 {
1685 return file_data_sc_check_update_ci(fd, dest_path, FILEDATA_CHANGE_UNSPECIFIED); 1684 return file_data_sc_check_update_ci(fd, dest_path, FILEDATA_CHANGE_UNSPECIFIED);
1686 } 1685 }
1687 1686
1688 static gboolean file_data_sc_update_ci_list_call_func(GList *fd_list, 1687 static gboolean file_data_sc_update_ci_list_call_func(GList *fd_list,
2128 } 2127 }
2129 2128
2130 gboolean file_data_perform_ci(FileData *fd) 2129 gboolean file_data_perform_ci(FileData *fd)
2131 { 2130 {
2132 FileDataChangeType type = fd->change->type; 2131 FileDataChangeType type = fd->change->type;
2132
2133 switch (type) 2133 switch (type)
2134 { 2134 {
2135 case FILEDATA_CHANGE_MOVE: 2135 case FILEDATA_CHANGE_MOVE:
2136 return file_data_perform_move(fd); 2136 return file_data_perform_move(fd);
2137 case FILEDATA_CHANGE_COPY: 2137 case FILEDATA_CHANGE_COPY:
2175 2175
2176 /* 2176 /*
2177 * updates FileData structure according to FileDataChangeInfo 2177 * updates FileData structure according to FileDataChangeInfo
2178 */ 2178 */
2179 2179
2180 gint file_data_apply_ci(FileData *fd) 2180 gboolean file_data_apply_ci(FileData *fd)
2181 { 2181 {
2182 FileDataChangeType type = fd->change->type; 2182 FileDataChangeType type = fd->change->type;
2183 2183
2184 /* FIXME delete ?*/ 2184 /* FIXME delete ?*/
2185 if (type == FILEDATA_CHANGE_MOVE || type == FILEDATA_CHANGE_RENAME) 2185 if (type == FILEDATA_CHANGE_MOVE || type == FILEDATA_CHANGE_RENAME)
2205 file_data_send_notification(fd, NOTIFY_TYPE_CHANGE); 2205 file_data_send_notification(fd, NOTIFY_TYPE_CHANGE);
2206 2206
2207 return TRUE; 2207 return TRUE;
2208 } 2208 }
2209 2209
2210 gint file_data_sc_apply_ci(FileData *fd) 2210 gboolean file_data_sc_apply_ci(FileData *fd)
2211 { 2211 {
2212 GList *work; 2212 GList *work;
2213 FileDataChangeType type = fd->change->type; 2213 FileDataChangeType type = fd->change->type;
2214 2214
2215 if (!file_data_sc_check_ci(fd, type)) return FALSE; 2215 if (!file_data_sc_check_ci(fd, type)) return FALSE;
2243 2243
2244 struct _NotifyData { 2244 struct _NotifyData {
2245 FileDataNotifyFunc func; 2245 FileDataNotifyFunc func;
2246 gpointer data; 2246 gpointer data;
2247 NotifyPriority priority; 2247 NotifyPriority priority;
2248 }; 2248 };
2249 2249
2250 static GList *notify_func_list = NULL; 2250 static GList *notify_func_list = NULL;
2251 2251
2252 static gint file_data_notify_sort(gconstpointer a, gconstpointer b) 2252 static gint file_data_notify_sort(gconstpointer a, gconstpointer b)
2253 { 2253 {
2257 if (nda->priority < ndb->priority) return -1; 2257 if (nda->priority < ndb->priority) return -1;
2258 if (nda->priority > ndb->priority) return 1; 2258 if (nda->priority > ndb->priority) return 1;
2259 return 0; 2259 return 0;
2260 } 2260 }
2261 2261
2262 gint file_data_register_notify_func(FileDataNotifyFunc func, gpointer data, NotifyPriority priority) 2262 gboolean file_data_register_notify_func(FileDataNotifyFunc func, gpointer data, NotifyPriority priority)
2263 { 2263 {
2264 NotifyData *nd; 2264 NotifyData *nd;
2265 2265
2266 nd = g_new(NotifyData, 1); 2266 nd = g_new(NotifyData, 1);
2267 nd->func = func; 2267 nd->func = func;
2272 DEBUG_1("Notify func registered: %p", nd); 2272 DEBUG_1("Notify func registered: %p", nd);
2273 2273
2274 return TRUE; 2274 return TRUE;
2275 } 2275 }
2276 2276
2277 gint file_data_unregister_notify_func(FileDataNotifyFunc func, gpointer data) 2277 gboolean file_data_unregister_notify_func(FileDataNotifyFunc func, gpointer data)
2278 { 2278 {
2279 GList *work = notify_func_list; 2279 GList *work = notify_func_list;
2280 2280
2281 while (work) 2281 while (work)
2282 { 2282 {
2327 if (!options->update_on_time_change) return TRUE; 2327 if (!options->update_on_time_change) return TRUE;
2328 g_hash_table_foreach(file_data_monitor_pool, realtime_monitor_check_cb, NULL); 2328 g_hash_table_foreach(file_data_monitor_pool, realtime_monitor_check_cb, NULL);
2329 return TRUE; 2329 return TRUE;
2330 } 2330 }
2331 2331
2332 gint file_data_register_real_time_monitor(FileData *fd) 2332 gboolean file_data_register_real_time_monitor(FileData *fd)
2333 { 2333 {
2334 gint count; 2334 gint count;
2335 2335
2336 file_data_ref(fd); 2336 file_data_ref(fd);
2337 2337
2351 } 2351 }
2352 2352
2353 return TRUE; 2353 return TRUE;
2354 } 2354 }
2355 2355
2356 gint file_data_unregister_real_time_monitor(FileData *fd) 2356 gboolean file_data_unregister_real_time_monitor(FileData *fd)
2357 { 2357 {
2358 gint count; 2358 gint count;
2359 2359
2360 g_assert(file_data_monitor_pool); 2360 g_assert(file_data_monitor_pool);
2361 2361