[Xfce4-commits] <xfdesktop:master> Rework all peek_pixbuf() methods to work like in Thunar, using GIO.
Jannis Pohlmann
noreply at xfce.org
Tue Nov 2 01:14:37 CET 2010
Updating branch refs/heads/master
to b0a38dd49cfe488c6aaebc19f72c9b868f5718b0 (commit)
from 3f81a95103b7eed956459c1b8211a70debbdd439 (commit)
commit b0a38dd49cfe488c6aaebc19f72c9b868f5718b0
Author: Jannis Pohlmann <jannis at xfce.org>
Date: Mon Oct 25 15:49:12 2010 +0200
Rework all peek_pixbuf() methods to work like in Thunar, using GIO.
src/xfdesktop-file-icon-manager.c | 1 -
src/xfdesktop-file-utils.c | 39 +++++++++++----------
src/xfdesktop-file-utils.h | 3 +-
src/xfdesktop-regular-file-icon.c | 69 ++++++++++++++++++++++++++++---------
src/xfdesktop-special-file-icon.c | 41 +++++++---------------
src/xfdesktop-volume-icon.c | 10 ++---
6 files changed, 92 insertions(+), 71 deletions(-)
diff --git a/src/xfdesktop-file-icon-manager.c b/src/xfdesktop-file-icon-manager.c
index b37a657..f55c87b 100644
--- a/src/xfdesktop-file-icon-manager.c
+++ b/src/xfdesktop-file-icon-manager.c
@@ -108,7 +108,6 @@ struct _XfdesktopFileIconManagerPrivate
GFile *folder;
XfdesktopFileIcon *desktop_icon;
GFileMonitor *monitor;
- ThunarVfsJob *list_job;
GFileEnumerator *enumerator;
GHashTable *icons;
diff --git a/src/xfdesktop-file-utils.c b/src/xfdesktop-file-utils.c
index 226c0f5..cda6178 100644
--- a/src/xfdesktop-file-utils.c
+++ b/src/xfdesktop-file-utils.c
@@ -160,8 +160,8 @@ xfdesktop_file_utils_get_file_kind(const ThunarVfsInfo *info,
return str;
}
-static
-gboolean xfdesktop_file_utils_is_desktop_file(GFileInfo *info)
+gboolean
+xfdesktop_file_utils_is_desktop_file(GFileInfo *info)
{
const gchar *content_type;
gboolean is_desktop_file = FALSE;
@@ -297,14 +297,13 @@ xfdesktop_file_utils_get_fallback_icon(gint size)
GdkPixbuf *
xfdesktop_file_utils_get_file_icon(const gchar *custom_icon_name,
- ThunarVfsInfo *info,
+ GFileInfo *info,
gint size,
const GdkPixbuf *emblem,
guint opacity)
{
GtkIconTheme *itheme = gtk_icon_theme_get_default();
GdkPixbuf *pix_theme = NULL, *pix = NULL;
- const gchar *icon_name;
if(custom_icon_name) {
pix_theme = gtk_icon_theme_load_icon(itheme, custom_icon_name, size,
@@ -312,20 +311,24 @@ xfdesktop_file_utils_get_file_icon(const gchar *custom_icon_name,
}
if(!pix_theme && info) {
- icon_name = thunar_vfs_info_get_custom_icon(info);
- if(icon_name) {
- pix_theme = gtk_icon_theme_load_icon(itheme, icon_name, size,
- ITHEME_FLAGS, NULL);
- }
- }
-
- if(!pix_theme && info && info->mime_info) {
- icon_name = thunar_vfs_mime_info_lookup_icon_name(info->mime_info,
- gtk_icon_theme_get_default());
- DBG("got mime info icon name: %s", icon_name);
- if(icon_name) {
- pix_theme = gtk_icon_theme_load_icon(itheme, icon_name, size,
- ITHEME_FLAGS, NULL);
+ GIcon *icon = g_file_info_get_icon(info);
+ if(icon) {
+ if(G_IS_THEMED_ICON(icon)) {
+ GtkIconInfo *icon_info = gtk_icon_theme_lookup_by_gicon(itheme,
+ icon, size,
+ ITHEME_FLAGS);
+ if(icon_info) {
+ pix_theme = gtk_icon_info_load_icon(icon_info, NULL);
+ gtk_icon_info_free(icon_info);
+ }
+ } else if(G_IS_LOADABLE_ICON(icon)) {
+ GInputStream *stream = g_loadable_icon_load(G_LOADABLE_ICON(icon),
+ size, NULL, NULL, NULL);
+ if(stream) {
+ pix = gdk_pixbuf_new_from_stream(stream, NULL, NULL);
+ g_object_unref(stream);
+ }
+ }
}
}
diff --git a/src/xfdesktop-file-utils.h b/src/xfdesktop-file-utils.h
index a94de89..5f37e95 100644
--- a/src/xfdesktop-file-utils.h
+++ b/src/xfdesktop-file-utils.h
@@ -57,6 +57,7 @@ void xfdesktop_file_utils_move_into(GtkWindow *parent,
gchar *xfdesktop_file_utils_get_file_kind(const ThunarVfsInfo *info,
gboolean *is_link);
+gboolean xfdesktop_file_utils_is_desktop_file(GFileInfo *info);
gboolean xfdesktop_file_utils_file_is_executable(GFileInfo *info);
GList *xfdesktop_file_utils_file_icon_list_to_file_list(GList *icon_list);
@@ -66,7 +67,7 @@ void xfdesktop_file_utils_file_list_free(GList *file_list);
GdkPixbuf *xfdesktop_file_utils_get_fallback_icon(gint size);
GdkPixbuf *xfdesktop_file_utils_get_file_icon(const gchar *custom_icon_name,
- ThunarVfsInfo *info,
+ GFileInfo *info,
gint size,
const GdkPixbuf *emblem,
guint opacity);
diff --git a/src/xfdesktop-regular-file-icon.c b/src/xfdesktop-regular-file-icon.c
index 9d7e41f..b57de9f 100644
--- a/src/xfdesktop-regular-file-icon.c
+++ b/src/xfdesktop-regular-file-icon.c
@@ -212,21 +212,55 @@ xfdesktop_regular_file_icon_peek_pixbuf(XfdesktopIcon *icon,
gint size)
{
XfdesktopRegularFileIcon *file_icon = XFDESKTOP_REGULAR_FILE_ICON(icon);
- const gchar *icon_name = NULL;
+ gchar *icon_name = NULL;
GdkPixbuf *emblem_pix = NULL;
-
+
if(size != file_icon->priv->cur_pix_size)
xfdesktop_regular_file_icon_invalidate_pixbuf(file_icon);
-
+
if(!file_icon->priv->pix) {
- /* check the application's binary name like thunar does (bug 1956) */
- if(!file_icon->priv->pix
- && file_icon->priv->info->flags & THUNAR_VFS_FILE_FLAGS_EXECUTABLE)
- {
- icon_name = thunar_vfs_path_get_name(file_icon->priv->info->path);
+ /* 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)) {
+ gchar *contents;
+ gsize length;
+
+ /* try to load the file into memory */
+ if(g_file_load_contents(file_icon->priv->file, NULL, &contents, &length,
+ NULL, NULL))
+ {
+ /* allocate a new key file */
+ GKeyFile *key_file = g_key_file_new();
+
+ /* try to parse the key file from the contents of the file */
+ if (g_key_file_load_from_data(key_file, contents, length, 0, NULL)) {
+ /* try to determine the custom icon name */
+ icon_name = g_key_file_get_string(key_file,
+ G_KEY_FILE_DESKTOP_GROUP,
+ G_KEY_FILE_DESKTOP_KEY_ICON,
+ NULL);
+ }
+
+ /* free key file and in-memory data */
+ g_key_file_free(key_file);
+ g_free(contents);
+ }
}
-
- if(file_icon->priv->info->flags & THUNAR_VFS_FILE_FLAGS_SYMLINK) {
+
+ /* 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))
+ {
GtkIconTheme *itheme = gtk_icon_theme_get_default();
gint sym_pix_size = size * 2 / 3;
@@ -241,22 +275,23 @@ xfdesktop_regular_file_icon_peek_pixbuf(XfdesktopIcon *icon,
sym_pix_size,
sym_pix_size,
GDK_INTERP_BILINEAR);
- g_object_unref(G_OBJECT(emblem_pix));
+ g_object_unref(emblem_pix);
emblem_pix = tmp;
}
}
}
- file_icon->priv->pix = xfdesktop_file_utils_get_file_icon(icon_name,
- file_icon->priv->info,
- size,
- emblem_pix,
+ file_icon->priv->pix = xfdesktop_file_utils_get_file_icon(icon_name,
+ file_icon->priv->file_info,
+ size, emblem_pix,
file_icon->priv->pix_opacity);
+ file_icon->priv->cur_pix_size = size;
+
if(emblem_pix)
- g_object_unref(G_OBJECT(emblem_pix));
+ g_object_unref(emblem_pix);
- file_icon->priv->cur_pix_size = size;
+ g_free(icon_name);
}
return file_icon->priv->pix;
diff --git a/src/xfdesktop-special-file-icon.c b/src/xfdesktop-special-file-icon.c
index 18342d7..86e8735 100644
--- a/src/xfdesktop-special-file-icon.c
+++ b/src/xfdesktop-special-file-icon.c
@@ -232,32 +232,17 @@ xfdesktop_special_file_icon_peek_pixbuf(XfdesktopIcon *icon,
if(!file_icon->priv->pix) {
const gchar *custom_icon_name = NULL;
- GtkIconTheme *icon_theme = gtk_icon_theme_get_for_screen(file_icon->priv->gscreen);
-
- if(XFDESKTOP_SPECIAL_FILE_ICON_HOME == file_icon->priv->type) {
- if(gtk_icon_theme_has_icon(icon_theme, "user-home"))
- custom_icon_name = "user-home";
- else if(gtk_icon_theme_has_icon(icon_theme, "gnome-fs-desktop"))
- custom_icon_name = "gnome-fs-desktop";
- } else if(XFDESKTOP_SPECIAL_FILE_ICON_TRASH == file_icon->priv->type) {
- if(file_icon->priv->trash_full) {
- if(gtk_icon_theme_has_icon(icon_theme, "user-trash-full"))
- custom_icon_name = "user-trash-full";
- else if(gtk_icon_theme_has_icon(icon_theme, "gnome-fs-trash-full"))
- custom_icon_name = "gnome-fs-trash-full";
- } else {
- if(gtk_icon_theme_has_icon(icon_theme, "user-trash"))
- custom_icon_name = "user-trash";
- else if(gtk_icon_theme_has_icon(icon_theme, "gnome-fs-trash-empty"))
- custom_icon_name = "gnome-fs-trash-empty";
- }
- }
+
+ /* use a custom icon name for the local filesystem root */
+ GFile *parent = g_file_get_parent(file_icon->priv->file);
+ if(!parent && g_file_has_uri_scheme(file_icon->priv->file, "file"))
+ custom_icon_name = "drive-harddisk";
+ if(parent)
+ g_object_unref(parent);
file_icon->priv->pix = xfdesktop_file_utils_get_file_icon(custom_icon_name,
- file_icon->priv->info,
- size,
- NULL,
- 100);
+ file_icon->priv->file_info,
+ size, NULL, 100);
file_icon->priv->cur_pix_size = size;
}
@@ -764,7 +749,7 @@ xfdesktop_special_file_icon_new(XfdesktopSpecialFileIconType type,
{
XfdesktopSpecialFileIcon *special_file_icon;
ThunarVfsPath *path = NULL;
- gchar *pathname;
+ gchar *uri;
switch(type) {
case XFDESKTOP_SPECIAL_FILE_ICON_FILESYSTEM:
@@ -790,9 +775,9 @@ xfdesktop_special_file_icon_new(XfdesktopSpecialFileIconType type,
thunar_vfs_path_unref(path);
/* convert the ThunarVfsPath into a GFile */
- pathname = thunar_vfs_path_dup_string(special_file_icon->priv->info->path);
- special_file_icon->priv->file = g_file_new_for_path(pathname);
- g_free(pathname);
+ uri = thunar_vfs_path_dup_uri(special_file_icon->priv->info->path);
+ special_file_icon->priv->file = g_file_new_for_uri(uri);
+ g_free(uri);
/* query file information from GIO */
special_file_icon->priv->file_info = g_file_query_info(special_file_icon->priv->file,
diff --git a/src/xfdesktop-volume-icon.c b/src/xfdesktop-volume-icon.c
index 107e092..1f443ec 100644
--- a/src/xfdesktop-volume-icon.c
+++ b/src/xfdesktop-volume-icon.c
@@ -241,16 +241,14 @@ xfdesktop_volume_icon_peek_pixbuf(XfdesktopIcon *icon,
if(size != file_icon->priv->cur_pix_size)
xfdesktop_volume_icon_invalidate_pixbuf(file_icon);
-
+
if(!file_icon->priv->pix) {
icon_name = thunar_vfs_volume_lookup_icon_name(file_icon->priv->volume,
gtk_icon_theme_get_default());
- file_icon->priv->pix = xfdesktop_file_utils_get_file_icon(icon_name,
- file_icon->priv->info,
- size,
- NULL,
- 100);
+ file_icon->priv->pix = xfdesktop_file_utils_get_file_icon(icon_name,
+ file_icon->priv->file_info,
+ size, NULL, 100);
file_icon->priv->cur_pix_size = size;
}
More information about the Xfce4-commits
mailing list