aboutsummaryrefslogtreecommitdiff
path: root/libdbusmenu-glib
diff options
context:
space:
mode:
Diffstat (limited to 'libdbusmenu-glib')
-rw-r--r--libdbusmenu-glib/Makefile.am2
-rw-r--r--libdbusmenu-glib/client-menuitem.c106
-rw-r--r--libdbusmenu-glib/client-menuitem.h61
-rw-r--r--libdbusmenu-glib/client.c13
-rw-r--r--libdbusmenu-glib/client.h5
-rw-r--r--libdbusmenu-glib/menuitem.c35
-rw-r--r--libdbusmenu-glib/menuitem.h8
-rw-r--r--libdbusmenu-glib/server.c2
8 files changed, 217 insertions, 15 deletions
diff --git a/libdbusmenu-glib/Makefile.am b/libdbusmenu-glib/Makefile.am
index fc37019..998af50 100644
--- a/libdbusmenu-glib/Makefile.am
+++ b/libdbusmenu-glib/Makefile.am
@@ -27,6 +27,8 @@ libdbusmenu_glib_la_SOURCES = \
server.c \
server-marshal.h \
server-marshal.c \
+ client-menuitem.h \
+ client-menuitem.c \
client.h \
client.c
diff --git a/libdbusmenu-glib/client-menuitem.c b/libdbusmenu-glib/client-menuitem.c
new file mode 100644
index 0000000..5d16a66
--- /dev/null
+++ b/libdbusmenu-glib/client-menuitem.c
@@ -0,0 +1,106 @@
+/*
+A small subclass of the menuitem for using clients.
+
+Copyright 2010 Canonical Ltd.
+
+Authors:
+ Ted Gould <ted@canonical.com>
+
+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;
+}
diff --git a/libdbusmenu-glib/client-menuitem.h b/libdbusmenu-glib/client-menuitem.h
new file mode 100644
index 0000000..ef61213
--- /dev/null
+++ b/libdbusmenu-glib/client-menuitem.h
@@ -0,0 +1,61 @@
+/*
+A small subclass of the menuitem for using clients.
+
+Copyright 2010 Canonical Ltd.
+
+Authors:
+ Ted Gould <ted@canonical.com>
+
+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
diff --git a/libdbusmenu-glib/client.c b/libdbusmenu-glib/client.c
index dbe7b3c..0f7fd65 100644
--- a/libdbusmenu-glib/client.c
+++ b/libdbusmenu-glib/client.c
@@ -35,6 +35,7 @@ License version 3 and version 2.1 along with this program. If not, see
#include "client.h"
#include "menuitem.h"
+#include "client-menuitem.h"
#include "dbusmenu-client.h"
#include "server-marshal.h"
@@ -626,14 +627,11 @@ menuitem_call_cb (DBusGProxy * proxy, GError * error, gpointer userdata)
return;
}
-static void
-menuitem_activate (DbusmenuMenuitem * mi, uint timestamp, 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;
}
@@ -659,11 +657,10 @@ parse_layout_xml(DbusmenuClient * client, xmlNodePtr node, DbusmenuMenuitem * it
}
/* 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 :( */
diff --git a/libdbusmenu-glib/client.h b/libdbusmenu-glib/client.h
index 15192f4..3909578 100644
--- a/libdbusmenu-glib/client.h
+++ b/libdbusmenu-glib/client.h
@@ -104,6 +104,11 @@ DbusmenuMenuitem * dbusmenu_client_get_root (DbusmenuClient * client)
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
diff --git a/libdbusmenu-glib/menuitem.c b/libdbusmenu-glib/menuitem.c
index 8198929..14bc2db 100644
--- a/libdbusmenu-glib/menuitem.c
+++ b/libdbusmenu-glib/menuitem.c
@@ -92,6 +92,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);
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 @@ dbusmenu_menuitem_class_init (DbusmenuMenuitemClass *klass)
object_class->set_property = set_property;
object_class->get_property = get_property;
+ klass->handle_event = handle_event;
+
/**
DbusmenuMenuitem::property-changed:
@arg0: The #DbusmenuMenuitem object.
@@ -339,6 +342,16 @@ get_property (GObject * obj, guint id, GValue * value, GParamSpec * pspec)
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 */
@@ -1113,21 +1126,35 @@ dbusmenu_menuitem_foreach (DbusmenuMenuitem * mi, void (*func) (DbusmenuMenuitem
}
/**
- 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;
}
diff --git a/libdbusmenu-glib/menuitem.h b/libdbusmenu-glib/menuitem.h
index 45445c6..4fc144e 100644
--- a/libdbusmenu-glib/menuitem.h
+++ b/libdbusmenu-glib/menuitem.h
@@ -92,6 +92,9 @@ struct _DbusmenuMenuitem
@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 @@ struct _DbusmenuMenuitemClass
/* 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 @@ void dbusmenu_menuitem_set_root (DbusmenuMenuitem * mi, gboolean root);
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
diff --git a/libdbusmenu-glib/server.c b/libdbusmenu-glib/server.c
index b6eb7aa..9d84750 100644
--- a/libdbusmenu-glib/server.c
+++ b/libdbusmenu-glib/server.c
@@ -553,7 +553,7 @@ _dbusmenu_server_event (DbusmenuServer * server, gint id, gchar * eventid, GValu
return FALSE;
}
- dbusmenu_menuitem_activate(mi, timestamp);
+ dbusmenu_menuitem_handle_event(mi, eventid, data, timestamp);
return TRUE;
}