Merge branch 'master' into tizen_2.1
[apps/native/ug-mobile-ap.git] / src / mh_view_wifi_setup.c
1 /*
2 * ug-mobile-ap
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 #include <notification.h>
20 #include "mh_view_wifi_setup.h"
21
22 static void __back_btn_cb(void *data, Evas_Object *obj, void *event_info);
23 static void __gl_realized(void *data, Evas_Object *obj, void *event_info);
24
25 static void __input_panel_event_cb(void *data, Ecore_IMF_Context *ctx, int value)
26 {
27         if (data == NULL) {
28                 ERR("data is NULL\n");
29                 return;
30         }
31
32         mh_appdata_t *ad = (mh_appdata_t *)data;
33         mh_wifi_setting_view_t *st = &ad->setup;
34
35         ad->imf_state = value;
36
37         if (st->navi_it == NULL) {
38                 DBG("naviframe item is not pushed yet\n");
39                 return;
40         }
41
42         if (value == ECORE_IMF_INPUT_PANEL_STATE_SHOW &&
43                         (ad->rotate_state == UG_EVENT_ROTATE_LANDSCAPE ||
44                          ad->rotate_state == UG_EVENT_ROTATE_LANDSCAPE_UPSIDEDOWN)) {
45                 DBG("ECORE_IMF_INPUT_PANEL_STATE_SHOW and Landscape mode\n");
46                 elm_naviframe_item_title_visible_set(st->navi_it, EINA_FALSE);
47         } else if (value == ECORE_IMF_INPUT_PANEL_STATE_HIDE) {
48                 DBG("ECORE_IMF_INPUT_PANEL_STATE_HIDE\n");
49                 elm_naviframe_item_title_visible_set(st->navi_it, EINA_TRUE);
50         }
51
52         return;
53 }
54
55 static void __hide_btn_changed_cb(void *data, Evas_Object *obj, void *event_info)
56 {
57         __MOBILE_AP_FUNC_ENTER__;
58
59         if (data == NULL || obj == NULL) {
60                 ERR("Invalid param\n");
61                 return;
62         }
63
64         mh_appdata_t *ad = (mh_appdata_t *)data;
65         int ret = 0;
66
67         ret = tethering_wifi_set_ssid_visibility(ad->handle,
68                         !ad->setup.visibility);
69         if (ret != TETHERING_ERROR_NONE) {
70                 ERR("tethering_wifi_set_ssid_visibility is failed : %d\n", ret);
71                 return;
72         }
73
74         ad->setup.visibility = !ad->setup.visibility;
75
76         __MOBILE_AP_FUNC_EXIT__;
77 }
78
79 static void __security_btn_changed_cb(void *data, Evas_Object *obj, void *event_info)
80 {
81         __MOBILE_AP_FUNC_ENTER__;
82
83         if (data == NULL || obj == NULL) {
84                 ERR("Invalid param\n");
85                 return;
86         }
87
88         mh_appdata_t *ad = (mh_appdata_t *)data;
89         int ret = 0;
90
91         if (ad->setup.security_type == TETHERING_WIFI_SECURITY_TYPE_NONE)
92                 ad->setup.security_type = TETHERING_WIFI_SECURITY_TYPE_WPA2_PSK;
93         else
94                 ad->setup.security_type = TETHERING_WIFI_SECURITY_TYPE_NONE;
95
96         ret = tethering_wifi_set_security_type(ad->handle, ad->setup.security_type);
97         if (ret != TETHERING_ERROR_NONE) {
98                 ERR("tethering_wifi_set_security_type is failed : %d\n", ret);
99                 return;
100         }
101
102         elm_genlist_item_update(ad->setup.pw_item);
103
104         __MOBILE_AP_FUNC_EXIT__;
105 }
106
107 static char *__gl_hide_label_get(void *data, Evas_Object *obj, const char *part)
108 {
109         __MOBILE_AP_FUNC_ENTER__;
110
111         if (data == NULL || obj == NULL || part == NULL) {
112                 ERR("Invalid param\n");
113                 return NULL;
114         }
115
116         if (strcmp(part, "elm.text") != 0) {
117                 ERR("Invalid param\n");
118                 return NULL;
119         }
120
121         __MOBILE_AP_FUNC_EXIT__;
122         return strdup(_("IDS_MOBILEAP_BODY_HIDE_MY_DEVICE"));
123 }
124
125 static char *__gl_security_label_get(void *data, Evas_Object *obj, const char *part)
126 {
127         __MOBILE_AP_FUNC_ENTER__;
128
129         if (data == NULL || obj == NULL || part == NULL) {
130                 ERR("Invalid param\n");
131                 return NULL;
132         }
133
134         if (strcmp(part, "elm.text") != 0) {
135                 ERR("Invalid param\n");
136                 return NULL;
137         }
138
139         __MOBILE_AP_FUNC_EXIT__;
140         return strdup(_("IDS_MOBILEAP_BODY_SECURITY"));
141 }
142
143 static char *__gl_name_label_get(void *data, Evas_Object *obj, const char *part)
144 {
145         __MOBILE_AP_FUNC_ENTER__;
146
147         if (data == NULL || obj == NULL || part == NULL) {
148                 ERR("Invalid param\n");
149                 return NULL;
150         }
151
152         if (strcmp(part, "elm.text") != 0) {
153                 ERR("Invalid param : %s\n", part);
154                 return NULL;
155         }
156
157         mh_appdata_t *ad = (mh_appdata_t *)data;
158         char label[MH_LABEL_LENGTH_MAX] = {0, };
159         char name_change_label[MH_LABEL_LENGTH_MAX] = {0, };
160         char path[MH_LABEL_LENGTH_MAX] = {0, };
161         char *device_name = NULL;
162
163         DBG("Device name : %s\n", ad->setup.device_name);
164
165         device_name = elm_entry_utf8_to_markup(ad->setup.device_name);
166         if (device_name == NULL) {
167                 ERR("elm_entry_utf8_to_markup is failed\n");
168                 return NULL;
169         }
170
171         snprintf(path, sizeof(path), "%s > %s",
172                         S_("IDS_COM_BODY_SETTINGS"),
173                         _("IDS_ST_BODY_ABOUT_PHONE"));
174         snprintf(name_change_label, sizeof(name_change_label),
175                         _("IDS_MOBILEAP_BODY_DEVICE_NAME_CAN_BE_CHANGED_IN_PS"),
176                         path);
177         snprintf(label, sizeof(label), "%s: %s<br>%s",
178                         _("IDS_MOBILEAP_BODY_DEVICE_NAME"),
179                         device_name,
180                         name_change_label);
181         free(device_name);
182
183         __MOBILE_AP_FUNC_EXIT__;
184
185         return strdup(label);
186 }
187
188 static Evas_Object *__gl_hide_icon_get(void *data, Evas_Object *obj,
189                 const char *part)
190 {
191         __MOBILE_AP_FUNC_ENTER__;
192
193         if (data == NULL || obj == NULL || part == NULL) {
194                 ERR("Invalid param\n");
195                 return NULL;
196         }
197
198         if (strcmp(part, "elm.icon") != 0) {
199                 ERR("Invalid param\n");
200                 return NULL;
201         }
202
203         mh_appdata_t *ad = (mh_appdata_t *)data;
204         Evas_Object *btn = NULL;
205
206         btn = elm_check_add(obj);
207         if (btn == NULL) {
208                 ERR("btn is NULL\n");
209                 return NULL;
210         }
211         elm_object_style_set(btn, "on&off");
212         evas_object_show(btn);
213         evas_object_pass_events_set(btn, EINA_TRUE);
214         evas_object_propagate_events_set(btn, EINA_FALSE);
215         elm_check_state_set(btn, ad->setup.visibility ? EINA_FALSE : EINA_TRUE);
216         evas_object_smart_callback_add(btn, "changed",
217                         __hide_btn_changed_cb, (void *)ad);
218
219         ad->setup.hide_btn = btn;
220
221         __MOBILE_AP_FUNC_EXIT__;
222         return btn;
223 }
224
225 static Evas_Object *__gl_security_icon_get(void *data, Evas_Object *obj,
226                 const char *part)
227 {
228         __MOBILE_AP_FUNC_ENTER__;
229
230         if (data == NULL || obj == NULL || part == NULL) {
231                 ERR("Invalid param\n");
232                 return NULL;
233         }
234
235         if (strcmp(part, "elm.icon") != 0) {
236                 ERR("Invalid param\n");
237                 return NULL;
238         }
239
240         mh_appdata_t *ad = (mh_appdata_t *)data;
241         Evas_Object *btn = NULL;
242
243         btn = elm_check_add(obj);
244
245         elm_object_style_set(btn, "on&off");
246         evas_object_show(btn);
247         evas_object_pass_events_set(btn, EINA_TRUE);
248         evas_object_propagate_events_set(btn, EINA_FALSE);
249         elm_check_state_set(btn, ad->setup.security_type ==
250                         TETHERING_WIFI_SECURITY_TYPE_NONE ?
251                         EINA_FALSE : EINA_TRUE);
252         evas_object_smart_callback_add(btn, "changed",
253                         __security_btn_changed_cb, (void *)ad);
254
255         ad->setup.security_btn = btn;
256
257         __MOBILE_AP_FUNC_EXIT__;
258         return btn;
259 }
260
261 static Eina_Bool __save_wifi_passphrase(mh_appdata_t *ad)
262 {
263         __MOBILE_AP_FUNC_ENTER__;
264
265         if (ad == NULL) {
266                 ERR("Invalid param\n");
267                 return EINA_FALSE;
268         }
269
270         mh_wifi_setting_view_t *st = &ad->setup;
271         int ret = 0;
272
273         ret = tethering_wifi_set_passphrase(ad->handle, st->wifi_passphrase_new);
274         if (ret != TETHERING_ERROR_NONE) {
275                 ERR("tethering_wifi_set_passphrase is failed : %d\n", ret);
276                 return EINA_FALSE;
277         }
278
279         g_strlcpy(st->wifi_passphrase, st->wifi_passphrase_new, sizeof(st->wifi_passphrase));
280
281         __MOBILE_AP_FUNC_EXIT__;
282
283         return EINA_TRUE;
284 }
285
286 static void __passphrase_maxlength_reached_cb(void *data, Evas_Object *obj,
287                 void *event_info)
288 {
289         __MOBILE_AP_FUNC_ENTER__;
290
291         if (data == NULL || obj == NULL) {
292                 ERR("The param is NULL\n");
293                 return;
294         }
295
296         mh_appdata_t *ad = (mh_appdata_t *)data;
297         char buf[MH_LABEL_LENGTH_MAX] = {0, };
298         int ret;
299
300         ecore_imf_input_panel_hide();
301         elm_object_focus_set(ad->setup.pw_entry, EINA_FALSE);
302
303         if (__save_wifi_passphrase(ad) == EINA_FALSE) {
304                 ERR("__save_wifi_passphrase is failed\n");
305         }
306
307         snprintf(buf, sizeof(buf),
308                         _("IDS_MOBILEAP_POP_PASSWORD_MUST_CONTAIN_AT_LEAST_PD_CHARACTERS_AND_NOT_EXCEED_PD_CHARACTERS"),
309                         WIFI_PASSPHRASE_LENGTH_MIN, WIFI_PASSPHRASE_LENGTH_MAX);
310
311         ret = notification_status_message_post(buf);
312         if (ret != NOTIFICATION_ERROR_NONE)
313                 ERR("notification_status_message_post() is failed : %d\n", ret);
314
315         __MOBILE_AP_FUNC_EXIT__;
316 }
317
318 static void __passphrase_activated_cb(void *data, Evas_Object *obj,
319                 void *event_info)
320 {
321         __MOBILE_AP_FUNC_ENTER__;
322
323         if (data == NULL || obj == NULL) {
324                 ERR("Invalid param\n");
325                 return;
326         }
327
328         mh_appdata_t *ad = (mh_appdata_t *)data;
329         int ret;
330         char *ptr;
331
332         ecore_imf_input_panel_hide();
333         elm_object_focus_set(ad->setup.pw_entry, EINA_FALSE);
334
335         if (strlen(ad->setup.wifi_passphrase_new) < WIFI_PASSPHRASE_LENGTH_MIN) {
336                 DBG("Password is shorter than %d\n", WIFI_PASSPHRASE_LENGTH_MIN);
337                 ret = notification_status_message_post(_("IDS_ST_BODY_ENTER_PASSWORD_OF_AT_LEAST_8_CHARACTERS"));
338                 if (ret != NOTIFICATION_ERROR_NONE)
339                         ERR("notification_status_message_post() is failed : %d\n", ret);
340
341                 ptr = elm_entry_utf8_to_markup(ad->setup.wifi_passphrase);
342                 if (ptr != NULL) {
343                         elm_entry_entry_set(ad->setup.pw_entry, ptr);
344                         free(ptr);
345                 } else {
346                         ERR("elm_entry_utf8_to_markup is failed\n");
347                 }
348
349                 return;
350         }
351
352         if (__save_wifi_passphrase(ad) == EINA_FALSE) {
353                 ERR("__save_wifi_passphrase is failed\n");
354         }
355
356         __MOBILE_AP_FUNC_EXIT__;
357
358         return;
359 }
360
361 static void __pw_entry_changed_cb(void *data, Evas_Object *obj,
362                 void *event_info)
363 {
364         __MOBILE_AP_FUNC_ENTER__;
365
366         if (data == NULL || obj == NULL) {
367                 ERR("Invalid param\n");
368                 return;
369         }
370
371         mh_appdata_t *ad = (mh_appdata_t *)data;
372         mh_wifi_setting_view_t *st = &ad->setup;
373         const char *changed_text;
374         char *utf8_string;
375
376         changed_text = elm_entry_entry_get(st->pw_entry);
377         if (changed_text == NULL) {
378                 ERR("elm_entry_entry_get is failed\n");
379                 return;
380         }
381
382         utf8_string = elm_entry_markup_to_utf8(changed_text);
383         if (utf8_string == NULL) {
384                 ERR("elm_entry_markup_to_utf8() Failed!!!\n");
385         } else {
386                 g_strlcpy(st->wifi_passphrase_new, utf8_string,
387                                 sizeof(st->wifi_passphrase_new));
388                 free(utf8_string);
389         }
390
391         if (!elm_object_focus_get(st->pw_entry)) {
392                 return;
393         }
394
395         if (elm_entry_is_empty(st->pw_entry)) {
396                 elm_object_item_signal_emit(st->pw_item,
397                                 "elm,state,eraser,hide", "");
398         } else {
399                 elm_object_item_signal_emit(st->pw_item,
400                                 "elm,state,eraser,show", "");
401         }
402
403         __MOBILE_AP_FUNC_EXIT__;
404
405         return;
406
407 }
408
409 static void __pw_entry_focused_cb(void *data, Evas_Object *obj,
410                 void *event_info)
411 {
412         __MOBILE_AP_FUNC_ENTER__;
413
414         if (data == NULL || obj == NULL) {
415                 ERR("Invalid param\n");
416                 return;
417         }
418
419         mh_appdata_t *ad = (mh_appdata_t *)data;
420         mh_wifi_setting_view_t *st = &ad->setup;
421
422         if (!elm_entry_is_empty(st->pw_entry)) {
423                 elm_entry_cursor_end_set(st->pw_entry);
424                 elm_object_item_signal_emit(st->pw_item,
425                                 "elm,state,eraser,show", "");
426         }
427
428         __MOBILE_AP_FUNC_EXIT__;
429
430         return;
431
432 }
433
434 static void __pw_entry_unfocused_cb(void *data, Evas_Object *obj,
435                 void *event_info)
436 {
437         __MOBILE_AP_FUNC_ENTER__;
438
439         if (data == NULL || obj == NULL) {
440                 ERR("Invalid param\n");
441                 return;
442         }
443
444         mh_appdata_t *ad = (mh_appdata_t *)data;
445         mh_wifi_setting_view_t *st = &ad->setup;
446
447         elm_object_item_signal_emit(st->pw_item,
448                         "elm,state,eraser,hide", "");
449
450         __MOBILE_AP_FUNC_EXIT__;
451
452         return;
453
454 }
455
456 static void __pw_layout_eraser_clicked_cb(void *data, Evas_Object *obj, void *event_info)
457 {
458         __MOBILE_AP_FUNC_ENTER__;
459
460         if (data == NULL || obj == NULL) {
461                 ERR("Invalid param\n");
462                 return;
463         }
464
465         mh_appdata_t *ad = (mh_appdata_t *)data;
466         mh_wifi_setting_view_t *st = &ad->setup;
467
468         elm_entry_entry_set(st->pw_entry, "");
469
470         __MOBILE_AP_FUNC_EXIT__;
471
472         return;
473
474 }
475
476 static char *__gl_pw_text_get(void *data, Evas_Object *obj, const char *part)
477 {
478         __MOBILE_AP_FUNC_ENTER__;
479
480         if (data == NULL || obj == NULL || part == NULL) {
481                 ERR("Invalid parameter\n");
482                 return NULL;
483         }
484
485         if (g_strcmp0(part, "elm.text") != 0) {
486                 ERR("Invalid part : %s\n", part);
487                 return NULL;
488         }
489
490         __MOBILE_AP_FUNC_EXIT__;
491         return strdup(_("IDS_MOBILEAP_BODY_PASSWORD"));
492 }
493
494 static Evas_Object *__gl_pw_icon_get(void *data, Evas_Object *obj,
495                 const char *part)
496 {
497         __MOBILE_AP_FUNC_ENTER__;
498
499         if (data == NULL || obj == NULL || part == NULL) {
500                 ERR("Invalid param\n");
501                 return NULL;
502         }
503
504         if (g_strcmp0(part, "elm.icon.entry") == 0) {
505                 static Elm_Entry_Filter_Limit_Size limit_filter_data;
506
507                 mh_appdata_t *ad = (mh_appdata_t *)data;
508                 mh_wifi_setting_view_t *st = &ad->setup;
509                 Evas_Object *entry = NULL;
510                 char *ptr = NULL;
511                 Ecore_IMF_Context *imf_context;
512
513                 entry = elm_entry_add(obj);
514                 if (entry == NULL) {
515                         ERR("elm_entry_add returns NULL\n");
516                         st->pw_entry = NULL;
517                         return NULL;
518                 }
519
520                 /* Set single line of entry */
521                 elm_entry_scrollable_set(entry, EINA_TRUE);
522                 elm_entry_single_line_set(entry, EINA_TRUE);
523                 elm_entry_input_panel_layout_set(entry, ELM_INPUT_PANEL_LAYOUT_PASSWORD);
524                 elm_entry_select_allow_set(entry, EINA_FALSE);
525                 elm_entry_context_menu_disabled_set(entry, EINA_TRUE);
526
527                 /* Set the maximum length filter for passphrase entry */
528                 limit_filter_data.max_char_count = 0;
529                 limit_filter_data.max_byte_count = WIFI_PASSPHRASE_LENGTH_MAX;
530                 elm_entry_markup_filter_append(entry,
531                                 elm_entry_filter_limit_size, &limit_filter_data);
532
533                 DBG("security_type : %d\n", st->security_type);
534                 if (st->security_type == TETHERING_WIFI_SECURITY_TYPE_NONE) {
535                         ptr = elm_entry_utf8_to_markup(st->wifi_passphrase);
536                         if (ptr != NULL) {
537                                 elm_entry_entry_set(entry, ptr);
538                                 free(ptr);
539                         } else {
540                                 ERR("elm_entry_utf8_to_markup is failed\n");
541                         }
542
543                         /* Set editable mode */
544                         elm_entry_input_panel_enabled_set(entry, EINA_FALSE);
545                         elm_object_disabled_set(entry, EINA_TRUE);
546                 } else {
547                         ptr = elm_entry_utf8_to_markup(st->wifi_passphrase_new);
548                         if (ptr != NULL) {
549                                 elm_entry_entry_set(entry, ptr);
550                                 free(ptr);
551                         } else {
552                                 ERR("elm_entry_utf8_to_markup is failed\n");
553                         }
554                 }
555
556                 evas_object_smart_callback_add(entry, "maxlength,reached",
557                                 __passphrase_maxlength_reached_cb, data);
558                 evas_object_smart_callback_add(entry, "activated",
559                                 __passphrase_activated_cb, data);
560                 evas_object_smart_callback_add(entry, "changed",
561                                 __pw_entry_changed_cb, data);
562                 evas_object_smart_callback_add(entry, "focused",
563                                 __pw_entry_focused_cb, data);
564                 evas_object_smart_callback_add(entry, "unfocused",
565                                 __pw_entry_unfocused_cb, data);
566
567                 imf_context = (Ecore_IMF_Context *)elm_entry_imf_context_get(entry);
568                 if (imf_context == NULL) {
569                         ERR("elm_entry_imf_context_get() is failed\n");
570                 } else {
571                         ecore_imf_context_input_panel_event_callback_add(imf_context,
572                                         ECORE_IMF_INPUT_PANEL_STATE_EVENT,
573                                         __input_panel_event_cb, (void *)ad);
574                 }
575
576                 elm_object_item_signal_emit(st->pw_item,
577                                 "elm,state,rename,hide", "");
578                 if (!elm_entry_is_empty(entry)) {
579                         elm_object_item_signal_emit(st->pw_item,
580                                         "elm,state,eraser,hide", "");
581                 }
582
583                 elm_object_part_text_set(entry, "elm.guide",
584                                 S_("IDS_COM_BODY_ENTER_PASSWORD"));
585
586                 evas_object_show(entry);
587                 st->pw_entry = entry;
588
589                 __MOBILE_AP_FUNC_EXIT__;
590                 return st->pw_entry;
591         } else if (g_strcmp0(part, "elm.icon.eraser") == 0) {
592                 Evas_Object *btn = elm_button_add(obj);
593                 elm_object_style_set(btn, "editfield_clear");
594                 evas_object_smart_callback_add(btn, "clicked", __pw_layout_eraser_clicked_cb, data);
595                 return btn;
596         } else {
597                 DBG("Unknown part : %s\n", part);
598         }
599
600         return NULL;
601 }
602
603 static void __gl_hide_item_sel(void *data, Evas_Object *obj, void *event_info)
604 {
605         __MOBILE_AP_FUNC_ENTER__;
606
607         if (data == NULL || obj == NULL || event_info == NULL) {
608                 ERR("param is NULL\n");
609                 return;
610         }
611
612         mh_appdata_t *ad = (mh_appdata_t *)data;
613
614         elm_genlist_item_selected_set((Elm_Object_Item*)event_info, EINA_FALSE);
615
616         __hide_btn_changed_cb(data, obj, NULL);
617         elm_check_state_set(ad->setup.hide_btn, ad->setup.visibility ?
618                         EINA_FALSE : EINA_TRUE);
619
620         __MOBILE_AP_FUNC_EXIT__;
621 }
622
623 static void __gl_security_item_sel(void *data, Evas_Object *obj, void *event_info)
624 {
625         __MOBILE_AP_FUNC_ENTER__;
626
627         if (data == NULL || obj == NULL || event_info == NULL) {
628                 ERR("param is NULL\n");
629                 return;
630         }
631
632         mh_appdata_t *ad = (mh_appdata_t *)data;
633
634         elm_genlist_item_selected_set((Elm_Object_Item*)event_info, EINA_FALSE);
635
636         __security_btn_changed_cb(data, obj, NULL);
637         elm_check_state_set(ad->setup.security_btn, ad->setup.security_type ==
638                         TETHERING_WIFI_SECURITY_TYPE_NONE ? EINA_FALSE : EINA_TRUE);
639
640         __MOBILE_AP_FUNC_EXIT__;
641 }
642
643 static void __free_genlist_itc(mh_appdata_t *ad)
644 {
645         __MOBILE_AP_FUNC_ENTER__;
646
647         elm_genlist_item_class_free(ad->setup.sp_itc);
648         elm_genlist_item_class_free(ad->setup.hide_itc);
649         elm_genlist_item_class_free(ad->setup.security_itc);
650         elm_genlist_item_class_free(ad->setup.pw_itc);
651         elm_genlist_item_class_free(ad->setup.name_itc);
652
653         __MOBILE_AP_FUNC_EXIT__;
654         return;
655 }
656
657 static void __set_genlist_itc(mh_appdata_t *ad)
658 {
659         __MOBILE_AP_FUNC_ENTER__;
660
661         ad->setup.sp_itc = elm_genlist_item_class_new();
662         ad->setup.sp_itc->item_style = "dialogue/separator";
663         ad->setup.sp_itc->func.text_get = NULL;
664         ad->setup.sp_itc->func.content_get = NULL;
665         ad->setup.sp_itc->func.state_get = NULL;
666         ad->setup.sp_itc->func.del = NULL;
667
668         ad->setup.hide_itc = elm_genlist_item_class_new();
669         ad->setup.hide_itc->item_style = "dialogue/1text.1icon";
670         ad->setup.hide_itc->func.text_get = __gl_hide_label_get;
671         ad->setup.hide_itc->func.content_get = __gl_hide_icon_get;
672         ad->setup.hide_itc->func.state_get = NULL;
673         ad->setup.hide_itc->func.del = NULL;
674
675         ad->setup.security_itc = elm_genlist_item_class_new();
676         ad->setup.security_itc->item_style = "dialogue/1text.1icon";
677         ad->setup.security_itc->func.text_get = __gl_security_label_get;
678         ad->setup.security_itc->func.content_get = __gl_security_icon_get;
679         ad->setup.security_itc->func.state_get = NULL;
680         ad->setup.security_itc->func.del = NULL;
681
682         ad->setup.pw_itc = elm_genlist_item_class_new();
683         ad->setup.pw_itc->item_style = "dialogue/editfield/title";
684         ad->setup.pw_itc->func.text_get = __gl_pw_text_get;
685         ad->setup.pw_itc->func.content_get = __gl_pw_icon_get;
686         ad->setup.pw_itc->func.state_get = NULL;
687         ad->setup.pw_itc->func.del = NULL;
688
689         ad->setup.name_itc = elm_genlist_item_class_new();
690         ad->setup.name_itc->item_style = "multiline/1text";
691         ad->setup.name_itc->func.text_get = __gl_name_label_get;
692         ad->setup.name_itc->func.content_get = NULL;
693         ad->setup.name_itc->func.state_get = NULL;
694         ad->setup.name_itc->func.del = NULL;
695
696         ad->setup.end_sp_itc = elm_genlist_item_class_new();
697         ad->setup.end_sp_itc->item_style = "dialogue/separator";
698         ad->setup.end_sp_itc->func.text_get = NULL;
699         ad->setup.end_sp_itc->func.content_get = NULL;
700         ad->setup.end_sp_itc->func.state_get = NULL;
701         ad->setup.end_sp_itc->func.del = NULL;
702
703         __MOBILE_AP_FUNC_EXIT__;
704         return;
705 }
706
707 static void __deconstruct_wifi_setup_view(mh_wifi_setting_view_t *st)
708 {
709         __MOBILE_AP_FUNC_ENTER__;
710
711         if (st == NULL) {
712                 ERR("st is NULL\n");
713                 return;
714         }
715
716         if (st->pw_entry == NULL) {
717                 ERR("pw_entry is NULL");
718                 return;
719         }
720
721         evas_object_smart_callback_del(st->hide_btn, "changed",
722                         __hide_btn_changed_cb);
723         evas_object_smart_callback_del(st->security_btn, "changed",
724                         __security_btn_changed_cb);
725         if (st->pw_entry) {
726                 evas_object_smart_callback_del(st->pw_entry,
727                                 "maxlength,reached",
728                                 __passphrase_maxlength_reached_cb);
729                 evas_object_smart_callback_del(st->pw_entry,
730                                 "activated",
731                                 __passphrase_activated_cb);
732         }
733         evas_object_smart_callback_del(st->back_btn, "clicked",
734                         __back_btn_cb);
735         evas_object_smart_callback_del(st->genlist, "realized",
736                         __gl_realized);
737
738         st->hide_btn = NULL;
739         st->security_btn = NULL;
740         st->pw_entry = NULL;
741         st->back_btn = NULL;
742         st->genlist = NULL;
743
744         __MOBILE_AP_FUNC_EXIT__;
745 }
746
747 static void __back_btn_cb(void *data, Evas_Object *obj, void *event_info)
748 {
749         __MOBILE_AP_FUNC_ENTER__;
750
751         if (data == NULL) {
752                 ERR("The param is NULL\n");
753                 return;
754         }
755
756         mh_appdata_t *ad = (mh_appdata_t *)data;
757         mh_wifi_setting_view_t *st = &ad->setup;
758         Eina_Bool imf_state;
759         int ret;
760         char *ptr = NULL;
761
762         imf_state = ecore_imf_input_panel_hide();
763         elm_object_focus_set(st->pw_entry, EINA_FALSE);
764
765         if (strlen(st->wifi_passphrase_new) < WIFI_PASSPHRASE_LENGTH_MIN) {
766                 DBG("Password is shorter than %d\n", WIFI_PASSPHRASE_LENGTH_MIN);
767                 ret = notification_status_message_post(_("IDS_ST_BODY_ENTER_PASSWORD_OF_AT_LEAST_8_CHARACTERS"));
768                 if (ret != NOTIFICATION_ERROR_NONE)
769                         ERR("notification_status_message_post() is failed : %d\n", ret);
770
771                 ptr = elm_entry_utf8_to_markup(st->wifi_passphrase);
772                 if (ptr != NULL) {
773                         elm_entry_entry_set(st->pw_entry, ptr);
774                         free(ptr);
775                 } else {
776                         ERR("elm_entry_utf8_to_markup is failed\n");
777                 }
778
779                 return;
780         }
781
782         if (g_strcmp0(st->wifi_passphrase, st->wifi_passphrase_new) != 0) {
783                 if (__save_wifi_passphrase(ad) == EINA_FALSE) {
784                         ERR("__save_wifi_passphrase is failed\n");
785                 }
786         }
787
788         if (imf_state == EINA_TRUE) {
789                 DBG("IMF is hided\n");
790                 return;
791         }
792
793         if (ad->main.need_recover_wifi_tethering == true) {
794                 DBG("Turn on Wi-Fi tethering again\n");
795                 _update_wifi_item(ad, MH_STATE_PROCESS);
796                 if (ad->main.help_item)
797                         elm_genlist_item_update(ad->main.help_item);
798
799                 ret = tethering_enable(ad->handle, TETHERING_TYPE_WIFI);
800                 if (ret != TETHERING_ERROR_NONE) {
801                         ERR("Wi-Fi tethering on is failed : %d\n", ret);
802                         _update_wifi_item(ad, MH_STATE_NONE);
803                         ad->main.need_recover_wifi_tethering = false;
804                 }
805         }
806
807         __deconstruct_wifi_setup_view(st);
808
809         evas_object_del(ad->setup.genlist);
810         __free_genlist_itc(ad);
811
812         elm_naviframe_item_pop(ad->naviframe);
813
814         __MOBILE_AP_FUNC_EXIT__;
815 }
816
817 static void __gl_realized(void *data, Evas_Object *obj, void *event_info)
818 {
819         __MOBILE_AP_FUNC_ENTER__;
820
821         mh_appdata_t *ad = (mh_appdata_t *)data;
822         mh_wifi_setting_view_t *st = &(ad->setup);
823         Elm_Object_Item *item = (Elm_Object_Item *)event_info;
824         Evas_Object *ao;
825         Evas_Object *btn;
826         char str[MH_LABEL_LENGTH_MAX] = {0, };
827         int i = 0;
828
829         if (item == st->hide_item) {
830                 DBG("Hide item is realized\n");
831                 elm_object_item_signal_emit(item, "elm,state,top", "");
832         } else if (item == st->security_item) {
833                 DBG("Security item is realized\n");
834                 elm_object_item_signal_emit(item, "elm,state,center", "");
835         } else if (item == st->pw_item) {
836                 DBG("Password item is realized\n");
837                 elm_object_item_signal_emit(item, "elm,state,bottom", "");
838         } else if (item == st->name_item) {
839                 DBG("Name item is realized\n");
840         }
841
842         for (i = 0; i < 2; i++) {
843                 if (item == st->sp_item[i])
844                         elm_object_item_access_unregister(item);
845         }
846
847         if (item == st->hide_item || item == st->security_item) {
848                 ao = elm_object_item_access_object_get(item);
849                 btn = elm_object_item_part_content_get(item, "on&off");
850                 snprintf(str, sizeof(str), "%s, %s", "On/off button",
851                                 (elm_check_state_get(btn) ? "On" : "Off"));
852                 elm_access_info_set(ao, ELM_ACCESS_CONTEXT_INFO, str);
853         }
854
855         __MOBILE_AP_FUNC_EXIT__;
856
857         return;
858 }
859
860 Evas_Object *__create_genlist(mh_appdata_t *ad)
861 {
862         __MOBILE_AP_FUNC_ENTER__;
863
864         if (ad == NULL) {
865                 ERR("ad is NULL\n");
866                 return NULL;
867         }
868
869         void *data = (void *)ad;
870         mh_wifi_setting_view_t *st = &ad->setup;
871         Evas_Object *genlist;
872         Elm_Object_Item *item;
873         int i = 0;
874
875         genlist = elm_genlist_add(ad->naviframe);
876         if (genlist == NULL) {
877                 ERR("genlist is NULL\n");
878                 return NULL;
879         }
880
881         elm_object_style_set(genlist, "dialogue");
882         elm_genlist_mode_set(genlist, ELM_LIST_COMPRESS);
883         evas_object_smart_callback_add(genlist, "realized", __gl_realized, ad);
884
885         __set_genlist_itc(ad);
886         item = elm_genlist_item_append(genlist, st->sp_itc, NULL, NULL,
887                         ELM_GENLIST_ITEM_NONE, NULL, NULL);
888         elm_genlist_item_select_mode_set(item, ELM_OBJECT_SELECT_MODE_DISPLAY_ONLY);
889         st->sp_item[i++] = item;
890
891         st->hide_item = elm_genlist_item_append(genlist, st->hide_itc, data, NULL,
892                         ELM_GENLIST_ITEM_NONE, __gl_hide_item_sel, data);
893
894         st->security_item = elm_genlist_item_append(genlist, st->security_itc, data, NULL,
895                         ELM_GENLIST_ITEM_NONE, __gl_security_item_sel, data);
896
897         st->pw_item = elm_genlist_item_append(genlist, st->pw_itc, data, NULL,
898                         ELM_GENLIST_ITEM_NONE, NULL, NULL);
899         elm_genlist_item_select_mode_set(st->pw_item, ELM_OBJECT_SELECT_MODE_NONE);
900
901         st->name_item = elm_genlist_item_append(genlist, st->name_itc, data, NULL,
902                         ELM_GENLIST_ITEM_NONE, NULL, NULL);
903         elm_genlist_item_select_mode_set(st->name_item, ELM_OBJECT_SELECT_MODE_DISPLAY_ONLY);
904
905         item = elm_genlist_item_append(genlist, st->end_sp_itc, NULL, NULL,
906                         ELM_GENLIST_ITEM_NONE, NULL, NULL);
907         elm_genlist_item_select_mode_set(item, ELM_OBJECT_SELECT_MODE_DISPLAY_ONLY);
908         st->sp_item[i++] = item;
909
910
911         __MOBILE_AP_FUNC_EXIT__;
912
913         return genlist;
914 }
915
916 char *__slide_title_access_info_cb(void *data, Evas_Object *obj)
917 {
918         Evas_Object *label;
919         Elm_Object_Item *navi_it;
920         Eina_Strbuf *buf;
921         const char *info;
922         char *ret;
923
924         navi_it = (Elm_Object_Item *) data;
925         label = elm_object_item_part_content_get(navi_it, "elm.swallow.title");
926         if (label == NULL)
927                 return NULL;
928
929         info = elm_object_text_get(label);
930         if (info == NULL)
931                 return NULL;
932
933         buf = eina_strbuf_new();
934         eina_strbuf_append(buf, info);
935
936         ret = eina_strbuf_string_steal(buf);
937         eina_strbuf_free(buf);
938         return ret;
939 }
940
941 static void __title_clicked_cb(void *data, Evas_Object *obj, void *event_info)
942 {
943         Evas_Object *label;
944         Elm_Object_Item *navi_it = event_info;
945         if (navi_it == NULL)
946                 return;
947
948         label = elm_object_item_part_content_get(navi_it, "elm.swallow.title");
949         if (label == NULL)
950                 return;
951
952         elm_label_slide_go(label);
953 }
954
955 void mh_draw_wifi_setup_view(mh_appdata_t *ad)
956 {
957         __MOBILE_AP_FUNC_ENTER__;
958
959         if (ad == NULL) {
960                 ERR("ad is NULL\n");
961                 return;
962         }
963
964         mh_wifi_setting_view_t *st = &ad->setup;
965         Evas_Object *ao;
966         Evas_Object *label;
967
968
969         if (st->genlist != NULL) {
970                 ERR("Wi-Fi setup view already exists\n");
971                 return;
972         }
973
974         st->genlist = __create_genlist(ad);
975         if (st->genlist == NULL) {
976                 ERR("__create_genlist returns NULL\n");
977                 goto FAIL;
978         }
979
980         st->back_btn = elm_button_add(ad->naviframe);
981         if (st->back_btn == NULL) {
982                 ERR("elm_button_add returns NULL\n");
983                 goto FAIL;
984         }
985         elm_object_style_set(st->back_btn, "naviframe/back_btn/default");
986         evas_object_smart_callback_add(st->back_btn, "clicked",
987                         __back_btn_cb, ad);
988         elm_object_focus_allow_set(st->back_btn, EINA_FALSE);
989
990         st->navi_it = elm_naviframe_item_push(ad->naviframe,
991                         NULL,
992                         st->back_btn, NULL, st->genlist, NULL);
993
994         /* Slide title */
995         label = _create_slide_title(ad->naviframe, _("IDS_MOBILEAP_MBODY_WI_FI_TETHERING_SETTINGS"));
996         elm_object_item_part_content_set(st->navi_it, "elm.swallow.title", label);
997         evas_object_smart_callback_add(ad->naviframe, "title,clicked", __title_clicked_cb, NULL);
998
999         ao = elm_object_item_access_object_get(st->navi_it);
1000         if (ao) {
1001                 elm_access_info_set(ao, ELM_ACCESS_TYPE, "title");
1002                 elm_access_info_cb_set(ao, ELM_ACCESS_INFO,
1003                                 __slide_title_access_info_cb, st->navi_it);
1004                 elm_object_focus_set(ao, EINA_TRUE);
1005         }
1006
1007         /* Realize genlist item forcely since UIFW doesn't make realize to avoid crash on landscape mode*/
1008         elm_genlist_item_update(st->pw_item);
1009
1010         __MOBILE_AP_FUNC_EXIT__;
1011
1012         return;
1013
1014 FAIL:
1015         if (st->back_btn)
1016                 evas_object_del(st->back_btn);
1017         if (st->genlist)
1018                 evas_object_del(st->genlist);
1019
1020         st->back_btn = NULL;
1021         st->genlist = NULL;
1022 }