1a2522b4fcfa1d509df03209b74d5f2df54b3908
[apps/core/preloaded/ciss.git] / src / ciss-respnd.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 "ciss-respnd.h"
18 #include "ciss-common.h"
19 #include "ciss-widget.h"
20 #include "ciss-tapi-request.h"
21 #include <Ecore_IMF.h>
22
23 typedef enum {
24         BT_KOR_MODE = 0,
25         BT_CHINESE_MODE = 1, /* Not support yet */ 
26         BT_ENG_LOWER_MODE = 2,
27         BT_ENG_UPPER_MODE = 3,
28         BT_NUMBER_MODE = 4,
29         BT_SYMBOL_MODE = 5,
30         BT_SYMBOL2_MODE = 6,
31         BT_SYMBOL3_MODE = 7,
32         BT_JAPANESE_MODE = 8,
33         BT_ENV_MODE = 9
34 } ciss_ime_mode_t;
35
36 static Elm_Entry_Filter_Limit_Size limit_filter_data;
37
38 static void __ciss_respond_cb(void *data, Evas_Object *obj, void *event_info)
39 {
40         DBG("coming inside __ciss_respond_cb \n");
41         int ret;
42         char *buf;
43         char ussd_str[TAPI_SS_USSD_DATA_SIZE_MAX] = {0, };
44         Ecore_IMF_Context *imf_context;
45         Evas_Object *error_popup;
46         ciss_mmi_context_t mmi_ctx;
47         ciss_appdata_t *ad = (ciss_appdata_t *)data;
48
49         buf = (char *)elm_entry_entry_get(ad->ef_entry);
50         imf_context = elm_entry_imf_context_get(ad->ef_entry);
51         if (imf_context)
52                 ecore_imf_context_input_panel_hide(imf_context);
53
54         snprintf(ussd_str, TAPI_SS_USSD_DATA_SIZE_MAX, "%s", buf);
55         if (strlen(ussd_str) == 0) {
56                 error_popup = _ciss_create_popup(ad->nf, CISS_STR_ENTER_NUMBER);
57                 evas_object_show(error_popup);
58                 return;
59         }
60
61         DBG("The data is %s %d \n", ussd_str, strlen(buf));
62
63         memset(&mmi_ctx, 0x0, sizeof(ciss_mmi_context_t));
64         mmi_ctx.opcode = unstructuredSS_Request;
65         mmi_ctx.ussd_type = TAPI_SS_USSD_TYPE_USER_RSP;
66         mmi_ctx.user_string_length = strlen(ussd_str);
67         memcpy(mmi_ctx.user_string, ussd_str, MAX_USS_CHAR);
68
69         ad->popup = _ciss_create_noti_popup(ad->win_main,
70                                 CISS_STR_REQUESTING, NULL, POPUP_DISPLAY_DURATION, ad);
71
72         ret = _ciss_send_tapi_request(&mmi_ctx, ad);
73
74         DBG("The value of ret is  %d \n", ret);
75 }
76
77 static void __ciss_changed_cb(void *data, Evas_Object *obj, void *event_info)
78 {
79         ret_if(NULL == data);
80
81         ciss_appdata_t *ad = (ciss_appdata_t *)data;
82         Evas_Object *editfield = ad->ef_layout;
83         Elm_Object_Item *navi_it = elm_naviframe_top_item_get(ad->nf);
84         ret_if(!navi_it);
85
86         if (elm_object_focus_get(editfield)) {
87                 Evas_Object *btn = elm_object_item_part_content_get(navi_it,
88                         "title_right_btn");
89
90                 if (elm_entry_is_empty(obj)) {
91                         elm_object_signal_emit(editfield, "elm,state,eraser,hide", "elm");
92                         if (btn)
93                                 elm_object_disabled_set(btn, EINA_TRUE);
94                 } else {
95                         elm_object_signal_emit(editfield, "elm,state,eraser,show", "elm");
96                         if (btn)
97                                 elm_object_disabled_set(btn, EINA_FALSE);
98                 }
99         }
100 }
101
102 static void __ciss_focused_cb(void *data, Evas_Object *obj, void *event_info)
103 {
104         ret_if(NULL == data);
105         ciss_appdata_t *ad = (ciss_appdata_t *)data;
106         Evas_Object *editfield = ad->ef_layout;
107
108         if (!elm_entry_is_empty(obj))
109                 elm_object_signal_emit(editfield, "elm,state,eraser,show", "elm");
110         elm_object_signal_emit(editfield, "elm,state,guidetext,hide", "elm");
111 }
112
113 static void __ciss_unfocused_cb(void *data, Evas_Object *obj, void *event_info)
114 {
115         ret_if(NULL == data);
116         ciss_appdata_t *ad = (ciss_appdata_t *)data;
117         Evas_Object *editfield = ad->ef_layout;
118
119         if (elm_entry_is_empty(obj))
120                 elm_object_signal_emit(editfield, "elm,state,guidetext,show", "elm");
121         elm_object_signal_emit(editfield, "elm,state,eraser,hide", "elm");
122 }
123
124 static void __ciss_eraser_clicked_cb(void *data, Evas_Object *obj, const char *emission, const char *source)
125 {
126         elm_entry_entry_set(data, "");
127 }
128
129 static Evas_Object *__ciss_editfield_add(Evas_Object *parent, void *data)
130 {
131         retv_if(data == NULL, NULL);
132         ciss_appdata_t *ad = (ciss_appdata_t *)data;
133
134         Evas_Object *layout = NULL;
135         Evas_Object *entry = NULL;
136
137         layout = elm_layout_add(parent);
138         ad->ef_layout = layout;
139         elm_layout_theme_set(layout, "layout", "editfield", "title");
140
141         entry = elm_entry_add(parent);
142         ad->ef_entry = entry;
143         elm_entry_scrollable_set(entry, EINA_TRUE);
144         elm_entry_single_line_set(entry, EINA_TRUE);
145
146         limit_filter_data.max_char_count = 0;
147         limit_filter_data.max_byte_count = TAPI_SS_USSD_DATA_SIZE_MAX;
148         elm_entry_markup_filter_append(entry, elm_entry_filter_limit_size, &limit_filter_data);
149         evas_object_smart_callback_add(entry, "changed", __ciss_changed_cb, ad);
150         evas_object_smart_callback_add(entry, "focused", __ciss_focused_cb, ad);
151         evas_object_smart_callback_add(entry, "unfocused", __ciss_unfocused_cb, ad);
152         evas_object_show(entry);
153
154         elm_object_part_content_set(layout, "elm.swallow.content", entry);
155         elm_object_part_text_set(layout, "elm.text", CISS_STR_ENTER_NUMBER);
156         elm_object_signal_callback_add(layout, "elm,eraser,clicked", "elm", __ciss_eraser_clicked_cb, entry);
157         elm_object_focus_set(entry, EINA_TRUE);
158
159         return layout;
160 }
161
162 static Evas_Object *__ciss_gl_content_respond_ime(void *data, Evas_Object *obj, const char *part)
163 {
164         Evas_Object *editfield = NULL;
165
166         if (!strcmp(part, "elm.icon")) {
167                 editfield = __ciss_editfield_add(obj, data);
168                 return editfield;
169         }
170
171         return NULL;
172 }
173
174 static Evas_Object *__ciss_respond_ime_genlist(void *data)
175 {
176         Elm_Object_Item *item = NULL;
177         Evas_Object *genlist;
178         ciss_appdata_t *ad = (ciss_appdata_t *)data;
179
180         genlist = elm_genlist_add(ad->nf);
181         elm_object_style_set(genlist, "dialogue");
182         _ciss_create_genlist_separator_no_line(genlist, ad);
183         _ciss_create_genlist_underline(genlist, ad);
184
185         ad->itc_ime->item_style = "1icon";
186         ad->itc_ime->func.text_get = NULL;
187         ad->itc_ime->func.content_get = __ciss_gl_content_respond_ime;
188         ad->itc_ime->func.state_get = NULL;
189         ad->itc_ime->func.del = NULL;
190
191         item = elm_genlist_item_append(genlist, ad->itc_ime,
192                         (void *)ad, NULL, ELM_GENLIST_ITEM_NONE,
193                         NULL, NULL);
194         return genlist;
195 }
196
197 void _ciss_create_respond_view(void *data)
198 {
199         DBG("Enter");
200         ciss_appdata_t *ad = (ciss_appdata_t *)data;
201         Evas_Object *ime_genlist;
202         Elm_Object_Item *navi_it = NULL;
203         Evas_Object *btn = NULL;
204
205         ime_genlist = __ciss_respond_ime_genlist(ad);
206
207         _ciss_remove_naviframe(ad->nf);
208         navi_it = elm_naviframe_item_push(ad->nf, CISS_STR_INFORMATION,
209                 NULL, NULL, ime_genlist, "1line");
210
211         btn = _ciss_create_title_btn(ad->nf, CISS_STR_QUIT,
212                 _ciss_ussd_quit_cb, (void *)ad);
213         elm_object_item_part_content_set(navi_it, "title_left_btn", btn);
214
215         btn = _ciss_create_title_btn(ad->nf, CISS_STR_REPLY,
216                 __ciss_respond_cb, (void *)ad);
217         elm_object_item_part_content_set(navi_it, "title_right_btn", btn);
218         elm_object_disabled_set(btn, EINA_TRUE);
219 }