Merge lp:~ted/indicator-session/better-locking into lp:indicator-session/0.1

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
Reviewer Review Type Date Requested Status
Neil J. Patel (community) Approve
Review via email: mp+13010@code.launchpad.net
To post a comment you must log in.
Revision history for this message
Neil J. Patel (njpatel) wrote :

Looks good. Approved.

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== modified file 'src/Makefile.am'
--- src/Makefile.am 2009-09-24 17:09:22 +0000
+++ src/Makefile.am 2009-10-07 17:25:21 +0000
@@ -112,7 +112,12 @@
112# Users Stuff112# Users Stuff
113###############113###############
114114
115indicator_users_service_SOURCES = users-service.c users-service-dbus.c users-service-marshal.c115indicator_users_service_SOURCES = \
116 lock-helper.c \
117 lock-helper.h \
118 users-service.c \
119 users-service-dbus.c \
120 users-service-marshal.c
116indicator_users_service_CFLAGS = $(USERSSERVICE_CFLAGS) -Wall -Werror121indicator_users_service_CFLAGS = $(USERSSERVICE_CFLAGS) -Wall -Werror
117indicator_users_service_LDADD = $(USERSSERVICE_LIBS)122indicator_users_service_LDADD = $(USERSSERVICE_LIBS)
118123
@@ -120,7 +125,11 @@
120# Session Stuff125# Session Stuff
121#################126#################
122127
123indicator_session_service_SOURCES = session-service.c gtk-dialog/gconf-helper.c128indicator_session_service_SOURCES = \
129 lock-helper.c \
130 lock-helper.h \
131 session-service.c \
132 gtk-dialog/gconf-helper.c
124indicator_session_service_CFLAGS = $(SESSIONSERVICE_CFLAGS) $(GCONF_CFLAGS) -DLIBEXECDIR=\"$(libexecdir)\" -Wall -Werror133indicator_session_service_CFLAGS = $(SESSIONSERVICE_CFLAGS) $(GCONF_CFLAGS) -DLIBEXECDIR=\"$(libexecdir)\" -Wall -Werror
125indicator_session_service_LDADD = $(SESSIONSERVICE_LIBS) $(GCONF_LIBS)134indicator_session_service_LDADD = $(SESSIONSERVICE_LIBS) $(GCONF_LIBS)
126135
127136
=== added file 'src/lock-helper.c'
--- src/lock-helper.c 1970-01-01 00:00:00 +0000
+++ src/lock-helper.c 2009-10-07 17:25:21 +0000
@@ -0,0 +1,326 @@
1/*
2A small helper for locking the screen.
3
4Copyright 2009 Canonical Ltd.
5
6Authors:
7 Ted Gould <ted@canonical.com>
8
9This program is free software: you can redistribute it and/or modify it
10under the terms of the GNU General Public License version 3, as published
11by the Free Software Foundation.
12
13This program is distributed in the hope that it will be useful, but
14WITHOUT ANY WARRANTY; without even the implied warranties of
15MERCHANTABILITY, SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR
16PURPOSE. See the GNU General Public License for more details.
17
18You should have received a copy of the GNU General Public License along
19with this program. If not, see <http://www.gnu.org/licenses/>.
20*/
21
22#include <dbus/dbus-glib.h>
23#include "lock-helper.h"
24
25static DBusGProxy * gss_proxy = NULL;
26static GMainLoop * gss_mainloop = NULL;
27static guint cookie = 0;
28static DBusGProxyCall * cookie_call = NULL;
29
30static DBusGProxy * gdm_settings_proxy = NULL;
31static gboolean gdm_auto_login = FALSE;
32static const gchar * gdm_auto_login_string = "daemon/AutomaticLoginEnable";
33
34static gboolean is_guest = FALSE;
35
36static gdm_autologin_cb_t gdm_autologin_cb = NULL;
37
38/* Checks to see if there is an error and reports
39 it. Not much else we can do. */
40static void
41unthrottle_return (DBusGProxy * proxy, DBusGProxyCall * call, gpointer data)
42{
43 GError * error = NULL;
44 dbus_g_proxy_end_call(proxy, call, &error,
45 G_TYPE_INVALID);
46
47 if (error != NULL) {
48 g_warning("Unable to unthrottle: %s", error->message);
49 }
50 return;
51}
52
53/* Sends an unthrottle if we're throttled. */
54void
55screensaver_unthrottle (void)
56{
57 g_return_if_fail(cookie != 0);
58
59 dbus_g_proxy_begin_call(gss_proxy, "UnThrottle",
60 unthrottle_return, NULL,
61 NULL,
62 G_TYPE_UINT, cookie,
63 G_TYPE_INVALID);
64
65 cookie = 0;
66 return;
67}
68
69/* Gets there return cookie from the throttle command
70 and sets things valid */
71static void
72throttle_return (DBusGProxy * proxy, DBusGProxyCall * call, gpointer data)
73{
74 GError * error = NULL;
75 cookie_call = NULL;
76
77 dbus_g_proxy_end_call(proxy, call, &error,
78 G_TYPE_UINT, &cookie,
79 G_TYPE_INVALID);
80
81 if (error != NULL) {
82 g_warning("Unable to throttle the screensaver: %s", error->message);
83 return;
84 }
85
86
87 if (cookie == 0) {
88 g_warning("We didn't get a throttle cookie!");
89 }
90
91 return;
92}
93
94/* Throttling the screensaver by using the screen saver
95 command. */
96void
97screensaver_throttle (gchar * reason)
98{
99 g_return_if_fail(cookie_call == NULL);
100 g_return_if_fail(will_lock_screen());
101
102 if (cookie != 0) {
103 screensaver_unthrottle();
104 }
105
106 cookie_call = dbus_g_proxy_begin_call(gss_proxy, "Throttle",
107 throttle_return, NULL,
108 NULL,
109 G_TYPE_STRING, "Session Menu",
110 G_TYPE_STRING, reason,
111 G_TYPE_INVALID);
112
113 return;
114}
115
116/* Setting up a call back */
117void
118lock_screen_gdm_cb_set (gdm_autologin_cb_t cb)
119{
120 if (gdm_autologin_cb) {
121 g_warning("Already had a callback, setting up a new one...");
122 }
123
124 gdm_autologin_cb = cb;
125 return;
126}
127
128/* This is our logic on whether the screen should be locked
129 or not. It effects everything else. */
130gboolean
131will_lock_screen (void)
132{
133 if (gdm_auto_login) {
134 return FALSE;
135 }
136 if (is_guest) {
137 return FALSE;
138 }
139
140 return TRUE;
141}
142
143/* Respond to the signal of autologin changing to see if the
144 setting for timed login changes. */
145static void
146gdm_settings_change (DBusGProxy * proxy, const gchar * value, const gchar * old, const gchar * new, gpointer data)
147{
148 if (g_strcmp0(value, gdm_auto_login_string)) {
149 /* This is not a setting that we care about,
150 there is only one. */
151 return;
152 }
153 g_debug("GDM Settings change: %s", new);
154
155 if (g_strcmp0(new, "true") == 0) {
156 gdm_auto_login = TRUE;
157 } else {
158 gdm_auto_login = FALSE;
159 }
160
161 if (gdm_autologin_cb != NULL) {
162 gdm_autologin_cb();
163 }
164
165 return;
166}
167
168/* Get back the data from querying to see if there is auto
169 login enabled in GDM */
170static void
171gdm_get_autologin (DBusGProxy * proxy, DBusGProxyCall * call, gpointer data)
172{
173 GError * error = NULL;
174 gchar * value = NULL;
175
176 if (!dbus_g_proxy_end_call(proxy, call, &error, G_TYPE_STRING, &value, G_TYPE_INVALID)) {
177 g_warning("Unable to get autologin setting: %s", error != NULL ? error->message : "null");
178 g_error_free(error);
179 return;
180 }
181
182 g_return_if_fail(value != NULL);
183 gdm_settings_change(proxy, gdm_auto_login_string, NULL, value, NULL);
184
185 return;
186}
187
188/* Sets up the proxy and queries for the setting to know
189 whether we're doing an autologin. */
190static void
191build_gdm_proxy (void)
192{
193 g_return_if_fail(gdm_settings_proxy == NULL);
194
195 /* Grab the system bus */
196 DBusGConnection * bus = dbus_g_bus_get(DBUS_BUS_SYSTEM, NULL);
197 g_return_if_fail(bus != NULL);
198
199 /* Get the settings proxy */
200 gdm_settings_proxy = dbus_g_proxy_new_for_name_owner(bus,
201 "org.gnome.DisplayManager",
202 "/org/gnome/DisplayManager/Settings",
203 "org.gnome.DisplayManager.Settings", NULL);
204 g_return_if_fail(gdm_settings_proxy != NULL);
205
206 /* Signal for value changed */
207 dbus_g_proxy_add_signal(gdm_settings_proxy,
208 "ValueChanged",
209 G_TYPE_STRING,
210 G_TYPE_STRING,
211 G_TYPE_STRING,
212 G_TYPE_INVALID);
213 dbus_g_proxy_connect_signal(gdm_settings_proxy,
214 "ValueChanged",
215 G_CALLBACK(gdm_settings_change),
216 NULL,
217 NULL);
218
219 /* Start to get the initial value */
220 dbus_g_proxy_begin_call(gdm_settings_proxy,
221 "GetValue",
222 gdm_get_autologin,
223 NULL,
224 NULL,
225 G_TYPE_STRING,
226 gdm_auto_login_string,
227 G_TYPE_INVALID);
228
229 return;
230}
231
232/* When the screensave go active, if we've got a mainloop
233 running we should quit it. */
234static void
235gss_active_changed (DBusGProxy * proxy, gboolean active, gpointer data)
236{
237 if (active && gss_mainloop != NULL) {
238 g_main_loop_quit(gss_mainloop);
239 }
240
241 return;
242}
243
244/* Build the gss proxy and set up it's signals */
245void
246build_gss_proxy (void)
247{
248 DBusGConnection * session_bus = dbus_g_bus_get(DBUS_BUS_SESSION, NULL);
249 g_return_if_fail(session_bus != NULL);
250
251 gss_proxy = dbus_g_proxy_new_for_name_owner(session_bus,
252 "org.gnome.ScreenSaver",
253 "/",
254 "org.gnome.ScreenSaver",
255 NULL);
256 g_return_if_fail(gss_proxy != NULL);
257
258 dbus_g_proxy_add_signal(gss_proxy, "ActiveChanged", G_TYPE_BOOLEAN, G_TYPE_INVALID);
259 dbus_g_proxy_connect_signal(gss_proxy, "ActiveChanged", G_CALLBACK(gss_active_changed), NULL, NULL);
260
261 return;
262}
263
264/* This is a timeout, we only want to wait for the screen to
265 lock for a little bit, but not forever. */
266static gboolean
267activate_timeout (gpointer data)
268{
269 guint * address = (guint *)data;
270 *address = 0;
271
272 if (gss_mainloop != NULL) {
273 g_main_loop_quit(gss_mainloop);
274 }
275
276 return FALSE;
277}
278
279/* A fun little function to actually lock the screen. If,
280 that's what you want, let's do it! */
281void
282lock_screen (DbusmenuMenuitem * mi, gpointer data)
283{
284 g_debug("Lock Screen");
285 if (!will_lock_screen()) {
286 g_debug("\tGDM set to autologin, blocking lock");
287 return;
288 }
289
290 g_return_if_fail(gss_proxy != NULL);
291
292 dbus_g_proxy_call_no_reply(gss_proxy,
293 "Lock",
294 G_TYPE_INVALID,
295 G_TYPE_INVALID);
296
297 if (gss_mainloop == NULL) {
298 gss_mainloop = g_main_loop_new(NULL, FALSE);
299 }
300
301 guint timer = g_timeout_add_seconds(1, activate_timeout, &timer);
302
303 g_main_loop_run(gss_mainloop);
304
305 if (timer != 0) {
306 g_source_remove(timer);
307 }
308
309 return;
310}
311
312/* Do what it takes to make the lock screen function work
313 and be happy. */
314gboolean
315lock_screen_setup (gpointer data)
316{
317 if (!g_strcmp0(g_get_user_name(), "guest")) {
318 is_guest = TRUE;
319 }
320
321 build_gdm_proxy();
322 build_gss_proxy();
323
324 return FALSE;
325}
326
0327
=== added file 'src/lock-helper.h'
--- src/lock-helper.h 1970-01-01 00:00:00 +0000
+++ src/lock-helper.h 2009-10-07 17:25:21 +0000
@@ -0,0 +1,37 @@
1/*
2A small helper for locking the screen.
3
4Copyright 2009 Canonical Ltd.
5
6Authors:
7 Ted Gould <ted@canonical.com>
8
9This program is free software: you can redistribute it and/or modify it
10under the terms of the GNU General Public License version 3, as published
11by the Free Software Foundation.
12
13This program is distributed in the hope that it will be useful, but
14WITHOUT ANY WARRANTY; without even the implied warranties of
15MERCHANTABILITY, SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR
16PURPOSE. See the GNU General Public License for more details.
17
18You should have received a copy of the GNU General Public License along
19with this program. If not, see <http://www.gnu.org/licenses/>.
20*/
21
22#ifndef LOCK_HELPER_H__
23#define LOCK_HELPER_H__
24
25#include <libdbusmenu-glib/menuitem.h>
26
27typedef void (*gdm_autologin_cb_t) (void);
28
29void screensaver_throttle (gchar * reason);
30void screensaver_unthrottle (void);
31
32gboolean will_lock_screen (void);
33void lock_screen (DbusmenuMenuitem * mi, gpointer data);
34gboolean lock_screen_setup (gpointer data);
35void lock_screen_gdm_cb_set (gdm_autologin_cb_t cb);
36
37#endif /* LOCK_HELPER_H__ */
038
=== modified file 'src/session-service.c'
--- src/session-service.c 2009-09-24 16:12:56 +0000
+++ src/session-service.c 2009-10-07 17:25:21 +0000
@@ -35,6 +35,8 @@
3535
36#include "gtk-dialog/gconf-helper.h"36#include "gtk-dialog/gconf-helper.h"
3737
38#include "lock-helper.h"
39
38#define DKP_ADDRESS "org.freedesktop.DeviceKit.Power"40#define DKP_ADDRESS "org.freedesktop.DeviceKit.Power"
39#define DKP_OBJECT "/org/freedesktop/DeviceKit/Power"41#define DKP_OBJECT "/org/freedesktop/DeviceKit/Power"
40#define DKP_INTERFACE "org.freedesktop.DeviceKit.Power"42#define DKP_INTERFACE "org.freedesktop.DeviceKit.Power"
@@ -44,10 +46,6 @@
44static DBusGProxy * dkp_main_proxy = NULL;46static DBusGProxy * dkp_main_proxy = NULL;
45static DBusGProxy * dkp_prop_proxy = NULL;47static DBusGProxy * dkp_prop_proxy = NULL;
4648
47static DBusGProxy * gdm_settings_proxy = NULL;
48static gboolean gdm_auto_login = FALSE;
49static const gchar * gdm_auto_login_string = "daemon/AutomaticLoginEnable";
50
51static DBusGProxyCall * suspend_call = NULL;49static DBusGProxyCall * suspend_call = NULL;
52static DBusGProxyCall * hibernate_call = NULL;50static DBusGProxyCall * hibernate_call = NULL;
5351
@@ -57,120 +55,12 @@
57static DbusmenuMenuitem * restart_mi = NULL;55static DbusmenuMenuitem * restart_mi = NULL;
58static DbusmenuMenuitem * shutdown_mi = NULL;56static DbusmenuMenuitem * shutdown_mi = NULL;
5957
6058/* A return from the command to sleep the system. Make sure
61/* Respond to the signal of autologin changing to see if the59 that we unthrottle the screensaver. */
62 setting for timed login changes. */60static void
63static void61sleep_response (DBusGProxy * proxy, DBusGProxyCall * call, gpointer data)
64gdm_settings_change (DBusGProxy * proxy, const gchar * value, const gchar * old, const gchar * new, gpointer data)62{
65{63 screensaver_unthrottle();
66 if (g_strcmp0(value, gdm_auto_login_string)) {
67 /* This is not a setting that we care about,
68 there is only one. */
69 return;
70 }
71 g_debug("GDM Settings change: %s", new);
72
73 if (g_strcmp0(new, "true") == 0) {
74 gdm_auto_login = TRUE;
75 } else {
76 gdm_auto_login = FALSE;
77 }
78
79 return;
80}
81
82/* Get back the data from querying to see if there is auto
83 login enabled in GDM */
84static void
85gdm_get_autologin (DBusGProxy * proxy, DBusGProxyCall * call, gpointer data)
86{
87 GError * error = NULL;
88 gchar * value = NULL;
89
90 if (!dbus_g_proxy_end_call(proxy, call, &error, G_TYPE_STRING, &value, G_TYPE_INVALID)) {
91 g_warning("Unable to get autologin setting: %s", error != NULL ? error->message : "null");
92 g_error_free(error);
93 return;
94 }
95
96 g_return_if_fail(value != NULL);
97 gdm_settings_change(proxy, gdm_auto_login_string, NULL, value, NULL);
98
99 return;
100}
101
102/* Sets up the proxy and queries for the setting to know
103 whether we're doing an autologin. */
104static gboolean
105build_gdm_proxy (gpointer null_data)
106{
107 g_return_val_if_fail(gdm_settings_proxy == NULL, FALSE);
108
109 /* Grab the system bus */
110 DBusGConnection * bus = dbus_g_bus_get(DBUS_BUS_SYSTEM, NULL);
111 g_return_val_if_fail(bus != NULL, FALSE);
112
113 /* Get the settings proxy */
114 gdm_settings_proxy = dbus_g_proxy_new_for_name_owner(bus,
115 "org.gnome.DisplayManager",
116 "/org/gnome/DisplayManager/Settings",
117 "org.gnome.DisplayManager.Settings", NULL);
118 g_return_val_if_fail(gdm_settings_proxy != NULL, FALSE);
119
120 /* Signal for value changed */
121 dbus_g_proxy_add_signal(gdm_settings_proxy,
122 "ValueChanged",
123 G_TYPE_STRING,
124 G_TYPE_STRING,
125 G_TYPE_STRING,
126 G_TYPE_INVALID);
127 dbus_g_proxy_connect_signal(gdm_settings_proxy,
128 "ValueChanged",
129 G_CALLBACK(gdm_settings_change),
130 NULL,
131 NULL);
132
133 /* Start to get the initial value */
134 dbus_g_proxy_begin_call(gdm_settings_proxy,
135 "GetValue",
136 gdm_get_autologin,
137 NULL,
138 NULL,
139 G_TYPE_STRING,
140 gdm_auto_login_string,
141 G_TYPE_INVALID);
142
143 return FALSE;
144}
145
146/* A fun little function to actually lock the screen. If,
147 that's what you want, let's do it! */
148static void
149lock_screen (void)
150{
151 g_debug("Lock Screen");
152 if (gdm_auto_login) {
153 g_debug("\tGDM set to autologin, blocking lock");
154 return;
155 }
156
157 DBusGConnection * session_bus = dbus_g_bus_get(DBUS_BUS_SESSION, NULL);
158 g_return_if_fail(session_bus != NULL);
159
160 DBusGProxy * proxy = dbus_g_proxy_new_for_name_owner(session_bus,
161 "org.gnome.ScreenSaver",
162 "/",
163 "org.gnome.ScreenSaver",
164 NULL);
165 g_return_if_fail(proxy != NULL);
166
167 dbus_g_proxy_call_no_reply(proxy,
168 "Lock",
169 G_TYPE_INVALID,
170 G_TYPE_INVALID);
171
172 g_object_unref(proxy);
173
174 return;64 return;
175}65}
17666
@@ -185,12 +75,15 @@
185 g_warning("Can not %s as no DeviceKit Power Proxy", type);75 g_warning("Can not %s as no DeviceKit Power Proxy", type);
186 }76 }
18777
188 lock_screen();78 screensaver_throttle(type);
79 lock_screen(NULL, NULL);
18980
190 dbus_g_proxy_call_no_reply(dkp_main_proxy,81 dbus_g_proxy_begin_call(dkp_main_proxy,
191 type,82 type,
192 G_TYPE_INVALID,83 sleep_response,
193 G_TYPE_INVALID);84 NULL,
85 NULL,
86 G_TYPE_INVALID);
19487
195 return;88 return;
196}89}
@@ -427,7 +320,7 @@
427 return 1;320 return 1;
428 } 321 }
429322
430 g_idle_add(build_gdm_proxy, NULL);323 g_idle_add(lock_screen_setup, NULL);
431324
432 root_menuitem = dbusmenu_menuitem_new();325 root_menuitem = dbusmenu_menuitem_new();
433 g_debug("Root ID: %d", dbusmenu_menuitem_get_id(root_menuitem));326 g_debug("Root ID: %d", dbusmenu_menuitem_get_id(root_menuitem));
434327
=== modified file 'src/users-service.c'
--- src/users-service.c 2009-10-05 20:38:14 +0000
+++ src/users-service.c 2009-10-07 17:25:21 +0000
@@ -35,6 +35,7 @@
3535
36#include "dbus-shared-names.h"36#include "dbus-shared-names.h"
37#include "users-service-dbus.h"37#include "users-service-dbus.h"
38#include "lock-helper.h"
3839
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"
4041
@@ -54,11 +55,6 @@
54static UsersServiceDbus *dbus_interface = NULL;55static UsersServiceDbus *dbus_interface = NULL;
5556
56static DbusmenuMenuitem *lock_menuitem = NULL;57static DbusmenuMenuitem *lock_menuitem = NULL;
57static gboolean is_guest = FALSE;
58
59static DBusGProxy * gdm_settings_proxy = NULL;
60static gboolean gdm_auto_login = FALSE;
61static const gchar * gdm_auto_login_string = "daemon/AutomaticLoginEnable";
6258
63static gint count;59static gint count;
64static GList *users;60static GList *users;
@@ -66,94 +62,15 @@
66/* Respond to the signal of autologin changing to see if the62/* Respond to the signal of autologin changing to see if the
67 setting for timed login changes. */63 setting for timed login changes. */
68static void64static void
69gdm_settings_change (DBusGProxy * proxy, const gchar * value, const gchar * old, const gchar * new, gpointer data)65gdm_settings_change (void)
70{66{
71 if (g_strcmp0(value, gdm_auto_login_string)) {67 if (!will_lock_screen()) {
72 /* This is not a setting that we care about,68 dbusmenu_menuitem_property_set(lock_menuitem, DBUSMENU_MENUITEM_PROP_SENSITIVE, "false");
73 there is only one. */
74 return;
75 }
76 g_debug("GDM Settings change: %s", new);
77
78 if (g_strcmp0(new, "true") == 0) {
79 gdm_auto_login = TRUE;
80 } else {69 } else {
81 gdm_auto_login = FALSE;70 dbusmenu_menuitem_property_set(lock_menuitem, DBUSMENU_MENUITEM_PROP_SENSITIVE, "true");
82 }71 }
8372
84 if (lock_menuitem != NULL) {73 return;
85 if (gdm_auto_login || is_guest) {
86 dbusmenu_menuitem_property_set(lock_menuitem, DBUSMENU_MENUITEM_PROP_SENSITIVE, "false");
87 } else {
88 dbusmenu_menuitem_property_set(lock_menuitem, DBUSMENU_MENUITEM_PROP_SENSITIVE, "true");
89 }
90 }
91
92 return;
93}
94
95/* Get back the data from querying to see if there is auto
96 login enabled in GDM */
97static void
98gdm_get_autologin (DBusGProxy * proxy, DBusGProxyCall * call, gpointer data)
99{
100 GError * error = NULL;
101 gchar * value = NULL;
102
103 if (!dbus_g_proxy_end_call(proxy, call, &error, G_TYPE_STRING, &value, G_TYPE_INVALID)) {
104 g_warning("Unable to get autologin setting: %s", error != NULL ? error->message : "null");
105 g_error_free(error);
106 return;
107 }
108
109 g_return_if_fail(value != NULL);
110 gdm_settings_change(proxy, gdm_auto_login_string, NULL, value, NULL);
111
112 return;
113}
114
115/* Sets up the proxy and queries for the setting to know
116 whether we're doing an autologin. */
117static gboolean
118build_gdm_proxy (gpointer null_data)
119{
120 g_return_val_if_fail(gdm_settings_proxy == NULL, FALSE);
121
122 /* Grab the system bus */
123 DBusGConnection * bus = dbus_g_bus_get(DBUS_BUS_SYSTEM, NULL);
124 g_return_val_if_fail(bus != NULL, FALSE);
125
126 /* Get the settings proxy */
127 gdm_settings_proxy = dbus_g_proxy_new_for_name_owner(bus,
128 "org.gnome.DisplayManager",
129 "/org/gnome/DisplayManager/Settings",
130 "org.gnome.DisplayManager.Settings", NULL);
131 g_return_val_if_fail(gdm_settings_proxy != NULL, FALSE);
132
133 /* Signal for value changed */
134 dbus_g_proxy_add_signal(gdm_settings_proxy,
135 "ValueChanged",
136 G_TYPE_STRING,
137 G_TYPE_STRING,
138 G_TYPE_STRING,
139 G_TYPE_INVALID);
140 dbus_g_proxy_connect_signal(gdm_settings_proxy,
141 "ValueChanged",
142 G_CALLBACK(gdm_settings_change),
143 NULL,
144 NULL);
145
146 /* Start to get the initial value */
147 dbus_g_proxy_begin_call(gdm_settings_proxy,
148 "GetValue",
149 gdm_get_autologin,
150 NULL,
151 NULL,
152 G_TYPE_STRING,
153 gdm_auto_login_string,
154 G_TYPE_INVALID);
155
156 return FALSE;
157}74}
15875
159static gboolean76static gboolean
@@ -222,37 +139,6 @@
222 return;139 return;
223}140}
224141
225/* A fun little function to actually lock the screen. If,
226 that's what you want, let's do it! */
227static void
228lock_screen (DbusmenuMenuitem * mi, gpointer data)
229{
230 g_debug("Lock Screen");
231 if (gdm_auto_login) {
232 g_debug("\tGDM set to autologin, blocking lock");
233 return;
234 }
235
236 DBusGConnection * session_bus = dbus_g_bus_get(DBUS_BUS_SESSION, NULL);
237 g_return_if_fail(session_bus != NULL);
238
239 DBusGProxy * proxy = dbus_g_proxy_new_for_name_owner(session_bus,
240 "org.gnome.ScreenSaver",
241 "/",
242 "org.gnome.ScreenSaver",
243 NULL);
244 g_return_if_fail(proxy != NULL);
245
246 dbus_g_proxy_call_no_reply(proxy,
247 "Lock",
248 G_TYPE_INVALID,
249 G_TYPE_INVALID);
250
251 g_object_unref(proxy);
252
253 return;
254}
255
256static void142static void
257activate_user_session (DbusmenuMenuitem *mi, gpointer user_data)143activate_user_session (DbusmenuMenuitem *mi, gpointer user_data)
258{144{
@@ -292,7 +178,7 @@
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"));
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);
294 dbusmenu_menuitem_child_append(root, lock_menuitem);180 dbusmenu_menuitem_child_append(root, lock_menuitem);
295 if (gdm_auto_login || is_guest) {181 if (!will_lock_screen()) {
296 dbusmenu_menuitem_property_set(lock_menuitem, DBUSMENU_MENUITEM_PROP_SENSITIVE, "false");182 dbusmenu_menuitem_property_set(lock_menuitem, DBUSMENU_MENUITEM_PROP_SENSITIVE, "false");
297 } else {183 } else {
298 dbusmenu_menuitem_property_set(lock_menuitem, DBUSMENU_MENUITEM_PROP_SENSITIVE, "true");184 dbusmenu_menuitem_property_set(lock_menuitem, DBUSMENU_MENUITEM_PROP_SENSITIVE, "true");
@@ -410,11 +296,8 @@
410 return 1;296 return 1;
411 }297 }
412298
413 if (!g_strcmp0(g_get_user_name(), "guest")) {299 g_idle_add(lock_screen_setup, NULL);
414 is_guest = TRUE;300 lock_screen_gdm_cb_set(gdm_settings_change);
415 }
416
417 g_idle_add(build_gdm_proxy, NULL);
418301
419 dbus_interface = g_object_new (USERS_SERVICE_DBUS_TYPE, NULL);302 dbus_interface = g_object_new (USERS_SERVICE_DBUS_TYPE, NULL);
420303

Subscribers

People subscribed via source and target branches