From eb1623a8c930746536a6119be9b30cecc6bf782d Mon Sep 17 00:00:00 2001 From: Jasmine Hassan Date: Thu, 18 Oct 2012 21:12:07 +0200 Subject: [tree-model] use GEmblemedIcon to render emblems. Use GEmblemedIcon instead of a separate column to render emblems. http://git.gnome.org/browse/nautilus/commit/?id=1694d7141bbe4a29e54cff77def697a6c9b4e118 --- src/file-manager/fm-tree-model.c | 135 ++++++++++++++------------------------- src/file-manager/fm-tree-model.h | 1 - 2 files changed, 49 insertions(+), 87 deletions(-) (limited to 'src/file-manager') diff --git a/src/file-manager/fm-tree-model.c b/src/file-manager/fm-tree-model.c index 15071b8c..c7bcab10 100644 --- a/src/file-manager/fm-tree-model.c +++ b/src/file-manager/fm-tree-model.c @@ -67,7 +67,6 @@ struct TreeNode GMount *mount; GdkPixbuf *closed_pixbuf; GdkPixbuf *open_pixbuf; - GdkPixbuf *emblem_pixbuf; FMTreeModelRoot *root; @@ -221,7 +220,6 @@ tree_node_destroy (FMTreeModel *model, TreeNode *node) object_unref_if_not_NULL (node->icon); object_unref_if_not_NULL (node->closed_pixbuf); object_unref_if_not_NULL (node->open_pixbuf); - object_unref_if_not_NULL (node->emblem_pixbuf); g_assert (node->done_loading_id == 0); g_assert (node->files_added_id == 0); @@ -278,17 +276,63 @@ get_menu_icon_for_file (TreeNode *node, CajaFileIconFlags flags) { CajaIconInfo *info; + GIcon *gicon, *emblem_icon, *emblemed_icon; + GEmblem *emblem; GdkPixbuf *pixbuf, *retval; gboolean highlight; int size; FMTreeModel *model; + GList *emblem_icons, *l; + char *emblems_to_ignore[3]; + int i; size = caja_get_icon_size_for_stock_size (GTK_ICON_SIZE_MENU); - info = caja_file_get_icon (file, size, flags); + gicon = caja_file_get_gicon (file, flags); + + i = 0; + emblems_to_ignore[i++] = CAJA_FILE_EMBLEM_NAME_TRASH; + + if (node->parent && node->parent->file) { + if (!caja_file_can_write (node->parent->file)) { + emblems_to_ignore[i++] = CAJA_FILE_EMBLEM_NAME_CANT_WRITE; + } + } + + emblems_to_ignore[i++] = NULL; + + emblem = NULL; + emblem_icons = caja_file_get_emblem_icons (node->file, + emblems_to_ignore); + + if (emblem_icons != NULL) { + emblem_icon = emblem_icons->data; + emblem = g_emblem_new (emblem_icon); + emblemed_icon = g_emblemed_icon_new (gicon, emblem); + + g_object_unref (emblem); + + for (l = emblem_icons->next; l != NULL; l = l->next) { + emblem_icon = l->data; + emblem = g_emblem_new (emblem_icon); + g_emblemed_icon_add_emblem + (G_EMBLEMED_ICON (emblemed_icon), emblem); + + g_object_unref (emblem); + } + + eel_g_object_list_free (emblem_icons); + + g_object_unref (gicon); + gicon = emblemed_icon; + } + + info = caja_icon_info_lookup (gicon, size); retval = caja_icon_info_get_pixbuf_nodefault_at_size (info, size); model = node->root->model; + g_object_unref (gicon); + highlight = (g_list_find_custom (model->details->highlighted_files, file, (GCompareFunc) caja_file_compare_location) != NULL); @@ -353,67 +397,6 @@ tree_node_update_open_pixbuf (TreeNode *node) return tree_node_update_pixbuf (node, &node->open_pixbuf, CAJA_FILE_ICON_FLAGS_FOR_OPEN_FOLDER); } -static GdkPixbuf * -tree_node_get_emblem_pixbuf_internal (TreeNode *node) -{ - GdkPixbuf *pixbuf; - GList *emblem_pixbufs; - char *emblems_to_ignore[3]; - int i; - - i = 0; - emblems_to_ignore[i++] = CAJA_FILE_EMBLEM_NAME_TRASH; - - if (node->parent && node->parent->file) - { - if (!caja_file_can_write (node->parent->file)) - { - emblems_to_ignore[i++] = CAJA_FILE_EMBLEM_NAME_CANT_WRITE; - } - } - - emblems_to_ignore[i++] = NULL; - - emblem_pixbufs = caja_file_get_emblem_pixbufs (node->file, - caja_get_icon_size_for_stock_size (GTK_ICON_SIZE_MENU), - TRUE, - emblems_to_ignore); - - - if (emblem_pixbufs != NULL) - { - pixbuf = g_object_ref (emblem_pixbufs->data); - } - else - { - pixbuf = NULL; - } - - eel_gdk_pixbuf_list_free (emblem_pixbufs); - - return pixbuf; -} - -static gboolean -tree_node_update_emblem_pixbuf (TreeNode *node) -{ - GdkPixbuf *pixbuf; - - if (node->emblem_pixbuf == NULL) - { - return FALSE; - } - pixbuf = tree_node_get_emblem_pixbuf_internal (node); - if (pixbuf == node->emblem_pixbuf) - { - g_object_unref (pixbuf); - return FALSE; - } - g_object_unref (node->emblem_pixbuf); - node->emblem_pixbuf = pixbuf; - return TRUE; -} - static gboolean tree_node_update_display_name (TreeNode *node) { @@ -459,16 +442,6 @@ tree_node_get_open_pixbuf (TreeNode *node) return node->open_pixbuf; } -static GdkPixbuf * -tree_node_get_emblem_pixbuf (TreeNode *node) -{ - if (node->emblem_pixbuf == NULL) - { - node->emblem_pixbuf = tree_node_get_emblem_pixbuf_internal (node); - } - return node->emblem_pixbuf; -} - static const char * tree_node_get_display_name (TreeNode *node) { @@ -919,7 +892,6 @@ update_node_without_reporting (FMTreeModel *model, TreeNode *node) changed |= tree_node_update_display_name (node); changed |= tree_node_update_closed_pixbuf (node); changed |= tree_node_update_open_pixbuf (node); - changed |= tree_node_update_emblem_pixbuf (node); return changed; } @@ -1244,8 +1216,6 @@ fm_tree_model_get_column_type (GtkTreeModel *model, int index) return GDK_TYPE_PIXBUF; case FM_TREE_MODEL_OPEN_PIXBUF_COLUMN: return GDK_TYPE_PIXBUF; - case FM_TREE_MODEL_EMBLEM_PIXBUF_COLUMN: - return GDK_TYPE_PIXBUF; case FM_TREE_MODEL_FONT_STYLE_COLUMN: return PANGO_TYPE_STYLE; default: @@ -1412,18 +1382,11 @@ fm_tree_model_get_value (GtkTreeModel *model, GtkTreeIter *iter, int column, GVa g_value_init (value, GDK_TYPE_PIXBUF); g_value_set_object (value, node == NULL ? NULL : tree_node_get_open_pixbuf (node)); break; - case FM_TREE_MODEL_EMBLEM_PIXBUF_COLUMN: - g_value_init (value, GDK_TYPE_PIXBUF); - g_value_set_object (value, node == NULL ? NULL : tree_node_get_emblem_pixbuf (node)); - break; case FM_TREE_MODEL_FONT_STYLE_COLUMN: g_value_init (value, PANGO_TYPE_STYLE); - if (node == NULL) - { + if (node == NULL) { g_value_set_enum (value, PANGO_STYLE_ITALIC); - } - else - { + } else { g_value_set_enum (value, PANGO_STYLE_NORMAL); } break; diff --git a/src/file-manager/fm-tree-model.h b/src/file-manager/fm-tree-model.h index bfca06e4..2e459392 100644 --- a/src/file-manager/fm-tree-model.h +++ b/src/file-manager/fm-tree-model.h @@ -49,7 +49,6 @@ enum FM_TREE_MODEL_DISPLAY_NAME_COLUMN, FM_TREE_MODEL_CLOSED_PIXBUF_COLUMN, FM_TREE_MODEL_OPEN_PIXBUF_COLUMN, - FM_TREE_MODEL_EMBLEM_PIXBUF_COLUMN, FM_TREE_MODEL_FONT_STYLE_COLUMN, FM_TREE_MODEL_NUM_COLUMNS }; -- cgit v1.2.1