[glib] action: Minor fixes



commit 81b91a8852c0840d907c8192c67b2e65b29d41c6
Author: Emmanuele Bassi <ebassi linux intel com>
Date:   Wed Aug 18 16:54:36 2010 +0100

    action: Minor fixes
    
    â?¢ Argument validation.
    
    â?¢ Since: annotations.
    
    â?¢ Remove (allow-none) annotations from return values.
    
    â?¢ Coding style fixes.

 gio/gaction.c      |   89 +++++++++++++++++++++----------
 gio/gactiongroup.c |  154 +++++++++++++++++++++++++++++++++++-----------------
 2 files changed, 166 insertions(+), 77 deletions(-)
---
diff --git a/gio/gaction.c b/gio/gaction.c
index bca7378..a01b2dd 100644
--- a/gio/gaction.c
+++ b/gio/gaction.c
@@ -19,7 +19,9 @@
  * Authors: Ryan Lortie <desrt desrt ca>
  */
 
+#include "config.h"
 #include "gaction.h"
+#include "glibintl.h"
 
 G_DEFINE_TYPE (GAction, g_action, G_TYPE_OBJECT)
 
@@ -229,36 +231,52 @@ g_action_class_init (GActionClass *class)
    *
    * @parameter will always be of the expected type.  In the event that
    * an incorrect type was given, no signal will be emitted.
-   **/
+   *
+   * Since: 2.26
+   */
   g_action_signals[SIGNAL_ACTIVATE] =
-    g_signal_new ("activate", G_TYPE_ACTION, G_SIGNAL_RUN_LAST,
+    g_signal_new (I_("activate"),
+                  G_TYPE_ACTION,
+                  G_SIGNAL_RUN_LAST,
                   G_STRUCT_OFFSET (GActionClass, activate),
-                  NULL, NULL, g_cclosure_marshal_VOID__VARIANT,
-                  G_TYPE_NONE, 1, G_TYPE_VARIANT);
+                  NULL, NULL,
+                  g_cclosure_marshal_VOID__VARIANT,
+                  G_TYPE_NONE, 1,
+                  G_TYPE_VARIANT);
 
   /**
    * GAction:name:
    *
    * The name of the action.  This is mostly meaningful for identifying
    * the action once it has been added to a #GActionGroup.
+   *
+   * Since: 2.26
    **/
   g_object_class_install_property (object_class, PROP_NAME,
-    g_param_spec_string ("name", "action name",
-                         "the name used to invoke the action",
-                         NULL, G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY |
-                         G_PARAM_STATIC_STRINGS));
+                                   g_param_spec_string ("name",
+                                                        P_("Action Name"),
+                                                        P_("The name used to invoke the action"),
+                                                        NULL,
+                                                        G_PARAM_READWRITE |
+                                                        G_PARAM_CONSTRUCT_ONLY |
+                                                        G_PARAM_STATIC_STRINGS));
 
   /**
    * GAction:parameter-type:
    *
    * The type of the parameter that must be given when activating the
    * action.
+   *
+   * Since: 2.26
    **/
   g_object_class_install_property (object_class, PROP_PARAMETER_TYPE,
-    g_param_spec_boxed ("parameter-type", "parameter type",
-                        "the type of GVariant passed to activate()",
-                        G_TYPE_VARIANT_TYPE, G_PARAM_READWRITE |
-                        G_PARAM_CONSTRUCT_ONLY | G_PARAM_STATIC_STRINGS));
+                                   g_param_spec_boxed ("parameter-type",
+                                                       P_("Parameter Type"),
+                                                       P_("The type of GVariant passed to activate()"),
+                                                       G_TYPE_VARIANT_TYPE,
+                                                       G_PARAM_READWRITE |
+                                                       G_PARAM_CONSTRUCT_ONLY |
+                                                       G_PARAM_STATIC_STRINGS));
 
   /**
    * GAction:enabled:
@@ -267,35 +285,51 @@ g_action_class_init (GActionClass *class)
    *
    * If the action is disabled then calls to g_action_activate() and
    * g_action_set_state() have no effect.
+   *
+   * Since: 2.26
    **/
   g_object_class_install_property (object_class, PROP_ENABLED,
-    g_param_spec_boolean ("enabled", "enabled",
-                          "if the action can be activated", TRUE,
-                          G_PARAM_CONSTRUCT | G_PARAM_READWRITE |
-                          G_PARAM_STATIC_STRINGS));
+                                   g_param_spec_boolean ("enabled",
+                                                         P_("Enabled"),
+                                                         P_("If the action can be activated"),
+                                                         TRUE,
+                                                         G_PARAM_CONSTRUCT |
+                                                         G_PARAM_READWRITE |
+                                                         G_PARAM_STATIC_STRINGS));
 
   /**
    * GAction:state-type:
    *
    * The #GVariantType of the state that the action has, or %NULL if the
    * action is stateless.
+   *
+   * Since: 2.26
    **/
   g_object_class_install_property (object_class, PROP_STATE_TYPE,
-    g_param_spec_boxed ("state-type", "state type",
-                        "the type of the state kept by the action",
-                        G_TYPE_VARIANT_TYPE, G_PARAM_READWRITE |
-                        G_PARAM_CONSTRUCT_ONLY | G_PARAM_STATIC_STRINGS));
+                                   g_param_spec_boxed ("state-type",
+                                                       P_("State Type"),
+                                                       P_("The type of the state kept by the action"),
+                                                       G_TYPE_VARIANT_TYPE,
+                                                       G_PARAM_READWRITE |
+                                                       G_PARAM_CONSTRUCT_ONLY |
+                                                       G_PARAM_STATIC_STRINGS));
 
   /**
    * GAction:state:
    *
    * The state of the action, or %NULL if the action is stateless.
+   *
+   * Since: 2.26
    **/
   g_object_class_install_property (object_class, PROP_STATE,
-    g_param_spec_variant ("state", "state", "the state the action is in",
-                          G_VARIANT_TYPE_ANY, NULL,
-                          G_PARAM_CONSTRUCT | G_PARAM_READWRITE |
-                          G_PARAM_STATIC_STRINGS));
+                                   g_param_spec_variant ("state",
+                                                         P_("State"),
+                                                         P_("The state the action is in"),
+                                                         G_VARIANT_TYPE_ANY,
+                                                         NULL,
+                                                         G_PARAM_CONSTRUCT |
+                                                         G_PARAM_READWRITE |
+                                                         G_PARAM_STATIC_STRINGS));
 
   g_type_class_add_private (class, sizeof (GActionPrivate));
 }
@@ -462,8 +496,7 @@ g_action_get_state_hint (GAction *action)
 {
   g_return_val_if_fail (G_IS_ACTION (action), NULL);
 
-  return G_ACTION_GET_CLASS (action)
-    ->get_state_hint (action);
+  return G_ACTION_GET_CLASS (action)->get_state_hint (action);
 }
 
 /**
@@ -539,13 +572,13 @@ g_action_activate (GAction  *action,
                      g_variant_is_of_type (parameter,
                                            action->priv->parameter_type)));
 
-  if (parameter)
+  if (parameter != NULL)
     g_variant_ref_sink (parameter);
 
   if (action->priv->enabled)
     g_signal_emit (action, g_action_signals[SIGNAL_ACTIVATE], 0, parameter);
 
-  if (parameter)
+  if (parameter != NULL)
     g_variant_unref (parameter);
 }
 
diff --git a/gio/gactiongroup.c b/gio/gactiongroup.c
index 4a585df..36aa97b 100644
--- a/gio/gactiongroup.c
+++ b/gio/gactiongroup.c
@@ -19,8 +19,11 @@
  * Authors: Ryan Lortie <desrt desrt ca>
  */
 
+#include "config.h"
 #include "gactiongroup.h"
+#include "gaction.h"
 #include "gio-marshal.h"
+#include "glibintl.h"
 
 /**
  * SECTION:gactiongroup
@@ -73,13 +76,18 @@ g_action_group_class_init (GActionGroupClass *class)
    *
    * Signals that a new action was just added to the group.  This signal
    * is emitted after the action has been added and is now visible.
+   *
+   * Since: 2.26
    **/
   g_action_group_signals[SIGNAL_ACTION_ADDED] =
-    g_signal_new ("action-added",
-                  G_TYPE_ACTION_GROUP, G_SIGNAL_RUN_LAST,
+    g_signal_new (I_("action-added"),
+                  G_TYPE_ACTION_GROUP,
+                  G_SIGNAL_RUN_LAST | G_SIGNAL_DETAILED,
                   G_STRUCT_OFFSET (GActionGroupClass, action_added),
-                  NULL, NULL, g_cclosure_marshal_VOID__STRING,
-                  G_TYPE_NONE, 1, G_TYPE_STRING);
+                  NULL, NULL,
+                  g_cclosure_marshal_VOID__STRING,
+                  G_TYPE_NONE, 1,
+                  G_TYPE_STRING);
 
   /**
    * GActionGroup::action-removed:
@@ -89,13 +97,18 @@ g_action_group_class_init (GActionGroupClass *class)
    * Signals that an action is just about to be removed from the group.
    * This signal is emitted before the action is removed, so the action
    * is still visible and can be queried from the signal handler.
+   *
+   * Since: 2.26
    **/
   g_action_group_signals[SIGNAL_ACTION_REMOVED] =
-    g_signal_new ("action-removed",
-                  G_TYPE_ACTION_GROUP, G_SIGNAL_RUN_LAST,
+    g_signal_new (I_("action-removed"),
+                  G_TYPE_ACTION_GROUP,
+                  G_SIGNAL_RUN_LAST | G_SIGNAL_DETAILED,
                   G_STRUCT_OFFSET (GActionGroupClass, action_removed),
-                  NULL, NULL, g_cclosure_marshal_VOID__STRING,
-                  G_TYPE_NONE, 1, G_TYPE_STRING);
+                  NULL, NULL,
+                  g_cclosure_marshal_VOID__STRING,
+                  G_TYPE_NONE, 1,
+                  G_TYPE_STRING);
 
 
   /**
@@ -105,13 +118,19 @@ g_action_group_class_init (GActionGroupClass *class)
    * @enabled: whether the action is enabled or not
    *
    * Signals that the enabled status of the named action has changed.
+   *
+   * Since: 2.26
    **/
   g_action_group_signals[SIGNAL_ACTION_ENABLED_CHANGED] =
-    g_signal_new ("action-enabled-changed",
-                  G_TYPE_ACTION_GROUP, G_SIGNAL_RUN_LAST,
+    g_signal_new (I_("action-enabled-changed"),
+                  G_TYPE_ACTION_GROUP,
+                  G_SIGNAL_RUN_LAST | G_SIGNAL_DETAILED,
                   G_STRUCT_OFFSET (GActionGroupClass, action_enabled_changed),
-                  NULL, NULL, _gio_marshal_VOID__STRING_BOOLEAN,
-                  G_TYPE_NONE, 2, G_TYPE_STRING, G_TYPE_BOOLEAN);
+                  NULL, NULL,
+                  _gio_marshal_VOID__STRING_BOOLEAN,
+                  G_TYPE_NONE, 2,
+                  G_TYPE_STRING,
+                  G_TYPE_BOOLEAN);
 
   /**
    * GActionGroup::action-state-changed:
@@ -120,14 +139,19 @@ g_action_group_class_init (GActionGroupClass *class)
    * @value: the new value of the state
    *
    * Signals that the state of the named action has changed.
+   *
+   * Since: 2.26
    **/
   g_action_group_signals[SIGNAL_ACTION_STATE_CHANGED] =
-    g_signal_new ("action-state-changed",
-                  G_TYPE_ACTION_GROUP, G_SIGNAL_RUN_LAST,
+    g_signal_new (I_("action-state-changed"),
+                  G_TYPE_ACTION_GROUP,
+                  G_SIGNAL_RUN_LAST | G_SIGNAL_DETAILED,
                   G_STRUCT_OFFSET (GActionGroupClass, action_state_changed),
-                  NULL, NULL, _gio_marshal_VOID__STRING_VARIANT,
-                  G_TYPE_NONE, 2, G_TYPE_STRING, G_TYPE_VARIANT);
-
+                  NULL, NULL,
+                  _gio_marshal_VOID__STRING_VARIANT,
+                  G_TYPE_NONE, 2,
+                  G_TYPE_STRING,
+                  G_TYPE_VARIANT);
 }
 
 /**
@@ -146,8 +170,9 @@ g_action_group_class_init (GActionGroupClass *class)
 gchar **
 g_action_group_list_actions (GActionGroup *action_group)
 {
-  return G_ACTION_GROUP_GET_CLASS (action_group)
-    ->list_actions (action_group);
+  g_return_val_if_fail (G_IS_ACTION_GROUP (action_group), NULL);
+
+  return G_ACTION_GROUP_GET_CLASS (action_group)->list_actions (action_group);
 }
 
 /**
@@ -165,8 +190,9 @@ gboolean
 g_action_group_has_action (GActionGroup *action_group,
                            const gchar  *action_name)
 {
-  return G_ACTION_GROUP_GET_CLASS (action_group)
-    ->has_action (action_group, action_name);
+  g_return_val_if_fail (G_IS_ACTION_GROUP (action_group), FALSE);
+
+  return G_ACTION_GROUP_GET_CLASS (action_group)->has_action (action_group, action_name);
 }
 
 /**
@@ -188,7 +214,7 @@ g_action_group_has_action (GActionGroup *action_group,
  * possible for an action to be removed and for a new action to be added
  * with the same name but a different parameter type.
  *
- * Returns: (allow-none): the parameter type
+ * Return value: the parameter type
  *
  * Since: 2.26
  **/
@@ -196,8 +222,9 @@ const GVariantType *
 g_action_group_get_parameter_type (GActionGroup *action_group,
                                    const gchar  *action_name)
 {
-  return G_ACTION_GROUP_GET_CLASS (action_group)
-    ->get_parameter_type (action_group, action_name);
+  g_return_val_if_fail (G_IS_ACTION_GROUP (action_group), NULL);
+
+  return G_ACTION_GROUP_GET_CLASS (action_group)->get_parameter_type (action_group, action_name);
 }
 
 /**
@@ -225,12 +252,13 @@ g_action_group_get_parameter_type (GActionGroup *action_group,
  *
  * Since: 2.26
  **/
- const GVariantType *
+const GVariantType *
 g_action_group_get_state_type (GActionGroup *action_group,
                                const gchar  *action_name)
 {
-  return G_ACTION_GROUP_GET_CLASS (action_group)
-    ->get_state_type (action_group, action_name);
+  g_return_val_if_fail (G_IS_ACTION_GROUP (action_group), NULL);
+
+  return G_ACTION_GROUP_GET_CLASS (action_group)->get_state_type (action_group, action_name);
 }
 
 /**
@@ -257,16 +285,17 @@ g_action_group_get_state_type (GActionGroup *action_group,
  * The return value (if non-%NULL) should be freed with
  * g_variant_unref() when it is no longer required.
  *
- * Returns: (allow-none): the state range hint
+ * Return value: the state range hint
  *
  * Since: 2.26
  **/
 GVariant *
 g_action_group_get_state_hint (GActionGroup *action_group,
-                                const gchar  *action_name)
+                               const gchar  *action_name)
 {
-  return G_ACTION_GROUP_GET_CLASS (action_group)
-    ->get_state_hint (action_group, action_name);
+  g_return_val_if_fail (G_IS_ACTION_GROUP (action_group), NULL);
+
+  return G_ACTION_GROUP_GET_CLASS (action_group)->get_state_hint (action_group, action_name);
 }
 
 /**
@@ -279,7 +308,7 @@ g_action_group_get_state_hint (GActionGroup *action_group,
  * An action must be enabled in order to be activated or in order to
  * have its state changed from outside callers.
  *
- * Returns: whether or not the action is currently enabled
+ * Return value: whether or not the action is currently enabled
  *
  * Since: 2.26
  **/
@@ -287,8 +316,9 @@ gboolean
 g_action_group_get_enabled (GActionGroup *action_group,
                             const gchar  *action_name)
 {
-  return G_ACTION_GROUP_GET_CLASS (action_group)
-    ->get_enabled (action_group, action_name);
+  g_return_val_if_fail (G_IS_ACTION_GROUP (action_group), FALSE);
+
+  return G_ACTION_GROUP_GET_CLASS (action_group)->get_enabled (action_group, action_name);
 }
 
 /**
@@ -305,7 +335,7 @@ g_action_group_get_enabled (GActionGroup *action_group,
  * The return value (if non-%NULL) should be freed with
  * g_variant_unref() when it is no longer required.
  *
- * Returns: (allow-none): the current state of the action
+ * Return value: the current state of the action
  *
  * Since: 2.26
  **/
@@ -313,8 +343,9 @@ GVariant *
 g_action_group_get_state (GActionGroup *action_group,
                           const gchar  *action_name)
 {
-  return G_ACTION_GROUP_GET_CLASS (action_group)
-    ->get_state (action_group, action_name);
+  g_return_val_if_fail (G_IS_ACTION_GROUP (action_group), NULL);
+
+  return G_ACTION_GROUP_GET_CLASS (action_group)->get_state (action_group, action_name);
 }
 
 /**
@@ -340,8 +371,11 @@ g_action_group_set_state (GActionGroup *action_group,
                           const gchar  *action_name,
                           GVariant     *value)
 {
-  G_ACTION_GROUP_GET_CLASS (action_group)
-    ->set_state (action_group, action_name, value);
+  g_return_if_fail (G_IS_ACTION_GROUP (action_group));
+  g_return_if_fail (action_name != NULL);
+  g_return_if_fail (value != NULL);
+
+  G_ACTION_GROUP_GET_CLASS (action_group)->set_state (action_group, action_name, value);
 }
 
 /**
@@ -364,8 +398,10 @@ g_action_group_activate (GActionGroup *action_group,
                          const gchar  *action_name,
                          GVariant     *parameter)
 {
-  G_ACTION_GROUP_GET_CLASS (action_group)
-    ->activate (action_group, action_name, parameter);
+  g_return_if_fail (G_IS_ACTION_GROUP (action_group));
+  g_return_if_fail (action_name != NULL);
+
+  G_ACTION_GROUP_GET_CLASS (action_group)->activate (action_group, action_name, parameter);
 }
 
 /**
@@ -373,7 +409,7 @@ g_action_group_activate (GActionGroup *action_group,
  * @action_group: a #GActionGroup
  * @action_name: the name of an action in the group
  *
- * Emits the "action-added" signal on @action_group.
+ * Emits the #GActionGroup::action-added signal on @action_group.
  *
  * This function should only be called by #GActionGroup implementations.
  *
@@ -383,9 +419,13 @@ void
 g_action_group_action_added (GActionGroup *action_group,
                              const gchar  *action_name)
 {
+  g_return_if_fail (G_IS_ACTION_GROUP (action_group));
+  g_return_if_fail (action_name != NULL);
+
   g_signal_emit (action_group,
                  g_action_group_signals[SIGNAL_ACTION_ADDED],
-                 g_quark_try_string (action_name), action_name);
+                 g_quark_try_string (action_name),
+                 action_name);
 }
 
 /**
@@ -393,7 +433,7 @@ g_action_group_action_added (GActionGroup *action_group,
  * @action_group: a #GActionGroup
  * @action_name: the name of an action in the group
  *
- * Emits the "action-removed" signal on @action_group.
+ * Emits the #GActionGroup::action-removed signal on @action_group.
  *
  * This function should only be called by #GActionGroup implementations.
  *
@@ -403,9 +443,13 @@ void
 g_action_group_action_removed (GActionGroup *action_group,
                                const gchar  *action_name)
 {
+  g_return_if_fail (G_IS_ACTION_GROUP (action_group));
+  g_return_if_fail (action_name != NULL);
+
   g_signal_emit (action_group,
                  g_action_group_signals[SIGNAL_ACTION_REMOVED],
-                 g_quark_try_string (action_name), action_name);
+                 g_quark_try_string (action_name),
+                 action_name);
 }
 
 /**
@@ -414,7 +458,7 @@ g_action_group_action_removed (GActionGroup *action_group,
  * @action_name: the name of an action in the group
  * @enabled: whether or not the action is now enabled
  *
- * Emits the "action-enabled-changed" signal on @action_group.
+ * Emits the #GActionGroup::action-enabled-changed signal on @action_group.
  *
  * This function should only be called by #GActionGroup implementations.
  *
@@ -425,9 +469,16 @@ g_action_group_action_enabled_changed (GActionGroup *action_group,
                                        const gchar  *action_name,
                                        gboolean      enabled)
 {
+  g_return_if_fail (G_IS_ACTION_GROUP (action_group));
+  g_return_if_fail (action_name != NULL);
+
+  enabled = !!enabled;
+
   g_signal_emit (action_group,
                  g_action_group_signals[SIGNAL_ACTION_ENABLED_CHANGED],
-                 g_quark_try_string (action_name), action_name);
+                 g_quark_try_string (action_name),
+                 action_name,
+                 enabled);
 }
 
 /**
@@ -436,7 +487,7 @@ g_action_group_action_enabled_changed (GActionGroup *action_group,
  * @action_name: the name of an action in the group
  * @state: the new state of the named action
  *
- * Emits the "action-state-changed" signal on @action_group.
+ * Emits the #GActionGroup::action-state-changed signal on @action_group.
  *
  * This function should only be called by #GActionGroup implementations.
  *
@@ -447,7 +498,12 @@ g_action_group_action_state_changed (GActionGroup *action_group,
                                      const gchar  *action_name,
                                      GVariant     *state)
 {
+  g_return_if_fail (G_IS_ACTION_GROUP (action_group));
+  g_return_if_fail (action_name != NULL);
+
   g_signal_emit (action_group,
                  g_action_group_signals[SIGNAL_ACTION_STATE_CHANGED],
-                 g_quark_try_string (action_name), action_name);
+                 g_quark_try_string (action_name),
+                 action_name,
+                 state);
 }



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