static GdkPixbuf * get_menu_icon_for_file (TreeNode *node, NemoFile *file, NemoFileIconFlags flags) { NemoIconInfo *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 = nemo_get_icon_size_for_stock_size (GTK_ICON_SIZE_MENU); gicon = G_ICON (nemo_file_get_icon_pixbuf (file, size, TRUE, flags)); i = 0; emblems_to_ignore[i++] = NEMO_FILE_EMBLEM_NAME_TRASH; if (node->parent && node->parent->file) { if (!nemo_file_can_write (node->parent->file)) { emblems_to_ignore[i++] = NEMO_FILE_EMBLEM_NAME_CANT_WRITE; } } emblems_to_ignore[i++] = NULL; emblem = NULL; emblem_icons = nemo_file_get_emblem_icons (node->file, emblems_to_ignore); /* 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 (nemo_icon_theme_can_render (G_THEMED_ICON (emblem_icon))) { emblem = g_emblem_new (emblem_icon); emblemed_icon = g_emblemed_icon_new (gicon, emblem); g_object_unref (gicon); g_object_unref (emblem); gicon = emblemed_icon; break; } } g_list_free_full (emblem_icons, g_object_unref); info = nemo_icon_info_lookup (gicon, size); retval = nemo_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) nemo_file_compare_location) != NULL); if (highlight) { pixbuf = eel_create_spotlight_pixbuf (retval); if (pixbuf != NULL) { g_object_unref (retval); retval = pixbuf; } } g_object_unref (info); return retval; }
static NemoIconInfo * nemo_icon_view_container_get_icon_images (NemoIconContainer *container, NemoIconData *data, int size, char **embedded_text, gboolean for_drag_accept, gboolean need_large_embeddded_text, gboolean *embedded_text_needs_loading, gboolean *has_window_open) { NemoIconView *icon_view; char **emblems_to_ignore; NemoFile *file; NemoFileIconFlags flags; NemoIconInfo *icon_info; GdkPixbuf *pixbuf; GIcon *emblemed_icon; GEmblem *emblem; GList *emblem_icons, *l; gint scale; file = (NemoFile *) data; g_assert (NEMO_IS_FILE (file)); icon_view = get_icon_view (container); g_return_val_if_fail (icon_view != NULL, NULL); *has_window_open = nemo_file_has_open_window (file); flags = NEMO_FILE_ICON_FLAGS_USE_MOUNT_ICON_AS_EMBLEM | NEMO_FILE_ICON_FLAGS_USE_THUMBNAILS; if (for_drag_accept) { flags |= NEMO_FILE_ICON_FLAGS_FOR_DRAG_ACCEPT; } emblems_to_ignore = nemo_view_get_emblem_names_to_exclude (NEMO_VIEW (icon_view)); emblem_icons = nemo_file_get_emblem_icons (file, emblems_to_ignore); g_strfreev (emblems_to_ignore); scale = gtk_widget_get_scale_factor (GTK_WIDGET (icon_view)); icon_info = nemo_file_get_icon (file, size, scale, flags); /* apply emblems */ if (emblem_icons != NULL) { l = emblem_icons; pixbuf = nemo_icon_info_get_pixbuf (icon_info); gint w, h, s; gboolean bad_ratio; w = gdk_pixbuf_get_width (pixbuf); h = gdk_pixbuf_get_height (pixbuf); s = MAX (w, h); if (s < size) size = s; bad_ratio = nemo_icon_get_emblem_size_for_icon_size (size) * scale > w || nemo_icon_get_emblem_size_for_icon_size (size) * scale > h; if (bad_ratio) goto skip_emblem; /* Would prefer to not use goto, but * I don't want to do these checks on * non-emblemed icons (the majority) * as it would be too costly */ emblem = g_emblem_new (l->data); emblemed_icon = g_emblemed_icon_new (G_ICON (pixbuf), emblem); g_object_unref (emblem); for (l = l->next; l != NULL; l = l->next) { emblem = g_emblem_new (l->data); g_emblemed_icon_add_emblem (G_EMBLEMED_ICON (emblemed_icon), emblem); g_object_unref (emblem); } g_clear_object (&icon_info); icon_info = nemo_icon_info_lookup (emblemed_icon, size, scale); g_object_unref (emblemed_icon); skip_emblem: g_object_unref (pixbuf); } if (emblem_icons != NULL) { g_list_free_full (emblem_icons, g_object_unref); } return icon_info; }
static void nemo_list_model_get_value (GtkTreeModel *tree_model, GtkTreeIter *iter, int column, GValue *value) { NemoListModel *model; FileEntry *file_entry; NemoFile *file; char *str; GdkPixbuf *icon, *rendered_icon; GIcon *gicon, *emblemed_icon, *emblem_icon; NemoIconInfo *icon_info; GEmblem *emblem; GList *emblem_icons, *l; int icon_size; NemoZoomLevel zoom_level; NemoFile *parent_file; char *emblems_to_ignore[3]; int i; NemoFileIconFlags flags; model = (NemoListModel *)tree_model; g_return_if_fail (model->details->stamp == iter->stamp); g_return_if_fail (!g_sequence_iter_is_end (iter->user_data)); file_entry = g_sequence_get (iter->user_data); file = file_entry->file; switch (column) { case NEMO_LIST_MODEL_FILE_COLUMN: g_value_init (value, NEMO_TYPE_FILE); g_value_set_object (value, file); break; case NEMO_LIST_MODEL_SUBDIRECTORY_COLUMN: g_value_init (value, NEMO_TYPE_DIRECTORY); g_value_set_object (value, file_entry->subdirectory); break; case NEMO_LIST_MODEL_SMALLEST_ICON_COLUMN: case NEMO_LIST_MODEL_SMALLER_ICON_COLUMN: case NEMO_LIST_MODEL_SMALL_ICON_COLUMN: case NEMO_LIST_MODEL_STANDARD_ICON_COLUMN: case NEMO_LIST_MODEL_LARGE_ICON_COLUMN: case NEMO_LIST_MODEL_LARGER_ICON_COLUMN: case NEMO_LIST_MODEL_LARGEST_ICON_COLUMN: g_value_init (value, GDK_TYPE_PIXBUF); if (file != NULL) { zoom_level = nemo_list_model_get_zoom_level_from_column_id (column); icon_size = nemo_get_icon_size_for_zoom_level (zoom_level); flags = NEMO_FILE_ICON_FLAGS_USE_THUMBNAILS | NEMO_FILE_ICON_FLAGS_FORCE_THUMBNAIL_SIZE | NEMO_FILE_ICON_FLAGS_USE_MOUNT_ICON_AS_EMBLEM; if (model->details->drag_view != NULL) { GtkTreePath *path_a, *path_b; gtk_tree_view_get_drag_dest_row (model->details->drag_view, &path_a, NULL); if (path_a != NULL) { path_b = gtk_tree_model_get_path (tree_model, iter); if (gtk_tree_path_compare (path_a, path_b) == 0) { flags |= NEMO_FILE_ICON_FLAGS_FOR_DRAG_ACCEPT; } gtk_tree_path_free (path_a); gtk_tree_path_free (path_b); } } gicon = G_ICON (nemo_file_get_icon_pixbuf (file, icon_size, TRUE, flags)); /* render emblems with GEmblemedIcon */ parent_file = nemo_file_get_parent (file); i = 0; emblems_to_ignore[i++] = NEMO_FILE_EMBLEM_NAME_TRASH; if (parent_file) { if (!nemo_file_can_write (parent_file)) { emblems_to_ignore[i++] = NEMO_FILE_EMBLEM_NAME_CANT_WRITE; } nemo_file_unref (parent_file); } emblems_to_ignore[i++] = NULL; emblem_icons = nemo_file_get_emblem_icons (file, emblems_to_ignore); /* pick only the first emblem we can render for the list view */ for (l = emblem_icons; l != NULL; l = l->next) { emblem_icon = l->data; if (nemo_icon_theme_can_render (G_THEMED_ICON (emblem_icon))) { emblem = g_emblem_new (emblem_icon); emblemed_icon = g_emblemed_icon_new (gicon, emblem); g_object_unref (gicon); g_object_unref (emblem); gicon = emblemed_icon; break; } } g_list_free_full (emblem_icons, g_object_unref); icon_info = nemo_icon_info_lookup (gicon, icon_size); icon = nemo_icon_info_get_pixbuf_at_size (icon_info, icon_size); g_object_unref (icon_info); g_object_unref (gicon); if (model->details->highlight_files != NULL && g_list_find_custom (model->details->highlight_files, file, (GCompareFunc) nemo_file_compare_location)) { rendered_icon = eel_create_spotlight_pixbuf (icon); if (rendered_icon != NULL) { g_object_unref (icon); icon = rendered_icon; } } g_value_set_object (value, icon); g_object_unref (icon); } break; case NEMO_LIST_MODEL_FILE_NAME_IS_EDITABLE_COLUMN: g_value_init (value, G_TYPE_BOOLEAN); g_value_set_boolean (value, file != NULL && nemo_file_can_rename (file)); break; default: if (column >= NEMO_LIST_MODEL_NUM_COLUMNS || column < NEMO_LIST_MODEL_NUM_COLUMNS + model->details->columns->len) { NemoColumn *nemo_column; GQuark attribute; nemo_column = model->details->columns->pdata[column - NEMO_LIST_MODEL_NUM_COLUMNS]; g_value_init (value, G_TYPE_STRING); g_object_get (nemo_column, "attribute_q", &attribute, NULL); if (file != NULL) { str = nemo_file_get_string_attribute_with_default_q (file, attribute); g_value_take_string (value, str); } else if (attribute == attribute_name_q) { if (file_entry->parent->loaded) { g_value_set_string (value, _("(Empty)")); } else { g_value_set_string (value, _("Loading...")); } } } else { g_assert_not_reached (); } } }