Mercurial > geeqie.yaz
comparison src/view_file.c @ 1606:74a7f9ea32a1
Merge common thumb code from view_file_list and view_file_icon to view_file.
author | zas_ |
---|---|
date | Thu, 14 May 2009 20:32:14 +0000 |
parents | b8e2690c440a |
children | 7bfa9fd0cd93 |
comparison
equal
deleted
inserted
replaced
1605:1e85af235201 | 1606:74a7f9ea32a1 |
---|---|
13 #include "view_file.h" | 13 #include "view_file.h" |
14 | 14 |
15 #include "editors.h" | 15 #include "editors.h" |
16 #include "layout.h" | 16 #include "layout.h" |
17 #include "menu.h" | 17 #include "menu.h" |
18 #include "thumb.h" | |
18 #include "ui_menu.h" | 19 #include "ui_menu.h" |
19 #include "ui_fileops.h" | 20 #include "ui_fileops.h" |
20 #include "utilops.h" | 21 #include "utilops.h" |
21 #include "view_file_list.h" | 22 #include "view_file_list.h" |
22 #include "view_file_icon.h" | 23 #include "view_file_icon.h" |
631 menu_item_add_stock(menu, _("Re_fresh"), GTK_STOCK_REFRESH, G_CALLBACK(vf_pop_menu_refresh_cb), vf); | 632 menu_item_add_stock(menu, _("Re_fresh"), GTK_STOCK_REFRESH, G_CALLBACK(vf_pop_menu_refresh_cb), vf); |
632 | 633 |
633 return menu; | 634 return menu; |
634 } | 635 } |
635 | 636 |
636 void vf_thumb_update(ViewFile *vf) | |
637 { | |
638 switch (vf->type) | |
639 { | |
640 case FILEVIEW_LIST: vflist_thumb_update(vf); break; | |
641 case FILEVIEW_ICON: vficon_thumb_update(vf); break; | |
642 } | |
643 } | |
644 | |
645 gboolean vf_refresh(ViewFile *vf) | 637 gboolean vf_refresh(ViewFile *vf) |
646 { | 638 { |
647 gboolean ret = FALSE; | 639 gboolean ret = FALSE; |
648 | 640 |
649 switch (vf->type) | 641 switch (vf->type) |
786 case FILEVIEW_LIST: vflist_thumb_set(vf, enable); break; | 778 case FILEVIEW_LIST: vflist_thumb_set(vf, enable); break; |
787 case FILEVIEW_ICON: /*vficon_thumb_set(vf, enable);*/ break; | 779 case FILEVIEW_ICON: /*vficon_thumb_set(vf, enable);*/ break; |
788 } | 780 } |
789 } | 781 } |
790 | 782 |
783 | |
784 static gboolean vf_thumb_next(ViewFile *vf); | |
785 | |
786 static gdouble vf_thumb_progress(ViewFile *vf) | |
787 { | |
788 gint count = 0; | |
789 gint done = 0; | |
790 | |
791 switch (vf->type) | |
792 { | |
793 case FILEVIEW_LIST: vflist_thumb_progress_count(vf->list, &count, &done); break; | |
794 case FILEVIEW_ICON: vficon_thumb_progress_count(vf->list, &count, &done); break; | |
795 } | |
796 | |
797 DEBUG_1("thumb progress: %d of %d", done, count); | |
798 return (gdouble)done / count; | |
799 } | |
800 | |
801 static void vf_set_thumb_fd(ViewFile *vf, FileData *fd) | |
802 { | |
803 switch (vf->type) | |
804 { | |
805 case FILEVIEW_LIST: vflist_set_thumb_fd(vf, fd); break; | |
806 case FILEVIEW_ICON: vficon_set_thumb_fd(vf, fd); break; | |
807 } | |
808 } | |
809 | |
810 static void vf_thumb_status(ViewFile *vf, gdouble val, const gchar *text) | |
811 { | |
812 if (vf->func_thumb_status) | |
813 { | |
814 vf->func_thumb_status(vf, val, text, vf->data_thumb_status); | |
815 } | |
816 } | |
817 | |
818 static void vf_thumb_do(ViewFile *vf, FileData *fd) | |
819 { | |
820 if (!fd) return; | |
821 | |
822 vf_set_thumb_fd(vf, fd); | |
823 vf_thumb_status(vf, vf_thumb_progress(vf), _("Loading thumbs...")); | |
824 } | |
825 | |
826 void vf_thumb_cleanup(ViewFile *vf) | |
827 { | |
828 vf_thumb_status(vf, 0.0, NULL); | |
829 | |
830 vf->thumbs_running = FALSE; | |
831 | |
832 thumb_loader_free(vf->thumbs_loader); | |
833 vf->thumbs_loader = NULL; | |
834 | |
835 vf->thumbs_filedata = NULL; | |
836 } | |
837 | |
838 void vf_thumb_stop(ViewFile *vf) | |
839 { | |
840 if (vf->thumbs_running) vf_thumb_cleanup(vf); | |
841 } | |
842 | |
843 static void vf_thumb_common_cb(ThumbLoader *tl, gpointer data) | |
844 { | |
845 ViewFile *vf = data; | |
846 | |
847 if (vf->thumbs_filedata && vf->thumbs_loader == tl) | |
848 { | |
849 vf_thumb_do(vf, vf->thumbs_filedata); | |
850 } | |
851 | |
852 while (vf_thumb_next(vf)); | |
853 } | |
854 | |
855 static void vf_thumb_error_cb(ThumbLoader *tl, gpointer data) | |
856 { | |
857 vf_thumb_common_cb(tl, data); | |
858 } | |
859 | |
860 static void vf_thumb_done_cb(ThumbLoader *tl, gpointer data) | |
861 { | |
862 vf_thumb_common_cb(tl, data); | |
863 } | |
864 | |
865 static gboolean vf_thumb_next(ViewFile *vf) | |
866 { | |
867 FileData *fd = NULL; | |
868 gint ret; | |
869 | |
870 if (!GTK_WIDGET_REALIZED(vf->listview)) | |
871 { | |
872 vf_thumb_status(vf, 0.0, NULL); | |
873 return FALSE; | |
874 } | |
875 | |
876 switch (vf->type) | |
877 { | |
878 case FILEVIEW_LIST: fd = vflist_thumb_next_fd(vf); break; | |
879 case FILEVIEW_ICON: fd = vficon_thumb_next_fd(vf); break; | |
880 } | |
881 | |
882 if (!fd) | |
883 { | |
884 /* done */ | |
885 vf_thumb_cleanup(vf); | |
886 return FALSE; | |
887 } | |
888 | |
889 vf->thumbs_filedata = fd; | |
890 | |
891 thumb_loader_free(vf->thumbs_loader); | |
892 | |
893 vf->thumbs_loader = thumb_loader_new(options->thumbnails.max_width, options->thumbnails.max_height); | |
894 thumb_loader_set_callbacks(vf->thumbs_loader, | |
895 vf_thumb_done_cb, | |
896 vf_thumb_error_cb, | |
897 NULL, | |
898 vf); | |
899 | |
900 if (!thumb_loader_start(vf->thumbs_loader, fd)) | |
901 { | |
902 /* set icon to unknown, continue */ | |
903 DEBUG_1("thumb loader start failed %s", fd->path); | |
904 vf_thumb_do(vf, fd); | |
905 | |
906 return TRUE; | |
907 } | |
908 | |
909 return FALSE; | |
910 } | |
911 | |
912 static void vf_thumb_reset_all(ViewFile *vf) | |
913 { | |
914 switch (vf->type) | |
915 { | |
916 case FILEVIEW_LIST: vflist_thumb_reset_all(vf); break; | |
917 case FILEVIEW_ICON: vficon_thumb_reset_all(vf); break; | |
918 } | |
919 } | |
920 | |
921 void vf_thumb_update(ViewFile *vf) | |
922 { | |
923 vf_thumb_stop(vf); | |
924 | |
925 if (vf->type == FILEVIEW_LIST && !VFLIST(vf)->thumbs_enabled) return; | |
926 | |
927 vf_thumb_status(vf, 0.0, _("Loading thumbs...")); | |
928 vf->thumbs_running = TRUE; | |
929 | |
930 if (thumb_format_changed) | |
931 { | |
932 vf_thumb_reset_all(vf); | |
933 thumb_format_changed = FALSE; | |
934 } | |
935 | |
936 while (vf_thumb_next(vf)); | |
937 } | |
938 | |
939 | |
791 void vf_marks_set(ViewFile *vf, gboolean enable) | 940 void vf_marks_set(ViewFile *vf, gboolean enable) |
792 { | 941 { |
793 if (vf->marks_enabled == enable) return; | 942 if (vf->marks_enabled == enable) return; |
794 | 943 |
795 vf->marks_enabled = enable; | 944 vf->marks_enabled = enable; |