action: Minor fixes

• Argument validation.

• Since: annotations.

• Remove (allow-none) annotations from return values.

• Coding style fixes.
This commit is contained in:
Emmanuele Bassi 2010-08-18 16:54:36 +01:00
parent 504117e284
commit 81b91a8852
2 changed files with 166 additions and 77 deletions

View File

@ -19,7 +19,9 @@
* Authors: Ryan Lortie <desrt@desrt.ca> * Authors: Ryan Lortie <desrt@desrt.ca>
*/ */
#include "config.h"
#include "gaction.h" #include "gaction.h"
#include "glibintl.h"
G_DEFINE_TYPE (GAction, g_action, G_TYPE_OBJECT) 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 * @parameter will always be of the expected type. In the event that
* an incorrect type was given, no signal will be emitted. * an incorrect type was given, no signal will be emitted.
**/ *
* Since: 2.26
*/
g_action_signals[SIGNAL_ACTIVATE] = 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), G_STRUCT_OFFSET (GActionClass, activate),
NULL, NULL, g_cclosure_marshal_VOID__VARIANT, NULL, NULL,
G_TYPE_NONE, 1, G_TYPE_VARIANT); g_cclosure_marshal_VOID__VARIANT,
G_TYPE_NONE, 1,
G_TYPE_VARIANT);
/** /**
* GAction:name: * GAction:name:
* *
* The name of the action. This is mostly meaningful for identifying * The name of the action. This is mostly meaningful for identifying
* the action once it has been added to a #GActionGroup. * the action once it has been added to a #GActionGroup.
*
* Since: 2.26
**/ **/
g_object_class_install_property (object_class, PROP_NAME, g_object_class_install_property (object_class, PROP_NAME,
g_param_spec_string ("name", "action name", g_param_spec_string ("name",
"the name used to invoke the action", P_("Action Name"),
NULL, G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY | P_("The name used to invoke the action"),
G_PARAM_STATIC_STRINGS)); NULL,
G_PARAM_READWRITE |
G_PARAM_CONSTRUCT_ONLY |
G_PARAM_STATIC_STRINGS));
/** /**
* GAction:parameter-type: * GAction:parameter-type:
* *
* The type of the parameter that must be given when activating the * The type of the parameter that must be given when activating the
* action. * action.
*
* Since: 2.26
**/ **/
g_object_class_install_property (object_class, PROP_PARAMETER_TYPE, g_object_class_install_property (object_class, PROP_PARAMETER_TYPE,
g_param_spec_boxed ("parameter-type", "parameter type", g_param_spec_boxed ("parameter-type",
"the type of GVariant passed to activate()", P_("Parameter Type"),
G_TYPE_VARIANT_TYPE, G_PARAM_READWRITE | P_("The type of GVariant passed to activate()"),
G_PARAM_CONSTRUCT_ONLY | G_PARAM_STATIC_STRINGS)); G_TYPE_VARIANT_TYPE,
G_PARAM_READWRITE |
G_PARAM_CONSTRUCT_ONLY |
G_PARAM_STATIC_STRINGS));
/** /**
* GAction:enabled: * GAction:enabled:
@ -267,35 +285,51 @@ g_action_class_init (GActionClass *class)
* *
* If the action is disabled then calls to g_action_activate() and * If the action is disabled then calls to g_action_activate() and
* g_action_set_state() have no effect. * g_action_set_state() have no effect.
*
* Since: 2.26
**/ **/
g_object_class_install_property (object_class, PROP_ENABLED, g_object_class_install_property (object_class, PROP_ENABLED,
g_param_spec_boolean ("enabled", "enabled", g_param_spec_boolean ("enabled",
"if the action can be activated", TRUE, P_("Enabled"),
G_PARAM_CONSTRUCT | G_PARAM_READWRITE | P_("If the action can be activated"),
G_PARAM_STATIC_STRINGS)); TRUE,
G_PARAM_CONSTRUCT |
G_PARAM_READWRITE |
G_PARAM_STATIC_STRINGS));
/** /**
* GAction:state-type: * GAction:state-type:
* *
* The #GVariantType of the state that the action has, or %NULL if the * The #GVariantType of the state that the action has, or %NULL if the
* action is stateless. * action is stateless.
*
* Since: 2.26
**/ **/
g_object_class_install_property (object_class, PROP_STATE_TYPE, g_object_class_install_property (object_class, PROP_STATE_TYPE,
g_param_spec_boxed ("state-type", "state type", g_param_spec_boxed ("state-type",
"the type of the state kept by the action", P_("State Type"),
G_TYPE_VARIANT_TYPE, G_PARAM_READWRITE | P_("The type of the state kept by the action"),
G_PARAM_CONSTRUCT_ONLY | G_PARAM_STATIC_STRINGS)); G_TYPE_VARIANT_TYPE,
G_PARAM_READWRITE |
G_PARAM_CONSTRUCT_ONLY |
G_PARAM_STATIC_STRINGS));
/** /**
* GAction:state: * GAction:state:
* *
* The state of the action, or %NULL if the action is stateless. * 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_object_class_install_property (object_class, PROP_STATE,
g_param_spec_variant ("state", "state", "the state the action is in", g_param_spec_variant ("state",
G_VARIANT_TYPE_ANY, NULL, P_("State"),
G_PARAM_CONSTRUCT | G_PARAM_READWRITE | P_("The state the action is in"),
G_PARAM_STATIC_STRINGS)); G_VARIANT_TYPE_ANY,
NULL,
G_PARAM_CONSTRUCT |
G_PARAM_READWRITE |
G_PARAM_STATIC_STRINGS));
g_type_class_add_private (class, sizeof (GActionPrivate)); 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); g_return_val_if_fail (G_IS_ACTION (action), NULL);
return G_ACTION_GET_CLASS (action) return G_ACTION_GET_CLASS (action)->get_state_hint (action);
->get_state_hint (action);
} }
/** /**
@ -539,13 +572,13 @@ g_action_activate (GAction *action,
g_variant_is_of_type (parameter, g_variant_is_of_type (parameter,
action->priv->parameter_type))); action->priv->parameter_type)));
if (parameter) if (parameter != NULL)
g_variant_ref_sink (parameter); g_variant_ref_sink (parameter);
if (action->priv->enabled) if (action->priv->enabled)
g_signal_emit (action, g_action_signals[SIGNAL_ACTIVATE], 0, parameter); g_signal_emit (action, g_action_signals[SIGNAL_ACTIVATE], 0, parameter);
if (parameter) if (parameter != NULL)
g_variant_unref (parameter); g_variant_unref (parameter);
} }

View File

@ -19,8 +19,11 @@
* Authors: Ryan Lortie <desrt@desrt.ca> * Authors: Ryan Lortie <desrt@desrt.ca>
*/ */
#include "config.h"
#include "gactiongroup.h" #include "gactiongroup.h"
#include "gaction.h"
#include "gio-marshal.h" #include "gio-marshal.h"
#include "glibintl.h"
/** /**
* SECTION:gactiongroup * 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 * 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. * is emitted after the action has been added and is now visible.
*
* Since: 2.26
**/ **/
g_action_group_signals[SIGNAL_ACTION_ADDED] = g_action_group_signals[SIGNAL_ACTION_ADDED] =
g_signal_new ("action-added", g_signal_new (I_("action-added"),
G_TYPE_ACTION_GROUP, G_SIGNAL_RUN_LAST, G_TYPE_ACTION_GROUP,
G_SIGNAL_RUN_LAST | G_SIGNAL_DETAILED,
G_STRUCT_OFFSET (GActionGroupClass, action_added), G_STRUCT_OFFSET (GActionGroupClass, action_added),
NULL, NULL, g_cclosure_marshal_VOID__STRING, NULL, NULL,
G_TYPE_NONE, 1, G_TYPE_STRING); g_cclosure_marshal_VOID__STRING,
G_TYPE_NONE, 1,
G_TYPE_STRING);
/** /**
* GActionGroup::action-removed: * 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. * 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 * This signal is emitted before the action is removed, so the action
* is still visible and can be queried from the signal handler. * is still visible and can be queried from the signal handler.
*
* Since: 2.26
**/ **/
g_action_group_signals[SIGNAL_ACTION_REMOVED] = g_action_group_signals[SIGNAL_ACTION_REMOVED] =
g_signal_new ("action-removed", g_signal_new (I_("action-removed"),
G_TYPE_ACTION_GROUP, G_SIGNAL_RUN_LAST, G_TYPE_ACTION_GROUP,
G_SIGNAL_RUN_LAST | G_SIGNAL_DETAILED,
G_STRUCT_OFFSET (GActionGroupClass, action_removed), G_STRUCT_OFFSET (GActionGroupClass, action_removed),
NULL, NULL, g_cclosure_marshal_VOID__STRING, NULL, NULL,
G_TYPE_NONE, 1, G_TYPE_STRING); 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 * @enabled: whether the action is enabled or not
* *
* Signals that the enabled status of the named action has changed. * Signals that the enabled status of the named action has changed.
*
* Since: 2.26
**/ **/
g_action_group_signals[SIGNAL_ACTION_ENABLED_CHANGED] = g_action_group_signals[SIGNAL_ACTION_ENABLED_CHANGED] =
g_signal_new ("action-enabled-changed", g_signal_new (I_("action-enabled-changed"),
G_TYPE_ACTION_GROUP, G_SIGNAL_RUN_LAST, G_TYPE_ACTION_GROUP,
G_SIGNAL_RUN_LAST | G_SIGNAL_DETAILED,
G_STRUCT_OFFSET (GActionGroupClass, action_enabled_changed), G_STRUCT_OFFSET (GActionGroupClass, action_enabled_changed),
NULL, NULL, _gio_marshal_VOID__STRING_BOOLEAN, NULL, NULL,
G_TYPE_NONE, 2, G_TYPE_STRING, G_TYPE_BOOLEAN); _gio_marshal_VOID__STRING_BOOLEAN,
G_TYPE_NONE, 2,
G_TYPE_STRING,
G_TYPE_BOOLEAN);
/** /**
* GActionGroup::action-state-changed: * GActionGroup::action-state-changed:
@ -120,14 +139,19 @@ g_action_group_class_init (GActionGroupClass *class)
* @value: the new value of the state * @value: the new value of the state
* *
* Signals that the state of the named action has changed. * Signals that the state of the named action has changed.
*
* Since: 2.26
**/ **/
g_action_group_signals[SIGNAL_ACTION_STATE_CHANGED] = g_action_group_signals[SIGNAL_ACTION_STATE_CHANGED] =
g_signal_new ("action-state-changed", g_signal_new (I_("action-state-changed"),
G_TYPE_ACTION_GROUP, G_SIGNAL_RUN_LAST, G_TYPE_ACTION_GROUP,
G_SIGNAL_RUN_LAST | G_SIGNAL_DETAILED,
G_STRUCT_OFFSET (GActionGroupClass, action_state_changed), G_STRUCT_OFFSET (GActionGroupClass, action_state_changed),
NULL, NULL, _gio_marshal_VOID__STRING_VARIANT, NULL, NULL,
G_TYPE_NONE, 2, G_TYPE_STRING, G_TYPE_VARIANT); _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 ** gchar **
g_action_group_list_actions (GActionGroup *action_group) g_action_group_list_actions (GActionGroup *action_group)
{ {
return G_ACTION_GROUP_GET_CLASS (action_group) g_return_val_if_fail (G_IS_ACTION_GROUP (action_group), NULL);
->list_actions (action_group);
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, g_action_group_has_action (GActionGroup *action_group,
const gchar *action_name) const gchar *action_name)
{ {
return G_ACTION_GROUP_GET_CLASS (action_group) g_return_val_if_fail (G_IS_ACTION_GROUP (action_group), FALSE);
->has_action (action_group, action_name);
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 * possible for an action to be removed and for a new action to be added
* with the same name but a different parameter type. * with the same name but a different parameter type.
* *
* Returns: (allow-none): the parameter type * Return value: the parameter type
* *
* Since: 2.26 * Since: 2.26
**/ **/
@ -196,8 +222,9 @@ const GVariantType *
g_action_group_get_parameter_type (GActionGroup *action_group, g_action_group_get_parameter_type (GActionGroup *action_group,
const gchar *action_name) const gchar *action_name)
{ {
return G_ACTION_GROUP_GET_CLASS (action_group) g_return_val_if_fail (G_IS_ACTION_GROUP (action_group), NULL);
->get_parameter_type (action_group, action_name);
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 * Since: 2.26
**/ **/
const GVariantType * const GVariantType *
g_action_group_get_state_type (GActionGroup *action_group, g_action_group_get_state_type (GActionGroup *action_group,
const gchar *action_name) const gchar *action_name)
{ {
return G_ACTION_GROUP_GET_CLASS (action_group) g_return_val_if_fail (G_IS_ACTION_GROUP (action_group), NULL);
->get_state_type (action_group, action_name);
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 * The return value (if non-%NULL) should be freed with
* g_variant_unref() when it is no longer required. * 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 * Since: 2.26
**/ **/
GVariant * GVariant *
g_action_group_get_state_hint (GActionGroup *action_group, 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) g_return_val_if_fail (G_IS_ACTION_GROUP (action_group), NULL);
->get_state_hint (action_group, action_name);
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 * An action must be enabled in order to be activated or in order to
* have its state changed from outside callers. * 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 * Since: 2.26
**/ **/
@ -287,8 +316,9 @@ gboolean
g_action_group_get_enabled (GActionGroup *action_group, g_action_group_get_enabled (GActionGroup *action_group,
const gchar *action_name) const gchar *action_name)
{ {
return G_ACTION_GROUP_GET_CLASS (action_group) g_return_val_if_fail (G_IS_ACTION_GROUP (action_group), FALSE);
->get_enabled (action_group, action_name);
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 * The return value (if non-%NULL) should be freed with
* g_variant_unref() when it is no longer required. * 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 * Since: 2.26
**/ **/
@ -313,8 +343,9 @@ GVariant *
g_action_group_get_state (GActionGroup *action_group, g_action_group_get_state (GActionGroup *action_group,
const gchar *action_name) const gchar *action_name)
{ {
return G_ACTION_GROUP_GET_CLASS (action_group) g_return_val_if_fail (G_IS_ACTION_GROUP (action_group), NULL);
->get_state (action_group, action_name);
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, const gchar *action_name,
GVariant *value) GVariant *value)
{ {
G_ACTION_GROUP_GET_CLASS (action_group) g_return_if_fail (G_IS_ACTION_GROUP (action_group));
->set_state (action_group, action_name, value); 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, const gchar *action_name,
GVariant *parameter) GVariant *parameter)
{ {
G_ACTION_GROUP_GET_CLASS (action_group) g_return_if_fail (G_IS_ACTION_GROUP (action_group));
->activate (action_group, action_name, parameter); 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_group: a #GActionGroup
* @action_name: the name of an action in the group * @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. * This function should only be called by #GActionGroup implementations.
* *
@ -383,9 +419,13 @@ void
g_action_group_action_added (GActionGroup *action_group, g_action_group_action_added (GActionGroup *action_group,
const gchar *action_name) 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_signal_emit (action_group,
g_action_group_signals[SIGNAL_ACTION_ADDED], 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_group: a #GActionGroup
* @action_name: the name of an action in the group * @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. * This function should only be called by #GActionGroup implementations.
* *
@ -403,9 +443,13 @@ void
g_action_group_action_removed (GActionGroup *action_group, g_action_group_action_removed (GActionGroup *action_group,
const gchar *action_name) 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_signal_emit (action_group,
g_action_group_signals[SIGNAL_ACTION_REMOVED], 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 * @action_name: the name of an action in the group
* @enabled: whether or not the action is now enabled * @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. * 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, const gchar *action_name,
gboolean enabled) 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_signal_emit (action_group,
g_action_group_signals[SIGNAL_ACTION_ENABLED_CHANGED], 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 * @action_name: the name of an action in the group
* @state: the new state of the named action * @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. * 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, const gchar *action_name,
GVariant *state) 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_signal_emit (action_group,
g_action_group_signals[SIGNAL_ACTION_STATE_CHANGED], 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);
} }