Fixed unable to input text to find hidden network
[apps/native/ug-wifi-efl.git] / sources / ui-gadget / viewers-layout / view_ime_hidden.c
1 /*
2  * Wi-Fi
3  *
4  * Copyright 2012 Samsung Electronics Co., Ltd
5  *
6  * Licensed under the Flora License, Version 1.0 (the "License");
7  * you may not use this file except in compliance with the License.
8  * You may obtain a copy of the License at
9  *
10  * http://www.tizenopensource.org/license
11  *
12  * Unless required by applicable law or agreed to in writing, software
13  * distributed under the License is distributed on an "AS IS" BASIS,
14  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15  * See the License for the specific language governing permissions and
16  * limitations under the License.
17  *
18  */
19
20 #include <feedback.h>
21
22 #include "ug_wifi.h"
23 #include "view_ime_hidden.h"
24 #include "i18nmanager.h"
25 #include "wlan_manager.h"
26 #include "viewer_manager.h"
27 #include "viewer_list.h"
28 #include "common_utils.h"
29
30 struct hiddep_ap_popup_data {
31         Evas_Object *win;
32         const char *str_pkg_name;
33         Evas_Object *popup;
34         Evas_Object *entry;
35         Evas_Object *ok_btn;
36 };
37
38 static hiddep_ap_popup_data_t *g_hidden_ap_popup_data = NULL;
39 static Elm_Genlist_Item_Class g_entry_itc;
40
41 static Eina_Bool _enable_scan_updates_cb(void *data)
42 {
43         /* Lets enable the scan updates */
44         wlan_manager_enable_scan_result_update();
45
46         /* Reset the ecore timer handle */
47         common_util_manager_ecore_scan_update_timer_reset();
48
49         return ECORE_CALLBACK_CANCEL;
50 }
51
52 static void __popup_entry_changed_cb(void* data, Evas_Object* obj, void* event_info)
53 {
54         if (g_hidden_ap_popup_data == NULL) {
55                 return;
56         }
57
58         hiddep_ap_popup_data_t *popup_data = g_hidden_ap_popup_data;
59         Evas_Object *ok_btn = popup_data->ok_btn;
60
61 //      if (elm_object_part_content_get(obj, "elm.swallow.clear")) {
62                 if (elm_object_focus_get(obj)) {
63                         if (elm_entry_is_empty(obj)) {
64                                 elm_object_signal_emit(obj, "elm,state,clear,hidden", "");
65                                 elm_object_disabled_set(ok_btn, EINA_TRUE);
66                                 elm_entry_input_panel_return_key_disabled_set(obj, EINA_TRUE);
67                         } else {
68                                 elm_object_signal_emit(obj, "elm,state,clear,visible", "");
69                                 elm_object_disabled_set(ok_btn, EINA_FALSE);
70                                 elm_entry_input_panel_return_key_disabled_set(obj, EINA_FALSE);
71                         }
72                 }
73 //      }
74 }
75
76 static void __popup_entry_focused_cb(void *data, Evas_Object *obj, void *event_info)
77 {
78         if (elm_object_part_content_get(obj, "elm.swallow.clear")) {
79                 if (!elm_entry_is_empty(obj)) {
80                         elm_object_signal_emit(obj, "elm,state,clear,visible", "");
81                 } else {
82                         elm_object_signal_emit(obj, "elm,state,clear,hidden", "");
83                 }
84         }
85         elm_object_signal_emit(obj, "elm,state,focus,on", "");
86 }
87
88 static void __popup_entry_unfocused_cb(void *data, Evas_Object *obj, void *event_info)
89 {
90         if (elm_object_part_content_get(obj, "elm.swallow.clear")) {
91                 elm_object_signal_emit(obj, "elm,state,clear,hidden", "");
92         }
93         elm_object_signal_emit(obj, "elm,state,focus,off", "");
94 }
95
96 static void __popup_entry_maxlength_reached(void *data, Evas_Object *obj,
97                 void *event_info)
98 {
99                 common_utils_send_message_to_net_popup("Password length",
100                                 "Lengthy Password", "notification", NULL);
101 }
102
103 static void __popup_entry_edit_mode_show_cb(void *data, Evas *e, Evas_Object *obj,
104                 void *event_info)
105 {
106         evas_object_event_callback_del(obj, EVAS_CALLBACK_SHOW,
107                         __popup_entry_edit_mode_show_cb);
108
109         elm_object_focus_set(obj, EINA_TRUE);
110 }
111
112 hiddep_ap_popup_data_t *view_hidden_ap_popup_data_get(void)
113 {
114         return g_hidden_ap_popup_data;
115 }
116
117 void view_hidden_ap_popup_delete(void)
118 {
119         if (g_hidden_ap_popup_data == NULL)
120                 return;
121
122         if (g_hidden_ap_popup_data->popup) {
123                 evas_object_del(g_hidden_ap_popup_data->popup);
124                 g_hidden_ap_popup_data->popup = NULL;
125         }
126
127         g_free(g_hidden_ap_popup_data);
128         g_hidden_ap_popup_data = NULL;
129 }
130
131 void view_hidden_ap_popup_destroy(void)
132 {
133         view_hidden_ap_popup_delete();
134
135         /* A delay is needed to get the smooth Input panel closing animation effect */
136         common_util_managed_ecore_scan_update_timer_add(0.1,
137                         _enable_scan_updates_cb, NULL);
138 }
139
140 static void view_hidden_ap_popup_ok_cb(void *data, Evas_Object *obj,
141                 void *event_info)
142 {
143         hiddep_ap_popup_data_t *popup_data = g_hidden_ap_popup_data;
144         char *entry_txt = NULL;
145         int err;
146
147         if (popup_data == NULL)
148                 return;
149
150         entry_txt = elm_entry_markup_to_utf8(elm_entry_entry_get(
151                         popup_data->entry));
152
153         err = wlan_manager_scan_with_ssid(entry_txt, entry_txt);
154         if (err != WLAN_MANAGER_ERR_NONE) {
155                 common_utils_send_message_to_net_popup("Network connection popup",
156                                 "no ap found", "notification", NULL);
157
158                 view_hidden_ap_popup_destroy();
159                 g_free(entry_txt);
160
161                 return;
162         }
163
164         viewer_manager_show(VIEWER_WINSET_SEARCHING);
165         viewer_manager_header_mode_set(HEADER_MODE_SEARCHING);
166
167         evas_object_del(popup_data->popup);
168         popup_data->popup = NULL;
169
170         /* A delay is needed to get the smooth Input panel closing animation effect */
171         common_util_managed_ecore_scan_update_timer_add(0.1,
172                         _enable_scan_updates_cb, NULL);
173 }
174
175 static void view_hidden_ap_popup_cancel_cb(void *data, Evas_Object *obj, void *event_info)
176 {
177         viewer_manager_request_scan();
178         view_hidden_ap_popup_destroy();
179 }
180
181 static Evas_Object *_gl_entry_item_content_get(void *data,
182                 Evas_Object *obj, const char *part)
183 {
184         if (obj == NULL) {
185                 return NULL;
186         }
187
188         int return_key_type;
189         Evas_Object *entry = NULL;
190         Evas_Object *editfield = NULL;
191
192         static Elm_Entry_Filter_Limit_Size limit_filter_data;
193
194         if (!g_strcmp0(part, "elm.swallow.content")) {
195                 editfield= elm_layout_add(obj);
196                 elm_layout_theme_set(editfield, "layout", "editfield", "singleline");
197                 evas_object_size_hint_weight_set(editfield, EVAS_HINT_EXPAND, 0.0);
198                 evas_object_size_hint_align_set(editfield, EVAS_HINT_FILL, 0.0);
199                 entry = elm_entry_add(editfield);
200                 elm_entry_single_line_set(entry, EINA_TRUE);
201                 elm_entry_scrollable_set(entry, EINA_TRUE);
202                 evas_object_size_hint_weight_set(entry, EVAS_HINT_EXPAND, 0.0);
203                 evas_object_size_hint_align_set(entry, EVAS_HINT_FILL, 0.0);
204                 if (!entry)
205                         return NULL;
206
207                 elm_entry_cnp_mode_set(entry, ELM_CNP_MODE_PLAINTEXT);
208                 elm_entry_input_panel_layout_set(entry, ELM_INPUT_PANEL_LAYOUT_NORMAL);
209                 elm_entry_prediction_allow_set(entry, EINA_FALSE);
210                 elm_entry_autocapital_type_set(entry, ELM_AUTOCAPITAL_TYPE_NONE);
211                 elm_object_domain_translatable_part_text_set(entry, "elm.guide",
212                                 PACKAGE, "IDS_ST_BODY_NETWORK_SSID");
213                 elm_object_signal_emit(entry, "elm,action,hide,search_icon", "");
214
215                 limit_filter_data.max_char_count = 32;
216                 elm_entry_markup_filter_append(entry, elm_entry_filter_limit_size,
217                                 &limit_filter_data);
218
219                 return_key_type = ECORE_IMF_INPUT_PANEL_RETURN_KEY_TYPE_DONE;
220                 elm_entry_input_panel_return_key_type_set(entry, return_key_type);
221                 elm_entry_input_panel_return_key_disabled_set(entry, EINA_TRUE);
222
223                 g_hidden_ap_popup_data->entry = entry;
224
225                 evas_object_smart_callback_add(entry, "activated",
226                                 view_hidden_ap_popup_ok_cb, NULL);
227                 evas_object_smart_callback_add(entry, "changed",
228                                 __popup_entry_changed_cb, NULL);
229                 evas_object_smart_callback_add(entry, "preedit,changed",
230                                 __popup_entry_changed_cb, NULL);
231                 evas_object_smart_callback_add(entry, "focused",
232                                 __popup_entry_focused_cb, NULL);
233                 evas_object_smart_callback_add(entry, "unfocused",
234                                 __popup_entry_unfocused_cb, NULL);
235                 evas_object_event_callback_add(entry, EVAS_CALLBACK_SHOW,
236                                 __popup_entry_edit_mode_show_cb, NULL);
237                 evas_object_smart_callback_add(entry, "maxlength,reached",
238                                 __popup_entry_maxlength_reached, NULL);
239
240                 elm_object_part_content_set(editfield, "elm.swallow.content", entry);
241                 elm_entry_input_panel_show(entry);
242
243                 return editfield;
244         }
245
246         return NULL;
247 }
248
249 static void popup_animation_finish_cb(void *data, Evas_Object *obj, void *event_info)
250 {
251         __COMMON_FUNC_ENTER__;
252         Elm_Object_Item *item = (Elm_Object_Item *) data;
253         Evas_Object *entry = NULL;
254
255         entry = elm_object_item_part_content_get(item, "elm.icon.entry");
256         elm_entry_input_panel_show(entry);
257         elm_object_focus_set(entry, EINA_TRUE);
258
259         __COMMON_FUNC_EXIT__;
260 }
261
262 void view_hidden_ap_popup_create(Evas_Object *win_main, const char *str_pkg_name)
263 {
264         __COMMON_FUNC_ENTER__;
265
266         Evas_Object *passpopup = NULL;
267         Evas_Object *genlist = NULL;
268         popup_btn_info_t popup_data;
269
270         if (win_main == NULL) {
271                 INFO_LOG(UG_NAME_ERR, "Invalid argument passed.");
272                 return;
273         }
274
275         if (g_hidden_ap_popup_data != NULL) {
276                 if (g_hidden_ap_popup_data->popup != NULL) {
277                         evas_object_del(g_hidden_ap_popup_data->popup);
278                         g_hidden_ap_popup_data->popup = NULL;
279                 }
280                 g_free(g_hidden_ap_popup_data);
281         }
282
283         g_hidden_ap_popup_data = g_try_new0(hiddep_ap_popup_data_t, 1);
284         if (g_hidden_ap_popup_data == NULL) {
285                 INFO_LOG(UG_NAME_ERR, "Memory allocation error.");
286                 return;
287         }
288
289         /* Lets disable the scan updates so that the UI is not refreshed un necessarily */
290         wlan_manager_disable_scan_result_update();
291
292         memset(&popup_data, 0, sizeof(popup_data));
293         popup_data.title_txt = "IDS_WIFI_BUTTON_FIND_HIDDEN_NETWORK";
294         popup_data.btn1_cb = view_hidden_ap_popup_cancel_cb;
295         popup_data.btn1_data = NULL;
296         popup_data.btn1_txt = "IDS_WIFI_SK_CANCEL";
297         popup_data.btn2_cb = view_hidden_ap_popup_ok_cb;
298         popup_data.btn2_data = NULL;
299         popup_data.btn2_txt = "IDS_COM_BODY_FIND";
300
301         passpopup = common_utils_show_info_popup(win_main, &popup_data);
302         g_hidden_ap_popup_data->ok_btn = popup_data.btn;
303         elm_object_disabled_set(g_hidden_ap_popup_data->ok_btn, EINA_TRUE);
304
305         g_hidden_ap_popup_data->win = win_main;
306         g_hidden_ap_popup_data->str_pkg_name = str_pkg_name;
307         g_hidden_ap_popup_data->popup = passpopup;
308
309         genlist = elm_genlist_add(passpopup);
310         evas_object_size_hint_weight_set(genlist, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
311         evas_object_size_hint_align_set(genlist, EVAS_HINT_FILL, EVAS_HINT_FILL);
312         //elm_genlist_realization_mode_set(genlist, EINA_TRUE);
313         elm_scroller_content_min_limit(genlist, EINA_FALSE, EINA_TRUE);
314
315         g_entry_itc.item_style = "full";
316         g_entry_itc.func.text_get = NULL;
317         g_entry_itc.func.content_get = _gl_entry_item_content_get;
318         g_entry_itc.func.state_get = NULL;
319         g_entry_itc.func.del = NULL;
320
321         Elm_Object_Item * entry_item = elm_genlist_item_append(genlist,
322                         &g_entry_itc, NULL, NULL, ELM_GENLIST_ITEM_NONE,
323                         NULL, NULL);
324
325         evas_object_smart_callback_add(passpopup, "show,finished",
326                         popup_animation_finish_cb, entry_item);
327
328         evas_object_show(genlist);
329         elm_object_content_set(passpopup, genlist);
330         evas_object_show(passpopup);
331
332         __COMMON_FUNC_EXIT__;
333 }