Commit 61d09c72 authored by Cosimo Cecchi's avatar Cosimo Cecchi

all: compute emblem names to ignore automatically

Consolidate identical code that builds a list of emblems to ignore
inside nautilus_file_get_emblem_icons()
parent 7cf92f0d
......@@ -6413,15 +6413,16 @@ nautilus_file_is_launchable (NautilusFile *file)
*
**/
GList *
nautilus_file_get_emblem_icons (NautilusFile *file,
char **exclude)
nautilus_file_get_emblem_icons (NautilusFile *file)
{
NautilusFile *parent_file;
GList *keywords, *l;
GList *icons;
char *icon_names[2];
char *exclude[3];
char *keyword;
int i;
GIcon *icon;
int i;
if (file == NULL) {
return NULL;
......@@ -6429,20 +6430,28 @@ nautilus_file_get_emblem_icons (NautilusFile *file,
g_return_val_if_fail (NAUTILUS_IS_FILE (file), NULL);
i = 0;
parent_file = nautilus_file_get_parent (file);
exclude[i++] = NAUTILUS_FILE_EMBLEM_NAME_TRASH;
if (parent_file) {
if (!nautilus_file_can_write (parent_file)) {
exclude[i++] = NAUTILUS_FILE_EMBLEM_NAME_CANT_WRITE;
}
nautilus_file_unref (parent_file);
}
exclude[i++] = NULL;
keywords = nautilus_file_get_keywords (file);
keywords = prepend_automatic_keywords (file, keywords);
icons = NULL;
for (l = keywords; l != NULL; l = l->next) {
keyword = l->data;
if (exclude) {
for (i = 0; exclude[i] != NULL; i++) {
if (strcmp (exclude[i], keyword) == 0) {
continue;
}
for (i = 0; exclude[i] != NULL; i++) {
if (strcmp (exclude[i], keyword) == 0) {
continue;
}
}
}
icon_names[0] = g_strconcat ("emblem-", keyword, NULL);
icon_names[1] = keyword;
......
......@@ -206,8 +206,7 @@ gboolean nautilus_file_should_show_thumbnail (Nautilu
gboolean nautilus_file_should_show_directory_item_count (NautilusFile *file);
gboolean nautilus_file_should_show_type (NautilusFile *file);
GList * nautilus_file_get_keywords (NautilusFile *file);
GList * nautilus_file_get_emblem_icons (NautilusFile *file,
char **exclude);
GList * nautilus_file_get_emblem_icons (NautilusFile *file);
char * nautilus_file_get_top_left_text (NautilusFile *file);
char * nautilus_file_peek_top_left_text (NautilusFile *file,
gboolean need_large_text,
......
......@@ -59,7 +59,6 @@ nautilus_icon_view_container_get_icon_images (NautilusIconContainer *container,
gboolean *has_window_open)
{
NautilusIconView *icon_view;
char **emblems_to_ignore;
NautilusFile *file;
gboolean use_embedding;
NautilusFileIconFlags flags;
......@@ -99,13 +98,8 @@ nautilus_icon_view_container_get_icon_images (NautilusIconContainer *container,
flags |= NAUTILUS_FILE_ICON_FLAGS_FOR_DRAG_ACCEPT;
}
emblems_to_ignore = nautilus_view_get_emblem_names_to_exclude
(NAUTILUS_VIEW (icon_view));
emblem_icons = nautilus_file_get_emblem_icons (file,
emblems_to_ignore);
g_strfreev (emblems_to_ignore);
icon_info = nautilus_file_get_icon (file, size, flags);
emblem_icons = nautilus_file_get_emblem_icons (file);
/* apply emblems */
if (emblem_icons != NULL) {
......
......@@ -255,9 +255,6 @@ nautilus_list_model_get_value (GtkTreeModel *tree_model, GtkTreeIter *iter, int
GList *emblem_icons, *l;
int icon_size;
NautilusZoomLevel zoom_level;
NautilusFile *parent_file;
char *emblems_to_ignore[3];
int i;
NautilusFileIconFlags flags;
model = (NautilusListModel *)tree_model;
......@@ -314,21 +311,7 @@ nautilus_list_model_get_value (GtkTreeModel *tree_model, GtkTreeIter *iter, int
}
gicon = G_ICON (nautilus_file_get_icon_pixbuf (file, icon_size, TRUE, flags));
/* render emblems with GEmblemedIcon */
parent_file = nautilus_file_get_parent (file);
i = 0;
emblems_to_ignore[i++] = NAUTILUS_FILE_EMBLEM_NAME_TRASH;
if (parent_file) {
if (!nautilus_file_can_write (parent_file)) {
emblems_to_ignore[i++] = NAUTILUS_FILE_EMBLEM_NAME_CANT_WRITE;
}
nautilus_file_unref (parent_file);
}
emblems_to_ignore[i++] = NULL;
emblem_icons = nautilus_file_get_emblem_icons (file,
emblems_to_ignore);
emblem_icons = nautilus_file_get_emblem_icons (file);
/* pick only the first emblem we can render for the list view */
for (l = emblem_icons; l != NULL; l = l->next) {
......
......@@ -273,26 +273,12 @@ get_menu_icon_for_file (TreeNode *node,
int size;
FMTreeModel *model;
GList *emblem_icons, *l;
char *emblems_to_ignore[3];
int i;
size = nautilus_get_icon_size_for_stock_size (GTK_ICON_SIZE_MENU);
gicon = G_ICON (nautilus_file_get_icon_pixbuf (file, size, TRUE, flags));
i = 0;
emblems_to_ignore[i++] = NAUTILUS_FILE_EMBLEM_NAME_TRASH;
if (node->parent && node->parent->file) {
if (!nautilus_file_can_write (node->parent->file)) {
emblems_to_ignore[i++] = NAUTILUS_FILE_EMBLEM_NAME_CANT_WRITE;
}
}
emblems_to_ignore[i++] = NULL;
emblem = NULL;
emblem_icons = nautilus_file_get_emblem_icons (node->file,
emblems_to_ignore);
emblem_icons = nautilus_file_get_emblem_icons (node->file);
/* pick only the first emblem we can render for the tree view */
for (l = emblem_icons; l != NULL; l = l->next) {
......
......@@ -676,28 +676,6 @@ nautilus_view_scroll_to_file (NautilusView *view,
NAUTILUS_VIEW_CLASS (G_OBJECT_GET_CLASS (view))->scroll_to_file (view, uri);
}
char **
nautilus_view_get_emblem_names_to_exclude (NautilusView *view)
{
char **excludes;
int i;
g_assert (NAUTILUS_IS_VIEW (view));
excludes = g_new (char *, 3);
i = 0;
excludes[i++] = g_strdup (NAUTILUS_FILE_EMBLEM_NAME_TRASH);
if (!nautilus_file_can_write (view->details->directory_as_file)) {
excludes[i++] = g_strdup (NAUTILUS_FILE_EMBLEM_NAME_CANT_WRITE);
}
excludes[i++] = NULL;
return excludes;
}
/**
* nautilus_view_get_selection:
*
......
......@@ -390,7 +390,6 @@ void nautilus_view_load_location (NautilusView *v
GFile *location);
void nautilus_view_stop_loading (NautilusView *view);
char ** nautilus_view_get_emblem_names_to_exclude (NautilusView *view);
char * nautilus_view_get_first_visible_file (NautilusView *view);
void nautilus_view_scroll_to_file (NautilusView *view,
const char *uri);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment