2013-06-28 17:41:43 +02:00
|
|
|
|
/*
|
|
|
|
|
* Copyright © 2013 Canonical Limited
|
|
|
|
|
*
|
2022-05-18 10:12:45 +02:00
|
|
|
|
* SPDX-License-Identifier: LGPL-2.1-or-later
|
|
|
|
|
*
|
2017-05-27 18:21:30 +02:00
|
|
|
|
* This library 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.1 of the License, or (at your option) any later version.
|
2013-06-28 17:41:43 +02:00
|
|
|
|
*
|
|
|
|
|
* 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/>.
|
2013-06-28 17:41:43 +02:00
|
|
|
|
*
|
|
|
|
|
* Authors: Ryan Lortie <desrt@desrt.ca>
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
#include "config.h"
|
|
|
|
|
|
|
|
|
|
#include "gpropertyaction.h"
|
|
|
|
|
|
|
|
|
|
#include "gsettings-mapping.h"
|
|
|
|
|
#include "gaction.h"
|
|
|
|
|
#include "glibintl.h"
|
|
|
|
|
|
|
|
|
|
/**
|
2023-10-24 11:55:38 +02:00
|
|
|
|
* GPropertyAction:
|
2013-06-28 17:41:43 +02:00
|
|
|
|
*
|
2023-10-24 11:55:38 +02:00
|
|
|
|
* A `GPropertyAction` is a way to get a [iface@Gio.Action] with a state value
|
|
|
|
|
* reflecting and controlling the value of a [class@GObject.Object] property.
|
2013-06-28 17:41:43 +02:00
|
|
|
|
*
|
|
|
|
|
* The state of the action will correspond to the value of the property.
|
|
|
|
|
* Changing it will change the property (assuming the requested value
|
2023-10-24 11:55:38 +02:00
|
|
|
|
* matches the requirements as specified in the [type@GObject.ParamSpec]).
|
2013-06-28 17:41:43 +02:00
|
|
|
|
*
|
|
|
|
|
* Only the most common types are presently supported. Booleans are
|
|
|
|
|
* mapped to booleans, strings to strings, signed/unsigned integers to
|
|
|
|
|
* int32/uint32 and floats and doubles to doubles.
|
|
|
|
|
*
|
|
|
|
|
* If the property is an enum then the state will be string-typed and
|
|
|
|
|
* conversion will automatically be performed between the enum value and
|
2023-10-24 11:55:38 +02:00
|
|
|
|
* ‘nick’ string as per the [type@GObject.EnumValue] table.
|
2013-06-28 17:41:43 +02:00
|
|
|
|
*
|
|
|
|
|
* Flags types are not currently supported.
|
|
|
|
|
*
|
|
|
|
|
* Properties of object types, boxed types and pointer types are not
|
|
|
|
|
* supported and probably never will be.
|
|
|
|
|
*
|
2023-10-24 11:55:38 +02:00
|
|
|
|
* Properties of [type@GLib.Variant] types are not currently supported.
|
2013-06-28 17:41:43 +02:00
|
|
|
|
*
|
2023-10-24 11:55:38 +02:00
|
|
|
|
* If the property is boolean-valued then the action will have a `NULL`
|
2013-06-28 17:41:43 +02:00
|
|
|
|
* parameter type, and activating the action (with no parameter) will
|
|
|
|
|
* toggle the value of the property.
|
|
|
|
|
*
|
|
|
|
|
* In all other cases, the parameter type will correspond to the type of
|
|
|
|
|
* the property.
|
|
|
|
|
*
|
|
|
|
|
* The general idea here is to reduce the number of locations where a
|
2014-02-08 19:22:58 +01:00
|
|
|
|
* particular piece of state is kept (and therefore has to be synchronised
|
2023-10-24 11:55:38 +02:00
|
|
|
|
* between). `GPropertyAction` does not have a separate state that is kept
|
|
|
|
|
* in sync with the property value — its state is the property value.
|
2013-06-28 17:41:43 +02:00
|
|
|
|
*
|
2023-10-24 11:55:38 +02:00
|
|
|
|
* For example, it might be useful to create a [iface@Gio.Action] corresponding
|
2024-01-15 15:43:53 +01:00
|
|
|
|
* to the `visible-child-name` property of a [`GtkStack`](https://docs.gtk.org/gtk4/class.Stack.html)
|
|
|
|
|
* so that the current page can be switched from a menu. The active radio
|
|
|
|
|
* indication in the menu is then directly determined from the active page of
|
|
|
|
|
* the `GtkStack`.
|
2013-06-28 17:41:43 +02:00
|
|
|
|
*
|
2023-10-24 11:55:38 +02:00
|
|
|
|
* An anti-example would be binding the `active-id` property on a
|
2024-01-15 15:43:53 +01:00
|
|
|
|
* [`GtkComboBox`](https://docs.gtk.org/gtk4/class.ComboBox.html). This is
|
|
|
|
|
* because the state of the combo box itself is probably uninteresting and is
|
|
|
|
|
* actually being used to control something else.
|
2013-06-28 17:41:43 +02:00
|
|
|
|
*
|
2023-10-24 11:55:38 +02:00
|
|
|
|
* Another anti-example would be to bind to the `visible-child-name`
|
2024-01-15 15:43:53 +01:00
|
|
|
|
* property of a [`GtkStack`](https://docs.gtk.org/gtk4/class.Stack.html) if
|
|
|
|
|
* this value is actually stored in [class@Gio.Settings]. In that case, the
|
|
|
|
|
* real source of the value is* [class@Gio.Settings]. If you want
|
|
|
|
|
* a [iface@Gio.Action] to control a setting stored in [class@Gio.Settings],
|
|
|
|
|
* see [method@Gio.Settings.create_action] instead, and possibly combine its
|
|
|
|
|
* use with [method@Gio.Settings.bind].
|
2013-06-28 17:41:43 +02:00
|
|
|
|
*
|
|
|
|
|
* Since: 2.38
|
|
|
|
|
**/
|
|
|
|
|
struct _GPropertyAction
|
|
|
|
|
{
|
|
|
|
|
GObject parent_instance;
|
|
|
|
|
|
|
|
|
|
gchar *name;
|
|
|
|
|
gpointer object;
|
|
|
|
|
GParamSpec *pspec;
|
|
|
|
|
const GVariantType *state_type;
|
2015-03-29 20:00:36 +02:00
|
|
|
|
gboolean invert_boolean;
|
2013-06-28 17:41:43 +02:00
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
typedef GObjectClass GPropertyActionClass;
|
|
|
|
|
|
|
|
|
|
static void g_property_action_iface_init (GActionInterface *iface);
|
|
|
|
|
G_DEFINE_TYPE_WITH_CODE (GPropertyAction, g_property_action, G_TYPE_OBJECT,
|
|
|
|
|
G_IMPLEMENT_INTERFACE (G_TYPE_ACTION, g_property_action_iface_init))
|
|
|
|
|
|
|
|
|
|
enum
|
|
|
|
|
{
|
|
|
|
|
PROP_NONE,
|
|
|
|
|
PROP_NAME,
|
|
|
|
|
PROP_PARAMETER_TYPE,
|
|
|
|
|
PROP_ENABLED,
|
|
|
|
|
PROP_STATE_TYPE,
|
|
|
|
|
PROP_STATE,
|
|
|
|
|
PROP_OBJECT,
|
2015-03-29 20:00:36 +02:00
|
|
|
|
PROP_PROPERTY_NAME,
|
|
|
|
|
PROP_INVERT_BOOLEAN
|
2013-06-28 17:41:43 +02:00
|
|
|
|
};
|
|
|
|
|
|
2015-03-29 20:00:36 +02:00
|
|
|
|
static gboolean
|
|
|
|
|
g_property_action_get_invert_boolean (GAction *action)
|
|
|
|
|
{
|
|
|
|
|
GPropertyAction *paction = G_PROPERTY_ACTION (action);
|
|
|
|
|
|
|
|
|
|
return paction->invert_boolean;
|
|
|
|
|
}
|
|
|
|
|
|
2013-06-28 17:41:43 +02:00
|
|
|
|
static const gchar *
|
|
|
|
|
g_property_action_get_name (GAction *action)
|
|
|
|
|
{
|
|
|
|
|
GPropertyAction *paction = G_PROPERTY_ACTION (action);
|
|
|
|
|
|
|
|
|
|
return paction->name;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static const GVariantType *
|
|
|
|
|
g_property_action_get_parameter_type (GAction *action)
|
|
|
|
|
{
|
|
|
|
|
GPropertyAction *paction = G_PROPERTY_ACTION (action);
|
|
|
|
|
|
|
|
|
|
return paction->pspec->value_type == G_TYPE_BOOLEAN ? NULL : paction->state_type;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static const GVariantType *
|
|
|
|
|
g_property_action_get_state_type (GAction *action)
|
|
|
|
|
{
|
|
|
|
|
GPropertyAction *paction = G_PROPERTY_ACTION (action);
|
|
|
|
|
|
|
|
|
|
return paction->state_type;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static GVariant *
|
|
|
|
|
g_property_action_get_state_hint (GAction *action)
|
|
|
|
|
{
|
2019-06-10 02:01:57 +02:00
|
|
|
|
GPropertyAction *paction = G_PROPERTY_ACTION (action);
|
|
|
|
|
|
|
|
|
|
if (paction->pspec->value_type == G_TYPE_INT)
|
|
|
|
|
{
|
|
|
|
|
GParamSpecInt *pspec = (GParamSpecInt *)paction->pspec;
|
|
|
|
|
return g_variant_new ("(ii)", pspec->minimum, pspec->maximum);
|
|
|
|
|
}
|
|
|
|
|
else if (paction->pspec->value_type == G_TYPE_UINT)
|
|
|
|
|
{
|
|
|
|
|
GParamSpecUInt *pspec = (GParamSpecUInt *)paction->pspec;
|
|
|
|
|
return g_variant_new ("(uu)", pspec->minimum, pspec->maximum);
|
|
|
|
|
}
|
|
|
|
|
else if (paction->pspec->value_type == G_TYPE_FLOAT)
|
|
|
|
|
{
|
|
|
|
|
GParamSpecFloat *pspec = (GParamSpecFloat *)paction->pspec;
|
|
|
|
|
return g_variant_new ("(dd)", (double)pspec->minimum, (double)pspec->maximum);
|
|
|
|
|
}
|
|
|
|
|
else if (paction->pspec->value_type == G_TYPE_DOUBLE)
|
|
|
|
|
{
|
|
|
|
|
GParamSpecDouble *pspec = (GParamSpecDouble *)paction->pspec;
|
|
|
|
|
return g_variant_new ("(dd)", pspec->minimum, pspec->maximum);
|
|
|
|
|
}
|
|
|
|
|
|
2013-06-28 17:41:43 +02:00
|
|
|
|
return NULL;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static gboolean
|
|
|
|
|
g_property_action_get_enabled (GAction *action)
|
|
|
|
|
{
|
|
|
|
|
return TRUE;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
|
g_property_action_set_state (GPropertyAction *paction,
|
|
|
|
|
GVariant *variant)
|
|
|
|
|
{
|
|
|
|
|
GValue value = G_VALUE_INIT;
|
|
|
|
|
|
|
|
|
|
g_value_init (&value, paction->pspec->value_type);
|
|
|
|
|
g_settings_get_mapping (&value, variant, NULL);
|
2015-03-29 20:00:36 +02:00
|
|
|
|
|
|
|
|
|
if (paction->pspec->value_type == G_TYPE_BOOLEAN && paction->invert_boolean)
|
|
|
|
|
g_value_set_boolean (&value, !g_value_get_boolean (&value));
|
|
|
|
|
|
2013-06-28 17:41:43 +02:00
|
|
|
|
g_object_set_property (paction->object, paction->pspec->name, &value);
|
|
|
|
|
g_value_unset (&value);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
|
g_property_action_change_state (GAction *action,
|
|
|
|
|
GVariant *value)
|
|
|
|
|
{
|
|
|
|
|
GPropertyAction *paction = G_PROPERTY_ACTION (action);
|
|
|
|
|
|
|
|
|
|
g_return_if_fail (g_variant_is_of_type (value, paction->state_type));
|
|
|
|
|
|
|
|
|
|
g_property_action_set_state (paction, value);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static GVariant *
|
|
|
|
|
g_property_action_get_state (GAction *action)
|
|
|
|
|
{
|
|
|
|
|
GPropertyAction *paction = G_PROPERTY_ACTION (action);
|
|
|
|
|
GValue value = G_VALUE_INIT;
|
|
|
|
|
GVariant *result;
|
|
|
|
|
|
|
|
|
|
g_value_init (&value, paction->pspec->value_type);
|
|
|
|
|
g_object_get_property (paction->object, paction->pspec->name, &value);
|
2015-03-29 20:00:36 +02:00
|
|
|
|
|
|
|
|
|
if (paction->pspec->value_type == G_TYPE_BOOLEAN && paction->invert_boolean)
|
|
|
|
|
g_value_set_boolean (&value, !g_value_get_boolean (&value));
|
|
|
|
|
|
2013-06-28 17:41:43 +02:00
|
|
|
|
result = g_settings_set_mapping (&value, paction->state_type, NULL);
|
|
|
|
|
g_value_unset (&value);
|
|
|
|
|
|
|
|
|
|
return g_variant_ref_sink (result);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
|
g_property_action_activate (GAction *action,
|
|
|
|
|
GVariant *parameter)
|
|
|
|
|
{
|
|
|
|
|
GPropertyAction *paction = G_PROPERTY_ACTION (action);
|
|
|
|
|
|
|
|
|
|
if (paction->pspec->value_type == G_TYPE_BOOLEAN)
|
|
|
|
|
{
|
|
|
|
|
gboolean value;
|
|
|
|
|
|
|
|
|
|
g_return_if_fail (paction->pspec->value_type == G_TYPE_BOOLEAN && parameter == NULL);
|
|
|
|
|
|
|
|
|
|
g_object_get (paction->object, paction->pspec->name, &value, NULL);
|
|
|
|
|
value = !value;
|
|
|
|
|
g_object_set (paction->object, paction->pspec->name, value, NULL);
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
g_return_if_fail (parameter != NULL && g_variant_is_of_type (parameter, paction->state_type));
|
|
|
|
|
|
|
|
|
|
g_property_action_set_state (paction, parameter);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static const GVariantType *
|
|
|
|
|
g_property_action_determine_type (GParamSpec *pspec)
|
|
|
|
|
{
|
|
|
|
|
if (G_TYPE_IS_ENUM (pspec->value_type))
|
|
|
|
|
return G_VARIANT_TYPE_STRING;
|
|
|
|
|
|
|
|
|
|
switch (pspec->value_type)
|
|
|
|
|
{
|
|
|
|
|
case G_TYPE_BOOLEAN:
|
|
|
|
|
return G_VARIANT_TYPE_BOOLEAN;
|
|
|
|
|
|
|
|
|
|
case G_TYPE_INT:
|
|
|
|
|
return G_VARIANT_TYPE_INT32;
|
|
|
|
|
|
|
|
|
|
case G_TYPE_UINT:
|
|
|
|
|
return G_VARIANT_TYPE_UINT32;
|
|
|
|
|
|
|
|
|
|
case G_TYPE_DOUBLE:
|
|
|
|
|
case G_TYPE_FLOAT:
|
|
|
|
|
return G_VARIANT_TYPE_DOUBLE;
|
|
|
|
|
|
|
|
|
|
case G_TYPE_STRING:
|
|
|
|
|
return G_VARIANT_TYPE_STRING;
|
|
|
|
|
|
|
|
|
|
default:
|
|
|
|
|
g_critical ("Unable to use GPropertyAction with property '%s::%s' of type '%s'",
|
|
|
|
|
g_type_name (pspec->owner_type), pspec->name, g_type_name (pspec->value_type));
|
|
|
|
|
return NULL;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
|
g_property_action_notify (GObject *object,
|
|
|
|
|
GParamSpec *pspec,
|
|
|
|
|
gpointer user_data)
|
|
|
|
|
{
|
|
|
|
|
GPropertyAction *paction = user_data;
|
|
|
|
|
|
|
|
|
|
g_assert (object == paction->object);
|
|
|
|
|
g_assert (pspec == paction->pspec);
|
|
|
|
|
|
|
|
|
|
g_object_notify (G_OBJECT (paction), "state");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
|
g_property_action_set_property_name (GPropertyAction *paction,
|
|
|
|
|
const gchar *property_name)
|
|
|
|
|
{
|
|
|
|
|
GParamSpec *pspec;
|
|
|
|
|
gchar *detailed;
|
|
|
|
|
|
2023-09-30 18:58:49 +02:00
|
|
|
|
/* In case somebody is constructing GPropertyAction without passing
|
|
|
|
|
* a property name
|
|
|
|
|
*/
|
|
|
|
|
if (G_UNLIKELY (property_name == NULL || property_name[0] == '\0'))
|
|
|
|
|
{
|
|
|
|
|
g_critical ("Attempted to use an empty property name for GPropertyAction");
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2013-06-28 17:41:43 +02:00
|
|
|
|
pspec = g_object_class_find_property (G_OBJECT_GET_CLASS (paction->object), property_name);
|
|
|
|
|
|
|
|
|
|
if (pspec == NULL)
|
|
|
|
|
{
|
|
|
|
|
g_critical ("Attempted to use non-existent property '%s::%s' for GPropertyAction",
|
|
|
|
|
G_OBJECT_TYPE_NAME (paction->object), property_name);
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (~pspec->flags & G_PARAM_READABLE || ~pspec->flags & G_PARAM_WRITABLE || pspec->flags & G_PARAM_CONSTRUCT_ONLY)
|
|
|
|
|
{
|
|
|
|
|
g_critical ("Property '%s::%s' used with GPropertyAction must be readable, writable, and not construct-only",
|
|
|
|
|
G_OBJECT_TYPE_NAME (paction->object), property_name);
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
paction->pspec = pspec;
|
|
|
|
|
|
|
|
|
|
detailed = g_strconcat ("notify::", paction->pspec->name, NULL);
|
|
|
|
|
paction->state_type = g_property_action_determine_type (paction->pspec);
|
|
|
|
|
g_signal_connect (paction->object, detailed, G_CALLBACK (g_property_action_notify), paction);
|
|
|
|
|
g_free (detailed);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
|
g_property_action_set_property (GObject *object,
|
|
|
|
|
guint prop_id,
|
|
|
|
|
const GValue *value,
|
|
|
|
|
GParamSpec *pspec)
|
|
|
|
|
{
|
|
|
|
|
GPropertyAction *paction = G_PROPERTY_ACTION (object);
|
|
|
|
|
|
|
|
|
|
switch (prop_id)
|
|
|
|
|
{
|
|
|
|
|
case PROP_NAME:
|
|
|
|
|
paction->name = g_value_dup_string (value);
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
case PROP_OBJECT:
|
|
|
|
|
paction->object = g_value_dup_object (value);
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
case PROP_PROPERTY_NAME:
|
|
|
|
|
g_property_action_set_property_name (paction, g_value_get_string (value));
|
|
|
|
|
break;
|
|
|
|
|
|
2015-03-29 20:00:36 +02:00
|
|
|
|
case PROP_INVERT_BOOLEAN:
|
|
|
|
|
paction->invert_boolean = g_value_get_boolean (value);
|
|
|
|
|
break;
|
|
|
|
|
|
2013-06-28 17:41:43 +02:00
|
|
|
|
default:
|
|
|
|
|
g_assert_not_reached ();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
|
g_property_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_property_action_get_name (action));
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
case PROP_PARAMETER_TYPE:
|
|
|
|
|
g_value_set_boxed (value, g_property_action_get_parameter_type (action));
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
case PROP_ENABLED:
|
|
|
|
|
g_value_set_boolean (value, g_property_action_get_enabled (action));
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
case PROP_STATE_TYPE:
|
|
|
|
|
g_value_set_boxed (value, g_property_action_get_state_type (action));
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
case PROP_STATE:
|
|
|
|
|
g_value_take_variant (value, g_property_action_get_state (action));
|
|
|
|
|
break;
|
|
|
|
|
|
2015-03-29 20:00:36 +02:00
|
|
|
|
case PROP_INVERT_BOOLEAN:
|
|
|
|
|
g_value_set_boolean (value, g_property_action_get_invert_boolean (action));
|
|
|
|
|
break;
|
|
|
|
|
|
2013-06-28 17:41:43 +02:00
|
|
|
|
default:
|
|
|
|
|
g_assert_not_reached ();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2023-10-02 16:20:25 +02:00
|
|
|
|
static void
|
|
|
|
|
g_property_action_dispose (GObject *object)
|
|
|
|
|
{
|
|
|
|
|
GPropertyAction *paction = G_PROPERTY_ACTION (object);
|
|
|
|
|
|
|
|
|
|
if (paction->object != NULL)
|
|
|
|
|
{
|
|
|
|
|
g_signal_handlers_disconnect_by_func (paction->object, g_property_action_notify, paction);
|
|
|
|
|
g_clear_object (&paction->object);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
G_OBJECT_CLASS (g_property_action_parent_class)->dispose (object);
|
|
|
|
|
}
|
|
|
|
|
|
2013-06-28 17:41:43 +02:00
|
|
|
|
static void
|
|
|
|
|
g_property_action_finalize (GObject *object)
|
|
|
|
|
{
|
|
|
|
|
GPropertyAction *paction = G_PROPERTY_ACTION (object);
|
|
|
|
|
|
|
|
|
|
g_free (paction->name);
|
|
|
|
|
|
|
|
|
|
G_OBJECT_CLASS (g_property_action_parent_class)
|
|
|
|
|
->finalize (object);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void
|
|
|
|
|
g_property_action_init (GPropertyAction *property)
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void
|
|
|
|
|
g_property_action_iface_init (GActionInterface *iface)
|
|
|
|
|
{
|
|
|
|
|
iface->get_name = g_property_action_get_name;
|
|
|
|
|
iface->get_parameter_type = g_property_action_get_parameter_type;
|
|
|
|
|
iface->get_state_type = g_property_action_get_state_type;
|
|
|
|
|
iface->get_state_hint = g_property_action_get_state_hint;
|
|
|
|
|
iface->get_enabled = g_property_action_get_enabled;
|
|
|
|
|
iface->get_state = g_property_action_get_state;
|
|
|
|
|
iface->change_state = g_property_action_change_state;
|
|
|
|
|
iface->activate = g_property_action_activate;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void
|
|
|
|
|
g_property_action_class_init (GPropertyActionClass *class)
|
|
|
|
|
{
|
|
|
|
|
GObjectClass *object_class = G_OBJECT_CLASS (class);
|
|
|
|
|
|
|
|
|
|
object_class->set_property = g_property_action_set_property;
|
|
|
|
|
object_class->get_property = g_property_action_get_property;
|
2023-10-02 16:20:25 +02:00
|
|
|
|
object_class->dispose = g_property_action_dispose;
|
2013-06-28 17:41:43 +02:00
|
|
|
|
object_class->finalize = g_property_action_finalize;
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* GPropertyAction:name:
|
|
|
|
|
*
|
|
|
|
|
* The name of the action. This is mostly meaningful for identifying
|
|
|
|
|
* the action once it has been added to a #GActionMap.
|
|
|
|
|
*
|
|
|
|
|
* Since: 2.38
|
|
|
|
|
**/
|
|
|
|
|
g_object_class_install_property (object_class, PROP_NAME,
|
2023-04-28 01:59:26 +02:00
|
|
|
|
g_param_spec_string ("name", NULL, NULL,
|
2013-06-28 17:41:43 +02:00
|
|
|
|
NULL,
|
|
|
|
|
G_PARAM_READWRITE |
|
|
|
|
|
G_PARAM_CONSTRUCT_ONLY |
|
|
|
|
|
G_PARAM_STATIC_STRINGS));
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* GPropertyAction:parameter-type:
|
|
|
|
|
*
|
|
|
|
|
* The type of the parameter that must be given when activating the
|
|
|
|
|
* action.
|
|
|
|
|
*
|
|
|
|
|
* Since: 2.38
|
|
|
|
|
**/
|
|
|
|
|
g_object_class_install_property (object_class, PROP_PARAMETER_TYPE,
|
2023-04-28 01:59:26 +02:00
|
|
|
|
g_param_spec_boxed ("parameter-type", NULL, NULL,
|
2013-06-28 17:41:43 +02:00
|
|
|
|
G_TYPE_VARIANT_TYPE,
|
|
|
|
|
G_PARAM_READABLE |
|
|
|
|
|
G_PARAM_STATIC_STRINGS));
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* GPropertyAction:enabled:
|
|
|
|
|
*
|
|
|
|
|
* If @action is currently enabled.
|
|
|
|
|
*
|
|
|
|
|
* If the action is disabled then calls to g_action_activate() and
|
|
|
|
|
* g_action_change_state() have no effect.
|
|
|
|
|
*
|
|
|
|
|
* Since: 2.38
|
|
|
|
|
**/
|
|
|
|
|
g_object_class_install_property (object_class, PROP_ENABLED,
|
2023-04-28 01:59:26 +02:00
|
|
|
|
g_param_spec_boolean ("enabled", NULL, NULL,
|
2013-06-28 17:41:43 +02:00
|
|
|
|
TRUE,
|
|
|
|
|
G_PARAM_READABLE |
|
|
|
|
|
G_PARAM_STATIC_STRINGS));
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* GPropertyAction:state-type:
|
|
|
|
|
*
|
|
|
|
|
* The #GVariantType of the state that the action has, or %NULL if the
|
|
|
|
|
* action is stateless.
|
|
|
|
|
*
|
|
|
|
|
* Since: 2.38
|
|
|
|
|
**/
|
|
|
|
|
g_object_class_install_property (object_class, PROP_STATE_TYPE,
|
2023-04-28 01:59:26 +02:00
|
|
|
|
g_param_spec_boxed ("state-type", NULL, NULL,
|
2013-06-28 17:41:43 +02:00
|
|
|
|
G_TYPE_VARIANT_TYPE,
|
|
|
|
|
G_PARAM_READABLE |
|
|
|
|
|
G_PARAM_STATIC_STRINGS));
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* GPropertyAction:state:
|
|
|
|
|
*
|
|
|
|
|
* The state of the action, or %NULL if the action is stateless.
|
|
|
|
|
*
|
|
|
|
|
* Since: 2.38
|
|
|
|
|
**/
|
|
|
|
|
g_object_class_install_property (object_class, PROP_STATE,
|
2023-04-28 01:59:26 +02:00
|
|
|
|
g_param_spec_variant ("state", NULL, NULL,
|
2013-06-28 17:41:43 +02:00
|
|
|
|
G_VARIANT_TYPE_ANY,
|
|
|
|
|
NULL,
|
|
|
|
|
G_PARAM_READABLE |
|
|
|
|
|
G_PARAM_STATIC_STRINGS));
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* GPropertyAction:object:
|
|
|
|
|
*
|
|
|
|
|
* The object to wrap a property on.
|
|
|
|
|
*
|
|
|
|
|
* The object must be a non-%NULL #GObject with properties.
|
|
|
|
|
*
|
|
|
|
|
* Since: 2.38
|
|
|
|
|
**/
|
|
|
|
|
g_object_class_install_property (object_class, PROP_OBJECT,
|
2023-04-28 01:59:26 +02:00
|
|
|
|
g_param_spec_object ("object", NULL, NULL,
|
2013-06-28 17:41:43 +02:00
|
|
|
|
G_TYPE_OBJECT,
|
|
|
|
|
G_PARAM_WRITABLE |
|
|
|
|
|
G_PARAM_CONSTRUCT_ONLY |
|
|
|
|
|
G_PARAM_STATIC_STRINGS));
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* GPropertyAction:property-name:
|
|
|
|
|
*
|
|
|
|
|
* The name of the property to wrap on the object.
|
|
|
|
|
*
|
|
|
|
|
* The property must exist on the passed-in object and it must be
|
|
|
|
|
* readable and writable (and not construct-only).
|
|
|
|
|
*
|
|
|
|
|
* Since: 2.38
|
|
|
|
|
**/
|
|
|
|
|
g_object_class_install_property (object_class, PROP_PROPERTY_NAME,
|
2023-04-28 01:59:26 +02:00
|
|
|
|
g_param_spec_string ("property-name", NULL, NULL,
|
2013-06-28 17:41:43 +02:00
|
|
|
|
NULL,
|
|
|
|
|
G_PARAM_WRITABLE |
|
|
|
|
|
G_PARAM_CONSTRUCT_ONLY |
|
|
|
|
|
G_PARAM_STATIC_STRINGS));
|
2015-03-29 20:00:36 +02:00
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* GPropertyAction:invert-boolean:
|
|
|
|
|
*
|
|
|
|
|
* If %TRUE, the state of the action will be the negation of the
|
|
|
|
|
* property value, provided the property is boolean.
|
|
|
|
|
*
|
|
|
|
|
* Since: 2.46
|
|
|
|
|
*/
|
|
|
|
|
g_object_class_install_property (object_class, PROP_INVERT_BOOLEAN,
|
2023-04-28 01:59:26 +02:00
|
|
|
|
g_param_spec_boolean ("invert-boolean", NULL, NULL,
|
2015-03-29 20:00:36 +02:00
|
|
|
|
FALSE,
|
|
|
|
|
G_PARAM_READWRITE |
|
|
|
|
|
G_PARAM_CONSTRUCT_ONLY |
|
|
|
|
|
G_PARAM_STATIC_STRINGS));
|
2013-06-28 17:41:43 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* g_property_action_new:
|
|
|
|
|
* @name: the name of the action to create
|
2015-02-26 19:17:59 +01:00
|
|
|
|
* @object: (type GObject.Object): the object that has the property
|
|
|
|
|
* to wrap
|
2013-06-28 17:41:43 +02:00
|
|
|
|
* @property_name: the name of the property
|
|
|
|
|
*
|
|
|
|
|
* Creates a #GAction corresponding to the value of property
|
|
|
|
|
* @property_name on @object.
|
|
|
|
|
*
|
|
|
|
|
* The property must be existent and readable and writable (and not
|
|
|
|
|
* construct-only).
|
|
|
|
|
*
|
|
|
|
|
* This function takes a reference on @object and doesn't release it
|
|
|
|
|
* until the action is destroyed.
|
|
|
|
|
*
|
|
|
|
|
* Returns: a new #GPropertyAction
|
|
|
|
|
*
|
|
|
|
|
* Since: 2.38
|
|
|
|
|
**/
|
|
|
|
|
GPropertyAction *
|
|
|
|
|
g_property_action_new (const gchar *name,
|
|
|
|
|
gpointer object,
|
|
|
|
|
const gchar *property_name)
|
|
|
|
|
{
|
|
|
|
|
g_return_val_if_fail (name != NULL, NULL);
|
|
|
|
|
g_return_val_if_fail (G_IS_OBJECT (object), NULL);
|
|
|
|
|
g_return_val_if_fail (property_name != NULL, NULL);
|
|
|
|
|
|
|
|
|
|
return g_object_new (G_TYPE_PROPERTY_ACTION,
|
|
|
|
|
"name", name,
|
|
|
|
|
"object", object,
|
|
|
|
|
"property-name", property_name,
|
|
|
|
|
NULL);
|
|
|
|
|
}
|