2 * Copyright 2012 Samsung Electronics Co., Ltd
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
8 * http://floralicense.org/license/
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.
17 #include <Elementary.h>
19 #include "cst-common.h"
20 #include "cst-common-string.h"
22 #include "cst-widget.h"
24 #include "cst-forwarding.h"
26 static Elm_Genlist_Item_Class *itc_ime = NULL;
27 static Elm_Genlist_Item_Class *itc_sep = NULL;
28 static char *def_ime_number = NULL;
30 static Elm_Genlist_Item_Class *itc_waiting_time = NULL;
31 static Elm_Genlist_Item_Class *itc_waiting_time_expand = NULL;
32 static CstGlItemData_t *waitingtime_item = NULL;
33 static int curr_wait_time = -1;
34 static Evas_Object *waitingtime_radio_btn = NULL;
35 static CstGlItemDisplayInfo_t list_cf_ime_dep2_waiting_time[] = {
36 {2, CST_STR_WAITING_TIME_5_SEC, ELM_GENLIST_ITEM_NONE, CST_GL_ITEM_RADIO_1TEXT, (void *)CST_CF_WAIT_TIME_IDX_5_SEC},
37 {2, CST_STR_WAITING_TIME_10_SEC, ELM_GENLIST_ITEM_NONE, CST_GL_ITEM_RADIO_1TEXT, (void *)CST_CF_WAIT_TIME_IDX_10_SEC},
38 {2, CST_STR_WAITING_TIME_15_SEC, ELM_GENLIST_ITEM_NONE, CST_GL_ITEM_RADIO_1TEXT, (void *)CST_CF_WAIT_TIME_IDX_15_SEC},
39 {2, CST_STR_WAITING_TIME_20_SEC, ELM_GENLIST_ITEM_NONE, CST_GL_ITEM_RADIO_1TEXT, (void *)CST_CF_WAIT_TIME_IDX_20_SEC},
40 {2, CST_STR_WAITING_TIME_25_SEC, ELM_GENLIST_ITEM_NONE, CST_GL_ITEM_RADIO_1TEXT, (void *)CST_CF_WAIT_TIME_IDX_25_SEC},
41 {2, CST_STR_WAITING_TIME_30_SEC, ELM_GENLIST_ITEM_NONE, CST_GL_ITEM_RADIO_1TEXT, (void *)CST_CF_WAIT_TIME_IDX_30_SEC},
43 {2, -1, ELM_GENLIST_ITEM_NONE, CST_GL_ITEM_NONE, NULL},
46 static int __cst_cf_ime_get_wait_time_index(int wait_time);
47 static int __cst_cf_ime_get_wait_time(int wait_time_idx);
48 static void __cst_cf_ime_gl_sel_waiting_time(void *data, Evas_Object *obj, void *event_info);
49 static void __cst_cf_ime_waiting_time_collapse_req(void *data, Evas_Object *obj, void *event_info);
50 static void __cst_cf_ime_waiting_time_collapse(int selected_time, Evas_Object *obj, void *event_info);
51 static void __cst_cf_ime_waiting_time_expand_req(void *data, Evas_Object *obj, void *event_info);
52 static void __cst_cf_ime_waiting_time_expand(void *data, Evas_Object *obj, void *event_info);
53 static void __cst_cf_ime_on_click_waitingtime_expand(void *data, Evas_Object *obj, void *event_info);
54 static void __cst_cf_ime_gl_del(void *data, Evas_Object *obj);
55 static Evas_Object *__cst_cf_ime_create_wait_time_radio_icon(Evas_Object *obj, Evas_Object *rdg, int value, int offset);
56 static Evas_Object *__cst_cf_ime_get_wait_time_sub_exp_icon(void *data, Evas_Object *obj, const char *part);
57 static char *__cst_cf_ime_get_wait_time_sub_exp_label(void *data, Evas_Object *obj, const char *part);
58 static char *__cst_cf_ime_cf_onoff_get_waiting_time_label(void *data, Evas_Object *obj, const char *part);
59 static Eina_Bool __cst_cf_is_waiting_time_available(int wait_time);
61 int _cst_get_input_number(char *buffer, void *data)
63 ENTER(_cst_get_input_number);
64 CstUgData_t *ugd = (CstUgData_t *)data;
65 const char *entry_input;
67 Ecore_IMF_Context *imf_ctx;
69 entry_input = elm_entry_entry_get(ugd->dg_entry);
70 retv_if(NULL == entry_input, -1);
71 if (strlen(entry_input) == 0) {
72 imf_ctx = elm_entry_imf_context_get(ugd->dg_entry);
74 ecore_imf_context_input_panel_hide(imf_ctx);
76 error = _cst_create_error_popup(ugd->nf, CST_ERROR_ENTER_NUMBER);
78 evas_object_show(error);
82 DBG("IME input string = %s length=%d", entry_input, strlen(entry_input));
84 snprintf(buffer, CST_MAX_PHONE_NUMBER_LEN, "%s", entry_input);
85 return strlen(entry_input);
88 void _cst_cf_ime_destroy_genlist_item_class(void)
90 ENTER(_cst_cf_ime_destroy_genlist_item_class);
91 DBG("\n\n *** Testing: CF-IME screen *** \n\n");
94 elm_genlist_item_class_free(itc_ime);
98 elm_genlist_item_class_free(itc_sep);
101 if (itc_waiting_time) {
102 elm_genlist_item_class_free(itc_waiting_time);
103 itc_waiting_time = NULL;
105 if (itc_waiting_time_expand) {
106 elm_genlist_item_class_free(itc_waiting_time_expand);
107 itc_waiting_time_expand = NULL;
111 static Evas_Object *__cst_gl_icon_get_cf_ime(void *data, Evas_Object *obj, const char *part)
113 retv_if(data == NULL, NULL);
114 CstUgData_t *ugd = (CstUgData_t *)data;
116 if (!strcmp(part, "elm.icon")) {
117 Evas_Object *ef = _cst_create_ime_editfield(ugd, obj, CST_IME_CALL_FORWARD, def_ime_number);
118 retv_if(ef == NULL, NULL);
120 return _cst_create_ime_btn_layout(obj, ef,
121 _cst_on_click_ime_contact_btn, (void *)ugd);
127 static int __cst_cf_ime_get_wait_time_index(int wait_time)
129 ENTER(__cst_cf_ime_get_wait_time_index);
132 if (wait_time == CST_CF_WAIT_TIME_5_SEC) {
133 index = CST_CF_WAIT_TIME_IDX_5_SEC;
134 } else if (wait_time == CST_CF_WAIT_TIME_10_SEC) {
135 index = CST_CF_WAIT_TIME_IDX_10_SEC;
136 } else if (wait_time == CST_CF_WAIT_TIME_15_SEC) {
137 index = CST_CF_WAIT_TIME_IDX_15_SEC;
138 } else if (wait_time == CST_CF_WAIT_TIME_20_SEC) {
139 index = CST_CF_WAIT_TIME_IDX_20_SEC;
140 } else if (wait_time == CST_CF_WAIT_TIME_25_SEC) {
141 index = CST_CF_WAIT_TIME_IDX_25_SEC;
143 index = CST_CF_WAIT_TIME_IDX_30_SEC;
149 static int __cst_cf_ime_get_wait_time(int wait_time_idx)
151 ENTER(__cst_cf_ime_get_wait_time);
154 if (wait_time_idx == CST_CF_WAIT_TIME_IDX_5_SEC) {
155 wait_time = CST_CF_WAIT_TIME_5_SEC;
156 } else if (wait_time_idx == CST_CF_WAIT_TIME_IDX_10_SEC) {
157 wait_time = CST_CF_WAIT_TIME_10_SEC;
158 } else if (wait_time_idx == CST_CF_WAIT_TIME_IDX_15_SEC) {
159 wait_time = CST_CF_WAIT_TIME_15_SEC;
160 } else if (wait_time_idx == CST_CF_WAIT_TIME_IDX_20_SEC) {
161 wait_time = CST_CF_WAIT_TIME_20_SEC;
162 } else if (wait_time_idx == CST_CF_WAIT_TIME_IDX_25_SEC) {
163 wait_time = CST_CF_WAIT_TIME_25_SEC;
165 wait_time = CST_CF_WAIT_TIME_30_SEC;
171 static void __cst_cf_ime_gl_sel_waiting_time(void *data, Evas_Object *obj, void *event_info)
173 elm_genlist_item_selected_set((Elm_Object_Item *)event_info, EINA_FALSE);
174 ret_if(NULL == data);
175 CstGlItemData_t *item_data = (CstGlItemData_t *)data;
177 curr_wait_time = __cst_cf_ime_get_wait_time((int)list_cf_ime_dep2_waiting_time[item_data->index].func);
179 if (waitingtime_radio_btn) {
180 elm_radio_value_set(waitingtime_radio_btn,
181 (int)list_cf_ime_dep2_waiting_time[item_data->index].func);
182 elm_genlist_item_update(item_data->parent_gl_item);
187 static void __cst_cf_ime_waiting_time_collapse_req(void *data, Evas_Object *obj, void *event_info)
189 ENTER(__cst_cf_ime_waiting_time_collapse_req);
190 Elm_Object_Item *item = (Elm_Object_Item *)event_info;
191 elm_genlist_item_expanded_set(item, 0);
194 static void __cst_cf_ime_waiting_time_collapse(int selected_time, Evas_Object *obj, void *event_info)
196 ENTER(__cst_cf_ime_waiting_time_collapse);
197 Elm_Object_Item *item = event_info;
198 int cf_wait_time_index = -1;
199 elm_genlist_item_subitems_clear(item);
201 cf_wait_time_index = __cst_cf_ime_get_wait_time_index(curr_wait_time);
203 if (selected_time != cf_wait_time_index) {
204 if (waitingtime_item) {
205 elm_genlist_item_update(waitingtime_item->gl_item);
210 static void __cst_cf_ime_waiting_time_expand_req(void *data, Evas_Object *obj, void *event_info)
212 ENTER(__cst_cf_ime_waiting_time_expand_req);
213 Elm_Object_Item *item = event_info;
214 elm_genlist_item_expanded_set(item, 1);
217 static void __cst_cf_ime_waiting_time_expand(void *data, Evas_Object *obj, void *event_info)
219 ENTER(__cst_cf_ime_waiting_time_expand);
220 ret_if(NULL == data);
221 CstGlItemData_t *item_data = (CstGlItemData_t *)data;
222 CstUgData_t *ugd = (CstUgData_t *)item_data->ugd;
223 Elm_Object_Item *it = (Elm_Object_Item *)event_info;
225 Evas_Object *genlist = elm_object_item_widget_get(it);
226 ret_if(NULL == genlist);
227 CstGlItemData_t *sub_item_data;
229 Ecore_IMF_Context *imf_ctx;
231 /* Hide the IMF if exists */
232 imf_ctx = elm_entry_imf_context_get(ugd->dg_entry);
234 ecore_imf_context_input_panel_hide(imf_ctx);
237 waitingtime_radio_btn = elm_radio_add(genlist);
238 elm_radio_value_set(waitingtime_radio_btn, -1);
239 for (i = 0; list_cf_ime_dep2_waiting_time[i].style != CST_GL_ITEM_NONE; ++i) {
240 sub_item_data = (CstGlItemData_t *)calloc(1, sizeof(CstGlItemData_t));
241 ret_if(sub_item_data == NULL);
242 sub_item_data->index = i;
243 sub_item_data->ugd = ugd;
244 sub_item_data->parent_gl_item = it;
245 elm_genlist_item_append(genlist, itc_waiting_time_expand,
246 (const void *)sub_item_data, it,
247 list_cf_ime_dep2_waiting_time[i].flags,
248 __cst_cf_ime_gl_sel_waiting_time, sub_item_data);
252 static void __cst_cf_ime_on_click_waitingtime_expand(void *data, Evas_Object *obj, void *event_info)
254 ENTER(__cst_cf_ime_on_click_waitingtime_expand);
255 ret_if(NULL == data);
256 Elm_Object_Item *item = (Elm_Object_Item *)event_info;
257 static int selected_waittime = -1;
259 elm_genlist_item_selected_set(item, EINA_FALSE);
260 if (elm_genlist_item_expanded_get(item)) {
261 __cst_cf_ime_waiting_time_collapse_req(data, obj, event_info);
262 __cst_cf_ime_waiting_time_collapse(selected_waittime, obj, event_info);
264 selected_waittime = __cst_cf_ime_get_wait_time_index(curr_wait_time);
265 __cst_cf_ime_waiting_time_expand_req(data, obj, event_info);
266 __cst_cf_ime_waiting_time_expand(data, obj, event_info);
270 static void __cst_cf_ime_gl_del(void *data, Evas_Object *obj)
272 ret_if(NULL == data);
273 CstGlItemData_t *item_data = (CstGlItemData_t *)data;
280 static Evas_Object *__cst_cf_ime_create_wait_time_radio_icon(Evas_Object *obj, Evas_Object *rdg, int value, int offset)
282 retv_if(NULL == obj, NULL);
285 Evas_Object *radio = elm_radio_add(obj);
286 elm_radio_state_value_set(radio, value);
287 elm_radio_group_add(radio, rdg);
289 rd_value = __cst_cf_ime_get_wait_time_index(curr_wait_time);
290 elm_radio_value_set(rdg, (rd_value + offset));
294 static Evas_Object *__cst_cf_ime_get_wait_time_sub_exp_icon(void *data, Evas_Object *obj, const char *part)
296 retv_if(NULL == data, NULL);
297 CstGlItemData_t *item_data = (CstGlItemData_t *)data;
299 if (!strcmp(part, "elm.icon")) {
300 Evas_Object *radio = NULL;
301 if (NULL == waitingtime_radio_btn) {
302 waitingtime_radio_btn = elm_radio_add(obj);
303 elm_radio_value_set(waitingtime_radio_btn, -1);
305 radio = __cst_cf_ime_create_wait_time_radio_icon(obj, waitingtime_radio_btn,
306 (int)list_cf_ime_dep2_waiting_time[item_data->index].func, 0);
312 static char *__cst_cf_ime_get_wait_time_sub_exp_label(void *data, Evas_Object *obj, const char *part)
314 retv_if(NULL == data, NULL);
315 CstGlItemData_t *item_data = (CstGlItemData_t *)data;
316 if (strcmp(part, "elm.text") == 0) {
317 return strdup(T_(list_cf_ime_dep2_waiting_time[item_data->index].str_id));
322 static char *__cst_cf_ime_cf_onoff_get_waiting_time_label(void *data, Evas_Object *obj, const char *part)
324 retv_if(NULL == data, NULL);
326 if (strcmp(part, "elm.text.1") == 0) {
327 return strdup(T_(CST_STR_WAITING_TIME));
328 } else if (strcmp(part, "elm.text.2") == 0) {
329 int cf_wait_time_index = __cst_cf_ime_get_wait_time_index(curr_wait_time);
330 if (list_cf_ime_dep2_waiting_time[cf_wait_time_index].str_id != -1) {
331 return strdup(T_(list_cf_ime_dep2_waiting_time[cf_wait_time_index].str_id));
337 static Evas_Object *__cst_create_cf_ime_genlist(CstUgData_t *ugd, int cf_flavour)
339 ENTER(__cst_create_cf_ime_genlist);
340 Evas_Object *genlist;
342 genlist = elm_genlist_add(ugd->nf);
343 _cst_create_genlist_separator(genlist, EINA_FALSE);
345 ugd->genlist_editfield_initialized = 0;
348 itc_ime = elm_genlist_item_class_new();
351 itc_sep = elm_genlist_item_class_new();
353 if (cf_flavour == CST_SSTYPE_CF_NO_REPLY) {
354 if (!itc_waiting_time) {
355 itc_waiting_time = elm_genlist_item_class_new();
357 if (!itc_waiting_time_expand) {
358 itc_waiting_time_expand = elm_genlist_item_class_new();
362 itc_ime->item_style = "dialogue/1icon";
363 itc_ime->func.text_get = NULL;
364 itc_ime->func.content_get = __cst_gl_icon_get_cf_ime;
365 itc_ime->func.state_get = NULL;
366 itc_ime->func.del = NULL;
368 itc_sep->item_style = "dialogue/seperator.4";
369 itc_sep->func.text_get = NULL;
370 itc_sep->func.content_get = NULL;
371 itc_sep->func.state_get = NULL;
372 itc_sep->func.del = NULL;
374 if (cf_flavour == CST_SSTYPE_CF_NO_REPLY) {
375 itc_waiting_time->item_style = "dialogue/2text.3/expandable";
376 itc_waiting_time->func.text_get = __cst_cf_ime_cf_onoff_get_waiting_time_label;
377 itc_waiting_time->func.content_get = NULL;
378 itc_waiting_time->func.state_get = NULL;
379 itc_waiting_time->func.del = NULL;
381 itc_waiting_time_expand->item_style = "dialogue/1text.1icon/expandable2";
382 itc_waiting_time_expand->func.text_get = __cst_cf_ime_get_wait_time_sub_exp_label;
383 itc_waiting_time_expand->func.content_get = __cst_cf_ime_get_wait_time_sub_exp_icon;
384 itc_waiting_time_expand->func.state_get = NULL;
385 itc_waiting_time_expand->func.del = __cst_cf_ime_gl_del;
386 waitingtime_item = (CstGlItemData_t *)calloc(1, sizeof(CstGlItemData_t));
387 retv_if(waitingtime_item == NULL, NULL);
388 waitingtime_item->ugd = ugd;
389 waitingtime_item->gl_item = NULL;
392 Elm_Object_Item *item = elm_genlist_item_append(genlist, itc_ime,
393 (void *)ugd, NULL, ELM_GENLIST_ITEM_NONE,
396 elm_genlist_item_select_mode_set(item, ELM_OBJECT_SELECT_MODE_DISPLAY_ONLY);
398 #ifdef _CALL_SET_OLD_SEPERATOR
399 elm_genlist_item_append(genlist, itc_sep,
400 NULL, NULL, ELM_GENLIST_ITEM_NONE,
403 elm_genlist_item_select_mode_set(item, ELM_OBJECT_SELECT_MODE_DISPLAY_ONLY);
405 if (cf_flavour == CST_SSTYPE_CF_NO_REPLY) {
406 #ifdef _CALL_SET_OLD_SEPERATOR
407 elm_genlist_item_append(genlist, itc_sep,
408 NULL, NULL, ELM_GENLIST_ITEM_NONE,
411 waitingtime_item->gl_item = elm_genlist_item_append(genlist, itc_waiting_time,
412 (const void *)waitingtime_item, NULL, ELM_GENLIST_ITEM_TREE,
413 __cst_cf_ime_on_click_waitingtime_expand, waitingtime_item);
419 int _cst_cf_ime_fetch_latest_wait_time(void)
421 ENTER(_cst_cf_ime_fetch_latest_wait_time);
423 return curr_wait_time;
426 static Eina_Bool __cst_cf_is_waiting_time_available(int wait_time)
428 Eina_Bool ret= EINA_FALSE;
432 case CST_CF_WAIT_TIME_5_SEC:
433 case CST_CF_WAIT_TIME_10_SEC:
434 case CST_CF_WAIT_TIME_15_SEC:
435 case CST_CF_WAIT_TIME_20_SEC:
436 case CST_CF_WAIT_TIME_25_SEC:
437 case CST_CF_WAIT_TIME_30_SEC:
441 case CST_CF_WAIT_TIME_NONE:
450 Evas_Object *_cst_create_cf_ime(Evas_Object *parent, char *edit_string,
451 int wait_time, int cf_flavour, void *data)
453 ENTER(_cst_create_cf_ime);
454 retv_if(data == NULL, NULL);
455 CstUgData_t *ugd = (CstUgData_t *)data;
456 Eina_Bool ret = EINA_FALSE;
458 if ((edit_string != NULL) && (strlen(edit_string) > 0)) {
459 def_ime_number = edit_string;
461 def_ime_number = NULL;
464 ret = __cst_cf_is_waiting_time_available(wait_time);
465 if (ret == EINA_TRUE) {
466 curr_wait_time = wait_time;
468 /* set default as 30 seconds */
469 curr_wait_time = CST_CF_WAIT_TIME_30_SEC;
472 Evas_Object *genlist = __cst_create_cf_ime_genlist(ugd, cf_flavour);