From 8453c34c99dea3ab0742bfb87045b880a723c4f9 Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Thu, 4 Feb 2010 19:30:15 -0800 Subject: Setting the initial id to -1 and then if so, and we get it, find us a good one. --- 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 14bc2db..6739257 100644 --- a/libdbusmenu-glib/menuitem.c +++ b/libdbusmenu-glib/menuitem.c @@ -270,7 +270,7 @@ dbusmenu_menuitem_init (DbusmenuMenuitem *self) { DbusmenuMenuitemPrivate * priv = DBUSMENU_MENUITEM_GET_PRIVATE(self); - priv->id = 0; + priv->id = -1; priv->children = NULL; priv->properties = g_hash_table_new_full(g_str_hash, g_str_equal, g_free, _g_value_free); @@ -335,6 +335,9 @@ get_property (GObject * obj, guint id, GValue * value, GParamSpec * pspec) switch (id) { case PROP_ID: + if (priv->id == -1) { + priv->id = menuitem_next_id++; + } g_value_set_int(value, priv->id); break; } -- cgit v1.2.3 From ac26a4454690ed124e9efa5f5be6b4c3ac05c1b2 Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Thu, 4 Feb 2010 19:55:00 -0800 Subject: Changing the IDs so that they're all INTs --- libdbusmenu-glib/menuitem.c | 6 +++--- libdbusmenu-glib/menuitem.h | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/libdbusmenu-glib/menuitem.c b/libdbusmenu-glib/menuitem.c index 6739257..a6f0e40 100644 --- a/libdbusmenu-glib/menuitem.c +++ b/libdbusmenu-glib/menuitem.c @@ -395,15 +395,15 @@ dbusmenu_menuitem_new_with_id (gint id) Return value: The ID of the @mi. */ -guint +gint dbusmenu_menuitem_get_id (DbusmenuMenuitem * mi) { g_return_val_if_fail(DBUSMENU_IS_MENUITEM(mi), 0); GValue retval = {0}; - g_value_init(&retval, G_TYPE_UINT); + g_value_init(&retval, G_TYPE_INT); g_object_get_property(G_OBJECT(mi), "id", &retval); - return g_value_get_uint(&retval); + return g_value_get_int(&retval); } /** diff --git a/libdbusmenu-glib/menuitem.h b/libdbusmenu-glib/menuitem.h index 4fc144e..69f82e5 100644 --- a/libdbusmenu-glib/menuitem.h +++ b/libdbusmenu-glib/menuitem.h @@ -127,7 +127,7 @@ GType dbusmenu_menuitem_get_type (void); DbusmenuMenuitem * dbusmenu_menuitem_new (void) G_GNUC_WARN_UNUSED_RESULT; DbusmenuMenuitem * dbusmenu_menuitem_new_with_id (gint id) G_GNUC_WARN_UNUSED_RESULT; -guint dbusmenu_menuitem_get_id (DbusmenuMenuitem * mi); +gint dbusmenu_menuitem_get_id (DbusmenuMenuitem * mi); GList * dbusmenu_menuitem_get_children (DbusmenuMenuitem * mi); GList * dbusmenu_menuitem_take_children (DbusmenuMenuitem * mi) G_GNUC_WARN_UNUSED_RESULT; -- cgit v1.2.3 From f53b4c6d5d510948d17ffb8cd164b8429aaec552 Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Thu, 4 Feb 2010 20:45:14 -0800 Subject: Better error value now that we're on gint --- 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 a6f0e40..243b07e 100644 --- a/libdbusmenu-glib/menuitem.c +++ b/libdbusmenu-glib/menuitem.c @@ -398,7 +398,7 @@ dbusmenu_menuitem_new_with_id (gint id) gint dbusmenu_menuitem_get_id (DbusmenuMenuitem * mi) { - g_return_val_if_fail(DBUSMENU_IS_MENUITEM(mi), 0); + g_return_val_if_fail(DBUSMENU_IS_MENUITEM(mi), -1); GValue retval = {0}; g_value_init(&retval, G_TYPE_INT); -- cgit v1.2.3 From 77eaa10df429d43f8e92c05be8e06d00d4b20bd7 Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Thu, 4 Feb 2010 20:46:10 -0800 Subject: Turning 'id' into a #define --- libdbusmenu-glib/menuitem.c | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/libdbusmenu-glib/menuitem.c b/libdbusmenu-glib/menuitem.c index 243b07e..de4a079 100644 --- a/libdbusmenu-glib/menuitem.c +++ b/libdbusmenu-glib/menuitem.c @@ -80,6 +80,8 @@ enum { PROP_ID, }; +#define PROP_ID_S "id" + #define DBUSMENU_MENUITEM_GET_PRIVATE(o) \ (G_TYPE_INSTANCE_GET_PRIVATE ((o), DBUSMENU_TYPE_MENUITEM, DbusmenuMenuitemPrivate)) @@ -210,7 +212,7 @@ dbusmenu_menuitem_class_init (DbusmenuMenuitemClass *klass) G_TYPE_NONE, 0, G_TYPE_NONE); g_object_class_install_property (object_class, PROP_ID, - g_param_spec_int("id", "ID for the menu item", + g_param_spec_int(PROP_ID_S, "ID for the menu item", "This is a unique indentifier for the menu item.", 0, 30000, 0, G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY | G_PARAM_STATIC_STRINGS)); @@ -368,7 +370,7 @@ handle_event (DbusmenuMenuitem * mi, const gchar * name, const GValue * value, g DbusmenuMenuitem * dbusmenu_menuitem_new (void) { - return g_object_new(DBUSMENU_TYPE_MENUITEM, "id", menuitem_next_id++, NULL); + return g_object_new(DBUSMENU_TYPE_MENUITEM, PROP_ID_S, menuitem_next_id++, NULL); } /** @@ -382,7 +384,7 @@ dbusmenu_menuitem_new (void) DbusmenuMenuitem * dbusmenu_menuitem_new_with_id (gint id) { - DbusmenuMenuitem * mi = g_object_new(DBUSMENU_TYPE_MENUITEM, "id", id, NULL); + DbusmenuMenuitem * mi = g_object_new(DBUSMENU_TYPE_MENUITEM, PROP_ID_S, id, NULL); /* g_debug("New Menuitem id %d goal id %d", dbusmenu_menuitem_get_id(mi), id); */ return mi; } @@ -402,7 +404,7 @@ dbusmenu_menuitem_get_id (DbusmenuMenuitem * mi) GValue retval = {0}; g_value_init(&retval, G_TYPE_INT); - g_object_get_property(G_OBJECT(mi), "id", &retval); + g_object_get_property(G_OBJECT(mi), PROP_ID_S, &retval); return g_value_get_int(&retval); } -- cgit v1.2.3 From 7ab5984535b4e5165f09a7a2dd36c252f8bdfbc2 Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Thu, 4 Feb 2010 20:48:08 -0800 Subject: Removing the work around --- 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 de4a079..6540a70 100644 --- a/libdbusmenu-glib/menuitem.c +++ b/libdbusmenu-glib/menuitem.c @@ -370,7 +370,7 @@ handle_event (DbusmenuMenuitem * mi, const gchar * name, const GValue * value, g DbusmenuMenuitem * dbusmenu_menuitem_new (void) { - return g_object_new(DBUSMENU_TYPE_MENUITEM, PROP_ID_S, menuitem_next_id++, NULL); + return g_object_new(DBUSMENU_TYPE_MENUITEM, NULL); } /** -- cgit v1.2.3 From e7c73019f38016f3ccc630d74a312e4428e1acb9 Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Thu, 4 Feb 2010 21:13:04 -0800 Subject: Manage whether the menuitem thinks it's a root item in the server based on whether it's set as the root item. --- libdbusmenu-glib/server.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/libdbusmenu-glib/server.c b/libdbusmenu-glib/server.c index 7d8e5c3..eb7c383 100644 --- a/libdbusmenu-glib/server.c +++ b/libdbusmenu-glib/server.c @@ -237,12 +237,14 @@ set_property (GObject * obj, guint id, const GValue * value, GParamSpec * pspec) case PROP_ROOT_NODE: if (priv->root != NULL) { dbusmenu_menuitem_foreach(priv->root, menuitem_signals_remove, obj); + dbusmenu_menuitem_set_root(priv->root, FALSE); g_object_unref(G_OBJECT(priv->root)); priv->root = NULL; } priv->root = DBUSMENU_MENUITEM(g_value_get_object(value)); if (priv->root != NULL) { g_object_ref(G_OBJECT(priv->root)); + dbusmenu_menuitem_set_root(priv->root, TRUE); dbusmenu_menuitem_foreach(priv->root, menuitem_signals_create, obj); } else { g_debug("Setting root node to NULL"); -- cgit v1.2.3 From 6203f12f1efe370b7f45ace7fe56ce1afd34337c Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Thu, 4 Feb 2010 21:17:32 -0800 Subject: Making it so that find_id handles the root id being 0 case. --- libdbusmenu-glib/menuitem.c | 6 ++++++ libdbusmenu-glib/server.c | 2 +- 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/libdbusmenu-glib/menuitem.c b/libdbusmenu-glib/menuitem.c index 6540a70..6b8b505 100644 --- a/libdbusmenu-glib/menuitem.c +++ b/libdbusmenu-glib/menuitem.c @@ -715,6 +715,12 @@ DbusmenuMenuitem * dbusmenu_menuitem_find_id (DbusmenuMenuitem * mi, gint id) { g_return_val_if_fail(DBUSMENU_IS_MENUITEM(mi), NULL); + if (id == 0) { + if (dbusmenu_menuitem_get_root(mi) == FALSE) { + g_warning("Getting a menuitem with id zero, but it's not set as root."); + } + return mi; + } find_id_t find_id = {mi: NULL, id: id}; find_id_helper(mi, &find_id); return find_id.mi; diff --git a/libdbusmenu-glib/server.c b/libdbusmenu-glib/server.c index eb7c383..f8267c2 100644 --- a/libdbusmenu-glib/server.c +++ b/libdbusmenu-glib/server.c @@ -518,7 +518,7 @@ static gboolean _dbusmenu_server_get_children (DbusmenuServer * server, gint id, GPtrArray * properties, GPtrArray ** output, GError ** error) { DbusmenuServerPrivate * priv = DBUSMENU_SERVER_GET_PRIVATE(server); - DbusmenuMenuitem * mi = id == 0 ? priv->root : dbusmenu_menuitem_find_id(priv->root, id); + DbusmenuMenuitem * mi = dbusmenu_menuitem_find_id(priv->root, id); if (mi == NULL) { if (error != NULL) { -- cgit v1.2.3 From 4accd480cff9980188aa3966f7cbeb5615b922d3 Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Thu, 4 Feb 2010 21:35:32 -0800 Subject: Annoying little .lo --- .bzrignore | 1 + 1 file changed, 1 insertion(+) diff --git a/.bzrignore b/.bzrignore index d6fb87f..0066799 100644 --- a/.bzrignore +++ b/.bzrignore @@ -58,3 +58,4 @@ tests/test-glib-objects tests/test-glib-objects-test tests/test-glib-objects.xml tools/testapp/dbusmenu-testapp +libdbusmenu-glib/libdbusmenu_glib_la-client-menuitem.lo -- cgit v1.2.3 From b43ae677fdd98a90e541212f22d752a3ba5c0877 Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Thu, 4 Feb 2010 21:40:32 -0800 Subject: Checking the IDs from menuitems. --- tests/test-glib-objects.c | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/tests/test-glib-objects.c b/tests/test-glib-objects.c index f3fbcc8..1d4f673 100644 --- a/tests/test-glib-objects.c +++ b/tests/test-glib-objects.c @@ -47,6 +47,30 @@ test_object_menuitem (void) return; } +/* Check to make sure a new ID is bigger than 0 */ +static void +test_object_menuitem_id (void) +{ + /* Build a menu item */ + DbusmenuMenuitem * item = dbusmenu_menuitem_new(); + + /* Test to make sure it's a happy object */ + g_assert(item != NULL); + g_assert(G_IS_OBJECT(item)); + g_assert(DBUSMENU_IS_MENUITEM(item)); + + g_assert(dbusmenu_menuitem_get_id(item) > 0); + + /* Set up a check to make sure it gets destroyed on unref */ + g_object_add_weak_pointer(G_OBJECT(item), (gpointer *)&item); + g_object_unref(item); + + /* Did it go away? */ + g_assert(item == NULL); + + return; +} + /* Set a string prop, make sure it's stored as one */ static void test_object_menuitem_props_string (void) @@ -255,6 +279,7 @@ static void test_glib_objects_suite (void) { g_test_add_func ("/dbusmenu/glib/objects/menuitem/base", test_object_menuitem); + g_test_add_func ("/dbusmenu/glib/objects/menuitem/id", test_object_menuitem_id); g_test_add_func ("/dbusmenu/glib/objects/menuitem/props_string", test_object_menuitem_props_string); g_test_add_func ("/dbusmenu/glib/objects/menuitem/props_int", test_object_menuitem_props_int); g_test_add_func ("/dbusmenu/glib/objects/menuitem/props_bool", test_object_menuitem_props_bool); -- cgit v1.2.3 From a7295dd2c5647f2ed599380e67c07d2281f4fd08 Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Thu, 4 Feb 2010 21:41:32 -0800 Subject: Start at '1' instead of '0' --- 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 6b8b505..1f4038e 100644 --- a/libdbusmenu-glib/menuitem.c +++ b/libdbusmenu-glib/menuitem.c @@ -251,7 +251,7 @@ g_value_transform_STRING_INT (const GValue * in, GValue * out) return; } -static gint menuitem_next_id = 0; +static gint menuitem_next_id = 1; /* A small little function to both clear the insides of a value as well as the memory it itself uses. */ -- cgit v1.2.3 From b45a161f2cc5fc8aba4f1c8837ce337b1a9bb339 Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Thu, 4 Feb 2010 21:59:04 -0800 Subject: Getting massive debugging for getting the id --- libdbusmenu-glib/menuitem.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/libdbusmenu-glib/menuitem.c b/libdbusmenu-glib/menuitem.c index 1f4038e..2deac2c 100644 --- a/libdbusmenu-glib/menuitem.c +++ b/libdbusmenu-glib/menuitem.c @@ -405,7 +405,11 @@ dbusmenu_menuitem_get_id (DbusmenuMenuitem * mi) GValue retval = {0}; g_value_init(&retval, G_TYPE_INT); g_object_get_property(G_OBJECT(mi), PROP_ID_S, &retval); - return g_value_get_int(&retval); + gint ret = g_value_get_int(&retval); + #ifdef MASSIVEDEBUGGING + g_debug("Getting menuitem ID: %d", ret); + #endif + return ret; } /** -- cgit v1.2.3 From 326cb8348ebed49490eac85ff1db88f4ecd2491d Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Thu, 4 Feb 2010 22:01:04 -0800 Subject: Adding in warnings for invalid property ids --- libdbusmenu-glib/menuitem.c | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/libdbusmenu-glib/menuitem.c b/libdbusmenu-glib/menuitem.c index 2deac2c..467d3f4 100644 --- a/libdbusmenu-glib/menuitem.c +++ b/libdbusmenu-glib/menuitem.c @@ -325,6 +325,9 @@ set_property (GObject * obj, guint id, const GValue * value, GParamSpec * pspec) menuitem_next_id = priv->id + 1; } break; + default: + G_OBJECT_WARN_INVALID_PROPERTY_ID(obj, id, pspec); + break; } return; @@ -342,6 +345,9 @@ get_property (GObject * obj, guint id, GValue * value, GParamSpec * pspec) } g_value_set_int(value, priv->id); break; + default: + G_OBJECT_WARN_INVALID_PROPERTY_ID(obj, id, pspec); + break; } return; -- cgit v1.2.3 From 4c4e8cb681afda3eb23befa3db88fd05852d7d6a Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Thu, 4 Feb 2010 22:06:09 -0800 Subject: Changing the default for the property to be the same as the struct default. --- 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 467d3f4..cacc0a8 100644 --- a/libdbusmenu-glib/menuitem.c +++ b/libdbusmenu-glib/menuitem.c @@ -214,7 +214,7 @@ dbusmenu_menuitem_class_init (DbusmenuMenuitemClass *klass) g_object_class_install_property (object_class, PROP_ID, g_param_spec_int(PROP_ID_S, "ID for the menu item", "This is a unique indentifier for the menu item.", - 0, 30000, 0, + -1, 30000, -1, G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY | G_PARAM_STATIC_STRINGS)); /* Check transfer functions for GValue */ -- cgit v1.2.3 From a94d7042028da404cb336c0a0e9fcdadb2406a61 Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Thu, 4 Feb 2010 23:18:24 -0800 Subject: Changing key value to -1 and having the id be a gint. Also not working about id mismatch with root. --- tests/test-glib-layout-client.c | 8 +++++--- tests/test-glib-layout-server.c | 4 ++-- tests/test-glib-layout.h | 22 +++++++++++----------- 3 files changed, 18 insertions(+), 16 deletions(-) diff --git a/tests/test-glib-layout-client.c b/tests/test-glib-layout-client.c index bb2d13a..82228b5 100644 --- a/tests/test-glib-layout-client.c +++ b/tests/test-glib-layout-client.c @@ -36,8 +36,10 @@ verify_root_to_layout(DbusmenuMenuitem * mi, layout_t * layout) g_debug("Verifying ID: %d", layout->id); if (layout->id != dbusmenu_menuitem_get_id(mi)) { - g_debug("Failed as ID %d is not equal to %d", layout->id, dbusmenu_menuitem_get_id(mi)); - return FALSE; + if (!(dbusmenu_menuitem_get_root(mi) && dbusmenu_menuitem_get_id(mi) == 0)) { + g_debug("Failed as ID %d is not equal to %d", layout->id, dbusmenu_menuitem_get_id(mi)); + return FALSE; + } } GList * children = dbusmenu_menuitem_get_children(mi); @@ -88,7 +90,7 @@ layout_updated (DbusmenuClient * client, gpointer data) layouton++; - if (layouts[layouton].id == 0) { + if (layouts[layouton].id == -1) { g_main_loop_quit(mainloop); } diff --git a/tests/test-glib-layout-server.c b/tests/test-glib-layout-server.c index 40dd048..111e164 100644 --- a/tests/test-glib-layout-server.c +++ b/tests/test-glib-layout-server.c @@ -41,7 +41,7 @@ layout2menuitem (layout_t * layout) if (layout->submenu != NULL) { guint count; - for (count = 0; layout->submenu[count].id != 0; count++) { + for (count = 0; layout->submenu[count].id != -1; count++) { DbusmenuMenuitem * child = layout2menuitem(&layout->submenu[count]); if (child != NULL) { dbusmenu_menuitem_child_append(local, child); @@ -60,7 +60,7 @@ static GMainLoop * mainloop = NULL; static gboolean timer_func (gpointer data) { - if (layouts[layouton].id == 0) { + if (layouts[layouton].id == -1) { g_main_loop_quit(mainloop); return FALSE; } diff --git a/tests/test-glib-layout.h b/tests/test-glib-layout.h index a13125d..b64c4ea 100644 --- a/tests/test-glib-layout.h +++ b/tests/test-glib-layout.h @@ -21,51 +21,51 @@ with this program. If not, see . typedef struct _layout_t layout_t; struct _layout_t { - guint id; + gint id; layout_t * submenu; }; layout_t submenu_2[] = { {id: 2, submenu: NULL}, {id: 3, submenu: NULL}, - {id: 0, submenu: NULL} + {id: -1, submenu: NULL} }; layout_t submenu_3_1[] = { {id: 3, submenu: NULL}, {id: 4, submenu: NULL}, {id: 5, submenu: NULL}, - {id: 0, submenu: NULL} + {id: -1, submenu: NULL} }; layout_t submenu_3_2[] = { {id: 7, submenu: NULL}, {id: 8, submenu: NULL}, {id: 9, submenu: NULL}, - {id: 0, submenu: NULL} + {id: -1, submenu: NULL} }; layout_t submenu_3[] = { {id: 2, submenu: submenu_3_1}, {id: 6, submenu: submenu_3_2}, - {id: 0, submenu: NULL} + {id: -1, submenu: NULL} }; layout_t submenu_4_1[] = { {id: 6, submenu: NULL}, - {id: 0, submenu: NULL} + {id: -1, submenu: NULL} }; layout_t submenu_4_2[] = { {id: 5, submenu: submenu_4_1}, - {id: 0, submenu: NULL} + {id: -1, submenu: NULL} }; layout_t submenu_4_3[] = { {id: 4, submenu: submenu_4_2}, - {id: 0, submenu: NULL} + {id: -1, submenu: NULL} }; layout_t submenu_4_4[] = { {id: 3, submenu: submenu_4_3}, - {id: 0, submenu: NULL} + {id: -1, submenu: NULL} }; layout_t submenu_4_5[] = { {id: 2, submenu: submenu_4_4}, - {id: 0, submenu: NULL} + {id: -1, submenu: NULL} }; layout_t layouts[] = { @@ -73,6 +73,6 @@ layout_t layouts[] = { {id: 1, submenu: submenu_2}, {id: 1, submenu: submenu_3}, {id: 1, submenu: submenu_4_5}, - {id: 0, submenu: NULL} + {id: -1, submenu: NULL} }; -- cgit v1.2.3 From 8cdb78101d94804eab37cb0f71c3f498cc0b885c Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Fri, 5 Feb 2010 09:13:58 -0800 Subject: Not failing if the IDs are different when the menuitem is root --- tests/test-glib-properties-client.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/tests/test-glib-properties-client.c b/tests/test-glib-properties-client.c index 39815aa..cb3d371 100644 --- a/tests/test-glib-properties-client.c +++ b/tests/test-glib-properties-client.c @@ -60,8 +60,10 @@ verify_root_to_layout(DbusmenuMenuitem * mi, proplayout_t * layout) g_debug("Verifying ID: %d", layout->id); if (layout->id != dbusmenu_menuitem_get_id(mi)) { - g_debug("\tFailed as ID %d is not equal to %d", layout->id, dbusmenu_menuitem_get_id(mi)); - return FALSE; + if (!dbusmenu_menuitem_get_root(mi)) { + g_debug("\tFailed as ID %d is not equal to %d", layout->id, dbusmenu_menuitem_get_id(mi)); + return FALSE; + } } if (!verify_props(mi, layout->properties)) { -- cgit v1.2.3 From 917517950f45b048111687f2cbae0616b4ef2cba Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Fri, 5 Feb 2010 09:19:42 -0800 Subject: If we're the root item always return that our ID is zero. --- libdbusmenu-glib/menuitem.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/libdbusmenu-glib/menuitem.c b/libdbusmenu-glib/menuitem.c index cacc0a8..8350b41 100644 --- a/libdbusmenu-glib/menuitem.c +++ b/libdbusmenu-glib/menuitem.c @@ -343,7 +343,11 @@ get_property (GObject * obj, guint id, GValue * value, GParamSpec * pspec) if (priv->id == -1) { priv->id = menuitem_next_id++; } - g_value_set_int(value, priv->id); + if (dbusmenu_menuitem_get_root(DBUSMENU_MENUITEM(obj))) { + g_value_set_int(value, 0); + } else { + g_value_set_int(value, priv->id); + } break; default: G_OBJECT_WARN_INVALID_PROPERTY_ID(obj, id, pspec); -- cgit v1.2.3 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(+) 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(-) 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 a930e6973028bc4e86080f2ae4b072a3f9cc61d0 Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Fri, 5 Feb 2010 09:54:42 -0800 Subject: Changing to the new ID error --- tests/test-glib-layout-client.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/test-glib-layout-client.c b/tests/test-glib-layout-client.c index 82228b5..5ea0cf8 100644 --- a/tests/test-glib-layout-client.c +++ b/tests/test-glib-layout-client.c @@ -57,13 +57,13 @@ verify_root_to_layout(DbusmenuMenuitem * mi, layout_t * layout) } guint i = 0; - for (i = 0; children != NULL && layout->submenu[i].id != 0; children = g_list_next(children), i++) { + for (i = 0; children != NULL && layout->submenu[i].id != -1; children = g_list_next(children), i++) { if (!verify_root_to_layout(DBUSMENU_MENUITEM(children->data), &layout->submenu[i])) { return FALSE; } } - if (children == NULL && layout->submenu[i].id == 0) { + if (children == NULL && layout->submenu[i].id == -1) { return TRUE; } -- cgit v1.2.3 From 277508f994a163f0e4acb8a18253aa08b9b3514a Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Fri, 5 Feb 2010 10:10:47 -0800 Subject: Changing the ID to be -1 instead of 0 --- tests/test-glib-properties-client.c | 6 +++--- tests/test-glib-properties-server.c | 6 +++--- tests/test-glib-properties.h | 12 ++++++------ 3 files changed, 12 insertions(+), 12 deletions(-) diff --git a/tests/test-glib-properties-client.c b/tests/test-glib-properties-client.c index cb3d371..434465a 100644 --- a/tests/test-glib-properties-client.c +++ b/tests/test-glib-properties-client.c @@ -87,13 +87,13 @@ verify_root_to_layout(DbusmenuMenuitem * mi, proplayout_t * layout) } guint i = 0; - for (i = 0; children != NULL && layout->submenu[i].id != 0; children = g_list_next(children), i++) { + for (i = 0; children != NULL && layout->submenu[i].id != -1; children = g_list_next(children), i++) { if (!verify_root_to_layout(DBUSMENU_MENUITEM(children->data), &layout->submenu[i])) { return FALSE; } } - if (children == NULL && layout->submenu[i].id == 0) { + if (children == NULL && layout->submenu[i].id == -1) { g_debug("\tPassed: %d", layout->id); return TRUE; } @@ -142,7 +142,7 @@ layout_verify_timer (gpointer data) layouton++; - if (layouts[layouton].id == 0) { + if (layouts[layouton].id == -1) { g_main_loop_quit(mainloop); } diff --git a/tests/test-glib-properties-server.c b/tests/test-glib-properties-server.c index 8dad37f..091e550 100644 --- a/tests/test-glib-properties-server.c +++ b/tests/test-glib-properties-server.c @@ -46,14 +46,14 @@ set_props (DbusmenuMenuitem * mi, gchar ** props) static DbusmenuMenuitem * layout2menuitem (proplayout_t * layout) { - if (layout == NULL || layout->id == 0) return NULL; + if (layout == NULL || layout->id == -1) return NULL; DbusmenuMenuitem * local = dbusmenu_menuitem_new_with_id(layout->id); set_props(local, layout->properties); if (layout->submenu != NULL) { guint count; - for (count = 0; layout->submenu[count].id != 0; count++) { + for (count = 0; layout->submenu[count].id != -1; count++) { DbusmenuMenuitem * child = layout2menuitem(&layout->submenu[count]); if (child != NULL) { dbusmenu_menuitem_child_append(local, child); @@ -72,7 +72,7 @@ static GMainLoop * mainloop = NULL; static gboolean timer_func (gpointer data) { - if (layouts[layouton].id == 0) { + if (layouts[layouton].id == -1) { g_main_loop_quit(mainloop); return FALSE; } diff --git a/tests/test-glib-properties.h b/tests/test-glib-properties.h index 5e83f5c..c0c929a 100644 --- a/tests/test-glib-properties.h +++ b/tests/test-glib-properties.h @@ -24,7 +24,7 @@ with this program. If not, see . typedef struct _proplayout_t proplayout_t; struct _proplayout_t { - guint id; + gint id; gchar ** properties; proplayout_t * submenu; }; @@ -68,7 +68,7 @@ proplayout_t submenu_4_1[] = { {id: 17, properties: props2, submenu: NULL}, {id: 18, properties: props2, submenu: NULL}, {id: 19, properties: props2, submenu: NULL}, - {id: 0, properties: NULL, submenu: NULL} + {id: -1, properties: NULL, submenu: NULL} }; proplayout_t submenu_4_2[] = { @@ -82,7 +82,7 @@ proplayout_t submenu_4_2[] = { {id: 27, properties: props2, submenu: NULL}, {id: 28, properties: props2, submenu: NULL}, {id: 29, properties: props2, submenu: NULL}, - {id: 0, properties: NULL, submenu: NULL} + {id: -1, properties: NULL, submenu: NULL} }; proplayout_t submenu_4_3[] = { @@ -96,14 +96,14 @@ proplayout_t submenu_4_3[] = { {id: 37, properties: props2, submenu: NULL}, {id: 38, properties: props2, submenu: NULL}, {id: 39, properties: props2, submenu: NULL}, - {id: 0, properties: NULL, submenu: NULL} + {id: -1, properties: NULL, submenu: NULL} }; proplayout_t submenu_4_0[] = { {id: 1, properties: props2, submenu: submenu_4_1}, {id: 2, properties: props2, submenu: submenu_4_2}, {id: 3, properties: props2, submenu: submenu_4_3}, - {id: 0, properties: NULL, submenu: NULL} + {id: -1, properties: NULL, submenu: NULL} }; proplayout_t layouts[] = { @@ -111,6 +111,6 @@ proplayout_t layouts[] = { {id: 10, properties: props2, submenu: NULL}, {id: 20, properties: props3, submenu: NULL}, {id: 100, properties: props2, submenu: submenu_4_0}, - {id: 0, properties: NULL, submenu: NULL} + {id: -1, properties: NULL, submenu: NULL} }; -- 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(-) 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 +++++++++++++++++++++ libdbusmenu-glib/menuitem.c | 20 ++++++++++++++++++++ libdbusmenu-glib/menuitem.h | 1 + 3 files changed, 42 insertions(+) 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; diff --git a/libdbusmenu-glib/menuitem.c b/libdbusmenu-glib/menuitem.c index 8350b41..a2d2682 100644 --- a/libdbusmenu-glib/menuitem.c +++ b/libdbusmenu-glib/menuitem.c @@ -987,6 +987,26 @@ dbusmenu_menuitem_property_exist (DbusmenuMenuitem * mi, const gchar * property) return value != NULL; } +/** + dbusmenu_menuitem_property_remove: + @mi: The #DbusmenuMenuitem to remove the property on. + @property: The property to look for. + + Removes a property from the menuitem. +*/ +void +dbusmenu_menuitem_property_remove (DbusmenuMenuitem * mi, const gchar * property) +{ + g_return_if_fail(DBUSMENU_IS_MENUITEM(mi)); + g_return_if_fail(property != NULL); + + DbusmenuMenuitemPrivate * priv = DBUSMENU_MENUITEM_GET_PRIVATE(mi); + + g_hash_table_remove(priv->properties, property); + + return; +} + /** dbusmenu_menuitem_properties_list: @mi: #DbusmenuMenuitem to list the properties on diff --git a/libdbusmenu-glib/menuitem.h b/libdbusmenu-glib/menuitem.h index 69f82e5..1382335 100644 --- a/libdbusmenu-glib/menuitem.h +++ b/libdbusmenu-glib/menuitem.h @@ -152,6 +152,7 @@ gint dbusmenu_menuitem_property_get_int (DbusmenuMenuitem * mi, const gchar * pr 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); +void dbusmenu_menuitem_property_remove (DbusmenuMenuitem * mi, const gchar * property); void dbusmenu_menuitem_set_root (DbusmenuMenuitem * mi, gboolean root); gboolean dbusmenu_menuitem_get_root (DbusmenuMenuitem * mi); -- cgit v1.2.3