Merge lp:~mterry/indicator-messages/tell-accounts-services into lp:indicator-messages/0.3

Proposed by Michael Terry on 2012-02-15
Status: Merged
Merged at revision: 249
Proposed branch: lp:~mterry/indicator-messages/tell-accounts-services
Merge into: lp:indicator-messages/0.3
Diff against target: 239 lines (+205/-0)
1 file modified
src/messages-service-dbus.c (+205/-0)
To merge this branch: bzr merge lp:~mterry/indicator-messages/tell-accounts-services
Reviewer Review Type Date Requested Status
Charles Kerr (community) 2012-02-15 Approve on 2012-02-15
Review via email: mp+93290@code.launchpad.net

Description of the change

Tell accounts service about whether we have messages. That way, LightDM can in turn notify unity-greeter.

To post a comment you must log in.
Charles Kerr (charlesk) wrote :

The patch is convoluted wrt stacking dbus calls, but it's probably unavoidable for this task. Except for some superficial changes like using g_clear_object(), I would probably write it about the same... :)

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== modified file 'src/messages-service-dbus.c'
--- src/messages-service-dbus.c 2011-07-21 21:25:58 +0000
+++ src/messages-service-dbus.c 2012-02-15 20:04:18 +0000
@@ -42,6 +42,8 @@
42struct _MessageServiceDbusPrivate42struct _MessageServiceDbusPrivate
43{43{
44 GDBusConnection * connection;44 GDBusConnection * connection;
45 GCancellable * accounts_cancel;
46 GDBusProxy * accounts_user;
45 gboolean dot;47 gboolean dot;
46 gboolean hidden;48 gboolean hidden;
47};49};
@@ -155,9 +157,199 @@
155}157}
156158
157static void159static void
160accounts_notify_cb (GObject *source_object, GAsyncResult *res,
161 gpointer user_data)
162{
163 GError * error = NULL;
164 GVariant * answer = g_dbus_proxy_call_finish(G_DBUS_PROXY(source_object), res, &error);
165
166 if (g_error_matches(error, G_IO_ERROR, G_IO_ERROR_CANCELLED)) {
167 g_error_free(error);
168 return; /* Must exit before accessing freed memory */
169 }
170
171 MessageServiceDbusPrivate * priv = MESSAGE_SERVICE_DBUS_GET_PRIVATE(user_data);
172
173 if (priv->accounts_cancel != NULL) {
174 g_object_unref(priv->accounts_cancel);
175 priv->accounts_cancel = NULL;
176 }
177
178 if (error != NULL) {
179 g_warning("Unable to get notify accounts service of message status: %s", error->message);
180 g_error_free(error);
181 return;
182 }
183
184 g_variant_unref (answer);
185}
186
187static void
188accounts_notify (MessageServiceDbus *self)
189{
190 MessageServiceDbusPrivate * priv = MESSAGE_SERVICE_DBUS_GET_PRIVATE(self);
191
192 if (priv->accounts_user == NULL)
193 return; /* We're not able to talk to accounts service */
194
195 if (priv->accounts_cancel != NULL) {
196 /* Cancel old notify before starting new one */
197 g_cancellable_cancel(priv->accounts_cancel);
198 g_object_unref(priv->accounts_cancel);
199 priv->accounts_cancel = NULL;
200 }
201
202 priv->accounts_cancel = g_cancellable_new();
203 g_dbus_proxy_call(priv->accounts_user,
204 "SetXHasMessages",
205 g_variant_new ("(b)", priv->dot),
206 G_DBUS_CALL_FLAGS_NONE,
207 -1, /* timeout */
208 priv->accounts_cancel,
209 accounts_notify_cb,
210 self);
211}
212
213static void
214get_accounts_user_proxy_cb (GObject *source_object, GAsyncResult *res,
215 gpointer user_data)
216{
217 GError * error = NULL;
218 GDBusProxy * proxy = g_dbus_proxy_new_for_bus_finish(res, &error);
219
220 if (g_error_matches(error, G_IO_ERROR, G_IO_ERROR_CANCELLED)) {
221 g_error_free(error);
222 return; /* Must exit before accessing freed memory */
223 }
224
225 MessageServiceDbusPrivate * priv = MESSAGE_SERVICE_DBUS_GET_PRIVATE(user_data);
226
227 if (priv->accounts_cancel != NULL) {
228 g_object_unref(priv->accounts_cancel);
229 priv->accounts_cancel = NULL;
230 }
231
232 if (error != NULL) {
233 g_warning("Unable to get proxy of accountsservice: %s", error->message);
234 g_error_free(error);
235 return;
236 }
237
238 priv->accounts_user = proxy;
239 accounts_notify (MESSAGE_SERVICE_DBUS (user_data));
240}
241
242static void
243get_accounts_user_find_user_cb (GObject *source_object, GAsyncResult *res,
244 gpointer user_data)
245{
246 GError * error = NULL;
247 GVariant * answer = g_dbus_proxy_call_finish(G_DBUS_PROXY(source_object), res, &error);
248
249 /* We're done with main accounts proxy now */
250 g_object_unref (source_object);
251
252 if (g_error_matches(error, G_IO_ERROR, G_IO_ERROR_CANCELLED)) {
253 g_error_free(error);
254 return; /* Must exit before accessing freed memory */
255 }
256
257 MessageServiceDbusPrivate * priv = MESSAGE_SERVICE_DBUS_GET_PRIVATE(user_data);
258
259 if (priv->accounts_cancel != NULL) {
260 g_object_unref(priv->accounts_cancel);
261 priv->accounts_cancel = NULL;
262 }
263
264 if (error != NULL) {
265 g_warning("Unable to get object name of user from accountsservice: %s", error->message);
266 g_error_free(error);
267 return;
268 }
269
270 if (!g_variant_is_of_type (answer, G_VARIANT_TYPE ("(o)"))) {
271 g_warning("Unexpected type from FindUserByName: %s", g_variant_get_type_string (answer));
272 g_variant_unref(answer);
273 return;
274 }
275
276 const gchar *path;
277 g_variant_get(answer, "(&o)", &path);
278
279 priv->accounts_cancel = g_cancellable_new();
280 g_dbus_proxy_new_for_bus(G_BUS_TYPE_SYSTEM,
281 G_DBUS_PROXY_FLAGS_NONE,
282 NULL,
283 "org.freedesktop.Accounts",
284 path,
285 "org.freedesktop.Accounts.User",
286 priv->accounts_cancel,
287 get_accounts_user_proxy_cb,
288 user_data);
289
290 g_variant_unref (answer);
291}
292
293static void
294get_accounts_proxy_cb (GObject *source_object, GAsyncResult *res,
295 gpointer user_data)
296{
297 GError * error = NULL;
298 GDBusProxy * proxy = g_dbus_proxy_new_for_bus_finish(res, &error);
299
300 if (g_error_matches(error, G_IO_ERROR, G_IO_ERROR_CANCELLED)) {
301 g_error_free(error);
302 return; /* Must exit before accessing freed memory */
303 }
304
305 MessageServiceDbusPrivate * priv = MESSAGE_SERVICE_DBUS_GET_PRIVATE(user_data);
306
307 if (priv->accounts_cancel != NULL) {
308 g_object_unref(priv->accounts_cancel);
309 priv->accounts_cancel = NULL;
310 }
311
312 if (error != NULL) {
313 g_warning("Unable to get proxy of accountsservice: %s", error->message);
314 g_error_free(error);
315 return;
316 }
317
318 priv->accounts_cancel = g_cancellable_new();
319 g_dbus_proxy_call(proxy,
320 "FindUserByName",
321 g_variant_new ("(s)", g_get_user_name ()),
322 G_DBUS_CALL_FLAGS_NONE,
323 -1, /* timeout */
324 priv->accounts_cancel,
325 get_accounts_user_find_user_cb,
326 user_data);
327}
328
329static void
330get_accounts_proxy (MessageServiceDbus *self)
331{
332 MessageServiceDbusPrivate * priv = MESSAGE_SERVICE_DBUS_GET_PRIVATE(self);
333
334 g_return_if_fail(priv->accounts_cancel == NULL);
335
336 priv->accounts_cancel = g_cancellable_new();
337 g_dbus_proxy_new_for_bus(G_BUS_TYPE_SYSTEM,
338 G_DBUS_PROXY_FLAGS_NONE,
339 NULL,
340 "org.freedesktop.Accounts",
341 "/org/freedesktop/Accounts",
342 "org.freedesktop.Accounts",
343 priv->accounts_cancel,
344 get_accounts_proxy_cb,
345 self);
346}
347
348static void
158message_service_dbus_init (MessageServiceDbus *self)349message_service_dbus_init (MessageServiceDbus *self)
159{350{
160 g_bus_get(G_BUS_TYPE_SESSION, NULL, connection_cb, self);351 g_bus_get(G_BUS_TYPE_SESSION, NULL, connection_cb, self);
352 get_accounts_proxy (self);
161353
162 MessageServiceDbusPrivate * priv = MESSAGE_SERVICE_DBUS_GET_PRIVATE(self);354 MessageServiceDbusPrivate * priv = MESSAGE_SERVICE_DBUS_GET_PRIVATE(self);
163355
@@ -177,6 +369,17 @@
177 priv->connection = NULL;369 priv->connection = NULL;
178 }370 }
179371
372 if (priv->accounts_cancel != NULL) {
373 g_cancellable_cancel(priv->accounts_cancel);
374 g_object_unref(priv->accounts_cancel);
375 priv->accounts_cancel = NULL;
376 }
377
378 if (priv->accounts_user != NULL) {
379 g_object_unref(priv->accounts_user);
380 priv->accounts_user = NULL;
381 }
382
180 G_OBJECT_CLASS (message_service_dbus_parent_class)->dispose (object);383 G_OBJECT_CLASS (message_service_dbus_parent_class)->dispose (object);
181 return;384 return;
182}385}
@@ -240,6 +443,8 @@
240 g_variant_new("(b)", priv->dot),443 g_variant_new("(b)", priv->dot),
241 NULL);444 NULL);
242 }445 }
446
447 accounts_notify (self);
243 }448 }
244 return;449 return;
245}450}

Subscribers

People subscribed via source and target branches