[rhythmbox] avoid doing work in class init functions



commit fd6a4bc640ee505f92ff9c57b069902c1683e9e2
Author: Jonathan Matthew <jonathan d14n org>
Date:   Fri May 17 08:45:20 2013 +1000

    avoid doing work in class init functions
    
    Class init functions are called as part of the introspection
    process.  During the build process we might not have a display
    to talk to, so we need to avoid doing anything that requires
    gdk to connect to the display.
    
    https://bugzilla.gnome.org/show_bug.cgi?id=700177

 rhythmdb/rhythmdb-property-model.c |   34 +++++++++++++++++-----------------
 rhythmdb/rhythmdb-query-model.c    |   10 +++++-----
 sources/rb-display-page-model.c    |    7 +++----
 widgets/rb-cell-renderer-rating.c  |    8 ++++++--
 widgets/rb-rating-helper.c         |    4 ++--
 widgets/rb-rating-helper.h         |    2 +-
 widgets/rb-rating.c                |    2 +-
 7 files changed, 35 insertions(+), 32 deletions(-)
---
diff --git a/rhythmdb/rhythmdb-property-model.c b/rhythmdb/rhythmdb-property-model.c
index c354022..c905984 100644
--- a/rhythmdb/rhythmdb-property-model.c
+++ b/rhythmdb/rhythmdb-property-model.c
@@ -220,23 +220,6 @@ rhythmdb_property_model_class_init (RhythmDBPropertyModelClass *klass)
 {
        GObjectClass *object_class = G_OBJECT_CLASS (klass);
 
-       if (!rhythmdb_property_model_artist_drag_target_list)
-               rhythmdb_property_model_artist_drag_target_list =
-                       gtk_target_list_new (targets_artist,
-                                            G_N_ELEMENTS (targets_artist));
-       if (!rhythmdb_property_model_album_drag_target_list)
-               rhythmdb_property_model_album_drag_target_list =
-                       gtk_target_list_new (targets_album,
-                                            G_N_ELEMENTS (targets_album));
-       if (!rhythmdb_property_model_genre_drag_target_list)
-               rhythmdb_property_model_genre_drag_target_list =
-                       gtk_target_list_new (targets_genre,
-                                            G_N_ELEMENTS (targets_genre));
-       if (!rhythmdb_property_model_location_drag_target_list)
-               rhythmdb_property_model_location_drag_target_list =
-                       gtk_target_list_new (targets_location,
-                                            G_N_ELEMENTS (targets_location));
-
        object_class->set_property = rhythmdb_property_model_set_property;
        object_class->get_property = rhythmdb_property_model_get_property;
 
@@ -484,6 +467,23 @@ rhythmdb_property_model_get_property (GObject *object,
 static void
 rhythmdb_property_model_init (RhythmDBPropertyModel *model)
 {
+       if (!rhythmdb_property_model_artist_drag_target_list)
+               rhythmdb_property_model_artist_drag_target_list =
+                       gtk_target_list_new (targets_artist,
+                                            G_N_ELEMENTS (targets_artist));
+       if (!rhythmdb_property_model_album_drag_target_list)
+               rhythmdb_property_model_album_drag_target_list =
+                       gtk_target_list_new (targets_album,
+                                            G_N_ELEMENTS (targets_album));
+       if (!rhythmdb_property_model_genre_drag_target_list)
+               rhythmdb_property_model_genre_drag_target_list =
+                       gtk_target_list_new (targets_genre,
+                                            G_N_ELEMENTS (targets_genre));
+       if (!rhythmdb_property_model_location_drag_target_list)
+               rhythmdb_property_model_location_drag_target_list =
+                       gtk_target_list_new (targets_location,
+                                            G_N_ELEMENTS (targets_location));
+
        model->priv = RHYTHMDB_PROPERTY_MODEL_GET_PRIVATE (model);
 
        model->priv->stamp = g_random_int ();
diff --git a/rhythmdb/rhythmdb-query-model.c b/rhythmdb/rhythmdb-query-model.c
index 4786c3f..abb1a55 100644
--- a/rhythmdb/rhythmdb-query-model.c
+++ b/rhythmdb/rhythmdb-query-model.c
@@ -311,11 +311,6 @@ rhythmdb_query_model_class_init (RhythmDBQueryModelClass *klass)
 {
        GObjectClass *object_class = G_OBJECT_CLASS (klass);
 
-       if (!rhythmdb_query_model_drag_target_list)
-               rhythmdb_query_model_drag_target_list
-                       = gtk_target_list_new (rhythmdb_query_model_drag_types,
-                                              G_N_ELEMENTS (rhythmdb_query_model_drag_types));
-
        object_class->set_property = rhythmdb_query_model_set_property;
        object_class->get_property = rhythmdb_query_model_get_property;
 
@@ -669,6 +664,11 @@ rhythmdb_query_model_get_property (GObject *object,
 static void
 rhythmdb_query_model_init (RhythmDBQueryModel *model)
 {
+       if (!rhythmdb_query_model_drag_target_list)
+               rhythmdb_query_model_drag_target_list
+                       = gtk_target_list_new (rhythmdb_query_model_drag_types,
+                                              G_N_ELEMENTS (rhythmdb_query_model_drag_types));
+
        model->priv = RHYTHMDB_QUERY_MODEL_GET_PRIVATE (model);
 
        model->priv->stamp = g_random_int ();
diff --git a/sources/rb-display-page-model.c b/sources/rb-display-page-model.c
index ac9504c..75354df 100644
--- a/sources/rb-display-page-model.c
+++ b/sources/rb-display-page-model.c
@@ -828,6 +828,9 @@ rb_display_page_model_new (void)
 static void
 rb_display_page_model_init (RBDisplayPageModel *model)
 {
+       if (!drag_target_list) {
+               drag_target_list = gtk_target_list_new (dnd_targets, G_N_ELEMENTS (dnd_targets));
+       }
 }
 
 static void
@@ -894,10 +897,6 @@ rb_display_page_model_class_init (RBDisplayPageModelClass *klass)
                              G_TYPE_NONE,
                              2,
                              RB_TYPE_DISPLAY_PAGE, GTK_TYPE_TREE_ITER);
-
-       if (!drag_target_list) {
-               drag_target_list = gtk_target_list_new (dnd_targets, G_N_ELEMENTS (dnd_targets));
-       }
 }
 
 /**
diff --git a/widgets/rb-cell-renderer-rating.c b/widgets/rb-cell-renderer-rating.c
index 8be208c..45cb550 100644
--- a/widgets/rb-cell-renderer-rating.c
+++ b/widgets/rb-cell-renderer-rating.c
@@ -105,6 +105,12 @@ static guint rb_cell_renderer_rating_signals[LAST_SIGNAL] = { 0 };
 static void
 rb_cell_renderer_rating_init (RBCellRendererRating *cellrating)
 {
+       RBCellRendererRatingClass *klass;
+
+       klass = RB_CELL_RENDERER_RATING_GET_CLASS (cellrating);
+       if (klass->priv->pixbufs == NULL) {
+               klass->priv->pixbufs = rb_rating_pixbufs_load ();
+       }
 
        cellrating->priv = RB_CELL_RENDERER_RATING_GET_PRIVATE (cellrating);
 
@@ -113,7 +119,6 @@ rb_cell_renderer_rating_init (RBCellRendererRating *cellrating)
                      "mode", GTK_CELL_RENDERER_MODE_ACTIVATABLE,
                      NULL);
 
-       /* create the needed icons */
 }
 
 static void
@@ -130,7 +135,6 @@ rb_cell_renderer_rating_class_init (RBCellRendererRatingClass *class)
        cell_class->activate = rb_cell_renderer_rating_activate;
 
        class->priv = g_new0 (RBCellRendererRatingClassPrivate, 1);
-       class->priv->pixbufs = rb_rating_pixbufs_new ();
 
        /**
         * RBCellRendererRating:rating:
diff --git a/widgets/rb-rating-helper.c b/widgets/rb-rating-helper.c
index 182c254..ca7a379 100644
--- a/widgets/rb-rating-helper.c
+++ b/widgets/rb-rating-helper.c
@@ -90,7 +90,7 @@ rb_rating_install_rating_property (GObjectClass *klass, gulong prop)
 }
 
 /**
- * rb_rating_pixbufs_new:
+ * rb_rating_pixbufs_load:
  *
  * Creates and returns a structure holding a set of pixbufs
  * to use to display ratings.
@@ -99,7 +99,7 @@ rb_rating_install_rating_property (GObjectClass *klass, gulong prop)
  * the pixbufs could be loaded.
  */
 RBRatingPixbufs *
-rb_rating_pixbufs_new (void)
+rb_rating_pixbufs_load (void)
 {
        RBRatingPixbufs *pixbufs;
        GtkIconTheme *theme;
diff --git a/widgets/rb-rating-helper.h b/widgets/rb-rating-helper.h
index f49c66e..8c78982 100644
--- a/widgets/rb-rating-helper.h
+++ b/widgets/rb-rating-helper.h
@@ -45,7 +45,7 @@ double   rb_rating_get_rating_from_widget (GtkWidget *widget,
                                           gint widget_x, gint widget_width,
                                           double current_rating);
 
-RBRatingPixbufs *rb_rating_pixbufs_new (void);
+RBRatingPixbufs *rb_rating_pixbufs_load (void);
 void             rb_rating_pixbufs_free (RBRatingPixbufs *pixbufs);
 
 void   rb_rating_install_rating_property (GObjectClass *klass, gulong prop);
diff --git a/widgets/rb-rating.c b/widgets/rb-rating.c
index 2a6a00b..5e3b596 100644
--- a/widgets/rb-rating.c
+++ b/widgets/rb-rating.c
@@ -205,7 +205,7 @@ rb_rating_init (RBRating *rating)
        rating->priv = RB_RATING_GET_PRIVATE (rating);
 
        /* create the needed icons */
-       rating->priv->pixbufs = rb_rating_pixbufs_new ();
+       rating->priv->pixbufs = rb_rating_pixbufs_load ();
        
        rb_rating_set_accessible_name (GTK_WIDGET (rating), 0.0);
 


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