Skip to content

Commit

Permalink
Improve ui_get_mime_icon()
Browse files Browse the repository at this point in the history
It may happen that even though we get GIcon, the actual icon dosen't exist (typically on Windows and OS X). Check if we can find the actual icon.

In addition, use "icon name" instead of "stock id" - the latter doesn't work on OS X / Windows for some reason.
  • Loading branch information
techee committed Dec 30, 2014
1 parent 6748e08 commit 7880c0f
Showing 1 changed file with 17 additions and 3 deletions.
20 changes: 17 additions & 3 deletions src/ui_utils.c
Expand Up @@ -2893,18 +2893,32 @@ GIcon *ui_get_mime_icon(const gchar *mime_type)
if (ctype)
{
icon = g_content_type_get_icon(ctype);
if (icon)
{
GtkIconInfo *icon_info;

icon_info = gtk_icon_theme_lookup_by_gicon(gtk_icon_theme_get_default(), icon, 16, 0);
if (!icon_info)
{
g_object_unref(icon);
icon = NULL;
}
else
gtk_icon_info_free(icon_info);
}

This comment has been minimized.

Copy link
@b4n

b4n Dec 30, 2014

Hum… what is the problem with a non-NULL but non-working GIcon? does it render something like broken icon instead of not rendering anything at all?

This comment has been minimized.

Copy link
@techee

techee via email Dec 31, 2014

Author Owner
g_free(ctype);
}

/* fallback if icon lookup failed, like it might happen on Windows (?) */
if (! icon)
{
const gchar *stock_id = GTK_STOCK_FILE;
const gchar *icon_name = "text-x-generic";

if (strstr(mime_type, "directory"))
stock_id = GTK_STOCK_DIRECTORY;
icon_name = "folder";

This comment has been minimized.

Copy link
@b4n

b4n Dec 30, 2014

I have no idea about the availability of those names, maybe we should triple check this not to break something by fixing another :)

This comment has been minimized.

Copy link
@techee

techee via email Dec 31, 2014

Author Owner

This comment has been minimized.

Copy link
@b4n

b4n Jan 3, 2015

I just tested with a Debian 6.0 (Squeeze, GTK 2.20, GLib 2.24) VM, and it seems to work OK. I had to force use of the fallback as the icons we request were found, but the new fallbacks were available just fine too.

We should probably check on Windows with GTK 2.16, and if it works there we probably can go ahead and apply this patch.

This comment has been minimized.

Copy link
@kugel-

kugel- Feb 11, 2015

We officially only support 2.24 these days no?

This comment has been minimized.

Copy link
@b4n

b4n Feb 11, 2015

not yet, but I think there was some plan or agreement to bump to it


icon = g_themed_icon_new(stock_id);
icon = g_themed_icon_new(icon_name);
}
return icon;
}
Expand Down

2 comments on commit 7880c0f

@b4n
Copy link

@b4n b4n commented on 7880c0f Dec 30, 2014

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

72 columns in commit messages is better ;)

@techee
Copy link
Owner Author

@techee techee commented on 7880c0f Dec 31, 2014 via email

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.