bd924b566c3204c60da9de77ce1914ffafc6da61
[apps/home/call.git] / ui / vcui-view-incoming.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-application.h"
19 #include "vcui-view-incoming.h"
20 #include "vcui-view-elements.h"
21
22 static int __vcui_view_incoming_oncreate(voice_call_view_data_t *view_data, int param1, void *param2, void *param3);
23 static int __vcui_view_incoming_onupdate(voice_call_view_data_t *view_data, void *update_data1, void *update_data2);
24 static int __vcui_view_incoming_onhide(voice_call_view_data_t *view_data);
25 static int __vcui_view_incoming_onshow(voice_call_view_data_t *view_data);
26 static int __vcui_view_incoming_destroy(voice_call_view_data_t *view_data);
27
28 static voice_call_view_data_t s_view = {
29         .type = VIEW_INCOMING_VIEW,
30         .app_data = NULL,
31         .layout = NULL,
32         .onCreate = __vcui_view_incoming_oncreate,
33         .onUpdate = __vcui_view_incoming_onupdate,
34         .onHide = __vcui_view_incoming_onhide,
35         .onShow = __vcui_view_incoming_onshow,
36         .onDestroy = __vcui_view_incoming_destroy,
37         .priv = NULL,
38 };
39
40 voice_call_view_data_t *_vcui_view_incoming_new(vcui_app_call_data_t *ad)
41 {
42
43         s_view.app_data = ad;
44         s_view.priv = calloc(1, sizeof(incoming_view_priv_t));
45
46         if (!s_view.priv) {
47                 CALL_UI_DEBUG("ERROR!!!!!!!!!!! ");
48         }
49
50         return &s_view;
51 }
52
53 static void __vcui_view_incoming_clear_button(Evas_Object *eo)
54 {
55         CALL_UI_DEBUG("..");
56         Evas_Object *sw;
57         sw = edje_object_part_swallow_get(_EDJ(eo), "btn_accept");
58         if (sw) {
59                 edje_object_part_unswallow(_EDJ(eo), sw);
60                 evas_object_del(sw);
61         }
62         sw = edje_object_part_swallow_get(_EDJ(eo), "btn_reject");
63         if (sw) {
64                 edje_object_part_unswallow(_EDJ(eo), sw);
65                 evas_object_del(sw);
66         }
67         sw = edje_object_part_swallow_get(_EDJ(eo), "btn_incoming1");
68         if (sw) {
69                 edje_object_part_unswallow(_EDJ(eo), sw);
70                 evas_object_del(sw);
71         }
72         sw = edje_object_part_swallow_get(_EDJ(eo), "btn_incoming2");
73         if (sw) {
74                 edje_object_part_unswallow(_EDJ(eo), sw);
75                 evas_object_del(sw);
76         }
77         sw = edje_object_part_swallow_get(_EDJ(eo), "btn_incoming3");
78         if (sw) {
79                 edje_object_part_unswallow(_EDJ(eo), sw);
80                 evas_object_del(sw);
81         }
82         sw = edje_object_part_swallow_get(_EDJ(eo), "btn_incoming4");
83         if (sw) {
84                 edje_object_part_unswallow(_EDJ(eo), sw);
85                 evas_object_del(sw);
86         }
87 }
88
89 static void __vcui_view_incoming_draw_screen(Evas_Object *eo, void *data)
90 {
91         CALL_UI_DEBUG("..");
92
93         voice_call_view_data_t *vd = (voice_call_view_data_t *)data;
94         incoming_view_priv_t *priv = (incoming_view_priv_t *)vd->priv;
95         vcui_app_call_data_t *ad = vd->app_data;
96         int hold_cnt = 0;
97         int active_cnt = 0;
98
99         /* ============ Check valid Evas Object ============= */
100         int valid = 0;
101         valid = _vcui_check_valid_eo(priv->contents, "INCOMINGVIEW");
102         if (valid == -1) {
103                 CALL_UI_DEBUG("[========== INCOMINGVIEW : Invalid Evas Object, priv->contents : %p ==========]", priv->contents);
104                 return;
105         }
106         /* ============ Check valid Evas Object ============= */
107
108         if (strcmp((char *)priv->now_data->call_file_path, NOIMG_ICON) == 0) {
109                 _vcui_show_wallpaper_image(priv->contents);
110                 _vcui_show_calling_name_bg(priv->contents);
111         } else {
112                 CALL_UI_DEBUG("there is caller image.");
113                 _vcui_show_wallpaper_image(priv->contents);
114                 _vcui_show_calling_name_bg(priv->contents);
115                 priv->ic = _vcui_show_contact_image(priv->contents, vd->app_data->win_main, priv->now_data->call_file_path);
116         }
117
118         /* call name (if nothing, call number) */
119         if (strlen((char *)priv->now_data->call_display) == 0) {
120                 edje_object_part_text_set(_EDJ(eo), "txt_call_name", (char *)priv->now_data->call_num);
121         } else {
122                 edje_object_part_text_set(_EDJ(eo), "txt_call_name", (char *)priv->now_data->call_display);
123                 edje_object_part_text_set(_EDJ(eo), "txt_contact_phone_type", (char *)priv->now_data->call_num);
124         }
125
126         active_cnt = _vcui_doc_get_count_unhold();
127         hold_cnt = _vcui_doc_get_count_hold();
128         CALL_UI_DEBUG("unhold:[%d], hold:[%d]",active_cnt, hold_cnt );
129         __vcui_view_incoming_clear_button(priv->contents);      /* to change 2nd incoming call view -> normal incoming call view. */
130         if (active_cnt == 0) {  /* no active call  - single mt call or 2nd call(1hold) */
131                 CALL_UI_DEBUG("normal incoming call");
132
133                 _vcui_create_button_accept(vd);
134                 _vcui_create_button_reject(vd);
135
136                 ad->beffect_needed = EINA_TRUE;
137         } else if (hold_cnt == 0) {     /* active call & no hold call - 2nd call(1active) */
138                 CALL_UI_DEBUG("2nd incoming call-1");
139                 char text[256] = { 0, };
140                 _vcui_create_button_second_incoming_reject(vd, _("IDS_CALL_BUTTON_REJECT"), "btn_incoming3");
141                 memset(text, 0x00, 256);
142                 snprintf(text, 256, "%s + %s", _("IDS_CALL_BODY_HOLD_ACTIVE_CALL_ABB"), _("IDS_CALL_BUTTON_ACCEPT"));
143                 _vcui_create_button_second_incoming_hold_and_accept(vd, text);
144                 memset(text, 0x00, 256);
145                 snprintf(text, 256, "%s + %s", _("IDS_CALL_POP_END_ACTIVE_CALL"), _("IDS_CALL_BUTTON_ACCEPT"));
146                 _vcui_create_button_second_incoming_end_and_accept(vd, text);
147         } else if (active_cnt == 1 && hold_cnt == 1) {  /* 1active & 1hold */
148                 CALL_UI_DEBUG("2nd incoming call - 1ACT & 1HLD");
149                 char text[256] = { 0, };
150                 _vcui_create_button_second_incoming_reject(vd, _("IDS_CALL_BUTTON_REJECT"), "btn_incoming1");
151
152                 memset(text, 0x00, 256);
153                 snprintf(text, 256, "%s + %s", _("IDS_CALL_POP_END_ACTIVE_CALL"), _("IDS_CALL_BUTTON_ACCEPT"));
154                 _vcui_create_button_second_incoming_end_active_and_accept(vd, text);
155
156                 memset(text, 0x00, 256);
157                 snprintf(text, 256, "%s + %s", _("IDS_CALL_OPT_END_HELD_CALL"), _("IDS_CALL_BUTTON_ACCEPT"));
158                 _vcui_create_button_second_incoming_end_hold_and_accept(vd, text);
159
160                 memset(text, 0x00, 256);
161                 snprintf(text, 256, "%s + %s", _("IDS_CALL_OPT_END_ALL_CALLS"), _("IDS_CALL_BUTTON_ACCEPT"));
162                 _vcui_create_button_second_incoming_end_all_and_accept(vd, text);
163         } else if (active_cnt >= 1 && hold_cnt == 1) {  /* 1+active & 1hold */
164                 CALL_UI_DEBUG("2nd incoming call - [1+]ACT & 1HLD");
165                 char text[256] = { 0, };
166                 _vcui_create_button_second_incoming_reject(vd, _("IDS_CALL_BUTTON_REJECT"), "btn_incoming1");
167
168                 memset(text, 0x00, 256);
169                 snprintf(text, 256, "%s(%d) + %s", _("IDS_CALL_POP_END_ACTIVE_CALL"), active_cnt, _("IDS_CALL_BUTTON_ACCEPT"));
170                 _vcui_create_button_second_incoming_end_active_and_accept(vd, text);
171
172                 memset(text, 0x00, 256);
173                 snprintf(text, 256, "%s + %s", _("IDS_CALL_OPT_END_HELD_CALL"), _("IDS_CALL_BUTTON_ACCEPT"));
174                 _vcui_create_button_second_incoming_end_hold_and_accept(vd, text);
175
176                 memset(text, 0x00, 256);
177                 snprintf(text, 256, "%s + %s", _("IDS_CALL_OPT_END_ALL_CALLS"), _("IDS_CALL_BUTTON_ACCEPT"));
178                 _vcui_create_button_second_incoming_end_all_and_accept(vd, text);
179         } else if (active_cnt == 1 && hold_cnt >= 1) {  /*  1active & 1+hold */
180                 CALL_UI_DEBUG("2nd incoming call - 1ACT & [1+]HLD");
181                 char text[256] = { 0, };
182                 _vcui_create_button_second_incoming_reject(vd, _("IDS_CALL_BUTTON_REJECT"), "btn_incoming1");
183
184                 memset(text, 0x00, 256);
185                 snprintf(text, 256, "%s + %s", _("IDS_CALL_POP_END_ACTIVE_CALL"), _("IDS_CALL_BUTTON_ACCEPT"));
186                 _vcui_create_button_second_incoming_end_active_and_accept(vd, text);
187
188                 memset(text, 0x00, 256);
189                 snprintf(text, 256, "%s(%d) + %s", _("IDS_CALL_OPT_END_HELD_CALL"), hold_cnt, _("IDS_CALL_BUTTON_ACCEPT"));
190                 _vcui_create_button_second_incoming_end_hold_and_accept(vd, text);
191
192                 memset(text, 0x00, 256);
193                 snprintf(text, 256, "%s + %s", _("IDS_CALL_OPT_END_ALL_CALLS"), _("IDS_CALL_BUTTON_ACCEPT"));
194                 _vcui_create_button_second_incoming_end_all_and_accept(vd, text);
195         }
196         CALL_UI_DEBUG("unhold:[%d], hold:[%d]", active_cnt, hold_cnt);
197
198         evas_object_show(eo);
199 }
200
201 static Evas_Object *__vcui_view_incoming_create_contents(void *data)
202 {
203         voice_call_view_data_t *vd = (voice_call_view_data_t *)data;
204         Evas_Object *eo = NULL;
205
206         /* load edje */
207         eo = _vcui_load_edj(vd->app_data->win_main, EDJ_NAME, GRP_MTVIEW);
208         if (eo == NULL)
209                 return NULL;
210
211         return eo;
212 }
213
214 static Evas_Object *__vcui_view_incoming_create_layout_main(Evas_Object *parent)
215 {
216         if (parent == NULL) {
217                 CALL_UI_DEBUG("ERROR");
218                 return NULL;
219         }
220
221         Evas_Object *ly;
222         ly = elm_layout_add(parent);
223         retvm_if(ly == NULL, NULL, "Failed elm_layout_add.");
224
225         elm_layout_theme_set(ly, "standard", "window", "integration");
226         evas_object_size_hint_weight_set(ly, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
227         elm_win_resize_object_add(parent, ly);
228
229         edje_object_signal_emit(_EDJ(ly), "elm,state,show,indicator", "elm");
230         edje_object_signal_emit(_EDJ(ly), "elm,state,show,content", "elm");
231         evas_object_show(ly);
232
233         return ly;
234 }
235
236 static int __vcui_view_incoming_oncreate(voice_call_view_data_t *view_data, int param1, void *param2, void *param3)
237 {
238         CALL_UI_DEBUG("incoming view create!!");
239
240         vcui_app_call_data_t *ad = view_data->app_data;
241         incoming_view_priv_t *priv = view_data->priv;
242
243         if (!view_data->layout) {
244
245                 view_data->layout = __vcui_view_incoming_create_layout_main(ad->win_main);
246                 if (view_data->layout == NULL) {
247                         CALL_UI_DEBUG("ERROR");
248                         return VC_ERROR;
249                 }
250
251                 priv->contents = __vcui_view_incoming_create_contents(view_data);
252                 elm_object_part_content_set(view_data->layout, "elm.swallow.content", priv->contents);
253
254                 evas_object_name_set(priv->contents, "INCOMINGVIEW");
255                 CALL_UI_DEBUG("[========== INCOMINGVIEW: priv->contents Addr : [%p] ==========]", priv->contents);
256
257         }
258
259         __vcui_view_incoming_onshow(view_data);
260         return VC_NO_ERROR;
261 }
262
263 static int __vcui_view_incoming_onupdate(voice_call_view_data_t *view_data, void *update_data1, void *update_data2)
264 {
265         CALL_UI_DEBUG("incoming view update");
266         incoming_view_priv_t *priv = view_data->priv;
267         if (priv->bdont_refresh == EINA_TRUE) {
268                 return VC_NO_ERROR;
269         }
270         priv->bselected_btn = EINA_FALSE;
271         __vcui_view_incoming_onshow(view_data);
272         return VC_NO_ERROR;
273 }
274
275 static int __vcui_view_incoming_onhide(voice_call_view_data_t *view_data)
276 {
277         CALL_UI_DEBUG("incoming view hide");
278
279         int valid = 0;
280         incoming_view_priv_t *priv = (incoming_view_priv_t *)view_data->priv;
281         valid = _vcui_check_valid_eo(priv->contents, "INCOMINGVIEW");
282
283         if (valid == -1) {
284                 CALL_UI_DEBUG("[========== INCOMINGVIEW : Invalid Evas Object, priv->contents : %p ==========]", priv->contents);
285         }
286
287         evas_object_hide(view_data->layout);
288         return VC_NO_ERROR;
289 }
290
291 static int __vcui_view_incoming_onshow(voice_call_view_data_t *view_data)
292 {
293         CALL_UI_DEBUG("incoming view show");
294         vcui_app_call_data_t *ad = _vcui_get_app_data();
295         int result = 0;
296
297         incoming_view_priv_t *priv = view_data->priv;
298         priv->now_data = _vcui_doc_get_recent_mt();
299         if (priv->now_data == NULL) {
300                 CALL_UI_DEBUG("call data is null");
301                 return VC_ERROR;
302         }
303
304         __vcui_view_incoming_draw_screen(priv->contents, view_data);
305
306         evas_object_hide(view_data->layout);
307         evas_object_show(view_data->layout);
308
309         _vcui_app_win_set_noti_type(EINA_TRUE);
310
311         return VC_NO_ERROR;
312 }
313
314 static int __vcui_view_incoming_destroy(voice_call_view_data_t *view_data)
315 {
316         CALL_UI_DEBUG("incoming view destroy");
317
318         vcui_app_call_data_t *ad = _vcui_get_app_data();
319
320         voice_call_view_data_t *vd = ad->view_st[VIEW_INCOMING_VIEW];
321         incoming_view_priv_t *priv = (incoming_view_priv_t *)vd->priv;
322
323         if (_vcui_is_idle_lock() == CALL_LOCK)
324                 _vcui_app_win_set_noti_type(EINA_TRUE);
325         else
326                 _vcui_app_win_set_noti_type(EINA_FALSE);
327
328         ad->bmute_ringtone = EINA_FALSE;
329
330         if (priv != NULL) {
331                 if (priv->contents) {
332                         evas_object_del(priv->contents);
333                         priv->contents = NULL;
334                 }
335
336                 free(priv);
337                 priv = NULL;
338         }
339
340         if (vd->layout != NULL) {
341                 evas_object_hide(vd->layout);
342                 evas_object_del(vd->layout);
343                 vd->layout = NULL;
344         }
345
346         ad->view_st[VIEW_INCOMING_VIEW] = NULL;
347         _vcui_cache_flush();
348
349         return VC_NO_ERROR;
350 }