GNOME Bugzilla – Bug 705483
Add GVariant API to ease using enum values for "radio" GActions
Last modified: 2018-05-24 15:35:40 UTC
It would be helpful, and would encourage good GMenu code, to have API to get a string state value for an enum. Some suggestions from Ryan on irc: <desrt> would it help if we have utility functions to convert string-typed GVariants into enum values of a given GType? we do this conversion logic internally for gsettings already <desrt> it's a bit magic, but it clearly has the potential to be useful <desrt> so we would have g_variant_get_enum (v, G_TYPE_FOO) and g_variant_new_enum (G_TYPE_FOO, x); <desrt> then you could switch (g_variant_get_enum (v, G_TYPE_FOO) { case G_FOO_X: case G_FOO_Y: ... } <desrt> just unsure what to do about the case where we have no match.... return -1 or something, i guess maybe with g_warning Personally, I think g_variant_get_enum_from_string() and g_variant_new_string_from_enum() would be clearer, as it's a string-based variant that we'll be dealing with, because a GVariant can't hold enum types.(Other than as ints and those would be vulnerable to changes in the enum value order).
-- GitLab Migration Automatic Message -- This bug has been migrated to GNOME's GitLab instance and has been closed from further activity. You can subscribe and participate further through the new bug through this link to our GitLab instance: https://gitlab.gnome.org/GNOME/glib/issues/741.