diff options
Diffstat (limited to 'libdbusmenu-glib')
-rw-r--r-- | libdbusmenu-glib/client.c | 105 | ||||
-rw-r--r-- | libdbusmenu-glib/client.h | 17 | ||||
-rw-r--r-- | libdbusmenu-glib/menuitem.c | 17 | ||||
-rw-r--r-- | libdbusmenu-glib/menuitem.h | 11 |
4 files changed, 144 insertions, 6 deletions
diff --git a/libdbusmenu-glib/client.c b/libdbusmenu-glib/client.c index 212071b..0a80c6e 100644 --- a/libdbusmenu-glib/client.c +++ b/libdbusmenu-glib/client.c @@ -68,6 +68,16 @@ struct _DbusmenuClientPrivate DBusGProxyCall * layoutcall; DBusGProxy * dbusproxy; + + GHashTable * type_handlers; +}; + +typedef struct _newItemPropData newItemPropData; +struct _newItemPropData +{ + DbusmenuClient * client; + DbusmenuMenuitem * item; + DbusmenuMenuitem * parent; }; #define DBUSMENU_CLIENT_GET_PRIVATE(o) \ @@ -187,6 +197,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 +243,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 +532,41 @@ 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) +{ + newItemPropData * propdata = (newItemPropData *)data; + DbusmenuClientPrivate * priv = DBUSMENU_CLIENT_GET_PRIVATE(propdata->client); + + menuitem_get_properties_cb (proxy, properties, error, propdata->item); + + gboolean handled = FALSE; + + const gchar * type; + DbusmenuClientTypeHandler newfunc = NULL; + + 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(propdata->item, propdata->parent, propdata->client); + } + + 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); + } + + g_free(propdata); + + return; +} + static void menuitem_call_cb (DBusGProxy * proxy, GError * error, gpointer userdata) { @@ -562,9 +614,15 @@ 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 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); } xmlNodePtr children; @@ -744,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 == NULL) { + 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; +} diff --git a/libdbusmenu-glib/client.h b/libdbusmenu-glib/client.h index 35f7122..fff9a6b 100644 --- a/libdbusmenu-glib/client.h +++ b/libdbusmenu-glib/client.h @@ -50,10 +50,15 @@ 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_SEPARATOR "separator" +#define DBUSMENU_CLIENT_TYPES_IMAGE "imageitem" + /** 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. @@ -90,9 +95,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 gboolean (*DbusmenuClientTypeHandler) (DbusmenuMenuitem * newitem, DbusmenuMenuitem * parent, DbusmenuClient * client); + +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 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..7806017 100644 --- a/libdbusmenu-glib/menuitem.h +++ b/libdbusmenu-glib/menuitem.h @@ -47,6 +47,13 @@ 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" +#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: @@ -71,6 +78,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 +97,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 +105,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); |