forked from enlightenment/efl
test_sys_notify: Refactoring to solve weird behavior when tested with more then two instances
- _ev_handler can't know whether elm_win still exists, so changed log style from notify to printf. In addition, release the callbacks when elm_win is destroyed. - use elm_sys_notify_send instead of elm_sys_notify_simple_send to show more functionality. - remove static variables not to print warnings when with more than two test_sys_notify pannel.
This commit is contained in:
parent
642049022a
commit
39cde4d628
|
@ -6,49 +6,72 @@
|
||||||
#define WIDTH 320
|
#define WIDTH 320
|
||||||
#define HEIGHT 160
|
#define HEIGHT 160
|
||||||
|
|
||||||
static Evas_Object *s = NULL;
|
struct _Sys_Notify_Data {
|
||||||
static Evas_Object *b = NULL;
|
Evas_Object *l;
|
||||||
static Evas_Object *l = NULL;
|
Evas_Object *n;
|
||||||
static Evas_Object *n = NULL;
|
Ecore_Event_Handler *handlers[2];
|
||||||
|
};
|
||||||
|
typedef struct _Sys_Notify_Data Sys_Notify_Data;
|
||||||
|
|
||||||
static Eina_Bool
|
static Eina_Bool
|
||||||
_ev_handler(void *data EINA_UNUSED,
|
_ev_handler(void *data EINA_UNUSED,
|
||||||
int type,
|
int type,
|
||||||
void *event)
|
void *event)
|
||||||
{
|
{
|
||||||
char msg[256];
|
|
||||||
|
|
||||||
Elm_Sys_Notify_Notification_Closed *closed;
|
Elm_Sys_Notify_Notification_Closed *closed;
|
||||||
Elm_Sys_Notify_Action_Invoked *action;
|
Elm_Sys_Notify_Action_Invoked *action;
|
||||||
|
|
||||||
if (type == ELM_EVENT_SYS_NOTIFY_NOTIFICATION_CLOSED)
|
if (type == ELM_EVENT_SYS_NOTIFY_NOTIFICATION_CLOSED)
|
||||||
{
|
{
|
||||||
closed = event;
|
closed = event;
|
||||||
sprintf(msg, "Notification Closed Event: %u %d.",
|
printf("Notification Closed Event: %u %d.\n",
|
||||||
closed->id, closed->reason);
|
closed->id, closed->reason);
|
||||||
}
|
}
|
||||||
else if (type == ELM_EVENT_SYS_NOTIFY_ACTION_INVOKED)
|
else if (type == ELM_EVENT_SYS_NOTIFY_ACTION_INVOKED)
|
||||||
{
|
{
|
||||||
action = event;
|
action = event;
|
||||||
sprintf(msg, "Notification Action Event: %u %s.",
|
printf("Notification Action Event: %u %s.\n",
|
||||||
action->id, action->action_key);
|
action->id, action->action_key);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
return ECORE_CALLBACK_PASS_ON;
|
return ECORE_CALLBACK_PASS_ON;
|
||||||
|
|
||||||
elm_object_text_set(l, msg);
|
|
||||||
evas_object_show(n);
|
|
||||||
|
|
||||||
return ECORE_CALLBACK_DONE;
|
return ECORE_CALLBACK_DONE;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void _sys_notify_cb(void *data, unsigned int id EINA_UNUSED)
|
||||||
|
{
|
||||||
|
Sys_Notify_Data *notify_data = data;
|
||||||
|
|
||||||
|
elm_object_text_set(notify_data->l, "notify is done");
|
||||||
|
evas_object_show(notify_data->n);
|
||||||
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
_bt_clicked(void *data EINA_UNUSED,
|
_bt_clicked(void *data,
|
||||||
Evas_Object *obj EINA_UNUSED,
|
Evas_Object *obj,
|
||||||
void *event_info EINA_UNUSED)
|
void *event_info EINA_UNUSED)
|
||||||
{
|
{
|
||||||
elm_sys_notify_simple_send
|
Evas_Object *s, *b;
|
||||||
("", elm_entry_entry_get(s), elm_entry_entry_get(b));
|
s = evas_object_data_get(obj, "summary");
|
||||||
|
b = evas_object_data_get(obj, "body");
|
||||||
|
|
||||||
|
elm_sys_notify_send(0, "", elm_entry_entry_get(s), elm_entry_entry_get(b),
|
||||||
|
ELM_SYS_NOTIFY_URGENCY_NORMAL,
|
||||||
|
-1, _sys_notify_cb, data);
|
||||||
|
}
|
||||||
|
|
||||||
|
static void
|
||||||
|
_test_sys_notify_win_del_cb(void *data,
|
||||||
|
Evas *e EINA_UNUSED,
|
||||||
|
Evas_Object *obj EINA_UNUSED,
|
||||||
|
void *event_info EINA_UNUSED)
|
||||||
|
{
|
||||||
|
Sys_Notify_Data *notify_data = data;
|
||||||
|
ecore_event_handler_del(notify_data->handlers[0]);
|
||||||
|
ecore_event_handler_del(notify_data->handlers[1]);
|
||||||
|
|
||||||
|
free(notify_data);
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
|
@ -56,20 +79,20 @@ test_sys_notify(void *data EINA_UNUSED,
|
||||||
Evas_Object *obj EINA_UNUSED,
|
Evas_Object *obj EINA_UNUSED,
|
||||||
void *event_info EINA_UNUSED)
|
void *event_info EINA_UNUSED)
|
||||||
{
|
{
|
||||||
Evas_Object *win, *bx, *it;
|
Evas_Object *win, *bx, *it, *btn;
|
||||||
|
Evas_Object *s, *b, *n, *l;
|
||||||
|
Sys_Notify_Data *notify_data;
|
||||||
|
|
||||||
elm_need_sys_notify();
|
elm_need_sys_notify();
|
||||||
|
|
||||||
ecore_event_handler_add(ELM_EVENT_SYS_NOTIFY_NOTIFICATION_CLOSED,
|
notify_data = malloc(sizeof(Sys_Notify_Data));
|
||||||
_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);
|
win = elm_win_add(NULL, "Sys Notify", ELM_WIN_BASIC);
|
||||||
elm_policy_set(ELM_POLICY_QUIT, ELM_POLICY_QUIT_LAST_WINDOW_CLOSED);
|
elm_policy_set(ELM_POLICY_QUIT, ELM_POLICY_QUIT_LAST_WINDOW_CLOSED);
|
||||||
elm_win_title_set(win, "System Notification");
|
elm_win_title_set(win, "System Notification");
|
||||||
elm_win_autodel_set(win, EINA_TRUE);
|
elm_win_autodel_set(win, EINA_TRUE);
|
||||||
|
evas_object_event_callback_add(win, EVAS_CALLBACK_DEL,
|
||||||
|
_test_sys_notify_win_del_cb, notify_data);
|
||||||
|
|
||||||
it = elm_bg_add(win);
|
it = elm_bg_add(win);
|
||||||
elm_win_resize_object_add(win, it);
|
elm_win_resize_object_add(win, it);
|
||||||
|
@ -77,12 +100,12 @@ test_sys_notify(void *data EINA_UNUSED,
|
||||||
evas_object_size_hint_max_set(it, WIDTH, HEIGHT);
|
evas_object_size_hint_max_set(it, WIDTH, HEIGHT);
|
||||||
evas_object_show(it);
|
evas_object_show(it);
|
||||||
|
|
||||||
n = elm_notify_add(win);
|
notify_data->n = n = elm_notify_add(win);
|
||||||
evas_object_size_hint_weight_set(n, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
|
evas_object_size_hint_weight_set(n, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
|
||||||
elm_notify_align_set(n, 0.5, 0.0);
|
elm_notify_align_set(n, 0.5, 0.0);
|
||||||
elm_notify_timeout_set(n, 2.0);
|
elm_notify_timeout_set(n, 2.0);
|
||||||
|
|
||||||
l = elm_label_add(win);
|
notify_data->l = l = elm_label_add(win);
|
||||||
elm_object_content_set(n, l);
|
elm_object_content_set(n, l);
|
||||||
evas_object_show(l);
|
evas_object_show(l);
|
||||||
|
|
||||||
|
@ -107,12 +130,19 @@ test_sys_notify(void *data EINA_UNUSED,
|
||||||
elm_box_pack_end(bx, b);
|
elm_box_pack_end(bx, b);
|
||||||
evas_object_show(b);
|
evas_object_show(b);
|
||||||
|
|
||||||
it = elm_button_add(win);
|
btn = elm_button_add(win);
|
||||||
elm_object_text_set(it, "Send Notification");
|
elm_object_text_set(btn, "Send Notification");
|
||||||
evas_object_smart_callback_add(it, "clicked", _bt_clicked, NULL);
|
evas_object_smart_callback_add(btn, "clicked", _bt_clicked, notify_data);
|
||||||
elm_box_pack_end(bx, it);
|
evas_object_data_set(btn, "summary", s);
|
||||||
evas_object_show(it);
|
evas_object_data_set(btn, "body", b);
|
||||||
|
elm_box_pack_end(bx, btn);
|
||||||
|
evas_object_show(btn);
|
||||||
|
|
||||||
evas_object_resize(win, WIDTH, HEIGHT);
|
evas_object_resize(win, WIDTH, HEIGHT);
|
||||||
evas_object_show(win);
|
evas_object_show(win);
|
||||||
|
|
||||||
|
notify_data->handlers[0] = ecore_event_handler_add(ELM_EVENT_SYS_NOTIFY_NOTIFICATION_CLOSED,
|
||||||
|
_ev_handler, notify_data);
|
||||||
|
notify_data->handlers[1] = ecore_event_handler_add(ELM_EVENT_SYS_NOTIFY_ACTION_INVOKED,
|
||||||
|
_ev_handler, notify_data);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue