94
static prompt_status_t
95
get_prompt_status (IndicatorSessionActionsDbus * self)
97
prompt_status_t prompt = PROMPT_NONE;
98
const priv_t * p = self->priv;
100
if (!g_settings_get_boolean (p->indicator_settings, "suppress-logout-restart-shutdown"))
102
/* can we use the Unity prompt? */
103
if ((prompt == PROMPT_NONE) && p && p->end_session_dialog)
105
GDBusProxy * proxy = G_DBUS_PROXY (p->end_session_dialog);
106
char * name = g_dbus_proxy_get_name_owner (proxy);
108
prompt = PROMPT_WITH_UNITY;
112
/* can we use zenity? */
113
if ((prompt == PROMPT_NONE) && p && p->zenity)
114
prompt = PROMPT_WITH_ZENITY;
125
84
on_seat_notify_multi_session (IndicatorSessionActionsDbus * self)
312
271
g_signal_connect_swapped (webcredentials, "notify::error-status",
313
272
G_CALLBACK(indicator_session_actions_notify_has_online_account_error), gself);
315
if (webcredentials_get_error_status (webcredentials))
316
indicator_session_actions_notify_has_online_account_error (gself);
319
275
log_and_clear_error (&err, G_STRLOC, G_STRFUNC);
356
311
priv_t * p = INDICATOR_SESSION_ACTIONS_DBUS(self)->priv;
358
if (g_settings_get_boolean (p->indicator_settings, "suppress-logout-menuitem"))
361
if (g_settings_get_boolean (p->lockdown_settings, "disable-log-out"))
368
my_can_reboot (IndicatorSessionActions * actions)
370
IndicatorSessionActionsDbus * self = INDICATOR_SESSION_ACTIONS_DBUS(actions);
371
priv_t * p = self->priv;
373
if (g_settings_get_boolean (p->indicator_settings, "suppress-restart-menuitem"))
376
/* Shutdown and Restart are the same dialog prompt in Unity,
377
so disable the redundant 'Restart' menuitem in that mode */
378
if (!g_settings_get_boolean (p->indicator_settings, "suppress-shutdown-menuitem"))
379
if (get_prompt_status(self) == PROMPT_WITH_UNITY)
313
return !g_settings_get_boolean (p->lockdown_settings, "disable-log-out");
411
342
my_can_prompt (IndicatorSessionActions * self)
413
return get_prompt_status(INDICATOR_SESSION_ACTIONS_DBUS(self)) != PROMPT_NONE;
344
gboolean can_prompt = FALSE;
345
const priv_t * p = INDICATOR_SESSION_ACTIONS_DBUS(self)->priv;
347
if (p && p->end_session_dialog)
349
GDBusProxy * proxy = G_DBUS_PROXY (p->end_session_dialog);
350
char * name = g_dbus_proxy_get_name_owner (proxy);
351
can_prompt = name != NULL;
457
logout_now (IndicatorSessionActionsDbus * self)
399
logout_now (IndicatorSessionActions * self, gboolean try_to_prompt)
459
priv_t * p = self->priv;
401
priv_t * p = INDICATOR_SESSION_ACTIONS_DBUS(self)->priv;
402
const int type = try_to_prompt ? 0 : 1;
461
404
g_return_if_fail (p->session_manager != NULL);
463
406
gnome_session_manager_call_logout (p->session_manager,
464
1, /* don't prompt */
471
on_reboot_response (GObject * o,
473
gpointer unused G_GNUC_UNUSED)
476
login1_manager_call_reboot_finish (LOGIN1_MANAGER(o), res, &err);
479
g_warning ("Unable to reboot: %s", err->message);
485
reboot_now (IndicatorSessionActionsDbus * self)
487
priv_t * p = self->priv;
414
logout_now_with_prompt (IndicatorSessionActions * self)
416
logout_now (self, TRUE);
420
logout_now_quietly (IndicatorSessionActions * self)
422
logout_now (self, FALSE);
426
reboot_now (IndicatorSessionActions * self)
428
priv_t * p = INDICATOR_SESSION_ACTIONS_DBUS(self)->priv;
489
430
g_return_if_fail (p->login1_manager != NULL);
491
432
login1_manager_call_reboot (p->login1_manager,
493
434
p->login1_manager_cancellable,
499
power_off_now (IndicatorSessionActionsDbus * self)
440
power_off_now (IndicatorSessionActions * self)
501
priv_t * p = self->priv;
442
priv_t * p = INDICATOR_SESSION_ACTIONS_DBUS(self)->priv;
503
444
g_return_if_fail (p->login1_manager != NULL);
545
486
g_assert (o != NULL);
547
g_signal_connect_swapped (o, "confirmed-logout", G_CALLBACK(logout_now), self);
488
g_signal_connect_swapped (o, "confirmed-logout", G_CALLBACK(logout_now_quietly), self);
548
489
g_signal_connect_swapped (o, "confirmed-reboot", G_CALLBACK(reboot_now), self);
549
490
g_signal_connect_swapped (o, "confirmed-shutdown", G_CALLBACK(power_off_now), self);
550
491
g_signal_connect_swapped (o, "canceled", G_CALLBACK(on_end_session_dialog_canceled), self);
560
zenity_question (IndicatorSessionActionsDbus * self,
561
const char * icon_name,
564
const char * ok_label,
565
const char * cancel_label)
571
command_line = g_strdup_printf ("%s"
573
" --icon-name=\"%s\""
577
" --cancel-label=\"%s\""
587
if (!g_spawn_command_line_sync (command_line, NULL, NULL, &exit_status, NULL))
589
/* Treat failure-to-prompt as user confirmation.
590
Otherwise how will the user ever log out? */
595
confirmed = exit_status == 0;
598
g_free (command_line);
603
my_logout (IndicatorSessionActions * actions)
605
IndicatorSessionActionsDbus * self = INDICATOR_SESSION_ACTIONS_DBUS (actions);
607
switch (get_prompt_status (self))
609
case PROMPT_WITH_UNITY:
610
show_unity_end_session_dialog (self, END_SESSION_TYPE_LOGOUT);
617
case PROMPT_WITH_ZENITY:
619
const char * primary = _("Are you sure you want to close all programs and log out?");
620
const char * secondary = _("Some software updates won't be applied until the computer next restarts.");
621
char * text = g_strdup_printf ("<big><b>%s</b></big>\n \n%s", primary, secondary);
623
gboolean confirmed = zenity_question (self,
640
my_reboot (IndicatorSessionActions * actions)
642
IndicatorSessionActionsDbus * self = INDICATOR_SESSION_ACTIONS_DBUS (actions);
644
switch (get_prompt_status (self))
646
case PROMPT_WITH_UNITY:
647
show_unity_end_session_dialog (self, END_SESSION_TYPE_REBOOT);
654
case PROMPT_WITH_ZENITY:
655
if (zenity_question (self,
658
_("Are you sure you want to close all programs and restart the computer?"),
667
my_power_off (IndicatorSessionActions * actions)
669
IndicatorSessionActionsDbus * self = INDICATOR_SESSION_ACTIONS_DBUS (actions);
671
switch (get_prompt_status (self))
673
case PROMPT_WITH_UNITY:
674
/* NB: TYPE_REBOOT instead of TYPE_SHUTDOWN because
675
the latter adds lock & logout options in Unity... */
676
show_unity_end_session_dialog (self, END_SESSION_TYPE_REBOOT);
679
case PROMPT_WITH_ZENITY:
680
if (zenity_question (self,
683
_("Are you sure you want to close all programs and shut down the computer?"),
686
power_off_now (self);
690
power_off_now (self);
501
my_logout (IndicatorSessionActions * self)
503
if (my_can_prompt (self))
504
show_end_session_dialog (INDICATOR_SESSION_ACTIONS_DBUS(self), END_SESSION_TYPE_LOGOUT);
506
logout_now_with_prompt (self);
511
my_reboot (IndicatorSessionActions * self)
513
if (my_can_prompt (self))
514
show_end_session_dialog (INDICATOR_SESSION_ACTIONS_DBUS(self), END_SESSION_TYPE_REBOOT);
520
my_power_off (IndicatorSessionActions * self)
522
/* NB: TYPE_REBOOT instead of TYPE_SHUTDOWN because
523
the latter adds lock & logout options in Unity... */
524
if (my_can_prompt (self))
525
show_end_session_dialog (INDICATOR_SESSION_ACTIONS_DBUS(self), END_SESSION_TYPE_REBOOT);
527
power_off_now (self);
711
546
run_outside_app ("yelp");
715
have_unity_control_center (void)
720
if (g_strcmp0 (g_getenv ("XDG_CURRENT_DESKTOP"), "Unity") != 0)
723
path = g_find_program_in_path ("unity-control-center");
724
have_ucc = path != NULL;
731
550
my_settings (IndicatorSessionActions * self G_GNUC_UNUSED)
733
if (have_unity_control_center ())
734
run_outside_app ("unity-control-center");
736
run_outside_app ("gnome-control-center");
740
my_online_accounts (IndicatorSessionActions * self G_GNUC_UNUSED)
742
if (have_unity_control_center ())
743
run_outside_app ("unity-control-center credentials");
745
run_outside_app ("gnome-control-center credentials");
552
run_outside_app ("gnome-control-center");
749
556
my_about (IndicatorSessionActions * self G_GNUC_UNUSED)
751
if (have_unity_control_center ())
752
run_outside_app ("unity-control-center info");
754
run_outside_app ("gnome-control-center info");
558
run_outside_app ("gnome-control-center info");
824
620
g_clear_object (&p->cancellable);
827
if (p->indicator_settings != NULL)
829
g_signal_handlers_disconnect_by_data (p->indicator_settings, self);
830
g_clear_object (&p->indicator_settings);
833
if (p->lockdown_settings != NULL)
835
g_signal_handlers_disconnect_by_data (p->lockdown_settings, self);
836
g_clear_object (&p->lockdown_settings);
839
if (p->webcredentials != NULL)
841
g_signal_handlers_disconnect_by_data (p->webcredentials, self);
842
g_clear_object (&p->webcredentials);
845
if (p->end_session_dialog != NULL)
847
stop_listening_to_dialog (self);
848
g_clear_object (&p->end_session_dialog);
623
g_clear_object (&p->lockdown_settings);
851
624
g_clear_object (&p->screen_saver);
852
625
g_clear_object (&p->session_manager);
626
g_clear_object (&p->webcredentials);
627
g_clear_object (&p->end_session_dialog);
853
628
set_dm_seat (self, NULL);
854
629
set_login1_manager (self, NULL);
855
630
set_login1_seat (self, NULL);
881
646
object_class = G_OBJECT_CLASS (klass);
882
647
object_class->dispose = my_dispose;
883
object_class->finalize = my_finalize;
885
649
actions_class = INDICATOR_SESSION_ACTIONS_CLASS (klass);
886
650
actions_class->can_lock = my_can_lock;
887
651
actions_class->can_logout = my_can_logout;
888
actions_class->can_reboot = my_can_reboot;
889
652
actions_class->can_switch = my_can_switch;
890
653
actions_class->can_suspend = my_can_suspend;
891
654
actions_class->can_hibernate = my_can_hibernate;
897
660
actions_class->reboot = my_reboot;
898
661
actions_class->power_off = my_power_off;
899
662
actions_class->settings = my_settings;
900
actions_class->online_accounts = my_online_accounts;
901
663
actions_class->help = my_help;
902
664
actions_class->about = my_about;
903
665
actions_class->switch_to_screensaver = my_switch_to_screensaver;
933
693
G_CALLBACK(indicator_session_actions_notify_can_switch), self);
934
694
p->lockdown_settings = s;
936
s = g_settings_new ("com.canonical.indicator.session");
937
g_signal_connect_swapped (s, "changed::suppress-logout-restart-shutdown",
938
G_CALLBACK(indicator_session_actions_notify_can_prompt), self);
939
g_signal_connect_swapped (s, "changed::suppress-logout-restart-shutdown",
940
G_CALLBACK(indicator_session_actions_notify_can_reboot), self);
941
g_signal_connect_swapped (s, "changed::suppress-restart-menuitem",
942
G_CALLBACK(indicator_session_actions_notify_can_reboot), self);
943
g_signal_connect_swapped (s, "changed::suppress-shutdown-menuitem",
944
G_CALLBACK(indicator_session_actions_notify_can_reboot), self);
945
p->indicator_settings = s;
947
696
gnome_screen_saver_proxy_new_for_bus (G_BUS_TYPE_SESSION,
948
697
G_DBUS_PROXY_FLAGS_NONE,
949
698
"org.gnome.ScreenSaver",