2010-08-30 18:58:49 +02:00
|
|
|
/*
|
|
|
|
* Copyright © 2010 Codethink Limited
|
|
|
|
*
|
|
|
|
* This program is free software: you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU Lesser General Public License as published
|
|
|
|
* by the Free Software Foundation; either version 2 of the licence or (at
|
|
|
|
* your option) any later version.
|
|
|
|
*
|
|
|
|
* This library is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
* Lesser General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Lesser General
|
2014-01-23 12:58:29 +01:00
|
|
|
* Public License along with this library; if not, see <http://www.gnu.org/licenses/>.
|
2010-08-30 18:58:49 +02:00
|
|
|
*
|
|
|
|
* Authors: Ryan Lortie <desrt@desrt.ca>
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "config.h"
|
|
|
|
|
|
|
|
#include "gsimpleaction.h"
|
|
|
|
|
|
|
|
#include "gaction.h"
|
|
|
|
#include "glibintl.h"
|
|
|
|
|
|
|
|
/**
|
|
|
|
* SECTION:gsimpleaction
|
|
|
|
* @title: GSimpleAction
|
2011-11-26 07:42:21 +01:00
|
|
|
* @short_description: A simple GAction implementation
|
2014-01-08 04:55:43 +01:00
|
|
|
* @include: gio/gio.h
|
2010-08-30 18:58:49 +02:00
|
|
|
*
|
2011-06-24 15:04:54 +02:00
|
|
|
* A #GSimpleAction is the obvious simple implementation of the #GAction
|
2011-11-26 07:42:21 +01:00
|
|
|
* interface. This is the easiest way to create an action for purposes of
|
2010-08-30 18:58:49 +02:00
|
|
|
* adding it to a #GSimpleActionGroup.
|
|
|
|
*
|
|
|
|
* See also #GtkAction.
|
2011-11-26 07:42:21 +01:00
|
|
|
*/
|
2011-06-29 11:11:59 +02:00
|
|
|
struct _GSimpleAction
|
2010-08-30 18:58:49 +02:00
|
|
|
{
|
2011-06-29 11:11:59 +02:00
|
|
|
GObject parent_instance;
|
|
|
|
|
2010-08-30 18:58:49 +02:00
|
|
|
gchar *name;
|
|
|
|
GVariantType *parameter_type;
|
2011-06-29 11:11:59 +02:00
|
|
|
gboolean enabled;
|
2010-08-30 18:58:49 +02:00
|
|
|
GVariant *state;
|
2013-10-28 22:59:26 +01:00
|
|
|
gboolean state_set_already;
|
2010-08-30 18:58:49 +02:00
|
|
|
};
|
|
|
|
|
2011-06-29 11:11:59 +02:00
|
|
|
typedef GObjectClass GSimpleActionClass;
|
|
|
|
|
|
|
|
static void g_simple_action_iface_init (GActionInterface *iface);
|
|
|
|
G_DEFINE_TYPE_WITH_CODE (GSimpleAction, g_simple_action, G_TYPE_OBJECT,
|
|
|
|
G_IMPLEMENT_INTERFACE (G_TYPE_ACTION, g_simple_action_iface_init))
|
|
|
|
|
2010-08-30 18:58:49 +02:00
|
|
|
enum
|
|
|
|
{
|
|
|
|
PROP_NONE,
|
|
|
|
PROP_NAME,
|
|
|
|
PROP_PARAMETER_TYPE,
|
|
|
|
PROP_ENABLED,
|
|
|
|
PROP_STATE_TYPE,
|
|
|
|
PROP_STATE
|
|
|
|
};
|
|
|
|
|
|
|
|
enum
|
|
|
|
{
|
2011-06-29 15:35:12 +02:00
|
|
|
SIGNAL_CHANGE_STATE,
|
2010-08-30 18:58:49 +02:00
|
|
|
SIGNAL_ACTIVATE,
|
|
|
|
NR_SIGNALS
|
|
|
|
};
|
|
|
|
|
|
|
|
static guint g_simple_action_signals[NR_SIGNALS];
|
|
|
|
|
|
|
|
static const gchar *
|
|
|
|
g_simple_action_get_name (GAction *action)
|
|
|
|
{
|
|
|
|
GSimpleAction *simple = G_SIMPLE_ACTION (action);
|
|
|
|
|
2011-06-29 11:11:59 +02:00
|
|
|
return simple->name;
|
2010-08-30 18:58:49 +02:00
|
|
|
}
|
|
|
|
|
2011-10-17 03:24:45 +02:00
|
|
|
static const GVariantType *
|
2010-08-30 18:58:49 +02:00
|
|
|
g_simple_action_get_parameter_type (GAction *action)
|
|
|
|
{
|
|
|
|
GSimpleAction *simple = G_SIMPLE_ACTION (action);
|
|
|
|
|
2011-06-29 11:11:59 +02:00
|
|
|
return simple->parameter_type;
|
2010-08-30 18:58:49 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
static const GVariantType *
|
|
|
|
g_simple_action_get_state_type (GAction *action)
|
|
|
|
{
|
|
|
|
GSimpleAction *simple = G_SIMPLE_ACTION (action);
|
|
|
|
|
2011-06-29 11:11:59 +02:00
|
|
|
if (simple->state != NULL)
|
|
|
|
return g_variant_get_type (simple->state);
|
2010-08-30 18:58:49 +02:00
|
|
|
else
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
static GVariant *
|
|
|
|
g_simple_action_get_state_hint (GAction *action)
|
|
|
|
{
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
static gboolean
|
|
|
|
g_simple_action_get_enabled (GAction *action)
|
|
|
|
{
|
|
|
|
GSimpleAction *simple = G_SIMPLE_ACTION (action);
|
|
|
|
|
2011-06-29 11:11:59 +02:00
|
|
|
return simple->enabled;
|
2010-08-30 18:58:49 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2011-06-29 11:11:59 +02:00
|
|
|
g_simple_action_change_state (GAction *action,
|
|
|
|
GVariant *value)
|
2010-08-30 18:58:49 +02:00
|
|
|
{
|
|
|
|
GSimpleAction *simple = G_SIMPLE_ACTION (action);
|
|
|
|
|
2011-06-29 15:35:12 +02:00
|
|
|
/* If the user connected a signal handler then they are responsible
|
|
|
|
* for handling state changes.
|
|
|
|
*/
|
|
|
|
if (g_signal_has_handler_pending (action, g_simple_action_signals[SIGNAL_CHANGE_STATE], 0, TRUE))
|
|
|
|
g_signal_emit (action, g_simple_action_signals[SIGNAL_CHANGE_STATE], 0, value);
|
|
|
|
|
|
|
|
/* If not, then the default behaviour is to just set the state. */
|
|
|
|
else
|
|
|
|
g_simple_action_set_state (simple, value);
|
2011-06-29 11:11:59 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* g_simple_action_set_state:
|
|
|
|
* @simple: a #GSimpleAction
|
|
|
|
* @value: the new #GVariant for the state
|
|
|
|
*
|
|
|
|
* Sets the state of the action.
|
|
|
|
*
|
|
|
|
* This directly updates the 'state' property to the given value.
|
|
|
|
*
|
|
|
|
* This should only be called by the implementor of the action. Users
|
|
|
|
* of the action should not attempt to directly modify the 'state'
|
|
|
|
* property. Instead, they should call g_action_change_state() to
|
|
|
|
* request the change.
|
|
|
|
*
|
2013-05-12 21:52:54 +02:00
|
|
|
* If the @value GVariant is floating, it is consumed.
|
|
|
|
*
|
2011-06-29 11:11:59 +02:00
|
|
|
* Since: 2.30
|
|
|
|
**/
|
|
|
|
void
|
|
|
|
g_simple_action_set_state (GSimpleAction *simple,
|
|
|
|
GVariant *value)
|
|
|
|
{
|
|
|
|
g_return_if_fail (G_IS_SIMPLE_ACTION (simple));
|
2010-08-30 18:58:49 +02:00
|
|
|
g_return_if_fail (value != NULL);
|
|
|
|
|
|
|
|
{
|
|
|
|
const GVariantType *state_type;
|
|
|
|
|
2011-06-29 11:11:59 +02:00
|
|
|
state_type = simple->state ?
|
|
|
|
g_variant_get_type (simple->state) : NULL;
|
2010-08-30 18:58:49 +02:00
|
|
|
g_return_if_fail (state_type != NULL);
|
|
|
|
g_return_if_fail (g_variant_is_of_type (value, state_type));
|
|
|
|
}
|
|
|
|
|
|
|
|
g_variant_ref_sink (value);
|
|
|
|
|
2011-06-29 11:11:59 +02:00
|
|
|
if (!simple->state || !g_variant_equal (simple->state, value))
|
2010-08-30 18:58:49 +02:00
|
|
|
{
|
2011-06-29 11:11:59 +02:00
|
|
|
if (simple->state)
|
|
|
|
g_variant_unref (simple->state);
|
2010-08-30 18:58:49 +02:00
|
|
|
|
2011-06-29 11:11:59 +02:00
|
|
|
simple->state = g_variant_ref (value);
|
2010-08-30 18:58:49 +02:00
|
|
|
|
|
|
|
g_object_notify (G_OBJECT (simple), "state");
|
|
|
|
}
|
|
|
|
|
|
|
|
g_variant_unref (value);
|
|
|
|
}
|
|
|
|
|
|
|
|
static GVariant *
|
|
|
|
g_simple_action_get_state (GAction *action)
|
|
|
|
{
|
|
|
|
GSimpleAction *simple = G_SIMPLE_ACTION (action);
|
|
|
|
|
2011-06-29 11:11:59 +02:00
|
|
|
return simple->state ? g_variant_ref (simple->state) : NULL;
|
2010-08-30 18:58:49 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
g_simple_action_activate (GAction *action,
|
|
|
|
GVariant *parameter)
|
|
|
|
{
|
|
|
|
GSimpleAction *simple = G_SIMPLE_ACTION (action);
|
|
|
|
|
2011-06-29 11:11:59 +02:00
|
|
|
g_return_if_fail (simple->parameter_type == NULL ?
|
2010-08-30 18:58:49 +02:00
|
|
|
parameter == NULL :
|
|
|
|
(parameter != NULL &&
|
|
|
|
g_variant_is_of_type (parameter,
|
2011-06-29 11:11:59 +02:00
|
|
|
simple->parameter_type)));
|
2010-08-30 18:58:49 +02:00
|
|
|
|
|
|
|
if (parameter != NULL)
|
|
|
|
g_variant_ref_sink (parameter);
|
|
|
|
|
2011-06-29 11:11:59 +02:00
|
|
|
if (simple->enabled)
|
2014-01-18 19:02:47 +01:00
|
|
|
{
|
|
|
|
/* If the user connected a signal handler then they are responsible
|
|
|
|
* for handling activation.
|
|
|
|
*/
|
|
|
|
if (g_signal_has_handler_pending (action, g_simple_action_signals[SIGNAL_ACTIVATE], 0, TRUE))
|
2014-01-18 20:27:26 +01:00
|
|
|
g_signal_emit (action, g_simple_action_signals[SIGNAL_ACTIVATE], 0, parameter);
|
2014-01-18 19:02:47 +01:00
|
|
|
|
|
|
|
/* If not, do some reasonable defaults for stateful actions. */
|
|
|
|
else if (simple->state)
|
|
|
|
{
|
|
|
|
/* If we have no parameter and this is a boolean action, toggle. */
|
|
|
|
if (parameter == NULL && g_variant_is_of_type (simple->state, G_VARIANT_TYPE_BOOLEAN))
|
|
|
|
{
|
|
|
|
gboolean was_enabled = g_variant_get_boolean (simple->state);
|
|
|
|
g_simple_action_change_state (action, g_variant_new_boolean (!was_enabled));
|
|
|
|
}
|
|
|
|
|
|
|
|
/* else, if the parameter and state type are the same, do a change-state */
|
|
|
|
else if (g_variant_is_of_type (simple->state, g_variant_get_type (parameter)))
|
|
|
|
g_simple_action_change_state (action, parameter);
|
|
|
|
}
|
|
|
|
}
|
2010-08-30 18:58:49 +02:00
|
|
|
|
|
|
|
if (parameter != NULL)
|
|
|
|
g_variant_unref (parameter);
|
|
|
|
}
|
|
|
|
|
2011-11-30 23:26:59 +01:00
|
|
|
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;
|
2011-12-21 01:12:56 +01:00
|
|
|
|
2011-11-30 23:26:59 +01:00
|
|
|
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:
|
2013-10-28 22:59:26 +01:00
|
|
|
/* The first time we see this (during construct) we should just
|
|
|
|
* take the state as it was handed to us.
|
|
|
|
*
|
|
|
|
* After that, we should make sure we go through the same checks
|
|
|
|
* as the C API.
|
|
|
|
*/
|
|
|
|
if (!action->state_set_already)
|
|
|
|
{
|
|
|
|
action->state = g_value_dup_variant (value);
|
|
|
|
action->state_set_already = TRUE;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
g_simple_action_set_state (action, g_value_get_variant (value));
|
|
|
|
|
2011-11-30 23:26:59 +01:00
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
g_assert_not_reached ();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-08-30 18:58:49 +02:00
|
|
|
static void
|
|
|
|
g_simple_action_get_property (GObject *object,
|
|
|
|
guint prop_id,
|
|
|
|
GValue *value,
|
|
|
|
GParamSpec *pspec)
|
|
|
|
{
|
|
|
|
GAction *action = G_ACTION (object);
|
|
|
|
|
|
|
|
switch (prop_id)
|
|
|
|
{
|
|
|
|
case PROP_NAME:
|
|
|
|
g_value_set_string (value, g_simple_action_get_name (action));
|
|
|
|
break;
|
|
|
|
|
|
|
|
case PROP_PARAMETER_TYPE:
|
|
|
|
g_value_set_boxed (value, g_simple_action_get_parameter_type (action));
|
|
|
|
break;
|
|
|
|
|
|
|
|
case PROP_ENABLED:
|
|
|
|
g_value_set_boolean (value, g_simple_action_get_enabled (action));
|
|
|
|
break;
|
|
|
|
|
|
|
|
case PROP_STATE_TYPE:
|
|
|
|
g_value_set_boxed (value, g_simple_action_get_state_type (action));
|
|
|
|
break;
|
|
|
|
|
|
|
|
case PROP_STATE:
|
|
|
|
g_value_take_variant (value, g_simple_action_get_state (action));
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
g_assert_not_reached ();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
g_simple_action_finalize (GObject *object)
|
|
|
|
{
|
|
|
|
GSimpleAction *simple = G_SIMPLE_ACTION (object);
|
|
|
|
|
2011-06-29 11:11:59 +02:00
|
|
|
g_free (simple->name);
|
|
|
|
if (simple->parameter_type)
|
|
|
|
g_variant_type_free (simple->parameter_type);
|
|
|
|
if (simple->state)
|
|
|
|
g_variant_unref (simple->state);
|
2010-08-30 18:58:49 +02:00
|
|
|
|
|
|
|
G_OBJECT_CLASS (g_simple_action_parent_class)
|
|
|
|
->finalize (object);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
g_simple_action_init (GSimpleAction *simple)
|
|
|
|
{
|
2011-12-01 15:38:04 +01:00
|
|
|
simple->enabled = TRUE;
|
2010-08-30 18:58:49 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
g_simple_action_iface_init (GActionInterface *iface)
|
|
|
|
{
|
|
|
|
iface->get_name = g_simple_action_get_name;
|
|
|
|
iface->get_parameter_type = g_simple_action_get_parameter_type;
|
|
|
|
iface->get_state_type = g_simple_action_get_state_type;
|
|
|
|
iface->get_state_hint = g_simple_action_get_state_hint;
|
|
|
|
iface->get_enabled = g_simple_action_get_enabled;
|
|
|
|
iface->get_state = g_simple_action_get_state;
|
2011-06-29 11:11:59 +02:00
|
|
|
iface->change_state = g_simple_action_change_state;
|
2010-08-30 18:58:49 +02:00
|
|
|
iface->activate = g_simple_action_activate;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
g_simple_action_class_init (GSimpleActionClass *class)
|
|
|
|
{
|
|
|
|
GObjectClass *object_class = G_OBJECT_CLASS (class);
|
|
|
|
|
2011-11-30 23:26:59 +01:00
|
|
|
object_class->set_property = g_simple_action_set_property;
|
2010-08-30 18:58:49 +02:00
|
|
|
object_class->get_property = g_simple_action_get_property;
|
|
|
|
object_class->finalize = g_simple_action_finalize;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* GSimpleAction::activate:
|
|
|
|
* @simple: the #GSimpleAction
|
|
|
|
* @parameter: (allow-none): the parameter to the activation
|
|
|
|
*
|
|
|
|
* Indicates that the action was just activated.
|
|
|
|
*
|
|
|
|
* @parameter will always be of the expected type. In the event that
|
|
|
|
* an incorrect type was given, no signal will be emitted.
|
|
|
|
*
|
2014-01-18 19:02:47 +01:00
|
|
|
* Since GLib 2.40, if no handler is connected to this signal then the
|
|
|
|
* default behaviour for boolean-stated actions with a %NULL parameter
|
|
|
|
* type is to toggle them via the #GSimpleAction::change-state signal.
|
|
|
|
* For stateful actions where the state type is equal to the parameter
|
|
|
|
* type, the default is to forward them directly to
|
|
|
|
* #GSimpleAction::change-state. This should allow almost all users
|
|
|
|
* of #GSimpleAction to connect only one handler or the other.
|
|
|
|
*
|
2010-10-11 21:57:09 +02:00
|
|
|
* Since: 2.28
|
2010-08-30 18:58:49 +02:00
|
|
|
*/
|
|
|
|
g_simple_action_signals[SIGNAL_ACTIVATE] =
|
|
|
|
g_signal_new (I_("activate"),
|
|
|
|
G_TYPE_SIMPLE_ACTION,
|
2011-03-04 18:21:51 +01:00
|
|
|
G_SIGNAL_RUN_LAST | G_SIGNAL_MUST_COLLECT,
|
2011-06-29 11:11:59 +02:00
|
|
|
0, NULL, NULL,
|
2010-08-30 18:58:49 +02:00
|
|
|
g_cclosure_marshal_VOID__VARIANT,
|
|
|
|
G_TYPE_NONE, 1,
|
|
|
|
G_TYPE_VARIANT);
|
|
|
|
|
2011-06-29 15:35:12 +02:00
|
|
|
/**
|
|
|
|
* GSimpleAction::change-state:
|
|
|
|
* @simple: the #GSimpleAction
|
|
|
|
* @value: (allow-none): the requested value for the state
|
|
|
|
*
|
|
|
|
* Indicates that the action just received a request to change its
|
|
|
|
* state.
|
|
|
|
*
|
|
|
|
* @value will always be of the correct state type. In the event that
|
|
|
|
* an incorrect type was given, no signal will be emitted.
|
|
|
|
*
|
|
|
|
* If no handler is connected to this signal then the default
|
|
|
|
* behaviour is to call g_simple_action_set_state() to set the state
|
2014-02-01 03:56:33 +01:00
|
|
|
* to the requested value. If you connect a signal handler then no
|
|
|
|
* default action is taken. If the state should change then you must
|
2011-06-29 15:35:12 +02:00
|
|
|
* call g_simple_action_set_state() from the handler.
|
|
|
|
*
|
2014-02-01 03:56:33 +01:00
|
|
|
* An example of a 'change-state' handler:
|
2014-02-01 21:11:49 +01:00
|
|
|
* |[<!-- language="C" -->
|
2011-06-29 15:53:24 +02:00
|
|
|
* static void
|
|
|
|
* change_volume_state (GSimpleAction *action,
|
|
|
|
* GVariant *value,
|
|
|
|
* gpointer user_data)
|
|
|
|
* {
|
|
|
|
* gint requested;
|
|
|
|
*
|
|
|
|
* requested = g_variant_get_int32 (value);
|
|
|
|
*
|
2014-02-15 03:33:36 +01:00
|
|
|
* // Volume only goes from 0 to 10
|
2011-06-29 15:53:24 +02:00
|
|
|
* if (0 <= requested && requested <= 10)
|
|
|
|
* g_simple_action_set_state (action, value);
|
|
|
|
* }
|
2014-02-01 03:56:33 +01:00
|
|
|
* ]|
|
2011-06-29 15:53:24 +02:00
|
|
|
*
|
2014-02-01 03:56:33 +01:00
|
|
|
* The handler need not set the state to the requested value.
|
|
|
|
* It could set it to any value at all, or take some other action.
|
2011-06-29 15:53:24 +02:00
|
|
|
*
|
2011-06-29 15:35:12 +02:00
|
|
|
* Since: 2.30
|
|
|
|
*/
|
|
|
|
g_simple_action_signals[SIGNAL_CHANGE_STATE] =
|
|
|
|
g_signal_new (I_("change-state"),
|
|
|
|
G_TYPE_SIMPLE_ACTION,
|
|
|
|
G_SIGNAL_RUN_LAST | G_SIGNAL_MUST_COLLECT,
|
|
|
|
0, NULL, NULL,
|
|
|
|
g_cclosure_marshal_VOID__VARIANT,
|
|
|
|
G_TYPE_NONE, 1,
|
|
|
|
G_TYPE_VARIANT);
|
|
|
|
|
2010-08-30 18:58:49 +02:00
|
|
|
/**
|
|
|
|
* GSimpleAction:name:
|
|
|
|
*
|
2014-02-01 03:56:33 +01:00
|
|
|
* The name of the action. This is mostly meaningful for identifying
|
2010-08-30 18:58:49 +02:00
|
|
|
* the action once it has been added to a #GSimpleActionGroup.
|
|
|
|
*
|
2010-10-11 21:57:09 +02:00
|
|
|
* Since: 2.28
|
2010-08-30 18:58:49 +02:00
|
|
|
**/
|
|
|
|
g_object_class_install_property (object_class, PROP_NAME,
|
|
|
|
g_param_spec_string ("name",
|
|
|
|
P_("Action Name"),
|
|
|
|
P_("The name used to invoke the action"),
|
|
|
|
NULL,
|
2011-11-30 23:26:59 +01:00
|
|
|
G_PARAM_READWRITE |
|
2011-12-21 01:11:19 +01:00
|
|
|
G_PARAM_CONSTRUCT_ONLY |
|
2010-08-30 18:58:49 +02:00
|
|
|
G_PARAM_STATIC_STRINGS));
|
|
|
|
|
|
|
|
/**
|
|
|
|
* GSimpleAction:parameter-type:
|
|
|
|
*
|
|
|
|
* The type of the parameter that must be given when activating the
|
|
|
|
* action.
|
|
|
|
*
|
2010-10-11 21:57:09 +02:00
|
|
|
* Since: 2.28
|
2010-08-30 18:58:49 +02:00
|
|
|
**/
|
|
|
|
g_object_class_install_property (object_class, PROP_PARAMETER_TYPE,
|
|
|
|
g_param_spec_boxed ("parameter-type",
|
|
|
|
P_("Parameter Type"),
|
|
|
|
P_("The type of GVariant passed to activate()"),
|
|
|
|
G_TYPE_VARIANT_TYPE,
|
2011-11-30 23:26:59 +01:00
|
|
|
G_PARAM_READWRITE |
|
2011-12-21 01:11:19 +01:00
|
|
|
G_PARAM_CONSTRUCT_ONLY |
|
2010-08-30 18:58:49 +02:00
|
|
|
G_PARAM_STATIC_STRINGS));
|
|
|
|
|
|
|
|
/**
|
|
|
|
* GSimpleAction:enabled:
|
|
|
|
*
|
|
|
|
* If @action is currently enabled.
|
|
|
|
*
|
2011-09-08 15:25:41 +02:00
|
|
|
* If the action is disabled then calls to g_action_activate() and
|
|
|
|
* g_action_change_state() have no effect.
|
2010-08-30 18:58:49 +02:00
|
|
|
*
|
2010-10-11 21:57:09 +02:00
|
|
|
* Since: 2.28
|
2010-08-30 18:58:49 +02:00
|
|
|
**/
|
|
|
|
g_object_class_install_property (object_class, PROP_ENABLED,
|
|
|
|
g_param_spec_boolean ("enabled",
|
|
|
|
P_("Enabled"),
|
|
|
|
P_("If the action can be activated"),
|
|
|
|
TRUE,
|
2011-12-21 01:11:19 +01:00
|
|
|
G_PARAM_READWRITE |
|
2010-08-30 18:58:49 +02:00
|
|
|
G_PARAM_STATIC_STRINGS));
|
|
|
|
|
|
|
|
/**
|
|
|
|
* GSimpleAction:state-type:
|
|
|
|
*
|
|
|
|
* The #GVariantType of the state that the action has, or %NULL if the
|
|
|
|
* action is stateless.
|
|
|
|
*
|
2010-10-11 21:57:09 +02:00
|
|
|
* Since: 2.28
|
2010-08-30 18:58:49 +02:00
|
|
|
**/
|
|
|
|
g_object_class_install_property (object_class, PROP_STATE_TYPE,
|
|
|
|
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_READABLE |
|
|
|
|
G_PARAM_STATIC_STRINGS));
|
|
|
|
|
|
|
|
/**
|
|
|
|
* GSimpleAction:state:
|
|
|
|
*
|
|
|
|
* The state of the action, or %NULL if the action is stateless.
|
|
|
|
*
|
2010-10-11 21:57:09 +02:00
|
|
|
* Since: 2.28
|
2010-08-30 18:58:49 +02:00
|
|
|
**/
|
|
|
|
g_object_class_install_property (object_class, PROP_STATE,
|
|
|
|
g_param_spec_variant ("state",
|
|
|
|
P_("State"),
|
|
|
|
P_("The state the action is in"),
|
|
|
|
G_VARIANT_TYPE_ANY,
|
|
|
|
NULL,
|
2013-10-28 22:59:26 +01:00
|
|
|
G_PARAM_READWRITE | G_PARAM_CONSTRUCT |
|
2010-08-30 18:58:49 +02:00
|
|
|
G_PARAM_STATIC_STRINGS));
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* g_simple_action_set_enabled:
|
|
|
|
* @simple: a #GSimpleAction
|
|
|
|
* @enabled: whether the action is enabled
|
|
|
|
*
|
|
|
|
* Sets the action as enabled or not.
|
|
|
|
*
|
|
|
|
* An action must be enabled in order to be activated or in order to
|
|
|
|
* have its state changed from outside callers.
|
|
|
|
*
|
2011-06-29 11:11:59 +02:00
|
|
|
* This should only be called by the implementor of the action. Users
|
|
|
|
* of the action should not attempt to modify its enabled flag.
|
|
|
|
*
|
2010-10-11 21:57:09 +02:00
|
|
|
* Since: 2.28
|
2010-08-30 18:58:49 +02:00
|
|
|
**/
|
|
|
|
void
|
|
|
|
g_simple_action_set_enabled (GSimpleAction *simple,
|
|
|
|
gboolean enabled)
|
|
|
|
{
|
|
|
|
g_return_if_fail (G_IS_SIMPLE_ACTION (simple));
|
|
|
|
|
|
|
|
enabled = !!enabled;
|
|
|
|
|
2011-06-29 11:11:59 +02:00
|
|
|
if (simple->enabled != enabled)
|
2010-08-30 18:58:49 +02:00
|
|
|
{
|
2011-06-29 11:11:59 +02:00
|
|
|
simple->enabled = enabled;
|
2010-08-30 18:58:49 +02:00
|
|
|
g_object_notify (G_OBJECT (simple), "enabled");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
/**
|
|
|
|
* g_simple_action_new:
|
|
|
|
* @name: the name of the action
|
|
|
|
* @parameter_type: (allow-none): the type of parameter to the activate function
|
|
|
|
*
|
|
|
|
* Creates a new action.
|
|
|
|
*
|
|
|
|
* The created action is stateless. See g_simple_action_new_stateful().
|
|
|
|
*
|
|
|
|
* Returns: a new #GSimpleAction
|
|
|
|
*
|
2010-10-11 21:57:09 +02:00
|
|
|
* Since: 2.28
|
2010-08-30 18:58:49 +02:00
|
|
|
**/
|
|
|
|
GSimpleAction *
|
|
|
|
g_simple_action_new (const gchar *name,
|
|
|
|
const GVariantType *parameter_type)
|
|
|
|
{
|
2011-12-21 01:12:56 +01:00
|
|
|
return g_object_new (G_TYPE_SIMPLE_ACTION,
|
|
|
|
"name", name,
|
|
|
|
"parameter-type", parameter_type,
|
|
|
|
NULL);
|
2010-08-30 18:58:49 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* g_simple_action_new_stateful:
|
|
|
|
* @name: the name of the action
|
|
|
|
* @parameter_type: (allow-none): the type of the parameter to the activate function
|
|
|
|
* @state: the initial state of the action
|
|
|
|
*
|
|
|
|
* Creates a new stateful action.
|
|
|
|
*
|
|
|
|
* @state is the initial state of the action. All future state values
|
|
|
|
* must have the same #GVariantType as the initial state.
|
|
|
|
*
|
|
|
|
* If the @state GVariant is floating, it is consumed.
|
|
|
|
*
|
|
|
|
* Returns: a new #GSimpleAction
|
|
|
|
*
|
2010-10-11 21:57:09 +02:00
|
|
|
* Since: 2.28
|
2010-08-30 18:58:49 +02:00
|
|
|
**/
|
|
|
|
GSimpleAction *
|
|
|
|
g_simple_action_new_stateful (const gchar *name,
|
|
|
|
const GVariantType *parameter_type,
|
|
|
|
GVariant *state)
|
|
|
|
{
|
2011-12-21 01:12:56 +01:00
|
|
|
return g_object_new (G_TYPE_SIMPLE_ACTION,
|
|
|
|
"name", name,
|
|
|
|
"parameter-type", parameter_type,
|
|
|
|
"state", state,
|
|
|
|
NULL);
|
2010-08-30 18:58:49 +02:00
|
|
|
}
|