From 960663e01f1bb8a59e20b62892f6945868c510d3 Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Mon, 19 Jul 2010 16:47:40 -0500 Subject: Initial write of group properties, has errors though :( --- libdbusmenu-glib/server.c | 49 +++++++++++++++++++++++++++++++++++++---------- 1 file changed, 39 insertions(+), 10 deletions(-) (limited to 'libdbusmenu-glib/server.c') diff --git a/libdbusmenu-glib/server.c b/libdbusmenu-glib/server.c index 13c2843..42fe61f 100644 --- a/libdbusmenu-glib/server.c +++ b/libdbusmenu-glib/server.c @@ -37,8 +37,8 @@ License version 3 and version 2.1 along with this program. If not, see /* DBus Prototypes */ static gboolean _dbusmenu_server_get_layout (DbusmenuServer * server, gint parent, guint * revision, gchar ** layout, GError ** error); static gboolean _dbusmenu_server_get_property (DbusmenuServer * server, gint id, gchar * property, gchar ** value, GError ** error); -static gboolean _dbusmenu_server_get_properties (DbusmenuServer * server, gint id, GPtrArray * properties, GHashTable ** dict, GError ** error); -static gboolean _dbusmenu_server_get_group_properties (DbusmenuServer * server, GArray * ids, GArray * properties, GHashTable ** values, GError ** error); +static gboolean _dbusmenu_server_get_properties (DbusmenuServer * server, gint id, gchar ** properties, GHashTable ** dict, GError ** error); +static gboolean _dbusmenu_server_get_group_properties (DbusmenuServer * server, GArray * ids, gchar ** properties, GPtrArray ** values, GError ** error); static gboolean _dbusmenu_server_event (DbusmenuServer * server, gint id, gchar * eventid, GValue * data, guint timestamp, GError ** error); static gboolean _dbusmenu_server_get_children (DbusmenuServer * server, gint id, GPtrArray * properties, GPtrArray ** output, GError ** error); static gboolean _dbusmenu_server_about_to_show (DbusmenuServer * server, gint id, gboolean * need_update, GError ** error); @@ -480,7 +480,7 @@ _dbusmenu_server_get_property (DbusmenuServer * server, gint id, gchar * propert } static gboolean -_dbusmenu_server_get_properties (DbusmenuServer * server, gint id, GPtrArray * properties, GHashTable ** dict, GError ** error) +_dbusmenu_server_get_properties (DbusmenuServer * server, gint id, gchar ** properties, GHashTable ** dict, GError ** error) { DbusmenuServerPrivate * priv = DBUSMENU_SERVER_GET_PRIVATE(server); DbusmenuMenuitem * mi = dbusmenu_menuitem_find_id(priv->root, id); @@ -501,16 +501,45 @@ _dbusmenu_server_get_properties (DbusmenuServer * server, gint id, GPtrArray * p return TRUE; } +/* Handles getting a bunch of properties from a variety of menu items + to make one mega dbus message */ static gboolean -_dbusmenu_server_get_group_properties (DbusmenuServer * server, GArray * ids, GArray * properties, GHashTable ** values, GError ** error) +_dbusmenu_server_get_group_properties (DbusmenuServer * server, GArray * ids, gchar ** properties, GPtrArray ** values, GError ** error) { - if (error != NULL) { - g_set_error(error, - error_quark(), - NOT_IMPLEMENTED, - "The GetGroupProperties function is not implemented, sorry."); + /* Build an initial pointer array */ + *values = g_ptr_array_new(); + + /* Go through each ID to get that ID's properties */ + int idcnt; + for (idcnt = 0; idcnt < ids->len; idcnt++) { + GHashTable * idprops = NULL; + GError * error = NULL; + gint id = g_array_index(ids, int, idcnt); + + /* Get the properties for this ID the old fashioned way. */ + if (!_dbusmenu_server_get_properties(server, id, properties, &idprops, &error)) { + g_warning("Error getting the properties from ID %d: %s", id, error->message); + g_error_free(error); + error = NULL; + continue; + } + + GValueArray * valarray = g_value_array_new(2); + + GValue idval = {0}; + g_value_init(&idval, G_TYPE_INT); + g_value_set_int(&idval, id); + g_value_array_append(valarray, &idval); + + GValue propval = {0}; + g_value_init(&propval, G_TYPE_HASH_TABLE); + g_value_set_boxed(&propval, idprops); + g_value_array_append(valarray, &propval); + + g_ptr_array_add(*values, valarray); } - return FALSE; + + return TRUE; } static void -- cgit v1.2.3 From 68e46ae11fda7dc9e9a7eada5b105536bdf9f574 Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Mon, 19 Jul 2010 20:42:36 -0500 Subject: Apparently it's a GValueArray. Feel like I'm coding freakin' Python. Guess and check. --- libdbusmenu-glib/server.c | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) (limited to 'libdbusmenu-glib/server.c') diff --git a/libdbusmenu-glib/server.c b/libdbusmenu-glib/server.c index 42fe61f..dc505a1 100644 --- a/libdbusmenu-glib/server.c +++ b/libdbusmenu-glib/server.c @@ -38,7 +38,7 @@ License version 3 and version 2.1 along with this program. If not, see static gboolean _dbusmenu_server_get_layout (DbusmenuServer * server, gint parent, guint * revision, gchar ** layout, GError ** error); static gboolean _dbusmenu_server_get_property (DbusmenuServer * server, gint id, gchar * property, gchar ** value, GError ** error); static gboolean _dbusmenu_server_get_properties (DbusmenuServer * server, gint id, gchar ** properties, GHashTable ** dict, GError ** error); -static gboolean _dbusmenu_server_get_group_properties (DbusmenuServer * server, GArray * ids, gchar ** properties, GPtrArray ** values, GError ** error); +static gboolean _dbusmenu_server_get_group_properties (DbusmenuServer * server, GArray * ids, gchar ** properties, GValueArray ** values, GError ** error); static gboolean _dbusmenu_server_event (DbusmenuServer * server, gint id, gchar * eventid, GValue * data, guint timestamp, GError ** error); static gboolean _dbusmenu_server_get_children (DbusmenuServer * server, gint id, GPtrArray * properties, GPtrArray ** output, GError ** error); static gboolean _dbusmenu_server_about_to_show (DbusmenuServer * server, gint id, gboolean * need_update, GError ** error); @@ -504,10 +504,10 @@ _dbusmenu_server_get_properties (DbusmenuServer * server, gint id, gchar ** prop /* Handles getting a bunch of properties from a variety of menu items to make one mega dbus message */ static gboolean -_dbusmenu_server_get_group_properties (DbusmenuServer * server, GArray * ids, gchar ** properties, GPtrArray ** values, GError ** error) +_dbusmenu_server_get_group_properties (DbusmenuServer * server, GArray * ids, gchar ** properties, GValueArray ** values, GError ** error) { /* Build an initial pointer array */ - *values = g_ptr_array_new(); + *values = g_value_array_new(ids->len); /* Go through each ID to get that ID's properties */ int idcnt; @@ -536,7 +536,11 @@ _dbusmenu_server_get_group_properties (DbusmenuServer * server, GArray * ids, gc g_value_set_boxed(&propval, idprops); g_value_array_append(valarray, &propval); - g_ptr_array_add(*values, valarray); + GValue * valwrapper = g_new0(GValue, 1); + g_value_init(valwrapper, G_TYPE_VALUE_ARRAY); + g_value_set_boxed(valwrapper, valarray); + + g_value_array_append(*values, valwrapper); } return TRUE; -- cgit v1.2.3 From 63601bed2c1bb3ffb786efa6c25e47fa97c0acb0 Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Mon, 19 Jul 2010 21:19:19 -0500 Subject: Switch array back and use the helpers, duh, now it works. --- libdbusmenu-glib/server.c | 32 ++++++++++++++------------------ 1 file changed, 14 insertions(+), 18 deletions(-) (limited to 'libdbusmenu-glib/server.c') diff --git a/libdbusmenu-glib/server.c b/libdbusmenu-glib/server.c index dc505a1..08a6631 100644 --- a/libdbusmenu-glib/server.c +++ b/libdbusmenu-glib/server.c @@ -38,10 +38,13 @@ License version 3 and version 2.1 along with this program. If not, see static gboolean _dbusmenu_server_get_layout (DbusmenuServer * server, gint parent, guint * revision, gchar ** layout, GError ** error); static gboolean _dbusmenu_server_get_property (DbusmenuServer * server, gint id, gchar * property, gchar ** value, GError ** error); static gboolean _dbusmenu_server_get_properties (DbusmenuServer * server, gint id, gchar ** properties, GHashTable ** dict, GError ** error); -static gboolean _dbusmenu_server_get_group_properties (DbusmenuServer * server, GArray * ids, gchar ** properties, GValueArray ** values, GError ** error); +static gboolean _dbusmenu_server_get_group_properties (DbusmenuServer * server, GArray * ids, gchar ** properties, GPtrArray ** values, GError ** error); static gboolean _dbusmenu_server_event (DbusmenuServer * server, gint id, gchar * eventid, GValue * data, guint timestamp, GError ** error); static gboolean _dbusmenu_server_get_children (DbusmenuServer * server, gint id, GPtrArray * properties, GPtrArray ** output, GError ** error); static gboolean _dbusmenu_server_about_to_show (DbusmenuServer * server, gint id, gboolean * need_update, GError ** error); +/* DBus Helpers */ +static void _gvalue_array_append_int(GValueArray *array, gint i); +static void _gvalue_array_append_hashtable(GValueArray *array, GHashTable * dict); #include "dbusmenu-server.h" @@ -504,10 +507,10 @@ _dbusmenu_server_get_properties (DbusmenuServer * server, gint id, gchar ** prop /* Handles getting a bunch of properties from a variety of menu items to make one mega dbus message */ static gboolean -_dbusmenu_server_get_group_properties (DbusmenuServer * server, GArray * ids, gchar ** properties, GValueArray ** values, GError ** error) +_dbusmenu_server_get_group_properties (DbusmenuServer * server, GArray * ids, gchar ** properties, GPtrArray ** values, GError ** error) { /* Build an initial pointer array */ - *values = g_value_array_new(ids->len); + *values = g_ptr_array_new(); /* Go through each ID to get that ID's properties */ int idcnt; @@ -526,26 +529,17 @@ _dbusmenu_server_get_group_properties (DbusmenuServer * server, GArray * ids, gc GValueArray * valarray = g_value_array_new(2); - GValue idval = {0}; - g_value_init(&idval, G_TYPE_INT); - g_value_set_int(&idval, id); - g_value_array_append(valarray, &idval); + _gvalue_array_append_int(valarray, id); + _gvalue_array_append_hashtable(valarray, idprops); - GValue propval = {0}; - g_value_init(&propval, G_TYPE_HASH_TABLE); - g_value_set_boxed(&propval, idprops); - g_value_array_append(valarray, &propval); - - GValue * valwrapper = g_new0(GValue, 1); - g_value_init(valwrapper, G_TYPE_VALUE_ARRAY); - g_value_set_boxed(valwrapper, valarray); - - g_value_array_append(*values, valwrapper); + g_ptr_array_add(*values, valarray); } return TRUE; } +/* Allocate a value on the stack for the int and append + it to the array. */ static void _gvalue_array_append_int(GValueArray *array, gint i) { @@ -557,6 +551,8 @@ _gvalue_array_append_int(GValueArray *array, gint i) g_value_unset(&value); } +/* Allocate a value on the stack for the hashtable and append + it to the array. */ static void _gvalue_array_append_hashtable(GValueArray *array, GHashTable * dict) { @@ -577,7 +573,7 @@ serialize_menuitem(gpointer data, gpointer user_data) gint id = dbusmenu_menuitem_get_id(mi); GHashTable * dict = dbusmenu_menuitem_properties_copy(mi); - GValueArray * item = g_value_array_new(1); + GValueArray * item = g_value_array_new(2); _gvalue_array_append_int(item, id); _gvalue_array_append_hashtable(item, dict); -- cgit v1.2.3 From 8c9e1febb85e0bd28cfc175cd015a4a1934baf55 Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Tue, 20 Jul 2010 12:13:18 -0500 Subject: Pulling the layout count update into a function along with signalling it. --- libdbusmenu-glib/server.c | 29 ++++++++++++++++------------- 1 file changed, 16 insertions(+), 13 deletions(-) (limited to 'libdbusmenu-glib/server.c') diff --git a/libdbusmenu-glib/server.c b/libdbusmenu-glib/server.c index 08a6631..7a39f1e 100644 --- a/libdbusmenu-glib/server.c +++ b/libdbusmenu-glib/server.c @@ -48,6 +48,8 @@ static void _gvalue_array_append_hashtable(GValueArray *array, GHashTable * dict #include "dbusmenu-server.h" +static void layout_update_signal (DbusmenuServer * server); + #define DBUSMENU_VERSION_NUMBER 2 /* Privates, I'll show you mine... */ @@ -260,8 +262,7 @@ set_property (GObject * obj, guint id, const GValue * value, GParamSpec * pspec) } else { g_debug("Setting root node to NULL"); } - priv->layout_revision++; - g_signal_emit(obj, signals[LAYOUT_UPDATED], 0, priv->layout_revision, 0, TRUE); + layout_update_signal(DBUSMENU_SERVER(obj)); break; default: g_return_if_reached(); @@ -305,6 +306,16 @@ get_property (GObject * obj, guint id, GValue * value, GParamSpec * pspec) return; } +/* Signals that the layout has been updated */ +static void +layout_update_signal (DbusmenuServer * server) +{ + DbusmenuServerPrivate * priv = DBUSMENU_SERVER_GET_PRIVATE(server); + priv->layout_revision++; + g_signal_emit(G_OBJECT(server), signals[LAYOUT_UPDATED], 0, priv->layout_revision, 0, TRUE); + return; +} + static void menuitem_property_changed (DbusmenuMenuitem * mi, gchar * property, GValue * value, DbusmenuServer * server) { @@ -335,10 +346,7 @@ menuitem_child_added (DbusmenuMenuitem * parent, DbusmenuMenuitem * child, guint menuitem_signals_create(child, server); g_list_foreach(dbusmenu_menuitem_get_children(child), added_check_children, server); - /* TODO: We probably need to group the layout update signals to make the number more reasonble. */ - DbusmenuServerPrivate * priv = DBUSMENU_SERVER_GET_PRIVATE(server); - priv->layout_revision++; - g_signal_emit(G_OBJECT(server), signals[LAYOUT_UPDATED], 0, priv->layout_revision, 0, TRUE); + layout_update_signal(server); return; } @@ -346,19 +354,14 @@ static void menuitem_child_removed (DbusmenuMenuitem * parent, DbusmenuMenuitem * child, DbusmenuServer * server) { menuitem_signals_remove(child, server); - /* TODO: We probably need to group the layout update signals to make the number more reasonble. */ - DbusmenuServerPrivate * priv = DBUSMENU_SERVER_GET_PRIVATE(server); - priv->layout_revision++; - g_signal_emit(G_OBJECT(server), signals[LAYOUT_UPDATED], 0, priv->layout_revision, 0, TRUE); + layout_update_signal(server); return; } static void menuitem_child_moved (DbusmenuMenuitem * parent, DbusmenuMenuitem * child, guint newpos, guint oldpos, DbusmenuServer * server) { - DbusmenuServerPrivate * priv = DBUSMENU_SERVER_GET_PRIVATE(server); - priv->layout_revision++; - g_signal_emit(G_OBJECT(server), signals[LAYOUT_UPDATED], 0, priv->layout_revision, 0, TRUE); + layout_update_signal(server); return; } -- cgit v1.2.3 From fe213d96ed2ff025c1c60cbffb4e0dd562d1c154 Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Tue, 20 Jul 2010 12:27:03 -0500 Subject: Adding in an idle function that queues the updates. --- libdbusmenu-glib/server.c | 27 ++++++++++++++++++++++++++- 1 file changed, 26 insertions(+), 1 deletion(-) (limited to 'libdbusmenu-glib/server.c') diff --git a/libdbusmenu-glib/server.c b/libdbusmenu-glib/server.c index 7a39f1e..4afd0c2 100644 --- a/libdbusmenu-glib/server.c +++ b/libdbusmenu-glib/server.c @@ -60,6 +60,7 @@ struct _DbusmenuServerPrivate DbusmenuMenuitem * root; gchar * dbusobject; gint layout_revision; + guint layout_idle; }; #define DBUSMENU_SERVER_GET_PRIVATE(o) \ @@ -201,6 +202,7 @@ dbusmenu_server_init (DbusmenuServer *self) priv->root = NULL; priv->dbusobject = NULL; priv->layout_revision = 1; + priv->layout_idle = 0; return; } @@ -210,6 +212,10 @@ dbusmenu_server_dispose (GObject *object) { DbusmenuServerPrivate * priv = DBUSMENU_SERVER_GET_PRIVATE(object); + if (priv->layout_idle != 0) { + g_source_remove(priv->layout_idle); + } + if (priv->root != NULL) { dbusmenu_menuitem_foreach(priv->root, menuitem_signals_remove, object); g_object_unref(priv->root); @@ -306,13 +312,32 @@ get_property (GObject * obj, guint id, GValue * value, GParamSpec * pspec) return; } +/* Handle actually signalling in the idle loop. This way we collect all + the updates. */ +static gboolean +layout_update_idle (gpointer user_data) +{ + DbusmenuServer * server = DBUSMENU_SERVER(user_data); + DbusmenuServerPrivate * priv = DBUSMENU_SERVER_GET_PRIVATE(server); + + g_signal_emit(G_OBJECT(server), signals[LAYOUT_UPDATED], 0, priv->layout_revision, 0, TRUE); + + priv->layout_idle = 0; + + return FALSE; +} + /* Signals that the layout has been updated */ static void layout_update_signal (DbusmenuServer * server) { DbusmenuServerPrivate * priv = DBUSMENU_SERVER_GET_PRIVATE(server); priv->layout_revision++; - g_signal_emit(G_OBJECT(server), signals[LAYOUT_UPDATED], 0, priv->layout_revision, 0, TRUE); + + if (priv->layout_idle == 0) { + priv->layout_idle = g_idle_add(layout_update_idle, server); + } + return; } -- cgit v1.2.3