[glib] GSimpleAction: Fix to comply with constructor rules



commit 41e5ba86a791a17bb560dd7813ad7e849e0230dc
Author: Colin Walters <walters verbum org>
Date:   Wed Nov 30 17:26:59 2011 -0500

    GSimpleAction: Fix to comply with constructor rules
    
    foo_new_*() must be pure wrappers around g_object_new(), otherwise
    their functionality is inaccessible to bindings.

 gio/gaction.c       |   12 +++++--
 gio/gsimpleaction.c |   82 ++++++++++++++++++++++++++++++--------------------
 2 files changed, 57 insertions(+), 37 deletions(-)
---
diff --git a/gio/gaction.c b/gio/gaction.c
index 8789d08..f2d9752 100644
--- a/gio/gaction.c
+++ b/gio/gaction.c
@@ -77,7 +77,8 @@ g_action_default_init (GActionInterface *iface)
                                                             P_("Action Name"),
                                                             P_("The name used to invoke the action"),
                                                             NULL,
-                                                            G_PARAM_READABLE |
+                                                            G_PARAM_READWRITE |
+							    G_PARAM_CONSTRUCT_ONLY |
                                                             G_PARAM_STATIC_STRINGS));
 
   /**
@@ -93,7 +94,8 @@ g_action_default_init (GActionInterface *iface)
                                                            P_("Parameter Type"),
                                                            P_("The type of GVariant passed to activate()"),
                                                            G_TYPE_VARIANT_TYPE,
-                                                           G_PARAM_READABLE |
+							   G_PARAM_READWRITE |
+							   G_PARAM_CONSTRUCT_ONLY |
                                                            G_PARAM_STATIC_STRINGS));
 
   /**
@@ -111,7 +113,8 @@ g_action_default_init (GActionInterface *iface)
                                                              P_("Enabled"),
                                                              P_("If the action can be activated"),
                                                              TRUE,
-                                                             G_PARAM_READABLE |
+							     G_PARAM_READWRITE |
+							     G_PARAM_CONSTRUCT_ONLY |
                                                              G_PARAM_STATIC_STRINGS));
 
   /**
@@ -143,7 +146,8 @@ g_action_default_init (GActionInterface *iface)
                                                              P_("The state the action is in"),
                                                              G_VARIANT_TYPE_ANY,
                                                              NULL,
-                                                             G_PARAM_READABLE |
+							     G_PARAM_READWRITE |
+							     G_PARAM_CONSTRUCT_ONLY |
                                                              G_PARAM_STATIC_STRINGS));
 }
 
diff --git a/gio/gsimpleaction.c b/gio/gsimpleaction.c
index c0d5340..d412e1d 100644
--- a/gio/gsimpleaction.c
+++ b/gio/gsimpleaction.c
@@ -208,6 +208,37 @@ g_simple_action_activate (GAction  *action,
 }
 
 static void
+g_simple_action_set_property (GObject    *object,
+                              guint       prop_id,
+                              const GValue     *value,
+                              GParamSpec *pspec)
+{
+  GSimpleAction *action = G_SIMPLE_ACTION (object);
+
+  switch (prop_id)
+    {
+    case PROP_NAME:
+      action->name = g_strdup (g_value_get_string (value));
+      break;
+      
+    case PROP_PARAMETER_TYPE:
+      action->parameter_type = g_value_dup_boxed (value);
+      break;
+
+    case PROP_ENABLED:
+      action->enabled = g_value_get_boolean (value);
+      break;
+
+    case PROP_STATE:
+      action->state = g_value_dup_variant (value);
+      break;
+
+    default:
+      g_assert_not_reached ();
+    }
+}
+
+static void
 g_simple_action_get_property (GObject    *object,
                               guint       prop_id,
                               GValue     *value,
@@ -280,6 +311,7 @@ g_simple_action_class_init (GSimpleActionClass *class)
 {
   GObjectClass *object_class = G_OBJECT_CLASS (class);
 
+  object_class->set_property = g_simple_action_set_property;
   object_class->get_property = g_simple_action_get_property;
   object_class->finalize = g_simple_action_finalize;
 
@@ -367,7 +399,8 @@ g_simple_action_class_init (GSimpleActionClass *class)
                                                         P_("Action Name"),
                                                         P_("The name used to invoke the action"),
                                                         NULL,
-                                                        G_PARAM_READABLE |
+                                                        G_PARAM_READWRITE |
+							G_PARAM_CONSTRUCT_ONLY |
                                                         G_PARAM_STATIC_STRINGS));
 
   /**
@@ -383,7 +416,8 @@ g_simple_action_class_init (GSimpleActionClass *class)
                                                        P_("Parameter Type"),
                                                        P_("The type of GVariant passed to activate()"),
                                                        G_TYPE_VARIANT_TYPE,
-                                                       G_PARAM_READABLE |
+                                                       G_PARAM_READWRITE |
+						       G_PARAM_CONSTRUCT_ONLY |
                                                        G_PARAM_STATIC_STRINGS));
 
   /**
@@ -401,7 +435,8 @@ g_simple_action_class_init (GSimpleActionClass *class)
                                                          P_("Enabled"),
                                                          P_("If the action can be activated"),
                                                          TRUE,
-                                                         G_PARAM_READABLE |
+							 G_PARAM_READWRITE |
+							 G_PARAM_CONSTRUCT_ONLY |
                                                          G_PARAM_STATIC_STRINGS));
 
   /**
@@ -433,7 +468,8 @@ g_simple_action_class_init (GSimpleActionClass *class)
                                                          P_("The state the action is in"),
                                                          G_VARIANT_TYPE_ANY,
                                                          NULL,
-                                                         G_PARAM_READABLE |
+							 G_PARAM_READWRITE |
+							 G_PARAM_CONSTRUCT_ONLY |
                                                          G_PARAM_STATIC_STRINGS));
 }
 
@@ -483,19 +519,10 @@ GSimpleAction *
 g_simple_action_new (const gchar        *name,
                      const GVariantType *parameter_type)
 {
-  GSimpleAction *simple;
-
-  g_return_val_if_fail (name != NULL, NULL);
-
-  simple = g_object_new (G_TYPE_SIMPLE_ACTION, NULL);
-  simple->name = g_strdup (name);
-
-  if (parameter_type)
-    simple->parameter_type = g_variant_type_copy (parameter_type);
-
-  simple->enabled = TRUE;
-
-  return simple;
+  return (GSimpleAction*) g_object_new (G_TYPE_SIMPLE_ACTION,
+					"name", name,
+					"parameter-type", parameter_type,
+					NULL);
 }
 
 /**
@@ -520,20 +547,9 @@ g_simple_action_new_stateful (const gchar        *name,
                               const GVariantType *parameter_type,
                               GVariant           *state)
 {
-  GSimpleAction *simple;
-
-  g_return_val_if_fail (name != NULL, NULL);
-  g_return_val_if_fail (state != NULL, NULL);
-
-  simple = g_object_new (G_TYPE_SIMPLE_ACTION, NULL);
-  simple->name = g_strdup (name);
-
-  if (parameter_type)
-    simple->parameter_type = g_variant_type_copy (parameter_type);
-
-  simple->state = g_variant_ref_sink (state);
-
-  simple->enabled = TRUE;
-
-  return simple;
+  return (GSimpleAction*) g_object_new (G_TYPE_SIMPLE_ACTION,
+					"name", name,
+					"parameter-type", parameter_type,
+					"state", state,
+					NULL);
 }



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