From a02639a8849df82b563331783f5d571622d65208 Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Wed, 5 Jan 2011 16:58:37 -0600 Subject: Handling the case of a NULL variant by making it clear the hashtable of that property. --- libdbusmenu-glib/menuitem.c | 24 ++++++++++++++++-------- 1 file changed, 16 insertions(+), 8 deletions(-) diff --git a/libdbusmenu-glib/menuitem.c b/libdbusmenu-glib/menuitem.c index ad6472b..50354ee 100644 --- a/libdbusmenu-glib/menuitem.c +++ b/libdbusmenu-glib/menuitem.c @@ -984,14 +984,22 @@ dbusmenu_menuitem_property_set_variant (DbusmenuMenuitem * mi, const gchar * pro DbusmenuMenuitemPrivate * priv = DBUSMENU_MENUITEM_GET_PRIVATE(mi); - gchar * lprop = g_strdup(property); - g_variant_ref(value); - gboolean replaced = FALSE; - gpointer currentval = g_hash_table_lookup(priv->properties, lprop); - if (currentval == NULL || !g_variant_equal((GVariant*)currentval, value)) { - g_hash_table_replace(priv->properties, lprop, value); - replaced = TRUE; + gpointer currentval = g_hash_table_lookup(priv->properties, property); + + if (value != NULL) { + gchar * lprop = g_strdup(property); + g_variant_ref(value); + + if (currentval == NULL || !g_variant_equal((GVariant*)currentval, value)) { + g_hash_table_replace(priv->properties, lprop, value); + replaced = TRUE; + } + } else { + if (currentval != NULL) { + g_hash_table_remove(priv->properties, property); + replaced = TRUE; + } } /* NOTE: The actual value is invalid at this point @@ -999,7 +1007,7 @@ dbusmenu_menuitem_property_set_variant (DbusmenuMenuitem * mi, const gchar * pro table. But the fact that there was a value is the imporant part. */ if (currentval == NULL || replaced) { - g_signal_emit(G_OBJECT(mi), signals[PROPERTY_CHANGED], 0, lprop, value, TRUE); + g_signal_emit(G_OBJECT(mi), signals[PROPERTY_CHANGED], 0, property, value, TRUE); } return TRUE; -- cgit v1.2.3 From e5f53f91d929c46914b4a02336e31724fb54ec95 Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Wed, 5 Jan 2011 20:47:09 -0600 Subject: Adding a test to test removing of properties --- tests/test-glib-objects.c | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/tests/test-glib-objects.c b/tests/test-glib-objects.c index 7143814..2c8eda9 100644 --- a/tests/test-glib-objects.c +++ b/tests/test-glib-objects.c @@ -274,6 +274,29 @@ test_object_menuitem_props_boolstr (void) return; } +/* Set and then remove a prop */ +static void +test_object_menuitem_props_removal (void) +{ + /* Build a menu item */ + DbusmenuMenuitem * item = dbusmenu_menuitem_new(); + + /* Test to make sure it's a happy object */ + g_assert(item != NULL); + + /* Set the property and ensure that it's set */ + dbusmenu_menuitem_property_set_variant(item, "myprop", g_variant_new_int32(34)); + g_assert(dbusmenu_menuitem_property_get_variant(item, "myprop") != NULL); + + /* Remove the property and ensure it goes away */ + dbusmenu_menuitem_property_set_variant(item, "myprop", NULL); + g_assert(dbusmenu_menuitem_property_get_variant(item, "myprop") == NULL); + + g_object_unref(item); + + return; +} + /* Build the test suite */ static void test_glib_objects_suite (void) @@ -286,6 +309,7 @@ test_glib_objects_suite (void) g_test_add_func ("/dbusmenu/glib/objects/menuitem/props_swap", test_object_menuitem_props_swap); g_test_add_func ("/dbusmenu/glib/objects/menuitem/props_signals", test_object_menuitem_props_signals); g_test_add_func ("/dbusmenu/glib/objects/menuitem/props_boolstr", test_object_menuitem_props_boolstr); + g_test_add_func ("/dbusmenu/glib/objects/menuitem/props_removal", test_object_menuitem_props_removal); return; } -- cgit v1.2.3 From 0c50ae11cafdd7ca04ae6d2a69390903d16daedd Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Wed, 5 Jan 2011 20:49:47 -0600 Subject: Adding a test for removal by string being NULL --- tests/test-glib-objects.c | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/tests/test-glib-objects.c b/tests/test-glib-objects.c index 2c8eda9..9c99280 100644 --- a/tests/test-glib-objects.c +++ b/tests/test-glib-objects.c @@ -292,6 +292,14 @@ test_object_menuitem_props_removal (void) dbusmenu_menuitem_property_set_variant(item, "myprop", NULL); g_assert(dbusmenu_menuitem_property_get_variant(item, "myprop") == NULL); + /* Set the property again */ + dbusmenu_menuitem_property_set_variant(item, "myprop", g_variant_new_int32(34)); + g_assert(dbusmenu_menuitem_property_get_variant(item, "myprop") != NULL); + + /* Remove the property with a NULL string */ + dbusmenu_menuitem_property_set(item, "myprop", NULL); + g_assert(dbusmenu_menuitem_property_get_variant(item, "myprop") == NULL); + g_object_unref(item); return; -- cgit v1.2.3 From 47263d9b6c912d013a77ce2efda27df9c7571920 Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Wed, 5 Jan 2011 20:51:51 -0600 Subject: Testing for the string being NULL before g_variant aborts on it. --- libdbusmenu-glib/menuitem.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/libdbusmenu-glib/menuitem.c b/libdbusmenu-glib/menuitem.c index 50354ee..31c23f4 100644 --- a/libdbusmenu-glib/menuitem.c +++ b/libdbusmenu-glib/menuitem.c @@ -913,7 +913,10 @@ dbusmenu_menuitem_find_id (DbusmenuMenuitem * mi, gint id) gboolean dbusmenu_menuitem_property_set (DbusmenuMenuitem * mi, const gchar * property, const gchar * value) { - GVariant * variant = g_variant_new("s", value); + GVariant * variant = NULL; + if (value != NULL) { + g_variant_new_string(value); + } return dbusmenu_menuitem_property_set_variant(mi, property, variant); } -- cgit v1.2.3 From 1b77b621285fe681ca030bf3f548ad04b50dd242 Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Wed, 5 Jan 2011 20:53:27 -0600 Subject: Oops, need to actually assign that return. --- libdbusmenu-glib/menuitem.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libdbusmenu-glib/menuitem.c b/libdbusmenu-glib/menuitem.c index 31c23f4..1e892c3 100644 --- a/libdbusmenu-glib/menuitem.c +++ b/libdbusmenu-glib/menuitem.c @@ -915,7 +915,7 @@ dbusmenu_menuitem_property_set (DbusmenuMenuitem * mi, const gchar * property, c { GVariant * variant = NULL; if (value != NULL) { - g_variant_new_string(value); + variant = g_variant_new_string(value); } return dbusmenu_menuitem_property_set_variant(mi, property, variant); } -- cgit v1.2.3 From 4df4ee42222a893f2f243bb58aae031225db32ee Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Wed, 5 Jan 2011 21:48:15 -0600 Subject: * Upstream Merge * Supporting removing properties --- debian/changelog | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/debian/changelog b/debian/changelog index d5a79cc..d2817a3 100644 --- a/debian/changelog +++ b/debian/changelog @@ -1,3 +1,10 @@ +libdbusmenu (0.3.90-0ubuntu4~remove1) UNRELEASED; urgency=low + + * Upstream Merge + * Supporting removing properties + + -- Ted Gould Wed, 05 Jan 2011 21:47:45 -0600 + libdbusmenu (0.3.90-0ubuntu3) natty; urgency=low * Updated for the gir abi transition @@ -12,13 +19,6 @@ libdbusmenu (0.3.90-0ubuntu2) natty; urgency=low -- Ken VanDine Thu, 09 Dec 2010 17:46:41 -0500 -libdbusmenu (0.3.90-0ubuntu2~ppa4~remove1) UNRELEASED; urgency=low - - * Upstream Merge - * Supporting removing properties - - -- Ted Gould Wed, 05 Jan 2011 21:24:36 -0600 - libdbusmenu (0.3.90-0ubuntu2~ppa3) natty; urgency=low * debian/control: Forgot jsonloader -- cgit v1.2.3 From 2af93062f8a8fb18e84c8b3f9704fdcd970c5219 Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Wed, 5 Jan 2011 21:53:59 -0600 Subject: releasing version 0.3.90-0ubuntu4~remove1 --- debian/changelog | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/debian/changelog b/debian/changelog index d2817a3..429c600 100644 --- a/debian/changelog +++ b/debian/changelog @@ -1,9 +1,9 @@ -libdbusmenu (0.3.90-0ubuntu4~remove1) UNRELEASED; urgency=low +libdbusmenu (0.3.90-0ubuntu4~remove1) natty; urgency=low * Upstream Merge * Supporting removing properties - -- Ted Gould Wed, 05 Jan 2011 21:47:45 -0600 + -- Ted Gould Wed, 05 Jan 2011 21:53:56 -0600 libdbusmenu (0.3.90-0ubuntu3) natty; urgency=low -- cgit v1.2.3