static PyObject * _wrap_gimp_thumbnail_peek_thumb(PyGObject *self, PyObject *args, PyObject *kwargs) { static char *kwlist[] = { "size", NULL }; PyObject *py_size = NULL; gint ret; GimpThumbSize size; if (!PyArg_ParseTupleAndKeywords(args, kwargs,"O:Gimp.Thumbnail.peek_thumb", kwlist, &py_size)) return NULL; if (pyg_enum_get_value(GIMP_TYPE_THUMB_SIZE, py_size, (gpointer)&size)) return NULL; ret = gimp_thumbnail_peek_thumb(GIMP_THUMBNAIL(self->obj), size); return pyg_enum_from_gtype(GIMP_TYPE_THUMB_STATE, ret); }
static void gimp_thumb_box_create_thumbnail (GimpThumbBox *box, const gchar *uri, GimpThumbnailSize size, gboolean force, GimpProgress *progress) { gchar *filename = file_utils_filename_from_uri (uri); GimpThumbnail *thumb; gchar *basename; if (filename) { gboolean regular = g_file_test (filename, G_FILE_TEST_IS_REGULAR); g_free (filename); if (! regular) return; } thumb = gimp_imagefile_get_thumbnail (box->imagefile); basename = file_utils_uri_display_basename (uri); gtk_label_set_text (GTK_LABEL (box->filename), basename); g_free (basename); gimp_object_set_name (GIMP_OBJECT (box->imagefile), uri); if (force || (gimp_thumbnail_peek_thumb (thumb, size) < GIMP_THUMB_STATE_FAILED && ! gimp_thumbnail_has_failed (thumb))) { GError *error = NULL; if (! gimp_imagefile_create_thumbnail (box->imagefile, box->context, progress, size, ! force, &error)) { gimp_message_literal (box->context->gimp, G_OBJECT (progress), GIMP_MESSAGE_ERROR, error->message); g_clear_error (&error); } } }
/** * gimp_thumbnail_check_thumb: * @thumbnail: a #GimpThumbnail object * @size: the preferred size of the thumbnail image * * Checks if a thumbnail file for the @thumbnail exists, loads it and * verifies it is valid and uptodate for the image file asosciated * with the @thumbnail. * * Return value: the thumbnail's #GimpThumbState after the update * * Since: 2.2 **/ GimpThumbState gimp_thumbnail_check_thumb (GimpThumbnail *thumbnail, GimpThumbSize size) { GdkPixbuf *pixbuf; g_return_val_if_fail (GIMP_IS_THUMBNAIL (thumbnail), FALSE); GIMP_THUMB_DEBUG_CALL (thumbnail); if (gimp_thumbnail_peek_thumb (thumbnail, size) == GIMP_THUMB_STATE_OK) return GIMP_THUMB_STATE_OK; pixbuf = gimp_thumbnail_load_thumb (thumbnail, size, NULL); if (pixbuf) g_object_unref (pixbuf); return thumbnail->thumb_state; }
/** * gimp_thumbnail_load_thumb: * @thumbnail: a #GimpThumbnail object * @size: the preferred #GimpThumbSize for the preview * @error: return location for possible errors * * Attempts to load a thumbnail preview for the image associated with * @thumbnail. Before you use this function you need need to set an * image location using gimp_thumbnail_set_uri() or * gimp_thumbnail_set_filename(). You can also peek at the thumb * before loading it using gimp_thumbnail_peek_thumb. * * This function will return the best matching pixbuf for the * specified @size. It returns the pixbuf as loaded from disk. It is * left to the caller to scale it to the desired size. The returned * pixbuf may also represent an outdated preview of the image file. * In order to verify if the preview is uptodate, you should check the * "thumb_state" property after calling this function. * * Return value: a preview pixbuf or %NULL if no thumbnail was found **/ GdkPixbuf * gimp_thumbnail_load_thumb (GimpThumbnail *thumbnail, GimpThumbSize size, GError **error) { GimpThumbState state; GdkPixbuf *pixbuf; const gchar *option; gint64 image_mtime; gint64 image_size; g_return_val_if_fail (GIMP_IS_THUMBNAIL (thumbnail), NULL); GIMP_THUMB_DEBUG_CALL (thumbnail); if (! thumbnail->image_uri) return NULL; state = gimp_thumbnail_peek_thumb (thumbnail, size); if (state < GIMP_THUMB_STATE_EXISTS || state == GIMP_THUMB_STATE_FAILED) return NULL; pixbuf = gdk_pixbuf_new_from_file (thumbnail->thumb_filename, NULL); if (! pixbuf) return NULL; #ifdef GIMP_THUMB_DEBUG g_printerr ("thumbnail loaded from %s\n", thumbnail->thumb_filename); #endif g_object_freeze_notify (G_OBJECT (thumbnail)); /* URI and mtime from the thumbnail need to match our file */ option = gdk_pixbuf_get_option (pixbuf, TAG_THUMB_URI); if (!option) goto finish; if (strcmp (option, thumbnail->image_uri)) { /* might be a local thumbnail, try if the local part matches */ const gchar *baseuri = strrchr (thumbnail->image_uri, '/'); if (!baseuri || strcmp (option, baseuri)) goto finish; } state = GIMP_THUMB_STATE_OLD; option = gdk_pixbuf_get_option (pixbuf, TAG_THUMB_MTIME); if (!option || sscanf (option, "%" G_GINT64_FORMAT, &image_mtime) != 1) goto finish; option = gdk_pixbuf_get_option (pixbuf, TAG_THUMB_FILESIZE); if (option && sscanf (option, "%" G_GINT64_FORMAT, &image_size) != 1) goto finish; /* TAG_THUMB_FILESIZE is optional but must match if present */ if (image_mtime == thumbnail->image_mtime && (option == NULL || image_size == thumbnail->image_filesize)) { if (thumbnail->thumb_size == GIMP_THUMB_SIZE_FAIL) state = GIMP_THUMB_STATE_FAILED; else state = GIMP_THUMB_STATE_OK; } if (state == GIMP_THUMB_STATE_FAILED) gimp_thumbnail_reset_info (thumbnail); else gimp_thumbnail_set_info_from_pixbuf (thumbnail, pixbuf); finish: if (thumbnail->thumb_size == GIMP_THUMB_SIZE_FAIL || (state != GIMP_THUMB_STATE_OLD && state != GIMP_THUMB_STATE_OK)) { g_object_unref (pixbuf); pixbuf = NULL; } g_object_set (thumbnail, "thumb-state", state, NULL); g_object_thaw_notify (G_OBJECT (thumbnail)); return pixbuf; }