From 211b77131ef01c0f2d55546c9ca62470916b864d Mon Sep 17 00:00:00 2001 From: Eric Koegel Date: Tue, 10 Jan 2012 20:40:21 +0300 Subject: [PATCH] Fixes custom icons for desktop files. The previous code looked for custom file icons in the ~/.thumbnails/ directory where the prefix matches the desktop file icon, however the code wouldn't ever work. This patch scans the thumbanil dir a loads a custom icon if there's a file that matches the file name on the desktop. So a file on the desktop named foo will have a custom icon loaded if the image in the .thumbnails dir is foo.gif --- src/xfdesktop-regular-file-icon.c | 41 ++++++++++++++++++++++++++++--------- 1 files changed, 31 insertions(+), 10 deletions(-) diff --git a/src/xfdesktop-regular-file-icon.c b/src/xfdesktop-regular-file-icon.c index e14256a..51257a5 100644 --- a/src/xfdesktop-regular-file-icon.c +++ b/src/xfdesktop-regular-file-icon.c @@ -209,22 +209,47 @@ xfdesktop_regular_file_icon_peek_pixbuf(XfdesktopIcon *icon, XfdesktopRegularFileIcon *file_icon = XFDESKTOP_REGULAR_FILE_ICON(icon); gchar *icon_name = NULL; GdkPixbuf *emblem_pix = NULL; + GIcon *gicon = NULL; if(size != file_icon->priv->cur_pix_size) xfdesktop_regular_file_icon_invalidate_pixbuf(file_icon); if(!file_icon->priv->pix) { - GIcon *gicon = NULL; + GFileEnumerator *enumerator; /* create a GFile for the $HOME/.thumbnails/ directory */ gchar *thumbnail_dir_path = g_build_filename(xfce_get_homedir(), ".thumbnails", NULL); - GFile *thumbnail_dir = g_file_new_for_path(thumbnail_dir_path); - if(g_file_has_prefix(file_icon->priv->file, thumbnail_dir)) { - /* use the filename as custom icon name for thumbnails */ - icon_name = g_file_get_path(file_icon->priv->file); - } else if(xfdesktop_file_utils_is_desktop_file(file_icon->priv->file_info)) { + /* User dropped in a directory, get the files in it */ + enumerator = g_file_enumerate_children ( + g_file_new_for_path(thumbnail_dir_path), + "standard::name,access::can-read", + G_FILE_QUERY_INFO_NONE, + NULL, + NULL); + + if (enumerator) { + GFileInfo *f_info; + + /* Check all the files for a prefix match */ + for (f_info = g_file_enumerator_next_file (enumerator, NULL, NULL); + f_info != NULL; + f_info = g_file_enumerator_next_file (enumerator, NULL, NULL)) + { + if(g_str_has_prefix(g_file_info_get_name (f_info), file_icon->priv->display_name)) { + /* use the filename as custom icon name for thumbnails */ + icon_name = g_strdup_printf("%s/%s", thumbnail_dir_path, g_file_info_get_name (f_info)); + break; + } + g_object_unref (f_info); + } + g_file_enumerator_close (enumerator, NULL, NULL); + g_object_unref (enumerator); + g_free(thumbnail_dir_path); + } + + if(!icon_name && xfdesktop_file_utils_is_desktop_file(file_icon->priv->file_info)) { gchar *contents; gsize length; @@ -250,10 +275,6 @@ xfdesktop_regular_file_icon_peek_pixbuf(XfdesktopIcon *icon, } } - /* release thumbnail path */ - g_object_unref(thumbnail_dir); - g_free(thumbnail_dir_path); - /* load the symlink emblem if necessary */ if(g_file_info_get_attribute_boolean(file_icon->priv->file_info, G_FILE_ATTRIBUTE_STANDARD_IS_SYMLINK)) -- 1.7.5.4