Merge lp:~cyphermox/indicator-session/logind-multiple-session-lp861171 into lp:indicator-session/13.10

Proposed by Mathieu Trudel-Lapierre
Status: Work in progress
Proposed branch: lp:~cyphermox/indicator-session/logind-multiple-session-lp861171
Merge into: lp:indicator-session/13.10
Diff against target: 211 lines (+119/-9)
3 files modified
debian/changelog (+7/-0)
src/dialog.c (+84/-2)
src/gtk-logout-helper.c (+28/-7)
To merge this branch: bzr merge lp:~cyphermox/indicator-session/logind-multiple-session-lp861171
Reviewer Review Type Date Requested Status
PS Jenkins bot (community) continuous-integration Approve
Indicator Applet Developers Pending
Review via email: mp+172118@code.launchpad.net

Commit message

Detect number of sessions via logind

Description of the change

Detect number of sessions via logind

To post a comment you must log in.
395. By Mathieu Trudel-Lapierre

Do the right thing and ask the user for permission if trying to shutdown
or reboot while other sessions are still logged in. (LP: #861171)

Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :
review: Needs Fixing (continuous-integration)
Revision history for this message
Charles Kerr (charlesk) wrote :

This looks great but let's get the GMenuified version of i-session landed first...

Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :
review: Approve (continuous-integration)
Revision history for this message
Charles Kerr (charlesk) wrote :

I'm going to update this patch to trunk i-session

Unmerged revisions

395. By Mathieu Trudel-Lapierre

Do the right thing and ask the user for permission if trying to shutdown
or reboot while other sessions are still logged in. (LP: #861171)

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'debian/changelog'
2--- debian/changelog 2013-06-19 02:01:26 +0000
3+++ debian/changelog 2013-06-28 18:36:28 +0000
4@@ -1,3 +1,10 @@
5+indicator-session (12.10.5daily13.06.28-0ubuntu1) UNRELEASED; urgency=low
6+
7+ * Do the right thing and ask the user for permission if trying to shutdown
8+ or reboot while other sessions are still logged in. (LP: #861171)
9+
10+ -- Mathieu Trudel-Lapierre <mathieu-tl@ubuntu.com> Fri, 28 Jun 2013 11:37:10 -0400
11+
12 indicator-session (12.10.5daily13.06.19-0ubuntu1) saucy; urgency=low
13
14 [ Mathieu Trudel-Lapierre ]
15
16=== modified file 'src/dialog.c'
17--- src/dialog.c 2013-04-11 15:33:54 +0000
18+++ src/dialog.c 2013-06-28 18:36:28 +0000
19@@ -64,6 +64,17 @@
20 static const gchar * restart_auth = N_("Restart Instead…");
21 static const gchar * body_logout_update = N_("Some software updates won’t apply until the computer next restarts.");
22
23+/* TRANSLATORS: This button appears on the restart/shutdown dialog when
24+ there are other users logged in. It will do a log out
25+ in place of a restart / shutdown. */
26+static const gchar * other_session = N_("Log Out Instead");
27+static const gchar * restart_other_session = N_("Other users are logged in. Restarting the computer will log them out without warning.");
28+static const gchar * restart_greeter_other_session = N_("Other users are logged in. You must log out these sessions before restarting.");
29+static const gchar * shutdown_other_session = N_("Other users are logged in. Shutting down the computer will log them out without warning.");
30+static const gchar * shutdown_greeter_other_session = N_("Other users are logged in. You must log out these sessions before shutting down.");
31+static const gchar * restart_anyway = N_("Restart Anyway");
32+static const gchar * shutdown_anyway = N_("Shut Down Anyway");
33+
34 static const gchar * icon_strings[LOGOUT_DIALOG_TYPE_CNT] = {
35 /* LOGOUT_DIALOG_LOGOUT, */ "system-log-out",
36 /* LOGOUT_DIALOG_RESTART, */ "system-restart",
37@@ -164,10 +175,57 @@
38 return g_strcmp0 (allowed, "yes") == 0;
39 }
40
41+/* Checks with console kit how many sessions are open */
42+static gulong
43+get_n_sessions (void)
44+{
45+ Login1Manager *manager_proxy;
46+ GVariant *sessions = NULL;
47+ GVariantIter *iter;
48+ gulong n_sessions = 0;
49+ GError *error = NULL;
50+
51+ manager_proxy = login1_manager_proxy_new_for_bus_sync (G_BUS_TYPE_SYSTEM,
52+ G_DBUS_PROXY_FLAGS_NONE,
53+ "org.freedesktop.login1",
54+ "/org/freedesktop/login1",
55+ NULL,
56+ &error);
57+ if (error) {
58+ g_warning ("Could not get manager proxy.");
59+ g_clear_error (&error);
60+ goto out;
61+ }
62+
63+ login1_manager_call_list_sessions_sync (manager_proxy, &sessions, NULL, &error);
64+
65+ if (error) {
66+ g_warning ("Could not get session list.");
67+ g_clear_error (&error);
68+ goto out;
69+ }
70+
71+ g_variant_get (sessions, "a(susso)", &iter);
72+ n_sessions = g_variant_iter_n_children (iter);
73+
74+out:
75+ g_debug ("found %d sessions", n_sessions);
76+
77+ return n_sessions;
78+}
79+
80+static inline gboolean
81+is_greeter_mode (void)
82+{
83+ return !g_strcmp0 (g_getenv ("INDICATOR_GREETER_MODE"), "1");
84+}
85+
86 LogoutDialog *
87 logout_dialog_new (LogoutDialogType type)
88 {
89- GtkWidget * image = gtk_image_new_from_icon_name(icon_strings[type], GTK_ICON_SIZE_DIALOG);
90+ gulong n_sessions = get_n_sessions ();
91+
92+ GtkWidget * image = gtk_image_new_from_icon_name(n_sessions > 1 ? GTK_STOCK_DIALOG_WARNING : icon_strings[type], GTK_ICON_SIZE_DIALOG);
93 gtk_widget_show(image);
94
95 LogoutDialog * dialog = LOGOUT_DIALOG(g_object_new(LOGOUT_DIALOG_TYPE,
96@@ -205,7 +263,31 @@
97 button_text = g_dpgettext2 (NULL, "button auth", button_auth_strings[type]);
98 }
99
100- if (restart_required) {
101+ if ((type == LOGOUT_DIALOG_TYPE_RESTART || type == LOGOUT_DIALOG_TYPE_SHUTDOWN) && n_sessions > 1) {
102+ if (!is_greeter_mode ()) {
103+ if (type == LOGOUT_DIALOG_TYPE_RESTART) {
104+ g_object_set(dialog, "text", _(restart_other_session), NULL);
105+ button_text = _(restart_anyway);
106+ } else {
107+ g_object_set(dialog, "text", _(shutdown_other_session), NULL);
108+ button_text = _(shutdown_anyway);
109+ }
110+ gtk_dialog_add_buttons(GTK_DIALOG(dialog),
111+ _(other_session), GTK_RESPONSE_HELP,
112+ _("Cancel"), GTK_RESPONSE_CANCEL,
113+ button_text, GTK_RESPONSE_YES,
114+ NULL);
115+ } else {
116+ if (type == LOGOUT_DIALOG_TYPE_RESTART) {
117+ g_object_set(dialog, "text", _(restart_greeter_other_session), NULL);
118+ } else {
119+ g_object_set(dialog, "text", _(shutdown_greeter_other_session), NULL);
120+ }
121+ gtk_dialog_add_buttons(GTK_DIALOG(dialog),
122+ GTK_STOCK_OK, GTK_RESPONSE_CANCEL,
123+ NULL);
124+ }
125+ } else if (restart_required) {
126 const gchar * restart_req;
127 if (allowed) {
128 restart_req = restart_updates;
129
130=== modified file 'src/gtk-logout-helper.c'
131--- src/gtk-logout-helper.c 2013-04-19 10:08:46 +0000
132+++ src/gtk-logout-helper.c 2013-06-28 18:36:28 +0000
133@@ -122,7 +122,7 @@
134 }
135
136 static void
137-session_action (LogoutDialogType action)
138+session_action (LogoutDialogType action, gboolean force)
139 {
140 GError * error = NULL;
141 GVariant *result = NULL;
142@@ -131,11 +131,19 @@
143 g_debug("Asking Session manager to 'Logout'");
144 result = call_gnome_session ("Logout", g_variant_new ("(u)", 1), &error);
145 } else if (action == LOGOUT_DIALOG_TYPE_SHUTDOWN) {
146- g_debug("Asking Session manager to 'RequestShutdown'");
147- result = call_gnome_session ("RequestShutdown", g_variant_new ("()"), &error);
148+ if (force) {
149+ logind_fallback(action);
150+ } else {
151+ g_debug("Asking Session manager to 'RequestShutdown'");
152+ result = call_gnome_session ("RequestShutdown", g_variant_new ("()"), &error);
153+ }
154 } else if (action == LOGOUT_DIALOG_TYPE_RESTART) {
155- g_debug("Asking Session manager to 'RequestReboot'");
156- result = call_gnome_session ("RequestReboot", g_variant_new ("()"), &error);
157+ if (force) {
158+ logind_fallback(action);
159+ } else {
160+ g_debug("Asking Session manager to 'RequestReboot'");
161+ result = call_gnome_session ("RequestReboot", g_variant_new ("()"), &error);
162+ }
163 } else {
164 g_warning ("Unknown session action");
165 }
166@@ -234,12 +242,15 @@
167 dialog = GTK_WIDGET(logout_dialog_new(type));
168 }
169
170+ gboolean force = FALSE;
171 if (dialog != NULL) {
172 GtkResponseType response = gtk_dialog_run(GTK_DIALOG(dialog));
173 gtk_widget_hide(dialog);
174
175 if (response == GTK_RESPONSE_OK) {
176 g_debug("Dialog return response: 'okay'");
177+ } else if (response == GTK_RESPONSE_YES) {
178+ g_debug("Dialog return response: 'yes'");
179 } else if (response == GTK_RESPONSE_HELP) {
180 g_debug("Dialog return response: 'help'");
181 } else {
182@@ -247,17 +258,27 @@
183 }
184
185 if (response == GTK_RESPONSE_HELP) {
186- type = LOGOUT_DIALOG_TYPE_RESTART;
187+ if (type == LOGOUT_DIALOG_TYPE_LOG_OUT)
188+ type = LOGOUT_DIALOG_TYPE_RESTART;
189+ else
190+ type = LOGOUT_DIALOG_TYPE_LOG_OUT;
191 response = GTK_RESPONSE_OK;
192 }
193
194+ /* If we know we're going to need authorization, then call for the action directly
195+ * rather than using Gnome session - it will just log us out instead and not prompt */
196+ if (response == GTK_RESPONSE_YES) {
197+ response = GTK_RESPONSE_OK;
198+ force = TRUE;
199+ }
200+
201 if (response != GTK_RESPONSE_OK) {
202 g_debug("Final response was not okay, quiting");
203 return 0;
204 }
205 }
206
207- session_action(type);
208+ session_action(type, force);
209 g_debug("Finished action, quiting");
210
211 return 0;

Subscribers

People subscribed via source and target branches