Mercurial > geeqie.yaz
comparison src/filelist.c @ 137:be3328a58875
started support for sidecar files like xmp, raw+jpeg etc.
author | nadvornik |
---|---|
date | Thu, 23 Aug 2007 20:45:59 +0000 |
parents | 847e4bc6b54c |
children | 71e1ebee420e |
comparison
equal
deleted
inserted
replaced
136:18c2a29e681c | 137:be3328a58875 |
---|---|
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 |
572 FileData *file_data_new(const gchar *path, struct stat *st) | 575 FileData *file_data_new(const gchar *path, struct stat *st) |
573 { | 576 { |
574 FileData *fd; | 577 FileData *fd; |
575 | 578 |
576 fd = g_new0(FileData, 1); | 579 fd = g_new0(FileData, 1); |
577 fd->path = path_to_utf8(path); | 580 fd->path = path_to_utf8(path); |
578 fd->name = filename_from_path(fd->path); | 581 fd->name = filename_from_path(fd->path); |
582 fd->extension = extension_from_path(fd->path); | |
583 | |
579 fd->size = st->st_size; | 584 fd->size = st->st_size; |
580 fd->date = st->st_mtime; | 585 fd->date = st->st_mtime; |
581 fd->pixbuf = NULL; | 586 fd->pixbuf = NULL; |
582 | 587 fd->sidecar_files = NULL; |
583 return fd; | 588 return fd; |
584 } | 589 } |
585 | 590 |
586 FileData *file_data_new_simple(const gchar *path) | 591 FileData *file_data_new_simple(const gchar *path) |
587 { | 592 { |
588 FileData *fd; | |
589 struct stat st; | 593 struct stat st; |
590 | 594 |
591 fd = g_new0(FileData, 1); | 595 if (!stat(path, &st)) |
592 fd->path = g_strdup(path); | 596 { |
593 fd->name = filename_from_path(fd->path); | 597 st.st_size = 0; |
594 | 598 st.st_mtime = 0; |
595 if (stat_utf8(fd->path, &st)) | 599 } |
596 { | 600 |
597 fd->size = st.st_size; | 601 return file_data_new(path, &st); |
598 fd->date = st.st_mtime; | 602 } |
599 } | 603 |
600 | 604 FileData *file_data_add_sidecar_file(FileData *target, SidecarFileData *sfd) |
601 fd->pixbuf = NULL; | 605 { |
602 | 606 target->sidecar_files = g_list_append(target->sidecar_files, sfd); |
603 return fd; | 607 return target; |
604 } | 608 } |
609 | |
610 FileData *file_data_merge_sidecar_files(FileData *target, FileData *source) | |
611 { | |
612 SidecarFileData *sfd; | |
613 | |
614 sfd = sidecar_file_data_new_from_file_data(source); | |
615 file_data_add_sidecar_file(target, sfd); | |
616 | |
617 target->sidecar_files = g_list_concat(target->sidecar_files, source->sidecar_files); | |
618 source->sidecar_files = NULL; | |
619 | |
620 file_data_free(source); | |
621 return target; | |
622 } | |
623 | |
605 | 624 |
606 void file_data_free(FileData *fd) | 625 void file_data_free(FileData *fd) |
607 { | 626 { |
627 GList *work; | |
608 g_free(fd->path); | 628 g_free(fd->path); |
609 if (fd->pixbuf) g_object_unref(fd->pixbuf); | 629 if (fd->pixbuf) g_object_unref(fd->pixbuf); |
630 | |
631 work = fd->sidecar_files; | |
632 while (work) | |
633 { | |
634 sidecar_file_data_free((SidecarFileData *)work->data); | |
635 work = work->next; | |
636 } | |
637 | |
638 g_list_free(fd->sidecar_files); | |
639 | |
610 g_free(fd); | 640 g_free(fd); |
641 } | |
642 | |
643 /* compare name without extension */ | |
644 gint file_data_compare_name_without_ext(FileData *fd1, FileData *fd2) | |
645 { | |
646 size_t len1 = fd1->extension - fd1->name; | |
647 size_t len2 = fd2->extension - fd2->name; | |
648 | |
649 if (len1 < len2) return -1; | |
650 if (len1 > len2) return 1; | |
651 | |
652 return strncmp(fd1->name, fd2->name, len1); | |
653 } | |
654 | |
655 /* | |
656 *----------------------------------------------------------------------------- | |
657 * sidecar file info struct | |
658 *----------------------------------------------------------------------------- | |
659 */ | |
660 | |
661 SidecarFileData *sidecar_file_data_new(const gchar *path, struct stat *st) | |
662 { | |
663 SidecarFileData *fd; | |
664 | |
665 fd = g_new0(SidecarFileData, 1); | |
666 fd->path = path_to_utf8(path); | |
667 fd->name = filename_from_path(fd->path); | |
668 fd->extension = extension_from_path(fd->path); | |
669 | |
670 fd->size = st->st_size; | |
671 fd->date = st->st_mtime; | |
672 | |
673 return fd; | |
674 } | |
675 | |
676 SidecarFileData *sidecar_file_data_new_simple(const gchar *path) | |
677 { | |
678 struct stat st; | |
679 | |
680 if (!stat(path, &st)) | |
681 { | |
682 st.st_size = 0; | |
683 st.st_mtime = 0; | |
684 } | |
685 | |
686 return sidecar_file_data_new(path, &st); | |
687 } | |
688 | |
689 SidecarFileData *sidecar_file_data_new_from_file_data(const FileData *fd) | |
690 { | |
691 SidecarFileData *sfd; | |
692 | |
693 sfd = g_new0(SidecarFileData, 1); | |
694 sfd->path = g_strdup(fd->path); | |
695 sfd->name = filename_from_path(sfd->path);; | |
696 sfd->extension = extension_from_path(sfd->path); | |
697 | |
698 sfd->size = fd->size; | |
699 sfd->date = fd->date; | |
700 | |
701 return sfd; | |
702 } | |
703 | |
704 | |
705 void sidecar_file_data_free(SidecarFileData *fd) | |
706 { | |
707 g_free(fd->path); | |
708 g_free(fd); | |
709 } | |
710 | |
711 gint sidecar_file_priority(const gchar *path) | |
712 { | |
713 const char *extension = extension_from_path(path); | |
714 | |
715 printf("prio %s >%s<\n", path, extension); | |
716 | |
717 if (strcmp(extension, ".cr2") == 0) return 1; | |
718 if (strcmp(extension, ".crw") == 0) return 2; | |
719 if (strcmp(extension, ".nef") == 0) return 3; | |
720 if (strcmp(extension, ".raw") == 0) return 4; | |
721 | |
722 if (strcmp(extension, ".jpg") == 0) return 1001; | |
723 | |
724 if (strcmp(extension, ".vaw") == 0) return 2001; | |
725 if (strcmp(extension, ".mp3") == 0) return 2002; | |
726 | |
727 if (strcmp(extension, ".xmp") == 0) return 3002; | |
728 | |
729 return 0; | |
611 } | 730 } |
612 | 731 |
613 /* | 732 /* |
614 *----------------------------------------------------------------------------- | 733 *----------------------------------------------------------------------------- |
615 * load file list | 734 * load file list |
665 { | 784 { |
666 filelist_sort_method = method; | 785 filelist_sort_method = method; |
667 filelist_sort_ascend = ascend; | 786 filelist_sort_ascend = ascend; |
668 return g_list_insert_sorted(list, fd, (GCompareFunc) sort_file_cb); | 787 return g_list_insert_sorted(list, fd, (GCompareFunc) sort_file_cb); |
669 } | 788 } |
789 | |
670 | 790 |
671 gint filelist_read(const gchar *path, GList **files, GList **dirs) | 791 gint filelist_read(const gchar *path, GList **files, GList **dirs) |
672 { | 792 { |
673 DIR *dp; | 793 DIR *dp; |
674 struct dirent *dir; | 794 struct dirent *dir; |
718 } | 838 } |
719 else | 839 else |
720 { | 840 { |
721 if ((files) && filter_name_exists(name)) | 841 if ((files) && filter_name_exists(name)) |
722 { | 842 { |
723 flist = g_list_prepend(flist, file_data_new(filepath, &ent_sbuf)); | 843 FileData *fd = file_data_new(filepath, &ent_sbuf); |
844 | |
845 GList *same = g_list_find_custom(flist, fd, file_data_compare_name_without_ext); | |
846 | |
847 int p1 = 0; | |
848 int p2 = 0; | |
849 FileData *samefd = NULL; | |
850 | |
851 if (same) | |
852 { | |
853 samefd = (FileData *) same->data; | |
854 p1 = sidecar_file_priority(samefd->name); | |
855 p2 = sidecar_file_priority(fd->name); | |
856 printf("same %s %s %d %d\n", fd->name, samefd->name, p2, p1); | |
857 } | |
858 | |
859 if (p1 && p2) | |
860 { | |
861 if (p1 < p2) | |
862 { | |
863 file_data_merge_sidecar_files(samefd, fd); | |
864 } | |
865 else | |
866 { | |
867 file_data_merge_sidecar_files(fd, samefd); | |
868 flist = g_list_delete_link(flist, same); | |
869 flist = g_list_prepend(flist, fd); | |
870 } | |
871 } | |
872 else | |
873 flist = g_list_prepend(flist, fd); | |
724 } | 874 } |
725 } | 875 } |
726 } | 876 } |
727 g_free(filepath); | 877 g_free(filepath); |
728 } | 878 } |