GdkPixbuf * get_file_pixbuf (GSearchWindow * gsearch, GFileInfo * file_info) { GdkPixbuf * pixbuf; GIcon * icon = NULL; const gchar * thumbnail_path = NULL; if (file_info == NULL) { return NULL; } icon = g_file_info_get_icon (file_info); if (gsearch->show_thumbnails == TRUE) { thumbnail_path = g_file_info_get_attribute_byte_string (file_info, G_FILE_ATTRIBUTE_THUMBNAIL_PATH); } if (thumbnail_path != NULL) { pixbuf = gsearchtool_get_thumbnail_image (thumbnail_path); } else { gchar * icon_string; icon_string = g_icon_to_string (icon); pixbuf = (GdkPixbuf *) g_hash_table_lookup (gsearch->search_results_filename_hash_table, icon_string); if (pixbuf == NULL) { pixbuf = get_themed_icon_pixbuf (G_THEMED_ICON (icon), ICON_SIZE, gtk_icon_theme_get_default ()); g_hash_table_insert (gsearch->search_results_filename_hash_table, g_strdup (icon_string), pixbuf); } g_free (icon_string); } return pixbuf; }
GdkPixbuf * _g_icon_get_pixbuf (GIcon *icon, int size, GtkIconTheme *theme) { GdkPixbuf *pixbuf; int w, h; if (icon == NULL) return NULL; pixbuf = NULL; if (G_IS_THEMED_ICON (icon)) pixbuf = get_themed_icon_pixbuf (G_THEMED_ICON (icon), size, theme); if (G_IS_FILE_ICON (icon)) pixbuf = get_file_icon_pixbuf (G_FILE_ICON (icon), size); if (pixbuf == NULL) return NULL; w = gdk_pixbuf_get_width (pixbuf); h = gdk_pixbuf_get_height (pixbuf); if (scale_keeping_ratio (&w, &h, size, size, FALSE)) { GdkPixbuf *scaled; scaled = gdk_pixbuf_scale_simple (pixbuf, w, h, GDK_INTERP_BILINEAR); g_object_unref (pixbuf); pixbuf = scaled; } return pixbuf; }
static GdkPixbuf * _get_icon_pixbuf (GIcon * icon, int size, GtkIconTheme * theme) { if (icon == NULL) return NULL; if (G_IS_THEMED_ICON (icon)) return get_themed_icon_pixbuf (G_THEMED_ICON (icon), size, theme); if (G_IS_FILE_ICON (icon)) return get_file_icon_pixbuf (G_FILE_ICON (icon), size); return NULL; }
GdkPixbuf * iconstore_get_pixbuf (GFileInfo * file_info) { // create new hash table if (pixbuf_hash_table == NULL) { pixbuf_hash_table = g_hash_table_new_full (g_str_hash, g_str_equal, g_free, g_object_unref); } GIcon *icon = NULL; gboolean icon_needs_free = FALSE; if (file_info) { icon = g_file_info_get_icon (file_info); } else { icon = g_icon_new_for_string ("image-missing", NULL); icon_needs_free = TRUE; } gchar *icon_string = g_icon_to_string (icon); GdkPixbuf *pixbuf = (GdkPixbuf *) g_hash_table_lookup (pixbuf_hash_table, icon_string); if (pixbuf == NULL) { pixbuf = get_themed_icon_pixbuf (G_THEMED_ICON (icon), ICON_SIZE, gtk_icon_theme_get_default ()); g_hash_table_insert (pixbuf_hash_table, g_strdup (icon_string), pixbuf); } if (icon_needs_free) { g_object_unref (icon); } g_free (icon_string); return pixbuf; }