apply FSL(Flora Software License)
[apps/home/call.git] / ui / src / vcui-app-window.c
1 /*
2  * Copyright 2012  Samsung Electronics Co., Ltd
3  *
4  * Licensed under the Flora License, Version 1.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.tizenopensource.org/license
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16
17
18 #include "vcui-app-window.h"
19 #include "vcui-view-quickpanel.h"
20
21 static Eina_Bool __vcui_app_win_focus_in_cb(void *data, int type, void *event);
22 static Eina_Bool __vcui_app_win_focus_out_cb(void *data, int type, void *event);
23 static void __vcui_app_win_main_win_del_cb(void *data, Evas_Object *obj, void *event);
24 static Eina_Bool __vcui_app_win_hard_key_down_cb(void *data, int type, void *event);
25 static Eina_Bool __vcui_app_win_hard_key_up_cb(void *data, int type, void *event);
26 static Eina_Bool __vcui_app_win_mouse_down_cb(void *data, int type, void *event);
27 /*static Eina_Bool __vcui_app_win_longpress_mute_timer_cb(void *data);*/
28 static Eina_Bool __vcui_app_win_volup_key_longpress_timer_cb(void *data);
29 static Eina_Bool __vcui_app_win_voldown_key_longpress_timer_cb(void *data);
30
31 Evas_Object *_vcui_app_win_create_main(vcui_app_call_data_t *ad, const char *name)
32 {
33         Evas_Object *eo;
34
35         eo = elm_win_add(NULL, name, ELM_WIN_BASIC);
36         if (eo) {
37                 elm_win_title_set(eo, name);
38                 elm_win_borderless_set(eo, EINA_TRUE);
39                 evas_object_smart_callback_add(eo, "delete,request", __vcui_app_win_main_win_del_cb, NULL);
40                 ecore_x_window_size_get(ecore_x_window_root_first_get(), &ad->root_w, &ad->root_h);
41                 evas_object_resize(eo, ad->root_w, ad->root_h);
42                 elm_win_indicator_mode_set(eo, ELM_WIN_INDICATOR_SHOW);
43         }
44
45         return eo;
46 }
47
48 static Eina_Bool __vcui_app_win_focus_in_cb(void *data, int type, void *event)
49 {
50         CALL_UI_DEBUG("..");
51         vcui_app_call_data_t *ad = (vcui_app_call_data_t *)data;
52         Ecore_X_Event_Window_Focus_Out *ev = (Ecore_X_Event_Window_Focus_Out *)event;
53
54         if (ad == NULL) {
55                 CALL_UI_DEBUG("ad == NULL");
56                 return ECORE_CALLBACK_CANCEL;
57         }
58
59         if (ad->win_main!= NULL && ev->win == elm_win_xwindow_get(ad->win_main)) {
60                 CALL_UI_DEBUG("Uninstall quick-panel view");
61                 _vcui_view_qp_uninstall_window(ad->view_st[VIEW_QUICKPANEL_VIEW]);
62         }
63
64         CALL_UI_DEBUG("__win_focus_in_cb leave");
65
66         return ECORE_CALLBACK_PASS_ON;
67 }
68
69 static Eina_Bool __vcui_app_win_focus_out_cb(void *data, int type, void *event)
70 {
71         CALL_UI_DEBUG("..");
72         vcui_app_call_data_t *ad = (vcui_app_call_data_t *)data;
73         Ecore_X_Event_Window_Focus_Out *ev = (Ecore_X_Event_Window_Focus_Out *)event;
74
75         if (ad == NULL) {
76                 CALL_UI_DEBUG("ad == NULL");
77                 return ECORE_CALLBACK_CANCEL;
78         }
79
80         if (ad->win_main != NULL && ev->win == elm_win_xwindow_get(ad->win_main)) {
81                 CALL_UI_DEBUG("install quick-panel view");
82                 _vcui_view_qp_install_window(ad->view_st[VIEW_QUICKPANEL_VIEW]);
83         }
84
85         CALL_UI_DEBUG("__win_focus_out_cb leave");
86
87         return ECORE_CALLBACK_PASS_ON;
88 }
89
90 static void __vcui_app_win_main_win_del_cb(void *data, Evas_Object *obj, void *event)
91 {
92         CALL_UI_DEBUG("..");
93         elm_exit();
94 }
95
96 static Eina_Bool __vcui_app_win_hard_key_down_cb(void *data, int type, void *event)
97 {
98         CALL_UI_DEBUG("..");
99
100         vcui_app_call_data_t *ad = (vcui_app_call_data_t *)data;
101         Ecore_Event_Key *ev = event;
102         gboolean banswering_enabled = EINA_FALSE;
103         gboolean bpowerkey_enabled = EINA_FALSE;
104
105         retvm_if(ev == NULL, 0, "ERROR!!! ========= Event is NULL!!!");
106
107         if (ad->view_top == -1) {
108                 CALL_UI_DEBUG("ad->view_top is -1.");
109 #ifdef SEND_END_TO_UG
110                 if ((ad->contact_ug != NULL) && (!strcmp(ev->keyname, KEY_END))) {
111                         CALL_UI_DEBUG("send end key to contact ug.");
112                         ug_send_key_event(UG_KEY_EVENT_END);
113                 }
114 #endif
115                 return EINA_FALSE;
116         }
117
118         if (!strcmp(ev->keyname, KEY_POWER)) {
119                 bpowerkey_enabled = _vcui_is_powerkey_mode_on();
120                 CALL_UI_DEBUG("[KEY]KEY_POWER pressed, bpowerkey_enabled(%d)", bpowerkey_enabled);
121                 if (bpowerkey_enabled == EINA_TRUE) {
122                         CALL_UI_DEBUG("Lock the LCD state to ON...");
123                         vcall_engine_device_control_lcd_state(VC_LCD_ON_LOCK);
124
125                         if (ad->view_st[ad->view_top]->type == VIEW_DIALLING_VIEW) {
126                                 if (ad->ball_view_hide) {
127                                         CALL_UI_DEBUG("VCUI_RQST_REDIAL_STOP !!");
128                                         vcall_engine_process_auto_redial(EINA_FALSE);
129                                         elm_exit();
130                                 } else {
131                                         vcall_engine_cancel_call();
132                                 }
133                         } else if (ad->view_st[ad->view_top]->type == VIEW_INCOMING_LOCK_VIEW) {
134                                 vcall_engine_reject_call();
135                         } else if ((ad->view_st[ad->view_top]->type >= VIEW_INCALL_ONECALL_VIEW)
136                                    && (ad->view_st[ad->view_top]->type <= VIEW_INCALL_MULTICALL_LIST_VIEW)) {
137                                 vcall_engine_release_call_by_type(VCALL_ENGINE_RELEASE_ALL_CALLS);
138                         } else {
139                                 CALL_UI_DEBUG("nothing...");
140                         }
141                 }
142         } else if (!strcmp(ev->keyname, KEY_VOLUMEUP)) {
143                 CALL_UI_DEBUG("[KEY]KEY_VOLUMEUP pressed");
144                 if (ad->view_st[ad->view_top]->type == VIEW_INCOMING_LOCK_VIEW) {
145                         vcall_engine_mute_alert();
146                         ad->bmute_ringtone = EINA_TRUE;
147                 } else {
148                         ad->vol_longpress_cnt = 0;
149                         vcall_engine_device_control_lcd_state(VC_LCD_ON);
150                         {
151                                 _vcui_set_volume(VAL_VOL_UP);
152                                 ad->volup_key_longpress_timer = ecore_timer_add(VOLUME_KEY_LONG_PRESS_TIMEOUT, __vcui_app_win_volup_key_longpress_timer_cb, ad);
153                         }
154                 }
155         } else if (!strcmp(ev->keyname, KEY_VOLUMEDOWN)) {
156                 CALL_UI_DEBUG("[KEY]KEY_VOLUMEDOWN pressed");
157                 if (ad->view_st[ad->view_top]->type == VIEW_INCOMING_LOCK_VIEW) {
158                         vcall_engine_mute_alert();
159                         ad->bmute_ringtone = EINA_TRUE;
160                 } else {
161                         ad->vol_longpress_cnt = 0;
162                         vcall_engine_device_control_lcd_state(VC_LCD_ON);
163                         {
164                                 _vcui_set_volume(VAL_VOL_DOWN);
165                                 ad->voldown_key_longpress_timer = ecore_timer_add(VOLUME_KEY_LONG_PRESS_TIMEOUT, __vcui_app_win_voldown_key_longpress_timer_cb, ad);
166                         }
167                 }
168         } else if (!strcmp(ev->keyname, KEY_SELECT)) {
169                 banswering_enabled = _vcui_is_answering_mode_on();
170                 CALL_UI_DEBUG("[KEY]KEY_SELECT pressed");
171                 if (banswering_enabled == EINA_TRUE) {
172                         if (ad->view_st[ad->view_top]->type == VIEW_INCOMING_LOCK_VIEW) {
173                                 CALL_UI_DEBUG("Answering mode on and Home key pressed on MT screen");
174
175                                 if (_vcui_is_phonelock_status() == EINA_FALSE)
176                                         vconf_set_int(VCONFKEY_IDLE_LOCK_STATE, VCONFKEY_IDLE_UNLOCK);
177                                 vcall_engine_answer_call();
178                         }
179                 }
180         }
181
182         CALL_UI_DEBUG("End..");
183         return EINA_FALSE;
184 }
185
186 static Eina_Bool __vcui_app_win_hard_key_up_cb(void *data, int type, void *event)
187 {
188         CALL_UI_DEBUG("..");
189
190         vcui_app_call_data_t *ad = (vcui_app_call_data_t *)data;
191         Ecore_Event_Key *ev = event;
192
193         retvm_if(ev == NULL, 0, "ERROR!!! ========= Event is NULL!!!");
194
195         if (0 == strcmp(ev->keyname, KEY_VOLUMEDOWN)) {
196                 if (ad->ringtone_longpress_mute_timer) {
197                         ecore_timer_del(ad->ringtone_longpress_mute_timer);
198                         ad->ringtone_longpress_mute_timer = NULL;
199                 }
200         }
201
202         ad->vol_longpress_cnt = 0;
203
204         if (ad->volup_key_longpress_timer) {
205                 ecore_timer_del(ad->volup_key_longpress_timer);
206                 ad->volup_key_longpress_timer = NULL;
207         }
208
209         if (ad->voldown_key_longpress_timer) {
210                 ecore_timer_del(ad->voldown_key_longpress_timer);
211                 ad->voldown_key_longpress_timer = NULL;
212         }
213
214         return EINA_FALSE;
215 }
216
217 static Eina_Bool __vcui_app_win_mouse_down_cb(void *data, int type, void *event)
218 {
219         vcui_app_call_data_t *ad = (vcui_app_call_data_t *)data;
220         Ecore_Event_Mouse_Button *ev = event;
221
222         ad->touch_x = ev->x;
223         ad->touch_y = ev->y;
224         return EINA_FALSE;
225 }
226
227 void _vcui_app_win_key_grab(vcui_app_call_data_t *ad)
228 {
229         int result = 0;
230         CALL_UI_KPI("_vcui_app_win_key_grab start");
231
232         /* Key Grab */
233         ad->disp = ecore_x_display_get();
234         ad->win = elm_win_xwindow_get(ad->win_main);
235
236         result = utilx_grab_key(ad->disp, ad->win, KEY_VOLUMEUP, EXCLUSIVE_GRAB);
237         if (result)
238                 CALL_UI_DEBUG("KEY_VOLUMEUP key grab failed");
239
240         result = utilx_grab_key(ad->disp, ad->win, KEY_VOLUMEDOWN, EXCLUSIVE_GRAB);
241         if (result)
242                 CALL_UI_DEBUG("KEY_VOLUMEDOWN key grab failed");
243
244         if (ad->downkey_handler == NULL)
245                 ad->downkey_handler = ecore_event_handler_add(ECORE_EVENT_KEY_DOWN, __vcui_app_win_hard_key_down_cb, ad);
246         if (ad->upkey_handler == NULL)
247                 ad->upkey_handler = ecore_event_handler_add(ECORE_EVENT_KEY_UP, __vcui_app_win_hard_key_up_cb, ad);
248         if (ad->mouse_evnt_handler == NULL)
249                 ad->mouse_evnt_handler = ecore_event_handler_add(ECORE_EVENT_MOUSE_BUTTON_DOWN, __vcui_app_win_mouse_down_cb, ad);      /*for ctxpopup */
250         if (ad->focus_in == NULL)
251                 ad->focus_in = ecore_event_handler_add(ECORE_X_EVENT_WINDOW_FOCUS_IN, __vcui_app_win_focus_in_cb, ad);
252         if (ad->focus_out == NULL)
253                 ad->focus_out = ecore_event_handler_add(ECORE_X_EVENT_WINDOW_FOCUS_OUT, __vcui_app_win_focus_out_cb, ad);
254
255         CALL_UI_KPI("_vcui_app_win_key_grab done");
256 }
257
258 #if 0
259 static Eina_Bool __vcui_app_win_longpress_mute_timer_cb(void *data)
260 {
261         CALL_UI_DEBUG("..");
262
263         vcui_app_call_data_t *ad = (vcui_app_call_data_t *)data;
264         call_data_t *call_data = _vcui_doc_get_recent_mt_call_data();
265
266         if (call_data == NULL)
267                 return ECORE_CALLBACK_CANCEL;
268
269         if (ad->ringtone_longpress_mute_timer) {
270                 ecore_timer_del(ad->ringtone_longpress_mute_timer);
271                 ad->ringtone_longpress_mute_timer = NULL;
272         }
273
274         ad->vol_longpress_cnt = 0;
275
276         if (ad->volup_key_longpress_timer) {
277                 ecore_timer_del(ad->volup_key_longpress_timer);
278                 ad->volup_key_longpress_timer = NULL;
279         }
280
281         if (ad->voldown_key_longpress_timer) {
282                 ecore_timer_del(ad->voldown_key_longpress_timer);
283                 ad->voldown_key_longpress_timer = NULL;
284         }
285
286         _vcui_view_popup_unload(ad->vol_ringtone_popup_eo);
287
288         vcall_engine_mute_alert();
289         ad->bmute_ringtone = EINA_TRUE;
290
291         return ECORE_CALLBACK_CANCEL;
292 }
293 #endif
294
295 static Eina_Bool __vcui_app_win_volup_key_longpress_timer_cb(void *data)
296 {
297         CALL_UI_DEBUG("..");
298
299         vcui_app_call_data_t *ad = (vcui_app_call_data_t *)data;
300
301         if (ad->view_st[ad->view_top]->type == VIEW_INCOMING_LOCK_VIEW) {
302                 if ((ad->ringtone_val == RINGTONE_MAX) || (ad->bmute_ringtone == EINA_TRUE)) {
303                         if (ad->volup_key_longpress_timer) {
304                                 ecore_timer_del(ad->volup_key_longpress_timer);
305                                 ad->volup_key_longpress_timer = NULL;
306                         }
307                         return ECORE_CALLBACK_CANCEL;
308                 }
309         } else if (ad->headset_status == EINA_TRUE) {
310                 if (ad->bt_vol_val == BT_VOL_MAX) {
311                         if (ad->volup_key_longpress_timer) {
312                                 ecore_timer_del(ad->volup_key_longpress_timer);
313                                 ad->volup_key_longpress_timer = NULL;
314                         }
315                         return ECORE_CALLBACK_CANCEL;
316                 }
317         } else {
318                 if (ad->voice_vol_val == VOICE_VOL_MAX) {
319                         if (ad->volup_key_longpress_timer) {
320                                 ecore_timer_del(ad->volup_key_longpress_timer);
321                                 ad->volup_key_longpress_timer = NULL;
322                         }
323                         return ECORE_CALLBACK_CANCEL;
324                 }
325         }
326
327         ad->vol_longpress_cnt++;
328
329         if ((ad->vol_longpress_cnt % 3) == 0) {
330                 _vcui_set_volume(VAL_VOL_UP);
331         }
332
333         return ECORE_CALLBACK_RENEW;
334 }
335
336 static Eina_Bool __vcui_app_win_voldown_key_longpress_timer_cb(void *data)
337 {
338         CALL_UI_DEBUG("..");
339
340         vcui_app_call_data_t *ad = (vcui_app_call_data_t *)data;
341
342         if (ad->view_st[ad->view_top]->type == VIEW_INCOMING_LOCK_VIEW) {
343                 if ((ad->ringtone_val == RINGTONE_MAX) || (ad->bmute_ringtone == EINA_TRUE)) {
344                         if (ad->voldown_key_longpress_timer) {
345                                 ecore_timer_del(ad->voldown_key_longpress_timer);
346                                 ad->voldown_key_longpress_timer = NULL;
347                         }
348                         return ECORE_CALLBACK_CANCEL;
349                 }
350         } else if (ad->headset_status == EINA_TRUE) {
351                 if (ad->bt_vol_val == BT_VOL_MIN) {
352                         if (ad->voldown_key_longpress_timer) {
353                                 ecore_timer_del(ad->voldown_key_longpress_timer);
354                                 ad->voldown_key_longpress_timer = NULL;
355                         }
356                         return ECORE_CALLBACK_CANCEL;
357                 }
358         } else {
359                 if (ad->voice_vol_val == VOICE_VOL_MIN) {
360                         if (ad->voldown_key_longpress_timer) {
361                                 ecore_timer_del(ad->voldown_key_longpress_timer);
362                                 ad->voldown_key_longpress_timer = NULL;
363                         }
364                         return ECORE_CALLBACK_CANCEL;
365                 }
366         }
367
368         ad->vol_longpress_cnt++;
369
370         if ((ad->vol_longpress_cnt % 3) == 0) {
371                 _vcui_set_volume(VAL_VOL_DOWN);
372         }
373
374         return ECORE_CALLBACK_RENEW;
375 }
376
377 void _vcui_app_win_set_noti_type(int bwin_noti)
378 {
379         Ecore_X_Window xwin;
380         vcui_app_call_data_t *ad = _vcui_get_app_data();
381
382         /* Get x-window */
383         xwin = elm_win_xwindow_get(ad->win_main);
384
385         if (bwin_noti == EINA_FALSE) {
386                 CALL_UI_DEBUG("window type: NORMAL");
387                 /* Set Normal window */
388                 ecore_x_netwm_window_type_set(xwin, ECORE_X_WINDOW_TYPE_NORMAL);
389         } else {
390                 CALL_UI_DEBUG("window type: NOTI-HIGH");
391                 /* Set Notification window */
392                 ecore_x_netwm_window_type_set(xwin, ECORE_X_WINDOW_TYPE_NOTIFICATION);
393                 /* Set Notification's priority to LEVEL_HIGH */
394                 utilx_set_system_notification_level(ecore_x_display_get(), xwin, UTILX_NOTIFICATION_LEVEL_HIGH);
395         }
396         return;
397 }