Merge lp:~ted/indicator-application/property-for-dbus-stuff into lp:indicator-application/0.4

Proposed by Ted Gould
Status: Merged
Merge reported by: Ted Gould
Merged at revision: not available
Proposed branch: lp:~ted/indicator-application/property-for-dbus-stuff
Merge into: lp:indicator-application/0.4
Diff against target: 155 lines (+84/-1)
2 files modified
src/app-indicator.c (+29/-1)
tests/test-libappindicator.c (+55/-0)
To merge this branch: bzr merge lp:~ted/indicator-application/property-for-dbus-stuff
Reviewer Review Type Date Requested Status
Indicator Applet Developers Pending
Review via email: mp+40688@code.launchpad.net

Description of the change

Adding a property to get the dbusmenu server so we can use it for testing. Oh, and a test to prove that it can be used for testing :)

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
1=== modified file 'src/app-indicator.c'
2--- src/app-indicator.c 2010-10-20 19:22:46 +0000
3+++ src/app-indicator.c 2010-11-12 04:40:04 +0000
4@@ -34,6 +34,7 @@
5 #include <dbus/dbus-glib.h>
6 #include <dbus/dbus-glib-bindings.h>
7
8+#include <libdbusmenu-glib/menuitem.h>
9 #include <libdbusmenu-glib/server.h>
10 #include <libdbusmenu-gtk/client.h>
11
12@@ -121,7 +122,8 @@
13 PROP_X_LABEL,
14 PROP_X_LABEL_GUIDE,
15 PROP_ORDERING_INDEX,
16- PROP_X_ORDERING_INDEX
17+ PROP_X_ORDERING_INDEX,
18+ PROP_DBUS_MENU_SERVER
19 };
20
21 /* The strings so that they can be slowly looked up. */
22@@ -139,6 +141,7 @@
23 #define PROP_X_LABEL_GUIDE_S ("x-ayatana-" PROP_LABEL_GUIDE_S)
24 #define PROP_ORDERING_INDEX_S "ordering-index"
25 #define PROP_X_ORDERING_INDEX_S ("x-ayatana-" PROP_ORDERING_INDEX_S)
26+#define PROP_DBUS_MENU_SERVER_S "dbus-menu-server"
27
28 /* Private macro, shhhh! */
29 #define APP_INDICATOR_GET_PRIVATE(o) \
30@@ -406,6 +409,19 @@
31 "A wrapper, please don't use.",
32 NULL,
33 G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
34+ /**
35+ AppIndicator:dbus-menu-server:
36+
37+ A way to get the internal dbusmenu server if it is available.
38+ This should only be used for testing.
39+ */
40+ g_object_class_install_property(object_class,
41+ PROP_DBUS_MENU_SERVER,
42+ g_param_spec_object (PROP_DBUS_MENU_SERVER_S,
43+ "The internal DBusmenu Server",
44+ "DBusmenu server which is available for testing the application indicators.",
45+ DBUSMENU_TYPE_SERVER,
46+ G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
47
48 /* Signals */
49
50@@ -794,6 +810,14 @@
51 priv->ordering_index = g_value_get_uint(value);
52 break;
53
54+ case PROP_DBUS_MENU_SERVER:
55+ if (priv->menuservice != NULL) {
56+ g_object_unref (priv->menuservice);
57+ }
58+ gpointer val = g_value_dup_object(value);
59+ priv->menuservice = DBUSMENU_SERVER(val);
60+ break;
61+
62 default:
63 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
64 break;
65@@ -866,6 +890,10 @@
66 g_value_set_uint(value, priv->ordering_index);
67 break;
68
69+ case PROP_DBUS_MENU_SERVER:
70+ g_value_set_object(value, priv->menuservice);
71+ break;
72+
73 default:
74 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
75 break;
76
77=== modified file 'tests/test-libappindicator.c'
78--- tests/test-libappindicator.c 2010-08-04 02:13:34 +0000
79+++ tests/test-libappindicator.c 2010-11-12 04:40:04 +0000
80@@ -25,6 +25,9 @@
81
82 #include <app-indicator.h>
83
84+#include <libdbusmenu-glib/menuitem.h>
85+#include <libdbusmenu-glib/server.h>
86+
87 void
88 test_libappindicator_prop_signals_status_helper (AppIndicator * ci, gchar * status, gboolean * signalactivated)
89 {
90@@ -225,6 +228,57 @@
91 }
92
93 void
94+test_libappindicator_set_menu (void)
95+{
96+ AppIndicator * ci = app_indicator_new ("my-id",
97+ "my-name",
98+ APP_INDICATOR_CATEGORY_APPLICATION_STATUS);
99+
100+ g_assert(ci != NULL);
101+
102+ GtkMenu * menu = GTK_MENU(gtk_menu_new());
103+
104+ GtkMenuItem * item = GTK_MENU_ITEM(gtk_menu_item_new_with_label("Test Label"));
105+ gtk_menu_shell_append(GTK_MENU_SHELL(menu), GTK_WIDGET(item));
106+ gtk_widget_show(GTK_WIDGET(item));
107+
108+ app_indicator_set_menu(ci, menu);
109+
110+ g_assert(app_indicator_get_menu(ci) != NULL);
111+
112+ GValue serverval = {0};
113+ g_value_init(&serverval, DBUSMENU_TYPE_SERVER);
114+ g_object_get_property(G_OBJECT(ci), "dbus-menu-server", &serverval);
115+
116+ DbusmenuServer * server = DBUSMENU_SERVER(g_value_get_object(&serverval));
117+ g_assert(server != NULL);
118+
119+ GValue rootval = {0};
120+ g_value_init(&rootval, DBUSMENU_TYPE_MENUITEM);
121+ g_object_get_property(G_OBJECT(server), DBUSMENU_SERVER_PROP_ROOT_NODE, &rootval);
122+ DbusmenuMenuitem * root = DBUSMENU_MENUITEM(g_value_get_object(&rootval));
123+ g_assert(root != NULL);
124+
125+ GList * children = dbusmenu_menuitem_get_children(root);
126+ g_assert(children != NULL);
127+ g_assert(g_list_length(children) == 1);
128+
129+ const gchar * label = dbusmenu_menuitem_property_get(DBUSMENU_MENUITEM(children->data), DBUSMENU_MENUITEM_PROP_LABEL);
130+ g_assert(label != NULL);
131+ g_assert(g_strcmp0(label, "Test Label") == 0);
132+
133+ /* Interesting, eh? We need this because we send out events on the bus
134+ but they don't come back until the idle is run. So we need those
135+ events to clear before removing the object */
136+ while (g_main_context_pending(NULL)) {
137+ g_main_context_iteration(NULL, TRUE);
138+ }
139+
140+ g_object_unref(G_OBJECT(ci));
141+ return;
142+}
143+
144+void
145 label_signals_cb (AppIndicator * appindicator, gchar * label, gchar * guide, gpointer user_data)
146 {
147 gint * label_signals_count = (gint *)user_data;
148@@ -301,6 +355,7 @@
149 g_test_add_func ("/indicator-application/libappindicator/init_set_props", test_libappindicator_init_set_props);
150 g_test_add_func ("/indicator-application/libappindicator/prop_signals", test_libappindicator_prop_signals);
151 g_test_add_func ("/indicator-application/libappindicator/set_label", test_libappindicator_set_label);
152+ g_test_add_func ("/indicator-application/libappindicator/set_menu", test_libappindicator_set_menu);
153 g_test_add_func ("/indicator-application/libappindicator/label_signals", test_libappindicator_label_signals);
154
155 return;

Subscribers

People subscribed via source and target branches