From 290cd2b1acc2f22d22c46b39fd1361d3048abe5e Mon Sep 17 00:00:00 2001 From: Milan Crha Date: Mon, 3 Aug 2009 20:42:45 +0200 Subject: Bug #580895 - Kill libgnomeui/gnome-thumbnail.h --- e-util/e-icon-factory.c | 69 ++++++++++++++++++++++++++++++++++++++++++++----- e-util/e-icon-factory.h | 2 ++ 2 files changed, 65 insertions(+), 6 deletions(-) (limited to 'e-util') diff --git a/e-util/e-icon-factory.c b/e-util/e-icon-factory.c index 1336164347..496a96a7e4 100644 --- a/e-util/e-icon-factory.c +++ b/e-util/e-icon-factory.c @@ -30,10 +30,11 @@ #include -#ifdef HAVE_LIBGNOMEUI_GNOME_THUMBNAIL_H -#include -#endif +#define GNOME_DESKTOP_USE_UNSTABLE_API +#include +#undef GNOME_DESKTOP_USE_UNSTABLE_API +#include #include #include "e-icon-factory.h" @@ -41,6 +42,7 @@ #include "art/broken-image-16.xpm" #include "art/broken-image-24.xpm" + #define d(x) typedef struct { @@ -332,10 +334,65 @@ e_icon_factory_pixbuf_scale (GdkPixbuf *pixbuf, gint width, gint height) if (height <= 0) height = 1; -#ifdef HAVE_LIBGNOMEUI_GNOME_THUMBNAIL_H /* because this can only scale down, not up */ if (gdk_pixbuf_get_width (pixbuf) > width && gdk_pixbuf_get_height (pixbuf) > height) - return gnome_thumbnail_scale_down_pixbuf (pixbuf, width, height); -#endif + return gnome_desktop_thumbnail_scale_down_pixbuf (pixbuf, width, height); + return gdk_pixbuf_scale_simple (pixbuf, width, height, GDK_INTERP_BILINEAR); } + +/** + * e_icon_factory_create_thumbnail + * Creates system thumbnail for a file filename. + * @param filename The file name to create the thumbnail for. + * @return Path to system thumbnail of the file; NULL if couldn't create it. Free it with g_free. + **/ +gchar * +e_icon_factory_create_thumbnail (const gchar *filename) +{ + static GnomeDesktopThumbnailFactory *thumbnail_factory = NULL; + struct stat file_stat; + gchar *thumbnail = NULL; + + g_return_val_if_fail (filename != NULL, NULL); + + if (thumbnail_factory == NULL) { + thumbnail_factory = gnome_desktop_thumbnail_factory_new (GNOME_DESKTOP_THUMBNAIL_SIZE_NORMAL); + } + + if (g_stat (filename, &file_stat) != -1 && S_ISREG (file_stat.st_mode)) { + gchar *content_type, *mime = NULL; + gboolean uncertain = FALSE; + + content_type = g_content_type_guess (filename, NULL, 0, &uncertain); + if (content_type) + mime = g_content_type_get_mime_type (content_type); + + if (mime) { + gchar *uri = g_filename_to_uri (filename, NULL, NULL); + + g_return_val_if_fail (uri != NULL, NULL); + + thumbnail = gnome_desktop_thumbnail_factory_lookup (thumbnail_factory, uri, file_stat.st_mtime); + if (!thumbnail && gnome_desktop_thumbnail_factory_can_thumbnail (thumbnail_factory, uri, mime, file_stat.st_mtime)) { + GdkPixbuf *pixbuf; + + pixbuf = gnome_desktop_thumbnail_factory_generate_thumbnail (thumbnail_factory, uri, mime); + + if (pixbuf) { + gnome_desktop_thumbnail_factory_save_thumbnail (thumbnail_factory, pixbuf, uri, file_stat.st_mtime); + g_object_unref (pixbuf); + + thumbnail = gnome_desktop_thumbnail_factory_lookup (thumbnail_factory, uri, file_stat.st_mtime); + } + } + + g_free (uri); + } + + g_free (content_type); + g_free (mime); + } + + return thumbnail; +} diff --git a/e-util/e-icon-factory.h b/e-util/e-icon-factory.h index b8a4df972f..52ac332363 100644 --- a/e-util/e-icon-factory.h +++ b/e-util/e-icon-factory.h @@ -36,4 +36,6 @@ GdkPixbuf * e_icon_factory_pixbuf_scale (GdkPixbuf *pixbuf, gint width, gint height); +gchar * e_icon_factory_create_thumbnail (const gchar *filename); + #endif /* _E_ICON_FACTORY_H_ */ -- cgit v1.2.3