[gnome-photos] Move SelectionToolbar's alignment & width code into its constructor



commit 7ee8276939dde84056d8f74d3801d1c27388d7b6
Author: Debarshi Ray <debarshir gnome org>
Date:   Sun Aug 5 18:47:17 2012 +0200

    Move SelectionToolbar's alignment & width code into its constructor

 src/photos-selection-toolbar.c |   82 +++++++++++++++++++++++++++++++++++++++-
 src/photos-selection-toolbar.h |    3 +-
 src/photos-view-embed.c        |   36 +-----------------
 3 files changed, 82 insertions(+), 39 deletions(-)
---
diff --git a/src/photos-selection-toolbar.c b/src/photos-selection-toolbar.c
index 51d4b36..e0c44d5 100644
--- a/src/photos-selection-toolbar.c
+++ b/src/photos-selection-toolbar.c
@@ -37,6 +37,8 @@
 struct _PhotosSelectionToolbarPrivate
 {
   ClutterActor *actor;
+  ClutterActor *parent_actor;
+  ClutterConstraint *width_constraint;
   GHashTable *item_listeners;
   GtkToolItem *left_group;
   GtkToolItem *right_group;
@@ -54,6 +56,12 @@ struct _PhotosSelectionToolbarPrivate
   gboolean inside_refresh;
 };
 
+enum
+{
+  PROP_0,
+  PROP_PARENT_ACTOR
+};
+
 
 G_DEFINE_TYPE (PhotosSelectionToolbar, photos_selection_toolbar, G_TYPE_OBJECT);
 
@@ -143,6 +151,24 @@ photos_selection_toolbar_favorite_clicked (GtkButton *button, gpointer user_data
 
 
 static void
+photos_selection_toolbar_notify_width (GObject *object, GParamSpec *pspec, gpointer user_data)
+{
+  PhotosSelectionToolbar *self = PHOTOS_SELECTION_TOOLBAR (user_data);
+  PhotosSelectionToolbarPrivate *priv = self->priv;
+  gfloat offset = 300.0;
+  gfloat width;
+
+  width = clutter_actor_get_width (priv->parent_actor);
+  if (width > 1000)
+    offset += (width - 1000);
+  else if (width < 600)
+    offset -= (600 - width);
+
+  clutter_bind_constraint_set_offset (CLUTTER_BIND_CONSTRAINT (priv->width_constraint), -1 * offset);
+}
+
+
+static void
 photos_selection_toolbar_open_clicked (GtkButton *button, gpointer user_data)
 {
   PhotosSelectionToolbar *self = PHOTOS_SELECTION_TOOLBAR (user_data);
@@ -334,11 +360,34 @@ photos_selection_toolbar_trash_clicked (GtkButton *button, gpointer user_data)
 
 
 static void
+photos_selection_toolbar_constructed (GObject *object)
+{
+  PhotosSelectionToolbar *self = PHOTOS_SELECTION_TOOLBAR (object);
+  PhotosSelectionToolbarPrivate *priv = self->priv;
+  ClutterConstraint *constraint;
+
+  G_OBJECT_CLASS (photos_selection_toolbar_parent_class)->constructed (object);
+
+  priv->width_constraint = clutter_bind_constraint_new (priv->parent_actor, CLUTTER_BIND_WIDTH, -300.0);
+  clutter_actor_add_constraint (priv->actor, priv->width_constraint);
+  g_signal_connect (priv->actor, "notify::width", G_CALLBACK (photos_selection_toolbar_notify_width), self);
+
+  constraint = clutter_align_constraint_new (priv->parent_actor, CLUTTER_ALIGN_X_AXIS, 0.50);
+  clutter_actor_add_constraint (priv->actor, constraint);
+
+  constraint = clutter_align_constraint_new (priv->parent_actor, CLUTTER_ALIGN_Y_AXIS, 0.95);
+  clutter_actor_add_constraint (priv->actor, constraint);
+}
+
+
+static void
 photos_selection_toolbar_dispose (GObject *object)
 {
   PhotosSelectionToolbar *self = PHOTOS_SELECTION_TOOLBAR (object);
   PhotosSelectionToolbarPrivate *priv = self->priv;
 
+  g_clear_object (&priv->parent_actor);
+
   if (priv->item_listeners != NULL)
     {
       g_hash_table_unref (priv->item_listeners);
@@ -358,6 +407,24 @@ photos_selection_toolbar_dispose (GObject *object)
 
 
 static void
+photos_selection_toolbar_set_property (GObject *object, guint prop_id, const GValue *value, GParamSpec *pspec)
+{
+  PhotosSelectionToolbar *self = PHOTOS_SELECTION_TOOLBAR (object);
+
+  switch (prop_id)
+    {
+    case PROP_PARENT_ACTOR:
+      self->priv->parent_actor = CLUTTER_ACTOR (g_value_dup_object (value));
+      break;
+
+    default:
+      G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
+      break;
+    }
+}
+
+
+static void
 photos_selection_toolbar_init (PhotosSelectionToolbar *self)
 {
   PhotosSelectionToolbarPrivate *priv;
@@ -475,16 +542,27 @@ photos_selection_toolbar_class_init (PhotosSelectionToolbarClass *class)
 {
   GObjectClass *object_class = G_OBJECT_CLASS (class);
 
+  object_class->constructed= photos_selection_toolbar_constructed;
   object_class->dispose = photos_selection_toolbar_dispose;
+  object_class->set_property = photos_selection_toolbar_set_property;
+
+  g_object_class_install_property (object_class,
+                                   PROP_PARENT_ACTOR,
+                                   g_param_spec_object ("parent-actor",
+                                                        "Parent actor",
+                                                        "A ClutterActor used for calculating the the alignment and "
+                                                        "width of the toolbar",
+                                                        CLUTTER_TYPE_ACTOR,
+                                                        G_PARAM_CONSTRUCT_ONLY | G_PARAM_WRITABLE));
 
   g_type_class_add_private (class, sizeof (PhotosSelectionToolbarPrivate));
 }
 
 
 PhotosSelectionToolbar *
-photos_selection_toolbar_new (void)
+photos_selection_toolbar_new (ClutterActor *parent_actor)
 {
-  return g_object_new (PHOTOS_TYPE_SELECTION_TOOLBAR, NULL);
+  return g_object_new (PHOTOS_TYPE_SELECTION_TOOLBAR, "parent-actor", parent_actor, NULL);
 }
 
 
diff --git a/src/photos-selection-toolbar.h b/src/photos-selection-toolbar.h
index d1955cf..a277b3c 100644
--- a/src/photos-selection-toolbar.h
+++ b/src/photos-selection-toolbar.h
@@ -64,10 +64,9 @@ struct _PhotosSelectionToolbarClass
 
 GType                     photos_selection_toolbar_get_type             (void) G_GNUC_CONST;
 
-PhotosSelectionToolbar   *photos_selection_toolbar_new                  (void);
+PhotosSelectionToolbar   *photos_selection_toolbar_new                  (ClutterActor *parent_actor);
 
 ClutterActor             *photos_selection_toolbar_get_actor            (PhotosSelectionToolbar *self);
-
 G_END_DECLS
 
 #endif /* PHOTOS_SELECTION_TOOLBAR_H */
diff --git a/src/photos-view-embed.c b/src/photos-view-embed.c
index 4960ee4..701ea39 100644
--- a/src/photos-view-embed.c
+++ b/src/photos-view-embed.c
@@ -42,7 +42,6 @@ struct _PhotosViewEmbedPrivate
   ClutterActor *error_box;
   ClutterActor *notebook_actor;
   ClutterActor *view_actor;
-  ClutterConstraint *width_constraint;
   ClutterLayoutManager *contents_layout;
   ClutterLayoutManager *view_layout;
   GCancellable *loader_cancellable;
@@ -273,24 +272,6 @@ photos_view_embed_query_status_changed (PhotosTrackerController *trk_cntrlr, gbo
 }
 
 
-static void
-photos_view_embed_selection_toolbar_notify_width (GObject *object, GParamSpec *pspec, gpointer user_data)
-{
-  PhotosViewEmbed *self = PHOTOS_VIEW_EMBED (user_data);
-  PhotosViewEmbedPrivate *priv = self->priv;
-  gfloat offset = 300.0;
-  gfloat width;
-
-  width = clutter_actor_get_width (priv->contents_actor);
-  if (width > 1000)
-    offset += (width - 1000);
-  else if (width < 600)
-    offset -= (600 - width);
-
-  clutter_bind_constraint_set_offset (CLUTTER_BIND_CONSTRAINT (priv->width_constraint), -1 * offset);
-}
-
-
 void
 photos_view_embed_set_error (PhotosViewEmbed *self, const gchar *primary, const gchar *secondary)
 {
@@ -361,7 +342,6 @@ photos_view_embed_init (PhotosViewEmbed *self)
   PhotosViewEmbedPrivate *priv;
   ClutterActor *toolbar_actor;
   ClutterColor color = {255, 255, 255, 255};
-  ClutterConstraint *constraint;
 
   self->priv = G_TYPE_INSTANCE_GET_PRIVATE (self, PHOTOS_TYPE_VIEW_EMBED, PhotosViewEmbedPrivate);
   priv = self->priv;
@@ -412,21 +392,7 @@ photos_view_embed_init (PhotosViewEmbed *self)
    *       ...
    */
 
-  priv->selection_toolbar = photos_selection_toolbar_new();
-  toolbar_actor = photos_selection_toolbar_get_actor (priv->selection_toolbar);
-
-  priv->width_constraint = clutter_bind_constraint_new (priv->contents_actor, CLUTTER_BIND_WIDTH, -300.0);
-  clutter_actor_add_constraint (toolbar_actor, priv->width_constraint);
-  g_signal_connect (toolbar_actor,
-                    "notify::width",
-                    G_CALLBACK (photos_view_embed_selection_toolbar_notify_width),
-                    self);
-
-  constraint = clutter_align_constraint_new (priv->contents_actor, CLUTTER_ALIGN_X_AXIS, 0.50);
-  clutter_actor_add_constraint (toolbar_actor, constraint);
-
-  constraint = clutter_align_constraint_new (priv->contents_actor, CLUTTER_ALIGN_Y_AXIS, 0.95);
-  clutter_actor_add_constraint (toolbar_actor, constraint);
+  priv->selection_toolbar = photos_selection_toolbar_new (priv->contents_actor);
 
   priv->mode_cntrlr = photos_mode_controller_new ();
   g_signal_connect (priv->mode_cntrlr,



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