~ubuntu-branches/ubuntu/jaunty/gimp/jaunty-security

« back to all changes in this revision

Viewing changes to app/core/gimpimagefile.c

  • Committer: Bazaar Package Importer
  • Author(s): Daniel Holbach
  • Date: 2007-05-02 16:33:03 UTC
  • mfrom: (1.1.4 upstream)
  • Revision ID: james.westby@ubuntu.com-20070502163303-bvzhjzbpw8qglc4y
Tags: 2.3.16-1ubuntu1
* Resynchronized with Debian, remaining Ubuntu changes:
  - debian/rules: i18n magic.
* debian/control.in:
  - Maintainer: Ubuntu Core Developers <ubuntu-devel@lists.ubuntu.com>
* debian/patches/02_help-message.patch,
  debian/patches/03_gimp.desktop.in.in.patch,
  debian/patches/10_dont_show_wizard.patch: updated.
* debian/patches/04_composite-signedness.patch,
  debian/patches/05_add-letter-spacing.patch: dropped, used upstream.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/* The GIMP -- an image manipulation program
 
1
/* GIMP - The GNU Image Manipulation Program
2
2
 * Copyright (C) 1995 Spencer Kimball and Peter Mattis
3
3
 *
4
4
 * gimpimagefile.c
55
55
};
56
56
 
57
57
 
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);
 
59
 
61
60
static void        gimp_imagefile_name_changed     (GimpObject     *object);
 
61
 
62
62
static void        gimp_imagefile_info_changed     (GimpImagefile  *imagefile);
63
63
static void        gimp_imagefile_notify_thumbnail (GimpImagefile  *imagefile,
64
64
                                                    GParamSpec     *pspec);
65
65
 
66
66
static GdkPixbuf * gimp_imagefile_get_new_pixbuf   (GimpViewable   *viewable,
 
67
                                                    GimpContext    *context,
67
68
                                                    gint            width,
68
69
                                                    gint            height);
69
70
static GdkPixbuf * gimp_imagefile_load_thumb       (GimpImagefile  *imagefile,
70
71
                                                    gint            width,
71
72
                                                    gint            height);
72
73
static gboolean    gimp_imagefile_save_thumb       (GimpImagefile  *imagefile,
73
 
                                                    GimpImage      *gimage,
 
74
                                                    GimpImage      *image,
74
75
                                                    gint            size,
75
76
                                                    gboolean        replace,
76
77
                                                    GError        **error);
87
88
                                                    gint            height);
88
89
 
89
90
 
 
91
G_DEFINE_TYPE (GimpImagefile, gimp_imagefile, GIMP_TYPE_VIEWABLE)
 
92
 
 
93
#define parent_class gimp_imagefile_parent_class
90
94
 
91
95
static guint gimp_imagefile_signals[LAST_SIGNAL] = { 0 };
92
96
 
93
 
static GimpViewableClass *parent_class = NULL;
94
 
 
95
 
 
96
 
GType
97
 
gimp_imagefile_get_type (void)
98
 
{
99
 
  static GType imagefile_type = 0;
100
 
 
101
 
  if (!imagefile_type)
102
 
    {
103
 
      static const GTypeInfo imagefile_info =
104
 
      {
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),
112
 
        0,              /* n_preallocs    */
113
 
        (GInstanceInitFunc) gimp_imagefile_init,
114
 
      };
115
 
 
116
 
      imagefile_type = g_type_register_static (GIMP_TYPE_VIEWABLE,
117
 
                                               "GimpImagefile",
118
 
                                               &imagefile_info, 0);
119
 
    }
120
 
 
121
 
  return imagefile_type;
122
 
}
123
97
 
124
98
static void
125
99
gimp_imagefile_class_init (GimpImagefileClass *klass)
129
103
  GimpViewableClass *viewable_class    = GIMP_VIEWABLE_CLASS (klass);
130
104
  gchar             *creator;
131
105
 
132
 
  parent_class = g_type_class_peek_parent (klass);
133
 
 
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),
144
116
 
145
117
  gimp_object_class->name_changed     = gimp_imagefile_name_changed;
146
118
 
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;
150
122
 
243
215
                                 gint           size,
244
216
                                 gboolean       replace)
245
217
{
246
 
  GimpThumbnail *thumbnail;
 
218
  GimpThumbnail  *thumbnail;
 
219
  GimpThumbState  image_state;
247
220
 
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)));
262
235
 
263
 
  if (gimp_thumbnail_peek_image (thumbnail) >= GIMP_THUMB_STATE_EXISTS)
 
236
  image_state = gimp_thumbnail_peek_image (thumbnail);
 
237
 
 
238
  if (image_state == GIMP_THUMB_STATE_REMOTE ||
 
239
      image_state >= GIMP_THUMB_STATE_EXISTS)
264
240
    {
265
241
      GimpImage    *image;
266
242
      gboolean      success;
279
255
        {
280
256
          gimp_thumbnail_set_info (imagefile->thumbnail,
281
257
                                   mime_type, width, height);
282
 
 
283
258
        }
284
259
      else
285
260
        {
286
261
          GimpPDBStatusType  status;
287
262
 
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);
292
268
 
293
269
          if (image)
306
282
      else
307
283
        {
308
284
          success = gimp_thumbnail_save_failure (thumbnail,
309
 
                                                 "The GIMP " GIMP_VERSION,
 
285
                                                 "GIMP " GIMP_VERSION,
310
286
                                                 &error);
311
287
          gimp_imagefile_update (imagefile);
312
288
        }
315
291
 
316
292
      if (! success)
317
293
        {
318
 
          g_message (error->message);
319
 
          g_error_free (error);
 
294
          gimp_message (imagefile->gimp, G_OBJECT (progress),
 
295
                        GIMP_MESSAGE_ERROR,
 
296
                        "%s", error->message);
 
297
          g_clear_error (&error);
320
298
        }
321
299
    }
322
300
}
395
373
gboolean
396
374
gimp_imagefile_save_thumbnail (GimpImagefile *imagefile,
397
375
                               const gchar   *mime_type,
398
 
                               GimpImage     *gimage)
 
376
                               GimpImage     *image)
399
377
{
400
378
  gint      size;
401
379
  gboolean  success = TRUE;
402
380
  GError   *error   = NULL;
403
381
 
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);
406
384
 
407
385
  size = imagefile->gimp->config->thumbnail_size;
408
386
 
409
387
  if (size > 0)
410
388
    {
411
389
      gimp_thumbnail_set_info_from_image (imagefile->thumbnail,
412
 
                                          mime_type, gimage);
 
390
                                          mime_type, image);
413
391
 
414
392
      success = gimp_imagefile_save_thumb (imagefile,
415
 
                                           gimage, size, FALSE,
 
393
                                           image, size, FALSE,
416
394
                                           &error);
417
395
      if (! success)
418
396
        {
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);
421
400
        }
422
401
    }
423
402
 
464
443
 
465
444
static GdkPixbuf *
466
445
gimp_imagefile_get_new_pixbuf (GimpViewable *viewable,
 
446
                               GimpContext  *context,
467
447
                               gint          width,
468
448
                               gint          height)
469
449
{
470
450
  GimpImagefile *imagefile = GIMP_IMAGEFILE (viewable);
471
451
  GdkPixbuf     *pixbuf;
 
452
  const gchar   *stock_id  = NULL;
472
453
 
473
454
  if (! GIMP_OBJECT (imagefile)->name)
474
455
    return NULL;
475
456
 
476
457
  pixbuf = gimp_imagefile_load_thumb (imagefile, width, height);
477
458
 
478
 
  if (pixbuf)
479
 
    {
480
 
      gimp_viewable_set_stock_id (GIMP_VIEWABLE (imagefile), NULL);
481
 
    }
482
 
  else if (imagefile->thumbnail->image_state == GIMP_THUMB_STATE_REMOTE)
483
 
    {
484
 
      gimp_viewable_set_stock_id (GIMP_VIEWABLE (imagefile), "gtk-network");
485
 
    }
486
 
  else if (imagefile->thumbnail->image_state == GIMP_THUMB_STATE_FOLDER)
487
 
    {
488
 
      gimp_viewable_set_stock_id (GIMP_VIEWABLE (imagefile), "gtk-open");
489
 
    }
490
 
  else if (imagefile->thumbnail->image_state == GIMP_THUMB_STATE_SPECIAL)
491
 
    {
492
 
      gimp_viewable_set_stock_id (GIMP_VIEWABLE (imagefile), "gtk-harddisk");
493
 
    }
494
 
  else
495
 
    {
496
 
      gimp_viewable_set_stock_id (GIMP_VIEWABLE (imagefile), NULL);
497
 
    }
 
459
  switch (imagefile->thumbnail->image_state)
 
460
    {
 
461
    case GIMP_THUMB_STATE_REMOTE:
 
462
      stock_id = "gtk-network";
 
463
      break;
 
464
 
 
465
    case GIMP_THUMB_STATE_FOLDER:
 
466
      stock_id = "gtk-directory";
 
467
      break;
 
468
 
 
469
    case GIMP_THUMB_STATE_SPECIAL:
 
470
      stock_id = "gtk-harddisk";
 
471
      break;
 
472
 
 
473
    case GIMP_THUMB_STATE_NOT_FOUND:
 
474
      stock_id = "gtk-dialog-question";
 
475
      break;
 
476
 
 
477
    default:
 
478
      break;
 
479
    }
 
480
 
 
481
  gimp_viewable_set_stock_id (GIMP_VIEWABLE (imagefile), stock_id);
498
482
 
499
483
  return pixbuf;
500
484
}
515
499
      gchar       *filename;
516
500
      const gchar *desc;
517
501
 
518
 
      filename = file_utils_uri_to_utf8_filename (thumbnail->image_uri);
 
502
      filename = file_utils_uri_display_name (thumbnail->image_uri);
519
503
      desc     = gimp_imagefile_get_desc_string (imagefile);
520
504
 
521
505
      if (desc)
529
513
        }
530
514
    }
531
515
 
532
 
  basename = file_utils_uri_to_utf8_basename (thumbnail->image_uri);
 
516
  basename = file_utils_uri_display_basename (thumbnail->image_uri);
533
517
 
534
518
  if (thumbnail->image_width > 0 && thumbnail->image_height > 0)
535
519
    {
536
520
      gchar *tmp = basename;
537
521
 
538
 
      basename = g_strdup_printf ("%s (%d x %d)",
 
522
      basename = g_strdup_printf ("%s (%d × %d)",
539
523
                                  tmp,
540
524
                                  thumbnail->image_width,
541
525
                                  thumbnail->image_height);
564
548
      imagefile->static_desc = TRUE;
565
549
      break;
566
550
 
567
 
    case GIMP_THUMB_STATE_REMOTE:
568
 
      imagefile->description = _("Remote image");
569
 
      imagefile->static_desc = TRUE;
570
 
      break;
571
 
 
572
551
    case GIMP_THUMB_STATE_FOLDER:
573
552
      imagefile->description = _("Folder");
574
553
      imagefile->static_desc = TRUE;
589
568
      {
590
569
        GString *str = g_string_new (NULL);
591
570
 
 
571
        if (thumbnail->image_state == GIMP_THUMB_STATE_REMOTE)
 
572
          {
 
573
            g_string_append (str, _("Remote File"));
 
574
            g_string_append_c (str, '\n');
 
575
          }
 
576
 
592
577
        if (thumbnail->image_filesize > 0)
593
578
          {
594
579
            gchar *size = gimp_memsize_to_string (thumbnail->image_filesize);
606
591
            break;
607
592
 
608
593
          case GIMP_THUMB_STATE_EXISTS:
609
 
            g_string_append (str, _("Loading preview ..."));
 
594
            g_string_append (str, _("Loading preview..."));
610
595
            break;
611
596
 
612
597
          case GIMP_THUMB_STATE_OLD:
619
604
 
620
605
          case GIMP_THUMB_STATE_OK:
621
606
            {
 
607
              if (thumbnail->image_state == GIMP_THUMB_STATE_REMOTE)
 
608
                {
 
609
                  g_string_append (str, _("(Preview may be out of date)"));
 
610
                  g_string_append_c (str, '\n');
 
611
                }
 
612
 
622
613
              if (thumbnail->image_width > 0 && thumbnail->image_height > 0)
623
614
                {
624
 
                  g_string_append_printf (str, _("%d x %d pixels"),
 
615
                  g_string_append_printf (str,
 
616
                                          ngettext ("%d × %d pixel",
 
617
                                                    "%d × %d pixels",
 
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);
637
631
 
638
 
                  if (thumbnail->image_num_layers == 1)
639
 
                    g_string_append (str, _("1 Layer"));
640
 
                  else
641
 
                    g_string_append_printf (str, _("%d Layers"),
642
 
                                            thumbnail->image_num_layers);
 
632
                  g_string_append_printf (str,
 
633
                                          ngettext ("%d layer",
 
634
                                                    "%d layers",
 
635
                                                    thumbnail->image_num_layers),
 
636
                                          thumbnail->image_num_layers);
643
637
                }
644
638
            }
645
639
            break;
682
676
    {
683
677
      if (error)
684
678
        {
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);
688
683
        }
689
684
 
690
685
      return NULL;
736
731
 
737
732
static gboolean
738
733
gimp_imagefile_save_thumb (GimpImagefile  *imagefile,
739
 
                           GimpImage      *gimage,
 
734
                           GimpImage      *image,
740
735
                           gint            size,
741
736
                           gboolean        replace,
742
737
                           GError        **error)
749
744
  if (size < 1)
750
745
    return TRUE;
751
746
 
752
 
  if (gimage->width <= size && gimage->height <= size)
 
747
  if (image->width <= size && image->height <= size)
753
748
    {
754
 
      width  = gimage->width;
755
 
      height = gimage->height;
 
749
      width  = image->width;
 
750
      height = image->height;
756
751
 
757
752
      size = MAX (width, height);
758
753
    }
759
754
  else
760
755
    {
761
 
      if (gimage->width < gimage->height)
 
756
      if (image->width < image->height)
762
757
        {
763
758
          height = size;
764
 
          width  = MAX (1, (size * gimage->width) / gimage->height);
 
759
          width  = MAX (1, (size * image->width) / image->height);
765
760
        }
766
761
      else
767
762
        {
768
763
          width  = size;
769
 
          height = MAX (1, (size * gimage->height) / gimage->width);
 
764
          height = MAX (1, (size * image->height) / image->width);
770
765
        }
771
766
    }
772
767
 
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),
 
771
                                         width, height);
774
772
 
775
773
  /*  when layer previews are disabled, we won't get a pixbuf  */
776
774
  if (! pixbuf)
778
776
 
779
777
  success = gimp_thumbnail_save_thumb (thumbnail,
780
778
                                       pixbuf,
781
 
                                       "The GIMP " GIMP_VERSION,
 
779
                                       "GIMP " GIMP_VERSION,
782
780
                                       error);
783
781
 
784
782
  g_object_unref (pixbuf);