void daemon_note_show(Daemon_Data *d, E_Notification *n) { e_notification_ref(n); d->open_notes = eina_list_append(d->open_notes, n); e_notification_ref(n); d->history = eina_list_append(d->history, n); // adjust history if ((int) eina_list_count(d->history) > d->max_history_length) { E_Notification *old; old = eina_list_data_get(d->history); d->history = eina_list_remove_list(d->history, d->history); d->history_start = e_notification_id_get(old) + 1; e_notification_unref(old); } { int timeout; timeout = e_notification_timeout_get(n); Timer_Data *td = calloc(1, sizeof(Timer_Data)); td->d = d; e_notification_ref(n); td->n = n; ecore_timer_add(timeout == -1 ? d->default_timeout : (float)timeout / 1000, cb_note_close_timer, td); } printf("Received notification from %s:\n%s\n%s\n\n", e_notification_app_name_get(n), e_notification_summary_get(n), e_notification_body_get(n) ); }
int main() { E_Notification_Daemon *d; E_Notification *n; Daemon_Data *dd; ecore_init(); dd = calloc(1, sizeof(Daemon_Data)); dd->open_notes = NULL; dd->history = NULL; dd->next_id = dd->history_start = 1; dd->max_history_length = 5; dd->default_timeout = 5; /* set up the daemon */ d = e_notification_daemon_add("e_notification_module", "Enlightenment"); e_notification_daemon_data_set(d, dd); dd->daemon = d; e_notification_daemon_callback_notify_set(d, cb_notify); e_notification_daemon_callback_close_notification_set(d, cb_close_notification); ecore_main_loop_begin(); while (dd->open_notes) { n = eina_list_data_get(dd->open_notes); e_notification_unref(n); dd->open_notes = eina_list_remove_list(dd->open_notes, dd->open_notes); } while (dd->history) { n = eina_list_data_get(dd->history); e_notification_unref(n); dd->history = eina_list_remove_list(dd->history, dd->history); } free(dd); e_notification_daemon_free(d); ecore_shutdown(); return 0; }
Eina_Bool cb_note_close_timer(void *data) { Timer_Data *td = data; if (!e_notification_closed_get(td->n)) daemon_note_close(td->d, td->n, E_NOTIFICATION_CLOSED_EXPIRED); e_notification_unref(td->n); free(td); return ECORE_CALLBACK_CANCEL; }
void daemon_note_close(Daemon_Data *dd, E_Notification *n, int reason) { printf("Close notification #%d\n", e_notification_id_get(n)); if (eina_list_data_find(dd->open_notes, n)) { dd->open_notes = eina_list_remove(dd->open_notes, n); e_notification_closed_set(n, 1); e_notification_daemon_signal_notification_closed(dd->daemon, e_notification_id_get(n), reason); e_notification_unref(n); } }
static void _notification_show_common(const char *summary, const char *body, int replaces_id) { E_Notification *n = e_notification_full_new ("enlightenment", replaces_id, "enlightenment", summary, body, -1); if (!n) return; _notification_notify(n); e_notification_unref(n); }