From aec55f7fae016a6d25f675a02ff42c981ec80c04 Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Thu, 21 Jan 2010 15:57:18 -0600 Subject: Set the node ID to zero if the node is the root node. --- libdbusmenu-glib/menuitem.c | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) (limited to 'libdbusmenu-glib/menuitem.c') diff --git a/libdbusmenu-glib/menuitem.c b/libdbusmenu-glib/menuitem.c index a03117c..3e06719 100644 --- a/libdbusmenu-glib/menuitem.c +++ b/libdbusmenu-glib/menuitem.c @@ -1060,12 +1060,17 @@ dbusmenu_menuitem_buildxml (DbusmenuMenuitem * mi, GPtrArray * array, gint revis { g_return_if_fail(DBUSMENU_IS_MENUITEM(mi)); + guint id = 0; + if (!dbusmenu_menuitem_get_root(mi)) { + id = dbusmenu_menuitem_get_id(mi); + } + GList * children = dbusmenu_menuitem_get_children(mi); /* TODO: Only put revision info in the root node. Save some bandwidth. */ if (children == NULL) { - g_ptr_array_add(array, g_strdup_printf("", dbusmenu_menuitem_get_id(mi), revision)); + g_ptr_array_add(array, g_strdup_printf("", id, revision)); } else { - g_ptr_array_add(array, g_strdup_printf("", dbusmenu_menuitem_get_id(mi), revision)); + g_ptr_array_add(array, g_strdup_printf("", id, revision)); for ( ; children != NULL; children = children->next) { dbusmenu_menuitem_buildxml(DBUSMENU_MENUITEM(children->data), array, revision); } -- cgit v1.2.3 From 4dea36b65076939e4f556a0f5e9d5c81c1553eb2 Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Thu, 21 Jan 2010 17:13:52 -0600 Subject: Removing the revision from the generated XML --- libdbusmenu-glib/menuitem.c | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) (limited to 'libdbusmenu-glib/menuitem.c') diff --git a/libdbusmenu-glib/menuitem.c b/libdbusmenu-glib/menuitem.c index 3e06719..0dcbade 100644 --- a/libdbusmenu-glib/menuitem.c +++ b/libdbusmenu-glib/menuitem.c @@ -1047,7 +1047,6 @@ dbusmenu_menuitem_get_root (DbusmenuMenuitem * mi) dbusmenu_menuitem_buildxml: @mi: #DbusmenuMenuitem to represent in XML @array: A list of string that will be turned into an XML file - @revision: The revision of the layout to embed in the XML This function will add strings to the array @array. It will put at least one entry if this menu item has no children. If it has @@ -1056,7 +1055,7 @@ dbusmenu_menuitem_get_root (DbusmenuMenuitem * mi) children to place their own tags in the array in between those two. */ void -dbusmenu_menuitem_buildxml (DbusmenuMenuitem * mi, GPtrArray * array, gint revision) +dbusmenu_menuitem_buildxml (DbusmenuMenuitem * mi, GPtrArray * array) { g_return_if_fail(DBUSMENU_IS_MENUITEM(mi)); @@ -1066,13 +1065,12 @@ dbusmenu_menuitem_buildxml (DbusmenuMenuitem * mi, GPtrArray * array, gint revis } GList * children = dbusmenu_menuitem_get_children(mi); - /* TODO: Only put revision info in the root node. Save some bandwidth. */ if (children == NULL) { - g_ptr_array_add(array, g_strdup_printf("", id, revision)); + g_ptr_array_add(array, g_strdup_printf("", id)); } else { - g_ptr_array_add(array, g_strdup_printf("", id, revision)); + g_ptr_array_add(array, g_strdup_printf("", id)); for ( ; children != NULL; children = children->next) { - dbusmenu_menuitem_buildxml(DBUSMENU_MENUITEM(children->data), array, revision); + dbusmenu_menuitem_buildxml(DBUSMENU_MENUITEM(children->data), array); } g_ptr_array_add(array, g_strdup("")); } -- cgit v1.2.3 From cdb85e85b88c090c3cd34e8bd412458e919464cf Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Fri, 22 Jan 2010 14:10:27 -0600 Subject: Changing the menuitem interface to have activate include a timestamp --- libdbusmenu-glib/menuitem.c | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) (limited to 'libdbusmenu-glib/menuitem.c') diff --git a/libdbusmenu-glib/menuitem.c b/libdbusmenu-glib/menuitem.c index a03117c..e50b2d8 100644 --- a/libdbusmenu-glib/menuitem.c +++ b/libdbusmenu-glib/menuitem.c @@ -127,6 +127,7 @@ dbusmenu_menuitem_class_init (DbusmenuMenuitemClass *klass) /** DbusmenuMenuitem::item-activated: @arg0: The #DbusmenuMenuitem object. + @arg1: The timestamp of when it was activated Emitted on the objects on the server side when they are signaled on the client side. @@ -136,8 +137,8 @@ dbusmenu_menuitem_class_init (DbusmenuMenuitemClass *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); + _dbusmenu_menuitem_marshal_VOID__UINT, + G_TYPE_NONE, 1, G_TYPE_UINT, G_TYPE_NONE); /** DbusmenuMenuitem::child-added: @arg0: The #DbusmenuMenuitem which is the parent. @@ -1114,18 +1115,19 @@ dbusmenu_menuitem_foreach (DbusmenuMenuitem * mi, void (*func) (DbusmenuMenuitem /** dbusmenu_menuitem_activate: @mi: The #DbusmenuMenuitem to send the signal on. + @timestamp: The timestamp of when the event happened 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) +dbusmenu_menuitem_activate (DbusmenuMenuitem * mi, guint timestamp) { g_return_if_fail(DBUSMENU_IS_MENUITEM(mi)); #ifdef MASSIVEDEBUGGING g_debug("Menuitem %d (%s) activated", ID(mi), LABEL(mi)); #endif - g_signal_emit(G_OBJECT(mi), signals[ITEM_ACTIVATED], 0, TRUE); + g_signal_emit(G_OBJECT(mi), signals[ITEM_ACTIVATED], 0, timestamp, TRUE); return; } -- cgit v1.2.3 From 1604731c2d68d1a56a4ab87d08ee1867a25eb25a Mon Sep 17 00:00:00 2001 From: Aurelien Gateau Date: Tue, 2 Feb 2010 16:32:49 -0800 Subject: Turn id into an int --- libdbusmenu-glib/menuitem.c | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) (limited to 'libdbusmenu-glib/menuitem.c') diff --git a/libdbusmenu-glib/menuitem.c b/libdbusmenu-glib/menuitem.c index 06d6200..08cc27b 100644 --- a/libdbusmenu-glib/menuitem.c +++ b/libdbusmenu-glib/menuitem.c @@ -55,7 +55,7 @@ License version 3 and version 2.1 along with this program. If not, see typedef struct _DbusmenuMenuitemPrivate DbusmenuMenuitemPrivate; struct _DbusmenuMenuitemPrivate { - guint id; + gint id; GList * children; GHashTable * properties; gboolean root; @@ -367,7 +367,7 @@ dbusmenu_menuitem_new (void) Return value: A newly allocated #DbusmenuMenuitem. */ DbusmenuMenuitem * -dbusmenu_menuitem_new_with_id (guint id) +dbusmenu_menuitem_new_with_id (gint 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); */ @@ -642,7 +642,7 @@ dbusmenu_menuitem_child_reorder(DbusmenuMenuitem * mi, DbusmenuMenuitem * child, can't be found. */ DbusmenuMenuitem * -dbusmenu_menuitem_child_find (DbusmenuMenuitem * mi, guint id) +dbusmenu_menuitem_child_find (DbusmenuMenuitem * mi, gint id) { g_return_val_if_fail(DBUSMENU_IS_MENUITEM(mi), NULL); @@ -661,7 +661,7 @@ dbusmenu_menuitem_child_find (DbusmenuMenuitem * mi, guint id) typedef struct { DbusmenuMenuitem * mi; - guint id; + gint id; } find_id_t; /* Basically the heart of the find_id that matches the @@ -697,7 +697,7 @@ find_id_helper (gpointer in_mi, gpointer in_find_id) represented by @mi. */ DbusmenuMenuitem * -dbusmenu_menuitem_find_id (DbusmenuMenuitem * mi, guint id) +dbusmenu_menuitem_find_id (DbusmenuMenuitem * mi, gint id) { g_return_val_if_fail(DBUSMENU_IS_MENUITEM(mi), NULL); find_id_t find_id = {mi: NULL, id: id}; @@ -1060,7 +1060,7 @@ dbusmenu_menuitem_buildxml (DbusmenuMenuitem * mi, GPtrArray * array) { g_return_if_fail(DBUSMENU_IS_MENUITEM(mi)); - guint id = 0; + gint id = 0; if (!dbusmenu_menuitem_get_root(mi)) { id = dbusmenu_menuitem_get_id(mi); } -- cgit v1.2.3 From 96512c9c06438eb32d8af0e29229f84455fffc64 Mon Sep 17 00:00:00 2001 From: Aurelien Gateau Date: Tue, 2 Feb 2010 19:02:34 -0800 Subject: - Allow id to be 0. - Fix default item type. --- libdbusmenu-glib/menuitem.c | 15 ++++++--------- 1 file changed, 6 insertions(+), 9 deletions(-) (limited to 'libdbusmenu-glib/menuitem.c') diff --git a/libdbusmenu-glib/menuitem.c b/libdbusmenu-glib/menuitem.c index 08cc27b..7e1e1ac 100644 --- a/libdbusmenu-glib/menuitem.c +++ b/libdbusmenu-glib/menuitem.c @@ -207,7 +207,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_uint("id", "ID for the menu item", + g_param_spec_int("id", "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)); @@ -246,7 +246,7 @@ g_value_transform_STRING_INT (const GValue * in, GValue * out) return; } -static guint menuitem_next_id = 1; +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. */ @@ -315,9 +315,9 @@ set_property (GObject * obj, guint id, const GValue * value, GParamSpec * pspec) switch (id) { case PROP_ID: - priv->id = g_value_get_uint(value); + priv->id = g_value_get_int(value); if (priv->id > menuitem_next_id) { - menuitem_next_id = priv->id; + menuitem_next_id = priv->id + 1; } break; } @@ -332,10 +332,7 @@ get_property (GObject * obj, guint id, GValue * value, GParamSpec * pspec) switch (id) { case PROP_ID: - if (priv->id == 0) { - priv->id = menuitem_next_id++; - } - g_value_set_uint(value, priv->id); + g_value_set_int(value, priv->id); break; } @@ -355,7 +352,7 @@ get_property (GObject * obj, guint id, GValue * value, GParamSpec * pspec) DbusmenuMenuitem * dbusmenu_menuitem_new (void) { - return g_object_new(DBUSMENU_TYPE_MENUITEM, NULL); + return g_object_new(DBUSMENU_TYPE_MENUITEM, "id", menuitem_next_id++, NULL); } /** -- cgit v1.2.3 From f62b7b881e204847691a409f81714626f6806df4 Mon Sep 17 00:00:00 2001 From: Aurelien Gateau Date: Tue, 2 Feb 2010 19:07:19 -0800 Subject: Root id should be 0 --- libdbusmenu-glib/menuitem.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'libdbusmenu-glib/menuitem.c') diff --git a/libdbusmenu-glib/menuitem.c b/libdbusmenu-glib/menuitem.c index 7e1e1ac..8198929 100644 --- a/libdbusmenu-glib/menuitem.c +++ b/libdbusmenu-glib/menuitem.c @@ -246,7 +246,7 @@ g_value_transform_STRING_INT (const GValue * in, GValue * out) return; } -static gint menuitem_next_id = 1; +static gint menuitem_next_id = 0; /* 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 48d1f0b6902b4833460c6562603d6a8c9555aad5 Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Wed, 3 Feb 2010 17:31:17 -0800 Subject: Creating a handle event function and a wrapper for it. --- libdbusmenu-glib/menuitem.c | 23 +++++++++++++++++++---- 1 file changed, 19 insertions(+), 4 deletions(-) (limited to 'libdbusmenu-glib/menuitem.c') diff --git a/libdbusmenu-glib/menuitem.c b/libdbusmenu-glib/menuitem.c index 06d6200..bc2e748 100644 --- a/libdbusmenu-glib/menuitem.c +++ b/libdbusmenu-glib/menuitem.c @@ -1116,21 +1116,36 @@ dbusmenu_menuitem_foreach (DbusmenuMenuitem * mi, void (*func) (DbusmenuMenuitem } /** - dbusmenu_menuitem_activate: + dbusmenu_menuitem_handle_event: @mi: The #DbusmenuMenuitem to send the signal on. + @name: The name of the signal + @value: A value that could be set for the event @timestamp: The timestamp of when the event happened + This function is called to create an event. It is likely + to be overrided by subclasses. The default menu item + will respond to the activate signal and do: + Emits the #DbusmenuMenuitem::item-activate signal on this menu item. Called by server objects when they get the appropriate DBus signals from the client. + + If you subclass this function you should really think + about calling the parent function unless you have a good + reason not to. */ void -dbusmenu_menuitem_activate (DbusmenuMenuitem * mi, guint timestamp) +dbusmenu_menuitem_handle_event (DbusmenuMenuitem * mi, const gchar * name, const GValue * value, guint timestamp) { g_return_if_fail(DBUSMENU_IS_MENUITEM(mi)); #ifdef MASSIVEDEBUGGING - g_debug("Menuitem %d (%s) activated", ID(mi), LABEL(mi)); + g_debug("Menuitem %d (%s) is getting event '%s'", ID(mi), LABEL(mi), name); #endif - g_signal_emit(G_OBJECT(mi), signals[ITEM_ACTIVATED], 0, timestamp, TRUE); + DbusmenuMenuitemClass * class = DBUSMENU_MENUITEM_GET_CLASS(mi); + + if (class->handle_event != NULL) { + return class->handle_event(mi, name, value, timestamp); + } + //g_signal_emit(G_OBJECT(mi), signals[ITEM_ACTIVATED], 0, timestamp, TRUE); return; } -- cgit v1.2.3 From eed846366d326c8f42ecb323abdb0794fae6f85e Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Wed, 3 Feb 2010 17:36:50 -0800 Subject: Creating the local default for event handling --- libdbusmenu-glib/menuitem.c | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) (limited to 'libdbusmenu-glib/menuitem.c') diff --git a/libdbusmenu-glib/menuitem.c b/libdbusmenu-glib/menuitem.c index bc2e748..90abb9d 100644 --- a/libdbusmenu-glib/menuitem.c +++ b/libdbusmenu-glib/menuitem.c @@ -92,6 +92,7 @@ static void set_property (GObject * obj, guint id, const GValue * value, GParamS static void get_property (GObject * obj, guint id, GValue * value, GParamSpec * pspec); static void g_value_transform_STRING_BOOLEAN (const GValue * in, GValue * out); static void g_value_transform_STRING_INT (const GValue * in, GValue * out); +static void handle_event (DbusmenuMenuitem * mi, const gchar * name, const GValue * value, guint timestamp); /* GObject stuff */ G_DEFINE_TYPE (DbusmenuMenuitem, dbusmenu_menuitem, G_TYPE_OBJECT); @@ -108,6 +109,8 @@ dbusmenu_menuitem_class_init (DbusmenuMenuitemClass *klass) object_class->set_property = set_property; object_class->get_property = get_property; + klass->handle_event = handle_event; + /** DbusmenuMenuitem::property-changed: @arg0: The #DbusmenuMenuitem object. @@ -342,6 +345,16 @@ get_property (GObject * obj, guint id, GValue * value, GParamSpec * pspec) return; } +/* Handles the activate event if it is sent. */ +static void +handle_event (DbusmenuMenuitem * mi, const gchar * name, const GValue * value, guint timestamp) +{ + if (g_strcmp0(name, "clicked") == 0) { + g_signal_emit(G_OBJECT(mi), signals[ITEM_ACTIVATED], 0, timestamp, TRUE); + } + + return; +} /* Public interface */ @@ -1146,6 +1159,5 @@ dbusmenu_menuitem_handle_event (DbusmenuMenuitem * mi, const gchar * name, const if (class->handle_event != NULL) { return class->handle_event(mi, name, value, timestamp); } - //g_signal_emit(G_OBJECT(mi), signals[ITEM_ACTIVATED], 0, timestamp, TRUE); return; } -- cgit v1.2.3