[glib-controller] Use modern property API



commit 93ccee060480cd83a24e2ff72a9a847cc03e35ee
Author: Emmanuele Bassi <ebassi linux intel com>
Date:   Mon Sep 12 18:12:18 2011 +0100

    Use modern property API

 doc/reference/glib-controller-sections.txt |    3 +
 examples/simple-model.c                    |    2 +-
 glib-controller/garraycontroller.c         |   66 ++++++++++++------
 glib-controller/garraycontroller.h         |    9 ++-
 glib-controller/gcontrollerevent.c         |   99 ++++++++++++++-------------
 glib-controller/ghashcontroller.c          |   66 ++++++++++++------
 glib-controller/ghashcontroller.h          |    9 ++-
 glib-controller/gptrarraycontroller.c      |   66 ++++++++++++------
 glib-controller/gptrarraycontroller.h      |    9 ++-
 glib-controller/tests/array-controller.c   |   12 ++--
 glib-controller/tests/hash-controller.c    |    6 +-
 11 files changed, 211 insertions(+), 136 deletions(-)
---
diff --git a/doc/reference/glib-controller-sections.txt b/doc/reference/glib-controller-sections.txt
index cf2df79..14b4092 100644
--- a/doc/reference/glib-controller-sections.txt
+++ b/doc/reference/glib-controller-sections.txt
@@ -4,6 +4,7 @@
 GHashController
 GHashControllerClass
 g_hash_controller_new
+g_hash_controller_new_with_hash
 g_hash_controller_set_hash
 g_hash_controller_get_hash
 
@@ -26,6 +27,7 @@ GHashControllerPrivate
 GPtrArrayController
 GPtrArrayControllerClass
 g_ptr_array_controller_new
+g_ptr_array_controller_new_with_array
 g_ptr_array_controller_set_array
 g_ptr_array_controller_get_array
 
@@ -68,6 +70,7 @@ G_CONTROLLER_GET_CLASS
 GArrayController
 GArrayControllerClass
 g_array_controller_new
+g_array_controller_new_with_array
 g_array_controller_set_array
 g_array_controller_get_array
 
diff --git a/examples/simple-model.c b/examples/simple-model.c
index a756def..ec373a7 100644
--- a/examples/simple-model.c
+++ b/examples/simple-model.c
@@ -62,7 +62,7 @@ my_simple_model_init (MySimpleModel *model)
 {
   GPtrArray *array = g_ptr_array_new_with_free_func (g_free);
 
-  model->controller = g_ptr_array_controller_new (array);
+  model->controller = g_ptr_array_controller_new_with_array (array);
   g_ptr_array_unref (array);
 
   model->array = array;
diff --git a/glib-controller/garraycontroller.c b/glib-controller/garraycontroller.c
index 45c1096..e79bd3e 100644
--- a/glib-controller/garraycontroller.c
+++ b/glib-controller/garraycontroller.c
@@ -23,10 +23,14 @@ enum
 {
   PROP_0,
 
-  PROP_ARRAY
+  ARRAY,
+
+  N_PROPERTIES
 };
 
-G_DEFINE_TYPE (GArrayController, g_array_controller, G_TYPE_CONTROLLER);
+static GParamSpec *controller_props[N_PROPERTIES] = { NULL, };
+
+G_DEFINE_TYPE (GArrayController, g_array_controller, G_TYPE_CONTROLLER)
 
 static void
 g_array_controller_set_property (GObject      *gobject,
@@ -38,7 +42,7 @@ g_array_controller_set_property (GObject      *gobject,
 
   switch (prop_id)
     {
-    case PROP_ARRAY:
+    case ARRAY:
       g_array_controller_set_array (self, g_value_get_boxed (value));
       break;
 
@@ -58,7 +62,7 @@ g_array_controller_get_property (GObject    *gobject,
 
   switch (prop_id)
     {
-    case PROP_ARRAY:
+    case ARRAY:
       g_value_set_boxed (value, priv->array);
       break;
 
@@ -69,39 +73,43 @@ g_array_controller_get_property (GObject    *gobject,
 }
 
 static void
-g_array_controller_finalize (GObject *gobject)
+g_array_controller_dispose (GObject *gobject)
 {
   GArrayControllerPrivate *priv = G_ARRAY_CONTROLLER (gobject)->priv;
 
-  if (priv->array)
-    g_array_unref (priv->array);
+  if (priv->array != NULL)
+    {
+      g_array_unref (priv->array);
+      priv->array = NULL;
+    }
 
-  G_OBJECT_CLASS (g_array_controller_parent_class)->finalize (gobject);
+  G_OBJECT_CLASS (g_array_controller_parent_class)->dispose (gobject);
 }
 
 static void
 g_array_controller_class_init (GArrayControllerClass *klass)
 {
   GObjectClass *gobject_class = G_OBJECT_CLASS (klass);
-  GParamSpec *pspec;
 
   gobject_class->set_property = g_array_controller_set_property;
   gobject_class->get_property = g_array_controller_get_property;
-  gobject_class->finalize = g_array_controller_finalize;
+  gobject_class->dispose = g_array_controller_dispose;
 
   /**
    * GArrayController:array:
    *
    * The #GArray to be controlled by a #GArrayController instance
    */
-  pspec = g_param_spec_boxed ("array",
-                              "Array",
-                              "The GArray to be controlled",
-                              G_TYPE_ARRAY,
-                              G_PARAM_READWRITE |
-                              G_PARAM_CONSTRUCT |
-                              G_PARAM_STATIC_STRINGS);
-  g_object_class_install_property (gobject_class, PROP_ARRAY, pspec);
+  controller_props[ARRAY] =
+    g_param_spec_boxed ("array",
+                        "Array",
+                        "The GArray to be controlled",
+                        G_TYPE_ARRAY,
+                        G_PARAM_READWRITE |
+                        G_PARAM_CONSTRUCT |
+                        G_PARAM_STATIC_STRINGS);
+
+  g_object_class_install_properties (gobject_class, N_PROPERTIES, controller_props);
 
   g_type_class_add_private (klass, sizeof (GArrayControllerPrivate));
 }
@@ -116,14 +124,27 @@ g_array_controller_init (GArrayController *self)
 
 /**
  * g_array_controller_new:
+ *
+ * Creates a new #GArrayController.
+ *
+ * Return value: (transfer full): the newly created #GArrayController
+ */
+GController *
+g_array_controller_new (void)
+{
+  return g_object_new (G_TYPE_ARRAY_CONTROLLER, NULL);
+}
+
+/**
+ * g_array_controller_new_with_array:
  * @array: (allow-none): a #GArray or %NULL
  *
- * Creates a new #GArrayController controlling the @array
+ * Creates a new #GArrayController controlling the @array.
  *
- * Return value: the newly created #GArrayController
+ * Return value: (transfer full): the newly created #GArrayController
  */
 GController *
-g_array_controller_new (GArray *array)
+g_array_controller_new_with_array (GArray *array)
 {
   return g_object_new (G_TYPE_ARRAY_CONTROLLER,
                        "array", array,
@@ -155,10 +176,11 @@ g_array_controller_set_array (GArrayController *controller,
     g_array_unref (controller->priv->array);
 
   controller->priv->array = array;
+
   if (controller->priv->array != NULL)
     g_array_ref (controller->priv->array);
 
-  g_object_notify (G_OBJECT (controller), "array");
+  g_object_notify_by_pspec (G_OBJECT (controller), controller_props[ARRAY]);
 }
 
 /**
diff --git a/glib-controller/garraycontroller.h b/glib-controller/garraycontroller.h
index e96e3e8..4d00b1c 100644
--- a/glib-controller/garraycontroller.h
+++ b/glib-controller/garraycontroller.h
@@ -38,11 +38,12 @@ struct _GArrayControllerClass
 
 GType g_array_controller_get_type (void) G_GNUC_CONST;
 
-GController *g_array_controller_new       (GArray           *array);
+GController *   g_array_controller_new                  (void);
+GController *   g_array_controller_new_with_array       (GArray           *array);
 
-void         g_array_controller_set_array (GArrayController *controller,
-                                           GArray           *array);
-GArray *     g_array_controller_get_array (GArrayController *controller);
+void            g_array_controller_set_array            (GArrayController *controller,
+                                                         GArray           *array);
+GArray *        g_array_controller_get_array            (GArrayController *controller);
 
 G_END_DECLS
 
diff --git a/glib-controller/gcontrollerevent.c b/glib-controller/gcontrollerevent.c
index 1b2f9df..9e76801 100644
--- a/glib-controller/gcontrollerevent.c
+++ b/glib-controller/gcontrollerevent.c
@@ -37,15 +37,17 @@ enum
 {
   PROP_0,
 
-  PROP_CONTROLLER,
-  PROP_ACTION,
-  PROP_INDEX_TYPE,
-  PROP_INDICES
+  CONTROLLER,
+  ACTION,
+  INDEX_TYPE,
+  INDICES,
+
+  N_PROPERTIES
 };
 
-G_DEFINE_TYPE (GControllerEvent,
-               g_controller_event,
-               G_TYPE_OBJECT);
+static GParamSpec *event_props[N_PROPERTIES] = { NULL, };
+
+G_DEFINE_TYPE (GControllerEvent, g_controller_event, G_TYPE_OBJECT)
 
 static GValueArray *
 add_indices (GValueArray *cur_indices,
@@ -97,19 +99,19 @@ g_controller_event_set_property (GObject      *gobject,
 
   switch (prop_id)
     {
-    case PROP_CONTROLLER:
+    case CONTROLLER:
       priv->controller = g_object_ref (g_value_get_object (value));
       break;
 
-    case PROP_ACTION:
+    case ACTION:
       priv->action = g_value_get_enum (value);
       break;
 
-    case PROP_INDEX_TYPE:
+    case INDEX_TYPE:
       priv->index_type = g_value_get_gtype (value);
       break;
 
-    case PROP_INDICES:
+    case INDICES:
       priv->indices = add_indices (priv->indices, g_value_get_boxed (value));
       break;
 
@@ -129,19 +131,19 @@ g_controller_event_get_property (GObject    *gobject,
 
   switch (prop_id)
     {
-    case PROP_CONTROLLER:
+    case CONTROLLER:
       g_value_set_object (value, priv->controller);
       break;
 
-    case PROP_ACTION:
+    case ACTION:
       g_value_set_enum (value, priv->action);
       break;
 
-    case PROP_INDEX_TYPE:
+    case INDEX_TYPE:
       g_value_set_gtype (value, priv->index_type);
       break;
 
-    case PROP_INDICES:
+    case INDICES:
       g_value_set_boxed (value, priv->indices);
       break;
 
@@ -180,7 +182,6 @@ static void
 g_controller_event_class_init (GControllerEventClass *klass)
 {
   GObjectClass *gobject_class = G_OBJECT_CLASS (klass);
-  GParamSpec *pspec;
 
   g_type_class_add_private (klass, sizeof (GControllerEventPrivate));
 
@@ -195,43 +196,43 @@ g_controller_event_class_init (GControllerEventClass *klass)
    *
    * The #GController instance that created this event
    */
-  pspec = g_param_spec_object ("controller",
-                               "Controller",
-                               "The controller instance that created the event",
-                               G_TYPE_CONTROLLER,
-                               G_PARAM_READWRITE |
-                               G_PARAM_CONSTRUCT_ONLY |
-                               G_PARAM_STATIC_STRINGS);
-  g_object_class_install_property (gobject_class, PROP_CONTROLLER, pspec);
+  event_props[CONTROLLER] =
+    g_param_spec_object ("controller",
+                         "Controller",
+                         "The controller instance that created the event",
+                         G_TYPE_CONTROLLER,
+                         G_PARAM_READWRITE |
+                         G_PARAM_CONSTRUCT_ONLY |
+                         G_PARAM_STATIC_STRINGS);
 
   /**
    * GControllerEvent:action:
    *
    * The #GControllerAction that caused the creation of the event
    */
-  pspec = g_param_spec_enum ("action",
-                             "Action",
-                             "The action that caused the creation of the event",
-                             G_TYPE_CONTROLLER_ACTION,
-                             G_CONTROLLER_INVALID_ACTION,
-                             G_PARAM_READWRITE |
-                             G_PARAM_CONSTRUCT_ONLY |
+  event_props[ACTION] =
+    g_param_spec_enum ("action",
+                       "Action",
+                       "The action that caused the creation of the event",
+                       G_TYPE_CONTROLLER_ACTION,
+                       G_CONTROLLER_INVALID_ACTION,
+                       G_PARAM_READWRITE |
+                       G_PARAM_CONSTRUCT_ONLY |
                              G_PARAM_STATIC_STRINGS);
-  g_object_class_install_property (gobject_class, PROP_ACTION, pspec);
 
   /**
    * GControllerEvent:index-type:
    *
    * The #GType representation of an index stored by the event
    */
-  pspec = g_param_spec_gtype ("index-type",
-                              "Index Type",
-                              "The type of the indices",
-                              G_TYPE_NONE,
-                              G_PARAM_READWRITE |
-                              G_PARAM_CONSTRUCT_ONLY |
-                              G_PARAM_STATIC_STRINGS);
-  g_object_class_install_property (gobject_class, PROP_INDEX_TYPE, pspec);
+  event_props[INDEX_TYPE] =
+    g_param_spec_gtype ("index-type",
+                        "Index Type",
+                        "The type of the indices",
+                        G_TYPE_NONE,
+                        G_PARAM_READWRITE |
+                        G_PARAM_CONSTRUCT_ONLY |
+                        G_PARAM_STATIC_STRINGS);
 
   /**
    * GControllerEvent:indices:
@@ -241,14 +242,16 @@ g_controller_event_class_init (GControllerEventClass *klass)
    * The indices are meaningful only for the data storage controlled
    * by the #GController that created this event
    */
-  pspec = g_param_spec_boxed ("indices",
-                              "Indices",
-                              "The indices inside the data storage",
-                              G_TYPE_VALUE_ARRAY,
-                              G_PARAM_READWRITE |
-                              G_PARAM_CONSTRUCT_ONLY |
-                              G_PARAM_STATIC_STRINGS);
-  g_object_class_install_property (gobject_class, PROP_INDICES, pspec);
+  event_props[INDICES] =
+    g_param_spec_boxed ("indices",
+                        "Indices",
+                        "The indices inside the data storage",
+                        G_TYPE_VALUE_ARRAY,
+                        G_PARAM_READWRITE |
+                        G_PARAM_CONSTRUCT_ONLY |
+                        G_PARAM_STATIC_STRINGS);
+
+  g_object_class_install_properties (gobject_class, N_PROPERTIES, event_props);
 }
 
 static void
diff --git a/glib-controller/ghashcontroller.c b/glib-controller/ghashcontroller.c
index b5ec6ca..ed564f6 100644
--- a/glib-controller/ghashcontroller.c
+++ b/glib-controller/ghashcontroller.c
@@ -23,10 +23,14 @@ enum
 {
   PROP_0,
 
-  PROP_HASH
+  HASH,
+
+  N_PROPERTIES
 };
 
-G_DEFINE_TYPE (GHashController, g_hash_controller, G_TYPE_CONTROLLER);
+static GParamSpec *controller_props[N_PROPERTIES] = { NULL, };
+
+G_DEFINE_TYPE (GHashController, g_hash_controller, G_TYPE_CONTROLLER)
 
 static void
 g_hash_controller_set_property (GObject      *gobject,
@@ -38,7 +42,7 @@ g_hash_controller_set_property (GObject      *gobject,
 
   switch (prop_id)
     {
-    case PROP_HASH:
+    case HASH:
       g_hash_controller_set_hash (self, g_value_get_boxed (value));
       break;
 
@@ -58,7 +62,7 @@ g_hash_controller_get_property (GObject    *gobject,
 
   switch (prop_id)
     {
-    case PROP_HASH:
+    case HASH:
       g_value_set_boxed (value, priv->hash);
       break;
 
@@ -69,39 +73,43 @@ g_hash_controller_get_property (GObject    *gobject,
 }
 
 static void
-g_hash_controller_finalize (GObject *gobject)
+g_hash_controller_dispose (GObject *gobject)
 {
   GHashControllerPrivate *priv = G_HASH_CONTROLLER (gobject)->priv;
 
-  if (priv->hash)
-    g_hash_table_unref (priv->hash);
+  if (priv->hash != NULL)
+    {
+      g_hash_table_unref (priv->hash);
+      priv->hash = NULL;
+    }
 
-  G_OBJECT_CLASS (g_hash_controller_parent_class)->finalize (gobject);
+  G_OBJECT_CLASS (g_hash_controller_parent_class)->dispose (gobject);
 }
 
 static void
 g_hash_controller_class_init (GHashControllerClass *klass)
 {
   GObjectClass *gobject_class = G_OBJECT_CLASS (klass);
-  GParamSpec *pspec;
 
   gobject_class->set_property = g_hash_controller_set_property;
   gobject_class->get_property = g_hash_controller_get_property;
-  gobject_class->finalize = g_hash_controller_finalize;
+  gobject_class->dispose = g_hash_controller_dispose;
 
   /**
    * GHashController:hash:
    *
    * The #GHashTable to be controlled by a #GHashController instance
    */
-  pspec = g_param_spec_boxed ("hash",
-                              "Hash",
-                              "The GHashTable to be controlled",
-                              G_TYPE_HASH_TABLE,
-                              G_PARAM_READWRITE |
-                              G_PARAM_CONSTRUCT |
-                              G_PARAM_STATIC_STRINGS);
-  g_object_class_install_property (gobject_class, PROP_HASH, pspec);
+  controller_props[HASH] =
+    g_param_spec_boxed ("hash",
+                        "Hash",
+                        "The GHashTable to be controlled",
+                        G_TYPE_HASH_TABLE,
+                        G_PARAM_READWRITE |
+                        G_PARAM_CONSTRUCT |
+                        G_PARAM_STATIC_STRINGS);
+
+  g_object_class_install_properties (gobject_class, N_PROPERTIES, controller_props);
 
   g_type_class_add_private (klass, sizeof (GHashControllerPrivate));
 }
@@ -116,14 +124,27 @@ g_hash_controller_init (GHashController *self)
 
 /**
  * g_hash_controller_new:
+ *
+ * Creates a new #GHashController.
+ *
+ * Return value: (transfer full): the newly created #GHashController
+ */
+GController *
+g_hash_controller_new (void)
+{
+  return g_object_new (G_TYPE_HASH_CONTROLLER, NULL);
+}
+
+/**
+ * g_hash_controller_new_with_hash:
  * @hash: (allow-none): a #GHashTable or %NULL
  *
- * Creates a new #GHashController controlling the @hash
+ * Creates a new #GHashController controlling the @hash.
  *
- * Return value: the newly created #GHashController
+ * Return value: (transfer full): the newly created #GHashController
  */
 GController *
-g_hash_controller_new (GHashTable *hash)
+g_hash_controller_new_with_hash (GHashTable *hash)
 {
   return g_object_new (G_TYPE_HASH_CONTROLLER,
                        "hash", hash,
@@ -154,10 +175,11 @@ g_hash_controller_set_hash (GHashController *controller,
     g_hash_table_unref (controller->priv->hash);
 
   controller->priv->hash = hash;
+
   if (controller->priv->hash != NULL)
     g_hash_table_ref (controller->priv->hash);
 
-  g_object_notify (G_OBJECT (controller), "hash");
+  g_object_notify_by_pspec (G_OBJECT (controller), controller_props[HASH]);
 }
 
 /**
diff --git a/glib-controller/ghashcontroller.h b/glib-controller/ghashcontroller.h
index 56ea2e7..e15b9c7 100644
--- a/glib-controller/ghashcontroller.h
+++ b/glib-controller/ghashcontroller.h
@@ -38,11 +38,12 @@ struct _GHashControllerClass
 
 GType g_hash_controller_get_type (void) G_GNUC_CONST;
 
-GController *g_hash_controller_new      (GHashTable      *hash);
+GController *   g_hash_controller_new           (void);
+GController *   g_hash_controller_new_with_hash (GHashTable      *hash);
 
-void         g_hash_controller_set_hash (GHashController *controller,
-                                         GHashTable      *hash);
-GHashTable * g_hash_controller_get_hash (GHashController *controller);
+void            g_hash_controller_set_hash      (GHashController *controller,
+                                                 GHashTable      *hash);
+GHashTable *    g_hash_controller_get_hash      (GHashController *controller);
 
 G_END_DECLS
 
diff --git a/glib-controller/gptrarraycontroller.c b/glib-controller/gptrarraycontroller.c
index e752f42..f593db5 100644
--- a/glib-controller/gptrarraycontroller.c
+++ b/glib-controller/gptrarraycontroller.c
@@ -23,10 +23,14 @@ enum
 {
   PROP_0,
 
-  PROP_ARRAY
+  ARRAY,
+
+  N_PROPERTIES
 };
 
-G_DEFINE_TYPE (GPtrArrayController, g_ptr_array_controller, G_TYPE_CONTROLLER);
+static GParamSpec *controller_props[N_PROPERTIES] = { NULL, };
+
+G_DEFINE_TYPE (GPtrArrayController, g_ptr_array_controller, G_TYPE_CONTROLLER)
 
 static void
 g_ptr_array_controller_set_property (GObject      *gobject,
@@ -38,7 +42,7 @@ g_ptr_array_controller_set_property (GObject      *gobject,
 
   switch (prop_id)
     {
-    case PROP_ARRAY:
+    case ARRAY:
       g_ptr_array_controller_set_array (self, g_value_get_boxed (value));
       break;
 
@@ -58,7 +62,7 @@ g_ptr_array_controller_get_property (GObject    *gobject,
 
   switch (prop_id)
     {
-    case PROP_ARRAY:
+    case ARRAY:
       g_value_set_boxed (value, priv->array);
       break;
 
@@ -69,39 +73,43 @@ g_ptr_array_controller_get_property (GObject    *gobject,
 }
 
 static void
-g_ptr_array_controller_finalize (GObject *gobject)
+g_ptr_array_controller_dispose (GObject *gobject)
 {
   GPtrArrayControllerPrivate *priv = G_PTR_ARRAY_CONTROLLER (gobject)->priv;
 
-  if (priv->array)
-    g_ptr_array_unref (priv->array);
+  if (priv->array != NULL)
+    {
+      g_ptr_array_unref (priv->array);
+      priv->array = NULL;
+    }
 
-  G_OBJECT_CLASS (g_ptr_array_controller_parent_class)->finalize (gobject);
+  G_OBJECT_CLASS (g_ptr_array_controller_parent_class)->dispose (gobject);
 }
 
 static void
 g_ptr_array_controller_class_init (GPtrArrayControllerClass *klass)
 {
   GObjectClass *gobject_class = G_OBJECT_CLASS (klass);
-  GParamSpec *pspec;
 
   gobject_class->set_property = g_ptr_array_controller_set_property;
   gobject_class->get_property = g_ptr_array_controller_get_property;
-  gobject_class->finalize = g_ptr_array_controller_finalize;
+  gobject_class->finalize = g_ptr_array_controller_dispose;
 
   /**
    * GPtrArrayController:array:
    *
    * The #GPtrArray to be controlled by a #GPtrArrayController instance
    */
-  pspec = g_param_spec_boxed ("array",
-                              "Array",
-                              "The GPtrArray to be controlled",
-                              G_TYPE_PTR_ARRAY,
-                              G_PARAM_READWRITE |
-                              G_PARAM_CONSTRUCT |
-                              G_PARAM_STATIC_STRINGS);
-  g_object_class_install_property (gobject_class, PROP_ARRAY, pspec);
+  controller_props[ARRAY] =
+    g_param_spec_boxed ("array",
+                        "Array",
+                        "The GPtrArray to be controlled",
+                        G_TYPE_PTR_ARRAY,
+                        G_PARAM_READWRITE |
+                        G_PARAM_CONSTRUCT |
+                        G_PARAM_STATIC_STRINGS);
+
+  g_object_class_install_properties (gobject_class, N_PROPERTIES, controller_props);
 
   g_type_class_add_private (klass, sizeof (GPtrArrayControllerPrivate));
 }
@@ -116,14 +124,27 @@ g_ptr_array_controller_init (GPtrArrayController *self)
 
 /**
  * g_ptr_array_controller_new:
+ *
+ * Creates a new #GPtrArrayController.
+ *
+ * Return value: (transfer full): the newly created #GPtrArrayController
+ */
+GController *
+g_ptr_array_controller_new (void)
+{
+  return g_object_new (G_TYPE_PTR_ARRAY_CONTROLLER, NULL);
+}
+
+/**
+ * g_ptr_array_controller_new_with_array:
  * @array: (allow-none): a #GPtrArray or %NULL
  *
- * Creates a new #GPtrArrayController controlling the @array
+ * Creates a new #GPtrArrayController controlling the @array.
  *
- * Return value: the newly created #GPtrArrayController
+ * Return value: (transfer full): the newly created #GPtrArrayController
  */
 GController *
-g_ptr_array_controller_new (GPtrArray *array)
+g_ptr_array_controller_new_with_array (GPtrArray *array)
 {
   return g_object_new (G_TYPE_PTR_ARRAY_CONTROLLER,
                        "array", array,
@@ -155,10 +176,11 @@ g_ptr_array_controller_set_array (GPtrArrayController *controller,
     g_ptr_array_unref (controller->priv->array);
 
   controller->priv->array = array;
+
   if (controller->priv->array != NULL)
     g_ptr_array_ref (controller->priv->array);
 
-  g_object_notify (G_OBJECT (controller), "array");
+  g_object_notify_by_pspec (G_OBJECT (controller), controller_props[ARRAY]);
 }
 
 /**
diff --git a/glib-controller/gptrarraycontroller.h b/glib-controller/gptrarraycontroller.h
index ee1a716..8e23745 100644
--- a/glib-controller/gptrarraycontroller.h
+++ b/glib-controller/gptrarraycontroller.h
@@ -38,11 +38,12 @@ struct _GPtrArrayControllerClass
 
 GType g_ptr_array_controller_get_type (void) G_GNUC_CONST;
 
-GController *g_ptr_array_controller_new       (GPtrArray           *array);
+GController *   g_ptr_array_controller_new              (void);
+GController *   g_ptr_array_controller_new_with_array   (GPtrArray           *array);
 
-void         g_ptr_array_controller_set_array (GPtrArrayController *controller,
-                                               GPtrArray           *array);
-GPtrArray *  g_ptr_array_controller_get_array (GPtrArrayController *controller);
+void            g_ptr_array_controller_set_array        (GPtrArrayController *controller,
+                                                         GPtrArray           *array);
+GPtrArray *     g_ptr_array_controller_get_array        (GPtrArrayController *controller);
 
 G_END_DECLS
 
diff --git a/glib-controller/tests/array-controller.c b/glib-controller/tests/array-controller.c
index 6161ac0..e93acb1 100644
--- a/glib-controller/tests/array-controller.c
+++ b/glib-controller/tests/array-controller.c
@@ -9,7 +9,7 @@ array_constructor (void)
   GArray *array;
 
   array = g_array_new (FALSE, FALSE, sizeof (int));
-  controller = g_array_controller_new (array);
+  controller = g_array_controller_new_with_array (array);
   g_assert (G_IS_ARRAY_CONTROLLER (controller));
   g_assert (g_array_controller_get_array (G_ARRAY_CONTROLLER (controller)) == array);
 
@@ -23,10 +23,10 @@ array_create_event (void)
   GController *controller;
   GControllerEvent *event;
 
-  controller = g_array_controller_new (NULL);
+  controller = g_array_controller_new ();
   event = g_controller_create_event (controller, G_CONTROLLER_CLEAR,
-                                             G_TYPE_UINT, 1,
-                                             0);
+                                     G_TYPE_UINT, 1,
+                                     0);
 
   g_assert (G_IS_CONTROLLER_EVENT (event));
   g_assert (g_controller_event_get_index_type (event) == G_TYPE_UINT);
@@ -72,7 +72,7 @@ static void
 array_emit_changed (void)
 {
   GArray *array = g_array_new (FALSE, FALSE, sizeof (int));
-  GController *controller = g_array_controller_new (array);
+  GController *controller = g_array_controller_new_with_array (array);
   ChangedClosure expected = { 0, 0 };
   GControllerEvent *ref;
   gulong id;
@@ -106,7 +106,7 @@ static void
 array_bulk_emit_changed (void)
 {
   GArray *array = g_array_new (FALSE, FALSE, sizeof (int));
-  GController *controller = g_array_controller_new (array);
+  GController *controller = g_array_controller_new_with_array (array);
   ChangedClosure expected = { 0, 0 };
   GControllerEvent *ref;
   gulong id;
diff --git a/glib-controller/tests/hash-controller.c b/glib-controller/tests/hash-controller.c
index a8615a4..0e2d84f 100644
--- a/glib-controller/tests/hash-controller.c
+++ b/glib-controller/tests/hash-controller.c
@@ -9,7 +9,7 @@ hash_constructor (void)
   GHashTable *hash;
 
   hash = g_hash_table_new (NULL, NULL);
-  controller = g_hash_controller_new (hash);
+  controller = g_hash_controller_new_with_hash (hash);
   g_assert (G_IS_HASH_CONTROLLER (controller));
   g_assert (g_hash_controller_get_hash (G_HASH_CONTROLLER (controller)) == hash);
 
@@ -23,7 +23,7 @@ hash_create_event (void)
   GController *controller;
   GControllerEvent *event;
 
-  controller = g_hash_controller_new (NULL);
+  controller = g_hash_controller_new ();
   event = g_controller_create_event (controller, G_CONTROLLER_CLEAR, G_TYPE_POINTER, 1, GINT_TO_POINTER (0xdeadbeef));
 
   g_assert (G_IS_CONTROLLER_EVENT (event));
@@ -76,7 +76,7 @@ static void
 hash_emit_changed (void)
 {
   GHashTable *hash = g_hash_table_new_full (g_str_hash, g_str_equal, NULL, g_free);
-  GController *controller = g_hash_controller_new (hash);
+  GController *controller = g_hash_controller_new_with_hash (hash);
   ChangedClosure expected = { 0, };
   GControllerEvent *ref;
   gchar *foo;



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