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

« back to all changes in this revision

Viewing changes to app/gui/splash.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
23
23
#include <gtk/gtk.h>
24
24
 
25
25
#include "libgimpbase/gimpbase.h"
 
26
#include "libgimpmath/gimpmath.h"
26
27
#include "libgimpcolor/gimpcolor.h"
27
28
 
28
29
#include "gui-types.h"
32
33
#include "gimp-intl.h"
33
34
 
34
35
 
 
36
/*  #define STARTUP_TIMER 1  */
 
37
 
 
38
 
35
39
typedef struct
36
40
{
37
41
  GtkWidget      *window;
39
43
  gint            width;
40
44
  gint            height;
41
45
  GtkWidget      *progress;
42
 
  GdkPixmap      *pixmap;
43
46
  GdkGC          *gc;
44
47
  PangoLayout    *upper;
45
48
  gint            upper_x, upper_y;
46
49
  PangoLayout    *lower;
47
50
  gint            lower_x, lower_y;
 
51
#ifdef STARTUP_TIMER
 
52
  GTimer         *timer;
 
53
  gdouble         last_time;
 
54
  gchar          *text1;
 
55
  gchar          *text2;
 
56
#endif
48
57
} GimpSplash;
49
58
 
50
59
static GimpSplash *splash = NULL;
51
60
 
52
61
 
53
 
static void        splash_map             (void);
54
 
static gboolean    splash_area_expose     (GtkWidget      *widget,
55
 
                                           GdkEventExpose *event,
56
 
                                           GimpSplash     *splash);
57
 
static GdkPixbuf * splash_pick_from_dir   (const gchar    *dirname);
58
 
static void        splash_rectangle_union (GdkRectangle   *dest,
59
 
                                           PangoRectangle *pango_rect,
60
 
                                           gint            offset_x,
61
 
                                           gint            offset_y);
62
 
static gboolean    splash_average_bottom  (GtkWidget      *widget,
63
 
                                           GdkPixbuf      *pixbuf,
64
 
                                           GdkColor       *color);
 
62
static void        splash_map                 (void);
 
63
static void        splash_position_layouts    (GimpSplash     *splash,
 
64
                                               const gchar    *text1,
 
65
                                               const gchar    *text2,
 
66
                                               GdkRectangle   *area);
 
67
static gboolean    splash_area_expose         (GtkWidget      *widget,
 
68
                                               GdkEventExpose *event,
 
69
                                               GimpSplash     *splash);
 
70
static void        splash_rectangle_union     (GdkRectangle   *dest,
 
71
                                               PangoRectangle *pango_rect,
 
72
                                               gint            offset_x,
 
73
                                               gint            offset_y);
 
74
static gboolean    splash_average_text_area   (GimpSplash     *splash,
 
75
                                               GdkPixbuf      *pixbuf,
 
76
                                               GdkColor       *color);
 
77
 
 
78
static GdkPixbufAnimation * splash_image_load          (gboolean     be_verbose);
 
79
static GdkPixbufAnimation * splash_image_pick_from_dir (const gchar *dirname,
 
80
                                                        gboolean     be_verbose);
 
81
 
 
82
#ifdef STARTUP_TIMER
 
83
static void        splash_timer_elapsed       (const gchar    *text1,
 
84
                                               const gchar    *text2,
 
85
                                               gdouble         percentage);
 
86
#endif
65
87
 
66
88
 
67
89
/*  public functions  */
68
90
 
69
91
void
70
 
splash_create (void)
 
92
splash_create (gboolean be_verbose)
71
93
{
72
 
  GtkWidget      *frame;
73
 
  GtkWidget      *vbox;
74
 
  GdkPixbuf      *pixbuf;
75
 
  GdkScreen      *screen;
76
 
  PangoAttrList  *attrs;
77
 
  PangoAttribute *attr;
78
 
  GdkGCValues     values;
79
 
  gchar          *filename;
 
94
  GtkWidget          *frame;
 
95
  GtkWidget          *vbox;
 
96
  GdkPixbufAnimation *pixbuf;
 
97
  GdkScreen          *screen;
 
98
  PangoAttrList      *attrs;
 
99
  PangoAttribute     *attr;
 
100
  GdkGCValues         values;
80
101
 
81
102
  g_return_if_fail (splash == NULL);
82
103
 
83
 
  filename = gimp_personal_rc_file ("gimp-splash.png");
84
 
  pixbuf = gdk_pixbuf_new_from_file (filename, NULL);
85
 
  g_free (filename);
86
 
 
87
 
  if (! pixbuf)
88
 
    {
89
 
      filename = gimp_personal_rc_file ("splashes");
90
 
      pixbuf = splash_pick_from_dir (filename);
91
 
      g_free (filename);
92
 
    }
93
 
 
94
 
  if (! pixbuf)
95
 
    {
96
 
      filename = g_build_filename (gimp_data_directory (),
97
 
                                   "images", "gimp-splash.png", NULL);
98
 
      pixbuf = gdk_pixbuf_new_from_file (filename, NULL);
99
 
      g_free (filename);
100
 
    }
101
 
 
102
 
  if (! pixbuf)
103
 
    {
104
 
      filename = g_build_filename (gimp_data_directory (), "splashes", NULL);
105
 
      pixbuf = splash_pick_from_dir (filename);
106
 
      g_free (filename);
107
 
    }
 
104
  pixbuf = splash_image_load (be_verbose);
108
105
 
109
106
  if (! pixbuf)
110
107
    return;
114
111
  splash->window =
115
112
    g_object_new (GTK_TYPE_WINDOW,
116
113
                  "type",            GTK_WINDOW_TOPLEVEL,
117
 
                  "type_hint",       GDK_WINDOW_TYPE_HINT_SPLASHSCREEN,
 
114
                  "type-hint",       GDK_WINDOW_TYPE_HINT_SPLASHSCREEN,
118
115
                  "title",           _("GIMP Startup"),
119
116
                  "role",            "gimp-startup",
120
 
                  "window_position", GTK_WIN_POS_CENTER,
 
117
                  "window-position", GTK_WIN_POS_CENTER,
121
118
                  "resizable",       FALSE,
122
119
                  NULL);
123
120
 
124
 
  g_signal_connect_swapped (splash->window, "delete_event",
 
121
  g_signal_connect_swapped (splash->window, "delete-event",
125
122
                            G_CALLBACK (exit),
126
123
                            GINT_TO_POINTER (0));
127
124
 
133
130
 
134
131
  screen = gtk_widget_get_screen (splash->window);
135
132
 
136
 
  splash->width  = MIN (gdk_pixbuf_get_width (pixbuf),
 
133
  splash->width  = MIN (gdk_pixbuf_animation_get_width (pixbuf),
137
134
                        gdk_screen_get_width (screen));
138
 
  splash->height = MIN (gdk_pixbuf_get_height (pixbuf),
 
135
  splash->height = MIN (gdk_pixbuf_animation_get_height (pixbuf),
139
136
                        gdk_screen_get_height (screen));
140
137
 
141
138
  frame = gtk_frame_new (NULL);
147
144
  gtk_container_add (GTK_CONTAINER (frame), vbox);
148
145
  gtk_widget_show (vbox);
149
146
 
150
 
  /*  prepare the drawing area  */
151
 
  splash->area = gtk_drawing_area_new ();
 
147
  /*  If the splash image is static, we use a drawing area and set the
 
148
   *  image as back pixmap, otherwise a GtkImage is being used.
 
149
   */
 
150
  if (gdk_pixbuf_animation_is_static_image (pixbuf))
 
151
    {
 
152
      splash->area = gtk_drawing_area_new ();
 
153
    }
 
154
  else
 
155
    {
 
156
      splash->area = gtk_image_new_from_animation (pixbuf);
 
157
    }
 
158
 
152
159
  gtk_box_pack_start_defaults (GTK_BOX (vbox), splash->area);
153
160
  gtk_widget_show (splash->area);
154
161
 
155
162
  gtk_widget_set_size_request (splash->area, splash->width, splash->height);
156
163
 
157
 
  gtk_widget_realize (splash->area);
158
 
 
159
 
  splash_average_bottom (splash->area, pixbuf, &values.foreground);
160
 
  splash->gc = gdk_gc_new_with_values (splash->area->window, &values,
161
 
                                       GDK_GC_FOREGROUND);
162
 
 
163
 
  splash->pixmap = gdk_pixmap_new (splash->area->window,
164
 
                                   splash->width, splash->height, -1);
165
 
  gdk_draw_pixbuf (splash->pixmap, splash->gc,
166
 
                   pixbuf, 0, 0, 0, 0, splash->width, splash->height,
167
 
                   GDK_RGB_DITHER_NORMAL, 0, 0);
168
 
  g_object_unref (pixbuf);
169
 
 
170
 
  g_signal_connect (splash->area, "expose_event",
171
 
                    G_CALLBACK (splash_area_expose),
172
 
                    splash);
173
 
 
174
164
  /*  create the pango layouts  */
175
165
  splash->upper = gtk_widget_create_pango_layout (splash->area, "");
176
166
  splash->lower = gtk_widget_create_pango_layout (splash->area, "");
184
174
  pango_layout_set_attributes (splash->upper, attrs);
185
175
  pango_attr_list_unref (attrs);
186
176
 
 
177
  /*  this sets the initial layout positions  */
 
178
  splash_position_layouts (splash, "", "", NULL);
 
179
 
 
180
  splash_average_text_area (splash,
 
181
                            gdk_pixbuf_animation_get_static_image (pixbuf),
 
182
                            &values.foreground);
 
183
 
 
184
  gtk_widget_realize (splash->area);
 
185
  splash->gc = gdk_gc_new_with_values (splash->area->window, &values,
 
186
                                       GDK_GC_FOREGROUND);
 
187
 
 
188
  if (gdk_pixbuf_animation_is_static_image (pixbuf))
 
189
    {
 
190
      GdkPixmap *pixmap = gdk_pixmap_new (splash->area->window,
 
191
                                          splash->width, splash->height, -1);
 
192
 
 
193
      gdk_draw_pixbuf (pixmap, splash->gc,
 
194
                       gdk_pixbuf_animation_get_static_image (pixbuf),
 
195
                       0, 0, 0, 0, splash->width, splash->height,
 
196
                       GDK_RGB_DITHER_NORMAL, 0, 0);
 
197
      gdk_window_set_back_pixmap (splash->area->window, pixmap, FALSE);
 
198
      g_object_unref (pixmap);
 
199
    }
 
200
 
 
201
  g_object_unref (pixbuf);
 
202
 
 
203
  g_signal_connect_after (splash->area, "expose-event",
 
204
                          G_CALLBACK (splash_area_expose),
 
205
                          splash);
 
206
 
187
207
  /*  add a progress bar  */
188
208
  splash->progress = gtk_progress_bar_new ();
189
209
  gtk_box_pack_end (GTK_BOX (vbox), splash->progress, FALSE, FALSE, 0);
190
210
  gtk_widget_show (splash->progress);
191
211
 
192
 
  gtk_widget_show (splash->window);
 
212
  gtk_widget_show_now (splash->window);
193
213
 
194
 
  while (gtk_events_pending ())
195
 
    gtk_main_iteration ();
 
214
#ifdef STARTUP_TIMER
 
215
  splash->timer = g_timer_new ();
 
216
#endif
196
217
}
197
218
 
198
219
void
204
225
  gtk_widget_destroy (splash->window);
205
226
 
206
227
  g_object_unref (splash->gc);
207
 
  g_object_unref (splash->pixmap);
208
228
  g_object_unref (splash->upper);
209
229
  g_object_unref (splash->lower);
210
230
 
 
231
#ifdef STARTUP_TIMER
 
232
  g_timer_destroy (splash->timer);
 
233
  g_free (splash->text1);
 
234
  g_free (splash->text2);
 
235
#endif
 
236
 
211
237
  g_free (splash);
212
238
  splash = NULL;
213
239
}
217
243
               const gchar *text2,
218
244
               gdouble      percentage)
219
245
{
220
 
  GdkRectangle    expose = { 0, 0, 0, 0 };
221
 
  PangoRectangle  ink;
222
 
  PangoRectangle  logical;
223
 
  gint            width;
224
 
  gint            height;
 
246
  GdkRectangle expose = { 0, 0, 0, 0 };
 
247
 
 
248
  g_return_if_fail (percentage >= 0.0 && percentage <= 1.0);
225
249
 
226
250
  if (! splash)
227
251
    return;
228
252
 
229
 
  width  = splash->area->allocation.width;
230
 
  height = splash->area->allocation.height;
231
 
 
232
 
  if (text1)
233
 
    {
234
 
      pango_layout_get_pixel_extents (splash->upper, &ink, NULL);
235
 
      splash_rectangle_union (&expose, &ink, splash->upper_x, splash->upper_y);
236
 
 
237
 
      pango_layout_set_text (splash->upper, text1, -1);
238
 
      pango_layout_get_pixel_extents (splash->upper, &ink, &logical);
239
 
 
240
 
      splash->upper_x = (width - logical.width) / 2;
241
 
      splash->upper_y = height - 2 * (logical.height + 6);
242
 
 
243
 
      splash_rectangle_union (&expose, &ink, splash->upper_x, splash->upper_y);
244
 
    }
245
 
 
246
 
  if (text2)
247
 
    {
248
 
      pango_layout_get_pixel_extents (splash->lower, &ink, NULL);
249
 
      splash_rectangle_union (&expose, &ink, splash->lower_x, splash->lower_y);
250
 
 
251
 
      pango_layout_set_text (splash->lower, text2, -1);
252
 
      pango_layout_get_pixel_extents (splash->lower, &ink, &logical);
253
 
 
254
 
      splash->lower_x = (width - logical.width) / 2;
255
 
      splash->lower_y = height - (logical.height + 6);
256
 
 
257
 
      splash_rectangle_union (&expose, &ink, splash->lower_x, splash->lower_y);
258
 
    }
 
253
#ifdef STARTUP_TIMER
 
254
  splash_timer_elapsed (text1, text2, percentage);
 
255
#endif
 
256
 
 
257
  splash_position_layouts (splash, text1, text2, &expose);
259
258
 
260
259
  if (expose.width > 0 && expose.height > 0)
261
260
    gtk_widget_queue_draw_area (splash->area,
263
262
                                expose.width, expose.height);
264
263
 
265
264
  gtk_progress_bar_set_fraction (GTK_PROGRESS_BAR (splash->progress),
266
 
                                 CLAMP (percentage, 0.0, 1.0));
 
265
                                 percentage);
267
266
 
268
267
  while (gtk_events_pending ())
269
268
    gtk_main_iteration ();
277
276
                    GdkEventExpose *event,
278
277
                    GimpSplash     *splash)
279
278
{
280
 
  gdk_gc_set_clip_rectangle (splash->gc, &event->area);
281
 
 
282
 
  gdk_draw_drawable (widget->window, splash->gc,
283
 
                     splash->pixmap, 0, 0,
284
 
                     (widget->allocation.width  - splash->width)  / 2,
285
 
                     (widget->allocation.height - splash->height) / 2,
286
 
                     splash->width,
287
 
                     splash->height);
 
279
  gdk_gc_set_clip_region (splash->gc, event->region);
288
280
 
289
281
  gdk_draw_layout (widget->window, splash->gc,
290
282
                   splash->upper_x, splash->upper_y, splash->upper);
304
296
   gtk_window_set_auto_startup_notification (TRUE);
305
297
}
306
298
 
307
 
static GdkPixbuf *
308
 
splash_pick_from_dir (const gchar *dirname)
 
299
/* area returns the union of the previous and new ink rectangles */
 
300
static void
 
301
splash_position_layouts (GimpSplash   *splash,
 
302
                         const gchar  *text1,
 
303
                         const gchar  *text2,
 
304
                         GdkRectangle *area)
309
305
{
310
 
  GdkPixbuf *pixbuf = NULL;
311
 
  GDir      *dir    = g_dir_open (dirname, 0, NULL);
312
 
 
313
 
  if (dir)
314
 
    {
315
 
      const gchar *entry;
316
 
      GList       *splashes = NULL;
317
 
 
318
 
      while ((entry = g_dir_read_name (dir)))
319
 
        splashes = g_list_prepend (splashes, g_strdup (entry));
320
 
 
321
 
      g_dir_close (dir);
322
 
 
323
 
      if (splashes)
324
 
        {
325
 
          gint32  i        = g_random_int_range (0, g_list_length (splashes));
326
 
          gchar  *filename = g_build_filename (dirname,
327
 
                                               g_list_nth_data (splashes, i),
328
 
                                               NULL);
329
 
 
330
 
          pixbuf = gdk_pixbuf_new_from_file (filename, NULL);
331
 
          g_free (filename);
332
 
 
333
 
          g_list_foreach (splashes, (GFunc) g_free, NULL);
334
 
          g_list_free (splashes);
335
 
        }
336
 
    }
337
 
 
338
 
  return pixbuf;
 
306
  PangoRectangle  ink;
 
307
  PangoRectangle  logical;
 
308
 
 
309
  if (text1)
 
310
    {
 
311
      pango_layout_get_pixel_extents (splash->upper, &ink, NULL);
 
312
 
 
313
      if (area)
 
314
        splash_rectangle_union (area, &ink, splash->upper_x, splash->upper_y);
 
315
 
 
316
      pango_layout_set_text (splash->upper, text1, -1);
 
317
      pango_layout_get_pixel_extents (splash->upper, &ink, &logical);
 
318
 
 
319
      splash->upper_x = (splash->width - logical.width) / 2;
 
320
      splash->upper_y = splash->height - 2 * (logical.height + 6);
 
321
 
 
322
      if (area)
 
323
        splash_rectangle_union (area, &ink, splash->upper_x, splash->upper_y);
 
324
    }
 
325
 
 
326
  if (text2)
 
327
    {
 
328
      pango_layout_get_pixel_extents (splash->lower, &ink, NULL);
 
329
 
 
330
      if (area)
 
331
        splash_rectangle_union (area, &ink, splash->lower_x, splash->lower_y);
 
332
 
 
333
      pango_layout_set_text (splash->lower, text2, -1);
 
334
      pango_layout_get_pixel_extents (splash->lower, &ink, &logical);
 
335
 
 
336
      splash->lower_x = (splash->width - logical.width) / 2;
 
337
      splash->lower_y = splash->height - (logical.height + 6);
 
338
 
 
339
      if (area)
 
340
        splash_rectangle_union (area, &ink, splash->lower_x, splash->lower_y);
 
341
    }
339
342
}
340
343
 
341
344
static void
358
361
}
359
362
 
360
363
/* This function chooses a gray value for the text color, based on
361
 
 * the average intensity of the lower 60 rows of the splash image.
 
364
 * the average luminance of the text area of the splash image.
362
365
 */
363
366
static gboolean
364
 
splash_average_bottom (GtkWidget *widget,
365
 
                       GdkPixbuf *pixbuf,
366
 
                       GdkColor  *color)
 
367
splash_average_text_area (GimpSplash *splash,
 
368
                          GdkPixbuf  *pixbuf,
 
369
                          GdkColor   *color)
367
370
{
368
371
  const guchar *pixels;
369
 
  gint          x, y;
370
 
  gint          width, height;
371
372
  gint          rowstride;
372
373
  gint          channels;
373
 
  gint          intensity;
374
 
  gint          count;
375
 
  guint         sum[3] = { 0, 0, 0 };
 
374
  gint          luminance = 0;
 
375
  guint         sum[3]    = { 0, 0, 0 };
 
376
  GdkRectangle  image     = { 0, 0, 0, 0 };
 
377
  GdkRectangle  area      = { 0, 0, 0, 0 };
376
378
 
377
379
  g_return_val_if_fail (GDK_IS_PIXBUF (pixbuf), FALSE);
378
380
  g_return_val_if_fail (gdk_pixbuf_get_bits_per_sample (pixbuf) == 8, FALSE);
379
381
 
380
 
  width     = gdk_pixbuf_get_width (pixbuf);
381
 
  height    = gdk_pixbuf_get_height (pixbuf);
382
 
  rowstride = gdk_pixbuf_get_rowstride (pixbuf);
383
 
  channels  = gdk_pixbuf_get_n_channels (pixbuf);
384
 
  pixels    = gdk_pixbuf_get_pixels (pixbuf);
385
 
 
386
 
  y = MAX (0, height - 60);
387
 
  count = width * (height - y);
388
 
 
389
 
  pixels += y * rowstride;
390
 
 
391
 
  for (; y < height; y++)
 
382
  image.width  = gdk_pixbuf_get_width (pixbuf);
 
383
  image.height = gdk_pixbuf_get_height (pixbuf);
 
384
  rowstride    = gdk_pixbuf_get_rowstride (pixbuf);
 
385
  channels     = gdk_pixbuf_get_n_channels (pixbuf);
 
386
  pixels       = gdk_pixbuf_get_pixels (pixbuf);
 
387
 
 
388
  splash_position_layouts (splash, "Short text", "Somewhat longer text", &area);
 
389
  splash_position_layouts (splash, "", "", NULL);
 
390
 
 
391
  if (gdk_rectangle_intersect (&image, &area, &area))
392
392
    {
393
 
      const guchar *src = pixels;
394
 
 
395
 
      for (x = 0; x < width; x++)
 
393
      const gint count = area.width * area.height;
 
394
      gint       x, y;
 
395
 
 
396
      pixels += area.x * channels;
 
397
      pixels += area.y * rowstride;
 
398
 
 
399
      for (y = 0; y < area.height; y++)
396
400
        {
397
 
          sum[0] += src[0];
398
 
          sum[1] += src[1];
399
 
          sum[2] += src[2];
400
 
 
401
 
          src += channels;
 
401
          const guchar *src = pixels;
 
402
 
 
403
          for (x = 0; x < area.width; x++)
 
404
            {
 
405
              sum[0] += src[0];
 
406
              sum[1] += src[1];
 
407
              sum[2] += src[2];
 
408
 
 
409
              src += channels;
 
410
            }
 
411
 
 
412
          pixels += rowstride;
402
413
        }
403
414
 
404
 
      pixels += rowstride;
 
415
      luminance = GIMP_RGB_LUMINANCE (sum[0] / count,
 
416
                                      sum[1] / count,
 
417
                                      sum[2] / count);
 
418
 
 
419
      luminance = CLAMP0255 (luminance > 127 ?
 
420
                             luminance - 223 : luminance + 223);
 
421
 
405
422
    }
406
423
 
407
 
  intensity = GIMP_RGB_INTENSITY (sum[0] / count,
408
 
                                  sum[1] / count,
409
 
                                  sum[2] / count);
410
 
 
411
 
  intensity = CLAMP0255 (intensity > 127 ? intensity - 223 : intensity + 223);
412
 
 
413
 
  color->red = color->green = color->blue = (intensity << 8 | intensity);
414
 
 
415
 
  return gdk_colormap_alloc_color (gtk_widget_get_colormap (widget),
 
424
  color->red = color->green = color->blue = (luminance << 8 | luminance);
 
425
 
 
426
  return gdk_colormap_alloc_color (gtk_widget_get_colormap (splash->area),
416
427
                                   color, FALSE, TRUE);
417
428
}
 
429
 
 
430
static GdkPixbufAnimation *
 
431
splash_image_load (gboolean be_verbose)
 
432
{
 
433
  GdkPixbufAnimation *pixbuf;
 
434
  gchar              *filename;
 
435
 
 
436
  filename = gimp_personal_rc_file ("gimp-splash.png");
 
437
 
 
438
  if (be_verbose)
 
439
    g_printerr ("Trying splash '%s' ... ", filename);
 
440
 
 
441
  pixbuf = gdk_pixbuf_animation_new_from_file (filename, NULL);
 
442
  g_free (filename);
 
443
 
 
444
  if (be_verbose)
 
445
    g_printerr (pixbuf ? "OK\n" : "failed\n");
 
446
 
 
447
  if (pixbuf)
 
448
    return pixbuf;
 
449
 
 
450
  filename = gimp_personal_rc_file ("splashes");
 
451
  pixbuf = splash_image_pick_from_dir (filename, be_verbose);
 
452
  g_free (filename);
 
453
 
 
454
  if (pixbuf)
 
455
    return pixbuf;
 
456
 
 
457
  filename = g_build_filename (gimp_data_directory (),
 
458
                               "images", "gimp-splash.png", NULL);
 
459
 
 
460
  if (be_verbose)
 
461
    g_printerr ("Trying splash '%s' ... ", filename);
 
462
 
 
463
  pixbuf = gdk_pixbuf_animation_new_from_file (filename, NULL);
 
464
  g_free (filename);
 
465
 
 
466
  if (be_verbose)
 
467
    g_printerr (pixbuf ? "OK\n" : "failed\n");
 
468
 
 
469
  if (pixbuf)
 
470
    return pixbuf;
 
471
 
 
472
  filename = g_build_filename (gimp_data_directory (), "splashes", NULL);
 
473
  pixbuf = splash_image_pick_from_dir (filename, be_verbose);
 
474
  g_free (filename);
 
475
 
 
476
  return pixbuf;
 
477
}
 
478
 
 
479
static GdkPixbufAnimation *
 
480
splash_image_pick_from_dir (const gchar *dirname,
 
481
                            gboolean     be_verbose)
 
482
{
 
483
  GdkPixbufAnimation *pixbuf = NULL;
 
484
  GDir               *dir    = g_dir_open (dirname, 0, NULL);
 
485
 
 
486
  if (dir)
 
487
    {
 
488
      const gchar *entry;
 
489
      GList       *splashes = NULL;
 
490
 
 
491
      while ((entry = g_dir_read_name (dir)))
 
492
        splashes = g_list_prepend (splashes, g_strdup (entry));
 
493
 
 
494
      g_dir_close (dir);
 
495
 
 
496
      if (splashes)
 
497
        {
 
498
          gint32  i        = g_random_int_range (0, g_list_length (splashes));
 
499
          gchar  *filename = g_build_filename (dirname,
 
500
                                               g_list_nth_data (splashes, i),
 
501
                                               NULL);
 
502
 
 
503
          if (be_verbose)
 
504
            g_printerr ("Trying splash '%s' ... ", filename);
 
505
 
 
506
          pixbuf = gdk_pixbuf_animation_new_from_file (filename, NULL);
 
507
          g_free (filename);
 
508
 
 
509
          if (be_verbose)
 
510
            g_printerr (pixbuf ? "OK\n" : "failed\n");
 
511
 
 
512
          g_list_foreach (splashes, (GFunc) g_free, NULL);
 
513
          g_list_free (splashes);
 
514
        }
 
515
    }
 
516
 
 
517
  return pixbuf;
 
518
}
 
519
 
 
520
#ifdef STARTUP_TIMER
 
521
static void
 
522
splash_timer_elapsed (const gchar *text1,
 
523
                      const gchar *text2,
 
524
                      gdouble      percentage)
 
525
{
 
526
  gdouble elapsed = g_timer_elapsed (splash->timer, NULL);
 
527
 
 
528
  if (text1)
 
529
    {
 
530
      g_free (splash->text1);
 
531
      splash->text1 = g_strdup (text1);
 
532
    }
 
533
 
 
534
  if (text2)
 
535
    {
 
536
      g_free (splash->text2);
 
537
      splash->text2 = g_strdup (text2);
 
538
    }
 
539
 
 
540
  g_printerr ("%8g  %8g  -  %s %g%%  -  %s\n",
 
541
              elapsed,
 
542
              elapsed - splash->last_time,
 
543
              splash->text1 ? splash->text1 : "",
 
544
              percentage * 100.0,
 
545
              splash->text2 ? splash->text2 : "");
 
546
 
 
547
  splash->last_time = elapsed;
 
548
}
 
549
#endif