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
33 #define PIXMAP_THUMB_TOO_OLD_TIME 5
39 #include <sys/types.h>
49 #include "gui_support.h"
60 GFSCache
*pixmap_cache
= NULL
;
62 static const char * bad_xpm
[] = {
80 MaskedPixmap
*im_error
;
81 MaskedPixmap
*im_unknown
;
82 MaskedPixmap
*im_symlink
;
84 MaskedPixmap
*im_unmounted
;
85 MaskedPixmap
*im_mounted
;
86 MaskedPixmap
*im_appdir
;
87 MaskedPixmap
*im_xattr
;
89 MaskedPixmap
*im_dirs
;
91 typedef struct _ChildThumbnail ChildThumbnail
;
93 /* There is one of these for each active child process */
94 struct _ChildThumbnail
{
100 static const char *stocks
[] = {
101 ROX_STOCK_SHOW_DETAILS
,
102 ROX_STOCK_SHOW_HIDDEN
,
108 static GtkIconSize mount_icon_size
= -1;
110 /* Static prototypes */
112 static void load_default_pixmaps(void);
113 static gint
purge(gpointer data
);
114 static MaskedPixmap
*image_from_file(const char *path
);
115 static MaskedPixmap
*get_bad_image(void);
116 static GdkPixbuf
*scale_pixbuf_up(GdkPixbuf
*src
, int max_w
, int max_h
);
117 static GdkPixbuf
*get_thumbnail_for(const char *path
);
118 static void thumbnail_child_done(ChildThumbnail
*info
);
119 static void child_create_thumbnail(const gchar
*path
);
120 static GdkPixbuf
*create_spotlight_pixbuf(GdkPixbuf
*src
, guint32 color
,
122 static GList
*thumbs_purge_cache(Option
*option
, xmlNode
*node
, guchar
*label
);
123 static gchar
*thumbnail_path(const gchar
*path
);
124 static gchar
*thumbnail_program(MIME_type
*type
);
126 /****************************************************************
127 * EXTERNAL INTERFACE *
128 ****************************************************************/
130 void pixmaps_init(void)
132 GtkIconFactory
*factory
;
135 gtk_widget_push_colormap(gdk_rgb_get_colormap());
137 pixmap_cache
= g_fscache_new((GFSLoadFunc
) image_from_file
, NULL
, NULL
);
139 g_timeout_add(10000, purge
, NULL
);
141 factory
= gtk_icon_factory_new();
142 for (i
= 0; i
< G_N_ELEMENTS(stocks
); i
++)
145 GError
*error
= NULL
;
148 const gchar
*name
= stocks
[i
];
150 path
= g_strconcat(app_dir
, "/images/", name
, ".png", NULL
);
151 pixbuf
= gdk_pixbuf_new_from_file(path
, &error
);
154 g_warning("%s", error
->message
);
156 pixbuf
= gdk_pixbuf_new_from_xpm_data(bad_xpm
);
160 iset
= gtk_icon_set_new_from_pixbuf(pixbuf
);
161 g_object_unref(G_OBJECT(pixbuf
));
162 gtk_icon_factory_add(factory
, name
, iset
);
163 gtk_icon_set_unref(iset
);
165 gtk_icon_factory_add_default(factory
);
167 mount_icon_size
= gtk_icon_size_register("rox-mount-size", 14, 14);
169 load_default_pixmaps();
171 option_register_widget("thumbs-purge-cache", thumbs_purge_cache
);
174 /* Load image <appdir>/images/name.png.
175 * Always returns with a valid image.
177 MaskedPixmap
*load_pixmap(const char *name
)
180 MaskedPixmap
*retval
;
182 path
= g_strconcat(app_dir
, "/images/", name
, ".png", NULL
);
183 retval
= image_from_file(path
);
187 retval
= get_bad_image();
192 /* Create a MaskedPixmap from a GTK stock ID. Always returns
195 static MaskedPixmap
*mp_from_stock(const char *stock_id
, int size
)
197 GtkIconSet
*icon_set
;
199 MaskedPixmap
*retval
;
201 icon_set
= gtk_icon_factory_lookup_default(stock_id
);
203 return get_bad_image();
205 pixbuf
= gtk_icon_set_render_icon(icon_set
,
206 gtk_widget_get_default_style(), /* Gtk bug */
212 retval
= masked_pixmap_new(pixbuf
);
213 gdk_pixbuf_unref(pixbuf
);
218 void pixmap_make_huge(MaskedPixmap
*mp
)
223 g_return_if_fail(mp
->src_pixbuf
!= NULL
);
225 /* Limit to small size now, otherwise they get scaled up in mixed mode.
228 mp
->huge_pixbuf
= scale_pixbuf_up(mp
->src_pixbuf
,
229 SMALL_WIDTH
, SMALL_HEIGHT
);
231 if (!mp
->huge_pixbuf
)
233 mp
->huge_pixbuf
= mp
->src_pixbuf
;
234 g_object_ref(mp
->huge_pixbuf
);
237 mp
->huge_pixbuf_lit
= create_spotlight_pixbuf(mp
->huge_pixbuf
,
239 mp
->huge_width
= gdk_pixbuf_get_width(mp
->huge_pixbuf
);
240 mp
->huge_height
= gdk_pixbuf_get_height(mp
->huge_pixbuf
);
243 void pixmap_make_small(MaskedPixmap
*mp
)
248 g_return_if_fail(mp
->src_pixbuf
!= NULL
);
250 mp
->sm_pixbuf
= scale_pixbuf(mp
->src_pixbuf
, SMALL_WIDTH
, SMALL_HEIGHT
);
254 mp
->sm_pixbuf
= mp
->src_pixbuf
;
255 g_object_ref(mp
->sm_pixbuf
);
258 mp
->sm_pixbuf_lit
= create_spotlight_pixbuf(mp
->sm_pixbuf
,
261 mp
->sm_width
= gdk_pixbuf_get_width(mp
->sm_pixbuf
);
262 mp
->sm_height
= gdk_pixbuf_get_height(mp
->sm_pixbuf
);
265 /* Load image 'path' in the background and insert into pixmap_cache.
266 * Call callback(data, path) when done (path is NULL => error).
267 * If the image is already uptodate, or being created already, calls the
268 * callback right away.
270 void pixmap_background_thumb(const gchar
*path
, GFunc callback
, gpointer data
)
276 ChildThumbnail
*info
;
281 image
= g_fscache_lookup_full(pixmap_cache
, path
,
282 FSCACHE_LOOKUP_ONLY_NEW
, &found
);
286 /* Thumbnail is known, or being created */
288 g_object_unref(image
);
289 callback(data
, NULL
);
293 g_return_if_fail(image
== NULL
);
295 pixbuf
= get_thumbnail_for(path
);
299 struct stat info1
, info2
;
302 dir
= g_path_get_dirname(path
);
304 /* If the image itself is in ~/.thumbnails, load it now
305 * (ie, don't create thumbnails for thumbnails!).
307 if (mc_stat(dir
, &info1
) != 0)
309 callback(data
, NULL
);
315 if (mc_stat(make_path(home_dir
, ".thumbnails/normal"),
317 info1
.st_dev
== info2
.st_dev
&&
318 info1
.st_ino
== info2
.st_ino
)
320 pixbuf
= rox_pixbuf_new_from_file_at_scale(path
,
321 PIXMAP_THUMB_SIZE
, PIXMAP_THUMB_SIZE
, TRUE
, NULL
);
324 g_fscache_insert(pixmap_cache
,
326 callback(data
, NULL
);
336 image
= masked_pixmap_new(pixbuf
);
337 gdk_pixbuf_unref(pixbuf
);
338 g_fscache_insert(pixmap_cache
, path
, image
, TRUE
);
339 callback(data
, (gchar
*) path
);
340 g_object_unref(G_OBJECT(image
));
344 type
= type_from_path(path
);
348 /* Add an entry, set to NULL, so no-one else tries to load this
351 g_fscache_insert(pixmap_cache
, path
, NULL
, TRUE
);
353 thumb_prog
= thumbnail_program(type
);
355 /* Only attempt to load 'images' types ourselves */
356 if (thumb_prog
== NULL
&& strcmp(type
->media_type
, "image") != 0)
358 callback(data
, NULL
);
359 return; /* Don't know how to handle this type */
367 delayed_error("fork(): %s", g_strerror(errno
));
368 callback(data
, NULL
);
374 /* We are the child process. (We are sloppy with freeing
375 memory, but since we go away very quickly, that's ok.) */
380 item
= diritem_new(g_basename(thumb_prog
));
382 diritem_restat(thumb_prog
, item
, NULL
);
383 if (item
->flags
& ITEM_FLAG_APPDIR
)
384 thumb_prog
= g_strconcat(thumb_prog
, "/AppRun",
387 execl(thumb_prog
, thumb_prog
, path
,
388 thumbnail_path(path
),
389 g_strdup_printf("%d", PIXMAP_THUMB_SIZE
),
394 child_create_thumbnail(path
);
400 info
= g_new(ChildThumbnail
, 1);
401 info
->path
= g_strdup(path
);
402 info
->callback
= callback
;
404 on_child_death(child
, (CallbackFn
) thumbnail_child_done
, info
);
407 /****************************************************************
408 * INTERNAL FUNCTIONS *
409 ****************************************************************/
411 /* Create a thumbnail file for this image */
412 static void save_thumbnail(const char *pathname
, GdkPixbuf
*full
)
416 int original_width
, original_height
;
418 char *md5
, *swidth
, *sheight
, *ssize
, *smtime
, *uri
;
423 thumb
= scale_pixbuf(full
, PIXMAP_THUMB_SIZE
, PIXMAP_THUMB_SIZE
);
425 original_width
= gdk_pixbuf_get_width(full
);
426 original_height
= gdk_pixbuf_get_height(full
);
428 if (mc_stat(pathname
, &info
) != 0)
431 swidth
= g_strdup_printf("%d", original_width
);
432 sheight
= g_strdup_printf("%d", original_height
);
433 ssize
= g_strdup_printf("%" SIZE_FMT
, info
.st_size
);
434 smtime
= g_strdup_printf("%ld", (long) info
.st_mtime
);
436 path
= pathdup(pathname
);
437 uri
= g_filename_to_uri(path
, NULL
, NULL
);
439 uri
= g_strconcat("file://", path
, NULL
);
443 to
= g_string_new(home_dir
);
444 g_string_append(to
, "/.thumbnails");
445 mkdir(to
->str
, 0700);
446 g_string_append(to
, "/normal/");
447 mkdir(to
->str
, 0700);
448 g_string_append(to
, md5
);
449 name_len
= to
->len
+ 4; /* Truncate to this length when renaming */
450 g_string_append_printf(to
, ".png.ROX-Filer-%ld", (long) getpid());
454 old_mask
= umask(0077);
455 gdk_pixbuf_save(thumb
, to
->str
, "png", NULL
,
456 "tEXt::Thumb::Image::Width", swidth
,
457 "tEXt::Thumb::Image::Height", sheight
,
458 "tEXt::Thumb::Size", ssize
,
459 "tEXt::Thumb::MTime", smtime
,
460 "tEXt::Thumb::URI", uri
,
461 "tEXt::Software", PROJECT
,
465 /* We create the file ###.png.ROX-Filer-PID and rename it to avoid
466 * a race condition if two programs create the same thumb at
472 final
= g_strndup(to
->str
, name_len
);
473 if (rename(to
->str
, final
))
474 g_warning("Failed to rename '%s' to '%s': %s",
475 to
->str
, final
, g_strerror(errno
));
479 g_string_free(to
, TRUE
);
487 static gchar
*thumbnail_path(const char *path
)
493 uri
= g_filename_to_uri(path
, NULL
, NULL
);
495 uri
= g_strconcat("file://", path
, NULL
);
498 to
= g_string_new(home_dir
);
499 g_string_append(to
, "/.thumbnails");
500 mkdir(to
->str
, 0700);
501 g_string_append(to
, "/normal/");
502 mkdir(to
->str
, 0700);
503 g_string_append(to
, md5
);
504 g_string_append(to
, ".png");
510 g_string_free(to
, FALSE
);
515 /* Return a program to create thumbnails for files of this type.
516 * NULL to try to make it ourself (using gdk).
519 static gchar
*thumbnail_program(MIME_type
*type
)
527 leaf
= g_strconcat(type
->media_type
, "_", type
->subtype
, NULL
);
528 path
= choices_find_xdg_path_load(leaf
, "MIME-thumb", SITE
);
535 path
= choices_find_xdg_path_load(type
->media_type
, "MIME-thumb",
541 /* Called in a subprocess. Load path and create the thumbnail
542 * file. Parent will notice when we die.
544 static void child_create_thumbnail(const gchar
*path
)
548 image
= rox_pixbuf_new_from_file_at_scale(path
,
549 PIXMAP_THUMB_SIZE
, PIXMAP_THUMB_SIZE
, TRUE
, NULL
);
552 save_thumbnail(path
, image
);
554 /* (no need to unref, as we're about to exit) */
557 /* Called when the child process exits */
558 static void thumbnail_child_done(ChildThumbnail
*info
)
562 thumb
= get_thumbnail_for(info
->path
);
568 image
= masked_pixmap_new(thumb
);
569 g_object_unref(thumb
);
571 g_fscache_insert(pixmap_cache
, info
->path
, image
, FALSE
);
572 g_object_unref(image
);
574 info
->callback(info
->data
, info
->path
);
577 info
->callback(info
->data
, NULL
);
583 /* Check if we have an up-to-date thumbnail for this image.
584 * If so, return it. Otherwise, returns NULL.
586 static GdkPixbuf
*get_thumbnail_for(const char *pathname
)
588 GdkPixbuf
*thumb
= NULL
;
589 char *thumb_path
, *md5
, *uri
, *path
;
590 const char *ssize
, *smtime
;
594 path
= pathdup(pathname
);
595 uri
= g_filename_to_uri(path
, NULL
, NULL
);
597 uri
= g_strconcat("file://", path
, NULL
);
601 thumb_path
= g_strdup_printf("%s/.thumbnails/normal/%s.png",
605 thumb
= gdk_pixbuf_new_from_file(thumb_path
, NULL
);
609 /* Note that these don't need freeing... */
610 ssize
= gdk_pixbuf_get_option(thumb
, "tEXt::Thumb::Size");
614 smtime
= gdk_pixbuf_get_option(thumb
, "tEXt::Thumb::MTime");
618 if (mc_stat(path
, &info
) != 0)
621 ttime
=(time_t) atol(smtime
);
623 if (info
.st_mtime
!= ttime
&& now
>ttime
+PIXMAP_THUMB_TOO_OLD_TIME
)
626 if (info
.st_size
< atol(ssize
))
632 gdk_pixbuf_unref(thumb
);
640 /* Load the image 'path' and return a pointer to the resulting
641 * MaskedPixmap. NULL on failure.
642 * Doesn't check for thumbnails (this is for small icons).
644 static MaskedPixmap
*image_from_file(const char *path
)
648 GError
*error
= NULL
;
650 pixbuf
= gdk_pixbuf_new_from_file(path
, &error
);
653 g_warning("%s\n", error
->message
);
658 image
= masked_pixmap_new(pixbuf
);
660 gdk_pixbuf_unref(pixbuf
);
665 /* Scale src down to fit in max_w, max_h and return the new pixbuf.
666 * If src is small enough, then ref it and return that.
668 GdkPixbuf
*scale_pixbuf(GdkPixbuf
*src
, int max_w
, int max_h
)
672 w
= gdk_pixbuf_get_width(src
);
673 h
= gdk_pixbuf_get_height(src
);
675 if (w
<= max_w
&& h
<= max_h
)
682 float scale_x
= ((float) w
) / max_w
;
683 float scale_y
= ((float) h
) / max_h
;
684 float scale
= MAX(scale_x
, scale_y
);
685 int dest_w
= w
/ scale
;
686 int dest_h
= h
/ scale
;
688 return gdk_pixbuf_scale_simple(src
,
691 GDK_INTERP_BILINEAR
);
695 /* Scale src up to fit in max_w, max_h and return the new pixbuf.
696 * If src is that size or bigger, then ref it and return that.
698 static GdkPixbuf
*scale_pixbuf_up(GdkPixbuf
*src
, int max_w
, int max_h
)
702 w
= gdk_pixbuf_get_width(src
);
703 h
= gdk_pixbuf_get_height(src
);
705 if (w
== 0 || h
== 0 || w
>= max_w
|| h
>= max_h
)
712 float scale_x
= max_w
/ ((float) w
);
713 float scale_y
= max_h
/ ((float) h
);
714 float scale
= MIN(scale_x
, scale_y
);
716 return gdk_pixbuf_scale_simple(src
,
719 GDK_INTERP_BILINEAR
);
723 /* Return a pointer to the (static) bad image. The ref counter will ensure
724 * that the image is never freed.
726 static MaskedPixmap
*get_bad_image(void)
731 bad
= gdk_pixbuf_new_from_xpm_data(bad_xpm
);
732 mp
= masked_pixmap_new(bad
);
733 gdk_pixbuf_unref(bad
);
738 /* Called now and then to clear out old pixmaps */
739 static gint
purge(gpointer data
)
741 g_fscache_purge(pixmap_cache
, PIXMAP_PURGE_TIME
);
746 static gpointer parent_class
;
748 static void masked_pixmap_finialize(GObject
*object
)
750 MaskedPixmap
*mp
= (MaskedPixmap
*) object
;
754 g_object_unref(mp
->src_pixbuf
);
755 mp
->src_pixbuf
= NULL
;
760 g_object_unref(mp
->huge_pixbuf
);
761 mp
->huge_pixbuf
= NULL
;
763 if (mp
->huge_pixbuf_lit
)
765 g_object_unref(mp
->huge_pixbuf_lit
);
766 mp
->huge_pixbuf_lit
= NULL
;
771 g_object_unref(mp
->pixbuf
);
776 g_object_unref(mp
->pixbuf_lit
);
777 mp
->pixbuf_lit
= NULL
;
782 g_object_unref(mp
->sm_pixbuf
);
783 mp
->sm_pixbuf
= NULL
;
785 if (mp
->sm_pixbuf_lit
)
787 g_object_unref(mp
->sm_pixbuf_lit
);
788 mp
->sm_pixbuf_lit
= NULL
;
791 G_OBJECT_CLASS(parent_class
)->finalize(object
);
794 static void masked_pixmap_class_init(gpointer gclass
, gpointer data
)
796 GObjectClass
*object
= (GObjectClass
*) gclass
;
798 parent_class
= g_type_class_peek_parent(gclass
);
800 object
->finalize
= masked_pixmap_finialize
;
803 static void masked_pixmap_init(GTypeInstance
*object
, gpointer gclass
)
805 MaskedPixmap
*mp
= (MaskedPixmap
*) object
;
807 mp
->src_pixbuf
= NULL
;
809 mp
->huge_pixbuf
= NULL
;
810 mp
->huge_pixbuf_lit
= NULL
;
812 mp
->huge_height
= -1;
815 mp
->pixbuf_lit
= NULL
;
819 mp
->sm_pixbuf
= NULL
;
820 mp
->sm_pixbuf_lit
= NULL
;
825 static GType
masked_pixmap_get_type(void)
827 static GType type
= 0;
831 static const GTypeInfo info
=
833 sizeof (MaskedPixmapClass
),
834 NULL
, /* base_init */
835 NULL
, /* base_finalise */
836 masked_pixmap_class_init
,
837 NULL
, /* class_finalise */
838 NULL
, /* class_data */
839 sizeof(MaskedPixmap
),
844 type
= g_type_register_static(G_TYPE_OBJECT
, "MaskedPixmap",
851 MaskedPixmap
*masked_pixmap_new(GdkPixbuf
*full_size
)
854 GdkPixbuf
*src_pixbuf
, *normal_pixbuf
;
856 g_return_val_if_fail(full_size
!= NULL
, NULL
);
858 src_pixbuf
= scale_pixbuf(full_size
, HUGE_WIDTH
, HUGE_HEIGHT
);
859 g_return_val_if_fail(src_pixbuf
!= NULL
, NULL
);
861 normal_pixbuf
= scale_pixbuf(src_pixbuf
, ICON_WIDTH
, ICON_HEIGHT
);
862 g_return_val_if_fail(normal_pixbuf
!= NULL
, NULL
);
864 mp
= g_object_new(masked_pixmap_get_type(), NULL
);
866 mp
->src_pixbuf
= src_pixbuf
;
868 mp
->pixbuf
= normal_pixbuf
;
869 mp
->pixbuf_lit
= create_spotlight_pixbuf(normal_pixbuf
, 0x000099, 128);
870 mp
->width
= gdk_pixbuf_get_width(normal_pixbuf
);
871 mp
->height
= gdk_pixbuf_get_height(normal_pixbuf
);
876 /* Stolen from eel...and modified to colourize the pixbuf.
877 * 'alpha' is the transparency of 'color' (0xRRGGBB):
878 * 0 = fully opaque, 255 = fully transparent.
880 static GdkPixbuf
*create_spotlight_pixbuf(GdkPixbuf
*src
,
886 int width
, height
, has_alpha
, src_row_stride
, dst_row_stride
;
887 guchar
*target_pixels
, *original_pixels
;
888 guchar
*pixsrc
, *pixdest
;
892 n_channels
= gdk_pixbuf_get_n_channels(src
);
893 has_alpha
= gdk_pixbuf_get_has_alpha(src
);
894 width
= gdk_pixbuf_get_width(src
);
895 height
= gdk_pixbuf_get_height(src
);
897 g_return_val_if_fail(gdk_pixbuf_get_colorspace(src
) ==
898 GDK_COLORSPACE_RGB
, NULL
);
899 g_return_val_if_fail((!has_alpha
&& n_channels
== 3) ||
900 (has_alpha
&& n_channels
== 4), NULL
);
901 g_return_val_if_fail(gdk_pixbuf_get_bits_per_sample(src
) == 8, NULL
);
903 dest
= gdk_pixbuf_new(gdk_pixbuf_get_colorspace(src
), has_alpha
,
904 gdk_pixbuf_get_bits_per_sample(src
),
907 dst_row_stride
= gdk_pixbuf_get_rowstride(dest
);
908 src_row_stride
= gdk_pixbuf_get_rowstride(src
);
909 target_pixels
= gdk_pixbuf_get_pixels(dest
);
910 original_pixels
= gdk_pixbuf_get_pixels(src
);
912 r
= (color
& 0xff0000) >> 16;
913 g
= (color
& 0xff00) >> 8;
916 for (i
= 0; i
< height
; i
++)
920 pixdest
= target_pixels
+ i
* dst_row_stride
;
921 pixsrc
= original_pixels
+ i
* src_row_stride
;
922 for (j
= 0; j
< width
; j
++)
924 tmp
= (*pixsrc
++ * alpha
+ r
* (255 - alpha
)) / 255;
925 *pixdest
++ = (guchar
) MIN(255, tmp
);
926 tmp
= (*pixsrc
++ * alpha
+ g
* (255 - alpha
)) / 255;
927 *pixdest
++ = (guchar
) MIN(255, tmp
);
928 tmp
= (*pixsrc
++ * alpha
+ b
* (255 - alpha
)) / 255;
929 *pixdest
++ = (guchar
) MIN(255, tmp
);
931 *pixdest
++ = *pixsrc
++;
938 /* Load all the standard pixmaps. Also sets the default window icon. */
939 static void load_default_pixmaps(void)
942 GError
*error
= NULL
;
944 im_error
= mp_from_stock(GTK_STOCK_DIALOG_WARNING
,
945 GTK_ICON_SIZE_DIALOG
);
946 im_unknown
= mp_from_stock(GTK_STOCK_DIALOG_QUESTION
,
947 GTK_ICON_SIZE_DIALOG
);
948 im_symlink
= load_pixmap("symlink");
950 im_unmounted
= mp_from_stock(ROX_STOCK_MOUNT
, mount_icon_size
);
951 im_mounted
= mp_from_stock(ROX_STOCK_MOUNTED
, mount_icon_size
);
952 im_appdir
= load_pixmap("application");
953 im_xattr
= load_pixmap("rox-xattr");
955 im_dirs
= load_pixmap("dirs");
957 pixbuf
= gdk_pixbuf_new_from_file(
958 make_path(app_dir
, ".DirIcon"), &error
);
963 icon_list
= g_list_append(NULL
, pixbuf
);
964 gtk_window_set_default_icon_list(icon_list
);
965 g_list_free(icon_list
);
967 g_object_unref(G_OBJECT(pixbuf
));
971 g_warning("%s\n", error
->message
);
976 /* Also purges memory cache */
977 static void purge_disk_cache(GtkWidget
*button
, gpointer data
)
984 g_fscache_purge(pixmap_cache
, 0);
986 path
= g_strconcat(home_dir
, "/.thumbnails/normal/", NULL
);
991 report_error(_("Can't delete thumbnails in %s:\n%s"),
992 path
, g_strerror(errno
));
996 while ((ent
= readdir(dir
)))
998 if (ent
->d_name
[0] == '.')
1000 list
= g_list_prepend(list
,
1001 g_strconcat(path
, ent
->d_name
, NULL
));
1008 action_delete(list
);
1009 destroy_glist(&list
);
1012 info_message(_("There are no thumbnails to delete"));
1017 static GList
*thumbs_purge_cache(Option
*option
, xmlNode
*node
, guchar
*label
)
1019 GtkWidget
*button
, *align
;
1021 g_return_val_if_fail(option
== NULL
, NULL
);
1023 align
= gtk_alignment_new(0, 0.5, 0, 0);
1024 button
= button_new_mixed(GTK_STOCK_CLEAR
,
1025 _("Purge thumbnails disk cache"));
1026 gtk_container_add(GTK_CONTAINER(align
), button
);
1027 g_signal_connect(button
, "clicked", G_CALLBACK(purge_disk_cache
), NULL
);
1029 return g_list_append(NULL
, align
);