1
/* The GIMP -- an image manipulation program
1
/* GIMP - The GNU Image Manipulation Program
2
2
* Copyright (C) 1995 Spencer Kimball and Peter Mattis
4
4
* This program is free software; you can redistribute it and/or modify
31
31
#include "config/gimpcoreconfig.h"
33
33
#include "core/gimp.h"
34
#include "core/gimpcontext.h"
34
35
#include "core/gimpimagefile.h"
35
36
#include "core/gimpprogress.h"
38
#include "plug-in/gimppluginmanager.h"
37
40
#include "file/file-utils.h"
39
42
#include "gimpfiledialog.h" /* eek */
48
51
/* local function prototypes */
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);
54
static void gimp_thumb_box_dispose (GObject *object);
55
static void gimp_thumb_box_finalize (GObject *object);
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);
55
static void gimp_thumb_box_dispose (GObject *object);
56
static void gimp_thumb_box_finalize (GObject *object);
58
static void gimp_thumb_box_style_set (GtkWidget *widget,
59
GtkStyle *prev_style);
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);
70
static void gimp_thumb_box_progress_message (GimpProgress *progress,
72
static gboolean gimp_thumb_box_progress_message (GimpProgress *progress,
74
GimpMessageSeverity severity,
72
75
const gchar *domain,
73
76
const gchar *message);
92
95
static gboolean gimp_thumb_box_auto_thumbnail (GimpThumbBox *box);
95
/* private variables */
97
static GtkFrameClass *parent_class = NULL;
101
gimp_thumb_box_get_type (void)
103
static GType box_type = 0;
107
static const GTypeInfo box_info =
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),
117
(GInstanceInitFunc) gimp_thumb_box_init,
120
static const GInterfaceInfo progress_iface_info =
122
(GInterfaceInitFunc) gimp_thumb_box_progress_iface_init,
123
NULL, /* iface_finalize */
124
NULL /* iface_data */
127
box_type = g_type_register_static (GTK_TYPE_FRAME,
131
g_type_add_interface_static (box_type, GIMP_TYPE_PROGRESS,
132
&progress_iface_info);
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))
102
#define parent_class gimp_thumb_box_parent_class
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);
144
parent_class = g_type_class_peek_parent (klass);
146
111
object_class->dispose = gimp_thumb_box_dispose;
147
112
object_class->finalize = gimp_thumb_box_finalize;
161
gimp_thumb_box_progress_iface_init (GimpProgressInterface *progress_iface)
126
gimp_thumb_box_progress_iface_init (GimpProgressInterface *iface)
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;
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;
298
gimp_thumb_box_progress_message (GimpProgress *progress,
301
const gchar *message)
263
gimp_thumb_box_progress_pulse (GimpProgress *progress)
265
GimpThumbBox *box = GIMP_THUMB_BOX (progress);
267
if (box->progress_active)
269
GtkProgressBar *bar = GTK_PROGRESS_BAR (box->progress);
271
gtk_progress_bar_pulse (bar);
276
gimp_thumb_box_progress_message (GimpProgress *progress,
278
GimpMessageSeverity severity,
280
const gchar *message)
303
282
/* GimpThumbBox never shows any messages */
307
288
/* public functions */
310
gimp_thumb_box_new (Gimp *gimp)
291
gimp_thumb_box_new (GimpContext *context)
312
293
GimpThumbBox *box;
322
303
GtkRequisition thumb_progress_requisition;
323
304
GtkRequisition progress_requisition;
325
g_return_val_if_fail (GIMP_IS_GIMP (gimp), NULL);
306
g_return_val_if_fail (GIMP_IS_CONTEXT (context), NULL);
327
308
box = g_object_new (GIMP_TYPE_THUMB_BOX, NULL);
310
box->context = context;
329
312
ebox = gtk_event_box_new ();
330
313
gtk_container_add (GTK_CONTAINER (box), ebox);
331
314
gtk_widget_show (ebox);
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),
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 ());
342
326
gimp_help_set_help_data (ebox, str, NULL);
351
335
gtk_box_pack_start (GTK_BOX (vbox), button, FALSE, FALSE, 0);
352
336
gtk_widget_show (button);
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);
359
g_signal_connect (button, "button_press_event",
360
G_CALLBACK (gtk_true),
362
g_signal_connect (button, "button_release_event",
363
G_CALLBACK (gtk_true),
365
g_signal_connect (button, "enter_notify_event",
366
G_CALLBACK (gtk_true),
368
g_signal_connect (button, "leave_notify_event",
343
g_signal_connect (button, "button-press-event",
344
G_CALLBACK (gtk_true),
346
g_signal_connect (button, "button-release-event",
347
G_CALLBACK (gtk_true),
349
g_signal_connect (button, "enter-notify-event",
350
G_CALLBACK (gtk_true),
352
g_signal_connect (button, "leave-notify-event",
369
353
G_CALLBACK (gtk_true),
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);
381
box->imagefile = gimp_imagefile_new (gimp, NULL);
365
box->imagefile = gimp_imagefile_new (context->gimp, NULL);
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),
391
375
gimp_view_renderer_get_frame_size (&h, &v);
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 +
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);
401
387
gtk_label_set_mnemonic_widget (GTK_LABEL (label), box->preview);
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,
410
399
gtk_box_pack_start (GTK_BOX (vbox2), box->filename, FALSE, FALSE, 0);
411
400
gtk_widget_show (box->filename);
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,
416
408
gtk_box_pack_start (GTK_BOX (vbox2), box->info, FALSE, FALSE, 0);
417
409
gtk_widget_show (box->info);
462
454
box->idle_id = 0;
465
gimp_object_set_name (GIMP_OBJECT (box->imagefile), uri);
457
gimp_object_take_name (GIMP_OBJECT (box->imagefile), uri);
461
gchar *basename = file_utils_uri_display_basename (uri);
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);
673
667
GimpThumbnailSize size,
676
gchar *filename = file_utils_filename_from_uri (uri);
678
if (filename && g_file_test (filename, G_FILE_TEST_IS_REGULAR))
680
GimpThumbnail *thumb = box->imagefile->thumbnail;
683
basename = file_utils_uri_to_utf8_basename (uri);
684
gtk_label_set_text (GTK_LABEL (box->filename), basename);
687
gimp_object_set_name (GIMP_OBJECT (box->imagefile), uri);
690
(gimp_thumbnail_peek_thumb (thumb, size) < GIMP_THUMB_STATE_FAILED &&
691
! gimp_thumbnail_has_failed (thumb)))
693
Gimp *gimp = box->imagefile->gimp;
695
gimp_imagefile_create_thumbnail (box->imagefile,
696
gimp_get_user_context (gimp),
670
gchar *filename = file_utils_filename_from_uri (uri);
671
GimpThumbnail *thumb;
676
gboolean regular = g_file_test (filename, G_FILE_TEST_IS_REGULAR);
684
thumb = box->imagefile->thumbnail;
686
basename = file_utils_uri_display_basename (uri);
687
gtk_label_set_text (GTK_LABEL (box->filename), basename);
690
gimp_object_set_name (GIMP_OBJECT (box->imagefile), uri);
693
(gimp_thumbnail_peek_thumb (thumb, size) < GIMP_THUMB_STATE_FAILED &&
694
! gimp_thumbnail_has_failed (thumb)))
696
gimp_imagefile_create_thumbnail (box->imagefile, box->context,
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,
726
724
if (thumb->image_filesize > 0)
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..."));
735
733
gtk_label_set_text (GTK_LABEL (box->info), text);
742
740
gtk_label_set_text (GTK_LABEL (box->info),
743
_("Creating Preview ..."));
741
_("Creating preview..."));
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,