58
static void gimp_imagefile_class_init (GimpImagefileClass *klass);
59
static void gimp_imagefile_init (GimpImagefile *imagefile);
60
58
static void gimp_imagefile_finalize (GObject *object);
61
60
static void gimp_imagefile_name_changed (GimpObject *object);
62
62
static void gimp_imagefile_info_changed (GimpImagefile *imagefile);
63
63
static void gimp_imagefile_notify_thumbnail (GimpImagefile *imagefile,
64
64
GParamSpec *pspec);
66
66
static GdkPixbuf * gimp_imagefile_get_new_pixbuf (GimpViewable *viewable,
69
70
static GdkPixbuf * gimp_imagefile_load_thumb (GimpImagefile *imagefile,
72
73
static gboolean gimp_imagefile_save_thumb (GimpImagefile *imagefile,
91
G_DEFINE_TYPE (GimpImagefile, gimp_imagefile, GIMP_TYPE_VIEWABLE)
93
#define parent_class gimp_imagefile_parent_class
91
95
static guint gimp_imagefile_signals[LAST_SIGNAL] = { 0 };
93
static GimpViewableClass *parent_class = NULL;
97
gimp_imagefile_get_type (void)
99
static GType imagefile_type = 0;
103
static const GTypeInfo imagefile_info =
105
sizeof (GimpImagefileClass),
106
(GBaseInitFunc) NULL,
107
(GBaseFinalizeFunc) NULL,
108
(GClassInitFunc) gimp_imagefile_class_init,
109
NULL, /* class_finalize */
110
NULL, /* class_data */
111
sizeof (GimpImagefile),
113
(GInstanceInitFunc) gimp_imagefile_init,
116
imagefile_type = g_type_register_static (GIMP_TYPE_VIEWABLE,
121
return imagefile_type;
125
99
gimp_imagefile_class_init (GimpImagefileClass *klass)
129
103
GimpViewableClass *viewable_class = GIMP_VIEWABLE_CLASS (klass);
132
parent_class = g_type_class_peek_parent (klass);
134
106
gimp_imagefile_signals[INFO_CHANGED] =
135
g_signal_new ("info_changed",
107
g_signal_new ("info-changed",
136
108
G_TYPE_FROM_CLASS (klass),
137
109
G_SIGNAL_RUN_FIRST,
138
110
G_STRUCT_OFFSET (GimpImagefileClass, info_changed),
145
117
gimp_object_class->name_changed = gimp_imagefile_name_changed;
147
viewable_class->name_changed_signal = "info_changed";
119
viewable_class->name_changed_signal = "info-changed";
148
120
viewable_class->get_new_pixbuf = gimp_imagefile_get_new_pixbuf;
149
121
viewable_class->get_description = gimp_imagefile_get_description;
244
216
gboolean replace)
246
GimpThumbnail *thumbnail;
218
GimpThumbnail *thumbnail;
219
GimpThumbState image_state;
248
221
g_return_if_fail (GIMP_IS_IMAGEFILE (imagefile));
249
222
g_return_if_fail (GIMP_IS_CONTEXT (context));
260
233
gimp_thumbnail_set_uri (thumbnail,
261
234
gimp_object_get_name (GIMP_OBJECT (imagefile)));
263
if (gimp_thumbnail_peek_image (thumbnail) >= GIMP_THUMB_STATE_EXISTS)
236
image_state = gimp_thumbnail_peek_image (thumbnail);
238
if (image_state == GIMP_THUMB_STATE_REMOTE ||
239
image_state >= GIMP_THUMB_STATE_EXISTS)
265
241
GimpImage *image;
266
242
gboolean success;
280
256
gimp_thumbnail_set_info (imagefile->thumbnail,
281
257
mime_type, width, height);
286
261
GimpPDBStatusType status;
288
263
image = file_open_image (imagefile->gimp, context, progress,
289
thumbnail->image_uri, thumbnail->image_uri,
290
NULL, GIMP_RUN_NONINTERACTIVE,
264
thumbnail->image_uri,
265
thumbnail->image_uri,
266
FALSE, NULL, GIMP_RUN_NONINTERACTIVE,
291
267
&status, &mime_type, NULL);
396
374
gimp_imagefile_save_thumbnail (GimpImagefile *imagefile,
397
375
const gchar *mime_type,
401
379
gboolean success = TRUE;
402
380
GError *error = NULL;
404
382
g_return_val_if_fail (GIMP_IS_IMAGEFILE (imagefile), FALSE);
405
g_return_val_if_fail (GIMP_IS_IMAGE (gimage), FALSE);
383
g_return_val_if_fail (GIMP_IS_IMAGE (image), FALSE);
407
385
size = imagefile->gimp->config->thumbnail_size;
411
389
gimp_thumbnail_set_info_from_image (imagefile->thumbnail,
414
392
success = gimp_imagefile_save_thumb (imagefile,
419
g_message (error->message);
420
g_error_free (error);
397
gimp_message (imagefile->gimp, NULL, GIMP_MESSAGE_ERROR,
398
"%s", error->message);
399
g_clear_error (&error);
465
444
static GdkPixbuf *
466
445
gimp_imagefile_get_new_pixbuf (GimpViewable *viewable,
446
GimpContext *context,
470
450
GimpImagefile *imagefile = GIMP_IMAGEFILE (viewable);
471
451
GdkPixbuf *pixbuf;
452
const gchar *stock_id = NULL;
473
454
if (! GIMP_OBJECT (imagefile)->name)
476
457
pixbuf = gimp_imagefile_load_thumb (imagefile, width, height);
480
gimp_viewable_set_stock_id (GIMP_VIEWABLE (imagefile), NULL);
482
else if (imagefile->thumbnail->image_state == GIMP_THUMB_STATE_REMOTE)
484
gimp_viewable_set_stock_id (GIMP_VIEWABLE (imagefile), "gtk-network");
486
else if (imagefile->thumbnail->image_state == GIMP_THUMB_STATE_FOLDER)
488
gimp_viewable_set_stock_id (GIMP_VIEWABLE (imagefile), "gtk-open");
490
else if (imagefile->thumbnail->image_state == GIMP_THUMB_STATE_SPECIAL)
492
gimp_viewable_set_stock_id (GIMP_VIEWABLE (imagefile), "gtk-harddisk");
496
gimp_viewable_set_stock_id (GIMP_VIEWABLE (imagefile), NULL);
459
switch (imagefile->thumbnail->image_state)
461
case GIMP_THUMB_STATE_REMOTE:
462
stock_id = "gtk-network";
465
case GIMP_THUMB_STATE_FOLDER:
466
stock_id = "gtk-directory";
469
case GIMP_THUMB_STATE_SPECIAL:
470
stock_id = "gtk-harddisk";
473
case GIMP_THUMB_STATE_NOT_FOUND:
474
stock_id = "gtk-dialog-question";
481
gimp_viewable_set_stock_id (GIMP_VIEWABLE (imagefile), stock_id);
532
basename = file_utils_uri_to_utf8_basename (thumbnail->image_uri);
516
basename = file_utils_uri_display_basename (thumbnail->image_uri);
534
518
if (thumbnail->image_width > 0 && thumbnail->image_height > 0)
536
520
gchar *tmp = basename;
538
basename = g_strdup_printf ("%s (%d x %d)",
522
basename = g_strdup_printf ("%s (%d × %d)",
540
524
thumbnail->image_width,
541
525
thumbnail->image_height);
564
548
imagefile->static_desc = TRUE;
567
case GIMP_THUMB_STATE_REMOTE:
568
imagefile->description = _("Remote image");
569
imagefile->static_desc = TRUE;
572
551
case GIMP_THUMB_STATE_FOLDER:
573
552
imagefile->description = _("Folder");
574
553
imagefile->static_desc = TRUE;
590
569
GString *str = g_string_new (NULL);
571
if (thumbnail->image_state == GIMP_THUMB_STATE_REMOTE)
573
g_string_append (str, _("Remote File"));
574
g_string_append_c (str, '\n');
592
577
if (thumbnail->image_filesize > 0)
594
579
gchar *size = gimp_memsize_to_string (thumbnail->image_filesize);
608
593
case GIMP_THUMB_STATE_EXISTS:
609
g_string_append (str, _("Loading preview ..."));
594
g_string_append (str, _("Loading preview..."));
612
597
case GIMP_THUMB_STATE_OLD:
620
605
case GIMP_THUMB_STATE_OK:
607
if (thumbnail->image_state == GIMP_THUMB_STATE_REMOTE)
609
g_string_append (str, _("(Preview may be out of date)"));
610
g_string_append_c (str, '\n');
622
613
if (thumbnail->image_width > 0 && thumbnail->image_height > 0)
624
g_string_append_printf (str, _("%d x %d pixels"),
615
g_string_append_printf (str,
616
ngettext ("%d × %d pixel",
618
thumbnail->image_height),
625
619
thumbnail->image_width,
626
620
thumbnail->image_height);
627
621
g_string_append_c (str, '\n');
635
629
if (thumbnail->image_type)
636
630
g_string_append_len (str, ", ", 2);
638
if (thumbnail->image_num_layers == 1)
639
g_string_append (str, _("1 Layer"));
641
g_string_append_printf (str, _("%d Layers"),
642
thumbnail->image_num_layers);
632
g_string_append_printf (str,
633
ngettext ("%d layer",
635
thumbnail->image_num_layers),
636
thumbnail->image_num_layers);
685
g_message (_("Could not open thumbnail '%s': %s"),
686
thumbnail->thumb_filename, error->message);
687
g_error_free (error);
679
gimp_message (imagefile->gimp, NULL, GIMP_MESSAGE_ERROR,
680
_("Could not open thumbnail '%s': %s"),
681
thumbnail->thumb_filename, error->message);
682
g_clear_error (&error);
752
if (gimage->width <= size && gimage->height <= size)
747
if (image->width <= size && image->height <= size)
754
width = gimage->width;
755
height = gimage->height;
749
width = image->width;
750
height = image->height;
757
752
size = MAX (width, height);
761
if (gimage->width < gimage->height)
756
if (image->width < image->height)
764
width = MAX (1, (size * gimage->width) / gimage->height);
759
width = MAX (1, (size * image->width) / image->height);
769
height = MAX (1, (size * gimage->height) / gimage->width);
764
height = MAX (1, (size * image->height) / image->width);
773
pixbuf = gimp_viewable_get_new_pixbuf (GIMP_VIEWABLE (gimage), width, height);
768
pixbuf = gimp_viewable_get_new_pixbuf (GIMP_VIEWABLE (image),
769
/* random context, unused */
770
gimp_get_user_context (image->gimp),
775
773
/* when layer previews are disabled, we won't get a pixbuf */