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