diff options
author | Ted Gould <ted@gould.cx> | 2009-12-15 11:50:59 -0600 |
---|---|---|
committer | Ted Gould <ted@gould.cx> | 2009-12-15 11:50:59 -0600 |
commit | 030d27a1ca21c10ddad7f04848f60b0b2adc4c40 (patch) | |
tree | 1120f838ecf4944165b49e415663b18e29f3129f | |
parent | 676987c27da3fb20881d9c56c25a005bdd088010 (diff) | |
download | libdbusmenu-030d27a1ca21c10ddad7f04848f60b0b2adc4c40.tar.gz libdbusmenu-030d27a1ca21c10ddad7f04848f60b0b2adc4c40.tar.bz2 libdbusmenu-030d27a1ca21c10ddad7f04848f60b0b2adc4c40.zip |
Basic implementation of some helper getter/setters for GValues with int and bools
-rw-r--r-- | libdbusmenu-glib/menuitem.c | 36 | ||||
-rw-r--r-- | libdbusmenu-glib/menuitem.h | 4 |
2 files changed, 40 insertions, 0 deletions
diff --git a/libdbusmenu-glib/menuitem.c b/libdbusmenu-glib/menuitem.c index 77f8e90..76ce79c 100644 --- a/libdbusmenu-glib/menuitem.c +++ b/libdbusmenu-glib/menuitem.c @@ -694,6 +694,24 @@ dbusmenu_menuitem_property_set (DbusmenuMenuitem * mi, const gchar * property, c return dbusmenu_menuitem_property_set_value(mi, property, &val); } +gboolean +dbusmenu_menuitem_property_set_bool (DbusmenuMenuitem * mi, const gchar * property, const gboolean value) +{ + GValue val = {0}; + g_value_init(&val, G_TYPE_BOOLEAN); + g_value_set_boolean(&val, value); + return dbusmenu_menuitem_property_set_value(mi, property, &val); +} + +gboolean +dbusmenu_menuitem_property_set_int (DbusmenuMenuitem * mi, const gchar * property, const gint value) +{ + GValue val = {0}; + g_value_init(&val, G_TYPE_INT); + g_value_set_int(&val, value); + return dbusmenu_menuitem_property_set_value(mi, property, &val); +} + /** dbusmenu_menuitem_property_set: @mi: The #DbusmenuMenuitem to set the property on. @@ -788,6 +806,24 @@ dbusmenu_menuitem_property_get_value (DbusmenuMenuitem * mi, const gchar * prope return (const GValue *)g_hash_table_lookup(priv->properties, property); } +gboolean +dbusmenu_menuitem_property_get_bool (DbusmenuMenuitem * mi, const gchar * property) +{ + const GValue * value = dbusmenu_menuitem_property_get_value(mi, property); + if (value == NULL) return FALSE; + if (G_VALUE_TYPE(value) != G_TYPE_BOOLEAN) return FALSE; + return g_value_get_boolean(value); +} + +gint +dbusmenu_menuitem_property_get_int (DbusmenuMenuitem * mi, const gchar * property) +{ + const GValue * value = dbusmenu_menuitem_property_get_value(mi, property); + if (value == NULL) return 0; + if (G_VALUE_TYPE(value) != G_TYPE_INT) return 0; + return g_value_get_int(value); +} + /** dbusmenu_menuitem_property_exit: diff --git a/libdbusmenu-glib/menuitem.h b/libdbusmenu-glib/menuitem.h index be56fc8..fc9e410 100644 --- a/libdbusmenu-glib/menuitem.h +++ b/libdbusmenu-glib/menuitem.h @@ -135,8 +135,12 @@ DbusmenuMenuitem * dbusmenu_menuitem_find_id (DbusmenuMenuitem * mi, guint id); gboolean dbusmenu_menuitem_property_set (DbusmenuMenuitem * mi, const gchar * property, const gchar * value); gboolean dbusmenu_menuitem_property_set_value (DbusmenuMenuitem * mi, const gchar * property, const GValue * value); +gboolean dbusmenu_menuitem_property_set_bool (DbusmenuMenuitem * mi, const gchar * property, const gboolean value); +gboolean dbusmenu_menuitem_property_set_int (DbusmenuMenuitem * mi, const gchar * property, const gint value); const gchar * dbusmenu_menuitem_property_get (DbusmenuMenuitem * mi, const gchar * property); const GValue * dbusmenu_menuitem_property_get_value (DbusmenuMenuitem * mi, const gchar * property); +gboolean dbusmenu_menuitem_property_get_bool (DbusmenuMenuitem * mi, const gchar * property); +gint dbusmenu_menuitem_property_get_int (DbusmenuMenuitem * mi, const gchar * property); gboolean dbusmenu_menuitem_property_exist (DbusmenuMenuitem * mi, const gchar * property); GList * dbusmenu_menuitem_properties_list (DbusmenuMenuitem * mi) G_GNUC_WARN_UNUSED_RESULT; GHashTable * dbusmenu_menuitem_properties_copy (DbusmenuMenuitem * mi); |