2011-10-27 19:49:24 -07:00
|
|
|
#include "e_mod_main.h"
|
|
|
|
|
|
|
|
/* Config function protos */
|
|
|
|
static Config *_notification_cfg_new(void);
|
|
|
|
static void _notification_cfg_free(Config *cfg);
|
|
|
|
|
|
|
|
/* Global variables */
|
|
|
|
E_Module *notification_mod = NULL;
|
|
|
|
Config *notification_cfg = NULL;
|
|
|
|
|
|
|
|
static E_Config_DD *conf_edd = NULL;
|
|
|
|
|
2016-03-30 13:16:44 -07:00
|
|
|
static unsigned int offline_id;
|
|
|
|
static unsigned int pres_id;
|
|
|
|
|
2011-10-27 19:49:24 -07:00
|
|
|
static unsigned int
|
2013-01-03 14:08:05 -08:00
|
|
|
_notification_notify(E_Notification_Notify *n)
|
2011-10-27 19:49:24 -07:00
|
|
|
{
|
2013-01-03 14:08:05 -08:00
|
|
|
unsigned int new_id;
|
2011-10-27 19:49:24 -07:00
|
|
|
|
2012-12-11 02:08:49 -08:00
|
|
|
if (e_desklock_state_get()) return 0;
|
2011-10-27 19:49:24 -07:00
|
|
|
|
2013-01-03 14:08:05 -08:00
|
|
|
notification_cfg->next_id++;
|
|
|
|
new_id = notification_cfg->next_id;
|
2013-04-25 01:12:43 -07:00
|
|
|
notification_popup_notify(n, new_id);
|
2011-10-27 19:49:24 -07:00
|
|
|
|
|
|
|
return new_id;
|
|
|
|
}
|
|
|
|
|
2016-03-30 13:16:44 -07:00
|
|
|
static void
|
|
|
|
_notification_id_update(void *d, unsigned int id)
|
|
|
|
{
|
|
|
|
uintptr_t *update_id = d;
|
|
|
|
|
|
|
|
*update_id = id;
|
|
|
|
}
|
|
|
|
|
2011-10-27 19:49:24 -07:00
|
|
|
static void
|
2013-01-03 14:08:24 -08:00
|
|
|
_notification_show_common(const char *summary,
|
|
|
|
const char *body,
|
2016-03-30 13:16:44 -07:00
|
|
|
unsigned int *update_id)
|
2011-10-27 19:49:24 -07:00
|
|
|
{
|
2013-01-03 14:08:24 -08:00
|
|
|
E_Notification_Notify n;
|
|
|
|
memset(&n, 0, sizeof(E_Notification_Notify));
|
|
|
|
n.app_name = "enlightenment";
|
2016-03-30 13:16:44 -07:00
|
|
|
n.replaces_id = *update_id;
|
2013-01-03 14:08:24 -08:00
|
|
|
n.icon.icon = "enlightenment";
|
2014-07-30 16:18:24 -07:00
|
|
|
n.summary = summary;
|
2013-01-03 14:08:24 -08:00
|
|
|
n.body = body;
|
2015-07-06 13:21:58 -07:00
|
|
|
n.urgency = E_NOTIFICATION_NOTIFY_URGENCY_CRITICAL;
|
2016-03-30 13:16:44 -07:00
|
|
|
e_notification_client_send(&n, _notification_id_update, update_id);
|
2011-10-27 19:49:24 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
_notification_show_presentation(Eina_Bool enabled)
|
|
|
|
{
|
|
|
|
const char *summary, *body;
|
|
|
|
|
|
|
|
if (enabled)
|
|
|
|
{
|
2015-02-23 12:26:00 -08:00
|
|
|
summary = _("Entered Presentation Mode");
|
|
|
|
body = _("Enlightenment has now entered <b>presentation</b> mode."
|
2011-11-01 15:28:36 -07:00
|
|
|
"<br>During presentation mode, screen saver, lock and "
|
|
|
|
"power saving will be disabled so you are not interrupted.");
|
2011-10-27 19:49:24 -07:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2011-11-01 15:28:36 -07:00
|
|
|
summary = _("Exited Presentation Mode");
|
2015-02-23 12:26:00 -08:00
|
|
|
body = _("Presentation mode has been exited."
|
2011-11-01 15:28:36 -07:00
|
|
|
"<br>Now screen saver, lock and "
|
|
|
|
"power saving settings will be restored.");
|
2011-10-27 19:49:24 -07:00
|
|
|
}
|
|
|
|
|
2016-03-30 13:16:44 -07:00
|
|
|
_notification_show_common(summary, body, &pres_id);
|
2011-10-27 19:49:24 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
_notification_show_offline(Eina_Bool enabled)
|
|
|
|
{
|
|
|
|
const char *summary, *body;
|
|
|
|
|
|
|
|
if (enabled)
|
|
|
|
{
|
2011-11-01 15:28:36 -07:00
|
|
|
summary = _("Enter Offline Mode");
|
|
|
|
body = _("Enlightenment is in <b>offline</b> mode.<br>"
|
|
|
|
"During offline mode, modules that use network will stop "
|
|
|
|
"polling remote services.");
|
2011-10-27 19:49:24 -07:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2011-11-01 15:28:36 -07:00
|
|
|
summary = _("Exited Offline Mode");
|
|
|
|
body = _("Now in <b>online</b> mode.<br>"
|
|
|
|
"Now modules that use network will "
|
|
|
|
"resume regular tasks.");
|
2011-10-27 19:49:24 -07:00
|
|
|
}
|
|
|
|
|
2016-03-30 13:16:44 -07:00
|
|
|
_notification_show_common(summary, body, &offline_id);
|
2011-10-27 19:49:24 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
static Eina_Bool
|
|
|
|
_notification_cb_config_mode_changed(Config *m_cfg,
|
2015-03-18 15:09:09 -07:00
|
|
|
int type EINA_UNUSED,
|
|
|
|
void *event EINA_UNUSED)
|
2011-10-27 19:49:24 -07:00
|
|
|
{
|
|
|
|
if (m_cfg->last_config_mode.presentation != e_config->mode.presentation)
|
|
|
|
{
|
|
|
|
m_cfg->last_config_mode.presentation = e_config->mode.presentation;
|
|
|
|
_notification_show_presentation(e_config->mode.presentation);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (m_cfg->last_config_mode.offline != e_config->mode.offline)
|
|
|
|
{
|
|
|
|
m_cfg->last_config_mode.offline = e_config->mode.offline;
|
|
|
|
_notification_show_offline(e_config->mode.offline);
|
|
|
|
}
|
|
|
|
|
|
|
|
return EINA_TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
static Eina_Bool
|
|
|
|
_notification_cb_initial_mode_timer(Config *m_cfg)
|
|
|
|
{
|
|
|
|
if (e_config->mode.presentation)
|
|
|
|
_notification_show_presentation(1);
|
|
|
|
if (e_config->mode.offline)
|
|
|
|
_notification_show_offline(1);
|
|
|
|
|
|
|
|
m_cfg->initial_mode_timer = NULL;
|
|
|
|
return EINA_FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Module Api Functions */
|
2015-05-07 12:13:10 -07:00
|
|
|
E_API E_Module_Api e_modapi = {E_MODULE_API_VERSION, "Notification"};
|
2011-10-27 19:49:24 -07:00
|
|
|
|
2013-01-03 14:08:05 -08:00
|
|
|
static const E_Notification_Server_Info server_info = {
|
2013-01-03 14:08:19 -08:00
|
|
|
.name = "e17",
|
|
|
|
.vendor = "enlightenment.org",
|
|
|
|
.version = "0.17",
|
|
|
|
.spec_version = "1.2",
|
|
|
|
.capabilities = { "body", "body-markup", NULL }
|
2013-01-03 14:08:05 -08:00
|
|
|
};
|
|
|
|
|
|
|
|
/* Callbacks */
|
|
|
|
static unsigned int
|
|
|
|
_notification_cb_notify(void *data EINA_UNUSED, E_Notification_Notify *n)
|
|
|
|
{
|
|
|
|
return _notification_notify(n);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
_notification_cb_close(void *data EINA_UNUSED, unsigned int id)
|
|
|
|
{
|
|
|
|
notification_popup_close(id);
|
|
|
|
}
|
|
|
|
|
2015-05-07 12:13:10 -07:00
|
|
|
E_API void *
|
2011-10-27 19:49:24 -07:00
|
|
|
e_modapi_init(E_Module *m)
|
|
|
|
{
|
|
|
|
char buf[PATH_MAX];
|
|
|
|
|
|
|
|
snprintf(buf, sizeof(buf), "%s/e-module-notification.edj", m->dir);
|
|
|
|
/* register config panel entry */
|
2011-11-01 15:28:36 -07:00
|
|
|
e_configure_registry_category_add("extensions", 90, _("Extensions"), NULL,
|
2011-10-27 19:49:24 -07:00
|
|
|
"preferences-extensions");
|
2011-11-01 15:28:36 -07:00
|
|
|
e_configure_registry_item_add("extensions/notification", 30,
|
|
|
|
_("Notification"), NULL,
|
2011-10-27 19:49:24 -07:00
|
|
|
buf, e_int_config_notification_module);
|
|
|
|
|
|
|
|
|
|
|
|
conf_edd = E_CONFIG_DD_NEW("Notification_Config", Config);
|
|
|
|
#undef T
|
|
|
|
#undef D
|
|
|
|
#define T Config
|
|
|
|
#define D conf_edd
|
|
|
|
E_CONFIG_VAL(D, T, version, INT);
|
|
|
|
E_CONFIG_VAL(D, T, show_low, INT);
|
|
|
|
E_CONFIG_VAL(D, T, show_normal, INT);
|
|
|
|
E_CONFIG_VAL(D, T, show_critical, INT);
|
|
|
|
E_CONFIG_VAL(D, T, corner, INT);
|
|
|
|
E_CONFIG_VAL(D, T, timeout, FLOAT);
|
|
|
|
E_CONFIG_VAL(D, T, force_timeout, INT);
|
|
|
|
E_CONFIG_VAL(D, T, ignore_replacement, INT);
|
2011-11-03 09:03:23 -07:00
|
|
|
E_CONFIG_VAL(D, T, dual_screen, INT);
|
2011-10-27 19:49:24 -07:00
|
|
|
|
|
|
|
notification_cfg = e_config_domain_load("module.notification", conf_edd);
|
|
|
|
if (notification_cfg &&
|
2011-11-01 15:28:36 -07:00
|
|
|
!(e_util_module_config_check(_("Notification Module"),
|
2011-10-27 19:49:24 -07:00
|
|
|
notification_cfg->version,
|
2012-12-21 15:57:05 -08:00
|
|
|
MOD_CONFIG_FILE_VERSION)))
|
2011-10-27 19:49:24 -07:00
|
|
|
{
|
|
|
|
_notification_cfg_free(notification_cfg);
|
2012-12-13 06:54:19 -08:00
|
|
|
notification_cfg = NULL;
|
2011-10-27 19:49:24 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
if (!notification_cfg)
|
2013-01-03 14:08:05 -08:00
|
|
|
notification_cfg = _notification_cfg_new();
|
2013-04-18 07:50:49 -07:00
|
|
|
/* upgrades */
|
|
|
|
if (notification_cfg->version - (MOD_CONFIG_FILE_EPOCH * 1000000) < 1)
|
|
|
|
{
|
|
|
|
if (notification_cfg->dual_screen) notification_cfg->dual_screen = POPUP_DISPLAY_POLICY_MULTI;
|
|
|
|
}
|
2013-04-18 05:04:23 -07:00
|
|
|
notification_cfg->version = MOD_CONFIG_FILE_VERSION;
|
2011-10-27 19:49:24 -07:00
|
|
|
|
|
|
|
/* set up the notification daemon */
|
2013-01-03 14:08:10 -08:00
|
|
|
if (!e_notification_server_register(&server_info, _notification_cb_notify,
|
2013-04-25 00:50:37 -07:00
|
|
|
_notification_cb_close, NULL))
|
2011-10-27 19:49:24 -07:00
|
|
|
{
|
2013-01-03 14:08:10 -08:00
|
|
|
e_util_dialog_show(_("Error during notification server initialization"),
|
2013-05-10 03:52:32 -07:00
|
|
|
_("Ensure there's no other module acting as a server "
|
|
|
|
"and that D-Bus is correctly installed and "
|
|
|
|
"running"));
|
2011-10-27 19:49:24 -07:00
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
notification_cfg->last_config_mode.presentation = e_config->mode.presentation;
|
|
|
|
notification_cfg->last_config_mode.offline = e_config->mode.offline;
|
2012-11-28 02:05:21 -08:00
|
|
|
notification_cfg->handler = ecore_event_handler_add
|
2011-10-27 19:49:24 -07:00
|
|
|
(E_EVENT_CONFIG_MODE_CHANGED, (Ecore_Event_Handler_Cb)_notification_cb_config_mode_changed,
|
2012-11-28 02:05:21 -08:00
|
|
|
notification_cfg);
|
2011-10-27 19:49:24 -07:00
|
|
|
notification_cfg->initial_mode_timer = ecore_timer_add
|
|
|
|
(0.1, (Ecore_Task_Cb)_notification_cb_initial_mode_timer, notification_cfg);
|
|
|
|
|
|
|
|
notification_mod = m;
|
2013-01-03 06:47:40 -08:00
|
|
|
|
2011-10-27 19:49:24 -07:00
|
|
|
return m;
|
|
|
|
}
|
|
|
|
|
2015-05-07 12:13:10 -07:00
|
|
|
E_API int
|
2015-03-18 15:09:09 -07:00
|
|
|
e_modapi_shutdown(E_Module *m EINA_UNUSED)
|
2011-10-27 19:49:24 -07:00
|
|
|
{
|
|
|
|
if (notification_cfg->initial_mode_timer)
|
|
|
|
ecore_timer_del(notification_cfg->initial_mode_timer);
|
|
|
|
|
2012-11-28 02:05:21 -08:00
|
|
|
if (notification_cfg->handler)
|
|
|
|
ecore_event_handler_del(notification_cfg->handler);
|
2011-10-27 19:49:24 -07:00
|
|
|
|
|
|
|
if (notification_cfg->cfd) e_object_del(E_OBJECT(notification_cfg->cfd));
|
|
|
|
e_configure_registry_item_del("extensions/notification");
|
|
|
|
e_configure_registry_category_del("extensions");
|
|
|
|
|
|
|
|
notification_popup_shutdown();
|
2013-01-03 14:08:10 -08:00
|
|
|
e_notification_server_unregister();
|
2013-01-03 14:08:05 -08:00
|
|
|
|
2011-10-27 19:49:24 -07:00
|
|
|
|
|
|
|
_notification_cfg_free(notification_cfg);
|
|
|
|
E_CONFIG_DD_FREE(conf_edd);
|
|
|
|
notification_mod = NULL;
|
|
|
|
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
2015-05-07 12:13:10 -07:00
|
|
|
E_API int
|
2015-03-18 15:09:09 -07:00
|
|
|
e_modapi_save(E_Module *m EINA_UNUSED)
|
2011-10-27 19:49:24 -07:00
|
|
|
{
|
2012-11-28 02:05:21 -08:00
|
|
|
return e_config_domain_save("module.notification", conf_edd, notification_cfg);
|
2011-10-27 19:49:24 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
static Config *
|
|
|
|
_notification_cfg_new(void)
|
|
|
|
{
|
|
|
|
Config *cfg;
|
|
|
|
|
|
|
|
cfg = E_NEW(Config, 1);
|
|
|
|
cfg->cfd = NULL;
|
2012-12-21 15:57:05 -08:00
|
|
|
cfg->version = MOD_CONFIG_FILE_VERSION;
|
2011-10-27 19:49:24 -07:00
|
|
|
cfg->show_low = 0;
|
|
|
|
cfg->show_normal = 1;
|
|
|
|
cfg->show_critical = 1;
|
|
|
|
cfg->timeout = 5.0;
|
|
|
|
cfg->force_timeout = 0;
|
|
|
|
cfg->ignore_replacement = 0;
|
2013-04-18 07:50:49 -07:00
|
|
|
cfg->dual_screen = POPUP_DISPLAY_POLICY_FIRST;
|
2011-10-27 19:49:24 -07:00
|
|
|
cfg->corner = CORNER_TR;
|
|
|
|
|
|
|
|
return cfg;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
_notification_cfg_free(Config *cfg)
|
|
|
|
{
|
2012-11-28 02:05:21 -08:00
|
|
|
free(cfg);
|
2011-10-27 19:49:24 -07:00
|
|
|
}
|