From 25074f627768ed049916b8ce65e404383dc86051 Mon Sep 17 00:00:00 2001 From: Luis Felipe Strano Moraes Date: Fri, 7 Dec 2012 17:23:34 +0000 Subject: [PATCH] [elm] Handling signals on elm_sys_notify. Author: Murilo Belluzzo SVN revision: 80474 --- legacy/elementary/src/bin/test_sys_notify.c | 55 ++++++++++++- legacy/elementary/src/lib/elm_sys_notify.c | 91 +++++++++++++++++++++ legacy/elementary/src/lib/elm_sys_notify.h | 46 +++++++++++ 3 files changed, 190 insertions(+), 2 deletions(-) diff --git a/legacy/elementary/src/bin/test_sys_notify.c b/legacy/elementary/src/bin/test_sys_notify.c index 111a346441..f7a6efc122 100644 --- a/legacy/elementary/src/bin/test_sys_notify.c +++ b/legacy/elementary/src/bin/test_sys_notify.c @@ -9,11 +9,47 @@ static Evas_Object *s = NULL; static Evas_Object *b = NULL; +static Evas_Object *l = NULL; +static Evas_Object *n = NULL; + +static Eina_Bool +_ev_handler(void *data __UNUSED__, + int type, + void *event) +{ + char msg[256]; + + Elm_Sys_Notify_Notification_Closed *closed; + Elm_Sys_Notify_Action_Invoked *action; + + if (type == ELM_EVENT_SYS_NOTIFY_NOTIFICATION_CLOSED) + { + closed = event; + sprintf(msg, "Notification Closed Event: %u %d.", + closed->id, closed->reason); + } + else if (type == ELM_EVENT_SYS_NOTIFY_ACTION_INVOKED) + { + action = event; + sprintf(msg, "Notification Action Event: %u %s.", + action->id, action->action_key); + } + else + return ECORE_CALLBACK_PASS_ON; + + elm_object_text_set(l, msg); + evas_object_show(n); + + return ECORE_CALLBACK_DONE; +} static void -_bt_clicked(void *data __UNUSED__, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__) +_bt_clicked(void *data __UNUSED__, + Evas_Object *obj __UNUSED__, + void *event_info __UNUSED__) { - elm_sys_notify_simple_send("", elm_entry_entry_get(s), elm_entry_entry_get(b)); + elm_sys_notify_simple_send + ("", elm_entry_entry_get(s), elm_entry_entry_get(b)); } void @@ -25,6 +61,12 @@ test_sys_notify(void *data __UNUSED__, elm_need_sys_notify(); + ecore_event_handler_add(ELM_EVENT_SYS_NOTIFY_NOTIFICATION_CLOSED, + _ev_handler, NULL); + + ecore_event_handler_add(ELM_EVENT_SYS_NOTIFY_ACTION_INVOKED, + _ev_handler, NULL); + win = elm_win_add(NULL, "Sys Notify", ELM_WIN_BASIC); elm_policy_set(ELM_POLICY_QUIT, ELM_POLICY_QUIT_LAST_WINDOW_CLOSED); elm_win_title_set(win, "System Notification"); @@ -36,6 +78,15 @@ test_sys_notify(void *data __UNUSED__, evas_object_size_hint_max_set(it, WIDTH, HEIGHT); evas_object_show(it); + n = elm_notify_add(win); + evas_object_size_hint_weight_set(n, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND); + elm_notify_align_set(n, 0.5, 0.0); + elm_notify_timeout_set(n, 2.0); + + l = elm_label_add(win); + elm_object_content_set(n, l); + evas_object_show(l); + bx = elm_box_add(win); evas_object_size_hint_weight_set(bx, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND); elm_win_resize_object_add(win, bx); diff --git a/legacy/elementary/src/lib/elm_sys_notify.c b/legacy/elementary/src/lib/elm_sys_notify.c index 0ccb897f88..2cd0cf50e6 100644 --- a/legacy/elementary/src/lib/elm_sys_notify.c +++ b/legacy/elementary/src/lib/elm_sys_notify.c @@ -5,6 +5,9 @@ #define BUS "org.freedesktop.Notifications" #define INTERFACE "org.freedesktop.Notifications" +EAPI int ELM_EVENT_SYS_NOTIFY_NOTIFICATION_CLOSED = 0; +EAPI int ELM_EVENT_SYS_NOTIFY_ACTION_INVOKED = 0; + #ifdef ELM_EDBUS2 static Eina_Bool _elm_need_sys_notify = EINA_FALSE; @@ -212,6 +215,82 @@ error: } #ifdef ELM_EDBUS2 +static void +_on_notification_closed(void *data EINA_UNUSED, + const EDBus_Message *msg) +{ + const char *errname; + const char *errmsg; + Elm_Sys_Notify_Notification_Closed *d; + + if (edbus_message_error_get(msg, &errname, &errmsg)) + { + ERR("Edbus Error: %s %s", errname, errmsg); + return; + } + + d = malloc(sizeof(*d)); + + if (!edbus_message_arguments_get(msg, "uu", &(d->id), &(d->reason))) + { + ERR("Error processing signal: "INTERFACE".NotificationClosed."); + goto cleanup; + } + + if (!ecore_event_add(ELM_EVENT_SYS_NOTIFY_NOTIFICATION_CLOSED, d, + NULL, NULL)) goto cleanup; + + return; + +cleanup: + free(d); +} + +static void +_ev_action_invoked_free(void *data EINA_UNUSED, + void *ev_data) +{ + Elm_Sys_Notify_Action_Invoked *d = ev_data; + + free(d->action_key); + free(d); +} + +static void +_on_action_invoked(void *data EINA_UNUSED, + const EDBus_Message *msg) +{ + const char *errname; + const char *aux; + + Elm_Sys_Notify_Action_Invoked *d; + + if (edbus_message_error_get(msg, &errname, &aux)) + { + ERR("Edbus Error: %s %s", errname, aux); + return; + } + + d = malloc(sizeof(*d)); + + if (!edbus_message_arguments_get(msg, "us", &(d->id), &aux)) + { + ERR("Error processing signal: "INTERFACE".ActionInvoked."); + goto cleanup; + } + + d->action_key = strdup(aux); + + if (!ecore_event_add(ELM_EVENT_SYS_NOTIFY_ACTION_INVOKED, d, + _ev_action_invoked_free, NULL)) goto cleanup; + + return; + +cleanup: + free(d->action_key); + free(d); +} + static void _release(void) { @@ -235,6 +314,12 @@ _update(void) _elm_sysnotif_obj = edbus_object_get(_elm_sysnotif_conn, BUS, OBJ); _elm_sysnotif_proxy = edbus_proxy_get(_elm_sysnotif_obj, INTERFACE); _elm_sys_notify_capabilities_get(); + + edbus_proxy_signal_handler_add(_elm_sysnotif_proxy, "NotificationClosed", + _on_notification_closed, NULL); + + edbus_proxy_signal_handler_add(_elm_sysnotif_proxy, "ActionInvoked", + _on_action_invoked, NULL); } static void @@ -271,6 +356,12 @@ elm_need_sys_notify(void) if (!elm_need_edbus()) return EINA_FALSE; + if (!ELM_EVENT_SYS_NOTIFY_NOTIFICATION_CLOSED) + ELM_EVENT_SYS_NOTIFY_NOTIFICATION_CLOSED = ecore_event_type_new(); + + if (!ELM_EVENT_SYS_NOTIFY_ACTION_INVOKED) + ELM_EVENT_SYS_NOTIFY_ACTION_INVOKED = ecore_event_type_new(); + _elm_sysnotif_conn = edbus_connection_get(EDBUS_CONNECTION_TYPE_SESSION); edbus_name_owner_changed_callback_add(_elm_sysnotif_conn, BUS, diff --git a/legacy/elementary/src/lib/elm_sys_notify.h b/legacy/elementary/src/lib/elm_sys_notify.h index 77aa78594b..aeff5a006d 100644 --- a/legacy/elementary/src/lib/elm_sys_notify.h +++ b/legacy/elementary/src/lib/elm_sys_notify.h @@ -1,6 +1,19 @@ #ifndef ELM_SYS_NOTIFY_H #define ELM_SYS_NOTIFY_H +/** + * The reason the notification was closed + * + * @since 1.8 + */ +typedef enum _Elm_Sys_Notify_Closed_Reason +{ + ELM_SYS_NOTIFY_CLOSED_EXPIRED, /** The notification expired. */ + ELM_SYS_NOTIFY_CLOSED_DISMISSED, /** The notification was dismissed by the user. */ + ELM_SYS_NOTIFY_CLOSED_REQUESTED, /** The notification was closed by a call to CloseNotification method. */ + ELM_SYS_NOTIFY_CLOSED_UNDEFINED /** Undefined/reserved reasons. */ +} Elm_Sys_Notify_Closed_Reason; + /** * Urgency levels of a notification * @@ -17,6 +30,39 @@ typedef enum _Elm_Sys_Notify_Urgency typedef void (*Elm_Sys_Notify_Send_Cb)(void *data, unsigned int id); +/** + * Emitted when the signal NotificationClosed is received. + */ +EAPI extern int ELM_EVENT_SYS_NOTIFY_NOTIFICATION_CLOSED; + +/** + * Emitted when the signal ActionInvoked is received. + */ +EAPI extern int ELM_EVENT_SYS_NOTIFY_ACTION_INVOKED; /**< A Action has been invoked. */ + +/** + * Data on event when Notification Closed is emitted. + * + * @since 1.8 + */ +typedef struct _Elm_Sys_Notify_Notification_Closed +{ + unsigned int id; /**< ID of the notification. */ + Elm_Sys_Notify_Closed_Reason reason; /**< The Reason the notification was closed. */ +} Elm_Sys_Notify_Notification_Closed; + + +/** + * Data on event when Action Invoked is emitted. + * + * @since 1.8 + */ +typedef struct _Elm_Sys_Notify_Action_Invoked +{ + unsigned int id; /**< ID of the notification. */ + char *action_key; /**< The key of the action invoked. These match the keys sent over in the list of actions. */ +} Elm_Sys_Notify_Action_Invoked; + /** * @def elm_sys_notify_simple_send *