<GActionGroup> represents a group of actions.
Actions can be used to expose functionality in a structured way, either
from one part of a program to another, or to the outside world. Action
groups are often used together with a
<GMenuModel> that provides additional
representation data for displaying the actions to the user, e.g. in a
menu.
The main way to interact with the actions in a
<GActionGroup> is to activate them with
action-group:activate-action.
Activating an action may require a <GVariant>
parameter. The required type of the parameter can be inquired with
action-group:get-action-parameter-type.
Actions may be disabled, see action-group:get-action-enabled?. Activating a
disabled action has no effect.
Actions may optionally have a state in the form of a
<GVariant>. The current state of an action
can be inquired with action-group:get-action-state. Activating a
stateful action may change its state, but it is also possible to set the
state by calling action-group:change-action-state.
As typical example, consider a text editing application which has an option to change the current font to ‘bold’. A good way to represent this would be a stateful action, with a boolean state. Activating the action would toggle the state.
Each action in the group has a unique name (which is a string). All
method calls, except action-group:list-actions take the name of an action as
an argument.
The <GActionGroup> API is meant to be the
‘public’ API to the action group. The calls here are exactly the
interaction that ‘external forces’ (eg: UI, incoming D-Bus messages,
etc.) are supposed to have with actions. ‘Internal’ APIs (ie: ones
meant only to be accessed by the action group implementation) are found
on subclasses. This is why you will find – for example –
action-group:get-action-enabled? but not an
equivalent set_action_enabled() method.
Signals are emitted on the action group in response to state changes on individual actions.
Implementations of <GActionGroup> should
provide implementations for the virtual functions action-group:list-actions and action-group:query-action. The other virtual functions
should not be implemented — their ‘wrappers’ are actually implemented
with calls to action-group:query-action.
Emits the action-group:action-added signal on self.
This function should only be called by
<GActionGroup> implementations.
Passed: a <GActionGroup>.
Passed: a string.
the name of an action in the group
Emits the action-group:action-enabled-changed signal on
self.
This function should only be called by
<GActionGroup> implementations.
Passed: a <GActionGroup>.
Passed: a string.
the name of an action in the group
Passed: a boolean.
whether the action is now enabled
Emits the action-group:action-removed signal on self.
This function should only be called by
<GActionGroup> implementations.
Passed: a <GActionGroup>.
Passed: a string.
the name of an action in the group
Emits the action-group:action-state-changed signal on
self.
This function should only be called by
<GActionGroup> implementations.
Passed: a <GActionGroup>.
Passed: a string.
the name of an action in the group
Passed: a <GVariant>.
the new state of the named action
Activate the named action within self.
If the action is expecting a parameter, then the correct type of
parameter must be given as parameter. If the action is expecting
no parameters then parameter must be NULL. See
action-group:get-action-parameter-type.
If the <GActionGroup> implementation supports
asynchronous remote activation over D-Bus, this call may return before
the relevant D-Bus traffic has been sent, or any replies have been
received. In order to block on such asynchronous activation calls,
dbus-connection:flush should be
called prior to the code, which depends on the result of the action
activation. Without flushing the D-Bus connection, there is no
guarantee that the action would have been activated.
The following code which runs in a remote app instance, shows an example
of a ‘quit’ action being activated on the primary app instance over
D-Bus. Here dbus-connection:flush is
called before exit(). Without dbus-connection:flush, the ‘quit’ action may fail to be
activated on the primary instance.
// call ‘quit’ action on primary instance
g_action_group_activate_action (G_ACTION_GROUP (app), "quit", NULL);
// make sure the action is activated now
g_dbus_connection_flush (…);
g_debug ("Application has been terminated. Exiting.");
exit (0);
Passed: a <GActionGroup>.
Passed: a string.
the name of the action to activate
Passed, or left out: a <GVariant>, or
#f.
parameters to the activation
Request for the state of the named action within self to be changed to value.
The action must be stateful and value must be of the correct type.
See action-group:get-action-state-type.
This call merely requests a change. The action may refuse to change its
state or may change its state to something other than value. See
action-group:get-action-state-hint.
If the value GVariant is floating, it is consumed.
Passed: a <GActionGroup>.
Passed: a string.
the name of the action to request the change on
Passed: a <GVariant>.
the new state
Checks if the named action within self is currently enabled.
An action must be enabled in order to be activated or in order to have its state changed from outside callers.
Passed: a <GActionGroup>.
Passed: a string.
the name of the action to query
Returned: a boolean.
whether the action is currently enabled
Queries the type of the parameter that must be given when activating the named action within self.
When activating the action using action-group:activate-action, the
<GVariant> given to that function must be of
the type returned by this function.
In the case that this function returns NULL, you must not give
any <GVariant>, but NULL instead.
The parameter type of a particular action will never change but it is possible for an action to be removed and for a new action to be added with the same name but a different parameter type.
Passed: a <GActionGroup>.
Passed: a string.
the name of the action to query
Returned: a <GVariantType>, or #f.
the parameter type
Queries the current state of the named action within self.
If the action is not stateful then NULL will be returned. If the
action is stateful then the type of the return value is the type given
by action-group:get-action-state-type.
The return value (if non-NULL) should be freed with
variant:unref when it is no longer
required.
Passed: a <GActionGroup>.
Passed: a string.
the name of the action to query
Returned: a <GVariant>, or #f.
the current state of the action
Requests a hint about the valid range of values for the state of the named action within self.
If NULL is returned it either means that the action is not
stateful or that there is no hint about the valid range of values for
the state of the action.
If a <GVariant> array is returned then each
item in the array is a possible value for the state. If a
<GVariant> pair (ie: two-tuple) is returned
then the tuple specifies the inclusive lower and upper bound of valid
values for the state.
In any case, the information is merely a hint. It may be possible to have a state value outside of the hinted range and setting a value within the range may fail.
The return value (if non-NULL) should be freed with
variant:unref when it is no longer
required.
Passed: a <GActionGroup>.
Passed: a string.
the name of the action to query
Returned: a <GVariant>, or #f.
the state range hint
Queries the type of the state of the named action within self.
If the action is stateful then this function returns the
<GVariantType> of the state. All calls
to action-group:change-action-state must give a
<GVariant> of this type and
action-group:get-action-state
will return a <GVariant> of the same type.
If the action is not stateful then this function will return
NULL. In that case, action-group:get-action-state will return
NULL and you must not call action-group:change-action-state.
The state type of a particular action will never change but it is possible for an action to be removed and for a new action to be added with the same name but a different state type.
Passed: a <GActionGroup>.
Passed: a string.
the name of the action to query
Returned: a <GVariantType>, or #f.
the state type, if the action is stateful
Checks if the named action exists within self.
Passed: a <GActionGroup>.
Passed: a string.
the name of the action to check for
Returned: a boolean.
whether the named action exists
Lists the actions contained within self.
The caller is responsible for freeing the list with
strfreev when it is no longer required.
Passed: a <GActionGroup>.
Returned: a vector, each a string.
a NULL-terminated array of the names of the actions in the group
Queries all aspects of the named action within an self.
This function acquires the information available from
action-group:has-action?,
action-group:get-action-enabled?,
action-group:get-action-parameter-type,
action-group:get-action-state-type,
action-group:get-action-state-hint and
action-group:get-action-state
with a single function call.
This provides two main benefits.
The first is the improvement in efficiency that comes with not having to
perform repeated lookups of the action in order to discover different
things about it. The second is that implementing
<GActionGroup> can now be done by only
overriding this one virtual function.
The interface provides a default implementation of this function that calls the individual functions, as required, to fetch the information. The interface also provides default implementations of those functions that call this function. All implementations, therefore, must override either this function or all of the others.
If the action exists, TRUE is returned and any of the requested
fields (as indicated by having a non-NULL reference passed in)
are filled. If the action doesn’t exist, FALSE is returned and
the fields may or may not have been modified.
Passed: a <GActionGroup>.
Passed: a string.
the name of an action in the group
Returned: a boolean.
TRUE if the action exists, else FALSE
Returned: a boolean.
if the action is presently enabled
Returned: a <GVariantType>.
the parameter type, or NULL if none needed
Returned: a <GVariantType>.
the state type, or NULL if stateless
Returned: a <GVariant>.
the state hint, or NULL if none
Returned: a <GVariant>.
the current state, or NULL if stateless
Connect a handler with (connect object action-group:action-added
handler). It is called as (handler self action-name).
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.
Passed: a <GActionGroup>.
Passed: a string.
the name of the action in action-group
Connect a handler with (connect object
action-group:action-enabled-changed handler). It is called as
(handler self action-name enabled).
Signals that the enabled status of the named action has changed.
Passed: a <GActionGroup>.
Passed: a string.
the name of the action in action-group
Passed: a boolean.
whether the action is enabled
Connect a handler with (connect object action-group:action-removed
handler). It is called as (handler self action-name).
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.
Passed: a <GActionGroup>.
Passed: a string.
the name of the action in action-group
Connect a handler with (connect object
action-group:action-state-changed handler). It is called as
(handler self action-name value).
Signals that the state of the named action has changed.
Passed: a <GActionGroup>.
Passed: a string.
the name of the action in action-group
Passed: a <GVariant>.
the new value of the state
Emits the action-group:action-added signal on self.
This function should only be called by
<GActionGroup> implementations.
To override it in a new class, give register-type #:vfuncs
`((action-added . ,procedure)). The procedure is called as
(procedure self action-name).
Passed: the class whose implementation to call: a class that implements
<GActionGroup>, or its GType number.
Passed: a <GActionGroup>.
Passed: a string.
the name of an action in the group
Emits the action-group:action-enabled-changed signal on
self.
This function should only be called by
<GActionGroup> implementations.
To override it in a new class, give register-type #:vfuncs
`((action-enabled-changed . ,procedure)). The procedure is called as
(procedure self action-name enabled).
Passed: the class whose implementation to call: a class that implements
<GActionGroup>, or its GType number.
Passed: a <GActionGroup>.
Passed: a string.
the name of an action in the group
Passed: a boolean.
whether the action is now enabled
Emits the action-group:action-removed signal on self.
This function should only be called by
<GActionGroup> implementations.
To override it in a new class, give register-type #:vfuncs
`((action-removed . ,procedure)). The procedure is called as
(procedure self action-name).
Passed: the class whose implementation to call: a class that implements
<GActionGroup>, or its GType number.
Passed: a <GActionGroup>.
Passed: a string.
the name of an action in the group
Emits the action-group:action-state-changed signal on
self.
This function should only be called by
<GActionGroup> implementations.
To override it in a new class, give register-type #:vfuncs
`((action-state-changed . ,procedure)). The procedure is called as
(procedure self action-name state).
Passed: the class whose implementation to call: a class that implements
<GActionGroup>, or its GType number.
Passed: a <GActionGroup>.
Passed: a string.
the name of an action in the group
Passed: a <GVariant>.
the new state of the named action
Activate the named action within self.
If the action is expecting a parameter, then the correct type of
parameter must be given as parameter. If the action is expecting
no parameters then parameter must be NULL. See
action-group:get-action-parameter-type.
If the <GActionGroup> implementation supports
asynchronous remote activation over D-Bus, this call may return before
the relevant D-Bus traffic has been sent, or any replies have been
received. In order to block on such asynchronous activation calls,
dbus-connection:flush should be
called prior to the code, which depends on the result of the action
activation. Without flushing the D-Bus connection, there is no
guarantee that the action would have been activated.
The following code which runs in a remote app instance, shows an example
of a ‘quit’ action being activated on the primary app instance over
D-Bus. Here dbus-connection:flush is
called before exit(). Without dbus-connection:flush, the ‘quit’ action may fail to be
activated on the primary instance.
// call ‘quit’ action on primary instance
g_action_group_activate_action (G_ACTION_GROUP (app), "quit", NULL);
// make sure the action is activated now
g_dbus_connection_flush (…);
g_debug ("Application has been terminated. Exiting.");
exit (0);
To override it in a new class, give register-type #:vfuncs
`((activate-action . ,procedure)). The procedure is called as
(procedure self action-name parameter).
Passed: the class whose implementation to call: a class that implements
<GActionGroup>, or its GType number.
Passed: a <GActionGroup>.
Passed: a string.
the name of the action to activate
Passed, or left out: a <GVariant>, or
#f.
parameters to the activation
Request for the state of the named action within self to be changed to value.
The action must be stateful and value must be of the correct type.
See action-group:get-action-state-type.
This call merely requests a change. The action may refuse to change its
state or may change its state to something other than value. See
action-group:get-action-state-hint.
If the value GVariant is floating, it is consumed.
To override it in a new class, give register-type #:vfuncs
`((change-action-state . ,procedure)). The procedure is called as
(procedure self action-name value).
Passed: the class whose implementation to call: a class that implements
<GActionGroup>, or its GType number.
Passed: a <GActionGroup>.
Passed: a string.
the name of the action to request the change on
Passed: a <GVariant>.
the new state
Checks if the named action within self is currently enabled.
An action must be enabled in order to be activated or in order to have its state changed from outside callers.
To override it in a new class, give register-type #:vfuncs
`((get-action-enabled . ,procedure)). The procedure is called as
(procedure self action-name) ⇒ %return.
Passed: the class whose implementation to call: a class that implements
<GActionGroup>, or its GType number.
Passed: a <GActionGroup>.
Passed: a string.
the name of the action to query
Returned: a boolean.
whether the action is currently enabled
Queries the type of the parameter that must be given when activating the named action within self.
When activating the action using action-group:activate-action, the
<GVariant> given to that function must be of
the type returned by this function.
In the case that this function returns NULL, you must not give
any <GVariant>, but NULL instead.
The parameter type of a particular action will never change but it is possible for an action to be removed and for a new action to be added with the same name but a different parameter type.
To override it in a new class, give register-type #:vfuncs
`((get-action-parameter-type . ,procedure)). The procedure is called
as (procedure self action-name) ⇒ %return.
Passed: the class whose implementation to call: a class that implements
<GActionGroup>, or its GType number.
Passed: a <GActionGroup>.
Passed: a string.
the name of the action to query
Returned: a <GVariantType>, or #f.
the parameter type
Queries the current state of the named action within self.
If the action is not stateful then NULL will be returned. If the
action is stateful then the type of the return value is the type given
by action-group:get-action-state-type.
The return value (if non-NULL) should be freed with
variant:unref when it is no longer
required.
To override it in a new class, give register-type #:vfuncs
`((get-action-state . ,procedure)). The procedure is called as
(procedure self action-name) ⇒ %return.
Passed: the class whose implementation to call: a class that implements
<GActionGroup>, or its GType number.
Passed: a <GActionGroup>.
Passed: a string.
the name of the action to query
Returned: a <GVariant>, or #f.
the current state of the action
Requests a hint about the valid range of values for the state of the named action within self.
If NULL is returned it either means that the action is not
stateful or that there is no hint about the valid range of values for
the state of the action.
If a <GVariant> array is returned then each
item in the array is a possible value for the state. If a
<GVariant> pair (ie: two-tuple) is returned
then the tuple specifies the inclusive lower and upper bound of valid
values for the state.
In any case, the information is merely a hint. It may be possible to have a state value outside of the hinted range and setting a value within the range may fail.
The return value (if non-NULL) should be freed with
variant:unref when it is no longer
required.
To override it in a new class, give register-type #:vfuncs
`((get-action-state-hint . ,procedure)). The procedure is called as
(procedure self action-name) ⇒ %return.
Passed: the class whose implementation to call: a class that implements
<GActionGroup>, or its GType number.
Passed: a <GActionGroup>.
Passed: a string.
the name of the action to query
Returned: a <GVariant>, or #f.
the state range hint
Queries the type of the state of the named action within self.
If the action is stateful then this function returns the
<GVariantType> of the state. All calls
to action-group:change-action-state must give a
<GVariant> of this type and
action-group:get-action-state
will return a <GVariant> of the same type.
If the action is not stateful then this function will return
NULL. In that case, action-group:get-action-state will return
NULL and you must not call action-group:change-action-state.
The state type of a particular action will never change but it is possible for an action to be removed and for a new action to be added with the same name but a different state type.
To override it in a new class, give register-type #:vfuncs
`((get-action-state-type . ,procedure)). The procedure is called as
(procedure self action-name) ⇒ %return.
Passed: the class whose implementation to call: a class that implements
<GActionGroup>, or its GType number.
Passed: a <GActionGroup>.
Passed: a string.
the name of the action to query
Returned: a <GVariantType>, or #f.
the state type, if the action is stateful
Checks if the named action exists within self.
To override it in a new class, give register-type #:vfuncs
`((has-action . ,procedure)). The procedure is called as
(procedure self action-name) ⇒ %return.
Passed: the class whose implementation to call: a class that implements
<GActionGroup>, or its GType number.
Passed: a <GActionGroup>.
Passed: a string.
the name of the action to check for
Returned: a boolean.
whether the named action exists
Lists the actions contained within self.
The caller is responsible for freeing the list with
strfreev when it is no longer required.
To override it in a new class, give register-type #:vfuncs
`((list-actions . ,procedure)). The procedure is called as
(procedure self) ⇒ %return.
Passed: the class whose implementation to call: a class that implements
<GActionGroup>, or its GType number.
Passed: a <GActionGroup>.
Returned: a vector, each a string.
a NULL-terminated array of the names of the actions in the group
Queries all aspects of the named action within an self.
This function acquires the information available from
action-group:has-action?,
action-group:get-action-enabled?,
action-group:get-action-parameter-type,
action-group:get-action-state-type,
action-group:get-action-state-hint and
action-group:get-action-state
with a single function call.
This provides two main benefits.
The first is the improvement in efficiency that comes with not having to
perform repeated lookups of the action in order to discover different
things about it. The second is that implementing
<GActionGroup> can now be done by only
overriding this one virtual function.
The interface provides a default implementation of this function that calls the individual functions, as required, to fetch the information. The interface also provides default implementations of those functions that call this function. All implementations, therefore, must override either this function or all of the others.
If the action exists, TRUE is returned and any of the requested
fields (as indicated by having a non-NULL reference passed in)
are filled. If the action doesn’t exist, FALSE is returned and
the fields may or may not have been modified.
To override it in a new class, give register-type #:vfuncs
`((query-action . ,procedure)). The procedure is called as
(procedure self action-name) ⇒ %return enabled parameter-type
state-type state-hint state.
Passed: the class whose implementation to call: a class that implements
<GActionGroup>, or its GType number.
Passed: a <GActionGroup>.
Passed: a string.
the name of an action in the group
Returned: a boolean.
TRUE if the action exists, else FALSE
Returned: a boolean.
if the action is presently enabled
Returned: a <GVariantType>.
the parameter type, or NULL if none needed
Returned: a <GVariantType>.
the state type, or NULL if stateless
Returned: a <GVariant>.
the state hint, or NULL if none
Returned: a <GVariant>.
the current state, or NULL if stateless