diff options
-rw-r--r-- | libdbusmenu-glib/menuitem.c | 29 | ||||
-rw-r--r-- | libdbusmenu-glib/menuitem.h | 2 | ||||
-rw-r--r-- | tests/test-glib-objects.c | 32 |
3 files changed, 54 insertions, 9 deletions
diff --git a/libdbusmenu-glib/menuitem.c b/libdbusmenu-glib/menuitem.c index 747cc01..827d6c5 100644 --- a/libdbusmenu-glib/menuitem.c +++ b/libdbusmenu-glib/menuitem.c @@ -930,7 +930,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) { + variant = g_variant_new_string(value); + } return dbusmenu_menuitem_property_set_variant(mi, property, variant); } @@ -1001,14 +1004,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 @@ -1016,7 +1027,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; diff --git a/libdbusmenu-glib/menuitem.h b/libdbusmenu-glib/menuitem.h index 0058ded..a4c7611 100644 --- a/libdbusmenu-glib/menuitem.h +++ b/libdbusmenu-glib/menuitem.h @@ -128,6 +128,7 @@ typedef void (*dbusmenu_menuitem_buildxml_slot_t) (DbusmenuMenuitem * mi, GPtrAr * @child_removed: Slot for #DbusmenuMenuitem::child-removed. * @child_moved: Slot for #DbusmenuMenuitem::child-moved. * @realized: Slot for #DbusmenuMenuitem::realized. + * @about_to_show: Slot for #DbusmenuMenuitem::about-to-show. * @buildxml: Virtual function that appends the strings required to represent this menu item in the menu XML file. * @handle_event: This function is to override how events are handled by subclasses. Look at #dbusmenu_menuitem_handle_event for lots of good information. * @send_about_to_show: Virtual function that notifies server that the client is about to show a menu. @@ -167,6 +168,7 @@ struct _DbusmenuMenuitemClass void (*reserved3) (void); void (*reserved4) (void); void (*reserved5) (void); + void (*reserved6) (void); }; GType dbusmenu_menuitem_get_type (void); diff --git a/tests/test-glib-objects.c b/tests/test-glib-objects.c index 7143814..9c99280 100644 --- a/tests/test-glib-objects.c +++ b/tests/test-glib-objects.c @@ -274,6 +274,37 @@ 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); + + /* 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; +} + /* Build the test suite */ static void test_glib_objects_suite (void) @@ -286,6 +317,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; } |