Merge lp:~ken-vandine/indicator-me/gdbus into lp:indicator-me

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
Reviewer Review Type Date Requested Status
Ted Gould (community) Approve
Review via email: mp+46178@code.launchpad.net
To post a comment you must log in.
lp:~ken-vandine/indicator-me/gdbus updated
120. By Ken VanDine

Ported to libgwibber 0.0.7

Revision history for this message
Ted Gould (ted) wrote :

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.

review: Needs Fixing
lp:~ken-vandine/indicator-me/gdbus updated
121. By Ken VanDine

* check status_proxy_cancel for NULL to prevents dupes
* cast user_data after checking for error from the dbus proxy

Revision history for this message
Ted Gould (ted) wrote :

Looks good!

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== modified file '.bzrignore'
--- .bzrignore 2010-01-11 14:41:00 +0000
+++ .bzrignore 2011-01-14 17:27:04 +0000
@@ -59,5 +59,5 @@
59src/libme.la59src/libme.la
60src/libme_la-indicator-me.lo60src/libme_la-indicator-me.lo
61po/indicator-me.pot61po/indicator-me.pot
62src/me-service-client.h62src/gen-me-service.xml.c
63src/me-service-server.h63src/gen-me-service.xml.h
6464
=== modified file 'configure.ac'
--- configure.ac 2011-01-10 21:16:11 +0000
+++ configure.ac 2011-01-14 17:27:04 +0000
@@ -6,7 +6,7 @@
6AC_PREREQ(2.53)6AC_PREREQ(2.53)
77
8AM_CONFIG_HEADER(config.h)8AM_CONFIG_HEADER(config.h)
9AM_INIT_AUTOMAKE(indicator-me, 0.2.10)9AM_INIT_AUTOMAKE(indicator-me, 0.2.11)
1010
11AM_MAINTAINER_MODE11AM_MAINTAINER_MODE
1212
@@ -29,21 +29,25 @@
2929
30GTK_REQUIRED_VERSION=2.1230GTK_REQUIRED_VERSION=2.12
31INDICATOR_REQUIRED_VERSION=0.3.031INDICATOR_REQUIRED_VERSION=0.3.0
32GWIBBER_REQUIRED_VERSION=0.0.432GWIBBER_REQUIRED_VERSION=0.0.7
33DBUSMENUGLIB_REQUIRED_VERSION=0.3.9033DBUSMENUGLIB_REQUIRED_VERSION=0.3.90
34DBUSMENUGTK_REQUIRED_VERSION=0.3.90
34TELEPATHYGLIB_REQUIRED_VERSION=0.9.035TELEPATHYGLIB_REQUIRED_VERSION=0.9.0
35GCONF_REQUIRED_VERSION=2.0.036GCONF_REQUIRED_VERSION=2.0.0
36INDICATOR_DISPLAY_OBJECTS=0.137INDICATOR_DISPLAY_OBJECTS=0.1
38GIO_UNIX_REQUIRED_VERSION=2.22
3739
38PKG_CHECK_MODULES(APPLET, gtk+-2.0 >= $GTK_REQUIRED_VERSION40PKG_CHECK_MODULES(APPLET, gtk+-2.0 >= $GTK_REQUIRED_VERSION
39 indicator >= $INDICATOR_REQUIRED_VERSION41 indicator >= $INDICATOR_REQUIRED_VERSION
40 libido-0.1 >= $INDICATOR_DISPLAY_OBJECTS42 libido-0.1 >= $INDICATOR_DISPLAY_OBJECTS
41 dbus-glib-143 dbus-glib-1
42 dbusmenu-glib-0.4 >= $DBUSMENUGLIB_REQUIRED_VERSION)44 dbusmenu-glib-0.4 >= $DBUSMENUGLIB_REQUIRED_VERSION
45 dbusmenu-gtk-0.4 >= $DBUSMENUGTK_REQUIRED_VERSION)
43PKG_CHECK_MODULES(MESERVICE, dbusmenu-glib-0.4 >= $DBUSMENUGLIB_REQUIRED_VERSION46PKG_CHECK_MODULES(MESERVICE, dbusmenu-glib-0.4 >= $DBUSMENUGLIB_REQUIRED_VERSION
44 gconf-2.0 >= $GCONF_REQUIRED_VERSION47 gconf-2.0 >= $GCONF_REQUIRED_VERSION
45 indicator >= $INDICATOR_REQUIRED_VERSION48 indicator >= $INDICATOR_REQUIRED_VERSION
46 gwibber >= $GWIBBER_REQUIRED_VERSION49 gwibber >= $GWIBBER_REQUIRED_VERSION
50 gio-unix-2.0 >= $GIO_UNIX_REQUIRED_VERSION
47 telepathy-glib >= $TELEPATHYGLIB_REQUIRED_VERSION)51 telepathy-glib >= $TELEPATHYGLIB_REQUIRED_VERSION)
4852
49###########################53###########################
5054
=== modified file 'src/Makefile.am'
--- src/Makefile.am 2010-02-17 22:52:43 +0000
+++ src/Makefile.am 2011-01-14 17:27:04 +0000
@@ -12,7 +12,8 @@
12 about-me-menu-item.h \12 about-me-menu-item.h \
13 indicator-me.c \13 indicator-me.c \
14 dbus-shared-names.h \14 dbus-shared-names.h \
15 me-service-client.h15 gen-me-service.xml.h \
16 gen-me-service.xml.c
16libme_la_CFLAGS = $(APPLET_CFLAGS) -Wall -Werror17libme_la_CFLAGS = $(APPLET_CFLAGS) -Wall -Werror
17libme_la_LIBADD = $(APPLET_LIBS)18libme_la_LIBADD = $(APPLET_LIBS)
18libme_la_LDFLAGS = -module -avoid-version19libme_la_LDFLAGS = -module -avoid-version
@@ -27,7 +28,8 @@
27 me-service.c \28 me-service.c \
28 me-service-dbus.h \29 me-service-dbus.h \
29 me-service-dbus.c \30 me-service-dbus.c \
30 me-service-server.h \31 gen-me-service.xml.h \
32 gen-me-service.xml.c \
31 me-service-gwibber.c \33 me-service-gwibber.c \
32 me-service-gwibber.h \34 me-service-gwibber.h \
33 status-provider.h \35 status-provider.h \
@@ -47,19 +49,15 @@
47indicator_me_service_CFLAGS = $(MESERVICE_CFLAGS) -Wall -Werror49indicator_me_service_CFLAGS = $(MESERVICE_CFLAGS) -Wall -Werror
48indicator_me_service_LDADD = $(MESERVICE_LIBS)50indicator_me_service_LDADD = $(MESERVICE_LIBS)
4951
50me-service-client.h: $(srcdir)/me-service.xml52gen-%.xml.h: %.xml
51 dbus-binding-tool \53 @echo "Building $@ from $<"
52 --prefix=_me_service_client \54 @echo "extern const char * _$(subst -,_,$(subst .,_,$(basename $<)));" > $@
53 --mode=glib-client \
54 --output=me-service-client.h \
55 $(srcdir)/me-service.xml
5655
57me-service-server.h: $(srcdir)/me-service.xml56gen-%.xml.c: %.xml
58 dbus-binding-tool \57 @echo "Building $@ from $<"
59 --prefix=_me_service_server \58 @echo "const char * _$(subst -,_,$(subst .,_,$(basename $<))) = " > $@
60 --mode=glib-server \59 @sed -e "s:\":\\\\\":g" -e s:^:\": -e s:\$$:\\\\n\": $< >> $@
61 --output=me-service-server.h \60 @echo ";" >> $@
62 $(srcdir)/me-service.xml
6361
64status-provider-pidgin-marshal.h: $(srcdir)/status-provider-pidgin.list62status-provider-pidgin-marshal.h: $(srcdir)/status-provider-pidgin.list
65 glib-genmarshal --header \63 glib-genmarshal --header \
@@ -96,8 +94,8 @@
96###############94###############
9795
98BUILT_SOURCES = \96BUILT_SOURCES = \
99 me-service-client.h \97 gen-me-service.xml.h \
100 me-service-server.h \98 gen-me-service.xml.c \
101 status-provider-mc5-marshal.h \99 status-provider-mc5-marshal.h \
102 status-provider-mc5-marshal.c \100 status-provider-mc5-marshal.c \
103 status-provider-pidgin-marshal.h \101 status-provider-pidgin-marshal.h \
@@ -113,4 +111,3 @@
113111
114CLEANFILES = \112CLEANFILES = \
115 $(BUILT_SOURCES)113 $(BUILT_SOURCES)
116
117114
=== modified file 'src/entry-menu-item.c'
--- src/entry-menu-item.c 2011-01-10 20:54:13 +0000
+++ src/entry-menu-item.c 2011-01-14 17:27:04 +0000
@@ -124,11 +124,18 @@
124 GVariant *value, guint timestamp)124 GVariant *value, guint timestamp)
125{125{
126 /* EntryMenuItemPrivate * priv = ENTRY_MENU_ITEM_GET_PRIVATE(self); */126 /* EntryMenuItemPrivate * priv = ENTRY_MENU_ITEM_GET_PRIVATE(self); */
127
128 g_debug ("handle_event");
129 if (g_strcmp0 (name, "send") == 0) {127 if (g_strcmp0 (name, "send") == 0) {
128 gchar * msg = NULL;
129 if (g_variant_is_of_type (value, G_VARIANT_TYPE_VARIANT)) {
130 msg = g_strdup(g_variant_get_string(g_variant_get_variant (value), NULL));
131
132 } else if (g_variant_is_of_type (value, G_VARIANT_TYPE_STRING)) {
133 msg = g_strdup(g_variant_get_string(value, NULL));
134
135 }
136
130 MeGwibberService *me_gwibber_service = me_gwibber_service_get ();137 MeGwibberService *me_gwibber_service = me_gwibber_service_get ();
131 me_gwibber_service_send (me_gwibber_service, g_variant_get_string (value, NULL));138 me_gwibber_service_send (me_gwibber_service, g_strdup(msg));
132 dbusmenu_menuitem_property_set (mi, ENTRY_MENUITEM_PROP_TEXT, "");139 dbusmenu_menuitem_property_set (mi, ENTRY_MENUITEM_PROP_TEXT, "");
133 }140 }
134141
135142
=== modified file 'src/indicator-me.c'
--- src/indicator-me.c 2011-01-10 21:16:11 +0000
+++ src/indicator-me.c 2011-01-14 17:27:04 +0000
@@ -25,12 +25,10 @@
25#include <glib.h>25#include <glib.h>
26#include <glib-object.h>26#include <glib-object.h>
27#include <gtk/gtk.h>27#include <gtk/gtk.h>
28#include <gio/gio.h>
28#include <libdbusmenu-glib/menuitem.h>29#include <libdbusmenu-glib/menuitem.h>
29#include <libdbusmenu-gtk/menu.h>30#include <libdbusmenu-gtk/menu.h>
3031
31#include <dbus/dbus-glib.h>
32#include <dbus/dbus-glib-bindings.h>
33
34#include <libindicator/indicator.h>32#include <libindicator/indicator.h>
35#include <libindicator/indicator-object.h>33#include <libindicator/indicator-object.h>
36#include <libindicator/indicator-service-manager.h>34#include <libindicator/indicator-service-manager.h>
@@ -40,7 +38,7 @@
40#include "about-me-menu-item.h"38#include "about-me-menu-item.h"
4139
42#include "dbus-shared-names.h"40#include "dbus-shared-names.h"
43#include "me-service-client.h"41#include "gen-me-service.xml.h"
4442
45#define INDICATOR_ME_TYPE (indicator_me_get_type ())43#define INDICATOR_ME_TYPE (indicator_me_get_type ())
46#define INDICATOR_ME(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), INDICATOR_ME_TYPE, IndicatorMe))44#define INDICATOR_ME(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), INDICATOR_ME_TYPE, IndicatorMe))
@@ -72,7 +70,9 @@
72/* Globals */70/* Globals */
73static GtkImage * status_image = NULL;71static GtkImage * status_image = NULL;
74static GtkLabel *label = NULL;72static GtkLabel *label = NULL;
75static DBusGProxy * status_proxy = NULL;73static GDBusProxy * status_proxy = NULL;
74
75static GCancellable * status_proxy_cancel = NULL;
7676
77static IdoEntryMenuItem *ido_entry = NULL;77static IdoEntryMenuItem *ido_entry = NULL;
7878
@@ -86,13 +86,19 @@
86static void indicator_me_dispose (GObject *object);86static void indicator_me_dispose (GObject *object);
87static void indicator_me_finalize (GObject *object);87static void indicator_me_finalize (GObject *object);
88static void connection_changed (IndicatorServiceManager * sm, gboolean connected, gpointer userdata);88static void connection_changed (IndicatorServiceManager * sm, gboolean connected, gpointer userdata);
89static void status_icon_cb (DBusGProxy * proxy, char * icons, GError *error, gpointer userdata);89static void receive_signal (GDBusProxy * proxy, gchar * sender_name, gchar * signal_name, GVariant * parameters, gpointer user_data);
90
90static gboolean new_entry_item (DbusmenuMenuitem * newitem,91static gboolean new_entry_item (DbusmenuMenuitem * newitem,
91 DbusmenuMenuitem * parent,92 DbusmenuMenuitem * parent,
92 DbusmenuClient * client);93 DbusmenuClient * client);
93static void entry_activate_cb (GtkEntry *entry, DbusmenuMenuitem *mi);94static void entry_activate_cb (GtkEntry *entry, DbusmenuMenuitem *mi);
94static void entry_prop_change_cb (DbusmenuMenuitem *mi, gchar *prop, GVariant *value, GtkEntry *entry);95static void entry_prop_change_cb (DbusmenuMenuitem *mi, gchar *prop, GVariant *value, GtkEntry *entry);
95static gboolean entry_hint_is_shown (GtkWidget *widget);96static gboolean entry_hint_is_shown (GtkWidget *widget);
97static void status_proxy_cb (GObject * object, GAsyncResult * res, gpointer user_data);
98static void status_icon_changed (IndicatorMe * self, gchar * icon);
99static void status_icon_cb (GObject * object, GAsyncResult * res, gpointer user_data);
100static void username_changed (IndicatorMe * self, gchar * username);
101static void username_cb (GObject * object, GAsyncResult * res, gpointer user_data);
96102
97G_DEFINE_TYPE (IndicatorMe, indicator_me, INDICATOR_OBJECT_TYPE);103G_DEFINE_TYPE (IndicatorMe, indicator_me, INDICATOR_OBJECT_TYPE);
98104
@@ -129,21 +135,65 @@
129static void135static void
130indicator_me_dispose (GObject *object)136indicator_me_dispose (GObject *object)
131{137{
138 IndicatorMe * self = INDICATOR_ME(object);
139
140 if (self->service != NULL) {
141 g_object_unref(G_OBJECT(self->service));
142 self->service = NULL;
143 }
144
145 if (status_proxy != NULL) {
146 g_object_unref(status_proxy);
147 status_proxy = NULL;
148 }
149
150 if (status_proxy_cancel != NULL) {
151 g_cancellable_cancel(status_proxy_cancel);
152 g_object_unref(status_proxy_cancel);
153 status_proxy_cancel = NULL;
154 }
132155
133 G_OBJECT_CLASS (indicator_me_parent_class)->dispose (object);156 G_OBJECT_CLASS (indicator_me_parent_class)->dispose (object);
157
134 return;158 return;
135}159}
136160
137static void161static void
138indicator_me_finalize (GObject *object)162indicator_me_finalize (GObject *object)
139{163{
140
141 G_OBJECT_CLASS (indicator_me_parent_class)->finalize (object);164 G_OBJECT_CLASS (indicator_me_parent_class)->finalize (object);
142 return;165 return;
143}166}
144167
145static void168static void
146username_cb (DBusGProxy * proxy, char * username, GError *error, gpointer userdata)169username_cb (GObject * object, GAsyncResult * res, gpointer user_data)
170{
171 GError * error = NULL;
172 gchar * username;
173 GVariant * result;
174
175 IndicatorMe * self = INDICATOR_ME (user_data);
176 g_return_if_fail(self != NULL);
177
178 result = g_dbus_proxy_call_finish(status_proxy, res, &error);
179 g_return_if_fail(status_proxy != NULL);
180
181 if (error != NULL) {
182 g_error("Could not get the username %s", error->message);
183 g_error_free(error);
184 return;
185 }
186
187 g_variant_get(result, "(&s)", &username);
188
189 if (username != NULL) {
190 username_changed (self, username);
191 }
192
193}
194
195static void
196username_changed (IndicatorMe * self, gchar * username)
147{197{
148 if (label == NULL) {198 if (label == NULL) {
149 label = GTK_LABEL(gtk_label_new(NULL));199 label = GTK_LABEL(gtk_label_new(NULL));
@@ -163,11 +213,10 @@
163static GtkLabel *213static GtkLabel *
164get_label (IndicatorObject * io)214get_label (IndicatorObject * io)
165{215{
166 if (label == NULL) {216 if (label == NULL) {
167 /* Create the label if it doesn't exist already */217 /* Create the label if it doesn't exist already */
168 username_cb (NULL, NULL, NULL, NULL);218 username_changed (NULL, NULL);
169 }219 }
170
171 return label;220 return label;
172}221}
173222
@@ -176,35 +225,74 @@
176{225{
177 if (status_image == NULL) {226 if (status_image == NULL) {
178 /* Will create the status icon if it doesn't exist already */227 /* Will create the status icon if it doesn't exist already */
179 status_icon_cb(NULL, DEFAULT_ICON, NULL, NULL);228 status_icon_changed(NULL, DEFAULT_ICON);
180 }229 }
181 return status_image;230 return status_image;
182}231}
183232
184static void233static void
185status_icon_cb (DBusGProxy * proxy, char * icons, GError *error, gpointer userdata)234status_icon_cb (GObject * object, GAsyncResult * res, gpointer user_data)
186{235{
187 g_return_if_fail(icons != NULL);236 GError * error = NULL;
188 g_return_if_fail(icons[0] != '\0');237 gchar * icon = NULL;
238 GVariant * result;
239
240 IndicatorMe * self = INDICATOR_ME (user_data);
241 g_return_if_fail(self != NULL);
242
243 result = g_dbus_proxy_call_finish(status_proxy, res, &error);
244 g_return_if_fail(status_proxy != NULL);
245
246 if (error != NULL) {
247 g_error("Could not get the username %s", error->message);
248 g_error_free(error);
249 return;
250 }
251
252 g_variant_get(result, "(&s)", &icon);
253
254 if (icon != NULL) {
255 status_icon_changed (self, icon);
256 }
257
258}
259
260static void
261status_icon_changed (IndicatorMe * self, gchar * icon)
262{
263 g_return_if_fail(icon != NULL);
264 g_return_if_fail(icon[0] != '\0');
189265
190 if (status_image == NULL) {266 if (status_image == NULL) {
191 status_image = indicator_image_helper (DEFAULT_ICON "-panel");267 status_image = indicator_image_helper (DEFAULT_ICON "-panel");
192 gtk_widget_show(GTK_WIDGET(status_image));268 gtk_widget_show(GTK_WIDGET(status_image));
193 }269 }
194270
195 gchar *panel_icon = g_strconcat (icons, "-panel", NULL);271 gchar *panel_icon = g_strconcat (icon, "-panel", NULL);
196 indicator_image_helper_update (status_image, panel_icon);272 indicator_image_helper_update (status_image, panel_icon);
197 g_free (panel_icon);273 g_free (panel_icon);
198274
199 return;275 return;
200}276}
201277
278/* Receives all signals from the service, routed to the appropriate functions */
202static void279static void
203status_icon_changed (DBusGProxy * proxy, gchar * icon, gpointer userdata)280receive_signal (GDBusProxy * proxy, gchar * sender_name, gchar * signal_name,
281 GVariant * parameters, gpointer user_data)
204{282{
205 g_debug("Changing status icon: '%s'", icon);283 IndicatorMe * self = INDICATOR_ME(user_data);
206284
207 return status_icon_cb(proxy, icon, NULL, NULL);285 if (g_strcmp0(signal_name, "StatusIconsChanged") == 0) {
286 gchar * icon;
287 g_variant_get (parameters, "(&s)", &icon);
288 status_icon_changed (self, icon);
289 }
290 else if (g_strcmp0(signal_name, "UserChanged") == 0) {
291 gchar * username;
292 g_variant_get (parameters, "(&s)", &username);
293 username_changed(self, username);
294 }
295 return;
208}296}
209297
210static void298static void
@@ -221,61 +309,93 @@
221}309}
222310
223static void311static void
224connection_changed (IndicatorServiceManager * sm, gboolean connected, gpointer userdata)312connection_changed (IndicatorServiceManager * self, gboolean connected, gpointer userdata)
225{313{
226 if (connected) {314 if (connected) {
227 if (status_proxy == NULL) {315 if (status_proxy == NULL) {
228 GError * error = NULL;316 if (status_proxy_cancel == NULL) {
229317 status_proxy_cancel = g_cancellable_new();
230 DBusGConnection * sbus = dbus_g_bus_get(DBUS_BUS_SESSION, NULL);
231
232 status_proxy = dbus_g_proxy_new_for_name_owner(sbus,
233 INDICATOR_ME_DBUS_NAME,
234 INDICATOR_ME_SERVICE_DBUS_OBJECT,
235 INDICATOR_ME_SERVICE_DBUS_INTERFACE,
236 &error);
237
238 if (error != NULL) {
239 g_warning("Unable to get status proxy: %s", error->message);
240 g_error_free(error);
241 }318 }
242319 g_dbus_proxy_new_for_bus (G_BUS_TYPE_SESSION,
243 if (status_proxy == NULL) return;320 G_DBUS_PROXY_FLAGS_NONE,
244321 NULL,
245 dbus_g_proxy_add_signal(status_proxy, "StatusIconsChanged", G_TYPE_STRING, G_TYPE_INVALID);322 INDICATOR_ME_DBUS_NAME,
246 dbus_g_proxy_connect_signal(status_proxy, "StatusIconsChanged", G_CALLBACK(status_icon_changed), NULL, NULL);323 INDICATOR_ME_SERVICE_DBUS_OBJECT,
247324 INDICATOR_ME_SERVICE_DBUS_INTERFACE,
248 dbus_g_proxy_add_signal(status_proxy, "UserChanged", G_TYPE_STRING, G_TYPE_INVALID);325 status_proxy_cancel,
249 dbus_g_proxy_connect_signal(status_proxy, "UserChanged", G_CALLBACK(username_cb), NULL, NULL);326 status_proxy_cb,
327 userdata);
328
250 }329 }
251
252 org_ayatana_indicator_me_service_status_icons_async(status_proxy, status_icon_cb, NULL);
253
254 /* query the service for the username to display */
255 org_ayatana_indicator_me_service_pretty_user_name_async(status_proxy, username_cb, NULL);
256 } else {330 } else {
257 DbusmenuMenuitem *mi = g_object_get_data (G_OBJECT (ido_entry),331 DbusmenuMenuitem *mi = g_object_get_data (G_OBJECT (ido_entry),
258 "dbusmenuitem");332 "dbusmenuitem");
259333
260 g_signal_handlers_disconnect_by_func (ido_entry,334 g_signal_handlers_disconnect_by_func (ido_entry,
261 G_CALLBACK (entry_activate_cb),335 G_CALLBACK (entry_activate_cb),
262 mi);336 mi);
263337
264 g_signal_handlers_disconnect_by_func (ido_entry,338 g_signal_handlers_disconnect_by_func (ido_entry,
265 G_CALLBACK (entry_prop_change_cb),339 G_CALLBACK (entry_prop_change_cb),
266 mi);340 mi);
267341
268 /* If we're disconnecting, go back to offline */342 /* If we're disconnecting, go back to offline */
269 status_icon_cb(NULL, DEFAULT_ICON, NULL, NULL);343 status_icon_changed(NULL, DEFAULT_ICON);
270344
271 g_object_unref (status_proxy);345 g_object_unref (status_proxy);
272 status_proxy = NULL;346 status_proxy = NULL;
273347
274 if (ido_entry != NULL) {348 if (ido_entry != NULL) {
275 gtk_widget_destroy (GTK_WIDGET (ido_entry));349 gtk_widget_destroy (GTK_WIDGET (ido_entry));
276 ido_entry = NULL;350 ido_entry = NULL;
277 }351 }
278 }352 }
353
354 return;
355}
356
357/* Callback from trying to create the proxy for the service, this
358 could include starting the service. Sometimes it'll fail and
359 we'll try to start that dang service again! */
360static void
361status_proxy_cb (GObject * object, GAsyncResult * res, gpointer user_data)
362{
363 GError * error = NULL;
364
365 g_return_if_fail(object != NULL);
366
367 GDBusProxy * proxy = g_dbus_proxy_new_for_bus_finish(res, &error);
368
369 if (status_proxy_cancel != NULL) {
370 g_object_unref(status_proxy_cancel);
371 status_proxy_cancel = NULL;
372 }
373
374 if (error != NULL) {
375 g_error("Could not grab DBus proxy for %s: %s", INDICATOR_ME_DBUS_NAME, error->message);
376 g_error_free(error);
377 return;
378 }
379
380 IndicatorMe * self = INDICATOR_ME (user_data);
381
382 /* Okay, we're good to grab the proxy at this point, we're
383 sure that it's ours. */
384 status_proxy = proxy;
385
386 g_signal_connect(status_proxy, "g-signal", G_CALLBACK(receive_signal), self);
387
388 /* Query to get the username */
389 g_debug("Get the username");
390 g_dbus_proxy_call(status_proxy, "PrettyUserName", NULL,
391 G_DBUS_CALL_FLAGS_NONE, -1, NULL,
392 (GAsyncReadyCallback) username_cb, self);
393
394 /* Query to get the status icon */
395 g_debug("Get the status icon");
396 g_dbus_proxy_call(status_proxy, "StatusIcons", NULL,
397 G_DBUS_CALL_FLAGS_NONE, -1, NULL,
398 (GAsyncReadyCallback) status_icon_cb, self);
279399
280 return;400 return;
281}401}
282402
=== modified file 'src/me-service-dbus.c'
--- src/me-service-dbus.c 2010-02-24 19:54:33 +0000
+++ src/me-service-dbus.c 2011-01-14 17:27:04 +0000
@@ -24,8 +24,9 @@
24#include "config.h"24#include "config.h"
25#endif25#endif
2626
27#include <dbus/dbus-glib.h>27#include <gio/gio.h>
2828
29#include "gen-me-service.xml.h"
29#include "dbus-shared-names.h"30#include "dbus-shared-names.h"
30#include "me-service-dbus.h"31#include "me-service-dbus.h"
3132
@@ -33,16 +34,28 @@
33static void status_service_dbus_init (StatusServiceDbus *self);34static void status_service_dbus_init (StatusServiceDbus *self);
34static void status_service_dbus_dispose (GObject *object);35static void status_service_dbus_dispose (GObject *object);
35static void status_service_dbus_finalize (GObject *object);36static void status_service_dbus_finalize (GObject *object);
36static gboolean _me_service_server_watch (StatusServiceDbus * service, GError ** error);37static GVariant * get_icon (StatusServiceDbus * service);
37static gboolean _me_service_server_status_icons (StatusServiceDbus * service, gchar ** icon, GError ** error);38static GVariant * get_username (StatusServiceDbus * service);
38static gboolean _me_service_server_pretty_user_name (StatusServiceDbus * service, gchar ** username, GError ** error);39static GVariant * status_service_dbus_watch (StatusServiceDbus * service);
3940static void bus_get_cb (GObject * object, GAsyncResult * res, gpointer user_data);
40#include "me-service-server.h"41static 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);
4142
42/* Private */43
44
45/**
46 StatusServiceDbusPrivate:
47 @dbus_registration: The handle for this object being registered
48 on dbus.
49
50 Structure to define the memory for the private area
51 of the status service dbus instance.
52*/
43typedef struct _StatusServiceDbusPrivate StatusServiceDbusPrivate;53typedef struct _StatusServiceDbusPrivate StatusServiceDbusPrivate;
44struct _StatusServiceDbusPrivate54struct _StatusServiceDbusPrivate
45{55{
56 GDBusConnection * bus;
57 GCancellable * bus_cancel;
58 guint dbus_registration;
46 gchar * name;59 gchar * name;
47 gchar * icon;60 gchar * icon;
48};61};
@@ -50,15 +63,15 @@
50#define STATUS_SERVICE_DBUS_GET_PRIVATE(o) \63#define STATUS_SERVICE_DBUS_GET_PRIVATE(o) \
51 (G_TYPE_INSTANCE_GET_PRIVATE ((o), STATUS_SERVICE_DBUS_TYPE, StatusServiceDbusPrivate))64 (G_TYPE_INSTANCE_GET_PRIVATE ((o), STATUS_SERVICE_DBUS_TYPE, StatusServiceDbusPrivate))
5265
53/* Signals */66/* GDBus Stuff */
54enum {67static GDBusNodeInfo * node_info = NULL;
55 USER_CHANGED,68static GDBusInterfaceInfo * interface_info = NULL;
56 STATUS_ICONS_CHANGED,69static GDBusInterfaceVTable interface_table = {
57 LAST_SIGNAL70 method_call: bus_method_call,
71 get_property: NULL, /* No properties */
72 set_property: NULL /* No properties */
58};73};
5974
60static guint signals[LAST_SIGNAL] = { 0 };
61
62/* GObject Boilerplate */75/* GObject Boilerplate */
63G_DEFINE_TYPE (StatusServiceDbus, status_service_dbus, G_TYPE_OBJECT);76G_DEFINE_TYPE (StatusServiceDbus, status_service_dbus, G_TYPE_OBJECT);
6477
@@ -72,64 +85,135 @@
72 object_class->dispose = status_service_dbus_dispose;85 object_class->dispose = status_service_dbus_dispose;
73 object_class->finalize = status_service_dbus_finalize;86 object_class->finalize = status_service_dbus_finalize;
7487
75 /**88 /* Setting up the DBus interfaces */
76 StatusServiceDbus::user-changed:89 if (node_info == NULL) {
77 @arg0: The #StatusServiceDbus object.90 GError * error = NULL;
78 @arg1: The place to put the new user name91
7992 node_info = g_dbus_node_info_new_for_xml(_me_service, &error);
80 Signals that the user name has changed and gives the93 if (error != NULL) {
81 new user name.94 g_error("Unable to parse Me Service Interface description: %s", error->message);
82 */95 g_error_free(error);
83 signals[USER_CHANGED] = g_signal_new("user-changed",96 }
84 G_TYPE_FROM_CLASS(klass),97 }
85 G_SIGNAL_RUN_LAST,98
86 G_STRUCT_OFFSET(StatusServiceDbusClass, user_changed),99 if (interface_info == NULL) {
87 NULL, NULL,100 interface_info = g_dbus_node_info_lookup_interface(node_info, INDICATOR_ME_SERVICE_DBUS_INTERFACE);
88 g_cclosure_marshal_VOID__STRING,101
89 G_TYPE_NONE, 1, G_TYPE_STRING);102 if (interface_info == NULL) {
90103 g_error("Unable to find interface '" INDICATOR_ME_SERVICE_DBUS_INTERFACE "'");
91 /**104 }
92 StatusServiceDbus::status-icons-changed:105 }
93 @arg0: The #StatusServiceDbus object.106
94 @arg1: The list of icon names representing the statuses in
95 the order they should be displayed. Left to right.
96
97 Signals that the user status set has changed and that
98 new icons may need to be loaded. The list of icons will
99 always be complete.
100 */
101 signals[STATUS_ICONS_CHANGED] = g_signal_new("status-icons-changed",
102 G_TYPE_FROM_CLASS(klass),
103 G_SIGNAL_RUN_LAST,
104 G_STRUCT_OFFSET(StatusServiceDbusClass, status_icons_changed),
105 NULL, NULL,
106 g_cclosure_marshal_VOID__STRING,
107 G_TYPE_NONE, 1, G_TYPE_STRING);
108
109 dbus_g_object_type_install_info(STATUS_SERVICE_DBUS_TYPE, &dbus_glib__me_service_server_object_info);
110
111 return;107 return;
112}108}
113109
114static void110static void
115status_service_dbus_init (StatusServiceDbus *self)111status_service_dbus_init (StatusServiceDbus *self)
116{112{
117
118 DBusGConnection * connection = dbus_g_bus_get(DBUS_BUS_SESSION, NULL);
119 dbus_g_connection_register_g_object(connection,
120 INDICATOR_ME_SERVICE_DBUS_OBJECT,
121 G_OBJECT(self));
122
123 StatusServiceDbusPrivate * priv = STATUS_SERVICE_DBUS_GET_PRIVATE(self);113 StatusServiceDbusPrivate * priv = STATUS_SERVICE_DBUS_GET_PRIVATE(self);
124 priv->name = NULL;114 priv->name = NULL;
125 priv->icon = NULL;115 priv->icon = NULL;
126116
127 return;117 priv->bus = NULL;
128}118 priv->bus_cancel = NULL;
119 priv->dbus_registration = 0;
120
121 priv->bus_cancel = g_cancellable_new();
122 g_bus_get(G_BUS_TYPE_SESSION,
123 priv->bus_cancel,
124 bus_get_cb,
125 self);
126
127 return;
128}
129
130static void
131bus_get_cb (GObject * object, GAsyncResult * res, gpointer user_data)
132{
133 GError * error = NULL;
134 GDBusConnection * connection = g_bus_get_finish(res, &error);
135
136 if (error != NULL) {
137 g_error("OMG! Unable to get a connection to DBus: %s", error->message);
138 g_error_free(error);
139 return;
140 }
141
142 StatusServiceDbusPrivate * priv = STATUS_SERVICE_DBUS_GET_PRIVATE(user_data);
143
144 g_warn_if_fail(priv->bus == NULL);
145 priv->bus = connection;
146
147 if (priv->bus_cancel != NULL) {
148 g_object_unref(priv->bus_cancel);
149 priv->bus_cancel = NULL;
150 }
151
152 /* Now register our object on our new connection */
153 priv->dbus_registration = g_dbus_connection_register_object(connection,
154 INDICATOR_ME_SERVICE_DBUS_OBJECT,
155 interface_info,
156 &interface_table,
157 user_data,
158 NULL,
159 &error);
160
161 if (error != NULL) {
162 g_error("Unable to register the object to DBus: %s", error->message);
163 g_error_free(error);
164 return;
165 }
166
167 return;
168}
169
170/* A method has been called from our dbus inteface. Figure out what it
171 is and dispatch it. */
172static void
173bus_method_call (GDBusConnection * connection, const gchar * sender,
174 const gchar * path, const gchar * interface,
175 const gchar * method, GVariant * params,
176 GDBusMethodInvocation * invocation, gpointer user_data)
177{
178 StatusServiceDbus * service = STATUS_SERVICE_DBUS(user_data);
179 GVariant * retval = NULL;
180
181 if (g_strcmp0(method, "PrettyUserName") == 0) {
182 retval = get_username(service);
183 } else if (g_strcmp0(method, "StatusIcons") == 0) {
184 retval = get_icon(service);
185 } else if (g_strcmp0(method, "Watch") == 0) {
186 retval = status_service_dbus_watch(service);
187 } else {
188 g_warning("Calling method '%s' on the indicator service and it's unknown", method);
189 }
190
191 g_dbus_method_invocation_return_value(invocation, retval);
192 return;
193}
194
129195
130static void196static void
131status_service_dbus_dispose (GObject *object)197status_service_dbus_dispose (GObject *object)
132{198{
199 StatusServiceDbusPrivate * priv = STATUS_SERVICE_DBUS_GET_PRIVATE(object);
200
201 if (priv->dbus_registration != 0) {
202 g_dbus_connection_unregister_object(priv->bus, priv->dbus_registration);
203 /* Don't care if it fails, there's nothing we can do */
204 priv->dbus_registration = 0;
205 }
206
207 if (priv->bus != NULL) {
208 g_object_unref(priv->bus);
209 priv->bus = NULL;
210 }
211
212 if (priv->bus_cancel != NULL) {
213 g_cancellable_cancel(priv->bus_cancel);
214 g_object_unref(priv->bus_cancel);
215 priv->bus_cancel = NULL;
216 }
133217
134 G_OBJECT_CLASS (status_service_dbus_parent_class)->dispose (object);218 G_OBJECT_CLASS (status_service_dbus_parent_class)->dispose (object);
135 return;219 return;
@@ -143,47 +227,25 @@
143 return;227 return;
144}228}
145229
146static gboolean230static GVariant *
147_me_service_server_watch (StatusServiceDbus * service, GError ** error)231status_service_dbus_watch (StatusServiceDbus * service)
148{232{
149233 return g_variant_new("(b)", TRUE);
150 return TRUE;234}
151}235
152236
153static gboolean237static GVariant *
154_me_service_server_status_icons (StatusServiceDbus * service, gchar ** icon, GError ** error)238get_username (StatusServiceDbus * service)
155{239{
156 if (!IS_STATUS_SERVICE_DBUS(service)) {240 StatusServiceDbusPrivate * priv = STATUS_SERVICE_DBUS_GET_PRIVATE(service);
157 g_warning("NO BAD EVIL!");241 return g_variant_new("(s)", priv->name);
158 return FALSE;242}
159 }243
160244static GVariant *
161 StatusServiceDbusPrivate * priv = STATUS_SERVICE_DBUS_GET_PRIVATE(service);245get_icon (StatusServiceDbus * service)
162 if (priv->icon == NULL) {246{
163 *icon = g_strdup("");247 StatusServiceDbusPrivate * priv = STATUS_SERVICE_DBUS_GET_PRIVATE(service);
164 } else {248 return g_variant_new("(s)", priv->icon);
165 *icon = g_strdup(priv->icon);
166 }
167
168 return TRUE;
169}
170
171static gboolean
172_me_service_server_pretty_user_name (StatusServiceDbus * service, gchar ** username, GError ** error)
173{
174 if (!IS_STATUS_SERVICE_DBUS(service)) {
175 g_warning("NO BAD EVIL!");
176 return FALSE;
177 }
178
179 StatusServiceDbusPrivate * priv = STATUS_SERVICE_DBUS_GET_PRIVATE(service);
180 if (priv->name == NULL) {
181 *username = g_strdup("");
182 } else {
183 *username = g_strdup(priv->name);
184 }
185
186 return TRUE;
187}249}
188250
189void251void
@@ -195,12 +257,31 @@
195257
196 StatusServiceDbusPrivate * priv = STATUS_SERVICE_DBUS_GET_PRIVATE(self);258 StatusServiceDbusPrivate * priv = STATUS_SERVICE_DBUS_GET_PRIVATE(self);
197259
260 GError * error = NULL;
261
198 if (priv->icon != NULL) {262 if (priv->icon != NULL) {
199 g_free(priv->icon);263 g_free(priv->icon);
200 }264 }
201 priv->icon = g_strdup(icon);265 priv->icon = g_strdup(icon);
202266
203 g_signal_emit(G_OBJECT(self), signals[STATUS_ICONS_CHANGED], 0, priv->icon, TRUE);267 if (priv->bus == NULL) {
268 return;
269 }
270
271 g_dbus_connection_emit_signal (priv->bus,
272 NULL,
273 INDICATOR_ME_SERVICE_DBUS_OBJECT,
274 INDICATOR_ME_SERVICE_DBUS_INTERFACE,
275 "StatusIconsChanged",
276 g_variant_new("(s)", icon),
277 &error);
278
279 if (error != NULL) {
280 g_error("Unable to send StatusIconsChanged signal: %s", error->message);
281 g_error_free(error);
282 return;
283 }
284
204 return;285 return;
205}286}
206287
@@ -213,11 +294,30 @@
213294
214 StatusServiceDbusPrivate * priv = STATUS_SERVICE_DBUS_GET_PRIVATE(self);295 StatusServiceDbusPrivate * priv = STATUS_SERVICE_DBUS_GET_PRIVATE(self);
215296
297 GError * error = NULL;
298
216 if (priv->name != NULL) {299 if (priv->name != NULL) {
217 g_free(priv->name);300 g_free(priv->name);
218 }301 }
219 priv->name = g_strdup(username);302 priv->name = g_strdup(username);
220303
221 g_signal_emit(G_OBJECT(self), signals[USER_CHANGED], 0, priv->name, TRUE);304 if (priv->bus == NULL) {
305 return;
306 }
307
308 g_dbus_connection_emit_signal (priv->bus,
309 NULL,
310 INDICATOR_ME_SERVICE_DBUS_OBJECT,
311 INDICATOR_ME_SERVICE_DBUS_INTERFACE,
312 "UserChanged",
313 NULL,
314 &error);
315
316 if (error != NULL) {
317 g_error("Unable to send UserChanged signal: %s", error->message);
318 g_error_free(error);
319 return;
320 }
321
222 return;322 return;
223}323}
224324
=== modified file 'src/me-service-gwibber.c'
--- src/me-service-gwibber.c 2010-09-15 21:07:40 +0000
+++ src/me-service-gwibber.c 2011-01-14 17:27:04 +0000
@@ -130,21 +130,13 @@
130 return;130 return;
131}131}
132132
133static gboolean
134check_account_send_enabled (GHashTable * account_table) {
135 return g_value_get_boolean(g_hash_table_lookup(account_table, "send_enabled"));
136}
137
138static void133static void
139query_account_manager (MeGwibberService *self)134query_account_manager (MeGwibberService *self)
140{135{
141 g_return_if_fail (IS_ME_GWIBBER_SERVICE (self));136 g_return_if_fail (IS_ME_GWIBBER_SERVICE (self));
142137
143 gpointer accounts_table;138 GList* accounts_list;
144 gpointer account_table;139 GwibberAccount* account;
145 GHashTableIter accounts_iter;
146 gpointer account;
147 gboolean send_enabled;
148140
149 MeGwibberServicePrivate * priv = ME_GWIBBER_SERVICE_GET_PRIVATE(self);141 MeGwibberServicePrivate * priv = ME_GWIBBER_SERVICE_GET_PRIVATE(self);
150142
@@ -152,26 +144,25 @@
152 g_warning ("no accounts, can't query for accounts");144 g_warning ("no accounts, can't query for accounts");
153 goto reset_accounts_string;145 goto reset_accounts_string;
154 }146 }
147 accounts_list = gwibber_accounts_list (priv->me_gwibber_accounts);
155 148
156 accounts_table = gwibber_accounts_list (priv->me_gwibber_accounts);149 if (accounts_list == NULL) {
157 if (accounts_table == NULL) {
158 g_warning ("failed to get accounts list");150 g_warning ("failed to get accounts list");
159 goto reset_accounts_string;151 goto reset_accounts_string;
160 }152 }
161153
162 g_hash_table_iter_init (&accounts_iter, accounts_table);
163
164 priv->has_configured_accounts = FALSE;154 priv->has_configured_accounts = FALSE;
165 GList *list = NULL;155 GList *list = NULL;
166156
167 while (g_hash_table_iter_next (&accounts_iter, &account, &account_table)) {157 GList* account_it;
168 send_enabled = check_account_send_enabled (account_table);158 for (account_it = accounts_list; account_it != NULL; account_it = account_it->next) {
169 if (send_enabled) {159 account = g_object_ref ((GwibberAccount*) account_it->data);
160 if (g_strcmp0(gwibber_account_get_send_enabled (account), "1") == 0) {
170 priv->has_configured_accounts = TRUE;161 priv->has_configured_accounts = TRUE;
171 GValue *value = g_hash_table_lookup (account_table, "service");162 const gchar * service_name = gwibber_account_get_service (account);
172 if (value != NULL)163 if (service_name != NULL) {
173 list = g_list_append (list,164 list = g_list_append (list, g_strdup (service_name));
174 g_strdup (g_value_get_string (value)));165 }
175 }166 }
176 }167 }
177168
@@ -206,8 +197,6 @@
206 ME_GWIBBER_SERVICE_SIGNAL_STATUS_CHANGED_ID,197 ME_GWIBBER_SERVICE_SIGNAL_STATUS_CHANGED_ID,
207 0, priv->status, TRUE);198 0, priv->status, TRUE);
208199
209 g_hash_table_destroy(accounts_table);
210
211 return;200 return;
212201
213reset_accounts_string:202reset_accounts_string:
@@ -280,7 +269,6 @@
280me_gwibber_accounts_exists_cb (GwibberAccounts * me_gwibber_accounts, gboolean exists, gpointer userdata)269me_gwibber_accounts_exists_cb (GwibberAccounts * me_gwibber_accounts, gboolean exists, gpointer userdata)
281{270{
282 MeGwibberServicePrivate * priv = ME_GWIBBER_SERVICE_GET_PRIVATE(ME_GWIBBER_SERVICE (userdata));271 MeGwibberServicePrivate * priv = ME_GWIBBER_SERVICE_GET_PRIVATE(ME_GWIBBER_SERVICE (userdata));
283
284 if (exists) {272 if (exists) {
285 if (priv->me_gwibber_accounts == NULL) {273 if (priv->me_gwibber_accounts == NULL) {
286 priv->me_gwibber_accounts = gwibber_accounts_new ();;274 priv->me_gwibber_accounts = gwibber_accounts_new ();;
@@ -304,16 +292,12 @@
304}292}
305293
306void294void
307me_gwibber_service_send (MeGwibberService *self, const gchar *msg)295me_gwibber_service_send (MeGwibberService *self, gchar * msg)
308{296{
309 g_return_if_fail (IS_ME_GWIBBER_SERVICE (self));297 g_return_if_fail (IS_ME_GWIBBER_SERVICE (self));
310298
311 MeGwibberServicePrivate * priv = ME_GWIBBER_SERVICE_GET_PRIVATE(self);299 MeGwibberServicePrivate * priv = ME_GWIBBER_SERVICE_GET_PRIVATE(self);
312300
313 GValue value = {0};
314 g_value_init(&value, G_TYPE_STRING);
315 g_value_set_string(&value, msg);
316
317 if (priv->me_gwibber_service == NULL) {301 if (priv->me_gwibber_service == NULL) {
318 setup_service_proxies (self);302 setup_service_proxies (self);
319 if (priv->me_gwibber_service == NULL) {303 if (priv->me_gwibber_service == NULL) {
@@ -322,9 +306,7 @@
322 }306 }
323 }307 }
324308
325 gwibber_service_send_message (priv->me_gwibber_service, g_value_get_string (&value));309 gwibber_service_send_message (priv->me_gwibber_service, msg);
326
327 g_value_unset(&value);
328310
329 return;311 return;
330}312}
331313
=== modified file 'src/me-service-gwibber.h'
--- src/me-service-gwibber.h 2010-09-15 21:07:40 +0000
+++ src/me-service-gwibber.h 2011-01-14 17:27:04 +0000
@@ -66,7 +66,7 @@
66GType me_gwibber_service_get_type (void) G_GNUC_CONST;66GType me_gwibber_service_get_type (void) G_GNUC_CONST;
67MeGwibberService * me_gwibber_service_new (void);67MeGwibberService * me_gwibber_service_new (void);
68MeGwibberService * me_gwibber_service_get (void);68MeGwibberService * me_gwibber_service_get (void);
69void me_gwibber_service_send (MeGwibberService *self, const gchar *msg);69void me_gwibber_service_send (MeGwibberService *self, gchar *msg);
70gboolean me_gwibber_service_has_configured_accounts (MeGwibberService *self);70gboolean me_gwibber_service_has_configured_accounts (MeGwibberService *self);
71const gchar * me_gwibber_service_get_accounts_string (MeGwibberService *self);71const gchar * me_gwibber_service_get_accounts_string (MeGwibberService *self);
7272

Subscribers

People subscribed via source and target branches