e: Change notification module to use internal notification API

Patch by: José Roberto de Souza  <zehortigoza@profusion.mobi>



SVN revision: 82118
This commit is contained in:
José Roberto de Souza 2013-01-03 22:08:05 +00:00 committed by Lucas De Marchi
parent 8ec8c40bb7
commit 80a3d9fb7a
3 changed files with 96 additions and 221 deletions

View File

@ -1,11 +1,5 @@
#include "e_mod_main.h" #include "e_mod_main.h"
/* Callback function protos */
static int _notification_cb_notify(E_Notification_Daemon *daemon,
E_Notification *n);
static void _notification_cb_close_notification(E_Notification_Daemon *daemon,
unsigned int id);
/* Config function protos */ /* Config function protos */
static Config *_notification_cfg_new(void); static Config *_notification_cfg_new(void);
static void _notification_cfg_free(Config *cfg); static void _notification_cfg_free(Config *cfg);
@ -19,43 +13,39 @@ static E_Config_DD *conf_edd = NULL;
static Eina_Inlist *cfg_opts = NULL; static Eina_Inlist *cfg_opts = NULL;
static unsigned int static unsigned int
_notification_notify(E_Notification *n) _notification_notify(E_Notification_Notify *n)
{ {
const char *appname; unsigned int new_id;
unsigned int replaces_id, new_id;
int popuped; int popuped;
if (e_desklock_state_get()) return 0; if (e_desklock_state_get()) return 0;
appname = e_notification_app_name_get(n);
replaces_id = e_notification_replaces_id_get(n);
if (replaces_id) new_id = replaces_id;
else new_id = notification_cfg->next_id++;
e_notification_id_set(n, new_id); notification_cfg->next_id++;
new_id = notification_cfg->next_id;
popuped = notification_popup_notify(n, replaces_id, appname); popuped = notification_popup_notify(n, new_id);
if (!popuped) if (!popuped)
{ {
e_notification_hint_urgency_set(n, 4); n->urgency = 4;
notification_popup_notify(n, replaces_id, appname); notification_popup_notify(n, new_id);
} }
return new_id; return new_id;
} }
//TODO use this call
static void static void
_notification_show_common(const char *summary, _notification_show_common(const char *summary EINA_UNUSED,
const char *body, const char *body EINA_UNUSED,
int replaces_id) int replaces_id EINA_UNUSED)
{ {
E_Notification *n = e_notification_full_new /*E_Notification *n = e_notification_full_new
("enlightenment", replaces_id, "enlightenment", summary, body, -1); ("enlightenment", replaces_id, "enlightenment", summary, body, -1);
if (!n) if (!n)
return; return;
_notification_notify(n); _notification_notify(n);
e_notification_unref(n); e_notification_unref(n);*/
} }
static void static void
@ -162,10 +152,26 @@ _notification_corner_info_cb(E_Configure_Option *co)
/* Module Api Functions */ /* Module Api Functions */
EAPI E_Module_Api e_modapi = {E_MODULE_API_VERSION, "Notification"}; EAPI E_Module_Api e_modapi = {E_MODULE_API_VERSION, "Notification"};
static const E_Notification_Server_Info server_info = {
"e17", "enlightenment.org", "0.17", "1.2", {"body", "body-markup", NULL}
};
/* 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);
}
EAPI void * EAPI void *
e_modapi_init(E_Module *m) e_modapi_init(E_Module *m)
{ {
E_Notification_Daemon *d;
char buf[PATH_MAX]; char buf[PATH_MAX];
E_Configure_Option *co; E_Configure_Option *co;
@ -204,26 +210,18 @@ e_modapi_init(E_Module *m)
} }
if (!notification_cfg) if (!notification_cfg)
{ notification_cfg = _notification_cfg_new();
notification_cfg = _notification_cfg_new();
}
/* set up the notification daemon */ /* set up the notification daemon */
e_notification_daemon_init(); if (!e_notification_start(_notification_cb_notify,
d = e_notification_daemon_add("e_notification_module", "Enlightenment"); _notification_cb_close,
if (!d) &server_info, notification_cfg))
{ {
_notification_cfg_free(notification_cfg);
notification_cfg = NULL;
e_util_dialog_show(_("Error During DBus Init!"), e_util_dialog_show(_("Error During DBus Init!"),
_("Error during DBus init! Please check if " _("Error during DBus init! Please check if "
"dbus is correctly installed and running.")); "dbus is correctly installed and running."));
return NULL; return NULL;
} }
notification_cfg->daemon = d;
e_notification_daemon_data_set(d, notification_cfg);
e_notification_daemon_callback_notify_set(d, _notification_cb_notify);
e_notification_daemon_callback_close_notification_set(d, _notification_cb_close_notification);
notification_cfg->last_config_mode.presentation = e_config->mode.presentation; notification_cfg->last_config_mode.presentation = e_config->mode.presentation;
notification_cfg->last_config_mode.offline = e_config->mode.offline; notification_cfg->last_config_mode.offline = e_config->mode.offline;
@ -272,9 +270,9 @@ e_modapi_shutdown(E_Module *m __UNUSED__)
e_configure_registry_category_del("extensions"); e_configure_registry_category_del("extensions");
notification_popup_shutdown(); notification_popup_shutdown();
e_notification_stop();
e_notification_daemon_free(notification_cfg->daemon);
e_notification_daemon_shutdown();
E_CONFIGURE_OPTION_LIST_CLEAR(cfg_opts); E_CONFIGURE_OPTION_LIST_CLEAR(cfg_opts);
e_configure_option_category_tag_del(_("screen"), _("notification")); e_configure_option_category_tag_del(_("screen"), _("notification"));
e_configure_option_category_tag_del(_("notification"), _("notification")); e_configure_option_category_tag_del(_("notification"), _("notification"));
@ -291,21 +289,6 @@ e_modapi_save(E_Module *m __UNUSED__)
return e_config_domain_save("module.notification", conf_edd, notification_cfg); return e_config_domain_save("module.notification", conf_edd, notification_cfg);
} }
/* Callbacks */
static int
_notification_cb_notify(E_Notification_Daemon *d __UNUSED__,
E_Notification *n)
{
return _notification_notify(n);
}
static void
_notification_cb_close_notification(E_Notification_Daemon *d __UNUSED__,
unsigned int id)
{
notification_popup_close(id);
}
static Config * static Config *
_notification_cfg_new(void) _notification_cfg_new(void)
{ {
@ -331,4 +314,3 @@ _notification_cfg_free(Config *cfg)
{ {
free(cfg); free(cfg);
} }

View File

@ -2,7 +2,6 @@
#define E_MOD_MAIN_H #define E_MOD_MAIN_H
#include "e.h" #include "e.h"
#include <E_Notification_Daemon.h>
/* Increment for Major Changes */ /* Increment for Major Changes */
#define MOD_CONFIG_FILE_EPOCH 1 #define MOD_CONFIG_FILE_EPOCH 1
@ -44,15 +43,15 @@ struct _Config
Ecore_Event_Handler *handler; Ecore_Event_Handler *handler;
Eina_List *popups; Eina_List *popups;
int next_id; unsigned int next_id;
Ecore_Timer *initial_mode_timer; Ecore_Timer *initial_mode_timer;
E_Notification_Daemon *daemon;
}; };
struct _Popup_Data struct _Popup_Data
{ {
E_Notification *notif; unsigned id;
E_Notification_Notify *notif;
E_Popup *win; E_Popup *win;
Evas *e; Evas *e;
Evas_Object *theme; Evas_Object *theme;
@ -63,7 +62,7 @@ struct _Popup_Data
}; };
int notification_popup_notify(E_Notification *n, unsigned int replaces_id, const char *appname); int notification_popup_notify(E_Notification_Notify *n, unsigned int id);
void notification_popup_shutdown(void); void notification_popup_shutdown(void);
void notification_popup_close(unsigned int id); void notification_popup_close(unsigned int id);

View File

@ -1,9 +1,8 @@
#include "e_mod_main.h" #include "e_mod_main.h"
/* Popup function protos */ /* Popup function protos */
static Popup_Data *_notification_popup_new(E_Notification *n); static Popup_Data *_notification_popup_new(E_Notification_Notify *n, unsigned id);
static Popup_Data *_notification_popup_find(unsigned int id); static Popup_Data *_notification_popup_find(unsigned int id);
static Popup_Data *_notification_popup_merge(E_Notification *n);
static int _notification_popup_place(Popup_Data *popup, static int _notification_popup_place(Popup_Data *popup,
int num); int num);
@ -24,58 +23,52 @@ static int next_pos = 0;
static Eina_Bool static Eina_Bool
_notification_timer_cb(Popup_Data *popup) _notification_timer_cb(Popup_Data *popup)
{ {
_notification_popup_del(e_notification_id_get(popup->notif), _notification_popup_del(popup->id, E_NOTIFICATION_CLOSED_REASON_EXPIRED);
E_NOTIFICATION_CLOSED_EXPIRED);
return EINA_FALSE; return EINA_FALSE;
} }
int int
notification_popup_notify(E_Notification *n, notification_popup_notify(E_Notification_Notify *n,
unsigned int replaces_id, unsigned int id)
const char *appname __UNUSED__)
{ {
double timeout;
Popup_Data *popup = NULL; Popup_Data *popup = NULL;
char urgency;
urgency = e_notification_hint_urgency_get(n); switch (n->urgency)
switch (urgency)
{ {
case E_NOTIFICATION_URGENCY_LOW: case E_NOTIFICATION_NOTIFY_URGENCY_LOW:
if (!notification_cfg->show_low) return 0; if (!notification_cfg->show_low) return 0;
break; break;
case E_NOTIFICATION_URGENCY_NORMAL: case E_NOTIFICATION_NOTIFY_URGENCY_NORMAL:
if (!notification_cfg->show_normal) return 0; if (!notification_cfg->show_normal) return 0;
break; break;
case E_NOTIFICATION_URGENCY_CRITICAL: case E_NOTIFICATION_NOTIFY_URGENCY_CRITICAL:
if (!notification_cfg->show_critical) return 0; if (!notification_cfg->show_critical) return 0;
break; break;
default: default:
break; break;
} }
if (notification_cfg->ignore_replacement)
n->replaces_id = 0;
if (notification_cfg->ignore_replacement) replaces_id = 0; if (n->replaces_id && (popup = _notification_popup_find(n->replaces_id)))
if (replaces_id && (popup = _notification_popup_find(replaces_id)))
{ {
e_notification_ref(n);
if (popup->notif) if (popup->notif)
e_notification_unref(popup->notif); e_notification_notify_free(popup->notif);
popup->notif = n; popup->notif = n;
popup->id = id;
_notification_popup_refresh(popup); _notification_popup_refresh(popup);
} }
else if (!replaces_id)
{
if ((popup = _notification_popup_merge(n)))
_notification_popup_refresh(popup);
}
if (!popup) if (!popup)
{ {
popup = _notification_popup_new(n); popup = _notification_popup_new(n, id);
if (!popup) return 0; if (!popup)
{
e_notification_notify_free(n);
ERR("Error creating popup");
return 0;
}
notification_cfg->popups = eina_list_append(notification_cfg->popups, popup); notification_cfg->popups = eina_list_append(notification_cfg->popups, popup);
edje_object_signal_emit(popup->theme, "notification,new", "notification"); edje_object_signal_emit(popup->theme, "notification,new", "notification");
} }
@ -86,14 +79,13 @@ notification_popup_notify(E_Notification *n,
popup->timer = NULL; popup->timer = NULL;
} }
timeout = e_notification_timeout_get(popup->notif); if (n->timeout < 0 || notification_cfg->force_timeout)
n->timeout = notification_cfg->timeout;
else n->timeout = n->timeout / 1000.0;
if (timeout < 0 || notification_cfg->force_timeout)
timeout = notification_cfg->timeout;
else timeout = (double)timeout / 1000.0;
if (timeout > 0) if (n->timeout > 0)
popup->timer = ecore_timer_add(timeout, (Ecore_Task_Cb)_notification_timer_cb, popup); popup->timer = ecore_timer_add(n->timeout, (Ecore_Task_Cb)_notification_timer_cb, popup);
return 1; return 1;
} }
@ -104,99 +96,15 @@ notification_popup_shutdown(void)
Popup_Data *popup; Popup_Data *popup;
EINA_LIST_FREE(notification_cfg->popups, popup) EINA_LIST_FREE(notification_cfg->popups, popup)
_notification_popdown(popup, E_NOTIFICATION_CLOSED_REQUESTED); _notification_popdown(popup, E_NOTIFICATION_CLOSED_REASON_REQUESTED);
} }
void void
notification_popup_close(unsigned int id) notification_popup_close(unsigned int id)
{ {
_notification_popup_del(id, E_NOTIFICATION_CLOSED_REQUESTED); _notification_popup_del(id, E_NOTIFICATION_CLOSED_REASON_REQUESTED);
} }
static Popup_Data *
_notification_popup_merge(E_Notification *n)
{
Eina_List *l, *l2;
Eina_List *i, *i2;
E_Notification_Action *a, *a2;
Popup_Data *popup;
const char *str1, *str2;
const char *body_old;
const char *body_new;
char *body_final;
size_t len;
str1 = e_notification_app_name_get(n);
if (!str1) return NULL;
EINA_LIST_FOREACH(notification_cfg->popups, l, popup)
{
if (!popup->notif) continue;
if (!(str2 = e_notification_app_name_get(popup->notif)))
continue;
if (str1 == str2) break;
}
if (!popup)
{
/* printf("- no poup to merge\n"); */
return NULL;
}
str1 = e_notification_summary_get(n);
str2 = e_notification_summary_get(popup->notif);
if (str1 && str2 && (str1 != str2))
{
/* printf("- summary doesn match, %s, %s\n", str1, str2); */
return NULL;
}
l = e_notification_actions_get(popup->notif);
l2 = e_notification_actions_get(n);
if ((!!l) + (!!l2) == 1)
{
/* printf("- actions dont match\n"); */
return NULL;
}
for (i = l, i2 = l2; i && i2; i = i->next, i2 = i2->next)
{
if ((!!i) + (!!i2) == 1) return NULL;
a = i->data, a2 = i2->data;
if ((!!a) + (!!a2) == 1) return NULL;
if (e_notification_action_id_get(a) !=
e_notification_action_id_get(a2)) return NULL;
if (e_notification_action_name_get(a) !=
e_notification_action_name_get(a2)) return NULL;
}
/* TODO p->n is not fallback alert..*/
/* TODO both allow merging */
body_old = e_notification_body_get(popup->notif);
body_new = e_notification_body_get(n);
len = strlen(body_old);
len += strlen(body_new);
len += 5; /* \xE2\x80\xA9 or <PS/> */
if (len < 65536) body_final = alloca(len + 1);
else body_final = malloc(len + 1);
/* Hack to allow e to include markup */
snprintf(body_final, len + 1, "%s<ps/>%s", body_old, body_new);
/* printf("set body %s\n", body_final); */
e_notification_body_set(n, body_final);
e_notification_unref(popup->notif);
popup->notif = n;
e_notification_ref(popup->notif);
if (len >= 65536) free(body_final);
return popup;
}
static void static void
_notification_theme_cb_deleted(Popup_Data *popup, _notification_theme_cb_deleted(Popup_Data *popup,
Evas_Object *obj __UNUSED__, Evas_Object *obj __UNUSED__,
@ -213,8 +121,7 @@ _notification_theme_cb_close(Popup_Data *popup,
const char *emission __UNUSED__, const char *emission __UNUSED__,
const char *source __UNUSED__) const char *source __UNUSED__)
{ {
_notification_popup_del(e_notification_id_get(popup->notif), _notification_popup_del(popup->id, E_NOTIFICATION_CLOSED_REASON_DISMISSED);
E_NOTIFICATION_CLOSED_DISMISSED);
} }
static void static void
@ -251,7 +158,7 @@ _notification_theme_cb_find(Popup_Data *popup,
} }
static Popup_Data * static Popup_Data *
_notification_popup_new(E_Notification *n) _notification_popup_new(E_Notification_Notify *n, unsigned id)
{ {
E_Container *con; E_Container *con;
Popup_Data *popup; Popup_Data *popup;
@ -260,11 +167,11 @@ _notification_popup_new(E_Notification *n)
E_Screen *scr; E_Screen *scr;
E_Zone *zone = NULL; E_Zone *zone = NULL;
if (popups_displayed > POPUP_LIMIT) return 0; EINA_SAFETY_ON_TRUE_RETURN_VAL(popups_displayed > POPUP_LIMIT, NULL);
popup = E_NEW(Popup_Data, 1); popup = E_NEW(Popup_Data, 1);
if (!popup) return NULL; EINA_SAFETY_ON_NULL_RETURN_VAL(popup, NULL);
e_notification_ref(n);
popup->notif = n; popup->notif = n;
popup->id = id;
con = e_container_current_get(e_manager_current_get()); con = e_container_current_get(e_manager_current_get());
screens = e_xinerama_screens_get(); screens = e_xinerama_screens_get();
@ -326,7 +233,6 @@ _notification_popup_new(E_Notification *n)
return popup; return popup;
error: error:
free(popup); free(popup);
e_notification_unref(n);
return NULL; return NULL;
} }
@ -379,9 +285,7 @@ _notification_popups_place(void)
int pos = 0; int pos = 0;
EINA_LIST_FOREACH(notification_cfg->popups, l, popup) EINA_LIST_FOREACH(notification_cfg->popups, l, popup)
{ pos = _notification_popup_place(popup, pos);
pos = _notification_popup_place(popup, pos);
}
next_pos = pos; next_pos = pos;
} }
@ -391,12 +295,11 @@ _notification_popup_refresh(Popup_Data *popup)
{ {
const char *icon_path; const char *icon_path;
const char *app_icon_max; const char *app_icon_max;
void *img;
int w, h, width = 80, height = 80; int w, h, width = 80, height = 80;
if (!popup) return; if (!popup) return;
popup->app_name = e_notification_app_name_get(popup->notif); popup->app_name = popup->notif->app_name;
if (popup->app_icon) if (popup->app_icon)
{ {
@ -429,12 +332,11 @@ _notification_popup_refresh(Popup_Data *popup)
} }
/* Check if the app specify an icon either by a path or by a hint */ /* Check if the app specify an icon either by a path or by a hint */
img = e_notification_hint_image_data_get(popup->notif); if (!popup->notif->icon.raw.data)
if (!img)
{ {
icon_path = e_notification_hint_image_path_get(popup->notif); icon_path = popup->notif->icon.icon_path;
if ((!icon_path) || (!icon_path[0])) if ((!icon_path) || (!icon_path[0]))
icon_path = e_notification_app_icon_get(popup->notif); icon_path = popup->notif->icon.icon;
if (icon_path) if (icon_path)
{ {
if (!strncmp(icon_path, "file://", 7)) icon_path += 7; if (!strncmp(icon_path, "file://", 7)) icon_path += 7;
@ -451,7 +353,8 @@ _notification_popup_refresh(Popup_Data *popup)
else else
{ {
Evas_Object *o = e_icon_add(popup->e); Evas_Object *o = e_icon_add(popup->e);
if (!e_util_icon_theme_set(o, icon_path)) evas_object_del(o); if (!e_util_icon_theme_set(o, icon_path))
evas_object_del(o);
else else
{ {
popup->app_icon = o; popup->app_icon = o;
@ -473,11 +376,9 @@ _notification_popup_refresh(Popup_Data *popup)
} }
} }
} }
if ((!img) && (!popup->app_icon)) else
img = e_notification_hint_icon_data_get(popup->notif);
if (img)
{ {
popup->app_icon = e_notification_image_evas_object_add(popup->e, img); popup->app_icon = e_notification_raw_image_get(popup->e, popup->notif);
evas_object_image_filled_set(popup->app_icon, EINA_TRUE); evas_object_image_filled_set(popup->app_icon, EINA_TRUE);
evas_object_image_alpha_set(popup->app_icon, EINA_TRUE); evas_object_image_alpha_set(popup->app_icon, EINA_TRUE);
evas_object_image_size_get(popup->app_icon, &w, &h); evas_object_image_size_get(popup->app_icon, &w, &h);
@ -539,9 +440,8 @@ _notification_popup_find(unsigned int id)
if (!id) return NULL; if (!id) return NULL;
EINA_LIST_FOREACH(notification_cfg->popups, l, popup) EINA_LIST_FOREACH(notification_cfg->popups, l, popup)
{ if (popup->id == id)
if (e_notification_id_get(popup->notif) == id) return popup; return popup;
}
return NULL; return NULL;
} }
@ -555,7 +455,7 @@ _notification_popup_del(unsigned int id,
EINA_LIST_FOREACH_SAFE(notification_cfg->popups, l, l2, popup) EINA_LIST_FOREACH_SAFE(notification_cfg->popups, l, l2, popup)
{ {
if (e_notification_id_get(popup->notif) == id) if (popup->id == id)
{ {
_notification_popdown(popup, reason); _notification_popdown(popup, reason);
notification_cfg->popups = eina_list_remove_list(notification_cfg->popups, l); notification_cfg->popups = eina_list_remove_list(notification_cfg->popups, l);
@ -577,10 +477,8 @@ _notification_popdown(Popup_Data *popup,
evas_object_del(popup->app_icon); evas_object_del(popup->app_icon);
evas_object_del(popup->theme); evas_object_del(popup->theme);
e_object_del(E_OBJECT(popup->win)); e_object_del(E_OBJECT(popup->win));
e_notification_closed_set(popup->notif, 1); e_notification_notification_closed(popup->id, reason);
e_notification_daemon_signal_notification_closed e_notification_notify_free(popup->notif);
(notification_cfg->daemon, e_notification_id_get(popup->notif), reason);
e_notification_unref(popup->notif);
free(popup); free(popup);
} }
@ -588,19 +486,15 @@ static void
_notification_format_message(Popup_Data *popup) _notification_format_message(Popup_Data *popup)
{ {
Evas_Object *o = popup->theme; Evas_Object *o = popup->theme;
const char *title = e_notification_summary_get(popup->notif); Eina_Strbuf *buf = eina_strbuf_new();
const char *b = e_notification_body_get(popup->notif); edje_object_part_text_set(o, "notification.text.title",
edje_object_part_text_set(o, "notification.text.title", title); popup->notif->sumary);
/* FIXME: Filter to only include allowed markup? */ /* FIXME: Filter to only include allowed markup? */
{ /* We need to replace \n with <br>. FIXME: We need to handle all the
/* We need to replace \n with <br>. FIXME: We need to handle all the * newline kinds, and paragraph separator. ATM this will suffice. */
* newline kinds, and paragraph separator. ATM this will suffice. */ eina_strbuf_append(buf, popup->notif->body);
Eina_Strbuf *buf = eina_strbuf_new(); eina_strbuf_replace_all(buf, "\n", "<br/>");
eina_strbuf_append(buf, b); edje_object_part_text_set(o, "notification.textblock.message",
eina_strbuf_replace_all(buf, "\n", "<br/>"); eina_strbuf_string_get(buf));
edje_object_part_text_set(o, "notification.textblock.message", eina_strbuf_free(buf);
eina_strbuf_string_get(buf));
eina_strbuf_free(buf);
}
} }