6013fffee1e670d7866869511a85066a4d50c608
[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 #include <efl_assist.h>
22
23 #include "ug_wifi.h"
24 #include "view_ime_hidden.h"
25 #include "i18nmanager.h"
26 #include "wlan_manager.h"
27 #include "viewer_manager.h"
28 #include "viewer_list.h"
29 #include "common_utils.h"
30
31 struct hiddep_ap_popup_data {
32         Evas_Object *win;
33         const char *str_pkg_name;
34         Evas_Object *popup;
35         Evas_Object *entry;
36         Evas_Object *ok_btn;
37 };
38
39 static hiddep_ap_popup_data_t *g_hidden_ap_popup_data = NULL;
40 static Elm_Genlist_Item_Class g_entry_itc;
41
42 static Eina_Bool _enable_scan_updates_cb(void *data)
43 {
44         /* Lets enable the scan updates */
45         wlan_manager_enable_scan_result_update();
46
47         /* Reset the ecore timer handle */
48         common_util_manager_ecore_scan_update_timer_reset();
49
50         return ECORE_CALLBACK_CANCEL;
51 }
52
53 static void __popup_entry_changed_cb(void* data, Evas_Object* obj, void* event_info)
54 {
55         if (g_hidden_ap_popup_data == NULL) {
56                 return;
57         }
58
59         hiddep_ap_popup_data_t *popup_data = g_hidden_ap_popup_data;
60         Evas_Object *ok_btn = popup_data->ok_btn;
61
62 //      if (elm_object_part_content_get(obj, "elm.swallow.clear")) {
63                 if (elm_object_focus_get(obj)) {
64                         if (elm_entry_is_empty(obj)) {
65                                 elm_object_signal_emit(obj, "elm,state,clear,hidden", "");
66                                 elm_object_disabled_set(ok_btn, EINA_TRUE);
67                                 elm_entry_input_panel_return_key_disabled_set(obj, EINA_TRUE);
68                         } else {
69                                 elm_object_signal_emit(obj, "elm,state,clear,visible", "");
70                                 elm_object_disabled_set(ok_btn, EINA_FALSE);
71                                 elm_entry_input_panel_return_key_disabled_set(obj, EINA_FALSE);
72                         }
73                 }
74 //      }
75 }
76
77 static void __popup_entry_focused_cb(void *data, Evas_Object *obj, void *event_info)
78 {
79         if (elm_object_part_content_get(obj, "elm.swallow.clear")) {
80                 if (!elm_entry_is_empty(obj)) {
81                         elm_object_signal_emit(obj, "elm,state,clear,visible", "");
82                 } else {
83                         elm_object_signal_emit(obj, "elm,state,clear,hidden", "");
84                 }
85         }
86         elm_object_signal_emit(obj, "elm,state,focus,on", "");
87 }
88
89 static void __popup_entry_unfocused_cb(void *data, Evas_Object *obj, void *event_info)
90 {
91         if (elm_object_part_content_get(obj, "elm.swallow.clear")) {
92                 elm_object_signal_emit(obj, "elm,state,clear,hidden", "");
93         }
94         elm_object_signal_emit(obj, "elm,state,focus,off", "");
95 }
96
97 static void __popup_entry_maxlength_reached(void *data, Evas_Object *obj,
98                 void *event_info)
99 {
100                 common_utils_send_message_to_net_popup("Password length",
101                                 "Lengthy Password", "notification", NULL);
102 }
103
104 hiddep_ap_popup_data_t *view_hidden_ap_popup_data_get(void)
105 {
106         return g_hidden_ap_popup_data;
107 }
108
109 void view_hidden_ap_popup_delete(void)
110 {
111         if (g_hidden_ap_popup_data == NULL)
112                 return;
113
114         if (g_hidden_ap_popup_data->popup) {
115                 evas_object_del(g_hidden_ap_popup_data->popup);
116                 g_hidden_ap_popup_data->popup = NULL;
117         }
118
119         g_free(g_hidden_ap_popup_data);
120         g_hidden_ap_popup_data = NULL;
121 }
122
123 void view_hidden_ap_popup_destroy(void)
124 {
125         view_hidden_ap_popup_delete();
126
127         /* A delay is needed to get the smooth Input panel closing animation effect */
128         common_util_managed_ecore_scan_update_timer_add(0.1,
129                         _enable_scan_updates_cb, NULL);
130 }
131
132 static void view_hidden_ap_popup_ok_cb(void *data, Evas_Object *obj,
133                 void *event_info)
134 {
135         hiddep_ap_popup_data_t *popup_data = g_hidden_ap_popup_data;
136         char *entry_txt = NULL;
137         int err;
138
139         if (popup_data == NULL)
140                 return;
141
142         entry_txt = elm_entry_markup_to_utf8(elm_entry_entry_get(
143                         popup_data->entry));
144
145         err = wlan_manager_scan_with_ssid(entry_txt, entry_txt);
146         if (err != WLAN_MANAGER_ERR_NONE) {
147                 common_utils_send_message_to_net_popup("Network connection popup",
148                                 "no ap found", "notification", NULL);
149
150                 view_hidden_ap_popup_destroy();
151                 g_free(entry_txt);
152
153                 return;
154         }
155
156         viewer_manager_show(VIEWER_WINSET_SEARCHING);
157         viewer_manager_header_mode_set(HEADER_MODE_SEARCHING);
158
159         evas_object_del(popup_data->popup);
160         popup_data->popup = NULL;
161
162         /* A delay is needed to get the smooth Input panel closing animation effect */
163         common_util_managed_ecore_scan_update_timer_add(0.1,
164                         _enable_scan_updates_cb, NULL);
165 }
166
167 static void view_hidden_ap_popup_cancel_cb(void *data, Evas_Object *obj, void *event_info)
168 {
169         viewer_manager_request_scan();
170         view_hidden_ap_popup_destroy();
171 }
172
173 static Evas_Object *_gl_entry_item_content_get(void *data,
174                 Evas_Object *obj, const char *part)
175 {
176         if (obj == NULL) {
177                 return NULL;
178         }
179
180         int return_key_type;
181         Evas_Object *entry = NULL;
182
183         static Elm_Entry_Filter_Limit_Size limit_filter_data;
184
185         if (!g_strcmp0(part, "elm.icon.entry")) {
186                 entry = elm_entry_add(obj);
187                 elm_layout_theme_set(entry, "layout", "editfield", "singleline");
188                 evas_object_size_hint_weight_set(entry, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
189                 evas_object_size_hint_align_set(entry, EVAS_HINT_FILL, EVAS_HINT_FILL);
190                 elm_entry_single_line_set(entry, EINA_TRUE);
191                 elm_entry_scrollable_set(entry, EINA_TRUE);
192                 if (!entry)
193                         return NULL;
194
195                 elm_entry_cnp_mode_set(entry, ELM_CNP_MODE_PLAINTEXT);
196                 elm_entry_input_panel_layout_set(entry, ELM_INPUT_PANEL_LAYOUT_NORMAL);
197                 elm_entry_prediction_allow_set(entry, EINA_FALSE);
198                 elm_entry_autocapital_type_set(entry, ELM_AUTOCAPITAL_TYPE_NONE);
199                 elm_object_domain_translatable_part_text_set(entry, "elm.guide",
200                                 PACKAGE, "IDS_ST_BODY_NETWORK_SSID");
201                 elm_object_signal_emit(entry, "elm,action,hide,search_icon", "");
202
203                 limit_filter_data.max_char_count = 32;
204                 elm_entry_markup_filter_append(entry, elm_entry_filter_limit_size,
205                                 &limit_filter_data);
206
207                 return_key_type = ECORE_IMF_INPUT_PANEL_RETURN_KEY_TYPE_DONE;
208                 elm_entry_input_panel_return_key_type_set(entry, return_key_type);
209                 elm_entry_input_panel_return_key_disabled_set(entry, EINA_TRUE);
210
211                 g_hidden_ap_popup_data->entry = entry;
212
213                 evas_object_smart_callback_add(entry, "activated",
214                                 view_hidden_ap_popup_ok_cb, NULL);
215                 evas_object_smart_callback_add(entry, "changed",
216                                 __popup_entry_changed_cb, NULL);
217                 evas_object_smart_callback_add(entry, "preedit,changed",
218                                 __popup_entry_changed_cb, NULL);
219                 evas_object_smart_callback_add(entry, "focused",
220                                 __popup_entry_focused_cb, NULL);
221                 evas_object_smart_callback_add(entry, "unfocused",
222                                 __popup_entry_unfocused_cb, NULL);
223                 evas_object_smart_callback_add(entry, "maxlength,reached",
224                                 __popup_entry_maxlength_reached, NULL);
225
226                 elm_entry_input_panel_show(entry);
227
228                 return entry;
229         }
230
231         return NULL;
232 }
233
234 static void popup_animation_finish_cb(void *data, Evas_Object *obj, void *event_info)
235 {
236         __COMMON_FUNC_ENTER__;
237         Elm_Object_Item *item = (Elm_Object_Item *) data;
238         Evas_Object *entry = NULL;
239
240         entry = elm_object_item_part_content_get(item, "elm.icon.entry");
241         elm_entry_input_panel_show(entry);
242         elm_object_focus_set(entry, EINA_TRUE);
243
244         __COMMON_FUNC_EXIT__;
245 }
246
247 void view_hidden_ap_popup_create(Evas_Object *win_main, const char *str_pkg_name)
248 {
249         __COMMON_FUNC_ENTER__;
250
251         Evas_Object *passpopup = NULL;
252         Evas_Object *genlist = NULL;
253         popup_btn_info_t popup_data;
254
255         if (win_main == NULL) {
256                 INFO_LOG(UG_NAME_ERR, "Invalid argument passed.");
257                 return;
258         }
259
260         if (g_hidden_ap_popup_data != NULL) {
261                 if (g_hidden_ap_popup_data->popup != NULL) {
262                         evas_object_del(g_hidden_ap_popup_data->popup);
263                         g_hidden_ap_popup_data->popup = NULL;
264                 }
265                 g_free(g_hidden_ap_popup_data);
266         }
267
268         g_hidden_ap_popup_data = g_try_new0(hiddep_ap_popup_data_t, 1);
269         if (g_hidden_ap_popup_data == NULL) {
270                 INFO_LOG(UG_NAME_ERR, "Memory allocation error.");
271                 return;
272         }
273
274         /* Lets disable the scan updates so that the UI is not refreshed un necessarily */
275         wlan_manager_disable_scan_result_update();
276
277         memset(&popup_data, 0, sizeof(popup_data));
278         popup_data.title_txt = "IDS_WIFI_BUTTON_FIND_HIDDEN_NETWORK";
279         popup_data.btn1_cb = view_hidden_ap_popup_cancel_cb;
280         popup_data.btn1_data = NULL;
281         popup_data.btn1_txt = "IDS_WIFI_SK_CANCEL";
282         popup_data.btn2_cb = view_hidden_ap_popup_ok_cb;
283         popup_data.btn2_data = NULL;
284         popup_data.btn2_txt = "IDS_COM_BODY_FIND";
285
286         passpopup = common_utils_show_info_popup(win_main, &popup_data);
287         g_hidden_ap_popup_data->ok_btn = popup_data.btn;
288         elm_object_disabled_set(g_hidden_ap_popup_data->ok_btn, EINA_TRUE);
289
290         g_hidden_ap_popup_data->win = win_main;
291         g_hidden_ap_popup_data->str_pkg_name = str_pkg_name;
292         g_hidden_ap_popup_data->popup = passpopup;
293
294         genlist = elm_genlist_add(passpopup);
295         evas_object_size_hint_weight_set(genlist, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
296         evas_object_size_hint_align_set(genlist, EVAS_HINT_FILL, EVAS_HINT_FILL);
297         elm_scroller_content_min_limit(genlist, EINA_FALSE, EINA_TRUE);
298
299         g_entry_itc.item_style = "entry";
300         g_entry_itc.func.text_get = NULL;
301         g_entry_itc.func.content_get = _gl_entry_item_content_get;
302         g_entry_itc.func.state_get = NULL;
303         g_entry_itc.func.del = NULL;
304
305         Elm_Object_Item * entry_item = elm_genlist_item_append(genlist,
306                         &g_entry_itc, NULL, NULL, ELM_GENLIST_ITEM_NONE,
307                         NULL, NULL);
308
309         evas_object_smart_callback_add(passpopup, "show,finished",
310                         popup_animation_finish_cb, entry_item);
311
312         evas_object_show(genlist);
313         elm_object_content_set(passpopup, genlist);
314         evas_object_show(passpopup);
315
316         __COMMON_FUNC_EXIT__;
317 }