GAction: make GObject properties read-only

GAction is a read-only interface (as is visible by the lack of _set() functions
on its API).  The properties on the interface currently force implementors to
support writing of the properties at construct time, however.

Lift that restriction.

Take advantage of this from GSimpleAction by nuking the set_property
function and setting the fields directly in the constructor.
This commit is contained in:
Ryan Lortie 2011-06-29 17:13:58 +01:00 committed by Robert Ancell
parent e6a25caa82
commit bde41dacf7
2 changed files with 25 additions and 52 deletions

View File

@ -77,8 +77,7 @@ g_action_default_init (GActionInterface *iface)
P_("Action Name"),
P_("The name used to invoke the action"),
NULL,
G_PARAM_READWRITE |
G_PARAM_CONSTRUCT_ONLY |
G_PARAM_READABLE |
G_PARAM_STATIC_STRINGS));
/**
@ -94,8 +93,7 @@ g_action_default_init (GActionInterface *iface)
P_("Parameter Type"),
P_("The type of GVariant passed to activate()"),
G_TYPE_VARIANT_TYPE,
G_PARAM_READWRITE |
G_PARAM_CONSTRUCT_ONLY |
G_PARAM_READABLE |
G_PARAM_STATIC_STRINGS));
/**
@ -113,8 +111,7 @@ g_action_default_init (GActionInterface *iface)
P_("Enabled"),
P_("If the action can be activated"),
TRUE,
G_PARAM_CONSTRUCT |
G_PARAM_READWRITE |
G_PARAM_READABLE |
G_PARAM_STATIC_STRINGS));
/**

View File

@ -207,35 +207,6 @@ g_simple_action_activate (GAction *action,
g_variant_unref (parameter);
}
static void
g_simple_action_set_property (GObject *object,
guint prop_id,
const GValue *value,
GParamSpec *pspec)
{
GSimpleAction *simple = G_SIMPLE_ACTION (object);
switch (prop_id)
{
case PROP_NAME:
g_assert (simple->name == NULL);
simple->name = g_value_dup_string (value);
break;
case PROP_PARAMETER_TYPE:
g_assert (simple->parameter_type == NULL);
simple->parameter_type = g_value_dup_boxed (value);
break;
case PROP_ENABLED:
g_simple_action_set_enabled (simple, g_value_get_boolean (value));
break;
default:
g_assert_not_reached ();
}
}
static void
g_simple_action_get_property (GObject *object,
guint prop_id,
@ -310,7 +281,6 @@ g_simple_action_class_init (GSimpleActionClass *class)
GObjectClass *object_class = G_OBJECT_CLASS (class);
object_class->get_property = g_simple_action_get_property;
object_class->set_property = g_simple_action_set_property;
object_class->finalize = g_simple_action_finalize;
/**
@ -397,8 +367,7 @@ g_simple_action_class_init (GSimpleActionClass *class)
P_("Action Name"),
P_("The name used to invoke the action"),
NULL,
G_PARAM_READWRITE |
G_PARAM_CONSTRUCT_ONLY |
G_PARAM_READABLE |
G_PARAM_STATIC_STRINGS));
/**
@ -414,8 +383,7 @@ g_simple_action_class_init (GSimpleActionClass *class)
P_("Parameter Type"),
P_("The type of GVariant passed to activate()"),
G_TYPE_VARIANT_TYPE,
G_PARAM_READWRITE |
G_PARAM_CONSTRUCT_ONLY |
G_PARAM_READABLE |
G_PARAM_STATIC_STRINGS));
/**
@ -433,8 +401,7 @@ g_simple_action_class_init (GSimpleActionClass *class)
P_("Enabled"),
P_("If the action can be activated"),
TRUE,
G_PARAM_CONSTRUCT |
G_PARAM_READWRITE |
G_PARAM_READABLE |
G_PARAM_STATIC_STRINGS));
/**
@ -516,10 +483,17 @@ GSimpleAction *
g_simple_action_new (const gchar *name,
const GVariantType *parameter_type)
{
return g_object_new (G_TYPE_SIMPLE_ACTION,
"name", name,
"parameter-type", parameter_type,
NULL);
GSimpleAction *simple;
simple = g_object_new (G_TYPE_SIMPLE_ACTION, NULL);
simple->name = g_strdup (name);
if (parameter_type)
simple->parameter_type = g_variant_type_copy (parameter_type);
simple->enabled = TRUE;
return simple;
}
/**
@ -546,13 +520,15 @@ g_simple_action_new_stateful (const gchar *name,
{
GSimpleAction *simple;
simple = g_object_new (G_TYPE_SIMPLE_ACTION,
"name", name,
"parameter-type", parameter_type,
NULL);
simple = g_object_new (G_TYPE_SIMPLE_ACTION, NULL);
simple->name = g_strdup (name);
if (state)
simple->state = g_variant_ref_sink (state);
if (parameter_type)
simple->parameter_type = g_variant_type_copy (parameter_type);
simple->state = g_variant_ref_sink (state);
simple->enabled = TRUE;
return simple;
}