4 * ROX-Filer, filer for the ROX desktop project
5 * Copyright (C) 2005, the ROX-Filer team.
7 * This program is free software; you can redistribute it and/or modify it
8 * under the terms of the GNU General Public License as published by the Free
9 * Software Foundation; either version 2 of the License, or (at your option)
12 * This program is distributed in the hope that it will be useful, but WITHOUT
13 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
14 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
17 * You should have received a copy of the GNU General Public License along with
18 * this program; if not, write to the Free Software Foundation, Inc., 59 Temple
19 * Place, Suite 330, Boston, MA 02111-1307 USA
22 /* pixmaps.c - code for handling pixbufs (despite the name!) */
27 /* Remove pixmaps from the cache when they haven't been accessed for
28 * this period of time (seconds).
31 #define PIXMAP_PURGE_TIME 1200
32 #define PIXMAP_THUMB_SIZE 128
38 #include <sys/types.h>
48 #include "gui_support.h"
59 GFSCache
*pixmap_cache
= NULL
;
61 static const char * bad_xpm
[] = {
79 MaskedPixmap
*im_error
;
80 MaskedPixmap
*im_unknown
;
81 MaskedPixmap
*im_symlink
;
83 MaskedPixmap
*im_unmounted
;
84 MaskedPixmap
*im_mounted
;
85 MaskedPixmap
*im_appdir
;
86 MaskedPixmap
*im_xattr
;
88 MaskedPixmap
*im_dirs
;
90 typedef struct _ChildThumbnail ChildThumbnail
;
92 /* There is one of these for each active child process */
93 struct _ChildThumbnail
{
99 static const char *stocks
[] = {
100 ROX_STOCK_SHOW_DETAILS
,
101 ROX_STOCK_SHOW_HIDDEN
,
107 static GtkIconSize mount_icon_size
= -1;
109 /* Static prototypes */
111 static void load_default_pixmaps(void);
112 static gint
purge(gpointer data
);
113 static MaskedPixmap
*image_from_file(const char *path
);
114 static MaskedPixmap
*get_bad_image(void);
115 static GdkPixbuf
*scale_pixbuf_up(GdkPixbuf
*src
, int max_w
, int max_h
);
116 static GdkPixbuf
*get_thumbnail_for(const char *path
);
117 static void thumbnail_child_done(ChildThumbnail
*info
);
118 static void child_create_thumbnail(const gchar
*path
);
119 static GdkPixbuf
*create_spotlight_pixbuf(GdkPixbuf
*src
, guint32 color
,
121 static GList
*thumbs_purge_cache(Option
*option
, xmlNode
*node
, guchar
*label
);
122 static gchar
*thumbnail_path(const gchar
*path
);
123 static gchar
*thumbnail_program(MIME_type
*type
);
125 /****************************************************************
126 * EXTERNAL INTERFACE *
127 ****************************************************************/
129 void pixmaps_init(void)
131 GtkIconFactory
*factory
;
134 gtk_widget_push_colormap(gdk_rgb_get_colormap());
136 pixmap_cache
= g_fscache_new((GFSLoadFunc
) image_from_file
, NULL
, NULL
);
138 g_timeout_add(10000, purge
, NULL
);
140 factory
= gtk_icon_factory_new();
141 for (i
= 0; i
< G_N_ELEMENTS(stocks
); i
++)
144 GError
*error
= NULL
;
147 const gchar
*name
= stocks
[i
];
149 path
= g_strconcat(app_dir
, "/images/", name
, ".png", NULL
);
150 pixbuf
= gdk_pixbuf_new_from_file(path
, &error
);
153 g_warning("%s", error
->message
);
155 pixbuf
= gdk_pixbuf_new_from_xpm_data(bad_xpm
);
159 iset
= gtk_icon_set_new_from_pixbuf(pixbuf
);
160 g_object_unref(G_OBJECT(pixbuf
));
161 gtk_icon_factory_add(factory
, name
, iset
);
162 gtk_icon_set_unref(iset
);
164 gtk_icon_factory_add_default(factory
);
166 mount_icon_size
= gtk_icon_size_register("rox-mount-size", 14, 14);
168 load_default_pixmaps();
170 option_register_widget("thumbs-purge-cache", thumbs_purge_cache
);
173 /* Load image <appdir>/images/name.png.
174 * Always returns with a valid image.
176 MaskedPixmap
*load_pixmap(const char *name
)
179 MaskedPixmap
*retval
;
181 path
= g_strconcat(app_dir
, "/images/", name
, ".png", NULL
);
182 retval
= image_from_file(path
);
186 retval
= get_bad_image();
191 /* Create a MaskedPixmap from a GTK stock ID. Always returns
194 static MaskedPixmap
*mp_from_stock(const char *stock_id
, int size
)
196 GtkIconSet
*icon_set
;
198 MaskedPixmap
*retval
;
200 icon_set
= gtk_icon_factory_lookup_default(stock_id
);
202 return get_bad_image();
204 pixbuf
= gtk_icon_set_render_icon(icon_set
,
205 gtk_widget_get_default_style(), /* Gtk bug */
211 retval
= masked_pixmap_new(pixbuf
);
212 gdk_pixbuf_unref(pixbuf
);
217 void pixmap_make_huge(MaskedPixmap
*mp
)
222 g_return_if_fail(mp
->src_pixbuf
!= NULL
);
224 /* Limit to small size now, otherwise they get scaled up in mixed mode.
227 mp
->huge_pixbuf
= scale_pixbuf_up(mp
->src_pixbuf
,
228 SMALL_WIDTH
, SMALL_HEIGHT
);
230 if (!mp
->huge_pixbuf
)
232 mp
->huge_pixbuf
= mp
->src_pixbuf
;
233 g_object_ref(mp
->huge_pixbuf
);
236 mp
->huge_pixbuf_lit
= create_spotlight_pixbuf(mp
->huge_pixbuf
,
238 mp
->huge_width
= gdk_pixbuf_get_width(mp
->huge_pixbuf
);
239 mp
->huge_height
= gdk_pixbuf_get_height(mp
->huge_pixbuf
);
242 void pixmap_make_small(MaskedPixmap
*mp
)
247 g_return_if_fail(mp
->src_pixbuf
!= NULL
);
249 mp
->sm_pixbuf
= scale_pixbuf(mp
->src_pixbuf
, SMALL_WIDTH
, SMALL_HEIGHT
);
253 mp
->sm_pixbuf
= mp
->src_pixbuf
;
254 g_object_ref(mp
->sm_pixbuf
);
257 mp
->sm_pixbuf_lit
= create_spotlight_pixbuf(mp
->sm_pixbuf
,
260 mp
->sm_width
= gdk_pixbuf_get_width(mp
->sm_pixbuf
);
261 mp
->sm_height
= gdk_pixbuf_get_height(mp
->sm_pixbuf
);
264 /* Load image 'path' in the background and insert into pixmap_cache.
265 * Call callback(data, path) when done (path is NULL => error).
266 * If the image is already uptodate, or being created already, calls the
267 * callback right away.
269 void pixmap_background_thumb(const gchar
*path
, GFunc callback
, gpointer data
)
275 ChildThumbnail
*info
;
280 image
= g_fscache_lookup_full(pixmap_cache
, path
,
281 FSCACHE_LOOKUP_ONLY_NEW
, &found
);
285 /* Thumbnail is known, or being created */
287 g_object_unref(image
);
288 callback(data
, NULL
);
292 g_return_if_fail(image
== NULL
);
294 pixbuf
= get_thumbnail_for(path
);
298 struct stat info1
, info2
;
301 dir
= g_path_get_dirname(path
);
303 /* If the image itself is in ~/.thumbnails, load it now
304 * (ie, don't create thumbnails for thumbnails!).
306 if (mc_stat(dir
, &info1
) != 0)
308 callback(data
, NULL
);
314 if (mc_stat(make_path(home_dir
, ".thumbnails/normal"),
316 info1
.st_dev
== info2
.st_dev
&&
317 info1
.st_ino
== info2
.st_ino
)
319 pixbuf
= rox_pixbuf_new_from_file_at_scale(path
,
320 PIXMAP_THUMB_SIZE
, PIXMAP_THUMB_SIZE
, TRUE
, NULL
);
323 g_fscache_insert(pixmap_cache
,
325 callback(data
, NULL
);
335 image
= masked_pixmap_new(pixbuf
);
336 gdk_pixbuf_unref(pixbuf
);
337 g_fscache_insert(pixmap_cache
, path
, image
, TRUE
);
338 callback(data
, (gchar
*) path
);
342 type
= type_from_path(path
);
346 /* Add an entry, set to NULL, so no-one else tries to load this
349 g_fscache_insert(pixmap_cache
, path
, NULL
, TRUE
);
351 thumb_prog
= thumbnail_program(type
);
353 /* Only attempt to load 'images' types ourselves */
354 if (thumb_prog
== NULL
&& strcmp(type
->media_type
, "image") != 0)
356 callback(data
, NULL
);
357 return; /* Don't know how to handle this type */
365 delayed_error("fork(): %s", g_strerror(errno
));
366 callback(data
, NULL
);
372 /* We are the child process. (We are sloppy with freeing
373 memory, but since we go away very quickly, that's ok.) */
378 item
= diritem_new(g_basename(thumb_prog
));
380 diritem_restat(thumb_prog
, item
, NULL
);
381 if (item
->flags
& ITEM_FLAG_APPDIR
)
382 thumb_prog
= g_strconcat(thumb_prog
, "/AppRun",
385 execl(thumb_prog
, thumb_prog
, path
,
386 thumbnail_path(path
),
387 g_strdup_printf("%d", PIXMAP_THUMB_SIZE
),
392 child_create_thumbnail(path
);
398 info
= g_new(ChildThumbnail
, 1);
399 info
->path
= g_strdup(path
);
400 info
->callback
= callback
;
402 on_child_death(child
, (CallbackFn
) thumbnail_child_done
, info
);
405 /****************************************************************
406 * INTERNAL FUNCTIONS *
407 ****************************************************************/
409 /* Create a thumbnail file for this image */
410 static void save_thumbnail(const char *pathname
, GdkPixbuf
*full
)
414 int original_width
, original_height
;
416 char *md5
, *swidth
, *sheight
, *ssize
, *smtime
, *uri
;
421 thumb
= scale_pixbuf(full
, PIXMAP_THUMB_SIZE
, PIXMAP_THUMB_SIZE
);
423 original_width
= gdk_pixbuf_get_width(full
);
424 original_height
= gdk_pixbuf_get_height(full
);
426 if (mc_stat(pathname
, &info
) != 0)
429 swidth
= g_strdup_printf("%d", original_width
);
430 sheight
= g_strdup_printf("%d", original_height
);
431 ssize
= g_strdup_printf("%" SIZE_FMT
, info
.st_size
);
432 smtime
= g_strdup_printf("%ld", (long) info
.st_mtime
);
434 path
= pathdup(pathname
);
435 uri
= g_filename_to_uri(path
, NULL
, NULL
);
437 uri
= g_strconcat("file://", path
, NULL
);
441 to
= g_string_new(home_dir
);
442 g_string_append(to
, "/.thumbnails");
443 mkdir(to
->str
, 0700);
444 g_string_append(to
, "/normal/");
445 mkdir(to
->str
, 0700);
446 g_string_append(to
, md5
);
447 name_len
= to
->len
+ 4; /* Truncate to this length when renaming */
448 g_string_append_printf(to
, ".png.ROX-Filer-%ld", (long) getpid());
452 old_mask
= umask(0077);
453 gdk_pixbuf_save(thumb
, to
->str
, "png", NULL
,
454 "tEXt::Thumb::Image::Width", swidth
,
455 "tEXt::Thumb::Image::Height", sheight
,
456 "tEXt::Thumb::Size", ssize
,
457 "tEXt::Thumb::MTime", smtime
,
458 "tEXt::Thumb::URI", uri
,
459 "tEXt::Software", PROJECT
,
463 /* We create the file ###.png.ROX-Filer-PID and rename it to avoid
464 * a race condition if two programs create the same thumb at
470 final
= g_strndup(to
->str
, name_len
);
471 if (rename(to
->str
, final
))
472 g_warning("Failed to rename '%s' to '%s': %s",
473 to
->str
, final
, g_strerror(errno
));
477 g_string_free(to
, TRUE
);
485 static gchar
*thumbnail_path(const char *path
)
491 uri
= g_filename_to_uri(path
, NULL
, NULL
);
493 uri
= g_strconcat("file://", path
, NULL
);
496 to
= g_string_new(home_dir
);
497 g_string_append(to
, "/.thumbnails");
498 mkdir(to
->str
, 0700);
499 g_string_append(to
, "/normal/");
500 mkdir(to
->str
, 0700);
501 g_string_append(to
, md5
);
502 g_string_append(to
, ".png");
508 g_string_free(to
, FALSE
);
513 /* Return a program to create thumbnails for files of this type.
514 * NULL to try to make it ourself (using gdk).
517 static gchar
*thumbnail_program(MIME_type
*type
)
525 leaf
= g_strconcat(type
->media_type
, "_", type
->subtype
, NULL
);
526 path
= choices_find_path_load(leaf
, "MIME-thumb");
533 path
= choices_find_path_load(type
->media_type
, "MIME-thumb");
538 /* Called in a subprocess. Load path and create the thumbnail
539 * file. Parent will notice when we die.
541 static void child_create_thumbnail(const gchar
*path
)
545 image
= rox_pixbuf_new_from_file_at_scale(path
,
546 PIXMAP_THUMB_SIZE
, PIXMAP_THUMB_SIZE
, TRUE
, NULL
);
549 save_thumbnail(path
, image
);
551 /* (no need to unref, as we're about to exit) */
554 /* Called when the child process exits */
555 static void thumbnail_child_done(ChildThumbnail
*info
)
559 thumb
= get_thumbnail_for(info
->path
);
565 image
= masked_pixmap_new(thumb
);
566 g_object_unref(thumb
);
568 g_fscache_insert(pixmap_cache
, info
->path
, image
, FALSE
);
569 g_object_unref(image
);
571 info
->callback(info
->data
, info
->path
);
574 info
->callback(info
->data
, NULL
);
580 /* Check if we have an up-to-date thumbnail for this image.
581 * If so, return it. Otherwise, returns NULL.
583 static GdkPixbuf
*get_thumbnail_for(const char *pathname
)
585 GdkPixbuf
*thumb
= NULL
;
586 char *thumb_path
, *md5
, *uri
, *path
;
587 const char *ssize
, *smtime
;
590 path
= pathdup(pathname
);
591 uri
= g_filename_to_uri(path
, NULL
, NULL
);
593 uri
= g_strconcat("file://", path
, NULL
);
597 thumb_path
= g_strdup_printf("%s/.thumbnails/normal/%s.png",
601 thumb
= gdk_pixbuf_new_from_file(thumb_path
, NULL
);
605 /* Note that these don't need freeing... */
606 ssize
= gdk_pixbuf_get_option(thumb
, "tEXt::Thumb::Size");
610 smtime
= gdk_pixbuf_get_option(thumb
, "tEXt::Thumb::MTime");
614 if (mc_stat(path
, &info
) != 0)
617 if (info
.st_mtime
!= atol(smtime
) || info
.st_size
!= atol(ssize
))
623 gdk_pixbuf_unref(thumb
);
631 /* Load the image 'path' and return a pointer to the resulting
632 * MaskedPixmap. NULL on failure.
633 * Doesn't check for thumbnails (this is for small icons).
635 static MaskedPixmap
*image_from_file(const char *path
)
639 GError
*error
= NULL
;
641 pixbuf
= gdk_pixbuf_new_from_file(path
, &error
);
644 g_warning("%s\n", error
->message
);
649 image
= masked_pixmap_new(pixbuf
);
651 gdk_pixbuf_unref(pixbuf
);
656 /* Scale src down to fit in max_w, max_h and return the new pixbuf.
657 * If src is small enough, then ref it and return that.
659 GdkPixbuf
*scale_pixbuf(GdkPixbuf
*src
, int max_w
, int max_h
)
663 w
= gdk_pixbuf_get_width(src
);
664 h
= gdk_pixbuf_get_height(src
);
666 if (w
<= max_w
&& h
<= max_h
)
673 float scale_x
= ((float) w
) / max_w
;
674 float scale_y
= ((float) h
) / max_h
;
675 float scale
= MAX(scale_x
, scale_y
);
676 int dest_w
= w
/ scale
;
677 int dest_h
= h
/ scale
;
679 return gdk_pixbuf_scale_simple(src
,
682 GDK_INTERP_BILINEAR
);
686 /* Scale src up to fit in max_w, max_h and return the new pixbuf.
687 * If src is that size or bigger, then ref it and return that.
689 static GdkPixbuf
*scale_pixbuf_up(GdkPixbuf
*src
, int max_w
, int max_h
)
693 w
= gdk_pixbuf_get_width(src
);
694 h
= gdk_pixbuf_get_height(src
);
696 if (w
== 0 || h
== 0 || w
>= max_w
|| h
>= max_h
)
703 float scale_x
= max_w
/ ((float) w
);
704 float scale_y
= max_h
/ ((float) h
);
705 float scale
= MIN(scale_x
, scale_y
);
707 return gdk_pixbuf_scale_simple(src
,
710 GDK_INTERP_BILINEAR
);
714 /* Return a pointer to the (static) bad image. The ref counter will ensure
715 * that the image is never freed.
717 static MaskedPixmap
*get_bad_image(void)
722 bad
= gdk_pixbuf_new_from_xpm_data(bad_xpm
);
723 mp
= masked_pixmap_new(bad
);
724 gdk_pixbuf_unref(bad
);
729 /* Called now and then to clear out old pixmaps */
730 static gint
purge(gpointer data
)
732 g_fscache_purge(pixmap_cache
, PIXMAP_PURGE_TIME
);
737 static gpointer parent_class
;
739 static void masked_pixmap_finialize(GObject
*object
)
741 MaskedPixmap
*mp
= (MaskedPixmap
*) object
;
745 g_object_unref(mp
->src_pixbuf
);
746 mp
->src_pixbuf
= NULL
;
751 g_object_unref(mp
->huge_pixbuf
);
752 mp
->huge_pixbuf
= NULL
;
754 if (mp
->huge_pixbuf_lit
)
756 g_object_unref(mp
->huge_pixbuf_lit
);
757 mp
->huge_pixbuf_lit
= NULL
;
762 g_object_unref(mp
->pixbuf
);
767 g_object_unref(mp
->pixbuf_lit
);
768 mp
->pixbuf_lit
= NULL
;
773 g_object_unref(mp
->sm_pixbuf
);
774 mp
->sm_pixbuf
= NULL
;
776 if (mp
->sm_pixbuf_lit
)
778 g_object_unref(mp
->sm_pixbuf_lit
);
779 mp
->sm_pixbuf_lit
= NULL
;
782 G_OBJECT_CLASS(parent_class
)->finalize(object
);
785 static void masked_pixmap_class_init(gpointer gclass
, gpointer data
)
787 GObjectClass
*object
= (GObjectClass
*) gclass
;
789 parent_class
= g_type_class_peek_parent(gclass
);
791 object
->finalize
= masked_pixmap_finialize
;
794 static void masked_pixmap_init(GTypeInstance
*object
, gpointer gclass
)
796 MaskedPixmap
*mp
= (MaskedPixmap
*) object
;
798 mp
->src_pixbuf
= NULL
;
800 mp
->huge_pixbuf
= NULL
;
801 mp
->huge_pixbuf_lit
= NULL
;
803 mp
->huge_height
= -1;
806 mp
->pixbuf_lit
= NULL
;
810 mp
->sm_pixbuf
= NULL
;
811 mp
->sm_pixbuf_lit
= NULL
;
816 static GType
masked_pixmap_get_type(void)
818 static GType type
= 0;
822 static const GTypeInfo info
=
824 sizeof (MaskedPixmapClass
),
825 NULL
, /* base_init */
826 NULL
, /* base_finalise */
827 masked_pixmap_class_init
,
828 NULL
, /* class_finalise */
829 NULL
, /* class_data */
830 sizeof(MaskedPixmap
),
835 type
= g_type_register_static(G_TYPE_OBJECT
, "MaskedPixmap",
842 MaskedPixmap
*masked_pixmap_new(GdkPixbuf
*full_size
)
845 GdkPixbuf
*src_pixbuf
, *normal_pixbuf
;
847 g_return_val_if_fail(full_size
!= NULL
, NULL
);
849 src_pixbuf
= scale_pixbuf(full_size
, HUGE_WIDTH
, HUGE_HEIGHT
);
850 g_return_val_if_fail(src_pixbuf
!= NULL
, NULL
);
852 normal_pixbuf
= scale_pixbuf(src_pixbuf
, ICON_WIDTH
, ICON_HEIGHT
);
853 g_return_val_if_fail(normal_pixbuf
!= NULL
, NULL
);
855 mp
= g_object_new(masked_pixmap_get_type(), NULL
);
857 mp
->src_pixbuf
= src_pixbuf
;
859 mp
->pixbuf
= normal_pixbuf
;
860 mp
->pixbuf_lit
= create_spotlight_pixbuf(normal_pixbuf
, 0x000099, 128);
861 mp
->width
= gdk_pixbuf_get_width(normal_pixbuf
);
862 mp
->height
= gdk_pixbuf_get_height(normal_pixbuf
);
867 /* Stolen from eel...and modified to colourize the pixbuf.
868 * 'alpha' is the transparency of 'color' (0xRRGGBB):
869 * 0 = fully opaque, 255 = fully transparent.
871 static GdkPixbuf
*create_spotlight_pixbuf(GdkPixbuf
*src
,
877 int width
, height
, has_alpha
, src_row_stride
, dst_row_stride
;
878 guchar
*target_pixels
, *original_pixels
;
879 guchar
*pixsrc
, *pixdest
;
883 n_channels
= gdk_pixbuf_get_n_channels(src
);
884 has_alpha
= gdk_pixbuf_get_has_alpha(src
);
885 width
= gdk_pixbuf_get_width(src
);
886 height
= gdk_pixbuf_get_height(src
);
888 g_return_val_if_fail(gdk_pixbuf_get_colorspace(src
) ==
889 GDK_COLORSPACE_RGB
, NULL
);
890 g_return_val_if_fail((!has_alpha
&& n_channels
== 3) ||
891 (has_alpha
&& n_channels
== 4), NULL
);
892 g_return_val_if_fail(gdk_pixbuf_get_bits_per_sample(src
) == 8, NULL
);
894 dest
= gdk_pixbuf_new(gdk_pixbuf_get_colorspace(src
), has_alpha
,
895 gdk_pixbuf_get_bits_per_sample(src
),
898 dst_row_stride
= gdk_pixbuf_get_rowstride(dest
);
899 src_row_stride
= gdk_pixbuf_get_rowstride(src
);
900 target_pixels
= gdk_pixbuf_get_pixels(dest
);
901 original_pixels
= gdk_pixbuf_get_pixels(src
);
903 r
= (color
& 0xff0000) >> 16;
904 g
= (color
& 0xff00) >> 8;
907 for (i
= 0; i
< height
; i
++)
911 pixdest
= target_pixels
+ i
* dst_row_stride
;
912 pixsrc
= original_pixels
+ i
* src_row_stride
;
913 for (j
= 0; j
< width
; j
++)
915 tmp
= (*pixsrc
++ * alpha
+ r
* (255 - alpha
)) / 255;
916 *pixdest
++ = (guchar
) MIN(255, tmp
);
917 tmp
= (*pixsrc
++ * alpha
+ g
* (255 - alpha
)) / 255;
918 *pixdest
++ = (guchar
) MIN(255, tmp
);
919 tmp
= (*pixsrc
++ * alpha
+ b
* (255 - alpha
)) / 255;
920 *pixdest
++ = (guchar
) MIN(255, tmp
);
922 *pixdest
++ = *pixsrc
++;
929 /* Load all the standard pixmaps. Also sets the default window icon. */
930 static void load_default_pixmaps(void)
933 GError
*error
= NULL
;
935 im_error
= mp_from_stock(GTK_STOCK_DIALOG_WARNING
,
936 GTK_ICON_SIZE_DIALOG
);
937 im_unknown
= mp_from_stock(GTK_STOCK_DIALOG_QUESTION
,
938 GTK_ICON_SIZE_DIALOG
);
939 im_symlink
= load_pixmap("symlink");
941 im_unmounted
= mp_from_stock(ROX_STOCK_MOUNT
, mount_icon_size
);
942 im_mounted
= mp_from_stock(ROX_STOCK_MOUNTED
, mount_icon_size
);
943 im_appdir
= load_pixmap("application");
944 im_xattr
= load_pixmap("rox-xattr");
946 im_dirs
= load_pixmap("dirs");
948 pixbuf
= gdk_pixbuf_new_from_file(
949 make_path(app_dir
, ".DirIcon"), &error
);
954 icon_list
= g_list_append(NULL
, pixbuf
);
955 gtk_window_set_default_icon_list(icon_list
);
956 g_list_free(icon_list
);
958 g_object_unref(G_OBJECT(pixbuf
));
962 g_warning("%s\n", error
->message
);
967 /* Also purges memory cache */
968 static void purge_disk_cache(GtkWidget
*button
, gpointer data
)
975 g_fscache_purge(pixmap_cache
, 0);
977 path
= g_strconcat(home_dir
, "/.thumbnails/normal/", NULL
);
982 report_error(_("Can't delete thumbnails in %s:\n%s"),
983 path
, g_strerror(errno
));
987 while ((ent
= readdir(dir
)))
989 if (ent
->d_name
[0] == '.')
991 list
= g_list_prepend(list
,
992 g_strconcat(path
, ent
->d_name
, NULL
));
1000 destroy_glist(&list
);
1003 info_message(_("There are no thumbnails to delete"));
1008 static GList
*thumbs_purge_cache(Option
*option
, xmlNode
*node
, guchar
*label
)
1010 GtkWidget
*button
, *align
;
1012 g_return_val_if_fail(option
== NULL
, NULL
);
1014 align
= gtk_alignment_new(0, 0.5, 0, 0);
1015 button
= button_new_mixed(GTK_STOCK_CLEAR
,
1016 _("Purge thumbnails disk cache"));
1017 gtk_container_add(GTK_CONTAINER(align
), button
);
1018 g_signal_connect(button
, "clicked", G_CALLBACK(purge_disk_cache
), NULL
);
1020 return g_list_append(NULL
, align
);