Merge lp:~ted/indicator-session/lock-on-sleep into lp:indicator-session/0.1

Proposed by Ted Gould
Status: Merged
Merged at revision: not available
Proposed branch: lp:~ted/indicator-session/lock-on-sleep
Merge into: lp:indicator-session/0.1
Diff against target: 155 lines
1 file modified
src/session-service.c (+125/-0)
To merge this branch: bzr merge lp:~ted/indicator-session/lock-on-sleep
Reviewer Review Type Date Requested Status
David Barth Approve
Review via email: mp+12321@code.launchpad.net
To post a comment you must log in.
Revision history for this message
Ted Gould (ted) wrote :

Adding code to lock the screen when one of the sleep commands is issued.

Revision history for this message
David Barth (dbarth) wrote :

This is a nice idea, but a change in the behavior of the applet and something that has actually not been specified. Besides, it would probably need a configuration option for enterprises to turn that ON, and for netbook users to have that OFF by default.

review: Disapprove
36. By Ted Gould

Putting in the infrastructure to have GDM settings proxy

37. By Ted Gould

Getting the basic grabbing of the proxy and getting the autologin value.

38. By Ted Gould

Setting up the signal handler to get changes to the value.

39. By Ted Gould

Wrong string! Oops.

40. By Ted Gould

Ah, truth, you got me again! Never will I trust you.

Revision history for this message
David Barth (dbarth) wrote :

Cool. To be pedantic i would move the test for autologin next to the lock_screen() call, not inside it.

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'src/session-service.c'
2--- src/session-service.c 2009-09-16 16:34:26 +0000
3+++ src/session-service.c 2009-09-24 16:16:11 +0000
4@@ -44,6 +44,10 @@
5 static DBusGProxy * dkp_main_proxy = NULL;
6 static DBusGProxy * dkp_prop_proxy = NULL;
7
8+static DBusGProxy * gdm_settings_proxy = NULL;
9+static gboolean gdm_auto_login = FALSE;
10+static const gchar * gdm_auto_login_string = "daemon/AutomaticLoginEnable";
11+
12 static DBusGProxyCall * suspend_call = NULL;
13 static DBusGProxyCall * hibernate_call = NULL;
14
15@@ -53,6 +57,123 @@
16 static DbusmenuMenuitem * restart_mi = NULL;
17 static DbusmenuMenuitem * shutdown_mi = NULL;
18
19+
20+/* Respond to the signal of autologin changing to see if the
21+ setting for timed login changes. */
22+static void
23+gdm_settings_change (DBusGProxy * proxy, const gchar * value, const gchar * old, const gchar * new, gpointer data)
24+{
25+ if (g_strcmp0(value, gdm_auto_login_string)) {
26+ /* This is not a setting that we care about,
27+ there is only one. */
28+ return;
29+ }
30+ g_debug("GDM Settings change: %s", new);
31+
32+ if (g_strcmp0(new, "true") == 0) {
33+ gdm_auto_login = TRUE;
34+ } else {
35+ gdm_auto_login = FALSE;
36+ }
37+
38+ return;
39+}
40+
41+/* Get back the data from querying to see if there is auto
42+ login enabled in GDM */
43+static void
44+gdm_get_autologin (DBusGProxy * proxy, DBusGProxyCall * call, gpointer data)
45+{
46+ GError * error = NULL;
47+ gchar * value = NULL;
48+
49+ if (!dbus_g_proxy_end_call(proxy, call, &error, G_TYPE_STRING, &value, G_TYPE_INVALID)) {
50+ g_warning("Unable to get autologin setting: %s", error != NULL ? error->message : "null");
51+ g_error_free(error);
52+ return;
53+ }
54+
55+ g_return_if_fail(value != NULL);
56+ gdm_settings_change(proxy, gdm_auto_login_string, NULL, value, NULL);
57+
58+ return;
59+}
60+
61+/* Sets up the proxy and queries for the setting to know
62+ whether we're doing an autologin. */
63+static gboolean
64+build_gdm_proxy (gpointer null_data)
65+{
66+ g_return_val_if_fail(gdm_settings_proxy == NULL, FALSE);
67+
68+ /* Grab the system bus */
69+ DBusGConnection * bus = dbus_g_bus_get(DBUS_BUS_SYSTEM, NULL);
70+ g_return_val_if_fail(bus != NULL, FALSE);
71+
72+ /* Get the settings proxy */
73+ gdm_settings_proxy = dbus_g_proxy_new_for_name_owner(bus,
74+ "org.gnome.DisplayManager",
75+ "/org/gnome/DisplayManager/Settings",
76+ "org.gnome.DisplayManager.Settings", NULL);
77+ g_return_val_if_fail(gdm_settings_proxy != NULL, FALSE);
78+
79+ /* Signal for value changed */
80+ dbus_g_proxy_add_signal(gdm_settings_proxy,
81+ "ValueChanged",
82+ G_TYPE_STRING,
83+ G_TYPE_STRING,
84+ G_TYPE_STRING,
85+ G_TYPE_INVALID);
86+ dbus_g_proxy_connect_signal(gdm_settings_proxy,
87+ "ValueChanged",
88+ G_CALLBACK(gdm_settings_change),
89+ NULL,
90+ NULL);
91+
92+ /* Start to get the initial value */
93+ dbus_g_proxy_begin_call(gdm_settings_proxy,
94+ "GetValue",
95+ gdm_get_autologin,
96+ NULL,
97+ NULL,
98+ G_TYPE_STRING,
99+ gdm_auto_login_string,
100+ G_TYPE_INVALID);
101+
102+ return FALSE;
103+}
104+
105+/* A fun little function to actually lock the screen. If,
106+ that's what you want, let's do it! */
107+static void
108+lock_screen (void)
109+{
110+ g_debug("Lock Screen");
111+ if (gdm_auto_login) {
112+ g_debug("\tGDM set to autologin, blocking lock");
113+ return;
114+ }
115+
116+ DBusGConnection * session_bus = dbus_g_bus_get(DBUS_BUS_SESSION, NULL);
117+ g_return_if_fail(session_bus != NULL);
118+
119+ DBusGProxy * proxy = dbus_g_proxy_new_for_name_owner(session_bus,
120+ "org.gnome.ScreenSaver",
121+ "/",
122+ "org.gnome.ScreenSaver",
123+ NULL);
124+ g_return_if_fail(proxy != NULL);
125+
126+ dbus_g_proxy_call_no_reply(proxy,
127+ "Lock",
128+ G_TYPE_INVALID,
129+ G_TYPE_INVALID);
130+
131+ g_object_unref(proxy);
132+
133+ return;
134+}
135+
136 /* Let's put this machine to sleep, with some info on how
137 it should sleep. */
138 static void
139@@ -64,6 +185,8 @@
140 g_warning("Can not %s as no DeviceKit Power Proxy", type);
141 }
142
143+ lock_screen();
144+
145 dbus_g_proxy_call_no_reply(dkp_main_proxy,
146 type,
147 G_TYPE_INVALID,
148@@ -304,6 +427,8 @@
149 return 1;
150 }
151
152+ g_idle_add(build_gdm_proxy, NULL);
153+
154 root_menuitem = dbusmenu_menuitem_new();
155 g_debug("Root ID: %d", dbusmenu_menuitem_get_id(root_menuitem));
156

Subscribers

People subscribed via source and target branches