Merge lp:~ken-vandine/indicator-me/gdbus into lp:indicator-me
- gdbus
- Merge into trunk
Proposed by
Ken VanDine
Status: | Merged |
---|---|
Merged at revision: | 121 |
Proposed branch: | lp:~ken-vandine/indicator-me/gdbus |
Merge into: | lp:indicator-me |
Diff against target: |
1018 lines (+434/-224) 8 files modified
.bzrignore (+2/-2) configure.ac (+7/-3) src/Makefile.am (+14/-17) src/entry-menu-item.c (+10/-3) src/indicator-me.c (+184/-64) src/me-service-dbus.c (+202/-102) src/me-service-gwibber.c (+14/-32) src/me-service-gwibber.h (+1/-1) |
To merge this branch: | bzr merge lp:~ken-vandine/indicator-me/gdbus |
Related bugs: |
Reviewer | Review Type | Date Requested | Status |
---|---|---|---|
Ted Gould (community) | Approve | ||
Review via email: mp+46178@code.launchpad.net |
Commit message
Description of the change
To post a comment you must log in.
- 120. By Ken VanDine
-
Ported to libgwibber 0.0.7
- 121. By Ken VanDine
-
* check status_proxy_cancel for NULL to prevents dupes
* cast user_data after checking for error from the dbus proxy
Preview Diff
[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1 | === modified file '.bzrignore' |
2 | --- .bzrignore 2010-01-11 14:41:00 +0000 |
3 | +++ .bzrignore 2011-01-14 17:27:04 +0000 |
4 | @@ -59,5 +59,5 @@ |
5 | src/libme.la |
6 | src/libme_la-indicator-me.lo |
7 | po/indicator-me.pot |
8 | -src/me-service-client.h |
9 | -src/me-service-server.h |
10 | +src/gen-me-service.xml.c |
11 | +src/gen-me-service.xml.h |
12 | |
13 | === modified file 'configure.ac' |
14 | --- configure.ac 2011-01-10 21:16:11 +0000 |
15 | +++ configure.ac 2011-01-14 17:27:04 +0000 |
16 | @@ -6,7 +6,7 @@ |
17 | AC_PREREQ(2.53) |
18 | |
19 | AM_CONFIG_HEADER(config.h) |
20 | -AM_INIT_AUTOMAKE(indicator-me, 0.2.10) |
21 | +AM_INIT_AUTOMAKE(indicator-me, 0.2.11) |
22 | |
23 | AM_MAINTAINER_MODE |
24 | |
25 | @@ -29,21 +29,25 @@ |
26 | |
27 | GTK_REQUIRED_VERSION=2.12 |
28 | INDICATOR_REQUIRED_VERSION=0.3.0 |
29 | -GWIBBER_REQUIRED_VERSION=0.0.4 |
30 | +GWIBBER_REQUIRED_VERSION=0.0.7 |
31 | DBUSMENUGLIB_REQUIRED_VERSION=0.3.90 |
32 | +DBUSMENUGTK_REQUIRED_VERSION=0.3.90 |
33 | TELEPATHYGLIB_REQUIRED_VERSION=0.9.0 |
34 | GCONF_REQUIRED_VERSION=2.0.0 |
35 | INDICATOR_DISPLAY_OBJECTS=0.1 |
36 | +GIO_UNIX_REQUIRED_VERSION=2.22 |
37 | |
38 | PKG_CHECK_MODULES(APPLET, gtk+-2.0 >= $GTK_REQUIRED_VERSION |
39 | indicator >= $INDICATOR_REQUIRED_VERSION |
40 | libido-0.1 >= $INDICATOR_DISPLAY_OBJECTS |
41 | dbus-glib-1 |
42 | - dbusmenu-glib-0.4 >= $DBUSMENUGLIB_REQUIRED_VERSION) |
43 | + dbusmenu-glib-0.4 >= $DBUSMENUGLIB_REQUIRED_VERSION |
44 | + dbusmenu-gtk-0.4 >= $DBUSMENUGTK_REQUIRED_VERSION) |
45 | PKG_CHECK_MODULES(MESERVICE, dbusmenu-glib-0.4 >= $DBUSMENUGLIB_REQUIRED_VERSION |
46 | gconf-2.0 >= $GCONF_REQUIRED_VERSION |
47 | indicator >= $INDICATOR_REQUIRED_VERSION |
48 | gwibber >= $GWIBBER_REQUIRED_VERSION |
49 | + gio-unix-2.0 >= $GIO_UNIX_REQUIRED_VERSION |
50 | telepathy-glib >= $TELEPATHYGLIB_REQUIRED_VERSION) |
51 | |
52 | ########################### |
53 | |
54 | === modified file 'src/Makefile.am' |
55 | --- src/Makefile.am 2010-02-17 22:52:43 +0000 |
56 | +++ src/Makefile.am 2011-01-14 17:27:04 +0000 |
57 | @@ -12,7 +12,8 @@ |
58 | about-me-menu-item.h \ |
59 | indicator-me.c \ |
60 | dbus-shared-names.h \ |
61 | - me-service-client.h |
62 | + gen-me-service.xml.h \ |
63 | + gen-me-service.xml.c |
64 | libme_la_CFLAGS = $(APPLET_CFLAGS) -Wall -Werror |
65 | libme_la_LIBADD = $(APPLET_LIBS) |
66 | libme_la_LDFLAGS = -module -avoid-version |
67 | @@ -27,7 +28,8 @@ |
68 | me-service.c \ |
69 | me-service-dbus.h \ |
70 | me-service-dbus.c \ |
71 | - me-service-server.h \ |
72 | + gen-me-service.xml.h \ |
73 | + gen-me-service.xml.c \ |
74 | me-service-gwibber.c \ |
75 | me-service-gwibber.h \ |
76 | status-provider.h \ |
77 | @@ -47,19 +49,15 @@ |
78 | indicator_me_service_CFLAGS = $(MESERVICE_CFLAGS) -Wall -Werror |
79 | indicator_me_service_LDADD = $(MESERVICE_LIBS) |
80 | |
81 | -me-service-client.h: $(srcdir)/me-service.xml |
82 | - dbus-binding-tool \ |
83 | - --prefix=_me_service_client \ |
84 | - --mode=glib-client \ |
85 | - --output=me-service-client.h \ |
86 | - $(srcdir)/me-service.xml |
87 | +gen-%.xml.h: %.xml |
88 | + @echo "Building $@ from $<" |
89 | + @echo "extern const char * _$(subst -,_,$(subst .,_,$(basename $<)));" > $@ |
90 | |
91 | -me-service-server.h: $(srcdir)/me-service.xml |
92 | - dbus-binding-tool \ |
93 | - --prefix=_me_service_server \ |
94 | - --mode=glib-server \ |
95 | - --output=me-service-server.h \ |
96 | - $(srcdir)/me-service.xml |
97 | +gen-%.xml.c: %.xml |
98 | + @echo "Building $@ from $<" |
99 | + @echo "const char * _$(subst -,_,$(subst .,_,$(basename $<))) = " > $@ |
100 | + @sed -e "s:\":\\\\\":g" -e s:^:\": -e s:\$$:\\\\n\": $< >> $@ |
101 | + @echo ";" >> $@ |
102 | |
103 | status-provider-pidgin-marshal.h: $(srcdir)/status-provider-pidgin.list |
104 | glib-genmarshal --header \ |
105 | @@ -96,8 +94,8 @@ |
106 | ############### |
107 | |
108 | BUILT_SOURCES = \ |
109 | - me-service-client.h \ |
110 | - me-service-server.h \ |
111 | + gen-me-service.xml.h \ |
112 | + gen-me-service.xml.c \ |
113 | status-provider-mc5-marshal.h \ |
114 | status-provider-mc5-marshal.c \ |
115 | status-provider-pidgin-marshal.h \ |
116 | @@ -113,4 +111,3 @@ |
117 | |
118 | CLEANFILES = \ |
119 | $(BUILT_SOURCES) |
120 | - |
121 | |
122 | === modified file 'src/entry-menu-item.c' |
123 | --- src/entry-menu-item.c 2011-01-10 20:54:13 +0000 |
124 | +++ src/entry-menu-item.c 2011-01-14 17:27:04 +0000 |
125 | @@ -124,11 +124,18 @@ |
126 | GVariant *value, guint timestamp) |
127 | { |
128 | /* EntryMenuItemPrivate * priv = ENTRY_MENU_ITEM_GET_PRIVATE(self); */ |
129 | - |
130 | - g_debug ("handle_event"); |
131 | if (g_strcmp0 (name, "send") == 0) { |
132 | + gchar * msg = NULL; |
133 | + if (g_variant_is_of_type (value, G_VARIANT_TYPE_VARIANT)) { |
134 | + msg = g_strdup(g_variant_get_string(g_variant_get_variant (value), NULL)); |
135 | + |
136 | + } else if (g_variant_is_of_type (value, G_VARIANT_TYPE_STRING)) { |
137 | + msg = g_strdup(g_variant_get_string(value, NULL)); |
138 | + |
139 | + } |
140 | + |
141 | MeGwibberService *me_gwibber_service = me_gwibber_service_get (); |
142 | - me_gwibber_service_send (me_gwibber_service, g_variant_get_string (value, NULL)); |
143 | + me_gwibber_service_send (me_gwibber_service, g_strdup(msg)); |
144 | dbusmenu_menuitem_property_set (mi, ENTRY_MENUITEM_PROP_TEXT, ""); |
145 | } |
146 | |
147 | |
148 | === modified file 'src/indicator-me.c' |
149 | --- src/indicator-me.c 2011-01-10 21:16:11 +0000 |
150 | +++ src/indicator-me.c 2011-01-14 17:27:04 +0000 |
151 | @@ -25,12 +25,10 @@ |
152 | #include <glib.h> |
153 | #include <glib-object.h> |
154 | #include <gtk/gtk.h> |
155 | +#include <gio/gio.h> |
156 | #include <libdbusmenu-glib/menuitem.h> |
157 | #include <libdbusmenu-gtk/menu.h> |
158 | |
159 | -#include <dbus/dbus-glib.h> |
160 | -#include <dbus/dbus-glib-bindings.h> |
161 | - |
162 | #include <libindicator/indicator.h> |
163 | #include <libindicator/indicator-object.h> |
164 | #include <libindicator/indicator-service-manager.h> |
165 | @@ -40,7 +38,7 @@ |
166 | #include "about-me-menu-item.h" |
167 | |
168 | #include "dbus-shared-names.h" |
169 | -#include "me-service-client.h" |
170 | +#include "gen-me-service.xml.h" |
171 | |
172 | #define INDICATOR_ME_TYPE (indicator_me_get_type ()) |
173 | #define INDICATOR_ME(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), INDICATOR_ME_TYPE, IndicatorMe)) |
174 | @@ -72,7 +70,9 @@ |
175 | /* Globals */ |
176 | static GtkImage * status_image = NULL; |
177 | static GtkLabel *label = NULL; |
178 | -static DBusGProxy * status_proxy = NULL; |
179 | +static GDBusProxy * status_proxy = NULL; |
180 | + |
181 | +static GCancellable * status_proxy_cancel = NULL; |
182 | |
183 | static IdoEntryMenuItem *ido_entry = NULL; |
184 | |
185 | @@ -86,13 +86,19 @@ |
186 | static void indicator_me_dispose (GObject *object); |
187 | static void indicator_me_finalize (GObject *object); |
188 | static void connection_changed (IndicatorServiceManager * sm, gboolean connected, gpointer userdata); |
189 | -static void status_icon_cb (DBusGProxy * proxy, char * icons, GError *error, gpointer userdata); |
190 | +static void receive_signal (GDBusProxy * proxy, gchar * sender_name, gchar * signal_name, GVariant * parameters, gpointer user_data); |
191 | + |
192 | static gboolean new_entry_item (DbusmenuMenuitem * newitem, |
193 | DbusmenuMenuitem * parent, |
194 | DbusmenuClient * client); |
195 | static void entry_activate_cb (GtkEntry *entry, DbusmenuMenuitem *mi); |
196 | static void entry_prop_change_cb (DbusmenuMenuitem *mi, gchar *prop, GVariant *value, GtkEntry *entry); |
197 | static gboolean entry_hint_is_shown (GtkWidget *widget); |
198 | +static void status_proxy_cb (GObject * object, GAsyncResult * res, gpointer user_data); |
199 | +static void status_icon_changed (IndicatorMe * self, gchar * icon); |
200 | +static void status_icon_cb (GObject * object, GAsyncResult * res, gpointer user_data); |
201 | +static void username_changed (IndicatorMe * self, gchar * username); |
202 | +static void username_cb (GObject * object, GAsyncResult * res, gpointer user_data); |
203 | |
204 | G_DEFINE_TYPE (IndicatorMe, indicator_me, INDICATOR_OBJECT_TYPE); |
205 | |
206 | @@ -129,21 +135,65 @@ |
207 | static void |
208 | indicator_me_dispose (GObject *object) |
209 | { |
210 | + IndicatorMe * self = INDICATOR_ME(object); |
211 | + |
212 | + if (self->service != NULL) { |
213 | + g_object_unref(G_OBJECT(self->service)); |
214 | + self->service = NULL; |
215 | + } |
216 | + |
217 | + if (status_proxy != NULL) { |
218 | + g_object_unref(status_proxy); |
219 | + status_proxy = NULL; |
220 | + } |
221 | + |
222 | + if (status_proxy_cancel != NULL) { |
223 | + g_cancellable_cancel(status_proxy_cancel); |
224 | + g_object_unref(status_proxy_cancel); |
225 | + status_proxy_cancel = NULL; |
226 | + } |
227 | |
228 | G_OBJECT_CLASS (indicator_me_parent_class)->dispose (object); |
229 | + |
230 | return; |
231 | } |
232 | |
233 | static void |
234 | indicator_me_finalize (GObject *object) |
235 | { |
236 | - |
237 | G_OBJECT_CLASS (indicator_me_parent_class)->finalize (object); |
238 | return; |
239 | } |
240 | |
241 | static void |
242 | -username_cb (DBusGProxy * proxy, char * username, GError *error, gpointer userdata) |
243 | +username_cb (GObject * object, GAsyncResult * res, gpointer user_data) |
244 | +{ |
245 | + GError * error = NULL; |
246 | + gchar * username; |
247 | + GVariant * result; |
248 | + |
249 | + IndicatorMe * self = INDICATOR_ME (user_data); |
250 | + g_return_if_fail(self != NULL); |
251 | + |
252 | + result = g_dbus_proxy_call_finish(status_proxy, res, &error); |
253 | + g_return_if_fail(status_proxy != NULL); |
254 | + |
255 | + if (error != NULL) { |
256 | + g_error("Could not get the username %s", error->message); |
257 | + g_error_free(error); |
258 | + return; |
259 | + } |
260 | + |
261 | + g_variant_get(result, "(&s)", &username); |
262 | + |
263 | + if (username != NULL) { |
264 | + username_changed (self, username); |
265 | + } |
266 | + |
267 | +} |
268 | + |
269 | +static void |
270 | +username_changed (IndicatorMe * self, gchar * username) |
271 | { |
272 | if (label == NULL) { |
273 | label = GTK_LABEL(gtk_label_new(NULL)); |
274 | @@ -163,11 +213,10 @@ |
275 | static GtkLabel * |
276 | get_label (IndicatorObject * io) |
277 | { |
278 | - if (label == NULL) { |
279 | + if (label == NULL) { |
280 | /* Create the label if it doesn't exist already */ |
281 | - username_cb (NULL, NULL, NULL, NULL); |
282 | - } |
283 | - |
284 | + username_changed (NULL, NULL); |
285 | + } |
286 | return label; |
287 | } |
288 | |
289 | @@ -176,35 +225,74 @@ |
290 | { |
291 | if (status_image == NULL) { |
292 | /* Will create the status icon if it doesn't exist already */ |
293 | - status_icon_cb(NULL, DEFAULT_ICON, NULL, NULL); |
294 | + status_icon_changed(NULL, DEFAULT_ICON); |
295 | } |
296 | return status_image; |
297 | } |
298 | |
299 | static void |
300 | -status_icon_cb (DBusGProxy * proxy, char * icons, GError *error, gpointer userdata) |
301 | -{ |
302 | - g_return_if_fail(icons != NULL); |
303 | - g_return_if_fail(icons[0] != '\0'); |
304 | +status_icon_cb (GObject * object, GAsyncResult * res, gpointer user_data) |
305 | +{ |
306 | + GError * error = NULL; |
307 | + gchar * icon = NULL; |
308 | + GVariant * result; |
309 | + |
310 | + IndicatorMe * self = INDICATOR_ME (user_data); |
311 | + g_return_if_fail(self != NULL); |
312 | + |
313 | + result = g_dbus_proxy_call_finish(status_proxy, res, &error); |
314 | + g_return_if_fail(status_proxy != NULL); |
315 | + |
316 | + if (error != NULL) { |
317 | + g_error("Could not get the username %s", error->message); |
318 | + g_error_free(error); |
319 | + return; |
320 | + } |
321 | + |
322 | + g_variant_get(result, "(&s)", &icon); |
323 | + |
324 | + if (icon != NULL) { |
325 | + status_icon_changed (self, icon); |
326 | + } |
327 | + |
328 | +} |
329 | + |
330 | +static void |
331 | +status_icon_changed (IndicatorMe * self, gchar * icon) |
332 | +{ |
333 | + g_return_if_fail(icon != NULL); |
334 | + g_return_if_fail(icon[0] != '\0'); |
335 | |
336 | if (status_image == NULL) { |
337 | - status_image = indicator_image_helper (DEFAULT_ICON "-panel"); |
338 | + status_image = indicator_image_helper (DEFAULT_ICON "-panel"); |
339 | gtk_widget_show(GTK_WIDGET(status_image)); |
340 | } |
341 | |
342 | - gchar *panel_icon = g_strconcat (icons, "-panel", NULL); |
343 | - indicator_image_helper_update (status_image, panel_icon); |
344 | - g_free (panel_icon); |
345 | + gchar *panel_icon = g_strconcat (icon, "-panel", NULL); |
346 | + indicator_image_helper_update (status_image, panel_icon); |
347 | + g_free (panel_icon); |
348 | |
349 | return; |
350 | } |
351 | |
352 | +/* Receives all signals from the service, routed to the appropriate functions */ |
353 | static void |
354 | -status_icon_changed (DBusGProxy * proxy, gchar * icon, gpointer userdata) |
355 | +receive_signal (GDBusProxy * proxy, gchar * sender_name, gchar * signal_name, |
356 | + GVariant * parameters, gpointer user_data) |
357 | { |
358 | - g_debug("Changing status icon: '%s'", icon); |
359 | + IndicatorMe * self = INDICATOR_ME(user_data); |
360 | |
361 | - return status_icon_cb(proxy, icon, NULL, NULL); |
362 | + if (g_strcmp0(signal_name, "StatusIconsChanged") == 0) { |
363 | + gchar * icon; |
364 | + g_variant_get (parameters, "(&s)", &icon); |
365 | + status_icon_changed (self, icon); |
366 | + } |
367 | + else if (g_strcmp0(signal_name, "UserChanged") == 0) { |
368 | + gchar * username; |
369 | + g_variant_get (parameters, "(&s)", &username); |
370 | + username_changed(self, username); |
371 | + } |
372 | + return; |
373 | } |
374 | |
375 | static void |
376 | @@ -221,61 +309,93 @@ |
377 | } |
378 | |
379 | static void |
380 | -connection_changed (IndicatorServiceManager * sm, gboolean connected, gpointer userdata) |
381 | +connection_changed (IndicatorServiceManager * self, gboolean connected, gpointer userdata) |
382 | { |
383 | if (connected) { |
384 | if (status_proxy == NULL) { |
385 | - GError * error = NULL; |
386 | - |
387 | - DBusGConnection * sbus = dbus_g_bus_get(DBUS_BUS_SESSION, NULL); |
388 | - |
389 | - status_proxy = dbus_g_proxy_new_for_name_owner(sbus, |
390 | - INDICATOR_ME_DBUS_NAME, |
391 | - INDICATOR_ME_SERVICE_DBUS_OBJECT, |
392 | - INDICATOR_ME_SERVICE_DBUS_INTERFACE, |
393 | - &error); |
394 | - |
395 | - if (error != NULL) { |
396 | - g_warning("Unable to get status proxy: %s", error->message); |
397 | - g_error_free(error); |
398 | + if (status_proxy_cancel == NULL) { |
399 | + status_proxy_cancel = g_cancellable_new(); |
400 | } |
401 | - |
402 | - if (status_proxy == NULL) return; |
403 | - |
404 | - dbus_g_proxy_add_signal(status_proxy, "StatusIconsChanged", G_TYPE_STRING, G_TYPE_INVALID); |
405 | - dbus_g_proxy_connect_signal(status_proxy, "StatusIconsChanged", G_CALLBACK(status_icon_changed), NULL, NULL); |
406 | - |
407 | - dbus_g_proxy_add_signal(status_proxy, "UserChanged", G_TYPE_STRING, G_TYPE_INVALID); |
408 | - dbus_g_proxy_connect_signal(status_proxy, "UserChanged", G_CALLBACK(username_cb), NULL, NULL); |
409 | + g_dbus_proxy_new_for_bus (G_BUS_TYPE_SESSION, |
410 | + G_DBUS_PROXY_FLAGS_NONE, |
411 | + NULL, |
412 | + INDICATOR_ME_DBUS_NAME, |
413 | + INDICATOR_ME_SERVICE_DBUS_OBJECT, |
414 | + INDICATOR_ME_SERVICE_DBUS_INTERFACE, |
415 | + status_proxy_cancel, |
416 | + status_proxy_cb, |
417 | + userdata); |
418 | + |
419 | } |
420 | - |
421 | - org_ayatana_indicator_me_service_status_icons_async(status_proxy, status_icon_cb, NULL); |
422 | - |
423 | - /* query the service for the username to display */ |
424 | - org_ayatana_indicator_me_service_pretty_user_name_async(status_proxy, username_cb, NULL); |
425 | } else { |
426 | - DbusmenuMenuitem *mi = g_object_get_data (G_OBJECT (ido_entry), |
427 | + DbusmenuMenuitem *mi = g_object_get_data (G_OBJECT (ido_entry), |
428 | "dbusmenuitem"); |
429 | |
430 | - g_signal_handlers_disconnect_by_func (ido_entry, |
431 | + g_signal_handlers_disconnect_by_func (ido_entry, |
432 | G_CALLBACK (entry_activate_cb), |
433 | mi); |
434 | |
435 | - g_signal_handlers_disconnect_by_func (ido_entry, |
436 | + g_signal_handlers_disconnect_by_func (ido_entry, |
437 | G_CALLBACK (entry_prop_change_cb), |
438 | mi); |
439 | |
440 | /* If we're disconnecting, go back to offline */ |
441 | - status_icon_cb(NULL, DEFAULT_ICON, NULL, NULL); |
442 | - |
443 | - g_object_unref (status_proxy); |
444 | - status_proxy = NULL; |
445 | - |
446 | - if (ido_entry != NULL) { |
447 | - gtk_widget_destroy (GTK_WIDGET (ido_entry)); |
448 | - ido_entry = NULL; |
449 | - } |
450 | - } |
451 | + status_icon_changed(NULL, DEFAULT_ICON); |
452 | + |
453 | + g_object_unref (status_proxy); |
454 | + status_proxy = NULL; |
455 | + |
456 | + if (ido_entry != NULL) { |
457 | + gtk_widget_destroy (GTK_WIDGET (ido_entry)); |
458 | + ido_entry = NULL; |
459 | + } |
460 | + } |
461 | + |
462 | + return; |
463 | +} |
464 | + |
465 | +/* Callback from trying to create the proxy for the service, this |
466 | + could include starting the service. Sometimes it'll fail and |
467 | + we'll try to start that dang service again! */ |
468 | +static void |
469 | +status_proxy_cb (GObject * object, GAsyncResult * res, gpointer user_data) |
470 | +{ |
471 | + GError * error = NULL; |
472 | + |
473 | + g_return_if_fail(object != NULL); |
474 | + |
475 | + GDBusProxy * proxy = g_dbus_proxy_new_for_bus_finish(res, &error); |
476 | + |
477 | + if (status_proxy_cancel != NULL) { |
478 | + g_object_unref(status_proxy_cancel); |
479 | + status_proxy_cancel = NULL; |
480 | + } |
481 | + |
482 | + if (error != NULL) { |
483 | + g_error("Could not grab DBus proxy for %s: %s", INDICATOR_ME_DBUS_NAME, error->message); |
484 | + g_error_free(error); |
485 | + return; |
486 | + } |
487 | + |
488 | + IndicatorMe * self = INDICATOR_ME (user_data); |
489 | + |
490 | + /* Okay, we're good to grab the proxy at this point, we're |
491 | + sure that it's ours. */ |
492 | + status_proxy = proxy; |
493 | + |
494 | + g_signal_connect(status_proxy, "g-signal", G_CALLBACK(receive_signal), self); |
495 | + |
496 | + /* Query to get the username */ |
497 | + g_debug("Get the username"); |
498 | + g_dbus_proxy_call(status_proxy, "PrettyUserName", NULL, |
499 | + G_DBUS_CALL_FLAGS_NONE, -1, NULL, |
500 | + (GAsyncReadyCallback) username_cb, self); |
501 | + |
502 | + /* Query to get the status icon */ |
503 | + g_debug("Get the status icon"); |
504 | + g_dbus_proxy_call(status_proxy, "StatusIcons", NULL, |
505 | + G_DBUS_CALL_FLAGS_NONE, -1, NULL, |
506 | + (GAsyncReadyCallback) status_icon_cb, self); |
507 | |
508 | return; |
509 | } |
510 | |
511 | === modified file 'src/me-service-dbus.c' |
512 | --- src/me-service-dbus.c 2010-02-24 19:54:33 +0000 |
513 | +++ src/me-service-dbus.c 2011-01-14 17:27:04 +0000 |
514 | @@ -24,8 +24,9 @@ |
515 | #include "config.h" |
516 | #endif |
517 | |
518 | -#include <dbus/dbus-glib.h> |
519 | +#include <gio/gio.h> |
520 | |
521 | +#include "gen-me-service.xml.h" |
522 | #include "dbus-shared-names.h" |
523 | #include "me-service-dbus.h" |
524 | |
525 | @@ -33,16 +34,28 @@ |
526 | static void status_service_dbus_init (StatusServiceDbus *self); |
527 | static void status_service_dbus_dispose (GObject *object); |
528 | static void status_service_dbus_finalize (GObject *object); |
529 | -static gboolean _me_service_server_watch (StatusServiceDbus * service, GError ** error); |
530 | -static gboolean _me_service_server_status_icons (StatusServiceDbus * service, gchar ** icon, GError ** error); |
531 | -static gboolean _me_service_server_pretty_user_name (StatusServiceDbus * service, gchar ** username, GError ** error); |
532 | - |
533 | -#include "me-service-server.h" |
534 | - |
535 | -/* Private */ |
536 | +static GVariant * get_icon (StatusServiceDbus * service); |
537 | +static GVariant * get_username (StatusServiceDbus * service); |
538 | +static GVariant * status_service_dbus_watch (StatusServiceDbus * service); |
539 | +static void bus_get_cb (GObject * object, GAsyncResult * res, gpointer user_data); |
540 | +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); |
541 | + |
542 | + |
543 | + |
544 | +/** |
545 | + StatusServiceDbusPrivate: |
546 | + @dbus_registration: The handle for this object being registered |
547 | + on dbus. |
548 | + |
549 | + Structure to define the memory for the private area |
550 | + of the status service dbus instance. |
551 | +*/ |
552 | typedef struct _StatusServiceDbusPrivate StatusServiceDbusPrivate; |
553 | struct _StatusServiceDbusPrivate |
554 | { |
555 | + GDBusConnection * bus; |
556 | + GCancellable * bus_cancel; |
557 | + guint dbus_registration; |
558 | gchar * name; |
559 | gchar * icon; |
560 | }; |
561 | @@ -50,15 +63,15 @@ |
562 | #define STATUS_SERVICE_DBUS_GET_PRIVATE(o) \ |
563 | (G_TYPE_INSTANCE_GET_PRIVATE ((o), STATUS_SERVICE_DBUS_TYPE, StatusServiceDbusPrivate)) |
564 | |
565 | -/* Signals */ |
566 | -enum { |
567 | - USER_CHANGED, |
568 | - STATUS_ICONS_CHANGED, |
569 | - LAST_SIGNAL |
570 | +/* GDBus Stuff */ |
571 | +static GDBusNodeInfo * node_info = NULL; |
572 | +static GDBusInterfaceInfo * interface_info = NULL; |
573 | +static GDBusInterfaceVTable interface_table = { |
574 | + method_call: bus_method_call, |
575 | + get_property: NULL, /* No properties */ |
576 | + set_property: NULL /* No properties */ |
577 | }; |
578 | |
579 | -static guint signals[LAST_SIGNAL] = { 0 }; |
580 | - |
581 | /* GObject Boilerplate */ |
582 | G_DEFINE_TYPE (StatusServiceDbus, status_service_dbus, G_TYPE_OBJECT); |
583 | |
584 | @@ -72,64 +85,135 @@ |
585 | object_class->dispose = status_service_dbus_dispose; |
586 | object_class->finalize = status_service_dbus_finalize; |
587 | |
588 | - /** |
589 | - StatusServiceDbus::user-changed: |
590 | - @arg0: The #StatusServiceDbus object. |
591 | - @arg1: The place to put the new user name |
592 | - |
593 | - Signals that the user name has changed and gives the |
594 | - new user name. |
595 | - */ |
596 | - signals[USER_CHANGED] = g_signal_new("user-changed", |
597 | - G_TYPE_FROM_CLASS(klass), |
598 | - G_SIGNAL_RUN_LAST, |
599 | - G_STRUCT_OFFSET(StatusServiceDbusClass, user_changed), |
600 | - NULL, NULL, |
601 | - g_cclosure_marshal_VOID__STRING, |
602 | - G_TYPE_NONE, 1, G_TYPE_STRING); |
603 | - |
604 | - /** |
605 | - StatusServiceDbus::status-icons-changed: |
606 | - @arg0: The #StatusServiceDbus object. |
607 | - @arg1: The list of icon names representing the statuses in |
608 | - the order they should be displayed. Left to right. |
609 | - |
610 | - Signals that the user status set has changed and that |
611 | - new icons may need to be loaded. The list of icons will |
612 | - always be complete. |
613 | - */ |
614 | - signals[STATUS_ICONS_CHANGED] = g_signal_new("status-icons-changed", |
615 | - G_TYPE_FROM_CLASS(klass), |
616 | - G_SIGNAL_RUN_LAST, |
617 | - G_STRUCT_OFFSET(StatusServiceDbusClass, status_icons_changed), |
618 | - NULL, NULL, |
619 | - g_cclosure_marshal_VOID__STRING, |
620 | - G_TYPE_NONE, 1, G_TYPE_STRING); |
621 | - |
622 | - dbus_g_object_type_install_info(STATUS_SERVICE_DBUS_TYPE, &dbus_glib__me_service_server_object_info); |
623 | - |
624 | + /* Setting up the DBus interfaces */ |
625 | + if (node_info == NULL) { |
626 | + GError * error = NULL; |
627 | + |
628 | + node_info = g_dbus_node_info_new_for_xml(_me_service, &error); |
629 | + if (error != NULL) { |
630 | + g_error("Unable to parse Me Service Interface description: %s", error->message); |
631 | + g_error_free(error); |
632 | + } |
633 | + } |
634 | + |
635 | + if (interface_info == NULL) { |
636 | + interface_info = g_dbus_node_info_lookup_interface(node_info, INDICATOR_ME_SERVICE_DBUS_INTERFACE); |
637 | + |
638 | + if (interface_info == NULL) { |
639 | + g_error("Unable to find interface '" INDICATOR_ME_SERVICE_DBUS_INTERFACE "'"); |
640 | + } |
641 | + } |
642 | + |
643 | return; |
644 | } |
645 | |
646 | static void |
647 | status_service_dbus_init (StatusServiceDbus *self) |
648 | { |
649 | - |
650 | - DBusGConnection * connection = dbus_g_bus_get(DBUS_BUS_SESSION, NULL); |
651 | - dbus_g_connection_register_g_object(connection, |
652 | - INDICATOR_ME_SERVICE_DBUS_OBJECT, |
653 | - G_OBJECT(self)); |
654 | - |
655 | StatusServiceDbusPrivate * priv = STATUS_SERVICE_DBUS_GET_PRIVATE(self); |
656 | priv->name = NULL; |
657 | priv->icon = NULL; |
658 | |
659 | - return; |
660 | -} |
661 | + priv->bus = NULL; |
662 | + priv->bus_cancel = NULL; |
663 | + priv->dbus_registration = 0; |
664 | + |
665 | + priv->bus_cancel = g_cancellable_new(); |
666 | + g_bus_get(G_BUS_TYPE_SESSION, |
667 | + priv->bus_cancel, |
668 | + bus_get_cb, |
669 | + self); |
670 | + |
671 | + return; |
672 | +} |
673 | + |
674 | +static void |
675 | +bus_get_cb (GObject * object, GAsyncResult * res, gpointer user_data) |
676 | +{ |
677 | + GError * error = NULL; |
678 | + GDBusConnection * connection = g_bus_get_finish(res, &error); |
679 | + |
680 | + if (error != NULL) { |
681 | + g_error("OMG! Unable to get a connection to DBus: %s", error->message); |
682 | + g_error_free(error); |
683 | + return; |
684 | + } |
685 | + |
686 | + StatusServiceDbusPrivate * priv = STATUS_SERVICE_DBUS_GET_PRIVATE(user_data); |
687 | + |
688 | + g_warn_if_fail(priv->bus == NULL); |
689 | + priv->bus = connection; |
690 | + |
691 | + if (priv->bus_cancel != NULL) { |
692 | + g_object_unref(priv->bus_cancel); |
693 | + priv->bus_cancel = NULL; |
694 | + } |
695 | + |
696 | + /* Now register our object on our new connection */ |
697 | + priv->dbus_registration = g_dbus_connection_register_object(connection, |
698 | + INDICATOR_ME_SERVICE_DBUS_OBJECT, |
699 | + interface_info, |
700 | + &interface_table, |
701 | + user_data, |
702 | + NULL, |
703 | + &error); |
704 | + |
705 | + if (error != NULL) { |
706 | + g_error("Unable to register the object to DBus: %s", error->message); |
707 | + g_error_free(error); |
708 | + return; |
709 | + } |
710 | + |
711 | + return; |
712 | +} |
713 | + |
714 | +/* A method has been called from our dbus inteface. Figure out what it |
715 | + is and dispatch it. */ |
716 | +static void |
717 | +bus_method_call (GDBusConnection * connection, const gchar * sender, |
718 | + const gchar * path, const gchar * interface, |
719 | + const gchar * method, GVariant * params, |
720 | + GDBusMethodInvocation * invocation, gpointer user_data) |
721 | +{ |
722 | + StatusServiceDbus * service = STATUS_SERVICE_DBUS(user_data); |
723 | + GVariant * retval = NULL; |
724 | + |
725 | + if (g_strcmp0(method, "PrettyUserName") == 0) { |
726 | + retval = get_username(service); |
727 | + } else if (g_strcmp0(method, "StatusIcons") == 0) { |
728 | + retval = get_icon(service); |
729 | + } else if (g_strcmp0(method, "Watch") == 0) { |
730 | + retval = status_service_dbus_watch(service); |
731 | + } else { |
732 | + g_warning("Calling method '%s' on the indicator service and it's unknown", method); |
733 | + } |
734 | + |
735 | + g_dbus_method_invocation_return_value(invocation, retval); |
736 | + return; |
737 | +} |
738 | + |
739 | |
740 | static void |
741 | status_service_dbus_dispose (GObject *object) |
742 | { |
743 | + StatusServiceDbusPrivate * priv = STATUS_SERVICE_DBUS_GET_PRIVATE(object); |
744 | + |
745 | + if (priv->dbus_registration != 0) { |
746 | + g_dbus_connection_unregister_object(priv->bus, priv->dbus_registration); |
747 | + /* Don't care if it fails, there's nothing we can do */ |
748 | + priv->dbus_registration = 0; |
749 | + } |
750 | + |
751 | + if (priv->bus != NULL) { |
752 | + g_object_unref(priv->bus); |
753 | + priv->bus = NULL; |
754 | + } |
755 | + |
756 | + if (priv->bus_cancel != NULL) { |
757 | + g_cancellable_cancel(priv->bus_cancel); |
758 | + g_object_unref(priv->bus_cancel); |
759 | + priv->bus_cancel = NULL; |
760 | + } |
761 | |
762 | G_OBJECT_CLASS (status_service_dbus_parent_class)->dispose (object); |
763 | return; |
764 | @@ -143,47 +227,25 @@ |
765 | return; |
766 | } |
767 | |
768 | -static gboolean |
769 | -_me_service_server_watch (StatusServiceDbus * service, GError ** error) |
770 | -{ |
771 | - |
772 | - return TRUE; |
773 | -} |
774 | - |
775 | -static gboolean |
776 | -_me_service_server_status_icons (StatusServiceDbus * service, gchar ** icon, GError ** error) |
777 | -{ |
778 | - if (!IS_STATUS_SERVICE_DBUS(service)) { |
779 | - g_warning("NO BAD EVIL!"); |
780 | - return FALSE; |
781 | - } |
782 | - |
783 | - StatusServiceDbusPrivate * priv = STATUS_SERVICE_DBUS_GET_PRIVATE(service); |
784 | - if (priv->icon == NULL) { |
785 | - *icon = g_strdup(""); |
786 | - } else { |
787 | - *icon = g_strdup(priv->icon); |
788 | - } |
789 | - |
790 | - return TRUE; |
791 | -} |
792 | - |
793 | -static gboolean |
794 | -_me_service_server_pretty_user_name (StatusServiceDbus * service, gchar ** username, GError ** error) |
795 | -{ |
796 | - if (!IS_STATUS_SERVICE_DBUS(service)) { |
797 | - g_warning("NO BAD EVIL!"); |
798 | - return FALSE; |
799 | - } |
800 | - |
801 | - StatusServiceDbusPrivate * priv = STATUS_SERVICE_DBUS_GET_PRIVATE(service); |
802 | - if (priv->name == NULL) { |
803 | - *username = g_strdup(""); |
804 | - } else { |
805 | - *username = g_strdup(priv->name); |
806 | - } |
807 | - |
808 | - return TRUE; |
809 | +static GVariant * |
810 | +status_service_dbus_watch (StatusServiceDbus * service) |
811 | +{ |
812 | + return g_variant_new("(b)", TRUE); |
813 | +} |
814 | + |
815 | + |
816 | +static GVariant * |
817 | +get_username (StatusServiceDbus * service) |
818 | +{ |
819 | + StatusServiceDbusPrivate * priv = STATUS_SERVICE_DBUS_GET_PRIVATE(service); |
820 | + return g_variant_new("(s)", priv->name); |
821 | +} |
822 | + |
823 | +static GVariant * |
824 | +get_icon (StatusServiceDbus * service) |
825 | +{ |
826 | + StatusServiceDbusPrivate * priv = STATUS_SERVICE_DBUS_GET_PRIVATE(service); |
827 | + return g_variant_new("(s)", priv->icon); |
828 | } |
829 | |
830 | void |
831 | @@ -195,12 +257,31 @@ |
832 | |
833 | StatusServiceDbusPrivate * priv = STATUS_SERVICE_DBUS_GET_PRIVATE(self); |
834 | |
835 | + GError * error = NULL; |
836 | + |
837 | if (priv->icon != NULL) { |
838 | g_free(priv->icon); |
839 | } |
840 | priv->icon = g_strdup(icon); |
841 | |
842 | - g_signal_emit(G_OBJECT(self), signals[STATUS_ICONS_CHANGED], 0, priv->icon, TRUE); |
843 | + if (priv->bus == NULL) { |
844 | + return; |
845 | + } |
846 | + |
847 | + g_dbus_connection_emit_signal (priv->bus, |
848 | + NULL, |
849 | + INDICATOR_ME_SERVICE_DBUS_OBJECT, |
850 | + INDICATOR_ME_SERVICE_DBUS_INTERFACE, |
851 | + "StatusIconsChanged", |
852 | + g_variant_new("(s)", icon), |
853 | + &error); |
854 | + |
855 | + if (error != NULL) { |
856 | + g_error("Unable to send StatusIconsChanged signal: %s", error->message); |
857 | + g_error_free(error); |
858 | + return; |
859 | + } |
860 | + |
861 | return; |
862 | } |
863 | |
864 | @@ -213,11 +294,30 @@ |
865 | |
866 | StatusServiceDbusPrivate * priv = STATUS_SERVICE_DBUS_GET_PRIVATE(self); |
867 | |
868 | + GError * error = NULL; |
869 | + |
870 | if (priv->name != NULL) { |
871 | g_free(priv->name); |
872 | } |
873 | priv->name = g_strdup(username); |
874 | |
875 | - g_signal_emit(G_OBJECT(self), signals[USER_CHANGED], 0, priv->name, TRUE); |
876 | + if (priv->bus == NULL) { |
877 | + return; |
878 | + } |
879 | + |
880 | + g_dbus_connection_emit_signal (priv->bus, |
881 | + NULL, |
882 | + INDICATOR_ME_SERVICE_DBUS_OBJECT, |
883 | + INDICATOR_ME_SERVICE_DBUS_INTERFACE, |
884 | + "UserChanged", |
885 | + NULL, |
886 | + &error); |
887 | + |
888 | + if (error != NULL) { |
889 | + g_error("Unable to send UserChanged signal: %s", error->message); |
890 | + g_error_free(error); |
891 | + return; |
892 | + } |
893 | + |
894 | return; |
895 | } |
896 | |
897 | === modified file 'src/me-service-gwibber.c' |
898 | --- src/me-service-gwibber.c 2010-09-15 21:07:40 +0000 |
899 | +++ src/me-service-gwibber.c 2011-01-14 17:27:04 +0000 |
900 | @@ -130,21 +130,13 @@ |
901 | return; |
902 | } |
903 | |
904 | -static gboolean |
905 | -check_account_send_enabled (GHashTable * account_table) { |
906 | - return g_value_get_boolean(g_hash_table_lookup(account_table, "send_enabled")); |
907 | -} |
908 | - |
909 | static void |
910 | query_account_manager (MeGwibberService *self) |
911 | { |
912 | g_return_if_fail (IS_ME_GWIBBER_SERVICE (self)); |
913 | |
914 | - gpointer accounts_table; |
915 | - gpointer account_table; |
916 | - GHashTableIter accounts_iter; |
917 | - gpointer account; |
918 | - gboolean send_enabled; |
919 | + GList* accounts_list; |
920 | + GwibberAccount* account; |
921 | |
922 | MeGwibberServicePrivate * priv = ME_GWIBBER_SERVICE_GET_PRIVATE(self); |
923 | |
924 | @@ -152,26 +144,25 @@ |
925 | g_warning ("no accounts, can't query for accounts"); |
926 | goto reset_accounts_string; |
927 | } |
928 | + accounts_list = gwibber_accounts_list (priv->me_gwibber_accounts); |
929 | |
930 | - accounts_table = gwibber_accounts_list (priv->me_gwibber_accounts); |
931 | - if (accounts_table == NULL) { |
932 | + if (accounts_list == NULL) { |
933 | g_warning ("failed to get accounts list"); |
934 | goto reset_accounts_string; |
935 | } |
936 | |
937 | - g_hash_table_iter_init (&accounts_iter, accounts_table); |
938 | - |
939 | priv->has_configured_accounts = FALSE; |
940 | GList *list = NULL; |
941 | |
942 | - while (g_hash_table_iter_next (&accounts_iter, &account, &account_table)) { |
943 | - send_enabled = check_account_send_enabled (account_table); |
944 | - if (send_enabled) { |
945 | + GList* account_it; |
946 | + for (account_it = accounts_list; account_it != NULL; account_it = account_it->next) { |
947 | + account = g_object_ref ((GwibberAccount*) account_it->data); |
948 | + if (g_strcmp0(gwibber_account_get_send_enabled (account), "1") == 0) { |
949 | priv->has_configured_accounts = TRUE; |
950 | - GValue *value = g_hash_table_lookup (account_table, "service"); |
951 | - if (value != NULL) |
952 | - list = g_list_append (list, |
953 | - g_strdup (g_value_get_string (value))); |
954 | + const gchar * service_name = gwibber_account_get_service (account); |
955 | + if (service_name != NULL) { |
956 | + list = g_list_append (list, g_strdup (service_name)); |
957 | + } |
958 | } |
959 | } |
960 | |
961 | @@ -206,8 +197,6 @@ |
962 | ME_GWIBBER_SERVICE_SIGNAL_STATUS_CHANGED_ID, |
963 | 0, priv->status, TRUE); |
964 | |
965 | - g_hash_table_destroy(accounts_table); |
966 | - |
967 | return; |
968 | |
969 | reset_accounts_string: |
970 | @@ -280,7 +269,6 @@ |
971 | me_gwibber_accounts_exists_cb (GwibberAccounts * me_gwibber_accounts, gboolean exists, gpointer userdata) |
972 | { |
973 | MeGwibberServicePrivate * priv = ME_GWIBBER_SERVICE_GET_PRIVATE(ME_GWIBBER_SERVICE (userdata)); |
974 | - |
975 | if (exists) { |
976 | if (priv->me_gwibber_accounts == NULL) { |
977 | priv->me_gwibber_accounts = gwibber_accounts_new ();; |
978 | @@ -304,16 +292,12 @@ |
979 | } |
980 | |
981 | void |
982 | -me_gwibber_service_send (MeGwibberService *self, const gchar *msg) |
983 | +me_gwibber_service_send (MeGwibberService *self, gchar * msg) |
984 | { |
985 | g_return_if_fail (IS_ME_GWIBBER_SERVICE (self)); |
986 | |
987 | MeGwibberServicePrivate * priv = ME_GWIBBER_SERVICE_GET_PRIVATE(self); |
988 | |
989 | - GValue value = {0}; |
990 | - g_value_init(&value, G_TYPE_STRING); |
991 | - g_value_set_string(&value, msg); |
992 | - |
993 | if (priv->me_gwibber_service == NULL) { |
994 | setup_service_proxies (self); |
995 | if (priv->me_gwibber_service == NULL) { |
996 | @@ -322,9 +306,7 @@ |
997 | } |
998 | } |
999 | |
1000 | - gwibber_service_send_message (priv->me_gwibber_service, g_value_get_string (&value)); |
1001 | - |
1002 | - g_value_unset(&value); |
1003 | + gwibber_service_send_message (priv->me_gwibber_service, msg); |
1004 | |
1005 | return; |
1006 | } |
1007 | |
1008 | === modified file 'src/me-service-gwibber.h' |
1009 | --- src/me-service-gwibber.h 2010-09-15 21:07:40 +0000 |
1010 | +++ src/me-service-gwibber.h 2011-01-14 17:27:04 +0000 |
1011 | @@ -66,7 +66,7 @@ |
1012 | GType me_gwibber_service_get_type (void) G_GNUC_CONST; |
1013 | MeGwibberService * me_gwibber_service_new (void); |
1014 | MeGwibberService * me_gwibber_service_get (void); |
1015 | -void me_gwibber_service_send (MeGwibberService *self, const gchar *msg); |
1016 | +void me_gwibber_service_send (MeGwibberService *self, gchar *msg); |
1017 | gboolean me_gwibber_service_has_configured_accounts (MeGwibberService *self); |
1018 | const gchar * me_gwibber_service_get_accounts_string (MeGwibberService *self); |
1019 |
conncetion_ changed( )
Should really check to see if status_proxy_cancel is NULL as well so that you don't allocate two of them.
status_proxy_cb()
You shouldn't cast the user_data to self before checking the error. There is a few cases where the indicator could be deallocated before this function is called and therefore user_data would be a random pointer.