summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRyuan Choi <ryuan.choi@samsung.com>2014-07-23 11:01:41 +0900
committerRyuan Choi <ryuan.choi@samsung.com>2014-07-23 11:01:41 +0900
commitb933cfcad0ee5e37f5001692c36297ae8497118c (patch)
treefbb3104bff7fc8f9c0474e017cfc4342eb4aa06b
parent1eb9c4f87dc534fd92aebc15731078a691bdf805 (diff)
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.
-rw-r--r--src/bin/test_sys_notify.c86
1 files changed, 58 insertions, 28 deletions
diff --git a/src/bin/test_sys_notify.c b/src/bin/test_sys_notify.c
index 0a6daccdc..92cbdd175 100644
--- a/src/bin/test_sys_notify.c
+++ b/src/bin/test_sys_notify.c
@@ -6,49 +6,72 @@
6#define WIDTH 320 6#define WIDTH 320
7#define HEIGHT 160 7#define HEIGHT 160
8 8
9static Evas_Object *s = NULL; 9struct _Sys_Notify_Data {
10static Evas_Object *b = NULL; 10 Evas_Object *l;
11static Evas_Object *l = NULL; 11 Evas_Object *n;
12static Evas_Object *n = NULL; 12 Ecore_Event_Handler *handlers[2];
13};
14typedef struct _Sys_Notify_Data Sys_Notify_Data;
13 15
14static Eina_Bool 16static Eina_Bool
15_ev_handler(void *data EINA_UNUSED, 17_ev_handler(void *data EINA_UNUSED,
16 int type, 18 int type,
17 void *event) 19 void *event)
18{ 20{
19 char msg[256];
20
21 Elm_Sys_Notify_Notification_Closed *closed; 21 Elm_Sys_Notify_Notification_Closed *closed;
22 Elm_Sys_Notify_Action_Invoked *action; 22 Elm_Sys_Notify_Action_Invoked *action;
23 23
24 if (type == ELM_EVENT_SYS_NOTIFY_NOTIFICATION_CLOSED) 24 if (type == ELM_EVENT_SYS_NOTIFY_NOTIFICATION_CLOSED)
25 { 25 {
26 closed = event; 26 closed = event;
27 sprintf(msg, "Notification Closed Event: %u %d.", 27 printf("Notification Closed Event: %u %d.\n",
28 closed->id, closed->reason); 28 closed->id, closed->reason);
29 } 29 }
30 else if (type == ELM_EVENT_SYS_NOTIFY_ACTION_INVOKED) 30 else if (type == ELM_EVENT_SYS_NOTIFY_ACTION_INVOKED)
31 { 31 {
32 action = event; 32 action = event;
33 sprintf(msg, "Notification Action Event: %u %s.", 33 printf("Notification Action Event: %u %s.\n",
34 action->id, action->action_key); 34 action->id, action->action_key);
35 } 35 }
36 else 36 else
37 return ECORE_CALLBACK_PASS_ON; 37 return ECORE_CALLBACK_PASS_ON;
38 38
39 elm_object_text_set(l, msg);
40 evas_object_show(n);
41
42 return ECORE_CALLBACK_DONE; 39 return ECORE_CALLBACK_DONE;
43} 40}
44 41
42static void _sys_notify_cb(void *data, unsigned int id EINA_UNUSED)
43{
44 Sys_Notify_Data *notify_data = data;
45
46 elm_object_text_set(notify_data->l, "notify is done");
47 evas_object_show(notify_data->n);
48}
49
45static void 50static void
46_bt_clicked(void *data EINA_UNUSED, 51_bt_clicked(void *data,
47 Evas_Object *obj EINA_UNUSED, 52 Evas_Object *obj,
48 void *event_info EINA_UNUSED) 53 void *event_info EINA_UNUSED)
49{ 54{
50 elm_sys_notify_simple_send 55 Evas_Object *s, *b;
51 ("", elm_entry_entry_get(s), elm_entry_entry_get(b)); 56 s = evas_object_data_get(obj, "summary");
57 b = evas_object_data_get(obj, "body");
58
59 elm_sys_notify_send(0, "", elm_entry_entry_get(s), elm_entry_entry_get(b),
60 ELM_SYS_NOTIFY_URGENCY_NORMAL,
61 -1, _sys_notify_cb, data);
62}
63
64static void
65_test_sys_notify_win_del_cb(void *data,
66 Evas *e EINA_UNUSED,
67 Evas_Object *obj EINA_UNUSED,
68 void *event_info EINA_UNUSED)
69{
70 Sys_Notify_Data *notify_data = data;
71 ecore_event_handler_del(notify_data->handlers[0]);
72 ecore_event_handler_del(notify_data->handlers[1]);
73
74 free(notify_data);
52} 75}
53 76
54void 77void
@@ -56,20 +79,20 @@ test_sys_notify(void *data EINA_UNUSED,
56 Evas_Object *obj EINA_UNUSED, 79 Evas_Object *obj EINA_UNUSED,
57 void *event_info EINA_UNUSED) 80 void *event_info EINA_UNUSED)
58{ 81{
59 Evas_Object *win, *bx, *it; 82 Evas_Object *win, *bx, *it, *btn;
83 Evas_Object *s, *b, *n, *l;
84 Sys_Notify_Data *notify_data;
60 85
61 elm_need_sys_notify(); 86 elm_need_sys_notify();
62 87
63 ecore_event_handler_add(ELM_EVENT_SYS_NOTIFY_NOTIFICATION_CLOSED, 88 notify_data = malloc(sizeof(Sys_Notify_Data));
64 _ev_handler, NULL);
65
66 ecore_event_handler_add(ELM_EVENT_SYS_NOTIFY_ACTION_INVOKED,
67 _ev_handler, NULL);
68 89
69 win = elm_win_add(NULL, "Sys Notify", ELM_WIN_BASIC); 90 win = elm_win_add(NULL, "Sys Notify", ELM_WIN_BASIC);
70 elm_policy_set(ELM_POLICY_QUIT, ELM_POLICY_QUIT_LAST_WINDOW_CLOSED); 91 elm_policy_set(ELM_POLICY_QUIT, ELM_POLICY_QUIT_LAST_WINDOW_CLOSED);
71 elm_win_title_set(win, "System Notification"); 92 elm_win_title_set(win, "System Notification");
72 elm_win_autodel_set(win, EINA_TRUE); 93 elm_win_autodel_set(win, EINA_TRUE);
94 evas_object_event_callback_add(win, EVAS_CALLBACK_DEL,
95 _test_sys_notify_win_del_cb, notify_data);
73 96
74 it = elm_bg_add(win); 97 it = elm_bg_add(win);
75 elm_win_resize_object_add(win, it); 98 elm_win_resize_object_add(win, it);
@@ -77,12 +100,12 @@ test_sys_notify(void *data EINA_UNUSED,
77 evas_object_size_hint_max_set(it, WIDTH, HEIGHT); 100 evas_object_size_hint_max_set(it, WIDTH, HEIGHT);
78 evas_object_show(it); 101 evas_object_show(it);
79 102
80 n = elm_notify_add(win); 103 notify_data->n = n = elm_notify_add(win);
81 evas_object_size_hint_weight_set(n, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND); 104 evas_object_size_hint_weight_set(n, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
82 elm_notify_align_set(n, 0.5, 0.0); 105 elm_notify_align_set(n, 0.5, 0.0);
83 elm_notify_timeout_set(n, 2.0); 106 elm_notify_timeout_set(n, 2.0);
84 107
85 l = elm_label_add(win); 108 notify_data->l = l = elm_label_add(win);
86 elm_object_content_set(n, l); 109 elm_object_content_set(n, l);
87 evas_object_show(l); 110 evas_object_show(l);
88 111
@@ -107,12 +130,19 @@ test_sys_notify(void *data EINA_UNUSED,
107 elm_box_pack_end(bx, b); 130 elm_box_pack_end(bx, b);
108 evas_object_show(b); 131 evas_object_show(b);
109 132
110 it = elm_button_add(win); 133 btn = elm_button_add(win);
111 elm_object_text_set(it, "Send Notification"); 134 elm_object_text_set(btn, "Send Notification");
112 evas_object_smart_callback_add(it, "clicked", _bt_clicked, NULL); 135 evas_object_smart_callback_add(btn, "clicked", _bt_clicked, notify_data);
113 elm_box_pack_end(bx, it); 136 evas_object_data_set(btn, "summary", s);
114 evas_object_show(it); 137 evas_object_data_set(btn, "body", b);
138 elm_box_pack_end(bx, btn);
139 evas_object_show(btn);
115 140
116 evas_object_resize(win, WIDTH, HEIGHT); 141 evas_object_resize(win, WIDTH, HEIGHT);
117 evas_object_show(win); 142 evas_object_show(win);
143
144 notify_data->handlers[0] = ecore_event_handler_add(ELM_EVENT_SYS_NOTIFY_NOTIFICATION_CLOSED,
145 _ev_handler, notify_data);
146 notify_data->handlers[1] = ecore_event_handler_add(ELM_EVENT_SYS_NOTIFY_ACTION_INVOKED,
147 _ev_handler, notify_data);
118} 148}