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,
13 /* (con|de)structor */
16 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)
20 n = e_notification_new();
23 n->app_name = eina_stringshare_add(app_name);
24 n->replaces_id = replaces_id;
25 n->app_icon = eina_stringshare_add(app_icon);
26 n->summary = eina_stringshare_add(summary);
27 n->body = eina_stringshare_add(body);
28 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);
120 e_notification_replaces_id_set(E_Notification *note, int replaces_id)
122 note->replaces_id = replaces_id;
126 e_notification_timeout_set(E_Notification *note, int timeout)
128 note->expire_timeout = timeout;
132 e_notification_closed_set(E_Notification *note, unsigned char closed)
134 note->closed = closed;
139 e_notification_id_get(E_Notification *note)
145 e_notification_app_name_get(E_Notification *note)
147 return note->app_name;
151 e_notification_app_icon_get(E_Notification *note)
153 return note->app_icon;
157 e_notification_summary_get(E_Notification *note)
159 return note->summary;
163 e_notification_body_get(E_Notification *note)
169 e_notification_actions_get(E_Notification *note)
171 return note->actions;
175 e_notification_replaces_id_get(E_Notification *note)
177 return note->replaces_id;
181 e_notification_timeout_get(E_Notification *note)
183 return note->expire_timeout;
187 e_notification_closed_get(E_Notification *note)
192 /***** actions *****/
195 e_notification_action_list_new()
203 static E_Notification_Action *
204 e_notification_action_new(const char *id, const char *name)
206 E_Notification_Action *act;
207 act = malloc(sizeof(E_Notification_Action));
208 act->id = eina_stringshare_add(id);
209 act->name = eina_stringshare_add(name);
214 e_notification_action_id_get(E_Notification_Action *a)
216 EINA_SAFETY_ON_NULL_RETURN_VAL(a, NULL);
221 e_notification_action_name_get(E_Notification_Action *a)
223 EINA_SAFETY_ON_NULL_RETURN_VAL(a, NULL);
227 /********* hints *******/
229 e_notification_hint_transient_set(E_Notification *n, Eina_Bool transient)
232 n->hint_flags |= E_NOTIFICATION_HINT_TRANSIENT;
234 n->hint_flags ^= E_NOTIFICATION_HINT_TRANSIENT;
238 e_notification_hint_resident_set(E_Notification *n, Eina_Bool resident)
241 n->hint_flags |= E_NOTIFICATION_HINT_RESIDENT;
243 n->hint_flags ^= E_NOTIFICATION_HINT_RESIDENT;
247 e_notification_hint_action_icons_set(E_Notification *n, Eina_Bool action_icons)
250 n->hint_flags |= E_NOTIFICATION_HINT_ACTION_ICONS;
252 n->hint_flags ^= E_NOTIFICATION_HINT_ACTION_ICONS;
256 e_notification_hint_urgency_set(E_Notification *n, char urgency)
258 n->hints.urgency = urgency;
259 n->hint_flags |= E_NOTIFICATION_HINT_URGENCY;
263 e_notification_hint_image_path_set(E_Notification *n, const char *path)
265 eina_stringshare_replace(&n->hints.image_path, path);
269 e_notification_hint_category_set(E_Notification *n, const char *category)
271 eina_stringshare_replace(&n->hints.category, category);
272 n->hint_flags |= E_NOTIFICATION_HINT_CATEGORY;
276 e_notification_hint_desktop_set(E_Notification *n, const char *desktop)
278 eina_stringshare_replace(&n->hints.desktop, desktop);
279 n->hint_flags |= E_NOTIFICATION_HINT_DESKTOP;
283 e_notification_hint_sound_file_set(E_Notification *n, const char *sound_file)
285 eina_stringshare_replace(&n->hints.sound_file, sound_file);
286 n->hint_flags |= E_NOTIFICATION_HINT_SOUND_FILE;
290 e_notification_hint_suppress_sound_set(E_Notification *n, char suppress_sound)
292 n->hints.suppress_sound = suppress_sound;
293 n->hint_flags |= E_NOTIFICATION_HINT_SUPPRESS_SOUND;
297 e_notification_hint_xy_set(E_Notification *n, int x, int y)
301 n->hint_flags |= E_NOTIFICATION_HINT_XY;
305 e_notification_hint_image_data_set(E_Notification *n, E_Notification_Image *image)
307 n->hints.image_data = image;
311 e_notification_hint_urgency_get(E_Notification *n)
313 return n->hint_flags & E_NOTIFICATION_HINT_URGENCY ? n->hints.urgency : 1;
317 e_notification_hint_category_get(E_Notification *n)
319 return n->hints.category;
323 e_notification_hint_desktop_get(E_Notification *n)
325 return n->hints.desktop;
329 e_notification_hint_image_path_get(E_Notification *n)
331 return n->hints.image_path;
335 e_notification_hint_sound_file_get(E_Notification *n)
337 return n->hints.sound_file;
341 e_notification_hint_suppress_sound_get(E_Notification *n)
343 return n->hints.suppress_sound;
347 e_notification_hint_xy_get(E_Notification *n, int *x, int *y)
349 if (x) *x = n->hints.x;
350 if (y) *y = n->hints.y;
352 return n->hint_flags & E_NOTIFICATION_HINT_XY ? 1 : 0;
355 EAPI E_Notification_Image *
356 e_notification_hint_image_data_get(E_Notification *n)
358 return n->hints.image_data;
361 EAPI E_Notification_Image *
362 e_notification_hint_icon_data_get(E_Notification *n)
364 return n->hints.icon_data;
367 EAPI E_Notification_Image *
368 e_notification_image_new()
370 E_Notification_Image *img;
372 img = calloc(1, sizeof(E_Notification_Image));
377 e_notification_image_free(E_Notification_Image *img)
379 if (img->data) free(img->data);
384 e_notification_image_evas_object_add(Evas *evas, E_Notification_Image *img)
387 Evas_Object *o = NULL;
389 if (!evas || !img) return NULL;
391 o = evas_object_image_add(evas);
392 evas_object_resize(o, img->width, img->height);
393 evas_object_image_alpha_set(o, img->has_alpha);
394 evas_object_image_size_set(o, img->width, img->height);
395 evas_object_image_fill_set(o, 0, 0, img->width, img->height);
396 imgdata = evas_object_image_data_get(o, 1);
398 if (img->bits_per_sample == 8)
400 /* Although not specified.
401 * The data are very likely to come from a GdkPixbuf
402 * which align each row on a 4-bytes boundary when using RGB.
403 * And is RGBA otherwise.
408 for (y = 0; y < img->height; y++)
410 src = img->data + y * img->rowstride;
411 dest = imgdata + y * img->width;
413 for (x = 0; x < img->width; x++, src += img->channels, dest++)
417 *dest = (*(src + 2) * *(src + 3) / 255);
418 *dest += (*(src + 1) * *(src + 3) / 255) << 8;
419 *dest += (*(src + 0) * *(src + 3) / 255) << 16;
420 *dest += *(src + 3) << 24;
425 *dest += *(src + 1) << 8;
426 *dest += *(src + 0) << 16;