[PATCH] Don't crash when some image data is not installed



The attached patch ensures that Nautilus doesn't crash when some image
data is not installed, but tries to continue without image data.
This mainly refers to lack of the pattern chit in the emblems, color and
pattern browser.

It also adds code for giving g_debug output when a pixmap couldn't be
located, adds g_asserts where neccessary and fixes a
nautilus_customization_make_pattern_chit refcount oddity. The function
used to unref the first inarg for no obvious reason.


-- 
Christian Neumair <chris gnome-de org>
Index: libnautilus-private/nautilus-customization-data.c
===================================================================
RCS file: /cvs/gnome/nautilus/libnautilus-private/nautilus-customization-data.c,v
retrieving revision 1.34
diff -u -p -r1.34 nautilus-customization-data.c
--- libnautilus-private/nautilus-customization-data.c	18 Mar 2006 07:13:48 -0000	1.34
+++ libnautilus-private/nautilus-customization-data.c	6 Oct 2006 14:07:46 -0000
@@ -130,16 +130,17 @@ nautilus_customization_data_new (const c
 		data->current_file_list = data->public_file_list;
 	}
 
+	data->pattern_frame = NULL;
+
 	/* load the frame if necessary */
 	if (strcmp (customization_name, "patterns") == 0) {
 		temp_str = nautilus_pixmap_file ("chit_frame.png");
-		data->pattern_frame = gdk_pixbuf_new_from_file (temp_str, NULL);
+		if (temp_str != NULL) {
+			data->pattern_frame = gdk_pixbuf_new_from_file (temp_str, NULL);
+		}
 		g_free (temp_str);
-	} else {
-		data->pattern_frame = NULL;
 	}
 
-	
 	data->private_data_was_displayed = FALSE;
 	data->data_is_for_a_menu = data_is_for_a_menu;
 	data->customization_name = g_strdup (customization_name);
@@ -223,15 +224,17 @@ nautilus_customization_data_get_next_ele
 	is_reset_image = eel_strcmp(current_file_info->name, RESET_IMAGE_NAME) == 0;
 
 	*emblem_name = g_strdup (current_file_info->name);
-	
-	if (strcmp (data->customization_name, "patterns") == 0) {
+
+	if (strcmp (data->customization_name, "patterns") == 0 &&
+	    data->pattern_frame != NULL) {
 		pixbuf = nautilus_customization_make_pattern_chit (orig_pixbuf, data->pattern_frame, FALSE, is_reset_image);
 	} else {
 		pixbuf = eel_gdk_pixbuf_scale_down_to_fit (orig_pixbuf, 
 							   data->maximum_icon_width, 
 							   data->maximum_icon_height);
-		g_object_unref (orig_pixbuf);
 	}
+
+	g_object_unref (orig_pixbuf);
 	
 	*pixbuf_out = pixbuf;
 	
@@ -360,8 +363,10 @@ nautilus_customization_make_pattern_chit
 	GdkPixbuf *pixbuf, *temp_pixbuf;
 	int frame_width, frame_height;
 	int pattern_width, pattern_height;
-	
-	
+
+	g_assert (pattern_tile != NULL);
+	g_assert (frame != NULL);
+
 	frame_width = gdk_pixbuf_get_width (frame);
 	frame_height = gdk_pixbuf_get_height (frame);
 	pattern_width = gdk_pixbuf_get_width (pattern_tile);
@@ -385,8 +390,6 @@ nautilus_customization_make_pattern_chit
 		g_object_unref (pixbuf);
 		pixbuf = temp_pixbuf;
 	}
-			      
-	g_object_unref (pattern_tile);
 
 	return pixbuf;
 }
Index: libnautilus-private/nautilus-file-utilities.c
===================================================================
RCS file: /cvs/gnome/nautilus/libnautilus-private/nautilus-file-utilities.c,v
retrieving revision 1.134
diff -u -p -r1.134 nautilus-file-utilities.c
--- libnautilus-private/nautilus-file-utilities.c	23 Aug 2006 09:07:16 -0000	1.134
+++ libnautilus-private/nautilus-file-utilities.c	6 Oct 2006 14:07:53 -0000
@@ -414,6 +414,11 @@ nautilus_pixmap_file (const char *partia
 	path = g_build_filename (DATADIR "/pixmaps/nautilus", partial_path, NULL);
 	if (g_file_test (path, G_FILE_TEST_EXISTS)) {
 		return path;
+	} else {
+		char *tmp;
+		tmp = nautilus_get_pixmap_directory ();
+		g_debug ("Failed to locate \"%s\" in Nautilus pixmap path \"%s\". Incomplete installation?", partial_path, tmp);
+		g_free (tmp);
 	}
 	g_free (path);
 	return NULL;
Index: src/nautilus-emblem-sidebar.c
===================================================================
RCS file: /cvs/gnome/nautilus/src/nautilus-emblem-sidebar.c,v
retrieving revision 1.9
diff -u -p -r1.9 nautilus-emblem-sidebar.c
--- src/nautilus-emblem-sidebar.c	16 Jun 2006 15:40:18 -0000	1.9
+++ src/nautilus-emblem-sidebar.c	6 Oct 2006 14:08:12 -0000
@@ -926,9 +926,12 @@ nautilus_emblem_sidebar_populate (Nautil
 	char *path;
 	GdkPixbuf *erase_pixbuf;
 
-	
+	erase_pixbuf = NULL;
+
 	path = nautilus_pixmap_file ("erase.png");
-	erase_pixbuf = gdk_pixbuf_new_from_file (path, NULL);
+	if (path != NULL) {
+		erase_pixbuf = gdk_pixbuf_new_from_file (path, NULL);
+	}
 	g_free (path);
 
 	if (erase_pixbuf != NULL) {
Index: src/nautilus-property-browser.c
===================================================================
RCS file: /cvs/gnome/nautilus/src/nautilus-property-browser.c,v
retrieving revision 1.219
diff -u -p -r1.219 nautilus-property-browser.c
--- src/nautilus-property-browser.c	16 Jun 2006 15:40:18 -0000	1.219
+++ src/nautilus-property-browser.c	6 Oct 2006 14:08:17 -0000
@@ -266,7 +266,9 @@ nautilus_property_browser_init (GtkObjec
 		
 	/* load the chit frame */
 	temp_str = nautilus_pixmap_file ("chit_frame.png");
-	property_browser->details->property_chit = gdk_pixbuf_new_from_file (temp_str, NULL);
+	if (temp_str != NULL) {
+		property_browser->details->property_chit = gdk_pixbuf_new_from_file (temp_str, NULL);
+	}
 	g_free (temp_str);
 	
 	/* set the initial size of the property browser */
@@ -742,8 +744,12 @@ make_drag_image (NautilusPropertyBrowser
 
 	if (property_browser->details->category_type == NAUTILUS_PROPERTY_EMBLEM) {
 		if (strcmp (file_name, "erase") == 0) {
+			pixbuf = NULL;
+
 			image_file_name = nautilus_pixmap_file (ERASE_OBJECT_NAME);
-			pixbuf = gdk_pixbuf_new_from_file (image_file_name, NULL);
+			if (image_file_name != NULL) {
+				pixbuf = gdk_pixbuf_new_from_file (image_file_name, NULL);
+			}
 			g_free (image_file_name);
 		} else {
 			icon_name = nautilus_emblem_get_icon_name_from_keyword (file_name);
@@ -790,13 +796,15 @@ make_drag_image (NautilusPropertyBrowser
 	
 	is_reset = eel_strcmp (file_name, RESET_IMAGE_NAME) == 0;
 	
-	if (strcmp (property_browser->details->category, "patterns") == 0) {
+	if (strcmp (property_browser->details->category, "patterns") == 0 &&
+	    property_browser->details->property_chit != NULL) {
 		pixbuf = nautilus_customization_make_pattern_chit (orig_pixbuf, property_browser->details->property_chit, TRUE, is_reset);
 	} else {
 		pixbuf = eel_gdk_pixbuf_scale_down_to_fit (orig_pixbuf, MAX_ICON_WIDTH, MAX_ICON_HEIGHT);
-		g_object_unref (orig_pixbuf);
 	}
 
+	gdk_pixbuf_unref (orig_pixbuf);
+
 	return pixbuf;
 }
 
@@ -807,6 +815,7 @@ static GdkPixbuf*
 make_color_drag_image (NautilusPropertyBrowser *property_browser, const char *color_spec, gboolean trim_edges)
 {
 	GdkPixbuf *color_square;
+	GdkPixbuf *ret;
 	int row, col, stride;
 	char *pixels, *row_pixels;
 	GdkColor color;
@@ -831,10 +840,19 @@ make_color_drag_image (NautilusPropertyB
 			*row_pixels++ = 255;
 		}
 	}
-	
-	return nautilus_customization_make_pattern_chit (color_square, 
-							    property_browser->details->property_chit,
-							    trim_edges, FALSE);	
+
+	g_assert (color_square != NULL);
+
+	if (property_browser->details->property_chit != NULL) {
+		ret = nautilus_customization_make_pattern_chit (color_square, 
+								property_browser->details->property_chit,
+								trim_edges, FALSE);
+		gdk_pixbuf_unref (color_square);
+	} else {
+		ret = color_square;
+	}
+
+	return ret;
 }
 
 /* this callback handles button presses on the category widget. It maintains the active state */
@@ -1730,7 +1748,9 @@ make_properties_from_directories (Nautil
 					
 			g_free (object_name);
 			g_free (object_label);
-			g_object_unref (object_pixbuf);
+			if (object_pixbuf != NULL) {
+				g_object_unref (object_pixbuf);
+			}
 		}
 		eel_g_list_free_deep (icons);
 		property_browser->details->has_local = FALSE;
@@ -1766,7 +1786,9 @@ make_properties_from_directories (Nautil
 			
 			g_free (object_name);
 			g_free (object_label);
-			g_object_unref (object_pixbuf);
+			if (object_pixbuf != NULL) {
+				g_object_unref (object_pixbuf);
+			}
 		}
 		
 		property_browser->details->has_local = nautilus_customization_data_private_data_was_displayed (customization_data);	
@@ -1788,12 +1810,15 @@ make_properties_from_directories (Nautil
 					      num_images - 1);
 		
 		gtk_widget_show (blank);
-		
+
+		object_pixbuf = NULL;
+
 		path = nautilus_pixmap_file (ERASE_OBJECT_NAME);
-		object_pixbuf = gdk_pixbuf_new_from_file (path, NULL);
+		if (path != NULL) {
+			object_pixbuf = gdk_pixbuf_new_from_file (path, NULL);
+		}
 		g_free (path);
 		property_image = labeled_image_new (_("Erase"), object_pixbuf, "erase", PANGO_SCALE_LARGE);
-		g_object_unref (object_pixbuf);
 		eel_labeled_image_set_fixed_image_height (EEL_LABELED_IMAGE (property_image), MAX_EMBLEM_HEIGHT);
 
 		gtk_container_add (GTK_CONTAINER (image_table), property_image);
@@ -1801,6 +1826,10 @@ make_properties_from_directories (Nautil
 	
 		eel_wrap_table_reorder_child (EEL_WRAP_TABLE (image_table),
 					      property_image, -1);
+
+		if (object_pixbuf != NULL) {
+			g_object_unref (object_pixbuf);
+		}
 	}
 
 	/*
@@ -1823,18 +1852,30 @@ add_reset_property (NautilusPropertyBrow
 	GtkWidget *reset_image;
 	GdkPixbuf *reset_pixbuf, *reset_chit;
 
+	reset_chit = NULL;
+
 	reset_image_file_name = g_strdup_printf ("%s/%s/%s", NAUTILUS_DATADIR, "patterns", RESET_IMAGE_NAME);
 	reset_pixbuf = gdk_pixbuf_new_from_file (reset_image_file_name, NULL);
-	reset_chit = nautilus_customization_make_pattern_chit (reset_pixbuf, property_browser->details->property_chit, FALSE, TRUE);
+	if (reset_pixbuf != NULL && property_browser->details->property_chit != NULL) {
+		reset_chit = nautilus_customization_make_pattern_chit (reset_pixbuf, property_browser->details->property_chit, FALSE, TRUE);
+	}
 	
 	g_free (reset_image_file_name);
 
-	reset_image = labeled_image_new ("Reset", reset_chit, RESET_IMAGE_NAME, PANGO_SCALE_MEDIUM);
+	reset_image = labeled_image_new ("Reset", reset_chit != NULL ? reset_chit : reset_pixbuf, RESET_IMAGE_NAME, PANGO_SCALE_MEDIUM);
 	gtk_container_add (GTK_CONTAINER (property_browser->details->content_table), reset_image);
 	eel_wrap_table_reorder_child (EEL_WRAP_TABLE (property_browser->details->content_table),
 					   reset_image,
 					   0);
 	gtk_widget_show (reset_image);
+
+	if (reset_pixbuf != NULL) {
+		g_object_unref (reset_pixbuf);
+	}
+
+	if (reset_chit != NULL) {
+		g_object_unref (reset_chit);
+	}
 }
 	
 /* generate properties from the children of the passed in node */
@@ -1935,9 +1976,11 @@ property_browser_category_button_new (co
 	g_return_val_if_fail (image != NULL, NULL);
 
 	file_name = nautilus_pixmap_file (image); 
-	g_return_val_if_fail (file_name != NULL, NULL);
-
-	button = eel_labeled_image_radio_button_new_from_file_name (display_name, file_name);
+	if (file_name != NULL) {
+		button = eel_labeled_image_radio_button_new_from_file_name (display_name, file_name);
+	} else {
+		button = eel_labeled_image_radio_button_new (display_name, NULL);
+	}
 
 	gtk_toggle_button_set_mode (GTK_TOGGLE_BUTTON (button), FALSE);
 


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]