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

« back to all changes in this revision

Viewing changes to app/widgets/gimpthumbbox.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
 * This program is free software; you can redistribute it and/or modify
31
31
#include "config/gimpcoreconfig.h"
32
32
 
33
33
#include "core/gimp.h"
 
34
#include "core/gimpcontext.h"
34
35
#include "core/gimpimagefile.h"
35
36
#include "core/gimpprogress.h"
36
37
 
 
38
#include "plug-in/gimppluginmanager.h"
 
39
 
37
40
#include "file/file-utils.h"
38
41
 
39
42
#include "gimpfiledialog.h" /* eek */
47
50
 
48
51
/*  local function prototypes  */
49
52
 
50
 
static void     gimp_thumb_box_class_init (GimpThumbBoxClass *klass);
51
 
static void     gimp_thumb_box_init       (GimpThumbBox      *box);
52
 
static void     gimp_thumb_box_progress_iface_init (GimpProgressInterface *progress_iface);
53
 
 
54
 
static void     gimp_thumb_box_dispose    (GObject           *object);
55
 
static void     gimp_thumb_box_finalize   (GObject           *object);
56
 
 
57
 
static void     gimp_thumb_box_style_set  (GtkWidget         *widget,
58
 
                                           GtkStyle          *prev_style);
 
53
static void     gimp_thumb_box_progress_iface_init (GimpProgressInterface *iface);
 
54
 
 
55
static void     gimp_thumb_box_dispose            (GObject           *object);
 
56
static void     gimp_thumb_box_finalize           (GObject           *object);
 
57
 
 
58
static void     gimp_thumb_box_style_set          (GtkWidget         *widget,
 
59
                                                   GtkStyle          *prev_style);
59
60
 
60
61
static GimpProgress *
61
62
                gimp_thumb_box_progress_start     (GimpProgress      *progress,
66
67
static void     gimp_thumb_box_progress_set_value (GimpProgress      *progress,
67
68
                                                   gdouble            percentage);
68
69
static gdouble  gimp_thumb_box_progress_get_value (GimpProgress      *progress);
 
70
static void     gimp_thumb_box_progress_pulse     (GimpProgress      *progress);
69
71
 
70
 
static void     gimp_thumb_box_progress_message   (GimpProgress      *progress,
 
72
static gboolean gimp_thumb_box_progress_message   (GimpProgress      *progress,
71
73
                                                   Gimp              *gimp,
 
74
                                                   GimpMessageSeverity  severity,
72
75
                                                   const gchar       *domain,
73
76
                                                   const gchar       *message);
74
77
 
92
95
static gboolean gimp_thumb_box_auto_thumbnail     (GimpThumbBox      *box);
93
96
 
94
97
 
95
 
/*  private variables  */
96
 
 
97
 
static GtkFrameClass *parent_class = NULL;
98
 
 
99
 
 
100
 
GType
101
 
gimp_thumb_box_get_type (void)
102
 
{
103
 
  static GType box_type = 0;
104
 
 
105
 
  if (! box_type)
106
 
    {
107
 
      static const GTypeInfo box_info =
108
 
      {
109
 
        sizeof (GimpThumbBoxClass),
110
 
        (GBaseInitFunc)     NULL,
111
 
        (GBaseFinalizeFunc) NULL,
112
 
        (GClassInitFunc)    gimp_thumb_box_class_init,
113
 
        NULL,           /* class_finalize */
114
 
        NULL,           /* class_data     */
115
 
        sizeof (GimpThumbBox),
116
 
        0,              /* n_preallocs    */
117
 
        (GInstanceInitFunc) gimp_thumb_box_init,
118
 
      };
119
 
 
120
 
      static const GInterfaceInfo progress_iface_info =
121
 
      {
122
 
        (GInterfaceInitFunc) gimp_thumb_box_progress_iface_init,
123
 
        NULL,           /* iface_finalize */
124
 
        NULL            /* iface_data     */
125
 
      };
126
 
 
127
 
      box_type = g_type_register_static (GTK_TYPE_FRAME,
128
 
                                         "GimpThumbBox",
129
 
                                         &box_info, 0);
130
 
 
131
 
      g_type_add_interface_static (box_type, GIMP_TYPE_PROGRESS,
132
 
                                   &progress_iface_info);
133
 
    }
134
 
 
135
 
  return box_type;
136
 
}
 
98
G_DEFINE_TYPE_WITH_CODE (GimpThumbBox, gimp_thumb_box, GTK_TYPE_FRAME,
 
99
                         G_IMPLEMENT_INTERFACE (GIMP_TYPE_PROGRESS,
 
100
                                                gimp_thumb_box_progress_iface_init))
 
101
 
 
102
#define parent_class gimp_thumb_box_parent_class
 
103
 
137
104
 
138
105
static void
139
106
gimp_thumb_box_class_init (GimpThumbBoxClass *klass)
141
108
  GObjectClass   *object_class = G_OBJECT_CLASS (klass);
142
109
  GtkWidgetClass *widget_class = GTK_WIDGET_CLASS (klass);
143
110
 
144
 
  parent_class = g_type_class_peek_parent (klass);
145
 
 
146
111
  object_class->dispose   = gimp_thumb_box_dispose;
147
112
  object_class->finalize  = gimp_thumb_box_finalize;
148
113
 
158
123
}
159
124
 
160
125
static void
161
 
gimp_thumb_box_progress_iface_init (GimpProgressInterface *progress_iface)
 
126
gimp_thumb_box_progress_iface_init (GimpProgressInterface *iface)
162
127
{
163
 
  progress_iface->start     = gimp_thumb_box_progress_start;
164
 
  progress_iface->end       = gimp_thumb_box_progress_end;
165
 
  progress_iface->is_active = gimp_thumb_box_progress_is_active;
166
 
  progress_iface->set_value = gimp_thumb_box_progress_set_value;
167
 
  progress_iface->get_value = gimp_thumb_box_progress_get_value;
168
 
 
169
 
  progress_iface->message   = gimp_thumb_box_progress_message;
 
128
  iface->start     = gimp_thumb_box_progress_start;
 
129
  iface->end       = gimp_thumb_box_progress_end;
 
130
  iface->is_active = gimp_thumb_box_progress_is_active;
 
131
  iface->set_value = gimp_thumb_box_progress_set_value;
 
132
  iface->get_value = gimp_thumb_box_progress_get_value;
 
133
  iface->pulse     = gimp_thumb_box_progress_pulse;
 
134
  iface->message   = gimp_thumb_box_progress_message;
170
135
}
171
136
 
172
137
static void
295
260
}
296
261
 
297
262
static void
298
 
gimp_thumb_box_progress_message (GimpProgress      *progress,
299
 
                                 Gimp              *gimp,
300
 
                                 const gchar       *domain,
301
 
                                 const gchar       *message)
 
263
gimp_thumb_box_progress_pulse (GimpProgress *progress)
 
264
{
 
265
  GimpThumbBox *box = GIMP_THUMB_BOX (progress);
 
266
 
 
267
  if (box->progress_active)
 
268
    {
 
269
      GtkProgressBar *bar = GTK_PROGRESS_BAR (box->progress);
 
270
 
 
271
      gtk_progress_bar_pulse (bar);
 
272
    }
 
273
}
 
274
 
 
275
static gboolean
 
276
gimp_thumb_box_progress_message (GimpProgress        *progress,
 
277
                                 Gimp                *gimp,
 
278
                                 GimpMessageSeverity  severity,
 
279
                                 const gchar         *domain,
 
280
                                 const gchar         *message)
302
281
{
303
282
  /*  GimpThumbBox never shows any messages  */
 
283
 
 
284
  return TRUE;
304
285
}
305
286
 
306
287
 
307
288
/*  public functions  */
308
289
 
309
290
GtkWidget *
310
 
gimp_thumb_box_new (Gimp *gimp)
 
291
gimp_thumb_box_new (GimpContext *context)
311
292
{
312
293
  GimpThumbBox   *box;
313
294
  GtkWidget      *vbox;
322
303
  GtkRequisition  thumb_progress_requisition;
323
304
  GtkRequisition  progress_requisition;
324
305
 
325
 
  g_return_val_if_fail (GIMP_IS_GIMP (gimp), NULL);
 
306
  g_return_val_if_fail (GIMP_IS_CONTEXT (context), NULL);
326
307
 
327
308
  box = g_object_new (GIMP_TYPE_THUMB_BOX, NULL);
328
309
 
 
310
  box->context = context;
 
311
 
329
312
  ebox = gtk_event_box_new ();
330
313
  gtk_container_add (GTK_CONTAINER (box), ebox);
331
314
  gtk_widget_show (ebox);
332
315
 
333
 
  g_signal_connect (ebox, "button_press_event",
 
316
  g_signal_connect (ebox, "button-press-event",
334
317
                    G_CALLBACK (gimp_thumb_box_ebox_button_press),
335
318
                    box);
336
319
 
337
320
  str = g_strdup_printf (_("Click to update preview\n"
338
 
                           "%s  Click to force update even "
 
321
                           "%s%sClick to force update even "
339
322
                           "if preview is up-to-date"),
340
 
                         gimp_get_mod_string (GDK_CONTROL_MASK));
 
323
                         gimp_get_mod_string (GDK_CONTROL_MASK),
 
324
                         gimp_get_mod_separator ());
341
325
 
342
326
  gimp_help_set_help_data (ebox, str, NULL);
343
327
 
351
335
  gtk_box_pack_start (GTK_BOX (vbox), button, FALSE, FALSE, 0);
352
336
  gtk_widget_show (button);
353
337
 
354
 
  label = gtk_label_new_with_mnemonic (_("_Preview"));
 
338
  label = gtk_label_new_with_mnemonic (_("Pr_eview"));
355
339
  gtk_misc_set_alignment (GTK_MISC (label), 0.0, 0.5);
356
340
  gtk_container_add (GTK_CONTAINER (button), label);
357
341
  gtk_widget_show (label);
358
342
 
359
 
  g_signal_connect (button, "button_press_event",
360
 
                    G_CALLBACK (gtk_true),
361
 
                    NULL);
362
 
  g_signal_connect (button, "button_release_event",
363
 
                    G_CALLBACK (gtk_true),
364
 
                    NULL);
365
 
  g_signal_connect (button, "enter_notify_event",
366
 
                    G_CALLBACK (gtk_true),
367
 
                    NULL);
368
 
  g_signal_connect (button, "leave_notify_event",
 
343
  g_signal_connect (button, "button-press-event",
 
344
                    G_CALLBACK (gtk_true),
 
345
                    NULL);
 
346
  g_signal_connect (button, "button-release-event",
 
347
                    G_CALLBACK (gtk_true),
 
348
                    NULL);
 
349
  g_signal_connect (button, "enter-notify-event",
 
350
                    G_CALLBACK (gtk_true),
 
351
                    NULL);
 
352
  g_signal_connect (button, "leave-notify-event",
369
353
                    G_CALLBACK (gtk_true),
370
354
                    NULL);
371
355
 
372
 
  vbox2 = gtk_vbox_new (FALSE, 2);
 
356
  vbox2 = gtk_vbox_new (FALSE, 6);
373
357
  gtk_container_set_border_width (GTK_CONTAINER (vbox2), 2);
374
358
  gtk_container_add (GTK_CONTAINER (vbox), vbox2);
375
359
  gtk_widget_show (vbox2);
378
362
  gtk_box_pack_start (GTK_BOX (vbox2), hbox, FALSE, FALSE, 0);
379
363
  gtk_widget_show (hbox);
380
364
 
381
 
  box->imagefile = gimp_imagefile_new (gimp, NULL);
 
365
  box->imagefile = gimp_imagefile_new (context->gimp, NULL);
382
366
 
383
 
  g_signal_connect (box->imagefile, "info_changed",
 
367
  g_signal_connect (box->imagefile, "info-changed",
384
368
                    G_CALLBACK (gimp_thumb_box_imagefile_info_changed),
385
369
                    box);
386
370
 
390
374
 
391
375
  gimp_view_renderer_get_frame_size (&h, &v);
392
376
 
393
 
  box->preview = gimp_view_new (GIMP_VIEWABLE (box->imagefile),
 
377
  box->preview = gimp_view_new (context,
 
378
                                GIMP_VIEWABLE (box->imagefile),
394
379
                                /* add padding for the shadow frame */
395
 
                                gimp->config->thumbnail_size + MAX (h, v),
 
380
                                context->gimp->config->thumbnail_size +
 
381
                                MAX (h, v),
396
382
                                0, FALSE);
397
383
 
398
 
  gtk_box_pack_start (GTK_BOX (hbox), box->preview, TRUE, FALSE, 10);
 
384
  gtk_box_pack_start (GTK_BOX (hbox), box->preview, TRUE, FALSE, 2);
399
385
  gtk_widget_show (box->preview);
400
386
 
401
387
  gtk_label_set_mnemonic_widget (GTK_LABEL (label), box->preview);
405
391
                    box);
406
392
 
407
393
  box->filename = gtk_label_new (_("No selection"));
408
 
  gtk_label_set_line_wrap (GTK_LABEL (box->filename), TRUE);
 
394
  gtk_label_set_ellipsize (GTK_LABEL (box->filename), PANGO_ELLIPSIZE_MIDDLE);
409
395
  gtk_label_set_justify (GTK_LABEL (box->filename), GTK_JUSTIFY_CENTER);
 
396
  gimp_label_set_attributes (GTK_LABEL (box->filename),
 
397
                             PANGO_ATTR_STYLE, PANGO_STYLE_OBLIQUE,
 
398
                             -1);
410
399
  gtk_box_pack_start (GTK_BOX (vbox2), box->filename, FALSE, FALSE, 0);
411
400
  gtk_widget_show (box->filename);
412
401
 
413
402
  box->info = gtk_label_new (" \n \n \n ");
414
403
  gtk_misc_set_alignment (GTK_MISC (box->info), 0.5, 0.0);
415
404
  gtk_label_set_justify (GTK_LABEL (box->info), GTK_JUSTIFY_CENTER);
 
405
  gimp_label_set_attributes (GTK_LABEL (box->info),
 
406
                             PANGO_ATTR_SCALE, PANGO_SCALE_SMALL,
 
407
                             -1);
416
408
  gtk_box_pack_start (GTK_BOX (vbox2), box->info, FALSE, FALSE, 0);
417
409
  gtk_widget_show (box->info);
418
410
 
451
443
}
452
444
 
453
445
void
454
 
gimp_thumb_box_set_uri (GimpThumbBox *box,
455
 
                        const gchar  *uri)
 
446
gimp_thumb_box_take_uri (GimpThumbBox *box,
 
447
                         gchar        *uri)
456
448
{
457
449
  g_return_if_fail (GIMP_IS_THUMB_BOX (box));
458
450
 
462
454
      box->idle_id = 0;
463
455
    }
464
456
 
465
 
  gimp_object_set_name (GIMP_OBJECT (box->imagefile), uri);
 
457
  gimp_object_take_name (GIMP_OBJECT (box->imagefile), uri);
466
458
 
467
459
  if (uri)
468
460
    {
469
 
      gchar *basename;
 
461
      gchar *basename = file_utils_uri_display_basename (uri);
470
462
 
471
 
      basename = file_utils_uri_to_utf8_basename (uri);
472
463
      gtk_label_set_text (GTK_LABEL (box->filename), basename);
473
464
      g_free (basename);
474
465
    }
535
526
  if (box->idle_id)
536
527
    return;
537
528
 
 
529
  if (thumb->image_state == GIMP_THUMB_STATE_REMOTE)
 
530
    return;
 
531
 
538
532
  switch (thumb->thumb_state)
539
533
    {
540
534
    case GIMP_THUMB_STATE_NOT_FOUND:
673
667
                                 GimpThumbnailSize  size,
674
668
                                 gboolean           force)
675
669
{
676
 
  gchar *filename = file_utils_filename_from_uri (uri);
677
 
 
678
 
  if (filename && g_file_test (filename, G_FILE_TEST_IS_REGULAR))
679
 
    {
680
 
      GimpThumbnail *thumb = box->imagefile->thumbnail;
681
 
      gchar         *basename;
682
 
 
683
 
      basename = file_utils_uri_to_utf8_basename (uri);
684
 
      gtk_label_set_text (GTK_LABEL (box->filename), basename);
685
 
      g_free (basename);
686
 
 
687
 
      gimp_object_set_name (GIMP_OBJECT (box->imagefile), uri);
688
 
 
689
 
      if (force ||
690
 
          (gimp_thumbnail_peek_thumb (thumb, size) < GIMP_THUMB_STATE_FAILED &&
691
 
           ! gimp_thumbnail_has_failed (thumb)))
692
 
        {
693
 
          Gimp *gimp = box->imagefile->gimp;
694
 
 
695
 
          gimp_imagefile_create_thumbnail (box->imagefile,
696
 
                                           gimp_get_user_context (gimp),
697
 
                                           GIMP_PROGRESS (box),
698
 
                                           size,
699
 
                                           !force);
700
 
        }
701
 
    }
702
 
 
703
 
  g_free (filename);
 
670
  gchar         *filename = file_utils_filename_from_uri (uri);
 
671
  GimpThumbnail *thumb;
 
672
  gchar         *basename;
 
673
 
 
674
  if (filename)
 
675
    {
 
676
      gboolean regular = g_file_test (filename, G_FILE_TEST_IS_REGULAR);
 
677
 
 
678
      g_free (filename);
 
679
 
 
680
      if (! regular)
 
681
        return;
 
682
    }
 
683
 
 
684
  thumb = box->imagefile->thumbnail;
 
685
 
 
686
  basename = file_utils_uri_display_basename (uri);
 
687
  gtk_label_set_text (GTK_LABEL (box->filename), basename);
 
688
  g_free (basename);
 
689
 
 
690
  gimp_object_set_name (GIMP_OBJECT (box->imagefile), uri);
 
691
 
 
692
  if (force ||
 
693
      (gimp_thumbnail_peek_thumb (thumb, size) < GIMP_THUMB_STATE_FAILED &&
 
694
       ! gimp_thumbnail_has_failed (thumb)))
 
695
    {
 
696
      gimp_imagefile_create_thumbnail (box->imagefile, box->context,
 
697
                                       GIMP_PROGRESS (box),
 
698
                                       size,
 
699
                                       !force);
 
700
    }
704
701
}
705
702
 
706
703
static gboolean
721
718
    case GIMP_THUMB_STATE_OLD:
722
719
      if (thumb->image_filesize < gimp->config->thumbnail_filesize_limit &&
723
720
          ! gimp_thumbnail_has_failed (thumb)                            &&
724
 
          file_utils_find_proc_by_extension (gimp->load_procs, uri))
 
721
          file_utils_find_proc_by_extension (gimp->plug_in_manager->load_procs,
 
722
                                             uri))
725
723
        {
726
724
          if (thumb->image_filesize > 0)
727
725
            {
730
728
 
731
729
              size = gimp_memsize_to_string (thumb->image_filesize);
732
730
              text = g_strdup_printf ("%s\n%s",
733
 
                                      size, _("Creating Preview ..."));
 
731
                                      size, _("Creating preview..."));
734
732
 
735
733
              gtk_label_set_text (GTK_LABEL (box->info), text);
736
734
 
740
738
          else
741
739
            {
742
740
              gtk_label_set_text (GTK_LABEL (box->info),
743
 
                                  _("Creating Preview ..."));
 
741
                                  _("Creating preview..."));
744
742
            }
745
743
 
746
 
          gimp_imagefile_create_thumbnail_weak (box->imagefile,
747
 
                                                gimp_get_user_context (gimp),
 
744
          gimp_imagefile_create_thumbnail_weak (box->imagefile, box->context,
748
745
                                                GIMP_PROGRESS (box),
749
746
                                                gimp->config->thumbnail_size,
750
747
                                                TRUE);