#include <notification_internal.h>
#define SERVICE_NAME "notification-display"
+#define HIDE_TIME 3.0
SET_TAG(SERVICE_NAME)
-void _dbg_notification(notification_h noti)
+struct _priv {
+ Evas_Object *win;
+ Evas_Object *popup;
+};
+
+static void _timeout(void *data, Evas_Object *obj, void *event_info)
+{
+ evas_object_hide(data);
+}
+
+void _show_notification(struct _priv *priv, notification_h noti)
{
- char *pkgname = NULL;
char *title = NULL;
char *content = NULL;
- char *image_path = NULL;
- notification_get_pkgname(noti, &pkgname);
notification_get_text(noti, NOTIFICATION_TEXT_TYPE_TITLE, &title);
notification_get_text(noti, NOTIFICATION_TEXT_TYPE_CONTENT, &content);
- notification_get_image(noti, NOTIFICATION_IMAGE_TYPE_ICON, &image_path);
- _DBG("\nNew Notification : %s", title);
- _DBG("Icon : %s", image_path);
- _DBG("Message : %s", content);
+ elm_object_text_set(priv->popup, content);
+ elm_object_part_text_set(priv->popup, "title,text", title);
+ evas_object_show(priv->popup);
+ evas_object_show(priv->win);
}
void _notification_changed_cb(void *data, notification_type_e notif_type)
{
+ struct _priv *priv;
+
notification_h noti = NULL;
- notification_list_h noti_list = NULL, get_list;
+ notification_list_h noti_list = NULL;
+
+ if (!data) {
+ _ERR("failed to get data");
+ return;
+ }
+ priv = data;
notification_get_list(NOTIFICATION_TYPE_NOTI, -1, ¬i_list);
- get_list = notification_list_get_tail(noti_list);
- if (get_list) {
- noti = notification_list_get_data(get_list);
- _dbg_notification(noti);
+ if (noti_list) {
+ noti = notification_list_get_data(noti_list);
+ if (noti)
+ _show_notification(priv, noti);
}
notification_free_list(noti_list);
}
+int _create_popup(struct _priv *priv)
+{
+ priv->win = elm_win_add(NULL, "popup", ELM_WIN_BASIC);
+ if (!priv->win) {
+ _ERR("elm_win_add failed");
+ return -1;
+ }
+ elm_win_autodel_set(priv->win, EINA_TRUE);
+ elm_win_alpha_set(priv->win, EINA_TRUE);
+
+ priv->popup = elm_popup_add(priv->win);
+ if (!priv->popup) {
+ evas_object_del(priv->win);
+ _ERR("elm_win_add failed");
+ return -1;
+ }
+ elm_popup_timeout_set(priv->popup, HIDE_TIME);
+ elm_popup_orient_set(priv->popup, ELM_POPUP_ORIENT_BOTTOM_RIGHT);
+ evas_object_smart_callback_add(priv->popup, "timeout",
+ _timeout, priv->win);
+
+ return 0;
+}
+
+void _destroy_popup(struct _priv *priv)
+{
+ evas_object_del(priv->popup);
+ evas_object_del(priv->win);
+}
+
int main(int argc, char **argv)
{
+ struct _priv *priv;
notification_error_e error_n;
elm_init(0, NULL);
+ priv = calloc(1, sizeof(*priv));
+ if (!priv) {
+ _ERR("failed to allocate priv");
+ return 0;
+ }
+
+ if (_create_popup(priv) < 0) {
+ _ERR("failed to create popup");
+ free(priv);
+ return 0;
+ }
+
error_n = NOTIFICATION_ERROR_SERVICE_NOT_READY;
while (error_n != NOTIFICATION_ERROR_NONE) {
error_n = notification_resister_changed_cb(
- _notification_changed_cb, NULL);
+ _notification_changed_cb, priv);
_DBG("Could not register with notifications server");
sleep(5);
}
elm_run();
+ _destroy_popup(priv);
+ free(priv);
+
elm_shutdown();
return 0;