comparison src/filelist.c @ 141:bdc16027fa6f

use FileData even for sidecar file list
author nadvornik
date Mon, 01 Oct 2007 19:52:10 +0000
parents 754c1e4349b6
children 0d1bf3ac6cd8
comparison
equal deleted inserted replaced
140:e57b0207e180 141:bdc16027fa6f
566 /* 566 /*
567 *----------------------------------------------------------------------------- 567 *-----------------------------------------------------------------------------
568 * file info struct 568 * file info struct
569 *----------------------------------------------------------------------------- 569 *-----------------------------------------------------------------------------
570 */ 570 */
571 SidecarFileData *sidecar_file_data_new_from_file_data(const FileData *fd);
572 void sidecar_file_data_free(SidecarFileData *fd);
573 571
574 static void file_data_set_path(FileData *fd, const gchar *path) 572 static void file_data_set_path(FileData *fd, const gchar *path)
575 { 573 {
576 574
577 if (strcmp(path, "/") == 0) 575 if (strcmp(path, "/") == 0)
661 } 659 }
662 660
663 return file_data_new(path_utf8, &st); 661 return file_data_new(path_utf8, &st);
664 } 662 }
665 663
666 FileData *file_data_add_sidecar_file(FileData *target, SidecarFileData *sfd) 664 FileData *file_data_add_sidecar_file(FileData *target, FileData *sfd)
667 { 665 {
668 target->sidecar_files = g_list_append(target->sidecar_files, sfd); 666 target->sidecar_files = g_list_append(target->sidecar_files, file_data_ref(sfd));
667 sfd->parent = target;
669 return target; 668 return target;
670 } 669 }
671 670
672 FileData *file_data_merge_sidecar_files(FileData *target, FileData *source) 671 FileData *file_data_merge_sidecar_files(FileData *target, FileData *source)
673 { 672 {
674 SidecarFileData *sfd; 673 GList *work;
675 674 file_data_add_sidecar_file(target, source);
676 sfd = sidecar_file_data_new_from_file_data(source); 675
677 file_data_add_sidecar_file(target, sfd); 676 work = source->sidecar_files;
678 677 while (work)
678 {
679 FileData *sfd = work->data;
680 sfd->parent = target;
681 work = work->next;
682 }
683
679 target->sidecar_files = g_list_concat(target->sidecar_files, source->sidecar_files); 684 target->sidecar_files = g_list_concat(target->sidecar_files, source->sidecar_files);
680 source->sidecar_files = NULL; 685 source->sidecar_files = NULL;
681 686
682 file_data_unref(source);
683 return target; 687 return target;
684 } 688 }
685 689
686 690
687 void file_data_free(FileData *fd) 691 void file_data_free(FileData *fd)
698 if (fd->pixbuf) g_object_unref(fd->pixbuf); 702 if (fd->pixbuf) g_object_unref(fd->pixbuf);
699 703
700 work = fd->sidecar_files; 704 work = fd->sidecar_files;
701 while (work) 705 while (work)
702 { 706 {
703 sidecar_file_data_free((SidecarFileData *)work->data); 707 FileData *sfd = work->data;
704 work = work->next; 708 sfd->parent = NULL;
705 } 709 work = work->next;
706 710 }
707 g_list_free(fd->sidecar_files); 711 filelist_free(fd->sidecar_files);
708 712
709 file_data_change_info_free(NULL, fd); 713 file_data_change_info_free(NULL, fd);
710 g_free(fd); 714 g_free(fd);
711 } 715 }
712 716
794 *----------------------------------------------------------------------------- 798 *-----------------------------------------------------------------------------
795 * sidecar file info struct 799 * sidecar file info struct
796 *----------------------------------------------------------------------------- 800 *-----------------------------------------------------------------------------
797 */ 801 */
798 802
799 SidecarFileData *sidecar_file_data_new(const gchar *path, struct stat *st)
800 {
801 SidecarFileData *fd;
802
803 fd = g_new0(SidecarFileData, 1);
804 fd->path = path_to_utf8(path);
805 fd->name = filename_from_path(fd->path);
806 fd->extension = extension_from_path(fd->path);
807
808 fd->size = st->st_size;
809 fd->date = st->st_mtime;
810
811 return fd;
812 }
813
814 SidecarFileData *sidecar_file_data_new_simple(const gchar *path)
815 {
816 struct stat st;
817
818 if (!stat(path, &st))
819 {
820 st.st_size = 0;
821 st.st_mtime = 0;
822 }
823
824 return sidecar_file_data_new(path, &st);
825 }
826
827 SidecarFileData *sidecar_file_data_new_from_file_data(const FileData *fd)
828 {
829 SidecarFileData *sfd;
830
831 sfd = g_new0(SidecarFileData, 1);
832 sfd->path = g_strdup(fd->path);
833 sfd->name = filename_from_path(sfd->path);;
834 sfd->extension = extension_from_path(sfd->path);
835
836 sfd->size = fd->size;
837 sfd->date = fd->date;
838
839 return sfd;
840 }
841
842
843 void sidecar_file_data_free(SidecarFileData *fd)
844 {
845 g_free(fd->path);
846 g_free(fd);
847 }
848 803
849 gint sidecar_file_priority(const gchar *path) 804 gint sidecar_file_priority(const gchar *path)
850 { 805 {
851 const char *extension = extension_from_path(path); 806 const char *extension = extension_from_path(path);
852 807
853 printf("prio %s >%s<\n", path, extension); 808 printf("prio %s >%s<\n", path, extension);
854 809
855 if (strcmp(extension, ".cr2") == 0) return 1; 810 if (strcmp(extension, ".jpg") == 0) return 1;
856 if (strcmp(extension, ".crw") == 0) return 2; 811
857 if (strcmp(extension, ".nef") == 0) return 3; 812 if (strcmp(extension, ".cr2") == 0) return 1001;
858 if (strcmp(extension, ".raw") == 0) return 4; 813 if (strcmp(extension, ".crw") == 0) return 1002;
859 814 if (strcmp(extension, ".nef") == 0) return 1003;
860 if (strcmp(extension, ".jpg") == 0) return 1001; 815 if (strcmp(extension, ".raw") == 0) return 1004;
816
861 817
862 if (strcmp(extension, ".vaw") == 0) return 2001; 818 if (strcmp(extension, ".vaw") == 0) return 2001;
863 if (strcmp(extension, ".mp3") == 0) return 2002; 819 if (strcmp(extension, ".mp3") == 0) return 2002;
864 820
865 if (strcmp(extension, ".xmp") == 0) return 3002; 821 if (strcmp(extension, ".xmp") == 0) return 3002;
873 GString *result = g_string_new(""); 829 GString *result = g_string_new("");
874 830
875 work = fd->sidecar_files; 831 work = fd->sidecar_files;
876 while (work) 832 while (work)
877 { 833 {
878 SidecarFileData *sfd = work->data; 834 FileData *sfd = work->data;
879 result = g_string_append(result, "+ "); 835 result = g_string_append(result, "+ ");
880 result = g_string_append(result, sfd->extension); 836 result = g_string_append(result, sfd->extension);
881 work = work->next; 837 work = work->next;
882 if (work) result = g_string_append_c(result, ' '); 838 if (work) result = g_string_append_c(result, ' ');
883 } 839 }