~ubuntu-branches/ubuntu/vivid/xfce4-session/vivid-proposed

« back to all changes in this revision

Viewing changes to xfce4-session/shutdown.c

  • Committer: Package Import Robot
  • Author(s): Lionel Le Folgoc
  • Date: 2012-05-18 20:21:52 UTC
  • mfrom: (4.1.7 experimental)
  • Revision ID: package-import@ubuntu.com-20120518202152-7bm9pla0j3ccfsnk
Tags: 4.10.0-1ubuntu1
* Merge from Debian experimental, remaining Ubuntu changes:
  - debian/control: build-depends on libgnome-keyring-dev to enable GNOME
    Keyring services support.
  - debian/rules: pass --enable-libgnome-keyring to dh_auto_configure.
  - debian/patches:
    + xubuntu_ignore-gdm-lang.patch: do not set $LANG to $GDM_LANG, there's
      already an xsession script to do that, and $GDM_LANG might not contain
      a valid locale code.

* debian/patches:
  - xubuntu_set-xdg-current-desktop.patch: added. Taken from xfce4-utils,
    export XDG_CURRENT_DESKTOP=XFCE, can be useful with alacarte and
    gnome-menus. lp #927172

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/* $Id$ */
2
 
/*-
3
 
 * Copyright (c) 2003-2004 Benedikt Meurer <benny@xfce.org>
4
 
 * All rights reserved.
5
 
 *
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)
9
 
 * any later version.
10
 
 *
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.
15
 
 *
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,
19
 
 * MA 02110-1301 USA.
20
 
 *
21
 
 * Parts of this file where taken from gnome-session/logout.c, which
22
 
 * was written by Owen Taylor <otaylor@redhat.com>.
23
 
 */
24
 
 
25
 
#ifdef HAVE_CONFIG_H
26
 
#include <config.h>
27
 
#endif
28
 
 
29
 
#ifdef HAVE_SYS_WAIT_H
30
 
#include <sys/wait.h>
31
 
#endif
32
 
 
33
 
#ifdef HAVE_STDLIB_H
34
 
#include <stdlib.h>
35
 
#endif
36
 
#ifdef HAVE_STRING_H
37
 
#include <string.h>
38
 
#endif
39
 
#ifdef HAVE_UNISTD_H
40
 
#include <unistd.h>
41
 
#endif
42
 
 
43
 
#ifdef HAVE_GETPWUID
44
 
#ifdef HAVE_SYS_TYPES_H
45
 
#include <sys/types.h>
46
 
#endif
47
 
#ifdef HAVE_PWD_H
48
 
#include <pwd.h>
49
 
#endif
50
 
#endif
51
 
 
52
 
#ifdef HAVE_ASM_UNISTD_H
53
 
#include <asm/unistd.h>  /* for __NR_ioprio_set */
54
 
#endif
55
 
 
56
 
#include <libxfce4util/libxfce4util.h>
57
 
#include <gtk/gtk.h>
58
 
 
59
 
#include <libxfsm/xfsm-util.h>
60
 
 
61
 
#include <xfce4-session/shutdown.h>
62
 
#include <xfce4-session/xfsm-compat-gnome.h>
63
 
#include <xfce4-session/xfsm-compat-kde.h>
64
 
#include <xfce4-session/xfsm-fadeout.h>
65
 
#include <xfce4-session/xfsm-global.h>
66
 
#include <xfce4-session/xfsm-legacy.h>
67
 
#include <xfce4-session/xfsm-shutdown-helper.h>
68
 
 
69
 
#define BORDER    6
70
 
 
71
 
 
72
 
static XfsmShutdownHelper *shutdown_helper = NULL;
73
 
 
74
 
static GtkWidget *shutdown_dialog = NULL;
75
 
 
76
 
#ifdef SESSION_SCREENSHOTS
77
 
static void
78
 
screenshot_save (const gchar *session_name, GdkPixmap *pm, GdkRectangle *area)
79
 
{
80
 
  gchar *display_name;
81
 
  gchar *resource;
82
 
  gchar *filename;
83
 
  GdkDisplay *dpy;
84
 
  GdkPixbuf *spb;
85
 
  GdkPixbuf *pb;
86
 
 
87
 
  pb = gdk_pixbuf_get_from_drawable (NULL, GDK_DRAWABLE (pm), NULL,
88
 
                                     0, 0, 0, 0, area->width, area->height);
89
 
 
90
 
  if (pb != NULL)
91
 
    {
92
 
      /* scale down the pixbuf */
93
 
      spb = gdk_pixbuf_scale_simple (pb, 52, 43, GDK_INTERP_HYPER);
94
 
 
95
 
      if (spb != NULL)
96
 
        {
97
 
          /* determine thumb file */
98
 
          dpy = gdk_drawable_get_display (GDK_DRAWABLE (pm));
99
 
          display_name = xfsm_gdk_display_get_fullname (dpy);
100
 
          resource = g_strconcat ("sessions/thumbs-", display_name,
101
 
                                  "/", session_name, ".png", NULL);
102
 
          filename = xfce_resource_save_location (XFCE_RESOURCE_CACHE,
103
 
                                                  resource, TRUE);
104
 
          g_free (display_name);
105
 
          g_free (resource);
106
 
 
107
 
          gdk_pixbuf_save (spb, filename, "png", NULL, NULL);
108
 
 
109
 
          g_object_unref (G_OBJECT (spb));
110
 
          g_free (filename);
111
 
        }
112
 
 
113
 
      g_object_unref (G_OBJECT (pb));
114
 
    }
115
 
}
116
 
#endif
117
 
 
118
 
 
119
 
static void
120
 
entry_activate_cb (GtkWidget *entry, GtkDialog *dialog)
121
 
{
122
 
  gtk_dialog_response (GTK_DIALOG (dialog), GTK_RESPONSE_OK);
123
 
}
124
 
 
125
 
static void
126
 
logout_button_clicked (GtkWidget *b, gint *shutdownType)
127
 
{
128
 
    *shutdownType = XFSM_SHUTDOWN_LOGOUT;
129
 
 
130
 
    gtk_dialog_response (GTK_DIALOG (shutdown_dialog), GTK_RESPONSE_OK);
131
 
}
132
 
 
133
 
static void
134
 
reboot_button_clicked (GtkWidget *b, gint *shutdownType)
135
 
{
136
 
    *shutdownType = XFSM_SHUTDOWN_REBOOT;
137
 
 
138
 
    gtk_dialog_response (GTK_DIALOG (shutdown_dialog), GTK_RESPONSE_OK);
139
 
}
140
 
 
141
 
static void
142
 
halt_button_clicked (GtkWidget *b, gint *shutdownType)
143
 
{
144
 
    *shutdownType = XFSM_SHUTDOWN_HALT;
145
 
 
146
 
    gtk_dialog_response (GTK_DIALOG (shutdown_dialog), GTK_RESPONSE_OK);
147
 
}
148
 
 
149
 
static void
150
 
suspend_button_clicked (GtkWidget *b, gint *shutdownType)
151
 
{
152
 
    *shutdownType = XFSM_SHUTDOWN_SUSPEND;
153
 
 
154
 
    gtk_dialog_response (GTK_DIALOG (shutdown_dialog), GTK_RESPONSE_OK);
155
 
}
156
 
 
157
 
static void
158
 
hibernate_button_clicked (GtkWidget *b, gint *shutdownType)
159
 
{
160
 
    *shutdownType = XFSM_SHUTDOWN_HIBERNATE;
161
 
 
162
 
    gtk_dialog_response (GTK_DIALOG (shutdown_dialog), GTK_RESPONSE_OK);
163
 
}
164
 
 
165
 
/*
166
 
 */
167
 
gboolean
168
 
shutdownDialog(const gchar *sessionName, XfsmShutdownType *shutdownType, gboolean *saveSession)
169
 
{
170
 
  gboolean accessibility;
171
 
  GtkIconTheme *icon_theme;
172
 
  XfsmFadeout *fadeout = NULL;
173
 
  GdkScreen *screen;
174
 
  GtkWidget *dialog;
175
 
  GtkWidget *label;
176
 
  GtkWidget *dbox;
177
 
  GtkWidget *hbox;
178
 
  GtkWidget *vbox;
179
 
  GtkWidget *vbox2;
180
 
  GtkWidget *image;
181
 
  GtkWidget *checkbox;
182
 
  GtkWidget *entry_vbox;
183
 
  GtkWidget *entry;
184
 
  GtkWidget *hidden;
185
 
  GtkWidget *logout_button;
186
 
  GtkWidget *reboot_button;
187
 
  GtkWidget *halt_button;
188
 
  GtkWidget *suspend_button = NULL;
189
 
  GtkWidget *hibernate_button = NULL;
190
 
  GtkWidget *cancel_button;
191
 
  GtkWidget *ok_button;
192
 
  GdkPixbuf *icon;
193
 
  gboolean saveonexit;
194
 
  gboolean autosave;
195
 
  gboolean prompt;
196
 
  gboolean show_suspend;
197
 
  gboolean show_hibernate;
198
 
 
199
 
  gboolean show_restart;
200
 
  gboolean show_shutdown;
201
 
 
202
 
  gboolean require_password;
203
 
 
204
 
  gint monitor;
205
 
  gint result;
206
 
  XfceKiosk *kiosk;
207
 
  gboolean kiosk_can_shutdown;
208
 
  gboolean kiosk_can_save_session;
209
 
  XfconfChannel *channel;
210
 
#ifdef SESSION_SCREENSHOTS
211
 
  GdkRectangle screenshot_area;
212
 
  GdkWindow *root;
213
 
  GdkPixmap *screenshot_pm = NULL;
214
 
  GdkGC *screenshot_gc;
215
 
#endif
216
 
#ifdef HAVE_GETPWUID
217
 
  struct passwd *pw;
218
 
#endif
219
 
 
220
 
  g_return_val_if_fail(saveSession != NULL, FALSE);
221
 
  g_return_val_if_fail(shutdownType != NULL, FALSE);
222
 
 
223
 
  icon_theme = gtk_icon_theme_get_default ();
224
 
 
225
 
  /* destroy any previously running shutdown helper first */
226
 
  if (shutdown_helper != NULL)
227
 
    {
228
 
      g_object_unref (shutdown_helper);
229
 
      shutdown_helper = NULL;
230
 
    }
231
 
 
232
 
  /* load kiosk settings */
233
 
  kiosk = xfce_kiosk_new ("xfce4-session");
234
 
  kiosk_can_shutdown = xfce_kiosk_query (kiosk, "Shutdown");
235
 
  kiosk_can_save_session = xfce_kiosk_query (kiosk, "SaveSession");
236
 
  xfce_kiosk_free (kiosk);
237
 
 
238
 
  /* load configuration */
239
 
  channel = xfsm_open_config ();
240
 
  channel = xfconf_channel_get ("xfce4-session");
241
 
  saveonexit = xfconf_channel_get_bool (channel, "/general/SaveOnExit", TRUE);
242
 
  autosave = xfconf_channel_get_bool (channel, "/general/AutoSave", FALSE);
243
 
  prompt = xfconf_channel_get_bool (channel, "/general/PromptOnLogout", TRUE);
244
 
  show_suspend = xfconf_channel_get_bool (channel, "/shutdown/ShowSuspend", TRUE);
245
 
  show_hibernate = xfconf_channel_get_bool (channel, "/shutdown/ShowHibernate", TRUE);
246
 
 
247
 
  /* make the session-save settings obey the kiosk settings */
248
 
  if (!kiosk_can_save_session)
249
 
    {
250
 
      saveonexit = FALSE;
251
 
      autosave = FALSE;
252
 
    }
253
 
 
254
 
  /* if PromptOnLogout is off, saving depends on AutoSave */
255
 
  if (!prompt)
256
 
    {
257
 
      *shutdownType = XFSM_SHUTDOWN_LOGOUT;
258
 
      *saveSession = autosave;
259
 
 
260
 
      return TRUE;
261
 
    }
262
 
 
263
 
  /* spawn the helper early so we know what it supports when
264
 
   * constructing the dialog */
265
 
  shutdown_helper = xfsm_shutdown_helper_new ();
266
 
 
267
 
  /* It's really bad here if someone else has the pointer
268
 
   * grabbed, so we first grab the pointer and keyboard
269
 
   * to an offscreen window, and then once we have the
270
 
   * server grabbed, move that to our dialog.
271
 
   */
272
 
  gtk_rc_reparse_all ();
273
 
 
274
 
  /* get screen with pointer */
275
 
  screen = xfce_gdk_screen_get_active (&monitor);
276
 
  if (screen == NULL)
277
 
    {
278
 
      screen = gdk_screen_get_default ();
279
 
      monitor = 0;
280
 
    }
281
 
 
282
 
  /* Try to grab Input on a hidden window first */
283
 
  hidden = gtk_invisible_new_for_screen (screen);
284
 
  gtk_widget_show_now (hidden);
285
 
 
286
 
  accessibility = GTK_IS_ACCESSIBLE (gtk_widget_get_accessible (hidden));
287
 
 
288
 
  if (!accessibility)
289
 
    {
290
 
      for (;;)
291
 
        {
292
 
          if (gdk_pointer_grab (hidden->window, TRUE, 0, NULL, NULL,
293
 
                                GDK_CURRENT_TIME) == GDK_GRAB_SUCCESS)
294
 
            {
295
 
              if (gdk_keyboard_grab (hidden->window, FALSE, GDK_CURRENT_TIME)
296
 
                  == GDK_GRAB_SUCCESS)
297
 
                {
298
 
                  break;
299
 
                }
300
 
 
301
 
              gdk_pointer_ungrab (GDK_CURRENT_TIME);
302
 
            }
303
 
 
304
 
          g_usleep (50 * 1000);
305
 
        }
306
 
 
307
 
#ifdef SESSION_SCREENSHOTS
308
 
      /* grab a screenshot */
309
 
      root = gdk_screen_get_root_window (screen);
310
 
      gdk_screen_get_monitor_geometry (screen, monitor, &screenshot_area);
311
 
      screenshot_pm = gdk_pixmap_new (GDK_DRAWABLE (root),
312
 
                                      screenshot_area.width,
313
 
                                      screenshot_area.height,
314
 
                                      -1);
315
 
      screenshot_gc = gdk_gc_new (GDK_DRAWABLE (screenshot_pm));
316
 
      gdk_gc_set_function (screenshot_gc, GDK_COPY);
317
 
      gdk_gc_set_subwindow (screenshot_gc, TRUE);
318
 
      gdk_draw_drawable (GDK_DRAWABLE (screenshot_pm),
319
 
                         screenshot_gc,
320
 
                         GDK_DRAWABLE (root),
321
 
                         screenshot_area.x,
322
 
                         screenshot_area.y,
323
 
                         0,
324
 
                         0,
325
 
                         screenshot_area.width,
326
 
                         screenshot_area.height);
327
 
      g_object_unref (G_OBJECT (screenshot_gc));
328
 
#endif
329
 
 
330
 
      /* display fadeout */
331
 
      fadeout = xfsm_fadeout_new (gtk_widget_get_display (hidden));
332
 
      gdk_flush ();
333
 
 
334
 
      /* create confirm dialog */
335
 
      dialog = g_object_new (GTK_TYPE_DIALOG,
336
 
                             "type", GTK_WINDOW_POPUP,
337
 
                             NULL);
338
 
    }
339
 
  else
340
 
    {
341
 
      dialog = gtk_dialog_new ();
342
 
      atk_object_set_role (gtk_widget_get_accessible (dialog), ATK_ROLE_ALERT);
343
 
      gtk_window_set_decorated (GTK_WINDOW (dialog), FALSE);
344
 
    }
345
 
 
346
 
  shutdown_dialog = dialog;
347
 
 
348
 
  cancel_button = gtk_dialog_add_button (GTK_DIALOG (dialog), GTK_STOCK_CANCEL,
349
 
                                         GTK_RESPONSE_CANCEL);
350
 
 
351
 
  ok_button = gtk_dialog_add_button (GTK_DIALOG (dialog), GTK_STOCK_OK,
352
 
                                     GTK_RESPONSE_OK);
353
 
 
354
 
  gtk_widget_hide (ok_button);
355
 
 
356
 
  gtk_dialog_set_default_response (GTK_DIALOG (dialog), GTK_RESPONSE_CANCEL);
357
 
  gtk_dialog_set_has_separator (GTK_DIALOG (dialog), FALSE);
358
 
  gtk_window_set_resizable (GTK_WINDOW (dialog), FALSE);
359
 
  gtk_window_set_screen (GTK_WINDOW (dialog), screen);
360
 
 
361
 
  dbox = GTK_DIALOG(dialog)->vbox;
362
 
 
363
 
  vbox = gtk_vbox_new(FALSE, BORDER);
364
 
  gtk_box_pack_start(GTK_BOX(dbox), vbox, TRUE, TRUE, 0);
365
 
  gtk_container_set_border_width (GTK_CONTAINER (vbox), BORDER);
366
 
  gtk_widget_show(vbox);
367
 
 
368
 
#ifdef HAVE_GETPWUID
369
 
  pw = getpwuid (getuid ());
370
 
  if (G_LIKELY(pw && pw->pw_name && *pw->pw_name))
371
 
    {
372
 
      gchar *text = g_strdup_printf (_("<span size='large'><b>Log out %s</b></span>"), pw->pw_name);
373
 
      GtkWidget *logout_label = g_object_new (GTK_TYPE_LABEL,
374
 
                                             "label", text,
375
 
                                             "use-markup", TRUE,
376
 
                                             "justify", GTK_JUSTIFY_CENTER,
377
 
                                             "xalign", 0.5,
378
 
                                             "yalign", 0.5,
379
 
                                             NULL);
380
 
 
381
 
      gtk_widget_show (logout_label);
382
 
      gtk_box_pack_start (GTK_BOX (vbox), logout_label, FALSE, FALSE, 0);
383
 
 
384
 
      g_free (text);
385
 
    }
386
 
#endif
387
 
 
388
 
  hbox = gtk_hbox_new (TRUE, BORDER);
389
 
  gtk_widget_show (hbox);
390
 
  gtk_box_pack_start (GTK_BOX (vbox), hbox, FALSE, FALSE, 0);
391
 
 
392
 
  /* logout */
393
 
  logout_button = gtk_button_new ();
394
 
  gtk_widget_show (logout_button);
395
 
  gtk_box_pack_start (GTK_BOX (hbox), logout_button, TRUE, TRUE, 0);
396
 
 
397
 
  g_signal_connect (logout_button, "clicked",
398
 
                    G_CALLBACK (logout_button_clicked), shutdownType);
399
 
 
400
 
  vbox2 = gtk_vbox_new (FALSE, BORDER);
401
 
  gtk_container_set_border_width (GTK_CONTAINER (vbox2), BORDER);
402
 
  gtk_widget_show (vbox2);
403
 
  gtk_container_add (GTK_CONTAINER (logout_button), vbox2);
404
 
 
405
 
  icon = gtk_icon_theme_load_icon (icon_theme,
406
 
                                   "system-log-out",
407
 
                                   32,
408
 
                                   0,
409
 
                                   NULL);
410
 
  if (!icon)
411
 
    icon = gtk_icon_theme_load_icon (icon_theme,
412
 
                                     "xfsm-logout",
413
 
                                     32,
414
 
                                     GTK_ICON_LOOKUP_GENERIC_FALLBACK,
415
 
                                     NULL);
416
 
 
417
 
  image = gtk_image_new_from_pixbuf (icon);
418
 
  gtk_widget_show (image);
419
 
  gtk_box_pack_start (GTK_BOX (vbox2), image, FALSE, FALSE, 0);
420
 
  g_object_unref (icon);
421
 
 
422
 
  label = gtk_label_new (_("Log Out"));
423
 
  gtk_widget_show (label);
424
 
  gtk_box_pack_start (GTK_BOX (vbox2), label, FALSE, FALSE, 0);
425
 
 
426
 
  /* reboot */
427
 
  reboot_button = gtk_button_new ();
428
 
  gtk_widget_show (reboot_button);
429
 
  gtk_box_pack_start (GTK_BOX (hbox), reboot_button, TRUE, TRUE, 0);
430
 
 
431
 
  g_signal_connect (reboot_button, "clicked",
432
 
                    G_CALLBACK (reboot_button_clicked), shutdownType);
433
 
 
434
 
  vbox2 = gtk_vbox_new (FALSE, BORDER);
435
 
  gtk_container_set_border_width (GTK_CONTAINER (vbox2), BORDER);
436
 
  gtk_widget_show (vbox2);
437
 
  gtk_container_add (GTK_CONTAINER (reboot_button), vbox2);
438
 
 
439
 
  icon = gtk_icon_theme_load_icon (icon_theme,
440
 
                                   "system-reboot",
441
 
                                   32,
442
 
                                   0,
443
 
                                   NULL);
444
 
 
445
 
  if (!icon)
446
 
    icon = gtk_icon_theme_load_icon (icon_theme,
447
 
                                     "xfsm-reboot",
448
 
                                     32,
449
 
                                     GTK_ICON_LOOKUP_GENERIC_FALLBACK,
450
 
                                     NULL);
451
 
 
452
 
  image = gtk_image_new_from_pixbuf (icon);
453
 
  gtk_widget_show (image);
454
 
  gtk_box_pack_start (GTK_BOX (vbox2), image, FALSE, FALSE, 0);
455
 
  g_object_unref (icon);
456
 
 
457
 
  label = gtk_label_new (_("Restart"));
458
 
  gtk_widget_show (label);
459
 
  gtk_box_pack_start (GTK_BOX (vbox2), label, FALSE, FALSE, 0);
460
 
 
461
 
  g_object_get (shutdown_helper,
462
 
                "user-can-restart", &show_restart,
463
 
                NULL);
464
 
 
465
 
  if (!kiosk_can_shutdown || !show_restart )
466
 
    gtk_widget_set_sensitive (reboot_button, FALSE);
467
 
 
468
 
  /* halt */
469
 
  halt_button = gtk_button_new ();
470
 
  gtk_widget_show (halt_button);
471
 
  gtk_box_pack_start (GTK_BOX (hbox), halt_button, TRUE, TRUE, 0);
472
 
 
473
 
  g_signal_connect (halt_button, "clicked",
474
 
                    G_CALLBACK (halt_button_clicked), shutdownType);
475
 
 
476
 
  vbox2 = gtk_vbox_new (FALSE, BORDER);
477
 
  gtk_container_set_border_width (GTK_CONTAINER (vbox2), BORDER);
478
 
  gtk_widget_show (vbox2);
479
 
  gtk_container_add (GTK_CONTAINER (halt_button), vbox2);
480
 
 
481
 
  icon = gtk_icon_theme_load_icon (icon_theme,
482
 
                                   "system-shutdown",
483
 
                                   32,
484
 
                                   0,
485
 
                                   NULL);
486
 
 
487
 
  if (!icon)
488
 
    icon = gtk_icon_theme_load_icon (icon_theme,
489
 
                                     "xfsm-shutdown",
490
 
                                     32,
491
 
                                     GTK_ICON_LOOKUP_GENERIC_FALLBACK,
492
 
                                     NULL);
493
 
 
494
 
  image = gtk_image_new_from_pixbuf (icon);
495
 
  gtk_widget_show (image);
496
 
  gtk_box_pack_start (GTK_BOX (vbox2), image, FALSE, FALSE, 0);
497
 
  g_object_unref (icon);
498
 
 
499
 
  label = gtk_label_new (_("Shut Down"));
500
 
  gtk_widget_show (label);
501
 
  gtk_box_pack_start (GTK_BOX (vbox2), label, FALSE, FALSE, 0);
502
 
 
503
 
  g_object_get (shutdown_helper,
504
 
                "user-can-shutdown", &show_shutdown,
505
 
                NULL);
506
 
 
507
 
  if (!kiosk_can_shutdown || !show_shutdown)
508
 
    gtk_widget_set_sensitive (halt_button, FALSE);
509
 
 
510
 
  if (show_suspend)
511
 
    g_object_get (shutdown_helper,
512
 
                  "user-can-suspend", &show_suspend,
513
 
                  NULL);
514
 
 
515
 
  if (show_hibernate)
516
 
    g_object_get (shutdown_helper,
517
 
                  "user-can-hibernate", &show_hibernate,
518
 
                  NULL);
519
 
 
520
 
 
521
 
  if (kiosk_can_shutdown && (show_suspend || show_hibernate))
522
 
    {
523
 
      hbox = gtk_hbox_new (FALSE, BORDER);
524
 
      gtk_widget_show (hbox);
525
 
      gtk_box_pack_start (GTK_BOX (vbox), hbox, FALSE, FALSE, 0);
526
 
    }
527
 
 
528
 
  /* suspend */
529
 
  if (kiosk_can_shutdown && show_suspend)
530
 
    {
531
 
      suspend_button = gtk_button_new ();
532
 
      gtk_widget_show (suspend_button);
533
 
      gtk_box_pack_start (GTK_BOX (hbox), suspend_button, TRUE, TRUE, 0);
534
 
 
535
 
      g_signal_connect (suspend_button, "clicked",
536
 
                        G_CALLBACK (suspend_button_clicked), shutdownType);
537
 
 
538
 
      vbox2 = gtk_vbox_new (FALSE, BORDER);
539
 
      gtk_container_set_border_width (GTK_CONTAINER (vbox2), BORDER);
540
 
      gtk_widget_show (vbox2);
541
 
      gtk_container_add (GTK_CONTAINER (suspend_button), vbox2);
542
 
 
543
 
      icon = gtk_icon_theme_load_icon (icon_theme,
544
 
                                       "system-suspend",
545
 
                                       32,
546
 
                                       0,
547
 
                                       NULL);
548
 
 
549
 
      if (!icon)
550
 
        icon = gtk_icon_theme_load_icon (icon_theme,
551
 
                                         "xfsm-suspend",
552
 
                                         32,
553
 
                                         GTK_ICON_LOOKUP_GENERIC_FALLBACK,
554
 
                                         NULL);
555
 
 
556
 
      image = gtk_image_new_from_pixbuf (icon);
557
 
      gtk_widget_show (image);
558
 
      gtk_box_pack_start (GTK_BOX (vbox2), image, FALSE, FALSE, 0);
559
 
      g_object_unref (icon);
560
 
 
561
 
      label = gtk_label_new (_("Suspend"));
562
 
      gtk_widget_show (label);
563
 
      gtk_box_pack_start (GTK_BOX (vbox2), label, FALSE, FALSE, 0);
564
 
    }
565
 
 
566
 
  /* hibernate */
567
 
  if (kiosk_can_shutdown && show_hibernate)
568
 
    {
569
 
      hibernate_button = gtk_button_new ();
570
 
      gtk_widget_show (hibernate_button);
571
 
      gtk_box_pack_start (GTK_BOX (hbox), hibernate_button, TRUE, TRUE, 0);
572
 
 
573
 
      g_signal_connect (hibernate_button, "clicked",
574
 
                        G_CALLBACK (hibernate_button_clicked), shutdownType);
575
 
 
576
 
      vbox2 = gtk_vbox_new (FALSE, BORDER);
577
 
      gtk_container_set_border_width (GTK_CONTAINER (vbox2), BORDER);
578
 
      gtk_widget_show (vbox2);
579
 
      gtk_container_add (GTK_CONTAINER (hibernate_button), vbox2);
580
 
 
581
 
      icon = gtk_icon_theme_load_icon (icon_theme,
582
 
                                       "system-hibernate",
583
 
                                       32,
584
 
                                       0,
585
 
                                       NULL);
586
 
 
587
 
      if (!icon)
588
 
        icon = gtk_icon_theme_load_icon (icon_theme,
589
 
                                         "xfsm-hibernate",
590
 
                                         32,
591
 
                                         GTK_ICON_LOOKUP_GENERIC_FALLBACK,
592
 
                                         NULL);
593
 
 
594
 
      image = gtk_image_new_from_pixbuf (icon);
595
 
      gtk_widget_show (image);
596
 
      gtk_box_pack_start (GTK_BOX (vbox2), image, FALSE, FALSE, 0);
597
 
      g_object_unref (icon);
598
 
 
599
 
      label = gtk_label_new (_("Hibernate"));
600
 
      gtk_widget_show (label);
601
 
      gtk_box_pack_start (GTK_BOX (vbox2), label, FALSE, FALSE, 0);
602
 
  }
603
 
 
604
 
  /* save session */
605
 
  if (!autosave && kiosk_can_save_session)
606
 
    {
607
 
      checkbox = gtk_check_button_new_with_mnemonic(
608
 
          _("_Save session for future logins"));
609
 
      gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(checkbox), saveonexit);
610
 
      gtk_box_pack_start(GTK_BOX(vbox), checkbox, FALSE, TRUE, BORDER);
611
 
      gtk_widget_show(checkbox);
612
 
    }
613
 
  else
614
 
    {
615
 
      checkbox = NULL;
616
 
    }
617
 
 
618
 
  /* create small border */
619
 
  if (!accessibility)
620
 
    xfsm_window_add_border (GTK_WINDOW (dialog));
621
 
 
622
 
  /* center dialog on target monitor */
623
 
  gtk_window_set_screen (GTK_WINDOW (dialog), screen);
624
 
  gtk_window_set_position (GTK_WINDOW (dialog), GTK_WIN_POS_CENTER);
625
 
 
626
 
  /* save portion of the root window covered by the dialog */
627
 
  if (!accessibility && shutdown_helper != NULL)
628
 
    {
629
 
      gtk_widget_realize (dialog);
630
 
      gdk_window_set_override_redirect (dialog->window, TRUE);
631
 
      gdk_window_raise (dialog->window);
632
 
    }
633
 
 
634
 
  /* need to realize the dialog first! */
635
 
  gtk_widget_show_now (dialog);
636
 
  gtk_widget_grab_focus (logout_button);
637
 
 
638
 
  /* Grab Keyboard and Mouse pointer */
639
 
  if (!accessibility)
640
 
    xfsm_window_grab_input (GTK_WINDOW (dialog));
641
 
 
642
 
  /* run the logout dialog */
643
 
  result = gtk_dialog_run (GTK_DIALOG(dialog));
644
 
 
645
 
  if (result == GTK_RESPONSE_OK) {
646
 
    *saveSession = autosave ? autosave :
647
 
            gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(checkbox));
648
 
  }
649
 
 
650
 
  gtk_widget_hide (dialog);
651
 
 
652
 
  g_object_get (shutdown_helper,
653
 
                "require-password", &require_password,
654
 
                NULL);
655
 
 
656
 
  /* ask password */
657
 
  if (result == GTK_RESPONSE_OK && *shutdownType != XFSM_SHUTDOWN_LOGOUT
658
 
      && require_password )
659
 
    {
660
 
      gtk_widget_show (ok_button);
661
 
 
662
 
      gtk_widget_destroy (vbox);
663
 
 
664
 
      entry_vbox = gtk_vbox_new (FALSE, BORDER);
665
 
      gtk_box_pack_start (GTK_BOX (dbox), entry_vbox, TRUE, TRUE, BORDER);
666
 
      gtk_widget_show (entry_vbox);
667
 
 
668
 
      label = gtk_label_new (_("Please enter your password:"));
669
 
      gtk_misc_set_alignment (GTK_MISC (label), 0, 0.5);
670
 
      gtk_widget_show (label);
671
 
      gtk_box_pack_start (GTK_BOX (entry_vbox), label, FALSE, FALSE, 0);
672
 
 
673
 
      entry = gtk_entry_new ();
674
 
      gtk_entry_set_visibility(GTK_ENTRY(entry), FALSE);
675
 
      gtk_box_pack_start (GTK_BOX (entry_vbox), entry, TRUE, TRUE, 0);
676
 
      g_signal_connect (G_OBJECT (entry), "activate",
677
 
                        G_CALLBACK (entry_activate_cb), dialog);
678
 
      gtk_widget_show (entry);
679
 
 
680
 
      /* center dialog on target monitor */
681
 
      gtk_window_set_screen (GTK_WINDOW (dialog), screen);
682
 
      gtk_window_set_position (GTK_WINDOW (dialog), GTK_WIN_POS_CENTER);
683
 
 
684
 
      gtk_widget_show_now (dialog);
685
 
      gtk_widget_grab_focus (entry);
686
 
 
687
 
      /* Grab Keyboard and Mouse pointer */
688
 
      if (!accessibility)
689
 
        xfsm_window_grab_input (GTK_WINDOW (dialog));
690
 
 
691
 
      result = gtk_dialog_run (GTK_DIALOG (dialog));
692
 
 
693
 
      if (result == GTK_RESPONSE_OK)
694
 
        {
695
 
          const gchar *password = gtk_entry_get_text (GTK_ENTRY (entry));
696
 
 
697
 
          if (!xfsm_shutdown_helper_send_password (shutdown_helper, password))
698
 
            {
699
 
              gtk_label_set_text (GTK_LABEL (label),
700
 
                                  _("<b>An error occurred</b>"));
701
 
              gtk_label_set_use_markup (GTK_LABEL (label), TRUE);
702
 
 
703
 
              gtk_container_remove (GTK_CONTAINER (
704
 
                    GTK_DIALOG (dialog)->action_area), cancel_button);
705
 
              gtk_container_remove (GTK_CONTAINER (
706
 
                    GTK_DIALOG (dialog)->action_area), ok_button);
707
 
 
708
 
              gtk_container_remove (GTK_CONTAINER (entry_vbox), entry);
709
 
 
710
 
              gtk_dialog_add_button (GTK_DIALOG (dialog),
711
 
                                     GTK_STOCK_CLOSE,
712
 
                                     GTK_RESPONSE_CANCEL);
713
 
 
714
 
              label = gtk_label_new (_("Either the password you entered is "
715
 
                                       "invalid, or the system administrator "
716
 
                                       "disallows shutting down this computer "
717
 
                                       "with your user account."));
718
 
              gtk_label_set_line_wrap (GTK_LABEL (label), TRUE);
719
 
              gtk_box_pack_start (GTK_BOX (entry_vbox), label, TRUE, TRUE, 0);
720
 
              gtk_widget_show (label);
721
 
 
722
 
              /* center dialog on target monitor */
723
 
              gtk_window_set_screen (GTK_WINDOW (dialog), screen);
724
 
              gtk_window_set_position (GTK_WINDOW (dialog), GTK_WIN_POS_CENTER);
725
 
 
726
 
              gtk_widget_show_now (dialog);
727
 
 
728
 
              /* Grab Keyboard and Mouse pointer */
729
 
              if (!accessibility)
730
 
                xfsm_window_grab_input (GTK_WINDOW (dialog));
731
 
 
732
 
              gtk_dialog_run (GTK_DIALOG (dialog));
733
 
 
734
 
              result = GTK_RESPONSE_CANCEL;
735
 
            }
736
 
        }
737
 
    }
738
 
 
739
 
  gtk_widget_destroy(dialog);
740
 
  gtk_widget_destroy(hidden);
741
 
 
742
 
  shutdown_dialog = NULL;
743
 
 
744
 
  /* Release Keyboard/Mouse pointer grab */
745
 
  if (!accessibility)
746
 
    {
747
 
      xfsm_fadeout_destroy (fadeout);
748
 
 
749
 
      gdk_pointer_ungrab (GDK_CURRENT_TIME);
750
 
      gdk_keyboard_ungrab (GDK_CURRENT_TIME);
751
 
      gdk_flush ();
752
 
    }
753
 
 
754
 
  /* process all pending events first */
755
 
  while (gtk_events_pending ())
756
 
    g_main_context_iteration (NULL, FALSE);
757
 
 
758
 
  /*
759
 
   * remember the current settings.
760
 
   */
761
 
  if (result == GTK_RESPONSE_OK)
762
 
    {
763
 
      xfconf_channel_set_string (channel, "/general/SessionName", sessionName);
764
 
      xfconf_channel_set_bool (channel, "/general/SaveOnExit", *saveSession);
765
 
    }
766
 
  else
767
 
    {
768
 
      g_object_unref (shutdown_helper);
769
 
      shutdown_helper = NULL;
770
 
    }
771
 
 
772
 
#ifdef SESSION_SCREENSHOTS
773
 
  if (screenshot_pm != NULL)
774
 
    {
775
 
      if (result == GTK_RESPONSE_OK)
776
 
        screenshot_save (sessionName, screenshot_pm, &screenshot_area);
777
 
 
778
 
      g_object_unref (G_OBJECT (screenshot_pm));
779
 
    }
780
 
#endif
781
 
 
782
 
  return (result == GTK_RESPONSE_OK);
783
 
}
784
 
 
785
 
 
786
 
/*
787
 
 */
788
 
gint
789
 
xfsm_shutdown(XfsmShutdownType type)
790
 
{
791
 
  gboolean result;
792
 
  GError *error = NULL;
793
 
 
794
 
  /* kludge */
795
 
  if (type == XFSM_SHUTDOWN_ASK)
796
 
    {
797
 
      g_warning ("xfsm_shutdown () passed XFSM_SHUTDOWN_ASK.  This is a bug.");
798
 
      type = XFSM_SHUTDOWN_LOGOUT;
799
 
    }
800
 
 
801
 
  /* these two remember if they were started or not */
802
 
  xfsm_compat_gnome_shutdown ();
803
 
  xfsm_compat_kde_shutdown ();
804
 
 
805
 
  /* kill legacy clients */
806
 
  xfsm_legacy_shutdown ();
807
 
 
808
 
#if !defined(__NR_ioprio_set) && defined(HAVE_SYNC)
809
 
  /* sync disk block in-core status with that on disk.  if
810
 
   * we have ioprio_set (), then we've already synced. */
811
 
  if (fork () == 0)
812
 
    {
813
 
# ifdef HAVE_SETSID
814
 
      setsid ();
815
 
# endif
816
 
      sync ();
817
 
      _exit (EXIT_SUCCESS);
818
 
    }
819
 
#endif  /* HAVE_SYNC */
820
 
 
821
 
  if (type == XFSM_SHUTDOWN_LOGOUT)
822
 
    return EXIT_SUCCESS;
823
 
 
824
 
  if (shutdown_helper == NULL)
825
 
    shutdown_helper = xfsm_shutdown_helper_new ();
826
 
 
827
 
  result = xfsm_shutdown_helper_send_command (shutdown_helper, type, &error);
828
 
  g_object_unref (shutdown_helper);
829
 
  shutdown_helper = NULL;
830
 
 
831
 
  if (!result)
832
 
    {
833
 
      xfce_message_dialog (NULL, _("Shutdown Failed"),
834
 
                           GTK_STOCK_DIALOG_ERROR,
835
 
                           _("Unable to perform shutdown"),
836
 
                           error->message,
837
 
                           GTK_STOCK_QUIT, GTK_RESPONSE_ACCEPT,
838
 
                           NULL);
839
 
      g_error_free (error);
840
 
      return EXIT_FAILURE;
841
 
    }
842
 
 
843
 
  return EXIT_SUCCESS;
844
 
}
845