diff options
author | FichteFoll <fichtefoll2@googlemail.com> | 2019-05-08 06:02:29 +0200 |
---|---|---|
committer | FichteFoll <fichtefoll2@googlemail.com> | 2019-05-08 14:50:16 +0200 |
commit | 05f30ad62a00288e903bb29b683ebaba748c9ad6 (patch) | |
tree | c528965dd863d7f0f9c2521948305b42a32359cb /dragon.c | |
parent | Remove deprecated gtk_button_set_alignment call (diff) | |
download | dragon-05f30ad62a00288e903bb29b683ebaba748c9ad6.tar.gz dragon-05f30ad62a00288e903bb29b683ebaba748c9ad6.tar.bz2 dragon-05f30ad62a00288e903bb29b683ebaba748c9ad6.zip |
Add fallback to generic icons
If the current theme doesn't have an icon for our file, try a few
generic mimetypes instead.
Diffstat (limited to 'dragon.c')
-rw-r--r-- | dragon.c | 13 |
1 files changed, 13 insertions, 0 deletions
@@ -136,6 +136,11 @@ GtkButton *add_button(char *label, struct draggable_thing *dragdata, int type) { return (GtkButton *)button; } +GtkIconInfo* icon_info_from_content_type(char *content_type) { + GIcon *icon = g_content_type_get_icon(content_type); + return gtk_icon_theme_lookup_by_gicon(icon_theme, icon, 48, 0); +} + void add_file_button(char *filename) { GFile *file = g_file_new_for_path(filename); if(!g_file_query_exists(file, NULL)) { @@ -147,11 +152,19 @@ void add_file_button(char *filename) { struct draggable_thing *dragdata = malloc(sizeof(struct draggable_thing)); dragdata->text = filename; dragdata->uri = uri; + GtkButton *button = add_button(filename, dragdata, TARGET_TYPE_URI); GFileInfo *fileinfo = g_file_query_info(file, "*", 0, NULL, NULL); GIcon *icon = g_file_info_get_icon(fileinfo); GtkIconInfo *icon_info = gtk_icon_theme_lookup_by_gicon(icon_theme, icon, 48, 0); + // Try a few fallback mimetypes if no icon can be found + if (!icon_info) + icon_info = icon_info_from_content_type("application/octet-stream"); + if (!icon_info) + icon_info = icon_info_from_content_type("text/x-generic"); + if (!icon_info) + icon_info = icon_info_from_content_type("text/plain"); if (icon_info) { GtkWidget *image = gtk_image_new_from_pixbuf( |