From a12a7aeb24ca9d310463fba824a47041b4677c25 Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Tue, 12 May 2009 11:49:55 -0500 Subject: Adding proporties to the private object. --- libdbusmenu-glib/menuitem.c | 2 ++ 1 file changed, 2 insertions(+) (limited to 'libdbusmenu-glib/menuitem.c') diff --git a/libdbusmenu-glib/menuitem.c b/libdbusmenu-glib/menuitem.c index 6360079..f228059 100644 --- a/libdbusmenu-glib/menuitem.c +++ b/libdbusmenu-glib/menuitem.c @@ -37,6 +37,7 @@ License version 3 and version 2.1 along with this program. If not, see @id: The ID of this menu item @children: A list of #DbusmenuMenuitem objects that are children to this one. + @properties: All of the properties on this menu item. These are the little secrets that we don't want getting out of data that we have. They can still be gotten using @@ -47,6 +48,7 @@ struct _DbusmenuMenuitemPrivate { guint id; GList * children; + GHashTable * properties; }; /* Properties */ -- cgit v1.2.3 From 0dccfbb4232b7711fb9c5b0f79e8e8f6d062217a Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Tue, 12 May 2009 11:55:15 -0500 Subject: Creating and destroying the properties. --- libdbusmenu-glib/menuitem.c | 8 ++++++++ 1 file changed, 8 insertions(+) (limited to 'libdbusmenu-glib/menuitem.c') diff --git a/libdbusmenu-glib/menuitem.c b/libdbusmenu-glib/menuitem.c index 742fc93..0641932 100644 --- a/libdbusmenu-glib/menuitem.c +++ b/libdbusmenu-glib/menuitem.c @@ -101,6 +101,8 @@ dbusmenu_menuitem_init (DbusmenuMenuitem *self) priv->id = 0; priv->children = NULL; + + priv->properties = g_hash_table_new_full(g_str_hash, g_str_equal, g_free, g_free); return; } @@ -116,6 +118,12 @@ dbusmenu_menuitem_dispose (GObject *object) static void dbusmenu_menuitem_finalize (GObject *object) { + DbusmenuMenuitemPrivate * priv = DBUSMENU_MENUITEM_GET_PRIVATE(object); + + if (priv->properties != NULL) { + g_hash_table_destroy(priv->properties); + priv->properties = NULL; + } G_OBJECT_CLASS (dbusmenu_menuitem_parent_class)->finalize (object); return; -- cgit v1.2.3 From 7ee71a2ec688646f0790b84fe82f99026f021e0c Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Tue, 12 May 2009 14:37:37 -0500 Subject: Fleshing out the property get and set functions (and exist) --- libdbusmenu-glib/menuitem.c | 71 +++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 68 insertions(+), 3 deletions(-) (limited to 'libdbusmenu-glib/menuitem.c') diff --git a/libdbusmenu-glib/menuitem.c b/libdbusmenu-glib/menuitem.c index 0641932..1ada67e 100644 --- a/libdbusmenu-glib/menuitem.c +++ b/libdbusmenu-glib/menuitem.c @@ -381,25 +381,90 @@ dbusmenu_menuitem_child_find (DbusmenuMenuitem * mi, guint id) return NULL; } +/** + dbusmenu_menuitem_property_set: + @mi: The #DbusmenuMenuitem to set the property on. + @property: Name of the property to set. + @value: The value of the property. + + Takes the pair of @property and @value and places them as a + property on @mi. If a property already exists by that name, + then the value is set to the new value. If not, the property + is added. If the value is changed or the property was previously + unset then the signal #DbusmenuMenuitem::prop-changed will be + emitted by this function. + + Return value: A boolean representing if the property value was set. +*/ gboolean dbusmenu_menuitem_property_set (DbusmenuMenuitem * mi, const gchar * property, const gchar * value) { + g_return_val_if_fail(DBUSMENU_IS_MENUITEM(mi), FALSE); + g_return_val_if_fail(property != NULL, FALSE); + + DbusmenuMenuitemPrivate * priv = DBUSMENU_MENUITEM_GET_PRIVATE(mi); + + gpointer lookup = g_hash_table_lookup(priv->properties, property); + if (g_strcmp0((gchar *)lookup, value) == 0) { + /* The value is the same as the value currently in the + table so we don't really care. Just say everything's okay */ + return TRUE; + } - return FALSE; + gchar * lprop = g_strdup(property); + gchar * lval = g_strdup(value); + + g_hash_table_insert(priv->properties, lprop, lval); + //g_signal_emit(G_OBJECT(mi), signals[PROPERTY_CHANGED], 0, property, TRUE); + + return TRUE; } +/** + dbusmenu_menuitem_property_get: + @mi: The #DbusmenuMenuitem to look for the property on. + @property: The property to grab. + + Look up a property on @mi and return the value of it if + it exits. #NULL will be returned if the property doesn't + exist. + + Return value: A string with the value of the property + that shouldn't be free'd. Or #NULL if the property + is not set. +*/ const gchar * dbusmenu_menuitem_property_get (DbusmenuMenuitem * mi, const gchar * property) { + g_return_val_if_fail(DBUSMENU_IS_MENUITEM(mi), NULL); + g_return_val_if_fail(property != NULL, NULL); - return NULL; + DbusmenuMenuitemPrivate * priv = DBUSMENU_MENUITEM_GET_PRIVATE(mi); + + return (const gchar *)g_hash_table_lookup(priv->properties, property); } +/** + dbusmenu_menuitem_property_exit: + @mi: The #DbusmenuMenuitem to look for the property on. + @property: The property to look for. + + Checkes to see if a particular property exists on @mi and + returns #TRUE if so. + + Return value: A boolean checking to see if the property is available +*/ gboolean dbusmenu_menuitem_property_exist (DbusmenuMenuitem * mi, const gchar * property) { + g_return_val_if_fail(DBUSMENU_IS_MENUITEM(mi), FALSE); + g_return_val_if_fail(property != NULL, FALSE); + + DbusmenuMenuitemPrivate * priv = DBUSMENU_MENUITEM_GET_PRIVATE(mi); + + gpointer value = g_hash_table_lookup(priv->properties, property); - return FALSE; + return value != NULL; } /** -- cgit v1.2.3 From 65cccec1e3ccf655a95d3d21e8b435df3bfbb477 Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Tue, 12 May 2009 15:04:04 -0500 Subject: Creating the property changed signal and emitting it. --- libdbusmenu-glib/menuitem.c | 26 +++++++++++++++++++++++++- 1 file changed, 25 insertions(+), 1 deletion(-) (limited to 'libdbusmenu-glib/menuitem.c') diff --git a/libdbusmenu-glib/menuitem.c b/libdbusmenu-glib/menuitem.c index 1ada67e..28b0dd0 100644 --- a/libdbusmenu-glib/menuitem.c +++ b/libdbusmenu-glib/menuitem.c @@ -51,6 +51,14 @@ struct _DbusmenuMenuitemPrivate GHashTable * properties; }; +/* Signals */ +enum { + PROPERTY_CHANGED, + LAST_SIGNAL +}; + +static guint signals[LAST_SIGNAL] = { 0 }; + /* Properties */ enum { PROP_0, @@ -83,6 +91,22 @@ dbusmenu_menuitem_class_init (DbusmenuMenuitemClass *klass) object_class->set_property = set_property; object_class->get_property = get_property; + /** + DbusmenuMenuitem::property-changed: + @arg0: The #DbusmenuMenuitem object. + @arg1: The name of the property that changed + + Emitted everytime a property on a menuitem is either + updated or added. + */ + signals[PROPERTY_CHANGED] = g_signal_new(DBUSMENU_MENUITEM_SIGNAL_PROPERTY_CHANGED, + G_TYPE_FROM_CLASS(klass), + G_SIGNAL_RUN_LAST, + G_STRUCT_OFFSET(DbusmenuMenuitemClass, property_changed), + NULL, NULL, + g_cclosure_marshal_VOID__STRING, + G_TYPE_NONE, 1, G_TYPE_STRING); + g_object_class_install_property (object_class, PROP_ID, g_param_spec_uint("id", "ID for the menu item", "This is a unique indentifier for the menu item.", @@ -415,7 +439,7 @@ dbusmenu_menuitem_property_set (DbusmenuMenuitem * mi, const gchar * property, c gchar * lval = g_strdup(value); g_hash_table_insert(priv->properties, lprop, lval); - //g_signal_emit(G_OBJECT(mi), signals[PROPERTY_CHANGED], 0, property, TRUE); + g_signal_emit(G_OBJECT(mi), signals[PROPERTY_CHANGED], 0, property, TRUE); return TRUE; } -- cgit v1.2.3 From 777fdb298f9f61e309fa9d0c31adb015667f9358 Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Tue, 12 May 2009 15:31:39 -0500 Subject: Changing the property update function to make it match closer to the dbus spec with two parameters. --- libdbusmenu-glib/menuitem.c | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) (limited to 'libdbusmenu-glib/menuitem.c') diff --git a/libdbusmenu-glib/menuitem.c b/libdbusmenu-glib/menuitem.c index 28b0dd0..4ee88c7 100644 --- a/libdbusmenu-glib/menuitem.c +++ b/libdbusmenu-glib/menuitem.c @@ -95,6 +95,7 @@ dbusmenu_menuitem_class_init (DbusmenuMenuitemClass *klass) DbusmenuMenuitem::property-changed: @arg0: The #DbusmenuMenuitem object. @arg1: The name of the property that changed + @arg2: The new value of the property Emitted everytime a property on a menuitem is either updated or added. @@ -104,8 +105,8 @@ dbusmenu_menuitem_class_init (DbusmenuMenuitemClass *klass) G_SIGNAL_RUN_LAST, G_STRUCT_OFFSET(DbusmenuMenuitemClass, property_changed), NULL, NULL, - g_cclosure_marshal_VOID__STRING, - G_TYPE_NONE, 1, G_TYPE_STRING); + g_cclosure_marshal_VOID__STRING_STRING, + G_TYPE_NONE, 2, G_TYPE_STRING, G_TYPE_STRING); g_object_class_install_property (object_class, PROP_ID, g_param_spec_uint("id", "ID for the menu item", @@ -439,7 +440,7 @@ dbusmenu_menuitem_property_set (DbusmenuMenuitem * mi, const gchar * property, c gchar * lval = g_strdup(value); g_hash_table_insert(priv->properties, lprop, lval); - g_signal_emit(G_OBJECT(mi), signals[PROPERTY_CHANGED], 0, property, TRUE); + g_signal_emit(G_OBJECT(mi), signals[PROPERTY_CHANGED], 0, property, value, TRUE); return TRUE; } -- cgit v1.2.3 From 6e8815b08af88622cd5add61a7088fc45ab73f37 Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Tue, 12 May 2009 15:35:28 -0500 Subject: Getting the proper marshaller for the change in API --- libdbusmenu-glib/menuitem.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'libdbusmenu-glib/menuitem.c') diff --git a/libdbusmenu-glib/menuitem.c b/libdbusmenu-glib/menuitem.c index 4ee88c7..99cae09 100644 --- a/libdbusmenu-glib/menuitem.c +++ b/libdbusmenu-glib/menuitem.c @@ -30,6 +30,7 @@ License version 3 and version 2.1 along with this program. If not, see #include "config.h" #endif #include "menuitem.h" +#include "menuitem-marshal.h" /* Private */ /** @@ -105,7 +106,7 @@ dbusmenu_menuitem_class_init (DbusmenuMenuitemClass *klass) G_SIGNAL_RUN_LAST, G_STRUCT_OFFSET(DbusmenuMenuitemClass, property_changed), NULL, NULL, - g_cclosure_marshal_VOID__STRING_STRING, + _dbusmenu_menuitem_marshal_VOID__STRING_STRING, G_TYPE_NONE, 2, G_TYPE_STRING, G_TYPE_STRING); g_object_class_install_property (object_class, PROP_ID, -- cgit v1.2.3 From 69228957b49867644ecc5351d5dc1e0f0458fc95 Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Tue, 12 May 2009 15:54:08 -0500 Subject: Adding in a foreach function for menuitems. --- libdbusmenu-glib/menuitem.c | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) (limited to 'libdbusmenu-glib/menuitem.c') diff --git a/libdbusmenu-glib/menuitem.c b/libdbusmenu-glib/menuitem.c index 99cae09..2d50bc6 100644 --- a/libdbusmenu-glib/menuitem.c +++ b/libdbusmenu-glib/menuitem.c @@ -523,3 +523,35 @@ dbusmenu_menuitem_buildxml (DbusmenuMenuitem * mi, GPtrArray * array) return; } +typedef struct { + void (*func) (DbusmenuMenuitem * mi, gpointer data); + gpointer data; +} foreach_struct_t; + +static void +foreach_helper (gpointer data, gpointer user_data) +{ + dbusmenu_menuitem_foreach(DBUSMENU_MENUITEM(data), ((foreach_struct_t *)user_data)->func, ((foreach_struct_t *)user_data)->data); + return; +} + +/** + dbusmenu_menuitem_foreach: + @mi: The #DbusmenItem to start from + @func: Function to call on every node in the tree + @data: User data to pass to the function + + This calls the function @func on this menu item and all + of the children of this item. And their children. And + their children. And... you get the point. It will get + called on the whole tree. +*/ +void +dbusmenu_menuitem_foreach (DbusmenuMenuitem * mi, void (*func) (DbusmenuMenuitem * mi, gpointer data), gpointer data) +{ + func(mi, data); + GList * children = dbusmenu_menuitem_get_children(mi); + foreach_struct_t foreach_data = {func: func, data: data}; + g_list_foreach(children, foreach_helper, &foreach_data); + return; +} -- cgit v1.2.3 From 7b53f1b10253936c905c77e29187493c4e3781e7 Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Tue, 12 May 2009 16:25:36 -0500 Subject: Adding in signals for child_added and child_removed --- libdbusmenu-glib/menuitem.c | 47 +++++++++++++++++++++++++++++++++++++++------ 1 file changed, 41 insertions(+), 6 deletions(-) (limited to 'libdbusmenu-glib/menuitem.c') diff --git a/libdbusmenu-glib/menuitem.c b/libdbusmenu-glib/menuitem.c index 2d50bc6..c4ffa3d 100644 --- a/libdbusmenu-glib/menuitem.c +++ b/libdbusmenu-glib/menuitem.c @@ -55,6 +55,9 @@ struct _DbusmenuMenuitemPrivate /* Signals */ enum { PROPERTY_CHANGED, + ITEM_ACTIVATED, + CHILD_ADDED, + CHILD_REMOVED, LAST_SIGNAL }; @@ -102,12 +105,44 @@ dbusmenu_menuitem_class_init (DbusmenuMenuitemClass *klass) updated or added. */ signals[PROPERTY_CHANGED] = g_signal_new(DBUSMENU_MENUITEM_SIGNAL_PROPERTY_CHANGED, - G_TYPE_FROM_CLASS(klass), - G_SIGNAL_RUN_LAST, - G_STRUCT_OFFSET(DbusmenuMenuitemClass, property_changed), - NULL, NULL, - _dbusmenu_menuitem_marshal_VOID__STRING_STRING, - G_TYPE_NONE, 2, G_TYPE_STRING, G_TYPE_STRING); + G_TYPE_FROM_CLASS(klass), + G_SIGNAL_RUN_LAST, + G_STRUCT_OFFSET(DbusmenuMenuitemClass, property_changed), + NULL, NULL, + _dbusmenu_menuitem_marshal_VOID__STRING_STRING, + G_TYPE_NONE, 2, G_TYPE_STRING, G_TYPE_STRING); + /** + DbusmenuMenuitem::child-added: + @arg0: The #DbusmenuMenuitem which is the parent. + @arg1: The #DbusmenuMenuitem which is the child. + + Signaled when the child menuitem has been added to + the parent. + */ + signals[CHILD_ADDED] = g_signal_new(DBUSMENU_MENUITEM_SIGNAL_CHILD_ADDED, + G_TYPE_FROM_CLASS(klass), + G_SIGNAL_RUN_LAST, + G_STRUCT_OFFSET(DbusmenuMenuitemClass, child_added), + NULL, NULL, + _dbusmenu_menuitem_marshal_VOID__OBJECT, + G_TYPE_NONE, 2, G_TYPE_OBJECT); + /** + DbusmenuMenuitem::child-removed: + @arg0: The #DbusmenuMenuitem which was the parent. + @arg1: The #DbusmenuMenuitem which was the child. + + Signaled when the child menuitem has been requested to + be removed from the parent. This signal is called when + it has been removed from the list but not yet had + #g_object_unref called on it. + */ + signals[CHILD_REMOVED] = g_signal_new(DBUSMENU_MENUITEM_SIGNAL_CHILD_REMOVED, + G_TYPE_FROM_CLASS(klass), + G_SIGNAL_RUN_LAST, + G_STRUCT_OFFSET(DbusmenuMenuitemClass, child_removed), + NULL, NULL, + _dbusmenu_menuitem_marshal_VOID__OBJECT, + G_TYPE_NONE, 2, G_TYPE_OBJECT); g_object_class_install_property (object_class, PROP_ID, g_param_spec_uint("id", "ID for the menu item", -- cgit v1.2.3 From 5971493366cde4f9cc55d963b22d451dd7ffbbcd Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Tue, 12 May 2009 16:34:49 -0500 Subject: Adding in the activate signal and a function to emit it on the server side of things. --- libdbusmenu-glib/menuitem.c | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) (limited to 'libdbusmenu-glib/menuitem.c') diff --git a/libdbusmenu-glib/menuitem.c b/libdbusmenu-glib/menuitem.c index c4ffa3d..6cfd581 100644 --- a/libdbusmenu-glib/menuitem.c +++ b/libdbusmenu-glib/menuitem.c @@ -111,6 +111,20 @@ dbusmenu_menuitem_class_init (DbusmenuMenuitemClass *klass) NULL, NULL, _dbusmenu_menuitem_marshal_VOID__STRING_STRING, G_TYPE_NONE, 2, G_TYPE_STRING, G_TYPE_STRING); + /** + DbusmenuMenuitem::item-activated: + @arg0: The #DbusmenuMenuitem object. + + Emitted on the objects on the server side when + they are signaled on the client side. + */ + signals[ITEM_ACTIVATED] = g_signal_new(DBUSMENU_MENUITEM_SIGNAL_ITEM_ACTIVATED, + G_TYPE_FROM_CLASS(klass), + G_SIGNAL_RUN_LAST, + G_STRUCT_OFFSET(DbusmenuMenuitemClass, item_activated), + NULL, NULL, + _dbusmenu_menuitem_marshal_VOID__VOID, + G_TYPE_NONE, 0, G_TYPE_NONE); /** DbusmenuMenuitem::child-added: @arg0: The #DbusmenuMenuitem which is the parent. @@ -590,3 +604,18 @@ dbusmenu_menuitem_foreach (DbusmenuMenuitem * mi, void (*func) (DbusmenuMenuitem g_list_foreach(children, foreach_helper, &foreach_data); return; } + +/** + dbusmenu_menuitem_activate: + @mi: The #DbusmenuMenuitem to send the signal on. + + Emits the #DbusmenuMenuitem::item-activate signal on this + menu item. Called by server objects when they get the + appropriate DBus signals from the client. +*/ +void +dbusmenu_menuitem_activate (DbusmenuMenuitem * mi) +{ + g_signal_emit(G_OBJECT(mi), signals[ITEM_ACTIVATED], 0, TRUE); + return; +} -- cgit v1.2.3 From 9a9f8a2e19a14c03fe45b53867d4aa12127333a6 Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Tue, 12 May 2009 16:55:00 -0500 Subject: Start signalling when children are added or removed --- libdbusmenu-glib/menuitem.c | 13 +++++++++++++ 1 file changed, 13 insertions(+) (limited to 'libdbusmenu-glib/menuitem.c') diff --git a/libdbusmenu-glib/menuitem.c b/libdbusmenu-glib/menuitem.c index 6cfd581..2563eb2 100644 --- a/libdbusmenu-glib/menuitem.c +++ b/libdbusmenu-glib/menuitem.c @@ -308,6 +308,15 @@ dbusmenu_menuitem_get_children (DbusmenuMenuitem * mi) return priv->children; } +/* For all the taken children we need to signal + that they were removed */ +static void +take_children_signal (gpointer data, gpointer user_data) +{ + g_signal_emit(G_OBJECT(user_data), signals[CHILD_REMOVED], 0, DBUSMENU_MENUITEM(data), TRUE); + return; +} + /** dbusmenu_menuitem_take_children: @mi: The #DbusmenMenuitem to take the children from. @@ -328,6 +337,7 @@ dbusmenu_menuitem_take_children (DbusmenuMenuitem * mi) DbusmenuMenuitemPrivate * priv = DBUSMENU_MENUITEM_GET_PRIVATE(mi); GList * children = priv->children; priv->children = NULL; + g_list_foreach(children, take_children_signal, mi); return children; } @@ -379,6 +389,7 @@ dbusmenu_menuitem_child_append (DbusmenuMenuitem * mi, DbusmenuMenuitem * child) DbusmenuMenuitemPrivate * priv = DBUSMENU_MENUITEM_GET_PRIVATE(mi); priv->children = g_list_append(priv->children, child); + g_signal_emit(G_OBJECT(mi), signals[CHILD_ADDED], 0, child, TRUE); return TRUE; } @@ -401,6 +412,7 @@ dbusmenu_menuitem_child_delete (DbusmenuMenuitem * mi, DbusmenuMenuitem * child) DbusmenuMenuitemPrivate * priv = DBUSMENU_MENUITEM_GET_PRIVATE(mi); priv->children = g_list_remove(priv->children, child); + g_signal_emit(G_OBJECT(mi), signals[CHILD_REMOVED], 0, child, TRUE); return TRUE; } @@ -424,6 +436,7 @@ dbusmenu_menuitem_child_add_position (DbusmenuMenuitem * mi, DbusmenuMenuitem * DbusmenuMenuitemPrivate * priv = DBUSMENU_MENUITEM_GET_PRIVATE(mi); priv->children = g_list_insert(priv->children, child, position); + g_signal_emit(G_OBJECT(mi), signals[CHILD_ADDED], 0, child, TRUE); return TRUE; } -- cgit v1.2.3 From d8c84214190fc0630d28a922627e686622b46d35 Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Wed, 13 May 2009 10:45:32 -0500 Subject: Add in a function to search the tree for an ID. This might need to be optimized later, I'm not sure how common this operation will be. --- libdbusmenu-glib/menuitem.c | 46 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 46 insertions(+) (limited to 'libdbusmenu-glib/menuitem.c') diff --git a/libdbusmenu-glib/menuitem.c b/libdbusmenu-glib/menuitem.c index 2563eb2..e017721 100644 --- a/libdbusmenu-glib/menuitem.c +++ b/libdbusmenu-glib/menuitem.c @@ -469,6 +469,52 @@ dbusmenu_menuitem_child_find (DbusmenuMenuitem * mi, guint id) return NULL; } +typedef struct { + DbusmenuMenuitem * mi; + guint id; +} find_id_t; + +/* Basically the heart of the find_id that matches the + API of GFunc. Unfortunately, this goes through all the + children, but it rejects them quickly. */ +static void +find_id_helper (gpointer in_mi, gpointer in_find_id) +{ + DbusmenuMenuitem * mi = (DbusmenuMenuitem *)in_mi; + find_id_t * find_id = (find_id_t *)in_find_id; + + if (find_id->mi != NULL) return; + if (find_id->id == dbusmenu_menuitem_get_id(mi)) { + find_id->mi = mi; + return; + } + + g_list_foreach(dbusmenu_menuitem_get_children(mi), find_id_helper, in_find_id); + return; +} + +/** + dbusmenu_menuitem_find_id: + @mi: #DbusmenuMenuitem at the top of the tree to search + @id: ID of the #DbusmenuMenuitem to search for + + This function searchs the whole tree of children that + are attached to @mi. This could be quite a few nodes, all + the way down the tree. It is a depth first search. + + Return value: The #DbusmenuMenuitem with the ID of @id + or #NULL if there isn't such a menu item in the tree + represented by @mi. +*/ +DbusmenuMenuitem * +dbusmenu_menuitem_find_id (DbusmenuMenuitem * mi, guint id) +{ + g_return_val_if_fail(DBUSMENU_IS_MENUITEM(mi), NULL); + find_id_t find_id = {mi: NULL, id: id}; + find_id_helper(mi, &find_id); + return find_id.mi; +} + /** dbusmenu_menuitem_property_set: @mi: The #DbusmenuMenuitem to set the property on. -- cgit v1.2.3 From b5312e7a0591a734a463d3eb50ff565605f210bf Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Fri, 15 May 2009 14:12:51 -0500 Subject: Adding in a function to get the properties, and make sure to catch soem more warnings and other protections. Also, no more deprecated GTK stuf. --- libdbusmenu-glib/menuitem.c | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) (limited to 'libdbusmenu-glib/menuitem.c') diff --git a/libdbusmenu-glib/menuitem.c b/libdbusmenu-glib/menuitem.c index e017721..6145ba2 100644 --- a/libdbusmenu-glib/menuitem.c +++ b/libdbusmenu-glib/menuitem.c @@ -601,6 +601,26 @@ dbusmenu_menuitem_property_exist (DbusmenuMenuitem * mi, const gchar * property) return value != NULL; } +/** + dbusmenu_menuitem_properties_list: + @mi: #DbusmenuMenuitem to list the properties on + + This functiong gets a list of the names of all the properties + that are set on this menu item. This data on the list is owned + by the menuitem but the list is not and should be freed using + g_list_free() when the calling function is done with it. + + Return value: A list of strings or NULL if there are none. +*/ +GList * +dbusmenu_menuitem_properties_list (DbusmenuMenuitem * mi) +{ + g_return_val_if_fail(DBUSMENU_IS_MENUITEM(mi), NULL); + + DbusmenuMenuitemPrivate * priv = DBUSMENU_MENUITEM_GET_PRIVATE(mi); + return g_hash_table_get_keys(priv->properties); +} + /** dbusmenu_menuitem_buildxml: @mi: #DbusmenuMenuitem to represent in XML @@ -657,6 +677,9 @@ foreach_helper (gpointer data, gpointer user_data) void dbusmenu_menuitem_foreach (DbusmenuMenuitem * mi, void (*func) (DbusmenuMenuitem * mi, gpointer data), gpointer data) { + g_return_if_fail(DBUSMENU_IS_MENUITEM(mi)); + g_return_if_fail(func != NULL); + func(mi, data); GList * children = dbusmenu_menuitem_get_children(mi); foreach_struct_t foreach_data = {func: func, data: data}; @@ -675,6 +698,7 @@ dbusmenu_menuitem_foreach (DbusmenuMenuitem * mi, void (*func) (DbusmenuMenuitem void dbusmenu_menuitem_activate (DbusmenuMenuitem * mi) { + g_return_if_fail(DBUSMENU_IS_MENUITEM(mi)); g_signal_emit(G_OBJECT(mi), signals[ITEM_ACTIVATED], 0, TRUE); return; } -- cgit v1.2.3 From 6faaaaf2a55589832d0c692e13fd8da25cb2dfc9 Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Tue, 19 May 2009 00:14:07 +0200 Subject: A function to copy the properties off of a menuitem. --- libdbusmenu-glib/menuitem.c | 35 +++++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) (limited to 'libdbusmenu-glib/menuitem.c') diff --git a/libdbusmenu-glib/menuitem.c b/libdbusmenu-glib/menuitem.c index 6145ba2..fa848d7 100644 --- a/libdbusmenu-glib/menuitem.c +++ b/libdbusmenu-glib/menuitem.c @@ -621,6 +621,41 @@ dbusmenu_menuitem_properties_list (DbusmenuMenuitem * mi) return g_hash_table_get_keys(priv->properties); } +static void +copy_helper (gpointer in_key, gpointer in_value, gpointer in_data) +{ + GHashTable * table = (GHashTable *)in_data; + g_hash_table_insert(table, in_key, in_value); + return; +} + +/** + dbusmenu_menuitem_properties_copy: + @mi: #DbusmenuMenuitem that we're interested in the properties of + + This function takes the properties of a #DbusmenuMenuitem + and puts them into a #GHashTable that is referenced by the + key of a string and has the value of a string. The hash + table may not have any entries if there aren't any or there + is an error in processing. It is the caller's responsibility + to destroy the created #GHashTable. + + Return value: A brand new #GHashTable that contains all of the + properties that are on this #DbusmenuMenuitem @mi. +*/ +GHashTable * +dbusmenu_menuitem_properties_copy (DbusmenuMenuitem * mi) +{ + GHashTable * ret = g_hash_table_new(g_str_hash, g_str_equal); + + g_return_val_if_fail(DBUSMENU_IS_MENUITEM(mi), ret); + + DbusmenuMenuitemPrivate * priv = DBUSMENU_MENUITEM_GET_PRIVATE(mi); + g_hash_table_foreach(priv->properties, copy_helper, ret); + + return ret; +} + /** dbusmenu_menuitem_buildxml: @mi: #DbusmenuMenuitem to represent in XML -- cgit v1.2.3 From dba873be00f6fec0d70681cb6e97347a96c5d720 Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Tue, 19 May 2009 03:54:28 +0200 Subject: Debug message on setting properties. --- libdbusmenu-glib/menuitem.c | 1 + 1 file changed, 1 insertion(+) (limited to 'libdbusmenu-glib/menuitem.c') diff --git a/libdbusmenu-glib/menuitem.c b/libdbusmenu-glib/menuitem.c index fa848d7..7567023 100644 --- a/libdbusmenu-glib/menuitem.c +++ b/libdbusmenu-glib/menuitem.c @@ -537,6 +537,7 @@ dbusmenu_menuitem_property_set (DbusmenuMenuitem * mi, const gchar * property, c g_return_val_if_fail(property != NULL, FALSE); DbusmenuMenuitemPrivate * priv = DBUSMENU_MENUITEM_GET_PRIVATE(mi); + g_debug("Setting a property. ID: %d Prop: %s Value: %s", priv->id, property, value); gpointer lookup = g_hash_table_lookup(priv->properties, property); if (g_strcmp0((gchar *)lookup, value) == 0) { -- cgit v1.2.3 From 9ce161afed2050ca706912f0308e9f9e842c04c0 Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Tue, 19 May 2009 04:08:59 +0200 Subject: Disabling a large number of debug messages. Most aren't needed anymore. --- libdbusmenu-glib/menuitem.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'libdbusmenu-glib/menuitem.c') diff --git a/libdbusmenu-glib/menuitem.c b/libdbusmenu-glib/menuitem.c index 7567023..9506cad 100644 --- a/libdbusmenu-glib/menuitem.c +++ b/libdbusmenu-glib/menuitem.c @@ -266,7 +266,7 @@ DbusmenuMenuitem * dbusmenu_menuitem_new_with_id (guint id) { DbusmenuMenuitem * mi = g_object_new(DBUSMENU_TYPE_MENUITEM, "id", id, NULL); - g_debug("New Menuitem id %d goal id %d", dbusmenu_menuitem_get_id(mi), id); + /* g_debug("New Menuitem id %d goal id %d", dbusmenu_menuitem_get_id(mi), id); */ return mi; } @@ -537,7 +537,7 @@ dbusmenu_menuitem_property_set (DbusmenuMenuitem * mi, const gchar * property, c g_return_val_if_fail(property != NULL, FALSE); DbusmenuMenuitemPrivate * priv = DBUSMENU_MENUITEM_GET_PRIVATE(mi); - g_debug("Setting a property. ID: %d Prop: %s Value: %s", priv->id, property, value); + /* g_debug("Setting a property. ID: %d Prop: %s Value: %s", priv->id, property, value); */ gpointer lookup = g_hash_table_lookup(priv->properties, property); if (g_strcmp0((gchar *)lookup, value) == 0) { -- cgit v1.2.3