2
* Copyright (c) 2003-2004 Benedikt Meurer <benny@xfce.org>
3
* Copyright (c) 2011 Nick Schermer <nick@xfce.org>
6
* This program is free software; you can redistribute it and/or modify
7
* it under the terms of the GNU General Public License as published by
8
* the Free Software Foundation; either version 2, or (at your option)
11
* This program is distributed in the hope that it will be useful,
12
* but WITHOUT ANY WARRANTY; without even the implied warranty of
13
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14
* GNU General Public License for more details.
16
* You should have received a copy of the GNU General Public License
17
* along with this program; if not, write to the Free Software
18
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
21
* Parts of this file where taken from gnome-session/logout.c, which
22
* was written by Owen Taylor <otaylor@redhat.com>.
29
#ifdef HAVE_SYS_WAIT_H
46
#include <libxfce4util/libxfce4util.h>
49
#include <libxfsm/xfsm-util.h>
51
#include <xfce4-session/xfsm-logout-dialog.h>
52
#include <xfce4-session/xfsm-fadeout.h>
53
#include <xfce4-session/xfsm-global.h>
54
#include <xfce4-session/xfsm-legacy.h>
55
#include <xfce4-session/xfsm-error.h>
57
#ifdef GDK_WINDOWING_X11
69
static void xfsm_logout_dialog_finalize (GObject *object);
70
static GtkWidget *xfsm_logout_dialog_button (const gchar *title,
71
const gchar *icon_name,
72
const gchar *icon_name_fallback,
73
XfsmShutdownType type,
74
XfsmLogoutDialog *dialog);
75
static void xfsm_logout_dialog_activate (XfsmLogoutDialog *dialog);
87
struct _XfsmLogoutDialogClass
89
GtkDialogClass __parent__;
92
struct _XfsmLogoutDialog
96
/* set when a button is clicked */
97
XfsmShutdownType type_clicked;
99
/* save session checkbox */
100
GtkWidget *save_session;
103
GtkWidget *box[N_MODES];
106
GtkWidget *button_cancel;
107
GtkWidget *button_ok;
108
GtkWidget *button_close;
111
GtkWidget *password_entry;
114
GtkWidget *error_label;
117
XfsmShutdown *shutdown;
122
G_DEFINE_TYPE (XfsmLogoutDialog, xfsm_logout_dialog, GTK_TYPE_DIALOG)
127
xfsm_logout_dialog_class_init (XfsmLogoutDialogClass *klass)
129
GObjectClass *gobject_class;
131
gobject_class = G_OBJECT_CLASS (klass);
132
gobject_class->finalize = xfsm_logout_dialog_finalize;
138
xfsm_logout_dialog_init (XfsmLogoutDialog *dialog)
140
const gchar *username;
143
PangoAttrList *attrs;
145
GtkWidget *button_vbox;
146
GtkWidget *main_vbox;
149
gboolean can_shutdown;
150
gboolean save_session = FALSE;
151
gboolean can_restart;
152
gboolean can_suspend = FALSE;
153
gboolean can_hibernate = FALSE;
154
gboolean auth_suspend = FALSE;
155
gboolean auth_hibernate = FALSE;
156
GError *error = NULL;
157
XfconfChannel *channel;
160
GtkWidget *separator;
161
gboolean upower_not_found = FALSE;
163
dialog->type_clicked = XFSM_SHUTDOWN_LOGOUT;
164
dialog->shutdown = xfsm_shutdown_get ();
166
gtk_dialog_set_default_response (GTK_DIALOG (dialog), GTK_RESPONSE_CANCEL);
167
gtk_dialog_set_has_separator (GTK_DIALOG (dialog), FALSE);
168
gtk_window_set_position (GTK_WINDOW (dialog), GTK_WIN_POS_CENTER);
169
gtk_window_set_resizable (GTK_WINDOW (dialog), FALSE);
171
/* load xfconf settings */
172
channel = xfsm_open_config ();
173
if (xfsm_shutdown_can_save_session (dialog->shutdown))
174
save_session = xfconf_channel_get_bool (channel, "/general/SaveOnExit", TRUE);
176
main_vbox = gtk_vbox_new (FALSE, BORDER);
177
gtk_box_pack_start (GTK_BOX (GTK_DIALOG (dialog)->vbox), main_vbox, TRUE, TRUE, 0);
178
gtk_container_set_border_width (GTK_CONTAINER (main_vbox), BORDER);
179
gtk_widget_show (main_vbox);
181
/* label showing the users' name */
182
username = g_get_real_name ();
185
|| strcmp ("Unknown", username) == 0)
186
username = g_get_user_name ();
188
label_str = g_strdup_printf (_("Log out %s"), username);
189
label = gtk_label_new (label_str);
190
gtk_label_set_justify (GTK_LABEL (label), GTK_JUSTIFY_CENTER);
191
gtk_box_pack_start (GTK_BOX (main_vbox), label, FALSE, TRUE, 0);
192
gtk_widget_show (label);
195
attrs = pango_attr_list_new ();
196
pango_attr_list_insert (attrs, pango_attr_scale_new (PANGO_SCALE_LARGE));
197
pango_attr_list_insert (attrs, pango_attr_weight_new (PANGO_WEIGHT_BOLD));
198
gtk_label_set_attributes (GTK_LABEL (label), attrs);
199
pango_attr_list_unref (attrs);
201
separator = gtk_hseparator_new ();
202
gtk_box_pack_start (GTK_BOX (main_vbox), separator, FALSE, TRUE, 0);
203
gtk_widget_show (separator);
206
* Start mode MODE_LOGOUT_BUTTONS
208
dialog->box[MODE_LOGOUT_BUTTONS] = vbox = gtk_vbox_new (FALSE, BORDER);
209
gtk_box_pack_start (GTK_BOX (main_vbox), vbox, TRUE, TRUE, 0);
214
dialog->button_cancel = gtk_dialog_add_button (GTK_DIALOG (dialog),
216
GTK_RESPONSE_CANCEL);
219
* Ok, for password mode
221
dialog->button_ok = gtk_dialog_add_button (GTK_DIALOG (dialog),
224
gtk_widget_hide (dialog->button_ok);
227
* Close, for password error
229
dialog->button_close = gtk_dialog_add_button (GTK_DIALOG (dialog),
231
GTK_RESPONSE_CANCEL);
232
gtk_widget_hide (dialog->button_close);
234
button_vbox = gtk_vbox_new (TRUE, BORDER);
235
gtk_box_pack_start (GTK_BOX (vbox), button_vbox, FALSE, TRUE, 0);
236
gtk_widget_show (button_vbox);
238
/* row for logout/shutdown and reboot */
239
hbox = gtk_hbox_new (TRUE, BORDER);
240
gtk_box_pack_start (GTK_BOX (button_vbox), hbox, FALSE, TRUE, 0);
241
gtk_widget_show (hbox);
246
button = xfsm_logout_dialog_button (_("_Log Out"), "system-log-out",
247
"xfsm-logout", XFSM_SHUTDOWN_LOGOUT,
250
gtk_box_pack_start (GTK_BOX (hbox), button, TRUE, TRUE, 0);
251
gtk_widget_show (button);
252
gtk_widget_grab_focus (button);
257
if (!xfsm_shutdown_can_restart (dialog->shutdown, &can_restart, &error))
259
g_printerr ("%s: Querying CanRestart failed, %s\n\n",
260
PACKAGE_NAME, ERROR_MSG (error));
261
g_clear_error (&error);
266
button = xfsm_logout_dialog_button (_("_Restart"), "system-reboot",
267
"xfsm-reboot", XFSM_SHUTDOWN_RESTART,
270
gtk_box_pack_start (GTK_BOX (hbox), button, TRUE, TRUE, 0);
271
gtk_widget_set_sensitive (button, can_restart);
272
gtk_widget_show (button);
277
if (!xfsm_shutdown_can_shutdown (dialog->shutdown, &can_shutdown, &error))
279
g_printerr ("%s: Querying CanShutdown failed. %s\n\n",
280
PACKAGE_NAME, ERROR_MSG (error));
281
g_clear_error (&error);
283
can_shutdown = FALSE;
286
button = xfsm_logout_dialog_button (_("Shut _Down"), "system-shutdown",
287
"xfsm-shutdown", XFSM_SHUTDOWN_SHUTDOWN,
290
gtk_box_pack_start (GTK_BOX (hbox), button, TRUE, TRUE, 0);
291
gtk_widget_set_sensitive (button, can_shutdown);
292
gtk_widget_show (button);
294
/* new row for suspend/hibernate */
295
hbox = gtk_hbox_new (TRUE, BORDER);
296
gtk_box_pack_start (GTK_BOX (button_vbox), hbox, FALSE, TRUE, 0);
301
* Hide the button if UPower is not installed or system cannot suspend
303
if (xfconf_channel_get_bool (channel, "/shutdown/ShowSuspend", TRUE))
305
if (xfsm_shutdown_can_suspend (dialog->shutdown, &can_suspend, &auth_suspend, &error))
309
button = xfsm_logout_dialog_button (_("Sus_pend"), "system-suspend",
310
"xfsm-suspend", XFSM_SHUTDOWN_SUSPEND,
313
gtk_box_pack_start (GTK_BOX (hbox), button, TRUE, TRUE, 0);
314
gtk_widget_set_sensitive (button, auth_suspend);
315
gtk_widget_show (button);
317
gtk_widget_show (hbox);
322
g_printerr ("%s: Querying suspend failed: %s\n\n",
323
PACKAGE_NAME, ERROR_MSG (error));
324
g_clear_error (&error);
326
/* don't try hibernate again */
327
upower_not_found = TRUE;
334
* Hide the button if UPower is not installed or system cannot suspend
336
if (!upower_not_found
337
&& xfconf_channel_get_bool (channel, "/shutdown/ShowHibernate", TRUE))
339
if (xfsm_shutdown_can_hibernate (dialog->shutdown, &can_hibernate, &auth_hibernate, &error))
343
button = xfsm_logout_dialog_button (_("_Hibernate"), "system-hibernate",
344
"xfsm-hibernate", XFSM_SHUTDOWN_HIBERNATE,
347
gtk_box_pack_start (GTK_BOX (hbox), button, TRUE, TRUE, 0);
348
gtk_widget_set_sensitive (button, auth_hibernate);
349
gtk_widget_show (button);
351
gtk_widget_show (hbox);
356
g_printerr ("%s: Querying hibernate failed: %s\n\n",
357
PACKAGE_NAME, ERROR_MSG (error));
358
g_clear_error (&error);
365
if (xfsm_shutdown_can_save_session (dialog->shutdown)
366
&& !xfconf_channel_get_bool (channel, "/general/AutoSave", FALSE))
368
dialog->save_session = gtk_check_button_new_with_mnemonic (_("_Save session for future logins"));
369
gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (dialog->save_session), save_session);
370
gtk_box_pack_start (GTK_BOX (vbox), dialog->save_session, FALSE, TRUE, BORDER);
371
gtk_widget_show (dialog->save_session);
374
attrs = pango_attr_list_new ();
375
pango_attr_list_insert (attrs, pango_attr_weight_new (PANGO_WEIGHT_BOLD));
378
* Start mode MODE_ASK_PASSWORD
380
dialog->box[MODE_ASK_PASSWORD] = vbox = gtk_vbox_new (FALSE, BORDER);
381
gtk_box_pack_start (GTK_BOX (main_vbox), vbox, TRUE, TRUE, 0);
383
hbox = gtk_hbox_new (FALSE, BORDER * 2);
384
gtk_box_pack_start (GTK_BOX (vbox), hbox, FALSE, TRUE, 0);
385
gtk_widget_show (hbox);
387
image = gtk_image_new_from_stock (GTK_STOCK_DIALOG_AUTHENTICATION, GTK_ICON_SIZE_DIALOG);
388
gtk_box_pack_start (GTK_BOX (hbox), image, FALSE, FALSE, 0);
389
gtk_widget_show (image);
391
vbox = gtk_vbox_new (FALSE, BORDER);
392
gtk_box_pack_start (GTK_BOX (hbox), vbox, TRUE, TRUE, 0);
393
gtk_widget_show (vbox);
395
label = gtk_label_new (_("Please enter your password"));
396
gtk_misc_set_alignment (GTK_MISC (label), 0.00, 0.50);
397
gtk_label_set_attributes (GTK_LABEL (label), attrs);
398
gtk_box_pack_start (GTK_BOX (vbox), label, FALSE, FALSE, 0);
399
gtk_widget_show (label);
401
dialog->password_entry = entry = gtk_entry_new ();
402
gtk_entry_set_visibility (GTK_ENTRY (entry), FALSE);
403
gtk_entry_set_width_chars (GTK_ENTRY (entry), 30);
404
gtk_box_pack_start (GTK_BOX (vbox), entry, TRUE, TRUE, 0);
405
g_signal_connect_swapped (G_OBJECT (entry), "activate",
406
G_CALLBACK (xfsm_logout_dialog_activate), dialog);
407
gtk_widget_show (entry);
410
* Start mode MODE_SHOW_ERROR
412
dialog->box[MODE_SHOW_ERROR] = vbox = gtk_vbox_new (FALSE, BORDER);
413
gtk_box_pack_start (GTK_BOX (main_vbox), vbox, TRUE, TRUE, 0);
415
hbox = gtk_hbox_new (FALSE, BORDER * 2);
416
gtk_box_pack_start (GTK_BOX (vbox), hbox, FALSE, TRUE, 0);
417
gtk_widget_show (hbox);
419
image = gtk_image_new_from_stock (GTK_STOCK_DIALOG_ERROR, GTK_ICON_SIZE_DIALOG);
420
gtk_box_pack_start (GTK_BOX (hbox), image, FALSE, FALSE, 0);
421
gtk_widget_show (image);
423
vbox = gtk_vbox_new (FALSE, BORDER);
424
gtk_box_pack_start (GTK_BOX (hbox), vbox, TRUE, TRUE, 0);
425
gtk_widget_show (vbox);
427
label = gtk_label_new (_("An error occurred"));
428
gtk_box_pack_start (GTK_BOX (vbox), label, FALSE, FALSE, 0);
429
gtk_misc_set_alignment (GTK_MISC (label), 0.00, 0.50);
430
gtk_label_set_attributes (GTK_LABEL (label), attrs);
431
gtk_widget_show (label);
433
label = gtk_label_new (_("Either the password you entered is "
434
"invalid, or the system administrator "
435
"disallows shutting down this computer "
436
"with your user account."));
437
gtk_label_set_line_wrap (GTK_LABEL (label), TRUE);
438
gtk_box_pack_start (GTK_BOX (vbox), label, TRUE, TRUE, 0);
439
gtk_widget_show (label);
441
pango_attr_list_unref (attrs);
447
xfsm_logout_dialog_finalize (GObject *object)
449
XfsmLogoutDialog *dialog = XFSM_LOGOUT_DIALOG (object);
451
g_object_unref (G_OBJECT (dialog->shutdown));
453
(*G_OBJECT_CLASS (xfsm_logout_dialog_parent_class)->finalize) (object);
459
xfsm_logout_dialog_set_mode (XfsmLogoutDialog *dialog,
464
for (i = 0; i < N_MODES; i++)
465
gtk_widget_set_visible (dialog->box[i], i == mode);
467
gtk_widget_set_visible (dialog->button_cancel, mode != MODE_SHOW_ERROR);
468
gtk_widget_set_visible (dialog->button_ok, mode == MODE_ASK_PASSWORD);
469
gtk_widget_set_visible (dialog->button_close, mode == MODE_SHOW_ERROR);
475
xfsm_logout_dialog_button_clicked (GtkWidget *button,
476
XfsmLogoutDialog *dialog)
480
val = g_object_get_data (G_OBJECT (button), "shutdown-type");
481
g_assert (val != NULL);
482
dialog->type_clicked = *val;
484
gtk_dialog_response (GTK_DIALOG (dialog), GTK_RESPONSE_OK);
490
xfsm_logout_dialog_button (const gchar *title,
491
const gchar *icon_name,
492
const gchar *icon_name_fallback,
493
XfsmShutdownType type,
494
XfsmLogoutDialog *dialog)
501
static gint icon_size = 0;
504
GtkIconTheme *icon_theme;
506
g_return_val_if_fail (XFSM_IS_LOGOUT_DIALOG (dialog), NULL);
508
val = g_new0 (gint, 1);
511
button = gtk_button_new ();
512
g_object_set_data_full (G_OBJECT (button), "shutdown-type", val, g_free);
513
g_signal_connect (G_OBJECT (button), "clicked",
514
G_CALLBACK (xfsm_logout_dialog_button_clicked), dialog);
516
vbox = gtk_vbox_new (FALSE, BORDER);
517
gtk_container_set_border_width (GTK_CONTAINER (vbox), BORDER);
518
gtk_container_add (GTK_CONTAINER (button), vbox);
519
gtk_widget_show (vbox);
521
if (G_UNLIKELY (icon_size == 0))
523
if (gtk_icon_size_lookup (GTK_ICON_SIZE_DND, &w, &h))
524
icon_size = MAX (w, h);
529
icon_theme = gtk_icon_theme_get_for_screen (gtk_window_get_screen (GTK_WINDOW (dialog)));
530
pixbuf = gtk_icon_theme_load_icon (icon_theme, icon_name, icon_size, 0, NULL);
531
if (G_UNLIKELY (pixbuf == NULL))
533
pixbuf = gtk_icon_theme_load_icon (icon_theme, icon_name_fallback,
534
icon_size, GTK_ICON_LOOKUP_GENERIC_FALLBACK,
538
image = gtk_image_new_from_pixbuf (pixbuf);
539
gtk_box_pack_start (GTK_BOX (vbox), image, FALSE, FALSE, 0);
540
gtk_widget_show (image);
542
label = gtk_label_new_with_mnemonic (title);
543
gtk_box_pack_start (GTK_BOX (vbox), label, FALSE, FALSE, 0);
544
gtk_widget_show (label);
552
xfsm_logout_dialog_activate (XfsmLogoutDialog *dialog)
554
g_return_if_fail (XFSM_IS_LOGOUT_DIALOG (dialog));
555
gtk_dialog_response (GTK_DIALOG (dialog), GTK_RESPONSE_OK);
561
xfsm_logout_dialog_screenshot_new (GdkScreen *screen)
563
GdkRectangle rect, screen_rect;
565
GdkPixbuf *screenshot;
568
g_return_val_if_fail (GDK_IS_SCREEN (screen), NULL);
572
screen_rect.width = gdk_screen_get_width (screen);
573
screen_rect.height = gdk_screen_get_height (screen);
575
window = gdk_screen_get_root_window (screen);
576
gdk_drawable_get_size (GDK_DRAWABLE (window), &rect.width, &rect.height);
577
gdk_window_get_origin (window, &x, &y);
582
if (!gdk_rectangle_intersect (&rect, &screen_rect, &rect))
585
screenshot = gdk_pixbuf_get_from_drawable (NULL,
586
GDK_DRAWABLE (window),
593
gdk_display_beep (gdk_screen_get_display (screen));
601
exo_gdk_pixbuf_scale_ratio (GdkPixbuf *source,
611
g_return_val_if_fail (GDK_IS_PIXBUF (source), NULL);
612
g_return_val_if_fail (dest_size > 0, NULL);
614
source_width = gdk_pixbuf_get_width (source);
615
source_height = gdk_pixbuf_get_height (source);
617
wratio = (gdouble) source_width / (gdouble) dest_size;
618
hratio = (gdouble) source_height / (gdouble) dest_size;
622
dest_width = rint (source_width / hratio);
623
dest_height = dest_size;
627
dest_width = dest_size;
628
dest_height = rint (source_height / wratio);
631
return gdk_pixbuf_scale_simple (source, MAX (dest_width, 1),
632
MAX (dest_height, 1), GDK_INTERP_BILINEAR);
638
xfsm_logout_dialog_screenshot_save (GdkPixbuf *screenshot,
640
const gchar *session_name)
646
GError *error = NULL;
649
g_return_if_fail (GDK_IS_PIXBUF (screenshot));
650
g_return_if_fail (GDK_IS_SCREEN (screen));
652
scaled = exo_gdk_pixbuf_scale_ratio (screenshot, SHOTSIZE);
653
if (G_LIKELY (scaled != NULL))
655
dpy = gdk_screen_get_display (screen);
656
display_name = xfsm_gdk_display_get_fullname (dpy);
657
path = g_strconcat ("sessions/thumbs-", display_name, "/", session_name, ".png", NULL);
658
filename = xfce_resource_save_location (XFCE_RESOURCE_CACHE, path, TRUE);
659
g_free (display_name);
662
if (!gdk_pixbuf_save (scaled, filename, "png", &error, NULL))
664
g_warning ("Failed to save session screenshot: %s", error->message);
665
g_error_free (error);
669
g_object_unref (G_OBJECT (scaled));
676
xfsm_logout_dialog_run (GtkDialog *dialog,
684
gtk_widget_show_now (GTK_WIDGET (dialog));
686
window = gtk_widget_get_window (GTK_WIDGET (dialog));
687
if (gdk_keyboard_grab (window, FALSE, GDK_CURRENT_TIME) != GDK_GRAB_SUCCESS)
688
g_critical ("Failed to grab the keyboard for logout window");
690
#ifdef GDK_WINDOWING_X11
691
/* force input to the dialog */
692
gdk_error_trap_push ();
693
XSetInputFocus (GDK_DISPLAY (),
694
GDK_WINDOW_XWINDOW (window),
695
RevertToParent, CurrentTime);
696
gdk_error_trap_pop ();
700
ret = gtk_dialog_run (dialog);
703
gdk_keyboard_ungrab (GDK_CURRENT_TIME);
711
xfsm_logout_dialog (const gchar *session_name,
712
XfsmShutdownType *return_type,
713
gboolean *return_save_session)
721
GdkPixbuf *screenshot = NULL;
722
XfsmFadeout *fadeout = NULL;
723
XfsmLogoutDialog *xfsm_dialog;
724
XfconfChannel *channel = xfsm_open_config ();
728
XfsmShutdown *shutdown;
730
g_return_val_if_fail (return_type != NULL, FALSE);
731
g_return_val_if_fail (return_save_session != NULL, FALSE);
733
shutdown = xfsm_shutdown_get ();
734
if (xfsm_shutdown_can_save_session (shutdown))
735
autosave = xfconf_channel_get_bool (channel, "/general/AutoSave", FALSE);
738
g_object_unref (shutdown);
740
/* check if we need to bother the user */
741
if (!xfconf_channel_get_bool (channel, "/general/PromptOnLogout", TRUE))
743
*return_type = XFSM_SHUTDOWN_LOGOUT;
744
*return_save_session = autosave;
749
/* decide on which screen we should show the dialog */
750
screen = xfce_gdk_screen_get_active (&monitor);
751
if (G_UNLIKELY (screen == NULL))
753
screen = gdk_screen_get_default ();
757
/* check if accessibility is enabled */
758
hidden = gtk_invisible_new_for_screen (screen);
759
gtk_widget_show (hidden);
760
a11y = GTK_IS_ACCESSIBLE (gtk_widget_get_accessible (hidden));
762
if (G_LIKELY (!a11y))
764
/* wait until we can grab the keyboard, we need this for
765
* the dialog when running it */
768
if (gdk_keyboard_grab (gtk_widget_get_window (hidden), FALSE,
769
GDK_CURRENT_TIME) == GDK_GRAB_SUCCESS)
771
gdk_keyboard_ungrab (GDK_CURRENT_TIME);
775
g_usleep (G_USEC_PER_SEC / 20);
778
/* make a screenshot */
779
if (xfconf_channel_get_bool (channel, "/general/ShowScreenshots", TRUE))
780
screenshot = xfsm_logout_dialog_screenshot_new (screen);
782
/* display fadeout */
783
fadeout = xfsm_fadeout_new (gdk_screen_get_display (screen));
786
dialog = g_object_new (XFSM_TYPE_LOGOUT_DIALOG,
787
"type", GTK_WINDOW_POPUP,
788
"screen", screen, NULL);
790
xfsm_window_add_border (GTK_WINDOW (dialog));
792
gtk_widget_realize (dialog);
793
gdk_window_set_override_redirect (dialog->window, TRUE);
794
gdk_window_raise (dialog->window);
798
dialog = g_object_new (XFSM_TYPE_LOGOUT_DIALOG,
800
"screen", screen, NULL);
802
gtk_window_set_keep_above (GTK_WINDOW (dialog), TRUE);
803
atk_object_set_role (gtk_widget_get_accessible (dialog), ATK_ROLE_ALERT);
806
gtk_widget_destroy (hidden);
808
xfsm_dialog = XFSM_LOGOUT_DIALOG (dialog);
811
xfsm_logout_dialog_set_mode (xfsm_dialog, MODE_LOGOUT_BUTTONS);
813
result = xfsm_logout_dialog_run (GTK_DIALOG (dialog), !a11y);
815
gtk_widget_hide (dialog);
817
if (result == GTK_RESPONSE_OK)
819
/* check if the sudo helper needs a password */
820
if (xfsm_shutdown_password_require (xfsm_dialog->shutdown, xfsm_dialog->type_clicked))
823
xfsm_logout_dialog_set_mode (xfsm_dialog, MODE_ASK_PASSWORD);
825
/* don't leave artifacts on the background window */
826
xfsm_fadeout_clear (fadeout);
828
/* loop for sudo password tries */
831
gtk_widget_grab_focus (xfsm_dialog->password_entry);
832
gtk_dialog_set_default_response (GTK_DIALOG (dialog), GTK_RESPONSE_OK);
833
result = xfsm_logout_dialog_run (GTK_DIALOG (dialog), !a11y);
835
if (result == GTK_RESPONSE_OK)
837
/* bit of visual feedback we're processing the password */
838
gtk_widget_set_sensitive (xfsm_dialog->button_cancel, FALSE);
839
gtk_widget_set_sensitive (xfsm_dialog->button_ok, FALSE);
841
/* update the widgets before we lock the loop */
842
while (gtk_events_pending ())
843
g_main_context_iteration (NULL, FALSE);
845
/* send the password to the helper */
846
text = gtk_entry_get_text (GTK_ENTRY (xfsm_dialog->password_entry));
847
state = xfsm_shutdown_password_send (xfsm_dialog->shutdown, xfsm_dialog->type_clicked, text);
848
gtk_entry_set_text (GTK_ENTRY (xfsm_dialog->password_entry), "");
850
gtk_widget_set_sensitive (xfsm_dialog->button_cancel, TRUE);
851
gtk_widget_set_sensitive (xfsm_dialog->button_ok, TRUE);
853
if (state == PASSWORD_RETRY)
856
if (state == PASSWORD_FAILED)
858
gtk_widget_hide (dialog);
860
xfsm_logout_dialog_set_mode (xfsm_dialog, MODE_SHOW_ERROR);
861
gtk_dialog_set_default_response (GTK_DIALOG (dialog), GTK_RESPONSE_CANCEL);
863
/* don't leave artifacts on the background window */
864
xfsm_fadeout_clear (fadeout);
867
xfsm_logout_dialog_run (GTK_DIALOG (dialog), !a11y);
869
result = GTK_RESPONSE_CANCEL;
873
/* cancel clicked, succeeded or helper killed */
877
gtk_widget_hide (dialog);
880
if (result == GTK_RESPONSE_OK)
882
/* store autosave state */
884
*return_save_session = TRUE;
885
else if (xfsm_dialog->save_session != NULL)
886
*return_save_session = gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (xfsm_dialog->save_session));
888
*return_save_session = FALSE;
890
/* return the clicked action */
891
*return_type = xfsm_dialog->type_clicked;
896
xfsm_fadeout_destroy (fadeout);
898
gtk_widget_destroy (dialog);
900
/* store channel settings if everything worked fine */
901
if (result == GTK_RESPONSE_OK)
903
xfconf_channel_set_string (channel, "/general/SessionName", session_name);
904
xfconf_channel_set_bool (channel, "/general/SaveOnExit", *return_save_session);
907
/* save the screenshot */
908
if (screenshot != NULL)
910
if (result == GTK_RESPONSE_OK)
911
xfsm_logout_dialog_screenshot_save (screenshot, screen, session_name);
912
g_object_unref (G_OBJECT (screenshot));
915
return (result == GTK_RESPONSE_OK);