GitLab repository storage has been migrated to hashed layout. Please contact Infrastructure team if you notice any issues with repositories or hooks.

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>
* nautilus-file-management-properties.desktop.in.in:
......
......@@ -168,7 +168,7 @@ fm_icon_container_prioritize_thumbnailing (NautilusIconContainer *container,
* Get the preference for which caption text should appear
* beneath icons.
*/
static EelStringList *
static const EelStringList *
fm_icon_container_get_icon_text_attributes_from_preferences (void)
{
static const EelStringList *attributes;
......@@ -178,11 +178,6 @@ fm_icon_container_get_icon_text_attributes_from_preferences (void)
&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
* from preferences.
*
......@@ -207,27 +202,25 @@ fm_icon_container_get_icon_text_attributes_from_preferences (void)
* with the preference.
*
* 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:
*
* 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
* user configuration. Use g_free to free the result.
* user configuration. Don't free the result.
* @view: FMIconView to query.
*
* Return value: A |-delimited string comprising attribute names, e.g. "name|size".
*
**/
static char *
fm_icon_container_get_icon_text_attribute_names (NautilusIconContainer *container)
static const EelStringList *
fm_icon_container_get_icon_text_attribute_names (NautilusIconContainer *container,
int *len)
{
EelStringList *attributes;
char *result;
const EelStringList *attributes;
int piece_count;
const int pieces_by_level[] = {
......@@ -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)];
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);
eel_string_list_free (attributes);
*len = MIN (piece_count, eel_string_list_get_length (attributes));
return result;
return attributes;
}
/* This callback returns the text, both the editable part, and the
......@@ -262,10 +253,10 @@ fm_icon_container_get_icon_text (NautilusIconContainer *container,
{
char *actual_uri;
gchar *description;
char *attribute_names;
char **text_array;
int i , slot_index;
char *attribute_string;
const EelStringList *attribute_names;
const char *attribute;
char *text_array[4];
int i, j, num_attributes;
FMIconView *icon_view;
NautilusFile *file;
......@@ -310,40 +301,25 @@ fm_icon_container_get_icon_text (NautilusIconContainer *container,
}
/* Find out what attributes go below each icon. */
attribute_names = fm_icon_container_get_icon_text_attribute_names (container);
text_array = g_strsplit (attribute_names, "|", 0);
g_free (attribute_names);
attribute_names = fm_icon_container_get_icon_text_attribute_names (container, &num_attributes);
/* Get the attributes. */
for (i = 0; text_array[i] != NULL; i++) {
/* if the attribute is "none", delete the array slot */
while (eel_strcmp (text_array[i], "none") == 0) {
g_free (text_array[i]);
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;
for (i = 0, j = 0; i < num_attributes; i++) {
attribute = eel_string_list_peek_nth (attribute_names, i);
if (eel_strcmp (attribute, "none") == 0) {
continue;
}
if (text_array[i] == NULL)
break;
}
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++] =
nautilus_file_get_string_attribute_with_default (file, attribute);
}
text_array[j] = NULL;
/* Return them. */
*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:
......
......@@ -392,16 +392,23 @@ update_icon_captions_from_gconf (GladeXML *xml)
GList *captions;
int i;
GList *l;
char *data;
captions = eel_preferences_get_string_glist (NAUTILUS_PREFERENCES_ICON_VIEW_CAPTIONS);
for (l = captions, i = 0;
captions != NULL && icon_captions_components[i] != NULL;
l = l->next, i++) {
icon_captions_components[i] != NULL;
i++) {
if (l != NULL) {
data = l->data;
l = l->next;
} else {
data = "none";
}
update_caption_combo_box (xml,
icon_captions_components[i],
(char *)l->data);
data);
}
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