apply FSL(Flora Software License)
[apps/home/call.git] / ui / src / vcui-view-common.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-common.h"
20 #include "vcui-view-layout-hd.h"
21
22 #include "vcui-view-dialing.h"
23 #include "vcui-view-incoming-lock.h"
24 #include "vcui-view-single-call.h"
25 #include "vcui-view-multi-call-split.h"
26 #include "vcui-view-multi-call-conf.h"
27 #include "vcui-view-multi-call-list.h"
28 #include "vcui-view-keypad.h"
29 #include "vcui-view-callend.h"
30 #include "vcui-view-quickpanel.h"
31
32 static vcui_view_common_t gincall_common_data;
33
34 void _vcui_view_common_init()
35 {
36         memset(&gincall_common_data, 0, sizeof(vcui_view_common_t));
37 }
38
39 static vcui_view_common_t *__vcui_view_common_get_common_data()
40 {
41         return &gincall_common_data;
42 }
43
44 static Eina_Bool __vcui_view_common_timer_cb(void *data)
45 {
46         vcui_view_common_t *common_data = __vcui_view_common_get_common_data();
47         char dur[TIME_BUF_LEN];
48         static int end_count = 0;
49
50         if (common_data->timer_flag == 1) {
51                 if (common_data->time_end_flag == TIME_END_START) {
52                         end_count = 0;
53                         return 1;
54                 } else if (common_data->time_end_flag == TIME_END_NO) {
55                         end_count++;
56                         if (end_count == 1) {
57                                 return 1;
58                         }
59                 }
60         }
61         common_data->current_call_time = time(NULL);
62
63         if (common_data->timer_flag == 1) {
64                 if (common_data->current_call_time > common_data->start_call_time) {
65                         time_t call_time = common_data->current_call_time - common_data->start_call_time;
66                         struct tm loctime;
67
68                         gmtime_r((const time_t *)&call_time, &loctime);
69                         snprintf(dur, TIME_BUF_LEN, "%02d:%02d:%02d", loctime.tm_hour, loctime.tm_min, loctime.tm_sec);
70
71                         _vcui_view_common_set_text_time(dur);
72                 }
73         }
74
75         return 1;
76 }
77
78 static Eina_Bool __vcui_view_common_timer_end_cb(void *data)
79 {
80         vcui_view_common_t *common_data = __vcui_view_common_get_common_data();
81         int end_type = common_data->end_type;
82         char dur[TIME_BUF_LEN];
83
84         if ((common_data->timer_flag == 1) && (common_data->time_end_flag == TIME_END_START)) {
85                 snprintf(dur, TIME_BUF_LEN, "%02d:%02d:%02d", common_data->hour, common_data->min, common_data->sec);
86                 if (common_data->time_count == 0) {
87                         _vcui_view_common_set_text_time(dur);
88                 } else if (common_data->time_count == 1) {
89                         _vcui_view_common_set_text_time(_(" "));
90                 } else if (common_data->time_count == 2) {
91                         _vcui_view_common_set_text_time(dur);
92                 } else if (common_data->time_count == 3) {
93                         _vcui_view_common_set_text_time(_(" "));
94                 } else if (common_data->time_count == 4) {
95                         char data_txt[VC_DATA_LENGTH_MAX] = { 0, };
96                         _vcui_view_common_set_text_time(_vcui_get_endcause_string(end_type, data_txt));
97                 }
98
99                 common_data->time_count++;
100                 if (common_data->time_count == TIME_END_MAX_SHOW) {
101                         common_data->time_end_flag = TIME_END_NO;
102                         common_data->time_count = 0;
103
104                         if (common_data->tm_end) {
105                                 ecore_timer_del(common_data->tm_end);
106                                 common_data->tm_end = NULL;
107                         }
108
109                         _vcui_view_common_call_terminate_or_view_change();
110                 }
111         }
112         return 1;
113 }
114
115 static Eina_Bool __vcui_view_common_timer_end_dialing_cb(void *data)
116 {
117         CALL_UI_DEBUG("..");
118         vcui_view_common_t *common_data = __vcui_view_common_get_common_data();
119
120         if (common_data->tm_end_dialing) {
121                 ecore_timer_del(common_data->tm_end_dialing);
122                 common_data->tm_end_dialing = NULL;
123         }
124
125         if (common_data->bredial == EINA_TRUE) {
126                 vcall_engine_process_auto_redial(EINA_TRUE);
127                 _vcui_view_popup_load_redial();
128         } else {
129                 _vcui_view_common_call_terminate_or_view_change();
130         }
131
132         return 1;
133 }
134
135 static Eina_Bool __vcui_view_common_timer_end_force_cb(void *data)
136 {
137         CALL_UI_DEBUG("..");
138         vcui_view_common_t *common_data = __vcui_view_common_get_common_data();
139
140         if (common_data->tm_end_force) {
141                 ecore_timer_del(common_data->tm_end_force);
142                 common_data->tm_end_force = NULL;
143         }
144
145         _vcui_view_common_call_terminate_or_view_change();
146
147         return 1;
148 }
149
150 void _vcui_view_common_set_text_time(char *time_dur)
151 {
152         vcui_app_call_data_t *ad = _vcui_get_app_data();
153         voice_call_view_data_t *data = ad->view_st[ad->view_top];
154
155         if (data != NULL) {
156                 if (data->type == VIEW_INCALL_ONECALL_VIEW) {
157                         _vc_ui_view_single_call_set_call_timer(data, time_dur);
158                 } else if (data->type == VIEW_INCALL_MULTICALL_SPLIT_VIEW) {
159                         _vcui_view_multi_call_split_set_call_timer(data, time_dur);
160                 } else if (data->type == VIEW_INCALL_MULTICALL_CONF_VIEW) {
161                         _vcui_view_multi_call_conf_set_call_timer(data, time_dur);
162                 } else if (data->type == VIEW_INCALL_MULTICALL_LIST_VIEW) {
163                         _vcui_view_multi_call_list_set_call_timer(data, time_dur);
164                 } else if (data->type == VIEW_ENDCALL_VIEW) {
165                         _vc_ui_view_callend_set_call_timer(data, time_dur);
166                 } else {
167                         /*to do nothing in case of other view. */
168                 }
169         }
170
171         if (ad->win_quickpanel && ad->quickpanel_layout) {
172                 _vc_ui_view_qp_set_call_timer(ad->quickpanel_layout, time_dur);
173         }
174 }
175
176 void _vcui_view_common_set_each_time(time_t starttime)
177 {
178         time_t curr_time;
179         unsigned long call_duration_in_sec = 0;
180         unsigned long sec = 0;
181         unsigned long min = 0;
182         unsigned long hr = 0;
183
184         curr_time = time(&curr_time);
185         call_duration_in_sec = curr_time - starttime;
186         sec = call_duration_in_sec % 60;
187         min = (call_duration_in_sec / 60) % 60;
188         hr = call_duration_in_sec / 3600;
189
190         vcui_view_common_t *common_data = __vcui_view_common_get_common_data();
191
192         /*set the start time for every call */
193         common_data->start_call_time = starttime;
194         CALL_UI_DEBUG(" common_data->start_call_time %lu", (unsigned long)common_data->start_call_time);
195
196         CALL_UI_DEBUG(" _vcui_view_common_set_each_time curr_time %d starttime %d", (int)curr_time, (int)starttime);
197
198         common_data->sec = sec;
199         common_data->min = min;
200         common_data->hour = hr;
201
202         char dur[TIME_BUF_LEN];
203         snprintf(dur, TIME_BUF_LEN, "%02d:%02d:%02d", common_data->hour, common_data->min, common_data->sec);
204         if (common_data->timer_flag == 1)
205                 _vcui_view_common_set_text_time(dur);
206
207         CALL_UI_DEBUG(" complete input time");
208
209 }
210
211 void _vcui_view_common_timer_text_init()
212 {
213         vcui_view_common_t *common_data = __vcui_view_common_get_common_data();
214
215         if (!common_data->tm) {
216                 if (common_data->timer_flag == 0) {
217                         common_data->sec = 0;
218                         common_data->min = 0;
219                         common_data->hour = 0;
220                         common_data->timer_flag = 1;
221                 }
222                 common_data->tm = ecore_timer_add(TIMER_TIMEOUT_1_SEC, __vcui_view_common_timer_cb, NULL);
223         }
224 }
225
226 void _vcui_view_common_timer_destroy()
227 {
228         vcui_view_common_t *common_data = __vcui_view_common_get_common_data();
229         if (common_data->tm) {
230                 ecore_timer_del(common_data->tm);
231                 common_data->tm = NULL;
232         }
233 }
234
235 void _vcui_view_common_timer_end_destroy()
236 {
237         vcui_view_common_t *common_data = __vcui_view_common_get_common_data();
238         if (common_data->tm_end) {
239                 ecore_timer_del(common_data->tm_end);
240                 common_data->tm_end = NULL;
241         }
242 }
243
244 void _vcui_view_common_timer_end_dialing_destroy()
245 {
246         vcui_view_common_t *common_data = __vcui_view_common_get_common_data();
247         if (common_data->tm_end_dialing) {
248                 ecore_timer_del(common_data->tm_end_dialing);
249                 common_data->tm_end_dialing = NULL;
250         }
251 }
252
253 void _vcui_view_common_timer_redial_reset()
254 {
255         CALL_UI_DEBUG("..");
256         vcui_view_common_t *common_data = __vcui_view_common_get_common_data();
257
258         _vcui_view_common_timer_end_destroy();
259         _vcui_view_common_timer_end_dialing_destroy();
260         common_data->time_end_flag = TIME_END_NO;
261 }
262
263 void _vcui_view_common_call_end_show_dialing(int end_type, int bredial)
264 {
265         CALL_UI_DEBUG("end_type:[%d]", end_type);
266         vcui_app_call_data_t *ad = _vcui_get_app_data();
267         vcui_view_common_t *common_data = __vcui_view_common_get_common_data();
268         char data[VC_DATA_LENGTH_MAX] = { 0, };
269
270         if (ad->call_end_type == CALL_END_TYPE_NONE) {
271                 _vcui_view_dialing_draw_txt_ended(ad->view_st[ad->view_top], end_type);
272         } else if (ad->call_end_type == CALL_END_TYPE_SINGLE_CALL) {
273                 common_data->time_end_flag = TIME_END_START;    /*to stop timer from updating the call end screen */
274                 _vcui_view_common_set_text_time(_vcui_get_endcause_string(end_type, data));
275         }
276
277         if (common_data->tm_end_dialing) {
278                 ecore_timer_del(common_data->tm_end_dialing);
279                 common_data->tm_end_dialing = NULL;
280         }
281         common_data->bredial = bredial;
282         common_data->tm_end_dialing = ecore_timer_add(TIMER_TIMEOUT_2_SEC, __vcui_view_common_timer_end_dialing_cb, NULL);
283
284 }
285
286 void _vcui_view_common_call_end_show(time_t start_time, int end_type)
287 {
288         CALL_UI_DEBUG("end_type:[%d]", end_type);
289         vcui_view_common_t *common_data = __vcui_view_common_get_common_data();
290
291         if (common_data->tm_end) {
292                 ecore_timer_del(common_data->tm_end);
293                 common_data->tm_end = NULL;
294         }
295         common_data->time_end_flag = TIME_END_START;
296         _vcui_view_common_set_each_time(start_time);
297
298         common_data->end_type = end_type;
299         common_data->tm_end = ecore_timer_add(TIMER_TIMEOUT_0_3_SEC, __vcui_view_common_timer_end_cb, NULL);
300 }
301
302 void _vcui_view_common_call_end_timer_reset(void)
303 {
304         CALL_UI_DEBUG("..");
305         vcui_view_common_t *common_data = __vcui_view_common_get_common_data();
306         if (common_data->tm_end) {
307                 ecore_timer_del(common_data->tm_end);
308                 common_data->tm_end = NULL;
309         }
310
311         if (common_data->tm_end_dialing) {
312                 ecore_timer_del(common_data->tm_end_dialing);
313                 common_data->tm_end_dialing = NULL;
314         }
315
316         common_data->tm_end_force = ecore_timer_add(TIMER_TIMEOUT_2_SEC, __vcui_view_common_timer_end_force_cb, NULL);
317 }
318
319 int _vcui_view_common_call_terminate_or_view_change(void)
320 {
321         CALL_UI_DEBUG("..");
322         vcui_app_call_data_t *ad = _vcui_get_app_data();
323
324         if (_vcui_doc_get_all_call_data_count() == 0) {
325                 if (ad->contact_ug == NULL) {
326                         CALL_UI_DEBUG("EXIT - contact ug is closed");
327                         elm_exit();
328                 } else {
329                         CALL_UI_DEBUG("show contact ug");
330                         CALL_UI_DEBUG("hide & destory [%d]", ad->view_top);
331                         if (ad->view_top != -1) {
332                                 ad->view_st[ad->view_top]->onHide(ad->view_st[ad->view_top]);
333                                 ad->view_st[ad->view_top]->onDestroy(ad->view_st[ad->view_top]);
334                                 ad->view_top = -1;
335                         }
336                         evas_object_show((Evas_Object *)ug_get_layout(ad->contact_ug));
337                 }
338         } else {
339                 _vcui_view_auto_change();
340         }
341         return VC_NO_ERROR;
342 }
343
344 void _vcui_view_common_show_noid_image(Evas_Object *layout)
345 {
346     CALL_UI_DEBUG("..");
347     vcui_app_call_data_t *ad = _vcui_get_app_data();
348     Evas_Object *noid_icon = NULL;
349
350     noid_icon = edje_object_part_swallow_get(_EDJ(layout), "swl-cid-noid");
351     if (noid_icon) {
352                 edje_object_part_unswallow(_EDJ(layout), noid_icon);
353                 evas_object_del(noid_icon);
354     }
355
356     noid_icon = elm_image_add(ad->win_main);
357     elm_object_part_content_set(layout, "swl-cid-noid", noid_icon);
358     elm_image_file_set(noid_icon, MO_NOCALLER_ID_ICON, NULL);
359
360     edje_object_signal_emit(_EDJ(layout), "show-noid-image", "show-noid");
361 }
362
363 void _vcui_view_common_update_mute_btn()
364 {
365         vcui_app_call_data_t *ad = _vcui_get_app_data();
366         vcui_app_call_view_id_t view_id = ad->view_top;
367         voice_call_view_data_t *vd = ad->view_st[view_id];
368         VCUI_RETURN_IF_FAIL(vd);
369
370         int valid = 0;
371
372         if (vd->layout) {
373                 if (view_id == VIEW_DIALLING_VIEW) {
374                         valid = _vc_ui_view_dialing_check_valid_eo(vd);
375                 } else if (view_id == VIEW_INCALL_ONECALL_VIEW) {
376                         valid = _vc_ui_view_single_call_check_valid_eo(vd);
377                 } else if (view_id == VIEW_INCALL_MULTICALL_SPLIT_VIEW) {
378                         valid = _vcui_view_multi_call_split_check_valid_eo(vd);
379                 } else if (view_id == VIEW_INCALL_MULTICALL_CONF_VIEW) {
380                         valid = _vcui_view_multi_call_conf_check_valid_eo(vd);
381                 } else if (view_id == VIEW_INCALL_MULTICALL_LIST_VIEW) {
382                         valid = _vcui_view_multi_call_list_check_valid_eo(vd);
383                 } else {
384                         CALL_UI_DEBUG("[============ BAD INPUT!!!! Check Input Layout!!!!! %d============]", view_id);
385                 }
386                 if (valid == -1) {
387                         CALL_UI_DEBUG("[========== WARNING!! Invalid Evas Object  ==========]");
388                         return;
389                 }
390         }
391
392         _vcui_create_bottom_middle_button(vd);
393 }
394