From 76cb1c3fd2545f1e7bcec62f788335fb6232178f Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Thu, 20 Aug 2009 10:35:20 -0500 Subject: AM 1.11 silence --- configure.ac | 2 ++ 1 file changed, 2 insertions(+) diff --git a/configure.ac b/configure.ac index 6a5ed9a..d259bef 100644 --- a/configure.ac +++ b/configure.ac @@ -19,6 +19,8 @@ AC_PROG_LIBTOOL AC_SUBST(VERSION) AC_CONFIG_MACRO_DIR([m4]) +m4_ifdef([AM_SILENT_RULES],[AM_SILENT_RULES([yes])]) + ########################### # Dependencies - GLib ########################### -- cgit v1.2.3 From 236ddb030b31aa78842c81fef0cd107a6b615124 Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Thu, 20 Aug 2009 12:54:53 -0500 Subject: Switching the new signal to be after the properties are gotten and adding a hashtable for type handlers. --- libdbusmenu-glib/client.c | 34 ++++++++++++++++++++++++++++++++-- libdbusmenu-glib/client.h | 12 +++++++++--- 2 files changed, 41 insertions(+), 5 deletions(-) diff --git a/libdbusmenu-glib/client.c b/libdbusmenu-glib/client.c index 212071b..9eb8b55 100644 --- a/libdbusmenu-glib/client.c +++ b/libdbusmenu-glib/client.c @@ -68,6 +68,8 @@ struct _DbusmenuClientPrivate DBusGProxyCall * layoutcall; DBusGProxy * dbusproxy; + + GHashTable * type_handlers; }; #define DBUSMENU_CLIENT_GET_PRIVATE(o) \ @@ -187,6 +189,9 @@ dbusmenu_client_init (DbusmenuClient *self) priv->dbusproxy = NULL; + priv->type_handlers = g_hash_table_new_full(g_str_hash, g_str_equal, + g_free, NULL); + return; } @@ -230,6 +235,10 @@ dbusmenu_client_finalize (GObject *object) g_free(priv->dbus_name); g_free(priv->dbus_object); + if (priv->type_handlers != NULL) { + g_hash_table_destroy(priv->type_handlers); + } + G_OBJECT_CLASS (dbusmenu_client_parent_class)->finalize (object); return; } @@ -515,6 +524,22 @@ menuitem_get_properties_cb (DBusGProxy * proxy, GHashTable * properties, GError 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 +menuitem_get_properties_new_cb (DBusGProxy * proxy, GHashTable * properties, GError * error, gpointer data) +{ + gpointer * unpackarray = (gpointer *)data; + + menuitem_get_properties_cb (proxy, properties, error, unpackarray[1]); + + g_signal_emit(G_OBJECT(unpackarray[0]), signals[NEW_MENUITEM], 0, unpackarray[1], TRUE); + + g_free(unpackarray); + + return; +} + static void menuitem_call_cb (DBusGProxy * proxy, GError * error, gpointer userdata) { @@ -562,9 +587,14 @@ parse_layout_xml(DbusmenuClient * client, xmlNodePtr node, DbusmenuMenuitem * it dbusmenu_menuitem_set_root(item, TRUE); } g_signal_connect(G_OBJECT(item), DBUSMENU_MENUITEM_SIGNAL_ITEM_ACTIVATED, G_CALLBACK(menuitem_activate), client); - g_signal_emit(G_OBJECT(client), signals[NEW_MENUITEM], 0, item, TRUE); + /* Get the properties queued up for this item */ - org_freedesktop_dbusmenu_get_properties_async(proxy, id, menuitem_get_properties_cb, item); + /* Not happy about this, but I need both of these :( */ + gpointer * packarray = g_new0(gpointer, 2); + packarray[0] = client; + packarray[1] = item; + + org_freedesktop_dbusmenu_get_properties_async(proxy, id, menuitem_get_properties_new_cb, packarray); } xmlNodePtr children; diff --git a/libdbusmenu-glib/client.h b/libdbusmenu-glib/client.h index 35f7122..20156d8 100644 --- a/libdbusmenu-glib/client.h +++ b/libdbusmenu-glib/client.h @@ -90,9 +90,15 @@ struct _DbusmenuClient { GObject parent; }; -GType dbusmenu_client_get_type (void); -DbusmenuClient * dbusmenu_client_new (const gchar * name, const gchar * object); -DbusmenuMenuitem * dbusmenu_client_get_root (DbusmenuClient * client); +typedef void (*DbusmenuClientTypeHandler) (DbusmenuMenuitem * newitem, DbusmenuMenuitem * parent); + +GType dbusmenu_client_get_type (void); +DbusmenuClient * dbusmenu_client_new (const gchar * name, + const gchar * object); +DbusmenuMenuitem * dbusmenu_client_get_root (DbusmenuClient * client); +gboolean dbusmenu_client_add_type_handler (DbusmenuClient * client, + const gchar * type, + DbusmenuClientTypeHandler newfunc); /** SECTION:client -- cgit v1.2.3 From 5583309ea061bc9a384d15b79193d8240e5f46a1 Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Thu, 20 Aug 2009 12:55:36 -0500 Subject: Seems intltool changed slightly --- po/Makefile.in.in | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/po/Makefile.in.in b/po/Makefile.in.in index c7e8302..402a25f 100644 --- a/po/Makefile.in.in +++ b/po/Makefile.in.in @@ -56,7 +56,7 @@ ALL_LINGUAS = @ALL_LINGUAS@ PO_LINGUAS=$(shell if test -r $(srcdir)/LINGUAS; then grep -v "^\#" $(srcdir)/LINGUAS; else echo "$(ALL_LINGUAS)"; fi) -USER_LINGUAS=$(shell if test -n "$(LINGUAS)"; then LLINGUAS="$(LINGUAS)"; ALINGUAS="$(ALL_LINGUAS)"; for lang in $$LLINGUAS; do if test -n "`grep '^$$lang$$' $(srcdir)/LINGUAS 2>/dev/null`" -o -n "`echo $$ALINGUAS|tr ' ' '\n'|grep '^$$lang$$'`"; then printf "$$lang "; fi; done; fi) +USER_LINGUAS=$(shell if test -n "$(LINGUAS)"; then LLINGUAS="$(LINGUAS)"; ALINGUAS="$(ALL_LINGUAS)"; for lang in $$LLINGUAS; do if test -n "`grep \^$$lang$$ $(srcdir)/LINGUAS 2>/dev/null`" -o -n "`echo $$ALINGUAS|tr ' ' '\n'|grep \^$$lang$$`"; then printf "$$lang "; fi; done; fi) USE_LINGUAS=$(shell if test -n "$(USER_LINGUAS)" -o -n "$(LINGUAS)"; then LLINGUAS="$(USER_LINGUAS)"; else if test -n "$(PO_LINGUAS)"; then LLINGUAS="$(PO_LINGUAS)"; else LLINGUAS="$(ALL_LINGUAS)"; fi; fi; for lang in $$LLINGUAS; do printf "$$lang "; done) -- cgit v1.2.3 From 69fe6b5ac33dfd64163d5b41f9a0719b23912e40 Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Thu, 20 Aug 2009 13:05:24 -0500 Subject: Makin' it so that if we have a type handler we use that, otherwise we pass things up. Also making it so that type handlers can report an error. --- libdbusmenu-glib/client.c | 22 ++++++++++++++++++++-- libdbusmenu-glib/client.h | 2 +- 2 files changed, 21 insertions(+), 3 deletions(-) diff --git a/libdbusmenu-glib/client.c b/libdbusmenu-glib/client.c index 9eb8b55..a4e4f72 100644 --- a/libdbusmenu-glib/client.c +++ b/libdbusmenu-glib/client.c @@ -530,10 +530,27 @@ static void menuitem_get_properties_new_cb (DBusGProxy * proxy, GHashTable * properties, GError * error, gpointer data) { gpointer * unpackarray = (gpointer *)data; + DbusmenuClientPrivate * priv = DBUSMENU_CLIENT_GET_PRIVATE(unpackarray[0]); menuitem_get_properties_cb (proxy, properties, error, unpackarray[1]); - g_signal_emit(G_OBJECT(unpackarray[0]), signals[NEW_MENUITEM], 0, unpackarray[1], TRUE); + gboolean handled = FALSE; + + const gchar * type; + DbusmenuClientTypeHandler newfunc = NULL; + + type = dbusmenu_menuitem_property_get(DBUSMENU_MENUITEM(unpackarray[1]), "type"); + if (type != NULL) { + newfunc = g_hash_table_lookup(priv->type_handlers, type); + } + + if (newfunc != NULL) { + handled = newfunc(DBUSMENU_MENUITEM(unpackarray[1]), DBUSMENU_MENUITEM(unpackarray[2])); + } + + if (!handled) { + g_signal_emit(G_OBJECT(unpackarray[0]), signals[NEW_MENUITEM], 0, unpackarray[1], TRUE); + } g_free(unpackarray); @@ -590,9 +607,10 @@ parse_layout_xml(DbusmenuClient * client, xmlNodePtr node, DbusmenuMenuitem * it /* Get the properties queued up for this item */ /* Not happy about this, but I need both of these :( */ - gpointer * packarray = g_new0(gpointer, 2); + gpointer * packarray = g_new0(gpointer, 3); packarray[0] = client; packarray[1] = item; + packarray[2] = parent; org_freedesktop_dbusmenu_get_properties_async(proxy, id, menuitem_get_properties_new_cb, packarray); } diff --git a/libdbusmenu-glib/client.h b/libdbusmenu-glib/client.h index 20156d8..9298d4e 100644 --- a/libdbusmenu-glib/client.h +++ b/libdbusmenu-glib/client.h @@ -90,7 +90,7 @@ struct _DbusmenuClient { GObject parent; }; -typedef void (*DbusmenuClientTypeHandler) (DbusmenuMenuitem * newitem, DbusmenuMenuitem * parent); +typedef gboolean (*DbusmenuClientTypeHandler) (DbusmenuMenuitem * newitem, DbusmenuMenuitem * parent); GType dbusmenu_client_get_type (void); DbusmenuClient * dbusmenu_client_new (const gchar * name, -- cgit v1.2.3 From 2a110cf96860653b68d1a165c7e3b7ddb1f993f8 Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Thu, 20 Aug 2009 13:20:54 -0500 Subject: Making things a little more type safe. Only one evil cast. --- libdbusmenu-glib/client.c | 34 +++++++++++++++++++++------------- 1 file changed, 21 insertions(+), 13 deletions(-) diff --git a/libdbusmenu-glib/client.c b/libdbusmenu-glib/client.c index a4e4f72..5809e1e 100644 --- a/libdbusmenu-glib/client.c +++ b/libdbusmenu-glib/client.c @@ -72,6 +72,14 @@ struct _DbusmenuClientPrivate GHashTable * type_handlers; }; +typedef struct _newItemPropData newItemPropData; +struct _newItemPropData +{ + DbusmenuClient * client; + DbusmenuMenuitem * item; + DbusmenuMenuitem * parent; +}; + #define DBUSMENU_CLIENT_GET_PRIVATE(o) \ (G_TYPE_INSTANCE_GET_PRIVATE ((o), DBUSMENU_TYPE_CLIENT, DbusmenuClientPrivate)) @@ -529,30 +537,30 @@ menuitem_get_properties_cb (DBusGProxy * proxy, GHashTable * properties, GError static void menuitem_get_properties_new_cb (DBusGProxy * proxy, GHashTable * properties, GError * error, gpointer data) { - gpointer * unpackarray = (gpointer *)data; - DbusmenuClientPrivate * priv = DBUSMENU_CLIENT_GET_PRIVATE(unpackarray[0]); + newItemPropData * propdata = (newItemPropData *)data; + DbusmenuClientPrivate * priv = DBUSMENU_CLIENT_GET_PRIVATE(propdata->client); - menuitem_get_properties_cb (proxy, properties, error, unpackarray[1]); + menuitem_get_properties_cb (proxy, properties, error, propdata->item); gboolean handled = FALSE; const gchar * type; DbusmenuClientTypeHandler newfunc = NULL; - type = dbusmenu_menuitem_property_get(DBUSMENU_MENUITEM(unpackarray[1]), "type"); + type = dbusmenu_menuitem_property_get(propdata->item, "type"); if (type != NULL) { newfunc = g_hash_table_lookup(priv->type_handlers, type); } if (newfunc != NULL) { - handled = newfunc(DBUSMENU_MENUITEM(unpackarray[1]), DBUSMENU_MENUITEM(unpackarray[2])); + handled = newfunc(propdata->item, propdata->parent); } if (!handled) { - g_signal_emit(G_OBJECT(unpackarray[0]), signals[NEW_MENUITEM], 0, unpackarray[1], TRUE); + g_signal_emit(G_OBJECT(propdata->client), signals[NEW_MENUITEM], 0, propdata->item, TRUE); } - g_free(unpackarray); + g_free(propdata); return; } @@ -606,13 +614,13 @@ parse_layout_xml(DbusmenuClient * client, xmlNodePtr node, DbusmenuMenuitem * it g_signal_connect(G_OBJECT(item), DBUSMENU_MENUITEM_SIGNAL_ITEM_ACTIVATED, G_CALLBACK(menuitem_activate), client); /* Get the properties queued up for this item */ - /* Not happy about this, but I need both of these :( */ - gpointer * packarray = g_new0(gpointer, 3); - packarray[0] = client; - packarray[1] = item; - packarray[2] = parent; + /* Not happy about this, but I need these :( */ + newItemPropData * propdata = g_new0(newItemPropData, 1); + propdata->client = client; + propdata->item = item; + propdata->parent = parent; - org_freedesktop_dbusmenu_get_properties_async(proxy, id, menuitem_get_properties_new_cb, packarray); + org_freedesktop_dbusmenu_get_properties_async(proxy, id, menuitem_get_properties_new_cb, propdata); } xmlNodePtr children; -- cgit v1.2.3 From 56f30fa80ae8b832d3d52f247194f90f30ae7dcc Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Tue, 25 Aug 2009 11:16:26 -0500 Subject: Creating a realized signal on the menu items. --- libdbusmenu-glib/menuitem.c | 17 +++++++++++++++++ libdbusmenu-glib/menuitem.h | 5 ++++- 2 files changed, 21 insertions(+), 1 deletion(-) diff --git a/libdbusmenu-glib/menuitem.c b/libdbusmenu-glib/menuitem.c index aba1f64..41c48e2 100644 --- a/libdbusmenu-glib/menuitem.c +++ b/libdbusmenu-glib/menuitem.c @@ -61,6 +61,7 @@ enum { CHILD_ADDED, CHILD_REMOVED, CHILD_MOVED, + REALIZED, LAST_SIGNAL }; @@ -178,6 +179,22 @@ dbusmenu_menuitem_class_init (DbusmenuMenuitemClass *klass) NULL, NULL, _dbusmenu_menuitem_marshal_VOID__OBJECT_UINT_UINT, G_TYPE_NONE, 3, G_TYPE_OBJECT, G_TYPE_UINT, G_TYPE_UINT); + /** + DbusmenuMenuitem::realized: + @arg0: The #DbusmenuMenuitem object. + + Emitted when the initial request for properties + is complete on the item. If there is a type + handler configured for the "type" parameter + that will be executed before this is signaled. + */ + signals[REALIZED] = g_signal_new(DBUSMENU_MENUITEM_SIGNAL_REALIZED, + G_TYPE_FROM_CLASS(klass), + G_SIGNAL_RUN_LAST, + G_STRUCT_OFFSET(DbusmenuMenuitemClass, realized), + NULL, NULL, + _dbusmenu_menuitem_marshal_VOID__VOID, + 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", diff --git a/libdbusmenu-glib/menuitem.h b/libdbusmenu-glib/menuitem.h index 29865c7..7704b4a 100644 --- a/libdbusmenu-glib/menuitem.h +++ b/libdbusmenu-glib/menuitem.h @@ -47,6 +47,7 @@ G_BEGIN_DECLS #define DBUSMENU_MENUITEM_SIGNAL_CHILD_ADDED "child-added" #define DBUSMENU_MENUITEM_SIGNAL_CHILD_REMOVED "child-removed" #define DBUSMENU_MENUITEM_SIGNAL_CHILD_MOVED "child-moved" +#define DBUSMENU_MENUITEM_SIGNAL_REALIZED "realized" /** DbusmenuMenuitem: @@ -71,6 +72,7 @@ struct _DbusmenuMenuitem @child_added: Slot for #DbusmenuMenuitem::child-added. @child_removed: Slot for #DbusmenuMenuitem::child-removed. @child_moved: Slot for #DbusmenuMenuitem::child-moved. + @realized: Slot for #DbusmenuMenuitem::realized. @buildxml: Virtual function that appends the strings required to represent this menu item in the menu XML file. @reserved1: Reserved for future use. @@ -89,6 +91,7 @@ struct _DbusmenuMenuitemClass void (*child_added) (DbusmenuMenuitem * child, guint position); void (*child_removed) (DbusmenuMenuitem * child); void (*child_moved) (DbusmenuMenuitem * child, guint newpos, guint oldpos); + void (*realized) (void); /* Virtual functions */ void (*buildxml) (GPtrArray * stringarray); @@ -96,7 +99,7 @@ struct _DbusmenuMenuitemClass void (*reserved1) (void); void (*reserved2) (void); void (*reserved3) (void); - void (*reserved4) (void); + /* void (*reserved4) (void); -- realized, realloc when bumping lib version */ }; GType dbusmenu_menuitem_get_type (void); -- cgit v1.2.3 From 3136e45a9b1aa56ba8d136df34310ab0891e1a84 Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Tue, 25 Aug 2009 11:28:13 -0500 Subject: Signaling the realized event after it has all it's parameters. --- libdbusmenu-glib/client.c | 2 ++ libdbusmenu-glib/menuitem.h | 1 + 2 files changed, 3 insertions(+) diff --git a/libdbusmenu-glib/client.c b/libdbusmenu-glib/client.c index 5809e1e..4f5922d 100644 --- a/libdbusmenu-glib/client.c +++ b/libdbusmenu-glib/client.c @@ -556,6 +556,8 @@ menuitem_get_properties_new_cb (DBusGProxy * proxy, GHashTable * properties, GEr handled = newfunc(propdata->item, propdata->parent); } + g_signal_emit(G_OBJECT(propdata->item), DBUSMENU_MENUITEM_SIGNAL_REALIZED_ID, 0, TRUE); + if (!handled) { g_signal_emit(G_OBJECT(propdata->client), signals[NEW_MENUITEM], 0, propdata->item, TRUE); } diff --git a/libdbusmenu-glib/menuitem.h b/libdbusmenu-glib/menuitem.h index 7704b4a..0a92153 100644 --- a/libdbusmenu-glib/menuitem.h +++ b/libdbusmenu-glib/menuitem.h @@ -48,6 +48,7 @@ G_BEGIN_DECLS #define DBUSMENU_MENUITEM_SIGNAL_CHILD_REMOVED "child-removed" #define DBUSMENU_MENUITEM_SIGNAL_CHILD_MOVED "child-moved" #define DBUSMENU_MENUITEM_SIGNAL_REALIZED "realized" +#define DBUSMENU_MENUITEM_SIGNAL_REALIZED_ID (g_signal_lookup(DBUSMENU_MENUITEM_SIGNAL_REALIZED, DBUSMENU_TYPE_MENUITEM)) /** DbusmenuMenuitem: -- cgit v1.2.3 From c25508f253327fa64fc3dd165480b021273834f4 Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Tue, 25 Aug 2009 12:09:22 -0500 Subject: Okay, building in some type handlers now. --- libdbusmenu-glib/client.h | 4 ++++ libdbusmenu-gtk/client.c | 30 ++++++++++++++++++++++++++++++ 2 files changed, 34 insertions(+) diff --git a/libdbusmenu-glib/client.h b/libdbusmenu-glib/client.h index 9298d4e..c30f318 100644 --- a/libdbusmenu-glib/client.h +++ b/libdbusmenu-glib/client.h @@ -50,6 +50,10 @@ G_BEGIN_DECLS #define DBUSMENU_CLIENT_PROP_DBUS_NAME "dbus-name" #define DBUSMENU_CLIENT_PROP_DBUS_OBJECT "dbus-object" +#define DBUSMENU_CLIENT_TYPES_DEFAULT "menuitem" +#define DBUSMENU_CLIENT_TYPES_SEPERATOR "seperator" +#define DBUSMENU_CLIENT_TYPES_IMAGE "imageitem" + /** DbusmenuClientClass: @parent_class: #GObjectClass diff --git a/libdbusmenu-gtk/client.c b/libdbusmenu-gtk/client.c index a236123..b2d19b4 100644 --- a/libdbusmenu-gtk/client.c +++ b/libdbusmenu-gtk/client.c @@ -44,6 +44,10 @@ static void new_child (DbusmenuMenuitem * mi, DbusmenuMenuitem * child, guint po static void delete_child (DbusmenuMenuitem * mi, DbusmenuMenuitem * child, DbusmenuGtkClient * gtkclient); static void move_child (DbusmenuMenuitem * mi, DbusmenuMenuitem * child, guint new, guint old, DbusmenuGtkClient * gtkclient); +static gboolean new_item_normal (DbusmenuMenuitem * newitem, DbusmenuMenuitem * parent); +static gboolean new_item_seperator (DbusmenuMenuitem * newitem, DbusmenuMenuitem * parent); +static gboolean new_item_image (DbusmenuMenuitem * newitem, DbusmenuMenuitem * parent); + /* GObject Stuff */ G_DEFINE_TYPE (DbusmenuGtkClient, dbusmenu_gtkclient, DBUSMENU_TYPE_CLIENT); @@ -62,6 +66,11 @@ static void dbusmenu_gtkclient_init (DbusmenuGtkClient *self) { g_signal_connect(G_OBJECT(self), DBUSMENU_CLIENT_SIGNAL_NEW_MENUITEM, G_CALLBACK(new_menuitem), NULL); + + dbusmenu_client_add_type_handler(DBUSMENU_CLIENT(self), DBUSMENU_CLIENT_TYPES_DEFAULT, new_item_normal); + dbusmenu_client_add_type_handler(DBUSMENU_CLIENT(self), DBUSMENU_CLIENT_TYPES_SEPERATOR, new_item_seperator); + dbusmenu_client_add_type_handler(DBUSMENU_CLIENT(self), DBUSMENU_CLIENT_TYPES_IMAGE, new_item_image); + return; } @@ -258,3 +267,24 @@ dbusmenu_gtkclient_menuitem_get (DbusmenuGtkClient * client, DbusmenuMenuitem * return mi; } +static gboolean +new_item_normal (DbusmenuMenuitem * newitem, DbusmenuMenuitem * parent) +{ + + + return TRUE; +} + +static gboolean +new_item_seperator (DbusmenuMenuitem * newitem, DbusmenuMenuitem * parent) +{ + + return TRUE; +} + +static gboolean +new_item_image (DbusmenuMenuitem * newitem, DbusmenuMenuitem * parent) +{ + + return TRUE; +} -- cgit v1.2.3 From be6ccb4737e45a73da882ddf3d3c0fc725739a6d Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Tue, 25 Aug 2009 14:10:38 -0500 Subject: Code reshuffle. Now a warning on new items and fleshing out the type-based functions. --- libdbusmenu-gtk/client.c | 28 +++++++++++++++++++--------- 1 file changed, 19 insertions(+), 9 deletions(-) diff --git a/libdbusmenu-gtk/client.c b/libdbusmenu-gtk/client.c index b2d19b4..0f24c39 100644 --- a/libdbusmenu-gtk/client.c +++ b/libdbusmenu-gtk/client.c @@ -134,17 +134,15 @@ destoryed_dbusmenuitem_cb (gpointer udata, GObject * dbusmenuitem) static void new_menuitem (DbusmenuClient * client, DbusmenuMenuitem * mi, gpointer userdata) { - gpointer ann_mi = g_object_get_data(G_OBJECT(mi), data_menuitem); - GtkMenuItem * gmi = GTK_MENU_ITEM(ann_mi); - - if (gmi != NULL) { - /* It's possible we've already been looked at, that's - okay, but we can just ignore this signal then. */ - return; - } + g_warning("Got new menuitem signal, which means they want something"); + g_warning(" that I simply don't have."); - gmi = GTK_MENU_ITEM(gtk_menu_item_new()); + return; +} +static void +base_new_menuitem (DbusmenuMenuitem * mi, GtkMenuItem * gmi, DbusmenuGtkClient * client) +{ /* Attach these two */ g_object_set_data(G_OBJECT(mi), data_menuitem, gmi); @@ -270,7 +268,19 @@ dbusmenu_gtkclient_menuitem_get (DbusmenuGtkClient * client, DbusmenuMenuitem * static gboolean new_item_normal (DbusmenuMenuitem * newitem, DbusmenuMenuitem * parent) { + gpointer ann_mi = g_object_get_data(G_OBJECT(newitem), data_menuitem); + GtkMenuItem * gmi = GTK_MENU_ITEM(ann_mi); + + if (gmi != NULL) { + /* It's possible we've already been looked at, that's + okay, but we can just ignore this signal then. */ + return TRUE; + } + + gmi = GTK_MENU_ITEM(gtk_menu_item_new()); + // Need client + base_new_menuitem(newitem, gmi, NULL); return TRUE; } -- cgit v1.2.3 From 0d23ee0ce837c23750bdeef3e01c4f117d1250fc Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Tue, 25 Aug 2009 14:13:34 -0500 Subject: Switching the prototype for type handlers so that it passes the client as well. --- libdbusmenu-glib/client.c | 2 +- libdbusmenu-glib/client.h | 2 +- libdbusmenu-gtk/client.c | 15 +++++++-------- 3 files changed, 9 insertions(+), 10 deletions(-) diff --git a/libdbusmenu-glib/client.c b/libdbusmenu-glib/client.c index 4f5922d..9ac880b 100644 --- a/libdbusmenu-glib/client.c +++ b/libdbusmenu-glib/client.c @@ -553,7 +553,7 @@ menuitem_get_properties_new_cb (DBusGProxy * proxy, GHashTable * properties, GEr } if (newfunc != NULL) { - handled = newfunc(propdata->item, propdata->parent); + handled = newfunc(propdata->item, propdata->parent, propdata->client); } g_signal_emit(G_OBJECT(propdata->item), DBUSMENU_MENUITEM_SIGNAL_REALIZED_ID, 0, TRUE); diff --git a/libdbusmenu-glib/client.h b/libdbusmenu-glib/client.h index c30f318..b4d214f 100644 --- a/libdbusmenu-glib/client.h +++ b/libdbusmenu-glib/client.h @@ -94,7 +94,7 @@ struct _DbusmenuClient { GObject parent; }; -typedef gboolean (*DbusmenuClientTypeHandler) (DbusmenuMenuitem * newitem, DbusmenuMenuitem * parent); +typedef gboolean (*DbusmenuClientTypeHandler) (DbusmenuMenuitem * newitem, DbusmenuMenuitem * parent, DbusmenuClient * client); GType dbusmenu_client_get_type (void); DbusmenuClient * dbusmenu_client_new (const gchar * name, diff --git a/libdbusmenu-gtk/client.c b/libdbusmenu-gtk/client.c index 0f24c39..bc4a72a 100644 --- a/libdbusmenu-gtk/client.c +++ b/libdbusmenu-gtk/client.c @@ -44,9 +44,9 @@ static void new_child (DbusmenuMenuitem * mi, DbusmenuMenuitem * child, guint po static void delete_child (DbusmenuMenuitem * mi, DbusmenuMenuitem * child, DbusmenuGtkClient * gtkclient); static void move_child (DbusmenuMenuitem * mi, DbusmenuMenuitem * child, guint new, guint old, DbusmenuGtkClient * gtkclient); -static gboolean new_item_normal (DbusmenuMenuitem * newitem, DbusmenuMenuitem * parent); -static gboolean new_item_seperator (DbusmenuMenuitem * newitem, DbusmenuMenuitem * parent); -static gboolean new_item_image (DbusmenuMenuitem * newitem, DbusmenuMenuitem * parent); +static gboolean new_item_normal (DbusmenuMenuitem * newitem, DbusmenuMenuitem * parent, DbusmenuClient * client); +static gboolean new_item_seperator (DbusmenuMenuitem * newitem, DbusmenuMenuitem * parent, DbusmenuClient * client); +static gboolean new_item_image (DbusmenuMenuitem * newitem, DbusmenuMenuitem * parent, DbusmenuClient * client); /* GObject Stuff */ G_DEFINE_TYPE (DbusmenuGtkClient, dbusmenu_gtkclient, DBUSMENU_TYPE_CLIENT); @@ -266,7 +266,7 @@ dbusmenu_gtkclient_menuitem_get (DbusmenuGtkClient * client, DbusmenuMenuitem * } static gboolean -new_item_normal (DbusmenuMenuitem * newitem, DbusmenuMenuitem * parent) +new_item_normal (DbusmenuMenuitem * newitem, DbusmenuMenuitem * parent, DbusmenuClient * client) { gpointer ann_mi = g_object_get_data(G_OBJECT(newitem), data_menuitem); GtkMenuItem * gmi = GTK_MENU_ITEM(ann_mi); @@ -279,21 +279,20 @@ new_item_normal (DbusmenuMenuitem * newitem, DbusmenuMenuitem * parent) gmi = GTK_MENU_ITEM(gtk_menu_item_new()); - // Need client - base_new_menuitem(newitem, gmi, NULL); + base_new_menuitem(newitem, gmi, DBUSMENU_GTKCLIENT(client)); return TRUE; } static gboolean -new_item_seperator (DbusmenuMenuitem * newitem, DbusmenuMenuitem * parent) +new_item_seperator (DbusmenuMenuitem * newitem, DbusmenuMenuitem * parent, DbusmenuClient * client) { return TRUE; } static gboolean -new_item_image (DbusmenuMenuitem * newitem, DbusmenuMenuitem * parent) +new_item_image (DbusmenuMenuitem * newitem, DbusmenuMenuitem * parent, DbusmenuClient * client) { return TRUE; -- cgit v1.2.3 From 780e2c229e24e20c026219ce6e87533092a172b2 Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Tue, 25 Aug 2009 14:46:54 -0500 Subject: Forgot some signal documentation. --- libdbusmenu-glib/client.h | 1 + 1 file changed, 1 insertion(+) diff --git a/libdbusmenu-glib/client.h b/libdbusmenu-glib/client.h index b4d214f..563a2e8 100644 --- a/libdbusmenu-glib/client.h +++ b/libdbusmenu-glib/client.h @@ -58,6 +58,7 @@ G_BEGIN_DECLS DbusmenuClientClass: @parent_class: #GObjectClass @layout_updated: Slot for #DbusmenuClient::layout-updated. + @new_menuitem: Slot for #DbusmenuClient::new-menuitem. @reserved1: Reserved for future use. @reserved2: Reserved for future use. @reserved3: Reserved for future use. -- cgit v1.2.3 From d5e159567d782bfd8568d9075bea32264f326dff Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Tue, 25 Aug 2009 14:47:43 -0500 Subject: It turns out that when you define functions in a header file, they don't just write themselves from your thoughts. Who's supposed to tell me these things? Anyway, now we have a way to register type handlers, like the header file said we should. --- libdbusmenu-glib/client.c | 43 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 43 insertions(+) diff --git a/libdbusmenu-glib/client.c b/libdbusmenu-glib/client.c index 9ac880b..c89b44b 100644 --- a/libdbusmenu-glib/client.c +++ b/libdbusmenu-glib/client.c @@ -802,3 +802,46 @@ dbusmenu_client_get_root (DbusmenuClient * client) return priv->root; } + +/** + dbusmenu_client_add_type_handler: + @client: Client where we're getting types coming in + @type: A text string that will be matched with the 'type' + property on incoming menu items + @newfunc: The function that will be executed with those new + items when they come in. + + This function connects into the type handling of the #DbusmenuClient. + Every new menuitem that comes in immediately gets asked for it's + properties. When we get those properties we check the 'type' + property and look to see if it matches a handler that is known + by the client. If so, the @newfunc function is executed on that + #DbusmenuMenuitem. If not, then the DbusmenuClient::new-menuitem + signal is sent. + + In the future the known types will be sent to the server so that it + can make choices about the menu item types availble. + + Return value: If registering the new type was successful. +*/ +gboolean +dbusmenu_client_add_type_handler (DbusmenuClient * client, const gchar * type, DbusmenuClientTypeHandler newfunc) +{ + g_return_val_if_fail(DBUSMENU_IS_CLIENT(client), FALSE); + + DbusmenuClientPrivate * priv = DBUSMENU_CLIENT_GET_PRIVATE(client); + + if (priv->type_handlers) { + g_warning("Type handlers hashtable not built"); + return FALSE; + } + + gpointer value = g_hash_table_lookup(priv->type_handlers, type); + if (value != NULL) { + g_warning("Type '%s' already had a registered handler.", type); + return FALSE; + } + + g_hash_table_insert(priv->type_handlers, g_strdup(type), newfunc); + return TRUE; +} -- cgit v1.2.3 From 6de64b37859c511bb6583ea8f98d52a5bc6d9029 Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Tue, 25 Aug 2009 15:38:18 -0500 Subject: Now we're building the child/parent relationship using the activation type function. --- libdbusmenu-gtk/client.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/libdbusmenu-gtk/client.c b/libdbusmenu-gtk/client.c index bc4a72a..913a902 100644 --- a/libdbusmenu-gtk/client.c +++ b/libdbusmenu-gtk/client.c @@ -148,7 +148,6 @@ base_new_menuitem (DbusmenuMenuitem * mi, GtkMenuItem * gmi, DbusmenuGtkClient * /* DbusmenuMenuitem signals */ g_signal_connect(G_OBJECT(mi), DBUSMENU_MENUITEM_SIGNAL_PROPERTY_CHANGED, G_CALLBACK(menu_prop_change_cb), gmi); - g_signal_connect(G_OBJECT(mi), DBUSMENU_MENUITEM_SIGNAL_CHILD_ADDED, G_CALLBACK(new_child), client); g_signal_connect(G_OBJECT(mi), DBUSMENU_MENUITEM_SIGNAL_CHILD_REMOVED, G_CALLBACK(delete_child), client); g_signal_connect(G_OBJECT(mi), DBUSMENU_MENUITEM_SIGNAL_CHILD_MOVED, G_CALLBACK(move_child), client); @@ -266,7 +265,7 @@ dbusmenu_gtkclient_menuitem_get (DbusmenuGtkClient * client, DbusmenuMenuitem * } static gboolean -new_item_normal (DbusmenuMenuitem * newitem, DbusmenuMenuitem * parent, DbusmenuClient * client) +new_item_normal (DbusmenuMenuitem * newitem, DbusmenuMenuitem * parent, DbusmenuClient * client) { gpointer ann_mi = g_object_get_data(G_OBJECT(newitem), data_menuitem); GtkMenuItem * gmi = GTK_MENU_ITEM(ann_mi); @@ -280,6 +279,9 @@ new_item_normal (DbusmenuMenuitem * newitem, DbusmenuMenuitem * parent, Dbus gmi = GTK_MENU_ITEM(gtk_menu_item_new()); base_new_menuitem(newitem, gmi, DBUSMENU_GTKCLIENT(client)); + if (parent != NULL) { + new_child(parent, newitem, dbusmenu_menuitem_get_position(newitem, parent), DBUSMENU_GTKCLIENT(client)); + } return TRUE; } -- cgit v1.2.3 From 7e5458a267bc02c113c082a8185adf325cf5780d Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Tue, 25 Aug 2009 15:47:37 -0500 Subject: Ah, bother. Check NULL. Brain fart. --- 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 c89b44b..0a80c6e 100644 --- a/libdbusmenu-glib/client.c +++ b/libdbusmenu-glib/client.c @@ -831,7 +831,7 @@ dbusmenu_client_add_type_handler (DbusmenuClient * client, const gchar * type, D DbusmenuClientPrivate * priv = DBUSMENU_CLIENT_GET_PRIVATE(client); - if (priv->type_handlers) { + if (priv->type_handlers == NULL) { g_warning("Type handlers hashtable not built"); return FALSE; } -- cgit v1.2.3 From 8b55963be1e11350223fb2343379f6e851b37434 Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Tue, 25 Aug 2009 16:32:58 -0500 Subject: Adding a type of 'menuitem' on all of these. --- tests/test-gtk-label.json | 134 +++++++++++++++++++++++----------------------- 1 file changed, 67 insertions(+), 67 deletions(-) diff --git a/tests/test-gtk-label.json b/tests/test-gtk-label.json index 64c1386..4bb9e0e 100644 --- a/tests/test-gtk-label.json +++ b/tests/test-gtk-label.json @@ -1,155 +1,155 @@ [ - {"id": 1, + {"id": 1, "type": "menuitem", "label": "value1", "submenu": [ - {"id": 30, + {"id": 30, "type": "menuitem", "label": "value30"}, - {"id": 31, + {"id": 31, "type": "menuitem", "label": "value31"}, - {"id": 32, + {"id": 32, "type": "menuitem", "label": "value32"}, - {"id": 33, + {"id": 33, "type": "menuitem", "label": "value33"}, - {"id": 34, + {"id": 34, "type": "menuitem", "label": "value34"}, - {"id": 35, + {"id": 35, "type": "menuitem", "label": "value35"}, - {"id": 36, + {"id": 36, "type": "menuitem", "label": "value36"}, - {"id": 37, + {"id": 37, "type": "menuitem", "label": "value37"}, - {"id": 38, + {"id": 38, "type": "menuitem", "label": "value38"}, - {"id": 39, + {"id": 39, "type": "menuitem", "label": "value39"} ] }, - {"id": 2, + {"id": 2, "type": "menuitem", "label": "value2", "submenu": [ - {"id": 20, + {"id": 20, "type": "menuitem", "label": "value20"}, - {"id": 21, + {"id": 21, "type": "menuitem", "label": "value21"}, - {"id": 22, + {"id": 22, "type": "menuitem", "label": "value22"}, - {"id": 23, + {"id": 23, "type": "menuitem", "label": "value23"}, - {"id": 24, + {"id": 24, "type": "menuitem", "label": "value24"}, - {"id": 25, + {"id": 25, "type": "menuitem", "label": "value25"}, - {"id": 26, + {"id": 26, "type": "menuitem", "label": "value26"}, - {"id": 27, + {"id": 27, "type": "menuitem", "label": "value27"}, - {"id": 28, + {"id": 28, "type": "menuitem", "label": "value28"}, - {"id": 29, + {"id": 29, "type": "menuitem", "label": "value29"} ] }, - {"id": 3, + {"id": 3, "type": "menuitem", "label": "a super long label that is really of unreasonable length but we should make sure it makes it across the bus", "not.a.value": "A useless value", "submenu": [ - {"id": 10, + {"id": 10, "type": "menuitem", "label": "value10"}, - {"id": 11, + {"id": 11, "type": "menuitem", "label": "value11"}, - {"id": 12, + {"id": 12, "type": "menuitem", "label": "value12"}, - {"id": 13, + {"id": 13, "type": "menuitem", "label": "value13"}, - {"id": 14, + {"id": 14, "type": "menuitem", "label": "value14"}, - {"id": 15, + {"id": 15, "type": "menuitem", "label": "value15"}, - {"id": 16, + {"id": 16, "type": "menuitem", "label": "value16"}, - {"id": 17, + {"id": 17, "type": "menuitem", "label": "value17"}, - {"id": 18, + {"id": 18, "type": "menuitem", "label": "value18"}, - {"id": 19, + {"id": 19, "type": "menuitem", "label": "value19"} ] }, - {"id": 4, + {"id": 4, "type": "menuitem", "label": "value2", "submenu": [ - {"id": 5, + {"id": 5, "type": "menuitem", "label": "value5", "submenu": [ - {"id": 10, + {"id": 10, "type": "menuitem", "label": "value10"}, - {"id": 11, + {"id": 11, "type": "menuitem", "label": "value11"}, - {"id": 12, + {"id": 12, "type": "menuitem", "label": "value12"}, - {"id": 13, + {"id": 13, "type": "menuitem", "label": "value13"}, - {"id": 14, + {"id": 14, "type": "menuitem", "label": "value14"}, - {"id": 15, + {"id": 15, "type": "menuitem", "label": "value15"}, - {"id": 16, + {"id": 16, "type": "menuitem", "label": "value16"}, - {"id": 17, + {"id": 17, "type": "menuitem", "label": "value17"}, - {"id": 18, + {"id": 18, "type": "menuitem", "label": "value18"}, - {"id": 19, + {"id": 19, "type": "menuitem", "label": "value19"} ] }, - {"id": 6, + {"id": 6, "type": "menuitem", "label": "value6", "submenu": [ - {"id": 20, + {"id": 20, "type": "menuitem", "label": "value20"}, - {"id": 21, + {"id": 21, "type": "menuitem", "label": "value21"}, - {"id": 22, + {"id": 22, "type": "menuitem", "label": "value22"}, - {"id": 23, + {"id": 23, "type": "menuitem", "label": "value23"}, - {"id": 24, + {"id": 24, "type": "menuitem", "label": "value24"}, - {"id": 25, + {"id": 25, "type": "menuitem", "label": "value25"}, - {"id": 26, + {"id": 26, "type": "menuitem", "label": "value26"}, - {"id": 27, + {"id": 27, "type": "menuitem", "label": "value27"}, - {"id": 28, + {"id": 28, "type": "menuitem", "label": "value28"}, - {"id": 29, + {"id": 29, "type": "menuitem", "label": "value29"} ] }, - {"id": 7, + {"id": 7, "type": "menuitem", "label": "value7", "submenu": [ - {"id": 30, + {"id": 30, "type": "menuitem", "label": "value30"}, - {"id": 31, + {"id": 31, "type": "menuitem", "label": "value31"}, - {"id": 32, + {"id": 32, "type": "menuitem", "label": "value32"}, - {"id": 33, + {"id": 33, "type": "menuitem", "label": "value33"}, - {"id": 34, + {"id": 34, "type": "menuitem", "label": "value34"}, - {"id": 35, + {"id": 35, "type": "menuitem", "label": "value35"}, - {"id": 36, + {"id": 36, "type": "menuitem", "label": "value36"}, - {"id": 37, + {"id": 37, "type": "menuitem", "label": "value37"}, - {"id": 38, + {"id": 38, "type": "menuitem", "label": "value38"}, - {"id": 39, + {"id": 39, "type": "menuitem", "label": "value39"} ] }, -- cgit v1.2.3 From fc7cc87f18d5fc301c06489517f48c720ffd5006 Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Wed, 26 Aug 2009 14:38:02 -0500 Subject: Adding a warning, showing the widget and moving the new signal to ensure everything is setup first --- libdbusmenu-gtk/client.c | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/libdbusmenu-gtk/client.c b/libdbusmenu-gtk/client.c index 913a902..79db256 100644 --- a/libdbusmenu-gtk/client.c +++ b/libdbusmenu-gtk/client.c @@ -65,12 +65,12 @@ dbusmenu_gtkclient_class_init (DbusmenuGtkClientClass *klass) static void dbusmenu_gtkclient_init (DbusmenuGtkClient *self) { - g_signal_connect(G_OBJECT(self), DBUSMENU_CLIENT_SIGNAL_NEW_MENUITEM, G_CALLBACK(new_menuitem), NULL); - dbusmenu_client_add_type_handler(DBUSMENU_CLIENT(self), DBUSMENU_CLIENT_TYPES_DEFAULT, new_item_normal); dbusmenu_client_add_type_handler(DBUSMENU_CLIENT(self), DBUSMENU_CLIENT_TYPES_SEPERATOR, new_item_seperator); dbusmenu_client_add_type_handler(DBUSMENU_CLIENT(self), DBUSMENU_CLIENT_TYPES_IMAGE, new_item_image); + g_signal_connect(G_OBJECT(self), DBUSMENU_CLIENT_SIGNAL_NEW_MENUITEM, G_CALLBACK(new_menuitem), NULL); + return; } @@ -257,7 +257,8 @@ dbusmenu_gtkclient_menuitem_get (DbusmenuGtkClient * client, DbusmenuMenuitem * GtkMenuItem * mi = GTK_MENU_ITEM(g_object_get_data(G_OBJECT(item), data_menuitem)); if (mi == NULL) { - new_menuitem(DBUSMENU_CLIENT(client), item, NULL); + // new_menuitem(DBUSMENU_CLIENT(client), item, NULL); + g_warning("GTK not updated"); mi = GTK_MENU_ITEM(g_object_get_data(G_OBJECT(item), data_menuitem)); } @@ -277,6 +278,7 @@ new_item_normal (DbusmenuMenuitem * newitem, DbusmenuMenuitem * parent, Dbusmenu } gmi = GTK_MENU_ITEM(gtk_menu_item_new()); + gtk_widget_show(GTK_WIDGET(gmi)); base_new_menuitem(newitem, gmi, DBUSMENU_GTKCLIENT(client)); if (parent != NULL) { -- cgit v1.2.3 From 41336bb019c846e48b06cca071aba917fc86d0c3 Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Wed, 26 Aug 2009 14:38:30 -0500 Subject: Instead of directly appending items, make it so that they're not connected until they're realized. --- libdbusmenu-gtk/menu.c | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/libdbusmenu-gtk/menu.c b/libdbusmenu-gtk/menu.c index bc7458c..6e78a04 100644 --- a/libdbusmenu-gtk/menu.c +++ b/libdbusmenu-gtk/menu.c @@ -213,6 +213,16 @@ root_child_delete (DbusmenuMenuitem * root, DbusmenuMenuitem * child, DbusmenuGt return; } +static void +child_realized (DbusmenuMenuitem * child, gpointer userdata) +{ + DbusmenuGtkMenu * menu = DBUSMENU_GTKMENU(userdata); + DbusmenuGtkMenuPrivate * priv = DBUSMENU_GTKMENU_GET_PRIVATE(menu); + + gtk_menu_append(menu, GTK_WIDGET(dbusmenu_gtkclient_menuitem_get(priv->client, child))); + return; +} + static void root_changed (DbusmenuGtkClient * client, DbusmenuMenuitem * newroot, DbusmenuGtkMenu * menu) { if (newroot == NULL) { @@ -227,7 +237,8 @@ root_changed (DbusmenuGtkClient * client, DbusmenuMenuitem * newroot, DbusmenuGt GList * child = NULL; guint count = 0; for (child = dbusmenu_menuitem_get_children(newroot); child != NULL; child = g_list_next(child)) { - gtk_menu_append(menu, GTK_WIDGET(dbusmenu_gtkclient_menuitem_get(client, child->data))); + /* gtk_menu_append(menu, GTK_WIDGET(dbusmenu_gtkclient_menuitem_get(client, child->data))); */ + g_signal_connect(G_OBJECT(child->data), DBUSMENU_MENUITEM_SIGNAL_REALIZED, G_CALLBACK(child_realized), menu); count++; } -- cgit v1.2.3 From 10f143ca67ff9b607cb24b2f77ba8bb472c19fff Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Wed, 26 Aug 2009 14:41:49 -0500 Subject: Use the label Luke! It helps. --- libdbusmenu-gtk/client.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libdbusmenu-gtk/client.c b/libdbusmenu-gtk/client.c index 79db256..f1fc13d 100644 --- a/libdbusmenu-gtk/client.c +++ b/libdbusmenu-gtk/client.c @@ -277,7 +277,7 @@ new_item_normal (DbusmenuMenuitem * newitem, DbusmenuMenuitem * parent, Dbusmenu return TRUE; } - gmi = GTK_MENU_ITEM(gtk_menu_item_new()); + gmi = GTK_MENU_ITEM(gtk_menu_item_new_with_label(dbusmenu_menuitem_property_get(newitem, "label"))); gtk_widget_show(GTK_WIDGET(gmi)); base_new_menuitem(newitem, gmi, DBUSMENU_GTKCLIENT(client)); -- cgit v1.2.3 From 70405abaa298f0ad4043988c637e4979fc43ffbe Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Wed, 26 Aug 2009 15:14:26 -0500 Subject: Making a separator --- libdbusmenu-gtk/client.c | 20 +++++++++++--------- 1 file changed, 11 insertions(+), 9 deletions(-) diff --git a/libdbusmenu-gtk/client.c b/libdbusmenu-gtk/client.c index f1fc13d..d3efb08 100644 --- a/libdbusmenu-gtk/client.c +++ b/libdbusmenu-gtk/client.c @@ -66,7 +66,7 @@ static void dbusmenu_gtkclient_init (DbusmenuGtkClient *self) { dbusmenu_client_add_type_handler(DBUSMENU_CLIENT(self), DBUSMENU_CLIENT_TYPES_DEFAULT, new_item_normal); - dbusmenu_client_add_type_handler(DBUSMENU_CLIENT(self), DBUSMENU_CLIENT_TYPES_SEPERATOR, new_item_seperator); + dbusmenu_client_add_type_handler(DBUSMENU_CLIENT(self), DBUSMENU_CLIENT_TYPES_SEPARATOR, new_item_seperator); dbusmenu_client_add_type_handler(DBUSMENU_CLIENT(self), DBUSMENU_CLIENT_TYPES_IMAGE, new_item_image); g_signal_connect(G_OBJECT(self), DBUSMENU_CLIENT_SIGNAL_NEW_MENUITEM, G_CALLBACK(new_menuitem), NULL); @@ -268,14 +268,7 @@ dbusmenu_gtkclient_menuitem_get (DbusmenuGtkClient * client, DbusmenuMenuitem * static gboolean new_item_normal (DbusmenuMenuitem * newitem, DbusmenuMenuitem * parent, DbusmenuClient * client) { - gpointer ann_mi = g_object_get_data(G_OBJECT(newitem), data_menuitem); - GtkMenuItem * gmi = GTK_MENU_ITEM(ann_mi); - - if (gmi != NULL) { - /* It's possible we've already been looked at, that's - okay, but we can just ignore this signal then. */ - return TRUE; - } + GtkMenuItem * gmi; gmi = GTK_MENU_ITEM(gtk_menu_item_new_with_label(dbusmenu_menuitem_property_get(newitem, "label"))); gtk_widget_show(GTK_WIDGET(gmi)); @@ -291,6 +284,15 @@ new_item_normal (DbusmenuMenuitem * newitem, DbusmenuMenuitem * parent, Dbusmenu static gboolean new_item_seperator (DbusmenuMenuitem * newitem, DbusmenuMenuitem * parent, DbusmenuClient * client) { + GtkMenuItem * gmi; + + gmi = GTK_MENU_ITEM(gtk_separator_menu_item_new()); + gtk_widget_show(GTK_WIDGET(gmi)); + + base_new_menuitem(newitem, gmi, DBUSMENU_GTKCLIENT(client)); + if (parent != NULL) { + new_child(parent, newitem, dbusmenu_menuitem_get_position(newitem, parent), DBUSMENU_GTKCLIENT(client)); + } return TRUE; } -- cgit v1.2.3 From 6e80defeeb473bb6df07644a755dcbae72dbf6e1 Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Wed, 26 Aug 2009 15:15:13 -0500 Subject: Spelling fix. --- libdbusmenu-glib/client.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libdbusmenu-glib/client.h b/libdbusmenu-glib/client.h index 563a2e8..fff9a6b 100644 --- a/libdbusmenu-glib/client.h +++ b/libdbusmenu-glib/client.h @@ -51,7 +51,7 @@ G_BEGIN_DECLS #define DBUSMENU_CLIENT_PROP_DBUS_OBJECT "dbus-object" #define DBUSMENU_CLIENT_TYPES_DEFAULT "menuitem" -#define DBUSMENU_CLIENT_TYPES_SEPERATOR "seperator" +#define DBUSMENU_CLIENT_TYPES_SEPARATOR "separator" #define DBUSMENU_CLIENT_TYPES_IMAGE "imageitem" /** -- cgit v1.2.3 From 749c283bbaaffff3ca4622ec32df6300ab08b559 Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Wed, 26 Aug 2009 15:18:50 -0500 Subject: Adding some defines for some common property values. --- libdbusmenu-glib/menuitem.h | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/libdbusmenu-glib/menuitem.h b/libdbusmenu-glib/menuitem.h index 0a92153..7806017 100644 --- a/libdbusmenu-glib/menuitem.h +++ b/libdbusmenu-glib/menuitem.h @@ -50,6 +50,11 @@ G_BEGIN_DECLS #define DBUSMENU_MENUITEM_SIGNAL_REALIZED "realized" #define DBUSMENU_MENUITEM_SIGNAL_REALIZED_ID (g_signal_lookup(DBUSMENU_MENUITEM_SIGNAL_REALIZED, DBUSMENU_TYPE_MENUITEM)) +#define DBUSMENU_MENUITEM_PROP_VISIBLE "visible" +#define DBUSMENU_MENUITEM_PROP_LABEL "label" +#define DBUSMENU_MENUITEM_PROP_ICON "icon" +#define DBUSMENU_MENUITEM_PROP_ICON_DATA "icon-data" + /** DbusmenuMenuitem: -- cgit v1.2.3 From 340e506debd81bb6f2dff5ee56e02ebf3b20b5dc Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Wed, 26 Aug 2009 15:25:37 -0500 Subject: Centralize visiblity processing and changes to the prop value. --- libdbusmenu-gtk/client.c | 21 +++++++++++++++++---- 1 file changed, 17 insertions(+), 4 deletions(-) diff --git a/libdbusmenu-gtk/client.c b/libdbusmenu-gtk/client.c index d3efb08..afa8bb3 100644 --- a/libdbusmenu-gtk/client.c +++ b/libdbusmenu-gtk/client.c @@ -104,14 +104,27 @@ menu_pressed_cb (GtkMenuItem * gmi, DbusmenuMenuitem * mi) return TRUE; } +/* Process the visible property */ +static void +process_visible (GtkMenuItem * gmi, const gchar * value) +{ + if (value == NULL || !g_strcmp0(value, "true")) { + gtk_widget_show(GTK_WIDGET(gmi)); + } else { + gtk_widget_hide(GTK_WIDGET(gmi)); + } + return; +} + /* Whenever we have a property change on a DbusmenuMenuitem we need to be responsive to that. */ static void menu_prop_change_cb (DbusmenuMenuitem * mi, gchar * prop, gchar * value, GtkMenuItem * gmi) { - if (!g_strcmp0(prop, "label")) { + if (!g_strcmp0(prop, DBUSMENU_MENUITEM_PROP_LABEL)) { gtk_menu_item_set_label(gmi, value); - gtk_widget_show(GTK_WIDGET(gmi)); + } else if (!g_strcmp0(prop, DBUSMENU_MENUITEM_PROP_VISIBLE)) { + process_visible(gmi, value); } return; @@ -157,6 +170,8 @@ base_new_menuitem (DbusmenuMenuitem * mi, GtkMenuItem * gmi, DbusmenuGtkClient * /* Life insurance */ g_object_weak_ref(G_OBJECT(mi), destoryed_dbusmenuitem_cb, gmi); + process_visible(gmi, dbusmenu_menuitem_property_get(mi, DBUSMENU_MENUITEM_PROP_VISIBLE)); + return; } @@ -271,7 +286,6 @@ new_item_normal (DbusmenuMenuitem * newitem, DbusmenuMenuitem * parent, Dbusmenu GtkMenuItem * gmi; gmi = GTK_MENU_ITEM(gtk_menu_item_new_with_label(dbusmenu_menuitem_property_get(newitem, "label"))); - gtk_widget_show(GTK_WIDGET(gmi)); base_new_menuitem(newitem, gmi, DBUSMENU_GTKCLIENT(client)); if (parent != NULL) { @@ -287,7 +301,6 @@ new_item_seperator (DbusmenuMenuitem * newitem, DbusmenuMenuitem * parent, Dbusm GtkMenuItem * gmi; gmi = GTK_MENU_ITEM(gtk_separator_menu_item_new()); - gtk_widget_show(GTK_WIDGET(gmi)); base_new_menuitem(newitem, gmi, DBUSMENU_GTKCLIENT(client)); if (parent != NULL) { -- cgit v1.2.3 From a5506477c08af6ecd1f15d898b737bdf69464c0d Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Wed, 26 Aug 2009 15:32:37 -0500 Subject: Making some separator tests and a visibility one as well. --- tests/test-gtk-label.json | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/tests/test-gtk-label.json b/tests/test-gtk-label.json index 4bb9e0e..19a6ca6 100644 --- a/tests/test-gtk-label.json +++ b/tests/test-gtk-label.json @@ -29,23 +29,23 @@ "submenu": [ {"id": 20, "type": "menuitem", "label": "value20"}, - {"id": 21, "type": "menuitem", + {"id": 21, "type": "separator", "label": "value21"}, {"id": 22, "type": "menuitem", "label": "value22"}, - {"id": 23, "type": "menuitem", + {"id": 23, "type": "separator", "label": "value23"}, {"id": 24, "type": "menuitem", "label": "value24"}, - {"id": 25, "type": "menuitem", + {"id": 25, "type": "separator", "label": "value25"}, {"id": 26, "type": "menuitem", "label": "value26"}, - {"id": 27, "type": "menuitem", + {"id": 27, "type": "separator", "label": "value27"}, {"id": 28, "type": "menuitem", "label": "value28"}, - {"id": 29, "type": "menuitem", + {"id": 29, "type": "menuitem", "visible": "false", "label": "value29"} ] }, -- cgit v1.2.3 From 9afd4dc68692b573582c3bd57489f9b5a541eb3a Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Wed, 26 Aug 2009 15:42:27 -0500 Subject: Adding in a default type handler, incase it's configured, but not set by clients. --- libdbusmenu-glib/client.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/libdbusmenu-glib/client.c b/libdbusmenu-glib/client.c index 0a80c6e..ffde8e3 100644 --- a/libdbusmenu-glib/client.c +++ b/libdbusmenu-glib/client.c @@ -550,6 +550,8 @@ menuitem_get_properties_new_cb (DBusGProxy * proxy, GHashTable * properties, GEr type = dbusmenu_menuitem_property_get(propdata->item, "type"); if (type != NULL) { newfunc = g_hash_table_lookup(priv->type_handlers, type); + } else { + newfunc = g_hash_table_lookup(priv->type_handlers, DBUSMENU_CLIENT_TYPES_DEFAULT); } if (newfunc != NULL) { -- cgit v1.2.3 From a7a3cd7d3ec49a25febf58d63b704a4b0287ad8e Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Wed, 26 Aug 2009 16:24:58 -0500 Subject: Having new children processed on realization --- libdbusmenu-gtk/menu.c | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/libdbusmenu-gtk/menu.c b/libdbusmenu-gtk/menu.c index 6e78a04..b6f8061 100644 --- a/libdbusmenu-gtk/menu.c +++ b/libdbusmenu-gtk/menu.c @@ -64,6 +64,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); /* Internal */ static void build_client (DbusmenuGtkMenu * self); +static void child_realized (DbusmenuMenuitem * child, gpointer userdata); /* GObject Stuff */ G_DEFINE_TYPE (DbusmenuGtkMenu, dbusmenu_gtkmenu, GTK_TYPE_MENU); @@ -188,9 +189,7 @@ static void root_child_added (DbusmenuMenuitem * root, DbusmenuMenuitem * child, guint position, DbusmenuGtkMenu * menu) { g_debug("Root new child"); - DbusmenuGtkMenuPrivate * priv = DBUSMENU_GTKMENU_GET_PRIVATE(menu); - gtk_menu_shell_insert(GTK_MENU_SHELL(menu), GTK_WIDGET(dbusmenu_gtkclient_menuitem_get(priv->client, child)), position); - gtk_widget_show(GTK_WIDGET(menu)); + g_signal_connect(G_OBJECT(child), DBUSMENU_MENUITEM_SIGNAL_REALIZED, G_CALLBACK(child_realized), menu); return; } -- cgit v1.2.3 From 29199629cd000bfdf33a911cf2971fcb9dad11dc Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Wed, 26 Aug 2009 16:31:40 -0500 Subject: We're going to need a new version for this change. --- configure.ac | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/configure.ac b/configure.ac index d259bef..950724c 100644 --- a/configure.ac +++ b/configure.ac @@ -5,7 +5,7 @@ AC_COPYRIGHT([Copyright 2009 Canonical]) AC_PREREQ(2.53) AM_CONFIG_HEADER(config.h) -AM_INIT_AUTOMAKE(libdbusmenu, 0.0.1) +AM_INIT_AUTOMAKE(libdbusmenu, 0.0.2) AM_MAINTAINER_MODE -- cgit v1.2.3 From b1e8c02ec17a79d89df08a5c7aedf0f5e46a2dfa Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Wed, 26 Aug 2009 16:58:46 -0500 Subject: Promoting the base function up to an API function so that it can be used else where. --- libdbusmenu-gtk/client.c | 34 ++++++++++++++++------------------ libdbusmenu-gtk/client.h | 2 ++ 2 files changed, 18 insertions(+), 18 deletions(-) diff --git a/libdbusmenu-gtk/client.c b/libdbusmenu-gtk/client.c index afa8bb3..54db5db 100644 --- a/libdbusmenu-gtk/client.c +++ b/libdbusmenu-gtk/client.c @@ -153,24 +153,28 @@ new_menuitem (DbusmenuClient * client, DbusmenuMenuitem * mi, gpointer userdata) return; } -static void -base_new_menuitem (DbusmenuMenuitem * mi, GtkMenuItem * gmi, DbusmenuGtkClient * client) +void +dbusmenu_gtkclient_newitem_base (DbusmenuGtkClient * client, DbusmenuMenuitem * item, GtkMenuItem * gmi, DbusmenuMenuitem * parent) { /* Attach these two */ - g_object_set_data(G_OBJECT(mi), data_menuitem, gmi); + g_object_set_data(G_OBJECT(item), data_menuitem, gmi); /* DbusmenuMenuitem signals */ - g_signal_connect(G_OBJECT(mi), DBUSMENU_MENUITEM_SIGNAL_PROPERTY_CHANGED, G_CALLBACK(menu_prop_change_cb), gmi); - g_signal_connect(G_OBJECT(mi), DBUSMENU_MENUITEM_SIGNAL_CHILD_REMOVED, G_CALLBACK(delete_child), client); - g_signal_connect(G_OBJECT(mi), DBUSMENU_MENUITEM_SIGNAL_CHILD_MOVED, G_CALLBACK(move_child), client); + g_signal_connect(G_OBJECT(item), DBUSMENU_MENUITEM_SIGNAL_PROPERTY_CHANGED, G_CALLBACK(menu_prop_change_cb), gmi); + g_signal_connect(G_OBJECT(item), DBUSMENU_MENUITEM_SIGNAL_CHILD_REMOVED, G_CALLBACK(delete_child), client); + g_signal_connect(G_OBJECT(item), DBUSMENU_MENUITEM_SIGNAL_CHILD_MOVED, G_CALLBACK(move_child), client); /* GtkMenuitem signals */ - g_signal_connect(G_OBJECT(gmi), "activate", G_CALLBACK(menu_pressed_cb), mi); + g_signal_connect(G_OBJECT(gmi), "activate", G_CALLBACK(menu_pressed_cb), item); /* Life insurance */ - g_object_weak_ref(G_OBJECT(mi), destoryed_dbusmenuitem_cb, gmi); + g_object_weak_ref(G_OBJECT(item), destoryed_dbusmenuitem_cb, gmi); + + process_visible(gmi, dbusmenu_menuitem_property_get(item, DBUSMENU_MENUITEM_PROP_VISIBLE)); - process_visible(gmi, dbusmenu_menuitem_property_get(mi, DBUSMENU_MENUITEM_PROP_VISIBLE)); + if (parent != NULL) { + new_child(parent, item, dbusmenu_menuitem_get_position(item, parent), DBUSMENU_GTKCLIENT(client)); + } return; } @@ -285,12 +289,9 @@ new_item_normal (DbusmenuMenuitem * newitem, DbusmenuMenuitem * parent, Dbusmenu { GtkMenuItem * gmi; - gmi = GTK_MENU_ITEM(gtk_menu_item_new_with_label(dbusmenu_menuitem_property_get(newitem, "label"))); + gmi = GTK_MENU_ITEM(gtk_menu_item_new_with_label(dbusmenu_menuitem_property_get(newitem, DBUSMENU_MENUITEM_PROP_LABEL))); - base_new_menuitem(newitem, gmi, DBUSMENU_GTKCLIENT(client)); - if (parent != NULL) { - new_child(parent, newitem, dbusmenu_menuitem_get_position(newitem, parent), DBUSMENU_GTKCLIENT(client)); - } + dbusmenu_gtkclient_newitem_base(DBUSMENU_GTKCLIENT(client), newitem, gmi, parent); return TRUE; } @@ -302,10 +303,7 @@ new_item_seperator (DbusmenuMenuitem * newitem, DbusmenuMenuitem * parent, Dbusm gmi = GTK_MENU_ITEM(gtk_separator_menu_item_new()); - base_new_menuitem(newitem, gmi, DBUSMENU_GTKCLIENT(client)); - if (parent != NULL) { - new_child(parent, newitem, dbusmenu_menuitem_get_position(newitem, parent), DBUSMENU_GTKCLIENT(client)); - } + dbusmenu_gtkclient_newitem_base(DBUSMENU_GTKCLIENT(client), newitem, gmi, parent); return TRUE; } diff --git a/libdbusmenu-gtk/client.h b/libdbusmenu-gtk/client.h index a549fe0..b1d816f 100644 --- a/libdbusmenu-gtk/client.h +++ b/libdbusmenu-gtk/client.h @@ -79,6 +79,8 @@ GType dbusmenu_gtkclient_get_type (void); DbusmenuGtkClient * dbusmenu_gtkclient_new (gchar * dbus_name, gchar * dbus_object); GtkMenuItem * dbusmenu_gtkclient_menuitem_get (DbusmenuGtkClient * client, DbusmenuMenuitem * item); +void dbusmenu_gtkclient_newitem_base (DbusmenuGtkClient * client, DbusmenuMenuitem * item, GtkMenuItem * gmi, DbusmenuMenuitem * parent); + /** SECTION:gtkmenu @short_description: A GTK Menu Object that syncronizes over DBus -- cgit v1.2.3 From c2a08568e054ace4d5cf6425e6fb0924ab4d2129 Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Wed, 26 Aug 2009 17:22:50 -0500 Subject: Adding a public accessor for getting the gtk client --- libdbusmenu-gtk/menu.c | 16 ++++++++++++++++ libdbusmenu-gtk/menu.h | 2 ++ 2 files changed, 18 insertions(+) diff --git a/libdbusmenu-gtk/menu.c b/libdbusmenu-gtk/menu.c index b6f8061..92cd13b 100644 --- a/libdbusmenu-gtk/menu.c +++ b/libdbusmenu-gtk/menu.c @@ -289,3 +289,19 @@ dbusmenu_gtkmenu_new (gchar * dbus_name, gchar * dbus_object) NULL); } +/** + dbusmenu_gtkmenu_get_client: + @menu: The #DbusmenuGtkMenu to get the client from + + An accessor for the client that this menu is using to + communicate with the server. + + Return value: A valid #DbusmenuGtkClient or NULL on error. +*/ +DbusmenuGtkClient * +dbusmenu_gtkmenu_get_client (DbusmenuGtkMenu * menu) +{ + g_return_val_if_fail(DBUSMENU_IS_GTKMENU(menu), NULL); + DbusmenuGtkMenuPrivate * priv = DBUSMENU_GTKMENU_GET_PRIVATE(menu); + return priv->client; +} diff --git a/libdbusmenu-gtk/menu.h b/libdbusmenu-gtk/menu.h index 73804c5..5147d30 100644 --- a/libdbusmenu-gtk/menu.h +++ b/libdbusmenu-gtk/menu.h @@ -31,6 +31,7 @@ License version 3 and version 2.1 along with this program. If not, see #include #include +#include "client.h" G_BEGIN_DECLS @@ -71,6 +72,7 @@ struct _DbusmenuGtkMenu { GType dbusmenu_gtkmenu_get_type (void); DbusmenuGtkMenu * dbusmenu_gtkmenu_new (gchar * dbus_name, gchar * dbus_object); +DbusmenuGtkClient * dbusmenu_gtkmenu_get_client (DbusmenuGtkMenu * menu); /** SECTION:gtkmenu -- cgit v1.2.3 From 287122c696ddf0cc0e00a0f7e39663024aaf5e6d Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Thu, 27 Aug 2009 08:30:16 -0500 Subject: Comment for Neil. Checking data. --- libdbusmenu-glib/client.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/libdbusmenu-glib/client.c b/libdbusmenu-glib/client.c index ffde8e3..9004f55 100644 --- a/libdbusmenu-glib/client.c +++ b/libdbusmenu-glib/client.c @@ -537,6 +537,8 @@ menuitem_get_properties_cb (DBusGProxy * proxy, GHashTable * properties, GError static void menuitem_get_properties_new_cb (DBusGProxy * proxy, GHashTable * properties, GError * error, gpointer data) { + g_return_if_fail(data != NULL); + newItemPropData * propdata = (newItemPropData *)data; DbusmenuClientPrivate * priv = DBUSMENU_CLIENT_GET_PRIVATE(propdata->client); -- cgit v1.2.3 From 084decde9945791e7116a16876aabb1788049616 Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Thu, 27 Aug 2009 08:34:46 -0500 Subject: Check the return of g_new0 for NULL. Comment by Neil. --- libdbusmenu-glib/client.c | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/libdbusmenu-glib/client.c b/libdbusmenu-glib/client.c index 9004f55..92c7aa9 100644 --- a/libdbusmenu-glib/client.c +++ b/libdbusmenu-glib/client.c @@ -622,11 +622,15 @@ parse_layout_xml(DbusmenuClient * client, xmlNodePtr node, DbusmenuMenuitem * it /* Get the properties queued up for this item */ /* Not happy about this, but I need these :( */ newItemPropData * propdata = g_new0(newItemPropData, 1); - propdata->client = client; - propdata->item = item; - propdata->parent = parent; - - org_freedesktop_dbusmenu_get_properties_async(proxy, id, menuitem_get_properties_new_cb, propdata); + if (propdata != NULL) { + propdata->client = client; + propdata->item = item; + propdata->parent = parent; + + org_freedesktop_dbusmenu_get_properties_async(proxy, id, menuitem_get_properties_new_cb, propdata); + } else { + g_warning("Unable to allocate memory to get properties for menuitem. This menuitem will never be realized."); + } } xmlNodePtr children; -- cgit v1.2.3 From 84c3e9454452203fec2bbff80a25028391360aac Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Thu, 27 Aug 2009 08:36:58 -0500 Subject: Making sure that type is not NULL. Comment from Neil. --- libdbusmenu-glib/client.c | 1 + 1 file changed, 1 insertion(+) diff --git a/libdbusmenu-glib/client.c b/libdbusmenu-glib/client.c index 92c7aa9..dd2254e 100644 --- a/libdbusmenu-glib/client.c +++ b/libdbusmenu-glib/client.c @@ -836,6 +836,7 @@ gboolean dbusmenu_client_add_type_handler (DbusmenuClient * client, const gchar * type, DbusmenuClientTypeHandler newfunc) { g_return_val_if_fail(DBUSMENU_IS_CLIENT(client), FALSE); + g_return_val_if_fail(type != NULL, FALSE); DbusmenuClientPrivate * priv = DBUSMENU_CLIENT_GET_PRIVATE(client); -- cgit v1.2.3 From 86b7b92f7f45eb77ce648a9fae5d48c3d0e02632 Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Thu, 27 Aug 2009 08:45:49 -0500 Subject: Adding checks to the type handling functions in GTK+ version of the lib. Comments by Neil. --- libdbusmenu-gtk/client.c | 22 ++++++++++++++++++---- 1 file changed, 18 insertions(+), 4 deletions(-) diff --git a/libdbusmenu-gtk/client.c b/libdbusmenu-gtk/client.c index 54db5db..7271c37 100644 --- a/libdbusmenu-gtk/client.c +++ b/libdbusmenu-gtk/client.c @@ -287,11 +287,18 @@ dbusmenu_gtkclient_menuitem_get (DbusmenuGtkClient * client, DbusmenuMenuitem * static gboolean new_item_normal (DbusmenuMenuitem * newitem, DbusmenuMenuitem * parent, DbusmenuClient * client) { - GtkMenuItem * gmi; + g_return_val_if_fail(DBUSMENU_IS_MENUITEM(newitem), FALSE); + g_return_val_if_fail(DBUSMENU_IS_GTKCLIENT(client), FALSE); + /* Note: not checking parent, it's reasonable for it to be NULL */ + GtkMenuItem * gmi; gmi = GTK_MENU_ITEM(gtk_menu_item_new_with_label(dbusmenu_menuitem_property_get(newitem, DBUSMENU_MENUITEM_PROP_LABEL))); - dbusmenu_gtkclient_newitem_base(DBUSMENU_GTKCLIENT(client), newitem, gmi, parent); + if (gmi != NULL) { + dbusmenu_gtkclient_newitem_base(DBUSMENU_GTKCLIENT(client), newitem, gmi, parent); + } else { + return FALSE; + } return TRUE; } @@ -299,11 +306,18 @@ new_item_normal (DbusmenuMenuitem * newitem, DbusmenuMenuitem * parent, Dbusmenu static gboolean new_item_seperator (DbusmenuMenuitem * newitem, DbusmenuMenuitem * parent, DbusmenuClient * client) { - GtkMenuItem * gmi; + g_return_val_if_fail(DBUSMENU_IS_MENUITEM(newitem), FALSE); + g_return_val_if_fail(DBUSMENU_IS_GTKCLIENT(client), FALSE); + /* Note: not checking parent, it's reasonable for it to be NULL */ + GtkMenuItem * gmi; gmi = GTK_MENU_ITEM(gtk_separator_menu_item_new()); - dbusmenu_gtkclient_newitem_base(DBUSMENU_GTKCLIENT(client), newitem, gmi, parent); + if (gmi != NULL) { + dbusmenu_gtkclient_newitem_base(DBUSMENU_GTKCLIENT(client), newitem, gmi, parent); + } else { + return FALSE; + } return TRUE; } -- cgit v1.2.3 From 9e5b9b3ce66ff01c8395ea28bc227bb34cb50f8e Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Thu, 27 Aug 2009 08:49:11 -0500 Subject: Checking the menu is a GTK menu before casting it. Comments by Neil. --- libdbusmenu-gtk/menu.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/libdbusmenu-gtk/menu.c b/libdbusmenu-gtk/menu.c index 92cd13b..74e1bec 100644 --- a/libdbusmenu-gtk/menu.c +++ b/libdbusmenu-gtk/menu.c @@ -215,6 +215,8 @@ root_child_delete (DbusmenuMenuitem * root, DbusmenuMenuitem * child, DbusmenuGt static void child_realized (DbusmenuMenuitem * child, gpointer userdata) { + g_return_if_fail(DBUSMENU_IS_GTKMENU(userdata)); + DbusmenuGtkMenu * menu = DBUSMENU_GTKMENU(userdata); DbusmenuGtkMenuPrivate * priv = DBUSMENU_GTKMENU_GET_PRIVATE(menu); -- cgit v1.2.3