2006-12-10 05:33:38 +08:00
|
|
|
|
/* GIMP - The GNU Image Manipulation Program
|
2001-08-09 17:07:17 +08:00
|
|
|
|
* Copyright (C) 1995 Spencer Kimball and Peter Mattis
|
|
|
|
|
*
|
2004-10-09 03:29:33 +08:00
|
|
|
|
* gimpimagefile.c
|
2002-04-30 01:20:26 +08:00
|
|
|
|
*
|
2004-02-28 00:27:06 +08:00
|
|
|
|
* Copyright (C) 2001-2004 Sven Neumann <sven@gimp.org>
|
2002-04-30 01:20:26 +08:00
|
|
|
|
* Michael Natterer <mitch@gimp.org>
|
2001-08-09 17:07:17 +08:00
|
|
|
|
*
|
2009-01-18 06:28:01 +08:00
|
|
|
|
* This program is free software: you can redistribute it and/or modify
|
2001-08-09 17:07:17 +08:00
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
2009-01-18 06:28:01 +08:00
|
|
|
|
* the Free Software Foundation; either version 3 of the License, or
|
2001-08-09 17:07:17 +08:00
|
|
|
|
* (at your option) any later version.
|
|
|
|
|
*
|
|
|
|
|
* This program 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 General Public License for more details.
|
|
|
|
|
*
|
|
|
|
|
* You should have received a copy of the GNU General Public License
|
2018-07-12 05:27:07 +08:00
|
|
|
|
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
2001-08-09 17:07:17 +08:00
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
#include "config.h"
|
|
|
|
|
|
|
|
|
|
#include <string.h>
|
|
|
|
|
|
2008-10-10 04:24:04 +08:00
|
|
|
|
#include <gegl.h>
|
2001-11-27 11:52:11 +08:00
|
|
|
|
#include <gdk-pixbuf/gdk-pixbuf.h>
|
2001-08-09 17:07:17 +08:00
|
|
|
|
|
2003-04-04 23:11:30 +08:00
|
|
|
|
#include "libgimpbase/gimpbase.h"
|
2003-12-08 17:12:25 +08:00
|
|
|
|
#include "libgimpthumb/gimpthumb.h"
|
2002-04-30 01:20:26 +08:00
|
|
|
|
|
2001-08-09 17:07:17 +08:00
|
|
|
|
#include "core-types.h"
|
|
|
|
|
|
2002-11-19 04:50:31 +08:00
|
|
|
|
#include "config/gimpcoreconfig.h"
|
|
|
|
|
|
2012-04-22 05:46:41 +08:00
|
|
|
|
#include "gegl/gimp-babl.h"
|
2012-04-07 08:50:50 +08:00
|
|
|
|
#include "gegl/gimp-gegl-utils.h"
|
|
|
|
|
|
2002-04-17 04:25:27 +08:00
|
|
|
|
#include "gimp.h"
|
|
|
|
|
#include "gimpcontainer.h"
|
2004-04-15 07:37:34 +08:00
|
|
|
|
#include "gimpcontext.h"
|
2002-04-17 04:25:27 +08:00
|
|
|
|
#include "gimpimage.h"
|
2001-08-09 17:07:17 +08:00
|
|
|
|
#include "gimpimagefile.h"
|
2002-04-17 04:25:27 +08:00
|
|
|
|
#include "gimpmarshal.h"
|
2007-08-02 22:54:29 +08:00
|
|
|
|
#include "gimppickable.h"
|
2004-08-11 02:47:21 +08:00
|
|
|
|
#include "gimpprogress.h"
|
2002-04-17 04:25:27 +08:00
|
|
|
|
|
|
|
|
|
#include "file/file-open.h"
|
|
|
|
|
|
2003-03-26 00:38:19 +08:00
|
|
|
|
#include "gimp-intl.h"
|
2001-08-09 17:07:17 +08:00
|
|
|
|
|
|
|
|
|
|
2002-04-17 04:25:27 +08:00
|
|
|
|
enum
|
|
|
|
|
{
|
|
|
|
|
INFO_CHANGED,
|
|
|
|
|
LAST_SIGNAL
|
|
|
|
|
};
|
|
|
|
|
|
2004-08-11 02:47:21 +08:00
|
|
|
|
|
2011-03-02 19:26:04 +08:00
|
|
|
|
typedef struct _GimpImagefilePrivate GimpImagefilePrivate;
|
|
|
|
|
|
|
|
|
|
struct _GimpImagefilePrivate
|
|
|
|
|
{
|
|
|
|
|
Gimp *gimp;
|
|
|
|
|
|
2014-07-05 18:51:54 +08:00
|
|
|
|
GFile *file;
|
2011-03-02 19:26:04 +08:00
|
|
|
|
GimpThumbnail *thumbnail;
|
2011-06-20 05:06:33 +08:00
|
|
|
|
GIcon *icon;
|
|
|
|
|
GCancellable *icon_cancellable;
|
2011-03-02 19:26:04 +08:00
|
|
|
|
|
|
|
|
|
gchar *description;
|
|
|
|
|
gboolean static_desc;
|
|
|
|
|
};
|
|
|
|
|
|
app, libgimp*, modules: don't use g_type_class_add_private() ...
... and G_TYPE_INSTANCE_GET_PRIVATE()
g_type_class_add_private() and G_TYPE_INSTANCE_GET_PRIVATE() were
deprecated in GLib 2.58. Instead, use
G_DEFINE_[ABSTRACT_]TYPE_WITH_PRIVATE(), and
G_ADD_PRIVATE[_DYNAMIC](), and the implictly-defined
foo_get_instance_private() functions, all of which are available in
the GLib versions we depend on.
This commit only covers types registered using one of the
G_DEFINE_FOO() macros (i.e., most types), but not types with a
custom registration function, of which we still have a few -- GLib
currently only provides a (non-deprecated) public API for adding a
private struct using the G_DEFINE_FOO() macros.
Note that this commit was 99% auto-generated (because I'm not
*that* crazy :), so if there are any style mismatches... we'll have
to live with them for now.
2018-09-19 00:09:39 +08:00
|
|
|
|
#define GET_PRIVATE(imagefile) ((GimpImagefilePrivate *) gimp_imagefile_get_instance_private ((GimpImagefile *) (imagefile)))
|
2011-03-02 19:26:04 +08:00
|
|
|
|
|
|
|
|
|
|
2011-06-20 05:06:33 +08:00
|
|
|
|
static void gimp_imagefile_dispose (GObject *object);
|
2004-09-27 07:44:24 +08:00
|
|
|
|
static void gimp_imagefile_finalize (GObject *object);
|
2005-12-11 03:24:36 +08:00
|
|
|
|
|
2004-09-27 07:44:24 +08:00
|
|
|
|
static void gimp_imagefile_name_changed (GimpObject *object);
|
2005-12-11 03:24:36 +08:00
|
|
|
|
|
2004-09-27 07:44:24 +08:00
|
|
|
|
static GdkPixbuf * gimp_imagefile_get_new_pixbuf (GimpViewable *viewable,
|
2006-08-30 05:44:51 +08:00
|
|
|
|
GimpContext *context,
|
2004-09-27 07:44:24 +08:00
|
|
|
|
gint width,
|
|
|
|
|
gint height);
|
2014-07-10 02:10:58 +08:00
|
|
|
|
static gchar * gimp_imagefile_get_description (GimpViewable *viewable,
|
|
|
|
|
gchar **tooltip);
|
|
|
|
|
|
|
|
|
|
static void gimp_imagefile_info_changed (GimpImagefile *imagefile);
|
|
|
|
|
static void gimp_imagefile_notify_thumbnail (GimpImagefile *imagefile,
|
|
|
|
|
GParamSpec *pspec);
|
|
|
|
|
|
|
|
|
|
static void gimp_imagefile_icon_callback (GObject *source_object,
|
|
|
|
|
GAsyncResult *result,
|
|
|
|
|
gpointer data);
|
|
|
|
|
|
2004-09-27 07:44:24 +08:00
|
|
|
|
static GdkPixbuf * gimp_imagefile_load_thumb (GimpImagefile *imagefile,
|
|
|
|
|
gint width,
|
|
|
|
|
gint height);
|
|
|
|
|
static gboolean gimp_imagefile_save_thumb (GimpImagefile *imagefile,
|
2006-03-29 01:08:36 +08:00
|
|
|
|
GimpImage *image,
|
2004-09-27 07:44:24 +08:00
|
|
|
|
gint size,
|
2004-10-23 23:30:39 +08:00
|
|
|
|
gboolean replace,
|
2004-09-27 07:44:24 +08:00
|
|
|
|
GError **error);
|
2004-01-06 10:33:08 +08:00
|
|
|
|
|
2004-11-14 01:06:06 +08:00
|
|
|
|
static void gimp_thumbnail_set_info_from_image (GimpThumbnail *thumbnail,
|
|
|
|
|
const gchar *mime_type,
|
|
|
|
|
GimpImage *image);
|
|
|
|
|
static void gimp_thumbnail_set_info (GimpThumbnail *thumbnail,
|
|
|
|
|
const gchar *mime_type,
|
|
|
|
|
gint width,
|
2008-11-10 16:21:36 +08:00
|
|
|
|
gint height,
|
2012-04-12 03:54:23 +08:00
|
|
|
|
const Babl *format,
|
2008-11-10 16:21:36 +08:00
|
|
|
|
gint num_layers);
|
2004-11-14 01:06:06 +08:00
|
|
|
|
|
|
|
|
|
|
app, libgimp*, modules: don't use g_type_class_add_private() ...
... and G_TYPE_INSTANCE_GET_PRIVATE()
g_type_class_add_private() and G_TYPE_INSTANCE_GET_PRIVATE() were
deprecated in GLib 2.58. Instead, use
G_DEFINE_[ABSTRACT_]TYPE_WITH_PRIVATE(), and
G_ADD_PRIVATE[_DYNAMIC](), and the implictly-defined
foo_get_instance_private() functions, all of which are available in
the GLib versions we depend on.
This commit only covers types registered using one of the
G_DEFINE_FOO() macros (i.e., most types), but not types with a
custom registration function, of which we still have a few -- GLib
currently only provides a (non-deprecated) public API for adding a
private struct using the G_DEFINE_FOO() macros.
Note that this commit was 99% auto-generated (because I'm not
*that* crazy :), so if there are any style mismatches... we'll have
to live with them for now.
2018-09-19 00:09:39 +08:00
|
|
|
|
G_DEFINE_TYPE_WITH_PRIVATE (GimpImagefile, gimp_imagefile, GIMP_TYPE_VIEWABLE)
|
2002-04-18 22:14:50 +08:00
|
|
|
|
|
2005-12-11 03:24:36 +08:00
|
|
|
|
#define parent_class gimp_imagefile_parent_class
|
2001-08-09 17:07:17 +08:00
|
|
|
|
|
2005-12-11 03:24:36 +08:00
|
|
|
|
static guint gimp_imagefile_signals[LAST_SIGNAL] = { 0 };
|
2001-08-09 17:07:17 +08:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
|
gimp_imagefile_class_init (GimpImagefileClass *klass)
|
|
|
|
|
{
|
2004-08-11 22:00:08 +08:00
|
|
|
|
GObjectClass *object_class = G_OBJECT_CLASS (klass);
|
|
|
|
|
GimpObjectClass *gimp_object_class = GIMP_OBJECT_CLASS (klass);
|
|
|
|
|
GimpViewableClass *viewable_class = GIMP_VIEWABLE_CLASS (klass);
|
2003-12-08 17:12:25 +08:00
|
|
|
|
gchar *creator;
|
2001-08-09 17:07:17 +08:00
|
|
|
|
|
2002-04-17 04:25:27 +08:00
|
|
|
|
gimp_imagefile_signals[INFO_CHANGED] =
|
2005-05-27 21:05:26 +08:00
|
|
|
|
g_signal_new ("info-changed",
|
2004-08-11 22:00:08 +08:00
|
|
|
|
G_TYPE_FROM_CLASS (klass),
|
|
|
|
|
G_SIGNAL_RUN_FIRST,
|
|
|
|
|
G_STRUCT_OFFSET (GimpImagefileClass, info_changed),
|
|
|
|
|
NULL, NULL,
|
|
|
|
|
gimp_marshal_VOID__VOID,
|
|
|
|
|
G_TYPE_NONE, 0);
|
2002-04-17 04:25:27 +08:00
|
|
|
|
|
2011-06-20 05:06:33 +08:00
|
|
|
|
object_class->dispose = gimp_imagefile_dispose;
|
2002-04-29 07:10:42 +08:00
|
|
|
|
object_class->finalize = gimp_imagefile_finalize;
|
|
|
|
|
|
|
|
|
|
gimp_object_class->name_changed = gimp_imagefile_name_changed;
|
|
|
|
|
|
2005-05-27 21:05:26 +08:00
|
|
|
|
viewable_class->name_changed_signal = "info-changed";
|
2004-09-27 07:44:24 +08:00
|
|
|
|
viewable_class->get_new_pixbuf = gimp_imagefile_get_new_pixbuf;
|
2003-04-09 00:01:01 +08:00
|
|
|
|
viewable_class->get_description = gimp_imagefile_get_description;
|
2002-04-17 07:03:23 +08:00
|
|
|
|
|
2004-01-06 10:33:08 +08:00
|
|
|
|
g_type_class_ref (GIMP_TYPE_IMAGE_TYPE);
|
|
|
|
|
|
2003-12-08 17:12:25 +08:00
|
|
|
|
creator = g_strdup_printf ("gimp-%d.%d",
|
|
|
|
|
GIMP_MAJOR_VERSION, GIMP_MINOR_VERSION);
|
2002-04-18 22:14:50 +08:00
|
|
|
|
|
2003-12-08 17:12:25 +08:00
|
|
|
|
gimp_thumb_init (creator, NULL);
|
2002-04-18 22:14:50 +08:00
|
|
|
|
|
2003-12-08 17:12:25 +08:00
|
|
|
|
g_free (creator);
|
2001-08-09 17:07:17 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
|
gimp_imagefile_init (GimpImagefile *imagefile)
|
|
|
|
|
{
|
2011-03-02 19:26:04 +08:00
|
|
|
|
GimpImagefilePrivate *private = GET_PRIVATE (imagefile);
|
|
|
|
|
|
|
|
|
|
private->thumbnail = gimp_thumbnail_new ();
|
2004-01-06 10:33:08 +08:00
|
|
|
|
|
2011-03-02 19:26:04 +08:00
|
|
|
|
g_signal_connect_object (private->thumbnail, "notify",
|
2004-01-06 10:33:08 +08:00
|
|
|
|
G_CALLBACK (gimp_imagefile_notify_thumbnail),
|
|
|
|
|
imagefile, G_CONNECT_SWAPPED);
|
2001-08-09 17:07:17 +08:00
|
|
|
|
}
|
|
|
|
|
|
2011-06-20 05:06:33 +08:00
|
|
|
|
static void
|
|
|
|
|
gimp_imagefile_dispose (GObject *object)
|
|
|
|
|
{
|
|
|
|
|
GimpImagefilePrivate *private = GET_PRIVATE (object);
|
|
|
|
|
|
|
|
|
|
if (private->icon_cancellable)
|
|
|
|
|
{
|
|
|
|
|
g_cancellable_cancel (private->icon_cancellable);
|
2017-07-16 00:38:01 +08:00
|
|
|
|
g_clear_object (&private->icon_cancellable);
|
2011-06-20 05:06:33 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
G_OBJECT_CLASS (parent_class)->dispose (object);
|
|
|
|
|
}
|
|
|
|
|
|
2002-04-17 07:59:53 +08:00
|
|
|
|
static void
|
|
|
|
|
gimp_imagefile_finalize (GObject *object)
|
|
|
|
|
{
|
2011-03-02 19:26:04 +08:00
|
|
|
|
GimpImagefilePrivate *private = GET_PRIVATE (object);
|
2003-12-08 17:12:25 +08:00
|
|
|
|
|
2011-03-02 19:26:04 +08:00
|
|
|
|
if (private->description)
|
2003-12-08 17:12:25 +08:00
|
|
|
|
{
|
2011-03-02 19:26:04 +08:00
|
|
|
|
if (! private->static_desc)
|
|
|
|
|
g_free (private->description);
|
2002-04-17 07:59:53 +08:00
|
|
|
|
|
2011-03-02 19:26:04 +08:00
|
|
|
|
private->description = NULL;
|
2003-12-08 17:12:25 +08:00
|
|
|
|
}
|
|
|
|
|
|
2017-07-16 00:38:01 +08:00
|
|
|
|
g_clear_object (&private->thumbnail);
|
|
|
|
|
g_clear_object (&private->icon);
|
|
|
|
|
g_clear_object (&private->file);
|
2014-07-05 18:51:54 +08:00
|
|
|
|
|
2002-04-17 07:59:53 +08:00
|
|
|
|
G_OBJECT_CLASS (parent_class)->finalize (object);
|
|
|
|
|
}
|
|
|
|
|
|
2014-07-10 02:10:58 +08:00
|
|
|
|
static void
|
|
|
|
|
gimp_imagefile_name_changed (GimpObject *object)
|
|
|
|
|
{
|
|
|
|
|
GimpImagefilePrivate *private = GET_PRIVATE (object);
|
|
|
|
|
|
|
|
|
|
if (GIMP_OBJECT_CLASS (parent_class)->name_changed)
|
|
|
|
|
GIMP_OBJECT_CLASS (parent_class)->name_changed (object);
|
|
|
|
|
|
|
|
|
|
gimp_thumbnail_set_uri (private->thumbnail, gimp_object_get_name (object));
|
|
|
|
|
|
2017-07-16 00:38:01 +08:00
|
|
|
|
g_clear_object (&private->file);
|
2014-07-10 02:10:58 +08:00
|
|
|
|
|
|
|
|
|
if (gimp_object_get_name (object))
|
|
|
|
|
private->file = g_file_new_for_uri (gimp_object_get_name (object));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static GdkPixbuf *
|
|
|
|
|
gimp_imagefile_get_new_pixbuf (GimpViewable *viewable,
|
|
|
|
|
GimpContext *context,
|
|
|
|
|
gint width,
|
|
|
|
|
gint height)
|
|
|
|
|
{
|
|
|
|
|
GimpImagefile *imagefile = GIMP_IMAGEFILE (viewable);
|
|
|
|
|
|
|
|
|
|
if (! gimp_object_get_name (imagefile))
|
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
|
|
return gimp_imagefile_load_thumb (imagefile, width, height);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static gchar *
|
|
|
|
|
gimp_imagefile_get_description (GimpViewable *viewable,
|
|
|
|
|
gchar **tooltip)
|
|
|
|
|
{
|
|
|
|
|
GimpImagefile *imagefile = GIMP_IMAGEFILE (viewable);
|
|
|
|
|
GimpImagefilePrivate *private = GET_PRIVATE (imagefile);
|
|
|
|
|
GimpThumbnail *thumbnail = private->thumbnail;
|
|
|
|
|
gchar *basename;
|
|
|
|
|
|
|
|
|
|
if (! private->file)
|
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
|
|
if (tooltip)
|
|
|
|
|
{
|
|
|
|
|
const gchar *name;
|
|
|
|
|
const gchar *desc;
|
|
|
|
|
|
|
|
|
|
name = gimp_file_get_utf8_name (private->file);
|
|
|
|
|
desc = gimp_imagefile_get_desc_string (imagefile);
|
|
|
|
|
|
|
|
|
|
if (desc)
|
|
|
|
|
*tooltip = g_strdup_printf ("%s\n%s", name, desc);
|
|
|
|
|
else
|
|
|
|
|
*tooltip = g_strdup (name);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
basename = g_path_get_basename (gimp_file_get_utf8_name (private->file));
|
|
|
|
|
|
|
|
|
|
if (thumbnail->image_width > 0 && thumbnail->image_height > 0)
|
|
|
|
|
{
|
|
|
|
|
gchar *tmp = basename;
|
|
|
|
|
|
|
|
|
|
basename = g_strdup_printf ("%s (%d × %d)",
|
|
|
|
|
tmp,
|
|
|
|
|
thumbnail->image_width,
|
|
|
|
|
thumbnail->image_height);
|
|
|
|
|
g_free (tmp);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return basename;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/* public functions */
|
|
|
|
|
|
2001-08-09 17:07:17 +08:00
|
|
|
|
GimpImagefile *
|
2014-07-05 18:51:54 +08:00
|
|
|
|
gimp_imagefile_new (Gimp *gimp,
|
|
|
|
|
GFile *file)
|
2001-08-09 17:07:17 +08:00
|
|
|
|
{
|
|
|
|
|
GimpImagefile *imagefile;
|
|
|
|
|
|
2003-01-25 01:38:24 +08:00
|
|
|
|
g_return_val_if_fail (GIMP_IS_GIMP (gimp), NULL);
|
2014-07-05 18:51:54 +08:00
|
|
|
|
g_return_val_if_fail (file == NULL || G_IS_FILE (file), NULL);
|
2003-01-25 01:38:24 +08:00
|
|
|
|
|
2003-03-12 05:04:09 +08:00
|
|
|
|
imagefile = g_object_new (GIMP_TYPE_IMAGEFILE, NULL);
|
2001-08-11 15:47:35 +08:00
|
|
|
|
|
2011-03-02 19:26:04 +08:00
|
|
|
|
GET_PRIVATE (imagefile)->gimp = gimp;
|
2003-12-08 17:12:25 +08:00
|
|
|
|
|
2014-07-05 18:51:54 +08:00
|
|
|
|
if (file)
|
|
|
|
|
{
|
|
|
|
|
gimp_object_take_name (GIMP_OBJECT (imagefile), g_file_get_uri (file));
|
|
|
|
|
|
|
|
|
|
/* file member gets created by gimp_imagefile_name_changed() */
|
|
|
|
|
}
|
2001-08-09 17:07:17 +08:00
|
|
|
|
|
|
|
|
|
return imagefile;
|
|
|
|
|
}
|
|
|
|
|
|
2014-07-07 06:46:25 +08:00
|
|
|
|
GFile *
|
|
|
|
|
gimp_imagefile_get_file (GimpImagefile *imagefile)
|
|
|
|
|
{
|
|
|
|
|
g_return_val_if_fail (GIMP_IS_IMAGEFILE (imagefile), NULL);
|
|
|
|
|
|
|
|
|
|
return GET_PRIVATE (imagefile)->file;
|
|
|
|
|
}
|
|
|
|
|
|
2014-07-08 06:49:05 +08:00
|
|
|
|
void
|
|
|
|
|
gimp_imagefile_set_file (GimpImagefile *imagefile,
|
|
|
|
|
GFile *file)
|
|
|
|
|
{
|
|
|
|
|
g_return_if_fail (GIMP_IS_IMAGEFILE (imagefile));
|
2014-07-10 02:10:58 +08:00
|
|
|
|
g_return_if_fail (file == NULL || G_IS_FILE (file));
|
2014-07-08 06:49:05 +08:00
|
|
|
|
|
2014-07-14 01:13:11 +08:00
|
|
|
|
if (GET_PRIVATE (imagefile)->file != file)
|
|
|
|
|
{
|
|
|
|
|
gimp_object_take_name (GIMP_OBJECT (imagefile),
|
|
|
|
|
file ? g_file_get_uri (file) : NULL);
|
|
|
|
|
}
|
2014-07-08 06:49:05 +08:00
|
|
|
|
}
|
|
|
|
|
|
2011-03-02 19:26:04 +08:00
|
|
|
|
GimpThumbnail *
|
|
|
|
|
gimp_imagefile_get_thumbnail (GimpImagefile *imagefile)
|
|
|
|
|
{
|
|
|
|
|
g_return_val_if_fail (GIMP_IS_IMAGEFILE (imagefile), NULL);
|
|
|
|
|
|
|
|
|
|
return GET_PRIVATE (imagefile)->thumbnail;
|
|
|
|
|
}
|
|
|
|
|
|
2011-06-20 05:06:33 +08:00
|
|
|
|
GIcon *
|
|
|
|
|
gimp_imagefile_get_gicon (GimpImagefile *imagefile)
|
|
|
|
|
{
|
|
|
|
|
GimpImagefilePrivate *private;
|
|
|
|
|
|
|
|
|
|
g_return_val_if_fail (GIMP_IS_IMAGEFILE (imagefile), NULL);
|
|
|
|
|
|
|
|
|
|
private = GET_PRIVATE (imagefile);
|
|
|
|
|
|
|
|
|
|
if (private->icon)
|
|
|
|
|
return private->icon;
|
|
|
|
|
|
2014-07-10 02:10:58 +08:00
|
|
|
|
if (private->file && ! private->icon_cancellable)
|
2011-06-20 05:06:33 +08:00
|
|
|
|
{
|
|
|
|
|
private->icon_cancellable = g_cancellable_new ();
|
|
|
|
|
|
2014-07-05 18:51:54 +08:00
|
|
|
|
g_file_query_info_async (private->file, "standard::icon",
|
2011-06-20 05:06:33 +08:00
|
|
|
|
G_FILE_QUERY_INFO_NONE,
|
|
|
|
|
G_PRIORITY_DEFAULT,
|
|
|
|
|
private->icon_cancellable,
|
|
|
|
|
gimp_imagefile_icon_callback,
|
|
|
|
|
imagefile);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return NULL;
|
|
|
|
|
}
|
|
|
|
|
|
2008-03-24 19:11:15 +08:00
|
|
|
|
void
|
|
|
|
|
gimp_imagefile_set_mime_type (GimpImagefile *imagefile,
|
|
|
|
|
const gchar *mime_type)
|
|
|
|
|
{
|
|
|
|
|
g_return_if_fail (GIMP_IS_IMAGEFILE (imagefile));
|
|
|
|
|
|
2011-03-02 19:26:04 +08:00
|
|
|
|
g_object_set (GET_PRIVATE (imagefile)->thumbnail,
|
2008-03-24 19:11:15 +08:00
|
|
|
|
"image-mimetype", mime_type,
|
|
|
|
|
NULL);
|
|
|
|
|
}
|
|
|
|
|
|
2002-04-17 04:25:27 +08:00
|
|
|
|
void
|
2004-01-11 07:55:28 +08:00
|
|
|
|
gimp_imagefile_update (GimpImagefile *imagefile)
|
2002-04-17 04:25:27 +08:00
|
|
|
|
{
|
2011-03-02 19:26:04 +08:00
|
|
|
|
GimpImagefilePrivate *private;
|
|
|
|
|
gchar *uri;
|
2004-01-06 10:33:08 +08:00
|
|
|
|
|
2002-04-17 04:25:27 +08:00
|
|
|
|
g_return_if_fail (GIMP_IS_IMAGEFILE (imagefile));
|
|
|
|
|
|
2011-03-02 19:26:04 +08:00
|
|
|
|
private = GET_PRIVATE (imagefile);
|
|
|
|
|
|
2002-04-17 07:03:23 +08:00
|
|
|
|
gimp_viewable_invalidate_preview (GIMP_VIEWABLE (imagefile));
|
2002-04-17 04:25:27 +08:00
|
|
|
|
|
2011-03-02 19:26:04 +08:00
|
|
|
|
g_object_get (private->thumbnail,
|
2004-01-06 10:33:08 +08:00
|
|
|
|
"image-uri", &uri,
|
|
|
|
|
NULL);
|
2003-12-08 17:12:25 +08:00
|
|
|
|
|
2002-04-17 07:03:23 +08:00
|
|
|
|
if (uri)
|
|
|
|
|
{
|
2004-01-11 07:55:28 +08:00
|
|
|
|
GimpImagefile *documents_imagefile = (GimpImagefile *)
|
2011-03-02 19:26:04 +08:00
|
|
|
|
gimp_container_get_child_by_name (private->gimp->documents, uri);
|
2002-04-17 04:25:27 +08:00
|
|
|
|
|
2004-01-11 07:55:28 +08:00
|
|
|
|
if (documents_imagefile != imagefile &&
|
|
|
|
|
GIMP_IS_IMAGEFILE (documents_imagefile))
|
|
|
|
|
gimp_viewable_invalidate_preview (GIMP_VIEWABLE (documents_imagefile));
|
2004-01-06 10:33:08 +08:00
|
|
|
|
|
|
|
|
|
g_free (uri);
|
2002-04-17 04:25:27 +08:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2013-05-27 03:26:08 +08:00
|
|
|
|
gboolean
|
|
|
|
|
gimp_imagefile_create_thumbnail (GimpImagefile *imagefile,
|
|
|
|
|
GimpContext *context,
|
|
|
|
|
GimpProgress *progress,
|
|
|
|
|
gint size,
|
|
|
|
|
gboolean replace,
|
|
|
|
|
GError **error)
|
2002-04-17 04:25:27 +08:00
|
|
|
|
{
|
2011-03-02 19:26:04 +08:00
|
|
|
|
GimpImagefilePrivate *private;
|
|
|
|
|
GimpThumbnail *thumbnail;
|
|
|
|
|
GimpThumbState image_state;
|
2004-03-03 23:30:48 +08:00
|
|
|
|
|
2013-05-27 03:26:08 +08:00
|
|
|
|
g_return_val_if_fail (GIMP_IS_IMAGEFILE (imagefile), FALSE);
|
|
|
|
|
g_return_val_if_fail (GIMP_IS_CONTEXT (context), FALSE);
|
|
|
|
|
g_return_val_if_fail (progress == NULL || GIMP_IS_PROGRESS (progress), FALSE);
|
|
|
|
|
g_return_val_if_fail (error == NULL || *error == NULL, FALSE);
|
2002-04-17 04:25:27 +08:00
|
|
|
|
|
2013-05-27 03:26:08 +08:00
|
|
|
|
/* thumbnailing is disabled, we successfully did nothing */
|
2003-12-08 17:12:25 +08:00
|
|
|
|
if (size < 1)
|
2013-05-27 03:26:08 +08:00
|
|
|
|
return TRUE;
|
2002-04-30 03:41:45 +08:00
|
|
|
|
|
2011-03-02 19:26:04 +08:00
|
|
|
|
private = GET_PRIVATE (imagefile);
|
|
|
|
|
|
|
|
|
|
thumbnail = private->thumbnail;
|
2004-03-03 23:30:48 +08:00
|
|
|
|
|
|
|
|
|
gimp_thumbnail_set_uri (thumbnail,
|
2009-09-01 04:47:18 +08:00
|
|
|
|
gimp_object_get_name (imagefile));
|
2002-04-30 09:40:44 +08:00
|
|
|
|
|
2005-02-09 08:47:09 +08:00
|
|
|
|
image_state = gimp_thumbnail_peek_image (thumbnail);
|
|
|
|
|
|
|
|
|
|
if (image_state == GIMP_THUMB_STATE_REMOTE ||
|
|
|
|
|
image_state >= GIMP_THUMB_STATE_EXISTS)
|
2002-04-17 04:25:27 +08:00
|
|
|
|
{
|
2008-11-10 16:21:36 +08:00
|
|
|
|
GimpImage *image;
|
|
|
|
|
gboolean success;
|
|
|
|
|
gint width = 0;
|
|
|
|
|
gint height = 0;
|
|
|
|
|
const gchar *mime_type = NULL;
|
2012-04-12 03:54:23 +08:00
|
|
|
|
const Babl *format = NULL;
|
2008-11-10 16:21:36 +08:00
|
|
|
|
gint num_layers = -1;
|
2002-04-17 04:25:27 +08:00
|
|
|
|
|
2013-11-24 01:05:55 +08:00
|
|
|
|
/* we only want to attempt thumbnailing on readable, regular files */
|
2014-07-07 06:46:25 +08:00
|
|
|
|
if (g_file_is_native (private->file))
|
2013-11-24 01:05:55 +08:00
|
|
|
|
{
|
|
|
|
|
GFileInfo *file_info;
|
|
|
|
|
gboolean regular;
|
|
|
|
|
gboolean readable;
|
|
|
|
|
|
2014-07-07 06:46:25 +08:00
|
|
|
|
file_info = g_file_query_info (private->file,
|
2013-11-24 01:05:55 +08:00
|
|
|
|
G_FILE_ATTRIBUTE_STANDARD_TYPE ","
|
|
|
|
|
G_FILE_ATTRIBUTE_ACCESS_CAN_READ,
|
|
|
|
|
G_FILE_QUERY_INFO_NONE,
|
|
|
|
|
NULL, NULL);
|
|
|
|
|
|
|
|
|
|
regular = (g_file_info_get_file_type (file_info) == G_FILE_TYPE_REGULAR);
|
|
|
|
|
readable = g_file_info_get_attribute_boolean (file_info,
|
|
|
|
|
G_FILE_ATTRIBUTE_ACCESS_CAN_READ);
|
|
|
|
|
|
|
|
|
|
g_object_unref (file_info);
|
|
|
|
|
|
|
|
|
|
if (! (regular && readable))
|
2014-07-07 06:46:25 +08:00
|
|
|
|
return TRUE;
|
2013-11-24 01:05:55 +08:00
|
|
|
|
}
|
|
|
|
|
|
2004-10-13 07:25:19 +08:00
|
|
|
|
g_object_ref (imagefile);
|
|
|
|
|
|
2013-05-27 03:26:08 +08:00
|
|
|
|
/* don't pass the error, we're only interested in errors from
|
|
|
|
|
* actual thumbnail saving
|
|
|
|
|
*/
|
2011-03-02 19:26:04 +08:00
|
|
|
|
image = file_open_thumbnail (private->gimp, context, progress,
|
2014-07-07 06:46:25 +08:00
|
|
|
|
private->file, size,
|
2008-11-10 16:21:36 +08:00
|
|
|
|
&mime_type, &width, &height,
|
2012-04-12 03:54:23 +08:00
|
|
|
|
&format, &num_layers, NULL);
|
2002-04-17 04:25:27 +08:00
|
|
|
|
|
2004-11-14 01:06:06 +08:00
|
|
|
|
if (image)
|
2002-04-17 04:25:27 +08:00
|
|
|
|
{
|
2011-03-02 19:26:04 +08:00
|
|
|
|
gimp_thumbnail_set_info (private->thumbnail,
|
2008-11-10 16:21:36 +08:00
|
|
|
|
mime_type, width, height,
|
2012-04-12 03:54:23 +08:00
|
|
|
|
format, num_layers);
|
2004-11-14 01:06:06 +08:00
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
GimpPDBStatusType status;
|
|
|
|
|
|
2013-05-27 03:26:08 +08:00
|
|
|
|
/* don't pass the error, we're only interested in errors
|
|
|
|
|
* from actual thumbnail saving
|
|
|
|
|
*/
|
2011-03-02 19:26:04 +08:00
|
|
|
|
image = file_open_image (private->gimp, context, progress,
|
2014-07-07 06:46:25 +08:00
|
|
|
|
private->file,
|
2007-04-17 23:54:01 +08:00
|
|
|
|
FALSE, NULL, GIMP_RUN_NONINTERACTIVE,
|
2004-11-14 01:06:06 +08:00
|
|
|
|
&status, &mime_type, NULL);
|
|
|
|
|
|
|
|
|
|
if (image)
|
2011-03-02 19:26:04 +08:00
|
|
|
|
gimp_thumbnail_set_info_from_image (private->thumbnail,
|
2004-11-14 01:06:06 +08:00
|
|
|
|
mime_type, image);
|
|
|
|
|
}
|
2004-05-14 08:01:11 +08:00
|
|
|
|
|
2004-11-14 01:06:06 +08:00
|
|
|
|
if (image)
|
|
|
|
|
{
|
2003-12-08 17:12:25 +08:00
|
|
|
|
success = gimp_imagefile_save_thumb (imagefile,
|
2004-11-14 01:06:06 +08:00
|
|
|
|
image, size, replace,
|
2013-05-27 03:26:08 +08:00
|
|
|
|
error);
|
2002-04-17 04:25:27 +08:00
|
|
|
|
|
2004-11-14 01:06:06 +08:00
|
|
|
|
g_object_unref (image);
|
2002-04-19 20:05:47 +08:00
|
|
|
|
}
|
2002-04-29 07:10:42 +08:00
|
|
|
|
else
|
|
|
|
|
{
|
2004-03-03 23:30:48 +08:00
|
|
|
|
success = gimp_thumbnail_save_failure (thumbnail,
|
2006-12-10 05:49:23 +08:00
|
|
|
|
"GIMP " GIMP_VERSION,
|
2013-05-27 03:26:08 +08:00
|
|
|
|
error);
|
2004-10-23 23:30:39 +08:00
|
|
|
|
gimp_imagefile_update (imagefile);
|
2002-04-29 07:10:42 +08:00
|
|
|
|
}
|
2002-04-30 01:20:26 +08:00
|
|
|
|
|
2004-10-13 07:25:19 +08:00
|
|
|
|
g_object_unref (imagefile);
|
|
|
|
|
|
2013-12-22 22:25:05 +08:00
|
|
|
|
if (! success)
|
|
|
|
|
{
|
|
|
|
|
g_object_set (thumbnail,
|
|
|
|
|
"thumb-state", GIMP_THUMB_STATE_FAILED,
|
|
|
|
|
NULL);
|
|
|
|
|
}
|
|
|
|
|
|
2013-05-27 03:26:08 +08:00
|
|
|
|
return success;
|
2002-04-30 01:20:26 +08:00
|
|
|
|
}
|
2013-05-27 03:26:08 +08:00
|
|
|
|
|
|
|
|
|
return TRUE;
|
2002-04-30 01:20:26 +08:00
|
|
|
|
}
|
|
|
|
|
|
2004-10-13 07:25:19 +08:00
|
|
|
|
/* The weak version doesn't ref the imagefile but deals gracefully
|
|
|
|
|
* with an imagefile that is destroyed while the thumbnail is
|
2016-07-02 01:50:13 +08:00
|
|
|
|
* created. This allows one to use this function w/o the need to
|
2012-11-11 22:50:25 +08:00
|
|
|
|
* block the user interface.
|
2004-10-13 07:25:19 +08:00
|
|
|
|
*/
|
|
|
|
|
void
|
|
|
|
|
gimp_imagefile_create_thumbnail_weak (GimpImagefile *imagefile,
|
|
|
|
|
GimpContext *context,
|
|
|
|
|
GimpProgress *progress,
|
2004-10-23 23:30:39 +08:00
|
|
|
|
gint size,
|
|
|
|
|
gboolean replace)
|
2004-10-13 07:25:19 +08:00
|
|
|
|
{
|
2011-03-02 19:26:04 +08:00
|
|
|
|
GimpImagefilePrivate *private;
|
|
|
|
|
GimpImagefile *local;
|
2004-10-13 07:25:19 +08:00
|
|
|
|
|
|
|
|
|
g_return_if_fail (GIMP_IS_IMAGEFILE (imagefile));
|
|
|
|
|
|
|
|
|
|
if (size < 1)
|
|
|
|
|
return;
|
|
|
|
|
|
2011-03-02 19:26:04 +08:00
|
|
|
|
private = GET_PRIVATE (imagefile);
|
|
|
|
|
|
2014-07-10 02:10:58 +08:00
|
|
|
|
if (! private->file)
|
2004-10-13 07:25:19 +08:00
|
|
|
|
return;
|
|
|
|
|
|
2014-07-05 18:51:54 +08:00
|
|
|
|
local = gimp_imagefile_new (private->gimp, private->file);
|
2004-10-13 07:25:19 +08:00
|
|
|
|
|
|
|
|
|
g_object_add_weak_pointer (G_OBJECT (imagefile), (gpointer) &imagefile);
|
|
|
|
|
|
2013-12-22 22:25:05 +08:00
|
|
|
|
if (! gimp_imagefile_create_thumbnail (local, context, progress, size, replace,
|
|
|
|
|
NULL))
|
|
|
|
|
{
|
2014-07-05 18:51:54 +08:00
|
|
|
|
/* The weak version works on a local copy so the thumbnail
|
|
|
|
|
* status of the actual image is not properly updated in case of
|
|
|
|
|
* creation failure, thus it would end up in a generic
|
|
|
|
|
* GIMP_THUMB_STATE_NOT_FOUND, which is less informative.
|
|
|
|
|
*/
|
2013-12-22 22:25:05 +08:00
|
|
|
|
g_object_set (private->thumbnail,
|
|
|
|
|
"thumb-state", GIMP_THUMB_STATE_FAILED,
|
|
|
|
|
NULL);
|
|
|
|
|
}
|
2004-10-13 07:25:19 +08:00
|
|
|
|
|
|
|
|
|
if (imagefile)
|
|
|
|
|
{
|
2014-07-10 02:10:58 +08:00
|
|
|
|
GFile *file = gimp_imagefile_get_file (imagefile);
|
2004-10-13 07:25:19 +08:00
|
|
|
|
|
2014-07-10 02:10:58 +08:00
|
|
|
|
if (file && g_file_equal (file, gimp_imagefile_get_file (local)))
|
2004-10-13 07:25:19 +08:00
|
|
|
|
{
|
|
|
|
|
gimp_imagefile_update (imagefile);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
g_object_remove_weak_pointer (G_OBJECT (imagefile),
|
|
|
|
|
(gpointer) &imagefile);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
g_object_unref (local);
|
|
|
|
|
}
|
|
|
|
|
|
2004-10-23 23:30:39 +08:00
|
|
|
|
gboolean
|
|
|
|
|
gimp_imagefile_check_thumbnail (GimpImagefile *imagefile)
|
|
|
|
|
{
|
2011-03-02 19:26:04 +08:00
|
|
|
|
GimpImagefilePrivate *private;
|
|
|
|
|
gint size;
|
2004-10-23 23:30:39 +08:00
|
|
|
|
|
|
|
|
|
g_return_val_if_fail (GIMP_IS_IMAGEFILE (imagefile), FALSE);
|
|
|
|
|
|
2011-03-02 19:26:04 +08:00
|
|
|
|
private = GET_PRIVATE (imagefile);
|
|
|
|
|
|
|
|
|
|
size = private->gimp->config->thumbnail_size;
|
2004-10-23 23:30:39 +08:00
|
|
|
|
|
|
|
|
|
if (size > 0)
|
|
|
|
|
{
|
|
|
|
|
GimpThumbState state;
|
|
|
|
|
|
2011-03-02 19:26:04 +08:00
|
|
|
|
state = gimp_thumbnail_check_thumb (private->thumbnail, size);
|
2004-10-23 23:30:39 +08:00
|
|
|
|
|
|
|
|
|
return (state == GIMP_THUMB_STATE_OK);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
|
}
|
|
|
|
|
|
2002-04-20 01:15:39 +08:00
|
|
|
|
gboolean
|
2013-05-27 03:26:08 +08:00
|
|
|
|
gimp_imagefile_save_thumbnail (GimpImagefile *imagefile,
|
|
|
|
|
const gchar *mime_type,
|
|
|
|
|
GimpImage *image,
|
|
|
|
|
GError **error)
|
2002-04-19 20:05:47 +08:00
|
|
|
|
{
|
2011-03-02 19:26:04 +08:00
|
|
|
|
GimpImagefilePrivate *private;
|
|
|
|
|
gint size;
|
|
|
|
|
gboolean success = TRUE;
|
2002-04-19 20:05:47 +08:00
|
|
|
|
|
2002-04-20 01:15:39 +08:00
|
|
|
|
g_return_val_if_fail (GIMP_IS_IMAGEFILE (imagefile), FALSE);
|
2006-03-29 01:08:36 +08:00
|
|
|
|
g_return_val_if_fail (GIMP_IS_IMAGE (image), FALSE);
|
2013-05-27 03:26:08 +08:00
|
|
|
|
g_return_val_if_fail (error == NULL || *error == NULL, FALSE);
|
2002-04-30 03:41:45 +08:00
|
|
|
|
|
2011-03-02 19:26:04 +08:00
|
|
|
|
private = GET_PRIVATE (imagefile);
|
|
|
|
|
|
|
|
|
|
size = private->gimp->config->thumbnail_size;
|
2002-04-19 20:05:47 +08:00
|
|
|
|
|
2004-10-23 23:30:39 +08:00
|
|
|
|
if (size > 0)
|
2002-04-19 20:05:47 +08:00
|
|
|
|
{
|
2011-03-02 19:26:04 +08:00
|
|
|
|
gimp_thumbnail_set_info_from_image (private->thumbnail,
|
2006-03-29 01:08:36 +08:00
|
|
|
|
mime_type, image);
|
2004-10-23 23:30:39 +08:00
|
|
|
|
|
|
|
|
|
success = gimp_imagefile_save_thumb (imagefile,
|
2006-03-29 01:08:36 +08:00
|
|
|
|
image, size, FALSE,
|
2013-05-27 03:26:08 +08:00
|
|
|
|
error);
|
2003-04-02 19:26:02 +08:00
|
|
|
|
}
|
2002-04-20 01:15:39 +08:00
|
|
|
|
|
|
|
|
|
return success;
|
2002-04-17 04:25:27 +08:00
|
|
|
|
}
|
|
|
|
|
|
2011-03-02 19:26:04 +08:00
|
|
|
|
|
|
|
|
|
/* private functions */
|
|
|
|
|
|
2004-01-06 22:29:35 +08:00
|
|
|
|
static void
|
|
|
|
|
gimp_imagefile_info_changed (GimpImagefile *imagefile)
|
|
|
|
|
{
|
2011-03-02 19:26:04 +08:00
|
|
|
|
GimpImagefilePrivate *private = GET_PRIVATE (imagefile);
|
|
|
|
|
|
|
|
|
|
if (private->description)
|
2004-01-06 22:29:35 +08:00
|
|
|
|
{
|
2011-03-02 19:26:04 +08:00
|
|
|
|
if (! private->static_desc)
|
|
|
|
|
g_free (private->description);
|
2004-01-06 22:29:35 +08:00
|
|
|
|
|
2011-03-02 19:26:04 +08:00
|
|
|
|
private->description = NULL;
|
2004-01-06 22:29:35 +08:00
|
|
|
|
}
|
2017-07-16 00:38:01 +08:00
|
|
|
|
|
|
|
|
|
g_clear_object (&private->icon);
|
2004-01-06 22:29:35 +08:00
|
|
|
|
|
|
|
|
|
g_signal_emit (imagefile, gimp_imagefile_signals[INFO_CHANGED], 0);
|
|
|
|
|
}
|
|
|
|
|
|
2004-01-06 10:33:08 +08:00
|
|
|
|
static void
|
|
|
|
|
gimp_imagefile_notify_thumbnail (GimpImagefile *imagefile,
|
|
|
|
|
GParamSpec *pspec)
|
|
|
|
|
{
|
|
|
|
|
if (strcmp (pspec->name, "image-state") == 0 ||
|
|
|
|
|
strcmp (pspec->name, "thumb-state") == 0)
|
|
|
|
|
{
|
2004-01-06 22:29:35 +08:00
|
|
|
|
gimp_imagefile_info_changed (imagefile);
|
2004-01-06 10:33:08 +08:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2011-06-20 05:06:33 +08:00
|
|
|
|
static void
|
|
|
|
|
gimp_imagefile_icon_callback (GObject *source_object,
|
|
|
|
|
GAsyncResult *result,
|
|
|
|
|
gpointer data)
|
|
|
|
|
{
|
2011-06-20 05:31:29 +08:00
|
|
|
|
GimpImagefile *imagefile;
|
|
|
|
|
GimpImagefilePrivate *private;
|
|
|
|
|
GFile *file = G_FILE (source_object);
|
|
|
|
|
GError *error = NULL;
|
2011-06-20 05:06:33 +08:00
|
|
|
|
GFileInfo *file_info;
|
|
|
|
|
|
|
|
|
|
file_info = g_file_query_info_finish (file, result, &error);
|
|
|
|
|
|
2011-06-20 05:31:29 +08:00
|
|
|
|
if (error)
|
|
|
|
|
{
|
|
|
|
|
/* we were cancelled from dispose() and the imagefile is
|
|
|
|
|
* long gone, bail out
|
|
|
|
|
*/
|
|
|
|
|
if (g_error_matches (error, G_IO_ERROR, G_IO_ERROR_CANCELLED))
|
|
|
|
|
{
|
|
|
|
|
g_clear_error (&error);
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#ifdef GIMP_UNSTABLE
|
|
|
|
|
g_printerr ("%s: %s\n", G_STRFUNC, error->message);
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
g_clear_error (&error);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
imagefile = GIMP_IMAGEFILE (data);
|
|
|
|
|
private = GET_PRIVATE (imagefile);
|
|
|
|
|
|
2011-06-20 05:06:33 +08:00
|
|
|
|
if (file_info)
|
|
|
|
|
{
|
|
|
|
|
private->icon = g_object_ref (g_file_info_get_icon (file_info));
|
|
|
|
|
g_object_unref (file_info);
|
|
|
|
|
}
|
|
|
|
|
|
2017-07-16 00:38:01 +08:00
|
|
|
|
g_clear_object (&private->icon_cancellable);
|
2011-06-20 05:06:33 +08:00
|
|
|
|
|
|
|
|
|
if (private->icon)
|
|
|
|
|
gimp_viewable_invalidate_preview (GIMP_VIEWABLE (imagefile));
|
|
|
|
|
}
|
|
|
|
|
|
2002-04-17 07:59:53 +08:00
|
|
|
|
const gchar *
|
2003-04-09 00:01:01 +08:00
|
|
|
|
gimp_imagefile_get_desc_string (GimpImagefile *imagefile)
|
2002-04-17 07:59:53 +08:00
|
|
|
|
{
|
2011-03-02 19:26:04 +08:00
|
|
|
|
GimpImagefilePrivate *private;
|
|
|
|
|
GimpThumbnail *thumbnail;
|
2003-12-08 17:12:25 +08:00
|
|
|
|
|
2002-04-17 07:59:53 +08:00
|
|
|
|
g_return_val_if_fail (GIMP_IS_IMAGEFILE (imagefile), NULL);
|
|
|
|
|
|
2011-03-02 19:26:04 +08:00
|
|
|
|
private = GET_PRIVATE (imagefile);
|
|
|
|
|
|
|
|
|
|
if (private->description)
|
|
|
|
|
return (const gchar *) private->description;
|
2002-04-17 07:59:53 +08:00
|
|
|
|
|
2011-03-02 19:26:04 +08:00
|
|
|
|
thumbnail = private->thumbnail;
|
2003-12-08 17:12:25 +08:00
|
|
|
|
|
|
|
|
|
switch (thumbnail->image_state)
|
2002-04-17 07:59:53 +08:00
|
|
|
|
{
|
2003-12-08 17:12:25 +08:00
|
|
|
|
case GIMP_THUMB_STATE_UNKNOWN:
|
2011-03-02 19:26:04 +08:00
|
|
|
|
private->description = NULL;
|
|
|
|
|
private->static_desc = TRUE;
|
2002-04-29 07:10:42 +08:00
|
|
|
|
break;
|
|
|
|
|
|
2004-02-26 01:33:45 +08:00
|
|
|
|
case GIMP_THUMB_STATE_FOLDER:
|
2011-03-02 19:26:04 +08:00
|
|
|
|
private->description = (gchar *) _("Folder");
|
|
|
|
|
private->static_desc = TRUE;
|
2004-02-26 01:33:45 +08:00
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
case GIMP_THUMB_STATE_SPECIAL:
|
2011-03-02 19:26:04 +08:00
|
|
|
|
private->description = (gchar *) _("Special File");
|
|
|
|
|
private->static_desc = TRUE;
|
2004-02-26 01:33:45 +08:00
|
|
|
|
break;
|
|
|
|
|
|
2003-12-08 17:12:25 +08:00
|
|
|
|
case GIMP_THUMB_STATE_NOT_FOUND:
|
2011-03-02 19:26:04 +08:00
|
|
|
|
private->description =
|
2004-03-03 23:30:48 +08:00
|
|
|
|
(gchar *) g_strerror (thumbnail->image_not_found_errno);
|
2011-03-02 19:26:04 +08:00
|
|
|
|
private->static_desc = TRUE;
|
2002-04-17 07:59:53 +08:00
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
default:
|
2002-04-29 07:10:42 +08:00
|
|
|
|
{
|
2003-12-08 17:12:25 +08:00
|
|
|
|
GString *str = g_string_new (NULL);
|
2002-04-29 07:10:42 +08:00
|
|
|
|
|
2005-02-09 08:47:09 +08:00
|
|
|
|
if (thumbnail->image_state == GIMP_THUMB_STATE_REMOTE)
|
|
|
|
|
{
|
|
|
|
|
g_string_append (str, _("Remote File"));
|
|
|
|
|
}
|
|
|
|
|
|
2003-12-08 17:12:25 +08:00
|
|
|
|
if (thumbnail->image_filesize > 0)
|
2002-04-29 07:10:42 +08:00
|
|
|
|
{
|
2011-09-13 17:39:24 +08:00
|
|
|
|
gchar *size = g_format_size (thumbnail->image_filesize);
|
2002-04-29 07:10:42 +08:00
|
|
|
|
|
2007-05-20 04:09:56 +08:00
|
|
|
|
if (str->len > 0)
|
|
|
|
|
g_string_append_c (str, '\n');
|
|
|
|
|
|
2002-04-29 07:10:42 +08:00
|
|
|
|
g_string_append (str, size);
|
|
|
|
|
g_free (size);
|
|
|
|
|
}
|
|
|
|
|
|
2003-12-08 17:12:25 +08:00
|
|
|
|
switch (thumbnail->thumb_state)
|
2002-04-29 07:10:42 +08:00
|
|
|
|
{
|
2003-12-08 17:12:25 +08:00
|
|
|
|
case GIMP_THUMB_STATE_NOT_FOUND:
|
2007-05-20 04:09:56 +08:00
|
|
|
|
if (str->len > 0)
|
|
|
|
|
g_string_append_c (str, '\n');
|
2004-10-25 06:30:52 +08:00
|
|
|
|
g_string_append (str, _("Click to create preview"));
|
2002-04-30 01:20:26 +08:00
|
|
|
|
break;
|
|
|
|
|
|
2003-12-08 17:12:25 +08:00
|
|
|
|
case GIMP_THUMB_STATE_EXISTS:
|
2007-05-20 04:09:56 +08:00
|
|
|
|
if (str->len > 0)
|
|
|
|
|
g_string_append_c (str, '\n');
|
2005-10-01 01:50:50 +08:00
|
|
|
|
g_string_append (str, _("Loading preview..."));
|
2002-04-29 07:10:42 +08:00
|
|
|
|
break;
|
|
|
|
|
|
2003-12-08 17:12:25 +08:00
|
|
|
|
case GIMP_THUMB_STATE_OLD:
|
2007-05-20 04:09:56 +08:00
|
|
|
|
if (str->len > 0)
|
|
|
|
|
g_string_append_c (str, '\n');
|
2002-04-30 01:20:26 +08:00
|
|
|
|
g_string_append (str, _("Preview is out of date"));
|
2002-04-29 07:10:42 +08:00
|
|
|
|
break;
|
|
|
|
|
|
2003-12-08 17:12:25 +08:00
|
|
|
|
case GIMP_THUMB_STATE_FAILED:
|
2007-05-20 04:09:56 +08:00
|
|
|
|
if (str->len > 0)
|
|
|
|
|
g_string_append_c (str, '\n');
|
2002-04-30 01:20:26 +08:00
|
|
|
|
g_string_append (str, _("Cannot create preview"));
|
2002-04-29 07:10:42 +08:00
|
|
|
|
break;
|
|
|
|
|
|
2003-12-08 17:12:25 +08:00
|
|
|
|
case GIMP_THUMB_STATE_OK:
|
2002-04-30 01:20:26 +08:00
|
|
|
|
{
|
2005-02-09 08:47:09 +08:00
|
|
|
|
if (thumbnail->image_state == GIMP_THUMB_STATE_REMOTE)
|
|
|
|
|
{
|
2007-05-20 04:09:56 +08:00
|
|
|
|
if (str->len > 0)
|
|
|
|
|
g_string_append_c (str, '\n');
|
|
|
|
|
|
2005-02-09 08:47:09 +08:00
|
|
|
|
g_string_append (str, _("(Preview may be out of date)"));
|
|
|
|
|
}
|
|
|
|
|
|
2003-12-08 17:12:25 +08:00
|
|
|
|
if (thumbnail->image_width > 0 && thumbnail->image_height > 0)
|
2002-04-30 01:20:26 +08:00
|
|
|
|
{
|
2007-05-20 04:09:56 +08:00
|
|
|
|
if (str->len > 0)
|
|
|
|
|
g_string_append_c (str, '\n');
|
|
|
|
|
|
2005-11-03 00:07:07 +08:00
|
|
|
|
g_string_append_printf (str,
|
2006-02-28 20:15:51 +08:00
|
|
|
|
ngettext ("%d × %d pixel",
|
|
|
|
|
"%d × %d pixels",
|
2005-11-03 00:07:07 +08:00
|
|
|
|
thumbnail->image_height),
|
2003-12-08 17:12:25 +08:00
|
|
|
|
thumbnail->image_width,
|
|
|
|
|
thumbnail->image_height);
|
2002-04-30 01:20:26 +08:00
|
|
|
|
}
|
2003-11-14 23:33:40 +08:00
|
|
|
|
|
2003-12-08 17:12:25 +08:00
|
|
|
|
if (thumbnail->image_type)
|
2007-05-20 04:09:56 +08:00
|
|
|
|
{
|
|
|
|
|
if (str->len > 0)
|
|
|
|
|
g_string_append_c (str, '\n');
|
|
|
|
|
|
|
|
|
|
g_string_append (str, gettext (thumbnail->image_type));
|
|
|
|
|
}
|
2002-04-30 01:20:26 +08:00
|
|
|
|
|
2003-12-08 17:12:25 +08:00
|
|
|
|
if (thumbnail->image_num_layers > 0)
|
2002-04-30 01:20:26 +08:00
|
|
|
|
{
|
2003-12-08 17:12:25 +08:00
|
|
|
|
if (thumbnail->image_type)
|
2002-04-30 01:20:26 +08:00
|
|
|
|
g_string_append_len (str, ", ", 2);
|
2007-05-20 04:09:56 +08:00
|
|
|
|
else if (str->len > 0)
|
|
|
|
|
g_string_append_c (str, '\n');
|
2002-04-30 01:20:26 +08:00
|
|
|
|
|
2005-09-21 07:09:51 +08:00
|
|
|
|
g_string_append_printf (str,
|
2005-09-21 07:15:57 +08:00
|
|
|
|
ngettext ("%d layer",
|
|
|
|
|
"%d layers",
|
2005-09-21 07:09:51 +08:00
|
|
|
|
thumbnail->image_num_layers),
|
|
|
|
|
thumbnail->image_num_layers);
|
2002-04-30 01:20:26 +08:00
|
|
|
|
}
|
|
|
|
|
}
|
2002-04-29 07:10:42 +08:00
|
|
|
|
break;
|
2003-11-14 23:33:40 +08:00
|
|
|
|
|
2002-04-29 07:10:42 +08:00
|
|
|
|
default:
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
2011-03-02 19:26:04 +08:00
|
|
|
|
private->description = g_string_free (str, FALSE);
|
|
|
|
|
private->static_desc = FALSE;
|
2002-04-29 07:10:42 +08:00
|
|
|
|
}
|
2002-04-17 07:59:53 +08:00
|
|
|
|
}
|
|
|
|
|
|
2011-03-02 19:26:04 +08:00
|
|
|
|
return (const gchar *) private->description;
|
2002-04-17 07:59:53 +08:00
|
|
|
|
}
|
|
|
|
|
|
2004-09-27 07:44:24 +08:00
|
|
|
|
static GdkPixbuf *
|
2003-12-08 17:12:25 +08:00
|
|
|
|
gimp_imagefile_load_thumb (GimpImagefile *imagefile,
|
2004-03-03 23:30:48 +08:00
|
|
|
|
gint width,
|
|
|
|
|
gint height)
|
2001-11-13 11:31:47 +08:00
|
|
|
|
{
|
2011-03-02 19:26:04 +08:00
|
|
|
|
GimpImagefilePrivate *private = GET_PRIVATE (imagefile);
|
|
|
|
|
GimpThumbnail *thumbnail = private->thumbnail;
|
|
|
|
|
GdkPixbuf *pixbuf = NULL;
|
|
|
|
|
GError *error = NULL;
|
|
|
|
|
gint size = MAX (width, height);
|
|
|
|
|
gint pixbuf_width;
|
|
|
|
|
gint pixbuf_height;
|
|
|
|
|
gint preview_width;
|
|
|
|
|
gint preview_height;
|
2002-04-17 04:25:27 +08:00
|
|
|
|
|
2003-12-08 17:12:25 +08:00
|
|
|
|
if (gimp_thumbnail_peek_thumb (thumbnail, size) < GIMP_THUMB_STATE_EXISTS)
|
|
|
|
|
return NULL;
|
2001-11-13 11:31:47 +08:00
|
|
|
|
|
2005-06-15 18:57:33 +08:00
|
|
|
|
if (thumbnail->image_state == GIMP_THUMB_STATE_NOT_FOUND)
|
|
|
|
|
return NULL;
|
|
|
|
|
|
2003-12-08 17:12:25 +08:00
|
|
|
|
pixbuf = gimp_thumbnail_load_thumb (thumbnail, size, &error);
|
2001-11-13 11:31:47 +08:00
|
|
|
|
|
2004-03-03 23:30:48 +08:00
|
|
|
|
if (! pixbuf)
|
2001-11-13 11:31:47 +08:00
|
|
|
|
{
|
2003-12-08 17:12:25 +08:00
|
|
|
|
if (error)
|
2004-09-27 07:44:24 +08:00
|
|
|
|
{
|
2011-03-02 19:26:04 +08:00
|
|
|
|
gimp_message (private->gimp, NULL, GIMP_MESSAGE_ERROR,
|
2006-10-10 02:49:15 +08:00
|
|
|
|
_("Could not open thumbnail '%s': %s"),
|
|
|
|
|
thumbnail->thumb_filename, error->message);
|
|
|
|
|
g_clear_error (&error);
|
2004-09-27 07:44:24 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return NULL;
|
2001-11-13 11:31:47 +08:00
|
|
|
|
}
|
2002-04-29 07:10:42 +08:00
|
|
|
|
|
2007-12-26 00:21:40 +08:00
|
|
|
|
pixbuf_width = gdk_pixbuf_get_width (pixbuf);
|
2004-03-03 23:30:48 +08:00
|
|
|
|
pixbuf_height = gdk_pixbuf_get_height (pixbuf);
|
|
|
|
|
|
|
|
|
|
gimp_viewable_calc_preview_size (pixbuf_width,
|
|
|
|
|
pixbuf_height,
|
|
|
|
|
width,
|
|
|
|
|
height,
|
|
|
|
|
TRUE, 1.0, 1.0,
|
|
|
|
|
&preview_width,
|
|
|
|
|
&preview_height,
|
|
|
|
|
NULL);
|
|
|
|
|
|
|
|
|
|
if (preview_width < pixbuf_width || preview_height < pixbuf_height)
|
|
|
|
|
{
|
2004-09-27 07:44:24 +08:00
|
|
|
|
GdkPixbuf *scaled = gdk_pixbuf_scale_simple (pixbuf,
|
|
|
|
|
preview_width,
|
|
|
|
|
preview_height,
|
|
|
|
|
GDK_INTERP_BILINEAR);
|
2004-03-03 23:30:48 +08:00
|
|
|
|
g_object_unref (pixbuf);
|
|
|
|
|
pixbuf = scaled;
|
|
|
|
|
|
2004-09-27 07:44:24 +08:00
|
|
|
|
pixbuf_width = preview_width;
|
|
|
|
|
pixbuf_height = preview_height;
|
2004-03-03 23:30:48 +08:00
|
|
|
|
}
|
|
|
|
|
|
2004-09-27 07:44:24 +08:00
|
|
|
|
if (gdk_pixbuf_get_n_channels (pixbuf) != 3)
|
|
|
|
|
{
|
|
|
|
|
GdkPixbuf *tmp = gdk_pixbuf_new (GDK_COLORSPACE_RGB, FALSE, 8,
|
|
|
|
|
pixbuf_width, pixbuf_height);
|
2001-11-13 11:31:47 +08:00
|
|
|
|
|
2004-09-27 07:44:24 +08:00
|
|
|
|
gdk_pixbuf_composite_color (pixbuf, tmp,
|
|
|
|
|
0, 0, pixbuf_width, pixbuf_height,
|
|
|
|
|
0.0, 0.0, 1.0, 1.0,
|
|
|
|
|
GDK_INTERP_NEAREST, 255,
|
|
|
|
|
0, 0, GIMP_CHECK_SIZE_SM,
|
|
|
|
|
0x66666666, 0x99999999);
|
2001-11-13 11:31:47 +08:00
|
|
|
|
|
2004-09-27 07:44:24 +08:00
|
|
|
|
g_object_unref (pixbuf);
|
|
|
|
|
pixbuf = tmp;
|
|
|
|
|
}
|
2001-11-13 11:31:47 +08:00
|
|
|
|
|
2004-09-27 07:44:24 +08:00
|
|
|
|
return pixbuf;
|
2001-11-13 11:31:47 +08:00
|
|
|
|
}
|
|
|
|
|
|
2002-04-20 01:15:39 +08:00
|
|
|
|
static gboolean
|
2003-12-08 17:12:25 +08:00
|
|
|
|
gimp_imagefile_save_thumb (GimpImagefile *imagefile,
|
2006-03-29 01:08:36 +08:00
|
|
|
|
GimpImage *image,
|
2003-12-08 17:12:25 +08:00
|
|
|
|
gint size,
|
2004-10-23 23:30:39 +08:00
|
|
|
|
gboolean replace,
|
2003-12-08 17:12:25 +08:00
|
|
|
|
GError **error)
|
2002-04-19 20:05:47 +08:00
|
|
|
|
{
|
2011-03-02 19:26:04 +08:00
|
|
|
|
GimpImagefilePrivate *private = GET_PRIVATE (imagefile);
|
|
|
|
|
GimpThumbnail *thumbnail = private->thumbnail;
|
|
|
|
|
GdkPixbuf *pixbuf;
|
|
|
|
|
gint width, height;
|
|
|
|
|
gboolean success = FALSE;
|
2002-04-19 20:05:47 +08:00
|
|
|
|
|
2003-12-25 20:10:26 +08:00
|
|
|
|
if (size < 1)
|
|
|
|
|
return TRUE;
|
|
|
|
|
|
2007-12-26 00:21:40 +08:00
|
|
|
|
if (gimp_image_get_width (image) <= size &&
|
|
|
|
|
gimp_image_get_height (image) <= size)
|
2002-04-19 20:05:47 +08:00
|
|
|
|
{
|
2007-12-26 00:21:40 +08:00
|
|
|
|
width = gimp_image_get_width (image);
|
|
|
|
|
height = gimp_image_get_height (image);
|
2002-04-30 04:27:54 +08:00
|
|
|
|
|
2004-11-03 03:36:23 +08:00
|
|
|
|
size = MAX (width, height);
|
2002-04-19 20:05:47 +08:00
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
2007-12-26 00:21:40 +08:00
|
|
|
|
if (gimp_image_get_width (image) < gimp_image_get_height (image))
|
2002-04-19 20:05:47 +08:00
|
|
|
|
{
|
2003-12-08 17:12:25 +08:00
|
|
|
|
height = size;
|
2007-12-26 00:21:40 +08:00
|
|
|
|
width = MAX (1, (size * gimp_image_get_width (image) /
|
|
|
|
|
gimp_image_get_height (image)));
|
2002-04-19 20:05:47 +08:00
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
2003-12-08 17:12:25 +08:00
|
|
|
|
width = size;
|
2007-12-26 00:21:40 +08:00
|
|
|
|
height = MAX (1, (size * gimp_image_get_height (image) /
|
|
|
|
|
gimp_image_get_width (image)));
|
2002-04-19 20:05:47 +08:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2007-08-02 22:54:29 +08:00
|
|
|
|
/* we need the projection constructed NOW, not some time later */
|
2013-09-14 05:29:06 +08:00
|
|
|
|
gimp_pickable_flush (GIMP_PICKABLE (image));
|
2007-08-02 22:54:29 +08:00
|
|
|
|
|
2006-08-30 05:44:51 +08:00
|
|
|
|
pixbuf = gimp_viewable_get_new_pixbuf (GIMP_VIEWABLE (image),
|
|
|
|
|
/* random context, unused */
|
|
|
|
|
gimp_get_user_context (image->gimp),
|
|
|
|
|
width, height);
|
2002-04-19 20:05:47 +08:00
|
|
|
|
|
2003-12-27 06:09:09 +08:00
|
|
|
|
/* when layer previews are disabled, we won't get a pixbuf */
|
|
|
|
|
if (! pixbuf)
|
|
|
|
|
return TRUE;
|
|
|
|
|
|
2004-02-28 00:27:06 +08:00
|
|
|
|
success = gimp_thumbnail_save_thumb (thumbnail,
|
2003-12-08 17:12:25 +08:00
|
|
|
|
pixbuf,
|
2006-12-10 05:49:23 +08:00
|
|
|
|
"GIMP " GIMP_VERSION,
|
2003-12-08 17:12:25 +08:00
|
|
|
|
error);
|
2002-04-19 20:05:47 +08:00
|
|
|
|
|
2003-01-06 06:07:10 +08:00
|
|
|
|
g_object_unref (pixbuf);
|
2002-04-19 20:05:47 +08:00
|
|
|
|
|
2003-12-08 17:12:25 +08:00
|
|
|
|
if (success)
|
2004-10-23 23:30:39 +08:00
|
|
|
|
{
|
|
|
|
|
if (replace)
|
|
|
|
|
gimp_thumbnail_delete_others (thumbnail, size);
|
|
|
|
|
else
|
|
|
|
|
gimp_thumbnail_delete_failure (thumbnail);
|
|
|
|
|
|
|
|
|
|
gimp_imagefile_update (imagefile);
|
|
|
|
|
}
|
2002-04-20 01:15:39 +08:00
|
|
|
|
|
|
|
|
|
return success;
|
2002-04-19 20:05:47 +08:00
|
|
|
|
}
|
2004-11-14 01:06:06 +08:00
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
|
gimp_thumbnail_set_info_from_image (GimpThumbnail *thumbnail,
|
|
|
|
|
const gchar *mime_type,
|
|
|
|
|
GimpImage *image)
|
|
|
|
|
{
|
2012-04-11 23:34:43 +08:00
|
|
|
|
const Babl *format;
|
2004-11-14 01:06:06 +08:00
|
|
|
|
|
|
|
|
|
/* peek the thumbnail to make sure that mtime and filesize are set */
|
|
|
|
|
gimp_thumbnail_peek_image (thumbnail);
|
|
|
|
|
|
2012-04-07 08:50:50 +08:00
|
|
|
|
format = gimp_image_get_layer_format (image,
|
|
|
|
|
gimp_image_has_alpha (image));
|
2004-11-14 01:06:06 +08:00
|
|
|
|
|
|
|
|
|
g_object_set (thumbnail,
|
|
|
|
|
"image-mimetype", mime_type,
|
2007-12-26 00:21:40 +08:00
|
|
|
|
"image-width", gimp_image_get_width (image),
|
2004-11-14 01:06:06 +08:00
|
|
|
|
"image-height", gimp_image_get_height (image),
|
2016-04-16 02:17:26 +08:00
|
|
|
|
"image-type", gimp_babl_format_get_description (format),
|
2009-08-02 18:24:06 +08:00
|
|
|
|
"image-num-layers", gimp_image_get_n_layers (image),
|
2004-11-14 01:06:06 +08:00
|
|
|
|
NULL);
|
|
|
|
|
}
|
|
|
|
|
|
2008-11-10 16:21:36 +08:00
|
|
|
|
/**
|
|
|
|
|
* gimp_thumbnail_set_info:
|
|
|
|
|
* @thumbnail: #GimpThumbnail object
|
|
|
|
|
* @mime_type: MIME type of the image associated with this thumbnail
|
|
|
|
|
* @width: width of the image associated with this thumbnail
|
|
|
|
|
* @height: height of the image associated with this thumbnail
|
2012-04-12 03:54:23 +08:00
|
|
|
|
* @format: format of the image (or NULL if the type is not known)
|
2008-11-10 16:21:36 +08:00
|
|
|
|
* @num_layers: number of layers in the image
|
|
|
|
|
* (or -1 if the number of layers is not known)
|
|
|
|
|
*
|
|
|
|
|
* Set information about the image associated with the @thumbnail object.
|
|
|
|
|
*/
|
2004-11-14 01:06:06 +08:00
|
|
|
|
static void
|
|
|
|
|
gimp_thumbnail_set_info (GimpThumbnail *thumbnail,
|
|
|
|
|
const gchar *mime_type,
|
|
|
|
|
gint width,
|
2008-11-10 16:21:36 +08:00
|
|
|
|
gint height,
|
2012-04-12 03:54:23 +08:00
|
|
|
|
const Babl *format,
|
2008-11-10 16:21:36 +08:00
|
|
|
|
gint num_layers)
|
2004-11-14 01:06:06 +08:00
|
|
|
|
{
|
|
|
|
|
/* peek the thumbnail to make sure that mtime and filesize are set */
|
|
|
|
|
gimp_thumbnail_peek_image (thumbnail);
|
|
|
|
|
|
|
|
|
|
g_object_set (thumbnail,
|
2008-11-10 16:21:36 +08:00
|
|
|
|
"image-mimetype", mime_type,
|
|
|
|
|
"image-width", width,
|
|
|
|
|
"image-height", height,
|
2004-11-14 01:06:06 +08:00
|
|
|
|
NULL);
|
2008-11-10 16:21:36 +08:00
|
|
|
|
|
2012-04-12 03:54:23 +08:00
|
|
|
|
if (format)
|
|
|
|
|
g_object_set (thumbnail,
|
2016-04-16 02:17:26 +08:00
|
|
|
|
"image-type", gimp_babl_format_get_description (format),
|
2012-04-12 03:54:23 +08:00
|
|
|
|
NULL);
|
2008-11-10 16:21:36 +08:00
|
|
|
|
|
|
|
|
|
if (num_layers != -1)
|
2012-04-12 03:54:23 +08:00
|
|
|
|
g_object_set (thumbnail,
|
|
|
|
|
"image-num-layers", num_layers,
|
|
|
|
|
NULL);
|
2004-11-14 01:06:06 +08:00
|
|
|
|
}
|