Merge lp:~mterry/indicator-datetime/update-after-resume into lp:indicator-datetime/0.3

Proposed by Michael Terry
Status: Merged
Merged at revision: 107
Proposed branch: lp:~mterry/indicator-datetime/update-after-resume
Merge into: lp:indicator-datetime/0.3
Diff against target: 128 lines (+43/-40)
2 files modified
src/datetime-service.c (+43/-0)
src/indicator-datetime.c (+0/-40)
To merge this branch: bzr merge lp:~mterry/indicator-datetime/update-after-resume
Reviewer Review Type Date Requested Status
Mikkel Kamstrup Erlandsen (community) Approve
Review via email: mp+57574@code.launchpad.net
To post a comment you must log in.
Revision history for this message
Mikkel Kamstrup Erlandsen (kamstrup) wrote :

 review approve

This code could be simplified a great deal by just using
g_dbus_connection_signal_subscribe() (that would also stop us from
leaking that proxy), but probably not a good idea to start a
refactoring at this point in the cycle :-)

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== modified file 'src/datetime-service.c'
--- src/datetime-service.c 2011-04-13 03:18:26 +0000
+++ src/datetime-service.c 2011-04-13 19:34:25 +0000
@@ -1199,6 +1199,40 @@
1199 return;1199 return;
1200}1200}
12011201
1202static void
1203session_active_change_cb (GDBusProxy * proxy, gchar * sender_name, gchar * signal_name,
1204 GVariant * parameters, gpointer user_data)
1205{
1206 // Just returned from suspend
1207 if (g_strcmp0(signal_name, "SystemIdleHintChanged") == 0) {
1208 gboolean idle = FALSE;
1209 g_variant_get(parameters, "(b)", &idle);
1210 if (!idle) {
1211 datetime_interface_update(DATETIME_INTERFACE(user_data));
1212 update_datetime(NULL);
1213 setup_timer();
1214 }
1215 }
1216 return;
1217}
1218
1219/* for hooking into console kit signal on wake from suspend */
1220static void
1221system_proxy_cb (GObject * object, GAsyncResult * res, gpointer user_data)
1222{
1223 GError * error = NULL;
1224
1225 GDBusProxy * proxy = g_dbus_proxy_new_for_bus_finish(res, &error);
1226
1227 if (error != NULL) {
1228 g_warning("Could not grab DBus proxy for ConsoleKit: %s", error->message);
1229 g_error_free(error);
1230 return;
1231 }
1232
1233 g_signal_connect(proxy, "g-signal", G_CALLBACK(session_active_change_cb), user_data);
1234}
1235
1202/* Callback from getting the address */1236/* Callback from getting the address */
1203static void1237static void
1204geo_address_cb (GeoclueAddress * address, int timestamp, GHashTable * addy_data, GeoclueAccuracy * accuracy, GError * error, gpointer user_data)1238geo_address_cb (GeoclueAddress * address, int timestamp, GHashTable * addy_data, GeoclueAccuracy * accuracy, GError * error, gpointer user_data)
@@ -1433,6 +1467,15 @@
1433 /* Setup the timer */1467 /* Setup the timer */
1434 setup_timer();1468 setup_timer();
14351469
1470 /* And watch for system resumes */
1471 g_dbus_proxy_new_for_bus (G_BUS_TYPE_SYSTEM,
1472 G_DBUS_PROXY_FLAGS_NONE,
1473 NULL,
1474 "org.freedesktop.ConsoleKit",
1475 "/org/freedesktop/ConsoleKit/Manager",
1476 "org.freedesktop.ConsoleKit.Manager",
1477 NULL, system_proxy_cb, dbus);
1478
1436 mainloop = g_main_loop_new(NULL, FALSE);1479 mainloop = g_main_loop_new(NULL, FALSE);
1437 g_main_loop_run(mainloop);1480 g_main_loop_run(mainloop);
14381481
14391482
=== modified file 'src/indicator-datetime.c'
--- src/indicator-datetime.c 2011-04-11 14:15:16 +0000
+++ src/indicator-datetime.c 2011-04-13 19:34:25 +0000
@@ -171,9 +171,7 @@
171static void guess_label_size (IndicatorDatetime * self);171static void guess_label_size (IndicatorDatetime * self);
172static void setup_timer (IndicatorDatetime * self, GDateTime * datetime);172static void setup_timer (IndicatorDatetime * self, GDateTime * datetime);
173static void update_time (IndicatorDatetime * self);173static void update_time (IndicatorDatetime * self);
174static void session_active_change_cb (GDBusProxy * proxy, gchar * sender_name, gchar * signal_name, GVariant * parameters, gpointer user_data);
175static void receive_signal (GDBusProxy * proxy, gchar * sender_name, gchar * signal_name, GVariant * parameters, gpointer user_data);174static void receive_signal (GDBusProxy * proxy, gchar * sender_name, gchar * signal_name, GVariant * parameters, gpointer user_data);
176static void system_proxy_cb (GObject * object, GAsyncResult * res, gpointer user_data);
177static void service_proxy_cb (GObject * object, GAsyncResult * res, gpointer user_data);175static void service_proxy_cb (GObject * object, GAsyncResult * res, gpointer user_data);
178static gint generate_strftime_bitmask (const char *time_str);176static gint generate_strftime_bitmask (const char *time_str);
179static void timezone_update_labels (indicator_item_t * mi_data);177static void timezone_update_labels (indicator_item_t * mi_data);
@@ -396,34 +394,8 @@
396 service_proxy_cb,394 service_proxy_cb,
397 self);395 self);
398396
399 g_dbus_proxy_new_for_bus (G_BUS_TYPE_SYSTEM,
400 G_DBUS_PROXY_FLAGS_NONE,
401 NULL,
402 "org.freedesktop.ConsoleKit",
403 "/org/freedesktop/ConsoleKit/Manager",
404 "org.freedesktop.ConsoleKit.Manager",
405 NULL, system_proxy_cb, self);
406 return;397 return;
407}398}
408/* for hooking into console kit signal on wake from suspend */
409static void
410system_proxy_cb (GObject * object, GAsyncResult * res, gpointer user_data)
411{
412 GError * error = NULL;
413
414 IndicatorDatetime * self = INDICATOR_DATETIME(user_data);
415 g_return_if_fail(self != NULL);
416
417 GDBusProxy * proxy = g_dbus_proxy_new_for_bus_finish(res, &error);
418
419 if (error != NULL) {
420 g_warning("Could not grab DBus proxy for %s: %s", SERVICE_NAME, error->message);
421 g_error_free(error);
422 return;
423 }
424 g_signal_connect(proxy, "g-signal", G_CALLBACK(session_active_change_cb), self);
425
426}
427399
428/* Callback from trying to create the proxy for the serivce, this400/* Callback from trying to create the proxy for the serivce, this
429 could include starting the service. Sometime it'll fail and401 could include starting the service. Sometime it'll fail and
@@ -855,18 +827,6 @@
855 return;827 return;
856}828}
857829
858static void
859session_active_change_cb (GDBusProxy * proxy, gchar * sender_name, gchar * signal_name,
860 GVariant * parameters, gpointer user_data)
861{
862 // Just returned from suspend
863 IndicatorDatetime * self = INDICATOR_DATETIME(user_data);
864 if (g_strcmp0(signal_name, "SystemIdleHintChanged") == 0 && g_variant_get_boolean(parameters) == FALSE) {
865 update_time(self);
866 }
867 return;
868}
869
870/* Receives all signals from the service, routed to the appropriate functions */830/* Receives all signals from the service, routed to the appropriate functions */
871static void831static void
872receive_signal (GDBusProxy * proxy, gchar * sender_name, gchar * signal_name,832receive_signal (GDBusProxy * proxy, gchar * sender_name, gchar * signal_name,

Subscribers

People subscribed via source and target branches