From da41d4b9f71260928d68bee40106bc68e4624023 Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Fri, 5 Feb 2010 09:37:53 -0800 Subject: Properly unref on layout updates --- libdbusmenu-glib/client.c | 8 ++++++++ 1 file changed, 8 insertions(+) (limited to 'libdbusmenu-glib/client.c') diff --git a/libdbusmenu-glib/client.c b/libdbusmenu-glib/client.c index 0f7fd65..d63278d 100644 --- a/libdbusmenu-glib/client.c +++ b/libdbusmenu-glib/client.c @@ -339,6 +339,7 @@ id_prop_update (DBusGProxy * proxy, gint id, gchar * property, GValue * value, D g_return_if_fail(menuitem != NULL); dbusmenu_menuitem_property_set_value(menuitem, property, value); + return; } @@ -747,6 +748,13 @@ parse_layout (DbusmenuClient * client, const gchar * layout) #ifdef MASSIVEDEBUGGING g_debug("Client signaling root changed."); #endif + + /* Switch the root around */ + g_object_ref(priv->root); + dbusmenu_menuitem_set_root(priv->root, TRUE); + dbusmenu_menuitem_set_root(oldroot, FALSE); + g_object_unref(oldroot); + g_signal_emit(G_OBJECT(client), signals[ROOT_CHANGED], 0, priv->root, TRUE); } -- cgit v1.2.3 From 919aa5eca6bdc79bdb9276aa499c5b612cc28c4d Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Fri, 5 Feb 2010 09:47:16 -0800 Subject: Managing the root value and the referencing the old root item. --- libdbusmenu-glib/client.c | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) (limited to 'libdbusmenu-glib/client.c') diff --git a/libdbusmenu-glib/client.c b/libdbusmenu-glib/client.c index d63278d..b69e984 100644 --- a/libdbusmenu-glib/client.c +++ b/libdbusmenu-glib/client.c @@ -737,6 +737,10 @@ parse_layout (DbusmenuClient * client, const gchar * layout) xmlNodePtr root = xmlDocGetRootElement(xmldoc); DbusmenuMenuitem * oldroot = priv->root; + if (oldroot != NULL) { + g_object_ref(oldroot); + } + priv->root = parse_layout_xml(client, root, priv->root, NULL, priv->menuproxy); xmlFreeDoc(xmldoc); @@ -752,8 +756,11 @@ parse_layout (DbusmenuClient * client, const gchar * layout) /* Switch the root around */ g_object_ref(priv->root); dbusmenu_menuitem_set_root(priv->root, TRUE); - dbusmenu_menuitem_set_root(oldroot, FALSE); - g_object_unref(oldroot); + + if (oldroot != NULL) { + dbusmenu_menuitem_set_root(oldroot, FALSE); + g_object_unref(oldroot); + } g_signal_emit(G_OBJECT(client), signals[ROOT_CHANGED], 0, priv->root, TRUE); } -- cgit v1.2.3 From f3a0de2eec4a60c9ca7a70b4e0b78f2d148f36f5 Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Fri, 5 Feb 2010 10:25:21 -0800 Subject: Whitespace --- libdbusmenu-glib/client.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'libdbusmenu-glib/client.c') diff --git a/libdbusmenu-glib/client.c b/libdbusmenu-glib/client.c index b69e984..8ff090d 100644 --- a/libdbusmenu-glib/client.c +++ b/libdbusmenu-glib/client.c @@ -676,7 +676,7 @@ parse_layout_xml(DbusmenuClient * client, xmlNodePtr node, DbusmenuMenuitem * it } else { g_warning("Unable to allocate memory to get properties for menuitem. This menuitem will never be realized."); } - } + } xmlNodePtr children; guint position; -- cgit v1.2.3 From 0f6f4c9cdd83d80dfd77fbedcc9a9468cb16eaae Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Fri, 5 Feb 2010 10:48:48 -0800 Subject: For IDs that we recycle (often the root id) we need to update the properties. Adds a new function to support syncing the properties in the menuitem. --- libdbusmenu-glib/client.c | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) (limited to 'libdbusmenu-glib/client.c') diff --git a/libdbusmenu-glib/client.c b/libdbusmenu-glib/client.c index 8ff090d..2302110 100644 --- a/libdbusmenu-glib/client.c +++ b/libdbusmenu-glib/client.c @@ -570,6 +570,22 @@ menuitem_get_properties_cb (DBusGProxy * proxy, GHashTable * properties, GError return; } +static void +menuitem_get_properties_replace_cb (DBusGProxy * proxy, GHashTable * properties, GError * error, gpointer data) +{ + GList * current_props = NULL; + + for (current_props = dbusmenu_menuitem_properties_list(DBUSMENU_MENUITEM(data)); + current_props != NULL ; current_props = g_list_next(current_props)) { + if (g_hash_table_lookup(properties, current_props->data) == NULL) { + dbusmenu_menuitem_property_remove(DBUSMENU_MENUITEM(data), (const gchar *)current_props->data); + } + } + + menuitem_get_properties_cb(proxy, properties, error, data); + return; +} + /* This is a different get properites call back that also sends new signals. It basically is a small wrapper around the original. */ static void @@ -648,6 +664,7 @@ parse_layout_xml(DbusmenuClient * client, xmlNodePtr node, DbusmenuMenuitem * it #ifdef MASSIVEDEBUGGING g_debug("Client looking at node with id: %d", id); #endif + /* If we don't have any item, or the IDs don't match */ if (item == NULL || dbusmenu_menuitem_get_id(item) != id) { if (item != NULL) { if (parent != NULL) { @@ -676,6 +693,10 @@ parse_layout_xml(DbusmenuClient * client, xmlNodePtr node, DbusmenuMenuitem * it } else { g_warning("Unable to allocate memory to get properties for menuitem. This menuitem will never be realized."); } + } else { + /* Refresh the properties */ + gchar * properties[1] = {NULL}; /* This gets them all */ + org_ayatana_dbusmenu_get_properties_async(proxy, id, (const gchar **)properties, menuitem_get_properties_replace_cb, item); } xmlNodePtr children; -- cgit v1.2.3