comparison src/image.c @ 888:d8e1e820cee7

reload changed images
author nadvornik
date Thu, 17 Jul 2008 21:51:21 +0000
parents ad420f2eb789
children bc9df0fecdc1
comparison
equal deleted inserted replaced
887:e418c33a49c8 888:d8e1e820cee7
42 /* throttle factor to increase read bytes by (2 is double, 3 is triple, etc.) */ 42 /* throttle factor to increase read bytes by (2 is double, 3 is triple, etc.) */
43 #define IMAGE_THROTTLE_FACTOR 32 43 #define IMAGE_THROTTLE_FACTOR 32
44 44
45 /* the file size at which throttling take place */ 45 /* the file size at which throttling take place */
46 #define IMAGE_THROTTLE_THRESHOLD 1048576 46 #define IMAGE_THROTTLE_THRESHOLD 1048576
47
48 #define IMAGE_AUTO_REFRESH_TIME 3000
49
50 47
51 static GList *image_list = NULL; 48 static GList *image_list = NULL;
52 49
53 50
54 static void image_update_title(ImageWindow *imd); 51 static void image_update_title(ImageWindow *imd);
771 image_change_pixbuf(imd, pixbuf, zoom); 768 image_change_pixbuf(imd, pixbuf, zoom);
772 g_object_unref(pixbuf); 769 g_object_unref(pixbuf);
773 770
774 imd->unknown = TRUE; 771 imd->unknown = TRUE;
775 } 772 }
776 imd->size = filesize(imd->image_fd->path);
777 imd->mtime = filetime(imd->image_fd->path);
778 } 773 }
779 else 774 else
780 { 775 {
781 if (imd->image_fd) 776 if (imd->image_fd)
782 { 777 {
783 GdkPixbuf *pixbuf; 778 GdkPixbuf *pixbuf;
784 779
785 pixbuf = pixbuf_inline(PIXBUF_INLINE_BROKEN); 780 pixbuf = pixbuf_inline(PIXBUF_INLINE_BROKEN);
786 image_change_pixbuf(imd, pixbuf, zoom); 781 image_change_pixbuf(imd, pixbuf, zoom);
787 g_object_unref(pixbuf); 782 g_object_unref(pixbuf);
788 imd->mtime = filetime(imd->image_fd->path);
789 } 783 }
790 else 784 else
791 { 785 {
792 image_change_pixbuf(imd, NULL, zoom); 786 image_change_pixbuf(imd, NULL, zoom);
793 imd->mtime = 0;
794 } 787 }
795 imd->unknown = TRUE; 788 imd->unknown = TRUE;
796 imd->size = 0;
797 } 789 }
798 790
799 image_update_util(imd); 791 image_update_util(imd);
800 } 792 }
801 793
804 { 796 {
805 797
806 imd->collection = cd; 798 imd->collection = cd;
807 imd->collection_info = info; 799 imd->collection_info = info;
808 800
801 if (imd->auto_refresh && imd->image_fd)
802 file_data_unregister_real_time_monitor(imd->image_fd);
803
809 file_data_unref(imd->image_fd); 804 file_data_unref(imd->image_fd);
810 imd->image_fd = file_data_ref(fd); 805 imd->image_fd = file_data_ref(fd);
811 806
807
812 image_change_complete(imd, zoom, TRUE); 808 image_change_complete(imd, zoom, TRUE);
813 809
814 image_update_title(imd); 810 image_update_title(imd);
815 image_state_set(imd, IMAGE_STATE_IMAGE); 811 image_state_set(imd, IMAGE_STATE_IMAGE);
812
813 if (imd->auto_refresh && imd->image_fd)
814 file_data_register_real_time_monitor(imd->image_fd);
816 } 815 }
817 816
818 /* 817 /*
819 *------------------------------------------------------------------- 818 *-------------------------------------------------------------------
820 * focus stuff 819 * focus stuff
986 } 985 }
987 986
988 /* merely changes path string, does not change the image! */ 987 /* merely changes path string, does not change the image! */
989 void image_set_fd(ImageWindow *imd, FileData *fd) 988 void image_set_fd(ImageWindow *imd, FileData *fd)
990 { 989 {
990 if (imd->auto_refresh && imd->image_fd)
991 file_data_unregister_real_time_monitor(imd->image_fd);
992
991 file_data_unref(imd->image_fd); 993 file_data_unref(imd->image_fd);
992 imd->image_fd = file_data_ref(fd); 994 imd->image_fd = file_data_ref(fd);
993 995
994 image_update_title(imd); 996 image_update_title(imd);
995 image_state_set(imd, IMAGE_STATE_IMAGE); 997 image_state_set(imd, IMAGE_STATE_IMAGE);
998
999 if (imd->auto_refresh && imd->image_fd)
1000 file_data_register_real_time_monitor(imd->image_fd);
996 } 1001 }
997 1002
998 /* load a new image */ 1003 /* load a new image */
999 1004
1000 void image_change_fd(ImageWindow *imd, FileData *fd, gdouble zoom) 1005 void image_change_fd(ImageWindow *imd, FileData *fd, gdouble zoom)
1114 1119
1115 imd->unknown = source->unknown; 1120 imd->unknown = source->unknown;
1116 1121
1117 imd->collection = source->collection; 1122 imd->collection = source->collection;
1118 imd->collection_info = source->collection_info; 1123 imd->collection_info = source->collection_info;
1119 imd->size = source->size;
1120 imd->mtime = source->mtime;
1121 1124
1122 image_loader_free(imd->il); 1125 image_loader_free(imd->il);
1123 imd->il = NULL; 1126 imd->il = NULL;
1124 1127
1125 image_set_fd(imd, image_get_fd(source)); 1128 image_set_fd(imd, image_get_fd(source));
1348 { 1351 {
1349 image_read_ahead_cancel(imd); 1352 image_read_ahead_cancel(imd);
1350 } 1353 }
1351 } 1354 }
1352 1355
1353 static gint image_auto_refresh_cb(gpointer data) 1356 static void image_notify_cb(FileData *fd, NotifyType type, gpointer data)
1354 { 1357 {
1355 ImageWindow *imd = data; 1358 ImageWindow *imd = data;
1356 time_t newtime;
1357 1359
1358 if (!imd || !image_get_pixbuf(imd) || 1360 if (!imd || !image_get_pixbuf(imd) ||
1359 imd->il || !imd->image_fd || 1361 imd->il || !imd->image_fd ||
1360 !options->update_on_time_change) return TRUE; 1362 !options->update_on_time_change) return;
1361 1363
1362 newtime = filetime(imd->image_fd->path); 1364 if (type == NOTIFY_TYPE_REREAD && fd == imd->image_fd)
1363 if (newtime > 0 && newtime != imd->mtime) 1365 {
1364 {
1365 imd->mtime = newtime;
1366 image_reload(imd); 1366 image_reload(imd);
1367 } 1367 }
1368 1368 }
1369 return TRUE; 1369
1370 } 1370 void image_auto_refresh_enable(ImageWindow *imd, gboolean enable)
1371 1371 {
1372 /* image auto refresh on time stamp change, in 1/1000's second, -1 disables */ 1372 if (!enable && imd->auto_refresh && imd->image_fd)
1373 1373 file_data_unregister_real_time_monitor(imd->image_fd);
1374 void image_auto_refresh(ImageWindow *imd, gint interval) 1374
1375 { 1375 if (enable && !imd->auto_refresh && imd->image_fd)
1376 if (!imd) return; 1376 file_data_register_real_time_monitor(imd->image_fd);
1377 if (pixbuf_renderer_get_tiles((PixbufRenderer *)imd->pr)) return; 1377
1378 1378 imd->auto_refresh = enable;
1379 if (imd->auto_refresh_id > -1)
1380 {
1381 g_source_remove(imd->auto_refresh_id);
1382 imd->auto_refresh_id = -1;
1383 imd->auto_refresh_interval = -1;
1384 }
1385
1386 if (interval < 0) return;
1387
1388 if (interval == 0) interval = IMAGE_AUTO_REFRESH_TIME;
1389
1390 imd->auto_refresh_id = g_timeout_add((guint32)interval, image_auto_refresh_cb, imd);
1391 imd->auto_refresh_interval = interval;
1392 } 1379 }
1393 1380
1394 void image_top_window_set_sync(ImageWindow *imd, gint allow_sync) 1381 void image_top_window_set_sync(ImageWindow *imd, gint allow_sync)
1395 { 1382 {
1396 imd->top_window_sync = allow_sync; 1383 imd->top_window_sync = allow_sync;
1598 1585
1599 static void image_free(ImageWindow *imd) 1586 static void image_free(ImageWindow *imd)
1600 { 1587 {
1601 image_list = g_list_remove(image_list, imd); 1588 image_list = g_list_remove(image_list, imd);
1602 1589
1590 if (imd->auto_refresh && imd->image_fd)
1591 file_data_unregister_real_time_monitor(imd->image_fd);
1592
1593 file_data_unregister_notify_func(image_notify_cb, imd);
1594
1603 image_reset(imd); 1595 image_reset(imd);
1604 1596
1605 image_read_ahead_cancel(imd); 1597 image_read_ahead_cancel(imd);
1606 image_auto_refresh(imd, -1);
1607 1598
1608 file_data_unref(imd->image_fd); 1599 file_data_unref(imd->image_fd);
1609 g_free(imd->title); 1600 g_free(imd->title);
1610 g_free(imd->title_right); 1601 g_free(imd->title_right);
1611 g_free(imd); 1602 g_free(imd);
1711 imd->color_profile_input = 0; 1702 imd->color_profile_input = 0;
1712 imd->color_profile_screen = 0; 1703 imd->color_profile_screen = 0;
1713 imd->color_profile_use_image = FALSE; 1704 imd->color_profile_use_image = FALSE;
1714 imd->color_profile_from_image = COLOR_PROFILE_NONE; 1705 imd->color_profile_from_image = COLOR_PROFILE_NONE;
1715 1706
1716 imd->auto_refresh_id = -1; 1707 imd->auto_refresh = FALSE;
1717 imd->auto_refresh_interval = -1;
1718 1708
1719 imd->delay_flip = FALSE; 1709 imd->delay_flip = FALSE;
1720 1710
1721 imd->func_update = NULL; 1711 imd->func_update = NULL;
1722 imd->func_complete = NULL; 1712 imd->func_complete = NULL;
1755 g_signal_connect(G_OBJECT(imd->pr), "render_complete", 1745 g_signal_connect(G_OBJECT(imd->pr), "render_complete",
1756 G_CALLBACK(image_render_complete_cb), imd); 1746 G_CALLBACK(image_render_complete_cb), imd);
1757 g_signal_connect(G_OBJECT(imd->pr), "drag", 1747 g_signal_connect(G_OBJECT(imd->pr), "drag",
1758 G_CALLBACK(image_drag_cb), imd); 1748 G_CALLBACK(image_drag_cb), imd);
1759 1749
1750 file_data_register_notify_func(image_notify_cb, imd, NOTIFY_PRIORITY_LOW);
1751
1760 image_list = g_list_append(image_list, imd); 1752 image_list = g_list_append(image_list, imd);
1761 1753
1762 return imd; 1754 return imd;
1763 } 1755 }