2006-09-03 01:51:32 -07:00
|
|
|
#include "e.h"
|
|
|
|
|
|
|
|
/* local subsystem functions */
|
2010-06-24 09:19:12 -07:00
|
|
|
static Eina_Bool _e_sys_cb_timer(void *data);
|
|
|
|
static Eina_Bool _e_sys_cb_exit(void *data, int type, void *event);
|
2012-06-08 00:36:56 -07:00
|
|
|
static void _e_sys_cb_logout_logout(void *data, E_Dialog *dia);
|
|
|
|
static void _e_sys_cb_logout_wait(void *data, E_Dialog *dia);
|
|
|
|
static void _e_sys_cb_logout_abort(void *data, E_Dialog *dia);
|
2010-06-24 09:19:12 -07:00
|
|
|
static Eina_Bool _e_sys_cb_logout_timer(void *data);
|
2012-06-08 00:36:56 -07:00
|
|
|
static void _e_sys_logout_after(void);
|
2012-09-01 07:56:16 -07:00
|
|
|
static void _e_sys_logout_begin(E_Sys_Action a_after, Eina_Bool raw);
|
2012-06-08 00:36:56 -07:00
|
|
|
static void _e_sys_current_action(void);
|
|
|
|
static void _e_sys_action_failed(void);
|
2012-09-01 07:56:16 -07:00
|
|
|
static int _e_sys_action_do(E_Sys_Action a, char *param, Eina_Bool raw);
|
2012-06-08 00:36:56 -07:00
|
|
|
static void _e_sys_dialog_cb_delete(E_Obj_Dialog *od);
|
2006-09-03 01:51:32 -07:00
|
|
|
|
|
|
|
static Ecore_Event_Handler *_e_sys_exe_exit_handler = NULL;
|
|
|
|
static Ecore_Exe *_e_sys_halt_check_exe = NULL;
|
|
|
|
static Ecore_Exe *_e_sys_reboot_check_exe = NULL;
|
|
|
|
static Ecore_Exe *_e_sys_suspend_check_exe = NULL;
|
|
|
|
static Ecore_Exe *_e_sys_hibernate_check_exe = NULL;
|
|
|
|
static int _e_sys_can_halt = 0;
|
|
|
|
static int _e_sys_can_reboot = 0;
|
|
|
|
static int _e_sys_can_suspend = 0;
|
|
|
|
static int _e_sys_can_hibernate = 0;
|
|
|
|
|
2006-09-09 00:00:14 -07:00
|
|
|
static E_Sys_Action _e_sys_action_current = E_SYS_NONE;
|
|
|
|
static E_Sys_Action _e_sys_action_after = E_SYS_NONE;
|
2012-09-01 07:56:16 -07:00
|
|
|
static Eina_Bool _e_sys_action_after_raw = EINA_FALSE;
|
2006-09-09 00:00:14 -07:00
|
|
|
static Ecore_Exe *_e_sys_exe = NULL;
|
2011-08-21 00:51:05 -07:00
|
|
|
static double _e_sys_begin_time = 0.0;
|
2006-09-09 00:00:14 -07:00
|
|
|
static double _e_sys_logout_begin_time = 0.0;
|
|
|
|
static Ecore_Timer *_e_sys_logout_timer = NULL;
|
2006-09-09 21:51:07 -07:00
|
|
|
static E_Obj_Dialog *_e_sys_dialog = NULL;
|
2010-02-17 06:03:06 -08:00
|
|
|
static E_Dialog *_e_sys_logout_confirm_dialog = NULL;
|
2012-09-01 07:56:16 -07:00
|
|
|
static Ecore_Timer *_e_sys_susp_hib_check_timer = NULL;
|
|
|
|
static double _e_sys_susp_hib_check_last_tick = 0.0;
|
2013-01-11 02:34:29 -08:00
|
|
|
static void (*_e_sys_suspend_func)(void) = NULL;
|
|
|
|
static void (*_e_sys_hibernate_func)(void) = NULL;
|
|
|
|
static void (*_e_sys_reboot_func)(void) = NULL;
|
|
|
|
static void (*_e_sys_shutdown_func)(void) = NULL;
|
|
|
|
static void (*_e_sys_logout_func)(void) = NULL;
|
|
|
|
static void (*_e_sys_resume_func)(void) = NULL;
|
2010-02-17 06:03:06 -08:00
|
|
|
|
2013-08-15 03:09:33 -07:00
|
|
|
static void _e_sys_systemd_handle_inhibit(void);
|
|
|
|
static void _e_sys_systemd_poweroff(void);
|
|
|
|
static void _e_sys_systemd_reboot(void);
|
|
|
|
static void _e_sys_systemd_suspend(void);
|
|
|
|
static void _e_sys_systemd_hibernate(void);
|
2013-08-15 10:03:04 -07:00
|
|
|
static void _e_sys_systemd_exists_cb(void *data, const Eldbus_Message *m, Eldbus_Pending *p);
|
2013-08-15 03:09:33 -07:00
|
|
|
|
|
|
|
static Eina_Bool systemd_works = EINA_FALSE;
|
2013-08-18 03:49:23 -07:00
|
|
|
static int _e_sys_systemd_inhibit_fd = -1;
|
2013-08-15 03:09:33 -07:00
|
|
|
|
2010-02-17 06:03:06 -08:00
|
|
|
static const int E_LOGOUT_AUTO_TIME = 60;
|
|
|
|
static const int E_LOGOUT_WAIT_TIME = 15;
|
2006-09-09 00:00:14 -07:00
|
|
|
|
2013-08-15 10:03:04 -07:00
|
|
|
static Eldbus_Proxy *login1_manger_proxy = NULL;
|
2013-08-15 03:09:33 -07:00
|
|
|
|
2012-09-21 02:16:37 -07:00
|
|
|
EAPI int E_EVENT_SYS_SUSPEND = -1;
|
|
|
|
EAPI int E_EVENT_SYS_HIBERNATE = -1;
|
|
|
|
EAPI int E_EVENT_SYS_RESUME = -1;
|
|
|
|
|
2006-09-03 01:51:32 -07:00
|
|
|
/* externally accessible functions */
|
2010-11-22 07:21:32 -08:00
|
|
|
EINTERN int
|
2006-09-03 01:51:32 -07:00
|
|
|
e_sys_init(void)
|
|
|
|
{
|
2013-08-15 10:03:04 -07:00
|
|
|
Eldbus_Connection *conn;
|
|
|
|
Eldbus_Object *obj;
|
|
|
|
|
2013-08-15 03:09:33 -07:00
|
|
|
eldbus_init();
|
|
|
|
conn = eldbus_connection_get(ELDBUS_CONNECTION_TYPE_SYSTEM);
|
2013-08-15 10:03:04 -07:00
|
|
|
obj = eldbus_object_get(conn, "org.freedesktop.login1",
|
|
|
|
"/org/freedesktop/login1");
|
|
|
|
login1_manger_proxy = eldbus_proxy_get(obj,
|
|
|
|
"org.freedesktop.login1.Manager");
|
|
|
|
eldbus_name_owner_get(conn, "org.freedesktop.login1",
|
|
|
|
_e_sys_systemd_exists_cb, NULL);
|
2013-08-15 03:09:33 -07:00
|
|
|
_e_sys_systemd_handle_inhibit();
|
|
|
|
|
2012-09-21 02:16:37 -07:00
|
|
|
E_EVENT_SYS_SUSPEND = ecore_event_type_new();
|
|
|
|
E_EVENT_SYS_HIBERNATE = ecore_event_type_new();
|
|
|
|
E_EVENT_SYS_RESUME = ecore_event_type_new();
|
2006-09-03 01:51:32 -07:00
|
|
|
/* this is not optimal - but it does work cleanly */
|
|
|
|
_e_sys_exe_exit_handler = ecore_event_handler_add(ECORE_EXE_EVENT_DEL,
|
2012-06-08 00:36:56 -07:00
|
|
|
_e_sys_cb_exit, NULL);
|
2006-09-03 01:51:32 -07:00
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
2010-11-22 07:21:32 -08:00
|
|
|
EINTERN int
|
2006-09-03 01:51:32 -07:00
|
|
|
e_sys_shutdown(void)
|
|
|
|
{
|
|
|
|
if (_e_sys_exe_exit_handler)
|
|
|
|
ecore_event_handler_del(_e_sys_exe_exit_handler);
|
|
|
|
_e_sys_exe_exit_handler = NULL;
|
|
|
|
_e_sys_halt_check_exe = NULL;
|
|
|
|
_e_sys_reboot_check_exe = NULL;
|
|
|
|
_e_sys_suspend_check_exe = NULL;
|
|
|
|
_e_sys_hibernate_check_exe = NULL;
|
2013-08-15 10:03:04 -07:00
|
|
|
if (login1_manger_proxy)
|
|
|
|
{
|
|
|
|
Eldbus_Connection *conn;
|
|
|
|
Eldbus_Object *obj;
|
|
|
|
|
|
|
|
obj = eldbus_proxy_object_get(login1_manger_proxy);
|
|
|
|
conn = eldbus_object_connection_get(obj);
|
|
|
|
eldbus_proxy_unref(login1_manger_proxy);
|
|
|
|
eldbus_object_unref(obj);
|
|
|
|
eldbus_connection_unref(conn);
|
|
|
|
login1_manger_proxy = NULL;
|
|
|
|
}
|
2013-08-18 03:49:23 -07:00
|
|
|
if (_e_sys_systemd_inhibit_fd >= 0)
|
|
|
|
{
|
|
|
|
close(_e_sys_systemd_inhibit_fd);
|
|
|
|
_e_sys_systemd_inhibit_fd = -1;
|
|
|
|
}
|
2013-08-15 03:09:33 -07:00
|
|
|
eldbus_shutdown();
|
2006-09-03 01:51:32 -07:00
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
EAPI int
|
|
|
|
e_sys_action_possible_get(E_Sys_Action a)
|
|
|
|
{
|
|
|
|
switch (a)
|
|
|
|
{
|
|
|
|
case E_SYS_EXIT:
|
|
|
|
case E_SYS_RESTART:
|
|
|
|
case E_SYS_EXIT_NOW:
|
2012-06-08 00:36:56 -07:00
|
|
|
return 1;
|
|
|
|
|
2006-09-03 01:51:32 -07:00
|
|
|
case E_SYS_LOGOUT:
|
2012-06-08 00:36:56 -07:00
|
|
|
return 1;
|
|
|
|
|
2006-09-03 01:51:32 -07:00
|
|
|
case E_SYS_HALT:
|
2008-07-08 07:00:53 -07:00
|
|
|
case E_SYS_HALT_NOW:
|
2012-06-08 00:36:56 -07:00
|
|
|
return _e_sys_can_halt;
|
|
|
|
|
2006-09-03 01:51:32 -07:00
|
|
|
case E_SYS_REBOOT:
|
2012-06-08 00:36:56 -07:00
|
|
|
return _e_sys_can_reboot;
|
|
|
|
|
2006-09-03 01:51:32 -07:00
|
|
|
case E_SYS_SUSPEND:
|
2012-06-08 00:36:56 -07:00
|
|
|
return _e_sys_can_suspend;
|
|
|
|
|
2006-09-03 01:51:32 -07:00
|
|
|
case E_SYS_HIBERNATE:
|
2012-06-08 00:36:56 -07:00
|
|
|
return _e_sys_can_hibernate;
|
|
|
|
|
2006-09-03 01:51:32 -07:00
|
|
|
default:
|
2012-06-08 00:36:56 -07:00
|
|
|
return 0;
|
2006-09-03 01:51:32 -07:00
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
EAPI int
|
|
|
|
e_sys_action_do(E_Sys_Action a, char *param)
|
|
|
|
{
|
2011-07-16 09:53:20 -07:00
|
|
|
int ret = 0;
|
2007-03-24 05:55:30 -07:00
|
|
|
|
2006-09-09 00:00:14 -07:00
|
|
|
if (_e_sys_action_current != E_SYS_NONE)
|
|
|
|
{
|
2012-06-08 00:36:56 -07:00
|
|
|
_e_sys_current_action();
|
|
|
|
return 0;
|
2006-09-09 00:00:14 -07:00
|
|
|
}
|
2006-09-03 01:51:32 -07:00
|
|
|
switch (a)
|
|
|
|
{
|
|
|
|
case E_SYS_EXIT:
|
|
|
|
case E_SYS_RESTART:
|
|
|
|
case E_SYS_EXIT_NOW:
|
|
|
|
case E_SYS_LOGOUT:
|
2006-09-09 00:00:14 -07:00
|
|
|
case E_SYS_SUSPEND:
|
|
|
|
case E_SYS_HIBERNATE:
|
2008-07-08 07:00:53 -07:00
|
|
|
case E_SYS_HALT_NOW:
|
2012-09-01 07:56:16 -07:00
|
|
|
ret = _e_sys_action_do(a, param, EINA_FALSE);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case E_SYS_HALT:
|
|
|
|
if (!e_util_immortal_check())
|
|
|
|
{
|
|
|
|
if (_e_sys_shutdown_func) _e_sys_shutdown_func();
|
|
|
|
else _e_sys_logout_begin(a, EINA_FALSE);
|
|
|
|
}
|
|
|
|
return 1;
|
|
|
|
break;
|
2013-01-11 02:34:29 -08:00
|
|
|
|
2012-09-01 07:56:16 -07:00
|
|
|
case E_SYS_REBOOT:
|
|
|
|
if (!e_util_immortal_check())
|
|
|
|
{
|
|
|
|
if (_e_sys_reboot_func) _e_sys_reboot_func();
|
|
|
|
else _e_sys_logout_begin(a, EINA_FALSE);
|
|
|
|
}
|
|
|
|
return 1;
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (ret) _e_sys_action_current = a;
|
|
|
|
else _e_sys_action_current = E_SYS_NONE;
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
EAPI int
|
|
|
|
e_sys_action_raw_do(E_Sys_Action a, char *param)
|
|
|
|
{
|
|
|
|
int ret = 0;
|
|
|
|
|
|
|
|
if (_e_sys_action_current != E_SYS_NONE)
|
|
|
|
{
|
|
|
|
_e_sys_current_action();
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
switch (a)
|
|
|
|
{
|
|
|
|
case E_SYS_EXIT:
|
|
|
|
case E_SYS_RESTART:
|
|
|
|
case E_SYS_EXIT_NOW:
|
|
|
|
case E_SYS_LOGOUT:
|
|
|
|
case E_SYS_SUSPEND:
|
|
|
|
case E_SYS_HIBERNATE:
|
|
|
|
case E_SYS_HALT_NOW:
|
|
|
|
ret = _e_sys_action_do(a, param, EINA_TRUE);
|
2012-06-08 00:36:56 -07:00
|
|
|
break;
|
|
|
|
|
2006-09-03 01:51:32 -07:00
|
|
|
case E_SYS_HALT:
|
|
|
|
case E_SYS_REBOOT:
|
2012-09-01 07:56:16 -07:00
|
|
|
if (!e_util_immortal_check()) _e_sys_logout_begin(a, EINA_TRUE);
|
2012-06-08 00:36:56 -07:00
|
|
|
return 1;
|
|
|
|
break;
|
|
|
|
|
2006-09-03 01:51:32 -07:00
|
|
|
default:
|
2011-07-16 09:53:20 -07:00
|
|
|
break;
|
2006-09-03 01:51:32 -07:00
|
|
|
}
|
2011-07-16 09:53:20 -07:00
|
|
|
|
|
|
|
if (ret) _e_sys_action_current = a;
|
|
|
|
else _e_sys_action_current = E_SYS_NONE;
|
|
|
|
|
2006-09-09 00:00:14 -07:00
|
|
|
return ret;
|
2006-09-03 01:51:32 -07:00
|
|
|
}
|
|
|
|
|
2008-11-26 04:54:23 -08:00
|
|
|
static Eina_List *extra_actions = NULL;
|
|
|
|
|
|
|
|
EAPI E_Sys_Con_Action *
|
|
|
|
e_sys_con_extra_action_register(const char *label,
|
|
|
|
const char *icon_group,
|
|
|
|
const char *button_name,
|
2012-06-08 00:36:56 -07:00
|
|
|
void (*func)(void *data),
|
2008-11-26 04:54:23 -08:00
|
|
|
const void *data)
|
|
|
|
{
|
|
|
|
E_Sys_Con_Action *sca;
|
2012-06-08 00:36:56 -07:00
|
|
|
|
2008-11-26 04:54:23 -08:00
|
|
|
sca = E_NEW(E_Sys_Con_Action, 1);
|
|
|
|
if (label)
|
|
|
|
sca->label = eina_stringshare_add(label);
|
|
|
|
if (icon_group)
|
|
|
|
sca->icon_group = eina_stringshare_add(icon_group);
|
|
|
|
if (button_name)
|
|
|
|
sca->button_name = eina_stringshare_add(button_name);
|
|
|
|
sca->func = func;
|
|
|
|
sca->data = data;
|
|
|
|
extra_actions = eina_list_append(extra_actions, sca);
|
|
|
|
return sca;
|
|
|
|
}
|
|
|
|
|
|
|
|
EAPI void
|
|
|
|
e_sys_con_extra_action_unregister(E_Sys_Con_Action *sca)
|
|
|
|
{
|
|
|
|
extra_actions = eina_list_remove(extra_actions, sca);
|
|
|
|
if (sca->label) eina_stringshare_del(sca->label);
|
|
|
|
if (sca->icon_group) eina_stringshare_del(sca->icon_group);
|
|
|
|
if (sca->button_name) eina_stringshare_del(sca->button_name);
|
|
|
|
free(sca);
|
|
|
|
}
|
|
|
|
|
|
|
|
EAPI const Eina_List *
|
|
|
|
e_sys_con_extra_action_list_get(void)
|
|
|
|
{
|
|
|
|
return extra_actions;
|
|
|
|
}
|
|
|
|
|
2012-09-01 07:56:16 -07:00
|
|
|
EAPI void
|
2013-01-11 02:34:29 -08:00
|
|
|
e_sys_handlers_set(void (*suspend_func)(void),
|
|
|
|
void (*hibernate_func)(void),
|
|
|
|
void (*reboot_func)(void),
|
|
|
|
void (*shutdown_func)(void),
|
|
|
|
void (*logout_func)(void),
|
|
|
|
void (*resume_func)(void))
|
2012-09-01 07:56:16 -07:00
|
|
|
{
|
|
|
|
_e_sys_suspend_func = suspend_func;
|
|
|
|
_e_sys_hibernate_func = hibernate_func;
|
|
|
|
_e_sys_reboot_func = reboot_func;
|
|
|
|
_e_sys_shutdown_func = shutdown_func;
|
|
|
|
_e_sys_logout_func = logout_func;
|
|
|
|
_e_sys_resume_func = resume_func;
|
|
|
|
}
|
|
|
|
|
2013-08-18 03:49:23 -07:00
|
|
|
static void
|
|
|
|
_e_sys_systemd_inhibit_cb(void *data __UNUSED__, const Eldbus_Message *m, Eldbus_Pending *p __UNUSED__)
|
|
|
|
{
|
|
|
|
int fd = -1;
|
|
|
|
if (eldbus_message_error_get(m, NULL, NULL)) return;
|
|
|
|
if (!eldbus_message_arguments_get(m, "h", &fd))
|
|
|
|
_e_sys_systemd_inhibit_fd = fd;
|
|
|
|
}
|
|
|
|
|
2013-08-15 03:09:33 -07:00
|
|
|
static void
|
|
|
|
_e_sys_systemd_handle_inhibit(void)
|
|
|
|
{
|
|
|
|
Eldbus_Message *m;
|
|
|
|
|
2013-08-15 10:03:04 -07:00
|
|
|
if (!login1_manger_proxy) return;
|
|
|
|
if (!(m = eldbus_proxy_method_call_new(login1_manger_proxy, "Inhibit")))
|
|
|
|
return;
|
2013-08-15 03:09:33 -07:00
|
|
|
eldbus_message_arguments_append
|
|
|
|
(m, "ssss",
|
|
|
|
"handle-power-key:"
|
|
|
|
"handle-suspend-key:"
|
|
|
|
"handle-hibernate-key:"
|
|
|
|
"handle-lid-switch", // what
|
|
|
|
"Enlightenment", // who (string)
|
|
|
|
"Normal Execution", // why (string)
|
|
|
|
"block");
|
2013-08-18 03:49:23 -07:00
|
|
|
eldbus_proxy_send(login1_manger_proxy, m, _e_sys_systemd_inhibit_cb, NULL, -1);
|
2013-08-15 03:09:33 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
_e_sys_systemd_check_cb(void *data, const Eldbus_Message *m, Eldbus_Pending *p __UNUSED__)
|
|
|
|
{
|
|
|
|
int *dest = data;
|
|
|
|
char *s = NULL;
|
|
|
|
if (!eldbus_message_arguments_get(m, "s", &s)) return;
|
|
|
|
if (!s) return;
|
|
|
|
if (!strcmp(s, "yes")) *dest = 1;
|
|
|
|
else *dest = 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
_e_sys_systemd_check(void)
|
|
|
|
{
|
2013-08-15 10:03:04 -07:00
|
|
|
if (!login1_manger_proxy) return;
|
|
|
|
if (!eldbus_proxy_call(login1_manger_proxy, "CanPowerOff",
|
|
|
|
_e_sys_systemd_check_cb, &_e_sys_can_halt, -1, ""))
|
|
|
|
return;
|
|
|
|
if (!eldbus_proxy_call(login1_manger_proxy, "CanReboot",
|
|
|
|
_e_sys_systemd_check_cb, &_e_sys_can_reboot, -1, ""))
|
|
|
|
return;
|
|
|
|
if (!eldbus_proxy_call(login1_manger_proxy, "CanSuspend",
|
|
|
|
_e_sys_systemd_check_cb, &_e_sys_can_suspend, -1, ""))
|
|
|
|
return;
|
|
|
|
if (!eldbus_proxy_call(login1_manger_proxy, "CanHibernate",
|
|
|
|
_e_sys_systemd_check_cb, &_e_sys_can_hibernate, -1, ""))
|
|
|
|
return;
|
2013-08-15 03:09:33 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
_e_sys_systemd_exists_cb(void *data __UNUSED__, const Eldbus_Message *m, Eldbus_Pending *p __UNUSED__)
|
|
|
|
{
|
|
|
|
const char *id = NULL;
|
|
|
|
|
|
|
|
if (eldbus_message_error_get(m, NULL, NULL)) goto fail;
|
|
|
|
if (!eldbus_message_arguments_get(m, "s", &id)) goto fail;
|
|
|
|
if ((!id) || (id[0] != ':')) goto fail;
|
|
|
|
systemd_works = EINA_TRUE;
|
|
|
|
_e_sys_systemd_check();
|
|
|
|
return;
|
|
|
|
fail:
|
|
|
|
systemd_works = EINA_FALSE;
|
|
|
|
/* delay this for 1.0 seconds while the rest of e starts up */
|
|
|
|
ecore_timer_add(1.0, _e_sys_cb_timer, NULL);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
_e_sys_systemd_poweroff(void)
|
|
|
|
{
|
2013-08-15 10:03:04 -07:00
|
|
|
eldbus_proxy_call(login1_manger_proxy, "PowerOff", NULL, NULL, -1, "b", 0);
|
2013-08-15 03:09:33 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
_e_sys_systemd_reboot(void)
|
|
|
|
{
|
2013-08-15 10:03:04 -07:00
|
|
|
eldbus_proxy_call(login1_manger_proxy, "Reboot", NULL, NULL, -1, "b", 0);
|
2013-08-15 03:09:33 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
_e_sys_systemd_suspend(void)
|
|
|
|
{
|
2013-08-15 10:03:04 -07:00
|
|
|
eldbus_proxy_call(login1_manger_proxy, "Suspend", NULL, NULL, -1, "b", 0);
|
2013-08-15 03:09:33 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
_e_sys_systemd_hibernate(void)
|
|
|
|
{
|
2013-08-15 10:03:04 -07:00
|
|
|
eldbus_proxy_call(login1_manger_proxy, "Hibernate", NULL, NULL, -1, "b", 0);
|
2013-08-15 03:09:33 -07:00
|
|
|
}
|
|
|
|
|
2012-09-01 07:56:16 -07:00
|
|
|
static Eina_Bool
|
|
|
|
_e_sys_susp_hib_check_timer_cb(void *data __UNUSED__)
|
|
|
|
{
|
|
|
|
double t = ecore_time_unix_get();
|
|
|
|
|
|
|
|
if ((t - _e_sys_susp_hib_check_last_tick) > 0.2)
|
|
|
|
{
|
|
|
|
_e_sys_susp_hib_check_timer = NULL;
|
|
|
|
if (_e_sys_dialog)
|
|
|
|
{
|
|
|
|
e_object_del(E_OBJECT(_e_sys_dialog));
|
|
|
|
_e_sys_dialog = NULL;
|
|
|
|
}
|
2012-09-21 02:16:37 -07:00
|
|
|
ecore_event_add(E_EVENT_SYS_RESUME, NULL, NULL, NULL);
|
2012-09-01 07:56:16 -07:00
|
|
|
if (_e_sys_resume_func) _e_sys_resume_func();
|
|
|
|
return EINA_FALSE;
|
|
|
|
}
|
|
|
|
_e_sys_susp_hib_check_last_tick = t;
|
|
|
|
return EINA_TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
_e_sys_susp_hib_check(void)
|
|
|
|
{
|
|
|
|
if (_e_sys_susp_hib_check_timer)
|
|
|
|
ecore_timer_del(_e_sys_susp_hib_check_timer);
|
|
|
|
_e_sys_susp_hib_check_last_tick = ecore_time_unix_get();
|
2013-01-11 02:34:29 -08:00
|
|
|
_e_sys_susp_hib_check_timer =
|
2012-09-01 07:56:16 -07:00
|
|
|
ecore_timer_add(0.1, _e_sys_susp_hib_check_timer_cb, NULL);
|
|
|
|
}
|
|
|
|
|
2006-09-03 01:51:32 -07:00
|
|
|
/* local subsystem functions */
|
2010-06-24 09:19:12 -07:00
|
|
|
static Eina_Bool
|
2010-11-05 11:40:31 -07:00
|
|
|
_e_sys_cb_timer(void *data __UNUSED__)
|
2006-10-21 03:28:01 -07:00
|
|
|
{
|
|
|
|
/* exec out sys helper and ask it to test if we are allowed to do these
|
|
|
|
* things
|
|
|
|
*/
|
|
|
|
char buf[4096];
|
2012-06-08 00:36:56 -07:00
|
|
|
|
2007-09-24 03:53:44 -07:00
|
|
|
e_init_status_set(_("Checking System Permissions"));
|
2012-06-08 00:36:56 -07:00
|
|
|
snprintf(buf, sizeof(buf),
|
|
|
|
"%s/enlightenment/utils/enlightenment_sys -t halt",
|
2011-07-16 08:58:59 -07:00
|
|
|
e_prefix_lib_get());
|
2006-10-21 03:28:01 -07:00
|
|
|
_e_sys_halt_check_exe = ecore_exe_run(buf, NULL);
|
2012-06-08 00:36:56 -07:00
|
|
|
snprintf(buf, sizeof(buf),
|
|
|
|
"%s/enlightenment/utils/enlightenment_sys -t reboot",
|
2011-07-16 08:58:59 -07:00
|
|
|
e_prefix_lib_get());
|
2006-10-21 03:28:01 -07:00
|
|
|
_e_sys_reboot_check_exe = ecore_exe_run(buf, NULL);
|
2012-06-08 00:36:56 -07:00
|
|
|
snprintf(buf, sizeof(buf),
|
|
|
|
"%s/enlightenment/utils/enlightenment_sys -t suspend",
|
2011-07-16 08:58:59 -07:00
|
|
|
e_prefix_lib_get());
|
2006-10-21 03:28:01 -07:00
|
|
|
_e_sys_suspend_check_exe = ecore_exe_run(buf, NULL);
|
2012-06-08 00:36:56 -07:00
|
|
|
snprintf(buf, sizeof(buf),
|
|
|
|
"%s/enlightenment/utils/enlightenment_sys -t hibernate",
|
2011-07-16 08:58:59 -07:00
|
|
|
e_prefix_lib_get());
|
2006-10-21 03:28:01 -07:00
|
|
|
_e_sys_hibernate_check_exe = ecore_exe_run(buf, NULL);
|
2010-06-24 09:19:12 -07:00
|
|
|
return ECORE_CALLBACK_CANCEL;
|
2006-10-21 03:28:01 -07:00
|
|
|
}
|
|
|
|
|
2010-06-24 09:19:12 -07:00
|
|
|
static Eina_Bool
|
2010-08-18 14:18:31 -07:00
|
|
|
_e_sys_cb_exit(void *data __UNUSED__, int type __UNUSED__, void *event)
|
2006-09-03 01:51:32 -07:00
|
|
|
{
|
|
|
|
Ecore_Exe_Event_Del *ev;
|
|
|
|
|
|
|
|
ev = event;
|
2006-09-09 00:00:14 -07:00
|
|
|
if ((_e_sys_exe) && (ev->exe == _e_sys_exe))
|
|
|
|
{
|
2012-06-08 00:36:56 -07:00
|
|
|
if (ev->exit_code != 0) _e_sys_action_failed();
|
|
|
|
if (((_e_sys_action_current != E_SYS_HALT) &&
|
|
|
|
(_e_sys_action_current != E_SYS_HALT_NOW) &&
|
|
|
|
(_e_sys_action_current != E_SYS_REBOOT)) ||
|
|
|
|
(ev->exit_code != 0))
|
|
|
|
{
|
|
|
|
if (_e_sys_dialog)
|
|
|
|
{
|
|
|
|
e_object_del(E_OBJECT(_e_sys_dialog));
|
|
|
|
_e_sys_dialog = NULL;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
_e_sys_action_current = E_SYS_NONE;
|
|
|
|
_e_sys_exe = NULL;
|
|
|
|
return ECORE_CALLBACK_RENEW;
|
2006-09-09 00:00:14 -07:00
|
|
|
}
|
2006-09-03 01:51:32 -07:00
|
|
|
if ((_e_sys_halt_check_exe) && (ev->exe == _e_sys_halt_check_exe))
|
|
|
|
{
|
2012-06-08 00:36:56 -07:00
|
|
|
e_init_status_set(_("System Check Done"));
|
|
|
|
/* exit_code: 0 == OK, 5 == suid root removed, 7 == group id error
|
|
|
|
* 10 == permission denied, 20 == action undefined */
|
|
|
|
if (ev->exit_code == 0)
|
|
|
|
{
|
|
|
|
_e_sys_can_halt = 1;
|
|
|
|
_e_sys_halt_check_exe = NULL;
|
|
|
|
}
|
2006-09-03 01:51:32 -07:00
|
|
|
}
|
|
|
|
else if ((_e_sys_reboot_check_exe) && (ev->exe == _e_sys_reboot_check_exe))
|
|
|
|
{
|
2012-06-08 00:36:56 -07:00
|
|
|
e_init_status_set(_("System Check Done"));
|
|
|
|
if (ev->exit_code == 0)
|
|
|
|
{
|
|
|
|
_e_sys_can_reboot = 1;
|
|
|
|
_e_sys_reboot_check_exe = NULL;
|
|
|
|
}
|
2006-09-03 01:51:32 -07:00
|
|
|
}
|
|
|
|
else if ((_e_sys_suspend_check_exe) && (ev->exe == _e_sys_suspend_check_exe))
|
|
|
|
{
|
2012-06-08 00:36:56 -07:00
|
|
|
e_init_status_set(_("System Check Done"));
|
|
|
|
if (ev->exit_code == 0)
|
|
|
|
{
|
|
|
|
_e_sys_can_suspend = 1;
|
|
|
|
_e_sys_suspend_check_exe = NULL;
|
|
|
|
}
|
2006-09-03 01:51:32 -07:00
|
|
|
}
|
|
|
|
else if ((_e_sys_hibernate_check_exe) && (ev->exe == _e_sys_hibernate_check_exe))
|
|
|
|
{
|
2012-06-08 00:36:56 -07:00
|
|
|
e_init_status_set(_("System Check Done"));
|
|
|
|
if (ev->exit_code == 0)
|
|
|
|
{
|
|
|
|
_e_sys_can_hibernate = 1;
|
|
|
|
_e_sys_hibernate_check_exe = NULL;
|
|
|
|
}
|
2006-09-03 01:51:32 -07:00
|
|
|
}
|
2010-06-24 09:19:12 -07:00
|
|
|
return ECORE_CALLBACK_RENEW;
|
2006-09-09 00:00:14 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2010-08-18 14:18:31 -07:00
|
|
|
_e_sys_cb_logout_logout(void *data __UNUSED__, E_Dialog *dia)
|
2006-09-09 00:00:14 -07:00
|
|
|
{
|
|
|
|
if (_e_sys_logout_timer)
|
|
|
|
{
|
2012-06-08 00:36:56 -07:00
|
|
|
ecore_timer_del(_e_sys_logout_timer);
|
|
|
|
_e_sys_logout_timer = NULL;
|
2006-09-09 00:00:14 -07:00
|
|
|
}
|
|
|
|
_e_sys_logout_begin_time = 0.0;
|
|
|
|
_e_sys_logout_after();
|
|
|
|
e_object_del(E_OBJECT(dia));
|
2010-02-17 06:03:06 -08:00
|
|
|
_e_sys_logout_confirm_dialog = NULL;
|
2006-09-09 00:00:14 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2010-08-18 14:18:31 -07:00
|
|
|
_e_sys_cb_logout_wait(void *data __UNUSED__, E_Dialog *dia)
|
2006-09-09 00:00:14 -07:00
|
|
|
{
|
|
|
|
if (_e_sys_logout_timer) ecore_timer_del(_e_sys_logout_timer);
|
|
|
|
_e_sys_logout_timer = ecore_timer_add(0.5, _e_sys_cb_logout_timer, NULL);
|
|
|
|
_e_sys_logout_begin_time = ecore_time_get();
|
|
|
|
e_object_del(E_OBJECT(dia));
|
2010-02-17 06:03:06 -08:00
|
|
|
_e_sys_logout_confirm_dialog = NULL;
|
2006-09-09 00:00:14 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2010-08-18 14:18:31 -07:00
|
|
|
_e_sys_cb_logout_abort(void *data __UNUSED__, E_Dialog *dia)
|
2006-09-09 00:00:14 -07:00
|
|
|
{
|
|
|
|
if (_e_sys_logout_timer)
|
|
|
|
{
|
2012-06-08 00:36:56 -07:00
|
|
|
ecore_timer_del(_e_sys_logout_timer);
|
|
|
|
_e_sys_logout_timer = NULL;
|
2006-09-09 00:00:14 -07:00
|
|
|
}
|
|
|
|
_e_sys_logout_begin_time = 0.0;
|
|
|
|
e_object_del(E_OBJECT(dia));
|
2010-02-17 06:03:06 -08:00
|
|
|
_e_sys_logout_confirm_dialog = NULL;
|
2006-09-09 00:00:14 -07:00
|
|
|
_e_sys_action_current = E_SYS_NONE;
|
|
|
|
_e_sys_action_after = E_SYS_NONE;
|
2012-09-01 07:56:16 -07:00
|
|
|
_e_sys_action_after_raw = EINA_FALSE;
|
2006-09-09 21:51:07 -07:00
|
|
|
if (_e_sys_dialog)
|
|
|
|
{
|
2012-06-08 00:36:56 -07:00
|
|
|
e_object_del(E_OBJECT(_e_sys_dialog));
|
|
|
|
_e_sys_dialog = NULL;
|
2006-09-09 21:51:07 -07:00
|
|
|
}
|
2006-09-09 00:00:14 -07:00
|
|
|
}
|
|
|
|
|
2010-02-17 06:03:06 -08:00
|
|
|
static void
|
|
|
|
_e_sys_logout_confirm_dialog_update(int remaining)
|
|
|
|
{
|
2012-08-22 00:02:41 -07:00
|
|
|
char txt[4096];
|
2010-02-17 06:03:06 -08:00
|
|
|
|
|
|
|
if (!_e_sys_logout_confirm_dialog)
|
|
|
|
{
|
2012-06-08 00:36:56 -07:00
|
|
|
fputs("ERROR: updating logout confirm dialog, but none exists!\n",
|
|
|
|
stderr);
|
|
|
|
return;
|
2010-02-17 06:03:06 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
snprintf(txt, sizeof(txt),
|
2012-06-08 00:36:56 -07:00
|
|
|
_("Logout is taking too long.<br>"
|
|
|
|
"Some applications refuse to close.<br>"
|
|
|
|
"Do you want to finish the logout<br>"
|
|
|
|
"anyway without closing these<br>"
|
|
|
|
"applications first?<br><br>"
|
|
|
|
"Auto logout in %d seconds."), remaining);
|
2010-02-17 06:03:06 -08:00
|
|
|
|
|
|
|
e_dialog_text_set(_e_sys_logout_confirm_dialog, txt);
|
|
|
|
}
|
|
|
|
|
2010-06-24 09:19:12 -07:00
|
|
|
static Eina_Bool
|
2010-08-18 14:18:31 -07:00
|
|
|
_e_sys_cb_logout_timer(void *data __UNUSED__)
|
2006-09-09 00:00:14 -07:00
|
|
|
{
|
2008-10-22 04:49:33 -07:00
|
|
|
Eina_List *l;
|
2009-08-21 08:08:49 -07:00
|
|
|
E_Border *bd;
|
2006-09-09 00:00:14 -07:00
|
|
|
int pending = 0;
|
2007-03-24 05:55:30 -07:00
|
|
|
|
2009-08-21 08:08:49 -07:00
|
|
|
EINA_LIST_FOREACH(e_border_client_list(), l, bd)
|
2006-09-09 00:00:14 -07:00
|
|
|
{
|
2012-06-08 00:36:56 -07:00
|
|
|
if (!bd->internal) pending++;
|
2006-09-09 00:00:14 -07:00
|
|
|
}
|
|
|
|
if (pending == 0) goto after;
|
2010-02-17 06:03:06 -08:00
|
|
|
else if (_e_sys_logout_confirm_dialog)
|
|
|
|
{
|
2012-06-08 00:36:56 -07:00
|
|
|
int remaining = E_LOGOUT_AUTO_TIME -
|
|
|
|
round(ecore_loop_time_get() - _e_sys_logout_begin_time);
|
|
|
|
/* it has taken 60 (E_LOGOUT_AUTO_TIME) seconds of waiting the
|
|
|
|
* confirm dialog and we still have apps that will not go
|
|
|
|
* away. Do the action as user may be far away or forgot it.
|
|
|
|
*
|
|
|
|
* NOTE: this is the behavior for many operating systems and I
|
|
|
|
* guess the reason is people that hit "shutdown" and
|
|
|
|
* put their laptops in their backpacks in the hope
|
|
|
|
* everything will be turned off properly.
|
|
|
|
*/
|
|
|
|
if (remaining > 0)
|
|
|
|
{
|
|
|
|
_e_sys_logout_confirm_dialog_update(remaining);
|
|
|
|
return ECORE_CALLBACK_RENEW;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
_e_sys_cb_logout_logout(NULL, _e_sys_logout_confirm_dialog);
|
|
|
|
return ECORE_CALLBACK_CANCEL;
|
|
|
|
}
|
2010-02-17 06:03:06 -08:00
|
|
|
}
|
2006-09-09 00:00:14 -07:00
|
|
|
else
|
|
|
|
{
|
2012-06-08 00:36:56 -07:00
|
|
|
/* it has taken 15 seconds of waiting and we still have apps that
|
|
|
|
* will not go away
|
|
|
|
*/
|
|
|
|
double now = ecore_loop_time_get();
|
|
|
|
if ((now - _e_sys_logout_begin_time) > E_LOGOUT_WAIT_TIME)
|
|
|
|
{
|
|
|
|
E_Dialog *dia;
|
|
|
|
|
|
|
|
dia = e_dialog_new(e_container_current_get(e_manager_current_get()), "E", "_sys_error_logout_slow");
|
|
|
|
if (dia)
|
|
|
|
{
|
|
|
|
_e_sys_logout_confirm_dialog = dia;
|
|
|
|
e_dialog_title_set(dia, _("Logout problems"));
|
|
|
|
e_dialog_icon_set(dia, "system-log-out", 64);
|
|
|
|
e_dialog_button_add(dia, _("Logout now"), NULL,
|
2011-07-16 08:58:59 -07:00
|
|
|
_e_sys_cb_logout_logout, NULL);
|
2012-06-08 00:36:56 -07:00
|
|
|
e_dialog_button_add(dia, _("Wait longer"), NULL,
|
2011-07-16 08:58:59 -07:00
|
|
|
_e_sys_cb_logout_wait, NULL);
|
2012-06-08 00:36:56 -07:00
|
|
|
e_dialog_button_add(dia, _("Cancel Logout"), NULL,
|
2011-07-16 08:58:59 -07:00
|
|
|
_e_sys_cb_logout_abort, NULL);
|
2012-06-08 00:36:56 -07:00
|
|
|
e_dialog_button_focus_num(dia, 1);
|
|
|
|
_e_sys_logout_confirm_dialog_update(E_LOGOUT_AUTO_TIME);
|
|
|
|
e_win_centered_set(dia->win, 1);
|
|
|
|
e_dialog_show(dia);
|
|
|
|
_e_sys_logout_begin_time = now;
|
|
|
|
}
|
|
|
|
return ECORE_CALLBACK_RENEW;
|
|
|
|
}
|
2006-09-09 00:00:14 -07:00
|
|
|
}
|
2010-06-24 09:19:12 -07:00
|
|
|
return ECORE_CALLBACK_RENEW;
|
2012-06-08 00:36:56 -07:00
|
|
|
after:
|
2006-09-09 00:00:14 -07:00
|
|
|
_e_sys_logout_after();
|
|
|
|
_e_sys_logout_timer = NULL;
|
2010-06-24 09:19:12 -07:00
|
|
|
return ECORE_CALLBACK_CANCEL;
|
2006-09-09 00:00:14 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
_e_sys_logout_after(void)
|
|
|
|
{
|
2006-09-09 21:51:07 -07:00
|
|
|
if (_e_sys_dialog)
|
|
|
|
{
|
2012-06-08 00:36:56 -07:00
|
|
|
e_object_del(E_OBJECT(_e_sys_dialog));
|
|
|
|
_e_sys_dialog = NULL;
|
2006-09-09 21:51:07 -07:00
|
|
|
}
|
|
|
|
_e_sys_action_current = _e_sys_action_after;
|
2012-09-01 07:56:16 -07:00
|
|
|
_e_sys_action_do(_e_sys_action_after, NULL, _e_sys_action_after_raw);
|
2006-09-09 00:00:14 -07:00
|
|
|
_e_sys_action_after = E_SYS_NONE;
|
2012-09-01 07:56:16 -07:00
|
|
|
_e_sys_action_after_raw = EINA_FALSE;
|
2006-09-09 00:00:14 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2012-09-01 07:56:16 -07:00
|
|
|
_e_sys_logout_begin(E_Sys_Action a_after, Eina_Bool raw)
|
2006-09-09 00:00:14 -07:00
|
|
|
{
|
2008-10-22 04:49:33 -07:00
|
|
|
Eina_List *l;
|
2009-08-21 08:08:49 -07:00
|
|
|
E_Border *bd;
|
2006-09-09 21:51:07 -07:00
|
|
|
E_Obj_Dialog *od;
|
2007-03-24 05:55:30 -07:00
|
|
|
|
2006-09-09 00:00:14 -07:00
|
|
|
/* start logout - at end do the a_after action */
|
2012-09-01 07:56:16 -07:00
|
|
|
if (!raw)
|
|
|
|
{
|
|
|
|
od = e_obj_dialog_new(e_container_current_get(e_manager_current_get()),
|
|
|
|
_("Logout in progress"), "E", "_sys_logout");
|
|
|
|
e_obj_dialog_obj_theme_set(od, "base/theme/sys", "e/sys/logout");
|
|
|
|
e_obj_dialog_obj_part_text_set(od, "e.textblock.message",
|
|
|
|
_("Logout in progress.<br>"
|
|
|
|
"<hilight>Please wait.</hilight>"));
|
|
|
|
e_obj_dialog_show(od);
|
|
|
|
e_obj_dialog_icon_set(od, "system-log-out");
|
|
|
|
if (_e_sys_dialog) e_object_del(E_OBJECT(_e_sys_dialog));
|
|
|
|
_e_sys_dialog = od;
|
|
|
|
}
|
2006-09-09 00:00:14 -07:00
|
|
|
_e_sys_action_after = a_after;
|
2012-09-01 07:56:16 -07:00
|
|
|
_e_sys_action_after_raw = raw;
|
2009-08-21 08:08:49 -07:00
|
|
|
EINA_LIST_FOREACH(e_border_client_list(), l, bd)
|
2006-09-09 00:00:14 -07:00
|
|
|
{
|
2012-06-08 00:36:56 -07:00
|
|
|
e_border_act_close_begin(bd);
|
2006-09-09 00:00:14 -07:00
|
|
|
}
|
|
|
|
/* and poll to see if all pending windows are gone yet every 0.5 sec */
|
|
|
|
_e_sys_logout_begin_time = ecore_time_get();
|
|
|
|
if (_e_sys_logout_timer) ecore_timer_del(_e_sys_logout_timer);
|
|
|
|
_e_sys_logout_timer = ecore_timer_add(0.5, _e_sys_cb_logout_timer, NULL);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
_e_sys_current_action(void)
|
|
|
|
{
|
|
|
|
/* display dialog that currently an action is in progress */
|
|
|
|
E_Dialog *dia;
|
|
|
|
|
2012-06-08 00:36:56 -07:00
|
|
|
dia = e_dialog_new(e_container_current_get(e_manager_current_get()),
|
2011-07-16 08:58:59 -07:00
|
|
|
"E", "_sys_error_action_busy");
|
2006-09-09 00:00:14 -07:00
|
|
|
if (!dia) return;
|
2007-03-24 05:55:30 -07:00
|
|
|
|
2006-09-09 00:00:14 -07:00
|
|
|
e_dialog_title_set(dia, _("Enlightenment is busy with another request"));
|
|
|
|
e_dialog_icon_set(dia, "enlightenment/sys", 64);
|
|
|
|
switch (_e_sys_action_current)
|
|
|
|
{
|
|
|
|
case E_SYS_LOGOUT:
|
2012-06-08 00:36:56 -07:00
|
|
|
e_dialog_text_set(dia, _("Logging out.<br>"
|
2011-07-16 08:58:59 -07:00
|
|
|
"You cannot perform other system actions<br>"
|
|
|
|
"once a logout has begun."));
|
2012-06-08 00:36:56 -07:00
|
|
|
break;
|
|
|
|
|
2006-09-09 00:00:14 -07:00
|
|
|
case E_SYS_HALT:
|
2008-07-08 08:48:39 -07:00
|
|
|
case E_SYS_HALT_NOW:
|
2012-06-08 00:36:56 -07:00
|
|
|
e_dialog_text_set(dia, _("Powering off.<br>"
|
2011-07-16 08:58:59 -07:00
|
|
|
"You cannot do any other system actions<br>"
|
|
|
|
"once a shutdown has been started."));
|
2012-06-08 00:36:56 -07:00
|
|
|
break;
|
|
|
|
|
2006-09-09 00:00:14 -07:00
|
|
|
case E_SYS_REBOOT:
|
2012-06-08 00:36:56 -07:00
|
|
|
e_dialog_text_set(dia, _("Resetting.<br>"
|
2011-07-16 08:58:59 -07:00
|
|
|
"You cannot do any other system actions<br>"
|
|
|
|
"once a reboot has begun."));
|
2012-06-08 00:36:56 -07:00
|
|
|
break;
|
|
|
|
|
2006-09-09 00:00:14 -07:00
|
|
|
case E_SYS_SUSPEND:
|
2012-06-08 00:36:56 -07:00
|
|
|
e_dialog_text_set(dia, _("Suspending.<br>"
|
2011-07-16 08:58:59 -07:00
|
|
|
"Until suspend is complete you cannot perform<br>"
|
|
|
|
"any other system actions."));
|
2012-06-08 00:36:56 -07:00
|
|
|
break;
|
|
|
|
|
2006-09-09 00:00:14 -07:00
|
|
|
case E_SYS_HIBERNATE:
|
2012-06-08 00:36:56 -07:00
|
|
|
e_dialog_text_set(dia, _("Hibernating.<br>"
|
2011-07-16 08:58:59 -07:00
|
|
|
"You cannot perform any other system actions<br>"
|
|
|
|
"until this is complete."));
|
2012-06-08 00:36:56 -07:00
|
|
|
break;
|
|
|
|
|
2006-09-09 00:00:14 -07:00
|
|
|
default:
|
2012-06-08 00:36:56 -07:00
|
|
|
e_dialog_text_set(dia, _("EEK! This should not happen"));
|
|
|
|
break;
|
2006-09-09 00:00:14 -07:00
|
|
|
}
|
|
|
|
e_dialog_button_add(dia, _("OK"), NULL, NULL, NULL);
|
|
|
|
e_dialog_button_focus_num(dia, 0);
|
|
|
|
e_win_centered_set(dia->win, 1);
|
|
|
|
e_dialog_show(dia);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
_e_sys_action_failed(void)
|
|
|
|
{
|
|
|
|
/* display dialog that the current action failed */
|
|
|
|
E_Dialog *dia;
|
|
|
|
|
2012-06-08 00:36:56 -07:00
|
|
|
dia = e_dialog_new(e_container_current_get(e_manager_current_get()),
|
2011-07-16 08:58:59 -07:00
|
|
|
"E", "_sys_error_action_failed");
|
2006-09-09 00:00:14 -07:00
|
|
|
if (!dia) return;
|
2007-03-24 05:55:30 -07:00
|
|
|
|
2006-09-09 00:00:14 -07:00
|
|
|
e_dialog_title_set(dia, _("Enlightenment is busy with another request"));
|
|
|
|
e_dialog_icon_set(dia, "enlightenment/sys", 64);
|
|
|
|
switch (_e_sys_action_current)
|
2006-09-03 01:51:32 -07:00
|
|
|
{
|
2006-09-09 00:00:14 -07:00
|
|
|
case E_SYS_HALT:
|
2008-07-08 08:48:39 -07:00
|
|
|
case E_SYS_HALT_NOW:
|
2012-06-08 00:36:56 -07:00
|
|
|
e_dialog_text_set(dia, _("Power off failed."));
|
|
|
|
break;
|
|
|
|
|
2006-09-09 00:00:14 -07:00
|
|
|
case E_SYS_REBOOT:
|
2012-06-08 00:36:56 -07:00
|
|
|
e_dialog_text_set(dia, _("Reset failed."));
|
|
|
|
break;
|
|
|
|
|
2006-09-09 00:00:14 -07:00
|
|
|
case E_SYS_SUSPEND:
|
2012-06-08 00:36:56 -07:00
|
|
|
e_dialog_text_set(dia, _("Suspend failed."));
|
|
|
|
break;
|
|
|
|
|
2006-09-09 00:00:14 -07:00
|
|
|
case E_SYS_HIBERNATE:
|
2012-06-08 00:36:56 -07:00
|
|
|
e_dialog_text_set(dia, _("Hibernate failed."));
|
|
|
|
break;
|
|
|
|
|
2006-09-09 00:00:14 -07:00
|
|
|
default:
|
2012-06-08 00:36:56 -07:00
|
|
|
e_dialog_text_set(dia, _("EEK! This should not happen"));
|
|
|
|
break;
|
2006-09-09 00:00:14 -07:00
|
|
|
}
|
|
|
|
e_dialog_button_add(dia, _("OK"), NULL, NULL, NULL);
|
|
|
|
e_dialog_button_focus_num(dia, 0);
|
|
|
|
e_win_centered_set(dia->win, 1);
|
|
|
|
e_dialog_show(dia);
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
2012-09-01 07:56:16 -07:00
|
|
|
_e_sys_action_do(E_Sys_Action a, char *param __UNUSED__, Eina_Bool raw)
|
2006-09-09 00:00:14 -07:00
|
|
|
{
|
2010-08-18 14:18:31 -07:00
|
|
|
char buf[PATH_MAX];
|
2006-09-09 21:51:07 -07:00
|
|
|
E_Obj_Dialog *od;
|
2013-08-15 03:09:33 -07:00
|
|
|
int ret = 0;
|
2007-03-24 05:55:30 -07:00
|
|
|
|
2006-09-09 00:00:14 -07:00
|
|
|
switch (a)
|
|
|
|
{
|
|
|
|
case E_SYS_EXIT:
|
2012-06-08 00:36:56 -07:00
|
|
|
// XXX TODO: check for e_fm_op_registry entries and confirm
|
|
|
|
if (!e_util_immortal_check())
|
2011-07-16 09:53:20 -07:00
|
|
|
ecore_main_loop_quit();
|
2012-06-08 00:36:56 -07:00
|
|
|
else
|
2011-07-16 09:53:20 -07:00
|
|
|
return 0;
|
2012-06-08 00:36:56 -07:00
|
|
|
break;
|
|
|
|
|
2006-09-09 00:00:14 -07:00
|
|
|
case E_SYS_RESTART:
|
2012-06-08 00:36:56 -07:00
|
|
|
// XXX TODO: check for e_fm_op_registry entries and confirm
|
2011-08-21 00:51:05 -07:00
|
|
|
// FIXME: we dont share out immortal info to restarted e. :(
|
|
|
|
// if (!e_util_immortal_check())
|
2012-06-08 00:36:56 -07:00
|
|
|
{
|
|
|
|
restart = 1;
|
|
|
|
ecore_main_loop_quit();
|
|
|
|
}
|
2011-08-21 00:51:05 -07:00
|
|
|
// else
|
|
|
|
// return 0;
|
2012-06-08 00:36:56 -07:00
|
|
|
break;
|
|
|
|
|
2006-09-09 00:00:14 -07:00
|
|
|
case E_SYS_EXIT_NOW:
|
2012-06-08 00:36:56 -07:00
|
|
|
exit(0);
|
|
|
|
break;
|
|
|
|
|
2006-09-09 00:00:14 -07:00
|
|
|
case E_SYS_LOGOUT:
|
2012-06-08 00:36:56 -07:00
|
|
|
// XXX TODO: check for e_fm_op_registry entries and confirm
|
2012-09-01 07:56:16 -07:00
|
|
|
if (raw)
|
|
|
|
{
|
|
|
|
_e_sys_logout_begin(E_SYS_EXIT, raw);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if (_e_sys_logout_func)
|
|
|
|
{
|
|
|
|
_e_sys_logout_func();
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
_e_sys_logout_begin(E_SYS_EXIT, raw);
|
|
|
|
}
|
|
|
|
}
|
2012-06-08 00:36:56 -07:00
|
|
|
break;
|
|
|
|
|
2006-09-09 00:00:14 -07:00
|
|
|
case E_SYS_HALT:
|
2008-07-08 08:48:39 -07:00
|
|
|
case E_SYS_HALT_NOW:
|
2012-06-08 00:36:56 -07:00
|
|
|
/* shutdown -h now */
|
|
|
|
if (e_util_immortal_check()) return 0;
|
|
|
|
snprintf(buf, sizeof(buf),
|
|
|
|
"%s/enlightenment/utils/enlightenment_sys halt",
|
2011-07-16 08:58:59 -07:00
|
|
|
e_prefix_lib_get());
|
2012-06-08 00:36:56 -07:00
|
|
|
if (_e_sys_exe)
|
|
|
|
{
|
2011-08-21 00:51:05 -07:00
|
|
|
if ((ecore_time_get() - _e_sys_begin_time) > 2.0)
|
2012-06-08 00:36:56 -07:00
|
|
|
_e_sys_current_action();
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2012-09-01 07:56:16 -07:00
|
|
|
if (raw)
|
|
|
|
{
|
|
|
|
_e_sys_begin_time = ecore_time_get();
|
2013-08-15 03:09:33 -07:00
|
|
|
if (systemd_works)
|
|
|
|
_e_sys_systemd_poweroff();
|
|
|
|
else
|
|
|
|
{
|
|
|
|
_e_sys_exe = ecore_exe_run(buf, NULL);
|
|
|
|
ret = 1;
|
|
|
|
}
|
2012-09-01 07:56:16 -07:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if (_e_sys_shutdown_func)
|
|
|
|
{
|
|
|
|
_e_sys_shutdown_func();
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
_e_sys_begin_time = ecore_time_get();
|
2013-08-15 03:09:33 -07:00
|
|
|
if (systemd_works)
|
|
|
|
_e_sys_systemd_hibernate();
|
|
|
|
else
|
|
|
|
{
|
|
|
|
_e_sys_exe = ecore_exe_run(buf, NULL);
|
|
|
|
ret = 1;
|
|
|
|
}
|
2012-09-01 07:56:16 -07:00
|
|
|
od = e_obj_dialog_new(e_container_current_get(e_manager_current_get()),
|
|
|
|
_("Power off"), "E", "_sys_halt");
|
|
|
|
e_obj_dialog_obj_theme_set(od, "base/theme/sys", "e/sys/halt");
|
|
|
|
e_obj_dialog_obj_part_text_set(od, "e.textblock.message",
|
|
|
|
_("Power off.<br>"
|
|
|
|
"<hilight>Please wait.</hilight>"));
|
|
|
|
e_obj_dialog_show(od);
|
|
|
|
e_obj_dialog_icon_set(od, "system-shutdown");
|
|
|
|
if (_e_sys_dialog) e_object_del(E_OBJECT(_e_sys_dialog));
|
|
|
|
e_obj_dialog_cb_delete_set(od, _e_sys_dialog_cb_delete);
|
|
|
|
_e_sys_dialog = od;
|
|
|
|
}
|
|
|
|
}
|
2012-06-08 00:36:56 -07:00
|
|
|
/* FIXME: display halt status */
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
2006-09-09 00:00:14 -07:00
|
|
|
case E_SYS_REBOOT:
|
2012-06-08 00:36:56 -07:00
|
|
|
/* shutdown -r now */
|
|
|
|
if (e_util_immortal_check()) return 0;
|
|
|
|
snprintf(buf, sizeof(buf),
|
2011-07-16 08:58:59 -07:00
|
|
|
"%s/enlightenment/utils/enlightenment_sys reboot",
|
2012-06-08 00:36:56 -07:00
|
|
|
e_prefix_lib_get());
|
|
|
|
if (_e_sys_exe)
|
|
|
|
{
|
2011-08-21 00:51:05 -07:00
|
|
|
if ((ecore_time_get() - _e_sys_begin_time) > 2.0)
|
2012-06-08 00:36:56 -07:00
|
|
|
_e_sys_current_action();
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2012-09-01 07:56:16 -07:00
|
|
|
if (raw)
|
|
|
|
{
|
|
|
|
_e_sys_begin_time = ecore_time_get();
|
2013-08-15 03:09:33 -07:00
|
|
|
if (systemd_works)
|
|
|
|
_e_sys_systemd_reboot();
|
|
|
|
else
|
|
|
|
{
|
|
|
|
_e_sys_exe = ecore_exe_run(buf, NULL);
|
|
|
|
ret = 1;
|
|
|
|
}
|
2012-09-01 07:56:16 -07:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if (_e_sys_reboot_func)
|
|
|
|
{
|
|
|
|
_e_sys_reboot_func();
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
_e_sys_begin_time = ecore_time_get();
|
2013-08-15 03:09:33 -07:00
|
|
|
if (systemd_works)
|
|
|
|
_e_sys_systemd_reboot();
|
|
|
|
else
|
|
|
|
{
|
|
|
|
_e_sys_exe = ecore_exe_run(buf, NULL);
|
|
|
|
ret = 1;
|
|
|
|
}
|
2012-09-01 07:56:16 -07:00
|
|
|
od = e_obj_dialog_new(e_container_current_get(e_manager_current_get()),
|
|
|
|
_("Resetting"), "E", "_sys_reboot");
|
|
|
|
e_obj_dialog_obj_theme_set(od, "base/theme/sys", "e/sys/reboot");
|
|
|
|
e_obj_dialog_obj_part_text_set(od, "e.textblock.message",
|
|
|
|
_("Resetting.<br>"
|
|
|
|
"<hilight>Please wait.</hilight>"));
|
|
|
|
e_obj_dialog_show(od);
|
|
|
|
e_obj_dialog_icon_set(od, "system-restart");
|
|
|
|
if (_e_sys_dialog) e_object_del(E_OBJECT(_e_sys_dialog));
|
|
|
|
e_obj_dialog_cb_delete_set(od, _e_sys_dialog_cb_delete);
|
|
|
|
_e_sys_dialog = od;
|
|
|
|
}
|
|
|
|
}
|
2012-06-08 00:36:56 -07:00
|
|
|
/* FIXME: display reboot status */
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
2006-09-09 00:00:14 -07:00
|
|
|
case E_SYS_SUSPEND:
|
2012-06-08 00:36:56 -07:00
|
|
|
/* /etc/acpi/sleep.sh force */
|
|
|
|
snprintf(buf, sizeof(buf),
|
2011-07-16 08:58:59 -07:00
|
|
|
"%s/enlightenment/utils/enlightenment_sys suspend",
|
2012-06-08 00:36:56 -07:00
|
|
|
e_prefix_lib_get());
|
|
|
|
if (_e_sys_exe)
|
|
|
|
{
|
2011-08-21 00:51:05 -07:00
|
|
|
if ((ecore_time_get() - _e_sys_begin_time) > 2.0)
|
2012-06-08 00:36:56 -07:00
|
|
|
_e_sys_current_action();
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2012-09-01 07:56:16 -07:00
|
|
|
if (raw)
|
|
|
|
{
|
|
|
|
_e_sys_susp_hib_check();
|
|
|
|
if (e_config->desklock_on_suspend)
|
|
|
|
e_desklock_show(EINA_TRUE);
|
|
|
|
_e_sys_begin_time = ecore_time_get();
|
2013-08-15 03:09:33 -07:00
|
|
|
if (systemd_works)
|
|
|
|
_e_sys_systemd_suspend();
|
|
|
|
else
|
|
|
|
{
|
|
|
|
_e_sys_exe = ecore_exe_run(buf, NULL);
|
|
|
|
ret = 1;
|
|
|
|
}
|
2012-09-01 07:56:16 -07:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2012-09-21 02:16:37 -07:00
|
|
|
ecore_event_add(E_EVENT_SYS_SUSPEND, NULL, NULL, NULL);
|
2012-09-01 07:56:16 -07:00
|
|
|
if (_e_sys_suspend_func)
|
|
|
|
{
|
|
|
|
_e_sys_suspend_func();
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if (e_config->desklock_on_suspend)
|
|
|
|
e_desklock_show(EINA_TRUE);
|
2013-01-11 02:34:29 -08:00
|
|
|
|
2012-09-01 07:56:16 -07:00
|
|
|
_e_sys_susp_hib_check();
|
2013-01-11 02:34:29 -08:00
|
|
|
|
2012-09-01 07:56:16 -07:00
|
|
|
_e_sys_begin_time = ecore_time_get();
|
2013-08-15 03:09:33 -07:00
|
|
|
if (systemd_works)
|
|
|
|
_e_sys_systemd_suspend();
|
|
|
|
else
|
|
|
|
{
|
|
|
|
_e_sys_exe = ecore_exe_run(buf, NULL);
|
|
|
|
ret = 1;
|
|
|
|
}
|
2012-09-01 07:56:16 -07:00
|
|
|
od = e_obj_dialog_new(e_container_current_get(e_manager_current_get()),
|
|
|
|
_("Suspending"), "E", "_sys_suspend");
|
|
|
|
e_obj_dialog_obj_theme_set(od, "base/theme/sys", "e/sys/suspend");
|
|
|
|
e_obj_dialog_obj_part_text_set(od, "e.textblock.message",
|
|
|
|
_("Suspending.<br>"
|
|
|
|
"<hilight>Please wait.</hilight>"));
|
|
|
|
e_obj_dialog_show(od);
|
|
|
|
e_obj_dialog_icon_set(od, "system-suspend");
|
|
|
|
if (_e_sys_dialog) e_object_del(E_OBJECT(_e_sys_dialog));
|
|
|
|
e_obj_dialog_cb_delete_set(od, _e_sys_dialog_cb_delete);
|
|
|
|
_e_sys_dialog = od;
|
|
|
|
}
|
|
|
|
}
|
2012-06-08 00:36:56 -07:00
|
|
|
/* FIXME: display suspend status */
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
2006-09-09 00:00:14 -07:00
|
|
|
case E_SYS_HIBERNATE:
|
2012-06-08 00:36:56 -07:00
|
|
|
/* /etc/acpi/hibernate.sh force */
|
|
|
|
snprintf(buf, sizeof(buf),
|
2011-07-16 08:58:59 -07:00
|
|
|
"%s/enlightenment/utils/enlightenment_sys hibernate",
|
2012-06-08 00:36:56 -07:00
|
|
|
e_prefix_lib_get());
|
|
|
|
if (_e_sys_exe)
|
|
|
|
{
|
2011-08-21 00:51:05 -07:00
|
|
|
if ((ecore_time_get() - _e_sys_begin_time) > 2.0)
|
2012-06-08 00:36:56 -07:00
|
|
|
_e_sys_current_action();
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2013-03-01 02:14:58 -08:00
|
|
|
if (raw)
|
2012-09-01 07:56:16 -07:00
|
|
|
{
|
2013-03-01 02:14:58 -08:00
|
|
|
_e_sys_susp_hib_check();
|
|
|
|
if (e_config->desklock_on_suspend)
|
|
|
|
e_desklock_show(EINA_TRUE);
|
|
|
|
_e_sys_begin_time = ecore_time_get();
|
2013-08-15 03:09:33 -07:00
|
|
|
if (systemd_works)
|
|
|
|
_e_sys_systemd_hibernate();
|
|
|
|
else
|
|
|
|
{
|
|
|
|
_e_sys_exe = ecore_exe_run(buf, NULL);
|
|
|
|
ret = 1;
|
|
|
|
}
|
2012-09-01 07:56:16 -07:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2013-03-01 02:14:58 -08:00
|
|
|
ecore_event_add(E_EVENT_SYS_HIBERNATE, NULL, NULL, NULL);
|
|
|
|
if (_e_sys_hibernate_func)
|
2012-09-01 07:56:16 -07:00
|
|
|
{
|
2013-03-01 02:14:58 -08:00
|
|
|
_e_sys_hibernate_func();
|
|
|
|
return 0;
|
2012-09-01 07:56:16 -07:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if (e_config->desklock_on_suspend)
|
|
|
|
e_desklock_show(EINA_TRUE);
|
2013-01-11 02:34:29 -08:00
|
|
|
|
2012-09-01 07:56:16 -07:00
|
|
|
_e_sys_susp_hib_check();
|
2013-01-11 02:34:29 -08:00
|
|
|
|
2012-09-01 07:56:16 -07:00
|
|
|
_e_sys_begin_time = ecore_time_get();
|
2013-08-15 03:09:33 -07:00
|
|
|
if (systemd_works)
|
|
|
|
_e_sys_systemd_hibernate();
|
|
|
|
else
|
|
|
|
{
|
|
|
|
_e_sys_exe = ecore_exe_run(buf, NULL);
|
|
|
|
ret = 1;
|
|
|
|
}
|
2012-09-01 07:56:16 -07:00
|
|
|
od = e_obj_dialog_new(e_container_current_get(e_manager_current_get()),
|
|
|
|
_("Hibernating"), "E", "_sys_hibernate");
|
|
|
|
e_obj_dialog_obj_theme_set(od, "base/theme/sys", "e/sys/hibernate");
|
|
|
|
e_obj_dialog_obj_part_text_set(od, "e.textblock.message",
|
|
|
|
_("Hibernating.<br>"
|
|
|
|
"<hilight>Please wait.</hilight>"));
|
|
|
|
e_obj_dialog_show(od);
|
|
|
|
e_obj_dialog_icon_set(od, "system-suspend-hibernate");
|
|
|
|
if (_e_sys_dialog) e_object_del(E_OBJECT(_e_sys_dialog));
|
|
|
|
_e_sys_dialog = od;
|
|
|
|
e_obj_dialog_cb_delete_set(od, _e_sys_dialog_cb_delete);
|
|
|
|
}
|
|
|
|
}
|
2012-06-08 00:36:56 -07:00
|
|
|
/* FIXME: display hibernate status */
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
2006-09-09 00:00:14 -07:00
|
|
|
default:
|
2012-06-08 00:36:56 -07:00
|
|
|
return 0;
|
2006-09-03 01:51:32 -07:00
|
|
|
}
|
2013-08-15 03:09:33 -07:00
|
|
|
return ret;
|
2006-09-03 01:51:32 -07:00
|
|
|
}
|
2013-01-11 02:34:29 -08:00
|
|
|
|
2012-06-08 00:36:56 -07:00
|
|
|
static void
|
2010-08-18 14:18:31 -07:00
|
|
|
_e_sys_dialog_cb_delete(E_Obj_Dialog *od __UNUSED__)
|
2006-10-27 18:30:31 -07:00
|
|
|
{
|
|
|
|
/* If we don't NULL out the _e_sys_dialog, then the
|
|
|
|
* ECORE_EXE_EVENT_DEL callback will trigger and segv if the window
|
|
|
|
* is deleted in some other way. */
|
|
|
|
_e_sys_dialog = NULL;
|
|
|
|
}
|
2013-01-11 02:34:29 -08:00
|
|
|
|