6 #include "e_notify_private.h"
8 /* private functions */
9 static Eina_List * e_notification_action_list_new();
10 static E_Notification_Action *e_notification_action_new(const char *id, const char *name);
12 /* (con|de)structor */
15 e_notification_full_new(const char *app_name, unsigned int replaces_id, const char *app_icon, const char *summary, const char *body, int expire_timeout)
19 n = e_notification_new();
22 n->app_name = eina_stringshare_add(app_name);
23 n->replaces_id = replaces_id;
24 n->app_icon = eina_stringshare_add(app_icon);
25 n->summary = eina_stringshare_add(summary);
26 n->body = eina_stringshare_add(body);
27 n->expire_timeout = expire_timeout;
37 n = calloc(1, sizeof(E_Notification));
45 e_notification_ref(E_Notification *n)
51 e_notification_unref(E_Notification *n)
53 if (--n->refcount == 0) e_notification_free(n);
57 e_notification_free(E_Notification *n)
61 eina_stringshare_del(n->app_name);
62 eina_stringshare_del(n->app_icon);
63 eina_stringshare_del(n->summary);
64 eina_stringshare_del(n->body);
66 eina_list_free(n->actions);
68 eina_stringshare_del(n->hints.category);
69 eina_stringshare_del(n->hints.desktop);
70 eina_stringshare_del(n->hints.sound_file);
71 if (n->hints.image_data) e_notification_image_free(n->hints.image_data);
72 if (n->hints.icon_data) e_notification_image_free(n->hints.icon_data);
78 e_notification_id_set(E_Notification *note, unsigned int id)
84 e_notification_app_name_set(E_Notification *note, const char *app_name)
86 eina_stringshare_replace(¬e->app_name, app_name);
90 e_notification_app_icon_set(E_Notification *note, const char *app_icon)
92 eina_stringshare_replace(¬e->app_icon, app_icon);
96 e_notification_summary_set(E_Notification *note, const char *summary)
98 eina_stringshare_replace(¬e->summary, summary);
102 e_notification_body_set(E_Notification *note, const char *body)
104 eina_stringshare_replace(¬e->body, body);
108 e_notification_action_add(E_Notification *n, const char *action_id, const char *action_name)
110 E_Notification_Action *a;
113 n->actions = e_notification_action_list_new();
115 a = e_notification_action_new(action_id, action_name);
116 n->actions = eina_list_append(n->actions, a);
121 e_notification_replaces_id_set(E_Notification *note, int replaces_id)
123 note->replaces_id = replaces_id;
127 e_notification_timeout_set(E_Notification *note, int timeout)
129 note->expire_timeout = timeout;
133 e_notification_closed_set(E_Notification *note, unsigned char closed)
135 note->closed = closed;
141 e_notification_id_get(E_Notification *note)
147 e_notification_app_name_get(E_Notification *note)
149 return note->app_name;
153 e_notification_app_icon_get(E_Notification *note)
155 return note->app_icon;
159 e_notification_summary_get(E_Notification *note)
161 return note->summary;
165 e_notification_body_get(E_Notification *note)
171 e_notification_actions_get(E_Notification *note)
173 return note->actions;
177 e_notification_replaces_id_get(E_Notification *note)
179 return note->replaces_id;
183 e_notification_timeout_get(E_Notification *note)
185 return note->expire_timeout;
189 e_notification_closed_get(E_Notification *note)
194 /***** actions *****/
197 e_notification_action_list_new()
205 static E_Notification_Action *
206 e_notification_action_new(const char *id, const char *name)
208 E_Notification_Action *act;
209 act = malloc(sizeof(E_Notification_Action));
210 act->id = eina_stringshare_add(id);
211 act->name = eina_stringshare_add(name);
216 /********* hints *******/
220 e_notification_hint_urgency_set(E_Notification *n, char urgency)
222 n->hints.urgency = urgency;
223 n->hint_flags |= E_NOTIFICATION_HINT_URGENCY;
227 e_notification_hint_category_set(E_Notification *n, const char *category)
229 eina_stringshare_replace(&n->hints.category, category);
230 n->hint_flags |= E_NOTIFICATION_HINT_CATEGORY;
234 e_notification_hint_desktop_set(E_Notification *n, const char *desktop)
236 eina_stringshare_replace(&n->hints.desktop, desktop);
237 n->hint_flags |= E_NOTIFICATION_HINT_DESKTOP;
241 e_notification_hint_sound_file_set(E_Notification *n, const char *sound_file)
243 eina_stringshare_replace(&n->hints.sound_file, sound_file);
244 n->hint_flags |= E_NOTIFICATION_HINT_SOUND_FILE;
248 e_notification_hint_suppress_sound_set(E_Notification *n, char suppress_sound)
250 n->hints.suppress_sound = suppress_sound;
251 n->hint_flags |= E_NOTIFICATION_HINT_SUPPRESS_SOUND;
255 e_notification_hint_xy_set(E_Notification *n, int x, int y)
259 n->hint_flags |= E_NOTIFICATION_HINT_XY;
263 e_notification_hint_image_data_set(E_Notification *n, E_Notification_Image *image)
265 n->hints.image_data = image;
270 e_notification_hint_urgency_get(E_Notification *n)
272 return (n->hint_flags & E_NOTIFICATION_HINT_URGENCY ? n->hints.urgency : 1);
276 e_notification_hint_category_get(E_Notification *n)
278 return n->hints.category;
282 e_notification_hint_desktop_get(E_Notification *n)
284 return n->hints.desktop;
288 e_notification_hint_sound_file_get(E_Notification *n)
290 return n->hints.sound_file;
294 e_notification_hint_suppress_sound_get(E_Notification *n)
296 return n->hints.suppress_sound;
300 e_notification_hint_xy_get(E_Notification *n, int *x, int *y)
302 if (x) *x = n->hints.x;
303 if (y) *y = n->hints.y;
305 return (n->hint_flags & E_NOTIFICATION_HINT_XY ? 1 : 0);
308 EAPI E_Notification_Image *
309 e_notification_hint_image_data_get(E_Notification *n)
311 return n->hints.image_data;
315 EAPI E_Notification_Image *
316 e_notification_hint_icon_data_get(E_Notification *n)
318 return n->hints.icon_data;
321 EAPI E_Notification_Image *
322 e_notification_image_new()
324 E_Notification_Image *img;
326 img = calloc(1, sizeof(E_Notification_Image));
331 e_notification_image_free(E_Notification_Image *img)
333 if (img->data) free(img->data);
339 e_notification_image_evas_object_add(Evas *evas, E_Notification_Image *img)
342 Evas_Object *o = NULL;
344 if (!evas || !img) return NULL;
346 o = evas_object_image_add(evas);
347 evas_object_resize(o, img->width, img->height);
348 evas_object_image_alpha_set(o, img->has_alpha);
349 evas_object_image_size_set(o, img->width, img->height);
350 evas_object_image_fill_set(o, 0, 0, img->width, img->height);
351 imgdata = evas_object_image_data_get(o, 1);
353 if (img->bits_per_sample == 8)
355 /* Although not specified.
356 * The data are very likely to come from a GdkPixbuf
357 * which align each row on a 4-bytes boundary when using RGB.
358 * And is RGBA otherwise.
363 for (y = 0; y < img->height; y++)
365 src = img->data + y * img->rowstride;
366 dest = imgdata + y * img->width;
368 for (x = 0; x < img->width; x++, src += img->channels, dest++)
372 *dest = (*(src + 2) * *(src + 3) / 255);
373 *dest += (*(src + 1) * *(src + 3) / 255) << 8;
374 *dest += (*(src + 0) * *(src + 3) / 255) << 16;
375 *dest += *(src + 3) << 24;
380 *dest += *(src + 1) << 8;
381 *dest += *(src + 0) << 16;