Merge lp:~bratsche/libdbusmenu/accel-keys into lp:libdbusmenu/0.5

Proposed by Cody Russell
Status: Merged
Merged at revision: 116
Proposed branch: lp:~bratsche/libdbusmenu/accel-keys
Merge into: lp:libdbusmenu/0.5
Diff against target: 1044 lines (+811/-4)
12 files modified
.bzrignore (+6/-0)
libdbusmenu-glib/menuitem.h (+6/-0)
libdbusmenu-gtk/client.c (+179/-0)
libdbusmenu-gtk/client.h (+3/-0)
libdbusmenu-gtk/genericmenuitem.c (+4/-1)
libdbusmenu-gtk/menuitem.c (+208/-0)
libdbusmenu-gtk/menuitem.h (+7/-0)
tests/Makefile.am (+77/-2)
tests/run-xvfb.sh (+1/-1)
tests/test-gtk-objects.c (+145/-0)
tests/test-gtk-shortcut-client.c (+76/-0)
tests/test-gtk-shortcut-server.c (+99/-0)
To merge this branch: bzr merge lp:~bratsche/libdbusmenu/accel-keys
Reviewer Review Type Date Requested Status
DBus Menu Team Pending
Review via email: mp+28104@code.launchpad.net

This proposal supersedes a proposal from 2010-06-21.

To post a comment you must log in.

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== modified file '.bzrignore'
--- .bzrignore 2010-06-08 18:12:32 +0000
+++ .bzrignore 2010-06-21 19:48:28 +0000
@@ -71,6 +71,12 @@
71libdbusmenu-gtk/DbusmenuGtk-0.2.tmp.gir71libdbusmenu-gtk/DbusmenuGtk-0.2.tmp.gir
72libdbusmenu-gtk/DbusmenuGtk-0.2.typelib72libdbusmenu-gtk/DbusmenuGtk-0.2.typelib
73libdbusmenu-gtk/DbusmenuGtk-0.2.vapi73libdbusmenu-gtk/DbusmenuGtk-0.2.vapi
74tests/test-gtk-objects
75tests/test-gtk-objects-test
76tests/test-gtk-objects.xml
77tests/test-gtk-shortcut
78tests/test-gtk-shortcut-client
79tests/test-gtk-shortcut-server
74tests/test-glib-submenu80tests/test-glib-submenu
75tests/test-glib-submenu-client81tests/test-glib-submenu-client
76tests/test-glib-submenu-server82tests/test-glib-submenu-server
7783
=== modified file 'libdbusmenu-glib/menuitem.h'
--- libdbusmenu-glib/menuitem.h 2010-06-17 19:58:28 +0000
+++ libdbusmenu-glib/menuitem.h 2010-06-21 19:48:28 +0000
@@ -58,6 +58,7 @@
58#define DBUSMENU_MENUITEM_PROP_ICON_DATA "icon-data"58#define DBUSMENU_MENUITEM_PROP_ICON_DATA "icon-data"
59#define DBUSMENU_MENUITEM_PROP_TOGGLE_TYPE "toggle-type"59#define DBUSMENU_MENUITEM_PROP_TOGGLE_TYPE "toggle-type"
60#define DBUSMENU_MENUITEM_PROP_TOGGLE_STATE "toggle-state"60#define DBUSMENU_MENUITEM_PROP_TOGGLE_STATE "toggle-state"
61#define DBUSMENU_MENUITEM_PROP_SHORTCUT "shortcut"
61#define DBUSMENU_MENUITEM_PROP_CHILD_DISPLAY "children-display"62#define DBUSMENU_MENUITEM_PROP_CHILD_DISPLAY "children-display"
6263
63#define DBUSMENU_MENUITEM_TOGGLE_CHECK "checkmark"64#define DBUSMENU_MENUITEM_TOGGLE_CHECK "checkmark"
@@ -69,6 +70,11 @@
6970
70#define DBUSMENU_MENUITEM_ICON_NAME_BLANK "blank-icon"71#define DBUSMENU_MENUITEM_ICON_NAME_BLANK "blank-icon"
7172
73#define DBUSMENU_MENUITEM_SHORTCUT_CONTROL "Control"
74#define DBUSMENU_MENUITEM_SHORTCUT_ALT "Alt"
75#define DBUSMENU_MENUITEM_SHORTCUT_SHIFT "Shift"
76#define DBUSMENU_MENUITEM_SHORTCUT_SUPER "Super"
77
72#define DBUSMENU_MENUITEM_CHILD_DISPLAY_SUBMENU "submenu"78#define DBUSMENU_MENUITEM_CHILD_DISPLAY_SUBMENU "submenu"
7379
74/**80/**
7581
=== modified file 'libdbusmenu-gtk/client.c'
--- libdbusmenu-gtk/client.c 2010-05-26 22:18:29 +0000
+++ libdbusmenu-gtk/client.c 2010-06-21 19:48:28 +0000
@@ -36,6 +36,15 @@
36#include "menuitem.h"36#include "menuitem.h"
37#include "genericmenuitem.h"37#include "genericmenuitem.h"
3838
39/* Private */
40typedef struct _DbusmenuGtkClientPrivate DbusmenuGtkClientPrivate;
41struct _DbusmenuGtkClientPrivate {
42 GtkAccelGroup * agroup;
43};
44
45#define DBUSMENU_GTKCLIENT_GET_PRIVATE(o) \
46(G_TYPE_INSTANCE_GET_PRIVATE ((o), DBUSMENU_GTKCLIENT_TYPE, DbusmenuGtkClientPrivate))
47
39/* Prototypes */48/* Prototypes */
40static void dbusmenu_gtkclient_class_init (DbusmenuGtkClientClass *klass);49static void dbusmenu_gtkclient_class_init (DbusmenuGtkClientClass *klass);
41static void dbusmenu_gtkclient_init (DbusmenuGtkClient *self);50static void dbusmenu_gtkclient_init (DbusmenuGtkClient *self);
@@ -62,6 +71,8 @@
62{71{
63 GObjectClass *object_class = G_OBJECT_CLASS (klass);72 GObjectClass *object_class = G_OBJECT_CLASS (klass);
6473
74 g_type_class_add_private (klass, sizeof (DbusmenuGtkClientPrivate));
75
65 object_class->dispose = dbusmenu_gtkclient_dispose;76 object_class->dispose = dbusmenu_gtkclient_dispose;
66 object_class->finalize = dbusmenu_gtkclient_finalize;77 object_class->finalize = dbusmenu_gtkclient_finalize;
6778
@@ -73,6 +84,10 @@
73static void84static void
74dbusmenu_gtkclient_init (DbusmenuGtkClient *self)85dbusmenu_gtkclient_init (DbusmenuGtkClient *self)
75{86{
87 DbusmenuGtkClientPrivate * priv = DBUSMENU_GTKCLIENT_GET_PRIVATE(self);
88
89 priv->agroup = NULL;
90
76 dbusmenu_client_add_type_handler(DBUSMENU_CLIENT(self), DBUSMENU_CLIENT_TYPES_DEFAULT, new_item_normal);91 dbusmenu_client_add_type_handler(DBUSMENU_CLIENT(self), DBUSMENU_CLIENT_TYPES_DEFAULT, new_item_normal);
77 dbusmenu_client_add_type_handler(DBUSMENU_CLIENT(self), DBUSMENU_CLIENT_TYPES_SEPARATOR, new_item_seperator);92 dbusmenu_client_add_type_handler(DBUSMENU_CLIENT(self), DBUSMENU_CLIENT_TYPES_SEPARATOR, new_item_seperator);
7893
@@ -85,6 +100,12 @@
85static void100static void
86dbusmenu_gtkclient_dispose (GObject *object)101dbusmenu_gtkclient_dispose (GObject *object)
87{102{
103 DbusmenuGtkClientPrivate * priv = DBUSMENU_GTKCLIENT_GET_PRIVATE(object);
104
105 if (priv->agroup != NULL) {
106 g_object_unref(priv->agroup);
107 priv->agroup = NULL;
108 }
88109
89 G_OBJECT_CLASS (dbusmenu_gtkclient_parent_class)->dispose (object);110 G_OBJECT_CLASS (dbusmenu_gtkclient_parent_class)->dispose (object);
90 return;111 return;
@@ -99,6 +120,151 @@
99 return;120 return;
100}121}
101122
123/* Structure for passing data to swap_agroup */
124typedef struct _swap_agroup_t swap_agroup_t;
125struct _swap_agroup_t {
126 DbusmenuGtkClient * client;
127 GtkAccelGroup * old_agroup;
128 GtkAccelGroup * new_agroup;
129};
130
131/* Looks at the old version of the accelerator group and
132 the new one and makes the state proper. */
133static gboolean
134do_swap_agroup (DbusmenuMenuitem * mi, gpointer userdata) {
135 swap_agroup_t * data = (swap_agroup_t *)userdata;
136
137 /* If we don't have a shortcut we don't care */
138 if (!dbusmenu_menuitem_property_exist(mi, DBUSMENU_MENUITEM_PROP_SHORTCUT)) {
139 return FALSE;
140 }
141
142 guint key = 0;
143 GdkModifierType modifiers = 0;
144
145 dbusmenu_menuitem_property_get_shortcut(mi, &key, &modifiers);
146
147 g_debug("Setting shortcut on '%s': %d %X", dbusmenu_menuitem_property_get(mi, DBUSMENU_MENUITEM_PROP_LABEL), key, modifiers);
148
149 if (key == 0) {
150 return FALSE;
151 }
152
153 GtkMenuItem * gmi = dbusmenu_gtkclient_menuitem_get(data->client, mi);
154 if (gmi == NULL) {
155 return FALSE;
156 }
157
158 const gchar * accel_path = gtk_menu_item_get_accel_path(gmi);
159
160 if (accel_path != NULL) {
161 gtk_accel_map_change_entry(accel_path, key, modifiers, TRUE /* replace */);
162 } else {
163 gchar * accel_path = g_strdup_printf("<Appmenus>/Generated/%X/%d", GPOINTER_TO_UINT(data->client), dbusmenu_menuitem_get_id(mi));
164
165 gtk_accel_map_add_entry(accel_path, key, modifiers);
166 gtk_widget_set_accel_path(GTK_WIDGET(gmi), accel_path, data->new_agroup);
167 g_free(accel_path);
168 }
169
170 GtkMenu * submenu = dbusmenu_gtkclient_menuitem_get_submenu(data->client, mi);
171 if (submenu != NULL) {
172 gtk_menu_set_accel_group(submenu, data->new_agroup);
173 }
174
175 return TRUE;
176}
177
178static void
179swap_agroup (DbusmenuMenuitem *mi, gpointer userdata) {
180 do_swap_agroup (mi, userdata);
181
182 return; /* See what I did here, Ted? :) */
183}
184
185/* Refresh the shortcut for an entry */
186static void
187refresh_shortcut (DbusmenuGtkClient * client, DbusmenuMenuitem * mi)
188{
189 g_return_if_fail(DBUSMENU_IS_GTKCLIENT(client));
190 g_return_if_fail(DBUSMENU_IS_MENUITEM(mi));
191
192 DbusmenuGtkClientPrivate * priv = DBUSMENU_GTKCLIENT_GET_PRIVATE(client);
193
194 swap_agroup_t data;
195 data.client = client;
196 data.old_agroup = priv->agroup;
197 data.new_agroup = priv->agroup;
198
199 if (do_swap_agroup(mi, &data)) {
200 guint key;
201 GdkModifierType mod;
202 GtkMenuItem *gmi = dbusmenu_gtkclient_menuitem_get (client, mi);
203
204 dbusmenu_menuitem_property_get_shortcut (mi, &key, &mod);
205
206 gtk_widget_add_accelerator (GTK_WIDGET (gmi), "activate", priv->agroup, key, mod, GTK_ACCEL_VISIBLE);
207 }
208
209 return;
210}
211
212
213/**
214 dbusmenu_gtkclient_set_accel_group:
215 @client: To set the group on
216 @agroup: The new acceleration group
217
218 Sets the acceleration group for the menu items with accelerators
219 on this client.
220*/
221void
222dbusmenu_gtkclient_set_accel_group (DbusmenuGtkClient * client, GtkAccelGroup * agroup)
223{
224 g_return_if_fail(DBUSMENU_IS_GTKCLIENT(client));
225 g_return_if_fail(GTK_IS_ACCEL_GROUP(agroup));
226
227 DbusmenuGtkClientPrivate * priv = DBUSMENU_GTKCLIENT_GET_PRIVATE(client);
228
229 DbusmenuMenuitem * root = dbusmenu_client_get_root(DBUSMENU_CLIENT(client));
230 if (root != NULL) {
231 swap_agroup_t data;
232 data.client = client;
233 data.old_agroup = priv->agroup;
234 data.new_agroup = agroup;
235
236 dbusmenu_menuitem_foreach(root, swap_agroup, &data);
237 }
238
239 if (priv->agroup != NULL) {
240 g_object_unref(priv->agroup);
241 priv->agroup = NULL;
242 }
243
244 priv->agroup = agroup;
245
246 return;
247}
248
249/**
250 dbusmenu_gtkclient_get_accel_group:
251 @client: Client to query for an accelerator group
252
253 Gets the accel group for this client.
254
255 Return value: Either a valid group or #NULL on error or
256 none set.
257*/
258GtkAccelGroup *
259dbusmenu_gtkclient_get_accel_group (DbusmenuGtkClient * client)
260{
261 g_return_val_if_fail(DBUSMENU_IS_GTKCLIENT(client), NULL);
262
263 DbusmenuGtkClientPrivate * priv = DBUSMENU_GTKCLIENT_GET_PRIVATE(client);
264
265 return priv->agroup;
266}
267
102/* Internal Functions */268/* Internal Functions */
103269
104static const gchar * data_menuitem = "dbusmenugtk-data-gtkmenuitem";270static const gchar * data_menuitem = "dbusmenugtk-data-gtkmenuitem";
@@ -225,6 +391,17 @@
225 return;391 return;
226}392}
227393
394/* Special handler for the shortcut changing as we need to have the
395 client for that one to get the accel group. */
396static void
397menu_shortcut_change_cb (DbusmenuMenuitem * mi, gchar * prop, GValue * value, DbusmenuGtkClient * client)
398{
399 if (!g_strcmp0(prop, DBUSMENU_MENUITEM_PROP_SHORTCUT)) {
400 refresh_shortcut(client, mi);
401 }
402 return;
403}
404
228/* Call back that happens when the DbusmenuMenuitem405/* Call back that happens when the DbusmenuMenuitem
229 is destroyed. We're making sure to clean up everything406 is destroyed. We're making sure to clean up everything
230 else down the pipe. */407 else down the pipe. */
@@ -291,6 +468,7 @@
291468
292 /* DbusmenuMenuitem signals */469 /* DbusmenuMenuitem signals */
293 g_signal_connect(G_OBJECT(item), DBUSMENU_MENUITEM_SIGNAL_PROPERTY_CHANGED, G_CALLBACK(menu_prop_change_cb), gmi);470 g_signal_connect(G_OBJECT(item), DBUSMENU_MENUITEM_SIGNAL_PROPERTY_CHANGED, G_CALLBACK(menu_prop_change_cb), gmi);
471 g_signal_connect(G_OBJECT(item), DBUSMENU_MENUITEM_SIGNAL_PROPERTY_CHANGED, G_CALLBACK(menu_shortcut_change_cb), client);
294 g_signal_connect(G_OBJECT(item), DBUSMENU_MENUITEM_SIGNAL_CHILD_REMOVED, G_CALLBACK(delete_child), client);472 g_signal_connect(G_OBJECT(item), DBUSMENU_MENUITEM_SIGNAL_CHILD_REMOVED, G_CALLBACK(delete_child), client);
295 g_signal_connect(G_OBJECT(item), DBUSMENU_MENUITEM_SIGNAL_CHILD_MOVED, G_CALLBACK(move_child), client);473 g_signal_connect(G_OBJECT(item), DBUSMENU_MENUITEM_SIGNAL_CHILD_MOVED, G_CALLBACK(move_child), client);
296474
@@ -305,6 +483,7 @@
305 process_sensitive(item, gmi, dbusmenu_menuitem_property_get_value(item, DBUSMENU_MENUITEM_PROP_ENABLED));483 process_sensitive(item, gmi, dbusmenu_menuitem_property_get_value(item, DBUSMENU_MENUITEM_PROP_ENABLED));
306 process_toggle_type(item, gmi, dbusmenu_menuitem_property_get_value(item, DBUSMENU_MENUITEM_PROP_TOGGLE_TYPE));484 process_toggle_type(item, gmi, dbusmenu_menuitem_property_get_value(item, DBUSMENU_MENUITEM_PROP_TOGGLE_TYPE));
307 process_toggle_state(item, gmi, dbusmenu_menuitem_property_get_value(item, DBUSMENU_MENUITEM_PROP_TOGGLE_STATE));485 process_toggle_state(item, gmi, dbusmenu_menuitem_property_get_value(item, DBUSMENU_MENUITEM_PROP_TOGGLE_STATE));
486 refresh_shortcut(client, item);
308487
309 /* Oh, we're a child, let's deal with that */488 /* Oh, we're a child, let's deal with that */
310 if (parent != NULL) {489 if (parent != NULL) {
311490
=== modified file 'libdbusmenu-gtk/client.h'
--- libdbusmenu-gtk/client.h 2010-05-26 22:18:29 +0000
+++ libdbusmenu-gtk/client.h 2010-06-21 19:48:28 +0000
@@ -79,6 +79,9 @@
79GtkMenuItem * dbusmenu_gtkclient_menuitem_get (DbusmenuGtkClient * client, DbusmenuMenuitem * item);79GtkMenuItem * dbusmenu_gtkclient_menuitem_get (DbusmenuGtkClient * client, DbusmenuMenuitem * item);
80GtkMenu * dbusmenu_gtkclient_menuitem_get_submenu (DbusmenuGtkClient * client, DbusmenuMenuitem * item);80GtkMenu * dbusmenu_gtkclient_menuitem_get_submenu (DbusmenuGtkClient * client, DbusmenuMenuitem * item);
8181
82void dbusmenu_gtkclient_set_accel_group (DbusmenuGtkClient * client, GtkAccelGroup * agroup);
83GtkAccelGroup * dbusmenu_gtkclient_get_accel_group (DbusmenuGtkClient * client);
84
82void dbusmenu_gtkclient_newitem_base (DbusmenuGtkClient * client, DbusmenuMenuitem * item, GtkMenuItem * gmi, DbusmenuMenuitem * parent);85void dbusmenu_gtkclient_newitem_base (DbusmenuGtkClient * client, DbusmenuMenuitem * item, GtkMenuItem * gmi, DbusmenuMenuitem * parent);
8386
84/**87/**
8588
=== modified file 'libdbusmenu-gtk/genericmenuitem.c'
--- libdbusmenu-gtk/genericmenuitem.c 2010-01-12 06:19:14 +0000
+++ libdbusmenu-gtk/genericmenuitem.c 2010-06-21 19:48:28 +0000
@@ -158,6 +158,8 @@
158static void158static void
159set_label (GtkMenuItem * menu_item, const gchar * label)159set_label (GtkMenuItem * menu_item, const gchar * label)
160{160{
161 if (label == NULL) return;
162
161 GtkWidget * child = gtk_bin_get_child(GTK_BIN(menu_item));163 GtkWidget * child = gtk_bin_get_child(GTK_BIN(menu_item));
162 GtkLabel * labelw = NULL;164 GtkLabel * labelw = NULL;
163 gboolean suppress_update = FALSE;165 gboolean suppress_update = FALSE;
@@ -191,9 +193,10 @@
191 update the one that we already have. */193 update the one that we already have. */
192 if (labelw == NULL) {194 if (labelw == NULL) {
193 /* Build it */195 /* Build it */
194 labelw = GTK_LABEL(gtk_label_new(label));196 labelw = GTK_LABEL(gtk_accel_label_new(label));
195 gtk_label_set_use_underline(GTK_LABEL(labelw), TRUE);197 gtk_label_set_use_underline(GTK_LABEL(labelw), TRUE);
196 gtk_misc_set_alignment(GTK_MISC(labelw), 0.0, 0.5);198 gtk_misc_set_alignment(GTK_MISC(labelw), 0.0, 0.5);
199 gtk_accel_label_set_accel_widget(GTK_ACCEL_LABEL(labelw), GTK_WIDGET(menu_item));
197 gtk_widget_show(GTK_WIDGET(labelw));200 gtk_widget_show(GTK_WIDGET(labelw));
198201
199 /* Check to see if it needs to be in the bin for this202 /* Check to see if it needs to be in the bin for this
200203
=== modified file 'libdbusmenu-gtk/menuitem.c'
--- libdbusmenu-gtk/menuitem.c 2009-09-03 20:32:17 +0000
+++ libdbusmenu-gtk/menuitem.c 2010-06-21 19:48:28 +0000
@@ -27,6 +27,8 @@
27*/27*/
2828
29#include "menuitem.h"29#include "menuitem.h"
30#include <gdk/gdk.h>
31#include <gtk/gtk.h>
3032
31/**33/**
32 dbusmenu_menuitem_property_set_image:34 dbusmenu_menuitem_property_set_image:
@@ -128,3 +130,209 @@
128 return icon;130 return icon;
129}131}
130132
133/**
134 dbusmenu_menuitem_property_set_shortcut_string:
135 @menuitem: The #DbusmenuMenuitem to set the shortcut on
136 @shortcut: String describing the shortcut
137
138 This function takes a GTK shortcut string as defined in
139 #gtk_accelerator_parse and turns that into the information
140 required to send it over DBusmenu.
141
142 Return value: Whether it was successful at setting the property.
143*/
144gboolean
145dbusmenu_menuitem_property_set_shortcut_string (DbusmenuMenuitem * menuitem, const gchar * shortcut)
146{
147 g_return_val_if_fail(DBUSMENU_IS_MENUITEM(menuitem), FALSE);
148 g_return_val_if_fail(shortcut != NULL, FALSE);
149
150 guint key = 0;
151 GdkModifierType modifier = 0;
152
153 gtk_accelerator_parse(shortcut, &key, &modifier);
154
155 if (key == 0) {
156 g_warning("Unable to parse shortcut string '%s'", shortcut);
157 return FALSE;
158 }
159
160 return dbusmenu_menuitem_property_set_shortcut(menuitem, key, modifier);
161}
162
163/* Append strings to an g_value_array */
164static void
165_g_value_array_append_string (GValueArray * array, const gchar * string)
166{
167 GValue value = {0};
168 g_value_init(&value, G_TYPE_STRING);
169 g_value_set_string(&value, string);
170 g_value_array_append(array, &value);
171 return;
172}
173
174/**
175 dbusmenu_menuitem_property_set_shortcut:
176 @menuitem: The #DbusmenuMenuitem to set the shortcut on
177 @key: The keycode of the key to send
178 @modifier: A bitmask of modifiers used to activate the item
179
180 Takes the modifer described by @key and @modifier and places that into
181 the format sending across Dbus for shortcuts.
182
183 Return value: Whether it was successful at setting the property.
184*/
185gboolean
186dbusmenu_menuitem_property_set_shortcut (DbusmenuMenuitem * menuitem, guint key, GdkModifierType modifier)
187{
188 g_return_val_if_fail(DBUSMENU_IS_MENUITEM(menuitem), FALSE);
189 g_return_val_if_fail(gtk_accelerator_valid(key, modifier), FALSE);
190
191 GValueArray * array = g_value_array_new(4); /* Four seems like the max we'd need, plus it's still small */
192
193 if (modifier & GDK_CONTROL_MASK) {
194 _g_value_array_append_string(array, DBUSMENU_MENUITEM_SHORTCUT_CONTROL);
195 }
196 if (modifier & GDK_MOD1_MASK) {
197 _g_value_array_append_string(array, DBUSMENU_MENUITEM_SHORTCUT_ALT);
198 }
199 if (modifier & GDK_SHIFT_MASK) {
200 _g_value_array_append_string(array, DBUSMENU_MENUITEM_SHORTCUT_SHIFT);
201 }
202 if (modifier & GDK_SUPER_MASK) {
203 _g_value_array_append_string(array, DBUSMENU_MENUITEM_SHORTCUT_SUPER);
204 }
205
206 _g_value_array_append_string(array, gdk_keyval_name(key));
207
208 GValueArray * wrapper = g_value_array_new(1);
209 GValue wrap_val = {0};
210 g_value_init(&wrap_val, G_TYPE_VALUE_ARRAY);
211 g_value_set_boxed(&wrap_val, array);
212 g_value_array_append(wrapper, &wrap_val);
213
214 GValue value = {0};
215 g_value_init(&value, G_TYPE_VALUE_ARRAY);
216 g_value_set_boxed(&value, wrapper);
217
218 dbusmenu_menuitem_property_set_value(menuitem, DBUSMENU_MENUITEM_PROP_SHORTCUT, &value);
219
220 return TRUE;
221}
222
223/* Look at the closures in an accel group and find
224 the one that matches the one we've been passed */
225static gboolean
226find_closure (GtkAccelKey * key, GClosure * closure, gpointer user_data)
227{
228 return closure == user_data;
229}
230
231/**
232 dbusmenu_menuitem_property_set_shortcut_menuitem:
233 @menuitem: The #DbusmenuMenuitem to set the shortcut on
234 @gmi: A menu item to steal the shortcut off of
235
236 Takes the shortcut that is installed on a menu item and calls
237 #dbusmenu_menuitem_property_set_shortcut with it. It also sets
238 up listeners to watch it change.
239
240 Return value: Whether it was successful at setting the property.
241*/
242gboolean
243dbusmenu_menuitem_property_set_shortcut_menuitem (DbusmenuMenuitem * menuitem, const GtkMenuItem * gmi)
244{
245 g_return_val_if_fail(DBUSMENU_IS_MENUITEM(menuitem), FALSE);
246 g_return_val_if_fail(GTK_IS_MENU_ITEM(gmi), FALSE);
247
248 GClosure * closure = NULL;
249 GList * clist;
250
251 clist = gtk_widget_list_accel_closures(GTK_WIDGET(gmi));
252 if (clist == NULL) {
253 g_warning("Menuitem does not have any closures.");
254 return FALSE;
255 }
256
257 closure = (GClosure *)clist->data;
258 g_list_free(clist);
259
260 GtkAccelGroup * group = gtk_accel_group_from_accel_closure(closure);
261
262 /* Seriously, if this returns NULL something is seriously
263 wrong in GTK. */
264 g_return_val_if_fail(group != NULL, FALSE);
265
266 GtkAccelKey * key = gtk_accel_group_find(group, find_closure, closure);
267 /* Again, not much we can do except complain loudly. */
268 g_return_val_if_fail(key != NULL, FALSE);
269
270 return dbusmenu_menuitem_property_set_shortcut(menuitem, key->accel_key, key->accel_mods);
271}
272
273/**
274 dbusmenu_menuitem_property_get_shortcut:
275 @menuitem: The #DbusmenuMenuitem to get the shortcut off
276 @key: Location to put the key value
277 @modifier: Location to put the modifier mask
278
279 This function gets a GTK shortcut as a key and a mask
280 for use to set the accelerators.
281*/
282void
283dbusmenu_menuitem_property_get_shortcut (DbusmenuMenuitem * menuitem, guint * key, GdkModifierType * modifier)
284{
285 *key = 0;
286 *modifier = 0;
287
288 g_return_if_fail(DBUSMENU_IS_MENUITEM(menuitem));
289
290 const GValue * wrapper = dbusmenu_menuitem_property_get_value(menuitem, DBUSMENU_MENUITEM_PROP_SHORTCUT);
291 if (wrapper == NULL) {
292 return;
293 }
294
295 GValueArray * wrapperarray = (GValueArray *)g_value_get_boxed(wrapper);
296 if (wrapperarray->n_values == 0) {
297 return;
298 }
299
300 if (wrapperarray->n_values != 1) {
301 g_warning("Shortcut is more than one entry. Which we don't currently support. Taking the first.");
302 }
303
304 GValue * ventryarray = g_value_array_get_nth(wrapperarray, 0);
305 GValueArray * entryarray = (GValueArray *)g_value_get_boxed(ventryarray);
306 if (entryarray->n_values == 0) {
307 /* Seems a little odd, but really, we're saying that it isn't a
308 shortcut, so I'm comfortable with exiting silently. */
309 return;
310 }
311
312 /* Parse through modifiers */
313 int i;
314 for (i = 0; i < entryarray->n_values - 1; i++) {
315 if (g_strcmp0(g_value_get_string(g_value_array_get_nth(entryarray, i)), DBUSMENU_MENUITEM_SHORTCUT_CONTROL) == 0) {
316 *modifier |= GDK_CONTROL_MASK;
317 continue;
318 }
319 if (g_strcmp0(g_value_get_string(g_value_array_get_nth(entryarray, i)), DBUSMENU_MENUITEM_SHORTCUT_ALT) == 0) {
320 *modifier |= GDK_MOD1_MASK;
321 continue;
322 }
323 if (g_strcmp0(g_value_get_string(g_value_array_get_nth(entryarray, i)), DBUSMENU_MENUITEM_SHORTCUT_SHIFT) == 0) {
324 *modifier |= GDK_SHIFT_MASK;
325 continue;
326 }
327 if (g_strcmp0(g_value_get_string(g_value_array_get_nth(entryarray, i)), DBUSMENU_MENUITEM_SHORTCUT_SUPER) == 0) {
328 *modifier |= GDK_SUPER_MASK;
329 continue;
330 }
331 }
332
333 GdkModifierType tempmod;
334
335 gtk_accelerator_parse(g_value_get_string(g_value_array_get_nth(entryarray, entryarray->n_values - 1)), key, &tempmod);
336
337 return;
338}
131339
=== modified file 'libdbusmenu-gtk/menuitem.h'
--- libdbusmenu-gtk/menuitem.h 2009-09-02 18:29:01 +0000
+++ libdbusmenu-gtk/menuitem.h 2010-06-21 19:48:28 +0000
@@ -32,8 +32,15 @@
32#include <glib.h>32#include <glib.h>
33#include <gdk-pixbuf/gdk-pixbuf.h>33#include <gdk-pixbuf/gdk-pixbuf.h>
34#include <libdbusmenu-glib/menuitem.h>34#include <libdbusmenu-glib/menuitem.h>
35#include <gdk/gdk.h>
36#include <gtk/gtk.h>
3537
36gboolean dbusmenu_menuitem_property_set_image (DbusmenuMenuitem * menuitem, const gchar * property, const GdkPixbuf * data);38gboolean dbusmenu_menuitem_property_set_image (DbusmenuMenuitem * menuitem, const gchar * property, const GdkPixbuf * data);
37GdkPixbuf * dbusmenu_menuitem_property_get_image (DbusmenuMenuitem * menuitem, const gchar * property);39GdkPixbuf * dbusmenu_menuitem_property_get_image (DbusmenuMenuitem * menuitem, const gchar * property);
3840
41gboolean dbusmenu_menuitem_property_set_shortcut (DbusmenuMenuitem * menuitem, guint key, GdkModifierType modifier);
42gboolean dbusmenu_menuitem_property_set_shortcut_string (DbusmenuMenuitem * menuitem, const gchar * shortcut);
43gboolean dbusmenu_menuitem_property_set_shortcut_menuitem (DbusmenuMenuitem * menuitem, const GtkMenuItem * gmi);
44void dbusmenu_menuitem_property_get_shortcut (DbusmenuMenuitem * menuitem, guint * key, GdkModifierType * modifiers);
45
39#endif46#endif
4047
=== modified file 'tests/Makefile.am'
--- tests/Makefile.am 2010-06-08 18:12:12 +0000
+++ tests/Makefile.am 2010-06-21 19:48:28 +0000
@@ -7,8 +7,10 @@
7 test-glib-properties \7 test-glib-properties \
8 test-glib-proxy \8 test-glib-proxy \
9 test-glib-simple-items \9 test-glib-simple-items \
10 test-gtk-objects-test \
10 test-glib-submenu \11 test-glib-submenu \
11 test-gtk-label \12 test-gtk-label \
13 test-gtk-shortcut \
12 test-gtk-reorder14 test-gtk-reorder
1315
14check_PROGRAMS = \16check_PROGRAMS = \
@@ -21,10 +23,13 @@
21 test-glib-proxy-client \23 test-glib-proxy-client \
22 test-glib-proxy-server \24 test-glib-proxy-server \
23 test-glib-proxy-proxy \25 test-glib-proxy-proxy \
26 test-gtk-objects \
24 test-glib-submenu-client \27 test-glib-submenu-client \
25 test-glib-submenu-server \28 test-glib-submenu-server \
26 test-gtk-label-client \29 test-gtk-label-client \
27 test-gtk-label-server \30 test-gtk-label-server \
31 test-gtk-shortcut-client \
32 test-gtk-shortcut-server \
28 test-glib-simple-items \33 test-glib-simple-items \
29 test-gtk-reorder-server34 test-gtk-reorder-server
3035
@@ -119,7 +124,7 @@
119124
120test-glib-objects-test: test-glib-objects Makefile.am125test-glib-objects-test: test-glib-objects Makefile.am
121 @echo "#!/bin/bash" > $@126 @echo "#!/bin/bash" > $@
122 @echo $(DBUS_RUNNER) --task gtester --parameter --verbose --parameter -k --parameter -o --parameter $(OBJECT_XML_REPORT) --parameter ./test-glib-objects >> $@127 @echo $(DBUS_RUNNER) --task gtester --task-name test --parameter --verbose --parameter -k --parameter -o --parameter $(OBJECT_XML_REPORT) --parameter ./test-glib-objects >> $@
123 @chmod +x $@128 @chmod +x $@
124129
125test_glib_objects_SOURCES = \130test_glib_objects_SOURCES = \
@@ -231,6 +236,34 @@
231 ../libdbusmenu-glib/libdbusmenu-glib.la \236 ../libdbusmenu-glib/libdbusmenu-glib.la \
232 $(DBUSMENUGLIB_LIBS)237 $(DBUSMENUGLIB_LIBS)
233238
239######################
240# Test GTK Object
241######################
242
243GTK_OBJECT_XML_REPORT = test-gtk-objects.xml
244
245test-gtk-objects-test: test-gtk-objects Makefile.am
246 @echo "#!/bin/bash" > $@
247 @echo $(XVFB_RUN) >> $@
248 @echo $(DBUS_RUNNER) --task gtester --task-name test --parameter --verbose --parameter -k --parameter -o --parameter $(GTK_OBJECT_XML_REPORT) --parameter ./test-gtk-objects >> $@
249 @chmod +x $@
250
251test_gtk_objects_SOURCES = \
252 test-gtk-objects.c
253
254test_gtk_objects_CFLAGS = \
255 -I $(srcdir)/.. \
256 $(DBUSMENUGLIB_CFLAGS) \
257 $(DBUSMENUGTK_CFLAGS) \
258 -DSRCDIR="\"$(srcdir)\"" \
259 -Wall -Werror
260
261test_gtk_objects_LDADD = \
262 ../libdbusmenu-glib/libdbusmenu-glib.la \
263 ../libdbusmenu-gtk/libdbusmenu-gtk.la \
264 $(DBUSMENUGLIB_LIBS) \
265 $(DBUSMENUGTK_LIBS)
266
234#########################267#########################
235# Test GTK Label268# Test GTK Label
236#########################269#########################
@@ -272,6 +305,46 @@
272 $(DBUSMENUTESTS_LIBS)305 $(DBUSMENUTESTS_LIBS)
273306
274#########################307#########################
308# Test GTK Shortcut
309#########################
310
311test-gtk-shortcut: test-gtk-shortcut-client test-gtk-shortcut-server Makefile.am
312 @echo "#!/bin/bash" > $@
313 @echo $(XVFB_RUN) >> $@
314 @echo $(DBUS_RUNNER) --task ./test-gtk-shortcut-client --task-name Client --task ./test-gtk-shortcut-server --task-name Server --ignore-return >> $@
315 @chmod +x $@
316
317test_gtk_shortcut_server_SOURCES = \
318 test-gtk-shortcut-server.c
319
320test_gtk_shortcut_server_CFLAGS = \
321 -I $(srcdir)/.. \
322 $(DBUSMENUGTK_CFLAGS) \
323 $(DBUSMENUTESTS_CFLAGS) \
324 $(DBUSMENUGLIB_CFLAGS) -Wall -Werror
325
326test_gtk_shortcut_server_LDADD = \
327 ../libdbusmenu-glib/libdbusmenu-glib.la \
328 ../libdbusmenu-gtk/libdbusmenu-gtk.la \
329 $(DBUSMENUGTK_LIBS) \
330 $(DBUSMENUTESTS_LIBS)
331
332test_gtk_shortcut_client_SOURCES = \
333 test-gtk-shortcut-client.c
334
335test_gtk_shortcut_client_CFLAGS = \
336 -I $(srcdir)/.. \
337 $(DBUSMENUGTK_CFLAGS) \
338 $(DBUSMENUTESTS_CFLAGS) \
339 $(DBUSMENUGLIB_CFLAGS) -Wall -Werror
340
341test_gtk_shortcut_client_LDADD = \
342 ../libdbusmenu-glib/libdbusmenu-glib.la \
343 ../libdbusmenu-gtk/libdbusmenu-gtk.la \
344 $(DBUSMENUGTK_LIBS) \
345 $(DBUSMENUTESTS_LIBS)
346
347#########################
275# Test GTK Reorder348# Test GTK Reorder
276#########################349#########################
277350
@@ -329,6 +402,7 @@
329 $(examples_DATA) \402 $(examples_DATA) \
330 run-xvfb.sh \403 run-xvfb.sh \
331 $(json_DATA) \404 $(json_DATA) \
405 test-gtk-objects.jpg \
332 dbusmenu-gtk/dbusMenuTest \406 dbusmenu-gtk/dbusMenuTest \
333 dbusmenu-gtk/mago_tests/dbusmenu.xml \407 dbusmenu-gtk/mago_tests/dbusmenu.xml \
334 dbusmenu-gtk/mago_tests/dbusmenu.py \408 dbusmenu-gtk/mago_tests/dbusmenu.py \
@@ -357,5 +431,6 @@
357431
358DISTCLEANFILES = \432DISTCLEANFILES = \
359 $(TESTS) \433 $(TESTS) \
360 $(OBJECT_XML_REPORT)434 $(OBJECT_XML_REPORT) \
435 $(GTK_OBJECT_XML_REPORT)
361436
362437
=== modified file 'tests/run-xvfb.sh'
--- tests/run-xvfb.sh 2009-11-20 00:03:49 +0000
+++ tests/run-xvfb.sh 2010-06-21 19:48:28 +0000
@@ -1,4 +1,4 @@
1if [ "$DISPLAY" == "" ]; then1if [ "x$DISPLAY" == "x" ]; then
2Xvfb -ac -noreset -screen 0 800x600x16 -help 2>/dev/null 1>&22Xvfb -ac -noreset -screen 0 800x600x16 -help 2>/dev/null 1>&2
3XID=`for id in 101 102 103 104 105 106 107 197 199 211 223 227 293 307 308 309 310 311 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 4703 4721 4723 4729 4733 4751 9973 9974 9975 9976 9977 9978 9979 9980 9981 9982 9983 9984 9985 9986 9987 9988 9989 9990 9991 9992 9993 9994 9995 9996 9997 9998 9999 ; do test -e /tmp/.X$id-lock || { echo $id; exit 0; }; done; exit 1`3XID=`for id in 101 102 103 104 105 106 107 197 199 211 223 227 293 307 308 309 310 311 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 4703 4721 4723 4729 4733 4751 9973 9974 9975 9976 9977 9978 9979 9980 9981 9982 9983 9984 9985 9986 9987 9988 9989 9990 9991 9992 9993 9994 9995 9996 9997 9998 9999 ; do test -e /tmp/.X$id-lock || { echo $id; exit 0; }; done; exit 1`
4{ Xvfb -ac -noreset -screen 0 800x600x16 :$XID -screen 0 800x600x16 -nolisten tcp -auth /dev/null >/dev/null 2>&1 & trap "kill -15 $! " 0 HUP INT QUIT TRAP USR1 PIPE TERM ; } || { echo "Gtk+Tests:ERROR: Failed to start Xvfb environment for X11 target tests."; exit 1; }4{ Xvfb -ac -noreset -screen 0 800x600x16 :$XID -screen 0 800x600x16 -nolisten tcp -auth /dev/null >/dev/null 2>&1 & trap "kill -15 $! " 0 HUP INT QUIT TRAP USR1 PIPE TERM ; } || { echo "Gtk+Tests:ERROR: Failed to start Xvfb environment for X11 target tests."; exit 1; }
55
=== added file 'tests/test-gtk-objects.c'
--- tests/test-gtk-objects.c 1970-01-01 00:00:00 +0000
+++ tests/test-gtk-objects.c 2010-06-21 19:48:28 +0000
@@ -0,0 +1,145 @@
1/*
2Testing for the various objects just by themselves.
3
4Copyright 2010 Canonical Ltd.
5
6Authors:
7 Ted Gould <ted@canonical.com>
8
9This program is free software: you can redistribute it and/or modify it
10under the terms of the GNU General Public License version 3, as published
11by the Free Software Foundation.
12
13This program is distributed in the hope that it will be useful, but
14WITHOUT ANY WARRANTY; without even the implied warranties of
15MERCHANTABILITY, SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR
16PURPOSE. See the GNU General Public License for more details.
17
18You should have received a copy of the GNU General Public License along
19with this program. If not, see <http://www.gnu.org/licenses/>.
20*/
21
22#include <libdbusmenu-glib/menuitem.h>
23#include <libdbusmenu-gtk/menuitem.h>
24#include <gdk/gdkkeysyms.h>
25
26#define TEST_IMAGE SRCDIR "/" "test-gtk-objects.jpg"
27
28/* Building the basic menu item, make sure we didn't break
29 any core GObject stuff */
30static void
31test_object_menuitem (void)
32{
33 /* Build a menu item */
34 DbusmenuMenuitem * item = dbusmenu_menuitem_new();
35
36 /* Test to make sure it's a happy object */
37 g_assert(item != NULL);
38 g_assert(G_IS_OBJECT(item));
39 g_assert(DBUSMENU_IS_MENUITEM(item));
40
41 /* Set up a check to make sure it gets destroyed on unref */
42 g_object_add_weak_pointer(G_OBJECT(item), (gpointer *)&item);
43 g_object_unref(item);
44
45 /* Did it go away? */
46 g_assert(item == NULL);
47
48 return;
49}
50
51/* Setting and getting a pixbuf */
52static void
53test_object_prop_pixbuf (void)
54{
55 const gchar * prop_name = "image-test";
56
57 /* Build a menu item */
58 DbusmenuMenuitem * item = dbusmenu_menuitem_new();
59
60 /* Test to make sure it's a happy object */
61 g_assert(item != NULL);
62 g_assert(G_IS_OBJECT(item));
63 g_assert(DBUSMENU_IS_MENUITEM(item));
64
65 /* Load our image */
66 GdkPixbuf * pixbuf = gdk_pixbuf_new_from_file(TEST_IMAGE, NULL);
67 g_assert(pixbuf != NULL);
68
69 /* Set the property */
70 gboolean success = dbusmenu_menuitem_property_set_image(item, prop_name, pixbuf);
71 g_assert(success);
72 g_object_unref(pixbuf);
73
74 /* Check to see if it's set */
75 const GValue * val = dbusmenu_menuitem_property_get_value(item, prop_name);
76 g_assert(val != NULL);
77
78 /* Get the pixbuf back! */
79 GdkPixbuf * newpixbuf = dbusmenu_menuitem_property_get_image(item, prop_name);
80 g_assert(newpixbuf != NULL);
81 g_object_unref(newpixbuf);
82
83 g_object_unref(item);
84
85 return;
86}
87
88/* Setting and getting a shortcut */
89static void
90test_object_prop_shortcut (void)
91{
92 /* Build a menu item */
93 DbusmenuMenuitem * item = dbusmenu_menuitem_new();
94
95 /* Test to make sure it's a happy object */
96 g_assert(item != NULL);
97 g_assert(G_IS_OBJECT(item));
98 g_assert(DBUSMENU_IS_MENUITEM(item));
99
100 guint key = GDK_c;
101 GdkModifierType modifier = GDK_CONTROL_MASK;
102
103 /* Set a shortcut */
104 gboolean success = dbusmenu_menuitem_property_set_shortcut(item, key, modifier);
105 g_assert(success);
106
107 /* Check for value */
108 const GValue * val = dbusmenu_menuitem_property_get_value(item, DBUSMENU_MENUITEM_PROP_SHORTCUT);
109 g_assert(val != NULL);
110
111 /* Check to see if we love it */
112 guint newkey = 0;
113 GdkModifierType newmodifier = 0;
114 dbusmenu_menuitem_property_get_shortcut(item, &newkey, &newmodifier);
115
116 g_assert(key == newkey);
117 g_assert(newmodifier == modifier);
118
119 g_object_unref(item);
120
121 return;
122}
123
124/* Build the test suite */
125static void
126test_gtk_objects_suite (void)
127{
128 g_test_add_func ("/dbusmenu/gtk/objects/menuitem/base", test_object_menuitem);
129 g_test_add_func ("/dbusmenu/gtk/objects/menuitem/prop_pixbuf", test_object_prop_pixbuf);
130 g_test_add_func ("/dbusmenu/gtk/objects/menuitem/prop_shortcut", test_object_prop_shortcut);
131 return;
132}
133
134gint
135main (gint argc, gchar * argv[])
136{
137 gtk_init(&argc, &argv);
138
139 g_test_init(&argc, &argv, NULL);
140
141 /* Test suites */
142 test_gtk_objects_suite();
143
144 return g_test_run ();
145}
0146
=== added file 'tests/test-gtk-objects.jpg'
1Binary files tests/test-gtk-objects.jpg 1970-01-01 00:00:00 +0000 and tests/test-gtk-objects.jpg 2010-06-21 19:48:28 +0000 differ147Binary files tests/test-gtk-objects.jpg 1970-01-01 00:00:00 +0000 and tests/test-gtk-objects.jpg 2010-06-21 19:48:28 +0000 differ
=== added file 'tests/test-gtk-shortcut-client.c'
--- tests/test-gtk-shortcut-client.c 1970-01-01 00:00:00 +0000
+++ tests/test-gtk-shortcut-client.c 2010-06-21 19:48:28 +0000
@@ -0,0 +1,76 @@
1/*
2A test for libdbusmenu to ensure its quality.
3
4Copyright 2009 Canonical Ltd.
5
6Authors:
7 Ted Gould <ted@canonical.com>
8
9This program is free software: you can redistribute it and/or modify it
10under the terms of the GNU General Public License version 3, as published
11by the Free Software Foundation.
12
13This program is distributed in the hope that it will be useful, but
14WITHOUT ANY WARRANTY; without even the implied warranties of
15MERCHANTABILITY, SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR
16PURPOSE. See the GNU General Public License for more details.
17
18You should have received a copy of the GNU General Public License along
19with this program. If not, see <http://www.gnu.org/licenses/>.
20*/
21
22#include <gtk/gtk.h>
23#include <libdbusmenu-gtk/menu.h>
24#include <libdbusmenu-gtk/client.h>
25
26static GMainLoop * mainloop = NULL;
27static gboolean passed = TRUE;
28static guint death_timer = 0;
29
30static gboolean
31timer_func (gpointer data)
32{
33 passed = TRUE;
34 g_main_loop_quit(mainloop);
35 return FALSE;
36}
37
38int
39main (int argc, char ** argv)
40{
41 gtk_init(&argc, &argv);
42
43 g_debug("Building Window");
44 GtkWidget * window = gtk_window_new(GTK_WINDOW_TOPLEVEL);
45 GtkWidget * menubar = gtk_menu_bar_new();
46 GtkWidget * menuitem = gtk_menu_item_new_with_label("Test");
47
48 DbusmenuGtkMenu * dmenu = dbusmenu_gtkmenu_new ("glib.label.test", "/org/test");
49 DbusmenuGtkClient * dclient = dbusmenu_gtkmenu_get_client(dmenu);
50
51 GtkAccelGroup * agroup = gtk_accel_group_new();
52 dbusmenu_gtkclient_set_accel_group(dclient, agroup);
53
54 gtk_menu_item_set_submenu(GTK_MENU_ITEM(menuitem), GTK_WIDGET(dmenu));
55 gtk_widget_show(menuitem);
56 gtk_menu_bar_append(menubar, menuitem);
57 gtk_widget_show(menubar);
58 gtk_container_add(GTK_CONTAINER(window), menubar);
59 gtk_window_set_title(GTK_WINDOW(window), "libdbusmenu-gtk test");
60 gtk_window_add_accel_group(GTK_WINDOW(window), agroup);
61 gtk_widget_show(window);
62
63 death_timer = g_timeout_add_seconds(10, timer_func, window);
64
65 g_debug("Entering Mainloop");
66 mainloop = g_main_loop_new(NULL, FALSE);
67 g_main_loop_run(mainloop);
68
69 if (passed) {
70 g_debug("Quiting");
71 return 0;
72 } else {
73 g_debug("Quiting as we're a failure");
74 return 1;
75 }
76}
077
=== added file 'tests/test-gtk-shortcut-server.c'
--- tests/test-gtk-shortcut-server.c 1970-01-01 00:00:00 +0000
+++ tests/test-gtk-shortcut-server.c 2010-06-21 19:48:28 +0000
@@ -0,0 +1,99 @@
1/*
2A test for libdbusmenu to ensure its quality.
3
4Copyright 2009 Canonical Ltd.
5
6Authors:
7 Ted Gould <ted@canonical.com>
8
9This program is free software: you can redistribute it and/or modify it
10under the terms of the GNU General Public License version 3, as published
11by the Free Software Foundation.
12
13This program is distributed in the hope that it will be useful, but
14WITHOUT ANY WARRANTY; without even the implied warranties of
15MERCHANTABILITY, SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR
16PURPOSE. See the GNU General Public License for more details.
17
18You should have received a copy of the GNU General Public License along
19with this program. If not, see <http://www.gnu.org/licenses/>.
20*/
21
22#include <glib.h>
23#include <gdk/gdkkeysyms.h>
24
25#include <dbus/dbus.h>
26#include <dbus/dbus-glib.h>
27#include <dbus/dbus-glib-lowlevel.h>
28#include <dbus/dbus-glib-bindings.h>
29
30#include <libdbusmenu-glib/menuitem.h>
31#include <libdbusmenu-glib/server.h>
32#include <libdbusmenu-gtk/menuitem.h>
33
34GMainLoop * mainloop = NULL;
35DbusmenuServer * server = NULL;
36
37gboolean
38timer_func (gpointer userdata)
39{
40 g_main_loop_quit(mainloop);
41 return FALSE;
42}
43
44void
45build_menu (void)
46{
47 DbusmenuMenuitem * item;
48
49 DbusmenuMenuitem * root = dbusmenu_menuitem_new();
50
51 item = dbusmenu_menuitem_new();
52 dbusmenu_menuitem_property_set(item, DBUSMENU_MENUITEM_PROP_LABEL, "Control-L");
53 dbusmenu_menuitem_property_set_shortcut(item, GDK_l, GDK_CONTROL_MASK);
54 dbusmenu_menuitem_child_append(root, item);
55 g_object_unref(item);
56
57
58 dbusmenu_server_set_root(server, root);
59 g_object_unref(root);
60
61 return;
62}
63
64int
65main (int argc, char ** argv)
66{
67 GError * error = NULL;
68
69 g_type_init();
70
71 DBusGConnection * connection = dbus_g_bus_get(DBUS_BUS_SESSION, NULL);
72 g_debug("DBus ID: %s", dbus_connection_get_server_id(dbus_g_connection_get_connection(dbus_g_bus_get(DBUS_BUS_SESSION, NULL))));
73
74 DBusGProxy * bus_proxy = dbus_g_proxy_new_for_name(connection, DBUS_SERVICE_DBUS, DBUS_PATH_DBUS, DBUS_INTERFACE_DBUS);
75 guint nameret = 0;
76
77 if (!org_freedesktop_DBus_request_name(bus_proxy, "glib.label.test", 0, &nameret, &error)) {
78 g_error("Unable to call to request name");
79 return 1;
80 }
81
82 if (nameret != DBUS_REQUEST_NAME_REPLY_PRIMARY_OWNER) {
83 g_error("Unable to get name");
84 return 1;
85 }
86
87 server = dbusmenu_server_new("/org/test");
88 build_menu();
89
90 g_timeout_add_seconds(10, timer_func, NULL);
91
92 mainloop = g_main_loop_new(NULL, FALSE);
93 g_main_loop_run(mainloop);
94
95 g_debug("Quiting");
96
97 return 0;
98}
99

Subscribers

People subscribed via source and target branches