2003-11-26 09:12:36 +08:00
|
|
|
/* LIBGIMP - The GIMP Library
|
|
|
|
* Copyright (C) 1995-1997 Peter Mattis and Spencer Kimball
|
|
|
|
*
|
|
|
|
* Thumbnail handling according to the Thumbnail Managing Standard.
|
|
|
|
* http://triq.net/~pearl/thumbnail-spec/
|
|
|
|
*
|
|
|
|
* Copyright (C) 2001-2003 Sven Neumann <sven@gimp.org>
|
|
|
|
* Michael Natterer <mitch@gimp.org>
|
|
|
|
*
|
|
|
|
* This library is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU Lesser General Public
|
|
|
|
* License as published by the Free Software Foundation; either
|
|
|
|
* version 2 of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This library is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
* Lesser General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Lesser General Public
|
|
|
|
* License along with this library; if not, write to the
|
|
|
|
* Free Software Foundation, Inc., 59 Temple Place - Suite 330,
|
|
|
|
* Boston, MA 02111-1307, USA.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "config.h"
|
|
|
|
|
|
|
|
#include <string.h>
|
|
|
|
#include <stdio.h>
|
2003-11-26 18:26:37 +08:00
|
|
|
#include <errno.h>
|
|
|
|
#include <sys/types.h>
|
|
|
|
#include <sys/stat.h>
|
2003-11-26 09:12:36 +08:00
|
|
|
|
|
|
|
#include <gdk-pixbuf/gdk-pixbuf.h>
|
|
|
|
|
2003-12-13 09:35:19 +08:00
|
|
|
#ifdef G_OS_WIN32
|
|
|
|
#include <libgimpbase/gimpwin32-io.h>
|
|
|
|
#endif
|
|
|
|
|
2003-11-26 09:12:36 +08:00
|
|
|
#include "gimpthumb-types.h"
|
|
|
|
#include "gimpthumb-utils.h"
|
|
|
|
#include "gimpthumbnail.h"
|
|
|
|
|
2003-12-02 10:06:20 +08:00
|
|
|
#include "libgimp/libgimp-intl.h"
|
|
|
|
|
2003-11-26 09:12:36 +08:00
|
|
|
|
2003-11-27 00:49:53 +08:00
|
|
|
#define TAG_DESCRIPTION "tEXt::Description"
|
|
|
|
#define TAG_SOFTWARE "tEXt::Software"
|
|
|
|
#define TAG_THUMB_URI "tEXt::Thumb::URI"
|
|
|
|
#define TAG_THUMB_MTIME "tEXt::Thumb::MTime"
|
|
|
|
#define TAG_THUMB_FILESIZE "tEXt::Thumb::Size"
|
|
|
|
#define TAG_THUMB_IMAGE_WIDTH "tEXt::Thumb::Image::Width"
|
|
|
|
#define TAG_THUMB_IMAGE_HEIGHT "tEXt::Thumb::Image::Height"
|
|
|
|
#define TAG_THUMB_GIMP_TYPE "tEXt::Thumb::X-GIMP::Type"
|
|
|
|
#define TAG_THUMB_GIMP_LAYERS "tEXt::Thumb::X-GIMP::Layers"
|
2003-11-26 09:12:36 +08:00
|
|
|
|
|
|
|
|
|
|
|
enum
|
|
|
|
{
|
|
|
|
PROP_0,
|
2003-11-27 00:49:53 +08:00
|
|
|
PROP_IMAGE_STATE,
|
|
|
|
PROP_IMAGE_URI,
|
|
|
|
PROP_IMAGE_MTIME,
|
|
|
|
PROP_IMAGE_FILESIZE,
|
|
|
|
PROP_IMAGE_WIDTH,
|
|
|
|
PROP_IMAGE_HEIGHT,
|
|
|
|
PROP_IMAGE_TYPE,
|
|
|
|
PROP_IMAGE_NUM_LAYERS,
|
|
|
|
PROP_THUMB_STATE
|
2003-11-26 09:12:36 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
|
2003-12-08 22:15:25 +08:00
|
|
|
static void gimp_thumbnail_class_init (GimpThumbnailClass *klass);
|
|
|
|
static void gimp_thumbnail_init (GimpThumbnail *thumbnail);
|
|
|
|
static void gimp_thumbnail_finalize (GObject *object);
|
|
|
|
static void gimp_thumbnail_set_property (GObject *object,
|
|
|
|
guint property_id,
|
|
|
|
const GValue *value,
|
|
|
|
GParamSpec *pspec);
|
|
|
|
static void gimp_thumbnail_get_property (GObject *object,
|
|
|
|
guint property_id,
|
|
|
|
GValue *value,
|
|
|
|
GParamSpec *pspec);
|
|
|
|
static void gimp_thumbnail_invalidate_thumb (GimpThumbnail *thumbnail);
|
|
|
|
static void gimp_thumbnail_reset_info (GimpThumbnail *thumbnail);
|
|
|
|
|
|
|
|
static void gimp_thumbnail_update_image (GimpThumbnail *thumbnail);
|
2003-12-14 21:21:44 +08:00
|
|
|
static void gimp_thumbnail_update_thumb (GimpThumbnail *thumbnail,
|
|
|
|
GimpThumbSize size);
|
2003-11-26 09:12:36 +08:00
|
|
|
|
|
|
|
|
|
|
|
static GObjectClass *parent_class = NULL;
|
|
|
|
|
|
|
|
|
|
|
|
GType
|
|
|
|
gimp_thumbnail_get_type (void)
|
|
|
|
{
|
|
|
|
static GType thumbnail_type = 0;
|
|
|
|
|
|
|
|
if (!thumbnail_type)
|
|
|
|
{
|
|
|
|
static const GTypeInfo thumbnail_info =
|
|
|
|
{
|
|
|
|
sizeof (GimpThumbnailClass),
|
|
|
|
(GBaseInitFunc) NULL,
|
|
|
|
(GBaseFinalizeFunc) NULL,
|
|
|
|
(GClassInitFunc) gimp_thumbnail_class_init,
|
|
|
|
NULL, /* class_finalize */
|
|
|
|
NULL, /* class_data */
|
|
|
|
sizeof (GimpThumbnail),
|
|
|
|
0, /* n_preallocs */
|
|
|
|
(GInstanceInitFunc) gimp_thumbnail_init,
|
|
|
|
};
|
|
|
|
|
|
|
|
thumbnail_type = g_type_register_static (G_TYPE_OBJECT,
|
|
|
|
"GimpThumbnail",
|
|
|
|
&thumbnail_info, 0);
|
|
|
|
}
|
|
|
|
|
|
|
|
return thumbnail_type;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gimp_thumbnail_class_init (GimpThumbnailClass *klass)
|
|
|
|
{
|
|
|
|
GObjectClass *object_class;
|
|
|
|
|
|
|
|
parent_class = g_type_class_peek_parent (klass);
|
|
|
|
|
|
|
|
object_class = G_OBJECT_CLASS (klass);
|
|
|
|
|
|
|
|
object_class->finalize = gimp_thumbnail_finalize;
|
|
|
|
object_class->set_property = gimp_thumbnail_set_property;
|
|
|
|
object_class->get_property = gimp_thumbnail_get_property;
|
|
|
|
|
|
|
|
g_object_class_install_property (object_class,
|
2003-11-27 00:49:53 +08:00
|
|
|
PROP_IMAGE_STATE,
|
|
|
|
g_param_spec_enum ("image-state", NULL,
|
2003-12-16 07:22:50 +08:00
|
|
|
"State of the image associated to the thumbnail object",
|
2003-11-26 09:12:36 +08:00
|
|
|
GIMP_TYPE_THUMB_STATE,
|
|
|
|
GIMP_THUMB_STATE_UNKNOWN,
|
|
|
|
G_PARAM_READWRITE));
|
|
|
|
g_object_class_install_property (object_class,
|
2003-11-27 00:49:53 +08:00
|
|
|
PROP_IMAGE_URI,
|
|
|
|
g_param_spec_string ("image-uri", NULL,
|
2003-12-16 07:22:50 +08:00
|
|
|
"URI of the image file",
|
2003-11-27 00:49:53 +08:00
|
|
|
NULL,
|
|
|
|
G_PARAM_READWRITE));
|
|
|
|
g_object_class_install_property (object_class,
|
|
|
|
PROP_IMAGE_MTIME,
|
2003-11-26 09:12:36 +08:00
|
|
|
g_param_spec_int64 ("image-mtime", NULL,
|
2003-12-16 07:22:50 +08:00
|
|
|
"Modification time of the image file in seconds since the Epoch",
|
2003-11-26 09:12:36 +08:00
|
|
|
0, G_MAXINT64, 0,
|
|
|
|
G_PARAM_READWRITE));
|
|
|
|
g_object_class_install_property (object_class,
|
2003-11-27 00:49:53 +08:00
|
|
|
PROP_IMAGE_FILESIZE,
|
2003-11-26 09:12:36 +08:00
|
|
|
g_param_spec_int64 ("image-filesize", NULL,
|
2003-12-16 07:22:50 +08:00
|
|
|
"Size of the image file in bytes",
|
2003-11-26 09:12:36 +08:00
|
|
|
0, G_MAXINT64, 0,
|
|
|
|
G_PARAM_READWRITE));
|
|
|
|
g_object_class_install_property (object_class,
|
2003-11-27 00:49:53 +08:00
|
|
|
PROP_IMAGE_WIDTH,
|
2003-11-26 09:12:36 +08:00
|
|
|
g_param_spec_int ("image-width", NULL,
|
2003-12-16 07:22:50 +08:00
|
|
|
"Width of the image in pixels",
|
2003-11-26 09:12:36 +08:00
|
|
|
0, G_MAXINT, 0,
|
|
|
|
G_PARAM_READWRITE));
|
|
|
|
g_object_class_install_property (object_class,
|
2003-11-27 00:49:53 +08:00
|
|
|
PROP_IMAGE_HEIGHT,
|
2003-11-26 09:12:36 +08:00
|
|
|
g_param_spec_int ("image-height", NULL,
|
2003-12-16 07:22:50 +08:00
|
|
|
"Height of the image in pixels",
|
2003-11-26 09:12:36 +08:00
|
|
|
0, G_MAXINT, 0,
|
|
|
|
G_PARAM_READWRITE));
|
|
|
|
g_object_class_install_property (object_class,
|
2003-11-27 00:49:53 +08:00
|
|
|
PROP_IMAGE_TYPE,
|
2003-11-26 09:12:36 +08:00
|
|
|
g_param_spec_string ("image-type", NULL,
|
2003-12-16 07:22:50 +08:00
|
|
|
"String describing the type of the image format",
|
2003-11-26 09:12:36 +08:00
|
|
|
NULL,
|
|
|
|
G_PARAM_READWRITE));
|
|
|
|
g_object_class_install_property (object_class,
|
2003-11-27 00:49:53 +08:00
|
|
|
PROP_IMAGE_NUM_LAYERS,
|
2003-11-26 09:12:36 +08:00
|
|
|
g_param_spec_int ("image-num-layers", NULL,
|
2003-12-16 07:22:50 +08:00
|
|
|
"The number of layers in the image",
|
2003-11-26 09:12:36 +08:00
|
|
|
0, G_MAXINT, 0,
|
|
|
|
G_PARAM_READWRITE));
|
2003-11-27 00:49:53 +08:00
|
|
|
g_object_class_install_property (object_class,
|
|
|
|
PROP_THUMB_STATE,
|
|
|
|
g_param_spec_enum ("thumb-state", NULL,
|
2003-12-16 07:22:50 +08:00
|
|
|
"State of the thumbnail file",
|
2003-11-27 00:49:53 +08:00
|
|
|
GIMP_TYPE_THUMB_STATE,
|
|
|
|
GIMP_THUMB_STATE_UNKNOWN,
|
|
|
|
G_PARAM_READWRITE));
|
2003-11-26 09:12:36 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gimp_thumbnail_init (GimpThumbnail *thumbnail)
|
|
|
|
{
|
2003-11-27 00:49:53 +08:00
|
|
|
thumbnail->image_state = GIMP_THUMB_STATE_UNKNOWN;
|
|
|
|
thumbnail->image_uri = NULL;
|
2003-11-26 09:12:36 +08:00
|
|
|
thumbnail->image_filename = NULL;
|
|
|
|
thumbnail->image_mtime = 0;
|
|
|
|
thumbnail->image_filesize = 0;
|
|
|
|
thumbnail->image_width = 0;
|
|
|
|
thumbnail->image_height = 0;
|
|
|
|
thumbnail->image_type = 0;
|
|
|
|
thumbnail->image_num_layers = 0;
|
2003-11-27 00:49:53 +08:00
|
|
|
|
|
|
|
thumbnail->thumb_state = GIMP_THUMB_STATE_UNKNOWN;
|
|
|
|
thumbnail->thumb_filename = NULL;
|
|
|
|
thumbnail->thumb_mtime = 0;
|
|
|
|
thumbnail->thumb_filesize = 0;
|
2003-11-26 09:12:36 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gimp_thumbnail_finalize (GObject *object)
|
|
|
|
{
|
|
|
|
GimpThumbnail *thumbnail = GIMP_THUMBNAIL (object);
|
|
|
|
|
2003-11-27 00:49:53 +08:00
|
|
|
if (thumbnail->image_uri)
|
2003-11-26 09:12:36 +08:00
|
|
|
{
|
2003-11-27 00:49:53 +08:00
|
|
|
g_free (thumbnail->image_uri);
|
|
|
|
thumbnail->image_uri = NULL;
|
2003-11-26 09:12:36 +08:00
|
|
|
}
|
|
|
|
if (thumbnail->image_filename)
|
|
|
|
{
|
|
|
|
g_free (thumbnail->image_filename);
|
|
|
|
thumbnail->image_filename = NULL;
|
|
|
|
}
|
|
|
|
if (thumbnail->image_type)
|
|
|
|
{
|
|
|
|
g_free (thumbnail->image_type);
|
|
|
|
thumbnail->image_type = NULL;
|
|
|
|
}
|
2003-11-27 00:49:53 +08:00
|
|
|
if (thumbnail->thumb_filename)
|
|
|
|
{
|
|
|
|
g_free (thumbnail->thumb_filename);
|
|
|
|
thumbnail->thumb_filename = NULL;
|
|
|
|
}
|
2003-11-26 09:12:36 +08:00
|
|
|
|
|
|
|
G_OBJECT_CLASS (parent_class)->finalize (object);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gimp_thumbnail_set_property (GObject *object,
|
|
|
|
guint property_id,
|
|
|
|
const GValue *value,
|
|
|
|
GParamSpec *pspec)
|
|
|
|
{
|
|
|
|
GimpThumbnail *thumbnail = GIMP_THUMBNAIL (object);
|
2003-11-27 00:49:53 +08:00
|
|
|
gint64 int_value;
|
2003-11-26 09:12:36 +08:00
|
|
|
|
|
|
|
switch (property_id)
|
|
|
|
{
|
2003-11-27 00:49:53 +08:00
|
|
|
case PROP_IMAGE_STATE:
|
|
|
|
thumbnail->image_state = g_value_get_enum (value);
|
|
|
|
break;
|
|
|
|
case PROP_IMAGE_URI:
|
2003-11-26 09:12:36 +08:00
|
|
|
gimp_thumbnail_set_uri (GIMP_THUMBNAIL (object),
|
|
|
|
g_value_get_string (value));
|
|
|
|
break;
|
2003-11-27 00:49:53 +08:00
|
|
|
case PROP_IMAGE_MTIME:
|
|
|
|
int_value = g_value_get_int64 (value);
|
|
|
|
if (thumbnail->image_mtime != int_value)
|
|
|
|
{
|
|
|
|
thumbnail->image_mtime = int_value;
|
|
|
|
gimp_thumbnail_invalidate_thumb (thumbnail);
|
|
|
|
}
|
2003-11-26 09:12:36 +08:00
|
|
|
break;
|
2003-11-27 00:49:53 +08:00
|
|
|
case PROP_IMAGE_FILESIZE:
|
|
|
|
int_value = g_value_get_int64 (value);
|
|
|
|
if (thumbnail->image_filesize != int_value)
|
|
|
|
{
|
|
|
|
thumbnail->image_filesize = int_value;
|
|
|
|
gimp_thumbnail_invalidate_thumb (thumbnail);
|
|
|
|
}
|
2003-11-26 09:12:36 +08:00
|
|
|
break;
|
2003-11-27 00:49:53 +08:00
|
|
|
case PROP_IMAGE_WIDTH:
|
2003-11-26 09:12:36 +08:00
|
|
|
thumbnail->image_width = g_value_get_int (value);
|
|
|
|
break;
|
2003-11-27 00:49:53 +08:00
|
|
|
case PROP_IMAGE_HEIGHT:
|
2003-11-26 09:12:36 +08:00
|
|
|
thumbnail->image_height = g_value_get_int (value);
|
|
|
|
break;
|
2003-11-27 00:49:53 +08:00
|
|
|
case PROP_IMAGE_TYPE:
|
2003-11-26 09:12:36 +08:00
|
|
|
g_free (thumbnail->image_type);
|
|
|
|
thumbnail->image_type = g_value_dup_string (value);
|
|
|
|
break;
|
2003-11-27 00:49:53 +08:00
|
|
|
case PROP_IMAGE_NUM_LAYERS:
|
2003-11-26 09:12:36 +08:00
|
|
|
thumbnail->image_num_layers = g_value_get_int (value);
|
|
|
|
break;
|
2003-11-27 00:49:53 +08:00
|
|
|
case PROP_THUMB_STATE:
|
|
|
|
thumbnail->thumb_state = g_value_get_enum (value);
|
|
|
|
break;
|
2003-11-26 09:12:36 +08:00
|
|
|
|
|
|
|
default:
|
|
|
|
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gimp_thumbnail_get_property (GObject *object,
|
|
|
|
guint property_id,
|
|
|
|
GValue *value,
|
|
|
|
GParamSpec *pspec)
|
|
|
|
{
|
|
|
|
GimpThumbnail *thumbnail = GIMP_THUMBNAIL (object);
|
|
|
|
|
|
|
|
switch (property_id)
|
|
|
|
{
|
2003-11-27 00:49:53 +08:00
|
|
|
case PROP_IMAGE_STATE:
|
|
|
|
g_value_set_enum (value, thumbnail->image_state);
|
2003-11-26 09:12:36 +08:00
|
|
|
break;
|
2003-11-27 00:49:53 +08:00
|
|
|
case PROP_IMAGE_URI:
|
|
|
|
g_value_set_string (value, thumbnail->image_uri);
|
2003-11-26 09:12:36 +08:00
|
|
|
break;
|
2003-11-27 00:49:53 +08:00
|
|
|
case PROP_IMAGE_MTIME:
|
2003-11-26 09:12:36 +08:00
|
|
|
g_value_set_int64 (value, thumbnail->image_mtime);
|
|
|
|
break;
|
2003-11-27 00:49:53 +08:00
|
|
|
case PROP_IMAGE_FILESIZE:
|
2003-11-26 09:12:36 +08:00
|
|
|
g_value_set_int64 (value, thumbnail->image_filesize);
|
|
|
|
break;
|
2003-11-27 00:49:53 +08:00
|
|
|
case PROP_IMAGE_WIDTH:
|
2003-11-26 09:12:36 +08:00
|
|
|
g_value_set_int (value, thumbnail->image_width);
|
|
|
|
break;
|
2003-11-27 00:49:53 +08:00
|
|
|
case PROP_IMAGE_HEIGHT:
|
2003-11-26 09:12:36 +08:00
|
|
|
g_value_set_int (value, thumbnail->image_height);
|
|
|
|
break;
|
2003-11-27 00:49:53 +08:00
|
|
|
case PROP_IMAGE_TYPE:
|
2003-11-26 09:12:36 +08:00
|
|
|
g_value_set_string (value, thumbnail->image_type);
|
|
|
|
break;
|
2003-11-27 00:49:53 +08:00
|
|
|
case PROP_IMAGE_NUM_LAYERS:
|
2003-11-26 09:12:36 +08:00
|
|
|
g_value_set_int (value, thumbnail->image_height);
|
|
|
|
break;
|
2003-11-27 00:49:53 +08:00
|
|
|
case PROP_THUMB_STATE:
|
|
|
|
g_value_set_enum (value, thumbnail->thumb_state);
|
|
|
|
break;
|
2003-11-26 09:12:36 +08:00
|
|
|
|
|
|
|
default:
|
|
|
|
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2003-12-16 07:22:50 +08:00
|
|
|
/**
|
|
|
|
* gimp_thumbnail_new:
|
|
|
|
*
|
|
|
|
* Creates a new #GimpThumbnail object.
|
|
|
|
*
|
|
|
|
* Return value: a newly allocated GimpThumbnail object
|
|
|
|
**/
|
2003-11-26 09:12:36 +08:00
|
|
|
GimpThumbnail *
|
|
|
|
gimp_thumbnail_new (void)
|
|
|
|
{
|
|
|
|
return g_object_new (GIMP_TYPE_THUMBNAIL, NULL);
|
|
|
|
}
|
|
|
|
|
2003-12-16 07:22:50 +08:00
|
|
|
/**
|
|
|
|
* gimp_thumbnail_set_uri:
|
|
|
|
* @thumbnail: a #GimpThumbnail object
|
|
|
|
* @uri: an escaped URI in UTF-8 encoding
|
|
|
|
*
|
|
|
|
* Sets the location of the image file associated with the #thumbnail.
|
|
|
|
*
|
|
|
|
* All informations stored in the #GimpThumbnail are reset.
|
|
|
|
**/
|
2003-11-26 09:12:36 +08:00
|
|
|
void
|
|
|
|
gimp_thumbnail_set_uri (GimpThumbnail *thumbnail,
|
|
|
|
const gchar *uri)
|
|
|
|
{
|
|
|
|
g_return_if_fail (GIMP_IS_THUMBNAIL (thumbnail));
|
|
|
|
|
2003-12-08 17:12:25 +08:00
|
|
|
if (thumbnail->image_uri)
|
|
|
|
g_free (thumbnail->image_uri);
|
|
|
|
|
|
|
|
thumbnail->image_uri = g_strdup (uri);
|
|
|
|
|
|
|
|
if (thumbnail->image_filename)
|
|
|
|
{
|
|
|
|
g_free (thumbnail->image_filename);
|
|
|
|
thumbnail->image_filename = NULL;
|
|
|
|
}
|
|
|
|
|
2003-11-27 00:49:53 +08:00
|
|
|
g_object_set (thumbnail,
|
|
|
|
"image-state", GIMP_THUMB_STATE_UNKNOWN,
|
|
|
|
"image-filesize", 0,
|
|
|
|
"image-mtime", 0,
|
|
|
|
"image-width", 0,
|
|
|
|
"image-height", 0,
|
|
|
|
"image-type", NULL,
|
|
|
|
"image-num-layers", 0,
|
|
|
|
NULL);
|
|
|
|
|
|
|
|
gimp_thumbnail_invalidate_thumb (thumbnail);
|
|
|
|
}
|
|
|
|
|
2003-12-16 07:22:50 +08:00
|
|
|
/**
|
|
|
|
* gimp_thumbnail_set_filename:
|
|
|
|
* @thumbnail: a #GimpThumbnail object
|
|
|
|
* @filename: a local filename in the encoding of the filesystem
|
|
|
|
* @error: return location for possible errors
|
|
|
|
*
|
|
|
|
* Sets the location of the image file associated with the #thumbnail.
|
|
|
|
*
|
|
|
|
* Return value: %TRUE if the filename was successfully set,
|
|
|
|
* %FALSE otherwise
|
|
|
|
**/
|
|
|
|
gboolean
|
|
|
|
gimp_thumbnail_set_filename (GimpThumbnail *thumbnail,
|
|
|
|
const gchar *filename,
|
|
|
|
GError **error)
|
|
|
|
{
|
|
|
|
gchar *uri = NULL;
|
|
|
|
|
|
|
|
g_return_val_if_fail (GIMP_IS_THUMBNAIL (thumbnail), FALSE);
|
|
|
|
g_return_val_if_fail (error == NULL || *error == NULL, FALSE);
|
|
|
|
|
|
|
|
if (filename)
|
|
|
|
uri = g_filename_to_uri (filename, NULL, error);
|
|
|
|
|
|
|
|
gimp_thumbnail_set_uri (thumbnail, uri);
|
|
|
|
|
|
|
|
g_free (uri);
|
|
|
|
|
|
|
|
return (!filename || uri);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* gimp_thumbnail_peek_image:
|
|
|
|
* @thumbnail: a #GimpThumbnail object
|
|
|
|
*
|
|
|
|
* Checks the image file associated with the @thumbnail and updates
|
|
|
|
* information such as state, filesize and modification time.
|
|
|
|
*
|
|
|
|
* Return value: the image's #GimpThumbState after the update
|
|
|
|
**/
|
2003-12-02 10:06:20 +08:00
|
|
|
GimpThumbState
|
|
|
|
gimp_thumbnail_peek_image (GimpThumbnail *thumbnail)
|
|
|
|
{
|
|
|
|
g_return_val_if_fail (GIMP_IS_THUMBNAIL (thumbnail),
|
|
|
|
GIMP_THUMB_STATE_UNKNOWN);
|
|
|
|
|
|
|
|
g_object_freeze_notify (G_OBJECT (thumbnail));
|
|
|
|
|
|
|
|
gimp_thumbnail_update_image (thumbnail);
|
|
|
|
|
|
|
|
g_object_thaw_notify (G_OBJECT (thumbnail));
|
|
|
|
|
|
|
|
return thumbnail->image_state;
|
|
|
|
}
|
|
|
|
|
2003-12-16 07:22:50 +08:00
|
|
|
/**
|
|
|
|
* gimp_thumbnail_peek_thumb:
|
|
|
|
* @thumbnail: a #GimpThumbnail object
|
|
|
|
* @size: the preferred size of the thumbnail image
|
|
|
|
*
|
|
|
|
* Checks if a thumbnail file for the @thumbnail exists. It doesn't
|
|
|
|
* load the thumbnail image and thus cannot check if the thumbnail is
|
|
|
|
* valid and uptodate for the image file asosciated with the
|
|
|
|
* @thumbnail.
|
|
|
|
*
|
|
|
|
* Return value: the thumbnail's #GimpThumbState after the update
|
|
|
|
**/
|
2003-12-02 10:06:20 +08:00
|
|
|
GimpThumbState
|
|
|
|
gimp_thumbnail_peek_thumb (GimpThumbnail *thumbnail,
|
|
|
|
GimpThumbSize size)
|
2003-11-27 00:49:53 +08:00
|
|
|
{
|
2003-12-02 10:06:20 +08:00
|
|
|
g_return_val_if_fail (GIMP_IS_THUMBNAIL (thumbnail),
|
|
|
|
GIMP_THUMB_STATE_UNKNOWN);
|
|
|
|
|
2003-11-27 00:49:53 +08:00
|
|
|
g_object_freeze_notify (G_OBJECT (thumbnail));
|
|
|
|
|
|
|
|
gimp_thumbnail_update_image (thumbnail);
|
2003-12-14 21:21:44 +08:00
|
|
|
gimp_thumbnail_update_thumb (thumbnail, size);
|
2003-11-27 00:49:53 +08:00
|
|
|
|
|
|
|
g_object_thaw_notify (G_OBJECT (thumbnail));
|
2003-12-02 10:06:20 +08:00
|
|
|
|
|
|
|
return thumbnail->thumb_state;
|
2003-11-27 00:49:53 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gimp_thumbnail_update_image (GimpThumbnail *thumbnail)
|
2003-11-26 09:12:36 +08:00
|
|
|
{
|
2003-11-27 00:49:53 +08:00
|
|
|
GimpThumbState state;
|
|
|
|
gint64 filesize = 0;
|
|
|
|
gint64 mtime = 0;
|
|
|
|
|
2003-12-08 17:12:25 +08:00
|
|
|
if (! thumbnail->image_uri)
|
|
|
|
return;
|
2003-11-26 09:12:36 +08:00
|
|
|
|
2003-11-27 00:49:53 +08:00
|
|
|
state = thumbnail->image_state;
|
2003-11-26 09:12:36 +08:00
|
|
|
|
|
|
|
switch (state)
|
|
|
|
{
|
|
|
|
case GIMP_THUMB_STATE_UNKNOWN:
|
|
|
|
g_return_if_fail (thumbnail->image_filename == NULL);
|
|
|
|
|
2003-11-27 00:49:53 +08:00
|
|
|
thumbnail->image_filename = g_filename_from_uri (thumbnail->image_uri,
|
2003-11-26 09:12:36 +08:00
|
|
|
NULL, NULL);
|
|
|
|
|
|
|
|
if (! thumbnail->image_filename)
|
|
|
|
state = GIMP_THUMB_STATE_REMOTE;
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
case GIMP_THUMB_STATE_REMOTE:
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
g_return_if_fail (thumbnail->image_filename != NULL);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
switch (state)
|
|
|
|
{
|
|
|
|
case GIMP_THUMB_STATE_REMOTE:
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
2003-11-27 00:49:53 +08:00
|
|
|
if (gimp_thumb_file_test (thumbnail->image_filename, &mtime, &filesize))
|
|
|
|
state = GIMP_THUMB_STATE_EXISTS;
|
2003-11-26 09:12:36 +08:00
|
|
|
else
|
2003-11-27 00:49:53 +08:00
|
|
|
state = GIMP_THUMB_STATE_NOT_FOUND;
|
2003-11-26 09:12:36 +08:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2003-11-27 00:49:53 +08:00
|
|
|
if (state != thumbnail->image_state)
|
2003-11-26 09:12:36 +08:00
|
|
|
{
|
2003-11-27 00:49:53 +08:00
|
|
|
g_object_set (thumbnail,
|
|
|
|
"image-state",
|
|
|
|
state, NULL);
|
|
|
|
}
|
2003-11-26 09:12:36 +08:00
|
|
|
|
2003-11-27 00:49:53 +08:00
|
|
|
if (mtime != thumbnail->image_mtime || filesize != thumbnail->image_filesize)
|
|
|
|
{
|
|
|
|
g_object_set (thumbnail,
|
|
|
|
"image-mtime", mtime,
|
|
|
|
"image-filesize", filesize,
|
|
|
|
NULL);
|
|
|
|
}
|
|
|
|
}
|
2003-11-26 09:12:36 +08:00
|
|
|
|
2003-11-27 00:49:53 +08:00
|
|
|
static void
|
2003-12-14 21:21:44 +08:00
|
|
|
gimp_thumbnail_update_thumb (GimpThumbnail *thumbnail,
|
|
|
|
GimpThumbSize size)
|
2003-11-27 00:49:53 +08:00
|
|
|
{
|
|
|
|
GimpThumbState state;
|
2003-12-14 21:21:44 +08:00
|
|
|
GimpThumbSize s;
|
2003-11-27 00:49:53 +08:00
|
|
|
gint64 filesize;
|
|
|
|
gint64 mtime;
|
2003-11-26 09:12:36 +08:00
|
|
|
|
2003-11-27 00:49:53 +08:00
|
|
|
state = thumbnail->thumb_state;
|
2003-12-14 21:21:44 +08:00
|
|
|
s = size;
|
2003-11-26 09:12:36 +08:00
|
|
|
|
2003-11-27 00:49:53 +08:00
|
|
|
switch (state)
|
|
|
|
{
|
|
|
|
case GIMP_THUMB_STATE_UNKNOWN:
|
2003-12-08 22:15:25 +08:00
|
|
|
if (! thumbnail->image_uri)
|
|
|
|
return;
|
|
|
|
/* fallthrough */
|
|
|
|
|
2003-12-08 17:12:25 +08:00
|
|
|
case GIMP_THUMB_STATE_NOT_FOUND:
|
2003-11-27 00:49:53 +08:00
|
|
|
g_return_if_fail (thumbnail->thumb_filename == NULL);
|
2003-11-26 09:12:36 +08:00
|
|
|
|
2003-11-27 00:49:53 +08:00
|
|
|
thumbnail->thumb_filename =
|
2003-12-14 21:21:44 +08:00
|
|
|
gimp_thumb_find_thumb (thumbnail->image_uri, &s);
|
2003-11-27 00:49:53 +08:00
|
|
|
break;
|
2003-11-26 09:12:36 +08:00
|
|
|
|
2003-11-27 00:49:53 +08:00
|
|
|
default:
|
|
|
|
g_return_if_fail (thumbnail->thumb_filename != NULL);
|
2003-11-26 09:12:36 +08:00
|
|
|
break;
|
|
|
|
}
|
2003-11-27 00:49:53 +08:00
|
|
|
|
|
|
|
switch (state)
|
|
|
|
{
|
|
|
|
default:
|
2003-12-14 21:21:44 +08:00
|
|
|
if (thumbnail->thumb_filename &&
|
|
|
|
gimp_thumb_file_test (thumbnail->thumb_filename, &mtime, &filesize))
|
|
|
|
{
|
|
|
|
state = GIMP_THUMB_STATE_EXISTS;
|
|
|
|
}
|
2003-11-27 00:49:53 +08:00
|
|
|
else
|
2003-12-14 21:21:44 +08:00
|
|
|
{
|
|
|
|
state = GIMP_THUMB_STATE_NOT_FOUND;
|
|
|
|
}
|
2003-11-27 00:49:53 +08:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (state != thumbnail->thumb_state)
|
|
|
|
g_object_set (thumbnail, "thumb-state", state, NULL);
|
2003-11-26 09:12:36 +08:00
|
|
|
}
|
|
|
|
|
2003-12-16 07:22:50 +08:00
|
|
|
static void
|
|
|
|
gimp_thumbnail_invalidate_thumb (GimpThumbnail *thumbnail)
|
2003-11-26 09:12:36 +08:00
|
|
|
{
|
2003-12-16 07:22:50 +08:00
|
|
|
if (thumbnail->thumb_filename)
|
|
|
|
{
|
|
|
|
g_free (thumbnail->thumb_filename);
|
|
|
|
thumbnail->thumb_filename = NULL;
|
|
|
|
}
|
2003-11-26 09:12:36 +08:00
|
|
|
|
2003-12-16 07:22:50 +08:00
|
|
|
thumbnail->thumb_filesize = 0;
|
|
|
|
thumbnail->thumb_mtime = 0;
|
2003-11-26 09:12:36 +08:00
|
|
|
|
2003-12-16 07:22:50 +08:00
|
|
|
if (thumbnail->thumb_state != GIMP_THUMB_STATE_UNKNOWN)
|
|
|
|
{
|
|
|
|
g_object_set (thumbnail,
|
|
|
|
"thumb-state", GIMP_THUMB_STATE_UNKNOWN,
|
|
|
|
NULL);
|
|
|
|
}
|
|
|
|
}
|
2003-11-26 09:12:36 +08:00
|
|
|
|
2003-12-16 07:22:50 +08:00
|
|
|
static void
|
|
|
|
gimp_thumbnail_reset_info (GimpThumbnail *thumbnail)
|
|
|
|
{
|
|
|
|
g_object_set (thumbnail,
|
|
|
|
"image-width", 0,
|
|
|
|
"image-height", 0,
|
|
|
|
"image-type", NULL,
|
|
|
|
"image-num-layers", 0,
|
|
|
|
NULL);
|
2003-11-26 09:12:36 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gimp_thumbnail_set_info_from_pixbuf (GimpThumbnail *thumbnail,
|
|
|
|
GdkPixbuf *pixbuf)
|
|
|
|
{
|
|
|
|
const gchar *option;
|
|
|
|
gint n;
|
|
|
|
|
|
|
|
g_object_freeze_notify (G_OBJECT (thumbnail));
|
|
|
|
|
|
|
|
gimp_thumbnail_reset_info (thumbnail);
|
|
|
|
|
|
|
|
option = gdk_pixbuf_get_option (pixbuf, TAG_THUMB_IMAGE_WIDTH);
|
|
|
|
if (option && sscanf (option, "%d", &n) == 1)
|
|
|
|
thumbnail->image_width = n;
|
|
|
|
|
|
|
|
option = gdk_pixbuf_get_option (pixbuf, TAG_THUMB_IMAGE_HEIGHT);
|
|
|
|
if (option && sscanf (option, "%d", &n) == 1)
|
|
|
|
thumbnail->image_height = n;
|
|
|
|
|
|
|
|
thumbnail->image_type =
|
|
|
|
g_strdup (gdk_pixbuf_get_option (pixbuf, TAG_THUMB_GIMP_TYPE));
|
|
|
|
|
|
|
|
option = gdk_pixbuf_get_option (pixbuf, TAG_THUMB_GIMP_LAYERS);
|
|
|
|
if (option && sscanf (option, "%d", &n) == 1)
|
|
|
|
thumbnail->image_num_layers = 0;
|
2003-11-27 00:49:53 +08:00
|
|
|
|
|
|
|
g_object_thaw_notify (G_OBJECT (thumbnail));
|
2003-11-26 09:12:36 +08:00
|
|
|
}
|
|
|
|
|
2003-12-16 07:22:50 +08:00
|
|
|
/**
|
|
|
|
* 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
|
|
|
|
**/
|
2003-11-26 09:12:36 +08:00
|
|
|
GdkPixbuf *
|
2003-12-02 10:06:20 +08:00
|
|
|
gimp_thumbnail_load_thumb (GimpThumbnail *thumbnail,
|
2003-11-26 09:12:36 +08:00
|
|
|
GimpThumbSize size,
|
|
|
|
GError **error)
|
|
|
|
{
|
2003-12-08 22:15:25 +08:00
|
|
|
GimpThumbState state;
|
|
|
|
GdkPixbuf *pixbuf = NULL;
|
|
|
|
gchar *name;
|
|
|
|
const gchar *option;
|
|
|
|
gint64 image_mtime;
|
|
|
|
gint64 image_size;
|
2003-11-26 09:12:36 +08:00
|
|
|
|
2003-12-16 07:22:50 +08:00
|
|
|
/* FIXME: this function needs review, it is broken!! */
|
|
|
|
|
2003-12-02 10:06:20 +08:00
|
|
|
g_return_val_if_fail (GIMP_IS_THUMBNAIL (thumbnail), NULL);
|
|
|
|
g_return_val_if_fail (error == NULL || *error == NULL, NULL);
|
|
|
|
|
2003-11-27 00:49:53 +08:00
|
|
|
if (! thumbnail->image_uri)
|
2003-11-26 09:12:36 +08:00
|
|
|
return NULL;
|
|
|
|
|
2003-12-08 22:15:25 +08:00
|
|
|
state = GIMP_THUMB_STATE_NOT_FOUND;
|
|
|
|
|
|
|
|
name = gimp_thumb_find_thumb (thumbnail->image_uri, &size);
|
|
|
|
if (!name)
|
|
|
|
goto cleanup;
|
2003-11-26 09:12:36 +08:00
|
|
|
|
2003-12-08 22:15:25 +08:00
|
|
|
pixbuf = gdk_pixbuf_new_from_file (name, error);
|
|
|
|
|
|
|
|
g_free (name);
|
|
|
|
|
|
|
|
if (! pixbuf)
|
|
|
|
goto cleanup;
|
|
|
|
|
|
|
|
/* URI and mtime from the thumbnail need to match our file */
|
|
|
|
option = gdk_pixbuf_get_option (pixbuf, TAG_THUMB_URI);
|
|
|
|
if (!option || strcmp (option, thumbnail->image_uri))
|
|
|
|
goto cleanup;
|
|
|
|
|
|
|
|
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 cleanup;
|
|
|
|
|
|
|
|
option = gdk_pixbuf_get_option (pixbuf, TAG_THUMB_FILESIZE);
|
|
|
|
if (option && sscanf (option, "%" G_GINT64_FORMAT, &image_size) != 1)
|
|
|
|
goto cleanup;
|
|
|
|
|
|
|
|
/* TAG_THUMB_FILESIZE is optional but must match if present */
|
|
|
|
if (image_mtime == thumbnail->image_mtime &&
|
|
|
|
(option == NULL || image_size == thumbnail->image_filesize))
|
2003-11-26 09:12:36 +08:00
|
|
|
{
|
2003-12-08 22:15:25 +08:00
|
|
|
if (size == GIMP_THUMB_SIZE_FAIL)
|
|
|
|
state = GIMP_THUMB_STATE_FAILED;
|
|
|
|
else
|
|
|
|
state = GIMP_THUMB_STATE_OK;
|
|
|
|
}
|
2003-11-26 09:12:36 +08:00
|
|
|
|
2003-12-08 22:15:25 +08:00
|
|
|
if (size == GIMP_THUMB_SIZE_FAIL)
|
|
|
|
gimp_thumbnail_reset_info (thumbnail);
|
|
|
|
else
|
|
|
|
gimp_thumbnail_set_info_from_pixbuf (thumbnail, pixbuf);
|
2003-11-26 09:12:36 +08:00
|
|
|
|
2003-12-08 22:15:25 +08:00
|
|
|
cleanup:
|
|
|
|
if (state != thumbnail->thumb_state)
|
|
|
|
g_object_set (thumbnail, "thumb-state", state, NULL);
|
2003-11-26 09:12:36 +08:00
|
|
|
|
2003-12-08 22:15:25 +08:00
|
|
|
if (pixbuf && (state != GIMP_THUMB_STATE_OLD &&
|
|
|
|
state != GIMP_THUMB_STATE_OK))
|
|
|
|
{
|
|
|
|
g_object_unref (pixbuf);
|
|
|
|
return NULL;
|
2003-11-26 09:12:36 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
return pixbuf;
|
|
|
|
}
|
|
|
|
|
2003-12-16 07:22:50 +08:00
|
|
|
/**
|
|
|
|
* gimp_thumbnail_save_thumb:
|
|
|
|
* @thumbnail: a #GimpThumbnail object
|
|
|
|
* @pixbuf: a #GdkPixbuf representing the preview thumbnail
|
|
|
|
* @software: a string describing the software saving the thumbnail
|
|
|
|
* @error: return location for possible errors
|
|
|
|
*
|
|
|
|
* Saves a preview thumbnail for the image associated with @thumbnail.
|
|
|
|
*
|
|
|
|
* The caller is responsible for setting the image file location, it's
|
|
|
|
* filesize, modification time. One way to set this info is to is to
|
|
|
|
* call gimp_thumbnail_set_uri() followed by gimp_thumbnail_peek_image().
|
|
|
|
* Since this won't work for remote images, it is left to the user of
|
|
|
|
* gimp_thumbnail_save_thumb() to do this or to set the information
|
|
|
|
* using the @thumbnail object properties.
|
|
|
|
*
|
|
|
|
* The image format type and the number of layers can optionally be
|
|
|
|
* set in order to be stored with the preview image.
|
|
|
|
*
|
|
|
|
* Return value: %TRUE if a thumbnail was successfully written,
|
|
|
|
* %FALSE otherwise
|
|
|
|
**/
|
2003-11-26 18:26:37 +08:00
|
|
|
gboolean
|
2003-12-02 10:06:20 +08:00
|
|
|
gimp_thumbnail_save_thumb (GimpThumbnail *thumbnail,
|
|
|
|
GdkPixbuf *pixbuf,
|
|
|
|
const gchar *software,
|
|
|
|
GError **error)
|
2003-11-26 18:26:37 +08:00
|
|
|
{
|
|
|
|
GimpThumbSize size;
|
|
|
|
gchar *name;
|
|
|
|
gchar *desc;
|
|
|
|
gchar *time_str;
|
|
|
|
gchar *size_str;
|
|
|
|
gchar *width_str;
|
|
|
|
gchar *height_str;
|
|
|
|
gchar *num_str;
|
|
|
|
gboolean success;
|
|
|
|
|
|
|
|
g_return_val_if_fail (GIMP_IS_THUMBNAIL (thumbnail), FALSE);
|
2003-11-27 00:49:53 +08:00
|
|
|
g_return_val_if_fail (thumbnail->image_uri != NULL, FALSE);
|
2003-11-26 18:26:37 +08:00
|
|
|
g_return_val_if_fail (GDK_IS_PIXBUF (pixbuf), FALSE);
|
|
|
|
g_return_val_if_fail (software != NULL, FALSE);
|
|
|
|
g_return_val_if_fail (error == NULL || *error == NULL, FALSE);
|
|
|
|
|
2003-12-02 10:06:20 +08:00
|
|
|
size = MAX (gdk_pixbuf_get_width (pixbuf), gdk_pixbuf_get_height (pixbuf));
|
2003-11-26 18:26:37 +08:00
|
|
|
if (size < 1)
|
|
|
|
return TRUE;
|
|
|
|
|
2003-12-14 21:21:44 +08:00
|
|
|
name = gimp_thumb_name_from_uri (thumbnail->image_uri, size);
|
2003-11-26 18:26:37 +08:00
|
|
|
if (! name)
|
|
|
|
return TRUE;
|
|
|
|
|
2003-12-08 21:09:33 +08:00
|
|
|
if (! gimp_thumb_ensure_thumb_dir (size, error))
|
|
|
|
{
|
|
|
|
g_free (name);
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
2003-11-27 00:49:53 +08:00
|
|
|
desc = g_strdup_printf ("Thumbnail of %s", thumbnail->image_uri);
|
2003-11-26 18:26:37 +08:00
|
|
|
time_str = g_strdup_printf ("%" G_GINT64_FORMAT, thumbnail->image_mtime);
|
|
|
|
size_str = g_strdup_printf ("%" G_GINT64_FORMAT, thumbnail->image_filesize);
|
|
|
|
|
|
|
|
width_str = g_strdup_printf ("%d", thumbnail->image_width);
|
|
|
|
height_str = g_strdup_printf ("%d", thumbnail->image_height);
|
|
|
|
num_str = g_strdup_printf ("%d", thumbnail->image_num_layers);
|
|
|
|
|
|
|
|
success = gdk_pixbuf_save (pixbuf, name, "png", error,
|
|
|
|
TAG_DESCRIPTION, desc,
|
|
|
|
TAG_SOFTWARE, software,
|
2003-11-27 00:49:53 +08:00
|
|
|
TAG_THUMB_URI, thumbnail->image_uri,
|
2003-11-26 18:26:37 +08:00
|
|
|
TAG_THUMB_MTIME, time_str,
|
|
|
|
TAG_THUMB_FILESIZE, size_str,
|
|
|
|
TAG_THUMB_IMAGE_WIDTH, width_str,
|
|
|
|
TAG_THUMB_IMAGE_HEIGHT, height_str,
|
|
|
|
|
|
|
|
thumbnail->image_type ?
|
|
|
|
TAG_THUMB_GIMP_TYPE : NULL,
|
|
|
|
thumbnail->image_type,
|
|
|
|
|
|
|
|
thumbnail->image_num_layers > 0 ?
|
|
|
|
TAG_THUMB_GIMP_LAYERS : NULL,
|
|
|
|
num_str,
|
|
|
|
|
|
|
|
NULL);
|
|
|
|
|
|
|
|
if (success)
|
|
|
|
{
|
2003-12-08 21:09:33 +08:00
|
|
|
success = (chmod (name, 0600) == 0);
|
2003-11-26 18:26:37 +08:00
|
|
|
|
|
|
|
if (! success)
|
|
|
|
g_set_error (error, G_FILE_ERROR, g_file_error_from_errno (errno),
|
|
|
|
"Could not set permissions of thumbnail '%s': %s",
|
|
|
|
name, g_strerror (errno));
|
|
|
|
}
|
|
|
|
|
|
|
|
g_free (num_str);
|
|
|
|
g_free (height_str);
|
|
|
|
g_free (width_str);
|
|
|
|
g_free (size_str);
|
|
|
|
g_free (time_str);
|
|
|
|
g_free (desc);
|
|
|
|
g_free (name);
|
|
|
|
|
|
|
|
return success;
|
|
|
|
}
|
|
|
|
|
2003-12-16 07:22:50 +08:00
|
|
|
/**
|
|
|
|
* gimp_thumbnail_save_failure:
|
|
|
|
* @thumbnail: a #GimpThumbnail object
|
|
|
|
* @software: a string describing the software saving the thumbnail
|
|
|
|
* @error: return location for possible errors
|
|
|
|
*
|
|
|
|
* Saves a failure thumbnail for the image associated with
|
|
|
|
* @thumbnail. This is an empty pixbuf that indicates that an attempt
|
|
|
|
* to create a preview for the image file failed. It should be used to
|
|
|
|
* prevent the software from further attempts to create this thumbnail.
|
|
|
|
*
|
|
|
|
* Return value: %TRUE if a failure thumbnail was successfully written,
|
|
|
|
* %FALSE otherwise
|
|
|
|
**/
|
2003-11-26 18:26:37 +08:00
|
|
|
gboolean
|
|
|
|
gimp_thumbnail_save_failure (GimpThumbnail *thumbnail,
|
|
|
|
const gchar *software,
|
|
|
|
GError **error)
|
|
|
|
{
|
2003-12-14 21:21:44 +08:00
|
|
|
GdkPixbuf *pixbuf;
|
|
|
|
gchar *name;
|
|
|
|
gchar *desc;
|
|
|
|
gchar *time_str;
|
|
|
|
gchar *size_str;
|
|
|
|
gboolean success;
|
2003-11-26 18:26:37 +08:00
|
|
|
|
|
|
|
g_return_val_if_fail (GIMP_IS_THUMBNAIL (thumbnail), FALSE);
|
2003-11-27 00:49:53 +08:00
|
|
|
g_return_val_if_fail (thumbnail->image_uri != NULL, FALSE);
|
2003-11-26 18:26:37 +08:00
|
|
|
g_return_val_if_fail (software != NULL, FALSE);
|
|
|
|
|
2003-12-14 21:21:44 +08:00
|
|
|
name = gimp_thumb_name_from_uri (thumbnail->image_uri, GIMP_THUMB_SIZE_FAIL);
|
2003-11-26 18:26:37 +08:00
|
|
|
if (! name)
|
|
|
|
return TRUE;
|
|
|
|
|
2003-12-14 21:21:44 +08:00
|
|
|
if (! gimp_thumb_ensure_thumb_dir (GIMP_THUMB_SIZE_FAIL, error))
|
2003-12-08 21:09:33 +08:00
|
|
|
{
|
|
|
|
g_free (name);
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
2003-11-26 18:26:37 +08:00
|
|
|
pixbuf = gdk_pixbuf_new (GDK_COLORSPACE_RGB, FALSE, 8, 1, 1);
|
|
|
|
|
2003-11-27 00:49:53 +08:00
|
|
|
desc = g_strdup_printf ("Thumbnail failure for %s", thumbnail->image_uri);
|
2003-11-26 18:26:37 +08:00
|
|
|
time_str = g_strdup_printf ("%" G_GINT64_FORMAT, thumbnail->image_mtime);
|
|
|
|
size_str = g_strdup_printf ("%" G_GINT64_FORMAT, thumbnail->image_filesize);
|
|
|
|
|
|
|
|
success = gdk_pixbuf_save (pixbuf, name, "png", error,
|
|
|
|
TAG_DESCRIPTION, desc,
|
|
|
|
TAG_SOFTWARE, software,
|
2003-11-27 00:49:53 +08:00
|
|
|
TAG_THUMB_URI, thumbnail->image_uri,
|
2003-11-26 18:26:37 +08:00
|
|
|
TAG_THUMB_MTIME, time_str,
|
|
|
|
TAG_THUMB_FILESIZE, size_str,
|
|
|
|
NULL);
|
|
|
|
if (success)
|
|
|
|
{
|
2003-12-08 21:09:33 +08:00
|
|
|
success = (chmod (name, 0600) == 0);
|
2003-11-26 18:26:37 +08:00
|
|
|
|
|
|
|
if (! success)
|
|
|
|
g_set_error (error, G_FILE_ERROR, g_file_error_from_errno (errno),
|
|
|
|
"Could not set permissions of thumbnail '%s': %s",
|
|
|
|
name, g_strerror (errno));
|
|
|
|
}
|
|
|
|
|
|
|
|
g_object_unref (pixbuf);
|
|
|
|
|
|
|
|
g_free (size_str);
|
|
|
|
g_free (time_str);
|
|
|
|
g_free (desc);
|
|
|
|
g_free (name);
|
|
|
|
|
|
|
|
return success;
|
|
|
|
}
|