2012/08/21: tizen 2.0 beta
[apps/home/call-setting.git] / src / cst-barring-ime.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 #include <Elementary.h>
18
19 #include "cst-common.h"
20 #include "cst-common-string.h"
21
22 #include "cst-widget.h"
23 #include "cst-barring-ime.h"
24
25 static Elm_Genlist_Item_Class *itc_ime = NULL;
26
27 int _cst_get_cb_input_password(char *buffer, void *data)
28 {
29         ENTER(_cst_get_cb_input_password);
30         CstUgData_t *ugd = (CstUgData_t *)data;
31         retv_if(!ugd, -1);
32         const char *entry_input;
33         Evas_Object *error;
34         Ecore_IMF_Context *imf_ctx;
35
36         entry_input = elm_entry_entry_get(ugd->dg_entry);
37         retv_if(!entry_input, -1);
38         if (strlen(entry_input) == 0) {
39                 imf_ctx = elm_entry_imf_context_get(ugd->dg_entry);
40                 if (imf_ctx) {
41                         ecore_imf_context_input_panel_hide(imf_ctx);
42                 }
43                 error = _cst_create_error_popup(ugd->nf, CST_ERROR_ENTER_NUMBER);
44                 retv_if(!error, -1);
45                 ugd->popup = error;
46                 evas_object_show(error);
47                 return -1;
48         }
49
50         DBG("IME input string = %s length=%d", entry_input, strlen(entry_input));
51
52         snprintf(buffer, CST_MAX_PHONE_NUMBER_LEN, "%s", entry_input);
53         return strlen(entry_input);
54 }
55
56 static Evas_Object *__cst_gl_icon_get_cb_ime(void *data, Evas_Object *obj, const char *part)
57 {
58         retv_if(data == NULL, NULL);
59         CstUgData_t *ugd = (CstUgData_t *)data;
60
61         if (!strcmp(part, "elm.icon")) {
62                 return _cst_create_ime_editfield(ugd, obj, CST_IME_CALL_BAR, NULL);
63         }
64
65         return NULL;
66 }
67
68 static Evas_Object *__cst_create_cb_ime_genlist(CstUgData_t *ugd)
69 {
70         ENTER(__cst_create_cb_ime_genlist);
71         Elm_Object_Item *item = NULL;
72         Evas_Object *genlist;
73
74         genlist = elm_genlist_add(ugd->nf);
75         elm_object_style_set(genlist, "dialogue");
76
77         if (!itc_ime)
78                 itc_ime = elm_genlist_item_class_new();
79
80         itc_ime->item_style = "1icon";
81         itc_ime->func.text_get = NULL;
82         itc_ime->func.content_get = __cst_gl_icon_get_cb_ime;
83         itc_ime->func.state_get = NULL;
84         itc_ime->func.del = NULL;
85
86         item = elm_genlist_item_append(genlist, itc_ime,
87                 (void *)ugd, NULL, ELM_GENLIST_ITEM_NONE,
88                 NULL, NULL);
89         return genlist;
90 }
91
92 Evas_Object *_cst_create_cb_ime(Evas_Object *parent, char *edit_string, void *data)
93 {
94         ENTER(_cst_create_cb_ime);
95         retv_if(NULL == data, NULL);
96         CstUgData_t *ugd = (CstUgData_t *)data;
97
98         Evas_Object *genlist = __cst_create_cb_ime_genlist(ugd);
99         return genlist;
100 }
101