6 #include "e_notify_private.h"
8 /* private functions */
9 static Eina_List *e_notification_action_list_new(void);
10 static E_Notification_Action *e_notification_action_new(const char *id,
13 int _e_dbus_notify_log_dom = -1;
18 if (_e_dbus_notify_log_dom == -1)
19 _e_dbus_notify_log_dom = eina_log_domain_register("e_dbus_notify", E_DBUS_COLOR_DEFAULT);
22 /* (con|de)structor */
25 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)
30 n = e_notification_new();
33 n->app_name = eina_stringshare_add(app_name);
34 n->replaces_id = replaces_id;
35 n->app_icon = eina_stringshare_add(app_icon);
36 n->summary = eina_stringshare_add(summary);
37 n->body = eina_stringshare_add(body);
38 n->expire_timeout = expire_timeout;
39 n->hints.x = n->hints.y = -1;
45 e_notification_new(void)
50 n = calloc(1, sizeof(E_Notification));
58 e_notification_ref(E_Notification *n)
65 e_notification_unref(E_Notification *n)
68 if (--n->refcount == 0) e_notification_free(n);
72 e_notification_free(E_Notification *n)
77 eina_stringshare_del(n->app_name);
78 eina_stringshare_del(n->app_icon);
79 eina_stringshare_del(n->summary);
80 eina_stringshare_del(n->body);
82 eina_list_free(n->actions);
84 eina_stringshare_del(n->hints.category);
85 eina_stringshare_del(n->hints.desktop);
86 eina_stringshare_del(n->hints.sound_file);
87 if (n->hints.image_data) e_notification_image_free(n->hints.image_data);
88 if (n->hints.icon_data) e_notification_image_free(n->hints.icon_data);
94 e_notification_id_set(E_Notification *note, unsigned int id)
101 e_notification_app_name_set(E_Notification *note, const char *app_name)
104 eina_stringshare_replace(¬e->app_name, app_name);
108 e_notification_app_icon_set(E_Notification *note, const char *app_icon)
111 eina_stringshare_replace(¬e->app_icon, app_icon);
115 e_notification_summary_set(E_Notification *note, const char *summary)
118 eina_stringshare_replace(¬e->summary, summary);
122 e_notification_body_set(E_Notification *note, const char *body)
125 eina_stringshare_replace(¬e->body, body);
129 e_notification_action_add(E_Notification *n, const char *action_id, const char *action_name)
131 E_Notification_Action *a;
135 n->actions = e_notification_action_list_new();
137 a = e_notification_action_new(action_id, action_name);
138 n->actions = eina_list_append(n->actions, a);
142 e_notification_replaces_id_set(E_Notification *note, int replaces_id)
145 note->replaces_id = replaces_id;
149 e_notification_timeout_set(E_Notification *note, int timeout)
152 note->expire_timeout = timeout;
156 e_notification_closed_set(E_Notification *note, unsigned char closed)
159 note->closed = closed;
164 e_notification_id_get(E_Notification *note)
171 e_notification_app_name_get(E_Notification *note)
174 return note->app_name;
178 e_notification_app_icon_get(E_Notification *note)
181 return note->app_icon;
185 e_notification_summary_get(E_Notification *note)
188 return note->summary;
192 e_notification_body_get(E_Notification *note)
199 e_notification_actions_get(E_Notification *note)
202 return note->actions;
206 e_notification_replaces_id_get(E_Notification *note)
209 return note->replaces_id;
213 e_notification_timeout_get(E_Notification *note)
216 return note->expire_timeout;
220 e_notification_closed_get(E_Notification *note)
226 /***** actions *****/
229 e_notification_action_list_new(void)
238 static E_Notification_Action *
239 e_notification_action_new(const char *id, const char *name)
241 E_Notification_Action *act;
244 act = malloc(sizeof(E_Notification_Action));
245 act->id = eina_stringshare_add(id);
246 act->name = eina_stringshare_add(name);
251 e_notification_action_id_get(E_Notification_Action *a)
254 EINA_SAFETY_ON_NULL_RETURN_VAL(a, NULL);
259 e_notification_action_name_get(E_Notification_Action *a)
262 EINA_SAFETY_ON_NULL_RETURN_VAL(a, NULL);
266 /********* hints *******/
268 e_notification_hint_transient_set(E_Notification *n, Eina_Bool transient)
272 n->hint_flags |= E_NOTIFICATION_HINT_TRANSIENT;
274 n->hint_flags ^= E_NOTIFICATION_HINT_TRANSIENT;
278 e_notification_hint_resident_set(E_Notification *n, Eina_Bool resident)
282 n->hint_flags |= E_NOTIFICATION_HINT_RESIDENT;
284 n->hint_flags ^= E_NOTIFICATION_HINT_RESIDENT;
288 e_notification_hint_action_icons_set(E_Notification *n, Eina_Bool action_icons)
292 n->hint_flags |= E_NOTIFICATION_HINT_ACTION_ICONS;
294 n->hint_flags ^= E_NOTIFICATION_HINT_ACTION_ICONS;
298 e_notification_hint_urgency_set(E_Notification *n, char urgency)
301 n->hints.urgency = urgency;
302 n->hint_flags |= E_NOTIFICATION_HINT_URGENCY;
306 e_notification_hint_image_path_set(E_Notification *n, const char *path)
309 eina_stringshare_replace(&n->hints.image_path, path);
313 e_notification_hint_category_set(E_Notification *n, const char *category)
316 eina_stringshare_replace(&n->hints.category, category);
317 n->hint_flags |= E_NOTIFICATION_HINT_CATEGORY;
321 e_notification_hint_desktop_set(E_Notification *n, const char *desktop)
324 eina_stringshare_replace(&n->hints.desktop, desktop);
325 n->hint_flags |= E_NOTIFICATION_HINT_DESKTOP;
329 e_notification_hint_sound_file_set(E_Notification *n, const char *sound_file)
332 eina_stringshare_replace(&n->hints.sound_file, sound_file);
333 n->hint_flags |= E_NOTIFICATION_HINT_SOUND_FILE;
337 e_notification_hint_suppress_sound_set(E_Notification *n, char suppress_sound)
340 n->hints.suppress_sound = suppress_sound;
341 n->hint_flags |= E_NOTIFICATION_HINT_SUPPRESS_SOUND;
345 e_notification_hint_xy_set(E_Notification *n, int x, int y)
350 n->hint_flags |= E_NOTIFICATION_HINT_XY;
354 e_notification_hint_image_data_set(E_Notification *n, E_Notification_Image *image)
357 n->hints.image_data = image;
361 e_notification_hint_urgency_get(E_Notification *n)
364 return n->hint_flags & E_NOTIFICATION_HINT_URGENCY ? n->hints.urgency : 1;
368 e_notification_hint_category_get(E_Notification *n)
371 return n->hints.category;
375 e_notification_hint_desktop_get(E_Notification *n)
378 return n->hints.desktop;
382 e_notification_hint_image_path_get(E_Notification *n)
385 return n->hints.image_path;
389 e_notification_hint_sound_file_get(E_Notification *n)
392 return n->hints.sound_file;
396 e_notification_hint_suppress_sound_get(E_Notification *n)
399 return n->hints.suppress_sound;
403 e_notification_hint_xy_get(E_Notification *n, int *x, int *y)
406 if (x) *x = n->hints.x;
407 if (y) *y = n->hints.y;
409 return n->hint_flags & E_NOTIFICATION_HINT_XY ? 1 : 0;
412 EAPI E_Notification_Image *
413 e_notification_hint_image_data_get(E_Notification *n)
416 return n->hints.image_data;
419 EAPI E_Notification_Image *
420 e_notification_hint_icon_data_get(E_Notification *n)
423 return n->hints.icon_data;
426 EAPI E_Notification_Image *
427 e_notification_image_new(void)
429 E_Notification_Image *img;
432 img = calloc(1, sizeof(E_Notification_Image));
433 img->bits_per_sample = 8;
438 e_notification_image_init(E_Notification_Image *img, Evas_Object *obj)
440 int x, y, w = 0, h = 0;
441 unsigned char *d, *imgdata;
446 EINA_SAFETY_ON_NULL_RETURN_VAL(img, EINA_FALSE);
447 EINA_SAFETY_ON_NULL_RETURN_VAL(obj, EINA_FALSE);
449 evas_object_image_size_get(obj, &w, &h);
450 if ((w <= 0) || (h <= 0)) return EINA_FALSE;
451 imgdata = evas_object_image_data_get(obj, EINA_FALSE);
452 if (!imgdata) return EINA_FALSE;
454 img->data = malloc(4 * w * h);
457 evas_object_image_data_set(obj, imgdata);
461 img->rowstride = 4 * w;
464 img->bits_per_sample = 8;
465 img->has_alpha = EINA_TRUE;
467 rowstride = evas_object_image_stride_get(obj);
468 for (y = 0; y < img->height; y++)
470 s = (int *)(imgdata + (y * rowstride));
471 d = img->data + (y * img->rowstride);
473 for (x = 0; x < img->width; x++, s++)
475 *d++ = (*s >> 16) & 0xff;
476 *d++ = (*s >> 8) & 0xff;
478 *d++ = (*s >> 24) & 0xff;
482 evas_object_image_data_set(obj, imgdata);
487 e_notification_image_free(E_Notification_Image *img)
496 _e_notification_image_evas_object_fill(E_Notification_Image *img, Evas_Object *obj)
498 unsigned char *imgdata;
500 EINA_SAFETY_ON_NULL_RETURN_VAL(img, EINA_FALSE);
501 EINA_SAFETY_ON_NULL_RETURN_VAL(obj, EINA_FALSE);
503 evas_object_image_colorspace_set(obj, EVAS_COLORSPACE_ARGB8888);
504 evas_object_image_alpha_set(obj, img->has_alpha);
505 evas_object_image_size_set(obj, img->width, img->height);
507 imgdata = evas_object_image_data_get(obj, EINA_TRUE);
508 if (!imgdata) return EINA_FALSE;
510 if (img->bits_per_sample == 8)
512 /* Although not specified.
513 * The data are very likely to come from a GdkPixbuf
514 * which align each row on a 4-bytes boundary when using RGB.
515 * And is RGBA otherwise. */
520 rowstride = evas_object_image_stride_get(obj);
521 for (y = 0; y < img->height; y++)
523 s = img->data + (y * img->rowstride);
524 d = (int *)(imgdata + (y * rowstride));
526 for (x = 0; x < img->width; x++, s += img->channels, d++)
529 *d = (s[3] << 24) | (s[0] << 16) | (s[1] << 8) | (s[2]);
531 *d = (0xff << 24) | (s[0] << 16) | (s[1] << 8) | (s[2]);
535 evas_object_image_data_update_add(obj, 0, 0, img->width, img->height);
536 evas_object_image_data_set(obj, imgdata);
542 e_notification_image_evas_object_add(Evas *evas, E_Notification_Image *img)
544 Evas_Object *o = NULL;
547 if ((!evas) || (!img)) return NULL;
548 o = evas_object_image_filled_add(evas);
549 evas_object_resize(o, img->width, img->height);
550 if (!_e_notification_image_evas_object_fill(img, o))