Commit a60e2aa8 authored by Alexander Larsson's avatar Alexander Larsson Committed by Alexander Larsson

Avoid crashing if not enough items in icon view caption pref (#357955)

2007-01-31  Alexander Larsson  <alexl@redhat.com>

	* src/nautilus-file-management-properties.c (update_icon_captions_from_gconf):
	Avoid crashing if not enough items in icon view caption pref (#357955)

	* src/file-manager/fm-icon-container.c (fm_icon_container_get_icon_text):
	Avoid spewing warnings in above case, also some performance fixes.	


svn path=/trunk/; revision=12711
parent 018994b7
2007-01-31 Alexander Larsson <alexl@redhat.com>
* src/nautilus-file-management-properties.c (update_icon_captions_from_gconf):
Avoid crashing if not enough items in icon view caption pref (#357955)
* src/file-manager/fm-icon-container.c (fm_icon_container_get_icon_text):
Avoid spewing warnings in above case, also some performance fixes.
2007-01-25 Luca Ferretti <elle.uca@libero.it> 2007-01-25 Luca Ferretti <elle.uca@libero.it>
* nautilus-file-management-properties.desktop.in.in: * nautilus-file-management-properties.desktop.in.in:
......
...@@ -168,7 +168,7 @@ fm_icon_container_prioritize_thumbnailing (NautilusIconContainer *container, ...@@ -168,7 +168,7 @@ fm_icon_container_prioritize_thumbnailing (NautilusIconContainer *container,
* Get the preference for which caption text should appear * Get the preference for which caption text should appear
* beneath icons. * beneath icons.
*/ */
static EelStringList * static const EelStringList *
fm_icon_container_get_icon_text_attributes_from_preferences (void) fm_icon_container_get_icon_text_attributes_from_preferences (void)
{ {
static const EelStringList *attributes; static const EelStringList *attributes;
...@@ -178,11 +178,6 @@ fm_icon_container_get_icon_text_attributes_from_preferences (void) ...@@ -178,11 +178,6 @@ fm_icon_container_get_icon_text_attributes_from_preferences (void)
&attributes); &attributes);
} }
/* A simple check that the attributes list matches the expected length */
g_return_val_if_fail (eel_string_list_get_length (attributes) == ICON_TEXT_ATTRIBUTES_NUM_ITEMS,
eel_string_list_new_from_tokens (ICON_TEXT_ATTRIBUTES_DEFAULT_TOKENS, ",", TRUE));
/* We don't need to sanity check the attributes list even though it came /* We don't need to sanity check the attributes list even though it came
* from preferences. * from preferences.
* *
...@@ -207,27 +202,25 @@ fm_icon_container_get_icon_text_attributes_from_preferences (void) ...@@ -207,27 +202,25 @@ fm_icon_container_get_icon_text_attributes_from_preferences (void)
* with the preference. * with the preference.
* *
* So, no more error checking on attributes is needed here and we can return * So, no more error checking on attributes is needed here and we can return
* a copy of the auto stored value. * a the auto stored value.
*/ */
return eel_string_list_copy (attributes); return attributes;
} }
/** /**
* fm_icon_view_get_icon_text_attribute_names: * fm_icon_view_get_icon_text_attribute_names:
* *
* Get a string representing which text attributes should be displayed * Get a list representing which text attributes should be displayed
* beneath an icon. The result is dependent on zoom level and possibly * beneath an icon. The result is dependent on zoom level and possibly
* user configuration. Use g_free to free the result. * user configuration. Don't free the result.
* @view: FMIconView to query. * @view: FMIconView to query.
* *
* Return value: A |-delimited string comprising attribute names, e.g. "name|size".
*
**/ **/
static char * static const EelStringList *
fm_icon_container_get_icon_text_attribute_names (NautilusIconContainer *container) fm_icon_container_get_icon_text_attribute_names (NautilusIconContainer *container,
int *len)
{ {
EelStringList *attributes; const EelStringList *attributes;
char *result;
int piece_count; int piece_count;
const int pieces_by_level[] = { const int pieces_by_level[] = {
...@@ -243,12 +236,10 @@ fm_icon_container_get_icon_text_attribute_names (NautilusIconContainer *containe ...@@ -243,12 +236,10 @@ fm_icon_container_get_icon_text_attribute_names (NautilusIconContainer *containe
piece_count = pieces_by_level[nautilus_icon_container_get_zoom_level (container)]; piece_count = pieces_by_level[nautilus_icon_container_get_zoom_level (container)];
attributes = fm_icon_container_get_icon_text_attributes_from_preferences (); attributes = fm_icon_container_get_icon_text_attributes_from_preferences ();
g_return_val_if_fail ((guint)piece_count <= eel_string_list_get_length (attributes), NULL);
result = eel_string_list_as_string (attributes, "|", piece_count); *len = MIN (piece_count, eel_string_list_get_length (attributes));
eel_string_list_free (attributes);
return result; return attributes;
} }
/* This callback returns the text, both the editable part, and the /* This callback returns the text, both the editable part, and the
...@@ -262,10 +253,10 @@ fm_icon_container_get_icon_text (NautilusIconContainer *container, ...@@ -262,10 +253,10 @@ fm_icon_container_get_icon_text (NautilusIconContainer *container,
{ {
char *actual_uri; char *actual_uri;
gchar *description; gchar *description;
char *attribute_names; const EelStringList *attribute_names;
char **text_array; const char *attribute;
int i , slot_index; char *text_array[4];
char *attribute_string; int i, j, num_attributes;
FMIconView *icon_view; FMIconView *icon_view;
NautilusFile *file; NautilusFile *file;
...@@ -310,40 +301,25 @@ fm_icon_container_get_icon_text (NautilusIconContainer *container, ...@@ -310,40 +301,25 @@ fm_icon_container_get_icon_text (NautilusIconContainer *container,
} }
/* Find out what attributes go below each icon. */ /* Find out what attributes go below each icon. */
attribute_names = fm_icon_container_get_icon_text_attribute_names (container); attribute_names = fm_icon_container_get_icon_text_attribute_names (container, &num_attributes);
text_array = g_strsplit (attribute_names, "|", 0);
g_free (attribute_names);
/* Get the attributes. */ /* Get the attributes. */
for (i = 0; text_array[i] != NULL; i++) { for (i = 0, j = 0; i < num_attributes; i++) {
/* if the attribute is "none", delete the array slot */ attribute = eel_string_list_peek_nth (attribute_names, i);
while (eel_strcmp (text_array[i], "none") == 0) { if (eel_strcmp (attribute, "none") == 0) {
g_free (text_array[i]); continue;
text_array[i] = NULL;
slot_index = i + 1;
while (text_array[slot_index] != NULL) {
text_array[slot_index - 1] = text_array[slot_index];
text_array[slot_index++] = NULL;
} }
if (text_array[i] == NULL) text_array[j++] =
break; nautilus_file_get_string_attribute_with_default (file, attribute);
}
if (text_array[i] == NULL)
break;
attribute_string = nautilus_file_get_string_attribute_with_default
(file, text_array[i]);
/* Replace each attribute name in the array with its string value */
g_free (text_array[i]);
text_array[i] = attribute_string;
} }
text_array[j] = NULL;
/* Return them. */ /* Return them. */
*additional_text = g_strjoinv ("\n", text_array); *additional_text = g_strjoinv ("\n", text_array);
g_strfreev (text_array); for (i = 0; i < j; i++) {
g_free(text_array[i]);
}
} }
/* Sort as follows: /* Sort as follows:
......
...@@ -392,16 +392,23 @@ update_icon_captions_from_gconf (GladeXML *xml) ...@@ -392,16 +392,23 @@ update_icon_captions_from_gconf (GladeXML *xml)
GList *captions; GList *captions;
int i; int i;
GList *l; GList *l;
char *data;
captions = eel_preferences_get_string_glist (NAUTILUS_PREFERENCES_ICON_VIEW_CAPTIONS); captions = eel_preferences_get_string_glist (NAUTILUS_PREFERENCES_ICON_VIEW_CAPTIONS);
for (l = captions, i = 0; for (l = captions, i = 0;
captions != NULL && icon_captions_components[i] != NULL; icon_captions_components[i] != NULL;
l = l->next, i++) { i++) {
if (l != NULL) {
data = l->data;
l = l->next;
} else {
data = "none";
}
update_caption_combo_box (xml, update_caption_combo_box (xml,
icon_captions_components[i], icon_captions_components[i],
(char *)l->data); data);
} }
eel_g_list_free_deep (captions); eel_g_list_free_deep (captions);
} }
......
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