Merge lp:~ted/indicator-session/better-locking into lp:indicator-session/0.1
- better-locking
- Merge into trunk
Proposed by
Ted Gould
Status: | Merged |
---|---|
Merged at revision: | not available |
Proposed branch: | lp:~ted/indicator-session/better-locking |
Merge into: | lp:indicator-session/0.1 |
Diff against target: |
770 lines 5 files modified
src/Makefile.am (+11/-2) src/lock-helper.c (+326/-0) src/lock-helper.h (+37/-0) src/session-service.c (+17/-124) src/users-service.c (+11/-128) |
To merge this branch: | bzr merge lp:~ted/indicator-session/better-locking |
Related bugs: |
Reviewer | Review Type | Date Requested | Status |
---|---|---|---|
Neil J. Patel (community) | Approve | ||
Review via email: mp+13010@code.launchpad.net |
Commit message
Description of the change
To post a comment you must log in.
Preview Diff
[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1 | === modified file 'src/Makefile.am' |
2 | --- src/Makefile.am 2009-09-24 17:09:22 +0000 |
3 | +++ src/Makefile.am 2009-10-07 17:25:21 +0000 |
4 | @@ -112,7 +112,12 @@ |
5 | # Users Stuff |
6 | ############### |
7 | |
8 | -indicator_users_service_SOURCES = users-service.c users-service-dbus.c users-service-marshal.c |
9 | +indicator_users_service_SOURCES = \ |
10 | + lock-helper.c \ |
11 | + lock-helper.h \ |
12 | + users-service.c \ |
13 | + users-service-dbus.c \ |
14 | + users-service-marshal.c |
15 | indicator_users_service_CFLAGS = $(USERSSERVICE_CFLAGS) -Wall -Werror |
16 | indicator_users_service_LDADD = $(USERSSERVICE_LIBS) |
17 | |
18 | @@ -120,7 +125,11 @@ |
19 | # Session Stuff |
20 | ################# |
21 | |
22 | -indicator_session_service_SOURCES = session-service.c gtk-dialog/gconf-helper.c |
23 | +indicator_session_service_SOURCES = \ |
24 | + lock-helper.c \ |
25 | + lock-helper.h \ |
26 | + session-service.c \ |
27 | + gtk-dialog/gconf-helper.c |
28 | indicator_session_service_CFLAGS = $(SESSIONSERVICE_CFLAGS) $(GCONF_CFLAGS) -DLIBEXECDIR=\"$(libexecdir)\" -Wall -Werror |
29 | indicator_session_service_LDADD = $(SESSIONSERVICE_LIBS) $(GCONF_LIBS) |
30 | |
31 | |
32 | === added file 'src/lock-helper.c' |
33 | --- src/lock-helper.c 1970-01-01 00:00:00 +0000 |
34 | +++ src/lock-helper.c 2009-10-07 17:25:21 +0000 |
35 | @@ -0,0 +1,326 @@ |
36 | +/* |
37 | +A small helper for locking the screen. |
38 | + |
39 | +Copyright 2009 Canonical Ltd. |
40 | + |
41 | +Authors: |
42 | + Ted Gould <ted@canonical.com> |
43 | + |
44 | +This program is free software: you can redistribute it and/or modify it |
45 | +under the terms of the GNU General Public License version 3, as published |
46 | +by the Free Software Foundation. |
47 | + |
48 | +This program is distributed in the hope that it will be useful, but |
49 | +WITHOUT ANY WARRANTY; without even the implied warranties of |
50 | +MERCHANTABILITY, SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR |
51 | +PURPOSE. See the GNU General Public License for more details. |
52 | + |
53 | +You should have received a copy of the GNU General Public License along |
54 | +with this program. If not, see <http://www.gnu.org/licenses/>. |
55 | +*/ |
56 | + |
57 | +#include <dbus/dbus-glib.h> |
58 | +#include "lock-helper.h" |
59 | + |
60 | +static DBusGProxy * gss_proxy = NULL; |
61 | +static GMainLoop * gss_mainloop = NULL; |
62 | +static guint cookie = 0; |
63 | +static DBusGProxyCall * cookie_call = NULL; |
64 | + |
65 | +static DBusGProxy * gdm_settings_proxy = NULL; |
66 | +static gboolean gdm_auto_login = FALSE; |
67 | +static const gchar * gdm_auto_login_string = "daemon/AutomaticLoginEnable"; |
68 | + |
69 | +static gboolean is_guest = FALSE; |
70 | + |
71 | +static gdm_autologin_cb_t gdm_autologin_cb = NULL; |
72 | + |
73 | +/* Checks to see if there is an error and reports |
74 | + it. Not much else we can do. */ |
75 | +static void |
76 | +unthrottle_return (DBusGProxy * proxy, DBusGProxyCall * call, gpointer data) |
77 | +{ |
78 | + GError * error = NULL; |
79 | + dbus_g_proxy_end_call(proxy, call, &error, |
80 | + G_TYPE_INVALID); |
81 | + |
82 | + if (error != NULL) { |
83 | + g_warning("Unable to unthrottle: %s", error->message); |
84 | + } |
85 | + return; |
86 | +} |
87 | + |
88 | +/* Sends an unthrottle if we're throttled. */ |
89 | +void |
90 | +screensaver_unthrottle (void) |
91 | +{ |
92 | + g_return_if_fail(cookie != 0); |
93 | + |
94 | + dbus_g_proxy_begin_call(gss_proxy, "UnThrottle", |
95 | + unthrottle_return, NULL, |
96 | + NULL, |
97 | + G_TYPE_UINT, cookie, |
98 | + G_TYPE_INVALID); |
99 | + |
100 | + cookie = 0; |
101 | + return; |
102 | +} |
103 | + |
104 | +/* Gets there return cookie from the throttle command |
105 | + and sets things valid */ |
106 | +static void |
107 | +throttle_return (DBusGProxy * proxy, DBusGProxyCall * call, gpointer data) |
108 | +{ |
109 | + GError * error = NULL; |
110 | + cookie_call = NULL; |
111 | + |
112 | + dbus_g_proxy_end_call(proxy, call, &error, |
113 | + G_TYPE_UINT, &cookie, |
114 | + G_TYPE_INVALID); |
115 | + |
116 | + if (error != NULL) { |
117 | + g_warning("Unable to throttle the screensaver: %s", error->message); |
118 | + return; |
119 | + } |
120 | + |
121 | + |
122 | + if (cookie == 0) { |
123 | + g_warning("We didn't get a throttle cookie!"); |
124 | + } |
125 | + |
126 | + return; |
127 | +} |
128 | + |
129 | +/* Throttling the screensaver by using the screen saver |
130 | + command. */ |
131 | +void |
132 | +screensaver_throttle (gchar * reason) |
133 | +{ |
134 | + g_return_if_fail(cookie_call == NULL); |
135 | + g_return_if_fail(will_lock_screen()); |
136 | + |
137 | + if (cookie != 0) { |
138 | + screensaver_unthrottle(); |
139 | + } |
140 | + |
141 | + cookie_call = dbus_g_proxy_begin_call(gss_proxy, "Throttle", |
142 | + throttle_return, NULL, |
143 | + NULL, |
144 | + G_TYPE_STRING, "Session Menu", |
145 | + G_TYPE_STRING, reason, |
146 | + G_TYPE_INVALID); |
147 | + |
148 | + return; |
149 | +} |
150 | + |
151 | +/* Setting up a call back */ |
152 | +void |
153 | +lock_screen_gdm_cb_set (gdm_autologin_cb_t cb) |
154 | +{ |
155 | + if (gdm_autologin_cb) { |
156 | + g_warning("Already had a callback, setting up a new one..."); |
157 | + } |
158 | + |
159 | + gdm_autologin_cb = cb; |
160 | + return; |
161 | +} |
162 | + |
163 | +/* This is our logic on whether the screen should be locked |
164 | + or not. It effects everything else. */ |
165 | +gboolean |
166 | +will_lock_screen (void) |
167 | +{ |
168 | + if (gdm_auto_login) { |
169 | + return FALSE; |
170 | + } |
171 | + if (is_guest) { |
172 | + return FALSE; |
173 | + } |
174 | + |
175 | + return TRUE; |
176 | +} |
177 | + |
178 | +/* Respond to the signal of autologin changing to see if the |
179 | + setting for timed login changes. */ |
180 | +static void |
181 | +gdm_settings_change (DBusGProxy * proxy, const gchar * value, const gchar * old, const gchar * new, gpointer data) |
182 | +{ |
183 | + if (g_strcmp0(value, gdm_auto_login_string)) { |
184 | + /* This is not a setting that we care about, |
185 | + there is only one. */ |
186 | + return; |
187 | + } |
188 | + g_debug("GDM Settings change: %s", new); |
189 | + |
190 | + if (g_strcmp0(new, "true") == 0) { |
191 | + gdm_auto_login = TRUE; |
192 | + } else { |
193 | + gdm_auto_login = FALSE; |
194 | + } |
195 | + |
196 | + if (gdm_autologin_cb != NULL) { |
197 | + gdm_autologin_cb(); |
198 | + } |
199 | + |
200 | + return; |
201 | +} |
202 | + |
203 | +/* Get back the data from querying to see if there is auto |
204 | + login enabled in GDM */ |
205 | +static void |
206 | +gdm_get_autologin (DBusGProxy * proxy, DBusGProxyCall * call, gpointer data) |
207 | +{ |
208 | + GError * error = NULL; |
209 | + gchar * value = NULL; |
210 | + |
211 | + if (!dbus_g_proxy_end_call(proxy, call, &error, G_TYPE_STRING, &value, G_TYPE_INVALID)) { |
212 | + g_warning("Unable to get autologin setting: %s", error != NULL ? error->message : "null"); |
213 | + g_error_free(error); |
214 | + return; |
215 | + } |
216 | + |
217 | + g_return_if_fail(value != NULL); |
218 | + gdm_settings_change(proxy, gdm_auto_login_string, NULL, value, NULL); |
219 | + |
220 | + return; |
221 | +} |
222 | + |
223 | +/* Sets up the proxy and queries for the setting to know |
224 | + whether we're doing an autologin. */ |
225 | +static void |
226 | +build_gdm_proxy (void) |
227 | +{ |
228 | + g_return_if_fail(gdm_settings_proxy == NULL); |
229 | + |
230 | + /* Grab the system bus */ |
231 | + DBusGConnection * bus = dbus_g_bus_get(DBUS_BUS_SYSTEM, NULL); |
232 | + g_return_if_fail(bus != NULL); |
233 | + |
234 | + /* Get the settings proxy */ |
235 | + gdm_settings_proxy = dbus_g_proxy_new_for_name_owner(bus, |
236 | + "org.gnome.DisplayManager", |
237 | + "/org/gnome/DisplayManager/Settings", |
238 | + "org.gnome.DisplayManager.Settings", NULL); |
239 | + g_return_if_fail(gdm_settings_proxy != NULL); |
240 | + |
241 | + /* Signal for value changed */ |
242 | + dbus_g_proxy_add_signal(gdm_settings_proxy, |
243 | + "ValueChanged", |
244 | + G_TYPE_STRING, |
245 | + G_TYPE_STRING, |
246 | + G_TYPE_STRING, |
247 | + G_TYPE_INVALID); |
248 | + dbus_g_proxy_connect_signal(gdm_settings_proxy, |
249 | + "ValueChanged", |
250 | + G_CALLBACK(gdm_settings_change), |
251 | + NULL, |
252 | + NULL); |
253 | + |
254 | + /* Start to get the initial value */ |
255 | + dbus_g_proxy_begin_call(gdm_settings_proxy, |
256 | + "GetValue", |
257 | + gdm_get_autologin, |
258 | + NULL, |
259 | + NULL, |
260 | + G_TYPE_STRING, |
261 | + gdm_auto_login_string, |
262 | + G_TYPE_INVALID); |
263 | + |
264 | + return; |
265 | +} |
266 | + |
267 | +/* When the screensave go active, if we've got a mainloop |
268 | + running we should quit it. */ |
269 | +static void |
270 | +gss_active_changed (DBusGProxy * proxy, gboolean active, gpointer data) |
271 | +{ |
272 | + if (active && gss_mainloop != NULL) { |
273 | + g_main_loop_quit(gss_mainloop); |
274 | + } |
275 | + |
276 | + return; |
277 | +} |
278 | + |
279 | +/* Build the gss proxy and set up it's signals */ |
280 | +void |
281 | +build_gss_proxy (void) |
282 | +{ |
283 | + DBusGConnection * session_bus = dbus_g_bus_get(DBUS_BUS_SESSION, NULL); |
284 | + g_return_if_fail(session_bus != NULL); |
285 | + |
286 | + gss_proxy = dbus_g_proxy_new_for_name_owner(session_bus, |
287 | + "org.gnome.ScreenSaver", |
288 | + "/", |
289 | + "org.gnome.ScreenSaver", |
290 | + NULL); |
291 | + g_return_if_fail(gss_proxy != NULL); |
292 | + |
293 | + dbus_g_proxy_add_signal(gss_proxy, "ActiveChanged", G_TYPE_BOOLEAN, G_TYPE_INVALID); |
294 | + dbus_g_proxy_connect_signal(gss_proxy, "ActiveChanged", G_CALLBACK(gss_active_changed), NULL, NULL); |
295 | + |
296 | + return; |
297 | +} |
298 | + |
299 | +/* This is a timeout, we only want to wait for the screen to |
300 | + lock for a little bit, but not forever. */ |
301 | +static gboolean |
302 | +activate_timeout (gpointer data) |
303 | +{ |
304 | + guint * address = (guint *)data; |
305 | + *address = 0; |
306 | + |
307 | + if (gss_mainloop != NULL) { |
308 | + g_main_loop_quit(gss_mainloop); |
309 | + } |
310 | + |
311 | + return FALSE; |
312 | +} |
313 | + |
314 | +/* A fun little function to actually lock the screen. If, |
315 | + that's what you want, let's do it! */ |
316 | +void |
317 | +lock_screen (DbusmenuMenuitem * mi, gpointer data) |
318 | +{ |
319 | + g_debug("Lock Screen"); |
320 | + if (!will_lock_screen()) { |
321 | + g_debug("\tGDM set to autologin, blocking lock"); |
322 | + return; |
323 | + } |
324 | + |
325 | + g_return_if_fail(gss_proxy != NULL); |
326 | + |
327 | + dbus_g_proxy_call_no_reply(gss_proxy, |
328 | + "Lock", |
329 | + G_TYPE_INVALID, |
330 | + G_TYPE_INVALID); |
331 | + |
332 | + if (gss_mainloop == NULL) { |
333 | + gss_mainloop = g_main_loop_new(NULL, FALSE); |
334 | + } |
335 | + |
336 | + guint timer = g_timeout_add_seconds(1, activate_timeout, &timer); |
337 | + |
338 | + g_main_loop_run(gss_mainloop); |
339 | + |
340 | + if (timer != 0) { |
341 | + g_source_remove(timer); |
342 | + } |
343 | + |
344 | + return; |
345 | +} |
346 | + |
347 | +/* Do what it takes to make the lock screen function work |
348 | + and be happy. */ |
349 | +gboolean |
350 | +lock_screen_setup (gpointer data) |
351 | +{ |
352 | + if (!g_strcmp0(g_get_user_name(), "guest")) { |
353 | + is_guest = TRUE; |
354 | + } |
355 | + |
356 | + build_gdm_proxy(); |
357 | + build_gss_proxy(); |
358 | + |
359 | + return FALSE; |
360 | +} |
361 | + |
362 | |
363 | === added file 'src/lock-helper.h' |
364 | --- src/lock-helper.h 1970-01-01 00:00:00 +0000 |
365 | +++ src/lock-helper.h 2009-10-07 17:25:21 +0000 |
366 | @@ -0,0 +1,37 @@ |
367 | +/* |
368 | +A small helper for locking the screen. |
369 | + |
370 | +Copyright 2009 Canonical Ltd. |
371 | + |
372 | +Authors: |
373 | + Ted Gould <ted@canonical.com> |
374 | + |
375 | +This program is free software: you can redistribute it and/or modify it |
376 | +under the terms of the GNU General Public License version 3, as published |
377 | +by the Free Software Foundation. |
378 | + |
379 | +This program is distributed in the hope that it will be useful, but |
380 | +WITHOUT ANY WARRANTY; without even the implied warranties of |
381 | +MERCHANTABILITY, SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR |
382 | +PURPOSE. See the GNU General Public License for more details. |
383 | + |
384 | +You should have received a copy of the GNU General Public License along |
385 | +with this program. If not, see <http://www.gnu.org/licenses/>. |
386 | +*/ |
387 | + |
388 | +#ifndef LOCK_HELPER_H__ |
389 | +#define LOCK_HELPER_H__ |
390 | + |
391 | +#include <libdbusmenu-glib/menuitem.h> |
392 | + |
393 | +typedef void (*gdm_autologin_cb_t) (void); |
394 | + |
395 | +void screensaver_throttle (gchar * reason); |
396 | +void screensaver_unthrottle (void); |
397 | + |
398 | +gboolean will_lock_screen (void); |
399 | +void lock_screen (DbusmenuMenuitem * mi, gpointer data); |
400 | +gboolean lock_screen_setup (gpointer data); |
401 | +void lock_screen_gdm_cb_set (gdm_autologin_cb_t cb); |
402 | + |
403 | +#endif /* LOCK_HELPER_H__ */ |
404 | |
405 | === modified file 'src/session-service.c' |
406 | --- src/session-service.c 2009-09-24 16:12:56 +0000 |
407 | +++ src/session-service.c 2009-10-07 17:25:21 +0000 |
408 | @@ -35,6 +35,8 @@ |
409 | |
410 | #include "gtk-dialog/gconf-helper.h" |
411 | |
412 | +#include "lock-helper.h" |
413 | + |
414 | #define DKP_ADDRESS "org.freedesktop.DeviceKit.Power" |
415 | #define DKP_OBJECT "/org/freedesktop/DeviceKit/Power" |
416 | #define DKP_INTERFACE "org.freedesktop.DeviceKit.Power" |
417 | @@ -44,10 +46,6 @@ |
418 | static DBusGProxy * dkp_main_proxy = NULL; |
419 | static DBusGProxy * dkp_prop_proxy = NULL; |
420 | |
421 | -static DBusGProxy * gdm_settings_proxy = NULL; |
422 | -static gboolean gdm_auto_login = FALSE; |
423 | -static const gchar * gdm_auto_login_string = "daemon/AutomaticLoginEnable"; |
424 | - |
425 | static DBusGProxyCall * suspend_call = NULL; |
426 | static DBusGProxyCall * hibernate_call = NULL; |
427 | |
428 | @@ -57,120 +55,12 @@ |
429 | static DbusmenuMenuitem * restart_mi = NULL; |
430 | static DbusmenuMenuitem * shutdown_mi = NULL; |
431 | |
432 | - |
433 | -/* Respond to the signal of autologin changing to see if the |
434 | - setting for timed login changes. */ |
435 | -static void |
436 | -gdm_settings_change (DBusGProxy * proxy, const gchar * value, const gchar * old, const gchar * new, gpointer data) |
437 | -{ |
438 | - if (g_strcmp0(value, gdm_auto_login_string)) { |
439 | - /* This is not a setting that we care about, |
440 | - there is only one. */ |
441 | - return; |
442 | - } |
443 | - g_debug("GDM Settings change: %s", new); |
444 | - |
445 | - if (g_strcmp0(new, "true") == 0) { |
446 | - gdm_auto_login = TRUE; |
447 | - } else { |
448 | - gdm_auto_login = FALSE; |
449 | - } |
450 | - |
451 | - return; |
452 | -} |
453 | - |
454 | -/* Get back the data from querying to see if there is auto |
455 | - login enabled in GDM */ |
456 | -static void |
457 | -gdm_get_autologin (DBusGProxy * proxy, DBusGProxyCall * call, gpointer data) |
458 | -{ |
459 | - GError * error = NULL; |
460 | - gchar * value = NULL; |
461 | - |
462 | - if (!dbus_g_proxy_end_call(proxy, call, &error, G_TYPE_STRING, &value, G_TYPE_INVALID)) { |
463 | - g_warning("Unable to get autologin setting: %s", error != NULL ? error->message : "null"); |
464 | - g_error_free(error); |
465 | - return; |
466 | - } |
467 | - |
468 | - g_return_if_fail(value != NULL); |
469 | - gdm_settings_change(proxy, gdm_auto_login_string, NULL, value, NULL); |
470 | - |
471 | - return; |
472 | -} |
473 | - |
474 | -/* Sets up the proxy and queries for the setting to know |
475 | - whether we're doing an autologin. */ |
476 | -static gboolean |
477 | -build_gdm_proxy (gpointer null_data) |
478 | -{ |
479 | - g_return_val_if_fail(gdm_settings_proxy == NULL, FALSE); |
480 | - |
481 | - /* Grab the system bus */ |
482 | - DBusGConnection * bus = dbus_g_bus_get(DBUS_BUS_SYSTEM, NULL); |
483 | - g_return_val_if_fail(bus != NULL, FALSE); |
484 | - |
485 | - /* Get the settings proxy */ |
486 | - gdm_settings_proxy = dbus_g_proxy_new_for_name_owner(bus, |
487 | - "org.gnome.DisplayManager", |
488 | - "/org/gnome/DisplayManager/Settings", |
489 | - "org.gnome.DisplayManager.Settings", NULL); |
490 | - g_return_val_if_fail(gdm_settings_proxy != NULL, FALSE); |
491 | - |
492 | - /* Signal for value changed */ |
493 | - dbus_g_proxy_add_signal(gdm_settings_proxy, |
494 | - "ValueChanged", |
495 | - G_TYPE_STRING, |
496 | - G_TYPE_STRING, |
497 | - G_TYPE_STRING, |
498 | - G_TYPE_INVALID); |
499 | - dbus_g_proxy_connect_signal(gdm_settings_proxy, |
500 | - "ValueChanged", |
501 | - G_CALLBACK(gdm_settings_change), |
502 | - NULL, |
503 | - NULL); |
504 | - |
505 | - /* Start to get the initial value */ |
506 | - dbus_g_proxy_begin_call(gdm_settings_proxy, |
507 | - "GetValue", |
508 | - gdm_get_autologin, |
509 | - NULL, |
510 | - NULL, |
511 | - G_TYPE_STRING, |
512 | - gdm_auto_login_string, |
513 | - G_TYPE_INVALID); |
514 | - |
515 | - return FALSE; |
516 | -} |
517 | - |
518 | -/* A fun little function to actually lock the screen. If, |
519 | - that's what you want, let's do it! */ |
520 | -static void |
521 | -lock_screen (void) |
522 | -{ |
523 | - g_debug("Lock Screen"); |
524 | - if (gdm_auto_login) { |
525 | - g_debug("\tGDM set to autologin, blocking lock"); |
526 | - return; |
527 | - } |
528 | - |
529 | - DBusGConnection * session_bus = dbus_g_bus_get(DBUS_BUS_SESSION, NULL); |
530 | - g_return_if_fail(session_bus != NULL); |
531 | - |
532 | - DBusGProxy * proxy = dbus_g_proxy_new_for_name_owner(session_bus, |
533 | - "org.gnome.ScreenSaver", |
534 | - "/", |
535 | - "org.gnome.ScreenSaver", |
536 | - NULL); |
537 | - g_return_if_fail(proxy != NULL); |
538 | - |
539 | - dbus_g_proxy_call_no_reply(proxy, |
540 | - "Lock", |
541 | - G_TYPE_INVALID, |
542 | - G_TYPE_INVALID); |
543 | - |
544 | - g_object_unref(proxy); |
545 | - |
546 | +/* A return from the command to sleep the system. Make sure |
547 | + that we unthrottle the screensaver. */ |
548 | +static void |
549 | +sleep_response (DBusGProxy * proxy, DBusGProxyCall * call, gpointer data) |
550 | +{ |
551 | + screensaver_unthrottle(); |
552 | return; |
553 | } |
554 | |
555 | @@ -185,12 +75,15 @@ |
556 | g_warning("Can not %s as no DeviceKit Power Proxy", type); |
557 | } |
558 | |
559 | - lock_screen(); |
560 | + screensaver_throttle(type); |
561 | + lock_screen(NULL, NULL); |
562 | |
563 | - dbus_g_proxy_call_no_reply(dkp_main_proxy, |
564 | - type, |
565 | - G_TYPE_INVALID, |
566 | - G_TYPE_INVALID); |
567 | + dbus_g_proxy_begin_call(dkp_main_proxy, |
568 | + type, |
569 | + sleep_response, |
570 | + NULL, |
571 | + NULL, |
572 | + G_TYPE_INVALID); |
573 | |
574 | return; |
575 | } |
576 | @@ -427,7 +320,7 @@ |
577 | return 1; |
578 | } |
579 | |
580 | - g_idle_add(build_gdm_proxy, NULL); |
581 | + g_idle_add(lock_screen_setup, NULL); |
582 | |
583 | root_menuitem = dbusmenu_menuitem_new(); |
584 | g_debug("Root ID: %d", dbusmenu_menuitem_get_id(root_menuitem)); |
585 | |
586 | === modified file 'src/users-service.c' |
587 | --- src/users-service.c 2009-10-05 20:38:14 +0000 |
588 | +++ src/users-service.c 2009-10-07 17:25:21 +0000 |
589 | @@ -35,6 +35,7 @@ |
590 | |
591 | #include "dbus-shared-names.h" |
592 | #include "users-service-dbus.h" |
593 | +#include "lock-helper.h" |
594 | |
595 | #define GUEST_SESSION_LAUNCHER "/usr/share/gdm/guest-session/guest-session-launch" |
596 | |
597 | @@ -54,11 +55,6 @@ |
598 | static UsersServiceDbus *dbus_interface = NULL; |
599 | |
600 | static DbusmenuMenuitem *lock_menuitem = NULL; |
601 | -static gboolean is_guest = FALSE; |
602 | - |
603 | -static DBusGProxy * gdm_settings_proxy = NULL; |
604 | -static gboolean gdm_auto_login = FALSE; |
605 | -static const gchar * gdm_auto_login_string = "daemon/AutomaticLoginEnable"; |
606 | |
607 | static gint count; |
608 | static GList *users; |
609 | @@ -66,94 +62,15 @@ |
610 | /* Respond to the signal of autologin changing to see if the |
611 | setting for timed login changes. */ |
612 | static void |
613 | -gdm_settings_change (DBusGProxy * proxy, const gchar * value, const gchar * old, const gchar * new, gpointer data) |
614 | +gdm_settings_change (void) |
615 | { |
616 | - if (g_strcmp0(value, gdm_auto_login_string)) { |
617 | - /* This is not a setting that we care about, |
618 | - there is only one. */ |
619 | - return; |
620 | - } |
621 | - g_debug("GDM Settings change: %s", new); |
622 | - |
623 | - if (g_strcmp0(new, "true") == 0) { |
624 | - gdm_auto_login = TRUE; |
625 | + if (!will_lock_screen()) { |
626 | + dbusmenu_menuitem_property_set(lock_menuitem, DBUSMENU_MENUITEM_PROP_SENSITIVE, "false"); |
627 | } else { |
628 | - gdm_auto_login = FALSE; |
629 | - } |
630 | - |
631 | - if (lock_menuitem != NULL) { |
632 | - if (gdm_auto_login || is_guest) { |
633 | - dbusmenu_menuitem_property_set(lock_menuitem, DBUSMENU_MENUITEM_PROP_SENSITIVE, "false"); |
634 | - } else { |
635 | - dbusmenu_menuitem_property_set(lock_menuitem, DBUSMENU_MENUITEM_PROP_SENSITIVE, "true"); |
636 | - } |
637 | - } |
638 | - |
639 | - return; |
640 | -} |
641 | - |
642 | -/* Get back the data from querying to see if there is auto |
643 | - login enabled in GDM */ |
644 | -static void |
645 | -gdm_get_autologin (DBusGProxy * proxy, DBusGProxyCall * call, gpointer data) |
646 | -{ |
647 | - GError * error = NULL; |
648 | - gchar * value = NULL; |
649 | - |
650 | - if (!dbus_g_proxy_end_call(proxy, call, &error, G_TYPE_STRING, &value, G_TYPE_INVALID)) { |
651 | - g_warning("Unable to get autologin setting: %s", error != NULL ? error->message : "null"); |
652 | - g_error_free(error); |
653 | - return; |
654 | - } |
655 | - |
656 | - g_return_if_fail(value != NULL); |
657 | - gdm_settings_change(proxy, gdm_auto_login_string, NULL, value, NULL); |
658 | - |
659 | - return; |
660 | -} |
661 | - |
662 | -/* Sets up the proxy and queries for the setting to know |
663 | - whether we're doing an autologin. */ |
664 | -static gboolean |
665 | -build_gdm_proxy (gpointer null_data) |
666 | -{ |
667 | - g_return_val_if_fail(gdm_settings_proxy == NULL, FALSE); |
668 | - |
669 | - /* Grab the system bus */ |
670 | - DBusGConnection * bus = dbus_g_bus_get(DBUS_BUS_SYSTEM, NULL); |
671 | - g_return_val_if_fail(bus != NULL, FALSE); |
672 | - |
673 | - /* Get the settings proxy */ |
674 | - gdm_settings_proxy = dbus_g_proxy_new_for_name_owner(bus, |
675 | - "org.gnome.DisplayManager", |
676 | - "/org/gnome/DisplayManager/Settings", |
677 | - "org.gnome.DisplayManager.Settings", NULL); |
678 | - g_return_val_if_fail(gdm_settings_proxy != NULL, FALSE); |
679 | - |
680 | - /* Signal for value changed */ |
681 | - dbus_g_proxy_add_signal(gdm_settings_proxy, |
682 | - "ValueChanged", |
683 | - G_TYPE_STRING, |
684 | - G_TYPE_STRING, |
685 | - G_TYPE_STRING, |
686 | - G_TYPE_INVALID); |
687 | - dbus_g_proxy_connect_signal(gdm_settings_proxy, |
688 | - "ValueChanged", |
689 | - G_CALLBACK(gdm_settings_change), |
690 | - NULL, |
691 | - NULL); |
692 | - |
693 | - /* Start to get the initial value */ |
694 | - dbus_g_proxy_begin_call(gdm_settings_proxy, |
695 | - "GetValue", |
696 | - gdm_get_autologin, |
697 | - NULL, |
698 | - NULL, |
699 | - G_TYPE_STRING, |
700 | - gdm_auto_login_string, |
701 | - G_TYPE_INVALID); |
702 | - |
703 | - return FALSE; |
704 | + dbusmenu_menuitem_property_set(lock_menuitem, DBUSMENU_MENUITEM_PROP_SENSITIVE, "true"); |
705 | + } |
706 | + |
707 | + return; |
708 | } |
709 | |
710 | static gboolean |
711 | @@ -222,37 +139,6 @@ |
712 | return; |
713 | } |
714 | |
715 | -/* A fun little function to actually lock the screen. If, |
716 | - that's what you want, let's do it! */ |
717 | -static void |
718 | -lock_screen (DbusmenuMenuitem * mi, gpointer data) |
719 | -{ |
720 | - g_debug("Lock Screen"); |
721 | - if (gdm_auto_login) { |
722 | - g_debug("\tGDM set to autologin, blocking lock"); |
723 | - return; |
724 | - } |
725 | - |
726 | - DBusGConnection * session_bus = dbus_g_bus_get(DBUS_BUS_SESSION, NULL); |
727 | - g_return_if_fail(session_bus != NULL); |
728 | - |
729 | - DBusGProxy * proxy = dbus_g_proxy_new_for_name_owner(session_bus, |
730 | - "org.gnome.ScreenSaver", |
731 | - "/", |
732 | - "org.gnome.ScreenSaver", |
733 | - NULL); |
734 | - g_return_if_fail(proxy != NULL); |
735 | - |
736 | - dbus_g_proxy_call_no_reply(proxy, |
737 | - "Lock", |
738 | - G_TYPE_INVALID, |
739 | - G_TYPE_INVALID); |
740 | - |
741 | - g_object_unref(proxy); |
742 | - |
743 | - return; |
744 | -} |
745 | - |
746 | static void |
747 | activate_user_session (DbusmenuMenuitem *mi, gpointer user_data) |
748 | { |
749 | @@ -292,7 +178,7 @@ |
750 | dbusmenu_menuitem_property_set(lock_menuitem, DBUSMENU_MENUITEM_PROP_LABEL, _("Lock Screen")); |
751 | g_signal_connect(G_OBJECT(lock_menuitem), DBUSMENU_MENUITEM_SIGNAL_ITEM_ACTIVATED, G_CALLBACK(lock_screen), NULL); |
752 | dbusmenu_menuitem_child_append(root, lock_menuitem); |
753 | - if (gdm_auto_login || is_guest) { |
754 | + if (!will_lock_screen()) { |
755 | dbusmenu_menuitem_property_set(lock_menuitem, DBUSMENU_MENUITEM_PROP_SENSITIVE, "false"); |
756 | } else { |
757 | dbusmenu_menuitem_property_set(lock_menuitem, DBUSMENU_MENUITEM_PROP_SENSITIVE, "true"); |
758 | @@ -410,11 +296,8 @@ |
759 | return 1; |
760 | } |
761 | |
762 | - if (!g_strcmp0(g_get_user_name(), "guest")) { |
763 | - is_guest = TRUE; |
764 | - } |
765 | - |
766 | - g_idle_add(build_gdm_proxy, NULL); |
767 | + g_idle_add(lock_screen_setup, NULL); |
768 | + lock_screen_gdm_cb_set(gdm_settings_change); |
769 | |
770 | dbus_interface = g_object_new (USERS_SERVICE_DBUS_TYPE, NULL); |
771 |
Looks good. Approved.