216
240
gsm_logout_dialog_show (GsmLogoutDialog *logout_dialog, gpointer user_data)
218
gsm_logout_set_info_text (logout_dialog, AUTOMATIC_ACTION_TIMEOUT);
220
if (logout_dialog->priv->default_response != GTK_RESPONSE_CANCEL)
221
gsm_logout_dialog_set_timeout (logout_dialog,
222
AUTOMATIC_ACTION_TIMEOUT);
242
gsm_logout_dialog_set_timeout (logout_dialog);
227
gsm_logout_set_info_text (GsmLogoutDialog *logout_dialog,
246
gsm_logout_dialog_timeout (gpointer data)
230
const char *seconds_warning;
231
char *secondary_text;
234
static char *session_type = NULL;
236
switch (logout_dialog->priv->default_response) {
237
case GSM_LOGOUT_RESPONSE_LOGOUT:
248
GsmLogoutDialog *logout_dialog;
249
char *seconds_warning;
250
char *secondary_text;
252
static char *session_type = NULL;
254
logout_dialog = (GsmLogoutDialog *) data;
256
if (!logout_dialog->priv->timeout) {
257
gtk_dialog_response (GTK_DIALOG (logout_dialog),
258
logout_dialog->priv->default_response);
263
if (logout_dialog->priv->timeout <= 30) {
264
seconds_to_show = logout_dialog->priv->timeout;
266
seconds_to_show = (logout_dialog->priv->timeout/10) * 10;
268
if (logout_dialog->priv->timeout % 10)
269
seconds_to_show += 10;
272
switch (logout_dialog->priv->type) {
273
case GSM_DIALOG_LOGOUT_TYPE_LOGOUT:
238
274
/* This string is shared with gsm-fail-whale-dialog.c */
239
275
seconds_warning = ngettext ("You will be automatically logged "
240
276
"out in %d second.",
289
321
secondary_text = g_strdup (seconds_warning);
292
buf = g_strdup_printf (secondary_text, seconds_to_show);
293
markup = g_markup_printf_escaped ("<i>%s</i>", buf);
295
gtk_label_set_markup (GTK_LABEL (logout_dialog->priv->info_label),
301
gsm_logout_dialog_timeout (gpointer data)
303
GsmLogoutDialog *logout_dialog;
306
logout_dialog = (GsmLogoutDialog *) data;
308
if (!logout_dialog->priv->timeout) {
309
gtk_dialog_response (GTK_DIALOG (logout_dialog),
310
logout_dialog->priv->default_response);
315
if (logout_dialog->priv->timeout <= 30) {
316
seconds_to_show = logout_dialog->priv->timeout;
318
seconds_to_show = (logout_dialog->priv->timeout/10) * 10;
320
if (logout_dialog->priv->timeout % 10)
321
seconds_to_show += 10;
324
gsm_logout_set_info_text (logout_dialog, seconds_to_show);
324
gtk_message_dialog_format_secondary_text (GTK_MESSAGE_DIALOG (logout_dialog),
326
329
logout_dialog->priv->timeout--;
331
g_free (secondary_text);
332
gsm_logout_dialog_set_timeout (GsmLogoutDialog *logout_dialog,
337
gsm_logout_dialog_set_timeout (GsmLogoutDialog *logout_dialog)
335
logout_dialog->priv->timeout = seconds;
339
logout_dialog->priv->timeout = AUTOMATIC_ACTION_TIMEOUT;
341
/* Sets the secondary text */
342
gsm_logout_dialog_timeout (logout_dialog);
337
344
if (logout_dialog->priv->timeout_id != 0) {
338
345
g_source_remove (logout_dialog->priv->timeout_id);
346
353
static GtkWidget *
347
gsm_logout_tile_new (const char *icon_name,
349
const char *description)
352
GtkWidget *alignment;
359
g_assert (title != NULL);
361
button = GTK_WIDGET (gtk_button_new ());
362
gtk_button_set_relief (GTK_BUTTON (button), GTK_RELIEF_NONE);
364
alignment = gtk_alignment_new (0, 0.5, 0, 0);
365
gtk_alignment_set_padding (GTK_ALIGNMENT (alignment), 0, 0, 6, 6);
366
gtk_container_add (GTK_CONTAINER (button), alignment);
368
hbox = gtk_hbox_new (FALSE, 12);
369
gtk_container_add (GTK_CONTAINER (alignment), hbox);
370
if (icon_name != NULL) {
371
image = gtk_image_new_from_icon_name (icon_name,
372
GTK_ICON_SIZE_DIALOG);
373
gtk_box_pack_start (GTK_BOX (hbox), image, FALSE, FALSE, 0);
376
vbox = gtk_vbox_new (FALSE, 2);
378
markup = g_markup_printf_escaped ("<span weight=\"bold\">%s</span>",
380
label = gtk_label_new (markup);
383
gtk_label_set_use_markup (GTK_LABEL (label), TRUE);
384
gtk_misc_set_alignment (GTK_MISC (label), 0.0, 0.5);
385
gtk_label_set_use_underline (GTK_LABEL (label), TRUE);
387
gtk_box_pack_start (GTK_BOX (vbox), label, FALSE, FALSE, 0);
389
if (description != NULL) {
395
style = gtk_widget_get_style (GTK_WIDGET (button));
396
color = &style->fg[GTK_STATE_INSENSITIVE];
397
markup = g_markup_printf_escaped ("<span size=\"small\" foreground=\"#%.2x%.2x%.2x\">%s</span>",
402
label = gtk_label_new (markup);
405
gtk_label_set_use_markup (GTK_LABEL (label), TRUE);
406
gtk_misc_set_alignment (GTK_MISC (label), 0.0, 0.5);
407
gtk_label_set_use_underline (GTK_LABEL (label), TRUE);
408
gtk_label_set_line_wrap (GTK_LABEL (label), TRUE);
410
gtk_box_pack_start (GTK_BOX (vbox), label, FALSE, FALSE, 0);
413
gtk_box_pack_start (GTK_BOX (hbox), vbox, FALSE, FALSE, 0);
419
gsm_logout_tile_clicked (GtkWidget *tile,
424
dialog = gtk_widget_get_toplevel (tile);
425
g_assert (GTK_IS_DIALOG (dialog));
426
gtk_dialog_response (GTK_DIALOG (dialog),
427
GPOINTER_TO_UINT (response_p));
431
gsm_logout_append_tile (GtkWidget *vbox,
432
unsigned int response,
433
const char *icon_name,
435
const char *description)
439
tile = gsm_logout_tile_new (icon_name, title, description);
440
gtk_box_pack_start (GTK_BOX (vbox), tile, TRUE, TRUE, 0);
441
gtk_widget_show_all (tile);
443
g_signal_connect (tile,
445
G_CALLBACK (gsm_logout_tile_clicked),
446
GUINT_TO_POINTER (response));
452
354
gsm_get_dialog (GsmDialogLogoutType type,
453
355
GdkScreen *screen,
454
356
guint32 activate_time)
456
358
GsmLogoutDialog *logout_dialog;
359
GtkWidget *dialog_image;
360
const char *primary_text;
459
361
const char *icon_name;
462
363
if (current_dialog != NULL) {
463
364
gtk_widget_destroy (GTK_WIDGET (current_dialog));
468
369
current_dialog = logout_dialog;
470
vbox = gtk_vbox_new (FALSE, 12);
471
gtk_box_pack_start (GTK_BOX (gtk_dialog_get_content_area (GTK_DIALOG (logout_dialog))), vbox,
473
gtk_container_set_border_width (GTK_CONTAINER (vbox), 6);
474
gtk_widget_show (vbox);
371
gtk_window_set_title (GTK_WINDOW (logout_dialog), "");
373
logout_dialog->priv->type = type;
476
375
icon_name = NULL;
480
379
case GSM_DIALOG_LOGOUT_TYPE_LOGOUT:
481
380
icon_name = GSM_ICON_LOGOUT;
482
title = _("Log Out of the Session");
381
primary_text = _("Log out of this system now?");
484
383
logout_dialog->priv->default_response = GSM_LOGOUT_RESPONSE_LOGOUT;
487
gsm_logout_append_tile (vbox, GSM_LOGOUT_RESPONSE_LOGOUT,
488
GSM_ICON_LOGOUT, _("_Log Out"),
489
_("Ends your session and logs you "
492
tile = gsm_logout_append_tile (vbox,
493
GSM_LOGOUT_RESPONSE_SWITCH_USER,
385
if (gsm_logout_supports_switch_user (logout_dialog)) {
386
gtk_dialog_add_button (GTK_DIALOG (logout_dialog),
495
387
_("_Switch User"),
496
_("Suspends your session, "
497
"allowing another user to "
498
"log in and use the "
500
if (!gsm_logout_supports_switch_user (logout_dialog)) {
501
gtk_widget_set_sensitive (tile, FALSE);
388
GSM_LOGOUT_RESPONSE_SWITCH_USER);
391
gtk_dialog_add_button (GTK_DIALOG (logout_dialog),
393
GTK_RESPONSE_CANCEL);
395
gtk_dialog_add_button (GTK_DIALOG (logout_dialog),
397
GSM_LOGOUT_RESPONSE_LOGOUT);
505
400
case GSM_DIALOG_LOGOUT_TYPE_SHUTDOWN:
506
401
icon_name = GSM_ICON_SHUTDOWN;
507
title = _("Shut Down the Computer");
402
primary_text = _("Shut down this system now?");
509
404
logout_dialog->priv->default_response = GSM_LOGOUT_RESPONSE_SHUTDOWN;
511
tile = gsm_logout_append_tile (vbox,
512
GSM_LOGOUT_RESPONSE_SHUTDOWN,
515
_("Ends your session and turns "
516
"off the computer."));
517
if (!gsm_logout_supports_shutdown (logout_dialog)) {
518
gtk_widget_set_sensitive (tile, FALSE);
519
/* If shutdown is not available, let's just fallback
520
* on cancel as the default action. We could fallback
521
* on reboot first, then suspend and then hibernate
522
* but it's not that useful, really */
523
logout_dialog->priv->default_response = GTK_RESPONSE_CANCEL;
526
tile = gsm_logout_append_tile (vbox,
527
GSM_LOGOUT_RESPONSE_REBOOT,
528
GSM_ICON_REBOOT, _("_Restart"),
529
_("Ends your session and "
530
"restarts the computer."));
531
if (!gsm_logout_supports_reboot (logout_dialog)) {
532
gtk_widget_set_sensitive (tile, FALSE);
535
/* We don't set those options insensitive if they are no
536
* supported (like we do for shutdown/restart) since some
537
* hardware just don't support suspend/hibernate. So we
538
* don't show those options in this case. */
539
406
if (gsm_logout_supports_system_suspend (logout_dialog)) {
540
gsm_logout_append_tile (vbox,
541
GSM_LOGOUT_RESPONSE_SLEEP,
542
GSM_ICON_SLEEP, _("S_uspend"),
543
_("Suspends your session "
544
"quickly, using minimal "
545
"power while the computer "
407
gtk_dialog_add_button (GTK_DIALOG (logout_dialog),
409
GSM_LOGOUT_RESPONSE_SLEEP);
549
412
if (gsm_logout_supports_system_hibernate (logout_dialog)) {
550
gsm_logout_append_tile (vbox,
551
GSM_LOGOUT_RESPONSE_HIBERNATE,
554
_("Suspends your session, "
555
"using no power until the "
556
"computer is restarted."));
413
gtk_dialog_add_button (GTK_DIALOG (logout_dialog),
415
GSM_LOGOUT_RESPONSE_HIBERNATE);
418
if (gsm_logout_supports_reboot (logout_dialog)) {
419
gtk_dialog_add_button (GTK_DIALOG (logout_dialog),
421
GSM_LOGOUT_RESPONSE_REBOOT);
424
gtk_dialog_add_button (GTK_DIALOG (logout_dialog),
426
GTK_RESPONSE_CANCEL);
428
if (gsm_logout_supports_shutdown (logout_dialog)) {
429
gtk_dialog_add_button (GTK_DIALOG (logout_dialog),
431
GSM_LOGOUT_RESPONSE_SHUTDOWN);
561
435
g_assert_not_reached ();
564
logout_dialog->priv->info_label = gtk_label_new ("");
565
gtk_label_set_line_wrap (GTK_LABEL (logout_dialog->priv->info_label),
567
gtk_box_pack_start (GTK_BOX (vbox), logout_dialog->priv->info_label,
569
gtk_widget_show (logout_dialog->priv->info_label);
438
dialog_image = gtk_message_dialog_get_image (GTK_MESSAGE_DIALOG (logout_dialog));
440
gtk_image_set_from_icon_name (GTK_IMAGE (dialog_image),
441
icon_name, GTK_ICON_SIZE_DIALOG);
571
442
gtk_window_set_icon_name (GTK_WINDOW (logout_dialog), icon_name);
572
gtk_window_set_title (GTK_WINDOW (logout_dialog), title);
573
gtk_window_set_position (GTK_WINDOW (logout_dialog),
574
GTK_WIN_POS_CENTER_ALWAYS);
443
gtk_window_set_position (GTK_WINDOW (logout_dialog), GTK_WIN_POS_CENTER_ALWAYS);
444
gtk_message_dialog_set_markup (GTK_MESSAGE_DIALOG (logout_dialog), primary_text);
576
446
gtk_dialog_set_default_response (GTK_DIALOG (logout_dialog),
577
447
logout_dialog->priv->default_response);
578
/* Note that focus is on the widget for the default response by default
579
* (since they're the first widget, except when it's Cancel */
580
if (logout_dialog->priv->default_response == GTK_RESPONSE_CANCEL)
581
gtk_window_set_focus (GTK_WINDOW (logout_dialog),
582
logout_dialog->priv->cancel_button);
584
449
gtk_window_set_screen (GTK_WINDOW (logout_dialog), screen);