diff options
author | Ted Gould <ted@canonical.com> | 2009-08-25 14:47:43 -0500 |
---|---|---|
committer | Ted Gould <ted@canonical.com> | 2009-08-25 14:47:43 -0500 |
commit | d5e159567d782bfd8568d9075bea32264f326dff (patch) | |
tree | d1831664616755b58c453aead722f182feca9cc6 | |
parent | 780e2c229e24e20c026219ce6e87533092a172b2 (diff) | |
download | libdbusmenu-d5e159567d782bfd8568d9075bea32264f326dff.tar.gz libdbusmenu-d5e159567d782bfd8568d9075bea32264f326dff.tar.bz2 libdbusmenu-d5e159567d782bfd8568d9075bea32264f326dff.zip |
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.
-rw-r--r-- | libdbusmenu-glib/client.c | 43 |
1 files changed, 43 insertions, 0 deletions
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; +} |