aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--.bzrignore3
-rw-r--r--configure.ac6
-rw-r--r--libdbusmenu-glib/client-marshal.list1
-rw-r--r--libdbusmenu-glib/client.c65
-rw-r--r--libdbusmenu-glib/client.h8
-rw-r--r--libdbusmenu-gtk/client.c15
-rw-r--r--tests/Makefile.am34
-rw-r--r--tests/test-glib-events-client.c140
-rw-r--r--tests/test-glib-events-server.c102
-rw-r--r--tests/test-gtk-label-client.c2
10 files changed, 357 insertions, 19 deletions
diff --git a/.bzrignore b/.bzrignore
index b21c55f..c1088c1 100644
--- a/.bzrignore
+++ b/.bzrignore
@@ -191,3 +191,6 @@ tests/test-json
libdbusmenu-glib/client-marshal.c
libdbusmenu-glib/client-marshal.h
libdbusmenu-glib/libdbusmenu_glib_la-client-marshal.lo
+tests/test-glib-events
+tests/test-glib-events-client
+tests/test-glib-events-server
diff --git a/configure.ac b/configure.ac
index a5c8248..5ccf9c3 100644
--- a/configure.ac
+++ b/configure.ac
@@ -1,11 +1,11 @@
-AC_INIT(libdbusmenu, 0.3.11, ted@canonical.com)
+AC_INIT(libdbusmenu, 0.3.12, ted@canonical.com)
AC_COPYRIGHT([Copyright 2009,2010 Canonical])
AC_PREREQ(2.62)
AM_CONFIG_HEADER(config.h)
-AM_INIT_AUTOMAKE(libdbusmenu, 0.3.11, [-Wno-portability])
+AM_INIT_AUTOMAKE(libdbusmenu, 0.3.12, [-Wno-portability])
AM_MAINTAINER_MODE
@@ -99,7 +99,7 @@ AC_PATH_PROG([VALA_API_GEN], [vapigen])
###########################
LIBDBUSMENU_CURRENT=1
-LIBDBUSMENU_REVISION=13
+LIBDBUSMENU_REVISION=14
LIBDBUSMENU_AGE=0
AC_SUBST(LIBDBUSMENU_CURRENT)
diff --git a/libdbusmenu-glib/client-marshal.list b/libdbusmenu-glib/client-marshal.list
index 34e3956..2e14491 100644
--- a/libdbusmenu-glib/client-marshal.list
+++ b/libdbusmenu-glib/client-marshal.list
@@ -1 +1,2 @@
VOID: OBJECT, UINT
+VOID: OBJECT, STRING, POINTER, UINT, POINTER
diff --git a/libdbusmenu-glib/client.c b/libdbusmenu-glib/client.c
index d88478c..ca16c9a 100644
--- a/libdbusmenu-glib/client.c
+++ b/libdbusmenu-glib/client.c
@@ -56,6 +56,7 @@ enum {
ROOT_CHANGED,
NEW_MENUITEM,
ITEM_ACTIVATE,
+ EVENT_RESULT,
LAST_SIGNAL
};
@@ -102,6 +103,16 @@ struct _properties_listener_t {
gboolean replied;
};
+typedef struct _event_data_t event_data_t;
+struct _event_data_t {
+ DbusmenuClient * client;
+ DbusmenuMenuitem * menuitem;
+ gchar * event;
+ GValue data;
+ guint timestamp;
+};
+
+
#define DBUSMENU_CLIENT_GET_PRIVATE(o) \
(G_TYPE_INSTANCE_GET_PRIVATE ((o), DBUSMENU_TYPE_CLIENT, DbusmenuClientPrivate))
@@ -206,6 +217,25 @@ dbusmenu_client_class_init (DbusmenuClientClass *klass)
NULL, NULL,
_dbusmenu_client_marshal_VOID__OBJECT_UINT,
G_TYPE_NONE, 2, G_TYPE_OBJECT, G_TYPE_UINT);
+ /**
+ DbusmenuClient::event-error:
+ @arg0: The #DbusmenuClient object
+ @arg1: The #DbusmenuMenuitem sent an event
+ @arg2: The ID of the event sent
+ @arg3: The data sent along with the event
+ @arg4: A timestamp that the event happened at
+ @arg5: Possibly the error in sending the event (or NULL)
+
+ Signal sent to show that there was an error in sending the event
+ to the server.
+ */
+ signals[EVENT_RESULT] = g_signal_new(DBUSMENU_CLIENT_SIGNAL_EVENT_RESULT,
+ G_TYPE_FROM_CLASS (klass),
+ G_SIGNAL_RUN_LAST,
+ G_STRUCT_OFFSET (DbusmenuClientClass, event_result),
+ NULL, NULL,
+ _dbusmenu_client_marshal_VOID__OBJECT_STRING_POINTER_UINT_POINTER,
+ G_TYPE_NONE, 5, G_TYPE_OBJECT, G_TYPE_STRING, G_TYPE_POINTER, G_TYPE_UINT, G_TYPE_POINTER);
g_object_class_install_property (object_class, PROP_DBUSOBJECT,
g_param_spec_string(DBUSMENU_CLIENT_PROP_DBUS_OBJECT, "DBus Object we represent",
@@ -1025,10 +1055,19 @@ menuitem_get_properties_new_cb (DBusGProxy * proxy, GHashTable * properties, GEr
static void
menuitem_call_cb (DBusGProxy * proxy, GError * error, gpointer userdata)
{
+ event_data_t * edata = (event_data_t *)userdata;
+
if (error != NULL) {
- g_warning("Unable to call menu item %d: %s", GPOINTER_TO_INT(userdata), error->message);
+ g_warning("Unable to call event '%s' on menu item %d: %s", edata->event, dbusmenu_menuitem_get_id(edata->menuitem), error->message);
}
+ g_signal_emit(edata->client, signals[EVENT_RESULT], 0, edata->menuitem, edata->event, &edata->data, edata->timestamp, error, TRUE);
+
+ g_value_unset(&edata->data);
+ g_free(edata->event);
+ g_object_unref(edata->menuitem);
+ g_free(edata);
+
return;
}
@@ -1041,6 +1080,13 @@ dbusmenu_client_send_event (DbusmenuClient * client, gint id, const gchar * name
g_return_if_fail(id >= 0);
g_return_if_fail(name != NULL);
+ DbusmenuClientPrivate * priv = DBUSMENU_CLIENT_GET_PRIVATE(client);
+ DbusmenuMenuitem * mi = dbusmenu_menuitem_find_id(priv->root, id);
+ if (mi == NULL) {
+ g_warning("Asked to activate a menuitem %d that we don't know about", id);
+ return;
+ }
+
if (value == NULL) {
GValue internalval = {0};
g_value_init(&internalval, G_TYPE_INT);
@@ -1048,8 +1094,21 @@ dbusmenu_client_send_event (DbusmenuClient * client, gint id, const gchar * name
value = &internalval;
}
- DbusmenuClientPrivate * priv = DBUSMENU_CLIENT_GET_PRIVATE(client);
- org_ayatana_dbusmenu_event_async (priv->menuproxy, id, name, value, timestamp, menuitem_call_cb, GINT_TO_POINTER(id));
+ event_data_t * edata = g_new0(event_data_t, 1);
+ edata->client = client;
+ edata->menuitem = mi;
+ g_object_ref(edata->menuitem);
+ edata->event = g_strdup(name);
+ g_value_init(&edata->data, G_VALUE_TYPE(value));
+ g_value_copy(value, &edata->data);
+ edata->timestamp = timestamp;
+
+ DBusGAsyncData *stuff;
+ stuff = g_slice_new (DBusGAsyncData);
+ stuff->cb = G_CALLBACK (menuitem_call_cb);
+ stuff->userdata = edata;
+ dbus_g_proxy_begin_call_with_timeout (priv->menuproxy, "Event", org_ayatana_dbusmenu_event_async_callback, stuff, _dbus_glib_async_data_free, 1000, G_TYPE_INT, id, G_TYPE_STRING, name, G_TYPE_VALUE, value, G_TYPE_UINT, timestamp, G_TYPE_INVALID);
+
return;
}
diff --git a/libdbusmenu-glib/client.h b/libdbusmenu-glib/client.h
index 6ca2232..5d4b5c3 100644
--- a/libdbusmenu-glib/client.h
+++ b/libdbusmenu-glib/client.h
@@ -47,6 +47,7 @@ G_BEGIN_DECLS
#define DBUSMENU_CLIENT_SIGNAL_ROOT_CHANGED "root-changed"
#define DBUSMENU_CLIENT_SIGNAL_NEW_MENUITEM "new-menuitem"
#define DBUSMENU_CLIENT_SIGNAL_ITEM_ACTIVATE "item-activate"
+#define DBUSMENU_CLIENT_SIGNAL_EVENT_RESULT "event-result"
#define DBUSMENU_CLIENT_PROP_DBUS_NAME "dbus-name"
#define DBUSMENU_CLIENT_PROP_DBUS_OBJECT "dbus-object"
@@ -60,10 +61,10 @@ G_BEGIN_DECLS
@parent_class: #GObjectClass
@layout_updated: Slot for #DbusmenuClient::layout-updated.
@new_menuitem: Slot for #DbusmenuClient::new-menuitem.
- @item_activate: Slote for #DbusmenuClient::item-activate.
+ @item_activate: Slot for #DbusmenuClient::item-activate.
+ @event_result: Slot for #DbusmenuClient::event-error.
@reserved1: Reserved for future use.
@reserved2: Reserved for future use.
- @reserved3: Reserved for future use.
A simple class that takes all of the information from a
#DbusmenuServer over DBus and makes the same set of
@@ -77,11 +78,12 @@ struct _DbusmenuClientClass {
void (*root_changed) (DbusmenuMenuitem * newroot);
void (*new_menuitem) (DbusmenuMenuitem * newitem);
void (*item_activate) (DbusmenuMenuitem * item, guint timestamp);
+ void (*event_result) (DbusmenuMenuitem * item, gchar * event, GValue * data, guint timestamp, GError * error);
/* Reserved for future use */
void (*reserved1) (void);
void (*reserved2) (void);
- void (*reserved3) (void);
+ /* void (*reserved3) (void); */
/* void (*reserved4) (void); */
};
diff --git a/libdbusmenu-gtk/client.c b/libdbusmenu-gtk/client.c
index 72f5b0b..6970d59 100644
--- a/libdbusmenu-gtk/client.c
+++ b/libdbusmenu-gtk/client.c
@@ -447,26 +447,25 @@ activate_helper (GtkMenuShell * shell)
GtkWidget * attach = gtk_menu_get_attach_widget(GTK_MENU(shell));
if (attach != NULL) {
- GtkWidget * parent = gtk_widget_get_parent(attach);
- GtkWidget *toplevel = gtk_widget_get_toplevel (attach);
+ GtkWidget * parent = gtk_widget_get_parent(GTK_WIDGET(attach));
if (parent != NULL) {
if (GTK_IS_MENU(parent)) {
activate_helper(GTK_MENU_SHELL(parent));
}
- if (!GTK_MENU_SHELL (parent)->active) {
- gtk_grab_add (parent);
- GTK_MENU_SHELL (parent)->have_grab = TRUE;
- GTK_MENU_SHELL (parent)->active = TRUE;
- }
+ if (!GTK_MENU_SHELL (parent)->active) {
+ gtk_grab_add (parent);
+ GTK_MENU_SHELL (parent)->have_grab = TRUE;
+ GTK_MENU_SHELL (parent)->active = TRUE;
+ }
gtk_menu_shell_select_item(GTK_MENU_SHELL(parent), attach);
}
}
}
- return;
+ return;
}
/* Signaled when we should show a menuitem at request of the application
diff --git a/tests/Makefile.am b/tests/Makefile.am
index 9f621cb..aa79c8f 100644
--- a/tests/Makefile.am
+++ b/tests/Makefile.am
@@ -5,6 +5,7 @@ CLEANFILES=
TESTS = \
test-glib-objects-test \
+ test-glib-events \
test-glib-layout \
test-glib-properties \
test-glib-proxy \
@@ -20,6 +21,8 @@ TESTS = \
check_PROGRAMS = \
glib-server-nomenu \
test-glib-objects \
+ test-glib-events-client \
+ test-glib-events-server \
test-glib-layout-client \
test-glib-layout-server \
test-glib-properties-client \
@@ -129,6 +132,37 @@ test_glib_layout_client_LDADD = \
$(DBUSMENUGLIB_LIBS)
######################
+# Test Glib Events
+######################
+
+test-glib-events: test-glib-events-client test-glib-events-server Makefile.am
+ @echo "#!/bin/bash" > $@
+ @echo $(DBUS_RUNNER) --task ./test-glib-events-client --task-name Client --task ./test-glib-events-server --task-name Server --ignore-return >> $@
+ @chmod +x $@
+
+test_glib_events_server_SOURCES = \
+ test-glib-events-server.c
+
+test_glib_events_server_CFLAGS = \
+ -I $(srcdir)/.. \
+ $(DBUSMENUGLIB_CFLAGS) -Wall -Werror
+
+test_glib_events_server_LDADD = \
+ ../libdbusmenu-glib/libdbusmenu-glib.la \
+ $(DBUSMENUGLIB_LIBS)
+
+test_glib_events_client_SOURCES = \
+ test-glib-events-client.c
+
+test_glib_events_client_CFLAGS = \
+ -I $(srcdir)/.. \
+ $(DBUSMENUGLIB_CFLAGS) -Wall -Werror
+
+test_glib_events_client_LDADD = \
+ ../libdbusmenu-glib/libdbusmenu-glib.la \
+ $(DBUSMENUGLIB_LIBS)
+
+######################
# Test JSON
######################
diff --git a/tests/test-glib-events-client.c b/tests/test-glib-events-client.c
new file mode 100644
index 0000000..97d5caf
--- /dev/null
+++ b/tests/test-glib-events-client.c
@@ -0,0 +1,140 @@
+/*
+A test for libdbusmenu to ensure its quality.
+
+Copyright 2009 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 the GNU General Public License version 3, 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 GNU General Public License for more details.
+
+You should have received a copy of the GNU General Public License along
+with this program. If not, see <http://www.gnu.org/licenses/>.
+*/
+
+#include <glib.h>
+
+#include <libdbusmenu-glib/client.h>
+#include <libdbusmenu-glib/menuitem.h>
+
+#include "test-glib-submenu.h"
+
+#define TIMESTAMP_VALUE 54
+#define DATA_VALUE 32
+#define USER_VALUE 76
+
+static GMainLoop * mainloop = NULL;
+static gboolean passed = TRUE;
+static gboolean first = TRUE;
+
+static void
+event_status (DbusmenuClient * client, DbusmenuMenuitem * item, gchar * name, GValue * data, guint timestamp, GError * error, gpointer user_data)
+{
+ g_debug("Event status: %s", error == NULL ? "Sent" : "Error");
+
+ if (timestamp != TIMESTAMP_VALUE) {
+ g_debug("Timestamp value pass fail got: %d", timestamp);
+ passed = FALSE;
+ g_main_loop_quit(mainloop);
+ return;
+ }
+
+ if (g_value_get_int(data) != DATA_VALUE) {
+ g_debug("Data value pass fail got: %d", g_value_get_int(data));
+ passed = FALSE;
+ g_main_loop_quit(mainloop);
+ return;
+ }
+
+ if (GPOINTER_TO_INT(user_data) != USER_VALUE) {
+ g_debug("User value pass fail got: %d", GPOINTER_TO_INT(user_data));
+ passed = FALSE;
+ g_main_loop_quit(mainloop);
+ return;
+ }
+
+ if (first && error != NULL) {
+ passed = FALSE;
+ g_debug("First signal back failed.");
+ g_main_loop_quit(mainloop);
+ return;
+ }
+
+ if (!first && error == NULL) {
+ passed = FALSE;
+ g_debug("Second signal didn't fail.");
+ g_main_loop_quit(mainloop);
+ return;
+ }
+
+ if (!first && error != NULL) {
+ g_debug("Second signal failed: pass.");
+ g_main_loop_quit(mainloop);
+ return;
+ }
+
+ first = FALSE;
+ dbusmenu_menuitem_handle_event(item, "clicked", data, timestamp);
+ return;
+}
+
+static void
+layout_updated (DbusmenuClient * client, gpointer user_data)
+{
+ g_debug("Layout Updated");
+
+ DbusmenuMenuitem * menuroot = dbusmenu_client_get_root(client);
+ if (menuroot == NULL) {
+ g_debug("Root is NULL?");
+ return;
+ }
+
+ GValue data = {0};
+ g_value_init(&data, G_TYPE_INT);
+ g_value_set_int(&data, DATA_VALUE);
+
+ dbusmenu_menuitem_handle_event(menuroot, "clicked", &data, TIMESTAMP_VALUE);
+
+ return;
+}
+
+static gboolean
+timer_func (gpointer data)
+{
+ g_debug("Death timer. Oops.");
+ passed = FALSE;
+ g_main_loop_quit(mainloop);
+ return FALSE;
+}
+
+int
+main (int argc, char ** argv)
+{
+ g_type_init();
+
+ DbusmenuClient * client = dbusmenu_client_new("org.dbusmenu.test", "/org/test");
+ g_signal_connect(G_OBJECT(client), DBUSMENU_CLIENT_SIGNAL_LAYOUT_UPDATED, G_CALLBACK(layout_updated), NULL);
+ g_signal_connect(G_OBJECT(client), DBUSMENU_CLIENT_SIGNAL_EVENT_RESULT, G_CALLBACK(event_status), GINT_TO_POINTER(USER_VALUE));
+
+ g_timeout_add_seconds(5, timer_func, client);
+
+ mainloop = g_main_loop_new(NULL, FALSE);
+ g_main_loop_run(mainloop);
+
+ g_object_unref(G_OBJECT(client));
+
+ if (passed) {
+ g_debug("Quiting");
+ return 0;
+ } else {
+ g_debug("Quiting as we're a failure");
+ return 1;
+ }
+}
diff --git a/tests/test-glib-events-server.c b/tests/test-glib-events-server.c
new file mode 100644
index 0000000..0d1e0b1
--- /dev/null
+++ b/tests/test-glib-events-server.c
@@ -0,0 +1,102 @@
+/*
+A test for libdbusmenu to ensure its quality.
+
+Copyright 2009 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 the GNU General Public License version 3, 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 GNU General Public License for more details.
+
+You should have received a copy of the GNU General Public License along
+with this program. If not, see <http://www.gnu.org/licenses/>.
+*/
+
+#include <glib.h>
+
+#include <dbus/dbus.h>
+#include <dbus/dbus-glib.h>
+#include <dbus/dbus-glib-lowlevel.h>
+#include <dbus/dbus-glib-bindings.h>
+
+#include <libdbusmenu-glib/server.h>
+#include <libdbusmenu-glib/menuitem.h>
+
+static DbusmenuServer * server = NULL;
+static GMainLoop * mainloop = NULL;
+static gboolean passed = TRUE;
+
+static void
+handle_event (void) {
+ g_debug("Handle event");
+ g_main_loop_quit(mainloop);
+ return;
+}
+
+static gboolean
+timer_func (gpointer data)
+{
+ passed = FALSE;
+ g_debug("Never got a signal");
+ g_main_loop_quit(mainloop);
+ return FALSE;
+}
+
+int
+main (int argc, char ** argv)
+{
+ GError * error = NULL;
+
+ g_type_init();
+
+ DBusGConnection * connection = dbus_g_bus_get(DBUS_BUS_SESSION, NULL);
+ g_debug("DBus ID: %s", dbus_connection_get_server_id(dbus_g_connection_get_connection(dbus_g_bus_get(DBUS_BUS_SESSION, NULL))));
+
+ DBusGProxy * bus_proxy = dbus_g_proxy_new_for_name(connection, DBUS_SERVICE_DBUS, DBUS_PATH_DBUS, DBUS_INTERFACE_DBUS);
+ guint nameret = 0;
+
+ if (!org_freedesktop_DBus_request_name(bus_proxy, "org.dbusmenu.test", 0, &nameret, &error)) {
+ g_error("Unable to call to request name");
+ return 1;
+ }
+
+ if (nameret != DBUS_REQUEST_NAME_REPLY_PRIMARY_OWNER) {
+ g_error("Unable to get name");
+ return 1;
+ }
+
+ server = dbusmenu_server_new("/org/test");
+ DbusmenuMenuitem * menuitem = dbusmenu_menuitem_new();
+ dbusmenu_server_set_root(server, menuitem);
+
+ g_signal_connect(G_OBJECT(menuitem), DBUSMENU_MENUITEM_SIGNAL_ITEM_ACTIVATED, G_CALLBACK(handle_event), NULL);
+
+ g_timeout_add_seconds(3, timer_func, NULL);
+
+ mainloop = g_main_loop_new(NULL, FALSE);
+ g_main_loop_run(mainloop);
+
+ if (passed) {
+ int i;
+
+ for (i = 0; i < 5; i++) {
+ g_debug("Ignoring signals: %d", i);
+ g_usleep(1000 * 1000);
+ }
+ }
+
+ if (passed) {
+ g_debug("Test Passed");
+ return 0;
+ } else {
+ g_debug("Test Failed");
+ return 1;
+ }
+}
diff --git a/tests/test-gtk-label-client.c b/tests/test-gtk-label-client.c
index 070c278..14eb5bd 100644
--- a/tests/test-gtk-label-client.c
+++ b/tests/test-gtk-label-client.c
@@ -22,7 +22,6 @@ with this program. If not, see <http://www.gnu.org/licenses/>.
#include <gtk/gtk.h>
#include <libdbusmenu-gtk/menu.h>
-static guint layouton = 0;
static GMainLoop * mainloop = NULL;
static gboolean passed = TRUE;
static guint death_timer = 0;
@@ -105,7 +104,6 @@ verify_root_to_layout(DbusmenuMenuitem * mi, proplayout_t * layout)
static gboolean
timer_func (gpointer data)
{
- g_debug("Death timer. Oops. Got to: %d", layouton);
passed = TRUE;
g_main_loop_quit(mainloop);
return FALSE;