aboutsummaryrefslogtreecommitdiff
path: root/libdbusmenu-glib/menuitem.c
diff options
context:
space:
mode:
authorTed Gould <ted@gould.cx>2011-02-21 21:06:41 -0600
committerTed Gould <ted@gould.cx>2011-02-21 21:06:41 -0600
commit494adf9835825c711fd9f05b44143d6331bcab63 (patch)
tree47a67c935498729c632b52e4038c29a3475be580 /libdbusmenu-glib/menuitem.c
parentc704e7e82e57f2ac6ca9e058459d600c0bbed6ab (diff)
downloadlibdbusmenu-494adf9835825c711fd9f05b44143d6331bcab63.tar.gz
libdbusmenu-494adf9835825c711fd9f05b44143d6331bcab63.tar.bz2
libdbusmenu-494adf9835825c711fd9f05b44143d6331bcab63.zip
When we're setting a value check to see if it's the same as the default and clear it if so.
Diffstat (limited to 'libdbusmenu-glib/menuitem.c')
-rw-r--r--libdbusmenu-glib/menuitem.c37
1 files changed, 37 insertions, 0 deletions
diff --git a/libdbusmenu-glib/menuitem.c b/libdbusmenu-glib/menuitem.c
index b6c5712..c744435 100644
--- a/libdbusmenu-glib/menuitem.c
+++ b/libdbusmenu-glib/menuitem.c
@@ -434,6 +434,14 @@ send_about_to_show (DbusmenuMenuitem * mi, void (*cb) (DbusmenuMenuitem * mi, gp
return;
}
+/* A helper function to get the type of the menuitem, this might
+ be a candidate for optimization in the future. */
+static const gchar *
+menuitem_get_type (DbusmenuMenuitem * mi)
+{
+ return dbusmenu_menuitem_property_get(mi, DBUSMENU_MENUITEM_PROP_TYPE);
+}
+
/* Public interface */
/**
@@ -1013,6 +1021,35 @@ dbusmenu_menuitem_property_set_variant (DbusmenuMenuitem * mi, const gchar * pro
DbusmenuMenuitemPrivate * priv = DBUSMENU_MENUITEM_GET_PRIVATE(mi);
+ const gchar * type = menuitem_get_type(mi);
+ if (type != NULL) {
+ /* Check the defaults database to see if we have a default
+ for this property. */
+ GVariant * default_value = dbusmenu_defaults_default_get(priv->defaults, type, property);
+ if (default_value != NULL) {
+ /* If we have a default we might also have an expected type */
+ GVariantType * default_type = dbusmenu_defaults_default_get_type(priv->defaults, type, property);
+
+ if (default_type != NULL) {
+ /* If we have an expected type we should check to see if
+ the value we've been given is of the same type and generate
+ a warning if it isn't */
+ if (!g_variant_is_of_type(value, default_type)) {
+ g_warning("Setting menuitem property '%s' with value of type '%s' when expecting '%s'", property, g_variant_get_type_string(value), g_variant_type_peek_string(default_type));
+ }
+ }
+
+ /* Now see if we're setting this to the same value as the
+ default. If we are then we just want to swallow this variant
+ and make the function behave like we're clearing it. */
+ if (g_variant_equal(default_value, value)) {
+ g_variant_ref_sink(value);
+ g_variant_unref(value);
+ value = NULL;
+ }
+ }
+ }
+
gboolean replaced = FALSE;
gpointer currentval = g_hash_table_lookup(priv->properties, property);