--- ../../dl/eog-2.32.1/src/eog-thumbnail.c 2010-11-13 05:16:52.000000000 -0800 +++ eog-thumbnail.c 2011-03-28 03:18:35.000000000 -0700 @@ -33,14 +33,27 @@ #endif #include +#include + #include "eog-thumbnail.h" #include "eog-list-store.h" +#include "eog-config-keys.h" #include "eog-debug.h" #define EOG_THUMB_ERROR eog_thumb_error_quark () static GnomeDesktopThumbnailFactory *factory = NULL; static GdkPixbuf *frame = NULL; +static GConfClient* eog_thumb_gconf_client = NULL; +static GdkPixbuf* eog_missing_image = NULL; + +typedef enum { + EOG_THUMBGEN_NEVER, + EOG_THUMBGEN_RAM, + EOG_THUMBGEN_DISK, +} EogThumbPolicy; + +static EogThumbPolicy eog_thumb_policy = EOG_THUMBGEN_RAM; typedef enum { EOG_THUMB_ERROR_VFS, @@ -437,6 +450,11 @@ GdkPixbuf* eog_thumbnail_load (EogImage *image, GError **error) { + if (eog_thumb_policy == EOG_THUMBGEN_NEVER) { + g_object_ref( eog_missing_image ); + return eog_missing_image; + } + GdkPixbuf *thumb = NULL; GFile *file; EogThumbData *data; @@ -456,7 +474,11 @@ (data->failed_thumb_exists && gnome_desktop_thumbnail_factory_has_valid_failed_thumbnail (factory, data->uri_str, data->mtime))) { eog_debug_message (DEBUG_THUMBNAIL, "%s: bad permissions or valid failed thumbnail present",data->uri_str); set_thumb_error (error, EOG_THUMB_ERROR_GENERIC, "Thumbnail creation failed"); +/* returning NULL here causes the Properties dialog to display incorrect info return NULL; +*/ + g_object_ref( eog_missing_image ); + return eog_missing_image; } /* check if there is already a valid cached thumbnail */ @@ -479,17 +501,21 @@ thumb = gnome_desktop_thumbnail_factory_generate_thumbnail (factory, data->uri_str, data->mime_type); } - if (thumb != NULL) { - /* Save the new thumbnail */ - gnome_desktop_thumbnail_factory_save_thumbnail (factory, thumb, data->uri_str, data->mtime); - eog_debug_message (DEBUG_THUMBNAIL, "%s: normal thumbnail saved",data->uri_str); - } else { - /* Save a failed thumbnail, to stop further thumbnail attempts */ - gnome_desktop_thumbnail_factory_create_failed_thumbnail (factory, data->uri_str, data->mtime); - eog_debug_message (DEBUG_THUMBNAIL, "%s: failed thumbnail saved",data->uri_str); - set_thumb_error (error, EOG_THUMB_ERROR_GENERIC, "Thumbnail creation failed"); + if (eog_thumb_policy == EOG_THUMBGEN_DISK) { + if (thumb != NULL) { + /* Save the new thumbnail */ + gnome_desktop_thumbnail_factory_save_thumbnail (factory, thumb, data->uri_str, data->mtime); + eog_debug_message (DEBUG_THUMBNAIL, "%s: normal thumbnail saved",data->uri_str); + } else { + /* Save a failed thumbnail, to stop further thumbnail attempts */ + gnome_desktop_thumbnail_factory_create_failed_thumbnail (factory, data->uri_str, data->mtime); + eog_debug_message (DEBUG_THUMBNAIL, "%s: failed thumbnail saved",data->uri_str); + set_thumb_error (error, EOG_THUMB_ERROR_GENERIC, "Thumbnail creation failed"); + } } } +/* this also probably needs an else{} with the same eog_missing_image workaround as the case above, for the same reasons +*/ eog_thumb_data_free (data); @@ -506,4 +532,60 @@ if (frame == NULL) { frame = gdk_pixbuf_new_from_file (EOG_DATA_DIR "/pixmaps/thumbnail-frame.png", NULL); } + + g_assert( !eog_missing_image && "Logic Error: eog_thumbnail_init called multiple times" ); + + GError* error = NULL; + + if (!eog_missing_image) { + GtkIconTheme* theme = gtk_icon_theme_get_default(); + + eog_missing_image = gtk_icon_theme_load_icon( theme, "image-missing", EOG_LIST_STORE_THUMB_SIZE, 0, &error ); + + if (error) { + g_warning( "Couldn't load icon: %s", error->message ); + g_error_free(error); + } + } + +/* NOTE +this has file scope in case someone wants to get fancy with changing it while eog is running, but if they're going to do that it should be presented in a dialog anyway. +since the complaint is simply that there's no way to stop eog spamming thumbnails, MHO is that people just want to be able to turn it off permanently, so this is fine. +since the multiple-init assert above hasn't tripped, this should probably just be a local +*/ + if (!eog_thumb_gconf_client) { + eog_thumb_gconf_client = gconf_client_get_default(); +/* FIXME +http://library.gnome.org/devel/gconf/stable/gconf-gconf-client.html says: +"It's important to call g_type_init() before using this GObject, to initialize the type system." +since eog doesn't do that, either eog has a bug or the docs are wrong. i don't know which, so someone from gnome needs to sort that out. +*/ + +/* NOTE +eog-config-keys.h has 30 copypasted "root" keypaths. when you decide where to put this one, you might want to correct those to use concatenation, like so: + #define EOG_CONF_PREFS_DIR EOG_CONF_DIR "/preferences/" +(and you might as well correct the definition of EOG_CONF_DIR to include the trailing slash while you're there) +*/ + +// gconf-editor doesn't let you add directories, so this has to go in the (app) root for now + GConfEntry* k = gconf_client_get_entry( eog_thumb_gconf_client, EOG_CONF_DIR"/thumbnail_policy", NULL, TRUE, NULL ); +/* NOTE +gnome docs for gconf_entry_get_value say "The returned value is not a copy, and should not be freed or modified." +there's a word for that: "const". fix the api and you won't need the note... +*/ + const GConfValue* v = gconf_entry_get_value(k); +/* NOTE +i've never used gconf calls and i'm not going to add a default (which should be 2 if you want to keep the current behavior) to the schema because (a) i'd probably get it wrong, and (b) this keeps all the changes to a single file. +this will mimic that default until the maintainers deal with it. +*/ + if (v && (v->type == GCONF_VALUE_INT)) + eog_thumb_policy = gconf_value_get_int(v); + else + eog_thumb_policy = EOG_THUMBGEN_DISK; + gconf_entry_unref(k); + g_object_unref(eog_thumb_gconf_client); + eog_thumb_gconf_client = NULL; + } + } +