[gimp] libgimpconfig: support "compat enums" in gimp_config_deserialize_enum()
- From: Michael Natterer <mitch src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gimp] libgimpconfig: support "compat enums" in gimp_config_deserialize_enum()
- Date: Fri, 6 Jan 2017 22:13:14 +0000 (UTC)
commit 7ab80eaa09fd8e01964b2d8dae5367cd99022fbd
Author: Michael Natterer <mitch gimp org>
Date: Fri Jan 6 23:09:39 2017 +0100
libgimpconfig: support "compat enums" in gimp_config_deserialize_enum()
If the enum value is not found among the nicks and names of the
GParamSpec's actual enum type, check if it has a "gimp-compat-enum"
GType attached as QData, and try the lookup there.
libgimpconfig/gimpconfig-deserialize.c | 33 +++++++++++++++++++++++++++++--
1 files changed, 30 insertions(+), 3 deletions(-)
---
diff --git a/libgimpconfig/gimpconfig-deserialize.c b/libgimpconfig/gimpconfig-deserialize.c
index c1a8b1e..7bc45bb 100644
--- a/libgimpconfig/gimpconfig-deserialize.c
+++ b/libgimpconfig/gimpconfig-deserialize.c
@@ -530,11 +530,38 @@ gimp_config_deserialize_enum (GValue *value,
enum_value = g_enum_get_value_by_nick (enum_class,
scanner->value.v_identifier);
- if (!enum_value)
+ if (! enum_value)
enum_value = g_enum_get_value_by_name (enum_class,
scanner->value.v_identifier);
+ if (! enum_value)
+ {
+ /* if the value was not found, check if we have a compat
+ * enum to find the ideitifier
+ */
+ GQuark quark = g_quark_from_static_string ("gimp-compat-enum");
+ GType compat_type = (GType) g_param_spec_get_qdata (prop_spec, quark);
+
+ if (compat_type)
+ {
+ GEnumClass *compat_class = g_type_class_ref (compat_type);
+
+ enum_value = g_enum_get_value_by_nick (compat_class,
+ scanner->value.v_identifier);
+ if (! enum_value)
+ enum_value = g_enum_get_value_by_name (compat_class,
+ scanner->value.v_identifier);
+
+ /* finally, if we found a compat value, make sure the
+ * same value exists in the original enum
+ */
+ if (enum_value)
+ enum_value = g_enum_get_value (enum_class, enum_value->value);
+
+ g_type_class_unref (compat_class);
+ }
+ }
- if (!enum_value)
+ if (! enum_value)
{
g_scanner_error (scanner,
_("invalid value '%s' for token %s"),
@@ -549,7 +576,7 @@ gimp_config_deserialize_enum (GValue *value,
enum_value = g_enum_get_value (enum_class,
(gint) scanner->value.v_int64);
- if (!enum_value)
+ if (! enum_value)
{
g_scanner_error (scanner,
_("invalid value '%ld' for token %s"),
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]