From 5c0f6f04e9be75e273049bf5b4134185c12d32c1 Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Thu, 17 Feb 2011 23:24:41 -0600 Subject: Adding a get_nick function for our enums --- libdbusmenu-glib/enum-types.c.in | 25 +++++++++++++++++++++++++ libdbusmenu-glib/enum-types.h.in | 2 ++ 2 files changed, 27 insertions(+) diff --git a/libdbusmenu-glib/enum-types.c.in b/libdbusmenu-glib/enum-types.c.in index d572d44..b0756d9 100644 --- a/libdbusmenu-glib/enum-types.c.in +++ b/libdbusmenu-glib/enum-types.c.in @@ -64,4 +64,29 @@ GType return etype; } +/** + @enum_name@_get_nick: + @value: The value of @EnumName@ to get the nick of + + Looks up in the enum table for the nick of @value. + + Return value: The nick for the given value or #NULL on error +*/ +const gchar * +@enum_name@_get_nick (@EnumName@ value) +{ + GEnumClass * class = G_ENUM_CLASS(g_type_class_ref(@enum_name@_get_type())); + g_return_val_if_fail(class != NULL, NULL); + + const gchar * ret = NULL; + GEnumValue * val = g_enum_get_value(class, value); + if (val != NULL) { + ret = val->value_nick; + } + + g_type_class_unref(class); + return ret; +} + + /*** END value-tail ***/ diff --git a/libdbusmenu-glib/enum-types.h.in b/libdbusmenu-glib/enum-types.h.in index 83b4bd2..eb24453 100644 --- a/libdbusmenu-glib/enum-types.h.in +++ b/libdbusmenu-glib/enum-types.h.in @@ -44,10 +44,12 @@ G_END_DECLS /*** BEGIN file-production ***/ /* Enumerations from file: "@filename@" */ +#include "@filename@" /*** END file-production ***/ /*** BEGIN value-header ***/ GType @enum_name@_get_type (void) G_GNUC_CONST; +const gchar * @enum_name@_get_nick (@EnumName@ value) G_GNUC_CONST; #define DBUSMENU_TYPE_@ENUMSHORT@ (@enum_name@_get_type()) /*** END value-header ***/ -- cgit v1.2.3