[rhythmbox] audioscrobbler: fix table allocation bug



commit 0db106cf5faa0a3b342fc18feaf51e20010345be
Author: Jamie Nicol <jamie thenicols net>
Date:   Tue Aug 10 18:00:39 2010 +0100

    audioscrobbler: fix table allocation bug
    
    The problem was that tables' contents were getting set before the
    table had been realized, meaning it would be incorrectly sized.
    The solution was to connect to the table's realize signal and queue
    a resize.

 plugins/audioscrobbler/audioscrobbler-profile.ui   |    5 +++
 .../rb-audioscrobbler-profile-source.c             |   27 +++++++++++---------
 2 files changed, 20 insertions(+), 12 deletions(-)
---
diff --git a/plugins/audioscrobbler/audioscrobbler-profile.ui b/plugins/audioscrobbler/audioscrobbler-profile.ui
index f027d9d..b2e3fc0 100644
--- a/plugins/audioscrobbler/audioscrobbler-profile.ui
+++ b/plugins/audioscrobbler/audioscrobbler-profile.ui
@@ -438,6 +438,7 @@
                   <object class="GtkTable" id="recent_tracks_table">
                     <property name="visible">True</property>
                     <property name="homogeneous">True</property>
+                    <signal name="realize" handler="list_table_realize_cb"/>
                     <signal name="size_allocate" handler="list_table_size_allocate_cb"/>
                     <child>
                       <placeholder/>
@@ -490,6 +491,7 @@
                   <object class="GtkTable" id="top_artists_table">
                     <property name="visible">True</property>
                     <property name="homogeneous">True</property>
+                    <signal name="realize" handler="list_table_realize_cb"/>
                     <signal name="size_allocate" handler="list_table_size_allocate_cb"/>
                     <child>
                       <placeholder/>
@@ -542,6 +544,7 @@
                   <object class="GtkTable" id="recommended_artists_table">
                     <property name="visible">True</property>
                     <property name="homogeneous">True</property>
+                    <signal name="realize" handler="list_table_realize_cb"/>
                     <signal name="size_allocate" handler="list_table_size_allocate_cb"/>
                     <child>
                       <placeholder/>
@@ -592,6 +595,7 @@
                   <object class="GtkTable" id="top_tracks_table">
                     <property name="visible">True</property>
                     <property name="homogeneous">True</property>
+                    <signal name="realize" handler="list_table_realize_cb"/>
                     <signal name="size_allocate" handler="list_table_size_allocate_cb"/>
                     <child>
                       <placeholder/>
@@ -642,6 +646,7 @@
                   <object class="GtkTable" id="loved_tracks_table">
                     <property name="visible">True</property>
                     <property name="homogeneous">True</property>
+                    <signal name="realize" handler="list_table_realize_cb"/>
                     <signal name="size_allocate" handler="list_table_size_allocate_cb"/>
                     <child>
                       <placeholder/>
diff --git a/plugins/audioscrobbler/rb-audioscrobbler-profile-source.c b/plugins/audioscrobbler/rb-audioscrobbler-profile-source.c
index 6a66636..d0a383a 100644
--- a/plugins/audioscrobbler/rb-audioscrobbler-profile-source.c
+++ b/plugins/audioscrobbler/rb-audioscrobbler-profile-source.c
@@ -213,6 +213,8 @@ static GtkWidget *create_list_button (RBAudioscrobblerProfileSource *source,
 static GtkWidget *create_popup_menu (RBAudioscrobblerProfileSource *source,
                                      RBAudioscrobblerUserData *data);
 static void list_table_pack_start (GtkTable *list_table, GtkWidget *child);
+void list_table_realize_cb (GtkWidget *table,
+                            gpointer user_data);
 void list_table_size_allocate_cb (GtkWidget *layout,
                                   GtkAllocation *allocation,
                                   gpointer user_data);
@@ -1444,6 +1446,10 @@ set_user_list (RBAudioscrobblerProfileSource *source,
 	}
 
 	if (list_data != NULL) {
+		if (gtk_widget_get_realized (list_table) == FALSE) {
+			rb_debug ("table has not been realized yet. it will need resized later");
+		}
+
 		/* add a new button for each item in the list */
 		for (i = 0; i < list_data->len; i++) {
 			RBAudioscrobblerUserData *data;
@@ -1542,11 +1548,6 @@ create_list_button (RBAudioscrobblerProfileSource *source,
 		          G_CALLBACK (list_item_clicked_cb),
 		          source);
 
-	/* this must be called, otherwise the buttons' size requests will be
-	 * incorrect and the allocation of the tables will not work at all.
-	 */
-	gtk_widget_show_all (button);
-
 	return button;
 }
 
@@ -1616,7 +1617,6 @@ list_table_pack_start (GtkTable *list_table, GtkWidget *child)
 	GList *children;
 	int num_children;
 	int num_columns;
-	GtkRequisition req;
 
 	children = gtk_container_get_children (GTK_CONTAINER (list_table));
 	num_children = g_list_length (children);
@@ -1629,14 +1629,17 @@ list_table_pack_start (GtkTable *list_table, GtkWidget *child)
 	                  GTK_FILL | GTK_EXPAND, GTK_FILL,
 	                  0, 0);
 
-	/* Make sure the button has an up to date size request,
-	 * otherwise the table allocation will not work
-	 */
-	gtk_widget_size_request (child, &req);
-
 	g_list_free (children);
 }
 
+void
+list_table_realize_cb (GtkWidget *table,
+                       gpointer user_data)
+{
+	rb_debug ("table has been realized. queueing resize");
+	gtk_widget_queue_resize (table);
+}
+
 /* resizes a GtkTable for a particular size allocation */
 void
 list_table_size_allocate_cb (GtkWidget *table,
@@ -1708,7 +1711,7 @@ list_table_size_allocate_cb (GtkWidget *table,
 		}
 	}
 
-	/* ensure the table is the correct size */
+	/* ensure the table will shrink to the correct size */
 	gtk_widget_set_size_request (table, 0, -1);
 
 	g_list_free (children);



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