Index: nautilus-throbber.c
===================================================================
RCS file: /cvs/gnome/nautilus/components/throbber/nautilus-throbber.c,v
retrieving revision 1.35
diff -u -r1.35 nautilus-throbber.c
--- nautilus-throbber.c	23 Apr 2003 09:49:36 -0000	1.35
+++ nautilus-throbber.c	27 May 2003 20:32:47 -0000
@@ -46,7 +46,6 @@
 #include <libnautilus-private/nautilus-file-utilities.h>
 #include <libnautilus-private/nautilus-global-preferences.h>
 #include <libnautilus-private/nautilus-icon-factory.h>
-#include <libnautilus-private/nautilus-theme.h>
 
 #define THROBBER_DEFAULT_TIMEOUT 100	/* Milliseconds Per Frame */
 
@@ -54,13 +53,13 @@
 	BonoboObject *control;
 	BonoboPropertyBag *property_bag;
 	GList	*image_list;
+	GnomeIconTheme *icon_theme;
 
-	GdkPixbuf *quiescent_pixbuf;
-	
-	int	max_frame;
+	int     max_frame;
 	int	delay;
 	int	current_frame;	
 	guint	timer_task;
+	int     base_size;
 	
 	gboolean ready;
 	gboolean small_mode;
@@ -69,7 +68,8 @@
 
 static void nautilus_throbber_load_images            (NautilusThrobber *throbber);
 static void nautilus_throbber_unload_images          (NautilusThrobber *throbber);
-static void nautilus_throbber_theme_changed          (gpointer          user_data);
+static void nautilus_throbber_theme_changed          (GnomeIconTheme   *icon_theme,
+						      NautilusThrobber *throbber);
 static void nautilus_throbber_remove_update_callback (NautilusThrobber *throbber);
 static AtkObject *nautilus_throbber_get_accessible   (GtkWidget *widget);
 
@@ -158,46 +158,9 @@
 	return throbber->details->control;
 }
 
-/* loop through all the images taking their union to compute the width and height of the throbber */
-static void
-get_throbber_dimensions (NautilusThrobber *throbber, int *throbber_width, int* throbber_height)
-{
-	int current_width, current_height;
-	int pixbuf_width, pixbuf_height;
-	GList *current_entry;
-	GdkPixbuf *pixbuf;
-	
-	/* start with the quiescent image */
-	current_width = gdk_pixbuf_get_width (throbber->details->quiescent_pixbuf);
-	current_height = gdk_pixbuf_get_height (throbber->details->quiescent_pixbuf);
-
-	/* loop through all the installed images, taking the union */
-	current_entry = throbber->details->image_list;
-	while (current_entry != NULL) {	
-		pixbuf = GDK_PIXBUF (current_entry->data);
-		pixbuf_width = gdk_pixbuf_get_width (pixbuf);
-		pixbuf_height = gdk_pixbuf_get_height (pixbuf);
-		
-		if (pixbuf_width > current_width) {
-			current_width = pixbuf_width;
-		}
-		
-		if (pixbuf_height > current_height) {
-			current_height = pixbuf_height;
-		}
-		
-		current_entry = current_entry->next;
-	}
-		
-	/* return the result */
-	*throbber_width = current_width;
-	*throbber_height = current_height;
-}
-
 static void
 nautilus_throbber_instance_init (NautilusThrobber *throbber)
 {
-	char *delay_str;
 	GtkWidget *widget = GTK_WIDGET (throbber);
 	
 	
@@ -210,16 +173,14 @@
 	
 	throbber->details = g_new0 (NautilusThrobberDetails, 1);
 	
-	/* set up the delay from the theme */
-	delay_str = nautilus_theme_get_theme_data ("throbber", "delay");
-	
-	if (delay_str) {
-		throbber->details->delay = atoi (delay_str);
-		g_free (delay_str);
-	} else {
-		throbber->details->delay = THROBBER_DEFAULT_TIMEOUT;		
-	}
+	throbber->details->delay = THROBBER_DEFAULT_TIMEOUT;
 	
+	throbber->details->icon_theme = gnome_icon_theme_new ();
+	g_signal_connect (throbber->details->icon_theme,
+			  "changed",
+			  G_CALLBACK (nautilus_throbber_theme_changed),
+			  throbber);
+
 	/* make the bonobo control */
 	throbber->details->control = BONOBO_OBJECT (bonobo_control_new (widget));
 	eel_add_weak_pointer (&throbber->details->control);
@@ -236,20 +197,12 @@
 				 Bonobo_PROPERTY_WRITEABLE);
 	nautilus_throbber_load_images (throbber);
 	gtk_widget_show (widget);
-
-	/* add a callback for when the theme changes */
-	eel_preferences_add_callback (NAUTILUS_PREFERENCES_THEME,
-				      nautilus_throbber_theme_changed,
-				      throbber);
 }
 
 /* handler for handling theme changes */
 static void
-nautilus_throbber_theme_changed (gpointer user_data)
+nautilus_throbber_theme_changed (GnomeIconTheme *icon_theme, NautilusThrobber *throbber)
 {
-	NautilusThrobber *throbber;
-
-	throbber = NAUTILUS_THROBBER (user_data);
 	gtk_widget_hide (GTK_WIDGET (throbber));
 	nautilus_throbber_load_images (throbber);
 	gtk_widget_show (GTK_WIDGET (throbber));	
@@ -263,16 +216,17 @@
 {
 	GList *element;
 
-	if (throbber->details->timer_task == 0) {
-		return g_object_ref (throbber->details->quiescent_pixbuf);
-	}
-	
 	if (throbber->details->image_list == NULL) {
 		return NULL;
 	}
 
-	element = g_list_nth (throbber->details->image_list, throbber->details->current_frame);
-	
+	if (throbber->details->timer_task == 0) {
+		element = throbber->details->image_list;
+	}
+	else {
+		element = g_list_nth (throbber->details->image_list, throbber->details->current_frame);
+	}
+
 	return g_object_ref (element->data);
 }
 
@@ -350,9 +304,11 @@
 	}
 
 	throbber->details->current_frame += 1;
-	if (throbber->details->current_frame > throbber->details->max_frame - 1) {
+
+	if (throbber->details->current_frame > throbber->details->max_frame - 1)
+	{
 		throbber->details->current_frame = 0;
-	}
+        }
 
 	gtk_widget_queue_draw (GTK_WIDGET (throbber));
 	return TRUE;
@@ -410,11 +366,6 @@
 {
 	GList *current_entry;
 
-	if (throbber->details->quiescent_pixbuf != NULL) {
-		g_object_unref (throbber->details->quiescent_pixbuf);
-		throbber->details->quiescent_pixbuf = NULL;
-	}
-
 	/* unref all the images in the list, and then let go of the list itself */
 	current_entry = throbber->details->image_list;
 	while (current_entry != NULL) {
@@ -426,83 +377,70 @@
 	throbber->details->image_list = NULL;
 }
 
-static GdkPixbuf*
-load_themed_image (const char *file_name, const char *image_theme, gboolean small_mode)
+static GdkPixbuf *
+create_frame (NautilusThrobber *throbber, GdkPixbuf *grid_pixbuf, int x, int y)
 {
-	GdkPixbuf *pixbuf, *temp_pixbuf;
-	char *image_path;
-	
-	if (image_theme == NULL) {
-		image_path = nautilus_theme_get_image_path (file_name);
-	} else {
-		image_path = nautilus_theme_get_image_path_from_theme (file_name, image_theme);	
+	GdkPixbuf *temp_pixbuf, *pixbuf;
+	int size;
+
+	size = throbber->details->base_size;
+
+	pixbuf = gdk_pixbuf_new_subpixbuf (grid_pixbuf,
+					   x, y,
+					   size, size);
+	g_return_val_if_fail (pixbuf != NULL, NULL);
+
+	if (throbber->details->small_mode)
+	{
+		temp_pixbuf = gdk_pixbuf_scale_simple (pixbuf,
+						       size * 2 / 3,
+						       size * 2 / 3,
+						       GDK_INTERP_BILINEAR);
+		g_object_unref (pixbuf);
+		pixbuf = temp_pixbuf;
 	}
-	
-	if (image_path) {
-		pixbuf = gdk_pixbuf_new_from_file (image_path, NULL);
-		
-		if (small_mode && pixbuf) {
-			temp_pixbuf = gdk_pixbuf_scale_simple (pixbuf,
-							       gdk_pixbuf_get_width (pixbuf) * 2 / 3,
-							       gdk_pixbuf_get_height (pixbuf) * 2 / 3,
-							       GDK_INTERP_BILINEAR);
-			g_object_unref (pixbuf);
-			pixbuf = temp_pixbuf;
-		}
-		
-		g_free (image_path);
-		return pixbuf;
+	else
+	{
+		temp_pixbuf = gdk_pixbuf_copy (pixbuf);
+		g_object_unref (pixbuf);
+		pixbuf = temp_pixbuf;
 	}
-	return NULL;
-}
 
-/* utility to make the throbber frame name from the index */
-
-static char *
-make_throbber_frame_name (int index)
-{
-	return g_strdup_printf ("throbber/%03d.png", index);
+	return pixbuf;
 }
 
 /* load all of the images of the throbber sequentially */
 static void
 nautilus_throbber_load_images (NautilusThrobber *throbber)
 {
-	int index;
-	char *throbber_frame_name, *image_theme, *frames;
-	GdkPixbuf *pixbuf;
+	int grid_width, grid_height, x, y, size;
+	char *icon;
+	GdkPixbuf *grid_pixbuf, *pixbuf;
 	GList *image_list;
-	
-	nautilus_throbber_unload_images (throbber);
-
-	image_theme = nautilus_theme_get_theme_data ("throbber", "image_theme");
-	throbber->details->quiescent_pixbuf = load_themed_image ("throbber/rest.png", image_theme, throbber->details->small_mode);
 
-	/* images are of the form throbber/001.png, 002.png, etc, so load them into a list */
+	nautilus_throbber_unload_images (throbber);
 
-	frames = nautilus_theme_get_theme_data ("throbber", "frame_count");
-	if (frames != NULL) {
-		throbber->details->max_frame = atoi (frames);
-		g_free (frames);
-	} else {
-		throbber->details->max_frame = 16;
-	}
+	icon = gnome_icon_theme_lookup_icon (throbber->details->icon_theme,
+					     "gnome-spinner", -1, NULL, &size);
+	g_return_if_fail (icon != NULL);
+
+	throbber->details->base_size = size;
+	grid_pixbuf = gdk_pixbuf_new_from_file (icon, NULL);
+	grid_width = gdk_pixbuf_get_width (grid_pixbuf);
+	grid_height = gdk_pixbuf_get_height (grid_pixbuf);
 
 	image_list = NULL;
-	for (index = 1; index <= throbber->details->max_frame; index++) {
-		throbber_frame_name = make_throbber_frame_name (index);
-		pixbuf = load_themed_image (throbber_frame_name, image_theme, throbber->details->small_mode);
-
-		g_free (throbber_frame_name);
-		if (pixbuf == NULL) {
-			throbber->details->max_frame = index - 1;
-			break;
+	for (y = 0; y < grid_height; y += size) {
+		for (x = 0; x < grid_width ; x += size) {
+			pixbuf = create_frame (throbber, grid_pixbuf, x, y);
+			image_list = g_list_prepend (image_list, pixbuf);
 		}
-		image_list = g_list_prepend (image_list, pixbuf);
 	}
 	throbber->details->image_list = g_list_reverse (image_list);
+	throbber->details->max_frame = g_list_length (throbber->details->image_list);
 
-	g_free (image_theme);
+	g_free (icon);
+	g_object_unref (grid_pixbuf);
 }
 
 void
@@ -522,10 +460,13 @@
 nautilus_throbber_size_request (GtkWidget *widget, GtkRequisition *requisition)
 {
 	int throbber_width, throbber_height;
-	NautilusThrobber *throbber = NAUTILUS_THROBBER (widget);
+	NautilusThrobber *throbber;
+
+	throbber = NAUTILUS_THROBBER (widget);
+
+	throbber_width = throbber->details->base_size;
+	throbber_height = throbber->details->base_size;
 
-	get_throbber_dimensions (throbber, &throbber_width, &throbber_height);
-	
 	/* allocate some extra margin so we don't butt up against toolbar edges */
 	requisition->width = throbber_width + 8;
    	requisition->height = throbber_height;
@@ -541,12 +482,11 @@
 	nautilus_throbber_remove_update_callback (throbber);
 	nautilus_throbber_unload_images (throbber);
 	
-	eel_preferences_remove_callback (NAUTILUS_PREFERENCES_THEME,
-					 nautilus_throbber_theme_changed, object);
-	
 	bonobo_object_unref (throbber->details->property_bag);
 	
 	eel_remove_weak_pointer (&throbber->details->control);
+
+	g_object_unref (throbber->details->icon_theme);
 
 	g_free (throbber->details);
 
