8 #include <E_Notification_Daemon.h>
10 typedef struct Daemon_Data Daemon_Data;
11 typedef struct Timer_Data Timer_Data;
21 E_Notification_Daemon *daemon;
22 Eina_List *open_notes;
26 int max_history_length;
33 daemon_note_close(Daemon_Data *dd, E_Notification *n, int reason)
35 printf("Close notification #%d\n", e_notification_id_get(n));
37 if (eina_list_data_find(dd->open_notes, n))
39 dd->open_notes = eina_list_remove(dd->open_notes, n);
40 e_notification_closed_set(n, 1);
41 e_notification_daemon_signal_notification_closed(dd->daemon, e_notification_id_get(n), reason);
42 e_notification_unref(n);
47 cb_note_close_timer(void *data)
49 Timer_Data *td = data;
51 if (!e_notification_closed_get(td->n))
52 daemon_note_close(td->d, td->n, E_NOTIFICATION_CLOSED_EXPIRED);
54 e_notification_unref(td->n);
57 return ECORE_CALLBACK_CANCEL;
61 daemon_note_show(Daemon_Data *d, E_Notification *n)
63 e_notification_ref(n);
64 d->open_notes = eina_list_append(d->open_notes, n);
65 e_notification_ref(n);
66 d->history = eina_list_append(d->history, n);
69 if ((int) eina_list_count(d->history) > d->max_history_length)
72 old = eina_list_data_get(d->history);
73 d->history = eina_list_remove_list(d->history, d->history);
74 d->history_start = e_notification_id_get(old) + 1;
75 e_notification_unref(old);
81 timeout = e_notification_timeout_get(n);
82 Timer_Data *td = calloc(1, sizeof(Timer_Data));
84 e_notification_ref(n);
86 ecore_timer_add(timeout == -1 ? d->default_timeout : (float)timeout / 1000, cb_note_close_timer, td);
89 printf("Received notification from %s:\n%s\n%s\n\n",
90 e_notification_app_name_get(n),
91 e_notification_summary_get(n), e_notification_body_get(n)
96 daemon_note_open_find(Daemon_Data *d, unsigned int id)
101 EINA_LIST_FOREACH(d->open_notes, l, n)
102 if (e_notification_id_get(n) == id) return n;
108 daemon_note_history_find(Daemon_Data *d, int id)
110 if (id < d->history_start) return NULL;
120 cb_notify(E_Notification_Daemon *daemon, E_Notification *n)
123 unsigned int replaces_id;
126 dd = e_notification_daemon_data_get(daemon);
127 replaces_id = e_notification_replaces_id_get(n);
130 // close old one flagged as replaced
133 new_id = dd->next_id++;
134 e_notification_id_set(n, new_id);
136 daemon_note_show(dd, n);
142 cb_close_notification(E_Notification_Daemon *daemon, unsigned int notification_id)
146 dd = e_notification_daemon_data_get(daemon);
147 n = daemon_note_open_find(dd, notification_id);
149 daemon_note_close(dd, n, E_NOTIFICATION_CLOSED_REQUESTED);
157 E_Notification_Daemon *d;
164 dd = calloc(1, sizeof(Daemon_Data));
165 dd->open_notes = NULL;
167 dd->next_id = dd->history_start = 1;
168 dd->max_history_length = 5;
169 dd->default_timeout = 5;
171 /* set up the daemon */
172 d = e_notification_daemon_add("e_notification_module", "Enlightenment");
173 e_notification_daemon_data_set(d, dd);
175 e_notification_daemon_callback_notify_set(d, cb_notify);
176 e_notification_daemon_callback_close_notification_set(d, cb_close_notification);
178 ecore_main_loop_begin();
179 while (dd->open_notes)
181 n = eina_list_data_get(dd->open_notes);
182 e_notification_unref(n);
183 dd->open_notes = eina_list_remove_list(dd->open_notes, dd->open_notes);
187 n = eina_list_data_get(dd->history);
188 e_notification_unref(n);
189 dd->history = eina_list_remove_list(dd->history, dd->history);
192 e_notification_daemon_free(d);