gulong size;
};
+static void file_cache_notify_cb(FileData *fd, NotifyType type, gpointer data);
+
FileCacheData *file_cache_new(FileCacheReleaseFunc release, gulong max_size)
{
FileCacheData *fc = g_new(FileCacheData, 1);
fc->list = NULL;
fc->max_size = max_size;
fc->size = 0;
+
+ file_data_register_notify_func(file_cache_notify_cb, fc, NOTIFY_PRIORITY_HIGH);
+
return fc;
}
DEBUG_1("cache move to front: fc=%p %s", fc, fd->path);
fc->list = g_list_remove_link(fc->list, work);
fc->list = g_list_concat(work, fc->list);
+
+// if (file_data_check_changed_files(fd)) /* this will eventually remove changed files from cache via file_cache_notify_cb */
+// return FALSE;
+
if (debug_file_cache) file_cache_dump(fc);
return TRUE;
}
fc->list = g_list_delete_link(fc->list, work);
work = prev;
- DEBUG_1("cache remove: fc=%p %s", fc, last_fe->fd->path);
+ DEBUG_1("file changed - cache remove: fc=%p %s", fc, last_fe->fd->path);
fc->size -= last_fe->size;
fc->release(last_fe->fd);
file_data_unref(last_fe->fd);
file_cache_set_size(fc, fc->max_size);
}
+static void file_cache_remove_fd(FileCacheData *fc, FileData *fd)
+{
+ GList *work;
+ FileCacheEntry *fe;
+
+ if (debug_file_cache) file_cache_dump(fc);
+
+ work = fc->list;
+ while (work)
+ {
+ GList *current = work;
+ fe = work->data;
+ work = work->next;
+
+ if (fe->fd == fd)
+ {
+ fc->list = g_list_delete_link(fc->list, current);
+
+ DEBUG_1("cache remove: fc=%p %s", fc, fe->fd->path);
+ fc->size -= fe->size;
+ fc->release(fe->fd);
+ file_data_unref(fe->fd);
+ g_free(fe);
+ }
+ }
+}
+
void file_cache_dump(FileCacheData *fc)
{
GList *work;
DEBUG_1("cache entry: fc=%p [%lu] %s %ld", fc, ++n, fe->fd->path, fe->size);
}
}
+
+static void file_cache_notify_cb(FileData *fd, NotifyType type, gpointer data)
+{
+ FileCacheData *fc = data;
+
+ if (type == NOTIFY_TYPE_REREAD)
+ {
+ file_cache_remove_fd(fc, fd);
+ }
+}
\ No newline at end of file
}
-static gboolean file_data_check_changed_files(FileData *fd)
+gboolean file_data_check_changed_files(FileData *fd)
{
gboolean ret = FALSE;
struct stat st;
void file_data_unref(FileData *fd);
#endif
+gboolean file_data_check_changed_files(FileData *fd);
+
void file_data_increment_version(FileData *fd);
gboolean file_data_add_change_info(FileData *fd, FileDataChangeType type, const gchar *src, const gchar *dest);
}
image_set_delay_flip(fs->imd, options->fullscreen.clean_flip);
- image_auto_refresh(fs->imd, fs->normal_imd->auto_refresh_interval);
+ image_auto_refresh_enable(fs->imd, fs->normal_imd->auto_refresh);
if (options->fullscreen.clean_flip)
{
osd_template_insert(vars, "number", g_strdup_printf("%d", n), OSDT_NO_DUP);
osd_template_insert(vars, "total", g_strdup_printf("%d", t), OSDT_NO_DUP);
osd_template_insert(vars, "name", (gchar *) name, OSDT_NONE);
- osd_template_insert(vars, "date", (gchar *) text_from_time(imd->mtime), OSDT_NONE);
- osd_template_insert(vars, "size", text_from_size_abrev(imd->size), OSDT_FREE);
+ osd_template_insert(vars, "date", imd->image_fd ? ((gchar *) text_from_time(imd->image_fd->date)) : "", OSDT_NONE);
+ osd_template_insert(vars, "size", imd->image_fd ? (text_from_size_abrev(imd->image_fd->size)) : g_strdup(""), OSDT_FREE);
osd_template_insert(vars, "zoom", image_zoom_get_as_text(imd), OSDT_FREE);
if (!imd->unknown)
/* the file size at which throttling take place */
#define IMAGE_THROTTLE_THRESHOLD 1048576
-#define IMAGE_AUTO_REFRESH_TIME 3000
-
-
static GList *image_list = NULL;
imd->unknown = TRUE;
}
- imd->size = filesize(imd->image_fd->path);
- imd->mtime = filetime(imd->image_fd->path);
}
else
{
pixbuf = pixbuf_inline(PIXBUF_INLINE_BROKEN);
image_change_pixbuf(imd, pixbuf, zoom);
g_object_unref(pixbuf);
- imd->mtime = filetime(imd->image_fd->path);
}
else
{
image_change_pixbuf(imd, NULL, zoom);
- imd->mtime = 0;
}
imd->unknown = TRUE;
- imd->size = 0;
}
image_update_util(imd);
imd->collection = cd;
imd->collection_info = info;
+ if (imd->auto_refresh && imd->image_fd)
+ file_data_unregister_real_time_monitor(imd->image_fd);
+
file_data_unref(imd->image_fd);
imd->image_fd = file_data_ref(fd);
+
image_change_complete(imd, zoom, TRUE);
image_update_title(imd);
image_state_set(imd, IMAGE_STATE_IMAGE);
+
+ if (imd->auto_refresh && imd->image_fd)
+ file_data_register_real_time_monitor(imd->image_fd);
}
/*
/* merely changes path string, does not change the image! */
void image_set_fd(ImageWindow *imd, FileData *fd)
{
+ if (imd->auto_refresh && imd->image_fd)
+ file_data_unregister_real_time_monitor(imd->image_fd);
+
file_data_unref(imd->image_fd);
imd->image_fd = file_data_ref(fd);
image_update_title(imd);
image_state_set(imd, IMAGE_STATE_IMAGE);
+
+ if (imd->auto_refresh && imd->image_fd)
+ file_data_register_real_time_monitor(imd->image_fd);
}
/* load a new image */
imd->collection = source->collection;
imd->collection_info = source->collection_info;
- imd->size = source->size;
- imd->mtime = source->mtime;
image_loader_free(imd->il);
imd->il = NULL;
}
}
-static gint image_auto_refresh_cb(gpointer data)
+static void image_notify_cb(FileData *fd, NotifyType type, gpointer data)
{
ImageWindow *imd = data;
- time_t newtime;
if (!imd || !image_get_pixbuf(imd) ||
imd->il || !imd->image_fd ||
- !options->update_on_time_change) return TRUE;
+ !options->update_on_time_change) return;
- newtime = filetime(imd->image_fd->path);
- if (newtime > 0 && newtime != imd->mtime)
+ if (type == NOTIFY_TYPE_REREAD && fd == imd->image_fd)
{
- imd->mtime = newtime;
image_reload(imd);
}
-
- return TRUE;
}
-/* image auto refresh on time stamp change, in 1/1000's second, -1 disables */
-
-void image_auto_refresh(ImageWindow *imd, gint interval)
+void image_auto_refresh_enable(ImageWindow *imd, gboolean enable)
{
- if (!imd) return;
- if (pixbuf_renderer_get_tiles((PixbufRenderer *)imd->pr)) return;
-
- if (imd->auto_refresh_id > -1)
- {
- g_source_remove(imd->auto_refresh_id);
- imd->auto_refresh_id = -1;
- imd->auto_refresh_interval = -1;
- }
+ if (!enable && imd->auto_refresh && imd->image_fd)
+ file_data_unregister_real_time_monitor(imd->image_fd);
- if (interval < 0) return;
+ if (enable && !imd->auto_refresh && imd->image_fd)
+ file_data_register_real_time_monitor(imd->image_fd);
- if (interval == 0) interval = IMAGE_AUTO_REFRESH_TIME;
-
- imd->auto_refresh_id = g_timeout_add((guint32)interval, image_auto_refresh_cb, imd);
- imd->auto_refresh_interval = interval;
+ imd->auto_refresh = enable;
}
void image_top_window_set_sync(ImageWindow *imd, gint allow_sync)
{
image_list = g_list_remove(image_list, imd);
+ if (imd->auto_refresh && imd->image_fd)
+ file_data_unregister_real_time_monitor(imd->image_fd);
+
+ file_data_unregister_notify_func(image_notify_cb, imd);
+
image_reset(imd);
image_read_ahead_cancel(imd);
- image_auto_refresh(imd, -1);
file_data_unref(imd->image_fd);
g_free(imd->title);
imd->color_profile_use_image = FALSE;
imd->color_profile_from_image = COLOR_PROFILE_NONE;
- imd->auto_refresh_id = -1;
- imd->auto_refresh_interval = -1;
+ imd->auto_refresh = FALSE;
imd->delay_flip = FALSE;
g_signal_connect(G_OBJECT(imd->pr), "drag",
G_CALLBACK(image_drag_cb), imd);
+ file_data_register_notify_func(image_notify_cb, imd, NOTIFY_PRIORITY_LOW);
+
image_list = g_list_append(image_list, imd);
return imd;
/* read ahead, pass NULL to cancel */
void image_prebuffer_set(ImageWindow *imd, FileData *fd);
-/* auto refresh, interval is 1/1000 sec, 0 uses default, -1 disables */
-void image_auto_refresh(ImageWindow *imd, gint interval);
+/* auto refresh */
+void image_auto_refresh_enable(ImageWindow *imd, gboolean enable);
/* allow top window to be resized ? */
void image_top_window_set_sync(ImageWindow *imd, gint allow_sync);
image_attach_window(vw->imd, vw->window, NULL, GQ_APPNAME, TRUE);
- image_auto_refresh(vw->imd, 0);
+ image_auto_refresh_enable(vw->imd, TRUE);
image_top_window_set_sync(vw->imd, TRUE);
gtk_container_add(GTK_CONTAINER(vw->window), vw->imd->widget);
gtk_label_set_text(GTK_LABEL(lw->info_zoom), text);
g_free(text);
- b = text_from_size(lw->image->size);
+ b = image_get_fd(lw->image) ? text_from_size(image_get_fd(lw->image)->size) : g_strdup("0");
if (lw->image->unknown)
{
image_background_set_color(lw->split_images[i], options->image.use_custom_border_color ? &options->image.border_color : NULL);
- image_auto_refresh(lw->split_images[i], 0);
+ image_auto_refresh_enable(lw->split_images[i], TRUE);
layout_image_dnd_init(lw, i);
image_color_profile_set(lw->split_images[i],
FileData *image_fd;
- gint64 size; /* file size (bytes) */
- time_t mtime; /* file modified time stamp */
gint unknown; /* failed to load image */
ImageLoader *il; /* FIXME - image loader should probably go to FileData, but it must first support
gint prev_color_row;
- gint auto_refresh_id;
- gint auto_refresh_interval;
+ gint auto_refresh;
gint delay_flip;
gint orientation;