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 ++++++++++++++------------------------- 1 file changed, 49 insertions(+), 86 deletions(-) (limited to 'src/file-manager/fm-tree-model.c') 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; -- cgit v1.2.1 From f170ef87e7968633dd4fb3e166e2e2ff0cfbba70 Mon Sep 17 00:00:00 2001 From: Jasmine Hassan Date: Thu, 18 Oct 2012 21:48:25 +0200 Subject: [tree-model] ony display the first emblem Only display the first emblem we can render. http://git.gnome.org/browse/nautilus/commit/?id=1d660252b408f3628a2d3d5943abcf6bfdd9091b --- src/file-manager/fm-tree-model.c | 29 ++++++++++++----------------- 1 file changed, 12 insertions(+), 17 deletions(-) (limited to 'src/file-manager/fm-tree-model.c') diff --git a/src/file-manager/fm-tree-model.c b/src/file-manager/fm-tree-model.c index c7bcab10..3a3e3604 100644 --- a/src/file-manager/fm-tree-model.c +++ b/src/file-manager/fm-tree-model.c @@ -298,35 +298,30 @@ get_menu_icon_for_file (TreeNode *node, 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; + /* pick only the first emblem we can render for the tree view */ + for (l = emblem_icons; l != NULL; l = l->next) { + emblem_icon = l->data; + if (caja_icon_theme_can_render (G_THEMED_ICON (emblem_icon))) { emblem = g_emblem_new (emblem_icon); - g_emblemed_icon_add_emblem - (G_EMBLEMED_ICON (emblemed_icon), emblem); + emblemed_icon = g_emblemed_icon_new (gicon, emblem); + g_object_unref (gicon); g_object_unref (emblem); - } + gicon = emblemed_icon; - eel_g_object_list_free (emblem_icons); - - g_object_unref (gicon); - gicon = emblemed_icon; + break; + } } + eel_g_object_list_free (emblem_icons); + info = caja_icon_info_lookup (gicon, size); retval = caja_icon_info_get_pixbuf_nodefault_at_size (info, size); model = node->root->model; -- cgit v1.2.1 From 7a42b9b076d6b831c89bd0b9e996368c1c95aef3 Mon Sep 17 00:00:00 2001 From: Jasmine Hassan Date: Thu, 18 Oct 2012 10:30:31 +0200 Subject: [all] use g_list_free() and g_strcmp0 instead of eel functions Was: general: use g_list_free_full() instead of eel functions http://git.gnome.org/browse/nautilus/commit/?id=5e669515fd7f760382e6b7aa1449734a35a2d7f4 . Instead of g_list_free_full(), we use g_list_foreach and g_list_free() to avoid unnecessary glib dependency bump to 2.28 --- src/file-manager/fm-tree-model.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'src/file-manager/fm-tree-model.c') diff --git a/src/file-manager/fm-tree-model.c b/src/file-manager/fm-tree-model.c index 3a3e3604..3423e2d1 100644 --- a/src/file-manager/fm-tree-model.c +++ b/src/file-manager/fm-tree-model.c @@ -29,7 +29,6 @@ #include #include "fm-tree-model.h" -#include #include #include #include @@ -320,7 +319,8 @@ get_menu_icon_for_file (TreeNode *node, } } - eel_g_object_list_free (emblem_icons); + g_list_foreach (emblem_icons, (GFunc) g_object_unref, NULL); + g_list_free(emblem_icons); info = caja_icon_info_lookup (gicon, size); retval = caja_icon_info_get_pixbuf_nodefault_at_size (info, size); -- cgit v1.2.1