[gthumb/ext: 30/79] update the thumbnail only if the file didn't change recently
- From: Paolo Bacchilega <paobac src gnome org>
- To: svn-commits-list gnome org
- Cc:
- Subject: [gthumb/ext: 30/79] update the thumbnail only if the file didn't change recently
- Date: Sun, 2 Aug 2009 20:26:25 +0000 (UTC)
commit d046ca071095735992c7b8da11018e316b380cac
Author: Paolo Bacchilega <paobac src gnome org>
Date: Tue Jun 30 00:55:02 2009 +0200
update the thumbnail only if the file didn't change recently
do not update the file each time a file_changed signal is emitted
to avoid excessive file reloads
gthumb/gth-file-list.c | 49 +++++++++++++++++++++++++++++++++++++++--
gthumb/gth-file-list.h | 2 +-
gthumb/gth-file-source-vfs.c | 2 +-
gthumb/gth-thumb-loader.c | 24 ++------------------
4 files changed, 51 insertions(+), 26 deletions(-)
---
diff --git a/gthumb/gth-file-list.c b/gthumb/gth-file-list.c
index a150d2c..e053604 100644
--- a/gthumb/gth-file-list.c
+++ b/gthumb/gth-file-list.c
@@ -99,6 +99,7 @@ struct _GthFileListPrivateData
gboolean cancel;
gboolean dirty;
guint dirty_event;
+ guint restart_thumb_update;
GList *queue; /* list of GthFileListOp */
GtkCellRenderer *thumbnail_renderer;
GtkCellRenderer *text_renderer;
@@ -162,6 +163,11 @@ _gth_file_list_clear_queue (GthFileList *file_list)
file_list->priv->dirty = FALSE;
}
+ if (file_list->priv->restart_thumb_update != 0) {
+ g_source_remove (file_list->priv->restart_thumb_update);
+ file_list->priv->restart_thumb_update = 0;
+ }
+
g_list_foreach (file_list->priv->queue, (GFunc) gth_file_list_op_free, NULL);
g_list_free (file_list->priv->queue);
file_list->priv->queue = NULL;
@@ -1056,6 +1062,36 @@ update_thumbs_stopped (gpointer callback_data)
}
+static gboolean
+restart_thumb_update_cb (gpointer data)
+{
+ GthFileList *file_list = data;
+
+ g_source_remove (file_list->priv->restart_thumb_update);
+ file_list->priv->restart_thumb_update = 0;
+
+ if (file_list->priv->queue == NULL)
+ _gth_file_list_update_next_thumb (file_list);
+
+ return FALSE;
+}
+
+
+static gboolean
+can_create_file_thumbnail (GthFileData *file_data,
+ GTimeVal *current_time,
+ gboolean *young_file_found)
+{
+ gboolean young_file;
+
+ young_file = (current_time->tv_sec - gth_file_data_get_mtime (file_data)) <= 1;
+ if (young_file)
+ *young_file_found = TRUE;
+
+ return ! file_data->error && ! young_file;
+}
+
+
static void
_gth_file_list_update_next_thumb (GthFileList *file_list)
{
@@ -1067,6 +1103,8 @@ _gth_file_list_update_next_thumb (GthFileList *file_list)
GthFileData *fd = NULL;
GList *list, *scan;
int new_pos = -1;
+ GTimeVal current_time;
+ gboolean young_file_found = FALSE;
if (file_list->priv->cancel || (file_list->priv->queue != NULL)) {
g_idle_add (update_thumbs_stopped, file_list);
@@ -1098,9 +1136,11 @@ _gth_file_list_update_next_thumb (GthFileList *file_list)
/* Find a not loaded thumbnail among the visible images. */
+ g_get_current_time (¤t_time);
+
while (pos <= last_pos) {
fd = scan->data;
- if (! fd->thumb_loaded && ! fd->error) {
+ if (! fd->thumb_loaded && can_create_file_thumbnail (fd, ¤t_time, &young_file_found)) {
new_pos = pos;
break;
}
@@ -1121,7 +1161,7 @@ _gth_file_list_update_next_thumb (GthFileList *file_list)
scan = g_list_nth (list, pos);
while (scan && ((pos - last_pos) <= N_LOOKAHEAD)) {
fd = scan->data;
- if (! fd->thumb_created && ! fd->error) {
+ if (! fd->thumb_created && can_create_file_thumbnail (fd, ¤t_time, &young_file_found)) {
new_pos = pos;
break;
}
@@ -1138,7 +1178,7 @@ _gth_file_list_update_next_thumb (GthFileList *file_list)
scan = g_list_nth (list, pos);
while (scan && ((first_pos - pos) <= N_LOOKAHEAD)) {
fd = scan->data;
- if (! fd->thumb_created && ! fd->error) {
+ if (! fd->thumb_created && can_create_file_thumbnail (fd, ¤t_time, &young_file_found)) {
new_pos = pos;
break;
}
@@ -1155,12 +1195,15 @@ _gth_file_list_update_next_thumb (GthFileList *file_list)
if (new_pos == -1) {
_gth_file_list_thumbs_completed (file_list);
+ if (young_file_found && (file_list->priv->restart_thumb_update == 0))
+ file_list->priv->restart_thumb_update = g_timeout_add (1500, restart_thumb_update_cb, file_list);
return;
}
/* We create thumbnail files for all images in the folder, but we only
load the visible ones (and N_LOOKAHEAD before and N_LOOKAHEAD after the visible range),
to minimize memory consumption in large folders. */
+
file_list->priv->update_thumb_in_view = (new_pos >= (first_pos - N_LOOKAHEAD)) &&
(new_pos <= (last_pos + N_LOOKAHEAD));
file_list->priv->thumb_pos = new_pos;
diff --git a/gthumb/gth-file-list.h b/gthumb/gth-file-list.h
index 222ccc2..cca125f 100644
--- a/gthumb/gth-file-list.h
+++ b/gthumb/gth-file-list.h
@@ -76,7 +76,7 @@ void gth_file_list_set_sort_func (GthFileList *file_list,
gboolean inverse_sort);
void gth_file_list_enable_thumbs (GthFileList *file_list,
gboolean enable);
-void gth_file_list_set_thumb_size (GthFileList *file_list,
+void gth_file_list_set_thumb_size (GthFileList *file_list,
int size);
GtkWidget * gth_file_list_get_view (GthFileList *file_list);
int gth_file_list_first_file (GthFileList *file_list,
diff --git a/gthumb/gth-file-source-vfs.c b/gthumb/gth-file-source-vfs.c
index f9352ad..97f2ade 100644
--- a/gthumb/gth-file-source-vfs.c
+++ b/gthumb/gth-file-source-vfs.c
@@ -34,7 +34,7 @@
#define GTH_MONITOR_N_EVENTS 3
#define MONITOR_UPDATE_DELAY 500
-#define DEBUG_MONITOR 1
+#undef DEBUG_MONITOR
struct _GthFileSourceVfsPrivate
{
diff --git a/gthumb/gth-thumb-loader.c b/gthumb/gth-thumb-loader.c
index 0baa2c7..1525f2f 100644
--- a/gthumb/gth-thumb-loader.c
+++ b/gthumb/gth-thumb-loader.c
@@ -45,7 +45,7 @@
#define THUMBNAIL_LARGE_SIZE 256
#define THUMBNAIL_NORMAL_SIZE 128
#define THUMBNAIL_DIR_PERMISSIONS 0700
-#define KILL_THUMBNAILER_DELAY 3000
+#define MAX_THUMBNAILER_LIFETIME 2000 /* kill the thumbnailer after this amount of time*/
struct _GthThumbLoaderPrivateData
{
@@ -468,7 +468,7 @@ image_loader_ready_cb (GthImageLoader *iloader,
tloader->priv->thumbnailer_watch = g_child_watch_add (tloader->priv->thumbnailer_pid,
watch_thumbnailer_cb,
tloader);
- tloader->priv->thumbnailer_timeout = g_timeout_add (KILL_THUMBNAILER_DELAY,
+ tloader->priv->thumbnailer_timeout = g_timeout_add (MAX_THUMBNAILER_LIFETIME,
kill_thumbnailer_cb,
tloader);
}
@@ -671,34 +671,16 @@ gth_thumb_loader_load__step2 (GthThumbLoader *tloader)
g_return_if_fail (tloader != NULL);
- /*if ((tloader->priv->file == NULL) || ! gth_file_data_is_readable (tloader->priv->file)) {
- g_signal_emit (G_OBJECT (tloader),
- gth_thumb_loader_signals[READY],
- 0,
- g_error_new_literal (GTHUMB_ERROR, 0, "cannot read the file"));
- return;
- }*/
-
if (tloader->priv->use_cache) {
char *uri;
time_t mtime;
uri = g_file_get_uri (tloader->priv->file->file);
mtime = gth_file_data_get_mtime (tloader->priv->file);
-
cache_path = gnome_desktop_thumbnail_factory_lookup (tloader->priv->thumb_factory, uri, mtime);
-
-/*debug (DEBUG_INFO, "thumbnail for %s: %s\n", uri, cache_path); FIXME: delete when done */
-
if ((cache_path == NULL)
- && gnome_desktop_thumbnail_factory_has_valid_failed_thumbnail (tloader->priv->thumb_factory, uri, mtime)
- && ((time (NULL) - mtime) > (time_t) 5))
+ && gnome_desktop_thumbnail_factory_has_valid_failed_thumbnail (tloader->priv->thumb_factory, uri, mtime))
{
- /* Use the existing "failed" thumbnail, if it is over
- 5 seconds old. Otherwise, try to thumbnail it again.
- The minimum age requirement addresses bug 432759,
- which occurs when a device like a scanner saves a file
- slowly in chunks. */
g_signal_emit (G_OBJECT (tloader),
gth_thumb_loader_signals[READY],
0,
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]