Index: shell/rb-source-header.c
===================================================================
RCS file: /cvs/gnome/rhythmbox/shell/rb-source-header.c,v
retrieving revision 1.50
diff -u -r1.50 rb-source-header.c
--- shell/rb-source-header.c	14 Apr 2006 09:14:31 -0000	1.50
+++ shell/rb-source-header.c	19 Apr 2006 13:16:43 -0000
@@ -64,6 +64,18 @@
 						      RBSourceHeader *header);
 static void rb_source_header_source_weak_destroy_cb (RBSourceHeader *header, RBSource *source);
 
+typedef struct {
+	gboolean disclosed;
+	char     *search_text;
+}  SourceState;
+
+static void
+sourcestate_free (SourceState *state)
+{
+        g_free (state->search_text);
+        g_free (state);
+}
+
 struct RBSourceHeaderPrivate
 {
 	RBSource *selected_source;
@@ -85,7 +97,8 @@
 	gboolean disclosed;
 	char *browser_key;
 
-	GHashTable *source_search_text;
+	GHashTable *source_states;
+	
 };
 
 #define RB_SOURCE_HEADER_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), RB_TYPE_SOURCE_HEADER, RBSourceHeaderPrivate))
@@ -258,8 +271,8 @@
 			  GTK_EXPAND | GTK_FILL,
 			  5, 0);
 
-	header->priv->source_search_text = g_hash_table_new_full (g_direct_hash, g_direct_equal,
-								  NULL, (GDestroyNotify)g_free);
+	header->priv->source_states = g_hash_table_new_full (g_direct_hash, g_direct_equal,
+							    NULL, (GDestroyNotify)sourcestate_free);
 }
 
 static void
@@ -282,10 +295,10 @@
 
 	g_return_if_fail (header->priv != NULL);
 
-	g_hash_table_foreach (header->priv->source_search_text,
+	g_hash_table_foreach (header->priv->source_states,
 			      (GHFunc) rb_source_header_source_weak_unref,
 			      header);
-	g_hash_table_destroy (header->priv->source_search_text);
+	g_hash_table_destroy (header->priv->source_states);
 
 	g_free (header->priv->browser_key);
 
@@ -322,9 +335,21 @@
 	rb_debug ("selected source %p", source);
 
 	if (header->priv->selected_source != NULL) {
-		const char *text = g_hash_table_lookup (header->priv->source_search_text,
-							header->priv->selected_source);
-			
+		SourceState *source_state;
+		char        *text;
+		gboolean    disclosed;
+
+		source_state = g_hash_table_lookup (header->priv->source_states,
+						    header->priv->selected_source);
+		
+		if (source_state) {
+			text = g_strdup (source_state->search_text);
+			disclosed = source_state->disclosed;
+		} else {
+			text = NULL;
+			disclosed = FALSE;
+		}
+
 		g_free (header->priv->browser_key);
 		header->priv->browser_key = rb_source_get_browser_key (header->priv->selected_source);
 	
@@ -343,8 +368,8 @@
 		else if (header->priv->browser_key)
 			header->priv->disclosed = eel_gconf_get_boolean (header->priv->browser_key);
 		else
-			/* FIXME: remember the previous state of the source*/
-			header->priv->disclosed = FALSE;
+			/* restore the previous state of the source*/
+			header->priv->disclosed = disclosed;
 	
 		if (!header->priv->have_browser && !header->priv->have_search)
 			gtk_widget_hide (GTK_WIDGET (header));
@@ -455,7 +480,7 @@
 static void
 rb_source_header_source_weak_destroy_cb (RBSourceHeader *header, RBSource *source)
 {
-	g_hash_table_remove (header->priv->source_search_text, source);
+	g_hash_table_remove (header->priv->source_states, source);
 }
 
 static void
@@ -463,18 +488,29 @@
 			    const char *text,
 			    RBSourceHeader *header)
 {
+	SourceState *old_state;
+
 	rb_debug  ("searching for \"%s\"", text);
 
-	/* if we haven't seen the source before, monitor it for deletion */
-	if (g_hash_table_lookup (header->priv->source_search_text, header->priv->selected_source) == NULL) {
+	old_state = g_hash_table_lookup (header->priv->source_states, header->priv->selected_source);
+
+	if (old_state) {
+		old_state->search_text = g_strdup (text);	
+	} else {
+		SourceState *new_state;
+
+		/* if we haven't seen the source before, monitor it for deletion */
 		g_object_weak_ref (G_OBJECT (header->priv->selected_source),
 				   (GWeakNotify)rb_source_header_source_weak_destroy_cb,
 				   header);
+
+		new_state = g_new (SourceState, 1);
+		new_state->search_text = g_strdup (text);	
+		g_hash_table_insert (header->priv->source_states,
+				     header->priv->selected_source,
+				     new_state); 
 	}
 
-	g_hash_table_insert (header->priv->source_search_text,
-			     header->priv->selected_source,
-			     g_strdup (text));
 	rb_source_search (header->priv->selected_source, text);
 	rb_source_header_sync_control_state (header);
 }
@@ -488,9 +524,31 @@
 	    return;
 	
 	if (header->priv->selected_source) {
+		SourceState *old_state;
+
 		rb_source_search (header->priv->selected_source, NULL);
-		g_hash_table_remove (header->priv->source_search_text, 
-				     header->priv->selected_source);
+
+		old_state = g_hash_table_lookup (header->priv->source_states,
+						 header->priv->selected_source);
+		if (old_state) {
+			old_state->search_text = NULL;
+		} else {
+			SourceState *new_state;
+
+			/* if we haven't seen the source before, monitor it for deletion */
+			g_object_weak_ref (G_OBJECT (header->priv->selected_source),
+					   (GWeakNotify)rb_source_header_source_weak_destroy_cb,
+					   header);
+
+			new_state = g_new (SourceState, 1);
+			new_state->search_text = NULL;
+			new_state->disclosed = FALSE;
+			g_hash_table_insert (header->priv->source_states,
+					     header->priv->selected_source,
+					     new_state); 
+		}
+
+
 	}
 	rb_search_entry_clear (RB_SEARCH_ENTRY (header->priv->search));
 	rb_source_header_sync_control_state (header);
@@ -509,7 +567,33 @@
 	if (header->priv->browser_key)
 		eel_gconf_set_boolean (header->priv->browser_key, 
 				       header->priv->disclosed);
+	else {
+		SourceState *old_state;
+		old_state = g_hash_table_lookup (header->priv->source_states,
+						 header->priv->selected_source);
+			
+		if (old_state)  {
+			old_state->disclosed = header->priv->disclosed;
+		} else {
+			SourceState *new_state;
+
+			/* if we haven't seen the source before, monitor it for deletion */
+			g_object_weak_ref (G_OBJECT (header->priv->selected_source),
+					   (GWeakNotify)rb_source_header_source_weak_destroy_cb,
+					   header);
+
+			new_state = g_new (SourceState, 1); 
+			new_state->search_text = NULL;
+			new_state->disclosed = header->priv->disclosed;
+
+			g_hash_table_insert (header->priv->source_states,
+					     header->priv->selected_source,
+					     new_state); 
+		}
+	}
 
+	rb_debug ("got view browser toggle");
+	
 	rb_source_header_sync_control_state (header);
 }
 
