Merge lp:~mterry/indicator-session/gdbus into lp:indicator-session/0.1

Proposed by Michael Terry
Status: Merged
Merged at revision: 130
Proposed branch: lp:~mterry/indicator-session/gdbus
Merge into: lp:indicator-session/0.1
Diff against target: 652 lines (+274/-96)
5 files modified
.bzrignore (+2/-2)
configure.ac (+4/-3)
src/Makefile.am (+14/-18)
src/indicator-session.c (+107/-44)
src/session-dbus.c (+147/-29)
To merge this branch: bzr merge lp:~mterry/indicator-session/gdbus
Reviewer Review Type Date Requested Status
Ken VanDine Approve
Review via email: mp+45885@code.launchpad.net

Description of the change

Ported to gdbus! (only the actual indicator part, not the bits that talk to other services over dbus)

To post a comment you must log in.
lp:~mterry/indicator-session/gdbus updated
131. By Michael Terry

also dispose of canel object

132. By Michael Terry

and cancel the cancel object

Revision history for this message
Sebastien Bacher (seb128) wrote :

out the serivce-> service typo the changes seems fine to me, not setting to "approve" since I'm not an official member of the indicator team though...

Revision history for this message
Sebastien Bacher (seb128) wrote :

oh, it seems you forgot to add gen-session-dbus.xml.*

Revision history for this message
Sebastien Bacher (seb128) wrote :

ignore the previous comment I forgot to run autoreconf before building the new version.

Revision history for this message
Ken VanDine (ken-vandine) wrote :

Thx for the review @seb128, setting to approved

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file '.bzrignore'
2--- .bzrignore 2010-03-17 13:09:07 +0000
3+++ .bzrignore 2011-01-11 19:02:23 +0000
4@@ -55,8 +55,8 @@
5 indicator-session-[0-9].[0-9].[0-9].tar.gz.asc
6 indicator-session-[0-9].[0-9].tar.gz.asc
7 src/consolekit-manager-client.h
8-src/session-dbus-client.h
9-src/session-dbus-server.h
10+src/gen-session-dbus.xml.c
11+src/gen-session-dbus.xml.h
12 src/upower-client.h
13 src/gdm-local-display-factory-client.h
14 src/consolekit-session-client.h
15
16=== modified file 'configure.ac'
17--- configure.ac 2010-08-12 16:32:35 +0000
18+++ configure.ac 2011-01-11 19:02:23 +0000
19@@ -32,14 +32,15 @@
20
21 PKG_CHECK_MODULES(APPLET, gtk+-2.0 >= $GTK_REQUIRED_VERSION
22 indicator >= $INDICATOR_REQUIRED_VERSION
23- dbusmenu-gtk >= $DBUSMENUGTK_REQUIRED_VERSION)
24+ dbusmenu-gtk-0.4 >= $DBUSMENUGTK_REQUIRED_VERSION)
25 AC_SUBST(APPLET_CFLAGS)
26 AC_SUBST(APPLET_LIBS)
27
28 DBUSMENUGLIB_REQUIRED_VERSION=0.1.1
29
30-PKG_CHECK_MODULES(SESSIONSERVICE, dbusmenu-glib >= $DBUSMENUGLIB_REQUIRED_VERSION
31- dbusmenu-gtk >= $DBUSMENUGTK_REQUIRED_VERSION
32+PKG_CHECK_MODULES(SESSIONSERVICE, dbusmenu-glib-0.4 >= $DBUSMENUGLIB_REQUIRED_VERSION
33+ dbusmenu-gtk-0.4 >= $DBUSMENUGTK_REQUIRED_VERSION
34+ dbus-glib-1
35 gio-unix-2.0
36 indicator >= $INDICATOR_REQUIRED_VERSION)
37
38
39=== modified file 'src/Makefile.am'
40--- src/Makefile.am 2010-03-17 13:09:07 +0000
41+++ src/Makefile.am 2011-01-11 19:02:23 +0000
42@@ -11,7 +11,7 @@
43 sessionlib_LTLIBRARIES = libsession.la
44 libsession_la_SOURCES = \
45 indicator-session.c \
46- session-dbus-client.h \
47+ gen-session-dbus.xml.h \
48 dbus-shared-names.h \
49 dbusmenu-shared.h \
50 users-service-client.h
51@@ -54,20 +54,6 @@
52 --output=upower-client.h \
53 $(srcdir)/upower.xml
54
55-session-dbus-client.h: $(srcdir)/session-dbus.xml
56- dbus-binding-tool \
57- --prefix=_session_dbus_client \
58- --mode=glib-client \
59- --output=session-dbus-client.h \
60- $(srcdir)/session-dbus.xml
61-
62-session-dbus-server.h: $(srcdir)/session-dbus.xml
63- dbus-binding-tool \
64- --prefix=_session_dbus_server \
65- --mode=glib-server \
66- --output=session-dbus-server.h \
67- $(srcdir)/session-dbus.xml
68-
69 users-service-marshal.h: $(srcdir)/users-service.list
70 glib-genmarshal --header \
71 --prefix=_users_service_marshal $(srcdir)/users-service.list \
72@@ -78,6 +64,16 @@
73 --prefix=_users_service_marshal $(srcdir)/users-service.list \
74 > users-service-marshal.c
75
76+gen-%.xml.c: %.xml
77+ @echo "Building $@ from $<"
78+ @echo "const char * _$(subst -,_,$(subst .,_,$(basename $<))) = " > $@
79+ @sed -e "s:\":\\\\\":g" -e s:^:\": -e s:\$$:\\\\n\": $< >> $@
80+ @echo ";" >> $@
81+
82+gen-%.xml.h: %.xml
83+ @echo "Building $@ from $<"
84+ @echo "extern const char * _$(subst -,_,$(subst .,_,$(basename $<)));" > $@
85+
86 #################
87 # Session Stuff
88 #################
89@@ -88,7 +84,7 @@
90 session-service.c \
91 session-dbus.c \
92 session-dbus.h \
93- session-dbus-server.h \
94+ gen-session-dbus.xml.c \
95 dbusmenu-shared.h \
96 gconf-helper.c \
97 users-service-dbus.h \
98@@ -129,8 +125,8 @@
99 consolekit-manager-client.h \
100 consolekit-session-client.h \
101 gdm-local-display-factory-client.h \
102- session-dbus-client.h \
103- session-dbus-server.h \
104+ gen-session-dbus.xml.c \
105+ gen-session-dbus.xml.h \
106 upower-client.h \
107 users-service-client.h \
108 users-service-marshal.h \
109
110=== modified file 'src/indicator-session.c'
111--- src/indicator-session.c 2010-08-06 18:45:10 +0000
112+++ src/indicator-session.c 2011-01-11 19:02:23 +0000
113@@ -31,9 +31,6 @@
114 #include <gio/gio.h>
115 #include <libdbusmenu-gtk/menu.h>
116
117-#include <dbus/dbus-glib.h>
118-#include <dbus/dbus-glib-bindings.h>
119-
120 #include <libindicator/indicator.h>
121 #include <libindicator/indicator-object.h>
122 #include <libindicator/indicator-service-manager.h>
123@@ -41,7 +38,6 @@
124
125 #include "dbus-shared-names.h"
126 #include "dbusmenu-shared.h"
127-#include "session-dbus-client.h"
128
129 #define INDICATOR_SESSION_TYPE (indicator_session_get_type ())
130 #define INDICATOR_SESSION(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), INDICATOR_SESSION_TYPE, IndicatorSession))
131@@ -62,7 +58,8 @@
132 IndicatorServiceManager * service;
133 GtkImage * status_image;
134 DbusmenuGtkMenu * menu;
135- DBusGProxy * service_proxy;
136+ GCancellable * service_proxy_cancel;
137+ GDBusProxy * service_proxy;
138 };
139
140 GType indicator_session_get_type (void);
141@@ -77,9 +74,11 @@
142 static GtkMenu * get_menu (IndicatorObject * io);
143 static gboolean build_menu_switch (DbusmenuMenuitem * newitem, DbusmenuMenuitem * parent, DbusmenuClient * client);
144 static gboolean new_user_item (DbusmenuMenuitem * newitem, DbusmenuMenuitem * parent, DbusmenuClient * client);
145-static void icon_changed (DBusGProxy * proxy, gchar * icon_name, gpointer user_data);
146+static void icon_changed (IndicatorSession * session, const gchar * icon_name);
147 static void service_connection_cb (IndicatorServiceManager * sm, gboolean connected, gpointer user_data);
148 static gboolean build_restart_item (DbusmenuMenuitem * newitem, DbusmenuMenuitem * parent, DbusmenuClient * client);
149+static void receive_signal (GDBusProxy * proxy, gchar * sender_name, gchar * signal_name, GVariant * parameters, gpointer user_data);
150+static void service_proxy_cb (GObject * object, GAsyncResult * res, gpointer user_data);
151
152 static void indicator_session_class_init (IndicatorSessionClass *klass);
153 static void indicator_session_init (IndicatorSession *self);
154@@ -109,6 +108,8 @@
155 {
156 /* Set good defaults */
157 self->service = NULL;
158+ self->service_proxy_cancel = NULL;
159+ self->service_proxy = NULL;
160
161 /* Now let's fire these guys up. */
162 self->service = indicator_service_manager_new_version(INDICATOR_SESSION_DBUS_NAME, INDICATOR_SESSION_DBUS_VERSION);
163@@ -125,19 +126,50 @@
164 GtkAccelGroup * agroup = gtk_accel_group_new();
165 dbusmenu_gtkclient_set_accel_group(DBUSMENU_GTKCLIENT(client), agroup);
166
167- DBusGConnection * session_bus = dbus_g_bus_get(DBUS_BUS_SESSION, NULL);
168- self->service_proxy = dbus_g_proxy_new_for_name(session_bus,
169- INDICATOR_SESSION_DBUS_NAME,
170- INDICATOR_SESSION_SERVICE_DBUS_OBJECT,
171- INDICATOR_SESSION_SERVICE_DBUS_IFACE);
172-
173- dbus_g_proxy_add_signal(self->service_proxy, "IconUpdated",
174- G_TYPE_STRING, G_TYPE_INVALID);
175- dbus_g_proxy_connect_signal(self->service_proxy,
176- "IconUpdated",
177- G_CALLBACK(icon_changed),
178- self,
179- NULL);
180+ self->service_proxy_cancel = g_cancellable_new();
181+
182+ g_dbus_proxy_new_for_bus (G_BUS_TYPE_SESSION,
183+ G_DBUS_PROXY_FLAGS_NONE,
184+ NULL,
185+ INDICATOR_SESSION_DBUS_NAME,
186+ INDICATOR_SESSION_SERVICE_DBUS_OBJECT,
187+ INDICATOR_SESSION_SERVICE_DBUS_IFACE,
188+ self->service_proxy_cancel,
189+ service_proxy_cb,
190+ self);
191+
192+ return;
193+}
194+
195+/* Callback from trying to create the proxy for the serivce, this
196+ could include starting the service. Sometime it'll fail and
197+ we'll try to start that dang service again! */
198+static void
199+service_proxy_cb (GObject * object, GAsyncResult * res, gpointer user_data)
200+{
201+ GError * error = NULL;
202+
203+ IndicatorSession * self = INDICATOR_SESSION(user_data);
204+ g_return_if_fail(self != NULL);
205+
206+ GDBusProxy * proxy = g_dbus_proxy_new_for_bus_finish(res, &error);
207+
208+ if (self->service_proxy_cancel != NULL) {
209+ g_object_unref(self->service_proxy_cancel);
210+ self->service_proxy_cancel = NULL;
211+ }
212+
213+ if (error != NULL) {
214+ g_error("Could not grab DBus proxy for %s: %s", INDICATOR_SESSION_DBUS_NAME, error->message);
215+ g_error_free(error);
216+ return;
217+ }
218+
219+ /* Okay, we're good to grab the proxy at this point, we're
220+ sure that it's ours. */
221+ self->service_proxy = proxy;
222+
223+ g_signal_connect(proxy, "g-signal", G_CALLBACK(receive_signal), self);
224
225 return;
226 }
227@@ -157,6 +189,12 @@
228 self->service_proxy = NULL;
229 }
230
231+ if (self->service_proxy_cancel != NULL) {
232+ g_cancellable_cancel(self->service_proxy_cancel);
233+ g_object_unref(self->service_proxy_cancel);
234+ self->service_proxy_cancel = NULL;
235+ }
236+
237 G_OBJECT_CLASS (indicator_session_parent_class)->dispose (object);
238 return;
239 }
240@@ -170,18 +208,26 @@
241 }
242
243 static void
244-icon_name_get_cb (DBusGProxy *proxy, char * OUT_name, GError *error, gpointer userdata)
245+icon_name_get_cb (GObject * obj, GAsyncResult * res, gpointer user_data)
246 {
247+ IndicatorSession * self = INDICATOR_SESSION(user_data);
248+ GError * error = NULL;
249+ gchar * name;
250+ GVariant * result;
251+
252+ result = g_dbus_proxy_call_finish(self->service_proxy, res, &error);
253+
254 if (error != NULL) {
255 return;
256 }
257
258- if (OUT_name == NULL || OUT_name[0] == '\0') {
259+ g_variant_get(result, "(&s)", &name);
260+
261+ if (name == NULL || name[0] == '\0') {
262 return;
263 }
264
265- IndicatorSession * self = INDICATOR_SESSION(userdata);
266- indicator_image_helper_update(self->status_image, OUT_name);
267+ indicator_image_helper_update(self->status_image, name);
268 return;
269 }
270
271@@ -191,7 +237,9 @@
272 IndicatorSession * self = INDICATOR_SESSION(user_data);
273
274 if (connected) {
275- org_ayatana_indicator_session_service_get_icon_async(self->service_proxy, icon_name_get_cb, user_data);
276+ g_dbus_proxy_call(self->service_proxy, "GetIcon", NULL,
277+ G_DBUS_CALL_FLAGS_NONE, -1, NULL,
278+ icon_name_get_cb, user_data);
279 } else {
280 indicator_image_helper_update(self->status_image, ICON_DEFAULT);
281 }
282@@ -206,13 +254,28 @@
283 }
284
285 static void
286-icon_changed (DBusGProxy * proxy, gchar * icon_name, gpointer user_data)
287+icon_changed (IndicatorSession * session, const gchar * icon_name)
288 {
289- IndicatorSession * session = INDICATOR_SESSION(user_data);
290 indicator_image_helper_update(session->status_image, icon_name);
291 return;
292 }
293
294+/* Receives all signals from the service, routed to the appropriate functions */
295+static void
296+receive_signal (GDBusProxy * proxy, gchar * sender_name, gchar * signal_name,
297+ GVariant * parameters, gpointer user_data)
298+{
299+ IndicatorSession * self = INDICATOR_SESSION(user_data);
300+
301+ if (g_strcmp0(signal_name, "IconUpdated") == 0) {
302+ const gchar *name;
303+ g_variant_get (parameters, "(&s)", &name);
304+ icon_changed(self, name);
305+ }
306+
307+ return;
308+}
309+
310 static GtkImage *
311 get_icon (IndicatorObject * io)
312 {
313@@ -221,10 +284,10 @@
314 }
315
316 static void
317-user_property_change (DbusmenuMenuitem * item, const gchar * property, const GValue * value, gpointer user_data)
318+user_property_change (DbusmenuMenuitem * item, const gchar * property, GVariant * variant, gpointer user_data)
319 {
320 if (g_strcmp0(property, USER_ITEM_PROP_LOGGED_IN) == 0) {
321- if (g_value_get_boolean(value)) {
322+ if (g_variant_get_boolean(variant)) {
323 gtk_widget_show(GTK_WIDGET(user_data));
324 } else {
325 gtk_widget_hide(GTK_WIDGET(user_data));
326@@ -308,7 +371,7 @@
327 }
328
329 static void
330-switch_property_change (DbusmenuMenuitem * item, const gchar * property, const GValue * value, gpointer user_data)
331+switch_property_change (DbusmenuMenuitem * item, const gchar * property, GVariant * variant, gpointer user_data)
332 {
333 if (g_strcmp0(property, MENU_SWITCH_USER) != 0) {
334 return;
335@@ -330,13 +393,13 @@
336 /* If there's a NULL string of some type, then we want to
337 go back to our old 'Switch User' which isn't great but
338 eh, this error condition should never happen. */
339- if (value == NULL || g_value_get_string(value) == NULL || g_value_get_string(value)[0] == '\0' || no_name_in_lang) {
340+ if (variant == NULL || g_variant_get_string(variant, NULL) == NULL || g_variant_get_string(variant, NULL)[0] == '\0' || no_name_in_lang) {
341 finalstring = _("Switch User...");
342 set_ellipsize = FALSE;
343 }
344
345 if (finalstring == NULL) {
346- const gchar * username = g_value_get_string(value);
347+ const gchar * username = g_variant_get_string(variant, NULL);
348 GtkStyle * style = gtk_widget_get_style(GTK_WIDGET(gmi));
349
350 PangoLayout * layout = pango_layout_new(gtk_widget_get_pango_context(GTK_WIDGET(gmi)));
351@@ -387,17 +450,17 @@
352 /* IF the label or icon changes we need to grab that and update
353 the menu item */
354 static void
355-restart_property_change (DbusmenuMenuitem * item, const gchar * property, const GValue * value, gpointer user_data)
356+restart_property_change (DbusmenuMenuitem * item, const gchar * property, GVariant * variant, gpointer user_data)
357 {
358 DbusmenuGtkClient * client = DBUSMENU_GTKCLIENT(user_data);
359 GtkMenuItem * gmi = dbusmenu_gtkclient_menuitem_get(client, item);
360
361 if (g_strcmp0(property, RESTART_ITEM_LABEL) == 0) {
362- gtk_menu_item_set_label(gmi, g_value_get_string(value));
363+ gtk_menu_item_set_label(gmi, g_variant_get_string(variant, NULL));
364 } else if (g_strcmp0(property, RESTART_ITEM_ICON) == 0) {
365 GtkWidget * image = gtk_image_menu_item_get_image(GTK_IMAGE_MENU_ITEM(gmi));
366
367- GIcon * gicon = g_themed_icon_new_with_default_fallbacks(g_value_get_string(value));
368+ GIcon * gicon = g_themed_icon_new_with_default_fallbacks(g_variant_get_string(variant, NULL));
369 if (image == NULL) {
370 image = gtk_image_new_from_gicon(gicon, GTK_ICON_SIZE_MENU);
371 gtk_image_menu_item_set_image(GTK_IMAGE_MENU_ITEM(gmi), image);
372@@ -424,16 +487,16 @@
373
374 g_signal_connect(G_OBJECT(newitem), DBUSMENU_MENUITEM_SIGNAL_PROPERTY_CHANGED, G_CALLBACK(restart_property_change), client);
375
376- /* Grab the inital values and put them into the item */
377- const GValue * value;
378- value = dbusmenu_menuitem_property_get_value(newitem, RESTART_ITEM_LABEL);
379- if (value != NULL) {
380- restart_property_change(newitem, RESTART_ITEM_LABEL, value, client);
381+ /* Grab the inital variants and put them into the item */
382+ GVariant * variant;
383+ variant = dbusmenu_menuitem_property_get_variant(newitem, RESTART_ITEM_LABEL);
384+ if (variant != NULL) {
385+ restart_property_change(newitem, RESTART_ITEM_LABEL, variant, client);
386 }
387
388- value = dbusmenu_menuitem_property_get_value(newitem, RESTART_ITEM_ICON);
389- if (value != NULL) {
390- restart_property_change(newitem, RESTART_ITEM_ICON, value, client);
391+ variant = dbusmenu_menuitem_property_get_variant(newitem, RESTART_ITEM_ICON);
392+ if (variant != NULL) {
393+ restart_property_change(newitem, RESTART_ITEM_ICON, variant, client);
394 }
395
396 return TRUE;
397@@ -448,7 +511,7 @@
398 DbusmenuGtkClient * client = DBUSMENU_GTKCLIENT(user_data);
399 DbusmenuMenuitem * mi = DBUSMENU_MENUITEM(g_object_get_data(G_OBJECT(widget), dbusmenu_item_data));
400
401- switch_property_change(mi, MENU_SWITCH_USER, dbusmenu_menuitem_property_get_value(mi, MENU_SWITCH_USER), client);
402+ switch_property_change(mi, MENU_SWITCH_USER, dbusmenu_menuitem_property_get_variant(mi, MENU_SWITCH_USER), client);
403 return;
404 }
405
406@@ -468,7 +531,7 @@
407
408 g_signal_connect(G_OBJECT(newitem), DBUSMENU_MENUITEM_SIGNAL_PROPERTY_CHANGED, G_CALLBACK(switch_property_change), client);
409 g_signal_connect(G_OBJECT(gmi), "style-set", G_CALLBACK(switch_style_set), client);
410- switch_property_change(newitem, MENU_SWITCH_USER, dbusmenu_menuitem_property_get_value(newitem, MENU_SWITCH_USER), client);
411+ switch_property_change(newitem, MENU_SWITCH_USER, dbusmenu_menuitem_property_get_variant(newitem, MENU_SWITCH_USER), client);
412
413 return TRUE;
414 }
415
416=== modified file 'src/session-dbus.c'
417--- src/session-dbus.c 2010-03-12 22:10:57 +0000
418+++ src/session-dbus.c 2011-01-11 19:02:23 +0000
419@@ -23,25 +23,33 @@
420 #include "config.h"
421 #endif
422
423+#include <gio/gio.h>
424+
425 #include "session-dbus.h"
426 #include "dbus-shared-names.h"
427
428-static gboolean _session_dbus_server_get_icon (SessionDbus * service, gchar ** icon, GError ** error);
429+static GVariant * get_icon (SessionDbus * service);
430+static void bus_get_cb (GObject * object, GAsyncResult * res, gpointer user_data);
431+static void bus_method_call (GDBusConnection * connection, const gchar * sender, const gchar * path, const gchar * interface, const gchar * method, GVariant * params, GDBusMethodInvocation * invocation, gpointer user_data);
432
433-#include "session-dbus-server.h"
434+#include "gen-session-dbus.xml.h"
435
436 typedef struct _SessionDbusPrivate SessionDbusPrivate;
437 struct _SessionDbusPrivate {
438 gchar * name;
439-};
440-
441-/* Signals */
442-enum {
443- ICON_UPDATED,
444- LAST_SIGNAL
445-};
446-
447-static guint signals[LAST_SIGNAL] = { 0 };
448+ GDBusConnection * bus;
449+ GCancellable * bus_cancel;
450+ guint dbus_registration;
451+};
452+
453+/* GDBus Stuff */
454+static GDBusNodeInfo * node_info = NULL;
455+static GDBusInterfaceInfo * interface_info = NULL;
456+static GDBusInterfaceVTable interface_table = {
457+ method_call: bus_method_call,
458+ get_property: NULL, /* No properties */
459+ set_property: NULL /* No properties */
460+};
461
462 #define SESSION_DBUS_GET_PRIVATE(o) \
463 (G_TYPE_INSTANCE_GET_PRIVATE ((o), SESSION_DBUS_TYPE, SessionDbusPrivate))
464@@ -63,15 +71,24 @@
465 object_class->dispose = session_dbus_dispose;
466 object_class->finalize = session_dbus_finalize;
467
468- signals[ICON_UPDATED] = g_signal_new ("icon-updated",
469- G_TYPE_FROM_CLASS (klass),
470- G_SIGNAL_RUN_LAST,
471- G_STRUCT_OFFSET (SessionDbusClass, icon_updated),
472- NULL, NULL,
473- g_cclosure_marshal_VOID__STRING,
474- G_TYPE_NONE, 1, G_TYPE_STRING);
475-
476- dbus_g_object_type_install_info(SESSION_DBUS_TYPE, &dbus_glib__session_dbus_server_object_info);
477+ /* Setting up the DBus interfaces */
478+ if (node_info == NULL) {
479+ GError * error = NULL;
480+
481+ node_info = g_dbus_node_info_new_for_xml(_session_dbus, &error);
482+ if (error != NULL) {
483+ g_error("Unable to parse Session Service Interface description: %s", error->message);
484+ g_error_free(error);
485+ }
486+ }
487+
488+ if (interface_info == NULL) {
489+ interface_info = g_dbus_node_info_lookup_interface(node_info, INDICATOR_SESSION_SERVICE_DBUS_IFACE);
490+
491+ if (interface_info == NULL) {
492+ g_error("Unable to find interface '" INDICATOR_SESSION_SERVICE_DBUS_IFACE "'");
493+ }
494+ }
495
496 return;
497 }
498@@ -79,19 +96,104 @@
499 static void
500 session_dbus_init (SessionDbus *self)
501 {
502- DBusGConnection * session = dbus_g_bus_get(DBUS_BUS_SESSION, NULL);
503- dbus_g_connection_register_g_object(session, INDICATOR_SESSION_SERVICE_DBUS_OBJECT, G_OBJECT(self));
504-
505 SessionDbusPrivate * priv = SESSION_DBUS_GET_PRIVATE(self);
506
507 priv->name = g_strdup(ICON_DEFAULT);
508-
509+ priv->bus = NULL;
510+ priv->bus_cancel = NULL;
511+ priv->dbus_registration = 0;
512+
513+ priv->bus_cancel = g_cancellable_new();
514+ g_bus_get(G_BUS_TYPE_SESSION,
515+ priv->bus_cancel,
516+ bus_get_cb,
517+ self);
518+
519+ return;
520+}
521+
522+static void
523+bus_get_cb (GObject * object, GAsyncResult * res, gpointer user_data)
524+{
525+ GError * error = NULL;
526+ GDBusConnection * connection = g_bus_get_finish(res, &error);
527+
528+ if (error != NULL) {
529+ g_error("OMG! Unable to get a connection to DBus: %s", error->message);
530+ g_error_free(error);
531+ return;
532+ }
533+
534+ SessionDbusPrivate * priv = SESSION_DBUS_GET_PRIVATE(user_data);
535+
536+ g_warn_if_fail(priv->bus == NULL);
537+ priv->bus = connection;
538+
539+ if (priv->bus_cancel != NULL) {
540+ g_object_unref(priv->bus_cancel);
541+ priv->bus_cancel = NULL;
542+ }
543+
544+ /* Now register our object on our new connection */
545+ priv->dbus_registration = g_dbus_connection_register_object(priv->bus,
546+ INDICATOR_SESSION_SERVICE_DBUS_OBJECT,
547+ interface_info,
548+ &interface_table,
549+ user_data,
550+ NULL,
551+ &error);
552+
553+ if (error != NULL) {
554+ g_error("Unable to register the object to DBus: %s", error->message);
555+ g_error_free(error);
556+ return;
557+ }
558+
559+ return;
560+}
561+
562+/* A method has been called from our dbus inteface. Figure out what it
563+ is and dispatch it. */
564+static void
565+bus_method_call (GDBusConnection * connection, const gchar * sender,
566+ const gchar * path, const gchar * interface,
567+ const gchar * method, GVariant * params,
568+ GDBusMethodInvocation * invocation, gpointer user_data)
569+{
570+ SessionDbus * service = SESSION_DBUS(user_data);
571+ GVariant * retval = NULL;
572+
573+ if (g_strcmp0(method, "GetIcon") == 0) {
574+ retval = get_icon(service);
575+ } else {
576+ g_warning("Calling method '%s' on the indicator service and it's unknown", method);
577+ }
578+
579+ g_dbus_method_invocation_return_value(invocation, retval);
580 return;
581 }
582
583 static void
584 session_dbus_dispose (GObject *object)
585 {
586+ SessionDbusPrivate * priv = SESSION_DBUS_GET_PRIVATE(object);
587+
588+ if (priv->dbus_registration != 0) {
589+ g_dbus_connection_unregister_object(priv->bus, priv->dbus_registration);
590+ /* Don't care if it fails, there's nothing we can do */
591+ priv->dbus_registration = 0;
592+ }
593+
594+ if (priv->bus != NULL) {
595+ g_object_unref(priv->bus);
596+ priv->bus = NULL;
597+ }
598+
599+ if (priv->bus_cancel != NULL) {
600+ g_cancellable_cancel(priv->bus_cancel);
601+ g_object_unref(priv->bus_cancel);
602+ priv->bus_cancel = NULL;
603+ }
604
605 G_OBJECT_CLASS (session_dbus_parent_class)->dispose (object);
606 return;
607@@ -111,12 +213,11 @@
608 return;
609 }
610
611-static gboolean
612-_session_dbus_server_get_icon (SessionDbus * service, gchar ** icon, GError ** error)
613+static GVariant *
614+get_icon (SessionDbus * service)
615 {
616 SessionDbusPrivate * priv = SESSION_DBUS_GET_PRIVATE(service);
617- *icon = g_strdup(priv->name);
618- return TRUE;
619+ return g_variant_new("(s)", priv->name);
620 }
621
622 SessionDbus *
623@@ -129,11 +230,28 @@
624 session_dbus_set_name (SessionDbus * session, const gchar * name)
625 {
626 SessionDbusPrivate * priv = SESSION_DBUS_GET_PRIVATE(session);
627+ GError * error = NULL;
628 if (priv->name != NULL) {
629 g_free(priv->name);
630 priv->name = NULL;
631 }
632 priv->name = g_strdup(name);
633- g_signal_emit(G_OBJECT(session), signals[ICON_UPDATED], 0, priv->name, TRUE);
634+
635+ if (priv->bus != NULL) {
636+ g_dbus_connection_emit_signal (priv->bus,
637+ NULL,
638+ INDICATOR_SESSION_SERVICE_DBUS_OBJECT,
639+ INDICATOR_SESSION_SERVICE_DBUS_IFACE,
640+ "IconUpdated",
641+ g_variant_new ("(s)", priv->name, NULL),
642+ &error);
643+
644+ if (error != NULL) {
645+ g_error("Unable to send IconUpdated signal: %s", error->message);
646+ g_error_free(error);
647+ return;
648+ }
649+ }
650+
651 return;
652 }

Subscribers

People subscribed via source and target branches