From 5223f971790ac6af46099e2ad2d3eb787a6fb729 Mon Sep 17 00:00:00 2001 From: Eric Koegel Date: Fri, 9 Dec 2011 16:31:40 +0300 Subject: [PATCH] Added an emblem to the icon to show when a volume is mounted. --- src/xfdesktop-volume-icon.c | 71 +++++++++++++++++++++++++++++++------------ 1 files changed, 51 insertions(+), 20 deletions(-) diff --git a/src/xfdesktop-volume-icon.c b/src/xfdesktop-volume-icon.c index 01a5570..62920b6 100644 --- a/src/xfdesktop-volume-icon.c +++ b/src/xfdesktop-volume-icon.c @@ -56,6 +56,8 @@ #include "xfdesktop-file-utils.h" #include "xfdesktop-volume-icon.h" +#define XFDESKTOP_VOLUME_MOUNTED_EMBLEM "emblem-generic" + struct _XfdesktopVolumeIconPrivate { GdkPixbuf *pix; @@ -224,12 +226,32 @@ xfdesktop_volume_icon_invalidate_pixbuf(XfdesktopVolumeIcon *icon) } } +static gboolean +xfdesktop_volume_icon_is_mounted(XfdesktopIcon *icon) +{ + GVolume *volume; + GMount *mount; + gboolean ret; + XfdesktopVolumeIcon *volume_icon = XFDESKTOP_VOLUME_ICON(icon); + + volume = xfdesktop_volume_icon_peek_volume(volume_icon); + mount = g_volume_get_mount(volume); + if(mount) { + ret = TRUE; + } else { + ret = FALSE; + } + + g_object_unref(mount); + return ret; +} static GdkPixbuf * xfdesktop_volume_icon_peek_pixbuf(XfdesktopIcon *icon, gint size) { XfdesktopVolumeIcon *file_icon = XFDESKTOP_VOLUME_ICON(icon); + GdkPixbuf *emblem_pix = NULL; g_return_val_if_fail(XFDESKTOP_IS_VOLUME_ICON(icon), NULL); @@ -242,12 +264,38 @@ xfdesktop_volume_icon_peek_pixbuf(XfdesktopIcon *icon, if(file_icon->priv->volume) gicon = g_volume_get_icon(file_icon->priv->volume); + /* load the mounted emblem if necessary */ + if(xfdesktop_volume_icon_is_mounted(icon)) + { + GtkIconTheme *itheme = gtk_icon_theme_get_default(); + gint sym_pix_size = size * 2 / 3; + + emblem_pix = gtk_icon_theme_load_icon(itheme, XFDESKTOP_VOLUME_MOUNTED_EMBLEM, + sym_pix_size, ITHEME_FLAGS, + NULL); + if(emblem_pix) { + if(gdk_pixbuf_get_width(emblem_pix) != sym_pix_size + || gdk_pixbuf_get_height(emblem_pix) != sym_pix_size) + { + GdkPixbuf *tmp = gdk_pixbuf_scale_simple(emblem_pix, + sym_pix_size, + sym_pix_size, + GDK_INTERP_BILINEAR); + g_object_unref(emblem_pix); + emblem_pix = tmp; + } + } + } + file_icon->priv->pix = xfdesktop_file_utils_get_icon(NULL, gicon, size, - NULL, 100); + emblem_pix, 100); file_icon->priv->cur_pix_size = size; } + if(emblem_pix) + g_object_unref(emblem_pix); + return file_icon->priv->pix; } @@ -268,10 +316,6 @@ xfdesktop_volume_icon_peek_label(XfdesktopIcon *icon) static GdkDragAction xfdesktop_volume_icon_get_allowed_drag_actions(XfdesktopIcon *icon) { - XfdesktopVolumeIcon *volume_icon = XFDESKTOP_VOLUME_ICON(icon); - GVolume *volume; - GMount *mount; - /* volume icons more or less represent the volume's mount point, usually * (hopefully) a local path. so when it's mounted, we certainly can't move * the mount point, but copying and linking should be OK. when not mounted, @@ -281,10 +325,7 @@ xfdesktop_volume_icon_get_allowed_drag_actions(XfdesktopIcon *icon) /* FIXME: should i allow all actions if not mounted as well, and try to * mount and resolve on drop? */ - volume = xfdesktop_volume_icon_peek_volume(volume_icon); - - mount = g_volume_get_mount(volume); - if(mount) { + if(xfdesktop_volume_icon_is_mounted(icon)) { GFileInfo *info = xfdesktop_file_icon_peek_file_info(XFDESKTOP_FILE_ICON(icon)); if(info) { if(g_file_info_get_attribute_boolean(info, G_FILE_ATTRIBUTE_ACCESS_CAN_READ)) @@ -292,8 +333,6 @@ xfdesktop_volume_icon_get_allowed_drag_actions(XfdesktopIcon *icon) else return GDK_ACTION_LINK; } - - g_object_unref(mount); } return 0; @@ -302,26 +341,18 @@ xfdesktop_volume_icon_get_allowed_drag_actions(XfdesktopIcon *icon) static GdkDragAction xfdesktop_volume_icon_get_allowed_drop_actions(XfdesktopIcon *icon) { - XfdesktopVolumeIcon *volume_icon = XFDESKTOP_VOLUME_ICON(icon); - GVolume *volume; - GMount *mount; - /* if not mounted, it doesn't really make sense to allow any operations * here. if mounted, we should allow everything if it's writable. */ /* FIXME: should i allow all actions if not mounted as well, and try to * mount and resolve on drop? */ - volume = xfdesktop_volume_icon_peek_volume(volume_icon); - - mount = g_volume_get_mount(volume); - if(mount) { + if(xfdesktop_volume_icon_is_mounted(icon)) { GFileInfo *info = xfdesktop_file_icon_peek_file_info(XFDESKTOP_FILE_ICON(icon)); if(info) { if(g_file_info_get_attribute_boolean(info, G_FILE_ATTRIBUTE_ACCESS_CAN_WRITE)) return GDK_ACTION_MOVE | GDK_ACTION_COPY | GDK_ACTION_LINK; } - g_object_unref(mount); } return 0; -- 1.7.5.4