Tizen release 1.0
[pkgs/c/ciss.git] / src / ciss-respnd.c
1 /*
2  * Copyright (c) 2000 - 2012 Samsung Electronics Co., Ltd All Rights Reserved 
3  *
4  * This file is part of <ciss>
5  * Written by <Sungjoon Won> <sungjoon.won@samsung.com>, <Jungmin Kim> <jm15.kim@samsung.com>
6  *
7  * PROPRIETARY/CONFIDENTIAL
8  *
9  * This software is the confidential and proprietary information of SAMSUNG ELECTRONICS ("Confidential Information").
10  * You shall not disclose such Confidential Information and shall use it only in accordance
11  * with the terms of the license agreement you entered into with SAMSUNG ELECTRONICS.
12  * SAMSUNG make no representations or warranties about the suitability of the software,
13  * either express or implied, including but not limited to the implied warranties of merchantability,
14  * fitness for a particular purpose, or non-infringement.
15  * SAMSUNG shall not be liable for any damages suffered by licensee as a result of using,
16  * modifying or distributing this software or its derivatives.
17  *
18  */
19
20 #include "ciss-respnd.h"
21 #include "ciss-common.h"
22 #include "ciss-widget.h"
23 #include <TapiEvent.h>
24 #include <Ecore_IMF.h>
25
26 typedef enum {
27         BT_KOR_MODE = 0,
28         BT_CHINESE_MODE = 1, /* Not support yet */
29         BT_ENG_LOWER_MODE = 2,
30         BT_ENG_UPPER_MODE = 3,
31         BT_NUMBER_MODE = 4,
32         BT_SYMBOL_MODE = 5,
33         BT_SYMBOL2_MODE = 6,
34         BT_SYMBOL3_MODE = 7,
35         BT_JAPANESE_MODE = 8,
36         BT_ENV_MODE = 9
37 } ciss_ime_mode_t;
38
39 static Elm_Entry_Filter_Limit_Size limit_filter_data;
40
41 static void __ciss_respond_cb(void *data, Evas_Object *obj, void *event_info)
42 {
43         DBG("coming inside __ciss_respond_cb \n");
44         int ret;
45         char *buf;
46         char ussd_str[TAPI_SS_USSD_DATA_SIZE_MAX] = {0, };
47         int pRequestId = 0;
48         Ecore_IMF_Context *imf_context;
49         Evas_Object *error_popup;
50         struct appdata *ad = (struct appdata *)data;
51
52         buf = (char *)elm_entry_entry_get(ad->ef_entry);
53         imf_context = elm_entry_imf_context_get(ad->ef_entry);
54         if (imf_context)
55                 ecore_imf_context_input_panel_hide(imf_context);
56
57         snprintf(ussd_str, TAPI_SS_USSD_DATA_SIZE_MAX, "%s", buf);
58         if (strlen(ussd_str) == 0) {
59                 error_popup = _ciss_create_popup(ad->nf, CISS_STR_ENTER_NUMBER);
60                 evas_object_show(error_popup);
61                 return;
62         }
63
64         DBG("The data is %s %d \n", ussd_str, strlen(buf));
65
66         TelSsUssdMsgInfo_t ussdRspRecord;
67         memset(&ussdRspRecord, 0, sizeof(TelSsUssdMsgInfo_t));
68         strncpy(ussdRspRecord.szUssdString, ussd_str, sizeof(ussdRspRecord.szUssdString) - 1);
69         ussdRspRecord.szUssdString[strlen(ussdRspRecord.szUssdString)] = '\0';
70         ussdRspRecord.UssdStringLength = strlen(ussdRspRecord.szUssdString);
71         ad->popup = _ciss_create_noti_popup(ad->win_main,
72                                 CISS_STR_REQUESTING, NULL, POPUP_DISPLAY_DURATION, ad);
73         ret = tel_send_ss_ussd_response(&ussdRspRecord, &pRequestId);
74
75         DBG("The value of ret is  %d and request id is %d \n", ret, pRequestId);
76         ad->request_id = pRequestId;    /* of no use as of now */
77 }
78
79 static void __ciss_changed_cb(void *data, Evas_Object *obj, void *event_info)
80 {
81         ret_if(NULL == data);
82
83         struct appdata *ad = (struct appdata *)data;
84         Evas_Object *editfield = ad->ef_layout;
85         Elm_Object_Item *navi_it = elm_naviframe_top_item_get(ad->nf);
86         ret_if(!navi_it);
87
88         if (elm_object_focus_get(editfield)) {
89                 Evas_Object *btn = elm_object_item_part_content_get(navi_it,
90                         "title_right_btn");
91
92                 if (elm_entry_is_empty(obj)) {
93                         elm_object_signal_emit(editfield, "elm,state,eraser,hide", "elm");
94                         if (btn)
95                                 elm_object_disabled_set(btn, EINA_TRUE);
96                 } else {
97                         elm_object_signal_emit(editfield, "elm,state,eraser,show", "elm");
98                         if (btn)
99                                 elm_object_disabled_set(btn, EINA_FALSE);
100                 }
101         }
102 }
103
104 static void __ciss_focused_cb(void *data, Evas_Object *obj, void *event_info)
105 {
106         ret_if(NULL == data);
107         struct appdata *ad = (struct appdata *)data;
108         Evas_Object *editfield = ad->ef_layout;
109
110         if (!elm_entry_is_empty(obj))
111                 elm_object_signal_emit(editfield, "elm,state,eraser,show", "elm");
112         elm_object_signal_emit(editfield, "elm,state,guidetext,hide", "elm");
113 }
114
115 static void __ciss_unfocused_cb(void *data, Evas_Object *obj, void *event_info)
116 {
117         ret_if(NULL == data);
118         struct appdata *ad = (struct appdata *)data;
119         Evas_Object *editfield = ad->ef_layout;
120
121         if (elm_entry_is_empty(obj))
122                 elm_object_signal_emit(editfield, "elm,state,guidetext,show", "elm");
123         elm_object_signal_emit(editfield, "elm,state,eraser,hide", "elm");
124 }
125
126 static void __ciss_eraser_clicked_cb(void *data, Evas_Object *obj, const char *emission, const char *source)
127 {
128         elm_entry_entry_set(data, "");
129 }
130
131 static Evas_Object *__ciss_editfield_add(Evas_Object *parent, void *data)
132 {
133         retv_if(data == NULL, NULL);
134         struct appdata *ad = (struct appdata *)data;
135
136         Evas_Object *layout = NULL;
137         Evas_Object *entry = NULL;
138
139         layout = elm_layout_add(parent);
140         ad->ef_layout = layout;
141         elm_layout_theme_set(layout, "layout", "editfield", "title");
142
143         entry = elm_entry_add(parent);
144         ad->ef_entry = entry;
145         elm_entry_scrollable_set(entry, EINA_TRUE);
146         elm_entry_single_line_set(entry, EINA_TRUE);
147
148         limit_filter_data.max_char_count = 0;
149         limit_filter_data.max_byte_count = TAPI_SS_USSD_DATA_SIZE_MAX;
150         elm_entry_markup_filter_append(entry, elm_entry_filter_limit_size, &limit_filter_data);
151         evas_object_smart_callback_add(entry, "changed", __ciss_changed_cb, ad);
152         evas_object_smart_callback_add(entry, "focused", __ciss_focused_cb, ad);
153         evas_object_smart_callback_add(entry, "unfocused", __ciss_unfocused_cb, ad);
154         evas_object_show(entry);
155
156         elm_object_part_content_set(layout, "elm.swallow.content", entry);
157         elm_object_part_text_set(layout, "elm.text", CISS_STR_ENTER_NUMBER);
158         elm_object_signal_callback_add(layout, "elm,eraser,clicked", "elm", __ciss_eraser_clicked_cb, entry);
159         elm_object_focus_set(entry, EINA_TRUE);
160
161         return layout;
162 }
163
164 static Evas_Object *__ciss_gl_content_respond_ime(void *data, Evas_Object *obj, const char *part)
165 {
166         Evas_Object *editfield = NULL;
167
168         if (!strcmp(part, "elm.icon")) {
169                 editfield = __ciss_editfield_add(obj, data);
170                 return editfield;
171         }
172
173         return NULL;
174 }
175
176 static Evas_Object *__ciss_respond_ime_genlist(void *data)
177 {
178         Elm_Object_Item *item = NULL;
179         Evas_Object *genlist;
180         struct appdata *ad = (struct appdata *)data;
181
182         genlist = elm_genlist_add(ad->nf);
183
184         ad->itc_ime->item_style = "1icon";
185         ad->itc_ime->func.text_get = NULL;
186         ad->itc_ime->func.content_get = __ciss_gl_content_respond_ime;
187         ad->itc_ime->func.state_get = NULL;
188         ad->itc_ime->func.del = NULL;
189
190         item = elm_genlist_item_append(genlist, ad->itc_ime,
191                         (void *)ad, NULL, ELM_GENLIST_ITEM_NONE,
192                         NULL, NULL);
193         return genlist;
194 }
195
196 void _ciss_create_respond_view(void *data)
197 {
198         DBG("Enter");
199         struct appdata *ad = (struct appdata *)data;
200         Evas_Object *ime_genlist;
201         Elm_Object_Item *navi_it = NULL;
202         Evas_Object *btn = NULL;
203
204         ime_genlist = __ciss_respond_ime_genlist(ad);
205
206         _ciss_remove_naviframe(ad->nf);
207         navi_it = elm_naviframe_item_push(ad->nf, CISS_STR_INFORMATION,
208                 NULL, NULL, ime_genlist, "1line");
209
210         btn = _cst_create_title_btn(ad->nf, CISS_STR_QUIT,
211                 _ciss_ussd_quit_cb, (void *)ad);
212         elm_object_item_part_content_set(navi_it, "title_left_btn", btn);
213
214         btn = _cst_create_title_btn(ad->nf, CISS_STR_REPLY,
215                 __ciss_respond_cb, (void *)ad);
216         elm_object_item_part_content_set(navi_it, "title_right_btn", btn);
217         elm_object_disabled_set(btn, EINA_TRUE);
218 }