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
1=== modified file 'src/datetime-service.c'
2--- src/datetime-service.c 2011-04-13 03:18:26 +0000
3+++ src/datetime-service.c 2011-04-13 19:34:25 +0000
4@@ -1199,6 +1199,40 @@
5 return;
6 }
7
8+static void
9+session_active_change_cb (GDBusProxy * proxy, gchar * sender_name, gchar * signal_name,
10+ GVariant * parameters, gpointer user_data)
11+{
12+ // Just returned from suspend
13+ if (g_strcmp0(signal_name, "SystemIdleHintChanged") == 0) {
14+ gboolean idle = FALSE;
15+ g_variant_get(parameters, "(b)", &idle);
16+ if (!idle) {
17+ datetime_interface_update(DATETIME_INTERFACE(user_data));
18+ update_datetime(NULL);
19+ setup_timer();
20+ }
21+ }
22+ return;
23+}
24+
25+/* for hooking into console kit signal on wake from suspend */
26+static void
27+system_proxy_cb (GObject * object, GAsyncResult * res, gpointer user_data)
28+{
29+ GError * error = NULL;
30+
31+ GDBusProxy * proxy = g_dbus_proxy_new_for_bus_finish(res, &error);
32+
33+ if (error != NULL) {
34+ g_warning("Could not grab DBus proxy for ConsoleKit: %s", error->message);
35+ g_error_free(error);
36+ return;
37+ }
38+
39+ g_signal_connect(proxy, "g-signal", G_CALLBACK(session_active_change_cb), user_data);
40+}
41+
42 /* Callback from getting the address */
43 static void
44 geo_address_cb (GeoclueAddress * address, int timestamp, GHashTable * addy_data, GeoclueAccuracy * accuracy, GError * error, gpointer user_data)
45@@ -1433,6 +1467,15 @@
46 /* Setup the timer */
47 setup_timer();
48
49+ /* And watch for system resumes */
50+ g_dbus_proxy_new_for_bus (G_BUS_TYPE_SYSTEM,
51+ G_DBUS_PROXY_FLAGS_NONE,
52+ NULL,
53+ "org.freedesktop.ConsoleKit",
54+ "/org/freedesktop/ConsoleKit/Manager",
55+ "org.freedesktop.ConsoleKit.Manager",
56+ NULL, system_proxy_cb, dbus);
57+
58 mainloop = g_main_loop_new(NULL, FALSE);
59 g_main_loop_run(mainloop);
60
61
62=== modified file 'src/indicator-datetime.c'
63--- src/indicator-datetime.c 2011-04-11 14:15:16 +0000
64+++ src/indicator-datetime.c 2011-04-13 19:34:25 +0000
65@@ -171,9 +171,7 @@
66 static void guess_label_size (IndicatorDatetime * self);
67 static void setup_timer (IndicatorDatetime * self, GDateTime * datetime);
68 static void update_time (IndicatorDatetime * self);
69-static void session_active_change_cb (GDBusProxy * proxy, gchar * sender_name, gchar * signal_name, GVariant * parameters, gpointer user_data);
70 static void receive_signal (GDBusProxy * proxy, gchar * sender_name, gchar * signal_name, GVariant * parameters, gpointer user_data);
71-static void system_proxy_cb (GObject * object, GAsyncResult * res, gpointer user_data);
72 static void service_proxy_cb (GObject * object, GAsyncResult * res, gpointer user_data);
73 static gint generate_strftime_bitmask (const char *time_str);
74 static void timezone_update_labels (indicator_item_t * mi_data);
75@@ -396,34 +394,8 @@
76 service_proxy_cb,
77 self);
78
79- g_dbus_proxy_new_for_bus (G_BUS_TYPE_SYSTEM,
80- G_DBUS_PROXY_FLAGS_NONE,
81- NULL,
82- "org.freedesktop.ConsoleKit",
83- "/org/freedesktop/ConsoleKit/Manager",
84- "org.freedesktop.ConsoleKit.Manager",
85- NULL, system_proxy_cb, self);
86 return;
87 }
88-/* for hooking into console kit signal on wake from suspend */
89-static void
90-system_proxy_cb (GObject * object, GAsyncResult * res, gpointer user_data)
91-{
92- GError * error = NULL;
93-
94- IndicatorDatetime * self = INDICATOR_DATETIME(user_data);
95- g_return_if_fail(self != NULL);
96-
97- GDBusProxy * proxy = g_dbus_proxy_new_for_bus_finish(res, &error);
98-
99- if (error != NULL) {
100- g_warning("Could not grab DBus proxy for %s: %s", SERVICE_NAME, error->message);
101- g_error_free(error);
102- return;
103- }
104- g_signal_connect(proxy, "g-signal", G_CALLBACK(session_active_change_cb), self);
105-
106-}
107
108 /* Callback from trying to create the proxy for the serivce, this
109 could include starting the service. Sometime it'll fail and
110@@ -855,18 +827,6 @@
111 return;
112 }
113
114-static void
115-session_active_change_cb (GDBusProxy * proxy, gchar * sender_name, gchar * signal_name,
116- GVariant * parameters, gpointer user_data)
117-{
118- // Just returned from suspend
119- IndicatorDatetime * self = INDICATOR_DATETIME(user_data);
120- if (g_strcmp0(signal_name, "SystemIdleHintChanged") == 0 && g_variant_get_boolean(parameters) == FALSE) {
121- update_time(self);
122- }
123- return;
124-}
125-
126 /* Receives all signals from the service, routed to the appropriate functions */
127 static void
128 receive_signal (GDBusProxy * proxy, gchar * sender_name, gchar * signal_name,

Subscribers

People subscribed via source and target branches