Merge authors: Ted Gould (ted) Related merge proposals: https://code.launchpad.net/~ted/dbusmenu/generic-signal-menuitem/+merge/18586 proposed by: Ted Gould (ted) review: Approve - David Barth (dbarth) ------------------------------------------------------------ revno: 59 [merge] committer: Ted Gould <[email protected]> branch nick: trunk timestamp: Wed 2010-02-03 18:47:30 -0800 message: Adding support for having generic signals in the menuitems. Moving 'clicked' to GTK. added: libdbusmenu-glib/client-menuitem.c libdbusmenu-glib/client-menuitem.h modified: libdbusmenu-glib/Makefile.am libdbusmenu-glib/client.c libdbusmenu-glib/client.h libdbusmenu-glib/menuitem.c libdbusmenu-glib/menuitem.h libdbusmenu-glib/server.c libdbusmenu-gtk/client.c
-- lp:dbusmenu https://code.launchpad.net/~dbusmenu-team/dbusmenu/trunk Your team ayatana-commits is subscribed to branch lp:dbusmenu. To unsubscribe from this branch go to https://code.launchpad.net/~dbusmenu-team/dbusmenu/trunk/+edit-subscription.
=== modified file 'libdbusmenu-glib/Makefile.am' --- libdbusmenu-glib/Makefile.am 2009-11-13 18:02:08 +0000 +++ libdbusmenu-glib/Makefile.am 2010-02-04 02:00:36 +0000 @@ -27,6 +27,8 @@ server.c \ server-marshal.h \ server-marshal.c \ + client-menuitem.h \ + client-menuitem.c \ client.h \ client.c === added file 'libdbusmenu-glib/client-menuitem.c' --- libdbusmenu-glib/client-menuitem.c 1970-01-01 00:00:00 +0000 +++ libdbusmenu-glib/client-menuitem.c 2010-02-04 02:45:12 +0000 @@ -0,0 +1,106 @@ +/* +A small subclass of the menuitem for using clients. + +Copyright 2010 Canonical Ltd. + +Authors: + Ted Gould <[email protected]> + +This program is free software: you can redistribute it and/or modify it +under the terms of either or both of the following licenses: + +1) the GNU Lesser General Public License version 3, as published by the +Free Software Foundation; and/or +2) the GNU Lesser General Public License version 2.1, as published by +the Free Software Foundation. + +This program is distributed in the hope that it will be useful, but +WITHOUT ANY WARRANTY; without even the implied warranties of +MERCHANTABILITY, SATISFACTORY QUALITY or FITNESS FOR A PARTICULAR +PURPOSE. See the applicable version of the GNU Lesser General Public +License for more details. + +You should have received a copy of both the GNU Lesser General Public +License version 3 and version 2.1 along with this program. If not, see +<http://www.gnu.org/licenses/> +*/ + +#ifdef HAVE_CONFIG_H +#include "config.h" +#endif + +#include "client-menuitem.h" + +typedef struct _DbusmenuClientMenuitemPrivate DbusmenuClientMenuitemPrivate; + +struct _DbusmenuClientMenuitemPrivate +{ + DbusmenuClient * client; +}; + +#define DBUSMENU_CLIENT_MENUITEM_GET_PRIVATE(o) \ +(G_TYPE_INSTANCE_GET_PRIVATE ((o), DBUSMENU_CLIENT_MENUITEM_TYPE, DbusmenuClientMenuitemPrivate)) + +static void dbusmenu_client_menuitem_class_init (DbusmenuClientMenuitemClass *klass); +static void dbusmenu_client_menuitem_init (DbusmenuClientMenuitem *self); +static void dbusmenu_client_menuitem_dispose (GObject *object); +static void dbusmenu_client_menuitem_finalize (GObject *object); +static void handle_event (DbusmenuMenuitem * mi, const gchar * name, const GValue * value, guint timestamp); + +G_DEFINE_TYPE (DbusmenuClientMenuitem, dbusmenu_client_menuitem, DBUSMENU_TYPE_MENUITEM); + +static void +dbusmenu_client_menuitem_class_init (DbusmenuClientMenuitemClass *klass) +{ + GObjectClass *object_class = G_OBJECT_CLASS (klass); + + g_type_class_add_private (klass, sizeof (DbusmenuClientMenuitemPrivate)); + + object_class->dispose = dbusmenu_client_menuitem_dispose; + object_class->finalize = dbusmenu_client_menuitem_finalize; + + DbusmenuMenuitemClass * mclass = DBUSMENU_MENUITEM_CLASS(klass); + mclass->handle_event = handle_event; + + return; +} + +static void +dbusmenu_client_menuitem_init (DbusmenuClientMenuitem *self) +{ + + return; +} + +static void +dbusmenu_client_menuitem_dispose (GObject *object) +{ + + G_OBJECT_CLASS (dbusmenu_client_menuitem_parent_class)->dispose (object); + return; +} + +static void +dbusmenu_client_menuitem_finalize (GObject *object) +{ + + G_OBJECT_CLASS (dbusmenu_client_menuitem_parent_class)->finalize (object); + return; +} + +DbusmenuClientMenuitem * +dbusmenu_client_menuitem_new (gint id, DbusmenuClient * client) +{ + DbusmenuClientMenuitem * mi = g_object_new(DBUSMENU_CLIENT_MENUITEM_TYPE, "id", id, NULL); + DbusmenuClientMenuitemPrivate * priv = DBUSMENU_CLIENT_MENUITEM_GET_PRIVATE(mi); + priv->client = client; + return mi; +} + +static void +handle_event (DbusmenuMenuitem * mi, const gchar * name, const GValue * value, guint timestamp) +{ + DbusmenuClientMenuitemPrivate * priv = DBUSMENU_CLIENT_MENUITEM_GET_PRIVATE(mi); + dbusmenu_client_send_event(priv->client, dbusmenu_menuitem_get_id(mi), name, value, timestamp); + return; +} === added file 'libdbusmenu-glib/client-menuitem.h' --- libdbusmenu-glib/client-menuitem.h 1970-01-01 00:00:00 +0000 +++ libdbusmenu-glib/client-menuitem.h 2010-02-04 02:45:12 +0000 @@ -0,0 +1,61 @@ +/* +A small subclass of the menuitem for using clients. + +Copyright 2010 Canonical Ltd. + +Authors: + Ted Gould <[email protected]> + +This program is free software: you can redistribute it and/or modify it +under the terms of either or both of the following licenses: + +1) the GNU Lesser General Public License version 3, as published by the +Free Software Foundation; and/or +2) the GNU Lesser General Public License version 2.1, as published by +the Free Software Foundation. + +This program is distributed in the hope that it will be useful, but +WITHOUT ANY WARRANTY; without even the implied warranties of +MERCHANTABILITY, SATISFACTORY QUALITY or FITNESS FOR A PARTICULAR +PURPOSE. See the applicable version of the GNU Lesser General Public +License for more details. + +You should have received a copy of both the GNU Lesser General Public +License version 3 and version 2.1 along with this program. If not, see +<http://www.gnu.org/licenses/> +*/ + +#ifndef __DBUSMENU_CLIENT_MENUITEM_H__ +#define __DBUSMENU_CLIENT_MENUITEM_H__ + +#include <glib.h> +#include <glib-object.h> +#include "menuitem.h" +#include "client.h" + +G_BEGIN_DECLS + +#define DBUSMENU_CLIENT_MENUITEM_TYPE (dbusmenu_client_menuitem_get_type ()) +#define DBUSMENU_CLIENT_MENUITEM(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), DBUSMENU_CLIENT_MENUITEM_TYPE, DbusmenuClientMenuitem)) +#define DBUSMENU_CLIENT_MENUITEM_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), DBUSMENU_CLIENT_MENUITEM_TYPE, DbusmenuClientMenuitemClass)) +#define DBUSMENU_IS_CLIENT_MENUITEM(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), DBUSMENU_CLIENT_MENUITEM_TYPE)) +#define DBUSMENU_IS_CLIENT_MENUITEM_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), DBUSMENU_CLIENT_MENUITEM_TYPE)) +#define DBUSMENU_CLIENT_MENUITEM_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), DBUSMENU_CLIENT_MENUITEM_TYPE, DbusmenuClientMenuitemClass)) + +typedef struct _DbusmenuClientMenuitem DbusmenuClientMenuitem; +typedef struct _DbusmenuClientMenuitemClass DbusmenuClientMenuitemClass; + +struct _DbusmenuClientMenuitemClass { + DbusmenuMenuitemClass parent_class; +}; + +struct _DbusmenuClientMenuitem { + DbusmenuMenuitem parent; +}; + +GType dbusmenu_client_menuitem_get_type (void); +DbusmenuClientMenuitem * dbusmenu_client_menuitem_new (gint id, DbusmenuClient * client); + +G_END_DECLS + +#endif === modified file 'libdbusmenu-glib/client.c' --- libdbusmenu-glib/client.c 2010-01-24 20:08:51 +0000 +++ libdbusmenu-glib/client.c 2010-02-04 02:09:57 +0000 @@ -35,6 +35,7 @@ #include "client.h" #include "menuitem.h" +#include "client-menuitem.h" #include "dbusmenu-client.h" #include "server-marshal.h" @@ -626,14 +627,11 @@ return; } -static void -menuitem_activate (DbusmenuMenuitem * mi, DbusmenuClient * client) +void +dbusmenu_client_send_event (DbusmenuClient * client, gint id, const gchar * name, const GValue * value, guint timestamp) { DbusmenuClientPrivate * priv = DBUSMENU_CLIENT_GET_PRIVATE(client); - GValue value = {0}; - g_value_init(&value, G_TYPE_INT); - g_value_set_int(&value, 0); - org_ayatana_dbusmenu_event_async (priv->menuproxy, dbusmenu_menuitem_get_id(mi), "clicked", &value, 0, menuitem_call_cb, mi); + org_ayatana_dbusmenu_event_async (priv->menuproxy, id, name, value, timestamp, menuitem_call_cb, GINT_TO_POINTER(id)); return; } @@ -661,11 +659,10 @@ } /* Build a new item */ - item = dbusmenu_menuitem_new_with_id(id); + item = DBUSMENU_MENUITEM(dbusmenu_client_menuitem_new(id, client)); if (parent == NULL) { dbusmenu_menuitem_set_root(item, TRUE); } - 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 these :( */ === modified file 'libdbusmenu-glib/client.h' --- libdbusmenu-glib/client.h 2009-12-10 04:57:31 +0000 +++ libdbusmenu-glib/client.h 2010-02-04 02:09:57 +0000 @@ -104,6 +104,11 @@ gboolean dbusmenu_client_add_type_handler (DbusmenuClient * client, const gchar * type, DbusmenuClientTypeHandler newfunc); +void dbusmenu_client_send_event (DbusmenuClient * client, + gint id, + const gchar * name, + const GValue * value, + guint timestamp); /** SECTION:client === modified file 'libdbusmenu-glib/menuitem.c' --- libdbusmenu-glib/menuitem.c 2010-01-22 20:53:39 +0000 +++ libdbusmenu-glib/menuitem.c 2010-02-04 01:36:50 +0000 @@ -92,6 +92,7 @@ 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 @@ 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 @@ 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 */ @@ -1116,21 +1129,35 @@ } /** - 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); + } return; } === modified file 'libdbusmenu-glib/menuitem.h' --- libdbusmenu-glib/menuitem.h 2010-01-22 20:10:27 +0000 +++ libdbusmenu-glib/menuitem.h 2010-02-04 01:31:17 +0000 @@ -92,6 +92,9 @@ @realized: Slot for #DbusmenuMenuitem::realized. @buildxml: Virtual function that appends the strings required to represent this menu item in the menu XML file. + @handle_event: This function is to override how events are handled + by subclasses. Look at #dbusmenu_menuitem_handle_event for + lots of good information. @reserved1: Reserved for future use. @reserved2: Reserved for future use. @reserved3: Reserved for future use. @@ -112,10 +115,11 @@ /* Virtual functions */ void (*buildxml) (GPtrArray * stringarray); + void (*handle_event) (DbusmenuMenuitem * mi, const gchar * name, const GValue * value, guint timestamp); void (*reserved1) (void); void (*reserved2) (void); - void (*reserved3) (void); + /* void (*reserved3) (void); */ /* void (*reserved4) (void); -- realized, realloc when bumping lib version */ }; @@ -153,7 +157,7 @@ gboolean dbusmenu_menuitem_get_root (DbusmenuMenuitem * mi); void dbusmenu_menuitem_foreach (DbusmenuMenuitem * mi, void (*func) (DbusmenuMenuitem * mi, gpointer data), gpointer data); -void dbusmenu_menuitem_activate (DbusmenuMenuitem * mi, guint timestamp); +void dbusmenu_menuitem_handle_event (DbusmenuMenuitem * mi, const gchar * name, const GValue * value, guint timestamp); /** SECTION:menuitem === modified file 'libdbusmenu-glib/server.c' --- libdbusmenu-glib/server.c 2010-01-24 20:08:51 +0000 +++ libdbusmenu-glib/server.c 2010-02-04 01:38:11 +0000 @@ -553,7 +553,7 @@ return FALSE; } - dbusmenu_menuitem_activate(mi, timestamp); + dbusmenu_menuitem_handle_event(mi, eventid, data, timestamp); return TRUE; } === modified file 'libdbusmenu-gtk/client.c' --- libdbusmenu-gtk/client.c 2010-01-24 20:09:10 +0000 +++ libdbusmenu-gtk/client.c 2010-02-04 02:11:22 +0000 @@ -109,7 +109,10 @@ static gboolean menu_pressed_cb (GtkMenuItem * gmi, DbusmenuMenuitem * mi) { - dbusmenu_menuitem_activate(mi, gtk_get_current_event_time()); + GValue value = {0}; + g_value_init(&value, G_TYPE_INT); + g_value_set_int(&value, 0); + dbusmenu_menuitem_handle_event(mi, "clicked", &value, gtk_get_current_event_time()); return TRUE; }
_______________________________________________ Mailing list: https://launchpad.net/~ayatana-commits Post to : [email protected] Unsubscribe : https://launchpad.net/~ayatana-commits More help : https://help.launchpad.net/ListHelp

